From 5fc386102380e6c15c81df4fd750f54641535eaa Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Tue, 15 Feb 2022 15:00:53 +0000 Subject: beginning to things out into cpu-dependent and cpu-independent code --- kc/core/cpu/mmu.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 kc/core/cpu/mmu.c (limited to 'kc/core/cpu/mmu.c') 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 + +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)); +} + -- cgit v1.3.1-1-g115d