diff options
Diffstat (limited to 'kernel/include/mm/tlb.h')
-rw-r--r-- | kernel/include/mm/tlb.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/kernel/include/mm/tlb.h b/kernel/include/mm/tlb.h new file mode 100644 index 0000000..836be4e --- /dev/null +++ b/kernel/include/mm/tlb.h @@ -0,0 +1,35 @@ +#pragma once + +#include "kernel.h" +#include "types.h" + +#include "mm/page.h" + +/* Invalidates any entries from the TLB which contain + * mappings for the given virtual address. */ +static inline void tlb_flush(uintptr_t vaddr) +{ + __asm__ volatile("invlpg (%0)" ::"r"(vaddr)); +} + +/* Invalidates any entries for count pages starting at + * vaddr from the TLB. If this range is very large it may + * be more efficient to call tlb_flush_all to invalidate + * the entire TLB. */ +static inline void tlb_flush_range(uintptr_t vaddr, size_t count) +{ + for (size_t i = 0; i < count; i++, vaddr += PAGE_SIZE) + { + tlb_flush(vaddr); + } +} + +/* Invalidates the entire TLB. */ +static inline void tlb_flush_all() +{ + uintptr_t pdir; + __asm__ volatile("movq %%cr3, %0" + : "=r"(pdir)); + __asm__ volatile("movq %0, %%cr3" ::"r"(pdir) + : "memory"); +} |