OSDN Git Service

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