authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 01:55:14+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 16:56:23+02:00
logef4ce7def1d4868d1d54832fba473f84938e40be
tree5f1dc8cd8b212fae19da6ba830354a721e03207a
parent2a155d75ac575c9a99918569249aecdf251e94d9
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std: fix zeroing of lr in powerpc _start and clone assembly

PowerPC assembly is wonderful because you can't tell at a glance whether an operand is an immediate integer or a register number. In this case, mtlr takes a register number, but we haven't zeroed r0, and it's not a hardwired zero register as on other architectures. Fix this by copying from r31 which we've just zeroed.

3 files changed, 4 insertions(+), 4 deletions(-)

lib/std/os/linux/powerpc.zig+1-1
...@@ -247,7 +247,7 @@ pub fn clone() callconv(.naked) u32 {...@@ -247,7 +247,7 @@ pub fn clone() callconv(.naked) u32 {
247 );247 );
248 asm volatile (248 asm volatile (
249 \\ li 31, 0249 \\ li 31, 0
250 \\ mtlr 0250 \\ mtlr 31
251 \\251 \\
252 \\ #call funcptr: move arg (d) into r3252 \\ #call funcptr: move arg (d) into r3
253 \\ mr 3, 30253 \\ mr 3, 30
lib/std/os/linux/powerpc64.zig+1-1
...@@ -232,7 +232,7 @@ pub fn clone() callconv(.naked) u64 {...@@ -232,7 +232,7 @@ pub fn clone() callconv(.naked) u64 {
232 );232 );
233 asm volatile (233 asm volatile (
234 \\ li 31, 0234 \\ li 31, 0
235 \\ mtlr 0235 \\ mtlr 31
236 \\236 \\
237 \\ # call fn(arg)237 \\ # call fn(arg)
238 \\ ld 3, 16(1)238 \\ ld 3, 16(1)
lib/std/start.zig+2-2
...@@ -438,7 +438,7 @@ fn _start() callconv(.naked) noreturn {...@@ -438,7 +438,7 @@ fn _start() callconv(.naked) noreturn {
438 \\ stwu 1, -16(1)438 \\ stwu 1, -16(1)
439 \\ stw 0, 0(1)439 \\ stw 0, 0(1)
440 \\ li 31, 0440 \\ li 31, 0
441 \\ mtlr 0441 \\ mtlr 31
442 \\ b %[posixCallMainAndExit]442 \\ b %[posixCallMainAndExit]
443 ,443 ,
444 .powerpc64, .powerpc64le =>444 .powerpc64, .powerpc64le =>
...@@ -451,7 +451,7 @@ fn _start() callconv(.naked) noreturn {...@@ -451,7 +451,7 @@ fn _start() callconv(.naked) noreturn {
451 \\ li 0, 0451 \\ li 0, 0
452 \\ stdu 0, -32(1)452 \\ stdu 0, -32(1)
453 \\ li 31, 0453 \\ li 31, 0
454 \\ mtlr 0454 \\ mtlr 31
455 \\ b %[posixCallMainAndExit]455 \\ b %[posixCallMainAndExit]
456 \\ nop456 \\ nop
457 ,457 ,