On Wed, 12 Feb 2025, Thomas Weißschuh wrote:
diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 753a8ed2cf695f0b5eac4b5e4d317fdb383ebf93..638520a3427a985fdbd5f5a49b55853bbadeee75 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -190,13 +257,33 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __ "1:\n" ".cpload $ra\n" "move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
+#if defined(_ABIO32) "addiu $sp, $sp, -4\n" /* space for .cprestore to store $gp */ ".cprestore 0\n" "li $t0, -8\n" "and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */ "addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */
"lui $t9, %hi(_start_c)\n" /* ABI requires current function address in $t9 */
+#else
"daddiu $sp, $sp, -8\n" /* space for .cprestore to store $gp */
".cpsetup $ra, 0, 1b\n"
"li $t0, -16\n"
"and $sp, $sp, $t0\n" /* $sp must be 16-byte aligned */
+#endif
Why is this code breaking stack alignment just to have to fix it up two instructions down the line? Or is it that the incoming $sp is not aligned in the first place (in which case we're having a deeper problem).
/* ABI requires current function address in $t9 */
+#if defined(_ABIO32) || defined(_ABIN32)
"ori $t9, %lo(_start_c)\n""lui $t9, %hi(_start_c)\n"
+#else
"lui $t9, %highest(_start_c)\n"
"ori $t9, %higher(_start_c)\n"
"dsll $t9, 0x10\n"
"ori $t9, %hi(_start_c)\n"
"dsll $t9, 0x10\n"
"ori $t9, %lo(_start_c)\n"
This could be optimised using a temporary (e.g. $at, but I guess any will do as I gather we don't have any ABI abnormalities here).
+#endif
- "jalr $t9\n" /* transfer to c runtime
*/ " nop\n" /* delayed slot
On an unrelated matter JALR above ought to be JAL (or otherwise there's no point in using the .cprestore pseudo-op). And I fail to see why this code has to be "noreorder" (except for the .cpload piece, of course), it's just asking for troubles.
Maciej