ref: 4a5814d74531579135e015781e869ad47bb58c6e
parent: 42d8c26769b81b40e790cf4de86f86e1c4193841
author: Ori Bernstein <[email protected]>
date: Sat Jul 21 17:01:33 EDT 2012
Make system calls work on OSX. It's close enough to Linux in terms of system call numbers that we can make things work across both.
--- a/sys.myr
+++ b/sys.myr
@@ -68,7 +68,7 @@
const Sysmmap2 : scno = 192
const Sysmunmap : scno = 91
- extern const syscall : (sc:scno, count:int, args:... -> int)
+ extern const syscall : (sc:scno, args:... -> int)
const exit : (status:int -> int)
const getpid : ( -> int)
@@ -86,13 +86,13 @@
const exit = {status; -> syscall(Sysexit, 1);}
const getpid = {; -> syscall(Sysgetpid, 1);}
-const kill = {pid, sig; -> syscall(Syskill, 2, pid, sig);}
-const open = {path, opts:fdopt; -> syscall(Sysopen, 2, path castto(char*), opts);}
-const close = {fd; -> syscall(Sysclose, 1, fd);}
-const creat = {path, mode; -> syscall(Syscreat, 2, path castto(char*), mode);}
-const read = {fd, buf; -> syscall(Sysread, 3, fd, buf castto(char*), buf.len);}
-const write = {fd, buf; -> syscall(Syswrite, 3, fd, buf castto(char*), buf.len);}
-const lseek = {fd, off, whence; -> syscall(Syslseek, 2, fd, off, whence);}
-const fstat = {fd, sb; -> syscall(Sysfstat, 2, fd, sb);}
-const munmap = {addr, len; -> syscall(Sysmunmap, 2, addr, len);}
-const mmap = {addr, len, prot, flags, fd, off; -> syscall(Sysmmap2, 6, addr, len, prot, flags, fd, off) castto(byte*);}
+const kill = {pid, sig; -> syscall(Syskill, pid, sig);}
+const open = {path, opts:fdopt; -> syscall(Sysopen, path castto(char*), opts);}
+const close = {fd; -> syscall(Sysclose, fd);}
+const creat = {path, mode; -> syscall(Syscreat, path castto(char*), mode);}
+const read = {fd, buf; -> syscall(Sysread, fd, buf castto(char*), buf.len);}
+const write = {fd, buf; -> syscall(Syswrite, fd, buf castto(char*), buf.len);}
+const lseek = {fd, off, whence; -> syscall(Syslseek, fd, off, whence);}
+const fstat = {fd, sb; -> syscall(Sysfstat, fd, sb);}
+const munmap = {addr, len; -> syscall(Sysmunmap, addr, len);}
+const mmap = {addr, len, prot, flags, fd, off; -> syscall(Sysmmap2, addr, len, prot, flags, fd, off) castto(byte*);}
--- a/syscall.s
+++ b/syscall.s
@@ -4,29 +4,23 @@
movl %esp,%ebp
movl 12(%ebp),%eax #count
shl $2,%eax
- jmp *.jmptab(%eax)
-.jmptab:
- .long .a0
- .long .a1
- .long .a2
- .long .a3
- .long .a4
- .long .a5
- .long .a6
/*
hack: 6 args uses %ebp, so we index
- relative to %esp. This means that if
- we actually start using stack space,
- this code will need adjustment
+ relative to %esp.
+
+ hack: We load 6 args regardless of
+ how many we actually have. This may
+ load junk values, but if the syscall
+ doesn't use them, it's going to be
+ harmless.
*/
-.a6: movl 36(%esp),%ebp
-.a5: movl 32(%esp),%edi
-.a4: movl 28(%esp),%esi
-.a3: movl 24(%esp),%edx
-.a2: movl 20(%esp),%ecx
-.a1: movl 16(%esp),%ebx
- /* 12(%esp) holds nargs */
-.a0: movl 8(%esp),%eax
+ movl 32(%esp),%ebp
+ movl 28(%esp),%edi
+ movl 24(%esp),%esi
+ movl 20(%esp),%edx
+ movl 16(%esp),%ecx
+ movl 12(%esp),%ebx
+ movl 8(%esp),%eax
int $0x80
movl %ebp,%esp
popl %ebp