syscalls.h 5.0 KB

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