diff options
| -rw-r--r-- | kernel/head.S | 4 | ||||
| -rw-r--r-- | kernel/trap.c | 21 |
2 files changed, 20 insertions, 5 deletions
diff --git a/kernel/head.S b/kernel/head.S index 210eb7c..31f423e 100644 --- a/kernel/head.S +++ b/kernel/head.S @@ -94,7 +94,9 @@ _start_kernel: li t6, 0 csrw sscratch, 0 - // Point tp and sp to the init task. + // Point tp and sp to the init task. This is not crucial because in the end + // we are not doing anything with the 'tp' register, and our processes + // actually don't do anything on the stack. la tp, tasks la sp, tasks + THREAD_SIZE diff --git a/kernel/trap.c b/kernel/trap.c index 4e31b6d..54bf6aa 100644 --- a/kernel/trap.c +++ b/kernel/trap.c @@ -67,9 +67,6 @@ __kernel __always_inline void exception_handler(uint64_t cause) * all registers. It's probably a bit over the top since it also does that for * registers we never care on this kernel (e.g. floating point registers), but * it's convenient. - * - * TODO: once this properly works, switch it to assembly to avoid creepy - * statements like the sad 'goto end' one. */ __aligned(4) __s_interrupt __kernel void interrupt_handler(void) { @@ -114,7 +111,23 @@ __aligned(4) __s_interrupt __kernel void interrupt_handler(void) printk("WARN: unknown interrupt just came in...\n"); } -end:; +end: + /* + * Here the restoring of the stack will happen, so it's actually not empty. + * + * NOTE: the restore of registers when we switch to another process here is + * actually pretty pointless (we are not 'restoring' anything in the point + * of view of the process we are about to schedule), but we keep the 'sp' + * register sane, at least. + * + * Anyways, when we schedule a process in this kernel we don't actually + * schedule it in the proper sense: we don't return to the last 'pc' for + * that process, but we actually run it from the entry address again. This + * is not relevant for this kernel because in the end our processes only do + * one thing, and 're-starting' is effectively the same in this (silly) + * kernel of ours :) + */ + ; } __kernel void setup_interrupts(void) |
