syscalls.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. /* 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/syscall.h>
  10. #ifndef __set_errno
  11. # define __set_errno(val) { (*__errno_location ()) = (val); return -1; }
  12. #endif
  13. #ifndef SYS_ify
  14. # define SYS_ify(syscall_name) (__NR_##syscall_name)
  15. #endif
  16. #ifndef __ASSEMBLER__
  17. /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  18. #define _syscall0(type,name) \
  19. type name(void) \
  20. { \
  21. long __res, __err; \
  22. __asm__ volatile ("li\t$2,%2\n\t" \
  23. "syscall\n\t" \
  24. "move\t%0, $2\n\t" \
  25. "move\t%1, $7" \
  26. : "=r" (__res), "=r" (__err) \
  27. : "i" (__NR_##name) \
  28. : "$2","$7","$8","$9","$10","$11","$12","$13","$14","$15", \
  29. "$24"); \
  30. if (__err == 0) \
  31. return (type) __res; \
  32. __set_errno(__res); \
  33. }
  34. /*
  35. * DANGER: This macro isn't usable for the pipe(2) call
  36. * which has a unusual return convention.
  37. */
  38. #define _syscall1(type,name,atype,a) \
  39. type name(atype a) \
  40. { \
  41. long __res, __err; \
  42. __asm__ volatile ("move\t$4,%3\n\t" \
  43. "li\t$2,%2\n\t" \
  44. "syscall\n\t" \
  45. "move\t%0, $2\n\t" \
  46. "move\t%1, $7" \
  47. : "=r" (__res), "=r" (__err) \
  48. : "i" (__NR_##name),"r" ((long)(a)) \
  49. : "$2","$4","$7","$8","$9","$10","$11","$12","$13","$14","$15","$24"); \
  50. if (__err == 0) \
  51. return (type) __res; \
  52. __set_errno(__res); \
  53. }
  54. #define _syscall2(type,name,atype,a,btype,b) \
  55. type name(atype a,btype b) \
  56. { \
  57. long __res, __err; \
  58. __asm__ volatile ("move\t$4,%3\n\t" \
  59. "move\t$5,%4\n\t" \
  60. "li\t$2,%2\n\t" \
  61. "syscall\n\t" \
  62. "move\t%0, $2\n\t" \
  63. "move\t%1, $7" \
  64. : "=r" (__res), "=r" (__err) \
  65. : "i" (__NR_##name),"r" ((long)(a)), \
  66. "r" ((long)(b)) \
  67. : "$2","$4","$5","$7","$8","$9","$10","$11","$12","$13", \
  68. "$14","$15", "$24"); \
  69. if (__err == 0) \
  70. return (type) __res; \
  71. __set_errno(__res); \
  72. }
  73. #define _syscall3(type,name,atype,a,btype,b,ctype,c) \
  74. type name (atype a, btype b, ctype c) \
  75. { \
  76. long __res, __err; \
  77. __asm__ volatile ("move\t$4,%3\n\t" \
  78. "move\t$5,%4\n\t" \
  79. "move\t$6,%5\n\t" \
  80. "li\t$2,%2\n\t" \
  81. "syscall\n\t" \
  82. "move\t%0, $2\n\t" \
  83. "move\t%1, $7" \
  84. : "=r" (__res), "=r" (__err) \
  85. : "i" (__NR_##name),"r" ((long)(a)), \
  86. "r" ((long)(b)), \
  87. "r" ((long)(c)) \
  88. : "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \
  89. "$13","$14","$15","$24"); \
  90. if (__err == 0) \
  91. return (type) __res; \
  92. __set_errno(__res); \
  93. }
  94. #define _syscall4(type,name,atype,a,btype,b,ctype,c,dtype,d) \
  95. type name (atype a, btype b, ctype c, dtype d) \
  96. { \
  97. long __res, __err; \
  98. __asm__ volatile ("move\t$4,%3\n\t" \
  99. "move\t$5,%4\n\t" \
  100. "move\t$6,%5\n\t" \
  101. "move\t$7,%6\n\t" \
  102. "li\t$2,%2\n\t" \
  103. "syscall\n\t" \
  104. "move\t%0, $2\n\t" \
  105. "move\t%1, $7" \
  106. : "=r" (__res), "=r" (__err) \
  107. : "i" (__NR_##name),"r" ((long)(a)), \
  108. "r" ((long)(b)), \
  109. "r" ((long)(c)), \
  110. "r" ((long)(d)) \
  111. : "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \
  112. "$13","$14","$15","$24"); \
  113. if (__err == 0) \
  114. return (type) __res; \
  115. __set_errno(__res); \
  116. }
  117. #define _syscall5(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e) \
  118. type name (atype a,btype b,ctype c,dtype d,etype e) \
  119. { \
  120. long __res, __err; \
  121. __asm__ volatile ("move\t$4,%3\n\t" \
  122. "move\t$5,%4\n\t" \
  123. "move\t$6,%5\n\t" \
  124. "lw\t$2,%7\n\t" \
  125. "move\t$7,%6\n\t" \
  126. "subu\t$29,24\n\t" \
  127. "sw\t$2,16($29)\n\t" \
  128. "li\t$2,%2\n\t" \
  129. "syscall\n\t" \
  130. "move\t%0, $2\n\t" \
  131. "move\t%1, $7\n\t" \
  132. "addiu\t$29,24" \
  133. : "=r" (__res), "=r" (__err) \
  134. : "i" (__NR_##name),"r" ((long)(a)), \
  135. "r" ((long)(b)), \
  136. "r" ((long)(c)), \
  137. "r" ((long)(d)), \
  138. "m" ((long)(e)) \
  139. : "$2","$4","$5","$6","$7","$8","$9","$10","$11","$12", \
  140. "$13","$14","$15","$24"); \
  141. if (__err == 0) \
  142. return (type) __res; \
  143. __set_errno(__res); \
  144. }
  145. #define _syscall6(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f) \
  146. type name (atype a,btype b,ctype c,dtype d,etype e,ftype f) \
  147. { \
  148. long __res, __err; \
  149. __asm__ volatile ("move\t$4,%3\n\t" \
  150. "move\t$5,%4\n\t" \
  151. "move\t$6,%5\n\t" \
  152. "lw\t$2,%7\n\t" \
  153. "lw\t$3,%8\n\t" \
  154. "move\t$7,%6\n\t" \
  155. "subu\t$29,24\n\t" \
  156. "sw\t$2,16($29)\n\t" \
  157. "sw\t$3,20($29)\n\t" \
  158. "li\t$2,%2\n\t" \
  159. "syscall\n\t" \
  160. "move\t%0, $2\n\t" \
  161. "move\t%1, $7\n\t" \
  162. "addiu\t$29,24" \
  163. : "=r" (__res), "=r" (__err) \
  164. : "i" (__NR_##name),"r" ((long)(a)), \
  165. "r" ((long)(b)), \
  166. "r" ((long)(c)), \
  167. "r" ((long)(d)), \
  168. "m" ((long)(e)), \
  169. "m" ((long)(f)) \
  170. : "$2","$3","$4","$5","$6","$7","$8","$9","$10","$11", \
  171. "$12","$13","$14","$15","$24"); \
  172. if (__err == 0) \
  173. return (type) __res; \
  174. __set_errno(__res); \
  175. }
  176. #define _syscall7(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f,gtype,g) \
  177. type name (atype a,btype b,ctype c,dtype d,etype e,ftype f,gtype g) \
  178. { \
  179. long __res, __err; \
  180. __asm__ volatile ("move\t$4,%3\n\t" \
  181. "move\t$5,%4\n\t" \
  182. "move\t$6,%5\n\t" \
  183. "lw\t$2,%7\n\t" \
  184. "lw\t$3,%8\n\t" \
  185. "move\t$7,%6\n\t" \
  186. "subu\t$29,32\n\t" \
  187. "sw\t$2,16($29)\n\t" \
  188. "lw\t$2,%9\n\t" \
  189. "sw\t$3,20($29)\n\t" \
  190. "sw\t$2,24($29)\n\t" \
  191. "li\t$2,%2\n\t" \
  192. "syscall\n\t" \
  193. "move\t%0, $2\n\t" \
  194. "move\t%1, $7\n\t" \
  195. "addiu\t$29,32" \
  196. : "=r" (__res), "=r" (__err) \
  197. : "i" (__NR_##name),"r" ((long)(a)), \
  198. "r" ((long)(b)), \
  199. "r" ((long)(c)), \
  200. "r" ((long)(d)), \
  201. "m" ((long)(e)), \
  202. "m" ((long)(f)), \
  203. "m" ((long)(g)) \
  204. : "$2","$3","$4","$5","$6","$7","$8","$9","$10","$11", \
  205. "$12","$13","$14","$15","$24"); \
  206. if (__err == 0) \
  207. return (type) __res; \
  208. __set_errno(__res); \
  209. }
  210. #endif /* __ASSEMBLER__ */
  211. #endif /* _BITS_SYSCALLS_H */