syscalls.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #include <bits/wordsize.h>
  7. #ifndef __ASSEMBLER__
  8. #include <errno.h>
  9. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  10. #undef __SYSCALL_STRING
  11. #if __WORDSIZE == 32
  12. # define __SYSCALL_STRING \
  13. "t 0x10\n\t" \
  14. "bcc 1f\n\t" \
  15. "mov %%o0, %0\n\t" \
  16. "sub %%g0, %%o0, %0\n\t" \
  17. "1:\n\t"
  18. # define __SYSCALL_RES_CHECK (__res < -255 || __res >= 0)
  19. #elif __WORDSIZE == 64
  20. # define __SYSCALL_STRING \
  21. "t 0x6d\n\t" \
  22. "sub %%g0, %%o0, %0\n\t" \
  23. "movcc %%xcc, %%o0, %0\n\t"
  24. # define __SYSCALL_RES_CHECK (__res >= 0)
  25. #else
  26. # error unknown __WORDSIZE
  27. #endif
  28. #define __SYSCALL_RETURN(type) \
  29. if (__SYSCALL_RES_CHECK) \
  30. return (type) __res; \
  31. __set_errno (-__res); \
  32. return (type) -1;
  33. #undef _syscall0
  34. #define _syscall0(type,name) \
  35. type name(void) \
  36. { \
  37. long __res; \
  38. register long __g1 __asm__ ("g1") = __NR_##name; \
  39. __asm__ __volatile__ (__SYSCALL_STRING \
  40. : "=r" (__res)\
  41. : "r" (__g1) \
  42. : "o0", "cc"); \
  43. __SYSCALL_RETURN(type) \
  44. }
  45. #undef _syscall1
  46. #define _syscall1(type,name,type1,arg1) \
  47. type name(type1 arg1) \
  48. { \
  49. long __res; \
  50. register long __g1 __asm__ ("g1") = __NR_##name; \
  51. register long __o0 __asm__ ("o0") = (long)(arg1); \
  52. __asm__ __volatile__ (__SYSCALL_STRING \
  53. : "=r" (__res), "=&r" (__o0) \
  54. : "1" (__o0), "r" (__g1) \
  55. : "cc"); \
  56. __SYSCALL_RETURN(type) \
  57. }
  58. #undef _syscall2
  59. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  60. type name(type1 arg1,type2 arg2) \
  61. { \
  62. long __res; \
  63. register long __g1 __asm__ ("g1") = __NR_##name; \
  64. register long __o0 __asm__ ("o0") = (long)(arg1); \
  65. register long __o1 __asm__ ("o1") = (long)(arg2); \
  66. __asm__ __volatile__ (__SYSCALL_STRING \
  67. : "=r" (__res), "=&r" (__o0) \
  68. : "1" (__o0), "r" (__o1), "r" (__g1) \
  69. : "cc"); \
  70. __SYSCALL_RETURN(type) \
  71. }
  72. #undef _syscall3
  73. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  74. type name(type1 arg1,type2 arg2,type3 arg3) \
  75. { \
  76. long __res; \
  77. register long __g1 __asm__ ("g1") = __NR_##name; \
  78. register long __o0 __asm__ ("o0") = (long)(arg1); \
  79. register long __o1 __asm__ ("o1") = (long)(arg2); \
  80. register long __o2 __asm__ ("o2") = (long)(arg3); \
  81. __asm__ __volatile__ (__SYSCALL_STRING \
  82. : "=r" (__res), "=&r" (__o0) \
  83. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \
  84. : "cc"); \
  85. __SYSCALL_RETURN(type) \
  86. }
  87. #undef _syscall4
  88. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  89. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  90. { \
  91. long __res; \
  92. register long __g1 __asm__ ("g1") = __NR_##name; \
  93. register long __o0 __asm__ ("o0") = (long)(arg1); \
  94. register long __o1 __asm__ ("o1") = (long)(arg2); \
  95. register long __o2 __asm__ ("o2") = (long)(arg3); \
  96. register long __o3 __asm__ ("o3") = (long)(arg4); \
  97. __asm__ __volatile__ (__SYSCALL_STRING \
  98. : "=r" (__res), "=&r" (__o0) \
  99. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \
  100. : "cc"); \
  101. __SYSCALL_RETURN(type) \
  102. }
  103. #undef _syscall5
  104. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  105. type5,arg5) \
  106. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  107. { \
  108. long __res; \
  109. register long __g1 __asm__ ("g1") = __NR_##name; \
  110. register long __o0 __asm__ ("o0") = (long)(arg1); \
  111. register long __o1 __asm__ ("o1") = (long)(arg2); \
  112. register long __o2 __asm__ ("o2") = (long)(arg3); \
  113. register long __o3 __asm__ ("o3") = (long)(arg4); \
  114. register long __o4 __asm__ ("o4") = (long)(arg5); \
  115. __asm__ __volatile__ (__SYSCALL_STRING \
  116. : "=r" (__res), "=&r" (__o0) \
  117. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \
  118. : "cc"); \
  119. __SYSCALL_RETURN(type) \
  120. }
  121. #undef _syscall6
  122. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  123. type5,arg5,type6,arg6) \
  124. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
  125. { \
  126. long __res; \
  127. register long __g1 __asm__ ("g1") = __NR_##name; \
  128. register long __o0 __asm__ ("o0") = (long)(arg1); \
  129. register long __o1 __asm__ ("o1") = (long)(arg2); \
  130. register long __o2 __asm__ ("o2") = (long)(arg3); \
  131. register long __o3 __asm__ ("o3") = (long)(arg4); \
  132. register long __o4 __asm__ ("o4") = (long)(arg5); \
  133. register long __o5 __asm__ ("o5") = (long)(arg6); \
  134. __asm__ __volatile__ (__SYSCALL_STRING \
  135. : "=r" (__res), "=&r" (__o0) \
  136. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__o5), "r" (__g1) \
  137. : "cc"); \
  138. __SYSCALL_RETURN(type) \
  139. }
  140. #endif /* __ASSEMBLER__ */
  141. #endif /* _BITS_SYSCALLS_H */