// src/heap.rs //! Provides the kernel heap. use core::arch::asm; use linked_list_allocator::LockedHeap; use crate::println; #[global_allocator] static ALLOCATOR: LockedHeap = LockedHeap::empty(); /// Initialise the kernel heap. /// # Safety /// Must be called at most once. pub unsafe fn init() { let heap_bottom; let heap_size; // UNSAFE: This is fine, just loading some constants. unsafe { // using inline assembly is easier to access linker constants asm!( "la {heap_bottom}, _kernel_heap_bottom", "la {heap_size}, _kernel_heap_size", heap_bottom = out(reg) heap_bottom, heap_size = out(reg) heap_size, options(nomem) ) }; println!( "Initialising kernel heap (bottom: {:#x}, size: {:#x})", heap_bottom as usize, heap_size ); // UNSAFE: Fine to call at most once. unsafe { ALLOCATOR.lock().init(heap_bottom, heap_size) }; }