diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 28859b7734..50b5a1b8c0 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -16,10 +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 memory_addresses::PhysAddr; use crate::arch::aarch64::kernel::core_local::*; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; @@ -43,14 +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 -} - #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { let fdt = env::fdt().unwrap(); @@ -68,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/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 61316a906a..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::get_ram_address; 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 = get_ram_address(); - info!("RAM starts at physical address {ram_start:p}"); - // determine physical address size let id_aa64mmfr0_el1 = ID_AA64MMFR0_EL1.extract(); diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 891e11eaea..49f744db66 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,15 +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 -} - #[cfg(feature = "smp")] pub fn get_possible_cpus() -> u32 { NUM_CPUS.load(Ordering::Relaxed) @@ -68,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 b7adf3cda7..b9b2ccc436 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; @@ -73,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() { @@ -225,7 +212,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..2480da2dd1 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -13,12 +13,11 @@ 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 +64,13 @@ pub fn fdt() -> Option> { }) } +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. #[cfg(all(target_arch = "x86_64", feature = "acpi"))] pub fn rsdp() -> Option> { @@ -90,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(); 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 diff --git a/src/mm/physicalmem.rs b/src/mm/physicalmem.rs index cbea30d0ec..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 = crate::arch::kernel::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"); }