poppin/kernel/src/utils.rs

25 lines
470 B
Rust

use x86::msr::{rdmsr, wrmsr, IA32_EFER};
use x86_64::{instructions, registers::control::{Cr0, Cr0Flags}};
pub fn hcf() -> ! {
loop {
instructions::hlt();
core::hint::spin_loop();
}
}
pub fn enable_nxe_bit() {
let nxe_bit = 1 << 11;
unsafe {
let efer = rdmsr(IA32_EFER);
wrmsr(IA32_EFER, efer | nxe_bit);
}
}
pub fn enable_write_protect_bit() {
unsafe { Cr0::write(Cr0::read() | Cr0Flags::WRITE_PROTECT) };
}