aboutsummaryrefslogtreecommitdiff
path: root/kernel/task/sched.c
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2014-03-17 15:53:45 +0100
committerJakob Odersky <jodersky@gmail.com>2014-03-17 15:53:45 +0100
commit5466218a5f9fb3d46f608806f222fcc99a306a4b (patch)
tree2d82056fe24bc508a985881149595fd83760b72a /kernel/task/sched.c
parentd106637504ec4cb5fa63feab11bd845faea2bc07 (diff)
downloadmux-5466218a5f9fb3d46f608806f222fcc99a306a4b.tar.gz
mux-5466218a5f9fb3d46f608806f222fcc99a306a4b.tar.bz2
mux-5466218a5f9fb3d46f608806f222fcc99a306a4b.zip
no time scheduler
Diffstat (limited to 'kernel/task/sched.c')
-rw-r--r--kernel/task/sched.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/kernel/task/sched.c b/kernel/task/sched.c
new file mode 100644
index 0000000..652d562
--- /dev/null
+++ b/kernel/task/sched.c
@@ -0,0 +1,45 @@
+#include "bug/panic.h"
+#include "task/task.h"
+#include "task/sched.h"
+#include "mcu/task/context.h"
+#include "mcu/task/context.h"
+
+
+struct tcb_t* volatile current = 0;
+
+struct list_head ready = LIST_HEAD_INIT(ready);
+
+void* volatile kstack;
+
+void spawn(struct tcb_t* const tcb) {
+ tcb->sp = stack_init(tcb->mem_low, tcb->mem_high, tcb->entry, tcb->id);
+ INIT_LIST_HEAD(&tcb->queue);
+ list_add_tail(&tcb->queue, &ready);
+}
+
+void yield(void) {
+ cli();
+ context_save();
+ schedule();
+ context_restore();
+ sei();
+ ret();
+}
+
+
+void sched_init() {
+ kstack_init(&kstack);
+ schedule();
+ context_restore();
+ sei();
+ ret();
+}
+
+void schedule() {
+ if(!list_empty(&ready)) {
+ current = list_entry(ready.next, struct tcb_t, queue);
+ list_move_tail(ready.next, &ready);
+ } else {
+ panic();
+ }
+} \ No newline at end of file