syscalls.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  9. /* user-visible error numbers are in the range -1 - -4095: see <asm-frv/errno.h> */
  10. #if defined _LIBC && !defined __set_errno
  11. # define __syscall_return(type, res) \
  12. do { \
  13. unsigned long __sr2 = (res); \
  14. if (__builtin_expect ((unsigned long)(__sr2) \
  15. >= (unsigned long)(-4095), 0)) { \
  16. extern int __syscall_error (int); \
  17. return (type) __syscall_error (__sr2); \
  18. } \
  19. return (type) (__sr2); \
  20. } while (0)
  21. #else
  22. # define __syscall_return(type, res) \
  23. do { \
  24. unsigned long __sr2 = (res); \
  25. if (__builtin_expect ((unsigned long)(__sr2) \
  26. >= (unsigned long)(-4095), 0)) { \
  27. __set_errno (-__sr2); \
  28. __sr2 = -1; \
  29. } \
  30. return (type) (__sr2); \
  31. } while (0)
  32. #endif
  33. #ifndef __set_errno
  34. # define __set_errno(val) ((*__errno_location ()) = (val))
  35. #endif
  36. /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  37. #define _syscall0(type,name) \
  38. type name(void) \
  39. { \
  40. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  41. register unsigned long __sc0 __asm__ ("gr8"); \
  42. __asm__ __volatile__ ("tra gr0,gr0" \
  43. : "=r" (__sc0) \
  44. : "r" (__scnum)); \
  45. __syscall_return(type,__sc0); \
  46. }
  47. #define _syscall1(type,name,type1,arg1) \
  48. type name(type1 arg1) \
  49. { \
  50. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  51. register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \
  52. __asm__ __volatile__ ("tra gr0,gr0" \
  53. : "+r" (__sc0) \
  54. : "r" (__scnum)); \
  55. __syscall_return(type,__sc0); \
  56. }
  57. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  58. type name(type1 arg1,type2 arg2) \
  59. { \
  60. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  61. register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \
  62. register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \
  63. __asm__ __volatile__ ("tra gr0,gr0" \
  64. : "+r" (__sc0) \
  65. : "r" (__scnum), "r" (__sc1)); \
  66. __syscall_return(type,__sc0); \
  67. }
  68. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  69. type name(type1 arg1,type2 arg2,type3 arg3) \
  70. { \
  71. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  72. register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \
  73. register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \
  74. register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \
  75. __asm__ __volatile__ ("tra gr0,gr0" \
  76. : "+r" (__sc0) \
  77. : "r" (__scnum), "r" (__sc1), "r" (__sc2)); \
  78. __syscall_return(type,__sc0); \
  79. }
  80. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  81. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  82. { \
  83. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  84. register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \
  85. register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \
  86. register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \
  87. register unsigned long __sc3 __asm__ ("gr11") = (unsigned long) arg4; \
  88. __asm__ __volatile__ ("tra gr0,gr0" \
  89. : "+r" (__sc0) \
  90. : "r" (__scnum), "r" (__sc1), "r" (__sc2), "r" (__sc3)); \
  91. __syscall_return(type,__sc0); \
  92. }
  93. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  94. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
  95. { \
  96. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  97. register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \
  98. register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \
  99. register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \
  100. register unsigned long __sc3 __asm__ ("gr11") = (unsigned long) arg4; \
  101. register unsigned long __sc4 __asm__ ("gr12") = (unsigned long) arg5; \
  102. __asm__ __volatile__ ("tra gr0,gr0" \
  103. : "+r" (__sc0) \
  104. : "r" (__scnum), "r" (__sc1), "r" (__sc2), \
  105. "r" (__sc3), "r" (__sc4)); \
  106. __syscall_return(type,__sc0); \
  107. }
  108. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5, type6, arg6) \
  109. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
  110. { \
  111. register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \
  112. register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \
  113. register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \
  114. register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \
  115. register unsigned long __sc3 __asm__ ("gr11") = (unsigned long) arg4; \
  116. register unsigned long __sc4 __asm__ ("gr12") = (unsigned long) arg5; \
  117. register unsigned long __sc5 __asm__ ("gr13") = (unsigned long) arg6; \
  118. __asm__ __volatile__ ("tra gr0,gr0" \
  119. : "+r" (__sc0) \
  120. : "r" (__scnum), "r" (__sc1), "r" (__sc2), \
  121. "r" (__sc3), "r" (__sc4), "r" (__sc5)); \
  122. __syscall_return(type,__sc0); \
  123. }
  124. #endif /* __ASSEMBLER__ */
  125. #endif /* _BITS_SYSCALLS_H */