diff options
| author | Timon Kruiper <timonkruiper@gmail.com> | 2021-04-05 22:50:54 +0200 |
|---|---|---|
| committer | Timon Kruiper <timonkruiper@gmail.com> | 2021-04-08 14:23:18 +0200 |
| commit | ac14b52e85f857f7f70846d22ea18ea265acb91a (patch) | |
| tree | bceefa15a211ba323fe7645dd69ab6b768f59555 /lib/std/start2.zig | |
| parent | e85cd616ef6439fdb9e7ac118251bb7c2296e553 (diff) | |
| download | zig-ac14b52e85f857f7f70846d22ea18ea265acb91a.tar.gz zig-ac14b52e85f857f7f70846d22ea18ea265acb91a.zip | |
stage2: add support for start.zig
This adds a simplified start2.zig that the current stage2 compiler is
able to generate code for.
Diffstat (limited to 'lib/std/start2.zig')
| -rw-r--r-- | lib/std/start2.zig | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/std/start2.zig b/lib/std/start2.zig new file mode 100644 index 0000000000..22f3578d98 --- /dev/null +++ b/lib/std/start2.zig @@ -0,0 +1,58 @@ +const root = @import("root"); +const builtin = @import("builtin"); + +comptime { + if (builtin.output_mode == 0) { // OutputMode.Exe + if (builtin.link_libc or builtin.object_format == 5) { // ObjectFormat.c + if (!@hasDecl(root, "main")) { + @export(otherMain, "main"); + } + } else { + if (!@hasDecl(root, "_start")) { + @export(otherStart, "_start"); + } + } + } +} + +// FIXME: Cannot call this function `main`, because `fully qualified names` +// have not been implemented yet. +fn otherMain() callconv(.C) c_int { + root.zigMain(); + return 0; +} + +// FIXME: Cannot call this function `_start`, because `fully qualified names` +// have not been implemented yet. +fn otherStart() callconv(.Naked) noreturn { + root.zigMain(); + otherExit(); +} + +// FIXME: Cannot call this function `exit`, because `fully qualified names` +// have not been implemented yet. +fn otherExit() noreturn { + if (builtin.arch == 31) { // x86_64 + asm volatile ("syscall" + : + : [number] "{rax}" (231), + [arg1] "{rdi}" (0) + : "rcx", "r11", "memory" + ); + } else if (builtin.arch == 0) { // arm + asm volatile ("svc #0" + : + : [number] "{r7}" (1), + [arg1] "{r0}" (0) + : "memory" + ); + } else if (builtin.arch == 2) { // aarch64 + asm volatile ("svc #0" + : + : [number] "{x8}" (93), + [arg1] "{x0}" (0) + : "memory", "cc" + ); + } else @compileError("not yet supported!"); + unreachable; +} |
