Kernel: MMU keeps track of the current

This commit is contained in:
Bananymous 2023-05-16 00:26:13 +03:00
parent d82c6c2337
commit 31ac3260ed
2 changed files with 10 additions and 0 deletions

View File

@ -18,6 +18,7 @@ namespace Kernel
{ {
static MMU* s_instance = nullptr; static MMU* s_instance = nullptr;
static MMU* s_current = nullptr;
void MMU::initialize() void MMU::initialize()
{ {
@ -34,6 +35,12 @@ namespace Kernel
return *s_instance; return *s_instance;
} }
MMU& MMU::current()
{
ASSERT(s_current);
return *s_current;
}
static uint64_t* allocate_page_aligned_page() static uint64_t* allocate_page_aligned_page()
{ {
void* page = kmalloc(PAGE_SIZE, PAGE_SIZE); void* page = kmalloc(PAGE_SIZE, PAGE_SIZE);
@ -130,6 +137,7 @@ namespace Kernel
void MMU::load() void MMU::load()
{ {
asm volatile("movq %0, %%cr3" :: "r"(m_highest_paging_struct)); asm volatile("movq %0, %%cr3" :: "r"(m_highest_paging_struct));
s_current = this;
} }
void MMU::identity_map_page(paddr_t address, flags_t flags) void MMU::identity_map_page(paddr_t address, flags_t flags)

View File

@ -20,6 +20,8 @@ namespace Kernel
static void initialize(); static void initialize();
static MMU& get(); static MMU& get();
static MMU& current();
MMU(); MMU();
~MMU(); ~MMU();