From 9ad9e705263d63bc89e01b35d55b04bdc232d32f Mon Sep 17 00:00:00 2001 From: Alvin Chang Date: Mon, 9 Sep 2024 13:42:25 +0800 Subject: [PATCH] core: riscv: Set exception return PC into XEPC instead of ra Instead of setting exception return PC into "ra" register and assign it to XEPC, we should directly set exception return PC into "XEPC" CSR to improve code redability. Signed-off-by: Alvin Chang --- core/arch/riscv/kernel/thread_arch.c | 2 +- core/arch/riscv/kernel/thread_rv.S | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/core/arch/riscv/kernel/thread_arch.c b/core/arch/riscv/kernel/thread_arch.c index 7dbf1f52aee..5db551d8219 100644 --- a/core/arch/riscv/kernel/thread_arch.c +++ b/core/arch/riscv/kernel/thread_arch.c @@ -503,7 +503,7 @@ static void set_ctx_regs(struct thread_ctx_regs *regs, unsigned long a0, .a3 = a3, .s0 = 0, .sp = user_sp, - .ra = entry_func, + .epc = entry_func, .status = status, .ie = ie, }; diff --git a/core/arch/riscv/kernel/thread_rv.S b/core/arch/riscv/kernel/thread_rv.S index 5b246cf4066..b0d5f1f9362 100644 --- a/core/arch/riscv/kernel/thread_rv.S +++ b/core/arch/riscv/kernel/thread_rv.S @@ -606,11 +606,12 @@ FUNC __thread_enter_user_mode , : /* Set user ie */ load_xregs a0, THREAD_CTX_REG_IE, REG_S0 csrw CSR_XIE, s0 - /* Set user status */ load_xregs a0, THREAD_CTX_REG_STATUS, REG_S0 csrw CSR_XSTATUS, s0 - + /* Set exception program counter */ + load_xregs a0, THREAD_CTX_REG_EPC, REG_S0 + csrw CSR_XEPC, s0 /* Load the rest of the general purpose registers */ load_xregs a0, THREAD_CTX_REG_RA, REG_RA, REG_TP load_xregs a0, THREAD_CTX_REG_T0, REG_T0, REG_T2 @@ -619,9 +620,6 @@ FUNC __thread_enter_user_mode , : load_xregs a0, THREAD_CTX_REG_T3, REG_T3, REG_T6 load_xregs a0, THREAD_CTX_REG_A0, REG_A0, REG_A7 - /* Set exception program counter */ - csrw CSR_XEPC, ra - /* Jump into user mode */ XRET END_FUNC __thread_enter_user_mode