syscalls.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include <asm/unistd.h>
  2. #undef __NR
  3. #define __NR(n) #n
  4. #undef __syscall_return
  5. #define __syscall_return(type) \
  6. return (__sc_err & 0x10000000 ? errno = __sc_ret, __sc_ret = -1 : 0), \
  7. (type) __sc_ret
  8. #undef __syscall_clobbers
  9. #define __syscall_clobbers \
  10. "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12"
  11. #undef _syscall0
  12. #define _syscall0(type,name) \
  13. type name(void) \
  14. { \
  15. unsigned long __sc_ret, __sc_err; \
  16. { \
  17. register unsigned long __sc_0 __asm__ ("r0"); \
  18. register unsigned long __sc_3 __asm__ ("r3"); \
  19. \
  20. __sc_0 = __NR_##name; \
  21. __asm__ __volatile__ \
  22. ("sc \n\t" \
  23. "mfcr %1 " \
  24. : "=&r" (__sc_3), "=&r" (__sc_0) \
  25. : "0" (__sc_3), "1" (__sc_0) \
  26. : __syscall_clobbers); \
  27. __sc_ret = __sc_3; \
  28. __sc_err = __sc_0; \
  29. } \
  30. __syscall_return (type); \
  31. }
  32. #undef _syscall1
  33. #define _syscall1(type,name,type1,arg1) \
  34. type name(type1 arg1) \
  35. { \
  36. unsigned long __sc_ret, __sc_err; \
  37. { \
  38. register unsigned long __sc_0 __asm__ ("r0"); \
  39. register unsigned long __sc_3 __asm__ ("r3"); \
  40. \
  41. __sc_3 = (unsigned long) (arg1); \
  42. __sc_0 = __NR_##name; \
  43. __asm__ __volatile__ \
  44. ("sc \n\t" \
  45. "mfcr %1 " \
  46. : "=&r" (__sc_3), "=&r" (__sc_0) \
  47. : "0" (__sc_3), "1" (__sc_0) \
  48. : __syscall_clobbers); \
  49. __sc_ret = __sc_3; \
  50. __sc_err = __sc_0; \
  51. } \
  52. __syscall_return (type); \
  53. }
  54. #undef _syscall2
  55. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  56. type name(type1 arg1, type2 arg2) \
  57. { \
  58. unsigned long __sc_ret, __sc_err; \
  59. { \
  60. register unsigned long __sc_0 __asm__ ("r0"); \
  61. register unsigned long __sc_3 __asm__ ("r3"); \
  62. register unsigned long __sc_4 __asm__ ("r4"); \
  63. \
  64. __sc_3 = (unsigned long) (arg1); \
  65. __sc_4 = (unsigned long) (arg2); \
  66. __sc_0 = __NR_##name; \
  67. __asm__ __volatile__ \
  68. ("sc \n\t" \
  69. "mfcr %1 " \
  70. : "=&r" (__sc_3), "=&r" (__sc_0) \
  71. : "0" (__sc_3), "1" (__sc_0), \
  72. "r" (__sc_4) \
  73. : __syscall_clobbers); \
  74. __sc_ret = __sc_3; \
  75. __sc_err = __sc_0; \
  76. } \
  77. __syscall_return (type); \
  78. }
  79. #undef _syscall3
  80. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  81. type name(type1 arg1, type2 arg2, type3 arg3) \
  82. { \
  83. unsigned long __sc_ret, __sc_err; \
  84. { \
  85. register unsigned long __sc_0 __asm__ ("r0"); \
  86. register unsigned long __sc_3 __asm__ ("r3"); \
  87. register unsigned long __sc_4 __asm__ ("r4"); \
  88. register unsigned long __sc_5 __asm__ ("r5"); \
  89. \
  90. __sc_3 = (unsigned long) (arg1); \
  91. __sc_4 = (unsigned long) (arg2); \
  92. __sc_5 = (unsigned long) (arg3); \
  93. __sc_0 = __NR_##name; \
  94. __asm__ __volatile__ \
  95. ("sc \n\t" \
  96. "mfcr %1 " \
  97. : "=&r" (__sc_3), "=&r" (__sc_0) \
  98. : "0" (__sc_3), "1" (__sc_0), \
  99. "r" (__sc_4), \
  100. "r" (__sc_5) \
  101. : __syscall_clobbers); \
  102. __sc_ret = __sc_3; \
  103. __sc_err = __sc_0; \
  104. } \
  105. __syscall_return (type); \
  106. }
  107. #undef _syscall4
  108. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  109. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  110. { \
  111. unsigned long __sc_ret, __sc_err; \
  112. { \
  113. register unsigned long __sc_0 __asm__ ("r0"); \
  114. register unsigned long __sc_3 __asm__ ("r3"); \
  115. register unsigned long __sc_4 __asm__ ("r4"); \
  116. register unsigned long __sc_5 __asm__ ("r5"); \
  117. register unsigned long __sc_6 __asm__ ("r6"); \
  118. \
  119. __sc_3 = (unsigned long) (arg1); \
  120. __sc_4 = (unsigned long) (arg2); \
  121. __sc_5 = (unsigned long) (arg3); \
  122. __sc_6 = (unsigned long) (arg4); \
  123. __sc_0 = __NR_##name; \
  124. __asm__ __volatile__ \
  125. ("sc \n\t" \
  126. "mfcr %1 " \
  127. : "=&r" (__sc_3), "=&r" (__sc_0) \
  128. : "0" (__sc_3), "1" (__sc_0), \
  129. "r" (__sc_4), \
  130. "r" (__sc_5), \
  131. "r" (__sc_6) \
  132. : __syscall_clobbers); \
  133. __sc_ret = __sc_3; \
  134. __sc_err = __sc_0; \
  135. } \
  136. __syscall_return (type); \
  137. }
  138. #undef _syscall5
  139. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  140. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
  141. { \
  142. unsigned long __sc_ret, __sc_err; \
  143. { \
  144. register unsigned long __sc_0 __asm__ ("r0"); \
  145. register unsigned long __sc_3 __asm__ ("r3"); \
  146. register unsigned long __sc_4 __asm__ ("r4"); \
  147. register unsigned long __sc_5 __asm__ ("r5"); \
  148. register unsigned long __sc_6 __asm__ ("r6"); \
  149. register unsigned long __sc_7 __asm__ ("r7"); \
  150. \
  151. __sc_3 = (unsigned long) (arg1); \
  152. __sc_4 = (unsigned long) (arg2); \
  153. __sc_5 = (unsigned long) (arg3); \
  154. __sc_6 = (unsigned long) (arg4); \
  155. __sc_7 = (unsigned long) (arg5); \
  156. __sc_0 = __NR_##name; \
  157. __asm__ __volatile__ \
  158. ("sc \n\t" \
  159. "mfcr %1 " \
  160. : "=&r" (__sc_3), "=&r" (__sc_0) \
  161. : "0" (__sc_3), "1" (__sc_0), \
  162. "r" (__sc_4), \
  163. "r" (__sc_5), \
  164. "r" (__sc_6), \
  165. "r" (__sc_7) \
  166. : __syscall_clobbers); \
  167. __sc_ret = __sc_3; \
  168. __sc_err = __sc_0; \
  169. } \
  170. __syscall_return (type); \
  171. }