From f0475a3d517b4df8eb2b73f22eaec91a72bcc51f Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 7 Dec 2014 19:59:34 +0100 Subject: Implement multitasking. --- kernel/l0/kmain.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'kernel/l0/kmain.c') diff --git a/kernel/l0/kmain.c b/kernel/l0/kmain.c index e6831b2..0a6bed9 100644 --- a/kernel/l0/kmain.c +++ b/kernel/l0/kmain.c @@ -10,6 +10,8 @@ #include #include +#include + #include extern char k_end_addr; // defined in linker script : 0xC0000000 plus kernel stuff @@ -19,11 +21,6 @@ void breakpoint_handler(registers_t *regs) { BOCHS_BREAKPOINT; } -void yield() { - // multitasking not implemented yet - dbg_printf("Warning : probable deadlock?\n"); -} - void region_test1() { void* p = region_alloc(0x1000, REGION_T_HW, 0); dbg_printf("Allocated one-page region: 0x%p\n", p); @@ -102,6 +99,28 @@ void kmalloc_test(void* kernel_data_end) { dbg_printf("Kmalloc test OK.\n"); dbg_print_region_stats(); } + +void test_task(void* a) { + int i = 0; + while(1) { + dbg_printf("b"); + for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx"); + if (++i == 8) { + yield(); + i = 0; + } + } +} +void kernel_init_stage2(void* data) { + task_t *tb = new_task(test_task); + resume_with_result(tb, 0, false); + + while(1) { + dbg_printf("a"); + for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx"); + } + PANIC("Reached kmain end! Falling off the edge."); +} void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { dbglog_setup(); @@ -141,8 +160,11 @@ void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { kmalloc_setup(); kmalloc_test(kernel_data_end); - - PANIC("Reached kmain end! Falling off the edge."); + // enter multi-tasking mode + // interrupts are enabled at this moment, so all + // code run from now on should be preemtible (ie thread-safe) + tasking_setup(kernel_init_stage2, 0); + PANIC("Should never come here."); } /* vim: set ts=4 sw=4 tw=0 noet :*/ -- cgit v1.2.3