summaryrefslogtreecommitdiff
path: root/kc/core/cpu/mmu.c
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2022-02-15 15:00:53 +0000
committerAda Christine <adachristine18@gmail.com>2022-02-15 15:00:53 +0000
commit5fc386102380e6c15c81df4fd750f54641535eaa (patch)
treec3aed0635aa10a80e1bbbe46a80e4e67f2be2c39 /kc/core/cpu/mmu.c
parent0c1bc025700656ce17bbd71f7d149744d65b7fb6 (diff)
beginning to things out into cpu-dependent and cpu-independent code
Diffstat (limited to 'kc/core/cpu/mmu.c')
-rw-r--r--kc/core/cpu/mmu.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/kc/core/cpu/mmu.c b/kc/core/cpu/mmu.c
new file mode 100644
index 0000000..60bee0f
--- /dev/null
+++ b/kc/core/cpu/mmu.c
@@ -0,0 +1,30 @@
+#include "mmu.h"
+#include "irq.h"
+
+#include <kernel/memory/paging.h>
+
+void mmu_set_map(phys_addr_t map)
+{
+ irq_lock();
+ __asm__ volatile ("mov %0, %%cr3" :: "r"(page_address(map, 1)));
+ irq_unlock();
+}
+
+phys_addr_t mmu_get_map(void)
+{
+ phys_addr_t pm4_phys;
+ irq_lock();
+ __asm__ volatile
+ (
+ "mov %%cr3, %0\n\t"
+ : "=r"(pm4_phys)
+ );
+ irq_unlock();
+ return page_address(pm4_phys, 1);
+}
+
+void mmu_invalidate(void *addr)
+{
+ __asm__ volatile ("invlpg (%0)" :: "r"(addr));
+}
+