use lazy_static::lazy_static; use spin::Mutex; use uart_16550::SerialPort; lazy_static! { pub static ref SERIAL1: Mutex = { let mut serial_port = unsafe { SerialPort::new(0x3f8) }; serial_port.init(); Mutex::new(serial_port) }; } #[doc(hidden)] pub fn _sprint(args: core::fmt::Arguments) { use core::fmt::Write; use x86_64::instructions::interrupts; interrupts::without_interrupts(|| { SERIAL1 .lock() .write_fmt(args) .expect("Printing to serial failed"); }); } #[macro_export] macro_rules! sprint { ($($arg:tt)*) => { $crate::serial::_sprint(format_args!($($arg)*)); } } #[macro_export] macro_rules! sprintln { () => ($crate::serial_print!("\n")); ($fmt:expr) => ($crate::sprint!(concat!($fmt, "\n"))); ($fmt:expr, $($arg:tt)*) => ($crate::sprint!(concat!($fmt, "\n"), $($arg)*)); }