diff --git a/src/allocator/linked_list.rs b/src/allocator/linked_list.rs index aa87e515c4..116aba5251 100644 --- a/src/allocator/linked_list.rs +++ b/src/allocator/linked_list.rs @@ -29,9 +29,9 @@ unsafe impl GlobalAlloc for Allocator { super::map_heap( &mut KernelMapper::lock_rw(), crate::KERNEL_HEAP_OFFSET + size, - crate::KERNEL_HEAP_SIZE, + super::KERNEL_HEAP_SIZE, ); - heap.extend(crate::KERNEL_HEAP_SIZE); + heap.extend(super::KERNEL_HEAP_SIZE); } } } diff --git a/src/allocator/mod.rs b/src/allocator/mod.rs index bdac2dab92..cccbb8454f 100644 --- a/src/allocator/mod.rs +++ b/src/allocator/mod.rs @@ -7,6 +7,9 @@ use rmm::{Flusher, FrameAllocator}; pub use self::linked_list::Allocator; mod linked_list; +/// Size of kernel heap +const KERNEL_HEAP_SIZE: usize = ::rmm::MEGABYTE; + unsafe fn map_heap(mapper: &mut KernelMapper, offset: usize, size: usize) { let mut flush_all = PageFlushAll::new(); @@ -37,7 +40,7 @@ unsafe fn map_heap(mapper: &mut KernelMapper, offset: usize, size: usize) pub unsafe fn init() { unsafe { let offset = crate::KERNEL_HEAP_OFFSET; - let size = crate::KERNEL_HEAP_SIZE; + let size = KERNEL_HEAP_SIZE; // Map heap pages map_heap(&mut KernelMapper::lock_rw(), offset, size); diff --git a/src/arch/aarch64/consts.rs b/src/arch/aarch64/consts.rs index df87c46d5a..145db36cdb 100644 --- a/src/arch/aarch64/consts.rs +++ b/src/arch/aarch64/consts.rs @@ -5,20 +5,11 @@ /// The size of a single PML4 pub const PML4_SIZE: usize = 0x0000_0080_0000_0000; -/// Offset of recursive paging (deprecated, but still reserved) -pub const RECURSIVE_PAGE_OFFSET: usize = (-(PML4_SIZE as isize)) as usize; - /// Offset of kernel -pub const KERNEL_OFFSET: usize = RECURSIVE_PAGE_OFFSET - PML4_SIZE; +pub const KERNEL_OFFSET: usize = (2 * PML4_SIZE).wrapping_neg(); /// Offset to kernel heap pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE; -/// Size of kernel heap -pub const KERNEL_HEAP_SIZE: usize = 1 * 1024 * 1024; // 1 MB - -/// Offset of physmap -// This needs to match RMM's PHYS_OFFSET -pub const PHYS_OFFSET: usize = 0xFFFF_8000_0000_0000; /// End offset of the user image, i.e. kernel start pub const USER_END_OFFSET: usize = 256 * PML4_SIZE; diff --git a/src/arch/riscv64/consts.rs b/src/arch/riscv64/consts.rs index 5f017f3f4e..39867f9029 100644 --- a/src/arch/riscv64/consts.rs +++ b/src/arch/riscv64/consts.rs @@ -6,20 +6,11 @@ const PML4_SHIFT: usize = (CurrentRmmArch::PAGE_LEVELS - 1) * CurrentRmmArch::PA /// The size of a single PML4 pub const PML4_SIZE: usize = 1_usize << PML4_SHIFT; -/// Offset of recursive paging (deprecated, but still reserved) -pub const RECURSIVE_PAGE_OFFSET: usize = (-(PML4_SIZE as isize)) as usize; - /// Offset of kernel -pub const KERNEL_OFFSET: usize = RECURSIVE_PAGE_OFFSET - PML4_SIZE; +pub const KERNEL_OFFSET: usize = (2 * PML4_SIZE).wrapping_neg(); /// Offset to kernel heap pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE; -/// Size of kernel heap -pub const KERNEL_HEAP_SIZE: usize = 1 * 1024 * 1024; // 1 MB - -/// Offset of physmap -// This needs to match RMM's PHYS_OFFSET -pub const PHYS_OFFSET: usize = (-1_isize << (CurrentRmmArch::PAGE_ADDRESS_SHIFT - 1)) as usize; /// End offset of the user image, i.e. kernel start pub const USER_END_OFFSET: usize = 1_usize << (CurrentRmmArch::PAGE_ADDRESS_SHIFT - 1); diff --git a/src/arch/x86/consts.rs b/src/arch/x86/consts.rs index 902de7f2d9..224896f5dd 100644 --- a/src/arch/x86/consts.rs +++ b/src/arch/x86/consts.rs @@ -15,12 +15,6 @@ pub const HPET_OFFSET: usize = IOAPIC_OFFSET + 4096; /// Offset to kernel heap (256 MiB max) pub const KERNEL_HEAP_OFFSET: usize = 0xE000_0000; -/// Size of kernel heap -pub const KERNEL_HEAP_SIZE: usize = rmm::MEGABYTE; - -/// Offset of physmap (1 GiB max) -// This needs to match RMM's PHYS_OFFSET -pub const PHYS_OFFSET: usize = 0x8000_0000; /// End offset of the user image, i.e. kernel start pub const USER_END_OFFSET: usize = 0x8000_0000; diff --git a/src/arch/x86_64/consts.rs b/src/arch/x86_64/consts.rs index 9936492312..6a744dbc2b 100644 --- a/src/arch/x86_64/consts.rs +++ b/src/arch/x86_64/consts.rs @@ -12,17 +12,10 @@ pub const PML4_SIZE: usize = 0x0000_0080_0000_0000; /// Offset of kernel -pub const KERNEL_MAX_SIZE: usize = 1_usize << 31; -pub const KERNEL_OFFSET: usize = KERNEL_MAX_SIZE.wrapping_neg(); +pub const KERNEL_OFFSET: usize = (1_usize << 31).wrapping_neg(); /// Offset to kernel heap pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE; -/// Size of kernel heap -pub const KERNEL_HEAP_SIZE: usize = 1 * 1024 * 1024; // 1 MB - -/// Offset of physmap -// This needs to match RMM's PHYS_OFFSET -pub const PHYS_OFFSET: usize = 0xFFFF_8000_0000_0000; /// End offset of the user image, i.e. kernel start // TODO: Make this offset at least PAGE_SIZE less? There are known hardware bugs on some arches, diff --git a/src/main.rs b/src/main.rs index dbbbbb5e92..5c47f91397 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,8 @@ mod macros; #[allow(dead_code)] // TODO mod arch; use crate::arch::*; +/// Offset of physmap +const PHYS_OFFSET: usize = ::PHYS_OFFSET; /// Heap allocators mod allocator;