sysdep.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Assembly macros for RISC-V.
  2. Copyright (C) 2011-2018
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _LINUX_RISCV_SYSDEP_H
  16. #define _LINUX_RISCV_SYSDEP_H 1
  17. #include <common/sysdep.h>
  18. #ifdef __ASSEMBLER__
  19. # include <sys/asm.h>
  20. # define ENTRY(name) LEAF(name)
  21. # define L(label) .L ## label
  22. /* Performs a system call, handling errors by setting errno. Linux indicates
  23. errors by setting a0 to a value between -1 and -4095. */
  24. # undef PSEUDO
  25. # define PSEUDO(name, syscall_name, args) \
  26. .text; \
  27. .align 2; \
  28. ENTRY (name); \
  29. li a7, SYS_ify (syscall_name); \
  30. scall; \
  31. li a7, -4096; \
  32. bgtu a0, a7, .Lsyscall_error ## name;
  33. # undef PSEUDO_END
  34. # define PSEUDO_END(sym) \
  35. SYSCALL_ERROR_HANDLER (sym) \
  36. ret; \
  37. END (sym)
  38. # if !IS_IN_libc
  39. # if defined (__PIC__)
  40. # define SYSCALL_ERROR_HANDLER(name) \
  41. .Lsyscall_error ## name: \
  42. la.tls.ie t1, errno; \
  43. add t1, t1, tp; \
  44. neg a0, a0; \
  45. sw a0, 0(t1); \
  46. li a0, -1;
  47. # else
  48. # define SYSCALL_ERROR_HANDLER(name) \
  49. .Lsyscall_error ## name: \
  50. lui t1, %tprel_hi(errno); \
  51. add t1, t1, tp, %tprel_add(errno); \
  52. neg a0, a0; \
  53. sw a0, %tprel_lo(errno)(t1); \
  54. li a0, -1;
  55. # endif
  56. # else
  57. # define SYSCALL_ERROR_HANDLER(name) \
  58. .Lsyscall_error ## name: \
  59. j __syscall_error;
  60. # endif
  61. /* Performs a system call, not setting errno. */
  62. # undef PSEUDO_NEORRNO
  63. # define PSEUDO_NOERRNO(name, syscall_name, args) \
  64. .align 2; \
  65. ENTRY (name); \
  66. li a7, SYS_ify (syscall_name); \
  67. scall;
  68. # undef PSEUDO_END_NOERRNO
  69. # define PSEUDO_END_NOERRNO(name) \
  70. END (name)
  71. # undef ret_NOERRNO
  72. # define ret_NOERRNO ret
  73. /* Perfroms a system call, returning the error code. */
  74. # undef PSEUDO_ERRVAL
  75. # define PSEUDO_ERRVAL(name, syscall_name, args) \
  76. PSEUDO_NOERRNO (name, syscall_name, args) \
  77. neg a0, a0;
  78. # undef PSEUDO_END_ERRVAL
  79. # define PSEUDO_END_ERRVAL(name) \
  80. END (name)
  81. # undef ret_ERRVAL
  82. # define ret_ERRVAL ret
  83. #endif /* __ASSEMBLER__ */
  84. /* In order to get __set_errno() definition in INLINE_SYSCALL. */
  85. #ifndef __ASSEMBLER__
  86. # include <errno.h>
  87. #endif
  88. #undef SYS_ify
  89. #define SYS_ify(syscall_name) __NR_##syscall_name
  90. #ifndef __ASSEMBLER__
  91. /* List of system calls which are supported as vsyscalls. */
  92. # define HAVE_CLOCK_GETRES_VSYSCALL 1
  93. # define HAVE_CLOCK_GETTIME_VSYSCALL 1
  94. # define HAVE_GETTIMEOFDAY_VSYSCALL 1
  95. # define HAVE_GETCPU_VSYSCALL 1
  96. extern long int __syscall_error (long int neg_errno);
  97. #endif /* ! __ASSEMBLER__ */
  98. #endif /* linux/riscv/sysdep.h */