Reorganize kernel memory mappings

This commit is contained in:
Jeremy Soller 2016-09-10 18:48:27 -06:00
parent 7ace92c60c
commit ce717ff277
12 changed files with 107 additions and 66 deletions

View file

@ -76,6 +76,6 @@ impl FrameAllocator for AreaFrameAllocator {
}
fn deallocate_frame(&mut self, frame: Frame) {
//println!("Leak frame: {:?}", frame);
//panic!("AreaFrameAllocator::deallocate_frame: not supported: {:?}", frame);
}
}

View file

@ -0,0 +1,39 @@
use super::AreaFrameAllocator;
const BITMAP_RESERVED: usize = 0;
const BITMAP_FREE: usize = 1;
const BITMAP_USED: usize = 2;
pub struct BitmapAllocator {
bitmap: &'static mut [u8]
}
impl BitmapAllocator {
pub fn new(area_frame_allocator: AreaFrameAllocator) -> BitmapAllocator {
BitmapAllocator {
bitmap: &mut []
}
}
}
impl FrameAllocator for BitmapAllocator {
fn allocate_frame(&mut self) -> Option<Frame> {
let mut i = 0;
while i < self.bitmap.len() {
if self.bitmap[i] == BITMAP_FREE {
self.bitmap[i] = BITMAP_USED;
return Some(Frame::containing_address(PhysicalAddress::new(i * 4096)));
}
}
None
}
fn deallocate_frame(&mut self, frame: Frame) {
let i = frame.starting_address().get()/4096;
if i < self.bitmap.len() && self.bitmap[i] == BITMAP_USED {
self.bitmap[i] = BITMAP_FREE;
} else {
panic!("BitmapAllocator::deallocate_frame: unowned frame {:?}", frame);
}
}
}

View file

@ -3,11 +3,11 @@
pub use paging::{PAGE_SIZE, PhysicalAddress};
use self::area_frame_alloc::AreaFrameAllocator;
use self::area_frame_allocator::AreaFrameAllocator;
use spin::Mutex;
pub mod area_frame_alloc;
pub mod area_frame_allocator;
/// The current memory map. It's size is maxed out to 512 entries, due to it being
/// from 0x500 to 0x5000 (800 is the absolute total)