summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-30 19:15:53 -0400
committerOri Bernstein <ori@eigenstate.org>2015-09-30 19:15:53 -0400
commite632cbfd8ca7424201e9054cc8c8d0a32a6c92c6 (patch)
treea97bbdff8ec0975d86dda99a6989a2e1c2b35fbe
parent1fb34b1a5524bb3325a97e301a6cc51884a74bbb (diff)
downloadmc-e632cbfd8ca7424201e9054cc8c8d0a32a6c92c6.tar.gz
Fix FreeBSD port. Add missing files, and some ABI issues.
-rw-r--r--lib/regex/bld.sub2
-rw-r--r--lib/std/syswrap-ss+freebsd.myr24
-rw-r--r--lib/sys/sys+freebsd-x64.myr10
-rw-r--r--lib/sys/syscall+freebsd-x64.s19
-rw-r--r--lib/sys/syserrno+freebsd.myr123
-rw-r--r--mbld/deps.myr2
6 files changed, 174 insertions, 6 deletions
diff --git a/lib/regex/bld.sub b/lib/regex/bld.sub
index 23d3011..5a6c079 100644
--- a/lib/regex/bld.sub
+++ b/lib/regex/bld.sub
@@ -4,8 +4,8 @@ lib regex =
ranges.myr
types.myr
- lib ../std:std
lib ../sys:sys
+ lib ../std:std
;;
bin redump {noinst} =
diff --git a/lib/std/syswrap-ss+freebsd.myr b/lib/std/syswrap-ss+freebsd.myr
new file mode 100644
index 0000000..15bb6fa
--- /dev/null
+++ b/lib/std/syswrap-ss+freebsd.myr
@@ -0,0 +1,24 @@
+use sys
+use "errno.use"
+use "cstrconv.use"
+use "slcp.use"
+use "die.use"
+
+pkg std =
+ const exit : (status:int -> void)
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
+;;
+
+const exit = {status; sys.exit(status)}
+const bgetcwd = {buf
+ var res
+
+ res = sys.__getcwd(buf) castto(errno)
+ if res == 0
+ -> cstrlen(buf) castto(errno)
+ elif res == Enomem
+ -> Erange
+ else
+ -> res
+ ;;
+}
diff --git a/lib/sys/sys+freebsd-x64.myr b/lib/sys/sys+freebsd-x64.myr
index b258492..901c6ab 100644
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -4,7 +4,7 @@ pkg sys =
type pid = int /* process id */
type scno = int64 /*syscall*/
type fdopt = int64 /* fd options */
- type fd = int64 /* fd */
+ type fd = int32 /* fd */
type whence = uint64 /* seek from whence */
type mprot = int64 /* memory protection */
type mopt = int64 /* memory mapping options */
@@ -672,7 +672,7 @@ pkg sys =
generic ioctl : (fd:fd, req : int64, arg:@a# -> int64)
const getdirentries : (fd : fd, buf : byte[:], basep : int64# -> int64)
const chdir : (p : byte[:] -> int64)
- const getcwd : (buf : byte[:] -> int64)
+ const __getcwd : (buf : byte[:] -> int64)
/* fd stuff */
const pipe : (fds : fd[2]# -> int64)
@@ -718,6 +718,8 @@ extern const cstring : (str : byte[:] -> byte#)
extern const alloca : (sz : size -> byte#)
extern const __cenvp : byte##
+extern const __freebsd_pipe : (fds : fd[2]# -> int64)
+
/* process management */
const exit = {status; syscall(Sysexit, a(status))}
const getpid = {; -> syscall(Sysgetpid, 1) castto(pid)}
@@ -786,10 +788,10 @@ generic ioctl = {fd, req, arg; -> syscall(Sysioctl, a(fd), a(req), a(arg)) castt
}
const getdirentries = {fd, buf, basep; -> syscall(Sysgetdirentries, a(fd), buf castto(byte#), a(buf.len), a(basep))}
const chdir = {dir; -> syscall(Syschdir, cstring(dir))}
-const getcwd = {buf; -> syscall(Sys__getcwd, a(buf), a(buf.len))}
+const __getcwd = {buf; -> syscall(Sys__getcwd, a(buf), a(buf.len))}
/* file stuff */
-const pipe = {fds; -> syscall(Syspipe, a(fds))}
+const pipe = {fds; -> __freebsd_pipe(fds)}
const dup = {fd; -> syscall(Sysdup, a(fd)) castto(fd)}
const dup2 = {src, dst; -> syscall(Sysdup2, a(src), a(dst)) castto(fd)}
const fcntl = {fd, cmd, args; -> syscall(Sysfcntl, a(fd), a(cmd), a(args))}
diff --git a/lib/sys/syscall+freebsd-x64.s b/lib/sys/syscall+freebsd-x64.s
index 2adcff8..8e560c2 100644
--- a/lib/sys/syscall+freebsd-x64.s
+++ b/lib/sys/syscall+freebsd-x64.s
@@ -22,3 +22,22 @@ sys$syscall:
.success:
ret
+
+/*
+ * pipe() syscall returns the pipes created in eax:edx, and
+ * needs to copy them to the destination locations manually.
+ */
+.globl sys$__freebsd_pipe
+sys$__freebsd_pipe:
+ movq $0x2a,%rax
+ syscall
+
+ jae .pipesuccess
+ negq %rax
+
+.pipesuccess:
+ movl %eax,(%rdi)
+ movl %edx,4(%rdi)
+ xorq %rax,%rax
+ ret
+
diff --git a/lib/sys/syserrno+freebsd.myr b/lib/sys/syserrno+freebsd.myr
new file mode 100644
index 0000000..e48f893
--- /dev/null
+++ b/lib/sys/syserrno+freebsd.myr
@@ -0,0 +1,123 @@
+pkg sys =
+ type errno = int
+
+ const Eperm : errno = -1 /* Operation not permitted */
+ const Enoent : errno = -2 /* No such file or directory */
+ const Esrch : errno = -3 /* No such process */
+ const Eintr : errno = -4 /* Interrupted system call */
+ const Eio : errno = -5 /* Input/output error */
+ const Enxio : errno = -6 /* Device not configured */
+ const E2big : errno = -7 /* Argument list too long */
+ const Enoexec : errno = -8 /* Exec format error */
+ const Ebadf : errno = -9 /* Bad file descriptor */
+ const Echild : errno = -10 /* No child processes */
+ const Edeadlk : errno = -11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+ const Enomem : errno = -12 /* Cannot allocate memory */
+ const Eacces : errno = -13 /* Permission denied */
+ const Efault : errno = -14 /* Bad address */
+ const Enotblk : errno = -15 /* Block device required */
+ const Ebusy : errno = -16 /* Device busy */
+ const Eexist : errno = -17 /* File exists */
+ const Exdev : errno = -18 /* Cross-device link */
+ const Enodev : errno = -19 /* Operation not supported by device */
+ const Enotdir : errno = -20 /* Not a directory */
+ const Eisdir : errno = -21 /* Is a directory */
+ const Einval : errno = -22 /* Invalid argument */
+ const Enfile : errno = -23 /* Too many open files in system */
+ const Emfile : errno = -24 /* Too many open files */
+ const Enotty : errno = -25 /* Inappropriate ioctl for device */
+ const Etxtbsy : errno = -26 /* Text file busy */
+ const Efbig : errno = -27 /* File too large */
+ const Enospc : errno = -28 /* No space left on device */
+ const Espipe : errno = -29 /* Illegal seek */
+ const Erofs : errno = -30 /* Read-only filesystem */
+ const Emlink : errno = -31 /* Too many links */
+ const Epipe : errno = -32 /* Broken pipe */
+
+ /* math software */
+ const Edom : errno = -33 /* Numerical argument out of domain */
+ const Erange : errno = -34 /* Result too large */
+
+ /* non-blocking and interrupt i/o */
+ const Eagain : errno = -35 /* Resource temporarily unavailable */
+ const Einprogress : errno = -36 /* Operation now in progress */
+ const Ealready : errno = -37 /* Operation already in progress */
+
+ /* ipc/network software -- argument errors */
+ const Enotsock : errno = -38 /* Socket operation on non-socket */
+ const Edestaddrreq : errno = -39 /* Destination address required */
+ const Emsgsize : errno = -40 /* Message too long */
+ const Eprototype : errno = -41 /* Protocol wrong type for socket */
+ const Enoprotoopt : errno = -42 /* Protocol not available */
+ const Eprotonosupport : errno = -43 /* Protocol not supported */
+ const Esocktnosupport : errno = -44 /* Socket type not supported */
+ const Eopnotsupp : errno = -45 /* Operation not supported */
+ const Epfnosupport : errno = -46 /* Protocol family not supported */
+ const Eafnosupport : errno = -47 /* Address family not supported by protocol family */
+ const Eaddrinuse : errno = -48 /* Address already in use */
+ const Eaddrnotavail : errno = -49 /* Can't assign requested address */
+
+ /* ipc/network software -- operational errors */
+ const Enetdown : errno = -50 /* Network is down */
+ const Enetunreach : errno = -51 /* Network is unreachable */
+ const Enetreset : errno = -52 /* Network dropped connection on reset */
+ const Econnaborted : errno = -53 /* Software caused connection abort */
+ const Econnreset : errno = -54 /* Connection reset by peer */
+ const Enobufs : errno = -55 /* No buffer space available */
+ const Eisconn : errno = -56 /* Socket is already connected */
+ const Enotconn : errno = -57 /* Socket is not connected */
+ const Eshutdown : errno = -58 /* Can't send after socket shutdown */
+ const Etoomanyrefs : errno = -59 /* Too many references: can't splice */
+ const Etimedout : errno = -60 /* Operation timed out */
+ const Econnrefused : errno = -61 /* Connection refused */
+
+ const Eloop : errno = -62 /* Too many levels of symbolic links */
+ const Enametoolong : errno = -63 /* File name too long */
+
+ /* should be rearranged */
+ const Ehostdown : errno = -64 /* Host is down */
+ const Ehostunreach : errno = -65 /* No route to host */
+ const Enotempty : errno = -66 /* Directory not empty */
+
+ /* quotas & mush */
+ const Eproclim : errno = -67 /* Too many processes */
+ const Eusers : errno = -68 /* Too many users */
+ const Edquot : errno = -69 /* Disc quota exceeded */
+
+ /* Network File System */
+ const Estale : errno = -70 /* Stale NFS file handle */
+ const Eremote : errno = -71 /* Too many levels of remote in path */
+ const Ebadrpc : errno = -72 /* RPC struct is bad */
+ const Erpcmismatch : errno = -73 /* RPC version wrong */
+ const Eprogunavail : errno = -74 /* RPC prog. not avail */
+ const Eprogmismatch : errno = -75 /* Program version wrong */
+ const Eprocunavail : errno = -76 /* Bad procedure for program */
+
+ const Enolck : errno = -77 /* No locks available */
+ const Enosys : errno = -78 /* Function not implemented */
+
+ const Eftype : errno = -79 /* Inappropriate file type or format */
+ const Eauth : errno = -80 /* Authentication error */
+ const Eneedauth : errno = -81 /* Need authenticator */
+ const Eidrm : errno = -82 /* Identifier removed */
+ const Enomsg : errno = -83 /* No message of desired type */
+ const Eoverflow : errno = -84 /* Value too large to be stored in data type */
+ const Ecanceled : errno = -85 /* Operation canceled */
+ const Eilseq : errno = -86 /* Illegal byte sequence */
+ const Enoattr : errno = -87 /* Attribute not found */
+
+ const Edoofus : errno = -88 /* Programming error */
+
+ const Ebadmsg : errno = -89 /* Bad message */
+ const Emultihop : errno = -90 /* Multihop attempted */
+ const Enolink : errno = -91 /* Link has been severed */
+ const Eproto : errno = -92 /* Protocol error */
+
+ const Enotcapable : errno = -93 /* Capabilities insufficient */
+ const Ecapmode : errno = -94 /* Not permitted in capability mode */
+ const Enotrecoverable : errno = -95 /* State not recoverable */
+ const Eownerdead : errno = -96 /* Previous owner died */
+
+ const Elast : errno = -96 /* Must be equal largest errno */
+;;
diff --git a/mbld/deps.myr b/mbld/deps.myr
index f4a8efd..e269250 100644
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -243,7 +243,7 @@ const scrapelibs = {dg, lib, incs
else
std.fput(1, "library {}: usefile version {} unknown\n", lib, v)
;;
- | `std.None: std.fatal("library {}: corrutpt or invalid usefile\n", lib)
+ | `std.None: std.fatal("library {}: corrupt or invalid usefile\n", lib)
;;
std.slfree(rdstr(f))
done = false