[boot] Set up initial page tables

Set up initial page tables for both the offset-mapped area and the
loaded kernel code and data.

* Got rid of the `loaded_elf` struct - the loader now runs after the
  initial PML4 is created and maps the ELF sections itself.
* Copied in the `page_table` and `page_table_indices` from the kernel,
  still need to clean this up and extract it into shared code.
* Added `page_table_cache` to the kernel args to pass along free pages
  that can be used for initial page tables.

Tags: paging
This commit is contained in:
Justin C. Miller
2020-05-17 22:03:44 -07:00
parent c9722a07f3
commit 4f4a35a7be
8 changed files with 263 additions and 67 deletions

View File

@@ -13,6 +13,7 @@
#include "hardware.h"
#include "loader.h"
#include "memory.h"
#include "paging.h"
#include "kernel_args.h"
@@ -136,7 +137,7 @@ load_module(
/// The main procedure for the portion of the loader that runs while
/// UEFI is still in control of the machine. (ie, while the loader still
/// has access to boot services.
loader::loaded_elf
kernel::entrypoint
bootloader_main_uefi(uefi::handle image, uefi::system_table *st, console &con, size_t *map_key)
{
error::uefi_handler handler(con);
@@ -160,12 +161,14 @@ bootloader_main_uefi(uefi::handle image, uefi::system_table *st, console &con, s
kernel::args::module *kernel =
load_module(disk, args, L"kernel", L"jsix.elf", kernel::args::mod_type::kernel);
paging::allocate_tables(args, bs);
loader::loaded_elf kernel_elf =
loader::load(kernel->location, kernel->size, bs);
kernel::entrypoint kentry =
loader::load(kernel->location, kernel->size, args, bs);
*map_key = memory::build_kernel_mem_map(args, bs);
return kernel_elf;
return kentry;
}
} // namespace boot
@@ -180,7 +183,7 @@ efi_main(uefi::handle image_handle, uefi::system_table *st)
console con(st->boot_services, st->con_out);
size_t map_key;
loader::loaded_elf kernel =
kernel::entrypoint kentry =
bootloader_main_uefi(image_handle, st, con, &map_key);
try_or_raise(