sysdep.h 5.7 KB

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