syscalls.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 SYS_ify(syscall_name) (__NR_##syscall_name)
  9. #define INLINE_SYSCALL_NCS(name, nr, args...) \
  10. (__extension__ \
  11. ({ \
  12. unsigned int _inline_sys_result = INTERNAL_SYSCALL_NCS (name, , nr, args);\
  13. if (unlikely (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ))) \
  14. { \
  15. __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, )); \
  16. _inline_sys_result = (unsigned int) -1; \
  17. } \
  18. (int) _inline_sys_result; \
  19. }) \
  20. )
  21. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  22. (__extension__ \
  23. ({unsigned int __internal_sys_result; \
  24. { \
  25. register int __a1 __asm__ ("gr8"); \
  26. register int _nr __asm__ ("gr7"); \
  27. LOAD_ARGS_##nr (args) \
  28. _nr = (name); \
  29. __asm__ __volatile__ ("tra gr0,gr0" \
  30. : "=r" (__a1) \
  31. : "r" (_nr) ASM_ARGS_##nr \
  32. : "memory"); \
  33. __internal_sys_result = __a1; \
  34. } \
  35. (int) __internal_sys_result; }) \
  36. )
  37. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  38. ((unsigned int) (val) >= 0xfffff001u)
  39. #define LOAD_ARGS_0()
  40. #define ASM_ARGS_0
  41. #define LOAD_ARGS_1(a1) \
  42. int __a1tmp = (int) (a1); \
  43. LOAD_ARGS_0 () \
  44. __a1 = __a1tmp;
  45. #define ASM_ARGS_1 ASM_ARGS_0, "r" (__a1)
  46. #define LOAD_ARGS_2(a1, a2) \
  47. int __a2tmp = (int) (a2); \
  48. LOAD_ARGS_1 (a1) \
  49. register int __a2 __asm__ ("gr8") = __a2tmp;
  50. #define ASM_ARGS_2 ASM_ARGS_1, "r" (__a2)
  51. #define LOAD_ARGS_3(a1, a2, a3) \
  52. int __a3tmp = (int) (a3); \
  53. LOAD_ARGS_2 (a1, a2) \
  54. register int __a3 __asm__ ("gr9") = __a3tmp;
  55. #define ASM_ARGS_3 ASM_ARGS_2, "r" (__a3)
  56. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  57. int __a4tmp = (int) (a4); \
  58. LOAD_ARGS_3 (a1, a2, a3) \
  59. register int __a4 __asm__ ("gr10") = __a4tmp;
  60. #define ASM_ARGS_4 ASM_ARGS_3, "r" (__a4)
  61. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  62. int __v1tmp = (int) (a5); \
  63. LOAD_ARGS_4 (a1, a2, a3, a4) \
  64. register int __v1 __asm__ ("gr11") = __v1tmp;
  65. #define ASM_ARGS_5 ASM_ARGS_4, "r" (__v1)
  66. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  67. int __v2tmp = (int) (a6); \
  68. LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
  69. register int __v2 __asm__ ("gr12") = __v2tmp;
  70. #define ASM_ARGS_6 ASM_ARGS_5, "r" (__v2)
  71. #endif /* __ASSEMBLER__ */
  72. #endif /* _BITS_SYSCALLS_H */