From e737164bfe1ba13c4de095c8668bc9c057990643 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/5] 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 6eaebd6ed5..d4420549cc 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -16,8 +16,8 @@ pub mod systemtime; use alloc::alloc::{Layout, alloc}; 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; @@ -60,10 +60,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 85a836072e..0a805f835a 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -69,14 +69,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 725a4fe74e2ba1237ebada574c47926ae0947483 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/5] feat(serial): hardcode addresses --- src/arch/aarch64/kernel/serial.rs | 24 +++++++++++------------- src/arch/x86_64/kernel/serial.rs | 8 ++------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/arch/aarch64/kernel/serial.rs b/src/arch/aarch64/kernel/serial.rs index efb0fa32f6..2a149b2432 100644 --- a/src/arch/aarch64/kernel/serial.rs +++ b/src/arch/aarch64/kernel/serial.rs @@ -1,8 +1,7 @@ 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 +17,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 7d26526cd0..204e64289d 100644 --- a/src/arch/x86_64/kernel/serial.rs +++ b/src/arch/x86_64/kernel/serial.rs @@ -24,12 +24,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 33c828f45ed75752881d786cd44b3fe5f1bf36b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 23 Jun 2026 13:54:57 +0200 Subject: [PATCH 3/5] feat(x86_64): require Uhyve-reported CPU count --- src/arch/x86_64/kernel/mod.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 0a805f835a..c0b488df3d 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -40,14 +40,8 @@ pub mod vga; #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { - use core::cmp; - match env::boot_info().platform_info { - // FIXME: Remove get_processor_count after a transition period for uhyve 0.1.3 adoption - PlatformInfo::Uhyve { num_cpus, .. } => cmp::max( - u32::try_from(num_cpus.get()).unwrap(), - get_processor_count(), - ), + PlatformInfo::Uhyve { num_cpus, .. } => u32::try_from(num_cpus.get()).unwrap(), _ => apic::local_apic_id_count(), } } From e48a09b55cf74dd2901c5f5ccd5700905a22cea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 23 Jun 2026 14:02:36 +0200 Subject: [PATCH 4/5] refactor(x86_64): don't import is_uhyve directly --- src/arch/x86_64/kernel/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index c0b488df3d..5581708d21 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -10,7 +10,7 @@ use x86_64::registers::control::{Cr0, Cr4}; pub(crate) use self::apic::{set_oneshot_timer, wakeup_core}; use crate::arch::x86_64::kernel::core_local::*; -use crate::env::{self, is_uhyve}; +use crate::env; #[cfg(feature = "acpi")] pub mod acpi; @@ -69,7 +69,7 @@ pub fn boot_processor_init() { processor::detect_features(); processor::configure(); - if cfg!(feature = "vga") && !is_uhyve() { + if cfg!(feature = "vga") && !env::is_uhyve() { #[cfg(feature = "vga")] vga::init(); } @@ -89,11 +89,11 @@ pub fn boot_processor_init() { interrupts::install(); systemtime::init(); - if !is_uhyve() { + if !env::is_uhyve() { #[cfg(feature = "acpi")] acpi::init(); } - if is_uhyve_with_pci() || !is_uhyve() { + if is_uhyve_with_pci() || !env::is_uhyve() { #[cfg(feature = "pci")] pci::init(); } @@ -120,7 +120,7 @@ pub fn application_processor_init() { } fn finish_processor_init() { - if is_uhyve() { + if env::is_uhyve() { // uhyve does not use apic::detect_from_acpi and therefore does not know the number of processors and // their APIC IDs in advance. // Therefore, we have to add each booted processor into the CPU_LOCAL_APIC_IDS vector ourselves. @@ -138,7 +138,7 @@ pub fn boot_next_processor() { // to initialize the next processor. let cpu_online = CPU_ONLINE.fetch_add(1, Ordering::Release); - if !is_uhyve() { + if !env::is_uhyve() { if cpu_online == 0 { #[cfg(all(target_os = "none", feature = "smp"))] apic::boot_application_processors(); From d4a4da1b154999455f9fa2ce0d599ea09b3ee493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 23 Jun 2026 14:03:39 +0200 Subject: [PATCH 5/5] refactor(env): centralize `is_uhyve_with_pci` --- src/arch/aarch64/kernel/mod.rs | 4 ---- src/arch/riscv64/kernel/mod.rs | 4 ---- src/arch/x86_64/kernel/mod.rs | 9 +-------- src/env.rs | 7 +++++++ src/lib.rs | 2 +- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index d4420549cc..831808ff73 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -39,10 +39,6 @@ pub(crate) static CURRENT_STACK_ADDRESS: AtomicPtr = AtomicPtr::new(ptr::nul #[cfg(target_os = "none")] global_asm!(include_str!("start.s")); -pub fn is_uhyve_with_pci() -> bool { - false -} - #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { let fdt = env::fdt().unwrap(); diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 5b8cf8b9c5..a24a0606b4 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -40,10 +40,6 @@ static NUM_CPUS: AtomicU32 = AtomicU32::new(0); // FUNCTIONS -pub fn is_uhyve_with_pci() -> bool { - false -} - #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { NUM_CPUS.load(Ordering::Relaxed) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 5581708d21..7e18b68a27 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -56,13 +56,6 @@ pub fn get_processor_count() -> u32 { 1 } -pub fn is_uhyve_with_pci() -> bool { - matches!( - env::boot_info().platform_info, - PlatformInfo::Uhyve { has_pci: true, .. } - ) -} - /// 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() { @@ -93,7 +86,7 @@ pub fn boot_processor_init() { #[cfg(feature = "acpi")] acpi::init(); } - if is_uhyve_with_pci() || !env::is_uhyve() { + if env::is_uhyve_with_pci() || !env::is_uhyve() { #[cfg(feature = "pci")] pci::init(); } diff --git a/src/env.rs b/src/env.rs index 3ae43bf010..f72ba28c99 100644 --- a/src/env.rs +++ b/src/env.rs @@ -47,6 +47,13 @@ pub fn is_uhyve() -> bool { matches!(boot_info().platform_info, PlatformInfo::Uhyve { .. }) } +pub fn is_uhyve_with_pci() -> bool { + matches!( + boot_info().platform_info, + PlatformInfo::Uhyve { has_pci: true, .. } + ) +} + pub fn is_uefi() -> bool { fdt().is_some_and(|fdt| fdt.root().compatible().first() == "hermit,uefi") } diff --git a/src/lib.rs b/src/lib.rs index 6754a05c90..78508ee9b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -285,7 +285,7 @@ fn boot_processor_main() -> ! { #[cfg(feature = "smp")] synch_all_cores(); - if kernel::is_uhyve_with_pci() || !env::is_uhyve() { + if env::is_uhyve_with_pci() || !env::is_uhyve() { #[cfg(feature = "pci")] drivers::pci::print_information(); }