From 31ac3260ed875647b692e21242d8b0811a696875 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 16 May 2023 00:26:13 +0300 Subject: [PATCH] Kernel: MMU keeps track of the current --- kernel/arch/x86_64/MMU.cpp | 8 ++++++++ kernel/include/kernel/Memory/MMU.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/kernel/arch/x86_64/MMU.cpp b/kernel/arch/x86_64/MMU.cpp index f8c309e4..67a079ce 100644 --- a/kernel/arch/x86_64/MMU.cpp +++ b/kernel/arch/x86_64/MMU.cpp @@ -18,6 +18,7 @@ namespace Kernel { static MMU* s_instance = nullptr; + static MMU* s_current = nullptr; void MMU::initialize() { @@ -34,6 +35,12 @@ namespace Kernel return *s_instance; } + MMU& MMU::current() + { + ASSERT(s_current); + return *s_current; + } + static uint64_t* allocate_page_aligned_page() { void* page = kmalloc(PAGE_SIZE, PAGE_SIZE); @@ -130,6 +137,7 @@ namespace Kernel void MMU::load() { asm volatile("movq %0, %%cr3" :: "r"(m_highest_paging_struct)); + s_current = this; } void MMU::identity_map_page(paddr_t address, flags_t flags) diff --git a/kernel/include/kernel/Memory/MMU.h b/kernel/include/kernel/Memory/MMU.h index 17728484..8e481608 100644 --- a/kernel/include/kernel/Memory/MMU.h +++ b/kernel/include/kernel/Memory/MMU.h @@ -20,6 +20,8 @@ namespace Kernel static void initialize(); static MMU& get(); + static MMU& current(); + MMU(); ~MMU();