Skip to content

Commit 7a0da80

Browse files
authored
Merge pull request #20797 from alexrp/start-more-arches
`start`: Add POSIX arc, csky, and hexagon support
2 parents 8f7cbaa + 108c682 commit 7a0da80

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/std/start.zig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,49 @@ fn _start() callconv(.Naked) noreturn {
259259
\\ and sp, x0, #-16
260260
\\ b %[posixCallMainAndExit]
261261
,
262+
.arc =>
263+
// The `arc` tag currently means ARCv2, which has an unusually low stack alignment
264+
// requirement. ARCv3 increases it from 4 to 16, but we don't support ARCv3 yet.
265+
\\ mov fp, 0
266+
\\ mov blink, 0
267+
\\ mov r0, sp
268+
\\ and sp, sp, -4
269+
\\ b %[posixCallMainAndExit]
270+
,
262271
.arm, .armeb, .thumb, .thumbeb =>
263272
\\ mov fp, #0
264273
\\ mov lr, #0
265274
\\ mov a1, sp
266275
\\ and sp, #-16
267276
\\ b %[posixCallMainAndExit]
268277
,
278+
// zig fmt: off
279+
.csky =>
280+
if (builtin.position_independent_code)
281+
// The CSKY ABI assumes that `gb` is set to the address of the GOT in order for
282+
// position-independent code to work. We depend on this in `std.os.linux.start_pie`
283+
// to locate `_DYNAMIC` as well.
284+
\\ grs t0, 1f
285+
\\ 1:
286+
\\ lrw gb, 1b@GOTPC
287+
\\ addu gb, t0
288+
else ""
289+
++
290+
\\ movi lr, 0
291+
\\ mov a0, sp
292+
\\ andi sp, sp, -8
293+
\\ jmpi %[posixCallMainAndExit]
294+
,
295+
// zig fmt: on
296+
.hexagon =>
297+
// r29 = SP, r30 = FP
298+
\\ r30 = #0
299+
\\ r0 = r29
300+
\\ r29 = and(r29, #-16)
301+
\\ memw(r29 + #-8) = r29
302+
\\ r29 = add(r29, #-8)
303+
\\ call %[posixCallMainAndExit]
304+
,
269305
.loongarch32, .loongarch64 =>
270306
\\ move $fp, $zero
271307
\\ move $a0, $sp

0 commit comments

Comments
 (0)