Use KERNEL_OFFSET from linker script
This commit is contained in:
@@ -28,7 +28,7 @@ unsafe impl GlobalAlloc for Allocator {
|
||||
let size = heap.size();
|
||||
super::map_heap(
|
||||
&mut KernelMapper::lock_rw(),
|
||||
crate::KERNEL_HEAP_OFFSET + size,
|
||||
crate::kernel_heap_offset() + size,
|
||||
super::KERNEL_HEAP_SIZE,
|
||||
);
|
||||
heap.extend(super::KERNEL_HEAP_SIZE);
|
||||
|
||||
@@ -39,7 +39,7 @@ unsafe fn map_heap(mapper: &mut KernelMapper<true>, offset: usize, size: usize)
|
||||
|
||||
pub unsafe fn init() {
|
||||
unsafe {
|
||||
let offset = crate::KERNEL_HEAP_OFFSET;
|
||||
let offset = crate::kernel_heap_offset();
|
||||
let size = KERNEL_HEAP_SIZE;
|
||||
|
||||
// Map heap pages
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
/// The size of a single PML4
|
||||
pub const PML4_SIZE: usize = 0x0000_0080_0000_0000;
|
||||
|
||||
/// Offset of kernel
|
||||
pub const KERNEL_OFFSET: usize = (2 * PML4_SIZE).wrapping_neg();
|
||||
|
||||
/// Offset to kernel heap
|
||||
pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE;
|
||||
#[inline(always)]
|
||||
pub fn kernel_heap_offset() -> usize {
|
||||
crate::kernel_executable_offsets::KERNEL_OFFSET() - PML4_SIZE
|
||||
}
|
||||
|
||||
/// End offset of the user image, i.e. kernel start
|
||||
pub const USER_END_OFFSET: usize = 256 * PML4_SIZE;
|
||||
|
||||
@@ -6,11 +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 kernel
|
||||
pub const KERNEL_OFFSET: usize = (2 * PML4_SIZE).wrapping_neg();
|
||||
|
||||
/// Offset to kernel heap
|
||||
pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE;
|
||||
#[inline(always)]
|
||||
pub fn kernel_heap_offset() -> usize {
|
||||
crate::kernel_executable_offsets::KERNEL_OFFSET() - PML4_SIZE
|
||||
}
|
||||
|
||||
/// End offset of the user image, i.e. kernel start
|
||||
pub const USER_END_OFFSET: usize = 1_usize << (CurrentRmmArch::PAGE_ADDRESS_SHIFT - 1);
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
// Each PML4 entry references up to 512 GB of memory
|
||||
// The second from the top (510) PML4 is reserved for the kernel
|
||||
|
||||
/// Offset of kernel (256 MiB max)
|
||||
pub const KERNEL_OFFSET: usize = 0xC000_0000;
|
||||
|
||||
// Framebuffer mapped by bootloader to 0xD000_0000 (128 MiB max)
|
||||
|
||||
// Offset to APIC mappings (optional)
|
||||
@@ -14,7 +11,10 @@ pub const IOAPIC_OFFSET: usize = LAPIC_OFFSET + 4096;
|
||||
pub const HPET_OFFSET: usize = IOAPIC_OFFSET + 4096;
|
||||
|
||||
/// Offset to kernel heap (256 MiB max)
|
||||
pub const KERNEL_HEAP_OFFSET: usize = 0xE000_0000;
|
||||
#[inline(always)]
|
||||
pub fn kernel_heap_offset() -> usize {
|
||||
0xE000_0000
|
||||
}
|
||||
|
||||
/// End offset of the user image, i.e. kernel start
|
||||
pub const USER_END_OFFSET: usize = 0x8000_0000;
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
pub const PML4_SIZE: usize = 0x0000_0080_0000_0000;
|
||||
|
||||
/// Offset of kernel
|
||||
pub const KERNEL_OFFSET: usize = (1_usize << 31).wrapping_neg();
|
||||
const KERNEL_OFFSET: usize = (1_usize << 31).wrapping_neg();
|
||||
|
||||
/// Offset to kernel heap
|
||||
pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE;
|
||||
#[inline(always)]
|
||||
pub fn kernel_heap_offset() -> usize {
|
||||
crate::kernel_executable_offsets::KERNEL_OFFSET() - PML4_SIZE
|
||||
}
|
||||
|
||||
/// 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,
|
||||
|
||||
+3
-1
@@ -223,7 +223,8 @@ fn run_userspace(token: &mut CleanLockToken) -> ! {
|
||||
macro_rules! linker_offsets(
|
||||
($($name:ident),*) => {
|
||||
$(
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn $name() -> usize {
|
||||
unsafe extern "C" {
|
||||
// TODO: UnsafeCell?
|
||||
@@ -236,6 +237,7 @@ macro_rules! linker_offsets(
|
||||
);
|
||||
mod kernel_executable_offsets {
|
||||
linker_offsets!(
|
||||
KERNEL_OFFSET,
|
||||
__text_start,
|
||||
__text_end,
|
||||
__rodata_start,
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ pub unsafe fn stack_trace() {
|
||||
unsafe {
|
||||
let mapper = KernelMapper::lock_ro();
|
||||
|
||||
let kernel_ptr = crate::KERNEL_OFFSET as *const u8;
|
||||
let kernel_ptr = crate::kernel_executable_offsets::KERNEL_OFFSET() as *const u8;
|
||||
let elf_header: &FileHeader<NativeEndian> = object::pod::from_bytes(slice::from_raw_parts(
|
||||
kernel_ptr,
|
||||
size_of::<FileHeader<NativeEndian>>(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
arch::{consts::KERNEL_OFFSET, CurrentRmmArch},
|
||||
arch::CurrentRmmArch,
|
||||
memory::PAGE_SIZE,
|
||||
startup::{memory::BootloaderMemoryKind::Null, KernelArgs},
|
||||
};
|
||||
@@ -331,7 +331,9 @@ unsafe fn map_memory<A: Arch>(areas: &[MemoryArea], mut bump_allocator: &mut Bum
|
||||
// Map kernel at KERNEL_OFFSET and identity map too
|
||||
for i in 0..kernel_size / A::PAGE_SIZE {
|
||||
let phys = PhysicalAddress::new(kernel_base + i * PAGE_SIZE);
|
||||
let virt = VirtualAddress::new(KERNEL_OFFSET + i * PAGE_SIZE);
|
||||
let virt = VirtualAddress::new(
|
||||
crate::kernel_executable_offsets::KERNEL_OFFSET() + i * PAGE_SIZE,
|
||||
);
|
||||
let flags = kernel_page_flags::<A>(virt);
|
||||
let flush = mapper
|
||||
.map_phys(virt, phys, flags)
|
||||
|
||||
Reference in New Issue
Block a user