summaryrefslogtreecommitdiff
path: root/test/hello/sys.myr
blob: 94ee715c198db247e70e503928946a6c94af8041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
pkg sys =
	type scno = int
	type fdopt = int
	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
	;;

	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 Sysexit	: scno = 1
	const Sysread	: scno = 3
	const Syswrite	: scno = 4
	const Sysopen	: scno = 5
	const Sysclose	: scno = 6
	const Syscreat	: scno = 8
	const Syslseek	: scno = 19
	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)

	const exit	: (status:int -> int)
	const getpid	: ( -> int)
	const kill	: (pid:int, sig:int -> int)
	const open	: (path:char[,], opts:fdopt -> int)
	const close	: (fd:int -> int)
	const creat	: (path:char[,], mode:int -> int)
	const read	: (fd:int, buf:char[,] -> int)
	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);}
const getpid	= {;			-> syscall(Sysgetpid, 1);}
const kill	= {pid, sig;		-> syscall(Syskill,  2, pid, sig);}
const open	= {path, opts:fdopt;	-> syscall(Sysopen,  2, path castto(char*), opts);}
const close	= {fd;			-> syscall(Sysclose, 1, fd);}
const creat	= {path, mode;		-> syscall(Syscreat, 2, path castto(char*), mode);}
const read	= {fd, buf;		-> syscall(Sysread,  3, fd, buf castto(char*), buf.len);}
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);}