mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[boot] Do address virtualization in the bootloader
More and more places in the kernel init code are taking addresses from the bootloader and translating them to offset-mapped addresses. The bootloader can do this, so it should.
This commit is contained in:
@@ -93,6 +93,8 @@ add_module(args::header *args, args::mod_type type, buffer &data)
|
|||||||
m.type = type;
|
m.type = type;
|
||||||
m.location = data.data;
|
m.location = data.data;
|
||||||
m.size = data.size;
|
m.size = data.size;
|
||||||
|
|
||||||
|
change_pointer(m.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check that all required cpu features are supported
|
/// Check that all required cpu features are supported
|
||||||
@@ -198,12 +200,15 @@ efi_main(uefi::handle image, uefi::system_table *st)
|
|||||||
reinterpret_cast<kernel::entrypoint>(kernel.entrypoint);
|
reinterpret_cast<kernel::entrypoint>(kernel.entrypoint);
|
||||||
status.next();
|
status.next();
|
||||||
|
|
||||||
|
|
||||||
hw::setup_control_regs();
|
hw::setup_control_regs();
|
||||||
memory::virtualize(args->pml4, map, st->runtime_services);
|
memory::virtualize(args->pml4, map, st->runtime_services);
|
||||||
status.next();
|
status.next();
|
||||||
|
|
||||||
|
change_pointer(args);
|
||||||
change_pointer(args->pml4);
|
change_pointer(args->pml4);
|
||||||
|
change_pointer(args->modules);
|
||||||
|
change_pointer(args->programs);
|
||||||
|
|
||||||
status.next();
|
status.next();
|
||||||
|
|
||||||
kentry(args);
|
kentry(args);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ kernel_main(args::header *header)
|
|||||||
bool has_video = false;
|
bool has_video = false;
|
||||||
if (header->video.size > 0) {
|
if (header->video.size > 0) {
|
||||||
has_video = true;
|
has_video = true;
|
||||||
fb = memory::to_virtual<args::framebuffer>(reinterpret_cast<uintptr_t>(&header->video));
|
fb = &header->video;
|
||||||
|
|
||||||
const args::framebuffer &video = header->video;
|
const args::framebuffer &video = header->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",
|
||||||
@@ -143,11 +143,10 @@ kernel_main(args::header *header)
|
|||||||
|
|
||||||
for (size_t i = 0; i < header->num_modules; ++i) {
|
for (size_t i = 0; i < header->num_modules; ++i) {
|
||||||
args::module &mod = header->modules[i];
|
args::module &mod = header->modules[i];
|
||||||
void *virt = memory::to_virtual<void>(mod.location);
|
|
||||||
|
|
||||||
switch (mod.type) {
|
switch (mod.type) {
|
||||||
case args::mod_type::symbol_table:
|
case args::mod_type::symbol_table:
|
||||||
new symbol_table {virt, mod.size};
|
new symbol_table {mod.location, mod.size};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -58,15 +58,18 @@ namespace kutil {
|
|||||||
void kfree(void *p) { return g_kernel_heap.free(p); }
|
void kfree(void *p) { return g_kernel_heap.free(p); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
uintptr_t
|
||||||
|
get_physical_page(T *p) {
|
||||||
|
return memory::page_align_down(reinterpret_cast<uintptr_t>(p));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
memory_initialize_pre_ctors(args::header &kargs)
|
memory_initialize_pre_ctors(args::header &kargs)
|
||||||
{
|
{
|
||||||
using kernel::args::frame_block;
|
using kernel::args::frame_block;
|
||||||
|
|
||||||
// Clean out any remaning bootloader page table entries
|
|
||||||
page_table *kpml4 = static_cast<page_table*>(kargs.pml4);
|
page_table *kpml4 = static_cast<page_table*>(kargs.pml4);
|
||||||
for (unsigned i = 0; i < memory::pml4e_kernel; ++i)
|
|
||||||
kpml4->entries[i] = 0;
|
|
||||||
|
|
||||||
new (&g_kernel_heap) kutil::heap_allocator {heap_start, kernel_max_heap};
|
new (&g_kernel_heap) kutil::heap_allocator {heap_start, kernel_max_heap};
|
||||||
|
|
||||||
@@ -75,17 +78,21 @@ memory_initialize_pre_ctors(args::header &kargs)
|
|||||||
|
|
||||||
// Mark all the things the bootloader allocated for us as used
|
// Mark all the things the bootloader allocated for us as used
|
||||||
g_frame_allocator.used(
|
g_frame_allocator.used(
|
||||||
reinterpret_cast<uintptr_t>(kargs.frame_blocks),
|
get_physical_page(&kargs),
|
||||||
|
memory::page_count(sizeof(kargs)));
|
||||||
|
|
||||||
|
g_frame_allocator.used(
|
||||||
|
get_physical_page(kargs.frame_blocks),
|
||||||
kargs.frame_block_pages);
|
kargs.frame_block_pages);
|
||||||
|
|
||||||
g_frame_allocator.used(
|
g_frame_allocator.used(
|
||||||
reinterpret_cast<uintptr_t>(kargs.pml4),
|
get_physical_page(kargs.pml4),
|
||||||
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::args::module &mod = kargs.modules[i];
|
||||||
g_frame_allocator.used(
|
g_frame_allocator.used(
|
||||||
reinterpret_cast<uintptr_t>(mod.location),
|
get_physical_page(mod.location),
|
||||||
memory::page_count(mod.size));
|
memory::page_count(mod.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +120,10 @@ memory_initialize_pre_ctors(args::header &kargs)
|
|||||||
memory::kernel_max_stacks,
|
memory::kernel_max_stacks,
|
||||||
vm_flags::write};
|
vm_flags::write};
|
||||||
vm.add(memory::stacks_start, &g_kernel_stacks);
|
vm.add(memory::stacks_start, &g_kernel_stacks);
|
||||||
|
|
||||||
|
// Clean out any remaning bootloader page table entries
|
||||||
|
for (unsigned i = 0; i < memory::pml4e_kernel; ++i)
|
||||||
|
kpml4->entries[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -122,7 +133,7 @@ memory_initialize_post_ctors(args::header &kargs)
|
|||||||
vm.add(memory::buffers_start, &g_kernel_buffers);
|
vm.add(memory::buffers_start, &g_kernel_buffers);
|
||||||
|
|
||||||
g_frame_allocator.free(
|
g_frame_allocator.free(
|
||||||
reinterpret_cast<uintptr_t>(kargs.page_tables),
|
get_physical_page(kargs.page_tables),
|
||||||
kargs.table_count);
|
kargs.table_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user