Recursively map the PML4
This commit is contained in:
parent
b3f8cb9003
commit
45b5817a36
|
@ -5,6 +5,7 @@ add_executable(zion
|
||||||
debug/debug.cpp
|
debug/debug.cpp
|
||||||
interrupt/interrupt.cpp
|
interrupt/interrupt.cpp
|
||||||
interrupt/interrupt_enter.s
|
interrupt/interrupt_enter.s
|
||||||
|
memory/paging_util.cpp
|
||||||
zion.cpp)
|
zion.cpp)
|
||||||
|
|
||||||
target_include_directories(zion
|
target_include_directories(zion
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "memory/paging_util.h"
|
||||||
|
|
||||||
|
#include "boot/boot_info.h"
|
||||||
|
|
||||||
|
#define PRESENT_BIT 0x1
|
||||||
|
#define READ_WRITE_BIT 0x2
|
||||||
|
|
||||||
|
void InitPaging() {
|
||||||
|
uint64_t pml4_addr = 0;
|
||||||
|
asm volatile("mov %%cr3, %0;" : "=r"(pml4_addr));
|
||||||
|
InitializePml4(pml4_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitializePml4(uint64_t pml4_physical_addr) {
|
||||||
|
uint64_t* pml4_virtual = reinterpret_cast<uint64_t*>(
|
||||||
|
boot::GetHigherHalfDirectMap() + pml4_physical_addr);
|
||||||
|
|
||||||
|
uint64_t recursive_entry = pml4_physical_addr | PRESENT_BIT | READ_WRITE_BIT;
|
||||||
|
pml4_virtual[0x1FE] = recursive_entry;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void InitPaging();
|
||||||
|
void InitializePml4(uint64_t pml4_physical_addr);
|
|
@ -5,10 +5,12 @@
|
||||||
#include "common/gdt.h"
|
#include "common/gdt.h"
|
||||||
#include "debug/debug.h"
|
#include "debug/debug.h"
|
||||||
#include "interrupt/interrupt.h"
|
#include "interrupt/interrupt.h"
|
||||||
|
#include "memory/paging_util.h"
|
||||||
|
|
||||||
extern "C" void zion() {
|
extern "C" void zion() {
|
||||||
InitGdt();
|
InitGdt();
|
||||||
InitIdt();
|
InitIdt();
|
||||||
|
InitPaging();
|
||||||
|
|
||||||
const limine_memmap_response& resp = boot::GetMemoryMap();
|
const limine_memmap_response& resp = boot::GetMemoryMap();
|
||||||
dbgln("Base,Length,Type");
|
dbgln("Base,Length,Type");
|
||||||
|
|
Loading…
Reference in New Issue