Skip to content

Commit 7893e1e

Browse files
committed
Switch task initialization to user mode
Tasks are now initialized to execute in U-mode rather than M-mode, enabling proper privilege isolation. The MPP field in mstatus is set to USER instead of MACH during context initialization.
1 parent 7ce46f3 commit 7893e1e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/riscv/hal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,12 @@ void hal_context_init(jmp_buf *ctx, size_t sp, size_t ss, size_t ra)
822822
/* Set the essential registers for a new task:
823823
* - SP is set to the prepared top of the task's stack.
824824
* - RA is set to the task's entry point.
825-
* - mstatus is set to enable interrupts and ensure machine mode.
825+
* - mstatus is set to enable interrupts and ensure user mode.
826826
*
827827
* When this context is first restored, the ret instruction will effectively
828828
* jump to this entry point, starting the task.
829829
*/
830830
(*ctx)[CONTEXT_SP] = (uint32_t) stack_top;
831831
(*ctx)[CONTEXT_RA] = (uint32_t) ra;
832-
(*ctx)[CONTEXT_MSTATUS] = MSTATUS_MIE | MSTATUS_MPP_MACH;
832+
(*ctx)[CONTEXT_MSTATUS] = MSTATUS_MIE | MSTATUS_MPP_USER;
833833
}

0 commit comments

Comments
 (0)