syscalls.h 2.3 KB

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