syscalls.h 4.9 KB

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