[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

@@ -16,7 +16,7 @@ frame_allocator::get()
return g_frame_allocator;
}
frame_allocator::frame_allocator(kernel::args::frame_block *frames, size_t count) :
frame_allocator::frame_allocator(kernel::init::frame_block *frames, size_t count) :
m_blocks {frames},
m_count {count}
{

View File

@@ -6,7 +6,7 @@
#include "kutil/spinlock.h"
namespace kernel {
namespace args {
namespace init {
struct frame_block;
}}
@@ -14,7 +14,7 @@ namespace args {
class frame_allocator
{
public:
using frame_block = kernel::args::frame_block;
using frame_block = kernel::init::frame_block;
/// Constructor
/// \arg blocks The bootloader-supplied frame bitmap block list

View File

@@ -34,7 +34,7 @@
#endif
extern "C" {
void kernel_main(kernel::args::header *header);
void kernel_main(kernel::init::args *args);
void (*__ctors)(void);
void (*__ctors_end)(void);
void long_ap_startup(cpu_data *cpu);
@@ -51,14 +51,14 @@ volatile size_t ap_startup_count;
static bool scheduler_ready = false;
/// Bootstrap the memory managers.
void memory_initialize_pre_ctors(args::header &kargs);
void memory_initialize_post_ctors(args::header &kargs);
process * load_simple_process(args::program &program);
void memory_initialize_pre_ctors(init::args &kargs);
void memory_initialize_post_ctors(init::args &kargs);
process * load_simple_process(init::program &program);
unsigned start_aps(lapic &apic, const kutil::vector<uint8_t> &ids, void *kpml4);
/// TODO: not this. this is awful.
args::framebuffer *fb = nullptr;
init::framebuffer *fb = nullptr;
void
init_console()
@@ -83,7 +83,7 @@ run_constructors()
}
void
kernel_main(args::header *header)
kernel_main(init::args *args)
{
kutil::assert_set_callback(__kernel_assert);
@@ -92,11 +92,11 @@ kernel_main(args::header *header)
cpu_validate();
log::debug(logs::boot, " jsix header is at: %016lx", header);
log::debug(logs::boot, " Memory map is at: %016lx", header->mem_map);
log::debug(logs::boot, "ACPI root table is at: %016lx", header->acpi_table);
log::debug(logs::boot, "Runtime service is at: %016lx", header->runtime_services);
log::debug(logs::boot, " Kernel PML4 is at: %016lx", header->pml4);
log::debug(logs::boot, "jsix init args are at: %016lx", args);
log::debug(logs::boot, " Memory map is at: %016lx", args->mem_map);
log::debug(logs::boot, "ACPI root table is at: %016lx", args->acpi_table);
log::debug(logs::boot, "Runtime service is at: %016lx", args->runtime_services);
log::debug(logs::boot, " Kernel PML4 is at: %016lx", args->pml4);
uint64_t cr0, cr4;
asm ("mov %%cr0, %0" : "=r"(cr0));
@@ -105,11 +105,11 @@ kernel_main(args::header *header)
log::debug(logs::boot, "Control regs: cr0:%lx cr4:%lx efer:%lx", cr0, cr4, efer);
bool has_video = false;
if (header->video.size > 0) {
if (args->video.size > 0) {
has_video = true;
fb = &header->video;
fb = &args->video;
const args::framebuffer &video = header->video;
const init::framebuffer &video = args->video;
log::debug(logs::boot, "Framebuffer: %dx%d[%d] type %d @ %llx size %llx",
video.horizontal,
video.vertical,
@@ -138,17 +138,17 @@ kernel_main(args::header *header)
disable_legacy_pic();
memory_initialize_pre_ctors(*header);
memory_initialize_pre_ctors(*args);
run_constructors();
memory_initialize_post_ctors(*header);
memory_initialize_post_ctors(*args);
cpu->tss->create_ist_stacks(cpu->idt->used_ist_entries());
for (size_t i = 0; i < header->num_modules; ++i) {
args::module &mod = header->modules[i];
for (size_t i = 0; i < args->num_modules; ++i) {
init::module &mod = args->modules[i];
switch (mod.type) {
case args::mod_type::symbol_table:
case init::mod_type::symbol_table:
new symbol_table {mod.location, mod.size};
break;
@@ -160,7 +160,7 @@ kernel_main(args::header *header)
syscall_initialize();
device_manager &devices = device_manager::get();
devices.parse_acpi(header->acpi_table);
devices.parse_acpi(args->acpi_table);
// Need the local APIC to get the BSP's id
uintptr_t apic_base = devices.get_lapic_base();
@@ -177,7 +177,7 @@ kernel_main(args::header *header)
apic->calibrate_timer();
const auto &apic_ids = devices.get_apic_ids();
unsigned num_cpus = start_aps(*apic, apic_ids, header->pml4);
unsigned num_cpus = start_aps(*apic, apic_ids, args->pml4);
interrupts_enable();
@@ -209,8 +209,8 @@ kernel_main(args::header *header)
scheduler_ready = true;
// Skip program 0, which is the kernel itself
for (unsigned i = 1; i < header->num_programs; ++i)
load_simple_process(header->programs[i]);
for (unsigned i = 1; i < args->num_programs; ++i)
load_simple_process(args->programs[i]);
if (!has_video)
sched->create_kernel_task(logger_task, scheduler::max_priority/2, true);

View File

@@ -4,6 +4,7 @@
#include "j6/init.h"
#include "kutil/assert.h"
#include "kutil/enum_bitfields.h"
#include "kutil/heap_allocator.h"
#include "kutil/no_construct.h"
@@ -22,13 +23,15 @@
using memory::heap_start;
using memory::kernel_max_heap;
using namespace kernel;
namespace kernel {
namespace args {
is_bitfield(section_flags);
namespace init {
is_bitfield(section_flags);
}}
using kernel::init::section_flags;
using namespace kernel;
extern "C" void initialize_main_thread();
extern "C" uintptr_t initialize_main_user_stack();
@@ -70,9 +73,9 @@ get_physical_page(T *p) {
}
void
memory_initialize_pre_ctors(args::header &kargs)
memory_initialize_pre_ctors(init::args &kargs)
{
using kernel::args::frame_block;
using kernel::init::frame_block;
page_table *kpml4 = static_cast<page_table*>(kargs.pml4);
@@ -95,14 +98,14 @@ memory_initialize_pre_ctors(args::header &kargs)
kargs.table_pages);
for (unsigned i = 0; i < kargs.num_modules; ++i) {
const kernel::args::module &mod = kargs.modules[i];
const kernel::init::module &mod = kargs.modules[i];
g_frame_allocator.used(
get_physical_page(mod.location),
memory::page_count(mod.size));
}
for (unsigned i = 0; i < kargs.num_programs; ++i) {
const kernel::args::program &prog = kargs.programs[i];
const kernel::init::program &prog = kargs.programs[i];
for (auto &sect : prog.sections) {
if (!sect.size) continue;
g_frame_allocator.used(
@@ -132,7 +135,7 @@ memory_initialize_pre_ctors(args::header &kargs)
}
void
memory_initialize_post_ctors(args::header &kargs)
memory_initialize_post_ctors(init::args &kargs)
{
vm_space &vm = vm_space::kernel_space();
vm.add(memory::buffers_start, &g_kernel_buffers);
@@ -199,9 +202,8 @@ log_mtrrs()
process *
load_simple_process(args::program &program)
load_simple_process(init::program &program)
{
using kernel::args::section_flags;
process *p = new process;
vm_space &space = p->space();
@@ -247,7 +249,7 @@ initialize_main_user_stack()
j6_init_value *initv = nullptr;
unsigned n = 0;
extern args::framebuffer *fb;
extern init::framebuffer *fb;
if (fb) {
j6_init_framebuffer *fb_desc = push<j6_init_framebuffer>(tcb->rsp3);
kutil::memset(fb_desc, 0, sizeof(j6_init_framebuffer));
@@ -258,7 +260,7 @@ initialize_main_user_stack()
fb_desc->horizontal = fb->horizontal;
fb_desc->scanline = fb->scanline;
if (fb->type == kernel::args::fb_type::bgr8)
if (fb->type == kernel::init::fb_type::bgr8)
fb_desc->flags |= 1;
initv = push<j6_init_value>(tcb->rsp3);