riscv/fork: fix gp register handling

This fixes the handling of gp register in fork.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu 2024-08-08 06:25:58 +08:00 committed by Xiang Xiao
parent 3f021d5429
commit 77cfbf8914
2 changed files with 5 additions and 1 deletions

View File

@ -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 */

View File

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