diff options
Diffstat (limited to 'src/kernel/core')
-rw-r--r-- | src/kernel/core/kmain.c | 15 | ||||
-rw-r--r-- | src/kernel/core/test.c | 50 |
2 files changed, 40 insertions, 25 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index 6c9700e..8f14843 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -1,4 +1,6 @@ #include <types.h> +#include <config.h> + #include "multiboot.h" #include "monitor.h" #include "sys.h" @@ -24,7 +26,7 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) { size_t totalRam = 0; uint32_t i; - mem_placementAddr = (size_t)&end; + mem_placementAddr = ((size_t)&end & 0xFFFFF000) + 0x1000; mbd->cmdline += 0xE0000000; mbd->mods_addr += 0xE0000000; struct module_t *mods = (struct module_t*)mbd->mods_addr; for (i = 0; i < mbd->mods_count; i++) { @@ -35,7 +37,12 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) { mem_placementAddr = (mods[i].mod_end & 0xFFFFF000) + 0x1000; } - monitor_write("Grapes 0.0.4 'Cat in my heart' starting up :\n"); + monitor_write(K_OS_NAME); + monitor_write(" version "); + monitor_write(K_OS_VER); + monitor_write(" codename '"); + monitor_write(K_OS_CODENAME); + monitor_write("' starting up :\n"); idt_init(); @@ -47,6 +54,8 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) { kheap_init(); timer_init(30); tasking_init(); + + test_run(); monitor_write("\nLoading modules :\n"); for (i = 0; i < mbd->mods_count; i++) { @@ -64,8 +73,6 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) { } } - test_run(); - monitor_write("Modules now RULE THE WORLD !\n"); sti(); tasking_switch(); diff --git a/src/kernel/core/test.c b/src/kernel/core/test.c index fa26c7b..867a4b5 100644 --- a/src/kernel/core/test.c +++ b/src/kernel/core/test.c @@ -3,27 +3,35 @@ #include <mem/mem.h> #include "sys.h" -#define TEST_KMALLOC(var, sz) void *var = kmalloc(sz); ASSERT(var > 0xE0000000); -#define TEST_KFREE(var) if (var != 0) { kfree(var); } +static void test_run_kmalloc() { + monitor_write("\tkmalloc:\n"); + int alloc_sizes[8] = { 10, 32, 16, 20, 64, 128, 32, 48 }; + int *ptrs[8] = { 0 }; + int t, i; + for (t = 0; t < 2; t++) { + for (i = 0; i < 8; i++) { + monitor_writeDec(i); monitor_write(" alloc "); monitor_writeDec(alloc_sizes[i]); + monitor_write(" : "); + ptrs[i] = kmalloc(alloc_sizes[i]); + ASSERT(ptrs[i] != 0); + *ptrs[i] = i; + monitor_writeHex((int)ptrs[i]); monitor_write("\n"); + } + monitor_write("free : "); + for (i = 0; i < 8; i++) { + monitor_writeDec(i); + ASSERT(*ptrs[i] == i); + kfree(ptrs[i]); + monitor_write("."); + } + monitor_write("\n"); + } +} +/* This function is called when the kernel starts up. + It runs some basic unit tests (for the moment, only tests kmalloc/kfree) */ void test_run() { - monitor_write("Unit tests:\n\tkmalloc:"); - int i; - for (i = 1; i <= 7; i++) { - monitor_write(" #"); monitor_writeDec(i); - TEST_KMALLOC(a, 32); - TEST_KMALLOC(b, 64); - TEST_KMALLOC(c, 256); - TEST_KMALLOC(d, 512); - TEST_KMALLOC(e, 1024); - TEST_KMALLOC(f, 4096); - TEST_KMALLOC(g, 16384); - TEST_KFREE(b); - TEST_KFREE(c); - TEST_KFREE(d); - TEST_KFREE(e); - TEST_KFREE(f); - TEST_KFREE(g); - } - monitor_write("\n >> Tests OK\n"); + monitor_write("Unit tests:\n"); + test_run_kmalloc(); + monitor_write(" >> Tests OK\n"); } |