sysdep.h 5.9 KB

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