52 lines
1.0 KiB
Rust
52 lines
1.0 KiB
Rust
use core::arch::asm;
|
|
|
|
const SERIAL_COM1: u16 = 0x3F8;
|
|
|
|
pub unsafe fn init() {
|
|
outb(SERIAL_COM1 + 1, 0x00); // Disable interrupts
|
|
|
|
outb(SERIAL_COM1 + 3, 0x80);
|
|
|
|
outb(SERIAL_COM1, 0x03); // 38400 baud (divisor = 3)
|
|
outb(SERIAL_COM1 + 1, 0x00);
|
|
|
|
outb(SERIAL_COM1 + 3, 0x03);
|
|
|
|
outb(SERIAL_COM1 + 2, 0xC7);
|
|
|
|
outb(SERIAL_COM1 + 4, 0x0B);
|
|
}
|
|
|
|
pub unsafe fn write_byte(byte: u8) {
|
|
while (inb(SERIAL_COM1 + 5) & 0x20) == 0 {}
|
|
outb(SERIAL_COM1, byte);
|
|
}
|
|
|
|
pub unsafe fn write_bytes(bytes: &[u8]) {
|
|
for &byte in bytes {
|
|
write_byte(byte);
|
|
}
|
|
}
|
|
|
|
pub unsafe fn write_str(string: &str) {
|
|
write_bytes(string.as_bytes());
|
|
}
|
|
|
|
unsafe fn outb(port: u16, value: u8) {
|
|
asm!(
|
|
"out dx, al",
|
|
in("dx") port,
|
|
in("al") value,
|
|
options(nostack, nomem, preserves_flags)
|
|
);
|
|
}
|
|
|
|
unsafe fn inb(port: u16) -> u8 {
|
|
let value: u8;
|
|
|
|
unsafe {
|
|
asm!("in al, dx",in("dx") port,out("al") value,options(nostack, nomem, preserves_flags));
|
|
}
|
|
|
|
value
|
|
} |