Kernel: Use x86_64::instructions::port for port IO

This commit is contained in:
apio 2022-11-01 12:46:21 +01:00
parent 3477df7bde
commit 793b24a994

View File

@ -1,35 +1,32 @@
#![cfg(target_arch = "x86_64")] #![cfg(target_arch = "x86_64")]
#![allow(dead_code)] #![allow(dead_code)]
use x86_64::instructions::port::Port;
use spin::Mutex;
pub const COM1: u16 = 0x3f8; pub const COM1: u16 = 0x3f8;
static SERIAL_DATA: Mutex<Port<u8>> = Mutex::new(Port::new(COM1));
use core::arch::asm; 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() -> () { pub unsafe fn io_delay() -> () {
outportb(0x80,0); let mut delay_port: Port<u8> = Port::new(0x80);
delay_port.write(0);
} }
pub mod serial { pub mod serial {
use super::*; use super::*;
unsafe fn wait() -> () { unsafe fn wait() -> () {
while (inportb(COM1 + 5) & 0x20) == 0 { let mut port: Port<u8> = Port::new(COM1 + 5);
while (port.read() & 0x20) == 0 {
asm!("pause"); asm!("pause");
} }
} }
pub fn putchar(c: u8) -> () { pub fn putchar(c: u8) -> () {
unsafe { wait(); } unsafe { wait(); }
unsafe { outportb(COM1, c); } unsafe { SERIAL_DATA.lock().write(c); }
} }
} }