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 /* Static functions. */
270 static void insop
PARAMS ((int, struct m68k_incant
*));
271 static void add_fix
PARAMS ((int, struct m68k_exp
*, int, int));
272 static void add_frag
PARAMS ((symbolS
*, offsetT
, int));
274 /* Like addword, but goes BEFORE general operands */
278 struct m68k_incant
*opcode
;
281 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
282 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
283 for(z
=0;z
<the_ins
.nrel
;z
++)
284 the_ins
.reloc
[z
].n
+=2;
285 for (z
= 0; z
< the_ins
.nfrag
; z
++)
286 the_ins
.fragb
[z
].fragoff
++;
287 the_ins
.opcode
[opcode
->m_codenum
]=w
;
291 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
294 add_fix (width
, exp
, pc_rel
, pc_fix
)
296 struct m68k_exp
*exp
;
300 the_ins
.reloc
[the_ins
.nrel
].n
= ((width
== 'B' || width
== '3')
304 : (the_ins
.numo
*2)));
305 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
306 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
307 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
309 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
311 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
314 /* Cause an extra frag to be generated here, inserting up to 10 bytes
315 (that value is chosen in the frag_var call in md_assemble). TYPE
316 is the subtype of the frag to be generated; its primary type is
317 rs_machine_dependent.
319 The TYPE parameter is also used by md_convert_frag_1 and
320 md_estimate_size_before_relax. The appropriate type of fixup will
321 be emitted by md_convert_frag_1.
323 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
325 add_frag (add
, off
, type
)
330 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
331 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
332 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
333 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
337 (op (ex) != O_constant && op (ex) != O_big)
339 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
340 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
341 static void m68k_ip
PARAMS ((char *));
342 static void insert_reg
PARAMS ((const char *, int));
343 static void select_control_regs
PARAMS ((void));
344 static void init_regtable
PARAMS ((void));
345 static int reverse_16_bits
PARAMS ((int in
));
346 static int reverse_8_bits
PARAMS ((int in
));
347 static void install_gen_operand
PARAMS ((int mode
, int val
));
348 static void install_operand
PARAMS ((int mode
, int val
));
349 static void s_bss
PARAMS ((int));
350 static void s_data1
PARAMS ((int));
351 static void s_data2
PARAMS ((int));
352 static void s_even
PARAMS ((int));
353 static void s_proc
PARAMS ((int));
354 static void mri_chip
PARAMS ((void));
355 static void s_chip
PARAMS ((int));
356 static void s_fopt
PARAMS ((int));
357 static void s_opt
PARAMS ((int));
358 static void s_reg
PARAMS ((int));
359 static void s_restore
PARAMS ((int));
360 static void s_save
PARAMS ((int));
361 static void s_mri_if
PARAMS ((int));
362 static void s_mri_else
PARAMS ((int));
363 static void s_mri_endi
PARAMS ((int));
364 static void s_mri_break
PARAMS ((int));
365 static void s_mri_next
PARAMS ((int));
366 static void s_mri_for
PARAMS ((int));
367 static void s_mri_endf
PARAMS ((int));
368 static void s_mri_repeat
PARAMS ((int));
369 static void s_mri_until
PARAMS ((int));
370 static void s_mri_while
PARAMS ((int));
371 static void s_mri_endw
PARAMS ((int));
372 static void md_apply_fix_2
PARAMS ((fixS
*, offsetT
));
373 static void md_convert_frag_1
PARAMS ((fragS
*));
375 static int current_architecture
;
383 static const struct m68k_cpu archs
[] = {
384 { m68000
, "68000", 0 },
385 { m68010
, "68010", 0 },
386 { m68020
, "68020", 0 },
387 { m68030
, "68030", 0 },
388 { m68040
, "68040", 0 },
389 { m68060
, "68060", 0 },
390 { cpu32
, "cpu32", 0 },
391 { m68881
, "68881", 0 },
392 { m68851
, "68851", 0 },
393 { mcf5200
, "5200", 0 },
394 /* Aliases (effectively, so far as gas is concerned) for the above
396 { m68020
, "68k", 1 },
397 { m68000
, "68302", 1 },
398 { m68000
, "68008", 1 },
399 { m68000
, "68ec000", 1 },
400 { m68000
, "68hc000", 1 },
401 { m68000
, "68hc001", 1 },
402 { m68020
, "68ec020", 1 },
403 { m68030
, "68ec030", 1 },
404 { m68040
, "68ec040", 1 },
405 { m68060
, "68ec060", 1 },
406 { cpu32
, "68330", 1 },
407 { cpu32
, "68331", 1 },
408 { cpu32
, "68332", 1 },
409 { cpu32
, "68333", 1 },
410 { cpu32
, "68340", 1 },
411 { cpu32
, "68360", 1 },
412 { m68881
, "68882", 1 },
415 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
417 /* BCC68000 is for patching in an extra jmp instruction for long offsets
418 on the 68000. The 68000 doesn't support long branches with branchs */
420 /* This table desribes how you change sizes for the various types of variable
421 size expressions. This version only supports two kinds. */
423 /* Note that calls to frag_var need to specify the maximum expansion
424 needed; this is currently 10 bytes for DBCC. */
427 How far Forward this mode will reach:
428 How far Backward this mode will reach:
429 How many bytes this mode will add to the size of the frag
430 Which mode to go to if the offset won't fit in this one
432 relax_typeS md_relax_table
[] =
434 {1, 1, 0, 0}, /* First entries aren't used */
435 {1, 1, 0, 0}, /* For no good reason except */
436 {1, 1, 0, 0}, /* that the VAX doesn't either */
439 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
440 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
444 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
445 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
449 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
450 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
454 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
455 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
456 {0, 0, 6, 0}, /* jmp long space */
459 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
460 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
461 {0, 0, 10, 0}, /* bra/jmp long space */
464 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
465 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
469 /* For, e.g., jmp pcrel indexed. */
470 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
471 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
476 /* These are the machine dependent pseudo-ops. These are included so
477 the assembler can work on the output from the SUN C compiler, which
481 /* This table describes all the machine specific pseudo-ops the assembler
482 has to support. The fields are:
483 pseudo-op name without dot
484 function to call to execute this pseudo-op
485 Integer arg to pass to the function
487 const pseudo_typeS md_pseudo_table
[] =
489 {"data1", s_data1
, 0},
490 {"data2", s_data2
, 0},
493 {"skip", s_space
, 0},
495 #if defined (TE_SUN3) || defined (OBJ_ELF)
496 {"align", s_align_bytes
, 0},
499 {"swbeg", s_ignore
, 0},
501 {"extend", float_cons
, 'x'},
502 {"ldouble", float_cons
, 'x'},
504 /* The following pseudo-ops are supported for MRI compatibility. */
506 {"comline", s_space
, 1},
508 {"mask2", s_ignore
, 0},
511 {"restore", s_restore
, 0},
515 {"if.b", s_mri_if
, 'b'},
516 {"if.w", s_mri_if
, 'w'},
517 {"if.l", s_mri_if
, 'l'},
518 {"else", s_mri_else
, 0},
519 {"else.s", s_mri_else
, 's'},
520 {"else.l", s_mri_else
, 'l'},
521 {"endi", s_mri_endi
, 0},
522 {"break", s_mri_break
, 0},
523 {"break.s", s_mri_break
, 's'},
524 {"break.l", s_mri_break
, 'l'},
525 {"next", s_mri_next
, 0},
526 {"next.s", s_mri_next
, 's'},
527 {"next.l", s_mri_next
, 'l'},
528 {"for", s_mri_for
, 0},
529 {"for.b", s_mri_for
, 'b'},
530 {"for.w", s_mri_for
, 'w'},
531 {"for.l", s_mri_for
, 'l'},
532 {"endf", s_mri_endf
, 0},
533 {"repeat", s_mri_repeat
, 0},
534 {"until", s_mri_until
, 0},
535 {"until.b", s_mri_until
, 'b'},
536 {"until.w", s_mri_until
, 'w'},
537 {"until.l", s_mri_until
, 'l'},
538 {"while", s_mri_while
, 0},
539 {"while.b", s_mri_while
, 'b'},
540 {"while.w", s_mri_while
, 'w'},
541 {"while.l", s_mri_while
, 'l'},
542 {"endw", s_mri_endw
, 0},
548 /* The mote pseudo ops are put into the opcode table, since they
549 don't start with a . they look like opcodes to gas.
553 extern void obj_coff_section
PARAMS ((int));
556 CONST pseudo_typeS mote_pseudo_table
[] =
569 {"xdef", s_globl
, 0},
571 {"align", s_align_bytes
, 0},
573 {"align", s_align_ptwo
, 0},
576 {"sect", obj_coff_section
, 0},
577 {"section", obj_coff_section
, 0},
582 #define issbyte(x) ((x)>=-128 && (x)<=127)
583 #define isubyte(x) ((x)>=0 && (x)<=255)
584 #define issword(x) ((x)>=-32768 && (x)<=32767)
585 #define isuword(x) ((x)>=0 && (x)<=65535)
587 #define isbyte(x) ((x)>= -255 && (x)<=255)
588 #define isword(x) ((x)>=-65536 && (x)<=65535)
589 #define islong(x) (1)
591 extern char *input_line_pointer
;
593 static char mklower_table
[256];
594 #define mklower(c) (mklower_table[(unsigned char)(c)])
595 static char notend_table
[256];
596 static char alt_notend_table
[256];
598 (! (notend_table[(unsigned char) *s] \
600 && alt_notend_table[(unsigned char) s[1]])))
602 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
604 #ifdef NO_PCREL_RELOCS
607 make_pcrel_absolute(fixP
, add_number
)
611 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
613 /* rewrite the PC relative instructions to absolute address ones.
614 * these are rumoured to be faster, and the apollo linker refuses
615 * to deal with the PC relative relocations.
617 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
622 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
628 as_fatal ("Unknown PC relative instruction");
633 #endif /* NO_PCREL_RELOCS */
636 tc_coff_fix2rtype (fixP
)
639 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
640 return R_RELLONG_NEG
;
641 #ifdef NO_PCREL_RELOCS
642 know (fixP
->fx_pcrel
== 0);
643 return (fixP
->fx_size
== 1 ? R_RELBYTE
644 : fixP
->fx_size
== 2 ? R_DIR16
647 return (fixP
->fx_pcrel
?
648 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
649 fixP
->fx_size
== 2 ? R_PCRWORD
:
651 (fixP
->fx_size
== 1 ? R_RELBYTE
:
652 fixP
->fx_size
== 2 ? R_RELWORD
:
661 /* Compute the relocation code for a fixup of SIZE bytes, using pc
662 relative relocation if PCREL is non-zero. PIC says whether a special
663 pic relocation was requested. */
665 static bfd_reloc_code_real_type get_reloc_code
666 PARAMS ((int, int, enum pic_relocation
));
668 static bfd_reloc_code_real_type
669 get_reloc_code (size
, pcrel
, pic
)
672 enum pic_relocation pic
;
680 return BFD_RELOC_8_GOT_PCREL
;
682 return BFD_RELOC_16_GOT_PCREL
;
684 return BFD_RELOC_32_GOT_PCREL
;
692 return BFD_RELOC_8_GOTOFF
;
694 return BFD_RELOC_16_GOTOFF
;
696 return BFD_RELOC_32_GOTOFF
;
704 return BFD_RELOC_8_PLT_PCREL
;
706 return BFD_RELOC_16_PLT_PCREL
;
708 return BFD_RELOC_32_PLT_PCREL
;
716 return BFD_RELOC_8_PLTOFF
;
718 return BFD_RELOC_16_PLTOFF
;
720 return BFD_RELOC_32_PLTOFF
;
730 return BFD_RELOC_8_PCREL
;
732 return BFD_RELOC_16_PCREL
;
734 return BFD_RELOC_32_PCREL
;
751 as_bad ("Can not do %d byte %s%srelocation", size
,
752 pcrel
? "pc-relative " : "",
753 pic
== pic_none
? "" : "pic ");
754 return BFD_RELOC_NONE
;
757 /* Here we decide which fixups can be adjusted to make them relative
758 to the beginning of the section instead of the symbol. Basically
759 we need to make sure that the dynamic relocations are done
760 correctly, so in some cases we force the original symbol to be
763 tc_m68k_fix_adjustable (fixP
)
766 /* Prevent all adjustments to global symbols. */
767 if (S_IS_EXTERNAL (fixP
->fx_addsy
))
770 /* adjust_reloc_syms doesn't know about the GOT */
771 switch (fixP
->fx_r_type
)
773 case BFD_RELOC_8_GOT_PCREL
:
774 case BFD_RELOC_16_GOT_PCREL
:
775 case BFD_RELOC_32_GOT_PCREL
:
776 case BFD_RELOC_8_GOTOFF
:
777 case BFD_RELOC_16_GOTOFF
:
778 case BFD_RELOC_32_GOTOFF
:
779 case BFD_RELOC_8_PLT_PCREL
:
780 case BFD_RELOC_16_PLT_PCREL
:
781 case BFD_RELOC_32_PLT_PCREL
:
782 case BFD_RELOC_8_PLTOFF
:
783 case BFD_RELOC_16_PLTOFF
:
784 case BFD_RELOC_32_PLTOFF
:
794 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
801 tc_gen_reloc (section
, fixp
)
806 bfd_reloc_code_real_type code
;
811 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
813 code
= fixp
->fx_r_type
;
815 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
816 that fixup_segment converted a non-PC relative reloc into a
817 PC relative reloc. In such a case, we need to convert the
824 code
= BFD_RELOC_8_PCREL
;
827 code
= BFD_RELOC_16_PCREL
;
830 code
= BFD_RELOC_32_PCREL
;
832 case BFD_RELOC_8_PCREL
:
833 case BFD_RELOC_16_PCREL
:
834 case BFD_RELOC_32_PCREL
:
835 case BFD_RELOC_8_GOT_PCREL
:
836 case BFD_RELOC_16_GOT_PCREL
:
837 case BFD_RELOC_32_GOT_PCREL
:
838 case BFD_RELOC_8_GOTOFF
:
839 case BFD_RELOC_16_GOTOFF
:
840 case BFD_RELOC_32_GOTOFF
:
841 case BFD_RELOC_8_PLT_PCREL
:
842 case BFD_RELOC_16_PLT_PCREL
:
843 case BFD_RELOC_32_PLT_PCREL
:
844 case BFD_RELOC_8_PLTOFF
:
845 case BFD_RELOC_16_PLTOFF
:
846 case BFD_RELOC_32_PLTOFF
:
849 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
850 "Cannot make %s relocation PC relative",
851 bfd_get_reloc_code_name (code
));
857 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
858 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
860 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
861 MAP (1, 0, BFD_RELOC_8
);
862 MAP (2, 0, BFD_RELOC_16
);
863 MAP (4, 0, BFD_RELOC_32
);
864 MAP (1, 1, BFD_RELOC_8_PCREL
);
865 MAP (2, 1, BFD_RELOC_16_PCREL
);
866 MAP (4, 1, BFD_RELOC_32_PCREL
);
874 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
875 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
876 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
879 reloc
->addend
= fixp
->fx_addnumber
;
884 reloc
->addend
= fixp
->fx_addnumber
;
886 reloc
->addend
= (section
->vma
887 + (fixp
->fx_pcrel_adjust
== 64
888 ? -1 : fixp
->fx_pcrel_adjust
)
890 + md_pcrel_from (fixp
));
893 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
894 assert (reloc
->howto
!= 0);
899 #endif /* BFD_ASSEMBLER */
901 /* Handle of the OPCODE hash table. NULL means any use before
902 m68k_ip_begin() will crash. */
903 static struct hash_control
*op_hash
;
905 /* Assemble an m68k instruction. */
912 register struct m68k_op
*opP
;
913 register struct m68k_incant
*opcode
;
914 register const char *s
;
915 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
916 char *pdot
, *pdotmove
;
917 enum m68k_size siz1
, siz2
;
921 LITTLENUM_TYPE words
[6];
922 LITTLENUM_TYPE
*wordp
;
923 unsigned long ok_arch
= 0;
925 if (*instring
== ' ')
926 instring
++; /* skip leading whitespace */
928 /* Scan up to end of operation-code, which MUST end in end-of-string
929 or exactly 1 space. */
931 for (p
= instring
; *p
!= '\0'; p
++)
941 the_ins
.error
= "No operator";
945 /* p now points to the end of the opcode name, probably whitespace.
946 Make sure the name is null terminated by clobbering the
947 whitespace, look it up in the hash table, then fix it back.
948 Remove a dot, first, since the opcode tables have none. */
951 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
952 *pdotmove
= pdotmove
[1];
958 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
963 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
964 *pdotmove
= pdotmove
[-1];
971 the_ins
.error
= "Unknown operator";
975 /* found a legitimate opcode, start matching operands */
979 if (opcode
->m_operands
== 0)
981 char *old
= input_line_pointer
;
983 input_line_pointer
= p
;
984 /* Ahh - it's a motorola style psuedo op */
985 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
986 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
987 input_line_pointer
= old
;
993 if (flag_mri
&& opcode
->m_opnum
== 0)
995 /* In MRI mode, random garbage is allowed after an instruction
996 which accepts no operands. */
997 the_ins
.args
= opcode
->m_operands
;
998 the_ins
.numargs
= opcode
->m_opnum
;
999 the_ins
.numo
= opcode
->m_codenum
;
1000 the_ins
.opcode
[0] = getone (opcode
);
1001 the_ins
.opcode
[1] = gettwo (opcode
);
1005 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1007 p
= crack_operand (p
, opP
);
1011 the_ins
.error
= opP
->error
;
1016 opsfound
= opP
- &the_ins
.operands
[0];
1018 /* This ugly hack is to support the floating pt opcodes in their
1019 standard form. Essentially, we fake a first enty of type COP#1 */
1020 if (opcode
->m_operands
[0] == 'I')
1024 for (n
= opsfound
; n
> 0; --n
)
1025 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1027 memset ((char *) (&the_ins
.operands
[0]), '\0',
1028 sizeof (the_ins
.operands
[0]));
1029 the_ins
.operands
[0].mode
= CONTROL
;
1030 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1034 /* We've got the operands. Find an opcode that'll accept them */
1037 /* If we didn't get the right number of ops, or we have no
1038 common model with this pattern then reject this pattern. */
1040 ok_arch
|= opcode
->m_arch
;
1041 if (opsfound
!= opcode
->m_opnum
1042 || ((opcode
->m_arch
& current_architecture
) == 0))
1046 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
1050 /* Warning: this switch is huge! */
1051 /* I've tried to organize the cases into this order:
1052 non-alpha first, then alpha by letter. Lower-case
1053 goes directly before uppercase counterpart. */
1054 /* Code with multiple case ...: gets sorted by the lowest
1055 case ... it belongs to. I hope this makes sense. */
1179 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1196 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1215 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1225 if (opP
->mode
!= IMMED
)
1227 else if (s
[1] == 'b'
1228 && ! isvar (&opP
->disp
)
1229 && (opP
->disp
.exp
.X_op
!= O_constant
1230 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1232 else if (s
[1] == 'B'
1233 && ! isvar (&opP
->disp
)
1234 && (opP
->disp
.exp
.X_op
!= O_constant
1235 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1237 else if (s
[1] == 'w'
1238 && ! isvar (&opP
->disp
)
1239 && (opP
->disp
.exp
.X_op
!= O_constant
1240 || ! isword (opP
->disp
.exp
.X_add_number
)))
1242 else if (s
[1] == 'W'
1243 && ! isvar (&opP
->disp
)
1244 && (opP
->disp
.exp
.X_op
!= O_constant
1245 || ! issword (opP
->disp
.exp
.X_add_number
)))
1251 if (opP
->mode
!= IMMED
)
1256 if (opP
->mode
== AREG
1257 || opP
->mode
== CONTROL
1258 || opP
->mode
== FPREG
1259 || opP
->mode
== IMMED
1260 || opP
->mode
== REGLST
1261 || (opP
->mode
!= ABSL
1263 || opP
->reg
== ZPC
)))
1268 if (opP
->mode
== CONTROL
1269 || opP
->mode
== FPREG
1270 || opP
->mode
== REGLST
1271 || opP
->mode
== IMMED
1272 || (opP
->mode
!= ABSL
1274 || opP
->reg
== ZPC
)))
1302 if (opP
->mode
== CONTROL
1303 || opP
->mode
== FPREG
1304 || opP
->mode
== REGLST
)
1309 if (opP
->mode
!= AINC
)
1314 if (opP
->mode
!= ADEC
)
1364 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1385 case '~': /* For now! (JF FOO is this right?) */
1407 if (opP
->mode
!= CONTROL
1408 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1413 if (opP
->mode
!= AREG
)
1418 if (opP
->mode
!= AINDR
)
1423 if (opP
->mode
!= ABSL
1425 && strncmp (instring
, "jbsr", 4) == 0))
1430 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1435 if (opP
->mode
!= DISP
1437 || opP
->reg
> ADDR7
)
1442 if (opP
->mode
!= DREG
)
1447 if (opP
->mode
!= FPREG
)
1452 if (opP
->mode
!= CONTROL
1459 if (opP
->mode
!= CONTROL
1461 || opP
->reg
> last_movec_reg
)
1465 const enum m68k_register
*rp
;
1466 for (rp
= control_regs
; *rp
; rp
++)
1467 if (*rp
== opP
->reg
)
1475 if (opP
->mode
!= IMMED
)
1481 if (opP
->mode
== DREG
1482 || opP
->mode
== AREG
1483 || opP
->mode
== FPREG
)
1492 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1495 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1498 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1506 else if (opP
->mode
== CONTROL
)
1515 opP
->mask
= 1 << 24;
1518 opP
->mask
= 1 << 25;
1521 opP
->mask
= 1 << 26;
1530 else if (opP
->mode
== ABSL
1531 && opP
->disp
.size
== SIZE_UNSPEC
1532 && opP
->disp
.exp
.X_op
== O_constant
)
1534 /* This is what the MRI REG pseudo-op generates. */
1536 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1538 else if (opP
->mode
!= REGLST
)
1540 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1542 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1547 if (opP
->mode
!= IMMED
)
1549 else if (opP
->disp
.exp
.X_op
!= O_constant
1550 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1552 else if (! m68k_quick
1553 && instring
[3] != 'q'
1554 && instring
[4] != 'q')
1559 if (opP
->mode
!= DREG
1560 && opP
->mode
!= IMMED
1561 && opP
->mode
!= ABSL
)
1566 if (opP
->mode
!= IMMED
)
1568 else if (opP
->disp
.exp
.X_op
!= O_constant
1569 || opP
->disp
.exp
.X_add_number
< 1
1570 || opP
->disp
.exp
.X_add_number
> 8)
1572 else if (! m68k_quick
1573 && (strncmp (instring
, "add", 3) == 0
1574 || strncmp (instring
, "sub", 3) == 0)
1575 && instring
[3] != 'q')
1580 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1585 if (opP
->mode
!= AINDR
1586 && (opP
->mode
!= BASE
1588 && opP
->reg
!= ZADDR0
)
1589 || opP
->disp
.exp
.X_op
!= O_absent
1590 || ((opP
->index
.reg
< DATA0
1591 || opP
->index
.reg
> DATA7
)
1592 && (opP
->index
.reg
< ADDR0
1593 || opP
->index
.reg
> ADDR7
))
1594 || opP
->index
.size
!= SIZE_UNSPEC
1595 || opP
->index
.scale
!= 1))
1600 if (opP
->mode
!= CONTROL
1601 || ! (opP
->reg
== FPI
1603 || opP
->reg
== FPC
))
1608 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1613 if (opP
->mode
!= IMMED
)
1615 else if (opP
->disp
.exp
.X_op
!= O_constant
1616 || opP
->disp
.exp
.X_add_number
< 0
1617 || opP
->disp
.exp
.X_add_number
> 7)
1622 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1626 /* JF these are out of order. We could put them
1627 in order if we were willing to put up with
1628 bunches of #ifdef m68851s in the code.
1630 Don't forget that you need these operands
1631 to use 68030 MMU instructions. */
1633 /* Memory addressing mode used by pflushr */
1635 if (opP
->mode
== CONTROL
1636 || opP
->mode
== FPREG
1637 || opP
->mode
== DREG
1638 || opP
->mode
== AREG
1639 || opP
->mode
== REGLST
)
1641 /* We should accept immediate operands, but they
1642 supposedly have to be quad word, and we don't
1643 handle that. I would like to see what a Motorola
1644 assembler does before doing something here. */
1645 if (opP
->mode
== IMMED
)
1650 if (opP
->mode
!= CONTROL
1651 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1656 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1661 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1666 if (opP
->mode
!= CONTROL
1669 && opP
->reg
!= SCC
))
1674 if (opP
->mode
!= CONTROL
1680 if (opP
->mode
!= CONTROL
1683 && opP
->reg
!= CRP
))
1688 if (opP
->mode
!= CONTROL
1689 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1690 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1695 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1700 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1705 if (opP
->mode
!= CONTROL
1712 } /* not a cache specifier. */
1716 if (opP
->mode
!= ABSL
)
1722 } /* switch on type of operand */
1726 } /* for each operand */
1727 } /* if immediately wrong */
1734 opcode
= opcode
->m_next
;
1739 && !(ok_arch
& current_architecture
))
1744 "invalid instruction for this architecture; needs ");
1745 cp
= buf
+ strlen (buf
);
1749 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1752 strcpy (cp
, "mmu (68030 or 68851)");
1755 strcpy (cp
, "68020 or higher");
1758 strcpy (cp
, "68000 or higher");
1761 strcpy (cp
, "68010 or higher");
1765 int got_one
= 0, idx
;
1766 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1769 if ((archs
[idx
].arch
& ok_arch
)
1770 && ! archs
[idx
].alias
)
1774 strcpy (cp
, " or ");
1778 strcpy (cp
, archs
[idx
].name
);
1784 cp
= xmalloc (strlen (buf
) + 1);
1789 the_ins
.error
= "operands mismatch";
1791 } /* Fell off the end */
1796 /* now assemble it */
1798 the_ins
.args
= opcode
->m_operands
;
1799 the_ins
.numargs
= opcode
->m_opnum
;
1800 the_ins
.numo
= opcode
->m_codenum
;
1801 the_ins
.opcode
[0] = getone (opcode
);
1802 the_ins
.opcode
[1] = gettwo (opcode
);
1804 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1806 /* This switch is a doozy.
1807 Watch the first step; its a big one! */
1836 tmpreg
= 0x3c; /* 7.4 */
1837 if (strchr ("bwl", s
[1]))
1838 nextword
= get_num (&opP
->disp
, 80);
1840 nextword
= get_num (&opP
->disp
, 0);
1841 if (isvar (&opP
->disp
))
1842 add_fix (s
[1], &opP
->disp
, 0, 0);
1846 if (!isbyte (nextword
))
1847 opP
->error
= "operand out of range";
1852 if (!isword (nextword
))
1853 opP
->error
= "operand out of range";
1858 if (!issword (nextword
))
1859 opP
->error
= "operand out of range";
1864 addword (nextword
>> 16);
1891 /* We gotta put out some float */
1892 if (op (&opP
->disp
) != O_big
)
1897 /* Can other cases happen here? */
1898 if (op (&opP
->disp
) != O_constant
)
1901 val
= (valueT
) offs (&opP
->disp
);
1905 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1906 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1910 offs (&opP
->disp
) = gencnt
;
1912 if (offs (&opP
->disp
) > 0)
1914 if (offs (&opP
->disp
) > baseo
)
1916 as_warn ("Bignum too big for %c format; truncated",
1918 offs (&opP
->disp
) = baseo
;
1920 baseo
-= offs (&opP
->disp
);
1923 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1924 offs (&opP
->disp
)--;
1929 gen_to_words (words
, baseo
, (long) outro
);
1930 for (wordp
= words
; baseo
--; wordp
++)
1934 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1937 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1940 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1943 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1946 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1950 nextword
= get_num (&opP
->disp
, 80);
1953 && ! isvar (&opP
->disp
)
1956 opP
->disp
.exp
.X_op
= O_symbol
;
1957 #ifndef BFD_ASSEMBLER
1958 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1960 opP
->disp
.exp
.X_add_symbol
=
1961 section_symbol (absolute_section
);
1965 /* Force into index mode. Hope this works */
1967 /* We do the first bit for 32-bit displacements, and the
1968 second bit for 16 bit ones. It is possible that we
1969 should make the default be WORD instead of LONG, but
1970 I think that'd break GCC, so we put up with a little
1971 inefficiency for the sake of working output. */
1973 if (!issword (nextword
)
1974 || (isvar (&opP
->disp
)
1975 && ((opP
->disp
.size
== SIZE_UNSPEC
1976 && flag_short_refs
== 0
1977 && cpu_of_arch (current_architecture
) >= m68020
)
1978 || opP
->disp
.size
== SIZE_LONG
)))
1980 if (cpu_of_arch (current_architecture
) < m68020
)
1982 "displacement too large for this architecture; needs 68020 or higher";
1984 tmpreg
= 0x3B; /* 7.3 */
1986 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1987 if (isvar (&opP
->disp
))
1991 if (opP
->disp
.size
== SIZE_LONG
1993 /* If the displacement needs pic
1994 relocation it cannot be relaxed. */
1995 || opP
->disp
.pic_reloc
!= pic_none
2000 add_fix ('l', &opP
->disp
, 1, 2);
2004 add_frag (adds (&opP
->disp
),
2006 TAB (PCLEA
, SZ_UNDEF
));
2013 add_fix ('l', &opP
->disp
, 0, 0);
2018 addword (nextword
>> 16);
2023 tmpreg
= 0x3A; /* 7.2 */
2025 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2027 if (isvar (&opP
->disp
))
2031 add_fix ('w', &opP
->disp
, 1, 0);
2034 add_fix ('w', &opP
->disp
, 0, 0);
2044 baseo
= get_num (&opP
->disp
, 80);
2045 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2046 outro
= get_num (&opP
->odisp
, 80);
2047 /* Figure out the `addressing mode'.
2048 Also turn on the BASE_DISABLE bit, if needed. */
2049 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2051 tmpreg
= 0x3b; /* 7.3 */
2052 if (opP
->reg
== ZPC
)
2055 else if (opP
->reg
== 0)
2058 tmpreg
= 0x30; /* 6.garbage */
2060 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2063 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2066 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2068 siz1
= opP
->disp
.size
;
2069 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2070 siz2
= opP
->odisp
.size
;
2074 /* Index register stuff */
2075 if (opP
->index
.reg
!= 0
2076 && opP
->index
.reg
>= DATA
2077 && opP
->index
.reg
<= ADDR7
)
2079 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2081 if (opP
->index
.size
== SIZE_LONG
2082 || (opP
->index
.size
== SIZE_UNSPEC
2083 && m68k_index_width_default
== SIZE_LONG
))
2086 if ((opP
->index
.scale
!= 1
2087 && cpu_of_arch (current_architecture
) < m68020
)
2088 || (opP
->index
.scale
== 8
2089 && current_architecture
== mcf5200
))
2092 "scale factor invalid on this architecture; needs cpu32 or 68020 or higher";
2095 switch (opP
->index
.scale
)
2112 GET US OUT OF HERE! */
2114 /* Must be INDEX, with an index register. Address
2115 register cannot be ZERO-PC, and either :b was
2116 forced, or we know it will fit. For a 68000 or
2117 68010, force this mode anyways, because the
2118 larger modes aren't supported. */
2119 if (opP
->mode
== BASE
2120 && ((opP
->reg
>= ADDR0
2121 && opP
->reg
<= ADDR7
)
2124 if (siz1
== SIZE_BYTE
2125 || cpu_of_arch (current_architecture
) < m68020
2126 || (siz1
== SIZE_UNSPEC
2127 && ! isvar (&opP
->disp
)
2128 && issbyte (baseo
)))
2130 nextword
+= baseo
& 0xff;
2132 if (isvar (&opP
->disp
))
2134 /* Do a byte relocation. If it doesn't
2135 fit (possible on m68000) let the
2136 fixup processing complain later. */
2138 add_fix ('B', &opP
->disp
, 1, 1);
2140 add_fix ('B', &opP
->disp
, 0, 0);
2142 else if (siz1
!= SIZE_BYTE
)
2144 if (siz1
!= SIZE_UNSPEC
)
2145 as_warn ("Forcing byte displacement");
2146 if (! issbyte (baseo
))
2147 opP
->error
= "byte displacement out of range";
2152 else if (siz1
== SIZE_UNSPEC
2154 && isvar (&opP
->disp
)
2155 && subs (&opP
->disp
) == NULL
2157 /* If the displacement needs pic
2158 relocation it cannot be relaxed. */
2159 && opP
->disp
.pic_reloc
== pic_none
2163 /* The code in md_convert_frag_1 needs to be
2164 able to adjust nextword. Call frag_grow
2165 to ensure that we have enough space in
2166 the frag obstack to make all the bytes
2169 nextword
+= baseo
& 0xff;
2171 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2172 TAB (PCINDEX
, SZ_UNDEF
));
2180 nextword
|= 0x40; /* No index reg */
2181 if (opP
->index
.reg
>= ZDATA0
2182 && opP
->index
.reg
<= ZDATA7
)
2183 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2184 else if (opP
->index
.reg
>= ZADDR0
2185 || opP
->index
.reg
<= ZADDR7
)
2186 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2189 /* It isn't simple. */
2191 if (cpu_of_arch (current_architecture
) < m68020
)
2193 "invalid operand mode for this architecture; needs 68020 or higher";
2196 /* If the guy specified a width, we assume that it is
2197 wide enough. Maybe it isn't. If so, we lose. */
2201 if (isvar (&opP
->disp
)
2203 : ! issword (baseo
))
2208 else if (! isvar (&opP
->disp
) && baseo
== 0)
2217 as_warn (":b not permitted; defaulting to :w");
2227 /* Figure out innner displacement stuff */
2228 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2230 if (cpu_of_arch (current_architecture
) & cpu32
)
2231 opP
->error
= "invalid operand mode for this architecture; needs 68020 or higher";
2235 if (isvar (&opP
->odisp
)
2237 : ! issword (outro
))
2242 else if (! isvar (&opP
->odisp
) && outro
== 0)
2251 as_warn (":b not permitted; defaulting to :w");
2260 if (opP
->mode
== POST
2261 && (nextword
& 0x40) == 0)
2266 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2268 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2269 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2271 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2273 if (siz1
== SIZE_LONG
)
2274 addword (baseo
>> 16);
2275 if (siz1
!= SIZE_UNSPEC
)
2278 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2279 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2280 if (siz2
== SIZE_LONG
)
2281 addword (outro
>> 16);
2282 if (siz2
!= SIZE_UNSPEC
)
2288 nextword
= get_num (&opP
->disp
, 80);
2289 switch (opP
->disp
.size
)
2294 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2296 tmpreg
= 0x38; /* 7.0 */
2300 /* Don't generate pc relative code on 68010 and
2302 if (isvar (&opP
->disp
)
2303 && !subs (&opP
->disp
)
2304 && adds (&opP
->disp
)
2306 /* If the displacement needs pic relocation it
2307 cannot be relaxed. */
2308 && opP
->disp
.pic_reloc
== pic_none
2310 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2311 && HAVE_LONG_BRANCH(current_architecture
)
2313 && !strchr ("~%&$?", s
[0]))
2315 tmpreg
= 0x3A; /* 7.2 */
2316 add_frag (adds (&opP
->disp
),
2318 TAB (PCREL
, SZ_UNDEF
));
2321 /* Fall through into long */
2323 if (isvar (&opP
->disp
))
2324 add_fix ('l', &opP
->disp
, 0, 0);
2326 tmpreg
= 0x39;/* 7.1 mode */
2327 addword (nextword
>> 16);
2332 as_bad ("unsupported byte value; use a different suffix");
2334 case SIZE_WORD
: /* Word */
2335 if (isvar (&opP
->disp
))
2336 add_fix ('w', &opP
->disp
, 0, 0);
2338 tmpreg
= 0x38;/* 7.0 mode */
2346 as_bad ("unknown/incorrect operand");
2349 install_gen_operand (s
[1], tmpreg
);
2355 { /* JF: I hate floating point! */
2370 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2371 if (isvar (&opP
->disp
))
2372 add_fix (s
[1], &opP
->disp
, 0, 0);
2375 case 'b': /* Danger: These do no check for
2376 certain types of overflow.
2378 if (!isbyte (tmpreg
))
2379 opP
->error
= "out of range";
2380 insop (tmpreg
, opcode
);
2381 if (isvar (&opP
->disp
))
2382 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2383 (opcode
->m_codenum
) * 2 + 1;
2386 if (!issbyte (tmpreg
))
2387 opP
->error
= "out of range";
2388 opcode
->m_opcode
|= tmpreg
;
2389 if (isvar (&opP
->disp
))
2390 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2393 if (!isword (tmpreg
))
2394 opP
->error
= "out of range";
2395 insop (tmpreg
, opcode
);
2396 if (isvar (&opP
->disp
))
2397 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2400 if (!issword (tmpreg
))
2401 opP
->error
= "out of range";
2402 insop (tmpreg
, opcode
);
2403 if (isvar (&opP
->disp
))
2404 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2407 /* Because of the way insop works, we put these two out
2409 insop (tmpreg
, opcode
);
2410 insop (tmpreg
>> 16, opcode
);
2411 if (isvar (&opP
->disp
))
2412 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2419 install_operand (s
[1], tmpreg
);
2430 install_operand (s
[1], opP
->reg
- ADDR
);
2434 tmpreg
= get_num (&opP
->disp
, 80);
2438 /* The pc_fix argument winds up in fx_pcrel_adjust,
2439 which is a char, and may therefore be unsigned. We
2440 want to pass -1, but we pass 64 instead, and convert
2441 back in md_pcrel_from. */
2442 add_fix ('B', &opP
->disp
, 1, 64);
2445 add_fix ('w', &opP
->disp
, 1, 0);
2450 if (!HAVE_LONG_BRANCH(current_architecture
))
2451 as_warn ("Can't use long branches on 68000/68010/5200");
2452 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2453 add_fix ('l', &opP
->disp
, 1, 0);
2458 if (subs (&opP
->disp
)) /* We can't relax it */
2462 /* If the displacement needs pic relocation it cannot be
2464 if (opP
->disp
.pic_reloc
!= pic_none
)
2468 /* This could either be a symbol, or an absolute
2469 address. No matter, the frag hacking will finger it
2470 out. Not quite: it can't switch from BRANCH to
2471 BCC68000 for the case where opnd is absolute (it
2472 needs to use the 68000 hack since no conditional abs
2474 if (( !HAVE_LONG_BRANCH(current_architecture
)
2475 || (0 == adds (&opP
->disp
)))
2476 && (the_ins
.opcode
[0] >= 0x6200)
2477 && (the_ins
.opcode
[0] <= 0x6f00))
2478 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2479 TAB (BCC68000
, SZ_UNDEF
));
2481 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2482 TAB (ABRANCH
, SZ_UNDEF
));
2485 if (isvar (&opP
->disp
))
2488 /* check for DBcc instruction */
2489 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2491 /* size varies if patch */
2492 /* needed for long form */
2493 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2494 TAB (DBCC
, SZ_UNDEF
));
2498 add_fix ('w', &opP
->disp
, 1, 0);
2502 case 'C': /* Fixed size LONG coproc branches */
2503 add_fix ('l', &opP
->disp
, 1, 0);
2507 case 'c': /* Var size Coprocesssor branches */
2508 if (subs (&opP
->disp
))
2510 add_fix ('l', &opP
->disp
, 1, 0);
2511 add_frag ((symbolS
*) 0, (offsetT
) 0, TAB (FBRANCH
, LONG
));
2513 else if (adds (&opP
->disp
))
2514 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2515 TAB (FBRANCH
, SZ_UNDEF
));
2518 /* add_frag ((symbolS *) 0, offs (&opP->disp),
2519 TAB(FBRANCH,SHORT)); */
2520 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2521 add_fix ('l', &opP
->disp
, 1, 0);
2531 case 'C': /* Ignore it */
2534 case 'd': /* JF this is a kludge */
2535 install_operand ('s', opP
->reg
- ADDR
);
2536 tmpreg
= get_num (&opP
->disp
, 80);
2537 if (!issword (tmpreg
))
2539 as_warn ("Expression out of range, using 0");
2546 install_operand (s
[1], opP
->reg
- DATA
);
2550 install_operand (s
[1], opP
->reg
- FP0
);
2554 tmpreg
= opP
->reg
- COP0
;
2555 install_operand (s
[1], tmpreg
);
2558 case 'J': /* JF foo */
2631 install_operand (s
[1], tmpreg
);
2635 tmpreg
= get_num (&opP
->disp
, 55);
2636 install_operand (s
[1], tmpreg
& 0x7f);
2643 if (tmpreg
& 0x7FF0000)
2644 as_bad ("Floating point register in register list");
2645 insop (reverse_16_bits (tmpreg
), opcode
);
2649 if (tmpreg
& 0x700FFFF)
2650 as_bad ("Wrong register in floating-point reglist");
2651 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2659 if (tmpreg
& 0x7FF0000)
2660 as_bad ("Floating point register in register list");
2661 insop (tmpreg
, opcode
);
2663 else if (s
[1] == '8')
2665 if (tmpreg
& 0x0FFFFFF)
2666 as_bad ("incorrect register in reglist");
2667 install_operand (s
[1], tmpreg
>> 24);
2671 if (tmpreg
& 0x700FFFF)
2672 as_bad ("wrong register in floating-point reglist");
2674 install_operand (s
[1], tmpreg
>> 16);
2679 install_operand (s
[1], get_num (&opP
->disp
, 60));
2683 tmpreg
= ((opP
->mode
== DREG
)
2684 ? 0x20 + opP
->reg
- DATA
2685 : (get_num (&opP
->disp
, 40) & 0x1F));
2686 install_operand (s
[1], tmpreg
);
2690 tmpreg
= get_num (&opP
->disp
, 10);
2693 install_operand (s
[1], tmpreg
);
2697 /* This depends on the fact that ADDR registers are eight
2698 more than their corresponding DATA regs, so the result
2699 will have the ADDR_REG bit set */
2700 install_operand (s
[1], opP
->reg
- DATA
);
2704 if (opP
->mode
== AINDR
)
2705 install_operand (s
[1], opP
->reg
- DATA
);
2707 install_operand (s
[1], opP
->index
.reg
- DATA
);
2711 if (opP
->reg
== FPI
)
2713 else if (opP
->reg
== FPS
)
2715 else if (opP
->reg
== FPC
)
2719 install_operand (s
[1], tmpreg
);
2722 case 'S': /* Ignore it */
2726 install_operand (s
[1], get_num (&opP
->disp
, 30));
2729 case 'U': /* Ignore it */
2748 as_fatal ("failed sanity check");
2749 } /* switch on cache token */
2750 install_operand (s
[1], tmpreg
);
2753 /* JF: These are out of order, I fear. */
2766 install_operand (s
[1], tmpreg
);
2792 install_operand (s
[1], tmpreg
);
2796 if (opP
->reg
== VAL
)
2815 install_operand (s
[1], tmpreg
);
2829 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2840 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2846 install_operand (s
[1], tmpreg
);
2849 know (opP
->reg
== PSR
);
2852 know (opP
->reg
== PCSR
);
2867 install_operand (s
[1], tmpreg
);
2870 tmpreg
= get_num (&opP
->disp
, 20);
2871 install_operand (s
[1], tmpreg
);
2873 case '_': /* used only for move16 absolute 32-bit address */
2874 tmpreg
= get_num (&opP
->disp
, 80);
2875 addword (tmpreg
>> 16);
2876 addword (tmpreg
& 0xFFFF);
2883 /* By the time whe get here (FINALLY) the_ins contains the complete
2884 instruction, ready to be emitted. . . */
2888 reverse_16_bits (in
)
2894 static int mask
[16] =
2896 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2897 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2899 for (n
= 0; n
< 16; n
++)
2902 out
|= mask
[15 - n
];
2905 } /* reverse_16_bits() */
2914 static int mask
[8] =
2916 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2919 for (n
= 0; n
< 8; n
++)
2925 } /* reverse_8_bits() */
2927 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2928 (that value is chosen in the frag_var call in md_assemble). TYPE
2929 is the subtype of the frag to be generated; its primary type is
2930 rs_machine_dependent.
2932 The TYPE parameter is also used by md_convert_frag_1 and
2933 md_estimate_size_before_relax. The appropriate type of fixup will
2934 be emitted by md_convert_frag_1.
2936 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2938 install_operand (mode
, val
)
2945 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2948 the_ins
.opcode
[0] |= val
<< 9;
2951 the_ins
.opcode
[1] |= val
<< 12;
2954 the_ins
.opcode
[1] |= val
<< 6;
2957 the_ins
.opcode
[1] |= val
;
2960 the_ins
.opcode
[2] |= val
<< 12;
2963 the_ins
.opcode
[2] |= val
<< 6;
2966 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2967 three words long! */
2969 the_ins
.opcode
[2] |= val
;
2972 the_ins
.opcode
[1] |= val
<< 7;
2975 the_ins
.opcode
[1] |= val
<< 10;
2979 the_ins
.opcode
[1] |= val
<< 5;
2984 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2987 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2990 the_ins
.opcode
[0] |= val
= 0xff;
2993 the_ins
.opcode
[0] |= val
<< 9;
2996 the_ins
.opcode
[1] |= val
;
2999 the_ins
.opcode
[1] |= val
;
3000 the_ins
.numo
++; /* What a hack */
3003 the_ins
.opcode
[1] |= val
<< 4;
3011 the_ins
.opcode
[0] |= (val
<< 6);
3014 the_ins
.opcode
[1] = (val
>> 16);
3015 the_ins
.opcode
[2] = val
& 0xffff;
3019 as_fatal ("failed sanity check.");
3021 } /* install_operand() */
3024 install_gen_operand (mode
, val
)
3031 the_ins
.opcode
[0] |= val
;
3034 /* This is a kludge!!! */
3035 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3044 the_ins
.opcode
[0] |= val
;
3046 /* more stuff goes here */
3048 as_fatal ("failed sanity check.");
3050 } /* install_gen_operand() */
3053 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3054 * then deal with the bitfield hack.
3058 crack_operand (str
, opP
)
3060 register struct m68k_op
*opP
;
3062 register int parens
;
3064 register char *beg_str
;
3072 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3078 else if (*str
== ')')
3082 opP
->error
= "Extra )";
3088 if (flag_mri
&& *str
== '\'')
3089 inquote
= ! inquote
;
3091 if (!*str
&& parens
)
3093 opP
->error
= "Missing )";
3098 if (m68k_ip_op (beg_str
, opP
) != 0)
3105 c
= *++str
; /* JF bitfield hack */
3110 as_bad ("Missing operand");
3115 /* This is the guts of the machine-dependent assembler. STR points to a
3116 machine dependent instruction. This function is supposed to emit
3117 the frags/bytes it assembles to.
3121 insert_reg (regname
, regnum
)
3122 const char *regname
;
3128 #ifdef REGISTER_PREFIX
3129 if (!flag_reg_prefix_optional
)
3131 buf
[0] = REGISTER_PREFIX
;
3132 strcpy (buf
+ 1, regname
);
3137 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3138 &zero_address_frag
));
3140 for (i
= 0; regname
[i
]; i
++)
3141 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3144 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3145 &zero_address_frag
));
3154 static const struct init_entry init_table
[] =
3209 /* control registers */
3210 { "sfc", SFC
}, /* Source Function Code */
3212 { "dfc", DFC
}, /* Destination Function Code */
3214 { "cacr", CACR
}, /* Cache Control Register */
3215 { "caar", CAAR
}, /* Cache Address Register */
3217 { "usp", USP
}, /* User Stack Pointer */
3218 { "vbr", VBR
}, /* Vector Base Register */
3219 { "msp", MSP
}, /* Master Stack Pointer */
3220 { "isp", ISP
}, /* Interrupt Stack Pointer */
3222 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0 */
3223 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1 */
3224 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0 */
3225 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1 */
3227 /* 68ec040 versions of same */
3228 { "iacr0", ITT0
}, /* Instruction Access Control Register 0 */
3229 { "iacr1", ITT1
}, /* Instruction Access Control Register 0 */
3230 { "dacr0", DTT0
}, /* Data Access Control Register 0 */
3231 { "dacr1", DTT1
}, /* Data Access Control Register 0 */
3233 /* mcf5200 versions of same. The ColdFire programmer's reference
3234 manual indicated that the order is 2,3,0,1, but Ken Rose
3235 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3236 { "acr0", ITT0
}, /* Access Control Unit 0 */
3237 { "acr1", ITT1
}, /* Access Control Unit 1 */
3238 { "acr2", DTT0
}, /* Access Control Unit 2 */
3239 { "acr3", DTT1
}, /* Access Control Unit 3 */
3241 { "tc", TC
}, /* MMU Translation Control Register */
3244 { "mmusr", MMUSR
}, /* MMU Status Register */
3245 { "srp", SRP
}, /* User Root Pointer */
3246 { "urp", URP
}, /* Supervisor Root Pointer */
3251 { "rombar", ROMBAR
}, /* ROM Base Address Register */
3252 { "rambar0", RAMBAR0
}, /* ROM Base Address Register */
3253 { "rambar1", RAMBAR1
}, /* ROM Base Address Register */
3254 { "mbar", MBAR
}, /* Module Base Address Register */
3255 /* end of control registers */
3289 /* 68ec030 versions of same */
3292 /* 68ec030 access control unit, identical to 030 MMU status reg */
3295 /* Suppressed data and address registers. */
3320 for (i
= 0; init_table
[i
].name
; i
++)
3321 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3324 static int no_68851
, no_68881
;
3327 /* a.out machine type. Default to 68020. */
3328 int m68k_aout_machtype
= 2;
3340 int shorts_this_frag
;
3343 /* In MRI mode, the instruction and operands are separated by a
3344 space. Anything following the operands is a comment. The label
3345 has already been removed. */
3353 for (s
= str
; *s
!= '\0'; s
++)
3355 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3373 inquote
= ! inquote
;
3378 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3383 for (n
= 0; n
< the_ins
.numargs
; n
++)
3384 if (the_ins
.operands
[n
].error
)
3386 er
= the_ins
.operands
[n
].error
;
3392 as_bad ("%s -- statement `%s' ignored", er
, str
);
3396 /* If there is a current label, record that it marks an instruction. */
3397 if (current_label
!= NULL
)
3399 current_label
->text
= 1;
3400 current_label
= NULL
;
3403 if (the_ins
.nfrag
== 0)
3405 /* No frag hacking involved; just put it out */
3406 toP
= frag_more (2 * the_ins
.numo
);
3407 fromP
= &the_ins
.opcode
[0];
3408 for (m
= the_ins
.numo
; m
; --m
)
3410 md_number_to_chars (toP
, (long) (*fromP
), 2);
3414 /* put out symbol-dependent info */
3415 for (m
= 0; m
< the_ins
.nrel
; m
++)
3417 switch (the_ins
.reloc
[m
].wid
)
3436 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3437 the_ins
.reloc
[m
].wid
);
3440 fixP
= fix_new_exp (frag_now
,
3441 ((toP
- frag_now
->fr_literal
)
3442 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3444 &the_ins
.reloc
[m
].exp
,
3445 the_ins
.reloc
[m
].pcrel
,
3446 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3447 the_ins
.reloc
[m
].pic_reloc
));
3448 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3449 if (the_ins
.reloc
[m
].wid
== 'B')
3450 fixP
->fx_signed
= 1;
3455 /* There's some frag hacking */
3456 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3461 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3463 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3464 toP
= frag_more (wid
);
3466 shorts_this_frag
= 0;
3467 for (m
= wid
/ 2; m
; --m
)
3469 md_number_to_chars (toP
, (long) (*fromP
), 2);
3474 for (m
= 0; m
< the_ins
.nrel
; m
++)
3476 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3478 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3481 wid
= the_ins
.reloc
[m
].wid
;
3484 the_ins
.reloc
[m
].wid
= 0;
3485 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3487 fixP
= fix_new_exp (frag_now
,
3488 ((toP
- frag_now
->fr_literal
)
3489 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3491 &the_ins
.reloc
[m
].exp
,
3492 the_ins
.reloc
[m
].pcrel
,
3493 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3494 the_ins
.reloc
[m
].pic_reloc
));
3495 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3497 (void) frag_var (rs_machine_dependent
, 10, 0,
3498 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3499 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3501 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3502 shorts_this_frag
= 0;
3505 toP
= frag_more (n
* sizeof (short));
3508 md_number_to_chars (toP
, (long) (*fromP
), 2);
3514 for (m
= 0; m
< the_ins
.nrel
; m
++)
3518 wid
= the_ins
.reloc
[m
].wid
;
3521 the_ins
.reloc
[m
].wid
= 0;
3522 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3524 fixP
= fix_new_exp (frag_now
,
3525 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3526 - shorts_this_frag
* 2),
3528 &the_ins
.reloc
[m
].exp
,
3529 the_ins
.reloc
[m
].pcrel
,
3530 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3531 the_ins
.reloc
[m
].pic_reloc
));
3532 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3540 * md_begin -- set up hash tables with 68000 instructions.
3541 * similar to what the vax assembler does. ---phr
3543 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3544 a copy of it at runtime, adding in the information we want but isn't
3545 there. I think it'd be better to have an awk script hack the table
3546 at compile time. Or even just xstr the table and use it as-is. But
3547 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3550 register const struct m68k_opcode
*ins
;
3551 register struct m68k_incant
*hack
, *slak
;
3552 register const char *retval
= 0; /* empty string, or error msg text */
3553 register unsigned int i
;
3558 flag_reg_prefix_optional
= 1;
3560 if (! m68k_rel32_from_cmdline
)
3564 op_hash
= hash_new ();
3566 obstack_begin (&robyn
, 4000);
3567 for (i
= 0; i
< m68k_numopcodes
; i
++)
3569 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3572 ins
= &m68k_opcodes
[i
];
3573 /* We *could* ignore insns that don't match our arch here
3574 but just leaving them out of the hash. */
3575 slak
->m_operands
= ins
->args
;
3576 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3577 slak
->m_arch
= ins
->arch
;
3578 slak
->m_opcode
= ins
->opcode
;
3579 /* This is kludgey */
3580 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3581 if (i
+ 1 != m68k_numopcodes
3582 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3584 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3589 slak
= slak
->m_next
;
3593 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3595 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3598 for (i
= 0; i
< m68k_numaliases
; i
++)
3600 const char *name
= m68k_opcode_aliases
[i
].primary
;
3601 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3602 PTR val
= hash_find (op_hash
, name
);
3604 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3605 retval
= hash_insert (op_hash
, alias
, val
);
3607 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3610 /* In MRI mode, all unsized branches are variable sized. Normally,
3611 they are word sized. */
3614 static struct m68k_opcode_alias mri_aliases
[] =
3634 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3636 const char *name
= mri_aliases
[i
].primary
;
3637 const char *alias
= mri_aliases
[i
].alias
;
3638 PTR val
= hash_find (op_hash
, name
);
3640 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3641 retval
= hash_jam (op_hash
, alias
, val
);
3643 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3647 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3648 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3650 for (i
= 0; i
< sizeof (notend_table
); i
++)
3652 notend_table
[i
] = 0;
3653 alt_notend_table
[i
] = 0;
3655 notend_table
[','] = 1;
3656 notend_table
['{'] = 1;
3657 notend_table
['}'] = 1;
3658 alt_notend_table
['a'] = 1;
3659 alt_notend_table
['A'] = 1;
3660 alt_notend_table
['d'] = 1;
3661 alt_notend_table
['D'] = 1;
3662 alt_notend_table
['#'] = 1;
3663 alt_notend_table
['&'] = 1;
3664 alt_notend_table
['f'] = 1;
3665 alt_notend_table
['F'] = 1;
3666 #ifdef REGISTER_PREFIX
3667 alt_notend_table
[REGISTER_PREFIX
] = 1;
3670 /* We need to put '(' in alt_notend_table to handle
3671 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3673 alt_notend_table
['('] = 1;
3675 /* We need to put '@' in alt_notend_table to handle
3676 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3678 alt_notend_table
['@'] = 1;
3680 /* We need to put digits in alt_notend_table to handle
3681 bfextu %d0{24:1},%d0
3683 alt_notend_table
['0'] = 1;
3684 alt_notend_table
['1'] = 1;
3685 alt_notend_table
['2'] = 1;
3686 alt_notend_table
['3'] = 1;
3687 alt_notend_table
['4'] = 1;
3688 alt_notend_table
['5'] = 1;
3689 alt_notend_table
['6'] = 1;
3690 alt_notend_table
['7'] = 1;
3691 alt_notend_table
['8'] = 1;
3692 alt_notend_table
['9'] = 1;
3694 #ifndef MIT_SYNTAX_ONLY
3695 /* Insert pseudo ops, these have to go into the opcode table since
3696 gas expects pseudo ops to start with a dot */
3699 while (mote_pseudo_table
[n
].poc_name
)
3701 hack
= (struct m68k_incant
*)
3702 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3703 hash_insert (op_hash
,
3704 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3705 hack
->m_operands
= 0;
3715 record_alignment (text_section
, 2);
3716 record_alignment (data_section
, 2);
3717 record_alignment (bss_section
, 2);
3722 select_control_regs ()
3724 /* Note which set of "movec" control registers is available. */
3725 switch (cpu_of_arch (current_architecture
))
3728 control_regs
= m68000_control_regs
;
3731 control_regs
= m68010_control_regs
;
3735 control_regs
= m68020_control_regs
;
3738 control_regs
= m68040_control_regs
;
3741 control_regs
= m68060_control_regs
;
3744 control_regs
= cpu32_control_regs
;
3747 control_regs
= mcf5200_control_regs
;
3755 m68k_init_after_args ()
3757 if (cpu_of_arch (current_architecture
) == 0)
3760 const char *default_cpu
= TARGET_CPU
;
3762 if (*default_cpu
== 'm')
3764 for (i
= 0; i
< n_archs
; i
++)
3765 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3769 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3770 current_architecture
|= m68020
;
3773 current_architecture
|= archs
[i
].arch
;
3775 /* Permit m68881 specification with all cpus; those that can't work
3776 with a coprocessor could be doing emulation. */
3777 if (current_architecture
& m68851
)
3779 if (current_architecture
& m68040
)
3781 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3784 /* What other incompatibilities could we check for? */
3786 /* Toss in some default assumptions about coprocessors. */
3788 && (cpu_of_arch (current_architecture
)
3789 /* Can CPU32 have a 68881 coprocessor?? */
3790 & (m68020
| m68030
| cpu32
)))
3792 current_architecture
|= m68881
;
3795 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3796 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3798 current_architecture
|= m68851
;
3800 if (no_68881
&& (current_architecture
& m68881
))
3801 as_bad ("options for 68881 and no-68881 both given");
3802 if (no_68851
&& (current_architecture
& m68851
))
3803 as_bad ("options for 68851 and no-68851 both given");
3806 /* Work out the magic number. This isn't very general. */
3807 if (current_architecture
& m68000
)
3808 m68k_aout_machtype
= 0;
3809 else if (current_architecture
& m68010
)
3810 m68k_aout_machtype
= 1;
3811 else if (current_architecture
& m68020
)
3812 m68k_aout_machtype
= 2;
3814 m68k_aout_machtype
= 2;
3817 /* Note which set of "movec" control registers is available. */
3818 select_control_regs ();
3820 if (cpu_of_arch (current_architecture
) < m68020
)
3821 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3824 /* This is called when a label is defined. */
3827 m68k_frob_label (sym
)
3830 struct label_line
*n
;
3832 n
= (struct label_line
*) xmalloc (sizeof *n
);
3835 as_where (&n
->file
, &n
->line
);
3841 /* This is called when a value that is not an instruction is emitted. */
3844 m68k_flush_pending_output ()
3846 current_label
= NULL
;
3849 /* This is called at the end of the assembly, when the final value of
3850 the label is known. We warn if this is a text symbol aligned at an
3854 m68k_frob_symbol (sym
)
3857 if ((S_GET_VALUE (sym
) & 1) != 0)
3859 struct label_line
*l
;
3861 for (l
= labels
; l
!= NULL
; l
= l
->next
)
3863 if (l
->label
== sym
)
3866 as_warn_where (l
->file
, l
->line
,
3867 "text label `%s' aligned to odd boundary",
3875 /* This is called if we go in or out of MRI mode because of the .mri
3879 m68k_mri_mode_change (on
)
3884 if (! flag_reg_prefix_optional
)
3886 flag_reg_prefix_optional
= 1;
3887 #ifdef REGISTER_PREFIX
3892 if (! m68k_rel32_from_cmdline
)
3897 if (! reg_prefix_optional_seen
)
3899 #ifdef REGISTER_PREFIX_OPTIONAL
3900 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
3902 flag_reg_prefix_optional
= 0;
3904 #ifdef REGISTER_PREFIX
3909 if (! m68k_rel32_from_cmdline
)
3914 /* Equal to MAX_PRECISION in atof-ieee.c */
3915 #define MAX_LITTLENUMS 6
3917 /* Turn a string in input_line_pointer into a floating point constant
3918 of type type, and store the appropriate bytes in *litP. The number
3919 of LITTLENUMS emitted is stored in *sizeP . An error message is
3920 returned, or NULL on OK. */
3923 md_atof (type
, litP
, sizeP
)
3929 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3930 LITTLENUM_TYPE
*wordP
;
3961 return "Bad call to MD_ATOF()";
3963 t
= atof_ieee (input_line_pointer
, type
, words
);
3965 input_line_pointer
= t
;
3967 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3968 for (wordP
= words
; prec
--;)
3970 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3971 litP
+= sizeof (LITTLENUM_TYPE
);
3977 md_number_to_chars (buf
, val
, n
)
3982 number_to_chars_bigendian (buf
, val
, n
);
3986 md_apply_fix_2 (fixP
, val
)
3990 addressT upper_limit
;
3991 offsetT lower_limit
;
3993 /* This is unnecessary but it convinces the native rs6000 compiler
3994 to generate the code we want. */
3995 char *buf
= fixP
->fx_frag
->fr_literal
;
3996 buf
+= fixP
->fx_where
;
3997 /* end ibm compiler workaround */
3999 if (val
& 0x80000000)
4000 val
|= ~(addressT
)0x7fffffff;
4007 memset (buf
, 0, fixP
->fx_size
);
4008 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
4013 switch (fixP
->fx_size
)
4015 /* The cast to offsetT below are necessary to make code correct for
4016 machines where ints are smaller than offsetT */
4020 lower_limit
= - (offsetT
) 0x80;
4023 *buf
++ = (val
>> 8);
4025 upper_limit
= 0x7fff;
4026 lower_limit
= - (offsetT
) 0x8000;
4029 *buf
++ = (val
>> 24);
4030 *buf
++ = (val
>> 16);
4031 *buf
++ = (val
>> 8);
4033 upper_limit
= 0x7fffffff;
4034 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
4037 BAD_CASE (fixP
->fx_size
);
4040 /* Fix up a negative reloc. */
4041 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4043 fixP
->fx_addsy
= fixP
->fx_subsy
;
4044 fixP
->fx_subsy
= NULL
;
4048 /* For non-pc-relative values, it's conceivable we might get something
4049 like "0xff" for a byte field. So extend the upper part of the range
4050 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4051 so that we can do any range checking at all. */
4052 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4053 upper_limit
= upper_limit
* 2 + 1;
4055 if ((addressT
) val
> upper_limit
4056 && (val
> 0 || val
< lower_limit
))
4057 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
4059 /* A one byte PC-relative reloc means a short branch. We can't use
4060 a short branch with a value of 0 or -1, because those indicate
4061 different opcodes (branches with longer offsets). fixup_segment
4062 in write.c may have clobbered fx_pcrel, so we need to examine the
4065 #ifdef BFD_ASSEMBLER
4066 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
4069 && fixP
->fx_size
== 1
4070 && (fixP
->fx_addsy
== NULL
4071 || S_IS_DEFINED (fixP
->fx_addsy
))
4072 && (val
== 0 || val
== -1))
4073 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
4076 #ifdef BFD_ASSEMBLER
4078 md_apply_fix (fixP
, valp
)
4082 md_apply_fix_2 (fixP
, (addressT
) *valp
);
4086 void md_apply_fix (fixP
, val
)
4090 md_apply_fix_2 (fixP
, (addressT
) val
);
4094 /* *fragP has been relaxed to its final size, and now needs to have
4095 the bytes inside it modified to conform to the new size There is UGLY
4099 md_convert_frag_1 (fragP
)
4100 register fragS
*fragP
;
4106 /* Address in object code of the displacement. */
4107 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4109 /* Address in gas core of the place to store the displacement. */
4110 /* This convinces the native rs6000 compiler to generate the code we
4112 register char *buffer_address
= fragP
->fr_literal
;
4113 buffer_address
+= fragP
->fr_fix
;
4114 /* end ibm compiler workaround */
4116 /* The displacement of the address, from current location. */
4117 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4118 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4120 #ifdef BFD_ASSEMBLER
4121 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
4124 switch (fragP
->fr_subtype
)
4126 case TAB (BCC68000
, BYTE
):
4127 case TAB (ABRANCH
, BYTE
):
4128 know (issbyte (disp
));
4130 as_bad ("short branch with zero offset: use :w");
4131 fragP
->fr_opcode
[1] = disp
;
4134 case TAB (DBCC
, SHORT
):
4135 know (issword (disp
));
4138 case TAB (BCC68000
, SHORT
):
4139 case TAB (ABRANCH
, SHORT
):
4140 know (issword (disp
));
4141 fragP
->fr_opcode
[1] = 0x00;
4144 case TAB (ABRANCH
, LONG
):
4145 if (!HAVE_LONG_BRANCH(current_architecture
))
4147 if (fragP
->fr_opcode
[0] == 0x61)
4150 fragP
->fr_opcode
[0] = 0x4E;
4151 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4165 else if (fragP
->fr_opcode
[0] == 0x60)
4167 fragP
->fr_opcode
[0] = 0x4E;
4168 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4169 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4170 fragP
->fr_offset
, 0, NO_RELOC
);
4176 as_bad ("Long branch offset not supported.");
4181 fragP
->fr_opcode
[1] = (char) 0xff;
4185 case TAB (BCC68000
, LONG
):
4186 /* only Bcc 68000 instructions can come here */
4187 /* change bcc into b!cc/jmp absl long */
4188 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4189 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4191 /* JF: these used to be fr_opcode[2,3], but they may be in a
4192 different frag, in which case refering to them is a no-no.
4193 Only fr_opcode[0,1] are guaranteed to work. */
4194 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4195 *buffer_address
++ = (char) 0xf9;
4196 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4197 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4198 fragP
->fr_offset
, 0, NO_RELOC
);
4202 case TAB (DBCC
, LONG
):
4203 /* only DBcc 68000 instructions can come here */
4204 /* change dbcc into dbcc/jmp absl long */
4205 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4206 *buffer_address
++ = 0x00; /* branch offset = 4 */
4207 *buffer_address
++ = 0x04;
4208 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4209 *buffer_address
++ = 0x06;
4210 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4211 *buffer_address
++ = (char) 0xf9;
4213 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4214 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4215 fragP
->fr_offset
, 0, NO_RELOC
);
4219 case TAB (FBRANCH
, SHORT
):
4220 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4223 case TAB (FBRANCH
, LONG
):
4224 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4227 case TAB (PCREL
, SHORT
):
4230 case TAB (PCREL
, LONG
):
4231 /* The thing to do here is force it to ABSOLUTE LONG, since
4232 PCREL is really trying to shorten an ABSOLUTE address anyway */
4233 /* JF FOO This code has not been tested */
4234 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4236 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4237 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
4238 (unsigned) fragP
->fr_opcode
[0],
4239 (unsigned long) fragP
->fr_address
);
4240 fragP
->fr_opcode
[1] &= ~0x3F;
4241 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4245 case TAB (PCLEA
, SHORT
):
4246 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4247 fragP
->fr_offset
, 1, NO_RELOC
);
4248 fragP
->fr_opcode
[1] &= ~0x3F;
4249 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4252 case TAB (PCLEA
, LONG
):
4253 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4254 fragP
->fr_offset
, 1, NO_RELOC
);
4255 fixP
->fx_pcrel_adjust
= 2;
4256 /* Already set to mode 7.3; this indicates: PC indirect with
4257 suppressed index, 32-bit displacement. */
4258 *buffer_address
++ = 0x01;
4259 *buffer_address
++ = 0x70;
4264 case TAB (PCINDEX
, BYTE
):
4266 if (!issbyte (disp
))
4268 as_bad ("displacement doesn't fit in one byte");
4271 assert (fragP
->fr_fix
>= 2);
4272 buffer_address
[-2] &= ~1;
4273 buffer_address
[-1] = disp
;
4276 case TAB (PCINDEX
, SHORT
):
4278 assert (issword (disp
));
4279 assert (fragP
->fr_fix
>= 2);
4280 buffer_address
[-2] |= 0x1;
4281 buffer_address
[-1] = 0x20;
4282 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4283 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4285 fixP
->fx_pcrel_adjust
= 2;
4288 case TAB (PCINDEX
, LONG
):
4290 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4291 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4293 fixP
->fx_pcrel_adjust
= 2;
4294 assert (fragP
->fr_fix
>= 2);
4295 buffer_address
[-2] |= 0x1;
4296 buffer_address
[-1] = 0x30;
4303 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4304 fragP
->fr_fix
+= ext
;
4308 #ifndef BFD_ASSEMBLER
4311 md_convert_frag (headers
, sec
, fragP
)
4312 object_headers
*headers
;
4316 md_convert_frag_1 (fragP
);
4322 md_convert_frag (abfd
, sec
, fragP
)
4327 md_convert_frag_1 (fragP
);
4331 /* Force truly undefined symbols to their maximum size, and generally set up
4332 the frag list to be relaxed
4335 md_estimate_size_before_relax (fragP
, segment
)
4336 register fragS
*fragP
;
4340 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4342 old_fix
= fragP
->fr_fix
;
4344 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4345 switch (fragP
->fr_subtype
)
4348 case TAB (ABRANCH
, SZ_UNDEF
):
4350 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4351 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4353 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4356 else if ((fragP
->fr_symbol
== 0) || !HAVE_LONG_BRANCH(current_architecture
))
4358 /* On 68000, or for absolute value, switch to abs long */
4359 /* FIXME, we should check abs val, pick short or long */
4360 if (fragP
->fr_opcode
[0] == 0x61)
4362 fragP
->fr_opcode
[0] = 0x4E;
4363 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4364 fix_new (fragP
, fragP
->fr_fix
, 4,
4365 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4369 else if (fragP
->fr_opcode
[0] == 0x60)
4371 fragP
->fr_opcode
[0] = 0x4E;
4372 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4373 fix_new (fragP
, fragP
->fr_fix
, 4,
4374 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4380 as_warn ("Long branch offset to extern symbol not supported.");
4384 { /* Symbol is still undefined. Make it simple */
4385 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4386 fragP
->fr_offset
, 1, NO_RELOC
);
4388 fragP
->fr_opcode
[1] = (char) 0xff;
4394 } /* case TAB(ABRANCH,SZ_UNDEF) */
4396 case TAB (FBRANCH
, SZ_UNDEF
):
4398 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
4400 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4405 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4406 fragP
->fr_offset
, 1, NO_RELOC
);
4408 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4412 } /* TAB(FBRANCH,SZ_UNDEF) */
4414 case TAB (PCREL
, SZ_UNDEF
):
4416 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4418 || cpu_of_arch (current_architecture
) < m68020
)
4420 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4425 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4429 } /* TAB(PCREL,SZ_UNDEF) */
4431 case TAB (BCC68000
, SZ_UNDEF
):
4433 if ((fragP
->fr_symbol
!= NULL
)
4434 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4436 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4439 /* only Bcc 68000 instructions can come here */
4440 /* change bcc into b!cc/jmp absl long */
4441 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4442 if (flag_short_refs
)
4444 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4445 /* JF: these were fr_opcode[2,3] */
4446 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4447 buffer_address
[1] = (char) 0xf8;
4448 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4449 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4450 fragP
->fr_offset
, 0, NO_RELOC
);
4455 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4456 /* JF: these were fr_opcode[2,3] */
4457 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4458 buffer_address
[1] = (char) 0xf9;
4459 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4460 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4461 fragP
->fr_offset
, 0, NO_RELOC
);
4466 } /* case TAB(BCC68000,SZ_UNDEF) */
4468 case TAB (DBCC
, SZ_UNDEF
):
4470 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4472 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4476 /* only DBcc 68000 instructions can come here */
4477 /* change dbcc into dbcc/jmp absl long */
4478 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4479 buffer_address
[0] = 0x00; /* branch offset = 4 */
4480 buffer_address
[1] = 0x04;
4481 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4483 if (flag_short_refs
)
4485 /* JF: these were fr_opcode[5-7] */
4486 buffer_address
[3] = 0x04; /* plus 4 */
4487 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4488 buffer_address
[5] = (char) 0xf8;
4489 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4490 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4491 fragP
->fr_offset
, 0, NO_RELOC
);
4496 /* JF: these were fr_opcode[5-7] */
4497 buffer_address
[3] = 0x06; /* Plus 6 */
4498 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4499 buffer_address
[5] = (char) 0xf9;
4500 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4501 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4502 fragP
->fr_offset
, 0, NO_RELOC
);
4508 } /* case TAB(DBCC,SZ_UNDEF) */
4510 case TAB (PCLEA
, SZ_UNDEF
):
4512 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4514 || cpu_of_arch (current_architecture
) < m68020
)
4516 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4521 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4525 } /* TAB(PCLEA,SZ_UNDEF) */
4527 case TAB (PCINDEX
, SZ_UNDEF
):
4528 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4529 || cpu_of_arch (current_architecture
) < m68020
)
4531 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4535 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4544 /* now that SZ_UNDEF are taken care of, check others */
4545 switch (fragP
->fr_subtype
)
4547 case TAB (BCC68000
, BYTE
):
4548 case TAB (ABRANCH
, BYTE
):
4549 /* We can't do a short jump to the next instruction, so in that
4550 case we force word mode. At this point S_GET_VALUE should
4551 return the offset of the symbol within its frag. If the
4552 symbol is at the start of a frag, and it is the next frag
4553 with any data in it (usually this is just the next frag, but
4554 assembler listings may introduce empty frags), we must use
4556 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0)
4560 for (l
= fragP
->fr_next
;
4561 l
!= fragP
->fr_symbol
->sy_frag
;
4563 if (l
->fr_fix
+ l
->fr_var
!= 0)
4565 if (l
== fragP
->fr_symbol
->sy_frag
)
4567 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4575 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4578 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4579 /* the bit-field entries in the relocation_info struct plays hell
4580 with the byte-order problems of cross-assembly. So as a hack,
4581 I added this mach. dependent ri twiddler. Ugly, but it gets
4583 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4584 are symbolnum, most sig. byte first. Last byte is broken up with
4585 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4586 nibble as nuthin. (on Sun 3 at least) */
4587 /* Translate the internal relocation information into target-specific
4591 md_ri_to_chars (the_bytes
, ri
)
4593 struct reloc_info_generic
*ri
;
4596 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4597 /* now the fun stuff */
4598 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4599 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4600 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4601 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4602 ((ri
->r_extern
<< 4) & 0x10));
4605 #endif /* comment */
4607 #ifndef BFD_ASSEMBLER
4609 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4612 relax_addressT segment_address_in_file
;
4615 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4616 * Out: GNU LD relocation length code: 0, 1, or 2.
4619 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4622 know (fixP
->fx_addsy
!= NULL
);
4624 md_number_to_chars (where
,
4625 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4628 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4629 ? S_GET_TYPE (fixP
->fx_addsy
)
4630 : fixP
->fx_addsy
->sy_number
);
4632 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4633 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4634 where
[6] = r_symbolnum
& 0x0ff;
4635 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4636 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4640 #endif /* OBJ_AOUT or OBJ_BOUT */
4642 #ifndef WORKING_DOT_WORD
4643 CONST
int md_short_jump_size
= 4;
4644 CONST
int md_long_jump_size
= 6;
4647 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4649 addressT from_addr
, to_addr
;
4655 offset
= to_addr
- (from_addr
+ 2);
4657 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4658 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4662 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4664 addressT from_addr
, to_addr
;
4670 if (!HAVE_LONG_BRANCH(current_architecture
))
4672 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4673 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4674 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4675 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4680 offset
= to_addr
- (from_addr
+ 2);
4681 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4682 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4688 /* Different values of OK tell what its OK to return. Things that
4689 aren't OK are an error (what a shock, no?)
4692 10: Absolute 1:8 only
4693 20: Absolute 0:7 only
4694 30: absolute 0:15 only
4695 40: Absolute 0:31 only
4696 50: absolute 0:127 only
4697 55: absolute -64:63 only
4698 60: absolute -128:127 only
4699 70: absolute 0:4095 only
4706 struct m68k_exp
*exp
;
4709 if (exp
->exp
.X_op
== O_absent
)
4711 /* Do the same thing the VAX asm does */
4712 op (exp
) = O_constant
;
4718 as_warn ("expression out of range: defaulting to 1");
4722 else if (exp
->exp
.X_op
== O_constant
)
4727 if (offs (exp
) < 1 || offs (exp
) > 8)
4729 as_warn ("expression out of range: defaulting to 1");
4734 if (offs (exp
) < 0 || offs (exp
) > 7)
4738 if (offs (exp
) < 0 || offs (exp
) > 15)
4742 if (offs (exp
) < 0 || offs (exp
) > 32)
4746 if (offs (exp
) < 0 || offs (exp
) > 127)
4750 if (offs (exp
) < -64 || offs (exp
) > 63)
4754 if (offs (exp
) < -128 || offs (exp
) > 127)
4758 if (offs (exp
) < 0 || offs (exp
) > 4095)
4761 as_warn ("expression out of range: defaulting to 0");
4769 else if (exp
->exp
.X_op
== O_big
)
4771 if (offs (exp
) <= 0 /* flonum */
4772 && (ok
== 80 /* no bignums */
4773 || (ok
> 10 /* small-int ranges including 0 ok */
4774 /* If we have a flonum zero, a zero integer should
4775 do as well (e.g., in moveq). */
4776 && generic_floating_point_number
.exponent
== 0
4777 && generic_floating_point_number
.low
[0] == 0)))
4779 /* HACK! Turn it into a long */
4780 LITTLENUM_TYPE words
[6];
4782 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4783 op (exp
) = O_constant
;
4786 offs (exp
) = words
[1] | (words
[0] << 16);
4790 op (exp
) = O_constant
;
4793 offs (exp
) = (ok
== 10) ? 1 : 0;
4794 as_warn ("Can't deal with expression; defaulting to %ld",
4800 if (ok
>= 10 && ok
<= 70)
4802 op (exp
) = O_constant
;
4805 offs (exp
) = (ok
== 10) ? 1 : 0;
4806 as_warn ("Can't deal with expression; defaulting to %ld",
4811 if (exp
->size
!= SIZE_UNSPEC
)
4819 if (!isbyte (offs (exp
)))
4820 as_warn ("expression doesn't fit in BYTE");
4823 if (!isword (offs (exp
)))
4824 as_warn ("expression doesn't fit in WORD");
4832 /* These are the back-ends for the various machine dependent pseudo-ops. */
4838 subseg_set (data_section
, 1);
4839 demand_empty_rest_of_line ();
4846 subseg_set (data_section
, 2);
4847 demand_empty_rest_of_line ();
4854 /* We don't support putting frags in the BSS segment, we fake it
4855 by marking in_bss, then looking at s_skip for clues. */
4857 subseg_set (bss_section
, 0);
4858 demand_empty_rest_of_line ();
4866 register long temp_fill
;
4868 temp
= 1; /* JF should be 2? */
4869 temp_fill
= get_absolute_expression ();
4870 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4871 frag_align (temp
, (int) temp_fill
, 0);
4872 demand_empty_rest_of_line ();
4873 record_alignment (now_seg
, temp
);
4880 demand_empty_rest_of_line ();
4883 /* Pseudo-ops handled for MRI compatibility. */
4885 /* This function returns non-zero if the argument is a conditional
4886 pseudo-op. This is called when checking whether a pending
4887 alignment is needed. */
4890 m68k_conditional_pseudoop (pop
)
4893 return (pop
->poc_handler
== s_mri_if
4894 || pop
->poc_handler
== s_mri_else
);
4897 /* Handle an MRI style chip specification. */
4906 s
= input_line_pointer
;
4907 /* We can't use get_symbol_end since the processor names are not proper
4909 while (is_part_of_name (c
= *input_line_pointer
++))
4911 *--input_line_pointer
= 0;
4912 for (i
= 0; i
< n_archs
; i
++)
4913 if (strcasecmp (s
, archs
[i
].name
) == 0)
4917 as_bad ("%s: unrecognized processor name", s
);
4918 *input_line_pointer
= c
;
4919 ignore_rest_of_line ();
4922 *input_line_pointer
= c
;
4924 if (*input_line_pointer
== '/')
4925 current_architecture
= 0;
4927 current_architecture
&= m68881
| m68851
;
4928 current_architecture
|= archs
[i
].arch
;
4930 while (*input_line_pointer
== '/')
4932 ++input_line_pointer
;
4933 s
= input_line_pointer
;
4934 /* We can't use get_symbol_end since the processor names are not
4936 while (is_part_of_name (c
= *input_line_pointer
++))
4938 *--input_line_pointer
= 0;
4939 if (strcmp (s
, "68881") == 0)
4940 current_architecture
|= m68881
;
4941 else if (strcmp (s
, "68851") == 0)
4942 current_architecture
|= m68851
;
4943 *input_line_pointer
= c
;
4946 /* Update info about available control registers. */
4947 select_control_regs ();
4950 /* The MRI CHIP pseudo-op. */
4960 stop
= mri_comment_field (&stopc
);
4963 mri_comment_end (stop
, stopc
);
4964 demand_empty_rest_of_line ();
4967 /* The MRI FOPT pseudo-op. */
4975 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4979 input_line_pointer
+= 3;
4980 temp
= get_absolute_expression ();
4981 if (temp
< 0 || temp
> 7)
4982 as_bad ("bad coprocessor id");
4984 m68k_float_copnum
= COP0
+ temp
;
4988 as_bad ("unrecognized fopt option");
4989 ignore_rest_of_line ();
4993 demand_empty_rest_of_line ();
4996 /* The structure used to handle the MRI OPT pseudo-op. */
5000 /* The name of the option. */
5003 /* If this is not NULL, just call this function. The first argument
5004 is the ARG field of this structure, the second argument is
5005 whether the option was negated. */
5006 void (*pfn
) PARAMS ((int arg
, int on
));
5008 /* If this is not NULL, and the PFN field is NULL, set the variable
5009 this points to. Set it to the ARG field if the option was not
5010 negated, and the NOTARG field otherwise. */
5013 /* The value to pass to PFN or to assign to *PVAR. */
5016 /* The value to assign to *PVAR if the option is negated. If PFN is
5017 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5018 the option may not be negated. */
5022 /* The table used to handle the MRI OPT pseudo-op. */
5024 static void skip_to_comma
PARAMS ((int, int));
5025 static void opt_nest
PARAMS ((int, int));
5026 static void opt_chip
PARAMS ((int, int));
5027 static void opt_list
PARAMS ((int, int));
5028 static void opt_list_symbols
PARAMS ((int, int));
5030 static const struct opt_action opt_table
[] =
5032 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5034 /* We do relaxing, so there is little use for these options. */
5035 { "b", 0, 0, 0, 0 },
5036 { "brs", 0, 0, 0, 0 },
5037 { "brb", 0, 0, 0, 0 },
5038 { "brl", 0, 0, 0, 0 },
5039 { "brw", 0, 0, 0, 0 },
5041 { "c", 0, 0, 0, 0 },
5042 { "cex", 0, 0, 0, 0 },
5043 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5044 { "cl", 0, 0, 0, 0 },
5045 { "cre", 0, 0, 0, 0 },
5046 { "d", 0, &flag_keep_locals
, 1, 0 },
5047 { "e", 0, 0, 0, 0 },
5048 { "f", 0, &flag_short_refs
, 1, 0 },
5049 { "frs", 0, &flag_short_refs
, 1, 0 },
5050 { "frl", 0, &flag_short_refs
, 0, 1 },
5051 { "g", 0, 0, 0, 0 },
5052 { "i", 0, 0, 0, 0 },
5053 { "m", 0, 0, 0, 0 },
5054 { "mex", 0, 0, 0, 0 },
5055 { "mc", 0, 0, 0, 0 },
5056 { "md", 0, 0, 0, 0 },
5057 { "nest", opt_nest
, 0, 0, 0 },
5058 { "next", skip_to_comma
, 0, 0, 0 },
5059 { "o", 0, 0, 0, 0 },
5060 { "old", 0, 0, 0, 0 },
5061 { "op", skip_to_comma
, 0, 0, 0 },
5062 { "pco", 0, 0, 0, 0 },
5063 { "p", opt_chip
, 0, 0, 0 },
5064 { "pcr", 0, 0, 0, 0 },
5065 { "pcs", 0, 0, 0, 0 },
5066 { "r", 0, 0, 0, 0 },
5067 { "quick", 0, &m68k_quick
, 1, 0 },
5068 { "rel32", 0, &m68k_rel32
, 1, 0 },
5069 { "s", opt_list
, 0, 0, 0 },
5070 { "t", opt_list_symbols
, 0, 0, 0 },
5071 { "w", 0, &flag_no_warnings
, 0, 1 },
5075 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
5077 /* The MRI OPT pseudo-op. */
5089 const struct opt_action
*o
;
5094 if (*input_line_pointer
== '-')
5096 ++input_line_pointer
;
5099 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5101 input_line_pointer
+= 2;
5105 s
= input_line_pointer
;
5106 c
= get_symbol_end ();
5108 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5110 if (strcasecmp (s
, o
->name
) == 0)
5114 /* Restore input_line_pointer now in case the option
5116 *input_line_pointer
= c
;
5117 (*o
->pfn
) (o
->arg
, t
);
5119 else if (o
->pvar
!= NULL
)
5121 if (! t
&& o
->arg
== o
->notarg
)
5122 as_bad ("option `%s' may not be negated", s
);
5123 *input_line_pointer
= c
;
5124 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5127 *input_line_pointer
= c
;
5133 as_bad ("option `%s' not recognized", s
);
5134 *input_line_pointer
= c
;
5137 while (*input_line_pointer
++ == ',');
5139 /* Move back to terminating character. */
5140 --input_line_pointer
;
5141 demand_empty_rest_of_line ();
5144 /* Skip ahead to a comma. This is used for OPT options which we do
5145 not suppor tand which take arguments. */
5148 skip_to_comma (arg
, on
)
5152 while (*input_line_pointer
!= ','
5153 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5154 ++input_line_pointer
;
5157 /* Handle the OPT NEST=depth option. */
5164 if (*input_line_pointer
!= '=')
5166 as_bad ("bad format of OPT NEST=depth");
5170 ++input_line_pointer
;
5171 max_macro_nest
= get_absolute_expression ();
5174 /* Handle the OPT P=chip option. */
5181 if (*input_line_pointer
!= '=')
5183 /* This is just OPT P, which we do not support. */
5187 ++input_line_pointer
;
5191 /* Handle the OPT S option. */
5201 /* Handle the OPT T option. */
5204 opt_list_symbols (arg
, on
)
5209 listing
|= LISTING_SYMBOLS
;
5211 listing
&=~ LISTING_SYMBOLS
;
5214 /* Handle the MRI REG pseudo-op. */
5227 if (line_label
== NULL
)
5229 as_bad ("missing label");
5230 ignore_rest_of_line ();
5235 stop
= mri_comment_field (&stopc
);
5239 s
= input_line_pointer
;
5240 while (isalnum ((unsigned char) *input_line_pointer
)
5241 #ifdef REGISTER_PREFIX
5242 || *input_line_pointer
== REGISTER_PREFIX
5244 || *input_line_pointer
== '/'
5245 || *input_line_pointer
== '-')
5246 ++input_line_pointer
;
5247 c
= *input_line_pointer
;
5248 *input_line_pointer
= '\0';
5250 if (m68k_ip_op (s
, &rop
) != 0)
5252 if (rop
.error
== NULL
)
5253 as_bad ("bad register list");
5255 as_bad ("bad register list: %s", rop
.error
);
5256 *input_line_pointer
= c
;
5257 ignore_rest_of_line ();
5261 *input_line_pointer
= c
;
5263 if (rop
.mode
== REGLST
)
5265 else if (rop
.mode
== DREG
)
5266 mask
= 1 << (rop
.reg
- DATA0
);
5267 else if (rop
.mode
== AREG
)
5268 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5269 else if (rop
.mode
== FPREG
)
5270 mask
= 1 << (rop
.reg
- FP0
+ 16);
5271 else if (rop
.mode
== CONTROL
5274 else if (rop
.mode
== CONTROL
5277 else if (rop
.mode
== CONTROL
5282 as_bad ("bad register list");
5283 ignore_rest_of_line ();
5287 S_SET_SEGMENT (line_label
, absolute_section
);
5288 S_SET_VALUE (line_label
, mask
);
5289 line_label
->sy_frag
= &zero_address_frag
;
5292 mri_comment_end (stop
, stopc
);
5294 demand_empty_rest_of_line ();
5297 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5301 struct save_opts
*next
;
5303 int symbols_case_sensitive
;
5311 /* FIXME: We don't save OPT S. */
5314 /* This variable holds the stack of saved options. */
5316 static struct save_opts
*save_stack
;
5318 /* The MRI SAVE pseudo-op. */
5324 struct save_opts
*s
;
5326 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5327 s
->abspcadd
= m68k_abspcadd
;
5328 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5329 s
->keep_locals
= flag_keep_locals
;
5330 s
->short_refs
= flag_short_refs
;
5331 s
->architecture
= current_architecture
;
5332 s
->quick
= m68k_quick
;
5333 s
->rel32
= m68k_rel32
;
5334 s
->listing
= listing
;
5335 s
->no_warnings
= flag_no_warnings
;
5337 s
->next
= save_stack
;
5340 demand_empty_rest_of_line ();
5343 /* The MRI RESTORE pseudo-op. */
5349 struct save_opts
*s
;
5351 if (save_stack
== NULL
)
5353 as_bad ("restore without save");
5354 ignore_rest_of_line ();
5359 save_stack
= s
->next
;
5361 m68k_abspcadd
= s
->abspcadd
;
5362 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5363 flag_keep_locals
= s
->keep_locals
;
5364 flag_short_refs
= s
->short_refs
;
5365 current_architecture
= s
->architecture
;
5366 m68k_quick
= s
->quick
;
5367 m68k_rel32
= s
->rel32
;
5368 listing
= s
->listing
;
5369 flag_no_warnings
= s
->no_warnings
;
5373 demand_empty_rest_of_line ();
5376 /* Types of MRI structured control directives. */
5378 enum mri_control_type
5386 /* This structure is used to stack the MRI structured control
5389 struct mri_control_info
5391 /* The directive within which this one is enclosed. */
5392 struct mri_control_info
*outer
;
5394 /* The type of directive. */
5395 enum mri_control_type type
;
5397 /* Whether an ELSE has been in an IF. */
5400 /* The add or sub statement at the end of a FOR. */
5403 /* The label of the top of a FOR or REPEAT loop. */
5406 /* The label to jump to for the next iteration, or the else
5407 expression of a conditional. */
5410 /* The label to jump to to break out of the loop, or the label past
5411 the end of a conditional. */
5415 /* The stack of MRI structured control directives. */
5417 static struct mri_control_info
*mri_control_stack
;
5419 /* The current MRI structured control directive index number, used to
5420 generate label names. */
5422 static int mri_control_index
;
5424 /* Some function prototypes. */
5426 static char *mri_control_label
PARAMS ((void));
5427 static struct mri_control_info
*push_mri_control
5428 PARAMS ((enum mri_control_type
));
5429 static void pop_mri_control
PARAMS ((void));
5430 static int parse_mri_condition
PARAMS ((int *));
5431 static int parse_mri_control_operand
5432 PARAMS ((int *, char **, char **, char **, char **));
5433 static int swap_mri_condition
PARAMS ((int));
5434 static int reverse_mri_condition
PARAMS ((int));
5435 static void build_mri_control_operand
5436 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5437 const char *, int));
5438 static void parse_mri_control_expression
5439 PARAMS ((char *, int, const char *, const char *, int));
5441 /* Generate a new MRI label structured control directive label name. */
5444 mri_control_label ()
5448 n
= (char *) xmalloc (20);
5449 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5450 ++mri_control_index
;
5454 /* Create a new MRI structured control directive. */
5456 static struct mri_control_info
*
5457 push_mri_control (type
)
5458 enum mri_control_type type
;
5460 struct mri_control_info
*n
;
5462 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5466 if (type
== mri_if
|| type
== mri_while
)
5469 n
->top
= mri_control_label ();
5470 n
->next
= mri_control_label ();
5471 n
->bottom
= mri_control_label ();
5473 n
->outer
= mri_control_stack
;
5474 mri_control_stack
= n
;
5479 /* Pop off the stack of MRI structured control directives. */
5484 struct mri_control_info
*n
;
5486 n
= mri_control_stack
;
5487 mri_control_stack
= n
->outer
;
5495 /* Recognize a condition code in an MRI structured control expression. */
5498 parse_mri_condition (pcc
)
5503 know (*input_line_pointer
== '<');
5505 ++input_line_pointer
;
5506 c1
= *input_line_pointer
++;
5507 c2
= *input_line_pointer
++;
5509 if (*input_line_pointer
!= '>')
5511 as_bad ("syntax error in structured control directive");
5515 ++input_line_pointer
;
5523 *pcc
= (c1
<< 8) | c2
;
5528 /* Parse a single operand in an MRI structured control expression. */
5531 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5548 if (*input_line_pointer
== '<')
5550 /* It's just a condition code. */
5551 return parse_mri_condition (pcc
);
5554 /* Look ahead for the condition code. */
5555 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5557 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5562 as_bad ("missing condition code in structured control directive");
5566 *leftstart
= input_line_pointer
;
5568 if (*leftstop
> *leftstart
5569 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5572 input_line_pointer
= s
;
5573 if (! parse_mri_condition (pcc
))
5576 /* Look ahead for AND or OR or end of line. */
5577 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5579 if ((strncasecmp (s
, "AND", 3) == 0
5580 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5581 || (strncasecmp (s
, "OR", 2) == 0
5582 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5586 *rightstart
= input_line_pointer
;
5588 if (*rightstop
> *rightstart
5589 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5592 input_line_pointer
= s
;
5597 #define MCC(b1, b2) (((b1) << 8) | (b2))
5599 /* Swap the sense of a condition. This changes the condition so that
5600 it generates the same result when the operands are swapped. */
5603 swap_mri_condition (cc
)
5608 case MCC ('h', 'i'): return MCC ('c', 's');
5609 case MCC ('l', 's'): return MCC ('c', 'c');
5610 case MCC ('c', 'c'): return MCC ('l', 's');
5611 case MCC ('c', 's'): return MCC ('h', 'i');
5612 case MCC ('p', 'l'): return MCC ('m', 'i');
5613 case MCC ('m', 'i'): return MCC ('p', 'l');
5614 case MCC ('g', 'e'): return MCC ('l', 'e');
5615 case MCC ('l', 't'): return MCC ('g', 't');
5616 case MCC ('g', 't'): return MCC ('l', 't');
5617 case MCC ('l', 'e'): return MCC ('g', 'e');
5622 /* Reverse the sense of a condition. */
5625 reverse_mri_condition (cc
)
5630 case MCC ('h', 'i'): return MCC ('l', 's');
5631 case MCC ('l', 's'): return MCC ('h', 'i');
5632 case MCC ('c', 'c'): return MCC ('c', 's');
5633 case MCC ('c', 's'): return MCC ('c', 'c');
5634 case MCC ('n', 'e'): return MCC ('e', 'q');
5635 case MCC ('e', 'q'): return MCC ('n', 'e');
5636 case MCC ('v', 'c'): return MCC ('v', 's');
5637 case MCC ('v', 's'): return MCC ('v', 'c');
5638 case MCC ('p', 'l'): return MCC ('m', 'i');
5639 case MCC ('m', 'i'): return MCC ('p', 'l');
5640 case MCC ('g', 'e'): return MCC ('l', 't');
5641 case MCC ('l', 't'): return MCC ('g', 'e');
5642 case MCC ('g', 't'): return MCC ('l', 'e');
5643 case MCC ('l', 'e'): return MCC ('g', 't');
5648 /* Build an MRI structured control expression. This generates test
5649 and branch instructions. It goes to TRUELAB if the condition is
5650 true, and to FALSELAB if the condition is false. Exactly one of
5651 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5652 is the size qualifier for the expression. EXTENT is the size to
5653 use for the branch. */
5656 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5657 rightstop
, truelab
, falselab
, extent
)
5664 const char *truelab
;
5665 const char *falselab
;
5671 if (leftstart
!= NULL
)
5673 struct m68k_op leftop
, rightop
;
5676 /* Swap the compare operands, if necessary, to produce a legal
5677 m68k compare instruction. Comparing a register operand with
5678 a non-register operand requires the register to be on the
5679 right (cmp, cmpa). Comparing an immediate value with
5680 anything requires the immediate value to be on the left
5685 (void) m68k_ip_op (leftstart
, &leftop
);
5690 (void) m68k_ip_op (rightstart
, &rightop
);
5693 if (rightop
.mode
== IMMED
5694 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5695 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5699 cc
= swap_mri_condition (cc
);
5701 leftstart
= rightstart
;
5704 leftstop
= rightstop
;
5709 if (truelab
== NULL
)
5711 cc
= reverse_mri_condition (cc
);
5715 if (leftstart
!= NULL
)
5717 buf
= (char *) xmalloc (20
5718 + (leftstop
- leftstart
)
5719 + (rightstop
- rightstart
));
5727 memcpy (s
, leftstart
, leftstop
- leftstart
);
5728 s
+= leftstop
- leftstart
;
5730 memcpy (s
, rightstart
, rightstop
- rightstart
);
5731 s
+= rightstop
- rightstart
;
5737 buf
= (char *) xmalloc (20 + strlen (truelab
));
5745 strcpy (s
, truelab
);
5750 /* Parse an MRI structured control expression. This generates test
5751 and branch instructions. STOP is where the expression ends. It
5752 goes to TRUELAB if the condition is true, and to FALSELAB if the
5753 condition is false. Exactly one of TRUELAB and FALSELAB will be
5754 NULL, meaning to fall through. QUAL is the size qualifier for the
5755 expression. EXTENT is the size to use for the branch. */
5758 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
5761 const char *truelab
;
5762 const char *falselab
;
5775 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5776 &rightstart
, &rightstop
))
5782 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5786 if (falselab
!= NULL
)
5789 flab
= mri_control_label ();
5791 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5792 rightstop
, (const char *) NULL
, flab
, extent
);
5794 input_line_pointer
+= 3;
5795 if (*input_line_pointer
!= '.'
5796 || input_line_pointer
[1] == '\0')
5800 qual
= input_line_pointer
[1];
5801 input_line_pointer
+= 2;
5804 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5805 &rightstart
, &rightstop
))
5811 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5812 rightstop
, truelab
, falselab
, extent
);
5814 if (falselab
== NULL
)
5817 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5821 if (truelab
!= NULL
)
5824 tlab
= mri_control_label ();
5826 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5827 rightstop
, tlab
, (const char *) NULL
, extent
);
5829 input_line_pointer
+= 2;
5830 if (*input_line_pointer
!= '.'
5831 || input_line_pointer
[1] == '\0')
5835 qual
= input_line_pointer
[1];
5836 input_line_pointer
+= 2;
5839 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5840 &rightstart
, &rightstop
))
5846 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5847 rightstop
, truelab
, falselab
, extent
);
5849 if (truelab
== NULL
)
5854 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5855 rightstop
, truelab
, falselab
, extent
);
5859 if (input_line_pointer
!= stop
)
5860 as_bad ("syntax error in structured control directive");
5863 /* Handle the MRI IF pseudo-op. This may be a structured control
5864 directive, or it may be a regular assembler conditional, depending
5873 struct mri_control_info
*n
;
5875 /* A structured control directive must end with THEN with an
5876 optional qualifier. */
5877 s
= input_line_pointer
;
5878 while (! is_end_of_line
[(unsigned char) *s
]
5879 && (! flag_mri
|| *s
!= '*'))
5882 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5885 if (s
- input_line_pointer
> 1
5889 if (s
- input_line_pointer
< 3
5890 || strncasecmp (s
- 3, "THEN", 4) != 0)
5894 as_bad ("missing then");
5895 ignore_rest_of_line ();
5899 /* It's a conditional. */
5904 /* Since this might be a conditional if, this pseudo-op will be
5905 called even if we are supported to be ignoring input. Double
5906 check now. Clobber *input_line_pointer so that ignore_input
5907 thinks that this is not a special pseudo-op. */
5908 c
= *input_line_pointer
;
5909 *input_line_pointer
= 0;
5910 if (ignore_input ())
5912 *input_line_pointer
= c
;
5913 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5914 ++input_line_pointer
;
5915 demand_empty_rest_of_line ();
5918 *input_line_pointer
= c
;
5920 n
= push_mri_control (mri_if
);
5922 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5923 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5926 input_line_pointer
= s
+ 3;
5928 input_line_pointer
= s
+ 1;
5932 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5933 ++input_line_pointer
;
5936 demand_empty_rest_of_line ();
5939 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5940 structured IF, associate the ELSE with the IF. Otherwise, assume
5941 it is a conditional else. */
5952 && (mri_control_stack
== NULL
5953 || mri_control_stack
->type
!= mri_if
5954 || mri_control_stack
->else_seen
))
5960 c
= *input_line_pointer
;
5961 *input_line_pointer
= 0;
5962 if (ignore_input ())
5964 *input_line_pointer
= c
;
5965 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5966 ++input_line_pointer
;
5967 demand_empty_rest_of_line ();
5970 *input_line_pointer
= c
;
5972 if (mri_control_stack
== NULL
5973 || mri_control_stack
->type
!= mri_if
5974 || mri_control_stack
->else_seen
)
5976 as_bad ("else without matching if");
5977 ignore_rest_of_line ();
5981 mri_control_stack
->else_seen
= 1;
5983 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
5986 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
5990 colon (mri_control_stack
->next
);
5994 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5995 ++input_line_pointer
;
5998 demand_empty_rest_of_line ();
6001 /* Handle the MRI ENDI pseudo-op. */
6007 if (mri_control_stack
== NULL
6008 || mri_control_stack
->type
!= mri_if
)
6010 as_bad ("endi without matching if");
6011 ignore_rest_of_line ();
6015 /* ignore_input will not return true for ENDI, so we don't need to
6016 worry about checking it again here. */
6018 if (! mri_control_stack
->else_seen
)
6019 colon (mri_control_stack
->next
);
6020 colon (mri_control_stack
->bottom
);
6026 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6027 ++input_line_pointer
;
6030 demand_empty_rest_of_line ();
6033 /* Handle the MRI BREAK pseudo-op. */
6036 s_mri_break (extent
)
6039 struct mri_control_info
*n
;
6043 n
= mri_control_stack
;
6045 && n
->type
!= mri_for
6046 && n
->type
!= mri_repeat
6047 && n
->type
!= mri_while
)
6051 as_bad ("break outside of structured loop");
6052 ignore_rest_of_line ();
6056 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6059 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6065 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6066 ++input_line_pointer
;
6069 demand_empty_rest_of_line ();
6072 /* Handle the MRI NEXT pseudo-op. */
6078 struct mri_control_info
*n
;
6082 n
= mri_control_stack
;
6084 && n
->type
!= mri_for
6085 && n
->type
!= mri_repeat
6086 && n
->type
!= mri_while
)
6090 as_bad ("next outside of structured loop");
6091 ignore_rest_of_line ();
6095 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6098 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6104 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6105 ++input_line_pointer
;
6108 demand_empty_rest_of_line ();
6111 /* Handle the MRI FOR pseudo-op. */
6117 const char *varstart
, *varstop
;
6118 const char *initstart
, *initstop
;
6119 const char *endstart
, *endstop
;
6120 const char *bystart
, *bystop
;
6124 struct mri_control_info
*n
;
6130 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6134 varstart
= input_line_pointer
;
6136 /* Look for the '='. */
6137 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6138 && *input_line_pointer
!= '=')
6139 ++input_line_pointer
;
6140 if (*input_line_pointer
!= '=')
6142 as_bad ("missing =");
6143 ignore_rest_of_line ();
6147 varstop
= input_line_pointer
;
6148 if (varstop
> varstart
6149 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6152 ++input_line_pointer
;
6154 initstart
= input_line_pointer
;
6156 /* Look for TO or DOWNTO. */
6159 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6161 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6162 && ! is_part_of_name (input_line_pointer
[2]))
6164 initstop
= input_line_pointer
;
6165 input_line_pointer
+= 2;
6168 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6169 && ! is_part_of_name (input_line_pointer
[6]))
6171 initstop
= input_line_pointer
;
6173 input_line_pointer
+= 6;
6176 ++input_line_pointer
;
6178 if (initstop
== NULL
)
6180 as_bad ("missing to or downto");
6181 ignore_rest_of_line ();
6184 if (initstop
> initstart
6185 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6189 endstart
= input_line_pointer
;
6191 /* Look for BY or DO. */
6194 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6196 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6197 && ! is_part_of_name (input_line_pointer
[2]))
6199 endstop
= input_line_pointer
;
6201 input_line_pointer
+= 2;
6204 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6205 && (input_line_pointer
[2] == '.'
6206 || ! is_part_of_name (input_line_pointer
[2])))
6208 endstop
= input_line_pointer
;
6209 input_line_pointer
+= 2;
6212 ++input_line_pointer
;
6214 if (endstop
== NULL
)
6216 as_bad ("missing do");
6217 ignore_rest_of_line ();
6220 if (endstop
> endstart
6221 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6227 bystop
= bystart
+ 2;
6232 bystart
= input_line_pointer
;
6236 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6238 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6239 && (input_line_pointer
[2] == '.'
6240 || ! is_part_of_name (input_line_pointer
[2])))
6242 bystop
= input_line_pointer
;
6243 input_line_pointer
+= 2;
6246 ++input_line_pointer
;
6250 as_bad ("missing do");
6251 ignore_rest_of_line ();
6254 if (bystop
> bystart
6255 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6259 if (*input_line_pointer
!= '.')
6263 extent
= input_line_pointer
[1];
6264 input_line_pointer
+= 2;
6267 /* We have fully parsed the FOR operands. Now build the loop. */
6269 n
= push_mri_control (mri_for
);
6271 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6282 memcpy (s
, initstart
, initstop
- initstart
);
6283 s
+= initstop
- initstart
;
6285 memcpy (s
, varstart
, varstop
- varstart
);
6286 s
+= varstop
- varstart
;
6300 memcpy (s
, endstart
, endstop
- endstart
);
6301 s
+= endstop
- endstart
;
6303 memcpy (s
, varstart
, varstop
- varstart
);
6304 s
+= varstop
- varstart
;
6312 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6314 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6317 /* Put together the add or sub instruction used by ENDF. */
6327 memcpy (s
, bystart
, bystop
- bystart
);
6328 s
+= bystop
- bystart
;
6330 memcpy (s
, varstart
, varstop
- varstart
);
6331 s
+= varstop
- varstart
;
6337 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6338 ++input_line_pointer
;
6341 demand_empty_rest_of_line ();
6344 /* Handle the MRI ENDF pseudo-op. */
6350 if (mri_control_stack
== NULL
6351 || mri_control_stack
->type
!= mri_for
)
6353 as_bad ("endf without for");
6354 ignore_rest_of_line ();
6358 colon (mri_control_stack
->next
);
6360 md_assemble (mri_control_stack
->incr
);
6362 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6363 md_assemble (mri_control_stack
->incr
);
6365 free (mri_control_stack
->incr
);
6367 colon (mri_control_stack
->bottom
);
6373 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6374 ++input_line_pointer
;
6377 demand_empty_rest_of_line ();
6380 /* Handle the MRI REPEAT pseudo-op. */
6383 s_mri_repeat (ignore
)
6386 struct mri_control_info
*n
;
6388 n
= push_mri_control (mri_repeat
);
6392 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6393 ++input_line_pointer
;
6395 demand_empty_rest_of_line ();
6398 /* Handle the MRI UNTIL pseudo-op. */
6406 if (mri_control_stack
== NULL
6407 || mri_control_stack
->type
!= mri_repeat
)
6409 as_bad ("until without repeat");
6410 ignore_rest_of_line ();
6414 colon (mri_control_stack
->next
);
6416 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6419 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6420 mri_control_stack
->top
, '\0');
6422 colon (mri_control_stack
->bottom
);
6424 input_line_pointer
= s
;
6430 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6431 ++input_line_pointer
;
6434 demand_empty_rest_of_line ();
6437 /* Handle the MRI WHILE pseudo-op. */
6445 struct mri_control_info
*n
;
6447 s
= input_line_pointer
;
6448 while (! is_end_of_line
[(unsigned char) *s
]
6449 && (! flag_mri
|| *s
!= '*'))
6452 while (*s
== ' ' || *s
== '\t')
6454 if (s
- input_line_pointer
> 1
6457 if (s
- input_line_pointer
< 2
6458 || strncasecmp (s
- 1, "DO", 2) != 0)
6460 as_bad ("missing do");
6461 ignore_rest_of_line ();
6465 n
= push_mri_control (mri_while
);
6469 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6470 s
[1] == '.' ? s
[2] : '\0');
6472 input_line_pointer
= s
+ 1;
6473 if (*input_line_pointer
== '.')
6474 input_line_pointer
+= 2;
6478 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6479 ++input_line_pointer
;
6482 demand_empty_rest_of_line ();
6485 /* Handle the MRI ENDW pseudo-op. */
6493 if (mri_control_stack
== NULL
6494 || mri_control_stack
->type
!= mri_while
)
6496 as_bad ("endw without while");
6497 ignore_rest_of_line ();
6501 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6502 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6506 colon (mri_control_stack
->bottom
);
6512 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6513 ++input_line_pointer
;
6516 demand_empty_rest_of_line ();
6521 * Invocation line includes a switch not recognized by the base assembler.
6522 * See if it's a processor-specific option. These are:
6524 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6525 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6526 * Select the architecture. Instructions or features not
6527 * supported by the selected architecture cause fatal
6528 * errors. More than one may be specified. The default is
6529 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6530 * for -m68000, and -m68882 is a synonym for -m68881.
6531 * -[A]m[c]no-68851, -[A]m[c]no-68881
6532 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6533 * so don't use or document it, but that's the way the parsing
6536 * -pic Indicates PIC.
6537 * -k Indicates PIC. (Sun 3 only.)
6540 * Permit `|' to be used in expressions.
6545 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6547 CONST
char *md_shortopts
= "lSA:m:k";
6550 struct option md_longopts
[] = {
6551 #define OPTION_PIC (OPTION_MD_BASE)
6552 {"pic", no_argument
, NULL
, OPTION_PIC
},
6553 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6554 {"register-prefix-optional", no_argument
, NULL
,
6555 OPTION_REGISTER_PREFIX_OPTIONAL
},
6556 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6557 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
6558 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6559 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
6560 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6561 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
6562 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6563 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
6564 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6565 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
6566 {NULL
, no_argument
, NULL
, 0}
6568 size_t md_longopts_size
= sizeof(md_longopts
);
6571 md_parse_option (c
, arg
)
6577 case 'l': /* -l means keep external to 2 bit offset
6578 rather than 16 bit one */
6579 flag_short_refs
= 1;
6582 case 'S': /* -S means that jbsr's always turn into
6584 flag_long_jumps
= 1;
6590 /* intentional fall-through */
6593 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6597 const char *oarg
= arg
;
6603 if (arg
[0] == 'c' && arg
[1] == '6')
6606 for (i
= 0; i
< n_archs
; i
++)
6607 if (!strcmp (arg
, archs
[i
].name
))
6612 as_bad ("unrecognized option `%s'", oarg
);
6615 arch
= archs
[i
].arch
;
6618 else if (arch
== m68851
)
6627 if (arg
[0] == 'c' && arg
[1] == '6')
6630 for (i
= 0; i
< n_archs
; i
++)
6631 if (!strcmp (arg
, archs
[i
].name
))
6633 unsigned long arch
= archs
[i
].arch
;
6634 if (cpu_of_arch (arch
))
6635 /* It's a cpu spec. */
6637 current_architecture
&= ~m68000up
;
6638 current_architecture
|= arch
;
6640 else if (arch
== m68881
)
6642 current_architecture
|= m68881
;
6645 else if (arch
== m68851
)
6647 current_architecture
|= m68851
;
6657 as_bad ("unrecognized architecture specification `%s'", arg
);
6666 break; /* -pic, Position Independent Code */
6668 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6669 flag_reg_prefix_optional
= 1;
6670 reg_prefix_optional_seen
= 1;
6673 /* -V: SVR4 argument to print version ID. */
6675 print_version_id ();
6678 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6679 should be emitted or not. FIXME: Not implemented. */
6683 case OPTION_BITWISE_OR
:
6688 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
6690 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
6694 m68k_comment_chars
= n
;
6698 case OPTION_BASE_SIZE_DEFAULT_16
:
6699 m68k_index_width_default
= SIZE_WORD
;
6702 case OPTION_BASE_SIZE_DEFAULT_32
:
6703 m68k_index_width_default
= SIZE_LONG
;
6706 case OPTION_DISP_SIZE_DEFAULT_16
:
6708 m68k_rel32_from_cmdline
= 1;
6711 case OPTION_DISP_SIZE_DEFAULT_32
:
6713 m68k_rel32_from_cmdline
= 1;
6724 md_show_usage (stream
)
6729 -l use 1 word for refs to undefined symbols [default 2]\n\
6730 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6731 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6732 | -mcpu32 | -m5200\n\
6733 specify variant of 680X0 architecture [default 68020]\n\
6734 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6735 target has/lacks floating-point coprocessor\n\
6736 [default yes for 68020, 68030, and cpu32]\n");
6738 -m68851 | -mno-68851\n\
6739 target has/lacks memory-management unit coprocessor\n\
6740 [default yes for 68020 and up]\n\
6741 -pic, -k generate position independent code\n\
6742 -S turn jbsr into jsr\n\
6743 --register-prefix-optional\n\
6744 recognize register names without prefix character\n\
6745 --bitwise-or do not treat `|' as a comment character\n");
6747 --base-size-default-16 base reg without size is 16 bits\n\
6748 --base-size-default-32 base reg without size is 32 bits (default)\n\
6749 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6750 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n");
6755 /* TEST2: Test md_assemble() */
6756 /* Warning, this routine probably doesn't work anymore */
6760 struct m68k_it the_ins
;
6768 if (!gets (buf
) || !*buf
)
6770 if (buf
[0] == '|' || buf
[1] == '.')
6772 for (cp
= buf
; *cp
; cp
++)
6777 memset (&the_ins
, '\0', sizeof (the_ins
));
6778 m68k_ip (&the_ins
, buf
);
6781 printf ("Error %s in %s\n", the_ins
.error
, buf
);
6785 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
6786 for (n
= 0; n
< the_ins
.numo
; n
++)
6787 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
6789 print_the_insn (&the_ins
.opcode
[0], stdout
);
6790 (void) putchar ('\n');
6792 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
6794 if (the_ins
.operands
[n
].error
)
6796 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
6799 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
6800 if (the_ins
.operands
[n
].b_const
)
6801 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
6802 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
6803 if (the_ins
.operands
[n
].b_iadd
)
6804 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
6805 (void) putchar ('\n');
6817 while (*str
&& *str
!= ' ')
6819 if (str
[-1] == ':' || str
[1] == '=')
6826 /* Possible states for relaxation:
6828 0 0 branch offset byte (bra, etc)
6832 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6836 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6843 /* We have no need to default values of symbols. */
6847 md_undefined_symbol (name
)
6853 /* Round up a section size to the appropriate boundary. */
6855 md_section_align (segment
, size
)
6860 #ifdef BFD_ASSEMBLER
6861 /* For a.out, force the section size to be aligned. If we don't do
6862 this, BFD will align it for us, but it will not write out the
6863 final bytes of the section. This may be a bug in BFD, but it is
6864 easier to fix it here since that is how the other a.out targets
6868 align
= bfd_get_section_alignment (stdoutput
, segment
);
6869 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
6876 /* Exactly what point is a PC-relative offset relative TO?
6877 On the 68k, it is relative to the address of the first extension
6878 word. The difference between the addresses of the offset and the
6879 first extension word is stored in fx_pcrel_adjust. */
6881 md_pcrel_from (fixP
)
6886 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6888 adjust
= fixP
->fx_pcrel_adjust
;
6891 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
6894 #ifndef BFD_ASSEMBLER
6899 tc_coff_symbol_emit_hook (ignore
)
6905 tc_coff_sizemachdep (frag
)
6908 switch (frag
->fr_subtype
& 0x3)
6925 /* end of tc-m68k.c */