syscalls.h 5.4 KB

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