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

@@ -2,42 +2,16 @@ use core::arch::asm;
use limine::response::{HhdmResponse, MemoryMapResponse};
#[cfg(target_arch = "x86_64")]
use crate::arch::x86_64::{
init::init_x86_64,
paging::{XunilFrameAllocator, example_mapping, initialize_paging},
};
use crate::arch::x86_64::{init::init_x86_64, paging::XunilFrameAllocator};
#[cfg(target_arch = "x86_64")]
use x86_64::{
VirtAddr, registers::control::Cr3, structures::paging::OffsetPageTable,
structures::paging::Page,
};
use x86_64::structures::paging::OffsetPageTable;
#[cfg(target_arch = "x86_64")]
pub fn memory_management_init(
pub fn init<'a>(
hhdm_response: &HhdmResponse,
memory_map_response: &MemoryMapResponse,
) -> OffsetPageTable<'static> {
let physical_offset = VirtAddr::new(hhdm_response.offset());
let (frame, _) = Cr3::read();
let mut mapper = unsafe { initialize_paging(physical_offset) };
let l4_virt = physical_offset + frame.start_address().as_u64() + 0xb8000;
let mut frame_allocator = XunilFrameAllocator::new(memory_map_response.entries());
let page = Page::containing_address(l4_virt);
unsafe {
example_mapping(page, &mut mapper, &mut frame_allocator);
}
mapper
}
#[cfg(target_arch = "x86_64")]
pub fn init(
hhdm_response: &HhdmResponse,
memory_map_response: &MemoryMapResponse,
) -> OffsetPageTable<'static> {
init_x86_64();
return memory_management_init(hhdm_response, memory_map_response);
memory_map_response: &'a MemoryMapResponse,
) -> (OffsetPageTable<'static>, XunilFrameAllocator<'a>) {
return init_x86_64(hhdm_response, memory_map_response);
}
pub fn idle() -> ! {