syscalls.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #ifndef SYS_ify
  14. # define SYS_ify(syscall_name) (__NR_##syscall_name)
  15. #endif
  16. #ifndef __ASSEMBLER__
  17. /* user-visible error numbers are in the range -1 - -4095: see <asm-frv/errno.h> */
  18. #if defined _LIBC && !defined __set_errno
  19. # define __syscall_return(type, res) \
  20. do { \
  21. unsigned long __sr2 = (res); \
  22. if (__builtin_expect ((unsigned long)(__sr2) \
  23. >= (unsigned long)(-4095), 0)) { \
  24. extern int __syscall_error (int); \
  25. return (type) __syscall_error (__sr2); \
  26. } \
  27. return (type) (__sr2); \
  28. } while (0)
  29. #else
  30. # define __syscall_return(type, res) \
  31. do { \
  32. unsigned long __sr2 = (res); \
  33. if (__builtin_expect ((unsigned long)(__sr2) \
  34. >= (unsigned long)(-4095), 0)) { \
  35. __set_errno (-__sr2); \
  36. __sr2 = -1; \
  37. } \
  38. return (type) (__sr2); \
  39. } while (0)
  40. #endif
  41. #define _syscall0(type,name) \
  42. type name(void) { \
  43. long __res; \
  44. __asm__ __volatile__ ( \
  45. "p0 = %1;\n\t" \
  46. "excpt 0;\n\t" \
  47. "%0=r0;\n\t" \
  48. : "=da" (__res) \
  49. : "i" (__NR_##name) \
  50. : "CC", "P0"); \
  51. __syscall_return(type,__res); \
  52. }
  53. #define _syscall1(type,name,type1,arg1) \
  54. type name(type1 arg1) { \
  55. long __res; \
  56. __asm__ __volatile__ ( \
  57. "r0=%2;\n\t" \
  58. "p0=%1;\n\t" \
  59. "excpt 0;\n\t" \
  60. "%0=r0;\n\t" \
  61. : "=da" (__res) \
  62. : "i" (__NR_##name), \
  63. "a" ((long)(arg1)) \
  64. : "CC", "R0", "P0"); \
  65. __syscall_return(type,__res); \
  66. }
  67. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  68. type name(type1 arg1,type2 arg2) { \
  69. long __res; \
  70. __asm__ __volatile__ ( \
  71. "r1=%3;\n\t" \
  72. "r0=%2;\n\t" \
  73. "p0=%1;\n\t" \
  74. "excpt 0;\n\t" \
  75. "%0=r0;\n\t" \
  76. : "=da" (__res) \
  77. : "i" (__NR_##name), \
  78. "a" ((long)(arg1)), \
  79. "a" ((long)(arg2)) \
  80. : "CC", "R0","R1", "P0"); \
  81. __syscall_return(type,__res); \
  82. }
  83. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  84. type name(type1 arg1,type2 arg2,type3 arg3) { \
  85. long __res; \
  86. __asm__ __volatile__ ( \
  87. "r2=%4;\n\t" \
  88. "r1=%3;\n\t" \
  89. "r0=%2;\n\t" \
  90. "p0=%1;\n\t" \
  91. "excpt 0;\n\t" \
  92. "%0=r0;\n\t" \
  93. : "=da" (__res) \
  94. : "i" (__NR_##name), \
  95. "a" ((long)(arg1)), \
  96. "a" ((long)(arg2)), \
  97. "a" ((long)(arg3)) \
  98. : "CC", "R0","R1","R2", "P0"); \
  99. __syscall_return(type,__res); \
  100. }
  101. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
  102. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  103. long __res; \
  104. __asm__ __volatile__ ( \
  105. "[--sp] = r3;\n\t" \
  106. "r3=%5;\n\t" \
  107. "r2=%4;\n\t" \
  108. "r1=%3;\n\t" \
  109. "r0=%2;\n\t" \
  110. "p0=%1;\n\t" \
  111. "excpt 0;\n\t" \
  112. "%0=r0;\n\t" \
  113. "r3 = [sp++];\n\t" \
  114. : "=da" (__res) \
  115. : "i" (__NR_##name), \
  116. "a" ((long)(arg1)), \
  117. "a" ((long)(arg2)), \
  118. "a" ((long)(arg3)), \
  119. "a" ((long)(arg4)) \
  120. : "CC", "R0","R1","R2","R3", "P0"); \
  121. __syscall_return(type,__res); \
  122. }
  123. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  124. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  125. long __res; \
  126. __asm__ __volatile__ ( \
  127. "[--sp] = r4;\n\t" \
  128. "[--sp] = r3;\n\t" \
  129. "r4=%6;\n\t" \
  130. "r3=%5;\n\t" \
  131. "r2=%4;\n\t" \
  132. "r1=%3;\n\t" \
  133. "r0=%2;\n\t" \
  134. "P0=%1;\n\t" \
  135. "excpt 0;\n\t" \
  136. "%0=r0;\n\t" \
  137. "r3 = [sp++];\n\t" \
  138. "r4 = [sp++];\n\t" \
  139. : "=da" (__res) \
  140. : "i" (__NR_##name), \
  141. "rm" ((long)(arg1)), \
  142. "rm" ((long)(arg2)), \
  143. "rm" ((long)(arg3)), \
  144. "rm" ((long)(arg4)), \
  145. "rm" ((long)(arg5)) \
  146. : "CC","R0","R1","R2","R3","R4","P0"); \
  147. __syscall_return(type,__res); \
  148. }
  149. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
  150. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) { \
  151. long __res; \
  152. __asm__ __volatile__ ( \
  153. "[--sp] = r5;\n\t" \
  154. "[--sp] = r4;\n\t" \
  155. "[--sp] = r3;\n\t" \
  156. "r4=%6;\n\t" \
  157. "r3=%5;\n\t" \
  158. "r2=%4;\n\t" \
  159. "r1=%3;\n\t" \
  160. "r0=%2;\n\t" \
  161. "P0=%1;\n\t" \
  162. "excpt 0;\n\t" \
  163. "%0=r0;\n\t" \
  164. "r3 = [sp++];\n\t" \
  165. "r4 = [sp++];\n\t" \
  166. "r5 = [sp++];\n\t" \
  167. : "=da" (__res) \
  168. : "i" (__NR_##name), \
  169. "rm" ((long)(arg1)), \
  170. "rm" ((long)(arg2)), \
  171. "rm" ((long)(arg3)), \
  172. "rm" ((long)(arg4)), \
  173. "rm" ((long)(arg5)), \
  174. "rm" ((long)(arg6)) \
  175. : "CC","R0","R1","R2","R3","R4","R5","P0"); \
  176. __syscall_return(type,__res); \
  177. }
  178. #endif /* __ASSEMBLER__ */
  179. #endif /* _BITS_SYSCALLS_H */