1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
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"
34 /* This string holds the chars that always start a comment. If the
35 pre-processor is disabled, these aren't very useful. The macro
36 tc_comment_chars points to this. We use this, rather than the
37 usual comment_chars, so that the --bitwise-or option will work. */
38 #if defined (TE_SVR4) || defined (TE_DELTA)
39 const char *m68k_comment_chars
= "|#";
41 const char *m68k_comment_chars
= "|";
44 /* This array holds the chars that only start a comment at the beginning of
45 a line. If the line seems to have the form '# 123 filename'
46 .line and .file directives will appear in the pre-processed output */
47 /* Note that input_file.c hand checks for '#' at the beginning of the
48 first line of the input file. This is because the compiler outputs
49 #NO_APP at the beginning of its output. */
50 /* Also note that comments like this one will always work. */
51 const char line_comment_chars
[] = "#*";
53 const char line_separator_chars
[] = ";";
55 /* Chars that can be used to separate mant from exp in floating point nums */
56 CONST
char EXP_CHARS
[] = "eE";
58 /* Chars that mean this number is a floating point constant, as
59 in "0f12.456" or "0d1.2345e12". */
61 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
63 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
64 changed in read.c . Ideally it shouldn't have to know about it at all,
65 but nothing is ideal around here. */
67 const int md_reloc_size
= 8; /* Size of relocation record */
69 /* Are we trying to generate PIC code? If so, absolute references
70 ought to be made into linkage table references or pc-relative
71 references. Not implemented. For ELF there are other means
72 to denote pic relocations. */
75 static int flag_short_refs
; /* -l option */
76 static int flag_long_jumps
; /* -S option */
77 static int flag_keep_pcrel
; /* --pcrel option. */
79 #ifdef REGISTER_PREFIX_OPTIONAL
80 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
82 int flag_reg_prefix_optional
;
85 /* Whether --register-prefix-optional was used on the command line. */
86 static int reg_prefix_optional_seen
;
88 /* The floating point coprocessor to use by default. */
89 static enum m68k_register m68k_float_copnum
= COP1
;
91 /* If this is non-zero, then references to number(%pc) will be taken
92 to refer to number, rather than to %pc + number. */
93 static int m68k_abspcadd
;
95 /* If this is non-zero, then the quick forms of the move, add, and sub
96 instructions are used when possible. */
97 static int m68k_quick
= 1;
99 /* If this is non-zero, then if the size is not specified for a base
100 or outer displacement, the assembler assumes that the size should
102 static int m68k_rel32
= 1;
104 /* This is non-zero if m68k_rel32 was set from the command line. */
105 static int m68k_rel32_from_cmdline
;
107 /* The default width to use for an index register when using a base
109 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
111 /* We want to warn if any text labels are misaligned. In order to get
112 the right line number, we need to record the line number for each
117 struct label_line
*next
;
124 /* The list of labels. */
126 static struct label_line
*labels
;
128 /* The current label. */
130 static struct label_line
*current_label
;
132 /* Its an arbitrary name: This means I don't approve of it */
133 /* See flames below */
134 static struct obstack robyn
;
136 #define TAB(x,y) (((x)<<2)+(y))
137 #define TABTYPE(xy) ((xy) >> 2)
143 /* Case `g' except when BCC68000 is applicable. */
145 /* Coprocessor branches. */
147 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
148 supported on all cpus. Widens to 32-bit absolute. */
150 /* For inserting an extra jmp instruction with long offset on 68000,
151 for expanding conditional branches. (Not bsr or bra.) Since the
152 68000 doesn't support 32-bit displacements for conditional
153 branches, we fake it by reversing the condition and branching
154 around a jmp with an absolute long operand. */
156 /* For the DBcc "instructions". If the displacement requires 32 bits,
157 the branch-around-a-jump game is played here too. */
159 /* Not currently used? */
161 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
167 const char *m_operands
;
168 unsigned long m_opcode
;
172 struct m68k_incant
*m_next
;
175 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
176 #define gettwo(x) (((x)->m_opcode)&0xffff)
178 static const enum m68k_register m68000_control_regs
[] = { 0 };
179 static const enum m68k_register m68010_control_regs
[] = {
183 static const enum m68k_register m68020_control_regs
[] = {
184 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
187 static const enum m68k_register m68040_control_regs
[] = {
188 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
189 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
192 static const enum m68k_register m68060_control_regs
[] = {
193 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
194 USP
, VBR
, URP
, SRP
, PCR
,
197 static const enum m68k_register mcf_control_regs
[] = {
198 CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, VBR
, ROMBAR
,
199 RAMBAR0
, RAMBAR1
, MBAR
,
202 #define cpu32_control_regs m68010_control_regs
204 static const enum m68k_register
*control_regs
;
206 /* internal form of a 68020 instruction */
210 const char *args
; /* list of opcode info */
213 int numo
; /* Number of shorts in opcode */
216 struct m68k_op operands
[6];
218 int nexp
; /* number of exprs in use */
219 struct m68k_exp exprs
[4];
221 int nfrag
; /* Number of frags we have to produce */
224 int fragoff
; /* Where in the current opcode the frag ends */
231 int nrel
; /* Num of reloc strucs in use */
238 /* In a pc relative address the difference between the address
239 of the offset and the address that the offset is relative
240 to. This depends on the addressing mode. Basically this
241 is the value to put in the offset field to address the
242 first byte of the offset, without regarding the special
243 significance of some values (in the branch instruction, for
247 /* Whether this expression needs special pic relocation, and if
249 enum pic_relocation pic_reloc
;
252 reloc
[5]; /* Five is enough??? */
255 #define cpu_of_arch(x) ((x) & (m68000up|mcf))
256 #define float_of_arch(x) ((x) & mfloat)
257 #define mmu_of_arch(x) ((x) & mmmu)
258 #define arch_coldfire_p(x) (((x) & mcf) != 0)
260 /* Macros for determining if cpu supports a specific addressing mode */
261 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32))
263 static struct m68k_it the_ins
; /* the instruction being assembled */
265 #define op(ex) ((ex)->exp.X_op)
266 #define adds(ex) ((ex)->exp.X_add_symbol)
267 #define subs(ex) ((ex)->exp.X_op_symbol)
268 #define offs(ex) ((ex)->exp.X_add_number)
270 /* Macros for adding things to the m68k_it struct */
272 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
274 /* Static functions. */
276 static void insop
PARAMS ((int, const struct m68k_incant
*));
277 static void add_fix
PARAMS ((int, struct m68k_exp
*, int, int));
278 static void add_frag
PARAMS ((symbolS
*, offsetT
, int));
280 /* Like addword, but goes BEFORE general operands */
284 const struct m68k_incant
*opcode
;
287 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
288 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
289 for(z
=0;z
<the_ins
.nrel
;z
++)
290 the_ins
.reloc
[z
].n
+=2;
291 for (z
= 0; z
< the_ins
.nfrag
; z
++)
292 the_ins
.fragb
[z
].fragoff
++;
293 the_ins
.opcode
[opcode
->m_codenum
]=w
;
297 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
300 add_fix (width
, exp
, pc_rel
, pc_fix
)
302 struct m68k_exp
*exp
;
306 the_ins
.reloc
[the_ins
.nrel
].n
= ((width
== 'B' || width
== '3')
310 : (the_ins
.numo
*2)));
311 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
312 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
313 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
315 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
317 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
320 /* Cause an extra frag to be generated here, inserting up to 10 bytes
321 (that value is chosen in the frag_var call in md_assemble). TYPE
322 is the subtype of the frag to be generated; its primary type is
323 rs_machine_dependent.
325 The TYPE parameter is also used by md_convert_frag_1 and
326 md_estimate_size_before_relax. The appropriate type of fixup will
327 be emitted by md_convert_frag_1.
329 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
331 add_frag (add
, off
, type
)
336 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
337 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
338 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
339 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
343 (op (ex) != O_constant && op (ex) != O_big)
345 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
346 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
347 static void m68k_ip
PARAMS ((char *));
348 static void insert_reg
PARAMS ((const char *, int));
349 static void select_control_regs
PARAMS ((void));
350 static void init_regtable
PARAMS ((void));
351 static int reverse_16_bits
PARAMS ((int in
));
352 static int reverse_8_bits
PARAMS ((int in
));
353 static void install_gen_operand
PARAMS ((int mode
, int val
));
354 static void install_operand
PARAMS ((int mode
, int val
));
355 static void s_bss
PARAMS ((int));
356 static void s_data1
PARAMS ((int));
357 static void s_data2
PARAMS ((int));
358 static void s_even
PARAMS ((int));
359 static void s_proc
PARAMS ((int));
360 static void mri_chip
PARAMS ((void));
361 static void s_chip
PARAMS ((int));
362 static void s_fopt
PARAMS ((int));
363 static void s_opt
PARAMS ((int));
364 static void s_reg
PARAMS ((int));
365 static void s_restore
PARAMS ((int));
366 static void s_save
PARAMS ((int));
367 static void s_mri_if
PARAMS ((int));
368 static void s_mri_else
PARAMS ((int));
369 static void s_mri_endi
PARAMS ((int));
370 static void s_mri_break
PARAMS ((int));
371 static void s_mri_next
PARAMS ((int));
372 static void s_mri_for
PARAMS ((int));
373 static void s_mri_endf
PARAMS ((int));
374 static void s_mri_repeat
PARAMS ((int));
375 static void s_mri_until
PARAMS ((int));
376 static void s_mri_while
PARAMS ((int));
377 static void s_mri_endw
PARAMS ((int));
378 static void md_apply_fix_2
PARAMS ((fixS
*, offsetT
));
379 static void md_convert_frag_1
PARAMS ((fragS
*));
381 static int current_architecture
;
389 static const struct m68k_cpu archs
[] = {
390 { m68000
, "68000", 0 },
391 { m68010
, "68010", 0 },
392 { m68020
, "68020", 0 },
393 { m68030
, "68030", 0 },
394 { m68040
, "68040", 0 },
395 { m68060
, "68060", 0 },
396 { cpu32
, "cpu32", 0 },
397 { m68881
, "68881", 0 },
398 { m68851
, "68851", 0 },
399 { mcf5200
, "5200", 0 },
400 { mcf5206e
, "5206e", 0 },
401 { mcf5307
, "5307", 0},
402 /* Aliases (effectively, so far as gas is concerned) for the above
404 { m68020
, "68k", 1 },
405 { m68000
, "68008", 1 },
406 { m68000
, "68302", 1 },
407 { m68000
, "68306", 1 },
408 { m68000
, "68307", 1 },
409 { m68000
, "68322", 1 },
410 { m68000
, "68356", 1 },
411 { m68000
, "68ec000", 1 },
412 { m68000
, "68hc000", 1 },
413 { m68000
, "68hc001", 1 },
414 { m68020
, "68ec020", 1 },
415 { m68030
, "68ec030", 1 },
416 { m68040
, "68ec040", 1 },
417 { m68060
, "68ec060", 1 },
418 { cpu32
, "68330", 1 },
419 { cpu32
, "68331", 1 },
420 { cpu32
, "68332", 1 },
421 { cpu32
, "68333", 1 },
422 { cpu32
, "68334", 1 },
423 { cpu32
, "68336", 1 },
424 { cpu32
, "68340", 1 },
425 { cpu32
, "68341", 1 },
426 { cpu32
, "68349", 1 },
427 { cpu32
, "68360", 1 },
428 { m68881
, "68882", 1 },
429 { mcf5200
, "5202", 1 },
430 { mcf5200
, "5204", 1 },
431 { mcf5200
, "5206", 1 },
434 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
436 /* BCC68000 is for patching in an extra jmp instruction for long offsets
437 on the 68000. The 68000 doesn't support long branches with branchs */
439 /* This table desribes how you change sizes for the various types of variable
440 size expressions. This version only supports two kinds. */
442 /* Note that calls to frag_var need to specify the maximum expansion
443 needed; this is currently 10 bytes for DBCC. */
446 How far Forward this mode will reach:
447 How far Backward this mode will reach:
448 How many bytes this mode will add to the size of the frag
449 Which mode to go to if the offset won't fit in this one
451 relax_typeS md_relax_table
[] =
453 {1, 1, 0, 0}, /* First entries aren't used */
454 {1, 1, 0, 0}, /* For no good reason except */
455 {1, 1, 0, 0}, /* that the VAX doesn't either */
458 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
459 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
463 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
464 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
468 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
469 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
473 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
474 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
475 {0, 0, 6, 0}, /* jmp long space */
478 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
479 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
480 {0, 0, 10, 0}, /* bra/jmp long space */
483 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
484 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
488 /* For, e.g., jmp pcrel indexed. */
489 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
490 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
495 /* These are the machine dependent pseudo-ops. These are included so
496 the assembler can work on the output from the SUN C compiler, which
500 /* This table describes all the machine specific pseudo-ops the assembler
501 has to support. The fields are:
502 pseudo-op name without dot
503 function to call to execute this pseudo-op
504 Integer arg to pass to the function
506 const pseudo_typeS md_pseudo_table
[] =
508 {"data1", s_data1
, 0},
509 {"data2", s_data2
, 0},
512 {"skip", s_space
, 0},
514 #if defined (TE_SUN3) || defined (OBJ_ELF)
515 {"align", s_align_bytes
, 0},
518 {"swbeg", s_ignore
, 0},
520 {"extend", float_cons
, 'x'},
521 {"ldouble", float_cons
, 'x'},
523 /* The following pseudo-ops are supported for MRI compatibility. */
525 {"comline", s_space
, 1},
527 {"mask2", s_ignore
, 0},
530 {"restore", s_restore
, 0},
534 {"if.b", s_mri_if
, 'b'},
535 {"if.w", s_mri_if
, 'w'},
536 {"if.l", s_mri_if
, 'l'},
537 {"else", s_mri_else
, 0},
538 {"else.s", s_mri_else
, 's'},
539 {"else.l", s_mri_else
, 'l'},
540 {"endi", s_mri_endi
, 0},
541 {"break", s_mri_break
, 0},
542 {"break.s", s_mri_break
, 's'},
543 {"break.l", s_mri_break
, 'l'},
544 {"next", s_mri_next
, 0},
545 {"next.s", s_mri_next
, 's'},
546 {"next.l", s_mri_next
, 'l'},
547 {"for", s_mri_for
, 0},
548 {"for.b", s_mri_for
, 'b'},
549 {"for.w", s_mri_for
, 'w'},
550 {"for.l", s_mri_for
, 'l'},
551 {"endf", s_mri_endf
, 0},
552 {"repeat", s_mri_repeat
, 0},
553 {"until", s_mri_until
, 0},
554 {"until.b", s_mri_until
, 'b'},
555 {"until.w", s_mri_until
, 'w'},
556 {"until.l", s_mri_until
, 'l'},
557 {"while", s_mri_while
, 0},
558 {"while.b", s_mri_while
, 'b'},
559 {"while.w", s_mri_while
, 'w'},
560 {"while.l", s_mri_while
, 'l'},
561 {"endw", s_mri_endw
, 0},
567 /* The mote pseudo ops are put into the opcode table, since they
568 don't start with a . they look like opcodes to gas.
572 extern void obj_coff_section
PARAMS ((int));
575 CONST pseudo_typeS mote_pseudo_table
[] =
588 {"xdef", s_globl
, 0},
590 {"align", s_align_bytes
, 0},
592 {"align", s_align_ptwo
, 0},
595 {"sect", obj_coff_section
, 0},
596 {"section", obj_coff_section
, 0},
601 #define issbyte(x) ((x)>=-128 && (x)<=127)
602 #define isubyte(x) ((x)>=0 && (x)<=255)
603 #define issword(x) ((x)>=-32768 && (x)<=32767)
604 #define isuword(x) ((x)>=0 && (x)<=65535)
606 #define isbyte(x) ((x)>= -255 && (x)<=255)
607 #define isword(x) ((x)>=-65536 && (x)<=65535)
608 #define islong(x) (1)
610 extern char *input_line_pointer
;
612 static char mklower_table
[256];
613 #define mklower(c) (mklower_table[(unsigned char)(c)])
614 static char notend_table
[256];
615 static char alt_notend_table
[256];
617 (! (notend_table[(unsigned char) *s] \
619 && alt_notend_table[(unsigned char) s[1]])))
621 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
623 #ifdef NO_PCREL_RELOCS
626 make_pcrel_absolute(fixP
, add_number
)
630 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
632 /* rewrite the PC relative instructions to absolute address ones.
633 * these are rumoured to be faster, and the apollo linker refuses
634 * to deal with the PC relative relocations.
636 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
641 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
647 as_fatal (_("Unknown PC relative instruction"));
652 #endif /* NO_PCREL_RELOCS */
655 tc_coff_fix2rtype (fixP
)
658 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
659 return R_RELLONG_NEG
;
660 #ifdef NO_PCREL_RELOCS
661 know (fixP
->fx_pcrel
== 0);
662 return (fixP
->fx_size
== 1 ? R_RELBYTE
663 : fixP
->fx_size
== 2 ? R_DIR16
666 return (fixP
->fx_pcrel
?
667 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
668 fixP
->fx_size
== 2 ? R_PCRWORD
:
670 (fixP
->fx_size
== 1 ? R_RELBYTE
:
671 fixP
->fx_size
== 2 ? R_RELWORD
:
680 /* Compute the relocation code for a fixup of SIZE bytes, using pc
681 relative relocation if PCREL is non-zero. PIC says whether a special
682 pic relocation was requested. */
684 static bfd_reloc_code_real_type get_reloc_code
685 PARAMS ((int, int, enum pic_relocation
));
687 static bfd_reloc_code_real_type
688 get_reloc_code (size
, pcrel
, pic
)
691 enum pic_relocation pic
;
699 return BFD_RELOC_8_GOT_PCREL
;
701 return BFD_RELOC_16_GOT_PCREL
;
703 return BFD_RELOC_32_GOT_PCREL
;
711 return BFD_RELOC_8_GOTOFF
;
713 return BFD_RELOC_16_GOTOFF
;
715 return BFD_RELOC_32_GOTOFF
;
723 return BFD_RELOC_8_PLT_PCREL
;
725 return BFD_RELOC_16_PLT_PCREL
;
727 return BFD_RELOC_32_PLT_PCREL
;
735 return BFD_RELOC_8_PLTOFF
;
737 return BFD_RELOC_16_PLTOFF
;
739 return BFD_RELOC_32_PLTOFF
;
749 return BFD_RELOC_8_PCREL
;
751 return BFD_RELOC_16_PCREL
;
753 return BFD_RELOC_32_PCREL
;
773 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
775 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
780 as_bad (_("Can not do %d byte relocation"), size
);
782 as_bad (_("Can not do %d byte pic relocation"), size
);
785 return BFD_RELOC_NONE
;
788 /* Here we decide which fixups can be adjusted to make them relative
789 to the beginning of the section instead of the symbol. Basically
790 we need to make sure that the dynamic relocations are done
791 correctly, so in some cases we force the original symbol to be
794 tc_m68k_fix_adjustable (fixP
)
797 /* Prevent all adjustments to global symbols. */
798 if (S_IS_EXTERNAL (fixP
->fx_addsy
)
799 || S_IS_WEAK (fixP
->fx_addsy
))
802 /* adjust_reloc_syms doesn't know about the GOT */
803 switch (fixP
->fx_r_type
)
805 case BFD_RELOC_8_GOT_PCREL
:
806 case BFD_RELOC_16_GOT_PCREL
:
807 case BFD_RELOC_32_GOT_PCREL
:
808 case BFD_RELOC_8_GOTOFF
:
809 case BFD_RELOC_16_GOTOFF
:
810 case BFD_RELOC_32_GOTOFF
:
811 case BFD_RELOC_8_PLT_PCREL
:
812 case BFD_RELOC_16_PLT_PCREL
:
813 case BFD_RELOC_32_PLT_PCREL
:
814 case BFD_RELOC_8_PLTOFF
:
815 case BFD_RELOC_16_PLTOFF
:
816 case BFD_RELOC_32_PLTOFF
:
819 case BFD_RELOC_VTABLE_INHERIT
:
820 case BFD_RELOC_VTABLE_ENTRY
:
830 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
837 tc_gen_reloc (section
, fixp
)
842 bfd_reloc_code_real_type code
;
847 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
849 code
= fixp
->fx_r_type
;
851 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
852 that fixup_segment converted a non-PC relative reloc into a
853 PC relative reloc. In such a case, we need to convert the
860 code
= BFD_RELOC_8_PCREL
;
863 code
= BFD_RELOC_16_PCREL
;
866 code
= BFD_RELOC_32_PCREL
;
868 case BFD_RELOC_8_PCREL
:
869 case BFD_RELOC_16_PCREL
:
870 case BFD_RELOC_32_PCREL
:
871 case BFD_RELOC_8_GOT_PCREL
:
872 case BFD_RELOC_16_GOT_PCREL
:
873 case BFD_RELOC_32_GOT_PCREL
:
874 case BFD_RELOC_8_GOTOFF
:
875 case BFD_RELOC_16_GOTOFF
:
876 case BFD_RELOC_32_GOTOFF
:
877 case BFD_RELOC_8_PLT_PCREL
:
878 case BFD_RELOC_16_PLT_PCREL
:
879 case BFD_RELOC_32_PLT_PCREL
:
880 case BFD_RELOC_8_PLTOFF
:
881 case BFD_RELOC_16_PLTOFF
:
882 case BFD_RELOC_32_PLTOFF
:
885 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
886 _("Cannot make %s relocation PC relative"),
887 bfd_get_reloc_code_name (code
));
893 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
894 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
896 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
897 MAP (1, 0, BFD_RELOC_8
);
898 MAP (2, 0, BFD_RELOC_16
);
899 MAP (4, 0, BFD_RELOC_32
);
900 MAP (1, 1, BFD_RELOC_8_PCREL
);
901 MAP (2, 1, BFD_RELOC_16_PCREL
);
902 MAP (4, 1, BFD_RELOC_32_PCREL
);
910 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
911 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
912 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
913 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
916 reloc
->addend
= fixp
->fx_addnumber
;
921 reloc
->addend
= fixp
->fx_addnumber
;
923 reloc
->addend
= (section
->vma
924 + (fixp
->fx_pcrel_adjust
== 64
925 ? -1 : fixp
->fx_pcrel_adjust
)
927 + md_pcrel_from (fixp
));
930 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
931 assert (reloc
->howto
!= 0);
936 #endif /* BFD_ASSEMBLER */
938 /* Return zero if the reference to SYMBOL from within the same segment may
942 /* On an ELF system, we can't relax an externally visible symbol,
943 because it may be overridden by a shared library. However, if
944 TARGET_OS is "elf", then we presume that we are assembling for an
945 embedded system, in which case we don't have to worry about shared
946 libraries, and we can relax anything. */
948 #define relaxable_symbol(symbol) \
949 (strcmp (TARGET_OS, "elf") == 0 \
950 || (! S_IS_EXTERNAL (symbol) \
951 && ! S_IS_WEAK (symbol)))
955 #define relaxable_symbol(symbol) 1
959 /* Handle of the OPCODE hash table. NULL means any use before
960 m68k_ip_begin() will crash. */
961 static struct hash_control
*op_hash
;
963 /* Assemble an m68k instruction. */
970 register struct m68k_op
*opP
;
971 register const struct m68k_incant
*opcode
;
972 register const char *s
;
973 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
974 char *pdot
, *pdotmove
;
975 enum m68k_size siz1
, siz2
;
979 LITTLENUM_TYPE words
[6];
980 LITTLENUM_TYPE
*wordp
;
981 unsigned long ok_arch
= 0;
983 if (*instring
== ' ')
984 instring
++; /* skip leading whitespace */
986 /* Scan up to end of operation-code, which MUST end in end-of-string
987 or exactly 1 space. */
989 for (p
= instring
; *p
!= '\0'; p
++)
999 the_ins
.error
= _("No operator");
1003 /* p now points to the end of the opcode name, probably whitespace.
1004 Make sure the name is null terminated by clobbering the
1005 whitespace, look it up in the hash table, then fix it back.
1006 Remove a dot, first, since the opcode tables have none. */
1009 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1010 *pdotmove
= pdotmove
[1];
1016 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1021 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1022 *pdotmove
= pdotmove
[-1];
1029 the_ins
.error
= _("Unknown operator");
1033 /* found a legitimate opcode, start matching operands */
1037 if (opcode
->m_operands
== 0)
1039 char *old
= input_line_pointer
;
1041 input_line_pointer
= p
;
1042 /* Ahh - it's a motorola style psuedo op */
1043 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1044 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1045 input_line_pointer
= old
;
1051 if (flag_mri
&& opcode
->m_opnum
== 0)
1053 /* In MRI mode, random garbage is allowed after an instruction
1054 which accepts no operands. */
1055 the_ins
.args
= opcode
->m_operands
;
1056 the_ins
.numargs
= opcode
->m_opnum
;
1057 the_ins
.numo
= opcode
->m_codenum
;
1058 the_ins
.opcode
[0] = getone (opcode
);
1059 the_ins
.opcode
[1] = gettwo (opcode
);
1063 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1065 p
= crack_operand (p
, opP
);
1069 the_ins
.error
= opP
->error
;
1074 opsfound
= opP
- &the_ins
.operands
[0];
1076 /* This ugly hack is to support the floating pt opcodes in their
1077 standard form. Essentially, we fake a first enty of type COP#1 */
1078 if (opcode
->m_operands
[0] == 'I')
1082 for (n
= opsfound
; n
> 0; --n
)
1083 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1085 memset ((char *) (&the_ins
.operands
[0]), '\0',
1086 sizeof (the_ins
.operands
[0]));
1087 the_ins
.operands
[0].mode
= CONTROL
;
1088 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1092 /* We've got the operands. Find an opcode that'll accept them */
1095 /* If we didn't get the right number of ops, or we have no
1096 common model with this pattern then reject this pattern. */
1098 ok_arch
|= opcode
->m_arch
;
1099 if (opsfound
!= opcode
->m_opnum
1100 || ((opcode
->m_arch
& current_architecture
) == 0))
1104 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
1108 /* Warning: this switch is huge! */
1109 /* I've tried to organize the cases into this order:
1110 non-alpha first, then alpha by letter. Lower-case
1111 goes directly before uppercase counterpart. */
1112 /* Code with multiple case ...: gets sorted by the lowest
1113 case ... it belongs to. I hope this makes sense. */
1219 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1236 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1255 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1265 if (opP
->mode
!= IMMED
)
1267 else if (s
[1] == 'b'
1268 && ! isvar (&opP
->disp
)
1269 && (opP
->disp
.exp
.X_op
!= O_constant
1270 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1272 else if (s
[1] == 'B'
1273 && ! isvar (&opP
->disp
)
1274 && (opP
->disp
.exp
.X_op
!= O_constant
1275 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1277 else if (s
[1] == 'w'
1278 && ! isvar (&opP
->disp
)
1279 && (opP
->disp
.exp
.X_op
!= O_constant
1280 || ! isword (opP
->disp
.exp
.X_add_number
)))
1282 else if (s
[1] == 'W'
1283 && ! isvar (&opP
->disp
)
1284 && (opP
->disp
.exp
.X_op
!= O_constant
1285 || ! issword (opP
->disp
.exp
.X_add_number
)))
1291 if (opP
->mode
!= IMMED
)
1296 if (opP
->mode
== AREG
1297 || opP
->mode
== CONTROL
1298 || opP
->mode
== FPREG
1299 || opP
->mode
== IMMED
1300 || opP
->mode
== REGLST
1301 || (opP
->mode
!= ABSL
1303 || opP
->reg
== ZPC
)))
1308 if (opP
->mode
== CONTROL
1309 || opP
->mode
== FPREG
1310 || opP
->mode
== REGLST
1311 || opP
->mode
== IMMED
1312 || (opP
->mode
!= ABSL
1314 || opP
->reg
== ZPC
)))
1342 if (opP
->mode
== CONTROL
1343 || opP
->mode
== FPREG
1344 || opP
->mode
== REGLST
)
1349 if (opP
->mode
!= AINC
)
1354 if (opP
->mode
!= ADEC
)
1404 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1425 case '~': /* For now! (JF FOO is this right?) */
1447 if (opP
->mode
!= CONTROL
1448 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1453 if (opP
->mode
!= AREG
)
1458 if (opP
->mode
!= AINDR
)
1463 if (opP
->mode
!= ABSL
1465 && strncmp (instring
, "jbsr", 4) == 0))
1470 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1475 if (opP
->mode
!= DISP
1477 || opP
->reg
> ADDR7
)
1482 if (opP
->mode
!= DREG
)
1487 if (opP
->reg
!= ACC
)
1492 if (opP
->mode
!= FPREG
)
1497 if (opP
->reg
!= MACSR
)
1502 if (opP
->reg
!= MASK
)
1507 if (opP
->mode
!= CONTROL
1514 if (opP
->mode
!= CONTROL
1516 || opP
->reg
> last_movec_reg
)
1520 const enum m68k_register
*rp
;
1521 for (rp
= control_regs
; *rp
; rp
++)
1522 if (*rp
== opP
->reg
)
1530 if (opP
->mode
!= IMMED
)
1536 if (opP
->mode
== DREG
1537 || opP
->mode
== AREG
1538 || opP
->mode
== FPREG
)
1547 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1550 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1553 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1561 else if (opP
->mode
== CONTROL
)
1570 opP
->mask
= 1 << 24;
1573 opP
->mask
= 1 << 25;
1576 opP
->mask
= 1 << 26;
1585 else if (opP
->mode
!= REGLST
)
1587 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1589 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1594 if (opP
->mode
!= IMMED
)
1596 else if (opP
->disp
.exp
.X_op
!= O_constant
1597 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1599 else if (! m68k_quick
1600 && instring
[3] != 'q'
1601 && instring
[4] != 'q')
1606 if (opP
->mode
!= DREG
1607 && opP
->mode
!= IMMED
1608 && opP
->mode
!= ABSL
)
1613 if (opP
->mode
!= IMMED
)
1615 else if (opP
->disp
.exp
.X_op
!= O_constant
1616 || opP
->disp
.exp
.X_add_number
< 1
1617 || opP
->disp
.exp
.X_add_number
> 8)
1619 else if (! m68k_quick
1620 && (strncmp (instring
, "add", 3) == 0
1621 || strncmp (instring
, "sub", 3) == 0)
1622 && instring
[3] != 'q')
1627 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1632 if (opP
->mode
!= AINDR
1633 && (opP
->mode
!= BASE
1635 && opP
->reg
!= ZADDR0
)
1636 || opP
->disp
.exp
.X_op
!= O_absent
1637 || ((opP
->index
.reg
< DATA0
1638 || opP
->index
.reg
> DATA7
)
1639 && (opP
->index
.reg
< ADDR0
1640 || opP
->index
.reg
> ADDR7
))
1641 || opP
->index
.size
!= SIZE_UNSPEC
1642 || opP
->index
.scale
!= 1))
1647 if (opP
->mode
!= CONTROL
1648 || ! (opP
->reg
== FPI
1650 || opP
->reg
== FPC
))
1655 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1660 if (opP
->mode
!= IMMED
)
1662 else if (opP
->disp
.exp
.X_op
!= O_constant
1663 || opP
->disp
.exp
.X_add_number
< 0
1664 || opP
->disp
.exp
.X_add_number
> 7)
1669 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1673 /* JF these are out of order. We could put them
1674 in order if we were willing to put up with
1675 bunches of #ifdef m68851s in the code.
1677 Don't forget that you need these operands
1678 to use 68030 MMU instructions. */
1680 /* Memory addressing mode used by pflushr */
1682 if (opP
->mode
== CONTROL
1683 || opP
->mode
== FPREG
1684 || opP
->mode
== DREG
1685 || opP
->mode
== AREG
1686 || opP
->mode
== REGLST
)
1688 /* We should accept immediate operands, but they
1689 supposedly have to be quad word, and we don't
1690 handle that. I would like to see what a Motorola
1691 assembler does before doing something here. */
1692 if (opP
->mode
== IMMED
)
1697 if (opP
->mode
!= CONTROL
1698 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1703 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1708 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1713 if (opP
->mode
!= CONTROL
1716 && opP
->reg
!= SCC
))
1721 if (opP
->mode
!= CONTROL
1727 if (opP
->mode
!= CONTROL
1730 && opP
->reg
!= CRP
))
1735 if (opP
->mode
!= CONTROL
1736 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1737 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1742 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1747 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1752 if (opP
->mode
!= CONTROL
1759 } /* not a cache specifier. */
1763 if (opP
->mode
!= ABSL
)
1768 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
1770 /* FIXME: kludge instead of fixing parser:
1771 upper/lower registers are *not* CONTROL
1772 registers, but ordinary ones. */
1773 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
1774 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
1782 } /* switch on type of operand */
1786 } /* for each operand */
1787 } /* if immediately wrong */
1794 opcode
= opcode
->m_next
;
1799 && !(ok_arch
& current_architecture
))
1804 _("invalid instruction for this architecture; needs "));
1805 cp
= buf
+ strlen (buf
);
1809 strcpy (cp
, _("fpu (68040, 68060 or 68881/68882)"));
1812 strcpy (cp
, _("mmu (68030 or 68851)"));
1815 strcpy (cp
, _("68020 or higher"));
1818 strcpy (cp
, _("68000 or higher"));
1821 strcpy (cp
, _("68010 or higher"));
1825 int got_one
= 0, idx
;
1827 idx
< (int) (sizeof (archs
) / sizeof (archs
[0]));
1830 if ((archs
[idx
].arch
& ok_arch
)
1831 && ! archs
[idx
].alias
)
1835 strcpy (cp
, " or ");
1839 strcpy (cp
, archs
[idx
].name
);
1845 cp
= xmalloc (strlen (buf
) + 1);
1850 the_ins
.error
= _("operands mismatch");
1852 } /* Fell off the end */
1857 /* now assemble it */
1859 the_ins
.args
= opcode
->m_operands
;
1860 the_ins
.numargs
= opcode
->m_opnum
;
1861 the_ins
.numo
= opcode
->m_codenum
;
1862 the_ins
.opcode
[0] = getone (opcode
);
1863 the_ins
.opcode
[1] = gettwo (opcode
);
1865 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1867 /* This switch is a doozy.
1868 Watch the first step; its a big one! */
1896 tmpreg
= 0x3c; /* 7.4 */
1897 if (strchr ("bwl", s
[1]))
1898 nextword
= get_num (&opP
->disp
, 80);
1900 nextword
= get_num (&opP
->disp
, 0);
1901 if (isvar (&opP
->disp
))
1902 add_fix (s
[1], &opP
->disp
, 0, 0);
1906 if (!isbyte (nextword
))
1907 opP
->error
= _("operand out of range");
1912 if (!isword (nextword
))
1913 opP
->error
= _("operand out of range");
1918 if (!issword (nextword
))
1919 opP
->error
= _("operand out of range");
1924 addword (nextword
>> 16);
1951 /* We gotta put out some float */
1952 if (op (&opP
->disp
) != O_big
)
1957 /* Can other cases happen here? */
1958 if (op (&opP
->disp
) != O_constant
)
1961 val
= (valueT
) offs (&opP
->disp
);
1965 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1966 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1970 offs (&opP
->disp
) = gencnt
;
1972 if (offs (&opP
->disp
) > 0)
1974 if (offs (&opP
->disp
) > baseo
)
1976 as_warn (_("Bignum too big for %c format; truncated"),
1978 offs (&opP
->disp
) = baseo
;
1980 baseo
-= offs (&opP
->disp
);
1983 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1984 offs (&opP
->disp
)--;
1989 gen_to_words (words
, baseo
, (long) outro
);
1990 for (wordp
= words
; baseo
--; wordp
++)
1994 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1997 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2000 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2003 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2006 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2010 nextword
= get_num (&opP
->disp
, 80);
2013 && ! isvar (&opP
->disp
)
2016 opP
->disp
.exp
.X_op
= O_symbol
;
2017 #ifndef BFD_ASSEMBLER
2018 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
2020 opP
->disp
.exp
.X_add_symbol
=
2021 section_symbol (absolute_section
);
2025 /* Force into index mode. Hope this works */
2027 /* We do the first bit for 32-bit displacements, and the
2028 second bit for 16 bit ones. It is possible that we
2029 should make the default be WORD instead of LONG, but
2030 I think that'd break GCC, so we put up with a little
2031 inefficiency for the sake of working output. */
2033 if (!issword (nextword
)
2034 || (isvar (&opP
->disp
)
2035 && ((opP
->disp
.size
== SIZE_UNSPEC
2036 && flag_short_refs
== 0
2037 && cpu_of_arch (current_architecture
) >= m68020
2038 && ! arch_coldfire_p (current_architecture
))
2039 || opP
->disp
.size
== SIZE_LONG
)))
2041 if (cpu_of_arch (current_architecture
) < m68020
2042 || arch_coldfire_p (current_architecture
))
2044 _("displacement too large for this architecture; needs 68020 or higher");
2046 tmpreg
= 0x3B; /* 7.3 */
2048 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2049 if (isvar (&opP
->disp
))
2053 if (opP
->disp
.size
== SIZE_LONG
2055 /* If the displacement needs pic
2056 relocation it cannot be relaxed. */
2057 || opP
->disp
.pic_reloc
!= pic_none
2062 add_fix ('l', &opP
->disp
, 1, 2);
2066 add_frag (adds (&opP
->disp
),
2068 TAB (PCLEA
, SZ_UNDEF
));
2075 add_fix ('l', &opP
->disp
, 0, 0);
2080 addword (nextword
>> 16);
2085 tmpreg
= 0x3A; /* 7.2 */
2087 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2089 if (isvar (&opP
->disp
))
2093 add_fix ('w', &opP
->disp
, 1, 0);
2096 add_fix ('w', &opP
->disp
, 0, 0);
2106 baseo
= get_num (&opP
->disp
, 80);
2107 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2108 outro
= get_num (&opP
->odisp
, 80);
2109 /* Figure out the `addressing mode'.
2110 Also turn on the BASE_DISABLE bit, if needed. */
2111 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2113 tmpreg
= 0x3b; /* 7.3 */
2114 if (opP
->reg
== ZPC
)
2117 else if (opP
->reg
== 0)
2120 tmpreg
= 0x30; /* 6.garbage */
2122 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2125 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2128 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2130 siz1
= opP
->disp
.size
;
2131 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2132 siz2
= opP
->odisp
.size
;
2136 /* Index register stuff */
2137 if (opP
->index
.reg
!= 0
2138 && opP
->index
.reg
>= DATA
2139 && opP
->index
.reg
<= ADDR7
)
2141 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2143 if (opP
->index
.size
== SIZE_LONG
2144 || (opP
->index
.size
== SIZE_UNSPEC
2145 && m68k_index_width_default
== SIZE_LONG
))
2148 if ((opP
->index
.scale
!= 1
2149 && cpu_of_arch (current_architecture
) < m68020
)
2150 || (opP
->index
.scale
== 8
2151 && arch_coldfire_p (current_architecture
)))
2154 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2157 if (arch_coldfire_p (current_architecture
)
2158 && opP
->index
.size
== SIZE_WORD
)
2159 opP
->error
= _("invalid index size for coldfire");
2161 switch (opP
->index
.scale
)
2178 GET US OUT OF HERE! */
2180 /* Must be INDEX, with an index register. Address
2181 register cannot be ZERO-PC, and either :b was
2182 forced, or we know it will fit. For a 68000 or
2183 68010, force this mode anyways, because the
2184 larger modes aren't supported. */
2185 if (opP
->mode
== BASE
2186 && ((opP
->reg
>= ADDR0
2187 && opP
->reg
<= ADDR7
)
2190 if (siz1
== SIZE_BYTE
2191 || cpu_of_arch (current_architecture
) < m68020
2192 || arch_coldfire_p (current_architecture
)
2193 || (siz1
== SIZE_UNSPEC
2194 && ! isvar (&opP
->disp
)
2195 && issbyte (baseo
)))
2197 nextword
+= baseo
& 0xff;
2199 if (isvar (&opP
->disp
))
2201 /* Do a byte relocation. If it doesn't
2202 fit (possible on m68000) let the
2203 fixup processing complain later. */
2205 add_fix ('B', &opP
->disp
, 1, 1);
2207 add_fix ('B', &opP
->disp
, 0, 0);
2209 else if (siz1
!= SIZE_BYTE
)
2211 if (siz1
!= SIZE_UNSPEC
)
2212 as_warn (_("Forcing byte displacement"));
2213 if (! issbyte (baseo
))
2214 opP
->error
= _("byte displacement out of range");
2219 else if (siz1
== SIZE_UNSPEC
2221 && isvar (&opP
->disp
)
2222 && subs (&opP
->disp
) == NULL
2224 /* If the displacement needs pic
2225 relocation it cannot be relaxed. */
2226 && opP
->disp
.pic_reloc
== pic_none
2230 /* The code in md_convert_frag_1 needs to be
2231 able to adjust nextword. Call frag_grow
2232 to ensure that we have enough space in
2233 the frag obstack to make all the bytes
2236 nextword
+= baseo
& 0xff;
2238 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2239 TAB (PCINDEX
, SZ_UNDEF
));
2247 nextword
|= 0x40; /* No index reg */
2248 if (opP
->index
.reg
>= ZDATA0
2249 && opP
->index
.reg
<= ZDATA7
)
2250 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2251 else if (opP
->index
.reg
>= ZADDR0
2252 || opP
->index
.reg
<= ZADDR7
)
2253 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2256 /* It isn't simple. */
2258 if (cpu_of_arch (current_architecture
) < m68020
2259 || arch_coldfire_p (current_architecture
))
2261 _("invalid operand mode for this architecture; needs 68020 or higher");
2264 /* If the guy specified a width, we assume that it is
2265 wide enough. Maybe it isn't. If so, we lose. */
2269 if (isvar (&opP
->disp
)
2271 : ! issword (baseo
))
2276 else if (! isvar (&opP
->disp
) && baseo
== 0)
2285 as_warn (_(":b not permitted; defaulting to :w"));
2295 /* Figure out innner displacement stuff */
2296 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2298 if (cpu_of_arch (current_architecture
) & cpu32
)
2299 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2303 if (isvar (&opP
->odisp
)
2305 : ! issword (outro
))
2310 else if (! isvar (&opP
->odisp
) && outro
== 0)
2319 as_warn (_(":b not permitted; defaulting to :w"));
2328 if (opP
->mode
== POST
2329 && (nextword
& 0x40) == 0)
2334 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2336 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2337 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2339 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2341 if (siz1
== SIZE_LONG
)
2342 addword (baseo
>> 16);
2343 if (siz1
!= SIZE_UNSPEC
)
2346 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2347 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2348 if (siz2
== SIZE_LONG
)
2349 addword (outro
>> 16);
2350 if (siz2
!= SIZE_UNSPEC
)
2356 nextword
= get_num (&opP
->disp
, 80);
2357 switch (opP
->disp
.size
)
2362 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2364 tmpreg
= 0x38; /* 7.0 */
2368 if (isvar (&opP
->disp
)
2369 && !subs (&opP
->disp
)
2370 && adds (&opP
->disp
)
2372 /* If the displacement needs pic relocation it
2373 cannot be relaxed. */
2374 && opP
->disp
.pic_reloc
== pic_none
2376 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2377 && relaxable_symbol (adds (&opP
->disp
))
2379 && !strchr ("~%&$?", s
[0]))
2381 tmpreg
= 0x3A; /* 7.2 */
2382 add_frag (adds (&opP
->disp
),
2384 TAB (PCREL
, SZ_UNDEF
));
2387 /* Fall through into long */
2389 if (isvar (&opP
->disp
))
2390 add_fix ('l', &opP
->disp
, 0, 0);
2392 tmpreg
= 0x39;/* 7.1 mode */
2393 addword (nextword
>> 16);
2398 as_bad (_("unsupported byte value; use a different suffix"));
2400 case SIZE_WORD
: /* Word */
2401 if (isvar (&opP
->disp
))
2402 add_fix ('w', &opP
->disp
, 0, 0);
2404 tmpreg
= 0x38;/* 7.0 mode */
2412 as_bad (_("unknown/incorrect operand"));
2415 install_gen_operand (s
[1], tmpreg
);
2421 { /* JF: I hate floating point! */
2436 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2437 if (isvar (&opP
->disp
))
2438 add_fix (s
[1], &opP
->disp
, 0, 0);
2441 case 'b': /* Danger: These do no check for
2442 certain types of overflow.
2444 if (!isbyte (tmpreg
))
2445 opP
->error
= _("out of range");
2446 insop (tmpreg
, opcode
);
2447 if (isvar (&opP
->disp
))
2448 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2449 (opcode
->m_codenum
) * 2 + 1;
2452 if (!issbyte (tmpreg
))
2453 opP
->error
= _("out of range");
2454 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
2455 if (isvar (&opP
->disp
))
2456 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2459 if (!isword (tmpreg
))
2460 opP
->error
= _("out of range");
2461 insop (tmpreg
, opcode
);
2462 if (isvar (&opP
->disp
))
2463 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2466 if (!issword (tmpreg
))
2467 opP
->error
= _("out of range");
2468 insop (tmpreg
, opcode
);
2469 if (isvar (&opP
->disp
))
2470 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2473 /* Because of the way insop works, we put these two out
2475 insop (tmpreg
, opcode
);
2476 insop (tmpreg
>> 16, opcode
);
2477 if (isvar (&opP
->disp
))
2478 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2485 install_operand (s
[1], tmpreg
);
2496 install_operand (s
[1], opP
->reg
- ADDR
);
2500 tmpreg
= get_num (&opP
->disp
, 80);
2504 /* The pc_fix argument winds up in fx_pcrel_adjust,
2505 which is a char, and may therefore be unsigned. We
2506 want to pass -1, but we pass 64 instead, and convert
2507 back in md_pcrel_from. */
2508 add_fix ('B', &opP
->disp
, 1, 64);
2511 add_fix ('w', &opP
->disp
, 1, 0);
2516 if (!HAVE_LONG_BRANCH(current_architecture
))
2517 as_warn (_("Can't use long branches on 68000/68010/5200"));
2518 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2519 add_fix ('l', &opP
->disp
, 1, 0);
2524 if (subs (&opP
->disp
)) /* We can't relax it */
2528 /* If the displacement needs pic relocation it cannot be
2530 if (opP
->disp
.pic_reloc
!= pic_none
)
2534 /* This could either be a symbol, or an absolute
2535 address. No matter, the frag hacking will finger it
2536 out. Not quite: it can't switch from BRANCH to
2537 BCC68000 for the case where opnd is absolute (it
2538 needs to use the 68000 hack since no conditional abs
2540 if (( !HAVE_LONG_BRANCH(current_architecture
)
2541 || (0 == adds (&opP
->disp
)))
2542 && (the_ins
.opcode
[0] >= 0x6200)
2543 && (the_ins
.opcode
[0] <= 0x6f00))
2544 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2545 TAB (BCC68000
, SZ_UNDEF
));
2547 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2548 TAB (ABRANCH
, SZ_UNDEF
));
2551 if (isvar (&opP
->disp
))
2554 /* check for DBcc instruction */
2555 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2557 /* size varies if patch */
2558 /* needed for long form */
2559 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2560 TAB (DBCC
, SZ_UNDEF
));
2564 add_fix ('w', &opP
->disp
, 1, 0);
2568 case 'C': /* Fixed size LONG coproc branches */
2569 add_fix ('l', &opP
->disp
, 1, 0);
2573 case 'c': /* Var size Coprocesssor branches */
2574 if (subs (&opP
->disp
))
2576 add_fix ('l', &opP
->disp
, 1, 0);
2577 add_frag ((symbolS
*) 0, (offsetT
) 0, TAB (FBRANCH
, LONG
));
2579 else if (adds (&opP
->disp
))
2580 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2581 TAB (FBRANCH
, SZ_UNDEF
));
2584 /* add_frag ((symbolS *) 0, offs (&opP->disp),
2585 TAB(FBRANCH,SHORT)); */
2586 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2587 add_fix ('l', &opP
->disp
, 1, 0);
2597 case 'C': /* Ignore it */
2600 case 'd': /* JF this is a kludge */
2601 install_operand ('s', opP
->reg
- ADDR
);
2602 tmpreg
= get_num (&opP
->disp
, 80);
2603 if (!issword (tmpreg
))
2605 as_warn (_("Expression out of range, using 0"));
2612 install_operand (s
[1], opP
->reg
- DATA
);
2615 case 'E': /* Ignore it */
2619 install_operand (s
[1], opP
->reg
- FP0
);
2622 case 'G': /* Ignore it */
2627 tmpreg
= opP
->reg
- COP0
;
2628 install_operand (s
[1], tmpreg
);
2631 case 'J': /* JF foo */
2704 install_operand (s
[1], tmpreg
);
2708 tmpreg
= get_num (&opP
->disp
, 55);
2709 install_operand (s
[1], tmpreg
& 0x7f);
2716 if (tmpreg
& 0x7FF0000)
2717 as_bad (_("Floating point register in register list"));
2718 insop (reverse_16_bits (tmpreg
), opcode
);
2722 if (tmpreg
& 0x700FFFF)
2723 as_bad (_("Wrong register in floating-point reglist"));
2724 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2732 if (tmpreg
& 0x7FF0000)
2733 as_bad (_("Floating point register in register list"));
2734 insop (tmpreg
, opcode
);
2736 else if (s
[1] == '8')
2738 if (tmpreg
& 0x0FFFFFF)
2739 as_bad (_("incorrect register in reglist"));
2740 install_operand (s
[1], tmpreg
>> 24);
2744 if (tmpreg
& 0x700FFFF)
2745 as_bad (_("wrong register in floating-point reglist"));
2747 install_operand (s
[1], tmpreg
>> 16);
2752 install_operand (s
[1], get_num (&opP
->disp
, 60));
2756 tmpreg
= ((opP
->mode
== DREG
)
2757 ? 0x20 + (int) (opP
->reg
- DATA
)
2758 : (get_num (&opP
->disp
, 40) & 0x1F));
2759 install_operand (s
[1], tmpreg
);
2763 tmpreg
= get_num (&opP
->disp
, 10);
2766 install_operand (s
[1], tmpreg
);
2770 /* This depends on the fact that ADDR registers are eight
2771 more than their corresponding DATA regs, so the result
2772 will have the ADDR_REG bit set */
2773 install_operand (s
[1], opP
->reg
- DATA
);
2777 if (opP
->mode
== AINDR
)
2778 install_operand (s
[1], opP
->reg
- DATA
);
2780 install_operand (s
[1], opP
->index
.reg
- DATA
);
2784 if (opP
->reg
== FPI
)
2786 else if (opP
->reg
== FPS
)
2788 else if (opP
->reg
== FPC
)
2792 install_operand (s
[1], tmpreg
);
2795 case 'S': /* Ignore it */
2799 install_operand (s
[1], get_num (&opP
->disp
, 30));
2802 case 'U': /* Ignore it */
2821 as_fatal (_("failed sanity check"));
2822 } /* switch on cache token */
2823 install_operand (s
[1], tmpreg
);
2826 /* JF: These are out of order, I fear. */
2839 install_operand (s
[1], tmpreg
);
2865 install_operand (s
[1], tmpreg
);
2869 if (opP
->reg
== VAL
)
2888 install_operand (s
[1], tmpreg
);
2902 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2913 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2919 install_operand (s
[1], tmpreg
);
2922 know (opP
->reg
== PSR
);
2925 know (opP
->reg
== PCSR
);
2940 install_operand (s
[1], tmpreg
);
2943 tmpreg
= get_num (&opP
->disp
, 20);
2944 install_operand (s
[1], tmpreg
);
2946 case '_': /* used only for move16 absolute 32-bit address */
2947 if (isvar (&opP
->disp
))
2948 add_fix ('l', &opP
->disp
, 0, 0);
2949 tmpreg
= get_num (&opP
->disp
, 80);
2950 addword (tmpreg
>> 16);
2951 addword (tmpreg
& 0xFFFF);
2954 install_operand (s
[1], opP
->reg
- DATA0L
);
2955 opP
->reg
-= (DATA0L
);
2956 opP
->reg
&= 0x0F; /* remove upper/lower bit */
2963 /* By the time whe get here (FINALLY) the_ins contains the complete
2964 instruction, ready to be emitted. . . */
2968 reverse_16_bits (in
)
2974 static int mask
[16] =
2976 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2977 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2979 for (n
= 0; n
< 16; n
++)
2982 out
|= mask
[15 - n
];
2985 } /* reverse_16_bits() */
2994 static int mask
[8] =
2996 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2999 for (n
= 0; n
< 8; n
++)
3005 } /* reverse_8_bits() */
3007 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3008 (that value is chosen in the frag_var call in md_assemble). TYPE
3009 is the subtype of the frag to be generated; its primary type is
3010 rs_machine_dependent.
3012 The TYPE parameter is also used by md_convert_frag_1 and
3013 md_estimate_size_before_relax. The appropriate type of fixup will
3014 be emitted by md_convert_frag_1.
3016 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3018 install_operand (mode
, val
)
3025 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
3028 the_ins
.opcode
[0] |= val
<< 9;
3031 the_ins
.opcode
[1] |= val
<< 12;
3034 the_ins
.opcode
[1] |= val
<< 6;
3037 the_ins
.opcode
[1] |= val
;
3040 the_ins
.opcode
[2] |= val
<< 12;
3043 the_ins
.opcode
[2] |= val
<< 6;
3046 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3047 three words long! */
3049 the_ins
.opcode
[2] |= val
;
3052 the_ins
.opcode
[1] |= val
<< 7;
3055 the_ins
.opcode
[1] |= val
<< 10;
3059 the_ins
.opcode
[1] |= val
<< 5;
3064 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3067 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3070 the_ins
.opcode
[0] |= val
= 0xff;
3073 the_ins
.opcode
[0] |= val
<< 9;
3076 the_ins
.opcode
[1] |= val
;
3079 the_ins
.opcode
[1] |= val
;
3080 the_ins
.numo
++; /* What a hack */
3083 the_ins
.opcode
[1] |= val
<< 4;
3091 the_ins
.opcode
[0] |= (val
<< 6);
3094 the_ins
.opcode
[1] = (val
>> 16);
3095 the_ins
.opcode
[2] = val
& 0xffff;
3098 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3099 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3100 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3103 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3104 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3107 the_ins
.opcode
[1] |= val
<< 12;
3108 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3111 the_ins
.opcode
[0] |= (val
& 0xF);
3112 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3115 the_ins
.opcode
[1] |= (val
& 0xF);
3116 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3119 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3123 as_fatal (_("failed sanity check."));
3125 } /* install_operand() */
3128 install_gen_operand (mode
, val
)
3135 the_ins
.opcode
[0] |= val
;
3138 /* This is a kludge!!! */
3139 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3148 the_ins
.opcode
[0] |= val
;
3150 /* more stuff goes here */
3152 as_fatal (_("failed sanity check."));
3154 } /* install_gen_operand() */
3157 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3158 * then deal with the bitfield hack.
3162 crack_operand (str
, opP
)
3164 register struct m68k_op
*opP
;
3166 register int parens
;
3168 register char *beg_str
;
3176 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3182 else if (*str
== ')')
3186 opP
->error
= _("Extra )");
3192 if (flag_mri
&& *str
== '\'')
3193 inquote
= ! inquote
;
3195 if (!*str
&& parens
)
3197 opP
->error
= _("Missing )");
3202 if (m68k_ip_op (beg_str
, opP
) != 0)
3209 c
= *++str
; /* JF bitfield hack */
3214 as_bad (_("Missing operand"));
3217 /* Detect MRI REG symbols and convert them to REGLSTs. */
3218 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3221 opP
->mask
= ~(int)opP
->reg
;
3228 /* This is the guts of the machine-dependent assembler. STR points to a
3229 machine dependent instruction. This function is supposed to emit
3230 the frags/bytes it assembles to.
3234 insert_reg (regname
, regnum
)
3235 const char *regname
;
3241 #ifdef REGISTER_PREFIX
3242 if (!flag_reg_prefix_optional
)
3244 buf
[0] = REGISTER_PREFIX
;
3245 strcpy (buf
+ 1, regname
);
3250 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3251 &zero_address_frag
));
3253 for (i
= 0; regname
[i
]; i
++)
3254 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3257 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3258 &zero_address_frag
));
3267 static const struct init_entry init_table
[] =
3326 /* control registers */
3327 { "sfc", SFC
}, /* Source Function Code */
3329 { "dfc", DFC
}, /* Destination Function Code */
3331 { "cacr", CACR
}, /* Cache Control Register */
3332 { "caar", CAAR
}, /* Cache Address Register */
3334 { "usp", USP
}, /* User Stack Pointer */
3335 { "vbr", VBR
}, /* Vector Base Register */
3336 { "msp", MSP
}, /* Master Stack Pointer */
3337 { "isp", ISP
}, /* Interrupt Stack Pointer */
3339 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0 */
3340 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1 */
3341 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0 */
3342 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1 */
3344 /* 68ec040 versions of same */
3345 { "iacr0", ITT0
}, /* Instruction Access Control Register 0 */
3346 { "iacr1", ITT1
}, /* Instruction Access Control Register 0 */
3347 { "dacr0", DTT0
}, /* Data Access Control Register 0 */
3348 { "dacr1", DTT1
}, /* Data Access Control Register 0 */
3350 /* mcf5200 versions of same. The ColdFire programmer's reference
3351 manual indicated that the order is 2,3,0,1, but Ken Rose
3352 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3353 { "acr0", ITT0
}, /* Access Control Unit 0 */
3354 { "acr1", ITT1
}, /* Access Control Unit 1 */
3355 { "acr2", DTT0
}, /* Access Control Unit 2 */
3356 { "acr3", DTT1
}, /* Access Control Unit 3 */
3358 { "tc", TC
}, /* MMU Translation Control Register */
3361 { "mmusr", MMUSR
}, /* MMU Status Register */
3362 { "srp", SRP
}, /* User Root Pointer */
3363 { "urp", URP
}, /* Supervisor Root Pointer */
3368 { "rombar", ROMBAR
}, /* ROM Base Address Register */
3369 { "rambar0", RAMBAR0
}, /* ROM Base Address Register */
3370 { "rambar1", RAMBAR1
}, /* ROM Base Address Register */
3371 { "mbar", MBAR
}, /* Module Base Address Register */
3372 /* end of control registers */
3406 /* 68ec030 versions of same */
3409 /* 68ec030 access control unit, identical to 030 MMU status reg */
3412 /* Suppressed data and address registers. */
3430 /* Upper and lower data and address registers, used by macw and msacw. */
3474 for (i
= 0; init_table
[i
].name
; i
++)
3475 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3478 static int no_68851
, no_68881
;
3481 /* a.out machine type. Default to 68020. */
3482 int m68k_aout_machtype
= 2;
3494 int shorts_this_frag
;
3497 /* In MRI mode, the instruction and operands are separated by a
3498 space. Anything following the operands is a comment. The label
3499 has already been removed. */
3507 for (s
= str
; *s
!= '\0'; s
++)
3509 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3527 inquote
= ! inquote
;
3532 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3537 for (n
= 0; n
< the_ins
.numargs
; n
++)
3538 if (the_ins
.operands
[n
].error
)
3540 er
= the_ins
.operands
[n
].error
;
3546 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
3550 /* If there is a current label, record that it marks an instruction. */
3551 if (current_label
!= NULL
)
3553 current_label
->text
= 1;
3554 current_label
= NULL
;
3557 if (the_ins
.nfrag
== 0)
3559 /* No frag hacking involved; just put it out */
3560 toP
= frag_more (2 * the_ins
.numo
);
3561 fromP
= &the_ins
.opcode
[0];
3562 for (m
= the_ins
.numo
; m
; --m
)
3564 md_number_to_chars (toP
, (long) (*fromP
), 2);
3568 /* put out symbol-dependent info */
3569 for (m
= 0; m
< the_ins
.nrel
; m
++)
3571 switch (the_ins
.reloc
[m
].wid
)
3590 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3591 the_ins
.reloc
[m
].wid
);
3594 fixP
= fix_new_exp (frag_now
,
3595 ((toP
- frag_now
->fr_literal
)
3596 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3598 &the_ins
.reloc
[m
].exp
,
3599 the_ins
.reloc
[m
].pcrel
,
3600 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3601 the_ins
.reloc
[m
].pic_reloc
));
3602 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3603 if (the_ins
.reloc
[m
].wid
== 'B')
3604 fixP
->fx_signed
= 1;
3609 /* There's some frag hacking */
3610 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3615 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3617 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3618 toP
= frag_more (wid
);
3620 shorts_this_frag
= 0;
3621 for (m
= wid
/ 2; m
; --m
)
3623 md_number_to_chars (toP
, (long) (*fromP
), 2);
3628 for (m
= 0; m
< the_ins
.nrel
; m
++)
3630 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3632 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3635 wid
= the_ins
.reloc
[m
].wid
;
3638 the_ins
.reloc
[m
].wid
= 0;
3639 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3641 fixP
= fix_new_exp (frag_now
,
3642 ((toP
- frag_now
->fr_literal
)
3643 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3645 &the_ins
.reloc
[m
].exp
,
3646 the_ins
.reloc
[m
].pcrel
,
3647 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3648 the_ins
.reloc
[m
].pic_reloc
));
3649 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3651 (void) frag_var (rs_machine_dependent
, 10, 0,
3652 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3653 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3655 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3656 shorts_this_frag
= 0;
3659 toP
= frag_more (n
* sizeof (short));
3662 md_number_to_chars (toP
, (long) (*fromP
), 2);
3668 for (m
= 0; m
< the_ins
.nrel
; m
++)
3672 wid
= the_ins
.reloc
[m
].wid
;
3675 the_ins
.reloc
[m
].wid
= 0;
3676 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3678 fixP
= fix_new_exp (frag_now
,
3679 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3680 - shorts_this_frag
* 2),
3682 &the_ins
.reloc
[m
].exp
,
3683 the_ins
.reloc
[m
].pcrel
,
3684 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3685 the_ins
.reloc
[m
].pic_reloc
));
3686 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3694 * md_begin -- set up hash tables with 68000 instructions.
3695 * similar to what the vax assembler does. ---phr
3697 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3698 a copy of it at runtime, adding in the information we want but isn't
3699 there. I think it'd be better to have an awk script hack the table
3700 at compile time. Or even just xstr the table and use it as-is. But
3701 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3704 register const struct m68k_opcode
*ins
;
3705 register struct m68k_incant
*hack
, *slak
;
3706 register const char *retval
= 0; /* empty string, or error msg text */
3712 flag_reg_prefix_optional
= 1;
3714 if (! m68k_rel32_from_cmdline
)
3718 op_hash
= hash_new ();
3720 obstack_begin (&robyn
, 4000);
3721 for (i
= 0; i
< m68k_numopcodes
; i
++)
3723 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3726 ins
= &m68k_opcodes
[i
];
3727 /* We *could* ignore insns that don't match our arch here
3728 but just leaving them out of the hash. */
3729 slak
->m_operands
= ins
->args
;
3730 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3731 slak
->m_arch
= ins
->arch
;
3732 slak
->m_opcode
= ins
->opcode
;
3733 /* This is kludgey */
3734 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3735 if (i
+ 1 != m68k_numopcodes
3736 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3738 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3743 slak
= slak
->m_next
;
3747 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3749 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
3752 for (i
= 0; i
< m68k_numaliases
; i
++)
3754 const char *name
= m68k_opcode_aliases
[i
].primary
;
3755 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3756 PTR val
= hash_find (op_hash
, name
);
3758 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
3759 retval
= hash_insert (op_hash
, alias
, val
);
3761 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
3764 /* In MRI mode, all unsized branches are variable sized. Normally,
3765 they are word sized. */
3768 static struct m68k_opcode_alias mri_aliases
[] =
3789 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
3792 const char *name
= mri_aliases
[i
].primary
;
3793 const char *alias
= mri_aliases
[i
].alias
;
3794 PTR val
= hash_find (op_hash
, name
);
3796 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
3797 retval
= hash_jam (op_hash
, alias
, val
);
3799 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
3803 for (i
= 0; i
< (int) sizeof (mklower_table
); i
++)
3804 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3806 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
3808 notend_table
[i
] = 0;
3809 alt_notend_table
[i
] = 0;
3811 notend_table
[','] = 1;
3812 notend_table
['{'] = 1;
3813 notend_table
['}'] = 1;
3814 alt_notend_table
['a'] = 1;
3815 alt_notend_table
['A'] = 1;
3816 alt_notend_table
['d'] = 1;
3817 alt_notend_table
['D'] = 1;
3818 alt_notend_table
['#'] = 1;
3819 alt_notend_table
['&'] = 1;
3820 alt_notend_table
['f'] = 1;
3821 alt_notend_table
['F'] = 1;
3822 #ifdef REGISTER_PREFIX
3823 alt_notend_table
[REGISTER_PREFIX
] = 1;
3826 /* We need to put '(' in alt_notend_table to handle
3827 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3829 alt_notend_table
['('] = 1;
3831 /* We need to put '@' in alt_notend_table to handle
3832 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3834 alt_notend_table
['@'] = 1;
3836 /* We need to put digits in alt_notend_table to handle
3837 bfextu %d0{24:1},%d0
3839 alt_notend_table
['0'] = 1;
3840 alt_notend_table
['1'] = 1;
3841 alt_notend_table
['2'] = 1;
3842 alt_notend_table
['3'] = 1;
3843 alt_notend_table
['4'] = 1;
3844 alt_notend_table
['5'] = 1;
3845 alt_notend_table
['6'] = 1;
3846 alt_notend_table
['7'] = 1;
3847 alt_notend_table
['8'] = 1;
3848 alt_notend_table
['9'] = 1;
3850 #ifndef MIT_SYNTAX_ONLY
3851 /* Insert pseudo ops, these have to go into the opcode table since
3852 gas expects pseudo ops to start with a dot */
3855 while (mote_pseudo_table
[n
].poc_name
)
3857 hack
= (struct m68k_incant
*)
3858 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3859 hash_insert (op_hash
,
3860 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3861 hack
->m_operands
= 0;
3871 record_alignment (text_section
, 2);
3872 record_alignment (data_section
, 2);
3873 record_alignment (bss_section
, 2);
3878 select_control_regs ()
3880 /* Note which set of "movec" control registers is available. */
3881 switch (cpu_of_arch (current_architecture
))
3884 control_regs
= m68000_control_regs
;
3887 control_regs
= m68010_control_regs
;
3891 control_regs
= m68020_control_regs
;
3894 control_regs
= m68040_control_regs
;
3897 control_regs
= m68060_control_regs
;
3900 control_regs
= cpu32_control_regs
;
3905 control_regs
= mcf_control_regs
;
3913 m68k_init_after_args ()
3915 if (cpu_of_arch (current_architecture
) == 0)
3918 const char *default_cpu
= TARGET_CPU
;
3920 if (*default_cpu
== 'm')
3922 for (i
= 0; i
< n_archs
; i
++)
3923 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3927 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU
);
3928 current_architecture
|= m68020
;
3931 current_architecture
|= archs
[i
].arch
;
3933 /* Permit m68881 specification with all cpus; those that can't work
3934 with a coprocessor could be doing emulation. */
3935 if (current_architecture
& m68851
)
3937 if (current_architecture
& m68040
)
3939 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
3942 /* What other incompatibilities could we check for? */
3944 /* Toss in some default assumptions about coprocessors. */
3946 && (cpu_of_arch (current_architecture
)
3947 /* Can CPU32 have a 68881 coprocessor?? */
3948 & (m68020
| m68030
| cpu32
)))
3950 current_architecture
|= m68881
;
3953 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3954 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3956 current_architecture
|= m68851
;
3958 if (no_68881
&& (current_architecture
& m68881
))
3959 as_bad (_("options for 68881 and no-68881 both given"));
3960 if (no_68851
&& (current_architecture
& m68851
))
3961 as_bad (_("options for 68851 and no-68851 both given"));
3964 /* Work out the magic number. This isn't very general. */
3965 if (current_architecture
& m68000
)
3966 m68k_aout_machtype
= 0;
3967 else if (current_architecture
& m68010
)
3968 m68k_aout_machtype
= 1;
3969 else if (current_architecture
& m68020
)
3970 m68k_aout_machtype
= 2;
3972 m68k_aout_machtype
= 2;
3975 /* Note which set of "movec" control registers is available. */
3976 select_control_regs ();
3978 if (cpu_of_arch (current_architecture
) < m68020
3979 || arch_coldfire_p (current_architecture
))
3980 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3983 /* This is called when a label is defined. */
3986 m68k_frob_label (sym
)
3989 struct label_line
*n
;
3991 n
= (struct label_line
*) xmalloc (sizeof *n
);
3994 as_where (&n
->file
, &n
->line
);
4000 /* This is called when a value that is not an instruction is emitted. */
4003 m68k_flush_pending_output ()
4005 current_label
= NULL
;
4008 /* This is called at the end of the assembly, when the final value of
4009 the label is known. We warn if this is a text symbol aligned at an
4013 m68k_frob_symbol (sym
)
4016 if (S_GET_SEGMENT (sym
) == reg_section
4017 && (int) S_GET_VALUE (sym
) < 0)
4019 S_SET_SEGMENT (sym
, absolute_section
);
4020 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4022 else if ((S_GET_VALUE (sym
) & 1) != 0)
4024 struct label_line
*l
;
4026 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4028 if (l
->label
== sym
)
4031 as_warn_where (l
->file
, l
->line
,
4032 _("text label `%s' aligned to odd boundary"),
4040 /* This is called if we go in or out of MRI mode because of the .mri
4044 m68k_mri_mode_change (on
)
4049 if (! flag_reg_prefix_optional
)
4051 flag_reg_prefix_optional
= 1;
4052 #ifdef REGISTER_PREFIX
4057 if (! m68k_rel32_from_cmdline
)
4062 if (! reg_prefix_optional_seen
)
4064 #ifdef REGISTER_PREFIX_OPTIONAL
4065 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4067 flag_reg_prefix_optional
= 0;
4069 #ifdef REGISTER_PREFIX
4074 if (! m68k_rel32_from_cmdline
)
4079 /* Equal to MAX_PRECISION in atof-ieee.c */
4080 #define MAX_LITTLENUMS 6
4082 /* Turn a string in input_line_pointer into a floating point constant
4083 of type TYPE, and store the appropriate bytes in *LITP. The number
4084 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4085 returned, or NULL on OK. */
4088 md_atof (type
, litP
, sizeP
)
4094 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
4095 LITTLENUM_TYPE
*wordP
;
4126 return _("Bad call to MD_ATOF()");
4128 t
= atof_ieee (input_line_pointer
, type
, words
);
4130 input_line_pointer
= t
;
4132 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
4133 for (wordP
= words
; prec
--;)
4135 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
4136 litP
+= sizeof (LITTLENUM_TYPE
);
4142 md_number_to_chars (buf
, val
, n
)
4147 number_to_chars_bigendian (buf
, val
, n
);
4151 md_apply_fix_2 (fixP
, val
)
4155 addressT upper_limit
;
4156 offsetT lower_limit
;
4158 /* This is unnecessary but it convinces the native rs6000 compiler
4159 to generate the code we want. */
4160 char *buf
= fixP
->fx_frag
->fr_literal
;
4161 buf
+= fixP
->fx_where
;
4162 /* end ibm compiler workaround */
4164 if (val
& 0x80000000)
4165 val
|= ~(addressT
)0x7fffffff;
4172 memset (buf
, 0, fixP
->fx_size
);
4173 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
4175 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4176 && !S_IS_DEFINED (fixP
->fx_addsy
)
4177 && !S_IS_WEAK (fixP
->fx_addsy
))
4178 S_SET_WEAK (fixP
->fx_addsy
);
4183 #ifdef BFD_ASSEMBLER
4184 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4185 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4189 switch (fixP
->fx_size
)
4191 /* The cast to offsetT below are necessary to make code correct for
4192 machines where ints are smaller than offsetT */
4196 lower_limit
= - (offsetT
) 0x80;
4199 *buf
++ = (val
>> 8);
4201 upper_limit
= 0x7fff;
4202 lower_limit
= - (offsetT
) 0x8000;
4205 *buf
++ = (val
>> 24);
4206 *buf
++ = (val
>> 16);
4207 *buf
++ = (val
>> 8);
4209 upper_limit
= 0x7fffffff;
4210 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
4213 BAD_CASE (fixP
->fx_size
);
4216 /* Fix up a negative reloc. */
4217 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4219 fixP
->fx_addsy
= fixP
->fx_subsy
;
4220 fixP
->fx_subsy
= NULL
;
4224 /* For non-pc-relative values, it's conceivable we might get something
4225 like "0xff" for a byte field. So extend the upper part of the range
4226 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4227 so that we can do any range checking at all. */
4228 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4229 upper_limit
= upper_limit
* 2 + 1;
4231 if ((addressT
) val
> upper_limit
4232 && (val
> 0 || val
< lower_limit
))
4233 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("value out of range"));
4235 /* A one byte PC-relative reloc means a short branch. We can't use
4236 a short branch with a value of 0 or -1, because those indicate
4237 different opcodes (branches with longer offsets). fixup_segment
4238 in write.c may have clobbered fx_pcrel, so we need to examine the
4241 #ifdef BFD_ASSEMBLER
4242 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
4245 && fixP
->fx_size
== 1
4246 && (fixP
->fx_addsy
== NULL
4247 || S_IS_DEFINED (fixP
->fx_addsy
))
4248 && (val
== 0 || val
== -1))
4249 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("invalid byte branch offset"));
4252 #ifdef BFD_ASSEMBLER
4254 md_apply_fix (fixP
, valp
)
4258 md_apply_fix_2 (fixP
, (addressT
) *valp
);
4262 void md_apply_fix (fixP
, val
)
4266 md_apply_fix_2 (fixP
, (addressT
) val
);
4270 /* *fragP has been relaxed to its final size, and now needs to have
4271 the bytes inside it modified to conform to the new size There is UGLY
4275 md_convert_frag_1 (fragP
)
4276 register fragS
*fragP
;
4282 /* Address in object code of the displacement. */
4283 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4285 /* Address in gas core of the place to store the displacement. */
4286 /* This convinces the native rs6000 compiler to generate the code we
4288 register char *buffer_address
= fragP
->fr_literal
;
4289 buffer_address
+= fragP
->fr_fix
;
4290 /* end ibm compiler workaround */
4292 /* The displacement of the address, from current location. */
4293 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4294 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4296 #ifdef BFD_ASSEMBLER
4297 disp
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
4300 switch (fragP
->fr_subtype
)
4302 case TAB (BCC68000
, BYTE
):
4303 case TAB (ABRANCH
, BYTE
):
4304 know (issbyte (disp
));
4306 as_bad (_("short branch with zero offset: use :w"));
4307 fragP
->fr_opcode
[1] = disp
;
4310 case TAB (DBCC
, SHORT
):
4311 know (issword (disp
));
4314 case TAB (BCC68000
, SHORT
):
4315 case TAB (ABRANCH
, SHORT
):
4316 know (issword (disp
));
4317 fragP
->fr_opcode
[1] = 0x00;
4320 case TAB (ABRANCH
, LONG
):
4321 if (!HAVE_LONG_BRANCH (current_architecture
))
4323 if (flag_keep_pcrel
)
4324 as_bad (_("long branch not supported"));
4326 if (fragP
->fr_opcode
[0] == 0x61)
4329 fragP
->fr_opcode
[0] = 0x4E;
4330 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4344 else if (fragP
->fr_opcode
[0] == 0x60)
4346 fragP
->fr_opcode
[0] = 0x4E;
4347 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4348 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4349 fragP
->fr_offset
, 0, NO_RELOC
);
4355 /* This should never happen, because if it's a conditional
4356 branch and we are on a 68000, BCC68000 should have been
4357 picked instead of ABRANCH. */
4363 fragP
->fr_opcode
[1] = (char) 0xff;
4367 case TAB (BCC68000
, LONG
):
4368 /* only Bcc 68000 instructions can come here */
4369 /* change bcc into b!cc/jmp absl long */
4370 if (flag_keep_pcrel
)
4371 as_bad (_("long branch not supported"));
4373 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4374 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4376 /* JF: these used to be fr_opcode[2,3], but they may be in a
4377 different frag, in which case refering to them is a no-no.
4378 Only fr_opcode[0,1] are guaranteed to work. */
4379 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4380 *buffer_address
++ = (char) 0xf9;
4381 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4382 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4383 fragP
->fr_offset
, 0, NO_RELOC
);
4387 case TAB (DBCC
, LONG
):
4388 /* only DBcc 68000 instructions can come here */
4389 /* Change dbcc into dbcc/bral. */
4390 if (! HAVE_LONG_BRANCH (current_architecture
) && flag_keep_pcrel
)
4391 as_bad (_("long branch not supported"));
4393 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4394 *buffer_address
++ = 0x00; /* branch offset = 4 */
4395 *buffer_address
++ = 0x04;
4396 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4397 *buffer_address
++ = 0x06;
4398 if (HAVE_LONG_BRANCH (current_architecture
))
4400 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
4401 *buffer_address
++ = (char) 0xff;
4405 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
4406 *buffer_address
++ = (char) 0xf9;
4409 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4410 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4411 fragP
->fr_offset
, HAVE_LONG_BRANCH (current_architecture
),
4416 case TAB (FBRANCH
, SHORT
):
4417 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4420 case TAB (FBRANCH
, LONG
):
4421 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4424 case TAB (PCREL
, SHORT
):
4427 case TAB (PCREL
, LONG
):
4428 /* The thing to do here is force it to ABSOLUTE LONG, since
4429 PCREL is really trying to shorten an ABSOLUTE address anyway */
4430 /* JF FOO This code has not been tested */
4431 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4433 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4434 as_bad (_("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx"),
4435 (unsigned) fragP
->fr_opcode
[0],
4436 (unsigned long) fragP
->fr_address
);
4437 fragP
->fr_opcode
[1] &= ~0x3F;
4438 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4442 case TAB (PCLEA
, SHORT
):
4443 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4444 fragP
->fr_offset
, 1, NO_RELOC
);
4445 fragP
->fr_opcode
[1] &= ~0x3F;
4446 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4449 case TAB (PCLEA
, LONG
):
4450 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4451 fragP
->fr_offset
, 1, NO_RELOC
);
4452 fixP
->fx_pcrel_adjust
= 2;
4453 /* Already set to mode 7.3; this indicates: PC indirect with
4454 suppressed index, 32-bit displacement. */
4455 *buffer_address
++ = 0x01;
4456 *buffer_address
++ = 0x70;
4461 case TAB (PCINDEX
, BYTE
):
4463 if (!issbyte (disp
))
4465 as_bad (_("displacement doesn't fit in one byte"));
4468 assert (fragP
->fr_fix
>= 2);
4469 buffer_address
[-2] &= ~1;
4470 buffer_address
[-1] = disp
;
4473 case TAB (PCINDEX
, SHORT
):
4475 assert (issword (disp
));
4476 assert (fragP
->fr_fix
>= 2);
4477 buffer_address
[-2] |= 0x1;
4478 buffer_address
[-1] = 0x20;
4479 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4480 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4482 fixP
->fx_pcrel_adjust
= 2;
4485 case TAB (PCINDEX
, LONG
):
4487 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4488 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4490 fixP
->fx_pcrel_adjust
= 2;
4491 assert (fragP
->fr_fix
>= 2);
4492 buffer_address
[-2] |= 0x1;
4493 buffer_address
[-1] = 0x30;
4500 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4501 fragP
->fr_fix
+= ext
;
4505 #ifndef BFD_ASSEMBLER
4508 md_convert_frag (headers
, sec
, fragP
)
4509 object_headers
*headers ATTRIBUTE_UNUSED
;
4510 segT sec ATTRIBUTE_UNUSED
;
4513 md_convert_frag_1 (fragP
);
4519 md_convert_frag (abfd
, sec
, fragP
)
4520 bfd
*abfd ATTRIBUTE_UNUSED
;
4521 segT sec ATTRIBUTE_UNUSED
;
4524 md_convert_frag_1 (fragP
);
4528 /* Force truly undefined symbols to their maximum size, and generally set up
4529 the frag list to be relaxed
4532 md_estimate_size_before_relax (fragP
, segment
)
4533 register fragS
*fragP
;
4537 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4539 old_fix
= fragP
->fr_fix
;
4541 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4542 switch (fragP
->fr_subtype
)
4545 case TAB (ABRANCH
, SZ_UNDEF
):
4547 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4548 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4549 && relaxable_symbol (fragP
->fr_symbol
))
4551 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4554 else if ((fragP
->fr_symbol
!= NULL
)
4555 && (flag_short_refs
|| flag_keep_pcrel
))
4556 { /* Symbol is undefined and we want short ref */
4557 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4558 fragP
->fr_offset
, 1, NO_RELOC
);
4563 else if ((fragP
->fr_symbol
== 0) || !HAVE_LONG_BRANCH(current_architecture
))
4565 /* On 68000, or for absolute value, switch to abs long */
4566 /* FIXME, we should check abs val, pick short or long */
4567 if (fragP
->fr_opcode
[0] == 0x61)
4569 fragP
->fr_opcode
[0] = 0x4E;
4570 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4571 fix_new (fragP
, fragP
->fr_fix
, 4,
4572 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4576 else if (fragP
->fr_opcode
[0] == 0x60)
4578 fragP
->fr_opcode
[0] = 0x4E;
4579 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4580 fix_new (fragP
, fragP
->fr_fix
, 4,
4581 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4587 /* This should never happen, because if it's a conditional
4588 branch and we are on a 68000, BCC68000 should have been
4589 picked instead of ABRANCH. */
4594 { /* Symbol is still undefined. Make it simple */
4595 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4596 fragP
->fr_offset
, 1, NO_RELOC
);
4598 fragP
->fr_opcode
[1] = (char) 0xff;
4604 } /* case TAB(ABRANCH,SZ_UNDEF) */
4606 case TAB (FBRANCH
, SZ_UNDEF
):
4608 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4609 && relaxable_symbol (fragP
->fr_symbol
))
4612 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4617 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4618 fragP
->fr_offset
, 1, NO_RELOC
);
4620 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4624 } /* TAB(FBRANCH,SZ_UNDEF) */
4626 case TAB (PCREL
, SZ_UNDEF
):
4628 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4629 && relaxable_symbol (fragP
->fr_symbol
))
4632 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4637 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4641 } /* TAB(PCREL,SZ_UNDEF) */
4643 case TAB (BCC68000
, SZ_UNDEF
):
4645 if ((fragP
->fr_symbol
!= NULL
)
4646 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4647 && relaxable_symbol (fragP
->fr_symbol
))
4649 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4652 /* only Bcc 68000 instructions can come here */
4653 if ((fragP
->fr_symbol
!= NULL
) && (flag_short_refs
|| flag_keep_pcrel
))
4655 /* the user wants short refs, so emit one */
4656 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4657 fragP
->fr_offset
, 1, NO_RELOC
);
4662 /* change bcc into b!cc/jmp absl long */
4663 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4664 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4665 /* JF: these were fr_opcode[2,3] */
4666 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4667 buffer_address
[1] = (char) 0xf9;
4668 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4669 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4670 fragP
->fr_offset
, 0, NO_RELOC
);
4675 } /* case TAB(BCC68000,SZ_UNDEF) */
4677 case TAB (DBCC
, SZ_UNDEF
):
4679 if (fragP
->fr_symbol
!= NULL
4680 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4681 && relaxable_symbol (fragP
->fr_symbol
))
4683 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4687 /* only DBcc 68000 instructions can come here */
4689 if (fragP
->fr_symbol
!= NULL
4691 || (! HAVE_LONG_BRANCH (current_architecture
)
4692 && flag_keep_pcrel
)))
4694 /* the user wants short refs, so emit one */
4695 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4696 fragP
->fr_offset
, 1, NO_RELOC
);
4701 /* Change dbcc into dbcc/bral. */
4702 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4703 buffer_address
[0] = 0x00; /* branch offset = 4 */
4704 buffer_address
[1] = 0x04;
4705 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4706 /* JF: these were fr_opcode[5-7] */
4707 buffer_address
[3] = 0x06; /* Plus 6 */
4708 if (HAVE_LONG_BRANCH (current_architecture
))
4710 buffer_address
[4] = 0x60; /* Put in bral (0x60ff). */
4711 buffer_address
[5] = (char) 0xff;
4715 buffer_address
[4] = 0x4e; /* Put in jmp long (0x4ef9). */
4716 buffer_address
[5] = (char) 0xf9;
4718 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4719 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4720 fragP
->fr_offset
, HAVE_LONG_BRANCH (current_architecture
),
4727 } /* case TAB(DBCC,SZ_UNDEF) */
4729 case TAB (PCLEA
, SZ_UNDEF
):
4731 if (((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4732 && relaxable_symbol (fragP
->fr_symbol
))
4734 || cpu_of_arch (current_architecture
) < m68020
4735 || cpu_of_arch (current_architecture
) == mcf5200
)
4737 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4742 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4746 } /* TAB(PCLEA,SZ_UNDEF) */
4748 case TAB (PCINDEX
, SZ_UNDEF
):
4749 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4750 && relaxable_symbol (fragP
->fr_symbol
))
4751 || cpu_of_arch (current_architecture
) < m68020
4752 || cpu_of_arch (current_architecture
) == mcf5200
)
4754 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4758 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4767 /* now that SZ_UNDEF are taken care of, check others */
4768 switch (fragP
->fr_subtype
)
4770 case TAB (BCC68000
, BYTE
):
4771 case TAB (ABRANCH
, BYTE
):
4772 /* We can't do a short jump to the next instruction, so in that
4773 case we force word mode. At this point S_GET_VALUE should
4774 return the offset of the symbol within its frag. If the
4775 symbol is at the start of a frag, and it is the next frag
4776 with any data in it (usually this is just the next frag, but
4777 assembler listings may introduce empty frags), we must use
4779 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0)
4784 stop
= symbol_get_frag (fragP
->fr_symbol
);
4785 for (l
= fragP
->fr_next
; l
!= stop
; l
= l
->fr_next
)
4786 if (l
->fr_fix
+ l
->fr_var
!= 0)
4790 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4798 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4801 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4802 /* the bit-field entries in the relocation_info struct plays hell
4803 with the byte-order problems of cross-assembly. So as a hack,
4804 I added this mach. dependent ri twiddler. Ugly, but it gets
4806 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4807 are symbolnum, most sig. byte first. Last byte is broken up with
4808 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4809 nibble as nuthin. (on Sun 3 at least) */
4810 /* Translate the internal relocation information into target-specific
4814 md_ri_to_chars (the_bytes
, ri
)
4816 struct reloc_info_generic
*ri
;
4819 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4820 /* now the fun stuff */
4821 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4822 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4823 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4824 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4825 ((ri
->r_extern
<< 4) & 0x10));
4828 #endif /* comment */
4830 #ifndef BFD_ASSEMBLER
4832 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4835 relax_addressT segment_address_in_file
;
4838 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4839 * Out: GNU LD relocation length code: 0, 1, or 2.
4842 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4845 know (fixP
->fx_addsy
!= NULL
);
4847 md_number_to_chars (where
,
4848 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4851 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4852 ? S_GET_TYPE (fixP
->fx_addsy
)
4853 : fixP
->fx_addsy
->sy_number
);
4855 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4856 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4857 where
[6] = r_symbolnum
& 0x0ff;
4858 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4859 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4863 #endif /* OBJ_AOUT or OBJ_BOUT */
4865 #ifndef WORKING_DOT_WORD
4866 CONST
int md_short_jump_size
= 4;
4867 CONST
int md_long_jump_size
= 6;
4870 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4872 addressT from_addr
, to_addr
;
4873 fragS
*frag ATTRIBUTE_UNUSED
;
4874 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
4878 offset
= to_addr
- (from_addr
+ 2);
4880 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4881 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4885 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4887 addressT from_addr
, to_addr
;
4893 if (!HAVE_LONG_BRANCH(current_architecture
))
4895 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4896 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4897 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4898 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4903 offset
= to_addr
- (from_addr
+ 2);
4904 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4905 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4911 /* Different values of OK tell what its OK to return. Things that
4912 aren't OK are an error (what a shock, no?)
4915 10: Absolute 1:8 only
4916 20: Absolute 0:7 only
4917 30: absolute 0:15 only
4918 40: Absolute 0:31 only
4919 50: absolute 0:127 only
4920 55: absolute -64:63 only
4921 60: absolute -128:127 only
4922 70: absolute 0:4095 only
4929 struct m68k_exp
*exp
;
4932 if (exp
->exp
.X_op
== O_absent
)
4934 /* Do the same thing the VAX asm does */
4935 op (exp
) = O_constant
;
4941 as_warn (_("expression out of range: defaulting to 1"));
4945 else if (exp
->exp
.X_op
== O_constant
)
4950 if (offs (exp
) < 1 || offs (exp
) > 8)
4952 as_warn (_("expression out of range: defaulting to 1"));
4957 if (offs (exp
) < 0 || offs (exp
) > 7)
4961 if (offs (exp
) < 0 || offs (exp
) > 15)
4965 if (offs (exp
) < 0 || offs (exp
) > 32)
4969 if (offs (exp
) < 0 || offs (exp
) > 127)
4973 if (offs (exp
) < -64 || offs (exp
) > 63)
4977 if (offs (exp
) < -128 || offs (exp
) > 127)
4981 if (offs (exp
) < 0 || offs (exp
) > 4095)
4984 as_warn (_("expression out of range: defaulting to 0"));
4992 else if (exp
->exp
.X_op
== O_big
)
4994 if (offs (exp
) <= 0 /* flonum */
4995 && (ok
== 80 /* no bignums */
4996 || (ok
> 10 /* small-int ranges including 0 ok */
4997 /* If we have a flonum zero, a zero integer should
4998 do as well (e.g., in moveq). */
4999 && generic_floating_point_number
.exponent
== 0
5000 && generic_floating_point_number
.low
[0] == 0)))
5002 /* HACK! Turn it into a long */
5003 LITTLENUM_TYPE words
[6];
5005 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5006 op (exp
) = O_constant
;
5009 offs (exp
) = words
[1] | (words
[0] << 16);
5013 op (exp
) = O_constant
;
5016 offs (exp
) = (ok
== 10) ? 1 : 0;
5017 as_warn (_("Can't deal with expression; defaulting to %ld"),
5023 if (ok
>= 10 && ok
<= 70)
5025 op (exp
) = O_constant
;
5028 offs (exp
) = (ok
== 10) ? 1 : 0;
5029 as_warn (_("Can't deal with expression; defaulting to %ld"),
5034 if (exp
->size
!= SIZE_UNSPEC
)
5042 if (!isbyte (offs (exp
)))
5043 as_warn (_("expression doesn't fit in BYTE"));
5046 if (!isword (offs (exp
)))
5047 as_warn (_("expression doesn't fit in WORD"));
5055 /* These are the back-ends for the various machine dependent pseudo-ops. */
5059 int ignore ATTRIBUTE_UNUSED
;
5061 subseg_set (data_section
, 1);
5062 demand_empty_rest_of_line ();
5067 int ignore ATTRIBUTE_UNUSED
;
5069 subseg_set (data_section
, 2);
5070 demand_empty_rest_of_line ();
5075 int ignore ATTRIBUTE_UNUSED
;
5077 /* We don't support putting frags in the BSS segment, we fake it
5078 by marking in_bss, then looking at s_skip for clues. */
5080 subseg_set (bss_section
, 0);
5081 demand_empty_rest_of_line ();
5086 int ignore ATTRIBUTE_UNUSED
;
5089 register long temp_fill
;
5091 temp
= 1; /* JF should be 2? */
5092 temp_fill
= get_absolute_expression ();
5093 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5094 frag_align (temp
, (int) temp_fill
, 0);
5095 demand_empty_rest_of_line ();
5096 record_alignment (now_seg
, temp
);
5101 int ignore ATTRIBUTE_UNUSED
;
5103 demand_empty_rest_of_line ();
5106 /* Pseudo-ops handled for MRI compatibility. */
5108 /* This function returns non-zero if the argument is a conditional
5109 pseudo-op. This is called when checking whether a pending
5110 alignment is needed. */
5113 m68k_conditional_pseudoop (pop
)
5116 return (pop
->poc_handler
== s_mri_if
5117 || pop
->poc_handler
== s_mri_else
);
5120 /* Handle an MRI style chip specification. */
5129 s
= input_line_pointer
;
5130 /* We can't use get_symbol_end since the processor names are not proper
5132 while (is_part_of_name (c
= *input_line_pointer
++))
5134 *--input_line_pointer
= 0;
5135 for (i
= 0; i
< n_archs
; i
++)
5136 if (strcasecmp (s
, archs
[i
].name
) == 0)
5140 as_bad (_("%s: unrecognized processor name"), s
);
5141 *input_line_pointer
= c
;
5142 ignore_rest_of_line ();
5145 *input_line_pointer
= c
;
5147 if (*input_line_pointer
== '/')
5148 current_architecture
= 0;
5150 current_architecture
&= m68881
| m68851
;
5151 current_architecture
|= archs
[i
].arch
;
5153 while (*input_line_pointer
== '/')
5155 ++input_line_pointer
;
5156 s
= input_line_pointer
;
5157 /* We can't use get_symbol_end since the processor names are not
5159 while (is_part_of_name (c
= *input_line_pointer
++))
5161 *--input_line_pointer
= 0;
5162 if (strcmp (s
, "68881") == 0)
5163 current_architecture
|= m68881
;
5164 else if (strcmp (s
, "68851") == 0)
5165 current_architecture
|= m68851
;
5166 *input_line_pointer
= c
;
5169 /* Update info about available control registers. */
5170 select_control_regs ();
5173 /* The MRI CHIP pseudo-op. */
5177 int ignore ATTRIBUTE_UNUSED
;
5183 stop
= mri_comment_field (&stopc
);
5186 mri_comment_end (stop
, stopc
);
5187 demand_empty_rest_of_line ();
5190 /* The MRI FOPT pseudo-op. */
5194 int ignore ATTRIBUTE_UNUSED
;
5198 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5202 input_line_pointer
+= 3;
5203 temp
= get_absolute_expression ();
5204 if (temp
< 0 || temp
> 7)
5205 as_bad (_("bad coprocessor id"));
5207 m68k_float_copnum
= COP0
+ temp
;
5211 as_bad (_("unrecognized fopt option"));
5212 ignore_rest_of_line ();
5216 demand_empty_rest_of_line ();
5219 /* The structure used to handle the MRI OPT pseudo-op. */
5223 /* The name of the option. */
5226 /* If this is not NULL, just call this function. The first argument
5227 is the ARG field of this structure, the second argument is
5228 whether the option was negated. */
5229 void (*pfn
) PARAMS ((int arg
, int on
));
5231 /* If this is not NULL, and the PFN field is NULL, set the variable
5232 this points to. Set it to the ARG field if the option was not
5233 negated, and the NOTARG field otherwise. */
5236 /* The value to pass to PFN or to assign to *PVAR. */
5239 /* The value to assign to *PVAR if the option is negated. If PFN is
5240 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5241 the option may not be negated. */
5245 /* The table used to handle the MRI OPT pseudo-op. */
5247 static void skip_to_comma
PARAMS ((int, int));
5248 static void opt_nest
PARAMS ((int, int));
5249 static void opt_chip
PARAMS ((int, int));
5250 static void opt_list
PARAMS ((int, int));
5251 static void opt_list_symbols
PARAMS ((int, int));
5253 static const struct opt_action opt_table
[] =
5255 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5257 /* We do relaxing, so there is little use for these options. */
5258 { "b", 0, 0, 0, 0 },
5259 { "brs", 0, 0, 0, 0 },
5260 { "brb", 0, 0, 0, 0 },
5261 { "brl", 0, 0, 0, 0 },
5262 { "brw", 0, 0, 0, 0 },
5264 { "c", 0, 0, 0, 0 },
5265 { "cex", 0, 0, 0, 0 },
5266 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5267 { "cl", 0, 0, 0, 0 },
5268 { "cre", 0, 0, 0, 0 },
5269 { "d", 0, &flag_keep_locals
, 1, 0 },
5270 { "e", 0, 0, 0, 0 },
5271 { "f", 0, &flag_short_refs
, 1, 0 },
5272 { "frs", 0, &flag_short_refs
, 1, 0 },
5273 { "frl", 0, &flag_short_refs
, 0, 1 },
5274 { "g", 0, 0, 0, 0 },
5275 { "i", 0, 0, 0, 0 },
5276 { "m", 0, 0, 0, 0 },
5277 { "mex", 0, 0, 0, 0 },
5278 { "mc", 0, 0, 0, 0 },
5279 { "md", 0, 0, 0, 0 },
5280 { "nest", opt_nest
, 0, 0, 0 },
5281 { "next", skip_to_comma
, 0, 0, 0 },
5282 { "o", 0, 0, 0, 0 },
5283 { "old", 0, 0, 0, 0 },
5284 { "op", skip_to_comma
, 0, 0, 0 },
5285 { "pco", 0, 0, 0, 0 },
5286 { "p", opt_chip
, 0, 0, 0 },
5287 { "pcr", 0, 0, 0, 0 },
5288 { "pcs", 0, 0, 0, 0 },
5289 { "r", 0, 0, 0, 0 },
5290 { "quick", 0, &m68k_quick
, 1, 0 },
5291 { "rel32", 0, &m68k_rel32
, 1, 0 },
5292 { "s", opt_list
, 0, 0, 0 },
5293 { "t", opt_list_symbols
, 0, 0, 0 },
5294 { "w", 0, &flag_no_warnings
, 0, 1 },
5298 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5300 /* The MRI OPT pseudo-op. */
5304 int ignore ATTRIBUTE_UNUSED
;
5312 const struct opt_action
*o
;
5317 if (*input_line_pointer
== '-')
5319 ++input_line_pointer
;
5322 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5324 input_line_pointer
+= 2;
5328 s
= input_line_pointer
;
5329 c
= get_symbol_end ();
5331 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5333 if (strcasecmp (s
, o
->name
) == 0)
5337 /* Restore input_line_pointer now in case the option
5339 *input_line_pointer
= c
;
5340 (*o
->pfn
) (o
->arg
, t
);
5342 else if (o
->pvar
!= NULL
)
5344 if (! t
&& o
->arg
== o
->notarg
)
5345 as_bad (_("option `%s' may not be negated"), s
);
5346 *input_line_pointer
= c
;
5347 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5350 *input_line_pointer
= c
;
5356 as_bad (_("option `%s' not recognized"), s
);
5357 *input_line_pointer
= c
;
5360 while (*input_line_pointer
++ == ',');
5362 /* Move back to terminating character. */
5363 --input_line_pointer
;
5364 demand_empty_rest_of_line ();
5367 /* Skip ahead to a comma. This is used for OPT options which we do
5368 not suppor tand which take arguments. */
5371 skip_to_comma (arg
, on
)
5372 int arg ATTRIBUTE_UNUSED
;
5373 int on ATTRIBUTE_UNUSED
;
5375 while (*input_line_pointer
!= ','
5376 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5377 ++input_line_pointer
;
5380 /* Handle the OPT NEST=depth option. */
5384 int arg ATTRIBUTE_UNUSED
;
5385 int on ATTRIBUTE_UNUSED
;
5387 if (*input_line_pointer
!= '=')
5389 as_bad (_("bad format of OPT NEST=depth"));
5393 ++input_line_pointer
;
5394 max_macro_nest
= get_absolute_expression ();
5397 /* Handle the OPT P=chip option. */
5401 int arg ATTRIBUTE_UNUSED
;
5402 int on ATTRIBUTE_UNUSED
;
5404 if (*input_line_pointer
!= '=')
5406 /* This is just OPT P, which we do not support. */
5410 ++input_line_pointer
;
5414 /* Handle the OPT S option. */
5418 int arg ATTRIBUTE_UNUSED
;
5424 /* Handle the OPT T option. */
5427 opt_list_symbols (arg
, on
)
5428 int arg ATTRIBUTE_UNUSED
;
5432 listing
|= LISTING_SYMBOLS
;
5434 listing
&=~ LISTING_SYMBOLS
;
5437 /* Handle the MRI REG pseudo-op. */
5441 int ignore ATTRIBUTE_UNUSED
;
5450 if (line_label
== NULL
)
5452 as_bad (_("missing label"));
5453 ignore_rest_of_line ();
5458 stop
= mri_comment_field (&stopc
);
5462 s
= input_line_pointer
;
5463 while (isalnum ((unsigned char) *input_line_pointer
)
5464 #ifdef REGISTER_PREFIX
5465 || *input_line_pointer
== REGISTER_PREFIX
5467 || *input_line_pointer
== '/'
5468 || *input_line_pointer
== '-')
5469 ++input_line_pointer
;
5470 c
= *input_line_pointer
;
5471 *input_line_pointer
= '\0';
5473 if (m68k_ip_op (s
, &rop
) != 0)
5475 if (rop
.error
== NULL
)
5476 as_bad (_("bad register list"));
5478 as_bad (_("bad register list: %s"), rop
.error
);
5479 *input_line_pointer
= c
;
5480 ignore_rest_of_line ();
5484 *input_line_pointer
= c
;
5486 if (rop
.mode
== REGLST
)
5488 else if (rop
.mode
== DREG
)
5489 mask
= 1 << (rop
.reg
- DATA0
);
5490 else if (rop
.mode
== AREG
)
5491 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5492 else if (rop
.mode
== FPREG
)
5493 mask
= 1 << (rop
.reg
- FP0
+ 16);
5494 else if (rop
.mode
== CONTROL
5497 else if (rop
.mode
== CONTROL
5500 else if (rop
.mode
== CONTROL
5505 as_bad (_("bad register list"));
5506 ignore_rest_of_line ();
5510 S_SET_SEGMENT (line_label
, reg_section
);
5511 S_SET_VALUE (line_label
, ~mask
);
5512 symbol_set_frag (line_label
, &zero_address_frag
);
5515 mri_comment_end (stop
, stopc
);
5517 demand_empty_rest_of_line ();
5520 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5524 struct save_opts
*next
;
5526 int symbols_case_sensitive
;
5534 /* FIXME: We don't save OPT S. */
5537 /* This variable holds the stack of saved options. */
5539 static struct save_opts
*save_stack
;
5541 /* The MRI SAVE pseudo-op. */
5545 int ignore ATTRIBUTE_UNUSED
;
5547 struct save_opts
*s
;
5549 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5550 s
->abspcadd
= m68k_abspcadd
;
5551 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5552 s
->keep_locals
= flag_keep_locals
;
5553 s
->short_refs
= flag_short_refs
;
5554 s
->architecture
= current_architecture
;
5555 s
->quick
= m68k_quick
;
5556 s
->rel32
= m68k_rel32
;
5557 s
->listing
= listing
;
5558 s
->no_warnings
= flag_no_warnings
;
5560 s
->next
= save_stack
;
5563 demand_empty_rest_of_line ();
5566 /* The MRI RESTORE pseudo-op. */
5570 int ignore ATTRIBUTE_UNUSED
;
5572 struct save_opts
*s
;
5574 if (save_stack
== NULL
)
5576 as_bad (_("restore without save"));
5577 ignore_rest_of_line ();
5582 save_stack
= s
->next
;
5584 m68k_abspcadd
= s
->abspcadd
;
5585 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5586 flag_keep_locals
= s
->keep_locals
;
5587 flag_short_refs
= s
->short_refs
;
5588 current_architecture
= s
->architecture
;
5589 m68k_quick
= s
->quick
;
5590 m68k_rel32
= s
->rel32
;
5591 listing
= s
->listing
;
5592 flag_no_warnings
= s
->no_warnings
;
5596 demand_empty_rest_of_line ();
5599 /* Types of MRI structured control directives. */
5601 enum mri_control_type
5609 /* This structure is used to stack the MRI structured control
5612 struct mri_control_info
5614 /* The directive within which this one is enclosed. */
5615 struct mri_control_info
*outer
;
5617 /* The type of directive. */
5618 enum mri_control_type type
;
5620 /* Whether an ELSE has been in an IF. */
5623 /* The add or sub statement at the end of a FOR. */
5626 /* The label of the top of a FOR or REPEAT loop. */
5629 /* The label to jump to for the next iteration, or the else
5630 expression of a conditional. */
5633 /* The label to jump to to break out of the loop, or the label past
5634 the end of a conditional. */
5638 /* The stack of MRI structured control directives. */
5640 static struct mri_control_info
*mri_control_stack
;
5642 /* The current MRI structured control directive index number, used to
5643 generate label names. */
5645 static int mri_control_index
;
5647 /* Some function prototypes. */
5649 static void mri_assemble
PARAMS ((char *));
5650 static char *mri_control_label
PARAMS ((void));
5651 static struct mri_control_info
*push_mri_control
5652 PARAMS ((enum mri_control_type
));
5653 static void pop_mri_control
PARAMS ((void));
5654 static int parse_mri_condition
PARAMS ((int *));
5655 static int parse_mri_control_operand
5656 PARAMS ((int *, char **, char **, char **, char **));
5657 static int swap_mri_condition
PARAMS ((int));
5658 static int reverse_mri_condition
PARAMS ((int));
5659 static void build_mri_control_operand
5660 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5661 const char *, int));
5662 static void parse_mri_control_expression
5663 PARAMS ((char *, int, const char *, const char *, int));
5665 /* Assemble an instruction for an MRI structured control directive. */
5673 /* md_assemble expects the opcode to be in lower case. */
5674 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
5676 if (isupper ((unsigned char) *s
))
5677 *s
= tolower ((unsigned char) *s
);
5683 /* Generate a new MRI label structured control directive label name. */
5686 mri_control_label ()
5690 n
= (char *) xmalloc (20);
5691 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5692 ++mri_control_index
;
5696 /* Create a new MRI structured control directive. */
5698 static struct mri_control_info
*
5699 push_mri_control (type
)
5700 enum mri_control_type type
;
5702 struct mri_control_info
*n
;
5704 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5708 if (type
== mri_if
|| type
== mri_while
)
5711 n
->top
= mri_control_label ();
5712 n
->next
= mri_control_label ();
5713 n
->bottom
= mri_control_label ();
5715 n
->outer
= mri_control_stack
;
5716 mri_control_stack
= n
;
5721 /* Pop off the stack of MRI structured control directives. */
5726 struct mri_control_info
*n
;
5728 n
= mri_control_stack
;
5729 mri_control_stack
= n
->outer
;
5737 /* Recognize a condition code in an MRI structured control expression. */
5740 parse_mri_condition (pcc
)
5745 know (*input_line_pointer
== '<');
5747 ++input_line_pointer
;
5748 c1
= *input_line_pointer
++;
5749 c2
= *input_line_pointer
++;
5751 if (*input_line_pointer
!= '>')
5753 as_bad (_("syntax error in structured control directive"));
5757 ++input_line_pointer
;
5765 *pcc
= (c1
<< 8) | c2
;
5770 /* Parse a single operand in an MRI structured control expression. */
5773 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5790 if (*input_line_pointer
== '<')
5792 /* It's just a condition code. */
5793 return parse_mri_condition (pcc
);
5796 /* Look ahead for the condition code. */
5797 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5799 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5804 as_bad (_("missing condition code in structured control directive"));
5808 *leftstart
= input_line_pointer
;
5810 if (*leftstop
> *leftstart
5811 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5814 input_line_pointer
= s
;
5815 if (! parse_mri_condition (pcc
))
5818 /* Look ahead for AND or OR or end of line. */
5819 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5821 if ((strncasecmp (s
, "AND", 3) == 0
5822 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5823 || (strncasecmp (s
, "OR", 2) == 0
5824 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5828 *rightstart
= input_line_pointer
;
5830 if (*rightstop
> *rightstart
5831 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5834 input_line_pointer
= s
;
5839 #define MCC(b1, b2) (((b1) << 8) | (b2))
5841 /* Swap the sense of a condition. This changes the condition so that
5842 it generates the same result when the operands are swapped. */
5845 swap_mri_condition (cc
)
5850 case MCC ('h', 'i'): return MCC ('c', 's');
5851 case MCC ('l', 's'): return MCC ('c', 'c');
5852 case MCC ('c', 'c'): return MCC ('l', 's');
5853 case MCC ('c', 's'): return MCC ('h', 'i');
5854 case MCC ('p', 'l'): return MCC ('m', 'i');
5855 case MCC ('m', 'i'): return MCC ('p', 'l');
5856 case MCC ('g', 'e'): return MCC ('l', 'e');
5857 case MCC ('l', 't'): return MCC ('g', 't');
5858 case MCC ('g', 't'): return MCC ('l', 't');
5859 case MCC ('l', 'e'): return MCC ('g', 'e');
5864 /* Reverse the sense of a condition. */
5867 reverse_mri_condition (cc
)
5872 case MCC ('h', 'i'): return MCC ('l', 's');
5873 case MCC ('l', 's'): return MCC ('h', 'i');
5874 case MCC ('c', 'c'): return MCC ('c', 's');
5875 case MCC ('c', 's'): return MCC ('c', 'c');
5876 case MCC ('n', 'e'): return MCC ('e', 'q');
5877 case MCC ('e', 'q'): return MCC ('n', 'e');
5878 case MCC ('v', 'c'): return MCC ('v', 's');
5879 case MCC ('v', 's'): return MCC ('v', 'c');
5880 case MCC ('p', 'l'): return MCC ('m', 'i');
5881 case MCC ('m', 'i'): return MCC ('p', 'l');
5882 case MCC ('g', 'e'): return MCC ('l', 't');
5883 case MCC ('l', 't'): return MCC ('g', 'e');
5884 case MCC ('g', 't'): return MCC ('l', 'e');
5885 case MCC ('l', 'e'): return MCC ('g', 't');
5890 /* Build an MRI structured control expression. This generates test
5891 and branch instructions. It goes to TRUELAB if the condition is
5892 true, and to FALSELAB if the condition is false. Exactly one of
5893 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5894 is the size qualifier for the expression. EXTENT is the size to
5895 use for the branch. */
5898 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5899 rightstop
, truelab
, falselab
, extent
)
5906 const char *truelab
;
5907 const char *falselab
;
5913 if (leftstart
!= NULL
)
5915 struct m68k_op leftop
, rightop
;
5918 /* Swap the compare operands, if necessary, to produce a legal
5919 m68k compare instruction. Comparing a register operand with
5920 a non-register operand requires the register to be on the
5921 right (cmp, cmpa). Comparing an immediate value with
5922 anything requires the immediate value to be on the left
5927 (void) m68k_ip_op (leftstart
, &leftop
);
5932 (void) m68k_ip_op (rightstart
, &rightop
);
5935 if (rightop
.mode
== IMMED
5936 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5937 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5941 cc
= swap_mri_condition (cc
);
5943 leftstart
= rightstart
;
5946 leftstop
= rightstop
;
5951 if (truelab
== NULL
)
5953 cc
= reverse_mri_condition (cc
);
5957 if (leftstart
!= NULL
)
5959 buf
= (char *) xmalloc (20
5960 + (leftstop
- leftstart
)
5961 + (rightstop
- rightstart
));
5969 memcpy (s
, leftstart
, leftstop
- leftstart
);
5970 s
+= leftstop
- leftstart
;
5972 memcpy (s
, rightstart
, rightstop
- rightstart
);
5973 s
+= rightstop
- rightstart
;
5979 buf
= (char *) xmalloc (20 + strlen (truelab
));
5987 strcpy (s
, truelab
);
5992 /* Parse an MRI structured control expression. This generates test
5993 and branch instructions. STOP is where the expression ends. It
5994 goes to TRUELAB if the condition is true, and to FALSELAB if the
5995 condition is false. Exactly one of TRUELAB and FALSELAB will be
5996 NULL, meaning to fall through. QUAL is the size qualifier for the
5997 expression. EXTENT is the size to use for the branch. */
6000 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
6003 const char *truelab
;
6004 const char *falselab
;
6017 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6018 &rightstart
, &rightstop
))
6024 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6028 if (falselab
!= NULL
)
6031 flab
= mri_control_label ();
6033 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6034 rightstop
, (const char *) NULL
, flab
, extent
);
6036 input_line_pointer
+= 3;
6037 if (*input_line_pointer
!= '.'
6038 || input_line_pointer
[1] == '\0')
6042 qual
= input_line_pointer
[1];
6043 input_line_pointer
+= 2;
6046 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6047 &rightstart
, &rightstop
))
6053 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6054 rightstop
, truelab
, falselab
, extent
);
6056 if (falselab
== NULL
)
6059 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6063 if (truelab
!= NULL
)
6066 tlab
= mri_control_label ();
6068 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6069 rightstop
, tlab
, (const char *) NULL
, extent
);
6071 input_line_pointer
+= 2;
6072 if (*input_line_pointer
!= '.'
6073 || input_line_pointer
[1] == '\0')
6077 qual
= input_line_pointer
[1];
6078 input_line_pointer
+= 2;
6081 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6082 &rightstart
, &rightstop
))
6088 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6089 rightstop
, truelab
, falselab
, extent
);
6091 if (truelab
== NULL
)
6096 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6097 rightstop
, truelab
, falselab
, extent
);
6101 if (input_line_pointer
!= stop
)
6102 as_bad (_("syntax error in structured control directive"));
6105 /* Handle the MRI IF pseudo-op. This may be a structured control
6106 directive, or it may be a regular assembler conditional, depending
6115 struct mri_control_info
*n
;
6117 /* A structured control directive must end with THEN with an
6118 optional qualifier. */
6119 s
= input_line_pointer
;
6120 while (! is_end_of_line
[(unsigned char) *s
]
6121 && (! flag_mri
|| *s
!= '*'))
6124 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6127 if (s
- input_line_pointer
> 1
6131 if (s
- input_line_pointer
< 3
6132 || strncasecmp (s
- 3, "THEN", 4) != 0)
6136 as_bad (_("missing then"));
6137 ignore_rest_of_line ();
6141 /* It's a conditional. */
6146 /* Since this might be a conditional if, this pseudo-op will be
6147 called even if we are supported to be ignoring input. Double
6148 check now. Clobber *input_line_pointer so that ignore_input
6149 thinks that this is not a special pseudo-op. */
6150 c
= *input_line_pointer
;
6151 *input_line_pointer
= 0;
6152 if (ignore_input ())
6154 *input_line_pointer
= c
;
6155 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6156 ++input_line_pointer
;
6157 demand_empty_rest_of_line ();
6160 *input_line_pointer
= c
;
6162 n
= push_mri_control (mri_if
);
6164 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6165 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6168 input_line_pointer
= s
+ 3;
6170 input_line_pointer
= s
+ 1;
6174 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6175 ++input_line_pointer
;
6178 demand_empty_rest_of_line ();
6181 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6182 structured IF, associate the ELSE with the IF. Otherwise, assume
6183 it is a conditional else. */
6194 && (mri_control_stack
== NULL
6195 || mri_control_stack
->type
!= mri_if
6196 || mri_control_stack
->else_seen
))
6202 c
= *input_line_pointer
;
6203 *input_line_pointer
= 0;
6204 if (ignore_input ())
6206 *input_line_pointer
= c
;
6207 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6208 ++input_line_pointer
;
6209 demand_empty_rest_of_line ();
6212 *input_line_pointer
= c
;
6214 if (mri_control_stack
== NULL
6215 || mri_control_stack
->type
!= mri_if
6216 || mri_control_stack
->else_seen
)
6218 as_bad (_("else without matching if"));
6219 ignore_rest_of_line ();
6223 mri_control_stack
->else_seen
= 1;
6225 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6228 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6232 colon (mri_control_stack
->next
);
6236 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6237 ++input_line_pointer
;
6240 demand_empty_rest_of_line ();
6243 /* Handle the MRI ENDI pseudo-op. */
6247 int ignore ATTRIBUTE_UNUSED
;
6249 if (mri_control_stack
== NULL
6250 || mri_control_stack
->type
!= mri_if
)
6252 as_bad (_("endi without matching if"));
6253 ignore_rest_of_line ();
6257 /* ignore_input will not return true for ENDI, so we don't need to
6258 worry about checking it again here. */
6260 if (! mri_control_stack
->else_seen
)
6261 colon (mri_control_stack
->next
);
6262 colon (mri_control_stack
->bottom
);
6268 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6269 ++input_line_pointer
;
6272 demand_empty_rest_of_line ();
6275 /* Handle the MRI BREAK pseudo-op. */
6278 s_mri_break (extent
)
6281 struct mri_control_info
*n
;
6285 n
= mri_control_stack
;
6287 && n
->type
!= mri_for
6288 && n
->type
!= mri_repeat
6289 && n
->type
!= mri_while
)
6293 as_bad (_("break outside of structured loop"));
6294 ignore_rest_of_line ();
6298 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6301 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6307 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6308 ++input_line_pointer
;
6311 demand_empty_rest_of_line ();
6314 /* Handle the MRI NEXT pseudo-op. */
6320 struct mri_control_info
*n
;
6324 n
= mri_control_stack
;
6326 && n
->type
!= mri_for
6327 && n
->type
!= mri_repeat
6328 && n
->type
!= mri_while
)
6332 as_bad (_("next outside of structured loop"));
6333 ignore_rest_of_line ();
6337 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6340 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6346 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6347 ++input_line_pointer
;
6350 demand_empty_rest_of_line ();
6353 /* Handle the MRI FOR pseudo-op. */
6359 const char *varstart
, *varstop
;
6360 const char *initstart
, *initstop
;
6361 const char *endstart
, *endstop
;
6362 const char *bystart
, *bystop
;
6366 struct mri_control_info
*n
;
6372 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6376 varstart
= input_line_pointer
;
6378 /* Look for the '='. */
6379 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6380 && *input_line_pointer
!= '=')
6381 ++input_line_pointer
;
6382 if (*input_line_pointer
!= '=')
6384 as_bad (_("missing ="));
6385 ignore_rest_of_line ();
6389 varstop
= input_line_pointer
;
6390 if (varstop
> varstart
6391 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6394 ++input_line_pointer
;
6396 initstart
= input_line_pointer
;
6398 /* Look for TO or DOWNTO. */
6401 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6403 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6404 && ! is_part_of_name (input_line_pointer
[2]))
6406 initstop
= input_line_pointer
;
6407 input_line_pointer
+= 2;
6410 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6411 && ! is_part_of_name (input_line_pointer
[6]))
6413 initstop
= input_line_pointer
;
6415 input_line_pointer
+= 6;
6418 ++input_line_pointer
;
6420 if (initstop
== NULL
)
6422 as_bad (_("missing to or downto"));
6423 ignore_rest_of_line ();
6426 if (initstop
> initstart
6427 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6431 endstart
= input_line_pointer
;
6433 /* Look for BY or DO. */
6436 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6438 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6439 && ! is_part_of_name (input_line_pointer
[2]))
6441 endstop
= input_line_pointer
;
6443 input_line_pointer
+= 2;
6446 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6447 && (input_line_pointer
[2] == '.'
6448 || ! is_part_of_name (input_line_pointer
[2])))
6450 endstop
= input_line_pointer
;
6451 input_line_pointer
+= 2;
6454 ++input_line_pointer
;
6456 if (endstop
== NULL
)
6458 as_bad (_("missing do"));
6459 ignore_rest_of_line ();
6462 if (endstop
> endstart
6463 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6469 bystop
= bystart
+ 2;
6474 bystart
= input_line_pointer
;
6478 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6480 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6481 && (input_line_pointer
[2] == '.'
6482 || ! is_part_of_name (input_line_pointer
[2])))
6484 bystop
= input_line_pointer
;
6485 input_line_pointer
+= 2;
6488 ++input_line_pointer
;
6492 as_bad (_("missing do"));
6493 ignore_rest_of_line ();
6496 if (bystop
> bystart
6497 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6501 if (*input_line_pointer
!= '.')
6505 extent
= input_line_pointer
[1];
6506 input_line_pointer
+= 2;
6509 /* We have fully parsed the FOR operands. Now build the loop. */
6511 n
= push_mri_control (mri_for
);
6513 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6524 memcpy (s
, initstart
, initstop
- initstart
);
6525 s
+= initstop
- initstart
;
6527 memcpy (s
, varstart
, varstop
- varstart
);
6528 s
+= varstop
- varstart
;
6542 memcpy (s
, endstart
, endstop
- endstart
);
6543 s
+= endstop
- endstart
;
6545 memcpy (s
, varstart
, varstop
- varstart
);
6546 s
+= varstop
- varstart
;
6554 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6556 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6559 /* Put together the add or sub instruction used by ENDF. */
6569 memcpy (s
, bystart
, bystop
- bystart
);
6570 s
+= bystop
- bystart
;
6572 memcpy (s
, varstart
, varstop
- varstart
);
6573 s
+= varstop
- varstart
;
6579 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6580 ++input_line_pointer
;
6583 demand_empty_rest_of_line ();
6586 /* Handle the MRI ENDF pseudo-op. */
6590 int ignore ATTRIBUTE_UNUSED
;
6592 if (mri_control_stack
== NULL
6593 || mri_control_stack
->type
!= mri_for
)
6595 as_bad (_("endf without for"));
6596 ignore_rest_of_line ();
6600 colon (mri_control_stack
->next
);
6602 mri_assemble (mri_control_stack
->incr
);
6604 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6605 mri_assemble (mri_control_stack
->incr
);
6607 free (mri_control_stack
->incr
);
6609 colon (mri_control_stack
->bottom
);
6615 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6616 ++input_line_pointer
;
6619 demand_empty_rest_of_line ();
6622 /* Handle the MRI REPEAT pseudo-op. */
6625 s_mri_repeat (ignore
)
6626 int ignore ATTRIBUTE_UNUSED
;
6628 struct mri_control_info
*n
;
6630 n
= push_mri_control (mri_repeat
);
6634 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6635 ++input_line_pointer
;
6637 demand_empty_rest_of_line ();
6640 /* Handle the MRI UNTIL pseudo-op. */
6648 if (mri_control_stack
== NULL
6649 || mri_control_stack
->type
!= mri_repeat
)
6651 as_bad (_("until without repeat"));
6652 ignore_rest_of_line ();
6656 colon (mri_control_stack
->next
);
6658 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6661 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6662 mri_control_stack
->top
, '\0');
6664 colon (mri_control_stack
->bottom
);
6666 input_line_pointer
= s
;
6672 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6673 ++input_line_pointer
;
6676 demand_empty_rest_of_line ();
6679 /* Handle the MRI WHILE pseudo-op. */
6687 struct mri_control_info
*n
;
6689 s
= input_line_pointer
;
6690 while (! is_end_of_line
[(unsigned char) *s
]
6691 && (! flag_mri
|| *s
!= '*'))
6694 while (*s
== ' ' || *s
== '\t')
6696 if (s
- input_line_pointer
> 1
6699 if (s
- input_line_pointer
< 2
6700 || strncasecmp (s
- 1, "DO", 2) != 0)
6702 as_bad (_("missing do"));
6703 ignore_rest_of_line ();
6707 n
= push_mri_control (mri_while
);
6711 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6712 s
[1] == '.' ? s
[2] : '\0');
6714 input_line_pointer
= s
+ 1;
6715 if (*input_line_pointer
== '.')
6716 input_line_pointer
+= 2;
6720 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6721 ++input_line_pointer
;
6724 demand_empty_rest_of_line ();
6727 /* Handle the MRI ENDW pseudo-op. */
6731 int ignore ATTRIBUTE_UNUSED
;
6735 if (mri_control_stack
== NULL
6736 || mri_control_stack
->type
!= mri_while
)
6738 as_bad (_("endw without while"));
6739 ignore_rest_of_line ();
6743 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6744 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6748 colon (mri_control_stack
->bottom
);
6754 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6755 ++input_line_pointer
;
6758 demand_empty_rest_of_line ();
6763 * Invocation line includes a switch not recognized by the base assembler.
6764 * See if it's a processor-specific option. These are:
6766 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6767 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6768 * Select the architecture. Instructions or features not
6769 * supported by the selected architecture cause fatal
6770 * errors. More than one may be specified. The default is
6771 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6772 * for -m68000, and -m68882 is a synonym for -m68881.
6773 * -[A]m[c]no-68851, -[A]m[c]no-68881
6774 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6775 * so don't use or document it, but that's the way the parsing
6778 * -pic Indicates PIC.
6779 * -k Indicates PIC. (Sun 3 only.)
6780 * --pcrel Never turn PC-relative branches into absolute jumps.
6783 * Permit `|' to be used in expressions.
6788 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6790 CONST
char *md_shortopts
= "lSA:m:k";
6793 struct option md_longopts
[] = {
6794 #define OPTION_PIC (OPTION_MD_BASE)
6795 {"pic", no_argument
, NULL
, OPTION_PIC
},
6796 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6797 {"register-prefix-optional", no_argument
, NULL
,
6798 OPTION_REGISTER_PREFIX_OPTIONAL
},
6799 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6800 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
6801 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6802 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
6803 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6804 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
6805 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6806 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
6807 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6808 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
6809 #define OPTION_PCREL (OPTION_MD_BASE + 7)
6810 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
6811 {NULL
, no_argument
, NULL
, 0}
6813 size_t md_longopts_size
= sizeof(md_longopts
);
6816 md_parse_option (c
, arg
)
6822 case 'l': /* -l means keep external to 2 bit offset
6823 rather than 16 bit one */
6824 flag_short_refs
= 1;
6827 case 'S': /* -S means that jbsr's always turn into
6829 flag_long_jumps
= 1;
6832 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
6833 branches into absolute jumps. */
6834 flag_keep_pcrel
= 1;
6840 /* intentional fall-through */
6843 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6847 const char *oarg
= arg
;
6853 if (arg
[0] == 'c' && arg
[1] == '6')
6856 for (i
= 0; i
< n_archs
; i
++)
6857 if (!strcmp (arg
, archs
[i
].name
))
6862 as_bad (_("unrecognized option `%s'"), oarg
);
6865 arch
= archs
[i
].arch
;
6868 else if (arch
== m68851
)
6877 if (arg
[0] == 'c' && arg
[1] == '6')
6880 for (i
= 0; i
< n_archs
; i
++)
6881 if (!strcmp (arg
, archs
[i
].name
))
6883 unsigned long arch
= archs
[i
].arch
;
6884 if (cpu_of_arch (arch
))
6885 /* It's a cpu spec. */
6887 current_architecture
&= ~m68000up
;
6888 current_architecture
|= arch
;
6890 else if (arch
== m68881
)
6892 current_architecture
|= m68881
;
6895 else if (arch
== m68851
)
6897 current_architecture
|= m68851
;
6907 as_bad (_("unrecognized architecture specification `%s'"), arg
);
6916 break; /* -pic, Position Independent Code */
6918 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6919 flag_reg_prefix_optional
= 1;
6920 reg_prefix_optional_seen
= 1;
6923 /* -V: SVR4 argument to print version ID. */
6925 print_version_id ();
6928 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6929 should be emitted or not. FIXME: Not implemented. */
6933 case OPTION_BITWISE_OR
:
6938 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
6940 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
6944 m68k_comment_chars
= n
;
6948 case OPTION_BASE_SIZE_DEFAULT_16
:
6949 m68k_index_width_default
= SIZE_WORD
;
6952 case OPTION_BASE_SIZE_DEFAULT_32
:
6953 m68k_index_width_default
= SIZE_LONG
;
6956 case OPTION_DISP_SIZE_DEFAULT_16
:
6958 m68k_rel32_from_cmdline
= 1;
6961 case OPTION_DISP_SIZE_DEFAULT_32
:
6963 m68k_rel32_from_cmdline
= 1;
6974 md_show_usage (stream
)
6977 fprintf(stream
, _("\
6979 -l use 1 word for refs to undefined symbols [default 2]\n\
6980 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6981 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6982 | -mcpu32 | -m5200\n\
6983 specify variant of 680X0 architecture [default 68020]\n\
6984 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6985 target has/lacks floating-point coprocessor\n\
6986 [default yes for 68020, 68030, and cpu32]\n"));
6987 fprintf(stream
, _("\
6988 -m68851 | -mno-68851\n\
6989 target has/lacks memory-management unit coprocessor\n\
6990 [default yes for 68020 and up]\n\
6991 -pic, -k generate position independent code\n\
6992 -S turn jbsr into jsr\n\
6993 --pcrel never turn PC-relative branches into absolute jumps\n\
6994 --register-prefix-optional\n\
6995 recognize register names without prefix character\n\
6996 --bitwise-or do not treat `|' as a comment character\n"));
6997 fprintf (stream
, _("\
6998 --base-size-default-16 base reg without size is 16 bits\n\
6999 --base-size-default-32 base reg without size is 32 bits (default)\n\
7000 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7001 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
7006 /* TEST2: Test md_assemble() */
7007 /* Warning, this routine probably doesn't work anymore */
7011 struct m68k_it the_ins
;
7019 if (!gets (buf
) || !*buf
)
7021 if (buf
[0] == '|' || buf
[1] == '.')
7023 for (cp
= buf
; *cp
; cp
++)
7028 memset (&the_ins
, '\0', sizeof (the_ins
));
7029 m68k_ip (&the_ins
, buf
);
7032 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7036 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7037 for (n
= 0; n
< the_ins
.numo
; n
++)
7038 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7040 print_the_insn (&the_ins
.opcode
[0], stdout
);
7041 (void) putchar ('\n');
7043 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7045 if (the_ins
.operands
[n
].error
)
7047 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7050 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
7051 if (the_ins
.operands
[n
].b_const
)
7052 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
7053 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7054 if (the_ins
.operands
[n
].b_iadd
)
7055 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
7056 (void) putchar ('\n');
7068 while (*str
&& *str
!= ' ')
7070 if (str
[-1] == ':' || str
[1] == '=')
7077 /* Possible states for relaxation:
7079 0 0 branch offset byte (bra, etc)
7083 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7087 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7094 /* We have no need to default values of symbols. */
7098 md_undefined_symbol (name
)
7099 char *name ATTRIBUTE_UNUSED
;
7104 /* Round up a section size to the appropriate boundary. */
7106 md_section_align (segment
, size
)
7107 segT segment ATTRIBUTE_UNUSED
;
7111 #ifdef BFD_ASSEMBLER
7112 /* For a.out, force the section size to be aligned. If we don't do
7113 this, BFD will align it for us, but it will not write out the
7114 final bytes of the section. This may be a bug in BFD, but it is
7115 easier to fix it here since that is how the other a.out targets
7119 align
= bfd_get_section_alignment (stdoutput
, segment
);
7120 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
7127 /* Exactly what point is a PC-relative offset relative TO?
7128 On the 68k, it is relative to the address of the first extension
7129 word. The difference between the addresses of the offset and the
7130 first extension word is stored in fx_pcrel_adjust. */
7132 md_pcrel_from (fixP
)
7137 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
7139 adjust
= fixP
->fx_pcrel_adjust
;
7142 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7145 #ifndef BFD_ASSEMBLER
7150 tc_coff_symbol_emit_hook (ignore
)
7151 symbolS
*ignore ATTRIBUTE_UNUSED
;
7156 tc_coff_sizemachdep (frag
)
7159 switch (frag
->fr_subtype
& 0x3)
7176 void m68k_elf_final_processing()
7178 /* Set file-specific flags if this is a cpu32 processor */
7179 if (cpu_of_arch (current_architecture
) & cpu32
)
7180 elf_elfheader (stdoutput
)->e_flags
|= EF_CPU32
;
7183 /* end of tc-m68k.c */