akern-gkgoat-fork/ableos/src/arch/x86_64/drivers/serial.rs

37 lines
938 B
Rust
Raw Normal View History

use spin::{Lazy, Mutex};
2021-11-16 06:09:27 +00:00
use uart_16550::SerialPort;
pub static SERIAL1: Lazy<Mutex<SerialPort>> = Lazy::new(|| {
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
serial_port.init();
Mutex::new(serial_port)
});
2021-11-16 06:09:27 +00:00
#[doc(hidden)]
pub fn _print(args: ::core::fmt::Arguments) {
2022-02-18 18:25:54 +00:00
use core::fmt::Write;
2022-07-31 10:22:39 +00:00
// /*
2022-02-18 18:25:54 +00:00
SERIAL1
.lock()
.write_fmt(args)
.expect("Printing to serial failed");
2022-07-31 10:22:39 +00:00
// */
2021-11-16 06:09:27 +00:00
}
2022-04-11 22:23:11 +00:00
2021-11-16 06:09:27 +00:00
/// Prints to the host through the serial interface.
#[macro_export]
2022-03-11 23:13:41 +00:00
macro_rules! sprint {
2021-11-16 06:09:27 +00:00
($($arg:tt)*) => {
$crate::arch::drivers::serial::_print(format_args!($($arg)*));
};
}
2022-04-11 22:23:11 +00:00
2021-11-16 06:09:27 +00:00
/// Prints to the host through the serial interface, appending a newline.
#[macro_export]
2022-03-11 23:13:41 +00:00
macro_rules! sprintln {
() => ($crate::sprint!("\n"));
($fmt:expr) => ($crate::sprint!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => ($crate::sprint!(
2021-11-16 06:09:27 +00:00
concat!($fmt, "\n"), $($arg)*));
}