Model page table entries

This commit is contained in:
Philipp Oppermann
2015-12-08 22:15:32 +01:00
parent d827f51bb6
commit 14384fb27f
5 changed files with 58 additions and 0 deletions

View File

@@ -12,3 +12,7 @@ spin = "0.3.4"
[dependencies.multiboot2] [dependencies.multiboot2]
git = "https://github.com/phil-opp/multiboot2-elf64" git = "https://github.com/phil-opp/multiboot2-elf64"
[dependencies.bitflags]
git = "https://github.com/phil-opp/bitflags.git"
branch = "no_std"

View File

@@ -19,6 +19,8 @@
extern crate rlibc; extern crate rlibc;
extern crate spin; extern crate spin;
extern crate multiboot2; extern crate multiboot2;
#[macro_use]
extern crate bitflags;
#[macro_use] #[macro_use]
mod vga_buffer; mod vga_buffer;

View File

@@ -1,4 +1,5 @@
pub use self::area_frame_allocator::AreaFrameAllocator; pub use self::area_frame_allocator::AreaFrameAllocator;
use self::paging::PhysicalAddress;
mod area_frame_allocator; mod area_frame_allocator;
mod paging; mod paging;
@@ -14,6 +15,10 @@ impl Frame {
fn containing_address(address: usize) -> Frame { fn containing_address(address: usize) -> Frame {
Frame { number: address / PAGE_SIZE } Frame { number: address / PAGE_SIZE }
} }
fn start_address(&self) -> PhysicalAddress {
self.number * PAGE_SIZE
}
} }
pub trait FrameAllocator { pub trait FrameAllocator {

View File

@@ -0,0 +1,45 @@
use memory::Frame;
pub struct Entry(u64);
impl Entry {
pub fn is_unused(&self) -> bool {
self.0 == 0
}
pub fn set_unused(&mut self) {
self.0 = 0;
}
pub fn flags(&self) -> EntryFlags {
EntryFlags::from_bits_truncate(self.0)
}
pub fn pointed_frame(&self) -> Option<Frame> {
if self.flags().contains(PRESENT) {
Some(Frame::containing_address(self.0 as usize & 0x000fffff_fffff000))
} else {
None
}
}
pub fn set(&mut self, frame: Frame, flags: EntryFlags) {
assert!(frame.start_address() & !0x000fffff_fffff000 == 0);
self.0 = (frame.start_address() as u64) | flags.bits();
}
}
bitflags! {
flags EntryFlags: u64 {
const PRESENT = 1 << 0,
const WRITABLE = 1 << 1,
const USER_ACCESSIBLE = 1 << 2,
const WRITE_THROUGH = 1 << 3,
const NO_CACHE = 1 << 4,
const ACCESSED = 1 << 5,
const DIRTY = 1 << 6,
const HUGE_PAGE = 1 << 7,
const GLOBAL = 1 << 8,
const NO_EXECUTE = 1 << 63,
}
}

View File

@@ -1,3 +1,5 @@
mod entry;
const ENTRY_COUNT: usize = 512; const ENTRY_COUNT: usize = 512;
pub type PhysicalAddress = usize; pub type PhysicalAddress = usize;