Updated to fedora-glibc-20060109T2152
[glibc/history.git] / sysdeps / powerpc / powerpc64 / sysdep.h
blob2745d7eb716811308e156f8aec825479efad4fd1
1 /* Assembly macros for 64-bit PowerPC.
2 Copyright (C) 2002, 2003, 2004, 2006 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
18 02110-1301 USA. */
20 #include <sysdeps/powerpc/sysdep.h>
22 #ifdef __ELF__
24 #ifdef __ASSEMBLER__
26 /* Support macros for CALL_MCOUNT. */
27 .macro SAVE_ARG NARG
28 .if \NARG
29 SAVE_ARG \NARG-1
30 std 2+\NARG,-72+8*(\NARG)(1)
31 .endif
32 .endm
34 .macro REST_ARG NARG
35 .if \NARG
36 REST_ARG \NARG-1
37 ld 2+\NARG,40+8*(\NARG)(1)
38 .endif
39 .endm
41 /* If compiled for profiling, call `_mcount' at the start of each function.
42 see ppc-mcount.S for more details. */
43 .macro CALL_MCOUNT NARG
44 #ifdef PROF
45 mflr r0
46 SAVE_ARG \NARG
47 std r0,16(r1)
48 stdu r1,-112(r1)
49 bl JUMPTARGET (_mcount)
50 ld r0,128(r1)
51 REST_ARG \NARG
52 addi r1,r1,112
53 mtlr r0
54 #endif
55 .endm
57 #ifdef USE_PPC64_OVERLAPPING_OPD
58 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase
59 #else
60 # define OPD_ENT(name) .quad BODY_LABEL (name), .TOC.@tocbase, 0
61 #endif
63 #define ENTRY_1(name) \
64 .section ".text"; \
65 .type BODY_LABEL(name),@function; \
66 .globl name; \
67 .section ".opd","aw"; \
68 .align 3; \
69 name##: OPD_ENT (name); \
70 .previous;
72 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
73 # define DOT_LABEL(X) .##X
74 # define BODY_LABEL(X) .##X
75 # define ENTRY_2(name) \
76 .globl BODY_LABEL(name); \
77 ENTRY_1(name) \
78 .size name, 24;
79 # define END_2(name) \
80 .size BODY_LABEL(name),.-BODY_LABEL(name);
81 #else
82 # define DOT_LABEL(X) X
83 # define BODY_LABEL(X) .LY##X
84 # define ENTRY_2(name) \
85 .type name,@function; \
86 ENTRY_1(name)
87 # define END_2(name) \
88 .size name,.-BODY_LABEL(name); \
89 .size BODY_LABEL(name),.-BODY_LABEL(name);
90 #endif
92 #define ENTRY(name) \
93 ENTRY_2(name) \
94 .align ALIGNARG(2); \
95 BODY_LABEL(name): \
96 cfi_startproc;
98 #define EALIGN_W_0 /* No words to insert. */
99 #define EALIGN_W_1 nop
100 #define EALIGN_W_2 nop;nop
101 #define EALIGN_W_3 nop;nop;nop
102 #define EALIGN_W_4 EALIGN_W_3;nop
103 #define EALIGN_W_5 EALIGN_W_4;nop
104 #define EALIGN_W_6 EALIGN_W_5;nop
105 #define EALIGN_W_7 EALIGN_W_6;nop
107 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
108 past a 2^alignt boundary. */
109 #define EALIGN(name, alignt, words) \
110 ENTRY_2(name) \
111 .align ALIGNARG(alignt); \
112 EALIGN_W_##words; \
113 BODY_LABEL(name): \
114 cfi_startproc;
116 /* Local labels stripped out by the linker. */
117 #undef L
118 #define L(x) .L##x
120 #define tostring(s) #s
121 #define stringify(s) tostring(s)
122 #define XGLUE(a,b) a##b
123 #define GLUE(a,b) XGLUE(a,b)
124 #define LT_LABEL(name) GLUE(.LT,name)
125 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
127 /* Support Traceback tables */
128 #define TB_ASM 0x000c000000000000
129 #define TB_GLOBALLINK 0x0000800000000000
130 #define TB_IS_EPROL 0x0000400000000000
131 #define TB_HAS_TBOFF 0x0000200000000000
132 #define TB_INT_PROC 0x0000100000000000
133 #define TB_HAS_CTL 0x0000080000000000
134 #define TB_TOCLESS 0x0000040000000000
135 #define TB_FP_PRESENT 0x0000020000000000
136 #define TB_LOG_ABORT 0x0000010000000000
137 #define TB_INT_HANDL 0x0000008000000000
138 #define TB_NAME_PRESENT 0x0000004000000000
139 #define TB_USES_ALLOCA 0x0000002000000000
140 #define TB_SAVES_CR 0x0000000200000000
141 #define TB_SAVES_LR 0x0000000100000000
142 #define TB_STORES_BC 0x0000000080000000
143 #define TB_FIXUP 0x0000000040000000
144 #define TB_FP_SAVED(fprs) (((fprs) & 0x3f) << 24)
145 #define TB_GPR_SAVED(gprs) (((fprs) & 0x3f) << 16)
146 #define TB_FIXEDPARMS(parms) (((parms) & 0xff) << 8)
147 #define TB_FLOATPARMS(parms) (((parms) & 0x7f) << 1)
148 #define TB_PARMSONSTK 0x0000000000000001
150 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
151 #define TB_DEFAULT TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
153 #define TRACEBACK(name) \
154 LT_LABEL(name): ; \
155 .long 0 ; \
156 .quad TB_DEFAULT ; \
157 .long LT_LABEL(name)-BODY_LABEL(name) ; \
158 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
159 LT_LABELSUFFIX(name,_name_start): ;\
160 .ascii stringify(name) ; \
161 LT_LABELSUFFIX(name,_name_end): ; \
162 .align 2 ;
164 #define TRACEBACK_MASK(name,mask) \
165 LT_LABEL(name): ; \
166 .long 0 ; \
167 .quad TB_DEFAULT | mask ; \
168 .long LT_LABEL(name)-BODY_LABEL(name) ; \
169 .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
170 LT_LABELSUFFIX(name,_name_start): ;\
171 .ascii stringify(name) ; \
172 LT_LABELSUFFIX(name,_name_end): ; \
173 .align 2 ;
175 /* END generates Traceback tables */
176 #undef END
177 #define END(name) \
178 cfi_endproc; \
179 TRACEBACK(name) \
180 END_2(name)
182 /* This form supports more informative traceback tables */
183 #define END_GEN_TB(name,mask) \
184 cfi_endproc; \
185 TRACEBACK_MASK(name,mask) \
186 END_2(name)
188 #define DO_CALL(syscall) \
189 li 0,syscall; \
192 /* ppc64 is always PIC */
193 #undef JUMPTARGET
194 #define JUMPTARGET(name) DOT_LABEL(name)
196 #define PSEUDO(name, syscall_name, args) \
197 .section ".text"; \
198 ENTRY (name) \
199 DO_CALL (SYS_ify (syscall_name));
201 #define PSEUDO_RET \
202 bnslr+; \
203 b JUMPTARGET(__syscall_error)
205 #define ret PSEUDO_RET
207 #undef PSEUDO_END
208 #define PSEUDO_END(name) \
209 END (name)
211 #define PSEUDO_NOERRNO(name, syscall_name, args) \
212 .section ".text"; \
213 ENTRY (name) \
214 DO_CALL (SYS_ify (syscall_name));
216 #define PSEUDO_RET_NOERRNO \
219 #define ret_NOERRNO PSEUDO_RET_NOERRNO
221 #undef PSEUDO_END_NOERRNO
222 #define PSEUDO_END_NOERRNO(name) \
223 END (name)
225 #define PSEUDO_ERRVAL(name, syscall_name, args) \
226 .section ".text"; \
227 ENTRY (name) \
228 DO_CALL (SYS_ify (syscall_name));
230 #define PSEUDO_RET_ERRVAL \
233 #define ret_ERRVAL PSEUDO_RET_ERRVAL
235 #undef PSEUDO_END_ERRVAL
236 #define PSEUDO_END_ERRVAL(name) \
237 END (name)
239 #else /* !__ASSEMBLER__ */
241 #ifdef USE_PPC64_OVERLAPPING_OPD
242 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
243 #else
244 # define OPD_ENT(name) ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
245 #endif
247 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
248 # define DOT_PREFIX "."
249 # define BODY_PREFIX "."
250 # define ENTRY_2(name) \
251 ".globl " BODY_PREFIX #name ";\n" \
252 ".size " #name ", 24;"
253 # define END_2(name) \
254 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
255 #else
256 # define DOT_PREFIX ""
257 # define BODY_PREFIX ".LY"
258 # define ENTRY_2(name) ".type " #name ",@function;"
259 # define END_2(name) \
260 ".size " #name ",.-" BODY_PREFIX #name ";\n" \
261 ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
262 #endif
264 #endif /* __ASSEMBLER__ */
266 #endif /* __ELF__ */