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 {...@@ -300,6 +300,12 @@ fn _start() callconv(.Naked) noreturn {
300 \\ and sp, #-16300 \\ and sp, #-16
301 \\ b %[posixCallMainAndExit]301 \\ b %[posixCallMainAndExit]
302 ,302 ,
303 .loongarch64 =>
304 \\ move $fp, $zero
305 \\ move $a0, $sp
306 \\ bstrins.d $sp, $zero, 3, 0
307 \\ b %[posixCallMainAndExit]
308 ,
303 .riscv64 =>309 .riscv64 =>
304 \\ li s0, 0310 \\ li s0, 0
305 \\ li ra, 0311 \\ li ra, 0
...@@ -307,6 +313,14 @@ fn _start() callconv(.Naked) noreturn {...@@ -307,6 +313,14 @@ fn _start() callconv(.Naked) noreturn {
307 \\ andi sp, sp, -16313 \\ andi sp, sp, -16
308 \\ tail %[posixCallMainAndExit]@plt314 \\ tail %[posixCallMainAndExit]@plt
309 ,315 ,
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 ,
310 .mips, .mipsel =>324 .mips, .mipsel =>
311 // The lr is already zeroed on entry, as specified by the ABI.325 // The lr is already zeroed on entry, as specified by the ABI.
312 \\ addiu $fp, $zero, 0326 \\ addiu $fp, $zero, 0
...@@ -340,8 +354,8 @@ fn _start() callconv(.Naked) noreturn {...@@ -340,8 +354,8 @@ fn _start() callconv(.Naked) noreturn {
340 ,354 ,
341 .powerpc64, .powerpc64le =>355 .powerpc64, .powerpc64le =>
342 // Setup the initial stack frame and clear the back chain pointer.356 // Setup the initial stack frame and clear the back chain pointer.
343 \\ addis 2, 12, .TOC. - _start@ha357 \\ addis 2, 12, .TOC. - %[_start]@ha
344 \\ addi 2, 2, .TOC. - _start@l358 \\ addi 2, 2, .TOC. - %[_start]@l
345 \\ mr 3, 1359 \\ mr 3, 1
346 \\ clrrdi 1, 1, 4360 \\ clrrdi 1, 1, 4
347 \\ li 0, 0361 \\ li 0, 0
...@@ -349,6 +363,15 @@ fn _start() callconv(.Naked) noreturn {...@@ -349,6 +363,15 @@ fn _start() callconv(.Naked) noreturn {
349 \\ mtlr 0363 \\ mtlr 0
350 \\ b %[posixCallMainAndExit]364 \\ b %[posixCallMainAndExit]
351 ,365 ,
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 ,
352 .sparc64 =>375 .sparc64 =>
353 // argc is stored after a register window (16 registers) plus stack bias376 // argc is stored after a register window (16 registers) plus stack bias
354 \\ mov %%g0, %%i6377 \\ mov %%g0, %%i6
...@@ -359,7 +382,8 @@ fn _start() callconv(.Naked) noreturn {...@@ -359,7 +382,8 @@ fn _start() callconv(.Naked) noreturn {
359 else => @compileError("unsupported arch"),382 else => @compileError("unsupported arch"),
360 }383 }
361 :384 :
362 : [posixCallMainAndExit] "X" (&posixCallMainAndExit),385 : [_start] "X" (_start),
386 [posixCallMainAndExit] "X" (&posixCallMainAndExit),
363 );387 );
364}388}
365389