syscalls.h 5.1 KB

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