From c63f340d90800895f007de64b7d2d14624263331 Mon Sep 17 00:00:00 2001 From: nthnluu Date: Sun, 28 Jan 2024 21:20:27 -0500 Subject: Created student weenix repository --- kernel/include/mm/tlb.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 kernel/include/mm/tlb.h (limited to 'kernel/include/mm/tlb.h') 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"); +} -- cgit v1.2.3-70-g09d2