syscalls.h 7.1 KB

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