1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
//! Functions to flush the translation lookaside buffer (TLB).

use VirtualAddress;

/// Invalidate the given address in the TLB using the `invlpg` instruction.
pub fn flush(addr: VirtualAddress) {
    unsafe { asm!("invlpg ($0)" :: "r" (addr.0) : "memory") };
}

/// Invalidate the TLB completely by reloading the CR3 register.
pub fn flush_all() {
    use registers::control_regs::{cr3, cr3_write};
    unsafe { cr3_write(cr3()) }
}