syscalls.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. #include <asm/traps.h>
  9. #define __syscall_return(type, res) \
  10. do { \
  11. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  12. \
  13. /* avoid using res which is declared to be in \
  14. register r2; errno might expand to a function \
  15. call and clobber it. */ \
  16. \
  17. int __err = -(res); \
  18. errno = __err; \
  19. res = -1; \
  20. } \
  21. return (type) (res); \
  22. } while (0)
  23. #define _syscall0(type,name) \
  24. type name(void) \
  25. { \
  26. long __res; \
  27. \
  28. __asm__ __volatile__ ( \
  29. \
  30. " \n\t" \
  31. \
  32. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  33. " movi r3, %1\n\t" /* __NR_##name */ \
  34. \
  35. " trap\n\t" \
  36. " mov %0, r2\n\t" /* syscall rtn */ \
  37. \
  38. " \n\t" \
  39. \
  40. : "=r" (__res) /* %0 */ \
  41. \
  42. : "i" (__NR_##name) /* %1 */ \
  43. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  44. \
  45. : "r2" /* Clobbered */ \
  46. , "r3" /* Clobbered */ \
  47. ); \
  48. \
  49. __syscall_return(type,__res); \
  50. }
  51. #define _syscall1(type,name,atype,a) \
  52. type name(atype a) \
  53. { \
  54. long __res; \
  55. \
  56. __asm__ __volatile__ ( \
  57. \
  58. " \n\t" \
  59. \
  60. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  61. " movi r3, %1\n\t" /* __NR_##name */ \
  62. " mov r4, %3\n\t" /* (long) a */ \
  63. \
  64. " trap\n\t" \
  65. " mov %0, r2\n\t" /* syscall rtn */ \
  66. \
  67. " \n\t" \
  68. \
  69. : "=r" (__res) /* %0 */ \
  70. \
  71. : "i" (__NR_##name) /* %1 */ \
  72. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  73. , "r" ((long) a) /* %3 */ \
  74. \
  75. : "r2" /* Clobbered */ \
  76. , "r3" /* Clobbered */ \
  77. , "r4" /* Clobbered */ \
  78. ); \
  79. \
  80. __syscall_return(type,__res); \
  81. }
  82. #define _syscall2(type,name,atype,a,btype,b) \
  83. type name(atype a,btype b) \
  84. { \
  85. long __res; \
  86. \
  87. __asm__ __volatile__ ( \
  88. \
  89. " \n\t" \
  90. \
  91. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  92. " movi r3, %1\n\t" /* __NR_##name */ \
  93. " mov r4, %3\n\t" /* (long) a */ \
  94. " mov r5, %4\n\t" /* (long) b */ \
  95. \
  96. " trap\n\t" \
  97. " mov %0, r2\n\t" /* syscall rtn */ \
  98. \
  99. " \n\t" \
  100. \
  101. : "=r" (__res) /* %0 */ \
  102. \
  103. : "i" (__NR_##name) /* %1 */ \
  104. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  105. , "r" ((long) a) /* %3 */ \
  106. , "r" ((long) b) /* %4 */ \
  107. \
  108. : "r2" /* Clobbered */ \
  109. , "r3" /* Clobbered */ \
  110. , "r4" /* Clobbered */ \
  111. , "r5" /* Clobbered */ \
  112. ); \
  113. \
  114. __syscall_return(type,__res); \
  115. }
  116. #define _syscall3(type,name,atype,a,btype,b,ctype,c) \
  117. type name(atype a,btype b,ctype c) \
  118. { \
  119. long __res; \
  120. \
  121. __asm__ __volatile__ ( \
  122. \
  123. " \n\t" \
  124. \
  125. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  126. " movi r3, %1\n\t" /* __NR_##name */ \
  127. " mov r4, %3\n\t" /* (long) a */ \
  128. " mov r5, %4\n\t" /* (long) b */ \
  129. " mov r6, %5\n\t" /* (long) c */ \
  130. \
  131. " trap\n\t" \
  132. " mov %0, r2\n\t" /* syscall rtn */ \
  133. \
  134. " \n\t" \
  135. \
  136. : "=r" (__res) /* %0 */ \
  137. \
  138. : "i" (__NR_##name) /* %1 */ \
  139. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  140. , "r" ((long) a) /* %3 */ \
  141. , "r" ((long) b) /* %4 */ \
  142. , "r" ((long) c) /* %5 */ \
  143. \
  144. : "r2" /* Clobbered */ \
  145. , "r3" /* Clobbered */ \
  146. , "r4" /* Clobbered */ \
  147. , "r5" /* Clobbered */ \
  148. , "r6" /* Clobbered */ \
  149. ); \
  150. \
  151. __syscall_return(type,__res); \
  152. }
  153. #define _syscall4(type,name,atype,a,btype,b,ctype,c,dtype,d) \
  154. type name (atype a, btype b, ctype c, dtype d) \
  155. { \
  156. long __res; \
  157. \
  158. __asm__ __volatile__ ( \
  159. \
  160. " \n\t" \
  161. \
  162. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  163. " movi r3, %1\n\t" /* __NR_##name */ \
  164. " mov r4, %3\n\t" /* (long) a */ \
  165. " mov r5, %4\n\t" /* (long) b */ \
  166. " mov r6, %5\n\t" /* (long) c */ \
  167. " mov r7, %6\n\t" /* (long) d */ \
  168. \
  169. " trap\n\t" \
  170. " mov %0, r2\n\t" /* syscall rtn */ \
  171. \
  172. " \n\t" \
  173. \
  174. : "=r" (__res) /* %0 */ \
  175. \
  176. : "i" (__NR_##name) /* %1 */ \
  177. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  178. , "r" ((long) a) /* %3 */ \
  179. , "r" ((long) b) /* %4 */ \
  180. , "r" ((long) c) /* %5 */ \
  181. , "r" ((long) d) /* %6 */ \
  182. \
  183. : "r2" /* Clobbered */ \
  184. , "r3" /* Clobbered */ \
  185. , "r4" /* Clobbered */ \
  186. , "r5" /* Clobbered */ \
  187. , "r6" /* Clobbered */ \
  188. , "r7" /* Clobbered */ \
  189. ); \
  190. \
  191. __syscall_return(type,__res); \
  192. }
  193. #define _syscall5(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e) \
  194. type name (atype a,btype b,ctype c,dtype d,etype e) \
  195. { \
  196. long __res; \
  197. \
  198. __asm__ __volatile__ ( \
  199. \
  200. " \n\t" \
  201. \
  202. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  203. " movi r3, %1\n\t" /* __NR_##name */ \
  204. " mov r4, %3\n\t" /* (long) a */ \
  205. " mov r5, %4\n\t" /* (long) b */ \
  206. " mov r6, %5\n\t" /* (long) c */ \
  207. " mov r7, %6\n\t" /* (long) c */ \
  208. " mov r8, %7\n\t" /* (long) e */ \
  209. \
  210. " trap\n\t" \
  211. " mov %0, r2\n\t" /* syscall rtn */ \
  212. \
  213. " \n\t" \
  214. \
  215. : "=r" (__res) /* %0 */ \
  216. \
  217. : "i" (__NR_##name) /* %1 */ \
  218. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  219. , "r" ((long) a) /* %3 */ \
  220. , "r" ((long) b) /* %4 */ \
  221. , "r" ((long) c) /* %5 */ \
  222. , "r" ((long) d) /* %6 */ \
  223. , "r" ((long) e) /* %7 */ \
  224. \
  225. : "r2" /* Clobbered */ \
  226. , "r3" /* Clobbered */ \
  227. , "r4" /* Clobbered */ \
  228. , "r5" /* Clobbered */ \
  229. , "r6" /* Clobbered */ \
  230. , "r7" /* Clobbered */ \
  231. , "r8" /* Clobbered */ \
  232. ); \
  233. \
  234. __syscall_return(type,__res); \
  235. }
  236. #define _syscall6(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e,ftype,f) \
  237. type name (atype a,btype b,ctype c,dtype d,etype e,ftype f) \
  238. { \
  239. long __res; \
  240. \
  241. __asm__ __volatile__ ( \
  242. \
  243. " \n\t" \
  244. \
  245. " movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  246. " movi r3, %1\n\t" /* __NR_##name */ \
  247. " mov r4, %3\n\t" /* (long) a */ \
  248. " mov r5, %4\n\t" /* (long) b */ \
  249. " mov r6, %5\n\t" /* (long) c */ \
  250. " mov r7, %6\n\t" /* (long) c */ \
  251. " mov r8, %7\n\t" /* (long) e */ \
  252. " mov r9, %8\n\t" /* (long) f */ \
  253. \
  254. " trap\n\t" \
  255. " mov %0, r2\n\t" /* syscall rtn */ \
  256. \
  257. " \n\t" \
  258. \
  259. : "=r" (__res) /* %0 */ \
  260. \
  261. : "i" (__NR_##name) /* %1 */ \
  262. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  263. , "r" ((long) a) /* %3 */ \
  264. , "r" ((long) b) /* %4 */ \
  265. , "r" ((long) c) /* %5 */ \
  266. , "r" ((long) d) /* %6 */ \
  267. , "r" ((long) e) /* %7 */ \
  268. , "r" ((long) f) /* %8 */ \
  269. \
  270. : "r2" /* Clobbered */ \
  271. , "r3" /* Clobbered */ \
  272. , "r4" /* Clobbered */ \
  273. , "r5" /* Clobbered */ \
  274. , "r6" /* Clobbered */ \
  275. , "r7" /* Clobbered */ \
  276. , "r8" /* Clobbered */ \
  277. , "r9" /* Clobbered */ \
  278. ); \
  279. \
  280. __syscall_return(type,__res); \
  281. }
  282. #endif /* __ASSEMBLER__ */
  283. #endif /* _BITS_SYSCALLS_H */