summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/mips/bits/syscalls.h
blob: bd0eb1eaf3a92512e03f2970f4fff182316e03ba (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#ifndef _BITS_SYSCALLS_H
#define _BITS_SYSCALLS_H
#ifndef _SYSCALL_H
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
#endif

#include <sgidefs.h>

#ifndef __ASSEMBLER__

#include <errno.h>

#define SYS_ify(syscall_name)  (__NR_##syscall_name)

#define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
	"$14", "$15", "$24", "$25", "memory"

#define _syscall0(type,name) \
type name(void) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a3 asm("$7"); 				\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %2	# " #name "\n\t"				\
	"syscall\n\t" 							\
	".set reorder" 							\
	: "=r" (__v0), "=r" (__a3) 					\
	: "i" (SYS_ify(name))						\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall1(type,name,atype,a) \
type name(atype a) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a3 asm("$7"); 				\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %3\t\t\t# " #name "\n\t"				\
	"syscall\n\t" 							\
	".set reorder" 							\
	: "=r" (__v0), "=r" (__a3) 					\
	: "r" (__a0), "i" (SYS_ify(name)) 				\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall2(type,name,atype,a,btype,b) \
type name(atype a,btype b) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a3 asm("$7"); 				\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %4\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	".set	reorder" 						\
	: "=r" (__v0), "=r" (__a3) 					\
	: "r" (__a0), "r" (__a1), "i" (SYS_ify(name))			\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall3(type,name,atype,a,btype,b,ctype,c) \
type name (atype a, btype b, ctype c) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7"); 				\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %5\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	".set	reorder" 						\
	: "=r" (__v0), "=r" (__a3) 					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "i" (SYS_ify(name)) 	\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall4(type,name,atype,a,btype,b,ctype,c,dtype,d) \
type name (atype a, btype b, ctype c, dtype d) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d; 	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %5\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3) 					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "i" (SYS_ify(name)) 	\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#if _MIPS_SIM == _MIPS_SIM_ABI32
#define _syscall5(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e) \
type name (atype a,btype b,ctype c,dtype d,etype e) \
{ 									\
	long err;							\
	long sys_result;						\
	const unsigned long *constE = (void*)(unsigned long) e;		\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d; 	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"lw	$2, %6\n\t" 						\
	"subu	$29, 32\n\t" 						\
	"sw	$2, 16($29)\n\t" 					\
	"li	$2, %5\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	"addiu	$29, 32\n\t" 						\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3) 					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "i" (SYS_ify(name)), 	\
	  "m" (constE)							\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall6(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f) \
type name (atype a,btype b,ctype c,dtype d,etype e,ftype f) \
{ 									\
	long err;							\
	long sys_result;						\
	const unsigned long *constE = (void*)(unsigned long) e;		\
	const unsigned long *constF = (void*)(unsigned long) f;		\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d;	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"lw	$2, %6\n\t" 						\
	"lw	$8, %7\n\t" 						\
	"subu	$29, 32\n\t" 						\
	"sw	$2, 16($29)\n\t" 					\
	"sw	$8, 20($29)\n\t" 					\
	"li	$2, %5\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	"addiu	$29, 32\n\t" 						\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3) 					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "i" (SYS_ify(name)), 	\
	  "m" (constE), "m" (constF)					\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall7(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f,gtype,g) \
type name (atype a,btype b,ctype c,dtype d,etype e,ftype f,gtype g) \
{ 									\
	long err;							\
	long sys_result;						\
	const unsigned long *constE = (void*)(unsigned long) e;		\
	const unsigned long *constF = (void*)(unsigned long) f;		\
	const unsigned long *constG = (void*)(unsigned long) g;		\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d;	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"lw	$2, %6\n\t" 						\
	"lw	$8, %7\n\t" 						\
	"lw	$9, %8\n\t" 						\
	"subu	$29, 32\n\t" 						\
	"sw	$2, 16($29)\n\t" 					\
	"sw	$8, 20($29)\n\t" 					\
	"sw	$9, 24($29)\n\t" 					\
	"li	$2, %5\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	"addiu	$29, 32\n\t" 						\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3) 					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "i" (SYS_ify(name)), 	\
	  "m" (constE), "m" (constF), "m" (constG)			\
	: __SYSCALL_CLOBBERS); \
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}
#else /* N32 || N64 */
#define _syscall5(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e) \
type name (atype a,btype b,ctype c,dtype d,etype e) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d; 	\
	register unsigned long __a4 asm("$8") = (unsigned long) e; 	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %6\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3)					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4), "i" (SYS_ify(name)) 	\
	: "$1", "$3", "$9", "$10", "$11", "$12", "$13",			\
		"$14", "$15", "$24", "$25", "memory");			\
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall6(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f) \
type name (atype a,btype b,ctype c,dtype d,etype e,ftype f) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d;	\
	register unsigned long __a4 asm("$8") = (unsigned long) e; 	\
	register unsigned long __a5 asm("$9") = (unsigned long) f; 	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %7\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3)					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4), "r" (__a5), "i" (SYS_ify(name)) 	\
	: "$1", "$3", "$10", "$11", "$12", "$13",			\
		"$14", "$15", "$24", "$25", "memory");			\
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}

#define _syscall7(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f,gtype,g) \
type name (atype a,btype b,ctype c,dtype d,etype e,ftype f,gtype g) \
{ 									\
	long err;							\
	long sys_result;						\
	{								\
	register unsigned long __v0 asm("$2"); 				\
	register unsigned long __a0 asm("$4") = (unsigned long) a; 	\
	register unsigned long __a1 asm("$5") = (unsigned long) b; 	\
	register unsigned long __a2 asm("$6") = (unsigned long) c; 	\
	register unsigned long __a3 asm("$7") = (unsigned long) d;	\
	register unsigned long __a4 asm("$8") = (unsigned long) e; 	\
	register unsigned long __a5 asm("$9") = (unsigned long) f; 	\
	register unsigned long __a6 asm("$10") = (unsigned long) g; 	\
	__asm__ volatile ( 						\
	".set	noreorder\n\t" 						\
	"li	$2, %8\t\t\t# " #name "\n\t" 				\
	"syscall\n\t" 							\
	".set	reorder" 						\
	: "=r" (__v0), "+r" (__a3)					\
	: "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4), "r" (__a5), "r" (__a6), "i" (SYS_ify(name)) 	\
	: "$1", "$3", "$11", "$12", "$13",			\
		"$14", "$15", "$24", "$25", "memory");			\
	err = __a3;							\
	sys_result = __v0;						\
	}								\
	if (err == 0)							\
		return (type) sys_result;				\
	__set_errno(sys_result);					\
	return (type)-1;						\
}
#endif	/* N32 || N64 */

#endif /* __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */