syscalls.h 7.3 KB

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