From 24032a9edde906693398798431a7d3dced95851b Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 4 Jun 2017 15:53:45 -0500 Subject: [PATCH] memory::paging: add a struct to own the P4 table, make Page Clone+Copy --- src/arch/x86_64/memory/paging/mod.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/arch/x86_64/memory/paging/mod.rs b/src/arch/x86_64/memory/paging/mod.rs index 5846a74..7cd63be 100644 --- a/src/arch/x86_64/memory/paging/mod.rs +++ b/src/arch/x86_64/memory/paging/mod.rs @@ -3,11 +3,16 @@ //! Extremely ripped off from Phil Oppermann's tutorials, because I don't feel like writing //! a paging system off the top of my head today. +use core::ptr::Unique; use super::PAGE_SIZE; +use super::{Frame, FrameAllocator}; mod entry; mod table; +use self::entry::*; +use self::table::{Table, Level4}; + /// Upper bound on entries per page table const ENTRY_COUNT: usize = 512; @@ -15,7 +20,23 @@ const ENTRY_COUNT: usize = 512; pub type PhysicalAddress = usize; pub type VirtualAddress = usize; -/// A representation of a virtual page +/// Owns the top-level active page table (P4). +pub struct ActivePageTable { + p4: Unique>, +} + +impl ActivePageTable { + /// There **must** be ***only one*** ActivePageTable instance. + /// Since we cannot guarantee this trivially, the constructor is unsafe. + pub unsafe fn new() -> ActivePageTable { + ActivePageTable { + p4: Unique::new(table::P4), + } + } +} + +/// A representation of a virtual page. +#[derive(Clone, Copy, Debug)] pub struct Page { index: usize, }