File size: 864 Bytes
dcbeeb2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | use core::fmt;
use spin::Mutex;
use uart_16550::SerialPort;
pub static SERIAL1: Mutex<Option<SerialPort>> = Mutex::new(None);
pub fn init() {
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
serial_port.init();
*SERIAL1.lock() = Some(serial_port);
}
#[doc(hidden)]
pub fn _print(args: fmt::Arguments) {
use core::fmt::Write;
use x86_64::instructions::interrupts;
interrupts::without_interrupts(|| {
if let Some(ref mut serial) = *SERIAL1.lock() {
serial.write_fmt(args).expect("Printing to serial failed");
}
});
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => {
$crate::drivers::serial::_print(format_args!($($arg)*))
};
}
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}
|