sysdep.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Assembler macros for Xtensa processors.
  2. Copyright (C) 2001, 2007 Free Software Foundation, Inc.
  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. #include <sys/syscall.h>
  16. #ifdef __ASSEMBLER__
  17. #define ALIGNARG(log2) 1 << log2
  18. #define ASM_TYPE_DIRECTIVE(name, typearg) .type name, typearg
  19. #define ASM_SIZE_DIRECTIVE(name) .size name, . - name
  20. #ifdef __STDC__
  21. #define C_LABEL(name) name :
  22. #else
  23. #define C_LABEL(name) name/**/:
  24. #endif
  25. #define ENTRY(name) \
  26. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  27. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
  28. .align ALIGNARG(2); \
  29. LITERAL_POSITION; \
  30. C_LABEL(name) \
  31. entry sp, FRAMESIZE; \
  32. CALL_MCOUNT
  33. #define HIDDEN_ENTRY(name) \
  34. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  35. .hidden C_SYMBOL_NAME(name); \
  36. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
  37. .align ALIGNARG(2); \
  38. LITERAL_POSITION; \
  39. C_LABEL(name) \
  40. entry sp, FRAMESIZE; \
  41. CALL_MCOUNT
  42. #undef END
  43. #define END(name) ASM_SIZE_DIRECTIVE(name)
  44. /* Define a macro for this directive so it can be removed in a few places. */
  45. #define LITERAL_POSITION .literal_position
  46. #undef JUMPTARGET
  47. #ifdef __PIC__
  48. /* The "@PLT" suffix is currently a no-op for non-shared linking, but
  49. it doesn't hurt to use it conditionally for PIC code in case that
  50. changes someday. */
  51. #define JUMPTARGET(name) name##@PLT
  52. #else
  53. #define JUMPTARGET(name) name
  54. #endif
  55. #define FRAMESIZE 16
  56. #define CALL_MCOUNT /* Do nothing. */
  57. /* Linux uses a negative return value to indicate syscall errors,
  58. unlike most Unices, which use the condition codes' carry flag.
  59. Since version 2.1 the return value of a system call might be
  60. negative even if the call succeeded. E.g., the `lseek' system call
  61. might return a large offset. Therefore we must not anymore test
  62. for < 0, but test for a real error by making sure the value in a2
  63. is a real error number. Linus said he will make sure the no syscall
  64. returns a value in -1 .. -4095 as a valid result so we can safely
  65. test with -4095. */
  66. /* We don't want the label for the error handler to be global when we define
  67. it here. */
  68. #define SYSCALL_ERROR_LABEL 0f
  69. #undef PSEUDO
  70. #define PSEUDO(name, syscall_name, args) \
  71. .text; \
  72. ENTRY (name) \
  73. DO_CALL (syscall_name, args); \
  74. movi a4, -4095; \
  75. bgeu a2, a4, SYSCALL_ERROR_LABEL; \
  76. .Lpseudo_end:
  77. #undef PSEUDO_END
  78. #define PSEUDO_END(name) \
  79. SYSCALL_ERROR_HANDLER \
  80. END (name)
  81. #undef PSEUDO_NOERRNO
  82. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  83. .text; \
  84. ENTRY (name) \
  85. DO_CALL (syscall_name, args)
  86. #undef PSEUDO_END_NOERRNO
  87. #define PSEUDO_END_NOERRNO(name) \
  88. END (name)
  89. #undef ret_NOERRNO
  90. #define ret_NOERRNO retw
  91. /* The function has to return the error code. */
  92. #undef PSEUDO_ERRVAL
  93. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  94. .text; \
  95. ENTRY (name) \
  96. DO_CALL (syscall_name, args); \
  97. neg a2, a2
  98. #undef PSEUDO_END_ERRVAL
  99. #define PSEUDO_END_ERRVAL(name) \
  100. END (name)
  101. #undef ret_ERRVAL
  102. #define ret_ERRVAL retw
  103. #if defined RTLD_PRIVATE_ERRNO
  104. # define SYSCALL_ERROR_HANDLER \
  105. 0: movi a4, rtld_errno; \
  106. neg a2, a2; \
  107. s32i a2, a4, 0; \
  108. movi a2, -1; \
  109. j .Lpseudo_end;
  110. #elif defined _LIBC_REENTRANT
  111. # if defined USE___THREAD
  112. # ifndef NOT_IN_libc
  113. # define SYSCALL_ERROR_ERRNO __libc_errno
  114. # else
  115. # define SYSCALL_ERROR_ERRNO errno
  116. # endif
  117. # define SYSCALL_ERROR_HANDLER \
  118. 0: rur a4, THREADPTR; \
  119. movi a3, SYSCALL_ERROR_ERRNO@TPOFF; \
  120. neg a2, a2; \
  121. add a4, a4, a3; \
  122. s32i a2, a4, 0; \
  123. movi a2, -1; \
  124. j .Lpseudo_end;
  125. # else /* !USE___THREAD */
  126. # define SYSCALL_ERROR_HANDLER \
  127. 0: neg a2, a2; \
  128. mov a6, a2; \
  129. movi a4, __errno_location@PLT; \
  130. callx4 a4; \
  131. s32i a2, a6, 0; \
  132. movi a2, -1; \
  133. j .Lpseudo_end;
  134. # endif /* !USE___THREAD */
  135. #else /* !_LIBC_REENTRANT */
  136. #define SYSCALL_ERROR_HANDLER \
  137. 0: movi a4, errno; \
  138. neg a2, a2; \
  139. s32i a2, a4, 0; \
  140. movi a2, -1; \
  141. j .Lpseudo_end;
  142. #endif /* _LIBC_REENTRANT */
  143. #endif /* __ASSEMBLER__ */