1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS 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 3, or (at your option)
13 GAS 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 GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "safe-ctype.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "opcode/m68k.h"
31 #include "m68k-parse.h"
42 static void m68k_elf_cons (int);
45 /* This string holds the chars that always start a comment. If the
46 pre-processor is disabled, these aren't very useful. The macro
47 tc_comment_chars points to this. We use this, rather than the
48 usual comment_chars, so that the --bitwise-or option will work. */
49 #if defined (TE_SVR4) || defined (TE_DELTA)
50 const char *m68k_comment_chars = "|#";
52 const char *m68k_comment_chars = "|";
55 /* This array holds the chars that only start a comment at the beginning of
56 a line. If the line seems to have the form '# 123 filename'
57 .line and .file directives will appear in the pre-processed output */
58 /* Note that input_file.c hand checks for '#' at the beginning of the
59 first line of the input file. This is because the compiler outputs
60 #NO_APP at the beginning of its output. */
61 /* Also note that comments like this one will always work. */
62 const char line_comment_chars[] = "#*";
64 const char line_separator_chars[] = ";";
66 /* Chars that can be used to separate mant from exp in floating point nums. */
67 const char EXP_CHARS[] = "eE";
69 /* Chars that mean this number is a floating point constant, as
70 in "0f12.456" or "0d1.2345e12". */
72 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
74 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
75 changed in read.c . Ideally it shouldn't have to know about it at all,
76 but nothing is ideal around here. */
78 /* Are we trying to generate PIC code? If so, absolute references
79 ought to be made into linkage table references or pc-relative
80 references. Not implemented. For ELF there are other means
81 to denote pic relocations. */
84 static int flag_short_refs; /* -l option. */
85 static int flag_long_jumps; /* -S option. */
86 static int flag_keep_pcrel; /* --pcrel option. */
88 #ifdef REGISTER_PREFIX_OPTIONAL
89 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
91 int flag_reg_prefix_optional;
94 /* Whether --register-prefix-optional was used on the command line. */
95 static int reg_prefix_optional_seen;
97 /* The floating point coprocessor to use by default. */
98 static enum m68k_register m68k_float_copnum = COP1;
100 /* If this is non-zero, then references to number(%pc) will be taken
101 to refer to number, rather than to %pc + number. */
102 static int m68k_abspcadd;
104 /* If this is non-zero, then the quick forms of the move, add, and sub
105 instructions are used when possible. */
106 static int m68k_quick = 1;
108 /* If this is non-zero, then if the size is not specified for a base
109 or outer displacement, the assembler assumes that the size should
111 static int m68k_rel32 = 1;
113 /* This is non-zero if m68k_rel32 was set from the command line. */
114 static int m68k_rel32_from_cmdline;
116 /* The default width to use for an index register when using a base
118 static enum m68k_size m68k_index_width_default = SIZE_LONG;
120 /* We want to warn if any text labels are misaligned. In order to get
121 the right line number, we need to record the line number for each
125 struct label_line *next;
132 /* The list of labels. */
134 static struct label_line *labels;
136 /* The current label. */
138 static struct label_line *current_label;
140 /* Pointer to list holding the opcodes sorted by name. */
141 static struct m68k_opcode const ** m68k_sorted_opcodes;
143 /* Its an arbitrary name: This means I don't approve of it.
145 static struct obstack robyn;
149 const char *m_operands;
150 unsigned long m_opcode;
154 struct m68k_incant *m_next;
157 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
158 #define gettwo(x) (((x)->m_opcode)&0xffff)
160 static const enum m68k_register m68000_ctrl[] = { 0 };
161 static const enum m68k_register m68010_ctrl[] = {
165 static const enum m68k_register m68020_ctrl[] = {
166 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
169 static const enum m68k_register m68040_ctrl[] = {
170 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
171 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
174 static const enum m68k_register m68060_ctrl[] = {
175 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
176 USP, VBR, URP, SRP, PCR,
179 static const enum m68k_register mcf_ctrl[] = {
180 CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
181 RAMBAR0, RAMBAR1, RAMBAR, MBAR,
184 static const enum m68k_register mcf51_ctrl[] = {
188 static const enum m68k_register mcf5206_ctrl[] = {
189 CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR_ALT, MBAR,
192 static const enum m68k_register mcf5208_ctrl[] = {
193 CACR, ACR0, ACR1, VBR, RAMBAR, RAMBAR1,
196 static const enum m68k_register mcf5210a_ctrl[] = {
197 VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR, RAMBAR1, MBAR,
200 static const enum m68k_register mcf5213_ctrl[] = {
201 VBR, RAMBAR, RAMBAR1, FLASHBAR,
204 static const enum m68k_register mcf5216_ctrl[] = {
205 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
208 static const enum m68k_register mcf5221x_ctrl[] = {
209 VBR, FLASHBAR, RAMBAR, RAMBAR1,
212 static const enum m68k_register mcf52223_ctrl[] = {
213 VBR, FLASHBAR, RAMBAR, RAMBAR1,
216 static const enum m68k_register mcf52235_ctrl[] = {
217 VBR, FLASHBAR, RAMBAR, RAMBAR1,
220 static const enum m68k_register mcf5225_ctrl[] = {
221 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, MBAR, RAMBAR1,
224 static const enum m68k_register mcf52259_ctrl[] = {
225 VBR, FLASHBAR, RAMBAR, RAMBAR1,
228 static const enum m68k_register mcf52277_ctrl[] = {
229 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
232 static const enum m68k_register mcf5235_ctrl[] = {
233 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
236 static const enum m68k_register mcf5249_ctrl[] = {
237 VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, RAMBAR, MBAR, MBAR2,
240 static const enum m68k_register mcf5250_ctrl[] = {
244 static const enum m68k_register mcf5253_ctrl[] = {
245 VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, RAMBAR, MBAR, MBAR2,
248 static const enum m68k_register mcf5271_ctrl[] = {
249 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
252 static const enum m68k_register mcf5272_ctrl[] = {
253 VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR_ALT, RAMBAR0, MBAR,
256 static const enum m68k_register mcf5275_ctrl[] = {
257 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
260 static const enum m68k_register mcf5282_ctrl[] = {
261 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
264 static const enum m68k_register mcf53017_ctrl[] = {
265 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
268 static const enum m68k_register mcf5307_ctrl[] = {
269 VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR_ALT, MBAR,
272 static const enum m68k_register mcf5329_ctrl[] = {
273 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
276 static const enum m68k_register mcf5373_ctrl[] = {
277 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
280 static const enum m68k_register mcfv4e_ctrl[] = {
281 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
282 VBR, PC, ROMBAR0, ROMBAR1, RAMBAR0, RAMBAR1,
284 MPCR /* Multiprocessor Control register */,
285 EDRAMBAR /* Embedded DRAM Base Address Register */,
286 /* Permutation control registers. */
287 PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
288 PCR3U0, PCR3L0, PCR3U1, PCR3L1,
290 TC /* ASID */, BUSCR /* MMUBAR */,
291 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
292 MBAR1 /* MBAR */, MBAR2 /* SECMBAR */, MBAR0 /* SECMBAR */,
293 ROMBAR /* ROMBAR0 */, RAMBAR /* RAMBAR1 */,
296 static const enum m68k_register mcf5407_ctrl[] = {
297 CACR, ASID, ACR0, ACR1, ACR2, ACR3,
298 VBR, PC, RAMBAR0, RAMBAR1, MBAR,
301 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
302 MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
305 static const enum m68k_register mcf54418_ctrl[] = {
306 CACR, ASID, ACR0, ACR1, ACR2, ACR3, ACR4, ACR5, ACR6, ACR7, MMUBAR, RGPIOBAR,
309 TC /* ASID */, BUSCR /* MMUBAR */,
310 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
311 RAMBAR /* RAMBAR1 */,
314 static const enum m68k_register mcf54455_ctrl[] = {
315 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
318 TC /* ASID */, BUSCR /* MMUBAR */,
319 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
320 RAMBAR /* RAMBAR1 */,
323 static const enum m68k_register mcf5475_ctrl[] = {
324 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
325 VBR, PC, RAMBAR0, RAMBAR1, MBAR,
327 TC /* ASID */, BUSCR /* MMUBAR */,
328 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
329 MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
332 static const enum m68k_register mcf5485_ctrl[] = {
333 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
334 VBR, PC, RAMBAR0, RAMBAR1, MBAR,
336 TC /* ASID */, BUSCR /* MMUBAR */,
337 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
338 MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
341 static const enum m68k_register fido_ctrl[] = {
342 SFC, DFC, USP, VBR, CAC, MBO,
345 #define cpu32_ctrl m68010_ctrl
347 static const enum m68k_register *control_regs;
349 /* Internal form of a 68020 instruction. */
353 const char *args; /* List of opcode info. */
356 int numo; /* Number of shorts in opcode. */
359 struct m68k_op operands[6];
361 int nexp; /* Number of exprs in use. */
362 struct m68k_exp exprs[4];
364 int nfrag; /* Number of frags we have to produce. */
367 int fragoff; /* Where in the current opcode the frag ends. */
374 int nrel; /* Num of reloc strucs in use. */
381 /* In a pc relative address the difference between the address
382 of the offset and the address that the offset is relative
383 to. This depends on the addressing mode. Basically this
384 is the value to put in the offset field to address the
385 first byte of the offset, without regarding the special
386 significance of some values (in the branch instruction, for
390 /* Whether this expression needs special pic relocation, and if
392 enum pic_relocation pic_reloc;
395 reloc[5]; /* Five is enough??? */
398 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a | fido_a))
399 #define float_of_arch(x) ((x) & mfloat)
400 #define mmu_of_arch(x) ((x) & mmmu)
401 #define arch_coldfire_p(x) ((x) & mcfisa_a)
402 #define arch_coldfire_fpu(x) ((x) & cfloat)
404 /* Macros for determining if cpu supports a specific addressing mode. */
405 #define HAVE_LONG_DISP(x) \
406 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
407 #define HAVE_LONG_CALL(x) \
408 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
409 #define HAVE_LONG_COND(x) \
410 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
411 #define HAVE_LONG_BRANCH(x) \
412 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b))
413 #define LONG_BRANCH_VIA_COND(x) (HAVE_LONG_COND(x) && !HAVE_LONG_BRANCH(x))
415 static struct m68k_it the_ins; /* The instruction being assembled. */
417 #define op(ex) ((ex)->exp.X_op)
418 #define adds(ex) ((ex)->exp.X_add_symbol)
419 #define subs(ex) ((ex)->exp.X_op_symbol)
420 #define offs(ex) ((ex)->exp.X_add_number)
422 /* Macros for adding things to the m68k_it struct. */
423 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
425 /* Like addword, but goes BEFORE general operands. */
428 insop (int w, const struct m68k_incant *opcode)
431 for (z = the_ins.numo; z > opcode->m_codenum; --z)
432 the_ins.opcode[z] = the_ins.opcode[z - 1];
433 for (z = 0; z < the_ins.nrel; z++)
434 the_ins.reloc[z].n += 2;
435 for (z = 0; z < the_ins.nfrag; z++)
436 the_ins.fragb[z].fragoff++;
437 the_ins.opcode[opcode->m_codenum] = w;
441 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
444 add_fix (int width, struct m68k_exp *exp, int pc_rel, int pc_fix)
446 the_ins.reloc[the_ins.nrel].n = (width == 'B' || width == '3'
447 ? the_ins.numo * 2 - 1
449 ? the_ins.numo * 2 + 1
450 : the_ins.numo * 2));
451 the_ins.reloc[the_ins.nrel].exp = exp->exp;
452 the_ins.reloc[the_ins.nrel].wid = width;
453 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
455 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
457 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
460 /* Cause an extra frag to be generated here, inserting up to 10 bytes
461 (that value is chosen in the frag_var call in md_assemble). TYPE
462 is the subtype of the frag to be generated; its primary type is
463 rs_machine_dependent.
465 The TYPE parameter is also used by md_convert_frag_1 and
466 md_estimate_size_before_relax. The appropriate type of fixup will
467 be emitted by md_convert_frag_1.
469 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
471 add_frag (symbolS *add, offsetT off, int type)
473 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
474 the_ins.fragb[the_ins.nfrag].fadd = add;
475 the_ins.fragb[the_ins.nfrag].foff = off;
476 the_ins.fragb[the_ins.nfrag++].fragty = type;
480 (op (ex) != O_constant && op (ex) != O_big)
482 static char *crack_operand (char *str, struct m68k_op *opP);
483 static int get_num (struct m68k_exp *exp, int ok);
484 static int reverse_16_bits (int in);
485 static int reverse_8_bits (int in);
486 static void install_gen_operand (int mode, int val);
487 static void install_operand (int mode, int val);
488 static void s_bss (int);
489 static void s_data1 (int);
490 static void s_data2 (int);
491 static void s_even (int);
492 static void s_proc (int);
493 static void s_chip (int);
494 static void s_fopt (int);
495 static void s_opt (int);
496 static void s_reg (int);
497 static void s_restore (int);
498 static void s_save (int);
499 static void s_mri_if (int);
500 static void s_mri_else (int);
501 static void s_mri_endi (int);
502 static void s_mri_break (int);
503 static void s_mri_next (int);
504 static void s_mri_for (int);
505 static void s_mri_endf (int);
506 static void s_mri_repeat (int);
507 static void s_mri_until (int);
508 static void s_mri_while (int);
509 static void s_mri_endw (int);
510 static void s_m68k_cpu (int);
511 static void s_m68k_arch (int);
515 unsigned long arch; /* Architecture features. */
516 const enum m68k_register *control_regs; /* Control regs on chip */
517 const char *name; /* Name */
518 int alias; /* Alias for a cannonical name. If 1, then
519 succeeds canonical name, if -1 then
520 succeeds canonical name, if <-1 ||>1 this is a
521 deprecated name, and the next/previous name
525 /* We hold flags for features explicitly enabled and explicitly
527 static int current_architecture;
528 static int not_current_architecture;
529 static const struct m68k_cpu *selected_arch;
530 static const struct m68k_cpu *selected_cpu;
531 static int initialized;
533 /* Architecture models. */
534 static const struct m68k_cpu m68k_archs[] =
536 {m68000, m68000_ctrl, "68000", 0},
537 {m68010, m68010_ctrl, "68010", 0},
538 {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
539 {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
540 {m68040, m68040_ctrl, "68040", 0},
541 {m68060, m68060_ctrl, "68060", 0},
542 {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
543 {fido_a, fido_ctrl, "fidoa", 0},
544 {mcfisa_a|mcfhwdiv, NULL, "isaa", 0},
545 {mcfisa_a|mcfhwdiv|mcfisa_aa|mcfusp, NULL, "isaaplus", 0},
546 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp, NULL, "isab", 0},
547 {mcfisa_a|mcfhwdiv|mcfisa_c|mcfusp, NULL, "isac", 0},
548 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac|mcfusp, mcf_ctrl, "cfv4", 0},
549 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "cfv4e", 0},
553 /* For -mno-mac we want to turn off all types of mac. */
554 static const unsigned no_mac = mcfmac | mcfemac;
556 /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
558 static const struct m68k_cpu m68k_extensions[] =
560 {m68851, NULL, "68851", -1},
561 {m68881, NULL, "68881", -1},
562 {m68881, NULL, "68882", -1},
564 {cfloat|m68881, NULL, "float", 0},
566 {mcfhwdiv, NULL, "div", 1},
567 {mcfusp, NULL, "usp", 1},
568 {mcfmac, (void *)&no_mac, "mac", 1},
569 {mcfemac, NULL, "emac", 1},
575 static const struct m68k_cpu m68k_cpus[] =
577 {m68000, m68000_ctrl, "68000", 0},
578 {m68000, m68000_ctrl, "68ec000", 1},
579 {m68000, m68000_ctrl, "68hc000", 1},
580 {m68000, m68000_ctrl, "68hc001", 1},
581 {m68000, m68000_ctrl, "68008", 1},
582 {m68000, m68000_ctrl, "68302", 1},
583 {m68000, m68000_ctrl, "68306", 1},
584 {m68000, m68000_ctrl, "68307", 1},
585 {m68000, m68000_ctrl, "68322", 1},
586 {m68000, m68000_ctrl, "68356", 1},
587 {m68010, m68010_ctrl, "68010", 0},
588 {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
589 {m68020|m68881|m68851, m68020_ctrl, "68k", 1},
590 {m68020|m68881|m68851, m68020_ctrl, "68ec020", 1},
591 {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
592 {m68030|m68881|m68851, m68020_ctrl, "68ec030", 1},
593 {m68040, m68040_ctrl, "68040", 0},
594 {m68040, m68040_ctrl, "68ec040", 1},
595 {m68060, m68060_ctrl, "68060", 0},
596 {m68060, m68060_ctrl, "68ec060", 1},
598 {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
599 {cpu32|m68881, cpu32_ctrl, "68330", 1},
600 {cpu32|m68881, cpu32_ctrl, "68331", 1},
601 {cpu32|m68881, cpu32_ctrl, "68332", 1},
602 {cpu32|m68881, cpu32_ctrl, "68333", 1},
603 {cpu32|m68881, cpu32_ctrl, "68334", 1},
604 {cpu32|m68881, cpu32_ctrl, "68336", 1},
605 {cpu32|m68881, cpu32_ctrl, "68340", 1},
606 {cpu32|m68881, cpu32_ctrl, "68341", 1},
607 {cpu32|m68881, cpu32_ctrl, "68349", 1},
608 {cpu32|m68881, cpu32_ctrl, "68360", 1},
610 {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51", 0},
611 {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51ac", 1},
612 {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51ag", 1},
613 {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51cn", 1},
614 {mcfisa_a|mcfisa_c|mcfusp|mcfmac, mcf51_ctrl, "51em", 1},
615 {mcfisa_a|mcfisa_c|mcfusp|mcfmac, mcf51_ctrl, "51je", 1},
616 {mcfisa_a|mcfisa_c|mcfusp|mcfemac, mcf51_ctrl, "51jf", 1},
617 {mcfisa_a|mcfisa_c|mcfusp|mcfemac, mcf51_ctrl, "51jg", 1},
618 {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51jm", 1},
619 {mcfisa_a|mcfisa_c|mcfusp|mcfmac, mcf51_ctrl, "51mm", 1},
620 {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51qe", 1},
621 {mcfisa_a|mcfisa_c|mcfusp|mcfemac, mcf51_ctrl, "51qm", 1},
623 {mcfisa_a, mcf_ctrl, "5200", 0},
624 {mcfisa_a, mcf_ctrl, "5202", 1},
625 {mcfisa_a, mcf_ctrl, "5204", 1},
626 {mcfisa_a, mcf5206_ctrl, "5206", 1},
628 {mcfisa_a|mcfhwdiv|mcfmac, mcf5206_ctrl, "5206e", 0},
630 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5207", -1},
631 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5208", 0},
633 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5210a_ctrl, "5210a", 0},
634 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5210a_ctrl, "5211a", 1},
636 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5211", -1},
637 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5212", -1},
638 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5213", 0},
640 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5214", -1},
641 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5216", 0},
642 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "521x", 2},
644 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5221x_ctrl, "5221x", 0},
646 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf52223_ctrl, "52221", -1},
647 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf52223_ctrl, "52223", 0},
649 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52230", -1},
650 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52233", -1},
651 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52234", -1},
652 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52235", 0},
654 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5225_ctrl, "5224", -1},
655 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5225_ctrl, "5225", 0},
657 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52277_ctrl, "52274", -1},
658 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52277_ctrl, "52277", 0},
660 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5232", -1},
661 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5233", -1},
662 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5234", -1},
663 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5235", -1},
664 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "523x", 0},
666 {mcfisa_a|mcfhwdiv|mcfemac, mcf5249_ctrl, "5249", 0},
667 {mcfisa_a|mcfhwdiv|mcfemac, mcf5250_ctrl, "5250", 0},
668 {mcfisa_a|mcfhwdiv|mcfemac, mcf5253_ctrl, "5253", 0},
670 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52252", -1},
671 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52254", -1},
672 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52255", -1},
673 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52256", -1},
674 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52258", -1},
675 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52259", 0},
677 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5270", -1},
678 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5271", 0},
680 {mcfisa_a|mcfhwdiv|mcfmac, mcf5272_ctrl, "5272", 0},
682 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5274", -1},
683 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5275", 0},
685 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5280", -1},
686 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5281", -1},
687 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5282", -1},
688 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "528x", 0},
690 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53011", -1},
691 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53012", -1},
692 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53013", -1},
693 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53014", -1},
694 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53015", -1},
695 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53016", -1},
696 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53017", 0},
698 {mcfisa_a|mcfhwdiv|mcfmac, mcf5307_ctrl, "5307", 0},
700 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5327", -1},
701 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5328", -1},
702 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5329", -1},
703 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "532x", 0},
705 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5372", -1},
706 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5373", -1},
707 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "537x", 0},
709 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfmac, mcf5407_ctrl, "5407",0},
711 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54410", -1},
712 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54415", -1},
713 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54416", -1},
714 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54417", -1},
715 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54418", 0},
717 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54450", -1},
718 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54451", -1},
719 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54452", -1},
720 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54453", -1},
721 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54454", -1},
722 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54455", 0},
724 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5470", -1},
725 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5471", -1},
726 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5472", -1},
727 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5473", -1},
728 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5474", -1},
729 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5475", -1},
730 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "547x", 0},
732 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5480", -1},
733 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5481", -1},
734 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5482", -1},
735 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5483", -1},
736 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5484", -1},
737 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5485", -1},
738 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "548x", 0},
740 {fido_a, fido_ctrl, "fidoa", 0},
741 {fido_a, fido_ctrl, "fido", 1},
746 static const struct m68k_cpu *m68k_lookup_cpu
747 (const char *, const struct m68k_cpu *, int, int *);
748 static int m68k_set_arch (const char *, int, int);
749 static int m68k_set_cpu (const char *, int, int);
750 static int m68k_set_extension (const char *, int, int);
751 static void m68k_init_arch (void);
753 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
754 architecture and we have a lot of relaxation modes. */
756 /* Macros used in the relaxation code. */
757 #define TAB(x,y) (((x) << 2) + (y))
758 #define TABTYPE(x) ((x) >> 2)
760 /* Relaxation states. */
766 /* Here are all the relaxation modes we support. First we can relax ordinary
767 branches. On 68020 and higher and on CPU32 all branch instructions take
768 three forms, so on these CPUs all branches always remain as such. When we
769 have to expand to the LONG form on a 68000, though, we substitute an
770 absolute jump instead. This is a direct replacement for unconditional
771 branches and a branch over a jump for conditional branches. However, if the
772 user requires PIC and disables this with --pcrel, we can only relax between
773 BYTE and SHORT forms, punting if that isn't enough. This gives us four
774 different relaxation modes for branches: */
776 #define BRANCHBWL 0 /* Branch byte, word, or long. */
777 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
778 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
779 #define BRANCHBW 3 /* Branch byte or word. */
781 /* We also relax coprocessor branches and DBcc's. All CPUs that support
782 coprocessor branches support them in word and long forms, so we have only
783 one relaxation mode for them. DBcc's are word only on all CPUs. We can
784 relax them to the LONG form with a branch-around sequence. This sequence
785 can use a long branch (if available) or an absolute jump (if acceptable).
786 This gives us two relaxation modes. If long branches are not available and
787 absolute jumps are not acceptable, we don't relax DBcc's. */
789 #define FBRANCH 4 /* Coprocessor branch. */
790 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
791 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
793 /* That's all for instruction relaxation. However, we also relax PC-relative
794 operands. Specifically, we have three operand relaxation modes. On the
795 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
796 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
797 two. Also PC+displacement+index operands in their simple form (with a non-
798 suppressed index without memory indirection) are supported on all CPUs, but
799 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
800 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
801 form of the PC+displacement+index operand. Finally, some absolute operands
802 can be relaxed down to 16-bit PC-relative. */
804 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
805 #define PCINDEX 8 /* PC + displacement + index. */
806 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
808 /* This relaxation is required for branches where there is no long
809 branch and we are in pcrel mode. We generate a bne/beq pair. */
810 #define BRANCHBWPL 10 /* Branch byte, word or pair of longs
813 /* Note that calls to frag_var need to specify the maximum expansion
814 needed; this is currently 12 bytes for bne/beq pair. */
815 #define FRAG_VAR_SIZE 12
818 How far Forward this mode will reach:
819 How far Backward this mode will reach:
820 How many bytes this mode will add to the size of the frag
821 Which mode to go to if the offset won't fit in this one
823 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
824 relax_typeS md_relax_table[] =
826 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
827 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
831 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
832 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
836 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
837 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
841 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
846 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
847 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
851 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
852 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
856 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
857 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
861 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
862 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
866 { 125, -130, 0, TAB (PCINDEX, SHORT) },
867 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
871 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
872 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
876 { 127, -128, 0, TAB (BRANCHBWPL, SHORT) },
877 { 32767, -32768, 2, TAB (BRANCHBWPL, LONG) },
882 /* These are the machine dependent pseudo-ops. These are included so
883 the assembler can work on the output from the SUN C compiler, which
886 /* This table describes all the machine specific pseudo-ops the assembler
887 has to support. The fields are:
888 pseudo-op name without dot
889 function to call to execute this pseudo-op
890 Integer arg to pass to the function. */
891 const pseudo_typeS md_pseudo_table[] =
893 {"data1", s_data1, 0},
894 {"data2", s_data2, 0},
897 {"skip", s_space, 0},
899 #if defined (TE_SUN3) || defined (OBJ_ELF)
900 {"align", s_align_bytes, 0},
903 {"swbeg", s_ignore, 0},
904 {"long", m68k_elf_cons, 4},
906 {"extend", float_cons, 'x'},
907 {"ldouble", float_cons, 'x'},
909 {"arch", s_m68k_arch, 0},
910 {"cpu", s_m68k_cpu, 0},
912 /* The following pseudo-ops are supported for MRI compatibility. */
914 {"comline", s_space, 1},
916 {"mask2", s_ignore, 0},
919 {"restore", s_restore, 0},
923 {"if.b", s_mri_if, 'b'},
924 {"if.w", s_mri_if, 'w'},
925 {"if.l", s_mri_if, 'l'},
926 {"else", s_mri_else, 0},
927 {"else.s", s_mri_else, 's'},
928 {"else.l", s_mri_else, 'l'},
929 {"endi", s_mri_endi, 0},
930 {"break", s_mri_break, 0},
931 {"break.s", s_mri_break, 's'},
932 {"break.l", s_mri_break, 'l'},
933 {"next", s_mri_next, 0},
934 {"next.s", s_mri_next, 's'},
935 {"next.l", s_mri_next, 'l'},
936 {"for", s_mri_for, 0},
937 {"for.b", s_mri_for, 'b'},
938 {"for.w", s_mri_for, 'w'},
939 {"for.l", s_mri_for, 'l'},
940 {"endf", s_mri_endf, 0},
941 {"repeat", s_mri_repeat, 0},
942 {"until", s_mri_until, 0},
943 {"until.b", s_mri_until, 'b'},
944 {"until.w", s_mri_until, 'w'},
945 {"until.l", s_mri_until, 'l'},
946 {"while", s_mri_while, 0},
947 {"while.b", s_mri_while, 'b'},
948 {"while.w", s_mri_while, 'w'},
949 {"while.l", s_mri_while, 'l'},
950 {"endw", s_mri_endw, 0},
955 /* The mote pseudo ops are put into the opcode table, since they
956 don't start with a . they look like opcodes to gas. */
958 const pseudo_typeS mote_pseudo_table[] =
971 {"xdef", s_globl, 0},
973 {"align", s_align_bytes, 0},
975 {"align", s_align_ptwo, 0},
978 {"sect", obj_coff_section, 0},
979 {"section", obj_coff_section, 0},
984 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
985 gives identical results to a 32-bit host. */
986 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
987 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
989 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
990 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
991 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
992 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
994 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
995 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
996 #define islong(x) (1)
998 static char notend_table[256];
999 static char alt_notend_table[256];
1001 (! (notend_table[(unsigned char) *s] \
1003 && alt_notend_table[(unsigned char) s[1]])))
1007 /* Return zero if the reference to SYMBOL from within the same segment may
1010 /* On an ELF system, we can't relax an externally visible symbol,
1011 because it may be overridden by a shared library. However, if
1012 TARGET_OS is "elf", then we presume that we are assembling for an
1013 embedded system, in which case we don't have to worry about shared
1014 libraries, and we can relax any external sym. */
1016 #define relaxable_symbol(symbol) \
1017 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
1018 || S_IS_WEAK (symbol)))
1020 /* Compute the relocation code for a fixup of SIZE bytes, using pc
1021 relative relocation if PCREL is non-zero. PIC says whether a special
1022 pic relocation was requested. */
1024 static bfd_reloc_code_real_type
1025 get_reloc_code (int size, int pcrel, enum pic_relocation pic)
1033 return BFD_RELOC_8_GOT_PCREL;
1035 return BFD_RELOC_16_GOT_PCREL;
1037 return BFD_RELOC_32_GOT_PCREL;
1045 return BFD_RELOC_8_GOTOFF;
1047 return BFD_RELOC_16_GOTOFF;
1049 return BFD_RELOC_32_GOTOFF;
1057 return BFD_RELOC_8_PLT_PCREL;
1059 return BFD_RELOC_16_PLT_PCREL;
1061 return BFD_RELOC_32_PLT_PCREL;
1069 return BFD_RELOC_8_PLTOFF;
1071 return BFD_RELOC_16_PLTOFF;
1073 return BFD_RELOC_32_PLTOFF;
1081 return BFD_RELOC_68K_TLS_GD8;
1083 return BFD_RELOC_68K_TLS_GD16;
1085 return BFD_RELOC_68K_TLS_GD32;
1093 return BFD_RELOC_68K_TLS_LDM8;
1095 return BFD_RELOC_68K_TLS_LDM16;
1097 return BFD_RELOC_68K_TLS_LDM32;
1105 return BFD_RELOC_68K_TLS_LDO8;
1107 return BFD_RELOC_68K_TLS_LDO16;
1109 return BFD_RELOC_68K_TLS_LDO32;
1117 return BFD_RELOC_68K_TLS_IE8;
1119 return BFD_RELOC_68K_TLS_IE16;
1121 return BFD_RELOC_68K_TLS_IE32;
1129 return BFD_RELOC_68K_TLS_LE8;
1131 return BFD_RELOC_68K_TLS_LE16;
1133 return BFD_RELOC_68K_TLS_LE32;
1143 return BFD_RELOC_8_PCREL;
1145 return BFD_RELOC_16_PCREL;
1147 return BFD_RELOC_32_PCREL;
1157 return BFD_RELOC_16;
1159 return BFD_RELOC_32;
1166 if (pic == pic_none)
1167 as_bad (_("Can not do %d byte pc-relative relocation"), size);
1169 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
1173 if (pic == pic_none)
1174 as_bad (_("Can not do %d byte relocation"), size);
1176 as_bad (_("Can not do %d byte pic relocation"), size);
1179 return BFD_RELOC_NONE;
1182 /* Here we decide which fixups can be adjusted to make them relative
1183 to the beginning of the section instead of the symbol. Basically
1184 we need to make sure that the dynamic relocations are done
1185 correctly, so in some cases we force the original symbol to be
1188 tc_m68k_fix_adjustable (fixS *fixP)
1190 /* Adjust_reloc_syms doesn't know about the GOT. */
1191 switch (fixP->fx_r_type)
1193 case BFD_RELOC_8_GOT_PCREL:
1194 case BFD_RELOC_16_GOT_PCREL:
1195 case BFD_RELOC_32_GOT_PCREL:
1196 case BFD_RELOC_8_GOTOFF:
1197 case BFD_RELOC_16_GOTOFF:
1198 case BFD_RELOC_32_GOTOFF:
1199 case BFD_RELOC_8_PLT_PCREL:
1200 case BFD_RELOC_16_PLT_PCREL:
1201 case BFD_RELOC_32_PLT_PCREL:
1202 case BFD_RELOC_8_PLTOFF:
1203 case BFD_RELOC_16_PLTOFF:
1204 case BFD_RELOC_32_PLTOFF:
1205 case BFD_RELOC_68K_TLS_GD32:
1206 case BFD_RELOC_68K_TLS_GD16:
1207 case BFD_RELOC_68K_TLS_GD8:
1208 case BFD_RELOC_68K_TLS_LDM32:
1209 case BFD_RELOC_68K_TLS_LDM16:
1210 case BFD_RELOC_68K_TLS_LDM8:
1211 case BFD_RELOC_68K_TLS_LDO32:
1212 case BFD_RELOC_68K_TLS_LDO16:
1213 case BFD_RELOC_68K_TLS_LDO8:
1214 case BFD_RELOC_68K_TLS_IE32:
1215 case BFD_RELOC_68K_TLS_IE16:
1216 case BFD_RELOC_68K_TLS_IE8:
1217 case BFD_RELOC_68K_TLS_LE32:
1218 case BFD_RELOC_68K_TLS_LE16:
1219 case BFD_RELOC_68K_TLS_LE8:
1222 case BFD_RELOC_VTABLE_INHERIT:
1223 case BFD_RELOC_VTABLE_ENTRY:
1231 #else /* !OBJ_ELF */
1233 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
1235 /* PR gas/3041 Weak symbols are not relaxable
1236 because they must be treated as extern. */
1237 #define relaxable_symbol(symbol) (!(S_IS_WEAK (symbol)))
1239 #endif /* OBJ_ELF */
1242 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
1245 bfd_reloc_code_real_type code;
1247 /* If the tcbit is set, then this was a fixup of a negative value
1248 that was never resolved. We do not have a reloc to handle this,
1249 so just return. We assume that other code will have detected this
1250 situation and produced a helpful error message, so we just tell the
1251 user that the reloc cannot be produced. */
1255 as_bad_where (fixp->fx_file, fixp->fx_line,
1256 _("Unable to produce reloc against symbol '%s'"),
1257 S_GET_NAME (fixp->fx_addsy));
1261 if (fixp->fx_r_type != BFD_RELOC_NONE)
1263 code = fixp->fx_r_type;
1265 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1266 that fixup_segment converted a non-PC relative reloc into a
1267 PC relative reloc. In such a case, we need to convert the
1274 code = BFD_RELOC_8_PCREL;
1277 code = BFD_RELOC_16_PCREL;
1280 code = BFD_RELOC_32_PCREL;
1282 case BFD_RELOC_8_PCREL:
1283 case BFD_RELOC_16_PCREL:
1284 case BFD_RELOC_32_PCREL:
1285 case BFD_RELOC_8_GOT_PCREL:
1286 case BFD_RELOC_16_GOT_PCREL:
1287 case BFD_RELOC_32_GOT_PCREL:
1288 case BFD_RELOC_8_GOTOFF:
1289 case BFD_RELOC_16_GOTOFF:
1290 case BFD_RELOC_32_GOTOFF:
1291 case BFD_RELOC_8_PLT_PCREL:
1292 case BFD_RELOC_16_PLT_PCREL:
1293 case BFD_RELOC_32_PLT_PCREL:
1294 case BFD_RELOC_8_PLTOFF:
1295 case BFD_RELOC_16_PLTOFF:
1296 case BFD_RELOC_32_PLTOFF:
1297 case BFD_RELOC_68K_TLS_GD32:
1298 case BFD_RELOC_68K_TLS_GD16:
1299 case BFD_RELOC_68K_TLS_GD8:
1300 case BFD_RELOC_68K_TLS_LDM32:
1301 case BFD_RELOC_68K_TLS_LDM16:
1302 case BFD_RELOC_68K_TLS_LDM8:
1303 case BFD_RELOC_68K_TLS_LDO32:
1304 case BFD_RELOC_68K_TLS_LDO16:
1305 case BFD_RELOC_68K_TLS_LDO8:
1306 case BFD_RELOC_68K_TLS_IE32:
1307 case BFD_RELOC_68K_TLS_IE16:
1308 case BFD_RELOC_68K_TLS_IE8:
1309 case BFD_RELOC_68K_TLS_LE32:
1310 case BFD_RELOC_68K_TLS_LE16:
1311 case BFD_RELOC_68K_TLS_LE8:
1314 as_bad_where (fixp->fx_file, fixp->fx_line,
1315 _("Cannot make %s relocation PC relative"),
1316 bfd_get_reloc_code_name (code));
1322 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1323 switch (F (fixp->fx_size, fixp->fx_pcrel))
1325 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1326 MAP (1, 0, BFD_RELOC_8);
1327 MAP (2, 0, BFD_RELOC_16);
1328 MAP (4, 0, BFD_RELOC_32);
1329 MAP (1, 1, BFD_RELOC_8_PCREL);
1330 MAP (2, 1, BFD_RELOC_16_PCREL);
1331 MAP (4, 1, BFD_RELOC_32_PCREL);
1339 reloc = (arelent *) xmalloc (sizeof (arelent));
1340 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1341 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1342 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1344 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
1346 && S_IS_WEAK (fixp->fx_addsy)
1347 && ! bfd_is_und_section (S_GET_SEGMENT (fixp->fx_addsy)))
1349 /* PR gas/3041 References to weak symbols must be treated as extern
1350 in order to be overridable by the linker, even if they are defined
1351 in the same object file. So the original addend must be written
1352 "as is" into the output section without further processing.
1353 The addend value must be hacked here in order to force
1354 bfd_install_relocation() to write the original value into the
1356 1) MD_APPLY_SYM_VALUE() is set to 1 for m68k/a.out, so the symbol
1357 value has already been added to the addend in fixup_segment(). We
1359 2) bfd_install_relocation() will incorrectly treat this symbol as
1360 resolved, so it will write the symbol value plus its addend and
1361 section VMA. As a workaround we can tweak the addend value here in
1362 order to get the original value in the section after the call to
1363 bfd_install_relocation(). */
1364 reloc->addend = fixp->fx_addnumber
1365 /* Fix because of MD_APPLY_SYM_VALUE() */
1366 - S_GET_VALUE (fixp->fx_addsy)
1367 /* Fix for bfd_install_relocation() */
1368 - (S_GET_VALUE (fixp->fx_addsy)
1369 + S_GET_SEGMENT (fixp->fx_addsy)->vma);
1371 else if (fixp->fx_pcrel)
1372 reloc->addend = fixp->fx_addnumber;
1376 if (!fixp->fx_pcrel)
1377 reloc->addend = fixp->fx_addnumber;
1379 reloc->addend = (section->vma
1380 + fixp->fx_pcrel_adjust
1381 + fixp->fx_addnumber
1382 + md_pcrel_from (fixp));
1385 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1386 gas_assert (reloc->howto != 0);
1391 /* Handle of the OPCODE hash table. NULL means any use before
1392 m68k_ip_begin() will crash. */
1393 static struct hash_control *op_hash;
1395 /* Assemble an m68k instruction. */
1398 m68k_ip (char *instring)
1401 register struct m68k_op *opP;
1402 register const struct m68k_incant *opcode;
1403 register const char *s;
1404 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1405 char *pdot, *pdotmove;
1406 enum m68k_size siz1, siz2;
1410 struct m68k_op operands_backup[6];
1411 LITTLENUM_TYPE words[6];
1412 LITTLENUM_TYPE *wordp;
1413 unsigned long ok_arch = 0;
1415 if (*instring == ' ')
1416 instring++; /* Skip leading whitespace. */
1418 /* Scan up to end of operation-code, which MUST end in end-of-string
1419 or exactly 1 space. */
1421 for (p = instring; *p != '\0'; p++)
1431 the_ins.error = _("No operator");
1435 /* p now points to the end of the opcode name, probably whitespace.
1436 Make sure the name is null terminated by clobbering the
1437 whitespace, look it up in the hash table, then fix it back.
1438 Remove a dot, first, since the opcode tables have none. */
1441 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1442 *pdotmove = pdotmove[1];
1448 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1453 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1454 *pdotmove = pdotmove[-1];
1461 the_ins.error = _("Unknown operator");
1465 /* Found a legitimate opcode, start matching operands. */
1469 if (opcode->m_operands == 0)
1471 char *old = input_line_pointer;
1473 input_line_pointer = p;
1474 /* Ahh - it's a motorola style psuedo op. */
1475 mote_pseudo_table[opcode->m_opnum].poc_handler
1476 (mote_pseudo_table[opcode->m_opnum].poc_val);
1477 input_line_pointer = old;
1483 if (flag_mri && opcode->m_opnum == 0)
1485 /* In MRI mode, random garbage is allowed after an instruction
1486 which accepts no operands. */
1487 the_ins.args = opcode->m_operands;
1488 the_ins.numargs = opcode->m_opnum;
1489 the_ins.numo = opcode->m_codenum;
1490 the_ins.opcode[0] = getone (opcode);
1491 the_ins.opcode[1] = gettwo (opcode);
1495 for (opP = &the_ins.operands[0]; *p; opP++)
1497 p = crack_operand (p, opP);
1501 the_ins.error = opP->error;
1506 opsfound = opP - &the_ins.operands[0];
1508 /* This ugly hack is to support the floating pt opcodes in their
1509 standard form. Essentially, we fake a first enty of type COP#1 */
1510 if (opcode->m_operands[0] == 'I')
1514 for (n = opsfound; n > 0; --n)
1515 the_ins.operands[n] = the_ins.operands[n - 1];
1517 memset (&the_ins.operands[0], '\0', sizeof (the_ins.operands[0]));
1518 the_ins.operands[0].mode = CONTROL;
1519 the_ins.operands[0].reg = m68k_float_copnum;
1523 /* We've got the operands. Find an opcode that'll accept them. */
1526 /* If we didn't get the right number of ops, or we have no
1527 common model with this pattern then reject this pattern. */
1529 ok_arch |= opcode->m_arch;
1530 if (opsfound != opcode->m_opnum
1531 || ((opcode->m_arch & current_architecture) == 0))
1537 /* Make a copy of the operands of this insn so that
1538 we can modify them safely, should we want to. */
1539 gas_assert (opsfound <= (int) ARRAY_SIZE (operands_backup));
1540 for (i = 0; i < opsfound; i++)
1541 operands_backup[i] = the_ins.operands[i];
1543 for (s = opcode->m_operands, opP = &operands_backup[0];
1547 /* Warning: this switch is huge! */
1548 /* I've tried to organize the cases into this order:
1549 non-alpha first, then alpha by letter. Lower-case
1550 goes directly before uppercase counterpart. */
1551 /* Code with multiple case ...: gets sorted by the lowest
1552 case ... it belongs to. I hope this makes sense. */
1658 if (opP->reg == PC || opP->reg == ZPC)
1675 if (opP->reg == PC || opP->reg == ZPC)
1694 if (opP->reg == PC || opP->reg == ZPC)
1704 if (opP->mode != IMMED)
1706 else if (s[1] == 'b'
1707 && ! isvar (&opP->disp)
1708 && (opP->disp.exp.X_op != O_constant
1709 || ! isbyte (opP->disp.exp.X_add_number)))
1711 else if (s[1] == 'B'
1712 && ! isvar (&opP->disp)
1713 && (opP->disp.exp.X_op != O_constant
1714 || ! issbyte (opP->disp.exp.X_add_number)))
1716 else if (s[1] == 'w'
1717 && ! isvar (&opP->disp)
1718 && (opP->disp.exp.X_op != O_constant
1719 || ! isword (opP->disp.exp.X_add_number)))
1721 else if (s[1] == 'W'
1722 && ! isvar (&opP->disp)
1723 && (opP->disp.exp.X_op != O_constant
1724 || ! issword (opP->disp.exp.X_add_number)))
1730 if (opP->mode != IMMED)
1735 if (opP->mode == AREG
1736 || opP->mode == CONTROL
1737 || opP->mode == FPREG
1738 || opP->mode == IMMED
1739 || opP->mode == REGLST
1740 || (opP->mode != ABSL
1742 || opP->reg == ZPC)))
1747 if (opP->mode == CONTROL
1748 || opP->mode == FPREG
1749 || opP->mode == REGLST
1750 || opP->mode == IMMED
1751 || (opP->mode != ABSL
1753 || opP->reg == ZPC)))
1781 if (opP->mode == CONTROL
1782 || opP->mode == FPREG
1783 || opP->mode == REGLST)
1788 if (opP->mode != AINC)
1793 if (opP->mode != ADEC)
1843 if (opP->reg == PC || opP->reg == ZPC)
1864 case '~': /* For now! (JF FOO is this right?) */
1886 if (opP->mode != CONTROL
1887 || (opP->reg != TT0 && opP->reg != TT1))
1892 if (opP->mode != AREG)
1897 if (opP->mode != AINDR)
1902 if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
1903 && (opP->mode != DISP
1905 || opP->reg > ADDR7))
1910 if (opP->mode != ABSL
1912 && strncmp (instring, "jbsr", 4) == 0))
1935 if (opP->mode != CONTROL || opP->reg != CCR)
1940 if (opP->mode != DISP
1942 || opP->reg > ADDR7)
1947 if (opP->mode != DREG)
1952 if (opP->reg != ACC)
1957 if (opP->reg != ACC && opP->reg != ACC1
1958 && opP->reg != ACC2 && opP->reg != ACC3)
1963 if (opP->mode != FPREG)
1968 if (opP->reg != MACSR)
1973 if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
1978 if (opP->reg != MASK)
1983 if (opP->mode != CONTROL
1990 if (opP->mode != LSH && opP->mode != RSH)
1995 if (opP->mode != CONTROL
1997 || opP->reg > last_movec_reg
2002 const enum m68k_register *rp;
2004 for (rp = control_regs; *rp; rp++)
2006 if (*rp == opP->reg)
2008 /* In most CPUs RAMBAR refers to control reg
2009 c05 (RAMBAR1), but a few CPUs have it
2010 refer to c04 (RAMBAR0). */
2011 else if (*rp == RAMBAR_ALT && opP->reg == RAMBAR)
2013 opP->reg = RAMBAR_ALT;
2023 if (opP->mode != IMMED)
2029 if (opP->mode == DREG
2030 || opP->mode == AREG
2031 || opP->mode == FPREG)
2040 opP->mask = 1 << (opP->reg - DATA0);
2043 opP->mask = 1 << (opP->reg - ADDR0 + 8);
2046 opP->mask = 1 << (opP->reg - FP0 + 16);
2054 else if (opP->mode == CONTROL)
2063 opP->mask = 1 << 24;
2066 opP->mask = 1 << 25;
2069 opP->mask = 1 << 26;
2078 else if (opP->mode != REGLST)
2080 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
2082 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
2087 if (opP->mode != IMMED)
2089 else if (opP->disp.exp.X_op != O_constant
2090 || ! issbyte (opP->disp.exp.X_add_number))
2092 else if (! m68k_quick
2093 && instring[3] != 'q'
2094 && instring[4] != 'q')
2099 if (opP->mode != DREG
2100 && opP->mode != IMMED
2101 && opP->mode != ABSL)
2106 if (opP->mode != IMMED)
2108 else if (opP->disp.exp.X_op != O_constant
2109 || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
2111 else if (! m68k_quick
2112 && (strncmp (instring, "add", 3) == 0
2113 || strncmp (instring, "sub", 3) == 0)
2114 && instring[3] != 'q')
2119 if (opP->mode != DREG && opP->mode != AREG)
2124 if (opP->mode != AINDR
2125 && (opP->mode != BASE
2127 && opP->reg != ZADDR0)
2128 || opP->disp.exp.X_op != O_absent
2129 || ((opP->index.reg < DATA0
2130 || opP->index.reg > DATA7)
2131 && (opP->index.reg < ADDR0
2132 || opP->index.reg > ADDR7))
2133 || opP->index.size != SIZE_UNSPEC
2134 || opP->index.scale != 1))
2139 if (opP->mode != CONTROL
2140 || ! (opP->reg == FPI
2142 || opP->reg == FPC))
2147 if (opP->mode != CONTROL || opP->reg != SR)
2152 if (opP->mode != IMMED)
2154 else if (opP->disp.exp.X_op != O_constant
2155 || TRUNC (opP->disp.exp.X_add_number) > 7)
2160 if (opP->mode != CONTROL || opP->reg != USP)
2165 if (opP->mode != IMMED)
2167 else if (opP->disp.exp.X_op != O_constant
2168 || (TRUNC (opP->disp.exp.X_add_number) != 0xffffffff
2169 && TRUNC (opP->disp.exp.X_add_number) - 1 > 6))
2174 if (opP->mode != IMMED)
2176 else if (opP->disp.exp.X_op != O_constant
2177 || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
2182 if (opP->mode != IMMED)
2184 else if (opP->disp.exp.X_op != O_constant
2185 || TRUNC (opP->disp.exp.X_add_number) > 511)
2189 /* JF these are out of order. We could put them
2190 in order if we were willing to put up with
2191 bunches of #ifdef m68851s in the code.
2193 Don't forget that you need these operands
2194 to use 68030 MMU instructions. */
2196 /* Memory addressing mode used by pflushr. */
2198 if (opP->mode == CONTROL
2199 || opP->mode == FPREG
2200 || opP->mode == DREG
2201 || opP->mode == AREG
2202 || opP->mode == REGLST)
2204 /* We should accept immediate operands, but they
2205 supposedly have to be quad word, and we don't
2206 handle that. I would like to see what a Motorola
2207 assembler does before doing something here. */
2208 if (opP->mode == IMMED)
2213 if (opP->mode != CONTROL
2214 || (opP->reg != SFC && opP->reg != DFC))
2219 if (opP->mode != CONTROL || opP->reg != TC)
2224 if (opP->mode != CONTROL || opP->reg != AC)
2229 if (opP->mode != CONTROL
2232 && opP->reg != SCC))
2237 if (opP->mode != CONTROL
2243 if (opP->mode != CONTROL
2246 && opP->reg != CRP))
2270 if (opP->mode != CONTROL
2271 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
2272 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
2277 if (opP->mode != CONTROL || opP->reg != PSR)
2282 if (opP->mode != CONTROL || opP->reg != PCSR)
2287 if (opP->mode != CONTROL
2296 if (opP->mode != ABSL)
2301 if (opP->reg < DATA0L || opP->reg > ADDR7U)
2303 /* FIXME: kludge instead of fixing parser:
2304 upper/lower registers are *not* CONTROL
2305 registers, but ordinary ones. */
2306 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
2307 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
2314 if (!(opP->mode == AINDR
2315 || (opP->mode == DISP
2316 && !(opP->reg == PC || opP->reg == ZPC))))
2321 if (!(opP->mode == AINDR || opP->mode == DISP))
2333 /* Since we have found the correct instruction, copy
2334 in the modifications that we may have made. */
2336 for (i = 0; i < opsfound; i++)
2337 the_ins.operands[i] = operands_backup[i];
2343 opcode = opcode->m_next;
2348 && !(ok_arch & current_architecture))
2350 const struct m68k_cpu *cpu;
2353 char *buf = xmalloc (space + 1);
2357 the_ins.error = buf;
2358 /* Make sure there's a NUL at the end of the buffer -- strncpy
2359 won't write one when it runs out of buffer. */
2361 #define APPEND(STRING) \
2362 (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
2364 APPEND (_("invalid instruction for this architecture; needs "));
2368 APPEND ("ColdFire ISA_A");
2371 APPEND ("ColdFire ");
2372 APPEND (_("hardware divide"));
2375 APPEND ("ColdFire ISA_A+");
2378 APPEND ("ColdFire ISA_B");
2381 APPEND ("ColdFire ISA_C");
2384 APPEND ("ColdFire fpu");
2387 APPEND ("M68K fpu");
2390 APPEND ("M68K mmu");
2394 APPEND (_("or higher"));
2398 APPEND (_("or higher"));
2402 APPEND (_("or higher"));
2410 for (cpu = m68k_cpus; cpu->name; cpu++)
2411 if (!cpu->alias && (cpu->arch & ok_arch))
2413 const struct m68k_cpu *alias;
2414 int seen_master = 0;
2420 for (alias = cpu; alias != m68k_cpus; alias--)
2421 if (alias[-1].alias >= 0)
2423 for (; !seen_master || alias->alias > 0; alias++)
2433 APPEND (alias->name);
2446 /* We ran out of space, so replace the end of the list
2451 strcpy (buf, " ...");
2455 the_ins.error = _("operands mismatch");
2462 /* Now assemble it. */
2463 the_ins.args = opcode->m_operands;
2464 the_ins.numargs = opcode->m_opnum;
2465 the_ins.numo = opcode->m_codenum;
2466 the_ins.opcode[0] = getone (opcode);
2467 the_ins.opcode[1] = gettwo (opcode);
2469 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
2474 /* This switch is a doozy.
2475 Watch the first step; its a big one! */
2508 tmpreg = 0x3c; /* 7.4 */
2509 if (strchr ("bwl", s[1]))
2510 nextword = get_num (&opP->disp, 90);
2512 nextword = get_num (&opP->disp, 0);
2513 if (isvar (&opP->disp))
2514 add_fix (s[1], &opP->disp, 0, 0);
2518 if (!isbyte (nextword))
2519 opP->error = _("operand out of range");
2524 if (!isword (nextword))
2525 opP->error = _("operand out of range");
2530 if (!issword (nextword))
2531 opP->error = _("operand out of range");
2536 addword (nextword >> 16);
2563 /* We gotta put out some float. */
2564 if (op (&opP->disp) != O_big)
2569 /* Can other cases happen here? */
2570 if (op (&opP->disp) != O_constant)
2573 val = (valueT) offs (&opP->disp);
2577 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2578 val >>= LITTLENUM_NUMBER_OF_BITS;
2582 offs (&opP->disp) = gencnt;
2584 if (offs (&opP->disp) > 0)
2586 if (offs (&opP->disp) > baseo)
2588 as_warn (_("Bignum too big for %c format; truncated"),
2590 offs (&opP->disp) = baseo;
2592 baseo -= offs (&opP->disp);
2595 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2596 offs (&opP->disp)--;
2601 gen_to_words (words, baseo, (long) outro);
2602 for (wordp = words; baseo--; wordp++)
2606 tmpreg = opP->reg - DATA; /* 0.dreg */
2609 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2612 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2615 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2618 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2622 nextword = get_num (&opP->disp, 90);
2624 /* Convert mode 5 addressing with a zero offset into
2625 mode 2 addressing to reduce the instruction size by a
2627 if (! isvar (&opP->disp)
2629 && (opP->disp.size == SIZE_UNSPEC)
2630 && (opP->reg >= ADDR0)
2631 && (opP->reg <= ADDR7))
2633 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2638 && ! isvar (&opP->disp)
2641 opP->disp.exp.X_op = O_symbol;
2642 opP->disp.exp.X_add_symbol =
2643 section_symbol (absolute_section);
2646 /* Force into index mode. Hope this works. */
2648 /* We do the first bit for 32-bit displacements, and the
2649 second bit for 16 bit ones. It is possible that we
2650 should make the default be WORD instead of LONG, but
2651 I think that'd break GCC, so we put up with a little
2652 inefficiency for the sake of working output. */
2654 if (!issword (nextword)
2655 || (isvar (&opP->disp)
2656 && ((opP->disp.size == SIZE_UNSPEC
2657 && flag_short_refs == 0
2658 && cpu_of_arch (current_architecture) >= m68020
2659 && ! arch_coldfire_p (current_architecture))
2660 || opP->disp.size == SIZE_LONG)))
2662 if (cpu_of_arch (current_architecture) < m68020
2663 || arch_coldfire_p (current_architecture))
2665 _("displacement too large for this architecture; needs 68020 or higher");
2667 tmpreg = 0x3B; /* 7.3 */
2669 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2670 if (isvar (&opP->disp))
2674 if (opP->disp.size == SIZE_LONG
2676 /* If the displacement needs pic
2677 relocation it cannot be relaxed. */
2678 || opP->disp.pic_reloc != pic_none
2683 add_fix ('l', &opP->disp, 1, 2);
2687 add_frag (adds (&opP->disp),
2688 SEXT (offs (&opP->disp)),
2689 TAB (PCREL1632, SZ_UNDEF));
2696 add_fix ('l', &opP->disp, 0, 0);
2701 addword (nextword >> 16);
2706 tmpreg = 0x3A; /* 7.2 */
2708 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2710 if (isvar (&opP->disp))
2714 add_fix ('w', &opP->disp, 1, 0);
2717 add_fix ('w', &opP->disp, 0, 0);
2727 baseo = get_num (&opP->disp, 90);
2728 if (opP->mode == POST || opP->mode == PRE)
2729 outro = get_num (&opP->odisp, 90);
2730 /* Figure out the `addressing mode'.
2731 Also turn on the BASE_DISABLE bit, if needed. */
2732 if (opP->reg == PC || opP->reg == ZPC)
2734 tmpreg = 0x3b; /* 7.3 */
2735 if (opP->reg == ZPC)
2738 else if (opP->reg == 0)
2741 tmpreg = 0x30; /* 6.garbage */
2743 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2746 tmpreg = 0x30 + opP->reg - ZADDR0;
2749 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2751 siz1 = opP->disp.size;
2752 if (opP->mode == POST || opP->mode == PRE)
2753 siz2 = opP->odisp.size;
2757 /* Index register stuff. */
2758 if (opP->index.reg != 0
2759 && opP->index.reg >= DATA
2760 && opP->index.reg <= ADDR7)
2762 nextword |= (opP->index.reg - DATA) << 12;
2764 if (opP->index.size == SIZE_LONG
2765 || (opP->index.size == SIZE_UNSPEC
2766 && m68k_index_width_default == SIZE_LONG))
2769 if ((opP->index.scale != 1
2770 && cpu_of_arch (current_architecture) < m68020)
2771 || (opP->index.scale == 8
2772 && (arch_coldfire_p (current_architecture)
2773 && !arch_coldfire_fpu (current_architecture))))
2776 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2779 if (arch_coldfire_p (current_architecture)
2780 && opP->index.size == SIZE_WORD)
2781 opP->error = _("invalid index size for coldfire");
2783 switch (opP->index.scale)
2800 GET US OUT OF HERE! */
2802 /* Must be INDEX, with an index register. Address
2803 register cannot be ZERO-PC, and either :b was
2804 forced, or we know it will fit. For a 68000 or
2805 68010, force this mode anyways, because the
2806 larger modes aren't supported. */
2807 if (opP->mode == BASE
2808 && ((opP->reg >= ADDR0
2809 && opP->reg <= ADDR7)
2812 if (siz1 == SIZE_BYTE
2813 || cpu_of_arch (current_architecture) < m68020
2814 || arch_coldfire_p (current_architecture)
2815 || (siz1 == SIZE_UNSPEC
2816 && ! isvar (&opP->disp)
2817 && issbyte (baseo)))
2819 nextword += baseo & 0xff;
2821 if (isvar (&opP->disp))
2823 /* Do a byte relocation. If it doesn't
2824 fit (possible on m68000) let the
2825 fixup processing complain later. */
2827 add_fix ('B', &opP->disp, 1, 1);
2829 add_fix ('B', &opP->disp, 0, 0);
2831 else if (siz1 != SIZE_BYTE)
2833 if (siz1 != SIZE_UNSPEC)
2834 as_warn (_("Forcing byte displacement"));
2835 if (! issbyte (baseo))
2836 opP->error = _("byte displacement out of range");
2841 else if (siz1 == SIZE_UNSPEC
2843 && isvar (&opP->disp)
2844 && subs (&opP->disp) == NULL
2846 /* If the displacement needs pic
2847 relocation it cannot be relaxed. */
2848 && opP->disp.pic_reloc == pic_none
2852 /* The code in md_convert_frag_1 needs to be
2853 able to adjust nextword. Call frag_grow
2854 to ensure that we have enough space in
2855 the frag obstack to make all the bytes
2858 nextword += baseo & 0xff;
2860 add_frag (adds (&opP->disp),
2861 SEXT (offs (&opP->disp)),
2862 TAB (PCINDEX, SZ_UNDEF));
2870 nextword |= 0x40; /* No index reg. */
2871 if (opP->index.reg >= ZDATA0
2872 && opP->index.reg <= ZDATA7)
2873 nextword |= (opP->index.reg - ZDATA0) << 12;
2874 else if (opP->index.reg >= ZADDR0
2875 || opP->index.reg <= ZADDR7)
2876 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2879 /* It isn't simple. */
2881 if (cpu_of_arch (current_architecture) < m68020
2882 || arch_coldfire_p (current_architecture))
2884 _("invalid operand mode for this architecture; needs 68020 or higher");
2887 /* If the guy specified a width, we assume that it is
2888 wide enough. Maybe it isn't. If so, we lose. */
2892 if (isvar (&opP->disp)
2894 : ! issword (baseo))
2899 else if (! isvar (&opP->disp) && baseo == 0)
2908 as_warn (_(":b not permitted; defaulting to :w"));
2918 /* Figure out inner displacement stuff. */
2919 if (opP->mode == POST || opP->mode == PRE)
2921 if (cpu_of_arch (current_architecture) & cpu32)
2922 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2926 if (isvar (&opP->odisp)
2928 : ! issword (outro))
2933 else if (! isvar (&opP->odisp) && outro == 0)
2942 as_warn (_(":b not permitted; defaulting to :w"));
2951 if (opP->mode == POST
2952 && (nextword & 0x40) == 0)
2957 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2959 if (opP->reg == PC || opP->reg == ZPC)
2960 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2962 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2964 if (siz1 == SIZE_LONG)
2965 addword (baseo >> 16);
2966 if (siz1 != SIZE_UNSPEC)
2969 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2970 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2971 if (siz2 == SIZE_LONG)
2972 addword (outro >> 16);
2973 if (siz2 != SIZE_UNSPEC)
2979 nextword = get_num (&opP->disp, 90);
2980 switch (opP->disp.size)
2985 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2987 tmpreg = 0x38; /* 7.0 */
2991 if (isvar (&opP->disp)
2992 && !subs (&opP->disp)
2993 && adds (&opP->disp)
2995 /* If the displacement needs pic relocation it
2996 cannot be relaxed. */
2997 && opP->disp.pic_reloc == pic_none
3000 && !strchr ("~%&$?", s[0]))
3002 tmpreg = 0x3A; /* 7.2 */
3003 add_frag (adds (&opP->disp),
3004 SEXT (offs (&opP->disp)),
3005 TAB (ABSTOPCREL, SZ_UNDEF));
3008 /* Fall through into long. */
3010 if (isvar (&opP->disp))
3011 add_fix ('l', &opP->disp, 0, 0);
3013 tmpreg = 0x39;/* 7.1 mode */
3014 addword (nextword >> 16);
3019 as_bad (_("unsupported byte value; use a different suffix"));
3023 if (isvar (&opP->disp))
3024 add_fix ('w', &opP->disp, 0, 0);
3026 tmpreg = 0x38;/* 7.0 mode */
3034 as_bad (_("unknown/incorrect operand"));
3038 /* If s[0] is '4', then this is for the mac instructions
3039 that can have a trailing_ampersand set. If so, set 0x100
3040 bit on tmpreg so install_gen_operand can check for it and
3041 set the appropriate bit (word2, bit 5). */
3044 if (opP->trailing_ampersand)
3047 install_gen_operand (s[1], tmpreg);
3053 { /* JF: I hate floating point! */
3068 tmpreg = get_num (&opP->disp, tmpreg);
3069 if (isvar (&opP->disp))
3070 add_fix (s[1], &opP->disp, 0, 0);
3073 case 'b': /* Danger: These do no check for
3074 certain types of overflow.
3076 if (!isbyte (tmpreg))
3077 opP->error = _("out of range");
3078 insop (tmpreg, opcode);
3079 if (isvar (&opP->disp))
3080 the_ins.reloc[the_ins.nrel - 1].n =
3081 (opcode->m_codenum) * 2 + 1;
3084 if (!issbyte (tmpreg))
3085 opP->error = _("out of range");
3086 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
3087 if (isvar (&opP->disp))
3088 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
3091 if (!isword (tmpreg))
3092 opP->error = _("out of range");
3093 insop (tmpreg, opcode);
3094 if (isvar (&opP->disp))
3095 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
3098 if (!issword (tmpreg))
3099 opP->error = _("out of range");
3100 insop (tmpreg, opcode);
3101 if (isvar (&opP->disp))
3102 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
3105 /* Because of the way insop works, we put these two out
3107 insop (tmpreg, opcode);
3108 insop (tmpreg >> 16, opcode);
3109 if (isvar (&opP->disp))
3110 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
3117 install_operand (s[1], tmpreg);
3128 install_operand (s[1], opP->reg - ADDR);
3132 tmpreg = get_num (&opP->disp, 90);
3137 add_fix ('B', &opP->disp, 1, -1);
3140 add_fix ('w', &opP->disp, 1, 0);
3145 the_ins.opcode[0] |= 0xff;
3146 add_fix ('l', &opP->disp, 1, 0);
3150 case 'g': /* Conditional branch */
3151 have_disp = HAVE_LONG_CALL (current_architecture);
3154 case 'b': /* Unconditional branch */
3155 have_disp = HAVE_LONG_BRANCH (current_architecture);
3156 use_pl = LONG_BRANCH_VIA_COND (current_architecture);
3159 case 's': /* Unconditional subroutine */
3160 have_disp = HAVE_LONG_CALL (current_architecture);
3163 if (subs (&opP->disp) /* We can't relax it. */
3165 /* If the displacement needs pic relocation it cannot be
3167 || opP->disp.pic_reloc != pic_none
3172 as_warn (_("Can't use long branches on this architecture"));
3176 /* This could either be a symbol, or an absolute
3177 address. If it's an absolute address, turn it into
3178 an absolute jump right here and keep it out of the
3180 if (adds (&opP->disp) == 0)
3182 if (the_ins.opcode[0] == 0x6000) /* jbra */
3183 the_ins.opcode[0] = 0x4EF9;
3184 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
3185 the_ins.opcode[0] = 0x4EB9;
3188 the_ins.opcode[0] ^= 0x0100;
3189 the_ins.opcode[0] |= 0x0006;
3192 add_fix ('l', &opP->disp, 0, 0);
3198 /* Now we know it's going into the relaxer. Now figure
3199 out which mode. We try in this order of preference:
3200 long branch, absolute jump, byte/word branches only. */
3202 add_frag (adds (&opP->disp),
3203 SEXT (offs (&opP->disp)),
3204 TAB (BRANCHBWL, SZ_UNDEF));
3205 else if (! flag_keep_pcrel)
3207 if ((the_ins.opcode[0] == 0x6000)
3208 || (the_ins.opcode[0] == 0x6100))
3209 add_frag (adds (&opP->disp),
3210 SEXT (offs (&opP->disp)),
3211 TAB (BRABSJUNC, SZ_UNDEF));
3213 add_frag (adds (&opP->disp),
3214 SEXT (offs (&opP->disp)),
3215 TAB (BRABSJCOND, SZ_UNDEF));
3218 add_frag (adds (&opP->disp),
3219 SEXT (offs (&opP->disp)),
3220 (use_pl ? TAB (BRANCHBWPL, SZ_UNDEF)
3221 : TAB (BRANCHBW, SZ_UNDEF)));
3224 if (isvar (&opP->disp))
3226 /* Check for DBcc instructions. We can relax them,
3227 but only if we have long branches and/or absolute
3229 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
3230 && (HAVE_LONG_BRANCH (current_architecture)
3231 || ! flag_keep_pcrel))
3233 if (HAVE_LONG_BRANCH (current_architecture))
3234 add_frag (adds (&opP->disp),
3235 SEXT (offs (&opP->disp)),
3236 TAB (DBCCLBR, SZ_UNDEF));
3238 add_frag (adds (&opP->disp),
3239 SEXT (offs (&opP->disp)),
3240 TAB (DBCCABSJ, SZ_UNDEF));
3243 add_fix ('w', &opP->disp, 1, 0);
3247 case 'C': /* Fixed size LONG coproc branches. */
3248 add_fix ('l', &opP->disp, 1, 0);
3252 case 'c': /* Var size Coprocesssor branches. */
3253 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
3255 the_ins.opcode[the_ins.numo - 1] |= 0x40;
3256 add_fix ('l', &opP->disp, 1, 0);
3261 add_frag (adds (&opP->disp),
3262 SEXT (offs (&opP->disp)),
3263 TAB (FBRANCH, SZ_UNDEF));
3270 case 'C': /* Ignore it. */
3273 case 'd': /* JF this is a kludge. */
3274 install_operand ('s', opP->reg - ADDR);
3275 tmpreg = get_num (&opP->disp, 90);
3276 if (!issword (tmpreg))
3278 as_warn (_("Expression out of range, using 0"));
3285 install_operand (s[1], opP->reg - DATA);
3288 case 'e': /* EMAC ACCx, reg/reg. */
3289 install_operand (s[1], opP->reg - ACC);
3292 case 'E': /* Ignore it. */
3296 install_operand (s[1], opP->reg - FP0);
3299 case 'g': /* EMAC ACCEXTx. */
3300 install_operand (s[1], opP->reg - ACCEXT01);
3303 case 'G': /* Ignore it. */
3308 tmpreg = opP->reg - COP0;
3309 install_operand (s[1], tmpreg);
3312 case 'i': /* MAC/EMAC scale factor. */
3313 install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
3316 case 'J': /* JF foo. */
3359 tmpreg = 0x00c + (opP->reg - ACR4);
3466 install_operand (s[1], tmpreg);
3470 tmpreg = get_num (&opP->disp, 55);
3471 install_operand (s[1], tmpreg & 0x7f);
3478 if (tmpreg & 0x7FF0000)
3479 as_bad (_("Floating point register in register list"));
3480 insop (reverse_16_bits (tmpreg), opcode);
3484 if (tmpreg & 0x700FFFF)
3485 as_bad (_("Wrong register in floating-point reglist"));
3486 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
3494 if (tmpreg & 0x7FF0000)
3495 as_bad (_("Floating point register in register list"));
3496 insop (tmpreg, opcode);
3498 else if (s[1] == '8')
3500 if (tmpreg & 0x0FFFFFF)
3501 as_bad (_("incorrect register in reglist"));
3502 install_operand (s[1], tmpreg >> 24);
3506 if (tmpreg & 0x700FFFF)
3507 as_bad (_("wrong register in floating-point reglist"));
3509 install_operand (s[1], tmpreg >> 16);
3514 install_operand (s[1], get_num (&opP->disp, 60));
3518 tmpreg = ((opP->mode == DREG)
3519 ? 0x20 + (int) (opP->reg - DATA)
3520 : (get_num (&opP->disp, 40) & 0x1F));
3521 install_operand (s[1], tmpreg);
3525 tmpreg = get_num (&opP->disp, 10);
3528 install_operand (s[1], tmpreg);
3532 /* This depends on the fact that ADDR registers are eight
3533 more than their corresponding DATA regs, so the result
3534 will have the ADDR_REG bit set. */
3535 install_operand (s[1], opP->reg - DATA);
3539 if (opP->mode == AINDR)
3540 install_operand (s[1], opP->reg - DATA);
3542 install_operand (s[1], opP->index.reg - DATA);
3546 if (opP->reg == FPI)
3548 else if (opP->reg == FPS)
3550 else if (opP->reg == FPC)
3554 install_operand (s[1], tmpreg);
3557 case 'S': /* Ignore it. */
3561 install_operand (s[1], get_num (&opP->disp, 30));
3564 case 'U': /* Ignore it. */
3583 as_fatal (_("failed sanity check"));
3584 } /* switch on cache token. */
3585 install_operand (s[1], tmpreg);
3588 /* JF: These are out of order, I fear. */
3601 install_operand (s[1], tmpreg);
3627 install_operand (s[1], tmpreg);
3631 if (opP->reg == VAL)
3650 install_operand (s[1], tmpreg);
3664 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
3675 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
3681 install_operand (s[1], tmpreg);
3684 know (opP->reg == PSR);
3687 know (opP->reg == PCSR);
3702 install_operand (s[1], tmpreg);
3705 tmpreg = get_num (&opP->disp, 20);
3706 install_operand (s[1], tmpreg);
3708 case '_': /* used only for move16 absolute 32-bit address. */
3709 if (isvar (&opP->disp))
3710 add_fix ('l', &opP->disp, 0, 0);
3711 tmpreg = get_num (&opP->disp, 90);
3712 addword (tmpreg >> 16);
3713 addword (tmpreg & 0xFFFF);
3716 install_operand (s[1], opP->reg - DATA0L);
3717 opP->reg -= (DATA0L);
3718 opP->reg &= 0x0F; /* remove upper/lower bit. */
3721 tmpreg = get_num (&opP->disp, 80);
3724 install_operand (s[1], tmpreg);
3727 tmpreg = get_num (&opP->disp, 10);
3728 install_operand (s[1], tmpreg - 1);
3731 tmpreg = get_num (&opP->disp, 65);
3732 install_operand (s[1], tmpreg);
3739 /* By the time whe get here (FINALLY) the_ins contains the complete
3740 instruction, ready to be emitted. . . */
3744 reverse_16_bits (int in)
3749 static int mask[16] =
3751 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3752 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3754 for (n = 0; n < 16; n++)
3757 out |= mask[15 - n];
3760 } /* reverse_16_bits() */
3763 reverse_8_bits (int in)
3768 static int mask[8] =
3770 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3773 for (n = 0; n < 8; n++)
3779 } /* reverse_8_bits() */
3781 /* Cause an extra frag to be generated here, inserting up to
3782 FRAG_VAR_SIZE bytes. TYPE is the subtype of the frag to be
3783 generated; its primary type is rs_machine_dependent.
3785 The TYPE parameter is also used by md_convert_frag_1 and
3786 md_estimate_size_before_relax. The appropriate type of fixup will
3787 be emitted by md_convert_frag_1.
3789 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3791 install_operand (int mode, int val)
3796 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
3799 the_ins.opcode[0] |= val << 9;
3802 the_ins.opcode[1] |= val << 9;
3805 the_ins.opcode[1] |= val << 12;
3808 the_ins.opcode[1] |= val << 6;
3811 the_ins.opcode[1] |= val;
3814 the_ins.opcode[2] |= val << 12;
3817 the_ins.opcode[2] |= val << 6;
3820 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3821 three words long! */
3823 the_ins.opcode[2] |= val;
3826 the_ins.opcode[1] |= val << 7;
3829 the_ins.opcode[1] |= val << 10;
3833 the_ins.opcode[1] |= val << 5;
3838 the_ins.opcode[1] |= (val << 10) | (val << 7);
3841 the_ins.opcode[1] |= (val << 12) | val;
3844 the_ins.opcode[0] |= val = 0xff;
3847 the_ins.opcode[0] |= val << 9;
3850 the_ins.opcode[1] |= val;
3853 the_ins.opcode[1] |= val;
3854 the_ins.numo++; /* What a hack. */
3857 the_ins.opcode[1] |= val << 4;
3865 the_ins.opcode[0] |= (val << 6);
3868 the_ins.opcode[1] = (val >> 16);
3869 the_ins.opcode[2] = val & 0xffff;
3872 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3873 the_ins.opcode[0] |= ((val & 0x7) << 9);
3874 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3876 case 'n': /* MAC/EMAC Rx on !load. */
3877 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3878 the_ins.opcode[0] |= ((val & 0x7) << 9);
3879 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3881 case 'o': /* MAC/EMAC Rx on load. */
3882 the_ins.opcode[1] |= val << 12;
3883 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3885 case 'M': /* MAC/EMAC Ry on !load. */
3886 the_ins.opcode[0] |= (val & 0xF);
3887 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3889 case 'N': /* MAC/EMAC Ry on load. */
3890 the_ins.opcode[1] |= (val & 0xF);
3891 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3894 the_ins.opcode[1] |= ((val != 1) << 10);
3897 the_ins.opcode[0] |= ((val & 0x3) << 9);
3900 the_ins.opcode[0] |= ((val & 0x3) << 0);
3902 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3903 the_ins.opcode[0] |= ((~val & 0x1) << 7);
3904 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3906 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3907 the_ins.opcode[0] |= ((val & 0x1) << 7);
3908 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3911 the_ins.opcode[1] |= ((val & 0x3) << 9);
3914 the_ins.opcode[0] |= (val & 0x1) <<10;
3918 as_fatal (_("failed sanity check."));
3923 install_gen_operand (int mode, int val)
3927 case '/': /* Special for mask loads for mac/msac insns with
3928 possible mask; trailing_ampersend set in bit 8. */
3929 the_ins.opcode[0] |= (val & 0x3f);
3930 the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
3933 the_ins.opcode[0] |= val;
3936 /* This is a kludge!!! */
3937 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3946 the_ins.opcode[0] |= val;
3948 /* more stuff goes here. */
3950 as_fatal (_("failed sanity check."));
3954 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3955 then deal with the bitfield hack. */
3958 crack_operand (char *str, struct m68k_op *opP)
3960 register int parens;
3962 register char *beg_str;
3970 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3976 else if (*str == ')')
3980 opP->error = _("Extra )");
3986 if (flag_mri && *str == '\'')
3987 inquote = ! inquote;
3989 if (!*str && parens)
3991 opP->error = _("Missing )");
3996 if (m68k_ip_op (beg_str, opP) != 0)
4003 c = *++str; /* JF bitfield hack. */
4008 as_bad (_("Missing operand"));
4011 /* Detect MRI REG symbols and convert them to REGLSTs. */
4012 if (opP->mode == CONTROL && (int)opP->reg < 0)
4015 opP->mask = ~(int)opP->reg;
4022 /* This is the guts of the machine-dependent assembler. STR points to a
4023 machine dependent instruction. This function is supposed to emit
4024 the frags/bytes it assembles to.
4028 insert_reg (const char *regname, int regnum)
4033 #ifdef REGISTER_PREFIX
4034 if (!flag_reg_prefix_optional)
4036 buf[0] = REGISTER_PREFIX;
4037 strcpy (buf + 1, regname);
4042 symbol_table_insert (symbol_new (regname, reg_section, regnum,
4043 &zero_address_frag));
4045 for (i = 0; regname[i]; i++)
4046 buf[i] = TOUPPER (regname[i]);
4049 symbol_table_insert (symbol_new (buf, reg_section, regnum,
4050 &zero_address_frag));
4059 static const struct init_entry init_table[] =
4119 { "accext01", ACCEXT01 },
4120 { "accext23", ACCEXT23 },
4124 /* Control registers. */
4125 { "sfc", SFC }, /* Source Function Code. */
4127 { "dfc", DFC }, /* Destination Function Code. */
4129 { "cacr", CACR }, /* Cache Control Register. */
4130 { "caar", CAAR }, /* Cache Address Register. */
4131 { "cpucr", CPUCR }, /* CPU Control Register. */
4133 { "usp", USP }, /* User Stack Pointer. */
4134 { "vbr", VBR }, /* Vector Base Register. */
4135 { "msp", MSP }, /* Master Stack Pointer. */
4136 { "isp", ISP }, /* Interrupt Stack Pointer. */
4138 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
4139 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
4140 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
4141 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
4143 /* 68ec040 versions of same */
4144 { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
4145 { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
4146 { "dacr0", DTT0 }, /* Data Access Control Register 0. */
4147 { "dacr1", DTT1 }, /* Data Access Control Register 0. */
4149 /* Coldfire versions of same. The ColdFire programmer's reference
4150 manual indicated that the order is 2,3,0,1, but Ken Rose
4151 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
4152 { "acr0", ACR0 }, /* Access Control Unit 0. */
4153 { "acr1", ACR1 }, /* Access Control Unit 1. */
4154 { "acr2", ACR2 }, /* Access Control Unit 2. */
4155 { "acr3", ACR3 }, /* Access Control Unit 3. */
4156 { "acr4", ACR4 }, /* Access Control Unit 4. */
4157 { "acr5", ACR5 }, /* Access Control Unit 5. */
4158 { "acr6", ACR6 }, /* Access Control Unit 6. */
4159 { "acr7", ACR7 }, /* Access Control Unit 7. */
4161 { "tc", TC }, /* MMU Translation Control Register. */
4165 { "mmusr", MMUSR }, /* MMU Status Register. */
4166 { "srp", SRP }, /* User Root Pointer. */
4167 { "urp", URP }, /* Supervisor Root Pointer. */
4170 { "mmubar", MMUBAR },
4173 { "rombar", ROMBAR }, /* ROM Base Address Register. */
4174 { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
4175 { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
4176 { "mbar", MBAR }, /* Module Base Address Register. */
4178 { "mbar0", MBAR0 }, /* mcfv4e registers. */
4179 { "mbar1", MBAR1 }, /* mcfv4e registers. */
4180 { "rombar0", ROMBAR0 }, /* mcfv4e registers. */
4181 { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
4182 { "mpcr", MPCR }, /* mcfv4e registers. */
4183 { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
4184 { "secmbar", SECMBAR }, /* mcfv4e registers. */
4185 { "asid", TC }, /* mcfv4e registers. */
4186 { "mmubar", BUSCR }, /* mcfv4e registers. */
4187 { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
4188 { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
4189 { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
4190 { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
4191 { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
4192 { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
4193 { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
4194 { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
4195 { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
4196 { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
4197 { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
4198 { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
4200 { "flashbar", FLASHBAR }, /* mcf528x registers. */
4201 { "rambar", RAMBAR }, /* mcf528x registers. */
4203 { "mbar2", MBAR2 }, /* mcf5249 registers. */
4205 { "rgpiobar", RGPIOBAR }, /* mcf54418 registers. */
4207 { "cac", CAC }, /* fido registers. */
4208 { "mbb", MBO }, /* fido registers (obsolete). */
4209 { "mbo", MBO }, /* fido registers. */
4210 /* End of control registers. */
4244 /* 68ec030 versions of same. */
4247 /* 68ec030 access control unit, identical to 030 MMU status reg. */
4250 /* Suppressed data and address registers. */
4268 /* Upper and lower data and address registers, used by macw and msacw. */
4309 init_regtable (void)
4312 for (i = 0; init_table[i].name; i++)
4313 insert_reg (init_table[i].name, init_table[i].number);
4317 md_assemble (char *str)
4324 int shorts_this_frag;
4327 if (!selected_cpu && !selected_arch)
4329 /* We've not selected an architecture yet. Set the default
4330 now. We do this lazily so that an initial .cpu or .arch directive
4332 if (!m68k_set_cpu (TARGET_CPU, 1, 1))
4333 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU);
4338 /* In MRI mode, the instruction and operands are separated by a
4339 space. Anything following the operands is a comment. The label
4340 has already been removed. */
4348 for (s = str; *s != '\0'; s++)
4350 if ((*s == ' ' || *s == '\t') && ! inquote)
4368 inquote = ! inquote;
4373 memset (&the_ins, '\0', sizeof (the_ins));
4378 for (n = 0; n < the_ins.numargs; n++)
4379 if (the_ins.operands[n].error)
4381 er = the_ins.operands[n].error;
4387 as_bad (_("%s -- statement `%s' ignored"), er, str);
4391 /* If there is a current label, record that it marks an instruction. */
4392 if (current_label != NULL)
4394 current_label->text = 1;
4395 current_label = NULL;
4399 /* Tie dwarf2 debug info to the address at the start of the insn. */
4400 dwarf2_emit_insn (0);
4403 if (the_ins.nfrag == 0)
4405 /* No frag hacking involved; just put it out. */
4406 toP = frag_more (2 * the_ins.numo);
4407 fromP = &the_ins.opcode[0];
4408 for (m = the_ins.numo; m; --m)
4410 md_number_to_chars (toP, (long) (*fromP), 2);
4414 /* Put out symbol-dependent info. */
4415 for (m = 0; m < the_ins.nrel; m++)
4417 switch (the_ins.reloc[m].wid)
4436 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4437 the_ins.reloc[m].wid);
4440 fixP = fix_new_exp (frag_now,
4441 ((toP - frag_now->fr_literal)
4442 - the_ins.numo * 2 + the_ins.reloc[m].n),
4444 &the_ins.reloc[m].exp,
4445 the_ins.reloc[m].pcrel,
4446 get_reloc_code (n, the_ins.reloc[m].pcrel,
4447 the_ins.reloc[m].pic_reloc));
4448 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4449 if (the_ins.reloc[m].wid == 'B')
4450 fixP->fx_signed = 1;
4455 /* There's some frag hacking. */
4457 /* Calculate the max frag size. */
4460 wid = 2 * the_ins.fragb[0].fragoff;
4461 for (n = 1; n < the_ins.nfrag; n++)
4462 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4463 /* frag_var part. */
4464 wid += FRAG_VAR_SIZE;
4465 /* Make sure the whole insn fits in one chunk, in particular that
4466 the var part is attached, as we access one byte before the
4467 variable frag for byte branches. */
4471 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
4476 wid = 2 * the_ins.fragb[n].fragoff;
4478 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4479 toP = frag_more (wid);
4481 shorts_this_frag = 0;
4482 for (m = wid / 2; m; --m)
4484 md_number_to_chars (toP, (long) (*fromP), 2);
4489 for (m = 0; m < the_ins.nrel; m++)
4491 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
4493 the_ins.reloc[m].n -= 2 * shorts_this_frag;
4496 wid = the_ins.reloc[m].wid;
4499 the_ins.reloc[m].wid = 0;
4500 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4502 fixP = fix_new_exp (frag_now,
4503 ((toP - frag_now->fr_literal)
4504 - the_ins.numo * 2 + the_ins.reloc[m].n),
4506 &the_ins.reloc[m].exp,
4507 the_ins.reloc[m].pcrel,
4508 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4509 the_ins.reloc[m].pic_reloc));
4510 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4512 (void) frag_var (rs_machine_dependent, FRAG_VAR_SIZE, 0,
4513 (relax_substateT) (the_ins.fragb[n].fragty),
4514 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
4516 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4517 shorts_this_frag = 0;
4520 toP = frag_more (n * 2);
4523 md_number_to_chars (toP, (long) (*fromP), 2);
4529 for (m = 0; m < the_ins.nrel; m++)
4533 wid = the_ins.reloc[m].wid;
4536 the_ins.reloc[m].wid = 0;
4537 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4539 fixP = fix_new_exp (frag_now,
4540 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
4541 - shorts_this_frag * 2),
4543 &the_ins.reloc[m].exp,
4544 the_ins.reloc[m].pcrel,
4545 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4546 the_ins.reloc[m].pic_reloc));
4547 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4551 /* Comparison function used by qsort to rank the opcode entries by name. */
4554 m68k_compare_opcode (const void * v1, const void * v2)
4556 struct m68k_opcode * op1, * op2;
4562 op1 = *(struct m68k_opcode **) v1;
4563 op2 = *(struct m68k_opcode **) v2;
4565 /* Compare the two names. If different, return the comparison.
4566 If the same, return the order they are in the opcode table. */
4567 ret = strcmp (op1->name, op2->name);
4578 const struct m68k_opcode *ins;
4579 struct m68k_incant *hack, *slak;
4580 const char *retval = 0; /* Empty string, or error msg text. */
4583 /* Set up hash tables with 68000 instructions.
4584 similar to what the vax assembler does. */
4585 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4586 a copy of it at runtime, adding in the information we want but isn't
4587 there. I think it'd be better to have an awk script hack the table
4588 at compile time. Or even just xstr the table and use it as-is. But
4589 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4594 flag_reg_prefix_optional = 1;
4596 if (! m68k_rel32_from_cmdline)
4600 /* First sort the opcode table into alphabetical order to seperate
4601 the order that the assembler wants to see the opcodes from the
4602 order that the disassembler wants to see them. */
4603 m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4604 if (!m68k_sorted_opcodes)
4605 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4606 m68k_numopcodes * ((int) sizeof (* m68k_sorted_opcodes)));
4608 for (i = m68k_numopcodes; i--;)
4609 m68k_sorted_opcodes[i] = m68k_opcodes + i;
4611 qsort (m68k_sorted_opcodes, m68k_numopcodes,
4612 sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
4614 op_hash = hash_new ();
4616 obstack_begin (&robyn, 4000);
4617 for (i = 0; i < m68k_numopcodes; i++)
4619 hack = slak = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4622 ins = m68k_sorted_opcodes[i];
4624 /* We must enter all insns into the table, because .arch and
4625 .cpu directives can change things. */
4626 slak->m_operands = ins->args;
4627 slak->m_arch = ins->arch;
4628 slak->m_opcode = ins->opcode;
4630 /* In most cases we can determine the number of opcode words
4631 by checking the second word of the mask. Unfortunately
4632 some instructions have 2 opcode words, but no fixed bits
4633 in the second word. A leading dot in the operands
4634 string also indicates 2 opcodes. */
4635 if (*slak->m_operands == '.')
4638 slak->m_codenum = 2;
4640 else if (ins->match & 0xffffL)
4641 slak->m_codenum = 2;
4643 slak->m_codenum = 1;
4644 slak->m_opnum = strlen (slak->m_operands) / 2;
4646 if (i + 1 != m68k_numopcodes
4647 && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
4649 slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4654 slak = slak->m_next;
4658 retval = hash_insert (op_hash, ins->name, (char *) hack);
4660 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
4663 for (i = 0; i < m68k_numaliases; i++)
4665 const char *name = m68k_opcode_aliases[i].primary;
4666 const char *alias = m68k_opcode_aliases[i].alias;
4667 void *val = hash_find (op_hash, name);
4670 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4671 retval = hash_insert (op_hash, alias, val);
4673 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4676 /* In MRI mode, all unsized branches are variable sized. Normally,
4677 they are word sized. */
4680 static struct m68k_opcode_alias mri_aliases[] =
4701 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
4704 const char *name = mri_aliases[i].primary;
4705 const char *alias = mri_aliases[i].alias;
4706 void *val = hash_find (op_hash, name);
4709 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4710 retval = hash_jam (op_hash, alias, val);
4712 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4716 for (i = 0; i < (int) sizeof (notend_table); i++)
4718 notend_table[i] = 0;
4719 alt_notend_table[i] = 0;
4722 notend_table[','] = 1;
4723 notend_table['{'] = 1;
4724 notend_table['}'] = 1;
4725 alt_notend_table['a'] = 1;
4726 alt_notend_table['A'] = 1;
4727 alt_notend_table['d'] = 1;
4728 alt_notend_table['D'] = 1;
4729 alt_notend_table['#'] = 1;
4730 alt_notend_table['&'] = 1;
4731 alt_notend_table['f'] = 1;
4732 alt_notend_table['F'] = 1;
4733 #ifdef REGISTER_PREFIX
4734 alt_notend_table[REGISTER_PREFIX] = 1;
4737 /* We need to put '(' in alt_notend_table to handle
4738 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4739 alt_notend_table['('] = 1;
4741 /* We need to put '@' in alt_notend_table to handle
4742 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4743 alt_notend_table['@'] = 1;
4745 /* We need to put digits in alt_notend_table to handle
4746 bfextu %d0{24:1},%d0 */
4747 alt_notend_table['0'] = 1;
4748 alt_notend_table['1'] = 1;
4749 alt_notend_table['2'] = 1;
4750 alt_notend_table['3'] = 1;
4751 alt_notend_table['4'] = 1;
4752 alt_notend_table['5'] = 1;
4753 alt_notend_table['6'] = 1;
4754 alt_notend_table['7'] = 1;
4755 alt_notend_table['8'] = 1;
4756 alt_notend_table['9'] = 1;
4758 #ifndef MIT_SYNTAX_ONLY
4759 /* Insert pseudo ops, these have to go into the opcode table since
4760 gas expects pseudo ops to start with a dot. */
4764 while (mote_pseudo_table[n].poc_name)
4766 hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4767 hash_insert (op_hash,
4768 mote_pseudo_table[n].poc_name, (char *) hack);
4769 hack->m_operands = 0;
4779 record_alignment (text_section, 2);
4780 record_alignment (data_section, 2);
4781 record_alignment (bss_section, 2);
4786 /* This is called when a label is defined. */
4789 m68k_frob_label (symbolS *sym)
4791 struct label_line *n;
4793 n = (struct label_line *) xmalloc (sizeof *n);
4796 as_where (&n->file, &n->line);
4802 dwarf2_emit_label (sym);
4806 /* This is called when a value that is not an instruction is emitted. */
4809 m68k_flush_pending_output (void)
4811 current_label = NULL;
4814 /* This is called at the end of the assembly, when the final value of
4815 the label is known. We warn if this is a text symbol aligned at an
4819 m68k_frob_symbol (symbolS *sym)
4821 if (S_GET_SEGMENT (sym) == reg_section
4822 && (int) S_GET_VALUE (sym) < 0)
4824 S_SET_SEGMENT (sym, absolute_section);
4825 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4827 else if ((S_GET_VALUE (sym) & 1) != 0)
4829 struct label_line *l;
4831 for (l = labels; l != NULL; l = l->next)
4833 if (l->label == sym)
4836 as_warn_where (l->file, l->line,
4837 _("text label `%s' aligned to odd boundary"),
4845 /* This is called if we go in or out of MRI mode because of the .mri
4849 m68k_mri_mode_change (int on)
4853 if (! flag_reg_prefix_optional)
4855 flag_reg_prefix_optional = 1;
4856 #ifdef REGISTER_PREFIX
4861 if (! m68k_rel32_from_cmdline)
4866 if (! reg_prefix_optional_seen)
4868 #ifdef REGISTER_PREFIX_OPTIONAL
4869 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4871 flag_reg_prefix_optional = 0;
4873 #ifdef REGISTER_PREFIX
4878 if (! m68k_rel32_from_cmdline)
4884 md_atof (int type, char *litP, int *sizeP)
4886 return ieee_md_atof (type, litP, sizeP, TRUE);
4890 md_number_to_chars (char *buf, valueT val, int n)
4892 number_to_chars_bigendian (buf, val, n);
4896 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
4898 offsetT val = *valP;
4899 addressT upper_limit;
4900 offsetT lower_limit;
4902 /* This is unnecessary but it convinces the native rs6000 compiler
4903 to generate the code we want. */
4904 char *buf = fixP->fx_frag->fr_literal;
4905 buf += fixP->fx_where;
4906 /* End ibm compiler workaround. */
4910 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
4916 memset (buf, 0, fixP->fx_size);
4917 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4919 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4920 && !S_IS_DEFINED (fixP->fx_addsy)
4921 && !S_IS_WEAK (fixP->fx_addsy))
4922 S_SET_WEAK (fixP->fx_addsy);
4924 switch (fixP->fx_r_type)
4926 case BFD_RELOC_68K_TLS_GD32:
4927 case BFD_RELOC_68K_TLS_GD16:
4928 case BFD_RELOC_68K_TLS_GD8:
4929 case BFD_RELOC_68K_TLS_LDM32:
4930 case BFD_RELOC_68K_TLS_LDM16:
4931 case BFD_RELOC_68K_TLS_LDM8:
4932 case BFD_RELOC_68K_TLS_LDO32:
4933 case BFD_RELOC_68K_TLS_LDO16:
4934 case BFD_RELOC_68K_TLS_LDO8:
4935 case BFD_RELOC_68K_TLS_IE32:
4936 case BFD_RELOC_68K_TLS_IE16:
4937 case BFD_RELOC_68K_TLS_IE8:
4938 case BFD_RELOC_68K_TLS_LE32:
4939 case BFD_RELOC_68K_TLS_LE16:
4940 case BFD_RELOC_68K_TLS_LE8:
4941 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4950 #elif defined(OBJ_AOUT)
4951 /* PR gas/3041 Do not fix frags referencing a weak symbol. */
4952 if (fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy))
4954 memset (buf, 0, fixP->fx_size);
4955 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4960 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4961 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4964 switch (fixP->fx_size)
4966 /* The cast to offsetT below are necessary to make code
4967 correct for machines where ints are smaller than offsetT. */
4971 lower_limit = - (offsetT) 0x80;
4974 *buf++ = (val >> 8);
4976 upper_limit = 0x7fff;
4977 lower_limit = - (offsetT) 0x8000;
4980 *buf++ = (val >> 24);
4981 *buf++ = (val >> 16);
4982 *buf++ = (val >> 8);
4984 upper_limit = 0x7fffffff;
4985 lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
4988 BAD_CASE (fixP->fx_size);
4991 /* Fix up a negative reloc. */
4992 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4994 fixP->fx_addsy = fixP->fx_subsy;
4995 fixP->fx_subsy = NULL;
4999 /* For non-pc-relative values, it's conceivable we might get something
5000 like "0xff" for a byte field. So extend the upper part of the range
5001 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
5002 so that we can do any range checking at all. */
5003 if (! fixP->fx_pcrel && ! fixP->fx_signed)
5004 upper_limit = upper_limit * 2 + 1;
5006 if ((addressT) val > upper_limit
5007 && (val > 0 || val < lower_limit))
5008 as_bad_where (fixP->fx_file, fixP->fx_line,
5009 _("value %ld out of range"), (long)val);
5011 /* A one byte PC-relative reloc means a short branch. We can't use
5012 a short branch with a value of 0 or -1, because those indicate
5013 different opcodes (branches with longer offsets). fixup_segment
5014 in write.c may have clobbered fx_pcrel, so we need to examine the
5017 || fixP->fx_r_type == BFD_RELOC_8_PCREL)
5018 && fixP->fx_size == 1
5019 && (fixP->fx_addsy == NULL
5020 || S_IS_DEFINED (fixP->fx_addsy))
5021 && (val == 0 || val == -1))
5022 as_bad_where (fixP->fx_file, fixP->fx_line,
5023 _("invalid byte branch offset"));
5026 /* *fragP has been relaxed to its final size, and now needs to have
5027 the bytes inside it modified to conform to the new size There is UGLY
5031 md_convert_frag_1 (fragS *fragP)
5036 /* Address in object code of the displacement. */
5037 register int object_address = fragP->fr_fix + fragP->fr_address;
5039 /* Address in gas core of the place to store the displacement. */
5040 /* This convinces the native rs6000 compiler to generate the code we
5042 register char *buffer_address = fragP->fr_literal;
5043 buffer_address += fragP->fr_fix;
5044 /* End ibm compiler workaround. */
5046 /* The displacement of the address, from current location. */
5047 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
5048 disp = (disp + fragP->fr_offset) - object_address;
5050 switch (fragP->fr_subtype)
5052 case TAB (BRANCHBWL, BYTE):
5053 case TAB (BRABSJUNC, BYTE):
5054 case TAB (BRABSJCOND, BYTE):
5055 case TAB (BRANCHBW, BYTE):
5056 case TAB (BRANCHBWPL, BYTE):
5057 know (issbyte (disp));
5059 as_bad_where (fragP->fr_file, fragP->fr_line,
5060 _("short branch with zero offset: use :w"));
5061 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
5062 fragP->fr_offset, 1, RELAX_RELOC_PC8);
5063 fixP->fx_pcrel_adjust = -1;
5065 case TAB (BRANCHBWL, SHORT):
5066 case TAB (BRABSJUNC, SHORT):
5067 case TAB (BRABSJCOND, SHORT):
5068 case TAB (BRANCHBW, SHORT):
5069 case TAB (BRANCHBWPL, SHORT):
5070 fragP->fr_opcode[1] = 0x00;
5071 fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
5072 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5075 case TAB (BRANCHBWL, LONG):
5076 fragP->fr_opcode[1] = (char) 0xFF;
5077 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5078 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5081 case TAB (BRANCHBWPL, LONG):
5082 /* Here we are converting an unconditional branch into a pair of
5083 conditional branches, in order to get the range. */
5084 fragP->fr_opcode[0] = 0x66; /* bne */
5085 fragP->fr_opcode[1] = 0xFF;
5086 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5087 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5088 fixP->fx_file = fragP->fr_file;
5089 fixP->fx_line = fragP->fr_line;
5090 fragP->fr_fix += 4; /* Skip first offset */
5091 buffer_address += 4;
5092 *buffer_address++ = 0x67; /* beq */
5093 *buffer_address++ = 0xff;
5094 fragP->fr_fix += 2; /* Skip second branch opcode */
5095 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5096 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5099 case TAB (BRABSJUNC, LONG):
5100 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
5102 if (flag_keep_pcrel)
5103 as_bad_where (fragP->fr_file, fragP->fr_line,
5104 _("Conversion of PC relative BSR to absolute JSR"));
5105 fragP->fr_opcode[0] = 0x4E;
5106 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
5107 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5108 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
5111 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
5113 if (flag_keep_pcrel)
5114 as_bad_where (fragP->fr_file, fragP->fr_line,
5115 _("Conversion of PC relative branch to absolute jump"));
5116 fragP->fr_opcode[0] = 0x4E;
5117 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
5118 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5119 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
5124 /* This cannot happen, because jbsr and jbra are the only two
5125 unconditional branches. */
5129 case TAB (BRABSJCOND, LONG):
5130 if (flag_keep_pcrel)
5131 as_bad_where (fragP->fr_file, fragP->fr_line,
5132 _("Conversion of PC relative conditional branch to absolute jump"));
5134 /* Only Bcc 68000 instructions can come here
5135 Change bcc into b!cc/jmp absl long. */
5136 fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
5137 fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
5139 /* JF: these used to be fr_opcode[2,3], but they may be in a
5140 different frag, in which case referring to them is a no-no.
5141 Only fr_opcode[0,1] are guaranteed to work. */
5142 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
5143 *buffer_address++ = (char) 0xf9;
5144 fragP->fr_fix += 2; /* Account for jmp instruction. */
5145 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5146 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
5149 case TAB (FBRANCH, SHORT):
5150 know ((fragP->fr_opcode[1] & 0x40) == 0);
5151 fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
5152 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5155 case TAB (FBRANCH, LONG):
5156 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
5157 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5158 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5161 case TAB (DBCCLBR, SHORT):
5162 case TAB (DBCCABSJ, SHORT):
5163 fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
5164 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5167 case TAB (DBCCLBR, LONG):
5168 /* Only DBcc instructions can come here.
5169 Change dbcc into dbcc/bral.
5170 JF: these used to be fr_opcode[2-7], but that's wrong. */
5171 if (flag_keep_pcrel)
5172 as_bad_where (fragP->fr_file, fragP->fr_line,
5173 _("Conversion of DBcc to absolute jump"));
5175 *buffer_address++ = 0x00; /* Branch offset = 4. */
5176 *buffer_address++ = 0x04;
5177 *buffer_address++ = 0x60; /* Put in bra pc+6. */
5178 *buffer_address++ = 0x06;
5179 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
5180 *buffer_address++ = (char) 0xff;
5182 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
5183 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5184 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5187 case TAB (DBCCABSJ, LONG):
5188 /* Only DBcc instructions can come here.
5189 Change dbcc into dbcc/jmp.
5190 JF: these used to be fr_opcode[2-7], but that's wrong. */
5191 if (flag_keep_pcrel)
5192 as_bad_where (fragP->fr_file, fragP->fr_line,
5193 _("Conversion of PC relative conditional branch to absolute jump"));
5195 *buffer_address++ = 0x00; /* Branch offset = 4. */
5196 *buffer_address++ = 0x04;
5197 *buffer_address++ = 0x60; /* Put in bra pc + 6. */
5198 *buffer_address++ = 0x06;
5199 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
5200 *buffer_address++ = (char) 0xf9;
5202 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
5203 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5204 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
5207 case TAB (PCREL1632, SHORT):
5208 fragP->fr_opcode[1] &= ~0x3F;
5209 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
5210 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
5211 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5214 case TAB (PCREL1632, LONG):
5215 /* Already set to mode 7.3; this indicates: PC indirect with
5216 suppressed index, 32-bit displacement. */
5217 *buffer_address++ = 0x01;
5218 *buffer_address++ = 0x70;
5220 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
5221 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5222 fixP->fx_pcrel_adjust = 2;
5225 case TAB (PCINDEX, BYTE):
5226 gas_assert (fragP->fr_fix >= 2);
5227 buffer_address[-2] &= ~1;
5228 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
5229 fragP->fr_offset, 1, RELAX_RELOC_PC8);
5230 fixP->fx_pcrel_adjust = 1;
5232 case TAB (PCINDEX, SHORT):
5233 gas_assert (fragP->fr_fix >= 2);
5234 buffer_address[-2] |= 0x1;
5235 buffer_address[-1] = 0x20;
5236 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
5237 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5238 fixP->fx_pcrel_adjust = 2;
5241 case TAB (PCINDEX, LONG):
5242 gas_assert (fragP->fr_fix >= 2);
5243 buffer_address[-2] |= 0x1;
5244 buffer_address[-1] = 0x30;
5245 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
5246 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5247 fixP->fx_pcrel_adjust = 2;
5250 case TAB (ABSTOPCREL, SHORT):
5251 fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
5252 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5255 case TAB (ABSTOPCREL, LONG):
5256 if (flag_keep_pcrel)
5257 as_bad_where (fragP->fr_file, fragP->fr_line,
5258 _("Conversion of PC relative displacement to absolute"));
5259 /* The thing to do here is force it to ABSOLUTE LONG, since
5260 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
5261 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
5263 fragP->fr_opcode[1] &= ~0x3F;
5264 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
5265 fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
5266 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
5272 fixP->fx_file = fragP->fr_file;
5273 fixP->fx_line = fragP->fr_line;
5278 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
5279 segT sec ATTRIBUTE_UNUSED,
5282 md_convert_frag_1 (fragP);
5285 /* Force truly undefined symbols to their maximum size, and generally set up
5286 the frag list to be relaxed
5289 md_estimate_size_before_relax (fragS *fragP, segT segment)
5291 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
5292 switch (fragP->fr_subtype)
5294 case TAB (BRANCHBWL, SZ_UNDEF):
5295 case TAB (BRANCHBWPL, SZ_UNDEF):
5296 case TAB (BRABSJUNC, SZ_UNDEF):
5297 case TAB (BRABSJCOND, SZ_UNDEF):
5299 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5300 && relaxable_symbol (fragP->fr_symbol))
5302 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5304 else if (flag_short_refs)
5306 /* Symbol is undefined and we want short ref. */
5307 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5311 /* Symbol is still undefined. Make it LONG. */
5312 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5317 case TAB (BRANCHBW, SZ_UNDEF):
5319 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5320 && relaxable_symbol (fragP->fr_symbol))
5322 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5326 /* Symbol is undefined and we don't have long branches. */
5327 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5332 case TAB (FBRANCH, SZ_UNDEF):
5333 case TAB (DBCCLBR, SZ_UNDEF):
5334 case TAB (DBCCABSJ, SZ_UNDEF):
5335 case TAB (PCREL1632, SZ_UNDEF):
5337 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5338 && relaxable_symbol (fragP->fr_symbol))
5341 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5345 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5350 case TAB (PCINDEX, SZ_UNDEF):
5351 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5352 && relaxable_symbol (fragP->fr_symbol)))
5354 fragP->fr_subtype = TAB (PCINDEX, BYTE);
5358 fragP->fr_subtype = TAB (PCINDEX, LONG);
5362 case TAB (ABSTOPCREL, SZ_UNDEF):
5364 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5365 && relaxable_symbol (fragP->fr_symbol)))
5367 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
5371 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
5380 /* Now that SZ_UNDEF are taken care of, check others. */
5381 switch (fragP->fr_subtype)
5383 case TAB (BRANCHBWL, BYTE):
5384 case TAB (BRABSJUNC, BYTE):
5385 case TAB (BRABSJCOND, BYTE):
5386 case TAB (BRANCHBW, BYTE):
5387 /* We can't do a short jump to the next instruction, so in that
5388 case we force word mode. If the symbol is at the start of a
5389 frag, and it is the next frag with any data in it (usually
5390 this is just the next frag, but assembler listings may
5391 introduce empty frags), we must use word mode. */
5392 if (fragP->fr_symbol)
5396 sym_frag = symbol_get_frag (fragP->fr_symbol);
5397 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
5401 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
5405 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5412 return md_relax_table[fragP->fr_subtype].rlx_length;
5415 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5416 /* the bit-field entries in the relocation_info struct plays hell
5417 with the byte-order problems of cross-assembly. So as a hack,
5418 I added this mach. dependent ri twiddler. Ugly, but it gets
5420 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5421 are symbolnum, most sig. byte first. Last byte is broken up with
5422 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5423 nibble as nuthin. (on Sun 3 at least) */
5424 /* Translate the internal relocation information into target-specific
5428 md_ri_to_chars (char *the_bytes, struct reloc_info_generic *ri)
5431 md_number_to_chars (the_bytes, ri->r_address, 4);
5432 /* Now the fun stuff. */
5433 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
5434 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
5435 the_bytes[6] = ri->r_symbolnum & 0x0ff;
5436 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80)
5437 | ((ri->r_length << 5) & 0x60)
5438 | ((ri->r_extern << 4) & 0x10));
5443 #endif /* OBJ_AOUT or OBJ_BOUT */
5445 #ifndef WORKING_DOT_WORD
5446 int md_short_jump_size = 4;
5447 int md_long_jump_size = 6;
5450 md_create_short_jump (char *ptr, addressT from_addr, addressT to_addr,
5451 fragS *frag ATTRIBUTE_UNUSED,
5452 symbolS *to_symbol ATTRIBUTE_UNUSED)
5456 offset = to_addr - (from_addr + 2);
5458 md_number_to_chars (ptr, (valueT) 0x6000, 2);
5459 md_number_to_chars (ptr + 2, (valueT) offset, 2);
5463 md_create_long_jump (char *ptr, addressT from_addr, addressT to_addr,
5464 fragS *frag, symbolS *to_symbol)
5468 if (!HAVE_LONG_BRANCH (current_architecture))
5470 if (flag_keep_pcrel)
5471 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5472 offset = to_addr - S_GET_VALUE (to_symbol);
5473 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
5474 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5475 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
5480 offset = to_addr - (from_addr + 2);
5481 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
5482 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5488 /* Different values of OK tell what its OK to return. Things that
5489 aren't OK are an error (what a shock, no?)
5492 10: Absolute 1:8 only
5493 20: Absolute 0:7 only
5494 30: absolute 0:15 only
5495 40: Absolute 0:31 only
5496 50: absolute 0:127 only
5497 55: absolute -64:63 only
5498 60: absolute -128:127 only
5499 65: absolute 0:511 only
5500 70: absolute 0:4095 only
5501 80: absolute -1, 1:7 only
5505 get_num (struct m68k_exp *exp, int ok)
5507 if (exp->exp.X_op == O_absent)
5509 /* Do the same thing the VAX asm does. */
5510 op (exp) = O_constant;
5516 as_warn (_("expression out of range: defaulting to 1"));
5520 else if (exp->exp.X_op == O_constant)
5525 if ((valueT) TRUNC (offs (exp)) - 1 > 7)
5527 as_warn (_("expression out of range: defaulting to 1"));
5532 if ((valueT) TRUNC (offs (exp)) > 7)
5536 if ((valueT) TRUNC (offs (exp)) > 15)
5540 if ((valueT) TRUNC (offs (exp)) > 32)
5544 if ((valueT) TRUNC (offs (exp)) > 127)
5548 if ((valueT) SEXT (offs (exp)) + 64 > 127)
5552 if ((valueT) SEXT (offs (exp)) + 128 > 255)
5556 if ((valueT) TRUNC (offs (exp)) > 511)
5560 if ((valueT) TRUNC (offs (exp)) > 4095)
5563 as_warn (_("expression out of range: defaulting to 0"));
5568 if ((valueT) TRUNC (offs (exp)) != 0xffffffff
5569 && (valueT) TRUNC (offs (exp)) - 1 > 6)
5571 as_warn (_("expression out of range: defaulting to 1"));
5579 else if (exp->exp.X_op == O_big)
5581 if (offs (exp) <= 0 /* flonum. */
5582 && (ok == 90 /* no bignums */
5583 || (ok > 10 /* Small-int ranges including 0 ok. */
5584 /* If we have a flonum zero, a zero integer should
5585 do as well (e.g., in moveq). */
5586 && generic_floating_point_number.exponent == 0
5587 && generic_floating_point_number.low[0] == 0)))
5589 /* HACK! Turn it into a long. */
5590 LITTLENUM_TYPE words[6];
5592 gen_to_words (words, 2, 8L); /* These numbers are magic! */
5593 op (exp) = O_constant;
5596 offs (exp) = words[1] | (words[0] << 16);
5600 op (exp) = O_constant;
5603 offs (exp) = (ok == 10) ? 1 : 0;
5604 as_warn (_("Can't deal with expression; defaulting to %ld"),
5610 if (ok >= 10 && ok <= 80)
5612 op (exp) = O_constant;
5615 offs (exp) = (ok == 10) ? 1 : 0;
5616 as_warn (_("Can't deal with expression; defaulting to %ld"),
5621 if (exp->size != SIZE_UNSPEC)
5629 if (!isbyte (offs (exp)))
5630 as_warn (_("expression doesn't fit in BYTE"));
5633 if (!isword (offs (exp)))
5634 as_warn (_("expression doesn't fit in WORD"));
5642 /* These are the back-ends for the various machine dependent pseudo-ops. */
5645 s_data1 (int ignore ATTRIBUTE_UNUSED)
5647 subseg_set (data_section, 1);
5648 demand_empty_rest_of_line ();
5652 s_data2 (int ignore ATTRIBUTE_UNUSED)
5654 subseg_set (data_section, 2);
5655 demand_empty_rest_of_line ();
5659 s_bss (int ignore ATTRIBUTE_UNUSED)
5661 /* We don't support putting frags in the BSS segment, we fake it
5662 by marking in_bss, then looking at s_skip for clues. */
5664 subseg_set (bss_section, 0);
5665 demand_empty_rest_of_line ();
5669 s_even (int ignore ATTRIBUTE_UNUSED)
5672 register long temp_fill;
5674 temp = 1; /* JF should be 2? */
5675 temp_fill = get_absolute_expression ();
5676 if (!need_pass_2) /* Never make frag if expect extra pass. */
5677 frag_align (temp, (int) temp_fill, 0);
5678 demand_empty_rest_of_line ();
5679 record_alignment (now_seg, temp);
5683 s_proc (int ignore ATTRIBUTE_UNUSED)
5685 demand_empty_rest_of_line ();
5688 /* Pseudo-ops handled for MRI compatibility. */
5690 /* This function returns non-zero if the argument is a conditional
5691 pseudo-op. This is called when checking whether a pending
5692 alignment is needed. */
5695 m68k_conditional_pseudoop (pseudo_typeS *pop)
5697 return (pop->poc_handler == s_mri_if
5698 || pop->poc_handler == s_mri_else);
5701 /* Handle an MRI style chip specification. */
5710 s = input_line_pointer;
5711 /* We can't use get_symbol_end since the processor names are not proper
5713 while (is_part_of_name (c = *input_line_pointer++))
5715 *--input_line_pointer = 0;
5716 for (i = 0; m68k_cpus[i].name; i++)
5717 if (strcasecmp (s, m68k_cpus[i].name) == 0)
5719 if (!m68k_cpus[i].name)
5721 as_bad (_("%s: unrecognized processor name"), s);
5722 *input_line_pointer = c;
5723 ignore_rest_of_line ();
5726 *input_line_pointer = c;
5728 if (*input_line_pointer == '/')
5729 current_architecture = 0;
5731 current_architecture &= m68881 | m68851;
5732 current_architecture |= m68k_cpus[i].arch & ~(m68881 | m68851);
5733 control_regs = m68k_cpus[i].control_regs;
5735 while (*input_line_pointer == '/')
5737 ++input_line_pointer;
5738 s = input_line_pointer;
5739 /* We can't use get_symbol_end since the processor names are not
5741 while (is_part_of_name (c = *input_line_pointer++))
5743 *--input_line_pointer = 0;
5744 if (strcmp (s, "68881") == 0)
5745 current_architecture |= m68881;
5746 else if (strcmp (s, "68851") == 0)
5747 current_architecture |= m68851;
5748 *input_line_pointer = c;
5752 /* The MRI CHIP pseudo-op. */
5755 s_chip (int ignore ATTRIBUTE_UNUSED)
5761 stop = mri_comment_field (&stopc);
5764 mri_comment_end (stop, stopc);
5765 demand_empty_rest_of_line ();
5768 /* The MRI FOPT pseudo-op. */
5771 s_fopt (int ignore ATTRIBUTE_UNUSED)
5775 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5779 input_line_pointer += 3;
5780 temp = get_absolute_expression ();
5781 if (temp < 0 || temp > 7)
5782 as_bad (_("bad coprocessor id"));
5784 m68k_float_copnum = COP0 + temp;
5788 as_bad (_("unrecognized fopt option"));
5789 ignore_rest_of_line ();
5793 demand_empty_rest_of_line ();
5796 /* The structure used to handle the MRI OPT pseudo-op. */
5800 /* The name of the option. */
5803 /* If this is not NULL, just call this function. The first argument
5804 is the ARG field of this structure, the second argument is
5805 whether the option was negated. */
5806 void (*pfn) (int arg, int on);
5808 /* If this is not NULL, and the PFN field is NULL, set the variable
5809 this points to. Set it to the ARG field if the option was not
5810 negated, and the NOTARG field otherwise. */
5813 /* The value to pass to PFN or to assign to *PVAR. */
5816 /* The value to assign to *PVAR if the option is negated. If PFN is
5817 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5818 the option may not be negated. */
5822 /* The table used to handle the MRI OPT pseudo-op. */
5824 static void skip_to_comma (int, int);
5825 static void opt_nest (int, int);
5826 static void opt_chip (int, int);
5827 static void opt_list (int, int);
5828 static void opt_list_symbols (int, int);
5830 static const struct opt_action opt_table[] =
5832 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5834 /* We do relaxing, so there is little use for these options. */
5835 { "b", 0, 0, 0, 0 },
5836 { "brs", 0, 0, 0, 0 },
5837 { "brb", 0, 0, 0, 0 },
5838 { "brl", 0, 0, 0, 0 },
5839 { "brw", 0, 0, 0, 0 },
5841 { "c", 0, 0, 0, 0 },
5842 { "cex", 0, 0, 0, 0 },
5843 { "case", 0, &symbols_case_sensitive, 1, 0 },
5844 { "cl", 0, 0, 0, 0 },
5845 { "cre", 0, 0, 0, 0 },
5846 { "d", 0, &flag_keep_locals, 1, 0 },
5847 { "e", 0, 0, 0, 0 },
5848 { "f", 0, &flag_short_refs, 1, 0 },
5849 { "frs", 0, &flag_short_refs, 1, 0 },
5850 { "frl", 0, &flag_short_refs, 0, 1 },
5851 { "g", 0, 0, 0, 0 },
5852 { "i", 0, 0, 0, 0 },
5853 { "m", 0, 0, 0, 0 },
5854 { "mex", 0, 0, 0, 0 },
5855 { "mc", 0, 0, 0, 0 },
5856 { "md", 0, 0, 0, 0 },
5857 { "nest", opt_nest, 0, 0, 0 },
5858 { "next", skip_to_comma, 0, 0, 0 },
5859 { "o", 0, 0, 0, 0 },
5860 { "old", 0, 0, 0, 0 },
5861 { "op", skip_to_comma, 0, 0, 0 },
5862 { "pco", 0, 0, 0, 0 },
5863 { "p", opt_chip, 0, 0, 0 },
5864 { "pcr", 0, 0, 0, 0 },
5865 { "pcs", 0, 0, 0, 0 },
5866 { "r", 0, 0, 0, 0 },
5867 { "quick", 0, &m68k_quick, 1, 0 },
5868 { "rel32", 0, &m68k_rel32, 1, 0 },
5869 { "s", opt_list, 0, 0, 0 },
5870 { "t", opt_list_symbols, 0, 0, 0 },
5871 { "w", 0, &flag_no_warnings, 0, 1 },
5875 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5877 /* The MRI OPT pseudo-op. */
5880 s_opt (int ignore ATTRIBUTE_UNUSED)
5888 const struct opt_action *o;
5893 if (*input_line_pointer == '-')
5895 ++input_line_pointer;
5898 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5900 input_line_pointer += 2;
5904 s = input_line_pointer;
5905 c = get_symbol_end ();
5907 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5909 if (strcasecmp (s, o->name) == 0)
5913 /* Restore input_line_pointer now in case the option
5915 *input_line_pointer = c;
5916 (*o->pfn) (o->arg, t);
5918 else if (o->pvar != NULL)
5920 if (! t && o->arg == o->notarg)
5921 as_bad (_("option `%s' may not be negated"), s);
5922 *input_line_pointer = c;
5923 *o->pvar = t ? o->arg : o->notarg;
5926 *input_line_pointer = c;
5932 as_bad (_("option `%s' not recognized"), s);
5933 *input_line_pointer = c;
5936 while (*input_line_pointer++ == ',');
5938 /* Move back to terminating character. */
5939 --input_line_pointer;
5940 demand_empty_rest_of_line ();
5943 /* Skip ahead to a comma. This is used for OPT options which we do
5944 not support and which take arguments. */
5947 skip_to_comma (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5949 while (*input_line_pointer != ','
5950 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5951 ++input_line_pointer;
5954 /* Handle the OPT NEST=depth option. */
5957 opt_nest (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5959 if (*input_line_pointer != '=')
5961 as_bad (_("bad format of OPT NEST=depth"));
5965 ++input_line_pointer;
5966 max_macro_nest = get_absolute_expression ();
5969 /* Handle the OPT P=chip option. */
5972 opt_chip (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5974 if (*input_line_pointer != '=')
5976 /* This is just OPT P, which we do not support. */
5980 ++input_line_pointer;
5984 /* Handle the OPT S option. */
5987 opt_list (int arg ATTRIBUTE_UNUSED, int on)
5992 /* Handle the OPT T option. */
5995 opt_list_symbols (int arg ATTRIBUTE_UNUSED, int on)
5998 listing |= LISTING_SYMBOLS;
6000 listing &= ~LISTING_SYMBOLS;
6003 /* Handle the MRI REG pseudo-op. */
6006 s_reg (int ignore ATTRIBUTE_UNUSED)
6015 if (line_label == NULL)
6017 as_bad (_("missing label"));
6018 ignore_rest_of_line ();
6023 stop = mri_comment_field (&stopc);
6027 s = input_line_pointer;
6028 while (ISALNUM (*input_line_pointer)
6029 #ifdef REGISTER_PREFIX
6030 || *input_line_pointer == REGISTER_PREFIX
6032 || *input_line_pointer == '/'
6033 || *input_line_pointer == '-')
6034 ++input_line_pointer;
6035 c = *input_line_pointer;
6036 *input_line_pointer = '\0';
6038 if (m68k_ip_op (s, &rop) != 0)
6040 if (rop.error == NULL)
6041 as_bad (_("bad register list"));
6043 as_bad (_("bad register list: %s"), rop.error);
6044 *input_line_pointer = c;
6045 ignore_rest_of_line ();
6049 *input_line_pointer = c;
6051 if (rop.mode == REGLST)
6053 else if (rop.mode == DREG)
6054 mask = 1 << (rop.reg - DATA0);
6055 else if (rop.mode == AREG)
6056 mask = 1 << (rop.reg - ADDR0 + 8);
6057 else if (rop.mode == FPREG)
6058 mask = 1 << (rop.reg - FP0 + 16);
6059 else if (rop.mode == CONTROL
6062 else if (rop.mode == CONTROL
6065 else if (rop.mode == CONTROL
6070 as_bad (_("bad register list"));
6071 ignore_rest_of_line ();
6075 S_SET_SEGMENT (line_label, reg_section);
6076 S_SET_VALUE (line_label, ~mask);
6077 symbol_set_frag (line_label, &zero_address_frag);
6080 mri_comment_end (stop, stopc);
6082 demand_empty_rest_of_line ();
6085 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
6089 struct save_opts *next;
6091 int symbols_case_sensitive;
6095 const enum m68k_register *control_regs;
6100 /* FIXME: We don't save OPT S. */
6103 /* This variable holds the stack of saved options. */
6105 static struct save_opts *save_stack;
6107 /* The MRI SAVE pseudo-op. */
6110 s_save (int ignore ATTRIBUTE_UNUSED)
6112 struct save_opts *s;
6114 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
6115 s->abspcadd = m68k_abspcadd;
6116 s->symbols_case_sensitive = symbols_case_sensitive;
6117 s->keep_locals = flag_keep_locals;
6118 s->short_refs = flag_short_refs;
6119 s->architecture = current_architecture;
6120 s->control_regs = control_regs;
6121 s->quick = m68k_quick;
6122 s->rel32 = m68k_rel32;
6123 s->listing = listing;
6124 s->no_warnings = flag_no_warnings;
6126 s->next = save_stack;
6129 demand_empty_rest_of_line ();
6132 /* The MRI RESTORE pseudo-op. */
6135 s_restore (int ignore ATTRIBUTE_UNUSED)
6137 struct save_opts *s;
6139 if (save_stack == NULL)
6141 as_bad (_("restore without save"));
6142 ignore_rest_of_line ();
6147 save_stack = s->next;
6149 m68k_abspcadd = s->abspcadd;
6150 symbols_case_sensitive = s->symbols_case_sensitive;
6151 flag_keep_locals = s->keep_locals;
6152 flag_short_refs = s->short_refs;
6153 current_architecture = s->architecture;
6154 control_regs = s->control_regs;
6155 m68k_quick = s->quick;
6156 m68k_rel32 = s->rel32;
6157 listing = s->listing;
6158 flag_no_warnings = s->no_warnings;
6162 demand_empty_rest_of_line ();
6165 /* Types of MRI structured control directives. */
6167 enum mri_control_type
6175 /* This structure is used to stack the MRI structured control
6178 struct mri_control_info
6180 /* The directive within which this one is enclosed. */
6181 struct mri_control_info *outer;
6183 /* The type of directive. */
6184 enum mri_control_type type;
6186 /* Whether an ELSE has been in an IF. */
6189 /* The add or sub statement at the end of a FOR. */
6192 /* The label of the top of a FOR or REPEAT loop. */
6195 /* The label to jump to for the next iteration, or the else
6196 expression of a conditional. */
6199 /* The label to jump to to break out of the loop, or the label past
6200 the end of a conditional. */
6204 /* The stack of MRI structured control directives. */
6206 static struct mri_control_info *mri_control_stack;
6208 /* The current MRI structured control directive index number, used to
6209 generate label names. */
6211 static int mri_control_index;
6213 /* Assemble an instruction for an MRI structured control directive. */
6216 mri_assemble (char *str)
6220 /* md_assemble expects the opcode to be in lower case. */
6221 for (s = str; *s != ' ' && *s != '\0'; s++)
6227 /* Generate a new MRI label structured control directive label name. */
6230 mri_control_label (void)
6234 n = (char *) xmalloc (20);
6235 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
6236 ++mri_control_index;
6240 /* Create a new MRI structured control directive. */
6242 static struct mri_control_info *
6243 push_mri_control (enum mri_control_type type)
6245 struct mri_control_info *n;
6247 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
6251 if (type == mri_if || type == mri_while)
6254 n->top = mri_control_label ();
6255 n->next = mri_control_label ();
6256 n->bottom = mri_control_label ();
6258 n->outer = mri_control_stack;
6259 mri_control_stack = n;
6264 /* Pop off the stack of MRI structured control directives. */
6267 pop_mri_control (void)
6269 struct mri_control_info *n;
6271 n = mri_control_stack;
6272 mri_control_stack = n->outer;
6280 /* Recognize a condition code in an MRI structured control expression. */
6283 parse_mri_condition (int *pcc)
6287 know (*input_line_pointer == '<');
6289 ++input_line_pointer;
6290 c1 = *input_line_pointer++;
6291 c2 = *input_line_pointer++;
6293 if (*input_line_pointer != '>')
6295 as_bad (_("syntax error in structured control directive"));
6299 ++input_line_pointer;
6305 *pcc = (c1 << 8) | c2;
6310 /* Parse a single operand in an MRI structured control expression. */
6313 parse_mri_control_operand (int *pcc, char **leftstart, char **leftstop,
6314 char **rightstart, char **rightstop)
6326 if (*input_line_pointer == '<')
6328 /* It's just a condition code. */
6329 return parse_mri_condition (pcc);
6332 /* Look ahead for the condition code. */
6333 for (s = input_line_pointer; *s != '\0'; ++s)
6335 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
6340 as_bad (_("missing condition code in structured control directive"));
6344 *leftstart = input_line_pointer;
6346 if (*leftstop > *leftstart
6347 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
6350 input_line_pointer = s;
6351 if (! parse_mri_condition (pcc))
6354 /* Look ahead for AND or OR or end of line. */
6355 for (s = input_line_pointer; *s != '\0'; ++s)
6357 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6358 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6360 if ((s == input_line_pointer
6363 && ((strncasecmp (s, "AND", 3) == 0
6364 && (s[3] == '.' || ! is_part_of_name (s[3])))
6365 || (strncasecmp (s, "OR", 2) == 0
6366 && (s[2] == '.' || ! is_part_of_name (s[2])))))
6370 *rightstart = input_line_pointer;
6372 if (*rightstop > *rightstart
6373 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
6376 input_line_pointer = s;
6381 #define MCC(b1, b2) (((b1) << 8) | (b2))
6383 /* Swap the sense of a condition. This changes the condition so that
6384 it generates the same result when the operands are swapped. */
6387 swap_mri_condition (int cc)
6391 case MCC ('h', 'i'): return MCC ('c', 's');
6392 case MCC ('l', 's'): return MCC ('c', 'c');
6393 /* <HS> is an alias for <CC>. */
6394 case MCC ('h', 's'):
6395 case MCC ('c', 'c'): return MCC ('l', 's');
6396 /* <LO> is an alias for <CS>. */
6397 case MCC ('l', 'o'):
6398 case MCC ('c', 's'): return MCC ('h', 'i');
6399 case MCC ('p', 'l'): return MCC ('m', 'i');
6400 case MCC ('m', 'i'): return MCC ('p', 'l');
6401 case MCC ('g', 'e'): return MCC ('l', 'e');
6402 case MCC ('l', 't'): return MCC ('g', 't');
6403 case MCC ('g', 't'): return MCC ('l', 't');
6404 case MCC ('l', 'e'): return MCC ('g', 'e');
6405 /* Issue a warning for conditions we can not swap. */
6406 case MCC ('n', 'e'): return MCC ('n', 'e'); /* no problem here */
6407 case MCC ('e', 'q'): return MCC ('e', 'q'); /* also no problem */
6408 case MCC ('v', 'c'):
6409 case MCC ('v', 's'):
6411 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6412 (char) (cc >> 8), (char) (cc));
6418 /* Reverse the sense of a condition. */
6421 reverse_mri_condition (int cc)
6425 case MCC ('h', 'i'): return MCC ('l', 's');
6426 case MCC ('l', 's'): return MCC ('h', 'i');
6427 /* <HS> is an alias for <CC> */
6428 case MCC ('h', 's'): return MCC ('l', 'o');
6429 case MCC ('c', 'c'): return MCC ('c', 's');
6430 /* <LO> is an alias for <CS> */
6431 case MCC ('l', 'o'): return MCC ('h', 's');
6432 case MCC ('c', 's'): return MCC ('c', 'c');
6433 case MCC ('n', 'e'): return MCC ('e', 'q');
6434 case MCC ('e', 'q'): return MCC ('n', 'e');
6435 case MCC ('v', 'c'): return MCC ('v', 's');
6436 case MCC ('v', 's'): return MCC ('v', 'c');
6437 case MCC ('p', 'l'): return MCC ('m', 'i');
6438 case MCC ('m', 'i'): return MCC ('p', 'l');
6439 case MCC ('g', 'e'): return MCC ('l', 't');
6440 case MCC ('l', 't'): return MCC ('g', 'e');
6441 case MCC ('g', 't'): return MCC ('l', 'e');
6442 case MCC ('l', 'e'): return MCC ('g', 't');
6447 /* Build an MRI structured control expression. This generates test
6448 and branch instructions. It goes to TRUELAB if the condition is
6449 true, and to FALSELAB if the condition is false. Exactly one of
6450 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6451 is the size qualifier for the expression. EXTENT is the size to
6452 use for the branch. */
6455 build_mri_control_operand (int qual, int cc, char *leftstart, char *leftstop,
6456 char *rightstart, char *rightstop,
6457 const char *truelab, const char *falselab,
6463 if (leftstart != NULL)
6465 struct m68k_op leftop, rightop;
6468 /* Swap the compare operands, if necessary, to produce a legal
6469 m68k compare instruction. Comparing a register operand with
6470 a non-register operand requires the register to be on the
6471 right (cmp, cmpa). Comparing an immediate value with
6472 anything requires the immediate value to be on the left
6477 (void) m68k_ip_op (leftstart, &leftop);
6482 (void) m68k_ip_op (rightstart, &rightop);
6485 if (rightop.mode == IMMED
6486 || ((leftop.mode == DREG || leftop.mode == AREG)
6487 && (rightop.mode != DREG && rightop.mode != AREG)))
6491 /* Correct conditional handling:
6492 if #1 <lt> d0 then ;means if (1 < d0)
6498 cmp #1,d0 if we do *not* swap the operands
6499 bgt true we need the swapped condition!
6506 leftstart = rightstart;
6509 leftstop = rightstop;
6514 cc = swap_mri_condition (cc);
6518 if (truelab == NULL)
6520 cc = reverse_mri_condition (cc);
6524 if (leftstart != NULL)
6526 buf = (char *) xmalloc (20
6527 + (leftstop - leftstart)
6528 + (rightstop - rightstart));
6534 *s++ = TOLOWER (qual);
6536 memcpy (s, leftstart, leftstop - leftstart);
6537 s += leftstop - leftstart;
6539 memcpy (s, rightstart, rightstop - rightstart);
6540 s += rightstop - rightstart;
6546 buf = (char *) xmalloc (20 + strlen (truelab));
6552 *s++ = TOLOWER (extent);
6554 strcpy (s, truelab);
6559 /* Parse an MRI structured control expression. This generates test
6560 and branch instructions. STOP is where the expression ends. It
6561 goes to TRUELAB if the condition is true, and to FALSELAB if the
6562 condition is false. Exactly one of TRUELAB and FALSELAB will be
6563 NULL, meaning to fall through. QUAL is the size qualifier for the
6564 expression. EXTENT is the size to use for the branch. */
6567 parse_mri_control_expression (char *stop, int qual, const char *truelab,
6568 const char *falselab, int extent)
6580 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6581 &rightstart, &rightstop))
6587 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
6591 if (falselab != NULL)
6594 flab = mri_control_label ();
6596 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6597 rightstop, (const char *) NULL, flab, extent);
6599 input_line_pointer += 3;
6600 if (*input_line_pointer != '.'
6601 || input_line_pointer[1] == '\0')
6605 qual = input_line_pointer[1];
6606 input_line_pointer += 2;
6609 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6610 &rightstart, &rightstop))
6616 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6617 rightstop, truelab, falselab, extent);
6619 if (falselab == NULL)
6622 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6626 if (truelab != NULL)
6629 tlab = mri_control_label ();
6631 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6632 rightstop, tlab, (const char *) NULL, extent);
6634 input_line_pointer += 2;
6635 if (*input_line_pointer != '.'
6636 || input_line_pointer[1] == '\0')
6640 qual = input_line_pointer[1];
6641 input_line_pointer += 2;
6644 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6645 &rightstart, &rightstop))
6651 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6652 rightstop, truelab, falselab, extent);
6654 if (truelab == NULL)
6659 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6660 rightstop, truelab, falselab, extent);
6664 if (input_line_pointer != stop)
6665 as_bad (_("syntax error in structured control directive"));
6668 /* Handle the MRI IF pseudo-op. This may be a structured control
6669 directive, or it may be a regular assembler conditional, depending
6677 struct mri_control_info *n;
6679 /* A structured control directive must end with THEN with an
6680 optional qualifier. */
6681 s = input_line_pointer;
6682 /* We only accept '*' as introduction of comments if preceded by white space
6683 or at first column of a line (I think this can't actually happen here?)
6684 This is important when assembling:
6685 if d0 <ne> 12(a0,d0*2) then
6686 if d0 <ne> #CONST*20 then. */
6687 while (! (is_end_of_line[(unsigned char) *s]
6690 && (s == input_line_pointer
6692 || *(s-1) == '\t'))))
6695 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6698 if (s - input_line_pointer > 1
6702 if (s - input_line_pointer < 3
6703 || strncasecmp (s - 3, "THEN", 4) != 0)
6707 as_bad (_("missing then"));
6708 ignore_rest_of_line ();
6712 /* It's a conditional. */
6717 /* Since this might be a conditional if, this pseudo-op will be
6718 called even if we are supported to be ignoring input. Double
6719 check now. Clobber *input_line_pointer so that ignore_input
6720 thinks that this is not a special pseudo-op. */
6721 c = *input_line_pointer;
6722 *input_line_pointer = 0;
6723 if (ignore_input ())
6725 *input_line_pointer = c;
6726 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6727 ++input_line_pointer;
6728 demand_empty_rest_of_line ();
6731 *input_line_pointer = c;
6733 n = push_mri_control (mri_if);
6735 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6736 n->next, s[1] == '.' ? s[2] : '\0');
6739 input_line_pointer = s + 3;
6741 input_line_pointer = s + 1;
6745 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6746 ++input_line_pointer;
6749 demand_empty_rest_of_line ();
6752 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6753 structured IF, associate the ELSE with the IF. Otherwise, assume
6754 it is a conditional else. */
6757 s_mri_else (int qual)
6764 && (mri_control_stack == NULL
6765 || mri_control_stack->type != mri_if
6766 || mri_control_stack->else_seen))
6772 c = *input_line_pointer;
6773 *input_line_pointer = 0;
6774 if (ignore_input ())
6776 *input_line_pointer = c;
6777 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6778 ++input_line_pointer;
6779 demand_empty_rest_of_line ();
6782 *input_line_pointer = c;
6784 if (mri_control_stack == NULL
6785 || mri_control_stack->type != mri_if
6786 || mri_control_stack->else_seen)
6788 as_bad (_("else without matching if"));
6789 ignore_rest_of_line ();
6793 mri_control_stack->else_seen = 1;
6795 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6796 q[0] = TOLOWER (qual);
6798 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6802 colon (mri_control_stack->next);
6806 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6807 ++input_line_pointer;
6810 demand_empty_rest_of_line ();
6813 /* Handle the MRI ENDI pseudo-op. */
6816 s_mri_endi (int ignore ATTRIBUTE_UNUSED)
6818 if (mri_control_stack == NULL
6819 || mri_control_stack->type != mri_if)
6821 as_bad (_("endi without matching if"));
6822 ignore_rest_of_line ();
6826 /* ignore_input will not return true for ENDI, so we don't need to
6827 worry about checking it again here. */
6829 if (! mri_control_stack->else_seen)
6830 colon (mri_control_stack->next);
6831 colon (mri_control_stack->bottom);
6837 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6838 ++input_line_pointer;
6841 demand_empty_rest_of_line ();
6844 /* Handle the MRI BREAK pseudo-op. */
6847 s_mri_break (int extent)
6849 struct mri_control_info *n;
6853 n = mri_control_stack;
6855 && n->type != mri_for
6856 && n->type != mri_repeat
6857 && n->type != mri_while)
6861 as_bad (_("break outside of structured loop"));
6862 ignore_rest_of_line ();
6866 buf = (char *) xmalloc (20 + strlen (n->bottom));
6867 ex[0] = TOLOWER (extent);
6869 sprintf (buf, "bra%s %s", ex, n->bottom);
6875 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6876 ++input_line_pointer;
6879 demand_empty_rest_of_line ();
6882 /* Handle the MRI NEXT pseudo-op. */
6885 s_mri_next (int extent)
6887 struct mri_control_info *n;
6891 n = mri_control_stack;
6893 && n->type != mri_for
6894 && n->type != mri_repeat
6895 && n->type != mri_while)
6899 as_bad (_("next outside of structured loop"));
6900 ignore_rest_of_line ();
6904 buf = (char *) xmalloc (20 + strlen (n->next));
6905 ex[0] = TOLOWER (extent);
6907 sprintf (buf, "bra%s %s", ex, n->next);
6913 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6914 ++input_line_pointer;
6917 demand_empty_rest_of_line ();
6920 /* Handle the MRI FOR pseudo-op. */
6923 s_mri_for (int qual)
6925 const char *varstart, *varstop;
6926 const char *initstart, *initstop;
6927 const char *endstart, *endstop;
6928 const char *bystart, *bystop;
6932 struct mri_control_info *n;
6938 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6942 varstart = input_line_pointer;
6944 /* Look for the '='. */
6945 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6946 && *input_line_pointer != '=')
6947 ++input_line_pointer;
6948 if (*input_line_pointer != '=')
6950 as_bad (_("missing ="));
6951 ignore_rest_of_line ();
6955 varstop = input_line_pointer;
6956 if (varstop > varstart
6957 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6960 ++input_line_pointer;
6962 initstart = input_line_pointer;
6964 /* Look for TO or DOWNTO. */
6967 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6969 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6970 && ! is_part_of_name (input_line_pointer[2]))
6972 initstop = input_line_pointer;
6973 input_line_pointer += 2;
6976 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6977 && ! is_part_of_name (input_line_pointer[6]))
6979 initstop = input_line_pointer;
6981 input_line_pointer += 6;
6984 ++input_line_pointer;
6986 if (initstop == NULL)
6988 as_bad (_("missing to or downto"));
6989 ignore_rest_of_line ();
6992 if (initstop > initstart
6993 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6997 endstart = input_line_pointer;
6999 /* Look for BY or DO. */
7002 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7004 if (strncasecmp (input_line_pointer, "BY", 2) == 0
7005 && ! is_part_of_name (input_line_pointer[2]))
7007 endstop = input_line_pointer;
7009 input_line_pointer += 2;
7012 if (strncasecmp (input_line_pointer, "DO", 2) == 0
7013 && (input_line_pointer[2] == '.'
7014 || ! is_part_of_name (input_line_pointer[2])))
7016 endstop = input_line_pointer;
7017 input_line_pointer += 2;
7020 ++input_line_pointer;
7022 if (endstop == NULL)
7024 as_bad (_("missing do"));
7025 ignore_rest_of_line ();
7028 if (endstop > endstart
7029 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
7035 bystop = bystart + 2;
7040 bystart = input_line_pointer;
7044 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7046 if (strncasecmp (input_line_pointer, "DO", 2) == 0
7047 && (input_line_pointer[2] == '.'
7048 || ! is_part_of_name (input_line_pointer[2])))
7050 bystop = input_line_pointer;
7051 input_line_pointer += 2;
7054 ++input_line_pointer;
7058 as_bad (_("missing do"));
7059 ignore_rest_of_line ();
7062 if (bystop > bystart
7063 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
7067 if (*input_line_pointer != '.')
7071 extent = input_line_pointer[1];
7072 input_line_pointer += 2;
7075 /* We have fully parsed the FOR operands. Now build the loop. */
7076 n = push_mri_control (mri_for);
7078 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
7080 /* Move init,var. */
7087 *s++ = TOLOWER (qual);
7089 memcpy (s, initstart, initstop - initstart);
7090 s += initstop - initstart;
7092 memcpy (s, varstart, varstop - varstart);
7093 s += varstop - varstart;
7105 *s++ = TOLOWER (qual);
7107 memcpy (s, endstart, endstop - endstart);
7108 s += endstop - endstart;
7110 memcpy (s, varstart, varstop - varstart);
7111 s += varstop - varstart;
7116 ex[0] = TOLOWER (extent);
7119 sprintf (buf, "blt%s %s", ex, n->bottom);
7121 sprintf (buf, "bgt%s %s", ex, n->bottom);
7124 /* Put together the add or sub instruction used by ENDF. */
7132 *s++ = TOLOWER (qual);
7134 memcpy (s, bystart, bystop - bystart);
7135 s += bystop - bystart;
7137 memcpy (s, varstart, varstop - varstart);
7138 s += varstop - varstart;
7144 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7145 ++input_line_pointer;
7148 demand_empty_rest_of_line ();
7151 /* Handle the MRI ENDF pseudo-op. */
7154 s_mri_endf (int ignore ATTRIBUTE_UNUSED)
7156 if (mri_control_stack == NULL
7157 || mri_control_stack->type != mri_for)
7159 as_bad (_("endf without for"));
7160 ignore_rest_of_line ();
7164 colon (mri_control_stack->next);
7166 mri_assemble (mri_control_stack->incr);
7168 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
7169 mri_assemble (mri_control_stack->incr);
7171 free (mri_control_stack->incr);
7173 colon (mri_control_stack->bottom);
7179 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7180 ++input_line_pointer;
7183 demand_empty_rest_of_line ();
7186 /* Handle the MRI REPEAT pseudo-op. */
7189 s_mri_repeat (int ignore ATTRIBUTE_UNUSED)
7191 struct mri_control_info *n;
7193 n = push_mri_control (mri_repeat);
7197 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7198 ++input_line_pointer;
7200 demand_empty_rest_of_line ();
7203 /* Handle the MRI UNTIL pseudo-op. */
7206 s_mri_until (int qual)
7210 if (mri_control_stack == NULL
7211 || mri_control_stack->type != mri_repeat)
7213 as_bad (_("until without repeat"));
7214 ignore_rest_of_line ();
7218 colon (mri_control_stack->next);
7220 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
7223 parse_mri_control_expression (s, qual, (const char *) NULL,
7224 mri_control_stack->top, '\0');
7226 colon (mri_control_stack->bottom);
7228 input_line_pointer = s;
7234 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7235 ++input_line_pointer;
7238 demand_empty_rest_of_line ();
7241 /* Handle the MRI WHILE pseudo-op. */
7244 s_mri_while (int qual)
7248 struct mri_control_info *n;
7250 s = input_line_pointer;
7251 /* We only accept '*' as introduction of comments if preceded by white space
7252 or at first column of a line (I think this can't actually happen here?)
7253 This is important when assembling:
7254 while d0 <ne> 12(a0,d0*2) do
7255 while d0 <ne> #CONST*20 do. */
7256 while (! (is_end_of_line[(unsigned char) *s]
7259 && (s == input_line_pointer
7261 || *(s-1) == '\t'))))
7264 while (*s == ' ' || *s == '\t')
7266 if (s - input_line_pointer > 1
7269 if (s - input_line_pointer < 2
7270 || strncasecmp (s - 1, "DO", 2) != 0)
7272 as_bad (_("missing do"));
7273 ignore_rest_of_line ();
7277 n = push_mri_control (mri_while);
7281 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
7282 s[1] == '.' ? s[2] : '\0');
7284 input_line_pointer = s + 1;
7285 if (*input_line_pointer == '.')
7286 input_line_pointer += 2;
7290 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7291 ++input_line_pointer;
7294 demand_empty_rest_of_line ();
7297 /* Handle the MRI ENDW pseudo-op. */
7300 s_mri_endw (int ignore ATTRIBUTE_UNUSED)
7304 if (mri_control_stack == NULL
7305 || mri_control_stack->type != mri_while)
7307 as_bad (_("endw without while"));
7308 ignore_rest_of_line ();
7312 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
7313 sprintf (buf, "bra %s", mri_control_stack->next);
7317 colon (mri_control_stack->bottom);
7323 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7324 ++input_line_pointer;
7327 demand_empty_rest_of_line ();
7330 /* Parse a .cpu directive. */
7333 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED)
7340 as_bad (_("already assembled instructions"));
7341 ignore_rest_of_line ();
7345 name = input_line_pointer;
7346 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
7347 input_line_pointer++;
7348 saved_char = *input_line_pointer;
7349 *input_line_pointer = 0;
7351 m68k_set_cpu (name, 1, 0);
7353 *input_line_pointer = saved_char;
7354 demand_empty_rest_of_line ();
7358 /* Parse a .arch directive. */
7361 s_m68k_arch (int ignored ATTRIBUTE_UNUSED)
7368 as_bad (_("already assembled instructions"));
7369 ignore_rest_of_line ();
7373 name = input_line_pointer;
7374 while (*input_line_pointer && *input_line_pointer != ','
7375 && !ISSPACE (*input_line_pointer))
7376 input_line_pointer++;
7377 saved_char = *input_line_pointer;
7378 *input_line_pointer = 0;
7380 if (m68k_set_arch (name, 1, 0))
7382 /* Scan extensions. */
7385 *input_line_pointer++ = saved_char;
7386 if (!*input_line_pointer || ISSPACE (*input_line_pointer))
7388 name = input_line_pointer;
7389 while (*input_line_pointer && *input_line_pointer != ','
7390 && !ISSPACE (*input_line_pointer))
7391 input_line_pointer++;
7392 saved_char = *input_line_pointer;
7393 *input_line_pointer = 0;
7395 while (m68k_set_extension (name, 1, 0));
7398 *input_line_pointer = saved_char;
7399 demand_empty_rest_of_line ();
7403 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
7404 if none is found, the caller is responsible for emitting an error
7405 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
7406 cpu name, if it begins with a '6' (possibly skipping an intervening
7407 'c'. We also allow a 'c' in the same place. if NEGATED is
7408 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
7409 the option is indeed negated. */
7411 static const struct m68k_cpu *
7412 m68k_lookup_cpu (const char *arg, const struct m68k_cpu *table,
7413 int allow_m, int *negated)
7415 /* allow negated value? */
7420 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
7427 /* Remove 'm' or 'mc' prefix from 68k variants. */
7434 else if (arg[1] == 'c' && arg[2] == '6')
7438 else if (arg[0] == 'c' && arg[1] == '6')
7441 for (; table->name; table++)
7442 if (!strcmp (arg, table->name))
7444 if (table->alias < -1 || table->alias > 1)
7445 as_bad (_("`%s' is deprecated, use `%s'"),
7446 table->name, table[table->alias < 0 ? 1 : -1].name);
7452 /* Set the cpu, issuing errors if it is unrecognized. */
7455 m68k_set_cpu (char const *name, int allow_m, int silent)
7457 const struct m68k_cpu *cpu;
7459 cpu = m68k_lookup_cpu (name, m68k_cpus, allow_m, NULL);
7464 as_bad (_("cpu `%s' unrecognized"), name);
7471 /* Set the architecture, issuing errors if it is unrecognized. */
7474 m68k_set_arch (char const *name, int allow_m, int silent)
7476 const struct m68k_cpu *arch;
7478 arch = m68k_lookup_cpu (name, m68k_archs, allow_m, NULL);
7483 as_bad (_("architecture `%s' unrecognized"), name);
7486 selected_arch = arch;
7490 /* Set the architecture extension, issuing errors if it is
7491 unrecognized, or invalid */
7494 m68k_set_extension (char const *name, int allow_m, int silent)
7497 const struct m68k_cpu *ext;
7499 ext = m68k_lookup_cpu (name, m68k_extensions, allow_m, &negated);
7504 as_bad (_("extension `%s' unrecognized"), name);
7509 not_current_architecture |= (ext->control_regs
7510 ? *(unsigned *)ext->control_regs: ext->arch);
7512 current_architecture |= ext->arch;
7517 Invocation line includes a switch not recognized by the base assembler.
7521 const char *md_shortopts = "lSA:m:kQ:V";
7523 const char *md_shortopts = "lSA:m:k";
7526 struct option md_longopts[] = {
7527 #define OPTION_PIC (OPTION_MD_BASE)
7528 {"pic", no_argument, NULL, OPTION_PIC},
7529 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7530 {"register-prefix-optional", no_argument, NULL,
7531 OPTION_REGISTER_PREFIX_OPTIONAL},
7532 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7533 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
7534 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7535 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
7536 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7537 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
7538 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7539 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
7540 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7541 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
7542 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7543 {"pcrel", no_argument, NULL, OPTION_PCREL},
7544 {NULL, no_argument, NULL, 0}
7546 size_t md_longopts_size = sizeof (md_longopts);
7549 md_parse_option (int c, char *arg)
7553 case 'l': /* -l means keep external to 2 bit offset
7554 rather than 16 bit one. */
7555 flag_short_refs = 1;
7558 case 'S': /* -S means that jbsr's always turn into
7560 flag_long_jumps = 1;
7563 case OPTION_PCREL: /* --pcrel means never turn PC-relative
7564 branches into absolute jumps. */
7565 flag_keep_pcrel = 1;
7571 break; /* -pic, Position Independent Code. */
7573 case OPTION_REGISTER_PREFIX_OPTIONAL:
7574 flag_reg_prefix_optional = 1;
7575 reg_prefix_optional_seen = 1;
7578 /* -V: SVR4 argument to print version ID. */
7580 print_version_id ();
7583 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7584 should be emitted or not. FIXME: Not implemented. */
7588 case OPTION_BITWISE_OR:
7593 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
7595 for (s = m68k_comment_chars; *s != '\0'; s++)
7599 m68k_comment_chars = n;
7603 case OPTION_BASE_SIZE_DEFAULT_16:
7604 m68k_index_width_default = SIZE_WORD;
7607 case OPTION_BASE_SIZE_DEFAULT_32:
7608 m68k_index_width_default = SIZE_LONG;
7611 case OPTION_DISP_SIZE_DEFAULT_16:
7613 m68k_rel32_from_cmdline = 1;
7616 case OPTION_DISP_SIZE_DEFAULT_32:
7618 m68k_rel32_from_cmdline = 1;
7623 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7626 /* Intentional fall-through. */
7628 if (!strncmp (arg, "arch=", 5))
7629 m68k_set_arch (arg + 5, 1, 0);
7630 else if (!strncmp (arg, "cpu=", 4))
7631 m68k_set_cpu (arg + 4, 1, 0);
7632 else if (m68k_set_extension (arg, 0, 1))
7634 else if (m68k_set_arch (arg, 0, 1))
7636 else if (m68k_set_cpu (arg, 0, 1))
7649 /* Setup tables from the selected arch and/or cpu */
7652 m68k_init_arch (void)
7654 if (not_current_architecture & current_architecture)
7656 as_bad (_("architecture features both enabled and disabled"));
7657 not_current_architecture &= ~current_architecture;
7661 current_architecture |= selected_arch->arch;
7662 control_regs = selected_arch->control_regs;
7665 current_architecture |= selected_cpu->arch;
7667 current_architecture &= ~not_current_architecture;
7669 if ((current_architecture & (cfloat | m68881)) == (cfloat | m68881))
7671 /* Determine which float is really meant. */
7672 if (current_architecture & (m68k_mask & ~m68881))
7673 current_architecture ^= cfloat;
7675 current_architecture ^= m68881;
7680 control_regs = selected_cpu->control_regs;
7681 if (current_architecture & ~selected_cpu->arch)
7683 as_bad (_("selected processor does not have all features of selected architecture"));
7684 current_architecture
7685 = selected_cpu->arch & ~not_current_architecture;
7689 if ((current_architecture & m68k_mask)
7690 && (current_architecture & ~m68k_mask))
7692 as_bad (_ ("m68k and cf features both selected"));
7693 if (current_architecture & m68k_mask)
7694 current_architecture &= m68k_mask;
7696 current_architecture &= ~m68k_mask;
7699 /* Permit m68881 specification with all cpus; those that can't work
7700 with a coprocessor could be doing emulation. */
7701 if (current_architecture & m68851)
7703 if (current_architecture & m68040)
7704 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7706 /* What other incompatibilities could we check for? */
7708 if (cpu_of_arch (current_architecture) < m68020
7709 || arch_coldfire_p (current_architecture))
7710 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
7716 md_show_usage (FILE *stream)
7718 const char *default_cpu = TARGET_CPU;
7721 /* Get the canonical name for the default target CPU. */
7722 if (*default_cpu == 'm')
7724 for (i = 0; m68k_cpus[i].name; i++)
7726 if (strcasecmp (default_cpu, m68k_cpus[i].name) == 0)
7728 while (m68k_cpus[i].alias > 0)
7730 while (m68k_cpus[i].alias < 0)
7732 default_cpu = m68k_cpus[i].name;
7736 fprintf (stream, _("\
7737 -march=<arch> set architecture\n\
7738 -mcpu=<cpu> set cpu [default %s]\n\
7740 for (i = 0; m68k_extensions[i].name; i++)
7741 fprintf (stream, _("\
7742 -m[no-]%-16s enable/disable%s architecture extension\n\
7743 "), m68k_extensions[i].name,
7744 m68k_extensions[i].alias > 0 ? " ColdFire"
7745 : m68k_extensions[i].alias < 0 ? " m68k" : "");
7747 fprintf (stream, _("\
7748 -l use 1 word for refs to undefined symbols [default 2]\n\
7749 -pic, -k generate position independent code\n\
7750 -S turn jbsr into jsr\n\
7751 --pcrel never turn PC-relative branches into absolute jumps\n\
7752 --register-prefix-optional\n\
7753 recognize register names without prefix character\n\
7754 --bitwise-or do not treat `|' as a comment character\n\
7755 --base-size-default-16 base reg without size is 16 bits\n\
7756 --base-size-default-32 base reg without size is 32 bits (default)\n\
7757 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7758 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7761 fprintf (stream, _("Architecture variants are: "));
7762 for (i = 0; m68k_archs[i].name; i++)
7765 fprintf (stream, " | ");
7766 fprintf (stream, "%s", m68k_archs[i].name);
7768 fprintf (stream, "\n");
7770 fprintf (stream, _("Processor variants are: "));
7771 for (i = 0; m68k_cpus[i].name; i++)
7774 fprintf (stream, " | ");
7775 fprintf (stream, "%s", m68k_cpus[i].name);
7777 fprintf (stream, _("\n"));
7782 /* TEST2: Test md_assemble() */
7783 /* Warning, this routine probably doesn't work anymore. */
7787 struct m68k_it the_ins;
7795 if (!gets (buf) || !*buf)
7797 if (buf[0] == '|' || buf[1] == '.')
7799 for (cp = buf; *cp; cp++)
7804 memset (&the_ins, '\0', sizeof (the_ins));
7805 m68k_ip (&the_ins, buf);
7808 printf (_("Error %s in %s\n"), the_ins.error, buf);
7812 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7813 for (n = 0; n < the_ins.numo; n++)
7814 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7816 print_the_insn (&the_ins.opcode[0], stdout);
7817 (void) putchar ('\n');
7819 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7821 if (the_ins.operands[n].error)
7823 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7826 printf ("mode %d, reg %d, ", the_ins.operands[n].mode,
7827 the_ins.operands[n].reg);
7828 if (the_ins.operands[n].b_const)
7829 printf ("Constant: '%.*s', ",
7830 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const,
7831 the_ins.operands[n].b_const);
7832 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg,
7833 the_ins.operands[n].isiz, the_ins.operands[n].imul);
7834 if (the_ins.operands[n].b_iadd)
7835 printf ("Iadd: '%.*s',",
7836 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd,
7837 the_ins.operands[n].b_iadd);
7846 is_label (char *str)
7850 while (*str && *str != ' ')
7852 if (str[-1] == ':' || str[1] == '=')
7859 /* Possible states for relaxation:
7861 0 0 branch offset byte (bra, etc)
7865 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7869 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7876 /* We have no need to default values of symbols. */
7879 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
7884 /* Round up a section size to the appropriate boundary. */
7886 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
7889 /* For a.out, force the section size to be aligned. If we don't do
7890 this, BFD will align it for us, but it will not write out the
7891 final bytes of the section. This may be a bug in BFD, but it is
7892 easier to fix it here since that is how the other a.out targets
7896 align = bfd_get_section_alignment (stdoutput, segment);
7897 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7903 /* Exactly what point is a PC-relative offset relative TO?
7904 On the 68k, it is relative to the address of the first extension
7905 word. The difference between the addresses of the offset and the
7906 first extension word is stored in fx_pcrel_adjust. */
7908 md_pcrel_from (fixS *fixP)
7912 adjust = fixP->fx_pcrel_adjust;
7915 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7920 m68k_elf_final_processing (void)
7924 if (arch_coldfire_fpu (current_architecture))
7925 flags |= EF_M68K_CFV4E;
7926 /* Set file-specific flags if this is a cpu32 processor. */
7927 if (cpu_of_arch (current_architecture) & cpu32)
7928 flags |= EF_M68K_CPU32;
7929 else if (cpu_of_arch (current_architecture) & fido_a)
7930 flags |= EF_M68K_FIDO;
7931 else if ((cpu_of_arch (current_architecture) & m68000up)
7932 && !(cpu_of_arch (current_architecture) & m68020up))
7933 flags |= EF_M68K_M68000;
7935 if (current_architecture & mcfisa_a)
7937 static const unsigned isa_features[][2] =
7939 {EF_M68K_CF_ISA_A_NODIV,mcfisa_a},
7940 {EF_M68K_CF_ISA_A, mcfisa_a|mcfhwdiv},
7941 {EF_M68K_CF_ISA_A_PLUS, mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp},
7942 {EF_M68K_CF_ISA_B_NOUSP,mcfisa_a|mcfisa_b|mcfhwdiv},
7943 {EF_M68K_CF_ISA_B, mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp},
7944 {EF_M68K_CF_ISA_C, mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp},
7945 {EF_M68K_CF_ISA_C_NODIV,mcfisa_a|mcfisa_c|mcfusp},
7948 static const unsigned mac_features[][2] =
7950 {EF_M68K_CF_MAC, mcfmac},
7951 {EF_M68K_CF_EMAC, mcfemac},
7957 pattern = (current_architecture
7958 & (mcfisa_a|mcfisa_aa|mcfisa_b|mcfisa_c|mcfhwdiv|mcfusp));
7959 for (ix = 0; isa_features[ix][1]; ix++)
7961 if (pattern == isa_features[ix][1])
7963 flags |= isa_features[ix][0];
7967 if (!isa_features[ix][1])
7970 as_warn (_("Not a defined coldfire architecture"));
7974 if (current_architecture & cfloat)
7975 flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
7977 pattern = current_architecture & (mcfmac|mcfemac);
7980 for (ix = 0; mac_features[ix][1]; ix++)
7982 if (pattern == mac_features[ix][1])
7984 flags |= mac_features[ix][0];
7988 if (!mac_features[ix][1])
7993 elf_elfheader (stdoutput)->e_flags |= flags;
7996 /* Parse @TLSLDO and return the desired relocation. */
7997 static bfd_reloc_code_real_type
7998 m68k_elf_suffix (char **str_p, expressionS *exp_p)
8007 return BFD_RELOC_UNUSED;
8009 for (ch = *str, str2 = ident;
8010 (str2 < ident + sizeof (ident) - 1
8011 && (ISALNUM (ch) || ch == '@'));
8020 if (strncmp (ident, "TLSLDO", 6) == 0
8023 /* Now check for identifier@suffix+constant. */
8024 if (*str == '-' || *str == '+')
8026 char *orig_line = input_line_pointer;
8027 expressionS new_exp;
8029 input_line_pointer = str;
8030 expression (&new_exp);
8031 if (new_exp.X_op == O_constant)
8033 exp_p->X_add_number += new_exp.X_add_number;
8034 str = input_line_pointer;
8037 if (&input_line_pointer != str_p)
8038 input_line_pointer = orig_line;
8042 return BFD_RELOC_68K_TLS_LDO32;
8045 return BFD_RELOC_UNUSED;
8048 /* Handles .long <tls_symbol>+0x8000 debug info.
8049 Clobbers input_line_pointer, checks end-of-line.
8050 Adapted from tc-ppc.c:ppc_elf_cons. */
8052 m68k_elf_cons (int nbytes /* 4=.long */)
8054 if (is_it_end_of_statement ())
8056 demand_empty_rest_of_line ();
8063 bfd_reloc_code_real_type reloc;
8066 if (exp.X_op == O_symbol
8067 && *input_line_pointer == '@'
8068 && (reloc = m68k_elf_suffix (&input_line_pointer,
8069 &exp)) != BFD_RELOC_UNUSED)
8071 reloc_howto_type *reloc_howto;
8074 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
8075 size = bfd_get_reloc_size (reloc_howto);
8079 as_bad (_("%s relocations do not fit in %d bytes\n"),
8080 reloc_howto->name, nbytes);
8087 p = frag_more (nbytes);
8089 if (target_big_endian)
8090 offset = nbytes - size;
8091 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
8096 emit_expr (&exp, (unsigned int) nbytes);
8098 while (*input_line_pointer++ == ',');
8100 /* Put terminator back into stream. */
8101 input_line_pointer--;
8102 demand_empty_rest_of_line ();
8107 tc_m68k_regname_to_dw2regnum (char *regname)
8109 unsigned int regnum;
8110 static const char *const regnames[] =
8112 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
8113 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
8114 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
8118 for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
8119 if (strcmp (regname, regnames[regnum]) == 0)
8126 tc_m68k_frame_initial_instructions (void)
8128 static int sp_regno = -1;
8131 sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
8133 cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
8134 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);
8137 /* Check and emit error if broken-word handling has failed to fix up a
8138 case-table. This is called from write.c, after doing everything it
8139 knows about how to handle broken words. */
8142 tc_m68k_check_adjusted_broken_word (offsetT new_offset, struct broken_word *brokwP)
8144 if (new_offset > 32767 || new_offset < -32768)
8145 as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line,
8146 _("Adjusted signed .word (%#lx) overflows: `switch'-statement too large."),