diff options
author | 2015-11-20 18:46:20 +0100 | |
---|---|---|
committer | 2015-11-21 19:34:09 +0100 | |
commit | 8f98633c56d3f3fde06d8b9dc2b65461f3b3451a (patch) | |
tree | 90cd3a07bb83bcc4846a3d9769a172aaa47d07ed | |
parent | 231559f903e87db3fe7320133d9644047be8f740 (diff) | |
download | rust-x86-8f98633c56d3f3fde06d8b9dc2b65461f3b3451a.tar.gz rust-x86-8f98633c56d3f3fde06d8b9dc2b65461f3b3451a.tar.zst rust-x86-8f98633c56d3f3fde06d8b9dc2b65461f3b3451a.zip |
Add a TLB module
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/tlb.rs | 20 |
2 files changed, 22 insertions, 1 deletions
@@ -41,4 +41,5 @@ pub mod syscall; pub mod perfcnt; pub mod cpuid { pub use raw_cpuid::*; -}
\ No newline at end of file +} +pub mod tlb; diff --git a/src/tlb.rs b/src/tlb.rs new file mode 100644 index 0000000..f20e37e --- /dev/null +++ b/src/tlb.rs @@ -0,0 +1,20 @@ +//! Functions to flush the translation lookaside buffer (TLB). + +/// Invalidate the given address in the TLB using the `invlpg` instruction. +/// +/// # Safety +/// This function is unsafe as it causes a general protection fault (GP) if the current privilege +/// level is not 0. +pub unsafe fn flush(addr: usize) { + asm!("invlpg ($0)" :: "r" (addr) : "memory" : "volatile"); +} + +/// Invalidate the TLB completely by reloading the CR3 register. +/// +/// # Safety +/// This function is unsafe as it causes a general protection fault (GP) if the current privilege +/// level is not 0. +pub unsafe fn flush_all() { + use controlregs::{cr3, cr3_write}; + cr3_write(cr3()) +} |