Browse Source

memory::paging: add a struct to own the P4 table, make Page Clone+Copy

master
3moon 8 years ago
parent
commit
24032a9edd
1 changed files with 22 additions and 1 deletions
  1. +22
    -1
      src/arch/x86_64/memory/paging/mod.rs

+ 22
- 1
src/arch/x86_64/memory/paging/mod.rs View File

@ -3,11 +3,16 @@
//! Extremely ripped off from Phil Oppermann's tutorials, because I don't feel like writing //! 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. //! a paging system off the top of my head today.
use core::ptr::Unique;
use super::PAGE_SIZE; use super::PAGE_SIZE;
use super::{Frame, FrameAllocator};
mod entry; mod entry;
mod table; mod table;
use self::entry::*;
use self::table::{Table, Level4};
/// Upper bound on entries per page table /// Upper bound on entries per page table
const ENTRY_COUNT: usize = 512; const ENTRY_COUNT: usize = 512;
@ -15,7 +20,23 @@ const ENTRY_COUNT: usize = 512;
pub type PhysicalAddress = usize; pub type PhysicalAddress = usize;
pub type VirtualAddress = usize; pub type VirtualAddress = usize;
/// A representation of a virtual page
/// Owns the top-level active page table (P4).
pub struct ActivePageTable {
p4: Unique<Table<Level4>>,
}
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 { pub struct Page {
index: usize, index: usize,
} }

Loading…
Cancel
Save