diff options
Diffstat (limited to 'kernel/src/io')
-rw-r--r-- | kernel/src/io/mod.rs | 2 | ||||
-rw-r--r-- | kernel/src/io/qemu.rs | 15 | ||||
-rw-r--r-- | kernel/src/io/serial.rs | 53 | ||||
-rw-r--r-- | kernel/src/io/vga_text.rs | 1 |
4 files changed, 52 insertions, 19 deletions
diff --git a/kernel/src/io/mod.rs b/kernel/src/io/mod.rs index 8a0652e..9ac924a 100644 --- a/kernel/src/io/mod.rs +++ b/kernel/src/io/mod.rs @@ -1,3 +1,3 @@ +pub mod qemu; pub mod serial; pub mod vga_text; - diff --git a/kernel/src/io/qemu.rs b/kernel/src/io/qemu.rs new file mode 100644 index 0000000..8b01885 --- /dev/null +++ b/kernel/src/io/qemu.rs @@ -0,0 +1,15 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum QemuExitCode { + Success = 0x10, // The actual exit code is (value << 1) | 1. + Failed = 0x11, +} + +pub fn exit_qemu(exit_code: QemuExitCode) { + use x86_64::instructions::port::Port; + + unsafe { + let mut port = Port::new(0xf4); + port.write(exit_code as u32); + } +} diff --git a/kernel/src/io/serial.rs b/kernel/src/io/serial.rs index e1d4660..2a3bae8 100644 --- a/kernel/src/io/serial.rs +++ b/kernel/src/io/serial.rs @@ -1,25 +1,42 @@ -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u32)] -pub enum QemuExitCode { - Success = 0x10, // The actual exit code is (value << 1) | 1. - Failed = 0x11, +use spin::Mutex; +use uart_16550::SerialPort; + +/*lazy_static! { + pub static ref SERIAL1: Mutex<SerialPort> = { + let mut serial_port = unsafe { SerialPort::new(0x3F8) }; + serial_port.init(); + Mutex::new(serial_port) + }; +}*/ +const SERIAL_IO_PORT: u16 = 0x3F8; + +static CONNECTION: Mutex<Serial> = Mutex::new(Serial { + initialized: false, + port: unsafe { SerialPort::new(SERIAL_IO_PORT) }, +}); + +struct Serial { + pub initialized: bool, + pub port: SerialPort, } -pub fn exit_qemu(exit_code: QemuExitCode) { - use x86_64::instructions::port::Port; +pub struct SerialStream {} - unsafe { - let mut port = Port::new(0xf4); - port.write(exit_code as u32); +impl SerialStream { + pub fn new() -> Self { + SerialStream {} } } -fn trivial_assertion() { - use crate::io::vga_text::OStream; - let mut stdout = OStream::new(); - stdout.clear(); - - stdout.print(b"trivial assertion... "); - assert_eq!(0, 1); - stdout.print(b"[ok]"); +impl core::fmt::Write for SerialStream { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + let mut guard = CONNECTION.lock(); + if !guard.initialized { + unsafe { + guard.port.init(); + } + guard.initialized = true; + } + guard.port.write_str(s) + } } diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs index 34f13a8..fddb3e1 100644 --- a/kernel/src/io/vga_text.rs +++ b/kernel/src/io/vga_text.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] #[repr(u8)] pub enum Color { Black = 0, |