syscalls.h 5.5 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. /* The Linux kernel uses different trap numbers on sh-2. */
  7. #if defined __sh2__ || defined __SH2A__
  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 SYSCALL_INST_STR(x) "trapa #"__stringify(__SH_SYSCALL_TRAP_BASE + x)"\n\t"
  15. #define SYSCALL_INST_STR0 SYSCALL_INST_STR(0)
  16. #define SYSCALL_INST_STR1 SYSCALL_INST_STR(1)
  17. #define SYSCALL_INST_STR2 SYSCALL_INST_STR(2)
  18. #define SYSCALL_INST_STR3 SYSCALL_INST_STR(3)
  19. #define SYSCALL_INST_STR4 SYSCALL_INST_STR(4)
  20. #define SYSCALL_INST_STR5 SYSCALL_INST_STR(5)
  21. #define SYSCALL_INST_STR6 SYSCALL_INST_STR(6)
  22. # ifdef NEED_SYSCALL_INST_PAD
  23. # define SYSCALL_INST_PAD "\
  24. or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0"
  25. # else
  26. # define SYSCALL_INST_PAD
  27. # endif
  28. #define ASMFMT_0
  29. #define ASMFMT_1 \
  30. , "r" (r4)
  31. #define ASMFMT_2 \
  32. , "r" (r4), "r" (r5)
  33. #define ASMFMT_3 \
  34. , "r" (r4), "r" (r5), "r" (r6)
  35. #define ASMFMT_4 \
  36. , "r" (r4), "r" (r5), "r" (r6), "r" (r7)
  37. #define ASMFMT_5 \
  38. , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0)
  39. #define ASMFMT_6 \
  40. , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1)
  41. #define ASMFMT_7 \
  42. , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1), "r" (r2)
  43. #define SUBSTITUTE_ARGS_0()
  44. #define SUBSTITUTE_ARGS_1(arg1) \
  45. long int _arg1 = (long int) (arg1); \
  46. register long int r4 __asm__ ("%r4") = (long int) (_arg1)
  47. #define SUBSTITUTE_ARGS_2(arg1, arg2) \
  48. long int _arg1 = (long int) (arg1); \
  49. long int _arg2 = (long int) (arg2); \
  50. register long int r4 __asm__ ("%r4") = (long int) (_arg1); \
  51. register long int r5 __asm__ ("%r5") = (long int) (_arg2)
  52. #define SUBSTITUTE_ARGS_3(arg1, arg2, arg3) \
  53. long int _arg1 = (long int) (arg1); \
  54. long int _arg2 = (long int) (arg2); \
  55. long int _arg3 = (long int) (arg3); \
  56. register long int r4 __asm__ ("%r4") = (long int) (_arg1); \
  57. register long int r5 __asm__ ("%r5") = (long int) (_arg2); \
  58. register long int r6 __asm__ ("%r6") = (long int) (_arg3)
  59. #define SUBSTITUTE_ARGS_4(arg1, arg2, arg3, arg4) \
  60. long int _arg1 = (long int) (arg1); \
  61. long int _arg2 = (long int) (arg2); \
  62. long int _arg3 = (long int) (arg3); \
  63. long int _arg4 = (long int) (arg4); \
  64. register long int r4 __asm__ ("%r4") = (long int) (_arg1); \
  65. register long int r5 __asm__ ("%r5") = (long int) (_arg2); \
  66. register long int r6 __asm__ ("%r6") = (long int) (_arg3); \
  67. register long int r7 __asm__ ("%r7") = (long int) (_arg4)
  68. #define SUBSTITUTE_ARGS_5(arg1, arg2, arg3, arg4, arg5) \
  69. long int _arg1 = (long int) (arg1); \
  70. long int _arg2 = (long int) (arg2); \
  71. long int _arg3 = (long int) (arg3); \
  72. long int _arg4 = (long int) (arg4); \
  73. long int _arg5 = (long int) (arg5); \
  74. register long int r4 __asm__ ("%r4") = (long int) (_arg1); \
  75. register long int r5 __asm__ ("%r5") = (long int) (_arg2); \
  76. register long int r6 __asm__ ("%r6") = (long int) (_arg3); \
  77. register long int r7 __asm__ ("%r7") = (long int) (_arg4); \
  78. register long int r0 __asm__ ("%r0") = (long int) (_arg5)
  79. #define SUBSTITUTE_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
  80. long int _arg1 = (long int) (arg1); \
  81. long int _arg2 = (long int) (arg2); \
  82. long int _arg3 = (long int) (arg3); \
  83. long int _arg4 = (long int) (arg4); \
  84. long int _arg5 = (long int) (arg5); \
  85. long int _arg6 = (long int) (arg6); \
  86. register long int r4 __asm__ ("%r4") = (long int)(_arg1); \
  87. register long int r5 __asm__ ("%r5") = (long int) (_arg2); \
  88. register long int r6 __asm__ ("%r6") = (long int) (_arg3); \
  89. register long int r7 __asm__ ("%r7") = (long int) (_arg4); \
  90. register long int r0 __asm__ ("%r0") = (long int) (_arg5); \
  91. register long int r1 __asm__ ("%r1") = (long int) (_arg6)
  92. #define SUBSTITUTE_ARGS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
  93. long int _arg1 = (long int) (arg1); \
  94. long int _arg2 = (long int) (arg2); \
  95. long int _arg3 = (long int) (arg3); \
  96. long int _arg4 = (long int) (arg4); \
  97. long int _arg5 = (long int) (arg5); \
  98. long int _arg6 = (long int) (arg6); \
  99. long int _arg7 = (long int) (arg7); \
  100. register long int r4 __asm__ ("%r4") = (long int) (_arg1); \
  101. register long int r5 __asm__ ("%r5") = (long int) (_arg2); \
  102. register long int r6 __asm__ ("%r6") = (long int) (_arg3); \
  103. register long int r7 __asm__ ("%r7") = (long int) (_arg4); \
  104. register long int r0 __asm__ ("%r0") = (long int) (_arg5); \
  105. register long int r1 __asm__ ("%r1") = (long int) (_arg6); \
  106. register long int r2 __asm__ ("%r2") = (long int) (_arg7)
  107. /* The _NCS variant allows non-constant syscall numbers. */
  108. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  109. ({ \
  110. unsigned long int resultvar; \
  111. register long int r3 __asm__ ("%r3") = (name); \
  112. SUBSTITUTE_ARGS_##nr(args); \
  113. \
  114. __asm__ __volatile__ (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
  115. : "=z" (resultvar) \
  116. : "r" (r3) ASMFMT_##nr \
  117. : "memory"); \
  118. \
  119. (int) resultvar; })
  120. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  121. ((unsigned int) (val) >= 0xfffff001u)
  122. #endif /* __ASSEMBLER__ */
  123. #endif /* _BITS_SYSCALLS_H */