From 791738aa2691e7fe607f708d3c671c9462b034dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 26 Jan 2026 15:30:57 +0100 Subject: [PATCH] build(deps): update uart_16550 to 0.5 --- Cargo.lock | 32 +++++--------------------------- Cargo.toml | 2 +- src/arch/x86_64/kernel/serial.rs | 24 +++++++++++++----------- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 042dd89d52..10976ab026 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -858,7 +858,7 @@ dependencies = [ "pci-ids", "pci_types", "rand_chacha", - "raw-cpuid 11.6.0", + "raw-cpuid", "riscv", "sbi-rt", "semihosting", @@ -1586,15 +1586,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" -[[package]] -name = "raw-cpuid" -version = "10.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "raw-cpuid" version = "11.6.0" @@ -2015,7 +2006,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa1699c0079cb7ff77b57fd429bcfa87b1220898bb303e0e45f75789778a376d" dependencies = [ - "raw-cpuid 11.6.0", + "raw-cpuid", "x86_64", ] @@ -2027,13 +2018,11 @@ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" [[package]] name = "uart_16550" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94d293f51425981fdb1b766beae254dbb711a17e8c4b549dc69b9b7ee0d478d5" +version = "0.5.0" +source = "git+https://github.com/rust-osdev/uart_16550.git#c17d30c5b268abe112f37d2b59593a84d49fd780" dependencies = [ "bitflags 2.11.0", - "rustversion", - "x86", + "embedded-io", ] [[package]] @@ -2489,17 +2478,6 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" -[[package]] -name = "x86" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385" -dependencies = [ - "bit_field", - "bitflags 1.3.2", - "raw-cpuid 10.7.0", -] - [[package]] name = "x86_64" version = "0.15.4" diff --git a/Cargo.toml b/Cargo.toml index aa5818308c..8a2367934e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -366,7 +366,7 @@ features = [ [target.'cfg(target_arch = "x86_64")'.dependencies] free-list = { version = "0.3", features = ["x86_64"] } raw-cpuid = "11" -uart_16550 = "0.4" +uart_16550 = { git = "https://github.com/rust-osdev/uart_16550.git", features = ["embedded-io"] } x86_64 = "0.15" memory_addresses = { version = "0.3", default-features = false, features = [ "x86_64", diff --git a/src/arch/x86_64/kernel/serial.rs b/src/arch/x86_64/kernel/serial.rs index 7803b9628d..a303910252 100644 --- a/src/arch/x86_64/kernel/serial.rs +++ b/src/arch/x86_64/kernel/serial.rs @@ -2,6 +2,8 @@ use alloc::collections::VecDeque; use embedded_io::{ErrorType, Read, ReadReady, Write}; use hermit_sync::{InterruptTicketMutex, Lazy}; +use uart_16550::backend::PioBackend; +use uart_16550::{Config, Uart16550}; #[cfg(feature = "pci")] use crate::arch::x86_64::kernel::interrupts; @@ -16,7 +18,7 @@ static UART_DEVICE: Lazy> = Lazy::new(|| unsafe { InterruptTicketMutex::new(UartDevice::new()) }); struct UartDevice { - pub uart: uart_16550::SerialPort, + pub uart: Uart16550, pub buffer: VecDeque, } @@ -27,8 +29,11 @@ impl UartDevice { .serial_port_base .unwrap() .get(); - let mut uart = unsafe { uart_16550::SerialPort::new(base) }; - uart.init(); + let mut uart = unsafe { Uart16550::new_port(base).unwrap() }; + uart.init(Config::default()).ok(); + // Once we have a fallback destination for output, + // we should log any error above and run + // `test_loopback` and `check_connected` here. Self { uart, @@ -64,12 +69,8 @@ impl ReadReady for SerialDevice { impl Write for SerialDevice { fn write(&mut self, buf: &[u8]) -> Result { let mut guard = UART_DEVICE.lock(); - - for &data in buf { - guard.uart.send(data); - } - - Ok(buf.len()) + let n = guard.uart.write(buf)?; + Ok(n) } fn flush(&mut self) -> Result<(), Self::Error> { @@ -81,8 +82,9 @@ impl Write for SerialDevice { pub(crate) fn get_serial_handler() -> (InterruptLine, fn()) { fn serial_handler() { let mut guard = UART_DEVICE.lock(); - if let Ok(c) = guard.uart.try_receive() { - guard.buffer.push_back(c); + + while let Ok(byte) = guard.uart.try_receive_byte() { + guard.buffer.push_back(byte); } drop(guard);