syscalls.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  5. #endif
  6. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  7. * header files. It also defines the traditional `SYS_<name>' macros for older
  8. * programs. */
  9. #include <bits/sysnum.h>
  10. #ifndef __set_errno
  11. # define __set_errno(val) (*__errno_location ()) = (val)
  12. #endif
  13. /*
  14. macros taken from glibc-2.3/sysdeps/unix/sysv/linux/sparc/sysdep.h
  15. Copyright (C) 2000, 2002 Free Software Foundation, Inc.
  16. Contributed by Jakub Jelinek <jakub@redhat.com>, 2000.
  17. */
  18. #ifndef __ASSEMBLER__
  19. #undef _syscall0
  20. #define _syscall0(type,name) \
  21. type name(void) \
  22. { \
  23. return (type) (INLINE_SYSCALL(name, 0)); \
  24. }
  25. #undef _syscall1
  26. #define _syscall1(type,name,type1,arg1) \
  27. type name(type1 arg1) \
  28. { \
  29. return (type) (INLINE_SYSCALL(name, 1, arg1)); \
  30. }
  31. #undef _syscall2
  32. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  33. type name(type1 arg1,type2 arg2) \
  34. { \
  35. return (type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \
  36. }
  37. #undef _syscall3
  38. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  39. type name(type1 arg1,type2 arg2,type3 arg3) \
  40. { \
  41. return (type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \
  42. }
  43. #undef _syscall4
  44. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  45. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  46. { \
  47. return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \
  48. }
  49. #undef _syscall5
  50. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  51. type5,arg5) \
  52. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  53. { \
  54. return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
  55. }
  56. #undef _syscall6
  57. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  58. type5,arg5,type6,arg6) \
  59. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
  60. { \
  61. return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \
  62. }
  63. #undef _syscall7
  64. #define _syscall7(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  65. type5,arg5,type6,arg6,type7,arg7) \
  66. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6,type7 arg7) \
  67. { \
  68. return (type) (INLINE_SYSCALL(name, 7, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); \
  69. }
  70. #define __SYSCALL_STRING \
  71. "ta 0x10;" \
  72. "bcs 2f;" \
  73. " nop;" \
  74. "1:" \
  75. ".subsection 2;" \
  76. "2:" \
  77. "save %%sp, -192, %%sp;" \
  78. "call __errno_location;" \
  79. " nop;" \
  80. "st %%i0,[%%o0];" \
  81. "ba 1b;" \
  82. " restore %%g0, -1, %%o0;" \
  83. ".previous;"
  84. #define __SYSCALL_CLOBBERS "g2", "g3", "g4", "g5", "g7", \
  85. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
  86. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
  87. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
  88. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
  89. "cc", "memory"
  90. #undef INLINE_SYSCALL
  91. #define INLINE_SYSCALL(name, nr, args...) _INLINE_SYSCALL##nr(name, args)
  92. #define _INLINE_SYSCALL0(name,dummy...) \
  93. ({ \
  94. register long __o0 __asm__ ("o0"); \
  95. register long __g1 __asm__ ("g1") = __NR_##name; \
  96. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  97. "0" (__g1) : \
  98. __SYSCALL_CLOBBERS); \
  99. __o0; \
  100. })
  101. #define _INLINE_SYSCALL1(name,arg1) \
  102. ({ \
  103. register long __o0 __asm__ ("o0") = (long)(arg1); \
  104. register long __g1 __asm__ ("g1") = __NR_##name; \
  105. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  106. "0" (__g1), "1" (__o0) : \
  107. __SYSCALL_CLOBBERS); \
  108. __o0; \
  109. })
  110. #define _INLINE_SYSCALL2(name,arg1,arg2) \
  111. ({ \
  112. register long __o0 __asm__ ("o0") = (long)(arg1); \
  113. register long __o1 __asm__ ("o1") = (long)(arg2); \
  114. register long __g1 __asm__ ("g1") = __NR_##name; \
  115. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  116. "0" (__g1), "1" (__o0), "r" (__o1) : \
  117. __SYSCALL_CLOBBERS); \
  118. __o0; \
  119. })
  120. #define _INLINE_SYSCALL3(name,arg1,arg2,arg3) \
  121. ({ \
  122. register long __o0 __asm__ ("o0") = (long)(arg1); \
  123. register long __o1 __asm__ ("o1") = (long)(arg2); \
  124. register long __o2 __asm__ ("o2") = (long)(arg3); \
  125. register long __g1 __asm__ ("g1") = __NR_##name; \
  126. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  127. "0" (__g1), "1" (__o0), "r" (__o1), \
  128. "r" (__o2) : \
  129. __SYSCALL_CLOBBERS); \
  130. __o0; \
  131. })
  132. #define _INLINE_SYSCALL4(name,arg1,arg2,arg3,arg4) \
  133. ({ \
  134. register long __o0 __asm__ ("o0") = (long)(arg1); \
  135. register long __o1 __asm__ ("o1") = (long)(arg2); \
  136. register long __o2 __asm__ ("o2") = (long)(arg3); \
  137. register long __o3 __asm__ ("o3") = (long)(arg4); \
  138. register long __g1 __asm__ ("g1") = __NR_##name; \
  139. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  140. "0" (__g1), "1" (__o0), "r" (__o1), \
  141. "r" (__o2), "r" (__o3) : \
  142. __SYSCALL_CLOBBERS); \
  143. __o0; \
  144. })
  145. #define _INLINE_SYSCALL5(name,arg1,arg2,arg3,arg4,arg5) \
  146. ({ \
  147. register long __o0 __asm__ ("o0") = (long)(arg1); \
  148. register long __o1 __asm__ ("o1") = (long)(arg2); \
  149. register long __o2 __asm__ ("o2") = (long)(arg3); \
  150. register long __o3 __asm__ ("o3") = (long)(arg4); \
  151. register long __o4 __asm__ ("o4") = (long)(arg5); \
  152. register long __g1 __asm__ ("g1") = __NR_##name; \
  153. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  154. "0" (__g1), "1" (__o0), "r" (__o1), \
  155. "r" (__o2), "r" (__o3), "r" (__o4) : \
  156. __SYSCALL_CLOBBERS); \
  157. __o0; \
  158. })
  159. #define _INLINE_SYSCALL6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
  160. ({ \
  161. register long __o0 __asm__ ("o0") = (long)(arg1); \
  162. register long __o1 __asm__ ("o1") = (long)(arg2); \
  163. register long __o2 __asm__ ("o2") = (long)(arg3); \
  164. register long __o3 __asm__ ("o3") = (long)(arg4); \
  165. register long __o4 __asm__ ("o4") = (long)(arg5); \
  166. register long __o5 __asm__ ("o5") = (long)(arg6); \
  167. register long __g1 __asm__ ("g1") = __NR_##name; \
  168. __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
  169. "0" (__g1), "1" (__o0), "r" (__o1), \
  170. "r" (__o2), "r" (__o3), "r" (__o4), \
  171. "r" (__o5) : \
  172. __SYSCALL_CLOBBERS); \
  173. __o0; \
  174. })
  175. #endif /* __ASSEMBLER__ */
  176. #endif /* _BITS_SYSCALLS_H */