sysdep.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* Assembly macros for 64-bit PowerPC.
  2. Copyright (C) 2002, 2003, 2004, 2006 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. #ifdef __ELF__
  16. #ifdef __ASSEMBLER__
  17. /* Support macros for CALL_MCOUNT. */
  18. .macro SAVE_ARG NARG
  19. .if \NARG
  20. SAVE_ARG \NARG-1
  21. std 2+\NARG,-72+8*(\NARG)(1)
  22. .endif
  23. .endm
  24. .macro REST_ARG NARG
  25. .if \NARG
  26. REST_ARG \NARG-1
  27. ld 2+\NARG,40+8*(\NARG)(1)
  28. .endif
  29. .endm
  30. /* If compiled for profiling, call `_mcount' at the start of each function.
  31. see ppc-mcount.S for more details. */
  32. .macro CALL_MCOUNT NARG
  33. #ifdef PROF
  34. mflr r0
  35. SAVE_ARG \NARG
  36. std r0,16(r1)
  37. stdu r1,-112(r1)
  38. bl JUMPTARGET (_mcount)
  39. ld r0,128(r1)
  40. REST_ARG \NARG
  41. addi r1,r1,112
  42. mtlr r0
  43. #endif
  44. .endm
  45. #ifdef USE_PPC64_OVERLAPPING_OPD
  46. # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase
  47. #else
  48. # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase, 0
  49. #endif
  50. #define ENTRY_1(name) \
  51. .section ".text"; \
  52. .type BODY_LABEL(name),@function; \
  53. .globl name; \
  54. .section ".opd","aw"; \
  55. .align 3; \
  56. name##: OPD_ENT (name); \
  57. .previous;
  58. # define DOT_LABEL(X) X
  59. # define BODY_LABEL(X) .LY##X
  60. # define ENTRY_2(name) \
  61. .type name,@function; \
  62. ENTRY_1(name)
  63. # define END_2(name) \
  64. .size name,.-BODY_LABEL(name); \
  65. .size BODY_LABEL(name),.-BODY_LABEL(name);
  66. #define ENTRY(name) \
  67. ENTRY_2(name) \
  68. .align ALIGNARG(2); \
  69. BODY_LABEL(name): \
  70. cfi_startproc;
  71. #define EALIGN_W_0 /* No words to insert. */
  72. #define EALIGN_W_1 nop
  73. #define EALIGN_W_2 nop;nop
  74. #define EALIGN_W_3 nop;nop;nop
  75. #define EALIGN_W_4 EALIGN_W_3;nop
  76. #define EALIGN_W_5 EALIGN_W_4;nop
  77. #define EALIGN_W_6 EALIGN_W_5;nop
  78. #define EALIGN_W_7 EALIGN_W_6;nop
  79. /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
  80. past a 2^alignt boundary. */
  81. #define EALIGN(name, alignt, words) \
  82. ENTRY_2(name) \
  83. .align ALIGNARG(alignt); \
  84. EALIGN_W_##words; \
  85. BODY_LABEL(name): \
  86. cfi_startproc;
  87. /* Local labels stripped out by the linker. */
  88. #undef L
  89. #define L(x) .L##x
  90. #define tostring(s) #s
  91. #define stringify(s) tostring(s)
  92. #define XGLUE(a,b) a##b
  93. #define GLUE(a,b) XGLUE(a,b)
  94. #define LT_LABEL(name) GLUE(.LT,name)
  95. #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
  96. /* Support Traceback tables */
  97. #define TB_ASM 0x000c000000000000
  98. #define TB_GLOBALLINK 0x0000800000000000
  99. #define TB_IS_EPROL 0x0000400000000000
  100. #define TB_HAS_TBOFF 0x0000200000000000
  101. #define TB_INT_PROC 0x0000100000000000
  102. #define TB_HAS_CTL 0x0000080000000000
  103. #define TB_TOCLESS 0x0000040000000000
  104. #define TB_FP_PRESENT 0x0000020000000000
  105. #define TB_LOG_ABORT 0x0000010000000000
  106. #define TB_INT_HANDL 0x0000008000000000
  107. #define TB_NAME_PRESENT 0x0000004000000000
  108. #define TB_USES_ALLOCA 0x0000002000000000
  109. #define TB_SAVES_CR 0x0000000200000000
  110. #define TB_SAVES_LR 0x0000000100000000
  111. #define TB_STORES_BC 0x0000000080000000
  112. #define TB_FIXUP 0x0000000040000000
  113. #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
  114. #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
  115. #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
  116. #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
  117. #define TB_PARMSONSTK 0x0000000000000001
  118. #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
  119. #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
  120. #define TRACEBACK(name) \
  121. LT_LABEL(name): ; \
  122. .long 0 ; \
  123. .quad TB_DEFAULT ; \
  124. .long LT_LABEL(name)-BODY_LABEL(name) ; \
  125. .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
  126. LT_LABELSUFFIX(name,_name_start): ;\
  127. .ascii stringify(name) ; \
  128. LT_LABELSUFFIX(name,_name_end): ; \
  129. .align 2 ;
  130. #define TRACEBACK_MASK(name,mask) \
  131. LT_LABEL(name): ; \
  132. .long 0 ; \
  133. .quad TB_DEFAULT | mask ; \
  134. .long LT_LABEL(name)-BODY_LABEL(name) ; \
  135. .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
  136. LT_LABELSUFFIX(name,_name_start): ;\
  137. .ascii stringify(name) ; \
  138. LT_LABELSUFFIX(name,_name_end): ; \
  139. .align 2 ;
  140. /* END generates Traceback tables */
  141. #undef END
  142. #define END(name) \
  143. cfi_endproc; \
  144. TRACEBACK(name) \
  145. END_2(name)
  146. /* This form supports more informative traceback tables */
  147. #define END_GEN_TB(name,mask) \
  148. cfi_endproc; \
  149. TRACEBACK_MASK(name,mask) \
  150. END_2(name)
  151. #define DO_CALL(syscall) \
  152. li 0,syscall; \
  153. sc
  154. /* ppc64 is always PIC */
  155. #undef JUMPTARGET
  156. #define JUMPTARGET(name) DOT_LABEL(name)
  157. #define PSEUDO(name, syscall_name, args) \
  158. .section ".text"; \
  159. ENTRY (name) \
  160. DO_CALL (SYS_ify (syscall_name));
  161. #define PSEUDO_RET \
  162. bnslr+; \
  163. b JUMPTARGET(__syscall_error)
  164. #define ret PSEUDO_RET
  165. #undef PSEUDO_END
  166. #define PSEUDO_END(name) \
  167. END (name)
  168. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  169. .section ".text"; \
  170. ENTRY (name) \
  171. DO_CALL (SYS_ify (syscall_name));
  172. #define PSEUDO_RET_NOERRNO \
  173. blr
  174. #define ret_NOERRNO PSEUDO_RET_NOERRNO
  175. #undef PSEUDO_END_NOERRNO
  176. #define PSEUDO_END_NOERRNO(name) \
  177. END (name)
  178. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  179. .section ".text"; \
  180. ENTRY (name) \
  181. DO_CALL (SYS_ify (syscall_name));
  182. #define PSEUDO_RET_ERRVAL \
  183. blr
  184. #undef ret_ERRVAL
  185. #define ret_ERRVAL PSEUDO_RET_ERRVAL
  186. #undef PSEUDO_END_ERRVAL
  187. #define PSEUDO_END_ERRVAL(name) \
  188. END (name)
  189. #else /* !__ASSEMBLER__ */
  190. #ifdef USE_PPC64_OVERLAPPING_OPD
  191. # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
  192. #else
  193. # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
  194. #endif
  195. # define DOT_PREFIX ""
  196. # define BODY_PREFIX ".LY"
  197. # define ENTRY_2(name) ".type " #name ",@function;"
  198. # define END_2(name) \
  199. ".size " #name ",.-" BODY_PREFIX #name ";\n" \
  200. ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
  201. #endif /* __ASSEMBLER__ */
  202. #endif /* __ELF__ */