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
|
#ifndef _BITS_SYSCALLS_H
#define _BITS_SYSCALLS_H
#ifndef _SYSCALL_H
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
#endif
/* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
* header files. It also defines the traditional `SYS_<name>' macros for older
* programs. */
#include <bits/sysnum.h>
#ifndef __set_errno
# define __set_errno(val) (*__errno_location ()) = (val)
#endif
#ifndef SYS_ify
# define SYS_ify(syscall_name) (__NR_##syscall_name)
#endif
#ifndef __ASSEMBLER__
/* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
#define _syscall0(type,name) \
type name(void) \
{ \
long __res, __err; \
__asm__ volatile ("li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name) \
: "$2","$7","$8","$9","$10","$11","$12","$13","$14","$15", \
"$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
return (type)-1; \
}
/*
* DANGER: This macro isn't usable for the pipe(2) call
* which has a unusual return convention.
*/
#define _syscall1(type,name,atype,a) \
type name(atype a) \
{ \
long __res, __err; \
__asm__ volatile ("move\t$4,%3\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)) \
: "$2","$4","$7","$8","$9","$10","$11","$12","$13","$14","$15","$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
return (type)-1; \
}
#define _syscall2(type,name,atype,a,btype,b) \
type name(atype a,btype b) \
{ \
long __res, __err; \
__asm__ volatile ("move\t$4,%3\n\t" \
"move\t$5,%4\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)), \
"r" ((unsigned long)(b)) \
: "$2","$4","$5","$7","$8","$9","$10","$11","$12","$13", \
"$14","$15", "$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
return (type)-1; \
}
#define _syscall3(type,name,atype,a,btype,b,ctype,c) \
type name (atype a, btype b, ctype c) \
{ \
long __res, __err; \
__asm__ volatile ("move\t$4,%3\n\t" \
"move\t$5,%4\n\t" \
"move\t$6,%5\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)), \
"r" ((unsigned long)(b)), \
"r" ((unsigned long)(c)) \
: "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \
"$13","$14","$15","$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
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 __res, __err; \
__asm__ volatile ("move\t$4,%3\n\t" \
"move\t$5,%4\n\t" \
"move\t$6,%5\n\t" \
"move\t$7,%6\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)), \
"r" ((unsigned long)(b)), \
"r" ((unsigned long)(c)), \
"r" ((unsigned long)(d)) \
: "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \
"$13","$14","$15","$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
return (type)-1; \
}
#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 __res, __err; \
const unsigned long *constE = (unsigned long *) e; \
__asm__ volatile ("move\t$4,%3\n\t" \
"move\t$5,%4\n\t" \
"move\t$6,%5\n\t" \
"lw\t$2,%7\n\t" \
"move\t$7,%6\n\t" \
"subu\t$29,24\n\t" \
"sw\t$2,16($29)\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7\n\t" \
"addiu\t$29,24" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)), \
"r" ((unsigned long)(b)), \
"r" ((unsigned long)(c)), \
"r" ((unsigned long)(d)), \
"m" ((constE)) \
: "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \
"$13","$14","$15","$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
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 __res, __err; \
const unsigned long *constE = (unsigned long *) e; \
const unsigned long *constF = (unsigned long *) f; \
__asm__ volatile ("move\t$4,%3\n\t" \
"move\t$5,%4\n\t" \
"move\t$6,%5\n\t" \
"lw\t$2,%7\n\t" \
"lw\t$3,%8\n\t" \
"move\t$7,%6\n\t" \
"subu\t$29,24\n\t" \
"sw\t$2,16($29)\n\t" \
"sw\t$3,20($29)\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7\n\t" \
"addiu\t$29,24" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)), \
"r" ((unsigned long)(b)), \
"r" ((unsigned long)(c)), \
"r" ((unsigned long)(d)), \
"m" ((constE)), \
"m" ((constF)) \
: "$2","$3","$4","$5","$6","$7","$8","$9","$10","$11", \
"$12","$13","$14","$15","$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
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 __res, __err; \
const unsigned long *constE = (unsigned long *) e; \
const unsigned long *constF = (unsigned long *) f; \
const unsigned long *constG = (unsigned long *) g; \
__asm__ volatile ("move\t$4,%3\n\t" \
"move\t$5,%4\n\t" \
"move\t$6,%5\n\t" \
"lw\t$2,%7\n\t" \
"lw\t$3,%8\n\t" \
"move\t$7,%6\n\t" \
"subu\t$29,32\n\t" \
"sw\t$2,16($29)\n\t" \
"lw\t$2,%9\n\t" \
"sw\t$3,20($29)\n\t" \
"sw\t$2,24($29)\n\t" \
"li\t$2,%2\n\t" \
"syscall\n\t" \
"move\t%0, $2\n\t" \
"move\t%1, $7\n\t" \
"addiu\t$29,32" \
: "=r" (__res), "=r" (__err) \
: "i" (__NR_##name),"r" ((unsigned long)(a)), \
"r" ((unsigned long)(b)), \
"r" ((unsigned long)(c)), \
"r" ((unsigned long)(d)), \
"m" ((constE)), \
"m" ((constF)), \
"m" ((constG)) \
: "$2","$3","$4","$5","$6","$7","$8","$9","$10","$11", \
"$12","$13","$14","$15","$24","memory"); \
if (__err == 0) \
return (type) __res; \
__set_errno(__res); \
return (type)-1; \
}
#endif /* __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */
|