syscalls.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* The Linux kernel uses different trap numbers on sh-2. */
  7. #ifdef __CONFIG_SH2__
  8. # define __SH_SYSCALL_TRAP_BASE 0x20
  9. #else
  10. # define __SH_SYSCALL_TRAP_BASE 0x10
  11. #endif
  12. #ifndef __ASSEMBLER__
  13. #include <errno.h>
  14. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  15. /* user-visible error numbers are in the range -1 - -125: see <asm-sh/errno.h> */
  16. #define __syscall_return(type, res) \
  17. do { \
  18. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  19. /* Avoid using "res" which is declared to be in register r0; \
  20. errno might expand to a function call and clobber it. */ \
  21. int __err = -(res); \
  22. __set_errno(__err); \
  23. res = -1; \
  24. } \
  25. return (type) (res); \
  26. } while (0)
  27. /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  28. #define _syscall0(type,name) \
  29. type name(void) \
  30. { \
  31. register long __sc0 __asm__ ("r3") = __NR_##name; \
  32. __asm__ __volatile__ ("trapa %1" \
  33. : "=z" (__sc0) \
  34. : "i" (__SH_SYSCALL_TRAP_BASE), "0" (__sc0) \
  35. : "memory" ); \
  36. __syscall_return(type,__sc0); \
  37. }
  38. #define _syscall1(type,name,type1,arg1) \
  39. type name(type1 arg1) \
  40. { \
  41. register long __sc0 __asm__ ("r3") = __NR_##name; \
  42. register long __sc4 __asm__ ("r4") = (long) arg1; \
  43. __asm__ __volatile__ ("trapa %1" \
  44. : "=z" (__sc0) \
  45. : "i" (__SH_SYSCALL_TRAP_BASE + 1), "0" (__sc0), "r" (__sc4) \
  46. : "memory"); \
  47. __syscall_return(type,__sc0); \
  48. }
  49. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  50. type name(type1 arg1,type2 arg2) \
  51. { \
  52. register long __sc0 __asm__ ("r3") = __NR_##name; \
  53. register long __sc4 __asm__ ("r4") = (long) arg1; \
  54. register long __sc5 __asm__ ("r5") = (long) arg2; \
  55. __asm__ __volatile__ ("trapa %1" \
  56. : "=z" (__sc0) \
  57. : "i" (__SH_SYSCALL_TRAP_BASE + 2), "0" (__sc0), "r" (__sc4), \
  58. "r" (__sc5) \
  59. : "memory"); \
  60. __syscall_return(type,__sc0); \
  61. }
  62. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  63. type name(type1 arg1,type2 arg2,type3 arg3) \
  64. { \
  65. register long __sc0 __asm__ ("r3") = __NR_##name; \
  66. register long __sc4 __asm__ ("r4") = (long) arg1; \
  67. register long __sc5 __asm__ ("r5") = (long) arg2; \
  68. register long __sc6 __asm__ ("r6") = (long) arg3; \
  69. __asm__ __volatile__ ("trapa %1" \
  70. : "=z" (__sc0) \
  71. : "i" (__SH_SYSCALL_TRAP_BASE + 3), "0" (__sc0), "r" (__sc4), \
  72. "r" (__sc5), "r" (__sc6) \
  73. : "memory"); \
  74. __syscall_return(type,__sc0); \
  75. }
  76. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  77. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  78. { \
  79. register long __sc0 __asm__ ("r3") = __NR_##name; \
  80. register long __sc4 __asm__ ("r4") = (long) arg1; \
  81. register long __sc5 __asm__ ("r5") = (long) arg2; \
  82. register long __sc6 __asm__ ("r6") = (long) arg3; \
  83. register long __sc7 __asm__ ("r7") = (long) arg4; \
  84. __asm__ __volatile__ ("trapa %1" \
  85. : "=z" (__sc0) \
  86. : "i" (__SH_SYSCALL_TRAP_BASE + 4), "0" (__sc0), "r" (__sc4), \
  87. "r" (__sc5), "r" (__sc6), \
  88. "r" (__sc7) \
  89. : "memory" ); \
  90. __syscall_return(type,__sc0); \
  91. }
  92. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  93. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
  94. { \
  95. register long __sc3 __asm__ ("r3") = __NR_##name; \
  96. register long __sc4 __asm__ ("r4") = (long) arg1; \
  97. register long __sc5 __asm__ ("r5") = (long) arg2; \
  98. register long __sc6 __asm__ ("r6") = (long) arg3; \
  99. register long __sc7 __asm__ ("r7") = (long) arg4; \
  100. register long __sc0 __asm__ ("r0") = (long) arg5; \
  101. __asm__ __volatile__ ("trapa %1" \
  102. : "=z" (__sc0) \
  103. : "i" (__SH_SYSCALL_TRAP_BASE + 5), "0" (__sc0), "r" (__sc4), \
  104. "r" (__sc5), "r" (__sc6), "r" (__sc7), "r" (__sc3) \
  105. : "memory" ); \
  106. __syscall_return(type,__sc0); \
  107. }
  108. #ifndef __SH_SYSCALL6_TRAPA
  109. #define __SH_SYSCALL6_TRAPA __SH_SYSCALL_TRAP_BASE + 6
  110. #endif
  111. /* Add in _syscall6 which is not in the kernel header */
  112. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
  113. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
  114. { \
  115. register long __sc3 __asm__ ("r3") = __NR_##name; \
  116. register long __sc4 __asm__ ("r4") = (long) arg1; \
  117. register long __sc5 __asm__ ("r5") = (long) arg2; \
  118. register long __sc6 __asm__ ("r6") = (long) arg3; \
  119. register long __sc7 __asm__ ("r7") = (long) arg4; \
  120. register long __sc0 __asm__ ("r0") = (long) arg5; \
  121. register long __sc1 __asm__ ("r1") = (long) arg6; \
  122. __asm__ __volatile__ ("trapa %1" \
  123. : "=z" (__sc0) \
  124. : "i" (__SH_SYSCALL6_TRAPA), "0" (__sc0), "r" (__sc4), \
  125. "r" (__sc5), "r" (__sc6), "r" (__sc7), "r" (__sc3), "r" (__sc1) \
  126. : "memory" ); \
  127. __syscall_return(type,__sc0); \
  128. }
  129. #endif /* __ASSEMBLER__ */
  130. #endif /* _BITS_SYSCALLS_H */