sysdep.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Assembly macros for LoongArch64.
  2. Copyright (C) 2024 uClibc-ng contributors.
  3. Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. #ifndef _LINUX_LOONGARCH64_SYSDEP_H
  6. #define _LINUX_LOONGARCH64_SYSDEP_H 1
  7. #include <common/sysdep.h>
  8. #include <sys/syscall.h>
  9. #ifdef __ASSEMBLER__
  10. # include <sys/asm.h>
  11. # define ENTRY(name) LEAF(name)
  12. # define L(label) .L ## label
  13. /* Performs a system call, handling errors by setting errno. Linux indicates
  14. errors by setting a0 to a value between -1 and -4095. */
  15. # undef PSEUDO
  16. # define PSEUDO(name, syscall_name, args) \
  17. .text; \
  18. .align 2; \
  19. ENTRY (name); \
  20. li.w a7, SYS_ify (syscall_name); \
  21. syscall 0; \
  22. li.d a7, -4096; \
  23. bgtu a0, a7, .Lsyscall_error ## name;
  24. # undef PSEUDO_END
  25. # define PSEUDO_END(sym) \
  26. SYSCALL_ERROR_HANDLER (sym) \
  27. jr ra; \
  28. END (sym)
  29. # if !IS_IN_libc
  30. # if defined (__PIC__)
  31. # define SYSCALL_ERROR_HANDLER(name) \
  32. .Lsyscall_error ## name: \
  33. sub.d a0, zero, a0; \
  34. la.tls.ie t1, errno; \
  35. add.d t1, t1, tp; \
  36. st.w a0, t1, 0; \
  37. li.w a0, -1;
  38. # else
  39. # define SYSCALL_ERROR_HANDLER(name) \
  40. .Lsyscall_error ## name: \
  41. sub.d a0, zero, a0; \
  42. la.tls.ie t1, errno; \
  43. add.d t1, t1, tp; \
  44. st.w a0, t1, 0; \
  45. li.w a0, -1;
  46. # endif
  47. # else
  48. # define SYSCALL_ERROR_HANDLER(name) \
  49. .Lsyscall_error ## name: \
  50. b __syscall_error;
  51. # endif
  52. /* Performs a system call, not setting errno. */
  53. # undef PSEUDO_NOERRNO
  54. # define PSEUDO_NOERRNO(name, syscall_name, args) \
  55. .align 2; \
  56. ENTRY (name); \
  57. li.w a7, SYS_ify (syscall_name); \
  58. syscall 0;
  59. # undef PSEUDO_END_NOERRNO
  60. # define PSEUDO_END_NOERRNO(name) \
  61. END (name)
  62. # undef ret_NOERRNO
  63. # define ret_NOERRNO jr ra
  64. /* Performs a system call, returning the error code. */
  65. # undef PSEUDO_ERRVAL
  66. # define PSEUDO_ERRVAL(name, syscall_name, args) \
  67. PSEUDO_NOERRNO (name, syscall_name, args) \
  68. sub.d a0, zero, a0;
  69. # undef PSEUDO_END_ERRVAL
  70. # define PSEUDO_END_ERRVAL(name) \
  71. END (name)
  72. # undef ret_ERRVAL
  73. # define ret_ERRVAL jr ra
  74. #endif /* __ASSEMBLER__ */
  75. /* In order to get __set_errno() definition in INLINE_SYSCALL. */
  76. #ifndef __ASSEMBLER__
  77. # include <errno.h>
  78. #endif
  79. #undef SYS_ify
  80. #define SYS_ify(syscall_name) __NR_##syscall_name
  81. #ifndef __ASSEMBLER__
  82. /* List of system calls which are supported as vsyscalls. */
  83. # define HAVE_CLOCK_GETRES_VSYSCALL 1
  84. # define HAVE_CLOCK_GETTIME_VSYSCALL 1
  85. # define HAVE_GETTIMEOFDAY_VSYSCALL 1
  86. # define HAVE_GETCPU_VSYSCALL 1
  87. extern long int __syscall_error (long int neg_errno);
  88. #endif /* ! __ASSEMBLER__ */
  89. #endif /* linux/loongarch64/sysdep.h */