forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arch: riscv: core: run zephyr completely in user/supervisor mode
Before that fix, zephyr was able to start only in machine mode. With that fix, zephyr can start (as guest) in user or supervisor mode. Fixes zephyrproject-rtos#68133 Signed-off-by: Sven Ginka <[email protected]>
- Loading branch information
Showing
13 changed files
with
121 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2016 Jean-Paul Etienne <[email protected]> | ||
* Copyright (c) 2018 Foundries.io Ltd | ||
* Copyright (c) 2020 BayLibre, SAS | ||
* Copyright (c) 2024 sensry GmbH | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -189,12 +190,12 @@ SECTION_FUNC(exception.entry, _isr_wrapper) | |
get_current_cpu s0 | ||
|
||
/* Save MEPC register */ | ||
csrr t0, mepc | ||
sr t0, __struct_arch_esf_mepc_OFFSET(sp) | ||
csrr t0, xepc | ||
sr t0, __struct_arch_esf_xepc_OFFSET(sp) | ||
|
||
/* Save MSTATUS register */ | ||
csrr t2, mstatus | ||
sr t2, __struct_arch_esf_mstatus_OFFSET(sp) | ||
csrr t2, xstatus | ||
sr t2, __struct_arch_esf_xstatus_OFFSET(sp) | ||
|
||
#if defined(CONFIG_FPU_SHARING) | ||
/* determine if FPU access was disabled */ | ||
|
@@ -319,7 +320,7 @@ no_fp: /* increment _current->arch.exception_depth */ | |
jal ra, __soc_is_irq | ||
bnez a0, is_interrupt | ||
#else | ||
csrr t0, mcause | ||
csrr t0, xcause | ||
srli t0, t0, RISCV_MCAUSE_IRQ_POS | ||
bnez t0, is_interrupt | ||
#endif | ||
|
@@ -329,7 +330,7 @@ no_fp: /* increment _current->arch.exception_depth */ | |
* perform a context-switch or an IRQ offload. Otherwise call _Fault | ||
* to report the exception. | ||
*/ | ||
csrr t0, mcause | ||
csrr t0, xcause | ||
li t2, CONFIG_RISCV_MCAUSE_EXCEPTION_MASK | ||
and t0, t0, t2 | ||
|
||
|
@@ -385,9 +386,9 @@ is_kernel_syscall: | |
* It's safe to always increment by 4, even with compressed | ||
* instructions, because the ecall instruction is always 4 bytes. | ||
*/ | ||
lr t0, __struct_arch_esf_mepc_OFFSET(sp) | ||
lr t0, __struct_arch_esf_xepc_OFFSET(sp) | ||
addi t0, t0, 4 | ||
sr t0, __struct_arch_esf_mepc_OFFSET(sp) | ||
sr t0, __struct_arch_esf_xepc_OFFSET(sp) | ||
|
||
#ifdef CONFIG_PMP_STACK_GUARD | ||
/* Re-activate PMP for m-mode */ | ||
|
@@ -505,9 +506,9 @@ is_user_syscall: | |
* Same as for is_kernel_syscall: increment saved MEPC by 4 to | ||
* prevent triggering the same ecall again upon exiting the ISR. | ||
*/ | ||
lr t1, __struct_arch_esf_mepc_OFFSET(sp) | ||
lr t1, __struct_arch_esf_xepc_OFFSET(sp) | ||
addi t1, t1, 4 | ||
sr t1, __struct_arch_esf_mepc_OFFSET(sp) | ||
sr t1, __struct_arch_esf_xepc_OFFSET(sp) | ||
|
||
/* Restore argument registers from user stack */ | ||
lr a0, __struct_arch_esf_a0_OFFSET(sp) | ||
|
@@ -565,7 +566,7 @@ is_interrupt: | |
* If we came from userspace then we need to reconfigure the | ||
* PMP for kernel mode stack guard. | ||
*/ | ||
lr t0, __struct_arch_esf_mstatus_OFFSET(sp) | ||
lr t0, __struct_arch_esf_xstatus_OFFSET(sp) | ||
li t1, MSTATUS_MPP | ||
and t0, t0, t1 | ||
bnez t0, 1f | ||
|
@@ -609,7 +610,7 @@ on_irq_stack: | |
#endif | ||
|
||
/* Get IRQ causing interrupt */ | ||
csrr a0, mcause | ||
csrr a0, xcause | ||
li t0, CONFIG_RISCV_MCAUSE_EXCEPTION_MASK | ||
and a0, a0, t0 | ||
|
||
|
@@ -714,10 +715,10 @@ fp_trap_exit: | |
#endif | ||
|
||
/* Restore MEPC and MSTATUS registers */ | ||
lr t0, __struct_arch_esf_mepc_OFFSET(sp) | ||
lr t2, __struct_arch_esf_mstatus_OFFSET(sp) | ||
csrw mepc, t0 | ||
csrw mstatus, t2 | ||
lr t0, __struct_arch_esf_xepc_OFFSET(sp) | ||
lr t2, __struct_arch_esf_xstatus_OFFSET(sp) | ||
csrw xepc, t0 | ||
csrw xstatus, t2 | ||
|
||
#ifdef CONFIG_USERSPACE | ||
/* | ||
|
@@ -775,4 +776,4 @@ fp_trap_exit: | |
|
||
#endif /* CONFIG_RISCV_SOC_HAS_ISR_STACKING */ | ||
|
||
mret | ||
xret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters