sysdep.h 5.1 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, write to the Free
  14. Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. #include <sys/syscall.h>
  17. #ifdef __ASSEMBLER__
  18. #define ALIGNARG(log2) 1 << log2
  19. #define ASM_TYPE_DIRECTIVE(name, typearg) .type name, typearg
  20. #define ASM_SIZE_DIRECTIVE(name) .size name, . - name
  21. #ifdef __STDC__
  22. #define C_LABEL(name) name :
  23. #else
  24. #define C_LABEL(name) name/**/:
  25. #endif
  26. #define ENTRY(name) \
  27. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  28. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
  29. .align ALIGNARG(2); \
  30. LITERAL_POSITION; \
  31. C_LABEL(name) \
  32. entry sp, FRAMESIZE; \
  33. CALL_MCOUNT
  34. #define HIDDEN_ENTRY(name) \
  35. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  36. .hidden C_SYMBOL_NAME(name); \
  37. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
  38. .align ALIGNARG(2); \
  39. LITERAL_POSITION; \
  40. C_LABEL(name) \
  41. entry sp, FRAMESIZE; \
  42. CALL_MCOUNT
  43. #undef END
  44. #define END(name) ASM_SIZE_DIRECTIVE(name)
  45. /* Define a macro for this directive so it can be removed in a few places. */
  46. #define LITERAL_POSITION .literal_position
  47. #undef JUMPTARGET
  48. #ifdef __PIC__
  49. /* The "@PLT" suffix is currently a no-op for non-shared linking, but
  50. it doesn't hurt to use it conditionally for PIC code in case that
  51. changes someday. */
  52. #define JUMPTARGET(name) name##@PLT
  53. #else
  54. #define JUMPTARGET(name) name
  55. #endif
  56. #define FRAMESIZE 16
  57. #define CALL_MCOUNT /* Do nothing. */
  58. /* Linux uses a negative return value to indicate syscall errors,
  59. unlike most Unices, which use the condition codes' carry flag.
  60. Since version 2.1 the return value of a system call might be
  61. negative even if the call succeeded. E.g., the `lseek' system call
  62. might return a large offset. Therefore we must not anymore test
  63. for < 0, but test for a real error by making sure the value in a2
  64. is a real error number. Linus said he will make sure the no syscall
  65. returns a value in -1 .. -4095 as a valid result so we can safely
  66. test with -4095. */
  67. /* We don't want the label for the error handler to be global when we define
  68. it here. */
  69. #define SYSCALL_ERROR_LABEL 0f
  70. #undef PSEUDO
  71. #define PSEUDO(name, syscall_name, args) \
  72. .text; \
  73. ENTRY (name) \
  74. DO_CALL (syscall_name, args); \
  75. movi a4, -4095; \
  76. bgeu a2, a4, SYSCALL_ERROR_LABEL; \
  77. .Lpseudo_end:
  78. #undef PSEUDO_END
  79. #define PSEUDO_END(name) \
  80. SYSCALL_ERROR_HANDLER \
  81. END (name)
  82. #undef PSEUDO_NOERRNO
  83. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  84. .text; \
  85. ENTRY (name) \
  86. DO_CALL (syscall_name, args)
  87. #undef PSEUDO_END_NOERRNO
  88. #define PSEUDO_END_NOERRNO(name) \
  89. END (name)
  90. #undef ret_NOERRNO
  91. #define ret_NOERRNO retw
  92. /* The function has to return the error code. */
  93. #undef PSEUDO_ERRVAL
  94. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  95. .text; \
  96. ENTRY (name) \
  97. DO_CALL (syscall_name, args); \
  98. neg a2, a2
  99. #undef PSEUDO_END_ERRVAL
  100. #define PSEUDO_END_ERRVAL(name) \
  101. END (name)
  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__ */