syscalls.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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, see
  16. <http://www.gnu.org/licenses/>. */
  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. #ifndef __ASSEMBLER__
  23. #include <errno.h>
  24. #undef IA64_USE_NEW_STUB
  25. #define __IA64_BREAK_SYSCALL 0x100000
  26. /* mostly taken from glibc sysdeps/unix/sysv/linux/ia64/sysdep.h */
  27. #define BREAK_INSN_1(num) "break " #num ";;\n\t"
  28. #define BREAK_INSN(num) BREAK_INSN_1(num)
  29. /* On IA-64 we have stacked registers for passing arguments. The
  30. "out" registers end up being the called function's "in"
  31. registers.
  32. Also, since we have plenty of registers we have two return values
  33. from a syscall. r10 is set to -1 on error, whilst r8 contains the
  34. (non-negative) errno on error or the return value on success.
  35. */
  36. # define DO_INLINE_SYSCALL_NCS(name, nr, args...) \
  37. LOAD_ARGS_##nr (args) \
  38. register long _r8 __asm__ ("r8"); \
  39. register long _r10 __asm__ ("r10"); \
  40. register long _r15 __asm__ ("r15") = name; \
  41. long _retval; \
  42. LOAD_REGS_##nr \
  43. __asm__ __volatile__ (BREAK_INSN (__IA64_BREAK_SYSCALL) \
  44. : "=r" (_r8), "=r" (_r10), "=r" (_r15) \
  45. ASM_OUTARGS_##nr \
  46. : "2" (_r15) ASM_ARGS_##nr \
  47. : "memory" ASM_CLOBBERS_##nr); \
  48. _retval = _r8;
  49. #define INLINE_SYSCALL_NCS(name, nr, args...) \
  50. (__extension__ \
  51. ({ \
  52. DO_INLINE_SYSCALL_NCS (name, nr, args) \
  53. if (unlikely (_r10 == -1)) \
  54. { \
  55. __set_errno (_retval); \
  56. _retval = -1; \
  57. } \
  58. _retval; \
  59. }) \
  60. )
  61. #define INTERNAL_SYSCALL_DECL(err) long int err
  62. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  63. (__extension__ \
  64. ({ \
  65. DO_INLINE_SYSCALL_NCS (name, nr, args) \
  66. err = _r10; \
  67. _retval; \
  68. }) \
  69. )
  70. #define INTERNAL_SYSCALL_ERROR_P(val, err) (err == -1)
  71. #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
  72. #define LOAD_ARGS_0()
  73. #define LOAD_REGS_0
  74. #define LOAD_ARGS_1(a1) \
  75. long _arg1 = (long) (a1); \
  76. LOAD_ARGS_0 ()
  77. #define LOAD_REGS_1 \
  78. register long _out0 __asm__ ("out0") = _arg1; \
  79. LOAD_REGS_0
  80. #define LOAD_ARGS_2(a1, a2) \
  81. long _arg2 = (long) (a2); \
  82. LOAD_ARGS_1 (a1)
  83. #define LOAD_REGS_2 \
  84. register long _out1 __asm__ ("out1") = _arg2; \
  85. LOAD_REGS_1
  86. #define LOAD_ARGS_3(a1, a2, a3) \
  87. long _arg3 = (long) (a3); \
  88. LOAD_ARGS_2 (a1, a2)
  89. #define LOAD_REGS_3 \
  90. register long _out2 __asm__ ("out2") = _arg3; \
  91. LOAD_REGS_2
  92. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  93. long _arg4 = (long) (a4); \
  94. LOAD_ARGS_3 (a1, a2, a3)
  95. #define LOAD_REGS_4 \
  96. register long _out3 __asm__ ("out3") = _arg4; \
  97. LOAD_REGS_3
  98. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  99. long _arg5 = (long) (a5); \
  100. LOAD_ARGS_4 (a1, a2, a3, a4)
  101. #define LOAD_REGS_5 \
  102. register long _out4 __asm__ ("out4") = _arg5; \
  103. LOAD_REGS_4
  104. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  105. long _arg6 = (long) (a6); \
  106. LOAD_ARGS_5 (a1, a2, a3, a4, a5)
  107. #define LOAD_REGS_6 \
  108. register long _out5 __asm__ ("out5") = _arg6; \
  109. LOAD_REGS_5
  110. #define ASM_OUTARGS_0
  111. #define ASM_OUTARGS_1 ASM_OUTARGS_0, "=r" (_out0)
  112. #define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
  113. #define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
  114. #define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
  115. #define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
  116. #define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
  117. #define ASM_ARGS_0
  118. #define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
  119. #define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
  120. #define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
  121. #define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
  122. #define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
  123. #define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
  124. #define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
  125. #define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
  126. #define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
  127. #define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
  128. #define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
  129. #define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
  130. #define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON , "b7"
  131. #define ASM_CLOBBERS_6_COMMON , "out6", "out7", \
  132. /* Non-stacked integer registers, minus r8, r10, r15. */ \
  133. "r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18", \
  134. "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
  135. "r28", "r29", "r30", "r31", \
  136. /* Predicate registers. */ \
  137. "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
  138. /* Non-rotating fp registers. */ \
  139. "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
  140. /* Branch registers. */ \
  141. "b6"
  142. #endif /* __ASSEMBLER__ */
  143. #endif /* _BITS_SYSCALLS_H */