syscalls.h 5.5 KB

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