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 string holds the chars that always start a comment. If the
30 pre-processor is disabled, these aren't very useful. The macro
31 tc_comment_chars points to this. We use this, rather than the
32 usual comment_chars, so that the --bitwise-or option will work. */
33 #if (defined (OBJ_ELF) && ! defined (TE_PSOS) && ! defined (TE_LINUX)) || defined (TE_DELTA)
34 const char *m68k_comment_chars
= "|#";
36 const char *m68k_comment_chars
= "|";
39 /* This array holds the chars that only start a comment at the beginning of
40 a line. If the line seems to have the form '# 123 filename'
41 .line and .file directives will appear in the pre-processed output */
42 /* Note that input_file.c hand checks for '#' at the beginning of the
43 first line of the input file. This is because the compiler outputs
44 #NO_APP at the beginning of its output. */
45 /* Also note that comments like this one will always work. */
46 const char line_comment_chars
[] = "#";
48 const char line_separator_chars
[] = "";
50 /* Chars that can be used to separate mant from exp in floating point nums */
51 CONST
char EXP_CHARS
[] = "eE";
53 /* Chars that mean this number is a floating point constant, as
54 in "0f12.456" or "0d1.2345e12". */
56 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
58 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
59 changed in read.c . Ideally it shouldn't have to know about it at all,
60 but nothing is ideal around here. */
62 const int md_reloc_size
= 8; /* Size of relocation record */
64 /* Are we trying to generate PIC code? If so, absolute references
65 ought to be made into linkage table references or pc-relative
66 references. Not implemented. For ELF there are other means
67 to denote pic relocations. */
70 static int flag_short_refs
; /* -l option */
71 static int flag_long_jumps
; /* -S option */
73 #ifdef REGISTER_PREFIX_OPTIONAL
74 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
76 int flag_reg_prefix_optional
;
79 /* Whether --register-prefix-optional was used on the command line. */
80 static int reg_prefix_optional_seen
;
82 /* The floating point coprocessor to use by default. */
83 static enum m68k_register m68k_float_copnum
= COP1
;
85 /* If this is non-zero, then references to number(%pc) will be taken
86 to refer to number, rather than to %pc + number. */
87 static int m68k_abspcadd
;
89 /* If this is non-zero, then the quick forms of the move, add, and sub
90 instructions are used when possible. */
91 static int m68k_quick
= 1;
93 /* If this is non-zero, then if the size is not specified for a base
94 or outer displacement, the assembler assumes that the size should
96 static int m68k_rel32
= 1;
98 /* Its an arbitrary name: This means I don't approve of it */
99 /* See flames below */
100 static struct obstack robyn
;
102 #define TAB(x,y) (((x)<<2)+(y))
103 #define TABTYPE(xy) ((xy) >> 2)
109 /* Case `g' except when BCC68000 is applicable. */
111 /* Coprocessor branches. */
113 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
114 supported on all cpus. Widens to 32-bit absolute. */
116 /* For inserting an extra jmp instruction with long offset on 68000,
117 for expanding conditional branches. (Not bsr or bra.) Since the
118 68000 doesn't support 32-bit displacements for conditional
119 branches, we fake it by reversing the condition and branching
120 around a jmp with an absolute long operand. */
122 /* For the DBcc "instructions". If the displacement requires 32 bits,
123 the branch-around-a-jump game is played here too. */
125 /* Not currently used? */
127 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
133 const char *m_operands
;
134 unsigned long m_opcode
;
138 struct m68k_incant
*m_next
;
141 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
142 #define gettwo(x) (((x)->m_opcode)&0xffff)
144 static const enum m68k_register m68000_control_regs
[] = { 0 };
145 static const enum m68k_register m68010_control_regs
[] = {
149 static const enum m68k_register m68020_control_regs
[] = {
150 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
153 static const enum m68k_register m68040_control_regs
[] = {
154 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
155 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
158 static const enum m68k_register m68060_control_regs
[] = {
159 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
160 USP
, VBR
, URP
, SRP
, PCR
,
163 static const enum m68k_register mcf5200_control_regs
[] = {
164 CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, VBR
, ROMBAR
,
165 RAMBAR0
, RAMBAR1
, MBAR
,
168 #define cpu32_control_regs m68010_control_regs
170 static const enum m68k_register
*control_regs
;
172 /* internal form of a 68020 instruction */
176 const char *args
; /* list of opcode info */
179 int numo
; /* Number of shorts in opcode */
182 struct m68k_op operands
[6];
184 int nexp
; /* number of exprs in use */
185 struct m68k_exp exprs
[4];
187 int nfrag
; /* Number of frags we have to produce */
190 int fragoff
; /* Where in the current opcode the frag ends */
197 int nrel
; /* Num of reloc strucs in use */
204 /* In a pc relative address the difference between the address
205 of the offset and the address that the offset is relative
206 to. This depends on the addressing mode. Basically this
207 is the value to put in the offset field to address the
208 first byte of the offset, without regarding the special
209 significance of some values (in the branch instruction, for
213 /* Whether this expression needs special pic relocation, and if
215 enum pic_relocation pic_reloc
;
218 reloc
[5]; /* Five is enough??? */
221 #define cpu_of_arch(x) ((x) & (m68000up|mcf5200))
222 #define float_of_arch(x) ((x) & mfloat)
223 #define mmu_of_arch(x) ((x) & mmmu)
225 static struct m68k_it the_ins
; /* the instruction being assembled */
227 #define op(ex) ((ex)->exp.X_op)
228 #define adds(ex) ((ex)->exp.X_add_symbol)
229 #define subs(ex) ((ex)->exp.X_op_symbol)
230 #define offs(ex) ((ex)->exp.X_add_number)
232 /* Macros for adding things to the m68k_it struct */
234 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
236 /* Like addword, but goes BEFORE general operands */
240 struct m68k_incant
*opcode
;
243 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
244 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
245 for(z
=0;z
<the_ins
.nrel
;z
++)
246 the_ins
.reloc
[z
].n
+=2;
247 for (z
= 0; z
< the_ins
.nfrag
; z
++)
248 the_ins
.fragb
[z
].fragoff
++;
249 the_ins
.opcode
[opcode
->m_codenum
]=w
;
253 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
256 add_fix (width
, exp
, pc_rel
, pc_fix
)
258 struct m68k_exp
*exp
;
262 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
266 : (the_ins
.numo
*2)));
267 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
268 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
269 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
271 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
273 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
276 /* Cause an extra frag to be generated here, inserting up to 10 bytes
277 (that value is chosen in the frag_var call in md_assemble). TYPE
278 is the subtype of the frag to be generated; its primary type is
279 rs_machine_dependent.
281 The TYPE parameter is also used by md_convert_frag_1 and
282 md_estimate_size_before_relax. The appropriate type of fixup will
283 be emitted by md_convert_frag_1.
285 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
287 add_frag(add
,off
,type
)
292 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
293 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
294 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
295 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
299 (op (ex) != O_constant && op (ex) != O_big)
301 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
302 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
303 static int reverse_16_bits
PARAMS ((int in
));
304 static int reverse_8_bits
PARAMS ((int in
));
305 static void install_gen_operand
PARAMS ((int mode
, int val
));
306 static void install_operand
PARAMS ((int mode
, int val
));
307 static void s_bss
PARAMS ((int));
308 static void s_data1
PARAMS ((int));
309 static void s_data2
PARAMS ((int));
310 static void s_even
PARAMS ((int));
311 static void s_proc
PARAMS ((int));
312 static void mri_chip
PARAMS ((void));
313 static void s_chip
PARAMS ((int));
314 static void s_fopt
PARAMS ((int));
315 static void s_opt
PARAMS ((int));
316 static void s_reg
PARAMS ((int));
317 static void s_restore
PARAMS ((int));
318 static void s_save
PARAMS ((int));
319 static void s_mri_if
PARAMS ((int));
320 static void s_mri_else
PARAMS ((int));
321 static void s_mri_endi
PARAMS ((int));
322 static void s_mri_break
PARAMS ((int));
323 static void s_mri_next
PARAMS ((int));
324 static void s_mri_for
PARAMS ((int));
325 static void s_mri_endf
PARAMS ((int));
326 static void s_mri_repeat
PARAMS ((int));
327 static void s_mri_until
PARAMS ((int));
328 static void s_mri_while
PARAMS ((int));
329 static void s_mri_endw
PARAMS ((int));
331 static int current_architecture
;
339 static const struct m68k_cpu archs
[] = {
340 { m68000
, "68000", 0 },
341 { m68010
, "68010", 0 },
342 { m68020
, "68020", 0 },
343 { m68030
, "68030", 0 },
344 { m68040
, "68040", 0 },
345 { m68060
, "68060", 0 },
346 { cpu32
, "cpu32", 0 },
347 { m68881
, "68881", 0 },
348 { m68851
, "68851", 0 },
349 { mcf5200
, "5200", 0 },
350 /* Aliases (effectively, so far as gas is concerned) for the above
352 { m68020
, "68k", 1 },
353 { m68000
, "68302", 1 },
354 { m68000
, "68008", 1 },
355 { m68000
, "68ec000", 1 },
356 { m68000
, "68hc000", 1 },
357 { m68000
, "68hc001", 1 },
358 { m68020
, "68ec020", 1 },
359 { m68030
, "68ec030", 1 },
360 { m68040
, "68ec040", 1 },
361 { m68060
, "68ec060", 1 },
362 { cpu32
, "68330", 1 },
363 { cpu32
, "68331", 1 },
364 { cpu32
, "68332", 1 },
365 { cpu32
, "68333", 1 },
366 { cpu32
, "68340", 1 },
367 { cpu32
, "68360", 1 },
368 { m68881
, "68882", 1 },
371 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
373 /* BCC68000 is for patching in an extra jmp instruction for long offsets
374 on the 68000. The 68000 doesn't support long branches with branchs */
376 /* This table desribes how you change sizes for the various types of variable
377 size expressions. This version only supports two kinds. */
379 /* Note that calls to frag_var need to specify the maximum expansion
380 needed; this is currently 10 bytes for DBCC. */
383 How far Forward this mode will reach:
384 How far Backward this mode will reach:
385 How many bytes this mode will add to the size of the frag
386 Which mode to go to if the offset won't fit in this one
388 relax_typeS md_relax_table
[] =
390 {1, 1, 0, 0}, /* First entries aren't used */
391 {1, 1, 0, 0}, /* For no good reason except */
392 {1, 1, 0, 0}, /* that the VAX doesn't either */
395 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
396 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
400 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
401 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
405 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
406 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
410 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
411 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
412 {0, 0, 6, 0}, /* jmp long space */
415 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
416 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
417 {0, 0, 10, 0}, /* bra/jmp long space */
420 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
421 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
425 /* For, e.g., jmp pcrel indexed. */
426 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
427 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
432 /* These are the machine dependent pseudo-ops. These are included so
433 the assembler can work on the output from the SUN C compiler, which
437 /* This table describes all the machine specific pseudo-ops the assembler
438 has to support. The fields are:
439 pseudo-op name without dot
440 function to call to execute this pseudo-op
441 Integer arg to pass to the function
443 const pseudo_typeS md_pseudo_table
[] =
445 {"data1", s_data1
, 0},
446 {"data2", s_data2
, 0},
449 {"skip", s_space
, 0},
451 #if defined (TE_SUN3) || defined (OBJ_ELF)
452 {"align", s_align_bytes
, 0},
455 {"swbeg", s_ignore
, 0},
457 {"extend", float_cons
, 'x'},
458 {"ldouble", float_cons
, 'x'},
460 /* The following pseudo-ops are supported for MRI compatibility. */
462 {"comline", s_space
, 1},
464 {"mask2", s_ignore
, 0},
467 {"restore", s_restore
, 0},
471 {"if.b", s_mri_if
, 'b'},
472 {"if.w", s_mri_if
, 'w'},
473 {"if.l", s_mri_if
, 'l'},
474 {"else", s_mri_else
, 0},
475 {"else.s", s_mri_else
, 's'},
476 {"else.l", s_mri_else
, 'l'},
477 {"endi", s_mri_endi
, 0},
478 {"break", s_mri_break
, 0},
479 {"break.s", s_mri_break
, 's'},
480 {"break.l", s_mri_break
, 'l'},
481 {"next", s_mri_next
, 0},
482 {"next.s", s_mri_next
, 's'},
483 {"next.l", s_mri_next
, 'l'},
484 {"for", s_mri_for
, 0},
485 {"for.b", s_mri_for
, 'b'},
486 {"for.w", s_mri_for
, 'w'},
487 {"for.l", s_mri_for
, 'l'},
488 {"endf", s_mri_endf
, 0},
489 {"repeat", s_mri_repeat
, 0},
490 {"until", s_mri_until
, 0},
491 {"until.b", s_mri_until
, 'b'},
492 {"until.w", s_mri_until
, 'w'},
493 {"until.l", s_mri_until
, 'l'},
494 {"while", s_mri_while
, 0},
495 {"while.b", s_mri_while
, 'b'},
496 {"while.w", s_mri_while
, 'w'},
497 {"while.l", s_mri_while
, 'l'},
498 {"endw", s_mri_endw
, 0},
504 /* The mote pseudo ops are put into the opcode table, since they
505 don't start with a . they look like opcodes to gas.
507 extern void obj_coff_section ();
509 CONST pseudo_typeS mote_pseudo_table
[] =
522 {"xdef", s_globl
, 0},
524 {"align", s_align_bytes
, 0},
526 {"align", s_align_ptwo
, 0},
529 {"sect", obj_coff_section
, 0},
530 {"section", obj_coff_section
, 0},
535 #define issbyte(x) ((x)>=-128 && (x)<=127)
536 #define isubyte(x) ((x)>=0 && (x)<=255)
537 #define issword(x) ((x)>=-32768 && (x)<=32767)
538 #define isuword(x) ((x)>=0 && (x)<=65535)
540 #define isbyte(x) ((x)>= -255 && (x)<=255)
541 #define isword(x) ((x)>=-65536 && (x)<=65535)
542 #define islong(x) (1)
544 extern char *input_line_pointer
;
546 static char mklower_table
[256];
547 #define mklower(c) (mklower_table[(unsigned char)(c)])
548 static char notend_table
[256];
549 static char alt_notend_table
[256];
551 (! (notend_table[(unsigned char) *s] \
553 && alt_notend_table[(unsigned char) s[1]])))
555 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
557 #ifdef NO_PCREL_RELOCS
560 make_pcrel_absolute(fixP
, add_number
)
564 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
566 /* rewrite the PC relative instructions to absolute address ones.
567 * these are rumoured to be faster, and the apollo linker refuses
568 * to deal with the PC relative relocations.
570 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
575 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
581 as_fatal ("Unknown PC relative instruction");
586 #endif /* NO_PCREL_RELOCS */
589 tc_coff_fix2rtype (fixP
)
592 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
593 return R_RELLONG_NEG
;
594 #ifdef NO_PCREL_RELOCS
595 know (fixP
->fx_pcrel
== 0);
596 return (fixP
->fx_size
== 1 ? R_RELBYTE
597 : fixP
->fx_size
== 2 ? R_DIR16
600 return (fixP
->fx_pcrel
?
601 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
602 fixP
->fx_size
== 2 ? R_PCRWORD
:
604 (fixP
->fx_size
== 1 ? R_RELBYTE
:
605 fixP
->fx_size
== 2 ? R_RELWORD
:
614 /* Compute the relocation code for a fixup of SIZE bytes, using pc
615 relative relocation if PCREL is non-zero. PIC says whether a special
616 pic relocation was requested. */
618 static bfd_reloc_code_real_type get_reloc_code
619 PARAMS ((int, int, enum pic_relocation
));
621 static bfd_reloc_code_real_type
622 get_reloc_code (size
, pcrel
, pic
)
625 enum pic_relocation pic
;
633 return BFD_RELOC_8_GOT_PCREL
;
635 return BFD_RELOC_16_GOT_PCREL
;
637 return BFD_RELOC_32_GOT_PCREL
;
645 return BFD_RELOC_8_GOTOFF
;
647 return BFD_RELOC_16_GOTOFF
;
649 return BFD_RELOC_32_GOTOFF
;
657 return BFD_RELOC_8_PLT_PCREL
;
659 return BFD_RELOC_16_PLT_PCREL
;
661 return BFD_RELOC_32_PLT_PCREL
;
669 return BFD_RELOC_8_PLTOFF
;
671 return BFD_RELOC_16_PLTOFF
;
673 return BFD_RELOC_32_PLTOFF
;
683 return BFD_RELOC_8_PCREL
;
685 return BFD_RELOC_16_PCREL
;
687 return BFD_RELOC_32_PCREL
;
704 as_bad ("Can not do %d byte %s%srelocation", size
,
705 pcrel
? "pc-relative " : "",
706 pic
== pic_none
? "" : "pic ");
707 return BFD_RELOC_NONE
;
710 /* Here we decide which fixups can be adjusted to make them relative
711 to the beginning of the section instead of the symbol. Basically
712 we need to make sure that the dynamic relocations are done
713 correctly, so in some cases we force the original symbol to be
716 tc_m68k_fix_adjustable (fixP
)
719 /* Prevent all adjustments to global symbols. */
720 if (S_IS_EXTERNAL (fixP
->fx_addsy
))
723 /* adjust_reloc_syms doesn't know about the GOT */
724 switch (fixP
->fx_r_type
)
726 case BFD_RELOC_8_GOT_PCREL
:
727 case BFD_RELOC_16_GOT_PCREL
:
728 case BFD_RELOC_32_GOT_PCREL
:
729 case BFD_RELOC_8_GOTOFF
:
730 case BFD_RELOC_16_GOTOFF
:
731 case BFD_RELOC_32_GOTOFF
:
732 case BFD_RELOC_8_PLT_PCREL
:
733 case BFD_RELOC_16_PLT_PCREL
:
734 case BFD_RELOC_32_PLT_PCREL
:
735 case BFD_RELOC_8_PLTOFF
:
736 case BFD_RELOC_16_PLTOFF
:
737 case BFD_RELOC_32_PLTOFF
:
747 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
754 tc_gen_reloc (section
, fixp
)
759 bfd_reloc_code_real_type code
;
764 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
766 code
= fixp
->fx_r_type
;
768 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
769 that fixup_segment converted a non-PC relative reloc into a
770 PC relative reloc. In such a case, we need to convert the
777 code
= BFD_RELOC_8_PCREL
;
780 code
= BFD_RELOC_16_PCREL
;
783 code
= BFD_RELOC_32_PCREL
;
785 case BFD_RELOC_8_PCREL
:
786 case BFD_RELOC_16_PCREL
:
787 case BFD_RELOC_32_PCREL
:
788 case BFD_RELOC_8_GOT_PCREL
:
789 case BFD_RELOC_16_GOT_PCREL
:
790 case BFD_RELOC_32_GOT_PCREL
:
791 case BFD_RELOC_8_GOTOFF
:
792 case BFD_RELOC_16_GOTOFF
:
793 case BFD_RELOC_32_GOTOFF
:
794 case BFD_RELOC_8_PLT_PCREL
:
795 case BFD_RELOC_16_PLT_PCREL
:
796 case BFD_RELOC_32_PLT_PCREL
:
797 case BFD_RELOC_8_PLTOFF
:
798 case BFD_RELOC_16_PLTOFF
:
799 case BFD_RELOC_32_PLTOFF
:
802 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
803 "Cannot make %s relocation PC relative",
804 bfd_get_reloc_code_name (code
));
810 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
811 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
813 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
814 MAP (1, 0, BFD_RELOC_8
);
815 MAP (2, 0, BFD_RELOC_16
);
816 MAP (4, 0, BFD_RELOC_32
);
817 MAP (1, 1, BFD_RELOC_8_PCREL
);
818 MAP (2, 1, BFD_RELOC_16_PCREL
);
819 MAP (4, 1, BFD_RELOC_32_PCREL
);
827 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
829 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
830 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
833 reloc
->addend
= fixp
->fx_addnumber
;
838 reloc
->addend
= fixp
->fx_addnumber
;
840 reloc
->addend
= (section
->vma
841 + (fixp
->fx_pcrel_adjust
== 64
842 ? -1 : fixp
->fx_pcrel_adjust
)
844 + md_pcrel_from (fixp
));
847 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
848 assert (reloc
->howto
!= 0);
853 #endif /* BFD_ASSEMBLER */
855 /* Handle of the OPCODE hash table. NULL means any use before
856 m68k_ip_begin() will crash. */
857 static struct hash_control
*op_hash
;
859 /* Assemble an m68k instruction. */
866 register struct m68k_op
*opP
;
867 register struct m68k_incant
*opcode
;
868 register const char *s
;
869 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
870 char *pdot
, *pdotmove
;
871 enum m68k_size siz1
, siz2
;
875 char *crack_operand ();
876 LITTLENUM_TYPE words
[6];
877 LITTLENUM_TYPE
*wordp
;
878 unsigned long ok_arch
= 0;
880 if (*instring
== ' ')
881 instring
++; /* skip leading whitespace */
883 /* Scan up to end of operation-code, which MUST end in end-of-string
884 or exactly 1 space. */
886 for (p
= instring
; *p
!= '\0'; p
++)
896 the_ins
.error
= "No operator";
900 /* p now points to the end of the opcode name, probably whitespace.
901 Make sure the name is null terminated by clobbering the
902 whitespace, look it up in the hash table, then fix it back.
903 Remove a dot, first, since the opcode tables have none. */
906 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
907 *pdotmove
= pdotmove
[1];
913 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
918 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
919 *pdotmove
= pdotmove
[-1];
926 the_ins
.error
= "Unknown operator";
930 /* found a legitimate opcode, start matching operands */
934 if (opcode
->m_operands
== 0)
936 char *old
= input_line_pointer
;
938 input_line_pointer
= p
;
939 /* Ahh - it's a motorola style psuedo op */
940 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
941 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
942 input_line_pointer
= old
;
948 if (flag_mri
&& opcode
->m_opnum
== 0)
950 /* In MRI mode, random garbage is allowed after an instruction
951 which accepts no operands. */
952 the_ins
.args
= opcode
->m_operands
;
953 the_ins
.numargs
= opcode
->m_opnum
;
954 the_ins
.numo
= opcode
->m_codenum
;
955 the_ins
.opcode
[0] = getone (opcode
);
956 the_ins
.opcode
[1] = gettwo (opcode
);
960 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
962 p
= crack_operand (p
, opP
);
966 the_ins
.error
= opP
->error
;
971 opsfound
= opP
- &the_ins
.operands
[0];
973 /* This ugly hack is to support the floating pt opcodes in their
974 standard form. Essentially, we fake a first enty of type COP#1 */
975 if (opcode
->m_operands
[0] == 'I')
979 for (n
= opsfound
; n
> 0; --n
)
980 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
982 memset ((char *) (&the_ins
.operands
[0]), '\0',
983 sizeof (the_ins
.operands
[0]));
984 the_ins
.operands
[0].mode
= CONTROL
;
985 the_ins
.operands
[0].reg
= m68k_float_copnum
;
989 /* We've got the operands. Find an opcode that'll accept them */
992 /* If we didn't get the right number of ops, or we have no
993 common model with this pattern then reject this pattern. */
995 if (opsfound
!= opcode
->m_opnum
996 || ((opcode
->m_arch
& current_architecture
) == 0))
999 ok_arch
|= opcode
->m_arch
;
1003 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
1007 /* Warning: this switch is huge! */
1008 /* I've tried to organize the cases into this order:
1009 non-alpha first, then alpha by letter. Lower-case
1010 goes directly before uppercase counterpart. */
1011 /* Code with multiple case ...: gets sorted by the lowest
1012 case ... it belongs to. I hope this makes sense. */
1052 if (opP
->mode
!= IMMED
)
1054 else if (s
[1] == 'b'
1055 && ! isvar (&opP
->disp
)
1056 && (opP
->disp
.exp
.X_op
!= O_constant
1057 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1059 else if (s
[1] == 'w'
1060 && ! isvar (&opP
->disp
)
1061 && (opP
->disp
.exp
.X_op
!= O_constant
1062 || ! isword (opP
->disp
.exp
.X_add_number
)))
1064 else if (s
[1] == 'W'
1065 && ! isvar (&opP
->disp
)
1066 && (opP
->disp
.exp
.X_op
!= O_constant
1067 || ! issword (opP
->disp
.exp
.X_add_number
)))
1073 if (opP
->mode
!= IMMED
)
1078 if (opP
->mode
== AREG
1079 || opP
->mode
== CONTROL
1080 || opP
->mode
== FPREG
1081 || opP
->mode
== IMMED
1082 || opP
->mode
== REGLST
1083 || (opP
->mode
!= ABSL
1085 || opP
->reg
== ZPC
)))
1090 if (opP
->mode
== CONTROL
1091 || opP
->mode
== FPREG
1092 || opP
->mode
== REGLST
1093 || opP
->mode
== IMMED
1094 || (opP
->mode
!= ABSL
1096 || opP
->reg
== ZPC
)))
1124 if (opP
->mode
== CONTROL
1125 || opP
->mode
== FPREG
1126 || opP
->mode
== REGLST
)
1131 if (opP
->mode
!= AINC
)
1136 if (opP
->mode
!= ADEC
)
1186 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1207 case '~': /* For now! (JF FOO is this right?) */
1229 if (opP
->mode
!= CONTROL
1230 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1235 if (opP
->mode
!= AREG
)
1240 if (opP
->mode
!= AINDR
)
1245 if (opP
->mode
!= ABSL
1247 && strncmp (instring
, "jbsr", 4) == 0))
1252 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1257 if (opP
->mode
!= DISP
1259 || opP
->reg
> ADDR7
)
1264 if (opP
->mode
!= DREG
)
1269 if (opP
->mode
!= FPREG
)
1274 if (opP
->mode
!= CONTROL
1281 if (opP
->mode
!= CONTROL
1283 || opP
->reg
> last_movec_reg
)
1287 const enum m68k_register
*rp
;
1288 for (rp
= control_regs
; *rp
; rp
++)
1289 if (*rp
== opP
->reg
)
1297 if (opP
->mode
!= IMMED
)
1303 if (opP
->mode
== DREG
1304 || opP
->mode
== AREG
1305 || opP
->mode
== FPREG
)
1314 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1317 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1320 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1328 else if (opP
->mode
== CONTROL
)
1337 opP
->mask
= 1 << 24;
1340 opP
->mask
= 1 << 25;
1343 opP
->mask
= 1 << 26;
1352 else if (opP
->mode
== ABSL
1353 && opP
->disp
.size
== SIZE_UNSPEC
1354 && opP
->disp
.exp
.X_op
== O_constant
)
1356 /* This is what the MRI REG pseudo-op generates. */
1358 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1360 else if (opP
->mode
!= REGLST
)
1362 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1364 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1369 if (opP
->mode
!= IMMED
)
1371 else if (opP
->disp
.exp
.X_op
!= O_constant
1372 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1374 else if (! m68k_quick
1375 && instring
[3] != 'q'
1376 && instring
[4] != 'q')
1381 if (opP
->mode
!= DREG
1382 && opP
->mode
!= IMMED
1383 && opP
->mode
!= ABSL
)
1388 if (opP
->mode
!= IMMED
)
1390 else if (opP
->disp
.exp
.X_op
!= O_constant
1391 || opP
->disp
.exp
.X_add_number
< 1
1392 || opP
->disp
.exp
.X_add_number
> 8)
1394 else if (! m68k_quick
1395 && (strncmp (instring
, "add", 3) == 0
1396 || strncmp (instring
, "sub", 3) == 0)
1397 && instring
[3] != 'q')
1402 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1407 if (opP
->mode
!= AINDR
1408 && (opP
->mode
!= BASE
1410 && opP
->reg
!= ZADDR0
)
1411 || opP
->disp
.exp
.X_op
!= O_absent
1412 || ((opP
->index
.reg
< DATA0
1413 || opP
->index
.reg
> DATA7
)
1414 && (opP
->index
.reg
< ADDR0
1415 || opP
->index
.reg
> ADDR7
))
1416 || opP
->index
.size
!= SIZE_UNSPEC
1417 || opP
->index
.scale
!= 1))
1422 if (opP
->mode
!= CONTROL
1423 || ! (opP
->reg
== FPI
1425 || opP
->reg
== FPC
))
1430 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1435 if (opP
->mode
!= IMMED
)
1437 else if (opP
->disp
.exp
.X_op
!= O_constant
1438 || opP
->disp
.exp
.X_add_number
< 0
1439 || opP
->disp
.exp
.X_add_number
> 7)
1444 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1448 /* JF these are out of order. We could put them
1449 in order if we were willing to put up with
1450 bunches of #ifdef m68851s in the code.
1452 Don't forget that you need these operands
1453 to use 68030 MMU instructions. */
1455 /* Memory addressing mode used by pflushr */
1457 if (opP
->mode
== CONTROL
1458 || opP
->mode
== FPREG
1459 || opP
->mode
== DREG
1460 || opP
->mode
== AREG
1461 || opP
->mode
== REGLST
)
1463 /* We should accept immediate operands, but they
1464 supposedly have to be quad word, and we don't
1465 handle that. I would like to see what a Motorola
1466 assembler does before doing something here. */
1467 if (opP
->mode
== IMMED
)
1472 if (opP
->mode
!= CONTROL
1473 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1478 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1483 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1488 if (opP
->mode
!= CONTROL
1491 && opP
->reg
!= SCC
))
1496 if (opP
->mode
!= CONTROL
1502 if (opP
->mode
!= CONTROL
1505 && opP
->reg
!= CRP
))
1510 if (opP
->mode
!= CONTROL
1511 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1512 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1517 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1522 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1527 if (opP
->mode
!= CONTROL
1534 } /* not a cache specifier. */
1538 if (opP
->mode
!= ABSL
)
1544 } /* switch on type of operand */
1548 } /* for each operand */
1549 } /* if immediately wrong */
1556 opcode
= opcode
->m_next
;
1561 && !(ok_arch
& current_architecture
))
1566 "invalid instruction for this architecture; needs ");
1567 cp
= buf
+ strlen (buf
);
1571 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1574 strcpy (cp
, "mmu (68030 or 68851)");
1577 strcpy (cp
, "68020 or higher");
1580 strcpy (cp
, "68000 or higher");
1583 strcpy (cp
, "68010 or higher");
1587 int got_one
= 0, idx
;
1588 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1591 if ((archs
[idx
].arch
& ok_arch
)
1592 && ! archs
[idx
].alias
)
1596 strcpy (cp
, " or ");
1600 strcpy (cp
, archs
[idx
].name
);
1612 the_ins
.error
= "operands mismatch";
1614 } /* Fell off the end */
1619 /* now assemble it */
1621 the_ins
.args
= opcode
->m_operands
;
1622 the_ins
.numargs
= opcode
->m_opnum
;
1623 the_ins
.numo
= opcode
->m_codenum
;
1624 the_ins
.opcode
[0] = getone (opcode
);
1625 the_ins
.opcode
[1] = gettwo (opcode
);
1627 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1629 /* This switch is a doozy.
1630 Watch the first step; its a big one! */
1651 tmpreg
= 0x3c; /* 7.4 */
1652 if (strchr ("bwl", s
[1]))
1653 nextword
= get_num (&opP
->disp
, 80);
1655 nextword
= get_num (&opP
->disp
, 0);
1656 if (isvar (&opP
->disp
))
1657 add_fix (s
[1], &opP
->disp
, 0, 0);
1661 if (!isbyte (nextword
))
1662 opP
->error
= "operand out of range";
1667 if (!isword (nextword
))
1668 opP
->error
= "operand out of range";
1673 if (!issword (nextword
))
1674 opP
->error
= "operand out of range";
1679 addword (nextword
>> 16);
1706 /* We gotta put out some float */
1707 if (op (&opP
->disp
) != O_big
)
1712 /* Can other cases happen here? */
1713 if (op (&opP
->disp
) != O_constant
)
1716 val
= (valueT
) offs (&opP
->disp
);
1720 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1721 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1725 offs (&opP
->disp
) = gencnt
;
1727 if (offs (&opP
->disp
) > 0)
1729 if (offs (&opP
->disp
) > baseo
)
1731 as_warn ("Bignum too big for %c format; truncated",
1733 offs (&opP
->disp
) = baseo
;
1735 baseo
-= offs (&opP
->disp
);
1738 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1739 offs (&opP
->disp
)--;
1744 gen_to_words (words
, baseo
, (long) outro
);
1745 for (wordp
= words
; baseo
--; wordp
++)
1749 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1752 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1755 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1758 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1761 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1765 nextword
= get_num (&opP
->disp
, 80);
1768 && ! isvar (&opP
->disp
)
1771 opP
->disp
.exp
.X_op
= O_symbol
;
1772 #ifndef BFD_ASSEMBLER
1773 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1775 opP
->disp
.exp
.X_add_symbol
=
1776 section_symbol (absolute_section
);
1780 /* Force into index mode. Hope this works */
1782 /* We do the first bit for 32-bit displacements, and the
1783 second bit for 16 bit ones. It is possible that we
1784 should make the default be WORD instead of LONG, but
1785 I think that'd break GCC, so we put up with a little
1786 inefficiency for the sake of working output. */
1788 if (!issword (nextword
)
1789 || (isvar (&opP
->disp
)
1790 && ((opP
->disp
.size
== SIZE_UNSPEC
1791 && flag_short_refs
== 0
1792 && cpu_of_arch (current_architecture
) >= m68020
)
1793 || opP
->disp
.size
== SIZE_LONG
)))
1795 if (cpu_of_arch (current_architecture
) < m68020
)
1797 "displacement too large for this architecture; needs 68020 or higher";
1799 tmpreg
= 0x3B; /* 7.3 */
1801 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1802 if (isvar (&opP
->disp
))
1806 if (opP
->disp
.size
== SIZE_LONG
1808 /* If the displacement needs pic
1809 relocation it cannot be relaxed. */
1810 || opP
->disp
.pic_reloc
!= pic_none
1815 add_fix ('l', &opP
->disp
, 1, 2);
1819 add_frag (adds (&opP
->disp
),
1821 TAB (PCLEA
, SZ_UNDEF
));
1828 add_fix ('l', &opP
->disp
, 0, 0);
1833 addword (nextword
>> 16);
1838 tmpreg
= 0x3A; /* 7.2 */
1840 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1842 if (isvar (&opP
->disp
))
1846 add_fix ('w', &opP
->disp
, 1, 0);
1849 add_fix ('w', &opP
->disp
, 0, 0);
1859 baseo
= get_num (&opP
->disp
, 80);
1860 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1861 outro
= get_num (&opP
->odisp
, 80);
1862 /* Figure out the `addressing mode'.
1863 Also turn on the BASE_DISABLE bit, if needed. */
1864 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1866 tmpreg
= 0x3b; /* 7.3 */
1867 if (opP
->reg
== ZPC
)
1870 else if (opP
->reg
== 0)
1873 tmpreg
= 0x30; /* 6.garbage */
1875 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
1878 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
1881 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1883 siz1
= opP
->disp
.size
;
1884 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1885 siz2
= opP
->odisp
.size
;
1889 /* Index register stuff */
1890 if (opP
->index
.reg
!= 0
1891 && opP
->index
.reg
>= DATA
1892 && opP
->index
.reg
<= ADDR7
)
1894 nextword
|= (opP
->index
.reg
- DATA
) << 12;
1896 if (opP
->index
.size
== SIZE_UNSPEC
1897 || opP
->index
.size
== SIZE_LONG
)
1900 if ((opP
->index
.scale
!= 1
1901 && cpu_of_arch (current_architecture
) < m68020
)
1902 || (opP
->index
.scale
== 8
1903 && current_architecture
== mcf5200
))
1906 "scale factor invalid on this architecture; needs cpu32 or 68020 or higher";
1909 switch (opP
->index
.scale
)
1926 GET US OUT OF HERE! */
1928 /* Must be INDEX, with an index register. Address
1929 register cannot be ZERO-PC, and either :b was
1930 forced, or we know it will fit. For a 68000 or
1931 68010, force this mode anyways, because the
1932 larger modes aren't supported. */
1933 if (opP
->mode
== BASE
1934 && ((opP
->reg
>= ADDR0
1935 && opP
->reg
<= ADDR7
)
1938 if (siz1
== SIZE_BYTE
1939 || cpu_of_arch (current_architecture
) < m68020
1940 || (siz1
== SIZE_UNSPEC
1941 && ! isvar (&opP
->disp
)
1942 && issbyte (baseo
)))
1944 nextword
+= baseo
& 0xff;
1946 if (isvar (&opP
->disp
))
1948 /* Do a byte relocation. If it doesn't
1949 fit (possible on m68000) let the
1950 fixup processing complain later. */
1952 add_fix ('B', &opP
->disp
, 1, 1);
1954 add_fix ('B', &opP
->disp
, 0, 0);
1956 else if (siz1
!= SIZE_BYTE
)
1958 if (siz1
!= SIZE_UNSPEC
)
1959 as_warn ("Forcing byte displacement");
1960 if (! issbyte (baseo
))
1961 opP
->error
= "byte displacement out of range";
1966 else if (siz1
== SIZE_UNSPEC
1968 && isvar (&opP
->disp
)
1969 && subs (&opP
->disp
) == NULL
1971 /* If the displacement needs pic
1972 relocation it cannot be relaxed. */
1973 && opP
->disp
.pic_reloc
== pic_none
1977 nextword
+= baseo
& 0xff;
1979 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1980 TAB (PCINDEX
, SZ_UNDEF
));
1988 nextword
|= 0x40; /* No index reg */
1989 if (opP
->index
.reg
>= ZDATA0
1990 && opP
->index
.reg
<= ZDATA7
)
1991 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
1992 else if (opP
->index
.reg
>= ZADDR0
1993 || opP
->index
.reg
<= ZADDR7
)
1994 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
1997 /* It isn't simple. */
1999 if (cpu_of_arch (current_architecture
) < m68020
)
2001 "invalid operand mode for this architecture; needs 68020 or higher";
2004 /* If the guy specified a width, we assume that it is
2005 wide enough. Maybe it isn't. If so, we lose. */
2009 if (isvar (&opP
->disp
)
2011 : ! issword (baseo
))
2016 else if (! isvar (&opP
->disp
) && baseo
== 0)
2025 as_warn (":b not permitted; defaulting to :w");
2035 /* Figure out innner displacement stuff */
2036 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2038 if (cpu_of_arch (current_architecture
) & cpu32
)
2039 opP
->error
= "invalid operand mode for this architecture; needs 68020 or higher";
2043 if (isvar (&opP
->odisp
)
2045 : ! issword (outro
))
2050 else if (! isvar (&opP
->odisp
) && outro
== 0)
2059 as_warn (":b not permitted; defaulting to :w");
2068 if (opP
->mode
== POST
2069 && (nextword
& 0x40) == 0)
2074 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2076 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2077 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2079 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2081 if (siz1
== SIZE_LONG
)
2082 addword (baseo
>> 16);
2083 if (siz1
!= SIZE_UNSPEC
)
2086 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2087 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2088 if (siz2
== SIZE_LONG
)
2089 addword (outro
>> 16);
2090 if (siz2
!= SIZE_UNSPEC
)
2096 nextword
= get_num (&opP
->disp
, 80);
2097 switch (opP
->disp
.size
)
2102 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2104 tmpreg
= 0x38; /* 7.0 */
2108 /* Don't generate pc relative code on 68010 and
2110 if (isvar (&opP
->disp
)
2111 && !subs (&opP
->disp
)
2112 && adds (&opP
->disp
)
2114 /* If the displacement needs pic relocation it
2115 cannot be relaxed. */
2116 && opP
->disp
.pic_reloc
== pic_none
2118 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2119 && cpu_of_arch (current_architecture
) >= m68020
2121 && !strchr ("~%&$?", s
[0]))
2123 tmpreg
= 0x3A; /* 7.2 */
2124 add_frag (adds (&opP
->disp
),
2126 TAB (PCREL
, SZ_UNDEF
));
2129 /* Fall through into long */
2131 if (isvar (&opP
->disp
))
2132 add_fix ('l', &opP
->disp
, 0, 0);
2134 tmpreg
= 0x39;/* 7.1 mode */
2135 addword (nextword
>> 16);
2139 case SIZE_WORD
: /* Word */
2140 if (isvar (&opP
->disp
))
2141 add_fix ('w', &opP
->disp
, 0, 0);
2143 tmpreg
= 0x38;/* 7.0 mode */
2151 as_bad ("unknown/incorrect operand");
2154 install_gen_operand (s
[1], tmpreg
);
2160 { /* JF: I hate floating point! */
2175 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2176 if (isvar (&opP
->disp
))
2177 add_fix (s
[1], &opP
->disp
, 0, 0);
2180 case 'b': /* Danger: These do no check for
2181 certain types of overflow.
2183 if (!isbyte (tmpreg
))
2184 opP
->error
= "out of range";
2185 insop (tmpreg
, opcode
);
2186 if (isvar (&opP
->disp
))
2187 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2188 (opcode
->m_codenum
) * 2 + 1;
2191 if (!isword (tmpreg
))
2192 opP
->error
= "out of range";
2193 insop (tmpreg
, opcode
);
2194 if (isvar (&opP
->disp
))
2195 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2198 if (!issword (tmpreg
))
2199 opP
->error
= "out of range";
2200 insop (tmpreg
, opcode
);
2201 if (isvar (&opP
->disp
))
2202 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2205 /* Because of the way insop works, we put these two out
2207 insop (tmpreg
, opcode
);
2208 insop (tmpreg
>> 16, opcode
);
2209 if (isvar (&opP
->disp
))
2210 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2216 install_operand (s
[1], tmpreg
);
2227 install_operand (s
[1], opP
->reg
- ADDR
);
2231 tmpreg
= get_num (&opP
->disp
, 80);
2235 /* The pc_fix argument winds up in fx_pcrel_adjust,
2236 which is a char, and may therefore be unsigned. We
2237 want to pass -1, but we pass 64 instead, and convert
2238 back in md_pcrel_from. */
2239 add_fix ('B', &opP
->disp
, 1, 64);
2242 add_fix ('w', &opP
->disp
, 1, 0);
2247 if (cpu_of_arch (current_architecture
) < m68020
)
2248 as_warn ("Can't use long branches on 68000/68010");
2249 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2250 add_fix ('l', &opP
->disp
, 1, 0);
2255 if (subs (&opP
->disp
)) /* We can't relax it */
2259 /* If the displacement needs pic relocation it cannot be
2261 if (opP
->disp
.pic_reloc
!= pic_none
)
2265 /* This could either be a symbol, or an absolute
2266 address. No matter, the frag hacking will finger it
2267 out. Not quite: it can't switch from BRANCH to
2268 BCC68000 for the case where opnd is absolute (it
2269 needs to use the 68000 hack since no conditional abs
2271 if (((cpu_of_arch (current_architecture
) < m68020
)
2272 || (0 == adds (&opP
->disp
)))
2273 && (the_ins
.opcode
[0] >= 0x6200)
2274 && (the_ins
.opcode
[0] <= 0x6f00))
2275 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2276 TAB (BCC68000
, SZ_UNDEF
));
2278 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2279 TAB (ABRANCH
, SZ_UNDEF
));
2282 if (isvar (&opP
->disp
))
2285 /* check for DBcc instruction */
2286 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2288 /* size varies if patch */
2289 /* needed for long form */
2290 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2291 TAB (DBCC
, SZ_UNDEF
));
2295 add_fix ('w', &opP
->disp
, 1, 0);
2299 case 'C': /* Fixed size LONG coproc branches */
2300 add_fix ('l', &opP
->disp
, 1, 0);
2304 case 'c': /* Var size Coprocesssor branches */
2305 if (subs (&opP
->disp
))
2307 add_fix ('l', &opP
->disp
, 1, 0);
2308 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2310 else if (adds (&opP
->disp
))
2311 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2312 TAB (FBRANCH
, SZ_UNDEF
));
2315 /* add_frag((symbolS *) 0, offs(&opP->disp),
2316 TAB(FBRANCH,SHORT)); */
2317 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2318 add_fix ('l', &opP
->disp
, 1, 0);
2328 case 'C': /* Ignore it */
2331 case 'd': /* JF this is a kludge */
2332 install_operand ('s', opP
->reg
- ADDR
);
2333 tmpreg
= get_num (&opP
->disp
, 80);
2334 if (!issword (tmpreg
))
2336 as_warn ("Expression out of range, using 0");
2343 install_operand (s
[1], opP
->reg
- DATA
);
2347 install_operand (s
[1], opP
->reg
- FP0
);
2351 tmpreg
= opP
->reg
- COP0
;
2352 install_operand (s
[1], tmpreg
);
2355 case 'J': /* JF foo */
2428 install_operand (s
[1], tmpreg
);
2432 tmpreg
= get_num (&opP
->disp
, 55);
2433 install_operand (s
[1], tmpreg
& 0x7f);
2440 if (tmpreg
& 0x7FF0000)
2441 as_bad ("Floating point register in register list");
2442 insop (reverse_16_bits (tmpreg
), opcode
);
2446 if (tmpreg
& 0x700FFFF)
2447 as_bad ("Wrong register in floating-point reglist");
2448 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2456 if (tmpreg
& 0x7FF0000)
2457 as_bad ("Floating point register in register list");
2458 insop (tmpreg
, opcode
);
2460 else if (s
[1] == '8')
2462 if (tmpreg
& 0x0FFFFFF)
2463 as_bad ("incorrect register in reglist");
2464 install_operand (s
[1], tmpreg
>> 24);
2468 if (tmpreg
& 0x700FFFF)
2469 as_bad ("wrong register in floating-point reglist");
2471 install_operand (s
[1], tmpreg
>> 16);
2476 install_operand (s
[1], get_num (&opP
->disp
, 60));
2480 tmpreg
= ((opP
->mode
== DREG
)
2481 ? 0x20 + opP
->reg
- DATA
2482 : (get_num (&opP
->disp
, 40) & 0x1F));
2483 install_operand (s
[1], tmpreg
);
2487 tmpreg
= get_num (&opP
->disp
, 10);
2490 install_operand (s
[1], tmpreg
);
2494 /* This depends on the fact that ADDR registers are eight
2495 more than their corresponding DATA regs, so the result
2496 will have the ADDR_REG bit set */
2497 install_operand (s
[1], opP
->reg
- DATA
);
2501 if (opP
->mode
== AINDR
)
2502 install_operand (s
[1], opP
->reg
- DATA
);
2504 install_operand (s
[1], opP
->index
.reg
- DATA
);
2508 if (opP
->reg
== FPI
)
2510 else if (opP
->reg
== FPS
)
2512 else if (opP
->reg
== FPC
)
2516 install_operand (s
[1], tmpreg
);
2519 case 'S': /* Ignore it */
2523 install_operand (s
[1], get_num (&opP
->disp
, 30));
2526 case 'U': /* Ignore it */
2545 as_fatal ("failed sanity check");
2546 } /* switch on cache token */
2547 install_operand (s
[1], tmpreg
);
2550 /* JF: These are out of order, I fear. */
2563 install_operand (s
[1], tmpreg
);
2589 install_operand (s
[1], tmpreg
);
2593 if (opP
->reg
== VAL
)
2612 install_operand (s
[1], tmpreg
);
2626 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2637 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2643 install_operand (s
[1], tmpreg
);
2646 know (opP
->reg
== PSR
);
2649 know (opP
->reg
== PCSR
);
2664 install_operand (s
[1], tmpreg
);
2667 tmpreg
= get_num (&opP
->disp
, 20);
2668 install_operand (s
[1], tmpreg
);
2670 case '_': /* used only for move16 absolute 32-bit address */
2671 tmpreg
= get_num (&opP
->disp
, 80);
2672 addword (tmpreg
>> 16);
2673 addword (tmpreg
& 0xFFFF);
2680 /* By the time whe get here (FINALLY) the_ins contains the complete
2681 instruction, ready to be emitted. . . */
2685 reverse_16_bits (in
)
2691 static int mask
[16] =
2693 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2694 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2696 for (n
= 0; n
< 16; n
++)
2699 out
|= mask
[15 - n
];
2702 } /* reverse_16_bits() */
2711 static int mask
[8] =
2713 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2716 for (n
= 0; n
< 8; n
++)
2722 } /* reverse_8_bits() */
2724 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2725 (that value is chosen in the frag_var call in md_assemble). TYPE
2726 is the subtype of the frag to be generated; its primary type is
2727 rs_machine_dependent.
2729 The TYPE parameter is also used by md_convert_frag_1 and
2730 md_estimate_size_before_relax. The appropriate type of fixup will
2731 be emitted by md_convert_frag_1.
2733 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2735 install_operand (mode
, val
)
2742 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2745 the_ins
.opcode
[0] |= val
<< 9;
2748 the_ins
.opcode
[1] |= val
<< 12;
2751 the_ins
.opcode
[1] |= val
<< 6;
2754 the_ins
.opcode
[1] |= val
;
2757 the_ins
.opcode
[2] |= val
<< 12;
2760 the_ins
.opcode
[2] |= val
<< 6;
2763 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2764 three words long! */
2766 the_ins
.opcode
[2] |= val
;
2769 the_ins
.opcode
[1] |= val
<< 7;
2772 the_ins
.opcode
[1] |= val
<< 10;
2776 the_ins
.opcode
[1] |= val
<< 5;
2781 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2784 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2787 the_ins
.opcode
[0] |= val
= 0xff;
2790 the_ins
.opcode
[0] |= val
<< 9;
2793 the_ins
.opcode
[1] |= val
;
2796 the_ins
.opcode
[1] |= val
;
2797 the_ins
.numo
++; /* What a hack */
2800 the_ins
.opcode
[1] |= val
<< 4;
2808 the_ins
.opcode
[0] |= (val
<< 6);
2811 the_ins
.opcode
[1] = (val
>> 16);
2812 the_ins
.opcode
[2] = val
& 0xffff;
2816 as_fatal ("failed sanity check.");
2818 } /* install_operand() */
2821 install_gen_operand (mode
, val
)
2828 the_ins
.opcode
[0] |= val
;
2831 /* This is a kludge!!! */
2832 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2841 the_ins
.opcode
[0] |= val
;
2843 /* more stuff goes here */
2845 as_fatal ("failed sanity check.");
2847 } /* install_gen_operand() */
2850 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2851 * then deal with the bitfield hack.
2855 crack_operand (str
, opP
)
2857 register struct m68k_op
*opP
;
2859 register int parens
;
2861 register char *beg_str
;
2869 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
2875 else if (*str
== ')')
2879 opP
->error
= "Extra )";
2885 if (flag_mri
&& *str
== '\'')
2886 inquote
= ! inquote
;
2888 if (!*str
&& parens
)
2890 opP
->error
= "Missing )";
2895 if (m68k_ip_op (beg_str
, opP
) != 0)
2902 c
= *++str
; /* JF bitfield hack */
2907 as_bad ("Missing operand");
2912 /* This is the guts of the machine-dependent assembler. STR points to a
2913 machine dependent instruction. This function is supposed to emit
2914 the frags/bytes it assembles to.
2918 insert_reg (regname
, regnum
)
2925 #ifdef REGISTER_PREFIX
2926 if (!flag_reg_prefix_optional
)
2928 buf
[0] = REGISTER_PREFIX
;
2929 strcpy (buf
+ 1, regname
);
2934 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
2935 &zero_address_frag
));
2937 for (i
= 0; regname
[i
]; i
++)
2938 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2941 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
2942 &zero_address_frag
));
2951 static const struct init_entry init_table
[] =
3006 /* control registers */
3007 { "sfc", SFC
}, /* Source Function Code */
3009 { "dfc", DFC
}, /* Destination Function Code */
3011 { "cacr", CACR
}, /* Cache Control Register */
3012 { "caar", CAAR
}, /* Cache Address Register */
3014 { "usp", USP
}, /* User Stack Pointer */
3015 { "vbr", VBR
}, /* Vector Base Register */
3016 { "msp", MSP
}, /* Master Stack Pointer */
3017 { "isp", ISP
}, /* Interrupt Stack Pointer */
3019 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0 */
3020 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1 */
3021 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0 */
3022 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1 */
3024 /* 68ec040 versions of same */
3025 { "iacr0", ITT0
}, /* Instruction Access Control Register 0 */
3026 { "iacr1", ITT1
}, /* Instruction Access Control Register 0 */
3027 { "dacr0", DTT0
}, /* Data Access Control Register 0 */
3028 { "dacr1", DTT1
}, /* Data Access Control Register 0 */
3030 /* mcf5200 versions of same */
3031 { "acr2", ITT0
}, /* Access Control Unit 2 */
3032 { "acr3", ITT1
}, /* Access Control Unit 3 */
3033 { "acr0", DTT0
}, /* Access Control Unit 0 */
3034 { "acr1", DTT1
}, /* Access Control Unit 1 */
3036 { "tc", TC
}, /* MMU Translation Control Register */
3039 { "mmusr", MMUSR
}, /* MMU Status Register */
3040 { "srp", SRP
}, /* User Root Pointer */
3041 { "urp", URP
}, /* Supervisor Root Pointer */
3046 { "rombar", ROMBAR
}, /* ROM Base Address Register */
3047 { "rambar0", RAMBAR0
}, /* ROM Base Address Register */
3048 { "rambar1", RAMBAR1
}, /* ROM Base Address Register */
3049 { "mbar", MBAR
}, /* Module Base Address Register */
3050 /* end of control registers */
3084 /* 68ec030 versions of same */
3087 /* 68ec030 access control unit, identical to 030 MMU status reg */
3090 /* Suppressed data and address registers. */
3115 for (i
= 0; init_table
[i
].name
; i
++)
3116 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3119 static int no_68851
, no_68881
;
3122 /* a.out machine type. Default to 68020. */
3123 int m68k_aout_machtype
= 2;
3135 int shorts_this_frag
;
3138 /* In MRI mode, the instruction and operands are separated by a
3139 space. Anything following the operands is a comment. The label
3140 has already been removed. */
3148 for (s
= str
; *s
!= '\0'; s
++)
3150 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3168 inquote
= ! inquote
;
3173 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3178 for (n
= 0; n
< the_ins
.numargs
; n
++)
3179 if (the_ins
.operands
[n
].error
)
3181 er
= the_ins
.operands
[n
].error
;
3187 as_bad ("%s -- statement `%s' ignored", er
, str
);
3191 if (the_ins
.nfrag
== 0)
3193 /* No frag hacking involved; just put it out */
3194 toP
= frag_more (2 * the_ins
.numo
);
3195 fromP
= &the_ins
.opcode
[0];
3196 for (m
= the_ins
.numo
; m
; --m
)
3198 md_number_to_chars (toP
, (long) (*fromP
), 2);
3202 /* put out symbol-dependent info */
3203 for (m
= 0; m
< the_ins
.nrel
; m
++)
3205 switch (the_ins
.reloc
[m
].wid
)
3223 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3224 the_ins
.reloc
[m
].wid
);
3227 fixP
= fix_new_exp (frag_now
,
3228 ((toP
- frag_now
->fr_literal
)
3229 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3231 &the_ins
.reloc
[m
].exp
,
3232 the_ins
.reloc
[m
].pcrel
,
3233 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3234 the_ins
.reloc
[m
].pic_reloc
));
3235 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3240 /* There's some frag hacking */
3241 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3246 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3248 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3249 toP
= frag_more (wid
);
3251 shorts_this_frag
= 0;
3252 for (m
= wid
/ 2; m
; --m
)
3254 md_number_to_chars (toP
, (long) (*fromP
), 2);
3259 for (m
= 0; m
< the_ins
.nrel
; m
++)
3261 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3263 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3266 wid
= the_ins
.reloc
[m
].wid
;
3269 the_ins
.reloc
[m
].wid
= 0;
3270 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3272 fixP
= fix_new_exp (frag_now
,
3273 ((toP
- frag_now
->fr_literal
)
3274 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3276 &the_ins
.reloc
[m
].exp
,
3277 the_ins
.reloc
[m
].pcrel
,
3278 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3279 the_ins
.reloc
[m
].pic_reloc
));
3280 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3282 (void) frag_var (rs_machine_dependent
, 10, 0,
3283 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3284 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3286 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3287 shorts_this_frag
= 0;
3290 toP
= frag_more (n
* sizeof (short));
3293 md_number_to_chars (toP
, (long) (*fromP
), 2);
3299 for (m
= 0; m
< the_ins
.nrel
; m
++)
3303 wid
= the_ins
.reloc
[m
].wid
;
3306 the_ins
.reloc
[m
].wid
= 0;
3307 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3309 fixP
= fix_new_exp (frag_now
,
3310 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3311 - shorts_this_frag
* 2),
3313 &the_ins
.reloc
[m
].exp
,
3314 the_ins
.reloc
[m
].pcrel
,
3315 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3316 the_ins
.reloc
[m
].pic_reloc
));
3317 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3325 * md_begin -- set up hash tables with 68000 instructions.
3326 * similar to what the vax assembler does. ---phr
3328 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3329 a copy of it at runtime, adding in the information we want but isn't
3330 there. I think it'd be better to have an awk script hack the table
3331 at compile time. Or even just xstr the table and use it as-is. But
3332 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3335 register const struct m68k_opcode
*ins
;
3336 register struct m68k_incant
*hack
, *slak
;
3337 register const char *retval
= 0; /* empty string, or error msg text */
3338 register unsigned int i
;
3343 flag_reg_prefix_optional
= 1;
3348 op_hash
= hash_new ();
3350 obstack_begin (&robyn
, 4000);
3351 for (i
= 0; i
< m68k_numopcodes
; i
++)
3353 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3356 ins
= &m68k_opcodes
[i
];
3357 /* We *could* ignore insns that don't match our arch here
3358 but just leaving them out of the hash. */
3359 slak
->m_operands
= ins
->args
;
3360 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3361 slak
->m_arch
= ins
->arch
;
3362 slak
->m_opcode
= ins
->opcode
;
3363 /* This is kludgey */
3364 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3365 if (i
+ 1 != m68k_numopcodes
3366 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3368 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3373 slak
= slak
->m_next
;
3377 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3379 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3382 for (i
= 0; i
< m68k_numaliases
; i
++)
3384 const char *name
= m68k_opcode_aliases
[i
].primary
;
3385 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3386 PTR val
= hash_find (op_hash
, name
);
3388 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3389 retval
= hash_insert (op_hash
, alias
, val
);
3391 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3394 /* In MRI mode, all unsized branches are variable sized. Normally,
3395 they are word sized. */
3398 static struct m68k_opcode_alias mri_aliases
[] =
3418 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3420 const char *name
= mri_aliases
[i
].primary
;
3421 const char *alias
= mri_aliases
[i
].alias
;
3422 PTR val
= hash_find (op_hash
, name
);
3424 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3425 retval
= hash_jam (op_hash
, alias
, val
);
3427 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3431 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3432 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3434 for (i
= 0; i
< sizeof (notend_table
); i
++)
3436 notend_table
[i
] = 0;
3437 alt_notend_table
[i
] = 0;
3439 notend_table
[','] = 1;
3440 notend_table
['{'] = 1;
3441 notend_table
['}'] = 1;
3442 alt_notend_table
['a'] = 1;
3443 alt_notend_table
['A'] = 1;
3444 alt_notend_table
['d'] = 1;
3445 alt_notend_table
['D'] = 1;
3446 alt_notend_table
['#'] = 1;
3447 alt_notend_table
['&'] = 1;
3448 alt_notend_table
['f'] = 1;
3449 alt_notend_table
['F'] = 1;
3450 #ifdef REGISTER_PREFIX
3451 alt_notend_table
[REGISTER_PREFIX
] = 1;
3454 /* We need to put '(' in alt_notend_table to handle
3455 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3457 alt_notend_table
['('] = 1;
3459 /* We need to put '@' in alt_notend_table to handle
3460 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3462 alt_notend_table
['@'] = 1;
3464 /* We need to put digits in alt_notend_table to handle
3465 bfextu %d0{24:1},%d0
3467 alt_notend_table
['0'] = 1;
3468 alt_notend_table
['1'] = 1;
3469 alt_notend_table
['2'] = 1;
3470 alt_notend_table
['3'] = 1;
3471 alt_notend_table
['4'] = 1;
3472 alt_notend_table
['5'] = 1;
3473 alt_notend_table
['6'] = 1;
3474 alt_notend_table
['7'] = 1;
3475 alt_notend_table
['8'] = 1;
3476 alt_notend_table
['9'] = 1;
3478 #ifndef MIT_SYNTAX_ONLY
3479 /* Insert pseudo ops, these have to go into the opcode table since
3480 gas expects pseudo ops to start with a dot */
3483 while (mote_pseudo_table
[n
].poc_name
)
3485 hack
= (struct m68k_incant
*)
3486 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3487 hash_insert (op_hash
,
3488 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3489 hack
->m_operands
= 0;
3499 record_alignment (text_section
, 2);
3500 record_alignment (data_section
, 2);
3501 record_alignment (bss_section
, 2);
3506 m68k_init_after_args ()
3508 if (cpu_of_arch (current_architecture
) == 0)
3511 const char *default_cpu
= TARGET_CPU
;
3513 if (*default_cpu
== 'm')
3515 for (i
= 0; i
< n_archs
; i
++)
3516 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3520 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3521 current_architecture
|= m68020
;
3524 current_architecture
|= archs
[i
].arch
;
3526 /* Permit m68881 specification with all cpus; those that can't work
3527 with a coprocessor could be doing emulation. */
3528 if (current_architecture
& m68851
)
3530 if (current_architecture
& m68040
)
3532 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3535 /* What other incompatibilities could we check for? */
3537 /* Toss in some default assumptions about coprocessors. */
3539 && (cpu_of_arch (current_architecture
)
3540 /* Can CPU32 have a 68881 coprocessor?? */
3541 & (m68020
| m68030
| cpu32
)))
3543 current_architecture
|= m68881
;
3546 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3547 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3549 current_architecture
|= m68851
;
3551 if (no_68881
&& (current_architecture
& m68881
))
3552 as_bad ("options for 68881 and no-68881 both given");
3553 if (no_68851
&& (current_architecture
& m68851
))
3554 as_bad ("options for 68851 and no-68851 both given");
3557 /* Work out the magic number. This isn't very general. */
3558 if (current_architecture
& m68000
)
3559 m68k_aout_machtype
= 0;
3560 else if (current_architecture
& m68010
)
3561 m68k_aout_machtype
= 1;
3562 else if (current_architecture
& m68020
)
3563 m68k_aout_machtype
= 2;
3565 m68k_aout_machtype
= 2;
3568 /* Note which set of "movec" control registers is available. */
3569 switch (cpu_of_arch (current_architecture
))
3572 control_regs
= m68000_control_regs
;
3575 control_regs
= m68010_control_regs
;
3579 control_regs
= m68020_control_regs
;
3582 control_regs
= m68040_control_regs
;
3585 control_regs
= m68060_control_regs
;
3588 control_regs
= cpu32_control_regs
;
3591 control_regs
= mcf5200_control_regs
;
3597 if (cpu_of_arch (current_architecture
) < m68020
)
3598 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3601 /* This is called if we go in or out of MRI mode because of the .mri
3605 m68k_mri_mode_change (on
)
3610 if (! flag_reg_prefix_optional
)
3612 flag_reg_prefix_optional
= 1;
3613 #ifdef REGISTER_PREFIX
3622 if (! reg_prefix_optional_seen
)
3624 #ifdef REGISTER_PREFIX_OPTIONAL
3625 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
3627 flag_reg_prefix_optional
= 0;
3629 #ifdef REGISTER_PREFIX
3638 /* Equal to MAX_PRECISION in atof-ieee.c */
3639 #define MAX_LITTLENUMS 6
3641 /* Turn a string in input_line_pointer into a floating point constant
3642 of type type, and store the appropriate bytes in *litP. The number
3643 of LITTLENUMS emitted is stored in *sizeP . An error message is
3644 returned, or NULL on OK. */
3647 md_atof (type
, litP
, sizeP
)
3653 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3654 LITTLENUM_TYPE
*wordP
;
3686 return "Bad call to MD_ATOF()";
3688 t
= atof_ieee (input_line_pointer
, type
, words
);
3690 input_line_pointer
= t
;
3692 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3693 for (wordP
= words
; prec
--;)
3695 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3696 litP
+= sizeof (LITTLENUM_TYPE
);
3702 md_number_to_chars (buf
, val
, n
)
3707 number_to_chars_bigendian (buf
, val
, n
);
3711 md_apply_fix_2 (fixP
, val
)
3715 addressT upper_limit
;
3716 offsetT lower_limit
;
3718 /* This is unnecessary but it convinces the native rs6000 compiler
3719 to generate the code we want. */
3720 char *buf
= fixP
->fx_frag
->fr_literal
;
3721 buf
+= fixP
->fx_where
;
3722 /* end ibm compiler workaround */
3724 if (val
& 0x80000000)
3725 val
|= ~(addressT
)0x7fffffff;
3732 memset (buf
, 0, fixP
->fx_size
);
3733 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
3738 switch (fixP
->fx_size
)
3740 /* The cast to offsetT below are necessary to make code correct for
3741 machines where ints are smaller than offsetT */
3745 lower_limit
= - (offsetT
) 0x80;
3748 *buf
++ = (val
>> 8);
3750 upper_limit
= 0x7fff;
3751 lower_limit
= - (offsetT
) 0x8000;
3754 *buf
++ = (val
>> 24);
3755 *buf
++ = (val
>> 16);
3756 *buf
++ = (val
>> 8);
3758 upper_limit
= 0x7fffffff;
3759 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3762 BAD_CASE (fixP
->fx_size
);
3765 /* Fix up a negative reloc. */
3766 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
3768 fixP
->fx_addsy
= fixP
->fx_subsy
;
3769 fixP
->fx_subsy
= NULL
;
3773 /* For non-pc-relative values, it's conceivable we might get something
3774 like "0xff" for a byte field. So extend the upper part of the range
3775 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3776 so that we can do any range checking at all. */
3777 if (!fixP
->fx_pcrel
)
3778 upper_limit
= upper_limit
* 2 + 1;
3780 if ((addressT
) val
> upper_limit
3781 && (val
> 0 || val
< lower_limit
))
3782 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
3784 /* A one byte PC-relative reloc means a short branch. We can't use
3785 a short branch with a value of 0 or -1, because those indicate
3786 different opcodes (branches with longer offsets). */
3788 && fixP
->fx_size
== 1
3789 && (fixP
->fx_addsy
== NULL
3790 || S_IS_DEFINED (fixP
->fx_addsy
))
3791 && (val
== 0 || val
== -1))
3792 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
3795 #ifdef BFD_ASSEMBLER
3797 md_apply_fix (fixP
, valp
)
3801 md_apply_fix_2 (fixP
, (addressT
) *valp
);
3805 void md_apply_fix (fixP
, val
)
3809 md_apply_fix_2 (fixP
, (addressT
) val
);
3813 /* *fragP has been relaxed to its final size, and now needs to have
3814 the bytes inside it modified to conform to the new size There is UGLY
3818 md_convert_frag_1 (fragP
)
3819 register fragS
*fragP
;
3825 /* Address in object code of the displacement. */
3826 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3828 /* Address in gas core of the place to store the displacement. */
3829 /* This convinces the native rs6000 compiler to generate the code we
3831 register char *buffer_address
= fragP
->fr_literal
;
3832 buffer_address
+= fragP
->fr_fix
;
3833 /* end ibm compiler workaround */
3835 /* The displacement of the address, from current location. */
3836 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3837 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3839 #ifdef BFD_ASSEMBLER
3840 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
3843 switch (fragP
->fr_subtype
)
3845 case TAB (BCC68000
, BYTE
):
3846 case TAB (ABRANCH
, BYTE
):
3847 know (issbyte (disp
));
3849 as_bad ("short branch with zero offset: use :w");
3850 fragP
->fr_opcode
[1] = disp
;
3853 case TAB (DBCC
, SHORT
):
3854 know (issword (disp
));
3857 case TAB (BCC68000
, SHORT
):
3858 case TAB (ABRANCH
, SHORT
):
3859 know (issword (disp
));
3860 fragP
->fr_opcode
[1] = 0x00;
3863 case TAB (ABRANCH
, LONG
):
3864 if (cpu_of_arch (current_architecture
) < m68020
)
3866 if (fragP
->fr_opcode
[0] == 0x61)
3869 fragP
->fr_opcode
[0] = 0x4E;
3870 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3884 else if (fragP
->fr_opcode
[0] == 0x60)
3886 fragP
->fr_opcode
[0] = 0x4E;
3887 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3888 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3889 fragP
->fr_offset
, 0, NO_RELOC
);
3895 as_bad ("Long branch offset not supported.");
3900 fragP
->fr_opcode
[1] = (char) 0xff;
3904 case TAB (BCC68000
, LONG
):
3905 /* only Bcc 68000 instructions can come here */
3906 /* change bcc into b!cc/jmp absl long */
3907 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3908 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
3910 /* JF: these used to be fr_opcode[2,3], but they may be in a
3911 different frag, in which case refering to them is a no-no.
3912 Only fr_opcode[0,1] are guaranteed to work. */
3913 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3914 *buffer_address
++ = (char) 0xf9;
3915 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3916 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3917 fragP
->fr_offset
, 0, NO_RELOC
);
3921 case TAB (DBCC
, LONG
):
3922 /* only DBcc 68000 instructions can come here */
3923 /* change dbcc into dbcc/jmp absl long */
3924 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3925 *buffer_address
++ = 0x00; /* branch offset = 4 */
3926 *buffer_address
++ = 0x04;
3927 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3928 *buffer_address
++ = 0x06;
3929 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3930 *buffer_address
++ = (char) 0xf9;
3932 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3933 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3934 fragP
->fr_offset
, 0, NO_RELOC
);
3938 case TAB (FBRANCH
, SHORT
):
3939 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
3942 case TAB (FBRANCH
, LONG
):
3943 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3946 case TAB (PCREL
, SHORT
):
3949 case TAB (PCREL
, LONG
):
3950 /* The thing to do here is force it to ABSOLUTE LONG, since
3951 PCREL is really trying to shorten an ABSOLUTE address anyway */
3952 /* JF FOO This code has not been tested */
3953 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
3955 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3956 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
3957 (unsigned) fragP
->fr_opcode
[0],
3958 (unsigned long) fragP
->fr_address
);
3959 fragP
->fr_opcode
[1] &= ~0x3F;
3960 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
3964 case TAB (PCLEA
, SHORT
):
3965 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3966 fragP
->fr_offset
, 1, NO_RELOC
);
3967 fragP
->fr_opcode
[1] &= ~0x3F;
3968 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
3971 case TAB (PCLEA
, LONG
):
3972 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
3973 fragP
->fr_offset
, 1, NO_RELOC
);
3974 fixP
->fx_pcrel_adjust
= 2;
3975 /* Already set to mode 7.3; this indicates: PC indirect with
3976 suppressed index, 32-bit displacement. */
3977 *buffer_address
++ = 0x01;
3978 *buffer_address
++ = 0x70;
3983 case TAB (PCINDEX
, BYTE
):
3985 if (!issbyte (disp
))
3987 as_bad ("displacement doesn't fit in one byte");
3990 assert (fragP
->fr_fix
>= 2);
3991 buffer_address
[-2] &= ~1;
3992 buffer_address
[-1] = disp
;
3995 case TAB (PCINDEX
, SHORT
):
3997 assert (issword (disp
));
3998 assert (fragP
->fr_fix
>= 2);
3999 buffer_address
[-2] |= 0x1;
4000 buffer_address
[-1] = 0x20;
4001 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4002 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4004 fixP
->fx_pcrel_adjust
= 2;
4007 case TAB (PCINDEX
, LONG
):
4009 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4010 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4012 fixP
->fx_pcrel_adjust
= 2;
4013 assert (fragP
->fr_fix
>= 2);
4014 buffer_address
[-2] |= 0x1;
4015 buffer_address
[-1] = 0x30;
4022 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4023 fragP
->fr_fix
+= ext
;
4027 #ifndef BFD_ASSEMBLER
4030 md_convert_frag (headers
, sec
, fragP
)
4031 object_headers
*headers
;
4035 md_convert_frag_1 (fragP
);
4041 md_convert_frag (abfd
, sec
, fragP
)
4046 md_convert_frag_1 (fragP
);
4050 /* Force truly undefined symbols to their maximum size, and generally set up
4051 the frag list to be relaxed
4054 md_estimate_size_before_relax (fragP
, segment
)
4055 register fragS
*fragP
;
4059 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4061 old_fix
= fragP
->fr_fix
;
4063 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4064 switch (fragP
->fr_subtype
)
4067 case TAB (ABRANCH
, SZ_UNDEF
):
4069 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4070 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4072 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4075 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
4077 /* On 68000, or for absolute value, switch to abs long */
4078 /* FIXME, we should check abs val, pick short or long */
4079 if (fragP
->fr_opcode
[0] == 0x61)
4081 fragP
->fr_opcode
[0] = 0x4E;
4082 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4083 fix_new (fragP
, fragP
->fr_fix
, 4,
4084 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4088 else if (fragP
->fr_opcode
[0] == 0x60)
4090 fragP
->fr_opcode
[0] = 0x4E;
4091 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4092 fix_new (fragP
, fragP
->fr_fix
, 4,
4093 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4099 as_warn ("Long branch offset to extern symbol not supported.");
4103 { /* Symbol is still undefined. Make it simple */
4104 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4105 fragP
->fr_offset
, 1, NO_RELOC
);
4107 fragP
->fr_opcode
[1] = (char) 0xff;
4113 } /* case TAB(ABRANCH,SZ_UNDEF) */
4115 case TAB (FBRANCH
, SZ_UNDEF
):
4117 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
4119 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4124 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4125 fragP
->fr_offset
, 1, NO_RELOC
);
4127 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4131 } /* TAB(FBRANCH,SZ_UNDEF) */
4133 case TAB (PCREL
, SZ_UNDEF
):
4135 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4137 || cpu_of_arch (current_architecture
) < m68020
)
4139 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4144 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4148 } /* TAB(PCREL,SZ_UNDEF) */
4150 case TAB (BCC68000
, SZ_UNDEF
):
4152 if ((fragP
->fr_symbol
!= NULL
)
4153 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4155 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4158 /* only Bcc 68000 instructions can come here */
4159 /* change bcc into b!cc/jmp absl long */
4160 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4161 if (flag_short_refs
)
4163 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4164 /* JF: these were fr_opcode[2,3] */
4165 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4166 buffer_address
[1] = (char) 0xf8;
4167 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4168 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4169 fragP
->fr_offset
, 0, NO_RELOC
);
4174 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4175 /* JF: these were fr_opcode[2,3] */
4176 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4177 buffer_address
[1] = (char) 0xf9;
4178 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4179 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4180 fragP
->fr_offset
, 0, NO_RELOC
);
4185 } /* case TAB(BCC68000,SZ_UNDEF) */
4187 case TAB (DBCC
, SZ_UNDEF
):
4189 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4191 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4195 /* only DBcc 68000 instructions can come here */
4196 /* change dbcc into dbcc/jmp absl long */
4197 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4198 buffer_address
[0] = 0x00; /* branch offset = 4 */
4199 buffer_address
[1] = 0x04;
4200 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4202 if (flag_short_refs
)
4204 /* JF: these were fr_opcode[5-7] */
4205 buffer_address
[3] = 0x04; /* plus 4 */
4206 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4207 buffer_address
[5] = (char) 0xf8;
4208 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4209 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4210 fragP
->fr_offset
, 0, NO_RELOC
);
4215 /* JF: these were fr_opcode[5-7] */
4216 buffer_address
[3] = 0x06; /* Plus 6 */
4217 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4218 buffer_address
[5] = (char) 0xf9;
4219 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4220 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4221 fragP
->fr_offset
, 0, NO_RELOC
);
4227 } /* case TAB(DBCC,SZ_UNDEF) */
4229 case TAB (PCLEA
, SZ_UNDEF
):
4231 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4233 || cpu_of_arch (current_architecture
) < m68020
)
4235 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4240 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4244 } /* TAB(PCLEA,SZ_UNDEF) */
4246 case TAB (PCINDEX
, SZ_UNDEF
):
4247 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4248 || cpu_of_arch (current_architecture
) < m68020
)
4250 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4254 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4263 /* now that SZ_UNDEF are taken care of, check others */
4264 switch (fragP
->fr_subtype
)
4266 case TAB (BCC68000
, BYTE
):
4267 case TAB (ABRANCH
, BYTE
):
4268 /* We can't do a short jump to the next instruction, so in that
4269 case we force word mode. At this point S_GET_VALUE should
4270 return the offset of the symbol within its frag. If the
4271 symbol is at the start of a frag, and it is the next frag
4272 with any data in it (usually this is just the next frag, but
4273 assembler listings may introduce empty frags), we must use
4275 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0)
4279 for (l
= fragP
->fr_next
;
4280 l
!= fragP
->fr_symbol
->sy_frag
;
4282 if (l
->fr_fix
+ l
->fr_var
!= 0)
4284 if (l
== fragP
->fr_symbol
->sy_frag
)
4286 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4294 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4297 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4298 /* the bit-field entries in the relocation_info struct plays hell
4299 with the byte-order problems of cross-assembly. So as a hack,
4300 I added this mach. dependent ri twiddler. Ugly, but it gets
4302 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4303 are symbolnum, most sig. byte first. Last byte is broken up with
4304 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4305 nibble as nuthin. (on Sun 3 at least) */
4306 /* Translate the internal relocation information into target-specific
4310 md_ri_to_chars (the_bytes
, ri
)
4312 struct reloc_info_generic
*ri
;
4315 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4316 /* now the fun stuff */
4317 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4318 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4319 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4320 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4321 ((ri
->r_extern
<< 4) & 0x10));
4324 #endif /* comment */
4326 #ifndef BFD_ASSEMBLER
4328 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4331 relax_addressT segment_address_in_file
;
4334 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4335 * Out: GNU LD relocation length code: 0, 1, or 2.
4338 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4341 know (fixP
->fx_addsy
!= NULL
);
4343 md_number_to_chars (where
,
4344 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4347 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4348 ? S_GET_TYPE (fixP
->fx_addsy
)
4349 : fixP
->fx_addsy
->sy_number
);
4351 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4352 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4353 where
[6] = r_symbolnum
& 0x0ff;
4354 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4355 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4359 #endif /* OBJ_AOUT or OBJ_BOUT */
4361 #ifndef WORKING_DOT_WORD
4362 CONST
int md_short_jump_size
= 4;
4363 CONST
int md_long_jump_size
= 6;
4366 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4368 addressT from_addr
, to_addr
;
4374 offset
= to_addr
- (from_addr
+ 2);
4376 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4377 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4381 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4383 addressT from_addr
, to_addr
;
4389 if (cpu_of_arch (current_architecture
) < m68020
)
4391 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4392 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4393 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4394 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4399 offset
= to_addr
- (from_addr
+ 2);
4400 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4401 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4407 /* Different values of OK tell what its OK to return. Things that
4408 aren't OK are an error (what a shock, no?)
4411 10: Absolute 1:8 only
4412 20: Absolute 0:7 only
4413 30: absolute 0:15 only
4414 40: Absolute 0:31 only
4415 50: absolute 0:127 only
4416 55: absolute -64:63 only
4417 60: absolute -128:127 only
4418 70: absolute 0:4095 only
4425 struct m68k_exp
*exp
;
4428 if (exp
->exp
.X_op
== O_absent
)
4430 /* Do the same thing the VAX asm does */
4431 op (exp
) = O_constant
;
4437 as_warn ("expression out of range: defaulting to 1");
4441 else if (exp
->exp
.X_op
== O_constant
)
4446 if (offs (exp
) < 1 || offs (exp
) > 8)
4448 as_warn ("expression out of range: defaulting to 1");
4453 if (offs (exp
) < 0 || offs (exp
) > 7)
4457 if (offs (exp
) < 0 || offs (exp
) > 15)
4461 if (offs (exp
) < 0 || offs (exp
) > 32)
4465 if (offs (exp
) < 0 || offs (exp
) > 127)
4469 if (offs (exp
) < -64 || offs (exp
) > 63)
4473 if (offs (exp
) < -128 || offs (exp
) > 127)
4477 if (offs (exp
) < 0 || offs (exp
) > 4095)
4480 as_warn ("expression out of range: defaulting to 0");
4488 else if (exp
->exp
.X_op
== O_big
)
4490 if (offs (exp
) <= 0 /* flonum */
4491 && (ok
== 80 /* no bignums */
4492 || (ok
> 10 /* small-int ranges including 0 ok */
4493 /* If we have a flonum zero, a zero integer should
4494 do as well (e.g., in moveq). */
4495 && generic_floating_point_number
.exponent
== 0
4496 && generic_floating_point_number
.low
[0] == 0)))
4498 /* HACK! Turn it into a long */
4499 LITTLENUM_TYPE words
[6];
4501 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4502 op (exp
) = O_constant
;
4505 offs (exp
) = words
[1] | (words
[0] << 16);
4509 op (exp
) = O_constant
;
4512 offs (exp
) = (ok
== 10) ? 1 : 0;
4513 as_warn ("Can't deal with expression; defaulting to %ld",
4519 if (ok
>= 10 && ok
<= 70)
4521 op (exp
) = O_constant
;
4524 offs (exp
) = (ok
== 10) ? 1 : 0;
4525 as_warn ("Can't deal with expression; defaulting to %ld",
4530 if (exp
->size
!= SIZE_UNSPEC
)
4538 if (!isbyte (offs (exp
)))
4539 as_warn ("expression doesn't fit in BYTE");
4542 if (!isword (offs (exp
)))
4543 as_warn ("expression doesn't fit in WORD");
4551 /* These are the back-ends for the various machine dependent pseudo-ops. */
4552 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4558 subseg_set (data_section
, 1);
4559 demand_empty_rest_of_line ();
4566 subseg_set (data_section
, 2);
4567 demand_empty_rest_of_line ();
4574 /* We don't support putting frags in the BSS segment, we fake it
4575 by marking in_bss, then looking at s_skip for clues. */
4577 subseg_set (bss_section
, 0);
4578 demand_empty_rest_of_line ();
4586 register long temp_fill
;
4588 temp
= 1; /* JF should be 2? */
4589 temp_fill
= get_absolute_expression ();
4590 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4591 frag_align (temp
, (int) temp_fill
);
4592 demand_empty_rest_of_line ();
4599 demand_empty_rest_of_line ();
4602 /* Pseudo-ops handled for MRI compatibility. */
4604 /* Handle an MRI style chip specification. */
4613 s
= input_line_pointer
;
4614 c
= get_symbol_end ();
4615 for (i
= 0; i
< n_archs
; i
++)
4616 if (strcasecmp (s
, archs
[i
].name
) == 0)
4620 as_bad ("%s: unrecognized processor name", s
);
4621 *input_line_pointer
= c
;
4622 ignore_rest_of_line ();
4625 *input_line_pointer
= c
;
4627 if (*input_line_pointer
== '/')
4628 current_architecture
= 0;
4630 current_architecture
&= m68881
| m68851
;
4631 current_architecture
|= archs
[i
].arch
;
4633 while (*input_line_pointer
== '/')
4635 ++input_line_pointer
;
4636 s
= input_line_pointer
;
4637 c
= get_symbol_end ();
4638 if (strcmp (s
, "68881") == 0)
4639 current_architecture
|= m68881
;
4640 else if (strcmp (s
, "68851") == 0)
4641 current_architecture
|= m68851
;
4642 *input_line_pointer
= c
;
4646 /* The MRI CHIP pseudo-op. */
4656 stop
= mri_comment_field (&stopc
);
4659 mri_comment_end (stop
, stopc
);
4660 demand_empty_rest_of_line ();
4663 /* The MRI FOPT pseudo-op. */
4671 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4675 input_line_pointer
+= 3;
4676 temp
= get_absolute_expression ();
4677 if (temp
< 0 || temp
> 7)
4678 as_bad ("bad coprocessor id");
4680 m68k_float_copnum
= COP0
+ temp
;
4684 as_bad ("unrecognized fopt option");
4685 ignore_rest_of_line ();
4689 demand_empty_rest_of_line ();
4692 /* The structure used to handle the MRI OPT pseudo-op. */
4696 /* The name of the option. */
4699 /* If this is not NULL, just call this function. The first argument
4700 is the ARG field of this structure, the second argument is
4701 whether the option was negated. */
4702 void (*pfn
) PARAMS ((int arg
, int on
));
4704 /* If this is not NULL, and the PFN field is NULL, set the variable
4705 this points to. Set it to the ARG field if the option was not
4706 negated, and the NOTARG field otherwise. */
4709 /* The value to pass to PFN or to assign to *PVAR. */
4712 /* The value to assign to *PVAR if the option is negated. If PFN is
4713 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4714 the option may not be negated. */
4718 /* The table used to handle the MRI OPT pseudo-op. */
4720 static void skip_to_comma
PARAMS ((int, int));
4721 static void opt_nest
PARAMS ((int, int));
4722 static void opt_chip
PARAMS ((int, int));
4723 static void opt_list
PARAMS ((int, int));
4724 static void opt_list_symbols
PARAMS ((int, int));
4726 static const struct opt_action opt_table
[] =
4728 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
4730 /* We do relaxing, so there is little use for these options. */
4731 { "b", 0, 0, 0, 0 },
4732 { "brs", 0, 0, 0, 0 },
4733 { "brb", 0, 0, 0, 0 },
4734 { "brl", 0, 0, 0, 0 },
4735 { "brw", 0, 0, 0, 0 },
4737 { "c", 0, 0, 0, 0 },
4738 { "cex", 0, 0, 0, 0 },
4739 { "case", 0, &symbols_case_sensitive
, 1, 0 },
4740 { "cl", 0, 0, 0, 0 },
4741 { "cre", 0, 0, 0, 0 },
4742 { "d", 0, &flag_keep_locals
, 1, 0 },
4743 { "e", 0, 0, 0, 0 },
4744 { "f", 0, &flag_short_refs
, 1, 0 },
4745 { "frs", 0, &flag_short_refs
, 1, 0 },
4746 { "frl", 0, &flag_short_refs
, 0, 1 },
4747 { "g", 0, 0, 0, 0 },
4748 { "i", 0, 0, 0, 0 },
4749 { "m", 0, 0, 0, 0 },
4750 { "mex", 0, 0, 0, 0 },
4751 { "mc", 0, 0, 0, 0 },
4752 { "md", 0, 0, 0, 0 },
4753 { "nest", opt_nest
, 0, 0, 0 },
4754 { "next", skip_to_comma
, 0, 0, 0 },
4755 { "o", 0, 0, 0, 0 },
4756 { "old", 0, 0, 0, 0 },
4757 { "op", skip_to_comma
, 0, 0, 0 },
4758 { "pco", 0, 0, 0, 0 },
4759 { "p", opt_chip
, 0, 0, 0 },
4760 { "pcr", 0, 0, 0, 0 },
4761 { "pcs", 0, 0, 0, 0 },
4762 { "r", 0, 0, 0, 0 },
4763 { "quick", 0, &m68k_quick
, 1, 0 },
4764 { "rel32", 0, &m68k_rel32
, 1, 0 },
4765 { "s", opt_list
, 0, 0, 0 },
4766 { "t", opt_list_symbols
, 0, 0, 0 },
4767 { "w", 0, &flag_no_warnings
, 0, 1 },
4771 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4773 /* The MRI OPT pseudo-op. */
4785 const struct opt_action
*o
;
4790 if (*input_line_pointer
== '-')
4792 ++input_line_pointer
;
4795 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
4797 input_line_pointer
+= 2;
4801 s
= input_line_pointer
;
4802 c
= get_symbol_end ();
4804 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
4806 if (strcasecmp (s
, o
->name
) == 0)
4810 /* Restore input_line_pointer now in case the option
4812 *input_line_pointer
= c
;
4813 (*o
->pfn
) (o
->arg
, t
);
4815 else if (o
->pvar
!= NULL
)
4817 if (! t
&& o
->arg
== o
->notarg
)
4818 as_bad ("option `%s' may not be negated", s
);
4819 *input_line_pointer
= c
;
4820 *o
->pvar
= t
? o
->arg
: o
->notarg
;
4823 *input_line_pointer
= c
;
4829 as_bad ("option `%s' not recognized", s
);
4830 *input_line_pointer
= c
;
4833 while (*input_line_pointer
++ == ',');
4835 /* Move back to terminating character. */
4836 --input_line_pointer
;
4837 demand_empty_rest_of_line ();
4840 /* Skip ahead to a comma. This is used for OPT options which we do
4841 not suppor tand which take arguments. */
4844 skip_to_comma (arg
, on
)
4848 while (*input_line_pointer
!= ','
4849 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4850 ++input_line_pointer
;
4853 /* Handle the OPT NEST=depth option. */
4860 if (*input_line_pointer
!= '=')
4862 as_bad ("bad format of OPT NEST=depth");
4866 ++input_line_pointer
;
4867 max_macro_nest
= get_absolute_expression ();
4870 /* Handle the OPT P=chip option. */
4877 if (*input_line_pointer
!= '=')
4879 /* This is just OPT P, which we do not support. */
4883 ++input_line_pointer
;
4887 /* Handle the OPT S option. */
4897 /* Handle the OPT T option. */
4900 opt_list_symbols (arg
, on
)
4905 listing
|= LISTING_SYMBOLS
;
4907 listing
&=~ LISTING_SYMBOLS
;
4910 /* Handle the MRI REG pseudo-op. */
4923 if (line_label
== NULL
)
4925 as_bad ("missing label");
4926 ignore_rest_of_line ();
4931 stop
= mri_comment_field (&stopc
);
4935 s
= input_line_pointer
;
4936 while (isalnum ((unsigned char) *input_line_pointer
)
4937 #ifdef REGISTER_PREFIX
4938 || *input_line_pointer
== REGISTER_PREFIX
4940 || *input_line_pointer
== '/'
4941 || *input_line_pointer
== '-')
4942 ++input_line_pointer
;
4943 c
= *input_line_pointer
;
4944 *input_line_pointer
= '\0';
4946 if (m68k_ip_op (s
, &rop
) != 0)
4948 if (rop
.error
== NULL
)
4949 as_bad ("bad register list");
4951 as_bad ("bad register list: %s", rop
.error
);
4952 *input_line_pointer
= c
;
4953 ignore_rest_of_line ();
4957 *input_line_pointer
= c
;
4959 if (rop
.mode
== REGLST
)
4961 else if (rop
.mode
== DREG
)
4962 mask
= 1 << (rop
.reg
- DATA0
);
4963 else if (rop
.mode
== AREG
)
4964 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
4965 else if (rop
.mode
== FPREG
)
4966 mask
= 1 << (rop
.reg
- FP0
+ 16);
4967 else if (rop
.mode
== CONTROL
4970 else if (rop
.mode
== CONTROL
4973 else if (rop
.mode
== CONTROL
4978 as_bad ("bad register list");
4979 ignore_rest_of_line ();
4983 S_SET_SEGMENT (line_label
, absolute_section
);
4984 S_SET_VALUE (line_label
, mask
);
4985 line_label
->sy_frag
= &zero_address_frag
;
4988 mri_comment_end (stop
, stopc
);
4990 demand_empty_rest_of_line ();
4993 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
4997 struct save_opts
*next
;
4999 int symbols_case_sensitive
;
5007 /* FIXME: We don't save OPT S. */
5010 /* This variable holds the stack of saved options. */
5012 static struct save_opts
*save_stack
;
5014 /* The MRI SAVE pseudo-op. */
5020 struct save_opts
*s
;
5022 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5023 s
->abspcadd
= m68k_abspcadd
;
5024 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5025 s
->keep_locals
= flag_keep_locals
;
5026 s
->short_refs
= flag_short_refs
;
5027 s
->architecture
= current_architecture
;
5028 s
->quick
= m68k_quick
;
5029 s
->rel32
= m68k_rel32
;
5030 s
->listing
= listing
;
5031 s
->no_warnings
= flag_no_warnings
;
5033 s
->next
= save_stack
;
5036 demand_empty_rest_of_line ();
5039 /* The MRI RESTORE pseudo-op. */
5045 struct save_opts
*s
;
5047 if (save_stack
== NULL
)
5049 as_bad ("restore without save");
5050 ignore_rest_of_line ();
5055 save_stack
= s
->next
;
5057 m68k_abspcadd
= s
->abspcadd
;
5058 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5059 flag_keep_locals
= s
->keep_locals
;
5060 flag_short_refs
= s
->short_refs
;
5061 current_architecture
= s
->architecture
;
5062 m68k_quick
= s
->quick
;
5063 m68k_rel32
= s
->rel32
;
5064 listing
= s
->listing
;
5065 flag_no_warnings
= s
->no_warnings
;
5069 demand_empty_rest_of_line ();
5072 /* Types of MRI structured control directives. */
5074 enum mri_control_type
5082 /* This structure is used to stack the MRI structured control
5085 struct mri_control_info
5087 /* The directive within which this one is enclosed. */
5088 struct mri_control_info
*outer
;
5090 /* The type of directive. */
5091 enum mri_control_type type
;
5093 /* Whether an ELSE has been in an IF. */
5096 /* The add or sub statement at the end of a FOR. */
5099 /* The label of the top of a FOR or REPEAT loop. */
5102 /* The label to jump to for the next iteration, or the else
5103 expression of a conditional. */
5106 /* The label to jump to to break out of the loop, or the label past
5107 the end of a conditional. */
5111 /* The stack of MRI structured control directives. */
5113 static struct mri_control_info
*mri_control_stack
;
5115 /* The current MRI structured control directive index number, used to
5116 generate label names. */
5118 static int mri_control_index
;
5120 /* Some function prototypes. */
5122 static char *mri_control_label
PARAMS ((void));
5123 static struct mri_control_info
*push_mri_control
5124 PARAMS ((enum mri_control_type
));
5125 static void pop_mri_control
PARAMS ((void));
5126 static int parse_mri_condition
PARAMS ((int *));
5127 static int parse_mri_control_operand
5128 PARAMS ((int *, char **, char **, char **, char **));
5129 static int swap_mri_condition
PARAMS ((int));
5130 static int reverse_mri_condition
PARAMS ((int));
5131 static void build_mri_control_operand
5132 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5133 const char *, int));
5134 static void parse_mri_control_expression
5135 PARAMS ((char *, int, const char *, const char *, int));
5137 /* Generate a new MRI label structured control directive label name. */
5140 mri_control_label ()
5144 n
= (char *) xmalloc (20);
5145 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5146 ++mri_control_index
;
5150 /* Create a new MRI structured control directive. */
5152 static struct mri_control_info
*
5153 push_mri_control (type
)
5154 enum mri_control_type type
;
5156 struct mri_control_info
*n
;
5158 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5162 if (type
== mri_if
|| type
== mri_while
)
5165 n
->top
= mri_control_label ();
5166 n
->next
= mri_control_label ();
5167 n
->bottom
= mri_control_label ();
5169 n
->outer
= mri_control_stack
;
5170 mri_control_stack
= n
;
5175 /* Pop off the stack of MRI structured control directives. */
5180 struct mri_control_info
*n
;
5182 n
= mri_control_stack
;
5183 mri_control_stack
= n
->outer
;
5191 /* Recognize a condition code in an MRI structured control expression. */
5194 parse_mri_condition (pcc
)
5199 know (*input_line_pointer
== '<');
5201 ++input_line_pointer
;
5202 c1
= *input_line_pointer
++;
5203 c2
= *input_line_pointer
++;
5205 if (*input_line_pointer
!= '>')
5207 as_bad ("syntax error in structured control directive");
5211 ++input_line_pointer
;
5219 *pcc
= (c1
<< 8) | c2
;
5224 /* Parse a single operand in an MRI structured control expression. */
5227 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5244 if (*input_line_pointer
== '<')
5246 /* It's just a condition code. */
5247 return parse_mri_condition (pcc
);
5250 /* Look ahead for the condition code. */
5251 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5253 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5258 as_bad ("missing condition code in structured control directive");
5262 *leftstart
= input_line_pointer
;
5264 if (*leftstop
> *leftstart
5265 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5268 input_line_pointer
= s
;
5269 if (! parse_mri_condition (pcc
))
5272 /* Look ahead for AND or OR or end of line. */
5273 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5275 if ((strncasecmp (s
, "AND", 3) == 0
5276 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5277 || (strncasecmp (s
, "OR", 2) == 0
5278 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5282 *rightstart
= input_line_pointer
;
5284 if (*rightstop
> *rightstart
5285 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5288 input_line_pointer
= s
;
5293 #define MCC(b1, b2) (((b1) << 8) | (b2))
5295 /* Swap the sense of a condition. This changes the condition so that
5296 it generates the same result when the operands are swapped. */
5299 swap_mri_condition (cc
)
5304 case MCC ('h', 'i'): return MCC ('c', 's');
5305 case MCC ('l', 's'): return MCC ('c', 'c');
5306 case MCC ('c', 'c'): return MCC ('l', 's');
5307 case MCC ('c', 's'): return MCC ('h', 'i');
5308 case MCC ('p', 'l'): return MCC ('m', 'i');
5309 case MCC ('m', 'i'): return MCC ('p', 'l');
5310 case MCC ('g', 'e'): return MCC ('l', 'e');
5311 case MCC ('l', 't'): return MCC ('g', 't');
5312 case MCC ('g', 't'): return MCC ('l', 't');
5313 case MCC ('l', 'e'): return MCC ('g', 'e');
5318 /* Reverse the sense of a condition. */
5321 reverse_mri_condition (cc
)
5326 case MCC ('h', 'i'): return MCC ('l', 's');
5327 case MCC ('l', 's'): return MCC ('h', 'i');
5328 case MCC ('c', 'c'): return MCC ('c', 's');
5329 case MCC ('c', 's'): return MCC ('c', 'c');
5330 case MCC ('n', 'e'): return MCC ('e', 'q');
5331 case MCC ('e', 'q'): return MCC ('n', 'e');
5332 case MCC ('v', 'c'): return MCC ('v', 's');
5333 case MCC ('v', 's'): return MCC ('v', 'c');
5334 case MCC ('p', 'l'): return MCC ('m', 'i');
5335 case MCC ('m', 'i'): return MCC ('p', 'l');
5336 case MCC ('g', 'e'): return MCC ('l', 't');
5337 case MCC ('l', 't'): return MCC ('g', 'e');
5338 case MCC ('g', 't'): return MCC ('l', 'e');
5339 case MCC ('l', 'e'): return MCC ('g', 't');
5344 /* Build an MRI structured control expression. This generates test
5345 and branch instructions. It goes to TRUELAB if the condition is
5346 true, and to FALSELAB if the condition is false. Exactly one of
5347 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5348 is the size qualifier for the expression. EXTENT is the size to
5349 use for the branch. */
5352 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5353 rightstop
, truelab
, falselab
, extent
)
5360 const char *truelab
;
5361 const char *falselab
;
5367 if (leftstart
!= NULL
)
5369 struct m68k_op leftop
, rightop
;
5372 /* Swap the compare operands, if necessary, to produce a legal
5373 m68k compare instruction. Comparing a register operand with
5374 a non-register operand requires the register to be on the
5375 right (cmp, cmpa). Comparing an immediate value with
5376 anything requires the immediate value to be on the left
5381 (void) m68k_ip_op (leftstart
, &leftop
);
5386 (void) m68k_ip_op (rightstart
, &rightop
);
5389 if (rightop
.mode
== IMMED
5390 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5391 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5395 cc
= swap_mri_condition (cc
);
5397 leftstart
= rightstart
;
5400 leftstop
= rightstop
;
5405 if (truelab
== NULL
)
5407 cc
= reverse_mri_condition (cc
);
5411 if (leftstart
!= NULL
)
5413 buf
= (char *) xmalloc (20
5414 + (leftstop
- leftstart
)
5415 + (rightstop
- rightstart
));
5423 memcpy (s
, leftstart
, leftstop
- leftstart
);
5424 s
+= leftstop
- leftstart
;
5426 memcpy (s
, rightstart
, rightstop
- rightstart
);
5427 s
+= rightstop
- rightstart
;
5433 buf
= (char *) xmalloc (20 + strlen (truelab
));
5441 strcpy (s
, truelab
);
5446 /* Parse an MRI structured control expression. This generates test
5447 and branch instructions. STOP is where the expression ends. It
5448 goes to TRUELAB if the condition is true, and to FALSELAB if the
5449 condition is false. Exactly one of TRUELAB and FALSELAB will be
5450 NULL, meaning to fall through. QUAL is the size qualifier for the
5451 expression. EXTENT is the size to use for the branch. */
5454 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
5457 const char *truelab
;
5458 const char *falselab
;
5471 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5472 &rightstart
, &rightstop
))
5478 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5482 if (falselab
!= NULL
)
5485 flab
= mri_control_label ();
5487 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5488 rightstop
, (const char *) NULL
, flab
, extent
);
5490 input_line_pointer
+= 3;
5491 if (*input_line_pointer
!= '.'
5492 || input_line_pointer
[1] == '\0')
5496 qual
= input_line_pointer
[1];
5497 input_line_pointer
+= 2;
5500 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5501 &rightstart
, &rightstop
))
5507 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5508 rightstop
, truelab
, falselab
, extent
);
5510 if (falselab
== NULL
)
5513 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5517 if (truelab
!= NULL
)
5520 tlab
= mri_control_label ();
5522 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5523 rightstop
, tlab
, (const char *) NULL
, extent
);
5525 input_line_pointer
+= 2;
5526 if (*input_line_pointer
!= '.'
5527 || input_line_pointer
[1] == '\0')
5531 qual
= input_line_pointer
[1];
5532 input_line_pointer
+= 2;
5535 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5536 &rightstart
, &rightstop
))
5542 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5543 rightstop
, truelab
, falselab
, extent
);
5545 if (truelab
== NULL
)
5550 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5551 rightstop
, truelab
, falselab
, extent
);
5555 if (input_line_pointer
!= stop
)
5556 as_bad ("syntax error in structured control directive");
5559 /* Handle the MRI IF pseudo-op. This may be a structured control
5560 directive, or it may be a regular assembler conditional, depending
5569 struct mri_control_info
*n
;
5571 /* A structured control directive must end with THEN with an
5572 optional qualifier. */
5573 s
= input_line_pointer
;
5574 while (! is_end_of_line
[(unsigned char) *s
]
5575 && (! flag_mri
|| *s
!= '*'))
5578 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5581 if (s
- input_line_pointer
> 1
5585 if (s
- input_line_pointer
< 3
5586 || strncasecmp (s
- 3, "THEN", 4) != 0)
5590 as_bad ("missing then");
5591 ignore_rest_of_line ();
5595 /* It's a conditional. */
5600 /* Since this might be a conditional if, this pseudo-op will be
5601 called even if we are supported to be ignoring input. Double
5602 check now. Clobber *input_line_pointer so that ignore_input
5603 thinks that this is not a special pseudo-op. */
5604 c
= *input_line_pointer
;
5605 *input_line_pointer
= 0;
5606 if (ignore_input ())
5608 *input_line_pointer
= c
;
5609 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5610 ++input_line_pointer
;
5611 demand_empty_rest_of_line ();
5614 *input_line_pointer
= c
;
5616 n
= push_mri_control (mri_if
);
5618 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5619 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5622 input_line_pointer
= s
+ 3;
5624 input_line_pointer
= s
+ 1;
5628 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5629 ++input_line_pointer
;
5632 demand_empty_rest_of_line ();
5635 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5636 structured IF, associate the ELSE with the IF. Otherwise, assume
5637 it is a conditional else. */
5648 && (mri_control_stack
== NULL
5649 || mri_control_stack
->type
!= mri_if
5650 || mri_control_stack
->else_seen
))
5656 c
= *input_line_pointer
;
5657 *input_line_pointer
= 0;
5658 if (ignore_input ())
5660 *input_line_pointer
= c
;
5661 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5662 ++input_line_pointer
;
5663 demand_empty_rest_of_line ();
5666 *input_line_pointer
= c
;
5668 if (mri_control_stack
== NULL
5669 || mri_control_stack
->type
!= mri_if
5670 || mri_control_stack
->else_seen
)
5672 as_bad ("else without matching if");
5673 ignore_rest_of_line ();
5677 mri_control_stack
->else_seen
= 1;
5679 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
5682 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
5686 colon (mri_control_stack
->next
);
5690 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5691 ++input_line_pointer
;
5694 demand_empty_rest_of_line ();
5697 /* Handle the MRI ENDI pseudo-op. */
5703 if (mri_control_stack
== NULL
5704 || mri_control_stack
->type
!= mri_if
)
5706 as_bad ("endi without matching if");
5707 ignore_rest_of_line ();
5711 /* ignore_input will not return true for ENDI, so we don't need to
5712 worry about checking it again here. */
5714 if (! mri_control_stack
->else_seen
)
5715 colon (mri_control_stack
->next
);
5716 colon (mri_control_stack
->bottom
);
5722 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5723 ++input_line_pointer
;
5726 demand_empty_rest_of_line ();
5729 /* Handle the MRI BREAK pseudo-op. */
5732 s_mri_break (extent
)
5735 struct mri_control_info
*n
;
5739 n
= mri_control_stack
;
5741 && n
->type
!= mri_for
5742 && n
->type
!= mri_repeat
5743 && n
->type
!= mri_while
)
5747 as_bad ("break outside of structured loop");
5748 ignore_rest_of_line ();
5752 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
5755 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
5761 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5762 ++input_line_pointer
;
5765 demand_empty_rest_of_line ();
5768 /* Handle the MRI NEXT pseudo-op. */
5774 struct mri_control_info
*n
;
5778 n
= mri_control_stack
;
5780 && n
->type
!= mri_for
5781 && n
->type
!= mri_repeat
5782 && n
->type
!= mri_while
)
5786 as_bad ("next outside of structured loop");
5787 ignore_rest_of_line ();
5791 buf
= (char *) xmalloc (20 + strlen (n
->next
));
5794 sprintf (buf
, "bra%s %s", ex
, n
->next
);
5800 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5801 ++input_line_pointer
;
5804 demand_empty_rest_of_line ();
5807 /* Handle the MRI FOR pseudo-op. */
5813 const char *varstart
, *varstop
;
5814 const char *initstart
, *initstop
;
5815 const char *endstart
, *endstop
;
5816 const char *bystart
, *bystop
;
5820 struct mri_control_info
*n
;
5826 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
5830 varstart
= input_line_pointer
;
5832 /* Look for the '='. */
5833 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
5834 && *input_line_pointer
!= '=')
5835 ++input_line_pointer
;
5836 if (*input_line_pointer
!= '=')
5838 as_bad ("missing =");
5839 ignore_rest_of_line ();
5843 varstop
= input_line_pointer
;
5844 if (varstop
> varstart
5845 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
5848 ++input_line_pointer
;
5850 initstart
= input_line_pointer
;
5852 /* Look for TO or DOWNTO. */
5855 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5857 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
5858 && ! is_part_of_name (input_line_pointer
[2]))
5860 initstop
= input_line_pointer
;
5861 input_line_pointer
+= 2;
5864 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
5865 && ! is_part_of_name (input_line_pointer
[6]))
5867 initstop
= input_line_pointer
;
5869 input_line_pointer
+= 6;
5872 ++input_line_pointer
;
5874 if (initstop
== NULL
)
5876 as_bad ("missing to or downto");
5877 ignore_rest_of_line ();
5880 if (initstop
> initstart
5881 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
5885 endstart
= input_line_pointer
;
5887 /* Look for BY or DO. */
5890 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5892 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
5893 && ! is_part_of_name (input_line_pointer
[2]))
5895 endstop
= input_line_pointer
;
5897 input_line_pointer
+= 2;
5900 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
5901 && (input_line_pointer
[2] == '.'
5902 || ! is_part_of_name (input_line_pointer
[2])))
5904 endstop
= input_line_pointer
;
5905 input_line_pointer
+= 2;
5908 ++input_line_pointer
;
5910 if (endstop
== NULL
)
5912 as_bad ("missing do");
5913 ignore_rest_of_line ();
5916 if (endstop
> endstart
5917 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
5923 bystop
= bystart
+ 2;
5928 bystart
= input_line_pointer
;
5932 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5934 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
5935 && (input_line_pointer
[2] == '.'
5936 || ! is_part_of_name (input_line_pointer
[2])))
5938 bystop
= input_line_pointer
;
5939 input_line_pointer
+= 2;
5942 ++input_line_pointer
;
5946 as_bad ("missing do");
5947 ignore_rest_of_line ();
5950 if (bystop
> bystart
5951 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
5955 if (*input_line_pointer
!= '.')
5959 extent
= input_line_pointer
[1];
5960 input_line_pointer
+= 2;
5963 /* We have fully parsed the FOR operands. Now build the loop. */
5965 n
= push_mri_control (mri_for
);
5967 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
5978 memcpy (s
, initstart
, initstop
- initstart
);
5979 s
+= initstop
- initstart
;
5981 memcpy (s
, varstart
, varstop
- varstart
);
5982 s
+= varstop
- varstart
;
5996 memcpy (s
, endstart
, endstop
- endstart
);
5997 s
+= endstop
- endstart
;
5999 memcpy (s
, varstart
, varstop
- varstart
);
6000 s
+= varstop
- varstart
;
6008 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6010 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6013 /* Put together the add or sub instruction used by ENDF. */
6023 memcpy (s
, bystart
, bystop
- bystart
);
6024 s
+= bystop
- bystart
;
6026 memcpy (s
, varstart
, varstop
- varstart
);
6027 s
+= varstop
- varstart
;
6033 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6034 ++input_line_pointer
;
6037 demand_empty_rest_of_line ();
6040 /* Handle the MRI ENDF pseudo-op. */
6046 if (mri_control_stack
== NULL
6047 || mri_control_stack
->type
!= mri_for
)
6049 as_bad ("endf without for");
6050 ignore_rest_of_line ();
6054 colon (mri_control_stack
->next
);
6056 md_assemble (mri_control_stack
->incr
);
6058 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6059 md_assemble (mri_control_stack
->incr
);
6061 free (mri_control_stack
->incr
);
6063 colon (mri_control_stack
->bottom
);
6069 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6070 ++input_line_pointer
;
6073 demand_empty_rest_of_line ();
6076 /* Handle the MRI REPEAT pseudo-op. */
6079 s_mri_repeat (ignore
)
6082 struct mri_control_info
*n
;
6084 n
= push_mri_control (mri_repeat
);
6088 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6089 ++input_line_pointer
;
6091 demand_empty_rest_of_line ();
6094 /* Handle the MRI UNTIL pseudo-op. */
6102 if (mri_control_stack
== NULL
6103 || mri_control_stack
->type
!= mri_repeat
)
6105 as_bad ("until without repeat");
6106 ignore_rest_of_line ();
6110 colon (mri_control_stack
->next
);
6112 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6115 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6116 mri_control_stack
->top
, '\0');
6118 colon (mri_control_stack
->bottom
);
6120 input_line_pointer
= s
;
6126 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6127 ++input_line_pointer
;
6130 demand_empty_rest_of_line ();
6133 /* Handle the MRI WHILE pseudo-op. */
6141 struct mri_control_info
*n
;
6143 s
= input_line_pointer
;
6144 while (! is_end_of_line
[(unsigned char) *s
]
6145 && (! flag_mri
|| *s
!= '*'))
6148 while (*s
== ' ' || *s
== '\t')
6150 if (s
- input_line_pointer
> 1
6153 if (s
- input_line_pointer
< 2
6154 || strncasecmp (s
- 1, "DO", 2) != 0)
6156 as_bad ("missing do");
6157 ignore_rest_of_line ();
6161 n
= push_mri_control (mri_while
);
6165 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6166 s
[1] == '.' ? s
[2] : '\0');
6168 input_line_pointer
= s
+ 1;
6169 if (*input_line_pointer
== '.')
6170 input_line_pointer
+= 2;
6174 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6175 ++input_line_pointer
;
6178 demand_empty_rest_of_line ();
6181 /* Handle the MRI ENDW pseudo-op. */
6189 if (mri_control_stack
== NULL
6190 || mri_control_stack
->type
!= mri_while
)
6192 as_bad ("endw without while");
6193 ignore_rest_of_line ();
6197 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6198 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6202 colon (mri_control_stack
->bottom
);
6208 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6209 ++input_line_pointer
;
6212 demand_empty_rest_of_line ();
6217 * Invocation line includes a switch not recognized by the base assembler.
6218 * See if it's a processor-specific option. These are:
6220 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6221 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6222 * Select the architecture. Instructions or features not
6223 * supported by the selected architecture cause fatal
6224 * errors. More than one may be specified. The default is
6225 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6226 * for -m68000, and -m68882 is a synonym for -m68881.
6227 * -[A]m[c]no-68851, -[A]m[c]no-68881
6228 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6229 * so don't use or document it, but that's the way the parsing
6232 * -pic Indicates PIC.
6233 * -k Indicates PIC. (Sun 3 only.)
6236 * Permit `|' to be used in expressions.
6241 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6243 CONST
char *md_shortopts
= "lSA:m:k";
6246 struct option md_longopts
[] = {
6247 #define OPTION_PIC (OPTION_MD_BASE)
6248 {"pic", no_argument
, NULL
, OPTION_PIC
},
6249 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6250 {"register-prefix-optional", no_argument
, NULL
,
6251 OPTION_REGISTER_PREFIX_OPTIONAL
},
6252 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6253 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
6254 {NULL
, no_argument
, NULL
, 0}
6256 size_t md_longopts_size
= sizeof(md_longopts
);
6259 md_parse_option (c
, arg
)
6265 case 'l': /* -l means keep external to 2 bit offset
6266 rather than 16 bit one */
6267 flag_short_refs
= 1;
6270 case 'S': /* -S means that jbsr's always turn into
6272 flag_long_jumps
= 1;
6278 /* intentional fall-through */
6281 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6285 const char *oarg
= arg
;
6291 if (arg
[0] == 'c' && arg
[1] == '6')
6294 for (i
= 0; i
< n_archs
; i
++)
6295 if (!strcmp (arg
, archs
[i
].name
))
6300 as_bad ("unrecognized option `%s'", oarg
);
6303 arch
= archs
[i
].arch
;
6306 else if (arch
== m68851
)
6315 if (arg
[0] == 'c' && arg
[1] == '6')
6318 for (i
= 0; i
< n_archs
; i
++)
6319 if (!strcmp (arg
, archs
[i
].name
))
6321 unsigned long arch
= archs
[i
].arch
;
6322 if (cpu_of_arch (arch
))
6323 /* It's a cpu spec. */
6325 current_architecture
&= ~m68000up
;
6326 current_architecture
|= arch
;
6328 else if (arch
== m68881
)
6330 current_architecture
|= m68881
;
6333 else if (arch
== m68851
)
6335 current_architecture
|= m68851
;
6345 as_bad ("unrecognized architecture specification `%s'", arg
);
6354 break; /* -pic, Position Independent Code */
6356 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6357 flag_reg_prefix_optional
= 1;
6358 reg_prefix_optional_seen
= 1;
6361 /* -V: SVR4 argument to print version ID. */
6363 print_version_id ();
6366 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6367 should be emitted or not. FIXME: Not implemented. */
6371 case OPTION_BITWISE_OR
:
6376 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
6378 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
6382 m68k_comment_chars
= n
;
6394 md_show_usage (stream
)
6399 -l use 1 word for refs to undefined symbols [default 2]\n\
6400 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6401 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6402 | -mcpu32 | -m5200\n\
6403 specify variant of 680X0 architecture [default 68020]\n\
6404 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6405 target has/lacks floating-point coprocessor\n\
6406 [default yes for 68020, 68030, and cpu32]\n");
6408 -m68851 | -mno-68851\n\
6409 target has/lacks memory-management unit coprocessor\n\
6410 [default yes for 68020 and up]\n\
6411 -pic, -k generate position independent code\n\
6412 -S turn jbsr into jsr\n\
6413 --register-prefix-optional\n\
6414 recognize register names without prefix character\n\
6415 --bitwise-or do not treat `|' as a comment character\n");
6420 /* TEST2: Test md_assemble() */
6421 /* Warning, this routine probably doesn't work anymore */
6425 struct m68k_it the_ins
;
6433 if (!gets (buf
) || !*buf
)
6435 if (buf
[0] == '|' || buf
[1] == '.')
6437 for (cp
= buf
; *cp
; cp
++)
6442 memset (&the_ins
, '\0', sizeof (the_ins
));
6443 m68k_ip (&the_ins
, buf
);
6446 printf ("Error %s in %s\n", the_ins
.error
, buf
);
6450 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
6451 for (n
= 0; n
< the_ins
.numo
; n
++)
6452 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
6454 print_the_insn (&the_ins
.opcode
[0], stdout
);
6455 (void) putchar ('\n');
6457 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
6459 if (the_ins
.operands
[n
].error
)
6461 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
6464 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
6465 if (the_ins
.operands
[n
].b_const
)
6466 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
6467 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
6468 if (the_ins
.operands
[n
].b_iadd
)
6469 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
6470 (void) putchar ('\n');
6482 while (*str
&& *str
!= ' ')
6484 if (str
[-1] == ':' || str
[1] == '=')
6491 /* Possible states for relaxation:
6493 0 0 branch offset byte (bra, etc)
6497 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6501 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6508 /* We have no need to default values of symbols. */
6512 md_undefined_symbol (name
)
6518 /* Round up a section size to the appropriate boundary. */
6520 md_section_align (segment
, size
)
6524 return size
; /* Byte alignment is fine */
6527 /* Exactly what point is a PC-relative offset relative TO?
6528 On the 68k, it is relative to the address of the first extension
6529 word. The difference between the addresses of the offset and the
6530 first extension word is stored in fx_pcrel_adjust. */
6532 md_pcrel_from (fixP
)
6537 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6539 adjust
= fixP
->fx_pcrel_adjust
;
6542 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
6545 #ifndef BFD_ASSEMBLER
6548 tc_coff_symbol_emit_hook (ignore
)
6554 tc_coff_sizemachdep (frag
)
6557 switch (frag
->fr_subtype
& 0x3)
6572 /* end of tc-m68k.c */