Skip to content

Commit

Permalink
find_kernel: give values meaningful names
Browse files Browse the repository at this point in the history
  • Loading branch information
cagatay-y committed Oct 3, 2024
1 parent c6f3be2 commit afa33dc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/arch/x86_64/multiboot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,29 @@ pub fn find_kernel() -> &'static [u8] {
let elf_len = end_address - start_address;
info!("Module length: {:#x}", elf_len);

// The mapping functions use `PhysAlloc`, even when the range they map
// is not covered by it, so it needs to be initialized before
// the mappings happen.
let free_memory_address = end_address.align_up(Size2MiB::SIZE as usize);
// TODO: Workaround for https://github.com/hermitcore/loader/issues/96
let free_memory_address = cmp::max(free_memory_address, 0x800000);
// Memory after the highest end address is unused and available for the physical memory manager.
PhysAlloc::init(free_memory_address);

// Identity-map the ELF header of the first module.
let first_module_mapping_end = start_address.align_up(Size2MiB::SIZE as usize);
paging::map_range::<Size4KiB>(
start_address,
start_address,
start_address.align_up(Size2MiB::SIZE as usize),
first_module_mapping_end,
PageTableFlags::empty(),
);

// map also the rest of the module
let address = start_address.align_up(Size2MiB::SIZE as usize);
paging::map_range::<Size2MiB>(
address,
address,
end_address.align_up(Size2MiB::SIZE as usize),
first_module_mapping_end,
first_module_mapping_end,
free_memory_address,
PageTableFlags::empty(),
);

Expand Down

0 comments on commit afa33dc

Please sign in to comment.