feat: frame allocation
This commit is contained in:
+30
-3
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user