rusty_os/
serial.rs

1use lazy_static::lazy_static;
2use spin::Mutex;
3use uart_16550::SerialPort;
4
5lazy_static! {
6    pub static ref SERIAL1: Mutex<SerialPort> = {
7        let mut serial_port = unsafe { SerialPort::new(0x3F8) };
8        serial_port.init();
9        Mutex::new(serial_port)
10    };
11}
12
13#[doc(hidden)]
14pub fn _print(args: ::core::fmt::Arguments) {
15    use core::fmt::Write;
16    SERIAL1
17        .lock()
18        .write_fmt(args)
19        .expect("Printed to serial failed");
20}
21
22// Prints to the host through the serial interface
23#[macro_export]
24macro_rules! serial_print {
25    ($($arg:tt)*) => {
26        $crate::serial::_print(format_args!($($arg)*));
27    };
28}
29
30// Prints to the host through the serial interface, appending a newline.
31#[macro_export]
32macro_rules! serial_println {
33    () => ($crate::serial_print!("\n"));
34    ($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
35    ($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
36        concat!($fmt, "\n"), $($arg)*));
37}