fix: bugs
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use core::arch::asm;
|
||||
use core::fmt::Write;
|
||||
use crate::mem::allocator::Locked;
|
||||
|
||||
pub struct SerialPort(u16);
|
||||
|
||||
@@ -7,16 +9,14 @@ impl SerialPort {
|
||||
|
||||
pub unsafe fn init() -> Self {
|
||||
let port = Self::COM1;
|
||||
// В новых версиях Rust даже внутри unsafe fn
|
||||
// вызовы других unsafe функций требуют явного блока
|
||||
unsafe {
|
||||
outb(port + 1, 0x00); // Disable interrupts
|
||||
outb(port + 3, 0x80); // Enable DLAB
|
||||
outb(port + 0, 0x03); // Divisor 3 (38400 baud)
|
||||
outb(port + 1, 0x00);
|
||||
outb(port + 3, 0x03); // 8 bits, no parity, 1 stop bit
|
||||
outb(port + 2, 0xC7); // Enable FIFO
|
||||
outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set
|
||||
outb(port + 3, 0x80);
|
||||
outb(port + 0, 0x03);
|
||||
outb(port + 1, 0x00);
|
||||
outb(port + 3, 0x03);
|
||||
outb(port + 2, 0xC7);
|
||||
outb(port + 4, 0x0B);
|
||||
}
|
||||
SerialPort(port)
|
||||
}
|
||||
@@ -38,6 +38,20 @@ impl core::fmt::Write for SerialPort {
|
||||
}
|
||||
}
|
||||
|
||||
static SERIAL_PORT: Locked<Option<SerialPort>> = Locked::new(None);
|
||||
|
||||
pub fn init_global() {
|
||||
let mut guard = SERIAL_PORT.lock();
|
||||
*guard = Some(unsafe { SerialPort::init() });
|
||||
}
|
||||
|
||||
pub fn write_global(args: core::fmt::Arguments) {
|
||||
let mut guard = SERIAL_PORT.lock();
|
||||
if let Some(ref mut sp) = *guard {
|
||||
let _ = sp.write_fmt(args);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn outb(port: u16, val: u8) {
|
||||
unsafe {
|
||||
asm!("out dx, al", in("dx") port, in("al") val, options(nomem, nostack, preserves_flags));
|
||||
|
||||
Reference in New Issue
Block a user