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/nuttx.git

commit 77cfbf8914935c2b81329840c001fc1036fd9bf8
Author: Yanfeng Liu <[email protected]>
AuthorDate: Thu Aug 8 06:25:58 2024 +0800

    riscv/fork: fix gp register handling
    
    This fixes the handling of gp register in fork.
    
    Signed-off-by: Yanfeng Liu <[email protected]>
---
 arch/risc-v/src/common/fork.S       | 4 ++++
 arch/risc-v/src/common/riscv_fork.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/risc-v/src/common/fork.S b/arch/risc-v/src/common/fork.S
index 9134266fec..a7ca257f05 100644
--- a/arch/risc-v/src/common/fork.S
+++ b/arch/risc-v/src/common/fork.S
@@ -123,6 +123,10 @@ up_fork:
   REGSTORE    s0, FORK_S0_OFFSET(sp)
 #endif
 
+#ifdef RISCV_SAVE_GP
+  REGSTORE    gp, FORK_GP_OFFSET(sp)
+#endif
+
   addi        a0, sp, FORK_SIZEOF
   REGSTORE    a0, FORK_SP_OFFSET(sp) /* original SP */
   REGSTORE    x1, FORK_RA_OFFSET(sp) /* return address */
diff --git a/arch/risc-v/src/common/riscv_fork.c 
b/arch/risc-v/src/common/riscv_fork.c
index 9187cc6ab5..40e463b2ae 100644
--- a/arch/risc-v/src/common/riscv_fork.c
+++ b/arch/risc-v/src/common/riscv_fork.c
@@ -308,7 +308,7 @@ pid_t riscv_fork(const struct fork_s *context)
 #endif
   child->cmn.xcp.regs[REG_SP]   = newsp;        /* Stack pointer */
 #ifdef RISCV_SAVE_GP
-  child->cmn.xcp.regs[REG_GP]   = newsp;        /* Global pointer */
+  child->cmn.xcp.regs[REG_GP]   = context->gp;  /* Global pointer */
 #endif
 #ifdef CONFIG_ARCH_FPU
   fregs                         = riscv_fpuregs(&child->cmn);

Reply via email to