1 /* Assembly macros for 64-bit PowerPC.
2 Copyright (C) 2002-2004, 2006, 2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
20 #include <sysdeps/powerpc/sysdep.h>
24 /* Support macros for CALL_MCOUNT. */
28 std 2+\NARG,40+8*(\NARG)(1)
35 ld 2+\NARG,112+40+8*(\NARG)(1)
39 .macro CFI_SAVE_ARG NARG
42 cfi_offset(2+\NARG,40+8*(\NARG))
46 .macro CFI_REST_ARG NARG
53 /* If compiled for profiling, call `_mcount' at the start of each function.
54 see ppc-mcount.S for more details. */
55 .macro CALL_MCOUNT NARG
61 cfi_adjust_cfa_offset(112)
64 bl JUMPTARGET (_mcount)
72 cfi_adjust_cfa_offset(-112)
78 #ifdef USE_PPC64_OVERLAPPING_OPD
79 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase
81 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase, 0
84 #define ENTRY_1(name) \
86 .type BODY_LABEL(name),@function; \
88 .section ".opd","aw"; \
90 name##: OPD_ENT (name); \
93 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
94 # define DOT_LABEL(X) .##X
95 # define BODY_LABEL(X) .##X
96 # define ENTRY_2(name) \
97 .globl BODY_LABEL(name); \
100 # define END_2(name) \
101 .size BODY_LABEL(name),.-BODY_LABEL(name);
103 # define DOT_LABEL(X) X
104 # define BODY_LABEL(X) .LY##X
105 # define ENTRY_2(name) \
106 .type name,@function; \
108 # define END_2(name) \
109 .size name,.-BODY_LABEL(name); \
110 .size BODY_LABEL(name),.-BODY_LABEL(name);
113 #define ENTRY(name) \
115 .align ALIGNARG(2); \
119 #define EALIGN_W_0 /* No words to insert. */
120 #define EALIGN_W_1 nop
121 #define EALIGN_W_2 nop;nop
122 #define EALIGN_W_3 nop;nop;nop
123 #define EALIGN_W_4 EALIGN_W_3;nop
124 #define EALIGN_W_5 EALIGN_W_4;nop
125 #define EALIGN_W_6 EALIGN_W_5;nop
126 #define EALIGN_W_7 EALIGN_W_6;nop
128 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
129 past a 2^alignt boundary. */
130 #define EALIGN(name, alignt, words) \
132 .align ALIGNARG(alignt); \
137 /* Local labels stripped out by the linker. */
141 #define tostring(s) #s
142 #define stringify(s) tostring(s)
143 #define XGLUE(a,b) a##b
144 #define GLUE(a,b) XGLUE(a,b)
145 #define LT_LABEL(name) GLUE(.LT,name)
146 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
148 /* Support Traceback tables */
149 #define TB_ASM 0x000c000000000000
150 #define TB_GLOBALLINK 0x0000800000000000
151 #define TB_IS_EPROL 0x0000400000000000
152 #define TB_HAS_TBOFF 0x0000200000000000
153 #define TB_INT_PROC 0x0000100000000000
154 #define TB_HAS_CTL 0x0000080000000000
155 #define TB_TOCLESS 0x0000040000000000
156 #define TB_FP_PRESENT 0x0000020000000000
157 #define TB_LOG_ABORT 0x0000010000000000
158 #define TB_INT_HANDL 0x0000008000000000
159 #define TB_NAME_PRESENT 0x0000004000000000
160 #define TB_USES_ALLOCA 0x0000002000000000
161 #define TB_SAVES_CR 0x0000000200000000
162 #define TB_SAVES_LR 0x0000000100000000
163 #define TB_STORES_BC 0x0000000080000000
164 #define TB_FIXUP 0x0000000040000000
165 #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
166 #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
167 #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
168 #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
169 #define TB_PARMSONSTK 0x0000000000000001
171 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
172 #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
174 #define TRACEBACK(name) \
178 .long LT_LABEL(name)-BODY_LABEL(name) ; \
179 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
180 LT_LABELSUFFIX(name,_name_start): ;\
181 .ascii stringify(name) ; \
182 LT_LABELSUFFIX(name,_name_end): ; \
185 #define TRACEBACK_MASK(name,mask) \
188 .quad TB_DEFAULT | mask ; \
189 .long LT_LABEL(name)-BODY_LABEL(name) ; \
190 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
191 LT_LABELSUFFIX(name,_name_start): ;\
192 .ascii stringify(name) ; \
193 LT_LABELSUFFIX(name,_name_end): ; \
196 /* END generates Traceback tables */
203 /* This form supports more informative traceback tables */
204 #define END_GEN_TB(name,mask) \
206 TRACEBACK_MASK(name,mask) \
209 #define DO_CALL(syscall) \
213 /* ppc64 is always PIC */
215 #define JUMPTARGET(name) DOT_LABEL(name)
217 #define PSEUDO(name, syscall_name, args) \
220 DO_CALL (SYS_ify (syscall_name));
223 #define TAIL_CALL_SYSCALL_ERROR \
224 b JUMPTARGET(__syscall_error)
226 /* Static version might be linked into a large app with a toc exceeding
227 64k. We can't put a toc adjusting stub on a plain branch, so can't
228 tail call __syscall_error. */
229 #define TAIL_CALL_SYSCALL_ERROR \
230 .ifdef .Local_syscall_error; \
231 b .Local_syscall_error; \
233 .Local_syscall_error: \
237 cfi_adjust_cfa_offset(112); \
239 bl JUMPTARGET(__syscall_error); \
243 cfi_adjust_cfa_offset(-112); \
252 TAIL_CALL_SYSCALL_ERROR
254 #define ret PSEUDO_RET
257 #define PSEUDO_END(name) \
260 #define PSEUDO_NOERRNO(name, syscall_name, args) \
263 DO_CALL (SYS_ify (syscall_name));
265 #define PSEUDO_RET_NOERRNO \
268 #define ret_NOERRNO PSEUDO_RET_NOERRNO
270 #undef PSEUDO_END_NOERRNO
271 #define PSEUDO_END_NOERRNO(name) \
274 #define PSEUDO_ERRVAL(name, syscall_name, args) \
277 DO_CALL (SYS_ify (syscall_name));
279 #define PSEUDO_RET_ERRVAL \
282 #define ret_ERRVAL PSEUDO_RET_ERRVAL
284 #undef PSEUDO_END_ERRVAL
285 #define PSEUDO_END_ERRVAL(name) \
288 #else /* !__ASSEMBLER__ */
290 #ifdef USE_PPC64_OVERLAPPING_OPD
291 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
293 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
296 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
297 # define DOT_PREFIX "."
298 # define BODY_PREFIX "."
299 # define ENTRY_2(name) \
300 ".globl " BODY_PREFIX #name ";\n" \
301 ".size " #name ", 24;"
302 # define END_2(name) \
303 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
305 # define DOT_PREFIX ""
306 # define BODY_PREFIX ".LY"
307 # define ENTRY_2(name) ".type " #name ",@function;"
308 # define END_2(name) \
309 ".size " #name ",.-" BODY_PREFIX #name ";\n" \
310 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
313 #endif /* __ASSEMBLER__ */