diff options
| author | Jacob G-W <jacoblevgw@gmail.com> | 2023-07-16 21:34:13 -0400 |
|---|---|---|
| committer | Jacob G-W <jacoblevgw@gmail.com> | 2023-08-02 18:19:07 -0400 |
| commit | d0fbfd3c9f419ceb7112d06d4a3500e9c13f6044 (patch) | |
| tree | ad6eeb111777476b7bf5a0411f98c38006131625 /lib/std/start.zig | |
| parent | 841b54f5e3447ee94d89007bf670b3924f78b0d2 (diff) | |
| download | zig-d0fbfd3c9f419ceb7112d06d4a3500e9c13f6044.tar.gz zig-d0fbfd3c9f419ceb7112d06d4a3500e9c13f6044.zip | |
Plan 9: add more features to std.os.plan9
* Replaces the exit assembly with the function from std.
* Reads the top-of-stack struct at program startup that can get information
like the pid.
* Changes the read and write functions to use the Pread and Pwrite syscalls
instead of the depreciated _READ and _WRITE
* Changes the openat function to use flags instead of perms.
Plan9 does not support perms when opening, just when creating.
* Adds an errstr function to read the errstr buf created by the kernel
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index f730b0dd90..d2099ca803 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -166,28 +166,7 @@ fn exit2(code: usize) noreturn { else => @compileError("TODO"), }, // exits(0) - .plan9 => switch (builtin.cpu.arch) { - .x86_64 => { - asm volatile ( - \\push $0 - \\push $0 - \\syscall - : - : [syscall_number] "{rbp}" (8), - : "rcx", "r11", "memory" - ); - }, - // TODO once we get stack setting with assembly on - // arm, exit with 0 instead of stack garbage - .aarch64 => { - asm volatile ("svc #0" - : - : [exit] "{x0}" (0x08), - : "memory", "cc" - ); - }, - else => @compileError("TODO"), - }, + .plan9 => std.os.plan9.exits(null), .windows => { ExitProcess(@as(u32, @truncate(code))); }, @@ -254,6 +233,13 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv } fn _start() callconv(.Naked) noreturn { + // TODO set Top of Stack on non x86_64-plan9 + if (native_os == .plan9 and native_arch == .x86_64) { + // from /sys/src/libc/amd64/main9.s + std.os.plan9.tos = asm volatile ("" + : [tos] "={rax}" (-> *std.os.plan9.Tos), + ); + } asm volatile (switch (native_arch) { .x86_64 => \\ xorl %%ebp, %%ebp |
