Skip to content

Commit

Permalink
Document what we mean by scheduling on this kernel
Browse files Browse the repository at this point in the history
The notion of 'scheduling' a process on this kernel is effectively the
same as starting the process anew. This is pretty bananas for any
general purpose kernel, but this is not our case.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Nov 30, 2024
1 parent f560a53 commit a7287a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 17 additions & 4 deletions kernel/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a7287a7

Please sign in to comment.