1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "safe-ctype.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "opcode/m68k.h"
31 #include "m68k-parse.h"
42 static void m68k_elf_cons (int);
45 /* This string holds the chars that always start a comment. If the
46 pre-processor is disabled, these aren't very useful. The macro
47 tc_comment_chars points to this. We use this, rather than the
48 usual comment_chars, so that the --bitwise-or option will work. */
49 #if defined (TE_SVR4) || defined (TE_DELTA)
50 const char *m68k_comment_chars
= "|#";
52 const char *m68k_comment_chars
= "|";
55 /* This array holds the chars that only start a comment at the beginning of
56 a line. If the line seems to have the form '# 123 filename'
57 .line and .file directives will appear in the pre-processed output */
58 /* Note that input_file.c hand checks for '#' at the beginning of the
59 first line of the input file. This is because the compiler outputs
60 #NO_APP at the beginning of its output. */
61 /* Also note that comments like this one will always work. */
62 const char line_comment_chars
[] = "#*";
64 const char line_separator_chars
[] = ";";
66 /* Chars that can be used to separate mant from exp in floating point nums. */
67 const char EXP_CHARS
[] = "eE";
69 /* Chars that mean this number is a floating point constant, as
70 in "0f12.456" or "0d1.2345e12". */
72 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
74 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
75 changed in read.c . Ideally it shouldn't have to know about it at all,
76 but nothing is ideal around here. */
78 /* Are we trying to generate PIC code? If so, absolute references
79 ought to be made into linkage table references or pc-relative
80 references. Not implemented. For ELF there are other means
81 to denote pic relocations. */
84 static int flag_short_refs
; /* -l option. */
85 static int flag_long_jumps
; /* -S option. */
86 static int flag_keep_pcrel
; /* --pcrel option. */
88 #ifdef REGISTER_PREFIX_OPTIONAL
89 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
91 int flag_reg_prefix_optional
;
94 /* Whether --register-prefix-optional was used on the command line. */
95 static int reg_prefix_optional_seen
;
97 /* The floating point coprocessor to use by default. */
98 static enum m68k_register m68k_float_copnum
= COP1
;
100 /* If this is non-zero, then references to number(%pc) will be taken
101 to refer to number, rather than to %pc + number. */
102 static int m68k_abspcadd
;
104 /* If this is non-zero, then the quick forms of the move, add, and sub
105 instructions are used when possible. */
106 static int m68k_quick
= 1;
108 /* If this is non-zero, then if the size is not specified for a base
109 or outer displacement, the assembler assumes that the size should
111 static int m68k_rel32
= 1;
113 /* This is non-zero if m68k_rel32 was set from the command line. */
114 static int m68k_rel32_from_cmdline
;
116 /* The default width to use for an index register when using a base
118 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
120 /* We want to warn if any text labels are misaligned. In order to get
121 the right line number, we need to record the line number for each
125 struct label_line
*next
;
132 /* The list of labels. */
134 static struct label_line
*labels
;
136 /* The current label. */
138 static struct label_line
*current_label
;
140 /* Pointer to list holding the opcodes sorted by name. */
141 static struct m68k_opcode
const ** m68k_sorted_opcodes
;
143 /* Its an arbitrary name: This means I don't approve of it.
145 static struct obstack robyn
;
149 const char *m_operands
;
150 unsigned long m_opcode
;
154 struct m68k_incant
*m_next
;
157 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
158 #define gettwo(x) (((x)->m_opcode)&0xffff)
160 static const enum m68k_register m68000_ctrl
[] = { 0 };
161 static const enum m68k_register m68010_ctrl
[] = {
165 static const enum m68k_register m68020_ctrl
[] = {
166 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
169 static const enum m68k_register m68040_ctrl
[] = {
170 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
171 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
174 static const enum m68k_register m68060_ctrl
[] = {
175 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
176 USP
, VBR
, URP
, SRP
, PCR
,
179 static const enum m68k_register mcf_ctrl
[] = {
180 CACR
, TC
, ACR0
, ACR1
, ACR2
, ACR3
, VBR
, ROMBAR
,
181 RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
,
184 static const enum m68k_register mcf51_ctrl
[] = {
188 static const enum m68k_register mcf5206_ctrl
[] = {
189 CACR
, ACR0
, ACR1
, VBR
, RAMBAR0
, RAMBAR_ALT
, MBAR
,
192 static const enum m68k_register mcf5208_ctrl
[] = {
193 CACR
, ACR0
, ACR1
, VBR
, RAMBAR
, RAMBAR1
,
196 static const enum m68k_register mcf5210a_ctrl
[] = {
197 VBR
, CACR
, ACR0
, ACR1
, ROMBAR
, RAMBAR
, RAMBAR1
, MBAR
,
200 static const enum m68k_register mcf5213_ctrl
[] = {
201 VBR
, RAMBAR
, RAMBAR1
, FLASHBAR
,
204 static const enum m68k_register mcf5216_ctrl
[] = {
205 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
208 static const enum m68k_register mcf52223_ctrl
[] = {
209 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
212 static const enum m68k_register mcf52235_ctrl
[] = {
213 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
216 static const enum m68k_register mcf5225_ctrl
[] = {
217 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, MBAR
, RAMBAR1
,
220 static const enum m68k_register mcf52259_ctrl
[] = {
221 VBR
, FLASHBAR
, RAMBAR
, RAMBAR1
,
224 static const enum m68k_register mcf52277_ctrl
[] = {
225 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
228 static const enum m68k_register mcf5235_ctrl
[] = {
229 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
232 static const enum m68k_register mcf5249_ctrl
[] = {
233 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
, MBAR2
,
236 static const enum m68k_register mcf5250_ctrl
[] = {
240 static const enum m68k_register mcf5253_ctrl
[] = {
241 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
, MBAR2
,
244 static const enum m68k_register mcf5271_ctrl
[] = {
245 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
248 static const enum m68k_register mcf5272_ctrl
[] = {
249 VBR
, CACR
, ACR0
, ACR1
, ROMBAR
, RAMBAR_ALT
, RAMBAR0
, MBAR
,
252 static const enum m68k_register mcf5275_ctrl
[] = {
253 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
256 static const enum m68k_register mcf5282_ctrl
[] = {
257 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
260 static const enum m68k_register mcf53017_ctrl
[] = {
261 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR
,
264 static const enum m68k_register mcf5307_ctrl
[] = {
265 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR_ALT
, MBAR
,
268 static const enum m68k_register mcf5329_ctrl
[] = {
269 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
272 static const enum m68k_register mcf5373_ctrl
[] = {
273 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
276 static const enum m68k_register mcfv4e_ctrl
[] = {
277 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
278 VBR
, PC
, ROMBAR0
, ROMBAR1
, RAMBAR0
, RAMBAR1
,
280 MPCR
/* Multiprocessor Control register */,
281 EDRAMBAR
/* Embedded DRAM Base Address Register */,
282 /* Permutation control registers. */
283 PCR1U0
, PCR1L0
, PCR1U1
, PCR1L1
, PCR2U0
, PCR2L0
, PCR2U1
, PCR2L1
,
284 PCR3U0
, PCR3L0
, PCR3U1
, PCR3L1
,
286 TC
/* ASID */, BUSCR
/* MMUBAR */,
287 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
288 MBAR1
/* MBAR */, MBAR2
/* SECMBAR */, MBAR0
/* SECMBAR */,
289 ROMBAR
/* ROMBAR0 */, RAMBAR
/* RAMBAR1 */,
292 static const enum m68k_register mcf5407_ctrl
[] = {
293 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
,
294 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
297 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
298 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
301 static const enum m68k_register mcf54455_ctrl
[] = {
302 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
303 VBR
, PC
, RAMBAR1
, MBAR
,
305 TC
/* ASID */, BUSCR
/* MMUBAR */,
306 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
307 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
310 static const enum m68k_register mcf5475_ctrl
[] = {
311 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
312 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
314 TC
/* ASID */, BUSCR
/* MMUBAR */,
315 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
316 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
319 static const enum m68k_register mcf5485_ctrl
[] = {
320 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
321 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
323 TC
/* ASID */, BUSCR
/* MMUBAR */,
324 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
325 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
328 static const enum m68k_register fido_ctrl
[] = {
329 SFC
, DFC
, USP
, VBR
, CAC
, MBO
,
332 #define cpu32_ctrl m68010_ctrl
334 static const enum m68k_register
*control_regs
;
336 /* Internal form of a 68020 instruction. */
340 const char *args
; /* List of opcode info. */
343 int numo
; /* Number of shorts in opcode. */
346 struct m68k_op operands
[6];
348 int nexp
; /* Number of exprs in use. */
349 struct m68k_exp exprs
[4];
351 int nfrag
; /* Number of frags we have to produce. */
354 int fragoff
; /* Where in the current opcode the frag ends. */
361 int nrel
; /* Num of reloc strucs in use. */
368 /* In a pc relative address the difference between the address
369 of the offset and the address that the offset is relative
370 to. This depends on the addressing mode. Basically this
371 is the value to put in the offset field to address the
372 first byte of the offset, without regarding the special
373 significance of some values (in the branch instruction, for
377 /* Whether this expression needs special pic relocation, and if
379 enum pic_relocation pic_reloc
;
382 reloc
[5]; /* Five is enough??? */
385 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a | fido_a))
386 #define float_of_arch(x) ((x) & mfloat)
387 #define mmu_of_arch(x) ((x) & mmmu)
388 #define arch_coldfire_p(x) ((x) & mcfisa_a)
389 #define arch_coldfire_fpu(x) ((x) & cfloat)
391 /* Macros for determining if cpu supports a specific addressing mode. */
392 #define HAVE_LONG_DISP(x) \
393 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
394 #define HAVE_LONG_CALL(x) \
395 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
396 #define HAVE_LONG_COND(x) \
397 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
398 #define HAVE_LONG_BRANCH(x) \
399 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b))
400 #define LONG_BRANCH_VIA_COND(x) (HAVE_LONG_COND(x) && !HAVE_LONG_BRANCH(x))
402 static struct m68k_it the_ins
; /* The instruction being assembled. */
404 #define op(ex) ((ex)->exp.X_op)
405 #define adds(ex) ((ex)->exp.X_add_symbol)
406 #define subs(ex) ((ex)->exp.X_op_symbol)
407 #define offs(ex) ((ex)->exp.X_add_number)
409 /* Macros for adding things to the m68k_it struct. */
410 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
412 /* Like addword, but goes BEFORE general operands. */
415 insop (int w
, const struct m68k_incant
*opcode
)
418 for (z
= the_ins
.numo
; z
> opcode
->m_codenum
; --z
)
419 the_ins
.opcode
[z
] = the_ins
.opcode
[z
- 1];
420 for (z
= 0; z
< the_ins
.nrel
; z
++)
421 the_ins
.reloc
[z
].n
+= 2;
422 for (z
= 0; z
< the_ins
.nfrag
; z
++)
423 the_ins
.fragb
[z
].fragoff
++;
424 the_ins
.opcode
[opcode
->m_codenum
] = w
;
428 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
431 add_fix (int width
, struct m68k_exp
*exp
, int pc_rel
, int pc_fix
)
433 the_ins
.reloc
[the_ins
.nrel
].n
= (width
== 'B' || width
== '3'
434 ? the_ins
.numo
* 2 - 1
436 ? the_ins
.numo
* 2 + 1
437 : the_ins
.numo
* 2));
438 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
439 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
440 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
442 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
444 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
447 /* Cause an extra frag to be generated here, inserting up to 10 bytes
448 (that value is chosen in the frag_var call in md_assemble). TYPE
449 is the subtype of the frag to be generated; its primary type is
450 rs_machine_dependent.
452 The TYPE parameter is also used by md_convert_frag_1 and
453 md_estimate_size_before_relax. The appropriate type of fixup will
454 be emitted by md_convert_frag_1.
456 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
458 add_frag (symbolS
*add
, offsetT off
, int type
)
460 the_ins
.fragb
[the_ins
.nfrag
].fragoff
= the_ins
.numo
;
461 the_ins
.fragb
[the_ins
.nfrag
].fadd
= add
;
462 the_ins
.fragb
[the_ins
.nfrag
].foff
= off
;
463 the_ins
.fragb
[the_ins
.nfrag
++].fragty
= type
;
467 (op (ex) != O_constant && op (ex) != O_big)
469 static char *crack_operand (char *str
, struct m68k_op
*opP
);
470 static int get_num (struct m68k_exp
*exp
, int ok
);
471 static int reverse_16_bits (int in
);
472 static int reverse_8_bits (int in
);
473 static void install_gen_operand (int mode
, int val
);
474 static void install_operand (int mode
, int val
);
475 static void s_bss (int);
476 static void s_data1 (int);
477 static void s_data2 (int);
478 static void s_even (int);
479 static void s_proc (int);
480 static void s_chip (int);
481 static void s_fopt (int);
482 static void s_opt (int);
483 static void s_reg (int);
484 static void s_restore (int);
485 static void s_save (int);
486 static void s_mri_if (int);
487 static void s_mri_else (int);
488 static void s_mri_endi (int);
489 static void s_mri_break (int);
490 static void s_mri_next (int);
491 static void s_mri_for (int);
492 static void s_mri_endf (int);
493 static void s_mri_repeat (int);
494 static void s_mri_until (int);
495 static void s_mri_while (int);
496 static void s_mri_endw (int);
497 static void s_m68k_cpu (int);
498 static void s_m68k_arch (int);
502 unsigned long arch
; /* Architecture features. */
503 const enum m68k_register
*control_regs
; /* Control regs on chip */
504 const char *name
; /* Name */
505 int alias
; /* Alias for a cannonical name. If 1, then
506 succeeds canonical name, if -1 then
507 succeeds canonical name, if <-1 ||>1 this is a
508 deprecated name, and the next/previous name
512 /* We hold flags for features explicitly enabled and explicitly
514 static int current_architecture
;
515 static int not_current_architecture
;
516 static const struct m68k_cpu
*selected_arch
;
517 static const struct m68k_cpu
*selected_cpu
;
518 static int initialized
;
520 /* Architecture models. */
521 static const struct m68k_cpu m68k_archs
[] =
523 {m68000
, m68000_ctrl
, "68000", 0},
524 {m68010
, m68010_ctrl
, "68010", 0},
525 {m68020
|m68881
|m68851
, m68020_ctrl
, "68020", 0},
526 {m68030
|m68881
|m68851
, m68020_ctrl
, "68030", 0},
527 {m68040
, m68040_ctrl
, "68040", 0},
528 {m68060
, m68060_ctrl
, "68060", 0},
529 {cpu32
|m68881
, cpu32_ctrl
, "cpu32", 0},
530 {fido_a
, fido_ctrl
, "fidoa", 0},
531 {mcfisa_a
|mcfhwdiv
, NULL
, "isaa", 0},
532 {mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfusp
, NULL
, "isaaplus", 0},
533 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfusp
, NULL
, "isab", 0},
534 {mcfisa_a
|mcfhwdiv
|mcfisa_c
|mcfusp
, NULL
, "isac", 0},
535 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
|mcfusp
, mcf_ctrl
, "cfv4", 0},
536 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcfv4e_ctrl
, "cfv4e", 0},
540 /* For -mno-mac we want to turn off all types of mac. */
541 static const unsigned no_mac
= mcfmac
| mcfemac
;
543 /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
545 static const struct m68k_cpu m68k_extensions
[] =
547 {m68851
, NULL
, "68851", -1},
548 {m68881
, NULL
, "68881", -1},
549 {m68881
, NULL
, "68882", -1},
551 {cfloat
|m68881
, NULL
, "float", 0},
553 {mcfhwdiv
, NULL
, "div", 1},
554 {mcfusp
, NULL
, "usp", 1},
555 {mcfmac
, (void *)&no_mac
, "mac", 1},
556 {mcfemac
, NULL
, "emac", 1},
562 static const struct m68k_cpu m68k_cpus
[] =
564 {m68000
, m68000_ctrl
, "68000", 0},
565 {m68000
, m68000_ctrl
, "68ec000", 1},
566 {m68000
, m68000_ctrl
, "68hc000", 1},
567 {m68000
, m68000_ctrl
, "68hc001", 1},
568 {m68000
, m68000_ctrl
, "68008", 1},
569 {m68000
, m68000_ctrl
, "68302", 1},
570 {m68000
, m68000_ctrl
, "68306", 1},
571 {m68000
, m68000_ctrl
, "68307", 1},
572 {m68000
, m68000_ctrl
, "68322", 1},
573 {m68000
, m68000_ctrl
, "68356", 1},
574 {m68010
, m68010_ctrl
, "68010", 0},
575 {m68020
|m68881
|m68851
, m68020_ctrl
, "68020", 0},
576 {m68020
|m68881
|m68851
, m68020_ctrl
, "68k", 1},
577 {m68020
|m68881
|m68851
, m68020_ctrl
, "68ec020", 1},
578 {m68030
|m68881
|m68851
, m68020_ctrl
, "68030", 0},
579 {m68030
|m68881
|m68851
, m68020_ctrl
, "68ec030", 1},
580 {m68040
, m68040_ctrl
, "68040", 0},
581 {m68040
, m68040_ctrl
, "68ec040", 1},
582 {m68060
, m68060_ctrl
, "68060", 0},
583 {m68060
, m68060_ctrl
, "68ec060", 1},
585 {cpu32
|m68881
, cpu32_ctrl
, "cpu32", 0},
586 {cpu32
|m68881
, cpu32_ctrl
, "68330", 1},
587 {cpu32
|m68881
, cpu32_ctrl
, "68331", 1},
588 {cpu32
|m68881
, cpu32_ctrl
, "68332", 1},
589 {cpu32
|m68881
, cpu32_ctrl
, "68333", 1},
590 {cpu32
|m68881
, cpu32_ctrl
, "68334", 1},
591 {cpu32
|m68881
, cpu32_ctrl
, "68336", 1},
592 {cpu32
|m68881
, cpu32_ctrl
, "68340", 1},
593 {cpu32
|m68881
, cpu32_ctrl
, "68341", 1},
594 {cpu32
|m68881
, cpu32_ctrl
, "68349", 1},
595 {cpu32
|m68881
, cpu32_ctrl
, "68360", 1},
597 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51", 0},
598 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51ac", 1},
599 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51cn", 1},
600 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfmac
, mcf51_ctrl
, "51em", 1},
601 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51jm", 1},
602 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51qe", 1},
604 {mcfisa_a
, mcf_ctrl
, "5200", 0},
605 {mcfisa_a
, mcf_ctrl
, "5202", 1},
606 {mcfisa_a
, mcf_ctrl
, "5204", 1},
607 {mcfisa_a
, mcf5206_ctrl
, "5206", 1},
609 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5206_ctrl
, "5206e", 0},
611 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5208_ctrl
, "5207", -1},
612 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5208_ctrl
, "5208", 0},
614 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5210a_ctrl
, "5210a", 0},
615 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5210a_ctrl
, "5211a", 1},
617 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5211", -1},
618 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5212", -1},
619 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5213", 0},
621 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "5214", -1},
622 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "5216", 0},
623 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "521x", 2},
625 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf52223_ctrl
, "52221", -1},
626 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf52223_ctrl
, "52223", 0},
628 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52230", -1},
629 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52233", -1},
630 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52234", -1},
631 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52235", 0},
633 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5225_ctrl
, "5224", -1},
634 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5225_ctrl
, "5225", 0},
636 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52277_ctrl
, "52274", -1},
637 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52277_ctrl
, "52277", 0},
639 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5232", -1},
640 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5233", -1},
641 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5234", -1},
642 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5235", -1},
643 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "523x", 0},
645 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5249_ctrl
, "5249", 0},
646 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5250_ctrl
, "5250", 0},
647 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5253_ctrl
, "5253", 0},
649 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52252", -1},
650 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52254", -1},
651 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52255", -1},
652 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52256", -1},
653 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52258", -1},
654 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52259", 0},
656 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5271_ctrl
, "5270", -1},
657 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5271_ctrl
, "5271", 0},
659 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5272_ctrl
, "5272", 0},
661 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5275_ctrl
, "5274", -1},
662 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5275_ctrl
, "5275", 0},
664 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5280", -1},
665 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5281", -1},
666 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5282", -1},
667 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "528x", 0},
669 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53011", -1},
670 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53012", -1},
671 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53013", -1},
672 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53014", -1},
673 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53015", -1},
674 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53016", -1},
675 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53017", 0},
677 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5307_ctrl
, "5307", 0},
679 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5327", -1},
680 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5328", -1},
681 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5329", -1},
682 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "532x", 0},
684 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "5372", -1},
685 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "5373", -1},
686 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "537x", 0},
688 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfmac
, mcf5407_ctrl
, "5407",0},
690 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54450", -1},
691 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54451", -1},
692 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54452", -1},
693 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54453", -1},
694 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54454", -1},
695 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54455", 0},
697 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5470", -1},
698 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5471", -1},
699 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5472", -1},
700 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5473", -1},
701 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5474", -1},
702 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5475", -1},
703 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "547x", 0},
705 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5480", -1},
706 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5481", -1},
707 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5482", -1},
708 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5483", -1},
709 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5484", -1},
710 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5485", -1},
711 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "548x", 0},
713 {fido_a
, fido_ctrl
, "fidoa", 0},
714 {fido_a
, fido_ctrl
, "fido", 1},
719 static const struct m68k_cpu
*m68k_lookup_cpu
720 (const char *, const struct m68k_cpu
*, int, int *);
721 static int m68k_set_arch (const char *, int, int);
722 static int m68k_set_cpu (const char *, int, int);
723 static int m68k_set_extension (const char *, int, int);
724 static void m68k_init_arch (void);
726 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
727 architecture and we have a lot of relaxation modes. */
729 /* Macros used in the relaxation code. */
730 #define TAB(x,y) (((x) << 2) + (y))
731 #define TABTYPE(x) ((x) >> 2)
733 /* Relaxation states. */
739 /* Here are all the relaxation modes we support. First we can relax ordinary
740 branches. On 68020 and higher and on CPU32 all branch instructions take
741 three forms, so on these CPUs all branches always remain as such. When we
742 have to expand to the LONG form on a 68000, though, we substitute an
743 absolute jump instead. This is a direct replacement for unconditional
744 branches and a branch over a jump for conditional branches. However, if the
745 user requires PIC and disables this with --pcrel, we can only relax between
746 BYTE and SHORT forms, punting if that isn't enough. This gives us four
747 different relaxation modes for branches: */
749 #define BRANCHBWL 0 /* Branch byte, word, or long. */
750 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
751 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
752 #define BRANCHBW 3 /* Branch byte or word. */
754 /* We also relax coprocessor branches and DBcc's. All CPUs that support
755 coprocessor branches support them in word and long forms, so we have only
756 one relaxation mode for them. DBcc's are word only on all CPUs. We can
757 relax them to the LONG form with a branch-around sequence. This sequence
758 can use a long branch (if available) or an absolute jump (if acceptable).
759 This gives us two relaxation modes. If long branches are not available and
760 absolute jumps are not acceptable, we don't relax DBcc's. */
762 #define FBRANCH 4 /* Coprocessor branch. */
763 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
764 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
766 /* That's all for instruction relaxation. However, we also relax PC-relative
767 operands. Specifically, we have three operand relaxation modes. On the
768 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
769 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
770 two. Also PC+displacement+index operands in their simple form (with a non-
771 suppressed index without memory indirection) are supported on all CPUs, but
772 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
773 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
774 form of the PC+displacement+index operand. Finally, some absolute operands
775 can be relaxed down to 16-bit PC-relative. */
777 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
778 #define PCINDEX 8 /* PC + displacement + index. */
779 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
781 /* This relaxation is required for branches where there is no long
782 branch and we are in pcrel mode. We generate a bne/beq pair. */
783 #define BRANCHBWPL 10 /* Branch byte, word or pair of longs
786 /* Note that calls to frag_var need to specify the maximum expansion
787 needed; this is currently 12 bytes for bne/beq pair. */
788 #define FRAG_VAR_SIZE 12
791 How far Forward this mode will reach:
792 How far Backward this mode will reach:
793 How many bytes this mode will add to the size of the frag
794 Which mode to go to if the offset won't fit in this one
796 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
797 relax_typeS md_relax_table
[] =
799 { 127, -128, 0, TAB (BRANCHBWL
, SHORT
) },
800 { 32767, -32768, 2, TAB (BRANCHBWL
, LONG
) },
804 { 127, -128, 0, TAB (BRABSJUNC
, SHORT
) },
805 { 32767, -32768, 2, TAB (BRABSJUNC
, LONG
) },
809 { 127, -128, 0, TAB (BRABSJCOND
, SHORT
) },
810 { 32767, -32768, 2, TAB (BRABSJCOND
, LONG
) },
814 { 127, -128, 0, TAB (BRANCHBW
, SHORT
) },
819 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
820 { 32767, -32768, 2, TAB (FBRANCH
, LONG
) },
824 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
825 { 32767, -32768, 2, TAB (DBCCLBR
, LONG
) },
829 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
830 { 32767, -32768, 2, TAB (DBCCABSJ
, LONG
) },
834 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
835 { 32767, -32768, 2, TAB (PCREL1632
, LONG
) },
839 { 125, -130, 0, TAB (PCINDEX
, SHORT
) },
840 { 32765, -32770, 2, TAB (PCINDEX
, LONG
) },
844 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
845 { 32767, -32768, 2, TAB (ABSTOPCREL
, LONG
) },
849 { 127, -128, 0, TAB (BRANCHBWPL
, SHORT
) },
850 { 32767, -32768, 2, TAB (BRANCHBWPL
, LONG
) },
855 /* These are the machine dependent pseudo-ops. These are included so
856 the assembler can work on the output from the SUN C compiler, which
859 /* This table describes all the machine specific pseudo-ops the assembler
860 has to support. The fields are:
861 pseudo-op name without dot
862 function to call to execute this pseudo-op
863 Integer arg to pass to the function. */
864 const pseudo_typeS md_pseudo_table
[] =
866 {"data1", s_data1
, 0},
867 {"data2", s_data2
, 0},
870 {"skip", s_space
, 0},
872 #if defined (TE_SUN3) || defined (OBJ_ELF)
873 {"align", s_align_bytes
, 0},
876 {"swbeg", s_ignore
, 0},
877 {"long", m68k_elf_cons
, 4},
879 {"extend", float_cons
, 'x'},
880 {"ldouble", float_cons
, 'x'},
882 {"arch", s_m68k_arch
, 0},
883 {"cpu", s_m68k_cpu
, 0},
885 /* The following pseudo-ops are supported for MRI compatibility. */
887 {"comline", s_space
, 1},
889 {"mask2", s_ignore
, 0},
892 {"restore", s_restore
, 0},
896 {"if.b", s_mri_if
, 'b'},
897 {"if.w", s_mri_if
, 'w'},
898 {"if.l", s_mri_if
, 'l'},
899 {"else", s_mri_else
, 0},
900 {"else.s", s_mri_else
, 's'},
901 {"else.l", s_mri_else
, 'l'},
902 {"endi", s_mri_endi
, 0},
903 {"break", s_mri_break
, 0},
904 {"break.s", s_mri_break
, 's'},
905 {"break.l", s_mri_break
, 'l'},
906 {"next", s_mri_next
, 0},
907 {"next.s", s_mri_next
, 's'},
908 {"next.l", s_mri_next
, 'l'},
909 {"for", s_mri_for
, 0},
910 {"for.b", s_mri_for
, 'b'},
911 {"for.w", s_mri_for
, 'w'},
912 {"for.l", s_mri_for
, 'l'},
913 {"endf", s_mri_endf
, 0},
914 {"repeat", s_mri_repeat
, 0},
915 {"until", s_mri_until
, 0},
916 {"until.b", s_mri_until
, 'b'},
917 {"until.w", s_mri_until
, 'w'},
918 {"until.l", s_mri_until
, 'l'},
919 {"while", s_mri_while
, 0},
920 {"while.b", s_mri_while
, 'b'},
921 {"while.w", s_mri_while
, 'w'},
922 {"while.l", s_mri_while
, 'l'},
923 {"endw", s_mri_endw
, 0},
928 /* The mote pseudo ops are put into the opcode table, since they
929 don't start with a . they look like opcodes to gas. */
931 const pseudo_typeS mote_pseudo_table
[] =
944 {"xdef", s_globl
, 0},
946 {"align", s_align_bytes
, 0},
948 {"align", s_align_ptwo
, 0},
951 {"sect", obj_coff_section
, 0},
952 {"section", obj_coff_section
, 0},
957 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
958 gives identical results to a 32-bit host. */
959 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
960 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
962 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
963 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
964 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
965 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
967 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
968 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
969 #define islong(x) (1)
971 static char notend_table
[256];
972 static char alt_notend_table
[256];
974 (! (notend_table[(unsigned char) *s] \
976 && alt_notend_table[(unsigned char) s[1]])))
980 /* Return zero if the reference to SYMBOL from within the same segment may
983 /* On an ELF system, we can't relax an externally visible symbol,
984 because it may be overridden by a shared library. However, if
985 TARGET_OS is "elf", then we presume that we are assembling for an
986 embedded system, in which case we don't have to worry about shared
987 libraries, and we can relax any external sym. */
989 #define relaxable_symbol(symbol) \
990 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
991 || S_IS_WEAK (symbol)))
993 /* Compute the relocation code for a fixup of SIZE bytes, using pc
994 relative relocation if PCREL is non-zero. PIC says whether a special
995 pic relocation was requested. */
997 static bfd_reloc_code_real_type
998 get_reloc_code (int size
, int pcrel
, enum pic_relocation pic
)
1006 return BFD_RELOC_8_GOT_PCREL
;
1008 return BFD_RELOC_16_GOT_PCREL
;
1010 return BFD_RELOC_32_GOT_PCREL
;
1018 return BFD_RELOC_8_GOTOFF
;
1020 return BFD_RELOC_16_GOTOFF
;
1022 return BFD_RELOC_32_GOTOFF
;
1030 return BFD_RELOC_8_PLT_PCREL
;
1032 return BFD_RELOC_16_PLT_PCREL
;
1034 return BFD_RELOC_32_PLT_PCREL
;
1042 return BFD_RELOC_8_PLTOFF
;
1044 return BFD_RELOC_16_PLTOFF
;
1046 return BFD_RELOC_32_PLTOFF
;
1054 return BFD_RELOC_68K_TLS_GD8
;
1056 return BFD_RELOC_68K_TLS_GD16
;
1058 return BFD_RELOC_68K_TLS_GD32
;
1066 return BFD_RELOC_68K_TLS_LDM8
;
1068 return BFD_RELOC_68K_TLS_LDM16
;
1070 return BFD_RELOC_68K_TLS_LDM32
;
1078 return BFD_RELOC_68K_TLS_LDO8
;
1080 return BFD_RELOC_68K_TLS_LDO16
;
1082 return BFD_RELOC_68K_TLS_LDO32
;
1090 return BFD_RELOC_68K_TLS_IE8
;
1092 return BFD_RELOC_68K_TLS_IE16
;
1094 return BFD_RELOC_68K_TLS_IE32
;
1102 return BFD_RELOC_68K_TLS_LE8
;
1104 return BFD_RELOC_68K_TLS_LE16
;
1106 return BFD_RELOC_68K_TLS_LE32
;
1116 return BFD_RELOC_8_PCREL
;
1118 return BFD_RELOC_16_PCREL
;
1120 return BFD_RELOC_32_PCREL
;
1130 return BFD_RELOC_16
;
1132 return BFD_RELOC_32
;
1139 if (pic
== pic_none
)
1140 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
1142 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
1146 if (pic
== pic_none
)
1147 as_bad (_("Can not do %d byte relocation"), size
);
1149 as_bad (_("Can not do %d byte pic relocation"), size
);
1152 return BFD_RELOC_NONE
;
1155 /* Here we decide which fixups can be adjusted to make them relative
1156 to the beginning of the section instead of the symbol. Basically
1157 we need to make sure that the dynamic relocations are done
1158 correctly, so in some cases we force the original symbol to be
1161 tc_m68k_fix_adjustable (fixS
*fixP
)
1163 /* Adjust_reloc_syms doesn't know about the GOT. */
1164 switch (fixP
->fx_r_type
)
1166 case BFD_RELOC_8_GOT_PCREL
:
1167 case BFD_RELOC_16_GOT_PCREL
:
1168 case BFD_RELOC_32_GOT_PCREL
:
1169 case BFD_RELOC_8_GOTOFF
:
1170 case BFD_RELOC_16_GOTOFF
:
1171 case BFD_RELOC_32_GOTOFF
:
1172 case BFD_RELOC_8_PLT_PCREL
:
1173 case BFD_RELOC_16_PLT_PCREL
:
1174 case BFD_RELOC_32_PLT_PCREL
:
1175 case BFD_RELOC_8_PLTOFF
:
1176 case BFD_RELOC_16_PLTOFF
:
1177 case BFD_RELOC_32_PLTOFF
:
1178 case BFD_RELOC_68K_TLS_GD32
:
1179 case BFD_RELOC_68K_TLS_GD16
:
1180 case BFD_RELOC_68K_TLS_GD8
:
1181 case BFD_RELOC_68K_TLS_LDM32
:
1182 case BFD_RELOC_68K_TLS_LDM16
:
1183 case BFD_RELOC_68K_TLS_LDM8
:
1184 case BFD_RELOC_68K_TLS_LDO32
:
1185 case BFD_RELOC_68K_TLS_LDO16
:
1186 case BFD_RELOC_68K_TLS_LDO8
:
1187 case BFD_RELOC_68K_TLS_IE32
:
1188 case BFD_RELOC_68K_TLS_IE16
:
1189 case BFD_RELOC_68K_TLS_IE8
:
1190 case BFD_RELOC_68K_TLS_LE32
:
1191 case BFD_RELOC_68K_TLS_LE16
:
1192 case BFD_RELOC_68K_TLS_LE8
:
1195 case BFD_RELOC_VTABLE_INHERIT
:
1196 case BFD_RELOC_VTABLE_ENTRY
:
1204 #else /* !OBJ_ELF */
1206 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
1208 /* PR gas/3041 Weak symbols are not relaxable
1209 because they must be treated as extern. */
1210 #define relaxable_symbol(symbol) (!(S_IS_WEAK (symbol)))
1212 #endif /* OBJ_ELF */
1215 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
1218 bfd_reloc_code_real_type code
;
1220 /* If the tcbit is set, then this was a fixup of a negative value
1221 that was never resolved. We do not have a reloc to handle this,
1222 so just return. We assume that other code will have detected this
1223 situation and produced a helpful error message, so we just tell the
1224 user that the reloc cannot be produced. */
1228 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1229 _("Unable to produce reloc against symbol '%s'"),
1230 S_GET_NAME (fixp
->fx_addsy
));
1234 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
1236 code
= fixp
->fx_r_type
;
1238 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1239 that fixup_segment converted a non-PC relative reloc into a
1240 PC relative reloc. In such a case, we need to convert the
1247 code
= BFD_RELOC_8_PCREL
;
1250 code
= BFD_RELOC_16_PCREL
;
1253 code
= BFD_RELOC_32_PCREL
;
1255 case BFD_RELOC_8_PCREL
:
1256 case BFD_RELOC_16_PCREL
:
1257 case BFD_RELOC_32_PCREL
:
1258 case BFD_RELOC_8_GOT_PCREL
:
1259 case BFD_RELOC_16_GOT_PCREL
:
1260 case BFD_RELOC_32_GOT_PCREL
:
1261 case BFD_RELOC_8_GOTOFF
:
1262 case BFD_RELOC_16_GOTOFF
:
1263 case BFD_RELOC_32_GOTOFF
:
1264 case BFD_RELOC_8_PLT_PCREL
:
1265 case BFD_RELOC_16_PLT_PCREL
:
1266 case BFD_RELOC_32_PLT_PCREL
:
1267 case BFD_RELOC_8_PLTOFF
:
1268 case BFD_RELOC_16_PLTOFF
:
1269 case BFD_RELOC_32_PLTOFF
:
1270 case BFD_RELOC_68K_TLS_GD32
:
1271 case BFD_RELOC_68K_TLS_GD16
:
1272 case BFD_RELOC_68K_TLS_GD8
:
1273 case BFD_RELOC_68K_TLS_LDM32
:
1274 case BFD_RELOC_68K_TLS_LDM16
:
1275 case BFD_RELOC_68K_TLS_LDM8
:
1276 case BFD_RELOC_68K_TLS_LDO32
:
1277 case BFD_RELOC_68K_TLS_LDO16
:
1278 case BFD_RELOC_68K_TLS_LDO8
:
1279 case BFD_RELOC_68K_TLS_IE32
:
1280 case BFD_RELOC_68K_TLS_IE16
:
1281 case BFD_RELOC_68K_TLS_IE8
:
1282 case BFD_RELOC_68K_TLS_LE32
:
1283 case BFD_RELOC_68K_TLS_LE16
:
1284 case BFD_RELOC_68K_TLS_LE8
:
1287 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1288 _("Cannot make %s relocation PC relative"),
1289 bfd_get_reloc_code_name (code
));
1295 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1296 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1298 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1299 MAP (1, 0, BFD_RELOC_8
);
1300 MAP (2, 0, BFD_RELOC_16
);
1301 MAP (4, 0, BFD_RELOC_32
);
1302 MAP (1, 1, BFD_RELOC_8_PCREL
);
1303 MAP (2, 1, BFD_RELOC_16_PCREL
);
1304 MAP (4, 1, BFD_RELOC_32_PCREL
);
1312 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1313 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1314 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1315 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1318 reloc
->addend
= fixp
->fx_addnumber
;
1319 else if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
1321 && S_IS_WEAK (fixp
->fx_addsy
)
1322 && ! bfd_is_und_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
1323 /* PR gas/3041 Adjust addend in order to force bfd_install_relocation()
1324 to put the symbol offset into frags referencing a weak symbol. */
1325 reloc
->addend
= fixp
->fx_addnumber
1326 - (S_GET_VALUE (fixp
->fx_addsy
) * 2);
1330 if (!fixp
->fx_pcrel
)
1331 reloc
->addend
= fixp
->fx_addnumber
;
1333 reloc
->addend
= (section
->vma
1334 /* Explicit sign extension in case char is
1336 + ((fixp
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80
1337 + fixp
->fx_addnumber
1338 + md_pcrel_from (fixp
));
1341 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1342 assert (reloc
->howto
!= 0);
1347 /* Handle of the OPCODE hash table. NULL means any use before
1348 m68k_ip_begin() will crash. */
1349 static struct hash_control
*op_hash
;
1351 /* Assemble an m68k instruction. */
1354 m68k_ip (char *instring
)
1357 register struct m68k_op
*opP
;
1358 register const struct m68k_incant
*opcode
;
1359 register const char *s
;
1360 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1361 char *pdot
, *pdotmove
;
1362 enum m68k_size siz1
, siz2
;
1366 struct m68k_op operands_backup
[6];
1367 LITTLENUM_TYPE words
[6];
1368 LITTLENUM_TYPE
*wordp
;
1369 unsigned long ok_arch
= 0;
1371 if (*instring
== ' ')
1372 instring
++; /* Skip leading whitespace. */
1374 /* Scan up to end of operation-code, which MUST end in end-of-string
1375 or exactly 1 space. */
1377 for (p
= instring
; *p
!= '\0'; p
++)
1387 the_ins
.error
= _("No operator");
1391 /* p now points to the end of the opcode name, probably whitespace.
1392 Make sure the name is null terminated by clobbering the
1393 whitespace, look it up in the hash table, then fix it back.
1394 Remove a dot, first, since the opcode tables have none. */
1397 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1398 *pdotmove
= pdotmove
[1];
1404 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1409 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1410 *pdotmove
= pdotmove
[-1];
1417 the_ins
.error
= _("Unknown operator");
1421 /* Found a legitimate opcode, start matching operands. */
1425 if (opcode
->m_operands
== 0)
1427 char *old
= input_line_pointer
;
1429 input_line_pointer
= p
;
1430 /* Ahh - it's a motorola style psuedo op. */
1431 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1432 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1433 input_line_pointer
= old
;
1439 if (flag_mri
&& opcode
->m_opnum
== 0)
1441 /* In MRI mode, random garbage is allowed after an instruction
1442 which accepts no operands. */
1443 the_ins
.args
= opcode
->m_operands
;
1444 the_ins
.numargs
= opcode
->m_opnum
;
1445 the_ins
.numo
= opcode
->m_codenum
;
1446 the_ins
.opcode
[0] = getone (opcode
);
1447 the_ins
.opcode
[1] = gettwo (opcode
);
1451 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1453 p
= crack_operand (p
, opP
);
1457 the_ins
.error
= opP
->error
;
1462 opsfound
= opP
- &the_ins
.operands
[0];
1464 /* This ugly hack is to support the floating pt opcodes in their
1465 standard form. Essentially, we fake a first enty of type COP#1 */
1466 if (opcode
->m_operands
[0] == 'I')
1470 for (n
= opsfound
; n
> 0; --n
)
1471 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1473 memset (&the_ins
.operands
[0], '\0', sizeof (the_ins
.operands
[0]));
1474 the_ins
.operands
[0].mode
= CONTROL
;
1475 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1479 /* We've got the operands. Find an opcode that'll accept them. */
1482 /* If we didn't get the right number of ops, or we have no
1483 common model with this pattern then reject this pattern. */
1485 ok_arch
|= opcode
->m_arch
;
1486 if (opsfound
!= opcode
->m_opnum
1487 || ((opcode
->m_arch
& current_architecture
) == 0))
1493 /* Make a copy of the operands of this insn so that
1494 we can modify them safely, should we want to. */
1495 assert (opsfound
<= (int) ARRAY_SIZE (operands_backup
));
1496 for (i
= 0; i
< opsfound
; i
++)
1497 operands_backup
[i
] = the_ins
.operands
[i
];
1499 for (s
= opcode
->m_operands
, opP
= &operands_backup
[0];
1503 /* Warning: this switch is huge! */
1504 /* I've tried to organize the cases into this order:
1505 non-alpha first, then alpha by letter. Lower-case
1506 goes directly before uppercase counterpart. */
1507 /* Code with multiple case ...: gets sorted by the lowest
1508 case ... it belongs to. I hope this makes sense. */
1614 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1631 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1650 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1660 if (opP
->mode
!= IMMED
)
1662 else if (s
[1] == 'b'
1663 && ! isvar (&opP
->disp
)
1664 && (opP
->disp
.exp
.X_op
!= O_constant
1665 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1667 else if (s
[1] == 'B'
1668 && ! isvar (&opP
->disp
)
1669 && (opP
->disp
.exp
.X_op
!= O_constant
1670 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1672 else if (s
[1] == 'w'
1673 && ! isvar (&opP
->disp
)
1674 && (opP
->disp
.exp
.X_op
!= O_constant
1675 || ! isword (opP
->disp
.exp
.X_add_number
)))
1677 else if (s
[1] == 'W'
1678 && ! isvar (&opP
->disp
)
1679 && (opP
->disp
.exp
.X_op
!= O_constant
1680 || ! issword (opP
->disp
.exp
.X_add_number
)))
1686 if (opP
->mode
!= IMMED
)
1691 if (opP
->mode
== AREG
1692 || opP
->mode
== CONTROL
1693 || opP
->mode
== FPREG
1694 || opP
->mode
== IMMED
1695 || opP
->mode
== REGLST
1696 || (opP
->mode
!= ABSL
1698 || opP
->reg
== ZPC
)))
1703 if (opP
->mode
== CONTROL
1704 || opP
->mode
== FPREG
1705 || opP
->mode
== REGLST
1706 || opP
->mode
== IMMED
1707 || (opP
->mode
!= ABSL
1709 || opP
->reg
== ZPC
)))
1737 if (opP
->mode
== CONTROL
1738 || opP
->mode
== FPREG
1739 || opP
->mode
== REGLST
)
1744 if (opP
->mode
!= AINC
)
1749 if (opP
->mode
!= ADEC
)
1799 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1820 case '~': /* For now! (JF FOO is this right?) */
1842 if (opP
->mode
!= CONTROL
1843 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1848 if (opP
->mode
!= AREG
)
1853 if (opP
->mode
!= AINDR
)
1858 if (opP
->mode
!= AINDR
&& opP
->mode
!= AINC
&& opP
->mode
!= ADEC
1859 && (opP
->mode
!= DISP
1861 || opP
->reg
> ADDR7
))
1866 if (opP
->mode
!= ABSL
1868 && strncmp (instring
, "jbsr", 4) == 0))
1891 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1896 if (opP
->mode
!= DISP
1898 || opP
->reg
> ADDR7
)
1903 if (opP
->mode
!= DREG
)
1908 if (opP
->reg
!= ACC
)
1913 if (opP
->reg
!= ACC
&& opP
->reg
!= ACC1
1914 && opP
->reg
!= ACC2
&& opP
->reg
!= ACC3
)
1919 if (opP
->mode
!= FPREG
)
1924 if (opP
->reg
!= MACSR
)
1929 if (opP
->reg
!= ACCEXT01
&& opP
->reg
!= ACCEXT23
)
1934 if (opP
->reg
!= MASK
)
1939 if (opP
->mode
!= CONTROL
1946 if (opP
->mode
!= LSH
&& opP
->mode
!= RSH
)
1951 if (opP
->mode
!= CONTROL
1953 || opP
->reg
> last_movec_reg
1958 const enum m68k_register
*rp
;
1960 for (rp
= control_regs
; *rp
; rp
++)
1962 if (*rp
== opP
->reg
)
1964 /* In most CPUs RAMBAR refers to control reg
1965 c05 (RAMBAR1), but a few CPUs have it
1966 refer to c04 (RAMBAR0). */
1967 else if (*rp
== RAMBAR_ALT
&& opP
->reg
== RAMBAR
)
1969 opP
->reg
= RAMBAR_ALT
;
1979 if (opP
->mode
!= IMMED
)
1985 if (opP
->mode
== DREG
1986 || opP
->mode
== AREG
1987 || opP
->mode
== FPREG
)
1996 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1999 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
2002 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
2010 else if (opP
->mode
== CONTROL
)
2019 opP
->mask
= 1 << 24;
2022 opP
->mask
= 1 << 25;
2025 opP
->mask
= 1 << 26;
2034 else if (opP
->mode
!= REGLST
)
2036 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
2038 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
2043 if (opP
->mode
!= IMMED
)
2045 else if (opP
->disp
.exp
.X_op
!= O_constant
2046 || ! issbyte (opP
->disp
.exp
.X_add_number
))
2048 else if (! m68k_quick
2049 && instring
[3] != 'q'
2050 && instring
[4] != 'q')
2055 if (opP
->mode
!= DREG
2056 && opP
->mode
!= IMMED
2057 && opP
->mode
!= ABSL
)
2062 if (opP
->mode
!= IMMED
)
2064 else if (opP
->disp
.exp
.X_op
!= O_constant
2065 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
2067 else if (! m68k_quick
2068 && (strncmp (instring
, "add", 3) == 0
2069 || strncmp (instring
, "sub", 3) == 0)
2070 && instring
[3] != 'q')
2075 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
2080 if (opP
->mode
!= AINDR
2081 && (opP
->mode
!= BASE
2083 && opP
->reg
!= ZADDR0
)
2084 || opP
->disp
.exp
.X_op
!= O_absent
2085 || ((opP
->index
.reg
< DATA0
2086 || opP
->index
.reg
> DATA7
)
2087 && (opP
->index
.reg
< ADDR0
2088 || opP
->index
.reg
> ADDR7
))
2089 || opP
->index
.size
!= SIZE_UNSPEC
2090 || opP
->index
.scale
!= 1))
2095 if (opP
->mode
!= CONTROL
2096 || ! (opP
->reg
== FPI
2098 || opP
->reg
== FPC
))
2103 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
2108 if (opP
->mode
!= IMMED
)
2110 else if (opP
->disp
.exp
.X_op
!= O_constant
2111 || TRUNC (opP
->disp
.exp
.X_add_number
) > 7)
2116 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
2121 if (opP
->mode
!= IMMED
)
2123 else if (opP
->disp
.exp
.X_op
!= O_constant
2124 || (TRUNC (opP
->disp
.exp
.X_add_number
) != 0xffffffff
2125 && TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 6))
2130 if (opP
->mode
!= IMMED
)
2132 else if (opP
->disp
.exp
.X_op
!= O_constant
2133 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
2138 if (opP
->mode
!= IMMED
)
2140 else if (opP
->disp
.exp
.X_op
!= O_constant
2141 || TRUNC (opP
->disp
.exp
.X_add_number
) > 511)
2145 /* JF these are out of order. We could put them
2146 in order if we were willing to put up with
2147 bunches of #ifdef m68851s in the code.
2149 Don't forget that you need these operands
2150 to use 68030 MMU instructions. */
2152 /* Memory addressing mode used by pflushr. */
2154 if (opP
->mode
== CONTROL
2155 || opP
->mode
== FPREG
2156 || opP
->mode
== DREG
2157 || opP
->mode
== AREG
2158 || opP
->mode
== REGLST
)
2160 /* We should accept immediate operands, but they
2161 supposedly have to be quad word, and we don't
2162 handle that. I would like to see what a Motorola
2163 assembler does before doing something here. */
2164 if (opP
->mode
== IMMED
)
2169 if (opP
->mode
!= CONTROL
2170 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
2175 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
2180 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
2185 if (opP
->mode
!= CONTROL
2188 && opP
->reg
!= SCC
))
2193 if (opP
->mode
!= CONTROL
2199 if (opP
->mode
!= CONTROL
2202 && opP
->reg
!= CRP
))
2226 if (opP
->mode
!= CONTROL
2227 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
2228 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
2233 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
2238 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
2243 if (opP
->mode
!= CONTROL
2252 if (opP
->mode
!= ABSL
)
2257 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
2259 /* FIXME: kludge instead of fixing parser:
2260 upper/lower registers are *not* CONTROL
2261 registers, but ordinary ones. */
2262 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
2263 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
2270 if (!(opP
->mode
== AINDR
2271 || (opP
->mode
== DISP
2272 && !(opP
->reg
== PC
|| opP
->reg
== ZPC
))))
2277 if (!(opP
->mode
== AINDR
|| opP
->mode
== DISP
))
2289 /* Since we have found the correct instruction, copy
2290 in the modifications that we may have made. */
2292 for (i
= 0; i
< opsfound
; i
++)
2293 the_ins
.operands
[i
] = operands_backup
[i
];
2299 opcode
= opcode
->m_next
;
2304 && !(ok_arch
& current_architecture
))
2306 const struct m68k_cpu
*cpu
;
2309 char *buf
= xmalloc (space
+ 1);
2313 the_ins
.error
= buf
;
2314 /* Make sure there's a NUL at the end of the buffer -- strncpy
2315 won't write one when it runs out of buffer. */
2317 #define APPEND(STRING) \
2318 (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
2320 APPEND (_("invalid instruction for this architecture; needs "));
2324 APPEND ("ColdFire ISA_A");
2327 APPEND ("ColdFire ");
2328 APPEND (_("hardware divide"));
2331 APPEND ("ColdFire ISA_A+");
2334 APPEND ("ColdFire ISA_B");
2337 APPEND ("ColdFire ISA_C");
2340 APPEND ("ColdFire fpu");
2343 APPEND ("M68K fpu");
2346 APPEND ("M68K mmu");
2350 APPEND (_("or higher"));
2354 APPEND (_("or higher"));
2358 APPEND (_("or higher"));
2366 for (cpu
= m68k_cpus
; cpu
->name
; cpu
++)
2367 if (!cpu
->alias
&& (cpu
->arch
& ok_arch
))
2369 const struct m68k_cpu
*alias
;
2370 int seen_master
= 0;
2376 for (alias
= cpu
; alias
!= m68k_cpus
; alias
--)
2377 if (alias
[-1].alias
>= 0)
2379 for (; !seen_master
|| alias
->alias
> 0; alias
++)
2389 APPEND (alias
->name
);
2402 /* We ran out of space, so replace the end of the list
2407 strcpy (buf
, " ...");
2411 the_ins
.error
= _("operands mismatch");
2418 /* Now assemble it. */
2419 the_ins
.args
= opcode
->m_operands
;
2420 the_ins
.numargs
= opcode
->m_opnum
;
2421 the_ins
.numo
= opcode
->m_codenum
;
2422 the_ins
.opcode
[0] = getone (opcode
);
2423 the_ins
.opcode
[1] = gettwo (opcode
);
2425 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2430 /* This switch is a doozy.
2431 Watch the first step; its a big one! */
2464 tmpreg
= 0x3c; /* 7.4 */
2465 if (strchr ("bwl", s
[1]))
2466 nextword
= get_num (&opP
->disp
, 90);
2468 nextword
= get_num (&opP
->disp
, 0);
2469 if (isvar (&opP
->disp
))
2470 add_fix (s
[1], &opP
->disp
, 0, 0);
2474 if (!isbyte (nextword
))
2475 opP
->error
= _("operand out of range");
2480 if (!isword (nextword
))
2481 opP
->error
= _("operand out of range");
2486 if (!issword (nextword
))
2487 opP
->error
= _("operand out of range");
2492 addword (nextword
>> 16);
2519 /* We gotta put out some float. */
2520 if (op (&opP
->disp
) != O_big
)
2525 /* Can other cases happen here? */
2526 if (op (&opP
->disp
) != O_constant
)
2529 val
= (valueT
) offs (&opP
->disp
);
2533 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2534 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2538 offs (&opP
->disp
) = gencnt
;
2540 if (offs (&opP
->disp
) > 0)
2542 if (offs (&opP
->disp
) > baseo
)
2544 as_warn (_("Bignum too big for %c format; truncated"),
2546 offs (&opP
->disp
) = baseo
;
2548 baseo
-= offs (&opP
->disp
);
2551 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
2552 offs (&opP
->disp
)--;
2557 gen_to_words (words
, baseo
, (long) outro
);
2558 for (wordp
= words
; baseo
--; wordp
++)
2562 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2565 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2568 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2571 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2574 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2578 nextword
= get_num (&opP
->disp
, 90);
2580 /* Convert mode 5 addressing with a zero offset into
2581 mode 2 addressing to reduce the instruction size by a
2583 if (! isvar (&opP
->disp
)
2585 && (opP
->disp
.size
== SIZE_UNSPEC
)
2586 && (opP
->reg
>= ADDR0
)
2587 && (opP
->reg
<= ADDR7
))
2589 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2594 && ! isvar (&opP
->disp
)
2597 opP
->disp
.exp
.X_op
= O_symbol
;
2598 opP
->disp
.exp
.X_add_symbol
=
2599 section_symbol (absolute_section
);
2602 /* Force into index mode. Hope this works. */
2604 /* We do the first bit for 32-bit displacements, and the
2605 second bit for 16 bit ones. It is possible that we
2606 should make the default be WORD instead of LONG, but
2607 I think that'd break GCC, so we put up with a little
2608 inefficiency for the sake of working output. */
2610 if (!issword (nextword
)
2611 || (isvar (&opP
->disp
)
2612 && ((opP
->disp
.size
== SIZE_UNSPEC
2613 && flag_short_refs
== 0
2614 && cpu_of_arch (current_architecture
) >= m68020
2615 && ! arch_coldfire_p (current_architecture
))
2616 || opP
->disp
.size
== SIZE_LONG
)))
2618 if (cpu_of_arch (current_architecture
) < m68020
2619 || arch_coldfire_p (current_architecture
))
2621 _("displacement too large for this architecture; needs 68020 or higher");
2623 tmpreg
= 0x3B; /* 7.3 */
2625 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2626 if (isvar (&opP
->disp
))
2630 if (opP
->disp
.size
== SIZE_LONG
2632 /* If the displacement needs pic
2633 relocation it cannot be relaxed. */
2634 || opP
->disp
.pic_reloc
!= pic_none
2639 add_fix ('l', &opP
->disp
, 1, 2);
2643 add_frag (adds (&opP
->disp
),
2644 SEXT (offs (&opP
->disp
)),
2645 TAB (PCREL1632
, SZ_UNDEF
));
2652 add_fix ('l', &opP
->disp
, 0, 0);
2657 addword (nextword
>> 16);
2662 tmpreg
= 0x3A; /* 7.2 */
2664 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2666 if (isvar (&opP
->disp
))
2670 add_fix ('w', &opP
->disp
, 1, 0);
2673 add_fix ('w', &opP
->disp
, 0, 0);
2683 baseo
= get_num (&opP
->disp
, 90);
2684 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2685 outro
= get_num (&opP
->odisp
, 90);
2686 /* Figure out the `addressing mode'.
2687 Also turn on the BASE_DISABLE bit, if needed. */
2688 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2690 tmpreg
= 0x3b; /* 7.3 */
2691 if (opP
->reg
== ZPC
)
2694 else if (opP
->reg
== 0)
2697 tmpreg
= 0x30; /* 6.garbage */
2699 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2702 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2705 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2707 siz1
= opP
->disp
.size
;
2708 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2709 siz2
= opP
->odisp
.size
;
2713 /* Index register stuff. */
2714 if (opP
->index
.reg
!= 0
2715 && opP
->index
.reg
>= DATA
2716 && opP
->index
.reg
<= ADDR7
)
2718 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2720 if (opP
->index
.size
== SIZE_LONG
2721 || (opP
->index
.size
== SIZE_UNSPEC
2722 && m68k_index_width_default
== SIZE_LONG
))
2725 if ((opP
->index
.scale
!= 1
2726 && cpu_of_arch (current_architecture
) < m68020
)
2727 || (opP
->index
.scale
== 8
2728 && (arch_coldfire_p (current_architecture
)
2729 && !arch_coldfire_fpu (current_architecture
))))
2732 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2735 if (arch_coldfire_p (current_architecture
)
2736 && opP
->index
.size
== SIZE_WORD
)
2737 opP
->error
= _("invalid index size for coldfire");
2739 switch (opP
->index
.scale
)
2756 GET US OUT OF HERE! */
2758 /* Must be INDEX, with an index register. Address
2759 register cannot be ZERO-PC, and either :b was
2760 forced, or we know it will fit. For a 68000 or
2761 68010, force this mode anyways, because the
2762 larger modes aren't supported. */
2763 if (opP
->mode
== BASE
2764 && ((opP
->reg
>= ADDR0
2765 && opP
->reg
<= ADDR7
)
2768 if (siz1
== SIZE_BYTE
2769 || cpu_of_arch (current_architecture
) < m68020
2770 || arch_coldfire_p (current_architecture
)
2771 || (siz1
== SIZE_UNSPEC
2772 && ! isvar (&opP
->disp
)
2773 && issbyte (baseo
)))
2775 nextword
+= baseo
& 0xff;
2777 if (isvar (&opP
->disp
))
2779 /* Do a byte relocation. If it doesn't
2780 fit (possible on m68000) let the
2781 fixup processing complain later. */
2783 add_fix ('B', &opP
->disp
, 1, 1);
2785 add_fix ('B', &opP
->disp
, 0, 0);
2787 else if (siz1
!= SIZE_BYTE
)
2789 if (siz1
!= SIZE_UNSPEC
)
2790 as_warn (_("Forcing byte displacement"));
2791 if (! issbyte (baseo
))
2792 opP
->error
= _("byte displacement out of range");
2797 else if (siz1
== SIZE_UNSPEC
2799 && isvar (&opP
->disp
)
2800 && subs (&opP
->disp
) == NULL
2802 /* If the displacement needs pic
2803 relocation it cannot be relaxed. */
2804 && opP
->disp
.pic_reloc
== pic_none
2808 /* The code in md_convert_frag_1 needs to be
2809 able to adjust nextword. Call frag_grow
2810 to ensure that we have enough space in
2811 the frag obstack to make all the bytes
2814 nextword
+= baseo
& 0xff;
2816 add_frag (adds (&opP
->disp
),
2817 SEXT (offs (&opP
->disp
)),
2818 TAB (PCINDEX
, SZ_UNDEF
));
2826 nextword
|= 0x40; /* No index reg. */
2827 if (opP
->index
.reg
>= ZDATA0
2828 && opP
->index
.reg
<= ZDATA7
)
2829 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2830 else if (opP
->index
.reg
>= ZADDR0
2831 || opP
->index
.reg
<= ZADDR7
)
2832 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2835 /* It isn't simple. */
2837 if (cpu_of_arch (current_architecture
) < m68020
2838 || arch_coldfire_p (current_architecture
))
2840 _("invalid operand mode for this architecture; needs 68020 or higher");
2843 /* If the guy specified a width, we assume that it is
2844 wide enough. Maybe it isn't. If so, we lose. */
2848 if (isvar (&opP
->disp
)
2850 : ! issword (baseo
))
2855 else if (! isvar (&opP
->disp
) && baseo
== 0)
2864 as_warn (_(":b not permitted; defaulting to :w"));
2874 /* Figure out inner displacement stuff. */
2875 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2877 if (cpu_of_arch (current_architecture
) & cpu32
)
2878 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2882 if (isvar (&opP
->odisp
)
2884 : ! issword (outro
))
2889 else if (! isvar (&opP
->odisp
) && outro
== 0)
2898 as_warn (_(":b not permitted; defaulting to :w"));
2907 if (opP
->mode
== POST
2908 && (nextword
& 0x40) == 0)
2913 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2915 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2916 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2918 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2920 if (siz1
== SIZE_LONG
)
2921 addword (baseo
>> 16);
2922 if (siz1
!= SIZE_UNSPEC
)
2925 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2926 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2927 if (siz2
== SIZE_LONG
)
2928 addword (outro
>> 16);
2929 if (siz2
!= SIZE_UNSPEC
)
2935 nextword
= get_num (&opP
->disp
, 90);
2936 switch (opP
->disp
.size
)
2941 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2943 tmpreg
= 0x38; /* 7.0 */
2947 if (isvar (&opP
->disp
)
2948 && !subs (&opP
->disp
)
2949 && adds (&opP
->disp
)
2951 /* If the displacement needs pic relocation it
2952 cannot be relaxed. */
2953 && opP
->disp
.pic_reloc
== pic_none
2956 && !strchr ("~%&$?", s
[0]))
2958 tmpreg
= 0x3A; /* 7.2 */
2959 add_frag (adds (&opP
->disp
),
2960 SEXT (offs (&opP
->disp
)),
2961 TAB (ABSTOPCREL
, SZ_UNDEF
));
2964 /* Fall through into long. */
2966 if (isvar (&opP
->disp
))
2967 add_fix ('l', &opP
->disp
, 0, 0);
2969 tmpreg
= 0x39;/* 7.1 mode */
2970 addword (nextword
>> 16);
2975 as_bad (_("unsupported byte value; use a different suffix"));
2979 if (isvar (&opP
->disp
))
2980 add_fix ('w', &opP
->disp
, 0, 0);
2982 tmpreg
= 0x38;/* 7.0 mode */
2990 as_bad (_("unknown/incorrect operand"));
2994 /* If s[0] is '4', then this is for the mac instructions
2995 that can have a trailing_ampersand set. If so, set 0x100
2996 bit on tmpreg so install_gen_operand can check for it and
2997 set the appropriate bit (word2, bit 5). */
3000 if (opP
->trailing_ampersand
)
3003 install_gen_operand (s
[1], tmpreg
);
3009 { /* JF: I hate floating point! */
3024 tmpreg
= get_num (&opP
->disp
, tmpreg
);
3025 if (isvar (&opP
->disp
))
3026 add_fix (s
[1], &opP
->disp
, 0, 0);
3029 case 'b': /* Danger: These do no check for
3030 certain types of overflow.
3032 if (!isbyte (tmpreg
))
3033 opP
->error
= _("out of range");
3034 insop (tmpreg
, opcode
);
3035 if (isvar (&opP
->disp
))
3036 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
3037 (opcode
->m_codenum
) * 2 + 1;
3040 if (!issbyte (tmpreg
))
3041 opP
->error
= _("out of range");
3042 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
3043 if (isvar (&opP
->disp
))
3044 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
3047 if (!isword (tmpreg
))
3048 opP
->error
= _("out of range");
3049 insop (tmpreg
, opcode
);
3050 if (isvar (&opP
->disp
))
3051 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3054 if (!issword (tmpreg
))
3055 opP
->error
= _("out of range");
3056 insop (tmpreg
, opcode
);
3057 if (isvar (&opP
->disp
))
3058 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3061 /* Because of the way insop works, we put these two out
3063 insop (tmpreg
, opcode
);
3064 insop (tmpreg
>> 16, opcode
);
3065 if (isvar (&opP
->disp
))
3066 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3073 install_operand (s
[1], tmpreg
);
3084 install_operand (s
[1], opP
->reg
- ADDR
);
3088 tmpreg
= get_num (&opP
->disp
, 90);
3093 add_fix ('B', &opP
->disp
, 1, -1);
3096 add_fix ('w', &opP
->disp
, 1, 0);
3101 the_ins
.opcode
[0] |= 0xff;
3102 add_fix ('l', &opP
->disp
, 1, 0);
3106 case 'g': /* Conditional branch */
3107 have_disp
= HAVE_LONG_CALL (current_architecture
);
3110 case 'b': /* Unconditional branch */
3111 have_disp
= HAVE_LONG_BRANCH (current_architecture
);
3112 use_pl
= LONG_BRANCH_VIA_COND (current_architecture
);
3115 case 's': /* Unconditional subroutine */
3116 have_disp
= HAVE_LONG_CALL (current_architecture
);
3119 if (subs (&opP
->disp
) /* We can't relax it. */
3121 /* If the displacement needs pic relocation it cannot be
3123 || opP
->disp
.pic_reloc
!= pic_none
3128 as_warn (_("Can't use long branches on this architecture"));
3132 /* This could either be a symbol, or an absolute
3133 address. If it's an absolute address, turn it into
3134 an absolute jump right here and keep it out of the
3136 if (adds (&opP
->disp
) == 0)
3138 if (the_ins
.opcode
[0] == 0x6000) /* jbra */
3139 the_ins
.opcode
[0] = 0x4EF9;
3140 else if (the_ins
.opcode
[0] == 0x6100) /* jbsr */
3141 the_ins
.opcode
[0] = 0x4EB9;
3144 the_ins
.opcode
[0] ^= 0x0100;
3145 the_ins
.opcode
[0] |= 0x0006;
3148 add_fix ('l', &opP
->disp
, 0, 0);
3154 /* Now we know it's going into the relaxer. Now figure
3155 out which mode. We try in this order of preference:
3156 long branch, absolute jump, byte/word branches only. */
3158 add_frag (adds (&opP
->disp
),
3159 SEXT (offs (&opP
->disp
)),
3160 TAB (BRANCHBWL
, SZ_UNDEF
));
3161 else if (! flag_keep_pcrel
)
3163 if ((the_ins
.opcode
[0] == 0x6000)
3164 || (the_ins
.opcode
[0] == 0x6100))
3165 add_frag (adds (&opP
->disp
),
3166 SEXT (offs (&opP
->disp
)),
3167 TAB (BRABSJUNC
, SZ_UNDEF
));
3169 add_frag (adds (&opP
->disp
),
3170 SEXT (offs (&opP
->disp
)),
3171 TAB (BRABSJCOND
, SZ_UNDEF
));
3174 add_frag (adds (&opP
->disp
),
3175 SEXT (offs (&opP
->disp
)),
3176 (use_pl
? TAB (BRANCHBWPL
, SZ_UNDEF
)
3177 : TAB (BRANCHBW
, SZ_UNDEF
)));
3180 if (isvar (&opP
->disp
))
3182 /* Check for DBcc instructions. We can relax them,
3183 but only if we have long branches and/or absolute
3185 if (((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
3186 && (HAVE_LONG_BRANCH (current_architecture
)
3187 || ! flag_keep_pcrel
))
3189 if (HAVE_LONG_BRANCH (current_architecture
))
3190 add_frag (adds (&opP
->disp
),
3191 SEXT (offs (&opP
->disp
)),
3192 TAB (DBCCLBR
, SZ_UNDEF
));
3194 add_frag (adds (&opP
->disp
),
3195 SEXT (offs (&opP
->disp
)),
3196 TAB (DBCCABSJ
, SZ_UNDEF
));
3199 add_fix ('w', &opP
->disp
, 1, 0);
3203 case 'C': /* Fixed size LONG coproc branches. */
3204 add_fix ('l', &opP
->disp
, 1, 0);
3208 case 'c': /* Var size Coprocesssor branches. */
3209 if (subs (&opP
->disp
) || (adds (&opP
->disp
) == 0))
3211 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
3212 add_fix ('l', &opP
->disp
, 1, 0);
3217 add_frag (adds (&opP
->disp
),
3218 SEXT (offs (&opP
->disp
)),
3219 TAB (FBRANCH
, SZ_UNDEF
));
3226 case 'C': /* Ignore it. */
3229 case 'd': /* JF this is a kludge. */
3230 install_operand ('s', opP
->reg
- ADDR
);
3231 tmpreg
= get_num (&opP
->disp
, 90);
3232 if (!issword (tmpreg
))
3234 as_warn (_("Expression out of range, using 0"));
3241 install_operand (s
[1], opP
->reg
- DATA
);
3244 case 'e': /* EMAC ACCx, reg/reg. */
3245 install_operand (s
[1], opP
->reg
- ACC
);
3248 case 'E': /* Ignore it. */
3252 install_operand (s
[1], opP
->reg
- FP0
);
3255 case 'g': /* EMAC ACCEXTx. */
3256 install_operand (s
[1], opP
->reg
- ACCEXT01
);
3259 case 'G': /* Ignore it. */
3264 tmpreg
= opP
->reg
- COP0
;
3265 install_operand (s
[1], tmpreg
);
3268 case 'i': /* MAC/EMAC scale factor. */
3269 install_operand (s
[1], opP
->mode
== LSH
? 0x1 : 0x3);
3272 case 'J': /* JF foo. */
3413 install_operand (s
[1], tmpreg
);
3417 tmpreg
= get_num (&opP
->disp
, 55);
3418 install_operand (s
[1], tmpreg
& 0x7f);
3425 if (tmpreg
& 0x7FF0000)
3426 as_bad (_("Floating point register in register list"));
3427 insop (reverse_16_bits (tmpreg
), opcode
);
3431 if (tmpreg
& 0x700FFFF)
3432 as_bad (_("Wrong register in floating-point reglist"));
3433 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
3441 if (tmpreg
& 0x7FF0000)
3442 as_bad (_("Floating point register in register list"));
3443 insop (tmpreg
, opcode
);
3445 else if (s
[1] == '8')
3447 if (tmpreg
& 0x0FFFFFF)
3448 as_bad (_("incorrect register in reglist"));
3449 install_operand (s
[1], tmpreg
>> 24);
3453 if (tmpreg
& 0x700FFFF)
3454 as_bad (_("wrong register in floating-point reglist"));
3456 install_operand (s
[1], tmpreg
>> 16);
3461 install_operand (s
[1], get_num (&opP
->disp
, 60));
3465 tmpreg
= ((opP
->mode
== DREG
)
3466 ? 0x20 + (int) (opP
->reg
- DATA
)
3467 : (get_num (&opP
->disp
, 40) & 0x1F));
3468 install_operand (s
[1], tmpreg
);
3472 tmpreg
= get_num (&opP
->disp
, 10);
3475 install_operand (s
[1], tmpreg
);
3479 /* This depends on the fact that ADDR registers are eight
3480 more than their corresponding DATA regs, so the result
3481 will have the ADDR_REG bit set. */
3482 install_operand (s
[1], opP
->reg
- DATA
);
3486 if (opP
->mode
== AINDR
)
3487 install_operand (s
[1], opP
->reg
- DATA
);
3489 install_operand (s
[1], opP
->index
.reg
- DATA
);
3493 if (opP
->reg
== FPI
)
3495 else if (opP
->reg
== FPS
)
3497 else if (opP
->reg
== FPC
)
3501 install_operand (s
[1], tmpreg
);
3504 case 'S': /* Ignore it. */
3508 install_operand (s
[1], get_num (&opP
->disp
, 30));
3511 case 'U': /* Ignore it. */
3530 as_fatal (_("failed sanity check"));
3531 } /* switch on cache token. */
3532 install_operand (s
[1], tmpreg
);
3535 /* JF: These are out of order, I fear. */
3548 install_operand (s
[1], tmpreg
);
3574 install_operand (s
[1], tmpreg
);
3578 if (opP
->reg
== VAL
)
3597 install_operand (s
[1], tmpreg
);
3611 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3622 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3628 install_operand (s
[1], tmpreg
);
3631 know (opP
->reg
== PSR
);
3634 know (opP
->reg
== PCSR
);
3649 install_operand (s
[1], tmpreg
);
3652 tmpreg
= get_num (&opP
->disp
, 20);
3653 install_operand (s
[1], tmpreg
);
3655 case '_': /* used only for move16 absolute 32-bit address. */
3656 if (isvar (&opP
->disp
))
3657 add_fix ('l', &opP
->disp
, 0, 0);
3658 tmpreg
= get_num (&opP
->disp
, 90);
3659 addword (tmpreg
>> 16);
3660 addword (tmpreg
& 0xFFFF);
3663 install_operand (s
[1], opP
->reg
- DATA0L
);
3664 opP
->reg
-= (DATA0L
);
3665 opP
->reg
&= 0x0F; /* remove upper/lower bit. */
3668 tmpreg
= get_num (&opP
->disp
, 80);
3671 install_operand (s
[1], tmpreg
);
3674 tmpreg
= get_num (&opP
->disp
, 10);
3675 install_operand (s
[1], tmpreg
- 1);
3678 tmpreg
= get_num (&opP
->disp
, 65);
3679 install_operand (s
[1], tmpreg
);
3686 /* By the time whe get here (FINALLY) the_ins contains the complete
3687 instruction, ready to be emitted. . . */
3691 reverse_16_bits (int in
)
3696 static int mask
[16] =
3698 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3699 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3701 for (n
= 0; n
< 16; n
++)
3704 out
|= mask
[15 - n
];
3707 } /* reverse_16_bits() */
3710 reverse_8_bits (int in
)
3715 static int mask
[8] =
3717 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3720 for (n
= 0; n
< 8; n
++)
3726 } /* reverse_8_bits() */
3728 /* Cause an extra frag to be generated here, inserting up to
3729 FRAG_VAR_SIZE bytes. TYPE is the subtype of the frag to be
3730 generated; its primary type is rs_machine_dependent.
3732 The TYPE parameter is also used by md_convert_frag_1 and
3733 md_estimate_size_before_relax. The appropriate type of fixup will
3734 be emitted by md_convert_frag_1.
3736 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3738 install_operand (int mode
, int val
)
3743 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge. */
3746 the_ins
.opcode
[0] |= val
<< 9;
3749 the_ins
.opcode
[1] |= val
<< 9;
3752 the_ins
.opcode
[1] |= val
<< 12;
3755 the_ins
.opcode
[1] |= val
<< 6;
3758 the_ins
.opcode
[1] |= val
;
3761 the_ins
.opcode
[2] |= val
<< 12;
3764 the_ins
.opcode
[2] |= val
<< 6;
3767 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3768 three words long! */
3770 the_ins
.opcode
[2] |= val
;
3773 the_ins
.opcode
[1] |= val
<< 7;
3776 the_ins
.opcode
[1] |= val
<< 10;
3780 the_ins
.opcode
[1] |= val
<< 5;
3785 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3788 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3791 the_ins
.opcode
[0] |= val
= 0xff;
3794 the_ins
.opcode
[0] |= val
<< 9;
3797 the_ins
.opcode
[1] |= val
;
3800 the_ins
.opcode
[1] |= val
;
3801 the_ins
.numo
++; /* What a hack. */
3804 the_ins
.opcode
[1] |= val
<< 4;
3812 the_ins
.opcode
[0] |= (val
<< 6);
3815 the_ins
.opcode
[1] = (val
>> 16);
3816 the_ins
.opcode
[2] = val
& 0xffff;
3819 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3820 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3821 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3823 case 'n': /* MAC/EMAC Rx on !load. */
3824 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3825 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3826 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3828 case 'o': /* MAC/EMAC Rx on load. */
3829 the_ins
.opcode
[1] |= val
<< 12;
3830 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3832 case 'M': /* MAC/EMAC Ry on !load. */
3833 the_ins
.opcode
[0] |= (val
& 0xF);
3834 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3836 case 'N': /* MAC/EMAC Ry on load. */
3837 the_ins
.opcode
[1] |= (val
& 0xF);
3838 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3841 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3844 the_ins
.opcode
[0] |= ((val
& 0x3) << 9);
3847 the_ins
.opcode
[0] |= ((val
& 0x3) << 0);
3849 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3850 the_ins
.opcode
[0] |= ((~val
& 0x1) << 7);
3851 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3853 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3854 the_ins
.opcode
[0] |= ((val
& 0x1) << 7);
3855 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3858 the_ins
.opcode
[1] |= ((val
& 0x3) << 9);
3861 the_ins
.opcode
[0] |= (val
& 0x1) <<10;
3865 as_fatal (_("failed sanity check."));
3870 install_gen_operand (int mode
, int val
)
3874 case '/': /* Special for mask loads for mac/msac insns with
3875 possible mask; trailing_ampersend set in bit 8. */
3876 the_ins
.opcode
[0] |= (val
& 0x3f);
3877 the_ins
.opcode
[1] |= (((val
& 0x100) >> 8) << 5);
3880 the_ins
.opcode
[0] |= val
;
3883 /* This is a kludge!!! */
3884 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3893 the_ins
.opcode
[0] |= val
;
3895 /* more stuff goes here. */
3897 as_fatal (_("failed sanity check."));
3901 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3902 then deal with the bitfield hack. */
3905 crack_operand (char *str
, struct m68k_op
*opP
)
3907 register int parens
;
3909 register char *beg_str
;
3917 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3923 else if (*str
== ')')
3927 opP
->error
= _("Extra )");
3933 if (flag_mri
&& *str
== '\'')
3934 inquote
= ! inquote
;
3936 if (!*str
&& parens
)
3938 opP
->error
= _("Missing )");
3943 if (m68k_ip_op (beg_str
, opP
) != 0)
3950 c
= *++str
; /* JF bitfield hack. */
3955 as_bad (_("Missing operand"));
3958 /* Detect MRI REG symbols and convert them to REGLSTs. */
3959 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3962 opP
->mask
= ~(int)opP
->reg
;
3969 /* This is the guts of the machine-dependent assembler. STR points to a
3970 machine dependent instruction. This function is supposed to emit
3971 the frags/bytes it assembles to.
3975 insert_reg (const char *regname
, int regnum
)
3980 #ifdef REGISTER_PREFIX
3981 if (!flag_reg_prefix_optional
)
3983 buf
[0] = REGISTER_PREFIX
;
3984 strcpy (buf
+ 1, regname
);
3989 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3990 &zero_address_frag
));
3992 for (i
= 0; regname
[i
]; i
++)
3993 buf
[i
] = TOUPPER (regname
[i
]);
3996 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3997 &zero_address_frag
));
4006 static const struct init_entry init_table
[] =
4066 { "accext01", ACCEXT01
},
4067 { "accext23", ACCEXT23
},
4071 /* Control registers. */
4072 { "sfc", SFC
}, /* Source Function Code. */
4074 { "dfc", DFC
}, /* Destination Function Code. */
4076 { "cacr", CACR
}, /* Cache Control Register. */
4077 { "caar", CAAR
}, /* Cache Address Register. */
4078 { "cpucr", CPUCR
}, /* CPU Control Register. */
4080 { "usp", USP
}, /* User Stack Pointer. */
4081 { "vbr", VBR
}, /* Vector Base Register. */
4082 { "msp", MSP
}, /* Master Stack Pointer. */
4083 { "isp", ISP
}, /* Interrupt Stack Pointer. */
4085 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0. */
4086 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1. */
4087 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0. */
4088 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1. */
4090 /* 68ec040 versions of same */
4091 { "iacr0", ITT0
}, /* Instruction Access Control Register 0. */
4092 { "iacr1", ITT1
}, /* Instruction Access Control Register 0. */
4093 { "dacr0", DTT0
}, /* Data Access Control Register 0. */
4094 { "dacr1", DTT1
}, /* Data Access Control Register 0. */
4096 /* Coldfire versions of same. The ColdFire programmer's reference
4097 manual indicated that the order is 2,3,0,1, but Ken Rose
4098 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
4099 { "acr0", ACR0
}, /* Access Control Unit 0. */
4100 { "acr1", ACR1
}, /* Access Control Unit 1. */
4101 { "acr2", ACR2
}, /* Access Control Unit 2. */
4102 { "acr3", ACR3
}, /* Access Control Unit 3. */
4104 { "tc", TC
}, /* MMU Translation Control Register. */
4108 { "mmusr", MMUSR
}, /* MMU Status Register. */
4109 { "srp", SRP
}, /* User Root Pointer. */
4110 { "urp", URP
}, /* Supervisor Root Pointer. */
4113 { "mmubar", MMUBAR
},
4116 { "rombar", ROMBAR
}, /* ROM Base Address Register. */
4117 { "rambar0", RAMBAR0
}, /* ROM Base Address Register. */
4118 { "rambar1", RAMBAR1
}, /* ROM Base Address Register. */
4119 { "mbar", MBAR
}, /* Module Base Address Register. */
4121 { "mbar0", MBAR0
}, /* mcfv4e registers. */
4122 { "mbar1", MBAR1
}, /* mcfv4e registers. */
4123 { "rombar0", ROMBAR0
}, /* mcfv4e registers. */
4124 { "rombar1", ROMBAR1
}, /* mcfv4e registers. */
4125 { "mpcr", MPCR
}, /* mcfv4e registers. */
4126 { "edrambar", EDRAMBAR
}, /* mcfv4e registers. */
4127 { "secmbar", SECMBAR
}, /* mcfv4e registers. */
4128 { "asid", TC
}, /* mcfv4e registers. */
4129 { "mmubar", BUSCR
}, /* mcfv4e registers. */
4130 { "pcr1u0", PCR1U0
}, /* mcfv4e registers. */
4131 { "pcr1l0", PCR1L0
}, /* mcfv4e registers. */
4132 { "pcr2u0", PCR2U0
}, /* mcfv4e registers. */
4133 { "pcr2l0", PCR2L0
}, /* mcfv4e registers. */
4134 { "pcr3u0", PCR3U0
}, /* mcfv4e registers. */
4135 { "pcr3l0", PCR3L0
}, /* mcfv4e registers. */
4136 { "pcr1u1", PCR1U1
}, /* mcfv4e registers. */
4137 { "pcr1l1", PCR1L1
}, /* mcfv4e registers. */
4138 { "pcr2u1", PCR2U1
}, /* mcfv4e registers. */
4139 { "pcr2l1", PCR2L1
}, /* mcfv4e registers. */
4140 { "pcr3u1", PCR3U1
}, /* mcfv4e registers. */
4141 { "pcr3l1", PCR3L1
}, /* mcfv4e registers. */
4143 { "flashbar", FLASHBAR
}, /* mcf528x registers. */
4144 { "rambar", RAMBAR
}, /* mcf528x registers. */
4146 { "mbar2", MBAR2
}, /* mcf5249 registers. */
4148 { "cac", CAC
}, /* fido registers. */
4149 { "mbb", MBO
}, /* fido registers (obsolete). */
4150 { "mbo", MBO
}, /* fido registers. */
4151 /* End of control registers. */
4185 /* 68ec030 versions of same. */
4188 /* 68ec030 access control unit, identical to 030 MMU status reg. */
4191 /* Suppressed data and address registers. */
4209 /* Upper and lower data and address registers, used by macw and msacw. */
4250 init_regtable (void)
4253 for (i
= 0; init_table
[i
].name
; i
++)
4254 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
4258 md_assemble (char *str
)
4265 int shorts_this_frag
;
4268 if (!selected_cpu
&& !selected_arch
)
4270 /* We've not selected an architecture yet. Set the default
4271 now. We do this lazily so that an initial .cpu or .arch directive
4273 if (!m68k_set_cpu (TARGET_CPU
, 1, 1))
4274 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU
);
4279 /* In MRI mode, the instruction and operands are separated by a
4280 space. Anything following the operands is a comment. The label
4281 has already been removed. */
4289 for (s
= str
; *s
!= '\0'; s
++)
4291 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
4309 inquote
= ! inquote
;
4314 memset (&the_ins
, '\0', sizeof (the_ins
));
4319 for (n
= 0; n
< the_ins
.numargs
; n
++)
4320 if (the_ins
.operands
[n
].error
)
4322 er
= the_ins
.operands
[n
].error
;
4328 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
4332 /* If there is a current label, record that it marks an instruction. */
4333 if (current_label
!= NULL
)
4335 current_label
->text
= 1;
4336 current_label
= NULL
;
4340 /* Tie dwarf2 debug info to the address at the start of the insn. */
4341 dwarf2_emit_insn (0);
4344 if (the_ins
.nfrag
== 0)
4346 /* No frag hacking involved; just put it out. */
4347 toP
= frag_more (2 * the_ins
.numo
);
4348 fromP
= &the_ins
.opcode
[0];
4349 for (m
= the_ins
.numo
; m
; --m
)
4351 md_number_to_chars (toP
, (long) (*fromP
), 2);
4355 /* Put out symbol-dependent info. */
4356 for (m
= 0; m
< the_ins
.nrel
; m
++)
4358 switch (the_ins
.reloc
[m
].wid
)
4377 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4378 the_ins
.reloc
[m
].wid
);
4381 fixP
= fix_new_exp (frag_now
,
4382 ((toP
- frag_now
->fr_literal
)
4383 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4385 &the_ins
.reloc
[m
].exp
,
4386 the_ins
.reloc
[m
].pcrel
,
4387 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
4388 the_ins
.reloc
[m
].pic_reloc
));
4389 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4390 if (the_ins
.reloc
[m
].wid
== 'B')
4391 fixP
->fx_signed
= 1;
4396 /* There's some frag hacking. */
4398 /* Calculate the max frag size. */
4401 wid
= 2 * the_ins
.fragb
[0].fragoff
;
4402 for (n
= 1; n
< the_ins
.nfrag
; n
++)
4403 wid
+= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4404 /* frag_var part. */
4405 wid
+= FRAG_VAR_SIZE
;
4406 /* Make sure the whole insn fits in one chunk, in particular that
4407 the var part is attached, as we access one byte before the
4408 variable frag for byte branches. */
4412 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
4417 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
4419 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4420 toP
= frag_more (wid
);
4422 shorts_this_frag
= 0;
4423 for (m
= wid
/ 2; m
; --m
)
4425 md_number_to_chars (toP
, (long) (*fromP
), 2);
4430 for (m
= 0; m
< the_ins
.nrel
; m
++)
4432 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
4434 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
4437 wid
= the_ins
.reloc
[m
].wid
;
4440 the_ins
.reloc
[m
].wid
= 0;
4441 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4443 fixP
= fix_new_exp (frag_now
,
4444 ((toP
- frag_now
->fr_literal
)
4445 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4447 &the_ins
.reloc
[m
].exp
,
4448 the_ins
.reloc
[m
].pcrel
,
4449 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4450 the_ins
.reloc
[m
].pic_reloc
));
4451 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4453 (void) frag_var (rs_machine_dependent
, FRAG_VAR_SIZE
, 0,
4454 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
4455 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
4457 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4458 shorts_this_frag
= 0;
4461 toP
= frag_more (n
* 2);
4464 md_number_to_chars (toP
, (long) (*fromP
), 2);
4470 for (m
= 0; m
< the_ins
.nrel
; m
++)
4474 wid
= the_ins
.reloc
[m
].wid
;
4477 the_ins
.reloc
[m
].wid
= 0;
4478 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4480 fixP
= fix_new_exp (frag_now
,
4481 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
4482 - shorts_this_frag
* 2),
4484 &the_ins
.reloc
[m
].exp
,
4485 the_ins
.reloc
[m
].pcrel
,
4486 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4487 the_ins
.reloc
[m
].pic_reloc
));
4488 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4492 /* Comparison function used by qsort to rank the opcode entries by name. */
4495 m68k_compare_opcode (const void * v1
, const void * v2
)
4497 struct m68k_opcode
* op1
, * op2
;
4503 op1
= *(struct m68k_opcode
**) v1
;
4504 op2
= *(struct m68k_opcode
**) v2
;
4506 /* Compare the two names. If different, return the comparison.
4507 If the same, return the order they are in the opcode table. */
4508 ret
= strcmp (op1
->name
, op2
->name
);
4519 const struct m68k_opcode
*ins
;
4520 struct m68k_incant
*hack
, *slak
;
4521 const char *retval
= 0; /* Empty string, or error msg text. */
4524 /* Set up hash tables with 68000 instructions.
4525 similar to what the vax assembler does. */
4526 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4527 a copy of it at runtime, adding in the information we want but isn't
4528 there. I think it'd be better to have an awk script hack the table
4529 at compile time. Or even just xstr the table and use it as-is. But
4530 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4535 flag_reg_prefix_optional
= 1;
4537 if (! m68k_rel32_from_cmdline
)
4541 /* First sort the opcode table into alphabetical order to seperate
4542 the order that the assembler wants to see the opcodes from the
4543 order that the disassembler wants to see them. */
4544 m68k_sorted_opcodes
= xmalloc (m68k_numopcodes
* sizeof (* m68k_sorted_opcodes
));
4545 if (!m68k_sorted_opcodes
)
4546 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4547 m68k_numopcodes
* ((int) sizeof (* m68k_sorted_opcodes
)));
4549 for (i
= m68k_numopcodes
; i
--;)
4550 m68k_sorted_opcodes
[i
] = m68k_opcodes
+ i
;
4552 qsort (m68k_sorted_opcodes
, m68k_numopcodes
,
4553 sizeof (m68k_sorted_opcodes
[0]), m68k_compare_opcode
);
4555 op_hash
= hash_new ();
4557 obstack_begin (&robyn
, 4000);
4558 for (i
= 0; i
< m68k_numopcodes
; i
++)
4560 hack
= slak
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4563 ins
= m68k_sorted_opcodes
[i
];
4565 /* We must enter all insns into the table, because .arch and
4566 .cpu directives can change things. */
4567 slak
->m_operands
= ins
->args
;
4568 slak
->m_arch
= ins
->arch
;
4569 slak
->m_opcode
= ins
->opcode
;
4571 /* In most cases we can determine the number of opcode words
4572 by checking the second word of the mask. Unfortunately
4573 some instructions have 2 opcode words, but no fixed bits
4574 in the second word. A leading dot in the operands
4575 string also indicates 2 opcodes. */
4576 if (*slak
->m_operands
== '.')
4579 slak
->m_codenum
= 2;
4581 else if (ins
->match
& 0xffffL
)
4582 slak
->m_codenum
= 2;
4584 slak
->m_codenum
= 1;
4585 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
4587 if (i
+ 1 != m68k_numopcodes
4588 && !strcmp (ins
->name
, m68k_sorted_opcodes
[i
+ 1]->name
))
4590 slak
->m_next
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4595 slak
= slak
->m_next
;
4599 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
4601 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
4604 for (i
= 0; i
< m68k_numaliases
; i
++)
4606 const char *name
= m68k_opcode_aliases
[i
].primary
;
4607 const char *alias
= m68k_opcode_aliases
[i
].alias
;
4608 void *val
= hash_find (op_hash
, name
);
4611 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4612 retval
= hash_insert (op_hash
, alias
, val
);
4614 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4617 /* In MRI mode, all unsized branches are variable sized. Normally,
4618 they are word sized. */
4621 static struct m68k_opcode_alias mri_aliases
[] =
4642 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
4645 const char *name
= mri_aliases
[i
].primary
;
4646 const char *alias
= mri_aliases
[i
].alias
;
4647 void *val
= hash_find (op_hash
, name
);
4650 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4651 retval
= hash_jam (op_hash
, alias
, val
);
4653 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4657 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
4659 notend_table
[i
] = 0;
4660 alt_notend_table
[i
] = 0;
4663 notend_table
[','] = 1;
4664 notend_table
['{'] = 1;
4665 notend_table
['}'] = 1;
4666 alt_notend_table
['a'] = 1;
4667 alt_notend_table
['A'] = 1;
4668 alt_notend_table
['d'] = 1;
4669 alt_notend_table
['D'] = 1;
4670 alt_notend_table
['#'] = 1;
4671 alt_notend_table
['&'] = 1;
4672 alt_notend_table
['f'] = 1;
4673 alt_notend_table
['F'] = 1;
4674 #ifdef REGISTER_PREFIX
4675 alt_notend_table
[REGISTER_PREFIX
] = 1;
4678 /* We need to put '(' in alt_notend_table to handle
4679 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4680 alt_notend_table
['('] = 1;
4682 /* We need to put '@' in alt_notend_table to handle
4683 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4684 alt_notend_table
['@'] = 1;
4686 /* We need to put digits in alt_notend_table to handle
4687 bfextu %d0{24:1},%d0 */
4688 alt_notend_table
['0'] = 1;
4689 alt_notend_table
['1'] = 1;
4690 alt_notend_table
['2'] = 1;
4691 alt_notend_table
['3'] = 1;
4692 alt_notend_table
['4'] = 1;
4693 alt_notend_table
['5'] = 1;
4694 alt_notend_table
['6'] = 1;
4695 alt_notend_table
['7'] = 1;
4696 alt_notend_table
['8'] = 1;
4697 alt_notend_table
['9'] = 1;
4699 #ifndef MIT_SYNTAX_ONLY
4700 /* Insert pseudo ops, these have to go into the opcode table since
4701 gas expects pseudo ops to start with a dot. */
4705 while (mote_pseudo_table
[n
].poc_name
)
4707 hack
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4708 hash_insert (op_hash
,
4709 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
4710 hack
->m_operands
= 0;
4720 record_alignment (text_section
, 2);
4721 record_alignment (data_section
, 2);
4722 record_alignment (bss_section
, 2);
4727 /* This is called when a label is defined. */
4730 m68k_frob_label (symbolS
*sym
)
4732 struct label_line
*n
;
4734 n
= (struct label_line
*) xmalloc (sizeof *n
);
4737 as_where (&n
->file
, &n
->line
);
4743 dwarf2_emit_label (sym
);
4747 /* This is called when a value that is not an instruction is emitted. */
4750 m68k_flush_pending_output (void)
4752 current_label
= NULL
;
4755 /* This is called at the end of the assembly, when the final value of
4756 the label is known. We warn if this is a text symbol aligned at an
4760 m68k_frob_symbol (symbolS
*sym
)
4762 if (S_GET_SEGMENT (sym
) == reg_section
4763 && (int) S_GET_VALUE (sym
) < 0)
4765 S_SET_SEGMENT (sym
, absolute_section
);
4766 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4768 else if ((S_GET_VALUE (sym
) & 1) != 0)
4770 struct label_line
*l
;
4772 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4774 if (l
->label
== sym
)
4777 as_warn_where (l
->file
, l
->line
,
4778 _("text label `%s' aligned to odd boundary"),
4786 /* This is called if we go in or out of MRI mode because of the .mri
4790 m68k_mri_mode_change (int on
)
4794 if (! flag_reg_prefix_optional
)
4796 flag_reg_prefix_optional
= 1;
4797 #ifdef REGISTER_PREFIX
4802 if (! m68k_rel32_from_cmdline
)
4807 if (! reg_prefix_optional_seen
)
4809 #ifdef REGISTER_PREFIX_OPTIONAL
4810 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4812 flag_reg_prefix_optional
= 0;
4814 #ifdef REGISTER_PREFIX
4819 if (! m68k_rel32_from_cmdline
)
4825 md_atof (int type
, char *litP
, int *sizeP
)
4827 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
4831 md_number_to_chars (char *buf
, valueT val
, int n
)
4833 number_to_chars_bigendian (buf
, val
, n
);
4837 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
4839 offsetT val
= *valP
;
4840 addressT upper_limit
;
4841 offsetT lower_limit
;
4843 /* This is unnecessary but it convinces the native rs6000 compiler
4844 to generate the code we want. */
4845 char *buf
= fixP
->fx_frag
->fr_literal
;
4846 buf
+= fixP
->fx_where
;
4847 /* End ibm compiler workaround. */
4851 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4857 memset (buf
, 0, fixP
->fx_size
);
4858 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4860 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4861 && !S_IS_DEFINED (fixP
->fx_addsy
)
4862 && !S_IS_WEAK (fixP
->fx_addsy
))
4863 S_SET_WEAK (fixP
->fx_addsy
);
4865 switch (fixP
->fx_r_type
)
4867 case BFD_RELOC_68K_TLS_GD32
:
4868 case BFD_RELOC_68K_TLS_GD16
:
4869 case BFD_RELOC_68K_TLS_GD8
:
4870 case BFD_RELOC_68K_TLS_LDM32
:
4871 case BFD_RELOC_68K_TLS_LDM16
:
4872 case BFD_RELOC_68K_TLS_LDM8
:
4873 case BFD_RELOC_68K_TLS_LDO32
:
4874 case BFD_RELOC_68K_TLS_LDO16
:
4875 case BFD_RELOC_68K_TLS_LDO8
:
4876 case BFD_RELOC_68K_TLS_IE32
:
4877 case BFD_RELOC_68K_TLS_IE16
:
4878 case BFD_RELOC_68K_TLS_IE8
:
4879 case BFD_RELOC_68K_TLS_LE32
:
4880 case BFD_RELOC_68K_TLS_LE16
:
4881 case BFD_RELOC_68K_TLS_LE8
:
4882 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
4891 #elif defined(OBJ_AOUT)
4892 /* PR gas/3041 Do not fix frags referencing a weak symbol. */
4893 if (fixP
->fx_addsy
&& S_IS_WEAK (fixP
->fx_addsy
))
4895 memset (buf
, 0, fixP
->fx_size
);
4896 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4901 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4902 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4905 switch (fixP
->fx_size
)
4907 /* The cast to offsetT below are necessary to make code
4908 correct for machines where ints are smaller than offsetT. */
4912 lower_limit
= - (offsetT
) 0x80;
4915 *buf
++ = (val
>> 8);
4917 upper_limit
= 0x7fff;
4918 lower_limit
= - (offsetT
) 0x8000;
4921 *buf
++ = (val
>> 24);
4922 *buf
++ = (val
>> 16);
4923 *buf
++ = (val
>> 8);
4925 upper_limit
= 0x7fffffff;
4926 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* Avoid constant overflow. */
4929 BAD_CASE (fixP
->fx_size
);
4932 /* Fix up a negative reloc. */
4933 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4935 fixP
->fx_addsy
= fixP
->fx_subsy
;
4936 fixP
->fx_subsy
= NULL
;
4940 /* For non-pc-relative values, it's conceivable we might get something
4941 like "0xff" for a byte field. So extend the upper part of the range
4942 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4943 so that we can do any range checking at all. */
4944 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4945 upper_limit
= upper_limit
* 2 + 1;
4947 if ((addressT
) val
> upper_limit
4948 && (val
> 0 || val
< lower_limit
))
4949 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4950 _("value %ld out of range"), (long)val
);
4952 /* A one byte PC-relative reloc means a short branch. We can't use
4953 a short branch with a value of 0 or -1, because those indicate
4954 different opcodes (branches with longer offsets). fixup_segment
4955 in write.c may have clobbered fx_pcrel, so we need to examine the
4958 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
4959 && fixP
->fx_size
== 1
4960 && (fixP
->fx_addsy
== NULL
4961 || S_IS_DEFINED (fixP
->fx_addsy
))
4962 && (val
== 0 || val
== -1))
4963 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4964 _("invalid byte branch offset"));
4967 /* *fragP has been relaxed to its final size, and now needs to have
4968 the bytes inside it modified to conform to the new size There is UGLY
4972 md_convert_frag_1 (fragS
*fragP
)
4977 /* Address in object code of the displacement. */
4978 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4980 /* Address in gas core of the place to store the displacement. */
4981 /* This convinces the native rs6000 compiler to generate the code we
4983 register char *buffer_address
= fragP
->fr_literal
;
4984 buffer_address
+= fragP
->fr_fix
;
4985 /* End ibm compiler workaround. */
4987 /* The displacement of the address, from current location. */
4988 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4989 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4991 switch (fragP
->fr_subtype
)
4993 case TAB (BRANCHBWL
, BYTE
):
4994 case TAB (BRABSJUNC
, BYTE
):
4995 case TAB (BRABSJCOND
, BYTE
):
4996 case TAB (BRANCHBW
, BYTE
):
4997 case TAB (BRANCHBWPL
, BYTE
):
4998 know (issbyte (disp
));
5000 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5001 _("short branch with zero offset: use :w"));
5002 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
5003 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
5004 fixP
->fx_pcrel_adjust
= -1;
5006 case TAB (BRANCHBWL
, SHORT
):
5007 case TAB (BRABSJUNC
, SHORT
):
5008 case TAB (BRABSJCOND
, SHORT
):
5009 case TAB (BRANCHBW
, SHORT
):
5010 case TAB (BRANCHBWPL
, SHORT
):
5011 fragP
->fr_opcode
[1] = 0x00;
5012 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5013 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5016 case TAB (BRANCHBWL
, LONG
):
5017 fragP
->fr_opcode
[1] = (char) 0xFF;
5018 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5019 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5022 case TAB (BRANCHBWPL
, LONG
):
5023 /* Here we are converting an unconditional branch into a pair of
5024 conditional branches, in order to get the range. */
5025 fragP
->fr_opcode
[0] = 0x66; /* bne */
5026 fragP
->fr_opcode
[1] = 0xFF;
5027 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5028 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5029 fixP
->fx_file
= fragP
->fr_file
;
5030 fixP
->fx_line
= fragP
->fr_line
;
5031 fragP
->fr_fix
+= 4; /* Skip first offset */
5032 buffer_address
+= 4;
5033 *buffer_address
++ = 0x67; /* beq */
5034 *buffer_address
++ = 0xff;
5035 fragP
->fr_fix
+= 2; /* Skip second branch opcode */
5036 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5037 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5040 case TAB (BRABSJUNC
, LONG
):
5041 if (fragP
->fr_opcode
[0] == 0x61) /* jbsr */
5043 if (flag_keep_pcrel
)
5044 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5045 _("Conversion of PC relative BSR to absolute JSR"));
5046 fragP
->fr_opcode
[0] = 0x4E;
5047 fragP
->fr_opcode
[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
5048 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5049 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5052 else if (fragP
->fr_opcode
[0] == 0x60) /* jbra */
5054 if (flag_keep_pcrel
)
5055 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5056 _("Conversion of PC relative branch to absolute jump"));
5057 fragP
->fr_opcode
[0] = 0x4E;
5058 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
5059 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5060 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5065 /* This cannot happen, because jbsr and jbra are the only two
5066 unconditional branches. */
5070 case TAB (BRABSJCOND
, LONG
):
5071 if (flag_keep_pcrel
)
5072 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5073 _("Conversion of PC relative conditional branch to absolute jump"));
5075 /* Only Bcc 68000 instructions can come here
5076 Change bcc into b!cc/jmp absl long. */
5077 fragP
->fr_opcode
[0] ^= 0x01; /* Invert bcc. */
5078 fragP
->fr_opcode
[1] = 0x06; /* Branch offset = 6. */
5080 /* JF: these used to be fr_opcode[2,3], but they may be in a
5081 different frag, in which case referring to them is a no-no.
5082 Only fr_opcode[0,1] are guaranteed to work. */
5083 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
5084 *buffer_address
++ = (char) 0xf9;
5085 fragP
->fr_fix
+= 2; /* Account for jmp instruction. */
5086 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5087 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5090 case TAB (FBRANCH
, SHORT
):
5091 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
5092 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5093 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5096 case TAB (FBRANCH
, LONG
):
5097 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit. */
5098 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5099 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5102 case TAB (DBCCLBR
, SHORT
):
5103 case TAB (DBCCABSJ
, SHORT
):
5104 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5105 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5108 case TAB (DBCCLBR
, LONG
):
5109 /* Only DBcc instructions can come here.
5110 Change dbcc into dbcc/bral.
5111 JF: these used to be fr_opcode[2-7], but that's wrong. */
5112 if (flag_keep_pcrel
)
5113 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5114 _("Conversion of DBcc to absolute jump"));
5116 *buffer_address
++ = 0x00; /* Branch offset = 4. */
5117 *buffer_address
++ = 0x04;
5118 *buffer_address
++ = 0x60; /* Put in bra pc+6. */
5119 *buffer_address
++ = 0x06;
5120 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
5121 *buffer_address
++ = (char) 0xff;
5123 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
5124 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5125 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5128 case TAB (DBCCABSJ
, LONG
):
5129 /* Only DBcc instructions can come here.
5130 Change dbcc into dbcc/jmp.
5131 JF: these used to be fr_opcode[2-7], but that's wrong. */
5132 if (flag_keep_pcrel
)
5133 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5134 _("Conversion of PC relative conditional branch to absolute jump"));
5136 *buffer_address
++ = 0x00; /* Branch offset = 4. */
5137 *buffer_address
++ = 0x04;
5138 *buffer_address
++ = 0x60; /* Put in bra pc + 6. */
5139 *buffer_address
++ = 0x06;
5140 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
5141 *buffer_address
++ = (char) 0xf9;
5143 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
5144 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5145 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5148 case TAB (PCREL1632
, SHORT
):
5149 fragP
->fr_opcode
[1] &= ~0x3F;
5150 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
5151 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
5152 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5155 case TAB (PCREL1632
, LONG
):
5156 /* Already set to mode 7.3; this indicates: PC indirect with
5157 suppressed index, 32-bit displacement. */
5158 *buffer_address
++ = 0x01;
5159 *buffer_address
++ = 0x70;
5161 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
5162 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5163 fixP
->fx_pcrel_adjust
= 2;
5166 case TAB (PCINDEX
, BYTE
):
5167 assert (fragP
->fr_fix
>= 2);
5168 buffer_address
[-2] &= ~1;
5169 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
5170 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
5171 fixP
->fx_pcrel_adjust
= 1;
5173 case TAB (PCINDEX
, SHORT
):
5174 assert (fragP
->fr_fix
>= 2);
5175 buffer_address
[-2] |= 0x1;
5176 buffer_address
[-1] = 0x20;
5177 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
5178 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5179 fixP
->fx_pcrel_adjust
= 2;
5182 case TAB (PCINDEX
, LONG
):
5183 assert (fragP
->fr_fix
>= 2);
5184 buffer_address
[-2] |= 0x1;
5185 buffer_address
[-1] = 0x30;
5186 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
5187 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5188 fixP
->fx_pcrel_adjust
= 2;
5191 case TAB (ABSTOPCREL
, SHORT
):
5192 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5193 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5196 case TAB (ABSTOPCREL
, LONG
):
5197 if (flag_keep_pcrel
)
5198 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5199 _("Conversion of PC relative displacement to absolute"));
5200 /* The thing to do here is force it to ABSOLUTE LONG, since
5201 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
5202 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
5204 fragP
->fr_opcode
[1] &= ~0x3F;
5205 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
5206 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5207 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5213 fixP
->fx_file
= fragP
->fr_file
;
5214 fixP
->fx_line
= fragP
->fr_line
;
5219 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5220 segT sec ATTRIBUTE_UNUSED
,
5223 md_convert_frag_1 (fragP
);
5226 /* Force truly undefined symbols to their maximum size, and generally set up
5227 the frag list to be relaxed
5230 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
5232 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
5233 switch (fragP
->fr_subtype
)
5235 case TAB (BRANCHBWL
, SZ_UNDEF
):
5236 case TAB (BRANCHBWPL
, SZ_UNDEF
):
5237 case TAB (BRABSJUNC
, SZ_UNDEF
):
5238 case TAB (BRABSJCOND
, SZ_UNDEF
):
5240 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5241 && relaxable_symbol (fragP
->fr_symbol
))
5243 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5245 else if (flag_short_refs
)
5247 /* Symbol is undefined and we want short ref. */
5248 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5252 /* Symbol is still undefined. Make it LONG. */
5253 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5258 case TAB (BRANCHBW
, SZ_UNDEF
):
5260 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5261 && relaxable_symbol (fragP
->fr_symbol
))
5263 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5267 /* Symbol is undefined and we don't have long branches. */
5268 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5273 case TAB (FBRANCH
, SZ_UNDEF
):
5274 case TAB (DBCCLBR
, SZ_UNDEF
):
5275 case TAB (DBCCABSJ
, SZ_UNDEF
):
5276 case TAB (PCREL1632
, SZ_UNDEF
):
5278 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5279 && relaxable_symbol (fragP
->fr_symbol
))
5282 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5286 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5291 case TAB (PCINDEX
, SZ_UNDEF
):
5292 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5293 && relaxable_symbol (fragP
->fr_symbol
)))
5295 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
5299 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
5303 case TAB (ABSTOPCREL
, SZ_UNDEF
):
5305 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5306 && relaxable_symbol (fragP
->fr_symbol
)))
5308 fragP
->fr_subtype
= TAB (ABSTOPCREL
, SHORT
);
5312 fragP
->fr_subtype
= TAB (ABSTOPCREL
, LONG
);
5321 /* Now that SZ_UNDEF are taken care of, check others. */
5322 switch (fragP
->fr_subtype
)
5324 case TAB (BRANCHBWL
, BYTE
):
5325 case TAB (BRABSJUNC
, BYTE
):
5326 case TAB (BRABSJCOND
, BYTE
):
5327 case TAB (BRANCHBW
, BYTE
):
5328 /* We can't do a short jump to the next instruction, so in that
5329 case we force word mode. If the symbol is at the start of a
5330 frag, and it is the next frag with any data in it (usually
5331 this is just the next frag, but assembler listings may
5332 introduce empty frags), we must use word mode. */
5333 if (fragP
->fr_symbol
)
5337 sym_frag
= symbol_get_frag (fragP
->fr_symbol
);
5338 if (S_GET_VALUE (fragP
->fr_symbol
) == sym_frag
->fr_address
)
5342 for (l
= fragP
->fr_next
; l
&& l
!= sym_frag
; l
= l
->fr_next
)
5346 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5353 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5356 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5357 /* the bit-field entries in the relocation_info struct plays hell
5358 with the byte-order problems of cross-assembly. So as a hack,
5359 I added this mach. dependent ri twiddler. Ugly, but it gets
5361 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5362 are symbolnum, most sig. byte first. Last byte is broken up with
5363 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5364 nibble as nuthin. (on Sun 3 at least) */
5365 /* Translate the internal relocation information into target-specific
5369 md_ri_to_chars (char *the_bytes
, struct reloc_info_generic
*ri
)
5372 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
5373 /* Now the fun stuff. */
5374 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
5375 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
5376 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
5377 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80)
5378 | ((ri
->r_length
<< 5) & 0x60)
5379 | ((ri
->r_extern
<< 4) & 0x10));
5384 #endif /* OBJ_AOUT or OBJ_BOUT */
5386 #ifndef WORKING_DOT_WORD
5387 int md_short_jump_size
= 4;
5388 int md_long_jump_size
= 6;
5391 md_create_short_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5392 fragS
*frag ATTRIBUTE_UNUSED
,
5393 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
5397 offset
= to_addr
- (from_addr
+ 2);
5399 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
5400 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
5404 md_create_long_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5405 fragS
*frag
, symbolS
*to_symbol
)
5409 if (!HAVE_LONG_BRANCH (current_architecture
))
5411 if (flag_keep_pcrel
)
5412 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5413 offset
= to_addr
- S_GET_VALUE (to_symbol
);
5414 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
5415 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5416 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
5421 offset
= to_addr
- (from_addr
+ 2);
5422 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
5423 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5429 /* Different values of OK tell what its OK to return. Things that
5430 aren't OK are an error (what a shock, no?)
5433 10: Absolute 1:8 only
5434 20: Absolute 0:7 only
5435 30: absolute 0:15 only
5436 40: Absolute 0:31 only
5437 50: absolute 0:127 only
5438 55: absolute -64:63 only
5439 60: absolute -128:127 only
5440 65: absolute 0:511 only
5441 70: absolute 0:4095 only
5442 80: absolute -1, 1:7 only
5446 get_num (struct m68k_exp
*exp
, int ok
)
5448 if (exp
->exp
.X_op
== O_absent
)
5450 /* Do the same thing the VAX asm does. */
5451 op (exp
) = O_constant
;
5457 as_warn (_("expression out of range: defaulting to 1"));
5461 else if (exp
->exp
.X_op
== O_constant
)
5466 if ((valueT
) TRUNC (offs (exp
)) - 1 > 7)
5468 as_warn (_("expression out of range: defaulting to 1"));
5473 if ((valueT
) TRUNC (offs (exp
)) > 7)
5477 if ((valueT
) TRUNC (offs (exp
)) > 15)
5481 if ((valueT
) TRUNC (offs (exp
)) > 32)
5485 if ((valueT
) TRUNC (offs (exp
)) > 127)
5489 if ((valueT
) SEXT (offs (exp
)) + 64 > 127)
5493 if ((valueT
) SEXT (offs (exp
)) + 128 > 255)
5497 if ((valueT
) TRUNC (offs (exp
)) > 511)
5501 if ((valueT
) TRUNC (offs (exp
)) > 4095)
5504 as_warn (_("expression out of range: defaulting to 0"));
5509 if ((valueT
) TRUNC (offs (exp
)) != 0xffffffff
5510 && (valueT
) TRUNC (offs (exp
)) - 1 > 6)
5512 as_warn (_("expression out of range: defaulting to 1"));
5520 else if (exp
->exp
.X_op
== O_big
)
5522 if (offs (exp
) <= 0 /* flonum. */
5523 && (ok
== 90 /* no bignums */
5524 || (ok
> 10 /* Small-int ranges including 0 ok. */
5525 /* If we have a flonum zero, a zero integer should
5526 do as well (e.g., in moveq). */
5527 && generic_floating_point_number
.exponent
== 0
5528 && generic_floating_point_number
.low
[0] == 0)))
5530 /* HACK! Turn it into a long. */
5531 LITTLENUM_TYPE words
[6];
5533 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5534 op (exp
) = O_constant
;
5537 offs (exp
) = words
[1] | (words
[0] << 16);
5541 op (exp
) = O_constant
;
5544 offs (exp
) = (ok
== 10) ? 1 : 0;
5545 as_warn (_("Can't deal with expression; defaulting to %ld"),
5551 if (ok
>= 10 && ok
<= 80)
5553 op (exp
) = O_constant
;
5556 offs (exp
) = (ok
== 10) ? 1 : 0;
5557 as_warn (_("Can't deal with expression; defaulting to %ld"),
5562 if (exp
->size
!= SIZE_UNSPEC
)
5570 if (!isbyte (offs (exp
)))
5571 as_warn (_("expression doesn't fit in BYTE"));
5574 if (!isword (offs (exp
)))
5575 as_warn (_("expression doesn't fit in WORD"));
5583 /* These are the back-ends for the various machine dependent pseudo-ops. */
5586 s_data1 (int ignore ATTRIBUTE_UNUSED
)
5588 subseg_set (data_section
, 1);
5589 demand_empty_rest_of_line ();
5593 s_data2 (int ignore ATTRIBUTE_UNUSED
)
5595 subseg_set (data_section
, 2);
5596 demand_empty_rest_of_line ();
5600 s_bss (int ignore ATTRIBUTE_UNUSED
)
5602 /* We don't support putting frags in the BSS segment, we fake it
5603 by marking in_bss, then looking at s_skip for clues. */
5605 subseg_set (bss_section
, 0);
5606 demand_empty_rest_of_line ();
5610 s_even (int ignore ATTRIBUTE_UNUSED
)
5613 register long temp_fill
;
5615 temp
= 1; /* JF should be 2? */
5616 temp_fill
= get_absolute_expression ();
5617 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5618 frag_align (temp
, (int) temp_fill
, 0);
5619 demand_empty_rest_of_line ();
5620 record_alignment (now_seg
, temp
);
5624 s_proc (int ignore ATTRIBUTE_UNUSED
)
5626 demand_empty_rest_of_line ();
5629 /* Pseudo-ops handled for MRI compatibility. */
5631 /* This function returns non-zero if the argument is a conditional
5632 pseudo-op. This is called when checking whether a pending
5633 alignment is needed. */
5636 m68k_conditional_pseudoop (pseudo_typeS
*pop
)
5638 return (pop
->poc_handler
== s_mri_if
5639 || pop
->poc_handler
== s_mri_else
);
5642 /* Handle an MRI style chip specification. */
5651 s
= input_line_pointer
;
5652 /* We can't use get_symbol_end since the processor names are not proper
5654 while (is_part_of_name (c
= *input_line_pointer
++))
5656 *--input_line_pointer
= 0;
5657 for (i
= 0; m68k_cpus
[i
].name
; i
++)
5658 if (strcasecmp (s
, m68k_cpus
[i
].name
) == 0)
5660 if (!m68k_cpus
[i
].name
)
5662 as_bad (_("%s: unrecognized processor name"), s
);
5663 *input_line_pointer
= c
;
5664 ignore_rest_of_line ();
5667 *input_line_pointer
= c
;
5669 if (*input_line_pointer
== '/')
5670 current_architecture
= 0;
5672 current_architecture
&= m68881
| m68851
;
5673 current_architecture
|= m68k_cpus
[i
].arch
& ~(m68881
| m68851
);
5674 control_regs
= m68k_cpus
[i
].control_regs
;
5676 while (*input_line_pointer
== '/')
5678 ++input_line_pointer
;
5679 s
= input_line_pointer
;
5680 /* We can't use get_symbol_end since the processor names are not
5682 while (is_part_of_name (c
= *input_line_pointer
++))
5684 *--input_line_pointer
= 0;
5685 if (strcmp (s
, "68881") == 0)
5686 current_architecture
|= m68881
;
5687 else if (strcmp (s
, "68851") == 0)
5688 current_architecture
|= m68851
;
5689 *input_line_pointer
= c
;
5693 /* The MRI CHIP pseudo-op. */
5696 s_chip (int ignore ATTRIBUTE_UNUSED
)
5702 stop
= mri_comment_field (&stopc
);
5705 mri_comment_end (stop
, stopc
);
5706 demand_empty_rest_of_line ();
5709 /* The MRI FOPT pseudo-op. */
5712 s_fopt (int ignore ATTRIBUTE_UNUSED
)
5716 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5720 input_line_pointer
+= 3;
5721 temp
= get_absolute_expression ();
5722 if (temp
< 0 || temp
> 7)
5723 as_bad (_("bad coprocessor id"));
5725 m68k_float_copnum
= COP0
+ temp
;
5729 as_bad (_("unrecognized fopt option"));
5730 ignore_rest_of_line ();
5734 demand_empty_rest_of_line ();
5737 /* The structure used to handle the MRI OPT pseudo-op. */
5741 /* The name of the option. */
5744 /* If this is not NULL, just call this function. The first argument
5745 is the ARG field of this structure, the second argument is
5746 whether the option was negated. */
5747 void (*pfn
) (int arg
, int on
);
5749 /* If this is not NULL, and the PFN field is NULL, set the variable
5750 this points to. Set it to the ARG field if the option was not
5751 negated, and the NOTARG field otherwise. */
5754 /* The value to pass to PFN or to assign to *PVAR. */
5757 /* The value to assign to *PVAR if the option is negated. If PFN is
5758 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5759 the option may not be negated. */
5763 /* The table used to handle the MRI OPT pseudo-op. */
5765 static void skip_to_comma (int, int);
5766 static void opt_nest (int, int);
5767 static void opt_chip (int, int);
5768 static void opt_list (int, int);
5769 static void opt_list_symbols (int, int);
5771 static const struct opt_action opt_table
[] =
5773 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5775 /* We do relaxing, so there is little use for these options. */
5776 { "b", 0, 0, 0, 0 },
5777 { "brs", 0, 0, 0, 0 },
5778 { "brb", 0, 0, 0, 0 },
5779 { "brl", 0, 0, 0, 0 },
5780 { "brw", 0, 0, 0, 0 },
5782 { "c", 0, 0, 0, 0 },
5783 { "cex", 0, 0, 0, 0 },
5784 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5785 { "cl", 0, 0, 0, 0 },
5786 { "cre", 0, 0, 0, 0 },
5787 { "d", 0, &flag_keep_locals
, 1, 0 },
5788 { "e", 0, 0, 0, 0 },
5789 { "f", 0, &flag_short_refs
, 1, 0 },
5790 { "frs", 0, &flag_short_refs
, 1, 0 },
5791 { "frl", 0, &flag_short_refs
, 0, 1 },
5792 { "g", 0, 0, 0, 0 },
5793 { "i", 0, 0, 0, 0 },
5794 { "m", 0, 0, 0, 0 },
5795 { "mex", 0, 0, 0, 0 },
5796 { "mc", 0, 0, 0, 0 },
5797 { "md", 0, 0, 0, 0 },
5798 { "nest", opt_nest
, 0, 0, 0 },
5799 { "next", skip_to_comma
, 0, 0, 0 },
5800 { "o", 0, 0, 0, 0 },
5801 { "old", 0, 0, 0, 0 },
5802 { "op", skip_to_comma
, 0, 0, 0 },
5803 { "pco", 0, 0, 0, 0 },
5804 { "p", opt_chip
, 0, 0, 0 },
5805 { "pcr", 0, 0, 0, 0 },
5806 { "pcs", 0, 0, 0, 0 },
5807 { "r", 0, 0, 0, 0 },
5808 { "quick", 0, &m68k_quick
, 1, 0 },
5809 { "rel32", 0, &m68k_rel32
, 1, 0 },
5810 { "s", opt_list
, 0, 0, 0 },
5811 { "t", opt_list_symbols
, 0, 0, 0 },
5812 { "w", 0, &flag_no_warnings
, 0, 1 },
5816 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5818 /* The MRI OPT pseudo-op. */
5821 s_opt (int ignore ATTRIBUTE_UNUSED
)
5829 const struct opt_action
*o
;
5834 if (*input_line_pointer
== '-')
5836 ++input_line_pointer
;
5839 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5841 input_line_pointer
+= 2;
5845 s
= input_line_pointer
;
5846 c
= get_symbol_end ();
5848 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5850 if (strcasecmp (s
, o
->name
) == 0)
5854 /* Restore input_line_pointer now in case the option
5856 *input_line_pointer
= c
;
5857 (*o
->pfn
) (o
->arg
, t
);
5859 else if (o
->pvar
!= NULL
)
5861 if (! t
&& o
->arg
== o
->notarg
)
5862 as_bad (_("option `%s' may not be negated"), s
);
5863 *input_line_pointer
= c
;
5864 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5867 *input_line_pointer
= c
;
5873 as_bad (_("option `%s' not recognized"), s
);
5874 *input_line_pointer
= c
;
5877 while (*input_line_pointer
++ == ',');
5879 /* Move back to terminating character. */
5880 --input_line_pointer
;
5881 demand_empty_rest_of_line ();
5884 /* Skip ahead to a comma. This is used for OPT options which we do
5885 not support and which take arguments. */
5888 skip_to_comma (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5890 while (*input_line_pointer
!= ','
5891 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5892 ++input_line_pointer
;
5895 /* Handle the OPT NEST=depth option. */
5898 opt_nest (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5900 if (*input_line_pointer
!= '=')
5902 as_bad (_("bad format of OPT NEST=depth"));
5906 ++input_line_pointer
;
5907 max_macro_nest
= get_absolute_expression ();
5910 /* Handle the OPT P=chip option. */
5913 opt_chip (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5915 if (*input_line_pointer
!= '=')
5917 /* This is just OPT P, which we do not support. */
5921 ++input_line_pointer
;
5925 /* Handle the OPT S option. */
5928 opt_list (int arg ATTRIBUTE_UNUSED
, int on
)
5933 /* Handle the OPT T option. */
5936 opt_list_symbols (int arg ATTRIBUTE_UNUSED
, int on
)
5939 listing
|= LISTING_SYMBOLS
;
5941 listing
&= ~LISTING_SYMBOLS
;
5944 /* Handle the MRI REG pseudo-op. */
5947 s_reg (int ignore ATTRIBUTE_UNUSED
)
5956 if (line_label
== NULL
)
5958 as_bad (_("missing label"));
5959 ignore_rest_of_line ();
5964 stop
= mri_comment_field (&stopc
);
5968 s
= input_line_pointer
;
5969 while (ISALNUM (*input_line_pointer
)
5970 #ifdef REGISTER_PREFIX
5971 || *input_line_pointer
== REGISTER_PREFIX
5973 || *input_line_pointer
== '/'
5974 || *input_line_pointer
== '-')
5975 ++input_line_pointer
;
5976 c
= *input_line_pointer
;
5977 *input_line_pointer
= '\0';
5979 if (m68k_ip_op (s
, &rop
) != 0)
5981 if (rop
.error
== NULL
)
5982 as_bad (_("bad register list"));
5984 as_bad (_("bad register list: %s"), rop
.error
);
5985 *input_line_pointer
= c
;
5986 ignore_rest_of_line ();
5990 *input_line_pointer
= c
;
5992 if (rop
.mode
== REGLST
)
5994 else if (rop
.mode
== DREG
)
5995 mask
= 1 << (rop
.reg
- DATA0
);
5996 else if (rop
.mode
== AREG
)
5997 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5998 else if (rop
.mode
== FPREG
)
5999 mask
= 1 << (rop
.reg
- FP0
+ 16);
6000 else if (rop
.mode
== CONTROL
6003 else if (rop
.mode
== CONTROL
6006 else if (rop
.mode
== CONTROL
6011 as_bad (_("bad register list"));
6012 ignore_rest_of_line ();
6016 S_SET_SEGMENT (line_label
, reg_section
);
6017 S_SET_VALUE (line_label
, ~mask
);
6018 symbol_set_frag (line_label
, &zero_address_frag
);
6021 mri_comment_end (stop
, stopc
);
6023 demand_empty_rest_of_line ();
6026 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
6030 struct save_opts
*next
;
6032 int symbols_case_sensitive
;
6036 const enum m68k_register
*control_regs
;
6041 /* FIXME: We don't save OPT S. */
6044 /* This variable holds the stack of saved options. */
6046 static struct save_opts
*save_stack
;
6048 /* The MRI SAVE pseudo-op. */
6051 s_save (int ignore ATTRIBUTE_UNUSED
)
6053 struct save_opts
*s
;
6055 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
6056 s
->abspcadd
= m68k_abspcadd
;
6057 s
->symbols_case_sensitive
= symbols_case_sensitive
;
6058 s
->keep_locals
= flag_keep_locals
;
6059 s
->short_refs
= flag_short_refs
;
6060 s
->architecture
= current_architecture
;
6061 s
->control_regs
= control_regs
;
6062 s
->quick
= m68k_quick
;
6063 s
->rel32
= m68k_rel32
;
6064 s
->listing
= listing
;
6065 s
->no_warnings
= flag_no_warnings
;
6067 s
->next
= save_stack
;
6070 demand_empty_rest_of_line ();
6073 /* The MRI RESTORE pseudo-op. */
6076 s_restore (int ignore ATTRIBUTE_UNUSED
)
6078 struct save_opts
*s
;
6080 if (save_stack
== NULL
)
6082 as_bad (_("restore without save"));
6083 ignore_rest_of_line ();
6088 save_stack
= s
->next
;
6090 m68k_abspcadd
= s
->abspcadd
;
6091 symbols_case_sensitive
= s
->symbols_case_sensitive
;
6092 flag_keep_locals
= s
->keep_locals
;
6093 flag_short_refs
= s
->short_refs
;
6094 current_architecture
= s
->architecture
;
6095 control_regs
= s
->control_regs
;
6096 m68k_quick
= s
->quick
;
6097 m68k_rel32
= s
->rel32
;
6098 listing
= s
->listing
;
6099 flag_no_warnings
= s
->no_warnings
;
6103 demand_empty_rest_of_line ();
6106 /* Types of MRI structured control directives. */
6108 enum mri_control_type
6116 /* This structure is used to stack the MRI structured control
6119 struct mri_control_info
6121 /* The directive within which this one is enclosed. */
6122 struct mri_control_info
*outer
;
6124 /* The type of directive. */
6125 enum mri_control_type type
;
6127 /* Whether an ELSE has been in an IF. */
6130 /* The add or sub statement at the end of a FOR. */
6133 /* The label of the top of a FOR or REPEAT loop. */
6136 /* The label to jump to for the next iteration, or the else
6137 expression of a conditional. */
6140 /* The label to jump to to break out of the loop, or the label past
6141 the end of a conditional. */
6145 /* The stack of MRI structured control directives. */
6147 static struct mri_control_info
*mri_control_stack
;
6149 /* The current MRI structured control directive index number, used to
6150 generate label names. */
6152 static int mri_control_index
;
6154 /* Assemble an instruction for an MRI structured control directive. */
6157 mri_assemble (char *str
)
6161 /* md_assemble expects the opcode to be in lower case. */
6162 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
6168 /* Generate a new MRI label structured control directive label name. */
6171 mri_control_label (void)
6175 n
= (char *) xmalloc (20);
6176 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
6177 ++mri_control_index
;
6181 /* Create a new MRI structured control directive. */
6183 static struct mri_control_info
*
6184 push_mri_control (enum mri_control_type type
)
6186 struct mri_control_info
*n
;
6188 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
6192 if (type
== mri_if
|| type
== mri_while
)
6195 n
->top
= mri_control_label ();
6196 n
->next
= mri_control_label ();
6197 n
->bottom
= mri_control_label ();
6199 n
->outer
= mri_control_stack
;
6200 mri_control_stack
= n
;
6205 /* Pop off the stack of MRI structured control directives. */
6208 pop_mri_control (void)
6210 struct mri_control_info
*n
;
6212 n
= mri_control_stack
;
6213 mri_control_stack
= n
->outer
;
6221 /* Recognize a condition code in an MRI structured control expression. */
6224 parse_mri_condition (int *pcc
)
6228 know (*input_line_pointer
== '<');
6230 ++input_line_pointer
;
6231 c1
= *input_line_pointer
++;
6232 c2
= *input_line_pointer
++;
6234 if (*input_line_pointer
!= '>')
6236 as_bad (_("syntax error in structured control directive"));
6240 ++input_line_pointer
;
6246 *pcc
= (c1
<< 8) | c2
;
6251 /* Parse a single operand in an MRI structured control expression. */
6254 parse_mri_control_operand (int *pcc
, char **leftstart
, char **leftstop
,
6255 char **rightstart
, char **rightstop
)
6267 if (*input_line_pointer
== '<')
6269 /* It's just a condition code. */
6270 return parse_mri_condition (pcc
);
6273 /* Look ahead for the condition code. */
6274 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6276 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
6281 as_bad (_("missing condition code in structured control directive"));
6285 *leftstart
= input_line_pointer
;
6287 if (*leftstop
> *leftstart
6288 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
6291 input_line_pointer
= s
;
6292 if (! parse_mri_condition (pcc
))
6295 /* Look ahead for AND or OR or end of line. */
6296 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6298 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6299 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6301 if ((s
== input_line_pointer
6304 && ((strncasecmp (s
, "AND", 3) == 0
6305 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
6306 || (strncasecmp (s
, "OR", 2) == 0
6307 && (s
[2] == '.' || ! is_part_of_name (s
[2])))))
6311 *rightstart
= input_line_pointer
;
6313 if (*rightstop
> *rightstart
6314 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
6317 input_line_pointer
= s
;
6322 #define MCC(b1, b2) (((b1) << 8) | (b2))
6324 /* Swap the sense of a condition. This changes the condition so that
6325 it generates the same result when the operands are swapped. */
6328 swap_mri_condition (int cc
)
6332 case MCC ('h', 'i'): return MCC ('c', 's');
6333 case MCC ('l', 's'): return MCC ('c', 'c');
6334 /* <HS> is an alias for <CC>. */
6335 case MCC ('h', 's'):
6336 case MCC ('c', 'c'): return MCC ('l', 's');
6337 /* <LO> is an alias for <CS>. */
6338 case MCC ('l', 'o'):
6339 case MCC ('c', 's'): return MCC ('h', 'i');
6340 case MCC ('p', 'l'): return MCC ('m', 'i');
6341 case MCC ('m', 'i'): return MCC ('p', 'l');
6342 case MCC ('g', 'e'): return MCC ('l', 'e');
6343 case MCC ('l', 't'): return MCC ('g', 't');
6344 case MCC ('g', 't'): return MCC ('l', 't');
6345 case MCC ('l', 'e'): return MCC ('g', 'e');
6346 /* Issue a warning for conditions we can not swap. */
6347 case MCC ('n', 'e'): return MCC ('n', 'e'); /* no problem here */
6348 case MCC ('e', 'q'): return MCC ('e', 'q'); /* also no problem */
6349 case MCC ('v', 'c'):
6350 case MCC ('v', 's'):
6352 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6353 (char) (cc
>> 8), (char) (cc
));
6359 /* Reverse the sense of a condition. */
6362 reverse_mri_condition (int cc
)
6366 case MCC ('h', 'i'): return MCC ('l', 's');
6367 case MCC ('l', 's'): return MCC ('h', 'i');
6368 /* <HS> is an alias for <CC> */
6369 case MCC ('h', 's'): return MCC ('l', 'o');
6370 case MCC ('c', 'c'): return MCC ('c', 's');
6371 /* <LO> is an alias for <CS> */
6372 case MCC ('l', 'o'): return MCC ('h', 's');
6373 case MCC ('c', 's'): return MCC ('c', 'c');
6374 case MCC ('n', 'e'): return MCC ('e', 'q');
6375 case MCC ('e', 'q'): return MCC ('n', 'e');
6376 case MCC ('v', 'c'): return MCC ('v', 's');
6377 case MCC ('v', 's'): return MCC ('v', 'c');
6378 case MCC ('p', 'l'): return MCC ('m', 'i');
6379 case MCC ('m', 'i'): return MCC ('p', 'l');
6380 case MCC ('g', 'e'): return MCC ('l', 't');
6381 case MCC ('l', 't'): return MCC ('g', 'e');
6382 case MCC ('g', 't'): return MCC ('l', 'e');
6383 case MCC ('l', 'e'): return MCC ('g', 't');
6388 /* Build an MRI structured control expression. This generates test
6389 and branch instructions. It goes to TRUELAB if the condition is
6390 true, and to FALSELAB if the condition is false. Exactly one of
6391 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6392 is the size qualifier for the expression. EXTENT is the size to
6393 use for the branch. */
6396 build_mri_control_operand (int qual
, int cc
, char *leftstart
, char *leftstop
,
6397 char *rightstart
, char *rightstop
,
6398 const char *truelab
, const char *falselab
,
6404 if (leftstart
!= NULL
)
6406 struct m68k_op leftop
, rightop
;
6409 /* Swap the compare operands, if necessary, to produce a legal
6410 m68k compare instruction. Comparing a register operand with
6411 a non-register operand requires the register to be on the
6412 right (cmp, cmpa). Comparing an immediate value with
6413 anything requires the immediate value to be on the left
6418 (void) m68k_ip_op (leftstart
, &leftop
);
6423 (void) m68k_ip_op (rightstart
, &rightop
);
6426 if (rightop
.mode
== IMMED
6427 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
6428 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
6432 /* Correct conditional handling:
6433 if #1 <lt> d0 then ;means if (1 < d0)
6439 cmp #1,d0 if we do *not* swap the operands
6440 bgt true we need the swapped condition!
6447 leftstart
= rightstart
;
6450 leftstop
= rightstop
;
6455 cc
= swap_mri_condition (cc
);
6459 if (truelab
== NULL
)
6461 cc
= reverse_mri_condition (cc
);
6465 if (leftstart
!= NULL
)
6467 buf
= (char *) xmalloc (20
6468 + (leftstop
- leftstart
)
6469 + (rightstop
- rightstart
));
6475 *s
++ = TOLOWER (qual
);
6477 memcpy (s
, leftstart
, leftstop
- leftstart
);
6478 s
+= leftstop
- leftstart
;
6480 memcpy (s
, rightstart
, rightstop
- rightstart
);
6481 s
+= rightstop
- rightstart
;
6487 buf
= (char *) xmalloc (20 + strlen (truelab
));
6493 *s
++ = TOLOWER (extent
);
6495 strcpy (s
, truelab
);
6500 /* Parse an MRI structured control expression. This generates test
6501 and branch instructions. STOP is where the expression ends. It
6502 goes to TRUELAB if the condition is true, and to FALSELAB if the
6503 condition is false. Exactly one of TRUELAB and FALSELAB will be
6504 NULL, meaning to fall through. QUAL is the size qualifier for the
6505 expression. EXTENT is the size to use for the branch. */
6508 parse_mri_control_expression (char *stop
, int qual
, const char *truelab
,
6509 const char *falselab
, int extent
)
6521 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6522 &rightstart
, &rightstop
))
6528 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6532 if (falselab
!= NULL
)
6535 flab
= mri_control_label ();
6537 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6538 rightstop
, (const char *) NULL
, flab
, extent
);
6540 input_line_pointer
+= 3;
6541 if (*input_line_pointer
!= '.'
6542 || input_line_pointer
[1] == '\0')
6546 qual
= input_line_pointer
[1];
6547 input_line_pointer
+= 2;
6550 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6551 &rightstart
, &rightstop
))
6557 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6558 rightstop
, truelab
, falselab
, extent
);
6560 if (falselab
== NULL
)
6563 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6567 if (truelab
!= NULL
)
6570 tlab
= mri_control_label ();
6572 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6573 rightstop
, tlab
, (const char *) NULL
, extent
);
6575 input_line_pointer
+= 2;
6576 if (*input_line_pointer
!= '.'
6577 || input_line_pointer
[1] == '\0')
6581 qual
= input_line_pointer
[1];
6582 input_line_pointer
+= 2;
6585 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6586 &rightstart
, &rightstop
))
6592 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6593 rightstop
, truelab
, falselab
, extent
);
6595 if (truelab
== NULL
)
6600 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6601 rightstop
, truelab
, falselab
, extent
);
6605 if (input_line_pointer
!= stop
)
6606 as_bad (_("syntax error in structured control directive"));
6609 /* Handle the MRI IF pseudo-op. This may be a structured control
6610 directive, or it may be a regular assembler conditional, depending
6618 struct mri_control_info
*n
;
6620 /* A structured control directive must end with THEN with an
6621 optional qualifier. */
6622 s
= input_line_pointer
;
6623 /* We only accept '*' as introduction of comments if preceded by white space
6624 or at first column of a line (I think this can't actually happen here?)
6625 This is important when assembling:
6626 if d0 <ne> 12(a0,d0*2) then
6627 if d0 <ne> #CONST*20 then. */
6628 while (! (is_end_of_line
[(unsigned char) *s
]
6631 && (s
== input_line_pointer
6633 || *(s
-1) == '\t'))))
6636 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6639 if (s
- input_line_pointer
> 1
6643 if (s
- input_line_pointer
< 3
6644 || strncasecmp (s
- 3, "THEN", 4) != 0)
6648 as_bad (_("missing then"));
6649 ignore_rest_of_line ();
6653 /* It's a conditional. */
6658 /* Since this might be a conditional if, this pseudo-op will be
6659 called even if we are supported to be ignoring input. Double
6660 check now. Clobber *input_line_pointer so that ignore_input
6661 thinks that this is not a special pseudo-op. */
6662 c
= *input_line_pointer
;
6663 *input_line_pointer
= 0;
6664 if (ignore_input ())
6666 *input_line_pointer
= c
;
6667 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6668 ++input_line_pointer
;
6669 demand_empty_rest_of_line ();
6672 *input_line_pointer
= c
;
6674 n
= push_mri_control (mri_if
);
6676 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6677 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6680 input_line_pointer
= s
+ 3;
6682 input_line_pointer
= s
+ 1;
6686 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6687 ++input_line_pointer
;
6690 demand_empty_rest_of_line ();
6693 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6694 structured IF, associate the ELSE with the IF. Otherwise, assume
6695 it is a conditional else. */
6698 s_mri_else (int qual
)
6705 && (mri_control_stack
== NULL
6706 || mri_control_stack
->type
!= mri_if
6707 || mri_control_stack
->else_seen
))
6713 c
= *input_line_pointer
;
6714 *input_line_pointer
= 0;
6715 if (ignore_input ())
6717 *input_line_pointer
= c
;
6718 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6719 ++input_line_pointer
;
6720 demand_empty_rest_of_line ();
6723 *input_line_pointer
= c
;
6725 if (mri_control_stack
== NULL
6726 || mri_control_stack
->type
!= mri_if
6727 || mri_control_stack
->else_seen
)
6729 as_bad (_("else without matching if"));
6730 ignore_rest_of_line ();
6734 mri_control_stack
->else_seen
= 1;
6736 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6737 q
[0] = TOLOWER (qual
);
6739 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6743 colon (mri_control_stack
->next
);
6747 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6748 ++input_line_pointer
;
6751 demand_empty_rest_of_line ();
6754 /* Handle the MRI ENDI pseudo-op. */
6757 s_mri_endi (int ignore ATTRIBUTE_UNUSED
)
6759 if (mri_control_stack
== NULL
6760 || mri_control_stack
->type
!= mri_if
)
6762 as_bad (_("endi without matching if"));
6763 ignore_rest_of_line ();
6767 /* ignore_input will not return true for ENDI, so we don't need to
6768 worry about checking it again here. */
6770 if (! mri_control_stack
->else_seen
)
6771 colon (mri_control_stack
->next
);
6772 colon (mri_control_stack
->bottom
);
6778 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6779 ++input_line_pointer
;
6782 demand_empty_rest_of_line ();
6785 /* Handle the MRI BREAK pseudo-op. */
6788 s_mri_break (int extent
)
6790 struct mri_control_info
*n
;
6794 n
= mri_control_stack
;
6796 && n
->type
!= mri_for
6797 && n
->type
!= mri_repeat
6798 && n
->type
!= mri_while
)
6802 as_bad (_("break outside of structured loop"));
6803 ignore_rest_of_line ();
6807 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6808 ex
[0] = TOLOWER (extent
);
6810 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6816 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6817 ++input_line_pointer
;
6820 demand_empty_rest_of_line ();
6823 /* Handle the MRI NEXT pseudo-op. */
6826 s_mri_next (int extent
)
6828 struct mri_control_info
*n
;
6832 n
= mri_control_stack
;
6834 && n
->type
!= mri_for
6835 && n
->type
!= mri_repeat
6836 && n
->type
!= mri_while
)
6840 as_bad (_("next outside of structured loop"));
6841 ignore_rest_of_line ();
6845 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6846 ex
[0] = TOLOWER (extent
);
6848 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6854 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6855 ++input_line_pointer
;
6858 demand_empty_rest_of_line ();
6861 /* Handle the MRI FOR pseudo-op. */
6864 s_mri_for (int qual
)
6866 const char *varstart
, *varstop
;
6867 const char *initstart
, *initstop
;
6868 const char *endstart
, *endstop
;
6869 const char *bystart
, *bystop
;
6873 struct mri_control_info
*n
;
6879 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6883 varstart
= input_line_pointer
;
6885 /* Look for the '='. */
6886 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6887 && *input_line_pointer
!= '=')
6888 ++input_line_pointer
;
6889 if (*input_line_pointer
!= '=')
6891 as_bad (_("missing ="));
6892 ignore_rest_of_line ();
6896 varstop
= input_line_pointer
;
6897 if (varstop
> varstart
6898 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6901 ++input_line_pointer
;
6903 initstart
= input_line_pointer
;
6905 /* Look for TO or DOWNTO. */
6908 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6910 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6911 && ! is_part_of_name (input_line_pointer
[2]))
6913 initstop
= input_line_pointer
;
6914 input_line_pointer
+= 2;
6917 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6918 && ! is_part_of_name (input_line_pointer
[6]))
6920 initstop
= input_line_pointer
;
6922 input_line_pointer
+= 6;
6925 ++input_line_pointer
;
6927 if (initstop
== NULL
)
6929 as_bad (_("missing to or downto"));
6930 ignore_rest_of_line ();
6933 if (initstop
> initstart
6934 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6938 endstart
= input_line_pointer
;
6940 /* Look for BY or DO. */
6943 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6945 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6946 && ! is_part_of_name (input_line_pointer
[2]))
6948 endstop
= input_line_pointer
;
6950 input_line_pointer
+= 2;
6953 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6954 && (input_line_pointer
[2] == '.'
6955 || ! is_part_of_name (input_line_pointer
[2])))
6957 endstop
= input_line_pointer
;
6958 input_line_pointer
+= 2;
6961 ++input_line_pointer
;
6963 if (endstop
== NULL
)
6965 as_bad (_("missing do"));
6966 ignore_rest_of_line ();
6969 if (endstop
> endstart
6970 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6976 bystop
= bystart
+ 2;
6981 bystart
= input_line_pointer
;
6985 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6987 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6988 && (input_line_pointer
[2] == '.'
6989 || ! is_part_of_name (input_line_pointer
[2])))
6991 bystop
= input_line_pointer
;
6992 input_line_pointer
+= 2;
6995 ++input_line_pointer
;
6999 as_bad (_("missing do"));
7000 ignore_rest_of_line ();
7003 if (bystop
> bystart
7004 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
7008 if (*input_line_pointer
!= '.')
7012 extent
= input_line_pointer
[1];
7013 input_line_pointer
+= 2;
7016 /* We have fully parsed the FOR operands. Now build the loop. */
7017 n
= push_mri_control (mri_for
);
7019 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
7021 /* Move init,var. */
7028 *s
++ = TOLOWER (qual
);
7030 memcpy (s
, initstart
, initstop
- initstart
);
7031 s
+= initstop
- initstart
;
7033 memcpy (s
, varstart
, varstop
- varstart
);
7034 s
+= varstop
- varstart
;
7046 *s
++ = TOLOWER (qual
);
7048 memcpy (s
, endstart
, endstop
- endstart
);
7049 s
+= endstop
- endstart
;
7051 memcpy (s
, varstart
, varstop
- varstart
);
7052 s
+= varstop
- varstart
;
7057 ex
[0] = TOLOWER (extent
);
7060 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
7062 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
7065 /* Put together the add or sub instruction used by ENDF. */
7073 *s
++ = TOLOWER (qual
);
7075 memcpy (s
, bystart
, bystop
- bystart
);
7076 s
+= bystop
- bystart
;
7078 memcpy (s
, varstart
, varstop
- varstart
);
7079 s
+= varstop
- varstart
;
7085 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7086 ++input_line_pointer
;
7089 demand_empty_rest_of_line ();
7092 /* Handle the MRI ENDF pseudo-op. */
7095 s_mri_endf (int ignore ATTRIBUTE_UNUSED
)
7097 if (mri_control_stack
== NULL
7098 || mri_control_stack
->type
!= mri_for
)
7100 as_bad (_("endf without for"));
7101 ignore_rest_of_line ();
7105 colon (mri_control_stack
->next
);
7107 mri_assemble (mri_control_stack
->incr
);
7109 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
7110 mri_assemble (mri_control_stack
->incr
);
7112 free (mri_control_stack
->incr
);
7114 colon (mri_control_stack
->bottom
);
7120 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7121 ++input_line_pointer
;
7124 demand_empty_rest_of_line ();
7127 /* Handle the MRI REPEAT pseudo-op. */
7130 s_mri_repeat (int ignore ATTRIBUTE_UNUSED
)
7132 struct mri_control_info
*n
;
7134 n
= push_mri_control (mri_repeat
);
7138 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7139 ++input_line_pointer
;
7141 demand_empty_rest_of_line ();
7144 /* Handle the MRI UNTIL pseudo-op. */
7147 s_mri_until (int qual
)
7151 if (mri_control_stack
== NULL
7152 || mri_control_stack
->type
!= mri_repeat
)
7154 as_bad (_("until without repeat"));
7155 ignore_rest_of_line ();
7159 colon (mri_control_stack
->next
);
7161 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
7164 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
7165 mri_control_stack
->top
, '\0');
7167 colon (mri_control_stack
->bottom
);
7169 input_line_pointer
= s
;
7175 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7176 ++input_line_pointer
;
7179 demand_empty_rest_of_line ();
7182 /* Handle the MRI WHILE pseudo-op. */
7185 s_mri_while (int qual
)
7189 struct mri_control_info
*n
;
7191 s
= input_line_pointer
;
7192 /* We only accept '*' as introduction of comments if preceded by white space
7193 or at first column of a line (I think this can't actually happen here?)
7194 This is important when assembling:
7195 while d0 <ne> 12(a0,d0*2) do
7196 while d0 <ne> #CONST*20 do. */
7197 while (! (is_end_of_line
[(unsigned char) *s
]
7200 && (s
== input_line_pointer
7202 || *(s
-1) == '\t'))))
7205 while (*s
== ' ' || *s
== '\t')
7207 if (s
- input_line_pointer
> 1
7210 if (s
- input_line_pointer
< 2
7211 || strncasecmp (s
- 1, "DO", 2) != 0)
7213 as_bad (_("missing do"));
7214 ignore_rest_of_line ();
7218 n
= push_mri_control (mri_while
);
7222 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
7223 s
[1] == '.' ? s
[2] : '\0');
7225 input_line_pointer
= s
+ 1;
7226 if (*input_line_pointer
== '.')
7227 input_line_pointer
+= 2;
7231 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7232 ++input_line_pointer
;
7235 demand_empty_rest_of_line ();
7238 /* Handle the MRI ENDW pseudo-op. */
7241 s_mri_endw (int ignore ATTRIBUTE_UNUSED
)
7245 if (mri_control_stack
== NULL
7246 || mri_control_stack
->type
!= mri_while
)
7248 as_bad (_("endw without while"));
7249 ignore_rest_of_line ();
7253 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
7254 sprintf (buf
, "bra %s", mri_control_stack
->next
);
7258 colon (mri_control_stack
->bottom
);
7264 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7265 ++input_line_pointer
;
7268 demand_empty_rest_of_line ();
7271 /* Parse a .cpu directive. */
7274 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED
)
7281 as_bad (_("already assembled instructions"));
7282 ignore_rest_of_line ();
7286 name
= input_line_pointer
;
7287 while (*input_line_pointer
&& !ISSPACE(*input_line_pointer
))
7288 input_line_pointer
++;
7289 saved_char
= *input_line_pointer
;
7290 *input_line_pointer
= 0;
7292 m68k_set_cpu (name
, 1, 0);
7294 *input_line_pointer
= saved_char
;
7295 demand_empty_rest_of_line ();
7299 /* Parse a .arch directive. */
7302 s_m68k_arch (int ignored ATTRIBUTE_UNUSED
)
7309 as_bad (_("already assembled instructions"));
7310 ignore_rest_of_line ();
7314 name
= input_line_pointer
;
7315 while (*input_line_pointer
&& *input_line_pointer
!= ','
7316 && !ISSPACE (*input_line_pointer
))
7317 input_line_pointer
++;
7318 saved_char
= *input_line_pointer
;
7319 *input_line_pointer
= 0;
7321 if (m68k_set_arch (name
, 1, 0))
7323 /* Scan extensions. */
7326 *input_line_pointer
++ = saved_char
;
7327 if (!*input_line_pointer
|| ISSPACE (*input_line_pointer
))
7329 name
= input_line_pointer
;
7330 while (*input_line_pointer
&& *input_line_pointer
!= ','
7331 && !ISSPACE (*input_line_pointer
))
7332 input_line_pointer
++;
7333 saved_char
= *input_line_pointer
;
7334 *input_line_pointer
= 0;
7336 while (m68k_set_extension (name
, 1, 0));
7339 *input_line_pointer
= saved_char
;
7340 demand_empty_rest_of_line ();
7344 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
7345 if none is found, the caller is responsible for emitting an error
7346 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
7347 cpu name, if it begins with a '6' (possibly skipping an intervening
7348 'c'. We also allow a 'c' in the same place. if NEGATED is
7349 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
7350 the option is indeed negated. */
7352 static const struct m68k_cpu
*
7353 m68k_lookup_cpu (const char *arg
, const struct m68k_cpu
*table
,
7354 int allow_m
, int *negated
)
7356 /* allow negated value? */
7361 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
7368 /* Remove 'm' or 'mc' prefix from 68k variants. */
7375 else if (arg
[1] == 'c' && arg
[2] == '6')
7379 else if (arg
[0] == 'c' && arg
[1] == '6')
7382 for (; table
->name
; table
++)
7383 if (!strcmp (arg
, table
->name
))
7385 if (table
->alias
< -1 || table
->alias
> 1)
7386 as_bad (_("`%s' is deprecated, use `%s'"),
7387 table
->name
, table
[table
->alias
< 0 ? 1 : -1].name
);
7393 /* Set the cpu, issuing errors if it is unrecognized. */
7396 m68k_set_cpu (char const *name
, int allow_m
, int silent
)
7398 const struct m68k_cpu
*cpu
;
7400 cpu
= m68k_lookup_cpu (name
, m68k_cpus
, allow_m
, NULL
);
7405 as_bad (_("cpu `%s' unrecognized"), name
);
7412 /* Set the architecture, issuing errors if it is unrecognized. */
7415 m68k_set_arch (char const *name
, int allow_m
, int silent
)
7417 const struct m68k_cpu
*arch
;
7419 arch
= m68k_lookup_cpu (name
, m68k_archs
, allow_m
, NULL
);
7424 as_bad (_("architecture `%s' unrecognized"), name
);
7427 selected_arch
= arch
;
7431 /* Set the architecture extension, issuing errors if it is
7432 unrecognized, or invalid */
7435 m68k_set_extension (char const *name
, int allow_m
, int silent
)
7438 const struct m68k_cpu
*ext
;
7440 ext
= m68k_lookup_cpu (name
, m68k_extensions
, allow_m
, &negated
);
7445 as_bad (_("extension `%s' unrecognized"), name
);
7450 not_current_architecture
|= (ext
->control_regs
7451 ? *(unsigned *)ext
->control_regs
: ext
->arch
);
7453 current_architecture
|= ext
->arch
;
7458 Invocation line includes a switch not recognized by the base assembler.
7462 const char *md_shortopts
= "lSA:m:kQ:V";
7464 const char *md_shortopts
= "lSA:m:k";
7467 struct option md_longopts
[] = {
7468 #define OPTION_PIC (OPTION_MD_BASE)
7469 {"pic", no_argument
, NULL
, OPTION_PIC
},
7470 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7471 {"register-prefix-optional", no_argument
, NULL
,
7472 OPTION_REGISTER_PREFIX_OPTIONAL
},
7473 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7474 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
7475 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7476 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
7477 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7478 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
7479 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7480 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
7481 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7482 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
7483 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7484 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
7485 {NULL
, no_argument
, NULL
, 0}
7487 size_t md_longopts_size
= sizeof (md_longopts
);
7490 md_parse_option (int c
, char *arg
)
7494 case 'l': /* -l means keep external to 2 bit offset
7495 rather than 16 bit one. */
7496 flag_short_refs
= 1;
7499 case 'S': /* -S means that jbsr's always turn into
7501 flag_long_jumps
= 1;
7504 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
7505 branches into absolute jumps. */
7506 flag_keep_pcrel
= 1;
7512 break; /* -pic, Position Independent Code. */
7514 case OPTION_REGISTER_PREFIX_OPTIONAL
:
7515 flag_reg_prefix_optional
= 1;
7516 reg_prefix_optional_seen
= 1;
7519 /* -V: SVR4 argument to print version ID. */
7521 print_version_id ();
7524 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7525 should be emitted or not. FIXME: Not implemented. */
7529 case OPTION_BITWISE_OR
:
7534 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
7536 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
7540 m68k_comment_chars
= n
;
7544 case OPTION_BASE_SIZE_DEFAULT_16
:
7545 m68k_index_width_default
= SIZE_WORD
;
7548 case OPTION_BASE_SIZE_DEFAULT_32
:
7549 m68k_index_width_default
= SIZE_LONG
;
7552 case OPTION_DISP_SIZE_DEFAULT_16
:
7554 m68k_rel32_from_cmdline
= 1;
7557 case OPTION_DISP_SIZE_DEFAULT_32
:
7559 m68k_rel32_from_cmdline
= 1;
7564 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7567 /* Intentional fall-through. */
7569 if (!strncmp (arg
, "arch=", 5))
7570 m68k_set_arch (arg
+ 5, 1, 0);
7571 else if (!strncmp (arg
, "cpu=", 4))
7572 m68k_set_cpu (arg
+ 4, 1, 0);
7573 else if (m68k_set_extension (arg
, 0, 1))
7575 else if (m68k_set_arch (arg
, 0, 1))
7577 else if (m68k_set_cpu (arg
, 0, 1))
7590 /* Setup tables from the selected arch and/or cpu */
7593 m68k_init_arch (void)
7595 if (not_current_architecture
& current_architecture
)
7597 as_bad (_("architecture features both enabled and disabled"));
7598 not_current_architecture
&= ~current_architecture
;
7602 current_architecture
|= selected_arch
->arch
;
7603 control_regs
= selected_arch
->control_regs
;
7606 current_architecture
|= selected_cpu
->arch
;
7608 current_architecture
&= ~not_current_architecture
;
7610 if ((current_architecture
& (cfloat
| m68881
)) == (cfloat
| m68881
))
7612 /* Determine which float is really meant. */
7613 if (current_architecture
& (m68k_mask
& ~m68881
))
7614 current_architecture
^= cfloat
;
7616 current_architecture
^= m68881
;
7621 control_regs
= selected_cpu
->control_regs
;
7622 if (current_architecture
& ~selected_cpu
->arch
)
7624 as_bad (_("selected processor does not have all features of selected architecture"));
7625 current_architecture
7626 = selected_cpu
->arch
& ~not_current_architecture
;
7630 if ((current_architecture
& m68k_mask
)
7631 && (current_architecture
& ~m68k_mask
))
7633 as_bad (_ ("m68k and cf features both selected"));
7634 if (current_architecture
& m68k_mask
)
7635 current_architecture
&= m68k_mask
;
7637 current_architecture
&= ~m68k_mask
;
7640 /* Permit m68881 specification with all cpus; those that can't work
7641 with a coprocessor could be doing emulation. */
7642 if (current_architecture
& m68851
)
7644 if (current_architecture
& m68040
)
7645 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7647 /* What other incompatibilities could we check for? */
7649 if (cpu_of_arch (current_architecture
) < m68020
7650 || arch_coldfire_p (current_architecture
))
7651 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
7657 md_show_usage (FILE *stream
)
7659 const char *default_cpu
= TARGET_CPU
;
7661 unsigned int default_arch
;
7663 /* Get the canonical name for the default target CPU. */
7664 if (*default_cpu
== 'm')
7666 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7668 if (strcasecmp (default_cpu
, m68k_cpus
[i
].name
) == 0)
7670 default_arch
= m68k_cpus
[i
].arch
;
7671 while (m68k_cpus
[i
].alias
> 0)
7673 while (m68k_cpus
[i
].alias
< 0)
7675 default_cpu
= m68k_cpus
[i
].name
;
7679 fprintf (stream
, _("\
7680 -march=<arch> set architecture\n\
7681 -mcpu=<cpu> set cpu [default %s]\n\
7683 for (i
= 0; m68k_extensions
[i
].name
; i
++)
7684 fprintf (stream
, _("\
7685 -m[no-]%-16s enable/disable%s architecture extension\n\
7686 "), m68k_extensions
[i
].name
,
7687 m68k_extensions
[i
].alias
> 0 ? " ColdFire"
7688 : m68k_extensions
[i
].alias
< 0 ? " m68k" : "");
7690 fprintf (stream
, _("\
7691 -l use 1 word for refs to undefined symbols [default 2]\n\
7692 -pic, -k generate position independent code\n\
7693 -S turn jbsr into jsr\n\
7694 --pcrel never turn PC-relative branches into absolute jumps\n\
7695 --register-prefix-optional\n\
7696 recognize register names without prefix character\n\
7697 --bitwise-or do not treat `|' as a comment character\n\
7698 --base-size-default-16 base reg without size is 16 bits\n\
7699 --base-size-default-32 base reg without size is 32 bits (default)\n\
7700 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7701 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7704 fprintf (stream
, _("Architecture variants are: "));
7705 for (i
= 0; m68k_archs
[i
].name
; i
++)
7708 fprintf (stream
, " | ");
7709 fprintf (stream
, "%s", m68k_archs
[i
].name
);
7711 fprintf (stream
, "\n");
7713 fprintf (stream
, _("Processor variants are: "));
7714 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7717 fprintf (stream
, " | ");
7718 fprintf (stream
, "%s", m68k_cpus
[i
].name
);
7720 fprintf (stream
, _("\n"));
7725 /* TEST2: Test md_assemble() */
7726 /* Warning, this routine probably doesn't work anymore. */
7730 struct m68k_it the_ins
;
7738 if (!gets (buf
) || !*buf
)
7740 if (buf
[0] == '|' || buf
[1] == '.')
7742 for (cp
= buf
; *cp
; cp
++)
7747 memset (&the_ins
, '\0', sizeof (the_ins
));
7748 m68k_ip (&the_ins
, buf
);
7751 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7755 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7756 for (n
= 0; n
< the_ins
.numo
; n
++)
7757 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7759 print_the_insn (&the_ins
.opcode
[0], stdout
);
7760 (void) putchar ('\n');
7762 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7764 if (the_ins
.operands
[n
].error
)
7766 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7769 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
,
7770 the_ins
.operands
[n
].reg
);
7771 if (the_ins
.operands
[n
].b_const
)
7772 printf ("Constant: '%.*s', ",
7773 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
,
7774 the_ins
.operands
[n
].b_const
);
7775 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
,
7776 the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7777 if (the_ins
.operands
[n
].b_iadd
)
7778 printf ("Iadd: '%.*s',",
7779 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
,
7780 the_ins
.operands
[n
].b_iadd
);
7789 is_label (char *str
)
7793 while (*str
&& *str
!= ' ')
7795 if (str
[-1] == ':' || str
[1] == '=')
7802 /* Possible states for relaxation:
7804 0 0 branch offset byte (bra, etc)
7808 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7812 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7819 /* We have no need to default values of symbols. */
7822 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
7827 /* Round up a section size to the appropriate boundary. */
7829 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
7832 /* For a.out, force the section size to be aligned. If we don't do
7833 this, BFD will align it for us, but it will not write out the
7834 final bytes of the section. This may be a bug in BFD, but it is
7835 easier to fix it here since that is how the other a.out targets
7839 align
= bfd_get_section_alignment (stdoutput
, segment
);
7840 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
7846 /* Exactly what point is a PC-relative offset relative TO?
7847 On the 68k, it is relative to the address of the first extension
7848 word. The difference between the addresses of the offset and the
7849 first extension word is stored in fx_pcrel_adjust. */
7851 md_pcrel_from (fixS
*fixP
)
7855 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7856 sign extend the value here. */
7857 adjust
= ((fixP
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80;
7860 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7865 m68k_elf_final_processing (void)
7869 if (arch_coldfire_fpu (current_architecture
))
7870 flags
|= EF_M68K_CFV4E
;
7871 /* Set file-specific flags if this is a cpu32 processor. */
7872 if (cpu_of_arch (current_architecture
) & cpu32
)
7873 flags
|= EF_M68K_CPU32
;
7874 else if (cpu_of_arch (current_architecture
) & fido_a
)
7875 flags
|= EF_M68K_FIDO
;
7876 else if ((cpu_of_arch (current_architecture
) & m68000up
)
7877 && !(cpu_of_arch (current_architecture
) & m68020up
))
7878 flags
|= EF_M68K_M68000
;
7880 if (current_architecture
& mcfisa_a
)
7882 static const unsigned isa_features
[][2] =
7884 {EF_M68K_CF_ISA_A_NODIV
,mcfisa_a
},
7885 {EF_M68K_CF_ISA_A
, mcfisa_a
|mcfhwdiv
},
7886 {EF_M68K_CF_ISA_A_PLUS
, mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
},
7887 {EF_M68K_CF_ISA_B_NOUSP
,mcfisa_a
|mcfisa_b
|mcfhwdiv
},
7888 {EF_M68K_CF_ISA_B
, mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfusp
},
7889 {EF_M68K_CF_ISA_C
, mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfusp
},
7890 {EF_M68K_CF_ISA_C_NODIV
,mcfisa_a
|mcfisa_c
|mcfusp
},
7893 static const unsigned mac_features
[][2] =
7895 {EF_M68K_CF_MAC
, mcfmac
},
7896 {EF_M68K_CF_EMAC
, mcfemac
},
7902 pattern
= (current_architecture
7903 & (mcfisa_a
|mcfisa_aa
|mcfisa_b
|mcfisa_c
|mcfhwdiv
|mcfusp
));
7904 for (ix
= 0; isa_features
[ix
][1]; ix
++)
7906 if (pattern
== isa_features
[ix
][1])
7908 flags
|= isa_features
[ix
][0];
7912 if (!isa_features
[ix
][1])
7915 as_warn (_("Not a defined coldfire architecture"));
7919 if (current_architecture
& cfloat
)
7920 flags
|= EF_M68K_CF_FLOAT
| EF_M68K_CFV4E
;
7922 pattern
= current_architecture
& (mcfmac
|mcfemac
);
7925 for (ix
= 0; mac_features
[ix
][1]; ix
++)
7927 if (pattern
== mac_features
[ix
][1])
7929 flags
|= mac_features
[ix
][0];
7933 if (!mac_features
[ix
][1])
7938 elf_elfheader (stdoutput
)->e_flags
|= flags
;
7941 /* Parse @TLSLDO and return the desired relocation. */
7942 static bfd_reloc_code_real_type
7943 m68k_elf_suffix (char **str_p
, expressionS
*exp_p
)
7952 return BFD_RELOC_UNUSED
;
7954 for (ch
= *str
, str2
= ident
;
7955 (str2
< ident
+ sizeof (ident
) - 1
7956 && (ISALNUM (ch
) || ch
== '@'));
7965 if (strncmp (ident
, "TLSLDO", 6) == 0
7968 /* Now check for identifier@suffix+constant. */
7969 if (*str
== '-' || *str
== '+')
7971 char *orig_line
= input_line_pointer
;
7972 expressionS new_exp
;
7974 input_line_pointer
= str
;
7975 expression (&new_exp
);
7976 if (new_exp
.X_op
== O_constant
)
7978 exp_p
->X_add_number
+= new_exp
.X_add_number
;
7979 str
= input_line_pointer
;
7982 if (&input_line_pointer
!= str_p
)
7983 input_line_pointer
= orig_line
;
7987 return BFD_RELOC_68K_TLS_LDO32
;
7990 return BFD_RELOC_UNUSED
;
7993 /* Handles .long <tls_symbol>+0x8000 debug info.
7994 Clobbers input_line_pointer, checks end-of-line.
7995 Adapted from tc-ppc.c:ppc_elf_cons. */
7997 m68k_elf_cons (int nbytes
/* 4=.long */)
7999 if (is_it_end_of_statement ())
8001 demand_empty_rest_of_line ();
8008 bfd_reloc_code_real_type reloc
;
8011 if (exp
.X_op
== O_symbol
8012 && *input_line_pointer
== '@'
8013 && (reloc
= m68k_elf_suffix (&input_line_pointer
,
8014 &exp
)) != BFD_RELOC_UNUSED
)
8016 reloc_howto_type
*reloc_howto
;
8019 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
8020 size
= bfd_get_reloc_size (reloc_howto
);
8024 as_bad (_("%s relocations do not fit in %d bytes\n"),
8025 reloc_howto
->name
, nbytes
);
8032 p
= frag_more (nbytes
);
8034 if (target_big_endian
)
8035 offset
= nbytes
- size
;
8036 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
8041 emit_expr (&exp
, (unsigned int) nbytes
);
8043 while (*input_line_pointer
++ == ',');
8045 /* Put terminator back into stream. */
8046 input_line_pointer
--;
8047 demand_empty_rest_of_line ();
8052 tc_m68k_regname_to_dw2regnum (char *regname
)
8054 unsigned int regnum
;
8055 static const char *const regnames
[] =
8057 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
8058 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
8059 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
8063 for (regnum
= 0; regnum
< ARRAY_SIZE (regnames
); regnum
++)
8064 if (strcmp (regname
, regnames
[regnum
]) == 0)
8071 tc_m68k_frame_initial_instructions (void)
8073 static int sp_regno
= -1;
8076 sp_regno
= tc_m68k_regname_to_dw2regnum ("sp");
8078 cfi_add_CFA_def_cfa (sp_regno
, -DWARF2_CIE_DATA_ALIGNMENT
);
8079 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN
, DWARF2_CIE_DATA_ALIGNMENT
);