diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/fbos/printk.h | 2 | ||||
| -rw-r--r-- | include/fbos/sched.h | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/include/fbos/printk.h b/include/fbos/printk.h index 5a12d7c..d5f4804 100644 --- a/include/fbos/printk.h +++ b/include/fbos/printk.h @@ -11,7 +11,7 @@ #ifdef __KERNEL__ extern void die(const char *const message); extern void printk(const char *const message); -extern void write(const char *const message, size_t n); +extern void sys_write(const char *const message, size_t n); #else #include <stdio.h> #include <stdlib.h> diff --git a/include/fbos/sched.h b/include/fbos/sched.h index f43b6e5..e8edafd 100644 --- a/include/fbos/sched.h +++ b/include/fbos/sched.h @@ -12,6 +12,9 @@ enum task_id { TASK_FIZZBUZZ = 3, }; +// Maximum length for the name of the process. +#define TASK_NAME_LEN 16 + // All the information we need to grab for processes. struct task_struct { // The stack allocated for the process. As you can see when initializing @@ -20,6 +23,9 @@ struct task_struct { // for simple `sp` values. void *stack; + // Name of the task to be printed for debugging purposes. + const char name[TASK_NAME_LEN]; + // The address for the binary entry. const void *entry_addr; }; @@ -27,14 +33,26 @@ struct task_struct { // Tasks available on this kernel. extern struct task_struct tasks[4]; -// Set the return address to U-mode to the given task. -__kernel __always_inline void set_return_address_to(int task_id) +// Prepare for switching to the given task. Note that this will not actually +// jump into the given task, but it will prepare the relevant registers before +// performing the actual jump. +__kernel __always_inline void prepare_switch_to(int task_id) { + register struct task_struct *current asm("tp"); + asm volatile("csrc sstatus, %0\n\t" "mv t0, %1\n\t" "csrw sepc, t0" ::"r"(1 << 8), "r"(tasks[task_id].entry_addr) : "t0"); + + current = &tasks[task_id]; + + // Not really unused, but I was getting into lots of petty trouble with GCC + // depending if running with/without DEBUG on. Hence, let's set 'tp' in C + // instead of with inline assembly, even if the compiler thinks the variable + // is set but not used. + __unused(current); } #endif // __FBOS_SCHED_H_ |
