syscalls.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2018 Kalray Inc.
  7. */
  8. #ifndef _BITS_SYSCALLS_H
  9. #define _BITS_SYSCALLS_H
  10. #ifndef _SYSCALL_H
  11. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  12. #endif
  13. #ifndef __ASSEMBLER__
  14. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  15. ({ \
  16. register long _ret __asm__("r0"); \
  17. register unsigned long _scno __asm__("r6") = name; \
  18. LOAD_ARGS_##nr (args) \
  19. __asm__ __volatile__("scall %[r_scno]" \
  20. : "=r" (_ret) \
  21. : [r_scno] "r" (_scno) ASM_ARGS_##nr \
  22. : ASM_CLOBBER_##nr); \
  23. _ret; \
  24. })
  25. /* Mark all argument registers as per ABI in the range r1-r5 as
  26. clobbered when they are not used for the invocation of the scall */
  27. #define ASM_CLOBBER_6 "cc", "memory", \
  28. "r7", "r8", "r9", "r10", "r11", /* unused argument registers */ \
  29. "r15", /* struct pointer */ \
  30. "r16", "r17", /* veneer registers */ \
  31. "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", /* 32->63 are caller-saved */ \
  32. "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", \
  33. "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", \
  34. "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63"
  35. #define ASM_CLOBBER_5 "r5", ASM_CLOBBER_6
  36. #define ASM_CLOBBER_4 "r4", ASM_CLOBBER_5
  37. #define ASM_CLOBBER_3 "r3", ASM_CLOBBER_4
  38. #define ASM_CLOBBER_2 "r2", ASM_CLOBBER_3
  39. #define ASM_CLOBBER_1 "r1", ASM_CLOBBER_2
  40. #define ASM_CLOBBER_0 ASM_CLOBBER_1
  41. #define LOAD_ARGS_0()
  42. #define ASM_ARGS_0
  43. #define LOAD_ARGS_1(a1) \
  44. LOAD_ARGS_0(); \
  45. _ret = (long) a1;
  46. #define ASM_ARGS_1 ASM_ARGS_0, "r"(_ret)
  47. #define LOAD_ARGS_2(a1, a2) \
  48. LOAD_ARGS_1(a1); \
  49. register long _a2 __asm__("r1") = (long) a2;
  50. #define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2)
  51. #define LOAD_ARGS_3(a1, a2, a3) \
  52. LOAD_ARGS_2(a1, a2); \
  53. register long _a3 __asm__("r2") = (long) a3;
  54. #define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3)
  55. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  56. LOAD_ARGS_3(a1, a2, a3); \
  57. register long _a4 __asm__("r3") = (long) a4;
  58. #define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4)
  59. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  60. LOAD_ARGS_4(a1, a2, a3, a4); \
  61. register long _a5 __asm__("r4") = (long) a5;
  62. #define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5)
  63. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  64. LOAD_ARGS_5(a1, a2, a3, a4, a5); \
  65. register long _a6 __asm__("r5") = (long) a6;
  66. #define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6)
  67. #endif /* __ASSEMBLER__ */
  68. #endif /* _BITS_SYSCALLS_H */