OSDN Git Service

* config/i386/linux.h (NO_PROFILE_COUNTERS): Define to 1.
[pf3gnuchains/gcc-fork.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 /* FP save and restore routines.  */
367 #undef  SAVE_FP_PREFIX
368 #define SAVE_FP_PREFIX (TARGET_64BIT ? "._savef" : "_savefpr_")
369 #undef  SAVE_FP_SUFFIX
370 #define SAVE_FP_SUFFIX (TARGET_64BIT ? "" : "_l")
371 #undef  RESTORE_FP_PREFIX
372 #define RESTORE_FP_PREFIX (TARGET_64BIT ? "._restf" : "_restfpr_")
373 #undef  RESTORE_FP_SUFFIX
374 #define RESTORE_FP_SUFFIX (TARGET_64BIT ? "" : "_l")
375
376 /* Dwarf2 debugging.  */
377 #undef  PREFERRED_DEBUGGING_TYPE
378 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
379
380 /* This is how to declare the size of a function.  */
381 #undef  ASM_DECLARE_FUNCTION_SIZE
382 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)                    \
383   do                                                                    \
384     {                                                                   \
385       if (!flag_inhibit_size_directive)                                 \
386         {                                                               \
387           fputs ("\t.size\t", (FILE));                                  \
388           if (TARGET_64BIT)                                             \
389             putc ('.', (FILE));                                         \
390           assemble_name ((FILE), (FNAME));                              \
391           fputs (",.-", (FILE));                                        \
392           if (TARGET_64BIT)                                             \
393             putc ('.', (FILE));                                         \
394           assemble_name ((FILE), (FNAME));                              \
395           putc ('\n', (FILE));                                          \
396         }                                                               \
397     }                                                                   \
398   while (0)
399
400 /* Return nonzero if this entry is to be written into the constant
401    pool in a special way.  We do so if this is a SYMBOL_REF, LABEL_REF
402    or a CONST containing one of them.  If -mfp-in-toc (the default),
403    we also do this for floating-point constants.  We actually can only
404    do this if the FP formats of the target and host machines are the
405    same, but we can't check that since not every file that uses
406    GO_IF_LEGITIMATE_ADDRESS_P includes real.h.  We also do this when
407    we can write the entry into the TOC and the entry is not larger
408    than a TOC entry.  */
409
410 #undef  ASM_OUTPUT_SPECIAL_POOL_ENTRY_P
411 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)                        \
412   (TARGET_TOC                                                           \
413    && (GET_CODE (X) == SYMBOL_REF                                       \
414        || (GET_CODE (X) == CONST && GET_CODE (XEXP (X, 0)) == PLUS      \
415            && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF)           \
416        || GET_CODE (X) == LABEL_REF                                     \
417        || (GET_CODE (X) == CONST_INT                                    \
418            && GET_MODE_BITSIZE (MODE) <= GET_MODE_BITSIZE (Pmode))      \
419        || (GET_CODE (X) == CONST_DOUBLE                                 \
420            && ((TARGET_64BIT                                            \
421                 && (TARGET_POWERPC64                                    \
422                     || TARGET_MINIMAL_TOC                               \
423                     || (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT     \
424                         && ! TARGET_NO_FP_IN_TOC)))                     \
425                || (!TARGET_64BIT                                        \
426                    && !TARGET_NO_FP_IN_TOC                              \
427                    && !TARGET_RELOCATABLE                               \
428                    && GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT       \
429                    && BITS_PER_WORD == HOST_BITS_PER_INT)))))
430
431 /* This is the same as the dbxelf.h version, except that we need to
432    use the function code label, not the function descriptor.  */
433 #undef  ASM_OUTPUT_SOURCE_LINE
434 #define ASM_OUTPUT_SOURCE_LINE(FILE, LINE)                              \
435 do                                                                      \
436   {                                                                     \
437     static int sym_lineno = 1;                                          \
438     char temp[256];                                                     \
439     ASM_GENERATE_INTERNAL_LABEL (temp, "LM", sym_lineno);               \
440     fprintf (FILE, "\t.stabn 68,0,%d,", LINE);                          \
441     assemble_name (FILE, temp);                                         \
442     putc ('-', FILE);                                                   \
443     if (TARGET_64BIT)                                                   \
444       putc ('.', FILE);                                                 \
445     assemble_name (FILE,                                                \
446                    XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));\
447     putc ('\n', FILE);                                                  \
448     (*targetm.asm_out.internal_label) (FILE, "LM", sym_lineno);         \
449     sym_lineno += 1;                                                    \
450   }                                                                     \
451 while (0)
452
453 /* Similarly, we want the function code label here.  */
454 #define DBX_OUTPUT_BRAC(FILE, NAME, BRAC) \
455   do                                                                    \
456     {                                                                   \
457       const char *flab;                                                 \
458       fprintf (FILE, "%s%d,0,0,", ASM_STABN_OP, BRAC);                  \
459       assemble_name (FILE, NAME);                                       \
460       putc ('-', FILE);                                                 \
461       if (current_function_func_begin_label != NULL_TREE)               \
462         flab = IDENTIFIER_POINTER (current_function_func_begin_label);  \
463       else                                                              \
464         {                                                               \
465           if (TARGET_64BIT)                                             \
466             putc ('.', FILE);                                           \
467           flab = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);  \
468         }                                                               \
469       assemble_name (FILE, flab);                                       \
470       putc ('\n', FILE);                                                \
471     }                                                                   \
472   while (0)
473
474 #define DBX_OUTPUT_LBRAC(FILE, NAME) DBX_OUTPUT_BRAC (FILE, NAME, N_LBRAC)
475 #define DBX_OUTPUT_RBRAC(FILE, NAME) DBX_OUTPUT_BRAC (FILE, NAME, N_RBRAC)
476
477 /* Another case where we want the dot name.  */
478 #define DBX_OUTPUT_NFUN(FILE, LSCOPE, DECL)                             \
479   do                                                                    \
480     {                                                                   \
481       fprintf (FILE, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);            \
482       assemble_name (FILE, LSCOPE);                                     \
483       putc ('-', FILE);                                                 \
484       if (TARGET_64BIT)                                                 \
485         putc ('.', FILE);                                               \
486       assemble_name (FILE, XSTR (XEXP (DECL_RTL (DECL), 0), 0));        \
487       putc ('\n', FILE);                                                \
488     }                                                                   \
489   while (0)
490
491 /* Select a format to encode pointers in exception handling data.  CODE
492    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
493    true if the symbol may be affected by dynamic relocations.  */
494 #undef  ASM_PREFERRED_EH_DATA_FORMAT
495 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
496   ((TARGET_64BIT || flag_pic || TARGET_RELOCATABLE)                     \
497    ? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel               \
498       | (TARGET_64BIT ? DW_EH_PE_udata8 : DW_EH_PE_sdata4))             \
499    : DW_EH_PE_absptr)
500
501 /* For backward compatibility, we must continue to use the AIX
502    structure return convention.  */
503 #undef DRAFT_V4_STRUCT_RET
504 #define DRAFT_V4_STRUCT_RET (!TARGET_64BIT)
505
506 /* Do code reading to identify a signal frame, and set the frame
507    state data appropriately.  See unwind-dw2.c for the structs.  */
508
509 #ifdef IN_LIBGCC2
510 #include <signal.h>
511 #include <sys/ucontext.h>
512
513 #ifdef __powerpc64__
514 enum { SIGNAL_FRAMESIZE = 128 };
515 #else
516 enum { SIGNAL_FRAMESIZE = 64 };
517 #endif
518 #endif
519
520 #ifdef __powerpc64__
521
522 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)               \
523   do {                                                                  \
524     unsigned char *pc_ = (CONTEXT)->ra;                                 \
525     struct sigcontext *sc_;                                             \
526     long new_cfa_;                                                      \
527     int i_;                                                             \
528                                                                         \
529     /* addi r1, r1, 128; li r0, 0x0077; sc  (sigreturn) */              \
530     /* addi r1, r1, 128; li r0, 0x00AC; sc  (rt_sigreturn) */           \
531     if (*(unsigned int *) (pc_+0) != 0x38210000 + SIGNAL_FRAMESIZE      \
532         || *(unsigned int *) (pc_+8) != 0x44000002)                     \
533       break;                                                            \
534     if (*(unsigned int *) (pc_+4) == 0x38000077)                        \
535       {                                                                 \
536         struct sigframe {                                               \
537           char gap[SIGNAL_FRAMESIZE];                                   \
538           struct sigcontext sigctx;                                     \
539         } *rt_ = (CONTEXT)->cfa;                                        \
540         sc_ = &rt_->sigctx;                                             \
541       }                                                                 \
542     else if (*(unsigned int *) (pc_+4) == 0x380000AC)                   \
543       {                                                                 \
544         struct rt_sigframe {                                            \
545           int tramp[6];                                                 \
546           struct siginfo *pinfo;                                        \
547           struct ucontext *puc;                                         \
548         } *rt_ = (struct rt_sigframe *) pc_;                            \
549         sc_ = &rt_->puc->uc_mcontext;                                   \
550       }                                                                 \
551     else                                                                \
552       break;                                                            \
553                                                                         \
554     new_cfa_ = sc_->regs->gpr[STACK_POINTER_REGNUM];                    \
555     (FS)->cfa_how = CFA_REG_OFFSET;                                     \
556     (FS)->cfa_reg = STACK_POINTER_REGNUM;                               \
557     (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;                \
558                                                                         \
559     for (i_ = 0; i_ < 32; i_++)                                         \
560       if (i_ != STACK_POINTER_REGNUM)                                   \
561         {                                                               \
562           (FS)->regs.reg[i_].how = REG_SAVED_OFFSET;                    \
563           (FS)->regs.reg[i_].loc.offset                                 \
564             = (long)&(sc_->regs->gpr[i_]) - new_cfa_;                   \
565         }                                                               \
566                                                                         \
567     (FS)->regs.reg[LINK_REGISTER_REGNUM].how = REG_SAVED_OFFSET;        \
568     (FS)->regs.reg[LINK_REGISTER_REGNUM].loc.offset                     \
569       = (long)&(sc_->regs->link) - new_cfa_;                            \
570                                                                         \
571     /* The unwinder expects the IP to point to the following insn,      \
572        whereas the kernel returns the address of the actual             \
573        faulting insn. We store NIP+4 in an unused register slot to      \
574        get the same result for multiple evaluation of the same signal   \
575        frame.  */                                                       \
576     sc_->regs->gpr[47] = sc_->regs->nip + 4;                            \
577     (FS)->regs.reg[CR0_REGNO].how = REG_SAVED_OFFSET;                   \
578     (FS)->regs.reg[CR0_REGNO].loc.offset                                \
579       = (long)&(sc_->regs->gpr[47]) - new_cfa_;                         \
580     (FS)->retaddr_column = CR0_REGNO;                                   \
581     goto SUCCESS;                                                       \
582   } while (0)
583
584 #else
585
586 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)               \
587   do {                                                                  \
588     unsigned char *pc_ = (CONTEXT)->ra;                                 \
589     struct sigcontext *sc_;                                             \
590     long new_cfa_;                                                      \
591     int i_;                                                             \
592                                                                         \
593     /* li r0, 0x7777; sc  (sigreturn old)  */                           \
594     /* li r0, 0x0077; sc  (sigreturn new)  */                           \
595     /* li r0, 0x6666; sc  (rt_sigreturn old)  */                        \
596     /* li r0, 0x00AC; sc  (rt_sigreturn new)  */                        \
597     if (*(unsigned int *) (pc_+4) != 0x44000002)                        \
598       break;                                                            \
599     if (*(unsigned int *) (pc_+0) == 0x38007777                         \
600         || *(unsigned int *) (pc_+0) == 0x38000077)                     \
601       {                                                                 \
602         struct sigframe {                                               \
603           char gap[SIGNAL_FRAMESIZE];                                   \
604           struct sigcontext sigctx;                                     \
605         } *rt_ = (CONTEXT)->cfa;                                        \
606         sc_ = &rt_->sigctx;                                             \
607       }                                                                 \
608     else if (*(unsigned int *) (pc_+0) == 0x38006666                    \
609              || *(unsigned int *) (pc_+0) == 0x380000AC)                \
610       {                                                                 \
611         struct rt_sigframe {                                            \
612           char gap[SIGNAL_FRAMESIZE];                                   \
613           unsigned long _unused[2];                                     \
614           struct siginfo *pinfo;                                        \
615           void *puc;                                                    \
616           struct siginfo info;                                          \
617           struct ucontext uc;                                           \
618         } *rt_ = (CONTEXT)->cfa;                                        \
619         sc_ = &rt_->uc.uc_mcontext;                                     \
620       }                                                                 \
621     else                                                                \
622       break;                                                            \
623                                                                         \
624     new_cfa_ = sc_->regs->gpr[STACK_POINTER_REGNUM];                    \
625     (FS)->cfa_how = CFA_REG_OFFSET;                                     \
626     (FS)->cfa_reg = STACK_POINTER_REGNUM;                               \
627     (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;                \
628                                                                         \
629     for (i_ = 0; i_ < 32; i_++)                                         \
630       if (i_ != STACK_POINTER_REGNUM)                                   \
631         {                                                               \
632           (FS)->regs.reg[i_].how = REG_SAVED_OFFSET;                    \
633           (FS)->regs.reg[i_].loc.offset                                 \
634             = (long)&(sc_->regs->gpr[i_]) - new_cfa_;                   \
635         }                                                               \
636                                                                         \
637     (FS)->regs.reg[LINK_REGISTER_REGNUM].how = REG_SAVED_OFFSET;        \
638     (FS)->regs.reg[LINK_REGISTER_REGNUM].loc.offset                     \
639       = (long)&(sc_->regs->link) - new_cfa_;                            \
640                                                                         \
641     /* The unwinder expects the IP to point to the following insn,      \
642        whereas the kernel returns the address of the actual             \
643        faulting insn. We store NIP+4 in an unused register slot to      \
644        get the same result for multiple evaluation of the same signal   \
645        frame.  */                                                       \
646     sc_->regs->gpr[47] = sc_->regs->nip + 4;                            \
647     (FS)->regs.reg[CR0_REGNO].how = REG_SAVED_OFFSET;                   \
648     (FS)->regs.reg[CR0_REGNO].loc.offset                                \
649       = (long)&(sc_->regs->gpr[47]) - new_cfa_;                         \
650     (FS)->retaddr_column = CR0_REGNO;                                   \
651     goto SUCCESS;                                                       \
652   } while (0)
653
654 #endif