syscalls.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (C) 2016 by Waldemar Brodkorb <wbx@uclibc-ng.org>
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. * ported from GNU libc
  5. */
  6. /* Copyright (C) 2005-2016 Free Software Foundation, Inc.
  7. This file is part of the GNU C Library.
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public License as
  10. published by the Free Software Foundation; either version 2.1 of the
  11. License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with the GNU C Library; if not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef _BITS_SYSCALLS_H
  20. #define _BITS_SYSCALLS_H
  21. #ifndef _SYSCALL_H
  22. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  23. #endif
  24. #ifndef __ASSEMBLER__
  25. #include <errno.h>
  26. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  27. ({ long _sys_result; \
  28. { \
  29. register long _x8 __asm__ ("x8"); \
  30. LOAD_ARGS_##nr (args) \
  31. _x8 = (name); \
  32. \
  33. __asm__ volatile ( \
  34. "svc 0 // syscall " # name \
  35. : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr \
  36. : "memory"); \
  37. \
  38. _sys_result = _x0; \
  39. } \
  40. _sys_result; })
  41. /* Macros for setting up inline __asm__ input regs */
  42. # define ASM_ARGS_0
  43. # define ASM_ARGS_1 , "r" (_x0)
  44. # define ASM_ARGS_2 ASM_ARGS_1, "r" (_x1)
  45. # define ASM_ARGS_3 ASM_ARGS_2, "r" (_x2)
  46. # define ASM_ARGS_4 ASM_ARGS_3, "r" (_x3)
  47. # define ASM_ARGS_5 ASM_ARGS_4, "r" (_x4)
  48. # define ASM_ARGS_6 ASM_ARGS_5, "r" (_x5)
  49. # define ASM_ARGS_7 ASM_ARGS_6, "r" (_x6)
  50. /* Macros for converting sys-call wrapper args into sys call args */
  51. # define LOAD_ARGS_0() \
  52. register long _x0 __asm__ ("x0");
  53. # define LOAD_ARGS_1(x0) \
  54. long _x0tmp; \
  55. LOAD_ARGS_0 () \
  56. _x0tmp = (long) (x0); \
  57. _x0 = _x0tmp;
  58. # define LOAD_ARGS_2(x0, x1) \
  59. register long _x1 __asm__ ("x1"); \
  60. long _x1tmp; \
  61. LOAD_ARGS_1 (x0) \
  62. _x1tmp = (long) (x1); \
  63. _x1 = _x1tmp;
  64. # define LOAD_ARGS_3(x0, x1, x2) \
  65. register long _x2 __asm__ ("x2"); \
  66. long _x2tmp; \
  67. LOAD_ARGS_2 (x0, x1) \
  68. _x2tmp = (long) (x2); \
  69. _x2 = _x2tmp;
  70. # define LOAD_ARGS_4(x0, x1, x2, x3) \
  71. register long _x3 __asm__ ("x3"); \
  72. long _x3tmp; \
  73. LOAD_ARGS_3 (x0, x1, x2) \
  74. _x3tmp = (long) (x3); \
  75. _x3 = _x3tmp;
  76. # define LOAD_ARGS_5(x0, x1, x2, x3, x4) \
  77. register long _x4 __asm__ ("x4"); \
  78. long _x4tmp; \
  79. LOAD_ARGS_4 (x0, x1, x2, x3) \
  80. _x4tmp = (long) (x4); \
  81. _x4 = _x4tmp;
  82. # define LOAD_ARGS_6(x0, x1, x2, x3, x4, x5) \
  83. register long _x5 __asm__ ("x5"); \
  84. long _x5tmp; \
  85. LOAD_ARGS_5 (x0, x1, x2, x3, x4) \
  86. _x5tmp = (long) (x5); \
  87. _x5 = _x5tmp;
  88. # define LOAD_ARGS_7(x0, x1, x2, x3, x4, x5, x6)\
  89. register long _x6 __asm__ ("x6"); \
  90. long _x6tmp; \
  91. LOAD_ARGS_6 (x0, x1, x2, x3, x4, x5) \
  92. _x6tmp = (long) (x6); \
  93. _x6 = _x6tmp;
  94. #endif /* ! __ASSEMBLER__ */
  95. #endif /* _BITS_SYSCALLS_H */