From ec115c43c4fa555272dd874b4d66ff3fa610e9ce Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 11 Jul 2019 01:46:28 -0700 Subject: [PATCH] Add kernel print macros --- src/main.rs | 7 ++----- src/vga_buffer.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7e63916..aac6ace 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![no_std] #![no_main] +#[macro_use] mod vga_buffer; use core::panic::PanicInfo; @@ -12,11 +13,7 @@ fn panic(_info: &PanicInfo) -> !{ #[no_mangle] pub extern "C" fn _start() -> ! { - - use core::fmt::Write; - vga_buffer::WRITER.lock().write_str("Gamarjoba, munde").unwrap(); - write!(vga_buffer::WRITER.lock(), ", hella {} bro", 2).unwrap(); - + println!("Gamarjoba, munde: {}", 1); loop {} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 0524e93..8c13f4a 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -3,6 +3,24 @@ use core::fmt; use spin::Mutex; use lazy_static::lazy_static; + +#[macro_export] +macro_rules! print { + ($($arg:tt)*) => ($crate::vga_buffer::_print(format_args!($($arg)*))); +} + +#[macro_export] +macro_rules! println { + () => ($crate::print!("\n")); + ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*))); +} + +#[doc(hidden)] +pub fn _print(args: fmt::Arguments) { + use core::fmt::Write; + WRITER.lock().write_fmt(args).unwrap(); +} + #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)]