1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/m68k.h"
28 #include "m68k-parse.h"
34 /* This string holds the chars that always start a comment. If the
35 pre-processor is disabled, these aren't very useful. The macro
36 tc_comment_chars points to this. We use this, rather than the
37 usual comment_chars, so that the --bitwise-or option will work. */
38 #if defined (TE_SVR4) || defined (TE_DELTA)
39 const char *m68k_comment_chars = "|#";
41 const char *m68k_comment_chars = "|";
44 /* This array holds the chars that only start a comment at the beginning of
45 a line. If the line seems to have the form '# 123 filename'
46 .line and .file directives will appear in the pre-processed output */
47 /* Note that input_file.c hand checks for '#' at the beginning of the
48 first line of the input file. This is because the compiler outputs
49 #NO_APP at the beginning of its output. */
50 /* Also note that comments like this one will always work. */
51 const char line_comment_chars[] = "#*";
53 const char line_separator_chars[] = ";";
55 /* Chars that can be used to separate mant from exp in floating point nums */
56 CONST char EXP_CHARS[] = "eE";
58 /* Chars that mean this number is a floating point constant, as
59 in "0f12.456" or "0d1.2345e12". */
61 CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
63 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
64 changed in read.c . Ideally it shouldn't have to know about it at all,
65 but nothing is ideal around here. */
67 const int md_reloc_size = 8; /* Size of relocation record */
69 /* Are we trying to generate PIC code? If so, absolute references
70 ought to be made into linkage table references or pc-relative
71 references. Not implemented. For ELF there are other means
72 to denote pic relocations. */
75 static int flag_short_refs; /* -l option */
76 static int flag_long_jumps; /* -S option */
78 #ifdef REGISTER_PREFIX_OPTIONAL
79 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
81 int flag_reg_prefix_optional;
84 /* Whether --register-prefix-optional was used on the command line. */
85 static int reg_prefix_optional_seen;
87 /* The floating point coprocessor to use by default. */
88 static enum m68k_register m68k_float_copnum = COP1;
90 /* If this is non-zero, then references to number(%pc) will be taken
91 to refer to number, rather than to %pc + number. */
92 static int m68k_abspcadd;
94 /* If this is non-zero, then the quick forms of the move, add, and sub
95 instructions are used when possible. */
96 static int m68k_quick = 1;
98 /* If this is non-zero, then if the size is not specified for a base
99 or outer displacement, the assembler assumes that the size should
101 static int m68k_rel32 = 1;
103 /* This is non-zero if m68k_rel32 was set from the command line. */
104 static int m68k_rel32_from_cmdline;
106 /* The default width to use for an index register when using a base
108 static enum m68k_size m68k_index_width_default = SIZE_LONG;
110 /* We want to warn if any text labels are misaligned. In order to get
111 the right line number, we need to record the line number for each
116 struct label_line *next;
123 /* The list of labels. */
125 static struct label_line *labels;
127 /* The current label. */
129 static struct label_line *current_label;
131 /* Its an arbitrary name: This means I don't approve of it */
132 /* See flames below */
133 static struct obstack robyn;
135 #define TAB(x,y) (((x)<<2)+(y))
136 #define TABTYPE(xy) ((xy) >> 2)
142 /* Case `g' except when BCC68000 is applicable. */
144 /* Coprocessor branches. */
146 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
147 supported on all cpus. Widens to 32-bit absolute. */
149 /* For inserting an extra jmp instruction with long offset on 68000,
150 for expanding conditional branches. (Not bsr or bra.) Since the
151 68000 doesn't support 32-bit displacements for conditional
152 branches, we fake it by reversing the condition and branching
153 around a jmp with an absolute long operand. */
155 /* For the DBcc "instructions". If the displacement requires 32 bits,
156 the branch-around-a-jump game is played here too. */
158 /* Not currently used? */
160 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
166 const char *m_operands;
167 unsigned long m_opcode;
171 struct m68k_incant *m_next;
174 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
175 #define gettwo(x) (((x)->m_opcode)&0xffff)
177 static const enum m68k_register m68000_control_regs[] = { 0 };
178 static const enum m68k_register m68010_control_regs[] = {
182 static const enum m68k_register m68020_control_regs[] = {
183 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
186 static const enum m68k_register m68040_control_regs[] = {
187 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
188 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
191 static const enum m68k_register m68060_control_regs[] = {
192 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
193 USP, VBR, URP, SRP, PCR,
196 static const enum m68k_register mcf_control_regs[] = {
197 CACR, TC, ITT0, ITT1, DTT0, DTT1, VBR, ROMBAR,
198 RAMBAR0, RAMBAR1, MBAR,
201 #define cpu32_control_regs m68010_control_regs
203 static const enum m68k_register *control_regs;
205 /* internal form of a 68020 instruction */
209 const char *args; /* list of opcode info */
212 int numo; /* Number of shorts in opcode */
215 struct m68k_op operands[6];
217 int nexp; /* number of exprs in use */
218 struct m68k_exp exprs[4];
220 int nfrag; /* Number of frags we have to produce */
223 int fragoff; /* Where in the current opcode the frag ends */
230 int nrel; /* Num of reloc strucs in use */
237 /* In a pc relative address the difference between the address
238 of the offset and the address that the offset is relative
239 to. This depends on the addressing mode. Basically this
240 is the value to put in the offset field to address the
241 first byte of the offset, without regarding the special
242 significance of some values (in the branch instruction, for
246 /* Whether this expression needs special pic relocation, and if
248 enum pic_relocation pic_reloc;
251 reloc[5]; /* Five is enough??? */
254 #define cpu_of_arch(x) ((x) & (m68000up|mcf))
255 #define float_of_arch(x) ((x) & mfloat)
256 #define mmu_of_arch(x) ((x) & mmmu)
257 #define arch_coldfire_p(x) (((x) & mcf) != 0)
259 /* Macros for determining if cpu supports a specific addressing mode */
260 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32))
262 static struct m68k_it the_ins; /* the instruction being assembled */
264 #define op(ex) ((ex)->exp.X_op)
265 #define adds(ex) ((ex)->exp.X_add_symbol)
266 #define subs(ex) ((ex)->exp.X_op_symbol)
267 #define offs(ex) ((ex)->exp.X_add_number)
269 /* Macros for adding things to the m68k_it struct */
271 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
273 /* Static functions. */
275 static void insop PARAMS ((int, const struct m68k_incant *));
276 static void add_fix PARAMS ((int, struct m68k_exp *, int, int));
277 static void add_frag PARAMS ((symbolS *, offsetT, int));
279 /* Like addword, but goes BEFORE general operands */
283 const struct m68k_incant *opcode;
286 for(z=the_ins.numo;z>opcode->m_codenum;--z)
287 the_ins.opcode[z]=the_ins.opcode[z-1];
288 for(z=0;z<the_ins.nrel;z++)
289 the_ins.reloc[z].n+=2;
290 for (z = 0; z < the_ins.nfrag; z++)
291 the_ins.fragb[z].fragoff++;
292 the_ins.opcode[opcode->m_codenum]=w;
296 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
299 add_fix (width, exp, pc_rel, pc_fix)
301 struct m68k_exp *exp;
305 the_ins.reloc[the_ins.nrel].n = ((width == 'B' || width == '3')
309 : (the_ins.numo*2)));
310 the_ins.reloc[the_ins.nrel].exp = exp->exp;
311 the_ins.reloc[the_ins.nrel].wid = width;
312 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
314 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
316 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
319 /* Cause an extra frag to be generated here, inserting up to 10 bytes
320 (that value is chosen in the frag_var call in md_assemble). TYPE
321 is the subtype of the frag to be generated; its primary type is
322 rs_machine_dependent.
324 The TYPE parameter is also used by md_convert_frag_1 and
325 md_estimate_size_before_relax. The appropriate type of fixup will
326 be emitted by md_convert_frag_1.
328 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
330 add_frag (add, off, type)
335 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;
336 the_ins.fragb[the_ins.nfrag].fadd=add;
337 the_ins.fragb[the_ins.nfrag].foff=off;
338 the_ins.fragb[the_ins.nfrag++].fragty=type;
342 (op (ex) != O_constant && op (ex) != O_big)
344 static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
345 static int get_num PARAMS ((struct m68k_exp *exp, int ok));
346 static void m68k_ip PARAMS ((char *));
347 static void insert_reg PARAMS ((const char *, int));
348 static void select_control_regs PARAMS ((void));
349 static void init_regtable PARAMS ((void));
350 static int reverse_16_bits PARAMS ((int in));
351 static int reverse_8_bits PARAMS ((int in));
352 static void install_gen_operand PARAMS ((int mode, int val));
353 static void install_operand PARAMS ((int mode, int val));
354 static void s_bss PARAMS ((int));
355 static void s_data1 PARAMS ((int));
356 static void s_data2 PARAMS ((int));
357 static void s_even PARAMS ((int));
358 static void s_proc PARAMS ((int));
359 static void mri_chip PARAMS ((void));
360 static void s_chip PARAMS ((int));
361 static void s_fopt PARAMS ((int));
362 static void s_opt PARAMS ((int));
363 static void s_reg PARAMS ((int));
364 static void s_restore PARAMS ((int));
365 static void s_save PARAMS ((int));
366 static void s_mri_if PARAMS ((int));
367 static void s_mri_else PARAMS ((int));
368 static void s_mri_endi PARAMS ((int));
369 static void s_mri_break PARAMS ((int));
370 static void s_mri_next PARAMS ((int));
371 static void s_mri_for PARAMS ((int));
372 static void s_mri_endf PARAMS ((int));
373 static void s_mri_repeat PARAMS ((int));
374 static void s_mri_until PARAMS ((int));
375 static void s_mri_while PARAMS ((int));
376 static void s_mri_endw PARAMS ((int));
377 static void md_apply_fix_2 PARAMS ((fixS *, offsetT));
378 static void md_convert_frag_1 PARAMS ((fragS *));
380 static int current_architecture;
388 static const struct m68k_cpu archs[] = {
389 { m68000, "68000", 0 },
390 { m68010, "68010", 0 },
391 { m68020, "68020", 0 },
392 { m68030, "68030", 0 },
393 { m68040, "68040", 0 },
394 { m68060, "68060", 0 },
395 { cpu32, "cpu32", 0 },
396 { m68881, "68881", 0 },
397 { m68851, "68851", 0 },
398 { mcf5200, "5200", 0 },
399 { mcf5206e, "5206e", 0 },
400 { mcf5307, "5307", 0},
401 /* Aliases (effectively, so far as gas is concerned) for the above
403 { m68020, "68k", 1 },
404 { m68000, "68008", 1 },
405 { m68000, "68302", 1 },
406 { m68000, "68306", 1 },
407 { m68000, "68307", 1 },
408 { m68000, "68322", 1 },
409 { m68000, "68356", 1 },
410 { m68000, "68ec000", 1 },
411 { m68000, "68hc000", 1 },
412 { m68000, "68hc001", 1 },
413 { m68020, "68ec020", 1 },
414 { m68030, "68ec030", 1 },
415 { m68040, "68ec040", 1 },
416 { m68060, "68ec060", 1 },
417 { cpu32, "68330", 1 },
418 { cpu32, "68331", 1 },
419 { cpu32, "68332", 1 },
420 { cpu32, "68333", 1 },
421 { cpu32, "68334", 1 },
422 { cpu32, "68336", 1 },
423 { cpu32, "68340", 1 },
424 { cpu32, "68341", 1 },
425 { cpu32, "68349", 1 },
426 { cpu32, "68360", 1 },
427 { m68881, "68882", 1 },
428 { mcf5200, "5202", 1 },
429 { mcf5200, "5204", 1 },
430 { mcf5200, "5206", 1 },
433 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
435 /* BCC68000 is for patching in an extra jmp instruction for long offsets
436 on the 68000. The 68000 doesn't support long branches with branchs */
438 /* This table desribes how you change sizes for the various types of variable
439 size expressions. This version only supports two kinds. */
441 /* Note that calls to frag_var need to specify the maximum expansion
442 needed; this is currently 10 bytes for DBCC. */
445 How far Forward this mode will reach:
446 How far Backward this mode will reach:
447 How many bytes this mode will add to the size of the frag
448 Which mode to go to if the offset won't fit in this one
450 relax_typeS md_relax_table[] =
452 {1, 1, 0, 0}, /* First entries aren't used */
453 {1, 1, 0, 0}, /* For no good reason except */
454 {1, 1, 0, 0}, /* that the VAX doesn't either */
457 {(127), (-128), 0, TAB (ABRANCH, SHORT)},
458 {(32767), (-32768), 2, TAB (ABRANCH, LONG)},
462 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
463 {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
467 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
468 {(32767), (-32768), 2, TAB (PCREL, LONG)},
472 {(127), (-128), 0, TAB (BCC68000, SHORT)},
473 {(32767), (-32768), 2, TAB (BCC68000, LONG)},
474 {0, 0, 6, 0}, /* jmp long space */
477 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
478 {(32767), (-32768), 2, TAB (DBCC, LONG)},
479 {0, 0, 10, 0}, /* bra/jmp long space */
482 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
483 {32767, -32768, 2, TAB (PCLEA, LONG)},
487 /* For, e.g., jmp pcrel indexed. */
488 {125, -130, 0, TAB (PCINDEX, SHORT)},
489 {32765, -32770, 2, TAB (PCINDEX, LONG)},
494 /* These are the machine dependent pseudo-ops. These are included so
495 the assembler can work on the output from the SUN C compiler, which
499 /* This table describes all the machine specific pseudo-ops the assembler
500 has to support. The fields are:
501 pseudo-op name without dot
502 function to call to execute this pseudo-op
503 Integer arg to pass to the function
505 const pseudo_typeS md_pseudo_table[] =
507 {"data1", s_data1, 0},
508 {"data2", s_data2, 0},
511 {"skip", s_space, 0},
513 #if defined (TE_SUN3) || defined (OBJ_ELF)
514 {"align", s_align_bytes, 0},
517 {"swbeg", s_ignore, 0},
519 {"extend", float_cons, 'x'},
520 {"ldouble", float_cons, 'x'},
522 /* The following pseudo-ops are supported for MRI compatibility. */
524 {"comline", s_space, 1},
526 {"mask2", s_ignore, 0},
529 {"restore", s_restore, 0},
533 {"if.b", s_mri_if, 'b'},
534 {"if.w", s_mri_if, 'w'},
535 {"if.l", s_mri_if, 'l'},
536 {"else", s_mri_else, 0},
537 {"else.s", s_mri_else, 's'},
538 {"else.l", s_mri_else, 'l'},
539 {"endi", s_mri_endi, 0},
540 {"break", s_mri_break, 0},
541 {"break.s", s_mri_break, 's'},
542 {"break.l", s_mri_break, 'l'},
543 {"next", s_mri_next, 0},
544 {"next.s", s_mri_next, 's'},
545 {"next.l", s_mri_next, 'l'},
546 {"for", s_mri_for, 0},
547 {"for.b", s_mri_for, 'b'},
548 {"for.w", s_mri_for, 'w'},
549 {"for.l", s_mri_for, 'l'},
550 {"endf", s_mri_endf, 0},
551 {"repeat", s_mri_repeat, 0},
552 {"until", s_mri_until, 0},
553 {"until.b", s_mri_until, 'b'},
554 {"until.w", s_mri_until, 'w'},
555 {"until.l", s_mri_until, 'l'},
556 {"while", s_mri_while, 0},
557 {"while.b", s_mri_while, 'b'},
558 {"while.w", s_mri_while, 'w'},
559 {"while.l", s_mri_while, 'l'},
560 {"endw", s_mri_endw, 0},
566 /* The mote pseudo ops are put into the opcode table, since they
567 don't start with a . they look like opcodes to gas.
571 extern void obj_coff_section PARAMS ((int));
574 CONST pseudo_typeS mote_pseudo_table[] =
587 {"xdef", s_globl, 0},
589 {"align", s_align_bytes, 0},
591 {"align", s_align_ptwo, 0},
594 {"sect", obj_coff_section, 0},
595 {"section", obj_coff_section, 0},
600 #define issbyte(x) ((x)>=-128 && (x)<=127)
601 #define isubyte(x) ((x)>=0 && (x)<=255)
602 #define issword(x) ((x)>=-32768 && (x)<=32767)
603 #define isuword(x) ((x)>=0 && (x)<=65535)
605 #define isbyte(x) ((x)>= -255 && (x)<=255)
606 #define isword(x) ((x)>=-65536 && (x)<=65535)
607 #define islong(x) (1)
609 extern char *input_line_pointer;
611 static char mklower_table[256];
612 #define mklower(c) (mklower_table[(unsigned char)(c)])
613 static char notend_table[256];
614 static char alt_notend_table[256];
616 (! (notend_table[(unsigned char) *s] \
618 && alt_notend_table[(unsigned char) s[1]])))
620 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
622 #ifdef NO_PCREL_RELOCS
625 make_pcrel_absolute(fixP, add_number)
629 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
631 /* rewrite the PC relative instructions to absolute address ones.
632 * these are rumoured to be faster, and the apollo linker refuses
633 * to deal with the PC relative relocations.
635 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
640 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
646 as_fatal (_("Unknown PC relative instruction"));
651 #endif /* NO_PCREL_RELOCS */
654 tc_coff_fix2rtype (fixP)
657 if (fixP->fx_tcbit && fixP->fx_size == 4)
658 return R_RELLONG_NEG;
659 #ifdef NO_PCREL_RELOCS
660 know (fixP->fx_pcrel == 0);
661 return (fixP->fx_size == 1 ? R_RELBYTE
662 : fixP->fx_size == 2 ? R_DIR16
665 return (fixP->fx_pcrel ?
666 (fixP->fx_size == 1 ? R_PCRBYTE :
667 fixP->fx_size == 2 ? R_PCRWORD :
669 (fixP->fx_size == 1 ? R_RELBYTE :
670 fixP->fx_size == 2 ? R_RELWORD :
679 /* Compute the relocation code for a fixup of SIZE bytes, using pc
680 relative relocation if PCREL is non-zero. PIC says whether a special
681 pic relocation was requested. */
683 static bfd_reloc_code_real_type get_reloc_code
684 PARAMS ((int, int, enum pic_relocation));
686 static bfd_reloc_code_real_type
687 get_reloc_code (size, pcrel, pic)
690 enum pic_relocation pic;
698 return BFD_RELOC_8_GOT_PCREL;
700 return BFD_RELOC_16_GOT_PCREL;
702 return BFD_RELOC_32_GOT_PCREL;
710 return BFD_RELOC_8_GOTOFF;
712 return BFD_RELOC_16_GOTOFF;
714 return BFD_RELOC_32_GOTOFF;
722 return BFD_RELOC_8_PLT_PCREL;
724 return BFD_RELOC_16_PLT_PCREL;
726 return BFD_RELOC_32_PLT_PCREL;
734 return BFD_RELOC_8_PLTOFF;
736 return BFD_RELOC_16_PLTOFF;
738 return BFD_RELOC_32_PLTOFF;
748 return BFD_RELOC_8_PCREL;
750 return BFD_RELOC_16_PCREL;
752 return BFD_RELOC_32_PCREL;
772 as_bad (_("Can not do %d byte pc-relative relocation"), size);
774 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
779 as_bad (_("Can not do %d byte relocation"), size);
781 as_bad (_("Can not do %d byte pic relocation"), size);
784 return BFD_RELOC_NONE;
787 /* Here we decide which fixups can be adjusted to make them relative
788 to the beginning of the section instead of the symbol. Basically
789 we need to make sure that the dynamic relocations are done
790 correctly, so in some cases we force the original symbol to be
793 tc_m68k_fix_adjustable (fixP)
796 /* Prevent all adjustments to global symbols. */
797 if (S_IS_EXTERNAL (fixP->fx_addsy)
798 || S_IS_WEAK (fixP->fx_addsy))
801 /* adjust_reloc_syms doesn't know about the GOT */
802 switch (fixP->fx_r_type)
804 case BFD_RELOC_8_GOT_PCREL:
805 case BFD_RELOC_16_GOT_PCREL:
806 case BFD_RELOC_32_GOT_PCREL:
807 case BFD_RELOC_8_GOTOFF:
808 case BFD_RELOC_16_GOTOFF:
809 case BFD_RELOC_32_GOTOFF:
810 case BFD_RELOC_8_PLT_PCREL:
811 case BFD_RELOC_16_PLT_PCREL:
812 case BFD_RELOC_32_PLT_PCREL:
813 case BFD_RELOC_8_PLTOFF:
814 case BFD_RELOC_16_PLTOFF:
815 case BFD_RELOC_32_PLTOFF:
818 case BFD_RELOC_VTABLE_INHERIT:
819 case BFD_RELOC_VTABLE_ENTRY:
829 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
836 tc_gen_reloc (section, fixp)
841 bfd_reloc_code_real_type code;
846 if (fixp->fx_r_type != BFD_RELOC_NONE)
848 code = fixp->fx_r_type;
850 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
851 that fixup_segment converted a non-PC relative reloc into a
852 PC relative reloc. In such a case, we need to convert the
859 code = BFD_RELOC_8_PCREL;
862 code = BFD_RELOC_16_PCREL;
865 code = BFD_RELOC_32_PCREL;
867 case BFD_RELOC_8_PCREL:
868 case BFD_RELOC_16_PCREL:
869 case BFD_RELOC_32_PCREL:
870 case BFD_RELOC_8_GOT_PCREL:
871 case BFD_RELOC_16_GOT_PCREL:
872 case BFD_RELOC_32_GOT_PCREL:
873 case BFD_RELOC_8_GOTOFF:
874 case BFD_RELOC_16_GOTOFF:
875 case BFD_RELOC_32_GOTOFF:
876 case BFD_RELOC_8_PLT_PCREL:
877 case BFD_RELOC_16_PLT_PCREL:
878 case BFD_RELOC_32_PLT_PCREL:
879 case BFD_RELOC_8_PLTOFF:
880 case BFD_RELOC_16_PLTOFF:
881 case BFD_RELOC_32_PLTOFF:
884 as_bad_where (fixp->fx_file, fixp->fx_line,
885 _("Cannot make %s relocation PC relative"),
886 bfd_get_reloc_code_name (code));
892 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
893 switch (F (fixp->fx_size, fixp->fx_pcrel))
895 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
896 MAP (1, 0, BFD_RELOC_8);
897 MAP (2, 0, BFD_RELOC_16);
898 MAP (4, 0, BFD_RELOC_32);
899 MAP (1, 1, BFD_RELOC_8_PCREL);
900 MAP (2, 1, BFD_RELOC_16_PCREL);
901 MAP (4, 1, BFD_RELOC_32_PCREL);
909 reloc = (arelent *) xmalloc (sizeof (arelent));
910 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
911 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
912 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
915 reloc->addend = fixp->fx_addnumber;
920 reloc->addend = fixp->fx_addnumber;
922 reloc->addend = (section->vma
923 + (fixp->fx_pcrel_adjust == 64
924 ? -1 : fixp->fx_pcrel_adjust)
926 + md_pcrel_from (fixp));
929 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
930 assert (reloc->howto != 0);
935 #endif /* BFD_ASSEMBLER */
937 /* Return zero if the reference to SYMBOL from within the same segment may
941 /* On an ELF system, we can't relax an externally visible symbol,
942 because it may be overridden by a shared library. However, if
943 TARGET_OS is "elf", then we presume that we are assembling for an
944 embedded system, in which case we don't have to worry about shared
945 libraries, and we can relax anything. */
947 #define relaxable_symbol(symbol) \
948 (strcmp (TARGET_OS, "elf") == 0 \
949 || (! S_IS_EXTERNAL (symbol) \
950 && ! S_IS_WEAK (symbol)))
954 #define relaxable_symbol(symbol) 1
958 /* Handle of the OPCODE hash table. NULL means any use before
959 m68k_ip_begin() will crash. */
960 static struct hash_control *op_hash;
962 /* Assemble an m68k instruction. */
969 register struct m68k_op *opP;
970 register const struct m68k_incant *opcode;
971 register const char *s;
972 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
973 char *pdot, *pdotmove;
974 enum m68k_size siz1, siz2;
978 LITTLENUM_TYPE words[6];
979 LITTLENUM_TYPE *wordp;
980 unsigned long ok_arch = 0;
982 if (*instring == ' ')
983 instring++; /* skip leading whitespace */
985 /* Scan up to end of operation-code, which MUST end in end-of-string
986 or exactly 1 space. */
988 for (p = instring; *p != '\0'; p++)
998 the_ins.error = _("No operator");
1002 /* p now points to the end of the opcode name, probably whitespace.
1003 Make sure the name is null terminated by clobbering the
1004 whitespace, look it up in the hash table, then fix it back.
1005 Remove a dot, first, since the opcode tables have none. */
1008 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1009 *pdotmove = pdotmove[1];
1015 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1020 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1021 *pdotmove = pdotmove[-1];
1028 the_ins.error = _("Unknown operator");
1032 /* found a legitimate opcode, start matching operands */
1036 if (opcode->m_operands == 0)
1038 char *old = input_line_pointer;
1040 input_line_pointer = p;
1041 /* Ahh - it's a motorola style psuedo op */
1042 mote_pseudo_table[opcode->m_opnum].poc_handler
1043 (mote_pseudo_table[opcode->m_opnum].poc_val);
1044 input_line_pointer = old;
1050 if (flag_mri && opcode->m_opnum == 0)
1052 /* In MRI mode, random garbage is allowed after an instruction
1053 which accepts no operands. */
1054 the_ins.args = opcode->m_operands;
1055 the_ins.numargs = opcode->m_opnum;
1056 the_ins.numo = opcode->m_codenum;
1057 the_ins.opcode[0] = getone (opcode);
1058 the_ins.opcode[1] = gettwo (opcode);
1062 for (opP = &the_ins.operands[0]; *p; opP++)
1064 p = crack_operand (p, opP);
1068 the_ins.error = opP->error;
1073 opsfound = opP - &the_ins.operands[0];
1075 /* This ugly hack is to support the floating pt opcodes in their
1076 standard form. Essentially, we fake a first enty of type COP#1 */
1077 if (opcode->m_operands[0] == 'I')
1081 for (n = opsfound; n > 0; --n)
1082 the_ins.operands[n] = the_ins.operands[n - 1];
1084 memset ((char *) (&the_ins.operands[0]), '\0',
1085 sizeof (the_ins.operands[0]));
1086 the_ins.operands[0].mode = CONTROL;
1087 the_ins.operands[0].reg = m68k_float_copnum;
1091 /* We've got the operands. Find an opcode that'll accept them */
1094 /* If we didn't get the right number of ops, or we have no
1095 common model with this pattern then reject this pattern. */
1097 ok_arch |= opcode->m_arch;
1098 if (opsfound != opcode->m_opnum
1099 || ((opcode->m_arch & current_architecture) == 0))
1103 for (s = opcode->m_operands, opP = &the_ins.operands[0];
1107 /* Warning: this switch is huge! */
1108 /* I've tried to organize the cases into this order:
1109 non-alpha first, then alpha by letter. Lower-case
1110 goes directly before uppercase counterpart. */
1111 /* Code with multiple case ...: gets sorted by the lowest
1112 case ... it belongs to. I hope this makes sense. */
1218 if (opP->reg == PC || opP->reg == ZPC)
1235 if (opP->reg == PC || opP->reg == ZPC)
1254 if (opP->reg == PC || opP->reg == ZPC)
1264 if (opP->mode != IMMED)
1266 else if (s[1] == 'b'
1267 && ! isvar (&opP->disp)
1268 && (opP->disp.exp.X_op != O_constant
1269 || ! isbyte (opP->disp.exp.X_add_number)))
1271 else if (s[1] == 'B'
1272 && ! isvar (&opP->disp)
1273 && (opP->disp.exp.X_op != O_constant
1274 || ! issbyte (opP->disp.exp.X_add_number)))
1276 else if (s[1] == 'w'
1277 && ! isvar (&opP->disp)
1278 && (opP->disp.exp.X_op != O_constant
1279 || ! isword (opP->disp.exp.X_add_number)))
1281 else if (s[1] == 'W'
1282 && ! isvar (&opP->disp)
1283 && (opP->disp.exp.X_op != O_constant
1284 || ! issword (opP->disp.exp.X_add_number)))
1290 if (opP->mode != IMMED)
1295 if (opP->mode == AREG
1296 || opP->mode == CONTROL
1297 || opP->mode == FPREG
1298 || opP->mode == IMMED
1299 || opP->mode == REGLST
1300 || (opP->mode != ABSL
1302 || opP->reg == ZPC)))
1307 if (opP->mode == CONTROL
1308 || opP->mode == FPREG
1309 || opP->mode == REGLST
1310 || opP->mode == IMMED
1311 || (opP->mode != ABSL
1313 || opP->reg == ZPC)))
1341 if (opP->mode == CONTROL
1342 || opP->mode == FPREG
1343 || opP->mode == REGLST)
1348 if (opP->mode != AINC)
1353 if (opP->mode != ADEC)
1403 if (opP->reg == PC || opP->reg == ZPC)
1424 case '~': /* For now! (JF FOO is this right?) */
1446 if (opP->mode != CONTROL
1447 || (opP->reg != TT0 && opP->reg != TT1))
1452 if (opP->mode != AREG)
1457 if (opP->mode != AINDR)
1462 if (opP->mode != ABSL
1464 && strncmp (instring, "jbsr", 4) == 0))
1469 if (opP->mode != CONTROL || opP->reg != CCR)
1474 if (opP->mode != DISP
1476 || opP->reg > ADDR7)
1481 if (opP->mode != DREG)
1486 if (opP->reg != ACC)
1491 if (opP->mode != FPREG)
1496 if (opP->reg != MACSR)
1501 if (opP->reg != MASK)
1506 if (opP->mode != CONTROL
1513 if (opP->mode != CONTROL
1515 || opP->reg > last_movec_reg)
1519 const enum m68k_register *rp;
1520 for (rp = control_regs; *rp; rp++)
1521 if (*rp == opP->reg)
1529 if (opP->mode != IMMED)
1535 if (opP->mode == DREG
1536 || opP->mode == AREG
1537 || opP->mode == FPREG)
1546 opP->mask = 1 << (opP->reg - DATA0);
1549 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1552 opP->mask = 1 << (opP->reg - FP0 + 16);
1560 else if (opP->mode == CONTROL)
1569 opP->mask = 1 << 24;
1572 opP->mask = 1 << 25;
1575 opP->mask = 1 << 26;
1584 else if (opP->mode != REGLST)
1586 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1588 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1593 if (opP->mode != IMMED)
1595 else if (opP->disp.exp.X_op != O_constant
1596 || ! issbyte (opP->disp.exp.X_add_number))
1598 else if (! m68k_quick
1599 && instring[3] != 'q'
1600 && instring[4] != 'q')
1605 if (opP->mode != DREG
1606 && opP->mode != IMMED
1607 && opP->mode != ABSL)
1612 if (opP->mode != IMMED)
1614 else if (opP->disp.exp.X_op != O_constant
1615 || opP->disp.exp.X_add_number < 1
1616 || opP->disp.exp.X_add_number > 8)
1618 else if (! m68k_quick
1619 && (strncmp (instring, "add", 3) == 0
1620 || strncmp (instring, "sub", 3) == 0)
1621 && instring[3] != 'q')
1626 if (opP->mode != DREG && opP->mode != AREG)
1631 if (opP->mode != AINDR
1632 && (opP->mode != BASE
1634 && opP->reg != ZADDR0)
1635 || opP->disp.exp.X_op != O_absent
1636 || ((opP->index.reg < DATA0
1637 || opP->index.reg > DATA7)
1638 && (opP->index.reg < ADDR0
1639 || opP->index.reg > ADDR7))
1640 || opP->index.size != SIZE_UNSPEC
1641 || opP->index.scale != 1))
1646 if (opP->mode != CONTROL
1647 || ! (opP->reg == FPI
1649 || opP->reg == FPC))
1654 if (opP->mode != CONTROL || opP->reg != SR)
1659 if (opP->mode != IMMED)
1661 else if (opP->disp.exp.X_op != O_constant
1662 || opP->disp.exp.X_add_number < 0
1663 || opP->disp.exp.X_add_number > 7)
1668 if (opP->mode != CONTROL || opP->reg != USP)
1672 /* JF these are out of order. We could put them
1673 in order if we were willing to put up with
1674 bunches of #ifdef m68851s in the code.
1676 Don't forget that you need these operands
1677 to use 68030 MMU instructions. */
1679 /* Memory addressing mode used by pflushr */
1681 if (opP->mode == CONTROL
1682 || opP->mode == FPREG
1683 || opP->mode == DREG
1684 || opP->mode == AREG
1685 || opP->mode == REGLST)
1687 /* We should accept immediate operands, but they
1688 supposedly have to be quad word, and we don't
1689 handle that. I would like to see what a Motorola
1690 assembler does before doing something here. */
1691 if (opP->mode == IMMED)
1696 if (opP->mode != CONTROL
1697 || (opP->reg != SFC && opP->reg != DFC))
1702 if (opP->mode != CONTROL || opP->reg != TC)
1707 if (opP->mode != CONTROL || opP->reg != AC)
1712 if (opP->mode != CONTROL
1715 && opP->reg != SCC))
1720 if (opP->mode != CONTROL
1726 if (opP->mode != CONTROL
1729 && opP->reg != CRP))
1734 if (opP->mode != CONTROL
1735 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1736 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1741 if (opP->mode != CONTROL || opP->reg != PSR)
1746 if (opP->mode != CONTROL || opP->reg != PCSR)
1751 if (opP->mode != CONTROL
1758 } /* not a cache specifier. */
1762 if (opP->mode != ABSL)
1767 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1769 /* FIXME: kludge instead of fixing parser:
1770 upper/lower registers are *not* CONTROL
1771 registers, but ordinary ones. */
1772 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1773 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1781 } /* switch on type of operand */
1785 } /* for each operand */
1786 } /* if immediately wrong */
1793 opcode = opcode->m_next;
1798 && !(ok_arch & current_architecture))
1803 _("invalid instruction for this architecture; needs "));
1804 cp = buf + strlen (buf);
1808 strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
1811 strcpy (cp, _("mmu (68030 or 68851)"));
1814 strcpy (cp, _("68020 or higher"));
1817 strcpy (cp, _("68000 or higher"));
1820 strcpy (cp, _("68010 or higher"));
1824 int got_one = 0, idx;
1826 idx < (int) (sizeof (archs) / sizeof (archs[0]));
1829 if ((archs[idx].arch & ok_arch)
1830 && ! archs[idx].alias)
1834 strcpy (cp, " or ");
1838 strcpy (cp, archs[idx].name);
1844 cp = xmalloc (strlen (buf) + 1);
1849 the_ins.error = _("operands mismatch");
1851 } /* Fell off the end */
1856 /* now assemble it */
1858 the_ins.args = opcode->m_operands;
1859 the_ins.numargs = opcode->m_opnum;
1860 the_ins.numo = opcode->m_codenum;
1861 the_ins.opcode[0] = getone (opcode);
1862 the_ins.opcode[1] = gettwo (opcode);
1864 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
1866 /* This switch is a doozy.
1867 Watch the first step; its a big one! */
1895 tmpreg = 0x3c; /* 7.4 */
1896 if (strchr ("bwl", s[1]))
1897 nextword = get_num (&opP->disp, 80);
1899 nextword = get_num (&opP->disp, 0);
1900 if (isvar (&opP->disp))
1901 add_fix (s[1], &opP->disp, 0, 0);
1905 if (!isbyte (nextword))
1906 opP->error = _("operand out of range");
1911 if (!isword (nextword))
1912 opP->error = _("operand out of range");
1917 if (!issword (nextword))
1918 opP->error = _("operand out of range");
1923 addword (nextword >> 16);
1950 /* We gotta put out some float */
1951 if (op (&opP->disp) != O_big)
1956 /* Can other cases happen here? */
1957 if (op (&opP->disp) != O_constant)
1960 val = (valueT) offs (&opP->disp);
1964 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
1965 val >>= LITTLENUM_NUMBER_OF_BITS;
1969 offs (&opP->disp) = gencnt;
1971 if (offs (&opP->disp) > 0)
1973 if (offs (&opP->disp) > baseo)
1975 as_warn (_("Bignum too big for %c format; truncated"),
1977 offs (&opP->disp) = baseo;
1979 baseo -= offs (&opP->disp);
1982 for (wordp = generic_bignum + offs (&opP->disp) - 1;
1983 offs (&opP->disp)--;
1988 gen_to_words (words, baseo, (long) outro);
1989 for (wordp = words; baseo--; wordp++)
1993 tmpreg = opP->reg - DATA; /* 0.dreg */
1996 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
1999 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2002 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2005 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2009 nextword = get_num (&opP->disp, 80);
2012 && ! isvar (&opP->disp)
2015 opP->disp.exp.X_op = O_symbol;
2016 #ifndef BFD_ASSEMBLER
2017 opP->disp.exp.X_add_symbol = &abs_symbol;
2019 opP->disp.exp.X_add_symbol =
2020 section_symbol (absolute_section);
2024 /* Force into index mode. Hope this works */
2026 /* We do the first bit for 32-bit displacements, and the
2027 second bit for 16 bit ones. It is possible that we
2028 should make the default be WORD instead of LONG, but
2029 I think that'd break GCC, so we put up with a little
2030 inefficiency for the sake of working output. */
2032 if (!issword (nextword)
2033 || (isvar (&opP->disp)
2034 && ((opP->disp.size == SIZE_UNSPEC
2035 && flag_short_refs == 0
2036 && cpu_of_arch (current_architecture) >= m68020
2037 && ! arch_coldfire_p (current_architecture))
2038 || opP->disp.size == SIZE_LONG)))
2040 if (cpu_of_arch (current_architecture) < m68020
2041 || arch_coldfire_p (current_architecture))
2043 _("displacement too large for this architecture; needs 68020 or higher");
2045 tmpreg = 0x3B; /* 7.3 */
2047 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2048 if (isvar (&opP->disp))
2052 if (opP->disp.size == SIZE_LONG
2054 /* If the displacement needs pic
2055 relocation it cannot be relaxed. */
2056 || opP->disp.pic_reloc != pic_none
2061 add_fix ('l', &opP->disp, 1, 2);
2065 add_frag (adds (&opP->disp),
2067 TAB (PCLEA, SZ_UNDEF));
2074 add_fix ('l', &opP->disp, 0, 0);
2079 addword (nextword >> 16);
2084 tmpreg = 0x3A; /* 7.2 */
2086 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2088 if (isvar (&opP->disp))
2092 add_fix ('w', &opP->disp, 1, 0);
2095 add_fix ('w', &opP->disp, 0, 0);
2105 baseo = get_num (&opP->disp, 80);
2106 if (opP->mode == POST || opP->mode == PRE)
2107 outro = get_num (&opP->odisp, 80);
2108 /* Figure out the `addressing mode'.
2109 Also turn on the BASE_DISABLE bit, if needed. */
2110 if (opP->reg == PC || opP->reg == ZPC)
2112 tmpreg = 0x3b; /* 7.3 */
2113 if (opP->reg == ZPC)
2116 else if (opP->reg == 0)
2119 tmpreg = 0x30; /* 6.garbage */
2121 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2124 tmpreg = 0x30 + opP->reg - ZADDR0;
2127 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2129 siz1 = opP->disp.size;
2130 if (opP->mode == POST || opP->mode == PRE)
2131 siz2 = opP->odisp.size;
2135 /* Index register stuff */
2136 if (opP->index.reg != 0
2137 && opP->index.reg >= DATA
2138 && opP->index.reg <= ADDR7)
2140 nextword |= (opP->index.reg - DATA) << 12;
2142 if (opP->index.size == SIZE_LONG
2143 || (opP->index.size == SIZE_UNSPEC
2144 && m68k_index_width_default == SIZE_LONG))
2147 if ((opP->index.scale != 1
2148 && cpu_of_arch (current_architecture) < m68020)
2149 || (opP->index.scale == 8
2150 && arch_coldfire_p (current_architecture)))
2153 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2156 if (arch_coldfire_p (current_architecture)
2157 && opP->index.size == SIZE_WORD)
2158 opP->error = _("invalid index size for coldfire");
2160 switch (opP->index.scale)
2177 GET US OUT OF HERE! */
2179 /* Must be INDEX, with an index register. Address
2180 register cannot be ZERO-PC, and either :b was
2181 forced, or we know it will fit. For a 68000 or
2182 68010, force this mode anyways, because the
2183 larger modes aren't supported. */
2184 if (opP->mode == BASE
2185 && ((opP->reg >= ADDR0
2186 && opP->reg <= ADDR7)
2189 if (siz1 == SIZE_BYTE
2190 || cpu_of_arch (current_architecture) < m68020
2191 || arch_coldfire_p (current_architecture)
2192 || (siz1 == SIZE_UNSPEC
2193 && ! isvar (&opP->disp)
2194 && issbyte (baseo)))
2196 nextword += baseo & 0xff;
2198 if (isvar (&opP->disp))
2200 /* Do a byte relocation. If it doesn't
2201 fit (possible on m68000) let the
2202 fixup processing complain later. */
2204 add_fix ('B', &opP->disp, 1, 1);
2206 add_fix ('B', &opP->disp, 0, 0);
2208 else if (siz1 != SIZE_BYTE)
2210 if (siz1 != SIZE_UNSPEC)
2211 as_warn (_("Forcing byte displacement"));
2212 if (! issbyte (baseo))
2213 opP->error = _("byte displacement out of range");
2218 else if (siz1 == SIZE_UNSPEC
2220 && isvar (&opP->disp)
2221 && subs (&opP->disp) == NULL
2223 /* If the displacement needs pic
2224 relocation it cannot be relaxed. */
2225 && opP->disp.pic_reloc == pic_none
2229 /* The code in md_convert_frag_1 needs to be
2230 able to adjust nextword. Call frag_grow
2231 to ensure that we have enough space in
2232 the frag obstack to make all the bytes
2235 nextword += baseo & 0xff;
2237 add_frag (adds (&opP->disp), offs (&opP->disp),
2238 TAB (PCINDEX, SZ_UNDEF));
2246 nextword |= 0x40; /* No index reg */
2247 if (opP->index.reg >= ZDATA0
2248 && opP->index.reg <= ZDATA7)
2249 nextword |= (opP->index.reg - ZDATA0) << 12;
2250 else if (opP->index.reg >= ZADDR0
2251 || opP->index.reg <= ZADDR7)
2252 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2255 /* It isn't simple. */
2257 if (cpu_of_arch (current_architecture) < m68020
2258 || arch_coldfire_p (current_architecture))
2260 _("invalid operand mode for this architecture; needs 68020 or higher");
2263 /* If the guy specified a width, we assume that it is
2264 wide enough. Maybe it isn't. If so, we lose. */
2268 if (isvar (&opP->disp)
2270 : ! issword (baseo))
2275 else if (! isvar (&opP->disp) && baseo == 0)
2284 as_warn (_(":b not permitted; defaulting to :w"));
2294 /* Figure out innner displacement stuff */
2295 if (opP->mode == POST || opP->mode == PRE)
2297 if (cpu_of_arch (current_architecture) & cpu32)
2298 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2302 if (isvar (&opP->odisp)
2304 : ! issword (outro))
2309 else if (! isvar (&opP->odisp) && outro == 0)
2318 as_warn (_(":b not permitted; defaulting to :w"));
2327 if (opP->mode == POST
2328 && (nextword & 0x40) == 0)
2333 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2335 if (opP->reg == PC || opP->reg == ZPC)
2336 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2338 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2340 if (siz1 == SIZE_LONG)
2341 addword (baseo >> 16);
2342 if (siz1 != SIZE_UNSPEC)
2345 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2346 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2347 if (siz2 == SIZE_LONG)
2348 addword (outro >> 16);
2349 if (siz2 != SIZE_UNSPEC)
2355 nextword = get_num (&opP->disp, 80);
2356 switch (opP->disp.size)
2361 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2363 tmpreg = 0x38; /* 7.0 */
2367 if (isvar (&opP->disp)
2368 && !subs (&opP->disp)
2369 && adds (&opP->disp)
2371 /* If the displacement needs pic relocation it
2372 cannot be relaxed. */
2373 && opP->disp.pic_reloc == pic_none
2375 && S_GET_SEGMENT (adds (&opP->disp)) == now_seg
2376 && relaxable_symbol (adds (&opP->disp))
2378 && !strchr ("~%&$?", s[0]))
2380 tmpreg = 0x3A; /* 7.2 */
2381 add_frag (adds (&opP->disp),
2383 TAB (PCREL, SZ_UNDEF));
2386 /* Fall through into long */
2388 if (isvar (&opP->disp))
2389 add_fix ('l', &opP->disp, 0, 0);
2391 tmpreg = 0x39;/* 7.1 mode */
2392 addword (nextword >> 16);
2397 as_bad (_("unsupported byte value; use a different suffix"));
2399 case SIZE_WORD: /* Word */
2400 if (isvar (&opP->disp))
2401 add_fix ('w', &opP->disp, 0, 0);
2403 tmpreg = 0x38;/* 7.0 mode */
2411 as_bad (_("unknown/incorrect operand"));
2414 install_gen_operand (s[1], tmpreg);
2420 { /* JF: I hate floating point! */
2435 tmpreg = get_num (&opP->disp, tmpreg);
2436 if (isvar (&opP->disp))
2437 add_fix (s[1], &opP->disp, 0, 0);
2440 case 'b': /* Danger: These do no check for
2441 certain types of overflow.
2443 if (!isbyte (tmpreg))
2444 opP->error = _("out of range");
2445 insop (tmpreg, opcode);
2446 if (isvar (&opP->disp))
2447 the_ins.reloc[the_ins.nrel - 1].n =
2448 (opcode->m_codenum) * 2 + 1;
2451 if (!issbyte (tmpreg))
2452 opP->error = _("out of range");
2453 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2454 if (isvar (&opP->disp))
2455 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2458 if (!isword (tmpreg))
2459 opP->error = _("out of range");
2460 insop (tmpreg, opcode);
2461 if (isvar (&opP->disp))
2462 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2465 if (!issword (tmpreg))
2466 opP->error = _("out of range");
2467 insop (tmpreg, opcode);
2468 if (isvar (&opP->disp))
2469 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2472 /* Because of the way insop works, we put these two out
2474 insop (tmpreg, opcode);
2475 insop (tmpreg >> 16, opcode);
2476 if (isvar (&opP->disp))
2477 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2484 install_operand (s[1], tmpreg);
2495 install_operand (s[1], opP->reg - ADDR);
2499 tmpreg = get_num (&opP->disp, 80);
2503 /* The pc_fix argument winds up in fx_pcrel_adjust,
2504 which is a char, and may therefore be unsigned. We
2505 want to pass -1, but we pass 64 instead, and convert
2506 back in md_pcrel_from. */
2507 add_fix ('B', &opP->disp, 1, 64);
2510 add_fix ('w', &opP->disp, 1, 0);
2515 if (!HAVE_LONG_BRANCH(current_architecture))
2516 as_warn (_("Can't use long branches on 68000/68010/5200"));
2517 the_ins.opcode[the_ins.numo - 1] |= 0xff;
2518 add_fix ('l', &opP->disp, 1, 0);
2523 if (subs (&opP->disp)) /* We can't relax it */
2527 /* If the displacement needs pic relocation it cannot be
2529 if (opP->disp.pic_reloc != pic_none)
2533 /* This could either be a symbol, or an absolute
2534 address. No matter, the frag hacking will finger it
2535 out. Not quite: it can't switch from BRANCH to
2536 BCC68000 for the case where opnd is absolute (it
2537 needs to use the 68000 hack since no conditional abs
2539 if (( !HAVE_LONG_BRANCH(current_architecture)
2540 || (0 == adds (&opP->disp)))
2541 && (the_ins.opcode[0] >= 0x6200)
2542 && (the_ins.opcode[0] <= 0x6f00))
2543 add_frag (adds (&opP->disp), offs (&opP->disp),
2544 TAB (BCC68000, SZ_UNDEF));
2546 add_frag (adds (&opP->disp), offs (&opP->disp),
2547 TAB (ABRANCH, SZ_UNDEF));
2550 if (isvar (&opP->disp))
2553 /* check for DBcc instruction */
2554 if ((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2556 /* size varies if patch */
2557 /* needed for long form */
2558 add_frag (adds (&opP->disp), offs (&opP->disp),
2559 TAB (DBCC, SZ_UNDEF));
2563 add_fix ('w', &opP->disp, 1, 0);
2567 case 'C': /* Fixed size LONG coproc branches */
2568 add_fix ('l', &opP->disp, 1, 0);
2572 case 'c': /* Var size Coprocesssor branches */
2573 if (subs (&opP->disp))
2575 add_fix ('l', &opP->disp, 1, 0);
2576 add_frag ((symbolS *) 0, (offsetT) 0, TAB (FBRANCH, LONG));
2578 else if (adds (&opP->disp))
2579 add_frag (adds (&opP->disp), offs (&opP->disp),
2580 TAB (FBRANCH, SZ_UNDEF));
2583 /* add_frag ((symbolS *) 0, offs (&opP->disp),
2584 TAB(FBRANCH,SHORT)); */
2585 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2586 add_fix ('l', &opP->disp, 1, 0);
2596 case 'C': /* Ignore it */
2599 case 'd': /* JF this is a kludge */
2600 install_operand ('s', opP->reg - ADDR);
2601 tmpreg = get_num (&opP->disp, 80);
2602 if (!issword (tmpreg))
2604 as_warn (_("Expression out of range, using 0"));
2611 install_operand (s[1], opP->reg - DATA);
2614 case 'E': /* Ignore it */
2618 install_operand (s[1], opP->reg - FP0);
2621 case 'G': /* Ignore it */
2626 tmpreg = opP->reg - COP0;
2627 install_operand (s[1], tmpreg);
2630 case 'J': /* JF foo */
2703 install_operand (s[1], tmpreg);
2707 tmpreg = get_num (&opP->disp, 55);
2708 install_operand (s[1], tmpreg & 0x7f);
2715 if (tmpreg & 0x7FF0000)
2716 as_bad (_("Floating point register in register list"));
2717 insop (reverse_16_bits (tmpreg), opcode);
2721 if (tmpreg & 0x700FFFF)
2722 as_bad (_("Wrong register in floating-point reglist"));
2723 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
2731 if (tmpreg & 0x7FF0000)
2732 as_bad (_("Floating point register in register list"));
2733 insop (tmpreg, opcode);
2735 else if (s[1] == '8')
2737 if (tmpreg & 0x0FFFFFF)
2738 as_bad (_("incorrect register in reglist"));
2739 install_operand (s[1], tmpreg >> 24);
2743 if (tmpreg & 0x700FFFF)
2744 as_bad (_("wrong register in floating-point reglist"));
2746 install_operand (s[1], tmpreg >> 16);
2751 install_operand (s[1], get_num (&opP->disp, 60));
2755 tmpreg = ((opP->mode == DREG)
2756 ? 0x20 + (int) (opP->reg - DATA)
2757 : (get_num (&opP->disp, 40) & 0x1F));
2758 install_operand (s[1], tmpreg);
2762 tmpreg = get_num (&opP->disp, 10);
2765 install_operand (s[1], tmpreg);
2769 /* This depends on the fact that ADDR registers are eight
2770 more than their corresponding DATA regs, so the result
2771 will have the ADDR_REG bit set */
2772 install_operand (s[1], opP->reg - DATA);
2776 if (opP->mode == AINDR)
2777 install_operand (s[1], opP->reg - DATA);
2779 install_operand (s[1], opP->index.reg - DATA);
2783 if (opP->reg == FPI)
2785 else if (opP->reg == FPS)
2787 else if (opP->reg == FPC)
2791 install_operand (s[1], tmpreg);
2794 case 'S': /* Ignore it */
2798 install_operand (s[1], get_num (&opP->disp, 30));
2801 case 'U': /* Ignore it */
2820 as_fatal (_("failed sanity check"));
2821 } /* switch on cache token */
2822 install_operand (s[1], tmpreg);
2825 /* JF: These are out of order, I fear. */
2838 install_operand (s[1], tmpreg);
2864 install_operand (s[1], tmpreg);
2868 if (opP->reg == VAL)
2887 install_operand (s[1], tmpreg);
2901 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2912 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2918 install_operand (s[1], tmpreg);
2921 know (opP->reg == PSR);
2924 know (opP->reg == PCSR);
2939 install_operand (s[1], tmpreg);
2942 tmpreg = get_num (&opP->disp, 20);
2943 install_operand (s[1], tmpreg);
2945 case '_': /* used only for move16 absolute 32-bit address */
2946 if (isvar (&opP->disp))
2947 add_fix ('l', &opP->disp, 0, 0);
2948 tmpreg = get_num (&opP->disp, 80);
2949 addword (tmpreg >> 16);
2950 addword (tmpreg & 0xFFFF);
2953 install_operand (s[1], opP->reg - DATA0L);
2954 opP->reg -= (DATA0L);
2955 opP->reg &= 0x0F; /* remove upper/lower bit */
2962 /* By the time whe get here (FINALLY) the_ins contains the complete
2963 instruction, ready to be emitted. . . */
2967 reverse_16_bits (in)
2973 static int mask[16] =
2975 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2976 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2978 for (n = 0; n < 16; n++)
2981 out |= mask[15 - n];
2984 } /* reverse_16_bits() */
2993 static int mask[8] =
2995 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2998 for (n = 0; n < 8; n++)
3004 } /* reverse_8_bits() */
3006 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3007 (that value is chosen in the frag_var call in md_assemble). TYPE
3008 is the subtype of the frag to be generated; its primary type is
3009 rs_machine_dependent.
3011 The TYPE parameter is also used by md_convert_frag_1 and
3012 md_estimate_size_before_relax. The appropriate type of fixup will
3013 be emitted by md_convert_frag_1.
3015 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3017 install_operand (mode, val)
3024 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge */
3027 the_ins.opcode[0] |= val << 9;
3030 the_ins.opcode[1] |= val << 12;
3033 the_ins.opcode[1] |= val << 6;
3036 the_ins.opcode[1] |= val;
3039 the_ins.opcode[2] |= val << 12;
3042 the_ins.opcode[2] |= val << 6;
3045 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3046 three words long! */
3048 the_ins.opcode[2] |= val;
3051 the_ins.opcode[1] |= val << 7;
3054 the_ins.opcode[1] |= val << 10;
3058 the_ins.opcode[1] |= val << 5;
3063 the_ins.opcode[1] |= (val << 10) | (val << 7);
3066 the_ins.opcode[1] |= (val << 12) | val;
3069 the_ins.opcode[0] |= val = 0xff;
3072 the_ins.opcode[0] |= val << 9;
3075 the_ins.opcode[1] |= val;
3078 the_ins.opcode[1] |= val;
3079 the_ins.numo++; /* What a hack */
3082 the_ins.opcode[1] |= val << 4;
3090 the_ins.opcode[0] |= (val << 6);
3093 the_ins.opcode[1] = (val >> 16);
3094 the_ins.opcode[2] = val & 0xffff;
3097 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3098 the_ins.opcode[0] |= ((val & 0x7) << 9);
3099 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3102 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3103 the_ins.opcode[0] |= ((val & 0x7) << 9);
3106 the_ins.opcode[1] |= val << 12;
3107 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3110 the_ins.opcode[0] |= (val & 0xF);
3111 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3114 the_ins.opcode[1] |= (val & 0xF);
3115 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3118 the_ins.opcode[1] |= ((val != 1) << 10);
3122 as_fatal (_("failed sanity check."));
3124 } /* install_operand() */
3127 install_gen_operand (mode, val)
3134 the_ins.opcode[0] |= val;
3137 /* This is a kludge!!! */
3138 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3147 the_ins.opcode[0] |= val;
3149 /* more stuff goes here */
3151 as_fatal (_("failed sanity check."));
3153 } /* install_gen_operand() */
3156 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3157 * then deal with the bitfield hack.
3161 crack_operand (str, opP)
3163 register struct m68k_op *opP;
3165 register int parens;
3167 register char *beg_str;
3175 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3181 else if (*str == ')')
3185 opP->error = _("Extra )");
3191 if (flag_mri && *str == '\'')
3192 inquote = ! inquote;
3194 if (!*str && parens)
3196 opP->error = _("Missing )");
3201 if (m68k_ip_op (beg_str, opP) != 0)
3208 c = *++str; /* JF bitfield hack */
3213 as_bad (_("Missing operand"));
3216 /* Detect MRI REG symbols and convert them to REGLSTs. */
3217 if (opP->mode == CONTROL && (int)opP->reg < 0)
3220 opP->mask = ~(int)opP->reg;
3227 /* This is the guts of the machine-dependent assembler. STR points to a
3228 machine dependent instruction. This function is supposed to emit
3229 the frags/bytes it assembles to.
3233 insert_reg (regname, regnum)
3234 const char *regname;
3240 #ifdef REGISTER_PREFIX
3241 if (!flag_reg_prefix_optional)
3243 buf[0] = REGISTER_PREFIX;
3244 strcpy (buf + 1, regname);
3249 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3250 &zero_address_frag));
3252 for (i = 0; regname[i]; i++)
3253 buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
3256 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3257 &zero_address_frag));
3266 static const struct init_entry init_table[] =
3325 /* control registers */
3326 { "sfc", SFC }, /* Source Function Code */
3328 { "dfc", DFC }, /* Destination Function Code */
3330 { "cacr", CACR }, /* Cache Control Register */
3331 { "caar", CAAR }, /* Cache Address Register */
3333 { "usp", USP }, /* User Stack Pointer */
3334 { "vbr", VBR }, /* Vector Base Register */
3335 { "msp", MSP }, /* Master Stack Pointer */
3336 { "isp", ISP }, /* Interrupt Stack Pointer */
3338 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0 */
3339 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1 */
3340 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0 */
3341 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1 */
3343 /* 68ec040 versions of same */
3344 { "iacr0", ITT0 }, /* Instruction Access Control Register 0 */
3345 { "iacr1", ITT1 }, /* Instruction Access Control Register 0 */
3346 { "dacr0", DTT0 }, /* Data Access Control Register 0 */
3347 { "dacr1", DTT1 }, /* Data Access Control Register 0 */
3349 /* mcf5200 versions of same. The ColdFire programmer's reference
3350 manual indicated that the order is 2,3,0,1, but Ken Rose
3351 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3352 { "acr0", ITT0 }, /* Access Control Unit 0 */
3353 { "acr1", ITT1 }, /* Access Control Unit 1 */
3354 { "acr2", DTT0 }, /* Access Control Unit 2 */
3355 { "acr3", DTT1 }, /* Access Control Unit 3 */
3357 { "tc", TC }, /* MMU Translation Control Register */
3360 { "mmusr", MMUSR }, /* MMU Status Register */
3361 { "srp", SRP }, /* User Root Pointer */
3362 { "urp", URP }, /* Supervisor Root Pointer */
3367 { "rombar", ROMBAR }, /* ROM Base Address Register */
3368 { "rambar0", RAMBAR0 }, /* ROM Base Address Register */
3369 { "rambar1", RAMBAR1 }, /* ROM Base Address Register */
3370 { "mbar", MBAR }, /* Module Base Address Register */
3371 /* end of control registers */
3405 /* 68ec030 versions of same */
3408 /* 68ec030 access control unit, identical to 030 MMU status reg */
3411 /* Suppressed data and address registers. */
3429 /* Upper and lower data and address registers, used by macw and msacw. */
3473 for (i = 0; init_table[i].name; i++)
3474 insert_reg (init_table[i].name, init_table[i].number);
3477 static int no_68851, no_68881;
3480 /* a.out machine type. Default to 68020. */
3481 int m68k_aout_machtype = 2;
3493 int shorts_this_frag;
3496 /* In MRI mode, the instruction and operands are separated by a
3497 space. Anything following the operands is a comment. The label
3498 has already been removed. */
3506 for (s = str; *s != '\0'; s++)
3508 if ((*s == ' ' || *s == '\t') && ! inquote)
3526 inquote = ! inquote;
3531 memset ((char *) (&the_ins), '\0', sizeof (the_ins));
3536 for (n = 0; n < the_ins.numargs; n++)
3537 if (the_ins.operands[n].error)
3539 er = the_ins.operands[n].error;
3545 as_bad (_("%s -- statement `%s' ignored"), er, str);
3549 /* If there is a current label, record that it marks an instruction. */
3550 if (current_label != NULL)
3552 current_label->text = 1;
3553 current_label = NULL;
3556 if (the_ins.nfrag == 0)
3558 /* No frag hacking involved; just put it out */
3559 toP = frag_more (2 * the_ins.numo);
3560 fromP = &the_ins.opcode[0];
3561 for (m = the_ins.numo; m; --m)
3563 md_number_to_chars (toP, (long) (*fromP), 2);
3567 /* put out symbol-dependent info */
3568 for (m = 0; m < the_ins.nrel; m++)
3570 switch (the_ins.reloc[m].wid)
3589 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3590 the_ins.reloc[m].wid);
3593 fixP = fix_new_exp (frag_now,
3594 ((toP - frag_now->fr_literal)
3595 - the_ins.numo * 2 + the_ins.reloc[m].n),
3597 &the_ins.reloc[m].exp,
3598 the_ins.reloc[m].pcrel,
3599 get_reloc_code (n, the_ins.reloc[m].pcrel,
3600 the_ins.reloc[m].pic_reloc));
3601 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3602 if (the_ins.reloc[m].wid == 'B')
3603 fixP->fx_signed = 1;
3608 /* There's some frag hacking */
3609 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
3614 wid = 2 * the_ins.fragb[n].fragoff;
3616 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3617 toP = frag_more (wid);
3619 shorts_this_frag = 0;
3620 for (m = wid / 2; m; --m)
3622 md_number_to_chars (toP, (long) (*fromP), 2);
3627 for (m = 0; m < the_ins.nrel; m++)
3629 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
3631 the_ins.reloc[m].n -= 2 * shorts_this_frag;
3634 wid = the_ins.reloc[m].wid;
3637 the_ins.reloc[m].wid = 0;
3638 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3640 fixP = fix_new_exp (frag_now,
3641 ((toP - frag_now->fr_literal)
3642 - the_ins.numo * 2 + the_ins.reloc[m].n),
3644 &the_ins.reloc[m].exp,
3645 the_ins.reloc[m].pcrel,
3646 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3647 the_ins.reloc[m].pic_reloc));
3648 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3650 (void) frag_var (rs_machine_dependent, 10, 0,
3651 (relax_substateT) (the_ins.fragb[n].fragty),
3652 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
3654 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3655 shorts_this_frag = 0;
3658 toP = frag_more (n * sizeof (short));
3661 md_number_to_chars (toP, (long) (*fromP), 2);
3667 for (m = 0; m < the_ins.nrel; m++)
3671 wid = the_ins.reloc[m].wid;
3674 the_ins.reloc[m].wid = 0;
3675 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3677 fixP = fix_new_exp (frag_now,
3678 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
3679 - shorts_this_frag * 2),
3681 &the_ins.reloc[m].exp,
3682 the_ins.reloc[m].pcrel,
3683 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3684 the_ins.reloc[m].pic_reloc));
3685 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3693 * md_begin -- set up hash tables with 68000 instructions.
3694 * similar to what the vax assembler does. ---phr
3696 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3697 a copy of it at runtime, adding in the information we want but isn't
3698 there. I think it'd be better to have an awk script hack the table
3699 at compile time. Or even just xstr the table and use it as-is. But
3700 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3703 register const struct m68k_opcode *ins;
3704 register struct m68k_incant *hack, *slak;
3705 register const char *retval = 0; /* empty string, or error msg text */
3711 flag_reg_prefix_optional = 1;
3713 if (! m68k_rel32_from_cmdline)
3717 op_hash = hash_new ();
3719 obstack_begin (&robyn, 4000);
3720 for (i = 0; i < m68k_numopcodes; i++)
3722 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3725 ins = &m68k_opcodes[i];
3726 /* We *could* ignore insns that don't match our arch here
3727 but just leaving them out of the hash. */
3728 slak->m_operands = ins->args;
3729 slak->m_opnum = strlen (slak->m_operands) / 2;
3730 slak->m_arch = ins->arch;
3731 slak->m_opcode = ins->opcode;
3732 /* This is kludgey */
3733 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
3734 if (i + 1 != m68k_numopcodes
3735 && !strcmp (ins->name, m68k_opcodes[i + 1].name))
3737 slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3742 slak = slak->m_next;
3746 retval = hash_insert (op_hash, ins->name, (char *) hack);
3748 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
3751 for (i = 0; i < m68k_numaliases; i++)
3753 const char *name = m68k_opcode_aliases[i].primary;
3754 const char *alias = m68k_opcode_aliases[i].alias;
3755 PTR val = hash_find (op_hash, name);
3757 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
3758 retval = hash_insert (op_hash, alias, val);
3760 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
3763 /* In MRI mode, all unsized branches are variable sized. Normally,
3764 they are word sized. */
3767 static struct m68k_opcode_alias mri_aliases[] =
3788 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
3791 const char *name = mri_aliases[i].primary;
3792 const char *alias = mri_aliases[i].alias;
3793 PTR val = hash_find (op_hash, name);
3795 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
3796 retval = hash_jam (op_hash, alias, val);
3798 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
3802 for (i = 0; i < (int) sizeof (mklower_table); i++)
3803 mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
3805 for (i = 0; i < (int) sizeof (notend_table); i++)
3807 notend_table[i] = 0;
3808 alt_notend_table[i] = 0;
3810 notend_table[','] = 1;
3811 notend_table['{'] = 1;
3812 notend_table['}'] = 1;
3813 alt_notend_table['a'] = 1;
3814 alt_notend_table['A'] = 1;
3815 alt_notend_table['d'] = 1;
3816 alt_notend_table['D'] = 1;
3817 alt_notend_table['#'] = 1;
3818 alt_notend_table['&'] = 1;
3819 alt_notend_table['f'] = 1;
3820 alt_notend_table['F'] = 1;
3821 #ifdef REGISTER_PREFIX
3822 alt_notend_table[REGISTER_PREFIX] = 1;
3825 /* We need to put '(' in alt_notend_table to handle
3826 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3828 alt_notend_table['('] = 1;
3830 /* We need to put '@' in alt_notend_table to handle
3831 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3833 alt_notend_table['@'] = 1;
3835 /* We need to put digits in alt_notend_table to handle
3836 bfextu %d0{24:1},%d0
3838 alt_notend_table['0'] = 1;
3839 alt_notend_table['1'] = 1;
3840 alt_notend_table['2'] = 1;
3841 alt_notend_table['3'] = 1;
3842 alt_notend_table['4'] = 1;
3843 alt_notend_table['5'] = 1;
3844 alt_notend_table['6'] = 1;
3845 alt_notend_table['7'] = 1;
3846 alt_notend_table['8'] = 1;
3847 alt_notend_table['9'] = 1;
3849 #ifndef MIT_SYNTAX_ONLY
3850 /* Insert pseudo ops, these have to go into the opcode table since
3851 gas expects pseudo ops to start with a dot */
3854 while (mote_pseudo_table[n].poc_name)
3856 hack = (struct m68k_incant *)
3857 obstack_alloc (&robyn, sizeof (struct m68k_incant));
3858 hash_insert (op_hash,
3859 mote_pseudo_table[n].poc_name, (char *) hack);
3860 hack->m_operands = 0;
3870 record_alignment (text_section, 2);
3871 record_alignment (data_section, 2);
3872 record_alignment (bss_section, 2);
3877 select_control_regs ()
3879 /* Note which set of "movec" control registers is available. */
3880 switch (cpu_of_arch (current_architecture))
3883 control_regs = m68000_control_regs;
3886 control_regs = m68010_control_regs;
3890 control_regs = m68020_control_regs;
3893 control_regs = m68040_control_regs;
3896 control_regs = m68060_control_regs;
3899 control_regs = cpu32_control_regs;
3904 control_regs = mcf_control_regs;
3912 m68k_init_after_args ()
3914 if (cpu_of_arch (current_architecture) == 0)
3917 const char *default_cpu = TARGET_CPU;
3919 if (*default_cpu == 'm')
3921 for (i = 0; i < n_archs; i++)
3922 if (strcasecmp (default_cpu, archs[i].name) == 0)
3926 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU);
3927 current_architecture |= m68020;
3930 current_architecture |= archs[i].arch;
3932 /* Permit m68881 specification with all cpus; those that can't work
3933 with a coprocessor could be doing emulation. */
3934 if (current_architecture & m68851)
3936 if (current_architecture & m68040)
3938 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
3941 /* What other incompatibilities could we check for? */
3943 /* Toss in some default assumptions about coprocessors. */
3945 && (cpu_of_arch (current_architecture)
3946 /* Can CPU32 have a 68881 coprocessor?? */
3947 & (m68020 | m68030 | cpu32)))
3949 current_architecture |= m68881;
3952 && (cpu_of_arch (current_architecture) & m68020up) != 0
3953 && (cpu_of_arch (current_architecture) & m68040up) == 0)
3955 current_architecture |= m68851;
3957 if (no_68881 && (current_architecture & m68881))
3958 as_bad (_("options for 68881 and no-68881 both given"));
3959 if (no_68851 && (current_architecture & m68851))
3960 as_bad (_("options for 68851 and no-68851 both given"));
3963 /* Work out the magic number. This isn't very general. */
3964 if (current_architecture & m68000)
3965 m68k_aout_machtype = 0;
3966 else if (current_architecture & m68010)
3967 m68k_aout_machtype = 1;
3968 else if (current_architecture & m68020)
3969 m68k_aout_machtype = 2;
3971 m68k_aout_machtype = 2;
3974 /* Note which set of "movec" control registers is available. */
3975 select_control_regs ();
3977 if (cpu_of_arch (current_architecture) < m68020
3978 || arch_coldfire_p (current_architecture))
3979 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
3982 /* This is called when a label is defined. */
3985 m68k_frob_label (sym)
3988 struct label_line *n;
3990 n = (struct label_line *) xmalloc (sizeof *n);
3993 as_where (&n->file, &n->line);
3999 /* This is called when a value that is not an instruction is emitted. */
4002 m68k_flush_pending_output ()
4004 current_label = NULL;
4007 /* This is called at the end of the assembly, when the final value of
4008 the label is known. We warn if this is a text symbol aligned at an
4012 m68k_frob_symbol (sym)
4015 if (S_GET_SEGMENT (sym) == reg_section
4016 && (int) S_GET_VALUE (sym) < 0)
4018 S_SET_SEGMENT (sym, absolute_section);
4019 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4021 else if ((S_GET_VALUE (sym) & 1) != 0)
4023 struct label_line *l;
4025 for (l = labels; l != NULL; l = l->next)
4027 if (l->label == sym)
4030 as_warn_where (l->file, l->line,
4031 _("text label `%s' aligned to odd boundary"),
4039 /* This is called if we go in or out of MRI mode because of the .mri
4043 m68k_mri_mode_change (on)
4048 if (! flag_reg_prefix_optional)
4050 flag_reg_prefix_optional = 1;
4051 #ifdef REGISTER_PREFIX
4056 if (! m68k_rel32_from_cmdline)
4061 if (! reg_prefix_optional_seen)
4063 #ifdef REGISTER_PREFIX_OPTIONAL
4064 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4066 flag_reg_prefix_optional = 0;
4068 #ifdef REGISTER_PREFIX
4073 if (! m68k_rel32_from_cmdline)
4078 /* Equal to MAX_PRECISION in atof-ieee.c */
4079 #define MAX_LITTLENUMS 6
4081 /* Turn a string in input_line_pointer into a floating point constant
4082 of type TYPE, and store the appropriate bytes in *LITP. The number
4083 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4084 returned, or NULL on OK. */
4087 md_atof (type, litP, sizeP)
4093 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4094 LITTLENUM_TYPE *wordP;
4125 return _("Bad call to MD_ATOF()");
4127 t = atof_ieee (input_line_pointer, type, words);
4129 input_line_pointer = t;
4131 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4132 for (wordP = words; prec--;)
4134 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4135 litP += sizeof (LITTLENUM_TYPE);
4141 md_number_to_chars (buf, val, n)
4146 number_to_chars_bigendian (buf, val, n);
4150 md_apply_fix_2 (fixP, val)
4154 addressT upper_limit;
4155 offsetT lower_limit;
4157 /* This is unnecessary but it convinces the native rs6000 compiler
4158 to generate the code we want. */
4159 char *buf = fixP->fx_frag->fr_literal;
4160 buf += fixP->fx_where;
4161 /* end ibm compiler workaround */
4163 if (val & 0x80000000)
4164 val |= ~(addressT)0x7fffffff;
4171 memset (buf, 0, fixP->fx_size);
4172 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
4174 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4175 && !S_IS_DEFINED (fixP->fx_addsy)
4176 && !S_IS_WEAK (fixP->fx_addsy))
4177 S_SET_WEAK (fixP->fx_addsy);
4182 #ifdef BFD_ASSEMBLER
4183 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4184 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4188 switch (fixP->fx_size)
4190 /* The cast to offsetT below are necessary to make code correct for
4191 machines where ints are smaller than offsetT */
4195 lower_limit = - (offsetT) 0x80;
4198 *buf++ = (val >> 8);
4200 upper_limit = 0x7fff;
4201 lower_limit = - (offsetT) 0x8000;
4204 *buf++ = (val >> 24);
4205 *buf++ = (val >> 16);
4206 *buf++ = (val >> 8);
4208 upper_limit = 0x7fffffff;
4209 lower_limit = - (offsetT) 0x7fffffff - 1; /* avoid constant overflow */
4212 BAD_CASE (fixP->fx_size);
4215 /* Fix up a negative reloc. */
4216 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4218 fixP->fx_addsy = fixP->fx_subsy;
4219 fixP->fx_subsy = NULL;
4223 /* For non-pc-relative values, it's conceivable we might get something
4224 like "0xff" for a byte field. So extend the upper part of the range
4225 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4226 so that we can do any range checking at all. */
4227 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4228 upper_limit = upper_limit * 2 + 1;
4230 if ((addressT) val > upper_limit
4231 && (val > 0 || val < lower_limit))
4232 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4234 /* A one byte PC-relative reloc means a short branch. We can't use
4235 a short branch with a value of 0 or -1, because those indicate
4236 different opcodes (branches with longer offsets). fixup_segment
4237 in write.c may have clobbered fx_pcrel, so we need to examine the
4240 #ifdef BFD_ASSEMBLER
4241 || fixP->fx_r_type == BFD_RELOC_8_PCREL
4244 && fixP->fx_size == 1
4245 && (fixP->fx_addsy == NULL
4246 || S_IS_DEFINED (fixP->fx_addsy))
4247 && (val == 0 || val == -1))
4248 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4251 #ifdef BFD_ASSEMBLER
4253 md_apply_fix (fixP, valp)
4257 md_apply_fix_2 (fixP, (addressT) *valp);
4261 void md_apply_fix (fixP, val)
4265 md_apply_fix_2 (fixP, (addressT) val);
4269 /* *fragP has been relaxed to its final size, and now needs to have
4270 the bytes inside it modified to conform to the new size There is UGLY
4274 md_convert_frag_1 (fragP)
4275 register fragS *fragP;
4281 /* Address in object code of the displacement. */
4282 register int object_address = fragP->fr_fix + fragP->fr_address;
4284 /* Address in gas core of the place to store the displacement. */
4285 /* This convinces the native rs6000 compiler to generate the code we
4287 register char *buffer_address = fragP->fr_literal;
4288 buffer_address += fragP->fr_fix;
4289 /* end ibm compiler workaround */
4291 /* The displacement of the address, from current location. */
4292 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4293 disp = (disp + fragP->fr_offset) - object_address;
4295 #ifdef BFD_ASSEMBLER
4296 disp += symbol_get_frag (fragP->fr_symbol)->fr_address;
4299 switch (fragP->fr_subtype)
4301 case TAB (BCC68000, BYTE):
4302 case TAB (ABRANCH, BYTE):
4303 know (issbyte (disp));
4305 as_bad (_("short branch with zero offset: use :w"));
4306 fragP->fr_opcode[1] = disp;
4309 case TAB (DBCC, SHORT):
4310 know (issword (disp));
4313 case TAB (BCC68000, SHORT):
4314 case TAB (ABRANCH, SHORT):
4315 know (issword (disp));
4316 fragP->fr_opcode[1] = 0x00;
4319 case TAB (ABRANCH, LONG):
4320 if (!HAVE_LONG_BRANCH(current_architecture))
4322 if (fragP->fr_opcode[0] == 0x61)
4325 fragP->fr_opcode[0] = 0x4E;
4326 fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4340 else if (fragP->fr_opcode[0] == 0x60)
4342 fragP->fr_opcode[0] = 0x4E;
4343 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4344 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4345 fragP->fr_offset, 0, NO_RELOC);
4351 /* This should never happen, because if it's a conditional
4352 branch and we are on a 68000, BCC68000 should have been
4353 picked instead of ABRANCH. */
4359 fragP->fr_opcode[1] = (char) 0xff;
4363 case TAB (BCC68000, LONG):
4364 /* only Bcc 68000 instructions can come here */
4365 /* change bcc into b!cc/jmp absl long */
4366 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
4367 fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
4369 /* JF: these used to be fr_opcode[2,3], but they may be in a
4370 different frag, in which case refering to them is a no-no.
4371 Only fr_opcode[0,1] are guaranteed to work. */
4372 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4373 *buffer_address++ = (char) 0xf9;
4374 fragP->fr_fix += 2; /* account for jmp instruction */
4375 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4376 fragP->fr_offset, 0, NO_RELOC);
4380 case TAB (DBCC, LONG):
4381 /* only DBcc 68000 instructions can come here */
4382 /* change dbcc into dbcc/jmp absl long */
4383 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4384 *buffer_address++ = 0x00; /* branch offset = 4 */
4385 *buffer_address++ = 0x04;
4386 *buffer_address++ = 0x60; /* put in bra pc+6 */
4387 *buffer_address++ = 0x06;
4388 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4389 *buffer_address++ = (char) 0xf9;
4391 fragP->fr_fix += 6; /* account for bra/jmp instructions */
4392 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4393 fragP->fr_offset, 0, NO_RELOC);
4397 case TAB (FBRANCH, SHORT):
4398 know ((fragP->fr_opcode[1] & 0x40) == 0);
4401 case TAB (FBRANCH, LONG):
4402 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
4405 case TAB (PCREL, SHORT):
4408 case TAB (PCREL, LONG):
4409 /* The thing to do here is force it to ABSOLUTE LONG, since
4410 PCREL is really trying to shorten an ABSOLUTE address anyway */
4411 /* JF FOO This code has not been tested */
4412 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4414 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4415 as_bad (_("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx"),
4416 (unsigned) fragP->fr_opcode[0],
4417 (unsigned long) fragP->fr_address);
4418 fragP->fr_opcode[1] &= ~0x3F;
4419 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4423 case TAB (PCLEA, SHORT):
4424 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4425 fragP->fr_offset, 1, NO_RELOC);
4426 fragP->fr_opcode[1] &= ~0x3F;
4427 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4430 case TAB (PCLEA, LONG):
4431 fixP = fix_new (fragP, (int) (fragP->fr_fix) + 2, 4, fragP->fr_symbol,
4432 fragP->fr_offset, 1, NO_RELOC);
4433 fixP->fx_pcrel_adjust = 2;
4434 /* Already set to mode 7.3; this indicates: PC indirect with
4435 suppressed index, 32-bit displacement. */
4436 *buffer_address++ = 0x01;
4437 *buffer_address++ = 0x70;
4442 case TAB (PCINDEX, BYTE):
4444 if (!issbyte (disp))
4446 as_bad (_("displacement doesn't fit in one byte"));
4449 assert (fragP->fr_fix >= 2);
4450 buffer_address[-2] &= ~1;
4451 buffer_address[-1] = disp;
4454 case TAB (PCINDEX, SHORT):
4456 assert (issword (disp));
4457 assert (fragP->fr_fix >= 2);
4458 buffer_address[-2] |= 0x1;
4459 buffer_address[-1] = 0x20;
4460 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4461 fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
4463 fixP->fx_pcrel_adjust = 2;
4466 case TAB (PCINDEX, LONG):
4468 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4469 fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
4471 fixP->fx_pcrel_adjust = 2;
4472 assert (fragP->fr_fix >= 2);
4473 buffer_address[-2] |= 0x1;
4474 buffer_address[-1] = 0x30;
4481 md_number_to_chars (buffer_address, (long) disp, (int) ext);
4482 fragP->fr_fix += ext;
4486 #ifndef BFD_ASSEMBLER
4489 md_convert_frag (headers, sec, fragP)
4490 object_headers *headers ATTRIBUTE_UNUSED;
4491 segT sec ATTRIBUTE_UNUSED;
4494 md_convert_frag_1 (fragP);
4500 md_convert_frag (abfd, sec, fragP)
4501 bfd *abfd ATTRIBUTE_UNUSED;
4502 segT sec ATTRIBUTE_UNUSED;
4505 md_convert_frag_1 (fragP);
4509 /* Force truly undefined symbols to their maximum size, and generally set up
4510 the frag list to be relaxed
4513 md_estimate_size_before_relax (fragP, segment)
4514 register fragS *fragP;
4518 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
4520 old_fix = fragP->fr_fix;
4522 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4523 switch (fragP->fr_subtype)
4526 case TAB (ABRANCH, SZ_UNDEF):
4528 if ((fragP->fr_symbol != NULL) /* Not absolute */
4529 && S_GET_SEGMENT (fragP->fr_symbol) == segment
4530 && relaxable_symbol (fragP->fr_symbol))
4532 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4535 else if ((fragP->fr_symbol != NULL) && flag_short_refs)
4536 { /* Symbol is undefined and we want short ref */
4537 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4538 fragP->fr_offset, 1, NO_RELOC);
4543 else if ((fragP->fr_symbol == 0) || !HAVE_LONG_BRANCH(current_architecture))
4545 /* On 68000, or for absolute value, switch to abs long */
4546 /* FIXME, we should check abs val, pick short or long */
4547 if (fragP->fr_opcode[0] == 0x61)
4549 fragP->fr_opcode[0] = 0x4E;
4550 fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4551 fix_new (fragP, fragP->fr_fix, 4,
4552 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
4556 else if (fragP->fr_opcode[0] == 0x60)
4558 fragP->fr_opcode[0] = 0x4E;
4559 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4560 fix_new (fragP, fragP->fr_fix, 4,
4561 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
4567 /* This should never happen, because if it's a conditional
4568 branch and we are on a 68000, BCC68000 should have been
4569 picked instead of ABRANCH. */
4574 { /* Symbol is still undefined. Make it simple */
4575 fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4576 fragP->fr_offset, 1, NO_RELOC);
4578 fragP->fr_opcode[1] = (char) 0xff;
4584 } /* case TAB(ABRANCH,SZ_UNDEF) */
4586 case TAB (FBRANCH, SZ_UNDEF):
4588 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4589 && relaxable_symbol (fragP->fr_symbol))
4592 fragP->fr_subtype = TAB (FBRANCH, SHORT);
4597 fix_new (fragP, (int) fragP->fr_fix, 4, fragP->fr_symbol,
4598 fragP->fr_offset, 1, NO_RELOC);
4600 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
4604 } /* TAB(FBRANCH,SZ_UNDEF) */
4606 case TAB (PCREL, SZ_UNDEF):
4608 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4609 && relaxable_symbol (fragP->fr_symbol))
4612 fragP->fr_subtype = TAB (PCREL, SHORT);
4617 fragP->fr_subtype = TAB (PCREL, LONG);
4621 } /* TAB(PCREL,SZ_UNDEF) */
4623 case TAB (BCC68000, SZ_UNDEF):
4625 if ((fragP->fr_symbol != NULL)
4626 && S_GET_SEGMENT (fragP->fr_symbol) == segment
4627 && relaxable_symbol (fragP->fr_symbol))
4629 fragP->fr_subtype = TAB (BCC68000, BYTE);
4632 /* only Bcc 68000 instructions can come here */
4633 if ((fragP->fr_symbol != NULL) && flag_short_refs)
4635 /* the user wants short refs, so emit one */
4636 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
4637 fragP->fr_offset, 1, NO_RELOC);
4642 /* change bcc into b!cc/jmp absl long */
4643 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
4644 fragP->fr_opcode[1] = 0x06; /* branch offset = 6 */
4645 /* JF: these were fr_opcode[2,3] */
4646 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
4647 buffer_address[1] = (char) 0xf9;
4648 fragP->fr_fix += 2; /* account for jmp instruction */
4649 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4650 fragP->fr_offset, 0, NO_RELOC);
4655 } /* case TAB(BCC68000,SZ_UNDEF) */
4657 case TAB (DBCC, SZ_UNDEF):
4659 if (fragP->fr_symbol != NULL
4660 && S_GET_SEGMENT (fragP->fr_symbol) == segment
4661 && relaxable_symbol (fragP->fr_symbol))
4663 fragP->fr_subtype = TAB (DBCC, SHORT);
4667 /* only DBcc 68000 instructions can come here */
4669 if (fragP->fr_symbol != NULL && flag_short_refs)
4671 /* the user wants short refs, so emit one */
4672 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
4673 fragP->fr_offset, 1, NO_RELOC);
4678 /* change dbcc into dbcc/jmp absl long */
4679 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4680 buffer_address[0] = 0x00; /* branch offset = 4 */
4681 buffer_address[1] = 0x04;
4682 buffer_address[2] = 0x60; /* put in bra pc + ... */
4683 /* JF: these were fr_opcode[5-7] */
4684 buffer_address[3] = 0x06; /* Plus 6 */
4685 buffer_address[4] = 0x4e; /* put in jmp long (0x4ef9) */
4686 buffer_address[5] = (char) 0xf9;
4687 fragP->fr_fix += 6; /* account for bra/jmp instruction */
4688 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4689 fragP->fr_offset, 0, NO_RELOC);
4695 } /* case TAB(DBCC,SZ_UNDEF) */
4697 case TAB (PCLEA, SZ_UNDEF):
4699 if (((S_GET_SEGMENT (fragP->fr_symbol)) == segment
4700 && relaxable_symbol (fragP->fr_symbol))
4702 || cpu_of_arch (current_architecture) < m68020
4703 || cpu_of_arch (current_architecture) == mcf5200)
4705 fragP->fr_subtype = TAB (PCLEA, SHORT);
4710 fragP->fr_subtype = TAB (PCLEA, LONG);
4714 } /* TAB(PCLEA,SZ_UNDEF) */
4716 case TAB (PCINDEX, SZ_UNDEF):
4717 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4718 && relaxable_symbol (fragP->fr_symbol))
4719 || cpu_of_arch (current_architecture) < m68020
4720 || cpu_of_arch (current_architecture) == mcf5200)
4722 fragP->fr_subtype = TAB (PCINDEX, BYTE);
4726 fragP->fr_subtype = TAB (PCINDEX, LONG);
4735 /* now that SZ_UNDEF are taken care of, check others */
4736 switch (fragP->fr_subtype)
4738 case TAB (BCC68000, BYTE):
4739 case TAB (ABRANCH, BYTE):
4740 /* We can't do a short jump to the next instruction, so in that
4741 case we force word mode. At this point S_GET_VALUE should
4742 return the offset of the symbol within its frag. If the
4743 symbol is at the start of a frag, and it is the next frag
4744 with any data in it (usually this is just the next frag, but
4745 assembler listings may introduce empty frags), we must use
4747 if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0)
4752 stop = symbol_get_frag (fragP->fr_symbol);
4753 for (l = fragP->fr_next; l != stop; l = l->fr_next)
4754 if (l->fr_fix + l->fr_var != 0)
4758 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4766 return fragP->fr_var + fragP->fr_fix - old_fix;
4769 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4770 /* the bit-field entries in the relocation_info struct plays hell
4771 with the byte-order problems of cross-assembly. So as a hack,
4772 I added this mach. dependent ri twiddler. Ugly, but it gets
4774 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4775 are symbolnum, most sig. byte first. Last byte is broken up with
4776 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4777 nibble as nuthin. (on Sun 3 at least) */
4778 /* Translate the internal relocation information into target-specific
4782 md_ri_to_chars (the_bytes, ri)
4784 struct reloc_info_generic *ri;
4787 md_number_to_chars (the_bytes, ri->r_address, 4);
4788 /* now the fun stuff */
4789 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
4790 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
4791 the_bytes[6] = ri->r_symbolnum & 0x0ff;
4792 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
4793 ((ri->r_extern << 4) & 0x10));
4796 #endif /* comment */
4798 #ifndef BFD_ASSEMBLER
4800 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
4803 relax_addressT segment_address_in_file;
4806 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4807 * Out: GNU LD relocation length code: 0, 1, or 2.
4810 static CONST unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
4813 know (fixP->fx_addsy != NULL);
4815 md_number_to_chars (where,
4816 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
4819 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
4820 ? S_GET_TYPE (fixP->fx_addsy)
4821 : fixP->fx_addsy->sy_number);
4823 where[4] = (r_symbolnum >> 16) & 0x0ff;
4824 where[5] = (r_symbolnum >> 8) & 0x0ff;
4825 where[6] = r_symbolnum & 0x0ff;
4826 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
4827 (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
4831 #endif /* OBJ_AOUT or OBJ_BOUT */
4833 #ifndef WORKING_DOT_WORD
4834 CONST int md_short_jump_size = 4;
4835 CONST int md_long_jump_size = 6;
4838 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
4840 addressT from_addr, to_addr;
4841 fragS *frag ATTRIBUTE_UNUSED;
4842 symbolS *to_symbol ATTRIBUTE_UNUSED;
4846 offset = to_addr - (from_addr + 2);
4848 md_number_to_chars (ptr, (valueT) 0x6000, 2);
4849 md_number_to_chars (ptr + 2, (valueT) offset, 2);
4853 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
4855 addressT from_addr, to_addr;
4861 if (!HAVE_LONG_BRANCH(current_architecture))
4863 offset = to_addr - S_GET_VALUE (to_symbol);
4864 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
4865 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4866 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
4871 offset = to_addr - (from_addr + 2);
4872 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
4873 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4879 /* Different values of OK tell what its OK to return. Things that
4880 aren't OK are an error (what a shock, no?)
4883 10: Absolute 1:8 only
4884 20: Absolute 0:7 only
4885 30: absolute 0:15 only
4886 40: Absolute 0:31 only
4887 50: absolute 0:127 only
4888 55: absolute -64:63 only
4889 60: absolute -128:127 only
4890 70: absolute 0:4095 only
4897 struct m68k_exp *exp;
4900 if (exp->exp.X_op == O_absent)
4902 /* Do the same thing the VAX asm does */
4903 op (exp) = O_constant;
4909 as_warn (_("expression out of range: defaulting to 1"));
4913 else if (exp->exp.X_op == O_constant)
4918 if (offs (exp) < 1 || offs (exp) > 8)
4920 as_warn (_("expression out of range: defaulting to 1"));
4925 if (offs (exp) < 0 || offs (exp) > 7)
4929 if (offs (exp) < 0 || offs (exp) > 15)
4933 if (offs (exp) < 0 || offs (exp) > 32)
4937 if (offs (exp) < 0 || offs (exp) > 127)
4941 if (offs (exp) < -64 || offs (exp) > 63)
4945 if (offs (exp) < -128 || offs (exp) > 127)
4949 if (offs (exp) < 0 || offs (exp) > 4095)
4952 as_warn (_("expression out of range: defaulting to 0"));
4960 else if (exp->exp.X_op == O_big)
4962 if (offs (exp) <= 0 /* flonum */
4963 && (ok == 80 /* no bignums */
4964 || (ok > 10 /* small-int ranges including 0 ok */
4965 /* If we have a flonum zero, a zero integer should
4966 do as well (e.g., in moveq). */
4967 && generic_floating_point_number.exponent == 0
4968 && generic_floating_point_number.low[0] == 0)))
4970 /* HACK! Turn it into a long */
4971 LITTLENUM_TYPE words[6];
4973 gen_to_words (words, 2, 8L); /* These numbers are magic! */
4974 op (exp) = O_constant;
4977 offs (exp) = words[1] | (words[0] << 16);
4981 op (exp) = O_constant;
4984 offs (exp) = (ok == 10) ? 1 : 0;
4985 as_warn (_("Can't deal with expression; defaulting to %ld"),
4991 if (ok >= 10 && ok <= 70)
4993 op (exp) = O_constant;
4996 offs (exp) = (ok == 10) ? 1 : 0;
4997 as_warn (_("Can't deal with expression; defaulting to %ld"),
5002 if (exp->size != SIZE_UNSPEC)
5010 if (!isbyte (offs (exp)))
5011 as_warn (_("expression doesn't fit in BYTE"));
5014 if (!isword (offs (exp)))
5015 as_warn (_("expression doesn't fit in WORD"));
5023 /* These are the back-ends for the various machine dependent pseudo-ops. */
5027 int ignore ATTRIBUTE_UNUSED;
5029 subseg_set (data_section, 1);
5030 demand_empty_rest_of_line ();
5035 int ignore ATTRIBUTE_UNUSED;
5037 subseg_set (data_section, 2);
5038 demand_empty_rest_of_line ();
5043 int ignore ATTRIBUTE_UNUSED;
5045 /* We don't support putting frags in the BSS segment, we fake it
5046 by marking in_bss, then looking at s_skip for clues. */
5048 subseg_set (bss_section, 0);
5049 demand_empty_rest_of_line ();
5054 int ignore ATTRIBUTE_UNUSED;
5057 register long temp_fill;
5059 temp = 1; /* JF should be 2? */
5060 temp_fill = get_absolute_expression ();
5061 if (!need_pass_2) /* Never make frag if expect extra pass. */
5062 frag_align (temp, (int) temp_fill, 0);
5063 demand_empty_rest_of_line ();
5064 record_alignment (now_seg, temp);
5069 int ignore ATTRIBUTE_UNUSED;
5071 demand_empty_rest_of_line ();
5074 /* Pseudo-ops handled for MRI compatibility. */
5076 /* This function returns non-zero if the argument is a conditional
5077 pseudo-op. This is called when checking whether a pending
5078 alignment is needed. */
5081 m68k_conditional_pseudoop (pop)
5084 return (pop->poc_handler == s_mri_if
5085 || pop->poc_handler == s_mri_else);
5088 /* Handle an MRI style chip specification. */
5097 s = input_line_pointer;
5098 /* We can't use get_symbol_end since the processor names are not proper
5100 while (is_part_of_name (c = *input_line_pointer++))
5102 *--input_line_pointer = 0;
5103 for (i = 0; i < n_archs; i++)
5104 if (strcasecmp (s, archs[i].name) == 0)
5108 as_bad (_("%s: unrecognized processor name"), s);
5109 *input_line_pointer = c;
5110 ignore_rest_of_line ();
5113 *input_line_pointer = c;
5115 if (*input_line_pointer == '/')
5116 current_architecture = 0;
5118 current_architecture &= m68881 | m68851;
5119 current_architecture |= archs[i].arch;
5121 while (*input_line_pointer == '/')
5123 ++input_line_pointer;
5124 s = input_line_pointer;
5125 /* We can't use get_symbol_end since the processor names are not
5127 while (is_part_of_name (c = *input_line_pointer++))
5129 *--input_line_pointer = 0;
5130 if (strcmp (s, "68881") == 0)
5131 current_architecture |= m68881;
5132 else if (strcmp (s, "68851") == 0)
5133 current_architecture |= m68851;
5134 *input_line_pointer = c;
5137 /* Update info about available control registers. */
5138 select_control_regs ();
5141 /* The MRI CHIP pseudo-op. */
5145 int ignore ATTRIBUTE_UNUSED;
5151 stop = mri_comment_field (&stopc);
5154 mri_comment_end (stop, stopc);
5155 demand_empty_rest_of_line ();
5158 /* The MRI FOPT pseudo-op. */
5162 int ignore ATTRIBUTE_UNUSED;
5166 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5170 input_line_pointer += 3;
5171 temp = get_absolute_expression ();
5172 if (temp < 0 || temp > 7)
5173 as_bad (_("bad coprocessor id"));
5175 m68k_float_copnum = COP0 + temp;
5179 as_bad (_("unrecognized fopt option"));
5180 ignore_rest_of_line ();
5184 demand_empty_rest_of_line ();
5187 /* The structure used to handle the MRI OPT pseudo-op. */
5191 /* The name of the option. */
5194 /* If this is not NULL, just call this function. The first argument
5195 is the ARG field of this structure, the second argument is
5196 whether the option was negated. */
5197 void (*pfn) PARAMS ((int arg, int on));
5199 /* If this is not NULL, and the PFN field is NULL, set the variable
5200 this points to. Set it to the ARG field if the option was not
5201 negated, and the NOTARG field otherwise. */
5204 /* The value to pass to PFN or to assign to *PVAR. */
5207 /* The value to assign to *PVAR if the option is negated. If PFN is
5208 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5209 the option may not be negated. */
5213 /* The table used to handle the MRI OPT pseudo-op. */
5215 static void skip_to_comma PARAMS ((int, int));
5216 static void opt_nest PARAMS ((int, int));
5217 static void opt_chip PARAMS ((int, int));
5218 static void opt_list PARAMS ((int, int));
5219 static void opt_list_symbols PARAMS ((int, int));
5221 static const struct opt_action opt_table[] =
5223 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5225 /* We do relaxing, so there is little use for these options. */
5226 { "b", 0, 0, 0, 0 },
5227 { "brs", 0, 0, 0, 0 },
5228 { "brb", 0, 0, 0, 0 },
5229 { "brl", 0, 0, 0, 0 },
5230 { "brw", 0, 0, 0, 0 },
5232 { "c", 0, 0, 0, 0 },
5233 { "cex", 0, 0, 0, 0 },
5234 { "case", 0, &symbols_case_sensitive, 1, 0 },
5235 { "cl", 0, 0, 0, 0 },
5236 { "cre", 0, 0, 0, 0 },
5237 { "d", 0, &flag_keep_locals, 1, 0 },
5238 { "e", 0, 0, 0, 0 },
5239 { "f", 0, &flag_short_refs, 1, 0 },
5240 { "frs", 0, &flag_short_refs, 1, 0 },
5241 { "frl", 0, &flag_short_refs, 0, 1 },
5242 { "g", 0, 0, 0, 0 },
5243 { "i", 0, 0, 0, 0 },
5244 { "m", 0, 0, 0, 0 },
5245 { "mex", 0, 0, 0, 0 },
5246 { "mc", 0, 0, 0, 0 },
5247 { "md", 0, 0, 0, 0 },
5248 { "nest", opt_nest, 0, 0, 0 },
5249 { "next", skip_to_comma, 0, 0, 0 },
5250 { "o", 0, 0, 0, 0 },
5251 { "old", 0, 0, 0, 0 },
5252 { "op", skip_to_comma, 0, 0, 0 },
5253 { "pco", 0, 0, 0, 0 },
5254 { "p", opt_chip, 0, 0, 0 },
5255 { "pcr", 0, 0, 0, 0 },
5256 { "pcs", 0, 0, 0, 0 },
5257 { "r", 0, 0, 0, 0 },
5258 { "quick", 0, &m68k_quick, 1, 0 },
5259 { "rel32", 0, &m68k_rel32, 1, 0 },
5260 { "s", opt_list, 0, 0, 0 },
5261 { "t", opt_list_symbols, 0, 0, 0 },
5262 { "w", 0, &flag_no_warnings, 0, 1 },
5266 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5268 /* The MRI OPT pseudo-op. */
5272 int ignore ATTRIBUTE_UNUSED;
5280 const struct opt_action *o;
5285 if (*input_line_pointer == '-')
5287 ++input_line_pointer;
5290 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5292 input_line_pointer += 2;
5296 s = input_line_pointer;
5297 c = get_symbol_end ();
5299 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5301 if (strcasecmp (s, o->name) == 0)
5305 /* Restore input_line_pointer now in case the option
5307 *input_line_pointer = c;
5308 (*o->pfn) (o->arg, t);
5310 else if (o->pvar != NULL)
5312 if (! t && o->arg == o->notarg)
5313 as_bad (_("option `%s' may not be negated"), s);
5314 *input_line_pointer = c;
5315 *o->pvar = t ? o->arg : o->notarg;
5318 *input_line_pointer = c;
5324 as_bad (_("option `%s' not recognized"), s);
5325 *input_line_pointer = c;
5328 while (*input_line_pointer++ == ',');
5330 /* Move back to terminating character. */
5331 --input_line_pointer;
5332 demand_empty_rest_of_line ();
5335 /* Skip ahead to a comma. This is used for OPT options which we do
5336 not suppor tand which take arguments. */
5339 skip_to_comma (arg, on)
5340 int arg ATTRIBUTE_UNUSED;
5341 int on ATTRIBUTE_UNUSED;
5343 while (*input_line_pointer != ','
5344 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5345 ++input_line_pointer;
5348 /* Handle the OPT NEST=depth option. */
5352 int arg ATTRIBUTE_UNUSED;
5353 int on ATTRIBUTE_UNUSED;
5355 if (*input_line_pointer != '=')
5357 as_bad (_("bad format of OPT NEST=depth"));
5361 ++input_line_pointer;
5362 max_macro_nest = get_absolute_expression ();
5365 /* Handle the OPT P=chip option. */
5369 int arg ATTRIBUTE_UNUSED;
5370 int on ATTRIBUTE_UNUSED;
5372 if (*input_line_pointer != '=')
5374 /* This is just OPT P, which we do not support. */
5378 ++input_line_pointer;
5382 /* Handle the OPT S option. */
5386 int arg ATTRIBUTE_UNUSED;
5392 /* Handle the OPT T option. */
5395 opt_list_symbols (arg, on)
5396 int arg ATTRIBUTE_UNUSED;
5400 listing |= LISTING_SYMBOLS;
5402 listing &=~ LISTING_SYMBOLS;
5405 /* Handle the MRI REG pseudo-op. */
5409 int ignore ATTRIBUTE_UNUSED;
5418 if (line_label == NULL)
5420 as_bad (_("missing label"));
5421 ignore_rest_of_line ();
5426 stop = mri_comment_field (&stopc);
5430 s = input_line_pointer;
5431 while (isalnum ((unsigned char) *input_line_pointer)
5432 #ifdef REGISTER_PREFIX
5433 || *input_line_pointer == REGISTER_PREFIX
5435 || *input_line_pointer == '/'
5436 || *input_line_pointer == '-')
5437 ++input_line_pointer;
5438 c = *input_line_pointer;
5439 *input_line_pointer = '\0';
5441 if (m68k_ip_op (s, &rop) != 0)
5443 if (rop.error == NULL)
5444 as_bad (_("bad register list"));
5446 as_bad (_("bad register list: %s"), rop.error);
5447 *input_line_pointer = c;
5448 ignore_rest_of_line ();
5452 *input_line_pointer = c;
5454 if (rop.mode == REGLST)
5456 else if (rop.mode == DREG)
5457 mask = 1 << (rop.reg - DATA0);
5458 else if (rop.mode == AREG)
5459 mask = 1 << (rop.reg - ADDR0 + 8);
5460 else if (rop.mode == FPREG)
5461 mask = 1 << (rop.reg - FP0 + 16);
5462 else if (rop.mode == CONTROL
5465 else if (rop.mode == CONTROL
5468 else if (rop.mode == CONTROL
5473 as_bad (_("bad register list"));
5474 ignore_rest_of_line ();
5478 S_SET_SEGMENT (line_label, reg_section);
5479 S_SET_VALUE (line_label, ~mask);
5480 symbol_set_frag (line_label, &zero_address_frag);
5483 mri_comment_end (stop, stopc);
5485 demand_empty_rest_of_line ();
5488 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5492 struct save_opts *next;
5494 int symbols_case_sensitive;
5502 /* FIXME: We don't save OPT S. */
5505 /* This variable holds the stack of saved options. */
5507 static struct save_opts *save_stack;
5509 /* The MRI SAVE pseudo-op. */
5513 int ignore ATTRIBUTE_UNUSED;
5515 struct save_opts *s;
5517 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5518 s->abspcadd = m68k_abspcadd;
5519 s->symbols_case_sensitive = symbols_case_sensitive;
5520 s->keep_locals = flag_keep_locals;
5521 s->short_refs = flag_short_refs;
5522 s->architecture = current_architecture;
5523 s->quick = m68k_quick;
5524 s->rel32 = m68k_rel32;
5525 s->listing = listing;
5526 s->no_warnings = flag_no_warnings;
5528 s->next = save_stack;
5531 demand_empty_rest_of_line ();
5534 /* The MRI RESTORE pseudo-op. */
5538 int ignore ATTRIBUTE_UNUSED;
5540 struct save_opts *s;
5542 if (save_stack == NULL)
5544 as_bad (_("restore without save"));
5545 ignore_rest_of_line ();
5550 save_stack = s->next;
5552 m68k_abspcadd = s->abspcadd;
5553 symbols_case_sensitive = s->symbols_case_sensitive;
5554 flag_keep_locals = s->keep_locals;
5555 flag_short_refs = s->short_refs;
5556 current_architecture = s->architecture;
5557 m68k_quick = s->quick;
5558 m68k_rel32 = s->rel32;
5559 listing = s->listing;
5560 flag_no_warnings = s->no_warnings;
5564 demand_empty_rest_of_line ();
5567 /* Types of MRI structured control directives. */
5569 enum mri_control_type
5577 /* This structure is used to stack the MRI structured control
5580 struct mri_control_info
5582 /* The directive within which this one is enclosed. */
5583 struct mri_control_info *outer;
5585 /* The type of directive. */
5586 enum mri_control_type type;
5588 /* Whether an ELSE has been in an IF. */
5591 /* The add or sub statement at the end of a FOR. */
5594 /* The label of the top of a FOR or REPEAT loop. */
5597 /* The label to jump to for the next iteration, or the else
5598 expression of a conditional. */
5601 /* The label to jump to to break out of the loop, or the label past
5602 the end of a conditional. */
5606 /* The stack of MRI structured control directives. */
5608 static struct mri_control_info *mri_control_stack;
5610 /* The current MRI structured control directive index number, used to
5611 generate label names. */
5613 static int mri_control_index;
5615 /* Some function prototypes. */
5617 static void mri_assemble PARAMS ((char *));
5618 static char *mri_control_label PARAMS ((void));
5619 static struct mri_control_info *push_mri_control
5620 PARAMS ((enum mri_control_type));
5621 static void pop_mri_control PARAMS ((void));
5622 static int parse_mri_condition PARAMS ((int *));
5623 static int parse_mri_control_operand
5624 PARAMS ((int *, char **, char **, char **, char **));
5625 static int swap_mri_condition PARAMS ((int));
5626 static int reverse_mri_condition PARAMS ((int));
5627 static void build_mri_control_operand
5628 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5629 const char *, int));
5630 static void parse_mri_control_expression
5631 PARAMS ((char *, int, const char *, const char *, int));
5633 /* Assemble an instruction for an MRI structured control directive. */
5641 /* md_assemble expects the opcode to be in lower case. */
5642 for (s = str; *s != ' ' && *s != '\0'; s++)
5644 if (isupper ((unsigned char) *s))
5645 *s = tolower ((unsigned char) *s);
5651 /* Generate a new MRI label structured control directive label name. */
5654 mri_control_label ()
5658 n = (char *) xmalloc (20);
5659 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5660 ++mri_control_index;
5664 /* Create a new MRI structured control directive. */
5666 static struct mri_control_info *
5667 push_mri_control (type)
5668 enum mri_control_type type;
5670 struct mri_control_info *n;
5672 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5676 if (type == mri_if || type == mri_while)
5679 n->top = mri_control_label ();
5680 n->next = mri_control_label ();
5681 n->bottom = mri_control_label ();
5683 n->outer = mri_control_stack;
5684 mri_control_stack = n;
5689 /* Pop off the stack of MRI structured control directives. */
5694 struct mri_control_info *n;
5696 n = mri_control_stack;
5697 mri_control_stack = n->outer;
5705 /* Recognize a condition code in an MRI structured control expression. */
5708 parse_mri_condition (pcc)
5713 know (*input_line_pointer == '<');
5715 ++input_line_pointer;
5716 c1 = *input_line_pointer++;
5717 c2 = *input_line_pointer++;
5719 if (*input_line_pointer != '>')
5721 as_bad (_("syntax error in structured control directive"));
5725 ++input_line_pointer;
5733 *pcc = (c1 << 8) | c2;
5738 /* Parse a single operand in an MRI structured control expression. */
5741 parse_mri_control_operand (pcc, leftstart, leftstop, rightstart, rightstop)
5758 if (*input_line_pointer == '<')
5760 /* It's just a condition code. */
5761 return parse_mri_condition (pcc);
5764 /* Look ahead for the condition code. */
5765 for (s = input_line_pointer; *s != '\0'; ++s)
5767 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
5772 as_bad (_("missing condition code in structured control directive"));
5776 *leftstart = input_line_pointer;
5778 if (*leftstop > *leftstart
5779 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
5782 input_line_pointer = s;
5783 if (! parse_mri_condition (pcc))
5786 /* Look ahead for AND or OR or end of line. */
5787 for (s = input_line_pointer; *s != '\0'; ++s)
5789 if ((strncasecmp (s, "AND", 3) == 0
5790 && (s[3] == '.' || ! is_part_of_name (s[3])))
5791 || (strncasecmp (s, "OR", 2) == 0
5792 && (s[2] == '.' || ! is_part_of_name (s[2]))))
5796 *rightstart = input_line_pointer;
5798 if (*rightstop > *rightstart
5799 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
5802 input_line_pointer = s;
5807 #define MCC(b1, b2) (((b1) << 8) | (b2))
5809 /* Swap the sense of a condition. This changes the condition so that
5810 it generates the same result when the operands are swapped. */
5813 swap_mri_condition (cc)
5818 case MCC ('h', 'i'): return MCC ('c', 's');
5819 case MCC ('l', 's'): return MCC ('c', 'c');
5820 case MCC ('c', 'c'): return MCC ('l', 's');
5821 case MCC ('c', 's'): return MCC ('h', 'i');
5822 case MCC ('p', 'l'): return MCC ('m', 'i');
5823 case MCC ('m', 'i'): return MCC ('p', 'l');
5824 case MCC ('g', 'e'): return MCC ('l', 'e');
5825 case MCC ('l', 't'): return MCC ('g', 't');
5826 case MCC ('g', 't'): return MCC ('l', 't');
5827 case MCC ('l', 'e'): return MCC ('g', 'e');
5832 /* Reverse the sense of a condition. */
5835 reverse_mri_condition (cc)
5840 case MCC ('h', 'i'): return MCC ('l', 's');
5841 case MCC ('l', 's'): return MCC ('h', 'i');
5842 case MCC ('c', 'c'): return MCC ('c', 's');
5843 case MCC ('c', 's'): return MCC ('c', 'c');
5844 case MCC ('n', 'e'): return MCC ('e', 'q');
5845 case MCC ('e', 'q'): return MCC ('n', 'e');
5846 case MCC ('v', 'c'): return MCC ('v', 's');
5847 case MCC ('v', 's'): return MCC ('v', 'c');
5848 case MCC ('p', 'l'): return MCC ('m', 'i');
5849 case MCC ('m', 'i'): return MCC ('p', 'l');
5850 case MCC ('g', 'e'): return MCC ('l', 't');
5851 case MCC ('l', 't'): return MCC ('g', 'e');
5852 case MCC ('g', 't'): return MCC ('l', 'e');
5853 case MCC ('l', 'e'): return MCC ('g', 't');
5858 /* Build an MRI structured control expression. This generates test
5859 and branch instructions. It goes to TRUELAB if the condition is
5860 true, and to FALSELAB if the condition is false. Exactly one of
5861 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5862 is the size qualifier for the expression. EXTENT is the size to
5863 use for the branch. */
5866 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5867 rightstop, truelab, falselab, extent)
5874 const char *truelab;
5875 const char *falselab;
5881 if (leftstart != NULL)
5883 struct m68k_op leftop, rightop;
5886 /* Swap the compare operands, if necessary, to produce a legal
5887 m68k compare instruction. Comparing a register operand with
5888 a non-register operand requires the register to be on the
5889 right (cmp, cmpa). Comparing an immediate value with
5890 anything requires the immediate value to be on the left
5895 (void) m68k_ip_op (leftstart, &leftop);
5900 (void) m68k_ip_op (rightstart, &rightop);
5903 if (rightop.mode == IMMED
5904 || ((leftop.mode == DREG || leftop.mode == AREG)
5905 && (rightop.mode != DREG && rightop.mode != AREG)))
5909 cc = swap_mri_condition (cc);
5911 leftstart = rightstart;
5914 leftstop = rightstop;
5919 if (truelab == NULL)
5921 cc = reverse_mri_condition (cc);
5925 if (leftstart != NULL)
5927 buf = (char *) xmalloc (20
5928 + (leftstop - leftstart)
5929 + (rightstop - rightstart));
5937 memcpy (s, leftstart, leftstop - leftstart);
5938 s += leftstop - leftstart;
5940 memcpy (s, rightstart, rightstop - rightstart);
5941 s += rightstop - rightstart;
5947 buf = (char *) xmalloc (20 + strlen (truelab));
5955 strcpy (s, truelab);
5960 /* Parse an MRI structured control expression. This generates test
5961 and branch instructions. STOP is where the expression ends. It
5962 goes to TRUELAB if the condition is true, and to FALSELAB if the
5963 condition is false. Exactly one of TRUELAB and FALSELAB will be
5964 NULL, meaning to fall through. QUAL is the size qualifier for the
5965 expression. EXTENT is the size to use for the branch. */
5968 parse_mri_control_expression (stop, qual, truelab, falselab, extent)
5971 const char *truelab;
5972 const char *falselab;
5985 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5986 &rightstart, &rightstop))
5992 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
5996 if (falselab != NULL)
5999 flab = mri_control_label ();
6001 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6002 rightstop, (const char *) NULL, flab, extent);
6004 input_line_pointer += 3;
6005 if (*input_line_pointer != '.'
6006 || input_line_pointer[1] == '\0')
6010 qual = input_line_pointer[1];
6011 input_line_pointer += 2;
6014 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6015 &rightstart, &rightstop))
6021 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6022 rightstop, truelab, falselab, extent);
6024 if (falselab == NULL)
6027 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6031 if (truelab != NULL)
6034 tlab = mri_control_label ();
6036 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6037 rightstop, tlab, (const char *) NULL, extent);
6039 input_line_pointer += 2;
6040 if (*input_line_pointer != '.'
6041 || input_line_pointer[1] == '\0')
6045 qual = input_line_pointer[1];
6046 input_line_pointer += 2;
6049 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6050 &rightstart, &rightstop))
6056 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6057 rightstop, truelab, falselab, extent);
6059 if (truelab == NULL)
6064 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6065 rightstop, truelab, falselab, extent);
6069 if (input_line_pointer != stop)
6070 as_bad (_("syntax error in structured control directive"));
6073 /* Handle the MRI IF pseudo-op. This may be a structured control
6074 directive, or it may be a regular assembler conditional, depending
6083 struct mri_control_info *n;
6085 /* A structured control directive must end with THEN with an
6086 optional qualifier. */
6087 s = input_line_pointer;
6088 while (! is_end_of_line[(unsigned char) *s]
6089 && (! flag_mri || *s != '*'))
6092 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6095 if (s - input_line_pointer > 1
6099 if (s - input_line_pointer < 3
6100 || strncasecmp (s - 3, "THEN", 4) != 0)
6104 as_bad (_("missing then"));
6105 ignore_rest_of_line ();
6109 /* It's a conditional. */
6114 /* Since this might be a conditional if, this pseudo-op will be
6115 called even if we are supported to be ignoring input. Double
6116 check now. Clobber *input_line_pointer so that ignore_input
6117 thinks that this is not a special pseudo-op. */
6118 c = *input_line_pointer;
6119 *input_line_pointer = 0;
6120 if (ignore_input ())
6122 *input_line_pointer = c;
6123 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6124 ++input_line_pointer;
6125 demand_empty_rest_of_line ();
6128 *input_line_pointer = c;
6130 n = push_mri_control (mri_if);
6132 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6133 n->next, s[1] == '.' ? s[2] : '\0');
6136 input_line_pointer = s + 3;
6138 input_line_pointer = s + 1;
6142 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6143 ++input_line_pointer;
6146 demand_empty_rest_of_line ();
6149 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6150 structured IF, associate the ELSE with the IF. Otherwise, assume
6151 it is a conditional else. */
6162 && (mri_control_stack == NULL
6163 || mri_control_stack->type != mri_if
6164 || mri_control_stack->else_seen))
6170 c = *input_line_pointer;
6171 *input_line_pointer = 0;
6172 if (ignore_input ())
6174 *input_line_pointer = c;
6175 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6176 ++input_line_pointer;
6177 demand_empty_rest_of_line ();
6180 *input_line_pointer = c;
6182 if (mri_control_stack == NULL
6183 || mri_control_stack->type != mri_if
6184 || mri_control_stack->else_seen)
6186 as_bad (_("else without matching if"));
6187 ignore_rest_of_line ();
6191 mri_control_stack->else_seen = 1;
6193 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6196 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6200 colon (mri_control_stack->next);
6204 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6205 ++input_line_pointer;
6208 demand_empty_rest_of_line ();
6211 /* Handle the MRI ENDI pseudo-op. */
6215 int ignore ATTRIBUTE_UNUSED;
6217 if (mri_control_stack == NULL
6218 || mri_control_stack->type != mri_if)
6220 as_bad (_("endi without matching if"));
6221 ignore_rest_of_line ();
6225 /* ignore_input will not return true for ENDI, so we don't need to
6226 worry about checking it again here. */
6228 if (! mri_control_stack->else_seen)
6229 colon (mri_control_stack->next);
6230 colon (mri_control_stack->bottom);
6236 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6237 ++input_line_pointer;
6240 demand_empty_rest_of_line ();
6243 /* Handle the MRI BREAK pseudo-op. */
6246 s_mri_break (extent)
6249 struct mri_control_info *n;
6253 n = mri_control_stack;
6255 && n->type != mri_for
6256 && n->type != mri_repeat
6257 && n->type != mri_while)
6261 as_bad (_("break outside of structured loop"));
6262 ignore_rest_of_line ();
6266 buf = (char *) xmalloc (20 + strlen (n->bottom));
6269 sprintf (buf, "bra%s %s", ex, n->bottom);
6275 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6276 ++input_line_pointer;
6279 demand_empty_rest_of_line ();
6282 /* Handle the MRI NEXT pseudo-op. */
6288 struct mri_control_info *n;
6292 n = mri_control_stack;
6294 && n->type != mri_for
6295 && n->type != mri_repeat
6296 && n->type != mri_while)
6300 as_bad (_("next outside of structured loop"));
6301 ignore_rest_of_line ();
6305 buf = (char *) xmalloc (20 + strlen (n->next));
6308 sprintf (buf, "bra%s %s", ex, n->next);
6314 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6315 ++input_line_pointer;
6318 demand_empty_rest_of_line ();
6321 /* Handle the MRI FOR pseudo-op. */
6327 const char *varstart, *varstop;
6328 const char *initstart, *initstop;
6329 const char *endstart, *endstop;
6330 const char *bystart, *bystop;
6334 struct mri_control_info *n;
6340 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6344 varstart = input_line_pointer;
6346 /* Look for the '='. */
6347 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6348 && *input_line_pointer != '=')
6349 ++input_line_pointer;
6350 if (*input_line_pointer != '=')
6352 as_bad (_("missing ="));
6353 ignore_rest_of_line ();
6357 varstop = input_line_pointer;
6358 if (varstop > varstart
6359 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6362 ++input_line_pointer;
6364 initstart = input_line_pointer;
6366 /* Look for TO or DOWNTO. */
6369 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6371 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6372 && ! is_part_of_name (input_line_pointer[2]))
6374 initstop = input_line_pointer;
6375 input_line_pointer += 2;
6378 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6379 && ! is_part_of_name (input_line_pointer[6]))
6381 initstop = input_line_pointer;
6383 input_line_pointer += 6;
6386 ++input_line_pointer;
6388 if (initstop == NULL)
6390 as_bad (_("missing to or downto"));
6391 ignore_rest_of_line ();
6394 if (initstop > initstart
6395 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6399 endstart = input_line_pointer;
6401 /* Look for BY or DO. */
6404 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6406 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6407 && ! is_part_of_name (input_line_pointer[2]))
6409 endstop = input_line_pointer;
6411 input_line_pointer += 2;
6414 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6415 && (input_line_pointer[2] == '.'
6416 || ! is_part_of_name (input_line_pointer[2])))
6418 endstop = input_line_pointer;
6419 input_line_pointer += 2;
6422 ++input_line_pointer;
6424 if (endstop == NULL)
6426 as_bad (_("missing do"));
6427 ignore_rest_of_line ();
6430 if (endstop > endstart
6431 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6437 bystop = bystart + 2;
6442 bystart = input_line_pointer;
6446 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6448 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6449 && (input_line_pointer[2] == '.'
6450 || ! is_part_of_name (input_line_pointer[2])))
6452 bystop = input_line_pointer;
6453 input_line_pointer += 2;
6456 ++input_line_pointer;
6460 as_bad (_("missing do"));
6461 ignore_rest_of_line ();
6464 if (bystop > bystart
6465 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6469 if (*input_line_pointer != '.')
6473 extent = input_line_pointer[1];
6474 input_line_pointer += 2;
6477 /* We have fully parsed the FOR operands. Now build the loop. */
6479 n = push_mri_control (mri_for);
6481 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6492 memcpy (s, initstart, initstop - initstart);
6493 s += initstop - initstart;
6495 memcpy (s, varstart, varstop - varstart);
6496 s += varstop - varstart;
6510 memcpy (s, endstart, endstop - endstart);
6511 s += endstop - endstart;
6513 memcpy (s, varstart, varstop - varstart);
6514 s += varstop - varstart;
6522 sprintf (buf, "blt%s %s", ex, n->bottom);
6524 sprintf (buf, "bgt%s %s", ex, n->bottom);
6527 /* Put together the add or sub instruction used by ENDF. */
6537 memcpy (s, bystart, bystop - bystart);
6538 s += bystop - bystart;
6540 memcpy (s, varstart, varstop - varstart);
6541 s += varstop - varstart;
6547 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6548 ++input_line_pointer;
6551 demand_empty_rest_of_line ();
6554 /* Handle the MRI ENDF pseudo-op. */
6558 int ignore ATTRIBUTE_UNUSED;
6560 if (mri_control_stack == NULL
6561 || mri_control_stack->type != mri_for)
6563 as_bad (_("endf without for"));
6564 ignore_rest_of_line ();
6568 colon (mri_control_stack->next);
6570 mri_assemble (mri_control_stack->incr);
6572 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6573 mri_assemble (mri_control_stack->incr);
6575 free (mri_control_stack->incr);
6577 colon (mri_control_stack->bottom);
6583 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6584 ++input_line_pointer;
6587 demand_empty_rest_of_line ();
6590 /* Handle the MRI REPEAT pseudo-op. */
6593 s_mri_repeat (ignore)
6594 int ignore ATTRIBUTE_UNUSED;
6596 struct mri_control_info *n;
6598 n = push_mri_control (mri_repeat);
6602 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6603 ++input_line_pointer;
6605 demand_empty_rest_of_line ();
6608 /* Handle the MRI UNTIL pseudo-op. */
6616 if (mri_control_stack == NULL
6617 || mri_control_stack->type != mri_repeat)
6619 as_bad (_("until without repeat"));
6620 ignore_rest_of_line ();
6624 colon (mri_control_stack->next);
6626 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6629 parse_mri_control_expression (s, qual, (const char *) NULL,
6630 mri_control_stack->top, '\0');
6632 colon (mri_control_stack->bottom);
6634 input_line_pointer = s;
6640 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6641 ++input_line_pointer;
6644 demand_empty_rest_of_line ();
6647 /* Handle the MRI WHILE pseudo-op. */
6655 struct mri_control_info *n;
6657 s = input_line_pointer;
6658 while (! is_end_of_line[(unsigned char) *s]
6659 && (! flag_mri || *s != '*'))
6662 while (*s == ' ' || *s == '\t')
6664 if (s - input_line_pointer > 1
6667 if (s - input_line_pointer < 2
6668 || strncasecmp (s - 1, "DO", 2) != 0)
6670 as_bad (_("missing do"));
6671 ignore_rest_of_line ();
6675 n = push_mri_control (mri_while);
6679 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6680 s[1] == '.' ? s[2] : '\0');
6682 input_line_pointer = s + 1;
6683 if (*input_line_pointer == '.')
6684 input_line_pointer += 2;
6688 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6689 ++input_line_pointer;
6692 demand_empty_rest_of_line ();
6695 /* Handle the MRI ENDW pseudo-op. */
6699 int ignore ATTRIBUTE_UNUSED;
6703 if (mri_control_stack == NULL
6704 || mri_control_stack->type != mri_while)
6706 as_bad (_("endw without while"));
6707 ignore_rest_of_line ();
6711 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
6712 sprintf (buf, "bra %s", mri_control_stack->next);
6716 colon (mri_control_stack->bottom);
6722 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6723 ++input_line_pointer;
6726 demand_empty_rest_of_line ();
6731 * Invocation line includes a switch not recognized by the base assembler.
6732 * See if it's a processor-specific option. These are:
6734 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6735 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6736 * Select the architecture. Instructions or features not
6737 * supported by the selected architecture cause fatal
6738 * errors. More than one may be specified. The default is
6739 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6740 * for -m68000, and -m68882 is a synonym for -m68881.
6741 * -[A]m[c]no-68851, -[A]m[c]no-68881
6742 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6743 * so don't use or document it, but that's the way the parsing
6746 * -pic Indicates PIC.
6747 * -k Indicates PIC. (Sun 3 only.)
6750 * Permit `|' to be used in expressions.
6755 CONST char *md_shortopts = "lSA:m:kQ:V";
6757 CONST char *md_shortopts = "lSA:m:k";
6760 struct option md_longopts[] = {
6761 #define OPTION_PIC (OPTION_MD_BASE)
6762 {"pic", no_argument, NULL, OPTION_PIC},
6763 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6764 {"register-prefix-optional", no_argument, NULL,
6765 OPTION_REGISTER_PREFIX_OPTIONAL},
6766 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6767 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
6768 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6769 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
6770 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6771 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
6772 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6773 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
6774 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6775 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
6776 {NULL, no_argument, NULL, 0}
6778 size_t md_longopts_size = sizeof(md_longopts);
6781 md_parse_option (c, arg)
6787 case 'l': /* -l means keep external to 2 bit offset
6788 rather than 16 bit one */
6789 flag_short_refs = 1;
6792 case 'S': /* -S means that jbsr's always turn into
6794 flag_long_jumps = 1;
6800 /* intentional fall-through */
6803 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
6807 const char *oarg = arg;
6813 if (arg[0] == 'c' && arg[1] == '6')
6816 for (i = 0; i < n_archs; i++)
6817 if (!strcmp (arg, archs[i].name))
6822 as_bad (_("unrecognized option `%s'"), oarg);
6825 arch = archs[i].arch;
6828 else if (arch == m68851)
6837 if (arg[0] == 'c' && arg[1] == '6')
6840 for (i = 0; i < n_archs; i++)
6841 if (!strcmp (arg, archs[i].name))
6843 unsigned long arch = archs[i].arch;
6844 if (cpu_of_arch (arch))
6845 /* It's a cpu spec. */
6847 current_architecture &= ~m68000up;
6848 current_architecture |= arch;
6850 else if (arch == m68881)
6852 current_architecture |= m68881;
6855 else if (arch == m68851)
6857 current_architecture |= m68851;
6867 as_bad (_("unrecognized architecture specification `%s'"), arg);
6876 break; /* -pic, Position Independent Code */
6878 case OPTION_REGISTER_PREFIX_OPTIONAL:
6879 flag_reg_prefix_optional = 1;
6880 reg_prefix_optional_seen = 1;
6883 /* -V: SVR4 argument to print version ID. */
6885 print_version_id ();
6888 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6889 should be emitted or not. FIXME: Not implemented. */
6893 case OPTION_BITWISE_OR:
6898 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
6900 for (s = m68k_comment_chars; *s != '\0'; s++)
6904 m68k_comment_chars = n;
6908 case OPTION_BASE_SIZE_DEFAULT_16:
6909 m68k_index_width_default = SIZE_WORD;
6912 case OPTION_BASE_SIZE_DEFAULT_32:
6913 m68k_index_width_default = SIZE_LONG;
6916 case OPTION_DISP_SIZE_DEFAULT_16:
6918 m68k_rel32_from_cmdline = 1;
6921 case OPTION_DISP_SIZE_DEFAULT_32:
6923 m68k_rel32_from_cmdline = 1;
6934 md_show_usage (stream)
6937 fprintf(stream, _("\
6939 -l use 1 word for refs to undefined symbols [default 2]\n\
6940 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6941 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6942 | -mcpu32 | -m5200\n\
6943 specify variant of 680X0 architecture [default 68020]\n\
6944 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6945 target has/lacks floating-point coprocessor\n\
6946 [default yes for 68020, 68030, and cpu32]\n"));
6947 fprintf(stream, _("\
6948 -m68851 | -mno-68851\n\
6949 target has/lacks memory-management unit coprocessor\n\
6950 [default yes for 68020 and up]\n\
6951 -pic, -k generate position independent code\n\
6952 -S turn jbsr into jsr\n\
6953 --register-prefix-optional\n\
6954 recognize register names without prefix character\n\
6955 --bitwise-or do not treat `|' as a comment character\n"));
6956 fprintf (stream, _("\
6957 --base-size-default-16 base reg without size is 16 bits\n\
6958 --base-size-default-32 base reg without size is 32 bits (default)\n\
6959 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6960 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
6965 /* TEST2: Test md_assemble() */
6966 /* Warning, this routine probably doesn't work anymore */
6970 struct m68k_it the_ins;
6978 if (!gets (buf) || !*buf)
6980 if (buf[0] == '|' || buf[1] == '.')
6982 for (cp = buf; *cp; cp++)
6987 memset (&the_ins, '\0', sizeof (the_ins));
6988 m68k_ip (&the_ins, buf);
6991 printf (_("Error %s in %s\n"), the_ins.error, buf);
6995 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
6996 for (n = 0; n < the_ins.numo; n++)
6997 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
6999 print_the_insn (&the_ins.opcode[0], stdout);
7000 (void) putchar ('\n');
7002 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7004 if (the_ins.operands[n].error)
7006 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7009 printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
7010 if (the_ins.operands[n].b_const)
7011 printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
7012 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
7013 if (the_ins.operands[n].b_iadd)
7014 printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
7015 (void) putchar ('\n');
7027 while (*str && *str != ' ')
7029 if (str[-1] == ':' || str[1] == '=')
7036 /* Possible states for relaxation:
7038 0 0 branch offset byte (bra, etc)
7042 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7046 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7053 /* We have no need to default values of symbols. */
7057 md_undefined_symbol (name)
7058 char *name ATTRIBUTE_UNUSED;
7063 /* Round up a section size to the appropriate boundary. */
7065 md_section_align (segment, size)
7066 segT segment ATTRIBUTE_UNUSED;
7070 #ifdef BFD_ASSEMBLER
7071 /* For a.out, force the section size to be aligned. If we don't do
7072 this, BFD will align it for us, but it will not write out the
7073 final bytes of the section. This may be a bug in BFD, but it is
7074 easier to fix it here since that is how the other a.out targets
7078 align = bfd_get_section_alignment (stdoutput, segment);
7079 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7086 /* Exactly what point is a PC-relative offset relative TO?
7087 On the 68k, it is relative to the address of the first extension
7088 word. The difference between the addresses of the offset and the
7089 first extension word is stored in fx_pcrel_adjust. */
7091 md_pcrel_from (fixP)
7096 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
7098 adjust = fixP->fx_pcrel_adjust;
7101 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7104 #ifndef BFD_ASSEMBLER
7109 tc_coff_symbol_emit_hook (ignore)
7110 symbolS *ignore ATTRIBUTE_UNUSED;
7115 tc_coff_sizemachdep (frag)
7118 switch (frag->fr_subtype & 0x3)
7135 void m68k_elf_final_processing()
7137 /* Set file-specific flags if this is a cpu32 processor */
7138 if (cpu_of_arch (current_architecture) & cpu32)
7139 elf_elfheader (stdoutput)->e_flags |= EF_CPU32;
7142 /* end of tc-m68k.c */