Implement print!/println! macros

This commit is contained in:
Philipp Oppermann
2019-01-25 13:22:33 +01:00
parent c1e3fa57c6
commit c43d6191c5
2 changed files with 18 additions and 9 deletions

View File

@@ -7,15 +7,7 @@ mod vga_buffer;
#[no_mangle] #[no_mangle]
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
use core::fmt::Write; println!("Hello World{}", "!");
vga_buffer::WRITER.lock().write_str("Hello again").unwrap();
write!(
vga_buffer::WRITER.lock(),
", some numbers: {} {}",
42,
1.337
)
.unwrap();
loop {} loop {}
} }

View File

@@ -123,3 +123,20 @@ impl fmt::Write for Writer {
Ok(()) Ok(())
} }
} }
#[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();
}