Commit 1999f978 authored by Stefan Lankes's avatar Stefan Lankes
Browse files

switch crate "log" for kernel messages

parent 749b25d0
......@@ -23,13 +23,20 @@ vga = []
bitflags = "1.0.*"
spin = "0.5"
[dependencies.log]
version = "0.4"
default-features = false
features = ["max_level_trace"]
[dependencies.smoltcp]
git = "https://github.com/hermitcore/smoltcp.git"
branch = "hermit"
default-features = false
features = ["log", "alloc", "socket-raw", "socket-udp", "socket-tcp", "proto-ipv4", "proto-dhcpv4"]
[target.'cfg(target_arch = "x86_64")'.dependencies.hermit-multiboot]
git = "https://github.com/hermitcore/multiboot.git"
#[dependencies.lazy_static]
#version = "1.0.1"
#features = ["spin_no_std"]
[target.'cfg(target_arch = "x86_64")'.dependencies.x86]
git = "https://github.com/hermitcore/rust-x86.git"
branch = "hermit"
......
......@@ -476,7 +476,7 @@ fn get_page_range<S: PageSize>(virtual_address: usize, count: usize) -> PageIter
}
pub fn get_page_table_entry<S: PageSize>(virtual_address: usize) -> Option<PageTableEntry> {
debug_mem!("Looking up Page Table Entry for {:#X}", virtual_address);
trace!("Looking up Page Table Entry for {:#X}", virtual_address);
let page = Page::<S>::including_address(virtual_address);
let root_pagetable = unsafe { &mut *L0TABLE_ADDRESS };
......@@ -484,7 +484,7 @@ pub fn get_page_table_entry<S: PageSize>(virtual_address: usize) -> Option<PageT
}
pub fn get_physical_address<S: PageSize>(virtual_address: usize) -> usize {
debug_mem!("Getting physical address for {:#X}", virtual_address);
trace!("Getting physical address for {:#X}", virtual_address);
let page = Page::<S>::including_address(virtual_address);
let root_pagetable = unsafe { &mut *L0TABLE_ADDRESS };
......@@ -521,7 +521,7 @@ pub extern "C" fn virt_to_phys(virtual_address: usize) -> usize {
}
pub fn map<S: PageSize>(virtual_address: usize, physical_address: usize, count: usize, flags: PageTableEntryFlags) {
debug_mem!("Mapping virtual address {:#X} to physical address {:#X} ({} pages)", virtual_address, physical_address, count);
trace!("Mapping virtual address {:#X} to physical address {:#X} ({} pages)", virtual_address, physical_address, count);
let range = get_page_range::<S>(virtual_address, count);
let root_pagetable = unsafe { &mut *L0TABLE_ADDRESS };
......
......@@ -519,7 +519,7 @@ pub extern "x86-interrupt" fn page_fault_handler(stack_frame: &mut irq::Exceptio
let root_pagetable = unsafe { &mut *PML4_ADDRESS };
let page = Page::<LargePageSize>::including_address(virtual_address);
debug_mem!("Mapping 2 MiB page for task heap ({:#X} => {:#X})", page.address(), physical_address);
trace!("Mapping 2 MiB page for task heap ({:#X} => {:#X})", page.address(), physical_address);
root_pagetable.map_page(
page,
physical_address,
......@@ -530,7 +530,7 @@ pub extern "x86-interrupt" fn page_fault_handler(stack_frame: &mut irq::Exceptio
// weak symbol "runtime_osinit"), we have to return a zeroed page.
unsafe {
if !runtime_osinit.is_null() {
debug_mem!("Go application detected, returning a zeroed page");
trace!("Go application detected, returning a zeroed page");
ptr::write_bytes(page.address() as *mut u8, 0, LargePageSize::SIZE);
}
}
......@@ -561,7 +561,7 @@ fn get_page_range<S: PageSize>(virtual_address: usize, count: usize) -> PageIter
}
pub fn get_page_table_entry<S: PageSize>(virtual_address: usize) -> Option<PageTableEntry> {
debug_mem!("Looking up Page Table Entry for {:#X}", virtual_address);
trace!("Looking up Page Table Entry for {:#X}", virtual_address);
let page = Page::<S>::including_address(virtual_address);
let root_pagetable = unsafe { &mut *PML4_ADDRESS };
......@@ -569,7 +569,7 @@ pub fn get_page_table_entry<S: PageSize>(virtual_address: usize) -> Option<PageT
}
pub fn get_physical_address<S: PageSize>(virtual_address: usize) -> usize {
debug_mem!("Getting physical address for {:#X}", virtual_address);
trace!("Getting physical address for {:#X}", virtual_address);
let page = Page::<S>::including_address(virtual_address);
let root_pagetable = unsafe { &mut *PML4_ADDRESS };
......@@ -606,7 +606,7 @@ pub extern "C" fn virt_to_phys(virtual_address: usize) -> usize {
}
pub fn map<S: PageSize>(virtual_address: usize, physical_address: usize, count: usize, flags: PageTableEntryFlags) {
debug_mem!("Mapping virtual address {:#X} to physical address {:#X} ({} pages)", virtual_address, physical_address, count);
trace!("Mapping virtual address {:#X} to physical address {:#X} ({} pages)", virtual_address, physical_address, count);
let range = get_page_range::<S>(virtual_address, count);
let root_pagetable = unsafe { &mut *PML4_ADDRESS };
......@@ -634,13 +634,13 @@ pub fn init() {
}
pub fn init_page_tables() {
debug_mem!("Create new view to the kernel space");
trace!("Create new view to the kernel space");
unsafe {
let pml4 = controlregs::cr3();
let pde = pml4 + 2*BasePageSize::SIZE as u64;
debug_mem!("Found PML4 at 0x{:x}", pml4);
trace!("Found PML4 at 0x{:x}", pml4);
// make sure that only the required areas are mapped
let start = pde + ((mm::kernel_end_address() >> (PAGE_MAP_BITS+PAGE_BITS)) * mem::size_of::<u64>()) as u64;
......
......@@ -42,6 +42,9 @@ extern crate spin;
#[cfg(target_arch = "x86_64")]
extern crate x86;
#[macro_use]
extern crate log;
// MODULES
#[macro_use]
mod macros;
......@@ -83,7 +86,7 @@ pub extern "C" fn sys_malloc(size: usize, align: usize) -> *mut u8 {
ptr = ALLOCATOR.alloc(layout);
}
debug_mem!("sys_malloc: allocate memory at 0x{:x} (size 0x{:x}, align 0x{:x})", ptr as usize, size, align);
trace!("sys_malloc: allocate memory at 0x{:x} (size 0x{:x}, align 0x{:x})", ptr as usize, size, align);
ptr
}
......@@ -97,7 +100,7 @@ pub extern "C" fn sys_realloc(ptr: *mut u8, size: usize, align: usize, new_size:
new_ptr = ALLOCATOR.realloc(ptr, layout, new_size);
}
debug_mem!("sys_realloc: resize memory at 0x{:x}, new address 0x{:x}", ptr as usize, new_ptr as usize);
trace!("sys_realloc: resize memory at 0x{:x}, new address 0x{:x}", ptr as usize, new_ptr as usize);
new_ptr
}
......@@ -106,7 +109,7 @@ pub extern "C" fn sys_realloc(ptr: *mut u8, size: usize, align: usize, new_size:
pub extern "C" fn sys_free(ptr: *mut u8, size: usize, align: usize) {
let layout: Layout = Layout::from_size_align(size, align).unwrap();
debug_mem!("sys_free: deallocate memory at 0x{:x} (size 0x{:x})", ptr as usize, size);
trace!("sys_free: deallocate memory at 0x{:x} (size 0x{:x})", ptr as usize, size);
unsafe {
ALLOCATOR.dealloc(ptr, layout);
......@@ -184,6 +187,7 @@ pub fn boot_processor_main() -> ! {
// Initialize the kernel and hardware.
unsafe { sections_init(); }
arch::message_output_init();
logging::init();
info!("Welcome to HermitCore-rs {} ({})", env!("CARGO_PKG_VERSION"), COMMIT_HASH);
arch::boot_processor_init();
......
// Copyright (c) 2017 Stefan Lankes, RWTH Aachen University
// Copyright (c) 2017-2019 Stefan Lankes, RWTH Aachen University
// 2017 Colin Finck, RWTH Aachen University
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
......@@ -6,58 +6,31 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
/// An enum representing the available verbosity levels of the logger.
#[allow(dead_code)]
#[derive(Copy, Clone)]
pub enum LogLevel {
/// Disable all our put messages
///
/// Designates without information
Disabled = 0,
/// The "error" level.
///
/// Designates very serious errors.
Error,
/// The "warn" level.
///
/// Designates hazardous situations.
Warning,
/// The "info" level.
///
/// Designates useful information.
Info,
// The "debug" level.
///
/// Designates lower priority information.
Debug,
// The "debug_mem" level.
///
/// Designates lower priority information of the memory management (high frequency!).
DebugMem,
}
use log::{Record, Level, Metadata, LevelFilter};
/// Data structures to filter kernel messages
pub struct KernelLogger {
pub log_level: LogLevel,
}
struct KernelLogger;
/// default logger to handle kernel messages
pub const LOGGER: KernelLogger = KernelLogger { log_level: LogLevel::Info };
static LOGGER: KernelLogger = KernelLogger;
impl log::Log for KernelLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= Level::Info
}
macro_rules! printlog {
($type:expr, $cmp_level:expr, $($arg:tt)+) => ({
let current_level = $crate::logging::LOGGER.log_level as u8;
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
println!("[{}][{}] {}", crate::arch::percore::core_id(), record.level(), record.args());
}
}
if current_level >= ($cmp_level as u8) {
println!("[{}][{}] {}", $crate::arch::percore::core_id(), $type, format_args!($($arg)+));
}
});
fn flush(&self) {}
}
/// Print formatted info text to our console, followed by a newline.
macro_rules! info {
($($arg:tt)+) => (printlog!("INFO", $crate::logging::LogLevel::Info, $($arg)+));
pub fn init() {
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(LevelFilter::Info)).unwrap();
}
macro_rules! infoheader {
......@@ -84,23 +57,3 @@ macro_rules! infofooter {
info!("");
});
}
/// Print formatted warnings to our console, followed by a newline.
macro_rules! warn {
($($arg:tt)+) => (printlog!("WARNING", $crate::logging::LogLevel::Warning, $($arg)+));
}
/// Print formatted warnings to our console, followed by a newline.
macro_rules! error {
($($arg:tt)+) => (printlog!("ERROR", $crate::logging::LogLevel::Error, $($arg)+));
}
/// Print formatted debug messages to our console, followed by a newline.
macro_rules! debug {
($($arg:tt)+) => (printlog!("DEBUG", $crate::logging::LogLevel::Debug, $($arg)+));
}
/// Print formatted debug messages to our console, followed by a newline.
macro_rules! debug_mem {
($($arg:tt)+) => (printlog!("DEBUG_MEM", $crate::logging::LogLevel::DebugMem, $($arg)+));
}
......@@ -49,7 +49,7 @@ impl HermitAllocatorInfo {
}
pub fn switch_to_system_allocator(&mut self) {
debug_mem!("Switching to the System Allocator");
trace!("Switching to the System Allocator");
self.is_bootstrapping = false;
}
}
......@@ -83,7 +83,7 @@ unsafe impl<'a> GlobalAlloc for &'a HermitAllocator {
/// An allocation using the always available Bootstrap Allocator.
unsafe fn alloc_bootstrap(layout: Layout) -> *mut u8 {
let ptr = &mut ALLOCATOR_INFO.heap[ALLOCATOR_INFO.index] as *mut u8;
debug_mem!("Allocating {} bytes at {:#X} using the Bootstrap Allocator", layout.size(), ptr as usize);
trace!("Allocating {} bytes at {:#X} using the Bootstrap Allocator", layout.size(), ptr as usize);
// Bump the heap index and align it up to the next BOOTSTRAP_HEAP_ALIGNMENT boundary.
ALLOCATOR_INFO.index = align_up!(ALLOCATOR_INFO.index + layout.size(), BOOTSTRAP_HEAP_ALIGNMENT);
......@@ -96,7 +96,7 @@ unsafe fn alloc_bootstrap(layout: Layout) -> *mut u8 {
/// An allocation using the initialized System Allocator.
fn alloc_system(layout: Layout) -> *mut u8 {
debug_mem!("Allocating {} bytes using the System Allocator", layout.size());
trace!("Allocating {} bytes using the System Allocator", layout.size());
let size = align_up!(layout.size(), BasePageSize::SIZE);
mm::allocate(size, true) as *mut u8
......@@ -104,7 +104,7 @@ fn alloc_system(layout: Layout) -> *mut u8 {
/// A deallocation using the initialized System Allocator.
fn dealloc_system(virtual_address: usize, layout: Layout) {
debug_mem!("Deallocating {} bytes at {:#X} using the System Allocator", layout.size(), virtual_address);
trace!("Deallocating {} bytes at {:#X} using the System Allocator", layout.size(), virtual_address);
let size = align_up!(layout.size(), BasePageSize::SIZE);
mm::deallocate(virtual_address, size);
......
......@@ -26,7 +26,7 @@ impl FreeList {
}
pub fn allocate(&mut self, size: usize) -> Result<usize, ()> {
debug_mem!("Allocating {} bytes from Free List {:#X}", size, self as *const Self as usize);
trace!("Allocating {} bytes from Free List {:#X}", size, self as *const Self as usize);
// Find a region in the Free List that has at least the requested size.
for node in self.list.iter() {
......@@ -98,7 +98,7 @@ impl FreeList {
}
pub fn allocate_aligned(&mut self, size: usize, alignment: usize) -> Result<usize, ()> {
debug_mem!("Allocating {} bytes from Free List {:#X} aligned to {} bytes", size, self as *const Self as usize, alignment);
trace!("Allocating {} bytes from Free List {:#X} aligned to {} bytes", size, self as *const Self as usize, alignment);
for node in self.list.iter() {
// Align up the start address of the current node in the list to the desired alignment.
......@@ -114,7 +114,7 @@ impl FreeList {
}
pub fn reserve(&mut self, address: usize, size: usize) -> Result<(), ()> {
debug_mem!("Reserving {} bytes at address {:#X} in Free List {:#X}", size, address, self as *const Self as usize);
trace!("Reserving {} bytes at address {:#X} in Free List {:#X}", size, address, self as *const Self as usize);
let end = address + size;
for node in self.list.iter() {
......@@ -130,7 +130,7 @@ impl FreeList {
}
pub fn deallocate(&mut self, address: usize, size: usize) {
debug_mem!("Deallocating {} bytes at {:#X} from Free List {:#X}", size, address, self as *const Self as usize);
trace!("Deallocating {} bytes at {:#X} from Free List {:#X}", size, address, self as *const Self as usize);
let end = address + size;
let mut iter = self.list.iter();
......
......@@ -33,7 +33,7 @@ impl NodePool {
return;
}
debug_mem!("Pool Maintenance!");
trace!("Pool Maintenance!");
self.maintenance_in_progress = true;
// Keep the desired minimum number of entries in the pool and move the rest into the local nodes_to_remove list.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment