Freelist testing in start

This commit is contained in:
Imbus 2025-09-09 12:10:05 +02:00
parent 9df66792f2
commit 435b712f25

View file

@ -2,6 +2,7 @@
#include <banner.h>
#include <buddy.h>
#include <config.h>
#include <freelist.h>
#include <memory.h>
#include <panic.h>
#include <proc.h>
@ -11,6 +12,7 @@
#include <stdio.h>
#include <string.h>
#include <uart.h>
#include <util.h>
/**
* 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);
}