sysdep.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, write to the Free
  14. Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  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. #define ret_ERRVAL retw
  102. #if defined RTLD_PRIVATE_ERRNO
  103. # define SYSCALL_ERROR_HANDLER \
  104. 0: movi a4, rtld_errno; \
  105. neg a2, a2; \
  106. s32i a2, a4, 0; \
  107. movi a2, -1; \
  108. j .Lpseudo_end;
  109. #elif defined _LIBC_REENTRANT
  110. # if defined USE___THREAD
  111. # ifndef NOT_IN_libc
  112. # define SYSCALL_ERROR_ERRNO __libc_errno
  113. # else
  114. # define SYSCALL_ERROR_ERRNO errno
  115. # endif
  116. # define SYSCALL_ERROR_HANDLER \
  117. 0: rur a4, THREADPTR; \
  118. movi a3, SYSCALL_ERROR_ERRNO@TPOFF; \
  119. neg a2, a2; \
  120. add a4, a4, a3; \
  121. s32i a2, a4, 0; \
  122. movi a2, -1; \
  123. j .Lpseudo_end;
  124. # else /* !USE___THREAD */
  125. # define SYSCALL_ERROR_HANDLER \
  126. 0: neg a2, a2; \
  127. mov a6, a2; \
  128. movi a4, __errno_location@PLT; \
  129. callx4 a4; \
  130. s32i a2, a6, 0; \
  131. movi a2, -1; \
  132. j .Lpseudo_end;
  133. # endif /* !USE___THREAD */
  134. #else /* !_LIBC_REENTRANT */
  135. #define SYSCALL_ERROR_HANDLER \
  136. 0: movi a4, errno; \
  137. neg a2, a2; \
  138. s32i a2, a4, 0; \
  139. movi a2, -1; \
  140. j .Lpseudo_end;
  141. #endif /* _LIBC_REENTRANT */
  142. #endif /* __ASSEMBLER__ */