From 68c8647760dd0c72dc7df64c401bc2f9e9be3e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 16:50:09 +0200 Subject: [PATCH 1/3] feat(env): drop support for non-FDT bootargs --- src/arch/aarch64/kernel/mod.rs | 6 +----- src/arch/riscv64/kernel/mod.rs | 4 ---- src/arch/x86_64/kernel/mod.rs | 8 -------- src/env.rs | 4 +--- 4 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 5a00d10ea0..319a91bd78 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -17,8 +17,8 @@ pub mod systemtime; use alloc::alloc::alloc; use core::alloc::Layout; use core::arch::global_asm; +use core::ptr; use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering}; -use core::{ptr, str}; pub(crate) use self::interrupts::wakeup_core; pub(crate) use self::processor::set_oneshot_timer; @@ -61,10 +61,6 @@ pub fn get_processor_count() -> u32 { 1 } -pub fn args() -> Option<&'static str> { - None -} - /// Real Boot Processor initialization as soon as we have put the first Welcome message on the screen. #[cfg(target_os = "none")] pub fn boot_processor_init() { diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 4b8ad9fb97..5b8cf8b9c5 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -59,10 +59,6 @@ pub fn get_processor_count() -> u32 { 1 } -pub fn args() -> Option<&'static str> { - None -} - pub fn get_hart_mask() -> u64 { HART_MASK.load(Ordering::Relaxed) } diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 8f1c32a125..fe97ded0ce 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -63,14 +63,6 @@ pub fn is_uhyve_with_pci() -> bool { ) } -pub fn args() -> Option<&'static str> { - match env::boot_info().platform_info { - PlatformInfo::Multiboot { command_line, .. } - | PlatformInfo::LinuxBootParams { command_line, .. } => command_line, - _ => None, - } -} - /// Real Boot Processor initialization as soon as we have put the first Welcome message on the screen. #[cfg(target_os = "none")] pub fn boot_processor_init() { diff --git a/src/env.rs b/src/env.rs index b865952201..3ae43bf010 100644 --- a/src/env.rs +++ b/src/env.rs @@ -13,8 +13,6 @@ use hermit_entry::boot_info::{BootInfo, PlatformInfo, RawBootInfo}; use hermit_sync::OnceCell; use memory_addresses::PhysAddr; -use crate::arch::kernel; - static BOOT_INFO: OnceCell = OnceCell::new(); pub fn boot_info() -> &'static BootInfo { @@ -92,7 +90,7 @@ impl Default for Cli { RandomState::with_seeds(0, 0, 0, 0), ); - let args = kernel::args().or_else(fdt_args).unwrap_or_default(); + let args = fdt_args().unwrap_or_default(); info!("bootargs = {args}"); let words = shell_words::split(args).unwrap(); From 5510f4ff38e334fa81ffb4c5c18c7aec3e2139f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 23 Jun 2026 13:46:42 +0200 Subject: [PATCH 2/3] feat(serial): hardcode addresses --- src/arch/aarch64/kernel/serial.rs | 26 +++++++++++++------------- src/arch/x86_64/kernel/serial.rs | 8 ++------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/arch/aarch64/kernel/serial.rs b/src/arch/aarch64/kernel/serial.rs index efb0fa32f6..d39921e08e 100644 --- a/src/arch/aarch64/kernel/serial.rs +++ b/src/arch/aarch64/kernel/serial.rs @@ -1,8 +1,9 @@ use alloc::collections::vec_deque::VecDeque; -use core::num::NonZero; -use core::ptr::NonNull; +use core::ptr::{self, NonNull}; -use arm_pl011_uart::{DataBits, Interrupts, LineConfig, Parity, StopBits, Uart, UniqueMmioPointer}; +use arm_pl011_uart::{ + DataBits, Interrupts, LineConfig, PL011Registers, Parity, StopBits, Uart, UniqueMmioPointer, +}; use embedded_io::{ErrorType, Read, ReadReady, Write}; use hermit_sync::{InterruptTicketMutex, Lazy}; @@ -18,16 +19,15 @@ pub(crate) struct UartDevice { impl UartDevice { pub fn new() -> Self { - let base = crate::env::boot_info() - .hardware_info - .serial_port_base - .unwrap(); - let base = NonZero::try_from(base).unwrap(); - let base = NonNull::with_exposed_provenance(base); - - let uart_pointer = unsafe { UniqueMmioPointer::new(base) }; - - let mut uart = Uart::new(uart_pointer); + // The loader maps the serial port to 0x1000. Eventually, the kernel + // should take care of the initial page tables. Until then, we hardcode + // the value to slowly move away from the Hermit-specific boot info + // struct. + let ptr = ptr::with_exposed_provenance_mut::(0x1000); + let ptr = NonNull::new(ptr).unwrap(); + let ptr = unsafe { UniqueMmioPointer::new(ptr) }; + + let mut uart = Uart::new(ptr); let line_config = LineConfig { data_bits: DataBits::Bits8, diff --git a/src/arch/x86_64/kernel/serial.rs b/src/arch/x86_64/kernel/serial.rs index 0e6eea22e4..70e37de0bb 100644 --- a/src/arch/x86_64/kernel/serial.rs +++ b/src/arch/x86_64/kernel/serial.rs @@ -22,12 +22,8 @@ struct UartDevice { impl UartDevice { pub unsafe fn new() -> Self { - let base = crate::env::boot_info() - .hardware_info - .serial_port_base - .unwrap() - .get(); - let mut uart = unsafe { Uart16550::new_port(base).unwrap() }; + let base_port = 0x3f8; + let mut uart = unsafe { Uart16550::new_port(base_port).unwrap() }; uart.init(Config::default()).ok(); // Once we have a fallback destination for output, // we should log any error above and run From 6bc62c976f5ae056b77dfd4e7ec751b805276fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 Jul 2026 17:30:03 +0200 Subject: [PATCH 3/3] refactor(env): extract `fdt_addr()` --- src/env.rs | 16 ++++++++++++---- src/mm/physicalmem.rs | 3 +-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/env.rs b/src/env.rs index 3ae43bf010..f016f27edb 100644 --- a/src/env.rs +++ b/src/env.rs @@ -3,6 +3,7 @@ use alloc::borrow::ToOwned; use alloc::string::String; use alloc::vec::Vec; +use core::num::NonZero; use core::{ptr, str}; use ahash::RandomState; @@ -51,9 +52,16 @@ pub fn is_uefi() -> bool { fdt().is_some_and(|fdt| fdt.root().compatible().first() == "hermit,uefi") } +pub fn fdt_addr() -> Option> { + boot_info() + .hardware_info + .device_tree + .map(|fdt| NonZero::new(fdt.get() as usize).unwrap()) +} + pub fn fdt() -> Option> { - boot_info().hardware_info.device_tree.map(|fdt| { - let ptr = ptr::with_exposed_provenance(fdt.get().try_into().unwrap()); + fdt_addr().map(|fdt| { + let ptr = ptr::with_exposed_provenance(fdt.get()); unsafe { Fdt::from_ptr(ptr).unwrap() } }) } @@ -67,14 +75,14 @@ pub(crate) fn get_ram_address() -> Option { /// Returns the RSDP physical address if available. #[cfg(all(target_arch = "x86_64", feature = "acpi"))] -pub fn rsdp() -> Option> { +pub fn rsdp() -> Option> { let rsdp = fdt()? .find_node("/hermit,rsdp")? .reg()? .next()? .starting_address .addr(); - core::num::NonZero::new(rsdp) + NonZero::new(rsdp) } pub fn fdt_args() -> Option<&'static str> { diff --git a/src/mm/physicalmem.rs b/src/mm/physicalmem.rs index 5b5376e654..758871230c 100644 --- a/src/mm/physicalmem.rs +++ b/src/mm/physicalmem.rs @@ -171,8 +171,7 @@ unsafe fn detect_from_fdt() -> Result<(), ()> { let kernel_region = PageRange::new(kernel_start, kernel_end).unwrap(); reserve(kernel_region); - let fdt_start = env::boot_info().hardware_info.device_tree.unwrap().get(); - let fdt_start = usize::try_from(fdt_start).unwrap(); + let fdt_start = env::fdt_addr().unwrap().get(); let fdt_end = fdt_start + fdt.total_size(); let fdt_region = PageRange::containing(fdt_start, fdt_end).unwrap(); reserve(fdt_region);