From 96ef3462ecaa406d7204dc7b202ba8900848f5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 17:24:57 +0200 Subject: [PATCH 1/7] refactor(physicalmem): use `get_ram_address` through `env` --- src/mm/physicalmem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm/physicalmem.rs b/src/mm/physicalmem.rs index cbea30d0ec..c09bd4ed3c 100644 --- a/src/mm/physicalmem.rs +++ b/src/mm/physicalmem.rs @@ -209,7 +209,7 @@ unsafe fn detect_from_limits() -> Result<(), ()> { } #[cfg(target_arch = "riscv64")] - let ram_address = crate::arch::kernel::get_ram_address().as_usize(); + let ram_address = env::get_ram_address().as_usize(); #[cfg(target_arch = "aarch64")] let ram_address = 0; From e74c2385c1ca8b8fe1b2753d57058cf5921c41ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 17:27:07 +0200 Subject: [PATCH 2/7] refactor(aarch64): don't import `get_ram_address` directly --- src/arch/aarch64/mm/paging.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 61316a906a..8914bffcda 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -8,7 +8,7 @@ use align_address::Align; use free_list::PageLayout; use memory_addresses::{PhysAddr, VirtAddr}; -use crate::env::get_ram_address; +use crate::env; use crate::mm::{FrameAlloc, PageRangeAllocator}; /// Pointer to the root page table (called "Level 0" in ARM terminology). @@ -710,7 +710,7 @@ pub fn unmap(virtual_address: VirtAddr, count: usize) { } pub unsafe fn init() { - let ram_start = get_ram_address(); + let ram_start = env::get_ram_address(); info!("RAM starts at physical address {ram_start:p}"); // determine physical address size From c86bff9a89114f26ac512b038b82250c9298af9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 17:22:12 +0200 Subject: [PATCH 3/7] refactor(env): centralize `get_ram_address` implementation --- src/arch/aarch64/kernel/mod.rs | 6 ------ src/arch/riscv64/kernel/mod.rs | 5 ----- src/arch/x86_64/kernel/mod.rs | 7 +------ src/env/mod.rs | 6 +++++- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 28859b7734..896e00ad5b 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -19,8 +19,6 @@ use core::arch::global_asm; use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering}; use core::{ptr, str}; -use memory_addresses::PhysAddr; - use crate::arch::aarch64::kernel::core_local::*; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; use crate::config::*; @@ -43,10 +41,6 @@ pub fn is_uhyve_with_pci() -> bool { false } -pub fn get_ram_address() -> PhysAddr { - PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start) -} - pub fn get_limit() -> usize { env::boot_info().hardware_info.phys_addr_range.end as usize } diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 891e11eaea..f0906bf9c5 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -16,7 +16,6 @@ use core::ptr; use core::sync::atomic::{AtomicPtr, AtomicU32, AtomicU64, Ordering}; use free_list::PageLayout; -use memory_addresses::PhysAddr; use riscv::register::sstatus; use crate::arch::riscv64::kernel::core_local::core_id; @@ -44,10 +43,6 @@ pub fn is_uhyve_with_pci() -> bool { false } -pub fn get_ram_address() -> PhysAddr { - PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start) -} - pub fn get_limit() -> usize { (env::boot_info().hardware_info.phys_addr_range.end - env::boot_info().hardware_info.phys_addr_range.start) as usize diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index b7adf3cda7..f62ba004b1 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -6,7 +6,6 @@ use core::slice; use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering}; use hermit_entry::boot_info::{PlatformInfo, RawBootInfo}; -use memory_addresses::PhysAddr; use x86_64::registers::control::{Cr0, Cr4}; use crate::arch::x86_64::kernel::core_local::*; @@ -38,10 +37,6 @@ pub(crate) mod systemtime; #[cfg(feature = "vga")] pub mod vga; -pub fn get_ram_address() -> PhysAddr { - PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start) -} - #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { use core::cmp; @@ -225,7 +220,7 @@ where use align_address::Align; use free_list::PageLayout; - use memory_addresses::VirtAddr; + use memory_addresses::{PhysAddr, VirtAddr}; use x86_64::structures::paging::{PageSize, Size4KiB as BasePageSize}; use crate::arch::x86_64::mm::paging::{self, PageTableEntryFlags, PageTableEntryFlagsExt}; diff --git a/src/env/mod.rs b/src/env/mod.rs index c85af8c55d..82cbfcf5de 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -13,12 +13,12 @@ use hashbrown::HashMap; use hashbrown::hash_map::Iter; use hermit_entry::boot_info::{BootInfo, PlatformInfo, RawBootInfo}; use hermit_sync::OnceCell; +use memory_addresses::PhysAddr; #[cfg(not(feature = "common-os"))] pub(crate) use self::executable::tls::TlsInfo; pub(crate) use self::executable::{executable_ptr_range, log_segments}; use crate::arch::kernel; -pub(crate) use crate::arch::kernel::get_ram_address; static BOOT_INFO: OnceCell = OnceCell::new(); @@ -65,6 +65,10 @@ pub fn fdt() -> Option> { }) } +pub(crate) fn get_ram_address() -> PhysAddr { + PhysAddr::new(boot_info().hardware_info.phys_addr_range.start) +} + /// Returns the RSDP physical address if available. #[cfg(all(target_arch = "x86_64", feature = "acpi"))] pub fn rsdp() -> Option> { From 20b4bb45050ab287802de83e045f5a1bd7540ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 18:01:04 +0200 Subject: [PATCH 4/7] fix(aarch64): don't print RAM start explicitly It is part of the printed start info --- src/arch/aarch64/mm/paging.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 8914bffcda..2ac29b12b9 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -8,7 +8,6 @@ use align_address::Align; use free_list::PageLayout; use memory_addresses::{PhysAddr, VirtAddr}; -use crate::env; use crate::mm::{FrameAlloc, PageRangeAllocator}; /// Pointer to the root page table (called "Level 0" in ARM terminology). @@ -710,9 +709,6 @@ pub fn unmap(virtual_address: VirtAddr, count: usize) { } pub unsafe fn init() { - let ram_start = env::get_ram_address(); - info!("RAM starts at physical address {ram_start:p}"); - // determine physical address size let id_aa64mmfr0_el1 = ID_AA64MMFR0_EL1.extract(); From 159611fa8229d957d4643116cb0dea2f8a7ae2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 18:03:34 +0200 Subject: [PATCH 5/7] fix(physicalmem): drop support for non-FDT memory --- src/arch/aarch64/kernel/mod.rs | 4 ---- src/arch/riscv64/kernel/mod.rs | 5 ----- src/mm/physicalmem.rs | 33 +-------------------------------- 3 files changed, 1 insertion(+), 41 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 896e00ad5b..d03ffb51f9 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -41,10 +41,6 @@ pub fn is_uhyve_with_pci() -> bool { false } -pub fn get_limit() -> usize { - env::boot_info().hardware_info.phys_addr_range.end as usize -} - #[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 f0906bf9c5..93aae10a64 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -43,11 +43,6 @@ pub fn is_uhyve_with_pci() -> bool { false } -pub fn get_limit() -> usize { - (env::boot_info().hardware_info.phys_addr_range.end - - env::boot_info().hardware_info.phys_addr_range.start) as usize -} - #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { NUM_CPUS.load(Ordering::Relaxed) diff --git a/src/mm/physicalmem.rs b/src/mm/physicalmem.rs index c09bd4ed3c..c61aa2f237 100644 --- a/src/mm/physicalmem.rs +++ b/src/mm/physicalmem.rs @@ -201,29 +201,6 @@ impl PageRangeExt for PageRange { } } -#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] -unsafe fn detect_from_limits() -> Result<(), ()> { - let limit = crate::arch::kernel::get_limit(); - if limit == 0 { - return Err(()); - } - - #[cfg(target_arch = "riscv64")] - let ram_address = env::get_ram_address().as_usize(); - #[cfg(target_arch = "aarch64")] - let ram_address = 0; - - let range = - PageRange::new(super::kernel_end_address().as_usize(), ram_address + limit).unwrap(); - unsafe { - PHYSICAL_FREE_LIST.lock().deallocate(range).unwrap(); - map_frame_range(range); - } - TOTAL_MEMORY.fetch_add(range.len().get(), Ordering::Relaxed); - - Ok(()) -} - unsafe fn init() { if env::is_uefi() && DeviceAlloc.phys_offset() != VirtAddr::zero() { let start = DeviceAlloc.phys_offset(); @@ -236,13 +213,5 @@ unsafe fn init() { return; } - cfg_select! { - any(target_arch = "aarch64", target_arch = "riscv64") => { - error!("Could not detect physical memory from FDT"); - unsafe { detect_from_limits().unwrap(); } - } - _ => { - panic!("Could not detect physical memory from FDT"); - } - } + panic!("Could not detect physical memory from FDT"); } From 8bdee86e5eed03a932a0a1f26f584ddf4676c32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 10 May 2026 17:28:27 +0200 Subject: [PATCH 6/7] feat(env): drop support for non-FDT RAM `get_ram_address` --- src/env/mod.rs | 7 +++++-- src/mm/mod.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/env/mod.rs b/src/env/mod.rs index 82cbfcf5de..f9f7a1300d 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -65,8 +65,11 @@ pub fn fdt() -> Option> { }) } -pub(crate) fn get_ram_address() -> PhysAddr { - PhysAddr::new(boot_info().hardware_info.phys_addr_range.start) +pub(crate) fn get_ram_address() -> Option { + let fdt = fdt()?; + let memory = fdt.memory(); + let ptr = memory.regions().next()?.starting_address; + Some(ptr.expose_provenance().into()) } /// Returns the RSDP physical address if available. diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 9c5ace4ac6..76bf3b4fb6 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -147,8 +147,8 @@ pub(crate) fn init() { // On UEFI, the given memory is guaranteed free memory and the kernel is located before the given memory reserved_space } else { - (kernel_addr_range.end.as_u64() - env::get_ram_address().as_u64() + reserved_space as u64) - as usize + (kernel_addr_range.end.as_u64() - env::get_ram_address().unwrap().as_u64() + + reserved_space as u64) as usize }; info!("Minimum memory size: {} MiB", min_mem >> 20); let avail_mem = total_mem From c92e6f7f5efdedf20633764aac51314bcf892257 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 7/7] 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/mod.rs | 3 +-- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index d03ffb51f9..50b5a1b8c0 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}; use crate::arch::aarch64::kernel::core_local::*; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; @@ -58,10 +58,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 93aae10a64..49f744db66 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -58,10 +58,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 f62ba004b1..b9b2ccc436 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -68,14 +68,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/mod.rs b/src/env/mod.rs index f9f7a1300d..2480da2dd1 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -18,7 +18,6 @@ use memory_addresses::PhysAddr; #[cfg(not(feature = "common-os"))] pub(crate) use self::executable::tls::TlsInfo; pub(crate) use self::executable::{executable_ptr_range, log_segments}; -use crate::arch::kernel; static BOOT_INFO: OnceCell = OnceCell::new(); @@ -97,7 +96,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();