parent
e2e9ead17c
commit
09098f0d2f
@ -0,0 +1,4 @@
|
||||
pub use self::page_table::*;
|
||||
use super::*;
|
||||
|
||||
mod page_table;
|
@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
pub use self::mock_page_table::MockPageTable;
|
||||
|
||||
pub mod mock_page_table;
|
||||
mod mock_page_table;
|
||||
|
||||
pub trait PageTable {
|
||||
fn accessed(&self, addr: VirtAddr) -> bool;
|
@ -0,0 +1,33 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Frame {
|
||||
number: usize,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
pub fn containing_address(address: PhysAddr) -> Frame {
|
||||
Frame{ number: address.get() as usize / PAGE_SIZE }
|
||||
}
|
||||
//TODO: Set private
|
||||
pub fn start_address(&self) -> PhysAddr {
|
||||
PhysAddr::new((self.number * PAGE_SIZE) as u64)
|
||||
}
|
||||
|
||||
pub fn clone(&self) -> Frame {
|
||||
Frame { number: self.number }
|
||||
}
|
||||
//TODO: Set private
|
||||
// pub fn range_inclusive(start: Frame, end: Frame) -> FrameIter {
|
||||
// FrameIter {
|
||||
// start: start,
|
||||
// end: end,
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
impl Drop for Frame {
|
||||
fn drop(&mut self) {
|
||||
panic!("frame must be deallocate");
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
use super::*;
|
||||
|
||||
pub trait FrameAllocator {
|
||||
fn allocate_frame(&mut self) -> Option<Frame>;
|
||||
fn deallocate_frame(&mut self, frame: Frame);
|
||||
}
|
||||
|
||||
pub trait MemoryArea {
|
||||
fn begin(&self) -> PhysAddr;
|
||||
fn end(&self) -> PhysAddr;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
pub use self::physaddr::PhysAddr;
|
||||
pub use self::frame::Frame;
|
||||
pub use self::frame_allocator::FrameAllocator;
|
||||
|
||||
use super::*;
|
||||
|
||||
mod frame;
|
||||
mod physaddr;
|
||||
mod frame_allocator;
|
@ -0,0 +1,50 @@
|
||||
use core::fmt;
|
||||
|
||||
/// Represents a physical memory address
|
||||
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct PhysAddr(u64);
|
||||
|
||||
impl PhysAddr {
|
||||
pub fn new(addr: u64) -> PhysAddr {
|
||||
PhysAddr(addr)
|
||||
}
|
||||
pub fn get(&self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for PhysAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:#x}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Binary for PhysAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PhysAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::LowerHex for PhysAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Octal for PhysAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::UpperHex for PhysAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
Loading…
Reference in new issue