Freelist testing in start
This commit is contained in:
parent
9df66792f2
commit
435b712f25
1 changed files with 20 additions and 1 deletions
21
kern/start.c
21
kern/start.c
|
|
@ -2,6 +2,7 @@
|
||||||
#include <banner.h>
|
#include <banner.h>
|
||||||
#include <buddy.h>
|
#include <buddy.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <freelist.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <panic.h>
|
#include <panic.h>
|
||||||
#include <proc.h>
|
#include <proc.h>
|
||||||
|
|
@ -11,6 +12,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <uart.h>
|
#include <uart.h>
|
||||||
|
#include <util.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate one stack per CPU (hart).
|
* Allocate one stack per CPU (hart).
|
||||||
|
|
@ -39,7 +41,7 @@ void start() {
|
||||||
// cpu (struct Cpu).
|
// cpu (struct Cpu).
|
||||||
write_tp(id);
|
write_tp(id);
|
||||||
|
|
||||||
if (id == 0) {
|
if (unlikely(id == 0)) {
|
||||||
/* Here we will do a bunch of initialization steps */
|
/* Here we will do a bunch of initialization steps */
|
||||||
memory_sweep(heap_start, heap_end);
|
memory_sweep(heap_start, heap_end);
|
||||||
buddy_init(heap_start, heap_end);
|
buddy_init(heap_start, heap_end);
|
||||||
|
|
@ -60,6 +62,23 @@ void start() {
|
||||||
else
|
else
|
||||||
PANIC("Some cores seem to have been enumerated incorrectly!\n");
|
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");
|
kprintf("To exit qemu, press CTRL+a followed by x\n");
|
||||||
spin_unlock(&sl);
|
spin_unlock(&sl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue