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