Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #67 from popcorn-kernel/log-system
Browse files Browse the repository at this point in the history
Simple log system
  • Loading branch information
SatoTsukasaCode authored Oct 23, 2023
2 parents ea877da + 1ab68eb commit 73bfdf7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use popcorn::{
hlt_loop, init,
low_level::vga_buffer::{clear_screen, Color},
print_with_colors, println,
userspace::output::MessageToVga,
userspace::output::MessageToVga, log, warn, error,
};
entry_point!(kernel_main);

Expand All @@ -26,7 +26,9 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
MessageToVga::new(Color::LightBlue, Color::Black, "Popcorn Kernel!")
);
println!(); //Newline being other than black and white caused a bug with the cursor
log!("Initializing...");
init(boot_info);
log!("Initialized!");

hlt_loop();
}
43 changes: 43 additions & 0 deletions src/userspace/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,49 @@ macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}

/// log!("text") - this will get the file that called this, and say it as [file_name] <text>
#[macro_export]
macro_rules! log {
($($arg:tt)*) => (
$crate::print_with_colors!(
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightBlue, $crate::low_level::vga_buffer::Color::Black, "["),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::Black, $crate::low_level::vga_buffer::Color::LightGreen, core::file!()),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightBlue, $crate::low_level::vga_buffer::Color::Black, "] "),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::White, $crate::low_level::vga_buffer::Color::Black, $($arg)*)
);
$crate::println!();
)
}

/// warn!("text") - this will get the file that called this, and say it as [file_name] <text>
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => (
$crate::print_with_colors!(
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightBlue, $crate::low_level::vga_buffer::Color::Black, "["),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::Black, $crate::low_level::vga_buffer::Color::Yellow, core::file!()),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightBlue, $crate::low_level::vga_buffer::Color::Black, "] "),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::Yellow, $crate::low_level::vga_buffer::Color::Black, $($arg)*)
);
$crate::println!();
)
}

/// error!("text") - this will get the file that called this, and say it as [file_name] <text>
#[macro_export]
macro_rules! error {
($($arg:tt)*) => (
$crate::print_with_colors!(
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightBlue, $crate::low_level::vga_buffer::Color::Black, "["),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::Black, $crate::low_level::vga_buffer::Color::LightRed, core::file!()),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightBlue, $crate::low_level::vga_buffer::Color::Black, "] "),
$crate::userspace::output::MessageToVga::new($crate::low_level::vga_buffer::Color::LightRed, $crate::low_level::vga_buffer::Color::Black, $($arg)*)
);
$crate::println!();
)
}

pub struct MessageToVga<'a> {
foreground: Color,
background: Color,
Expand Down

0 comments on commit 73bfdf7

Please sign in to comment.