OSDN Git Service

Update copyrights.
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / sgs.h
1 /* Definitions of target machine for GNU compiler for m68k targets using
2    assemblers derived from AT&T "SGS" releases.
3    Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.
4    Written by Fred Fish (fnf@cygnus.com)
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 /* Control assembler-syntax conditionals in m68k.md and conditionals in
24    m68k.h.  Note that some systems may also require SGS_SWAP_W and/or
25    SGS_SWITCH_TABLES to be defined as well.  */
26
27 #define MOTOROLA                /* Use Motorola syntax rather than "MIT" */
28 #define SGS                     /* Uses SGS assembler */
29 #define SGS_CMP_ORDER           /* Takes cmp operands in reverse order */
30
31 #include "m68k/m68k.h"
32
33 /* SGS specific assembler pseudo ops. */
34
35 #define BYTE_ASM_OP             ".byte"
36 #define WORD_ASM_OP             ".short"
37 #define LONG_ASM_OP             ".long"
38 #define SPACE_ASM_OP            ".space"
39 #define ALIGN_ASM_OP            ".align"
40 #undef GLOBAL_ASM_OP
41 #define GLOBAL_ASM_OP           ".global"
42 #define SWBEG_ASM_OP            ".swbeg"
43 #define SET_ASM_OP              ".set"
44
45 #define UNALIGNED_SHORT_ASM_OP  ".short"        /* Used in dwarfout.c */
46 #define UNALIGNED_INT_ASM_OP    ".long"         /* Used in dwarfout.c */
47
48 #define ASM_PN_FORMAT           "%s_%d"         /* Format for private names */
49
50 /* Here are four prefixes that are used by asm_fprintf to
51    facilitate customization for alternate assembler syntaxes.
52    Machines with no likelihood of an alternate syntax need not
53    define these and need not use asm_fprintf.  */
54
55 /* The prefix for register names.  Note that REGISTER_NAMES
56    is supposed to include this prefix. Also note that this is NOT an
57    fprintf format string, it is a literal string */
58
59 #undef REGISTER_PREFIX
60 #define REGISTER_PREFIX "%"
61
62 /* The prefix for local (compiler generated) labels.
63    These labels will not appear in the symbol table. */
64
65 #undef LOCAL_LABEL_PREFIX
66 #define LOCAL_LABEL_PREFIX "."
67
68 /* The prefix to add to user-visible assembler symbols. */
69
70 #undef USER_LABEL_PREFIX
71 #define USER_LABEL_PREFIX ""
72
73 /* The prefix for immediate operands.  */
74
75 #undef IMMEDIATE_PREFIX
76 #define IMMEDIATE_PREFIX "&"
77
78 /* How to refer to registers in assembler output.
79    This sequence is indexed by compiler's hard-register-number.
80    Motorola format uses different register names than defined in m68k.h.
81    We also take this chance to convert 'a6' to 'fp' */
82
83 #undef REGISTER_NAMES
84
85 #ifndef SUPPORT_SUN_FPA
86
87 #define REGISTER_NAMES \
88 {"%d0",   "%d1",   "%d2",   "%d3",   "%d4",   "%d5",   "%d6",   "%d7",       \
89  "%a0",   "%a1",   "%a2",   "%a3",   "%a4",   "%a5",   "%fp",   "%sp",       \
90  "%fp0",  "%fp1",  "%fp2",  "%fp3",  "%fp4",  "%fp5",  "%fp6",  "%fp7" }
91
92 #else /* SUPPORTED_SUN_FPA */
93
94 #define REGISTER_NAMES \
95 {"%d0",   "%d1",   "%d2",   "%d3",   "%d4",   "%d5",   "%d6",   "%d7",       \
96  "%a0",   "%a1",   "%a2",   "%a3",   "%a4",   "%a5",   "%fp",   "%sp",       \
97  "%fp0",  "%fp1",  "%fp2",  "%fp3",  "%fp4",  "%fp5",  "%fp6",  "%fp7",      \
98  "%fpa0", "%fpa1", "%fpa2", "%fpa3", "%fpa4", "%fpa5", "%fpa6","%fpa7",      \
99  "%fpa8", "%fpa9", "%fpa10","%fpa11","%fpa12","%fpa13","%fpa14","%fpa15",    \
100  "%fpa16","%fpa17","%fpa18","%fpa19","%fpa20","%fpa21","%fpa22","%fpa23",    \
101  "%fpa24","%fpa25","%fpa26","%fpa27","%fpa28","%fpa29","%fpa30","%fpa31" }
102
103 #endif /* defined SUPPORT_SUN_FPA */
104
105 /* When using an SGS assembler, modify the name of the artificial label which
106    identifies this file as having been compiled with gcc, and the macro that
107    emits such a label in the assembly output, to use '%' rather than '.' */
108
109 #define ASM_IDENTIFY_GCC(FILE)                          \
110  { fprintf ((FILE), "%s:\n", "gcc2_compiled%"); }
111
112 /* This is how to output an assembler line defining an `int' constant.  */
113 /* The SGS assembler doesn't understand ".word". */
114
115 #undef ASM_OUTPUT_SHORT
116 #define ASM_OUTPUT_SHORT(FILE,VALUE)                    \
117 ( fprintf ((FILE), "\t%s ", WORD_ASM_OP),               \
118   output_addr_const ((FILE), (VALUE)),                  \
119   fprintf ((FILE), "\n"))
120
121 #undef ASM_OUTPUT_LONG_DOUBLE
122 #define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE)                      \
123 do { long l[3];                                                 \
124      REAL_VALUE_TO_TARGET_LONG_DOUBLE (VALUE, l);               \
125      fprintf ((FILE), "\t%s 0x%x,0x%x,0x%x\n", LONG_ASM_OP,     \
126              l[0], l[1], l[2]);                                 \
127    } while (0)
128
129 /* This is how to output an assembler line defining a `double' constant.  */
130
131 #undef ASM_OUTPUT_DOUBLE
132 #define ASM_OUTPUT_DOUBLE(FILE,VALUE)                   \
133 do { long l[2];                                         \
134      REAL_VALUE_TO_TARGET_DOUBLE (VALUE, l);            \
135      fprintf ((FILE), "\t%s 0x%x,0x%x\n", LONG_ASM_OP,  \
136               l[0], l[1]);                              \
137    } while (0)
138
139 /* This is how to output an assembler line defining a `float' constant.  */
140
141 #undef ASM_OUTPUT_FLOAT
142 #define ASM_OUTPUT_FLOAT(FILE,VALUE)                    \
143 do { long l;                                            \
144      REAL_VALUE_TO_TARGET_SINGLE (VALUE, l);            \
145      fprintf ((FILE), "\t%s 0x%x\n", LONG_ASM_OP, l);   \
146    } while (0)
147
148 /* This is how to output an assembler line that says to advance the
149    location counter to a multiple of 2**LOG bytes.  */
150
151 #undef ASM_OUTPUT_ALIGN
152 #define ASM_OUTPUT_ALIGN(FILE,LOG)                              \
153   if ((LOG) > 0)                                                \
154     fprintf ((FILE), "\t%s \t%u\n", ALIGN_ASM_OP, 1 << (LOG));  \
155   else if ((LOG) > 31)                                          \
156     abort ();
157
158 /* The routine used to output null terminated string literals.  We cannot
159    use the ".string" pseudo op, because it silently truncates strings to
160    1023 bytes.  There is no "partial string op" which works like ".string"
161    but doesn't append a null byte, so we can't chop the input string up
162    into small pieces and use that.  Our only remaining alternative is to
163    output the string one byte at a time. */
164
165 #define ASM_OUTPUT_ASCII(FILE,PTR,LEN)                          \
166 do {                                                            \
167   register int sp = 0, lp = 0, ch;                              \
168   fprintf ((FILE), "\t%s ", BYTE_ASM_OP);                       \
169   do {                                                          \
170     ch = (PTR)[sp];                                             \
171     if (ch > ' ' && ! (ch & 0x80) && ch != '\\')                \
172       {                                                         \
173         fprintf ((FILE), "'%c", ch);                            \
174       }                                                         \
175     else                                                        \
176       {                                                         \
177         fprintf ((FILE), "0x%x", ch);                           \
178       }                                                         \
179     if (++sp < (LEN))                                           \
180       {                                                         \
181         if ((sp % 10) == 0)                                     \
182           {                                                     \
183             fprintf ((FILE), "\n\t%s ", BYTE_ASM_OP);           \
184           }                                                     \
185         else                                                    \
186           {                                                     \
187             putc (',', (FILE));                                 \
188           }                                                     \
189       }                                                         \
190   } while (sp < (LEN));                                         \
191   putc ('\n', (FILE));                                          \
192 } while (0)
193
194
195 /* SGS based assemblers don't understand #NO_APP and #APP, so just don't
196    bother emitting them. */
197
198 #undef ASM_APP_ON
199 #define ASM_APP_ON ""
200
201 #undef ASM_APP_OFF
202 #define ASM_APP_OFF ""
203
204 /* When using SGS derived assemblers, change the "MIT" or "MOTOROLA"
205    to "SGS/AT&T"  */
206
207 #undef TARGET_VERSION
208 #define TARGET_VERSION fprintf (stderr, " (68k, SGS/AT&T syntax)");
209
210 /* Use proper assembler syntax for these macros.  */
211 #undef ASM_OUTPUT_REG_PUSH
212 #define ASM_OUTPUT_REG_PUSH(FILE,REGNO)  \
213   asm_fprintf (FILE, "\t%Omove.l %s,-(%Rsp)\n", reg_names[REGNO])
214
215 #undef ASM_OUTPUT_REG_POP
216 #define ASM_OUTPUT_REG_POP(FILE,REGNO)  \
217   asm_fprintf (FILE, "\t%Omove.l (%Rsp)+,%s\n", reg_names[REGNO])
218
219 #undef ASM_OUTPUT_FLOAT_OPERAND
220 #define ASM_OUTPUT_FLOAT_OPERAND(CODE,FILE,VALUE)       \
221   do { long l;                                          \
222        REAL_VALUE_TO_TARGET_SINGLE (VALUE, l);          \
223        asm_fprintf ((FILE), "%I0x%x", l);               \
224      } while (0)
225   
226 #undef ASM_OUTPUT_DOUBLE_OPERAND
227 #define ASM_OUTPUT_DOUBLE_OPERAND(FILE,VALUE)           \
228   do { long l[2];                                       \
229        REAL_VALUE_TO_TARGET_DOUBLE (VALUE, l);          \
230        asm_fprintf ((FILE), "%I0x%x%08x", l[0], l[1]);  \
231      } while (0)
232
233 /* How to output a block of SIZE zero bytes.  Note that the `space' pseudo,
234    when used in the text segment, causes SGS assemblers to output nop insns
235    rather than 0s, so we set ASM_NO_SKIP_IN_TEXT to prevent this. */
236
237 #define ASM_NO_SKIP_IN_TEXT 1
238
239 #undef ASM_OUTPUT_SKIP
240 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
241   fprintf (FILE, "\t%s %u\n", SPACE_ASM_OP, (SIZE))
242 \f
243 /* Translate Motorola opcodes such as `jbeq' into SGS opcodes such
244    as `beq.w'.
245    Delete the `e' in `move...' and `fmove'.
246    Change `ftst' to `ftest'.
247    Change `fbne' to `fbneq'
248    Change `fsne' to `fsneq'
249    Change `divsl' to `tdivs' (32/32 -> 32r:32q)
250    Change `divul' to `tdivu' (32/32 -> 32r:32q)
251    Optionally change swap to swap.w.
252    */
253
254 #ifdef SGS_SWAP_W
255 #define ASM_OUTPUT_OPCODE(FILE, PTR)                    \
256 {                                                       \
257   extern int flag_pic;                                  \
258   if (!strncmp ((PTR), "jbsr", 4))                      \
259     { if (flag_pic)                                     \
260         fprintf ((FILE), "bsr");                        \
261       else                                              \
262         fprintf ((FILE), "jsr");                        \
263     (PTR) += 4; }                                       \
264   else if ((PTR)[0] == 'j' && (PTR)[1] == 'b')          \
265     { ++(PTR);                                          \
266       while (*(PTR) != ' ')                             \
267         { putc (*(PTR), (FILE)); ++(PTR); }             \
268       fprintf ((FILE), ".w"); }                         \
269   else if ((PTR)[0] == 's')                             \
270     {                                                   \
271       if (!strncmp ((PTR), "swap", 4))                  \
272         { fprintf ((FILE), "swap.w"); (PTR) += 4; }     \
273     }                                                   \
274 /* FMOVE ==> FMOV, (and F%& F%$ translations) */        \
275   else if ((PTR)[0] == 'f')                             \
276     {                                                   \
277       if (!strncmp ((PTR), "fmove", 5))                 \
278         { fprintf ((FILE), "fmov"); (PTR) += 5; }       \
279       else if (!strncmp ((PTR), "ftst", 4))             \
280         { fprintf ((FILE), "ftest"); (PTR) += 4; }      \
281       else if (!strncmp ((PTR), "fbne", 4))             \
282         { fprintf ((FILE), "fbneq"); (PTR) += 4; }      \
283       else if (!strncmp ((PTR), "fsne", 4))             \
284         { fprintf ((FILE), "fsneq"); (PTR) += 4; }      \
285       else if (!strncmp ((PTR), "f%$move", 7))          \
286         { (PTR) += 7;                                   \
287           if (TARGET_68040_ONLY)                        \
288             fprintf ((FILE), "fsmov");                  \
289           else fprintf ((FILE), "fmov"); }              \
290       else if (!strncmp ((PTR), "f%&move", 7))          \
291         { (PTR) += 7;                                   \
292           if (TARGET_68040_ONLY)                        \
293             fprintf ((FILE), "fdmov");                  \
294           else fprintf ((FILE), "fmov"); }              \
295     }                                                   \
296 /* MOVE, MOVEA, MOVEQ, MOVEC ==> MOV    */              \
297   else if ((PTR)[0] == 'm' && (PTR)[1] == 'o'           \
298            && (PTR)[2] == 'v' && (PTR)[3] == 'e')       \
299     { fprintf ((FILE), "mov"); (PTR) += 4;              \
300        if ((PTR)[0] == 'q' || (PTR)[0] == 'a'           \
301            || (PTR)[0] == 'c') (PTR)++; }               \
302 /* SUB, SUBQ, SUBA, SUBI ==> SUB */                     \
303   else if ((PTR)[0] == 's' && (PTR)[1] == 'u'           \
304            && (PTR)[2] == 'b')                          \
305     { fprintf ((FILE), "sub"); (PTR) += 3;              \
306        if ((PTR)[0] == 'q' || (PTR)[0] == 'i'           \
307            || (PTR)[0] == 'a') (PTR)++; }               \
308 /* CMP, CMPA, CMPI, CMPM ==> CMP        */              \
309   else if ((PTR)[0] == 'c' && (PTR)[1] == 'm'           \
310            && (PTR)[2] == 'p')                          \
311     { fprintf ((FILE), "cmp"); (PTR) += 3;              \
312        if ((PTR)[0] == 'a' || (PTR)[0] == 'i'           \
313            || (PTR)[0] == 'm') (PTR)++; }               \
314 /* DIVSL ==> TDIVS */                                   \
315   else if ((PTR)[0] == 'd' && (PTR)[1] == 'i'           \
316            && (PTR)[2] == 'v' && (PTR)[3] == 's'        \
317            && (PTR)[4] == 'l')                          \
318     { fprintf ((FILE), "tdivs"); (PTR) += 5; }          \
319 /* DIVUL ==> TDIVU */                                   \
320   else if ((PTR)[0] == 'd' && (PTR)[1] == 'i'           \
321            && (PTR)[2] == 'v' && (PTR)[3] == 'u'        \
322            && (PTR)[4] == 'l')                          \
323     { fprintf ((FILE), "tdivu"); (PTR) += 5; }          \
324 }
325
326 #else /* not SGS_SWAP_W */
327
328 #define ASM_OUTPUT_OPCODE(FILE, PTR)                    \
329 {                                                       \
330   extern int flag_pic;                                  \
331   if (!strncmp ((PTR), "jbsr", 4))                      \
332     { if (flag_pic)                                     \
333         fprintf ((FILE), "bsr");                        \
334       else                                              \
335         fprintf ((FILE), "jsr");                        \
336     (PTR) += 4; }                                       \
337   else if ((PTR)[0] == 'j' && (PTR)[1] == 'b')          \
338     { ++(PTR);                                          \
339       while (*(PTR) != ' ')                             \
340         { putc (*(PTR), (FILE)); ++(PTR); }             \
341       fprintf ((FILE), ".w"); }                         \
342 /* FMOVE ==> FMOV, (and F%& F%$ translations) */        \
343   else if ((PTR)[0] == 'f')                             \
344     {                                                   \
345       if (!strncmp ((PTR), "fmove", 5))                 \
346         { fprintf ((FILE), "fmov"); (PTR) += 5; }       \
347       else if (!strncmp ((PTR), "ftst", 4))             \
348         { fprintf ((FILE), "ftest"); (PTR) += 4; }      \
349       else if (!strncmp ((PTR), "fbne", 4))             \
350         { fprintf ((FILE), "fbneq"); (PTR) += 4; }      \
351       else if (!strncmp ((PTR), "fsne", 4))             \
352         { fprintf ((FILE), "fsneq"); (PTR) += 4; }      \
353       else if (!strncmp ((PTR), "f%$move", 7))          \
354         { (PTR) += 7;                                   \
355           if (TARGET_68040_ONLY)                        \
356             fprintf ((FILE), "fsmov");                  \
357           else fprintf ((FILE), "fmov"); }              \
358       else if (!strncmp ((PTR), "f%&move", 7))          \
359         { (PTR) += 7;                                   \
360           if (TARGET_68040_ONLY)                        \
361             fprintf ((FILE), "fdmov");                  \
362           else fprintf ((FILE), "fmov"); }              \
363     }                                                   \
364 /* MOVE, MOVEA, MOVEQ, MOVEC ==> MOV    */              \
365   else if ((PTR)[0] == 'm' && (PTR)[1] == 'o'           \
366            && (PTR)[2] == 'v' && (PTR)[3] == 'e')       \
367     { fprintf ((FILE), "mov"); (PTR) += 4;              \
368        if ((PTR)[0] == 'q' || (PTR)[0] == 'a'           \
369            || (PTR)[0] == 'c') (PTR)++; }               \
370 /* SUB, SUBQ, SUBA, SUBI ==> SUB */                     \
371   else if ((PTR)[0] == 's' && (PTR)[1] == 'u'           \
372            && (PTR)[2] == 'b')                          \
373     { fprintf ((FILE), "sub"); (PTR) += 3;              \
374        if ((PTR)[0] == 'q' || (PTR)[0] == 'i'           \
375            || (PTR)[0] == 'a') (PTR)++; }               \
376 /* CMP, CMPA, CMPI, CMPM ==> CMP        */              \
377   else if ((PTR)[0] == 'c' && (PTR)[1] == 'm'           \
378            && (PTR)[2] == 'p')                          \
379     { fprintf ((FILE), "cmp"); (PTR) += 3;              \
380        if ((PTR)[0] == 'a' || (PTR)[0] == 'i'           \
381            || (PTR)[0] == 'm') (PTR)++; }               \
382 /* DIVSL ==> TDIVS */                                   \
383   else if ((PTR)[0] == 'd' && (PTR)[1] == 'i'           \
384            && (PTR)[2] == 'v' && (PTR)[3] == 's'        \
385            && (PTR)[4] == 'l')                          \
386     { fprintf ((FILE), "tdivs"); (PTR) += 5; }          \
387 /* DIVUL ==> TDIVU */                                   \
388   else if ((PTR)[0] == 'd' && (PTR)[1] == 'i'           \
389            && (PTR)[2] == 'v' && (PTR)[3] == 'u'        \
390            && (PTR)[4] == 'l')                          \
391     { fprintf ((FILE), "tdivu"); (PTR) += 5; }          \
392 }
393
394 #endif /* not SGS_SWAP_W */
395 \f
396 /* This macro outputs the label at the start of a switch table.  The
397    ".swbeg <N>" is an assembler directive that causes the switch table
398    size to be inserted into the object code so that disassemblers, for
399    example, can identify that it is the start of a switch table. */
400
401 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE,PREFIX,NUM,TABLE)             \
402   fprintf ((FILE), "\t%s &%d\n", SWBEG_ASM_OP, XVECLEN (PATTERN (TABLE), 1));
403
404 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLE)                    \
405   do {                                                                  \
406     ASM_OUTPUT_BEFORE_CASE_LABEL((FILE),(PREFIX),(NUM),(TABLE));        \
407     ASM_OUTPUT_INTERNAL_LABEL((FILE),(PREFIX),(NUM));                   \
408   } while (0)
409
410 /* At end of a switch table, define LDnnn iff the symbol LInnn was defined.
411    Some SGS assemblers have a bug such that "Lnnn-LInnn-2.b(pc,d0.l*2)"
412    fails to assemble.  Luckily "LDnnn(pc,d0.l*2)" produces the results
413    we want.  This difference can be accommodated by making the assembler
414    define such "LDnnn" to be either "Lnnn-LInnn-2.b", "Lnnn", or any other
415    string, as necessary.  This is accomplished via the ASM_OUTPUT_CASE_END
416    macro. */
417
418 #undef ASM_OUTPUT_CASE_END
419 #define ASM_OUTPUT_CASE_END(FILE,NUM,TABLE)             \
420 { if (switch_table_difference_label_flag)               \
421     asm_fprintf (FILE, "\t%s %LLD%d,%LL%d-%LLI%d-2.b\n",\
422                  SET_ASM_OP, (NUM), (NUM), (NUM));      \
423   switch_table_difference_label_flag = 0; }
424
425 extern int switch_table_difference_label_flag;
426
427 /* This is how to output an element of a case-vector that is relative.  */
428
429 #undef ASM_OUTPUT_ADDR_DIFF_ELT
430 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)        \
431   asm_fprintf (FILE, "\t%s %LL%d-%LL%d\n", WORD_ASM_OP, VALUE, REL)
432
433 /* Currently, JUMP_TABLES_IN_TEXT_SECTION must be defined in order to
434    keep switch tables in the text section. */
435    
436 #define JUMP_TABLES_IN_TEXT_SECTION 1
437
438 /* Store in OUTPUT a string (made with alloca) containing
439    an assembler-name for a local static variable named NAME.
440    LABELNO is an integer which is different for each call.  */
441
442 #undef ASM_FORMAT_PRIVATE_NAME
443 #define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO)  \
444 ( (OUTPUT) = (char *) alloca (strlen ((NAME)) + 10),    \
445   sprintf ((OUTPUT), ASM_PN_FORMAT, (NAME), (LABELNO)))
446