syscalls.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
  4. Based on code originally written by David Mosberger-Tang
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifndef _BITS_SYSCALLS_H
  18. #define _BITS_SYSCALLS_H
  19. #ifndef _SYSCALL_H
  20. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  21. #endif
  22. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  23. * header files. It also defines the traditional `SYS_<name>' macros for older
  24. * programs. */
  25. #include <bits/sysnum.h>
  26. #ifndef __set_errno
  27. # define __set_errno(val) (*__errno_location ()) = (val)
  28. #endif
  29. #ifndef __ASSEMBLER__
  30. #undef IA64_USE_NEW_STUB
  31. #define SYS_ify(syscall_name) __NR_##syscall_name
  32. /* taken from asm-ia64/break.h */
  33. #define __IA64_BREAK_SYSCALL "0x100000"
  34. #define _DO_SYSCALL(name, nr, args...) \
  35. LOAD_ARGS_##nr (args) \
  36. register long _r8 asm ("r8"); \
  37. register long _r10 asm ("r10"); \
  38. register long _r15 asm ("r15") = SYS_ify(name); \
  39. long _retval; \
  40. LOAD_REGS_##nr \
  41. __asm __volatile ("break " __IA64_BREAK_SYSCALL ";;\n\t" \
  42. : "=r" (_r8), "=r" (_r10), "=r" (_r15) ASM_OUTARGS_##nr \
  43. : "2" (_r15) ASM_ARGS_##nr \
  44. : "memory" ASM_CLOBBERS_##nr); \
  45. _retval = _r8; \
  46. if (_r10 == -1) { \
  47. __set_errno (_retval); \
  48. _retval = -1; \
  49. }
  50. #define LOAD_ARGS_0()
  51. #define LOAD_REGS_0
  52. #define LOAD_ARGS_1(a1) \
  53. long _arg1 = (long) (a1); \
  54. LOAD_ARGS_0 ()
  55. #define LOAD_REGS_1 \
  56. register long _out0 asm ("out0") = _arg1; \
  57. LOAD_REGS_0
  58. #define LOAD_ARGS_2(a1, a2) \
  59. long _arg2 = (long) (a2); \
  60. LOAD_ARGS_1 (a1)
  61. #define LOAD_REGS_2 \
  62. register long _out1 asm ("out1") = _arg2; \
  63. LOAD_REGS_1
  64. #define LOAD_ARGS_3(a1, a2, a3) \
  65. long _arg3 = (long) (a3); \
  66. LOAD_ARGS_2 (a1, a2)
  67. #define LOAD_REGS_3 \
  68. register long _out2 asm ("out2") = _arg3; \
  69. LOAD_REGS_2
  70. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  71. long _arg4 = (long) (a4); \
  72. LOAD_ARGS_3 (a1, a2, a3)
  73. #define LOAD_REGS_4 \
  74. register long _out3 asm ("out3") = _arg4; \
  75. LOAD_REGS_3
  76. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  77. long _arg5 = (long) (a5); \
  78. LOAD_ARGS_4 (a1, a2, a3, a4)
  79. #define LOAD_REGS_5 \
  80. register long _out4 asm ("out4") = _arg5; \
  81. LOAD_REGS_4
  82. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  83. long _arg6 = (long) (a6); \
  84. LOAD_ARGS_5 (a1, a2, a3, a4, a5)
  85. #define LOAD_REGS_6 \
  86. register long _out5 asm ("out5") = _arg6; \
  87. LOAD_REGS_5
  88. #define ASM_OUTARGS_0
  89. #define ASM_OUTARGS_1 ASM_OUTARGS_0, "=r" (_out0)
  90. #define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
  91. #define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
  92. #define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
  93. #define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
  94. #define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
  95. #ifdef IA64_USE_NEW_STUB
  96. #define ASM_ARGS_0
  97. #define ASM_ARGS_1 ASM_ARGS_0, "4" (_out0)
  98. #define ASM_ARGS_2 ASM_ARGS_1, "5" (_out1)
  99. #define ASM_ARGS_3 ASM_ARGS_2, "6" (_out2)
  100. #define ASM_ARGS_4 ASM_ARGS_3, "7" (_out3)
  101. #define ASM_ARGS_5 ASM_ARGS_4, "8" (_out4)
  102. #define ASM_ARGS_6 ASM_ARGS_5, "9" (_out5)
  103. #else
  104. #define ASM_ARGS_0
  105. #define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
  106. #define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
  107. #define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
  108. #define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
  109. #define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
  110. #define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
  111. #endif
  112. #define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
  113. #define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
  114. #define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
  115. #define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
  116. #define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
  117. #define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
  118. #define ASM_CLOBBERS_6_COMMON , "out6", "out7", \
  119. /* Non-stacked integer registers, minus r8, r10, r15. */ \
  120. "r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18", \
  121. "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
  122. "r28", "r29", "r30", "r31", \
  123. /* Predicate registers. */ \
  124. "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
  125. /* Non-rotating fp registers. */ \
  126. "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
  127. /* Branch registers. */ \
  128. "b6"
  129. #ifdef IA64_USE_NEW_STUB
  130. # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON
  131. #else
  132. # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON , "b7"
  133. #endif
  134. #define _syscall0(type,name) \
  135. type name(void) \
  136. { \
  137. _DO_SYSCALL(name, 0); return (type) _retval; \
  138. }
  139. #define _syscall1(type,name,type1,arg1) \
  140. type name(type1 arg1) \
  141. { \
  142. _DO_SYSCALL(name, 1, arg1); return (type) _retval; \
  143. }
  144. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  145. type name(type1 arg1, type2 arg2) \
  146. { \
  147. _DO_SYSCALL(name, 2, arg1, arg2); return (type) _retval; \
  148. }
  149. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  150. type name(type1 arg1, type2 arg2, type3 arg3) \
  151. { \
  152. _DO_SYSCALL(name, 3, arg1, arg2, arg3); return (type) _retval; \
  153. }
  154. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  155. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  156. { \
  157. _DO_SYSCALL(name, 4, arg1, arg2, arg3, arg4); return (type) _retval; \
  158. }
  159. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  160. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
  161. { \
  162. _DO_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5); return (type) _retval; \
  163. }
  164. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
  165. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
  166. { \
  167. _DO_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6); return (type) _retval; \
  168. }
  169. #endif /* __ASSEMBLER__ */
  170. #endif /* _BITS_SYSCALLS_H */