syscalls.h 5.3 KB

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