From 564c6b64e94d7e47183cd075e3eb601078c76b2a Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 18 Apr 2017 12:25:59 +0200 Subject: [PATCH] Switch to the new page table after mapping all sections --- src/memory/paging/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index e734949..8c23586 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -104,6 +104,21 @@ impl ActivePageTable { temporary_page.unmap(self); } + pub fn switch(&mut self, new_table: InactivePageTable) -> InactivePageTable { + use x86_64::PhysicalAddress; + use x86_64::registers::control_regs; + + let old_table = InactivePageTable { + p4_frame: Frame::containing_address( + control_regs::cr3().0 as usize + ), + }; + unsafe { + control_regs::cr3_write(PhysicalAddress( + new_table.p4_frame.start_address() as u64)); + } + old_table + } } pub struct InactivePageTable { @@ -167,4 +182,7 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) } } }); + + let old_table = active_table.switch(new_table); + println!("NEW TABLE!!!"); }