syscalls.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Based on arm/bits/syscalls.h
  3. */
  4. #ifndef _BITS_SYSCALLS_H
  5. #define _BITS_SYSCALLS_H
  6. #ifndef _SYSCALL_H
  7. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  8. #endif
  9. /*
  10. Some of the sneaky macros in the code were taken from
  11. glibc-2.3.2/sysdeps/unix/sysv/linux/arm/sysdep.h
  12. */
  13. #ifdef __ASSEMBLER__
  14. /* TODO: recheck this */
  15. /* Call a given syscall, with arguments loaded. Unlike the DO_CALL
  16. macro in glibc, this macro does not load syscall arguments. */
  17. #undef DO_CALL
  18. #define DO_CALL(syscall_name) \
  19. l.lwz r11, =SYS_ify (syscall_name); \
  20. l.sys 1 \
  21. l.nop
  22. #else
  23. #include <errno.h>
  24. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  25. ({ unsigned long __sys_result; \
  26. { \
  27. register long __sc_ret __asm__ ("r11") = name; \
  28. LOAD_ARGS_##nr (args) \
  29. __asm__ __volatile__ ("l.sys 1" \
  30. : "=r" (__sc_ret) ASM_ARGS_OUT_##nr \
  31. : "0" (__sc_ret) ASM_ARGS_IN_##nr \
  32. : ASM_CLOBBERS_##nr \
  33. "r12", "r13", "r15", "r17", "r19", \
  34. "r21", "r23", "r25", "r27", "r29", \
  35. "r31"); \
  36. __asm__ __volatile__ ("l.nop"); \
  37. __sys_result = __sc_ret; \
  38. } \
  39. (long) __sys_result; })
  40. /* : "0", "1", "2", "3", "4", "5", "6", \ */
  41. /* : ASM_CLOBBERS_##nr, \ */
  42. #define LOAD_ARGS_0()
  43. #define ASM_ARGS_OUT_0
  44. #define ASM_ARGS_IN_0
  45. #define ASM_CLOBBERS_0 "r3", ASM_CLOBBERS_1
  46. #define LOAD_ARGS_1(a) \
  47. LOAD_ARGS_0 () \
  48. register long __a __asm__ ("r3") = (long)(a);
  49. #define ASM_ARGS_OUT_1 ASM_ARGS_OUT_0, "=r" (__a)
  50. #define ASM_ARGS_IN_1 ASM_ARGS_IN_0, "1" (__a)
  51. #define ASM_CLOBBERS_1 "r4", ASM_CLOBBERS_2
  52. #define LOAD_ARGS_2(a, b) \
  53. LOAD_ARGS_1 (a) \
  54. register long __b __asm__ ("r4") = (long)(b);
  55. #define ASM_ARGS_OUT_2 ASM_ARGS_OUT_1, "=r" (__b)
  56. #define ASM_ARGS_IN_2 ASM_ARGS_IN_1, "2" (__b)
  57. #define ASM_CLOBBERS_2 "r5", ASM_CLOBBERS_3
  58. #define LOAD_ARGS_3(a, b, c) \
  59. LOAD_ARGS_2 (a, b) \
  60. register long __c __asm__ ("r5") = (long)(c);
  61. #define ASM_ARGS_OUT_3 ASM_ARGS_OUT_2, "=r" (__c)
  62. #define ASM_ARGS_IN_3 ASM_ARGS_IN_2, "3" (__c)
  63. #define ASM_CLOBBERS_3 "r6", ASM_CLOBBERS_4
  64. #define LOAD_ARGS_4(a, b, c, d) \
  65. LOAD_ARGS_3 (a, b, c) \
  66. register long __d __asm__ ("r6") = (long)(d);
  67. #define ASM_ARGS_OUT_4 ASM_ARGS_OUT_3, "=r" (__d)
  68. #define ASM_ARGS_IN_4 ASM_ARGS_IN_3, "4" (__d)
  69. #define ASM_CLOBBERS_4 "r7", ASM_CLOBBERS_5
  70. #define LOAD_ARGS_5(a, b, c, d, e) \
  71. LOAD_ARGS_4 (a, b, c, d) \
  72. register long __e __asm__ ("r7") = (long)(e);
  73. #define ASM_ARGS_OUT_5 ASM_ARGS_OUT_4, "=r" (__e)
  74. #define ASM_ARGS_IN_5 ASM_ARGS_IN_4, "5" (__e)
  75. #define ASM_CLOBBERS_5 "r8", ASM_CLOBBERS_6
  76. #define LOAD_ARGS_6(a, b, c, d, e, f) \
  77. LOAD_ARGS_5 (a, b, c, d, e) \
  78. register long __f __asm__ ("r8") = (long)(f);
  79. #define ASM_ARGS_OUT_6 ASM_ARGS_OUT_5, "=r" (__f)
  80. #define ASM_ARGS_IN_6 ASM_ARGS_IN_5, "6" (__f)
  81. #define ASM_CLOBBERS_6
  82. #endif /* __ASSEMBLER__ */
  83. #endif /* _BITS_SYSCALLS_H */