From f84488319238c11d240e9a8ce67a15f3f1713a15 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Wed, 8 Dec 2021 16:29:53 +0100 Subject: [PATCH] feat(paging): enabling write protection Signed-off-by: Julien CLEMENT --- src/lib.rs | 9 +++++++++ src/memory/paging/mod.rs | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5e9eacd..f35c140 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,7 @@ pub fn init(frame_allocator: &mut A, boot_info: &BootInformation) vga::change_color(ColorCode::new(Color::LightCyan, Color::Black)); println!("Starting init"); enable_nxe_bit(); + enable_write_protect_bit(); memory::kernel_remap(frame_allocator, boot_info); gdt::init_gdt(); interrupts::init_idt(); @@ -46,6 +47,14 @@ fn enable_nxe_bit() { unsafe { Efer::update(|efer| *efer |= EferFlags::NO_EXECUTE_ENABLE) } } + +fn enable_write_protect_bit() { + println!("Enabling write protection bit"); + use x86_64::registers::control::{Cr0, Cr0Flags}; + + unsafe { Cr0::write(Cr0::read() | Cr0Flags::WRITE_PROTECT) }; +} + fn get_frame_allocator(multiboot_info_addr: usize) -> memory::AreaFrameAllocator { let boot_info = unsafe { multiboot2::load(multiboot_info_addr) }; let memory_map_tag = boot_info.memory_map_tag().expect("Memory map tag required"); diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 835fc12..60181db 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -47,8 +47,6 @@ pub fn kernel_remap(allocator: &mut A, boot_info: &BootInformation) // section is not loaded to memory continue; } - println!("mapping section at addr: {:#x}, size: {:#x}", - section.addr, section.size); assert!(section.start_address() % PAGE_SIZE == 0, "sections need to be page aligned");