syscalls.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscall.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. #undef _syscall_return
  10. #define _syscall_return(type) \
  11. do { \
  12. if ((unsigned long) (_sc_ret) >= (unsigned long) (-125)) { \
  13. __set_errno(-_sc_ret); \
  14. _sc_ret = -1; \
  15. } \
  16. \
  17. return (type) (_sc_ret); \
  18. } while (0)
  19. #define _syscall_clobbers \
  20. "r1", "r2", "r3", "r4", \
  21. "r5", "r6", "r7", "r8", \
  22. "r9", "r10", "r11"
  23. #ifdef _syscall0
  24. # undef _syscall0
  25. #endif
  26. #define _syscall0(type, name) \
  27. type name (void) \
  28. { \
  29. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  30. long _sc_ret; \
  31. \
  32. __asm__ __volatile__ ( \
  33. " pushl %%ap \n" \
  34. " pushl $0x0 \n" \
  35. " movl %%sp, %%ap \n" \
  36. " chmk %%r0 \n" \
  37. " addl2 $4, %%sp \n" \
  38. " movl (%%sp)+, %%ap \n" \
  39. : "=r" (_sc_0) \
  40. : "0" (_sc_0) \
  41. : _syscall_clobbers); \
  42. \
  43. _sc_ret = _sc_0; \
  44. _syscall_return (type); \
  45. }
  46. #ifdef _syscall1
  47. # undef _syscall1
  48. #endif
  49. #define _syscall1(type, name, type1, arg1) \
  50. type name (type1 arg1) \
  51. { \
  52. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  53. long _sc_ret; \
  54. \
  55. __asm__ __volatile__ ( \
  56. " pushl %%ap \n" \
  57. " pushl %2 \n" \
  58. " pushl $0x1 \n" \
  59. " movl %%sp, %%ap \n" \
  60. " chmk %%r0 \n" \
  61. " addl2 $8, %%sp \n" \
  62. " movl (%%sp)+, %%ap \n" \
  63. : "=r" (_sc_0) \
  64. : "0" (_sc_0), \
  65. "m" (arg1) \
  66. : _syscall_clobbers); \
  67. \
  68. _sc_ret = _sc_0; \
  69. _syscall_return (type); \
  70. }
  71. #ifdef _syscall2
  72. # undef _syscall2
  73. #endif
  74. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  75. type name (type1 arg1, \
  76. type2 arg2) \
  77. { \
  78. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  79. long _sc_ret; \
  80. \
  81. __asm__ __volatile__ ( \
  82. " pushl %%ap \n" \
  83. " pushl %3 \n" \
  84. " pushl %2 \n" \
  85. " pushl $0x2 \n" \
  86. " movl %%sp, %%ap \n" \
  87. " chmk %%r0 \n" \
  88. " addl2 $12, %%sp \n" \
  89. " movl (%%sp)+, %%ap \n" \
  90. : "=r" (_sc_0) \
  91. : "0" (_sc_0), \
  92. "m" (arg1), \
  93. "m" (arg2) \
  94. : _syscall_clobbers); \
  95. \
  96. _sc_ret = _sc_0; \
  97. _syscall_return (type); \
  98. }
  99. #ifdef _syscall3
  100. # undef _syscall3
  101. #endif
  102. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  103. type name (type1 arg1, \
  104. type2 arg2, \
  105. type3 arg3) \
  106. { \
  107. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  108. long _sc_ret; \
  109. \
  110. __asm__ __volatile__ ( \
  111. " pushl %%ap \n" \
  112. " pushl %4 \n" \
  113. " pushl %3 \n" \
  114. " pushl %2 \n" \
  115. " pushl $0x3 \n" \
  116. " movl %%sp, %%ap \n" \
  117. " chmk %%r0 \n" \
  118. " addl2 $16, %%sp \n" \
  119. " movl (%%sp)+, %%ap \n" \
  120. : "=r" (_sc_0) \
  121. : "0" (_sc_0), \
  122. "m" (arg1), \
  123. "m" (arg2), \
  124. "m" (arg3) \
  125. : _syscall_clobbers); \
  126. \
  127. _sc_ret = _sc_0; \
  128. _syscall_return (type); \
  129. }
  130. #ifdef _syscall4
  131. # undef _syscall4
  132. #endif
  133. #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
  134. type4, arg4) \
  135. type name (type1 arg1, \
  136. type2 arg2, \
  137. type3 arg3, \
  138. type4 arg4) \
  139. { \
  140. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  141. long _sc_ret; \
  142. \
  143. __asm__ __volatile__ ( \
  144. " pushl %%ap \n" \
  145. " pushl %5 \n" \
  146. " pushl %4 \n" \
  147. " pushl %3 \n" \
  148. " pushl %2 \n" \
  149. " pushl $0x4 \n" \
  150. " movl %%sp, %%ap \n" \
  151. " chmk %%r0 \n" \
  152. " addl2 $20, %%sp \n" \
  153. " movl (%%sp)+, %%ap \n" \
  154. : "=r" (_sc_0) \
  155. : "0" (_sc_0), \
  156. "m" (arg1), \
  157. "m" (arg2), \
  158. "m" (arg3), \
  159. "m" (arg4) \
  160. : _syscall_clobbers); \
  161. \
  162. _sc_ret = _sc_0; \
  163. _syscall_return (type); \
  164. }
  165. #ifdef _syscall5
  166. # undef _syscall5
  167. #endif
  168. #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
  169. type4, arg4, type5, arg5) \
  170. type name (type1 arg1, \
  171. type2 arg2, \
  172. type3 arg3, \
  173. type4 arg4, \
  174. type5 arg5) \
  175. { \
  176. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  177. long _sc_ret; \
  178. \
  179. __asm__ __volatile__ ( \
  180. " pushl %%ap \n" \
  181. " pushl %6 \n" \
  182. " pushl %5 \n" \
  183. " pushl %4 \n" \
  184. " pushl %3 \n" \
  185. " pushl %2 \n" \
  186. " pushl $0x5 \n" \
  187. " movl %%sp, %%ap \n" \
  188. " chmk %%r0 \n" \
  189. " addl2 $24, %%sp \n" \
  190. " movl (%%sp)+, %%ap \n" \
  191. : "=r" (_sc_0) \
  192. : "0" (_sc_0), \
  193. "m" (arg1), \
  194. "m" (arg2), \
  195. "m" (arg3), \
  196. "m" (arg4), \
  197. "m" (arg5) \
  198. : _syscall_clobbers); \
  199. \
  200. _sc_ret = _sc_0; \
  201. _syscall_return (type); \
  202. }
  203. #ifdef _syscall6
  204. # undef _syscall6
  205. #endif
  206. #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
  207. type4, arg4, type5, arg5, type6, arg6) \
  208. type name (type1 arg1, \
  209. type2 arg2, \
  210. type3 arg3, \
  211. type4 arg4, \
  212. type5 arg5, \
  213. type6 arg6) \
  214. { \
  215. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  216. long _sc_ret; \
  217. \
  218. __asm__ __volatile__ ( \
  219. " pushl %%ap \n" \
  220. " pushl %7 \n" \
  221. " pushl %6 \n" \
  222. " pushl %5 \n" \
  223. " pushl %4 \n" \
  224. " pushl %3 \n" \
  225. " pushl %2 \n" \
  226. " pushl $0x6 \n" \
  227. " movl %%sp, %%ap \n" \
  228. " chmk %%r0 \n" \
  229. " addl2 $28, %%sp \n" \
  230. " movl (%%sp)+, %%ap \n" \
  231. : "=r" (_sc_0) \
  232. : "0" (_sc_0), \
  233. "m" (arg1), \
  234. "m" (arg2), \
  235. "m" (arg3), \
  236. "m" (arg4), \
  237. "m" (arg5), \
  238. "m" (arg6) \
  239. : _syscall_clobbers); \
  240. \
  241. _sc_ret = _sc_0; \
  242. _syscall_return (type); \
  243. }
  244. #endif /* __ASSEMBLER__ */
  245. #endif /* _BITS_SYSCALLS_H */