[all] Rename kernel::args to kernel::init

The kernel::args namespace is really the protocol for initializing the
kernel from the bootloader. Also, the header struct in that namespace
isn't actually a header, but a collection of parameters. This change
renames the namespace to kernel::init and the struct to args.
This commit is contained in:
Justin C. Miller
2021-05-28 12:34:46 -07:00
parent 82333ceb82
commit 910fde3b2c
16 changed files with 117 additions and 108 deletions

View File

@@ -57,13 +57,13 @@ console::console(uefi::boot_services *bs, uefi::protos::simple_text_output *out)
m_out->set_attribute(uefi::attribute::light_gray);
m_out->output_string(L" booting...\r\n");
if (m_fb.type != kernel::args::fb_type::none) {
if (m_fb.type != kernel::init::fb_type::none) {
wchar_t const * type = nullptr;
switch (m_fb.type) {
case kernel::args::fb_type::rgb8:
case kernel::init::fb_type::rgb8:
type = L"rgb8";
break;
case kernel::args::fb_type::bgr8:
case kernel::init::fb_type::bgr8:
type = L"bgr8";
break;
default:
@@ -86,7 +86,7 @@ console::pick_mode(uefi::boot_services *bs)
uefi::protos::graphics_output *gfx_out_proto;
uefi::guid guid = uefi::protos::graphics_output::guid;
m_fb.type = kernel::args::fb_type::none;
m_fb.type = kernel::init::fb_type::none;
uefi::status has_gop = bs->locate_protocol(&guid, nullptr,
(void **)&gfx_out_proto);
@@ -138,13 +138,13 @@ console::pick_mode(uefi::boot_services *bs)
switch (gfx_out_proto->mode->info->pixel_format) {
case uefi::pixel_format::rgb8:
m_fb.type = kernel::args::fb_type::rgb8;
m_fb.type = kernel::init::fb_type::rgb8;
break;
case uefi::pixel_format::bgr8:
m_fb.type = kernel::args::fb_type::bgr8;
m_fb.type = kernel::init::fb_type::bgr8;
break;
default:
m_fb.type = kernel::args::fb_type::none;
m_fb.type = kernel::init::fb_type::none;
}
}
}

View File

@@ -14,7 +14,7 @@ namespace boot {
class console
{
public:
using framebuffer = kernel::args::framebuffer;
using framebuffer = kernel::init::framebuffer;
console(uefi::boot_services *bs, uefi::protos::simple_text_output *out);

View File

@@ -10,7 +10,7 @@
#include "paging.h"
#include "status.h"
namespace args = kernel::args;
namespace init = kernel::init;
namespace boot {
namespace loader {
@@ -49,7 +49,7 @@ is_elfheader_valid(const elf::header *header)
void
load_program(
args::program &program,
init::program &program,
const wchar_t *name,
buffer data,
uefi::boot_services *bs)
@@ -98,7 +98,7 @@ load_program(
if (pheader->type != elf::PT_LOAD)
continue;
args::program_section &section = program.sections[program.num_sections++];
init::program_section &section = program.sections[program.num_sections++];
void *src_start = offset_ptr<void>(data.data, pheader->offset);
void *dest_start = offset_ptr<void>(pages, pheader->vaddr - prog_base);
@@ -107,7 +107,7 @@ load_program(
section.phys_addr = reinterpret_cast<uintptr_t>(dest_start);
section.virt_addr = pheader->vaddr;
section.size = pheader->mem_size;
section.type = static_cast<args::section_flags>(pheader->flags);
section.type = static_cast<init::section_flags>(pheader->flags);
}
program.entrypoint = header->entrypoint;

View File

@@ -28,11 +28,12 @@ load_file(
/// Parse and load an ELF file in memory into a loaded image.
/// \arg program The program structure to fill
/// \arg name The name of the program being loaded
/// \arg data Buffer of the ELF file in memory
/// \arg bs Boot services
void
load_program(
kernel::args::program &program,
kernel::init::program &program,
const wchar_t *name,
buffer data,
uefi::boot_services *bs);

View File

@@ -23,7 +23,7 @@ namespace kernel {
#include "kernel_memory.h"
}
namespace args = kernel::args;
namespace init = kernel::init;
namespace boot {
@@ -52,7 +52,7 @@ void change_pointer(T *&pointer)
/// Allocate space for kernel args. Allocates enough space from pool
/// memory for the args header and the module and program headers.
args::header *
init::args *
allocate_args_structure(
uefi::boot_services *bs,
size_t max_modules,
@@ -60,12 +60,12 @@ allocate_args_structure(
{
status_line status {L"Setting up kernel args memory"};
args::header *args = nullptr;
init::args *args = nullptr;
size_t args_size =
sizeof(args::header) + // The header itself
max_modules * sizeof(args::module) + // The module structures
max_programs * sizeof(args::program); // The program structures
sizeof(init::args) + // The header itself
max_modules * sizeof(init::module) + // The module structures
max_programs * sizeof(init::program); // The program structures
try_or_raise(
bs->allocate_pool(uefi::memory_type::loader_data, args_size,
@@ -75,11 +75,11 @@ allocate_args_structure(
bs->set_mem(args, args_size, 0);
args->modules =
reinterpret_cast<args::module*>(args + 1);
reinterpret_cast<init::module*>(args + 1);
args->num_modules = 0;
args->programs =
reinterpret_cast<args::program*>(args->modules + max_modules);
reinterpret_cast<init::program*>(args->modules + max_modules);
args->num_programs = 0;
return args;
@@ -87,9 +87,9 @@ allocate_args_structure(
/// Add a module to the kernel args list
inline void
add_module(args::header *args, args::mod_type type, buffer &data)
add_module(init::args *args, init::mod_type type, buffer &data)
{
args::module &m = args->modules[args->num_modules++];
init::module &m = args->modules[args->num_modules++];
m.type = type;
m.location = data.data;
m.size = data.size;
@@ -122,7 +122,7 @@ check_cpu_supported()
/// 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.
args::header *
init::args *
uefi_preboot(uefi::handle image, uefi::system_table *st)
{
status_line status {L"Performing UEFI pre-boot"};
@@ -131,11 +131,11 @@ uefi_preboot(uefi::handle image, uefi::system_table *st)
uefi::runtime_services *rs = st->runtime_services;
memory::init_pointer_fixup(bs, rs);
args::header *args =
init::args *args =
allocate_args_structure(bs, max_modules, max_programs);
args->magic = args::magic;
args->version = args::version;
args->magic = init::magic;
args->version = init::version;
args->runtime_services = rs;
args->acpi_table = hw::find_acpi_table(st);
paging::allocate_tables(args, bs);
@@ -146,11 +146,11 @@ uefi_preboot(uefi::handle image, uefi::system_table *st)
buffer symbols = loader::load_file(disk, L"symbol table", L"symbol_table.dat",
uefi::memory_type::loader_data);
add_module(args, args::mod_type::symbol_table, symbols);
add_module(args, init::mod_type::symbol_table, symbols);
for (auto &desc : program_list) {
buffer buf = loader::load_file(disk, desc.name, desc.path);
args::program &program = args->programs[args->num_programs++];
init::program &program = args->programs[args->num_programs++];
loader::load_program(program, desc.name, buf, bs);
}
@@ -158,7 +158,7 @@ uefi_preboot(uefi::handle image, uefi::system_table *st)
}
memory::efi_mem_map
uefi_exit(args::header *args, uefi::handle image, uefi::boot_services *bs)
uefi_exit(init::args *args, uefi::handle image, uefi::boot_services *bs)
{
status_line status {L"Exiting UEFI", nullptr, false};
@@ -182,14 +182,14 @@ efi_main(uefi::handle image, uefi::system_table *st)
console con(st->boot_services, st->con_out);
check_cpu_supported();
args::header *args = uefi_preboot(image, st);
init::args *args = uefi_preboot(image, st);
memory::efi_mem_map map = uefi_exit(args, image, st->boot_services);
args->video = con.fb();
status_bar status {con.fb()}; // Switch to fb status display
// Map the kernel to the appropriate address
args::program &kernel = args->programs[0];
init::program &kernel = args->programs[0];
for (auto &section : kernel.sections)
if (section.size)
paging::map_section(args, section);

View File

@@ -12,10 +12,10 @@
namespace boot {
namespace memory {
using mem_entry = kernel::args::mem_entry;
using mem_type = kernel::args::mem_type;
using frame_block = kernel::args::frame_block;
using kernel::args::frames_per_block;
using mem_entry = kernel::init::mem_entry;
using mem_type = kernel::init::mem_type;
using frame_block = kernel::init::frame_block;
using kernel::init::frames_per_block;
size_t fixup_pointer_index = 0;
void **fixup_pointers[64];
@@ -57,7 +57,7 @@ memory_type_name(uefi::memory_type t)
}
static const wchar_t *
kernel_memory_type_name(kernel::args::mem_type t)
kernel_memory_type_name(kernel::init::mem_type t)
{
return kernel_memory_type_names[static_cast<uint32_t>(t)];
}
@@ -146,7 +146,7 @@ inline size_t bitmap_size(size_t frames) { return (frames + 63) / 64; }
inline size_t num_blocks(size_t frames) { return (frames + (frames_per_block-1)) / frames_per_block; }
void
build_kernel_frame_blocks(const mem_entry *map, size_t nent, kernel::args::header *args, uefi::boot_services *bs)
build_kernel_frame_blocks(const mem_entry *map, size_t nent, kernel::init::args *args, uefi::boot_services *bs)
{
status_line status {L"Creating kernel frame accounting map"};
@@ -230,7 +230,7 @@ build_kernel_frame_blocks(const mem_entry *map, size_t nent, kernel::args::heade
}
void
fix_frame_blocks(kernel::args::header *args)
fix_frame_blocks(kernel::init::args *args)
{
// Map the frame blocks to the appropriate address
paging::map_pages(args,
@@ -250,7 +250,7 @@ fix_frame_blocks(kernel::args::header *args)
}
efi_mem_map
build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs)
build_kernel_mem_map(kernel::init::args *args, uefi::boot_services *bs)
{
status_line status {L"Creating kernel memory map"};
@@ -259,7 +259,7 @@ build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs)
size_t map_size = map.num_entries() * sizeof(mem_entry);
kernel::args::mem_entry *kernel_map = nullptr;
mem_entry *kernel_map = nullptr;
try_or_raise(
bs->allocate_pages(
uefi::allocate_type::any_pages,
@@ -350,7 +350,7 @@ build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs)
/*
// kernel map dump
for (unsigned i = 0; i < nent; ++i) {
const kernel::args::mem_entry &e = kernel_map[i];
const mem_entry &e = kernel_map[i];
console::print(L" kRange %lx (%lx) %x(%s) [%lu]\r\n",
e.start, e.attr, e.type, kernel_memory_type_name(e.type), e.pages);
}

View File

@@ -61,15 +61,15 @@ struct efi_mem_map
/// Add the kernel's memory map as a module to the kernel args.
/// \returns The uefi memory map used to build the kernel map
efi_mem_map build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs);
efi_mem_map build_kernel_mem_map(kernel::init::args *args, uefi::boot_services *bs);
/// Create the kernel frame allocation maps
void build_kernel_frame_blocks(
const kernel::args::mem_entry *map, size_t nent,
kernel::args::header *args, uefi::boot_services *bs);
const kernel::init::mem_entry *map, size_t nent,
kernel::init::args *args, uefi::boot_services *bs);
/// Map the frame allocation maps to the right spot and fix up pointers
void fix_frame_blocks(kernel::args::header *args);
void fix_frame_blocks(kernel::init::args *args);
/// Activate the given memory mappings. Sets the given page tables live as well
/// as informs UEFI runtime services of the new mappings.

View File

@@ -186,7 +186,7 @@ add_current_mappings(page_table *new_pml4)
}
void
allocate_tables(kernel::args::header *args, uefi::boot_services *bs)
allocate_tables(kernel::init::args *args, uefi::boot_services *bs)
{
status_line status(L"Allocating initial page tables");
@@ -233,7 +233,7 @@ constexpr bool has_flag(E set, E flag) {
void
map_pages(
kernel::args::header *args,
kernel::init::args *args,
uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag)
{
@@ -266,10 +266,10 @@ map_pages(
void
map_section(
kernel::args::header *args,
const kernel::args::program_section &section)
kernel::init::args *args,
const kernel::init::program_section &section)
{
using kernel::args::section_flags;
using kernel::init::section_flags;
size_t pages = memory::bytes_to_pages(section.size);

View File

@@ -29,30 +29,36 @@ struct page_table
/// page tables are pre-filled. All pages are saved as a module in kernel args
/// and kernel args' `page_table_cache` and `num_free_tables` are updated with
/// the leftover space.
/// \arg args The kernel args struct, used for the page table cache and pml4
void allocate_tables(
kernel::args::header *args,
kernel::init::args *args,
uefi::boot_services *bs);
/// Copy existing page table entries to a new page table. Does not do a deep
/// copy - the new PML4 is updated to point to the existing next-level page
/// tables in the current PML4.
/// \arg new_pml4 The new PML4 to copy into
void add_current_mappings(page_table *new_pml4);
/// Map physical memory pages to virtual addresses in the given page tables.
/// \arg args The kernel args header, used for the page table cache and pml4
/// \arg section The program section to load
/// \arg args The kernel args struct, used for the page table cache and pml4
/// \arg phys The physical address of the pages to map
/// \arg virt The virtual address at which to map the pages
/// \arg count The number of pages to map
/// \arg write_flag If true, mark the pages writeable
/// \arg exe_flag If true, mark the pages executable
void map_pages(
kernel::args::header *args,
kernel::init::args *args,
uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag);
/// Map a program section in physical memory to its virtual address in the
/// given page tables.
/// \arg args The kernel args header, used for the page table cache and pml4
/// \arg args The kernel args struct, used for the page table cache and pml4
/// \arg section The program section to load
void map_section(
kernel::args::header *args,
const kernel::args::program_section &section);
kernel::init::args *args,
const kernel::init::program_section &section);
} // namespace paging

View File

@@ -148,7 +148,7 @@ status_line::do_fail(const wchar_t *message, uefi::status status)
status_bar::status_bar(kernel::args::framebuffer const &fb) :
status_bar::status_bar(kernel::init::framebuffer const &fb) :
status(fb.size),
m_outer(nullptr)
{
@@ -196,14 +196,14 @@ status_bar::do_fail(const wchar_t *message, uefi::status status)
static uint32_t
make_color(uint8_t r, uint8_t g, uint8_t b, uint16_t type)
{
switch (static_cast<kernel::args::fb_type>(type)) {
case kernel::args::fb_type::bgr8:
switch (static_cast<kernel::init::fb_type>(type)) {
case kernel::init::fb_type::bgr8:
return
(static_cast<uint32_t>(b) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(r) << 16);
case kernel::args::fb_type::rgb8:
case kernel::init::fb_type::rgb8:
return
(static_cast<uint32_t>(r) << 0) |
(static_cast<uint32_t>(g) << 8) |

View File

@@ -6,7 +6,7 @@
#include <uefi/types.h>
namespace kernel {
namespace args {
namespace init {
class framebuffer;
}
}
@@ -92,11 +92,11 @@ class status_bar :
public:
constexpr static unsigned type = 2;
using framebuffer = kernel::args::framebuffer;
using framebuffer = kernel::init::framebuffer;
/// Constructor.
/// \arg fb The framebuffer descriptor to draw to
status_bar(kernel::args::framebuffer const &fb);
status_bar(kernel::init::framebuffer const &fb);
~status_bar();
virtual void do_warn(const wchar_t *message, uefi::status status) override;