syscalls.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. : "memory","CC","R0","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. "rm" ((long)(arg1)) \
  64. : "memory","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. "rm" ((long)(arg1)), \
  79. "rm" ((long)(arg2)) \
  80. : "memory","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. "rm" ((long)(arg1)), \
  96. "rm" ((long)(arg2)), \
  97. "rm" ((long)(arg3)) \
  98. : "memory","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. "r3=%5;\n\t" \
  106. "r2=%4;\n\t" \
  107. "r1=%3;\n\t" \
  108. "r0=%2;\n\t" \
  109. "p0=%1;\n\t" \
  110. "excpt 0;\n\t" \
  111. "%0=r0;\n\t" \
  112. : "=da" (__res) \
  113. : "i" (__NR_##name), \
  114. "rm" ((long)(arg1)), \
  115. "rm" ((long)(arg2)), \
  116. "rm" ((long)(arg3)), \
  117. "rm" ((long)(arg4)) \
  118. : "memory","CC","R0","R1","R2","R3","P0"); \
  119. __syscall_return(type,__res); \
  120. }
  121. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  122. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  123. long __res; \
  124. __asm__ __volatile__ ( \
  125. "r4=%6;\n\t" \
  126. "r3=%5;\n\t" \
  127. "r2=%4;\n\t" \
  128. "r1=%3;\n\t" \
  129. "r0=%2;\n\t" \
  130. "P0=%1;\n\t" \
  131. "excpt 0;\n\t" \
  132. "%0=r0;\n\t" \
  133. : "=da" (__res) \
  134. : "i" (__NR_##name), \
  135. "rm" ((long)(arg1)), \
  136. "rm" ((long)(arg2)), \
  137. "rm" ((long)(arg3)), \
  138. "rm" ((long)(arg4)), \
  139. "rm" ((long)(arg5)) \
  140. : "memory","CC","R0","R1","R2","R3","R4","P0"); \
  141. __syscall_return(type,__res); \
  142. }
  143. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
  144. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) { \
  145. long __res; \
  146. __asm__ __volatile__ ( \
  147. "r5=%7;\n\t" \
  148. "r4=%6;\n\t" \
  149. "r3=%5;\n\t" \
  150. "r2=%4;\n\t" \
  151. "r1=%3;\n\t" \
  152. "r0=%2;\n\t" \
  153. "P0=%1;\n\t" \
  154. "excpt 0;\n\t" \
  155. "%0=r0;\n\t" \
  156. : "=da" (__res) \
  157. : "i" (__NR_##name), \
  158. "rm" ((long)(arg1)), \
  159. "rm" ((long)(arg2)), \
  160. "rm" ((long)(arg3)), \
  161. "rm" ((long)(arg4)), \
  162. "rm" ((long)(arg5)), \
  163. "rm" ((long)(arg6)) \
  164. : "memory","CC","R0","R1","R2","R3","R4","R5","P0"); \
  165. __syscall_return(type,__res); \
  166. }
  167. #endif /* __ASSEMBLER__ */
  168. #endif /* _BITS_SYSCALLS_H */