pkarashchenko commented on a change in pull request #5782:
URL: https://github.com/apache/incubator-nuttx/pull/5782#discussion_r838475386



##########
File path: arch/risc-v/src/common/riscv_exception_common.S
##########
@@ -137,63 +102,27 @@ exception_common:
   addi       sp, sp, XCPTCONTEXT_SIZE
 #endif
 
-
-  /* If context switch is needed, return a new sp     */
+  /* If context switch is needed, return a new sp */
 
   mv         sp, a0
-  REGLOAD    s0, REG_EPC(sp)     /* restore mepc      */
-  csrw       mepc, s0
 
-  REGLOAD    s0, REG_INT_CTX(sp) /* restore mstatus   */
-  csrw       mstatus, s0
+  REGLOAD    s0, REG_EPC(sp)      /* restore sepc */
+  csrw       CSR_EPC, s0
 
-#ifdef RISCV_SAVE_GP
-  REGLOAD    x3,  REG_X3(sp)   /* gp */
-#endif
-  REGLOAD    x4,  REG_X4(sp)   /* tp */
-  REGLOAD    x5,  REG_X5(sp)   /* t0 */
-  REGLOAD    x6,  REG_X6(sp)   /* t1 */
-  REGLOAD    x7,  REG_X7(sp)   /* t2 */
-  REGLOAD    x8,  REG_X8(sp)   /* s0 */
-  REGLOAD    x9,  REG_X9(sp)   /* s1 */
-  REGLOAD    x10, REG_X10(sp)  /* a0 */
-  REGLOAD    x11, REG_X11(sp)  /* a1 */
-  REGLOAD    x12, REG_X12(sp)  /* a2 */
-  REGLOAD    x13, REG_X13(sp)  /* a3 */
-  REGLOAD    x14, REG_X14(sp)  /* a4 */
-  REGLOAD    x15, REG_X15(sp)  /* a5 */
-  REGLOAD    x16, REG_X16(sp)  /* a6 */
-  REGLOAD    x17, REG_X17(sp)  /* a7 */
-  REGLOAD    x18, REG_X18(sp)  /* s2 */
-  REGLOAD    x19, REG_X19(sp)  /* s3 */
-  REGLOAD    x20, REG_X20(sp)  /* s4 */
-  REGLOAD    x21, REG_X21(sp)  /* s5 */
-  REGLOAD    x22, REG_X22(sp)  /* s6 */
-  REGLOAD    x23, REG_X23(sp)  /* s7 */
-  REGLOAD    x24, REG_X24(sp)  /* s8 */
-  REGLOAD    x25, REG_X25(sp)  /* s9 */
-  REGLOAD    x26, REG_X26(sp)  /* s10 */
-  REGLOAD    x27, REG_X27(sp)  /* s11 */
-  REGLOAD    x28, REG_X28(sp)  /* t3 */
-  REGLOAD    x29, REG_X29(sp)  /* t4 */
-  REGLOAD    x30, REG_X30(sp)  /* t5 */
-  REGLOAD    x31, REG_X31(sp)  /* t6 */
-
-  REGLOAD    x1,  REG_X1(sp)   /* ra */
-
-  REGLOAD    sp,  REG_X2(sp)   /* restore original sp */
-
-  /* Return from Machine Interrupt */
-
-  mret
-
-/************************************************************************************
- *  Name: g_intstackalloc and g_intstacktop
- 
************************************************************************************/
+  REGLOAD    s0, REG_INT_CTX(sp)  /* restore sstatus */
+  csrw       CSR_STATUS, s0
 
-/************************************************************************************
+  load_ctx   sp
+
+  REGLOAD    sp, REG_SP(sp)       /* restore original sp */
+
+  /* Return from exception */
+
+  eret

Review comment:
       Sorry, maybe my question is invalid because I'm very limited familiar 
with RISC-V, but shouldn't we use `mret` to return from `M-mode` and `sret` 
(`eret`) to return from `S-mode`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to