⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

veridian_kernel/arch/x86_64/
serial.rs

1//! x86_64 serial port driver for kernel debugging output.
2//!
3//! Uses the `uart_16550` crate to interface with COM1 at I/O port 0x3F8.
4//! Provides `serial_print!` and `serial_println!` macros for formatted output.
5
6use lazy_static::lazy_static;
7use spin::Mutex;
8use uart_16550::SerialPort;
9
10lazy_static! {
11    pub static ref SERIAL1: Mutex<SerialPort> = {
12        // SAFETY: 0x3F8 is the well-known I/O port address for COM1 (16550 UART).
13        let mut serial_port = unsafe { SerialPort::new(0x3F8) };
14        serial_port.init();
15        Mutex::new(serial_port)
16    };
17}
18
19#[doc(hidden)]
20pub fn _print(args: ::core::fmt::Arguments) {
21    use core::fmt::Write;
22
23    use x86_64::instructions::interrupts;
24
25    interrupts::without_interrupts(|| {
26        SERIAL1
27            .lock()
28            .write_fmt(args)
29            .expect("Printing to serial failed");
30    });
31}
32
33// Alias for compatibility
34#[doc(hidden)]
35pub fn _serial_print(args: ::core::fmt::Arguments) {
36    _print(args);
37}