From c1f32451679f3f73170f23b0846e12dacff1da60 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Thu, 30 May 2024 15:11:24 +0300 Subject: [PATCH] riscv-v/fork.S: Fix clobbering of s0 in fork() Value of s0 (callee-saved) must be preserved through the call, use a0 (caller-saved) to calculate the original SP instead. --- arch/risc-v/src/common/fork.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/risc-v/src/common/fork.S b/arch/risc-v/src/common/fork.S index 37d4bc9cfe..9070e93b21 100644 --- a/arch/risc-v/src/common/fork.S +++ b/arch/risc-v/src/common/fork.S @@ -117,8 +117,8 @@ up_fork: REGSTORE s0, FORK_S0_OFFSET(sp) #endif - addi s0, sp, FORK_SIZEOF - REGSTORE s0, FORK_SP_OFFSET(sp) /* original SP */ + addi a0, sp, FORK_SIZEOF + REGSTORE a0, FORK_SP_OFFSET(sp) /* original SP */ REGSTORE x1, FORK_RA_OFFSET(sp) /* return address */ /* Floating point registers */