authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-22 18:25:24-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-22 18:25:24-07:00
log8a8a7ba35bd1d580f60a44e1a2803457595df30e
treef78967075d7c438656f1cda7596dc1ab1e566df5
parent05a8c4796f633bfebad7ec403560ce442cae11ba
parent8ffc41f74705246e61f3c02c253d40b1464ea2bf
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20733 from alexrp/start-porting

`start`: Add startup code for loongarch64, m68k, and s390x

1 files changed, 27 insertions(+), 3 deletions(-)

lib/std/start.zig+27-3
......@@ -300,6 +300,12 @@ fn _start() callconv(.Naked) noreturn {
300300 \\ and sp, #-16
301301 \\ b %[posixCallMainAndExit]
302302 ,
303 .loongarch64 =>
304 \\ move $fp, $zero
305 \\ move $a0, $sp
306 \\ bstrins.d $sp, $zero, 3, 0
307 \\ b %[posixCallMainAndExit]
308 ,
303309 .riscv64 =>
304310 \\ li s0, 0
305311 \\ li ra, 0
......@@ -307,6 +313,14 @@ fn _start() callconv(.Naked) noreturn {
307313 \\ andi sp, sp, -16
308314 \\ tail %[posixCallMainAndExit]@plt
309315 ,
316 .m68k =>
317 // Note that the - 8 is needed because pc in the jsr instruction points into the middle
318 // of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.)
319 \\ suba.l %%fp, %%fp
320 \\ move.l %%sp, -(%%sp)
321 \\ lea %[posixCallMainAndExit] - . - 8, %%a0
322 \\ jsr (%%pc, %%a0)
323 ,
310324 .mips, .mipsel =>
311325 // The lr is already zeroed on entry, as specified by the ABI.
312326 \\ addiu $fp, $zero, 0
......@@ -340,8 +354,8 @@ fn _start() callconv(.Naked) noreturn {
340354 ,
341355 .powerpc64, .powerpc64le =>
342356 // Setup the initial stack frame and clear the back chain pointer.
343 \\ addis 2, 12, .TOC. - _start@ha
344 \\ addi 2, 2, .TOC. - _start@l
357 \\ addis 2, 12, .TOC. - %[_start]@ha
358 \\ addi 2, 2, .TOC. - %[_start]@l
345359 \\ mr 3, 1
346360 \\ clrrdi 1, 1, 4
347361 \\ li 0, 0
......@@ -349,6 +363,15 @@ fn _start() callconv(.Naked) noreturn {
349363 \\ mtlr 0
350364 \\ b %[posixCallMainAndExit]
351365 ,
366 .s390x =>
367 // Set up the stack frame (register save area and cleared back-chain slot).
368 // Note: Stack pointer is guaranteed by ABI to be 8-byte aligned as required.
369 \\ lgr %r2, %r15
370 \\ aghi %r15, -160
371 \\ lghi %r0, 0
372 \\ stg %r0, 0(%r15)
373 \\ jg %[posixCallMainAndExit]
374 ,
352375 .sparc64 =>
353376 // argc is stored after a register window (16 registers) plus stack bias
354377 \\ mov %%g0, %%i6
......@@ -359,7 +382,8 @@ fn _start() callconv(.Naked) noreturn {
359382 else => @compileError("unsupported arch"),
360383 }
361384 :
362 : [posixCallMainAndExit] "X" (&posixCallMainAndExit),
385 : [_start] "X" (_start),
386 [posixCallMainAndExit] "X" (&posixCallMainAndExit),
363387 );
364388}
365389