syscalls.h 4.5 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. /* 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 - -125: see <asm-sh/errno.h> */
  18. #define __syscall_return(type, res) \
  19. do { \
  20. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  21. /* Avoid using "res" which is declared to be in register r0; \
  22. errno might expand to a function call and clobber it. */ \
  23. int __err = -(res); \
  24. __set_errno(__err); \
  25. res = -1; \
  26. } \
  27. return (type) (res); \
  28. } while (0)
  29. /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  30. #define _syscall0(type,name) \
  31. type name(void) \
  32. { \
  33. register long __sc0 __asm__ ("r3") = __NR_##name; \
  34. __asm__ __volatile__ ("trapa #0x10" \
  35. : "=z" (__sc0) \
  36. : "0" (__sc0) \
  37. : "memory" ); \
  38. __syscall_return(type,__sc0); \
  39. }
  40. #define _syscall1(type,name,type1,arg1) \
  41. type name(type1 arg1) \
  42. { \
  43. register long __sc0 __asm__ ("r3") = __NR_##name; \
  44. register long __sc4 __asm__ ("r4") = (long) arg1; \
  45. __asm__ __volatile__ ("trapa #0x11" \
  46. : "=z" (__sc0) \
  47. : "0" (__sc0), "r" (__sc4) \
  48. : "memory"); \
  49. __syscall_return(type,__sc0); \
  50. }
  51. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  52. type name(type1 arg1,type2 arg2) \
  53. { \
  54. register long __sc0 __asm__ ("r3") = __NR_##name; \
  55. register long __sc4 __asm__ ("r4") = (long) arg1; \
  56. register long __sc5 __asm__ ("r5") = (long) arg2; \
  57. __asm__ __volatile__ ("trapa #0x12" \
  58. : "=z" (__sc0) \
  59. : "0" (__sc0), "r" (__sc4), "r" (__sc5) \
  60. : "memory"); \
  61. __syscall_return(type,__sc0); \
  62. }
  63. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  64. type name(type1 arg1,type2 arg2,type3 arg3) \
  65. { \
  66. register long __sc0 __asm__ ("r3") = __NR_##name; \
  67. register long __sc4 __asm__ ("r4") = (long) arg1; \
  68. register long __sc5 __asm__ ("r5") = (long) arg2; \
  69. register long __sc6 __asm__ ("r6") = (long) arg3; \
  70. __asm__ __volatile__ ("trapa #0x13" \
  71. : "=z" (__sc0) \
  72. : "0" (__sc0), "r" (__sc4), "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 #0x14" \
  85. : "=z" (__sc0) \
  86. : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6), \
  87. "r" (__sc7) \
  88. : "memory" ); \
  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 long __sc3 __asm__ ("r3") = __NR_##name; \
  95. register long __sc4 __asm__ ("r4") = (long) arg1; \
  96. register long __sc5 __asm__ ("r5") = (long) arg2; \
  97. register long __sc6 __asm__ ("r6") = (long) arg3; \
  98. register long __sc7 __asm__ ("r7") = (long) arg4; \
  99. register long __sc0 __asm__ ("r0") = (long) arg5; \
  100. __asm__ __volatile__ ("trapa #0x15" \
  101. : "=z" (__sc0) \
  102. : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6), "r" (__sc7), \
  103. "r" (__sc3) \
  104. : "memory" ); \
  105. __syscall_return(type,__sc0); \
  106. }
  107. /* Add in _syscall6 which is not in the kernel header */
  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 long __sc3 __asm__ ("r3") = __NR_##name; \
  112. register long __sc4 __asm__ ("r4") = (long) arg1; \
  113. register long __sc5 __asm__ ("r5") = (long) arg2; \
  114. register long __sc6 __asm__ ("r6") = (long) arg3; \
  115. register long __sc7 __asm__ ("r7") = (long) arg4; \
  116. register long __sc0 __asm__ ("r0") = (long) arg5; \
  117. register long __sc1 __asm__ ("r1") = (long) arg6; \
  118. __asm__ __volatile__ ("trapa #0x16" \
  119. : "=z" (__sc0) \
  120. : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6), "r" (__sc7), \
  121. "r" (__sc3), "r" (__sc1) \
  122. : "memory" ); \
  123. __syscall_return(type,__sc0); \
  124. }
  125. #endif /* __ASSEMBLER__ */
  126. #endif /* _BITS_SYSCALLS_H */