feat: add pmm, add vmm, add allocator, create memory management foundation
This commit is contained in:
57
kernel/src/debug.rs
Normal file
57
kernel/src/debug.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
pub mod serial;
|
||||
|
||||
use embedded_graphics::pixelcolor::Rgb888;
|
||||
use embedded_graphics::prelude::RgbColor;
|
||||
|
||||
pub enum LogLevel {
|
||||
Info, Warn, Error,
|
||||
}
|
||||
|
||||
impl LogLevel {
|
||||
pub fn serial_color_code(&self) -> &str {
|
||||
match self {
|
||||
LogLevel::Info => "\x1b[32m",
|
||||
LogLevel::Warn => "\x1b[33m",
|
||||
LogLevel::Error => "\x1b[31m",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn console_color(&self) -> Rgb888 {
|
||||
match self {
|
||||
LogLevel::Info => Rgb888::GREEN,
|
||||
LogLevel::Warn => Rgb888::YELLOW,
|
||||
LogLevel::Error => Rgb888::RED,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! log {
|
||||
($console:expr, $level:expr, $module:expr, $($arg:tt)*) => {{
|
||||
use core::fmt::Write;
|
||||
use embedded_graphics::pixelcolor::Rgb888;
|
||||
|
||||
// Visual screen output
|
||||
$console.set_color($level.console_color());
|
||||
let _ = write!($console, "[ LOG ] ");
|
||||
|
||||
$console.set_color(Rgb888::WHITE);
|
||||
let _ = write!($console, "{:<6} | ", $module);
|
||||
let _ = writeln!($console, $($arg)*);
|
||||
|
||||
// Serial debug output
|
||||
let mut sp = unsafe { $crate::debug::serial::SerialPort::init() };
|
||||
let _ = writeln!(
|
||||
sp,
|
||||
"{}[{:>5}]\x1b[0m {:<8} | {}",
|
||||
$level.serial_color_code(),
|
||||
"LOG",
|
||||
$module,
|
||||
format_args!($($arg)*)
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! info { ($c:expr, $m:expr, $($p:tt)*) => { $crate::log!($c, $crate::debug::LogLevel::Info, $m, $($p)*) }; }
|
||||
#[macro_export] macro_rules! warn { ($c:expr, $m:expr, $($p:tt)*) => { $crate::log!($c, $crate::debug::LogLevel::Warn, $m, $($p)*) }; }
|
||||
#[macro_export] macro_rules! error { ($c:expr, $m:expr, $($p:tt)*) => { $crate::log!($c, $crate::debug::LogLevel::Error, $m, $($p)*) }; }
|
||||
Reference in New Issue
Block a user