mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Set the NXE and the WP bit
This commit is contained in:
21
src/lib.rs
21
src/lib.rs
@@ -68,12 +68,33 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
|||||||
memory_map_tag.memory_areas());
|
memory_map_tag.memory_areas());
|
||||||
|
|
||||||
memory::test_paging(&mut frame_allocator);
|
memory::test_paging(&mut frame_allocator);
|
||||||
|
|
||||||
|
enable_nxe_bit();
|
||||||
|
enable_write_protect_bit();
|
||||||
|
|
||||||
memory::remap_the_kernel(&mut frame_allocator, boot_info);
|
memory::remap_the_kernel(&mut frame_allocator, boot_info);
|
||||||
println!("It did not crash!");
|
println!("It did not crash!");
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enable_nxe_bit() {
|
||||||
|
use x86::msr::{IA32_EFER, rdmsr, wrmsr};
|
||||||
|
|
||||||
|
let nxe_bit = 1 << 11;
|
||||||
|
unsafe {
|
||||||
|
let efer = rdmsr(IA32_EFER);
|
||||||
|
wrmsr(IA32_EFER, efer | nxe_bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enable_write_protect_bit() {
|
||||||
|
use x86::controlregs::{cr0, cr0_write};
|
||||||
|
|
||||||
|
let wp_bit = 1 << 16;
|
||||||
|
unsafe { cr0_write(cr0() | wp_bit) };
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[lang = "eh_personality"]
|
#[lang = "eh_personality"]
|
||||||
extern "C" fn eh_personality() {}
|
extern "C" fn eh_personality() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user