Kernel: Map multiboot2 memory in PageTable initialization
It cannot be assumed that multiboot data lies between kernel_end and 2 GiB mark, so I properly allocate virtual address space for it.
This commit is contained in:
parent
69a39b7077
commit
c17cdb39d5
|
@ -139,16 +139,6 @@ namespace Kernel
|
|||
// Map (0 -> phys_kernel_end) to (KERNEL_OFFSET -> virt_kernel_end)
|
||||
map_range_at(0, KERNEL_OFFSET, (uintptr_t)g_kernel_end - KERNEL_OFFSET, Flags::ReadWrite | Flags::Present);
|
||||
|
||||
// Map multiboot info
|
||||
vaddr_t multiboot_data_start = (vaddr_t)g_multiboot2_info & PAGE_ADDR_MASK;
|
||||
vaddr_t multiboot_data_end = (vaddr_t)g_multiboot2_info + g_multiboot2_info->total_size;
|
||||
map_range_at(
|
||||
V2P(multiboot_data_start),
|
||||
multiboot_data_start,
|
||||
multiboot_data_end - multiboot_data_start,
|
||||
Flags::ReadWrite | Flags::Present
|
||||
);
|
||||
|
||||
// Map executable kernel memory as executable
|
||||
map_range_at(
|
||||
V2P(g_kernel_execute_start),
|
||||
|
@ -164,6 +154,22 @@ namespace Kernel
|
|||
g_userspace_end - g_userspace_start,
|
||||
Flags::Execute | Flags::UserSupervisor | Flags::Present
|
||||
);
|
||||
|
||||
// Map multiboot memory
|
||||
paddr_t multiboot2_data_start = (vaddr_t)g_multiboot2_info & PAGE_ADDR_MASK;
|
||||
paddr_t multiboot2_data_end = (vaddr_t)g_multiboot2_info + g_multiboot2_info->total_size;
|
||||
|
||||
size_t multiboot2_needed_pages = BAN::Math::div_round_up<size_t>(multiboot2_data_end - multiboot2_data_start, PAGE_SIZE);
|
||||
vaddr_t multiboot2_vaddr = reserve_free_contiguous_pages(multiboot2_needed_pages, KERNEL_OFFSET);
|
||||
|
||||
map_range_at(
|
||||
multiboot2_data_start,
|
||||
multiboot2_vaddr,
|
||||
multiboot2_needed_pages * PAGE_SIZE,
|
||||
Flags::ReadWrite | Flags::Present
|
||||
);
|
||||
|
||||
g_multiboot2_info = (multiboot2_info_t*)(multiboot2_vaddr + ((vaddr_t)g_multiboot2_info % PAGE_SIZE));
|
||||
}
|
||||
|
||||
BAN::ErrorOr<PageTable*> PageTable::create_userspace()
|
||||
|
|
|
@ -197,8 +197,6 @@ long_mode:
|
|||
jmp *%rcx
|
||||
|
||||
higher_half:
|
||||
addq $KERNEL_OFFSET, g_multiboot2_info
|
||||
|
||||
# call global constuctors
|
||||
call _init
|
||||
|
||||
|
|
Loading…
Reference in New Issue