From 435b712f2542f62c8325844125ea750bc36c3288 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 9 Sep 2025 12:10:05 +0200 Subject: [PATCH] Freelist testing in start --- kern/start.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kern/start.c b/kern/start.c index c892765..7d0e855 100644 --- a/kern/start.c +++ b/kern/start.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include /** * Allocate one stack per CPU (hart). @@ -39,7 +41,7 @@ void start() { // cpu (struct Cpu). write_tp(id); - if (id == 0) { + if (unlikely(id == 0)) { /* Here we will do a bunch of initialization steps */ memory_sweep(heap_start, heap_end); buddy_init(heap_start, heap_end); @@ -60,6 +62,23 @@ void start() { else PANIC("Some cores seem to have been enumerated incorrectly!\n"); + { + FreeList fl; + void *mem = buddy_alloc(4096); + fl_init(&fl, (uintptr_t)mem, 4096, sizeof(int)); + + uint32_t *hello = fl_alloc(&fl); + + *hello = UINT32_MAX; + + int a = fl_available(&fl); + assert_msg(fl_check(&fl) > 0, "FreeList checking failed, might be corrupt."); + kprintf("Available: %d\n", a); + kprintf("Size: %d\n", fl.size); + + buddy_free(mem); + } + kprintf("To exit qemu, press CTRL+a followed by x\n"); spin_unlock(&sl); }