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)
6 This file is part of GNU CC.
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)
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.
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. */
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. */
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 */
31 #include "m68k/m68k.h"
33 /* SGS specific assembler pseudo ops. */
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"
41 #define GLOBAL_ASM_OP ".global"
42 #define SWBEG_ASM_OP ".swbeg"
43 #define SET_ASM_OP ".set"
45 #define UNALIGNED_SHORT_ASM_OP ".short" /* Used in dwarfout.c */
46 #define UNALIGNED_INT_ASM_OP ".long" /* Used in dwarfout.c */
48 #define ASM_PN_FORMAT "%s_%d" /* Format for private names */
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. */
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 */
59 #undef REGISTER_PREFIX
60 #define REGISTER_PREFIX "%"
62 /* The prefix for local (compiler generated) labels.
63 These labels will not appear in the symbol table. */
65 #undef LOCAL_LABEL_PREFIX
66 #define LOCAL_LABEL_PREFIX "."
68 /* The prefix to add to user-visible assembler symbols. */
70 #undef USER_LABEL_PREFIX
71 #define USER_LABEL_PREFIX ""
73 /* The prefix for immediate operands. */
75 #undef IMMEDIATE_PREFIX
76 #define IMMEDIATE_PREFIX "&"
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' */
85 #ifndef SUPPORT_SUN_FPA
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" }
92 #else /* SUPPORTED_SUN_FPA */
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" }
103 #endif /* defined SUPPORT_SUN_FPA */
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 '.' */
109 #define ASM_IDENTIFY_GCC(FILE) \
110 { fprintf ((FILE), "%s:\n", "gcc2_compiled%"); }
112 /* This is how to output an assembler line defining an `int' constant. */
113 /* The SGS assembler doesn't understand ".word". */
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"))
121 #undef ASM_OUTPUT_LONG_DOUBLE
122 #define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE) \
124 REAL_VALUE_TO_TARGET_LONG_DOUBLE (VALUE, l); \
125 fprintf ((FILE), "\t%s 0x%x,0x%x,0x%x\n", LONG_ASM_OP, \
129 /* This is how to output an assembler line defining a `double' constant. */
131 #undef ASM_OUTPUT_DOUBLE
132 #define ASM_OUTPUT_DOUBLE(FILE,VALUE) \
134 REAL_VALUE_TO_TARGET_DOUBLE (VALUE, l); \
135 fprintf ((FILE), "\t%s 0x%x,0x%x\n", LONG_ASM_OP, \
139 /* This is how to output an assembler line defining a `float' constant. */
141 #undef ASM_OUTPUT_FLOAT
142 #define ASM_OUTPUT_FLOAT(FILE,VALUE) \
144 REAL_VALUE_TO_TARGET_SINGLE (VALUE, l); \
145 fprintf ((FILE), "\t%s 0x%x\n", LONG_ASM_OP, l); \
148 /* This is how to output an assembler line that says to advance the
149 location counter to a multiple of 2**LOG bytes. */
151 #undef ASM_OUTPUT_ALIGN
152 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
154 fprintf ((FILE), "\t%s \t%u\n", ALIGN_ASM_OP, 1 << (LOG)); \
155 else if ((LOG) > 31) \
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. */
165 #define ASM_OUTPUT_ASCII(FILE,PTR,LEN) \
167 register int sp = 0, lp = 0, ch; \
168 fprintf ((FILE), "\t%s ", BYTE_ASM_OP); \
171 if (ch > ' ' && ! (ch & 0x80) && ch != '\\') \
173 fprintf ((FILE), "'%c", ch); \
177 fprintf ((FILE), "0x%x", ch); \
181 if ((sp % 10) == 0) \
183 fprintf ((FILE), "\n\t%s ", BYTE_ASM_OP); \
187 putc (',', (FILE)); \
190 } while (sp < (LEN)); \
191 putc ('\n', (FILE)); \
195 /* SGS based assemblers don't understand #NO_APP and #APP, so just don't
196 bother emitting them. */
199 #define ASM_APP_ON ""
202 #define ASM_APP_OFF ""
204 /* When using SGS derived assemblers, change the "MIT" or "MOTOROLA"
207 #undef TARGET_VERSION
208 #define TARGET_VERSION fprintf (stderr, " (68k, SGS/AT&T syntax)");
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])
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])
219 #undef ASM_OUTPUT_FLOAT_OPERAND
220 #define ASM_OUTPUT_FLOAT_OPERAND(CODE,FILE,VALUE) \
222 REAL_VALUE_TO_TARGET_SINGLE (VALUE, l); \
223 asm_fprintf ((FILE), "%I0x%x", l); \
226 #undef ASM_OUTPUT_DOUBLE_OPERAND
227 #define ASM_OUTPUT_DOUBLE_OPERAND(FILE,VALUE) \
229 REAL_VALUE_TO_TARGET_DOUBLE (VALUE, l); \
230 asm_fprintf ((FILE), "%I0x%x%08x", l[0], l[1]); \
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. */
237 #define ASM_NO_SKIP_IN_TEXT 1
239 #undef ASM_OUTPUT_SKIP
240 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
241 fprintf (FILE, "\t%s %u\n", SPACE_ASM_OP, (SIZE))
243 /* Translate Motorola opcodes such as `jbeq' into SGS opcodes such
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.
255 #define ASM_OUTPUT_OPCODE(FILE, PTR) \
257 extern int flag_pic; \
258 if (!strncmp ((PTR), "jbsr", 4)) \
260 fprintf ((FILE), "bsr"); \
262 fprintf ((FILE), "jsr"); \
264 else if ((PTR)[0] == 'j' && (PTR)[1] == 'b') \
266 while (*(PTR) != ' ') \
267 { putc (*(PTR), (FILE)); ++(PTR); } \
268 fprintf ((FILE), ".w"); } \
269 else if ((PTR)[0] == 's') \
271 if (!strncmp ((PTR), "swap", 4)) \
272 { fprintf ((FILE), "swap.w"); (PTR) += 4; } \
274 /* FMOVE ==> FMOV, (and F%& F%$ translations) */ \
275 else if ((PTR)[0] == 'f') \
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)) \
287 if (TARGET_68040_ONLY) \
288 fprintf ((FILE), "fsmov"); \
289 else fprintf ((FILE), "fmov"); } \
290 else if (!strncmp ((PTR), "f%&move", 7)) \
292 if (TARGET_68040_ONLY) \
293 fprintf ((FILE), "fdmov"); \
294 else fprintf ((FILE), "fmov"); } \
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; } \
326 #else /* not SGS_SWAP_W */
328 #define ASM_OUTPUT_OPCODE(FILE, PTR) \
330 extern int flag_pic; \
331 if (!strncmp ((PTR), "jbsr", 4)) \
333 fprintf ((FILE), "bsr"); \
335 fprintf ((FILE), "jsr"); \
337 else if ((PTR)[0] == 'j' && (PTR)[1] == 'b') \
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') \
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)) \
355 if (TARGET_68040_ONLY) \
356 fprintf ((FILE), "fsmov"); \
357 else fprintf ((FILE), "fmov"); } \
358 else if (!strncmp ((PTR), "f%&move", 7)) \
360 if (TARGET_68040_ONLY) \
361 fprintf ((FILE), "fdmov"); \
362 else fprintf ((FILE), "fmov"); } \
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; } \
394 #endif /* not SGS_SWAP_W */
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. */
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));
404 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLE) \
406 ASM_OUTPUT_BEFORE_CASE_LABEL((FILE),(PREFIX),(NUM),(TABLE)); \
407 ASM_OUTPUT_INTERNAL_LABEL((FILE),(PREFIX),(NUM)); \
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
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; }
425 extern int switch_table_difference_label_flag;
427 /* This is how to output an element of a case-vector that is relative. */
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)
433 /* Currently, JUMP_TABLES_IN_TEXT_SECTION must be defined in order to
434 keep switch tables in the text section. */
436 #define JUMP_TABLES_IN_TEXT_SECTION 1
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. */
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)))