1#include "sys/syscall.h"
2
3#define SYSCALL(name) \
4	.global name	; \
5name:			; \
6	ldi	r4, SYS ## name ; \
7	bra	__trap0
8
9	.text
10	.stabs	"trap.S",100,0,0,__trap0
11	.stabs	"int:t(0,1)=r(0,1);-65536;65535;",128,0,0,0
12	.stabs	"long int:t(0,2)=r(0,1);0020000000000;0017777777777;",128,0,0,0
13	.stabs	"_trap0:F(0,1)",36,0,1,__trap0
14	.stabs	"arg1:P(0,1)",64,0,1,0
15	.stabs	"arg2:P(0,1)",64,0,1,1
16	.stabs	"arg3:P(0,1)",64,0,1,2
17	.stabs	"arg4:P(0,1)",64,0,1,3
18	.stabs	"number:P(0,1)",64,0,1,4
19	.global	__trap0
20	.type	__trap0,@function
21__trap0:
22	trap	15			/* trap 15 returns result in r0, error code in r4 */
23	cmpeqi	r4,0			/* is error code zero? */
24	brf0t	ret			/* yes, skip setting errno */
25#if __INT__==32
26	st	r4,@(errno+2,r14)	/* no, set errno */
27	srai	r4,15			/* sign extend high word */
28	st	r4,@(errno,r14)
29#else
30	st	r4,@(errno,r14)	/* no, set errno */
31#endif
32
33ret:
34	jmp	r13		/* return to caller */
35.Ltrap0:
36	.size	__trap0,.Ltrap0-__trap0
37	.stabs	"",36,0,0,.Ltrap0-__trap0
38
39#define CONCAT(a,b) a ## b
40#define STRING(a) #a
41#define XSTRING(a) STRING(a)
42#define XSTRING2(a,b) XSTRING(CONCAT(a,b))
43
44#if __INT__==32
45#define _read _read16
46#define _lseek _lseek16
47#define _write _write16
48#define _close _close16
49#define _open _open16
50#define _creat _creat16
51#define _exit _exit16
52#define _stat _stat16
53#define _chmod _chmod16
54#define _chown _chown16
55#define _fork _fork16
56#define _wait _wait16
57#define _execve _execve16
58#define _execv _execv16
59#define _pipe _pipe16
60#define _kill _kill16
61#define _getpid _getpid16
62#endif
63
64/* Until the assembler allows semicolon as a statement separator, */
65/* we cannot use the SYSCALL macro.  So expand it manually for now. */
66
67/* #SYSCALL(_read) */
68/* #SYSCALL(_lseek) */
69/* #SYSCALL(_write) */
70/* #SYSCALL(_close) */
71/* #SYSCALL(_open) */
72/* #SYSCALL(_creat) */
73/* #SYSCALL(_exit) */
74/* #SYSCALL(_stat) */
75/* #SYSCALL(_chmod) */
76/* #SYSCALL(_chown) */
77/* #SYSCALL(_fork) */
78/* #SYSCALL(_wait) */
79/* #SYSCALL(_execve) */
80/* #SYSCALL(_execv) */
81/* #SYSCALL(_pipe) */
82/* #SYSCALL(_getpid) */
83/* #SYSCALL(_kill) */
84
85	.global	_read
86	.type	_read,@function
87	.stabs	XSTRING2(_read,:F(0,1)),36,0,2,_read
88	.stabs	"fd:P(0,1)",64,0,1,0
89	.stabs	"ptr:P(0,1)",64,0,1,1
90	.stabs	"len:P(0,1)",64,0,1,2
91_read:
92	ldi	r4, SYS_read
93	bra	__trap0
94.Lread:
95	.size	_read,.-_read
96	.stabs	"",36,0,0,.Lread-_read
97
98	.global	_lseek
99	.type	_lseek,@function
100	.stabs	XSTRING2(_lseek,:F(0,1)),36,0,3,_lseek
101	.stabs	"fd:P(0,1)",64,0,1,0
102	.stabs	"offset:P(0,1)",64,0,1,2
103	.stabs	"whence:p(0,1)",160,0,1,0
104_lseek:
105	ldi	r4, SYS_lseek
106	bra	__trap0
107.Llseek:
108	.size	_lseek,.Llseek-_lseek
109	.stabs	"",36,0,0,.Llseek-_lseek
110
111	.global	_write
112	.type	_write,@function
113	.stabs	XSTRING2(_write,:F(0,1)),36,0,4,_write
114	.stabs	"fd:P(0,1)",64,0,1,0
115	.stabs	"ptr:P(0,1)",64,0,1,1
116	.stabs	"len:P(0,1)",64,0,1,2
117_write:
118	ldi	r4, SYS_write
119	bra	__trap0
120.Lwrite:
121	.size	_write,.Lwrite-_write
122	.stabs	"",36,0,0,.Lwrite-_write
123
124	.global	_close
125	.type	_close,@function
126	.stabs	XSTRING2(_close,:F(0,1)),36,0,5,_close
127	.stabs	"fd:P(0,1)",64,0,1,0
128_close:
129	ldi	r4, SYS_close
130	bra	__trap0
131.Lclose:
132	.size	_close,.Lclose-_close
133	.stabs	"",36,0,0,.Lclose-_close
134
135	.global	_open
136	.type	_open,@function
137	.stabs	XSTRING2(_open,:F(0,1)),36,0,6,_open
138	.stabs	"name:P(0,1)",64,0,1,0
139	.stabs	"flags:P(0,1)",64,0,1,1
140	.stabs	"mode:P(0,1)",64,0,1,2
141_open:
142	ldi	r4, SYS_open
143	bra	__trap0
144.Lopen:
145	.size	_open,.Lopen-_open
146	.stabs	"",36,0,0,.Lopen-_open
147
148	.global	_creat
149	.type	_creat,@function
150	.stabs	XSTRING2(_creat,:F(0,1)),36,0,7,_creat
151	.stabs	"name:P(0,1)",64,0,1,0
152	.stabs	"mode:P(0,1)",64,0,1,1
153_creat:
154	ldi	r4, SYS_creat
155	bra	__trap0
156.Lcreat:
157	.size	_creat,.Lcreat-_creat
158	.stabs	"",36,0,0,.Lcreat-_creat
159
160	.global	_exit
161	.type	_exit,@function
162	.stabs	XSTRING2(_exit,:F(0,1)),36,0,8,_exit
163	.stabs	"status:P(0,1)",64,0,1,0
164_exit:
165	ldi	r4, SYS_exit
166	bra	__trap0
167.Lexit:
168	.size	_exit,.Lexit-_exit
169	.stabs	"",36,0,0,.Lexit-_exit
170
171	.global	_stat
172	.type	_stat,@function
173	.stabs	XSTRING2(_stat,:F(0,1)),36,0,9,_stat
174	.stabs	"name:P(0,1)",64,0,1,0
175	.stabs	"packet:P(0,1)",64,0,1,1
176_stat:
177	ldi	r4, SYS_stat
178	bra	__trap0
179.Lstat:
180	.size	_stat,.Lstat-_stat
181	.stabs	"",36,0,0,.Lstat-_stat
182
183	.global	_chmod
184	.type	_chmod,@function
185	.stabs	XSTRING2(_chmod,:F(0,1)),36,0,10,_chmod
186	.stabs	"name:P(0,1)",64,0,1,0
187	.stabs	"mode:P(0,1)",64,0,1,1
188_chmod:
189	ldi	r4, SYS_chmod
190	bra	__trap0
191.Lchmod:
192	.size	_chmod,.Lchmod-_chmod
193	.stabs	"",36,0,0,.Lchmod-_chmod
194
195	.global	_chown
196	.type	_chown,@function
197	.stabs	XSTRING2(_chown,:F(0,1)),36,0,11,_chown
198	.stabs	"name:P(0,1)",64,0,1,0
199	.stabs	"uid:P(0,1)",64,0,1,1
200	.stabs	"gid:P(0,1)",64,0,1,2
201_chown:
202	ldi	r4, SYS_chown
203	bra	__trap0
204.Lchown:
205	.size	_chown,.Lchown-_chown
206	.stabs	"",36,0,0,.Lchown-_chown
207
208	.global	_fork
209	.type	_fork,@function
210	.stabs	XSTRING2(_fork,:F(0,1)),36,0,12,_fork
211_fork:
212	ldi	r4, SYS_fork
213	bra	__trap0
214.Lfork:
215	.size	_fork,.Lfork-_fork
216	.stabs	"",36,0,0,.Lfork-_fork
217
218	.global	_wait
219	.type	_wait,@function
220	.stabs	"status:P(0,1)",64,0,1,0
221	.stabs	XSTRING2(_wait,:F(0,1)),36,0,13,_wait
222_wait:
223	ldi	r4, SYS_wait
224	bra	__trap0
225.Lwait:
226	.size	_wait,.Lwait-_wait
227	.stabs	"",36,0,0,.Lwait-_wait
228
229	.global	_execve
230	.type	_execve,@function
231	.stabs	"name:P(0,1)",64,0,1,0
232	.stabs	"argv:P(0,1)",64,0,1,1
233	.stabs	"envp:P(0,1)",64,0,1,2
234	.stabs	XSTRING2(_execve,:F(0,1)),36,0,14,_execve
235_execve:
236	ldi	r4, SYS_execve
237	bra	__trap0
238.Lexecve:
239	.size	_execve,.Lexecve-_execve
240	.stabs	"",36,0,0,.Lexecve-_execve
241
242	.global	_execv
243	.type	_execv,@function
244	.stabs	XSTRING2(_execv,:F(0,1)),36,0,15,_execv
245	.stabs	"name:P(0,1)",64,0,1,0
246	.stabs	"argv:P(0,1)",64,0,1,1
247_execv:
248	ldi	r4, SYS_execv
249	bra	__trap0
250.Lexecv:
251	.size	_execv,.Lexecv-_execv
252	.stabs	"",36,0,0,.Lexecv-_execv
253
254	.global	_pipe
255	.type	_pipe,@function
256	.stabs	XSTRING2(_pipe,:F(0,1)),36,0,16,_pipe
257	.stabs	"fds:P(0,1)",64,0,1,0
258_pipe:
259	ldi	r4, SYS_pipe
260	bra	__trap0
261.Lpipe:
262	.size	_pipe,.Lpipe-_pipe
263	.stabs	"",36,0,0,.Lpipe-_pipe
264
265	.global	time
266	.type	time,@function
267	.stabs	XSTRING2(time,:F(0,1)),36,0,17,time
268	.stabs	"ptr:P(0,1)",64,0,1,0
269time:
270	ldi	r4, SYS_time
271	bra	__trap0
272.Ltime:
273	.size	time,.Ltime-time
274	.stabs	"",36,0,0,.Ltime-time
275
276	.global	_kill
277	.type	_kill,@function
278	.stabs	XSTRING2(_kill,:F(0,1)),36,0,18,_kill
279	.stabs	"pid:P(0,1)",64,0,1,0
280	.stabs	"sig:P(0,1)",64,0,1,1
281_kill:
282	ldi	r4, SYS_kill
283	bra	__trap0
284.Lkill:
285	.size	_kill,.Lkill-_kill
286	.stabs	"",36,0,0,.Lkill-_kill
287
288	.global	_getpid
289	.type	_getpid,@function
290	.stabs	XSTRING2(_getpid,:F(0,1)),36,0,19,_getpid
291_getpid:
292	ldi	r4, SYS_getpid
293	bra	__trap0
294.Lgetpid:
295	.size	_getpid,.Lgetpid-_getpid
296	.stabs	"",36,0,0,.Lgetpid-_getpid
297