aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ds/bitmap.rs0
-rw-r--r--src/ds/mod.rs1
-rw-r--r--src/lib.rs6
-rw-r--r--src/mm/pma.rs70
4 files changed, 59 insertions, 18 deletions
diff --git a/src/ds/bitmap.rs b/src/ds/bitmap.rs
deleted file mode 100644
index e69de29..0000000
--- a/src/ds/bitmap.rs
+++ /dev/null
diff --git a/src/ds/mod.rs b/src/ds/mod.rs
index 7cfb300..e8ae652 100644
--- a/src/ds/mod.rs
+++ b/src/ds/mod.rs
@@ -1,2 +1 @@
-pub mod bitmap;
pub mod queue;
diff --git a/src/lib.rs b/src/lib.rs
index d982d51..7bde927 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -35,6 +35,12 @@ pub extern "C" fn _entry() -> ! {
// interrupt::interrupt_enable();
//
// busy loop query keyboard
+ let mut framemap = mm::pma::FMap::new();
+ framemap.init();
+ println!("Bitmap starting from : {:p}", framemap.bm.as_ptr());
+ println!("Skip first {} bytes", framemap.skip_byte);
+
+
loop {
// let code = io::KBCTL_GLOBAL.lock().simple_read();
io::KBCTL_GLOBAL.lock().fetch_key();
diff --git a/src/mm/pma.rs b/src/mm/pma.rs
index aa5e193..af789e8 100644
--- a/src/mm/pma.rs
+++ b/src/mm/pma.rs
@@ -1,4 +1,4 @@
-use crate::defs::Mem;
+use crate::defs::{self, Mem};
use core::ffi::c_void;
use core::{ptr, slice};
// this is POC code, it will be ugly
@@ -6,26 +6,62 @@ use core::{ptr, slice};
extern "C" {
pub fn ___KERNEL_END__();
}
-/// Bitmap for physical frames. to get around the chicken-egg problem, we provide a provisional
-/// bitmap of fixed length in the startup code.
-pub struct PFMap {
- bm: &'static mut [u8],
- skip: usize, // pfn to skip (because they are already used by the initial kernel image)
- end: usize, // pfn limit
+
+type BitU8 = u8;
+/// Bitmap for physical frames
+pub struct FMap {
+ pub bm: &'static mut [BitU8],
+ // skip over the kernel image and the bitmap itself.
+ pub skip_byte: usize,
}
-// TODO PMA initialization : needs to singleton
+pub enum PMAError{
+ DoubleFree
+}
-impl PFMap {}
+impl FMap {
+ pub fn new() -> Self {
+ let map_start = ___KERNEL_END__ as usize;
+ let fmap = Self {
+ bm: unsafe { slice::from_raw_parts_mut(map_start as *mut u8, Mem::PHY_BM_SIZE) },
+ // looks ugly, perhaps FIXME
+ // We'll waste several frames for the sake of easy alignment
+ skip_byte: 1 + ((map_start >> Mem::PAGE_SHIFT) / 8),
+ };
+ fmap
+ }
-pub struct Frame {
- pfn: usize,
-}
+ /// return : index to the bitmap u8 , bit mask to retrive the bit.
+ fn locate_bit(addr: usize) -> Option<(usize, u8)> {
+ if addr >= Mem::PHY_TOP {
+ return None
+ }
+ let pn = addr >> Mem::PAGE_SHIFT;
+ let idx = pn / 8;
+ let mask:u8 = 1 << (pn % 8);
+ Some((idx, mask))
+ }
-impl Frame {
- pub fn addr(&self) -> usize {
- self.pfn << Mem::PAGE_SHIFT
+ pub fn alloc_frame(&mut self) -> usize {
+ for i in self.skip_byte..self.bm.len() {
+ if self.bm[i] == 0xff {
+ continue
+ }
+ todo!()
+ }
+ 0
+ }
+
+ pub fn dealloc_frame(&mut self) -> Result<(),PMAError>{
+ Ok(())
}
-}
-// pub struct PageAlloctor;
+ pub fn init(&mut self) {
+ for i in 0..self.skip_byte {
+ self.bm[i] = 0xff;
+ }
+ for i in self.skip_byte..self.bm.len() {
+ self.bm[i] = 0;
+ }
+ }
+}