From 2430b7b2a7354c31a9b58b553a75c3a685b2e2ce Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 6 Sep 2026 21:11:34 +0800 Subject: uart: more elegant init earlyprintk: actually init COM1, not sure why the other coms arent working --- kernel/src/io/output/serial/uart_16550.rs | 32 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'kernel/src/io') diff --git a/kernel/src/io/output/serial/uart_16550.rs b/kernel/src/io/output/serial/uart_16550.rs index acdebda..2df3668 100644 --- a/kernel/src/io/output/serial/uart_16550.rs +++ b/kernel/src/io/output/serial/uart_16550.rs @@ -1,8 +1,12 @@ +use core::array; + +use strum::{EnumIter, IntoEnumIterator}; use uart_16550::{ Config, Uart16550Tty, Uart16550TtyError, backend::{PioBackend, PortIoAddress}, }; +#[derive(EnumIter)] #[repr(u16)] // TODO: parse & validate via acpi alors scratch enum SerialPortAddress { @@ -35,23 +39,15 @@ impl Uart16550 { // TODO: more type safe mut config: [Option; 4], ) -> Result> { - unsafe { - Ok(Self { - coms: [ - init_port(&mut config[0], SerialPortAddress::COM1)?, - init_port(&mut config[1], SerialPortAddress::COM2)?, - init_port(&mut config[2], SerialPortAddress::COM3)?, - init_port(&mut config[3], SerialPortAddress::COM4)?, - ], - }) - } - } -} + let mut addrs = SerialPortAddress::iter(); -#[inline(always)] -unsafe fn init_port( - cfg: &mut Option, - addr: SerialPortAddress, -) -> Result>, Uart16550TtyError> { - cfg.take().map(|c| unsafe { Uart16550Tty::new_port(addr.into(), c) }).transpose() + Ok(Self { + coms: array::try_from_fn(|i| { + config[i] + .take() + .map(|c| unsafe { Uart16550Tty::new_port(addrs.next().unwrap().into(), c) }) + .transpose() + })?, + }) + } } -- cgit v1.2.3