Skip to content

Commit

Permalink
core: riscv: Fix misconfiguration of XSCRATCH when XRET to kernel mode
Browse files Browse the repository at this point in the history
When the program wants to XRET to kernel mode, the value of XSCRATCH
must be cleared to zero.

Signed-off-by: Alvin Chang <alvinga@andestech.com>
  • Loading branch information
gagachang committed Sep 11, 2024
1 parent 910bc35 commit 9c11c01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/arch/riscv/kernel/thread_rv.S
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ native_interrupt_from_kernel:
/* Restore XIE */
load_xregs sp, THREAD_CTX_REG_IE, REG_T0
csrw CSR_XIE, t0
/* Set scratch as thread_core_local */
csrw CSR_XSCRATCH, tp
/* We are going to XRET to kernel mode. Set XSCRATCH as 0 */
csrw CSR_XSCRATCH, 0
/* Restore all GPRs */
load_xregs sp, THREAD_CTX_REG_RA, REG_RA
load_xregs sp, THREAD_CTX_REG_GP, REG_GP
Expand Down Expand Up @@ -252,8 +252,8 @@ set_sp:
/* Restore XIE */
load_xregs sp, THREAD_ABT_REG_IE, REG_T0
csrw CSR_XIE, t0
/* Set scratch as thread_core_local */
csrw CSR_XSCRATCH, tp
/* We are going to XRET to kernel mode. Set XSCRATCH as 0 */
csrw CSR_XSCRATCH, 0

/* Update core local flags */
lw a0, THREAD_CORE_LOCAL_FLAGS(tp)
Expand Down

0 comments on commit 9c11c01

Please sign in to comment.