syscalls.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /*
  7. Some of the sneaky macros in the code were taken from
  8. glibc .../sysdeps/unix/sysv/linux/xtensa/sysdep.h
  9. */
  10. #ifdef __ASSEMBLER__
  11. /* The register layout upon entering the function is:
  12. return addr stack ptr arg0, arg1, arg2, arg3, arg4, arg5
  13. ----------- --------- ----------------------------------
  14. a0 a1 a2, a3, a4, a5, a6, a7
  15. (Of course a function with say 3 arguments does not have entries for
  16. arguments 4, 5, and 6.)
  17. Linux takes system-call arguments in registers. The ABI and Xtensa
  18. software conventions require the system-call number in a2. We move any
  19. argument that was in a2 to a7, and a7 to a8 if we have all 6 arguments.
  20. Note that for improved efficiency, we do NOT shift all parameters down
  21. one register to maintain the original order.
  22. syscall number arg0, arg1, arg2, arg3, arg4, arg5
  23. -------------- ----------------------------------
  24. a2 a6, a3, a4, a5, a8, a9
  25. Upon return, a2 and a3 are clobbered; all other registers are preserved. */
  26. #undef DO_CALL
  27. #define DO_CALL(syscall_name, nargs) \
  28. DO_ARGS_##nargs \
  29. movi a2, SYS_ify (syscall_name); \
  30. syscall
  31. #define DO_ARGS_0
  32. #define DO_ARGS_1 mov a6, a2;
  33. #define DO_ARGS_2 mov a6, a2;
  34. #define DO_ARGS_3 mov a6, a2;
  35. #define DO_ARGS_4 mov a6, a2;
  36. #define DO_ARGS_5 mov a8, a6; mov a6, a2;
  37. #define DO_ARGS_6 mov a9, a7; mov a8, a6; mov a6, a2;
  38. #else /* not __ASSEMBLER__ */
  39. #include <errno.h>
  40. #define STR(s) #s
  41. #define LD_ARG(n,ar) register int _a##n __asm__ (STR(a##n)) = (int) (ar)
  42. #define LD_ARGS_0()
  43. #define LD_ARGS_1(a0) LD_ARG(6,a0)
  44. #define LD_ARGS_2(a0,a1) LD_ARGS_1(a0); LD_ARG(3,a1)
  45. #define LD_ARGS_3(a0,a1,a2) LD_ARGS_2(a0,a1); LD_ARG(4,a2)
  46. #define LD_ARGS_4(a0,a1,a2,a3) LD_ARGS_3(a0,a1,a2); LD_ARG(5,a3)
  47. #define LD_ARGS_5(a0,a1,a2,a3,a4) LD_ARGS_4(a0,a1,a2,a3); LD_ARG(8,a4)
  48. #define LD_ARGS_6(a0,a1,a2,a3,a4,a5) LD_ARGS_5(a0,a1,a2,a3,a4); LD_ARG(9,a5)
  49. #define ASM_ARGS_0 "r"(_a2)
  50. #define ASM_ARGS_1 ASM_ARGS_0, "r"(_a6)
  51. #define ASM_ARGS_2 ASM_ARGS_1, "r"(_a3)
  52. #define ASM_ARGS_3 ASM_ARGS_2, "r"(_a4)
  53. #define ASM_ARGS_4 ASM_ARGS_3, "r"(_a5)
  54. #define ASM_ARGS_5 ASM_ARGS_4, "r"(_a8)
  55. #define ASM_ARGS_6 ASM_ARGS_5, "r"(_a9)
  56. /* Define a macro which expands into the inline wrapper code for a system
  57. call. */
  58. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  59. ({ LD_ARG(2, name); \
  60. LD_ARGS_##nr(args); \
  61. __asm__ __volatile__ ("syscall\n" \
  62. : "=a" (_a2) \
  63. : ASM_ARGS_##nr \
  64. : "memory"); \
  65. (long) _a2; })
  66. #endif /* not __ASSEMBLER__ */
  67. #endif /* _BITS_SYSCALLS_H */