diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2024-07-25 01:08:03 +0200 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2024-07-29 10:04:54 +0200 |
| commit | 77fc3b88fbdf805e0c2c1fc2647513cee56813a4 (patch) | |
| tree | e67dfe81ffcc14fb6a625961839e2e1d094fa16d /lib/std/start.zig | |
| parent | 66b71273a2555da23f6d706c22e3d85f43fe602b (diff) | |
| download | zig-77fc3b88fbdf805e0c2c1fc2647513cee56813a4.tar.gz zig-77fc3b88fbdf805e0c2c1fc2647513cee56813a4.zip | |
start: Set up the gp register on mips and mips64.
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index 326857d9c0..78845904d6 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -329,6 +329,11 @@ fn _start() callconv(.Naked) noreturn { \\ jsr (%%pc, %%a0) , .mips, .mipsel => + \\ bal 1f + \\ .gpword . + \\ 1: + \\ lw $gp, 0($ra) + \\ subu $gp, $ra, $gp \\ move $fp, $0 \\ move $ra, $0 \\ move $a0, $sp @@ -336,6 +341,14 @@ fn _start() callconv(.Naked) noreturn { \\ j %[posixCallMainAndExit] , .mips64, .mips64el => + \\ bal 1f + \\ .gpdword . + \\ 1: + // The `gp` register on MIPS serves a similar purpose to `r2` (ToC pointer) on PPC64. + // We need to set it up in order for dynamically-linked / position-independent code to + // work. + \\ ld $gp, 0($ra) + \\ dsubu $gp, $ra, $gp \\ move $fp, $0 \\ move $ra, $0 \\ move $a0, $sp |
