1
0
Fork 0

feat/kernel: Added First-Fit algorithm for kernel heap

This commit is contained in:
Kevin Alavik 2025-05-15 19:52:40 +02:00
parent 65fbb97d8a
commit 6374144f4a
Signed by: cmpsb
GPG key ID: 10D1CC0526FDC6D7
6 changed files with 134 additions and 2 deletions

View file

@ -12,6 +12,7 @@
#include <mm/pmm.h>
#include <arch/paging.h>
#include <mm/vmm.h>
#include <mm/heap.h>
__attribute__((used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
__attribute__((used, section(".limine_requests"))) static volatile struct limine_memmap_request memmap_request = {
@ -31,6 +32,7 @@ struct limine_memmap_response *memmap = NULL;
uint64_t kvirt = 0;
uint64_t kphys = 0;
uint64_t kstack_top = 0;
vctx_t *kvm_ctx = NULL;
void emk_entry(void)
{
@ -91,7 +93,7 @@ void emk_entry(void)
log_early("Initialized paging");
/* Kernel Virtual Memory Context, not to be confused with KVM */
vctx_t *kvm_ctx = vinit(kernel_pagemap, 0x1000);
kvm_ctx = vinit(kernel_pagemap, 0x1000);
if (!kvm_ctx)
{
kpanic(NULL, "Failed to create kernel VMM context");
@ -108,5 +110,18 @@ void emk_entry(void)
vfree(kvm_ctx, b);
log_early("Initialized virtual page manager");
/* Setup kernel heap */
heap_init();
char *c = kmalloc(1);
if (!c)
{
kpanic(NULL, "Failed to allocate single byte on heap");
}
*c = 32;
log_early("Allocated 1 byte @ %llx", (uint64_t)c);
kfree(c);
log_early("Initialized kernel heap");
hlt();
}