diff --git a/src/main.rs b/src/main.rs index 83bce51..2a650ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,7 @@ static HELLO: &[u8] = b"Hello toto :3"; // looks for a function named `_start` by default #[unsafe(no_mangle)] pub extern "C" fn _start() -> ! { - use core::fmt::Write; - vga_buffer::WRITER.lock().write_str("TOTOTO !!!! :3").unwrap(); - write!(vga_buffer::WRITER.lock(), ", smoking cigarette in the shower when they get wet i just light another :{}", 3).unwrap(); + println!("smoking cigarettes in the shower\nwhen they get wet i just light another\n:{}", 3); loop {} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 8f71171..0bfd606 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -3,14 +3,6 @@ use volatile::Volatile; use lazy_static::lazy_static; use spin::Mutex; -lazy_static! { - pub static ref WRITER: Mutex = Mutex::new(Writer { - column_position: 0, - color_code: ColorCode::new(Color::Pink, Color::Black), - buffer: unsafe { &mut *(0xB8000 as *mut Buffer) }, - }); -} - #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)] @@ -72,6 +64,15 @@ pub struct Writer { buffer: &'static mut Buffer, } +lazy_static! { + pub static ref WRITER: Mutex = Mutex::new(Writer { + column_position: 0, + color_code: ColorCode::new(Color::Pink, Color::Black), + buffer: unsafe { &mut *(0xB8000 as *mut Buffer) }, + }); +} + + impl fmt::Write for Writer { fn write_str(&mut self, s: &str) -> fmt::Result { self.write_string(s); @@ -79,6 +80,24 @@ impl fmt::Write for Writer { } } +#[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(); +} + + impl Writer { pub fn write_byte(&mut self, byte: u8) { match byte { @@ -136,3 +155,4 @@ impl Writer { } } } +