shithub: mc

Download patch

ref: 3982a9ac9debac6f6c0670f59d3577610b69d4f9
parent: 1c5aa84742e3804a13a2d8fb990d82a6e493bf5a
author: Ori Bernstein <[email protected]>
date: Wed Jun 20 20:34:36 EDT 2012

Add mmap/munmap syscalls to test code.

--- a/test/hello/sys.myr
+++ b/test/hello/sys.myr
@@ -1,4 +1,3 @@
-
 pkg sys =
 	type scno = int
 	type fdopt = int
@@ -42,6 +41,8 @@
 	const Sysfstat	: scno = 108
 	const Syskill	: scno = 37
 	const Sysgetpid	: scno = 20
+	const Sysmmap2	: scno = 192
+	const Sysmunmap	: scno = 91
 
 	extern const syscall : (sc:scno, count:int, args:... -> int)
 
@@ -55,6 +56,8 @@
 	const write	: (fd:int, buf:char[,] -> int)
 	const lseek	: (fd:int, off:uint, whence:int -> int)
 	const fstat	: (fd:int, sb:statbuf* -> int)
+	const munmap	: (addr:byte*, len:uint -> int)
+	const mmap	: (add:byte*, len:uint, prot:uint, flags:uint, fd:int, off:uint)
 ;;
 
 const exit	= {status;		-> syscall(Sysexit, 1);}
@@ -67,3 +70,5 @@
 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);}
--- a/test/hello/syscall.s
+++ b/test/hello/syscall.s
@@ -11,13 +11,22 @@
 	.long .a2
 	.long .a3
 	.long .a4
-.a5:	movl 32(%ebp),%edi
-.a4:	movl 28(%ebp),%esi
-.a3:	movl 24(%ebp),%edx
-.a2:	movl 20(%ebp),%ecx
-.a1:	movl 16(%ebp),%ebx
-	/* 12(%ebp) holds nargs */
-.a0:	movl 8(%ebp),%eax
+	.long .a5
+	.long .a5 
+	/*
+	   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
+	 */
+.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
         int $0x80
 	movl %ebp,%esp
 	popl %ebp