aboutsummaryrefslogtreecommitdiff
path: root/kernel/l0/kmain.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-12-07 19:59:34 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-12-07 19:59:34 +0100
commitf0475a3d517b4df8eb2b73f22eaec91a72bcc51f (patch)
tree084e6cd1db812cafdd67ba650796eda3091c2ea7 /kernel/l0/kmain.c
parentd7aaba8c85cc71f3184cddcf20b740c5157c864d (diff)
downloadkogata-f0475a3d517b4df8eb2b73f22eaec91a72bcc51f.tar.gz
kogata-f0475a3d517b4df8eb2b73f22eaec91a72bcc51f.zip
Implement multitasking.
Diffstat (limited to 'kernel/l0/kmain.c')
-rw-r--r--kernel/l0/kmain.c36
1 files changed, 29 insertions, 7 deletions
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 <region.h>
#include <kmalloc.h>
+#include <task.h>
+
#include <slab_alloc.h>
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 :*/