Update some docs and add a little more code to main

This commit is contained in:
2025-02-28 22:45:31 +00:00
parent fdd556f742
commit 394e932b9c
7 changed files with 78 additions and 288 deletions
+18 -21
View File
@@ -1,12 +1,14 @@
/* use core::{
use crate::arch::x86_64::cpu::port::{inb, outb};
use core::{
fmt,
sync::atomic::{AtomicUsize, Ordering},
};
use spin::{Lazy, Mutex};
use x86_64::instructions::interrupts;
#[macro_export]
macro_rules! serial_print {
($($arg:tt)*) => ($crate::_serial_write(format_args!($($arg)*)));
($($arg:tt)*) => ($crate::io::serial::_serial_write(format_args!($($arg)*)));
}
#[macro_export]
@@ -15,10 +17,6 @@ macro_rules! serial_println {
($($arg:tt)*) => (serial_print!("{}\n", format_args!($($arg)*)));
}
use super::port::{inb, outb};
use x86_64::instructions::interrupts;
pub fn _serial_write(args: fmt::Arguments) {
use core::fmt::Write;
@@ -77,7 +75,7 @@ impl fmt::Write for Writer {
impl Writer {
unsafe fn write_success(&self) -> bool {
inb(PORT + 5) & 0x20 != 0
unsafe { inb(PORT + 5) & 0x20 != 0 }
}
pub fn write_byte(&self, data: u8) {
@@ -103,21 +101,21 @@ pub fn init() -> Result<(), &'static str> {
}
pub fn test() -> Result<(), &'static str> {
outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT, 0x03); // Set divisor to 3 (lo byte) 38400 baud
outb(PORT + 1, 0x00); // (hi byte)
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-bytethreshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(PORT, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
unsafe { outb(PORT + 1, 0x00) }; // Disable all interrupts
unsafe { outb(PORT + 3, 0x80) }; // Enable DLAB (set baud rate divisor)
unsafe { outb(PORT, 0x03) }; // Set divisor to 3 (lo byte) 38400 baud
unsafe { outb(PORT + 1, 0x00) }; // (hi byte)
unsafe { outb(PORT + 3, 0x03) }; // 8 bits, no parity, one stop bit
unsafe { outb(PORT + 2, 0xC7) }; // Enable FIFO, clear them, with 14-bytethreshold
unsafe { outb(PORT + 4, 0x0B) }; // IRQs enabled, RTS/DSR set
unsafe { outb(PORT + 4, 0x1E) }; // Set in loopback mode, test the serial chip
unsafe { outb(PORT, 0xAE) }; // Test serial chip (send byte 0xAE and check if serial returns same byte)
if inb(PORT) != 0xAE {
return Err("serial test failed");
if unsafe { inb(PORT) } != 0xAE {
return Err("Serial test failed");
}
outb(PORT + 4, 0x0F);
unsafe { outb(PORT + 4, 0x0F) };
Ok(())
}
@@ -143,7 +141,7 @@ impl Reader {
}
unsafe fn read_ready(&self) -> bool {
inb(PORT + 5) & 1 != 0
unsafe { inb(PORT + 5) & 1 != 0 }
}
pub fn read(&self) -> u8 {
@@ -153,4 +151,3 @@ impl Reader {
}
}
}
*/