Remove __ELF__ conditionals
[platform/upstream/glibc.git] / sysdeps / powerpc / powerpc64 / sysdep.h
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.
4
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.
9
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.
14
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
18    02110-1301 USA.  */
19
20 #include <sysdeps/powerpc/sysdep.h>
21
22 #ifdef __ASSEMBLER__
23
24 /* Support macros for CALL_MCOUNT.  */
25         .macro SAVE_ARG NARG
26         .if \NARG
27         SAVE_ARG \NARG-1
28         std     2+\NARG,40+8*(\NARG)(1)
29         .endif
30         .endm
31
32         .macro REST_ARG NARG
33         .if \NARG
34         REST_ARG \NARG-1
35         ld      2+\NARG,112+40+8*(\NARG)(1)
36         .endif
37         .endm
38
39         .macro CFI_SAVE_ARG NARG
40         .if \NARG
41         CFI_SAVE_ARG \NARG-1
42         cfi_offset(2+\NARG,40+8*(\NARG))
43         .endif
44         .endm
45
46         .macro CFI_REST_ARG NARG
47         .if \NARG
48         CFI_REST_ARG \NARG-1
49         cfi_restore(2+\NARG)
50         .endif
51         .endm
52
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
56 #ifdef  PROF
57         mflr    r0
58         SAVE_ARG \NARG
59         std     r0,16(r1)
60         stdu    r1,-112(r1)
61         cfi_adjust_cfa_offset(112)
62         cfi_offset(lr,16)
63         CFI_SAVE_ARG \NARG
64         bl      JUMPTARGET (_mcount)
65 #ifndef SHARED
66         nop
67 #endif
68         ld      r0,128(r1)
69         REST_ARG \NARG
70         mtlr    r0
71         addi    r1,r1,112
72         cfi_adjust_cfa_offset(-112)
73         cfi_restore(lr)
74         CFI_REST_ARG \NARG
75 #endif
76         .endm
77
78 #ifdef USE_PPC64_OVERLAPPING_OPD
79 # define OPD_ENT(name)  .quad BODY_LABEL (name), .TOC.@tocbase
80 #else
81 # define OPD_ENT(name)  .quad BODY_LABEL (name), .TOC.@tocbase, 0
82 #endif
83
84 #define ENTRY_1(name)   \
85         .section        ".text";                \
86         .type BODY_LABEL(name),@function;       \
87         .globl name;                            \
88         .section ".opd","aw";                   \
89         .align 3;                               \
90 name##: OPD_ENT (name);                         \
91         .previous;
92
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);                \
98         ENTRY_1(name)                           \
99         .size name, 24;
100 # define END_2(name)    \
101         .size BODY_LABEL(name),.-BODY_LABEL(name);
102 #else
103 # define DOT_LABEL(X) X
104 # define BODY_LABEL(X) .LY##X
105 # define ENTRY_2(name)  \
106         .type name,@function;                   \
107         ENTRY_1(name)
108 # define END_2(name)    \
109         .size name,.-BODY_LABEL(name);          \
110         .size BODY_LABEL(name),.-BODY_LABEL(name);
111 #endif
112
113 #define ENTRY(name)     \
114         ENTRY_2(name)                           \
115         .align ALIGNARG(2);                     \
116 BODY_LABEL(name):                               \
117         cfi_startproc;
118
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
127
128 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
129    past a 2^alignt boundary.  */
130 #define EALIGN(name, alignt, words) \
131         ENTRY_2(name)                           \
132         .align ALIGNARG(alignt);                \
133         EALIGN_W_##words;                       \
134 BODY_LABEL(name):                               \
135         cfi_startproc;
136
137 /* Local labels stripped out by the linker.  */
138 #undef L
139 #define L(x) .L##x
140
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)
147
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
170
171 #define PPC_HIGHER(v)           (((v) >> 32) & 0xffff)
172 #define TB_DEFAULT              TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
173
174 #define TRACEBACK(name) \
175 LT_LABEL(name): ; \
176         .long   0 ; \
177         .quad   TB_DEFAULT ; \
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): ; \
183         .align  2 ;
184
185 #define TRACEBACK_MASK(name,mask) \
186 LT_LABEL(name): ; \
187         .long   0 ; \
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): ; \
194         .align  2 ;
195
196 /* END generates Traceback tables */
197 #undef  END
198 #define END(name) \
199   cfi_endproc;                  \
200   TRACEBACK(name)               \
201   END_2(name)
202
203 /* This form supports more informative traceback tables */
204 #define END_GEN_TB(name,mask)   \
205   cfi_endproc;                  \
206   TRACEBACK_MASK(name,mask)     \
207   END_2(name)
208
209 #define DO_CALL(syscall) \
210     li 0,syscall; \
211     sc
212
213 /* ppc64 is always PIC */
214 #undef JUMPTARGET
215 #define JUMPTARGET(name) DOT_LABEL(name)
216
217 #define PSEUDO(name, syscall_name, args) \
218   .section ".text";     \
219   ENTRY (name) \
220   DO_CALL (SYS_ify (syscall_name));
221
222 #ifdef SHARED
223 #define TAIL_CALL_SYSCALL_ERROR \
224     b JUMPTARGET(__syscall_error)
225 #else
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; \
232     .else; \
233 .Local_syscall_error: \
234     mflr 0; \
235     std 0,16(1); \
236     stdu 1,-112(1); \
237     cfi_adjust_cfa_offset(112); \
238     cfi_offset(lr,16); \
239     bl JUMPTARGET(__syscall_error); \
240     nop; \
241     ld 0,112+16(1); \
242     addi 1,1,112; \
243     cfi_adjust_cfa_offset(-112); \
244     mtlr 0; \
245     cfi_restore(lr); \
246     blr; \
247     .endif
248 #endif
249
250 #define PSEUDO_RET \
251     bnslr+; \
252     TAIL_CALL_SYSCALL_ERROR
253
254 #define ret PSEUDO_RET
255
256 #undef  PSEUDO_END
257 #define PSEUDO_END(name) \
258   END (name)
259
260 #define PSEUDO_NOERRNO(name, syscall_name, args) \
261   .section ".text";     \
262   ENTRY (name) \
263   DO_CALL (SYS_ify (syscall_name));
264
265 #define PSEUDO_RET_NOERRNO \
266     blr
267
268 #define ret_NOERRNO PSEUDO_RET_NOERRNO
269
270 #undef  PSEUDO_END_NOERRNO
271 #define PSEUDO_END_NOERRNO(name) \
272   END (name)
273
274 #define PSEUDO_ERRVAL(name, syscall_name, args) \
275   .section ".text";     \
276   ENTRY (name) \
277   DO_CALL (SYS_ify (syscall_name));
278
279 #define PSEUDO_RET_ERRVAL \
280     blr
281
282 #define ret_ERRVAL PSEUDO_RET_ERRVAL
283
284 #undef  PSEUDO_END_ERRVAL
285 #define PSEUDO_END_ERRVAL(name) \
286   END (name)
287
288 #else /* !__ASSEMBLER__ */
289
290 #ifdef USE_PPC64_OVERLAPPING_OPD
291 # define OPD_ENT(name)  ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
292 #else
293 # define OPD_ENT(name)  ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
294 #endif
295
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 ";"
304 #else
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 ";"
311 #endif
312
313 #endif  /* __ASSEMBLER__ */