sysdep.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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_PREFIX(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. #define ENTRY(name) \
  39. ENTRY_PREFIX(name) \
  40. abi_entry(sp, FRAMESIZE);
  41. #define HIDDEN_ENTRY(name) \
  42. .globl C_SYMBOL_NAME(name); \
  43. .hidden C_SYMBOL_NAME(name); \
  44. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
  45. .align ALIGNARG(2); \
  46. LITERAL_POSITION; \
  47. C_LABEL(name) \
  48. abi_entry(sp, FRAMESIZE);
  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. /* Linux uses a negative return value to indicate syscall errors,
  80. unlike most Unices, which use the condition codes' carry flag.
  81. Since version 2.1 the return value of a system call might be
  82. negative even if the call succeeded. E.g., the `lseek' system call
  83. might return a large offset. Therefore we must not anymore test
  84. for < 0, but test for a real error by making sure the value in a2
  85. is a real error number. Linus said he will make sure the no syscall
  86. returns a value in -1 .. -4095 as a valid result so we can safely
  87. test with -4095. */
  88. /* We don't want the label for the error handler to be global when we define
  89. it here. */
  90. #define SYSCALL_ERROR_LABEL 0f
  91. #undef PSEUDO
  92. #define PSEUDO(name, syscall_name, args) \
  93. .text; \
  94. ENTRY (name) \
  95. DO_CALL (syscall_name, args); \
  96. movi a4, -4095; \
  97. bgeu a2, a4, SYSCALL_ERROR_LABEL; \
  98. .Lpseudo_end:
  99. #undef PSEUDO_END
  100. #define PSEUDO_END(name) \
  101. SYSCALL_ERROR_HANDLER \
  102. END (name)
  103. #undef PSEUDO_NOERRNO
  104. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  105. .text; \
  106. ENTRY (name) \
  107. DO_CALL (syscall_name, args)
  108. #undef PSEUDO_END_NOERRNO
  109. #define PSEUDO_END_NOERRNO(name) \
  110. END (name)
  111. #undef ret_NOERRNO
  112. #define ret_NOERRNO abi_ret
  113. /* The function has to return the error code. */
  114. #undef PSEUDO_ERRVAL
  115. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  116. .text; \
  117. ENTRY (name) \
  118. DO_CALL (syscall_name, args); \
  119. neg a2, a2
  120. #undef PSEUDO_END_ERRVAL
  121. #define PSEUDO_END_ERRVAL(name) \
  122. END (name)
  123. #undef ret_ERRVAL
  124. #define ret_ERRVAL abi_ret
  125. #if defined _LIBC_REENTRANT
  126. # if defined USE___THREAD
  127. # define SYSCALL_ERROR_ERRNO errno
  128. # define SYSCALL_ERROR_HANDLER \
  129. 0: rur a4, THREADPTR; \
  130. movi a3, SYSCALL_ERROR_ERRNO@TPOFF; \
  131. neg a2, a2; \
  132. add a4, a4, a3; \
  133. s32i a2, a4, 0; \
  134. movi a2, -1; \
  135. j .Lpseudo_end;
  136. # else /* !USE___THREAD */
  137. #if defined(__XTENSA_WINDOWED_ABI__)
  138. # define SYSCALL_ERROR_HANDLER \
  139. 0: neg a2, a2; \
  140. mov a6, a2; \
  141. movi a4, __errno_location@PLT; \
  142. callx4 a4; \
  143. s32i a2, a6, 0; \
  144. movi a2, -1; \
  145. j .Lpseudo_end;
  146. #elif defined(__XTENSA_CALL0_ABI__)
  147. # define SYSCALL_ERROR_HANDLER \
  148. 0: neg a2, a2; \
  149. addi a1, a1, -16; \
  150. s32i a0, a1, 0; \
  151. s32i a2, a1, 4; \
  152. movi a0, __errno_location@PLT; \
  153. callx0 a0; \
  154. l32i a0, a1, 0; \
  155. l32i a3, a1, 4; \
  156. addi a1, a1, 16; \
  157. s32i a3, a2, 0; \
  158. movi a2, -1; \
  159. j .Lpseudo_end;
  160. #else
  161. #error Unsupported Xtensa ABI
  162. #endif
  163. # endif /* !USE___THREAD */
  164. #else /* !_LIBC_REENTRANT */
  165. #define SYSCALL_ERROR_HANDLER \
  166. 0: movi a4, errno; \
  167. neg a2, a2; \
  168. s32i a2, a4, 0; \
  169. movi a2, -1; \
  170. j .Lpseudo_end;
  171. #endif /* _LIBC_REENTRANT */
  172. #endif /* __ASSEMBLER__ */
  173. #endif /* _LINUX_XTENSA_SYSDEP_H */