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



##########
File path: arch/risc-v/src/common/riscv_swint.c
##########
@@ -179,6 +187,31 @@ int riscv_swint(int irq, void *context, void *arg)
   riscv_registerdump(regs);
 #endif
 
+  /* Handle the syscall */
+
+  regs = riscv_handle_syscall(regs);
+
+  /* Report what happened.  That might difficult in the case of a context
+   * switch
+   */
+
+#ifdef CONFIG_DEBUG_SYSCALL_INFO
+  if (regs != CURRENT_REGS)
+    {
+      svcinfo("SWInt Return: Context switch!\n");
+      riscv_registerdump((const uintptr_t *)CURRENT_REGS);
+    }
+  else
+    {
+      svcinfo("SWInt Return: %d\n", regs[REG_A0]);
+    }
+#endif
+
+  return OK;
+}
+
+void *riscv_handle_syscall(uintptr_t *regs)

Review comment:
       > There were two points:
   > 
   > 1. int riscv_swint(int irq, void *context, void *arg), irq is not active 
as the call comes from thread, arg is not used / set, but then again irq is not 
used either so it does not matter...
   
   We can pass the fix value here.
   
   > 2. The handling of CURRENT_REGS, e.g. DEBUGASSERT(regs && regs == 
CURRENT_REGS); The function has 1 global variable so it is not really re-entrant
   > 
   > riscv_syscall_dispatch is re-entrant, always
   
   
   it isn't a problem since you need disable interrupt anyway to simulate ECALL.
   
   > 
   > If you think that removing the test for regs == CURRENT_REGS is fine, then 
the function can be combined. To me splitting the logical part (the switch 
case) out of the already massive function made sense.
   
   I think it's better to call up_doirq just like execption_common once 
riscv_syscall_dispatch finish to prepare the environment.
   From the concept, RISCV kernel mode different from ARM is just because 
S-mode can't generate the exception to self. So, the  change really needed is 
simulate ECALL inside ssy_callx, other part should be shared with M-mode and 
S-mode as much as possible.




-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to