shithub: mc

Download patch

ref: 07c71bf1ffe122b10c171d151f36c03a0f73585a
parent: aa736008ef9bec12e7e880f2ce60b2aa0e04260c
parent: 979a0dd6fec80a4fe66ced0b5e2ba30cd574abc1
author: Ori Bernstein <[email protected]>
date: Wed Oct 3 18:05:03 EDT 2012

Merge branch 'master' of git+ssh://git.eigenstate.org/git/ori/mc

--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -12,7 +12,8 @@
 
 ASMSRC= \
     start.s \
-    syscall.s
+    syscall.s \
+    util.s
 
 include ../config.mk
 
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -369,6 +369,7 @@
 	const Sysprocess_vm_writev	: scno = 311
 
 	extern const syscall : (sc:scno, args:... -> int64)
+	extern const cstring : (str : byte[:] -> byte*)
 
 	const exit	: (status:int64 -> void)
 	const getpid	: ( -> int64)
@@ -387,9 +388,9 @@
 const exit	= {status;		syscall(Sysexit, 1);}
 const getpid	= {;			-> syscall(Sysgetpid, 1);}
 const kill	= {pid, sig;		-> syscall(Syskill, pid, sig);}
-const open	= {path, opts, mode;	-> syscall(Sysopen, path castto(char*), opts);}
+const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), opts, mode);}
 const close	= {fd;			-> syscall(Sysclose, fd);}
-const creat	= {path, mode;		-> syscall(Syscreat, path castto(char*), mode);}
+const creat	= {path, mode;		-> syscall(Syscreat, cstring(path), 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 castto(size));}
 const lseek	= {fd, off, whence;	-> syscall(Syslseek, fd, off, whence);}
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -433,7 +433,7 @@
 const exit	= {status;		syscall(Sysexit, 1);}
 const getpid	= {;			-> syscall(Sysgetpid, 1);}
 const kill	= {pid, sig;		-> syscall(Syskill, pid, sig);}
-const open	= {path, opts, mode;	-> syscall(Sysopen, path castto(char*), opts);}
+const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path) opts, mode);}
 const close	= {fd;			-> syscall(Sysclose, fd);}
 const creat	= {path, mode;		-> open(path, Ocreat | Otrunc | Owronly, mode);}
 const read	= {fd, buf;		-> syscall(Sysread, fd, buf castto(char*), buf.len);}
--- a/libstd/syscall-linux.s
+++ b/libstd/syscall-linux.s
@@ -20,3 +20,4 @@
 
 	popq %rbp
 	ret
+
--- /dev/null
+++ b/libstd/util.s
@@ -1,0 +1,29 @@
+/*
+ * Allocates a C string on the stack, for
+ * use within system calls, which is the only
+ * place the Myrddin stack should need nul-terminated
+ * strings.
+ *
+ * This is in assembly, because for efficiency we
+ * allocate the C strings on the stack, and don't adjust
+ * %rsp when returning.
+ */
+.globl std$cstring
+std$cstring:
+	movq (%rsp),%r15	/* ret addr */
+	movq 8(%rsp),%rsi	/* src */
+        movq %rsp,%rdi          /* dest */
+	movq %rsp,%rax          /* ret val */
+	movq 16(%rsp),%rcx	/* len */
+
+	subq %rcx,%rsp          /* get stack */
+        subq $1,%rsp            /* nul */
+        andq $(~15),%rsp        /* align */
+
+	cld
+	rep movsb
+        movb $0,(%rdi)          /* terminate */
+
+	pushq %r15              /* ret addr */
+	ret
+
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -162,7 +162,7 @@
     char *localdep;
     char *deps[512];
     char buf[1024];
-    char *extra[2] = {"-o", "" /* filename */};
+    char *extra[] = {"-g", "-o", "" /* filename */};
 
     if (hassuffix(file, ".myr")) {
         getdeps(file, deps, 512, &ndeps);
@@ -189,8 +189,8 @@
     } else if (hassuffix(file, ".s")) {
         swapsuffix(buf, sizeof buf, file, ".s", ".o");
         if (isfresh(file, buf)) {
-            extra[1] = buf;
-            gencmd(&cmd, &ncmd, as, file, extra, 2);
+            extra[2] = buf;
+            gencmd(&cmd, &ncmd, as, file, extra, 3);
             run(cmd);
         }
     }