Add RecursivePageTable as an owner for the P4 table

This commit is contained in:
Philipp Oppermann
2015-12-09 00:55:53 +01:00
parent 46b93e0650
commit fb7d2d22b6

View File

@@ -1,5 +1,7 @@
pub use self::entry::*; pub use self::entry::*;
use memory::{PAGE_SIZE, Frame, FrameAllocator}; use memory::{PAGE_SIZE, Frame, FrameAllocator};
use self::table::{Table, Level4};
use core::ptr::Unique;
mod entry; mod entry;
mod table; mod table;
@@ -39,6 +41,24 @@ impl Page {
} }
} }
pub struct RecursivePageTable {
p4: Unique<Table<Level4>>,
}
impl RecursivePageTable {
pub unsafe fn new() -> RecursivePageTable {
RecursivePageTable { p4: Unique::new(table::P4) }
}
fn p4(&self) -> &Table<Level4> {
unsafe { self.p4.get() }
}
fn p4_mut(&mut self) -> &mut Table<Level4> {
unsafe { self.p4.get_mut() }
}
}
pub unsafe fn translate(virtual_address: VirtualAddress) -> Option<PhysicalAddress> { pub unsafe fn translate(virtual_address: VirtualAddress) -> Option<PhysicalAddress> {
let offset = virtual_address % PAGE_SIZE; let offset = virtual_address % PAGE_SIZE;
translate_page(Page::containing_address(virtual_address)) translate_page(Page::containing_address(virtual_address))