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



##########
File path: arch/risc-v/src/common/riscv_internal.h
##########
@@ -283,6 +292,63 @@ int riscv_pause_handler(int irq, void *c, void *arg);
 
 uintptr_t riscv_mhartid(void);
 
+#ifdef CONFIG_ARCH_USE_S_MODE
+/* If kernel runs in Supervisor mode, declare proper function prototypes,
+ * this is because it is not possible to ecall from S mode to S mode
+ */
+
+int riscv_saveusercontext(uintptr_t *saveregs);
+void riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function;
+void riscv_switchcontext(uintptr_t *saveregs, uintptr_t *restoreregs);
+void riscv_syscall_return(void);
+void riscv_syscall_dispatch(void) noreturn_function;
+
+#else
+
+#ifndef __ASSEMBLY__
+
+/* Context switching via system calls ***************************************/
+
+/* SYS call 0:
+ *
+ * int riscv_saveusercontext(uintptr_t *saveregs);
+ *
+ * Return:
+ * 0: Normal Return
+ * 1: Context Switch Return
+ */
+
+#define riscv_saveusercontext(saveregs) \
+  sys_call1(SYS_save_context, (uintptr_t)saveregs)

Review comment:
       > Then it is doable yes. One final concern of mine is if the syscall.h 
header is published to the apps-folder in make export / make import, the flags 
usage will be exposed there. I will check if this happens.
   
   Yes, arch/syscall.h is in the exported / imported package, but it is already 
contaminated with e.g. the ARCH_USE_S_MODE flag, and the reserved syscall 
numbers (which the import package does not need):
   
   #ifndef CONFIG_ARCH_USE_S_MODE
   /* SYS call 1 and 2 are defined for internal use by the RISC-V port (see
    * arch/risc-v/include/syscall.h). In addition, SYS call 3 is the
    * return from a SYS call in kernel mode. The first four syscall values must,
    * therefore, be reserved (0 is not used).
    */
   
   #define SYS_save_context          (0)
   ...
   
   I will remove ksys_callx and merge the implementations by flagging with 
__KERNEL__ etc. Now I finally understand how the same symbol can be referenced 
from two places who require a different implementation.
   
   Still, at some point, IMHO the user declarations of arch/syscall.h should be 
moved under libc/machine. The user does not need to know of the reserved 
values. The only thing it needs is the declarations / definitions of the 
sys_call functions.




-- 
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