Download kernel/src/drivers/serial.rs from Jaswanth-2008/AeroOS: direct link, hf CLI and curl.
- Browser
- Download file 864 Bytes
-
https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/drivers/serial.rs
- Command line
-
hf download hf://Jaswanth-2008/AeroOS/kernel/src/drivers/serial.rs
-
curl -L -o serial.rs https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/drivers/serial.rs
864 Bytes
| 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); | |
| } | |
| 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_rules! print { | |
| ($($arg:tt)*) => { | |
| $crate::drivers::serial::_print(format_args!($($arg)*)) | |
| }; | |
| } | |
| macro_rules! println { | |
| () => ($crate::print!("\n")); | |
| ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*))); | |
| } | |