diff options
| author | Marc Tiehuis <marctiehuis@gmail.com> | 2018-07-11 21:53:59 +1200 |
|---|---|---|
| committer | Greg V <greg@unrelenting.technology> | 2018-10-20 15:15:01 +0300 |
| commit | 19659c3bd347471d3d55597bdc1c141e9e4a1ae1 (patch) | |
| tree | e601a2d87d64277f611271c1e02d834def0892cb /std | |
| parent | 102cb61e401ba2266938882d8a7d751a31a49ab2 (diff) | |
| download | zig-19659c3bd347471d3d55597bdc1c141e9e4a1ae1.tar.gz zig-19659c3bd347471d3d55597bdc1c141e9e4a1ae1.zip | |
freebsd: Fix argc resolution in _start
FreeBSD appears to use rdi instead of rsp as in other posix systems.
According to some loose documentation, x86 passes values on the stack,
so amd64 freebsd may be the only exception.
Diffstat (limited to 'std')
| -rw-r--r-- | std/os/freebsd.zig | 8 | ||||
| -rw-r--r-- | std/special/bootstrap.zig | 15 |
2 files changed, 15 insertions, 8 deletions
diff --git a/std/os/freebsd.zig b/std/os/freebsd.zig index ee7e93d653..8a582db92f 100644 --- a/std/os/freebsd.zig +++ b/std/os/freebsd.zig @@ -348,7 +348,7 @@ pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } pub fn WIFSTOPPED(s: i32) bool { - return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; + return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; } pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s) & 0xffff) -% 1 < 0xff; @@ -368,7 +368,7 @@ pub fn getErrno(r: usize) usize { } pub fn dup2(old: i32, new: i32) usize { - return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); + return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new)); } pub fn chdir(path: [*]const u8) usize { @@ -388,7 +388,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { } pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { - return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); + return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); } pub fn isatty(fd: i32) bool { @@ -425,7 +425,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { } pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { - return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); + return arch.syscall4(arch.SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); } pub fn pipe(fd: *[2]i32) usize { diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 53c646abdc..1fc80f2439 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -20,10 +20,17 @@ comptime { nakedcc fn _start() noreturn { switch (builtin.arch) { - builtin.Arch.x86_64 => { - argc_ptr = asm ("lea (%%rsp), %[argc]" - : [argc] "=r" (-> [*]usize) - ); + builtin.Arch.x86_64 => switch (builtin.os) { + builtin.Os.freebsd => { + argc_ptr = asm ("lea (%%rdi), %[argc]" + : [argc] "=r" (-> [*]usize) + ); + }, + else => { + argc_ptr = asm ("lea (%%rsp), %[argc]" + : [argc] "=r" (-> [*]usize) + ); + }, }, builtin.Arch.i386 => { argc_ptr = asm ("lea (%%esp), %[argc]" |
