diff options
Diffstat (limited to 'kc/core/cpu')
| -rw-r--r-- | kc/core/cpu/irq.c | 24 | ||||
| -rw-r--r-- | kc/core/cpu/irq.h | 4 | ||||
| -rw-r--r-- | kc/core/cpu/mmu.c | 30 | ||||
| -rw-r--r-- | kc/core/cpu/mmu.h | 9 |
4 files changed, 67 insertions, 0 deletions
diff --git a/kc/core/cpu/irq.c b/kc/core/cpu/irq.c new file mode 100644 index 0000000..639aca3 --- /dev/null +++ b/kc/core/cpu/irq.c @@ -0,0 +1,24 @@ +#include "irq.h" + +#include <stdatomic.h> + +static atomic_uint_fast64_t irq_lock_count = 0; + +void irq_lock(void) +{ + __asm__ volatile ("cli;"); +} + +void irq_unlock(void) +{ + if (irq_lock_count >= 1) + { + irq_lock_count--; + } + + if (irq_lock_count == 0) + { + __asm__ volatile ("sti;"); + } +} + diff --git a/kc/core/cpu/irq.h b/kc/core/cpu/irq.h index 9874761..9734860 100644 --- a/kc/core/cpu/irq.h +++ b/kc/core/cpu/irq.h @@ -3,6 +3,10 @@ #include "interrupt.h" #ifndef __ASSEMBLER__ + +void irq_lock(void); +void irq_unlock(void); + #else .macro IRQ_DECLARE name:req handler:req, irq:req, offset:req 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)); +} + diff --git a/kc/core/cpu/mmu.h b/kc/core/cpu/mmu.h new file mode 100644 index 0000000..2021a2e --- /dev/null +++ b/kc/core/cpu/mmu.h @@ -0,0 +1,9 @@ +#pragma once + +#include "memory.h" + +void mmu_set_map(phys_addr_t map); +phys_addr_t mmu_get_map(void); + +void mmu_invalidate(void *addr); + |
