syscalls.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifdef __ASSEMBLER__
  7. #undef DO_CALL
  8. #define DO_CALL(syscall_name, args) \
  9. DOARGS_##args \
  10. movi r2, SYS_ify(syscall_name); \
  11. trap;
  12. #define DOARGS_0 /* nothing */
  13. #define DOARGS_1 /* nothing */
  14. #define DOARGS_2 /* nothing */
  15. #define DOARGS_3 /* nothing */
  16. #define DOARGS_4 /* nothing */
  17. #define DOARGS_5 ldw r8, 0(sp);
  18. #define DOARGS_6 ldw r9, 4(sp); ldw r8, 0(sp);
  19. #else
  20. #include <errno.h>
  21. #undef INTERNAL_SYSCALL_DECL
  22. #define INTERNAL_SYSCALL_DECL(err) unsigned int err __attribute__((unused))
  23. #undef INTERNAL_SYSCALL_ERROR_P
  24. #define INTERNAL_SYSCALL_ERROR_P(val, err) ((void) (val), (unsigned int) (err))
  25. #undef INTERNAL_SYSCALL_ERRNO
  26. #define INTERNAL_SYSCALL_ERRNO(val, err) ((void) (err), val)
  27. #undef INTERNAL_SYSCALL_NCS
  28. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  29. ({ unsigned int _sys_result; \
  30. { \
  31. LOAD_ARGS_##nr (args) \
  32. LOAD_REGS_##nr \
  33. register int _r2 __asm__ ("r2") = (int)(name); \
  34. register int _sys_err __asm__ ("r7"); \
  35. __asm__ volatile ("trap" \
  36. : "+r" (_r2), "=r" (_sys_err) \
  37. : ASM_ARGS_##nr \
  38. : "memory"); \
  39. _sys_result = _r2; \
  40. err = _sys_err; \
  41. } \
  42. (int) _sys_result; })
  43. #define LOAD_ARGS_0()
  44. #define LOAD_REGS_0
  45. #define ASM_ARGS_0
  46. #define LOAD_ARGS_1(a1) \
  47. LOAD_ARGS_0 () \
  48. int __arg1 = (int) (a1);
  49. #define LOAD_REGS_1 \
  50. register int _r4 __asm__ ("r4") = __arg1; \
  51. LOAD_REGS_0
  52. #define ASM_ARGS_1 "r" (_r4)
  53. #define LOAD_ARGS_2(a1, a2) \
  54. LOAD_ARGS_1 (a1) \
  55. int __arg2 = (int) (a2);
  56. #define LOAD_REGS_2 \
  57. register int _r5 __asm__ ("r5") = __arg2; \
  58. LOAD_REGS_1
  59. #define ASM_ARGS_2 ASM_ARGS_1, "r" (_r5)
  60. #define LOAD_ARGS_3(a1, a2, a3) \
  61. LOAD_ARGS_2 (a1, a2) \
  62. int __arg3 = (int) (a3);
  63. #define LOAD_REGS_3 \
  64. register int _r6 __asm__ ("r6") = __arg3; \
  65. LOAD_REGS_2
  66. #define ASM_ARGS_3 ASM_ARGS_2, "r" (_r6)
  67. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  68. LOAD_ARGS_3 (a1, a2, a3) \
  69. int __arg4 = (int) (a4);
  70. #define LOAD_REGS_4 \
  71. register int _r7 __asm__ ("r7") = __arg4; \
  72. LOAD_REGS_3
  73. #define ASM_ARGS_4 ASM_ARGS_3, "r" (_r7)
  74. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  75. LOAD_ARGS_4 (a1, a2, a3, a4) \
  76. int __arg5 = (int) (a5);
  77. #define LOAD_REGS_5 \
  78. register int _r8 __asm__ ("r8") = __arg5; \
  79. LOAD_REGS_4
  80. #define ASM_ARGS_5 ASM_ARGS_4, "r" (_r8)
  81. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  82. LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
  83. int __arg6 = (int) (a6);
  84. #define LOAD_REGS_6 \
  85. register int _r9 __asm__ ("r9") = __arg6; \
  86. LOAD_REGS_5
  87. #define ASM_ARGS_6 ASM_ARGS_5, "r" (_r9)
  88. #endif /* __ASSEMBLER__ */
  89. #endif /* _BITS_SYSCALLS_H */