feat(paging): enabling write protection
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
		
							parent
							
								
									5ff8596233
								
							
						
					
					
						commit
						f844883192
					
				@ -34,6 +34,7 @@ pub fn init<A>(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");
 | 
			
		||||
 | 
			
		||||
@ -47,8 +47,6 @@ pub fn kernel_remap<A>(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");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user