diff options
Diffstat (limited to 'src/kernel/task.c')
-rw-r--r-- | src/kernel/task.c | 90 |
1 files changed, 84 insertions, 6 deletions
diff --git a/src/kernel/task.c b/src/kernel/task.c index 3e64639..79b2f09 100644 --- a/src/kernel/task.c +++ b/src/kernel/task.c @@ -1,14 +1,92 @@ #include "panic.h" #include "task.h" +#include "paging.h" -segment_id new_segment(bool is_code, uint32_t length, uint32_t *location_out) { - panic("TODO: make new segment"); +struct tss { + struct tss *prev; + + uint32_t esp0; + uint32_t ss0; + uint32_t esp1; + uint32_t ss1; + uint32_t esp2; + uint32_t ss2; + + uint32_t cr3; + uint32_t eip; + uint32_t eflags; + + uint32_t eax; + uint32_t ecx; + uint32_t edx; + uint32_t ebx; + uint32_t esp; + uint32_t ebp; + uint32_t esi; + uint32_t edi; + + uint32_t es; + uint32_t cs; + uint32_t ss; + uint32_t ds; + uint32_t fs; + uint32_t gs; + + uint32_t ldt; + uint16_t trap; + uint16_t iomp; +} __attribute__ ((packed)); + +#define TSS ((struct tss *)0x00004f98) + +#define MAX_TASKS 64 + +struct task_state tasks[MAX_TASKS]; +struct task_state *active_task; + +void init_tasks() { + active_task = tasks; + + for (uint8_t i = 0; i < MAX_TASKS; ++i) + tasks[i].page_directory = 0; + + TSS->ss0 = 0x18; + TSS->esp0 = 0x00040000; +//TSS->cs = 0x13; +//TSS->ds = 0x1b; +//TSS->ss = 0x1b; + TSS->iomp = sizeof(struct tss); + + asm volatile ( + "mov $0x08, %%ax\n" + "ltr %%ax" + : : : "ax"); +} + +void new_task(struct task_state state) { + for (uint8_t n = 0; n < MAX_TASKS; ++n) + if (!tasks[n].page_directory) { + tasks[n] = state; + return; + } + panic("Maximum number of tasks reached."); } -segment_id mirror_segment(bool is_code, segment_id other) { - panic("TODO: make new segment with same base and limit"); +void advance_active_task() { + struct task_state *prev_task = active_task; + do { + if (++active_task == tasks + MAX_TASKS) + active_task = tasks; + if (active_task == prev_task) { + logsz("No active tasks.\nHalting."); + while (1) + asm ("hlt"); + } + } + while (!active_task->page_directory); } -task_handle new_task(segment_id cs, segment_id ds, uint32_t eip, uint32_t esp) { - panic("TODO: add task to scheduler"); +void delete_task(struct task_state *state) { + free_task_pd(state->page_directory); + state->page_directory = 0; }
\ No newline at end of file |