syscalls.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #define __UCLIBC_MMAP_HAS_6_ARGS__
  7. #include <bits/wordsize.h>
  8. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  9. * header files. It also defines the traditional `SYS_<name>' macros for older
  10. * programs. */
  11. #include <bits/sysnum.h>
  12. #ifndef __set_errno
  13. # define __set_errno(val) (*__errno_location ()) = (val)
  14. #endif
  15. #ifndef __ASSEMBLER__
  16. #undef __SYSCALL_STRING
  17. #if __WORDSIZE == 32
  18. # define __SYSCALL_STRING \
  19. "t 0x10\n\t" \
  20. "bcc 1f\n\t" \
  21. "mov %%o0, %0\n\t" \
  22. "sub %%g0, %%o0, %0\n\t" \
  23. "1:\n\t"
  24. # define __SYSCALL_RES_CHECK (__res < -255 || __res >= 0)
  25. #elif __WORDSIZE == 64
  26. # define __SYSCALL_STRING \
  27. "t 0x6d\n\t" \
  28. "sub %%g0, %%o0, %0\n\t" \
  29. "movcc %%xcc, %%o0, %0\n\t"
  30. # define __SYSCALL_RES_CHECK (__res >= 0)
  31. #else
  32. # error unknown __WORDSIZE
  33. #endif
  34. #define __SYSCALL_RETURN(type) \
  35. if (__SYSCALL_RES_CHECK) \
  36. return (type) __res; \
  37. __set_errno (-__res); \
  38. return (type) -1;
  39. #undef _syscall0
  40. #define _syscall0(type,name) \
  41. type name(void) \
  42. { \
  43. long __res; \
  44. register long __g1 __asm__ ("g1") = __NR_##name; \
  45. __asm__ __volatile__ (__SYSCALL_STRING \
  46. : "=r" (__res)\
  47. : "r" (__g1) \
  48. : "o0", "cc"); \
  49. __SYSCALL_RETURN(type) \
  50. }
  51. #undef _syscall1
  52. #define _syscall1(type,name,type1,arg1) \
  53. type name(type1 arg1) \
  54. { \
  55. long __res; \
  56. register long __g1 __asm__ ("g1") = __NR_##name; \
  57. register long __o0 __asm__ ("o0") = (long)(arg1); \
  58. __asm__ __volatile__ (__SYSCALL_STRING \
  59. : "=r" (__res), "=&r" (__o0) \
  60. : "1" (__o0), "r" (__g1) \
  61. : "cc"); \
  62. __SYSCALL_RETURN(type) \
  63. }
  64. #undef _syscall2
  65. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  66. type name(type1 arg1,type2 arg2) \
  67. { \
  68. long __res; \
  69. register long __g1 __asm__ ("g1") = __NR_##name; \
  70. register long __o0 __asm__ ("o0") = (long)(arg1); \
  71. register long __o1 __asm__ ("o1") = (long)(arg2); \
  72. __asm__ __volatile__ (__SYSCALL_STRING \
  73. : "=r" (__res), "=&r" (__o0) \
  74. : "1" (__o0), "r" (__o1), "r" (__g1) \
  75. : "cc"); \
  76. __SYSCALL_RETURN(type) \
  77. }
  78. #undef _syscall3
  79. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  80. type name(type1 arg1,type2 arg2,type3 arg3) \
  81. { \
  82. long __res; \
  83. register long __g1 __asm__ ("g1") = __NR_##name; \
  84. register long __o0 __asm__ ("o0") = (long)(arg1); \
  85. register long __o1 __asm__ ("o1") = (long)(arg2); \
  86. register long __o2 __asm__ ("o2") = (long)(arg3); \
  87. __asm__ __volatile__ (__SYSCALL_STRING \
  88. : "=r" (__res), "=&r" (__o0) \
  89. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \
  90. : "cc"); \
  91. __SYSCALL_RETURN(type) \
  92. }
  93. #undef _syscall4
  94. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  95. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  96. { \
  97. long __res; \
  98. register long __g1 __asm__ ("g1") = __NR_##name; \
  99. register long __o0 __asm__ ("o0") = (long)(arg1); \
  100. register long __o1 __asm__ ("o1") = (long)(arg2); \
  101. register long __o2 __asm__ ("o2") = (long)(arg3); \
  102. register long __o3 __asm__ ("o3") = (long)(arg4); \
  103. __asm__ __volatile__ (__SYSCALL_STRING \
  104. : "=r" (__res), "=&r" (__o0) \
  105. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \
  106. : "cc"); \
  107. __SYSCALL_RETURN(type) \
  108. }
  109. #undef _syscall5
  110. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  111. type5,arg5) \
  112. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  113. { \
  114. long __res; \
  115. register long __g1 __asm__ ("g1") = __NR_##name; \
  116. register long __o0 __asm__ ("o0") = (long)(arg1); \
  117. register long __o1 __asm__ ("o1") = (long)(arg2); \
  118. register long __o2 __asm__ ("o2") = (long)(arg3); \
  119. register long __o3 __asm__ ("o3") = (long)(arg4); \
  120. register long __o4 __asm__ ("o4") = (long)(arg5); \
  121. __asm__ __volatile__ (__SYSCALL_STRING \
  122. : "=r" (__res), "=&r" (__o0) \
  123. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \
  124. : "cc"); \
  125. __SYSCALL_RETURN(type) \
  126. }
  127. #undef _syscall6
  128. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  129. type5,arg5,type6,arg6) \
  130. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
  131. { \
  132. long __res; \
  133. register long __g1 __asm__ ("g1") = __NR_##name; \
  134. register long __o0 __asm__ ("o0") = (long)(arg1); \
  135. register long __o1 __asm__ ("o1") = (long)(arg2); \
  136. register long __o2 __asm__ ("o2") = (long)(arg3); \
  137. register long __o3 __asm__ ("o3") = (long)(arg4); \
  138. register long __o4 __asm__ ("o4") = (long)(arg5); \
  139. register long __o5 __asm__ ("o5") = (long)(arg6); \
  140. __asm__ __volatile__ (__SYSCALL_STRING \
  141. : "=r" (__res), "=&r" (__o0) \
  142. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__o5), "r" (__g1) \
  143. : "cc"); \
  144. __SYSCALL_RETURN(type) \
  145. }
  146. #endif /* __ASSEMBLER__ */
  147. #endif /* _BITS_SYSCALLS_H */