summaryrefslogtreecommitdiff
path: root/libstd/sys+plan9-x64.myr
blob: e658cec9e873e4019aa07abeb4f7fcf57c3385d9 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use "systypes.use"

pkg sys =
	type pid	= int64	/* process id */
	type scno	= int64	/* syscall */
	type fdopt	= int64	/* fd options */
	type fd		= int32	/* fd */
	type rflags	= int32	/* rfork flags */

	const Ordonly	: fdopt = 0
	const Owronly	: fdopt = 1
	const Ordwr	: fdopt = 2
	const Oexec	: fdopt = 3

	const Otrunc	: fdopt = 16
	const Ocexec	: fdopt = 32
	const Orclose	: fdopt = 64
	const Oexcl	: fdopt = 0x1000

	const Qtdir	: int64  = 0x80
	const Qtappend	: int64  = 0x40
	const Qtexcl	: int64  = 0x20
	const Qtmount	: int64  = 0x10
	const Qtauth	: int64  = 0x08
	const Qttmp	: int64  = 0x04
	const Qtfile	: int64  = 0x00

	const Dmdir	: int64 = 0x8000000
	const Dmappend	: int64 = 0x4000000
	const Dmexcl	: int64 = 0x2000000
	const Dmmount	: int64 = 0x1000000
	const Dmauth	: int64 = 0x0800000
	const Dmtmp	: int64 = 0x0400000
	const Dmread	: int64 = 0x4
	const Dmwrite	: int64 = 0x2
	const Dmexec	: int64 = 0x1

	const Syssysr1		: scno = 0
	const Sys_errstr	: scno = 1
	const Sysbind		: scno = 2
	const Syschdir		: scno = 3
	const Sysclose		: scno = 4
	const Sysdup		: scno = 5
	const Sysalarm		: scno = 6
	const Sysexec		: scno = 7
	const Sysexits		: scno = 8
	const Sys_fsession	: scno = 9
	const Sysfauth		: scno = 10
	const Sys_fstat		: scno = 11
	const Syssegbrk		: scno = 12
	const Sys_mount		: scno = 13
	const Sysopen		: scno = 14
	const Sys_read		: scno = 15
	const Sysoseek		: scno = 16
	const Syssleep		: scno = 17
	const Sys_stat		: scno = 18
	const Sysrfork		: scno = 19
	const Sys_write		: scno = 20
	const Syspipe		: scno = 21
	const Syscreate		: scno = 22
	const Sysfd2path	: scno = 23
	const Sysbrk_		: scno = 24
	const Sysremove		: scno = 25
	const Sys_wstat		: scno = 26
	const Sys_fwstat	: scno = 27
	const Sysnotify		: scno = 28
	const Sysnoted		: scno = 29
	const Syssegattach	: scno = 30
	const Syssegdetach	: scno = 31
	const Syssegfree	: scno = 32
	const Syssegflush	: scno = 33
	const Sysrendezvous	: scno = 34
	const Sysunmount	: scno = 35
	const Sys_wait		: scno = 36
	const Syssemacquire	: scno = 37
	const Syssemrelease	: scno = 38
	const Sysseek		: scno = 39
	const Sysfversion	: scno = 40
	const Syserrstr		: scno = 41
	const Sysstat		: scno = 42
	const Sysfstat		: scno = 43
	const Syswstat		: scno = 44
	const Sysfwstat		: scno = 45
	const Sysmount		: scno = 46
	const Sysawait		: scno = 47
	const Syspread		: scno = 50
	const Syspwrite		: scno = 51
	const Systsemacquire	: scno = 52
	const Sys_nsec		: scno = 53


	const sysr1	: (->int)
	const bind	: (nm : byte[:], old : byte[:] -> int)
	const chdir	: (dir : byte[:] -> int)
	const close	: (fd : fd -> int)
	const dup	: (old : fd, new : fd -> fd)
	const alarm	: (msec : uint32 -> int)
	const exits	: (msg : byte[:] -> int)
	const fauth	: (fd : fd, name : byte[:] -> int)
	const segbrk	: (saddr : void#, addr : void# -> int)
	const open	: (path : byte[:], opt : fdopt -> fd)
	const sleep	: (msec : uint32 -> int)
	const rfork	: (rflags : rflags -> pid)
	const pipe	: (fds : fd[:] -> int)
	const create	: (path : byte[:], opt : fdopt, perm : int -> fd)
	const fd2path	: (fd : fd, path : byte[:] -> int)
	const remove	: (path : byte[:] -> int)
	const notify	: (fn : (a : void#, c : char# -> int) -> int)
	const noted	: (v : int32 -> int)
	const segattach	: (attr : int32, class : byte[:], va : void#, len : uint32 -> int)
	const segdetach	: (va : void# -> int)
	const segfree	: (va : void#, len : uint32 -> int)
	const segflush	: (va : void#, len : uint32 -> int)
	const unmount	: (name : byte[:], old : byte[:] -> int)
	const errstr	: (buf : byte[:] -> int)
	const stat	: (name : byte[:], edir : byte[:] -> int)
	const fstat	: (fd : fd, edir : byte[:] -> int)
	const wstat	: (name : byte[:], edir : byte[:] -> int)
	const fwstat	: (fd : byte[:],  edir : byte[:] -> int)
	const seek	: (fd : fd, len : off, ty : int -> off)
	const mount	: (fd : fd, afd : fd, old : byte[:], flag : int32, aname : byte[:] -> int)
	const await	: (buf : byte[:] -> int)
	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)
;;

/* asm stub from syscall.s */
extern const syscall : (scno : scno, args : ... -> int)
/* asm stubs from util+plan9.s */
extern const cstring	: (str : byte[:] -> byte#)
extern const alloca	: (sz : size	-> byte#)


generic ptr = {x : @t; -> x castto(byte#)}
generic len32 = {a : @t[:]; -> a.len castto(uint32)}

const sysr1	= {;		-> syscall(Syssysr1)}
const bind	= {name, old;	-> syscall(Sysbind, cstring(name), cstring(old))}
const chdir 	= {dir;		-> syscall(Syschdir, cstring(dir)) }
const close 	= {fd;		-> syscall(Sysclose, fd)}
const dup	= {ofd, nfd;	-> syscall(Sysdup, ofd, nfd) castto(fd)}
const alarm 	= {msec;	-> syscall(Sysalarm, msec)}
const exits 	= {msg;		-> syscall(Sysexits, cstring(msg))}
const fauth 	= {fd, aname;	-> syscall(Sysfauth, fd, cstring(aname))}
const segbrk 	= {saddr, addr;	-> syscall(Syssegbrk, saddr, addr)}
const open 	= {path, opt;	-> syscall(Sysopen, cstring(path), opt) castto(fd)}
const sleep 	= {msec;	-> syscall(Syssleep, msec)}
const rfork 	= {rflags;	-> syscall(Sysrfork, rflags) castto(pid)}
const pipe 	= {fds;		-> syscall(Syspipe, ptr(fds))}
const create 	= {path, mode, perm;	-> syscall(Syscreate, cstring(path), mode, perm) castto(fd)}
const fd2path	= {fd, buf;	-> syscall(Sysfd2path, fd, ptr(buf), len32(buf))}
const remove	= {path;	-> syscall(Sysremove, cstring(path))}
const notify	= {fn;		-> syscall(Sysnotify, fn)}	/* FIXME: this is likely to break... */
const noted	= {v;		-> syscall(Sysnoted, v)}
const segattach	= {attr, class, va, len;	-> syscall(Syssegattach, attr, cstring(class), va, len)}
const segdetach	= {va;		-> syscall(Syssegdetach, va)}
const segfree	= {va, len;	-> syscall(Syssegfree, va, len)}
const segflush	= {va, len;	-> syscall(Syssegfree, va, len)}
const unmount	= {name, old;	-> syscall(Sysunmount, cstring(name), cstring(old))}
const errstr	= {buf;		-> syscall(Syserrstr, ptr(buf), len32(buf))}
const stat	= {name, edir;	-> syscall(Sysstat, cstring(name), ptr(edir), len32(edir))}
const fstat	= {fd, edir;	-> syscall(Sysstat, fd, ptr(edir), len32(edir))}
const wstat	= {name, edir;	-> syscall(Syswstat, cstring(name), ptr(edir), len32(edir))}
const fwstat	= {fd, edir;	-> syscall(Sysfwstat, fd, ptr(edir), len32(edir))}
const mount	= {fd, afd, old, flag, aname;	-> syscall(Sysmount, fd, afd, cstring(old), flag, cstring(aname))}
const await	= {buf;		-> syscall(Sysawait, ptr(buf), len32(buf))}
const pread	= {fd, buf, off;	-> syscall(Syspread, fd, ptr(buf), len32(buf), off) castto(size)}
const pwrite	= {fd, buf, off;	-> syscall(Syspwrite, fd, ptr(buf), len32(buf), off) castto(size)}
const seek	= {fd, n, ty
	var ret : off
	syscall(Sysseek, &ret, fd, n, ty)
	-> ret
}
const exec	= {bin, args
	var p, cargs, i

	/* we need an array of C strings. */
	p = alloca((args.len + 1)*sizeof(byte#))
	cargs = (ptr(p) castto(byte##))[:args.len + 1]
	for i = 0; i < args.len; i++
		cargs[i] = cstring(args[i])
	;;
	cargs[args.len] = ptr(0)
	-> syscall(Sysexec, cstring(bin), cargs)
}
/* ??? do I care for now?
const brk_	= { }
const fversion	= {fd, bufsz, vers, nvers;	-> syscall(Sysfversion, fd, bufsz, }
const await	= {;}
const rendezvous	= {;}
const semacquire	= {;}
const semrelease	= {;}
const tsemacquire	= {;}
*/