syscalls.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2017 Hangzhou C-SKY Microsystems co.,ltd.
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
  5. * in this tarball.
  6. */
  7. #ifndef _BITS_SYSCALLS_H
  8. #define _BITS_SYSCALLS_H
  9. #ifndef _SYSCALL_H
  10. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  11. #endif
  12. #undef __NR_iopl
  13. #undef __NR_vm86
  14. /*
  15. Some of the sneaky macros in the code were taken from
  16. glibc-2.3.2/sysdeps/unix/sysv/linux/arm/sysdep.h
  17. */
  18. //#include <errno.h>
  19. #define INLINE_SYSCALL_NCS(name, nr, args...) \
  20. (__extension__ \
  21. ({ \
  22. unsigned int _inline_sys_result = INTERNAL_SYSCALL_NCS (name, , nr, args);\
  23. if (unlikely (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ))) \
  24. { \
  25. __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, )); \
  26. _inline_sys_result = (unsigned int) -1; \
  27. } \
  28. (int) _inline_sys_result; \
  29. }) \
  30. )
  31. #undef INTERNAL_SYSCALL_NCS
  32. #ifndef __cskyabiv2__
  33. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  34. ({unsigned int __sys_result; \
  35. { \
  36. register int _a1 __asm__ ("a0"), _nr __asm__ ("r1"); \
  37. LOAD_ARGS_##nr (args) \
  38. _nr = (name); \
  39. __asm__ __volatile__ ("trap 0 \n\t" \
  40. : "=r" (_a1) \
  41. : "r" (_nr) ASM_ARGS_##nr \
  42. : "memory"); \
  43. __sys_result = _a1; \
  44. } \
  45. (int) __sys_result; })
  46. #else /* __cskyabiv2__ */
  47. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  48. ({unsigned int __sys_result; \
  49. { \
  50. register int _a1 __asm__ ("a0"), _nr __asm__ ("r7"); \
  51. LOAD_ARGS_##nr (args) \
  52. _nr = (name); \
  53. __asm__ __volatile__ ("trap 0 \n\t" \
  54. : "=r" (_a1) \
  55. : "r" (_nr) ASM_ARGS_##nr \
  56. : "memory"); \
  57. __sys_result = _a1; \
  58. } \
  59. (int) __sys_result; })
  60. #endif /* __ABI_CSKY_V2__ */
  61. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  62. ((unsigned int) (val) >= 0xfffff001u)
  63. #define LOAD_ARGS_0()
  64. #define ASM_ARGS_0
  65. #define LOAD_ARGS_1(a1) \
  66. _a1 = (int) (a1); \
  67. LOAD_ARGS_0 ()
  68. #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
  69. #define LOAD_ARGS_2(a1, a2) \
  70. register int _a2 __asm__ ("a1") = (int) (a2); \
  71. LOAD_ARGS_1 (a1)
  72. #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
  73. #define LOAD_ARGS_3(a1, a2, a3) \
  74. register int _a3 __asm__ ("a2") = (int) (a3); \
  75. LOAD_ARGS_2 (a1, a2)
  76. #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
  77. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  78. register int _a4 __asm__ ("a3") = (int) (a4); \
  79. LOAD_ARGS_3 (a1, a2, a3)
  80. #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
  81. #ifndef __cskyabiv2__
  82. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  83. register int _v1 __asm__ ("a4") = (int) (a5); \
  84. LOAD_ARGS_4 (a1, a2, a3, a4)
  85. #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
  86. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  87. register int _v2 __asm__ ("a5") = (int) (a6); \
  88. LOAD_ARGS_5 (a1, a2, a3, a4, a5)
  89. #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
  90. #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
  91. register int _v3 __asm__ ("r8") = (int) (a7); \
  92. LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
  93. #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
  94. #else /* __cskyabiv2__ */
  95. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  96. register int _v1 __asm__ ("l0") = (int) (a5); \
  97. LOAD_ARGS_4 (a1, a2, a3, a4)
  98. #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
  99. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  100. register int _v2 __asm__ ("l1") = (int) (a6); \
  101. LOAD_ARGS_5 (a1, a2, a3, a4, a5)
  102. #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
  103. #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
  104. register int _v3 __asm__ ("l2") = (int) (a7); \
  105. LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
  106. #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
  107. #endif /* __ABI_CSKY_V2__ */
  108. #endif /* _BITS_SYSCALLS_H */