shithub: mc

Download patch

ref: e04b2965eda82789f111cb7917afb504bc93c8d9
parent: 2f8a4d4228222a227c4022478bd8e2e64596af52
author: Ori Bernstein <[email protected]>
date: Tue Dec 23 11:34:37 EST 2014

More plan9 syscall wrapping.

--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -85,6 +85,9 @@
 %.myr: %+$(ARCH).myr
 	cp $< $@
 
+%.s: %+$(SYSCLASS).s
+	cp $< $@
+
 %.s: %+$(SYS)-$(ARCH).s
 	cp $< $@
 
--- a/libstd/sys+plan9-x64.myr
+++ b/libstd/sys+plan9-x64.myr
@@ -7,6 +7,25 @@
 	type fd		= int32	/* fd */
 	type rflags	= int32	/* rfork flags */
 
+	type tos = struct
+		prof	: prof
+		cyclefreq	: uint64
+		kcycles	: int64
+		pcycles	: int64
+		pid	: uint32
+		clock	: uint32
+	;;
+
+	type prof = 
+		pp	: byte#	/* plink */
+		next	: byte# /* plink */
+		last	: byte# /* plink */
+		first	: byte# /* plink */
+		pid	: uint32 /* plink */
+		what	: uint32 /* plink */
+	;;
+
+
 	const Ordonly	: fdopt = 0
 	const Owronly	: fdopt = 1
 	const Ordwr	: fdopt = 2
@@ -35,6 +54,19 @@
 	const Dmwrite	: int = 0x2
 	const Dmexec	: int = 0x1
 
+	const Rfnameg	: rflags = 1 << 0,
+	const Rfenvg	: rflags = 1 << 1,
+	const Rffdg	: rflags = 1 << 2,
+	const Rfnoteg	: rflags = 1 << 3,
+	const Rfproc	: rflags = 1 << 4,
+	const Rfmem	: rflags = 1 << 5,
+	const Rfnowait	: rflags = 1 << 6,
+	const Rfcnameg	: rflags = 1 << 10,
+	const Rfcenvg	: rflags = 1 << 11,
+	const Rfcfdg	: rflags = 1 << 12,
+	const Rfrend	: rflags = 1 << 13,
+	const Rfnomnt	: rflags = 1 << 14
+
 	const Syssysr1		: scno = 0
 	const Sys_errstr	: scno = 1
 	const Sysbind		: scno = 2
@@ -101,7 +133,7 @@
 	const open	: (path : byte[:], opt : fdopt -> fd)
 	const sleep	: (msec : uint32 -> int)
 	const rfork	: (rflags : rflags -> pid)
