sysdep.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. #ifdef HAVE_ASM_GLOBAL_DOT_NAME
  59. # define DOT_LABEL(X) .##X
  60. # define BODY_LABEL(X) .##X
  61. # define ENTRY_2(name) \
  62. .globl BODY_LABEL(name); \
  63. ENTRY_1(name) \
  64. .size name, 24;
  65. # define END_2(name) \
  66. .size BODY_LABEL(name),.-BODY_LABEL(name);
  67. #else
  68. # define DOT_LABEL(X) X
  69. # define BODY_LABEL(X) .LY##X
  70. # define ENTRY_2(name) \
  71. .type name,@function; \
  72. ENTRY_1(name)
  73. # define END_2(name) \
  74. .size name,.-BODY_LABEL(name); \
  75. .size BODY_LABEL(name),.-BODY_LABEL(name);
  76. #endif
  77. #define ENTRY(name) \
  78. ENTRY_2(name) \
  79. .align ALIGNARG(2); \
  80. BODY_LABEL(name): \
  81. cfi_startproc;
  82. #define EALIGN_W_0 /* No words to insert. */
  83. #define EALIGN_W_1 nop
  84. #define EALIGN_W_2 nop;nop
  85. #define EALIGN_W_3 nop;nop;nop
  86. #define EALIGN_W_4 EALIGN_W_3;nop
  87. #define EALIGN_W_5 EALIGN_W_4;nop
  88. #define EALIGN_W_6 EALIGN_W_5;nop
  89. #define EALIGN_W_7 EALIGN_W_6;nop
  90. /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
  91. past a 2^alignt boundary. */
  92. #define EALIGN(name, alignt, words) \
  93. ENTRY_2(name) \
  94. .align ALIGNARG(alignt); \
  95. EALIGN_W_##words; \
  96. BODY_LABEL(name): \
  97. cfi_startproc;
  98. /* Local labels stripped out by the linker. */
  99. #undef L
  100. #define L(x) .L##x
  101. #define tostring(s) #s
  102. #define stringify(s) tostring(s)
  103. #define XGLUE(a,b) a##b
  104. #define GLUE(a,b) XGLUE(a,b)
  105. #define LT_LABEL(name) GLUE(.LT,name)
  106. #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
  107. /* Support Traceback tables */
  108. #define TB_ASM 0x000c000000000000
  109. #define TB_GLOBALLINK 0x0000800000000000
  110. #define TB_IS_EPROL 0x0000400000000000
  111. #define TB_HAS_TBOFF 0x0000200000000000
  112. #define TB_INT_PROC 0x0000100000000000
  113. #define TB_HAS_CTL 0x0000080000000000
  114. #define TB_TOCLESS 0x0000040000000000
  115. #define TB_FP_PRESENT 0x0000020000000000
  116. #define TB_LOG_ABORT 0x0000010000000000
  117. #define TB_INT_HANDL 0x0000008000000000
  118. #define TB_NAME_PRESENT 0x0000004000000000
  119. #define TB_USES_ALLOCA 0x0000002000000000
  120. #define TB_SAVES_CR 0x0000000200000000
  121. #define TB_SAVES_LR 0x0000000100000000
  122. #define TB_STORES_BC 0x0000000080000000
  123. #define TB_FIXUP 0x0000000040000000
  124. #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
  125. #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
  126. #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
  127. #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
  128. #define TB_PARMSONSTK 0x0000000000000001
  129. #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
  130. #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
  131. #define TRACEBACK(name) \
  132. LT_LABEL(name): ; \
  133. .long 0 ; \
  134. .quad TB_DEFAULT ; \
  135. .long LT_LABEL(name)-BODY_LABEL(name) ; \
  136. .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
  137. LT_LABELSUFFIX(name,_name_start): ;\
  138. .ascii stringify(name) ; \
  139. LT_LABELSUFFIX(name,_name_end): ; \
  140. .align 2 ;
  141. #define TRACEBACK_MASK(name,mask) \
  142. LT_LABEL(name): ; \
  143. .long 0 ; \
  144. .quad TB_DEFAULT | mask ; \
  145. .long LT_LABEL(name)-BODY_LABEL(name) ; \
  146. .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
  147. LT_LABELSUFFIX(name,_name_start): ;\
  148. .ascii stringify(name) ; \
  149. LT_LABELSUFFIX(name,_name_end): ; \
  150. .align 2 ;
  151. /* END generates Traceback tables */
  152. #undef END
  153. #define END(name) \
  154. cfi_endproc; \
  155. TRACEBACK(name) \
  156. END_2(name)
  157. /* This form supports more informative traceback tables */
  158. #define END_GEN_TB(name,mask) \
  159. cfi_endproc; \
  160. TRACEBACK_MASK(name,mask) \
  161. END_2(name)
  162. #define DO_CALL(syscall) \
  163. li 0,syscall; \
  164. sc
  165. /* ppc64 is always PIC */
  166. #undef JUMPTARGET
  167. #define JUMPTARGET(name) DOT_LABEL(name)
  168. #define PSEUDO(name, syscall_name, args) \
  169. .section ".text"; \
  170. ENTRY (name) \
  171. DO_CALL (SYS_ify (syscall_name));
  172. #define PSEUDO_RET \
  173. bnslr+; \
  174. b JUMPTARGET(__syscall_error)
  175. #define ret PSEUDO_RET
  176. #undef PSEUDO_END
  177. #define PSEUDO_END(name) \
  178. END (name)
  179. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  180. .section ".text"; \
  181. ENTRY (name) \
  182. DO_CALL (SYS_ify (syscall_name));
  183. #define PSEUDO_RET_NOERRNO \
  184. blr
  185. #define ret_NOERRNO PSEUDO_RET_NOERRNO
  186. #undef PSEUDO_END_NOERRNO
  187. #define PSEUDO_END_NOERRNO(name) \
  188. END (name)
  189. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  190. .section ".text"; \
  191. ENTRY (name) \
  192. DO_CALL (SYS_ify (syscall_name));
  193. #define PSEUDO_RET_ERRVAL \
  194. blr
  195. #define ret_ERRVAL PSEUDO_RET_ERRVAL
  196. #undef PSEUDO_END_ERRVAL
  197. #define PSEUDO_END_ERRVAL(name) \
  198. END (name)
  199. #else /* !__ASSEMBLER__ */
  200. #ifdef USE_PPC64_OVERLAPPING_OPD
  201. # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
  202. #else
  203. # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
  204. #endif
  205. #ifdef HAVE_ASM_GLOBAL_DOT_NAME
  206. # define DOT_PREFIX "."
  207. # define BODY_PREFIX "."
  208. # define ENTRY_2(name) \
  209. ".globl " BODY_PREFIX #name ";\n" \
  210. ".size " #name ", 24;"
  211. # define END_2(name) \
  212. ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
  213. #else
  214. # define DOT_PREFIX ""
  215. # define BODY_PREFIX ".LY"
  216. # define ENTRY_2(name) ".type " #name ",@function;"
  217. # define END_2(name) \
  218. ".size " #name ",.-" BODY_PREFIX #name ";\n" \
  219. ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
  220. #endif
  221. #endif /* __ASSEMBLER__ */
  222. #endif /* __ELF__ */