summaryrefslogtreecommitdiff
path: root/kernel/src/io/serial.rs
blob: 3f661e934d6ef19341f8f7dacf0af653c46da7ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use lazy_static::lazy_static;
use spin::Mutex;
use uart_16550::SerialPort;

const SERIAL_IO_PORT: u16 = 0x3F8;

lazy_static! {
    pub static ref SERIAL1: Mutex<SerialPort> = {
        let mut serial_port = unsafe { SerialPort::new(SERIAL_IO_PORT) };
        serial_port.init();
        Mutex::new(serial_port)
    };
}

pub struct SerialStream {}

impl SerialStream {
    pub fn new() -> Self {
        SerialStream {}
    }
}

impl core::fmt::Write for SerialStream {
    fn write_str(&mut self, s: &str) -> core::fmt::Result {
        SERIAL1.lock().write_str(s)
    }
}