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] == 'B'
1156 && ! isvar (&opP
->disp
)
1157 && (opP
->disp
.exp
.X_op
!= O_constant
1158 || ! issbyte (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 || ! isword (opP
->disp
.exp
.X_add_number
)))
1165 else if (s
[1] == 'W'
1166 && ! isvar (&opP
->disp
)
1167 && (opP
->disp
.exp
.X_op
!= O_constant
1168 || ! issword (opP
->disp
.exp
.X_add_number
)))
1174 if (opP
->mode
!= IMMED
)
1179 if (opP
->mode
== AREG
1180 || opP
->mode
== CONTROL
1181 || opP
->mode
== FPREG
1182 || opP
->mode
== IMMED
1183 || opP
->mode
== REGLST
1184 || (opP
->mode
!= ABSL
1186 || opP
->reg
== ZPC
)))
1191 if (opP
->mode
== CONTROL
1192 || opP
->mode
== FPREG
1193 || opP
->mode
== REGLST
1194 || opP
->mode
== IMMED
1195 || (opP
->mode
!= ABSL
1197 || opP
->reg
== ZPC
)))
1225 if (opP
->mode
== CONTROL
1226 || opP
->mode
== FPREG
1227 || opP
->mode
== REGLST
)
1232 if (opP
->mode
!= AINC
)
1237 if (opP
->mode
!= ADEC
)
1287 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1308 case '~': /* For now! (JF FOO is this right?) */
1330 if (opP
->mode
!= CONTROL
1331 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1336 if (opP
->mode
!= AREG
)
1341 if (opP
->mode
!= AINDR
)
1346 if (opP
->mode
!= ABSL
1348 && strncmp (instring
, "jbsr", 4) == 0))
1353 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1358 if (opP
->mode
!= DISP
1360 || opP
->reg
> ADDR7
)
1365 if (opP
->mode
!= DREG
)
1370 if (opP
->mode
!= FPREG
)
1375 if (opP
->mode
!= CONTROL
1382 if (opP
->mode
!= CONTROL
1384 || opP
->reg
> last_movec_reg
)
1388 const enum m68k_register
*rp
;
1389 for (rp
= control_regs
; *rp
; rp
++)
1390 if (*rp
== opP
->reg
)
1398 if (opP
->mode
!= IMMED
)
1404 if (opP
->mode
== DREG
1405 || opP
->mode
== AREG
1406 || opP
->mode
== FPREG
)
1415 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1418 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1421 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1429 else if (opP
->mode
== CONTROL
)
1438 opP
->mask
= 1 << 24;
1441 opP
->mask
= 1 << 25;
1444 opP
->mask
= 1 << 26;
1453 else if (opP
->mode
== ABSL
1454 && opP
->disp
.size
== SIZE_UNSPEC
1455 && opP
->disp
.exp
.X_op
== O_constant
)
1457 /* This is what the MRI REG pseudo-op generates. */
1459 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1461 else if (opP
->mode
!= REGLST
)
1463 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1465 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1470 if (opP
->mode
!= IMMED
)
1472 else if (opP
->disp
.exp
.X_op
!= O_constant
1473 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1475 else if (! m68k_quick
1476 && instring
[3] != 'q'
1477 && instring
[4] != 'q')
1482 if (opP
->mode
!= DREG
1483 && opP
->mode
!= IMMED
1484 && opP
->mode
!= ABSL
)
1489 if (opP
->mode
!= IMMED
)
1491 else if (opP
->disp
.exp
.X_op
!= O_constant
1492 || opP
->disp
.exp
.X_add_number
< 1
1493 || opP
->disp
.exp
.X_add_number
> 8)
1495 else if (! m68k_quick
1496 && (strncmp (instring
, "add", 3) == 0
1497 || strncmp (instring
, "sub", 3) == 0)
1498 && instring
[3] != 'q')
1503 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1508 if (opP
->mode
!= AINDR
1509 && (opP
->mode
!= BASE
1511 && opP
->reg
!= ZADDR0
)
1512 || opP
->disp
.exp
.X_op
!= O_absent
1513 || ((opP
->index
.reg
< DATA0
1514 || opP
->index
.reg
> DATA7
)
1515 && (opP
->index
.reg
< ADDR0
1516 || opP
->index
.reg
> ADDR7
))
1517 || opP
->index
.size
!= SIZE_UNSPEC
1518 || opP
->index
.scale
!= 1))
1523 if (opP
->mode
!= CONTROL
1524 || ! (opP
->reg
== FPI
1526 || opP
->reg
== FPC
))
1531 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1536 if (opP
->mode
!= IMMED
)
1538 else if (opP
->disp
.exp
.X_op
!= O_constant
1539 || opP
->disp
.exp
.X_add_number
< 0
1540 || opP
->disp
.exp
.X_add_number
> 7)
1545 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1549 /* JF these are out of order. We could put them
1550 in order if we were willing to put up with
1551 bunches of #ifdef m68851s in the code.
1553 Don't forget that you need these operands
1554 to use 68030 MMU instructions. */
1556 /* Memory addressing mode used by pflushr */
1558 if (opP
->mode
== CONTROL
1559 || opP
->mode
== FPREG
1560 || opP
->mode
== DREG
1561 || opP
->mode
== AREG
1562 || opP
->mode
== REGLST
)
1564 /* We should accept immediate operands, but they
1565 supposedly have to be quad word, and we don't
1566 handle that. I would like to see what a Motorola
1567 assembler does before doing something here. */
1568 if (opP
->mode
== IMMED
)
1573 if (opP
->mode
!= CONTROL
1574 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1579 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1584 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1589 if (opP
->mode
!= CONTROL
1592 && opP
->reg
!= SCC
))
1597 if (opP
->mode
!= CONTROL
1603 if (opP
->mode
!= CONTROL
1606 && opP
->reg
!= CRP
))
1611 if (opP
->mode
!= CONTROL
1612 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1613 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1618 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1623 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1628 if (opP
->mode
!= CONTROL
1635 } /* not a cache specifier. */
1639 if (opP
->mode
!= ABSL
)
1645 } /* switch on type of operand */
1649 } /* for each operand */
1650 } /* if immediately wrong */
1657 opcode
= opcode
->m_next
;
1662 && !(ok_arch
& current_architecture
))
1667 "invalid instruction for this architecture; needs ");
1668 cp
= buf
+ strlen (buf
);
1672 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1675 strcpy (cp
, "mmu (68030 or 68851)");
1678 strcpy (cp
, "68020 or higher");
1681 strcpy (cp
, "68000 or higher");
1684 strcpy (cp
, "68010 or higher");
1688 int got_one
= 0, idx
;
1689 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1692 if ((archs
[idx
].arch
& ok_arch
)
1693 && ! archs
[idx
].alias
)
1697 strcpy (cp
, " or ");
1701 strcpy (cp
, archs
[idx
].name
);
1707 cp
= xmalloc (strlen (buf
) + 1);
1712 the_ins
.error
= "operands mismatch";
1714 } /* Fell off the end */
1719 /* now assemble it */
1721 the_ins
.args
= opcode
->m_operands
;
1722 the_ins
.numargs
= opcode
->m_opnum
;
1723 the_ins
.numo
= opcode
->m_codenum
;
1724 the_ins
.opcode
[0] = getone (opcode
);
1725 the_ins
.opcode
[1] = gettwo (opcode
);
1727 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1729 /* This switch is a doozy.
1730 Watch the first step; its a big one! */
1757 tmpreg
= 0x3c; /* 7.4 */
1758 if (strchr ("bwl", s
[1]))
1759 nextword
= get_num (&opP
->disp
, 80);
1761 nextword
= get_num (&opP
->disp
, 0);
1762 if (isvar (&opP
->disp
))
1763 add_fix (s
[1], &opP
->disp
, 0, 0);
1767 if (!isbyte (nextword
))
1768 opP
->error
= "operand out of range";
1773 if (!isword (nextword
))
1774 opP
->error
= "operand out of range";
1779 if (!issword (nextword
))
1780 opP
->error
= "operand out of range";
1785 addword (nextword
>> 16);
1812 /* We gotta put out some float */
1813 if (op (&opP
->disp
) != O_big
)
1818 /* Can other cases happen here? */
1819 if (op (&opP
->disp
) != O_constant
)
1822 val
= (valueT
) offs (&opP
->disp
);
1826 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1827 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1831 offs (&opP
->disp
) = gencnt
;
1833 if (offs (&opP
->disp
) > 0)
1835 if (offs (&opP
->disp
) > baseo
)
1837 as_warn ("Bignum too big for %c format; truncated",
1839 offs (&opP
->disp
) = baseo
;
1841 baseo
-= offs (&opP
->disp
);
1844 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1845 offs (&opP
->disp
)--;
1850 gen_to_words (words
, baseo
, (long) outro
);
1851 for (wordp
= words
; baseo
--; wordp
++)
1855 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1858 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1861 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1864 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1867 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1871 nextword
= get_num (&opP
->disp
, 80);
1874 && ! isvar (&opP
->disp
)
1877 opP
->disp
.exp
.X_op
= O_symbol
;
1878 #ifndef BFD_ASSEMBLER
1879 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1881 opP
->disp
.exp
.X_add_symbol
=
1882 section_symbol (absolute_section
);
1886 /* Force into index mode. Hope this works */
1888 /* We do the first bit for 32-bit displacements, and the
1889 second bit for 16 bit ones. It is possible that we
1890 should make the default be WORD instead of LONG, but
1891 I think that'd break GCC, so we put up with a little
1892 inefficiency for the sake of working output. */
1894 if (!issword (nextword
)
1895 || (isvar (&opP
->disp
)
1896 && ((opP
->disp
.size
== SIZE_UNSPEC
1897 && flag_short_refs
== 0
1898 && cpu_of_arch (current_architecture
) >= m68020
)
1899 || opP
->disp
.size
== SIZE_LONG
)))
1901 if (cpu_of_arch (current_architecture
) < m68020
)
1903 "displacement too large for this architecture; needs 68020 or higher";
1905 tmpreg
= 0x3B; /* 7.3 */
1907 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1908 if (isvar (&opP
->disp
))
1912 if (opP
->disp
.size
== SIZE_LONG
1914 /* If the displacement needs pic
1915 relocation it cannot be relaxed. */
1916 || opP
->disp
.pic_reloc
!= pic_none
1921 add_fix ('l', &opP
->disp
, 1, 2);
1925 add_frag (adds (&opP
->disp
),
1927 TAB (PCLEA
, SZ_UNDEF
));
1934 add_fix ('l', &opP
->disp
, 0, 0);
1939 addword (nextword
>> 16);
1944 tmpreg
= 0x3A; /* 7.2 */
1946 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1948 if (isvar (&opP
->disp
))
1952 add_fix ('w', &opP
->disp
, 1, 0);
1955 add_fix ('w', &opP
->disp
, 0, 0);
1965 baseo
= get_num (&opP
->disp
, 80);
1966 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1967 outro
= get_num (&opP
->odisp
, 80);
1968 /* Figure out the `addressing mode'.
1969 Also turn on the BASE_DISABLE bit, if needed. */
1970 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1972 tmpreg
= 0x3b; /* 7.3 */
1973 if (opP
->reg
== ZPC
)
1976 else if (opP
->reg
== 0)
1979 tmpreg
= 0x30; /* 6.garbage */
1981 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
1984 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
1987 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1989 siz1
= opP
->disp
.size
;
1990 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1991 siz2
= opP
->odisp
.size
;
1995 /* Index register stuff */
1996 if (opP
->index
.reg
!= 0
1997 && opP
->index
.reg
>= DATA
1998 && opP
->index
.reg
<= ADDR7
)
2000 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2002 if (opP
->index
.size
== SIZE_LONG
2003 || (opP
->index
.size
== SIZE_UNSPEC
2004 && m68k_index_width_default
== SIZE_LONG
))
2007 if ((opP
->index
.scale
!= 1
2008 && cpu_of_arch (current_architecture
) < m68020
)
2009 || (opP
->index
.scale
== 8
2010 && current_architecture
== mcf5200
))
2013 "scale factor invalid on this architecture; needs cpu32 or 68020 or higher";
2016 switch (opP
->index
.scale
)
2033 GET US OUT OF HERE! */
2035 /* Must be INDEX, with an index register. Address
2036 register cannot be ZERO-PC, and either :b was
2037 forced, or we know it will fit. For a 68000 or
2038 68010, force this mode anyways, because the
2039 larger modes aren't supported. */
2040 if (opP
->mode
== BASE
2041 && ((opP
->reg
>= ADDR0
2042 && opP
->reg
<= ADDR7
)
2045 if (siz1
== SIZE_BYTE
2046 || cpu_of_arch (current_architecture
) < m68020
2047 || (siz1
== SIZE_UNSPEC
2048 && ! isvar (&opP
->disp
)
2049 && issbyte (baseo
)))
2051 nextword
+= baseo
& 0xff;
2053 if (isvar (&opP
->disp
))
2055 /* Do a byte relocation. If it doesn't
2056 fit (possible on m68000) let the
2057 fixup processing complain later. */
2059 add_fix ('B', &opP
->disp
, 1, 1);
2061 add_fix ('B', &opP
->disp
, 0, 0);
2063 else if (siz1
!= SIZE_BYTE
)
2065 if (siz1
!= SIZE_UNSPEC
)
2066 as_warn ("Forcing byte displacement");
2067 if (! issbyte (baseo
))
2068 opP
->error
= "byte displacement out of range";
2073 else if (siz1
== SIZE_UNSPEC
2075 && isvar (&opP
->disp
)
2076 && subs (&opP
->disp
) == NULL
2078 /* If the displacement needs pic
2079 relocation it cannot be relaxed. */
2080 && opP
->disp
.pic_reloc
== pic_none
2084 nextword
+= baseo
& 0xff;
2086 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2087 TAB (PCINDEX
, SZ_UNDEF
));
2095 nextword
|= 0x40; /* No index reg */
2096 if (opP
->index
.reg
>= ZDATA0
2097 && opP
->index
.reg
<= ZDATA7
)
2098 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2099 else if (opP
->index
.reg
>= ZADDR0
2100 || opP
->index
.reg
<= ZADDR7
)
2101 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2104 /* It isn't simple. */
2106 if (cpu_of_arch (current_architecture
) < m68020
)
2108 "invalid operand mode for this architecture; needs 68020 or higher";
2111 /* If the guy specified a width, we assume that it is
2112 wide enough. Maybe it isn't. If so, we lose. */
2116 if (isvar (&opP
->disp
)
2118 : ! issword (baseo
))
2123 else if (! isvar (&opP
->disp
) && baseo
== 0)
2132 as_warn (":b not permitted; defaulting to :w");
2142 /* Figure out innner displacement stuff */
2143 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2145 if (cpu_of_arch (current_architecture
) & cpu32
)
2146 opP
->error
= "invalid operand mode for this architecture; needs 68020 or higher";
2150 if (isvar (&opP
->odisp
)
2152 : ! issword (outro
))
2157 else if (! isvar (&opP
->odisp
) && outro
== 0)
2166 as_warn (":b not permitted; defaulting to :w");
2175 if (opP
->mode
== POST
2176 && (nextword
& 0x40) == 0)
2181 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2183 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2184 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2186 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2188 if (siz1
== SIZE_LONG
)
2189 addword (baseo
>> 16);
2190 if (siz1
!= SIZE_UNSPEC
)
2193 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2194 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2195 if (siz2
== SIZE_LONG
)
2196 addword (outro
>> 16);
2197 if (siz2
!= SIZE_UNSPEC
)
2203 nextword
= get_num (&opP
->disp
, 80);
2204 switch (opP
->disp
.size
)
2209 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2211 tmpreg
= 0x38; /* 7.0 */
2215 /* Don't generate pc relative code on 68010 and
2217 if (isvar (&opP
->disp
)
2218 && !subs (&opP
->disp
)
2219 && adds (&opP
->disp
)
2221 /* If the displacement needs pic relocation it
2222 cannot be relaxed. */
2223 && opP
->disp
.pic_reloc
== pic_none
2225 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2226 && cpu_of_arch (current_architecture
) >= m68020
2228 && !strchr ("~%&$?", s
[0]))
2230 tmpreg
= 0x3A; /* 7.2 */
2231 add_frag (adds (&opP
->disp
),
2233 TAB (PCREL
, SZ_UNDEF
));
2236 /* Fall through into long */
2238 if (isvar (&opP
->disp
))
2239 add_fix ('l', &opP
->disp
, 0, 0);
2241 tmpreg
= 0x39;/* 7.1 mode */
2242 addword (nextword
>> 16);
2246 case SIZE_WORD
: /* Word */
2247 if (isvar (&opP
->disp
))
2248 add_fix ('w', &opP
->disp
, 0, 0);
2250 tmpreg
= 0x38;/* 7.0 mode */
2258 as_bad ("unknown/incorrect operand");
2261 install_gen_operand (s
[1], tmpreg
);
2267 { /* JF: I hate floating point! */
2282 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2283 if (isvar (&opP
->disp
))
2284 add_fix (s
[1], &opP
->disp
, 0, 0);
2287 case 'b': /* Danger: These do no check for
2288 certain types of overflow.
2290 if (!isbyte (tmpreg
))
2291 opP
->error
= "out of range";
2292 insop (tmpreg
, opcode
);
2293 if (isvar (&opP
->disp
))
2294 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2295 (opcode
->m_codenum
) * 2 + 1;
2298 if (!issbyte (tmpreg
))
2299 opP
->error
= "out of range";
2300 opcode
->m_opcode
|= tmpreg
;
2301 if (isvar (&opP
->disp
))
2302 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2305 if (!isword (tmpreg
))
2306 opP
->error
= "out of range";
2307 insop (tmpreg
, opcode
);
2308 if (isvar (&opP
->disp
))
2309 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2312 if (!issword (tmpreg
))
2313 opP
->error
= "out of range";
2314 insop (tmpreg
, opcode
);
2315 if (isvar (&opP
->disp
))
2316 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2319 /* Because of the way insop works, we put these two out
2321 insop (tmpreg
, opcode
);
2322 insop (tmpreg
>> 16, opcode
);
2323 if (isvar (&opP
->disp
))
2324 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2330 install_operand (s
[1], tmpreg
);
2341 install_operand (s
[1], opP
->reg
- ADDR
);
2345 tmpreg
= get_num (&opP
->disp
, 80);
2349 /* The pc_fix argument winds up in fx_pcrel_adjust,
2350 which is a char, and may therefore be unsigned. We
2351 want to pass -1, but we pass 64 instead, and convert
2352 back in md_pcrel_from. */
2353 add_fix ('B', &opP
->disp
, 1, 64);
2356 add_fix ('w', &opP
->disp
, 1, 0);
2361 if (cpu_of_arch (current_architecture
) < m68020
)
2362 as_warn ("Can't use long branches on 68000/68010");
2363 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2364 add_fix ('l', &opP
->disp
, 1, 0);
2369 if (subs (&opP
->disp
)) /* We can't relax it */
2373 /* If the displacement needs pic relocation it cannot be
2375 if (opP
->disp
.pic_reloc
!= pic_none
)
2379 /* This could either be a symbol, or an absolute
2380 address. No matter, the frag hacking will finger it
2381 out. Not quite: it can't switch from BRANCH to
2382 BCC68000 for the case where opnd is absolute (it
2383 needs to use the 68000 hack since no conditional abs
2385 if (((cpu_of_arch (current_architecture
) < m68020
)
2386 || (0 == adds (&opP
->disp
)))
2387 && (the_ins
.opcode
[0] >= 0x6200)
2388 && (the_ins
.opcode
[0] <= 0x6f00))
2389 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2390 TAB (BCC68000
, SZ_UNDEF
));
2392 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2393 TAB (ABRANCH
, SZ_UNDEF
));
2396 if (isvar (&opP
->disp
))
2399 /* check for DBcc instruction */
2400 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2402 /* size varies if patch */
2403 /* needed for long form */
2404 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2405 TAB (DBCC
, SZ_UNDEF
));
2409 add_fix ('w', &opP
->disp
, 1, 0);
2413 case 'C': /* Fixed size LONG coproc branches */
2414 add_fix ('l', &opP
->disp
, 1, 0);
2418 case 'c': /* Var size Coprocesssor branches */
2419 if (subs (&opP
->disp
))
2421 add_fix ('l', &opP
->disp
, 1, 0);
2422 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2424 else if (adds (&opP
->disp
))
2425 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2426 TAB (FBRANCH
, SZ_UNDEF
));
2429 /* add_frag((symbolS *) 0, offs(&opP->disp),
2430 TAB(FBRANCH,SHORT)); */
2431 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2432 add_fix ('l', &opP
->disp
, 1, 0);
2442 case 'C': /* Ignore it */
2445 case 'd': /* JF this is a kludge */
2446 install_operand ('s', opP
->reg
- ADDR
);
2447 tmpreg
= get_num (&opP
->disp
, 80);
2448 if (!issword (tmpreg
))
2450 as_warn ("Expression out of range, using 0");
2457 install_operand (s
[1], opP
->reg
- DATA
);
2461 install_operand (s
[1], opP
->reg
- FP0
);
2465 tmpreg
= opP
->reg
- COP0
;
2466 install_operand (s
[1], tmpreg
);
2469 case 'J': /* JF foo */
2542 install_operand (s
[1], tmpreg
);
2546 tmpreg
= get_num (&opP
->disp
, 55);
2547 install_operand (s
[1], tmpreg
& 0x7f);
2554 if (tmpreg
& 0x7FF0000)
2555 as_bad ("Floating point register in register list");
2556 insop (reverse_16_bits (tmpreg
), opcode
);
2560 if (tmpreg
& 0x700FFFF)
2561 as_bad ("Wrong register in floating-point reglist");
2562 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2570 if (tmpreg
& 0x7FF0000)
2571 as_bad ("Floating point register in register list");
2572 insop (tmpreg
, opcode
);
2574 else if (s
[1] == '8')
2576 if (tmpreg
& 0x0FFFFFF)
2577 as_bad ("incorrect register in reglist");
2578 install_operand (s
[1], tmpreg
>> 24);
2582 if (tmpreg
& 0x700FFFF)
2583 as_bad ("wrong register in floating-point reglist");
2585 install_operand (s
[1], tmpreg
>> 16);
2590 install_operand (s
[1], get_num (&opP
->disp
, 60));
2594 tmpreg
= ((opP
->mode
== DREG
)
2595 ? 0x20 + opP
->reg
- DATA
2596 : (get_num (&opP
->disp
, 40) & 0x1F));
2597 install_operand (s
[1], tmpreg
);
2601 tmpreg
= get_num (&opP
->disp
, 10);
2604 install_operand (s
[1], tmpreg
);
2608 /* This depends on the fact that ADDR registers are eight
2609 more than their corresponding DATA regs, so the result
2610 will have the ADDR_REG bit set */
2611 install_operand (s
[1], opP
->reg
- DATA
);
2615 if (opP
->mode
== AINDR
)
2616 install_operand (s
[1], opP
->reg
- DATA
);
2618 install_operand (s
[1], opP
->index
.reg
- DATA
);
2622 if (opP
->reg
== FPI
)
2624 else if (opP
->reg
== FPS
)
2626 else if (opP
->reg
== FPC
)
2630 install_operand (s
[1], tmpreg
);
2633 case 'S': /* Ignore it */
2637 install_operand (s
[1], get_num (&opP
->disp
, 30));
2640 case 'U': /* Ignore it */
2659 as_fatal ("failed sanity check");
2660 } /* switch on cache token */
2661 install_operand (s
[1], tmpreg
);
2664 /* JF: These are out of order, I fear. */
2677 install_operand (s
[1], tmpreg
);
2703 install_operand (s
[1], tmpreg
);
2707 if (opP
->reg
== VAL
)
2726 install_operand (s
[1], tmpreg
);
2740 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2751 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2757 install_operand (s
[1], tmpreg
);
2760 know (opP
->reg
== PSR
);
2763 know (opP
->reg
== PCSR
);
2778 install_operand (s
[1], tmpreg
);
2781 tmpreg
= get_num (&opP
->disp
, 20);
2782 install_operand (s
[1], tmpreg
);
2784 case '_': /* used only for move16 absolute 32-bit address */
2785 tmpreg
= get_num (&opP
->disp
, 80);
2786 addword (tmpreg
>> 16);
2787 addword (tmpreg
& 0xFFFF);
2794 /* By the time whe get here (FINALLY) the_ins contains the complete
2795 instruction, ready to be emitted. . . */
2799 reverse_16_bits (in
)
2805 static int mask
[16] =
2807 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2808 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2810 for (n
= 0; n
< 16; n
++)
2813 out
|= mask
[15 - n
];
2816 } /* reverse_16_bits() */
2825 static int mask
[8] =
2827 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2830 for (n
= 0; n
< 8; n
++)
2836 } /* reverse_8_bits() */
2838 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2839 (that value is chosen in the frag_var call in md_assemble). TYPE
2840 is the subtype of the frag to be generated; its primary type is
2841 rs_machine_dependent.
2843 The TYPE parameter is also used by md_convert_frag_1 and
2844 md_estimate_size_before_relax. The appropriate type of fixup will
2845 be emitted by md_convert_frag_1.
2847 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2849 install_operand (mode
, val
)
2856 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2859 the_ins
.opcode
[0] |= val
<< 9;
2862 the_ins
.opcode
[1] |= val
<< 12;
2865 the_ins
.opcode
[1] |= val
<< 6;
2868 the_ins
.opcode
[1] |= val
;
2871 the_ins
.opcode
[2] |= val
<< 12;
2874 the_ins
.opcode
[2] |= val
<< 6;
2877 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2878 three words long! */
2880 the_ins
.opcode
[2] |= val
;
2883 the_ins
.opcode
[1] |= val
<< 7;
2886 the_ins
.opcode
[1] |= val
<< 10;
2890 the_ins
.opcode
[1] |= val
<< 5;
2895 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2898 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2901 the_ins
.opcode
[0] |= val
= 0xff;
2904 the_ins
.opcode
[0] |= val
<< 9;
2907 the_ins
.opcode
[1] |= val
;
2910 the_ins
.opcode
[1] |= val
;
2911 the_ins
.numo
++; /* What a hack */
2914 the_ins
.opcode
[1] |= val
<< 4;
2922 the_ins
.opcode
[0] |= (val
<< 6);
2925 the_ins
.opcode
[1] = (val
>> 16);
2926 the_ins
.opcode
[2] = val
& 0xffff;
2930 as_fatal ("failed sanity check.");
2932 } /* install_operand() */
2935 install_gen_operand (mode
, val
)
2942 the_ins
.opcode
[0] |= val
;
2945 /* This is a kludge!!! */
2946 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2955 the_ins
.opcode
[0] |= val
;
2957 /* more stuff goes here */
2959 as_fatal ("failed sanity check.");
2961 } /* install_gen_operand() */
2964 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2965 * then deal with the bitfield hack.
2969 crack_operand (str
, opP
)
2971 register struct m68k_op
*opP
;
2973 register int parens
;
2975 register char *beg_str
;
2983 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
2989 else if (*str
== ')')
2993 opP
->error
= "Extra )";
2999 if (flag_mri
&& *str
== '\'')
3000 inquote
= ! inquote
;
3002 if (!*str
&& parens
)
3004 opP
->error
= "Missing )";
3009 if (m68k_ip_op (beg_str
, opP
) != 0)
3016 c
= *++str
; /* JF bitfield hack */
3021 as_bad ("Missing operand");
3026 /* This is the guts of the machine-dependent assembler. STR points to a
3027 machine dependent instruction. This function is supposed to emit
3028 the frags/bytes it assembles to.
3032 insert_reg (regname
, regnum
)
3039 #ifdef REGISTER_PREFIX
3040 if (!flag_reg_prefix_optional
)
3042 buf
[0] = REGISTER_PREFIX
;
3043 strcpy (buf
+ 1, regname
);
3048 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3049 &zero_address_frag
));
3051 for (i
= 0; regname
[i
]; i
++)
3052 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3055 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3056 &zero_address_frag
));
3065 static const struct init_entry init_table
[] =
3120 /* control registers */
3121 { "sfc", SFC
}, /* Source Function Code */
3123 { "dfc", DFC
}, /* Destination Function Code */
3125 { "cacr", CACR
}, /* Cache Control Register */
3126 { "caar", CAAR
}, /* Cache Address Register */
3128 { "usp", USP
}, /* User Stack Pointer */
3129 { "vbr", VBR
}, /* Vector Base Register */
3130 { "msp", MSP
}, /* Master Stack Pointer */
3131 { "isp", ISP
}, /* Interrupt Stack Pointer */
3133 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0 */
3134 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1 */
3135 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0 */
3136 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1 */
3138 /* 68ec040 versions of same */
3139 { "iacr0", ITT0
}, /* Instruction Access Control Register 0 */
3140 { "iacr1", ITT1
}, /* Instruction Access Control Register 0 */
3141 { "dacr0", DTT0
}, /* Data Access Control Register 0 */
3142 { "dacr1", DTT1
}, /* Data Access Control Register 0 */
3144 /* mcf5200 versions of same. The ColdFire programmer's reference
3145 manual indicated that the order is 2,3,0,1, but Ken Rose
3146 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3147 { "acr0", ITT0
}, /* Access Control Unit 0 */
3148 { "acr1", ITT1
}, /* Access Control Unit 1 */
3149 { "acr2", DTT0
}, /* Access Control Unit 2 */
3150 { "acr3", DTT1
}, /* Access Control Unit 3 */
3152 { "tc", TC
}, /* MMU Translation Control Register */
3155 { "mmusr", MMUSR
}, /* MMU Status Register */
3156 { "srp", SRP
}, /* User Root Pointer */
3157 { "urp", URP
}, /* Supervisor Root Pointer */
3162 { "rombar", ROMBAR
}, /* ROM Base Address Register */
3163 { "rambar0", RAMBAR0
}, /* ROM Base Address Register */
3164 { "rambar1", RAMBAR1
}, /* ROM Base Address Register */
3165 { "mbar", MBAR
}, /* Module Base Address Register */
3166 /* end of control registers */
3200 /* 68ec030 versions of same */
3203 /* 68ec030 access control unit, identical to 030 MMU status reg */
3206 /* Suppressed data and address registers. */
3231 for (i
= 0; init_table
[i
].name
; i
++)
3232 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3235 static int no_68851
, no_68881
;
3238 /* a.out machine type. Default to 68020. */
3239 int m68k_aout_machtype
= 2;
3251 int shorts_this_frag
;
3254 /* In MRI mode, the instruction and operands are separated by a
3255 space. Anything following the operands is a comment. The label
3256 has already been removed. */
3264 for (s
= str
; *s
!= '\0'; s
++)
3266 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3284 inquote
= ! inquote
;
3289 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3294 for (n
= 0; n
< the_ins
.numargs
; n
++)
3295 if (the_ins
.operands
[n
].error
)
3297 er
= the_ins
.operands
[n
].error
;
3303 as_bad ("%s -- statement `%s' ignored", er
, str
);
3307 if (the_ins
.nfrag
== 0)
3309 /* No frag hacking involved; just put it out */
3310 toP
= frag_more (2 * the_ins
.numo
);
3311 fromP
= &the_ins
.opcode
[0];
3312 for (m
= the_ins
.numo
; m
; --m
)
3314 md_number_to_chars (toP
, (long) (*fromP
), 2);
3318 /* put out symbol-dependent info */
3319 for (m
= 0; m
< the_ins
.nrel
; m
++)
3321 switch (the_ins
.reloc
[m
].wid
)
3339 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3340 the_ins
.reloc
[m
].wid
);
3343 fixP
= fix_new_exp (frag_now
,
3344 ((toP
- frag_now
->fr_literal
)
3345 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3347 &the_ins
.reloc
[m
].exp
,
3348 the_ins
.reloc
[m
].pcrel
,
3349 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3350 the_ins
.reloc
[m
].pic_reloc
));
3351 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3352 if (the_ins
.reloc
[m
].wid
== 'B')
3353 fixP
->fx_signed
= 1;
3358 /* There's some frag hacking */
3359 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3364 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3366 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3367 toP
= frag_more (wid
);
3369 shorts_this_frag
= 0;
3370 for (m
= wid
/ 2; m
; --m
)
3372 md_number_to_chars (toP
, (long) (*fromP
), 2);
3377 for (m
= 0; m
< the_ins
.nrel
; m
++)
3379 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3381 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3384 wid
= the_ins
.reloc
[m
].wid
;
3387 the_ins
.reloc
[m
].wid
= 0;
3388 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3390 fixP
= fix_new_exp (frag_now
,
3391 ((toP
- frag_now
->fr_literal
)
3392 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3394 &the_ins
.reloc
[m
].exp
,
3395 the_ins
.reloc
[m
].pcrel
,
3396 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3397 the_ins
.reloc
[m
].pic_reloc
));
3398 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3400 (void) frag_var (rs_machine_dependent
, 10, 0,
3401 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3402 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3404 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3405 shorts_this_frag
= 0;
3408 toP
= frag_more (n
* sizeof (short));
3411 md_number_to_chars (toP
, (long) (*fromP
), 2);
3417 for (m
= 0; m
< the_ins
.nrel
; m
++)
3421 wid
= the_ins
.reloc
[m
].wid
;
3424 the_ins
.reloc
[m
].wid
= 0;
3425 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3427 fixP
= fix_new_exp (frag_now
,
3428 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3429 - shorts_this_frag
* 2),
3431 &the_ins
.reloc
[m
].exp
,
3432 the_ins
.reloc
[m
].pcrel
,
3433 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3434 the_ins
.reloc
[m
].pic_reloc
));
3435 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3443 * md_begin -- set up hash tables with 68000 instructions.
3444 * similar to what the vax assembler does. ---phr
3446 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3447 a copy of it at runtime, adding in the information we want but isn't
3448 there. I think it'd be better to have an awk script hack the table
3449 at compile time. Or even just xstr the table and use it as-is. But
3450 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3453 register const struct m68k_opcode
*ins
;
3454 register struct m68k_incant
*hack
, *slak
;
3455 register const char *retval
= 0; /* empty string, or error msg text */
3456 register unsigned int i
;
3461 flag_reg_prefix_optional
= 1;
3463 if (! m68k_rel32_from_cmdline
)
3467 op_hash
= hash_new ();
3469 obstack_begin (&robyn
, 4000);
3470 for (i
= 0; i
< m68k_numopcodes
; i
++)
3472 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3475 ins
= &m68k_opcodes
[i
];
3476 /* We *could* ignore insns that don't match our arch here
3477 but just leaving them out of the hash. */
3478 slak
->m_operands
= ins
->args
;
3479 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3480 slak
->m_arch
= ins
->arch
;
3481 slak
->m_opcode
= ins
->opcode
;
3482 /* This is kludgey */
3483 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3484 if (i
+ 1 != m68k_numopcodes
3485 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3487 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3492 slak
= slak
->m_next
;
3496 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3498 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3501 for (i
= 0; i
< m68k_numaliases
; i
++)
3503 const char *name
= m68k_opcode_aliases
[i
].primary
;
3504 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3505 PTR val
= hash_find (op_hash
, name
);
3507 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3508 retval
= hash_insert (op_hash
, alias
, val
);
3510 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3513 /* In MRI mode, all unsized branches are variable sized. Normally,
3514 they are word sized. */
3517 static struct m68k_opcode_alias mri_aliases
[] =
3537 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3539 const char *name
= mri_aliases
[i
].primary
;
3540 const char *alias
= mri_aliases
[i
].alias
;
3541 PTR val
= hash_find (op_hash
, name
);
3543 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3544 retval
= hash_jam (op_hash
, alias
, val
);
3546 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3550 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3551 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3553 for (i
= 0; i
< sizeof (notend_table
); i
++)
3555 notend_table
[i
] = 0;
3556 alt_notend_table
[i
] = 0;
3558 notend_table
[','] = 1;
3559 notend_table
['{'] = 1;
3560 notend_table
['}'] = 1;
3561 alt_notend_table
['a'] = 1;
3562 alt_notend_table
['A'] = 1;
3563 alt_notend_table
['d'] = 1;
3564 alt_notend_table
['D'] = 1;
3565 alt_notend_table
['#'] = 1;
3566 alt_notend_table
['&'] = 1;
3567 alt_notend_table
['f'] = 1;
3568 alt_notend_table
['F'] = 1;
3569 #ifdef REGISTER_PREFIX
3570 alt_notend_table
[REGISTER_PREFIX
] = 1;
3573 /* We need to put '(' in alt_notend_table to handle
3574 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3576 alt_notend_table
['('] = 1;
3578 /* We need to put '@' in alt_notend_table to handle
3579 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3581 alt_notend_table
['@'] = 1;
3583 /* We need to put digits in alt_notend_table to handle
3584 bfextu %d0{24:1},%d0
3586 alt_notend_table
['0'] = 1;
3587 alt_notend_table
['1'] = 1;
3588 alt_notend_table
['2'] = 1;
3589 alt_notend_table
['3'] = 1;
3590 alt_notend_table
['4'] = 1;
3591 alt_notend_table
['5'] = 1;
3592 alt_notend_table
['6'] = 1;
3593 alt_notend_table
['7'] = 1;
3594 alt_notend_table
['8'] = 1;
3595 alt_notend_table
['9'] = 1;
3597 #ifndef MIT_SYNTAX_ONLY
3598 /* Insert pseudo ops, these have to go into the opcode table since
3599 gas expects pseudo ops to start with a dot */
3602 while (mote_pseudo_table
[n
].poc_name
)
3604 hack
= (struct m68k_incant
*)
3605 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3606 hash_insert (op_hash
,
3607 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3608 hack
->m_operands
= 0;
3618 record_alignment (text_section
, 2);
3619 record_alignment (data_section
, 2);
3620 record_alignment (bss_section
, 2);
3625 select_control_regs ()
3627 /* Note which set of "movec" control registers is available. */
3628 switch (cpu_of_arch (current_architecture
))
3631 control_regs
= m68000_control_regs
;
3634 control_regs
= m68010_control_regs
;
3638 control_regs
= m68020_control_regs
;
3641 control_regs
= m68040_control_regs
;
3644 control_regs
= m68060_control_regs
;
3647 control_regs
= cpu32_control_regs
;
3650 control_regs
= mcf5200_control_regs
;
3658 m68k_init_after_args ()
3660 if (cpu_of_arch (current_architecture
) == 0)
3663 const char *default_cpu
= TARGET_CPU
;
3665 if (*default_cpu
== 'm')
3667 for (i
= 0; i
< n_archs
; i
++)
3668 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3672 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3673 current_architecture
|= m68020
;
3676 current_architecture
|= archs
[i
].arch
;
3678 /* Permit m68881 specification with all cpus; those that can't work
3679 with a coprocessor could be doing emulation. */
3680 if (current_architecture
& m68851
)
3682 if (current_architecture
& m68040
)
3684 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3687 /* What other incompatibilities could we check for? */
3689 /* Toss in some default assumptions about coprocessors. */
3691 && (cpu_of_arch (current_architecture
)
3692 /* Can CPU32 have a 68881 coprocessor?? */
3693 & (m68020
| m68030
| cpu32
)))
3695 current_architecture
|= m68881
;
3698 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3699 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3701 current_architecture
|= m68851
;
3703 if (no_68881
&& (current_architecture
& m68881
))
3704 as_bad ("options for 68881 and no-68881 both given");
3705 if (no_68851
&& (current_architecture
& m68851
))
3706 as_bad ("options for 68851 and no-68851 both given");
3709 /* Work out the magic number. This isn't very general. */
3710 if (current_architecture
& m68000
)
3711 m68k_aout_machtype
= 0;
3712 else if (current_architecture
& m68010
)
3713 m68k_aout_machtype
= 1;
3714 else if (current_architecture
& m68020
)
3715 m68k_aout_machtype
= 2;
3717 m68k_aout_machtype
= 2;
3720 /* Note which set of "movec" control registers is available. */
3721 select_control_regs ();
3723 if (cpu_of_arch (current_architecture
) < m68020
)
3724 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3727 /* This is called if we go in or out of MRI mode because of the .mri
3731 m68k_mri_mode_change (on
)
3736 if (! flag_reg_prefix_optional
)
3738 flag_reg_prefix_optional
= 1;
3739 #ifdef REGISTER_PREFIX
3744 if (! m68k_rel32_from_cmdline
)
3749 if (! reg_prefix_optional_seen
)
3751 #ifdef REGISTER_PREFIX_OPTIONAL
3752 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
3754 flag_reg_prefix_optional
= 0;
3756 #ifdef REGISTER_PREFIX
3761 if (! m68k_rel32_from_cmdline
)
3766 /* Equal to MAX_PRECISION in atof-ieee.c */
3767 #define MAX_LITTLENUMS 6
3769 /* Turn a string in input_line_pointer into a floating point constant
3770 of type type, and store the appropriate bytes in *litP. The number
3771 of LITTLENUMS emitted is stored in *sizeP . An error message is
3772 returned, or NULL on OK. */
3775 md_atof (type
, litP
, sizeP
)
3781 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3782 LITTLENUM_TYPE
*wordP
;
3814 return "Bad call to MD_ATOF()";
3816 t
= atof_ieee (input_line_pointer
, type
, words
);
3818 input_line_pointer
= t
;
3820 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3821 for (wordP
= words
; prec
--;)
3823 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3824 litP
+= sizeof (LITTLENUM_TYPE
);
3830 md_number_to_chars (buf
, val
, n
)
3835 number_to_chars_bigendian (buf
, val
, n
);
3839 md_apply_fix_2 (fixP
, val
)
3843 addressT upper_limit
;
3844 offsetT lower_limit
;
3846 /* This is unnecessary but it convinces the native rs6000 compiler
3847 to generate the code we want. */
3848 char *buf
= fixP
->fx_frag
->fr_literal
;
3849 buf
+= fixP
->fx_where
;
3850 /* end ibm compiler workaround */
3852 if (val
& 0x80000000)
3853 val
|= ~(addressT
)0x7fffffff;
3860 memset (buf
, 0, fixP
->fx_size
);
3861 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
3866 switch (fixP
->fx_size
)
3868 /* The cast to offsetT below are necessary to make code correct for
3869 machines where ints are smaller than offsetT */
3873 lower_limit
= - (offsetT
) 0x80;
3876 *buf
++ = (val
>> 8);
3878 upper_limit
= 0x7fff;
3879 lower_limit
= - (offsetT
) 0x8000;
3882 *buf
++ = (val
>> 24);
3883 *buf
++ = (val
>> 16);
3884 *buf
++ = (val
>> 8);
3886 upper_limit
= 0x7fffffff;
3887 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3890 BAD_CASE (fixP
->fx_size
);
3893 /* Fix up a negative reloc. */
3894 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
3896 fixP
->fx_addsy
= fixP
->fx_subsy
;
3897 fixP
->fx_subsy
= NULL
;
3901 /* For non-pc-relative values, it's conceivable we might get something
3902 like "0xff" for a byte field. So extend the upper part of the range
3903 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3904 so that we can do any range checking at all. */
3905 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
3906 upper_limit
= upper_limit
* 2 + 1;
3908 if ((addressT
) val
> upper_limit
3909 && (val
> 0 || val
< lower_limit
))
3910 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
3912 /* A one byte PC-relative reloc means a short branch. We can't use
3913 a short branch with a value of 0 or -1, because those indicate
3914 different opcodes (branches with longer offsets). */
3916 && fixP
->fx_size
== 1
3917 && (fixP
->fx_addsy
== NULL
3918 || S_IS_DEFINED (fixP
->fx_addsy
))
3919 && (val
== 0 || val
== -1))
3920 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
3923 #ifdef BFD_ASSEMBLER
3925 md_apply_fix (fixP
, valp
)
3929 md_apply_fix_2 (fixP
, (addressT
) *valp
);
3933 void md_apply_fix (fixP
, val
)
3937 md_apply_fix_2 (fixP
, (addressT
) val
);
3941 /* *fragP has been relaxed to its final size, and now needs to have
3942 the bytes inside it modified to conform to the new size There is UGLY
3946 md_convert_frag_1 (fragP
)
3947 register fragS
*fragP
;
3953 /* Address in object code of the displacement. */
3954 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3956 /* Address in gas core of the place to store the displacement. */
3957 /* This convinces the native rs6000 compiler to generate the code we
3959 register char *buffer_address
= fragP
->fr_literal
;
3960 buffer_address
+= fragP
->fr_fix
;
3961 /* end ibm compiler workaround */
3963 /* The displacement of the address, from current location. */
3964 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3965 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3967 #ifdef BFD_ASSEMBLER
3968 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
3971 switch (fragP
->fr_subtype
)
3973 case TAB (BCC68000
, BYTE
):
3974 case TAB (ABRANCH
, BYTE
):
3975 know (issbyte (disp
));
3977 as_bad ("short branch with zero offset: use :w");
3978 fragP
->fr_opcode
[1] = disp
;
3981 case TAB (DBCC
, SHORT
):
3982 know (issword (disp
));
3985 case TAB (BCC68000
, SHORT
):
3986 case TAB (ABRANCH
, SHORT
):
3987 know (issword (disp
));
3988 fragP
->fr_opcode
[1] = 0x00;
3991 case TAB (ABRANCH
, LONG
):
3992 if (cpu_of_arch (current_architecture
) < m68020
)
3994 if (fragP
->fr_opcode
[0] == 0x61)
3997 fragP
->fr_opcode
[0] = 0x4E;
3998 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4012 else if (fragP
->fr_opcode
[0] == 0x60)
4014 fragP
->fr_opcode
[0] = 0x4E;
4015 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4016 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4017 fragP
->fr_offset
, 0, NO_RELOC
);
4023 as_bad ("Long branch offset not supported.");
4028 fragP
->fr_opcode
[1] = (char) 0xff;
4032 case TAB (BCC68000
, LONG
):
4033 /* only Bcc 68000 instructions can come here */
4034 /* change bcc into b!cc/jmp absl long */
4035 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4036 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4038 /* JF: these used to be fr_opcode[2,3], but they may be in a
4039 different frag, in which case refering to them is a no-no.
4040 Only fr_opcode[0,1] are guaranteed to work. */
4041 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4042 *buffer_address
++ = (char) 0xf9;
4043 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4044 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4045 fragP
->fr_offset
, 0, NO_RELOC
);
4049 case TAB (DBCC
, LONG
):
4050 /* only DBcc 68000 instructions can come here */
4051 /* change dbcc into dbcc/jmp absl long */
4052 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4053 *buffer_address
++ = 0x00; /* branch offset = 4 */
4054 *buffer_address
++ = 0x04;
4055 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4056 *buffer_address
++ = 0x06;
4057 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4058 *buffer_address
++ = (char) 0xf9;
4060 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4061 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4062 fragP
->fr_offset
, 0, NO_RELOC
);
4066 case TAB (FBRANCH
, SHORT
):
4067 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4070 case TAB (FBRANCH
, LONG
):
4071 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4074 case TAB (PCREL
, SHORT
):
4077 case TAB (PCREL
, LONG
):
4078 /* The thing to do here is force it to ABSOLUTE LONG, since
4079 PCREL is really trying to shorten an ABSOLUTE address anyway */
4080 /* JF FOO This code has not been tested */
4081 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4083 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4084 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
4085 (unsigned) fragP
->fr_opcode
[0],
4086 (unsigned long) fragP
->fr_address
);
4087 fragP
->fr_opcode
[1] &= ~0x3F;
4088 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4092 case TAB (PCLEA
, SHORT
):
4093 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4094 fragP
->fr_offset
, 1, NO_RELOC
);
4095 fragP
->fr_opcode
[1] &= ~0x3F;
4096 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4099 case TAB (PCLEA
, LONG
):
4100 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4101 fragP
->fr_offset
, 1, NO_RELOC
);
4102 fixP
->fx_pcrel_adjust
= 2;
4103 /* Already set to mode 7.3; this indicates: PC indirect with
4104 suppressed index, 32-bit displacement. */
4105 *buffer_address
++ = 0x01;
4106 *buffer_address
++ = 0x70;
4111 case TAB (PCINDEX
, BYTE
):
4113 if (!issbyte (disp
))
4115 as_bad ("displacement doesn't fit in one byte");
4118 assert (fragP
->fr_fix
>= 2);
4119 buffer_address
[-2] &= ~1;
4120 buffer_address
[-1] = disp
;
4123 case TAB (PCINDEX
, SHORT
):
4125 assert (issword (disp
));
4126 assert (fragP
->fr_fix
>= 2);
4127 buffer_address
[-2] |= 0x1;
4128 buffer_address
[-1] = 0x20;
4129 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4130 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4132 fixP
->fx_pcrel_adjust
= 2;
4135 case TAB (PCINDEX
, LONG
):
4137 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4138 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4140 fixP
->fx_pcrel_adjust
= 2;
4141 assert (fragP
->fr_fix
>= 2);
4142 buffer_address
[-2] |= 0x1;
4143 buffer_address
[-1] = 0x30;
4150 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4151 fragP
->fr_fix
+= ext
;
4155 #ifndef BFD_ASSEMBLER
4158 md_convert_frag (headers
, sec
, fragP
)
4159 object_headers
*headers
;
4163 md_convert_frag_1 (fragP
);
4169 md_convert_frag (abfd
, sec
, fragP
)
4174 md_convert_frag_1 (fragP
);
4178 /* Force truly undefined symbols to their maximum size, and generally set up
4179 the frag list to be relaxed
4182 md_estimate_size_before_relax (fragP
, segment
)
4183 register fragS
*fragP
;
4187 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4189 old_fix
= fragP
->fr_fix
;
4191 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4192 switch (fragP
->fr_subtype
)
4195 case TAB (ABRANCH
, SZ_UNDEF
):
4197 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4198 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4200 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4203 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
4205 /* On 68000, or for absolute value, switch to abs long */
4206 /* FIXME, we should check abs val, pick short or long */
4207 if (fragP
->fr_opcode
[0] == 0x61)
4209 fragP
->fr_opcode
[0] = 0x4E;
4210 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4211 fix_new (fragP
, fragP
->fr_fix
, 4,
4212 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4216 else if (fragP
->fr_opcode
[0] == 0x60)
4218 fragP
->fr_opcode
[0] = 0x4E;
4219 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4220 fix_new (fragP
, fragP
->fr_fix
, 4,
4221 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4227 as_warn ("Long branch offset to extern symbol not supported.");
4231 { /* Symbol is still undefined. Make it simple */
4232 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4233 fragP
->fr_offset
, 1, NO_RELOC
);
4235 fragP
->fr_opcode
[1] = (char) 0xff;
4241 } /* case TAB(ABRANCH,SZ_UNDEF) */
4243 case TAB (FBRANCH
, SZ_UNDEF
):
4245 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
4247 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4252 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4253 fragP
->fr_offset
, 1, NO_RELOC
);
4255 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4259 } /* TAB(FBRANCH,SZ_UNDEF) */
4261 case TAB (PCREL
, SZ_UNDEF
):
4263 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4265 || cpu_of_arch (current_architecture
) < m68020
)
4267 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4272 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4276 } /* TAB(PCREL,SZ_UNDEF) */
4278 case TAB (BCC68000
, SZ_UNDEF
):
4280 if ((fragP
->fr_symbol
!= NULL
)
4281 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4283 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4286 /* only Bcc 68000 instructions can come here */
4287 /* change bcc into b!cc/jmp absl long */
4288 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4289 if (flag_short_refs
)
4291 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4292 /* JF: these were fr_opcode[2,3] */
4293 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4294 buffer_address
[1] = (char) 0xf8;
4295 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4296 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4297 fragP
->fr_offset
, 0, NO_RELOC
);
4302 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4303 /* JF: these were fr_opcode[2,3] */
4304 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4305 buffer_address
[1] = (char) 0xf9;
4306 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4307 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4308 fragP
->fr_offset
, 0, NO_RELOC
);
4313 } /* case TAB(BCC68000,SZ_UNDEF) */
4315 case TAB (DBCC
, SZ_UNDEF
):
4317 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4319 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4323 /* only DBcc 68000 instructions can come here */
4324 /* change dbcc into dbcc/jmp absl long */
4325 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4326 buffer_address
[0] = 0x00; /* branch offset = 4 */
4327 buffer_address
[1] = 0x04;
4328 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4330 if (flag_short_refs
)
4332 /* JF: these were fr_opcode[5-7] */
4333 buffer_address
[3] = 0x04; /* plus 4 */
4334 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4335 buffer_address
[5] = (char) 0xf8;
4336 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4337 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4338 fragP
->fr_offset
, 0, NO_RELOC
);
4343 /* JF: these were fr_opcode[5-7] */
4344 buffer_address
[3] = 0x06; /* Plus 6 */
4345 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4346 buffer_address
[5] = (char) 0xf9;
4347 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4348 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4349 fragP
->fr_offset
, 0, NO_RELOC
);
4355 } /* case TAB(DBCC,SZ_UNDEF) */
4357 case TAB (PCLEA
, SZ_UNDEF
):
4359 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4361 || cpu_of_arch (current_architecture
) < m68020
)
4363 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4368 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4372 } /* TAB(PCLEA,SZ_UNDEF) */
4374 case TAB (PCINDEX
, SZ_UNDEF
):
4375 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4376 || cpu_of_arch (current_architecture
) < m68020
)
4378 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4382 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4391 /* now that SZ_UNDEF are taken care of, check others */
4392 switch (fragP
->fr_subtype
)
4394 case TAB (BCC68000
, BYTE
):
4395 case TAB (ABRANCH
, BYTE
):
4396 /* We can't do a short jump to the next instruction, so in that
4397 case we force word mode. At this point S_GET_VALUE should
4398 return the offset of the symbol within its frag. If the
4399 symbol is at the start of a frag, and it is the next frag
4400 with any data in it (usually this is just the next frag, but
4401 assembler listings may introduce empty frags), we must use
4403 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0)
4407 for (l
= fragP
->fr_next
;
4408 l
!= fragP
->fr_symbol
->sy_frag
;
4410 if (l
->fr_fix
+ l
->fr_var
!= 0)
4412 if (l
== fragP
->fr_symbol
->sy_frag
)
4414 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4422 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4425 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4426 /* the bit-field entries in the relocation_info struct plays hell
4427 with the byte-order problems of cross-assembly. So as a hack,
4428 I added this mach. dependent ri twiddler. Ugly, but it gets
4430 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4431 are symbolnum, most sig. byte first. Last byte is broken up with
4432 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4433 nibble as nuthin. (on Sun 3 at least) */
4434 /* Translate the internal relocation information into target-specific
4438 md_ri_to_chars (the_bytes
, ri
)
4440 struct reloc_info_generic
*ri
;
4443 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4444 /* now the fun stuff */
4445 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4446 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4447 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4448 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4449 ((ri
->r_extern
<< 4) & 0x10));
4452 #endif /* comment */
4454 #ifndef BFD_ASSEMBLER
4456 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4459 relax_addressT segment_address_in_file
;
4462 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4463 * Out: GNU LD relocation length code: 0, 1, or 2.
4466 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4469 know (fixP
->fx_addsy
!= NULL
);
4471 md_number_to_chars (where
,
4472 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4475 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4476 ? S_GET_TYPE (fixP
->fx_addsy
)
4477 : fixP
->fx_addsy
->sy_number
);
4479 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4480 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4481 where
[6] = r_symbolnum
& 0x0ff;
4482 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4483 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4487 #endif /* OBJ_AOUT or OBJ_BOUT */
4489 #ifndef WORKING_DOT_WORD
4490 CONST
int md_short_jump_size
= 4;
4491 CONST
int md_long_jump_size
= 6;
4494 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4496 addressT from_addr
, to_addr
;
4502 offset
= to_addr
- (from_addr
+ 2);
4504 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4505 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4509 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4511 addressT from_addr
, to_addr
;
4517 if (cpu_of_arch (current_architecture
) < m68020
)
4519 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4520 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4521 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4522 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4527 offset
= to_addr
- (from_addr
+ 2);
4528 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4529 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4535 /* Different values of OK tell what its OK to return. Things that
4536 aren't OK are an error (what a shock, no?)
4539 10: Absolute 1:8 only
4540 20: Absolute 0:7 only
4541 30: absolute 0:15 only
4542 40: Absolute 0:31 only
4543 50: absolute 0:127 only
4544 55: absolute -64:63 only
4545 60: absolute -128:127 only
4546 70: absolute 0:4095 only
4553 struct m68k_exp
*exp
;
4556 if (exp
->exp
.X_op
== O_absent
)
4558 /* Do the same thing the VAX asm does */
4559 op (exp
) = O_constant
;
4565 as_warn ("expression out of range: defaulting to 1");
4569 else if (exp
->exp
.X_op
== O_constant
)
4574 if (offs (exp
) < 1 || offs (exp
) > 8)
4576 as_warn ("expression out of range: defaulting to 1");
4581 if (offs (exp
) < 0 || offs (exp
) > 7)
4585 if (offs (exp
) < 0 || offs (exp
) > 15)
4589 if (offs (exp
) < 0 || offs (exp
) > 32)
4593 if (offs (exp
) < 0 || offs (exp
) > 127)
4597 if (offs (exp
) < -64 || offs (exp
) > 63)
4601 if (offs (exp
) < -128 || offs (exp
) > 127)
4605 if (offs (exp
) < 0 || offs (exp
) > 4095)
4608 as_warn ("expression out of range: defaulting to 0");
4616 else if (exp
->exp
.X_op
== O_big
)
4618 if (offs (exp
) <= 0 /* flonum */
4619 && (ok
== 80 /* no bignums */
4620 || (ok
> 10 /* small-int ranges including 0 ok */
4621 /* If we have a flonum zero, a zero integer should
4622 do as well (e.g., in moveq). */
4623 && generic_floating_point_number
.exponent
== 0
4624 && generic_floating_point_number
.low
[0] == 0)))
4626 /* HACK! Turn it into a long */
4627 LITTLENUM_TYPE words
[6];
4629 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4630 op (exp
) = O_constant
;
4633 offs (exp
) = words
[1] | (words
[0] << 16);
4637 op (exp
) = O_constant
;
4640 offs (exp
) = (ok
== 10) ? 1 : 0;
4641 as_warn ("Can't deal with expression; defaulting to %ld",
4647 if (ok
>= 10 && ok
<= 70)
4649 op (exp
) = O_constant
;
4652 offs (exp
) = (ok
== 10) ? 1 : 0;
4653 as_warn ("Can't deal with expression; defaulting to %ld",
4658 if (exp
->size
!= SIZE_UNSPEC
)
4666 if (!isbyte (offs (exp
)))
4667 as_warn ("expression doesn't fit in BYTE");
4670 if (!isword (offs (exp
)))
4671 as_warn ("expression doesn't fit in WORD");
4679 /* These are the back-ends for the various machine dependent pseudo-ops. */
4680 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4686 subseg_set (data_section
, 1);
4687 demand_empty_rest_of_line ();
4694 subseg_set (data_section
, 2);
4695 demand_empty_rest_of_line ();
4702 /* We don't support putting frags in the BSS segment, we fake it
4703 by marking in_bss, then looking at s_skip for clues. */
4705 subseg_set (bss_section
, 0);
4706 demand_empty_rest_of_line ();
4714 register long temp_fill
;
4716 temp
= 1; /* JF should be 2? */
4717 temp_fill
= get_absolute_expression ();
4718 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4719 frag_align (temp
, (int) temp_fill
);
4720 demand_empty_rest_of_line ();
4727 demand_empty_rest_of_line ();
4730 /* Pseudo-ops handled for MRI compatibility. */
4732 /* This function returns non-zero if the argument is a conditional
4733 pseudo-op. This is called when checking whether a pending
4734 alignment is needed. */
4737 m68k_conditional_pseudoop (pop
)
4740 return (pop
->poc_handler
== s_mri_if
4741 || pop
->poc_handler
== s_mri_else
);
4744 /* Handle an MRI style chip specification. */
4753 s
= input_line_pointer
;
4754 c
= get_symbol_end ();
4755 for (i
= 0; i
< n_archs
; i
++)
4756 if (strcasecmp (s
, archs
[i
].name
) == 0)
4760 as_bad ("%s: unrecognized processor name", s
);
4761 *input_line_pointer
= c
;
4762 ignore_rest_of_line ();
4765 *input_line_pointer
= c
;
4767 if (*input_line_pointer
== '/')
4768 current_architecture
= 0;
4770 current_architecture
&= m68881
| m68851
;
4771 current_architecture
|= archs
[i
].arch
;
4773 while (*input_line_pointer
== '/')
4775 ++input_line_pointer
;
4776 s
= input_line_pointer
;
4777 c
= get_symbol_end ();
4778 if (strcmp (s
, "68881") == 0)
4779 current_architecture
|= m68881
;
4780 else if (strcmp (s
, "68851") == 0)
4781 current_architecture
|= m68851
;
4782 *input_line_pointer
= c
;
4785 /* Update info about available control registers. */
4786 select_control_regs ();
4789 /* The MRI CHIP pseudo-op. */
4799 stop
= mri_comment_field (&stopc
);
4802 mri_comment_end (stop
, stopc
);
4803 demand_empty_rest_of_line ();
4806 /* The MRI FOPT pseudo-op. */
4814 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4818 input_line_pointer
+= 3;
4819 temp
= get_absolute_expression ();
4820 if (temp
< 0 || temp
> 7)
4821 as_bad ("bad coprocessor id");
4823 m68k_float_copnum
= COP0
+ temp
;
4827 as_bad ("unrecognized fopt option");
4828 ignore_rest_of_line ();
4832 demand_empty_rest_of_line ();
4835 /* The structure used to handle the MRI OPT pseudo-op. */
4839 /* The name of the option. */
4842 /* If this is not NULL, just call this function. The first argument
4843 is the ARG field of this structure, the second argument is
4844 whether the option was negated. */
4845 void (*pfn
) PARAMS ((int arg
, int on
));
4847 /* If this is not NULL, and the PFN field is NULL, set the variable
4848 this points to. Set it to the ARG field if the option was not
4849 negated, and the NOTARG field otherwise. */
4852 /* The value to pass to PFN or to assign to *PVAR. */
4855 /* The value to assign to *PVAR if the option is negated. If PFN is
4856 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4857 the option may not be negated. */
4861 /* The table used to handle the MRI OPT pseudo-op. */
4863 static void skip_to_comma
PARAMS ((int, int));
4864 static void opt_nest
PARAMS ((int, int));
4865 static void opt_chip
PARAMS ((int, int));
4866 static void opt_list
PARAMS ((int, int));
4867 static void opt_list_symbols
PARAMS ((int, int));
4869 static const struct opt_action opt_table
[] =
4871 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
4873 /* We do relaxing, so there is little use for these options. */
4874 { "b", 0, 0, 0, 0 },
4875 { "brs", 0, 0, 0, 0 },
4876 { "brb", 0, 0, 0, 0 },
4877 { "brl", 0, 0, 0, 0 },
4878 { "brw", 0, 0, 0, 0 },
4880 { "c", 0, 0, 0, 0 },
4881 { "cex", 0, 0, 0, 0 },
4882 { "case", 0, &symbols_case_sensitive
, 1, 0 },
4883 { "cl", 0, 0, 0, 0 },
4884 { "cre", 0, 0, 0, 0 },
4885 { "d", 0, &flag_keep_locals
, 1, 0 },
4886 { "e", 0, 0, 0, 0 },
4887 { "f", 0, &flag_short_refs
, 1, 0 },
4888 { "frs", 0, &flag_short_refs
, 1, 0 },
4889 { "frl", 0, &flag_short_refs
, 0, 1 },
4890 { "g", 0, 0, 0, 0 },
4891 { "i", 0, 0, 0, 0 },
4892 { "m", 0, 0, 0, 0 },
4893 { "mex", 0, 0, 0, 0 },
4894 { "mc", 0, 0, 0, 0 },
4895 { "md", 0, 0, 0, 0 },
4896 { "nest", opt_nest
, 0, 0, 0 },
4897 { "next", skip_to_comma
, 0, 0, 0 },
4898 { "o", 0, 0, 0, 0 },
4899 { "old", 0, 0, 0, 0 },
4900 { "op", skip_to_comma
, 0, 0, 0 },
4901 { "pco", 0, 0, 0, 0 },
4902 { "p", opt_chip
, 0, 0, 0 },
4903 { "pcr", 0, 0, 0, 0 },
4904 { "pcs", 0, 0, 0, 0 },
4905 { "r", 0, 0, 0, 0 },
4906 { "quick", 0, &m68k_quick
, 1, 0 },
4907 { "rel32", 0, &m68k_rel32
, 1, 0 },
4908 { "s", opt_list
, 0, 0, 0 },
4909 { "t", opt_list_symbols
, 0, 0, 0 },
4910 { "w", 0, &flag_no_warnings
, 0, 1 },
4914 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4916 /* The MRI OPT pseudo-op. */
4928 const struct opt_action
*o
;
4933 if (*input_line_pointer
== '-')
4935 ++input_line_pointer
;
4938 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
4940 input_line_pointer
+= 2;
4944 s
= input_line_pointer
;
4945 c
= get_symbol_end ();
4947 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
4949 if (strcasecmp (s
, o
->name
) == 0)
4953 /* Restore input_line_pointer now in case the option
4955 *input_line_pointer
= c
;
4956 (*o
->pfn
) (o
->arg
, t
);
4958 else if (o
->pvar
!= NULL
)
4960 if (! t
&& o
->arg
== o
->notarg
)
4961 as_bad ("option `%s' may not be negated", s
);
4962 *input_line_pointer
= c
;
4963 *o
->pvar
= t
? o
->arg
: o
->notarg
;
4966 *input_line_pointer
= c
;
4972 as_bad ("option `%s' not recognized", s
);
4973 *input_line_pointer
= c
;
4976 while (*input_line_pointer
++ == ',');
4978 /* Move back to terminating character. */
4979 --input_line_pointer
;
4980 demand_empty_rest_of_line ();
4983 /* Skip ahead to a comma. This is used for OPT options which we do
4984 not suppor tand which take arguments. */
4987 skip_to_comma (arg
, on
)
4991 while (*input_line_pointer
!= ','
4992 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4993 ++input_line_pointer
;
4996 /* Handle the OPT NEST=depth option. */
5003 if (*input_line_pointer
!= '=')
5005 as_bad ("bad format of OPT NEST=depth");
5009 ++input_line_pointer
;
5010 max_macro_nest
= get_absolute_expression ();
5013 /* Handle the OPT P=chip option. */
5020 if (*input_line_pointer
!= '=')
5022 /* This is just OPT P, which we do not support. */
5026 ++input_line_pointer
;
5030 /* Handle the OPT S option. */
5040 /* Handle the OPT T option. */
5043 opt_list_symbols (arg
, on
)
5048 listing
|= LISTING_SYMBOLS
;
5050 listing
&=~ LISTING_SYMBOLS
;
5053 /* Handle the MRI REG pseudo-op. */
5066 if (line_label
== NULL
)
5068 as_bad ("missing label");
5069 ignore_rest_of_line ();
5074 stop
= mri_comment_field (&stopc
);
5078 s
= input_line_pointer
;
5079 while (isalnum ((unsigned char) *input_line_pointer
)
5080 #ifdef REGISTER_PREFIX
5081 || *input_line_pointer
== REGISTER_PREFIX
5083 || *input_line_pointer
== '/'
5084 || *input_line_pointer
== '-')
5085 ++input_line_pointer
;
5086 c
= *input_line_pointer
;
5087 *input_line_pointer
= '\0';
5089 if (m68k_ip_op (s
, &rop
) != 0)
5091 if (rop
.error
== NULL
)
5092 as_bad ("bad register list");
5094 as_bad ("bad register list: %s", rop
.error
);
5095 *input_line_pointer
= c
;
5096 ignore_rest_of_line ();
5100 *input_line_pointer
= c
;
5102 if (rop
.mode
== REGLST
)
5104 else if (rop
.mode
== DREG
)
5105 mask
= 1 << (rop
.reg
- DATA0
);
5106 else if (rop
.mode
== AREG
)
5107 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5108 else if (rop
.mode
== FPREG
)
5109 mask
= 1 << (rop
.reg
- FP0
+ 16);
5110 else if (rop
.mode
== CONTROL
5113 else if (rop
.mode
== CONTROL
5116 else if (rop
.mode
== CONTROL
5121 as_bad ("bad register list");
5122 ignore_rest_of_line ();
5126 S_SET_SEGMENT (line_label
, absolute_section
);
5127 S_SET_VALUE (line_label
, mask
);
5128 line_label
->sy_frag
= &zero_address_frag
;
5131 mri_comment_end (stop
, stopc
);
5133 demand_empty_rest_of_line ();
5136 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5140 struct save_opts
*next
;
5142 int symbols_case_sensitive
;
5150 /* FIXME: We don't save OPT S. */
5153 /* This variable holds the stack of saved options. */
5155 static struct save_opts
*save_stack
;
5157 /* The MRI SAVE pseudo-op. */
5163 struct save_opts
*s
;
5165 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5166 s
->abspcadd
= m68k_abspcadd
;
5167 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5168 s
->keep_locals
= flag_keep_locals
;
5169 s
->short_refs
= flag_short_refs
;
5170 s
->architecture
= current_architecture
;
5171 s
->quick
= m68k_quick
;
5172 s
->rel32
= m68k_rel32
;
5173 s
->listing
= listing
;
5174 s
->no_warnings
= flag_no_warnings
;
5176 s
->next
= save_stack
;
5179 demand_empty_rest_of_line ();
5182 /* The MRI RESTORE pseudo-op. */
5188 struct save_opts
*s
;
5190 if (save_stack
== NULL
)
5192 as_bad ("restore without save");
5193 ignore_rest_of_line ();
5198 save_stack
= s
->next
;
5200 m68k_abspcadd
= s
->abspcadd
;
5201 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5202 flag_keep_locals
= s
->keep_locals
;
5203 flag_short_refs
= s
->short_refs
;
5204 current_architecture
= s
->architecture
;
5205 m68k_quick
= s
->quick
;
5206 m68k_rel32
= s
->rel32
;
5207 listing
= s
->listing
;
5208 flag_no_warnings
= s
->no_warnings
;
5212 demand_empty_rest_of_line ();
5215 /* Types of MRI structured control directives. */
5217 enum mri_control_type
5225 /* This structure is used to stack the MRI structured control
5228 struct mri_control_info
5230 /* The directive within which this one is enclosed. */
5231 struct mri_control_info
*outer
;
5233 /* The type of directive. */
5234 enum mri_control_type type
;
5236 /* Whether an ELSE has been in an IF. */
5239 /* The add or sub statement at the end of a FOR. */
5242 /* The label of the top of a FOR or REPEAT loop. */
5245 /* The label to jump to for the next iteration, or the else
5246 expression of a conditional. */
5249 /* The label to jump to to break out of the loop, or the label past
5250 the end of a conditional. */
5254 /* The stack of MRI structured control directives. */
5256 static struct mri_control_info
*mri_control_stack
;
5258 /* The current MRI structured control directive index number, used to
5259 generate label names. */
5261 static int mri_control_index
;
5263 /* Some function prototypes. */
5265 static char *mri_control_label
PARAMS ((void));
5266 static struct mri_control_info
*push_mri_control
5267 PARAMS ((enum mri_control_type
));
5268 static void pop_mri_control
PARAMS ((void));
5269 static int parse_mri_condition
PARAMS ((int *));
5270 static int parse_mri_control_operand
5271 PARAMS ((int *, char **, char **, char **, char **));
5272 static int swap_mri_condition
PARAMS ((int));
5273 static int reverse_mri_condition
PARAMS ((int));
5274 static void build_mri_control_operand
5275 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5276 const char *, int));
5277 static void parse_mri_control_expression
5278 PARAMS ((char *, int, const char *, const char *, int));
5280 /* Generate a new MRI label structured control directive label name. */
5283 mri_control_label ()
5287 n
= (char *) xmalloc (20);
5288 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5289 ++mri_control_index
;
5293 /* Create a new MRI structured control directive. */
5295 static struct mri_control_info
*
5296 push_mri_control (type
)
5297 enum mri_control_type type
;
5299 struct mri_control_info
*n
;
5301 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5305 if (type
== mri_if
|| type
== mri_while
)
5308 n
->top
= mri_control_label ();
5309 n
->next
= mri_control_label ();
5310 n
->bottom
= mri_control_label ();
5312 n
->outer
= mri_control_stack
;
5313 mri_control_stack
= n
;
5318 /* Pop off the stack of MRI structured control directives. */
5323 struct mri_control_info
*n
;
5325 n
= mri_control_stack
;
5326 mri_control_stack
= n
->outer
;
5334 /* Recognize a condition code in an MRI structured control expression. */
5337 parse_mri_condition (pcc
)
5342 know (*input_line_pointer
== '<');
5344 ++input_line_pointer
;
5345 c1
= *input_line_pointer
++;
5346 c2
= *input_line_pointer
++;
5348 if (*input_line_pointer
!= '>')
5350 as_bad ("syntax error in structured control directive");
5354 ++input_line_pointer
;
5362 *pcc
= (c1
<< 8) | c2
;
5367 /* Parse a single operand in an MRI structured control expression. */
5370 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5387 if (*input_line_pointer
== '<')
5389 /* It's just a condition code. */
5390 return parse_mri_condition (pcc
);
5393 /* Look ahead for the condition code. */
5394 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5396 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5401 as_bad ("missing condition code in structured control directive");
5405 *leftstart
= input_line_pointer
;
5407 if (*leftstop
> *leftstart
5408 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5411 input_line_pointer
= s
;
5412 if (! parse_mri_condition (pcc
))
5415 /* Look ahead for AND or OR or end of line. */
5416 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5418 if ((strncasecmp (s
, "AND", 3) == 0
5419 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5420 || (strncasecmp (s
, "OR", 2) == 0
5421 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5425 *rightstart
= input_line_pointer
;
5427 if (*rightstop
> *rightstart
5428 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5431 input_line_pointer
= s
;
5436 #define MCC(b1, b2) (((b1) << 8) | (b2))
5438 /* Swap the sense of a condition. This changes the condition so that
5439 it generates the same result when the operands are swapped. */
5442 swap_mri_condition (cc
)
5447 case MCC ('h', 'i'): return MCC ('c', 's');
5448 case MCC ('l', 's'): return MCC ('c', 'c');
5449 case MCC ('c', 'c'): return MCC ('l', 's');
5450 case MCC ('c', 's'): return MCC ('h', 'i');
5451 case MCC ('p', 'l'): return MCC ('m', 'i');
5452 case MCC ('m', 'i'): return MCC ('p', 'l');
5453 case MCC ('g', 'e'): return MCC ('l', 'e');
5454 case MCC ('l', 't'): return MCC ('g', 't');
5455 case MCC ('g', 't'): return MCC ('l', 't');
5456 case MCC ('l', 'e'): return MCC ('g', 'e');
5461 /* Reverse the sense of a condition. */
5464 reverse_mri_condition (cc
)
5469 case MCC ('h', 'i'): return MCC ('l', 's');
5470 case MCC ('l', 's'): return MCC ('h', 'i');
5471 case MCC ('c', 'c'): return MCC ('c', 's');
5472 case MCC ('c', 's'): return MCC ('c', 'c');
5473 case MCC ('n', 'e'): return MCC ('e', 'q');
5474 case MCC ('e', 'q'): return MCC ('n', 'e');
5475 case MCC ('v', 'c'): return MCC ('v', 's');
5476 case MCC ('v', 's'): return MCC ('v', 'c');
5477 case MCC ('p', 'l'): return MCC ('m', 'i');
5478 case MCC ('m', 'i'): return MCC ('p', 'l');
5479 case MCC ('g', 'e'): return MCC ('l', 't');
5480 case MCC ('l', 't'): return MCC ('g', 'e');
5481 case MCC ('g', 't'): return MCC ('l', 'e');
5482 case MCC ('l', 'e'): return MCC ('g', 't');
5487 /* Build an MRI structured control expression. This generates test
5488 and branch instructions. It goes to TRUELAB if the condition is
5489 true, and to FALSELAB if the condition is false. Exactly one of
5490 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5491 is the size qualifier for the expression. EXTENT is the size to
5492 use for the branch. */
5495 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5496 rightstop
, truelab
, falselab
, extent
)
5503 const char *truelab
;
5504 const char *falselab
;
5510 if (leftstart
!= NULL
)
5512 struct m68k_op leftop
, rightop
;
5515 /* Swap the compare operands, if necessary, to produce a legal
5516 m68k compare instruction. Comparing a register operand with
5517 a non-register operand requires the register to be on the
5518 right (cmp, cmpa). Comparing an immediate value with
5519 anything requires the immediate value to be on the left
5524 (void) m68k_ip_op (leftstart
, &leftop
);
5529 (void) m68k_ip_op (rightstart
, &rightop
);
5532 if (rightop
.mode
== IMMED
5533 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5534 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5538 cc
= swap_mri_condition (cc
);
5540 leftstart
= rightstart
;
5543 leftstop
= rightstop
;
5548 if (truelab
== NULL
)
5550 cc
= reverse_mri_condition (cc
);
5554 if (leftstart
!= NULL
)
5556 buf
= (char *) xmalloc (20
5557 + (leftstop
- leftstart
)
5558 + (rightstop
- rightstart
));
5566 memcpy (s
, leftstart
, leftstop
- leftstart
);
5567 s
+= leftstop
- leftstart
;
5569 memcpy (s
, rightstart
, rightstop
- rightstart
);
5570 s
+= rightstop
- rightstart
;
5576 buf
= (char *) xmalloc (20 + strlen (truelab
));
5584 strcpy (s
, truelab
);
5589 /* Parse an MRI structured control expression. This generates test
5590 and branch instructions. STOP is where the expression ends. It
5591 goes to TRUELAB if the condition is true, and to FALSELAB if the
5592 condition is false. Exactly one of TRUELAB and FALSELAB will be
5593 NULL, meaning to fall through. QUAL is the size qualifier for the
5594 expression. EXTENT is the size to use for the branch. */
5597 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
5600 const char *truelab
;
5601 const char *falselab
;
5614 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5615 &rightstart
, &rightstop
))
5621 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5625 if (falselab
!= NULL
)
5628 flab
= mri_control_label ();
5630 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5631 rightstop
, (const char *) NULL
, flab
, extent
);
5633 input_line_pointer
+= 3;
5634 if (*input_line_pointer
!= '.'
5635 || input_line_pointer
[1] == '\0')
5639 qual
= input_line_pointer
[1];
5640 input_line_pointer
+= 2;
5643 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5644 &rightstart
, &rightstop
))
5650 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5651 rightstop
, truelab
, falselab
, extent
);
5653 if (falselab
== NULL
)
5656 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5660 if (truelab
!= NULL
)
5663 tlab
= mri_control_label ();
5665 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5666 rightstop
, tlab
, (const char *) NULL
, extent
);
5668 input_line_pointer
+= 2;
5669 if (*input_line_pointer
!= '.'
5670 || input_line_pointer
[1] == '\0')
5674 qual
= input_line_pointer
[1];
5675 input_line_pointer
+= 2;
5678 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5679 &rightstart
, &rightstop
))
5685 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5686 rightstop
, truelab
, falselab
, extent
);
5688 if (truelab
== NULL
)
5693 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5694 rightstop
, truelab
, falselab
, extent
);
5698 if (input_line_pointer
!= stop
)
5699 as_bad ("syntax error in structured control directive");
5702 /* Handle the MRI IF pseudo-op. This may be a structured control
5703 directive, or it may be a regular assembler conditional, depending
5712 struct mri_control_info
*n
;
5714 /* A structured control directive must end with THEN with an
5715 optional qualifier. */
5716 s
= input_line_pointer
;
5717 while (! is_end_of_line
[(unsigned char) *s
]
5718 && (! flag_mri
|| *s
!= '*'))
5721 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5724 if (s
- input_line_pointer
> 1
5728 if (s
- input_line_pointer
< 3
5729 || strncasecmp (s
- 3, "THEN", 4) != 0)
5733 as_bad ("missing then");
5734 ignore_rest_of_line ();
5738 /* It's a conditional. */
5743 /* Since this might be a conditional if, this pseudo-op will be
5744 called even if we are supported to be ignoring input. Double
5745 check now. Clobber *input_line_pointer so that ignore_input
5746 thinks that this is not a special pseudo-op. */
5747 c
= *input_line_pointer
;
5748 *input_line_pointer
= 0;
5749 if (ignore_input ())
5751 *input_line_pointer
= c
;
5752 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5753 ++input_line_pointer
;
5754 demand_empty_rest_of_line ();
5757 *input_line_pointer
= c
;
5759 n
= push_mri_control (mri_if
);
5761 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5762 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5765 input_line_pointer
= s
+ 3;
5767 input_line_pointer
= s
+ 1;
5771 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5772 ++input_line_pointer
;
5775 demand_empty_rest_of_line ();
5778 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5779 structured IF, associate the ELSE with the IF. Otherwise, assume
5780 it is a conditional else. */
5791 && (mri_control_stack
== NULL
5792 || mri_control_stack
->type
!= mri_if
5793 || mri_control_stack
->else_seen
))
5799 c
= *input_line_pointer
;
5800 *input_line_pointer
= 0;
5801 if (ignore_input ())
5803 *input_line_pointer
= c
;
5804 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5805 ++input_line_pointer
;
5806 demand_empty_rest_of_line ();
5809 *input_line_pointer
= c
;
5811 if (mri_control_stack
== NULL
5812 || mri_control_stack
->type
!= mri_if
5813 || mri_control_stack
->else_seen
)
5815 as_bad ("else without matching if");
5816 ignore_rest_of_line ();
5820 mri_control_stack
->else_seen
= 1;
5822 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
5825 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
5829 colon (mri_control_stack
->next
);
5833 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5834 ++input_line_pointer
;
5837 demand_empty_rest_of_line ();
5840 /* Handle the MRI ENDI pseudo-op. */
5846 if (mri_control_stack
== NULL
5847 || mri_control_stack
->type
!= mri_if
)
5849 as_bad ("endi without matching if");
5850 ignore_rest_of_line ();
5854 /* ignore_input will not return true for ENDI, so we don't need to
5855 worry about checking it again here. */
5857 if (! mri_control_stack
->else_seen
)
5858 colon (mri_control_stack
->next
);
5859 colon (mri_control_stack
->bottom
);
5865 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5866 ++input_line_pointer
;
5869 demand_empty_rest_of_line ();
5872 /* Handle the MRI BREAK pseudo-op. */
5875 s_mri_break (extent
)
5878 struct mri_control_info
*n
;
5882 n
= mri_control_stack
;
5884 && n
->type
!= mri_for
5885 && n
->type
!= mri_repeat
5886 && n
->type
!= mri_while
)
5890 as_bad ("break outside of structured loop");
5891 ignore_rest_of_line ();
5895 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
5898 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
5904 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5905 ++input_line_pointer
;
5908 demand_empty_rest_of_line ();
5911 /* Handle the MRI NEXT pseudo-op. */
5917 struct mri_control_info
*n
;
5921 n
= mri_control_stack
;
5923 && n
->type
!= mri_for
5924 && n
->type
!= mri_repeat
5925 && n
->type
!= mri_while
)
5929 as_bad ("next outside of structured loop");
5930 ignore_rest_of_line ();
5934 buf
= (char *) xmalloc (20 + strlen (n
->next
));
5937 sprintf (buf
, "bra%s %s", ex
, n
->next
);
5943 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5944 ++input_line_pointer
;
5947 demand_empty_rest_of_line ();
5950 /* Handle the MRI FOR pseudo-op. */
5956 const char *varstart
, *varstop
;
5957 const char *initstart
, *initstop
;
5958 const char *endstart
, *endstop
;
5959 const char *bystart
, *bystop
;
5963 struct mri_control_info
*n
;
5969 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
5973 varstart
= input_line_pointer
;
5975 /* Look for the '='. */
5976 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
5977 && *input_line_pointer
!= '=')
5978 ++input_line_pointer
;
5979 if (*input_line_pointer
!= '=')
5981 as_bad ("missing =");
5982 ignore_rest_of_line ();
5986 varstop
= input_line_pointer
;
5987 if (varstop
> varstart
5988 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
5991 ++input_line_pointer
;
5993 initstart
= input_line_pointer
;
5995 /* Look for TO or DOWNTO. */
5998 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6000 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6001 && ! is_part_of_name (input_line_pointer
[2]))
6003 initstop
= input_line_pointer
;
6004 input_line_pointer
+= 2;
6007 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6008 && ! is_part_of_name (input_line_pointer
[6]))
6010 initstop
= input_line_pointer
;
6012 input_line_pointer
+= 6;
6015 ++input_line_pointer
;
6017 if (initstop
== NULL
)
6019 as_bad ("missing to or downto");
6020 ignore_rest_of_line ();
6023 if (initstop
> initstart
6024 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6028 endstart
= input_line_pointer
;
6030 /* Look for BY or DO. */
6033 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6035 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6036 && ! is_part_of_name (input_line_pointer
[2]))
6038 endstop
= input_line_pointer
;
6040 input_line_pointer
+= 2;
6043 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6044 && (input_line_pointer
[2] == '.'
6045 || ! is_part_of_name (input_line_pointer
[2])))
6047 endstop
= input_line_pointer
;
6048 input_line_pointer
+= 2;
6051 ++input_line_pointer
;
6053 if (endstop
== NULL
)
6055 as_bad ("missing do");
6056 ignore_rest_of_line ();
6059 if (endstop
> endstart
6060 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6066 bystop
= bystart
+ 2;
6071 bystart
= input_line_pointer
;
6075 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6077 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6078 && (input_line_pointer
[2] == '.'
6079 || ! is_part_of_name (input_line_pointer
[2])))
6081 bystop
= input_line_pointer
;
6082 input_line_pointer
+= 2;
6085 ++input_line_pointer
;
6089 as_bad ("missing do");
6090 ignore_rest_of_line ();
6093 if (bystop
> bystart
6094 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6098 if (*input_line_pointer
!= '.')
6102 extent
= input_line_pointer
[1];
6103 input_line_pointer
+= 2;
6106 /* We have fully parsed the FOR operands. Now build the loop. */
6108 n
= push_mri_control (mri_for
);
6110 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6121 memcpy (s
, initstart
, initstop
- initstart
);
6122 s
+= initstop
- initstart
;
6124 memcpy (s
, varstart
, varstop
- varstart
);
6125 s
+= varstop
- varstart
;
6139 memcpy (s
, endstart
, endstop
- endstart
);
6140 s
+= endstop
- endstart
;
6142 memcpy (s
, varstart
, varstop
- varstart
);
6143 s
+= varstop
- varstart
;
6151 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6153 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6156 /* Put together the add or sub instruction used by ENDF. */
6166 memcpy (s
, bystart
, bystop
- bystart
);
6167 s
+= bystop
- bystart
;
6169 memcpy (s
, varstart
, varstop
- varstart
);
6170 s
+= varstop
- varstart
;
6176 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6177 ++input_line_pointer
;
6180 demand_empty_rest_of_line ();
6183 /* Handle the MRI ENDF pseudo-op. */
6189 if (mri_control_stack
== NULL
6190 || mri_control_stack
->type
!= mri_for
)
6192 as_bad ("endf without for");
6193 ignore_rest_of_line ();
6197 colon (mri_control_stack
->next
);
6199 md_assemble (mri_control_stack
->incr
);
6201 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6202 md_assemble (mri_control_stack
->incr
);
6204 free (mri_control_stack
->incr
);
6206 colon (mri_control_stack
->bottom
);
6212 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6213 ++input_line_pointer
;
6216 demand_empty_rest_of_line ();
6219 /* Handle the MRI REPEAT pseudo-op. */
6222 s_mri_repeat (ignore
)
6225 struct mri_control_info
*n
;
6227 n
= push_mri_control (mri_repeat
);
6231 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6232 ++input_line_pointer
;
6234 demand_empty_rest_of_line ();
6237 /* Handle the MRI UNTIL pseudo-op. */
6245 if (mri_control_stack
== NULL
6246 || mri_control_stack
->type
!= mri_repeat
)
6248 as_bad ("until without repeat");
6249 ignore_rest_of_line ();
6253 colon (mri_control_stack
->next
);
6255 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6258 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6259 mri_control_stack
->top
, '\0');
6261 colon (mri_control_stack
->bottom
);
6263 input_line_pointer
= s
;
6269 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6270 ++input_line_pointer
;
6273 demand_empty_rest_of_line ();
6276 /* Handle the MRI WHILE pseudo-op. */
6284 struct mri_control_info
*n
;
6286 s
= input_line_pointer
;
6287 while (! is_end_of_line
[(unsigned char) *s
]
6288 && (! flag_mri
|| *s
!= '*'))
6291 while (*s
== ' ' || *s
== '\t')
6293 if (s
- input_line_pointer
> 1
6296 if (s
- input_line_pointer
< 2
6297 || strncasecmp (s
- 1, "DO", 2) != 0)
6299 as_bad ("missing do");
6300 ignore_rest_of_line ();
6304 n
= push_mri_control (mri_while
);
6308 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6309 s
[1] == '.' ? s
[2] : '\0');
6311 input_line_pointer
= s
+ 1;
6312 if (*input_line_pointer
== '.')
6313 input_line_pointer
+= 2;
6317 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6318 ++input_line_pointer
;
6321 demand_empty_rest_of_line ();
6324 /* Handle the MRI ENDW pseudo-op. */
6332 if (mri_control_stack
== NULL
6333 || mri_control_stack
->type
!= mri_while
)
6335 as_bad ("endw without while");
6336 ignore_rest_of_line ();
6340 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6341 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6345 colon (mri_control_stack
->bottom
);
6351 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6352 ++input_line_pointer
;
6355 demand_empty_rest_of_line ();
6360 * Invocation line includes a switch not recognized by the base assembler.
6361 * See if it's a processor-specific option. These are:
6363 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6364 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6365 * Select the architecture. Instructions or features not
6366 * supported by the selected architecture cause fatal
6367 * errors. More than one may be specified. The default is
6368 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6369 * for -m68000, and -m68882 is a synonym for -m68881.
6370 * -[A]m[c]no-68851, -[A]m[c]no-68881
6371 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6372 * so don't use or document it, but that's the way the parsing
6375 * -pic Indicates PIC.
6376 * -k Indicates PIC. (Sun 3 only.)
6379 * Permit `|' to be used in expressions.
6384 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6386 CONST
char *md_shortopts
= "lSA:m:k";
6389 struct option md_longopts
[] = {
6390 #define OPTION_PIC (OPTION_MD_BASE)
6391 {"pic", no_argument
, NULL
, OPTION_PIC
},
6392 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6393 {"register-prefix-optional", no_argument
, NULL
,
6394 OPTION_REGISTER_PREFIX_OPTIONAL
},
6395 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6396 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
6397 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6398 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
6399 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6400 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
6401 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6402 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
6403 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6404 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
6405 {NULL
, no_argument
, NULL
, 0}
6407 size_t md_longopts_size
= sizeof(md_longopts
);
6410 md_parse_option (c
, arg
)
6416 case 'l': /* -l means keep external to 2 bit offset
6417 rather than 16 bit one */
6418 flag_short_refs
= 1;
6421 case 'S': /* -S means that jbsr's always turn into
6423 flag_long_jumps
= 1;
6429 /* intentional fall-through */
6432 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6436 const char *oarg
= arg
;
6442 if (arg
[0] == 'c' && arg
[1] == '6')
6445 for (i
= 0; i
< n_archs
; i
++)
6446 if (!strcmp (arg
, archs
[i
].name
))
6451 as_bad ("unrecognized option `%s'", oarg
);
6454 arch
= archs
[i
].arch
;
6457 else if (arch
== m68851
)
6466 if (arg
[0] == 'c' && arg
[1] == '6')
6469 for (i
= 0; i
< n_archs
; i
++)
6470 if (!strcmp (arg
, archs
[i
].name
))
6472 unsigned long arch
= archs
[i
].arch
;
6473 if (cpu_of_arch (arch
))
6474 /* It's a cpu spec. */
6476 current_architecture
&= ~m68000up
;
6477 current_architecture
|= arch
;
6479 else if (arch
== m68881
)
6481 current_architecture
|= m68881
;
6484 else if (arch
== m68851
)
6486 current_architecture
|= m68851
;
6496 as_bad ("unrecognized architecture specification `%s'", arg
);
6505 break; /* -pic, Position Independent Code */
6507 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6508 flag_reg_prefix_optional
= 1;
6509 reg_prefix_optional_seen
= 1;
6512 /* -V: SVR4 argument to print version ID. */
6514 print_version_id ();
6517 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6518 should be emitted or not. FIXME: Not implemented. */
6522 case OPTION_BITWISE_OR
:
6527 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
6529 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
6533 m68k_comment_chars
= n
;
6537 case OPTION_BASE_SIZE_DEFAULT_16
:
6538 m68k_index_width_default
= SIZE_WORD
;
6541 case OPTION_BASE_SIZE_DEFAULT_32
:
6542 m68k_index_width_default
= SIZE_LONG
;
6545 case OPTION_DISP_SIZE_DEFAULT_16
:
6547 m68k_rel32_from_cmdline
= 1;
6550 case OPTION_DISP_SIZE_DEFAULT_32
:
6552 m68k_rel32_from_cmdline
= 1;
6563 md_show_usage (stream
)
6568 -l use 1 word for refs to undefined symbols [default 2]\n\
6569 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6570 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6571 | -mcpu32 | -m5200\n\
6572 specify variant of 680X0 architecture [default 68020]\n\
6573 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6574 target has/lacks floating-point coprocessor\n\
6575 [default yes for 68020, 68030, and cpu32]\n");
6577 -m68851 | -mno-68851\n\
6578 target has/lacks memory-management unit coprocessor\n\
6579 [default yes for 68020 and up]\n\
6580 -pic, -k generate position independent code\n\
6581 -S turn jbsr into jsr\n\
6582 --register-prefix-optional\n\
6583 recognize register names without prefix character\n\
6584 --bitwise-or do not treat `|' as a comment character\n");
6586 --base-size-default-16 base reg without size is 16 bits\n\
6587 --base-size-default-32 base reg without size is 32 bits (default)\n\
6588 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6589 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n");
6594 /* TEST2: Test md_assemble() */
6595 /* Warning, this routine probably doesn't work anymore */
6599 struct m68k_it the_ins
;
6607 if (!gets (buf
) || !*buf
)
6609 if (buf
[0] == '|' || buf
[1] == '.')
6611 for (cp
= buf
; *cp
; cp
++)
6616 memset (&the_ins
, '\0', sizeof (the_ins
));
6617 m68k_ip (&the_ins
, buf
);
6620 printf ("Error %s in %s\n", the_ins
.error
, buf
);
6624 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
6625 for (n
= 0; n
< the_ins
.numo
; n
++)
6626 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
6628 print_the_insn (&the_ins
.opcode
[0], stdout
);
6629 (void) putchar ('\n');
6631 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
6633 if (the_ins
.operands
[n
].error
)
6635 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
6638 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
6639 if (the_ins
.operands
[n
].b_const
)
6640 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
6641 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
6642 if (the_ins
.operands
[n
].b_iadd
)
6643 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
6644 (void) putchar ('\n');
6656 while (*str
&& *str
!= ' ')
6658 if (str
[-1] == ':' || str
[1] == '=')
6665 /* Possible states for relaxation:
6667 0 0 branch offset byte (bra, etc)
6671 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6675 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6682 /* We have no need to default values of symbols. */
6686 md_undefined_symbol (name
)
6692 /* Round up a section size to the appropriate boundary. */
6694 md_section_align (segment
, size
)
6698 return size
; /* Byte alignment is fine */
6701 /* Exactly what point is a PC-relative offset relative TO?
6702 On the 68k, it is relative to the address of the first extension
6703 word. The difference between the addresses of the offset and the
6704 first extension word is stored in fx_pcrel_adjust. */
6706 md_pcrel_from (fixP
)
6711 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6713 adjust
= fixP
->fx_pcrel_adjust
;
6716 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
6719 #ifndef BFD_ASSEMBLER
6722 tc_coff_symbol_emit_hook (ignore
)
6728 tc_coff_sizemachdep (frag
)
6731 switch (frag
->fr_subtype
& 0x3)
6746 /* end of tc-m68k.c */