feat: frame allocation

This commit is contained in:
Zoe
2026-08-19 09:58:43 -05:00
parent 2a1bf17d8b
commit 35d18495ec
7 changed files with 498 additions and 104 deletions
+30 -3
View File
@@ -15,13 +15,40 @@ pub extern "C" fn _start() -> ! {
serial::init().unwrap();
arch::init();
let _boot_info = boot::load_boot_info().unwrap();
let boot_info = boot::load_boot_info().unwrap();
let mut allocator = memory::FrameAllocator::new(
boot_info.memory_regions(),
memory::DirectMap::new(boot_info.hhdm_offset),
)
.expect("failed to create frame allocator");
let initial = allocator.free_frames();
let first = allocator.alloc().unwrap();
let second = allocator.alloc().unwrap();
let third = allocator.alloc().unwrap();
assert_ne!(first, second);
assert_ne!(second, third);
assert_eq!(allocator.free_frames(), initial - 3);
let addr = 0xDEADBEEF as *mut u32;
unsafe {
*addr = 0xDEADBEEF;
allocator.dealloc(second);
allocator.dealloc(first);
allocator.dealloc(third);
}
assert_eq!(allocator.free_frames(), initial);
let a = allocator.alloc().unwrap();
let b = allocator.alloc().unwrap();
let c = allocator.alloc().unwrap();
assert_ne!(a, b);
assert_ne!(b, c);
assert_ne!(a, c);
hcf();
}