syscalls.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 ASMFMT_0
  9. #define ASMFMT_1 , "g"(er1)
  10. #define ASMFMT_2 , "g"(er1), "g"(er2)
  11. #define ASMFMT_3 , "g"(er1), "g"(er2), "g"(er3)
  12. #define ASMFMT_4 , "g"(er1), "g"(er2), "g"(er3), "g"(er4)
  13. #define ASMFMT_5 , "g"(er1), "g"(er2), "g"(er3), "g"(er4), "g"(er5)
  14. #define ASMFMT_6 , "g"(er1), "g"(er2), "g"(er3), "g"(er4), "m"(er5), "m"(er6)
  15. #define SUBSTITUTE_ARGS_0() do {} while(0);
  16. #define SUBSTITUTE_ARGS_1(arg1) \
  17. register long int er1 __asm__("er1") = (long int)arg1;
  18. #define SUBSTITUTE_ARGS_2(arg1, arg2) \
  19. register long int er1 __asm__("er1") = (long int)arg1; \
  20. register long int er2 __asm__("er2") = (long int)arg2;
  21. #define SUBSTITUTE_ARGS_3(arg1, arg2, arg3) \
  22. register long int er1 __asm__("er1") = (long int)arg1; \
  23. register long int er2 __asm__("er2") = (long int)arg2; \
  24. register long int er3 __asm__("er3") = (long int)arg3;
  25. #define SUBSTITUTE_ARGS_4(arg1, arg2, arg3, arg4) \
  26. register long int er1 __asm__("er1") = (long int)arg1; \
  27. register long int er2 __asm__("er2") = (long int)arg2; \
  28. register long int er3 __asm__("er3") = (long int)arg3; \
  29. register long int er4 __asm__("er4") = (long int)arg4;
  30. #define SUBSTITUTE_ARGS_5(arg1, arg2, arg3, arg4, arg5) \
  31. register long int er1 __asm__("er1") = (long int)arg1; \
  32. register long int er2 __asm__("er2") = (long int)arg2; \
  33. register long int er3 __asm__("er3") = (long int)arg3; \
  34. register long int er4 __asm__("er4") = (long int)arg4; \
  35. register long int er5 __asm__("er5") = (long int)arg5;
  36. #define SUBSTITUTE_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
  37. register long int er1 __asm__("er1") = (long int)arg1; \
  38. register long int er2 __asm__("er2") = (long int)arg2; \
  39. register long int er3 __asm__("er3") = (long int)arg3; \
  40. register long int er4 __asm__("er4") = (long int)arg4; \
  41. long int er5 = (long int)arg5; \
  42. long int er6 = (long int)arg6;
  43. #define LOAD_ARGS_0
  44. #define LOAD_ARGS_1
  45. #define LOAD_ARGS_2
  46. #define LOAD_ARGS_3
  47. #define LOAD_ARGS_4
  48. #define LOAD_ARGS_5
  49. #define LOAD_ARGS_6 "mov.l er5,@-sp\n\tmov.l %6,er5\n\t" \
  50. "mov.l er6,@-sp\n\tmov.l %7,er6\n\t"
  51. #define RESTORE_ARGS_0
  52. #define RESTORE_ARGS_1
  53. #define RESTORE_ARGS_2
  54. #define RESTORE_ARGS_3
  55. #define RESTORE_ARGS_4
  56. #define RESTORE_ARGS_5
  57. #define RESTORE_ARGS_6 "mov.l @sp+,er6\n\tmov.l @sp+,er5"
  58. /* The _NCS variant allows non-constant syscall numbers. */
  59. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  60. (__extension__ \
  61. ({ \
  62. register long int er0 __asm__ ("er0"); \
  63. SUBSTITUTE_ARGS_##nr(args) \
  64. __asm__ __volatile__ ( \
  65. LOAD_ARGS_##nr \
  66. "mov.l %1,er0\n\t" \
  67. "trapa #0\n\t" \
  68. RESTORE_ARGS_##nr \
  69. : "=r" (er0) \
  70. : "ir" (name) ASMFMT_##nr \
  71. : "memory" \
  72. ); \
  73. (int) er0; \
  74. }) \
  75. )
  76. #endif /* __ASSEMBLER__ */
  77. #endif /* _BITS_SYSCALLS_H */