2 #ifndef __syscall_retval
3 #define __syscall_retval(v) do { } while(0)
6 #ifndef __syscall_error
7 #define __syscall_error(e) do { errno = (e); } while(0)
10 #define __check(pos, reg) \
11 ".ifnc " pos ", " reg "\n\t" \
16 #define __stringify0(val) #val
20 #define __stringify(val) __stringify0(val)
23 #define __comment(name) \
24 "\t/* kernel sys_" #name "[" __stringify(__NR_##name) "] */"
27 /* *****************************************
28 ALPHA ALPHA ALPHA ALPHA *
29 alpha kernel interface */
31 #if defined(__alpha__)
33 /* The Alpha calling convention doesn't use the stack until
34 after the first six arguments have been passed in registers.
37 args: a0($16), a1($17), a2($18), a3($19), a4($20), a5($21)
39 serr: a3($19) (!=0, err=sret)
43 #define __syscall_return(type, ret, err) do { \
44 __syscall_retval(ret); \
47 __syscall_error(__err); \
53 #define __syscall_regdef(name, reg) \
54 register long __sc_##name __asm__ (reg)
56 #define __syscall_regval(name, reg, val) \
57 register long __sc_##name __asm__ (reg) = (long)(val)
59 #define __syscall_clobbers \
60 "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
61 "$22", "$23", "$24", "$25", "$27", "$28", "memory" \
64 #define _syscall0(type, name) \
67 long __sc_ret, __sc_err; \
69 __syscall_regval(v0, "$0", __NR_##name); \
70 __syscall_regdef(a3, "$19"); \
72 __asm__ __volatile__ ( \
73 __check("%0%1%2", "$0$19$0") \
74 "callsys" __comment(name) \
75 : "=r"(__sc_v0), "=r"(__sc_a3) \
77 : "$16", "$17", "$18", "$20", "$21", \
83 __syscall_return(type, __sc_ret, __sc_err); \
86 #define _syscall1(type, name, type1, arg1) \
87 type name(type1 arg1) \
89 long __sc_ret, __sc_err; \
91 __syscall_regval(v0, "$0", __NR_##name); \
92 __syscall_regval(a0, "$16", arg1); \
93 __syscall_regdef(a3, "$19"); \
95 __asm__ __volatile__ ( \
96 __check("%0%1%2%3", "$0$19$0$16") \
97 "callsys" __comment(name) \
98 : "=r"(__sc_v0), "=r"(__sc_a3) \
101 : "$17", "$18", "$20", "$21", \
104 __sc_ret = __sc_v0; \
105 __sc_err = __sc_a3; \
107 __syscall_return(type, __sc_ret, __sc_err); \
110 #define _syscall2(type, name, type1, arg1, type2, arg2) \
111 type name(type1 arg1, type2 arg2) \
113 long __sc_ret, __sc_err; \
115 __syscall_regval(v0, "$0", __NR_##name); \
116 __syscall_regval(a0, "$16", arg1); \
117 __syscall_regval(a1, "$17", arg2); \
118 __syscall_regdef(a3, "$19"); \
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) \
125 "r"(__sc_a0), "r"(__sc_a1) \
126 : "$18", "$20", "$21", \
129 __sc_ret = __sc_v0; \
130 __sc_err = __sc_a3; \
132 __syscall_return(type, __sc_ret, __sc_err); \
135 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
136 type name(type1 arg1, type2 arg2, type3 arg3) \
138 long __sc_ret, __sc_err; \
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"); \
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) \
151 "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2) \
155 __sc_ret = __sc_v0; \
156 __sc_err = __sc_a3; \
158 __syscall_return(type, __sc_ret, __sc_err); \
161 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
163 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
165 long __sc_ret, __sc_err; \
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); \
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) \
178 "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2), \
183 __sc_ret = __sc_v0; \
184 __sc_err = __sc_a3; \
186 __syscall_return(type, __sc_ret, __sc_err); \
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) \
193 long __sc_ret, __sc_err; \
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); \
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) \
207 "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2), \
208 "1"(__sc_a3), "r"(__sc_a4) \
212 __sc_ret = __sc_v0; \
213 __sc_err = __sc_a3; \
215 __syscall_return(type, __sc_ret, __sc_err); \
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) \
223 long __sc_ret, __sc_err; \
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); \
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) \
239 "r"(__sc_a0), "r"(__sc_a1), "r"(__sc_a2), \
240 "1"(__sc_a3), "r"(__sc_a4), "r"(__sc_a5) \
241 : __syscall_clobbers \
243 __sc_ret = __sc_v0; \
244 __sc_err = __sc_a3; \
246 __syscall_return(type, __sc_ret, __sc_err); \
251 /* *****************************************
253 arm kernel interface */
255 #elif defined(__arm__)
257 /* The Arm calling convention uses stack args after four arguments
258 but the Linux kernel gets up to seven arguments in registers.
261 args: a1(r0), a2(r1), a3(r2), a4(r3), v1(r4), v2(r5),
263 serr: (err= sret > (unsigned)-EMAXERRNO)
267 #define EMAXERRNO 125
270 #define __syscall_errcon(res) \
271 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
273 #define __syscall_return(type, res) do { \
274 __syscall_retval(res); \
275 if (__syscall_errcon(res)) { \
276 int __err = -(res); \
277 __syscall_error(__err); \
283 #define __syscall_regdef(name, reg) \
284 register int __sc_##name __asm__ (reg)
286 #define __syscall_regval(name, reg, val) \
287 register int __sc_##name __asm__ (reg) = (int)(val)
290 #define _syscall0(type, name) \
295 __syscall_regdef(a1, "r0"); \
297 __asm__ __volatile__ ( \
298 __check("%0", "r0") \
299 "swi %1" __comment(name) \
304 __sc_res = __sc_a1; \
306 __syscall_return(type, __sc_res); \
309 #define _syscall1(type, name, type1, arg1) \
310 type name(type1 arg1) \
314 __syscall_regval(a1, "r0", arg1); \
316 __asm__ __volatile__ ( \
317 __check("%0%2", "r0r0") \
318 "swi %1" __comment(name) \
320 : "i"(__NR_##name), \
324 __sc_res = __sc_a1; \
326 __syscall_return(type, __sc_res); \
329 #define _syscall2(type, name, type1, arg1, type2, arg2) \
330 type name(type1 arg1, type2 arg2) \
334 __syscall_regval(a1, "r0", arg1); \
335 __syscall_regval(a2, "r1", arg2); \
337 __asm__ __volatile__ ( \
338 __check("%0%2%3", "r0r0r1") \
339 "swi %1" __comment(name) \
341 : "i"(__NR_##name), \
342 "0"(__sc_a1), "r"(__sc_a2) \
345 __sc_res = __sc_a1; \
347 __syscall_return(type, __sc_res); \
350 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
351 type name(type1 arg1, type2 arg2, type3 arg3) \
355 __syscall_regval(a1, "r0", arg1); \
356 __syscall_regval(a2, "r1", arg2); \
357 __syscall_regval(a3, "r2", arg3); \
359 __asm__ __volatile__ ( \
360 __check("%0%2%3%4", "r0r0r1r2") \
361 "swi %1" __comment(name) \
363 : "i"(__NR_##name), \
364 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3) \
367 __sc_res = __sc_a1; \
369 __syscall_return(type, __sc_res); \
372 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
374 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
378 __syscall_regval(a1, "r0", arg1); \
379 __syscall_regval(a2, "r1", arg2); \
380 __syscall_regval(a3, "r2", arg3); \
381 __syscall_regval(a4, "r3", arg4); \
383 __asm__ __volatile__ ( \
384 __check("%0%2%3%4%5", "r0r0r1r2r3") \
385 "swi %1" __comment(name) \
387 : "i"(__NR_##name), \
388 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
392 __sc_res = __sc_a1; \
394 __syscall_return(type, __sc_res); \
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) \
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); \
409 __asm__ __volatile__ ( \
410 __check("%0%2%3%4%5%6", "r0r0r1r2r3r4") \
411 "swi %1" __comment(name) \
413 : "i"(__NR_##name), \
414 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
415 "r"(__sc_a4), "r"(__sc_v1) \
418 __sc_res = __sc_a1; \
420 __syscall_return(type, __sc_res); \
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) \
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); \
437 __asm__ __volatile__ ( \
438 __check("%0%2%3%4%5%6%7", "r0r0r1r2r3r4r5") \
439 "swi %1" __comment(name) \
441 : "i"(__NR_##name), \
442 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
443 "r"(__sc_a4), "r"(__sc_v1), "r"(__sc_v2) \
446 __sc_res = __sc_a1; \
448 __syscall_return(type, __sc_res); \
452 /* *****************************************
453 CRIS CRIS CRIS CRIS *
454 cris v10 kernel interface */
456 #elif defined(__cris__)
458 /* The Cris calling convention uses stack args after four arguments
459 but the Linux kernel gets up to six arguments in registers.
462 args: (r10), (r11), (r12), (r13), (mof), (srp),
464 serr: (err= sret > (unsigned)-EMAXERRNO)
468 #define EMAXERRNO 125
471 #define __syscall_errcon(res) \
472 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
474 #define __syscall_return(type, res) do { \
475 __syscall_retval(res); \
476 if (__syscall_errcon(res)) { \
477 int __err = -(res); \
478 __syscall_error(__err); \
484 #define __syscall_regdef(name, reg) \
485 register long __sc_##name __asm__ (reg)
487 #define __syscall_regval(name, reg, val) \
488 register long __sc_##name __asm__ (reg) = (long)(val)
490 #define _syscall0(type, name) \
495 __syscall_regval(a0, "r9", __NR_##name); \
496 __syscall_regdef(a1, "r10"); \
498 __asm__ __volatile__ ( \
499 __check("%0%1", "$r10$r9") \
500 "break 13" __comment(name) \
503 : "memory", "srp", "r13", "r12", "r11" \
505 __sc_res = __sc_a1; \
507 __syscall_return(type, __sc_res); \
510 #define _syscall1(type, name, type1, arg1) \
511 type name(type1 arg1) \
515 __syscall_regval(a0, "r9", __NR_##name); \
516 __syscall_regval(a1, "r10", arg1); \
518 __asm__ __volatile__ ( \
519 __check("%0%1%2", "$r10$r9$r10") \
520 "break 13" __comment(name) \
524 : "memory", "srp", "r13", "r12", "r11" \
526 __sc_res = __sc_a1; \
528 __syscall_return(type, __sc_res); \
531 #define _syscall2(type, name, type1, arg1, type2, arg2) \
532 type name(type1 arg1, type2 arg2) \
536 __syscall_regval(a0, "r9", __NR_##name); \
537 __syscall_regval(a1, "r10", arg1); \
538 __syscall_regval(a2, "r11", arg2); \
540 __asm__ __volatile__ ( \
541 __check("%0%1%2%3", "$r10$r9$r10$r11") \
542 "break 13" __comment(name) \
545 "0"(__sc_a1), "r"(__sc_a2) \
546 : "memory", "srp", "r13", "r12" \
548 __sc_res = __sc_a1; \
550 __syscall_return(type, __sc_res); \
553 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
554 type name(type1 arg1, type2 arg2, type3 arg3) \
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); \
563 __asm__ __volatile__ ( \
564 __check("%0%1%2%3%4", "$r10$r9$r10$r11$r12") \
565 "break 13" __comment(name) \
568 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3) \
569 : "memory", "srp", "r13" \
571 __sc_res = __sc_a1; \
573 __syscall_return(type, __sc_res); \
576 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
578 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
588 __asm__ __volatile__ ( \
589 __check("%0%1%2%3%4%5", "$r10$r9$r10$r11$r12$r13") \
590 "break 13" __comment(name) \
593 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
597 __sc_res = __sc_a1; \
599 __syscall_return(type, __sc_res); \
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) \
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); \
614 __asm__ __volatile__ ( \
615 __check("%0%1%2%3%4%5", "$r10$r9$r10$r11$r12$r13") \
617 "break 13" __comment(name) \
620 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
625 __sc_res = __sc_a1; \
627 __syscall_return(type, __sc_res); \
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) \
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); \
643 __asm__ __volatile__ ( \
644 __check("%0%1%2%3%4%5", "$r10$r9$r10$r11$r12$r13") \
647 "break 13" __comment(name) \
650 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
652 "g"((long)arg5), "g"((long)arg6) \
655 __sc_res = __sc_a1; \
657 __syscall_return(type, __sc_res); \
661 /* *****************************************
663 frv kernel interface */
665 #elif defined(__frv__)
667 #warning syscall arch frv not implemented yet
670 /* *****************************************
671 H8300 H8300 H8300 H8300 *
672 h8/300 kernel interface */
674 #elif defined(__h8300__)
676 #warning syscall arch h8300 not implemented yet
679 /* *****************************************
680 I386 I386 I386 I386 *
681 i386 kernel interface */
683 #elif defined(__i386__)
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.
690 args: a1(ebx), a2(ecx), a3(edx), a4(esi), a5(edi), a6(ebp)
692 serr: (err= sret > (unsigned)-EMAXERRNO)
696 #define EMAXERRNO 129
699 #define __syscall_errcon(res) \
700 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
702 #define __syscall_return(type, res) do { \
703 __syscall_retval(res); \
704 if (__syscall_errcon(res)) { \
705 int __err = -(res); \
706 __syscall_error(__err); \
712 #define __syscall_regdef(name, reg) \
713 register long __sc_##name __asm__ (reg)
715 #define __syscall_regval(name, reg, val) \
716 register long __sc_##name __asm__ (reg) = (long)(val)
719 #define _syscall0(type, name) \
724 __syscall_regval(a0, "eax", __NR_##name); \
727 __check("%0%1", "%%eax%%eax") \
728 "int $0x80" __comment(name) \
733 __sc_res = __sc_a0; \
735 __syscall_return(type, __sc_res); \
738 #define _syscall1(type, name, type1, arg1) \
739 type name(type1 arg1) \
743 __syscall_regval(a0, "eax", __NR_##name); \
744 __syscall_regval(a1, "ebx", arg1); \
747 __check("%0%1%2", "%%eax%%eax%%ebx") \
748 "int $0x80" __comment(name) \
754 __sc_res = __sc_a0; \
756 __syscall_return(type, __sc_res); \
759 #define _syscall2(type, name, type1, arg1, type2, arg2) \
760 type name(type1 arg1, type2 arg2) \
764 __syscall_regval(a0, "eax", __NR_##name); \
765 __syscall_regval(a1, "ebx", arg1); \
766 __syscall_regval(a2, "ecx", arg2); \
769 __check("%0%1%2%3", "%%eax%%eax%%ebx%%ecx") \
770 "int $0x80" __comment(name) \
773 "r" (__sc_a1), "r"(__sc_a2) \
776 __sc_res = __sc_a0; \
778 __syscall_return(type, __sc_res); \
781 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
782 type name(type1 arg1, type2 arg2, type3 arg3) \
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); \
792 __check("%0%1%2%3%4", "%%eax%%eax%%ebx%%ecx%%edx") \
793 "int $0x80" __comment(name) \
796 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3) \
799 __sc_res = __sc_a0; \
801 __syscall_return(type, __sc_res); \
805 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
807 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
818 __check("%0%1%2%3%4%5", \
819 "%%eax%%eax%%ebx%%ecx%%edx%%esi") \
820 "int $0x80" __comment(name) \
823 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3), \
827 __sc_res = __sc_a0; \
829 __syscall_return(type, __sc_res); \
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) \
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); \
846 __check("%0%1%2%3%4%5%6", \
847 "%%eax%%eax%%ebx%%ecx%%edx%%esi%%edi") \
848 "int $0x80" __comment(name) \
851 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3), \
852 "r" (__sc_a4), "r"(__sc_a5) \
855 __sc_res = __sc_a0; \
857 __syscall_return(type, __sc_res); \
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) \
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); \
876 __check("%0%1%2%3%4%5%6%7", \
877 "%%eax%%eax%%ebx%%ecx%%edx%%esi%%edi%%ebp") \
878 "int $0x80" __comment(name) \
881 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3), \
882 "r" (__sc_a4), "r"(__sc_a5), "r" (__sc_a6) \
885 __sc_res = __sc_a0; \
887 __syscall_return(type, __sc_res); \
891 /* *****************************************
892 IA64 IA64 IA64 IA64 *
893 ia64 kernel interface */
895 #elif defined(__ia64__)
897 #warning syscall arch ia64 not implemented yet
900 /* *****************************************
901 M32R IM32R M32R M32R *
902 m32r kernel interface */
904 #elif defined(__m32r__)
906 #warning syscall arch m32r not implemented yet
909 /* *****************************************
910 M68K M68K M68K M68K *
911 m68k kernel interface */
913 #elif defined(__m68000__)
915 #warning syscall arch m68k not implemented yet
918 /* *****************************************
919 MIPS MIPS MIPS MIPS *
920 mips kernel interface */
922 #elif defined(__mips__)
924 #warning syscall arch mips not implemented yet
927 /* *****************************************
928 HPPA HPPA HPPA HPPA *
929 hppa kernel interface */
931 #elif defined(__hppa__)
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
938 The system call number MUST ALWAYS be loaded in the delay
939 slot of the ble instruction, or restarting system calls
943 args: r26, r25, r24, r23, r22, r21
945 serr: (err= sret > (unsigned)-EMAXERRNO)
946 clob: r1, r2, r4, r20, r29, r31, memory
950 #define EMAXERRNO 4095
953 #define __syscall_errcon(res) \
954 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
956 #define __syscall_return(type, res) do { \
957 __syscall_retval(res); \
958 if (__syscall_errcon(res)) { \
959 int __err = -(res); \
960 __syscall_error(__err); \
966 #define __syscall_clobbers \
967 "%r1", "%r2", "%r4", "%r20", "%r29", "%r31", "memory"
969 #define __syscall_regdef(name, reg) \
970 register unsigned long __sc_##name __asm__ (reg)
972 #define __syscall_regval(name, reg, val) \
973 register unsigned long __sc_##name __asm__ (reg) = \
977 #define _syscall0(type, name) \
982 __syscall_regdef(ret, "r28"); \
984 __asm__ __volatile__ ( \
985 __check("%0", "%%r28") \
986 "ble 0x100(%%sr2, %%r0)" \
987 __comment(name) "\n\t" \
991 : "%r21", "%r22", "%r23", \
992 "%r24", "%r25", "%r26", \
995 __sc_res = __sc_ret; \
997 __syscall_return(type, __sc_res); \
1000 #define _syscall1(type, name, type1, arg1) \
1001 type name(type1 arg1) \
1005 __syscall_regdef(ret, "r28"); \
1006 __syscall_regval(a1, "r26", arg1); \
1008 __asm__ __volatile__ ( \
1009 __check("%0%2", "%%r28%%r26") \
1010 "ble 0x100(%%sr2, %%r0)" \
1011 __comment(name) "\n\t" \
1014 : "i"(__NR_##name), \
1016 : "%r21", "%r22", "%r23", "%r24", "%r25", \
1017 __syscall_clobbers \
1019 __sc_res = __sc_ret; \
1021 __syscall_return(type, __sc_res); \
1024 #define _syscall2(type, name, type1, arg1, type2, arg2) \
1025 type name(type1 arg1, type2 arg2) \
1029 __syscall_regdef(ret, "r28"); \
1030 __syscall_regval(a1, "r26", arg1); \
1031 __syscall_regval(a2, "r25", arg2); \
1033 __asm__ __volatile__ ( \
1034 __check("%0%2%3", "%%r28%%r26%%r25") \
1035 "ble 0x100(%%sr2, %%r0)" \
1036 __comment(name) "\n\t" \
1039 : "i"(__NR_##name), \
1040 "r"(__sc_a1), "r"(__sc_a2) \
1041 : "%r21", "%r22", "%r23", "%r24", \
1042 __syscall_clobbers \
1044 __sc_res = __sc_ret; \
1046 __syscall_return(type, __sc_res); \
1049 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
1050 type name(type1 arg1, type2 arg2, type3 arg3) \
1054 __syscall_regdef(ret, "r28"); \
1055 __syscall_regval(a1, "r26", arg1); \
1056 __syscall_regval(a2, "r25", arg2); \
1057 __syscall_regval(a3, "r24", arg3); \
1059 __asm__ __volatile__ ( \
1060 __check("%0%2%3%4", "%%r28%%r26%%r25%%r24") \
1061 "ble 0x100(%%sr2, %%r0)" \
1062 __comment(name) "\n\t" \
1065 : "i"(__NR_##name), \
1066 "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3) \
1067 : "%r21", "%r22", "%r23", \
1068 __syscall_clobbers \
1070 __sc_res = __sc_ret; \
1072 __syscall_return(type, __sc_res); \
1075 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
1077 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
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" \
1093 : "i"(__NR_##name), \
1094 "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1097 __syscall_clobbers \
1099 __sc_res = __sc_ret; \
1101 __syscall_return(type, __sc_res); \
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) \
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); \
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" \
1124 : "i"(__NR_##name), \
1125 "r"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1126 "r"(__sc_a4), "r"(__sc_a5) \
1128 __syscall_clobbers \
1130 __sc_res = __sc_ret; \
1132 __syscall_return(type, __sc_res); \
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) \
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); \
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" \
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 \
1162 __sc_res = __sc_ret; \
1164 __syscall_return(type, __sc_res); \
1169 /* *****************************************
1170 PPC64 PPC64 PPC64 PPC64 *
1171 ppc64 kernel interface */
1173 #elif defined(__powerpc64__)
1175 #warning syscall arch ppc64 not implemented yet
1178 /* *****************************************
1180 ppc kernel interface */
1182 #elif defined(__powerpc__)
1184 /* The powerpc calling convention uses r3-r10 to pass the first
1185 eight arguments, the remainder is spilled onto the stack.
1188 args: a1(r3), a2(r4), a3(r5), a4(r6), a5(r7), a6(r8)
1195 #define __syscall_errcon(err) (err & 0x10000000)
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); \
1204 return (type) ret; \
1207 #define __syscall_regdef(name, reg) \
1208 register long __sc_##name __asm__ (reg)
1210 #define __syscall_regval(name, reg, val) \
1211 register long __sc_##name __asm__ (reg) = (long)(val)
1213 #define __syscall_clobbers \
1214 "r9", "r10", "r11", "r12", \
1215 "cr0", "ctr", "memory"
1218 #define _syscall0(type, name) \
1221 long __sc_ret, __sc_err; \
1223 __syscall_regval(r0, "r0", __NR_##name); \
1224 __syscall_regdef(a1, "r3"); \
1226 __asm__ __volatile__ ( \
1227 "sc" __comment(name) "\n\t" \
1229 : "=r"(__sc_r0), "=r"(__sc_a1) \
1231 : "r4", "r5", "r6", "r7", "r8", \
1232 __syscall_clobbers \
1234 __sc_ret = __sc_a1; \
1235 __sc_err = __sc_r0; \
1237 __syscall_return(type, __sc_ret, __sc_err); \
1240 #define _syscall1(type, name, type1, arg1) \
1241 type name(type1 arg1) \
1243 unsigned long __sc_ret, __sc_err; \
1245 __syscall_regval(r0, "r0", __NR_##name); \
1246 __syscall_regval(a1, "r3", arg1); \
1248 __asm__ __volatile__ ( \
1249 "sc" __comment(name) "\n\t" \
1251 : "=r"(__sc_r0), "=r"(__sc_a1) \
1254 : "r4", "r5", "r6", "r7", "r8", \
1255 __syscall_clobbers \
1257 __sc_ret = __sc_a1; \
1258 __sc_err = __sc_r0; \
1260 __syscall_return(type, __sc_ret, __sc_err); \
1263 #define _syscall2(type, name, type1, arg1, type2, arg2) \
1264 type name(type1 arg1, type2 arg2) \
1266 unsigned long __sc_ret, __sc_err; \
1268 __syscall_regval(r0, "r0", __NR_##name); \
1269 __syscall_regval(a1, "r3", arg1); \
1270 __syscall_regval(a2, "r4", arg2); \
1272 __asm__ __volatile__ ( \
1273 "sc" __comment(name) "\n\t" \
1275 : "=r"(__sc_r0), "=r"(__sc_a1) \
1277 "1"(__sc_a1), "r"(__sc_a2) \
1278 : "r5", "r6", "r7", "r8", \
1279 __syscall_clobbers \
1281 __sc_ret = __sc_a1; \
1282 __sc_err = __sc_r0; \
1284 __syscall_return(type, __sc_ret, __sc_err); \
1287 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
1288 type name(type1 arg1, type2 arg2, type3 arg3) \
1290 unsigned long __sc_ret, __sc_err; \
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); \
1297 __asm__ __volatile__ ( \
1298 "sc" __comment(name) "\n\t" \
1300 : "=r"(__sc_r0), "=r"(__sc_a1) \
1302 "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3) \
1303 : "r6", "r7", "r8", \
1304 __syscall_clobbers \
1306 __sc_ret = __sc_a1; \
1307 __sc_err = __sc_r0; \
1309 __syscall_return(type, __sc_ret, __sc_err); \
1313 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
1315 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
1317 unsigned long __sc_ret, __sc_err; \
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); \
1325 __asm__ __volatile__ ( \
1326 "sc" __comment(name) "\n\t" \
1328 : "=r"(__sc_r0), "=r"(__sc_a1) \
1330 "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1333 __syscall_clobbers \
1335 __sc_ret = __sc_a1; \
1336 __sc_err = __sc_r0; \
1338 __syscall_return(type, __sc_ret, __sc_err); \
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) \
1345 unsigned long __sc_ret, __sc_err; \
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); \
1354 __asm__ __volatile__ ( \
1355 "sc" __comment(name) "\n\t" \
1357 : "=r"(__sc_r0), "=r"(__sc_a1) \
1359 "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1360 "r"(__sc_a4), "r"(__sc_a5) \
1362 __syscall_clobbers \
1364 __sc_ret = __sc_a1; \
1365 __sc_err = __sc_r0; \
1367 __syscall_return(type, __sc_ret, __sc_err); \
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) \
1375 unsigned long __sc_ret, __sc_err; \
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); \
1385 __asm__ __volatile__ ( \
1386 "sc" __comment(name) "\n\t" \
1388 : "=r"(__sc_r0), "=r"(__sc_a1) \
1390 "1"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1391 "r"(__sc_a4), "r"(__sc_a5), "r"(__sc_a6) \
1392 : __syscall_clobbers \
1394 __sc_ret = __sc_a1; \
1395 __sc_err = __sc_r0; \
1397 __syscall_return(type, __sc_ret, __sc_err); \
1401 /* *****************************************
1402 S390X S390X S390X S390X *
1403 s390x kernel interface */
1405 #elif defined(__s390x__)
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.
1412 args: a1(r2), a2(r3), a3(r4), a4(r5), a5(r6), a6(r7)
1414 serr: (err= sret > (unsigned)-EMAXERRNO)
1420 #define EMAXERRNO 4095
1423 #define __syscall_errcon(res) \
1424 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
1426 #define __syscall_return(type, res) do { \
1427 __syscall_retval(res); \
1428 if (__syscall_errcon(res)) { \
1429 int __err = -(res); \
1430 __syscall_error(__err); \
1433 return (type) res; \
1436 #define __syscall_regdef(name, reg) \
1437 register unsigned long __sc_##name __asm__ (reg)
1439 #define __syscall_regval(name, reg, val) \
1440 register unsigned long __sc_##name __asm__ (reg) = \
1441 (unsigned long)(val)
1443 #define __syscall_clobbers "memory"
1446 #define _syscall0(type, name) \
1451 __syscall_regval(nr, "r1", __NR_##name); \
1452 __syscall_regdef(a1, "r2"); \
1454 __asm__ volatile ( \
1455 __check("%0%1", "%%r2%%r1") \
1456 "svc 0" __comment(name) \
1459 : __syscall_clobbers \
1461 __sc_res = __sc_a1; \
1463 __syscall_return(type, __sc_res); \
1466 #define _syscall1(type, name, type1, arg1) \
1467 type name(type1 arg1) \
1471 __syscall_regval(nr, "r1", __NR_##name); \
1472 __syscall_regval(a1, "r2", arg1); \
1474 __asm__ volatile ( \
1475 __check("%0%1%2", "%%r2%%r1%%r2") \
1476 "svc 0" __comment(name) \
1480 : __syscall_clobbers \
1482 __sc_res = __sc_a1; \
1484 __syscall_return(type, __sc_res); \
1487 #define _syscall2(type, name, type1, arg1, type2, arg2) \
1488 type name(type1 arg1, type2 arg2) \
1492 __syscall_regval(nr, "r1", __NR_##name); \
1493 __syscall_regval(a1, "r2", arg1); \
1494 __syscall_regval(a2, "r3", arg2); \
1496 __asm__ volatile ( \
1497 __check("%0%1%2%3", "%%r2%%r1%%r2%%r3") \
1498 "svc 0" __comment(name) \
1501 "0"(__sc_a1), "r"(__sc_a2) \
1502 : __syscall_clobbers \
1504 __sc_res = __sc_a1; \
1506 __syscall_return(type, __sc_res); \
1509 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
1510 type name(type1 arg1, type2 arg2, type3 arg3) \
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); \
1519 __asm__ volatile ( \
1520 __check("%0%1%2%3%4", "%%r2%%r1%%r2%%r3%%r4") \
1521 "svc 0" __comment(name) \
1524 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3) \
1525 : __syscall_clobbers \
1527 __sc_res = __sc_a1; \
1529 __syscall_return(type, __sc_res); \
1532 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
1534 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
1544 __asm__ volatile ( \
1545 __check("%0%1%2%3%4%5", "%%r2%%r1%%r2%%r3%%r4%%r5") \
1546 "svc 0" __comment(name) \
1549 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1551 : __syscall_clobbers \
1553 __sc_res = __sc_a1; \
1555 __syscall_return(type, __sc_res); \
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) \
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); \
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) \
1577 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1578 "r"(__sc_a4), "r"(__sc_a5) \
1579 : __syscall_clobbers \
1581 __sc_res = __sc_a1; \
1583 __syscall_return(type, __sc_res); \
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) \
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); \
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) \
1607 "0"(__sc_a1), "r"(__sc_a2), "r"(__sc_a3), \
1608 "r"(__sc_a4), "r"(__sc_a5), "r"(__sc_a6) \
1609 : __syscall_clobbers \
1611 __sc_res = __sc_a1; \
1613 __syscall_return(type, __sc_res); \
1618 /* *****************************************
1619 S390 S390 S390 S390 *
1620 s390 kernel interface */
1622 #elif defined(__s390__)
1624 #warning syscall arch s390 not implemented yet
1627 /* *****************************************
1629 sh kernel interface */
1631 #elif defined(__sh__) && !defined(__SH5__)
1633 #warning syscall arch sh not implemented yet
1636 /* *****************************************
1637 SH64 SH64 SH64 SH64 *
1638 sh64 kernel interface */
1640 #elif defined(__sh__) && defined(__SH5__)
1642 #warning syscall arch sh64 not implemented yet
1645 /* *****************************************
1646 SPARC64 SPARC64 SPARC64 SPARC64 *
1647 sparc64 kernel interface */
1649 #elif defined(__sparc__) && defined(__arch64__)
1651 /* The sparc64 calling convention uses o0-o5 to pass the first six
1652 arguments (mapped via register windows).
1655 args: o0, o1, o2, o3, o4, o5
1659 clob: g1-g6, g7?, o7?, f0-f31, cc
1663 #define EMAXERRNO 515
1666 #define __syscall_errcon(res) \
1667 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
1669 #define __syscall_return(type, res) do { \
1670 __syscall_retval(res); \
1671 if (__syscall_errcon(res)) { \
1672 int __err = -(res); \
1673 __syscall_error(__err); \
1676 return (type) res; \
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", \
1689 #define __syscall_regdef(name, reg) \
1690 register long __sc_##name __asm__ (reg)
1692 #define __syscall_regval(name, reg, val) \
1693 register long __sc_##name __asm__ (reg) = (long)(val)
1695 #define _syscall0(type, name) \
1700 __syscall_regval(g1, "g1", __NR_##name); \
1701 __syscall_regdef(o0, "o0"); \
1703 __asm__ volatile ( \
1704 "ta 0x6d" __comment(name) "\n\t" \
1705 "bcs,a,pt %%xcc,1f\n\t" \
1706 "sub %%g0,%%o0,%%o0\n" \
1710 : __syscall_clobbers \
1712 __sc_res = __sc_o0; \
1714 __syscall_return(type, __sc_res); \
1717 #define _syscall1(type, name, type1, arg1) \
1718 type name(type1 arg1) \
1722 __syscall_regval(g1, "g1", __NR_##name); \
1723 __syscall_regval(o0, "o0", arg1); \
1725 __asm__ volatile ( \
1726 "ta 0x6d" __comment(name) "\n\t" \
1727 "bcs,a,pt %%xcc,1f\n\t" \
1728 "sub %%g0,%%o0,%%o0\n" \
1733 : __syscall_clobbers \
1735 __sc_res = __sc_o0; \
1737 __syscall_return(type, __sc_res); \
1740 #define _syscall2(type, name, type1, arg1, type2, arg2) \
1741 type name(type1 arg1, type2 arg2) \
1745 __syscall_regval(g1, "g1", __NR_##name); \
1746 __syscall_regval(o0, "o0", arg1); \
1747 __syscall_regval(o1, "o1", arg2); \
1749 __asm__ volatile ( \
1750 "ta 0x6d" __comment(name) "\n\t" \
1751 "bcs,a,pt %%xcc,1f\n\t" \
1752 "sub %%g0,%%o0,%%o0\n" \
1756 "0"(__sc_o0), "r"(__sc_o1) \
1757 : __syscall_clobbers \
1759 __sc_res = __sc_o0; \
1761 __syscall_return(type, __sc_res); \
1764 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
1765 type name(type1 arg1, type2 arg2, type3 arg3) \
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); \
1774 __asm__ volatile ( \
1775 "ta 0x6d" __comment(name) "\n\t" \
1776 "bcs,a,pt %%xcc,1f\n\t" \
1777 "sub %%g0,%%o0,%%o0\n" \
1781 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2) \
1782 : __syscall_clobbers \
1784 __sc_res = __sc_o0; \
1786 __syscall_return(type, __sc_res); \
1789 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
1791 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
1801 __asm__ volatile ( \
1802 "ta 0x6d" __comment(name) "\n\t" \
1803 "bcs,a,pt %%xcc,1f\n\t" \
1804 "sub %%g0,%%o0,%%o0\n" \
1808 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2), \
1810 : __syscall_clobbers \
1812 __sc_res = __sc_o0; \
1814 __syscall_return(type, __sc_res); \
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) \
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); \
1830 __asm__ volatile ( \
1831 "ta 0x6d" __comment(name) "\n\t" \
1832 "bcs,a,pt %%xcc,1f\n\t" \
1833 "sub %%g0,%%o0,%%o0\n" \
1837 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2), \
1838 "r"(__sc_o3), "r"(__sc_o4) \
1839 : __syscall_clobbers \
1841 __sc_res = __sc_o0; \
1843 __syscall_return(type, __sc_res); \
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) \
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); \
1861 __asm__ volatile ( \
1862 "ta 0x6d" __comment(name) "\n\t" \
1863 "bcs,a,pt %%xcc,1f\n\t" \
1864 "sub %%g0,%%o0,%%o0\n" \
1868 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2), \
1869 "r"(__sc_o3), "r"(__sc_o4), "r"(__sc_o5) \
1870 : __syscall_clobbers \
1872 __sc_res = __sc_o0; \
1874 __syscall_return(type, __sc_res); \
1878 /* *****************************************
1879 SPARC SPARC SPARC SPARC *
1880 sparc kernel interface */
1882 #elif defined(__sparc__)
1884 /* The sparc calling convention uses o0-o5 to pass the first six
1885 arguments (mapped via register windows).
1888 args: o0, o1, o2, o3, o4, o5
1892 clob: g1-g6, g7?, o7?, f0-f31, cc
1896 #define EMAXERRNO 515
1899 #define __syscall_errcon(res) \
1900 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
1902 #define __syscall_return(type, res) do { \
1903 __syscall_retval(res); \
1904 if (__syscall_errcon(res)) { \
1905 int __err = -(res); \
1906 __syscall_error(__err); \
1909 return (type) res; \
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", \
1920 #define __syscall_regdef(name, reg) \
1921 register long __sc_##name __asm__ (reg)
1923 #define __syscall_regval(name, reg, val) \
1924 register long __sc_##name __asm__ (reg) = (long)(val)
1926 #define _syscall0(type, name) \
1931 __syscall_regval(g1, "g1", __NR_##name); \
1932 __syscall_regdef(o0, "o0"); \
1934 __asm__ volatile ( \
1935 "t 0x10" __comment(name) "\n\t" \
1937 "sub %%g0,%%o0,%%o0\n" \
1941 : __syscall_clobbers \
1943 __sc_res = __sc_o0; \
1945 __syscall_return(type, __sc_res); \
1948 #define _syscall1(type, name, type1, arg1) \
1949 type name(type1 arg1) \
1953 __syscall_regval(g1, "g1", __NR_##name); \
1954 __syscall_regval(o0, "o0", arg1); \
1956 __asm__ volatile ( \
1957 "t 0x10" __comment(name) "\n\t" \
1959 "sub %%g0,%%o0,%%o0\n" \
1964 : __syscall_clobbers \
1966 __sc_res = __sc_o0; \
1968 __syscall_return(type, __sc_res); \
1971 #define _syscall2(type, name, type1, arg1, type2, arg2) \
1972 type name(type1 arg1, type2 arg2) \
1976 __syscall_regval(g1, "g1", __NR_##name); \
1977 __syscall_regval(o0, "o0", arg1); \
1978 __syscall_regval(o1, "o1", arg2); \
1980 __asm__ volatile ( \
1981 "t 0x10" __comment(name) "\n\t" \
1983 "sub %%g0,%%o0,%%o0\n" \
1987 "0"(__sc_o0), "r"(__sc_o1) \
1988 : __syscall_clobbers \
1990 __sc_res = __sc_o0; \
1992 __syscall_return(type, __sc_res); \
1995 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
1996 type name(type1 arg1, type2 arg2, type3 arg3) \
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); \
2005 __asm__ volatile ( \
2006 "t 0x10" __comment(name) "\n\t" \
2008 "sub %%g0,%%o0,%%o0\n" \
2012 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2) \
2013 : __syscall_clobbers \
2015 __sc_res = __sc_o0; \
2017 __syscall_return(type, __sc_res); \
2020 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
2022 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
2032 __asm__ volatile ( \
2033 "t 0x10" __comment(name) "\n\t" \
2035 "sub %%g0,%%o0,%%o0\n" \
2039 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2), \
2041 : __syscall_clobbers \
2043 __sc_res = __sc_o0; \
2045 __syscall_return(type, __sc_res); \
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) \
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); \
2061 __asm__ volatile ( \
2062 "t 0x10" __comment(name) "\n\t" \
2064 "sub %%g0,%%o0,%%o0\n" \
2068 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2), \
2069 "r"(__sc_o3), "r"(__sc_o4) \
2070 : __syscall_clobbers \
2072 __sc_res = __sc_o0; \
2074 __syscall_return(type, __sc_res); \
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) \
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); \
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" \
2096 "sub %%g0,%%o0,%%o0\n" \
2100 "0"(__sc_o0), "r"(__sc_o1), "r"(__sc_o2), \
2101 "r"(__sc_o3), "r"(__sc_o4), "r"(__sc_o5) \
2102 : __syscall_clobbers \
2104 __sc_res = __sc_o0; \
2106 __syscall_return(type, __sc_res); \
2110 /* *****************************************
2111 V850 V850 V850 V850 *
2112 v850 kernel interface */
2114 #elif defined(__v850__)
2116 #warning syscall arch v850 not implemented yet
2119 /* *****************************************
2120 X86_64 X86_64 X86_64 X86_64 *
2121 x86_64 kernel interface */
2123 #elif defined(__x86_64__)
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.
2129 args: a1(rdi), a2(rsi), a3(rdx), a4(r10), a5(r8), a6(r9)
2131 serr: (err= sret > (unsigned)-EMAXERRNO)
2137 #define EMAXERRNO 4095
2140 #define __syscall_errcon(res) \
2141 ((unsigned long)(res) >= (unsigned long)(-EMAXERRNO))
2143 #define __syscall_return(type, res) do { \
2144 __syscall_retval(res); \
2145 if (__syscall_errcon(res)) { \
2146 int __err = -(res); \
2147 __syscall_error(__err); \
2150 return (type) res; \
2153 #define __syscall_clobbers \
2154 "cc", "r11", "rcx", "memory"
2156 #define __syscall_regdef(name, reg) \
2157 register long __sc_##name __asm__ (reg)
2159 #define __syscall_regval(name, reg, val) \
2160 register long __sc_##name __asm__ (reg) = (long)(val)
2163 #define _syscall0(type, name) \
2168 __syscall_regval(a0, "rax", __NR_##name); \
2170 __asm__ volatile ( \
2171 __check("%0%1", "%%rax%%rax") \
2172 "syscall" __comment(name) \
2175 : __syscall_clobbers \
2177 __sc_res = __sc_a0; \
2179 __syscall_return(type, __sc_res); \
2182 #define _syscall1(type, name, type1, arg1) \
2183 type name(type1 arg1) \
2187 __syscall_regval(a0, "rax", __NR_##name); \
2188 __syscall_regval(a1, "rdi", arg1); \
2190 __asm__ volatile ( \
2191 __check("%0%1%2", "%%rax%%rax%%rdi") \
2192 "syscall" __comment(name) \
2196 : __syscall_clobbers \
2198 __sc_res = __sc_a0; \
2200 __syscall_return(type, __sc_res); \
2203 #define _syscall2(type, name, type1, arg1, type2, arg2) \
2204 type name(type1 arg1, type2 arg2) \
2208 __syscall_regval(a0, "rax", __NR_##name); \
2209 __syscall_regval(a1, "rdi", arg1); \
2210 __syscall_regval(a2, "rsi", arg2); \
2212 __asm__ volatile ( \
2213 __check("%0%1%2%3", "%%rax%%rax%%rdi%%rsi") \
2214 "syscall" __comment(name) \
2217 "r" (__sc_a1), "r"(__sc_a2) \
2218 : __syscall_clobbers \
2220 __sc_res = __sc_a0; \
2222 __syscall_return(type, __sc_res); \
2225 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
2226 type name(type1 arg1, type2 arg2, type3 arg3) \
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); \
2235 __asm__ volatile ( \
2236 __check("%0%1%2%3%4", "%%rax%%rax%%rdi%%rsi%%rdx") \
2237 "syscall" __comment(name) \
2240 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3) \
2241 : __syscall_clobbers \
2243 __sc_res = __sc_a0; \
2245 __syscall_return(type, __sc_res); \
2249 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
2251 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
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); \
2261 __asm__ volatile ( \
2262 __check("%0%1%2%3%4%5", \
2263 "%%rax%%rax%%rdi%%rsi%%rdx%%r10") \
2264 "syscall" __comment(name) \
2267 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3), \
2269 : __syscall_clobbers \
2271 __sc_res = __sc_a0; \
2273 __syscall_return(type, __sc_res); \
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) \
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); \
2289 __asm__ volatile ( \
2290 __check("%0%1%2%3%4%5%6", \
2291 "%%rax%%rax%%rdi%%rsi%%rdx%%r10%%r8") \
2292 "syscall" __comment(name) \
2295 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3), \
2296 "r" (__sc_a4), "r"(__sc_a5) \
2297 : __syscall_clobbers \
2299 __sc_res = __sc_a0; \
2301 __syscall_return(type, __sc_res); \
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) \
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); \
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) \
2325 "r" (__sc_a1), "r"(__sc_a2), "r" (__sc_a3), \
2326 "r" (__sc_a4), "r"(__sc_a5), "r" (__sc_a6) \
2327 : __syscall_clobbers \
2329 __sc_res = __sc_a0; \
2331 __syscall_return(type, __sc_res); \