authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-25 01:08:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-29 10:04:54+02:00
log77fc3b88fbdf805e0c2c1fc2647513cee56813a4
treee67dfe81ffcc14fb6a625961839e2e1d094fa16d
parent66b71273a2555da23f6d706c22e3d85f43fe602b
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

start: Set up the gp register on mips and mips64.


1 files changed, 13 insertions(+), 0 deletions(-)

lib/std/start.zig+13
...@@ -329,6 +329,11 @@ fn _start() callconv(.Naked) noreturn {...@@ -329,6 +329,11 @@ fn _start() callconv(.Naked) noreturn {
329 \\ jsr (%%pc, %%a0)329 \\ jsr (%%pc, %%a0)
330 ,330 ,
331 .mips, .mipsel =>331 .mips, .mipsel =>
332 \\ bal 1f
333 \\ .gpword .
334 \\ 1:
335 \\ lw $gp, 0($ra)
336 \\ subu $gp, $ra, $gp
332 \\ move $fp, $0337 \\ move $fp, $0
333 \\ move $ra, $0338 \\ move $ra, $0
334 \\ move $a0, $sp339 \\ move $a0, $sp
...@@ -336,6 +341,14 @@ fn _start() callconv(.Naked) noreturn {...@@ -336,6 +341,14 @@ fn _start() callconv(.Naked) noreturn {
336 \\ j %[posixCallMainAndExit]341 \\ j %[posixCallMainAndExit]
337 ,342 ,
338 .mips64, .mips64el =>343 .mips64, .mips64el =>
344 \\ bal 1f
345 \\ .gpdword .
346 \\ 1:
347 // The `gp` register on MIPS serves a similar purpose to `r2` (ToC pointer) on PPC64.
348 // We need to set it up in order for dynamically-linked / position-independent code to
349 // work.
350 \\ ld $gp, 0($ra)
351 \\ dsubu $gp, $ra, $gp
339 \\ move $fp, $0352 \\ move $fp, $0
340 \\ move $ra, $0353 \\ move $ra, $0
341 \\ move $a0, $sp354 \\ move $a0, $sp