Clean and document header files.

- Add missing doc comments to header files
- Move allocate_kernel_args to main.cpp
- Split functions out into pointer_manipulation.h
This commit is contained in:
Justin C. Miller
2020-05-10 01:42:22 -07:00
parent 9aa749e877
commit 10c8f6e4b5
11 changed files with 191 additions and 102 deletions

View File

@@ -85,6 +85,42 @@ detect_debug_mode(EFI_RUNTIME_SERVICES *run, kernel_args *header) {
}
*/
/// Allocate space for kernel args. Allocates enough space from pool
/// memory for the args header and `max_modules` module headers.
kernel::args::header *
allocate_args_structure(
uefi::boot_services *bs,
size_t max_modules)
{
status_line status(L"Setting up kernel args memory");
kernel::args::header *args = nullptr;
size_t args_size =
sizeof(kernel::args::header) + // The header itself
max_modules * sizeof(kernel::args::module); // The module structures
try_or_raise(
bs->allocate_pool(memory::args_type, args_size,
reinterpret_cast<void**>(&args)),
L"Could not allocate argument memory");
bs->set_mem(args, args_size, 0);
args->modules =
reinterpret_cast<kernel::args::module*>(args + 1);
args->num_modules = 0;
return args;
}
/// Load a file from disk into memory. Also adds an entry to the kernel
/// args module headers pointing at the loaded data.
/// \arg disk The opened UEFI filesystem to load from
/// \arg args The kernel args header to update with module information
/// \arg name Name of the module (informational only)
/// \arg path Path on `disk` of the file to load
/// \arg type Type specifier of this module (eg, initrd or kernel)
kernel::args::module *
load_module(
fs::file &disk,
@@ -104,6 +140,9 @@ load_module(
return &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
bootloader_main_uefi(uefi::handle image, uefi::system_table *st, console &con)
{
@@ -115,7 +154,7 @@ bootloader_main_uefi(uefi::handle image, uefi::system_table *st, console &con)
memory::init_pointer_fixup(bs, rs);
kernel::args::header *args =
memory::allocate_args_structure(bs, max_modules);
allocate_args_structure(bs, max_modules);
args->magic = kernel::args::magic;
args->version = kernel::args::version;
@@ -238,6 +277,7 @@ bootloader_main_uefi(uefi::handle image, uefi::system_table *st, console &con)
*/
} // namespace boot
/// The UEFI entrypoint for the loader.
extern "C" uefi::status
efi_main(uefi::handle image_handle, uefi::system_table *st)
{