Skip to content

Commit 8a8a7ba

Browse files
authored
Merge pull request #20733 from alexrp/start-porting
`start`: Add startup code for loongarch64, m68k, and s390x
2 parents 05a8c47 + 8ffc41f commit 8a8a7ba

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

lib/std/start.zig

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,27 @@ 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
306312
\\ mv a0, sp
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,15 +354,24 @@ 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
348362
\\ stdu 0, -32(1)
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

0 commit comments

Comments
 (0)