diff options
author | 2016-08-11 20:04:24 -0700 | |
---|---|---|
committer | 2016-08-11 20:04:24 -0700 | |
commit | f9cd6a03de179fad9dc489c5bbc78c4250e5aa55 (patch) | |
tree | 8c17a28962386d63f53b658e6e333e34f8a85ea6 /src/shared/tlb.rs | |
parent | afc9c65bf1dc5d0a6589e1b3d30551b6cc88f0e7 (diff) | |
download | rust-x86-f9cd6a03de179fad9dc489c5bbc78c4250e5aa55.tar.gz rust-x86-f9cd6a03de179fad9dc489c5bbc78c4250e5aa55.tar.zst rust-x86-f9cd6a03de179fad9dc489c5bbc78c4250e5aa55.zip |
Moved cache flushing operations out of bits64 to shared because they
apply to both.
Diffstat (limited to 'src/shared/tlb.rs')
-rw-r--r-- | src/shared/tlb.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/tlb.rs b/src/shared/tlb.rs new file mode 100644 index 0000000..f99604f --- /dev/null +++ b/src/shared/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"); +} + +/// 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 shared::control_regs::{cr3, cr3_write}; + cr3_write(cr3()) +} |