From 4c9e93295c8be094ca8502fc337e975587c3a025 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Mon, 15 Jul 2024 16:44:37 +0800 Subject: [PATCH] add: console log support --- os/src/console.rs | 35 +++++++++++++++++++++++++++++++++++ os/src/main.rs | 6 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/os/src/console.rs b/os/src/console.rs index 09da39f..7d2b0cf 100644 --- a/os/src/console.rs +++ b/os/src/console.rs @@ -30,4 +30,39 @@ macro_rules! println { ($fmt: literal $(, $($arg: tt)+)?) => { $crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?)); } +} + +#[macro_export] +macro_rules! log_error { + ($fmt: literal $(, $($arg: tt)+)?) => { + $crate::console::print(format_args!(concat!("\x1b[31m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?)); + } +} + +#[macro_export] +macro_rules! log_warning { + ($fmt: literal $(, $($arg: tt)+)?) => { + $crate::console::print(format_args!(concat!("\x1b[93m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?)); + } +} + +#[macro_export] +macro_rules! log_information { + ($fmt: literal $(, $($arg: tt)+)?) => { + $crate::console::print(format_args!(concat!("\x1b[34m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?)); + } +} + +#[macro_export] +macro_rules! log_debug { + ($fmt: literal $(, $($arg: tt)+)?) => { + $crate::console::print(format_args!(concat!("\x1b[32m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?)); + } +} + +#[macro_export] +macro_rules! log_trace { + ($fmt: literal $(, $($arg: tt)+)?) => { + $crate::console::print(format_args!(concat!("\x1b[90m" ,concat!($fmt, "\x1b[0m\n")) $(, $($arg)+)?)); + } } \ No newline at end of file diff --git a/os/src/main.rs b/os/src/main.rs index 0418b54..7d69b5e 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -13,7 +13,11 @@ global_asm!(include_str!("entry.asm")); #[no_mangle] fn rust_main() -> ! { clear_bss(); - println!("Hello, rCore!"); + log_error!("Hello, rCore!"); + log_warning!("Hello, rCore!"); + log_information!("Hello, rCore!"); + log_debug!("Hello, rCore!"); + log_trace!("Hello, rCore!"); sbi::shutdown(false); }