1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/m68k.h"
28 #include "m68k-parse.h"
30 /* This string holds the chars that always start a comment. If the
31 pre-processor is disabled, these aren't very useful. The macro
32 tc_comment_chars points to this. We use this, rather than the
33 usual comment_chars, so that the --bitwise-or option will work. */
34 #if defined (TE_SVR4) || defined (TE_DELTA)
35 const char *m68k_comment_chars
= "|#";
37 const char *m68k_comment_chars
= "|";
40 /* This array holds the chars that only start a comment at the beginning of
41 a line. If the line seems to have the form '# 123 filename'
42 .line and .file directives will appear in the pre-processed output */
43 /* Note that input_file.c hand checks for '#' at the beginning of the
44 first line of the input file. This is because the compiler outputs
45 #NO_APP at the beginning of its output. */
46 /* Also note that comments like this one will always work. */
47 const char line_comment_chars
[] = "#*";
49 const char line_separator_chars
[] = "";
51 /* Chars that can be used to separate mant from exp in floating point nums */
52 CONST
char EXP_CHARS
[] = "eE";
54 /* Chars that mean this number is a floating point constant, as
55 in "0f12.456" or "0d1.2345e12". */
57 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
59 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
60 changed in read.c . Ideally it shouldn't have to know about it at all,
61 but nothing is ideal around here. */
63 const int md_reloc_size
= 8; /* Size of relocation record */
65 /* Are we trying to generate PIC code? If so, absolute references
66 ought to be made into linkage table references or pc-relative
67 references. Not implemented. For ELF there are other means
68 to denote pic relocations. */
71 static int flag_short_refs
; /* -l option */
72 static int flag_long_jumps
; /* -S option */
74 #ifdef REGISTER_PREFIX_OPTIONAL
75 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
77 int flag_reg_prefix_optional
;
80 /* Whether --register-prefix-optional was used on the command line. */
81 static int reg_prefix_optional_seen
;
83 /* The floating point coprocessor to use by default. */
84 static enum m68k_register m68k_float_copnum
= COP1
;
86 /* If this is non-zero, then references to number(%pc) will be taken
87 to refer to number, rather than to %pc + number. */
88 static int m68k_abspcadd
;
90 /* If this is non-zero, then the quick forms of the move, add, and sub
91 instructions are used when possible. */
92 static int m68k_quick
= 1;
94 /* If this is non-zero, then if the size is not specified for a base
95 or outer displacement, the assembler assumes that the size should
97 static int m68k_rel32
= 1;
99 /* This is non-zero if m68k_rel32 was set from the command line. */
100 static int m68k_rel32_from_cmdline
;
102 /* The default width to use for an index register when using a base
104 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
106 /* We want to warn if any text labels are misaligned. In order to get
107 the right line number, we need to record the line number for each
112 struct label_line
*next
;
119 /* The list of labels. */
121 static struct label_line
*labels
;
123 /* The current label. */
125 static struct label_line
*current_label
;
127 /* Its an arbitrary name: This means I don't approve of it */
128 /* See flames below */
129 static struct obstack robyn
;
131 #define TAB(x,y) (((x)<<2)+(y))
132 #define TABTYPE(xy) ((xy) >> 2)
138 /* Case `g' except when BCC68000 is applicable. */
140 /* Coprocessor branches. */
142 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
143 supported on all cpus. Widens to 32-bit absolute. */
145 /* For inserting an extra jmp instruction with long offset on 68000,
146 for expanding conditional branches. (Not bsr or bra.) Since the
147 68000 doesn't support 32-bit displacements for conditional
148 branches, we fake it by reversing the condition and branching
149 around a jmp with an absolute long operand. */
151 /* For the DBcc "instructions". If the displacement requires 32 bits,
152 the branch-around-a-jump game is played here too. */
154 /* Not currently used? */
156 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
162 const char *m_operands
;
163 unsigned long m_opcode
;
167 struct m68k_incant
*m_next
;
170 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
171 #define gettwo(x) (((x)->m_opcode)&0xffff)
173 static const enum m68k_register m68000_control_regs
[] = { 0 };
174 static const enum m68k_register m68010_control_regs
[] = {
178 static const enum m68k_register m68020_control_regs
[] = {
179 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
182 static const enum m68k_register m68040_control_regs
[] = {
183 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
184 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
187 static const enum m68k_register m68060_control_regs
[] = {
188 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
189 USP
, VBR
, URP
, SRP
, PCR
,
192 static const enum m68k_register mcf5200_control_regs
[] = {
193 CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, VBR
, ROMBAR
,
194 RAMBAR0
, RAMBAR1
, MBAR
,
197 #define cpu32_control_regs m68010_control_regs
199 static const enum m68k_register
*control_regs
;
201 /* internal form of a 68020 instruction */
205 const char *args
; /* list of opcode info */
208 int numo
; /* Number of shorts in opcode */
211 struct m68k_op operands
[6];
213 int nexp
; /* number of exprs in use */
214 struct m68k_exp exprs
[4];
216 int nfrag
; /* Number of frags we have to produce */
219 int fragoff
; /* Where in the current opcode the frag ends */
226 int nrel
; /* Num of reloc strucs in use */
233 /* In a pc relative address the difference between the address
234 of the offset and the address that the offset is relative
235 to. This depends on the addressing mode. Basically this
236 is the value to put in the offset field to address the
237 first byte of the offset, without regarding the special
238 significance of some values (in the branch instruction, for
242 /* Whether this expression needs special pic relocation, and if
244 enum pic_relocation pic_reloc
;
247 reloc
[5]; /* Five is enough??? */
250 #define cpu_of_arch(x) ((x) & (m68000up|mcf5200))
251 #define float_of_arch(x) ((x) & mfloat)
252 #define mmu_of_arch(x) ((x) & mmmu)
254 /* Macros for determining if cpu supports a specific addressing mode */
255 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32))
257 static struct m68k_it the_ins
; /* the instruction being assembled */
259 #define op(ex) ((ex)->exp.X_op)
260 #define adds(ex) ((ex)->exp.X_add_symbol)
261 #define subs(ex) ((ex)->exp.X_op_symbol)
262 #define offs(ex) ((ex)->exp.X_add_number)
264 /* Macros for adding things to the m68k_it struct */
266 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
268 /* Static functions. */
270 static void insop
PARAMS ((int, const struct m68k_incant
*));
271 static void add_fix
PARAMS ((int, struct m68k_exp
*, int, int));
272 static void add_frag
PARAMS ((symbolS
*, offsetT
, int));
274 /* Like addword, but goes BEFORE general operands */
278 const struct m68k_incant
*opcode
;
281 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
282 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
283 for(z
=0;z
<the_ins
.nrel
;z
++)
284 the_ins
.reloc
[z
].n
+=2;
285 for (z
= 0; z
< the_ins
.nfrag
; z
++)
286 the_ins
.fragb
[z
].fragoff
++;
287 the_ins
.opcode
[opcode
->m_codenum
]=w
;
291 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
294 add_fix (width
, exp
, pc_rel
, pc_fix
)
296 struct m68k_exp
*exp
;
300 the_ins
.reloc
[the_ins
.nrel
].n
= ((width
== 'B' || width
== '3')
304 : (the_ins
.numo
*2)));
305 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
306 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
307 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
309 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
311 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
314 /* Cause an extra frag to be generated here, inserting up to 10 bytes
315 (that value is chosen in the frag_var call in md_assemble). TYPE
316 is the subtype of the frag to be generated; its primary type is
317 rs_machine_dependent.
319 The TYPE parameter is also used by md_convert_frag_1 and
320 md_estimate_size_before_relax. The appropriate type of fixup will
321 be emitted by md_convert_frag_1.
323 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
325 add_frag (add
, off
, type
)
330 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
331 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
332 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
333 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
337 (op (ex) != O_constant && op (ex) != O_big)
339 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
340 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
341 static void m68k_ip
PARAMS ((char *));
342 static void insert_reg
PARAMS ((const char *, int));
343 static void select_control_regs
PARAMS ((void));
344 static void init_regtable
PARAMS ((void));
345 static int reverse_16_bits
PARAMS ((int in
));
346 static int reverse_8_bits
PARAMS ((int in
));
347 static void install_gen_operand
PARAMS ((int mode
, int val
));
348 static void install_operand
PARAMS ((int mode
, int val
));
349 static void s_bss
PARAMS ((int));
350 static void s_data1
PARAMS ((int));
351 static void s_data2
PARAMS ((int));
352 static void s_even
PARAMS ((int));
353 static void s_proc
PARAMS ((int));
354 static void mri_chip
PARAMS ((void));
355 static void s_chip
PARAMS ((int));
356 static void s_fopt
PARAMS ((int));
357 static void s_opt
PARAMS ((int));
358 static void s_reg
PARAMS ((int));
359 static void s_restore
PARAMS ((int));
360 static void s_save
PARAMS ((int));
361 static void s_mri_if
PARAMS ((int));
362 static void s_mri_else
PARAMS ((int));
363 static void s_mri_endi
PARAMS ((int));
364 static void s_mri_break
PARAMS ((int));
365 static void s_mri_next
PARAMS ((int));
366 static void s_mri_for
PARAMS ((int));
367 static void s_mri_endf
PARAMS ((int));
368 static void s_mri_repeat
PARAMS ((int));
369 static void s_mri_until
PARAMS ((int));
370 static void s_mri_while
PARAMS ((int));
371 static void s_mri_endw
PARAMS ((int));
372 static void md_apply_fix_2
PARAMS ((fixS
*, offsetT
));
373 static void md_convert_frag_1
PARAMS ((fragS
*));
375 static int current_architecture
;
383 static const struct m68k_cpu archs
[] = {
384 { m68000
, "68000", 0 },
385 { m68010
, "68010", 0 },
386 { m68020
, "68020", 0 },
387 { m68030
, "68030", 0 },
388 { m68040
, "68040", 0 },
389 { m68060
, "68060", 0 },
390 { cpu32
, "cpu32", 0 },
391 { m68881
, "68881", 0 },
392 { m68851
, "68851", 0 },
393 { mcf5200
, "5200", 0 },
394 /* Aliases (effectively, so far as gas is concerned) for the above
396 { m68020
, "68k", 1 },
397 { m68000
, "68008", 1 },
398 { m68000
, "68302", 1 },
399 { m68000
, "68306", 1 },
400 { m68000
, "68307", 1 },
401 { m68000
, "68322", 1 },
402 { m68000
, "68356", 1 },
403 { m68000
, "68ec000", 1 },
404 { m68000
, "68hc000", 1 },
405 { m68000
, "68hc001", 1 },
406 { m68020
, "68ec020", 1 },
407 { m68030
, "68ec030", 1 },
408 { m68040
, "68ec040", 1 },
409 { m68060
, "68ec060", 1 },
410 { cpu32
, "68330", 1 },
411 { cpu32
, "68331", 1 },
412 { cpu32
, "68332", 1 },
413 { cpu32
, "68333", 1 },
414 { cpu32
, "68334", 1 },
415 { cpu32
, "68336", 1 },
416 { cpu32
, "68340", 1 },
417 { cpu32
, "68341", 1 },
418 { cpu32
, "68349", 1 },
419 { cpu32
, "68360", 1 },
420 { m68881
, "68882", 1 },
423 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
425 /* BCC68000 is for patching in an extra jmp instruction for long offsets
426 on the 68000. The 68000 doesn't support long branches with branchs */
428 /* This table desribes how you change sizes for the various types of variable
429 size expressions. This version only supports two kinds. */
431 /* Note that calls to frag_var need to specify the maximum expansion
432 needed; this is currently 10 bytes for DBCC. */
435 How far Forward this mode will reach:
436 How far Backward this mode will reach:
437 How many bytes this mode will add to the size of the frag
438 Which mode to go to if the offset won't fit in this one
440 relax_typeS md_relax_table
[] =
442 {1, 1, 0, 0}, /* First entries aren't used */
443 {1, 1, 0, 0}, /* For no good reason except */
444 {1, 1, 0, 0}, /* that the VAX doesn't either */
447 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
448 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
452 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
453 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
457 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
458 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
462 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
463 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
464 {0, 0, 6, 0}, /* jmp long space */
467 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
468 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
469 {0, 0, 10, 0}, /* bra/jmp long space */
472 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
473 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
477 /* For, e.g., jmp pcrel indexed. */
478 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
479 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
484 /* These are the machine dependent pseudo-ops. These are included so
485 the assembler can work on the output from the SUN C compiler, which
489 /* This table describes all the machine specific pseudo-ops the assembler
490 has to support. The fields are:
491 pseudo-op name without dot
492 function to call to execute this pseudo-op
493 Integer arg to pass to the function
495 const pseudo_typeS md_pseudo_table
[] =
497 {"data1", s_data1
, 0},
498 {"data2", s_data2
, 0},
501 {"skip", s_space
, 0},
503 #if defined (TE_SUN3) || defined (OBJ_ELF)
504 {"align", s_align_bytes
, 0},
507 {"swbeg", s_ignore
, 0},
509 {"extend", float_cons
, 'x'},
510 {"ldouble", float_cons
, 'x'},
512 /* The following pseudo-ops are supported for MRI compatibility. */
514 {"comline", s_space
, 1},
516 {"mask2", s_ignore
, 0},
519 {"restore", s_restore
, 0},
523 {"if.b", s_mri_if
, 'b'},
524 {"if.w", s_mri_if
, 'w'},
525 {"if.l", s_mri_if
, 'l'},
526 {"else", s_mri_else
, 0},
527 {"else.s", s_mri_else
, 's'},
528 {"else.l", s_mri_else
, 'l'},
529 {"endi", s_mri_endi
, 0},
530 {"break", s_mri_break
, 0},
531 {"break.s", s_mri_break
, 's'},
532 {"break.l", s_mri_break
, 'l'},
533 {"next", s_mri_next
, 0},
534 {"next.s", s_mri_next
, 's'},
535 {"next.l", s_mri_next
, 'l'},
536 {"for", s_mri_for
, 0},
537 {"for.b", s_mri_for
, 'b'},
538 {"for.w", s_mri_for
, 'w'},
539 {"for.l", s_mri_for
, 'l'},
540 {"endf", s_mri_endf
, 0},
541 {"repeat", s_mri_repeat
, 0},
542 {"until", s_mri_until
, 0},
543 {"until.b", s_mri_until
, 'b'},
544 {"until.w", s_mri_until
, 'w'},
545 {"until.l", s_mri_until
, 'l'},
546 {"while", s_mri_while
, 0},
547 {"while.b", s_mri_while
, 'b'},
548 {"while.w", s_mri_while
, 'w'},
549 {"while.l", s_mri_while
, 'l'},
550 {"endw", s_mri_endw
, 0},
556 /* The mote pseudo ops are put into the opcode table, since they
557 don't start with a . they look like opcodes to gas.
561 extern void obj_coff_section
PARAMS ((int));
564 CONST pseudo_typeS mote_pseudo_table
[] =
577 {"xdef", s_globl
, 0},
579 {"align", s_align_bytes
, 0},
581 {"align", s_align_ptwo
, 0},
584 {"sect", obj_coff_section
, 0},
585 {"section", obj_coff_section
, 0},
590 #define issbyte(x) ((x)>=-128 && (x)<=127)
591 #define isubyte(x) ((x)>=0 && (x)<=255)
592 #define issword(x) ((x)>=-32768 && (x)<=32767)
593 #define isuword(x) ((x)>=0 && (x)<=65535)
595 #define isbyte(x) ((x)>= -255 && (x)<=255)
596 #define isword(x) ((x)>=-65536 && (x)<=65535)
597 #define islong(x) (1)
599 extern char *input_line_pointer
;
601 static char mklower_table
[256];
602 #define mklower(c) (mklower_table[(unsigned char)(c)])
603 static char notend_table
[256];
604 static char alt_notend_table
[256];
606 (! (notend_table[(unsigned char) *s] \
608 && alt_notend_table[(unsigned char) s[1]])))
610 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
612 #ifdef NO_PCREL_RELOCS
615 make_pcrel_absolute(fixP
, add_number
)
619 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
621 /* rewrite the PC relative instructions to absolute address ones.
622 * these are rumoured to be faster, and the apollo linker refuses
623 * to deal with the PC relative relocations.
625 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
630 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
636 as_fatal (_("Unknown PC relative instruction"));
641 #endif /* NO_PCREL_RELOCS */
644 tc_coff_fix2rtype (fixP
)
647 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
648 return R_RELLONG_NEG
;
649 #ifdef NO_PCREL_RELOCS
650 know (fixP
->fx_pcrel
== 0);
651 return (fixP
->fx_size
== 1 ? R_RELBYTE
652 : fixP
->fx_size
== 2 ? R_DIR16
655 return (fixP
->fx_pcrel
?
656 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
657 fixP
->fx_size
== 2 ? R_PCRWORD
:
659 (fixP
->fx_size
== 1 ? R_RELBYTE
:
660 fixP
->fx_size
== 2 ? R_RELWORD
:
669 /* Compute the relocation code for a fixup of SIZE bytes, using pc
670 relative relocation if PCREL is non-zero. PIC says whether a special
671 pic relocation was requested. */
673 static bfd_reloc_code_real_type get_reloc_code
674 PARAMS ((int, int, enum pic_relocation
));
676 static bfd_reloc_code_real_type
677 get_reloc_code (size
, pcrel
, pic
)
680 enum pic_relocation pic
;
688 return BFD_RELOC_8_GOT_PCREL
;
690 return BFD_RELOC_16_GOT_PCREL
;
692 return BFD_RELOC_32_GOT_PCREL
;
700 return BFD_RELOC_8_GOTOFF
;
702 return BFD_RELOC_16_GOTOFF
;
704 return BFD_RELOC_32_GOTOFF
;
712 return BFD_RELOC_8_PLT_PCREL
;
714 return BFD_RELOC_16_PLT_PCREL
;
716 return BFD_RELOC_32_PLT_PCREL
;
724 return BFD_RELOC_8_PLTOFF
;
726 return BFD_RELOC_16_PLTOFF
;
728 return BFD_RELOC_32_PLTOFF
;
738 return BFD_RELOC_8_PCREL
;
740 return BFD_RELOC_16_PCREL
;
742 return BFD_RELOC_32_PCREL
;
762 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
764 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
769 as_bad (_("Can not do %d byte relocation"), size
);
771 as_bad (_("Can not do %d byte pic relocation"), size
);
774 return BFD_RELOC_NONE
;
777 /* Here we decide which fixups can be adjusted to make them relative
778 to the beginning of the section instead of the symbol. Basically
779 we need to make sure that the dynamic relocations are done
780 correctly, so in some cases we force the original symbol to be
783 tc_m68k_fix_adjustable (fixP
)
786 /* Prevent all adjustments to global symbols. */
787 if (S_IS_EXTERNAL (fixP
->fx_addsy
)
788 || S_IS_WEAK (fixP
->fx_addsy
))
791 /* adjust_reloc_syms doesn't know about the GOT */
792 switch (fixP
->fx_r_type
)
794 case BFD_RELOC_8_GOT_PCREL
:
795 case BFD_RELOC_16_GOT_PCREL
:
796 case BFD_RELOC_32_GOT_PCREL
:
797 case BFD_RELOC_8_GOTOFF
:
798 case BFD_RELOC_16_GOTOFF
:
799 case BFD_RELOC_32_GOTOFF
:
800 case BFD_RELOC_8_PLT_PCREL
:
801 case BFD_RELOC_16_PLT_PCREL
:
802 case BFD_RELOC_32_PLT_PCREL
:
803 case BFD_RELOC_8_PLTOFF
:
804 case BFD_RELOC_16_PLTOFF
:
805 case BFD_RELOC_32_PLTOFF
:
815 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
822 tc_gen_reloc (section
, fixp
)
827 bfd_reloc_code_real_type code
;
832 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
834 code
= fixp
->fx_r_type
;
836 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
837 that fixup_segment converted a non-PC relative reloc into a
838 PC relative reloc. In such a case, we need to convert the
845 code
= BFD_RELOC_8_PCREL
;
848 code
= BFD_RELOC_16_PCREL
;
851 code
= BFD_RELOC_32_PCREL
;
853 case BFD_RELOC_8_PCREL
:
854 case BFD_RELOC_16_PCREL
:
855 case BFD_RELOC_32_PCREL
:
856 case BFD_RELOC_8_GOT_PCREL
:
857 case BFD_RELOC_16_GOT_PCREL
:
858 case BFD_RELOC_32_GOT_PCREL
:
859 case BFD_RELOC_8_GOTOFF
:
860 case BFD_RELOC_16_GOTOFF
:
861 case BFD_RELOC_32_GOTOFF
:
862 case BFD_RELOC_8_PLT_PCREL
:
863 case BFD_RELOC_16_PLT_PCREL
:
864 case BFD_RELOC_32_PLT_PCREL
:
865 case BFD_RELOC_8_PLTOFF
:
866 case BFD_RELOC_16_PLTOFF
:
867 case BFD_RELOC_32_PLTOFF
:
870 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
871 _("Cannot make %s relocation PC relative"),
872 bfd_get_reloc_code_name (code
));
878 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
879 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
881 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
882 MAP (1, 0, BFD_RELOC_8
);
883 MAP (2, 0, BFD_RELOC_16
);
884 MAP (4, 0, BFD_RELOC_32
);
885 MAP (1, 1, BFD_RELOC_8_PCREL
);
886 MAP (2, 1, BFD_RELOC_16_PCREL
);
887 MAP (4, 1, BFD_RELOC_32_PCREL
);
895 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
896 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
897 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
900 reloc
->addend
= fixp
->fx_addnumber
;
905 reloc
->addend
= fixp
->fx_addnumber
;
907 reloc
->addend
= (section
->vma
908 + (fixp
->fx_pcrel_adjust
== 64
909 ? -1 : fixp
->fx_pcrel_adjust
)
911 + md_pcrel_from (fixp
));
914 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
915 assert (reloc
->howto
!= 0);
920 #endif /* BFD_ASSEMBLER */
922 /* Return zero if the reference to SYMBOL from within the same segment may
926 #define relaxable_symbol(symbol) \
927 (! S_IS_EXTERNAL (symbol) && ! S_IS_WEAK (symbol))
931 #define relaxable_symbol(symbol) 1
935 /* Handle of the OPCODE hash table. NULL means any use before
936 m68k_ip_begin() will crash. */
937 static struct hash_control
*op_hash
;
939 /* Assemble an m68k instruction. */
946 register struct m68k_op
*opP
;
947 register const struct m68k_incant
*opcode
;
948 register const char *s
;
949 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
950 char *pdot
, *pdotmove
;
951 enum m68k_size siz1
, siz2
;
955 LITTLENUM_TYPE words
[6];
956 LITTLENUM_TYPE
*wordp
;
957 unsigned long ok_arch
= 0;
959 if (*instring
== ' ')
960 instring
++; /* skip leading whitespace */
962 /* Scan up to end of operation-code, which MUST end in end-of-string
963 or exactly 1 space. */
965 for (p
= instring
; *p
!= '\0'; p
++)
975 the_ins
.error
= _("No operator");
979 /* p now points to the end of the opcode name, probably whitespace.
980 Make sure the name is null terminated by clobbering the
981 whitespace, look it up in the hash table, then fix it back.
982 Remove a dot, first, since the opcode tables have none. */
985 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
986 *pdotmove
= pdotmove
[1];
992 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
997 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
998 *pdotmove
= pdotmove
[-1];
1005 the_ins
.error
= _("Unknown operator");
1009 /* found a legitimate opcode, start matching operands */
1013 if (opcode
->m_operands
== 0)
1015 char *old
= input_line_pointer
;
1017 input_line_pointer
= p
;
1018 /* Ahh - it's a motorola style psuedo op */
1019 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1020 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1021 input_line_pointer
= old
;
1027 if (flag_mri
&& opcode
->m_opnum
== 0)
1029 /* In MRI mode, random garbage is allowed after an instruction
1030 which accepts no operands. */
1031 the_ins
.args
= opcode
->m_operands
;
1032 the_ins
.numargs
= opcode
->m_opnum
;
1033 the_ins
.numo
= opcode
->m_codenum
;
1034 the_ins
.opcode
[0] = getone (opcode
);
1035 the_ins
.opcode
[1] = gettwo (opcode
);
1039 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1041 p
= crack_operand (p
, opP
);
1045 the_ins
.error
= opP
->error
;
1050 opsfound
= opP
- &the_ins
.operands
[0];
1052 /* This ugly hack is to support the floating pt opcodes in their
1053 standard form. Essentially, we fake a first enty of type COP#1 */
1054 if (opcode
->m_operands
[0] == 'I')
1058 for (n
= opsfound
; n
> 0; --n
)
1059 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1061 memset ((char *) (&the_ins
.operands
[0]), '\0',
1062 sizeof (the_ins
.operands
[0]));
1063 the_ins
.operands
[0].mode
= CONTROL
;
1064 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1068 /* We've got the operands. Find an opcode that'll accept them */
1071 /* If we didn't get the right number of ops, or we have no
1072 common model with this pattern then reject this pattern. */
1074 ok_arch
|= opcode
->m_arch
;
1075 if (opsfound
!= opcode
->m_opnum
1076 || ((opcode
->m_arch
& current_architecture
) == 0))
1080 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
1084 /* Warning: this switch is huge! */
1085 /* I've tried to organize the cases into this order:
1086 non-alpha first, then alpha by letter. Lower-case
1087 goes directly before uppercase counterpart. */
1088 /* Code with multiple case ...: gets sorted by the lowest
1089 case ... it belongs to. I hope this makes sense. */
1195 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1212 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1231 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1241 if (opP
->mode
!= IMMED
)
1243 else if (s
[1] == 'b'
1244 && ! isvar (&opP
->disp
)
1245 && (opP
->disp
.exp
.X_op
!= O_constant
1246 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1248 else if (s
[1] == 'B'
1249 && ! isvar (&opP
->disp
)
1250 && (opP
->disp
.exp
.X_op
!= O_constant
1251 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1253 else if (s
[1] == 'w'
1254 && ! isvar (&opP
->disp
)
1255 && (opP
->disp
.exp
.X_op
!= O_constant
1256 || ! isword (opP
->disp
.exp
.X_add_number
)))
1258 else if (s
[1] == 'W'
1259 && ! isvar (&opP
->disp
)
1260 && (opP
->disp
.exp
.X_op
!= O_constant
1261 || ! issword (opP
->disp
.exp
.X_add_number
)))
1267 if (opP
->mode
!= IMMED
)
1272 if (opP
->mode
== AREG
1273 || opP
->mode
== CONTROL
1274 || opP
->mode
== FPREG
1275 || opP
->mode
== IMMED
1276 || opP
->mode
== REGLST
1277 || (opP
->mode
!= ABSL
1279 || opP
->reg
== ZPC
)))
1284 if (opP
->mode
== CONTROL
1285 || opP
->mode
== FPREG
1286 || opP
->mode
== REGLST
1287 || opP
->mode
== IMMED
1288 || (opP
->mode
!= ABSL
1290 || opP
->reg
== ZPC
)))
1318 if (opP
->mode
== CONTROL
1319 || opP
->mode
== FPREG
1320 || opP
->mode
== REGLST
)
1325 if (opP
->mode
!= AINC
)
1330 if (opP
->mode
!= ADEC
)
1380 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1401 case '~': /* For now! (JF FOO is this right?) */
1423 if (opP
->mode
!= CONTROL
1424 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1429 if (opP
->mode
!= AREG
)
1434 if (opP
->mode
!= AINDR
)
1439 if (opP
->mode
!= ABSL
1441 && strncmp (instring
, "jbsr", 4) == 0))
1446 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1451 if (opP
->mode
!= DISP
1453 || opP
->reg
> ADDR7
)
1458 if (opP
->mode
!= DREG
)
1463 if (opP
->mode
!= FPREG
)
1468 if (opP
->mode
!= CONTROL
1475 if (opP
->mode
!= CONTROL
1477 || opP
->reg
> last_movec_reg
)
1481 const enum m68k_register
*rp
;
1482 for (rp
= control_regs
; *rp
; rp
++)
1483 if (*rp
== opP
->reg
)
1491 if (opP
->mode
!= IMMED
)
1497 if (opP
->mode
== DREG
1498 || opP
->mode
== AREG
1499 || opP
->mode
== FPREG
)
1508 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1511 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1514 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1522 else if (opP
->mode
== CONTROL
)
1531 opP
->mask
= 1 << 24;
1534 opP
->mask
= 1 << 25;
1537 opP
->mask
= 1 << 26;
1546 else if (opP
->mode
!= REGLST
)
1548 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1550 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1555 if (opP
->mode
!= IMMED
)
1557 else if (opP
->disp
.exp
.X_op
!= O_constant
1558 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1560 else if (! m68k_quick
1561 && instring
[3] != 'q'
1562 && instring
[4] != 'q')
1567 if (opP
->mode
!= DREG
1568 && opP
->mode
!= IMMED
1569 && opP
->mode
!= ABSL
)
1574 if (opP
->mode
!= IMMED
)
1576 else if (opP
->disp
.exp
.X_op
!= O_constant
1577 || opP
->disp
.exp
.X_add_number
< 1
1578 || opP
->disp
.exp
.X_add_number
> 8)
1580 else if (! m68k_quick
1581 && (strncmp (instring
, "add", 3) == 0
1582 || strncmp (instring
, "sub", 3) == 0)
1583 && instring
[3] != 'q')
1588 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1593 if (opP
->mode
!= AINDR
1594 && (opP
->mode
!= BASE
1596 && opP
->reg
!= ZADDR0
)
1597 || opP
->disp
.exp
.X_op
!= O_absent
1598 || ((opP
->index
.reg
< DATA0
1599 || opP
->index
.reg
> DATA7
)
1600 && (opP
->index
.reg
< ADDR0
1601 || opP
->index
.reg
> ADDR7
))
1602 || opP
->index
.size
!= SIZE_UNSPEC
1603 || opP
->index
.scale
!= 1))
1608 if (opP
->mode
!= CONTROL
1609 || ! (opP
->reg
== FPI
1611 || opP
->reg
== FPC
))
1616 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1621 if (opP
->mode
!= IMMED
)
1623 else if (opP
->disp
.exp
.X_op
!= O_constant
1624 || opP
->disp
.exp
.X_add_number
< 0
1625 || opP
->disp
.exp
.X_add_number
> 7)
1630 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1634 /* JF these are out of order. We could put them
1635 in order if we were willing to put up with
1636 bunches of #ifdef m68851s in the code.
1638 Don't forget that you need these operands
1639 to use 68030 MMU instructions. */
1641 /* Memory addressing mode used by pflushr */
1643 if (opP
->mode
== CONTROL
1644 || opP
->mode
== FPREG
1645 || opP
->mode
== DREG
1646 || opP
->mode
== AREG
1647 || opP
->mode
== REGLST
)
1649 /* We should accept immediate operands, but they
1650 supposedly have to be quad word, and we don't
1651 handle that. I would like to see what a Motorola
1652 assembler does before doing something here. */
1653 if (opP
->mode
== IMMED
)
1658 if (opP
->mode
!= CONTROL
1659 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1664 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1669 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1674 if (opP
->mode
!= CONTROL
1677 && opP
->reg
!= SCC
))
1682 if (opP
->mode
!= CONTROL
1688 if (opP
->mode
!= CONTROL
1691 && opP
->reg
!= CRP
))
1696 if (opP
->mode
!= CONTROL
1697 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1698 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1703 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1708 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1713 if (opP
->mode
!= CONTROL
1720 } /* not a cache specifier. */
1724 if (opP
->mode
!= ABSL
)
1730 } /* switch on type of operand */
1734 } /* for each operand */
1735 } /* if immediately wrong */
1742 opcode
= opcode
->m_next
;
1747 && !(ok_arch
& current_architecture
))
1752 _("invalid instruction for this architecture; needs "));
1753 cp
= buf
+ strlen (buf
);
1757 strcpy (cp
, _("fpu (68040, 68060 or 68881/68882)"));
1760 strcpy (cp
, _("mmu (68030 or 68851)"));
1763 strcpy (cp
, _("68020 or higher"));
1766 strcpy (cp
, _("68000 or higher"));
1769 strcpy (cp
, _("68010 or higher"));
1773 int got_one
= 0, idx
;
1774 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1777 if ((archs
[idx
].arch
& ok_arch
)
1778 && ! archs
[idx
].alias
)
1782 strcpy (cp
, " or ");
1786 strcpy (cp
, archs
[idx
].name
);
1792 cp
= xmalloc (strlen (buf
) + 1);
1797 the_ins
.error
= _("operands mismatch");
1799 } /* Fell off the end */
1804 /* now assemble it */
1806 the_ins
.args
= opcode
->m_operands
;
1807 the_ins
.numargs
= opcode
->m_opnum
;
1808 the_ins
.numo
= opcode
->m_codenum
;
1809 the_ins
.opcode
[0] = getone (opcode
);
1810 the_ins
.opcode
[1] = gettwo (opcode
);
1812 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1814 /* This switch is a doozy.
1815 Watch the first step; its a big one! */
1843 tmpreg
= 0x3c; /* 7.4 */
1844 if (strchr ("bwl", s
[1]))
1845 nextword
= get_num (&opP
->disp
, 80);
1847 nextword
= get_num (&opP
->disp
, 0);
1848 if (isvar (&opP
->disp
))
1849 add_fix (s
[1], &opP
->disp
, 0, 0);
1853 if (!isbyte (nextword
))
1854 opP
->error
= _("operand out of range");
1859 if (!isword (nextword
))
1860 opP
->error
= _("operand out of range");
1865 if (!issword (nextword
))
1866 opP
->error
= _("operand out of range");
1871 addword (nextword
>> 16);
1898 /* We gotta put out some float */
1899 if (op (&opP
->disp
) != O_big
)
1904 /* Can other cases happen here? */
1905 if (op (&opP
->disp
) != O_constant
)
1908 val
= (valueT
) offs (&opP
->disp
);
1912 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1913 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1917 offs (&opP
->disp
) = gencnt
;
1919 if (offs (&opP
->disp
) > 0)
1921 if (offs (&opP
->disp
) > baseo
)
1923 as_warn (_("Bignum too big for %c format; truncated"),
1925 offs (&opP
->disp
) = baseo
;
1927 baseo
-= offs (&opP
->disp
);
1930 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1931 offs (&opP
->disp
)--;
1936 gen_to_words (words
, baseo
, (long) outro
);
1937 for (wordp
= words
; baseo
--; wordp
++)
1941 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1944 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1947 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1950 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1953 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1957 nextword
= get_num (&opP
->disp
, 80);
1960 && ! isvar (&opP
->disp
)
1963 opP
->disp
.exp
.X_op
= O_symbol
;
1964 #ifndef BFD_ASSEMBLER
1965 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1967 opP
->disp
.exp
.X_add_symbol
=
1968 section_symbol (absolute_section
);
1972 /* Force into index mode. Hope this works */
1974 /* We do the first bit for 32-bit displacements, and the
1975 second bit for 16 bit ones. It is possible that we
1976 should make the default be WORD instead of LONG, but
1977 I think that'd break GCC, so we put up with a little
1978 inefficiency for the sake of working output. */
1980 if (!issword (nextword
)
1981 || (isvar (&opP
->disp
)
1982 && ((opP
->disp
.size
== SIZE_UNSPEC
1983 && flag_short_refs
== 0
1984 && cpu_of_arch (current_architecture
) >= m68020
1985 && cpu_of_arch (current_architecture
) != mcf5200
)
1986 || opP
->disp
.size
== SIZE_LONG
)))
1988 if (cpu_of_arch (current_architecture
) < m68020
1989 || cpu_of_arch (current_architecture
) == mcf5200
)
1991 _("displacement too large for this architecture; needs 68020 or higher");
1993 tmpreg
= 0x3B; /* 7.3 */
1995 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1996 if (isvar (&opP
->disp
))
2000 if (opP
->disp
.size
== SIZE_LONG
2002 /* If the displacement needs pic
2003 relocation it cannot be relaxed. */
2004 || opP
->disp
.pic_reloc
!= pic_none
2009 add_fix ('l', &opP
->disp
, 1, 2);
2013 add_frag (adds (&opP
->disp
),
2015 TAB (PCLEA
, SZ_UNDEF
));
2022 add_fix ('l', &opP
->disp
, 0, 0);
2027 addword (nextword
>> 16);
2032 tmpreg
= 0x3A; /* 7.2 */
2034 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2036 if (isvar (&opP
->disp
))
2040 add_fix ('w', &opP
->disp
, 1, 0);
2043 add_fix ('w', &opP
->disp
, 0, 0);
2053 baseo
= get_num (&opP
->disp
, 80);
2054 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2055 outro
= get_num (&opP
->odisp
, 80);
2056 /* Figure out the `addressing mode'.
2057 Also turn on the BASE_DISABLE bit, if needed. */
2058 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2060 tmpreg
= 0x3b; /* 7.3 */
2061 if (opP
->reg
== ZPC
)
2064 else if (opP
->reg
== 0)
2067 tmpreg
= 0x30; /* 6.garbage */
2069 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2072 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2075 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2077 siz1
= opP
->disp
.size
;
2078 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2079 siz2
= opP
->odisp
.size
;
2083 /* Index register stuff */
2084 if (opP
->index
.reg
!= 0
2085 && opP
->index
.reg
>= DATA
2086 && opP
->index
.reg
<= ADDR7
)
2088 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2090 if (opP
->index
.size
== SIZE_LONG
2091 || (opP
->index
.size
== SIZE_UNSPEC
2092 && m68k_index_width_default
== SIZE_LONG
))
2095 if ((opP
->index
.scale
!= 1
2096 && cpu_of_arch (current_architecture
) < m68020
)
2097 || (opP
->index
.scale
== 8
2098 && current_architecture
== mcf5200
))
2101 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2104 switch (opP
->index
.scale
)
2121 GET US OUT OF HERE! */
2123 /* Must be INDEX, with an index register. Address
2124 register cannot be ZERO-PC, and either :b was
2125 forced, or we know it will fit. For a 68000 or
2126 68010, force this mode anyways, because the
2127 larger modes aren't supported. */
2128 if (opP
->mode
== BASE
2129 && ((opP
->reg
>= ADDR0
2130 && opP
->reg
<= ADDR7
)
2133 if (siz1
== SIZE_BYTE
2134 || cpu_of_arch (current_architecture
) < m68020
2135 || cpu_of_arch (current_architecture
) == mcf5200
2136 || (siz1
== SIZE_UNSPEC
2137 && ! isvar (&opP
->disp
)
2138 && issbyte (baseo
)))
2140 nextword
+= baseo
& 0xff;
2142 if (isvar (&opP
->disp
))
2144 /* Do a byte relocation. If it doesn't
2145 fit (possible on m68000) let the
2146 fixup processing complain later. */
2148 add_fix ('B', &opP
->disp
, 1, 1);
2150 add_fix ('B', &opP
->disp
, 0, 0);
2152 else if (siz1
!= SIZE_BYTE
)
2154 if (siz1
!= SIZE_UNSPEC
)
2155 as_warn (_("Forcing byte displacement"));
2156 if (! issbyte (baseo
))
2157 opP
->error
= _("byte displacement out of range");
2162 else if (siz1
== SIZE_UNSPEC
2164 && isvar (&opP
->disp
)
2165 && subs (&opP
->disp
) == NULL
2167 /* If the displacement needs pic
2168 relocation it cannot be relaxed. */
2169 && opP
->disp
.pic_reloc
== pic_none
2173 /* The code in md_convert_frag_1 needs to be
2174 able to adjust nextword. Call frag_grow
2175 to ensure that we have enough space in
2176 the frag obstack to make all the bytes
2179 nextword
+= baseo
& 0xff;
2181 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2182 TAB (PCINDEX
, SZ_UNDEF
));
2190 nextword
|= 0x40; /* No index reg */
2191 if (opP
->index
.reg
>= ZDATA0
2192 && opP
->index
.reg
<= ZDATA7
)
2193 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2194 else if (opP
->index
.reg
>= ZADDR0
2195 || opP
->index
.reg
<= ZADDR7
)
2196 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2199 /* It isn't simple. */
2201 if (cpu_of_arch (current_architecture
) < m68020
2202 || cpu_of_arch (current_architecture
) == mcf5200
)
2204 _("invalid operand mode for this architecture; needs 68020 or higher");
2207 /* If the guy specified a width, we assume that it is
2208 wide enough. Maybe it isn't. If so, we lose. */
2212 if (isvar (&opP
->disp
)
2214 : ! issword (baseo
))
2219 else if (! isvar (&opP
->disp
) && baseo
== 0)
2228 as_warn (_(":b not permitted; defaulting to :w"));
2238 /* Figure out innner displacement stuff */
2239 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2241 if (cpu_of_arch (current_architecture
) & cpu32
)
2242 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2246 if (isvar (&opP
->odisp
)
2248 : ! issword (outro
))
2253 else if (! isvar (&opP
->odisp
) && outro
== 0)
2262 as_warn (_(":b not permitted; defaulting to :w"));
2271 if (opP
->mode
== POST
2272 && (nextword
& 0x40) == 0)
2277 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2279 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2280 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2282 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2284 if (siz1
== SIZE_LONG
)
2285 addword (baseo
>> 16);
2286 if (siz1
!= SIZE_UNSPEC
)
2289 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2290 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2291 if (siz2
== SIZE_LONG
)
2292 addword (outro
>> 16);
2293 if (siz2
!= SIZE_UNSPEC
)
2299 nextword
= get_num (&opP
->disp
, 80);
2300 switch (opP
->disp
.size
)
2305 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2307 tmpreg
= 0x38; /* 7.0 */
2311 /* Don't generate pc relative code on 68010 and
2313 if (isvar (&opP
->disp
)
2314 && !subs (&opP
->disp
)
2315 && adds (&opP
->disp
)
2317 /* If the displacement needs pic relocation it
2318 cannot be relaxed. */
2319 && opP
->disp
.pic_reloc
== pic_none
2321 && S_GET_SEGMENT (adds (&opP
->disp
)) == now_seg
2322 && relaxable_symbol (adds (&opP
->disp
))
2323 && HAVE_LONG_BRANCH(current_architecture
)
2325 && !strchr ("~%&$?", s
[0]))
2327 tmpreg
= 0x3A; /* 7.2 */
2328 add_frag (adds (&opP
->disp
),
2330 TAB (PCREL
, SZ_UNDEF
));
2333 /* Fall through into long */
2335 if (isvar (&opP
->disp
))
2336 add_fix ('l', &opP
->disp
, 0, 0);
2338 tmpreg
= 0x39;/* 7.1 mode */
2339 addword (nextword
>> 16);
2344 as_bad (_("unsupported byte value; use a different suffix"));
2346 case SIZE_WORD
: /* Word */
2347 if (isvar (&opP
->disp
))
2348 add_fix ('w', &opP
->disp
, 0, 0);
2350 tmpreg
= 0x38;/* 7.0 mode */
2358 as_bad (_("unknown/incorrect operand"));
2361 install_gen_operand (s
[1], tmpreg
);
2367 { /* JF: I hate floating point! */
2382 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2383 if (isvar (&opP
->disp
))
2384 add_fix (s
[1], &opP
->disp
, 0, 0);
2387 case 'b': /* Danger: These do no check for
2388 certain types of overflow.
2390 if (!isbyte (tmpreg
))
2391 opP
->error
= _("out of range");
2392 insop (tmpreg
, opcode
);
2393 if (isvar (&opP
->disp
))
2394 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2395 (opcode
->m_codenum
) * 2 + 1;
2398 if (!issbyte (tmpreg
))
2399 opP
->error
= _("out of range");
2400 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
2401 if (isvar (&opP
->disp
))
2402 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2405 if (!isword (tmpreg
))
2406 opP
->error
= _("out of range");
2407 insop (tmpreg
, opcode
);
2408 if (isvar (&opP
->disp
))
2409 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2412 if (!issword (tmpreg
))
2413 opP
->error
= _("out of range");
2414 insop (tmpreg
, opcode
);
2415 if (isvar (&opP
->disp
))
2416 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2419 /* Because of the way insop works, we put these two out
2421 insop (tmpreg
, opcode
);
2422 insop (tmpreg
>> 16, opcode
);
2423 if (isvar (&opP
->disp
))
2424 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2431 install_operand (s
[1], tmpreg
);
2442 install_operand (s
[1], opP
->reg
- ADDR
);
2446 tmpreg
= get_num (&opP
->disp
, 80);
2450 /* The pc_fix argument winds up in fx_pcrel_adjust,
2451 which is a char, and may therefore be unsigned. We
2452 want to pass -1, but we pass 64 instead, and convert
2453 back in md_pcrel_from. */
2454 add_fix ('B', &opP
->disp
, 1, 64);
2457 add_fix ('w', &opP
->disp
, 1, 0);
2462 if (!HAVE_LONG_BRANCH(current_architecture
))
2463 as_warn (_("Can't use long branches on 68000/68010/5200"));
2464 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2465 add_fix ('l', &opP
->disp
, 1, 0);
2470 if (subs (&opP
->disp
)) /* We can't relax it */
2474 /* If the displacement needs pic relocation it cannot be
2476 if (opP
->disp
.pic_reloc
!= pic_none
)
2480 /* This could either be a symbol, or an absolute
2481 address. No matter, the frag hacking will finger it
2482 out. Not quite: it can't switch from BRANCH to
2483 BCC68000 for the case where opnd is absolute (it
2484 needs to use the 68000 hack since no conditional abs
2486 if (( !HAVE_LONG_BRANCH(current_architecture
)
2487 || (0 == adds (&opP
->disp
)))
2488 && (the_ins
.opcode
[0] >= 0x6200)
2489 && (the_ins
.opcode
[0] <= 0x6f00))
2490 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2491 TAB (BCC68000
, SZ_UNDEF
));
2493 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2494 TAB (ABRANCH
, SZ_UNDEF
));
2497 if (isvar (&opP
->disp
))
2500 /* check for DBcc instruction */
2501 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2503 /* size varies if patch */
2504 /* needed for long form */
2505 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2506 TAB (DBCC
, SZ_UNDEF
));
2510 add_fix ('w', &opP
->disp
, 1, 0);
2514 case 'C': /* Fixed size LONG coproc branches */
2515 add_fix ('l', &opP
->disp
, 1, 0);
2519 case 'c': /* Var size Coprocesssor branches */
2520 if (subs (&opP
->disp
))
2522 add_fix ('l', &opP
->disp
, 1, 0);
2523 add_frag ((symbolS
*) 0, (offsetT
) 0, TAB (FBRANCH
, LONG
));
2525 else if (adds (&opP
->disp
))
2526 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2527 TAB (FBRANCH
, SZ_UNDEF
));
2530 /* add_frag ((symbolS *) 0, offs (&opP->disp),
2531 TAB(FBRANCH,SHORT)); */
2532 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2533 add_fix ('l', &opP
->disp
, 1, 0);
2543 case 'C': /* Ignore it */
2546 case 'd': /* JF this is a kludge */
2547 install_operand ('s', opP
->reg
- ADDR
);
2548 tmpreg
= get_num (&opP
->disp
, 80);
2549 if (!issword (tmpreg
))
2551 as_warn (_("Expression out of range, using 0"));
2558 install_operand (s
[1], opP
->reg
- DATA
);
2562 install_operand (s
[1], opP
->reg
- FP0
);
2566 tmpreg
= opP
->reg
- COP0
;
2567 install_operand (s
[1], tmpreg
);
2570 case 'J': /* JF foo */
2643 install_operand (s
[1], tmpreg
);
2647 tmpreg
= get_num (&opP
->disp
, 55);
2648 install_operand (s
[1], tmpreg
& 0x7f);
2655 if (tmpreg
& 0x7FF0000)
2656 as_bad (_("Floating point register in register list"));
2657 insop (reverse_16_bits (tmpreg
), opcode
);
2661 if (tmpreg
& 0x700FFFF)
2662 as_bad (_("Wrong register in floating-point reglist"));
2663 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2671 if (tmpreg
& 0x7FF0000)
2672 as_bad (_("Floating point register in register list"));
2673 insop (tmpreg
, opcode
);
2675 else if (s
[1] == '8')
2677 if (tmpreg
& 0x0FFFFFF)
2678 as_bad (_("incorrect register in reglist"));
2679 install_operand (s
[1], tmpreg
>> 24);
2683 if (tmpreg
& 0x700FFFF)
2684 as_bad (_("wrong register in floating-point reglist"));
2686 install_operand (s
[1], tmpreg
>> 16);
2691 install_operand (s
[1], get_num (&opP
->disp
, 60));
2695 tmpreg
= ((opP
->mode
== DREG
)
2696 ? 0x20 + opP
->reg
- DATA
2697 : (get_num (&opP
->disp
, 40) & 0x1F));
2698 install_operand (s
[1], tmpreg
);
2702 tmpreg
= get_num (&opP
->disp
, 10);
2705 install_operand (s
[1], tmpreg
);
2709 /* This depends on the fact that ADDR registers are eight
2710 more than their corresponding DATA regs, so the result
2711 will have the ADDR_REG bit set */
2712 install_operand (s
[1], opP
->reg
- DATA
);
2716 if (opP
->mode
== AINDR
)
2717 install_operand (s
[1], opP
->reg
- DATA
);
2719 install_operand (s
[1], opP
->index
.reg
- DATA
);
2723 if (opP
->reg
== FPI
)
2725 else if (opP
->reg
== FPS
)
2727 else if (opP
->reg
== FPC
)
2731 install_operand (s
[1], tmpreg
);
2734 case 'S': /* Ignore it */
2738 install_operand (s
[1], get_num (&opP
->disp
, 30));
2741 case 'U': /* Ignore it */
2760 as_fatal (_("failed sanity check"));
2761 } /* switch on cache token */
2762 install_operand (s
[1], tmpreg
);
2765 /* JF: These are out of order, I fear. */
2778 install_operand (s
[1], tmpreg
);
2804 install_operand (s
[1], tmpreg
);
2808 if (opP
->reg
== VAL
)
2827 install_operand (s
[1], tmpreg
);
2841 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2852 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2858 install_operand (s
[1], tmpreg
);
2861 know (opP
->reg
== PSR
);
2864 know (opP
->reg
== PCSR
);
2879 install_operand (s
[1], tmpreg
);
2882 tmpreg
= get_num (&opP
->disp
, 20);
2883 install_operand (s
[1], tmpreg
);
2885 case '_': /* used only for move16 absolute 32-bit address */
2886 if (isvar (&opP
->disp
))
2887 add_fix ('l', &opP
->disp
, 0, 0);
2888 tmpreg
= get_num (&opP
->disp
, 80);
2889 addword (tmpreg
>> 16);
2890 addword (tmpreg
& 0xFFFF);
2897 /* By the time whe get here (FINALLY) the_ins contains the complete
2898 instruction, ready to be emitted. . . */
2902 reverse_16_bits (in
)
2908 static int mask
[16] =
2910 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2911 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2913 for (n
= 0; n
< 16; n
++)
2916 out
|= mask
[15 - n
];
2919 } /* reverse_16_bits() */
2928 static int mask
[8] =
2930 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2933 for (n
= 0; n
< 8; n
++)
2939 } /* reverse_8_bits() */
2941 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2942 (that value is chosen in the frag_var call in md_assemble). TYPE
2943 is the subtype of the frag to be generated; its primary type is
2944 rs_machine_dependent.
2946 The TYPE parameter is also used by md_convert_frag_1 and
2947 md_estimate_size_before_relax. The appropriate type of fixup will
2948 be emitted by md_convert_frag_1.
2950 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2952 install_operand (mode
, val
)
2959 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2962 the_ins
.opcode
[0] |= val
<< 9;
2965 the_ins
.opcode
[1] |= val
<< 12;
2968 the_ins
.opcode
[1] |= val
<< 6;
2971 the_ins
.opcode
[1] |= val
;
2974 the_ins
.opcode
[2] |= val
<< 12;
2977 the_ins
.opcode
[2] |= val
<< 6;
2980 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2981 three words long! */
2983 the_ins
.opcode
[2] |= val
;
2986 the_ins
.opcode
[1] |= val
<< 7;
2989 the_ins
.opcode
[1] |= val
<< 10;
2993 the_ins
.opcode
[1] |= val
<< 5;
2998 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3001 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3004 the_ins
.opcode
[0] |= val
= 0xff;
3007 the_ins
.opcode
[0] |= val
<< 9;
3010 the_ins
.opcode
[1] |= val
;
3013 the_ins
.opcode
[1] |= val
;
3014 the_ins
.numo
++; /* What a hack */
3017 the_ins
.opcode
[1] |= val
<< 4;
3025 the_ins
.opcode
[0] |= (val
<< 6);
3028 the_ins
.opcode
[1] = (val
>> 16);
3029 the_ins
.opcode
[2] = val
& 0xffff;
3033 as_fatal (_("failed sanity check."));
3035 } /* install_operand() */
3038 install_gen_operand (mode
, val
)
3045 the_ins
.opcode
[0] |= val
;
3048 /* This is a kludge!!! */
3049 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3058 the_ins
.opcode
[0] |= val
;
3060 /* more stuff goes here */
3062 as_fatal (_("failed sanity check."));
3064 } /* install_gen_operand() */
3067 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3068 * then deal with the bitfield hack.
3072 crack_operand (str
, opP
)
3074 register struct m68k_op
*opP
;
3076 register int parens
;
3078 register char *beg_str
;
3086 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3092 else if (*str
== ')')
3096 opP
->error
= _("Extra )");
3102 if (flag_mri
&& *str
== '\'')
3103 inquote
= ! inquote
;
3105 if (!*str
&& parens
)
3107 opP
->error
= _("Missing )");
3112 if (m68k_ip_op (beg_str
, opP
) != 0)
3119 c
= *++str
; /* JF bitfield hack */
3124 as_bad (_("Missing operand"));
3127 /* Detect MRI REG symbols and convert them to REGLSTs. */
3128 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3131 opP
->mask
= ~(int)opP
->reg
;
3138 /* This is the guts of the machine-dependent assembler. STR points to a
3139 machine dependent instruction. This function is supposed to emit
3140 the frags/bytes it assembles to.
3144 insert_reg (regname
, regnum
)
3145 const char *regname
;
3151 #ifdef REGISTER_PREFIX
3152 if (!flag_reg_prefix_optional
)
3154 buf
[0] = REGISTER_PREFIX
;
3155 strcpy (buf
+ 1, regname
);
3160 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3161 &zero_address_frag
));
3163 for (i
= 0; regname
[i
]; i
++)
3164 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3167 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3168 &zero_address_frag
));
3177 static const struct init_entry init_table
[] =
3232 /* control registers */
3233 { "sfc", SFC
}, /* Source Function Code */
3235 { "dfc", DFC
}, /* Destination Function Code */
3237 { "cacr", CACR
}, /* Cache Control Register */
3238 { "caar", CAAR
}, /* Cache Address Register */
3240 { "usp", USP
}, /* User Stack Pointer */
3241 { "vbr", VBR
}, /* Vector Base Register */
3242 { "msp", MSP
}, /* Master Stack Pointer */
3243 { "isp", ISP
}, /* Interrupt Stack Pointer */
3245 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0 */
3246 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1 */
3247 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0 */
3248 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1 */
3250 /* 68ec040 versions of same */
3251 { "iacr0", ITT0
}, /* Instruction Access Control Register 0 */
3252 { "iacr1", ITT1
}, /* Instruction Access Control Register 0 */
3253 { "dacr0", DTT0
}, /* Data Access Control Register 0 */
3254 { "dacr1", DTT1
}, /* Data Access Control Register 0 */
3256 /* mcf5200 versions of same. The ColdFire programmer's reference
3257 manual indicated that the order is 2,3,0,1, but Ken Rose
3258 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3259 { "acr0", ITT0
}, /* Access Control Unit 0 */
3260 { "acr1", ITT1
}, /* Access Control Unit 1 */
3261 { "acr2", DTT0
}, /* Access Control Unit 2 */
3262 { "acr3", DTT1
}, /* Access Control Unit 3 */
3264 { "tc", TC
}, /* MMU Translation Control Register */
3267 { "mmusr", MMUSR
}, /* MMU Status Register */
3268 { "srp", SRP
}, /* User Root Pointer */
3269 { "urp", URP
}, /* Supervisor Root Pointer */
3274 { "rombar", ROMBAR
}, /* ROM Base Address Register */
3275 { "rambar0", RAMBAR0
}, /* ROM Base Address Register */
3276 { "rambar1", RAMBAR1
}, /* ROM Base Address Register */
3277 { "mbar", MBAR
}, /* Module Base Address Register */
3278 /* end of control registers */
3312 /* 68ec030 versions of same */
3315 /* 68ec030 access control unit, identical to 030 MMU status reg */
3318 /* Suppressed data and address registers. */
3343 for (i
= 0; init_table
[i
].name
; i
++)
3344 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3347 static int no_68851
, no_68881
;
3350 /* a.out machine type. Default to 68020. */
3351 int m68k_aout_machtype
= 2;
3363 int shorts_this_frag
;
3366 /* In MRI mode, the instruction and operands are separated by a
3367 space. Anything following the operands is a comment. The label
3368 has already been removed. */
3376 for (s
= str
; *s
!= '\0'; s
++)
3378 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3396 inquote
= ! inquote
;
3401 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3406 for (n
= 0; n
< the_ins
.numargs
; n
++)
3407 if (the_ins
.operands
[n
].error
)
3409 er
= the_ins
.operands
[n
].error
;
3415 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
3419 /* If there is a current label, record that it marks an instruction. */
3420 if (current_label
!= NULL
)
3422 current_label
->text
= 1;
3423 current_label
= NULL
;
3426 if (the_ins
.nfrag
== 0)
3428 /* No frag hacking involved; just put it out */
3429 toP
= frag_more (2 * the_ins
.numo
);
3430 fromP
= &the_ins
.opcode
[0];
3431 for (m
= the_ins
.numo
; m
; --m
)
3433 md_number_to_chars (toP
, (long) (*fromP
), 2);
3437 /* put out symbol-dependent info */
3438 for (m
= 0; m
< the_ins
.nrel
; m
++)
3440 switch (the_ins
.reloc
[m
].wid
)
3459 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3460 the_ins
.reloc
[m
].wid
);
3463 fixP
= fix_new_exp (frag_now
,
3464 ((toP
- frag_now
->fr_literal
)
3465 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3467 &the_ins
.reloc
[m
].exp
,
3468 the_ins
.reloc
[m
].pcrel
,
3469 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
3470 the_ins
.reloc
[m
].pic_reloc
));
3471 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3472 if (the_ins
.reloc
[m
].wid
== 'B')
3473 fixP
->fx_signed
= 1;
3478 /* There's some frag hacking */
3479 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3484 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3486 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3487 toP
= frag_more (wid
);
3489 shorts_this_frag
= 0;
3490 for (m
= wid
/ 2; m
; --m
)
3492 md_number_to_chars (toP
, (long) (*fromP
), 2);
3497 for (m
= 0; m
< the_ins
.nrel
; m
++)
3499 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3501 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3504 wid
= the_ins
.reloc
[m
].wid
;
3507 the_ins
.reloc
[m
].wid
= 0;
3508 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3510 fixP
= fix_new_exp (frag_now
,
3511 ((toP
- frag_now
->fr_literal
)
3512 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3514 &the_ins
.reloc
[m
].exp
,
3515 the_ins
.reloc
[m
].pcrel
,
3516 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3517 the_ins
.reloc
[m
].pic_reloc
));
3518 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3520 (void) frag_var (rs_machine_dependent
, 10, 0,
3521 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3522 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3524 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3525 shorts_this_frag
= 0;
3528 toP
= frag_more (n
* sizeof (short));
3531 md_number_to_chars (toP
, (long) (*fromP
), 2);
3537 for (m
= 0; m
< the_ins
.nrel
; m
++)
3541 wid
= the_ins
.reloc
[m
].wid
;
3544 the_ins
.reloc
[m
].wid
= 0;
3545 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3547 fixP
= fix_new_exp (frag_now
,
3548 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3549 - shorts_this_frag
* 2),
3551 &the_ins
.reloc
[m
].exp
,
3552 the_ins
.reloc
[m
].pcrel
,
3553 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
3554 the_ins
.reloc
[m
].pic_reloc
));
3555 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
3563 * md_begin -- set up hash tables with 68000 instructions.
3564 * similar to what the vax assembler does. ---phr
3566 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3567 a copy of it at runtime, adding in the information we want but isn't
3568 there. I think it'd be better to have an awk script hack the table
3569 at compile time. Or even just xstr the table and use it as-is. But
3570 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3573 register const struct m68k_opcode
*ins
;
3574 register struct m68k_incant
*hack
, *slak
;
3575 register const char *retval
= 0; /* empty string, or error msg text */
3576 register unsigned int i
;
3581 flag_reg_prefix_optional
= 1;
3583 if (! m68k_rel32_from_cmdline
)
3587 op_hash
= hash_new ();
3589 obstack_begin (&robyn
, 4000);
3590 for (i
= 0; i
< m68k_numopcodes
; i
++)
3592 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3595 ins
= &m68k_opcodes
[i
];
3596 /* We *could* ignore insns that don't match our arch here
3597 but just leaving them out of the hash. */
3598 slak
->m_operands
= ins
->args
;
3599 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3600 slak
->m_arch
= ins
->arch
;
3601 slak
->m_opcode
= ins
->opcode
;
3602 /* This is kludgey */
3603 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3604 if (i
+ 1 != m68k_numopcodes
3605 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3607 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3612 slak
= slak
->m_next
;
3616 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3618 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
3621 for (i
= 0; i
< m68k_numaliases
; i
++)
3623 const char *name
= m68k_opcode_aliases
[i
].primary
;
3624 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3625 PTR val
= hash_find (op_hash
, name
);
3627 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
3628 retval
= hash_insert (op_hash
, alias
, val
);
3630 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
3633 /* In MRI mode, all unsized branches are variable sized. Normally,
3634 they are word sized. */
3637 static struct m68k_opcode_alias mri_aliases
[] =
3657 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3659 const char *name
= mri_aliases
[i
].primary
;
3660 const char *alias
= mri_aliases
[i
].alias
;
3661 PTR val
= hash_find (op_hash
, name
);
3663 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
3664 retval
= hash_jam (op_hash
, alias
, val
);
3666 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
3670 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3671 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3673 for (i
= 0; i
< sizeof (notend_table
); i
++)
3675 notend_table
[i
] = 0;
3676 alt_notend_table
[i
] = 0;
3678 notend_table
[','] = 1;
3679 notend_table
['{'] = 1;
3680 notend_table
['}'] = 1;
3681 alt_notend_table
['a'] = 1;
3682 alt_notend_table
['A'] = 1;
3683 alt_notend_table
['d'] = 1;
3684 alt_notend_table
['D'] = 1;
3685 alt_notend_table
['#'] = 1;
3686 alt_notend_table
['&'] = 1;
3687 alt_notend_table
['f'] = 1;
3688 alt_notend_table
['F'] = 1;
3689 #ifdef REGISTER_PREFIX
3690 alt_notend_table
[REGISTER_PREFIX
] = 1;
3693 /* We need to put '(' in alt_notend_table to handle
3694 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3696 alt_notend_table
['('] = 1;
3698 /* We need to put '@' in alt_notend_table to handle
3699 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3701 alt_notend_table
['@'] = 1;
3703 /* We need to put digits in alt_notend_table to handle
3704 bfextu %d0{24:1},%d0
3706 alt_notend_table
['0'] = 1;
3707 alt_notend_table
['1'] = 1;
3708 alt_notend_table
['2'] = 1;
3709 alt_notend_table
['3'] = 1;
3710 alt_notend_table
['4'] = 1;
3711 alt_notend_table
['5'] = 1;
3712 alt_notend_table
['6'] = 1;
3713 alt_notend_table
['7'] = 1;
3714 alt_notend_table
['8'] = 1;
3715 alt_notend_table
['9'] = 1;
3717 #ifndef MIT_SYNTAX_ONLY
3718 /* Insert pseudo ops, these have to go into the opcode table since
3719 gas expects pseudo ops to start with a dot */
3722 while (mote_pseudo_table
[n
].poc_name
)
3724 hack
= (struct m68k_incant
*)
3725 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3726 hash_insert (op_hash
,
3727 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3728 hack
->m_operands
= 0;
3738 record_alignment (text_section
, 2);
3739 record_alignment (data_section
, 2);
3740 record_alignment (bss_section
, 2);
3745 select_control_regs ()
3747 /* Note which set of "movec" control registers is available. */
3748 switch (cpu_of_arch (current_architecture
))
3751 control_regs
= m68000_control_regs
;
3754 control_regs
= m68010_control_regs
;
3758 control_regs
= m68020_control_regs
;
3761 control_regs
= m68040_control_regs
;
3764 control_regs
= m68060_control_regs
;
3767 control_regs
= cpu32_control_regs
;
3770 control_regs
= mcf5200_control_regs
;
3778 m68k_init_after_args ()
3780 if (cpu_of_arch (current_architecture
) == 0)
3783 const char *default_cpu
= TARGET_CPU
;
3785 if (*default_cpu
== 'm')
3787 for (i
= 0; i
< n_archs
; i
++)
3788 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3792 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU
);
3793 current_architecture
|= m68020
;
3796 current_architecture
|= archs
[i
].arch
;
3798 /* Permit m68881 specification with all cpus; those that can't work
3799 with a coprocessor could be doing emulation. */
3800 if (current_architecture
& m68851
)
3802 if (current_architecture
& m68040
)
3804 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
3807 /* What other incompatibilities could we check for? */
3809 /* Toss in some default assumptions about coprocessors. */
3811 && (cpu_of_arch (current_architecture
)
3812 /* Can CPU32 have a 68881 coprocessor?? */
3813 & (m68020
| m68030
| cpu32
)))
3815 current_architecture
|= m68881
;
3818 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3819 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3821 current_architecture
|= m68851
;
3823 if (no_68881
&& (current_architecture
& m68881
))
3824 as_bad (_("options for 68881 and no-68881 both given"));
3825 if (no_68851
&& (current_architecture
& m68851
))
3826 as_bad (_("options for 68851 and no-68851 both given"));
3829 /* Work out the magic number. This isn't very general. */
3830 if (current_architecture
& m68000
)
3831 m68k_aout_machtype
= 0;
3832 else if (current_architecture
& m68010
)
3833 m68k_aout_machtype
= 1;
3834 else if (current_architecture
& m68020
)
3835 m68k_aout_machtype
= 2;
3837 m68k_aout_machtype
= 2;
3840 /* Note which set of "movec" control registers is available. */
3841 select_control_regs ();
3843 if (cpu_of_arch (current_architecture
) < m68020
3844 || cpu_of_arch (current_architecture
) == mcf5200
)
3845 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3848 /* This is called when a label is defined. */
3851 m68k_frob_label (sym
)
3854 struct label_line
*n
;
3856 n
= (struct label_line
*) xmalloc (sizeof *n
);
3859 as_where (&n
->file
, &n
->line
);
3865 /* This is called when a value that is not an instruction is emitted. */
3868 m68k_flush_pending_output ()
3870 current_label
= NULL
;
3873 /* This is called at the end of the assembly, when the final value of
3874 the label is known. We warn if this is a text symbol aligned at an
3878 m68k_frob_symbol (sym
)
3881 if (S_GET_SEGMENT (sym
) == reg_section
3882 && (int) S_GET_VALUE (sym
) < 0)
3884 S_SET_SEGMENT (sym
, absolute_section
);
3885 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
3887 else if ((S_GET_VALUE (sym
) & 1) != 0)
3889 struct label_line
*l
;
3891 for (l
= labels
; l
!= NULL
; l
= l
->next
)
3893 if (l
->label
== sym
)
3896 as_warn_where (l
->file
, l
->line
,
3897 _("text label `%s' aligned to odd boundary"),
3905 /* This is called if we go in or out of MRI mode because of the .mri
3909 m68k_mri_mode_change (on
)
3914 if (! flag_reg_prefix_optional
)
3916 flag_reg_prefix_optional
= 1;
3917 #ifdef REGISTER_PREFIX
3922 if (! m68k_rel32_from_cmdline
)
3927 if (! reg_prefix_optional_seen
)
3929 #ifdef REGISTER_PREFIX_OPTIONAL
3930 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
3932 flag_reg_prefix_optional
= 0;
3934 #ifdef REGISTER_PREFIX
3939 if (! m68k_rel32_from_cmdline
)
3944 /* Equal to MAX_PRECISION in atof-ieee.c */
3945 #define MAX_LITTLENUMS 6
3947 /* Turn a string in input_line_pointer into a floating point constant
3948 of type type, and store the appropriate bytes in *litP. The number
3949 of LITTLENUMS emitted is stored in *sizeP . An error message is
3950 returned, or NULL on OK. */
3953 md_atof (type
, litP
, sizeP
)
3959 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3960 LITTLENUM_TYPE
*wordP
;
3991 return _("Bad call to MD_ATOF()");
3993 t
= atof_ieee (input_line_pointer
, type
, words
);
3995 input_line_pointer
= t
;
3997 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3998 for (wordP
= words
; prec
--;)
4000 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
4001 litP
+= sizeof (LITTLENUM_TYPE
);
4007 md_number_to_chars (buf
, val
, n
)
4012 number_to_chars_bigendian (buf
, val
, n
);
4016 md_apply_fix_2 (fixP
, val
)
4020 addressT upper_limit
;
4021 offsetT lower_limit
;
4023 /* This is unnecessary but it convinces the native rs6000 compiler
4024 to generate the code we want. */
4025 char *buf
= fixP
->fx_frag
->fr_literal
;
4026 buf
+= fixP
->fx_where
;
4027 /* end ibm compiler workaround */
4029 if (val
& 0x80000000)
4030 val
|= ~(addressT
)0x7fffffff;
4037 memset (buf
, 0, fixP
->fx_size
);
4038 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc */
4043 switch (fixP
->fx_size
)
4045 /* The cast to offsetT below are necessary to make code correct for
4046 machines where ints are smaller than offsetT */
4050 lower_limit
= - (offsetT
) 0x80;
4053 *buf
++ = (val
>> 8);
4055 upper_limit
= 0x7fff;
4056 lower_limit
= - (offsetT
) 0x8000;
4059 *buf
++ = (val
>> 24);
4060 *buf
++ = (val
>> 16);
4061 *buf
++ = (val
>> 8);
4063 upper_limit
= 0x7fffffff;
4064 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
4067 BAD_CASE (fixP
->fx_size
);
4070 /* Fix up a negative reloc. */
4071 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4073 fixP
->fx_addsy
= fixP
->fx_subsy
;
4074 fixP
->fx_subsy
= NULL
;
4078 /* For non-pc-relative values, it's conceivable we might get something
4079 like "0xff" for a byte field. So extend the upper part of the range
4080 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4081 so that we can do any range checking at all. */
4082 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4083 upper_limit
= upper_limit
* 2 + 1;
4085 if ((addressT
) val
> upper_limit
4086 && (val
> 0 || val
< lower_limit
))
4087 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("value out of range"));
4089 /* A one byte PC-relative reloc means a short branch. We can't use
4090 a short branch with a value of 0 or -1, because those indicate
4091 different opcodes (branches with longer offsets). fixup_segment
4092 in write.c may have clobbered fx_pcrel, so we need to examine the
4095 #ifdef BFD_ASSEMBLER
4096 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
4099 && fixP
->fx_size
== 1
4100 && (fixP
->fx_addsy
== NULL
4101 || S_IS_DEFINED (fixP
->fx_addsy
))
4102 && (val
== 0 || val
== -1))
4103 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("invalid byte branch offset"));
4106 #ifdef BFD_ASSEMBLER
4108 md_apply_fix (fixP
, valp
)
4112 md_apply_fix_2 (fixP
, (addressT
) *valp
);
4116 void md_apply_fix (fixP
, val
)
4120 md_apply_fix_2 (fixP
, (addressT
) val
);
4124 /* *fragP has been relaxed to its final size, and now needs to have
4125 the bytes inside it modified to conform to the new size There is UGLY
4129 md_convert_frag_1 (fragP
)
4130 register fragS
*fragP
;
4136 /* Address in object code of the displacement. */
4137 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4139 /* Address in gas core of the place to store the displacement. */
4140 /* This convinces the native rs6000 compiler to generate the code we
4142 register char *buffer_address
= fragP
->fr_literal
;
4143 buffer_address
+= fragP
->fr_fix
;
4144 /* end ibm compiler workaround */
4146 /* The displacement of the address, from current location. */
4147 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4148 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4150 #ifdef BFD_ASSEMBLER
4151 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
4154 switch (fragP
->fr_subtype
)
4156 case TAB (BCC68000
, BYTE
):
4157 case TAB (ABRANCH
, BYTE
):
4158 know (issbyte (disp
));
4160 as_bad (_("short branch with zero offset: use :w"));
4161 fragP
->fr_opcode
[1] = disp
;
4164 case TAB (DBCC
, SHORT
):
4165 know (issword (disp
));
4168 case TAB (BCC68000
, SHORT
):
4169 case TAB (ABRANCH
, SHORT
):
4170 know (issword (disp
));
4171 fragP
->fr_opcode
[1] = 0x00;
4174 case TAB (ABRANCH
, LONG
):
4175 if (!HAVE_LONG_BRANCH(current_architecture
))
4177 if (fragP
->fr_opcode
[0] == 0x61)
4180 fragP
->fr_opcode
[0] = 0x4E;
4181 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4195 else if (fragP
->fr_opcode
[0] == 0x60)
4197 fragP
->fr_opcode
[0] = 0x4E;
4198 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4199 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4200 fragP
->fr_offset
, 0, NO_RELOC
);
4206 as_bad (_("Long branch offset not supported."));
4211 fragP
->fr_opcode
[1] = (char) 0xff;
4215 case TAB (BCC68000
, LONG
):
4216 /* only Bcc 68000 instructions can come here */
4217 /* change bcc into b!cc/jmp absl long */
4218 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4219 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4221 /* JF: these used to be fr_opcode[2,3], but they may be in a
4222 different frag, in which case refering to them is a no-no.
4223 Only fr_opcode[0,1] are guaranteed to work. */
4224 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4225 *buffer_address
++ = (char) 0xf9;
4226 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4227 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4228 fragP
->fr_offset
, 0, NO_RELOC
);
4232 case TAB (DBCC
, LONG
):
4233 /* only DBcc 68000 instructions can come here */
4234 /* change dbcc into dbcc/jmp absl long */
4235 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4236 *buffer_address
++ = 0x00; /* branch offset = 4 */
4237 *buffer_address
++ = 0x04;
4238 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4239 *buffer_address
++ = 0x06;
4240 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4241 *buffer_address
++ = (char) 0xf9;
4243 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4244 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4245 fragP
->fr_offset
, 0, NO_RELOC
);
4249 case TAB (FBRANCH
, SHORT
):
4250 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4253 case TAB (FBRANCH
, LONG
):
4254 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4257 case TAB (PCREL
, SHORT
):
4260 case TAB (PCREL
, LONG
):
4261 /* The thing to do here is force it to ABSOLUTE LONG, since
4262 PCREL is really trying to shorten an ABSOLUTE address anyway */
4263 /* JF FOO This code has not been tested */
4264 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4266 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4267 as_bad (_("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx"),
4268 (unsigned) fragP
->fr_opcode
[0],
4269 (unsigned long) fragP
->fr_address
);
4270 fragP
->fr_opcode
[1] &= ~0x3F;
4271 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4275 case TAB (PCLEA
, SHORT
):
4276 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4277 fragP
->fr_offset
, 1, NO_RELOC
);
4278 fragP
->fr_opcode
[1] &= ~0x3F;
4279 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4282 case TAB (PCLEA
, LONG
):
4283 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4284 fragP
->fr_offset
, 1, NO_RELOC
);
4285 fixP
->fx_pcrel_adjust
= 2;
4286 /* Already set to mode 7.3; this indicates: PC indirect with
4287 suppressed index, 32-bit displacement. */
4288 *buffer_address
++ = 0x01;
4289 *buffer_address
++ = 0x70;
4294 case TAB (PCINDEX
, BYTE
):
4296 if (!issbyte (disp
))
4298 as_bad (_("displacement doesn't fit in one byte"));
4301 assert (fragP
->fr_fix
>= 2);
4302 buffer_address
[-2] &= ~1;
4303 buffer_address
[-1] = disp
;
4306 case TAB (PCINDEX
, SHORT
):
4308 assert (issword (disp
));
4309 assert (fragP
->fr_fix
>= 2);
4310 buffer_address
[-2] |= 0x1;
4311 buffer_address
[-1] = 0x20;
4312 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4313 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4315 fixP
->fx_pcrel_adjust
= 2;
4318 case TAB (PCINDEX
, LONG
):
4320 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4321 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
4323 fixP
->fx_pcrel_adjust
= 2;
4324 assert (fragP
->fr_fix
>= 2);
4325 buffer_address
[-2] |= 0x1;
4326 buffer_address
[-1] = 0x30;
4333 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4334 fragP
->fr_fix
+= ext
;
4338 #ifndef BFD_ASSEMBLER
4341 md_convert_frag (headers
, sec
, fragP
)
4342 object_headers
*headers
;
4346 md_convert_frag_1 (fragP
);
4352 md_convert_frag (abfd
, sec
, fragP
)
4357 md_convert_frag_1 (fragP
);
4361 /* Force truly undefined symbols to their maximum size, and generally set up
4362 the frag list to be relaxed
4365 md_estimate_size_before_relax (fragP
, segment
)
4366 register fragS
*fragP
;
4370 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4372 old_fix
= fragP
->fr_fix
;
4374 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4375 switch (fragP
->fr_subtype
)
4378 case TAB (ABRANCH
, SZ_UNDEF
):
4380 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4381 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4383 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4386 else if ((fragP
->fr_symbol
== 0) || !HAVE_LONG_BRANCH(current_architecture
))
4388 /* On 68000, or for absolute value, switch to abs long */
4389 /* FIXME, we should check abs val, pick short or long */
4390 if (fragP
->fr_opcode
[0] == 0x61)
4392 fragP
->fr_opcode
[0] = 0x4E;
4393 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4394 fix_new (fragP
, fragP
->fr_fix
, 4,
4395 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4399 else if (fragP
->fr_opcode
[0] == 0x60)
4401 fragP
->fr_opcode
[0] = 0x4E;
4402 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4403 fix_new (fragP
, fragP
->fr_fix
, 4,
4404 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4410 as_warn (_("Long branch offset to extern symbol not supported."));
4414 { /* Symbol is still undefined. Make it simple */
4415 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4416 fragP
->fr_offset
, 1, NO_RELOC
);
4418 fragP
->fr_opcode
[1] = (char) 0xff;
4424 } /* case TAB(ABRANCH,SZ_UNDEF) */
4426 case TAB (FBRANCH
, SZ_UNDEF
):
4428 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
4430 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4435 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4436 fragP
->fr_offset
, 1, NO_RELOC
);
4438 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4442 } /* TAB(FBRANCH,SZ_UNDEF) */
4444 case TAB (PCREL
, SZ_UNDEF
):
4446 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4447 && relaxable_symbol (fragP
->fr_symbol
))
4449 || cpu_of_arch (current_architecture
) < m68020
4450 || cpu_of_arch (current_architecture
) == mcf5200
)
4452 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4457 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4461 } /* TAB(PCREL,SZ_UNDEF) */
4463 case TAB (BCC68000
, SZ_UNDEF
):
4465 if ((fragP
->fr_symbol
!= NULL
)
4466 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4468 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4471 /* only Bcc 68000 instructions can come here */
4472 /* change bcc into b!cc/jmp absl long */
4473 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4474 if (flag_short_refs
)
4476 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4477 /* JF: these were fr_opcode[2,3] */
4478 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4479 buffer_address
[1] = (char) 0xf8;
4480 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4481 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4482 fragP
->fr_offset
, 0, NO_RELOC
);
4487 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4488 /* JF: these were fr_opcode[2,3] */
4489 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4490 buffer_address
[1] = (char) 0xf9;
4491 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4492 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4493 fragP
->fr_offset
, 0, NO_RELOC
);
4498 } /* case TAB(BCC68000,SZ_UNDEF) */
4500 case TAB (DBCC
, SZ_UNDEF
):
4502 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4504 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4508 /* only DBcc 68000 instructions can come here */
4509 /* change dbcc into dbcc/jmp absl long */
4510 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4511 buffer_address
[0] = 0x00; /* branch offset = 4 */
4512 buffer_address
[1] = 0x04;
4513 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4515 if (flag_short_refs
)
4517 /* JF: these were fr_opcode[5-7] */
4518 buffer_address
[3] = 0x04; /* plus 4 */
4519 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4520 buffer_address
[5] = (char) 0xf8;
4521 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4522 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4523 fragP
->fr_offset
, 0, NO_RELOC
);
4528 /* JF: these were fr_opcode[5-7] */
4529 buffer_address
[3] = 0x06; /* Plus 6 */
4530 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4531 buffer_address
[5] = (char) 0xf9;
4532 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4533 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4534 fragP
->fr_offset
, 0, NO_RELOC
);
4540 } /* case TAB(DBCC,SZ_UNDEF) */
4542 case TAB (PCLEA
, SZ_UNDEF
):
4544 if (((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4545 && relaxable_symbol (fragP
->fr_symbol
))
4547 || cpu_of_arch (current_architecture
) < m68020
4548 || cpu_of_arch (current_architecture
) == mcf5200
)
4550 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4555 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4559 } /* TAB(PCLEA,SZ_UNDEF) */
4561 case TAB (PCINDEX
, SZ_UNDEF
):
4562 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4563 && relaxable_symbol (fragP
->fr_symbol
))
4564 || cpu_of_arch (current_architecture
) < m68020
4565 || cpu_of_arch (current_architecture
) == mcf5200
)
4567 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4571 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4580 /* now that SZ_UNDEF are taken care of, check others */
4581 switch (fragP
->fr_subtype
)
4583 case TAB (BCC68000
, BYTE
):
4584 case TAB (ABRANCH
, BYTE
):
4585 /* We can't do a short jump to the next instruction, so in that
4586 case we force word mode. At this point S_GET_VALUE should
4587 return the offset of the symbol within its frag. If the
4588 symbol is at the start of a frag, and it is the next frag
4589 with any data in it (usually this is just the next frag, but
4590 assembler listings may introduce empty frags), we must use
4592 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0)
4596 for (l
= fragP
->fr_next
;
4597 l
!= fragP
->fr_symbol
->sy_frag
;
4599 if (l
->fr_fix
+ l
->fr_var
!= 0)
4601 if (l
== fragP
->fr_symbol
->sy_frag
)
4603 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4611 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4614 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4615 /* the bit-field entries in the relocation_info struct plays hell
4616 with the byte-order problems of cross-assembly. So as a hack,
4617 I added this mach. dependent ri twiddler. Ugly, but it gets
4619 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4620 are symbolnum, most sig. byte first. Last byte is broken up with
4621 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4622 nibble as nuthin. (on Sun 3 at least) */
4623 /* Translate the internal relocation information into target-specific
4627 md_ri_to_chars (the_bytes
, ri
)
4629 struct reloc_info_generic
*ri
;
4632 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4633 /* now the fun stuff */
4634 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4635 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4636 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4637 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4638 ((ri
->r_extern
<< 4) & 0x10));
4641 #endif /* comment */
4643 #ifndef BFD_ASSEMBLER
4645 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4648 relax_addressT segment_address_in_file
;
4651 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4652 * Out: GNU LD relocation length code: 0, 1, or 2.
4655 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4658 know (fixP
->fx_addsy
!= NULL
);
4660 md_number_to_chars (where
,
4661 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4664 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4665 ? S_GET_TYPE (fixP
->fx_addsy
)
4666 : fixP
->fx_addsy
->sy_number
);
4668 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4669 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4670 where
[6] = r_symbolnum
& 0x0ff;
4671 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4672 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4676 #endif /* OBJ_AOUT or OBJ_BOUT */
4678 #ifndef WORKING_DOT_WORD
4679 CONST
int md_short_jump_size
= 4;
4680 CONST
int md_long_jump_size
= 6;
4683 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4685 addressT from_addr
, to_addr
;
4691 offset
= to_addr
- (from_addr
+ 2);
4693 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4694 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4698 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4700 addressT from_addr
, to_addr
;
4706 if (!HAVE_LONG_BRANCH(current_architecture
))
4708 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4709 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4710 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4711 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4716 offset
= to_addr
- (from_addr
+ 2);
4717 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4718 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4724 /* Different values of OK tell what its OK to return. Things that
4725 aren't OK are an error (what a shock, no?)
4728 10: Absolute 1:8 only
4729 20: Absolute 0:7 only
4730 30: absolute 0:15 only
4731 40: Absolute 0:31 only
4732 50: absolute 0:127 only
4733 55: absolute -64:63 only
4734 60: absolute -128:127 only
4735 70: absolute 0:4095 only
4742 struct m68k_exp
*exp
;
4745 if (exp
->exp
.X_op
== O_absent
)
4747 /* Do the same thing the VAX asm does */
4748 op (exp
) = O_constant
;
4754 as_warn (_("expression out of range: defaulting to 1"));
4758 else if (exp
->exp
.X_op
== O_constant
)
4763 if (offs (exp
) < 1 || offs (exp
) > 8)
4765 as_warn (_("expression out of range: defaulting to 1"));
4770 if (offs (exp
) < 0 || offs (exp
) > 7)
4774 if (offs (exp
) < 0 || offs (exp
) > 15)
4778 if (offs (exp
) < 0 || offs (exp
) > 32)
4782 if (offs (exp
) < 0 || offs (exp
) > 127)
4786 if (offs (exp
) < -64 || offs (exp
) > 63)
4790 if (offs (exp
) < -128 || offs (exp
) > 127)
4794 if (offs (exp
) < 0 || offs (exp
) > 4095)
4797 as_warn (_("expression out of range: defaulting to 0"));
4805 else if (exp
->exp
.X_op
== O_big
)
4807 if (offs (exp
) <= 0 /* flonum */
4808 && (ok
== 80 /* no bignums */
4809 || (ok
> 10 /* small-int ranges including 0 ok */
4810 /* If we have a flonum zero, a zero integer should
4811 do as well (e.g., in moveq). */
4812 && generic_floating_point_number
.exponent
== 0
4813 && generic_floating_point_number
.low
[0] == 0)))
4815 /* HACK! Turn it into a long */
4816 LITTLENUM_TYPE words
[6];
4818 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4819 op (exp
) = O_constant
;
4822 offs (exp
) = words
[1] | (words
[0] << 16);
4826 op (exp
) = O_constant
;
4829 offs (exp
) = (ok
== 10) ? 1 : 0;
4830 as_warn (_("Can't deal with expression; defaulting to %ld"),
4836 if (ok
>= 10 && ok
<= 70)
4838 op (exp
) = O_constant
;
4841 offs (exp
) = (ok
== 10) ? 1 : 0;
4842 as_warn (_("Can't deal with expression; defaulting to %ld"),
4847 if (exp
->size
!= SIZE_UNSPEC
)
4855 if (!isbyte (offs (exp
)))
4856 as_warn (_("expression doesn't fit in BYTE"));
4859 if (!isword (offs (exp
)))
4860 as_warn (_("expression doesn't fit in WORD"));
4868 /* These are the back-ends for the various machine dependent pseudo-ops. */
4874 subseg_set (data_section
, 1);
4875 demand_empty_rest_of_line ();
4882 subseg_set (data_section
, 2);
4883 demand_empty_rest_of_line ();
4890 /* We don't support putting frags in the BSS segment, we fake it
4891 by marking in_bss, then looking at s_skip for clues. */
4893 subseg_set (bss_section
, 0);
4894 demand_empty_rest_of_line ();
4902 register long temp_fill
;
4904 temp
= 1; /* JF should be 2? */
4905 temp_fill
= get_absolute_expression ();
4906 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4907 frag_align (temp
, (int) temp_fill
, 0);
4908 demand_empty_rest_of_line ();
4909 record_alignment (now_seg
, temp
);
4916 demand_empty_rest_of_line ();
4919 /* Pseudo-ops handled for MRI compatibility. */
4921 /* This function returns non-zero if the argument is a conditional
4922 pseudo-op. This is called when checking whether a pending
4923 alignment is needed. */
4926 m68k_conditional_pseudoop (pop
)
4929 return (pop
->poc_handler
== s_mri_if
4930 || pop
->poc_handler
== s_mri_else
);
4933 /* Handle an MRI style chip specification. */
4942 s
= input_line_pointer
;
4943 /* We can't use get_symbol_end since the processor names are not proper
4945 while (is_part_of_name (c
= *input_line_pointer
++))
4947 *--input_line_pointer
= 0;
4948 for (i
= 0; i
< n_archs
; i
++)
4949 if (strcasecmp (s
, archs
[i
].name
) == 0)
4953 as_bad (_("%s: unrecognized processor name"), s
);
4954 *input_line_pointer
= c
;
4955 ignore_rest_of_line ();
4958 *input_line_pointer
= c
;
4960 if (*input_line_pointer
== '/')
4961 current_architecture
= 0;
4963 current_architecture
&= m68881
| m68851
;
4964 current_architecture
|= archs
[i
].arch
;
4966 while (*input_line_pointer
== '/')
4968 ++input_line_pointer
;
4969 s
= input_line_pointer
;
4970 /* We can't use get_symbol_end since the processor names are not
4972 while (is_part_of_name (c
= *input_line_pointer
++))
4974 *--input_line_pointer
= 0;
4975 if (strcmp (s
, "68881") == 0)
4976 current_architecture
|= m68881
;
4977 else if (strcmp (s
, "68851") == 0)
4978 current_architecture
|= m68851
;
4979 *input_line_pointer
= c
;
4982 /* Update info about available control registers. */
4983 select_control_regs ();
4986 /* The MRI CHIP pseudo-op. */
4996 stop
= mri_comment_field (&stopc
);
4999 mri_comment_end (stop
, stopc
);
5000 demand_empty_rest_of_line ();
5003 /* The MRI FOPT pseudo-op. */
5011 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5015 input_line_pointer
+= 3;
5016 temp
= get_absolute_expression ();
5017 if (temp
< 0 || temp
> 7)
5018 as_bad (_("bad coprocessor id"));
5020 m68k_float_copnum
= COP0
+ temp
;
5024 as_bad (_("unrecognized fopt option"));
5025 ignore_rest_of_line ();
5029 demand_empty_rest_of_line ();
5032 /* The structure used to handle the MRI OPT pseudo-op. */
5036 /* The name of the option. */
5039 /* If this is not NULL, just call this function. The first argument
5040 is the ARG field of this structure, the second argument is
5041 whether the option was negated. */
5042 void (*pfn
) PARAMS ((int arg
, int on
));
5044 /* If this is not NULL, and the PFN field is NULL, set the variable
5045 this points to. Set it to the ARG field if the option was not
5046 negated, and the NOTARG field otherwise. */
5049 /* The value to pass to PFN or to assign to *PVAR. */
5052 /* The value to assign to *PVAR if the option is negated. If PFN is
5053 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5054 the option may not be negated. */
5058 /* The table used to handle the MRI OPT pseudo-op. */
5060 static void skip_to_comma
PARAMS ((int, int));
5061 static void opt_nest
PARAMS ((int, int));
5062 static void opt_chip
PARAMS ((int, int));
5063 static void opt_list
PARAMS ((int, int));
5064 static void opt_list_symbols
PARAMS ((int, int));
5066 static const struct opt_action opt_table
[] =
5068 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5070 /* We do relaxing, so there is little use for these options. */
5071 { "b", 0, 0, 0, 0 },
5072 { "brs", 0, 0, 0, 0 },
5073 { "brb", 0, 0, 0, 0 },
5074 { "brl", 0, 0, 0, 0 },
5075 { "brw", 0, 0, 0, 0 },
5077 { "c", 0, 0, 0, 0 },
5078 { "cex", 0, 0, 0, 0 },
5079 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5080 { "cl", 0, 0, 0, 0 },
5081 { "cre", 0, 0, 0, 0 },
5082 { "d", 0, &flag_keep_locals
, 1, 0 },
5083 { "e", 0, 0, 0, 0 },
5084 { "f", 0, &flag_short_refs
, 1, 0 },
5085 { "frs", 0, &flag_short_refs
, 1, 0 },
5086 { "frl", 0, &flag_short_refs
, 0, 1 },
5087 { "g", 0, 0, 0, 0 },
5088 { "i", 0, 0, 0, 0 },
5089 { "m", 0, 0, 0, 0 },
5090 { "mex", 0, 0, 0, 0 },
5091 { "mc", 0, 0, 0, 0 },
5092 { "md", 0, 0, 0, 0 },
5093 { "nest", opt_nest
, 0, 0, 0 },
5094 { "next", skip_to_comma
, 0, 0, 0 },
5095 { "o", 0, 0, 0, 0 },
5096 { "old", 0, 0, 0, 0 },
5097 { "op", skip_to_comma
, 0, 0, 0 },
5098 { "pco", 0, 0, 0, 0 },
5099 { "p", opt_chip
, 0, 0, 0 },
5100 { "pcr", 0, 0, 0, 0 },
5101 { "pcs", 0, 0, 0, 0 },
5102 { "r", 0, 0, 0, 0 },
5103 { "quick", 0, &m68k_quick
, 1, 0 },
5104 { "rel32", 0, &m68k_rel32
, 1, 0 },
5105 { "s", opt_list
, 0, 0, 0 },
5106 { "t", opt_list_symbols
, 0, 0, 0 },
5107 { "w", 0, &flag_no_warnings
, 0, 1 },
5111 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
5113 /* The MRI OPT pseudo-op. */
5125 const struct opt_action
*o
;
5130 if (*input_line_pointer
== '-')
5132 ++input_line_pointer
;
5135 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5137 input_line_pointer
+= 2;
5141 s
= input_line_pointer
;
5142 c
= get_symbol_end ();
5144 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5146 if (strcasecmp (s
, o
->name
) == 0)
5150 /* Restore input_line_pointer now in case the option
5152 *input_line_pointer
= c
;
5153 (*o
->pfn
) (o
->arg
, t
);
5155 else if (o
->pvar
!= NULL
)
5157 if (! t
&& o
->arg
== o
->notarg
)
5158 as_bad (_("option `%s' may not be negated"), s
);
5159 *input_line_pointer
= c
;
5160 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5163 *input_line_pointer
= c
;
5169 as_bad (_("option `%s' not recognized"), s
);
5170 *input_line_pointer
= c
;
5173 while (*input_line_pointer
++ == ',');
5175 /* Move back to terminating character. */
5176 --input_line_pointer
;
5177 demand_empty_rest_of_line ();
5180 /* Skip ahead to a comma. This is used for OPT options which we do
5181 not suppor tand which take arguments. */
5184 skip_to_comma (arg
, on
)
5188 while (*input_line_pointer
!= ','
5189 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5190 ++input_line_pointer
;
5193 /* Handle the OPT NEST=depth option. */
5200 if (*input_line_pointer
!= '=')
5202 as_bad (_("bad format of OPT NEST=depth"));
5206 ++input_line_pointer
;
5207 max_macro_nest
= get_absolute_expression ();
5210 /* Handle the OPT P=chip option. */
5217 if (*input_line_pointer
!= '=')
5219 /* This is just OPT P, which we do not support. */
5223 ++input_line_pointer
;
5227 /* Handle the OPT S option. */
5237 /* Handle the OPT T option. */
5240 opt_list_symbols (arg
, on
)
5245 listing
|= LISTING_SYMBOLS
;
5247 listing
&=~ LISTING_SYMBOLS
;
5250 /* Handle the MRI REG pseudo-op. */
5263 if (line_label
== NULL
)
5265 as_bad (_("missing label"));
5266 ignore_rest_of_line ();
5271 stop
= mri_comment_field (&stopc
);
5275 s
= input_line_pointer
;
5276 while (isalnum ((unsigned char) *input_line_pointer
)
5277 #ifdef REGISTER_PREFIX
5278 || *input_line_pointer
== REGISTER_PREFIX
5280 || *input_line_pointer
== '/'
5281 || *input_line_pointer
== '-')
5282 ++input_line_pointer
;
5283 c
= *input_line_pointer
;
5284 *input_line_pointer
= '\0';
5286 if (m68k_ip_op (s
, &rop
) != 0)
5288 if (rop
.error
== NULL
)
5289 as_bad (_("bad register list"));
5291 as_bad (_("bad register list: %s"), rop
.error
);
5292 *input_line_pointer
= c
;
5293 ignore_rest_of_line ();
5297 *input_line_pointer
= c
;
5299 if (rop
.mode
== REGLST
)
5301 else if (rop
.mode
== DREG
)
5302 mask
= 1 << (rop
.reg
- DATA0
);
5303 else if (rop
.mode
== AREG
)
5304 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5305 else if (rop
.mode
== FPREG
)
5306 mask
= 1 << (rop
.reg
- FP0
+ 16);
5307 else if (rop
.mode
== CONTROL
5310 else if (rop
.mode
== CONTROL
5313 else if (rop
.mode
== CONTROL
5318 as_bad (_("bad register list"));
5319 ignore_rest_of_line ();
5323 S_SET_SEGMENT (line_label
, reg_section
);
5324 S_SET_VALUE (line_label
, ~mask
);
5325 line_label
->sy_frag
= &zero_address_frag
;
5328 mri_comment_end (stop
, stopc
);
5330 demand_empty_rest_of_line ();
5333 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5337 struct save_opts
*next
;
5339 int symbols_case_sensitive
;
5347 /* FIXME: We don't save OPT S. */
5350 /* This variable holds the stack of saved options. */
5352 static struct save_opts
*save_stack
;
5354 /* The MRI SAVE pseudo-op. */
5360 struct save_opts
*s
;
5362 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5363 s
->abspcadd
= m68k_abspcadd
;
5364 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5365 s
->keep_locals
= flag_keep_locals
;
5366 s
->short_refs
= flag_short_refs
;
5367 s
->architecture
= current_architecture
;
5368 s
->quick
= m68k_quick
;
5369 s
->rel32
= m68k_rel32
;
5370 s
->listing
= listing
;
5371 s
->no_warnings
= flag_no_warnings
;
5373 s
->next
= save_stack
;
5376 demand_empty_rest_of_line ();
5379 /* The MRI RESTORE pseudo-op. */
5385 struct save_opts
*s
;
5387 if (save_stack
== NULL
)
5389 as_bad (_("restore without save"));
5390 ignore_rest_of_line ();
5395 save_stack
= s
->next
;
5397 m68k_abspcadd
= s
->abspcadd
;
5398 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5399 flag_keep_locals
= s
->keep_locals
;
5400 flag_short_refs
= s
->short_refs
;
5401 current_architecture
= s
->architecture
;
5402 m68k_quick
= s
->quick
;
5403 m68k_rel32
= s
->rel32
;
5404 listing
= s
->listing
;
5405 flag_no_warnings
= s
->no_warnings
;
5409 demand_empty_rest_of_line ();
5412 /* Types of MRI structured control directives. */
5414 enum mri_control_type
5422 /* This structure is used to stack the MRI structured control
5425 struct mri_control_info
5427 /* The directive within which this one is enclosed. */
5428 struct mri_control_info
*outer
;
5430 /* The type of directive. */
5431 enum mri_control_type type
;
5433 /* Whether an ELSE has been in an IF. */
5436 /* The add or sub statement at the end of a FOR. */
5439 /* The label of the top of a FOR or REPEAT loop. */
5442 /* The label to jump to for the next iteration, or the else
5443 expression of a conditional. */
5446 /* The label to jump to to break out of the loop, or the label past
5447 the end of a conditional. */
5451 /* The stack of MRI structured control directives. */
5453 static struct mri_control_info
*mri_control_stack
;
5455 /* The current MRI structured control directive index number, used to
5456 generate label names. */
5458 static int mri_control_index
;
5460 /* Some function prototypes. */
5462 static void mri_assemble
PARAMS ((char *));
5463 static char *mri_control_label
PARAMS ((void));
5464 static struct mri_control_info
*push_mri_control
5465 PARAMS ((enum mri_control_type
));
5466 static void pop_mri_control
PARAMS ((void));
5467 static int parse_mri_condition
PARAMS ((int *));
5468 static int parse_mri_control_operand
5469 PARAMS ((int *, char **, char **, char **, char **));
5470 static int swap_mri_condition
PARAMS ((int));
5471 static int reverse_mri_condition
PARAMS ((int));
5472 static void build_mri_control_operand
5473 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5474 const char *, int));
5475 static void parse_mri_control_expression
5476 PARAMS ((char *, int, const char *, const char *, int));
5478 /* Assemble an instruction for an MRI structured control directive. */
5486 /* md_assemble expects the opcode to be in lower case. */
5487 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
5489 if (isupper ((unsigned char) *s
))
5490 *s
= tolower ((unsigned char) *s
);
5496 /* Generate a new MRI label structured control directive label name. */
5499 mri_control_label ()
5503 n
= (char *) xmalloc (20);
5504 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5505 ++mri_control_index
;
5509 /* Create a new MRI structured control directive. */
5511 static struct mri_control_info
*
5512 push_mri_control (type
)
5513 enum mri_control_type type
;
5515 struct mri_control_info
*n
;
5517 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5521 if (type
== mri_if
|| type
== mri_while
)
5524 n
->top
= mri_control_label ();
5525 n
->next
= mri_control_label ();
5526 n
->bottom
= mri_control_label ();
5528 n
->outer
= mri_control_stack
;
5529 mri_control_stack
= n
;
5534 /* Pop off the stack of MRI structured control directives. */
5539 struct mri_control_info
*n
;
5541 n
= mri_control_stack
;
5542 mri_control_stack
= n
->outer
;
5550 /* Recognize a condition code in an MRI structured control expression. */
5553 parse_mri_condition (pcc
)
5558 know (*input_line_pointer
== '<');
5560 ++input_line_pointer
;
5561 c1
= *input_line_pointer
++;
5562 c2
= *input_line_pointer
++;
5564 if (*input_line_pointer
!= '>')
5566 as_bad (_("syntax error in structured control directive"));
5570 ++input_line_pointer
;
5578 *pcc
= (c1
<< 8) | c2
;
5583 /* Parse a single operand in an MRI structured control expression. */
5586 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
5603 if (*input_line_pointer
== '<')
5605 /* It's just a condition code. */
5606 return parse_mri_condition (pcc
);
5609 /* Look ahead for the condition code. */
5610 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5612 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5617 as_bad (_("missing condition code in structured control directive"));
5621 *leftstart
= input_line_pointer
;
5623 if (*leftstop
> *leftstart
5624 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5627 input_line_pointer
= s
;
5628 if (! parse_mri_condition (pcc
))
5631 /* Look ahead for AND or OR or end of line. */
5632 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5634 if ((strncasecmp (s
, "AND", 3) == 0
5635 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5636 || (strncasecmp (s
, "OR", 2) == 0
5637 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
5641 *rightstart
= input_line_pointer
;
5643 if (*rightstop
> *rightstart
5644 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
5647 input_line_pointer
= s
;
5652 #define MCC(b1, b2) (((b1) << 8) | (b2))
5654 /* Swap the sense of a condition. This changes the condition so that
5655 it generates the same result when the operands are swapped. */
5658 swap_mri_condition (cc
)
5663 case MCC ('h', 'i'): return MCC ('c', 's');
5664 case MCC ('l', 's'): return MCC ('c', 'c');
5665 case MCC ('c', 'c'): return MCC ('l', 's');
5666 case MCC ('c', 's'): return MCC ('h', 'i');
5667 case MCC ('p', 'l'): return MCC ('m', 'i');
5668 case MCC ('m', 'i'): return MCC ('p', 'l');
5669 case MCC ('g', 'e'): return MCC ('l', 'e');
5670 case MCC ('l', 't'): return MCC ('g', 't');
5671 case MCC ('g', 't'): return MCC ('l', 't');
5672 case MCC ('l', 'e'): return MCC ('g', 'e');
5677 /* Reverse the sense of a condition. */
5680 reverse_mri_condition (cc
)
5685 case MCC ('h', 'i'): return MCC ('l', 's');
5686 case MCC ('l', 's'): return MCC ('h', 'i');
5687 case MCC ('c', 'c'): return MCC ('c', 's');
5688 case MCC ('c', 's'): return MCC ('c', 'c');
5689 case MCC ('n', 'e'): return MCC ('e', 'q');
5690 case MCC ('e', 'q'): return MCC ('n', 'e');
5691 case MCC ('v', 'c'): return MCC ('v', 's');
5692 case MCC ('v', 's'): return MCC ('v', 'c');
5693 case MCC ('p', 'l'): return MCC ('m', 'i');
5694 case MCC ('m', 'i'): return MCC ('p', 'l');
5695 case MCC ('g', 'e'): return MCC ('l', 't');
5696 case MCC ('l', 't'): return MCC ('g', 'e');
5697 case MCC ('g', 't'): return MCC ('l', 'e');
5698 case MCC ('l', 'e'): return MCC ('g', 't');
5703 /* Build an MRI structured control expression. This generates test
5704 and branch instructions. It goes to TRUELAB if the condition is
5705 true, and to FALSELAB if the condition is false. Exactly one of
5706 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5707 is the size qualifier for the expression. EXTENT is the size to
5708 use for the branch. */
5711 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5712 rightstop
, truelab
, falselab
, extent
)
5719 const char *truelab
;
5720 const char *falselab
;
5726 if (leftstart
!= NULL
)
5728 struct m68k_op leftop
, rightop
;
5731 /* Swap the compare operands, if necessary, to produce a legal
5732 m68k compare instruction. Comparing a register operand with
5733 a non-register operand requires the register to be on the
5734 right (cmp, cmpa). Comparing an immediate value with
5735 anything requires the immediate value to be on the left
5740 (void) m68k_ip_op (leftstart
, &leftop
);
5745 (void) m68k_ip_op (rightstart
, &rightop
);
5748 if (rightop
.mode
== IMMED
5749 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
5750 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
5754 cc
= swap_mri_condition (cc
);
5756 leftstart
= rightstart
;
5759 leftstop
= rightstop
;
5764 if (truelab
== NULL
)
5766 cc
= reverse_mri_condition (cc
);
5770 if (leftstart
!= NULL
)
5772 buf
= (char *) xmalloc (20
5773 + (leftstop
- leftstart
)
5774 + (rightstop
- rightstart
));
5782 memcpy (s
, leftstart
, leftstop
- leftstart
);
5783 s
+= leftstop
- leftstart
;
5785 memcpy (s
, rightstart
, rightstop
- rightstart
);
5786 s
+= rightstop
- rightstart
;
5792 buf
= (char *) xmalloc (20 + strlen (truelab
));
5800 strcpy (s
, truelab
);
5805 /* Parse an MRI structured control expression. This generates test
5806 and branch instructions. STOP is where the expression ends. It
5807 goes to TRUELAB if the condition is true, and to FALSELAB if the
5808 condition is false. Exactly one of TRUELAB and FALSELAB will be
5809 NULL, meaning to fall through. QUAL is the size qualifier for the
5810 expression. EXTENT is the size to use for the branch. */
5813 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
5816 const char *truelab
;
5817 const char *falselab
;
5830 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5831 &rightstart
, &rightstop
))
5837 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5841 if (falselab
!= NULL
)
5844 flab
= mri_control_label ();
5846 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5847 rightstop
, (const char *) NULL
, flab
, extent
);
5849 input_line_pointer
+= 3;
5850 if (*input_line_pointer
!= '.'
5851 || input_line_pointer
[1] == '\0')
5855 qual
= input_line_pointer
[1];
5856 input_line_pointer
+= 2;
5859 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5860 &rightstart
, &rightstop
))
5866 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5867 rightstop
, truelab
, falselab
, extent
);
5869 if (falselab
== NULL
)
5872 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5876 if (truelab
!= NULL
)
5879 tlab
= mri_control_label ();
5881 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5882 rightstop
, tlab
, (const char *) NULL
, extent
);
5884 input_line_pointer
+= 2;
5885 if (*input_line_pointer
!= '.'
5886 || input_line_pointer
[1] == '\0')
5890 qual
= input_line_pointer
[1];
5891 input_line_pointer
+= 2;
5894 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5895 &rightstart
, &rightstop
))
5901 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5902 rightstop
, truelab
, falselab
, extent
);
5904 if (truelab
== NULL
)
5909 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5910 rightstop
, truelab
, falselab
, extent
);
5914 if (input_line_pointer
!= stop
)
5915 as_bad (_("syntax error in structured control directive"));
5918 /* Handle the MRI IF pseudo-op. This may be a structured control
5919 directive, or it may be a regular assembler conditional, depending
5928 struct mri_control_info
*n
;
5930 /* A structured control directive must end with THEN with an
5931 optional qualifier. */
5932 s
= input_line_pointer
;
5933 while (! is_end_of_line
[(unsigned char) *s
]
5934 && (! flag_mri
|| *s
!= '*'))
5937 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5940 if (s
- input_line_pointer
> 1
5944 if (s
- input_line_pointer
< 3
5945 || strncasecmp (s
- 3, "THEN", 4) != 0)
5949 as_bad (_("missing then"));
5950 ignore_rest_of_line ();
5954 /* It's a conditional. */
5959 /* Since this might be a conditional if, this pseudo-op will be
5960 called even if we are supported to be ignoring input. Double
5961 check now. Clobber *input_line_pointer so that ignore_input
5962 thinks that this is not a special pseudo-op. */
5963 c
= *input_line_pointer
;
5964 *input_line_pointer
= 0;
5965 if (ignore_input ())
5967 *input_line_pointer
= c
;
5968 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5969 ++input_line_pointer
;
5970 demand_empty_rest_of_line ();
5973 *input_line_pointer
= c
;
5975 n
= push_mri_control (mri_if
);
5977 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5978 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5981 input_line_pointer
= s
+ 3;
5983 input_line_pointer
= s
+ 1;
5987 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5988 ++input_line_pointer
;
5991 demand_empty_rest_of_line ();
5994 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5995 structured IF, associate the ELSE with the IF. Otherwise, assume
5996 it is a conditional else. */
6007 && (mri_control_stack
== NULL
6008 || mri_control_stack
->type
!= mri_if
6009 || mri_control_stack
->else_seen
))
6015 c
= *input_line_pointer
;
6016 *input_line_pointer
= 0;
6017 if (ignore_input ())
6019 *input_line_pointer
= c
;
6020 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6021 ++input_line_pointer
;
6022 demand_empty_rest_of_line ();
6025 *input_line_pointer
= c
;
6027 if (mri_control_stack
== NULL
6028 || mri_control_stack
->type
!= mri_if
6029 || mri_control_stack
->else_seen
)
6031 as_bad (_("else without matching if"));
6032 ignore_rest_of_line ();
6036 mri_control_stack
->else_seen
= 1;
6038 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6041 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6045 colon (mri_control_stack
->next
);
6049 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6050 ++input_line_pointer
;
6053 demand_empty_rest_of_line ();
6056 /* Handle the MRI ENDI pseudo-op. */
6062 if (mri_control_stack
== NULL
6063 || mri_control_stack
->type
!= mri_if
)
6065 as_bad (_("endi without matching if"));
6066 ignore_rest_of_line ();
6070 /* ignore_input will not return true for ENDI, so we don't need to
6071 worry about checking it again here. */
6073 if (! mri_control_stack
->else_seen
)
6074 colon (mri_control_stack
->next
);
6075 colon (mri_control_stack
->bottom
);
6081 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6082 ++input_line_pointer
;
6085 demand_empty_rest_of_line ();
6088 /* Handle the MRI BREAK pseudo-op. */
6091 s_mri_break (extent
)
6094 struct mri_control_info
*n
;
6098 n
= mri_control_stack
;
6100 && n
->type
!= mri_for
6101 && n
->type
!= mri_repeat
6102 && n
->type
!= mri_while
)
6106 as_bad (_("break outside of structured loop"));
6107 ignore_rest_of_line ();
6111 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6114 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6120 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6121 ++input_line_pointer
;
6124 demand_empty_rest_of_line ();
6127 /* Handle the MRI NEXT pseudo-op. */
6133 struct mri_control_info
*n
;
6137 n
= mri_control_stack
;
6139 && n
->type
!= mri_for
6140 && n
->type
!= mri_repeat
6141 && n
->type
!= mri_while
)
6145 as_bad (_("next outside of structured loop"));
6146 ignore_rest_of_line ();
6150 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6153 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6159 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6160 ++input_line_pointer
;
6163 demand_empty_rest_of_line ();
6166 /* Handle the MRI FOR pseudo-op. */
6172 const char *varstart
, *varstop
;
6173 const char *initstart
, *initstop
;
6174 const char *endstart
, *endstop
;
6175 const char *bystart
, *bystop
;
6179 struct mri_control_info
*n
;
6185 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6189 varstart
= input_line_pointer
;
6191 /* Look for the '='. */
6192 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6193 && *input_line_pointer
!= '=')
6194 ++input_line_pointer
;
6195 if (*input_line_pointer
!= '=')
6197 as_bad (_("missing ="));
6198 ignore_rest_of_line ();
6202 varstop
= input_line_pointer
;
6203 if (varstop
> varstart
6204 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6207 ++input_line_pointer
;
6209 initstart
= input_line_pointer
;
6211 /* Look for TO or DOWNTO. */
6214 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6216 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6217 && ! is_part_of_name (input_line_pointer
[2]))
6219 initstop
= input_line_pointer
;
6220 input_line_pointer
+= 2;
6223 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6224 && ! is_part_of_name (input_line_pointer
[6]))
6226 initstop
= input_line_pointer
;
6228 input_line_pointer
+= 6;
6231 ++input_line_pointer
;
6233 if (initstop
== NULL
)
6235 as_bad (_("missing to or downto"));
6236 ignore_rest_of_line ();
6239 if (initstop
> initstart
6240 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6244 endstart
= input_line_pointer
;
6246 /* Look for BY or DO. */
6249 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6251 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6252 && ! is_part_of_name (input_line_pointer
[2]))
6254 endstop
= input_line_pointer
;
6256 input_line_pointer
+= 2;
6259 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6260 && (input_line_pointer
[2] == '.'
6261 || ! is_part_of_name (input_line_pointer
[2])))
6263 endstop
= input_line_pointer
;
6264 input_line_pointer
+= 2;
6267 ++input_line_pointer
;
6269 if (endstop
== NULL
)
6271 as_bad (_("missing do"));
6272 ignore_rest_of_line ();
6275 if (endstop
> endstart
6276 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6282 bystop
= bystart
+ 2;
6287 bystart
= input_line_pointer
;
6291 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6293 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6294 && (input_line_pointer
[2] == '.'
6295 || ! is_part_of_name (input_line_pointer
[2])))
6297 bystop
= input_line_pointer
;
6298 input_line_pointer
+= 2;
6301 ++input_line_pointer
;
6305 as_bad (_("missing do"));
6306 ignore_rest_of_line ();
6309 if (bystop
> bystart
6310 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6314 if (*input_line_pointer
!= '.')
6318 extent
= input_line_pointer
[1];
6319 input_line_pointer
+= 2;
6322 /* We have fully parsed the FOR operands. Now build the loop. */
6324 n
= push_mri_control (mri_for
);
6326 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6337 memcpy (s
, initstart
, initstop
- initstart
);
6338 s
+= initstop
- initstart
;
6340 memcpy (s
, varstart
, varstop
- varstart
);
6341 s
+= varstop
- varstart
;
6355 memcpy (s
, endstart
, endstop
- endstart
);
6356 s
+= endstop
- endstart
;
6358 memcpy (s
, varstart
, varstop
- varstart
);
6359 s
+= varstop
- varstart
;
6367 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6369 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6372 /* Put together the add or sub instruction used by ENDF. */
6382 memcpy (s
, bystart
, bystop
- bystart
);
6383 s
+= bystop
- bystart
;
6385 memcpy (s
, varstart
, varstop
- varstart
);
6386 s
+= varstop
- varstart
;
6392 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6393 ++input_line_pointer
;
6396 demand_empty_rest_of_line ();
6399 /* Handle the MRI ENDF pseudo-op. */
6405 if (mri_control_stack
== NULL
6406 || mri_control_stack
->type
!= mri_for
)
6408 as_bad (_("endf without for"));
6409 ignore_rest_of_line ();
6413 colon (mri_control_stack
->next
);
6415 mri_assemble (mri_control_stack
->incr
);
6417 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6418 mri_assemble (mri_control_stack
->incr
);
6420 free (mri_control_stack
->incr
);
6422 colon (mri_control_stack
->bottom
);
6428 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6429 ++input_line_pointer
;
6432 demand_empty_rest_of_line ();
6435 /* Handle the MRI REPEAT pseudo-op. */
6438 s_mri_repeat (ignore
)
6441 struct mri_control_info
*n
;
6443 n
= push_mri_control (mri_repeat
);
6447 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6448 ++input_line_pointer
;
6450 demand_empty_rest_of_line ();
6453 /* Handle the MRI UNTIL pseudo-op. */
6461 if (mri_control_stack
== NULL
6462 || mri_control_stack
->type
!= mri_repeat
)
6464 as_bad (_("until without repeat"));
6465 ignore_rest_of_line ();
6469 colon (mri_control_stack
->next
);
6471 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6474 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6475 mri_control_stack
->top
, '\0');
6477 colon (mri_control_stack
->bottom
);
6479 input_line_pointer
= s
;
6485 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6486 ++input_line_pointer
;
6489 demand_empty_rest_of_line ();
6492 /* Handle the MRI WHILE pseudo-op. */
6500 struct mri_control_info
*n
;
6502 s
= input_line_pointer
;
6503 while (! is_end_of_line
[(unsigned char) *s
]
6504 && (! flag_mri
|| *s
!= '*'))
6507 while (*s
== ' ' || *s
== '\t')
6509 if (s
- input_line_pointer
> 1
6512 if (s
- input_line_pointer
< 2
6513 || strncasecmp (s
- 1, "DO", 2) != 0)
6515 as_bad (_("missing do"));
6516 ignore_rest_of_line ();
6520 n
= push_mri_control (mri_while
);
6524 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6525 s
[1] == '.' ? s
[2] : '\0');
6527 input_line_pointer
= s
+ 1;
6528 if (*input_line_pointer
== '.')
6529 input_line_pointer
+= 2;
6533 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6534 ++input_line_pointer
;
6537 demand_empty_rest_of_line ();
6540 /* Handle the MRI ENDW pseudo-op. */
6548 if (mri_control_stack
== NULL
6549 || mri_control_stack
->type
!= mri_while
)
6551 as_bad (_("endw without while"));
6552 ignore_rest_of_line ();
6556 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6557 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6561 colon (mri_control_stack
->bottom
);
6567 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6568 ++input_line_pointer
;
6571 demand_empty_rest_of_line ();
6576 * Invocation line includes a switch not recognized by the base assembler.
6577 * See if it's a processor-specific option. These are:
6579 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6580 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6581 * Select the architecture. Instructions or features not
6582 * supported by the selected architecture cause fatal
6583 * errors. More than one may be specified. The default is
6584 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6585 * for -m68000, and -m68882 is a synonym for -m68881.
6586 * -[A]m[c]no-68851, -[A]m[c]no-68881
6587 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6588 * so don't use or document it, but that's the way the parsing
6591 * -pic Indicates PIC.
6592 * -k Indicates PIC. (Sun 3 only.)
6595 * Permit `|' to be used in expressions.
6600 CONST
char *md_shortopts
= "lSA:m:kQ:V";
6602 CONST
char *md_shortopts
= "lSA:m:k";
6605 struct option md_longopts
[] = {
6606 #define OPTION_PIC (OPTION_MD_BASE)
6607 {"pic", no_argument
, NULL
, OPTION_PIC
},
6608 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6609 {"register-prefix-optional", no_argument
, NULL
,
6610 OPTION_REGISTER_PREFIX_OPTIONAL
},
6611 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6612 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
6613 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6614 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
6615 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6616 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
6617 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6618 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
6619 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6620 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
6621 {NULL
, no_argument
, NULL
, 0}
6623 size_t md_longopts_size
= sizeof(md_longopts
);
6626 md_parse_option (c
, arg
)
6632 case 'l': /* -l means keep external to 2 bit offset
6633 rather than 16 bit one */
6634 flag_short_refs
= 1;
6637 case 'S': /* -S means that jbsr's always turn into
6639 flag_long_jumps
= 1;
6645 /* intentional fall-through */
6648 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
6652 const char *oarg
= arg
;
6658 if (arg
[0] == 'c' && arg
[1] == '6')
6661 for (i
= 0; i
< n_archs
; i
++)
6662 if (!strcmp (arg
, archs
[i
].name
))
6667 as_bad (_("unrecognized option `%s'"), oarg
);
6670 arch
= archs
[i
].arch
;
6673 else if (arch
== m68851
)
6682 if (arg
[0] == 'c' && arg
[1] == '6')
6685 for (i
= 0; i
< n_archs
; i
++)
6686 if (!strcmp (arg
, archs
[i
].name
))
6688 unsigned long arch
= archs
[i
].arch
;
6689 if (cpu_of_arch (arch
))
6690 /* It's a cpu spec. */
6692 current_architecture
&= ~m68000up
;
6693 current_architecture
|= arch
;
6695 else if (arch
== m68881
)
6697 current_architecture
|= m68881
;
6700 else if (arch
== m68851
)
6702 current_architecture
|= m68851
;
6712 as_bad (_("unrecognized architecture specification `%s'"), arg
);
6721 break; /* -pic, Position Independent Code */
6723 case OPTION_REGISTER_PREFIX_OPTIONAL
:
6724 flag_reg_prefix_optional
= 1;
6725 reg_prefix_optional_seen
= 1;
6728 /* -V: SVR4 argument to print version ID. */
6730 print_version_id ();
6733 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6734 should be emitted or not. FIXME: Not implemented. */
6738 case OPTION_BITWISE_OR
:
6743 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
6745 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
6749 m68k_comment_chars
= n
;
6753 case OPTION_BASE_SIZE_DEFAULT_16
:
6754 m68k_index_width_default
= SIZE_WORD
;
6757 case OPTION_BASE_SIZE_DEFAULT_32
:
6758 m68k_index_width_default
= SIZE_LONG
;
6761 case OPTION_DISP_SIZE_DEFAULT_16
:
6763 m68k_rel32_from_cmdline
= 1;
6766 case OPTION_DISP_SIZE_DEFAULT_32
:
6768 m68k_rel32_from_cmdline
= 1;
6779 md_show_usage (stream
)
6782 fprintf(stream
, _("\
6784 -l use 1 word for refs to undefined symbols [default 2]\n\
6785 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
6786 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
6787 | -mcpu32 | -m5200\n\
6788 specify variant of 680X0 architecture [default 68020]\n\
6789 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6790 target has/lacks floating-point coprocessor\n\
6791 [default yes for 68020, 68030, and cpu32]\n"));
6792 fprintf(stream
, _("\
6793 -m68851 | -mno-68851\n\
6794 target has/lacks memory-management unit coprocessor\n\
6795 [default yes for 68020 and up]\n\
6796 -pic, -k generate position independent code\n\
6797 -S turn jbsr into jsr\n\
6798 --register-prefix-optional\n\
6799 recognize register names without prefix character\n\
6800 --bitwise-or do not treat `|' as a comment character\n"));
6801 fprintf (stream
, _("\
6802 --base-size-default-16 base reg without size is 16 bits\n\
6803 --base-size-default-32 base reg without size is 32 bits (default)\n\
6804 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6805 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
6810 /* TEST2: Test md_assemble() */
6811 /* Warning, this routine probably doesn't work anymore */
6815 struct m68k_it the_ins
;
6823 if (!gets (buf
) || !*buf
)
6825 if (buf
[0] == '|' || buf
[1] == '.')
6827 for (cp
= buf
; *cp
; cp
++)
6832 memset (&the_ins
, '\0', sizeof (the_ins
));
6833 m68k_ip (&the_ins
, buf
);
6836 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
6840 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
6841 for (n
= 0; n
< the_ins
.numo
; n
++)
6842 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
6844 print_the_insn (&the_ins
.opcode
[0], stdout
);
6845 (void) putchar ('\n');
6847 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
6849 if (the_ins
.operands
[n
].error
)
6851 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
6854 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
6855 if (the_ins
.operands
[n
].b_const
)
6856 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
6857 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
6858 if (the_ins
.operands
[n
].b_iadd
)
6859 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
6860 (void) putchar ('\n');
6872 while (*str
&& *str
!= ' ')
6874 if (str
[-1] == ':' || str
[1] == '=')
6881 /* Possible states for relaxation:
6883 0 0 branch offset byte (bra, etc)
6887 1 0 indexed offsets byte a0@(32,d4:w:1) etc
6891 2 0 two-offset index word-word a0@(32,d4)@(45) etc
6898 /* We have no need to default values of symbols. */
6902 md_undefined_symbol (name
)
6908 /* Round up a section size to the appropriate boundary. */
6910 md_section_align (segment
, size
)
6915 #ifdef BFD_ASSEMBLER
6916 /* For a.out, force the section size to be aligned. If we don't do
6917 this, BFD will align it for us, but it will not write out the
6918 final bytes of the section. This may be a bug in BFD, but it is
6919 easier to fix it here since that is how the other a.out targets
6923 align
= bfd_get_section_alignment (stdoutput
, segment
);
6924 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
6931 /* Exactly what point is a PC-relative offset relative TO?
6932 On the 68k, it is relative to the address of the first extension
6933 word. The difference between the addresses of the offset and the
6934 first extension word is stored in fx_pcrel_adjust. */
6936 md_pcrel_from (fixP
)
6941 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
6943 adjust
= fixP
->fx_pcrel_adjust
;
6946 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
6949 #ifndef BFD_ASSEMBLER
6954 tc_coff_symbol_emit_hook (ignore
)
6960 tc_coff_sizemachdep (frag
)
6963 switch (frag
->fr_subtype
& 0x3)
6980 /* end of tc-m68k.c */