Skip to content

Commit

Permalink
Rename 'switch_to' to 'set_return_address_to'
Browse files Browse the repository at this point in the history
The original name came from a previous hack the did not work but somehow
the old name remained. Now it was more misleading than anything else, so
let's rename it to something that is closer to what it actually does.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Nov 30, 2024
1 parent 891742e commit f560a53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 2 additions & 4 deletions include/fbos/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ struct task_struct {
// Tasks available on this kernel.
extern struct task_struct tasks[4];

// Switch execution to the given U-mode task. Note that this function will not
// do the actual returning, but it prepares the relevant registers for an
// eventual jump.
__kernel __always_inline void switch_to(int task_id)
// Set the return address to U-mode to the given task.
__kernel __always_inline void set_return_address_to(int task_id)
{
asm volatile("csrc sstatus, %0\n\t"
"mv t0, %1\n\t"
Expand Down
9 changes: 4 additions & 5 deletions kernel/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ __aligned(4) __s_interrupt __kernel void interrupt_handler(void)

if (IS_EXCEPTION(cause)) {
exception_handler(cause);
switch_to(TASK_INIT);
set_return_address_to(TASK_INIT);
goto end;
}

Expand All @@ -94,12 +94,11 @@ __aligned(4) __s_interrupt __kernel void interrupt_handler(void)
// BEHOLD! The fizz buzz logic! :D
seconds_elapsed += 1;
if ((seconds_elapsed % 15) == 0) {
switch_to(TASK_FIZZBUZZ);
set_return_address_to(TASK_FIZZBUZZ);
} else if ((seconds_elapsed % 5) == 0) {
switch_to(TASK_BUZZ);
set_return_address_to(TASK_BUZZ);
} else if ((seconds_elapsed % 3) == 0) {
switch_to(TASK_FIZZ);
} else {
set_return_address_to(TASK_FIZZ);
}

// Re-enable timer interrupts.
Expand Down

0 comments on commit f560a53

Please sign in to comment.