Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/arch/aarch64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand All @@ -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() {
Expand Down
4 changes: 0 additions & 4 deletions src/arch/aarch64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -710,9 +709,6 @@ pub fn unmap<S: PageSize>(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();

Expand Down
14 changes: 0 additions & 14 deletions src/arch/riscv64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
15 changes: 1 addition & 14 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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};
Expand Down
12 changes: 9 additions & 3 deletions src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BootInfo> = OnceCell::new();

Expand Down Expand Up @@ -65,6 +64,13 @@ pub fn fdt() -> Option<Fdt<'static>> {
})
}

pub(crate) fn get_ram_address() -> Option<PhysAddr> {
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<core::num::NonZero<usize>> {
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 1 addition & 32 deletions src/mm/physicalmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
}
Loading