Add physical mod and reorganize.

master
WangRunji 7 years ago
parent e2e9ead17c
commit 09098f0d2f

@ -3,8 +3,10 @@
extern crate alloc; extern crate alloc;
pub mod physical;
pub mod paging;
pub mod memory_set; pub mod memory_set;
pub mod swap; pub mod swap;
pub mod page_table;
type VirtAddr = usize; type VirtAddr = usize;
const PAGE_SIZE: usize = 4096;

@ -0,0 +1,4 @@
pub use self::page_table::*;
use super::*;
mod page_table;

@ -1,6 +1,7 @@
use super::*; use super::*;
pub use self::mock_page_table::MockPageTable;
pub mod mock_page_table; mod mock_page_table;
pub trait PageTable { pub trait PageTable {
fn accessed(&self, addr: VirtAddr) -> bool; 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)
}
}

@ -81,7 +81,7 @@ mod test {
use alloc::{arc::Arc, boxed::Box}; use alloc::{arc::Arc, boxed::Box};
use core::mem::uninitialized; use core::mem::uninitialized;
use core::cell::RefCell; use core::cell::RefCell;
use page_table::mock_page_table::MockPageTable; use paging::MockPageTable;
impl SwappablePageTable for MockPageTable { impl SwappablePageTable for MockPageTable {
fn swap_out(&mut self, addr: usize) -> Result<(), ()> { fn swap_out(&mut self, addr: usize) -> Result<(), ()> {

@ -39,7 +39,7 @@ mod test {
use super::*; use super::*;
use alloc::{arc::Arc, boxed::Box}; use alloc::{arc::Arc, boxed::Box};
use core::cell::RefCell; use core::cell::RefCell;
use page_table::mock_page_table::MockPageTable; use paging::MockPageTable;
enum MemOp { enum MemOp {
R(usize), W(usize) R(usize), W(usize)

@ -2,7 +2,7 @@ pub use self::fifo::FifoSwapManager;
pub use self::enhanced_clock::EnhancedClockSwapManager; pub use self::enhanced_clock::EnhancedClockSwapManager;
use super::*; use super::*;
use super::page_table::PageTable; use super::paging::PageTable;
mod fifo; mod fifo;
mod enhanced_clock; mod enhanced_clock;

Loading…
Cancel
Save