authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-07-11 21:53:59+12:00
committergravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-20 15:15:01+03:00
log19659c3bd347471d3d55597bdc1c141e9e4a1ae1
treee601a2d87d64277f611271c1e02d834def0892cb
parent102cb61e401ba2266938882d8a7d751a31a49ab2

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.

2 files changed, 15 insertions(+), 8 deletions(-)

std/os/freebsd.zig+4-4
......@@ -348,7 +348,7 @@ pub fn WIFEXITED(s: i32) bool {
348348 return WTERMSIG(s) == 0;
349349}
350350pub fn WIFSTOPPED(s: i32) bool {
351 return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
351 return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
352352}
353353pub fn WIFSIGNALED(s: i32) bool {
354354 return (unsigned(s) & 0xffff) -% 1 < 0xff;
......@@ -368,7 +368,7 @@ pub fn getErrno(r: usize) usize {
368368}
369369
370370pub fn dup2(old: i32, new: i32) usize {
371 return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));
371 return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new));
372372}
373373
374374pub fn chdir(path: [*]const u8) usize {
......@@ -388,7 +388,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
388388}
389389
390390pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
391 return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);
391 return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count);
392392}
393393
394394pub fn isatty(fd: i32) bool {
......@@ -425,7 +425,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
425425}
426426
427427pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
428 return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
428 return arch.syscall4(arch.SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset);
429429}
430430
431431pub fn pipe(fd: *[2]i32) usize {
std/special/bootstrap.zig+11-4
......@@ -20,10 +20,17 @@ comptime {
2020
2121nakedcc fn _start() noreturn {
2222 switch (builtin.arch) {
23 builtin.Arch.x86_64 => {
24 argc_ptr = asm ("lea (%%rsp), %[argc]"
25 : [argc] "=r" (-> [*]usize)
26 );
23 builtin.Arch.x86_64 => switch (builtin.os) {
24 builtin.Os.freebsd => {
25 argc_ptr = asm ("lea (%%rdi), %[argc]"
26 : [argc] "=r" (-> [*]usize)
27 );
28 },
29 else => {
30 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> [*]usize)
32 );
33 },
2734 },
2835 builtin.Arch.i386 => {
2936 argc_ptr = asm ("lea (%%esp), %[argc]"