mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Implement print!/println! macros
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -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 {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user