28
kernel/src/logger/serial.rs
Normal file
28
kernel/src/logger/serial.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use core::fmt;
|
||||
|
||||
pub struct SerialPort {
|
||||
port: uart_16550::SerialPort,
|
||||
}
|
||||
|
||||
impl SerialPort {
|
||||
/// # Safety
|
||||
///
|
||||
/// unsafe because this function must only be called once
|
||||
pub unsafe fn init() -> Self {
|
||||
let mut port = unsafe { uart_16550::SerialPort::new(0x3F8) };
|
||||
port.init();
|
||||
Self { port }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for SerialPort {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for char in s.bytes() {
|
||||
match char {
|
||||
b'\n' => self.port.write_str("\r\n").unwrap(),
|
||||
byte => self.port.send(byte),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user