Refactor initial memory paging

This commit is contained in:
Andrey Turkin
2024-07-16 06:58:35 +03:00
parent 3fbd52a212
commit 0a6a90415a
16 changed files with 651 additions and 1284 deletions
+17
View File
@@ -25,6 +25,23 @@ use crate::{
};
use rmm::{BumpAllocator, FrameAllocator, FrameCount, FrameUsage, TableKind, VirtualAddress};
/// Available physical memory areas
pub(crate) static AREAS: SyncUnsafeCell<[rmm::MemoryArea; 512]> = SyncUnsafeCell::new(
[rmm::MemoryArea {
base: PhysicalAddress::new(0),
size: 0,
}; 512],
);
pub(crate) static AREA_COUNT: SyncUnsafeCell<u16> = SyncUnsafeCell::new(0);
// TODO: Share code
pub(crate) fn areas() -> &'static [rmm::MemoryArea] {
// SAFETY: Both AREAS and AREA_COUNT are initialized once and then never changed.
//
// TODO: Memory hotplug?
unsafe { &(&*AREAS.get())[..AREA_COUNT.get().read().into()] }
}
/// Get the number of frames available
pub fn free_frames() -> usize {
total_frames() - used_frames()