1 /* Assembly macros for 64-bit PowerPC.
2 Copyright (C) 2002-2017 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 #define DOT_LABEL(X) X
144 #define BODY_LABEL(X) .LY##X
145 #define ENTRY_2(name) \
146 .type name,@function; \
148 #define END_2(name) \
149 .size name,.-BODY_LABEL(name); \
150 .size BODY_LABEL(name),.-BODY_LABEL(name);
151 #define LOCALENTRY(name)
153 #else /* _CALL_ELF */
155 /* Macro to prepare for calling via a function pointer. */
156 .macro PPC64_LOAD_FUNCPTR PTR
161 #define DOT_LABEL(X) X
162 #define BODY_LABEL(X) X
163 #define ENTRY_2(name) \
165 .type name,@function;
166 #define END_2(name) \
168 #define LOCALENTRY(name) \
169 1: addis r2,r12,.TOC.-1b@ha; \
170 addi r2,r2,.TOC.-1b@l; \
171 .localentry name,.-name;
173 #endif /* _CALL_ELF */
175 #define ENTRY(name) \
178 .align ALIGNARG(2); \
183 #define EALIGN_W_0 /* No words to insert. */
184 #define EALIGN_W_1 nop
185 #define EALIGN_W_2 nop;nop
186 #define EALIGN_W_3 nop;nop;nop
187 #define EALIGN_W_4 EALIGN_W_3;nop
188 #define EALIGN_W_5 EALIGN_W_4;nop
189 #define EALIGN_W_6 EALIGN_W_5;nop
190 #define EALIGN_W_7 EALIGN_W_6;nop
192 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
193 past a 2^alignt boundary. */
194 #define EALIGN(name, alignt, words) \
197 .align ALIGNARG(alignt); \
203 /* Local labels stripped out by the linker. */
207 #define tostring(s) #s
208 #define stringify(s) tostring(s)
209 #define XGLUE(a,b) a##b
210 #define GLUE(a,b) XGLUE(a,b)
211 #define LT_LABEL(name) GLUE(.LT,name)
212 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
214 /* Support Traceback tables */
215 #define TB_ASM 0x000c000000000000
216 #define TB_GLOBALLINK 0x0000800000000000
217 #define TB_IS_EPROL 0x0000400000000000
218 #define TB_HAS_TBOFF 0x0000200000000000
219 #define TB_INT_PROC 0x0000100000000000
220 #define TB_HAS_CTL 0x0000080000000000
221 #define TB_TOCLESS 0x0000040000000000
222 #define TB_FP_PRESENT 0x0000020000000000
223 #define TB_LOG_ABORT 0x0000010000000000
224 #define TB_INT_HANDL 0x0000008000000000
225 #define TB_NAME_PRESENT 0x0000004000000000
226 #define TB_USES_ALLOCA 0x0000002000000000
227 #define TB_SAVES_CR 0x0000000200000000
228 #define TB_SAVES_LR 0x0000000100000000
229 #define TB_STORES_BC 0x0000000080000000
230 #define TB_FIXUP 0x0000000040000000
231 #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
232 #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
233 #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
234 #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
235 #define TB_PARMSONSTK 0x0000000000000001
237 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
238 #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
240 #define TRACEBACK(name) \
244 .long LT_LABEL(name)-BODY_LABEL(name) ; \
245 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
246 LT_LABELSUFFIX(name,_name_start): ;\
247 .ascii stringify(name) ; \
248 LT_LABELSUFFIX(name,_name_end): ; \
251 #define TRACEBACK_MASK(name,mask) \
254 .quad TB_DEFAULT | mask ; \
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 /* END generates Traceback tables */
269 /* This form supports more informative traceback tables */
270 #define END_GEN_TB(name,mask) \
272 TRACEBACK_MASK(name,mask) \
275 #if !IS_IN(rtld) && defined (ENABLE_LOCK_ELISION)
276 # define ABORT_TRANSACTION \
279 lwz 0,TM_CAPABLE(13); \
282 li 11,_ABORT_SYSCALL; \
287 # define ABORT_TRANSACTION
290 #define DO_CALL(syscall) \
295 /* ppc64 is always PIC */
297 #define JUMPTARGET(name) DOT_LABEL(name)
299 #define PSEUDO(name, syscall_name, args) \
302 DO_CALL (SYS_ify (syscall_name));
305 #define TAIL_CALL_SYSCALL_ERROR \
306 b JUMPTARGET(__syscall_error)
308 /* Static version might be linked into a large app with a toc exceeding
309 64k. We can't put a toc adjusting stub on a plain branch, so can't
310 tail call __syscall_error. */
311 #define TAIL_CALL_SYSCALL_ERROR \
312 .ifdef .Local_syscall_error; \
313 b .Local_syscall_error; \
315 .Local_syscall_error: \
317 std 0,FRAME_LR_SAVE(1); \
318 stdu 1,-FRAME_MIN_SIZE(1); \
319 cfi_adjust_cfa_offset(FRAME_MIN_SIZE); \
320 cfi_offset(lr,FRAME_LR_SAVE); \
321 bl JUMPTARGET(__syscall_error); \
323 ld 0,FRAME_MIN_SIZE+FRAME_LR_SAVE(1); \
324 addi 1,1,FRAME_MIN_SIZE; \
325 cfi_adjust_cfa_offset(-FRAME_MIN_SIZE); \
334 TAIL_CALL_SYSCALL_ERROR
336 #define ret PSEUDO_RET
339 #define PSEUDO_END(name) \
342 #define PSEUDO_NOERRNO(name, syscall_name, args) \
345 DO_CALL (SYS_ify (syscall_name));
347 #define PSEUDO_RET_NOERRNO \
350 #define ret_NOERRNO PSEUDO_RET_NOERRNO
352 #undef PSEUDO_END_NOERRNO
353 #define PSEUDO_END_NOERRNO(name) \
356 #define PSEUDO_ERRVAL(name, syscall_name, args) \
359 DO_CALL (SYS_ify (syscall_name));
361 #define PSEUDO_RET_ERRVAL \
364 #define ret_ERRVAL PSEUDO_RET_ERRVAL
366 #undef PSEUDO_END_ERRVAL
367 #define PSEUDO_END_ERRVAL(name) \
370 #else /* !__ASSEMBLER__ */
374 #define PPC64_LOAD_FUNCPTR(ptr) \
375 "ld 12,0(" #ptr ");\n" \
376 "ld 2,8(" #ptr ");\n" \
378 "ld 11,16(" #ptr ");"
380 #ifdef USE_PPC64_OVERLAPPING_OPD
381 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
383 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
386 #define ENTRY_1(name) \
387 ".type " BODY_PREFIX #name ",@function;\n" \
388 ".globl " #name ";\n" \
389 ".pushsection \".opd\",\"aw\";\n" \
392 OPD_ENT (name) "\n" \
395 #define DOT_PREFIX ""
396 #define BODY_PREFIX ".LY"
397 #define ENTRY_2(name) \
398 ".type " #name ",@function;\n" \
400 #define END_2(name) \
401 ".size " #name ",.-" BODY_PREFIX #name ";\n" \
402 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
403 #define LOCALENTRY(name)
405 #else /* _CALL_ELF */
407 #define PPC64_LOAD_FUNCPTR(ptr) \
408 "mr 12," #ptr ";\n" \
411 #define DOT_PREFIX ""
412 #define BODY_PREFIX ""
413 #define ENTRY_2(name) \
414 ".type " #name ",@function;\n" \
416 #define END_2(name) \
417 ".size " #name ",.-" #name ";"
418 #define LOCALENTRY(name) \
419 "1: addis 2,12,.TOC.-1b@ha;\n" \
420 "addi 2,2,.TOC.-1b@l;\n" \
421 ".localentry " #name ",.-" #name ";"
423 #endif /* _CALL_ELF */
425 #endif /* __ASSEMBLER__ */