summaryrefslogtreecommitdiff
path: root/libstd/sys+plan9-x64.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-12-24 19:10:02 -0800
committerOri Bernstein <ori@eigenstate.org>2014-12-24 19:10:02 -0800
commit1ee4f4207111b7fcfb0a75db1ebd7298af671007 (patch)
tree0e2dcd046bf28e77bcb6192c24856261585d5e44 /libstd/sys+plan9-x64.myr
parent0b0365bc107ae23e2b88335373bafdd1cb54e5a2 (diff)
downloadmc-1ee4f4207111b7fcfb0a75db1ebd7298af671007.tar.gz
Make a hello world using syscalls work on Plan 9.
YAY!
Diffstat (limited to 'libstd/sys+plan9-x64.myr')
-rw-r--r--libstd/sys+plan9-x64.myr71
1 files changed, 38 insertions, 33 deletions
diff --git a/libstd/sys+plan9-x64.myr b/libstd/sys+plan9-x64.myr
index a67d844..2690b98 100644
--- a/libstd/sys+plan9-x64.myr
+++ b/libstd/sys+plan9-x64.myr
@@ -1,8 +1,8 @@
use "systypes.use"
pkg sys =
+ type scno = int64 /* syscall */
type pid = int32 /* process id */
- type scno = int32 /* syscall */
type fdopt = int32 /* fd options */
type fd = int32 /* fd */
type rflags = int32 /* rfork flags */
@@ -166,44 +166,49 @@ extern const cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
-generic ptr = {x : @t; -> x castto(byte#)}
-generic len32 = {a : @t[:]; -> a.len castto(uint32)}
+/*
+ABI mismatch: Plan 9 aligns all arguments individually to
+8 bytes, Myrddin uses natural alignment (min(sizeof(t), 16).
+Cast to a 64 bit type to paper over this.
+*/
+generic a = {a : @t; -> a castto(uint64)}
+generic s = {a : @t; -> a castto(int64)}
const sysr1 = {; -> syscall(Syssysr1)}
const bind = {name, old; -> syscall(Sysbind, cstring(name), cstring(old))}
const chdir = {dir; -> syscall(Syschdir, cstring(dir)) }
-const close = {fd; -> syscall(Sysclose, fd)}
-const dup = {ofd, nfd; -> syscall(Sysdup, ofd, nfd) castto(fd)}
-const alarm = {msec; -> syscall(Sysalarm, msec)}
+const close = {fd; -> syscall(Sysclose, a(fd))}
+const dup = {ofd, nfd; -> syscall(Sysdup, a(ofd), a(nfd)) castto(fd)}
+const alarm = {msec; -> syscall(Sysalarm, a(msec))}
const exits = {msg; -> syscall(Sysexits, cstring(msg))}
-const fauth = {fd, aname; -> syscall(Sysfauth, fd, cstring(aname))}
-const segbrk = {saddr, addr; -> syscall(Syssegbrk, saddr, addr)}
-const open = {path, opt; -> syscall(Sysopen, cstring(path), opt) castto(fd)}
-const sleep = {msec; -> syscall(Syssleep, msec)}
-const rfork = {rflags; -> syscall(Sysrfork, rflags) castto(pid)}
-const pipe = {fds; -> syscall(Syspipe, ptr(fds))}
-const create = {path, mode, perm; -> syscall(Syscreate, cstring(path), mode, perm) castto(fd)}
-const fd2path = {fd, buf; -> syscall(Sysfd2path, fd, ptr(buf), len32(buf))}
+const fauth = {fd, aname; -> syscall(Sysfauth, a(fd), cstring(aname))}
+const segbrk = {saddr, addr; -> syscall(Syssegbrk, a(saddr), a(addr))}
+const open = {path, opt; -> syscall(Sysopen, cstring(path), a(opt)) castto(fd)}
+const sleep = {msec; -> syscall(Syssleep, a(msec))}
+const rfork = {rflags; -> syscall(Sysrfork, a(rflags)) castto(pid)}
+const pipe = {fds; -> syscall(Syspipe, a(fds))}
+const create = {path, mode, perm; -> syscall(Syscreate, cstring(path), a(mode), a(perm)) castto(fd)}
+const fd2path = {fd, buf; -> syscall(Sysfd2path, a(fd), a(buf), a(buf.len))}
const remove = {path; -> syscall(Sysremove, cstring(path))}
-const notify = {fn; -> syscall(Sysnotify, fn)} /* FIXME: this is likely to break... */
-const noted = {v; -> syscall(Sysnoted, v)}
-const segattach = {attr, class, va, len; -> syscall(Syssegattach, attr, cstring(class), va, len)}
-const segdetach = {va; -> syscall(Syssegdetach, va)}
-const segfree = {va, len; -> syscall(Syssegfree, va, len)}
-const segflush = {va, len; -> syscall(Syssegfree, va, len)}
+const notify = {fn; -> syscall(Sysnotify, fn)} /* FIXME: this is likely to break when we do closures... */
+const noted = {v; -> syscall(Sysnoted, a(v))}
+const segattach = {attr, class, va, len; -> syscall(Syssegattach, a(attr), cstring(class), a(va), a(len))}
+const segdetach = {va; -> syscall(Syssegdetach, a(va))}
+const segfree = {va, len; -> syscall(Syssegfree, a(va), a(len))}
+const segflush = {va, len; -> syscall(Syssegfree, a(va), a(len))}
const unmount = {name, old; -> syscall(Sysunmount, cstring(name), cstring(old))}
-const errstr = {buf; -> syscall(Syserrstr, ptr(buf), len32(buf))}
-const stat = {name, edir; -> syscall(Sysstat, cstring(name), ptr(edir), len32(edir))}
-const fstat = {fd, edir; -> syscall(Sysstat, fd, ptr(edir), len32(edir))}
-const wstat = {name, edir; -> syscall(Syswstat, cstring(name), ptr(edir), len32(edir))}
-const fwstat = {fd, edir; -> syscall(Sysfwstat, fd, ptr(edir), len32(edir))}
-const mount = {fd, afd, old, flag, aname; -> syscall(Sysmount, fd, afd, cstring(old), flag, cstring(aname))}
-const await = {buf; -> syscall(Sysawait, ptr(buf), len32(buf))}
-const pread = {fd, buf, off; -> syscall(Syspread, fd, ptr(buf), len32(buf), off) castto(size)}
-const pwrite = {fd, buf, off; -> syscall(Syspwrite, fd, ptr(buf), len32(buf), off) castto(size)}
+const errstr = {buf; -> syscall(Syserrstr, a(buf), a(buf.len))}
+const stat = {name, edir; -> syscall(Sysstat, cstring(name), a(edir), a(edir))}
+const fstat = {fd, edir; -> syscall(Sysstat, a(fd), a(edir), a(edir))}
+const wstat = {name, edir; -> syscall(Syswstat, cstring(name), a(edir), a(edir))}
+const fwstat = {fd, edir; -> syscall(Sysfwstat, a(fd), a(edir), a(edir))}
+const mount = {fd, afd, old, flag, aname; -> syscall(Sysmount, a(fd), a(afd), cstring(old), a(flag), cstring(aname))}
+const await = {buf; -> syscall(Sysawait, a(buf), a(buf.len))}
+const pread = {fd, buf, off; -> syscall(Syspread, a(fd), a(buf), a(buf.len), off) castto(size)}
+const pwrite = {fd, buf, off; -> syscall(Syspwrite, a(fd), a(buf), a(buf.len), s(off)) castto(size)}
const seek = {fd, n, ty
var ret : off
- syscall(Sysseek, &ret, fd, n, ty)
+ syscall(Sysseek, a(&ret), a(fd), a(n), a(ty))
-> ret
}
const exec = {bin, args
@@ -211,12 +216,12 @@ const exec = {bin, args
/* we need an array of C strings. */
p = alloca((args.len + 1)*sizeof(byte#))
- cargs = (ptr(p) castto(byte##))[:args.len + 1]
+ cargs = (a(p) castto(byte##))[:args.len + 1]
for i = 0; i < args.len; i++
cargs[i] = cstring(args[i])
;;
- cargs[args.len] = ptr(0)
- -> syscall(Sysexec, cstring(bin), cargs)
+ cargs[args.len] = 0 castto(byte#)
+ -> syscall(Sysexec, cstring(bin), a(cargs))
}
/* ??? do I care for now?
const brk_ = { }