From 5e994b9dff7242c59cf23b3d20882ce093b68bf4 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Wed, 8 Dec 2021 02:59:24 +0100 Subject: [PATCH] feat(paging): switch page table and identity map VGA buffer and multiboot info structs Signed-off-by: Julien CLEMENT --- src/memory/paging/mod.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 769242b..2b5d9d5 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -43,8 +43,22 @@ pub fn kernel_remap(allocator: &mut A, boot_info: &BootInformation) } } } + let vga_buffer_frame = Frame::::containing_address(PhysAddr::new(0xb8000)); + unsafe { + mapper.identity_map(vga_buffer_frame, Flags::PRESENT | Flags::WRITABLE, allocator).expect("Failed to identity map VGA buffer").flush(); + } + let multiboot_start = Frame::::containing_address(PhysAddr::new(boot_info.start_address() as u64)); + let multiboot_end = Frame::containing_address(PhysAddr::new(boot_info.end_address() as u64 - 1)); + for frame in Frame::range_inclusive(multiboot_start, multiboot_end) { + unsafe { + mapper.identity_map(frame, Flags::PRESENT, allocator).expect("Failed to identity map multiboot info struct").flush(); + } + } }); + + new_table.activate(); + println!("Loaded new page table!"); } struct InactivePageTable { @@ -79,6 +93,18 @@ impl InactivePageTable { temporary_page.unmap(active_table); } + + pub fn activate(&mut self) -> InactivePageTable { + let old_table = InactivePageTable { + p4_frame: Frame::containing_address( + control::Cr3::read().0.start_address() + ), + }; + unsafe { + control::Cr3::write(self.p4_frame, control::Cr3Flags::empty()); + } + old_table + } } pub fn get_active_page_table() -> RecursivePageTable<'static> { @@ -104,8 +130,6 @@ pub fn test_paging(allocator: &mut A) let frame_ptr: *mut u8 = frame.start_address().as_u64() as *mut u8; unsafe { - println!("Page: {:#?}, Frame: {:#?}", *page_ptr, *frame_ptr); - *frame_ptr = 42; - println!("Page: {:#?}, Frame: {:#?}", *page_ptr, *frame_ptr); + println!("Page: {:#?}, Frame: {:#?}", page_ptr, frame_ptr); } }