Add preemptive switch_task to timer
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 1aebed6..46fc885 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -19,12 +19,12 @@
void other_thread()
{
- greet();
- kprintf("Other thread returning...\n");
- switch_task();
-
while (true)
- asm volatile("hlt");
+ {
+ greet();
+ for (int i = 0; i < 0xffffff; i++)
+ asm volatile("nop");
+ }
}
int kmain(struct multiboot_info *mboot)
@@ -77,17 +77,18 @@
init_tasks();
kprintf("\ndone initializing tasks\n");
- greet();
- kprintf("other_thread = 0x%x\n", &other_thread);
spawn_thread(other_thread);
- kprintf("thread spawned\n");
-
- switch_task();
- kprintf("Back in main thread\n");
asm volatile("sti");
while (true)
+ {
+ greet();
+ for (int i = 0; i < 0xffffff; i++)
+ asm volatile("nop");
+ }
+
+ while (true)
asm volatile("hlt");
return 0xCAFEBABE;
diff --git a/src/kernel/task.c b/src/kernel/task.c
index b460f25..e891ff2 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -10,8 +10,6 @@
void _init_tasks(uint kernel_esp, uint kernel_ebp, uint kernel_eip)
{
- asm volatile("cli");
-
kprintf("_init_tasks\n");
processes[0] = (struct process){
@@ -43,8 +41,6 @@
};
kprintf("Returning from _init_tasks\n");
-
- asm volatile("sti");
}
struct process *get_process(uint pid)
diff --git a/src/kernel/timer.c b/src/kernel/timer.c
index bafd06c..8ed0be8 100644
--- a/src/kernel/timer.c
+++ b/src/kernel/timer.c
@@ -3,12 +3,14 @@
#include "log.h"
#include "pic.h"
#include "registers.h"
+#include "task.h"
static ulong tick = 0;
static void timer_cb(struct registers *regs)
{
- // do nothing :)
+ // Preemptive multitasking!
+ switch_task();
}
void init_timer(uint hz)