1 /* Assembly macros for 64-bit PowerPC.
2 Copyright (C) 2002-2015 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 /* Stack frame offsets. */
25 #define FRAME_MIN_SIZE 112
26 #define FRAME_MIN_SIZE_PARM 112
27 #define FRAME_BACKCHAIN 0
28 #define FRAME_CR_SAVE 8
29 #define FRAME_LR_SAVE 16
30 #define FRAME_TOC_SAVE 40
31 #define FRAME_PARM_SAVE 48
32 #define FRAME_PARM1_SAVE 48
33 #define FRAME_PARM2_SAVE 56
34 #define FRAME_PARM3_SAVE 64
35 #define FRAME_PARM4_SAVE 72
36 #define FRAME_PARM5_SAVE 80
37 #define FRAME_PARM6_SAVE 88
38 #define FRAME_PARM7_SAVE 96
39 #define FRAME_PARM8_SAVE 104
40 #define FRAME_PARM9_SAVE 112
42 #define FRAME_MIN_SIZE 32
43 #define FRAME_MIN_SIZE_PARM 96
44 #define FRAME_BACKCHAIN 0
45 #define FRAME_CR_SAVE 8
46 #define FRAME_LR_SAVE 16
47 #define FRAME_TOC_SAVE 24
48 #define FRAME_PARM_SAVE 32
49 #define FRAME_PARM1_SAVE 32
50 #define FRAME_PARM2_SAVE 40
51 #define FRAME_PARM3_SAVE 48
52 #define FRAME_PARM4_SAVE 56
53 #define FRAME_PARM5_SAVE 64
54 #define FRAME_PARM6_SAVE 72
55 #define FRAME_PARM7_SAVE 80
56 #define FRAME_PARM8_SAVE 88
57 #define FRAME_PARM9_SAVE 96
60 /* Support macros for CALL_MCOUNT. */
62 #define call_mcount_parm_offset (-64)
64 #define call_mcount_parm_offset FRAME_PARM_SAVE
69 std
2+\NARG
,call_mcount_parm_offset
-8+8*(\NARG
)(1)
76 ld
2+\NARG
,FRAME_MIN_SIZE_PARM
+call_mcount_parm_offset
-8+8*(\NARG
)(1)
80 .macro CFI_SAVE_ARG NARG
83 cfi_offset(2+\NARG
,call_mcount_parm_offset
-8+8*(\NARG
))
87 .macro CFI_REST_ARG NARG
94 /* If compiled for profiling, call `_mcount' at the start of each function.
95 see ppc-mcount.S for more details. */
96 .macro CALL_MCOUNT NARG
100 std r0
,FRAME_LR_SAVE(r1
)
101 stdu r1
,-FRAME_MIN_SIZE_PARM(r1
)
102 cfi_adjust_cfa_offset(FRAME_MIN_SIZE_PARM
)
103 cfi_offset(lr
,FRAME_LR_SAVE
)
105 bl
JUMPTARGET (_mcount
)
109 ld r0
,FRAME_MIN_SIZE_PARM
+FRAME_LR_SAVE(r1
)
112 addi r1
,r1
,FRAME_MIN_SIZE_PARM
113 cfi_adjust_cfa_offset(-FRAME_MIN_SIZE_PARM
)
121 /* Macro to prepare for calling via a function pointer. */
122 .macro PPC64_LOAD_FUNCPTR PTR
129 #ifdef USE_PPC64_OVERLAPPING_OPD
130 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase
132 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase, 0
135 #define ENTRY_1(name) \
136 .type BODY_LABEL(name),@function; \
138 .section ".opd","aw"; \
140 name##: OPD_ENT (name); \
143 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
144 # define DOT_LABEL(X) .##X
145 # define BODY_LABEL(X) .##X
146 # define ENTRY_2(name) \
147 .globl BODY_LABEL(name); \
150 # define END_2(name) \
151 .size BODY_LABEL(name),.-BODY_LABEL(name);
153 # define DOT_LABEL(X) X
154 # define BODY_LABEL(X) .LY##X
155 # define ENTRY_2(name) \
156 .type name,@function; \
158 # define END_2(name) \
159 .size name,.-BODY_LABEL(name); \
160 .size BODY_LABEL(name),.-BODY_LABEL(name);
162 #define LOCALENTRY(name)
164 #else /* _CALL_ELF */
166 /* Macro to prepare for calling via a function pointer. */
167 .macro PPC64_LOAD_FUNCPTR PTR
172 #define DOT_LABEL(X) X
173 #define BODY_LABEL(X) X
174 #define ENTRY_2(name) \
176 .type name,@function;
177 #define END_2(name) \
179 #define LOCALENTRY(name) \
180 1: addis r2,r12,.TOC.-1b@ha; \
181 addi r2,r2,.TOC.-1b@l; \
182 .localentry name,.-name;
184 #endif /* _CALL_ELF */
186 #define ENTRY(name) \
189 .align ALIGNARG(2); \
194 #define EALIGN_W_0 /* No words to insert. */
195 #define EALIGN_W_1 nop
196 #define EALIGN_W_2 nop;nop
197 #define EALIGN_W_3 nop;nop;nop
198 #define EALIGN_W_4 EALIGN_W_3;nop
199 #define EALIGN_W_5 EALIGN_W_4;nop
200 #define EALIGN_W_6 EALIGN_W_5;nop
201 #define EALIGN_W_7 EALIGN_W_6;nop
203 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
204 past a 2^alignt boundary. */
205 #define EALIGN(name, alignt, words) \
208 .align ALIGNARG(alignt); \
214 /* Local labels stripped out by the linker. */
218 #define tostring(s) #s
219 #define stringify(s) tostring(s)
220 #define XGLUE(a,b) a##b
221 #define GLUE(a,b) XGLUE(a,b)
222 #define LT_LABEL(name) GLUE(.LT,name)
223 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
225 /* Support Traceback tables */
226 #define TB_ASM 0x000c000000000000
227 #define TB_GLOBALLINK 0x0000800000000000
228 #define TB_IS_EPROL 0x0000400000000000
229 #define TB_HAS_TBOFF 0x0000200000000000
230 #define TB_INT_PROC 0x0000100000000000
231 #define TB_HAS_CTL 0x0000080000000000
232 #define TB_TOCLESS 0x0000040000000000
233 #define TB_FP_PRESENT 0x0000020000000000
234 #define TB_LOG_ABORT 0x0000010000000000
235 #define TB_INT_HANDL 0x0000008000000000
236 #define TB_NAME_PRESENT 0x0000004000000000
237 #define TB_USES_ALLOCA 0x0000002000000000
238 #define TB_SAVES_CR 0x0000000200000000
239 #define TB_SAVES_LR 0x0000000100000000
240 #define TB_STORES_BC 0x0000000080000000
241 #define TB_FIXUP 0x0000000040000000
242 #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
243 #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
244 #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
245 #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
246 #define TB_PARMSONSTK 0x0000000000000001
248 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
249 #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
251 #define TRACEBACK(name) \
255 .long LT_LABEL(name)-BODY_LABEL(name) ; \
256 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
257 LT_LABELSUFFIX(name,_name_start): ;\
258 .ascii stringify(name) ; \
259 LT_LABELSUFFIX(name,_name_end): ; \
262 #define TRACEBACK_MASK(name,mask) \
265 .quad TB_DEFAULT | mask ; \
266 .long LT_LABEL(name)-BODY_LABEL(name) ; \
267 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
268 LT_LABELSUFFIX(name,_name_start): ;\
269 .ascii stringify(name) ; \
270 LT_LABELSUFFIX(name,_name_end): ; \
273 /* END generates Traceback tables */
280 /* This form supports more informative traceback tables */
281 #define END_GEN_TB(name,mask) \
283 TRACEBACK_MASK(name,mask) \
286 #define DO_CALL(syscall) \
290 /* ppc64 is always PIC */
292 #define JUMPTARGET(name) DOT_LABEL(name)
294 #define PSEUDO(name, syscall_name, args) \
297 DO_CALL (SYS_ify (syscall_name));
300 #define TAIL_CALL_SYSCALL_ERROR \
301 b JUMPTARGET(__syscall_error)
303 /* Static version might be linked into a large app with a toc exceeding
304 64k. We can't put a toc adjusting stub on a plain branch, so can't
305 tail call __syscall_error. */
306 #define TAIL_CALL_SYSCALL_ERROR \
307 .ifdef .Local_syscall_error; \
308 b .Local_syscall_error; \
310 .Local_syscall_error: \
312 std 0,FRAME_LR_SAVE(1); \
313 stdu 1,-FRAME_MIN_SIZE(1); \
314 cfi_adjust_cfa_offset(FRAME_MIN_SIZE); \
315 cfi_offset(lr,FRAME_LR_SAVE); \
316 bl JUMPTARGET(__syscall_error); \
318 ld 0,FRAME_MIN_SIZE+FRAME_LR_SAVE(1); \
319 addi 1,1,FRAME_MIN_SIZE; \
320 cfi_adjust_cfa_offset(-FRAME_MIN_SIZE); \
329 TAIL_CALL_SYSCALL_ERROR
331 #define ret PSEUDO_RET
334 #define PSEUDO_END(name) \
337 #define PSEUDO_NOERRNO(name, syscall_name, args) \
340 DO_CALL (SYS_ify (syscall_name));
342 #define PSEUDO_RET_NOERRNO \
345 #define ret_NOERRNO PSEUDO_RET_NOERRNO
347 #undef PSEUDO_END_NOERRNO
348 #define PSEUDO_END_NOERRNO(name) \
351 #define PSEUDO_ERRVAL(name, syscall_name, args) \
354 DO_CALL (SYS_ify (syscall_name));
356 #define PSEUDO_RET_ERRVAL \
359 #define ret_ERRVAL PSEUDO_RET_ERRVAL
361 #undef PSEUDO_END_ERRVAL
362 #define PSEUDO_END_ERRVAL(name) \
365 #else /* !__ASSEMBLER__ */
369 #define PPC64_LOAD_FUNCPTR(ptr) \
370 "ld 12,0(" #ptr ");\n" \
371 "ld 2,8(" #ptr ");\n" \
373 "ld 11,16(" #ptr ");"
375 #ifdef USE_PPC64_OVERLAPPING_OPD
376 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
378 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
381 #define ENTRY_1(name) \
382 ".type " BODY_PREFIX #name ",@function;\n" \
383 ".globl " #name ";\n" \
384 ".pushsection \".opd\",\"aw\";\n" \
387 OPD_ENT (name) "\n" \
390 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
391 # define DOT_PREFIX "."
392 # define BODY_PREFIX "."
393 # define ENTRY_2(name) \
394 ".globl " BODY_PREFIX #name ";\n" \
396 ".size " #name ", 24;"
397 # define END_2(name) \
398 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
400 # define DOT_PREFIX ""
401 # define BODY_PREFIX ".LY"
402 # define ENTRY_2(name) \
403 ".type " #name ",@function;\n" \
405 # define END_2(name) \
406 ".size " #name ",.-" BODY_PREFIX #name ";\n" \
407 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
409 #define LOCALENTRY(name)
411 #else /* _CALL_ELF */
413 #define PPC64_LOAD_FUNCPTR(ptr) \
414 "mr 12," #ptr ";\n" \
417 #define DOT_PREFIX ""
418 #define BODY_PREFIX ""
419 #define ENTRY_2(name) \
420 ".type " #name ",@function;\n" \
422 #define END_2(name) \
423 ".size " #name ",.-" #name ";"
424 #define LOCALENTRY(name) \
425 "1: addis 2,12,.TOC.-1b@ha;\n" \
426 "addi 2,2,.TOC.-1b@l;\n" \
427 ".localentry " #name ",.-" #name ";"
429 #endif /* _CALL_ELF */
431 #endif /* __ASSEMBLER__ */