From de3c5ad75a52a084f5457a13a60e8aa6fbb5a6a5 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 2 Apr 2024 11:18:52 +0000 Subject: [PATCH] platform: riscv64: fix building with -fno-omit-frame-pointer Register s0 is the frame-pointer register and must be handled separately. Signed-off-by: Heinrich Schuchardt --- src/greenlet/platform/switch_riscv_unix.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/greenlet/platform/switch_riscv_unix.h b/src/greenlet/platform/switch_riscv_unix.h index 24df9dbb..e74f37af 100644 --- a/src/greenlet/platform/switch_riscv_unix.h +++ b/src/greenlet/platform/switch_riscv_unix.h @@ -3,7 +3,7 @@ #ifdef SLP_EVAL #define STACK_MAGIC 0 -#define REGS_TO_SAVE "s0", "s1", "s2", "s3", "s4", "s5", \ +#define REGS_TO_SAVE "s1", "s2", "s3", "s4", "s5", \ "s6", "s7", "s8", "s9", "s10", "s11", "fs0", "fs1", \ "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", \ "fs10", "fs11" @@ -11,20 +11,24 @@ static int slp_switch(void) { + long fp; int ret; long *stackref, stsizediff; __asm__ volatile ("" : : : REGS_TO_SAVE); + __asm__ volatile ("mv %0, fp" : "=r" (fp) : ); __asm__ volatile ("mv %0, sp" : "=r" (stackref) : ); { SLP_SAVE_STATE(stackref, stsizediff); __asm__ volatile ( "add sp, sp, %0\n\t" + "add fp, fp, %0\n\t" : /* no outputs */ : "r" (stsizediff) ); SLP_RESTORE_STATE(); } __asm__ volatile ("" : : : REGS_TO_SAVE); + __asm__ volatile ("ld fp, %0" : : "m" (fp)); __asm__ volatile ("mv %0, zero" : "=r" (ret) : ); return ret; }