implemented println! macro

This commit is contained in:
clizia 2025-08-27 01:05:47 +02:00
parent f94b8537cf
commit 16e1bc308f
2 changed files with 29 additions and 11 deletions

View file

@ -3,14 +3,6 @@ use volatile::Volatile;
use lazy_static::lazy_static;
use spin::Mutex;
lazy_static! {
pub static ref WRITER: Mutex<Writer> = 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<Writer> = 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 {
}
}
}