sysdep.h 6.8 KB

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