This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b7f9867aa arch/risc-v: use STACK_FRAME_SIZE for in S-mode syscall asm
9b7f9867aa is described below

commit 9b7f9867aad7ff2d04b97516ab86b68d733447b6
Author: Petro Karashchenko <[email protected]>
AuthorDate: Sun Apr 3 23:11:38 2022 +0200

    arch/risc-v: use STACK_FRAME_SIZE for in S-mode syscall asm
    
    Signed-off-by: Petro Karashchenko <[email protected]>
---
 arch/risc-v/include/arch.h              |  5 +++++
 arch/risc-v/include/syscall.h           | 10 +++++-----
 arch/risc-v/src/common/riscv_internal.h |  7 ++-----
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/risc-v/include/arch.h b/arch/risc-v/include/arch.h
index b68fe154e7..ed9745605b 100644
--- a/arch/risc-v/include/arch.h
+++ b/arch/risc-v/include/arch.h
@@ -65,6 +65,11 @@
 #  define REGSTORE  __STR(sd)
 #endif
 
+/* RISC-V requires a 16-byte stack alignment. */
+
+#define STACK_ALIGNMENT     16
+#define STACK_FRAME_SIZE    __XSTR(STACK_ALIGNMENT)
+
 /****************************************************************************
  * Inline functions
  ****************************************************************************/
diff --git a/arch/risc-v/include/syscall.h b/arch/risc-v/include/syscall.h
index bf16ffeb0b..d232425662 100644
--- a/arch/risc-v/include/syscall.h
+++ b/arch/risc-v/include/syscall.h
@@ -126,11 +126,11 @@
 
 #if defined (CONFIG_ARCH_USE_S_MODE) && defined (__KERNEL__)
 #  define ASM_SYS_CALL \
-     " addi sp, sp, -16\n"                  /* Make room */ \
-     REGSTORE " ra, 0(sp)\n"                /* Save ra */ \
-     " jal  ra, riscv_dispatch_syscall\n"   /* Dispatch (modifies ra) */ \
-     REGLOAD " ra, 0(sp)\n"                 /* Restore ra */ \
-     " addi sp, sp, 16\n"                   /* Restore sp */
+     " addi sp, sp, -" STACK_FRAME_SIZE "\n" /* Make room */ \
+     REGSTORE " ra, 0(sp)\n"                 /* Save ra */ \
+     " jal  ra, riscv_dispatch_syscall\n"    /* Dispatch (modifies ra) */ \
+     REGLOAD " ra, 0(sp)\n"                  /* Restore ra */ \
+     " addi sp, sp, " STACK_FRAME_SIZE "\n"  /* Restore sp */
 #else
 #  define ASM_SYS_CALL \
      "ecall"
diff --git a/arch/risc-v/src/common/riscv_internal.h 
b/arch/risc-v/src/common/riscv_internal.h
index a19f1f8ae9..1a2c8693e2 100644
--- a/arch/risc-v/src/common/riscv_internal.h
+++ b/arch/risc-v/src/common/riscv_internal.h
@@ -33,6 +33,8 @@
 #  include <sys/types.h>
 #  include <stdint.h>
 #  include <syscall.h>
+#else
+#  include <arch/arch.h>
 #endif
 
 /****************************************************************************
@@ -47,11 +49,6 @@
 #define INTSTACK_COLOR 0xdeadbeef
 #define HEAP_COLOR     'h'
 
-/* RISC-V requires a 16-byte stack alignment. */
-
-#define STACK_ALIGNMENT     16
-#define STACK_FRAME_SIZE    __XSTR(STACK_ALIGNMENT)
-
 /* Stack alignment macros */
 
 #define STACK_ALIGN_MASK    (STACK_ALIGNMENT - 1)

Reply via email to