syscalls.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 <features.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. /* This code is mostly cut & paste from the uClinux bfin port */
  12. #ifndef __ASSEMBLER__
  13. #define __syscall_return(type, res) \
  14. do { \
  15. if ((unsigned long)(res) >= (unsigned long)(-125)) \
  16. { __set_errno(-(res)); \
  17. res = -1; \
  18. } \
  19. return (type) (res); \
  20. } while (0)
  21. #define _syscall0(type,name) \
  22. type name(void) { \
  23. long __res; \
  24. __asm__ __volatile__ ( \
  25. "p0 = %1;\n\t" \
  26. "excpt 0;\n\t" \
  27. "%0=r0;\n\t" \
  28. : "=da" (__res) \
  29. : "i" (__NR_##name) \
  30. : "CC", "P0"); \
  31. __syscall_return(type,__res); \
  32. }
  33. #define _syscall1(type,name,type1,arg1) \
  34. type name(type1 arg1) { \
  35. long __res; \
  36. __asm__ __volatile__ ( \
  37. "r0=%2;\n\t" \
  38. "p0=%1;\n\t" \
  39. "excpt 0;\n\t" \
  40. "%0=r0;\n\t" \
  41. : "=da" (__res) \
  42. : "i" (__NR_##name), \
  43. "a" ((long)(arg1)) \
  44. : "CC", "R0", "P0"); \
  45. __syscall_return(type,__res); \
  46. }
  47. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  48. type name(type1 arg1,type2 arg2) { \
  49. long __res; \
  50. __asm__ __volatile__ ( \
  51. "r1=%3;\n\t" \
  52. "r0=%2;\n\t" \
  53. "p0=%1;\n\t" \
  54. "excpt 0;\n\t" \
  55. "%0=r0;\n\t" \
  56. : "=da" (__res) \
  57. : "i" (__NR_##name), \
  58. "a" ((long)(arg1)), \
  59. "a" ((long)(arg2)) \
  60. : "CC", "R0","R1", "P0"); \
  61. __syscall_return(type,__res); \
  62. }
  63. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  64. type name(type1 arg1,type2 arg2,type3 arg3) { \
  65. long __res; \
  66. __asm__ __volatile__ ( \
  67. "r2=%4;\n\t" \
  68. "r1=%3;\n\t" \
  69. "r0=%2;\n\t" \
  70. "p0=%1;\n\t" \
  71. "excpt 0;\n\t" \
  72. "%0=r0;\n\t" \
  73. : "=da" (__res) \
  74. : "i" (__NR_##name), \
  75. "a" ((long)(arg1)), \
  76. "a" ((long)(arg2)), \
  77. "a" ((long)(arg3)) \
  78. : "CC", "R0","R1","R2", "P0"); \
  79. __syscall_return(type,__res); \
  80. }
  81. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
  82. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  83. long __res; \
  84. __asm__ __volatile__ ( \
  85. "[--sp] = r3;\n\t" \
  86. "r3=%5;\n\t" \
  87. "r2=%4;\n\t" \
  88. "r1=%3;\n\t" \
  89. "r0=%2;\n\t" \
  90. "p0=%1;\n\t" \
  91. "excpt 0;\n\t" \
  92. "%0=r0;\n\t" \
  93. "r3 = [sp++];\n\t" \
  94. : "=da" (__res) \
  95. : "i" (__NR_##name), \
  96. "a" ((long)(arg1)), \
  97. "a" ((long)(arg2)), \
  98. "a" ((long)(arg3)), \
  99. "a" ((long)(arg4)) \
  100. : "CC", "R0","R1","R2","R3", "P0"); \
  101. __syscall_return(type,__res); \
  102. }
  103. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  104. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  105. long __res; \
  106. __asm__ __volatile__ ( \
  107. "[--sp] = r4;\n\t" \
  108. "[--sp] = r3;\n\t" \
  109. "r4=%6;\n\t" \
  110. "r3=%5;\n\t" \
  111. "r2=%4;\n\t" \
  112. "r1=%3;\n\t" \
  113. "r0=%2;\n\t" \
  114. "P0=%1;\n\t" \
  115. "excpt 0;\n\t" \
  116. "%0=r0;\n\t" \
  117. "r3 = [sp++];\n\t" \
  118. "r4 = [sp++];\n\t" \
  119. : "=da" (__res) \
  120. : "i" (__NR_##name), \
  121. "rm" ((long)(arg1)), \
  122. "rm" ((long)(arg2)), \
  123. "rm" ((long)(arg3)), \
  124. "rm" ((long)(arg4)), \
  125. "rm" ((long)(arg5)) \
  126. : "CC","R0","R1","R2","R3","R4","P0"); \
  127. __syscall_return(type,__res); \
  128. }
  129. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  130. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  131. long __res; \
  132. __asm__ __volatile__ ( \
  133. "[--sp] = r5;\n\t" \
  134. "[--sp] = r4;\n\t" \
  135. "[--sp] = r3;\n\t" \
  136. "r4=%6;\n\t" \
  137. "r3=%5;\n\t" \
  138. "r2=%4;\n\t" \
  139. "r1=%3;\n\t" \
  140. "r0=%2;\n\t" \
  141. "P0=%1;\n\t" \
  142. "excpt 0;\n\t" \
  143. "%0=r0;\n\t" \
  144. "r3 = [sp++];\n\t" \
  145. "r4 = [sp++];\n\t" \
  146. "r5 = [sp++];\n\t" \
  147. : "=da" (__res) \
  148. : "i" (__NR_##name), \
  149. "rm" ((long)(arg1)), \
  150. "rm" ((long)(arg2)), \
  151. "rm" ((long)(arg3)), \
  152. "rm" ((long)(arg4)), \
  153. "rm" ((long)(arg5)), \
  154. "rm" ((long)(arg6)) \
  155. : "CC","R0","R1","R2","R3","R4","R5","P0"); \
  156. __syscall_return(type,__res); \
  157. }
  158. #endif /* __ASSEMBLER__ */
  159. #endif /* _BITS_SYSCALLS_H */