syscalls.h 4.8 KB

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