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



##########
File path: arch/risc-v/src/common/riscv_swint.c
##########
@@ -116,6 +134,26 @@ static void dispatch_syscall(void)
      " ecall"                     /* Return from the syscall */
   );
 }
+#else
+static void dispatch_syscall(void)
+{
+  asm volatile
+    (
+     " addi sp, sp, -4\n"         /* Create a stack frame to hold ra */

Review comment:
       Should be relatively simple by:
   ```
   #define STR_INSTR(n)         #n
   #define INSTR(n)              STR_INSTR(n)
   
   #ifdef CONFIG_ARCH_RV32
   # define REGLOAD lw
   # define REGSTORE sw
   #else
   # define REGLOAD ld
   # define REGSTORE sd
   #endif
   ```
   and then
   ```
   static void dispatch_syscall(void)
   {
     asm volatile
       (
        " addi sp, sp, -4\n"               /* Create a stack frame to hold ra */
        " " INSTR(REGSTORE) " ra, 0(sp)\n" /* Save ra in the stack frame */
        " la   t0, g_stublookup\n"         /* t0=The base of the stub lookup 
table */
        " slli a0, a0, 3\n"                /* a0=Offset for the stub lookup 
table */
        " add  t0, t0, a0\n"               /* t0=The address in the table */
        " " INSTR(REGLOAD) " t0, 0(t0)\n"  /* t0=The address of the stub for 
this syscall */
        " jalr ra, t0\n"                   /* Call the stub (modifies ra) */
        " " INSTR(REGLOAD) " ra, 0(sp)\n"  /* Restore ra */
        " addi sp, sp, 4\n"                /* Destroy the stack frame */
        " mv   a2, a0\n"                   /* a2=Save return value in a0 */
        " li   a0, 3\n"                    /* a0=SYS_syscall_return (3) */
        " ecall"                           /* Return from the syscall */
     );
   }
   ```

##########
File path: arch/risc-v/src/common/riscv_swint.c
##########
@@ -116,6 +134,26 @@ static void dispatch_syscall(void)
      " ecall"                     /* Return from the syscall */
   );
 }
+#else
+static void dispatch_syscall(void)
+{
+  asm volatile
+    (
+     " addi sp, sp, -4\n"         /* Create a stack frame to hold ra */

Review comment:
       Should be relatively simple by:
   ```
   #define STR_INSTR(n)         #n
   #define INSTR(n)             STR_INSTR(n)
   
   #ifdef CONFIG_ARCH_RV32
   # define REGLOAD lw
   # define REGSTORE sw
   #else
   # define REGLOAD ld
   # define REGSTORE sd
   #endif
   ```
   and then
   ```
   static void dispatch_syscall(void)
   {
     asm volatile
       (
        " addi sp, sp, -4\n"               /* Create a stack frame to hold ra */
        " " INSTR(REGSTORE) " ra, 0(sp)\n" /* Save ra in the stack frame */
        " la   t0, g_stublookup\n"         /* t0=The base of the stub lookup 
table */
        " slli a0, a0, 3\n"                /* a0=Offset for the stub lookup 
table */
        " add  t0, t0, a0\n"               /* t0=The address in the table */
        " " INSTR(REGLOAD) " t0, 0(t0)\n"  /* t0=The address of the stub for 
this syscall */
        " jalr ra, t0\n"                   /* Call the stub (modifies ra) */
        " " INSTR(REGLOAD) " ra, 0(sp)\n"  /* Restore ra */
        " addi sp, sp, 4\n"                /* Destroy the stack frame */
        " mv   a2, a0\n"                   /* a2=Save return value in a0 */
        " li   a0, 3\n"                    /* a0=SYS_syscall_return (3) */
        " ecall"                           /* Return from the syscall */
     );
   }
   ```




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