aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorDavid Rubin <daviru007@icloud.com>2024-07-25 05:50:30 -0700
committerDavid Rubin <daviru007@icloud.com>2024-07-26 04:19:55 -0700
commita1f6a8ef90f0778e4fc5d314eeb1f0a0a93fa53a (patch)
tree7b8cefb2e4cd68db0dd1e3711e42048d6763efb8 /lib/std/start.zig
parentb533e848a288bcf91da2720dc2646b88225642e9 (diff)
downloadzig-a1f6a8ef90f0778e4fc5d314eeb1f0a0a93fa53a.tar.gz
zig-a1f6a8ef90f0778e4fc5d314eeb1f0a0a93fa53a.zip
riscv: airAsm rewrite
with this rewrite we can call functions inside of inline assembly, enabling us to use the default start.zig logic all that's left is to implement lr/sc loops for atomically manipulating 1 and 2 byte values, after which we can use the segfault handler logic.
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig53
1 files changed, 9 insertions, 44 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index 326857d9c0..f911550f08 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -20,8 +20,7 @@ pub const simplified_logic =
builtin.zig_backend == .stage2_arm or
builtin.zig_backend == .stage2_sparc64 or
builtin.cpu.arch == .spirv32 or
- builtin.cpu.arch == .spirv64 or
- builtin.zig_backend == .stage2_riscv64;
+ builtin.cpu.arch == .spirv64;
comptime {
// No matter what, we import the root file, so that any export, test, comptime
@@ -41,10 +40,6 @@ comptime {
} else if (builtin.os.tag == .opencl) {
if (@hasDecl(root, "main"))
@export(spirvMain2, .{ .name = "main" });
- } else if (native_arch.isRISCV()) {
- if (!@hasDecl(root, "_start")) {
- @export(riscv_start, .{ .name = "_start" });
- }
} else {
if (!@hasDecl(root, "_start")) {
@export(_start2, .{ .name = "_start" });
@@ -206,42 +201,6 @@ fn wasi_start() callconv(.C) void {
}
}
-fn riscv_start() callconv(.C) noreturn {
- std.process.exit(switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
- .NoReturn => root.main(),
- .Void => ret: {
- root.main();
- break :ret 0;
- },
- .Int => |info| ret: {
- if (info.bits != 8 or info.signedness == .signed) {
- @compileError(bad_main_ret);
- }
- break :ret root.main();
- },
- .ErrorUnion => ret: {
- const result = root.main() catch {
- const stderr = std.io.getStdErr().writer();
- stderr.writeAll("failed with error\n") catch {
- @panic("failed to print when main returned error");
- };
- break :ret 1;
- };
- switch (@typeInfo(@TypeOf(result))) {
- .Void => break :ret 0,
- .Int => |info| {
- if (info.bits != 8 or info.signedness == .signed) {
- @compileError(bad_main_ret);
- }
- return result;
- },
- else => @compileError(bad_main_ret),
- }
- },
- else => @compileError(bad_main_ret),
- });
-}
-
fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize {
uefi.handle = handle;
uefi.system_table = system_table;
@@ -519,8 +478,10 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
std.os.argv = argv[0..argc];
std.os.environ = envp;
- std.debug.maybeEnableSegfaultHandler();
- maybeIgnoreSigpipe();
+ if (builtin.zig_backend != .stage2_riscv64) {
+ std.debug.maybeEnableSegfaultHandler();
+ maybeIgnoreSigpipe();
+ }
return callMain();
}
@@ -563,6 +524,10 @@ pub inline fn callMain() u8 {
if (@typeInfo(ReturnType) != .ErrorUnion) @compileError(bad_main_ret);
const result = root.main() catch |err| {
+ if (builtin.zig_backend == .stage2_riscv64) {
+ std.debug.print("error: failed with error\n", .{});
+ return 1;
+ }
std.log.err("{s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);