sysdep.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #undef END
  34. #define END(name) ASM_SIZE_DIRECTIVE(name)
  35. /* Define a macro for this directive so it can be removed in a few places. */
  36. #define LITERAL_POSITION .literal_position
  37. #undef JUMPTARGET
  38. #ifdef __PIC__
  39. /* The "@PLT" suffix is currently a no-op for non-shared linking, but
  40. it doesn't hurt to use it conditionally for PIC code in case that
  41. changes someday. */
  42. #define JUMPTARGET(name) name##@PLT
  43. #else
  44. #define JUMPTARGET(name) name
  45. #endif
  46. #define FRAMESIZE 16
  47. #define CALL_MCOUNT /* Do nothing. */
  48. /* Linux uses a negative return value to indicate syscall errors,
  49. unlike most Unices, which use the condition codes' carry flag.
  50. Since version 2.1 the return value of a system call might be
  51. negative even if the call succeeded. E.g., the `lseek' system call
  52. might return a large offset. Therefore we must not anymore test
  53. for < 0, but test for a real error by making sure the value in a2
  54. is a real error number. Linus said he will make sure the no syscall
  55. returns a value in -1 .. -4095 as a valid result so we can safely
  56. test with -4095. */
  57. /* We don't want the label for the error handler to be global when we define
  58. it here. */
  59. #define SYSCALL_ERROR_LABEL 0f
  60. #undef PSEUDO
  61. #define PSEUDO(name, syscall_name, args) \
  62. .text; \
  63. ENTRY (name) \
  64. DO_CALL (syscall_name, args); \
  65. movi a4, -4095; \
  66. bgeu a2, a4, SYSCALL_ERROR_LABEL; \
  67. .Lpseudo_end:
  68. #undef PSEUDO_END
  69. #define PSEUDO_END(name) \
  70. SYSCALL_ERROR_HANDLER \
  71. END (name)
  72. #undef PSEUDO_NOERRNO
  73. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  74. .text; \
  75. ENTRY (name) \
  76. DO_CALL (syscall_name, args)
  77. #undef PSEUDO_END_NOERRNO
  78. #define PSEUDO_END_NOERRNO(name) \
  79. END (name)
  80. #undef ret_NOERRNO
  81. #define ret_NOERRNO retw
  82. /* The function has to return the error code. */
  83. #undef PSEUDO_ERRVAL
  84. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  85. .text; \
  86. ENTRY (name) \
  87. DO_CALL (syscall_name, args); \
  88. neg a2, a2
  89. #undef PSEUDO_END_ERRVAL
  90. #define PSEUDO_END_ERRVAL(name) \
  91. END (name)
  92. #define ret_ERRVAL retw
  93. #if RTLD_PRIVATE_ERRNO
  94. # define SYSCALL_ERROR_HANDLER \
  95. 0: movi a4, rtld_errno; \
  96. neg a2, a2; \
  97. s32i a2, a4, 0; \
  98. movi a2, -1; \
  99. j .Lpseudo_end;
  100. #elif defined _LIBC_REENTRANT
  101. # if USE___THREAD
  102. # ifndef NOT_IN_libc
  103. # define SYSCALL_ERROR_ERRNO __libc_errno
  104. # else
  105. # define SYSCALL_ERROR_ERRNO errno
  106. # endif
  107. # define SYSCALL_ERROR_HANDLER \
  108. 0: rur a4, THREADPTR; \
  109. movi a3, SYSCALL_ERROR_ERRNO@TPOFF; \
  110. neg a2, a2; \
  111. add a4, a4, a3; \
  112. s32i a2, a4, 0; \
  113. movi a2, -1; \
  114. j .Lpseudo_end;
  115. # else /* !USE___THREAD */
  116. # define SYSCALL_ERROR_HANDLER \
  117. 0: neg a2, a2; \
  118. mov a6, a2; \
  119. movi a4, __errno_location@PLT; \
  120. callx4 a4; \
  121. s32i a2, a6, 0; \
  122. movi a2, -1; \
  123. j .Lpseudo_end;
  124. # endif /* !USE___THREAD */
  125. #else /* !_LIBC_REENTRANT */
  126. #define SYSCALL_ERROR_HANDLER \
  127. 0: movi a4, errno; \
  128. neg a2, a2; \
  129. s32i a2, a4, 0; \
  130. movi a2, -1; \
  131. j .Lpseudo_end;
  132. #endif /* _LIBC_REENTRANT */
  133. #endif /* __ASSEMBLER__ */