OSDN Git Service

* defaults.h (ASM_OUTPUT_TYPE_DIRECTIVE, ASM_OUTPUT_SIZE_DIRECTIVE,
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / m68kv4.h
1 /* Target definitions for GNU compiler for mc680x0 running System V.4
2    Copyright (C) 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000
3    Free Software Foundation, Inc.
4    Contributed by Ron Guilmette (rfg@monkeys.com) and
5    Fred Fish (fnf@cygnus.com).
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.  */
23
24 /* Use SGS_* macros to control compilation in m68k.md */
25
26 #define SGS_SWITCH_TABLES       /* Different switch table handling */
27
28 /* TODO: convert includes to ${tm_file} list in config.gcc.  */
29 #include "m68k/sgs.h"           /* The m68k/SVR4 assembler is SGS based */
30
31 #include "dbxelf.h"
32 #include "elfos.h"
33 #include "svr4.h"               /* Pick up the generic SVR4 macros */
34
35 /* See m68k.h.  7 means 68020 with 68881.  */
36
37 #ifndef TARGET_DEFAULT
38 #define TARGET_DEFAULT (MASK_BITFIELD|MASK_68881|MASK_68020)
39 #endif
40
41 /*  Override the definition of NO_DOLLAR_IN_LABEL in svr4.h, for special
42     g++ assembler names.  When this is defined, g++ uses embedded '.'
43     characters and some m68k assemblers have problems with this.  The
44     chances are much greater that any particular assembler will permit
45     embedded '$' characters.  */
46
47 #undef NO_DOLLAR_IN_LABEL
48
49 /* Define PCC_STATIC_STRUCT_RETURN if the convention on the target machine
50    is to use the nonreentrant technique for returning structure and union
51    values, as commonly implemented by the AT&T Portable C Compiler (PCC).
52    When defined, the gcc option -fpcc-struct-return can be used to cause
53    this form to be generated.  When undefined, the option does nothing.
54    For m68k SVR4, the convention is to use a reentrant technique compatible
55    with the gcc default, so override the definition of this macro in m68k.h */
56
57 #undef PCC_STATIC_STRUCT_RETURN
58
59 /* Provide a set of pre-definitions and pre-assertions appropriate for
60    the m68k running svr4.  __svr4__ is our extension.  */
61
62 #define CPP_PREDEFINES \
63   "-Dm68k -Dunix -D__svr4__ -D__motorola__ \
64  -Asystem=unix -Asystem=svr4 -Acpu=m68k -Amachine=m68k"
65
66 /* Test to see if the target includes a 68881 by default, and use CPP_SPEC
67    to control whether or not __HAVE_68881__ is defined by default or not.
68    If a 68881 is the default, gcc will use inline 68881 instructions, by
69    predefining __HAVE_68881__, unless -msoft-float is specified.
70    If a 68881 is not the default, gcc will only define __HAVE_68881__ if
71    -m68881 is specified.  */
72
73 #if TARGET_DEFAULT & MASK_68881
74 #define CPP_SPEC "%{!msoft-float:-D__HAVE_68881__}"
75 #else
76 #define CPP_SPEC "%{m68881:-D__HAVE_68881__}"
77 #endif
78
79 /* Output assembler code to FILE to increment profiler label # LABELNO
80    for profiling a function entry.  We override the definition in m68k.h
81    and match the way the native m68k/SVR4 compiler does profiling, with the
82    address of the profile counter in a1, not a0, and using bsr rather
83    than jsr.  */
84
85 #undef FUNCTION_PROFILER
86 #define FUNCTION_PROFILER(FILE, LABELNO)                                \
87   asm_fprintf ((FILE), "\tlea.l\t(%LLP%d,%Rpc),%Ra1\n\tbsr\t_mcount\n", \
88                (LABELNO))
89
90 /* Local common symbols are declared to the assembler with ".lcomm" rather
91    than ".bss", so override the definition in svr4.h */
92 /* ??? svr4.h no longer defines this, and this is only used by m68k/amix.h.  */
93
94 #undef BSS_ASM_OP
95 #define BSS_ASM_OP      "\t.lcomm\t"
96
97 /* Register in which address to store a structure value is passed to a
98    function.  The default in m68k.h is a1.  For m68k/SVR4 it is a0.  */
99
100 #undef STRUCT_VALUE_REGNUM
101 #define STRUCT_VALUE_REGNUM 8
102
103 /* Register in which static-chain is passed to a function.  The
104    default in m68k.h is a0, but that is already the struct value
105    regnum.  Make it a1 instead.  */
106
107 #undef STATIC_CHAIN_REGNUM
108 #define STATIC_CHAIN_REGNUM 9
109
110 #define ASM_COMMENT_START "#"
111
112 /* Define how the m68k registers should be numbered for Dwarf output.
113    The numbering provided here should be compatible with the native
114    SVR4 SDB debugger in the m68k/SVR4 reference port, where d0-d7
115    are 0-7, a0-a8 are 8-15, and fp0-fp7 are 16-23.  */
116
117 #define DBX_REGISTER_NUMBER(REGNO) (REGNO)
118
119 /* The ASM_OUTPUT_SKIP macro is first defined in m68k.h, using ".skip".
120    It is then overridden by m68k/sgs.h to use ".space", and again by svr4.h
121    to use ".zero".  The m68k/SVR4 assembler uses ".space", so repeat the
122    definition from m68k/sgs.h here.  Note that ASM_NO_SKIP_IN_TEXT is
123    defined in m68k/sgs.h, so we don't have to repeat it here.  */
124
125 #undef ASM_OUTPUT_SKIP
126 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
127   fprintf (FILE, "%s%u\n", SPACE_ASM_OP, (SIZE))
128
129 /* 1 if N is a possible register number for a function value.
130    For m68k/SVR4 allow d0, a0, or fp0 as return registers, for integral,
131    pointer, or floating types, respectively. Reject fp0 if not using a
132    68881 coprocessor.  */
133
134 #undef FUNCTION_VALUE_REGNO_P
135 #define FUNCTION_VALUE_REGNO_P(N) \
136   ((N) == 0 || (N) == 8 || (TARGET_68881 && (N) == 16))
137
138 /* Define this to be true when FUNCTION_VALUE_REGNO_P is true for
139    more than one register.  */
140
141 #undef NEEDS_UNTYPED_CALL
142 #define NEEDS_UNTYPED_CALL 1
143
144 /* Define how to generate (in the callee) the output value of a function
145    and how to find (in the caller) the value returned by a function.  VALTYPE
146    is the data type of the value (as a tree).  If the precise function being
147    called is known, FUNC is its FUNCTION_DECL; otherwise, FUNC is 0.
148    For m68k/SVR4 generate the result in d0, a0, or fp0 as appropriate.  */
149    
150 #undef FUNCTION_VALUE
151 #define FUNCTION_VALUE(VALTYPE, FUNC)                                   \
152   (TREE_CODE (VALTYPE) == REAL_TYPE && TARGET_68881                     \
153    ? gen_rtx_REG (TYPE_MODE (VALTYPE), 16)                              \
154    : (POINTER_TYPE_P (VALTYPE)                                          \
155       ? gen_rtx_REG (TYPE_MODE (VALTYPE), 8)                            \
156       : gen_rtx_REG (TYPE_MODE (VALTYPE), 0)))
157
158 /* For compatibility with the large body of existing code which does not
159    always properly declare external functions returning pointer types, the
160    m68k/SVR4 convention is to copy the value returned for pointer functions
161    from a0 to d0 in the function epilogue, so that callers that have
162    neglected to properly declare the callee can still find the correct return
163    value.  */
164
165 #define FUNCTION_EXTRA_EPILOGUE(FILE, SIZE)                             \
166 do {                                                                    \
167   if (current_function_returns_pointer                                  \
168       && ! find_equiv_reg (0, get_last_insn (), 0, 0, 0, 8, Pmode))     \
169     asm_fprintf (FILE, "\tmov.l %Ra0,%Rd0\n");                          \
170 } while (0);
171
172 /* Define how to find the value returned by a library function assuming the
173    value has mode MODE.
174    For m68k/SVR4 look for integer values in d0, pointer values in d0
175    (returned in both d0 and a0), and floating values in fp0.  */
176
177 #undef LIBCALL_VALUE
178 #define LIBCALL_VALUE(MODE)                                             \
179   ((((MODE) == SFmode || (MODE) == DFmode || (MODE) == XFmode)          \
180     && TARGET_68881)                                                    \
181    ? gen_rtx_REG ((MODE), 16)                                           \
182    : gen_rtx_REG ((MODE), 0))
183
184 /* Boundary (in *bits*) on which stack pointer should be aligned.
185    The m68k/SVR4 convention is to keep the stack pointer longword aligned.  */
186  
187 #undef STACK_BOUNDARY
188 #define STACK_BOUNDARY 32
189
190 /* Alignment of field after `int : 0' in a structure.
191    For m68k/SVR4, this is the next longword boundary.  */
192
193 #undef EMPTY_FIELD_BOUNDARY
194 #define EMPTY_FIELD_BOUNDARY 32
195
196 /* No data type wants to be aligned rounder than this.
197    For m68k/SVR4, some types (doubles for example) are aligned on 8 byte
198    boundaries */
199         
200 #undef BIGGEST_ALIGNMENT
201 #define BIGGEST_ALIGNMENT 64
202
203 /* SVR4 m68k assembler is bitching on the `comm i,1,1' which asks for 
204    1 byte alignment. Don't generate alignment for COMMON seems to be
205    safer until we the assembler is fixed.  */
206 #undef ASM_OUTPUT_ALIGNED_COMMON
207 /* Same problem with this one.  */
208 #undef ASM_OUTPUT_ALIGNED_LOCAL
209
210 /* The `string' directive on m68k svr4 does not handle string with
211    escape char (ie., `\') right. Use normal way to output ASCII bytes
212    seems to be safer.  */
213 #undef ASM_OUTPUT_ASCII
214 #define ASM_OUTPUT_ASCII(FILE,PTR,LEN)                          \
215 do {                                                            \
216   register size_t sp = 0, limit = (LEN);                        \
217   fputs (integer_asm_op (1, TRUE), (FILE));                     \
218   do {                                                          \
219     int ch = (PTR)[sp];                                         \
220     if (ch > ' ' && ! (ch & 0x80) && ch != '\\')                \
221       {                                                         \
222         fprintf ((FILE), "'%c", ch);                            \
223       }                                                         \
224     else                                                        \
225       {                                                         \
226         fprintf ((FILE), "0x%x", ch);                           \
227       }                                                         \
228     if (++sp < limit)                                           \
229       {                                                         \
230         if ((sp % 10) == 0)                                     \
231           {                                                     \
232             fprintf ((FILE), "\n%s", integer_asm_op (1, TRUE)); \
233           }                                                     \
234         else                                                    \
235           {                                                     \
236             putc (',', (FILE));                                 \
237           }                                                     \
238       }                                                         \
239   } while (sp < limit);                                         \
240   putc ('\n', (FILE));                                          \
241 } while (0)
242
243 /* SVR4 m68k assembler is bitching on the syntax `2.b'.
244    So use the "LLDnnn-LLnnn" format.  Define LLDnnn after the table.  */
245
246 #undef ASM_OUTPUT_CASE_END
247 #define ASM_OUTPUT_CASE_END(FILE,NUM,TABLE)                             \
248 do {                                                                    \
249   if (switch_table_difference_label_flag)                               \
250     asm_fprintf ((FILE), "%s%LLD%d,%LL%d\n", SET_ASM_OP, (NUM), (NUM)); \
251   switch_table_difference_label_flag = 0;                               \
252 } while (0)
253
254 int switch_table_difference_label_flag;
255
256 #undef ASM_OUTPUT_COMMON
257 #undef ASM_OUTPUT_LOCAL
258 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
259 ( fputs (".comm ", (FILE)),                     \
260   assemble_name ((FILE), (NAME)),               \
261   fprintf ((FILE), ",%u\n", (SIZE)))
262
263 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
264 ( fputs (".lcomm ", (FILE)),                    \
265   assemble_name ((FILE), (NAME)),               \
266   fprintf ((FILE), ",%u\n", (SIZE)))
267
268 /* Override the definition in svr4.h. In m68k svr4, using swbeg is the 
269    standard way to do switch table.  */
270 #undef ASM_OUTPUT_BEFORE_CASE_LABEL
271 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE,PREFIX,NUM,TABLE)             \
272   fprintf ((FILE), "%s&%d\n", SWBEG_ASM_OP, XVECLEN (PATTERN (TABLE), 1));
273
274 /* In m68k svr4, a symbol_ref rtx can be a valid PIC operand if it is an
275    operand of a function call.  */
276 #undef LEGITIMATE_PIC_OPERAND_P
277 #define LEGITIMATE_PIC_OPERAND_P(X) \
278   ((! symbolic_operand (X, VOIDmode) \
279     && ! (GET_CODE (X) == CONST_DOUBLE && mem_for_const_double (X) != 0 \
280           && GET_CODE (mem_for_const_double (X)) == MEM                 \
281           && symbolic_operand (XEXP (mem_for_const_double (X), 0),      \
282                                VOIDmode)))                              \
283    || (GET_CODE (X) == SYMBOL_REF && SYMBOL_REF_FLAG (X))               \
284    || PCREL_GENERAL_OPERAND_OK)
285
286 /* Turn off function cse if we are doing PIC. We always want function call
287    to be done as `bsr foo@PLTPC', so it will force the assembler to create 
288    the PLT entry for `foo'. Doing function cse will cause the address of `foo'
289    to be loaded into a register, which is exactly what we want to avoid when
290    we are doing PIC on svr4 m68k.  */
291 #undef OVERRIDE_OPTIONS
292 #define OVERRIDE_OPTIONS                \
293 {                                       \
294   if (flag_pic) flag_no_function_cse = 1; \
295   if (! TARGET_68020 && flag_pic == 2)  \
296     error("-fPIC is not currently supported on the 68000 or 68010\n");  \
297 }
298
299 /* Output assembler code for a block containing the constant parts
300    of a trampoline, leaving space for the variable parts.  */
301
302 /* On m68k svr4, the trampoline is different from the generic version
303    in that we use a1 as the static call chain.  */
304
305 #undef TRAMPOLINE_TEMPLATE
306 #define TRAMPOLINE_TEMPLATE(FILE)                                       \
307 {                                                                       \
308   assemble_aligned_integer (2, GEN_INT (0x227a));                       \
309   assemble_aligned_integer (2, GEN_INT (8));                            \
310   assemble_aligned_integer (2, GEN_INT (0x2f3a));                       \
311   assemble_aligned_integer (2, GEN_INT (8));                            \
312   assemble_aligned_integer (2, GEN_INT (0x4e75));                       \
313   assemble_aligned_integer (4, const0_rtx);                             \
314   assemble_aligned_integer (4, const0_rtx);                             \
315 }
316
317 /* Redefine since we are using a different trampoline */
318 #undef TRAMPOLINE_SIZE
319 #define TRAMPOLINE_SIZE 18
320
321 /* Emit RTL insns to initialize the variable parts of a trampoline.
322    FNADDR is an RTX for the address of the function's pure code.
323    CXT is an RTX for the static chain value for the function.  */
324
325 #undef INITIALIZE_TRAMPOLINE
326 #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)                       \
327 {                                                                       \
328   emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 10)), CXT); \
329   emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 14)), FNADDR); \
330 }