1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/m68k.h"
28 #include "m68k-parse.h"
30 /* This string holds the chars that always start a comment. If the
31 pre-processor is disabled, these aren't very useful. The macro
32 tc_comment_chars points to this. We use this, rather than the
33 usual comment_chars, so that the --bitwise-or option will work. */
34 #if defined (TE_SVR4) || defined (TE_DELTA)
35 const char *m68k_comment_chars
= "|#";
37 const char *m68k_comment_chars
= "|";
40 /* This array holds the chars that only start a comment at the beginning of
41 a line. If the line seems to have the form '# 123 filename'
42 .line and .file directives will appear in the pre-processed output */
43 /* Note that input_file.c hand checks for '#' at the beginning of the
44 first line of the input file. This is because the compiler outputs
45 #NO_APP at the beginning of its output. */
46 /* Also note that comments like this one will always work. */
47 const char line_comment_chars
[] = "#";
49 const char line_separator_chars
[] = "";
51 /* Chars that can be used to separate mant from exp in floating point nums */
52 CONST
char EXP_CHARS
[] = "eE";
54 /* Chars that mean this number is a floating point constant, as
55 in "0f12.456" or "0d1.2345e12". */
57 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
59 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
60 changed in read.c . Ideally it shouldn't have to know about it at all,
61 but nothing is ideal around here. */
63 const int md_reloc_size
= 8; /* Size of relocation record */
65 /* Are we trying to generate PIC code? If so, absolute references
66 ought to be made into linkage table references or pc-relative
67 references. Not implemented. For ELF there are other means
68 to denote pic relocations. */
71 static int flag_short_refs
; /* -l option */
72 static int flag_long_jumps
; /* -S option */
74 #ifdef REGISTER_PREFIX_OPTIONAL
75 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
77 int flag_reg_prefix_optional
;
80 /* Whether --register-prefix-optional was used on the command line. */
81 static int reg_prefix_optional_seen
;
83 /* The floating point coprocessor to use by default. */
84 static enum m68k_register m68k_float_copnum
= COP1
;
86 /* If this is non-zero, then references to number(%pc) will be taken
87 to refer to number, rather than to %pc + number. */
88 static int m68k_abspcadd
;
90 /* If this is non-zero, then the quick forms of the move, add, and sub
91 instructions are used when possible. */
92 static int m68k_quick
= 1;
94 /* If this is non-zero, then if the size is not specified for a base
95 or outer displacement, the assembler assumes that the size should
97 static int m68k_rel32
= 1;
99 /* This is non-zero if m68k_rel32 was set from the command line. */
100 static int m68k_rel32_from_cmdline
;
102 /* The default width to use for an index register when using a base
104 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
106 /* We want to warn if any text labels are misaligned. In order to get
107 the right line number, we need to record the line number for each
112 struct label_line
*next
;
119 /* The list of labels. */
121 static struct label_line
*labels
;
123 /* The current label. */
125 static struct label_line
*current_label
;
127 /* Its an arbitrary name: This means I don't approve of it */
128 /* See flames below */
129 static struct obstack robyn
;
131 #define TAB(x,y) (((x)<<2)+(y))
132 #define TABTYPE(xy) ((xy) >> 2)
138 /* Case `g' except when BCC68000 is applicable. */
140 /* Coprocessor branches. */
142 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
143 supported on all cpus. Widens to 32-bit absolute. */
145 /* For inserting an extra jmp instruction with long offset on 68000,
146 for expanding conditional branches. (Not bsr or bra.) Since the
147 68000 doesn't support 32-bit displacements for conditional
148 branches, we fake it by reversing the condition and branching
149 around a jmp with an absolute long operand. */
151 /* For the DBcc "instructions". If the displacement requires 32 bits,
152 the branch-around-a-jump game is played here too. */
154 /* Not currently used? */
156 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
162 const char *m_operands
;
163 unsigned long m_opcode
;
167 struct m68k_incant
*m_next
;
170 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
171 #define gettwo(x) (((x)->m_opcode)&0xffff)
173 static const enum m68k_register m68000_control_regs
[] = { 0 };
174 static const enum m68k_register m68010_control_regs
[] = {
178 static const enum m68k_register m68020_control_regs
[] = {
179 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
182 static const enum m68k_register m68040_control_regs
[] = {
183 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
184 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
187 static const enum m68k_register m68060_control_regs
[] = {
188 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
189 USP
, VBR
, URP
, SRP
, PCR
,
192 static const enum m68k_register mcf5200_control_regs
[] = {
193 CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, VBR
, ROMBAR
,
194 RAMBAR0
, RAMBAR1
, MBAR
,
197 #define cpu32_control_regs m68010_control_regs
199 static const enum m68k_register
*control_regs
;
201 /* internal form of a 68020 instruction */
205 const char *args
; /* list of opcode info */
208 int numo
; /* Number of shorts in opcode */
211 struct m68k_op operands
[6];
213 int nexp
; /* number of exprs in use */
214 struct m68k_exp exprs
[4];
216 int nfrag
; /* Number of frags we have to produce */
219 int fragoff
; /* Where in the current opcode the frag ends */
226 int nrel
; /* Num of reloc strucs in use */
233 /* In a pc relative address the difference between the address
234 of the offset and the address that the offset is relative
235 to. This depends on the addressing mode. Basically this
236 is the value to put in the offset field to address the
237 first byte of the offset, without regarding the special
238 significance of some values (in the branch instruction, for
242 /* Whether this expression needs special pic relocation, and if
244 enum pic_relocation pic_reloc
;
247 reloc
[5]; /* Five is enough??? */
250 #define cpu_of_arch(x) ((x) & (m68000up|mcf5200))
251 #define float_of_arch(x) ((x) & mfloat)
252 #define mmu_of_arch(x) ((x) & mmmu)
254 /* Macros for determining if cpu supports a specific addressing mode */
255 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32))
257 static struct m68k_it the_ins
; /* the instruction being assembled */
259 #define op(ex) ((ex)->exp.X_op)
260 #define adds(ex) ((ex)->exp.X_add_symbol)
261 #define subs(ex) ((ex)->exp.X_op_symbol)
262 #define offs(ex) ((ex)->exp.X_add_number)
264 /* Macros for adding things to the m68k_it struct */
266 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
268 /* Like addword, but goes BEFORE general operands */
272 struct m68k_incant
*opcode
;
275 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
276 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
277 for(z
=0;z
<the_ins
.nrel
;z
++)
278 the_ins
.reloc
[z
].n
+=2;
279 for (z
= 0; z
< the_ins
.nfrag
; z
++)
280 the_ins
.fragb
[z
].fragoff
++;
281 the_ins
.opcode
[opcode
->m_codenum
]=w
;
285 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
288 add_fix (width
, exp
, pc_rel
, pc_fix
)
290 struct m68k_exp
*exp
;
294 the_ins
.reloc
[the_ins
.nrel
].n
= ((width
== 'B' || width
== '3')
298 : (the_ins
.numo
*2)));
299 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
300 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
301 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
303 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
305 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
308 /* Cause an extra frag to be generated here, inserting up to 10 bytes
309 (that value is chosen in the frag_var call in md_assemble). TYPE
310 is the subtype of the frag to be generated; its primary type is
311 rs_machine_dependent.
313 The TYPE parameter is also used by md_convert_frag_1 and
314 md_estimate_size_before_relax. The appropriate type of fixup will
315 be emitted by md_convert_frag_1.
317 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
319 add_frag(add
,off
,type
)
324 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
325 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
326 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
327 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
331 (op (ex) != O_constant && op (ex) != O_big)
333 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
334 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
335 static int reverse_16_bits
PARAMS ((int in
));
336 static int reverse_8_bits
PARAMS ((int in
));
337 static void install_gen_operand
PARAMS ((int mode
, int val
));
338 static void install_operand
PARAMS ((int mode
, int val
));
339 static void s_bss
PARAMS ((int));
340 static void s_data1
PARAMS ((int));
341 static void s_data2
PARAMS ((int));
342 static void s_even
PARAMS ((int));
343 static void s_proc
PARAMS ((int));
344 static void mri_chip
PARAMS ((void));
345 static void s_chip
PARAMS ((int));
346 static void s_fopt
PARAMS ((int));
347 static void s_opt
PARAMS ((int));
348 static void s_reg
PARAMS ((int));
349 static void s_restore
PARAMS ((int));
350 static void s_save
PARAMS ((int));
351 static void s_mri_if
PARAMS ((int));
352 static void s_mri_else
PARAMS ((int));
353 static void s_mri_endi
PARAMS ((int));
354 static void s_mri_break
PARAMS ((int));
355 static void s_mri_next
PARAMS ((int));
356 static void s_mri_for
PARAMS ((int));
357 static void s_mri_endf
PARAMS ((int));
358 static void s_mri_repeat
PARAMS ((int));
359 static void s_mri_until
PARAMS ((int));
360 static void s_mri_while
PARAMS ((int));
361 static void s_mri_endw
PARAMS ((int));
363 static int current_architecture
;
371 static const struct m68k_cpu archs
[] = {
372 { m68000
, "68000", 0 },
373 { m68010
, "68010", 0 },
374 { m68020
, "68020", 0 },
375 { m68030
, "68030", 0 },
376 { m68040
, "68040", 0 },
377 { m68060
, "68060", 0 },
378 { cpu32
, "cpu32", 0 },
379 { m68881
, "68881", 0 },
380 { m68851
, "68851", 0 },
381 { mcf5200
, "5200", 0 },
382 /* Aliases (effectively, so far as gas is concerned) for the above
384 { m68020
, "68k", 1 },
385 { m68000
, "68302", 1 },
386 { m68000
, "68008", 1 },
387 { m68000
, "68ec000", 1 },
388 { m68000
, "68hc000", 1 },
389 { m68000
, "68hc001", 1 },
390 { m68020
, "68ec020", 1 },
391 { m68030
, "68ec030", 1 },
392 { m68040
, "68ec040", 1 },
393 { m68060
, "68ec060", 1 },
394 { cpu32
, "68330", 1 },
395 { cpu32
, "68331", 1 },
396 { cpu32
, "68332", 1 },
397 { cpu32
, "68333", 1 },
398 { cpu32
, "68340", 1 },
399 { cpu32
, "68360", 1 },
400 { m68881
, "68882", 1 },
403 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
405 /* BCC68000 is for patching in an extra jmp instruction for long offsets
406 on the 68000. The 68000 doesn't support long branches with branchs */
408 /* This table desribes how you change sizes for the various types of variable
409 size expressions. This version only supports two kinds. */
411 /* Note that calls to frag_var need to specify the maximum expansion
412 needed; this is currently 10 bytes for DBCC. */
415 How far Forward this mode will reach:
416 How far Backward this mode will reach:
417 How many bytes this mode will add to the size of the frag
418 Which mode to go to if the offset won't fit in this one
420 relax_typeS md_relax_table
[] =
422 {1, 1, 0, 0}, /* First entries aren't used */
423 {1, 1, 0, 0}, /* For no good reason except */
424 {1, 1, 0, 0}, /* that the VAX doesn't either */
427 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
428 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
432 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
433 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
437 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
438 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
442 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
443 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
444 {0, 0, 6, 0}, /* jmp long space */
447 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
448 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
449 {0, 0, 10, 0}, /* bra/jmp long space */
452 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
453 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
457 /* For, e.g., jmp pcrel indexed. */
458 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
459 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
464 /* These are the machine dependent pseudo-ops. These are included so
465 the assembler can work on the output from the SUN C compiler, which
469 /* This table describes all the machine specific pseudo-ops the assembler
470 has to support. The fields are:
471 pseudo-op name without dot
472 function to call to execute this pseudo-op
473 Integer arg to pass to the function
475 const pseudo_typeS md_pseudo_table
[] =
477 {"data1", s_data1
, 0},
478 {"data2", s_data2
, 0},
481 {"skip", s_space
, 0},
483 #if defined (TE_SUN3) || defined (OBJ_ELF)
484 {"align", s_align_bytes
, 0},
487 {"swbeg", s_ignore
, 0},
489 {"extend", float_cons
, 'x'},
490 {"ldouble", float_cons
, 'x'},
492 /* The following pseudo-ops are supported for MRI compatibility. */
494 {"comline", s_space
, 1},
496 {"mask2", s_ignore
, 0},
499 {"restore", s_restore
, 0},
503 {"if.b", s_mri_if
, 'b'},
504 {"if.w", s_mri_if
, 'w'},
505 {"if.l", s_mri_if
, 'l'},
506 {"else", s_mri_else
, 0},
507 {"else.s", s_mri_else
, 's'},
508 {"else.l", s_mri_else
, 'l'},
509 {"endi", s_mri_endi
, 0},
510 {"break", s_mri_break
, 0},
511 {"break.s", s_mri_break
, 's'},
512 {"break.l", s_mri_break
, 'l'},
513 {"next", s_mri_next
, 0},
514 {"next.s", s_mri_next
, 's'},
515 {"next.l", s_mri_next
, 'l'},
516 {"for", s_mri_for
, 0},
517 {"for.b", s_mri_for
, 'b'},
518 {"for.w", s_mri_for
, 'w'},
519 {"for.l", s_mri_for
, 'l'},
520 {"endf", s_mri_endf
, 0},
521 {"repeat", s_mri_repeat
, 0},
522 {"until", s_mri_until
, 0},
523 {"until.b", s_mri_until
, 'b'},
524 {"until.w", s_mri_until
, 'w'},
525 {"until.l", s_mri_until
, 'l'},
526 {"while", s_mri_while
, 0},
527 {"while.b", s_mri_while
, 'b'},
528 {"while.w", s_mri_while
, 'w'},
529 {"while.l", s_mri_while
, 'l'},
530 {"endw", s_mri_endw
, 0},
536 /* The mote pseudo ops are put into the opcode table, since they
537 don't start with a . they look like opcodes to gas.
539 extern void obj_coff_section ();
541 CONST pseudo_typeS mote_pseudo_table
[] =
554 {"xdef", s_globl
, 0},
556 {"align", s_align_bytes
, 0},
558 {"align", s_align_ptwo
, 0},
561 {"sect", obj_coff_section
, 0},
562 {"section", obj_coff_section
, 0},
567 #define issbyte(x) ((x)>=-128 && (x)<=127)
568 #define isubyte(x) ((x)>=0 && (x)<=255)
569 #define issword(x) ((x)>=-32768 && (x)<=32767)
570 #define isuword(x) ((x)>=0 && (x)<=65535)
572 #define isbyte(x) ((x)>= -255 && (x)<=255)
573 #define isword(x) ((x)>=-65536 && (x)<=65535)
574 #define islong(x) (1)
576 extern char *input_line_pointer
;
578 static char mklower_table
[256];
579 #define mklower(c) (mklower_table[(unsigned char)(c)])
580 static char notend_table
[256];
581 static char alt_notend_table
[256];
583 (! (notend_table[(unsigned char) *s] \
585 && alt_notend_table[(unsigned char) s[1]])))
587 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
589 #ifdef NO_PCREL_RELOCS
592 make_pcrel_absolute(fixP
, add_number
)
596 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
598 /* rewrite the PC relative instructions to absolute address ones.
599 * these are rumoured to be faster, and the apollo linker refuses
600 * to deal with the PC relative relocations.
602 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
607 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
613 as_fatal ("Unknown PC relative instruction");
618 #endif /* NO_PCREL_RELOCS */
621 tc_coff_fix2rtype (fixP
)
624 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
625 return R_RELLONG_NEG
;
626 #ifdef NO_PCREL_RELOCS
627 know (fixP
->fx_pcrel
== 0);
628 return (fixP
->fx_size
== 1 ? R_RELBYTE
629 : fixP
->fx_size
== 2 ? R_DIR16
632 return (fixP
->fx_pcrel
?
633 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
634 fixP
->fx_size
== 2 ? R_PCRWORD
:
636 (fixP
->fx_size
== 1 ? R_RELBYTE
:
637 fixP
->fx_size
== 2 ? R_RELWORD
:
646 /* Compute the relocation code for a fixup of SIZE bytes, using pc
647 relative relocation if PCREL is non-zero. PIC says whether a special
648 pic relocation was requested. */
650 static bfd_reloc_code_real_type get_reloc_code
651 PARAMS ((int, int, enum pic_relocation
));
653 static bfd_reloc_code_real_type
654 get_reloc_code (size
, pcrel
, pic
)
657 enum pic_relocation pic
;
665 return BFD_RELOC_8_GOT_PCREL
;
667 return BFD_RELOC_16_GOT_PCREL
;
669 return BFD_RELOC_32_GOT_PCREL
;
677 return BFD_RELOC_8_GOTOFF
;
679 return BFD_RELOC_16_GOTOFF
;
681 return BFD_RELOC_32_GOTOFF
;
689 return BFD_RELOC_8_PLT_PCREL
;
691 return BFD_RELOC_16_PLT_PCREL
;
693 return BFD_RELOC_32_PLT_PCREL
;
701 return BFD_RELOC_8_PLTOFF
;
703 return BFD_RELOC_16_PLTOFF
;
705 return BFD_RELOC_32_PLTOFF
;
715 return BFD_RELOC_8_PCREL
;
717 return BFD_RELOC_16_PCREL
;
719 return BFD_RELOC_32_PCREL
;
736 as_bad ("Can not do %d byte %s%srelocation", size
,
737 pcrel
? "pc-relative " : "",
738 pic
== pic_none
? "" : "pic ");
739 return BFD_RELOC_NONE
;
742 /* Here we decide which fixups can be adjusted to make them relative
743 to the beginning of the section instead of the symbol. Basically
744 we need to make sure that the dynamic relocations are done
745 correctly, so in some cases we force the original symbol to be
748 tc_m68k_fix_adjustable (fixP
)
751 /* Prevent all adjustments to global symbols. */
752 if (S_IS_EXTERNAL (fixP
->fx_addsy
))
755 /* adjust_reloc_syms doesn't know about the GOT */
756 switch (fixP
->fx_r_type
)
758 case BFD_RELOC_8_GOT_PCREL
:
759 case BFD_RELOC_16_GOT_PCREL
:
760 case BFD_RELOC_32_GOT_PCREL
:
761 case BFD_RELOC_8_GOTOFF
:
762 case BFD_RELOC_16_GOTOFF
:
763 case BFD_RELOC_32_GOTOFF
:
764 case BFD_RELOC_8_PLT_PCREL
:
765 case BFD_RELOC_16_PLT_PCREL
:
766 case BFD_RELOC_32_PLT_PCREL
:
767 case BFD_RELOC_8_PLTOFF
:
768 case BFD_RELOC_16_PLTOFF
:
769 case BFD_RELOC_32_PLTOFF
:
779 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
786 tc_gen_reloc (section
, fixp
)
791 bfd_reloc_code_real_type code
;
796 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
798 code
= fixp
->fx_r_type
;
800 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
801 that fixup_segment converted a non-PC relative reloc into a
802 PC relative reloc. In such a case, we need to convert the
809 code
= BFD_RELOC_8_PCREL
;
812 code
= BFD_RELOC_16_PCREL
;
815 code
= BFD_RELOC_32_PCREL
;
817 case BFD_RELOC_8_PCREL
:
818 case BFD_RELOC_16_PCREL
:
819 case BFD_RELOC_32_PCREL
:
820 case BFD_RELOC_8_GOT_PCREL
:
821 case BFD_RELOC_16_GOT_PCREL
:
822 case BFD_RELOC_32_GOT_PCREL
:
823 case BFD_RELOC_8_GOTOFF
:
824 case BFD_RELOC_16_GOTOFF
:
825 case BFD_RELOC_32_GOTOFF
:
826 case BFD_RELOC_8_PLT_PCREL
:
827 case BFD_RELOC_16_PLT_PCREL
:
828 case BFD_RELOC_32_PLT_PCREL
:
829 case BFD_RELOC_8_PLTOFF
:
830 case BFD_RELOC_16_PLTOFF
:
831 case BFD_RELOC_32_PLTOFF
:
834 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
835 "Cannot make %s relocation PC relative",
836 bfd_get_reloc_code_name (code
));
842 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
843 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
845 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
846 MAP (1, 0, BFD_RELOC_8
);
847 MAP (2, 0, BFD_RELOC_16
);
848 MAP (4, 0, BFD_RELOC_32
);
849 MAP (1, 1, BFD_RELOC_8_PCREL
);
850 MAP (2, 1, BFD_RELOC_16_PCREL
);
851 MAP (4, 1, BFD_RELOC_32_PCREL
);
859 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
861 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
862 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
865 reloc
->addend
= fixp
->fx_addnumber
;
870 reloc
->addend
= fixp
->fx_addnumber
;
872 reloc
->addend
= (section
->vma
873 + (fixp
->fx_pcrel_adjust
== 64
874 ? -1 : fixp
->fx_pcrel_adjust
)
876 + md_pcrel_from (fixp
));
879 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
880 assert (reloc
->howto
!= 0);
885 #endif /* BFD_ASSEMBLER */
887 /* Handle of the OPCODE hash table. NULL means any use before
888 m68k_ip_begin() will crash. */
889 static struct hash_control
*op_hash
;
891 /* Assemble an m68k instruction. */
898 register struct m68k_op
*opP
;
899 register struct m68k_incant
*opcode
;
900 register const char *s
;
901 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
902 char *pdot
, *pdotmove
;
903 enum m68k_size siz1
, siz2
;
907 char *crack_operand ();
908 LITTLENUM_TYPE words
[6];
909 LITTLENUM_TYPE
*wordp
;
910 unsigned long ok_arch
= 0;
912 if (*instring
== ' ')
913 instring
++; /* skip leading whitespace */
915 /* Scan up to end of operation-code, which MUST end in end-of-string
916 or exactly 1 space. */
918 for (p
= instring
; *p
!= '\0'; p
++)
928 the_ins
.error
= "No operator";
932 /* p now points to the end of the opcode name, probably whitespace.
933 Make sure the name is null terminated by clobbering the
934 whitespace, look it up in the hash table, then fix it back.
935 Remove a dot, first, since the opcode tables have none. */
938 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
939 *pdotmove
= pdotmove
[1];
945 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
950 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
951 *pdotmove
= pdotmove
[-1];
958 the_ins
.error
= "Unknown operator";
962 /* found a legitimate opcode, start matching operands */
966 if (opcode
->m_operands
== 0)
968 char *old
= input_line_pointer
;
970 input_line_pointer
= p
;
971 /* Ahh - it's a motorola style psuedo op */
972 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
973 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
974 input_line_pointer
= old
;
980 if (flag_mri
&& opcode
->m_opnum
== 0)
982 /* In MRI mode, random garbage is allowed after an instruction
983 which accepts no operands. */
984 the_ins
.args
= opcode
->m_operands
;
985 the_ins
.numargs
= opcode
->m_opnum
;
986 the_ins
.numo
= opcode
->m_codenum
;
987 the_ins
.opcode
[0] = getone (opcode
);
988 the_ins
.opcode
[1] = gettwo (opcode
);
992 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
994 p
= crack_operand (p
, opP
);
998 the_ins
.error
= opP
->error
;
1003 opsfound
= opP
- &the_ins
.operands
[0];
1005 /* This ugly hack is to support the floating pt opcodes in their
1006 standard form. Essentially, we fake a first enty of type COP#1 */
1007 if (opcode
->m_operands
[0] == 'I')
1011 for (n
= opsfound
; n
> 0; --n
)
1012 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1014 memset ((char *) (&the_ins
.operands
[0]), '\0',
1015 sizeof (the_ins
.operands
[0]));
1016 the_ins
.operands
[0].mode
= CONTROL
;
1017 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1021 /* We've got the operands. Find an opcode that'll accept them */
1024 /* If we didn't get the right number of ops, or we have no
1025 common model with this pattern then reject this pattern. */
1027 ok_arch
|= opcode
->m_arch
;
1028 if (opsfound
!= opcode
->m_opnum
1029 || ((opcode
->m_arch
& current_architecture
) == 0))
1033 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
1037 /* Warning: this switch is huge! */
1038 /* I've tried to organize the cases into this order:
1039 non-alpha first, then alpha by letter. Lower-case
1040 goes directly before uppercase counterpart. */
1041 /* Code with multiple case ...: gets sorted by the lowest
1042 case ... it belongs to. I hope this makes sense. */
1166 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1175 if (opP
->mode
!= IMMED
)
1177 else if (s
[1] == 'b'
1178 && ! isvar (&opP
->disp
)
1179 && (opP
->disp
.exp
.X_op
!= O_constant
1180 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1182 else if (s
[1] == 'B'
1183 && ! isvar (&opP
->disp
)
1184 && (opP
->disp
.exp
.X_op
!= O_constant
1185 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1187 else if (s
[1] == 'w'
1188 && ! isvar (&opP
->disp
)
1189 && (opP
->disp
.exp
.X_op
!= O_constant
1190 || ! isword (opP
->disp
.exp
.X_add_number
)))
1192 else if (s
[1] == 'W'
1193 && ! isvar (&opP
->disp
)
1194 && (opP
->disp
.exp
.X_op
!= O_constant
1195 || ! issword (opP
->disp
.exp
.X_add_number
)))
1201 if (opP
->mode
!= IMMED
)
1206 if (opP
->mode
== AREG
1207 || opP
->mode
== CONTROL
1208 || opP
->mode
== FPREG
1209 || opP
->mode
== IMMED
1210 || opP
->mode
== REGLST
1211 || (opP
->mode
!= ABSL
1213 || opP
->reg
== ZPC
)))
1218 if (opP
->mode
== CONTROL
1219 || opP
->mode
== FPREG
1220 || opP
->mode
== REGLST
1221 || opP
->mode
== IMMED
1222 || (opP
->mode
!= ABSL
1224 || opP
->reg
== ZPC
)))
1252 if (opP
->mode
== CONTROL
1253 || opP
->mode
== FPREG
1254 || opP
->mode
== REGLST
)
1259 if (opP
->mode
!= AINC
)
1264 if (opP
->mode
!= ADEC
)
1314 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1335 case '~': /* For now! (JF FOO is this right?) */
1357 if (opP
->mode
!= CONTROL
1358 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1363 if (opP
->mode
!= AREG
)
1368 if (opP
->mode
!= AINDR
)
1373 if (opP
->mode
!= ABSL
1375 && strncmp (instring
, "jbsr", 4) == 0))
1380 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1385 if (opP
->mode
!= DISP
1387 || opP
->reg
> ADDR7
)
1392 if (opP
->mode
!= DREG
)
1397 if (opP
->mode
!= FPREG
)
1402 if (opP
->mode
!= CONTROL
1409 if (opP
->mode
!= CONTROL
1411 || opP
->reg
> last_movec_reg
)
1415 const enum m68k_register
*rp
;
1416 for (rp
= control_regs
; *rp
; rp
++)
1417 if (*rp
== opP
->reg
)
1425 if (opP
->mode
!= IMMED
)
1431 if (opP
->mode
== DREG
1432 || opP
->mode
== AREG
1433 || opP
->mode
== FPREG
)
1442 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1445 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1448 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1456 else if (opP
->mode
== CONTROL
)
1465 opP
->mask
= 1 << 24;
1468 opP
->mask
= 1 << 25;
1471 opP
->mask
= 1 << 26;
1480 else if (opP
->mode
== ABSL
1481 && opP
->disp
.size
== SIZE_UNSPEC
1482 && opP
->disp
.exp
.X_op
== O_constant
)
1484 /* This is what the MRI REG pseudo-op generates. */
1486 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1488 else if (opP
->mode
!= REGLST
)
1490 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1492 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1497 if (opP
->mode
!= IMMED
)
1499 else if (opP
->disp
.exp
.X_op
!= O_constant
1500 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1502 else if (! m68k_quick
1503 && instring
[3] != 'q'
1504 && instring
[4] != 'q')
1509 if (opP
->mode
!= DREG
1510 && opP
->mode
!= IMMED
1511 && opP
->mode
!= ABSL
)
1516 if (opP
->mode
!= IMMED
)
1518 else if (opP
->disp
.exp
.X_op
!= O_constant
1519 || opP
->disp
.exp
.X_add_number
< 1
1520 || opP
->disp
.exp
.X_add_number
> 8)
1522 else if (! m68k_quick
1523 && (strncmp (instring
, "add", 3) == 0
1524 || strncmp (instring
, "sub", 3) == 0)
1525 && instring
[3] != 'q')
1530 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1535 if (opP
->mode
!= AINDR
1536 && (opP
->mode
!= BASE
1538 && opP
->reg
!= ZADDR0
)
1539 || opP
->disp
.exp
.X_op
!= O_absent
1540 || ((opP
->index
.reg
< DATA0
1541 || opP
->index
.reg
> DATA7
)
1542 && (opP
->index
.reg
< ADDR0
1543 || opP
->index
.reg
> ADDR7
))
1544 || opP
->index
.size
!= SIZE_UNSPEC
1545 || opP
->index
.scale
!= 1))
1550 if (opP
->mode
!= CONTROL
1551 || ! (opP
->reg
== FPI
1553 || opP
->reg
== FPC
))
1558 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1563 if (opP
->mode
!= IMMED
)
1565 else if (opP
->disp
.exp
.X_op
!= O_constant
1566 || opP
->disp
.exp
.X_add_number
< 0
1567 || opP
->disp
.exp
.X_add_number
> 7)
1572 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1576 /* JF these are out of order. We could put them
1577 in order if we were willing to put up with
1578 bunches of #ifdef m68851s in the code.
1580 Don't forget that you need these operands
1581 to use 68030 MMU instructions. */
1583 /* Memory addressing mode used by pflushr */
1585 if (opP
->mode
== CONTROL
1586 || opP
->mode
== FPREG
1587 || opP
->mode
== DREG
1588 || opP
->mode
== AREG
1589 || opP
->mode
== REGLST
)
1591 /* We should accept immediate operands, but they
1592 supposedly have to be quad word, and we don't
1593 handle that. I would like to see what a Motorola
1594 assembler does before doing something here. */
1595 if (opP
->mode
== IMMED
)
1600 if (opP
->mode
!= CONTROL
1601 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1606 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1611 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1616 if (opP
->mode
!= CONTROL
1619 && opP
->reg
!= SCC
))
1624 if (opP
->mode
!= CONTROL
1630 if (opP
->mode
!= CONTROL
1633 && opP
->reg
!= CRP
))
1638 if (opP
->mode
!= CONTROL
1639 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1640 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1645 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1650 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1655 if (opP
->mode
!= CONTROL
1662 } /* not a cache specifier. */
1666 if (opP
->mode
!= ABSL
)
1672 } /* switch on type of operand */
1676 } /* for each operand */
1677 } /* if immediately wrong */
1684 opcode
= opcode
->m_next
;
1689 && !(ok_arch
& current_architecture
))
1694 "invalid instruction for this architecture; needs ");
1695 cp
= buf
+ strlen (buf
);
1699 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1702 strcpy (cp
, "mmu (68030 or 68851)");
1705 strcpy (cp
, "68020 or higher");
1708 strcpy (cp
, "68000 or higher");
1711 strcpy (cp
, "68010 or higher");
1715 int got_one
= 0, idx
;
1716 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1719 if ((archs
[idx
].arch
& ok_arch
)
1720 && ! archs
[idx
].alias
)
1724 strcpy (cp
, " or ");
1728 strcpy (cp
, archs
[idx
].name
);
1734 cp
= xmalloc (strlen (buf
) + 1);
1739 the_ins
.error
= "operands mismatch";
1741 } /* Fell off the end */
1746 /* now assemble it */
1748 the_ins
.args
= opcode
->m_operands
;
1749 the_ins
.numargs
= opcode
->m_opnum
;
1750 the_ins
.numo
= opcode
->m_codenum
;
1751 the_ins
.opcode
[0] = getone (opcode
);
1752 the_ins
.opcode
[1] = gettwo (opcode
);
1754 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1756 /* This switch is a doozy.
1757 Watch the first step; its a big one! */
1784 tmpreg
= 0x3c; /* 7.4 */
1785 if (strchr ("bwl", s
[1]))
1786 nextword
= get_num (&opP
->disp
, 80);
1788 nextword
= get_num (&opP
->disp
, 0);
1789 if (isvar (&opP
->disp
))
1790 add_fix (s
[1], &opP
->disp
, 0, 0);
1794 if (!isbyte (nextword
))
1795 opP
->error
= "operand out of range";
1800 if (!isword (nextword
))
1801 opP
->error
= "operand out of range";
1806 if (!issword (nextword
))
1807 opP
->error
= "operand out of range";
1812 addword (nextword
>> 16);
1839 /* We gotta put out some float */
1840 if (op (&opP
->disp
) != O_big
)
1845 /* Can other cases happen here? */
1846 if (op (&opP
->disp
) != O_constant
)
1849 val
= (valueT
) offs (&opP
->disp
);
1853 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1854 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1858 offs (&opP
->disp
) = gencnt
;
1860 if (offs (&opP
->disp
) > 0)
1862 if (offs (&opP
->disp
) > baseo
)
1864 as_warn ("Bignum too big for %c format; truncated",
1866 offs (&opP
->disp
) = baseo
;
1868 baseo
-= offs (&opP
->disp
);
1871 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1872 offs (&opP
->disp
)--;
1877 gen_to_words (words
, baseo
, (long) outro
);
1878 for (wordp
= words
; baseo
--; wordp
++)
1882 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1885 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1888 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1891 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1894 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1898 nextword
= get_num (&opP
->disp
, 80);
1901 && ! isvar (&opP
->disp
)
1904 opP
->disp
.exp
.X_op
= O_symbol
;
1905 #ifndef BFD_ASSEMBLER
1906 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1908 opP
->disp
.exp
.X_add_symbol
=
1909 section_symbol (absolute_section
);
1913 /* Force into index mode. Hope this works */
1915 /* We do the first bit for 32-bit displacements, and the
1916 second bit for 16 bit ones. It is possible that we
1917 should make the default be WORD instead of LONG, but
1918 I think that'd break GCC, so we put up with a little
1919 inefficiency for the sake of working output. */
1921 if (!issword (nextword
)
1922 || (isvar (&opP
->disp
)
1923 && ((opP
->disp
.size
== SIZE_UNSPEC
1924 && flag_short_refs
== 0
1925 && cpu_of_arch (current_architecture
) >= m68020
)
1926 || opP
->disp
.size
== SIZE_LONG
)))
1928 if (cpu_of_arch (current_architecture
) < m68020
)
1930 "displacement too large for this architecture; needs 68020 or higher";
1932 tmpreg
= 0x3B; /* 7.3 */
1934 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1935 if (isvar (&opP
->disp
))
1939 if (opP
->disp
.size
== SIZE_LONG
1941 /* If the displacement needs pic
1942 relocation it cannot be relaxed. */
1943 || opP
->disp
.pic_reloc
!= pic_none
1948 add_fix ('l', &opP
->disp
, 1, 2);
1952 add_frag (adds (&opP
->disp
),
1954 TAB (PCLEA
, SZ_UNDEF
));
1961 add_fix ('l', &opP
->disp
, 0, 0);
1966 addword (nextword
>> 16);
1971 tmpreg
= 0x3A; /* 7.2 */
1973 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1975 if (isvar (&opP
->disp
))
1979 add_fix ('w', &opP
->disp
, 1, 0);
1982 add_fix ('w', &opP
->disp
, 0, 0);
1992 baseo
= get_num (&opP
->disp
, 80);
1993 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1994 outro
= get_num (&opP
->odisp
, 80);
1995 /* Figure out the `addressing mode'.
1996 Also turn on the BASE_DISABLE bit, if needed. */
1997 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1999 tmpreg
= 0x3b; /* 7.3 */
2000 if (opP
->reg
== ZPC
)
2003 else if (opP
->reg
== 0)
2006 tmpreg
= 0x30; /* 6.garbage */
2008 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2011 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2014 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2016 siz1
= opP
->disp
.size
;
2017 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2018 siz2
= opP
->odisp
.size
;
2022 /* Index register stuff */
2023 if (opP
->index
.reg
!= 0
2024 && opP
->index
.reg
>= DATA
2025 && opP
->index
.reg
<= ADDR7
)
2027 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2029 if (opP
->index
.size
== SIZE_LONG
2030 || (opP
->index
.size
== SIZE_UNSPEC
2031 && m68k_index_width_default
== SIZE_LONG
))
2034 if ((opP
->index
.scale
!= 1
2035 && cpu_of_arch (current_architecture
) < m68020
)
2036 || (opP
->index
.scale
== 8
2037 && current_architecture
== mcf5200
))
2040 "scale factor invalid on this architecture; needs cpu32 or 68020 or higher";
2043 switch (opP
->index
.scale
)
2060 GET US OUT OF HERE! */
2062 /* Must be INDEX, with an index register. Address
2063 register cannot be ZERO-PC, and either :b was
2064 forced, or we know it will fit. For a 68000 or
2065 68010, force this mode anyways, because the
2066 larger modes aren't supported. */
2067 if (opP
->mode
== BASE
2068 && ((opP
->reg
>= ADDR0
2069 && opP
->reg
<= ADDR7
)
2072 if (siz1
== SIZE_BYTE
2073 || cpu_of_arch (current_architecture
) < m68020
2074 || (siz1
== SIZE_UNSPEC
2075 && ! isvar (&opP
->disp
)
2076 && issbyte (baseo
)))
2078 nextword
+= baseo
& 0xff;
2080 if (isvar (&opP
->disp
))
2082 /* Do a byte relocation. If it doesn't
2083 fit (possible on m68000) let the
2084 fixup processing complain later. */
2086 add_fix ('B', &opP
->disp
, 1, 1);
2088 add_fix ('B', &opP
->disp
, 0, 0);
2090 else if (siz1
!= SIZE_BYTE
)
2092 if (siz1
!= SIZE_UNSPEC
)
2093 as_warn ("Forcing byte displacement");
2094 if (! issbyte (baseo
))
2095 opP
->error
= "byte displacement out of range";
2100 else if (siz1
== SIZE_UNSPEC
2102 && isvar (&opP
->disp
)
2103 && subs (&opP
->disp
) == NULL
2105 /* If the displacement needs pic
2106 relocation it cannot be relaxed. */
2107 && opP
->disp
.pic_reloc
== pic_none
2111 /* The code in md_convert_frag_1 needs to be
2112 able to adjust nextword. Call frag_grow
2113 to ensure that we have enough space in
2114 the frag obstack to make all the bytes
2117 nextword
+= baseo
& 0xff;
2119 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2120 TAB (PCINDEX
, SZ_UNDEF
));
2128 nextword
|= 0x40; /* No index reg */
2129 if (opP
->index
.reg
>= ZDATA0
2130 && opP
->index
.reg
<= ZDATA7
)
2131 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2132 else if (opP
->index
.reg
>= ZADDR0
2133 || opP
->index
.reg
<= ZADDR7
)
2134 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2137 /* It isn't simple. */
2139 if (cpu_of_arch (current_architecture
) < m68020
)
2141 "invalid operand mode for this architecture; needs 68020 or higher";
2144 /* If the guy specified a width, we assume that it is
2145 wide enough. Maybe it isn't. If so, we lose. */
2149 if (isvar (&opP
->disp
)
2151 : ! issword (baseo
))
2156 else if (! isvar (&opP
->disp
) && baseo
== 0)
2165 as_warn (":b not permitted; defaulting to :w");
2175 /* Figure out innner displacement stuff */
2176 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2178 if (cpu_of_arch (current_architecture
) & cpu32
)
2179 opP
->error
= "invalid operand mode for this architecture; needs 68020 or higher";
2183 if (isvar (&opP
->odisp
)
2185 : ! issword (outro
))
2190 else if (! isvar (&opP
->odisp
) && outro
== 0)
2199 as_warn (":b not permitted; defaulting to :w");
2208 if (opP
->mode
== POST
2209 && (nextword
& 0x40) == 0)
2214 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2216 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2217 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2219 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2221 if (siz1
== SIZE_LONG
)
2222 addword (baseo
>> 16);
2223 if (siz1
!= SIZE_UNSPEC
)
2226 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2227 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2228 if (siz2
== SIZE_LONG
)
2229 addword (outro
>> 16);
2230 if (siz2
!= SIZE_UNSPEC
)
2236 nextword
= get_num (&opP
->disp
, 80);
2237 switch (opP
->disp
.size
)
2242 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2244 tmpreg
= 0x38; /* 7.0 */
2248 /* Don't generate pc relative code on 68010 and
2250 if (isvar (&opP
->disp
)
2251 && !subs (&opP
->disp
)
2252 && adds (&opP
->disp
)
2254 /* If the displacement needs pic relocation it
2255 cannot be relaxed. */
2256 && opP
->disp
.pic_reloc
== pic_none
2258 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2259 && HAVE_LONG_BRANCH(current_architecture
)
2261 && !strchr ("~%&$?", s
[0]))
2263 tmpreg
= 0x3A; /* 7.2 */
2264 add_frag (adds (&opP
->disp
),
2266 TAB (PCREL
, SZ_UNDEF
));
2269 /* Fall through into long */
2271 if (isvar (&opP
->disp
))
2272 add_fix ('l', &opP
->disp
, 0, 0);
2274 tmpreg
= 0x39;/* 7.1 mode */
2275 addword (nextword
>> 16);
2279 case SIZE_WORD
: /* Word */
2280 if (isvar (&opP
->disp
))
2281 add_fix ('w', &opP
->disp
, 0, 0);
2283 tmpreg
= 0x38;/* 7.0 mode */
2291 as_bad ("unknown/incorrect operand");
2294 install_gen_operand (s
[1], tmpreg
);
2300 { /* JF: I hate floating point! */
2315 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2316 if (isvar (&opP
->disp
))
2317 add_fix (s
[1], &opP
->disp
, 0, 0);
2320 case 'b': /* Danger: These do no check for
2321 certain types of overflow.
2323 if (!isbyte (tmpreg
))
2324 opP
->error
= "out of range";
2325 insop (tmpreg
, opcode
);
2326 if (isvar (&opP
->disp
))
2327 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2328 (opcode
->m_codenum
) * 2 + 1;
2331 if (!issbyte (tmpreg
))
2332 opP
->error
= "out of range";
2333 opcode
->m_opcode
|= tmpreg
;
2334 if (isvar (&opP
->disp
))
2335 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2338 if (!isword (tmpreg
))
2339 opP
->error
= "out of range";
2340 insop (tmpreg
, opcode
);
2341 if (isvar (&opP
->disp
))
2342 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2345 if (!issword (tmpreg
))
2346 opP
->error
= "out of range";
2347 insop (tmpreg
, opcode
);
2348 if (isvar (&opP
->disp
))
2349 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2352 /* Because of the way insop works, we put these two out
2354 insop (tmpreg
, opcode
);
2355 insop (tmpreg
>> 16, opcode
);
2356 if (isvar (&opP
->disp
))
2357 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2363 install_operand (s
[1], tmpreg
);
2374 install_operand (s
[1], opP
->reg
- ADDR
);
2378 tmpreg
= get_num (&opP
->disp
, 80);
2382 /* The pc_fix argument winds up in fx_pcrel_adjust,
2383 which is a char, and may therefore be unsigned. We
2384 want to pass -1, but we pass 64 instead, and convert
2385 back in md_pcrel_from. */
2386 add_fix ('B', &opP
->disp
, 1, 64);
2389 add_fix ('w', &opP
->disp
, 1, 0);
2394 if (!HAVE_LONG_BRANCH(current_architecture
))
2395 as_warn ("Can't use long branches on 68000/68010/5200");
2396 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2397 add_fix ('l', &opP
->disp
, 1, 0);
2402 if (subs (&opP
->disp
)) /* We can't relax it */
2406 /* If the displacement needs pic relocation it cannot be
2408 if (opP
->disp
.pic_reloc
!= pic_none
)
2412 /* This could either be a symbol, or an absolute
2413 address. No matter, the frag hacking will finger it
2414 out. Not quite: it can't switch from BRANCH to
2415 BCC68000 for the case where opnd is absolute (it
2416 needs to use the 68000 hack since no conditional abs
2418 if (( !HAVE_LONG_BRANCH(current_architecture
)
2419 || (0 == adds (&opP
->disp
)))
2420 && (the_ins
.opcode
[0] >= 0x6200)
2421 && (the_ins
.opcode
[0] <= 0x6f00))
2422 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2423 TAB (BCC68000
, SZ_UNDEF
));
2425 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2426 TAB (ABRANCH
, SZ_UNDEF
));
2429 if (isvar (&opP
->disp
))
2432 /* check for DBcc instruction */
2433 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2435 /* size varies if patch */
2436 /* needed for long form */
2437 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2438 TAB (DBCC
, SZ_UNDEF
));
2442 add_fix ('w', &opP
->disp
, 1, 0);
2446 case 'C': /* Fixed size LONG coproc branches */
2447 add_fix ('l', &opP
->disp
, 1, 0);
2451 case 'c': /* Var size Coprocesssor branches */
2452 if (subs (&opP
->disp
))
2454 add_fix ('l', &opP
->disp
, 1, 0);
2455 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2457 else if (adds (&opP
->disp
))
2458 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2459 TAB (FBRANCH
, SZ_UNDEF
));
2462 /* add_frag((symbolS *) 0, offs(&opP->disp),
2463 TAB(FBRANCH,SHORT)); */
2464 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2465 add_fix ('l', &opP
->disp
, 1, 0);
2475 case 'C': /* Ignore it */
2478 case 'd': /* JF this is a kludge */
2479 install_operand ('s', opP
->reg
- ADDR
);
2480 tmpreg
= get_num (&opP
->disp
, 80);
2481 if (!issword (tmpreg
))
2483 as_warn ("Expression out of range, using 0");
2490 install_operand (s
[1], opP
->reg
- DATA
);
2494 install_operand (s
[1], opP
->reg
- FP0
);
2498 tmpreg
= opP
->reg
- COP0
;
2499 install_operand (s
[1], tmpreg
);
2502 case 'J': /* JF foo */
2575 install_operand (s
[1], tmpreg
);
2579 tmpreg
= get_num (&opP
->disp
, 55);
2580 install_operand (s
[1], tmpreg
& 0x7f);
2587 if (tmpreg
& 0x7FF0000)
2588 as_bad ("Floating point register in register list");
2589 insop (reverse_16_bits (tmpreg
), opcode
);
2593 if (tmpreg
& 0x700FFFF)
2594 as_bad ("Wrong register in floating-point reglist");
2595 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2603 if (tmpreg
& 0x7FF0000)
2604 as_bad ("Floating point register in register list");
2605 insop (tmpreg
, opcode
);
2607 else if (s
[1] == '8')
2609 if (tmpreg
& 0x0FFFFFF)
2610 as_bad ("incorrect register in reglist");
2611 install_operand (s
[1], tmpreg
>> 24);
2615 if (tmpreg
& 0x700FFFF)
2616 as_bad ("wrong register in floating-point reglist");
2618 install_operand (s
[1], tmpreg
>> 16);
2623 install_operand (s
[1], get_num (&opP
->disp
, 60));
2627 tmpreg
= ((opP
->mode
== DREG
)
2628 ? 0x20 + opP
->reg
- DATA
2629 : (get_num (&opP
->disp
, 40) & 0x1F));
2630 install_operand (s
[1], tmpreg
);
2634 tmpreg
= get_num (&opP
->disp
, 10);
2637 install_operand (s
[1], tmpreg
);
2641 /* This depends on the fact that ADDR registers are eight
2642 more than their corresponding DATA regs, so the result
2643 will have the ADDR_REG bit set */
2644 install_operand (s
[1], opP
->reg
- DATA
);
2648 if (opP
->mode
== AINDR
)
2649 install_operand (s
[1], opP
->reg
- DATA
);
2651 install_operand (s
[1], opP
->index
.reg
- DATA
);
2655 if (opP
->reg
== FPI
)
2657 else if (opP
->reg
== FPS
)
2659 else if (opP
->reg
== FPC
)
2663 install_operand (s
[1], tmpreg
);
2666 case 'S': /* Ignore it */
2670 install_operand (s
[1], get_num (&opP
->disp
, 30));
2673 case 'U': /* Ignore it */
2692 as_fatal ("failed sanity check");
2693 } /* switch on cache token */
2694 install_operand (s
[1], tmpreg
);
2697 /* JF: These are out of order, I fear. */
2710 install_operand (s
[1], tmpreg
);
2736 install_operand (s
[1], tmpreg
);
2740 if (opP
->reg
== VAL
)
2759 install_operand (s
[1], tmpreg
);
2773 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2784 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2790 install_operand (s
[1], tmpreg
);
2793 know (opP
->reg
== PSR
);
2796 know (opP
->reg
== PCSR
);
2811 install_operand (s
[1], tmpreg
);
2814 tmpreg
= get_num (&opP
->disp
, 20);
2815 install_operand (s
[1], tmpreg
);
2817 case '_': /* used only for move16 absolute 32-bit address */
2818 tmpreg
= get_num (&opP
->disp
, 80);
2819 addword (tmpreg
>> 16);
2820 addword (tmpreg
& 0xFFFF);
2827 /* By the time whe get here (FINALLY) the_ins contains the complete
2828 instruction, ready to be emitted. . . */
2832 reverse_16_bits (in
)
2838 static int mask
[16] =
2840 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2841 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2843 for (n
= 0; n
< 16; n
++)
2846 out
|= mask
[15 - n
];
2849 } /* reverse_16_bits() */
2858 static int mask
[8] =
2860 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2863 for (n
= 0; n
< 8; n
++)
2869 } /* reverse_8_bits() */
2871 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2872 (that value is chosen in the frag_var call in md_assemble). TYPE
2873 is the subtype of the frag to be generated; its primary type is
2874 rs_machine_dependent.
2876 The TYPE parameter is also used by md_convert_frag_1 and
2877 md_estimate_size_before_relax. The appropriate type of fixup will
2878 be emitted by md_convert_frag_1.
2880 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2882 install_operand (mode
, val
)
2889 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2892 the_ins
.opcode
[0] |= val
<< 9;
2895 the_ins
.opcode
[1] |= val
<< 12;
2898 the_ins
.opcode
[1] |= val
<< 6;
2901 the_ins
.opcode
[1] |= val
;
2904 the_ins
.opcode
[2] |= val
<< 12;
2907 the_ins
.opcode
[2] |= val
<< 6;
2910 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2911 three words long! */
2913 the_ins
.opcode
[2] |= val
;
2916 the_ins
.opcode
[1] |= val
<< 7;
2919 the_ins
.opcode
[1] |= val
<< 10;
2923 the_ins
.opcode
[1] |= val
<< 5;
2928 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2931 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2934 the_ins
.opcode
[0] |= val
= 0xff;
2937 the_ins
.opcode
[0] |= val
<< 9;
2940 the_ins
.opcode
[1] |= val
;
2943 the_ins
.opcode
[1] |= val
;
2944 the_ins
.numo
++; /* What a hack */
2947 the_ins
.opcode
[1] |= val
<< 4;
2955 the_ins
.opcode
[0] |= (val
<< 6);
2958 the_ins
.opcode
[1] = (val
>> 16);
2959 the_ins
.opcode
[2] = val
& 0xffff;
2963 as_fatal ("failed sanity check.");
2965 } /* install_operand() */
2968 install_gen_operand (mode
, val
)
2975 the_ins
.opcode
[0] |= val
;
2978 /* This is a kludge!!! */
2979 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2988 the_ins
.opcode
[0] |= val
;
2990 /* more stuff goes here */
2992 as_fatal ("failed sanity check.");
2994 } /* install_gen_operand() */
2997 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2998 * then deal with the bitfield hack.
3002 crack_operand (str
, opP
)
3004 register struct m68k_op
*opP
;
3006 register int parens
;
3008 register char *beg_str
;
3016 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3022 else if (*str
== ')')
3026 opP
->error
= "Extra )";
3032 if (flag_mri
&& *str
== '\'')
3033 inquote
= ! inquote
;
3035 if (!*str
&& parens
)
3037 opP
->error
= "Missing )";
3042 if (m68k_ip_op (beg_str
, opP
) != 0)
3049 c
= *++str
; /* JF bitfield hack */
3054 as_bad ("Missing operand");
3059 /* This is the guts of the machine-dependent assembler. STR points to a
3060 machine dependent instruction. This function is supposed to emit
3061 the frags/bytes it assembles to.
3065 insert_reg (regname
, regnum
)
3072 #ifdef REGISTER_PREFIX
3073 if (!flag_reg_prefix_optional
)
3075 buf
[0] = REGISTER_PREFIX
;
3076 strcpy (buf
+ 1, regname
);
3081 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3082 &zero_address_frag
));
3084 for (i
= 0; regname
[i
]; i
++)
3085 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3088 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3089 &zero_address_frag
));
3098 static const struct init_entry init_table
[] =
3153 /* control registers */
3154 { "sfc", SFC
}, /* Source Function Code */
3156 { "dfc", DFC
}, /* Destination Function Code */
3158 { "cacr", CACR
}, /* Cache Control Register */
3159 { "caar", CAAR
}, /* Cache Address Register */
3161 { "usp", USP
}, /* User Stack Pointer */
3162 { "vbr", VBR
}, /* Vector Base Register */
3163 { "msp", MSP
}, /* Master Stack Pointer */
3164 { "isp", ISP
}, /* Interrupt Stack Pointer */
3166 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0 */
3167 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1 */
3168 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0 */
3169 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1 */
3171 /* 68ec040 versions of same */
3172 { "iacr0", ITT0
}, /* Instruction Access Control Register 0 */
3173 { "iacr1", ITT1
}, /* Instruction Access Control Register 0 */
3174 { "dacr0", DTT0
}, /* Data Access Control Register 0 */
3175 { "dacr1", DTT1
}, /* Data Access Control Register 0 */
3177 /* mcf5200 versions of same. The ColdFire programmer's reference
3178 manual indicated that the order is 2,3,0,1, but Ken Rose
3179 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3180 { "acr0", ITT0
}, /* Access Control Unit 0 */
3181 { "acr1", ITT1
}, /* Access Control Unit 1 */
3182 { "acr2", DTT0
}, /* Access Control Unit 2 */
3183 { "acr3", DTT1
}, /* Access Control Unit 3 */
3185 { "tc", TC
}, /* MMU Translation Control Register */
3188 { "mmusr", MMUSR
}, /* MMU Status Register */
3189 { "srp", SRP
}, /* User Root Pointer */
3190 { "urp", URP
}, /* Supervisor Root Pointer */
3195 { "rombar", ROMBAR
}, /* ROM Base Address Register */
3196 { "rambar0", RAMBAR0
}, /* ROM Base Address Register */
3197 { "rambar1", RAMBAR1
}, /* ROM Base Address Register */
3198 { "mbar", MBAR
}, /* Module Base Address Register */
3199 /* end of control registers */
3233 /* 68ec030 versions of same */
3236 /* 68ec030 access control unit, identical to 030 MMU status reg */
3239 /* Suppressed data and address registers. */
3264 for (i
= 0; init_table
[i
].name
; i
++)
3265 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3268 static int no_68851
, no_68881
;
3271 /* a.out machine type. Default to 68020. */
3272 int m68k_aout_machtype
= 2;
3284 int shorts_this_frag
;
3287 /* In MRI mode, the instruction and operands are separated by a
3288 space. Anything following the operands is a comment. The label
3289 has already been removed. */
3297 for (s
= str
; *s
!= '\0'; s
++)
3299 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3317 inquote
= ! inquote
;
3322 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3327 for (n
= 0; n
< the_ins
.numargs
; n
++)
3328 if (the_ins
.operands
[n
].error
)
3330 er
= the_ins
.operands
[n
].error
;
3336 as_bad ("%s -- statement `%s' ignored", er
, str
);
3340 /* If there is a current label, record that it marks an instruction. */
3341 if (current_label
!= NULL
)
3343 current_label
->text
= 1;
3344 current_label
= NULL
;
3347 if (the_ins
.nfrag
== 0)
3349 /* No frag hacking involved; just put it out */
3350 toP
= frag_more (2 * the_ins
.numo
);
3351 fromP
= &the_ins
.opcode
[0];
3352 for (m
= the_ins
.numo
; m
; --m
)
3354 md_number_to_chars (toP
, (long) (*fromP
), 2);
3358 /* put out symbol-dependent info */
3359 for (m
= 0; m
< the_ins
.nrel
; m
++)
3361 switch (the_ins
.reloc
[m
].wid
)
3379 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3380 the_ins
.reloc
[m
].wid
);
3383 fixP
= fix_new_exp (frag_now
,
3384 ((toP
- frag_now
->fr_literal
)
3385 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3387 &the_ins
.reloc
[m
].exp
,
3388 the_ins
.reloc
[m
].pcrel
,
3389 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3390 the_ins
.reloc
[m
].pic_reloc
));
3391 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3392 if (the_ins
.reloc
[m
].wid
== 'B')
3393 fixP
->fx_signed
= 1;
3398 /* There's some frag hacking */
3399 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3404 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3406 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3407 toP
= frag_more (wid
);
3409 shorts_this_frag
= 0;
3410 for (m
= wid
/ 2; m
; --m
)
3412 md_number_to_chars (toP
, (long) (*fromP
), 2);
3417 for (m
= 0; m
< the_ins
.nrel
; m
++)
3419 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3421 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3424 wid
= the_ins
.reloc
[m
].wid
;
3427 the_ins
.reloc
[m
].wid
= 0;
3428 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3430 fixP
= fix_new_exp (frag_now
,
3431 ((toP
- frag_now
->fr_literal
)
3432 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3434 &the_ins
.reloc
[m
].exp
,
3435 the_ins
.reloc
[m
].pcrel
,
3436 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3437 the_ins
.reloc
[m
].pic_reloc
));
3438 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3440 (void) frag_var (rs_machine_dependent
, 10, 0,
3441 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3442 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3444 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3445 shorts_this_frag
= 0;
3448 toP
= frag_more (n
* sizeof (short));
3451 md_number_to_chars (toP
, (long) (*fromP
), 2);
3457 for (m
= 0; m
< the_ins
.nrel
; m
++)
3461 wid
= the_ins
.reloc
[m
].wid
;
3464 the_ins
.reloc
[m
].wid
= 0;
3465 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3467 fixP
= fix_new_exp (frag_now
,
3468 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3469 - shorts_this_frag
* 2),
3471 &the_ins
.reloc
[m
].exp
,
3472 the_ins
.reloc
[m
].pcrel
,
3473 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3474 the_ins
.reloc
[m
].pic_reloc
));
3475 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3483 * md_begin -- set up hash tables with 68000 instructions.
3484 * similar to what the vax assembler does. ---phr
3486 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3487 a copy of it at runtime, adding in the information we want but isn't
3488 there. I think it'd be better to have an awk script hack the table
3489 at compile time. Or even just xstr the table and use it as-is. But
3490 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3493 register const struct m68k_opcode
*ins
;
3494 register struct m68k_incant
*hack
, *slak
;
3495 register const char *retval
= 0; /* empty string, or error msg text */
3496 register unsigned int i
;
3501 flag_reg_prefix_optional
= 1;
3503 if (! m68k_rel32_from_cmdline
)
3507 op_hash
= hash_new ();
3509 obstack_begin (&robyn
, 4000);
3510 for (i
= 0; i
< m68k_numopcodes
; i
++)
3512 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3515 ins
= &m68k_opcodes
[i
];
3516 /* We *could* ignore insns that don't match our arch here
3517 but just leaving them out of the hash. */
3518 slak
->m_operands
= ins
->args
;
3519 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3520 slak
->m_arch
= ins
->arch
;
3521 slak
->m_opcode
= ins
->opcode
;
3522 /* This is kludgey */
3523 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3524 if (i
+ 1 != m68k_numopcodes
3525 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3527 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3532 slak
= slak
->m_next
;
3536 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3538 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3541 for (i
= 0; i
< m68k_numaliases
; i
++)
3543 const char *name
= m68k_opcode_aliases
[i
].primary
;
3544 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3545 PTR val
= hash_find (op_hash
, name
);
3547 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3548 retval
= hash_insert (op_hash
, alias
, val
);
3550 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3553 /* In MRI mode, all unsized branches are variable sized. Normally,
3554 they are word sized. */
3557 static struct m68k_opcode_alias mri_aliases
[] =
3577 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3579 const char *name
= mri_aliases
[i
].primary
;
3580 const char *alias
= mri_aliases
[i
].alias
;
3581 PTR val
= hash_find (op_hash
, name
);
3583 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3584 retval
= hash_jam (op_hash
, alias
, val
);
3586 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3590 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3591 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3593 for (i
= 0; i
< sizeof (notend_table
); i
++)
3595 notend_table
[i
] = 0;
3596 alt_notend_table
[i
] = 0;
3598 notend_table
[','] = 1;
3599 notend_table
['{'] = 1;
3600 notend_table
['}'] = 1;
3601 alt_notend_table
['a'] = 1;
3602 alt_notend_table
['A'] = 1;
3603 alt_notend_table
['d'] = 1;
3604 alt_notend_table
['D'] = 1;
3605 alt_notend_table
['#'] = 1;
3606 alt_notend_table
['&'] = 1;
3607 alt_notend_table
['f'] = 1;
3608 alt_notend_table
['F'] = 1;
3609 #ifdef REGISTER_PREFIX
3610 alt_notend_table
[REGISTER_PREFIX
] = 1;
3613 /* We need to put '(' in alt_notend_table to handle
3614 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3616 alt_notend_table
['('] = 1;
3618 /* We need to put '@' in alt_notend_table to handle
3619 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3621 alt_notend_table
['@'] = 1;
3623 /* We need to put digits in alt_notend_table to handle
3624 bfextu %d0{24:1},%d0
3626 alt_notend_table
['0'] = 1;
3627 alt_notend_table
['1'] = 1;
3628 alt_notend_table
['2'] = 1;
3629 alt_notend_table
['3'] = 1;
3630 alt_notend_table
['4'] = 1;
3631 alt_notend_table
['5'] = 1;
3632 alt_notend_table
['6'] = 1;
3633 alt_notend_table
['7'] = 1;
3634 alt_notend_table
['8'] = 1;
3635 alt_notend_table
['9'] = 1;
3637 #ifndef MIT_SYNTAX_ONLY
3638 /* Insert pseudo ops, these have to go into the opcode table since
3639 gas expects pseudo ops to start with a dot */
3642 while (mote_pseudo_table
[n
].poc_name
)
3644 hack
= (struct m68k_incant
*)
3645 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3646 hash_insert (op_hash
,
3647 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3648 hack
->m_operands
= 0;
3658 record_alignment (text_section
, 2);
3659 record_alignment (data_section
, 2);
3660 record_alignment (bss_section
, 2);
3665 select_control_regs ()
3667 /* Note which set of "movec" control registers is available. */
3668 switch (cpu_of_arch (current_architecture
))
3671 control_regs
= m68000_control_regs
;
3674 control_regs
= m68010_control_regs
;
3678 control_regs
= m68020_control_regs
;
3681 control_regs
= m68040_control_regs
;
3684 control_regs
= m68060_control_regs
;
3687 control_regs
= cpu32_control_regs
;
3690 control_regs
= mcf5200_control_regs
;
3698 m68k_init_after_args ()
3700 if (cpu_of_arch (current_architecture
) == 0)
3703 const char *default_cpu
= TARGET_CPU
;
3705 if (*default_cpu
== 'm')
3707 for (i
= 0; i
< n_archs
; i
++)
3708 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3712 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3713 current_architecture
|= m68020
;
3716 current_architecture
|= archs
[i
].arch
;
3718 /* Permit m68881 specification with all cpus; those that can't work
3719 with a coprocessor could be doing emulation. */
3720 if (current_architecture
& m68851
)
3722 if (current_architecture
& m68040
)
3724 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3727 /* What other incompatibilities could we check for? */
3729 /* Toss in some default assumptions about coprocessors. */
3731 && (cpu_of_arch (current_architecture
)
3732 /* Can CPU32 have a 68881 coprocessor?? */
3733 & (m68020
| m68030
| cpu32
)))
3735 current_architecture
|= m68881
;
3738 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3739 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3741 current_architecture
|= m68851
;
3743 if (no_68881
&& (current_architecture
& m68881
))
3744 as_bad ("options for 68881 and no-68881 both given");
3745 if (no_68851
&& (current_architecture
& m68851
))
3746 as_bad ("options for 68851 and no-68851 both given");
3749 /* Work out the magic number. This isn't very general. */
3750 if (current_architecture
& m68000
)
3751 m68k_aout_machtype
= 0;
3752 else if (current_architecture
& m68010
)
3753 m68k_aout_machtype
= 1;
3754 else if (current_architecture
& m68020
)
3755 m68k_aout_machtype
= 2;
3757 m68k_aout_machtype
= 2;
3760 /* Note which set of "movec" control registers is available. */
3761 select_control_regs ();
3763 if (cpu_of_arch (current_architecture
) < m68020
)
3764 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3767 /* This is called when a label is defined. */
3770 m68k_frob_label (sym
)
3773 struct label_line
*n
;
3775 n
= (struct label_line
*) xmalloc (sizeof *n
);
3778 as_where (&n
->file
, &n
->line
);
3784 /* This is called when a value that is not an instruction is emitted. */
3787 m68k_flush_pending_output ()
3789 current_label
= NULL
;
3792 /* This is called at the end of the assembly, when the final value of
3793 the label is known. We warn if this is a text symbol aligned at an
3797 m68k_frob_symbol (sym
)
3800 if ((S_GET_VALUE (sym
) & 1) != 0)
3802 struct label_line
*l
;
3804 for (l
= labels
; l
!= NULL
; l
= l
->next
)
3806 if (l
->label
== sym
)
3809 as_warn_where (l
->file
, l
->line
,
3810 "text label `%s' aligned to odd boundary",
3818 /* This is called if we go in or out of MRI mode because of the .mri
3822 m68k_mri_mode_change (on
)
3827 if (! flag_reg_prefix_optional
)
3829 flag_reg_prefix_optional
= 1;
3830 #ifdef REGISTER_PREFIX
3835 if (! m68k_rel32_from_cmdline
)
3840 if (! reg_prefix_optional_seen
)
3842 #ifdef REGISTER_PREFIX_OPTIONAL
3843 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
3845 flag_reg_prefix_optional
= 0;
3847 #ifdef REGISTER_PREFIX
3852 if (! m68k_rel32_from_cmdline
)
3857 /* Equal to MAX_PRECISION in atof-ieee.c */
3858 #define MAX_LITTLENUMS 6
3860 /* Turn a string in input_line_pointer into a floating point constant
3861 of type type, and store the appropriate bytes in *litP. The number
3862 of LITTLENUMS emitted is stored in *sizeP . An error message is
3863 returned, or NULL on OK. */
3866 md_atof (type
, litP
, sizeP
)
3872 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3873 LITTLENUM_TYPE
*wordP
;
3905 return "Bad call to MD_ATOF()";
3907 t
= atof_ieee (input_line_pointer
, type
, words
);
3909 input_line_pointer
= t
;
3911 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3912 for (wordP
= words
; prec
--;)
3914 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3915 litP
+= sizeof (LITTLENUM_TYPE
);
3921 md_number_to_chars (buf
, val
, n
)
3926 number_to_chars_bigendian (buf
, val
, n
);
3930 md_apply_fix_2 (fixP
, val
)
3934 addressT upper_limit
;
3935 offsetT lower_limit
;
3937 /* This is unnecessary but it convinces the native rs6000 compiler
3938 to generate the code we want. */
3939 char *buf
= fixP
->fx_frag
->fr_literal
;
3940 buf
+= fixP
->fx_where
;
3941 /* end ibm compiler workaround */
3943 if (val
& 0x80000000)
3944 val
|= ~(addressT
)0x7fffffff;
3951 memset (buf
, 0, fixP
->fx_size
);
3952 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
3957 switch (fixP
->fx_size
)
3959 /* The cast to offsetT below are necessary to make code correct for
3960 machines where ints are smaller than offsetT */
3964 lower_limit
= - (offsetT
) 0x80;
3967 *buf
++ = (val
>> 8);
3969 upper_limit
= 0x7fff;
3970 lower_limit
= - (offsetT
) 0x8000;
3973 *buf
++ = (val
>> 24);
3974 *buf
++ = (val
>> 16);
3975 *buf
++ = (val
>> 8);
3977 upper_limit
= 0x7fffffff;
3978 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3981 BAD_CASE (fixP
->fx_size
);
3984 /* Fix up a negative reloc. */
3985 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
3987 fixP
->fx_addsy
= fixP
->fx_subsy
;
3988 fixP
->fx_subsy
= NULL
;
3992 /* For non-pc-relative values, it's conceivable we might get something
3993 like "0xff" for a byte field. So extend the upper part of the range
3994 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3995 so that we can do any range checking at all. */
3996 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
3997 upper_limit
= upper_limit
* 2 + 1;
3999 if ((addressT
) val
> upper_limit
4000 && (val
> 0 || val
< lower_limit
))
4001 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
4003 /* A one byte PC-relative reloc means a short branch. We can't use
4004 a short branch with a value of 0 or -1, because those indicate
4005 different opcodes (branches with longer offsets). */
4007 && fixP
->fx_size
== 1
4008 && (fixP
->fx_addsy
== NULL
4009 || S_IS_DEFINED (fixP
->fx_addsy
))
4010 && (val
== 0 || val
== -1))
4011 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
4014 #ifdef BFD_ASSEMBLER
4016 md_apply_fix (fixP
, valp
)
4020 md_apply_fix_2 (fixP
, (addressT
) *valp
);
4024 void md_apply_fix (fixP
, val
)
4028 md_apply_fix_2 (fixP
, (addressT
) val
);
4032 /* *fragP has been relaxed to its final size, and now needs to have
4033 the bytes inside it modified to conform to the new size There is UGLY
4037 md_convert_frag_1 (fragP
)
4038 register fragS
*fragP
;
4044 /* Address in object code of the displacement. */
4045 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4047 /* Address in gas core of the place to store the displacement. */
4048 /* This convinces the native rs6000 compiler to generate the code we
4050 register char *buffer_address
= fragP
->fr_literal
;
4051 buffer_address
+= fragP
->fr_fix
;
4052 /* end ibm compiler workaround */
4054 /* The displacement of the address, from current location. */
4055 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4056 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4058 #ifdef BFD_ASSEMBLER
4059 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
4062 switch (fragP
->fr_subtype
)
4064 case TAB (BCC68000
, BYTE
):
4065 case TAB (ABRANCH
, BYTE
):
4066 know (issbyte (disp
));
4068 as_bad ("short branch with zero offset: use :w");
4069 fragP
->fr_opcode
[1] = disp
;
4072 case TAB (DBCC
, SHORT
):
4073 know (issword (disp
));
4076 case TAB (BCC68000
, SHORT
):
4077 case TAB (ABRANCH
, SHORT
):
4078 know (issword (disp
));
4079 fragP
->fr_opcode
[1] = 0x00;
4082 case TAB (ABRANCH
, LONG
):
4083 if (!HAVE_LONG_BRANCH(current_architecture
))
4085 if (fragP
->fr_opcode
[0] == 0x61)
4088 fragP
->fr_opcode
[0] = 0x4E;
4089 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4103 else if (fragP
->fr_opcode
[0] == 0x60)
4105 fragP
->fr_opcode
[0] = 0x4E;
4106 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4107 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4108 fragP
->fr_offset
, 0, NO_RELOC
);
4114 as_bad ("Long branch offset not supported.");
4119 fragP
->fr_opcode
[1] = (char) 0xff;
4123 case TAB (BCC68000
, LONG
):
4124 /* only Bcc 68000 instructions can come here */
4125 /* change bcc into b!cc/jmp absl long */
4126 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4127 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4129 /* JF: these used to be fr_opcode[2,3], but they may be in a
4130 different frag, in which case refering to them is a no-no.
4131 Only fr_opcode[0,1] are guaranteed to work. */
4132 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4133 *buffer_address
++ = (char) 0xf9;
4134 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4135 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4136 fragP
->fr_offset
, 0, NO_RELOC
);
4140 case TAB (DBCC
, LONG
):
4141 /* only DBcc 68000 instructions can come here */
4142 /* change dbcc into dbcc/jmp absl long */
4143 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4144 *buffer_address
++ = 0x00; /* branch offset = 4 */
4145 *buffer_address
++ = 0x04;
4146 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4147 *buffer_address
++ = 0x06;
4148 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4149 *buffer_address
++ = (char) 0xf9;
4151 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4152 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4153 fragP
->fr_offset
, 0, NO_RELOC
);
4157 case TAB (FBRANCH
, SHORT
):
4158 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4161 case TAB (FBRANCH
, LONG
):
4162 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4165 case TAB (PCREL
, SHORT
):
4168 case TAB (PCREL
, LONG
):
4169 /* The thing to do here is force it to ABSOLUTE LONG, since
4170 PCREL is really trying to shorten an ABSOLUTE address anyway */
4171 /* JF FOO This code has not been tested */
4172 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4174 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4175 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
4176 (unsigned) fragP
->fr_opcode
[0],
4177 (unsigned long) fragP
->fr_address
);
4178 fragP
->fr_opcode
[1] &= ~0x3F;
4179 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4183 case TAB (PCLEA
, SHORT
):
4184 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4185 fragP
->fr_offset
, 1, NO_RELOC
);
4186 fragP
->fr_opcode
[1] &= ~0x3F;
4187 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4190 case TAB (PCLEA
, LONG
):
4191 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4192 fragP
->fr_offset
, 1, NO_RELOC
);
4193 fixP
->fx_pcrel_adjust
= 2;
4194 /* Already set to mode 7.3; this indicates: PC indirect with
4195 suppressed index, 32-bit displacement. */
4196 *buffer_address
++ = 0x01;
4197 *buffer_address
++ = 0x70;
4202 case TAB (PCINDEX
, BYTE
):
4204 if (!issbyte (disp
))
4206 as_bad ("displacement doesn't fit in one byte");
4209 assert (fragP
->fr_fix
>= 2);
4210 buffer_address
[-2] &= ~1;
4211 buffer_address
[-1] = disp
;
4214 case TAB (PCINDEX
, SHORT
):
4216 assert (issword (disp
));
4217 assert (fragP
->fr_fix
>= 2);
4218 buffer_address
[-2] |= 0x1;
4219 buffer_address
[-1] = 0x20;
4220 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4221 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4223 fixP
->fx_pcrel_adjust
= 2;
4226 case TAB (PCINDEX
, LONG
):
4228 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4229 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4231 fixP
->fx_pcrel_adjust
= 2;
4232 assert (fragP
->fr_fix
>= 2);
4233 buffer_address
[-2] |= 0x1;
4234 buffer_address
[-1] = 0x30;
4241 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4242 fragP
->fr_fix
+= ext
;
4246 #ifndef BFD_ASSEMBLER
4249 md_convert_frag (headers
, sec
, fragP
)
4250 object_headers
*headers
;
4254 md_convert_frag_1 (fragP
);
4260 md_convert_frag (abfd
, sec
, fragP
)
4265 md_convert_frag_1 (fragP
);
4269 /* Force truly undefined symbols to their maximum size, and generally set up
4270 the frag list to be relaxed
4273 md_estimate_size_before_relax (fragP
, segment
)
4274 register fragS
*fragP
;
4278 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4280 old_fix
= fragP
->fr_fix
;
4282 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4283 switch (fragP
->fr_subtype
)
4286 case TAB (ABRANCH
, SZ_UNDEF
):
4288 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4289 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4291 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4294 else if ((fragP
->fr_symbol
== 0) || !HAVE_LONG_BRANCH(current_architecture
))
4296 /* On 68000, or for absolute value, switch to abs long */
4297 /* FIXME, we should check abs val, pick short or long */
4298 if (fragP
->fr_opcode
[0] == 0x61)
4300 fragP
->fr_opcode
[0] = 0x4E;
4301 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4302 fix_new (fragP
, fragP
->fr_fix
, 4,
4303 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4307 else if (fragP
->fr_opcode
[0] == 0x60)
4309 fragP
->fr_opcode
[0] = 0x4E;
4310 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4311 fix_new (fragP
, fragP
->fr_fix
, 4,
4312 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4318 as_warn ("Long branch offset to extern symbol not supported.");
4322 { /* Symbol is still undefined. Make it simple */
4323 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4324 fragP
->fr_offset
, 1, NO_RELOC
);
4326 fragP
->fr_opcode
[1] = (char) 0xff;
4332 } /* case TAB(ABRANCH,SZ_UNDEF) */
4334 case TAB (FBRANCH
, SZ_UNDEF
):
4336 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
4338 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4343 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4344 fragP
->fr_offset
, 1, NO_RELOC
);
4346 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4350 } /* TAB(FBRANCH,SZ_UNDEF) */
4352 case TAB (PCREL
, SZ_UNDEF
):
4354 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4356 || cpu_of_arch (current_architecture
) < m68020
)
4358 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4363 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4367 } /* TAB(PCREL,SZ_UNDEF) */
4369 case TAB (BCC68000
, SZ_UNDEF
):
4371 if ((fragP
->fr_symbol
!= NULL
)
4372 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4374 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4377 /* only Bcc 68000 instructions can come here */
4378 /* change bcc into b!cc/jmp absl long */
4379 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4380 if (flag_short_refs
)
4382 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4383 /* JF: these were fr_opcode[2,3] */
4384 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4385 buffer_address
[1] = (char) 0xf8;
4386 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4387 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4388 fragP
->fr_offset
, 0, NO_RELOC
);
4393 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4394 /* JF: these were fr_opcode[2,3] */
4395 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4396 buffer_address
[1] = (char) 0xf9;
4397 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4398 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4399 fragP
->fr_offset
, 0, NO_RELOC
);
4404 } /* case TAB(BCC68000,SZ_UNDEF) */
4406 case TAB (DBCC
, SZ_UNDEF
):
4408 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4410 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4414 /* only DBcc 68000 instructions can come here */
4415 /* change dbcc into dbcc/jmp absl long */
4416 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4417 buffer_address
[0] = 0x00; /* branch offset = 4 */
4418 buffer_address
[1] = 0x04;
4419 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4421 if (flag_short_refs
)
4423 /* JF: these were fr_opcode[5-7] */
4424 buffer_address
[3] = 0x04; /* plus 4 */
4425 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4426 buffer_address
[5] = (char) 0xf8;
4427 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4428 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4429 fragP
->fr_offset
, 0, NO_RELOC
);
4434 /* JF: these were fr_opcode[5-7] */
4435 buffer_address
[3] = 0x06; /* Plus 6 */
4436 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4437 buffer_address
[5] = (char) 0xf9;
4438 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4439 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4440 fragP
->fr_offset
, 0, NO_RELOC
);
4446 } /* case TAB(DBCC,SZ_UNDEF) */
4448 case TAB (PCLEA
, SZ_UNDEF
):
4450 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4452 || cpu_of_arch (current_architecture
) < m68020
)
4454 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4459 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4463 } /* TAB(PCLEA,SZ_UNDEF) */
4465 case TAB (PCINDEX
, SZ_UNDEF
):
4466 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4467 || cpu_of_arch (current_architecture
) < m68020
)
4469 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4473 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4482 /* now that SZ_UNDEF are taken care of, check others */
4483 switch (fragP
->fr_subtype
)
4485 case TAB (BCC68000
, BYTE
):
4486 case TAB (ABRANCH
, BYTE
):
4487 /* We can't do a short jump to the next instruction, so in that
4488 case we force word mode. At this point S_GET_VALUE should
4489 return the offset of the symbol within its frag. If the
4490 symbol is at the start of a frag, and it is the next frag
4491 with any data in it (usually this is just the next frag, but
4492 assembler listings may introduce empty frags), we must use
4494 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0)
4498 for (l
= fragP
->fr_next
;
4499 l
!= fragP
->fr_symbol
->sy_frag
;
4501 if (l
->fr_fix
+ l
->fr_var
!= 0)
4503 if (l
== fragP
->fr_symbol
->sy_frag
)
4505 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4513 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4516 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4517 /* the bit-field entries in the relocation_info struct plays hell
4518 with the byte-order problems of cross-assembly. So as a hack,
4519 I added this mach. dependent ri twiddler. Ugly, but it gets
4521 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4522 are symbolnum, most sig. byte first. Last byte is broken up with
4523 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4524 nibble as nuthin. (on Sun 3 at least) */
4525 /* Translate the internal relocation information into target-specific
4529 md_ri_to_chars (the_bytes
, ri
)
4531 struct reloc_info_generic
*ri
;
4534 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4535 /* now the fun stuff */
4536 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4537 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4538 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4539 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4540 ((ri
->r_extern
<< 4) & 0x10));
4543 #endif /* comment */
4545 #ifndef BFD_ASSEMBLER
4547 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4550 relax_addressT segment_address_in_file
;
4553 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4554 * Out: GNU LD relocation length code: 0, 1, or 2.
4557 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4560 know (fixP
->fx_addsy
!= NULL
);
4562 md_number_to_chars (where
,
4563 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4566 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4567 ? S_GET_TYPE (fixP
->fx_addsy
)
4568 : fixP
->fx_addsy
->sy_number
);
4570 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4571 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4572 where
[6] = r_symbolnum
& 0x0ff;
4573 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4574 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4578 #endif /* OBJ_AOUT or OBJ_BOUT */
4580 #ifndef WORKING_DOT_WORD
4581 CONST
int md_short_jump_size
= 4;
4582 CONST
int md_long_jump_size
= 6;
4585 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4587 addressT from_addr
, to_addr
;
4593 offset
= to_addr
- (from_addr
+ 2);
4595 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4596 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4600 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4602 addressT from_addr
, to_addr
;
4608 if (!HAVE_LONG_BRANCH(current_architecture
))
4610 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4611 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4612 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4613 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4618 offset
= to_addr
- (from_addr
+ 2);
4619 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4620 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4626 /* Different values of OK tell what its OK to return. Things that
4627 aren't OK are an error (what a shock, no?)
4630 10: Absolute 1:8 only
4631 20: Absolute 0:7 only
4632 30: absolute 0:15 only
4633 40: Absolute 0:31 only
4634 50: absolute 0:127 only
4635 55: absolute -64:63 only
4636 60: absolute -128:127 only
4637 70: absolute 0:4095 only
4644 struct m68k_exp
*exp
;
4647 if (exp
->exp
.X_op
== O_absent
)
4649 /* Do the same thing the VAX asm does */
4650 op (exp
) = O_constant
;
4656 as_warn ("expression out of range: defaulting to 1");
4660 else if (exp
->exp
.X_op
== O_constant
)
4665 if (offs (exp
) < 1 || offs (exp
) > 8)
4667 as_warn ("expression out of range: defaulting to 1");
4672 if (offs (exp
) < 0 || offs (exp
) > 7)
4676 if (offs (exp
) < 0 || offs (exp
) > 15)
4680 if (offs (exp
) < 0 || offs (exp
) > 32)
4684 if (offs (exp
) < 0 || offs (exp
) > 127)
4688 if (offs (exp
) < -64 || offs (exp
) > 63)
4692 if (offs (exp
) < -128 || offs (exp
) > 127)
4696 if (offs (exp
) < 0 || offs (exp
) > 4095)
4699 as_warn ("expression out of range: defaulting to 0");
4707 else if (exp
->exp
.X_op
== O_big
)
4709 if (offs (exp
) <= 0 /* flonum */
4710 && (ok
== 80 /* no bignums */
4711 || (ok
> 10 /* small-int ranges including 0 ok */
4712 /* If we have a flonum zero, a zero integer should
4713 do as well (e.g., in moveq). */
4714 && generic_floating_point_number
.exponent
== 0
4715 && generic_floating_point_number
.low
[0] == 0)))
4717 /* HACK! Turn it into a long */
4718 LITTLENUM_TYPE words
[6];
4720 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4721 op (exp
) = O_constant
;
4724 offs (exp
) = words
[1] | (words
[0] << 16);
4728 op (exp
) = O_constant
;
4731 offs (exp
) = (ok
== 10) ? 1 : 0;
4732 as_warn ("Can't deal with expression; defaulting to %ld",
4738 if (ok
>= 10 && ok
<= 70)
4740 op (exp
) = O_constant
;
4743 offs (exp
) = (ok
== 10) ? 1 : 0;
4744 as_warn ("Can't deal with expression; defaulting to %ld",
4749 if (exp
->size
!= SIZE_UNSPEC
)
4757 if (!isbyte (offs (exp
)))
4758 as_warn ("expression doesn't fit in BYTE");
4761 if (!isword (offs (exp
)))
4762 as_warn ("expression doesn't fit in WORD");
4770 /* These are the back-ends for the various machine dependent pseudo-ops. */
4771 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4777 subseg_set (data_section
, 1);
4778 demand_empty_rest_of_line ();
4785 subseg_set (data_section
, 2);
4786 demand_empty_rest_of_line ();
4793 /* We don't support putting frags in the BSS segment, we fake it
4794 by marking in_bss, then looking at s_skip for clues. */
4796 subseg_set (bss_section
, 0);
4797 demand_empty_rest_of_line ();
4805 register long temp_fill
;
4807 temp
= 1; /* JF should be 2? */
4808 temp_fill
= get_absolute_expression ();
4809 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4810 frag_align (temp
, (int) temp_fill
, 0);
4811 demand_empty_rest_of_line ();
4812 record_alignment (now_seg
, temp
);
4819 demand_empty_rest_of_line ();
4822 /* Pseudo-ops handled for MRI compatibility. */
4824 /* This function returns non-zero if the argument is a conditional
4825 pseudo-op. This is called when checking whether a pending
4826 alignment is needed. */
4829 m68k_conditional_pseudoop (pop
)
4832 return (pop
->poc_handler
== s_mri_if
4833 || pop
->poc_handler
== s_mri_else
);
4836 /* Handle an MRI style chip specification. */
4845 s
= input_line_pointer
;
4846 c
= get_symbol_end ();
4847 for (i
= 0; i
< n_archs
; i
++)
4848 if (strcasecmp (s
, archs
[i
].name
) == 0)
4852 as_bad ("%s: unrecognized processor name", s
);
4853 *input_line_pointer
= c
;
4854 ignore_rest_of_line ();
4857 *input_line_pointer
= c
;
4859 if (*input_line_pointer
== '/')
4860 current_architecture
= 0;
4862 current_architecture
&= m68881
| m68851
;
4863 current_architecture
|= archs
[i
].arch
;
4865 while (*input_line_pointer
== '/')
4867 ++input_line_pointer
;
4868 s
= input_line_pointer
;
4869 c
= get_symbol_end ();
4870 if (strcmp (s
, "68881") == 0)
4871 current_architecture
|= m68881
;
4872 else if (strcmp (s
, "68851") == 0)
4873 current_architecture
|= m68851
;
4874 *input_line_pointer
= c
;
4877 /* Update info about available control registers. */
4878 select_control_regs ();
4881 /* The MRI CHIP pseudo-op. */
4891 stop
= mri_comment_field (&stopc
);
4894 mri_comment_end (stop
, stopc
);
4895 demand_empty_rest_of_line ();
4898 /* The MRI FOPT pseudo-op. */
4906 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4910 input_line_pointer
+= 3;
4911 temp
= get_absolute_expression ();
4912 if (temp
< 0 || temp
> 7)
4913 as_bad ("bad coprocessor id");
4915 m68k_float_copnum
= COP0
+ temp
;
4919 as_bad ("unrecognized fopt option");
4920 ignore_rest_of_line ();
4924 demand_empty_rest_of_line ();
4927 /* The structure used to handle the MRI OPT pseudo-op. */
4931 /* The name of the option. */
4934 /* If this is not NULL, just call this function. The first argument
4935 is the ARG field of this structure, the second argument is
4936 whether the option was negated. */
4937 void (*pfn
) PARAMS ((int arg
, int on
));
4939 /* If this is not NULL, and the PFN field is NULL, set the variable
4940 this points to. Set it to the ARG field if the option was not
4941 negated, and the NOTARG field otherwise. */
4944 /* The value to pass to PFN or to assign to *PVAR. */
4947 /* The value to assign to *PVAR if the option is negated. If PFN is
4948 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4949 the option may not be negated. */
4953 /* The table used to handle the MRI OPT pseudo-op. */
4955 static void skip_to_comma
PARAMS ((int, int));
4956 static void opt_nest
PARAMS ((int, int));
4957 static void opt_chip
PARAMS ((int, int));
4958 static void opt_list
PARAMS ((int, int));
4959 static void opt_list_symbols
PARAMS ((int, int));
4961 static const struct opt_action opt_table
[] =
4963 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
4965 /* We do relaxing, so there is little use for these options. */
4966 { "b", 0, 0, 0, 0 },
4967 { "brs", 0, 0, 0, 0 },
4968 { "brb", 0, 0, 0, 0 },
4969 { "brl", 0, 0, 0, 0 },
4970 { "brw", 0, 0, 0, 0 },
4972 { "c", 0, 0, 0, 0 },
4973 { "cex", 0, 0, 0, 0 },
4974 { "case", 0, &symbols_case_sensitive
, 1, 0 },
4975 { "cl", 0, 0, 0, 0 },
4976 { "cre", 0, 0, 0, 0 },
4977 { "d", 0, &flag_keep_locals
, 1, 0 },
4978 { "e", 0, 0, 0, 0 },
4979 { "f", 0, &flag_short_refs
, 1, 0 },
4980 { "frs", 0, &flag_short_refs
, 1, 0 },
4981 { "frl", 0, &flag_short_refs
, 0, 1 },
4982 { "g", 0, 0, 0, 0 },
4983 { "i", 0, 0, 0, 0 },
4984 { "m", 0, 0, 0, 0 },
4985 { "mex", 0, 0, 0, 0 },
4986 { "mc", 0, 0, 0, 0 },
4987 { "md", 0, 0, 0, 0 },
4988 { "nest", opt_nest
, 0, 0, 0 },
4989 { "next", skip_to_comma
, 0, 0, 0 },
4990 { "o", 0, 0, 0, 0 },
4991 { "old", 0, 0, 0, 0 },
4992 { "op", skip_to_comma
, 0, 0, 0 },
4993 { "pco", 0, 0, 0, 0 },
4994 { "p", opt_chip
, 0, 0, 0 },
4995 { "pcr", 0, 0, 0, 0 },
4996 { "pcs", 0, 0, 0, 0 },
4997 { "r", 0, 0, 0, 0 },
4998 { "quick", 0, &m68k_quick
, 1, 0 },
4999 { "rel32", 0, &m68k_rel32
, 1, 0 },
5000 { "s", opt_list
, 0, 0, 0 },
5001 { "t", opt_list_symbols
, 0, 0, 0 },
5002 { "w", 0, &flag_no_warnings
, 0, 1 },
5006 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
5008 /* The MRI OPT pseudo-op. */
5020 const struct opt_action
*o
;
5025 if (*input_line_pointer
== '-')
5027 ++input_line_pointer
;
5030 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5032 input_line_pointer
+= 2;
5036 s
= input_line_pointer
;
5037 c
= get_symbol_end ();
5039 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5041 if (strcasecmp (s
, o
->name
) == 0)
5045 /* Restore input_line_pointer now in case the option
5047 *input_line_pointer
= c
;
5048 (*o
->pfn
) (o
->arg
, t
);
5050 else if (o
->pvar
!= NULL
)
5052 if (! t
&& o
->arg
== o
->notarg
)
5053 as_bad ("option `%s' may not be negated", s
);
5054 *input_line_pointer
= c
;
5055 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5058 *input_line_pointer
= c
;
5064 as_bad ("option `%s' not recognized", s
);
5065 *input_line_pointer
= c
;
5068 while (*input_line_pointer
++ == ',');
5070 /* Move back to terminating character. */
5071 --input_line_pointer
;
5072 demand_empty_rest_of_line ();
5075 /* Skip ahead to a comma. This is used for OPT options which we do
5076 not suppor tand which take arguments. */
5079 skip_to_comma (arg
, on
)
5083 while (*input_line_pointer
!= ','
5084 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5085 ++input_line_pointer
;
5088 /* Handle the OPT NEST=depth option. */
5095 if (*input_line_pointer
!= '=')
5097 as_bad ("bad format of OPT NEST=depth");
5101 ++input_line_pointer
;
5102 max_macro_nest
= get_absolute_expression ();
5105 /* Handle the OPT P=chip option. */
5112 if (*input_line_pointer
!= '=')
5114 /* This is just OPT P, which we do not support. */
5118 ++input_line_pointer
;
5122 /* Handle the OPT S option. */
5132 /* Handle the OPT T option. */
5135 opt_list_symbols (arg
, on
)
5140 listing
|= LISTING_SYMBOLS
;
5142 listing
&=~ LISTING_SYMBOLS
;
5145 /* Handle the MRI REG pseudo-op. */
5158 if (line_label
== NULL
)
5160 as_bad ("missing label");
5161 ignore_rest_of_line ();
5166 stop
= mri_comment_field (&stopc
);
5170 s
= input_line_pointer
;
5171 while (isalnum ((unsigned char) *input_line_pointer
)
5172 #ifdef REGISTER_PREFIX
5173 || *input_line_pointer
== REGISTER_PREFIX
5175 || *input_line_pointer
== '/'
5176 || *input_line_pointer
== '-')
5177 ++input_line_pointer
;
5178 c
= *input_line_pointer
;
5179 *input_line_pointer
= '\0';
5181 if (m68k_ip_op (s
, &rop
) != 0)
5183 if (rop
.error
== NULL
)
5184 as_bad ("bad register list");
5186 as_bad ("bad register list: %s", rop
.error
);
5187 *input_line_pointer
= c
;
5188 ignore_rest_of_line ();
5192 *input_line_pointer
= c
;
5194 if (rop
.mode
== REGLST
)
5196 else if (rop
.mode
== DREG
)
5197 mask
= 1 << (rop
.reg
- DATA0
);
5198 else if (rop
.mode
== AREG
)
5199 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5200 else if (rop
.mode
== FPREG
)
5201 mask
= 1 << (rop
.reg
- FP0
+ 16);
5202 else if (rop
.mode
== CONTROL
5205 else if (rop
.mode
== CONTROL
5208 else if (rop
.mode
== CONTROL
5213 as_bad ("bad register list");
5214 ignore_rest_of_line ();
5218 S_SET_SEGMENT (line_label
, absolute_section
);
5219 S_SET_VALUE (line_label
, mask
);
5220 line_label
->sy_frag
= &zero_address_frag
;
5223 mri_comment_end (stop
, stopc
);
5225 demand_empty_rest_of_line ();
5228 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5232 struct save_opts
*next
;
5234 int symbols_case_sensitive
;
5242 /* FIXME: We don't save OPT S. */
5245 /* This variable holds the stack of saved options. */
5247 static struct save_opts
*save_stack
;
5249 /* The MRI SAVE pseudo-op. */
5255 struct save_opts
*s
;
5257 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5258 s
->abspcadd
= m68k_abspcadd
;
5259 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5260 s
->keep_locals
= flag_keep_locals
;
5261 s
->short_refs
= flag_short_refs
;
5262 s
->architecture
= current_architecture
;
5263 s
->quick
= m68k_quick
;
5264 s
->rel32
= m68k_rel32
;
5265 s
->listing
= listing
;
5266 s
->no_warnings
= flag_no_warnings
;
5268 s
->next
= save_stack
;
5271 demand_empty_rest_of_line ();
5274 /* The MRI RESTORE pseudo-op. */
5280 struct save_opts
*s
;
5282 if (save_stack
== NULL
)
5284 as_bad ("restore without save");
5285 ignore_rest_of_line ();
5290 save_stack
= s
->next
;
5292 m68k_abspcadd
= s
->abspcadd
;
5293 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5294 flag_keep_locals
= s
->keep_locals
;
5295 flag_short_refs
= s
->short_refs
;
5296 current_architecture
= s
->architecture
;
5297 m68k_quick
= s
->quick
;
5298 m68k_rel32
= s
->rel32
;
5299 listing
= s
->listing
;
5300 flag_no_warnings
= s
->no_warnings
;
5304 demand_empty_rest_of_line ();
5307 /* Types of MRI structured control directives. */
5309 enum mri_control_type
5317 /* This structure is used to stack the MRI structured control
5320 struct mri_control_info
5322 /* The directive within which this one is enclosed. */
5323 struct mri_control_info
*outer
;
5325 /* The type of directive. */
5326 enum mri_control_type type
;
5328 /* Whether an ELSE has been in an IF. */
5331 /* The add or sub statement at the end of a FOR. */
5334 /* The label of the top of a FOR or REPEAT loop. */
5337 /* The label to jump to for the next iteration, or the else
5338 expression of a conditional. */
5341 /* The label to jump to to break out of the loop, or the label past
5342 the end of a conditional. */
5346 /* The stack of MRI structured control directives. */
5348 static struct mri_control_info
*mri_control_stack
;
5350 /* The current MRI structured control directive index number, used to
5351 generate label names. */
5353 static int mri_control_index
;
5355 /* Some function prototypes. */
5357 static char *mri_control_label
PARAMS ((void));
5358 static struct mri_control_info
*push_mri_control
5359 PARAMS ((enum mri_control_type
));
5360 static void pop_mri_control
PARAMS ((void));
5361 static int parse_mri_condition
PARAMS ((int *));
5362 static int parse_mri_control_operand
5363 PARAMS ((int *, char **, char **, char **, char **));
5364 static int swap_mri_condition
PARAMS ((int));
5365 static int reverse_mri_condition
PARAMS ((int));
5366 static void build_mri_control_operand
5367 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5368 const char *, int));
5369 static void parse_mri_control_expression
5370 PARAMS ((char *, int, const char *, const char *, int));
5372 /* Generate a new MRI label structured control directive label name. */
5375 mri_control_label ()
5379 n
= (char *) xmalloc (20);
5380 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5381 ++mri_control_index
;
5385 /* Create a new MRI structured control directive. */
5387 static struct mri_control_info
*
5388 push_mri_control (type
)
5389 enum mri_control_type type
;
5391 struct mri_control_info
*n
;
5393 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5397 if (type
== mri_if
|| type
== mri_while
)
5400 n
->top
= mri_control_label ();
5401 n
->next
= mri_control_label ();
5402 n
->bottom
= mri_control_label ();
5404 n
->outer
= mri_control_stack
;
5405 mri_control_stack
= n
;
5410 /* Pop off the stack of MRI structured control directives. */
5415 struct mri_control_info
*n
;
5417 n
= mri_control_stack
;
5418 mri_control_stack
= n
->outer
;
5426 /* Recognize a condition code in an MRI structured control expression. */
5429 parse_mri_condition (pcc
)
5434 know (*input_line_pointer
== '<');
5436 ++input_line_pointer
;
5437 c1
= *input_line_pointer
++;
5438 c2
= *input_line_pointer
++;
5440 if (*input_line_pointer
!= '>')
5442 as_bad ("syntax error in structured control directive");
5446 ++input_line_pointer
;
5454 *pcc
= (c1
<< 8) | c2
;
5459 /* Parse a single operand in an MRI structured control expression. */
5462 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5479 if (*input_line_pointer
== '<')
5481 /* It's just a condition code. */
5482 return parse_mri_condition (pcc
);
5485 /* Look ahead for the condition code. */
5486 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5488 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5493 as_bad ("missing condition code in structured control directive");
5497 *leftstart
= input_line_pointer
;
5499 if (*leftstop
> *leftstart
5500 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5503 input_line_pointer
= s
;
5504 if (! parse_mri_condition (pcc
))
5507 /* Look ahead for AND or OR or end of line. */
5508 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5510 if ((strncasecmp (s
, "AND", 3) == 0
5511 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5512 || (strncasecmp (s
, "OR", 2) == 0
5513 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5517 *rightstart
= input_line_pointer
;
5519 if (*rightstop
> *rightstart
5520 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5523 input_line_pointer
= s
;
5528 #define MCC(b1, b2) (((b1) << 8) | (b2))
5530 /* Swap the sense of a condition. This changes the condition so that
5531 it generates the same result when the operands are swapped. */
5534 swap_mri_condition (cc
)
5539 case MCC ('h', 'i'): return MCC ('c', 's');
5540 case MCC ('l', 's'): return MCC ('c', 'c');
5541 case MCC ('c', 'c'): return MCC ('l', 's');
5542 case MCC ('c', 's'): return MCC ('h', 'i');
5543 case MCC ('p', 'l'): return MCC ('m', 'i');
5544 case MCC ('m', 'i'): return MCC ('p', 'l');
5545 case MCC ('g', 'e'): return MCC ('l', 'e');
5546 case MCC ('l', 't'): return MCC ('g', 't');
5547 case MCC ('g', 't'): return MCC ('l', 't');
5548 case MCC ('l', 'e'): return MCC ('g', 'e');
5553 /* Reverse the sense of a condition. */
5556 reverse_mri_condition (cc
)
5561 case MCC ('h', 'i'): return MCC ('l', 's');
5562 case MCC ('l', 's'): return MCC ('h', 'i');
5563 case MCC ('c', 'c'): return MCC ('c', 's');
5564 case MCC ('c', 's'): return MCC ('c', 'c');
5565 case MCC ('n', 'e'): return MCC ('e', 'q');
5566 case MCC ('e', 'q'): return MCC ('n', 'e');
5567 case MCC ('v', 'c'): return MCC ('v', 's');
5568 case MCC ('v', 's'): return MCC ('v', 'c');
5569 case MCC ('p', 'l'): return MCC ('m', 'i');
5570 case MCC ('m', 'i'): return MCC ('p', 'l');
5571 case MCC ('g', 'e'): return MCC ('l', 't');
5572 case MCC ('l', 't'): return MCC ('g', 'e');
5573 case MCC ('g', 't'): return MCC ('l', 'e');
5574 case MCC ('l', 'e'): return MCC ('g', 't');
5579 /* Build an MRI structured control expression. This generates test
5580 and branch instructions. It goes to TRUELAB if the condition is
5581 true, and to FALSELAB if the condition is false. Exactly one of
5582 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5583 is the size qualifier for the expression. EXTENT is the size to
5584 use for the branch. */
5587 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5588 rightstop
, truelab
, falselab
, extent
)
5595 const char *truelab
;
5596 const char *falselab
;
5602 if (leftstart
!= NULL
)
5604 struct m68k_op leftop
, rightop
;
5607 /* Swap the compare operands, if necessary, to produce a legal
5608 m68k compare instruction. Comparing a register operand with
5609 a non-register operand requires the register to be on the
5610 right (cmp, cmpa). Comparing an immediate value with
5611 anything requires the immediate value to be on the left
5616 (void) m68k_ip_op (leftstart
, &leftop
);
5621 (void) m68k_ip_op (rightstart
, &rightop
);
5624 if (rightop
.mode
== IMMED
5625 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5626 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5630 cc
= swap_mri_condition (cc
);
5632 leftstart
= rightstart
;
5635 leftstop
= rightstop
;
5640 if (truelab
== NULL
)
5642 cc
= reverse_mri_condition (cc
);
5646 if (leftstart
!= NULL
)
5648 buf
= (char *) xmalloc (20
5649 + (leftstop
- leftstart
)
5650 + (rightstop
- rightstart
));
5658 memcpy (s
, leftstart
, leftstop
- leftstart
);
5659 s
+= leftstop
- leftstart
;
5661 memcpy (s
, rightstart
, rightstop
- rightstart
);
5662 s
+= rightstop
- rightstart
;
5668 buf
= (char *) xmalloc (20 + strlen (truelab
));
5676 strcpy (s
, truelab
);
5681 /* Parse an MRI structured control expression. This generates test
5682 and branch instructions. STOP is where the expression ends. It
5683 goes to TRUELAB if the condition is true, and to FALSELAB if the
5684 condition is false. Exactly one of TRUELAB and FALSELAB will be
5685 NULL, meaning to fall through. QUAL is the size qualifier for the
5686 expression. EXTENT is the size to use for the branch. */
5689 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
5692 const char *truelab
;
5693 const char *falselab
;
5706 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5707 &rightstart
, &rightstop
))
5713 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5717 if (falselab
!= NULL
)
5720 flab
= mri_control_label ();
5722 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5723 rightstop
, (const char *) NULL
, flab
, extent
);
5725 input_line_pointer
+= 3;
5726 if (*input_line_pointer
!= '.'
5727 || input_line_pointer
[1] == '\0')
5731 qual
= input_line_pointer
[1];
5732 input_line_pointer
+= 2;
5735 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5736 &rightstart
, &rightstop
))
5742 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5743 rightstop
, truelab
, falselab
, extent
);
5745 if (falselab
== NULL
)
5748 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5752 if (truelab
!= NULL
)
5755 tlab
= mri_control_label ();
5757 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5758 rightstop
, tlab
, (const char *) NULL
, extent
);
5760 input_line_pointer
+= 2;
5761 if (*input_line_pointer
!= '.'
5762 || input_line_pointer
[1] == '\0')
5766 qual
= input_line_pointer
[1];
5767 input_line_pointer
+= 2;
5770 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5771 &rightstart
, &rightstop
))
5777 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5778 rightstop
, truelab
, falselab
, extent
);
5780 if (truelab
== NULL
)
5785 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5786 rightstop
, truelab
, falselab
, extent
);
5790 if (input_line_pointer
!= stop
)
5791 as_bad ("syntax error in structured control directive");
5794 /* Handle the MRI IF pseudo-op. This may be a structured control
5795 directive, or it may be a regular assembler conditional, depending
5804 struct mri_control_info
*n
;
5806 /* A structured control directive must end with THEN with an
5807 optional qualifier. */
5808 s
= input_line_pointer
;
5809 while (! is_end_of_line
[(unsigned char) *s
]
5810 && (! flag_mri
|| *s
!= '*'))
5813 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5816 if (s
- input_line_pointer
> 1
5820 if (s
- input_line_pointer
< 3
5821 || strncasecmp (s
- 3, "THEN", 4) != 0)
5825 as_bad ("missing then");
5826 ignore_rest_of_line ();
5830 /* It's a conditional. */
5835 /* Since this might be a conditional if, this pseudo-op will be
5836 called even if we are supported to be ignoring input. Double
5837 check now. Clobber *input_line_pointer so that ignore_input
5838 thinks that this is not a special pseudo-op. */
5839 c
= *input_line_pointer
;
5840 *input_line_pointer
= 0;
5841 if (ignore_input ())
5843 *input_line_pointer
= c
;
5844 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5845 ++input_line_pointer
;
5846 demand_empty_rest_of_line ();
5849 *input_line_pointer
= c
;
5851 n
= push_mri_control (mri_if
);
5853 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5854 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5857 input_line_pointer
= s
+ 3;
5859 input_line_pointer
= s
+ 1;
5863 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5864 ++input_line_pointer
;
5867 demand_empty_rest_of_line ();
5870 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5871 structured IF, associate the ELSE with the IF. Otherwise, assume
5872 it is a conditional else. */
5883 && (mri_control_stack
== NULL
5884 || mri_control_stack
->type
!= mri_if
5885 || mri_control_stack
->else_seen
))
5891 c
= *input_line_pointer
;
5892 *input_line_pointer
= 0;
5893 if (ignore_input ())
5895 *input_line_pointer
= c
;
5896 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5897 ++input_line_pointer
;
5898 demand_empty_rest_of_line ();
5901 *input_line_pointer
= c
;
5903 if (mri_control_stack
== NULL
5904 || mri_control_stack
->type
!= mri_if
5905 || mri_control_stack
->else_seen
)
5907 as_bad ("else without matching if");
5908 ignore_rest_of_line ();
5912 mri_control_stack
->else_seen
= 1;
5914 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
5917 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
5921 colon (mri_control_stack
->next
);
5925 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5926 ++input_line_pointer
;
5929 demand_empty_rest_of_line ();
5932 /* Handle the MRI ENDI pseudo-op. */
5938 if (mri_control_stack
== NULL
5939 || mri_control_stack
->type
!= mri_if
)
5941 as_bad ("endi without matching if");
5942 ignore_rest_of_line ();
5946 /* ignore_input will not return true for ENDI, so we don't need to
5947 worry about checking it again here. */
5949 if (! mri_control_stack
->else_seen
)
5950 colon (mri_control_stack
->next
);
5951 colon (mri_control_stack
->bottom
);
5957 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5958 ++input_line_pointer
;
5961 demand_empty_rest_of_line ();
5964 /* Handle the MRI BREAK pseudo-op. */
5967 s_mri_break (extent
)
5970 struct mri_control_info
*n
;
5974 n
= mri_control_stack
;
5976 && n
->type
!= mri_for
5977 && n
->type
!= mri_repeat
5978 && n
->type
!= mri_while
)
5982 as_bad ("break outside of structured loop");
5983 ignore_rest_of_line ();
5987 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
5990 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
5996 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5997 ++input_line_pointer
;
6000 demand_empty_rest_of_line ();
6003 /* Handle the MRI NEXT pseudo-op. */
6009 struct mri_control_info
*n
;
6013 n
= mri_control_stack
;
6015 && n
->type
!= mri_for
6016 && n
->type
!= mri_repeat
6017 && n
->type
!= mri_while
)
6021 as_bad ("next outside of structured loop");
6022 ignore_rest_of_line ();
6026 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6029 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6035 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6036 ++input_line_pointer
;
6039 demand_empty_rest_of_line ();
6042 /* Handle the MRI FOR pseudo-op. */
6048 const char *varstart
, *varstop
;
6049 const char *initstart
, *initstop
;
6050 const char *endstart
, *endstop
;
6051 const char *bystart
, *bystop
;
6055 struct mri_control_info
*n
;
6061 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6065 varstart
= input_line_pointer
;
6067 /* Look for the '='. */
6068 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6069 && *input_line_pointer
!= '=')
6070 ++input_line_pointer
;
6071 if (*input_line_pointer
!= '=')
6073 as_bad ("missing =");
6074 ignore_rest_of_line ();
6078 varstop
= input_line_pointer
;
6079 if (varstop
> varstart
6080 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6083 ++input_line_pointer
;
6085 initstart
= input_line_pointer
;
6087 /* Look for TO or DOWNTO. */
6090 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6092 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6093 && ! is_part_of_name (input_line_pointer
[2]))
6095 initstop
= input_line_pointer
;
6096 input_line_pointer
+= 2;
6099 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6100 && ! is_part_of_name (input_line_pointer
[6]))
6102 initstop
= input_line_pointer
;
6104 input_line_pointer
+= 6;
6107 ++input_line_pointer
;
6109 if (initstop
== NULL
)
6111 as_bad ("missing to or downto");
6112 ignore_rest_of_line ();
6115 if (initstop
> initstart
6116 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6120 endstart
= input_line_pointer
;
6122 /* Look for BY or DO. */
6125 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6127 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6128 && ! is_part_of_name (input_line_pointer
[2]))
6130 endstop
= input_line_pointer
;
6132 input_line_pointer
+= 2;
6135 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6136 && (input_line_pointer
[2] == '.'
6137 || ! is_part_of_name (input_line_pointer
[2])))
6139 endstop
= input_line_pointer
;
6140 input_line_pointer
+= 2;
6143 ++input_line_pointer
;
6145 if (endstop
== NULL
)
6147 as_bad ("missing do");
6148 ignore_rest_of_line ();
6151 if (endstop
> endstart
6152 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6158 bystop
= bystart
+ 2;
6163 bystart
= input_line_pointer
;
6167 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6169 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6170 && (input_line_pointer
[2] == '.'
6171 || ! is_part_of_name (input_line_pointer
[2])))
6173 bystop
= input_line_pointer
;
6174 input_line_pointer
+= 2;
6177 ++input_line_pointer
;
6181 as_bad ("missing do");
6182 ignore_rest_of_line ();
6185 if (bystop
> bystart
6186 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6190 if (*input_line_pointer
!= '.')
6194 extent
= input_line_pointer
[1];
6195 input_line_pointer
+= 2;
6198 /* We have fully parsed the FOR operands. Now build the loop. */
6200 n
= push_mri_control (mri_for
);
6202 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6213 memcpy (s
, initstart
, initstop
- initstart
);
6214 s
+= initstop
- initstart
;
6216 memcpy (s
, varstart
, varstop
- varstart
);
6217 s
+= varstop
- varstart
;
6231 memcpy (s
, endstart
, endstop
- endstart
);
6232 s
+= endstop
- endstart
;
6234 memcpy (s
, varstart
, varstop
- varstart
);
6235 s
+= varstop
- varstart
;
6243 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6245 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6248 /* Put together the add or sub instruction used by ENDF. */
6258 memcpy (s
, bystart
, bystop
- bystart
);
6259 s
+= bystop
- bystart
;
6261 memcpy (s
, varstart
, varstop
- varstart
);
6262 s
+= varstop
- varstart
;
6268 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6269 ++input_line_pointer
;
6272 demand_empty_rest_of_line ();
6275 /* Handle the MRI ENDF pseudo-op. */
6281 if (mri_control_stack
== NULL
6282 || mri_control_stack
->type
!= mri_for
)
6284 as_bad ("endf without for");
6285 ignore_rest_of_line ();
6289 colon (mri_control_stack
->next
);
6291 md_assemble (mri_control_stack
->incr
);
6293 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6294 md_assemble (mri_control_stack
->incr
);
6296 free (mri_control_stack
->incr
);
6298 colon (mri_control_stack
->bottom
);
6304 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6305 ++input_line_pointer
;
6308 demand_empty_rest_of_line ();
6311 /* Handle the MRI REPEAT pseudo-op. */
6314 s_mri_repeat (ignore
)
6317 struct mri_control_info
*n
;
6319 n
= push_mri_control (mri_repeat
);
6323 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6324 ++input_line_pointer
;
6326 demand_empty_rest_of_line ();
6329 /* Handle the MRI UNTIL pseudo-op. */
6337 if (mri_control_stack
== NULL
6338 || mri_control_stack
->type
!= mri_repeat
)
6340 as_bad ("until without repeat");
6341 ignore_rest_of_line ();
6345 colon (mri_control_stack
->next
);
6347 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6350 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6351 mri_control_stack
->top
, '\0');
6353 colon (mri_control_stack
->bottom
);
6355 input_line_pointer
= s
;
6361 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6362 ++input_line_pointer
;
6365 demand_empty_rest_of_line ();
6368 /* Handle the MRI WHILE pseudo-op. */
6376 struct mri_control_info
*n
;
6378 s
= input_line_pointer
;
6379 while (! is_end_of_line
[(unsigned char) *s
]
6380 && (! flag_mri
|| *s
!= '*'))
6383 while (*s
== ' ' || *s
== '\t')
6385 if (s
- input_line_pointer
> 1
6388 if (s
- input_line_pointer
< 2
6389 || strncasecmp (s
- 1, "DO", 2) != 0)
6391 as_bad ("missing do");
6392 ignore_rest_of_line ();
6396 n
= push_mri_control (mri_while
);
6400 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6401 s
[1] == '.' ? s
[2] : '\0');
6403 input_line_pointer
= s
+ 1;
6404 if (*input_line_pointer
== '.')
6405 input_line_pointer
+= 2;
6409 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6410 ++input_line_pointer
;
6413 demand_empty_rest_of_line ();
6416 /* Handle the MRI ENDW pseudo-op. */
6424 if (mri_control_stack
== NULL
6425 || mri_control_stack
->type
!= mri_while
)
6427 as_bad ("endw without while");
6428 ignore_rest_of_line ();
6432 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6433 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6437 colon (mri_control_stack
->bottom
);
6443 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6444 ++input_line_pointer
;
6447 demand_empty_rest_of_line ();
6452 * Invocation line includes a switch not recognized by the base assembler.
6453 * See if it's a processor-specific option. These are:
6455 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6456 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6457 * Select the architecture. Instructions or features not
6458 * supported by the selected architecture cause fatal
6459 * errors. More than one may be specified. The default is
6460 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6461 * for -m68000, and -m68882 is a synonym for -m68881.
6462 * -[A]m[c]no-68851, -[A]m[c]no-68881
6463 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6464 * so don't use or document it, but that's the way the parsing
6467 * -pic Indicates PIC.
6468 * -k Indicates PIC. (Sun 3 only.)
6471 * Permit `|' to be used in expressions.
6476 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6478 CONST
char *md_shortopts
= "lSA:m:k";
6481 struct option md_longopts
[] = {
6482 #define OPTION_PIC (OPTION_MD_BASE)
6483 {"pic", no_argument
, NULL
, OPTION_PIC
},
6484 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6485 {"register-prefix-optional", no_argument
, NULL
,
6486 OPTION_REGISTER_PREFIX_OPTIONAL
},
6487 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6488 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
6489 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6490 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
6491 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6492 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
6493 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6494 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
6495 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6496 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
6497 {NULL
, no_argument
, NULL
, 0}
6499 size_t md_longopts_size
= sizeof(md_longopts
);
6502 md_parse_option (c
, arg
)
6508 case 'l': /* -l means keep external to 2 bit offset
6509 rather than 16 bit one */
6510 flag_short_refs
= 1;
6513 case 'S': /* -S means that jbsr's always turn into
6515 flag_long_jumps
= 1;
6521 /* intentional fall-through */
6524 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6528 const char *oarg
= arg
;
6534 if (arg
[0] == 'c' && arg
[1] == '6')
6537 for (i
= 0; i
< n_archs
; i
++)
6538 if (!strcmp (arg
, archs
[i
].name
))
6543 as_bad ("unrecognized option `%s'", oarg
);
6546 arch
= archs
[i
].arch
;
6549 else if (arch
== m68851
)
6558 if (arg
[0] == 'c' && arg
[1] == '6')
6561 for (i
= 0; i
< n_archs
; i
++)
6562 if (!strcmp (arg
, archs
[i
].name
))
6564 unsigned long arch
= archs
[i
].arch
;
6565 if (cpu_of_arch (arch
))
6566 /* It's a cpu spec. */
6568 current_architecture
&= ~m68000up
;
6569 current_architecture
|= arch
;
6571 else if (arch
== m68881
)
6573 current_architecture
|= m68881
;
6576 else if (arch
== m68851
)
6578 current_architecture
|= m68851
;
6588 as_bad ("unrecognized architecture specification `%s'", arg
);
6597 break; /* -pic, Position Independent Code */
6599 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6600 flag_reg_prefix_optional
= 1;
6601 reg_prefix_optional_seen
= 1;
6604 /* -V: SVR4 argument to print version ID. */
6606 print_version_id ();
6609 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6610 should be emitted or not. FIXME: Not implemented. */
6614 case OPTION_BITWISE_OR
:
6619 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
6621 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
6625 m68k_comment_chars
= n
;
6629 case OPTION_BASE_SIZE_DEFAULT_16
:
6630 m68k_index_width_default
= SIZE_WORD
;
6633 case OPTION_BASE_SIZE_DEFAULT_32
:
6634 m68k_index_width_default
= SIZE_LONG
;
6637 case OPTION_DISP_SIZE_DEFAULT_16
:
6639 m68k_rel32_from_cmdline
= 1;
6642 case OPTION_DISP_SIZE_DEFAULT_32
:
6644 m68k_rel32_from_cmdline
= 1;
6655 md_show_usage (stream
)
6660 -l use 1 word for refs to undefined symbols [default 2]\n\
6661 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6662 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6663 | -mcpu32 | -m5200\n\
6664 specify variant of 680X0 architecture [default 68020]\n\
6665 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6666 target has/lacks floating-point coprocessor\n\
6667 [default yes for 68020, 68030, and cpu32]\n");
6669 -m68851 | -mno-68851\n\
6670 target has/lacks memory-management unit coprocessor\n\
6671 [default yes for 68020 and up]\n\
6672 -pic, -k generate position independent code\n\
6673 -S turn jbsr into jsr\n\
6674 --register-prefix-optional\n\
6675 recognize register names without prefix character\n\
6676 --bitwise-or do not treat `|' as a comment character\n");
6678 --base-size-default-16 base reg without size is 16 bits\n\
6679 --base-size-default-32 base reg without size is 32 bits (default)\n\
6680 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6681 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n");
6686 /* TEST2: Test md_assemble() */
6687 /* Warning, this routine probably doesn't work anymore */
6691 struct m68k_it the_ins
;
6699 if (!gets (buf
) || !*buf
)
6701 if (buf
[0] == '|' || buf
[1] == '.')
6703 for (cp
= buf
; *cp
; cp
++)
6708 memset (&the_ins
, '\0', sizeof (the_ins
));
6709 m68k_ip (&the_ins
, buf
);
6712 printf ("Error %s in %s\n", the_ins
.error
, buf
);
6716 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
6717 for (n
= 0; n
< the_ins
.numo
; n
++)
6718 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
6720 print_the_insn (&the_ins
.opcode
[0], stdout
);
6721 (void) putchar ('\n');
6723 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
6725 if (the_ins
.operands
[n
].error
)
6727 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
6730 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
6731 if (the_ins
.operands
[n
].b_const
)
6732 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
6733 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
6734 if (the_ins
.operands
[n
].b_iadd
)
6735 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
6736 (void) putchar ('\n');
6748 while (*str
&& *str
!= ' ')
6750 if (str
[-1] == ':' || str
[1] == '=')
6757 /* Possible states for relaxation:
6759 0 0 branch offset byte (bra, etc)
6763 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6767 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6774 /* We have no need to default values of symbols. */
6778 md_undefined_symbol (name
)
6784 /* Round up a section size to the appropriate boundary. */
6786 md_section_align (segment
, size
)
6790 return size
; /* Byte alignment is fine */
6793 /* Exactly what point is a PC-relative offset relative TO?
6794 On the 68k, it is relative to the address of the first extension
6795 word. The difference between the addresses of the offset and the
6796 first extension word is stored in fx_pcrel_adjust. */
6798 md_pcrel_from (fixP
)
6803 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6805 adjust
= fixP
->fx_pcrel_adjust
;
6808 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
6811 #ifndef BFD_ASSEMBLER
6814 tc_coff_symbol_emit_hook (ignore
)
6820 tc_coff_sizemachdep (frag
)
6823 switch (frag
->fr_subtype
& 0x3)
6838 /* end of tc-m68k.c */