@@ -224,14 +224,27 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv
224
224
}
225
225
226
226
fn _start () callconv (.Naked ) noreturn {
227
+ // It's important that all checks here are comptime since having any kind of non-asm code in a
228
+ // naked function is asking for trouble with some LLVM backends.
229
+
227
230
// TODO set Top of Stack on non x86_64-plan9
228
- if (native_os == .plan9 and native_arch == .x86_64 ) {
231
+ if (comptime native_os == .plan9 and native_arch == .x86_64 ) {
229
232
// from /sys/src/libc/amd64/main9.s
230
233
std .os .plan9 .tos = asm volatile (""
231
234
: [tos ] "={rax}" (- > * std .os .plan9 .Tos ),
232
235
);
233
236
}
234
237
238
+ // Move this to the riscv prong below when this is resolved: https://github.com/ziglang/zig/issues/20918
239
+ if (comptime builtin .cpu .arch .isRISCV () and builtin .zig_backend != .stage2_riscv64 ) asm volatile (
240
+ \\ .weak __global_pointer$
241
+ \\ .hidden __global_pointer$
242
+ \\ .option push
243
+ \\ .option norelax
244
+ \\ lla gp, __global_pointer$
245
+ \\ .option pop
246
+ );
247
+
235
248
// Note that we maintain a very low level of trust with regards to ABI guarantees at this point.
236
249
// We will redundantly align the stack, clear the link register, etc. While e.g. the Linux
237
250
// kernel is usually good about upholding the ABI guarantees, the same cannot be said of dynamic
@@ -275,24 +288,19 @@ fn _start() callconv(.Naked) noreturn {
275
288
\\ and sp, #-16
276
289
\\ b %[posixCallMainAndExit]
277
290
,
278
- // zig fmt: off
279
291
.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
- ++
292
+ // The CSKY ABI assumes that `gb` is set to the address of the GOT in order for
293
+ // position-independent code to work. We depend on this in `std.os.linux.start_pie`
294
+ // to locate `_DYNAMIC` as well.
295
+ \\ grs t0, 1f
296
+ \\ 1:
297
+ \\ lrw gb, 1b@GOTPC
298
+ \\ addu gb, t0
290
299
\\ movi lr, 0
291
300
\\ mov a0, sp
292
301
\\ andi sp, sp, -8
293
302
\\ jmpi %[posixCallMainAndExit]
294
303
,
295
- // zig fmt: on
296
304
.hexagon = >
297
305
// r29 = SP, r30 = FP
298
306
\\ r30 = #0
@@ -308,27 +316,13 @@ fn _start() callconv(.Naked) noreturn {
308
316
\\ bstrins.d $sp, $zero, 3, 0
309
317
\\ b %[posixCallMainAndExit]
310
318
,
311
- // zig fmt: off
312
319
.riscv32 , .riscv64 = >
313
- // The self-hosted riscv64 backend is not able to assemble this yet.
314
- if (builtin .zig_backend != .stage2_riscv64 )
315
- // The RISC-V ELF ABI assumes that `gp` is set to the value of `__global_pointer$` at
316
- // startup in order for GP relaxation to work, even in static builds.
317
- \\ .weak __global_pointer$
318
- \\ .hidden __global_pointer$
319
- \\ .option push
320
- \\ .option norelax
321
- \\ lla gp, __global_pointer$
322
- \\ .option pop
323
- else ""
324
- ++
325
320
\\ li s0, 0
326
321
\\ li ra, 0
327
322
\\ mv a0, sp
328
323
\\ andi sp, sp, -16
329
324
\\ tail %[posixCallMainAndExit]@plt
330
325
,
331
- // zig fmt: off
332
326
.m68k = >
333
327
// Note that the - 8 is needed because pc in the jsr instruction points into the middle
334
328
// of the jsr instruction. (The lea is 6 bytes, the jsr is 4 bytes.)
0 commit comments