-	const pipe	: (fds : fd[:] -> int)
+	const pipe	: (fds : fd[2]# -> int)
 	const create	: (path : byte[:], opt : fdopt, perm : int -> fd)
 	const fd2path	: (fd : fd, path : byte[:] -> int)
 	const remove	: (path : byte[:] -> int)
@@ -123,6 +155,8 @@
 	const pread	: (fd : fd, buf : byte[:], off : off -> size)
 	const pwrite	: (fd : fd, buf : byte[:], off : off -> size)
 	const exec	: (bin : byte[:], args : byte[:][:] -> int)
+
+	extern const gettos	: (-> tos#)
 ;;
 
 /* asm stub from syscall.s */
--- a/libstd/syswrap+plan9.myr
+++ b/libstd/syswrap+plan9.myr
@@ -38,28 +38,30 @@
 	const waitpid	: (pid:pid, loc:int32#, opt : int64	-> int64)
 ;;
 
+extern const _tos : 
+
 /* fd stuff */
 const open	= {path, opts;	-> openmode(path, opts, 0o777)}
-const openmode	= {path, opts, mode;
+const openmode	= {path, opts, mod
 	if opts & Ocreat != 0
-		-> sys.create(path, opts castto(sys.fdopt), mode) castto(fd)
+		-> sys.create(path, opts castto(sys.fdopt), mode castto(int)) castto(fd)
 	else
 		-> sys.open(path, opts castto(sys.fdopt)) castto(fd)
 	;;
 }
 const close	= {fd;		-> sys.close(fd castto(sys.fd)) castto(int64)}
-const creat	= {path, mode;	-> sys.create(path, sys.Owronly | sys.Otrunc, mode) castto(fd)}
-const read	= {fd, buf;	-> sys.read(fd castto(sys.fd), buf) castto(size)}
-const write	= {fd, buf;	-> sys.write(fd castto(sys.fd), buf) castto(size)}
+const creat	= {path, mode;	-> sys.create(path, sys.Owronly | sys.Otrunc, mode castto(int)) castto(fd)}
+const read	= {fd, buf;	-> sys.pread(fd castto(sys.fd), buf, -1 castto(sys.off)) castto(size)}
+const write	= {fd, buf;	-> sys.pwrite(fd castto(sys.fd), buf, -1 castto(sys.off)) castto(size)}
 const pipe	= {fds;		-> sys.pipe(fds castto(sys.fd[2]#))}
 
 /* path manipulation */
-const mkdir	= {path, mode;	-> 
+const mkdir	= {path, mod
 	var fd
 
-	fd = sys.create(path, sys.Oread, sys.Dmdir | mode)
+	fd = sys.create(path, sys.Ordonly, sys.Dmdir | (mode castto(int)))
 	if fd >= 0
-		close(fd)
+		sys.close(fd)
 		-> 0
 	else
 		-> -1
@@ -68,22 +70,22 @@
 const unlink	= {path;	-> sys.remove(path)}
 
 /* process stuff */
-const getpid	= {;		-> _tos.pid}
+const getpid	= {;		-> sys.gettos().pid}
 const suicide	= {pid;		-> (0 castto(int#))#}
-const fork	= {;		-> sys.fork() castto(pid)}
-const execv	= {cmd, args;	-> sys.execv(cmd, args)}
-const execve	= {cmd, args, env;	-> sys.execve(cmd, args)}	/* FIXME: don't ignore env */
-const exit	= {status;	
+const fork	= {;		-> sys.rfork(sys.Rfproc | sys.Rffdg | sys.Rfrend) castto(pid)}
+const execv	= {cmd, args;	-> sys.exec(cmd, args) castto(int64)}
+const execve	= {cmd, args, env;	-> sys.exec(cmd, args) castto(int64)}	/* FIXME: don't ignore env */
+const exit	= {status
 	if status == 0
-		sys.exit("")
+		sys.exits("")
 	else
-		sys.exit("failure")
+		sys.exits("failure")
 	;;
 }
-const waitpid	= {pid, loc, opt;	->
+const waitpid	= {pid, loc, opt
 	/* FIXME: this is very wrong. */
 	var buf : byte[512]
 	sys.await(buf[:])
-	pid# = 0
+	loc# = 0
 	-> 0
 }
--- a/libstd/util+plan9.s
+++ b/libstd/util+plan9.s
@@ -65,3 +65,7 @@
 	MOVQ    -8(BP),R15
 	MOVQ    (BP),BP
 	RET
+
+TEXT sys$gettos+0(SB),$0
+	LEAQ	_tos+0(SB),AX
+	RET
--- a/libstd/util.s
+++ /dev/null
@@ -1,73 +1,0 @@
-/*
- * 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 sys$cstring
-.globl _sys$cstring
-_sys$cstring:
-sys$cstring:
-	/* save registers */
-	pushq %rbp
-	movq %rsp,%rbp
-	pushq %r15
-	pushq %rsi
-	pushq %rdi
-	pushq %rcx
-
-	movq 8(%rbp),%r15	/* ret addr */
-	movq 16(%rbp),%rsi	/* src */
-	movq 24(%rbp),%rcx	/* len */
-
-	subq %rcx,%rsp		/* get stack */
-	subq $1,%rsp		/* +1 for nul */
-	movq %rsp,%rdi		/* dest */
-	movq %rsp,%rax		/* ret val */
-	subq $16,%rsp		/* "unpop" the args */
-	andq $(~15),%rsp	/* align */
-
-	cld
-	rep movsb
-	movb $0,(%rdi)		/* terminate */
-
-	pushq %r15		/* ret addr */
-
-	/* restore registers */
-	movq -32(%rbp),%rcx
-	movq -24(%rbp),%rdi
-	movq -16(%rbp),%rsi
-	movq -8(%rbp),%r15
-	movq (%rbp),%rbp
-	ret
-
-.globl sys$alloca
-.globl _sys$alloca
-_sys$alloca:
-sys$alloca:
-	/* save registers */
-	pushq %rbp
-	movq %rsp,%rbp
-	pushq %r15
-	pushq %rbx
-
-	movq 8(%rbp),%r15	/* ret addr */
-	movq 16(%rbp),%rbx	/* len */
-
-	/* get stack space */
-	subq %rbx,%rsp		/* get stack space */
-	movq %rsp,%rax		/* top of stack (return value) */
-	subq $16,%rsp		/* "unpop" the args for return */
-	andq $(~15),%rsp	/* align */
-
-	pushq %r15		/* ret addr */
-
-	/* restore registers */
-	movq -16(%rbp),%rbx
-	movq -8(%rbp),%r15
-	movq (%rbp),%rbp
-	ret