// 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_start; let heap_size; // UNSAFE: This is fine, just loading some constants. unsafe { // using inline assembly is easier to access linker constants asm!( "la {heap_start}, _heap_start", "la {heap_size}, _heap_size", heap_start = out(reg) heap_start, heap_size = out(reg) heap_size, options(nomem) ) }; println!( "Initialising kernel heap (bottom: {:#x}, size: {:#x})", heap_start as usize, heap_size ); // UNSAFE: Fine to call at most once. unsafe { ALLOCATOR.lock().init(heap_start, heap_size) }; }