syscalls.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #include <errno.h>
  7. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  8. * header files. It also defines the traditional `SYS_<name>' macros for older
  9. * programs. */
  10. #include <bits/sysnum.h>
  11. /* m68k headers does stupid stuff with __NR_iopl / __NR_vm86:
  12. * #define __NR_iopl not supported
  13. * #define __NR_vm86 not supported
  14. */
  15. #undef __NR_iopl
  16. #undef __NR_vm86
  17. #ifndef __ASSEMBLER__
  18. /* Linux takes system call arguments in registers:
  19. syscall number %d0 call-clobbered
  20. arg 1 %d1 call-clobbered
  21. arg 2 %d2 call-saved
  22. arg 3 %d3 call-saved
  23. arg 4 %d4 call-saved
  24. arg 5 %d5 call-saved
  25. The stack layout upon entering the function is:
  26. 20(%sp) Arg# 5
  27. 16(%sp) Arg# 4
  28. 12(%sp) Arg# 3
  29. 8(%sp) Arg# 2
  30. 4(%sp) Arg# 1
  31. (%sp) Return address
  32. (Of course a function with say 3 arguments does not have entries for
  33. arguments 4 and 5.)
  34. Separate move's are faster than movem, but need more space. Since
  35. speed is more important, we don't use movem. Since %a0 and %a1 are
  36. scratch registers, we can use them for saving as well. */
  37. #define __syscall_return(type, res) \
  38. do { \
  39. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  40. /* avoid using res which is declared to be in register d0; \
  41. errno might expand to a function call and clobber it. */ \
  42. int __err = -(res); \
  43. __set_errno(__err); \
  44. res = -1; \
  45. } \
  46. return (type) (res); \
  47. } while (0)
  48. #define _syscall0(type, name) \
  49. type name(void) \
  50. { \
  51. long __res; \
  52. __asm__ __volatile__ ( \
  53. "movel %1, %%d0\n\t" \
  54. "trap #0\n\t" \
  55. "movel %%d0, %0" \
  56. : "=g" (__res) \
  57. : "i" (__NR_##name) \
  58. : "cc", "%d0"); \
  59. __syscall_return(type, __res); \
  60. }
  61. #define _syscall1(type, name, atype, a) \
  62. type name(atype a) \
  63. { \
  64. long __res; \
  65. __asm__ __volatile__ ( \
  66. "movel %2, %%d1\n\t" \
  67. "movel %1, %%d0\n\t" \
  68. "trap #0\n\t" \
  69. "movel %%d0, %0" \
  70. : "=g" (__res) \
  71. : "i" (__NR_##name), \
  72. "g" ((long)a) \
  73. : "cc", "%d0", "%d1"); \
  74. __syscall_return(type, __res); \
  75. }
  76. #define _syscall2(type, name, atype, a, btype, b) \
  77. type name(atype a, btype b) \
  78. { \
  79. long __res; \
  80. __asm__ __volatile__ ( \
  81. "movel %3, %%d2\n\t" \
  82. "movel %2, %%d1\n\t" \
  83. "movel %1, %%d0\n\t" \
  84. "trap #0\n\t" \
  85. "movel %%d0, %0" \
  86. : "=g" (__res) \
  87. : "i" (__NR_##name), \
  88. "a" ((long)a), \
  89. "g" ((long)b) \
  90. : "cc", "%d0", "%d1", "%d2"); \
  91. __syscall_return(type, __res); \
  92. }
  93. #define _syscall3(type, name, atype, a, btype, b, ctype, c) \
  94. type name(atype a, btype b, ctype c) \
  95. { \
  96. long __res; \
  97. __asm__ __volatile__ ( \
  98. "movel %4, %%d3\n\t" \
  99. "movel %3, %%d2\n\t" \
  100. "movel %2, %%d1\n\t" \
  101. "movel %1, %%d0\n\t" \
  102. "trap #0\n\t" \
  103. "movel %%d0, %0" \
  104. : "=g" (__res) \
  105. : "i" (__NR_##name), \
  106. "a" ((long)a), \
  107. "a" ((long)b), \
  108. "g" ((long)c) \
  109. : "cc", "%d0", "%d1", "%d2", "%d3"); \
  110. __syscall_return(type, __res); \
  111. }
  112. #define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
  113. type name(atype a, btype b, ctype c, dtype d) \
  114. { \
  115. long __res; \
  116. __asm__ __volatile__ ( \
  117. "movel %5, %%d4\n\t" \
  118. "movel %4, %%d3\n\t" \
  119. "movel %3, %%d2\n\t" \
  120. "movel %2, %%d1\n\t" \
  121. "movel %1, %%d0\n\t" \
  122. "trap #0\n\t" \
  123. "movel %%d0, %0" \
  124. : "=g" (__res) \
  125. : "i" (__NR_##name), \
  126. "a" ((long)a), \
  127. "a" ((long)b), \
  128. "a" ((long)c), \
  129. "g" ((long)d) \
  130. : "cc", "%d0", "%d1", "%d2", "%d3", \
  131. "%d4"); \
  132. __syscall_return(type, __res); \
  133. }
  134. #define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e) \
  135. type name(atype a, btype b, ctype c, dtype d, etype e) \
  136. { \
  137. long __res; \
  138. __asm__ __volatile__ ( \
  139. "movel %6, %%d5\n\t" \
  140. "movel %5, %%d4\n\t" \
  141. "movel %4, %%d3\n\t" \
  142. "movel %3, %%d2\n\t" \
  143. "movel %2, %%d1\n\t" \
  144. "movel %1, %%d0\n\t" \
  145. "trap #0\n\t" \
  146. "movel %%d0, %0" \
  147. : "=g" (__res) \
  148. : "i" (__NR_##name), \
  149. "a" ((long)a), \
  150. "a" ((long)b), \
  151. "a" ((long)c), \
  152. "a" ((long)d), \
  153. "g" ((long)e) \
  154. : "cc", "%d0", "%d1", "%d2", "%d3", \
  155. "%d4", "%d5"); \
  156. __syscall_return(type, __res); \
  157. }
  158. #define _syscall6(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e, ftype, f) \
  159. type name(atype a, btype b, ctype c, dtype d, etype e, ftype f) \
  160. { \
  161. long __res; \
  162. __asm__ __volatile__ ( \
  163. "movel %7, %%a0\n\t" \
  164. "movel %6, %%d5\n\t" \
  165. "movel %5, %%d4\n\t" \
  166. "movel %4, %%d3\n\t" \
  167. "movel %3, %%d2\n\t" \
  168. "movel %2, %%d1\n\t" \
  169. "movel %1, %%d0\n\t" \
  170. "trap #0\n\t" \
  171. "movel %%d0, %0" \
  172. : "=g" (__res) \
  173. : "i" (__NR_##name), \
  174. "a" ((long)a), \
  175. "a" ((long)b), \
  176. "a" ((long)c), \
  177. "a" ((long)d), \
  178. "g" ((long)e), \
  179. "g" ((long)f) \
  180. : "cc", "%d0", "%d1", "%d2", "%d3", \
  181. "%d4", "%d5", "%a0"); \
  182. __syscall_return(type, __res); \
  183. }
  184. #endif /* __ASSEMBLER__ */
  185. #endif /* _BITS_SYSCALLS_H */