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 {...@@ -348,7 +348,7 @@ pub fn WIFEXITED(s: i32) bool {
348 return WTERMSIG(s) == 0;348 return WTERMSIG(s) == 0;
349}349}
350pub fn WIFSTOPPED(s: i32) bool {350pub fn WIFSTOPPED(s: i32) bool {
351 return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;351 return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
352}352}
353pub fn WIFSIGNALED(s: i32) bool {353pub fn WIFSIGNALED(s: i32) bool {
354 return (unsigned(s) & 0xffff) -% 1 < 0xff;354 return (unsigned(s) & 0xffff) -% 1 < 0xff;
...@@ -368,7 +368,7 @@ pub fn getErrno(r: usize) usize {...@@ -368,7 +368,7 @@ pub fn getErrno(r: usize) usize {
368}368}
369369
370pub fn dup2(old: i32, new: i32) usize {370pub 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));
372}372}
373373
374pub fn chdir(path: [*]const u8) usize {374pub fn chdir(path: [*]const u8) usize {
...@@ -388,7 +388,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {...@@ -388,7 +388,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
388}388}
389389
390pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {390pub 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);
392}392}
393393
394pub fn isatty(fd: i32) bool {394pub fn isatty(fd: i32) bool {
...@@ -425,7 +425,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {...@@ -425,7 +425,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
425}425}
426426
427pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {427pub 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);
429}429}
430430
431pub fn pipe(fd: *[2]i32) usize {431pub fn pipe(fd: *[2]i32) usize {
std/special/bootstrap.zig+11-4
...@@ -20,10 +20,17 @@ comptime {...@@ -20,10 +20,17 @@ comptime {
2020
21nakedcc fn _start() noreturn {21nakedcc fn _start() noreturn {
22 switch (builtin.arch) {22 switch (builtin.arch) {
23 builtin.Arch.x86_64 => {23 builtin.Arch.x86_64 => switch (builtin.os) {
24 argc_ptr = asm ("lea (%%rsp), %[argc]"24 builtin.Os.freebsd => {
25 : [argc] "=r" (-> [*]usize)25 argc_ptr = asm ("lea (%%rdi), %[argc]"
26 );26 : [argc] "=r" (-> [*]usize)
27 );
28 },
29 else => {
30 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> [*]usize)
32 );
33 },
27 },34 },
28 builtin.Arch.i386 => {35 builtin.Arch.i386 => {
29 argc_ptr = asm ("lea (%%esp), %[argc]"36 argc_ptr = asm ("lea (%%esp), %[argc]"