diff --git a/moon/src/arch/x86_64/io.rs b/moon/src/arch/x86_64/io.rs index cfde91f5..23304c22 100644 --- a/moon/src/arch/x86_64/io.rs +++ b/moon/src/arch/x86_64/io.rs @@ -1,35 +1,32 @@ #![cfg(target_arch = "x86_64")] #![allow(dead_code)] +use x86_64::instructions::port::Port; +use spin::Mutex; + pub const COM1: u16 = 0x3f8; +static SERIAL_DATA: Mutex> = Mutex::new(Port::new(COM1)); + use core::arch::asm; -pub unsafe fn outportb(port: u16, value: u8) -> () { - asm!("out dx, al", in("al") value, in("dx") port); -} - -pub unsafe fn inportb(port: u16) -> u8 { - let value: u8; - asm!("in al, dx", out("al") value, in("dx") port); - return value; -} - pub unsafe fn io_delay() -> () { - outportb(0x80,0); + let mut delay_port: Port = Port::new(0x80); + delay_port.write(0); } pub mod serial { use super::*; unsafe fn wait() -> () { - while (inportb(COM1 + 5) & 0x20) == 0 { + let mut port: Port = Port::new(COM1 + 5); + while (port.read() & 0x20) == 0 { asm!("pause"); } } pub fn putchar(c: u8) -> () { unsafe { wait(); } - unsafe { outportb(COM1, c); } + unsafe { SERIAL_DATA.lock().write(c); } } } \ No newline at end of file