aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kapi/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/kapi/memory.cpp')
-rw-r--r--arch/x86_64/src/kapi/memory.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp
index d09a4c1..ed3edef 100644
--- a/arch/x86_64/src/kapi/memory.cpp
+++ b/arch/x86_64/src/kapi/memory.cpp
@@ -1,11 +1,14 @@
#include "kapi/memory.hpp"
+#include "kapi/cio.hpp"
#include "kapi/system.hpp"
#include "x86_64/boot/boot.hpp"
#include "x86_64/boot/ld.hpp"
+#include "x86_64/cpu/impl/control_registers.hpp"
#include "x86_64/cpu/registers.hpp"
#include "x86_64/memory/buffered_allocator.hpp"
+#include "x86_64/memory/kernel_mapper.hpp"
#include "x86_64/memory/mmu.hpp"
#include "x86_64/memory/page_table.hpp"
#include "x86_64/memory/page_utilities.hpp"
@@ -60,7 +63,7 @@ namespace teachos::memory
}
//! Inject, or graft, a faux recursive PML4 into the active page mapping structure.
- auto inject_faux_pml4(frame_allocator & allocator) -> void
+ auto inject_faux_pml4(frame_allocator & allocator)
{
using namespace x86_64;
using entry_flags = page_table::entry::flags;
@@ -105,6 +108,8 @@ namespace teachos::memory
auto new_pml1 = (**new_pml2).next(pml2_index);
(**new_pml1)[pml1_index] = pml1_entry;
+
+ return *new_pml4_frame;
}
} // namespace
@@ -131,12 +136,15 @@ namespace teachos::memory
enable_cpu_protections();
auto allocation_buffer = x86_64::buffered_allocator<4>{&allocator};
- inject_faux_pml4(allocation_buffer);
+ auto new_pml4_frame = inject_faux_pml4(allocation_buffer);
- // paging::kernel_mapper kernel(allocator, memory_information);
- // kernel.remap_kernel();
- // video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black);
- // video::vga::text::newline();
+ auto mapper = x86_64::kernel_mapper{allocation_buffer, boot::bootstrap_information.mbi};
+ mapper.remap_kernel();
+ cio::println("[x86_64:MEM] prepared new kernel image page maps.");
+
+ auto cr3 = cpu::x86_64::cr3::read();
+ cr3.address(new_pml4_frame.start_address());
+ cpu::x86_64::cr3::write(cr3);
// remap_heap(heap::KERNEL_HEAP_START, heap::KERNEL_HEAP_SIZE);
// video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black);