From dbefd9336cc808e76f8e9d8d238f5a348d14604a Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Sun, 25 Feb 2024 04:55:09 +0100 Subject: add mm and ds modules (yet empty) --- src/mm/heap_allocator.rs | 2 ++ src/mm/mod.rs | 1 + src/mm/pma.rs | 28 +++++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/mm/heap_allocator.rs (limited to 'src/mm') diff --git a/src/mm/heap_allocator.rs b/src/mm/heap_allocator.rs new file mode 100644 index 0000000..5a7463d --- /dev/null +++ b/src/mm/heap_allocator.rs @@ -0,0 +1,2 @@ +#![feature(global_allocator, allocator_api, heap_api)] +struct HeapAllocator; diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 1298d0d..b030dfb 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -1 +1,2 @@ +pub mod heap_allocator; pub mod pma; diff --git a/src/mm/pma.rs b/src/mm/pma.rs index f9a40ee..aa5e193 100644 --- a/src/mm/pma.rs +++ b/src/mm/pma.rs @@ -1,9 +1,31 @@ -use core::ffi::c_void; use crate::defs::Mem; +use core::ffi::c_void; +use core::{ptr, slice}; // this is POC code, it will be ugly + extern "C" { - static KERNEL_END: *const c_void; + 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 } -// pub struct PageAlloctor; +// TODO PMA initialization : needs to singleton + +impl PFMap {} +pub struct Frame { + pfn: usize, +} + +impl Frame { + pub fn addr(&self) -> usize { + self.pfn << Mem::PAGE_SHIFT + } +} + +// pub struct PageAlloctor; -- cgit v1.2.3-70-g09d2