|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
// Enable 'No-Execute' bit in page entry
|
|
|
|
|
/// Enable 'No-Execute' bit in page entry
|
|
|
|
|
pub fn enable_nxe_bit() {
|
|
|
|
|
use x86_64::registers::msr::{IA32_EFER, rdmsr, wrmsr};
|
|
|
|
|
|
|
|
|
@ -11,7 +11,7 @@ pub fn enable_nxe_bit() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enable write protection in kernel mode
|
|
|
|
|
/// Enable write protection in kernel mode
|
|
|
|
|
pub fn enable_write_protect_bit() {
|
|
|
|
|
use x86_64::registers::control_regs::{cr0, cr0_write, Cr0};
|
|
|
|
|
|
|
|
|
@ -19,3 +19,14 @@ pub fn enable_write_protect_bit() {
|
|
|
|
|
// But we are in kernel mode. So it's safe.
|
|
|
|
|
unsafe { cr0_write(cr0() | Cr0::WRITE_PROTECT) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Exit qemu
|
|
|
|
|
/// See: https://wiki.osdev.org/Shutdown
|
|
|
|
|
/// Must run qemu with `-device isa-debug-exit`
|
|
|
|
|
/// The error code is `value written to 0x501` *2 +1, so it should be odd
|
|
|
|
|
pub unsafe fn exit_in_qemu(error_code: u8) -> ! {
|
|
|
|
|
use x86_64::instructions::port::outb;
|
|
|
|
|
assert!(error_code & 1 == 1);
|
|
|
|
|
outb(0x501, (error_code - 1) / 2);
|
|
|
|
|
unreachable!()
|
|
|
|
|
}
|