[PATCH] tools/nolibc: MIPS: fix clobbers of 'lo' and 'hi' registers on different ISAs

From: Thomas Weißschuh

Date: Wed Feb 18 2026 - 06:46:08 EST


Earlier MIPS64 ISAs still provide the 'lo' and 'hi' special registers.
These are clobbered by system calls and need to be marked as such to
avoid miscompilations.
Also 32-bit ISAs from r6 on do not define the 'lo' and 'hi' registers.

Handle all different combinations of ABI and ISAs.

Fixes: a6a2a8a42972 ("tools/nolibc: MIPS: add support for N64 and N32 ABIs")
Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
---
tools/include/nolibc/arch-mips.h | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h
index a72506ceec6b..210bd907b51f 100644
--- a/tools/include/nolibc/arch-mips.h
+++ b/tools/include/nolibc/arch-mips.h
@@ -41,23 +41,44 @@

#if defined(_ABIO32)

-#define _NOLIBC_SYSCALL_CLOBBERLIST \
- "memory", "cc", "at", "v1", "hi", "lo", \
- "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9"
#define _NOLIBC_SYSCALL_STACK_RESERVE "addiu $sp, $sp, -32\n"
#define _NOLIBC_SYSCALL_STACK_UNRESERVE "addiu $sp, $sp, 32\n"

#else /* _ABIN32 || _ABI64 */

+#define _NOLIBC_SYSCALL_STACK_RESERVE
+#define _NOLIBC_SYSCALL_STACK_UNRESERVE
+
+#endif /* _ABIO32 */
+
+
+#if defined(_ABIO32) && __mips_isa_rev >= 6
+
+#define _NOLIBC_SYSCALL_CLOBBERLIST \
+ "memory", "cc", "at", "v1", \
+ "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9"
+
+#elif defined(_ABIO32) && __mips_isa_rev < 6
+
+#define _NOLIBC_SYSCALL_CLOBBERLIST \
+ "memory", "cc", "at", "v1", "hi", "lo", \
+ "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9"
+
+#elif __mips_isa_rev >= 6 /* _ABIN32 || _ABI64 */
+
/* binutils, GCC and clang disagree about register aliases, use numbers instead. */
#define _NOLIBC_SYSCALL_CLOBBERLIST \
"memory", "cc", "at", "v1", \
"10", "11", "12", "13", "14", "15", "24", "25"

-#define _NOLIBC_SYSCALL_STACK_RESERVE
-#define _NOLIBC_SYSCALL_STACK_UNRESERVE
+#else /* __mips_is_rev < 6 && (_ABIN32 || _ABI64) */
+
+#define _NOLIBC_SYSCALL_CLOBBERLIST \
+ "memory", "cc", "at", "v1", "hi", "lo", \
+ "10", "11", "12", "13", "14", "15", "24", "25"
+
+#endif /* __mips_isa_rev and ABI */

-#endif /* _ABIO32 */

#define my_syscall0(num) \
({ \

---
base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
change-id: 20260218-nolibc-mips-clobber-499e9fbdb5bf

Best regards,
--
Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>