1 /* Assembly macros for 64-bit PowerPC.
2 Copyright (C) 2002-2013 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <sysdeps/powerpc/sysdep.h>
23 /* Support macros for CALL_MCOUNT. */
27 std 2+\NARG,40+8*(\NARG)(1)
34 ld 2+\NARG,112+40+8*(\NARG)(1)
38 .macro CFI_SAVE_ARG NARG
41 cfi_offset(2+\NARG,40+8*(\NARG))
45 .macro CFI_REST_ARG NARG
52 /* If compiled for profiling, call `_mcount' at the start of each function.
53 see ppc-mcount.S for more details. */
54 .macro CALL_MCOUNT NARG
60 cfi_adjust_cfa_offset(112)
63 bl JUMPTARGET (_mcount)
71 cfi_adjust_cfa_offset(-112)
77 #ifdef USE_PPC64_OVERLAPPING_OPD
78 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase
80 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase, 0
83 #define ENTRY_1(name) \
85 .type BODY_LABEL(name),@function; \
87 .section ".opd","aw"; \
89 name##: OPD_ENT (name); \
92 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
93 # define DOT_LABEL(X) .##X
94 # define BODY_LABEL(X) .##X
95 # define ENTRY_2(name) \
96 .globl BODY_LABEL(name); \
99 # define END_2(name) \
100 .size BODY_LABEL(name),.-BODY_LABEL(name);
102 # define DOT_LABEL(X) X
103 # define BODY_LABEL(X) .LY##X
104 # define ENTRY_2(name) \
105 .type name,@function; \
107 # define END_2(name) \
108 .size name,.-BODY_LABEL(name); \
109 .size BODY_LABEL(name),.-BODY_LABEL(name);
112 #define ENTRY(name) \
114 .align ALIGNARG(2); \
118 #define EALIGN_W_0 /* No words to insert. */
119 #define EALIGN_W_1 nop
120 #define EALIGN_W_2 nop;nop
121 #define EALIGN_W_3 nop;nop;nop
122 #define EALIGN_W_4 EALIGN_W_3;nop
123 #define EALIGN_W_5 EALIGN_W_4;nop
124 #define EALIGN_W_6 EALIGN_W_5;nop
125 #define EALIGN_W_7 EALIGN_W_6;nop
127 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
128 past a 2^alignt boundary. */
129 #define EALIGN(name, alignt, words) \
131 .align ALIGNARG(alignt); \
136 /* Local labels stripped out by the linker. */
140 #define tostring(s) #s
141 #define stringify(s) tostring(s)
142 #define XGLUE(a,b) a##b
143 #define GLUE(a,b) XGLUE(a,b)
144 #define LT_LABEL(name) GLUE(.LT,name)
145 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
147 /* Support Traceback tables */
148 #define TB_ASM 0x000c000000000000
149 #define TB_GLOBALLINK 0x0000800000000000
150 #define TB_IS_EPROL 0x0000400000000000
151 #define TB_HAS_TBOFF 0x0000200000000000
152 #define TB_INT_PROC 0x0000100000000000
153 #define TB_HAS_CTL 0x0000080000000000
154 #define TB_TOCLESS 0x0000040000000000
155 #define TB_FP_PRESENT 0x0000020000000000
156 #define TB_LOG_ABORT 0x0000010000000000
157 #define TB_INT_HANDL 0x0000008000000000
158 #define TB_NAME_PRESENT 0x0000004000000000
159 #define TB_USES_ALLOCA 0x0000002000000000
160 #define TB_SAVES_CR 0x0000000200000000
161 #define TB_SAVES_LR 0x0000000100000000
162 #define TB_STORES_BC 0x0000000080000000
163 #define TB_FIXUP 0x0000000040000000
164 #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
165 #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
166 #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
167 #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
168 #define TB_PARMSONSTK 0x0000000000000001
170 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
171 #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
173 #define TRACEBACK(name) \
177 .long LT_LABEL(name)-BODY_LABEL(name) ; \
178 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
179 LT_LABELSUFFIX(name,_name_start): ;\
180 .ascii stringify(name) ; \
181 LT_LABELSUFFIX(name,_name_end): ; \
184 #define TRACEBACK_MASK(name,mask) \
187 .quad TB_DEFAULT | mask ; \
188 .long LT_LABEL(name)-BODY_LABEL(name) ; \
189 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
190 LT_LABELSUFFIX(name,_name_start): ;\
191 .ascii stringify(name) ; \
192 LT_LABELSUFFIX(name,_name_end): ; \
195 /* END generates Traceback tables */
202 /* This form supports more informative traceback tables */
203 #define END_GEN_TB(name,mask) \
205 TRACEBACK_MASK(name,mask) \
208 #define DO_CALL(syscall) \
212 /* ppc64 is always PIC */
214 #define JUMPTARGET(name) DOT_LABEL(name)
216 #define PSEUDO(name, syscall_name, args) \
219 DO_CALL (SYS_ify (syscall_name));
222 #define TAIL_CALL_SYSCALL_ERROR \
223 b JUMPTARGET(__syscall_error)
225 /* Static version might be linked into a large app with a toc exceeding
226 64k. We can't put a toc adjusting stub on a plain branch, so can't
227 tail call __syscall_error. */
228 #define TAIL_CALL_SYSCALL_ERROR \
229 .ifdef .Local_syscall_error; \
230 b .Local_syscall_error; \
232 .Local_syscall_error: \
236 cfi_adjust_cfa_offset(112); \
238 bl JUMPTARGET(__syscall_error); \
242 cfi_adjust_cfa_offset(-112); \
251 TAIL_CALL_SYSCALL_ERROR
253 #define ret PSEUDO_RET
256 #define PSEUDO_END(name) \
259 #define PSEUDO_NOERRNO(name, syscall_name, args) \
262 DO_CALL (SYS_ify (syscall_name));
264 #define PSEUDO_RET_NOERRNO \
267 #define ret_NOERRNO PSEUDO_RET_NOERRNO
269 #undef PSEUDO_END_NOERRNO
270 #define PSEUDO_END_NOERRNO(name) \
273 #define PSEUDO_ERRVAL(name, syscall_name, args) \
276 DO_CALL (SYS_ify (syscall_name));
278 #define PSEUDO_RET_ERRVAL \
281 #define ret_ERRVAL PSEUDO_RET_ERRVAL
283 #undef PSEUDO_END_ERRVAL
284 #define PSEUDO_END_ERRVAL(name) \
287 #else /* !__ASSEMBLER__ */
289 #ifdef USE_PPC64_OVERLAPPING_OPD
290 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
292 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
295 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
296 # define DOT_PREFIX "."
297 # define BODY_PREFIX "."
298 # define ENTRY_2(name) \
299 ".globl " BODY_PREFIX #name ";\n" \
300 ".size " #name ", 24;"
301 # define END_2(name) \
302 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
304 # define DOT_PREFIX ""
305 # define BODY_PREFIX ".LY"
306 # define ENTRY_2(name) ".type " #name ",@function;"
307 # define END_2(name) \
308 ".size " #name ",.-" BODY_PREFIX #name ";\n" \
309 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
312 #endif /* __ASSEMBLER__ */