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

Simple log system #67

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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