sysdep.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <sys/syscall.h>
  19. #ifdef __ASSEMBLER__
  20. # include <sys/asm.h>
  21. # define ENTRY(name) LEAF(name)
  22. # define L(label) .L ## label
  23. /* Performs a system call, handling errors by setting errno. Linux indicates
  24. errors by setting a0 to a value between -1 and -4095. */
  25. # undef PSEUDO
  26. # define PSEUDO(name, syscall_name, args) \
  27. .text; \
  28. .align 2; \
  29. ENTRY (name); \
  30. li a7, SYS_ify (syscall_name); \
  31. scall; \
  32. li a7, -4096; \
  33. bgtu a0, a7, .Lsyscall_error ## name;
  34. # undef PSEUDO_END
  35. # define PSEUDO_END(sym) \
  36. SYSCALL_ERROR_HANDLER (sym) \
  37. ret; \
  38. END (sym)
  39. # if !IS_IN_libc
  40. # if defined (__PIC__)
  41. # define SYSCALL_ERROR_HANDLER(name) \
  42. .Lsyscall_error ## name: \
  43. la.tls.ie t1, errno; \
  44. add t1, t1, tp; \
  45. neg a0, a0; \
  46. sw a0, 0(t1); \
  47. li a0, -1;
  48. # else
  49. # define SYSCALL_ERROR_HANDLER(name) \
  50. .Lsyscall_error ## name: \
  51. lui t1, %tprel_hi(errno); \
  52. add t1, t1, tp, %tprel_add(errno); \
  53. neg a0, a0; \
  54. sw a0, %tprel_lo(errno)(t1); \
  55. li a0, -1;
  56. # endif
  57. # else
  58. # define SYSCALL_ERROR_HANDLER(name) \
  59. .Lsyscall_error ## name: \
  60. j __syscall_error;
  61. # endif
  62. /* Performs a system call, not setting errno. */
  63. # undef PSEUDO_NEORRNO
  64. # define PSEUDO_NOERRNO(name, syscall_name, args) \
  65. .align 2; \
  66. ENTRY (name); \
  67. li a7, SYS_ify (syscall_name); \
  68. scall;
  69. # undef PSEUDO_END_NOERRNO
  70. # define PSEUDO_END_NOERRNO(name) \
  71. END (name)
  72. # undef ret_NOERRNO
  73. # define ret_NOERRNO ret
  74. /* Perfroms a system call, returning the error code. */
  75. # undef PSEUDO_ERRVAL
  76. # define PSEUDO_ERRVAL(name, syscall_name, args) \
  77. PSEUDO_NOERRNO (name, syscall_name, args) \
  78. neg a0, a0;
  79. # undef PSEUDO_END_ERRVAL
  80. # define PSEUDO_END_ERRVAL(name) \
  81. END (name)
  82. # undef ret_ERRVAL
  83. # define ret_ERRVAL ret
  84. #endif /* __ASSEMBLER__ */
  85. /* In order to get __set_errno() definition in INLINE_SYSCALL. */
  86. #ifndef __ASSEMBLER__
  87. # include <errno.h>
  88. #endif
  89. #undef SYS_ify
  90. #define SYS_ify(syscall_name) __NR_##syscall_name
  91. #ifndef __ASSEMBLER__
  92. /* List of system calls which are supported as vsyscalls. */
  93. # define HAVE_CLOCK_GETRES_VSYSCALL 1
  94. # define HAVE_CLOCK_GETTIME_VSYSCALL 1
  95. # define HAVE_GETTIMEOFDAY_VSYSCALL 1
  96. # define HAVE_GETCPU_VSYSCALL 1
  97. extern long int __syscall_error (long int neg_errno);
  98. #endif /* ! __ASSEMBLER__ */
  99. #endif /* linux/riscv/sysdep.h */