Add a linked list allocator for heap that can now do 256 mib due to

frame allocator optimizations, make a basic init function in arch that
will initialize everything for a given arch. Add tests in kmain for
alloc, and add a Locked struct used for static mutables and the linked
list.
This commit is contained in:
csd4ni3l
2026-03-28 15:06:16 +01:00
parent 269d900d97
commit 4a3c1c9ced
8 changed files with 285 additions and 67 deletions

View File

@@ -1,8 +1,31 @@
use crate::arch::x86_64::gdt::load_gdt_x86_64;
use crate::arch::x86_64::interrupts::{PICS, init_idt_x86_64};
use limine::response::{HhdmResponse, MemoryMapResponse};
use x86_64::instructions::interrupts;
pub fn init_x86_64() {
#[cfg(target_arch = "x86_64")]
use crate::arch::x86_64::{
heap::init_heap,
paging::{XunilFrameAllocator, initialize_paging},
};
#[cfg(target_arch = "x86_64")]
use x86_64::{VirtAddr, structures::paging::OffsetPageTable};
#[cfg(target_arch = "x86_64")]
pub fn memory_management_init<'a>(
hhdm_response: &HhdmResponse,
memory_map_response: &'a MemoryMapResponse,
) -> (OffsetPageTable<'static>, XunilFrameAllocator<'a>) {
let physical_offset = VirtAddr::new(hhdm_response.offset());
let mapper = unsafe { initialize_paging(physical_offset) };
let frame_allocator = XunilFrameAllocator::new(memory_map_response.entries());
(mapper, frame_allocator)
}
pub fn init_x86_64<'a>(
hhdm_response: &HhdmResponse,
memory_map_response: &'a MemoryMapResponse,
) -> (OffsetPageTable<'static>, XunilFrameAllocator<'a>) {
load_gdt_x86_64();
init_idt_x86_64();
@@ -13,4 +36,13 @@ pub fn init_x86_64() {
}
interrupts::enable();
let (mut mapper, mut frame_allocator) =
memory_management_init(hhdm_response, memory_map_response);
init_heap(&mut mapper, &mut frame_allocator)
.ok()
.expect("Failed to initalize heap");
return (mapper, frame_allocator);
}