syscalls.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #define TRAP_ID_SYSCALL 0
  7. #ifndef __ASSEMBLER__
  8. #include <errno.h>
  9. #define __syscall_return(type, res) \
  10. do { \
  11. if (unlikely(INTERNAL_SYSCALL_ERROR_P(res, ))) { \
  12. __set_errno(INTERNAL_SYSCALL_ERRNO(res, )); \
  13. res = (unsigned long) -1; \
  14. } \
  15. return (type) (res); \
  16. } while (0)
  17. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  18. (__extension__ \
  19. ({ \
  20. long __res; \
  21. __asm__ __volatile__ ( \
  22. "movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \
  23. "movi r3, %1\n\t" /* __NR_##name */ \
  24. ASM_ARGS_##nr \
  25. "trap\n\t" \
  26. "mov %0, r2\n\t" /* syscall return */ \
  27. : "=r" (__res) /* %0 */ \
  28. : "i" (name) /* %1 */ \
  29. , "i" (TRAP_ID_SYSCALL) /* %2 */ \
  30. MAP_ARGS_##nr (args) /* %3-%8 */ \
  31. : "r2" \
  32. , "r3" \
  33. CLOB_ARGS_##nr /* Clobbered */ \
  34. ); \
  35. __res; \
  36. }) \
  37. )
  38. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  39. ((unsigned long)(val) >= (unsigned long)(-125))
  40. #define ASM_ARGS_0
  41. #define MAP_ARGS_0()
  42. #define CLOB_ARGS_0
  43. #define ASM_ARGS_1 \
  44. "mov r4, %3\n\t"
  45. #define MAP_ARGS_1(a) \
  46. , "r" ((long) a)
  47. #define CLOB_ARGS_1 \
  48. , "r4"
  49. #define ASM_ARGS_2 \
  50. ASM_ARGS_1 \
  51. "mov r5, %4\n\t"
  52. #define MAP_ARGS_2(a, b) \
  53. MAP_ARGS_1(a) \
  54. , "r" ((long) b)
  55. #define CLOB_ARGS_2 \
  56. CLOB_ARGS_1 \
  57. , "r5"
  58. #define ASM_ARGS_3 \
  59. ASM_ARGS_2 \
  60. "mov r6, %5\n\t"
  61. #define MAP_ARGS_3(a, b, c) \
  62. MAP_ARGS_2(a, b) \
  63. , "r" ((long) c)
  64. #define CLOB_ARGS_3 \
  65. CLOB_ARGS_2 \
  66. , "r6"
  67. #define ASM_ARGS_4 \
  68. ASM_ARGS_3 \
  69. "mov r7, %6\n\t"
  70. #define MAP_ARGS_4(a, b, c, d) \
  71. MAP_ARGS_3(a, b, c) \
  72. , "r" ((long) d)
  73. #define CLOB_ARGS_4 \
  74. CLOB_ARGS_3 \
  75. , "r7"
  76. #define ASM_ARGS_5 \
  77. ASM_ARGS_4 \
  78. "mov r8, %7\n\t"
  79. #define MAP_ARGS_5(a, b, c, d, e) \
  80. MAP_ARGS_4(a, b, c, d) \
  81. , "r" ((long) e)
  82. #define CLOB_ARGS_5 \
  83. CLOB_ARGS_4 \
  84. , "r8"
  85. #define ASM_ARGS_6 \
  86. ASM_ARGS_5 \
  87. "mov r9, %8\n\t"
  88. #define MAP_ARGS_6(a, b, c, d, e, f) \
  89. MAP_ARGS_5(a, b, c, d, e) \
  90. , "r" ((long) f)
  91. #define CLOB_ARGS_6 \
  92. CLOB_ARGS_5 \
  93. , "r9"
  94. #endif /* __ASSEMBLER__ */
  95. #endif /* _BITS_SYSCALLS_H */