1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 1997
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"
30 /* This string holds the chars that always start a comment. If the
31 pre-processor is disabled, these aren't very useful. The macro
32 tc_comment_chars points to this. We use this, rather than the
33 usual comment_chars, so that the --bitwise-or option will work. */
34 #if (defined (OBJ_ELF) && ! defined (TE_PSOS) && ! defined (TE_LINUX)) || defined (TE_DELTA)
35 const char *m68k_comment_chars = "|#";
37 const char *m68k_comment_chars = "|";
40 /* This array holds the chars that only start a comment at the beginning of
41 a line. If the line seems to have the form '# 123 filename'
42 .line and .file directives will appear in the pre-processed output */
43 /* Note that input_file.c hand checks for '#' at the beginning of the
44 first line of the input file. This is because the compiler outputs
45 #NO_APP at the beginning of its output. */
46 /* Also note that comments like this one will always work. */
47 const char line_comment_chars[] = "#";
49 const char line_separator_chars[] = "";
51 /* Chars that can be used to separate mant from exp in floating point nums */
52 CONST char EXP_CHARS[] = "eE";
54 /* Chars that mean this number is a floating point constant, as
55 in "0f12.456" or "0d1.2345e12". */
57 CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
59 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
60 changed in read.c . Ideally it shouldn't have to know about it at all,
61 but nothing is ideal around here. */
63 const int md_reloc_size = 8; /* Size of relocation record */
65 /* Are we trying to generate PIC code? If so, absolute references
66 ought to be made into linkage table references or pc-relative
67 references. Not implemented. For ELF there are other means
68 to denote pic relocations. */
71 static int flag_short_refs; /* -l option */
72 static int flag_long_jumps; /* -S option */
74 #ifdef REGISTER_PREFIX_OPTIONAL
75 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
77 int flag_reg_prefix_optional;
80 /* Whether --register-prefix-optional was used on the command line. */
81 static int reg_prefix_optional_seen;
83 /* The floating point coprocessor to use by default. */
84 static enum m68k_register m68k_float_copnum = COP1;
86 /* If this is non-zero, then references to number(%pc) will be taken
87 to refer to number, rather than to %pc + number. */
88 static int m68k_abspcadd;
90 /* If this is non-zero, then the quick forms of the move, add, and sub
91 instructions are used when possible. */
92 static int m68k_quick = 1;
94 /* If this is non-zero, then if the size is not specified for a base
95 or outer displacement, the assembler assumes that the size should
97 static int m68k_rel32 = 1;
99 /* This is non-zero if m68k_rel32 was set from the command line. */
100 static int m68k_rel32_from_cmdline;
102 /* The default width to use for an index register when using a base
104 static enum m68k_size m68k_index_width_default = SIZE_LONG;
106 /* Its an arbitrary name: This means I don't approve of it */
107 /* See flames below */
108 static struct obstack robyn;
110 #define TAB(x,y) (((x)<<2)+(y))
111 #define TABTYPE(xy) ((xy) >> 2)
117 /* Case `g' except when BCC68000 is applicable. */
119 /* Coprocessor branches. */
121 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
122 supported on all cpus. Widens to 32-bit absolute. */
124 /* For inserting an extra jmp instruction with long offset on 68000,
125 for expanding conditional branches. (Not bsr or bra.) Since the
126 68000 doesn't support 32-bit displacements for conditional
127 branches, we fake it by reversing the condition and branching
128 around a jmp with an absolute long operand. */
130 /* For the DBcc "instructions". If the displacement requires 32 bits,
131 the branch-around-a-jump game is played here too. */
133 /* Not currently used? */
135 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
141 const char *m_operands;
142 unsigned long m_opcode;
146 struct m68k_incant *m_next;
149 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
150 #define gettwo(x) (((x)->m_opcode)&0xffff)
152 static const enum m68k_register m68000_control_regs[] = { 0 };
153 static const enum m68k_register m68010_control_regs[] = {
157 static const enum m68k_register m68020_control_regs[] = {
158 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
161 static const enum m68k_register m68040_control_regs[] = {
162 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
163 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
166 static const enum m68k_register m68060_control_regs[] = {
167 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
168 USP, VBR, URP, SRP, PCR,
171 static const enum m68k_register mcf5200_control_regs[] = {
172 CACR, TC, ITT0, ITT1, DTT0, DTT1, VBR, ROMBAR,
173 RAMBAR0, RAMBAR1, MBAR,
176 #define cpu32_control_regs m68010_control_regs
178 static const enum m68k_register *control_regs;
180 /* internal form of a 68020 instruction */
184 const char *args; /* list of opcode info */
187 int numo; /* Number of shorts in opcode */
190 struct m68k_op operands[6];
192 int nexp; /* number of exprs in use */
193 struct m68k_exp exprs[4];
195 int nfrag; /* Number of frags we have to produce */
198 int fragoff; /* Where in the current opcode the frag ends */
205 int nrel; /* Num of reloc strucs in use */
212 /* In a pc relative address the difference between the address
213 of the offset and the address that the offset is relative
214 to. This depends on the addressing mode. Basically this
215 is the value to put in the offset field to address the
216 first byte of the offset, without regarding the special
217 significance of some values (in the branch instruction, for
221 /* Whether this expression needs special pic relocation, and if
223 enum pic_relocation pic_reloc;
226 reloc[5]; /* Five is enough??? */
229 #define cpu_of_arch(x) ((x) & (m68000up|mcf5200))
230 #define float_of_arch(x) ((x) & mfloat)
231 #define mmu_of_arch(x) ((x) & mmmu)
233 static struct m68k_it the_ins; /* the instruction being assembled */
235 #define op(ex) ((ex)->exp.X_op)
236 #define adds(ex) ((ex)->exp.X_add_symbol)
237 #define subs(ex) ((ex)->exp.X_op_symbol)
238 #define offs(ex) ((ex)->exp.X_add_number)
240 /* Macros for adding things to the m68k_it struct */
242 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
244 /* Like addword, but goes BEFORE general operands */
248 struct m68k_incant *opcode;
251 for(z=the_ins.numo;z>opcode->m_codenum;--z)
252 the_ins.opcode[z]=the_ins.opcode[z-1];
253 for(z=0;z<the_ins.nrel;z++)
254 the_ins.reloc[z].n+=2;
255 for (z = 0; z < the_ins.nfrag; z++)
256 the_ins.fragb[z].fragoff++;
257 the_ins.opcode[opcode->m_codenum]=w;
261 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
264 add_fix (width, exp, pc_rel, pc_fix)
266 struct m68k_exp *exp;
270 the_ins.reloc[the_ins.nrel].n = ((width == 'B' || width == '3')
274 : (the_ins.numo*2)));
275 the_ins.reloc[the_ins.nrel].exp = exp->exp;
276 the_ins.reloc[the_ins.nrel].wid = width;
277 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
279 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
281 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
284 /* Cause an extra frag to be generated here, inserting up to 10 bytes
285 (that value is chosen in the frag_var call in md_assemble). TYPE
286 is the subtype of the frag to be generated; its primary type is
287 rs_machine_dependent.
289 The TYPE parameter is also used by md_convert_frag_1 and
290 md_estimate_size_before_relax. The appropriate type of fixup will
291 be emitted by md_convert_frag_1.
293 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
295 add_frag(add,off,type)
300 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;
301 the_ins.fragb[the_ins.nfrag].fadd=add;
302 the_ins.fragb[the_ins.nfrag].foff=off;
303 the_ins.fragb[the_ins.nfrag++].fragty=type;
307 (op (ex) != O_constant && op (ex) != O_big)
309 static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
310 static int get_num PARAMS ((struct m68k_exp *exp, int ok));
311 static int reverse_16_bits PARAMS ((int in));
312 static int reverse_8_bits PARAMS ((int in));
313 static void install_gen_operand PARAMS ((int mode, int val));
314 static void install_operand PARAMS ((int mode, int val));
315 static void s_bss PARAMS ((int));
316 static void s_data1 PARAMS ((int));
317 static void s_data2 PARAMS ((int));
318 static void s_even PARAMS ((int));
319 static void s_proc PARAMS ((int));
320 static void mri_chip PARAMS ((void));
321 static void s_chip PARAMS ((int));
322 static void s_fopt PARAMS ((int));
323 static void s_opt PARAMS ((int));
324 static void s_reg PARAMS ((int));
325 static void s_restore PARAMS ((int));
326 static void s_save PARAMS ((int));
327 static void s_mri_if PARAMS ((int));
328 static void s_mri_else PARAMS ((int));
329 static void s_mri_endi PARAMS ((int));
330 static void s_mri_break PARAMS ((int));
331 static void s_mri_next PARAMS ((int));
332 static void s_mri_for PARAMS ((int));
333 static void s_mri_endf PARAMS ((int));
334 static void s_mri_repeat PARAMS ((int));
335 static void s_mri_until PARAMS ((int));
336 static void s_mri_while PARAMS ((int));
337 static void s_mri_endw PARAMS ((int));
339 static int current_architecture;
347 static const struct m68k_cpu archs[] = {
348 { m68000, "68000", 0 },
349 { m68010, "68010", 0 },
350 { m68020, "68020", 0 },
351 { m68030, "68030", 0 },
352 { m68040, "68040", 0 },
353 { m68060, "68060", 0 },
354 { cpu32, "cpu32", 0 },
355 { m68881, "68881", 0 },
356 { m68851, "68851", 0 },
357 { mcf5200, "5200", 0 },
358 /* Aliases (effectively, so far as gas is concerned) for the above
360 { m68020, "68k", 1 },
361 { m68000, "68302", 1 },
362 { m68000, "68008", 1 },
363 { m68000, "68ec000", 1 },
364 { m68000, "68hc000", 1 },
365 { m68000, "68hc001", 1 },
366 { m68020, "68ec020", 1 },
367 { m68030, "68ec030", 1 },
368 { m68040, "68ec040", 1 },
369 { m68060, "68ec060", 1 },
370 { cpu32, "68330", 1 },
371 { cpu32, "68331", 1 },
372 { cpu32, "68332", 1 },
373 { cpu32, "68333", 1 },
374 { cpu32, "68340", 1 },
375 { cpu32, "68360", 1 },
376 { m68881, "68882", 1 },
379 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
381 /* BCC68000 is for patching in an extra jmp instruction for long offsets
382 on the 68000. The 68000 doesn't support long branches with branchs */
384 /* This table desribes how you change sizes for the various types of variable
385 size expressions. This version only supports two kinds. */
387 /* Note that calls to frag_var need to specify the maximum expansion
388 needed; this is currently 10 bytes for DBCC. */
391 How far Forward this mode will reach:
392 How far Backward this mode will reach:
393 How many bytes this mode will add to the size of the frag
394 Which mode to go to if the offset won't fit in this one
396 relax_typeS md_relax_table[] =
398 {1, 1, 0, 0}, /* First entries aren't used */
399 {1, 1, 0, 0}, /* For no good reason except */
400 {1, 1, 0, 0}, /* that the VAX doesn't either */
403 {(127), (-128), 0, TAB (ABRANCH, SHORT)},
404 {(32767), (-32768), 2, TAB (ABRANCH, LONG)},
408 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
409 {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
413 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
414 {(32767), (-32768), 2, TAB (PCREL, LONG)},
418 {(127), (-128), 0, TAB (BCC68000, SHORT)},
419 {(32767), (-32768), 2, TAB (BCC68000, LONG)},
420 {0, 0, 6, 0}, /* jmp long space */
423 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
424 {(32767), (-32768), 2, TAB (DBCC, LONG)},
425 {0, 0, 10, 0}, /* bra/jmp long space */
428 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
429 {32767, -32768, 2, TAB (PCLEA, LONG)},
433 /* For, e.g., jmp pcrel indexed. */
434 {125, -130, 0, TAB (PCINDEX, SHORT)},
435 {32765, -32770, 2, TAB (PCINDEX, LONG)},
440 /* These are the machine dependent pseudo-ops. These are included so
441 the assembler can work on the output from the SUN C compiler, which
445 /* This table describes all the machine specific pseudo-ops the assembler
446 has to support. The fields are:
447 pseudo-op name without dot
448 function to call to execute this pseudo-op
449 Integer arg to pass to the function
451 const pseudo_typeS md_pseudo_table[] =
453 {"data1", s_data1, 0},
454 {"data2", s_data2, 0},
457 {"skip", s_space, 0},
459 #if defined (TE_SUN3) || defined (OBJ_ELF)
460 {"align", s_align_bytes, 0},
463 {"swbeg", s_ignore, 0},
465 {"extend", float_cons, 'x'},
466 {"ldouble", float_cons, 'x'},
468 /* The following pseudo-ops are supported for MRI compatibility. */
470 {"comline", s_space, 1},
472 {"mask2", s_ignore, 0},
475 {"restore", s_restore, 0},
479 {"if.b", s_mri_if, 'b'},
480 {"if.w", s_mri_if, 'w'},
481 {"if.l", s_mri_if, 'l'},
482 {"else", s_mri_else, 0},
483 {"else.s", s_mri_else, 's'},
484 {"else.l", s_mri_else, 'l'},
485 {"endi", s_mri_endi, 0},
486 {"break", s_mri_break, 0},
487 {"break.s", s_mri_break, 's'},
488 {"break.l", s_mri_break, 'l'},
489 {"next", s_mri_next, 0},
490 {"next.s", s_mri_next, 's'},
491 {"next.l", s_mri_next, 'l'},
492 {"for", s_mri_for, 0},
493 {"for.b", s_mri_for, 'b'},
494 {"for.w", s_mri_for, 'w'},
495 {"for.l", s_mri_for, 'l'},
496 {"endf", s_mri_endf, 0},
497 {"repeat", s_mri_repeat, 0},
498 {"until", s_mri_until, 0},
499 {"until.b", s_mri_until, 'b'},
500 {"until.w", s_mri_until, 'w'},
501 {"until.l", s_mri_until, 'l'},
502 {"while", s_mri_while, 0},
503 {"while.b", s_mri_while, 'b'},
504 {"while.w", s_mri_while, 'w'},
505 {"while.l", s_mri_while, 'l'},
506 {"endw", s_mri_endw, 0},
512 /* The mote pseudo ops are put into the opcode table, since they
513 don't start with a . they look like opcodes to gas.
515 extern void obj_coff_section ();
517 CONST pseudo_typeS mote_pseudo_table[] =
530 {"xdef", s_globl, 0},
532 {"align", s_align_bytes, 0},
534 {"align", s_align_ptwo, 0},
537 {"sect", obj_coff_section, 0},
538 {"section", obj_coff_section, 0},
543 #define issbyte(x) ((x)>=-128 && (x)<=127)
544 #define isubyte(x) ((x)>=0 && (x)<=255)
545 #define issword(x) ((x)>=-32768 && (x)<=32767)
546 #define isuword(x) ((x)>=0 && (x)<=65535)
548 #define isbyte(x) ((x)>= -255 && (x)<=255)
549 #define isword(x) ((x)>=-65536 && (x)<=65535)
550 #define islong(x) (1)
552 extern char *input_line_pointer;
554 static char mklower_table[256];
555 #define mklower(c) (mklower_table[(unsigned char)(c)])
556 static char notend_table[256];
557 static char alt_notend_table[256];
559 (! (notend_table[(unsigned char) *s] \
561 && alt_notend_table[(unsigned char) s[1]])))
563 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
565 #ifdef NO_PCREL_RELOCS
568 make_pcrel_absolute(fixP, add_number)
572 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
574 /* rewrite the PC relative instructions to absolute address ones.
575 * these are rumoured to be faster, and the apollo linker refuses
576 * to deal with the PC relative relocations.
578 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
583 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
589 as_fatal ("Unknown PC relative instruction");
594 #endif /* NO_PCREL_RELOCS */
597 tc_coff_fix2rtype (fixP)
600 if (fixP->fx_tcbit && fixP->fx_size == 4)
601 return R_RELLONG_NEG;
602 #ifdef NO_PCREL_RELOCS
603 know (fixP->fx_pcrel == 0);
604 return (fixP->fx_size == 1 ? R_RELBYTE
605 : fixP->fx_size == 2 ? R_DIR16
608 return (fixP->fx_pcrel ?
609 (fixP->fx_size == 1 ? R_PCRBYTE :
610 fixP->fx_size == 2 ? R_PCRWORD :
612 (fixP->fx_size == 1 ? R_RELBYTE :
613 fixP->fx_size == 2 ? R_RELWORD :
622 /* Compute the relocation code for a fixup of SIZE bytes, using pc
623 relative relocation if PCREL is non-zero. PIC says whether a special
624 pic relocation was requested. */
626 static bfd_reloc_code_real_type get_reloc_code
627 PARAMS ((int, int, enum pic_relocation));
629 static bfd_reloc_code_real_type
630 get_reloc_code (size, pcrel, pic)
633 enum pic_relocation pic;
641 return BFD_RELOC_8_GOT_PCREL;
643 return BFD_RELOC_16_GOT_PCREL;
645 return BFD_RELOC_32_GOT_PCREL;
653 return BFD_RELOC_8_GOTOFF;
655 return BFD_RELOC_16_GOTOFF;
657 return BFD_RELOC_32_GOTOFF;
665 return BFD_RELOC_8_PLT_PCREL;
667 return BFD_RELOC_16_PLT_PCREL;
669 return BFD_RELOC_32_PLT_PCREL;
677 return BFD_RELOC_8_PLTOFF;
679 return BFD_RELOC_16_PLTOFF;
681 return BFD_RELOC_32_PLTOFF;
691 return BFD_RELOC_8_PCREL;
693 return BFD_RELOC_16_PCREL;
695 return BFD_RELOC_32_PCREL;
712 as_bad ("Can not do %d byte %s%srelocation", size,
713 pcrel ? "pc-relative " : "",
714 pic == pic_none ? "" : "pic ");
715 return BFD_RELOC_NONE;
718 /* Here we decide which fixups can be adjusted to make them relative
719 to the beginning of the section instead of the symbol. Basically
720 we need to make sure that the dynamic relocations are done
721 correctly, so in some cases we force the original symbol to be
724 tc_m68k_fix_adjustable (fixP)
727 /* Prevent all adjustments to global symbols. */
728 if (S_IS_EXTERNAL (fixP->fx_addsy))
731 /* adjust_reloc_syms doesn't know about the GOT */
732 switch (fixP->fx_r_type)
734 case BFD_RELOC_8_GOT_PCREL:
735 case BFD_RELOC_16_GOT_PCREL:
736 case BFD_RELOC_32_GOT_PCREL:
737 case BFD_RELOC_8_GOTOFF:
738 case BFD_RELOC_16_GOTOFF:
739 case BFD_RELOC_32_GOTOFF:
740 case BFD_RELOC_8_PLT_PCREL:
741 case BFD_RELOC_16_PLT_PCREL:
742 case BFD_RELOC_32_PLT_PCREL:
743 case BFD_RELOC_8_PLTOFF:
744 case BFD_RELOC_16_PLTOFF:
745 case BFD_RELOC_32_PLTOFF:
755 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
762 tc_gen_reloc (section, fixp)
767 bfd_reloc_code_real_type code;
772 if (fixp->fx_r_type != BFD_RELOC_NONE)
774 code = fixp->fx_r_type;
776 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
777 that fixup_segment converted a non-PC relative reloc into a
778 PC relative reloc. In such a case, we need to convert the
785 code = BFD_RELOC_8_PCREL;
788 code = BFD_RELOC_16_PCREL;
791 code = BFD_RELOC_32_PCREL;
793 case BFD_RELOC_8_PCREL:
794 case BFD_RELOC_16_PCREL:
795 case BFD_RELOC_32_PCREL:
796 case BFD_RELOC_8_GOT_PCREL:
797 case BFD_RELOC_16_GOT_PCREL:
798 case BFD_RELOC_32_GOT_PCREL:
799 case BFD_RELOC_8_GOTOFF:
800 case BFD_RELOC_16_GOTOFF:
801 case BFD_RELOC_32_GOTOFF:
802 case BFD_RELOC_8_PLT_PCREL:
803 case BFD_RELOC_16_PLT_PCREL:
804 case BFD_RELOC_32_PLT_PCREL:
805 case BFD_RELOC_8_PLTOFF:
806 case BFD_RELOC_16_PLTOFF:
807 case BFD_RELOC_32_PLTOFF:
810 as_bad_where (fixp->fx_file, fixp->fx_line,
811 "Cannot make %s relocation PC relative",
812 bfd_get_reloc_code_name (code));
818 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
819 switch (F (fixp->fx_size, fixp->fx_pcrel))
821 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
822 MAP (1, 0, BFD_RELOC_8);
823 MAP (2, 0, BFD_RELOC_16);
824 MAP (4, 0, BFD_RELOC_32);
825 MAP (1, 1, BFD_RELOC_8_PCREL);
826 MAP (2, 1, BFD_RELOC_16_PCREL);
827 MAP (4, 1, BFD_RELOC_32_PCREL);
835 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
837 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
838 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
841 reloc->addend = fixp->fx_addnumber;
846 reloc->addend = fixp->fx_addnumber;
848 reloc->addend = (section->vma
849 + (fixp->fx_pcrel_adjust == 64
850 ? -1 : fixp->fx_pcrel_adjust)
852 + md_pcrel_from (fixp));
855 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
856 assert (reloc->howto != 0);
861 #endif /* BFD_ASSEMBLER */
863 /* Handle of the OPCODE hash table. NULL means any use before
864 m68k_ip_begin() will crash. */
865 static struct hash_control *op_hash;
867 /* Assemble an m68k instruction. */
874 register struct m68k_op *opP;
875 register struct m68k_incant *opcode;
876 register const char *s;
877 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
878 char *pdot, *pdotmove;
879 enum m68k_size siz1, siz2;
883 char *crack_operand ();
884 LITTLENUM_TYPE words[6];
885 LITTLENUM_TYPE *wordp;
886 unsigned long ok_arch = 0;
888 if (*instring == ' ')
889 instring++; /* skip leading whitespace */
891 /* Scan up to end of operation-code, which MUST end in end-of-string
892 or exactly 1 space. */
894 for (p = instring; *p != '\0'; p++)
904 the_ins.error = "No operator";
908 /* p now points to the end of the opcode name, probably whitespace.
909 Make sure the name is null terminated by clobbering the
910 whitespace, look it up in the hash table, then fix it back.
911 Remove a dot, first, since the opcode tables have none. */
914 for (pdotmove = pdot; pdotmove < p; pdotmove++)
915 *pdotmove = pdotmove[1];
921 opcode = (struct m68k_incant *) hash_find (op_hash, instring);
926 for (pdotmove = p; pdotmove > pdot; pdotmove--)
927 *pdotmove = pdotmove[-1];
934 the_ins.error = "Unknown operator";
938 /* found a legitimate opcode, start matching operands */
942 if (opcode->m_operands == 0)
944 char *old = input_line_pointer;
946 input_line_pointer = p;
947 /* Ahh - it's a motorola style psuedo op */
948 mote_pseudo_table[opcode->m_opnum].poc_handler
949 (mote_pseudo_table[opcode->m_opnum].poc_val);
950 input_line_pointer = old;
956 if (flag_mri && opcode->m_opnum == 0)
958 /* In MRI mode, random garbage is allowed after an instruction
959 which accepts no operands. */
960 the_ins.args = opcode->m_operands;
961 the_ins.numargs = opcode->m_opnum;
962 the_ins.numo = opcode->m_codenum;
963 the_ins.opcode[0] = getone (opcode);
964 the_ins.opcode[1] = gettwo (opcode);
968 for (opP = &the_ins.operands[0]; *p; opP++)
970 p = crack_operand (p, opP);
974 the_ins.error = opP->error;
979 opsfound = opP - &the_ins.operands[0];
981 /* This ugly hack is to support the floating pt opcodes in their
982 standard form. Essentially, we fake a first enty of type COP#1 */
983 if (opcode->m_operands[0] == 'I')
987 for (n = opsfound; n > 0; --n)
988 the_ins.operands[n] = the_ins.operands[n - 1];
990 memset ((char *) (&the_ins.operands[0]), '\0',
991 sizeof (the_ins.operands[0]));
992 the_ins.operands[0].mode = CONTROL;
993 the_ins.operands[0].reg = m68k_float_copnum;
997 /* We've got the operands. Find an opcode that'll accept them */
1000 /* If we didn't get the right number of ops, or we have no
1001 common model with this pattern then reject this pattern. */
1003 ok_arch |= opcode->m_arch;
1004 if (opsfound != opcode->m_opnum
1005 || ((opcode->m_arch & current_architecture) == 0))
1009 for (s = opcode->m_operands, opP = &the_ins.operands[0];
1013 /* Warning: this switch is huge! */
1014 /* I've tried to organize the cases into this order:
1015 non-alpha first, then alpha by letter. Lower-case
1016 goes directly before uppercase counterpart. */
1017 /* Code with multiple case ...: gets sorted by the lowest
1018 case ... it belongs to. I hope this makes sense. */
1148 if (opP->mode != IMMED)
1150 else if (s[1] == 'b'
1151 && ! isvar (&opP->disp)
1152 && (opP->disp.exp.X_op != O_constant
1153 || ! isbyte (opP->disp.exp.X_add_number)))
1155 else if (s[1] == 'w'
1156 && ! isvar (&opP->disp)
1157 && (opP->disp.exp.X_op != O_constant
1158 || ! isword (opP->disp.exp.X_add_number)))
1160 else if (s[1] == 'W'
1161 && ! isvar (&opP->disp)
1162 && (opP->disp.exp.X_op != O_constant
1163 || ! issword (opP->disp.exp.X_add_number)))
1169 if (opP->mode != IMMED)
1174 if (opP->mode == AREG
1175 || opP->mode == CONTROL
1176 || opP->mode == FPREG
1177 || opP->mode == IMMED
1178 || opP->mode == REGLST
1179 || (opP->mode != ABSL
1181 || opP->reg == ZPC)))
1186 if (opP->mode == CONTROL
1187 || opP->mode == FPREG
1188 || opP->mode == REGLST
1189 || opP->mode == IMMED
1190 || (opP->mode != ABSL
1192 || opP->reg == ZPC)))
1220 if (opP->mode == CONTROL
1221 || opP->mode == FPREG
1222 || opP->mode == REGLST)
1227 if (opP->mode != AINC)
1232 if (opP->mode != ADEC)
1282 if (opP->reg == PC || opP->reg == ZPC)
1303 case '~': /* For now! (JF FOO is this right?) */
1325 if (opP->mode != CONTROL
1326 || (opP->reg != TT0 && opP->reg != TT1))
1331 if (opP->mode != AREG)
1336 if (opP->mode != AINDR)
1341 if (opP->mode != ABSL
1343 && strncmp (instring, "jbsr", 4) == 0))
1348 if (opP->mode != CONTROL || opP->reg != CCR)
1353 if (opP->mode != DISP
1355 || opP->reg > ADDR7)
1360 if (opP->mode != DREG)
1365 if (opP->mode != FPREG)
1370 if (opP->mode != CONTROL
1377 if (opP->mode != CONTROL
1379 || opP->reg > last_movec_reg)
1383 const enum m68k_register *rp;
1384 for (rp = control_regs; *rp; rp++)
1385 if (*rp == opP->reg)
1393 if (opP->mode != IMMED)
1399 if (opP->mode == DREG
1400 || opP->mode == AREG
1401 || opP->mode == FPREG)
1410 opP->mask = 1 << (opP->reg - DATA0);
1413 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1416 opP->mask = 1 << (opP->reg - FP0 + 16);
1424 else if (opP->mode == CONTROL)
1433 opP->mask = 1 << 24;
1436 opP->mask = 1 << 25;
1439 opP->mask = 1 << 26;
1448 else if (opP->mode == ABSL
1449 && opP->disp.size == SIZE_UNSPEC
1450 && opP->disp.exp.X_op == O_constant)
1452 /* This is what the MRI REG pseudo-op generates. */
1454 opP->mask = opP->disp.exp.X_add_number;
1456 else if (opP->mode != REGLST)
1458 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1460 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1465 if (opP->mode != IMMED)
1467 else if (opP->disp.exp.X_op != O_constant
1468 || ! issbyte (opP->disp.exp.X_add_number))
1470 else if (! m68k_quick
1471 && instring[3] != 'q'
1472 && instring[4] != 'q')
1477 if (opP->mode != DREG
1478 && opP->mode != IMMED
1479 && opP->mode != ABSL)
1484 if (opP->mode != IMMED)
1486 else if (opP->disp.exp.X_op != O_constant
1487 || opP->disp.exp.X_add_number < 1
1488 || opP->disp.exp.X_add_number > 8)
1490 else if (! m68k_quick
1491 && (strncmp (instring, "add", 3) == 0
1492 || strncmp (instring, "sub", 3) == 0)
1493 && instring[3] != 'q')
1498 if (opP->mode != DREG && opP->mode != AREG)
1503 if (opP->mode != AINDR
1504 && (opP->mode != BASE
1506 && opP->reg != ZADDR0)
1507 || opP->disp.exp.X_op != O_absent
1508 || ((opP->index.reg < DATA0
1509 || opP->index.reg > DATA7)
1510 && (opP->index.reg < ADDR0
1511 || opP->index.reg > ADDR7))
1512 || opP->index.size != SIZE_UNSPEC
1513 || opP->index.scale != 1))
1518 if (opP->mode != CONTROL
1519 || ! (opP->reg == FPI
1521 || opP->reg == FPC))
1526 if (opP->mode != CONTROL || opP->reg != SR)
1531 if (opP->mode != IMMED)
1533 else if (opP->disp.exp.X_op != O_constant
1534 || opP->disp.exp.X_add_number < 0
1535 || opP->disp.exp.X_add_number > 7)
1540 if (opP->mode != CONTROL || opP->reg != USP)
1544 /* JF these are out of order. We could put them
1545 in order if we were willing to put up with
1546 bunches of #ifdef m68851s in the code.
1548 Don't forget that you need these operands
1549 to use 68030 MMU instructions. */
1551 /* Memory addressing mode used by pflushr */
1553 if (opP->mode == CONTROL
1554 || opP->mode == FPREG
1555 || opP->mode == DREG
1556 || opP->mode == AREG
1557 || opP->mode == REGLST)
1559 /* We should accept immediate operands, but they
1560 supposedly have to be quad word, and we don't
1561 handle that. I would like to see what a Motorola
1562 assembler does before doing something here. */
1563 if (opP->mode == IMMED)
1568 if (opP->mode != CONTROL
1569 || (opP->reg != SFC && opP->reg != DFC))
1574 if (opP->mode != CONTROL || opP->reg != TC)
1579 if (opP->mode != CONTROL || opP->reg != AC)
1584 if (opP->mode != CONTROL
1587 && opP->reg != SCC))
1592 if (opP->mode != CONTROL
1598 if (opP->mode != CONTROL
1601 && opP->reg != CRP))
1606 if (opP->mode != CONTROL
1607 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1608 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1613 if (opP->mode != CONTROL || opP->reg != PSR)
1618 if (opP->mode != CONTROL || opP->reg != PCSR)
1623 if (opP->mode != CONTROL
1630 } /* not a cache specifier. */
1634 if (opP->mode != ABSL)
1640 } /* switch on type of operand */
1644 } /* for each operand */
1645 } /* if immediately wrong */
1652 opcode = opcode->m_next;
1657 && !(ok_arch & current_architecture))
1662 "invalid instruction for this architecture; needs ");
1663 cp = buf + strlen (buf);
1667 strcpy (cp, "fpu (68040, 68060 or 68881/68882)");
1670 strcpy (cp, "mmu (68030 or 68851)");
1673 strcpy (cp, "68020 or higher");
1676 strcpy (cp, "68000 or higher");
1679 strcpy (cp, "68010 or higher");
1683 int got_one = 0, idx;
1684 for (idx = 0; idx < sizeof (archs) / sizeof (archs[0]);
1687 if ((archs[idx].arch & ok_arch)
1688 && ! archs[idx].alias)
1692 strcpy (cp, " or ");
1696 strcpy (cp, archs[idx].name);
1702 cp = xmalloc (strlen (buf) + 1);
1707 the_ins.error = "operands mismatch";
1709 } /* Fell off the end */
1714 /* now assemble it */
1716 the_ins.args = opcode->m_operands;
1717 the_ins.numargs = opcode->m_opnum;
1718 the_ins.numo = opcode->m_codenum;
1719 the_ins.opcode[0] = getone (opcode);
1720 the_ins.opcode[1] = gettwo (opcode);
1722 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
1724 /* This switch is a doozy.
1725 Watch the first step; its a big one! */
1752 tmpreg = 0x3c; /* 7.4 */
1753 if (strchr ("bwl", s[1]))
1754 nextword = get_num (&opP->disp, 80);
1756 nextword = get_num (&opP->disp, 0);
1757 if (isvar (&opP->disp))
1758 add_fix (s[1], &opP->disp, 0, 0);
1762 if (!isbyte (nextword))
1763 opP->error = "operand out of range";
1768 if (!isword (nextword))
1769 opP->error = "operand out of range";
1774 if (!issword (nextword))
1775 opP->error = "operand out of range";
1780 addword (nextword >> 16);
1807 /* We gotta put out some float */
1808 if (op (&opP->disp) != O_big)
1813 /* Can other cases happen here? */
1814 if (op (&opP->disp) != O_constant)
1817 val = (valueT) offs (&opP->disp);
1821 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
1822 val >>= LITTLENUM_NUMBER_OF_BITS;
1826 offs (&opP->disp) = gencnt;
1828 if (offs (&opP->disp) > 0)
1830 if (offs (&opP->disp) > baseo)
1832 as_warn ("Bignum too big for %c format; truncated",
1834 offs (&opP->disp) = baseo;
1836 baseo -= offs (&opP->disp);
1839 for (wordp = generic_bignum + offs (&opP->disp) - 1;
1840 offs (&opP->disp)--;
1845 gen_to_words (words, baseo, (long) outro);
1846 for (wordp = words; baseo--; wordp++)
1850 tmpreg = opP->reg - DATA; /* 0.dreg */
1853 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
1856 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
1859 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
1862 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
1866 nextword = get_num (&opP->disp, 80);
1869 && ! isvar (&opP->disp)
1872 opP->disp.exp.X_op = O_symbol;
1873 #ifndef BFD_ASSEMBLER
1874 opP->disp.exp.X_add_symbol = &abs_symbol;
1876 opP->disp.exp.X_add_symbol =
1877 section_symbol (absolute_section);
1881 /* Force into index mode. Hope this works */
1883 /* We do the first bit for 32-bit displacements, and the
1884 second bit for 16 bit ones. It is possible that we
1885 should make the default be WORD instead of LONG, but
1886 I think that'd break GCC, so we put up with a little
1887 inefficiency for the sake of working output. */
1889 if (!issword (nextword)
1890 || (isvar (&opP->disp)
1891 && ((opP->disp.size == SIZE_UNSPEC
1892 && flag_short_refs == 0
1893 && cpu_of_arch (current_architecture) >= m68020)
1894 || opP->disp.size == SIZE_LONG)))
1896 if (cpu_of_arch (current_architecture) < m68020)
1898 "displacement too large for this architecture; needs 68020 or higher";
1900 tmpreg = 0x3B; /* 7.3 */
1902 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
1903 if (isvar (&opP->disp))
1907 if (opP->disp.size == SIZE_LONG
1909 /* If the displacement needs pic
1910 relocation it cannot be relaxed. */
1911 || opP->disp.pic_reloc != pic_none
1916 add_fix ('l', &opP->disp, 1, 2);
1920 add_frag (adds (&opP->disp),
1922 TAB (PCLEA, SZ_UNDEF));
1929 add_fix ('l', &opP->disp, 0, 0);
1934 addword (nextword >> 16);
1939 tmpreg = 0x3A; /* 7.2 */
1941 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
1943 if (isvar (&opP->disp))
1947 add_fix ('w', &opP->disp, 1, 0);
1950 add_fix ('w', &opP->disp, 0, 0);
1960 baseo = get_num (&opP->disp, 80);
1961 if (opP->mode == POST || opP->mode == PRE)
1962 outro = get_num (&opP->odisp, 80);
1963 /* Figure out the `addressing mode'.
1964 Also turn on the BASE_DISABLE bit, if needed. */
1965 if (opP->reg == PC || opP->reg == ZPC)
1967 tmpreg = 0x3b; /* 7.3 */
1968 if (opP->reg == ZPC)
1971 else if (opP->reg == 0)
1974 tmpreg = 0x30; /* 6.garbage */
1976 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
1979 tmpreg = 0x30 + opP->reg - ZADDR0;
1982 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
1984 siz1 = opP->disp.size;
1985 if (opP->mode == POST || opP->mode == PRE)
1986 siz2 = opP->odisp.size;
1990 /* Index register stuff */
1991 if (opP->index.reg != 0
1992 && opP->index.reg >= DATA
1993 && opP->index.reg <= ADDR7)
1995 nextword |= (opP->index.reg - DATA) << 12;
1997 if (opP->index.size == SIZE_LONG
1998 || (opP->index.size == SIZE_UNSPEC
1999 && m68k_index_width_default == SIZE_LONG))
2002 if ((opP->index.scale != 1
2003 && cpu_of_arch (current_architecture) < m68020)
2004 || (opP->index.scale == 8
2005 && current_architecture == mcf5200))
2008 "scale factor invalid on this architecture; needs cpu32 or 68020 or higher";
2011 switch (opP->index.scale)
2028 GET US OUT OF HERE! */
2030 /* Must be INDEX, with an index register. Address
2031 register cannot be ZERO-PC, and either :b was
2032 forced, or we know it will fit. For a 68000 or
2033 68010, force this mode anyways, because the
2034 larger modes aren't supported. */
2035 if (opP->mode == BASE
2036 && ((opP->reg >= ADDR0
2037 && opP->reg <= ADDR7)
2040 if (siz1 == SIZE_BYTE
2041 || cpu_of_arch (current_architecture) < m68020
2042 || (siz1 == SIZE_UNSPEC
2043 && ! isvar (&opP->disp)
2044 && issbyte (baseo)))
2046 nextword += baseo & 0xff;
2048 if (isvar (&opP->disp))
2050 /* Do a byte relocation. If it doesn't
2051 fit (possible on m68000) let the
2052 fixup processing complain later. */
2054 add_fix ('B', &opP->disp, 1, 1);
2056 add_fix ('B', &opP->disp, 0, 0);
2058 else if (siz1 != SIZE_BYTE)
2060 if (siz1 != SIZE_UNSPEC)
2061 as_warn ("Forcing byte displacement");
2062 if (! issbyte (baseo))
2063 opP->error = "byte displacement out of range";
2068 else if (siz1 == SIZE_UNSPEC
2070 && isvar (&opP->disp)
2071 && subs (&opP->disp) == NULL
2073 /* If the displacement needs pic
2074 relocation it cannot be relaxed. */
2075 && opP->disp.pic_reloc == pic_none
2079 nextword += baseo & 0xff;
2081 add_frag (adds (&opP->disp), offs (&opP->disp),
2082 TAB (PCINDEX, SZ_UNDEF));
2090 nextword |= 0x40; /* No index reg */
2091 if (opP->index.reg >= ZDATA0
2092 && opP->index.reg <= ZDATA7)
2093 nextword |= (opP->index.reg - ZDATA0) << 12;
2094 else if (opP->index.reg >= ZADDR0
2095 || opP->index.reg <= ZADDR7)
2096 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2099 /* It isn't simple. */
2101 if (cpu_of_arch (current_architecture) < m68020)
2103 "invalid operand mode for this architecture; needs 68020 or higher";
2106 /* If the guy specified a width, we assume that it is
2107 wide enough. Maybe it isn't. If so, we lose. */
2111 if (isvar (&opP->disp)
2113 : ! issword (baseo))
2118 else if (! isvar (&opP->disp) && baseo == 0)
2127 as_warn (":b not permitted; defaulting to :w");
2137 /* Figure out innner displacement stuff */
2138 if (opP->mode == POST || opP->mode == PRE)
2140 if (cpu_of_arch (current_architecture) & cpu32)
2141 opP->error = "invalid operand mode for this architecture; needs 68020 or higher";
2145 if (isvar (&opP->odisp)
2147 : ! issword (outro))
2152 else if (! isvar (&opP->odisp) && outro == 0)
2161 as_warn (":b not permitted; defaulting to :w");
2170 if (opP->mode == POST
2171 && (nextword & 0x40) == 0)
2176 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2178 if (opP->reg == PC || opP->reg == ZPC)
2179 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2181 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2183 if (siz1 == SIZE_LONG)
2184 addword (baseo >> 16);
2185 if (siz1 != SIZE_UNSPEC)
2188 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2189 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2190 if (siz2 == SIZE_LONG)
2191 addword (outro >> 16);
2192 if (siz2 != SIZE_UNSPEC)
2198 nextword = get_num (&opP->disp, 80);
2199 switch (opP->disp.size)
2204 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2206 tmpreg = 0x38; /* 7.0 */
2210 /* Don't generate pc relative code on 68010 and
2212 if (isvar (&opP->disp)
2213 && !subs (&opP->disp)
2214 && adds (&opP->disp)
2216 /* If the displacement needs pic relocation it
2217 cannot be relaxed. */
2218 && opP->disp.pic_reloc == pic_none
2220 && S_GET_SEGMENT (adds (&opP->disp)) == now_seg
2221 && cpu_of_arch (current_architecture) >= m68020
2223 && !strchr ("~%&$?", s[0]))
2225 tmpreg = 0x3A; /* 7.2 */
2226 add_frag (adds (&opP->disp),
2228 TAB (PCREL, SZ_UNDEF));
2231 /* Fall through into long */
2233 if (isvar (&opP->disp))
2234 add_fix ('l', &opP->disp, 0, 0);
2236 tmpreg = 0x39;/* 7.1 mode */
2237 addword (nextword >> 16);
2241 case SIZE_WORD: /* Word */
2242 if (isvar (&opP->disp))
2243 add_fix ('w', &opP->disp, 0, 0);
2245 tmpreg = 0x38;/* 7.0 mode */
2253 as_bad ("unknown/incorrect operand");
2256 install_gen_operand (s[1], tmpreg);
2262 { /* JF: I hate floating point! */
2277 tmpreg = get_num (&opP->disp, tmpreg);
2278 if (isvar (&opP->disp))
2279 add_fix (s[1], &opP->disp, 0, 0);
2282 case 'b': /* Danger: These do no check for
2283 certain types of overflow.
2285 if (!isbyte (tmpreg))
2286 opP->error = "out of range";
2287 insop (tmpreg, opcode);
2288 if (isvar (&opP->disp))
2289 the_ins.reloc[the_ins.nrel - 1].n =
2290 (opcode->m_codenum) * 2 + 1;
2293 if (!isword (tmpreg))
2294 opP->error = "out of range";
2295 insop (tmpreg, opcode);
2296 if (isvar (&opP->disp))
2297 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2300 if (!issword (tmpreg))
2301 opP->error = "out of range";
2302 insop (tmpreg, opcode);
2303 if (isvar (&opP->disp))
2304 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2307 /* Because of the way insop works, we put these two out
2309 insop (tmpreg, opcode);
2310 insop (tmpreg >> 16, opcode);
2311 if (isvar (&opP->disp))
2312 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2318 install_operand (s[1], tmpreg);
2329 install_operand (s[1], opP->reg - ADDR);
2333 tmpreg = get_num (&opP->disp, 80);
2337 /* The pc_fix argument winds up in fx_pcrel_adjust,
2338 which is a char, and may therefore be unsigned. We
2339 want to pass -1, but we pass 64 instead, and convert
2340 back in md_pcrel_from. */
2341 add_fix ('B', &opP->disp, 1, 64);
2344 add_fix ('w', &opP->disp, 1, 0);
2349 if (cpu_of_arch (current_architecture) < m68020)
2350 as_warn ("Can't use long branches on 68000/68010");
2351 the_ins.opcode[the_ins.numo - 1] |= 0xff;
2352 add_fix ('l', &opP->disp, 1, 0);
2357 if (subs (&opP->disp)) /* We can't relax it */
2361 /* If the displacement needs pic relocation it cannot be
2363 if (opP->disp.pic_reloc != pic_none)
2367 /* This could either be a symbol, or an absolute
2368 address. No matter, the frag hacking will finger it
2369 out. Not quite: it can't switch from BRANCH to
2370 BCC68000 for the case where opnd is absolute (it
2371 needs to use the 68000 hack since no conditional abs
2373 if (((cpu_of_arch (current_architecture) < m68020)
2374 || (0 == adds (&opP->disp)))
2375 && (the_ins.opcode[0] >= 0x6200)
2376 && (the_ins.opcode[0] <= 0x6f00))
2377 add_frag (adds (&opP->disp), offs (&opP->disp),
2378 TAB (BCC68000, SZ_UNDEF));
2380 add_frag (adds (&opP->disp), offs (&opP->disp),
2381 TAB (ABRANCH, SZ_UNDEF));
2384 if (isvar (&opP->disp))
2387 /* check for DBcc instruction */
2388 if ((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2390 /* size varies if patch */
2391 /* needed for long form */
2392 add_frag (adds (&opP->disp), offs (&opP->disp),
2393 TAB (DBCC, SZ_UNDEF));
2397 add_fix ('w', &opP->disp, 1, 0);
2401 case 'C': /* Fixed size LONG coproc branches */
2402 add_fix ('l', &opP->disp, 1, 0);
2406 case 'c': /* Var size Coprocesssor branches */
2407 if (subs (&opP->disp))
2409 add_fix ('l', &opP->disp, 1, 0);
2410 add_frag ((symbolS *) 0, (long) 0, TAB (FBRANCH, LONG));
2412 else if (adds (&opP->disp))
2413 add_frag (adds (&opP->disp), offs (&opP->disp),
2414 TAB (FBRANCH, SZ_UNDEF));
2417 /* add_frag((symbolS *) 0, offs(&opP->disp),
2418 TAB(FBRANCH,SHORT)); */
2419 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2420 add_fix ('l', &opP->disp, 1, 0);
2430 case 'C': /* Ignore it */
2433 case 'd': /* JF this is a kludge */
2434 install_operand ('s', opP->reg - ADDR);
2435 tmpreg = get_num (&opP->disp, 80);
2436 if (!issword (tmpreg))
2438 as_warn ("Expression out of range, using 0");
2445 install_operand (s[1], opP->reg - DATA);
2449 install_operand (s[1], opP->reg - FP0);
2453 tmpreg = opP->reg - COP0;
2454 install_operand (s[1], tmpreg);
2457 case 'J': /* JF foo */
2530 install_operand (s[1], tmpreg);
2534 tmpreg = get_num (&opP->disp, 55);
2535 install_operand (s[1], tmpreg & 0x7f);
2542 if (tmpreg & 0x7FF0000)
2543 as_bad ("Floating point register in register list");
2544 insop (reverse_16_bits (tmpreg), opcode);
2548 if (tmpreg & 0x700FFFF)
2549 as_bad ("Wrong register in floating-point reglist");
2550 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
2558 if (tmpreg & 0x7FF0000)
2559 as_bad ("Floating point register in register list");
2560 insop (tmpreg, opcode);
2562 else if (s[1] == '8')
2564 if (tmpreg & 0x0FFFFFF)
2565 as_bad ("incorrect register in reglist");
2566 install_operand (s[1], tmpreg >> 24);
2570 if (tmpreg & 0x700FFFF)
2571 as_bad ("wrong register in floating-point reglist");
2573 install_operand (s[1], tmpreg >> 16);
2578 install_operand (s[1], get_num (&opP->disp, 60));
2582 tmpreg = ((opP->mode == DREG)
2583 ? 0x20 + opP->reg - DATA
2584 : (get_num (&opP->disp, 40) & 0x1F));
2585 install_operand (s[1], tmpreg);
2589 tmpreg = get_num (&opP->disp, 10);
2592 install_operand (s[1], tmpreg);
2596 /* This depends on the fact that ADDR registers are eight
2597 more than their corresponding DATA regs, so the result
2598 will have the ADDR_REG bit set */
2599 install_operand (s[1], opP->reg - DATA);
2603 if (opP->mode == AINDR)
2604 install_operand (s[1], opP->reg - DATA);
2606 install_operand (s[1], opP->index.reg - DATA);
2610 if (opP->reg == FPI)
2612 else if (opP->reg == FPS)
2614 else if (opP->reg == FPC)
2618 install_operand (s[1], tmpreg);
2621 case 'S': /* Ignore it */
2625 install_operand (s[1], get_num (&opP->disp, 30));
2628 case 'U': /* Ignore it */
2647 as_fatal ("failed sanity check");
2648 } /* switch on cache token */
2649 install_operand (s[1], tmpreg);
2652 /* JF: These are out of order, I fear. */
2665 install_operand (s[1], tmpreg);
2691 install_operand (s[1], tmpreg);
2695 if (opP->reg == VAL)
2714 install_operand (s[1], tmpreg);
2728 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2739 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2745 install_operand (s[1], tmpreg);
2748 know (opP->reg == PSR);
2751 know (opP->reg == PCSR);
2766 install_operand (s[1], tmpreg);
2769 tmpreg = get_num (&opP->disp, 20);
2770 install_operand (s[1], tmpreg);
2772 case '_': /* used only for move16 absolute 32-bit address */
2773 tmpreg = get_num (&opP->disp, 80);
2774 addword (tmpreg >> 16);
2775 addword (tmpreg & 0xFFFF);
2782 /* By the time whe get here (FINALLY) the_ins contains the complete
2783 instruction, ready to be emitted. . . */
2787 reverse_16_bits (in)
2793 static int mask[16] =
2795 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2796 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2798 for (n = 0; n < 16; n++)
2801 out |= mask[15 - n];
2804 } /* reverse_16_bits() */
2813 static int mask[8] =
2815 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2818 for (n = 0; n < 8; n++)
2824 } /* reverse_8_bits() */
2826 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2827 (that value is chosen in the frag_var call in md_assemble). TYPE
2828 is the subtype of the frag to be generated; its primary type is
2829 rs_machine_dependent.
2831 The TYPE parameter is also used by md_convert_frag_1 and
2832 md_estimate_size_before_relax. The appropriate type of fixup will
2833 be emitted by md_convert_frag_1.
2835 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2837 install_operand (mode, val)
2844 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge */
2847 the_ins.opcode[0] |= val << 9;
2850 the_ins.opcode[1] |= val << 12;
2853 the_ins.opcode[1] |= val << 6;
2856 the_ins.opcode[1] |= val;
2859 the_ins.opcode[2] |= val << 12;
2862 the_ins.opcode[2] |= val << 6;
2865 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2866 three words long! */
2868 the_ins.opcode[2] |= val;
2871 the_ins.opcode[1] |= val << 7;
2874 the_ins.opcode[1] |= val << 10;
2878 the_ins.opcode[1] |= val << 5;
2883 the_ins.opcode[1] |= (val << 10) | (val << 7);
2886 the_ins.opcode[1] |= (val << 12) | val;
2889 the_ins.opcode[0] |= val = 0xff;
2892 the_ins.opcode[0] |= val << 9;
2895 the_ins.opcode[1] |= val;
2898 the_ins.opcode[1] |= val;
2899 the_ins.numo++; /* What a hack */
2902 the_ins.opcode[1] |= val << 4;
2910 the_ins.opcode[0] |= (val << 6);
2913 the_ins.opcode[1] = (val >> 16);
2914 the_ins.opcode[2] = val & 0xffff;
2918 as_fatal ("failed sanity check.");
2920 } /* install_operand() */
2923 install_gen_operand (mode, val)
2930 the_ins.opcode[0] |= val;
2933 /* This is a kludge!!! */
2934 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
2943 the_ins.opcode[0] |= val;
2945 /* more stuff goes here */
2947 as_fatal ("failed sanity check.");
2949 } /* install_gen_operand() */
2952 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2953 * then deal with the bitfield hack.
2957 crack_operand (str, opP)
2959 register struct m68k_op *opP;
2961 register int parens;
2963 register char *beg_str;
2971 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
2977 else if (*str == ')')
2981 opP->error = "Extra )";
2987 if (flag_mri && *str == '\'')
2988 inquote = ! inquote;
2990 if (!*str && parens)
2992 opP->error = "Missing )";
2997 if (m68k_ip_op (beg_str, opP) != 0)
3004 c = *++str; /* JF bitfield hack */
3009 as_bad ("Missing operand");
3014 /* This is the guts of the machine-dependent assembler. STR points to a
3015 machine dependent instruction. This function is supposed to emit
3016 the frags/bytes it assembles to.
3020 insert_reg (regname, regnum)
3027 #ifdef REGISTER_PREFIX
3028 if (!flag_reg_prefix_optional)
3030 buf[0] = REGISTER_PREFIX;
3031 strcpy (buf + 1, regname);
3036 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3037 &zero_address_frag));
3039 for (i = 0; regname[i]; i++)
3040 buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
3043 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3044 &zero_address_frag));
3053 static const struct init_entry init_table[] =
3108 /* control registers */
3109 { "sfc", SFC }, /* Source Function Code */
3111 { "dfc", DFC }, /* Destination Function Code */
3113 { "cacr", CACR }, /* Cache Control Register */
3114 { "caar", CAAR }, /* Cache Address Register */
3116 { "usp", USP }, /* User Stack Pointer */
3117 { "vbr", VBR }, /* Vector Base Register */
3118 { "msp", MSP }, /* Master Stack Pointer */
3119 { "isp", ISP }, /* Interrupt Stack Pointer */
3121 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0 */
3122 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1 */
3123 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0 */
3124 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1 */
3126 /* 68ec040 versions of same */
3127 { "iacr0", ITT0 }, /* Instruction Access Control Register 0 */
3128 { "iacr1", ITT1 }, /* Instruction Access Control Register 0 */
3129 { "dacr0", DTT0 }, /* Data Access Control Register 0 */
3130 { "dacr1", DTT1 }, /* Data Access Control Register 0 */
3132 /* mcf5200 versions of same. The ColdFire programmer's reference
3133 manual indicated that the order is 2,3,0,1, but Ken Rose
3134 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3135 { "acr0", ITT0 }, /* Access Control Unit 0 */
3136 { "acr1", ITT1 }, /* Access Control Unit 1 */
3137 { "acr2", DTT0 }, /* Access Control Unit 2 */
3138 { "acr3", DTT1 }, /* Access Control Unit 3 */
3140 { "tc", TC }, /* MMU Translation Control Register */
3143 { "mmusr", MMUSR }, /* MMU Status Register */
3144 { "srp", SRP }, /* User Root Pointer */
3145 { "urp", URP }, /* Supervisor Root Pointer */
3150 { "rombar", ROMBAR }, /* ROM Base Address Register */
3151 { "rambar0", RAMBAR0 }, /* ROM Base Address Register */
3152 { "rambar1", RAMBAR1 }, /* ROM Base Address Register */
3153 { "mbar", MBAR }, /* Module Base Address Register */
3154 /* end of control registers */
3188 /* 68ec030 versions of same */
3191 /* 68ec030 access control unit, identical to 030 MMU status reg */
3194 /* Suppressed data and address registers. */
3219 for (i = 0; init_table[i].name; i++)
3220 insert_reg (init_table[i].name, init_table[i].number);
3223 static int no_68851, no_68881;
3226 /* a.out machine type. Default to 68020. */
3227 int m68k_aout_machtype = 2;
3239 int shorts_this_frag;
3242 /* In MRI mode, the instruction and operands are separated by a
3243 space. Anything following the operands is a comment. The label
3244 has already been removed. */
3252 for (s = str; *s != '\0'; s++)
3254 if ((*s == ' ' || *s == '\t') && ! inquote)
3272 inquote = ! inquote;
3277 memset ((char *) (&the_ins), '\0', sizeof (the_ins));
3282 for (n = 0; n < the_ins.numargs; n++)
3283 if (the_ins.operands[n].error)
3285 er = the_ins.operands[n].error;
3291 as_bad ("%s -- statement `%s' ignored", er, str);
3295 if (the_ins.nfrag == 0)
3297 /* No frag hacking involved; just put it out */
3298 toP = frag_more (2 * the_ins.numo);
3299 fromP = &the_ins.opcode[0];
3300 for (m = the_ins.numo; m; --m)
3302 md_number_to_chars (toP, (long) (*fromP), 2);
3306 /* put out symbol-dependent info */
3307 for (m = 0; m < the_ins.nrel; m++)
3309 switch (the_ins.reloc[m].wid)
3327 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3328 the_ins.reloc[m].wid);
3331 fixP = fix_new_exp (frag_now,
3332 ((toP - frag_now->fr_literal)
3333 - the_ins.numo * 2 + the_ins.reloc[m].n),
3335 &the_ins.reloc[m].exp,
3336 the_ins.reloc[m].pcrel,
3337 get_reloc_code (n, the_ins.reloc[m].pcrel,
3338 the_ins.reloc[m].pic_reloc));
3339 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3344 /* There's some frag hacking */
3345 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
3350 wid = 2 * the_ins.fragb[n].fragoff;
3352 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3353 toP = frag_more (wid);
3355 shorts_this_frag = 0;
3356 for (m = wid / 2; m; --m)
3358 md_number_to_chars (toP, (long) (*fromP), 2);
3363 for (m = 0; m < the_ins.nrel; m++)
3365 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
3367 the_ins.reloc[m].n -= 2 * shorts_this_frag;
3370 wid = the_ins.reloc[m].wid;
3373 the_ins.reloc[m].wid = 0;
3374 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3376 fixP = fix_new_exp (frag_now,
3377 ((toP - frag_now->fr_literal)
3378 - the_ins.numo * 2 + the_ins.reloc[m].n),
3380 &the_ins.reloc[m].exp,
3381 the_ins.reloc[m].pcrel,
3382 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3383 the_ins.reloc[m].pic_reloc));
3384 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3386 (void) frag_var (rs_machine_dependent, 10, 0,
3387 (relax_substateT) (the_ins.fragb[n].fragty),
3388 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
3390 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3391 shorts_this_frag = 0;
3394 toP = frag_more (n * sizeof (short));
3397 md_number_to_chars (toP, (long) (*fromP), 2);
3403 for (m = 0; m < the_ins.nrel; m++)
3407 wid = the_ins.reloc[m].wid;
3410 the_ins.reloc[m].wid = 0;
3411 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3413 fixP = fix_new_exp (frag_now,
3414 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
3415 - shorts_this_frag * 2),
3417 &the_ins.reloc[m].exp,
3418 the_ins.reloc[m].pcrel,
3419 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3420 the_ins.reloc[m].pic_reloc));
3421 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3429 * md_begin -- set up hash tables with 68000 instructions.
3430 * similar to what the vax assembler does. ---phr
3432 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3433 a copy of it at runtime, adding in the information we want but isn't
3434 there. I think it'd be better to have an awk script hack the table
3435 at compile time. Or even just xstr the table and use it as-is. But
3436 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3439 register const struct m68k_opcode *ins;
3440 register struct m68k_incant *hack, *slak;
3441 register const char *retval = 0; /* empty string, or error msg text */
3442 register unsigned int i;
3447 flag_reg_prefix_optional = 1;
3449 if (! m68k_rel32_from_cmdline)
3453 op_hash = hash_new ();
3455 obstack_begin (&robyn, 4000);
3456 for (i = 0; i < m68k_numopcodes; i++)
3458 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3461 ins = &m68k_opcodes[i];
3462 /* We *could* ignore insns that don't match our arch here
3463 but just leaving them out of the hash. */
3464 slak->m_operands = ins->args;
3465 slak->m_opnum = strlen (slak->m_operands) / 2;
3466 slak->m_arch = ins->arch;
3467 slak->m_opcode = ins->opcode;
3468 /* This is kludgey */
3469 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
3470 if (i + 1 != m68k_numopcodes
3471 && !strcmp (ins->name, m68k_opcodes[i + 1].name))
3473 slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3478 slak = slak->m_next;
3482 retval = hash_insert (op_hash, ins->name, (char *) hack);
3484 as_fatal ("Internal Error: Can't hash %s: %s", ins->name, retval);
3487 for (i = 0; i < m68k_numaliases; i++)
3489 const char *name = m68k_opcode_aliases[i].primary;
3490 const char *alias = m68k_opcode_aliases[i].alias;
3491 PTR val = hash_find (op_hash, name);
3493 as_fatal ("Internal Error: Can't find %s in hash table", name);
3494 retval = hash_insert (op_hash, alias, val);
3496 as_fatal ("Internal Error: Can't hash %s: %s", alias, retval);
3499 /* In MRI mode, all unsized branches are variable sized. Normally,
3500 they are word sized. */
3503 static struct m68k_opcode_alias mri_aliases[] =
3523 for (i = 0; i < sizeof mri_aliases / sizeof mri_aliases[0]; i++)
3525 const char *name = mri_aliases[i].primary;
3526 const char *alias = mri_aliases[i].alias;
3527 PTR val = hash_find (op_hash, name);
3529 as_fatal ("Internal Error: Can't find %s in hash table", name);
3530 retval = hash_jam (op_hash, alias, val);
3532 as_fatal ("Internal Error: Can't hash %s: %s", alias, retval);
3536 for (i = 0; i < sizeof (mklower_table); i++)
3537 mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
3539 for (i = 0; i < sizeof (notend_table); i++)
3541 notend_table[i] = 0;
3542 alt_notend_table[i] = 0;
3544 notend_table[','] = 1;
3545 notend_table['{'] = 1;
3546 notend_table['}'] = 1;
3547 alt_notend_table['a'] = 1;
3548 alt_notend_table['A'] = 1;
3549 alt_notend_table['d'] = 1;
3550 alt_notend_table['D'] = 1;
3551 alt_notend_table['#'] = 1;
3552 alt_notend_table['&'] = 1;
3553 alt_notend_table['f'] = 1;
3554 alt_notend_table['F'] = 1;
3555 #ifdef REGISTER_PREFIX
3556 alt_notend_table[REGISTER_PREFIX] = 1;
3559 /* We need to put '(' in alt_notend_table to handle
3560 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3562 alt_notend_table['('] = 1;
3564 /* We need to put '@' in alt_notend_table to handle
3565 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3567 alt_notend_table['@'] = 1;
3569 /* We need to put digits in alt_notend_table to handle
3570 bfextu %d0{24:1},%d0
3572 alt_notend_table['0'] = 1;
3573 alt_notend_table['1'] = 1;
3574 alt_notend_table['2'] = 1;
3575 alt_notend_table['3'] = 1;
3576 alt_notend_table['4'] = 1;
3577 alt_notend_table['5'] = 1;
3578 alt_notend_table['6'] = 1;
3579 alt_notend_table['7'] = 1;
3580 alt_notend_table['8'] = 1;
3581 alt_notend_table['9'] = 1;
3583 #ifndef MIT_SYNTAX_ONLY
3584 /* Insert pseudo ops, these have to go into the opcode table since
3585 gas expects pseudo ops to start with a dot */
3588 while (mote_pseudo_table[n].poc_name)
3590 hack = (struct m68k_incant *)
3591 obstack_alloc (&robyn, sizeof (struct m68k_incant));
3592 hash_insert (op_hash,
3593 mote_pseudo_table[n].poc_name, (char *) hack);
3594 hack->m_operands = 0;
3604 record_alignment (text_section, 2);
3605 record_alignment (data_section, 2);
3606 record_alignment (bss_section, 2);
3611 select_control_regs ()
3613 /* Note which set of "movec" control registers is available. */
3614 switch (cpu_of_arch (current_architecture))
3617 control_regs = m68000_control_regs;
3620 control_regs = m68010_control_regs;
3624 control_regs = m68020_control_regs;
3627 control_regs = m68040_control_regs;
3630 control_regs = m68060_control_regs;
3633 control_regs = cpu32_control_regs;
3636 control_regs = mcf5200_control_regs;
3644 m68k_init_after_args ()
3646 if (cpu_of_arch (current_architecture) == 0)
3649 const char *default_cpu = TARGET_CPU;
3651 if (*default_cpu == 'm')
3653 for (i = 0; i < n_archs; i++)
3654 if (strcasecmp (default_cpu, archs[i].name) == 0)
3658 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU);
3659 current_architecture |= m68020;
3662 current_architecture |= archs[i].arch;
3664 /* Permit m68881 specification with all cpus; those that can't work
3665 with a coprocessor could be doing emulation. */
3666 if (current_architecture & m68851)
3668 if (current_architecture & m68040)
3670 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3673 /* What other incompatibilities could we check for? */
3675 /* Toss in some default assumptions about coprocessors. */
3677 && (cpu_of_arch (current_architecture)
3678 /* Can CPU32 have a 68881 coprocessor?? */
3679 & (m68020 | m68030 | cpu32)))
3681 current_architecture |= m68881;
3684 && (cpu_of_arch (current_architecture) & m68020up) != 0
3685 && (cpu_of_arch (current_architecture) & m68040up) == 0)
3687 current_architecture |= m68851;
3689 if (no_68881 && (current_architecture & m68881))
3690 as_bad ("options for 68881 and no-68881 both given");
3691 if (no_68851 && (current_architecture & m68851))
3692 as_bad ("options for 68851 and no-68851 both given");
3695 /* Work out the magic number. This isn't very general. */
3696 if (current_architecture & m68000)
3697 m68k_aout_machtype = 0;
3698 else if (current_architecture & m68010)
3699 m68k_aout_machtype = 1;
3700 else if (current_architecture & m68020)
3701 m68k_aout_machtype = 2;
3703 m68k_aout_machtype = 2;
3706 /* Note which set of "movec" control registers is available. */
3707 select_control_regs ();
3709 if (cpu_of_arch (current_architecture) < m68020)
3710 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
3713 /* This is called if we go in or out of MRI mode because of the .mri
3717 m68k_mri_mode_change (on)
3722 if (! flag_reg_prefix_optional)
3724 flag_reg_prefix_optional = 1;
3725 #ifdef REGISTER_PREFIX
3730 if (! m68k_rel32_from_cmdline)
3735 if (! reg_prefix_optional_seen)
3737 #ifdef REGISTER_PREFIX_OPTIONAL
3738 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
3740 flag_reg_prefix_optional = 0;
3742 #ifdef REGISTER_PREFIX
3747 if (! m68k_rel32_from_cmdline)
3752 /* Equal to MAX_PRECISION in atof-ieee.c */
3753 #define MAX_LITTLENUMS 6
3755 /* Turn a string in input_line_pointer into a floating point constant
3756 of type type, and store the appropriate bytes in *litP. The number
3757 of LITTLENUMS emitted is stored in *sizeP . An error message is
3758 returned, or NULL on OK. */
3761 md_atof (type, litP, sizeP)
3767 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3768 LITTLENUM_TYPE *wordP;
3800 return "Bad call to MD_ATOF()";
3802 t = atof_ieee (input_line_pointer, type, words);
3804 input_line_pointer = t;
3806 *sizeP = prec * sizeof (LITTLENUM_TYPE);
3807 for (wordP = words; prec--;)
3809 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
3810 litP += sizeof (LITTLENUM_TYPE);
3816 md_number_to_chars (buf, val, n)
3821 number_to_chars_bigendian (buf, val, n);
3825 md_apply_fix_2 (fixP, val)
3829 addressT upper_limit;
3830 offsetT lower_limit;
3832 /* This is unnecessary but it convinces the native rs6000 compiler
3833 to generate the code we want. */
3834 char *buf = fixP->fx_frag->fr_literal;
3835 buf += fixP->fx_where;
3836 /* end ibm compiler workaround */
3838 if (val & 0x80000000)
3839 val |= ~(addressT)0x7fffffff;
3846 memset (buf, 0, fixP->fx_size);
3847 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
3852 switch (fixP->fx_size)
3854 /* The cast to offsetT below are necessary to make code correct for
3855 machines where ints are smaller than offsetT */
3859 lower_limit = - (offsetT) 0x80;
3862 *buf++ = (val >> 8);
3864 upper_limit = 0x7fff;
3865 lower_limit = - (offsetT) 0x8000;
3868 *buf++ = (val >> 24);
3869 *buf++ = (val >> 16);
3870 *buf++ = (val >> 8);
3872 upper_limit = 0x7fffffff;
3873 lower_limit = - (offsetT) 0x7fffffff - 1; /* avoid constant overflow */
3876 BAD_CASE (fixP->fx_size);
3879 /* Fix up a negative reloc. */
3880 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
3882 fixP->fx_addsy = fixP->fx_subsy;
3883 fixP->fx_subsy = NULL;
3887 /* For non-pc-relative values, it's conceivable we might get something
3888 like "0xff" for a byte field. So extend the upper part of the range
3889 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3890 so that we can do any range checking at all. */
3891 if (!fixP->fx_pcrel)
3892 upper_limit = upper_limit * 2 + 1;
3894 if ((addressT) val > upper_limit
3895 && (val > 0 || val < lower_limit))
3896 as_bad_where (fixP->fx_file, fixP->fx_line, "value out of range");
3898 /* A one byte PC-relative reloc means a short branch. We can't use
3899 a short branch with a value of 0 or -1, because those indicate
3900 different opcodes (branches with longer offsets). */
3902 && fixP->fx_size == 1
3903 && (fixP->fx_addsy == NULL
3904 || S_IS_DEFINED (fixP->fx_addsy))
3905 && (val == 0 || val == -1))
3906 as_bad_where (fixP->fx_file, fixP->fx_line, "invalid byte branch offset");
3909 #ifdef BFD_ASSEMBLER
3911 md_apply_fix (fixP, valp)
3915 md_apply_fix_2 (fixP, (addressT) *valp);
3919 void md_apply_fix (fixP, val)
3923 md_apply_fix_2 (fixP, (addressT) val);
3927 /* *fragP has been relaxed to its final size, and now needs to have
3928 the bytes inside it modified to conform to the new size There is UGLY
3932 md_convert_frag_1 (fragP)
3933 register fragS *fragP;
3939 /* Address in object code of the displacement. */
3940 register int object_address = fragP->fr_fix + fragP->fr_address;
3942 /* Address in gas core of the place to store the displacement. */
3943 /* This convinces the native rs6000 compiler to generate the code we
3945 register char *buffer_address = fragP->fr_literal;
3946 buffer_address += fragP->fr_fix;
3947 /* end ibm compiler workaround */
3949 /* The displacement of the address, from current location. */
3950 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
3951 disp = (disp + fragP->fr_offset) - object_address;
3953 #ifdef BFD_ASSEMBLER
3954 disp += fragP->fr_symbol->sy_frag->fr_address;
3957 switch (fragP->fr_subtype)
3959 case TAB (BCC68000, BYTE):
3960 case TAB (ABRANCH, BYTE):
3961 know (issbyte (disp));
3963 as_bad ("short branch with zero offset: use :w");
3964 fragP->fr_opcode[1] = disp;
3967 case TAB (DBCC, SHORT):
3968 know (issword (disp));
3971 case TAB (BCC68000, SHORT):
3972 case TAB (ABRANCH, SHORT):
3973 know (issword (disp));
3974 fragP->fr_opcode[1] = 0x00;
3977 case TAB (ABRANCH, LONG):
3978 if (cpu_of_arch (current_architecture) < m68020)
3980 if (fragP->fr_opcode[0] == 0x61)
3983 fragP->fr_opcode[0] = 0x4E;
3984 fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3998 else if (fragP->fr_opcode[0] == 0x60)
4000 fragP->fr_opcode[0] = 0x4E;
4001 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4002 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4003 fragP->fr_offset, 0, NO_RELOC);
4009 as_bad ("Long branch offset not supported.");
4014 fragP->fr_opcode[1] = (char) 0xff;
4018 case TAB (BCC68000, LONG):
4019 /* only Bcc 68000 instructions can come here */
4020 /* change bcc into b!cc/jmp absl long */
4021 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
4022 fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
4024 /* JF: these used to be fr_opcode[2,3], but they may be in a
4025 different frag, in which case refering to them is a no-no.
4026 Only fr_opcode[0,1] are guaranteed to work. */
4027 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4028 *buffer_address++ = (char) 0xf9;
4029 fragP->fr_fix += 2; /* account for jmp instruction */
4030 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4031 fragP->fr_offset, 0, NO_RELOC);
4035 case TAB (DBCC, LONG):
4036 /* only DBcc 68000 instructions can come here */
4037 /* change dbcc into dbcc/jmp absl long */
4038 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4039 *buffer_address++ = 0x00; /* branch offset = 4 */
4040 *buffer_address++ = 0x04;
4041 *buffer_address++ = 0x60; /* put in bra pc+6 */
4042 *buffer_address++ = 0x06;
4043 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4044 *buffer_address++ = (char) 0xf9;
4046 fragP->fr_fix += 6; /* account for bra/jmp instructions */
4047 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4048 fragP->fr_offset, 0, NO_RELOC);
4052 case TAB (FBRANCH, SHORT):
4053 know ((fragP->fr_opcode[1] & 0x40) == 0);
4056 case TAB (FBRANCH, LONG):
4057 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
4060 case TAB (PCREL, SHORT):
4063 case TAB (PCREL, LONG):
4064 /* The thing to do here is force it to ABSOLUTE LONG, since
4065 PCREL is really trying to shorten an ABSOLUTE address anyway */
4066 /* JF FOO This code has not been tested */
4067 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4069 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4070 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
4071 (unsigned) fragP->fr_opcode[0],
4072 (unsigned long) fragP->fr_address);
4073 fragP->fr_opcode[1] &= ~0x3F;
4074 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4078 case TAB (PCLEA, SHORT):
4079 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4080 fragP->fr_offset, 1, NO_RELOC);
4081 fragP->fr_opcode[1] &= ~0x3F;
4082 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4085 case TAB (PCLEA, LONG):
4086 fixP = fix_new (fragP, (int) (fragP->fr_fix) + 2, 4, fragP->fr_symbol,
4087 fragP->fr_offset, 1, NO_RELOC);
4088 fixP->fx_pcrel_adjust = 2;
4089 /* Already set to mode 7.3; this indicates: PC indirect with
4090 suppressed index, 32-bit displacement. */
4091 *buffer_address++ = 0x01;
4092 *buffer_address++ = 0x70;
4097 case TAB (PCINDEX, BYTE):
4099 if (!issbyte (disp))
4101 as_bad ("displacement doesn't fit in one byte");
4104 assert (fragP->fr_fix >= 2);
4105 buffer_address[-2] &= ~1;
4106 buffer_address[-1] = disp;
4109 case TAB (PCINDEX, SHORT):
4111 assert (issword (disp));
4112 assert (fragP->fr_fix >= 2);
4113 buffer_address[-2] |= 0x1;
4114 buffer_address[-1] = 0x20;
4115 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4116 fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
4118 fixP->fx_pcrel_adjust = 2;
4121 case TAB (PCINDEX, LONG):
4123 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4124 fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
4126 fixP->fx_pcrel_adjust = 2;
4127 assert (fragP->fr_fix >= 2);
4128 buffer_address[-2] |= 0x1;
4129 buffer_address[-1] = 0x30;
4136 md_number_to_chars (buffer_address, (long) disp, (int) ext);
4137 fragP->fr_fix += ext;
4141 #ifndef BFD_ASSEMBLER
4144 md_convert_frag (headers, sec, fragP)
4145 object_headers *headers;
4149 md_convert_frag_1 (fragP);
4155 md_convert_frag (abfd, sec, fragP)
4160 md_convert_frag_1 (fragP);
4164 /* Force truly undefined symbols to their maximum size, and generally set up
4165 the frag list to be relaxed
4168 md_estimate_size_before_relax (fragP, segment)
4169 register fragS *fragP;
4173 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
4175 old_fix = fragP->fr_fix;
4177 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4178 switch (fragP->fr_subtype)
4181 case TAB (ABRANCH, SZ_UNDEF):
4183 if ((fragP->fr_symbol != NULL) /* Not absolute */
4184 && S_GET_SEGMENT (fragP->fr_symbol) == segment)
4186 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4189 else if ((fragP->fr_symbol == 0) || (cpu_of_arch (current_architecture) < m68020))
4191 /* On 68000, or for absolute value, switch to abs long */
4192 /* FIXME, we should check abs val, pick short or long */
4193 if (fragP->fr_opcode[0] == 0x61)
4195 fragP->fr_opcode[0] = 0x4E;
4196 fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4197 fix_new (fragP, fragP->fr_fix, 4,
4198 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
4202 else if (fragP->fr_opcode[0] == 0x60)
4204 fragP->fr_opcode[0] = 0x4E;
4205 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4206 fix_new (fragP, fragP->fr_fix, 4,
4207 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
4213 as_warn ("Long branch offset to extern symbol not supported.");
4217 { /* Symbol is still undefined. Make it simple */
4218 fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4219 fragP->fr_offset, 1, NO_RELOC);
4221 fragP->fr_opcode[1] = (char) 0xff;
4227 } /* case TAB(ABRANCH,SZ_UNDEF) */
4229 case TAB (FBRANCH, SZ_UNDEF):
4231 if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flag_short_refs)
4233 fragP->fr_subtype = TAB (FBRANCH, SHORT);
4238 fix_new (fragP, (int) fragP->fr_fix, 4, fragP->fr_symbol,
4239 fragP->fr_offset, 1, NO_RELOC);
4241 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
4245 } /* TAB(FBRANCH,SZ_UNDEF) */
4247 case TAB (PCREL, SZ_UNDEF):
4249 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4251 || cpu_of_arch (current_architecture) < m68020)
4253 fragP->fr_subtype = TAB (PCREL, SHORT);
4258 fragP->fr_subtype = TAB (PCREL, LONG);
4262 } /* TAB(PCREL,SZ_UNDEF) */
4264 case TAB (BCC68000, SZ_UNDEF):
4266 if ((fragP->fr_symbol != NULL)
4267 && S_GET_SEGMENT (fragP->fr_symbol) == segment)
4269 fragP->fr_subtype = TAB (BCC68000, BYTE);
4272 /* only Bcc 68000 instructions can come here */
4273 /* change bcc into b!cc/jmp absl long */
4274 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
4275 if (flag_short_refs)
4277 fragP->fr_opcode[1] = 0x04; /* branch offset = 6 */
4278 /* JF: these were fr_opcode[2,3] */
4279 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
4280 buffer_address[1] = (char) 0xf8;
4281 fragP->fr_fix += 2; /* account for jmp instruction */
4282 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
4283 fragP->fr_offset, 0, NO_RELOC);
4288 fragP->fr_opcode[1] = 0x06; /* branch offset = 6 */
4289 /* JF: these were fr_opcode[2,3] */
4290 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
4291 buffer_address[1] = (char) 0xf9;
4292 fragP->fr_fix += 2; /* account for jmp instruction */
4293 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4294 fragP->fr_offset, 0, NO_RELOC);
4299 } /* case TAB(BCC68000,SZ_UNDEF) */
4301 case TAB (DBCC, SZ_UNDEF):
4303 if (fragP->fr_symbol != NULL && S_GET_SEGMENT (fragP->fr_symbol) == segment)
4305 fragP->fr_subtype = TAB (DBCC, SHORT);
4309 /* only DBcc 68000 instructions can come here */
4310 /* change dbcc into dbcc/jmp absl long */
4311 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4312 buffer_address[0] = 0x00; /* branch offset = 4 */
4313 buffer_address[1] = 0x04;
4314 buffer_address[2] = 0x60; /* put in bra pc + ... */
4316 if (flag_short_refs)
4318 /* JF: these were fr_opcode[5-7] */
4319 buffer_address[3] = 0x04; /* plus 4 */
4320 buffer_address[4] = 0x4e; /* Put in Jump Word */
4321 buffer_address[5] = (char) 0xf8;
4322 fragP->fr_fix += 6; /* account for bra/jmp instruction */
4323 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
4324 fragP->fr_offset, 0, NO_RELOC);
4329 /* JF: these were fr_opcode[5-7] */
4330 buffer_address[3] = 0x06; /* Plus 6 */
4331 buffer_address[4] = 0x4e; /* put in jmp long (0x4ef9) */
4332 buffer_address[5] = (char) 0xf9;
4333 fragP->fr_fix += 6; /* account for bra/jmp instruction */
4334 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4335 fragP->fr_offset, 0, NO_RELOC);
4341 } /* case TAB(DBCC,SZ_UNDEF) */
4343 case TAB (PCLEA, SZ_UNDEF):
4345 if ((S_GET_SEGMENT (fragP->fr_symbol)) == segment
4347 || cpu_of_arch (current_architecture) < m68020)
4349 fragP->fr_subtype = TAB (PCLEA, SHORT);
4354 fragP->fr_subtype = TAB (PCLEA, LONG);
4358 } /* TAB(PCLEA,SZ_UNDEF) */
4360 case TAB (PCINDEX, SZ_UNDEF):
4361 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4362 || cpu_of_arch (current_architecture) < m68020)
4364 fragP->fr_subtype = TAB (PCINDEX, BYTE);
4368 fragP->fr_subtype = TAB (PCINDEX, LONG);
4377 /* now that SZ_UNDEF are taken care of, check others */
4378 switch (fragP->fr_subtype)
4380 case TAB (BCC68000, BYTE):
4381 case TAB (ABRANCH, BYTE):
4382 /* We can't do a short jump to the next instruction, so in that
4383 case we force word mode. At this point S_GET_VALUE should
4384 return the offset of the symbol within its frag. If the
4385 symbol is at the start of a frag, and it is the next frag
4386 with any data in it (usually this is just the next frag, but
4387 assembler listings may introduce empty frags), we must use
4389 if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0)
4393 for (l = fragP->fr_next;
4394 l != fragP->fr_symbol->sy_frag;
4396 if (l->fr_fix + l->fr_var != 0)
4398 if (l == fragP->fr_symbol->sy_frag)
4400 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4408 return fragP->fr_var + fragP->fr_fix - old_fix;
4411 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4412 /* the bit-field entries in the relocation_info struct plays hell
4413 with the byte-order problems of cross-assembly. So as a hack,
4414 I added this mach. dependent ri twiddler. Ugly, but it gets
4416 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4417 are symbolnum, most sig. byte first. Last byte is broken up with
4418 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4419 nibble as nuthin. (on Sun 3 at least) */
4420 /* Translate the internal relocation information into target-specific
4424 md_ri_to_chars (the_bytes, ri)
4426 struct reloc_info_generic *ri;
4429 md_number_to_chars (the_bytes, ri->r_address, 4);
4430 /* now the fun stuff */
4431 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
4432 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
4433 the_bytes[6] = ri->r_symbolnum & 0x0ff;
4434 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
4435 ((ri->r_extern << 4) & 0x10));
4438 #endif /* comment */
4440 #ifndef BFD_ASSEMBLER
4442 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
4445 relax_addressT segment_address_in_file;
4448 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4449 * Out: GNU LD relocation length code: 0, 1, or 2.
4452 static CONST unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
4455 know (fixP->fx_addsy != NULL);
4457 md_number_to_chars (where,
4458 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
4461 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
4462 ? S_GET_TYPE (fixP->fx_addsy)
4463 : fixP->fx_addsy->sy_number);
4465 where[4] = (r_symbolnum >> 16) & 0x0ff;
4466 where[5] = (r_symbolnum >> 8) & 0x0ff;
4467 where[6] = r_symbolnum & 0x0ff;
4468 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
4469 (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
4473 #endif /* OBJ_AOUT or OBJ_BOUT */
4475 #ifndef WORKING_DOT_WORD
4476 CONST int md_short_jump_size = 4;
4477 CONST int md_long_jump_size = 6;
4480 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
4482 addressT from_addr, to_addr;
4488 offset = to_addr - (from_addr + 2);
4490 md_number_to_chars (ptr, (valueT) 0x6000, 2);
4491 md_number_to_chars (ptr + 2, (valueT) offset, 2);
4495 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
4497 addressT from_addr, to_addr;
4503 if (cpu_of_arch (current_architecture) < m68020)
4505 offset = to_addr - S_GET_VALUE (to_symbol);
4506 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
4507 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4508 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
4513 offset = to_addr - (from_addr + 2);
4514 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
4515 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4521 /* Different values of OK tell what its OK to return. Things that
4522 aren't OK are an error (what a shock, no?)
4525 10: Absolute 1:8 only
4526 20: Absolute 0:7 only
4527 30: absolute 0:15 only
4528 40: Absolute 0:31 only
4529 50: absolute 0:127 only
4530 55: absolute -64:63 only
4531 60: absolute -128:127 only
4532 70: absolute 0:4095 only
4539 struct m68k_exp *exp;
4542 if (exp->exp.X_op == O_absent)
4544 /* Do the same thing the VAX asm does */
4545 op (exp) = O_constant;
4551 as_warn ("expression out of range: defaulting to 1");
4555 else if (exp->exp.X_op == O_constant)
4560 if (offs (exp) < 1 || offs (exp) > 8)
4562 as_warn ("expression out of range: defaulting to 1");
4567 if (offs (exp) < 0 || offs (exp) > 7)
4571 if (offs (exp) < 0 || offs (exp) > 15)
4575 if (offs (exp) < 0 || offs (exp) > 32)
4579 if (offs (exp) < 0 || offs (exp) > 127)
4583 if (offs (exp) < -64 || offs (exp) > 63)
4587 if (offs (exp) < -128 || offs (exp) > 127)
4591 if (offs (exp) < 0 || offs (exp) > 4095)
4594 as_warn ("expression out of range: defaulting to 0");
4602 else if (exp->exp.X_op == O_big)
4604 if (offs (exp) <= 0 /* flonum */
4605 && (ok == 80 /* no bignums */
4606 || (ok > 10 /* small-int ranges including 0 ok */
4607 /* If we have a flonum zero, a zero integer should
4608 do as well (e.g., in moveq). */
4609 && generic_floating_point_number.exponent == 0
4610 && generic_floating_point_number.low[0] == 0)))
4612 /* HACK! Turn it into a long */
4613 LITTLENUM_TYPE words[6];
4615 gen_to_words (words, 2, 8L); /* These numbers are magic! */
4616 op (exp) = O_constant;
4619 offs (exp) = words[1] | (words[0] << 16);
4623 op (exp) = O_constant;
4626 offs (exp) = (ok == 10) ? 1 : 0;
4627 as_warn ("Can't deal with expression; defaulting to %ld",
4633 if (ok >= 10 && ok <= 70)
4635 op (exp) = O_constant;
4638 offs (exp) = (ok == 10) ? 1 : 0;
4639 as_warn ("Can't deal with expression; defaulting to %ld",
4644 if (exp->size != SIZE_UNSPEC)
4652 if (!isbyte (offs (exp)))
4653 as_warn ("expression doesn't fit in BYTE");
4656 if (!isword (offs (exp)))
4657 as_warn ("expression doesn't fit in WORD");
4665 /* These are the back-ends for the various machine dependent pseudo-ops. */
4666 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4672 subseg_set (data_section, 1);
4673 demand_empty_rest_of_line ();
4680 subseg_set (data_section, 2);
4681 demand_empty_rest_of_line ();
4688 /* We don't support putting frags in the BSS segment, we fake it
4689 by marking in_bss, then looking at s_skip for clues. */
4691 subseg_set (bss_section, 0);
4692 demand_empty_rest_of_line ();
4700 register long temp_fill;
4702 temp = 1; /* JF should be 2? */
4703 temp_fill = get_absolute_expression ();
4704 if (!need_pass_2) /* Never make frag if expect extra pass. */
4705 frag_align (temp, (int) temp_fill);
4706 demand_empty_rest_of_line ();
4713 demand_empty_rest_of_line ();
4716 /* Pseudo-ops handled for MRI compatibility. */
4718 /* This function returns non-zero if the argument is a conditional
4719 pseudo-op. This is called when checking whether a pending
4720 alignment is needed. */
4723 m68k_conditional_pseudoop (pop)
4726 return (pop->poc_handler == s_mri_if
4727 || pop->poc_handler == s_mri_else);
4730 /* Handle an MRI style chip specification. */
4739 s = input_line_pointer;
4740 c = get_symbol_end ();
4741 for (i = 0; i < n_archs; i++)
4742 if (strcasecmp (s, archs[i].name) == 0)
4746 as_bad ("%s: unrecognized processor name", s);
4747 *input_line_pointer = c;
4748 ignore_rest_of_line ();
4751 *input_line_pointer = c;
4753 if (*input_line_pointer == '/')
4754 current_architecture = 0;
4756 current_architecture &= m68881 | m68851;
4757 current_architecture |= archs[i].arch;
4759 while (*input_line_pointer == '/')
4761 ++input_line_pointer;
4762 s = input_line_pointer;
4763 c = get_symbol_end ();
4764 if (strcmp (s, "68881") == 0)
4765 current_architecture |= m68881;
4766 else if (strcmp (s, "68851") == 0)
4767 current_architecture |= m68851;
4768 *input_line_pointer = c;
4771 /* Update info about available control registers. */
4772 select_control_regs ();
4775 /* The MRI CHIP pseudo-op. */
4785 stop = mri_comment_field (&stopc);
4788 mri_comment_end (stop, stopc);
4789 demand_empty_rest_of_line ();
4792 /* The MRI FOPT pseudo-op. */
4800 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
4804 input_line_pointer += 3;
4805 temp = get_absolute_expression ();
4806 if (temp < 0 || temp > 7)
4807 as_bad ("bad coprocessor id");
4809 m68k_float_copnum = COP0 + temp;
4813 as_bad ("unrecognized fopt option");
4814 ignore_rest_of_line ();
4818 demand_empty_rest_of_line ();
4821 /* The structure used to handle the MRI OPT pseudo-op. */
4825 /* The name of the option. */
4828 /* If this is not NULL, just call this function. The first argument
4829 is the ARG field of this structure, the second argument is
4830 whether the option was negated. */
4831 void (*pfn) PARAMS ((int arg, int on));
4833 /* If this is not NULL, and the PFN field is NULL, set the variable
4834 this points to. Set it to the ARG field if the option was not
4835 negated, and the NOTARG field otherwise. */
4838 /* The value to pass to PFN or to assign to *PVAR. */
4841 /* The value to assign to *PVAR if the option is negated. If PFN is
4842 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4843 the option may not be negated. */
4847 /* The table used to handle the MRI OPT pseudo-op. */
4849 static void skip_to_comma PARAMS ((int, int));
4850 static void opt_nest PARAMS ((int, int));
4851 static void opt_chip PARAMS ((int, int));
4852 static void opt_list PARAMS ((int, int));
4853 static void opt_list_symbols PARAMS ((int, int));
4855 static const struct opt_action opt_table[] =
4857 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
4859 /* We do relaxing, so there is little use for these options. */
4860 { "b", 0, 0, 0, 0 },
4861 { "brs", 0, 0, 0, 0 },
4862 { "brb", 0, 0, 0, 0 },
4863 { "brl", 0, 0, 0, 0 },
4864 { "brw", 0, 0, 0, 0 },
4866 { "c", 0, 0, 0, 0 },
4867 { "cex", 0, 0, 0, 0 },
4868 { "case", 0, &symbols_case_sensitive, 1, 0 },
4869 { "cl", 0, 0, 0, 0 },
4870 { "cre", 0, 0, 0, 0 },
4871 { "d", 0, &flag_keep_locals, 1, 0 },
4872 { "e", 0, 0, 0, 0 },
4873 { "f", 0, &flag_short_refs, 1, 0 },
4874 { "frs", 0, &flag_short_refs, 1, 0 },
4875 { "frl", 0, &flag_short_refs, 0, 1 },
4876 { "g", 0, 0, 0, 0 },
4877 { "i", 0, 0, 0, 0 },
4878 { "m", 0, 0, 0, 0 },
4879 { "mex", 0, 0, 0, 0 },
4880 { "mc", 0, 0, 0, 0 },
4881 { "md", 0, 0, 0, 0 },
4882 { "nest", opt_nest, 0, 0, 0 },
4883 { "next", skip_to_comma, 0, 0, 0 },
4884 { "o", 0, 0, 0, 0 },
4885 { "old", 0, 0, 0, 0 },
4886 { "op", skip_to_comma, 0, 0, 0 },
4887 { "pco", 0, 0, 0, 0 },
4888 { "p", opt_chip, 0, 0, 0 },
4889 { "pcr", 0, 0, 0, 0 },
4890 { "pcs", 0, 0, 0, 0 },
4891 { "r", 0, 0, 0, 0 },
4892 { "quick", 0, &m68k_quick, 1, 0 },
4893 { "rel32", 0, &m68k_rel32, 1, 0 },
4894 { "s", opt_list, 0, 0, 0 },
4895 { "t", opt_list_symbols, 0, 0, 0 },
4896 { "w", 0, &flag_no_warnings, 0, 1 },
4900 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4902 /* The MRI OPT pseudo-op. */
4914 const struct opt_action *o;
4919 if (*input_line_pointer == '-')
4921 ++input_line_pointer;
4924 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
4926 input_line_pointer += 2;
4930 s = input_line_pointer;
4931 c = get_symbol_end ();
4933 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
4935 if (strcasecmp (s, o->name) == 0)
4939 /* Restore input_line_pointer now in case the option
4941 *input_line_pointer = c;
4942 (*o->pfn) (o->arg, t);
4944 else if (o->pvar != NULL)
4946 if (! t && o->arg == o->notarg)
4947 as_bad ("option `%s' may not be negated", s);
4948 *input_line_pointer = c;
4949 *o->pvar = t ? o->arg : o->notarg;
4952 *input_line_pointer = c;
4958 as_bad ("option `%s' not recognized", s);
4959 *input_line_pointer = c;
4962 while (*input_line_pointer++ == ',');
4964 /* Move back to terminating character. */
4965 --input_line_pointer;
4966 demand_empty_rest_of_line ();
4969 /* Skip ahead to a comma. This is used for OPT options which we do
4970 not suppor tand which take arguments. */
4973 skip_to_comma (arg, on)
4977 while (*input_line_pointer != ','
4978 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4979 ++input_line_pointer;
4982 /* Handle the OPT NEST=depth option. */
4989 if (*input_line_pointer != '=')
4991 as_bad ("bad format of OPT NEST=depth");
4995 ++input_line_pointer;
4996 max_macro_nest = get_absolute_expression ();
4999 /* Handle the OPT P=chip option. */
5006 if (*input_line_pointer != '=')
5008 /* This is just OPT P, which we do not support. */
5012 ++input_line_pointer;
5016 /* Handle the OPT S option. */
5026 /* Handle the OPT T option. */
5029 opt_list_symbols (arg, on)
5034 listing |= LISTING_SYMBOLS;
5036 listing &=~ LISTING_SYMBOLS;
5039 /* Handle the MRI REG pseudo-op. */
5052 if (line_label == NULL)
5054 as_bad ("missing label");
5055 ignore_rest_of_line ();
5060 stop = mri_comment_field (&stopc);
5064 s = input_line_pointer;
5065 while (isalnum ((unsigned char) *input_line_pointer)
5066 #ifdef REGISTER_PREFIX
5067 || *input_line_pointer == REGISTER_PREFIX
5069 || *input_line_pointer == '/'
5070 || *input_line_pointer == '-')
5071 ++input_line_pointer;
5072 c = *input_line_pointer;
5073 *input_line_pointer = '\0';
5075 if (m68k_ip_op (s, &rop) != 0)
5077 if (rop.error == NULL)
5078 as_bad ("bad register list");
5080 as_bad ("bad register list: %s", rop.error);
5081 *input_line_pointer = c;
5082 ignore_rest_of_line ();
5086 *input_line_pointer = c;
5088 if (rop.mode == REGLST)
5090 else if (rop.mode == DREG)
5091 mask = 1 << (rop.reg - DATA0);
5092 else if (rop.mode == AREG)
5093 mask = 1 << (rop.reg - ADDR0 + 8);
5094 else if (rop.mode == FPREG)
5095 mask = 1 << (rop.reg - FP0 + 16);
5096 else if (rop.mode == CONTROL
5099 else if (rop.mode == CONTROL
5102 else if (rop.mode == CONTROL
5107 as_bad ("bad register list");
5108 ignore_rest_of_line ();
5112 S_SET_SEGMENT (line_label, absolute_section);
5113 S_SET_VALUE (line_label, mask);
5114 line_label->sy_frag = &zero_address_frag;
5117 mri_comment_end (stop, stopc);
5119 demand_empty_rest_of_line ();
5122 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5126 struct save_opts *next;
5128 int symbols_case_sensitive;
5136 /* FIXME: We don't save OPT S. */
5139 /* This variable holds the stack of saved options. */
5141 static struct save_opts *save_stack;
5143 /* The MRI SAVE pseudo-op. */
5149 struct save_opts *s;
5151 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5152 s->abspcadd = m68k_abspcadd;
5153 s->symbols_case_sensitive = symbols_case_sensitive;
5154 s->keep_locals = flag_keep_locals;
5155 s->short_refs = flag_short_refs;
5156 s->architecture = current_architecture;
5157 s->quick = m68k_quick;
5158 s->rel32 = m68k_rel32;
5159 s->listing = listing;
5160 s->no_warnings = flag_no_warnings;
5162 s->next = save_stack;
5165 demand_empty_rest_of_line ();
5168 /* The MRI RESTORE pseudo-op. */
5174 struct save_opts *s;
5176 if (save_stack == NULL)
5178 as_bad ("restore without save");
5179 ignore_rest_of_line ();
5184 save_stack = s->next;
5186 m68k_abspcadd = s->abspcadd;
5187 symbols_case_sensitive = s->symbols_case_sensitive;
5188 flag_keep_locals = s->keep_locals;
5189 flag_short_refs = s->short_refs;
5190 current_architecture = s->architecture;
5191 m68k_quick = s->quick;
5192 m68k_rel32 = s->rel32;
5193 listing = s->listing;
5194 flag_no_warnings = s->no_warnings;
5198 demand_empty_rest_of_line ();
5201 /* Types of MRI structured control directives. */
5203 enum mri_control_type
5211 /* This structure is used to stack the MRI structured control
5214 struct mri_control_info
5216 /* The directive within which this one is enclosed. */
5217 struct mri_control_info *outer;
5219 /* The type of directive. */
5220 enum mri_control_type type;
5222 /* Whether an ELSE has been in an IF. */
5225 /* The add or sub statement at the end of a FOR. */
5228 /* The label of the top of a FOR or REPEAT loop. */
5231 /* The label to jump to for the next iteration, or the else
5232 expression of a conditional. */
5235 /* The label to jump to to break out of the loop, or the label past
5236 the end of a conditional. */
5240 /* The stack of MRI structured control directives. */
5242 static struct mri_control_info *mri_control_stack;
5244 /* The current MRI structured control directive index number, used to
5245 generate label names. */
5247 static int mri_control_index;
5249 /* Some function prototypes. */
5251 static char *mri_control_label PARAMS ((void));
5252 static struct mri_control_info *push_mri_control
5253 PARAMS ((enum mri_control_type));
5254 static void pop_mri_control PARAMS ((void));
5255 static int parse_mri_condition PARAMS ((int *));
5256 static int parse_mri_control_operand
5257 PARAMS ((int *, char **, char **, char **, char **));
5258 static int swap_mri_condition PARAMS ((int));
5259 static int reverse_mri_condition PARAMS ((int));
5260 static void build_mri_control_operand
5261 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5262 const char *, int));
5263 static void parse_mri_control_expression
5264 PARAMS ((char *, int, const char *, const char *, int));
5266 /* Generate a new MRI label structured control directive label name. */
5269 mri_control_label ()
5273 n = (char *) xmalloc (20);
5274 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5275 ++mri_control_index;
5279 /* Create a new MRI structured control directive. */
5281 static struct mri_control_info *
5282 push_mri_control (type)
5283 enum mri_control_type type;
5285 struct mri_control_info *n;
5287 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5291 if (type == mri_if || type == mri_while)
5294 n->top = mri_control_label ();
5295 n->next = mri_control_label ();
5296 n->bottom = mri_control_label ();
5298 n->outer = mri_control_stack;
5299 mri_control_stack = n;
5304 /* Pop off the stack of MRI structured control directives. */
5309 struct mri_control_info *n;
5311 n = mri_control_stack;
5312 mri_control_stack = n->outer;
5320 /* Recognize a condition code in an MRI structured control expression. */
5323 parse_mri_condition (pcc)
5328 know (*input_line_pointer == '<');
5330 ++input_line_pointer;
5331 c1 = *input_line_pointer++;
5332 c2 = *input_line_pointer++;
5334 if (*input_line_pointer != '>')
5336 as_bad ("syntax error in structured control directive");
5340 ++input_line_pointer;
5348 *pcc = (c1 << 8) | c2;
5353 /* Parse a single operand in an MRI structured control expression. */
5356 parse_mri_control_operand (pcc, leftstart, leftstop, rightstart, rightstop)
5373 if (*input_line_pointer == '<')
5375 /* It's just a condition code. */
5376 return parse_mri_condition (pcc);
5379 /* Look ahead for the condition code. */
5380 for (s = input_line_pointer; *s != '\0'; ++s)
5382 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
5387 as_bad ("missing condition code in structured control directive");
5391 *leftstart = input_line_pointer;
5393 if (*leftstop > *leftstart
5394 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
5397 input_line_pointer = s;
5398 if (! parse_mri_condition (pcc))
5401 /* Look ahead for AND or OR or end of line. */
5402 for (s = input_line_pointer; *s != '\0'; ++s)
5404 if ((strncasecmp (s, "AND", 3) == 0
5405 && (s[3] == '.' || ! is_part_of_name (s[3])))
5406 || (strncasecmp (s, "OR", 2) == 0
5407 && (s[2] == '.' || ! is_part_of_name (s[2]))))
5411 *rightstart = input_line_pointer;
5413 if (*rightstop > *rightstart
5414 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
5417 input_line_pointer = s;
5422 #define MCC(b1, b2) (((b1) << 8) | (b2))
5424 /* Swap the sense of a condition. This changes the condition so that
5425 it generates the same result when the operands are swapped. */
5428 swap_mri_condition (cc)
5433 case MCC ('h', 'i'): return MCC ('c', 's');
5434 case MCC ('l', 's'): return MCC ('c', 'c');
5435 case MCC ('c', 'c'): return MCC ('l', 's');
5436 case MCC ('c', 's'): return MCC ('h', 'i');
5437 case MCC ('p', 'l'): return MCC ('m', 'i');
5438 case MCC ('m', 'i'): return MCC ('p', 'l');
5439 case MCC ('g', 'e'): return MCC ('l', 'e');
5440 case MCC ('l', 't'): return MCC ('g', 't');
5441 case MCC ('g', 't'): return MCC ('l', 't');
5442 case MCC ('l', 'e'): return MCC ('g', 'e');
5447 /* Reverse the sense of a condition. */
5450 reverse_mri_condition (cc)
5455 case MCC ('h', 'i'): return MCC ('l', 's');
5456 case MCC ('l', 's'): return MCC ('h', 'i');
5457 case MCC ('c', 'c'): return MCC ('c', 's');
5458 case MCC ('c', 's'): return MCC ('c', 'c');
5459 case MCC ('n', 'e'): return MCC ('e', 'q');
5460 case MCC ('e', 'q'): return MCC ('n', 'e');
5461 case MCC ('v', 'c'): return MCC ('v', 's');
5462 case MCC ('v', 's'): return MCC ('v', 'c');
5463 case MCC ('p', 'l'): return MCC ('m', 'i');
5464 case MCC ('m', 'i'): return MCC ('p', 'l');
5465 case MCC ('g', 'e'): return MCC ('l', 't');
5466 case MCC ('l', 't'): return MCC ('g', 'e');
5467 case MCC ('g', 't'): return MCC ('l', 'e');
5468 case MCC ('l', 'e'): return MCC ('g', 't');
5473 /* Build an MRI structured control expression. This generates test
5474 and branch instructions. It goes to TRUELAB if the condition is
5475 true, and to FALSELAB if the condition is false. Exactly one of
5476 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5477 is the size qualifier for the expression. EXTENT is the size to
5478 use for the branch. */
5481 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5482 rightstop, truelab, falselab, extent)
5489 const char *truelab;
5490 const char *falselab;
5496 if (leftstart != NULL)
5498 struct m68k_op leftop, rightop;
5501 /* Swap the compare operands, if necessary, to produce a legal
5502 m68k compare instruction. Comparing a register operand with
5503 a non-register operand requires the register to be on the
5504 right (cmp, cmpa). Comparing an immediate value with
5505 anything requires the immediate value to be on the left
5510 (void) m68k_ip_op (leftstart, &leftop);
5515 (void) m68k_ip_op (rightstart, &rightop);
5518 if (rightop.mode == IMMED
5519 || ((leftop.mode == DREG || leftop.mode == AREG)
5520 && (rightop.mode != DREG && rightop.mode != AREG)))
5524 cc = swap_mri_condition (cc);
5526 leftstart = rightstart;
5529 leftstop = rightstop;
5534 if (truelab == NULL)
5536 cc = reverse_mri_condition (cc);
5540 if (leftstart != NULL)
5542 buf = (char *) xmalloc (20
5543 + (leftstop - leftstart)
5544 + (rightstop - rightstart));
5552 memcpy (s, leftstart, leftstop - leftstart);
5553 s += leftstop - leftstart;
5555 memcpy (s, rightstart, rightstop - rightstart);
5556 s += rightstop - rightstart;
5562 buf = (char *) xmalloc (20 + strlen (truelab));
5570 strcpy (s, truelab);
5575 /* Parse an MRI structured control expression. This generates test
5576 and branch instructions. STOP is where the expression ends. It
5577 goes to TRUELAB if the condition is true, and to FALSELAB if the
5578 condition is false. Exactly one of TRUELAB and FALSELAB will be
5579 NULL, meaning to fall through. QUAL is the size qualifier for the
5580 expression. EXTENT is the size to use for the branch. */
5583 parse_mri_control_expression (stop, qual, truelab, falselab, extent)
5586 const char *truelab;
5587 const char *falselab;
5600 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5601 &rightstart, &rightstop))
5607 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
5611 if (falselab != NULL)
5614 flab = mri_control_label ();
5616 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5617 rightstop, (const char *) NULL, flab, extent);
5619 input_line_pointer += 3;
5620 if (*input_line_pointer != '.'
5621 || input_line_pointer[1] == '\0')
5625 qual = input_line_pointer[1];
5626 input_line_pointer += 2;
5629 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5630 &rightstart, &rightstop))
5636 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5637 rightstop, truelab, falselab, extent);
5639 if (falselab == NULL)
5642 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
5646 if (truelab != NULL)
5649 tlab = mri_control_label ();
5651 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5652 rightstop, tlab, (const char *) NULL, extent);
5654 input_line_pointer += 2;
5655 if (*input_line_pointer != '.'
5656 || input_line_pointer[1] == '\0')
5660 qual = input_line_pointer[1];
5661 input_line_pointer += 2;
5664 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5665 &rightstart, &rightstop))
5671 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5672 rightstop, truelab, falselab, extent);
5674 if (truelab == NULL)
5679 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5680 rightstop, truelab, falselab, extent);
5684 if (input_line_pointer != stop)
5685 as_bad ("syntax error in structured control directive");
5688 /* Handle the MRI IF pseudo-op. This may be a structured control
5689 directive, or it may be a regular assembler conditional, depending
5698 struct mri_control_info *n;
5700 /* A structured control directive must end with THEN with an
5701 optional qualifier. */
5702 s = input_line_pointer;
5703 while (! is_end_of_line[(unsigned char) *s]
5704 && (! flag_mri || *s != '*'))
5707 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
5710 if (s - input_line_pointer > 1
5714 if (s - input_line_pointer < 3
5715 || strncasecmp (s - 3, "THEN", 4) != 0)
5719 as_bad ("missing then");
5720 ignore_rest_of_line ();
5724 /* It's a conditional. */
5729 /* Since this might be a conditional if, this pseudo-op will be
5730 called even if we are supported to be ignoring input. Double
5731 check now. Clobber *input_line_pointer so that ignore_input
5732 thinks that this is not a special pseudo-op. */
5733 c = *input_line_pointer;
5734 *input_line_pointer = 0;
5735 if (ignore_input ())
5737 *input_line_pointer = c;
5738 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5739 ++input_line_pointer;
5740 demand_empty_rest_of_line ();
5743 *input_line_pointer = c;
5745 n = push_mri_control (mri_if);
5747 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
5748 n->next, s[1] == '.' ? s[2] : '\0');
5751 input_line_pointer = s + 3;
5753 input_line_pointer = s + 1;
5757 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5758 ++input_line_pointer;
5761 demand_empty_rest_of_line ();
5764 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5765 structured IF, associate the ELSE with the IF. Otherwise, assume
5766 it is a conditional else. */
5777 && (mri_control_stack == NULL
5778 || mri_control_stack->type != mri_if
5779 || mri_control_stack->else_seen))
5785 c = *input_line_pointer;
5786 *input_line_pointer = 0;
5787 if (ignore_input ())
5789 *input_line_pointer = c;
5790 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5791 ++input_line_pointer;
5792 demand_empty_rest_of_line ();
5795 *input_line_pointer = c;
5797 if (mri_control_stack == NULL
5798 || mri_control_stack->type != mri_if
5799 || mri_control_stack->else_seen)
5801 as_bad ("else without matching if");
5802 ignore_rest_of_line ();
5806 mri_control_stack->else_seen = 1;
5808 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
5811 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
5815 colon (mri_control_stack->next);
5819 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5820 ++input_line_pointer;
5823 demand_empty_rest_of_line ();
5826 /* Handle the MRI ENDI pseudo-op. */
5832 if (mri_control_stack == NULL
5833 || mri_control_stack->type != mri_if)
5835 as_bad ("endi without matching if");
5836 ignore_rest_of_line ();
5840 /* ignore_input will not return true for ENDI, so we don't need to
5841 worry about checking it again here. */
5843 if (! mri_control_stack->else_seen)
5844 colon (mri_control_stack->next);
5845 colon (mri_control_stack->bottom);
5851 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5852 ++input_line_pointer;
5855 demand_empty_rest_of_line ();
5858 /* Handle the MRI BREAK pseudo-op. */
5861 s_mri_break (extent)
5864 struct mri_control_info *n;
5868 n = mri_control_stack;
5870 && n->type != mri_for
5871 && n->type != mri_repeat
5872 && n->type != mri_while)
5876 as_bad ("break outside of structured loop");
5877 ignore_rest_of_line ();
5881 buf = (char *) xmalloc (20 + strlen (n->bottom));
5884 sprintf (buf, "bra%s %s", ex, n->bottom);
5890 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5891 ++input_line_pointer;
5894 demand_empty_rest_of_line ();
5897 /* Handle the MRI NEXT pseudo-op. */
5903 struct mri_control_info *n;
5907 n = mri_control_stack;
5909 && n->type != mri_for
5910 && n->type != mri_repeat
5911 && n->type != mri_while)
5915 as_bad ("next outside of structured loop");
5916 ignore_rest_of_line ();
5920 buf = (char *) xmalloc (20 + strlen (n->next));
5923 sprintf (buf, "bra%s %s", ex, n->next);
5929 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5930 ++input_line_pointer;
5933 demand_empty_rest_of_line ();
5936 /* Handle the MRI FOR pseudo-op. */
5942 const char *varstart, *varstop;
5943 const char *initstart, *initstop;
5944 const char *endstart, *endstop;
5945 const char *bystart, *bystop;
5949 struct mri_control_info *n;
5955 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
5959 varstart = input_line_pointer;
5961 /* Look for the '='. */
5962 while (! is_end_of_line[(unsigned char) *input_line_pointer]
5963 && *input_line_pointer != '=')
5964 ++input_line_pointer;
5965 if (*input_line_pointer != '=')
5967 as_bad ("missing =");
5968 ignore_rest_of_line ();
5972 varstop = input_line_pointer;
5973 if (varstop > varstart
5974 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
5977 ++input_line_pointer;
5979 initstart = input_line_pointer;
5981 /* Look for TO or DOWNTO. */
5984 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5986 if (strncasecmp (input_line_pointer, "TO", 2) == 0
5987 && ! is_part_of_name (input_line_pointer[2]))
5989 initstop = input_line_pointer;
5990 input_line_pointer += 2;
5993 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
5994 && ! is_part_of_name (input_line_pointer[6]))
5996 initstop = input_line_pointer;
5998 input_line_pointer += 6;
6001 ++input_line_pointer;
6003 if (initstop == NULL)
6005 as_bad ("missing to or downto");
6006 ignore_rest_of_line ();
6009 if (initstop > initstart
6010 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6014 endstart = input_line_pointer;
6016 /* Look for BY or DO. */
6019 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6021 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6022 && ! is_part_of_name (input_line_pointer[2]))
6024 endstop = input_line_pointer;
6026 input_line_pointer += 2;
6029 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6030 && (input_line_pointer[2] == '.'
6031 || ! is_part_of_name (input_line_pointer[2])))
6033 endstop = input_line_pointer;
6034 input_line_pointer += 2;
6037 ++input_line_pointer;
6039 if (endstop == NULL)
6041 as_bad ("missing do");
6042 ignore_rest_of_line ();
6045 if (endstop > endstart
6046 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6052 bystop = bystart + 2;
6057 bystart = input_line_pointer;
6061 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6063 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6064 && (input_line_pointer[2] == '.'
6065 || ! is_part_of_name (input_line_pointer[2])))
6067 bystop = input_line_pointer;
6068 input_line_pointer += 2;
6071 ++input_line_pointer;
6075 as_bad ("missing do");
6076 ignore_rest_of_line ();
6079 if (bystop > bystart
6080 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6084 if (*input_line_pointer != '.')
6088 extent = input_line_pointer[1];
6089 input_line_pointer += 2;
6092 /* We have fully parsed the FOR operands. Now build the loop. */
6094 n = push_mri_control (mri_for);
6096 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6107 memcpy (s, initstart, initstop - initstart);
6108 s += initstop - initstart;
6110 memcpy (s, varstart, varstop - varstart);
6111 s += varstop - varstart;
6125 memcpy (s, endstart, endstop - endstart);
6126 s += endstop - endstart;
6128 memcpy (s, varstart, varstop - varstart);
6129 s += varstop - varstart;
6137 sprintf (buf, "blt%s %s", ex, n->bottom);
6139 sprintf (buf, "bgt%s %s", ex, n->bottom);
6142 /* Put together the add or sub instruction used by ENDF. */
6152 memcpy (s, bystart, bystop - bystart);
6153 s += bystop - bystart;
6155 memcpy (s, varstart, varstop - varstart);
6156 s += varstop - varstart;
6162 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6163 ++input_line_pointer;
6166 demand_empty_rest_of_line ();
6169 /* Handle the MRI ENDF pseudo-op. */
6175 if (mri_control_stack == NULL
6176 || mri_control_stack->type != mri_for)
6178 as_bad ("endf without for");
6179 ignore_rest_of_line ();
6183 colon (mri_control_stack->next);
6185 md_assemble (mri_control_stack->incr);
6187 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6188 md_assemble (mri_control_stack->incr);
6190 free (mri_control_stack->incr);
6192 colon (mri_control_stack->bottom);
6198 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6199 ++input_line_pointer;
6202 demand_empty_rest_of_line ();
6205 /* Handle the MRI REPEAT pseudo-op. */
6208 s_mri_repeat (ignore)
6211 struct mri_control_info *n;
6213 n = push_mri_control (mri_repeat);
6217 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6218 ++input_line_pointer;
6220 demand_empty_rest_of_line ();
6223 /* Handle the MRI UNTIL pseudo-op. */
6231 if (mri_control_stack == NULL
6232 || mri_control_stack->type != mri_repeat)
6234 as_bad ("until without repeat");
6235 ignore_rest_of_line ();
6239 colon (mri_control_stack->next);
6241 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6244 parse_mri_control_expression (s, qual, (const char *) NULL,
6245 mri_control_stack->top, '\0');
6247 colon (mri_control_stack->bottom);
6249 input_line_pointer = s;
6255 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6256 ++input_line_pointer;
6259 demand_empty_rest_of_line ();
6262 /* Handle the MRI WHILE pseudo-op. */
6270 struct mri_control_info *n;
6272 s = input_line_pointer;
6273 while (! is_end_of_line[(unsigned char) *s]
6274 && (! flag_mri || *s != '*'))
6277 while (*s == ' ' || *s == '\t')
6279 if (s - input_line_pointer > 1
6282 if (s - input_line_pointer < 2
6283 || strncasecmp (s - 1, "DO", 2) != 0)
6285 as_bad ("missing do");
6286 ignore_rest_of_line ();
6290 n = push_mri_control (mri_while);
6294 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6295 s[1] == '.' ? s[2] : '\0');
6297 input_line_pointer = s + 1;
6298 if (*input_line_pointer == '.')
6299 input_line_pointer += 2;
6303 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6304 ++input_line_pointer;
6307 demand_empty_rest_of_line ();
6310 /* Handle the MRI ENDW pseudo-op. */
6318 if (mri_control_stack == NULL
6319 || mri_control_stack->type != mri_while)
6321 as_bad ("endw without while");
6322 ignore_rest_of_line ();
6326 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
6327 sprintf (buf, "bra %s", mri_control_stack->next);
6331 colon (mri_control_stack->bottom);
6337 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6338 ++input_line_pointer;
6341 demand_empty_rest_of_line ();
6346 * Invocation line includes a switch not recognized by the base assembler.
6347 * See if it's a processor-specific option. These are:
6349 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6350 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6351 * Select the architecture. Instructions or features not
6352 * supported by the selected architecture cause fatal
6353 * errors. More than one may be specified. The default is
6354 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6355 * for -m68000, and -m68882 is a synonym for -m68881.
6356 * -[A]m[c]no-68851, -[A]m[c]no-68881
6357 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6358 * so don't use or document it, but that's the way the parsing
6361 * -pic Indicates PIC.
6362 * -k Indicates PIC. (Sun 3 only.)
6365 * Permit `|' to be used in expressions.
6370 CONST char *md_shortopts = "lSA:m:kQ:V";
6372 CONST char *md_shortopts = "lSA:m:k";
6375 struct option md_longopts[] = {
6376 #define OPTION_PIC (OPTION_MD_BASE)
6377 {"pic", no_argument, NULL, OPTION_PIC},
6378 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6379 {"register-prefix-optional", no_argument, NULL,
6380 OPTION_REGISTER_PREFIX_OPTIONAL},
6381 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6382 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
6383 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6384 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
6385 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6386 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
6387 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6388 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
6389 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6390 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
6391 {NULL, no_argument, NULL, 0}
6393 size_t md_longopts_size = sizeof(md_longopts);
6396 md_parse_option (c, arg)
6402 case 'l': /* -l means keep external to 2 bit offset
6403 rather than 16 bit one */
6404 flag_short_refs = 1;
6407 case 'S': /* -S means that jbsr's always turn into
6409 flag_long_jumps = 1;
6415 /* intentional fall-through */
6418 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
6422 const char *oarg = arg;
6428 if (arg[0] == 'c' && arg[1] == '6')
6431 for (i = 0; i < n_archs; i++)
6432 if (!strcmp (arg, archs[i].name))
6437 as_bad ("unrecognized option `%s'", oarg);
6440 arch = archs[i].arch;
6443 else if (arch == m68851)
6452 if (arg[0] == 'c' && arg[1] == '6')
6455 for (i = 0; i < n_archs; i++)
6456 if (!strcmp (arg, archs[i].name))
6458 unsigned long arch = archs[i].arch;
6459 if (cpu_of_arch (arch))
6460 /* It's a cpu spec. */
6462 current_architecture &= ~m68000up;
6463 current_architecture |= arch;
6465 else if (arch == m68881)
6467 current_architecture |= m68881;
6470 else if (arch == m68851)
6472 current_architecture |= m68851;
6482 as_bad ("unrecognized architecture specification `%s'", arg);
6491 break; /* -pic, Position Independent Code */
6493 case OPTION_REGISTER_PREFIX_OPTIONAL:
6494 flag_reg_prefix_optional = 1;
6495 reg_prefix_optional_seen = 1;
6498 /* -V: SVR4 argument to print version ID. */
6500 print_version_id ();
6503 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6504 should be emitted or not. FIXME: Not implemented. */
6508 case OPTION_BITWISE_OR:
6513 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
6515 for (s = m68k_comment_chars; *s != '\0'; s++)
6519 m68k_comment_chars = n;
6523 case OPTION_BASE_SIZE_DEFAULT_16:
6524 m68k_index_width_default = SIZE_WORD;
6527 case OPTION_BASE_SIZE_DEFAULT_32:
6528 m68k_index_width_default = SIZE_LONG;
6531 case OPTION_DISP_SIZE_DEFAULT_16:
6533 m68k_rel32_from_cmdline = 1;
6536 case OPTION_DISP_SIZE_DEFAULT_32:
6538 m68k_rel32_from_cmdline = 1;
6549 md_show_usage (stream)
6554 -l use 1 word for refs to undefined symbols [default 2]\n\
6555 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6556 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6557 | -mcpu32 | -m5200\n\
6558 specify variant of 680X0 architecture [default 68020]\n\
6559 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6560 target has/lacks floating-point coprocessor\n\
6561 [default yes for 68020, 68030, and cpu32]\n");
6563 -m68851 | -mno-68851\n\
6564 target has/lacks memory-management unit coprocessor\n\
6565 [default yes for 68020 and up]\n\
6566 -pic, -k generate position independent code\n\
6567 -S turn jbsr into jsr\n\
6568 --register-prefix-optional\n\
6569 recognize register names without prefix character\n\
6570 --bitwise-or do not treat `|' as a comment character\n");
6572 --base-size-default-16 base reg without size is 16 bits\n\
6573 --base-size-default-32 base reg without size is 32 bits (default)\n\
6574 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6575 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n");
6580 /* TEST2: Test md_assemble() */
6581 /* Warning, this routine probably doesn't work anymore */
6585 struct m68k_it the_ins;
6593 if (!gets (buf) || !*buf)
6595 if (buf[0] == '|' || buf[1] == '.')
6597 for (cp = buf; *cp; cp++)
6602 memset (&the_ins, '\0', sizeof (the_ins));
6603 m68k_ip (&the_ins, buf);
6606 printf ("Error %s in %s\n", the_ins.error, buf);
6610 printf ("Opcode(%d.%s): ", the_ins.numo, the_ins.args);
6611 for (n = 0; n < the_ins.numo; n++)
6612 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
6614 print_the_insn (&the_ins.opcode[0], stdout);
6615 (void) putchar ('\n');
6617 for (n = 0; n < strlen (the_ins.args) / 2; n++)
6619 if (the_ins.operands[n].error)
6621 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
6624 printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
6625 if (the_ins.operands[n].b_const)
6626 printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
6627 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
6628 if (the_ins.operands[n].b_iadd)
6629 printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
6630 (void) putchar ('\n');
6642 while (*str && *str != ' ')
6644 if (str[-1] == ':' || str[1] == '=')
6651 /* Possible states for relaxation:
6653 0 0 branch offset byte (bra, etc)
6657 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6661 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6668 /* We have no need to default values of symbols. */
6672 md_undefined_symbol (name)
6678 /* Round up a section size to the appropriate boundary. */
6680 md_section_align (segment, size)
6684 return size; /* Byte alignment is fine */
6687 /* Exactly what point is a PC-relative offset relative TO?
6688 On the 68k, it is relative to the address of the first extension
6689 word. The difference between the addresses of the offset and the
6690 first extension word is stored in fx_pcrel_adjust. */
6692 md_pcrel_from (fixP)
6697 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6699 adjust = fixP->fx_pcrel_adjust;
6702 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
6705 #ifndef BFD_ASSEMBLER
6708 tc_coff_symbol_emit_hook (ignore)
6714 tc_coff_sizemachdep (frag)
6717 switch (frag->fr_subtype & 0x3)
6732 /* end of tc-m68k.c */