1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "opcode/m68k.h"
27 #include "m68k-parse.h"
29 /* This array holds the chars that always start a comment. If the
30 pre-processor is disabled, these aren't very useful */
31 #if defined (OBJ_ELF) || defined (TE_DELTA)
32 const char comment_chars
[] = "|#";
34 const char comment_chars
[] = "|";
37 /* This array holds the chars that only start a comment at the beginning of
38 a line. If the line seems to have the form '# 123 filename'
39 .line and .file directives will appear in the pre-processed output */
40 /* Note that input_file.c hand checks for '#' at the beginning of the
41 first line of the input file. This is because the compiler outputs
42 #NO_APP at the beginning of its output. */
43 /* Also note that comments like this one will always work. */
44 const char line_comment_chars
[] = "#";
46 const char line_separator_chars
[] = "";
48 /* Chars that can be used to separate mant from exp in floating point nums */
49 CONST
char EXP_CHARS
[] = "eE";
51 /* Chars that mean this number is a floating point constant, as
52 in "0f12.456" or "0d1.2345e12". */
54 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
56 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
57 changed in read.c . Ideally it shouldn't have to know about it at all,
58 but nothing is ideal around here. */
60 const int md_reloc_size
= 8; /* Size of relocation record */
62 /* Are we trying to generate PIC code? If so, absolute references
63 ought to be made into linkage table references or pc-relative
64 references. Not implemented. For ELF there are other means
65 to denote pic relocations. */
68 static int flag_short_refs
; /* -l option */
69 static int flag_long_jumps
; /* -S option */
71 #ifdef REGISTER_PREFIX_OPTIONAL
72 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
74 int flag_reg_prefix_optional
;
77 /* The floating point coprocessor to use by default. */
78 static enum m68k_register m68k_float_copnum
= COP1
;
80 /* If this is non-zero, then references to number(%pc) will be taken
81 to refer to number, rather than to %pc + number. */
82 static int m68k_abspcadd
;
84 /* If this is non-zero, then the quick forms of the move, add, and sub
85 instructions are used when possible. */
86 static int m68k_quick
= 1;
88 /* If this is non-zero, then if the size is not specified for a base
89 or outer displacement, the assembler assumes that the size should
91 static int m68k_rel32
= 1;
93 /* Its an arbitrary name: This means I don't approve of it */
94 /* See flames below */
95 static struct obstack robyn
;
97 #define TAB(x,y) (((x)<<2)+(y))
98 #define TABTYPE(xy) ((xy) >> 2)
104 /* Case `g' except when BCC68000 is applicable. */
106 /* Coprocessor branches. */
108 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
109 supported on all cpus. Widens to 32-bit absolute. */
111 /* For inserting an extra jmp instruction with long offset on 68000,
112 for expanding conditional branches. (Not bsr or bra.) Since the
113 68000 doesn't support 32-bit displacements for conditional
114 branches, we fake it by reversing the condition and branching
115 around a jmp with an absolute long operand. */
117 /* For the DBcc "instructions". If the displacement requires 32 bits,
118 the branch-around-a-jump game is played here too. */
120 /* Not currently used? */
122 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
128 const char *m_operands
;
129 unsigned long m_opcode
;
133 struct m68k_incant
*m_next
;
136 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
137 #define gettwo(x) (((x)->m_opcode)&0xffff)
139 static const enum m68k_register m68000_control_regs
[] = { 0 };
140 static const enum m68k_register m68010_control_regs
[] = {
144 static const enum m68k_register m68020_control_regs
[] = {
145 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
148 static const enum m68k_register m68040_control_regs
[] = {
149 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
150 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
153 static const enum m68k_register m68060_control_regs
[] = {
154 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
155 USP
, VBR
, URP
, SRP
, PCR
,
158 #define cpu32_control_regs m68010_control_regs
160 static const enum m68k_register
*control_regs
;
162 /* internal form of a 68020 instruction */
166 const char *args
; /* list of opcode info */
169 int numo
; /* Number of shorts in opcode */
172 struct m68k_op operands
[6];
174 int nexp
; /* number of exprs in use */
175 struct m68k_exp exprs
[4];
177 int nfrag
; /* Number of frags we have to produce */
180 int fragoff
; /* Where in the current opcode the frag ends */
187 int nrel
; /* Num of reloc strucs in use */
194 /* In a pc relative address the difference between the address
195 of the offset and the address that the offset is relative
196 to. This depends on the addressing mode. Basically this
197 is the value to put in the offset field to address the
198 first byte of the offset, without regarding the special
199 significance of some values (in the branch instruction, for
203 /* Whether this expression needs special pic relocation, and if
205 enum pic_relocation pic_reloc
;
208 reloc
[5]; /* Five is enough??? */
211 #define cpu_of_arch(x) ((x) & m68000up)
212 #define float_of_arch(x) ((x) & mfloat)
213 #define mmu_of_arch(x) ((x) & mmmu)
215 static struct m68k_it the_ins
; /* the instruction being assembled */
217 #define op(ex) ((ex)->exp.X_op)
218 #define adds(ex) ((ex)->exp.X_add_symbol)
219 #define subs(ex) ((ex)->exp.X_op_symbol)
220 #define offs(ex) ((ex)->exp.X_add_number)
222 /* Macros for adding things to the m68k_it struct */
224 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
226 /* Like addword, but goes BEFORE general operands */
230 struct m68k_incant
*opcode
;
233 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
234 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
235 for(z
=0;z
<the_ins
.nrel
;z
++)
236 the_ins
.reloc
[z
].n
+=2;
237 for (z
= 0; z
< the_ins
.nfrag
; z
++)
238 the_ins
.fragb
[z
].fragoff
++;
239 the_ins
.opcode
[opcode
->m_codenum
]=w
;
243 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
246 add_fix (width
, exp
, pc_rel
, pc_fix
)
248 struct m68k_exp
*exp
;
252 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
256 : (the_ins
.numo
*2)));
257 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
258 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
259 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
261 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
263 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
266 /* Cause an extra frag to be generated here, inserting up to 10 bytes
267 (that value is chosen in the frag_var call in md_assemble). TYPE
268 is the subtype of the frag to be generated; its primary type is
269 rs_machine_dependent.
271 The TYPE parameter is also used by md_convert_frag_1 and
272 md_estimate_size_before_relax. The appropriate type of fixup will
273 be emitted by md_convert_frag_1.
275 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
277 add_frag(add
,off
,type
)
282 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
283 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
284 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
285 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
289 (op (ex) != O_constant && op (ex) != O_big)
291 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
292 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
293 static int reverse_16_bits
PARAMS ((int in
));
294 static int reverse_8_bits
PARAMS ((int in
));
295 static void install_gen_operand
PARAMS ((int mode
, int val
));
296 static void install_operand
PARAMS ((int mode
, int val
));
297 static void s_bss
PARAMS ((int));
298 static void s_data1
PARAMS ((int));
299 static void s_data2
PARAMS ((int));
300 static void s_even
PARAMS ((int));
301 static void s_proc
PARAMS ((int));
302 static void mri_chip
PARAMS ((void));
303 static void s_chip
PARAMS ((int));
304 static void s_fopt
PARAMS ((int));
305 static void s_opt
PARAMS ((int));
306 static void s_reg
PARAMS ((int));
307 static void s_restore
PARAMS ((int));
308 static void s_save
PARAMS ((int));
309 static void s_mri_if
PARAMS ((int));
310 static void s_mri_else
PARAMS ((int));
311 static void s_mri_endi
PARAMS ((int));
312 static void s_mri_break
PARAMS ((int));
313 static void s_mri_next
PARAMS ((int));
314 static void s_mri_for
PARAMS ((int));
315 static void s_mri_endf
PARAMS ((int));
316 static void s_mri_repeat
PARAMS ((int));
317 static void s_mri_until
PARAMS ((int));
318 static void s_mri_while
PARAMS ((int));
319 static void s_mri_endw
PARAMS ((int));
321 static int current_architecture
;
329 static const struct m68k_cpu archs
[] = {
330 { m68000
, "68000", 0 },
331 { m68010
, "68010", 0 },
332 { m68020
, "68020", 0 },
333 { m68030
, "68030", 0 },
334 { m68040
, "68040", 0 },
335 { m68060
, "68060", 0 },
336 { cpu32
, "cpu32", 0 },
337 { m68881
, "68881", 0 },
338 { m68851
, "68851", 0 },
339 /* Aliases (effectively, so far as gas is concerned) for the above
341 { m68020
, "68k", 1 },
342 { m68000
, "68302", 1 },
343 { m68000
, "68008", 1 },
344 { m68000
, "68ec000", 1 },
345 { m68000
, "68hc000", 1 },
346 { m68000
, "68hc001", 1 },
347 { m68020
, "68ec020", 1 },
348 { m68030
, "68ec030", 1 },
349 { m68040
, "68ec040", 1 },
350 { cpu32
, "68330", 1 },
351 { cpu32
, "68331", 1 },
352 { cpu32
, "68332", 1 },
353 { cpu32
, "68333", 1 },
354 { cpu32
, "68340", 1 },
355 { cpu32
, "68360", 1 },
356 { m68881
, "68882", 1 },
359 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
361 /* BCC68000 is for patching in an extra jmp instruction for long offsets
362 on the 68000. The 68000 doesn't support long branches with branchs */
364 /* This table desribes how you change sizes for the various types of variable
365 size expressions. This version only supports two kinds. */
367 /* Note that calls to frag_var need to specify the maximum expansion
368 needed; this is currently 10 bytes for DBCC. */
371 How far Forward this mode will reach:
372 How far Backward this mode will reach:
373 How many bytes this mode will add to the size of the frag
374 Which mode to go to if the offset won't fit in this one
376 relax_typeS md_relax_table
[] =
378 {1, 1, 0, 0}, /* First entries aren't used */
379 {1, 1, 0, 0}, /* For no good reason except */
380 {1, 1, 0, 0}, /* that the VAX doesn't either */
383 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
384 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
388 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
389 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
393 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
394 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
398 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
399 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
400 {0, 0, 6, 0}, /* jmp long space */
403 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
404 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
405 {0, 0, 10, 0}, /* bra/jmp long space */
408 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
409 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
413 /* For, e.g., jmp pcrel indexed. */
414 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
415 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
420 /* These are the machine dependent pseudo-ops. These are included so
421 the assembler can work on the output from the SUN C compiler, which
425 /* This table describes all the machine specific pseudo-ops the assembler
426 has to support. The fields are:
427 pseudo-op name without dot
428 function to call to execute this pseudo-op
429 Integer arg to pass to the function
431 const pseudo_typeS md_pseudo_table
[] =
433 {"data1", s_data1
, 0},
434 {"data2", s_data2
, 0},
437 {"skip", s_space
, 0},
439 #if defined (TE_SUN3) || defined (OBJ_ELF)
440 {"align", s_align_bytes
, 0},
443 {"swbeg", s_ignore
, 0},
445 {"extend", float_cons
, 'x'},
446 {"ldouble", float_cons
, 'x'},
448 /* The following pseudo-ops are supported for MRI compatibility. */
450 {"comline", s_space
, 1},
452 {"mask2", s_ignore
, 0},
455 {"restore", s_restore
, 0},
459 {"if.b", s_mri_if
, 'b'},
460 {"if.w", s_mri_if
, 'w'},
461 {"if.l", s_mri_if
, 'l'},
462 {"else", s_mri_else
, 0},
463 {"else.s", s_mri_else
, 's'},
464 {"else.l", s_mri_else
, 'l'},
465 {"endi", s_mri_endi
, 0},
466 {"break", s_mri_break
, 0},
467 {"break.s", s_mri_break
, 's'},
468 {"break.l", s_mri_break
, 'l'},
469 {"next", s_mri_next
, 0},
470 {"next.s", s_mri_next
, 's'},
471 {"next.l", s_mri_next
, 'l'},
472 {"for", s_mri_for
, 0},
473 {"for.b", s_mri_for
, 'b'},
474 {"for.w", s_mri_for
, 'w'},
475 {"for.l", s_mri_for
, 'l'},
476 {"endf", s_mri_endf
, 0},
477 {"repeat", s_mri_repeat
, 0},
478 {"until", s_mri_until
, 0},
479 {"until.b", s_mri_until
, 'b'},
480 {"until.w", s_mri_until
, 'w'},
481 {"until.l", s_mri_until
, 'l'},
482 {"while", s_mri_while
, 0},
483 {"while.b", s_mri_while
, 'b'},
484 {"while.w", s_mri_while
, 'w'},
485 {"while.l", s_mri_while
, 'l'},
486 {"endw", s_mri_endw
, 0},
492 /* The mote pseudo ops are put into the opcode table, since they
493 don't start with a . they look like opcodes to gas.
495 extern void obj_coff_section ();
497 CONST pseudo_typeS mote_pseudo_table
[] =
510 {"xdef", s_globl
, 0},
512 {"align", s_align_bytes
, 0},
514 {"align", s_align_ptwo
, 0},
517 {"sect", obj_coff_section
, 0},
518 {"section", obj_coff_section
, 0},
523 #define issbyte(x) ((x)>=-128 && (x)<=127)
524 #define isubyte(x) ((x)>=0 && (x)<=255)
525 #define issword(x) ((x)>=-32768 && (x)<=32767)
526 #define isuword(x) ((x)>=0 && (x)<=65535)
528 #define isbyte(x) ((x)>= -255 && (x)<=255)
529 #define isword(x) ((x)>=-65536 && (x)<=65535)
530 #define islong(x) (1)
532 extern char *input_line_pointer
;
534 static char mklower_table
[256];
535 #define mklower(c) (mklower_table[(unsigned char)(c)])
536 static char notend_table
[256];
537 static char alt_notend_table
[256];
539 (! (notend_table[(unsigned char) *s] \
541 && alt_notend_table[(unsigned char) s[1]])))
543 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
545 #ifdef NO_PCREL_RELOCS
548 make_pcrel_absolute(fixP
, add_number
)
552 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
554 /* rewrite the PC relative instructions to absolute address ones.
555 * these are rumoured to be faster, and the apollo linker refuses
556 * to deal with the PC relative relocations.
558 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
563 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
569 as_fatal ("Unknown PC relative instruction");
574 #endif /* NO_PCREL_RELOCS */
577 tc_coff_fix2rtype (fixP
)
580 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
581 return R_RELLONG_NEG
;
582 #ifdef NO_PCREL_RELOCS
583 know (fixP
->fx_pcrel
== 0);
584 return (fixP
->fx_size
== 1 ? R_RELBYTE
585 : fixP
->fx_size
== 2 ? R_DIR16
588 return (fixP
->fx_pcrel
?
589 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
590 fixP
->fx_size
== 2 ? R_PCRWORD
:
592 (fixP
->fx_size
== 1 ? R_RELBYTE
:
593 fixP
->fx_size
== 2 ? R_RELWORD
:
602 /* Compute the relocation code for a fixup of SIZE bytes, using pc
603 relative relocation if PCREL is non-zero. PIC says whether a special
604 pic relocation was requested. */
606 static bfd_reloc_code_real_type get_reloc_code
607 PARAMS ((int, int, enum pic_relocation
));
609 static bfd_reloc_code_real_type
610 get_reloc_code (size
, pcrel
, pic
)
613 enum pic_relocation pic
;
621 return BFD_RELOC_8_GOT_PCREL
;
623 return BFD_RELOC_16_GOT_PCREL
;
625 return BFD_RELOC_32_GOT_PCREL
;
633 return BFD_RELOC_8_GOTOFF
;
635 return BFD_RELOC_16_GOTOFF
;
637 return BFD_RELOC_32_GOTOFF
;
645 return BFD_RELOC_8_PLT_PCREL
;
647 return BFD_RELOC_16_PLT_PCREL
;
649 return BFD_RELOC_32_PLT_PCREL
;
657 return BFD_RELOC_8_PLTOFF
;
659 return BFD_RELOC_16_PLTOFF
;
661 return BFD_RELOC_32_PLTOFF
;
671 return BFD_RELOC_8_PCREL
;
673 return BFD_RELOC_16_PCREL
;
675 return BFD_RELOC_32_PCREL
;
692 as_bad ("Can not do %d byte %s%srelocation", size
,
693 pcrel
? "pc-relative " : "",
694 pic
== pic_none
? "" : "pic ");
695 return BFD_RELOC_NONE
;
698 /* Here we decide which fixups can be adjusted to make them relative
699 to the beginning of the section instead of the symbol. Basically
700 we need to make sure that the dynamic relocations are done
701 correctly, so in some cases we force the original symbol to be
704 tc_m68k_fix_adjustable (fixP
)
707 /* Prevent all adjustments to global symbols. */
708 if (S_IS_EXTERNAL (fixP
->fx_addsy
))
711 /* adjust_reloc_syms doesn't know about the GOT */
712 switch (fixP
->fx_r_type
)
714 case BFD_RELOC_8_GOT_PCREL
:
715 case BFD_RELOC_16_GOT_PCREL
:
716 case BFD_RELOC_32_GOT_PCREL
:
717 case BFD_RELOC_8_GOTOFF
:
718 case BFD_RELOC_16_GOTOFF
:
719 case BFD_RELOC_32_GOTOFF
:
720 case BFD_RELOC_8_PLT_PCREL
:
721 case BFD_RELOC_16_PLT_PCREL
:
722 case BFD_RELOC_32_PLT_PCREL
:
723 case BFD_RELOC_8_PLTOFF
:
724 case BFD_RELOC_16_PLTOFF
:
725 case BFD_RELOC_32_PLTOFF
:
735 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
742 tc_gen_reloc (section
, fixp
)
747 bfd_reloc_code_real_type code
;
752 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
753 code
= fixp
->fx_r_type
;
756 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
757 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
759 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
760 MAP (1, 0, BFD_RELOC_8
);
761 MAP (2, 0, BFD_RELOC_16
);
762 MAP (4, 0, BFD_RELOC_32
);
763 MAP (1, 1, BFD_RELOC_8_PCREL
);
764 MAP (2, 1, BFD_RELOC_16_PCREL
);
765 MAP (4, 1, BFD_RELOC_32_PCREL
);
773 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
775 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
776 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
779 reloc
->addend
= fixp
->fx_addnumber
;
784 reloc
->addend
= fixp
->fx_addnumber
;
785 else if ((fixp
->fx_addsy
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
786 reloc
->addend
= (section
->vma
787 + (fixp
->fx_pcrel_adjust
== 64
788 ? -1 : fixp
->fx_pcrel_adjust
)
790 + md_pcrel_from (fixp
));
792 reloc
->addend
= (fixp
->fx_offset
793 + (fixp
->fx_pcrel_adjust
== 64
794 ? -1 : fixp
->fx_pcrel_adjust
));
797 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
798 assert (reloc
->howto
!= 0);
803 #endif /* BFD_ASSEMBLER */
805 /* Handle of the OPCODE hash table. NULL means any use before
806 m68k_ip_begin() will crash. */
807 static struct hash_control
*op_hash
;
809 /* Assemble an m68k instruction. */
816 register struct m68k_op
*opP
;
817 register struct m68k_incant
*opcode
;
818 register const char *s
;
819 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
820 char *pdot
, *pdotmove
;
821 enum m68k_size siz1
, siz2
;
825 char *crack_operand ();
826 LITTLENUM_TYPE words
[6];
827 LITTLENUM_TYPE
*wordp
;
828 unsigned long ok_arch
= 0;
830 if (*instring
== ' ')
831 instring
++; /* skip leading whitespace */
833 /* Scan up to end of operation-code, which MUST end in end-of-string
834 or exactly 1 space. */
836 for (p
= instring
; *p
!= '\0'; p
++)
846 the_ins
.error
= "No operator";
850 /* p now points to the end of the opcode name, probably whitespace.
851 Make sure the name is null terminated by clobbering the
852 whitespace, look it up in the hash table, then fix it back.
853 Remove a dot, first, since the opcode tables have none. */
856 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
857 *pdotmove
= pdotmove
[1];
863 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
868 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
869 *pdotmove
= pdotmove
[-1];
876 the_ins
.error
= "Unknown operator";
880 /* found a legitimate opcode, start matching operands */
884 if (opcode
->m_operands
== 0)
886 char *old
= input_line_pointer
;
888 input_line_pointer
= p
;
889 /* Ahh - it's a motorola style psuedo op */
890 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
891 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
892 input_line_pointer
= old
;
898 if (flag_mri
&& opcode
->m_opnum
== 0)
900 /* In MRI mode, random garbage is allowed after an instruction
901 which accepts no operands. */
902 the_ins
.args
= opcode
->m_operands
;
903 the_ins
.numargs
= opcode
->m_opnum
;
904 the_ins
.numo
= opcode
->m_codenum
;
905 the_ins
.opcode
[0] = getone (opcode
);
906 the_ins
.opcode
[1] = gettwo (opcode
);
910 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
912 p
= crack_operand (p
, opP
);
916 the_ins
.error
= opP
->error
;
921 opsfound
= opP
- &the_ins
.operands
[0];
923 /* This ugly hack is to support the floating pt opcodes in their
924 standard form. Essentially, we fake a first enty of type COP#1 */
925 if (opcode
->m_operands
[0] == 'I')
929 for (n
= opsfound
; n
> 0; --n
)
930 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
932 memset ((char *) (&the_ins
.operands
[0]), '\0',
933 sizeof (the_ins
.operands
[0]));
934 the_ins
.operands
[0].mode
= CONTROL
;
935 the_ins
.operands
[0].reg
= m68k_float_copnum
;
939 /* We've got the operands. Find an opcode that'll accept them */
942 /* If we didn't get the right number of ops, or we have no
943 common model with this pattern then reject this pattern. */
945 if (opsfound
!= opcode
->m_opnum
946 || ((opcode
->m_arch
& current_architecture
) == 0))
949 ok_arch
|= opcode
->m_arch
;
953 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
957 /* Warning: this switch is huge! */
958 /* I've tried to organize the cases into this order:
959 non-alpha first, then alpha by letter. Lower-case
960 goes directly before uppercase counterpart. */
961 /* Code with multiple case ...: gets sorted by the lowest
962 case ... it belongs to. I hope this makes sense. */
1002 if (opP
->mode
!= IMMED
)
1004 else if (s
[1] == 'b'
1005 && ! isvar (&opP
->disp
)
1006 && (opP
->disp
.exp
.X_op
!= O_constant
1007 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1009 else if (s
[1] == 'w'
1010 && ! isvar (&opP
->disp
)
1011 && (opP
->disp
.exp
.X_op
!= O_constant
1012 || ! isword (opP
->disp
.exp
.X_add_number
)))
1014 else if (s
[1] == 'W'
1015 && ! isvar (&opP
->disp
)
1016 && (opP
->disp
.exp
.X_op
!= O_constant
1017 || ! issword (opP
->disp
.exp
.X_add_number
)))
1023 if (opP
->mode
!= IMMED
)
1028 if (opP
->mode
== AREG
1029 || opP
->mode
== CONTROL
1030 || opP
->mode
== FPREG
1031 || opP
->mode
== IMMED
1032 || opP
->mode
== REGLST
1033 || (opP
->mode
!= ABSL
1035 || opP
->reg
== ZPC
)))
1040 if (opP
->mode
== CONTROL
1041 || opP
->mode
== FPREG
1042 || opP
->mode
== REGLST
1043 || opP
->mode
== IMMED
1044 || (opP
->mode
!= ABSL
1046 || opP
->reg
== ZPC
)))
1074 if (opP
->mode
== CONTROL
1075 || opP
->mode
== FPREG
1076 || opP
->mode
== REGLST
)
1081 if (opP
->mode
!= AINC
)
1086 if (opP
->mode
!= ADEC
)
1136 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1157 case '~': /* For now! (JF FOO is this right?) */
1179 if (opP
->mode
!= CONTROL
1180 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1185 if (opP
->mode
!= AREG
)
1190 if (opP
->mode
!= AINDR
)
1195 if (opP
->mode
!= ABSL
1197 && strncmp (instring
, "jbsr", 4) == 0))
1202 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1207 if (opP
->mode
!= DISP
1209 || opP
->reg
> ADDR7
)
1214 if (opP
->mode
!= DREG
)
1219 if (opP
->mode
!= FPREG
)
1224 if (opP
->mode
!= CONTROL
1231 if (opP
->mode
!= CONTROL
1233 || opP
->reg
> last_movec_reg
)
1237 const enum m68k_register
*rp
;
1238 for (rp
= control_regs
; *rp
; rp
++)
1239 if (*rp
== opP
->reg
)
1247 if (opP
->mode
!= IMMED
)
1253 if (opP
->mode
== DREG
1254 || opP
->mode
== AREG
1255 || opP
->mode
== FPREG
)
1264 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1267 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1270 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1278 else if (opP
->mode
== CONTROL
)
1287 opP
->mask
= 1 << 24;
1290 opP
->mask
= 1 << 25;
1293 opP
->mask
= 1 << 26;
1302 else if (opP
->mode
== ABSL
1303 && opP
->disp
.size
== SIZE_UNSPEC
1304 && opP
->disp
.exp
.X_op
== O_constant
)
1306 /* This is what the MRI REG pseudo-op generates. */
1308 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1310 else if (opP
->mode
!= REGLST
)
1312 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1314 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1319 if (opP
->mode
!= IMMED
)
1321 else if (opP
->disp
.exp
.X_op
!= O_constant
1322 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1324 else if (! m68k_quick
1325 && instring
[3] != 'q'
1326 && instring
[4] != 'q')
1331 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1336 if (opP
->mode
!= IMMED
)
1338 else if (opP
->disp
.exp
.X_op
!= O_constant
1339 || opP
->disp
.exp
.X_add_number
< 1
1340 || opP
->disp
.exp
.X_add_number
> 8)
1342 else if (! m68k_quick
1343 && (strncmp (instring
, "add", 3) == 0
1344 || strncmp (instring
, "sub", 3) == 0)
1345 && instring
[3] != 'q')
1350 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1355 if (opP
->mode
!= AINDR
1356 && (opP
->mode
!= BASE
1358 && opP
->reg
!= ZADDR0
)
1359 || opP
->disp
.exp
.X_op
!= O_absent
1360 || ((opP
->index
.reg
< DATA0
1361 || opP
->index
.reg
> DATA7
)
1362 && (opP
->index
.reg
< ADDR0
1363 || opP
->index
.reg
> ADDR7
))
1364 || opP
->index
.size
!= SIZE_UNSPEC
1365 || opP
->index
.scale
!= 1))
1370 if (opP
->mode
!= CONTROL
1371 || ! (opP
->reg
== FPI
1373 || opP
->reg
== FPC
))
1378 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1383 if (opP
->mode
!= IMMED
)
1385 else if (opP
->disp
.exp
.X_op
!= O_constant
1386 || opP
->disp
.exp
.X_add_number
< 0
1387 || opP
->disp
.exp
.X_add_number
> 7)
1392 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1396 /* JF these are out of order. We could put them
1397 in order if we were willing to put up with
1398 bunches of #ifdef m68851s in the code.
1400 Don't forget that you need these operands
1401 to use 68030 MMU instructions. */
1403 /* Memory addressing mode used by pflushr */
1405 if (opP
->mode
== CONTROL
1406 || opP
->mode
== FPREG
1407 || opP
->mode
== DREG
1408 || opP
->mode
== AREG
1409 || opP
->mode
== REGLST
)
1411 /* We should accept immediate operands, but they
1412 supposedly have to be quad word, and we don't
1413 handle that. I would like to see what a Motorola
1414 assembler does before doing something here. */
1415 if (opP
->mode
== IMMED
)
1420 if (opP
->mode
!= CONTROL
1421 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1426 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1431 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1436 if (opP
->mode
!= CONTROL
1439 && opP
->reg
!= SCC
))
1444 if (opP
->mode
!= CONTROL
1450 if (opP
->mode
!= CONTROL
1453 && opP
->reg
!= CRP
))
1458 if (opP
->mode
!= CONTROL
1459 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1460 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1465 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1470 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1475 if (opP
->mode
!= CONTROL
1482 } /* not a cache specifier. */
1486 if (opP
->mode
!= ABSL
)
1492 } /* switch on type of operand */
1496 } /* for each operand */
1497 } /* if immediately wrong */
1504 opcode
= opcode
->m_next
;
1509 && !(ok_arch
& current_architecture
))
1514 "invalid instruction for this architecture; needs ");
1515 cp
= buf
+ strlen (buf
);
1519 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1522 strcpy (cp
, "mmu (68030 or 68851)");
1525 strcpy (cp
, "68020 or higher");
1528 strcpy (cp
, "68000 or higher");
1531 strcpy (cp
, "68010 or higher");
1535 int got_one
= 0, idx
;
1536 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1539 if ((archs
[idx
].arch
& ok_arch
)
1540 && ! archs
[idx
].alias
)
1544 strcpy (cp
, " or ");
1548 strcpy (cp
, archs
[idx
].name
);
1560 the_ins
.error
= "operands mismatch";
1562 } /* Fell off the end */
1567 /* now assemble it */
1569 the_ins
.args
= opcode
->m_operands
;
1570 the_ins
.numargs
= opcode
->m_opnum
;
1571 the_ins
.numo
= opcode
->m_codenum
;
1572 the_ins
.opcode
[0] = getone (opcode
);
1573 the_ins
.opcode
[1] = gettwo (opcode
);
1575 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1577 /* This switch is a doozy.
1578 Watch the first step; its a big one! */
1599 tmpreg
= 0x3c; /* 7.4 */
1600 if (strchr ("bwl", s
[1]))
1601 nextword
= get_num (&opP
->disp
, 80);
1603 nextword
= get_num (&opP
->disp
, 0);
1604 if (isvar (&opP
->disp
))
1605 add_fix (s
[1], &opP
->disp
, 0, 0);
1609 if (!isbyte (nextword
))
1610 opP
->error
= "operand out of range";
1615 if (!isword (nextword
))
1616 opP
->error
= "operand out of range";
1621 if (!issword (nextword
))
1622 opP
->error
= "operand out of range";
1627 addword (nextword
>> 16);
1654 /* We gotta put out some float */
1655 if (op (&opP
->disp
) != O_big
)
1660 /* Can other cases happen here? */
1661 if (op (&opP
->disp
) != O_constant
)
1664 val
= (valueT
) offs (&opP
->disp
);
1668 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1669 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1673 offs (&opP
->disp
) = gencnt
;
1675 if (offs (&opP
->disp
) > 0)
1677 if (offs (&opP
->disp
) > baseo
)
1679 as_warn ("Bignum too big for %c format; truncated",
1681 offs (&opP
->disp
) = baseo
;
1683 baseo
-= offs (&opP
->disp
);
1686 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1687 offs (&opP
->disp
)--;
1692 gen_to_words (words
, baseo
, (long) outro
);
1693 for (wordp
= words
; baseo
--; wordp
++)
1697 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1700 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1703 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1706 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1709 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1713 nextword
= get_num (&opP
->disp
, 80);
1716 && ! isvar (&opP
->disp
)
1719 opP
->disp
.exp
.X_op
= O_symbol
;
1720 #ifndef BFD_ASSEMBLER
1721 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1723 opP
->disp
.exp
.X_add_symbol
=
1724 section_symbol (absolute_section
);
1728 /* Force into index mode. Hope this works */
1730 /* We do the first bit for 32-bit displacements, and the
1731 second bit for 16 bit ones. It is possible that we
1732 should make the default be WORD instead of LONG, but
1733 I think that'd break GCC, so we put up with a little
1734 inefficiency for the sake of working output. */
1736 if (!issword (nextword
)
1737 || (isvar (&opP
->disp
)
1738 && ((opP
->disp
.size
== SIZE_UNSPEC
1739 && flag_short_refs
== 0
1740 && cpu_of_arch (current_architecture
) >= m68020
)
1741 || opP
->disp
.size
== SIZE_LONG
)))
1744 tmpreg
= 0x3B; /* 7.3 */
1746 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1747 if (isvar (&opP
->disp
))
1751 if (opP
->disp
.size
== SIZE_LONG
1753 /* If the displacement needs pic
1754 relocation it cannot be relaxed. */
1755 || opP
->disp
.pic_reloc
!= pic_none
1760 add_fix ('l', &opP
->disp
, 1, 2);
1764 add_frag (adds (&opP
->disp
),
1766 TAB (PCLEA
, SZ_UNDEF
));
1773 add_fix ('l', &opP
->disp
, 0, 0);
1778 addword (nextword
>> 16);
1783 tmpreg
= 0x3A; /* 7.2 */
1785 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1787 if (isvar (&opP
->disp
))
1791 add_fix ('w', &opP
->disp
, 1, 0);
1794 add_fix ('w', &opP
->disp
, 0, 0);
1804 baseo
= get_num (&opP
->disp
, 80);
1805 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1806 outro
= get_num (&opP
->odisp
, 80);
1807 /* Figure out the `addressing mode'.
1808 Also turn on the BASE_DISABLE bit, if needed. */
1809 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1811 tmpreg
= 0x3b; /* 7.3 */
1812 if (opP
->reg
== ZPC
)
1815 else if (opP
->reg
== 0)
1818 tmpreg
= 0x30; /* 6.garbage */
1820 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
1823 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
1826 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1828 siz1
= opP
->disp
.size
;
1829 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1830 siz2
= opP
->odisp
.size
;
1834 /* Index register stuff */
1835 if (opP
->index
.reg
!= 0
1836 && opP
->index
.reg
>= DATA
1837 && opP
->index
.reg
<= ADDR7
)
1839 nextword
|= (opP
->index
.reg
- DATA
) << 12;
1841 if (opP
->index
.size
== SIZE_UNSPEC
1842 || opP
->index
.size
== SIZE_LONG
)
1845 if (cpu_of_arch (current_architecture
) < m68020
)
1847 if (opP
->index
.scale
!= 1)
1850 "scale factor invalid on this architecture; needs 68020 or higher";
1854 switch (opP
->index
.scale
)
1871 GET US OUT OF HERE! */
1873 /* Must be INDEX, with an index register. Address
1874 register cannot be ZERO-PC, and either :b was
1875 forced, or we know it will fit. For a 68000 or
1876 68010, force this mode anyways, because the
1877 larger modes aren't supported. */
1878 if (opP
->mode
== BASE
1879 && ((opP
->reg
>= ADDR0
1880 && opP
->reg
<= ADDR7
)
1883 if (siz1
== SIZE_BYTE
1884 || cpu_of_arch (current_architecture
) < m68020
1885 || (siz1
== SIZE_UNSPEC
1886 && ! isvar (&opP
->disp
)
1887 && issbyte (baseo
)))
1889 nextword
+= baseo
& 0xff;
1891 if (isvar (&opP
->disp
))
1893 /* Do a byte relocation. If it doesn't
1894 fit (possible on m68000) let the
1895 fixup processing complain later. */
1897 add_fix ('B', &opP
->disp
, 1, 1);
1899 add_fix ('B', &opP
->disp
, 0, 0);
1901 else if (siz1
!= SIZE_BYTE
)
1903 if (siz1
!= SIZE_UNSPEC
)
1904 as_warn ("Forcing byte displacement");
1905 if (! issbyte (baseo
))
1906 opP
->error
= "byte displacement out of range";
1911 else if (siz1
== SIZE_UNSPEC
1913 && isvar (&opP
->disp
)
1914 && subs (&opP
->disp
) == NULL
1916 /* If the displacement needs pic
1917 relocation it cannot be relaxed. */
1918 && opP
->disp
.pic_reloc
== pic_none
1922 nextword
+= baseo
& 0xff;
1924 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1925 TAB (PCINDEX
, SZ_UNDEF
));
1933 nextword
|= 0x40; /* No index reg */
1934 if (opP
->index
.reg
>= ZDATA0
1935 && opP
->index
.reg
<= ZDATA7
)
1936 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
1937 else if (opP
->index
.reg
>= ZADDR0
1938 || opP
->index
.reg
<= ZADDR7
)
1939 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
1942 /* It isn't simple. */
1944 if (cpu_of_arch (current_architecture
) < m68020
)
1946 "invalid operand mode for this architecture; needs 68020 or higher";
1949 /* If the guy specified a width, we assume that it is
1950 wide enough. Maybe it isn't. If so, we lose. */
1954 if (isvar (&opP
->disp
)
1956 : ! issword (baseo
))
1961 else if (! isvar (&opP
->disp
) && baseo
== 0)
1970 as_warn (":b not permitted; defaulting to :w");
1980 /* Figure out innner displacement stuff */
1981 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1986 if (isvar (&opP
->odisp
)
1988 : ! issword (outro
))
1993 else if (! isvar (&opP
->odisp
) && outro
== 0)
2002 as_warn (":b not permitted; defaulting to :w");
2011 if (opP
->mode
== POST
2012 && (nextword
& 0x40) == 0)
2017 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2019 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2020 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2022 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2024 if (siz1
== SIZE_LONG
)
2025 addword (baseo
>> 16);
2026 if (siz1
!= SIZE_UNSPEC
)
2029 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2030 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2031 if (siz2
== SIZE_LONG
)
2032 addword (outro
>> 16);
2033 if (siz2
!= SIZE_UNSPEC
)
2039 nextword
= get_num (&opP
->disp
, 80);
2040 switch (opP
->disp
.size
)
2045 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2047 tmpreg
= 0x38; /* 7.0 */
2051 /* Don't generate pc relative code on 68010 and
2053 if (isvar (&opP
->disp
)
2054 && !subs (&opP
->disp
)
2055 && adds (&opP
->disp
)
2057 /* If the displacement needs pic relocation it
2058 cannot be relaxed. */
2059 && opP
->disp
.pic_reloc
== pic_none
2061 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2062 && cpu_of_arch (current_architecture
) >= m68020
2064 && !strchr ("~%&$?", s
[0]))
2066 tmpreg
= 0x3A; /* 7.2 */
2067 add_frag (adds (&opP
->disp
),
2069 TAB (PCREL
, SZ_UNDEF
));
2072 /* Fall through into long */
2074 if (isvar (&opP
->disp
))
2075 add_fix ('l', &opP
->disp
, 0, 0);
2077 tmpreg
= 0x39;/* 7.1 mode */
2078 addword (nextword
>> 16);
2082 case SIZE_WORD
: /* Word */
2083 if (isvar (&opP
->disp
))
2084 add_fix ('w', &opP
->disp
, 0, 0);
2086 tmpreg
= 0x38;/* 7.0 mode */
2094 as_bad ("unknown/incorrect operand");
2097 install_gen_operand (s
[1], tmpreg
);
2103 { /* JF: I hate floating point! */
2118 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2119 if (isvar (&opP
->disp
))
2120 add_fix (s
[1], &opP
->disp
, 0, 0);
2123 case 'b': /* Danger: These do no check for
2124 certain types of overflow.
2126 if (!isbyte (tmpreg
))
2127 opP
->error
= "out of range";
2128 insop (tmpreg
, opcode
);
2129 if (isvar (&opP
->disp
))
2130 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2133 if (!isword (tmpreg
))
2134 opP
->error
= "out of range";
2135 insop (tmpreg
, opcode
);
2136 if (isvar (&opP
->disp
))
2137 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2140 if (!issword (tmpreg
))
2141 opP
->error
= "out of range";
2142 insop (tmpreg
, opcode
);
2143 if (isvar (&opP
->disp
))
2144 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2147 /* Because of the way insop works, we put these two out
2149 insop (tmpreg
, opcode
);
2150 insop (tmpreg
>> 16, opcode
);
2151 if (isvar (&opP
->disp
))
2152 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2158 install_operand (s
[1], tmpreg
);
2169 install_operand (s
[1], opP
->reg
- ADDR
);
2173 tmpreg
= get_num (&opP
->disp
, 80);
2177 /* The pc_fix argument winds up in fx_pcrel_adjust,
2178 which is a char, and may therefore be unsigned. We
2179 want to pass -1, but we pass 64 instead, and convert
2180 back in md_pcrel_from. */
2181 add_fix ('B', &opP
->disp
, 1, 64);
2184 add_fix ('w', &opP
->disp
, 1, 0);
2189 if (cpu_of_arch (current_architecture
) < m68020
)
2190 as_warn ("Can't use long branches on 68000/68010");
2191 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2192 add_fix ('l', &opP
->disp
, 1, 0);
2197 if (subs (&opP
->disp
)) /* We can't relax it */
2201 /* If the displacement needs pic relocation it cannot be
2203 if (opP
->disp
.pic_reloc
!= pic_none
)
2207 /* This could either be a symbol, or an absolute
2208 address. No matter, the frag hacking will finger it
2209 out. Not quite: it can't switch from BRANCH to
2210 BCC68000 for the case where opnd is absolute (it
2211 needs to use the 68000 hack since no conditional abs
2213 if (((cpu_of_arch (current_architecture
) < m68020
)
2214 || (0 == adds (&opP
->disp
)))
2215 && (the_ins
.opcode
[0] >= 0x6200)
2216 && (the_ins
.opcode
[0] <= 0x6f00))
2217 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2218 TAB (BCC68000
, SZ_UNDEF
));
2220 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2221 TAB (ABRANCH
, SZ_UNDEF
));
2224 if (isvar (&opP
->disp
))
2227 /* check for DBcc instruction */
2228 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2230 /* size varies if patch */
2231 /* needed for long form */
2232 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2233 TAB (DBCC
, SZ_UNDEF
));
2237 add_fix ('w', &opP
->disp
, 1, 0);
2241 case 'C': /* Fixed size LONG coproc branches */
2242 add_fix ('l', &opP
->disp
, 1, 0);
2246 case 'c': /* Var size Coprocesssor branches */
2247 if (subs (&opP
->disp
))
2249 add_fix ('l', &opP
->disp
, 1, 0);
2250 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2252 else if (adds (&opP
->disp
))
2253 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2254 TAB (FBRANCH
, SZ_UNDEF
));
2257 /* add_frag((symbolS *) 0, offs(&opP->disp),
2258 TAB(FBRANCH,SHORT)); */
2259 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2260 add_fix ('l', &opP
->disp
, 1, 0);
2270 case 'C': /* Ignore it */
2273 case 'd': /* JF this is a kludge */
2274 install_operand ('s', opP
->reg
- ADDR
);
2275 tmpreg
= get_num (&opP
->disp
, 80);
2276 if (!issword (tmpreg
))
2278 as_warn ("Expression out of range, using 0");
2285 install_operand (s
[1], opP
->reg
- DATA
);
2289 install_operand (s
[1], opP
->reg
- FP0
);
2293 tmpreg
= opP
->reg
- COP0
;
2294 install_operand (s
[1], tmpreg
);
2297 case 'J': /* JF foo */
2358 install_operand (s
[1], tmpreg
);
2362 tmpreg
= get_num (&opP
->disp
, 55);
2363 install_operand (s
[1], tmpreg
& 0x7f);
2370 if (tmpreg
& 0x7FF0000)
2371 as_bad ("Floating point register in register list");
2372 insop (reverse_16_bits (tmpreg
), opcode
);
2376 if (tmpreg
& 0x700FFFF)
2377 as_bad ("Wrong register in floating-point reglist");
2378 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2386 if (tmpreg
& 0x7FF0000)
2387 as_bad ("Floating point register in register list");
2388 insop (tmpreg
, opcode
);
2390 else if (s
[1] == '8')
2392 if (tmpreg
& 0x0FFFFFF)
2393 as_bad ("incorrect register in reglist");
2394 install_operand (s
[1], tmpreg
>> 24);
2398 if (tmpreg
& 0x700FFFF)
2399 as_bad ("wrong register in floating-point reglist");
2401 install_operand (s
[1], tmpreg
>> 16);
2406 install_operand (s
[1], get_num (&opP
->disp
, 60));
2410 tmpreg
= ((opP
->mode
== DREG
)
2411 ? 0x20 + opP
->reg
- DATA
2412 : (get_num (&opP
->disp
, 40) & 0x1F));
2413 install_operand (s
[1], tmpreg
);
2417 tmpreg
= get_num (&opP
->disp
, 10);
2420 install_operand (s
[1], tmpreg
);
2424 /* This depends on the fact that ADDR registers are eight
2425 more than their corresponding DATA regs, so the result
2426 will have the ADDR_REG bit set */
2427 install_operand (s
[1], opP
->reg
- DATA
);
2431 if (opP
->mode
== AINDR
)
2432 install_operand (s
[1], opP
->reg
- DATA
);
2434 install_operand (s
[1], opP
->index
.reg
- DATA
);
2438 if (opP
->reg
== FPI
)
2440 else if (opP
->reg
== FPS
)
2442 else if (opP
->reg
== FPC
)
2446 install_operand (s
[1], tmpreg
);
2449 case 'S': /* Ignore it */
2453 install_operand (s
[1], get_num (&opP
->disp
, 30));
2456 case 'U': /* Ignore it */
2475 as_fatal ("failed sanity check");
2476 } /* switch on cache token */
2477 install_operand (s
[1], tmpreg
);
2480 /* JF: These are out of order, I fear. */
2493 install_operand (s
[1], tmpreg
);
2519 install_operand (s
[1], tmpreg
);
2523 if (opP
->reg
== VAL
)
2542 install_operand (s
[1], tmpreg
);
2556 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2567 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2573 install_operand (s
[1], tmpreg
);
2576 know (opP
->reg
== PSR
);
2579 know (opP
->reg
== PCSR
);
2594 install_operand (s
[1], tmpreg
);
2597 tmpreg
= get_num (&opP
->disp
, 20);
2598 install_operand (s
[1], tmpreg
);
2600 case '_': /* used only for move16 absolute 32-bit address */
2601 tmpreg
= get_num (&opP
->disp
, 80);
2602 addword (tmpreg
>> 16);
2603 addword (tmpreg
& 0xFFFF);
2610 /* By the time whe get here (FINALLY) the_ins contains the complete
2611 instruction, ready to be emitted. . . */
2615 reverse_16_bits (in
)
2621 static int mask
[16] =
2623 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2624 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2626 for (n
= 0; n
< 16; n
++)
2629 out
|= mask
[15 - n
];
2632 } /* reverse_16_bits() */
2641 static int mask
[8] =
2643 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2646 for (n
= 0; n
< 8; n
++)
2652 } /* reverse_8_bits() */
2654 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2655 (that value is chosen in the frag_var call in md_assemble). TYPE
2656 is the subtype of the frag to be generated; its primary type is
2657 rs_machine_dependent.
2659 The TYPE parameter is also used by md_convert_frag_1 and
2660 md_estimate_size_before_relax. The appropriate type of fixup will
2661 be emitted by md_convert_frag_1.
2663 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2665 install_operand (mode
, val
)
2672 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2675 the_ins
.opcode
[0] |= val
<< 9;
2678 the_ins
.opcode
[1] |= val
<< 12;
2681 the_ins
.opcode
[1] |= val
<< 6;
2684 the_ins
.opcode
[1] |= val
;
2687 the_ins
.opcode
[2] |= val
<< 12;
2690 the_ins
.opcode
[2] |= val
<< 6;
2693 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2694 three words long! */
2696 the_ins
.opcode
[2] |= val
;
2699 the_ins
.opcode
[1] |= val
<< 7;
2702 the_ins
.opcode
[1] |= val
<< 10;
2706 the_ins
.opcode
[1] |= val
<< 5;
2711 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2714 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2717 the_ins
.opcode
[0] |= val
= 0xff;
2720 the_ins
.opcode
[0] |= val
<< 9;
2723 the_ins
.opcode
[1] |= val
;
2726 the_ins
.opcode
[1] |= val
;
2727 the_ins
.numo
++; /* What a hack */
2730 the_ins
.opcode
[1] |= val
<< 4;
2738 the_ins
.opcode
[0] |= (val
<< 6);
2741 the_ins
.opcode
[1] = (val
>> 16);
2742 the_ins
.opcode
[2] = val
& 0xffff;
2746 as_fatal ("failed sanity check.");
2748 } /* install_operand() */
2751 install_gen_operand (mode
, val
)
2758 the_ins
.opcode
[0] |= val
;
2761 /* This is a kludge!!! */
2762 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2771 the_ins
.opcode
[0] |= val
;
2773 /* more stuff goes here */
2775 as_fatal ("failed sanity check.");
2777 } /* install_gen_operand() */
2780 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2781 * then deal with the bitfield hack.
2785 crack_operand (str
, opP
)
2787 register struct m68k_op
*opP
;
2789 register int parens
;
2791 register char *beg_str
;
2799 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
2805 else if (*str
== ')')
2809 opP
->error
= "Extra )";
2815 if (flag_mri
&& *str
== '\'')
2816 inquote
= ! inquote
;
2818 if (!*str
&& parens
)
2820 opP
->error
= "Missing )";
2825 if (m68k_ip_op (beg_str
, opP
) != 0)
2832 c
= *++str
; /* JF bitfield hack */
2837 as_bad ("Missing operand");
2842 /* This is the guts of the machine-dependent assembler. STR points to a
2843 machine dependent instruction. This function is supposed to emit
2844 the frags/bytes it assembles to.
2848 insert_reg (regname
, regnum
)
2855 #ifdef REGISTER_PREFIX
2856 if (!flag_reg_prefix_optional
)
2858 buf
[0] = REGISTER_PREFIX
;
2859 strcpy (buf
+ 1, regname
);
2864 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
2865 &zero_address_frag
));
2867 for (i
= 0; regname
[i
]; i
++)
2868 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2871 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
2872 &zero_address_frag
));
2881 static const struct init_entry init_table
[] =
2991 /* 68ec030 versions of same */
2994 /* 68ec030 access control unit, identical to 030 MMU status reg */
2997 /* Suppressed data and address registers. */
3022 for (i
= 0; init_table
[i
].name
; i
++)
3023 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3026 static int no_68851
, no_68881
;
3029 /* a.out machine type. Default to 68020. */
3030 int m68k_aout_machtype
= 2;
3042 int shorts_this_frag
;
3045 /* In MRI mode, the instruction and operands are separated by a
3046 space. Anything following the operands is a comment. The label
3047 has already been removed. */
3055 for (s
= str
; *s
!= '\0'; s
++)
3057 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3075 inquote
= ! inquote
;
3080 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3085 for (n
= 0; n
< the_ins
.numargs
; n
++)
3086 if (the_ins
.operands
[n
].error
)
3088 er
= the_ins
.operands
[n
].error
;
3094 as_bad ("%s -- statement `%s' ignored", er
, str
);
3098 if (the_ins
.nfrag
== 0)
3100 /* No frag hacking involved; just put it out */
3101 toP
= frag_more (2 * the_ins
.numo
);
3102 fromP
= &the_ins
.opcode
[0];
3103 for (m
= the_ins
.numo
; m
; --m
)
3105 md_number_to_chars (toP
, (long) (*fromP
), 2);
3109 /* put out symbol-dependent info */
3110 for (m
= 0; m
< the_ins
.nrel
; m
++)
3112 switch (the_ins
.reloc
[m
].wid
)
3130 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3131 the_ins
.reloc
[m
].wid
);
3134 fixP
= fix_new_exp (frag_now
,
3135 ((toP
- frag_now
->fr_literal
)
3136 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3138 &the_ins
.reloc
[m
].exp
,
3139 the_ins
.reloc
[m
].pcrel
,
3140 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3141 the_ins
.reloc
[m
].pic_reloc
));
3142 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3147 /* There's some frag hacking */
3148 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3153 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3155 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3156 toP
= frag_more (wid
);
3158 shorts_this_frag
= 0;
3159 for (m
= wid
/ 2; m
; --m
)
3161 md_number_to_chars (toP
, (long) (*fromP
), 2);
3166 for (m
= 0; m
< the_ins
.nrel
; m
++)
3168 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3170 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3173 wid
= the_ins
.reloc
[m
].wid
;
3176 the_ins
.reloc
[m
].wid
= 0;
3177 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3179 fixP
= fix_new_exp (frag_now
,
3180 ((toP
- frag_now
->fr_literal
)
3181 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3183 &the_ins
.reloc
[m
].exp
,
3184 the_ins
.reloc
[m
].pcrel
,
3185 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3186 the_ins
.reloc
[m
].pic_reloc
));
3187 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3189 (void) frag_var (rs_machine_dependent
, 10, 0,
3190 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3191 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3193 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3194 shorts_this_frag
= 0;
3197 toP
= frag_more (n
* sizeof (short));
3200 md_number_to_chars (toP
, (long) (*fromP
), 2);
3206 for (m
= 0; m
< the_ins
.nrel
; m
++)
3210 wid
= the_ins
.reloc
[m
].wid
;
3213 the_ins
.reloc
[m
].wid
= 0;
3214 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3216 fixP
= fix_new_exp (frag_now
,
3217 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3218 - shorts_this_frag
* 2),
3220 &the_ins
.reloc
[m
].exp
,
3221 the_ins
.reloc
[m
].pcrel
,
3222 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3223 the_ins
.reloc
[m
].pic_reloc
));
3224 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3232 * md_begin -- set up hash tables with 68000 instructions.
3233 * similar to what the vax assembler does. ---phr
3235 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3236 a copy of it at runtime, adding in the information we want but isn't
3237 there. I think it'd be better to have an awk script hack the table
3238 at compile time. Or even just xstr the table and use it as-is. But
3239 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3242 register const struct m68k_opcode
*ins
;
3243 register struct m68k_incant
*hack
, *slak
;
3244 register const char *retval
= 0; /* empty string, or error msg text */
3245 register unsigned int i
;
3250 flag_reg_prefix_optional
= 1;
3255 op_hash
= hash_new ();
3257 obstack_begin (&robyn
, 4000);
3258 for (i
= 0; i
< m68k_numopcodes
; i
++)
3260 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3263 ins
= &m68k_opcodes
[i
];
3264 /* We *could* ignore insns that don't match our arch here
3265 but just leaving them out of the hash. */
3266 slak
->m_operands
= ins
->args
;
3267 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3268 slak
->m_arch
= ins
->arch
;
3269 slak
->m_opcode
= ins
->opcode
;
3270 /* This is kludgey */
3271 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3272 if (i
+ 1 != m68k_numopcodes
3273 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3275 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3280 slak
= slak
->m_next
;
3284 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3286 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3289 for (i
= 0; i
< m68k_numaliases
; i
++)
3291 const char *name
= m68k_opcode_aliases
[i
].primary
;
3292 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3293 PTR val
= hash_find (op_hash
, name
);
3295 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3296 retval
= hash_insert (op_hash
, alias
, val
);
3298 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3301 /* In MRI mode, all unsized branches are variable sized. Normally,
3302 they are word sized. */
3305 static struct m68k_opcode_alias mri_aliases
[] =
3325 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3327 const char *name
= mri_aliases
[i
].primary
;
3328 const char *alias
= mri_aliases
[i
].alias
;
3329 PTR val
= hash_find (op_hash
, name
);
3331 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3332 retval
= hash_jam (op_hash
, alias
, val
);
3334 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3338 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3339 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3341 for (i
= 0; i
< sizeof (notend_table
); i
++)
3343 notend_table
[i
] = 0;
3344 alt_notend_table
[i
] = 0;
3346 notend_table
[','] = 1;
3347 notend_table
['{'] = 1;
3348 notend_table
['}'] = 1;
3349 alt_notend_table
['a'] = 1;
3350 alt_notend_table
['A'] = 1;
3351 alt_notend_table
['d'] = 1;
3352 alt_notend_table
['D'] = 1;
3353 alt_notend_table
['#'] = 1;
3354 alt_notend_table
['&'] = 1;
3355 alt_notend_table
['f'] = 1;
3356 alt_notend_table
['F'] = 1;
3357 #ifdef REGISTER_PREFIX
3358 alt_notend_table
[REGISTER_PREFIX
] = 1;
3361 /* We need to put '(' in alt_notend_table to handle
3362 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3364 alt_notend_table
['('] = 1;
3366 /* We need to put '@' in alt_notend_table to handle
3367 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3369 alt_notend_table
['@'] = 1;
3371 #ifndef MIT_SYNTAX_ONLY
3372 /* Insert pseudo ops, these have to go into the opcode table since
3373 gas expects pseudo ops to start with a dot */
3376 while (mote_pseudo_table
[n
].poc_name
)
3378 hack
= (struct m68k_incant
*)
3379 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3380 hash_insert (op_hash
,
3381 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3382 hack
->m_operands
= 0;
3392 record_alignment (text_section
, 2);
3393 record_alignment (data_section
, 2);
3394 record_alignment (bss_section
, 2);
3399 m68k_init_after_args ()
3401 if (cpu_of_arch (current_architecture
) == 0)
3404 const char *default_cpu
= TARGET_CPU
;
3406 if (*default_cpu
== 'm')
3408 for (i
= 0; i
< n_archs
; i
++)
3409 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3413 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3414 current_architecture
|= m68020
;
3417 current_architecture
|= archs
[i
].arch
;
3419 /* Permit m68881 specification with all cpus; those that can't work
3420 with a coprocessor could be doing emulation. */
3421 if (current_architecture
& m68851
)
3423 if (current_architecture
& m68040
)
3425 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3428 /* What other incompatibilities could we check for? */
3430 /* Toss in some default assumptions about coprocessors. */
3432 && (cpu_of_arch (current_architecture
)
3433 /* Can CPU32 have a 68881 coprocessor?? */
3434 & (m68020
| m68030
| cpu32
)))
3436 current_architecture
|= m68881
;
3439 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3440 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3442 current_architecture
|= m68851
;
3444 if (no_68881
&& (current_architecture
& m68881
))
3445 as_bad ("options for 68881 and no-68881 both given");
3446 if (no_68851
&& (current_architecture
& m68851
))
3447 as_bad ("options for 68851 and no-68851 both given");
3450 /* Work out the magic number. This isn't very general. */
3451 if (current_architecture
& m68000
)
3452 m68k_aout_machtype
= 0;
3453 else if (current_architecture
& m68010
)
3454 m68k_aout_machtype
= 1;
3455 else if (current_architecture
& m68020
)
3456 m68k_aout_machtype
= 2;
3458 m68k_aout_machtype
= 2;
3461 /* Note which set of "movec" control registers is available. */
3462 switch (cpu_of_arch (current_architecture
))
3465 control_regs
= m68000_control_regs
;
3468 control_regs
= m68010_control_regs
;
3472 control_regs
= m68020_control_regs
;
3475 control_regs
= m68040_control_regs
;
3478 control_regs
= m68060_control_regs
;
3481 control_regs
= cpu32_control_regs
;
3487 if (cpu_of_arch (current_architecture
) < m68020
)
3488 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3491 /* Equal to MAX_PRECISION in atof-ieee.c */
3492 #define MAX_LITTLENUMS 6
3494 /* Turn a string in input_line_pointer into a floating point constant
3495 of type type, and store the appropriate bytes in *litP. The number
3496 of LITTLENUMS emitted is stored in *sizeP . An error message is
3497 returned, or NULL on OK. */
3500 md_atof (type
, litP
, sizeP
)
3506 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3507 LITTLENUM_TYPE
*wordP
;
3539 return "Bad call to MD_ATOF()";
3541 t
= atof_ieee (input_line_pointer
, type
, words
);
3543 input_line_pointer
= t
;
3545 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3546 for (wordP
= words
; prec
--;)
3548 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3549 litP
+= sizeof (LITTLENUM_TYPE
);
3555 md_number_to_chars (buf
, val
, n
)
3560 number_to_chars_bigendian (buf
, val
, n
);
3564 md_apply_fix_2 (fixP
, val
)
3568 addressT upper_limit
;
3569 offsetT lower_limit
;
3571 /* This is unnecessary but it convinces the native rs6000 compiler
3572 to generate the code we want. */
3573 char *buf
= fixP
->fx_frag
->fr_literal
;
3574 buf
+= fixP
->fx_where
;
3575 /* end ibm compiler workaround */
3577 if (val
& 0x80000000)
3578 val
|= ~(addressT
)0x7fffffff;
3585 memset (buf
, 0, fixP
->fx_size
);
3586 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
3591 switch (fixP
->fx_size
)
3593 /* The cast to offsetT below are necessary to make code correct for
3594 machines where ints are smaller than offsetT */
3598 lower_limit
= - (offsetT
) 0x80;
3601 *buf
++ = (val
>> 8);
3603 upper_limit
= 0x7fff;
3604 lower_limit
= - (offsetT
) 0x8000;
3607 *buf
++ = (val
>> 24);
3608 *buf
++ = (val
>> 16);
3609 *buf
++ = (val
>> 8);
3611 upper_limit
= 0x7fffffff;
3612 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3615 BAD_CASE (fixP
->fx_size
);
3618 /* Fix up a negative reloc. */
3619 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
3621 fixP
->fx_addsy
= fixP
->fx_subsy
;
3622 fixP
->fx_subsy
= NULL
;
3626 /* For non-pc-relative values, it's conceivable we might get something
3627 like "0xff" for a byte field. So extend the upper part of the range
3628 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3629 so that we can do any range checking at all. */
3630 if (!fixP
->fx_pcrel
)
3631 upper_limit
= upper_limit
* 2 + 1;
3633 if ((addressT
) val
> upper_limit
3634 && (val
> 0 || val
< lower_limit
))
3635 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
3637 /* A one byte PC-relative reloc means a short branch. We can't use
3638 a short branch with a value of 0 or -1, because those indicate
3639 different opcodes (branches with longer offsets). */
3641 && fixP
->fx_size
== 1
3642 && (fixP
->fx_addsy
== NULL
3643 || S_IS_DEFINED (fixP
->fx_addsy
))
3644 && (val
== 0 || val
== -1))
3645 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
3648 #ifdef BFD_ASSEMBLER
3650 md_apply_fix (fixP
, valp
)
3654 md_apply_fix_2 (fixP
, (addressT
) *valp
);
3658 void md_apply_fix (fixP
, val
)
3662 md_apply_fix_2 (fixP
, (addressT
) val
);
3666 /* *fragP has been relaxed to its final size, and now needs to have
3667 the bytes inside it modified to conform to the new size There is UGLY
3671 md_convert_frag_1 (fragP
)
3672 register fragS
*fragP
;
3678 /* Address in object code of the displacement. */
3679 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3681 /* Address in gas core of the place to store the displacement. */
3682 /* This convinces the native rs6000 compiler to generate the code we
3684 register char *buffer_address
= fragP
->fr_literal
;
3685 buffer_address
+= fragP
->fr_fix
;
3686 /* end ibm compiler workaround */
3688 /* The displacement of the address, from current location. */
3689 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3690 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3692 #ifdef BFD_ASSEMBLER
3693 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
3696 switch (fragP
->fr_subtype
)
3698 case TAB (BCC68000
, BYTE
):
3699 case TAB (ABRANCH
, BYTE
):
3700 know (issbyte (disp
));
3702 as_bad ("short branch with zero offset: use :w");
3703 fragP
->fr_opcode
[1] = disp
;
3706 case TAB (DBCC
, SHORT
):
3707 know (issword (disp
));
3710 case TAB (BCC68000
, SHORT
):
3711 case TAB (ABRANCH
, SHORT
):
3712 know (issword (disp
));
3713 fragP
->fr_opcode
[1] = 0x00;
3716 case TAB (ABRANCH
, LONG
):
3717 if (cpu_of_arch (current_architecture
) < m68020
)
3719 if (fragP
->fr_opcode
[0] == 0x61)
3722 fragP
->fr_opcode
[0] = 0x4E;
3723 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3737 else if (fragP
->fr_opcode
[0] == 0x60)
3739 fragP
->fr_opcode
[0] = 0x4E;
3740 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3741 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3742 fragP
->fr_offset
, 0, NO_RELOC
);
3748 as_bad ("Long branch offset not supported.");
3753 fragP
->fr_opcode
[1] = (char) 0xff;
3757 case TAB (BCC68000
, LONG
):
3758 /* only Bcc 68000 instructions can come here */
3759 /* change bcc into b!cc/jmp absl long */
3760 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3761 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
3763 /* JF: these used to be fr_opcode[2,3], but they may be in a
3764 different frag, in which case refering to them is a no-no.
3765 Only fr_opcode[0,1] are guaranteed to work. */
3766 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3767 *buffer_address
++ = (char) 0xf9;
3768 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3769 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3770 fragP
->fr_offset
, 0, NO_RELOC
);
3774 case TAB (DBCC
, LONG
):
3775 /* only DBcc 68000 instructions can come here */
3776 /* change dbcc into dbcc/jmp absl long */
3777 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3778 *buffer_address
++ = 0x00; /* branch offset = 4 */
3779 *buffer_address
++ = 0x04;
3780 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3781 *buffer_address
++ = 0x06;
3782 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3783 *buffer_address
++ = (char) 0xf9;
3785 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3786 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3787 fragP
->fr_offset
, 0, NO_RELOC
);
3791 case TAB (FBRANCH
, SHORT
):
3792 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
3795 case TAB (FBRANCH
, LONG
):
3796 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3799 case TAB (PCREL
, SHORT
):
3802 case TAB (PCREL
, LONG
):
3803 /* The thing to do here is force it to ABSOLUTE LONG, since
3804 PCREL is really trying to shorten an ABSOLUTE address anyway */
3805 /* JF FOO This code has not been tested */
3806 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
3808 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3809 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
3810 (unsigned) fragP
->fr_opcode
[0],
3811 (unsigned long) fragP
->fr_address
);
3812 fragP
->fr_opcode
[1] &= ~0x3F;
3813 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
3817 case TAB (PCLEA
, SHORT
):
3818 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3819 fragP
->fr_offset
, 1, NO_RELOC
);
3820 fragP
->fr_opcode
[1] &= ~0x3F;
3821 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
3824 case TAB (PCLEA
, LONG
):
3825 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
3826 fragP
->fr_offset
, 1, NO_RELOC
);
3827 fixP
->fx_pcrel_adjust
= 2;
3828 /* Already set to mode 7.3; this indicates: PC indirect with
3829 suppressed index, 32-bit displacement. */
3830 *buffer_address
++ = 0x01;
3831 *buffer_address
++ = 0x70;
3836 case TAB (PCINDEX
, BYTE
):
3838 if (!issbyte (disp
))
3840 as_bad ("displacement doesn't fit in one byte");
3843 assert (fragP
->fr_fix
>= 2);
3844 buffer_address
[-2] &= ~1;
3845 buffer_address
[-1] = disp
;
3848 case TAB (PCINDEX
, SHORT
):
3850 assert (issword (disp
));
3851 assert (fragP
->fr_fix
>= 2);
3852 buffer_address
[-2] |= 0x1;
3853 buffer_address
[-1] = 0x20;
3854 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3855 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3857 fixP
->fx_pcrel_adjust
= 2;
3860 case TAB (PCINDEX
, LONG
):
3862 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3863 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3865 fixP
->fx_pcrel_adjust
= 2;
3866 assert (fragP
->fr_fix
>= 2);
3867 buffer_address
[-2] |= 0x1;
3868 buffer_address
[-1] = 0x30;
3875 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
3876 fragP
->fr_fix
+= ext
;
3880 #ifndef BFD_ASSEMBLER
3883 md_convert_frag (headers
, sec
, fragP
)
3884 object_headers
*headers
;
3888 md_convert_frag_1 (fragP
);
3894 md_convert_frag (abfd
, sec
, fragP
)
3899 md_convert_frag_1 (fragP
);
3903 /* Force truly undefined symbols to their maximum size, and generally set up
3904 the frag list to be relaxed
3907 md_estimate_size_before_relax (fragP
, segment
)
3908 register fragS
*fragP
;
3912 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3914 old_fix
= fragP
->fr_fix
;
3916 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3917 switch (fragP
->fr_subtype
)
3920 case TAB (ABRANCH
, SZ_UNDEF
):
3922 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3923 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3925 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
3928 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
3930 /* On 68000, or for absolute value, switch to abs long */
3931 /* FIXME, we should check abs val, pick short or long */
3932 if (fragP
->fr_opcode
[0] == 0x61)
3934 fragP
->fr_opcode
[0] = 0x4E;
3935 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3936 fix_new (fragP
, fragP
->fr_fix
, 4,
3937 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3941 else if (fragP
->fr_opcode
[0] == 0x60)
3943 fragP
->fr_opcode
[0] = 0x4E;
3944 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3945 fix_new (fragP
, fragP
->fr_fix
, 4,
3946 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3952 as_warn ("Long branch offset to extern symbol not supported.");
3956 { /* Symbol is still undefined. Make it simple */
3957 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3958 fragP
->fr_offset
, 1, NO_RELOC
);
3960 fragP
->fr_opcode
[1] = (char) 0xff;
3966 } /* case TAB(ABRANCH,SZ_UNDEF) */
3968 case TAB (FBRANCH
, SZ_UNDEF
):
3970 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
3972 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
3977 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3978 fragP
->fr_offset
, 1, NO_RELOC
);
3980 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3984 } /* TAB(FBRANCH,SZ_UNDEF) */
3986 case TAB (PCREL
, SZ_UNDEF
):
3988 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3990 || cpu_of_arch (current_architecture
) < m68020
)
3992 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
3997 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4001 } /* TAB(PCREL,SZ_UNDEF) */
4003 case TAB (BCC68000
, SZ_UNDEF
):
4005 if ((fragP
->fr_symbol
!= NULL
)
4006 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4008 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4011 /* only Bcc 68000 instructions can come here */
4012 /* change bcc into b!cc/jmp absl long */
4013 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4014 if (flag_short_refs
)
4016 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4017 /* JF: these were fr_opcode[2,3] */
4018 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4019 buffer_address
[1] = (char) 0xf8;
4020 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4021 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4022 fragP
->fr_offset
, 0, NO_RELOC
);
4027 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4028 /* JF: these were fr_opcode[2,3] */
4029 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4030 buffer_address
[1] = (char) 0xf9;
4031 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4032 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4033 fragP
->fr_offset
, 0, NO_RELOC
);
4038 } /* case TAB(BCC68000,SZ_UNDEF) */
4040 case TAB (DBCC
, SZ_UNDEF
):
4042 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4044 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4048 /* only DBcc 68000 instructions can come here */
4049 /* change dbcc into dbcc/jmp absl long */
4050 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4051 buffer_address
[0] = 0x00; /* branch offset = 4 */
4052 buffer_address
[1] = 0x04;
4053 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4055 if (flag_short_refs
)
4057 /* JF: these were fr_opcode[5-7] */
4058 buffer_address
[3] = 0x04; /* plus 4 */
4059 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4060 buffer_address
[5] = (char) 0xf8;
4061 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4062 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4063 fragP
->fr_offset
, 0, NO_RELOC
);
4068 /* JF: these were fr_opcode[5-7] */
4069 buffer_address
[3] = 0x06; /* Plus 6 */
4070 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4071 buffer_address
[5] = (char) 0xf9;
4072 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4073 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4074 fragP
->fr_offset
, 0, NO_RELOC
);
4080 } /* case TAB(DBCC,SZ_UNDEF) */
4082 case TAB (PCLEA
, SZ_UNDEF
):
4084 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4086 || cpu_of_arch (current_architecture
) < m68020
)
4088 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4093 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4097 } /* TAB(PCLEA,SZ_UNDEF) */
4099 case TAB (PCINDEX
, SZ_UNDEF
):
4100 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4101 || cpu_of_arch (current_architecture
) < m68020
)
4103 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4107 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4116 /* now that SZ_UNDEF are taken care of, check others */
4117 switch (fragP
->fr_subtype
)
4119 case TAB (BCC68000
, BYTE
):
4120 case TAB (ABRANCH
, BYTE
):
4121 /* We can't do a short jump to the next instruction,
4122 so we force word mode. */
4123 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
4124 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
4126 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4133 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4136 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4137 /* the bit-field entries in the relocation_info struct plays hell
4138 with the byte-order problems of cross-assembly. So as a hack,
4139 I added this mach. dependent ri twiddler. Ugly, but it gets
4141 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4142 are symbolnum, most sig. byte first. Last byte is broken up with
4143 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4144 nibble as nuthin. (on Sun 3 at least) */
4145 /* Translate the internal relocation information into target-specific
4149 md_ri_to_chars (the_bytes
, ri
)
4151 struct reloc_info_generic
*ri
;
4154 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4155 /* now the fun stuff */
4156 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4157 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4158 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4159 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4160 ((ri
->r_extern
<< 4) & 0x10));
4163 #endif /* comment */
4165 #ifndef BFD_ASSEMBLER
4167 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4170 relax_addressT segment_address_in_file
;
4173 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4174 * Out: GNU LD relocation length code: 0, 1, or 2.
4177 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4180 know (fixP
->fx_addsy
!= NULL
);
4182 md_number_to_chars (where
,
4183 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4186 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4187 ? S_GET_TYPE (fixP
->fx_addsy
)
4188 : fixP
->fx_addsy
->sy_number
);
4190 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4191 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4192 where
[6] = r_symbolnum
& 0x0ff;
4193 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4194 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4198 #endif /* OBJ_AOUT or OBJ_BOUT */
4200 #ifndef WORKING_DOT_WORD
4201 CONST
int md_short_jump_size
= 4;
4202 CONST
int md_long_jump_size
= 6;
4205 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4207 addressT from_addr
, to_addr
;
4213 offset
= to_addr
- (from_addr
+ 2);
4215 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4216 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4220 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4222 addressT from_addr
, to_addr
;
4228 if (cpu_of_arch (current_architecture
) < m68020
)
4230 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4231 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4232 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4233 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4238 offset
= to_addr
- (from_addr
+ 2);
4239 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4240 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4246 /* Different values of OK tell what its OK to return. Things that
4247 aren't OK are an error (what a shock, no?)
4250 10: Absolute 1:8 only
4251 20: Absolute 0:7 only
4252 30: absolute 0:15 only
4253 40: Absolute 0:31 only
4254 50: absolute 0:127 only
4255 55: absolute -64:63 only
4256 60: absolute -128:127 only
4257 70: absolute 0:4095 only
4264 struct m68k_exp
*exp
;
4267 if (exp
->exp
.X_op
== O_absent
)
4269 /* Do the same thing the VAX asm does */
4270 op (exp
) = O_constant
;
4276 as_warn ("expression out of range: defaulting to 1");
4280 else if (exp
->exp
.X_op
== O_constant
)
4285 if (offs (exp
) < 1 || offs (exp
) > 8)
4287 as_warn ("expression out of range: defaulting to 1");
4292 if (offs (exp
) < 0 || offs (exp
) > 7)
4296 if (offs (exp
) < 0 || offs (exp
) > 15)
4300 if (offs (exp
) < 0 || offs (exp
) > 32)
4304 if (offs (exp
) < 0 || offs (exp
) > 127)
4308 if (offs (exp
) < -64 || offs (exp
) > 63)
4312 if (offs (exp
) < -128 || offs (exp
) > 127)
4316 if (offs (exp
) < 0 || offs (exp
) > 4095)
4319 as_warn ("expression out of range: defaulting to 0");
4327 else if (exp
->exp
.X_op
== O_big
)
4329 if (offs (exp
) <= 0 /* flonum */
4330 && (ok
== 80 /* no bignums */
4331 || (ok
> 10 /* small-int ranges including 0 ok */
4332 /* If we have a flonum zero, a zero integer should
4333 do as well (e.g., in moveq). */
4334 && generic_floating_point_number
.exponent
== 0
4335 && generic_floating_point_number
.low
[0] == 0)))
4337 /* HACK! Turn it into a long */
4338 LITTLENUM_TYPE words
[6];
4340 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4341 op (exp
) = O_constant
;
4344 offs (exp
) = words
[1] | (words
[0] << 16);
4348 op (exp
) = O_constant
;
4351 offs (exp
) = (ok
== 10) ? 1 : 0;
4352 as_warn ("Can't deal with expression; defaulting to %ld",
4358 if (ok
>= 10 && ok
<= 70)
4360 op (exp
) = O_constant
;
4363 offs (exp
) = (ok
== 10) ? 1 : 0;
4364 as_warn ("Can't deal with expression; defaulting to %ld",
4369 if (exp
->size
!= SIZE_UNSPEC
)
4377 if (!isbyte (offs (exp
)))
4378 as_warn ("expression doesn't fit in BYTE");
4381 if (!isword (offs (exp
)))
4382 as_warn ("expression doesn't fit in WORD");
4390 /* These are the back-ends for the various machine dependent pseudo-ops. */
4391 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4397 subseg_set (data_section
, 1);
4398 demand_empty_rest_of_line ();
4405 subseg_set (data_section
, 2);
4406 demand_empty_rest_of_line ();
4413 /* We don't support putting frags in the BSS segment, we fake it
4414 by marking in_bss, then looking at s_skip for clues. */
4416 subseg_set (bss_section
, 0);
4417 demand_empty_rest_of_line ();
4425 register long temp_fill
;
4427 temp
= 1; /* JF should be 2? */
4428 temp_fill
= get_absolute_expression ();
4429 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4430 frag_align (temp
, (int) temp_fill
);
4431 demand_empty_rest_of_line ();
4438 demand_empty_rest_of_line ();
4441 /* Pseudo-ops handled for MRI compatibility. */
4443 /* Handle an MRI style chip specification. */
4452 s
= input_line_pointer
;
4453 c
= get_symbol_end ();
4454 for (i
= 0; i
< n_archs
; i
++)
4455 if (strcasecmp (s
, archs
[i
].name
) == 0)
4459 as_bad ("%s: unrecognized processor name", s
);
4460 *input_line_pointer
= c
;
4461 ignore_rest_of_line ();
4464 *input_line_pointer
= c
;
4466 if (*input_line_pointer
== '/')
4467 current_architecture
= 0;
4469 current_architecture
&= m68881
| m68851
;
4470 current_architecture
|= archs
[i
].arch
;
4472 while (*input_line_pointer
== '/')
4474 ++input_line_pointer
;
4475 s
= input_line_pointer
;
4476 c
= get_symbol_end ();
4477 if (strcmp (s
, "68881") == 0)
4478 current_architecture
|= m68881
;
4479 else if (strcmp (s
, "68851") == 0)
4480 current_architecture
|= m68851
;
4481 *input_line_pointer
= c
;
4485 /* The MRI CHIP pseudo-op. */
4495 stop
= mri_comment_field (&stopc
);
4498 mri_comment_end (stop
, stopc
);
4499 demand_empty_rest_of_line ();
4502 /* The MRI FOPT pseudo-op. */
4510 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4514 input_line_pointer
+= 3;
4515 temp
= get_absolute_expression ();
4516 if (temp
< 0 || temp
> 7)
4517 as_bad ("bad coprocessor id");
4519 m68k_float_copnum
= COP0
+ temp
;
4523 as_bad ("unrecognized fopt option");
4524 ignore_rest_of_line ();
4528 demand_empty_rest_of_line ();
4531 /* The structure used to handle the MRI OPT pseudo-op. */
4535 /* The name of the option. */
4538 /* If this is not NULL, just call this function. The first argument
4539 is the ARG field of this structure, the second argument is
4540 whether the option was negated. */
4541 void (*pfn
) PARAMS ((int arg
, int on
));
4543 /* If this is not NULL, and the PFN field is NULL, set the variable
4544 this points to. Set it to the ARG field if the option was not
4545 negated, and the NOTARG field otherwise. */
4548 /* The value to pass to PFN or to assign to *PVAR. */
4551 /* The value to assign to *PVAR if the option is negated. If PFN is
4552 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4553 the option may not be negated. */
4557 /* The table used to handle the MRI OPT pseudo-op. */
4559 static void skip_to_comma
PARAMS ((int, int));
4560 static void opt_nest
PARAMS ((int, int));
4561 static void opt_chip
PARAMS ((int, int));
4562 static void opt_list
PARAMS ((int, int));
4563 static void opt_list_symbols
PARAMS ((int, int));
4565 static const struct opt_action opt_table
[] =
4567 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
4569 /* We do relaxing, so there is little use for these options. */
4570 { "b", 0, 0, 0, 0 },
4571 { "brs", 0, 0, 0, 0 },
4572 { "brb", 0, 0, 0, 0 },
4573 { "brl", 0, 0, 0, 0 },
4574 { "brw", 0, 0, 0, 0 },
4576 { "c", 0, 0, 0, 0 },
4577 { "cex", 0, 0, 0, 0 },
4578 { "case", 0, &symbols_case_sensitive
, 1, 0 },
4579 { "cl", 0, 0, 0, 0 },
4580 { "cre", 0, 0, 0, 0 },
4581 { "d", 0, &flag_keep_locals
, 1, 0 },
4582 { "e", 0, 0, 0, 0 },
4583 { "f", 0, &flag_short_refs
, 1, 0 },
4584 { "frs", 0, &flag_short_refs
, 1, 0 },
4585 { "frl", 0, &flag_short_refs
, 0, 1 },
4586 { "g", 0, 0, 0, 0 },
4587 { "i", 0, 0, 0, 0 },
4588 { "m", 0, 0, 0, 0 },
4589 { "mex", 0, 0, 0, 0 },
4590 { "mc", 0, 0, 0, 0 },
4591 { "md", 0, 0, 0, 0 },
4592 { "nest", opt_nest
, 0, 0, 0 },
4593 { "next", skip_to_comma
, 0, 0, 0 },
4594 { "o", 0, 0, 0, 0 },
4595 { "old", 0, 0, 0, 0 },
4596 { "op", skip_to_comma
, 0, 0, 0 },
4597 { "pco", 0, 0, 0, 0 },
4598 { "p", opt_chip
, 0, 0, 0 },
4599 { "pcr", 0, 0, 0, 0 },
4600 { "pcs", 0, 0, 0, 0 },
4601 { "r", 0, 0, 0, 0 },
4602 { "quick", 0, &m68k_quick
, 1, 0 },
4603 { "rel32", 0, &m68k_rel32
, 1, 0 },
4604 { "s", opt_list
, 0, 0, 0 },
4605 { "t", opt_list_symbols
, 0, 0, 0 },
4606 { "w", 0, &flag_no_warnings
, 0, 1 },
4610 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4612 /* The MRI OPT pseudo-op. */
4624 const struct opt_action
*o
;
4629 if (*input_line_pointer
== '-')
4631 ++input_line_pointer
;
4634 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
4636 input_line_pointer
+= 2;
4640 s
= input_line_pointer
;
4641 c
= get_symbol_end ();
4643 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
4645 if (strcasecmp (s
, o
->name
) == 0)
4649 /* Restore input_line_pointer now in case the option
4651 *input_line_pointer
= c
;
4652 (*o
->pfn
) (o
->arg
, t
);
4654 else if (o
->pvar
!= NULL
)
4656 if (! t
&& o
->arg
== o
->notarg
)
4657 as_bad ("option `%s' may not be negated", s
);
4658 *input_line_pointer
= c
;
4659 *o
->pvar
= t
? o
->arg
: o
->notarg
;
4662 *input_line_pointer
= c
;
4668 as_bad ("option `%s' not recognized", s
);
4669 *input_line_pointer
= c
;
4672 while (*input_line_pointer
++ == ',');
4674 /* Move back to terminating character. */
4675 --input_line_pointer
;
4676 demand_empty_rest_of_line ();
4679 /* Skip ahead to a comma. This is used for OPT options which we do
4680 not suppor tand which take arguments. */
4683 skip_to_comma (arg
, on
)
4687 while (*input_line_pointer
!= ','
4688 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4689 ++input_line_pointer
;
4692 /* Handle the OPT NEST=depth option. */
4699 if (*input_line_pointer
!= '=')
4701 as_bad ("bad format of OPT NEST=depth");
4705 ++input_line_pointer
;
4706 max_macro_nest
= get_absolute_expression ();
4709 /* Handle the OPT P=chip option. */
4716 if (*input_line_pointer
!= '=')
4718 /* This is just OPT P, which we do not support. */
4722 ++input_line_pointer
;
4726 /* Handle the OPT S option. */
4736 /* Handle the OPT T option. */
4739 opt_list_symbols (arg
, on
)
4744 listing
|= LISTING_SYMBOLS
;
4746 listing
&=~ LISTING_SYMBOLS
;
4749 /* Handle the MRI REG pseudo-op. */
4762 if (line_label
== NULL
)
4764 as_bad ("missing label");
4765 ignore_rest_of_line ();
4770 stop
= mri_comment_field (&stopc
);
4774 s
= input_line_pointer
;
4775 while (isalnum ((unsigned char) *input_line_pointer
)
4776 #ifdef REGISTER_PREFIX
4777 || *input_line_pointer
== REGISTER_PREFIX
4779 || *input_line_pointer
== '/'
4780 || *input_line_pointer
== '-')
4781 ++input_line_pointer
;
4782 c
= *input_line_pointer
;
4783 *input_line_pointer
= '\0';
4785 if (m68k_ip_op (s
, &rop
) != 0)
4787 if (rop
.error
== NULL
)
4788 as_bad ("bad register list");
4790 as_bad ("bad register list: %s", rop
.error
);
4791 *input_line_pointer
= c
;
4792 ignore_rest_of_line ();
4796 *input_line_pointer
= c
;
4798 if (rop
.mode
== REGLST
)
4800 else if (rop
.mode
== DREG
)
4801 mask
= 1 << (rop
.reg
- DATA0
);
4802 else if (rop
.mode
== AREG
)
4803 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
4804 else if (rop
.mode
== FPREG
)
4805 mask
= 1 << (rop
.reg
- FP0
+ 16);
4806 else if (rop
.mode
== CONTROL
4809 else if (rop
.mode
== CONTROL
4812 else if (rop
.mode
== CONTROL
4817 as_bad ("bad register list");
4818 ignore_rest_of_line ();
4822 S_SET_SEGMENT (line_label
, absolute_section
);
4823 S_SET_VALUE (line_label
, mask
);
4824 line_label
->sy_frag
= &zero_address_frag
;
4827 mri_comment_end (stop
, stopc
);
4829 demand_empty_rest_of_line ();
4832 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
4836 struct save_opts
*next
;
4838 int symbols_case_sensitive
;
4846 /* FIXME: We don't save OPT S. */
4849 /* This variable holds the stack of saved options. */
4851 static struct save_opts
*save_stack
;
4853 /* The MRI SAVE pseudo-op. */
4859 struct save_opts
*s
;
4861 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
4862 s
->abspcadd
= m68k_abspcadd
;
4863 s
->symbols_case_sensitive
= symbols_case_sensitive
;
4864 s
->keep_locals
= flag_keep_locals
;
4865 s
->short_refs
= flag_short_refs
;
4866 s
->architecture
= current_architecture
;
4867 s
->quick
= m68k_quick
;
4868 s
->rel32
= m68k_rel32
;
4869 s
->listing
= listing
;
4870 s
->no_warnings
= flag_no_warnings
;
4872 s
->next
= save_stack
;
4875 demand_empty_rest_of_line ();
4878 /* The MRI RESTORE pseudo-op. */
4884 struct save_opts
*s
;
4886 if (save_stack
== NULL
)
4888 as_bad ("restore without save");
4889 ignore_rest_of_line ();
4894 save_stack
= s
->next
;
4896 m68k_abspcadd
= s
->abspcadd
;
4897 symbols_case_sensitive
= s
->symbols_case_sensitive
;
4898 flag_keep_locals
= s
->keep_locals
;
4899 flag_short_refs
= s
->short_refs
;
4900 current_architecture
= s
->architecture
;
4901 m68k_quick
= s
->quick
;
4902 m68k_rel32
= s
->rel32
;
4903 listing
= s
->listing
;
4904 flag_no_warnings
= s
->no_warnings
;
4908 demand_empty_rest_of_line ();
4911 /* Types of MRI structured control directives. */
4913 enum mri_control_type
4921 /* This structure is used to stack the MRI structured control
4924 struct mri_control_info
4926 /* The directive within which this one is enclosed. */
4927 struct mri_control_info
*outer
;
4929 /* The type of directive. */
4930 enum mri_control_type type
;
4932 /* Whether an ELSE has been in an IF. */
4935 /* The add or sub statement at the end of a FOR. */
4938 /* The label of the top of a FOR or REPEAT loop. */
4941 /* The label to jump to for the next iteration, or the else
4942 expression of a conditional. */
4945 /* The label to jump to to break out of the loop, or the label past
4946 the end of a conditional. */
4950 /* The stack of MRI structured control directives. */
4952 static struct mri_control_info
*mri_control_stack
;
4954 /* The current MRI structured control directive index number, used to
4955 generate label names. */
4957 static int mri_control_index
;
4959 /* Some function prototypes. */
4961 static char *mri_control_label
PARAMS ((void));
4962 static struct mri_control_info
*push_mri_control
4963 PARAMS ((enum mri_control_type
));
4964 static void pop_mri_control
PARAMS ((void));
4965 static int parse_mri_condition
PARAMS ((int *));
4966 static int parse_mri_control_operand
4967 PARAMS ((int *, char **, char **, char **, char **));
4968 static int swap_mri_condition
PARAMS ((int));
4969 static int reverse_mri_condition
PARAMS ((int));
4970 static void build_mri_control_operand
4971 PARAMS ((int, int, char *, char *, char *, char *, const char *,
4972 const char *, int));
4973 static void parse_mri_control_expression
4974 PARAMS ((char *, int, const char *, const char *, int));
4976 /* Generate a new MRI label structured control directive label name. */
4979 mri_control_label ()
4983 n
= (char *) xmalloc (20);
4984 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
4985 ++mri_control_index
;
4989 /* Create a new MRI structured control directive. */
4991 static struct mri_control_info
*
4992 push_mri_control (type
)
4993 enum mri_control_type type
;
4995 struct mri_control_info
*n
;
4997 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5001 if (type
== mri_if
|| type
== mri_while
)
5004 n
->top
= mri_control_label ();
5005 n
->next
= mri_control_label ();
5006 n
->bottom
= mri_control_label ();
5008 n
->outer
= mri_control_stack
;
5009 mri_control_stack
= n
;
5014 /* Pop off the stack of MRI structured control directives. */
5019 struct mri_control_info
*n
;
5021 n
= mri_control_stack
;
5022 mri_control_stack
= n
->outer
;
5030 /* Recognize a condition code in an MRI structured control expression. */
5033 parse_mri_condition (pcc
)
5038 know (*input_line_pointer
== '<');
5040 ++input_line_pointer
;
5041 c1
= *input_line_pointer
++;
5042 c2
= *input_line_pointer
++;
5044 if (*input_line_pointer
!= '>')
5046 as_bad ("syntax error in structured control directive");
5050 ++input_line_pointer
;
5058 *pcc
= (c1
<< 8) | c2
;
5063 /* Parse a single operand in an MRI structured control expression. */
5066 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5083 if (*input_line_pointer
== '<')
5085 /* It's just a condition code. */
5086 return parse_mri_condition (pcc
);
5089 /* Look ahead for the condition code. */
5090 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5092 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5097 as_bad ("missing condition code in structured control directive");
5101 *leftstart
= input_line_pointer
;
5103 if (*leftstop
> *leftstart
5104 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5107 input_line_pointer
= s
;
5108 if (! parse_mri_condition (pcc
))
5111 /* Look ahead for AND or OR or end of line. */
5112 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5114 if ((strncasecmp (s
, "AND", 3) == 0
5115 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5116 || (strncasecmp (s
, "OR", 2) == 0
5117 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5121 *rightstart
= input_line_pointer
;
5123 if (*rightstop
> *rightstart
5124 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5127 input_line_pointer
= s
;
5132 #define MCC(b1, b2) (((b1) << 8) | (b2))
5134 /* Swap the sense of a condition. This changes the condition so that
5135 it generates the same result when the operands are swapped. */
5138 swap_mri_condition (cc
)
5143 case MCC ('h', 'i'): return MCC ('c', 's');
5144 case MCC ('l', 's'): return MCC ('c', 'c');
5145 case MCC ('c', 'c'): return MCC ('l', 's');
5146 case MCC ('c', 's'): return MCC ('h', 'i');
5147 case MCC ('p', 'l'): return MCC ('m', 'i');
5148 case MCC ('m', 'i'): return MCC ('p', 'l');
5149 case MCC ('g', 'e'): return MCC ('l', 'e');
5150 case MCC ('l', 't'): return MCC ('g', 't');
5151 case MCC ('g', 't'): return MCC ('l', 't');
5152 case MCC ('l', 'e'): return MCC ('g', 'e');
5157 /* Reverse the sense of a condition. */
5160 reverse_mri_condition (cc
)
5165 case MCC ('h', 'i'): return MCC ('l', 's');
5166 case MCC ('l', 's'): return MCC ('h', 'i');
5167 case MCC ('c', 'c'): return MCC ('c', 's');
5168 case MCC ('c', 's'): return MCC ('c', 'c');
5169 case MCC ('n', 'e'): return MCC ('e', 'q');
5170 case MCC ('e', 'q'): return MCC ('n', 'e');
5171 case MCC ('v', 'c'): return MCC ('v', 's');
5172 case MCC ('v', 's'): return MCC ('v', 'c');
5173 case MCC ('p', 'l'): return MCC ('m', 'i');
5174 case MCC ('m', 'i'): return MCC ('p', 'l');
5175 case MCC ('g', 'e'): return MCC ('l', 't');
5176 case MCC ('l', 't'): return MCC ('g', 'e');
5177 case MCC ('g', 't'): return MCC ('l', 'e');
5178 case MCC ('l', 'e'): return MCC ('g', 't');
5183 /* Build an MRI structured control expression. This generates test
5184 and branch instructions. It goes to TRUELAB if the condition is
5185 true, and to FALSELAB if the condition is false. Exactly one of
5186 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5187 is the size qualifier for the expression. EXTENT is the size to
5188 use for the branch. */
5191 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5192 rightstop
, truelab
, falselab
, extent
)
5199 const char *truelab
;
5200 const char *falselab
;
5206 if (leftstart
!= NULL
)
5208 struct m68k_op leftop
, rightop
;
5211 /* Swap the compare operands, if necessary, to produce a legal
5212 m68k compare instruction. Comparing a register operand with
5213 a non-register operand requires the register to be on the
5214 right (cmp, cmpa). Comparing an immediate value with
5215 anything requires the immediate value to be on the left
5220 (void) m68k_ip_op (leftstart
, &leftop
);
5225 (void) m68k_ip_op (rightstart
, &rightop
);
5228 if (rightop
.mode
== IMMED
5229 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5230 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5234 cc
= swap_mri_condition (cc
);
5236 leftstart
= rightstart
;
5239 leftstop
= rightstop
;
5244 if (truelab
== NULL
)
5246 cc
= reverse_mri_condition (cc
);
5250 if (leftstart
!= NULL
)
5252 buf
= (char *) xmalloc (20
5253 + (leftstop
- leftstart
)
5254 + (rightstop
- rightstart
));
5262 memcpy (s
, leftstart
, leftstop
- leftstart
);
5263 s
+= leftstop
- leftstart
;
5265 memcpy (s
, rightstart
, rightstop
- rightstart
);
5266 s
+= rightstop
- rightstart
;
5272 buf
= (char *) xmalloc (20 + strlen (truelab
));
5280 strcpy (s
, truelab
);
5285 /* Parse an MRI structured control expression. This generates test
5286 and branch instructions. STOP is where the expression ends. It
5287 goes to TRUELAB if the condition is true, and to FALSELAB if the
5288 condition is false. Exactly one of TRUELAB and FALSELAB will be
5289 NULL, meaning to fall through. QUAL is the size qualifier for the
5290 expression. EXTENT is the size to use for the branch. */
5293 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
5296 const char *truelab
;
5297 const char *falselab
;
5310 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5311 &rightstart
, &rightstop
))
5317 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5321 if (falselab
!= NULL
)
5324 flab
= mri_control_label ();
5326 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5327 rightstop
, (const char *) NULL
, flab
, extent
);
5329 input_line_pointer
+= 3;
5330 if (*input_line_pointer
!= '.'
5331 || input_line_pointer
[1] == '\0')
5335 qual
= input_line_pointer
[1];
5336 input_line_pointer
+= 2;
5339 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5340 &rightstart
, &rightstop
))
5346 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5347 rightstop
, truelab
, falselab
, extent
);
5349 if (falselab
== NULL
)
5352 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5356 if (truelab
!= NULL
)
5359 tlab
= mri_control_label ();
5361 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5362 rightstop
, tlab
, (const char *) NULL
, extent
);
5364 input_line_pointer
+= 2;
5365 if (*input_line_pointer
!= '.'
5366 || input_line_pointer
[1] == '\0')
5370 qual
= input_line_pointer
[1];
5371 input_line_pointer
+= 2;
5374 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5375 &rightstart
, &rightstop
))
5381 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5382 rightstop
, truelab
, falselab
, extent
);
5384 if (truelab
== NULL
)
5389 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5390 rightstop
, truelab
, falselab
, extent
);
5394 if (input_line_pointer
!= stop
)
5395 as_bad ("syntax error in structured control directive");
5398 /* Handle the MRI IF pseudo-op. This may be a structured control
5399 directive, or it may be a regular assembler conditional, depending
5408 struct mri_control_info
*n
;
5410 /* A structured control directive must end with THEN with an
5411 optional qualifier. */
5412 s
= input_line_pointer
;
5413 while (! is_end_of_line
[(unsigned char) *s
]
5414 && (! flag_mri
|| *s
!= '*'))
5417 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5420 if (s
- input_line_pointer
> 1
5424 if (s
- input_line_pointer
< 3
5425 || strncasecmp (s
- 3, "THEN", 4) != 0)
5429 as_bad ("missing then");
5430 ignore_rest_of_line ();
5434 /* It's a conditional. */
5439 /* Since this might be a conditional if, this pseudo-op will be
5440 called even if we are supported to be ignoring input. Double
5441 check now. Clobber *input_line_pointer so that ignore_input
5442 thinks that this is not a special pseudo-op. */
5443 c
= *input_line_pointer
;
5444 *input_line_pointer
= 0;
5445 if (ignore_input ())
5447 *input_line_pointer
= c
;
5448 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5449 ++input_line_pointer
;
5450 demand_empty_rest_of_line ();
5453 *input_line_pointer
= c
;
5455 n
= push_mri_control (mri_if
);
5457 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5458 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5461 input_line_pointer
= s
+ 3;
5463 input_line_pointer
= s
+ 1;
5467 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5468 ++input_line_pointer
;
5471 demand_empty_rest_of_line ();
5474 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5475 structured IF, associate the ELSE with the IF. Otherwise, assume
5476 it is a conditional else. */
5487 && (mri_control_stack
== NULL
5488 || mri_control_stack
->type
!= mri_if
5489 || mri_control_stack
->else_seen
))
5495 c
= *input_line_pointer
;
5496 *input_line_pointer
= 0;
5497 if (ignore_input ())
5499 *input_line_pointer
= c
;
5500 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5501 ++input_line_pointer
;
5502 demand_empty_rest_of_line ();
5505 *input_line_pointer
= c
;
5507 if (mri_control_stack
== NULL
5508 || mri_control_stack
->type
!= mri_if
5509 || mri_control_stack
->else_seen
)
5511 as_bad ("else without matching if");
5512 ignore_rest_of_line ();
5516 mri_control_stack
->else_seen
= 1;
5518 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
5521 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
5525 colon (mri_control_stack
->next
);
5529 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5530 ++input_line_pointer
;
5533 demand_empty_rest_of_line ();
5536 /* Handle the MRI ENDI pseudo-op. */
5542 if (mri_control_stack
== NULL
5543 || mri_control_stack
->type
!= mri_if
)
5545 as_bad ("endi without matching if");
5546 ignore_rest_of_line ();
5550 /* ignore_input will not return true for ENDI, so we don't need to
5551 worry about checking it again here. */
5553 if (! mri_control_stack
->else_seen
)
5554 colon (mri_control_stack
->next
);
5555 colon (mri_control_stack
->bottom
);
5561 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5562 ++input_line_pointer
;
5565 demand_empty_rest_of_line ();
5568 /* Handle the MRI BREAK pseudo-op. */
5571 s_mri_break (extent
)
5574 struct mri_control_info
*n
;
5578 n
= mri_control_stack
;
5580 && n
->type
!= mri_for
5581 && n
->type
!= mri_repeat
5582 && n
->type
!= mri_while
)
5586 as_bad ("break outside of structured loop");
5587 ignore_rest_of_line ();
5591 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
5594 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
5600 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5601 ++input_line_pointer
;
5604 demand_empty_rest_of_line ();
5607 /* Handle the MRI NEXT pseudo-op. */
5613 struct mri_control_info
*n
;
5617 n
= mri_control_stack
;
5619 && n
->type
!= mri_for
5620 && n
->type
!= mri_repeat
5621 && n
->type
!= mri_while
)
5625 as_bad ("next outside of structured loop");
5626 ignore_rest_of_line ();
5630 buf
= (char *) xmalloc (20 + strlen (n
->next
));
5633 sprintf (buf
, "bra%s %s", ex
, n
->next
);
5639 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5640 ++input_line_pointer
;
5643 demand_empty_rest_of_line ();
5646 /* Handle the MRI FOR pseudo-op. */
5652 const char *varstart
, *varstop
;
5653 const char *initstart
, *initstop
;
5654 const char *endstart
, *endstop
;
5655 const char *bystart
, *bystop
;
5659 struct mri_control_info
*n
;
5665 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
5669 varstart
= input_line_pointer
;
5671 /* Look for the '='. */
5672 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
5673 && *input_line_pointer
!= '=')
5674 ++input_line_pointer
;
5675 if (*input_line_pointer
!= '=')
5677 as_bad ("missing =");
5678 ignore_rest_of_line ();
5682 varstop
= input_line_pointer
;
5683 if (varstop
> varstart
5684 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
5687 ++input_line_pointer
;
5689 initstart
= input_line_pointer
;
5691 /* Look for TO or DOWNTO. */
5694 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5696 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
5697 && ! is_part_of_name (input_line_pointer
[2]))
5699 initstop
= input_line_pointer
;
5700 input_line_pointer
+= 2;
5703 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
5704 && ! is_part_of_name (input_line_pointer
[6]))
5706 initstop
= input_line_pointer
;
5708 input_line_pointer
+= 6;
5711 ++input_line_pointer
;
5713 if (initstop
== NULL
)
5715 as_bad ("missing to or downto");
5716 ignore_rest_of_line ();
5719 if (initstop
> initstart
5720 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
5724 endstart
= input_line_pointer
;
5726 /* Look for BY or DO. */
5729 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5731 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
5732 && ! is_part_of_name (input_line_pointer
[2]))
5734 endstop
= input_line_pointer
;
5736 input_line_pointer
+= 2;
5739 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
5740 && (input_line_pointer
[2] == '.'
5741 || ! is_part_of_name (input_line_pointer
[2])))
5743 endstop
= input_line_pointer
;
5744 input_line_pointer
+= 2;
5747 ++input_line_pointer
;
5749 if (endstop
== NULL
)
5751 as_bad ("missing do");
5752 ignore_rest_of_line ();
5755 if (endstop
> endstart
5756 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
5762 bystop
= bystart
+ 2;
5767 bystart
= input_line_pointer
;
5771 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5773 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
5774 && (input_line_pointer
[2] == '.'
5775 || ! is_part_of_name (input_line_pointer
[2])))
5777 bystop
= input_line_pointer
;
5778 input_line_pointer
+= 2;
5781 ++input_line_pointer
;
5785 as_bad ("missing do");
5786 ignore_rest_of_line ();
5789 if (bystop
> bystart
5790 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
5794 if (*input_line_pointer
!= '.')
5798 extent
= input_line_pointer
[1];
5799 input_line_pointer
+= 2;
5802 /* We have fully parsed the FOR operands. Now build the loop. */
5804 n
= push_mri_control (mri_for
);
5806 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
5817 memcpy (s
, initstart
, initstop
- initstart
);
5818 s
+= initstop
- initstart
;
5820 memcpy (s
, varstart
, varstop
- varstart
);
5821 s
+= varstop
- varstart
;
5835 memcpy (s
, endstart
, endstop
- endstart
);
5836 s
+= endstop
- endstart
;
5838 memcpy (s
, varstart
, varstop
- varstart
);
5839 s
+= varstop
- varstart
;
5847 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
5849 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
5852 /* Put together the add or sub instruction used by ENDF. */
5862 memcpy (s
, bystart
, bystop
- bystart
);
5863 s
+= bystop
- bystart
;
5865 memcpy (s
, varstart
, varstop
- varstart
);
5866 s
+= varstop
- varstart
;
5872 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5873 ++input_line_pointer
;
5876 demand_empty_rest_of_line ();
5879 /* Handle the MRI ENDF pseudo-op. */
5885 if (mri_control_stack
== NULL
5886 || mri_control_stack
->type
!= mri_for
)
5888 as_bad ("endf without for");
5889 ignore_rest_of_line ();
5893 colon (mri_control_stack
->next
);
5895 md_assemble (mri_control_stack
->incr
);
5897 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
5898 md_assemble (mri_control_stack
->incr
);
5900 free (mri_control_stack
->incr
);
5902 colon (mri_control_stack
->bottom
);
5908 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5909 ++input_line_pointer
;
5912 demand_empty_rest_of_line ();
5915 /* Handle the MRI REPEAT pseudo-op. */
5918 s_mri_repeat (ignore
)
5921 struct mri_control_info
*n
;
5923 n
= push_mri_control (mri_repeat
);
5927 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5928 ++input_line_pointer
;
5930 demand_empty_rest_of_line ();
5933 /* Handle the MRI UNTIL pseudo-op. */
5941 if (mri_control_stack
== NULL
5942 || mri_control_stack
->type
!= mri_repeat
)
5944 as_bad ("until without repeat");
5945 ignore_rest_of_line ();
5949 colon (mri_control_stack
->next
);
5951 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
5954 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
5955 mri_control_stack
->top
, '\0');
5957 colon (mri_control_stack
->bottom
);
5959 input_line_pointer
= s
;
5965 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5966 ++input_line_pointer
;
5969 demand_empty_rest_of_line ();
5972 /* Handle the MRI WHILE pseudo-op. */
5980 struct mri_control_info
*n
;
5982 s
= input_line_pointer
;
5983 while (! is_end_of_line
[(unsigned char) *s
]
5984 && (! flag_mri
|| *s
!= '*'))
5987 while (*s
== ' ' || *s
== '\t')
5989 if (s
- input_line_pointer
> 1
5992 if (s
- input_line_pointer
< 2
5993 || strncasecmp (s
- 1, "DO", 2) != 0)
5995 as_bad ("missing do");
5996 ignore_rest_of_line ();
6000 n
= push_mri_control (mri_while
);
6004 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6005 s
[1] == '.' ? s
[2] : '\0');
6007 input_line_pointer
= s
+ 1;
6008 if (*input_line_pointer
== '.')
6009 input_line_pointer
+= 2;
6013 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6014 ++input_line_pointer
;
6017 demand_empty_rest_of_line ();
6020 /* Handle the MRI ENDW pseudo-op. */
6028 if (mri_control_stack
== NULL
6029 || mri_control_stack
->type
!= mri_while
)
6031 as_bad ("endw without while");
6032 ignore_rest_of_line ();
6036 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6037 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6041 colon (mri_control_stack
->bottom
);
6047 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6048 ++input_line_pointer
;
6051 demand_empty_rest_of_line ();
6056 * Invocation line includes a switch not recognized by the base assembler.
6057 * See if it's a processor-specific option. These are:
6059 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6060 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6061 * Select the architecture. Instructions or features not
6062 * supported by the selected architecture cause fatal
6063 * errors. More than one may be specified. The default is
6064 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6065 * for -m68000, and -m68882 is a synonym for -m68881.
6066 * -[A]m[c]no-68851, -[A]m[c]no-68881
6067 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6068 * so don't use or document it, but that's the way the parsing
6071 * -pic Indicates PIC.
6072 * -k Indicates PIC. (Sun 3 only.)
6077 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6079 CONST
char *md_shortopts
= "lSA:m:k";
6082 struct option md_longopts
[] = {
6083 #define OPTION_PIC (OPTION_MD_BASE)
6084 {"pic", no_argument
, NULL
, OPTION_PIC
},
6085 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6086 {"register-prefix-optional", no_argument
, NULL
,
6087 OPTION_REGISTER_PREFIX_OPTIONAL
},
6088 {NULL
, no_argument
, NULL
, 0}
6090 size_t md_longopts_size
= sizeof(md_longopts
);
6093 md_parse_option (c
, arg
)
6099 case 'l': /* -l means keep external to 2 bit offset
6100 rather than 16 bit one */
6101 flag_short_refs
= 1;
6104 case 'S': /* -S means that jbsr's always turn into
6106 flag_long_jumps
= 1;
6112 /* intentional fall-through */
6115 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6119 const char *oarg
= arg
;
6125 if (arg
[0] == 'c' && arg
[1] == '6')
6128 for (i
= 0; i
< n_archs
; i
++)
6129 if (!strcmp (arg
, archs
[i
].name
))
6134 as_bad ("unrecognized option `%s'", oarg
);
6137 arch
= archs
[i
].arch
;
6140 else if (arch
== m68851
)
6149 if (arg
[0] == 'c' && arg
[1] == '6')
6152 for (i
= 0; i
< n_archs
; i
++)
6153 if (!strcmp (arg
, archs
[i
].name
))
6155 unsigned long arch
= archs
[i
].arch
;
6156 if (cpu_of_arch (arch
))
6157 /* It's a cpu spec. */
6159 current_architecture
&= ~m68000up
;
6160 current_architecture
|= arch
;
6162 else if (arch
== m68881
)
6164 current_architecture
|= m68881
;
6167 else if (arch
== m68851
)
6169 current_architecture
|= m68851
;
6179 as_bad ("unrecognized architecture specification `%s'", arg
);
6188 break; /* -pic, Position Independent Code */
6190 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6191 flag_reg_prefix_optional
= 1;
6194 /* -V: SVR4 argument to print version ID. */
6196 print_version_id ();
6199 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6200 should be emitted or not. FIXME: Not implemented. */
6212 md_show_usage (stream
)
6217 -l use 1 word for refs to undefined symbols [default 2]\n\
6218 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6219 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6221 specify variant of 680X0 architecture [default 68020]\n\
6222 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6223 target has/lacks floating-point coprocessor\n\
6224 [default yes for 68020, 68030, and cpu32]\n");
6226 -m68851 | -mno-68851\n\
6227 target has/lacks memory-management unit coprocessor\n\
6228 [default yes for 68020 and up]\n\
6229 -pic, -k generate position independent code\n\
6230 -S turn jbsr into jsr\n\
6231 --register-prefix-optional\n\
6232 recognize register names without prefix character\n");
6237 /* TEST2: Test md_assemble() */
6238 /* Warning, this routine probably doesn't work anymore */
6242 struct m68k_it the_ins
;
6250 if (!gets (buf
) || !*buf
)
6252 if (buf
[0] == '|' || buf
[1] == '.')
6254 for (cp
= buf
; *cp
; cp
++)
6259 memset (&the_ins
, '\0', sizeof (the_ins
));
6260 m68k_ip (&the_ins
, buf
);
6263 printf ("Error %s in %s\n", the_ins
.error
, buf
);
6267 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
6268 for (n
= 0; n
< the_ins
.numo
; n
++)
6269 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
6271 print_the_insn (&the_ins
.opcode
[0], stdout
);
6272 (void) putchar ('\n');
6274 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
6276 if (the_ins
.operands
[n
].error
)
6278 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
6281 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
6282 if (the_ins
.operands
[n
].b_const
)
6283 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
6284 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
6285 if (the_ins
.operands
[n
].b_iadd
)
6286 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
6287 (void) putchar ('\n');
6299 while (*str
&& *str
!= ' ')
6301 if (str
[-1] == ':' || str
[1] == '=')
6308 /* Possible states for relaxation:
6310 0 0 branch offset byte (bra, etc)
6314 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6318 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6325 /* We have no need to default values of symbols. */
6329 md_undefined_symbol (name
)
6335 /* Round up a section size to the appropriate boundary. */
6337 md_section_align (segment
, size
)
6341 return size
; /* Byte alignment is fine */
6344 /* Exactly what point is a PC-relative offset relative TO?
6345 On the 68k, it is relative to the address of the first extension
6346 word. The difference between the addresses of the offset and the
6347 first extension word is stored in fx_pcrel_adjust. */
6349 md_pcrel_from (fixP
)
6354 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6356 adjust
= fixP
->fx_pcrel_adjust
;
6359 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
6362 #ifndef BFD_ASSEMBLER
6365 tc_coff_symbol_emit_hook (ignore
)
6371 tc_coff_sizemachdep (frag
)
6374 switch (frag
->fr_subtype
& 0x3)
6389 /* end of tc-m68k.c */