From c3ae5ba68dc418a5d5de6d67c3aacbfdb1bf2305 Mon Sep 17 00:00:00 2001 From: Chloe M Date: Fri, 10 Jul 2026 20:56:46 -0400 Subject: [PATCH] ptos/amd64: tlb: Add TLB operation helpers Signed-off-by: Chloe M --- service/ptos/head/arch/amd64/tlb.h | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 service/ptos/head/arch/amd64/tlb.h diff --git a/service/ptos/head/arch/amd64/tlb.h b/service/ptos/head/arch/amd64/tlb.h new file mode 100644 index 0000000..b7d9ac5 --- /dev/null +++ b/service/ptos/head/arch/amd64/tlb.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: TLB related helpers + * Author: Chloe M. + */ + +#ifndef _MACHINE_TLB_H_ +#define _MACHINE_TLB_H_ 1 + +#include +#include + +/* + * Flush a single virtual address from the translation + * lookaside buffer. + * + * @VirtualBase: Virtual address to flush + */ +ALWAYS_INLINE static inline VOID +MdTlbFlushSingle(UPTR VirtualBase) +{ + VirtualBase = ALIGN_DOWN(VirtualBase, PAGESIZE); + ASMV( + "invlpg %0" + : + : "m" (VirtualBase) + : "memory" + ); +} + +/* + * Flush all entries from the translation lookaside buffer. + * + * XXX: This should be used quite judiciously due to the + * collateral damage caused by this operation which + * incurs a large performance penalty. + */ +ALWAYS_INLINE static inline VOID +MdTlbFlushAll(VOID) +{ + ASMV( + "mov %%cr3, %%rax\n" + "mov %%rax, %%cr3" + : + : + : "memory", "rax" + ); +} + +#endif /* !_MACHINE_TLB_H_ */