]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/rs6000/linux64.h
config.gcc (with_cpu handling): Translate sparc64 in $machine to --with-cpu=v9.
[thirdparty/gcc.git] / gcc / config / rs6000 / linux64.h
1 /* Definitions of target machine for GNU compiler,
2 for 64 bit PowerPC linux.
3 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 2, or (at your
10 option) any later version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
21
22 #ifndef RS6000_BI_ARCH
23
24 #undef DEFAULT_ABI
25 #define DEFAULT_ABI ABI_AIX
26
27 #undef TARGET_64BIT
28 #define TARGET_64BIT 1
29
30 #define DEFAULT_ARCH64_P 1
31 #define RS6000_BI_ARCH_P 0
32
33 #else
34
35 #define DEFAULT_ARCH64_P (TARGET_DEFAULT & MASK_64BIT)
36 #define RS6000_BI_ARCH_P 1
37
38 #endif
39
40 #ifdef IN_LIBGCC2
41 #undef TARGET_64BIT
42 #ifdef __powerpc64__
43 #define TARGET_64BIT 1
44 #else
45 #define TARGET_64BIT 0
46 #endif
47 #endif
48
49 #undef TARGET_AIX
50 #define TARGET_AIX TARGET_64BIT
51
52 #undef PROCESSOR_DEFAULT64
53 #define PROCESSOR_DEFAULT64 PROCESSOR_PPC630
54
55 #undef TARGET_RELOCATABLE
56 #define TARGET_RELOCATABLE (!TARGET_64BIT && (target_flags & MASK_RELOCATABLE))
57
58 #undef RS6000_ABI_NAME
59 #define RS6000_ABI_NAME (TARGET_64BIT ? "aixdesc" : "sysv")
60
61 #define INVALID_64BIT "-m%s not supported in this configuration"
62 #define INVALID_32BIT INVALID_64BIT
63
64 #undef SUBSUBTARGET_OVERRIDE_OPTIONS
65 #define SUBSUBTARGET_OVERRIDE_OPTIONS \
66 do \
67 { \
68 if (TARGET_64BIT) \
69 { \
70 if (DEFAULT_ABI != ABI_AIX) \
71 { \
72 DEFAULT_ABI = ABI_AIX; \
73 error (INVALID_64BIT, "call"); \
74 } \
75 if (TARGET_RELOCATABLE) \
76 { \
77 target_flags &= ~MASK_RELOCATABLE; \
78 error (INVALID_64BIT, "relocatable"); \
79 } \
80 if (TARGET_EABI) \
81 { \
82 target_flags &= ~MASK_EABI; \
83 error (INVALID_64BIT, "eabi"); \
84 } \
85 if (TARGET_PROTOTYPE) \
86 { \
87 target_flags &= ~MASK_PROTOTYPE; \
88 error (INVALID_64BIT, "prototype"); \
89 } \
90 } \
91 else \
92 { \
93 if (!RS6000_BI_ARCH_P) \
94 error (INVALID_32BIT, "32"); \
95 } \
96 } \
97 while (0)
98
99 #ifdef RS6000_BI_ARCH
100
101 #undef OVERRIDE_OPTIONS
102 #define OVERRIDE_OPTIONS \
103 rs6000_override_options (((TARGET_DEFAULT ^ target_flags) & MASK_64BIT) \
104 ? (char *) 0 : TARGET_CPU_DEFAULT)
105
106 #undef ASM_FILE_START
107 #define ASM_FILE_START(FILE) \
108 do \
109 { \
110 output_file_directive ((FILE), main_input_filename); \
111 rs6000_file_start (FILE, (((TARGET_DEFAULT ^ target_flags) \
112 & MASK_64BIT) \
113 ? (char *) 0 : TARGET_CPU_DEFAULT)); \
114 } \
115 while (0)
116
117 #endif
118
119 #undef ASM_DEFAULT_SPEC
120 #undef ASM_SPEC
121 #undef LINK_OS_LINUX_SPEC
122
123 #ifndef RS6000_BI_ARCH
124 #define ASM_DEFAULT_SPEC "-mppc64"
125 #define ASM_SPEC "%(asm_spec64) %(asm_spec_common)"
126 #define LINK_OS_LINUX_SPEC "%(link_os_linux_spec64)"
127 #else
128 #if DEFAULT_ARCH64_P
129 #define ASM_DEFAULT_SPEC "-mppc%{!m32:64}"
130 #define ASM_SPEC "%{m32:%(asm_spec32)}%{!m32:%(asm_spec64)} %(asm_spec_common)"
131 #define LINK_OS_LINUX_SPEC "%{m32:%(link_os_linux_spec32)}%{!m32:%(link_os_linux_spec64)}"
132 #else
133 #define ASM_DEFAULT_SPEC "-mppc%{m64:64}"
134 #define ASM_SPEC "%{!m64:%(asm_spec32)}%{m64:%(asm_spec64)} %(asm_spec_common)"
135 #define LINK_OS_LINUX_SPEC "%{!m64:%(link_os_linux_spec32)}%{m64:%(link_os_linux_spec64)}"
136 #endif
137 #endif
138
139 #define ASM_SPEC32 "-a32 %{n} %{T} %{Ym,*} %{Yd,*} \
140 %{mrelocatable} %{mrelocatable-lib} %{fpic:-K PIC} %{fPIC:-K PIC} \
141 %{memb} %{!memb: %{msdata: -memb} %{msdata=eabi: -memb}} \
142 %{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \
143 %{mcall-freebsd: -mbig} \
144 %{mcall-i960-old: -mlittle} \
145 %{mcall-linux: -mbig} \
146 %{mcall-gnu: -mbig} \
147 %{mcall-netbsd: -mbig} \
148 }}}}"
149
150 #define ASM_SPEC64 "-a64"
151
152 #define ASM_SPEC_COMMON "%(asm_cpu) \
153 %{.s: %{mregnames} %{mno-regnames}} %{.S: %{mregnames} %{mno-regnames}} \
154 %{v:-V} %{Qy:} %{!Qn:-Qy} %{Wa,*:%*} \
155 %{mlittle} %{mlittle-endian} %{mbig} %{mbig-endian}"
156
157 #undef SUBSUBTARGET_EXTRA_SPECS
158 #define SUBSUBTARGET_EXTRA_SPECS \
159 { "asm_spec_common", ASM_SPEC_COMMON }, \
160 { "asm_spec32", ASM_SPEC32 }, \
161 { "asm_spec64", ASM_SPEC64 }, \
162 { "link_os_linux_spec32", LINK_OS_LINUX_SPEC32 }, \
163 { "link_os_linux_spec64", LINK_OS_LINUX_SPEC64 },
164
165 #undef MULTILIB_DEFAULTS
166 #if DEFAULT_ARCH64_P
167 #define MULTILIB_DEFAULTS { "m64" }
168 #else
169 #define MULTILIB_DEFAULTS { "m32" }
170 #endif
171
172 #ifndef RS6000_BI_ARCH
173
174 /* 64-bit PowerPC Linux always has a TOC. */
175 #undef TARGET_TOC
176 #define TARGET_TOC 1
177
178 /* Some things from sysv4.h we don't do when 64 bit. */
179 #undef TARGET_RELOCATABLE
180 #define TARGET_RELOCATABLE 0
181 #undef TARGET_EABI
182 #define TARGET_EABI 0
183 #undef TARGET_PROTOTYPE
184 #define TARGET_PROTOTYPE 0
185
186 #endif
187
188 #define MASK_PROFILE_KERNEL 0x00080000
189
190 /* Non-standard profiling for kernels, which just saves LR then calls
191 _mcount without worrying about arg saves. The idea is to change
192 the function prologue as little as possible as it isn't easy to
193 account for arg save/restore code added just for _mcount. */
194 #define TARGET_PROFILE_KERNEL (target_flags & MASK_PROFILE_KERNEL)
195
196 /* Override sysv4.h. */
197 #undef EXTRA_SUBTARGET_SWITCHES
198 #define EXTRA_SUBTARGET_SWITCHES \
199 {"profile-kernel", MASK_PROFILE_KERNEL, \
200 N_("Call mcount for profiling before a function prologue") }, \
201 {"no-profile-kernel", -MASK_PROFILE_KERNEL, \
202 N_("Call mcount for profiling after a function prologue") },
203
204 /* We use glibc _mcount for profiling. */
205 #define NO_PROFILE_COUNTERS TARGET_64BIT
206 #define PROFILE_HOOK(LABEL) \
207 do { if (TARGET_64BIT) output_profile_hook (LABEL); } while (0)
208
209 /* We don't need to generate entries in .fixup. */
210 #undef RELOCATABLE_NEEDS_FIXUP
211
212 /* This now supports a natural alignment mode. */
213 /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints. */
214 #undef ADJUST_FIELD_ALIGN
215 #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
216 ((TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (FIELD)) == VECTOR_TYPE) \
217 ? 128 \
218 : (TARGET_64BIT \
219 && TARGET_ALIGN_NATURAL == 0 \
220 && TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
221 ? get_inner_array_type (FIELD) \
222 : TREE_TYPE (FIELD)) == DFmode) \
223 ? MIN ((COMPUTED), 32) \
224 : (COMPUTED))
225
226 /* AIX increases natural record alignment to doubleword if the first
227 field is an FP double while the FP fields remain word aligned. */
228 #undef ROUND_TYPE_ALIGN
229 #define ROUND_TYPE_ALIGN(STRUCT, COMPUTED, SPECIFIED) \
230 ((TARGET_ALTIVEC && TREE_CODE (STRUCT) == VECTOR_TYPE) \
231 ? MAX (MAX ((COMPUTED), (SPECIFIED)), 128) \
232 : (TARGET_64BIT \
233 && (TREE_CODE (STRUCT) == RECORD_TYPE \
234 || TREE_CODE (STRUCT) == UNION_TYPE \
235 || TREE_CODE (STRUCT) == QUAL_UNION_TYPE) \
236 && TYPE_FIELDS (STRUCT) != 0 \
237 && TARGET_ALIGN_NATURAL == 0 \
238 && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode) \
239 ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64) \
240 : MAX ((COMPUTED), (SPECIFIED)))
241
242 /* Indicate that jump tables go in the text section. */
243 #undef JUMP_TABLES_IN_TEXT_SECTION
244 #define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
245
246 /* __throw will restore its own return address to be the same as the
247 return address of the function that the throw is being made to.
248 This is unfortunate, because we want to check the original
249 return address to see if we need to restore the TOC.
250 So we have to squirrel it away with this. */
251 #define SETUP_FRAME_ADDRESSES() \
252 do { if (TARGET_64BIT) rs6000_aix_emit_builtin_unwind_init (); } while (0)
253
254 /* Override svr4.h */
255 #undef MD_EXEC_PREFIX
256 #undef MD_STARTFILE_PREFIX
257
258 /* Override sysv4.h */
259 #undef CPP_SYSV_SPEC
260 #define CPP_SYSV_SPEC ""
261
262 #undef TARGET_OS_CPP_BUILTINS
263 #define TARGET_OS_CPP_BUILTINS() \
264 do \
265 { \
266 if (TARGET_64BIT) \
267 { \
268 builtin_define ("__PPC__"); \
269 builtin_define ("__PPC64__"); \
270 builtin_define ("__powerpc__"); \
271 builtin_define ("__powerpc64__"); \
272 builtin_define ("__PIC__"); \
273 builtin_assert ("cpu=powerpc64"); \
274 builtin_assert ("machine=powerpc64"); \
275 } \
276 else \
277 { \
278 builtin_define_std ("PPC"); \
279 builtin_define_std ("powerpc"); \
280 builtin_assert ("cpu=powerpc"); \
281 builtin_assert ("machine=powerpc"); \
282 TARGET_OS_SYSV_CPP_BUILTINS (); \
283 } \
284 } \
285 while (0)
286
287 #undef CPP_OS_DEFAULT_SPEC
288 #define CPP_OS_DEFAULT_SPEC "%(cpp_os_linux)"
289
290 /* The GNU C++ standard library currently requires _GNU_SOURCE being
291 defined on glibc-based systems. This temporary hack accomplishes this,
292 it should go away as soon as libstdc++-v3 has a real fix. */
293 #undef CPLUSPLUS_CPP_SPEC
294 #define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
295
296 #undef LINK_SHLIB_SPEC
297 #define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}}"
298
299 #undef LIB_DEFAULT_SPEC
300 #define LIB_DEFAULT_SPEC "%(lib_linux)"
301
302 #undef STARTFILE_DEFAULT_SPEC
303 #define STARTFILE_DEFAULT_SPEC "%(startfile_linux)"
304
305 #undef ENDFILE_DEFAULT_SPEC
306 #define ENDFILE_DEFAULT_SPEC "%(endfile_linux)"
307
308 #undef LINK_START_DEFAULT_SPEC
309 #define LINK_START_DEFAULT_SPEC "%(link_start_linux)"
310
311 #undef LINK_OS_DEFAULT_SPEC
312 #define LINK_OS_DEFAULT_SPEC "%(link_os_linux)"
313
314 #define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \
315 %{rdynamic:-export-dynamic} \
316 %{!dynamic-linker:-dynamic-linker /lib/ld.so.1}}}"
317
318 #define LINK_OS_LINUX_SPEC64 "-m elf64ppc %{!shared: %{!static: \
319 %{rdynamic:-export-dynamic} \
320 %{!dynamic-linker:-dynamic-linker /lib64/ld64.so.1}}}"
321
322 #undef TOC_SECTION_ASM_OP
323 #define TOC_SECTION_ASM_OP \
324 (TARGET_64BIT \
325 ? "\t.section\t\".toc\",\"aw\"" \
326 : "\t.section\t\".got\",\"aw\"")
327
328 #undef MINIMAL_TOC_SECTION_ASM_OP
329 #define MINIMAL_TOC_SECTION_ASM_OP \
330 (TARGET_64BIT \
331 ? "\t.section\t\".toc1\",\"aw\"" \
332 : ((TARGET_RELOCATABLE || flag_pic) \
333 ? "\t.section\t\".got2\",\"aw\"" \
334 : "\t.section\t\".got1\",\"aw\""))
335
336 #undef TARGET_VERSION
337 #define TARGET_VERSION fprintf (stderr, " (PowerPC64 GNU/Linux)");
338
339 /* Must be at least as big as our pointer type. */
340 #undef SIZE_TYPE
341 #define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int")
342
343 #undef PTRDIFF_TYPE
344 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
345
346 #undef WCHAR_TYPE
347 #define WCHAR_TYPE (TARGET_64BIT ? "int" : "long int")
348 #undef WCHAR_TYPE_SIZE
349 #define WCHAR_TYPE_SIZE 32
350
351 /* Override rs6000.h definition. */
352 #undef ASM_APP_ON
353 #define ASM_APP_ON "#APP\n"
354
355 /* Override rs6000.h definition. */
356 #undef ASM_APP_OFF
357 #define ASM_APP_OFF "#NO_APP\n"
358
359 /* PowerPC no-op instruction. */
360 #undef RS6000_CALL_GLUE
361 #define RS6000_CALL_GLUE (TARGET_64BIT ? "nop" : "cror 31,31,31")
362
363 #undef RS6000_MCOUNT
364 #define RS6000_MCOUNT "_mcount"
365
366 #ifdef __powerpc64__
367 /* _init and _fini functions are built from bits spread across many
368 object files, each potentially with a different TOC pointer. For
369 that reason, place a nop after the call so that the linker can
370 restore the TOC pointer if a TOC adjusting call stub is needed. */
371 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
372 asm (SECTION_OP "\n" \
373 " bl ." #FUNC "\n" \
374 " nop\n" \
375 " .previous");
376 #endif
377
378 /* FP save and restore routines. */
379 #undef SAVE_FP_PREFIX
380 #define SAVE_FP_PREFIX (TARGET_64BIT ? "._savef" : "_savefpr_")
381 #undef SAVE_FP_SUFFIX
382 #define SAVE_FP_SUFFIX (TARGET_64BIT ? "" : "_l")
383 #undef RESTORE_FP_PREFIX
384 #define RESTORE_FP_PREFIX (TARGET_64BIT ? "._restf" : "_restfpr_")
385 #undef RESTORE_FP_SUFFIX
386 #define RESTORE_FP_SUFFIX (TARGET_64BIT ? "" : "_l")
387
388 /* Dwarf2 debugging. */
389 #undef PREFERRED_DEBUGGING_TYPE
390 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
391
392 /* This is how to declare the size of a function. */
393 #undef ASM_DECLARE_FUNCTION_SIZE
394 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
395 do \
396 { \
397 if (!flag_inhibit_size_directive) \
398 { \
399 fputs ("\t.size\t", (FILE)); \
400 if (TARGET_64BIT) \
401 putc ('.', (FILE)); \
402 assemble_name ((FILE), (FNAME)); \
403 fputs (",.-", (FILE)); \
404 if (TARGET_64BIT) \
405 putc ('.', (FILE)); \
406 assemble_name ((FILE), (FNAME)); \
407 putc ('\n', (FILE)); \
408 } \
409 } \
410 while (0)
411
412 /* Return nonzero if this entry is to be written into the constant
413 pool in a special way. We do so if this is a SYMBOL_REF, LABEL_REF
414 or a CONST containing one of them. If -mfp-in-toc (the default),
415 we also do this for floating-point constants. We actually can only
416 do this if the FP formats of the target and host machines are the
417 same, but we can't check that since not every file that uses
418 GO_IF_LEGITIMATE_ADDRESS_P includes real.h. We also do this when
419 we can write the entry into the TOC and the entry is not larger
420 than a TOC entry. */
421
422 #undef ASM_OUTPUT_SPECIAL_POOL_ENTRY_P
423 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE) \
424 (TARGET_TOC \
425 && (GET_CODE (X) == SYMBOL_REF \
426 || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS \
427 && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF) \
428 || GET_CODE (X) == LABEL_REF \
429 || (GET_CODE (X) == CONST_INT \
430 && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode)) \
431 || (GET_CODE (X) == CONST_DOUBLE \
432 && ((TARGET_64BIT \
433 && (TARGET_POWERPC64 \
434 || TARGET_MINIMAL_TOC \
435 || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
436 && ! TARGET_NO_FP_IN_TOC))) \
437 || (!TARGET_64BIT \
438 && !TARGET_NO_FP_IN_TOC \
439 && !TARGET_RELOCATABLE \
440 && GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
441 && BITS_PER_WORD == HOST_BITS_PER_INT)))))
442
443 /* This is the same as the dbxelf.h version, except that we need to
444 use the function code label, not the function descriptor. */
445 #undef ASM_OUTPUT_SOURCE_LINE
446 #define ASM_OUTPUT_SOURCE_LINE(FILE, LINE) \
447 do \
448 { \
449 static int sym_lineno = 1; \
450 char temp[256]; \
451 ASM_GENERATE_INTERNAL_LABEL (temp, "LM", sym_lineno); \
452 fprintf (FILE, "\t.stabn 68,0,%d,", LINE); \
453 assemble_name (FILE, temp); \
454 putc ('-', FILE); \
455 if (TARGET_64BIT) \
456 putc ('.', FILE); \
457 assemble_name (FILE, \
458 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));\
459 putc ('\n', FILE); \
460 (*targetm.asm_out.internal_label) (FILE, "LM", sym_lineno); \
461 sym_lineno += 1; \
462 } \
463 while (0)
464
465 /* Similarly, we want the function code label here. */
466 #define DBX_OUTPUT_BRAC(FILE, NAME, BRAC) \
467 do \
468 { \
469 const char *flab; \
470 fprintf (FILE, "%s%d,0,0,", ASM_STABN_OP, BRAC); \
471 assemble_name (FILE, NAME); \
472 putc ('-', FILE); \
473 if (current_function_func_begin_label != NULL_TREE) \
474 flab = IDENTIFIER_POINTER (current_function_func_begin_label); \
475 else \
476 { \
477 if (TARGET_64BIT) \
478 putc ('.', FILE); \
479 flab = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); \
480 } \
481 assemble_name (FILE, flab); \
482 putc ('\n', FILE); \
483 } \
484 while (0)
485
486 #define DBX_OUTPUT_LBRAC(FILE, NAME) DBX_OUTPUT_BRAC (FILE, NAME, N_LBRAC)
487 #define DBX_OUTPUT_RBRAC(FILE, NAME) DBX_OUTPUT_BRAC (FILE, NAME, N_RBRAC)
488
489 /* Another case where we want the dot name. */
490 #define DBX_OUTPUT_NFUN(FILE, LSCOPE, DECL) \
491 do \
492 { \
493 fprintf (FILE, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN); \
494 assemble_name (FILE, LSCOPE); \
495 putc ('-', FILE); \
496 if (TARGET_64BIT) \
497 putc ('.', FILE); \
498 assemble_name (FILE, XSTR (XEXP (DECL_RTL (DECL), 0), 0)); \
499 putc ('\n', FILE); \
500 } \
501 while (0)
502
503 /* Select a format to encode pointers in exception handling data. CODE
504 is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
505 true if the symbol may be affected by dynamic relocations. */
506 #undef ASM_PREFERRED_EH_DATA_FORMAT
507 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
508 ((TARGET_64BIT || flag_pic || TARGET_RELOCATABLE) \
509 ? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel \
510 | (TARGET_64BIT ? DW_EH_PE_udata8 : DW_EH_PE_sdata4)) \
511 : DW_EH_PE_absptr)
512
513 /* For backward compatibility, we must continue to use the AIX
514 structure return convention. */
515 #undef DRAFT_V4_STRUCT_RET
516 #define DRAFT_V4_STRUCT_RET (!TARGET_64BIT)
517
518 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
519
520 /* Do code reading to identify a signal frame, and set the frame
521 state data appropriately. See unwind-dw2.c for the structs. */
522
523 #ifdef IN_LIBGCC2
524 #include <signal.h>
525 #include <sys/ucontext.h>
526
527 #ifdef __powerpc64__
528 enum { SIGNAL_FRAMESIZE = 128 };
529 #else
530 enum { SIGNAL_FRAMESIZE = 64 };
531 #endif
532 #endif
533
534 #ifdef __powerpc64__
535
536 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
537 do { \
538 unsigned char *pc_ = (CONTEXT)->ra; \
539 struct sigcontext *sc_; \
540 long new_cfa_; \
541 int i_; \
542 \
543 /* addi r1, r1, 128; li r0, 0x0077; sc (sigreturn) */ \
544 /* addi r1, r1, 128; li r0, 0x00AC; sc (rt_sigreturn) */ \
545 if (*(unsigned int *) (pc_+0) != 0x38210000 + SIGNAL_FRAMESIZE \
546 || *(unsigned int *) (pc_+8) != 0x44000002) \
547 break; \
548 if (*(unsigned int *) (pc_+4) == 0x38000077) \
549 { \
550 struct sigframe { \
551 char gap[SIGNAL_FRAMESIZE]; \
552 struct sigcontext sigctx; \
553 } *rt_ = (CONTEXT)->cfa; \
554 sc_ = &rt_->sigctx; \
555 } \
556 else if (*(unsigned int *) (pc_+4) == 0x380000AC) \
557 { \
558 struct rt_sigframe { \
559 int tramp[6]; \
560 struct siginfo *pinfo; \
561 struct ucontext *puc; \
562 } *rt_ = (struct rt_sigframe *) pc_; \
563 sc_ = &rt_->puc->uc_mcontext; \
564 } \
565 else \
566 break; \
567 \
568 new_cfa_ = sc_->regs->gpr[STACK_POINTER_REGNUM]; \
569 (FS)->cfa_how = CFA_REG_OFFSET; \
570 (FS)->cfa_reg = STACK_POINTER_REGNUM; \
571 (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \
572 \
573 for (i_ = 0; i_ < 32; i_++) \
574 if (i_ != STACK_POINTER_REGNUM) \
575 { \
576 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
577 (FS)->regs.reg[i_].loc.offset \
578 = (long)&(sc_->regs->gpr[i_]) - new_cfa_; \
579 } \
580 \
581 (FS)->regs.reg[LINK_REGISTER_REGNUM].how = REG_SAVED_OFFSET; \
582 (FS)->regs.reg[LINK_REGISTER_REGNUM].loc.offset \
583 = (long)&(sc_->regs->link) - new_cfa_; \
584 \
585 /* The unwinder expects the IP to point to the following insn, \
586 whereas the kernel returns the address of the actual \
587 faulting insn. We store NIP+4 in an unused register slot to \
588 get the same result for multiple evaluation of the same signal \
589 frame. */ \
590 sc_->regs->gpr[47] = sc_->regs->nip + 4; \
591 (FS)->regs.reg[CR0_REGNO].how = REG_SAVED_OFFSET; \
592 (FS)->regs.reg[CR0_REGNO].loc.offset \
593 = (long)&(sc_->regs->gpr[47]) - new_cfa_; \
594 (FS)->retaddr_column = CR0_REGNO; \
595 goto SUCCESS; \
596 } while (0)
597
598 #else
599
600 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
601 do { \
602 unsigned char *pc_ = (CONTEXT)->ra; \
603 struct sigcontext *sc_; \
604 long new_cfa_; \
605 int i_; \
606 \
607 /* li r0, 0x7777; sc (sigreturn old) */ \
608 /* li r0, 0x0077; sc (sigreturn new) */ \
609 /* li r0, 0x6666; sc (rt_sigreturn old) */ \
610 /* li r0, 0x00AC; sc (rt_sigreturn new) */ \
611 if (*(unsigned int *) (pc_+4) != 0x44000002) \
612 break; \
613 if (*(unsigned int *) (pc_+0) == 0x38007777 \
614 || *(unsigned int *) (pc_+0) == 0x38000077) \
615 { \
616 struct sigframe { \
617 char gap[SIGNAL_FRAMESIZE]; \
618 struct sigcontext sigctx; \
619 } *rt_ = (CONTEXT)->cfa; \
620 sc_ = &rt_->sigctx; \
621 } \
622 else if (*(unsigned int *) (pc_+0) == 0x38006666 \
623 || *(unsigned int *) (pc_+0) == 0x380000AC) \
624 { \
625 struct rt_sigframe { \
626 char gap[SIGNAL_FRAMESIZE]; \
627 unsigned long _unused[2]; \
628 struct siginfo *pinfo; \
629 void *puc; \
630 struct siginfo info; \
631 struct ucontext uc; \
632 } *rt_ = (CONTEXT)->cfa; \
633 sc_ = &rt_->uc.uc_mcontext; \
634 } \
635 else \
636 break; \
637 \
638 new_cfa_ = sc_->regs->gpr[STACK_POINTER_REGNUM]; \
639 (FS)->cfa_how = CFA_REG_OFFSET; \
640 (FS)->cfa_reg = STACK_POINTER_REGNUM; \
641 (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \
642 \
643 for (i_ = 0; i_ < 32; i_++) \
644 if (i_ != STACK_POINTER_REGNUM) \
645 { \
646 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
647 (FS)->regs.reg[i_].loc.offset \
648 = (long)&(sc_->regs->gpr[i_]) - new_cfa_; \
649 } \
650 \
651 (FS)->regs.reg[LINK_REGISTER_REGNUM].how = REG_SAVED_OFFSET; \
652 (FS)->regs.reg[LINK_REGISTER_REGNUM].loc.offset \
653 = (long)&(sc_->regs->link) - new_cfa_; \
654 \
655 /* The unwinder expects the IP to point to the following insn, \
656 whereas the kernel returns the address of the actual \
657 faulting insn. We store NIP+4 in an unused register slot to \
658 get the same result for multiple evaluation of the same signal \
659 frame. */ \
660 sc_->regs->gpr[47] = sc_->regs->nip + 4; \
661 (FS)->regs.reg[CR0_REGNO].how = REG_SAVED_OFFSET; \
662 (FS)->regs.reg[CR0_REGNO].loc.offset \
663 = (long)&(sc_->regs->gpr[47]) - new_cfa_; \
664 (FS)->retaddr_column = CR0_REGNO; \
665 goto SUCCESS; \
666 } while (0)
667
668 #endif