shithub: mc

Download patch

ref: 4b2947c3f828c6895ab15eb83814321d112d3c1a
parent: 9954d66557d7cd1f604bf662547404ee534d8915
author: Ori Bernstein <[email protected]>
date: Tue Jun 19 07:13:19 EDT 2012

Add "hello world" program.

--- /dev/null
+++ b/test/hello/Makefile
@@ -1,0 +1,11 @@
+# don't build anything for 'all'
+all: 
+	./bld.sh
+.PHONY: clean
+clean:
+	@for i in `awk '{print $$1}' tests`; do \
+	    echo rm -f $$i; \
+	    rm -f $$i; \
+	done
+
+install:
--- /dev/null
+++ b/test/hello/bld.sh
@@ -1,0 +1,38 @@
+#!/bin/bash
+
+# We have no dependency handling yet, so this is done via
+# a shell script. Also, we want to rebuild everything for
+# testing purposes on every run as things stand.
+
+export PATH=.:$PATH
+export MC=../8/8m
+export MU=../util/muse
+export CC=cc
+export ASOPT="-g"
+
+function use {
+    N=`basename $1 .myr`
+
+    echo $MU $1 -o $N.use && \
+    $MU $1 -o $N.use
+}
+
+function build {
+    N=`basename $1 .myr`
+
+    echo $MC $1 && \
+    $MC $1 -I. && \
+    mv a.s $N.s && \
+    $CC $ASOPT -m32 -c $N.s
+}
+
+function assem {
+    $CC $ASOPT -m32 -c $1
+}
+
+assem syscall.s
+use sys.myr
+build sys.myr
+build hello.myr
+
+$CC -m32 -o hello sys.o hello.o syscall.o
--- /dev/null
+++ b/test/hello/hello.myr
@@ -1,0 +1,5 @@
+use "sys.use"
+
+const main = {
+	sys.write(1, "Hello world\n")
+}
--- /dev/null
+++ b/test/hello/sys.myr
@@ -1,0 +1,70 @@
+
+pkg sys =
+	type scno = int
+	type fdopt = int
+
+	const Rdonly  	: fdopt = 0x0
+	const Wronly  	: fdopt = 0x1
+	const Rdwr    	: fdopt = 0x2
+	const Append  	: fdopt = 0x80
+	const Creat   	: fdopt = 0x40
+	const Nofollow	: fdopt = 0x20000
+	const Ndelay  	: fdopt = 0x800
+	const Trunc   	: fdopt = 0x200
+
+	const Sexit	: scno = 1
+	const Sread	: scno = 3
+	const Swrite	: scno = 4
+	const Sopen	: scno = 5
+	const Sclose	: scno = 6
+	const Screat	: scno = 8
+	const Slseek	: scno = 19
+	const Sfstat	: scno = 108
+	const Skill	: scno = 37
+	const Sgetpid	: scno = 20
+
+	type statbuf = struct
+		 dev     : uint
+		 ino     : uint
+		 mode    : uint16
+		 nlink   : uint16
+		 uid     : uint16
+		 gid     : uint16
+		 rdev    : uint
+		 size    : uint
+		 blksize : uint
+		 blocks  : uint
+		 atime   : uint
+		 atimens : uint
+		 mtime   : uint
+		 mtimens : uint
+		 ctime   : uint
+		 ctimens : uint
+		 _unused1: uint
+		 _unused2: uint
+	 ;;
+
+	extern const syscall : (sc:scno, count:int, args:... -> int)
+
+	const exit	: (status:int)
+	const getpid	: ()
+	const kill	: (pid:int, sig:int)
+	const open	: (path:char[,], opts:fdopt)
+	const close	: (fd:int)
+	const creat	: (path:char[,], mode:int)
+	const read	: (fd:int, buf:char[,])
+	const write	: (fd:int, buf:char[,])
+	const lseek	: (fd:int, off:uint, whence:int)
+	const fstat	: (fd:int, sb:statbuf*)
+;;
+
+const exit	= {status;		-> syscall(Sexit, 1);}
+const getpid	= {;			-> syscall(Sgetpid, 1);}
+const kill	= {pid, sig;		-> syscall(Skill,  2, pid, sig);}
+const open	= {path, opts:fdopt;	-> syscall(Sopen,  2, path castto(char*), opts);}
+const close	= {fd;			-> syscall(Sclose, 1, fd);}
+const creat	= {path, mode;		-> syscall(Screat, 2, path castto(char*), mode);}
+const read	= {fd, buf;		-> syscall(Sread,  3, fd, buf castto(char*), buf.len);}
+const write	= {fd, buf;		-> syscall(Swrite, 3, fd, buf castto(char*), buf.len);}
+const lseek	= {fd, off:uint, whence;-> syscall(Slseek, 2, fd, off, whence);}
+const fstat	= {fd, sb;		-> syscall(Sfstat, 2, fd, sb);}
--- /dev/null
+++ b/test/hello/syscall.s
@@ -1,0 +1,24 @@
+.globl sys$syscall
+sys$syscall:
+	pushl %ebp
+	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
+.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
+        int $0x80
+	movl %ebp,%esp
+	popl %ebp
+	ret