syscalls.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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-sh64/errno.h> */
  18. #define __syscall_return(type, res) \
  19. do { \
  20. /* Note: when returning from kernel the return value is in r9 \
  21. ** This prevents conflicts between return value and arg1 \
  22. ** when dispatching signal handler, in other words makes \
  23. ** life easier in the system call epilogue (see entry.S) \
  24. */ \
  25. register unsigned long __sr2 __asm__ ("r2") = res; \
  26. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  27. errno = -(res); \
  28. __sr2 = -1; \
  29. } \
  30. return (type) (__sr2); \
  31. } while (0)
  32. /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  33. #define _syscall0(type,name) \
  34. type name(void) \
  35. { \
  36. register unsigned long __sc0 __asm__ ("r9") = ((0x10 << 16) | __NR_##name); \
  37. __asm__ __volatile__ ("trapa %1" \
  38. : "=r" (__sc0) \
  39. : "r" (__sc0) ); \
  40. __syscall_return(type,__sc0); \
  41. }
  42. #define _syscall1(type,name,type1,arg1) \
  43. type name(type1 arg1) \
  44. { \
  45. register unsigned long __sc0 __asm__ ("r9") = ((0x11 << 16) | __NR_##name); \
  46. register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
  47. __asm__ __volatile__ ("trapa %1" \
  48. : "=r" (__sc0) \
  49. : "r" (__sc0), "r" (__sc2)); \
  50. __syscall_return(type,__sc0); \
  51. }
  52. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  53. type name(type1 arg1,type2 arg2) \
  54. { \
  55. register unsigned long __sc0 __asm__ ("r9") = ((0x12 << 16) | __NR_##name); \
  56. register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
  57. register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
  58. __asm__ __volatile__ ("trapa %1" \
  59. : "=r" (__sc0) \
  60. : "r" (__sc0), "r" (__sc2), "r" (__sc3) ); \
  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 unsigned long __sc0 __asm__ ("r9") = ((0x13 << 16) | __NR_##name); \
  67. register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
  68. register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
  69. register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
  70. __asm__ __volatile__ ("trapa %1" \
  71. : "=r" (__sc0) \
  72. : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4) ); \
  73. __syscall_return(type,__sc0); \
  74. }
  75. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  76. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  77. { \
  78. register unsigned long __sc0 __asm__ ("r9") = ((0x14 << 16) | __NR_##name); \
  79. register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
  80. register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
  81. register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
  82. register unsigned long __sc5 __asm__ ("r5") = (unsigned long) arg4; \
  83. __asm__ __volatile__ ("trapa %1" \
  84. : "=r" (__sc0) \
  85. : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5) );\
  86. __syscall_return(type,__sc0); \
  87. }
  88. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  89. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
  90. { \
  91. register unsigned long __sc0 __asm__ ("r9") = ((0x15 << 16) | __NR_##name); \
  92. register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
  93. register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
  94. register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
  95. register unsigned long __sc5 __asm__ ("r5") = (unsigned long) arg4; \
  96. register unsigned long __sc6 __asm__ ("r6") = (unsigned long) arg5; \
  97. __asm__ __volatile__ ("trapa %1" \
  98. : "=r" (__sc0) \
  99. : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
  100. "r" (__sc6)); \
  101. __syscall_return(type,__sc0); \
  102. }
  103. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5, type6, arg6) \
  104. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
  105. { \
  106. register unsigned long __sc0 __asm__ ("r9") = ((0x16 << 16) | __NR_##name); \
  107. register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
  108. register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
  109. register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
  110. register unsigned long __sc5 __asm__ ("r5") = (unsigned long) arg4; \
  111. register unsigned long __sc6 __asm__ ("r6") = (unsigned long) arg5; \
  112. register unsigned long __sc7 __asm__ ("r7") = (unsigned long) arg6; \
  113. __asm__ __volatile__ ("trapa %1" \
  114. : "=r" (__sc0) \
  115. : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
  116. "r" (__sc6), "r" (__sc7)); \
  117. __syscall_return(type,__sc0); \
  118. }
  119. #endif /* __ASSEMBLER__ */
  120. #endif /* _BITS_SYSCALLS_H */