[boot] Restructure boot paging and program loading

Restructuring paging into an object that carries its page cache with it
and makes for simpler code. Program loading is also changed to not copy
the pages loaded from the file into new pages - we can impose a new
constraint that anything loaded by boot have a simple, page-aligned
layout so that we can just map the existing pages into the right
addresses. Also included are some linker script changes to help
accommodate this.
This commit is contained in:
Justin C. Miller
2023-02-05 22:02:41 -08:00
parent aba45b9b67
commit ab31825ab3
16 changed files with 406 additions and 301 deletions

View File

@@ -3,6 +3,7 @@
#pragma once
#include <bootproto/init.h>
#include <bootproto/kernel.h>
#include <util/counted.h>
namespace bootproto {
@@ -11,32 +12,47 @@ namespace bootproto {
namespace boot {
class descriptor;
namespace fs {
class file;
}
namespace fs { class file; }
namespace paging { class pager; }
namespace loader {
// Bootloader ELF file requirements
// ================================
// The bootloader accepts a subset of valid ELF files to load, with
// the following requiresments:
// 1. All program segments are page-aligned.
// 2. PT_LOAD segments cannot contain a mix of PROGBITS and NOBITS
// sections. i.e., section memory size must equal either zero or
// its file size.
// 3. There are only one or zero PT_LOAD NOBITS program segments.
/// Load a file from disk into memory.
/// \arg disk The opened UEFI filesystem to load from
/// \arg path The path of the file to load
util::buffer
load_file(
fs::file &disk,
const wchar_t *path);
util::buffer load_file(fs::file &disk, const wchar_t *path);
/// Parse and load an ELF file in memory into a loaded image.
/// \arg disk The opened UEFI filesystem to load from
/// \arg desc The descriptor identifying the program
/// Parse a buffer holding ELF data into a bootproto::program
/// \arg name The human-readable name of the program to load
/// \arg verify If this is the kernel and should have its header verified
bootproto::program *
load_program(
fs::file &disk,
/// \arg data A buffer containing an ELF executable
/// \arg program A program structure to fill
void parse_program(
const wchar_t *name,
const descriptor &desc,
util::const_buffer data,
bootproto::program &program);
/// Parse a buffer holding ELF data and map it to be runnable
/// \arg data The ELF data in memory
/// \arg name The human-readable name of the program to load
/// \arg pager The kernel space pager, to map programs into
/// \arg verify If this is the kernel and should have its header verified
/// \returns The entrypoint to the loaded program
uintptr_t
load_program(
util::const_buffer data,
const wchar_t *name,
paging::pager &pager,
bool verify = false);
/// Load a file from disk into memory, creating an init args module