summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-19 17:40:46 -0400
committerOri Bernstein <ori@eigenstate.org>2015-09-19 17:40:46 -0400
commit837b2cb7b258a5a81325e521b1555b18f88eab74 (patch)
treebaa484483d3dc9f531aec8cb9db75426d26ab354
parent54daa7961f3639adc9965ffa4ddf98e4ab0f2ff9 (diff)
downloadmc-837b2cb7b258a5a81325e521b1555b18f88eab74.tar.gz
Fix syscalls on FreeBSD
-rw-r--r--lib/std/bld.sub1
-rw-r--r--lib/std/execvp.myr1
-rw-r--r--lib/sys/bld.sub1
-rw-r--r--lib/sys/sys+freebsd-x64.myr16
-rw-r--r--lib/sys/syscall+freebsd-x64.s17
-rw-r--r--rt/start-freebsd.s3
-rw-r--r--rt/start-linux.s2
7 files changed, 24 insertions, 17 deletions
diff --git a/lib/std/bld.sub b/lib/std/bld.sub
index b5e37f6..1a2111c 100644
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -77,6 +77,7 @@ lib std {inc=.} =
syswrap-ss+linux.myr
syswrap-ss+osx.myr
syswrap-ss+plan9.myr
+ syswrap-ss+freebsd.myr
syswrap+plan9.myr
syswrap+posixy.myr
;;
diff --git a/lib/std/execvp.myr b/lib/std/execvp.myr
index 38d9fc5..58c8c60 100644
--- a/lib/std/execvp.myr
+++ b/lib/std/execvp.myr
@@ -1,5 +1,6 @@
use "alloc.use"
use "env.use"
+use "errno.use"
use "fmt.use"
use "option.use"
use "strfind.use"
diff --git a/lib/sys/bld.sub b/lib/sys/bld.sub
index b26c158..44152d2 100644
--- a/lib/sys/bld.sub
+++ b/lib/sys/bld.sub
@@ -9,6 +9,7 @@ lib sys =
syscall+plan9-x64.s
syserrno+linux.myr
syserrno+osx.myr
+ syserrno+freebsd.myr
systypes.myr
ifreq+freebsd.myr
ifreq+linux.myr
diff --git a/lib/sys/sys+freebsd-x64.myr b/lib/sys/sys+freebsd-x64.myr
index 7618876..b258492 100644
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -87,11 +87,11 @@ pkg sys =
;;
type utsname = struct
- system : byte[256]
- node : byte[256]
- release : byte[256]
- version : byte[256]
- machine : byte[256]
+ system : byte[32]
+ node : byte[32]
+ release : byte[32]
+ version : byte[32]
+ machine : byte[32]
;;
type sockaddr = struct
@@ -712,9 +712,7 @@ pkg sys =
wraps a syscall argument, converting it to 64 bits for the syscall function. This is
the same as casting, but more concise than writing castto(int64)
*/
-generic a = {x : @t
- -> a(x)
-}
+generic a = {x : @t; -> x castto(uint64)}
extern const cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
@@ -736,7 +734,7 @@ const execv = {cmd, args
/* of course we fucking have to duplicate this code everywhere,
* since we want to stack allocate... */
p = alloca((args.len + 1)*sizeof(byte#))
- cargs = (p castto(byte##))[:args.len]
+ cargs = (p castto(byte##))[:args.len + 1]
for i = 0; i < args.len; i++
cargs[i] = cstring(args[i])
;;
diff --git a/lib/sys/syscall+freebsd-x64.s b/lib/sys/syscall+freebsd-x64.s
index 8002099..2adcff8 100644
--- a/lib/sys/syscall+freebsd-x64.s
+++ b/lib/sys/syscall+freebsd-x64.s
@@ -8,14 +8,17 @@ sys$syscall:
harmless.
*/
movq %rdi,%rax
- movq %rsi,%rdi
- movq %rdx,%rsi
- movq %rcx,%rdx
- movq %r8,%r10
- movq %r9,%r8
- movq 8(%rsp),%r9
+ /* 8(%rsp): hidden type arg */
+ movq 16(%rsp),%rdi
+ movq 24(%rsp),%rsi
+ movq 32(%rsp),%rdx
+ movq 40(%rsp),%r10
+ movq 48(%rsp),%r8
+ movq 56(%rsp),%r9
syscall
+ jae .success
+ negq %rax
+.success:
ret
-
diff --git a/rt/start-freebsd.s b/rt/start-freebsd.s
index 9f5dd2d..396674c 100644
--- a/rt/start-freebsd.s
+++ b/rt/start-freebsd.s
@@ -53,6 +53,9 @@ _start:
pushq %rsi
pushq %rdx
+ /* call pre-main initializers */
+ call __init__
+
/* enter the main program */
call main
/* exit(0) */
diff --git a/rt/start-linux.s b/rt/start-linux.s
index 963d21b..2164515 100644
--- a/rt/start-linux.s
+++ b/rt/start-linux.s
@@ -66,7 +66,7 @@ _start:
pushq %rsi
pushq %rdx
- /* enter the main program */
+ /* call pre-main initializers */
call __init__
/* enter the main program */
call main