generalized setting and getting of vserver limits
[util-vserver.git] / lib / syscall-alternative.h
1
2 #ifndef __syscall_retval
3 #define __syscall_retval(v)     do { } while(0)
4 #endif
5
6 #ifndef __syscall_error
7 #define __syscall_error(e)      do { errno = (e); } while(0)
8 #endif
9
10 #define __check(pos, reg)                                               \
11         ".ifnc " pos ", " reg "\n\t"                                    \
12         ".err\n\t"                                                      \
13         ".endif\n\t"
14
15 #ifndef __stringify0
16 #define __stringify0(val)       #val
17 #endif
18
19 #ifndef __stringify
20 #define __stringify(val)        __stringify0(val)
21 #endif
22
23 #define __comment(name)                                                 \
24         "\t/* kernel sys_" #name "[" __stringify(__NR_##name) "] */"
25
26
27 /*      *****************************************
28         ALPHA   ALPHA   ALPHA   ALPHA           *
29         alpha kernel interface                  */
30         
31 #if     defined(__alpha__)
32
33 /*      The Alpha calling convention doesn't use the stack until 
34         after the first six arguments have been passed in registers.
35         
36         scnr:   v0($0)
37         args:   a0($16), a1($17), a2($18), a3($19), a4($20), a5($21)
38         sret:   v0($0)
39         serr:   a3($19) (!=0, err=sret)
40 */
41
42
43 #define __syscall_return(type, ret, err) do {                           \
44         __syscall_retval(ret);                                          \
45         if (err) {                                                      \
46                 int __err = (ret);                                      \
47                 __syscall_error(__err);                                 \
48                 ret = -1;                                               \
49         }                                                               \
50         return (type) ret;                                              \
51 } while (0)                             
52
53 #define __syscall_regdef(name, reg)                                     \
54         register long __sc_##name __asm__ (reg)
55
56 #define __syscall_regval(name, reg, val)                                \
57         register long __sc_##name __asm__ (reg) = (long)(val)
58         
59 #define __syscall_clobbers                                              \
60         "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",                 \
61         "$22", "$23", "$24", "$25", "$27", "$28", "memory"              \
62
63
64 #define _syscall0(type, name)                                           \
65 type name(void)                                                         \
66 {                                                                       \
67         long __sc_ret, __sc_err;                                        \
68         {                                                               \
69                 __syscall_regval(v0, "$0", __NR_##name);                \
70                 __syscall_regdef(a3, "$19");                            \
71                                                                         \
72                 __asm__ __volatile__ (                                  \
73                 __check("%0%1%2", "$0$19$0")                            \
74                         "callsys" __comment(name)                       \
75                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
76                       : "0"(__sc_v0)                                    \
77                       : "$16", "$17", "$18", "$20", "$21",              \
78                         __syscall_clobbers                              \
79                 );                                                      \
80                 __sc_ret = __sc_v0;                                     \
81                 __sc_err = __sc_a3;                                     \
82         }                                                               \
83         __syscall_return(type, __sc_ret, __sc_err);                     \
84 }
85
86 #define _syscall1(type, name, type1, arg1)                              \
87 type name(type1 arg1)                                                   \
88 {                                                                       \
89         long __sc_ret, __sc_err;                                        \
90         {                                                               \
91                 __syscall_regval(v0, "$0", __NR_##name);                \
92                 __syscall_regval(a0, "$16", arg1);                      \
93                 __syscall_regdef(a3, "$19");                            \
94                                                                         \
95                 __asm__ __volatile__ (                                  \
96                 __check("%0%1%2%3", "$0$19$0$16")                       \
97                         "callsys" __comment(name)                       \
98                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
99                       : "0"(__sc_v0),                                   \
100                         "r"(__sc_a0)                                    \
101                       : "$17", "$18", "$20", "$21",                     \
102                         __syscall_clobbers                              \
103                 );                                                      \
104                 __sc_ret = __sc_v0;                                     \
105                 __sc_err = __sc_a3;                                     \
106         }                                                               \
107         __syscall_return(type, __sc_ret, __sc_err);                     \
108 }
109
110 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
111 type name(type1 arg1, type2 arg2)                                       \
112 {                                                                       \
113         long __sc_ret, __sc_err;                                        \
114         {                                                               \
115                 __syscall_regval(v0, "$0", __NR_##name);                \
116                 __syscall_regval(a0, "$16", arg1);                      \
117                 __syscall_regval(a1, "$17", arg2);                      \
118                 __syscall_regdef(a3, "$19");                            \
119                                                                         \
120                 __asm__ __volatile__ (                                  \
121                 __check("%0%1%2%3%4", "$0$19$0$16$17")                  \
122                         "callsys" __comment(name)                       \
123                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
124                       : "0"(__sc_v0),                                   \
125                         "r"(__sc_a0), "r"(__sc_a1)                      \
126                       : "$18", "$20", "$21",                            \
127                         __syscall_clobbers                              \
128                 );                                                      \
129                 __sc_ret = __sc_v0;                                     \
130                 __sc_err = __sc_a3;                                     \
131         }                                                               \
132         __syscall_return(type, __sc_ret, __sc_err);                     \
133 }
134
135 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
136 type name(type1 arg1, type2 arg2, type3 arg3)                           \
137 {                                                                       \
138         long __sc_ret, __sc_err;                                        \
139         {                                                               \
140                 __syscall_regval(v0, "$0", __NR_##name);                \
141                 __syscall_regval(a0, "$16", arg1);                      \
142                 __syscall_regval(a1, "$17", arg2);                      \
143                 __syscall_regval(a2, "$18", arg3);                      \
144                 __syscall_regdef(a3, "$19");                            \
145                                                                         \
146                 __asm__ __volatile__ (                                  \
147                 __check("%0%1%2%3%4%5", "$0$19$0$16$17$18")             \
148                         "callsys" __comment(name)                       \
149                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
150                       : "0"(__sc_v0),                                   \
151                         "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2)        \
152                       : "$20", "$21",                                   \
153                         __syscall_clobbers                              \
154                 );                                                      \
155                 __sc_ret = __sc_v0;                                     \
156                 __sc_err = __sc_a3;                                     \
157         }                                                               \
158         __syscall_return(type, __sc_ret, __sc_err);                     \
159 }
160
161 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
162                               type4, arg4)                              \
163 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
164 {                                                                       \
165         long __sc_ret, __sc_err;                                        \
166         {                                                               \
167                 __syscall_regval(v0, "$0", __NR_##name);                \
168                 __syscall_regval(a0, "$16", arg1);                      \
169                 __syscall_regval(a1, "$17", arg2);                      \
170                 __syscall_regval(a2, "$18", arg3);                      \
171                 __syscall_regval(a3, "$19", arg4);                      \
172                                                                         \
173                 __asm__ __volatile__ (                                  \
174                 __check("%0%1%2%3%4%5%6", "$0$19$0$16$17$18$19")        \
175                         "callsys" __comment(name)                       \
176                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
177                       : "0"(__sc_v0),                                   \
178                         "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2),       \
179                         "1"(__sc_a3)                                    \
180                       : "$20", "$21",                                   \
181                         __syscall_clobbers                              \
182                 );                                                      \
183                 __sc_ret = __sc_v0;                                     \
184                 __sc_err = __sc_a3;                                     \
185         }                                                               \
186         __syscall_return(type, __sc_ret, __sc_err);                     \
187
188
189 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
190                               type4, arg4, type5, arg5)                 \
191 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
192 {                                                                       \
193         long __sc_ret, __sc_err;                                        \
194         {                                                               \
195                 __syscall_regval(v0, "$0", __NR_##name);                \
196                 __syscall_regval(a0, "$16", arg1);                      \
197                 __syscall_regval(a1, "$17", arg2);                      \
198                 __syscall_regval(a2, "$18", arg3);                      \
199                 __syscall_regval(a3, "$19", arg4);                      \
200                 __syscall_regval(a4, "$20", arg5);                      \
201                                                                         \
202                 __asm__ __volatile__ (                                  \
203                 __check("%0%1%2%3%4%5%6%7", "$0$19$0$16$17$18$19$20")   \
204                         "callsys" __comment(name)                       \
205                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
206                       : "0"(__sc_v0),                                   \
207                         "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2),       \
208                         "1"(__sc_a3), "r"(__sc_a4)                      \
209                       : "$21",                                          \
210                         __syscall_clobbers                              \
211                 );                                                      \
212                 __sc_ret = __sc_v0;                                     \
213                 __sc_err = __sc_a3;                                     \
214         }                                                               \
215         __syscall_return(type, __sc_ret, __sc_err);                     \
216 }
217
218 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
219                               type4, arg4, type5, arg5, type6, arg6)    \
220 type name (type1 arg1, type2 arg2, type3 arg3,                          \
221            type4 arg4, type5 arg5, type6 arg6)                          \
222 {                                                                       \
223         long __sc_ret, __sc_err;                                        \
224         {                                                               \
225                 __syscall_regval(v0, "$0", __NR_##name);                \
226                 __syscall_regval(a0, "$16", arg1);                      \
227                 __syscall_regval(a1, "$17", arg2);                      \
228                 __syscall_regval(a2, "$18", arg3);                      \
229                 __syscall_regval(a3, "$19", arg4);                      \
230                 __syscall_regval(a4, "$20", arg5);                      \
231                 __syscall_regval(a5, "$21", arg6);                      \
232                                                                         \
233                 __asm__ __volatile__ (                                  \
234                 __check("%0%1%2%3%4%5%6%7%8",                           \
235                         "$0$19$0$16$17$18$19$20$21")                    \
236                         "callsys" __comment(name)                       \
237                       : "=r"(__sc_v0), "=r"(__sc_a3)                    \
238                       : "0"(__sc_v0),                                   \
239                         "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2),       \
240                         "1"(__sc_a3), "r"(__sc_a4), "r"(__sc_a5)        \
241                       : __syscall_clobbers                              \
242                 );                                                      \
243                 __sc_ret = __sc_v0;                                     \
244                 __sc_err = __sc_a3;                                     \
245         }                                                               \
246         __syscall_return(type, __sc_ret, __sc_err);                     \
247 }
248
249
250
251 /*      *****************************************
252         ARM     ARM     ARM     ARM             *
253         arm kernel interface                    */
254
255 #elif   defined(__arm__)
256
257 /*      The Arm calling convention uses stack args after four arguments
258         but the Linux kernel gets up to seven arguments in registers.
259         
260         scnr:   imm
261         args:   a1(r0), a2(r1), a3(r2), a4(r3), v1(r4), v2(r5), 
262         sret:   a1(r0)
263         serr:   (err= sret > (unsigned)-EMAXERRNO)
264 */
265
266 #ifndef EMAXERRNO
267 #define EMAXERRNO   125
268 #endif
269
270 #define __syscall_errcon(res)                                           \
271         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
272
273 #define __syscall_return(type, res) do {                                \
274         __syscall_retval(res);                                          \
275         if (__syscall_errcon(res)) {                                    \
276                 int __err = -(res);                                     \
277                 __syscall_error(__err);                                 \
278                 res = -1;                                               \
279         }                                                               \
280         return (type) res;                                              \
281 } while (0)                             
282
283 #define __syscall_regdef(name, reg)                                     \
284         register int __sc_##name __asm__ (reg)
285
286 #define __syscall_regval(name, reg, val)                                \
287         register int __sc_##name __asm__ (reg) = (int)(val)
288
289
290 #define _syscall0(type, name)                                           \
291 type name(void)                                                         \
292 {                                                                       \
293         long __sc_res;                                                  \
294         {                                                               \
295                 __syscall_regdef(a1, "r0");                             \
296                                                                         \
297                 __asm__ __volatile__ (                                  \
298                 __check("%0", "r0")                                     \
299                         "swi %1" __comment(name)                        \
300                       : "=r"(__sc_a1)                                   \
301                       : "i"(__NR_##name)                                \
302                       : "memory"                                        \
303                 );                                                      \
304                 __sc_res = __sc_a1;                                     \
305         }                                                               \
306         __syscall_return(type, __sc_res);                               \
307 }
308
309 #define _syscall1(type, name, type1, arg1)                              \
310 type name(type1 arg1)                                                   \
311 {                                                                       \
312         long __sc_res;                                                  \
313         {                                                               \
314                 __syscall_regval(a1, "r0", arg1);                       \
315                                                                         \
316                 __asm__ __volatile__ (                                  \
317                 __check("%0%2", "r0r0")                                 \
318                         "swi %1" __comment(name)                        \
319                       : "=r"(__sc_a1)                                   \
320                       : "i"(__NR_##name),                               \
321                         "0"(__sc_a1)                                    \
322                       : "memory"                                        \
323                 );                                                      \
324                 __sc_res = __sc_a1;                                     \
325         }                                                               \
326         __syscall_return(type, __sc_res);                               \
327 }
328
329 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
330 type name(type1 arg1, type2 arg2)                                       \
331 {                                                                       \
332         long __sc_res;                                                  \
333         {                                                               \
334                 __syscall_regval(a1, "r0", arg1);                       \
335                 __syscall_regval(a2, "r1", arg2);                       \
336                                                                         \
337                 __asm__ __volatile__ (                                  \
338                 __check("%0%2%3", "r0r0r1")                             \
339                         "swi %1" __comment(name)                        \
340                       : "=r"(__sc_a1)                                   \
341                       : "i"(__NR_##name),                               \
342                         "0"(__sc_a1), "r"(__sc_a2)                      \
343                       : "memory"                                        \
344                 );                                                      \
345                 __sc_res = __sc_a1;                                     \
346         }                                                               \
347         __syscall_return(type, __sc_res);                               \
348 }
349
350 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
351 type name(type1 arg1, type2 arg2, type3 arg3)                           \
352 {                                                                       \
353         long __sc_res;                                                  \
354         {                                                               \
355                 __syscall_regval(a1, "r0", arg1);                       \
356                 __syscall_regval(a2, "r1", arg2);                       \
357                 __syscall_regval(a3, "r2", arg3);                       \
358                                                                         \
359                 __asm__ __volatile__ (                                  \
360                 __check("%0%2%3%4", "r0r0r1r2")                         \
361                         "swi %1" __comment(name)                        \
362                       : "=r"(__sc_a1)                                   \
363                       : "i"(__NR_##name),                               \
364                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3)        \
365                       : "memory"                                        \
366                 );                                                      \
367                 __sc_res = __sc_a1;                                     \
368         }                                                               \
369         __syscall_return(type, __sc_res);                               \
370 }
371
372 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
373                               type4, arg4)                              \
374 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
375 {                                                                       \
376         long __sc_res;                                                  \
377         {                                                               \
378                 __syscall_regval(a1, "r0", arg1);                       \
379                 __syscall_regval(a2, "r1", arg2);                       \
380                 __syscall_regval(a3, "r2", arg3);                       \
381                 __syscall_regval(a4, "r3", arg4);                       \
382                                                                         \
383                 __asm__ __volatile__ (                                  \
384                 __check("%0%2%3%4%5", "r0r0r1r2r3")                     \
385                         "swi %1" __comment(name)                        \
386                       : "=r"(__sc_a1)                                   \
387                       : "i"(__NR_##name),                               \
388                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
389                         "r"(__sc_a4)                                    \
390                       : "memory"                                        \
391                 );                                                      \
392                 __sc_res = __sc_a1;                                     \
393         }                                                               \
394         __syscall_return(type, __sc_res);                               \
395
396
397 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
398                               type4, arg4, type5, arg5)                 \
399 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
400 {                                                                       \
401         long __sc_res;                                                  \
402         {                                                               \
403                 __syscall_regval(a1, "r0", arg1);                       \
404                 __syscall_regval(a2, "r1", arg2);                       \
405                 __syscall_regval(a3, "r2", arg3);                       \
406                 __syscall_regval(a4, "r3", arg4);                       \
407                 __syscall_regval(v1, "r4", arg5);                       \
408                                                                         \
409                 __asm__ __volatile__ (                                  \
410                 __check("%0%2%3%4%5%6", "r0r0r1r2r3r4")                 \
411                         "swi %1" __comment(name)                        \
412                       : "=r"(__sc_a1)                                   \
413                       : "i"(__NR_##name),                               \
414                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
415                         "r"(__sc_a4), "r"(__sc_v1)                      \
416                       : "memory"                                        \
417                 );                                                      \
418                 __sc_res = __sc_a1;                                     \
419         }                                                               \
420         __syscall_return(type, __sc_res);                               \
421 }
422
423 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
424                               type4, arg4, type5, arg5, type6, arg6)    \
425 type name (type1 arg1, type2 arg2, type3 arg3,                          \
426            type4 arg4, type5 arg5, type6 arg6)                          \
427 {                                                                       \
428         long __sc_res;                                                  \
429         {                                                               \
430                 __syscall_regval(a1, "r0", arg1);                       \
431                 __syscall_regval(a2, "r1", arg2);                       \
432                 __syscall_regval(a3, "r2", arg3);                       \
433                 __syscall_regval(a4, "r3", arg4);                       \
434                 __syscall_regval(v1, "r4", arg5);                       \
435                 __syscall_regval(v2, "r5", arg6);                       \
436                                                                         \
437                 __asm__ __volatile__ (                                  \
438                 __check("%0%2%3%4%5%6%7", "r0r0r1r2r3r4r5")             \
439                         "swi %1" __comment(name)                        \
440                       : "=r"(__sc_a1)                                   \
441                       : "i"(__NR_##name),                               \
442                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
443                         "r"(__sc_a4), "r"(__sc_v1), "r"(__sc_v2)        \
444                       : "memory"                                        \
445                 );                                                      \
446                 __sc_res = __sc_a1;                                     \
447         }                                                               \
448         __syscall_return(type, __sc_res);                               \
449 }
450
451
452 /*      *****************************************
453         CRIS    CRIS    CRIS    CRIS            *
454         cris v10 kernel interface               */
455
456 #elif   defined(__cris__)
457
458 /*      The Cris calling convention uses stack args after four arguments
459         but the Linux kernel gets up to six arguments in registers.
460         
461         scnr:   (r9)
462         args:   (r10), (r11), (r12), (r13), (mof), (srp), 
463         sret:   (r10)
464         serr:   (err= sret > (unsigned)-EMAXERRNO)
465 */
466
467 #ifndef EMAXERRNO
468 #define EMAXERRNO   125
469 #endif
470
471 #define __syscall_errcon(res)                                           \
472         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
473
474 #define __syscall_return(type, res) do {                                \
475         __syscall_retval(res);                                          \
476         if (__syscall_errcon(res)) {                                    \
477                 int __err = -(res);                                     \
478                 __syscall_error(__err);                                 \
479                 res = -1;                                               \
480         }                                                               \
481         return (type) res;                                              \
482 } while (0)                             
483
484 #define __syscall_regdef(name, reg)                                     \
485         register long __sc_##name __asm__ (reg)
486
487 #define __syscall_regval(name, reg, val)                                \
488         register long __sc_##name __asm__ (reg) = (long)(val)
489
490 #define _syscall0(type, name)                                           \
491 type name(void)                                                         \
492 {                                                                       \
493         long __sc_res;                                                  \
494         {                                                               \
495                 __syscall_regval(a0, "r9", __NR_##name);                \
496                 __syscall_regdef(a1, "r10");                            \
497                                                                         \
498                 __asm__ __volatile__ (                                  \
499                 __check("%0%1", "$r10$r9")                              \
500                         "break 13" __comment(name)                      \
501                       : "=r"(__sc_a1)                                   \
502                       : "r"(__sc_a0)                                    \
503                       : "memory", "srp", "r13", "r12", "r11"            \
504                 );                                                      \
505                 __sc_res = __sc_a1;                                     \
506         }                                                               \
507         __syscall_return(type, __sc_res);                               \
508 }
509
510 #define _syscall1(type, name, type1, arg1)                              \
511 type name(type1 arg1)                                                   \
512 {                                                                       \
513         long __sc_res;                                                  \
514         {                                                               \
515                 __syscall_regval(a0, "r9", __NR_##name);                \
516                 __syscall_regval(a1, "r10", arg1);                      \
517                                                                         \
518                 __asm__ __volatile__ (                                  \
519                 __check("%0%1%2", "$r10$r9$r10")                        \
520                         "break 13" __comment(name)                      \
521                       : "=r"(__sc_a1)                                   \
522                       : "r"(__sc_a0),                                   \
523                         "0"(__sc_a1)                                    \
524                       : "memory", "srp", "r13", "r12", "r11"            \
525                 );                                                      \
526                 __sc_res = __sc_a1;                                     \
527         }                                                               \
528         __syscall_return(type, __sc_res);                               \
529 }
530
531 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
532 type name(type1 arg1, type2 arg2)                                       \
533 {                                                                       \
534         long __sc_res;                                                  \
535         {                                                               \
536                 __syscall_regval(a0, "r9", __NR_##name);                \
537                 __syscall_regval(a1, "r10", arg1);                      \
538                 __syscall_regval(a2, "r11", arg2);                      \
539                                                                         \
540                 __asm__ __volatile__ (                                  \
541                 __check("%0%1%2%3", "$r10$r9$r10$r11")                  \
542                         "break 13" __comment(name)                      \
543                       : "=r"(__sc_a1)                                   \
544                       : "r"(__sc_a0),                                   \
545                         "0"(__sc_a1), "r"(__sc_a2)                      \
546                       : "memory", "srp", "r13", "r12"                   \
547                 );                                                      \
548                 __sc_res = __sc_a1;                                     \
549         }                                                               \
550         __syscall_return(type, __sc_res);                               \
551 }
552
553 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
554 type name(type1 arg1, type2 arg2, type3 arg3)                           \
555 {                                                                       \
556         long __sc_res;                                                  \
557         {                                                               \
558                 __syscall_regval(a0, "r9", __NR_##name);                \
559                 __syscall_regval(a1, "r10", arg1);                      \
560                 __syscall_regval(a2, "r11", arg2);                      \
561                 __syscall_regval(a3, "r12", arg3);                      \
562                                                                         \
563                 __asm__ __volatile__ (                                  \
564                 __check("%0%1%2%3%4", "$r10$r9$r10$r11$r12")            \
565                         "break 13" __comment(name)                      \
566                       : "=r"(__sc_a1)                                   \
567                       : "r"(__sc_a0),                                   \
568                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3)        \
569                       : "memory", "srp", "r13"                          \
570                 );                                                      \
571                 __sc_res = __sc_a1;                                     \
572         }                                                               \
573         __syscall_return(type, __sc_res);                               \
574 }
575
576 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
577                               type4, arg4)                              \
578 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
579 {                                                                       \
580         long __sc_res;                                                  \
581         {                                                               \
582                 __syscall_regval(a0, "r9", __NR_##name);                \
583                 __syscall_regval(a1, "r10", arg1);                      \
584                 __syscall_regval(a2, "r11", arg2);                      \
585                 __syscall_regval(a3, "r12", arg3);                      \
586                 __syscall_regval(a4, "r13", arg4);                      \
587                                                                         \
588                 __asm__ __volatile__ (                                  \
589                 __check("%0%1%2%3%4%5", "$r10$r9$r10$r11$r12$r13")      \
590                         "break 13" __comment(name)                      \
591                       : "=r"(__sc_a1)                                   \
592                       : "r"(__sc_a0),                                   \
593                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
594                         "r"(__sc_a4)                                    \
595                       : "memory", "srp"                                 \
596                 );                                                      \
597                 __sc_res = __sc_a1;                                     \
598         }                                                               \
599         __syscall_return(type, __sc_res);                               \
600
601
602 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
603                               type4, arg4, type5, arg5)                 \
604 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
605 {                                                                       \
606         long __sc_res;                                                  \
607         {                                                               \
608                 __syscall_regval(a0, "r9", __NR_##name);                \
609                 __syscall_regval(a1, "r10", arg1);                      \
610                 __syscall_regval(a2, "r11", arg2);                      \
611                 __syscall_regval(a3, "r12", arg3);                      \
612                 __syscall_regval(a4, "r13", arg4);                      \
613                                                                         \
614                 __asm__ __volatile__ (                                  \
615                 __check("%0%1%2%3%4%5", "$r10$r9$r10$r11$r12$r13")      \
616                         "move %6,$mof\n\t"                              \
617                         "break 13" __comment(name)                      \
618                       : "=r"(__sc_a1)                                   \
619                       : "r"(__sc_a0),                                   \
620                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
621                         "r"(__sc_a4),                                   \
622                         "g"((long)arg5)                                 \
623                       : "memory", "srp"                                 \
624                 );                                                      \
625                 __sc_res = __sc_a1;                                     \
626         }                                                               \
627         __syscall_return(type, __sc_res);                               \
628 }
629
630 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
631                               type4, arg4, type5, arg5, type6, arg6)    \
632 type name (type1 arg1, type2 arg2, type3 arg3,                          \
633            type4 arg4, type5 arg5, type6 arg6)                          \
634 {                                                                       \
635         long __sc_res;                                                  \
636         {                                                               \
637                 __syscall_regval(a0, "r9", __NR_##name);                \
638                 __syscall_regval(a1, "r10", arg1);                      \
639                 __syscall_regval(a2, "r11", arg2);                      \
640                 __syscall_regval(a3, "r12", arg3);                      \
641                 __syscall_regval(a4, "r13", arg4);                      \
642                                                                         \
643                 __asm__ __volatile__ (                                  \
644                 __check("%0%1%2%3%4%5", "$r10$r9$r10$r11$r12$r13")      \
645                         "move %6,$mof\n\t"                              \
646                         "move %7,$srp\n\t"                              \
647                         "break 13" __comment(name)                      \
648                       : "=r"(__sc_a1)                                   \
649                       : "r"(__sc_a0),                                   \
650                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
651                         "r"(__sc_a4),                                   \
652                         "g"((long)arg5), "g"((long)arg6)                \
653                       : "memory"                                        \
654                 );                                                      \
655                 __sc_res = __sc_a1;                                     \
656         }                                                               \
657         __syscall_return(type, __sc_res);                               \
658 }
659
660
661 /*      *****************************************
662         FRV     FRV     FRV     FRV             *
663         frv kernel interface            */
664
665 #elif   defined(__frv__)
666
667 #warning syscall arch frv not implemented yet
668
669
670 /*      *****************************************
671         H8300   H8300   H8300   H8300           *
672         h8/300 kernel interface                 */
673
674 #elif   defined(__h8300__)
675
676 #warning syscall arch h8300 not implemented yet
677
678
679 /*      *****************************************
680         I386    I386    I386    I386            *
681         i386 kernel interface                   */
682
683 #elif   defined(__i386__)
684
685 /*      The x86 calling convention uses stack args for all arguments,
686         but the Linux kernel passes the first six arguments in the
687         following registers: ebx, ecx, edx, esi, edi, ebp.
688         
689         scnr:   a0(eax)
690         args:   a1(ebx), a2(ecx), a3(edx), a4(esi), a5(edi), a6(ebp) 
691         sret:   a0(eax)
692         serr:   (err= sret > (unsigned)-EMAXERRNO)
693 */
694
695 #ifndef EMAXERRNO
696 #define EMAXERRNO   129
697 #endif
698
699 #define __syscall_errcon(res)                                           \
700         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
701
702 #define __syscall_return(type, res) do {                                \
703         __syscall_retval(res);                                          \
704         if (__syscall_errcon(res)) {                                    \
705                 int __err = -(res);                                     \
706                 __syscall_error(__err);                                 \
707                 res = -1;                                               \
708         }                                                               \
709         return (type) res;                                              \
710 } while (0)                             
711
712 #define __syscall_regdef(name, reg)                                     \
713         register long __sc_##name __asm__ (reg)
714
715 #define __syscall_regval(name, reg, val)                                \
716         register long __sc_##name __asm__ (reg) = (long)(val)
717
718
719 #define _syscall0(type, name)                                           \
720 type name(void)                                                         \
721 {                                                                       \
722         long __sc_res;                                                  \
723         {                                                               \
724                 __syscall_regval(a0, "eax", __NR_##name);               \
725                                                                         \
726                 __asm__ volatile (                                      \
727                 __check("%0%1", "%%eax%%eax")                           \
728                         "int $0x80" __comment(name)                     \
729                       : "=a"(__sc_a0)                                   \
730                       : "0"(__sc_a0)                                    \
731                       : "memory"                                        \
732                 );                                                      \
733                 __sc_res = __sc_a0;                                     \
734         }                                                               \
735         __syscall_return(type, __sc_res);                               \
736 }
737
738 #define _syscall1(type, name, type1, arg1)                              \
739 type name(type1 arg1)                                                   \
740 {                                                                       \
741         long __sc_res;                                                  \
742         {                                                               \
743                 __syscall_regval(a0, "eax", __NR_##name);               \
744                 __syscall_regval(a1, "ebx", arg1);                      \
745                                                                         \
746                 __asm__ volatile (                                      \
747                 __check("%0%1%2", "%%eax%%eax%%ebx")                    \
748                         "int $0x80" __comment(name)                     \
749                       : "=a"(__sc_a0)                                   \
750                       : "0"(__sc_a0),                                   \
751                         "r" (__sc_a1)                                   \
752                       : "memory"                                        \
753                 );                                                      \
754                 __sc_res = __sc_a0;                                     \
755         }                                                               \
756         __syscall_return(type, __sc_res);                               \
757 }
758
759 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
760 type name(type1 arg1, type2 arg2)                                       \
761 {                                                                       \
762         long __sc_res;                                                  \
763         {                                                               \
764                 __syscall_regval(a0, "eax", __NR_##name);               \
765                 __syscall_regval(a1, "ebx", arg1);                      \
766                 __syscall_regval(a2, "ecx", arg2);                      \
767                                                                         \
768                 __asm__ volatile (                                      \
769                 __check("%0%1%2%3", "%%eax%%eax%%ebx%%ecx")             \
770                         "int $0x80" __comment(name)                     \
771                       : "=a"(__sc_a0)                                   \
772                       : "0"(__sc_a0),                                   \
773                         "r" (__sc_a1), "r"(__sc_a2)                     \
774                       : "memory"                                        \
775                 );                                                      \
776                 __sc_res = __sc_a0;                                     \
777         }                                                               \
778         __syscall_return(type, __sc_res);                               \
779 }
780
781 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
782 type name(type1 arg1, type2 arg2, type3 arg3)                           \
783 {                                                                       \
784         long __sc_res;                                                  \
785         {                                                               \
786                 __syscall_regval(a0, "eax", __NR_##name);               \
787                 __syscall_regval(a1, "ebx", arg1);                      \
788                 __syscall_regval(a2, "ecx", arg2);                      \
789                 __syscall_regval(a3, "edx", arg3);                      \
790                                                                         \
791                 __asm__ volatile (                                      \
792                 __check("%0%1%2%3%4", "%%eax%%eax%%ebx%%ecx%%edx")      \
793                         "int $0x80" __comment(name)                     \
794                       : "=a"(__sc_a0)                                   \
795                       : "0"(__sc_a0),                                   \
796                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3)      \
797                       : "memory"                                        \
798                 );                                                      \
799                 __sc_res = __sc_a0;                                     \
800         }                                                               \
801         __syscall_return(type, __sc_res);                               \
802
803
804
805 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
806                               type4, arg4)                              \
807 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
808 {                                                                       \
809         long __sc_res;                                                  \
810         {                                                               \
811                 __syscall_regval(a0, "eax", __NR_##name);               \
812                 __syscall_regval(a1, "ebx", arg1);                      \
813                 __syscall_regval(a2, "ecx", arg2);                      \
814                 __syscall_regval(a3, "edx", arg3);                      \
815                 __syscall_regval(a4, "esi", arg4);                      \
816                                                                         \
817                 __asm__ volatile (                                      \
818                 __check("%0%1%2%3%4%5",                                 \
819                         "%%eax%%eax%%ebx%%ecx%%edx%%esi")               \
820                         "int $0x80" __comment(name)                     \
821                       : "=a"(__sc_a0)                                   \
822                       : "0"(__sc_a0),                                   \
823                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3),     \
824                         "r" (__sc_a4)                                   \
825                       : "memory"                                        \
826                 );                                                      \
827                 __sc_res = __sc_a0;                                     \
828         }                                                               \
829         __syscall_return(type, __sc_res);                               \
830
831
832 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
833                               type4, arg4, type5, arg5)                 \
834 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
835 {                                                                       \
836         long __sc_res;                                                  \
837         {                                                               \
838                 __syscall_regval(a0, "eax", __NR_##name);               \
839                 __syscall_regval(a1, "ebx", arg1);                      \
840                 __syscall_regval(a2, "ecx", arg2);                      \
841                 __syscall_regval(a3, "edx", arg3);                      \
842                 __syscall_regval(a4, "esi", arg4);                      \
843                 __syscall_regval(a5, "edi", arg5);                      \
844                                                                         \
845                 __asm__ volatile (                                      \
846                 __check("%0%1%2%3%4%5%6",                               \
847                         "%%eax%%eax%%ebx%%ecx%%edx%%esi%%edi")          \
848                         "int $0x80" __comment(name)                     \
849                       : "=a"(__sc_a0)                                   \
850                       : "0"(__sc_a0),                                   \
851                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3),     \
852                         "r" (__sc_a4), "r"(__sc_a5)                     \
853                       : "memory"                                        \
854                 );                                                      \
855                 __sc_res = __sc_a0;                                     \
856         }                                                               \
857         __syscall_return(type, __sc_res);                               \
858 }
859
860 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
861                               type4, arg4, type5, arg5, type6, arg6)    \
862 type name (type1 arg1, type2 arg2, type3 arg3,                          \
863            type4 arg4, type5 arg5, type6 arg6)                          \
864 {                                                                       \
865         long __sc_res;                                                  \
866         {                                                               \
867                 __syscall_regval(a0, "eax", __NR_##name);               \
868                 __syscall_regval(a1, "ebx", arg1);                      \
869                 __syscall_regval(a2, "ecx", arg2);                      \
870                 __syscall_regval(a3, "edx", arg3);                      \
871                 __syscall_regval(a4, "esi", arg4);                      \
872                 __syscall_regval(a5, "edi", arg5);                      \
873                 __syscall_regval(a6, "ebp", arg6);                      \
874                                                                         \
875                 __asm__ volatile (                                      \
876                 __check("%0%1%2%3%4%5%6%7",                             \
877                         "%%eax%%eax%%ebx%%ecx%%edx%%esi%%edi%%ebp")     \
878                         "int $0x80" __comment(name)                     \
879                       : "=a"(__sc_a0)                                   \
880                       : "0"(__sc_a0),                                   \
881                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3),     \
882                         "r" (__sc_a4), "r"(__sc_a5), "r" (__sc_a6)      \
883                       : "memory"                                        \
884                 );                                                      \
885                 __sc_res = __sc_a0;                                     \
886         }                                                               \
887         __syscall_return(type, __sc_res);                               \
888 }
889
890
891 /*      *****************************************
892         IA64    IA64    IA64    IA64            *
893         ia64 kernel interface                   */
894
895 #elif   defined(__ia64__)
896
897 #warning syscall arch ia64 not implemented yet
898
899
900 /*      *****************************************
901         M32R    IM32R   M32R    M32R            *
902         m32r kernel interface                   */
903
904 #elif   defined(__m32r__)
905
906 #warning syscall arch m32r not implemented yet
907
908
909 /*      *****************************************
910         M68K    M68K    M68K    M68K            *
911         m68k kernel interface                   */
912
913 #elif   defined(__m68000__)
914
915 #warning syscall arch m68k not implemented yet
916
917
918 /*      *****************************************
919         MIPS    MIPS    MIPS    MIPS            *
920         mips kernel interface                   */
921
922 #elif defined(__mips__)
923
924 #warning syscall arch mips not implemented yet
925
926
927 /*      *****************************************
928         HPPA    HPPA    HPPA    HPPA            *
929         hppa kernel interface                   */
930
931 #elif defined(__hppa__)
932
933 /*      The hppa calling convention uses r26-r23 for the first 4
934         arguments, the rest is spilled onto the stack. However the
935         Linux kernel passes the first six arguments in the registers
936         r26-r21. 
937         
938         The system call number MUST ALWAYS be loaded in the delay 
939         slot of the ble instruction, or restarting system calls 
940         WILL NOT WORK.
941         
942         scnr:   r20
943         args:   r26, r25, r24, r23, r22, r21 
944         sret:   r28
945         serr:   (err= sret > (unsigned)-EMAXERRNO)
946         clob:   r1, r2, r4, r20, r29, r31, memory
947 */
948
949 #ifndef EMAXERRNO
950 #define EMAXERRNO   4095
951 #endif
952
953 #define __syscall_errcon(res)                                           \
954         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
955
956 #define __syscall_return(type, res) do {                                \
957         __syscall_retval(res);                                          \
958         if (__syscall_errcon(res)) {                                    \
959                 int __err = -(res);                                     \
960                 __syscall_error(__err);                                 \
961                 res = -1;                                               \
962         }                                                               \
963         return (type) res;                                              \
964 } while (0)                             
965
966 #define __syscall_clobbers                                              \
967         "%r1", "%r2", "%r4", "%r20", "%r29", "%r31", "memory" 
968
969 #define __syscall_regdef(name, reg)                                     \
970         register unsigned long __sc_##name __asm__ (reg)
971
972 #define __syscall_regval(name, reg, val)                                \
973         register unsigned long __sc_##name __asm__ (reg) =              \
974         (unsigned long)(val)
975
976
977 #define _syscall0(type, name)                                           \
978 type name(void)                                                         \
979 {                                                                       \
980         long __sc_res;                                                  \
981         {                                                               \
982                 __syscall_regdef(ret, "r28");                           \
983                                                                         \
984                 __asm__ __volatile__ (                                  \
985                 __check("%0", "%%r28")                                  \
986                         "ble  0x100(%%sr2, %%r0)"                       \
987                                 __comment(name) "\n\t"                  \
988                         "ldi %1, %%r20"                                 \
989                       : "=r"(__sc_ret)                                  \
990                       : "i"(__NR_##name)                                \
991                       : "%r21", "%r22", "%r23",                         \
992                         "%r24", "%r25", "%r26",                         \
993                         __syscall_clobbers                              \
994                 );                                                      \
995                 __sc_res = __sc_ret;                                    \
996         }                                                               \
997         __syscall_return(type, __sc_res);                               \
998 }
999
1000 #define _syscall1(type, name, type1, arg1)                              \
1001 type name(type1 arg1)                                                   \
1002 {                                                                       \
1003         long __sc_res;                                                  \
1004         {                                                               \
1005                 __syscall_regdef(ret, "r28");                           \
1006                 __syscall_regval(a1, "r26", arg1);                      \
1007                                                                         \
1008                 __asm__ __volatile__ (                                  \
1009                 __check("%0%2", "%%r28%%r26")                           \
1010                         "ble  0x100(%%sr2, %%r0)"                       \
1011                                 __comment(name) "\n\t"                  \
1012                         "ldi %1, %%r20"                                 \
1013                       : "=r"(__sc_ret)                                  \
1014                       : "i"(__NR_##name),                               \
1015                         "r"(__sc_a1)                                    \
1016                       : "%r21", "%r22", "%r23", "%r24", "%r25",         \
1017                         __syscall_clobbers                              \
1018                 );                                                      \
1019                 __sc_res = __sc_ret;                                    \
1020         }                                                               \
1021         __syscall_return(type, __sc_res);                               \
1022 }
1023
1024 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
1025 type name(type1 arg1, type2 arg2)                                       \
1026 {                                                                       \
1027         long __sc_res;                                                  \
1028         {                                                               \
1029                 __syscall_regdef(ret, "r28");                           \
1030                 __syscall_regval(a1, "r26", arg1);                      \
1031                 __syscall_regval(a2, "r25", arg2);                      \
1032                                                                         \
1033                 __asm__ __volatile__ (                                  \
1034                 __check("%0%2%3", "%%r28%%r26%%r25")                    \
1035                         "ble  0x100(%%sr2, %%r0)"                       \
1036                                 __comment(name) "\n\t"                  \
1037                         "ldi %1, %%r20"                                 \
1038                       : "=r"(__sc_ret)                                  \
1039                       : "i"(__NR_##name),                               \
1040                         "r"(__sc_a1), "r"(__sc_a2)                      \
1041                       : "%r21", "%r22", "%r23", "%r24",                 \
1042                         __syscall_clobbers                              \
1043                 );                                                      \
1044                 __sc_res = __sc_ret;                                    \
1045         }                                                               \
1046         __syscall_return(type, __sc_res);                               \
1047 }
1048
1049 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
1050 type name(type1 arg1, type2 arg2, type3 arg3)                           \
1051 {                                                                       \
1052         long __sc_res;                                                  \
1053         {                                                               \
1054                 __syscall_regdef(ret, "r28");                           \
1055                 __syscall_regval(a1, "r26", arg1);                      \
1056                 __syscall_regval(a2, "r25", arg2);                      \
1057                 __syscall_regval(a3, "r24", arg3);                      \
1058                                                                         \
1059                 __asm__ __volatile__ (                                  \
1060                 __check("%0%2%3%4", "%%r28%%r26%%r25%%r24")             \
1061                         "ble  0x100(%%sr2, %%r0)"                       \
1062                                 __comment(name) "\n\t"                  \
1063                         "ldi %1, %%r20"                                 \
1064                       : "=r"(__sc_ret)                                  \
1065                       : "i"(__NR_##name),                               \
1066                         "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3)        \
1067                       : "%r21", "%r22", "%r23",                         \
1068                         __syscall_clobbers                              \
1069                 );                                                      \
1070                 __sc_res = __sc_ret;                                    \
1071         }                                                               \
1072         __syscall_return(type, __sc_res);                               \
1073
1074
1075 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1076                               type4, arg4)                              \
1077 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
1078 {                                                                       \
1079         long __sc_res;                                                  \
1080         {                                                               \
1081                 __syscall_regdef(ret, "r28");                           \
1082                 __syscall_regval(a1, "r26", arg1);                      \
1083                 __syscall_regval(a2, "r25", arg2);                      \
1084                 __syscall_regval(a3, "r24", arg3);                      \
1085                 __syscall_regval(a4, "r23", arg4);                      \
1086                                                                         \
1087                 __asm__ __volatile__ (                                  \
1088                 __check("%0%2%3%4%5", "%%r28%%r26%%r25%%r24%%r23")      \
1089                         "ble  0x100(%%sr2, %%r0)"                       \
1090                                 __comment(name) "\n\t"                  \
1091                         "ldi %1, %%r20"                                 \
1092                       : "=r"(__sc_ret)                                  \
1093                       : "i"(__NR_##name),                               \
1094                         "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1095                         "r"(__sc_a4)                                    \
1096                       : "%r21", "%r22",                                 \
1097                         __syscall_clobbers                              \
1098                 );                                                      \
1099                 __sc_res = __sc_ret;                                    \
1100         }                                                               \
1101         __syscall_return(type, __sc_res);                               \
1102
1103
1104 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1105                               type4, arg4, type5, arg5)                 \
1106 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
1107 {                                                                       \
1108         long __sc_res;                                                  \
1109         {                                                               \
1110                 __syscall_regdef(ret, "r28");                           \
1111                 __syscall_regval(a1, "r26", arg1);                      \
1112                 __syscall_regval(a2, "r25", arg2);                      \
1113                 __syscall_regval(a3, "r24", arg3);                      \
1114                 __syscall_regval(a4, "r23", arg4);                      \
1115                 __syscall_regval(a5, "r22", arg5);                      \
1116                                                                         \
1117                 __asm__ __volatile__ (                                  \
1118                 __check("%0%2%3%4%5%6",                                 \
1119                         "%%r28%%r26%%r25%%r24%%r23%%r22")               \
1120                         "ble  0x100(%%sr2, %%r0)"                       \
1121                                 __comment(name) "\n\t"                  \
1122                         "ldi %1, %%r20"                                 \
1123                       : "=r"(__sc_ret)                                  \
1124                       : "i"(__NR_##name),                               \
1125                         "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1126                         "r"(__sc_a4), "r"(__sc_a5)                      \
1127                       : "%r21",                                         \
1128                         __syscall_clobbers                              \
1129                 );                                                      \
1130                 __sc_res = __sc_ret;                                    \
1131         }                                                               \
1132         __syscall_return(type, __sc_res);                               \
1133 }
1134
1135 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1136                         type4, arg4, type5, arg5, type6, arg6)          \
1137 type name (type1 arg1, type2 arg2, type3 arg3,                          \
1138            type4 arg4, type5 arg5, type6 arg6)                          \
1139 {                                                                       \
1140         long __sc_res;                                                  \
1141         {                                                               \
1142                 __syscall_regdef(ret, "r28");                           \
1143                 __syscall_regval(a1, "r26", arg1);                      \
1144                 __syscall_regval(a2, "r25", arg2);                      \
1145                 __syscall_regval(a3, "r24", arg3);                      \
1146                 __syscall_regval(a4, "r23", arg4);                      \
1147                 __syscall_regval(a5, "r22", arg5);                      \
1148                 __syscall_regval(a6, "r21", arg6);                      \
1149                                                                         \
1150                 __asm__ __volatile__ (                                  \
1151                 __check("%0%2%3%4%5%6%7",                               \
1152                         "%%r28%%r26%%r25%%r24%%r23%%r22%%r21")          \
1153                         "ble  0x100(%%sr2, %%r0)"                       \
1154                                 __comment(name) "\n\t"                  \
1155                         "ldi %1, %%r20"                                 \
1156                       : "=r"(__sc_ret)                                  \
1157                       : "i"(__NR_##name),                               \
1158                         "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1159                         "r"(__sc_a4), "r"(__sc_a5), "r"(__sc_a6)        \
1160                       : __syscall_clobbers                              \
1161                 );                                                      \
1162                 __sc_res = __sc_ret;                                    \
1163         }                                                               \
1164         __syscall_return(type, __sc_res);                               \
1165 }
1166
1167
1168
1169 /*      *****************************************
1170         PPC64   PPC64   PPC64   PPC64           *
1171         ppc64 kernel interface                  */
1172
1173 #elif defined(__powerpc64__)
1174
1175 #warning syscall arch ppc64 not implemented yet
1176
1177
1178 /*      *****************************************
1179         PPC     PPC     PPC     PPC             *
1180         ppc kernel interface                    */
1181
1182 #elif defined(__powerpc__)
1183
1184 /*      The powerpc calling convention uses r3-r10 to pass the first
1185         eight arguments, the remainder is spilled onto the stack.
1186         
1187         scnr:   r0
1188         args:   a1(r3), a2(r4), a3(r5), a4(r6), a5(r7), a6(r8)
1189         sret:   r3
1190         serr:   (carry)
1191         call:   sc
1192         clob:   cr0, ctr
1193 */
1194
1195 #define __syscall_errcon(err)   (err & 0x10000000)
1196
1197 #define __syscall_return(type, ret, err) do {                           \
1198         __syscall_retval(ret);                                          \
1199         if (__syscall_errcon(err)) {                                    \
1200                 int __err = (ret);                                      \
1201                 __syscall_error(__err);                                 \
1202                 ret = -1;                                               \
1203         }                                                               \
1204         return (type) ret;                                              \
1205 } while (0)                             
1206
1207 #define __syscall_regdef(name, reg)                                     \
1208         register long __sc_##name __asm__ (reg)
1209
1210 #define __syscall_regval(name, reg, val)                                \
1211         register long __sc_##name __asm__ (reg) = (long)(val)
1212
1213 #define __syscall_clobbers                                              \
1214         "r9", "r10", "r11", "r12",                                      \
1215         "cr0", "ctr", "memory"
1216
1217
1218 #define _syscall0(type, name)                                           \
1219 type name(void)                                                         \
1220 {                                                                       \
1221         long __sc_ret, __sc_err;                                \
1222         {                                                               \
1223                 __syscall_regval(r0, "r0", __NR_##name);                \
1224                 __syscall_regdef(a1, "r3");                             \
1225                                                                         \
1226                 __asm__ __volatile__ (                                  \
1227                         "sc" __comment(name) "\n\t"                     \
1228                         "mfcr %0"                                       \
1229                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1230                       : "0"(__sc_r0)                                    \
1231                       : "r4", "r5", "r6", "r7", "r8",                   \
1232                         __syscall_clobbers                              \
1233                 );                                                      \
1234                 __sc_ret = __sc_a1;                                     \
1235                 __sc_err = __sc_r0;                                     \
1236         }                                                               \
1237         __syscall_return(type, __sc_ret, __sc_err);                     \
1238 }
1239
1240 #define _syscall1(type, name, type1, arg1)                              \
1241 type name(type1 arg1)                                                   \
1242 {                                                                       \
1243         unsigned long __sc_ret, __sc_err;                               \
1244         {                                                               \
1245                 __syscall_regval(r0, "r0", __NR_##name);                \
1246                 __syscall_regval(a1, "r3", arg1);                       \
1247                                                                         \
1248                 __asm__ __volatile__ (                                  \
1249                         "sc" __comment(name) "\n\t"                     \
1250                         "mfcr %0"                                       \
1251                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1252                       : "0"(__sc_r0),                                   \
1253                         "1"(__sc_a1)                                    \
1254                       : "r4", "r5", "r6", "r7", "r8",                   \
1255                         __syscall_clobbers                              \
1256                 );                                                      \
1257                 __sc_ret = __sc_a1;                                     \
1258                 __sc_err = __sc_r0;                                     \
1259         }                                                               \
1260         __syscall_return(type, __sc_ret, __sc_err);                     \
1261 }
1262
1263 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
1264 type name(type1 arg1, type2 arg2)                                       \
1265 {                                                                       \
1266         unsigned long __sc_ret, __sc_err;                               \
1267         {                                                               \
1268                 __syscall_regval(r0, "r0", __NR_##name);                \
1269                 __syscall_regval(a1, "r3", arg1);                       \
1270                 __syscall_regval(a2, "r4", arg2);                       \
1271                                                                         \
1272                 __asm__ __volatile__ (                                  \
1273                         "sc" __comment(name) "\n\t"                     \
1274                         "mfcr %0"                                       \
1275                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1276                       : "0"(__sc_r0),                                   \
1277                         "1"(__sc_a1), "r"(__sc_a2)                      \
1278                       : "r5", "r6", "r7", "r8",                         \
1279                         __syscall_clobbers                              \
1280                 );                                                      \
1281                 __sc_ret = __sc_a1;                                     \
1282                 __sc_err = __sc_r0;                                     \
1283         }                                                               \
1284         __syscall_return(type, __sc_ret, __sc_err);                     \
1285 }
1286
1287 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
1288 type name(type1 arg1, type2 arg2, type3 arg3)                           \
1289 {                                                                       \
1290         unsigned long __sc_ret, __sc_err;                               \
1291         {                                                               \
1292                 __syscall_regval(r0, "r0", __NR_##name);                \
1293                 __syscall_regval(a1, "r3", arg1);                       \
1294                 __syscall_regval(a2, "r4", arg2);                       \
1295                 __syscall_regval(a3, "r5", arg3);                       \
1296                                                                         \
1297                 __asm__ __volatile__ (                                  \
1298                         "sc" __comment(name) "\n\t"                     \
1299                         "mfcr %0"                                       \
1300                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1301                       : "0"(__sc_r0),                                   \
1302                         "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3)        \
1303                       : "r6", "r7", "r8",                               \
1304                         __syscall_clobbers                              \
1305                 );                                                      \
1306                 __sc_ret = __sc_a1;                                     \
1307                 __sc_err = __sc_r0;                                     \
1308         }                                                               \
1309         __syscall_return(type, __sc_ret, __sc_err);                     \
1310
1311
1312
1313 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1314                               type4, arg4)                              \
1315 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
1316 {                                                                       \
1317         unsigned long __sc_ret, __sc_err;                               \
1318         {                                                               \
1319                 __syscall_regval(r0, "r0", __NR_##name);                \
1320                 __syscall_regval(a1, "r3", arg1);                       \
1321                 __syscall_regval(a2, "r4", arg2);                       \
1322                 __syscall_regval(a3, "r5", arg3);                       \
1323                 __syscall_regval(a4, "r6", arg4);                       \
1324                                                                         \
1325                 __asm__ __volatile__ (                                  \
1326                         "sc" __comment(name) "\n\t"                     \
1327                         "mfcr %0"                                       \
1328                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1329                       : "0"(__sc_r0),                                   \
1330                         "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1331                         "r"(__sc_a4)                                    \
1332                       : "r7", "r8",                                     \
1333                         __syscall_clobbers                              \
1334                 );                                                      \
1335                 __sc_ret = __sc_a1;                                     \
1336                 __sc_err = __sc_r0;                                     \
1337         }                                                               \
1338         __syscall_return(type, __sc_ret, __sc_err);                     \
1339
1340
1341 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1342                               type4, arg4, type5, arg5)                 \
1343 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
1344 {                                                                       \
1345         unsigned long __sc_ret, __sc_err;                               \
1346         {                                                               \
1347                 __syscall_regval(r0, "r0", __NR_##name);                \
1348                 __syscall_regval(a1, "r3", arg1);                       \
1349                 __syscall_regval(a2, "r4", arg2);                       \
1350                 __syscall_regval(a3, "r5", arg3);                       \
1351                 __syscall_regval(a4, "r6", arg4);                       \
1352                 __syscall_regval(a5, "r7", arg5);                       \
1353                                                                         \
1354                 __asm__ __volatile__ (                                  \
1355                         "sc" __comment(name) "\n\t"                     \
1356                         "mfcr %0"                                       \
1357                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1358                       : "0"(__sc_r0),                                   \
1359                         "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1360                         "r"(__sc_a4), "r"(__sc_a5)                      \
1361                       : "r8",                                           \
1362                         __syscall_clobbers                              \
1363                 );                                                      \
1364                 __sc_ret = __sc_a1;                                     \
1365                 __sc_err = __sc_r0;                                     \
1366         }                                                               \
1367         __syscall_return(type, __sc_ret, __sc_err);                     \
1368 }
1369
1370 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1371                               type4, arg4, type5, arg5, type6, arg6)    \
1372 type name (type1 arg1, type2 arg2, type3 arg3,                          \
1373            type4 arg4, type5 arg5, type6 arg6)                          \
1374 {                                                                       \
1375         unsigned long __sc_ret, __sc_err;                               \
1376         {                                                               \
1377                 __syscall_regval(r0, "r0", __NR_##name);                \
1378                 __syscall_regval(a1, "r3", arg1);                       \
1379                 __syscall_regval(a2, "r4", arg2);                       \
1380                 __syscall_regval(a3, "r5", arg3);                       \
1381                 __syscall_regval(a4, "r6", arg4);                       \
1382                 __syscall_regval(a5, "r7", arg5);                       \
1383                 __syscall_regval(a6, "r8", arg6);                       \
1384                                                                         \
1385                 __asm__ __volatile__ (                                  \
1386                         "sc" __comment(name) "\n\t"                     \
1387                         "mfcr %0"                                       \
1388                       : "=r"(__sc_r0), "=r"(__sc_a1)                    \
1389                       : "0"(__sc_r0),                                   \
1390                         "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1391                         "r"(__sc_a4), "r"(__sc_a5), "r"(__sc_a6)        \
1392                       : __syscall_clobbers                              \
1393                 );                                                      \
1394                 __sc_ret = __sc_a1;                                     \
1395                 __sc_err = __sc_r0;                                     \
1396         }                                                               \
1397         __syscall_return(type, __sc_ret, __sc_err);                     \
1398 }
1399
1400
1401 /*      *****************************************
1402         S390X   S390X   S390X   S390X           *
1403         s390x kernel interface                  */
1404
1405 #elif defined(__s390x__)
1406
1407 /*      The s390x calling convention passes the first five arguments
1408         in r2-r6, the remainder is spilled onto the stack. However 
1409         the Linux kernel passes the first six arguments in r2-r7.
1410         
1411         scnr:   imm, r1 
1412         args:   a1(r2), a2(r3), a3(r4), a4(r5), a5(r6), a6(r7)
1413         sret:   r2
1414         serr:   (err= sret > (unsigned)-EMAXERRNO)
1415         call:   svc
1416         clob:   memory
1417 */
1418
1419 #ifndef EMAXERRNO
1420 #define EMAXERRNO   4095
1421 #endif
1422
1423 #define __syscall_errcon(res)                                           \
1424         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
1425
1426 #define __syscall_return(type, res) do {                                \
1427         __syscall_retval(res);                                          \
1428         if (__syscall_errcon(res)) {                                    \
1429                 int __err = -(res);                                     \
1430                 __syscall_error(__err);                                 \
1431                 res = -1;                                               \
1432         }                                                               \
1433         return (type) res;                                              \
1434 } while (0)                             
1435
1436 #define __syscall_regdef(name, reg)                                     \
1437         register unsigned long __sc_##name __asm__ (reg)
1438
1439 #define __syscall_regval(name, reg, val)                                \
1440         register unsigned long __sc_##name __asm__ (reg) =              \
1441                 (unsigned long)(val)
1442
1443 #define __syscall_clobbers      "memory"
1444
1445
1446 #define _syscall0(type, name)                                           \
1447 type name(void)                                                         \
1448 {                                                                       \
1449         long __sc_res;                                                  \
1450         {                                                               \
1451                 __syscall_regval(nr, "r1", __NR_##name);                \
1452                 __syscall_regdef(a1, "r2");                             \
1453                                                                         \
1454                 __asm__ volatile (                                      \
1455                 __check("%0%1", "%%r2%%r1")                             \
1456                         "svc  0" __comment(name)                        \
1457                       : "=r"(__sc_a1)                                   \
1458                       : "r"(__sc_nr)                                    \
1459                       : __syscall_clobbers                              \
1460                 );                                                      \
1461                 __sc_res = __sc_a1;                                     \
1462         }                                                               \
1463         __syscall_return(type, __sc_res);                               \
1464 }
1465
1466 #define _syscall1(type, name, type1, arg1)                              \
1467 type name(type1 arg1)                                                   \
1468 {                                                                       \
1469         long __sc_res;                                                  \
1470         {                                                               \
1471                 __syscall_regval(nr, "r1", __NR_##name);                \
1472                 __syscall_regval(a1, "r2", arg1);                       \
1473                                                                         \
1474                 __asm__ volatile (                                      \
1475                 __check("%0%1%2", "%%r2%%r1%%r2")                       \
1476                         "svc  0" __comment(name)                        \
1477                       : "=r"(__sc_a1)                                   \
1478                       : "r"(__sc_nr),                                   \
1479                         "0"(__sc_a1)                                    \
1480                       : __syscall_clobbers                              \
1481                 );                                                      \
1482                 __sc_res = __sc_a1;                                     \
1483         }                                                               \
1484         __syscall_return(type, __sc_res);                               \
1485 }
1486
1487 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
1488 type name(type1 arg1, type2 arg2)                                       \
1489 {                                                                       \
1490         long __sc_res;                                                  \
1491         {                                                               \
1492                 __syscall_regval(nr, "r1", __NR_##name);                \
1493                 __syscall_regval(a1, "r2", arg1);                       \
1494                 __syscall_regval(a2, "r3", arg2);                       \
1495                                                                         \
1496                 __asm__ volatile (                                      \
1497                 __check("%0%1%2%3", "%%r2%%r1%%r2%%r3")                 \
1498                         "svc  0" __comment(name)                        \
1499                       : "=r"(__sc_a1)                                   \
1500                       : "r"(__sc_nr),                                   \
1501                         "0"(__sc_a1), "r"(__sc_a2)                      \
1502                       : __syscall_clobbers                              \
1503                 );                                                      \
1504                 __sc_res = __sc_a1;                                     \
1505         }                                                               \
1506         __syscall_return(type, __sc_res);                               \
1507 }
1508
1509 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
1510 type name(type1 arg1, type2 arg2, type3 arg3)                           \
1511 {                                                                       \
1512         long __sc_res;                                                  \
1513         {                                                               \
1514                 __syscall_regval(nr, "r1", __NR_##name);                \
1515                 __syscall_regval(a1, "r2", arg1);                       \
1516                 __syscall_regval(a2, "r3", arg2);                       \
1517                 __syscall_regval(a3, "r4", arg3);                       \
1518                                                                         \
1519                 __asm__ volatile (                                      \
1520                 __check("%0%1%2%3%4", "%%r2%%r1%%r2%%r3%%r4")           \
1521                         "svc  0" __comment(name)                        \
1522                       : "=r"(__sc_a1)                                   \
1523                       : "r"(__sc_nr),                                   \
1524                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3)        \
1525                       : __syscall_clobbers                              \
1526                 );                                                      \
1527                 __sc_res = __sc_a1;                                     \
1528         }                                                               \
1529         __syscall_return(type, __sc_res);                               \
1530
1531
1532 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1533                               type4, arg4)                              \
1534 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
1535 {                                                                       \
1536         long __sc_res;                                                  \
1537         {                                                               \
1538                 __syscall_regval(nr, "r1", __NR_##name);                \
1539                 __syscall_regval(a1, "r2", arg1);                       \
1540                 __syscall_regval(a2, "r3", arg2);                       \
1541                 __syscall_regval(a3, "r4", arg3);                       \
1542                 __syscall_regval(a4, "r5", arg4);                       \
1543                                                                         \
1544                 __asm__ volatile (                                      \
1545                 __check("%0%1%2%3%4%5", "%%r2%%r1%%r2%%r3%%r4%%r5")     \
1546                         "svc  0" __comment(name)                        \
1547                       : "=r"(__sc_a1)                                   \
1548                       : "r"(__sc_nr),                                   \
1549                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1550                         "r"(__sc_a4)                                    \
1551                       : __syscall_clobbers                              \
1552                 );                                                      \
1553                 __sc_res = __sc_a1;                                     \
1554         }                                                               \
1555         __syscall_return(type, __sc_res);                               \
1556
1557
1558 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1559                               type4, arg4, type5, arg5)                 \
1560 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
1561 {                                                                       \
1562         long __sc_res;                                                  \
1563         {                                                               \
1564                 __syscall_regval(nr, "r1", __NR_##name);                \
1565                 __syscall_regval(a1, "r2", arg1);                       \
1566                 __syscall_regval(a2, "r3", arg2);                       \
1567                 __syscall_regval(a3, "r4", arg3);                       \
1568                 __syscall_regval(a4, "r5", arg4);                       \
1569                 __syscall_regval(a5, "r6", arg5);                       \
1570                                                                         \
1571                 __asm__ volatile (                                      \
1572                 __check("%0%1%2%3%4%5%6",                               \
1573                         "%%r2%%r1%%r2%%r3%%r4%%r5%%r6")                 \
1574                         "svc  0" __comment(name)                        \
1575                       : "=r"(__sc_a1)                                   \
1576                       : "r"(__sc_nr),                                   \
1577                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1578                         "r"(__sc_a4), "r"(__sc_a5)                      \
1579                       : __syscall_clobbers                              \
1580                 );                                                      \
1581                 __sc_res = __sc_a1;                                     \
1582         }                                                               \
1583         __syscall_return(type, __sc_res);                               \
1584 }
1585
1586 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1587                         type4, arg4, type5, arg5, type6, arg6)          \
1588 type name (type1 arg1, type2 arg2, type3 arg3,                          \
1589            type4 arg4, type5 arg5, type6 arg6)                          \
1590 {                                                                       \
1591         long __sc_res;                                                  \
1592         {                                                               \
1593                 __syscall_regval(nr, "r1", __NR_##name);                \
1594                 __syscall_regval(a1, "r2", arg1);                       \
1595                 __syscall_regval(a2, "r3", arg2);                       \
1596                 __syscall_regval(a3, "r4", arg3);                       \
1597                 __syscall_regval(a4, "r5", arg4);                       \
1598                 __syscall_regval(a5, "r6", arg5);                       \
1599                 __syscall_regval(a6, "r7", arg6);                       \
1600                                                                         \
1601                 __asm__ volatile (                                      \
1602                 __check("%0%1%2%3%4%5%6%7",                             \
1603                         "%%r2%%r1%%r2%%r3%%r4%%r5%%r6%%r7")             \
1604                         "svc  0" __comment(name)                        \
1605                       : "=r"(__sc_a1)                                   \
1606                       : "r"(__sc_nr),                                   \
1607                         "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3),       \
1608                         "r"(__sc_a4), "r"(__sc_a5), "r"(__sc_a6)        \
1609                       : __syscall_clobbers                              \
1610                 );                                                      \
1611                 __sc_res = __sc_a1;                                     \
1612         }                                                               \
1613         __syscall_return(type, __sc_res);                               \
1614 }
1615
1616
1617
1618 /*      *****************************************
1619         S390    S390    S390    S390            *
1620         s390 kernel interface                   */
1621
1622 #elif defined(__s390__)
1623
1624 #warning syscall arch s390 not implemented yet
1625
1626
1627 /*      *****************************************
1628         SH      SH      SH      SH              *
1629         sh kernel interface                     */
1630
1631 #elif defined(__sh__) && !defined(__SH5__)
1632
1633 #warning syscall arch sh not implemented yet
1634
1635
1636 /*      *****************************************
1637         SH64    SH64    SH64    SH64            *
1638         sh64 kernel interface                   */
1639
1640 #elif defined(__sh__) && defined(__SH5__)
1641
1642 #warning syscall arch sh64 not implemented yet
1643
1644
1645 /*      *****************************************
1646         SPARC64 SPARC64 SPARC64 SPARC64         *
1647         sparc64 kernel interface                */
1648
1649 #elif defined(__sparc__) && defined(__arch64__)
1650
1651 /*      The sparc64 calling convention uses o0-o5 to pass the first six
1652         arguments (mapped via register windows).
1653         
1654         scnr:   g1
1655         args:   o0, o1, o2, o3, o4, o5 
1656         sret:   o0
1657         serr:   (carry)
1658         call:   t 0x10
1659         clob:   g1-g6, g7?, o7?, f0-f31, cc
1660 */
1661
1662 #ifndef EMAXERRNO
1663 #define EMAXERRNO   515
1664 #endif
1665
1666 #define __syscall_errcon(res)                                           \
1667         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
1668
1669 #define __syscall_return(type, res) do {                                \
1670         __syscall_retval(res);                                          \
1671         if (__syscall_errcon(res)) {                                    \
1672                 int __err = -(res);                                     \
1673                 __syscall_error(__err);                                 \
1674                 res = -1;                                               \
1675         }                                                               \
1676         return (type) res;                                              \
1677 } while (0)                             
1678
1679 #define __syscall_clobbers                                              \
1680         "g2", "g3", "g4", "g5", "g6",                                   \
1681         "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8",           \
1682         "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16",          \
1683         "f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24",         \
1684         "f25", "f26", "f27", "f28", "f29", "f30", "f31", "f32",         \
1685         "f34", "f36", "f38", "f40", "f42", "f44", "f46", "f48",         \
1686         "f50", "f52", "f54", "f56", "f58", "f60", "f62",                \
1687         "cc", "memory" 
1688
1689 #define __syscall_regdef(name, reg)                                     \
1690         register long __sc_##name __asm__ (reg)
1691
1692 #define __syscall_regval(name, reg, val)                                \
1693         register long __sc_##name __asm__ (reg) = (long)(val)
1694
1695 #define _syscall0(type, name)                                           \
1696 type name(void)                                                         \
1697 {                                                                       \
1698         long __sc_res;                                                  \
1699         {                                                               \
1700                 __syscall_regval(g1, "g1", __NR_##name);                \
1701                 __syscall_regdef(o0, "o0");                             \
1702                                                                         \
1703                 __asm__ volatile (                                      \
1704                         "ta 0x6d" __comment(name) "\n\t"                \
1705                         "bcs,a,pt %%xcc,1f\n\t"                         \
1706                         "sub %%g0,%%o0,%%o0\n"                          \
1707                         "1:"                                            \
1708                       : "=r"(__sc_o0)                                   \
1709                       : "r"(__sc_g1)                                    \
1710                       : __syscall_clobbers                              \
1711                 );                                                      \
1712                 __sc_res = __sc_o0;                                     \
1713         }                                                               \
1714         __syscall_return(type, __sc_res);                               \
1715 }
1716
1717 #define _syscall1(type, name, type1, arg1)                              \
1718 type name(type1 arg1)                                                   \
1719 {                                                                       \
1720         long __sc_res;                                                  \
1721         {                                                               \
1722                 __syscall_regval(g1, "g1", __NR_##name);                \
1723                 __syscall_regval(o0, "o0", arg1);                       \
1724                                                                         \
1725                 __asm__ volatile (                                      \
1726                         "ta 0x6d" __comment(name) "\n\t"                \
1727                         "bcs,a,pt %%xcc,1f\n\t"                         \
1728                         "sub %%g0,%%o0,%%o0\n"                          \
1729                         "1:"                                            \
1730                       : "=r"(__sc_o0)                                   \
1731                       : "r"(__sc_g1),                                   \
1732                         "0"(__sc_o0)                                    \
1733                       : __syscall_clobbers                              \
1734                 );                                                      \
1735                 __sc_res = __sc_o0;                                     \
1736         }                                                               \
1737         __syscall_return(type, __sc_res);                               \
1738 }
1739
1740 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
1741 type name(type1 arg1, type2 arg2)                                       \
1742 {                                                                       \
1743         long __sc_res;                                                  \
1744         {                                                               \
1745                 __syscall_regval(g1, "g1", __NR_##name);                \
1746                 __syscall_regval(o0, "o0", arg1);                       \
1747                 __syscall_regval(o1, "o1", arg2);                       \
1748                                                                         \
1749                 __asm__ volatile (                                      \
1750                         "ta 0x6d" __comment(name) "\n\t"                \
1751                         "bcs,a,pt %%xcc,1f\n\t"                         \
1752                         "sub %%g0,%%o0,%%o0\n"                          \
1753                         "1:"                                            \
1754                       : "=r"(__sc_o0)                                   \
1755                       : "r"(__sc_g1),                                   \
1756                         "0"(__sc_o0), "r"(__sc_o1)                      \
1757                       : __syscall_clobbers                              \
1758                 );                                                      \
1759                 __sc_res = __sc_o0;                                     \
1760         }                                                               \
1761         __syscall_return(type, __sc_res);                               \
1762 }
1763
1764 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
1765 type name(type1 arg1, type2 arg2, type3 arg3)                           \
1766 {                                                                       \
1767         long __sc_res;                                                  \
1768         {                                                               \
1769                 __syscall_regval(g1, "g1", __NR_##name);                \
1770                 __syscall_regval(o0, "o0", arg1);                       \
1771                 __syscall_regval(o1, "o1", arg2);                       \
1772                 __syscall_regval(o2, "o2", arg3);                       \
1773                                                                         \
1774                 __asm__ volatile (                                      \
1775                         "ta 0x6d" __comment(name) "\n\t"                \
1776                         "bcs,a,pt %%xcc,1f\n\t"                         \
1777                         "sub %%g0,%%o0,%%o0\n"                          \
1778                         "1:"                                            \
1779                       : "=r"(__sc_o0)                                   \
1780                       : "r"(__sc_g1),                                   \
1781                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2)        \
1782                       : __syscall_clobbers                              \
1783                 );                                                      \
1784                 __sc_res = __sc_o0;                                     \
1785         }                                                               \
1786         __syscall_return(type, __sc_res);                               \
1787
1788
1789 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1790                               type4, arg4)                              \
1791 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
1792 {                                                                       \
1793         long __sc_res;                                                  \
1794         {                                                               \
1795                 __syscall_regval(g1, "g1", __NR_##name);                \
1796                 __syscall_regval(o0, "o0", arg1);                       \
1797                 __syscall_regval(o1, "o1", arg2);                       \
1798                 __syscall_regval(o2, "o2", arg3);                       \
1799                 __syscall_regval(o3, "o3", arg4);                       \
1800                                                                         \
1801                 __asm__ volatile (                                      \
1802                         "ta 0x6d" __comment(name) "\n\t"                \
1803                         "bcs,a,pt %%xcc,1f\n\t"                         \
1804                         "sub %%g0,%%o0,%%o0\n"                          \
1805                         "1:"                                            \
1806                       : "=r"(__sc_o0)                                   \
1807                       : "r"(__sc_g1),                                   \
1808                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2),       \
1809                         "r"(__sc_o3)                                    \
1810                       : __syscall_clobbers                              \
1811                 );                                                      \
1812                 __sc_res = __sc_o0;                                     \
1813         }                                                               \
1814         __syscall_return(type, __sc_res);                               \
1815
1816
1817 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1818                               type4, arg4, type5, arg5)                 \
1819 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
1820 {                                                                       \
1821         long __sc_res;                                                  \
1822         {                                                               \
1823                 __syscall_regval(g1, "g1", __NR_##name);                \
1824                 __syscall_regval(o0, "o0", arg1);                       \
1825                 __syscall_regval(o1, "o1", arg2);                       \
1826                 __syscall_regval(o2, "o2", arg3);                       \
1827                 __syscall_regval(o3, "o3", arg4);                       \
1828                 __syscall_regval(o4, "o4", arg5);                       \
1829                                                                         \
1830                 __asm__ volatile (                                      \
1831                         "ta 0x6d" __comment(name) "\n\t"                \
1832                         "bcs,a,pt %%xcc,1f\n\t"                         \
1833                         "sub %%g0,%%o0,%%o0\n"                          \
1834                         "1:"                                            \
1835                       : "=r"(__sc_o0)                                   \
1836                       : "r"(__sc_g1),                                   \
1837                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2),       \
1838                         "r"(__sc_o3), "r"(__sc_o4)                      \
1839                       : __syscall_clobbers                              \
1840                 );                                                      \
1841                 __sc_res = __sc_o0;                                     \
1842         }                                                               \
1843         __syscall_return(type, __sc_res);                               \
1844 }
1845
1846 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1847                         type4, arg4, type5, arg5, type6, arg6)          \
1848 type name (type1 arg1, type2 arg2, type3 arg3,                          \
1849            type4 arg4, type5 arg5, type6 arg6)                          \
1850 {                                                                       \
1851         long __sc_res;                                                  \
1852         {                                                               \
1853                 __syscall_regval(g1, "g1", __NR_##name);                \
1854                 __syscall_regval(o0, "o0", arg1);                       \
1855                 __syscall_regval(o1, "o1", arg2);                       \
1856                 __syscall_regval(o2, "o2", arg3);                       \
1857                 __syscall_regval(o3, "o3", arg4);                       \
1858                 __syscall_regval(o4, "o4", arg5);                       \
1859                 __syscall_regval(o5, "o5", arg6);                       \
1860                                                                         \
1861                 __asm__ volatile (                                      \
1862                         "ta 0x6d" __comment(name) "\n\t"                \
1863                         "bcs,a,pt %%xcc,1f\n\t"                         \
1864                         "sub %%g0,%%o0,%%o0\n"                          \
1865                         "1:"                                            \
1866                       : "=r"(__sc_o0)                                   \
1867                       : "r"(__sc_g1),                                   \
1868                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2),       \
1869                         "r"(__sc_o3), "r"(__sc_o4), "r"(__sc_o5)        \
1870                       : __syscall_clobbers                              \
1871                 );                                                      \
1872                 __sc_res = __sc_o0;                                     \
1873         }                                                               \
1874         __syscall_return(type, __sc_res);                               \
1875 }
1876
1877
1878 /*      *****************************************
1879         SPARC   SPARC   SPARC   SPARC           *
1880         sparc kernel interface                  */
1881
1882 #elif defined(__sparc__)
1883
1884 /*      The sparc calling convention uses o0-o5 to pass the first six
1885         arguments (mapped via register windows).
1886         
1887         scnr:   g1
1888         args:   o0, o1, o2, o3, o4, o5 
1889         sret:   o0
1890         serr:   (carry)
1891         call:   t 0x10
1892         clob:   g1-g6, g7?, o7?, f0-f31, cc
1893 */
1894
1895 #ifndef EMAXERRNO
1896 #define EMAXERRNO   515
1897 #endif
1898
1899 #define __syscall_errcon(res)                                           \
1900         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
1901
1902 #define __syscall_return(type, res) do {                                \
1903         __syscall_retval(res);                                          \
1904         if (__syscall_errcon(res)) {                                    \
1905                 int __err = -(res);                                     \
1906                 __syscall_error(__err);                                 \
1907                 res = -1;                                               \
1908         }                                                               \
1909         return (type) res;                                              \
1910 } while (0)                             
1911
1912 #define __syscall_clobbers                                              \
1913         "g2", "g3", "g4", "g5", "g6",                                   \
1914         "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8",           \
1915         "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16",          \
1916         "f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24",         \
1917         "f25", "f26", "f27", "f28", "f29", "f30", "f31",                \
1918         "cc", "memory" 
1919
1920 #define __syscall_regdef(name, reg)                                     \
1921         register long __sc_##name __asm__ (reg)
1922
1923 #define __syscall_regval(name, reg, val)                                \
1924         register long __sc_##name __asm__ (reg) = (long)(val)
1925
1926 #define _syscall0(type, name)                                           \
1927 type name(void)                                                         \
1928 {                                                                       \
1929         long __sc_res;                                                  \
1930         {                                                               \
1931                 __syscall_regval(g1, "g1", __NR_##name);                \
1932                 __syscall_regdef(o0, "o0");                             \
1933                                                                         \
1934                 __asm__ volatile (                                      \
1935                         "t 0x10" __comment(name) "\n\t"                 \
1936                         "bcs,a 1f\n\t"                                  \
1937                         "sub %%g0,%%o0,%%o0\n"                          \
1938                         "1:"                                            \
1939                       : "=r"(__sc_o0)                                   \
1940                       : "r"(__sc_g1)                                    \
1941                       : __syscall_clobbers                              \
1942                 );                                                      \
1943                 __sc_res = __sc_o0;                                     \
1944         }                                                               \
1945         __syscall_return(type, __sc_res);                               \
1946 }
1947
1948 #define _syscall1(type, name, type1, arg1)                              \
1949 type name(type1 arg1)                                                   \
1950 {                                                                       \
1951         long __sc_res;                                                  \
1952         {                                                               \
1953                 __syscall_regval(g1, "g1", __NR_##name);                \
1954                 __syscall_regval(o0, "o0", arg1);                       \
1955                                                                         \
1956                 __asm__ volatile (                                      \
1957                         "t 0x10" __comment(name) "\n\t"                 \
1958                         "bcs,a 1f\n\t"                                  \
1959                         "sub %%g0,%%o0,%%o0\n"                          \
1960                         "1:"                                            \
1961                       : "=r"(__sc_o0)                                   \
1962                       : "r"(__sc_g1),                                   \
1963                         "0"(__sc_o0)                                    \
1964                       : __syscall_clobbers                              \
1965                 );                                                      \
1966                 __sc_res = __sc_o0;                                     \
1967         }                                                               \
1968         __syscall_return(type, __sc_res);                               \
1969 }
1970
1971 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
1972 type name(type1 arg1, type2 arg2)                                       \
1973 {                                                                       \
1974         long __sc_res;                                                  \
1975         {                                                               \
1976                 __syscall_regval(g1, "g1", __NR_##name);                \
1977                 __syscall_regval(o0, "o0", arg1);                       \
1978                 __syscall_regval(o1, "o1", arg2);                       \
1979                                                                         \
1980                 __asm__ volatile (                                      \
1981                         "t 0x10" __comment(name) "\n\t"                 \
1982                         "bcs,a 1f\n\t"                                  \
1983                         "sub %%g0,%%o0,%%o0\n"                          \
1984                         "1:"                                            \
1985                       : "=r"(__sc_o0)                                   \
1986                       : "r"(__sc_g1),                                   \
1987                         "0"(__sc_o0), "r"(__sc_o1)                      \
1988                       : __syscall_clobbers                              \
1989                 );                                                      \
1990                 __sc_res = __sc_o0;                                     \
1991         }                                                               \
1992         __syscall_return(type, __sc_res);                               \
1993 }
1994
1995 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
1996 type name(type1 arg1, type2 arg2, type3 arg3)                           \
1997 {                                                                       \
1998         long __sc_res;                                                  \
1999         {                                                               \
2000                 __syscall_regval(g1, "g1", __NR_##name);                \
2001                 __syscall_regval(o0, "o0", arg1);                       \
2002                 __syscall_regval(o1, "o1", arg2);                       \
2003                 __syscall_regval(o2, "o2", arg3);                       \
2004                                                                         \
2005                 __asm__ volatile (                                      \
2006                         "t 0x10" __comment(name) "\n\t"                 \
2007                         "bcs,a 1f\n\t"                                  \
2008                         "sub %%g0,%%o0,%%o0\n"                          \
2009                         "1:"                                            \
2010                       : "=r"(__sc_o0)                                   \
2011                       : "r"(__sc_g1),                                   \
2012                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2)        \
2013                       : __syscall_clobbers                              \
2014                 );                                                      \
2015                 __sc_res = __sc_o0;                                     \
2016         }                                                               \
2017         __syscall_return(type, __sc_res);                               \
2018
2019
2020 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
2021                               type4, arg4)                              \
2022 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
2023 {                                                                       \
2024         long __sc_res;                                                  \
2025         {                                                               \
2026                 __syscall_regval(g1, "g1", __NR_##name);                \
2027                 __syscall_regval(o0, "o0", arg1);                       \
2028                 __syscall_regval(o1, "o1", arg2);                       \
2029                 __syscall_regval(o2, "o2", arg3);                       \
2030                 __syscall_regval(o3, "o3", arg4);                       \
2031                                                                         \
2032                 __asm__ volatile (                                      \
2033                         "t 0x10" __comment(name) "\n\t"                 \
2034                         "bcs,a 1f\n\t"                                  \
2035                         "sub %%g0,%%o0,%%o0\n"                          \
2036                         "1:"                                            \
2037                       : "=r"(__sc_o0)                                   \
2038                       : "r"(__sc_g1),                                   \
2039                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2),       \
2040                         "r"(__sc_o3)                                    \
2041                       : __syscall_clobbers                              \
2042                 );                                                      \
2043                 __sc_res = __sc_o0;                                     \
2044         }                                                               \
2045         __syscall_return(type, __sc_res);                               \
2046
2047
2048 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
2049                               type4, arg4, type5, arg5)                 \
2050 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
2051 {                                                                       \
2052         long __sc_res;                                                  \
2053         {                                                               \
2054                 __syscall_regval(g1, "g1", __NR_##name);                \
2055                 __syscall_regval(o0, "o0", arg1);                       \
2056                 __syscall_regval(o1, "o1", arg2);                       \
2057                 __syscall_regval(o2, "o2", arg3);                       \
2058                 __syscall_regval(o3, "o3", arg4);                       \
2059                 __syscall_regval(o4, "o4", arg5);                       \
2060                                                                         \
2061                 __asm__ volatile (                                      \
2062                         "t 0x10" __comment(name) "\n\t"                 \
2063                         "bcs,a 1f\n\t"                                  \
2064                         "sub %%g0,%%o0,%%o0\n"                          \
2065                         "1:"                                            \
2066                       : "=r"(__sc_o0)                                   \
2067                       : "r"(__sc_g1),                                   \
2068                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2),       \
2069                         "r"(__sc_o3), "r"(__sc_o4)                      \
2070                       : __syscall_clobbers                              \
2071                 );                                                      \
2072                 __sc_res = __sc_o0;                                     \
2073         }                                                               \
2074         __syscall_return(type, __sc_res);                               \
2075 }
2076
2077 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
2078                         type4, arg4, type5, arg5, type6, arg6)          \
2079 type name (type1 arg1, type2 arg2, type3 arg3,                          \
2080            type4 arg4, type5 arg5, type6 arg6)                          \
2081 {                                                                       \
2082         long __sc_res;                                                  \
2083         {                                                               \
2084                 __syscall_regval(g1, "g1", __NR_##name);                \
2085                 __syscall_regval(o0, "o0", arg1);                       \
2086                 __syscall_regval(o1, "o1", arg2);                       \
2087                 __syscall_regval(o2, "o2", arg3);                       \
2088                 __syscall_regval(o3, "o3", arg4);                       \
2089                 __syscall_regval(o4, "o4", arg5);                       \
2090                 __syscall_regval(o5, "o5", arg6);                       \
2091                                                                         \
2092                 __asm__ volatile (                                      \
2093                 __check("%0%1%2%3%4%5", "$o0$g1$o0$o1$o2$o3$o4$o5$o6")  \
2094                         "t 0x10" __comment(name) "\n\t"                 \
2095                         "bcs,a 1f\n\t"                                  \
2096                         "sub %%g0,%%o0,%%o0\n"                          \
2097                         "1:"                                            \
2098                       : "=r"(__sc_o0)                                   \
2099                       : "r"(__sc_g1),                                   \
2100                         "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2),       \
2101                         "r"(__sc_o3), "r"(__sc_o4), "r"(__sc_o5)        \
2102                       : __syscall_clobbers                              \
2103                 );                                                      \
2104                 __sc_res = __sc_o0;                                     \
2105         }                                                               \
2106         __syscall_return(type, __sc_res);                               \
2107 }
2108
2109
2110 /*      *****************************************
2111         V850    V850    V850    V850            *
2112         v850 kernel interface                   */
2113
2114 #elif defined(__v850__)
2115
2116 #warning syscall arch v850 not implemented yet
2117
2118
2119 /*      *****************************************
2120         X86_64  X86_64  X86_64  X86_64          *
2121         x86_64 kernel interface                 */
2122
2123 #elif defined(__x86_64__)
2124
2125 /*      The x86_64 calling convention uses rdi, rsi, rdx, rcx, r8, r9
2126         but the Linux kernel interface uses rdi, rsi, rdx, r10, r8, r9.
2127         
2128         scnr:   a0(rax)
2129         args:   a1(rdi), a2(rsi), a3(rdx), a4(r10), a5(r8), a6(r9) 
2130         sret:   a0(rax)
2131         serr:   (err= sret > (unsigned)-EMAXERRNO)
2132         call:   syscall
2133         clob:   rcx, r11
2134 */
2135
2136 #ifndef EMAXERRNO
2137 #define EMAXERRNO   4095
2138 #endif
2139
2140 #define __syscall_errcon(res)                                           \
2141         ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
2142
2143 #define __syscall_return(type, res) do {                                \
2144         __syscall_retval(res);                                          \
2145         if (__syscall_errcon(res)) {                                    \
2146                 int __err = -(res);                                     \
2147                 __syscall_error(__err);                                 \
2148                 res = -1;                                               \
2149         }                                                               \
2150         return (type) res;                                              \
2151 } while (0)                             
2152
2153 #define __syscall_clobbers                                              \
2154         "cc", "r11", "rcx", "memory" 
2155
2156 #define __syscall_regdef(name, reg)                                     \
2157         register long __sc_##name __asm__ (reg)
2158
2159 #define __syscall_regval(name, reg, val)                                \
2160         register long __sc_##name __asm__ (reg) = (long)(val)
2161
2162
2163 #define _syscall0(type, name)                                           \
2164 type name(void)                                                         \
2165 {                                                                       \
2166         long __sc_res;                                                  \
2167         {                                                               \
2168                 __syscall_regval(a0, "rax", __NR_##name);               \
2169                                                                         \
2170                 __asm__ volatile (                                      \
2171                 __check("%0%1", "%%rax%%rax")                           \
2172                         "syscall" __comment(name)                       \
2173                       : "=a"(__sc_a0)                                   \
2174                       : "0"(__sc_a0)                                    \
2175                       : __syscall_clobbers                              \
2176                 );                                                      \
2177                 __sc_res = __sc_a0;                                     \
2178         }                                                               \
2179         __syscall_return(type, __sc_res);                               \
2180 }
2181
2182 #define _syscall1(type, name, type1, arg1)                              \
2183 type name(type1 arg1)                                                   \
2184 {                                                                       \
2185         long __sc_res;                                                  \
2186         {                                                               \
2187                 __syscall_regval(a0, "rax", __NR_##name);               \
2188                 __syscall_regval(a1, "rdi", arg1);                      \
2189                                                                         \
2190                 __asm__ volatile (                                      \
2191                 __check("%0%1%2", "%%rax%%rax%%rdi")                    \
2192                         "syscall" __comment(name)                       \
2193                       : "=a"(__sc_a0)                                   \
2194                       : "0"(__sc_a0),                                   \
2195                         "r" (__sc_a1)                                   \
2196                       : __syscall_clobbers                              \
2197                 );                                                      \
2198                 __sc_res = __sc_a0;                                     \
2199         }                                                               \
2200         __syscall_return(type, __sc_res);                               \
2201 }
2202
2203 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
2204 type name(type1 arg1, type2 arg2)                                       \
2205 {                                                                       \
2206         long __sc_res;                                                  \
2207         {                                                               \
2208                 __syscall_regval(a0, "rax", __NR_##name);               \
2209                 __syscall_regval(a1, "rdi", arg1);                      \
2210                 __syscall_regval(a2, "rsi", arg2);                      \
2211                                                                         \
2212                 __asm__ volatile (                                      \
2213                 __check("%0%1%2%3", "%%rax%%rax%%rdi%%rsi")             \
2214                         "syscall" __comment(name)                       \
2215                       : "=a"(__sc_a0)                                   \
2216                       : "0"(__sc_a0),                                   \
2217                         "r" (__sc_a1), "r"(__sc_a2)                     \
2218                       : __syscall_clobbers                              \
2219                 );                                                      \
2220                 __sc_res = __sc_a0;                                     \
2221         }                                                               \
2222         __syscall_return(type, __sc_res);                               \
2223 }
2224
2225 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
2226 type name(type1 arg1, type2 arg2, type3 arg3)                           \
2227 {                                                                       \
2228         long __sc_res;                                                  \
2229         {                                                               \
2230                 __syscall_regval(a0, "rax", __NR_##name);               \
2231                 __syscall_regval(a1, "rdi", arg1);                      \
2232                 __syscall_regval(a2, "rsi", arg2);                      \
2233                 __syscall_regval(a3, "rdx", arg3);                      \
2234                                                                         \
2235                 __asm__ volatile (                                      \
2236                 __check("%0%1%2%3%4", "%%rax%%rax%%rdi%%rsi%%rdx")      \
2237                         "syscall" __comment(name)                       \
2238                       : "=a"(__sc_a0)                                   \
2239                       : "0"(__sc_a0),                                   \
2240                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3)      \
2241                       : __syscall_clobbers                              \
2242                 );                                                      \
2243                 __sc_res = __sc_a0;                                     \
2244         }                                                               \
2245         __syscall_return(type, __sc_res);                               \
2246
2247
2248
2249 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
2250                               type4, arg4)                              \
2251 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4)              \
2252 {                                                                       \
2253         long __sc_res;                                                  \
2254         {                                                               \
2255                 __syscall_regval(a0, "rax", __NR_##name);               \
2256                 __syscall_regval(a1, "rdi", arg1);                      \
2257                 __syscall_regval(a2, "rsi", arg2);                      \
2258                 __syscall_regval(a3, "rdx", arg3);                      \
2259                 __syscall_regval(a4, "r10", arg4);                      \
2260                                                                         \
2261                 __asm__ volatile (                                      \
2262                 __check("%0%1%2%3%4%5",                                 \
2263                         "%%rax%%rax%%rdi%%rsi%%rdx%%r10")               \
2264                         "syscall" __comment(name)                       \
2265                       : "=a"(__sc_a0)                                   \
2266                       : "0"(__sc_a0),                                   \
2267                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3),     \
2268                         "r" (__sc_a4)                                   \
2269                       : __syscall_clobbers                              \
2270                 );                                                      \
2271                 __sc_res = __sc_a0;                                     \
2272         }                                                               \
2273         __syscall_return(type, __sc_res);                               \
2274
2275
2276 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
2277                               type4, arg4, type5, arg5)                 \
2278 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)  \
2279 {                                                                       \
2280         long __sc_res;                                                  \
2281         {                                                               \
2282                 __syscall_regval(a0, "rax", __NR_##name);               \
2283                 __syscall_regval(a1, "rdi", arg1);                      \
2284                 __syscall_regval(a2, "rsi", arg2);                      \
2285                 __syscall_regval(a3, "rdx", arg3);                      \
2286                 __syscall_regval(a4, "r10", arg4);                      \
2287                 __syscall_regval(a5, "r8", arg5);                       \
2288                                                                         \
2289                 __asm__ volatile (                                      \
2290                 __check("%0%1%2%3%4%5%6",                               \
2291                         "%%rax%%rax%%rdi%%rsi%%rdx%%r10%%r8")           \
2292                         "syscall" __comment(name)                       \
2293                       : "=a"(__sc_a0)                                   \
2294                       : "0"(__sc_a0),                                   \
2295                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3),     \
2296                         "r" (__sc_a4), "r"(__sc_a5)                     \
2297                       : __syscall_clobbers                              \
2298                 );                                                      \
2299                 __sc_res = __sc_a0;                                     \
2300         }                                                               \
2301         __syscall_return(type, __sc_res);                               \
2302 }
2303
2304 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
2305                         type4, arg4, type5, arg5, type6, arg6)          \
2306 type name (type1 arg1, type2 arg2, type3 arg3,                          \
2307            type4 arg4, type5 arg5, type6 arg6)                          \
2308 {                                                                       \
2309         long __sc_res;                                                  \
2310         {                                                               \
2311                 __syscall_regval(a0, "rax", __NR_##name);               \
2312                 __syscall_regval(a1, "rdi", arg1);                      \
2313                 __syscall_regval(a2, "rsi", arg2);                      \
2314                 __syscall_regval(a3, "rdx", arg3);                      \
2315                 __syscall_regval(a4, "r10", arg4);                      \
2316                 __syscall_regval(a5, "r8", arg5);                       \
2317                 __syscall_regval(a6, "r9", arg6);                       \
2318                                                                         \
2319                 __asm__ volatile (                                      \
2320                 __check("%0%1%2%3%4%5%6%7",                             \
2321                         "%%rax%%rax%%rdi%%rsi%%rdx%%r10%%r8%%r9")       \
2322                         "syscall" __comment(name)                       \
2323                       : "=a"(__sc_a0)                                   \
2324                       : "0"(__sc_a0),                                   \
2325                         "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3),     \
2326                         "r" (__sc_a4), "r"(__sc_a5), "r" (__sc_a6)      \
2327                       : __syscall_clobbers                              \
2328                 );                                                      \
2329                 __sc_res = __sc_a0;                                     \
2330         }                                                               \
2331         __syscall_return(type, __sc_res);                               \
2332 }
2333
2334
2335 #endif
2336