Skip to content

Commit e2eec20

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 03adecd commit e2eec20

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
@@ -784,12 +784,12 @@ void hal_context_init(jmp_buf *ctx, size_t sp, size_t ss, size_t ra)
784784
/* Set the essential registers for a new task:
785785
* - SP is set to the prepared top of the task's stack.
786786
* - RA is set to the task's entry point.
787-
* - mstatus is set to enable interrupts and ensure machine mode.
787+
* - mstatus is set to enable interrupts and ensure user mode.
788788
*
789789
* When this context is first restored, the ret instruction will effectively
790790
* jump to this entry point, starting the task.
791791
*/
792792
(*ctx)[CONTEXT_SP] = (uint32_t) stack_top;
793793
(*ctx)[CONTEXT_RA] = (uint32_t) ra;
794-
(*ctx)[CONTEXT_MSTATUS] = MSTATUS_MIE | MSTATUS_MPP_MACH;
794+
(*ctx)[CONTEXT_MSTATUS] = MSTATUS_MIE | MSTATUS_MPP_USER;
795795
}

0 commit comments

Comments
 (0)