[libunwind] [libunwind][Mips] Fix the o32 register save/restore code for MIPS I (PR #246542)
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 17:50:48 PST 2026
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/246542
MIPS I has no ldc1/sdc1, so UnwindRegistersSave.S and
UnwindRegistersRestore.S do not assemble for hard-float o32 on MIPS I.
Use the swc1/lwc1 path that single-float already uses. The context
layout stays the same.
jumpto() also loads $8 and moves it to HI right away with mthi, then
does the same for LO. The code is in .set noreorder, so on MIPS I mthi
and mtlo read $8 in the load delay slot and get the old value. Load HI
into $8 and LO into $9 first, then do the mthi and mtlo. Both registers
are restored from the context afterwards.
>From 4febc8522d433e6cc622dc36025e5db070fff2b0 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Thu, 26 Nov 2026 20:45:17 -0500
Subject: [PATCH] [libunwind][Mips] Fix the o32 register save/restore code for
MIPS I
MIPS I has no ldc1/sdc1, so UnwindRegistersSave.S and
UnwindRegistersRestore.S do not assemble for hard-float o32 on MIPS I.
Use the swc1/lwc1 path that single-float already uses. The context
layout stays the same.
jumpto() also loads $8 and moves it to HI right away with mthi, then
does the same for LO. The code is in .set noreorder, so on MIPS I mthi
and mtlo read $8 in the load delay slot and get the old value. Load HI
into $8 and LO into $9 first, then do the mthi and mtlo. Both registers
are restored from the context afterwards.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
---
libunwind/src/UnwindRegistersRestore.S | 7 ++++---
libunwind/src/UnwindRegistersSave.S | 8 ++++----
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S
index b1b075ba556f91..37feaf69199c62 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -1018,7 +1018,7 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
.set noreorder
.set nomacro
#ifdef __mips_hard_float
-#if defined(__mips_single_float)
+#if defined(__mips_single_float) || __mips == 1
// See the matching comment in UnwindRegistersSave.S.
lwc1 $f0, (4 * 36 + 8 * 0)($4)
lwc1 $f1, (4 * 36 + 8 * 1)($4)
@@ -1106,10 +1106,11 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
#endif
#if __mips_isa_rev < 6
// restore hi and lo
+ // MIPS 1 has load delay slot. Load both values before using them.
lw $8, (4 * 33)($4)
+ lw $9, (4 * 34)($4)
mthi $8
- lw $8, (4 * 34)($4)
- mtlo $8
+ mtlo $9
#endif
// r0 is zero
lw $1, (4 * 1)($4)
diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S
index 1dbc1f697bc14a..c26fd101f217fa 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -277,10 +277,10 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
sw $8, (4 * 34)($4)
#endif
#ifdef __mips_hard_float
-#if defined(__mips_single_float)
- // A single-precision-only FPU has no sdc1. Each register still occupies
- // an 8-byte slot so that the context layout matches the other o32 FPU
- // configurations; only the low half of each slot is used.
+#if defined(__mips_single_float) || __mips == 1
+ // A single-precision-only FPU and MIPS I have no sdc1. Each register still
+ // occupies an 8-byte slot so that the context layout matches the other o32
+ // FPU configurations; only the low half of each slot is used.
swc1 $f0, (4 * 36 + 8 * 0)($4)
swc1 $f1, (4 * 36 + 8 * 1)($4)
swc1 $f2, (4 * 36 + 8 * 2)($4)
More information about the cfe-commits
mailing list