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

View File

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

View File

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

View File

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

View File

@@ -12,10 +12,10 @@
namespace boot { namespace boot {
namespace memory { namespace memory {
using mem_entry = kernel::args::mem_entry; using mem_entry = kernel::init::mem_entry;
using mem_type = kernel::args::mem_type; using mem_type = kernel::init::mem_type;
using frame_block = kernel::args::frame_block; using frame_block = kernel::init::frame_block;
using kernel::args::frames_per_block; using kernel::init::frames_per_block;
size_t fixup_pointer_index = 0; size_t fixup_pointer_index = 0;
void **fixup_pointers[64]; void **fixup_pointers[64];
@@ -57,7 +57,7 @@ memory_type_name(uefi::memory_type t)
} }
static const wchar_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)]; 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; } inline size_t num_blocks(size_t frames) { return (frames + (frames_per_block-1)) / frames_per_block; }
void 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"}; 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 void
fix_frame_blocks(kernel::args::header *args) fix_frame_blocks(kernel::init::args *args)
{ {
// Map the frame blocks to the appropriate address // Map the frame blocks to the appropriate address
paging::map_pages(args, paging::map_pages(args,
@@ -250,7 +250,7 @@ fix_frame_blocks(kernel::args::header *args)
} }
efi_mem_map 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"}; 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); 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( try_or_raise(
bs->allocate_pages( bs->allocate_pages(
uefi::allocate_type::any_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 // kernel map dump
for (unsigned i = 0; i < nent; ++i) { 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", 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); 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. /// Add the kernel's memory map as a module to the kernel args.
/// \returns The uefi memory map used to build the kernel map /// \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 /// Create the kernel frame allocation maps
void build_kernel_frame_blocks( void build_kernel_frame_blocks(
const kernel::args::mem_entry *map, size_t nent, const kernel::init::mem_entry *map, size_t nent,
kernel::args::header *args, uefi::boot_services *bs); kernel::init::args *args, uefi::boot_services *bs);
/// Map the frame allocation maps to the right spot and fix up pointers /// 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 /// Activate the given memory mappings. Sets the given page tables live as well
/// as informs UEFI runtime services of the new mappings. /// as informs UEFI runtime services of the new mappings.

View File

@@ -186,7 +186,7 @@ add_current_mappings(page_table *new_pml4)
} }
void 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"); status_line status(L"Allocating initial page tables");
@@ -233,7 +233,7 @@ constexpr bool has_flag(E set, E flag) {
void void
map_pages( map_pages(
kernel::args::header *args, kernel::init::args *args,
uintptr_t phys, uintptr_t virt, uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag) size_t count, bool write_flag, bool exe_flag)
{ {
@@ -266,10 +266,10 @@ map_pages(
void void
map_section( map_section(
kernel::args::header *args, kernel::init::args *args,
const kernel::args::program_section &section) 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); 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 /// 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 /// and kernel args' `page_table_cache` and `num_free_tables` are updated with
/// the leftover space. /// the leftover space.
/// \arg args The kernel args struct, used for the page table cache and pml4
void allocate_tables( void allocate_tables(
kernel::args::header *args, kernel::init::args *args,
uefi::boot_services *bs); uefi::boot_services *bs);
/// Copy existing page table entries to a new page table. Does not do a deep /// 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 /// copy - the new PML4 is updated to point to the existing next-level page
/// tables in the current PML4. /// tables in the current PML4.
/// \arg new_pml4 The new PML4 to copy into
void add_current_mappings(page_table *new_pml4); void add_current_mappings(page_table *new_pml4);
/// Map physical memory pages to virtual addresses in the given page tables. /// 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 args The kernel args struct, used for the page table cache and pml4
/// \arg section The program section to load /// \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( void map_pages(
kernel::args::header *args, kernel::init::args *args,
uintptr_t phys, uintptr_t virt, uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag); size_t count, bool write_flag, bool exe_flag);
/// Map a program section in physical memory to its virtual address in the /// Map a program section in physical memory to its virtual address in the
/// given page tables. /// 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 /// \arg section The program section to load
void map_section( void map_section(
kernel::args::header *args, kernel::init::args *args,
const kernel::args::program_section &section); const kernel::init::program_section &section);
} // namespace paging } // 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), status(fb.size),
m_outer(nullptr) m_outer(nullptr)
{ {
@@ -196,14 +196,14 @@ status_bar::do_fail(const wchar_t *message, uefi::status status)
static uint32_t static uint32_t
make_color(uint8_t r, uint8_t g, uint8_t b, uint16_t type) make_color(uint8_t r, uint8_t g, uint8_t b, uint16_t type)
{ {
switch (static_cast<kernel::args::fb_type>(type)) { switch (static_cast<kernel::init::fb_type>(type)) {
case kernel::args::fb_type::bgr8: case kernel::init::fb_type::bgr8:
return return
(static_cast<uint32_t>(b) << 0) | (static_cast<uint32_t>(b) << 0) |
(static_cast<uint32_t>(g) << 8) | (static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(r) << 16); (static_cast<uint32_t>(r) << 16);
case kernel::args::fb_type::rgb8: case kernel::init::fb_type::rgb8:
return return
(static_cast<uint32_t>(r) << 0) | (static_cast<uint32_t>(r) << 0) |
(static_cast<uint32_t>(g) << 8) | (static_cast<uint32_t>(g) << 8) |

View File

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

View File

@@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
namespace kernel { namespace kernel {
namespace args { namespace init {
constexpr uint32_t magic = 0x600dda7a; constexpr uint32_t magic = 0x600dda7a;
constexpr uint16_t version = 1; constexpr uint16_t version = 1;
@@ -92,7 +92,7 @@ enum class boot_flags : uint16_t {
debug = 0x0001 debug = 0x0001
}; };
struct header { struct args {
uint32_t magic; uint32_t magic;
uint16_t version; uint16_t version;
boot_flags flags; boot_flags flags;
@@ -122,8 +122,8 @@ struct header {
} }
__attribute__((aligned(alignof(max_align_t)))); __attribute__((aligned(alignof(max_align_t))));
} // namespace args } // namespace init
using entrypoint = __attribute__((sysv_abi)) void (*)(args::header *); using entrypoint = __attribute__((sysv_abi)) void (*)(init::args *);
} // namespace kernel } // namespace kernel

View File

@@ -16,7 +16,7 @@ frame_allocator::get()
return g_frame_allocator; 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_blocks {frames},
m_count {count} m_count {count}
{ {

View File

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

View File

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

View File

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