1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987-2019 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "safe-ctype.h"
25 #include "dwarf2dbg.h"
26 #include "dw2gencfi.h"
28 #include "opcode/m68k.h"
29 #include "m68k-parse.h"
32 static void m68k_elf_cons (int);
34 /* This string holds the chars that always start a comment. If the
35 pre-processor is disabled, these aren't very useful. The macro
36 tc_comment_chars points to this. We use this, rather than the
37 usual comment_chars, so that the --bitwise-or option will work. */
38 #if defined (TE_SVR4) || defined (TE_DELTA)
39 const char *m68k_comment_chars
= "|#";
41 const char *m68k_comment_chars
= "|";
44 /* This array holds the chars that only start a comment at the beginning of
45 a line. If the line seems to have the form '# 123 filename'
46 .line and .file directives will appear in the pre-processed output */
47 /* Note that input_file.c hand checks for '#' at the beginning of the
48 first line of the input file. This is because the compiler outputs
49 #NO_APP at the beginning of its output. */
50 /* Also note that comments like this one will always work. */
51 const char line_comment_chars
[] = "#*";
53 const char line_separator_chars
[] = ";";
55 /* Chars that can be used to separate mant from exp in floating point nums. */
56 const char EXP_CHARS
[] = "eE";
58 /* Chars that mean this number is a floating point constant, as
59 in "0f12.456" or "0d1.2345e12". */
61 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
63 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
64 changed in read.c . Ideally it shouldn't have to know about it at all,
65 but nothing is ideal around here. */
67 /* Are we trying to generate PIC code? If so, absolute references
68 ought to be made into linkage table references or pc-relative
69 references. Not implemented. For ELF there are other means
70 to denote pic relocations. */
73 static int flag_short_refs
; /* -l option. */
74 static int flag_long_jumps
; /* -S option. */
75 static int flag_keep_pcrel
; /* --pcrel option. */
77 #ifdef REGISTER_PREFIX_OPTIONAL
78 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
80 int flag_reg_prefix_optional
;
83 /* Whether --register-prefix-optional was used on the command line. */
84 static int reg_prefix_optional_seen
;
86 /* The floating point coprocessor to use by default. */
87 static enum m68k_register m68k_float_copnum
= COP1
;
89 /* If this is non-zero, then references to number(%pc) will be taken
90 to refer to number, rather than to %pc + number. */
91 static int m68k_abspcadd
;
93 /* If this is non-zero, then the quick forms of the move, add, and sub
94 instructions are used when possible. */
95 static int m68k_quick
= 1;
97 /* If this is non-zero, then if the size is not specified for a base
98 or outer displacement, the assembler assumes that the size should
100 static int m68k_rel32
= 1;
102 /* This is non-zero if m68k_rel32 was set from the command line. */
103 static int m68k_rel32_from_cmdline
;
105 /* The default width to use for an index register when using a base
107 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
109 /* We want to warn if any text labels are misaligned. In order to get
110 the right line number, we need to record the line number for each
114 struct label_line
*next
;
121 /* The list of labels. */
123 static struct label_line
*labels
;
125 /* The current label. */
127 static struct label_line
*current_label
;
129 /* Pointer to list holding the opcodes sorted by name. */
130 static struct m68k_opcode
const ** m68k_sorted_opcodes
;
132 /* It's an arbitrary name: This means I don't approve of it.
134 static struct obstack robyn
;
138 const char *m_operands
;
139 unsigned long m_opcode
;
143 struct m68k_incant
*m_next
;
146 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
147 #define gettwo(x) (((x)->m_opcode)&0xffff)
149 static const enum m68k_register m68000_ctrl
[] = { 0 };
150 static const enum m68k_register m68010_ctrl
[] = {
154 static const enum m68k_register m68020_ctrl
[] = {
155 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
158 static const enum m68k_register m68040_ctrl
[] = {
159 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
160 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
163 static const enum m68k_register m68060_ctrl
[] = {
164 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
165 USP
, VBR
, URP
, SRP
, PCR
,
168 static const enum m68k_register mcf_ctrl
[] = {
169 CACR
, TC
, ACR0
, ACR1
, ACR2
, ACR3
, VBR
, ROMBAR
,
170 RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
,
173 static const enum m68k_register mcf51_ctrl
[] = {
177 static const enum m68k_register mcf5206_ctrl
[] = {
178 CACR
, ACR0
, ACR1
, VBR
, RAMBAR0
, RAMBAR_ALT
, MBAR
,
181 static const enum m68k_register mcf5208_ctrl
[] = {
182 CACR
, ACR0
, ACR1
, VBR
, RAMBAR
, RAMBAR1
,
185 static const enum m68k_register mcf5210a_ctrl
[] = {
186 VBR
, CACR
, ACR0
, ACR1
, ROMBAR
, RAMBAR
, RAMBAR1
, MBAR
,
189 static const enum m68k_register mcf5213_ctrl
[] = {
190 VBR
, RAMBAR
, RAMBAR1
, FLASHBAR
,
193 static const enum m68k_register mcf5216_ctrl
[] = {
194 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
197 static const enum m68k_register mcf5221x_ctrl
[] = {
198 VBR
, FLASHBAR
, RAMBAR
, RAMBAR1
,
201 static const enum m68k_register mcf52223_ctrl
[] = {
202 VBR
, FLASHBAR
, RAMBAR
, RAMBAR1
,
205 static const enum m68k_register mcf52235_ctrl
[] = {
206 VBR
, FLASHBAR
, RAMBAR
, RAMBAR1
,
209 static const enum m68k_register mcf5225_ctrl
[] = {
210 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, MBAR
, RAMBAR1
,
213 static const enum m68k_register mcf52259_ctrl
[] = {
214 VBR
, FLASHBAR
, RAMBAR
, RAMBAR1
,
217 static const enum m68k_register mcf52277_ctrl
[] = {
218 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
221 static const enum m68k_register mcf5235_ctrl
[] = {
222 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
225 static const enum m68k_register mcf5249_ctrl
[] = {
226 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
, MBAR2
,
229 static const enum m68k_register mcf5250_ctrl
[] = {
233 static const enum m68k_register mcf5253_ctrl
[] = {
234 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
, MBAR2
,
237 static const enum m68k_register mcf5271_ctrl
[] = {
238 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
241 static const enum m68k_register mcf5272_ctrl
[] = {
242 VBR
, CACR
, ACR0
, ACR1
, ROMBAR
, RAMBAR_ALT
, RAMBAR0
, MBAR
,
245 static const enum m68k_register mcf5275_ctrl
[] = {
246 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
249 static const enum m68k_register mcf5282_ctrl
[] = {
250 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
253 static const enum m68k_register mcf53017_ctrl
[] = {
254 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
257 static const enum m68k_register mcf5307_ctrl
[] = {
258 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR_ALT
, MBAR
,
261 static const enum m68k_register mcf5329_ctrl
[] = {
262 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
265 static const enum m68k_register mcf5373_ctrl
[] = {
266 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
269 static const enum m68k_register mcfv4e_ctrl
[] = {
270 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
271 VBR
, PC
, ROMBAR0
, ROMBAR1
, RAMBAR0
, RAMBAR1
,
273 MPCR
/* Multiprocessor Control register */,
274 EDRAMBAR
/* Embedded DRAM Base Address Register */,
275 /* Permutation control registers. */
276 PCR1U0
, PCR1L0
, PCR1U1
, PCR1L1
, PCR2U0
, PCR2L0
, PCR2U1
, PCR2L1
,
277 PCR3U0
, PCR3L0
, PCR3U1
, PCR3L1
,
279 TC
/* ASID */, BUSCR
/* MMUBAR */,
280 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
281 MBAR1
/* MBAR */, MBAR2
/* SECMBAR */, MBAR0
/* SECMBAR */,
282 ROMBAR
/* ROMBAR0 */, RAMBAR
/* RAMBAR1 */,
285 static const enum m68k_register mcf5407_ctrl
[] = {
286 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
,
287 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
290 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
291 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
294 static const enum m68k_register mcf54418_ctrl
[] = {
295 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, ACR4
, ACR5
, ACR6
, ACR7
, MMUBAR
, RGPIOBAR
,
298 TC
/* ASID */, BUSCR
/* MMUBAR */,
299 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
300 RAMBAR
/* RAMBAR1 */,
303 static const enum m68k_register mcf54455_ctrl
[] = {
304 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
307 TC
/* ASID */, BUSCR
/* MMUBAR */,
308 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
309 RAMBAR
/* RAMBAR1 */,
312 static const enum m68k_register mcf5475_ctrl
[] = {
313 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
314 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
316 TC
/* ASID */, BUSCR
/* MMUBAR */,
317 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
318 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
321 static const enum m68k_register mcf5485_ctrl
[] = {
322 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
323 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
325 TC
/* ASID */, BUSCR
/* MMUBAR */,
326 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
327 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
330 static const enum m68k_register fido_ctrl
[] = {
331 SFC
, DFC
, USP
, VBR
, CAC
, MBO
,
334 #define cpu32_ctrl m68010_ctrl
336 static const enum m68k_register
*control_regs
;
338 /* Internal form of a 68020 instruction. */
342 const char *args
; /* List of opcode info. */
345 int numo
; /* Number of shorts in opcode. */
348 struct m68k_op operands
[6];
350 int nexp
; /* Number of exprs in use. */
351 struct m68k_exp exprs
[4];
353 int nfrag
; /* Number of frags we have to produce. */
356 int fragoff
; /* Where in the current opcode the frag ends. */
363 int nrel
; /* Num of reloc structs in use. */
370 /* In a pc relative address the difference between the address
371 of the offset and the address that the offset is relative
372 to. This depends on the addressing mode. Basically this
373 is the value to put in the offset field to address the
374 first byte of the offset, without regarding the special
375 significance of some values (in the branch instruction, for
378 /* Whether this expression needs special pic relocation, and if
380 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
;
441 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
442 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
445 /* Cause an extra frag to be generated here, inserting up to 10 bytes
446 (that value is chosen in the frag_var call in md_assemble). TYPE
447 is the subtype of the frag to be generated; its primary type is
448 rs_machine_dependent.
450 The TYPE parameter is also used by md_convert_frag_1 and
451 md_estimate_size_before_relax. The appropriate type of fixup will
452 be emitted by md_convert_frag_1.
454 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
456 add_frag (symbolS
*add
, offsetT off
, int type
)
458 the_ins
.fragb
[the_ins
.nfrag
].fragoff
= the_ins
.numo
;
459 the_ins
.fragb
[the_ins
.nfrag
].fadd
= add
;
460 the_ins
.fragb
[the_ins
.nfrag
].foff
= off
;
461 the_ins
.fragb
[the_ins
.nfrag
++].fragty
= type
;
465 (op (ex) != O_constant && op (ex) != O_big)
467 static char *crack_operand (char *str
, struct m68k_op
*opP
);
468 static int get_num (struct m68k_exp
*exp
, int ok
);
469 static int reverse_16_bits (int in
);
470 static int reverse_8_bits (int in
);
471 static void install_gen_operand (int mode
, int val
);
472 static void install_operand (int mode
, int val
);
473 static void s_bss (int);
474 static void s_data1 (int);
475 static void s_data2 (int);
476 static void s_even (int);
477 static void s_proc (int);
478 static void s_chip (int);
479 static void s_fopt (int);
480 static void s_opt (int);
481 static void s_reg (int);
482 static void s_restore (int);
483 static void s_save (int);
484 static void s_mri_if (int);
485 static void s_mri_else (int);
486 static void s_mri_endi (int);
487 static void s_mri_break (int);
488 static void s_mri_next (int);
489 static void s_mri_for (int);
490 static void s_mri_endf (int);
491 static void s_mri_repeat (int);
492 static void s_mri_until (int);
493 static void s_mri_while (int);
494 static void s_mri_endw (int);
495 static void s_m68k_cpu (int);
496 static void s_m68k_arch (int);
500 unsigned long arch
; /* Architecture features. */
501 const enum m68k_register
*control_regs
; /* Control regs on chip */
502 const char *name
; /* Name */
503 int alias
; /* Alias for a canonical name. If 1, then
504 succeeds canonical name, if -1 then
505 succeeds canonical name, if <-1 ||>1 this is a
506 deprecated name, and the next/previous name
510 /* We hold flags for features explicitly enabled and explicitly
512 static int current_architecture
;
513 static int not_current_architecture
;
514 static const struct m68k_cpu
*selected_arch
;
515 static const struct m68k_cpu
*selected_cpu
;
516 static int initialized
;
518 /* Architecture models. */
519 static const struct m68k_cpu m68k_archs
[] =
521 {m68000
, m68000_ctrl
, "68000", 0},
522 {m68010
, m68010_ctrl
, "68010", 0},
523 {m68020
|m68881
|m68851
, m68020_ctrl
, "68020", 0},
524 {m68030
|m68881
|m68851
, m68020_ctrl
, "68030", 0},
525 {m68040
, m68040_ctrl
, "68040", 0},
526 {m68060
, m68060_ctrl
, "68060", 0},
527 {cpu32
|m68881
, cpu32_ctrl
, "cpu32", 0},
528 {fido_a
, fido_ctrl
, "fidoa", 0},
529 {mcfisa_a
|mcfhwdiv
, NULL
, "isaa", 0},
530 {mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfusp
, NULL
, "isaaplus", 0},
531 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfusp
, NULL
, "isab", 0},
532 {mcfisa_a
|mcfhwdiv
|mcfisa_c
|mcfusp
, NULL
, "isac", 0},
533 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
|mcfusp
, mcf_ctrl
, "cfv4", 0},
534 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcfv4e_ctrl
, "cfv4e", 0},
538 /* For -mno-mac we want to turn off all types of mac. */
539 static const unsigned no_mac
= mcfmac
| mcfemac
;
541 /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
543 static const struct m68k_cpu m68k_extensions
[] =
545 {m68851
, NULL
, "68851", -1},
546 {m68881
, NULL
, "68881", -1},
547 {m68881
, NULL
, "68882", -1},
549 {cfloat
|m68881
, NULL
, "float", 0},
551 {mcfhwdiv
, NULL
, "div", 1},
552 {mcfusp
, NULL
, "usp", 1},
553 {mcfmac
, (void *)&no_mac
, "mac", 1},
554 {mcfemac
, NULL
, "emac", 1},
560 static const struct m68k_cpu m68k_cpus
[] =
562 {m68000
, m68000_ctrl
, "68000", 0},
563 {m68000
, m68000_ctrl
, "68ec000", 1},
564 {m68000
, m68000_ctrl
, "68hc000", 1},
565 {m68000
, m68000_ctrl
, "68hc001", 1},
566 {m68000
, m68000_ctrl
, "68008", 1},
567 {m68000
, m68000_ctrl
, "68302", 1},
568 {m68000
, m68000_ctrl
, "68306", 1},
569 {m68000
, m68000_ctrl
, "68307", 1},
570 {m68000
, m68000_ctrl
, "68322", 1},
571 {m68000
, m68000_ctrl
, "68356", 1},
572 {m68010
, m68010_ctrl
, "68010", 0},
573 {m68020
|m68881
|m68851
, m68020_ctrl
, "68020", 0},
574 {m68020
|m68881
|m68851
, m68020_ctrl
, "68k", 1},
575 {m68020
|m68881
|m68851
, m68020_ctrl
, "68ec020", 1},
576 {m68030
|m68881
|m68851
, m68020_ctrl
, "68030", 0},
577 {m68030
|m68881
|m68851
, m68020_ctrl
, "68ec030", 1},
578 {m68040
, m68040_ctrl
, "68040", 0},
579 {m68040
, m68040_ctrl
, "68ec040", 1},
580 {m68060
, m68060_ctrl
, "68060", 0},
581 {m68060
, m68060_ctrl
, "68ec060", 1},
583 {cpu32
|m68881
, cpu32_ctrl
, "cpu32", 0},
584 {cpu32
|m68881
, cpu32_ctrl
, "68330", 1},
585 {cpu32
|m68881
, cpu32_ctrl
, "68331", 1},
586 {cpu32
|m68881
, cpu32_ctrl
, "68332", 1},
587 {cpu32
|m68881
, cpu32_ctrl
, "68333", 1},
588 {cpu32
|m68881
, cpu32_ctrl
, "68334", 1},
589 {cpu32
|m68881
, cpu32_ctrl
, "68336", 1},
590 {cpu32
|m68881
, cpu32_ctrl
, "68340", 1},
591 {cpu32
|m68881
, cpu32_ctrl
, "68341", 1},
592 {cpu32
|m68881
, cpu32_ctrl
, "68349", 1},
593 {cpu32
|m68881
, cpu32_ctrl
, "68360", 1},
595 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51", 0},
596 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51ac", 1},
597 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51ag", 1},
598 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51cn", 1},
599 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfmac
, mcf51_ctrl
, "51em", 1},
600 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfmac
, mcf51_ctrl
, "51je", 1},
601 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfemac
, mcf51_ctrl
, "51jf", 1},
602 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfemac
, mcf51_ctrl
, "51jg", 1},
603 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51jm", 1},
604 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfmac
, mcf51_ctrl
, "51mm", 1},
605 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51_ctrl
, "51qe", 1},
606 {mcfisa_a
|mcfisa_c
|mcfusp
|mcfemac
, mcf51_ctrl
, "51qm", 1},
608 {mcfisa_a
, mcf_ctrl
, "5200", 0},
609 {mcfisa_a
, mcf_ctrl
, "5202", 1},
610 {mcfisa_a
, mcf_ctrl
, "5204", 1},
611 {mcfisa_a
, mcf5206_ctrl
, "5206", 1},
613 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5206_ctrl
, "5206e", 0},
615 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5208_ctrl
, "5207", -1},
616 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5208_ctrl
, "5208", 0},
618 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5210a_ctrl
, "5210a", 0},
619 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5210a_ctrl
, "5211a", 1},
621 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5211", -1},
622 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5212", -1},
623 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5213", 0},
625 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "5214", -1},
626 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "5216", 0},
627 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "521x", 2},
629 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5221x_ctrl
, "5221x", 0},
631 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf52223_ctrl
, "52221", -1},
632 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf52223_ctrl
, "52223", 0},
634 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52230", -1},
635 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52233", -1},
636 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52234", -1},
637 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52235", 0},
639 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5225_ctrl
, "5224", -1},
640 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5225_ctrl
, "5225", 0},
642 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52277_ctrl
, "52274", -1},
643 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52277_ctrl
, "52277", 0},
645 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5232", -1},
646 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5233", -1},
647 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5234", -1},
648 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5235", -1},
649 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "523x", 0},
651 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5249_ctrl
, "5249", 0},
652 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5250_ctrl
, "5250", 0},
653 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5253_ctrl
, "5253", 0},
655 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52252", -1},
656 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52254", -1},
657 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52255", -1},
658 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52256", -1},
659 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52258", -1},
660 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52259_ctrl
, "52259", 0},
662 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5271_ctrl
, "5270", -1},
663 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5271_ctrl
, "5271", 0},
665 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5272_ctrl
, "5272", 0},
667 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5275_ctrl
, "5274", -1},
668 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5275_ctrl
, "5275", 0},
670 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5280", -1},
671 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5281", -1},
672 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5282", -1},
673 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "528x", 0},
675 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53011", -1},
676 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53012", -1},
677 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53013", -1},
678 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53014", -1},
679 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53015", -1},
680 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53016", -1},
681 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf53017_ctrl
, "53017", 0},
683 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5307_ctrl
, "5307", 0},
685 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5327", -1},
686 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5328", -1},
687 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5329", -1},
688 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "532x", 0},
690 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "5372", -1},
691 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "5373", -1},
692 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "537x", 0},
694 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfmac
, mcf5407_ctrl
, "5407",0},
696 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54418_ctrl
, "54410", -1},
697 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54418_ctrl
, "54415", -1},
698 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54418_ctrl
, "54416", -1},
699 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54418_ctrl
, "54417", -1},
700 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54418_ctrl
, "54418", 0},
702 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54450", -1},
703 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54451", -1},
704 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54452", -1},
705 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54453", -1},
706 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54454", -1},
707 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54455", 0},
709 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5470", -1},
710 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5471", -1},
711 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5472", -1},
712 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5473", -1},
713 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5474", -1},
714 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5475", -1},
715 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "547x", 0},
717 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5480", -1},
718 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5481", -1},
719 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5482", -1},
720 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5483", -1},
721 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5484", -1},
722 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5485", -1},
723 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "548x", 0},
725 {fido_a
, fido_ctrl
, "fidoa", 0},
726 {fido_a
, fido_ctrl
, "fido", 1},
731 static const struct m68k_cpu
*m68k_lookup_cpu
732 (const char *, const struct m68k_cpu
*, int, int *);
733 static int m68k_set_arch (const char *, int, int);
734 static int m68k_set_cpu (const char *, int, int);
735 static int m68k_set_extension (const char *, int, int);
736 static void m68k_init_arch (void);
738 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
739 architecture and we have a lot of relaxation modes. */
741 /* Macros used in the relaxation code. */
742 #define TAB(x,y) (((x) << 2) + (y))
743 #define TABTYPE(x) ((x) >> 2)
745 /* Relaxation states. */
751 /* Here are all the relaxation modes we support. First we can relax ordinary
752 branches. On 68020 and higher and on CPU32 all branch instructions take
753 three forms, so on these CPUs all branches always remain as such. When we
754 have to expand to the LONG form on a 68000, though, we substitute an
755 absolute jump instead. This is a direct replacement for unconditional
756 branches and a branch over a jump for conditional branches. However, if the
757 user requires PIC and disables this with --pcrel, we can only relax between
758 BYTE and SHORT forms, punting if that isn't enough. This gives us four
759 different relaxation modes for branches: */
761 #define BRANCHBWL 0 /* Branch byte, word, or long. */
762 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
763 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
764 #define BRANCHBW 3 /* Branch byte or word. */
766 /* We also relax coprocessor branches and DBcc's. All CPUs that support
767 coprocessor branches support them in word and long forms, so we have only
768 one relaxation mode for them. DBcc's are word only on all CPUs. We can
769 relax them to the LONG form with a branch-around sequence. This sequence
770 can use a long branch (if available) or an absolute jump (if acceptable).
771 This gives us two relaxation modes. If long branches are not available and
772 absolute jumps are not acceptable, we don't relax DBcc's. */
774 #define FBRANCH 4 /* Coprocessor branch. */
775 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
776 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
778 /* That's all for instruction relaxation. However, we also relax PC-relative
779 operands. Specifically, we have three operand relaxation modes. On the
780 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
781 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
782 two. Also PC+displacement+index operands in their simple form (with a non-
783 suppressed index without memory indirection) are supported on all CPUs, but
784 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
785 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
786 form of the PC+displacement+index operand. Finally, some absolute operands
787 can be relaxed down to 16-bit PC-relative. */
789 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
790 #define PCINDEX 8 /* PC + displacement + index. */
791 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
793 /* This relaxation is required for branches where there is no long
794 branch and we are in pcrel mode. We generate a bne/beq pair. */
795 #define BRANCHBWPL 10 /* Branch byte, word or pair of longs
798 /* Note that calls to frag_var need to specify the maximum expansion
799 needed; this is currently 12 bytes for bne/beq pair. */
800 #define FRAG_VAR_SIZE 12
803 How far Forward this mode will reach:
804 How far Backward this mode will reach:
805 How many bytes this mode will add to the size of the frag
806 Which mode to go to if the offset won't fit in this one
808 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
809 relax_typeS md_relax_table
[] =
811 { 127, -128, 0, TAB (BRANCHBWL
, SHORT
) },
812 { 32767, -32768, 2, TAB (BRANCHBWL
, LONG
) },
816 { 127, -128, 0, TAB (BRABSJUNC
, SHORT
) },
817 { 32767, -32768, 2, TAB (BRABSJUNC
, LONG
) },
821 { 127, -128, 0, TAB (BRABSJCOND
, SHORT
) },
822 { 32767, -32768, 2, TAB (BRABSJCOND
, LONG
) },
826 { 127, -128, 0, TAB (BRANCHBW
, SHORT
) },
831 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
832 { 32767, -32768, 2, TAB (FBRANCH
, LONG
) },
836 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
837 { 32767, -32768, 2, TAB (DBCCLBR
, LONG
) },
841 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
842 { 32767, -32768, 2, TAB (DBCCABSJ
, LONG
) },
846 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
847 { 32767, -32768, 2, TAB (PCREL1632
, LONG
) },
851 { 125, -130, 0, TAB (PCINDEX
, SHORT
) },
852 { 32765, -32770, 2, TAB (PCINDEX
, LONG
) },
856 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
857 { 32767, -32768, 2, TAB (ABSTOPCREL
, LONG
) },
861 { 127, -128, 0, TAB (BRANCHBWPL
, SHORT
) },
862 { 32767, -32768, 2, TAB (BRANCHBWPL
, LONG
) },
867 /* These are the machine dependent pseudo-ops. These are included so
868 the assembler can work on the output from the SUN C compiler, which
871 /* This table describes all the machine specific pseudo-ops the assembler
872 has to support. The fields are:
873 pseudo-op name without dot
874 function to call to execute this pseudo-op
875 Integer arg to pass to the function. */
876 const pseudo_typeS md_pseudo_table
[] =
878 {"data1", s_data1
, 0},
879 {"data2", s_data2
, 0},
882 {"skip", s_space
, 0},
884 {"align", s_align_bytes
, 0},
885 {"swbeg", s_ignore
, 0},
886 {"long", m68k_elf_cons
, 4},
887 {"extend", float_cons
, 'x'},
888 {"ldouble", float_cons
, 'x'},
890 {"arch", s_m68k_arch
, 0},
891 {"cpu", s_m68k_cpu
, 0},
893 /* The following pseudo-ops are supported for MRI compatibility. */
895 {"comline", s_space
, 1},
897 {"mask2", s_ignore
, 0},
900 {"restore", s_restore
, 0},
904 {"if.b", s_mri_if
, 'b'},
905 {"if.w", s_mri_if
, 'w'},
906 {"if.l", s_mri_if
, 'l'},
907 {"else", s_mri_else
, 0},
908 {"else.s", s_mri_else
, 's'},
909 {"else.l", s_mri_else
, 'l'},
910 {"endi", s_mri_endi
, 0},
911 {"break", s_mri_break
, 0},
912 {"break.s", s_mri_break
, 's'},
913 {"break.l", s_mri_break
, 'l'},
914 {"next", s_mri_next
, 0},
915 {"next.s", s_mri_next
, 's'},
916 {"next.l", s_mri_next
, 'l'},
917 {"for", s_mri_for
, 0},
918 {"for.b", s_mri_for
, 'b'},
919 {"for.w", s_mri_for
, 'w'},
920 {"for.l", s_mri_for
, 'l'},
921 {"endf", s_mri_endf
, 0},
922 {"repeat", s_mri_repeat
, 0},
923 {"until", s_mri_until
, 0},
924 {"until.b", s_mri_until
, 'b'},
925 {"until.w", s_mri_until
, 'w'},
926 {"until.l", s_mri_until
, 'l'},
927 {"while", s_mri_while
, 0},
928 {"while.b", s_mri_while
, 'b'},
929 {"while.w", s_mri_while
, 'w'},
930 {"while.l", s_mri_while
, 'l'},
931 {"endw", s_mri_endw
, 0},
936 /* The mote pseudo ops are put into the opcode table, since they
937 don't start with a . they look like opcodes to gas. */
939 const pseudo_typeS mote_pseudo_table
[] =
952 {"xdef", s_globl
, 0},
953 {"align", s_align_bytes
, 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]])))
979 /* Return zero if the reference to SYMBOL from within the same segment may
982 /* On an ELF system, we can't relax an externally visible symbol,
983 because it may be overridden by a shared library. However, if
984 TARGET_OS is "elf", then we presume that we are assembling for an
985 embedded system, in which case we don't have to worry about shared
986 libraries, and we can relax any external sym. */
988 #define relaxable_symbol(symbol) \
989 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
990 || S_IS_WEAK (symbol)))
992 /* Compute the relocation code for a fixup of SIZE bytes, using pc
993 relative relocation if PCREL is non-zero. PIC says whether a special
994 pic relocation was requested. */
996 static bfd_reloc_code_real_type
997 get_reloc_code (int size
, int pcrel
, enum pic_relocation pic
)
1005 return BFD_RELOC_8_GOT_PCREL
;
1007 return BFD_RELOC_16_GOT_PCREL
;
1009 return BFD_RELOC_32_GOT_PCREL
;
1017 return BFD_RELOC_8_GOTOFF
;
1019 return BFD_RELOC_16_GOTOFF
;
1021 return BFD_RELOC_32_GOTOFF
;
1029 return BFD_RELOC_8_PLT_PCREL
;
1031 return BFD_RELOC_16_PLT_PCREL
;
1033 return BFD_RELOC_32_PLT_PCREL
;
1041 return BFD_RELOC_8_PLTOFF
;
1043 return BFD_RELOC_16_PLTOFF
;
1045 return BFD_RELOC_32_PLTOFF
;
1053 return BFD_RELOC_68K_TLS_GD8
;
1055 return BFD_RELOC_68K_TLS_GD16
;
1057 return BFD_RELOC_68K_TLS_GD32
;
1065 return BFD_RELOC_68K_TLS_LDM8
;
1067 return BFD_RELOC_68K_TLS_LDM16
;
1069 return BFD_RELOC_68K_TLS_LDM32
;
1077 return BFD_RELOC_68K_TLS_LDO8
;
1079 return BFD_RELOC_68K_TLS_LDO16
;
1081 return BFD_RELOC_68K_TLS_LDO32
;
1089 return BFD_RELOC_68K_TLS_IE8
;
1091 return BFD_RELOC_68K_TLS_IE16
;
1093 return BFD_RELOC_68K_TLS_IE32
;
1101 return BFD_RELOC_68K_TLS_LE8
;
1103 return BFD_RELOC_68K_TLS_LE16
;
1105 return BFD_RELOC_68K_TLS_LE32
;
1115 return BFD_RELOC_8_PCREL
;
1117 return BFD_RELOC_16_PCREL
;
1119 return BFD_RELOC_32_PCREL
;
1129 return BFD_RELOC_16
;
1131 return BFD_RELOC_32
;
1138 if (pic
== pic_none
)
1139 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
1141 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
1145 if (pic
== pic_none
)
1146 as_bad (_("Can not do %d byte relocation"), size
);
1148 as_bad (_("Can not do %d byte pic relocation"), size
);
1151 return BFD_RELOC_NONE
;
1154 /* Here we decide which fixups can be adjusted to make them relative
1155 to the beginning of the section instead of the symbol. Basically
1156 we need to make sure that the dynamic relocations are done
1157 correctly, so in some cases we force the original symbol to be
1160 tc_m68k_fix_adjustable (fixS
*fixP
)
1162 /* Adjust_reloc_syms doesn't know about the GOT. */
1163 switch (fixP
->fx_r_type
)
1165 case BFD_RELOC_8_GOT_PCREL
:
1166 case BFD_RELOC_16_GOT_PCREL
:
1167 case BFD_RELOC_32_GOT_PCREL
:
1168 case BFD_RELOC_8_GOTOFF
:
1169 case BFD_RELOC_16_GOTOFF
:
1170 case BFD_RELOC_32_GOTOFF
:
1171 case BFD_RELOC_8_PLT_PCREL
:
1172 case BFD_RELOC_16_PLT_PCREL
:
1173 case BFD_RELOC_32_PLT_PCREL
:
1174 case BFD_RELOC_8_PLTOFF
:
1175 case BFD_RELOC_16_PLTOFF
:
1176 case BFD_RELOC_32_PLTOFF
:
1177 case BFD_RELOC_68K_TLS_GD32
:
1178 case BFD_RELOC_68K_TLS_GD16
:
1179 case BFD_RELOC_68K_TLS_GD8
:
1180 case BFD_RELOC_68K_TLS_LDM32
:
1181 case BFD_RELOC_68K_TLS_LDM16
:
1182 case BFD_RELOC_68K_TLS_LDM8
:
1183 case BFD_RELOC_68K_TLS_LDO32
:
1184 case BFD_RELOC_68K_TLS_LDO16
:
1185 case BFD_RELOC_68K_TLS_LDO8
:
1186 case BFD_RELOC_68K_TLS_IE32
:
1187 case BFD_RELOC_68K_TLS_IE16
:
1188 case BFD_RELOC_68K_TLS_IE8
:
1189 case BFD_RELOC_68K_TLS_LE32
:
1190 case BFD_RELOC_68K_TLS_LE16
:
1191 case BFD_RELOC_68K_TLS_LE8
:
1194 case BFD_RELOC_VTABLE_INHERIT
:
1195 case BFD_RELOC_VTABLE_ENTRY
:
1204 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
1207 bfd_reloc_code_real_type code
;
1209 /* If the tcbit is set, then this was a fixup of a negative value
1210 that was never resolved. We do not have a reloc to handle this,
1211 so just return. We assume that other code will have detected this
1212 situation and produced a helpful error message, so we just tell the
1213 user that the reloc cannot be produced. */
1217 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1218 _("Unable to produce reloc against symbol '%s'"),
1219 S_GET_NAME (fixp
->fx_addsy
));
1223 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
1225 code
= fixp
->fx_r_type
;
1227 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1228 that fixup_segment converted a non-PC relative reloc into a
1229 PC relative reloc. In such a case, we need to convert the
1236 code
= BFD_RELOC_8_PCREL
;
1239 code
= BFD_RELOC_16_PCREL
;
1242 code
= BFD_RELOC_32_PCREL
;
1244 case BFD_RELOC_8_PCREL
:
1245 case BFD_RELOC_16_PCREL
:
1246 case BFD_RELOC_32_PCREL
:
1247 case BFD_RELOC_8_GOT_PCREL
:
1248 case BFD_RELOC_16_GOT_PCREL
:
1249 case BFD_RELOC_32_GOT_PCREL
:
1250 case BFD_RELOC_8_GOTOFF
:
1251 case BFD_RELOC_16_GOTOFF
:
1252 case BFD_RELOC_32_GOTOFF
:
1253 case BFD_RELOC_8_PLT_PCREL
:
1254 case BFD_RELOC_16_PLT_PCREL
:
1255 case BFD_RELOC_32_PLT_PCREL
:
1256 case BFD_RELOC_8_PLTOFF
:
1257 case BFD_RELOC_16_PLTOFF
:
1258 case BFD_RELOC_32_PLTOFF
:
1259 case BFD_RELOC_68K_TLS_GD32
:
1260 case BFD_RELOC_68K_TLS_GD16
:
1261 case BFD_RELOC_68K_TLS_GD8
:
1262 case BFD_RELOC_68K_TLS_LDM32
:
1263 case BFD_RELOC_68K_TLS_LDM16
:
1264 case BFD_RELOC_68K_TLS_LDM8
:
1265 case BFD_RELOC_68K_TLS_LDO32
:
1266 case BFD_RELOC_68K_TLS_LDO16
:
1267 case BFD_RELOC_68K_TLS_LDO8
:
1268 case BFD_RELOC_68K_TLS_IE32
:
1269 case BFD_RELOC_68K_TLS_IE16
:
1270 case BFD_RELOC_68K_TLS_IE8
:
1271 case BFD_RELOC_68K_TLS_LE32
:
1272 case BFD_RELOC_68K_TLS_LE16
:
1273 case BFD_RELOC_68K_TLS_LE8
:
1276 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1277 _("Cannot make %s relocation PC relative"),
1278 bfd_get_reloc_code_name (code
));
1284 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1285 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1287 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1288 MAP (1, 0, BFD_RELOC_8
);
1289 MAP (2, 0, BFD_RELOC_16
);
1290 MAP (4, 0, BFD_RELOC_32
);
1291 MAP (1, 1, BFD_RELOC_8_PCREL
);
1292 MAP (2, 1, BFD_RELOC_16_PCREL
);
1293 MAP (4, 1, BFD_RELOC_32_PCREL
);
1301 reloc
= XNEW (arelent
);
1302 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
1303 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1304 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1305 if (!fixp
->fx_pcrel
)
1306 reloc
->addend
= fixp
->fx_addnumber
;
1308 reloc
->addend
= (section
->vma
1309 + fixp
->fx_pcrel_adjust
1310 + fixp
->fx_addnumber
1311 + md_pcrel_from (fixp
));
1313 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1314 gas_assert (reloc
->howto
!= 0);
1319 /* Handle of the OPCODE hash table. NULL means any use before
1320 m68k_ip_begin() will crash. */
1321 static struct hash_control
*op_hash
;
1323 /* Assemble an m68k instruction. */
1326 m68k_ip (char *instring
)
1329 struct m68k_op
*opP
;
1330 const struct m68k_incant
*opcode
;
1332 int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1333 char *pdot
, *pdotmove
;
1334 enum m68k_size siz1
, siz2
;
1338 struct m68k_op operands_backup
[6];
1339 LITTLENUM_TYPE words
[6];
1340 LITTLENUM_TYPE
*wordp
;
1341 unsigned long ok_arch
= 0;
1343 if (*instring
== ' ')
1344 instring
++; /* Skip leading whitespace. */
1346 /* Scan up to end of operation-code, which MUST end in end-of-string
1347 or exactly 1 space. */
1349 for (p
= instring
; *p
!= '\0'; p
++)
1359 the_ins
.error
= _("No operator");
1363 /* p now points to the end of the opcode name, probably whitespace.
1364 Make sure the name is null terminated by clobbering the
1365 whitespace, look it up in the hash table, then fix it back.
1366 Remove a dot, first, since the opcode tables have none. */
1369 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1370 *pdotmove
= pdotmove
[1];
1376 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1381 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1382 *pdotmove
= pdotmove
[-1];
1389 the_ins
.error
= _("Unknown operator");
1393 /* Found a legitimate opcode, start matching operands. */
1397 if (opcode
->m_operands
== 0)
1399 char *old
= input_line_pointer
;
1401 input_line_pointer
= p
;
1402 /* Ahh - it's a motorola style pseudo op. */
1403 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1404 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1405 input_line_pointer
= old
;
1411 if (flag_mri
&& opcode
->m_opnum
== 0)
1413 /* In MRI mode, random garbage is allowed after an instruction
1414 which accepts no operands. */
1415 the_ins
.args
= opcode
->m_operands
;
1416 the_ins
.numargs
= opcode
->m_opnum
;
1417 the_ins
.numo
= opcode
->m_codenum
;
1418 the_ins
.opcode
[0] = getone (opcode
);
1419 the_ins
.opcode
[1] = gettwo (opcode
);
1423 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1425 p
= crack_operand (p
, opP
);
1429 the_ins
.error
= opP
->error
;
1434 opsfound
= opP
- &the_ins
.operands
[0];
1436 /* This ugly hack is to support the floating pt opcodes in their
1437 standard form. Essentially, we fake a first entry of type COP#1 */
1438 if (opcode
->m_operands
[0] == 'I')
1442 for (n
= opsfound
; n
> 0; --n
)
1443 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1445 memset (&the_ins
.operands
[0], '\0', sizeof (the_ins
.operands
[0]));
1446 the_ins
.operands
[0].mode
= CONTROL
;
1447 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1451 /* We've got the operands. Find an opcode that'll accept them. */
1454 /* If we didn't get the right number of ops, or we have no
1455 common model with this pattern then reject this pattern. */
1457 ok_arch
|= opcode
->m_arch
;
1458 if (opsfound
!= opcode
->m_opnum
1459 || ((opcode
->m_arch
& current_architecture
) == 0))
1465 /* Make a copy of the operands of this insn so that
1466 we can modify them safely, should we want to. */
1467 gas_assert (opsfound
<= (int) ARRAY_SIZE (operands_backup
));
1468 for (i
= 0; i
< opsfound
; i
++)
1469 operands_backup
[i
] = the_ins
.operands
[i
];
1471 for (s
= opcode
->m_operands
, opP
= &operands_backup
[0];
1475 /* Warning: this switch is huge! */
1476 /* I've tried to organize the cases into this order:
1477 non-alpha first, then alpha by letter. Lower-case
1478 goes directly before uppercase counterpart. */
1479 /* Code with multiple case ...: gets sorted by the lowest
1480 case ... it belongs to. I hope this makes sense. */
1586 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1603 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1622 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1632 if (opP
->mode
!= IMMED
)
1634 else if (s
[1] == 'b'
1635 && ! isvar (&opP
->disp
)
1636 && (opP
->disp
.exp
.X_op
!= O_constant
1637 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1639 else if (s
[1] == 'B'
1640 && ! isvar (&opP
->disp
)
1641 && (opP
->disp
.exp
.X_op
!= O_constant
1642 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1644 else if (s
[1] == 'w'
1645 && ! isvar (&opP
->disp
)
1646 && (opP
->disp
.exp
.X_op
!= O_constant
1647 || ! isword (opP
->disp
.exp
.X_add_number
)))
1649 else if (s
[1] == 'W'
1650 && ! isvar (&opP
->disp
)
1651 && (opP
->disp
.exp
.X_op
!= O_constant
1652 || ! issword (opP
->disp
.exp
.X_add_number
)))
1658 if (opP
->mode
!= IMMED
)
1663 if (opP
->mode
== AREG
1664 || opP
->mode
== CONTROL
1665 || opP
->mode
== FPREG
1666 || opP
->mode
== IMMED
1667 || opP
->mode
== REGLST
1668 || (opP
->mode
!= ABSL
1670 || opP
->reg
== ZPC
)))
1675 if (opP
->mode
== CONTROL
1676 || opP
->mode
== FPREG
1677 || opP
->mode
== REGLST
1678 || opP
->mode
== IMMED
1679 || (opP
->mode
!= ABSL
1681 || opP
->reg
== ZPC
)))
1709 if (opP
->mode
== CONTROL
1710 || opP
->mode
== FPREG
1711 || opP
->mode
== REGLST
)
1716 if (opP
->mode
!= AINC
)
1721 if (opP
->mode
!= ADEC
)
1771 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1792 case '~': /* For now! (JF FOO is this right?) */
1814 if (opP
->mode
!= CONTROL
1815 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1820 if (opP
->mode
!= AREG
)
1825 if (opP
->mode
!= AINDR
)
1830 if (opP
->mode
!= AINDR
&& opP
->mode
!= AINC
&& opP
->mode
!= ADEC
1831 && (opP
->mode
!= DISP
1833 || opP
->reg
> ADDR7
))
1838 if (opP
->mode
!= ABSL
1840 && strncmp (instring
, "jbsr", 4) == 0))
1863 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1868 if (opP
->mode
!= DISP
1870 || opP
->reg
> ADDR7
)
1875 if (opP
->mode
!= DREG
)
1880 if (opP
->reg
!= ACC
)
1885 if (opP
->reg
!= ACC
&& opP
->reg
!= ACC1
1886 && opP
->reg
!= ACC2
&& opP
->reg
!= ACC3
)
1891 if (opP
->mode
!= FPREG
)
1896 if (opP
->reg
!= MACSR
)
1901 if (opP
->reg
!= ACCEXT01
&& opP
->reg
!= ACCEXT23
)
1906 if (opP
->reg
!= MASK
)
1911 if (opP
->mode
!= CONTROL
1918 if (opP
->mode
!= LSH
&& opP
->mode
!= RSH
)
1923 if (opP
->mode
!= CONTROL
1925 || opP
->reg
> last_movec_reg
1930 const enum m68k_register
*rp
;
1932 for (rp
= control_regs
; *rp
; rp
++)
1934 if (*rp
== opP
->reg
)
1936 /* In most CPUs RAMBAR refers to control reg
1937 c05 (RAMBAR1), but a few CPUs have it
1938 refer to c04 (RAMBAR0). */
1939 else if (*rp
== RAMBAR_ALT
&& opP
->reg
== RAMBAR
)
1941 opP
->reg
= RAMBAR_ALT
;
1951 if (opP
->mode
!= IMMED
)
1957 if (opP
->mode
== DREG
1958 || opP
->mode
== AREG
1959 || opP
->mode
== FPREG
)
1968 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1971 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1974 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1982 else if (opP
->mode
== CONTROL
)
1991 opP
->mask
= 1 << 24;
1994 opP
->mask
= 1 << 25;
1997 opP
->mask
= 1 << 26;
2006 else if (opP
->mode
!= REGLST
)
2008 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
2010 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
2015 if (opP
->mode
!= IMMED
)
2017 else if (opP
->disp
.exp
.X_op
!= O_constant
2018 || ! issbyte (opP
->disp
.exp
.X_add_number
))
2020 else if (! m68k_quick
2021 && instring
[3] != 'q'
2022 && instring
[4] != 'q')
2027 if (opP
->mode
!= DREG
2028 && opP
->mode
!= IMMED
2029 && opP
->mode
!= ABSL
)
2034 if (opP
->mode
!= IMMED
)
2036 else if (opP
->disp
.exp
.X_op
!= O_constant
2037 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
2039 else if (! m68k_quick
2040 && (strncmp (instring
, "add", 3) == 0
2041 || strncmp (instring
, "sub", 3) == 0)
2042 && instring
[3] != 'q')
2047 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
2052 if (opP
->mode
!= AINDR
2053 && (opP
->mode
!= BASE
2055 && opP
->reg
!= ZADDR0
)
2056 || opP
->disp
.exp
.X_op
!= O_absent
2057 || ((opP
->index
.reg
< DATA0
2058 || opP
->index
.reg
> DATA7
)
2059 && (opP
->index
.reg
< ADDR0
2060 || opP
->index
.reg
> ADDR7
))
2061 || opP
->index
.size
!= SIZE_UNSPEC
2062 || opP
->index
.scale
!= 1))
2067 if (opP
->mode
!= CONTROL
2068 || ! (opP
->reg
== FPI
2070 || opP
->reg
== FPC
))
2075 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
2080 if (opP
->mode
!= IMMED
)
2082 else if (opP
->disp
.exp
.X_op
!= O_constant
2083 || TRUNC (opP
->disp
.exp
.X_add_number
) > 7)
2088 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
2093 if (opP
->mode
!= IMMED
)
2095 else if (opP
->disp
.exp
.X_op
!= O_constant
2096 || (TRUNC (opP
->disp
.exp
.X_add_number
) != 0xffffffff
2097 && TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 6))
2102 if (opP
->mode
!= IMMED
)
2104 else if (opP
->disp
.exp
.X_op
!= O_constant
2105 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
2110 if (opP
->mode
!= IMMED
)
2112 else if (opP
->disp
.exp
.X_op
!= O_constant
2113 || TRUNC (opP
->disp
.exp
.X_add_number
) > 511)
2117 /* JF these are out of order. We could put them
2118 in order if we were willing to put up with
2119 bunches of #ifdef m68851s in the code.
2121 Don't forget that you need these operands
2122 to use 68030 MMU instructions. */
2124 /* Memory addressing mode used by pflushr. */
2126 if (opP
->mode
== CONTROL
2127 || opP
->mode
== FPREG
2128 || opP
->mode
== DREG
2129 || opP
->mode
== AREG
2130 || opP
->mode
== REGLST
)
2132 /* We should accept immediate operands, but they
2133 supposedly have to be quad word, and we don't
2134 handle that. I would like to see what a Motorola
2135 assembler does before doing something here. */
2136 if (opP
->mode
== IMMED
)
2141 if (opP
->mode
!= CONTROL
2142 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
2147 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
2152 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
2157 if (opP
->mode
!= CONTROL
2160 && opP
->reg
!= SCC
))
2165 if (opP
->mode
!= CONTROL
2171 if (opP
->mode
!= CONTROL
2174 && opP
->reg
!= CRP
))
2198 if (opP
->mode
!= CONTROL
2199 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
2200 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
2205 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
2210 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
2215 if (opP
->mode
!= CONTROL
2224 if (opP
->mode
!= ABSL
)
2229 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
2231 /* FIXME: kludge instead of fixing parser:
2232 upper/lower registers are *not* CONTROL
2233 registers, but ordinary ones. */
2234 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
2235 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
2242 if (!(opP
->mode
== AINDR
2243 || (opP
->mode
== DISP
2244 && !(opP
->reg
== PC
|| opP
->reg
== ZPC
))))
2249 if (!(opP
->mode
== AINDR
|| opP
->mode
== DISP
))
2261 /* Since we have found the correct instruction, copy
2262 in the modifications that we may have made. */
2264 for (i
= 0; i
< opsfound
; i
++)
2265 the_ins
.operands
[i
] = operands_backup
[i
];
2271 opcode
= opcode
->m_next
;
2276 && !(ok_arch
& current_architecture
))
2278 const struct m68k_cpu
*cpu
;
2281 char *buf
= XNEWVEC (char, space
+ 1);
2285 the_ins
.error
= buf
;
2286 /* Make sure there's a NUL at the end of the buffer -- strncpy
2287 won't write one when it runs out of buffer. */
2289 #define APPEND(STRING) \
2290 (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
2292 APPEND (_("invalid instruction for this architecture; needs "));
2296 APPEND ("ColdFire ISA_A");
2299 APPEND ("ColdFire ");
2300 APPEND (_("hardware divide"));
2303 APPEND ("ColdFire ISA_A+");
2306 APPEND ("ColdFire ISA_B");
2309 APPEND ("ColdFire ISA_C");
2312 APPEND ("ColdFire fpu");
2315 APPEND ("M68K fpu");
2318 APPEND ("M68K mmu");
2322 APPEND (_("or higher"));
2326 APPEND (_("or higher"));
2330 APPEND (_("or higher"));
2338 for (cpu
= m68k_cpus
; cpu
->name
; cpu
++)
2339 if (!cpu
->alias
&& (cpu
->arch
& ok_arch
))
2341 const struct m68k_cpu
*alias
;
2342 int seen_master
= 0;
2348 for (alias
= cpu
; alias
!= m68k_cpus
; alias
--)
2349 if (alias
[-1].alias
>= 0)
2351 for (; !seen_master
|| alias
->alias
> 0; alias
++)
2361 APPEND (alias
->name
);
2374 /* We ran out of space, so replace the end of the list
2379 strcpy (buf
, " ...");
2383 the_ins
.error
= _("operands mismatch");
2390 /* Now assemble it. */
2391 the_ins
.args
= opcode
->m_operands
;
2392 the_ins
.numargs
= opcode
->m_opnum
;
2393 the_ins
.numo
= opcode
->m_codenum
;
2394 the_ins
.opcode
[0] = getone (opcode
);
2395 the_ins
.opcode
[1] = gettwo (opcode
);
2397 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2402 /* This switch is a doozy.
2403 Watch the first step; it's a big one! */
2436 tmpreg
= 0x3c; /* 7.4 */
2437 if (strchr ("bwl", s
[1]))
2438 nextword
= get_num (&opP
->disp
, 90);
2440 nextword
= get_num (&opP
->disp
, 0);
2441 if (isvar (&opP
->disp
))
2442 add_fix (s
[1], &opP
->disp
, 0, 0);
2446 if (!isbyte (nextword
))
2447 opP
->error
= _("operand out of range");
2452 if (!isword (nextword
))
2453 opP
->error
= _("operand out of range");
2458 if (!issword (nextword
))
2459 opP
->error
= _("operand out of range");
2464 addword (nextword
>> 16);
2491 /* We gotta put out some float. */
2492 if (op (&opP
->disp
) != O_big
)
2497 /* Can other cases happen here? */
2498 if (op (&opP
->disp
) != O_constant
)
2501 val
= (valueT
) offs (&opP
->disp
);
2505 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2506 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2510 offs (&opP
->disp
) = gencnt
;
2512 if (offs (&opP
->disp
) > 0)
2514 if (offs (&opP
->disp
) > baseo
)
2516 as_warn (_("Bignum too big for %c format; truncated"),
2518 offs (&opP
->disp
) = baseo
;
2520 baseo
-= offs (&opP
->disp
);
2523 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
2524 offs (&opP
->disp
)--;
2529 gen_to_words (words
, baseo
, (long) outro
);
2530 for (wordp
= words
; baseo
--; wordp
++)
2534 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2537 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2540 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2543 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2546 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2550 nextword
= get_num (&opP
->disp
, 90);
2552 /* Convert mode 5 addressing with a zero offset into
2553 mode 2 addressing to reduce the instruction size by a
2555 if (! isvar (&opP
->disp
)
2557 && (opP
->disp
.size
== SIZE_UNSPEC
)
2558 && (opP
->reg
>= ADDR0
)
2559 && (opP
->reg
<= ADDR7
))
2561 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2566 && ! isvar (&opP
->disp
)
2569 opP
->disp
.exp
.X_op
= O_symbol
;
2570 opP
->disp
.exp
.X_add_symbol
=
2571 section_symbol (absolute_section
);
2574 /* Force into index mode. Hope this works. */
2576 /* We do the first bit for 32-bit displacements, and the
2577 second bit for 16 bit ones. It is possible that we
2578 should make the default be WORD instead of LONG, but
2579 I think that'd break GCC, so we put up with a little
2580 inefficiency for the sake of working output. */
2582 if (!issword (nextword
)
2583 || (isvar (&opP
->disp
)
2584 && ((opP
->disp
.size
== SIZE_UNSPEC
2585 && flag_short_refs
== 0
2586 && cpu_of_arch (current_architecture
) >= m68020
2587 && ! arch_coldfire_p (current_architecture
))
2588 || opP
->disp
.size
== SIZE_LONG
)))
2590 if (cpu_of_arch (current_architecture
) < m68020
2591 || arch_coldfire_p (current_architecture
))
2593 _("displacement too large for this architecture; needs 68020 or higher");
2595 tmpreg
= 0x3B; /* 7.3 */
2597 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2598 if (isvar (&opP
->disp
))
2602 if (opP
->disp
.size
== SIZE_LONG
2603 /* If the displacement needs pic
2604 relocation it cannot be relaxed. */
2605 || opP
->disp
.pic_reloc
!= pic_none
)
2608 add_fix ('l', &opP
->disp
, 1, 2);
2612 add_frag (adds (&opP
->disp
),
2613 SEXT (offs (&opP
->disp
)),
2614 TAB (PCREL1632
, SZ_UNDEF
));
2621 add_fix ('l', &opP
->disp
, 0, 0);
2626 addword (nextword
>> 16);
2631 tmpreg
= 0x3A; /* 7.2 */
2633 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2635 if (isvar (&opP
->disp
))
2639 add_fix ('w', &opP
->disp
, 1, 0);
2642 add_fix ('w', &opP
->disp
, 0, 0);
2652 baseo
= get_num (&opP
->disp
, 90);
2653 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2654 outro
= get_num (&opP
->odisp
, 90);
2655 /* Figure out the `addressing mode'.
2656 Also turn on the BASE_DISABLE bit, if needed. */
2657 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2659 tmpreg
= 0x3b; /* 7.3 */
2660 if (opP
->reg
== ZPC
)
2663 else if (opP
->reg
== 0)
2666 tmpreg
= 0x30; /* 6.garbage */
2668 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2671 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2674 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2676 siz1
= opP
->disp
.size
;
2677 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2678 siz2
= opP
->odisp
.size
;
2682 /* Index register stuff. */
2683 if (opP
->index
.reg
!= 0
2684 && opP
->index
.reg
>= DATA
2685 && opP
->index
.reg
<= ADDR7
)
2687 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2689 if (opP
->index
.size
== SIZE_LONG
2690 || (opP
->index
.size
== SIZE_UNSPEC
2691 && m68k_index_width_default
== SIZE_LONG
))
2694 if ((opP
->index
.scale
!= 1
2695 && cpu_of_arch (current_architecture
) < m68020
)
2696 || (opP
->index
.scale
== 8
2697 && (arch_coldfire_p (current_architecture
)
2698 && !arch_coldfire_fpu (current_architecture
))))
2701 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2704 if (arch_coldfire_p (current_architecture
)
2705 && opP
->index
.size
== SIZE_WORD
)
2706 opP
->error
= _("invalid index size for coldfire");
2708 switch (opP
->index
.scale
)
2725 GET US OUT OF HERE! */
2727 /* Must be INDEX, with an index register. Address
2728 register cannot be ZERO-PC, and either :b was
2729 forced, or we know it will fit. For a 68000 or
2730 68010, force this mode anyways, because the
2731 larger modes aren't supported. */
2732 if (opP
->mode
== BASE
2733 && ((opP
->reg
>= ADDR0
2734 && opP
->reg
<= ADDR7
)
2737 if (siz1
== SIZE_BYTE
2738 || cpu_of_arch (current_architecture
) < m68020
2739 || arch_coldfire_p (current_architecture
)
2740 || (siz1
== SIZE_UNSPEC
2741 && ! isvar (&opP
->disp
)
2742 && issbyte (baseo
)))
2744 nextword
+= baseo
& 0xff;
2746 if (isvar (&opP
->disp
))
2748 /* Do a byte relocation. If it doesn't
2749 fit (possible on m68000) let the
2750 fixup processing complain later. */
2752 add_fix ('B', &opP
->disp
, 1, 1);
2754 add_fix ('B', &opP
->disp
, 0, 0);
2756 else if (siz1
!= SIZE_BYTE
)
2758 if (siz1
!= SIZE_UNSPEC
)
2759 as_warn (_("Forcing byte displacement"));
2760 if (! issbyte (baseo
))
2761 opP
->error
= _("byte displacement out of range");
2766 else if (siz1
== SIZE_UNSPEC
2768 && isvar (&opP
->disp
)
2769 && subs (&opP
->disp
) == NULL
2770 /* If the displacement needs pic
2771 relocation it cannot be relaxed. */
2772 && opP
->disp
.pic_reloc
== pic_none
)
2774 /* The code in md_convert_frag_1 needs to be
2775 able to adjust nextword. Call frag_grow
2776 to ensure that we have enough space in
2777 the frag obstack to make all the bytes
2780 nextword
+= baseo
& 0xff;
2782 add_frag (adds (&opP
->disp
),
2783 SEXT (offs (&opP
->disp
)),
2784 TAB (PCINDEX
, SZ_UNDEF
));
2792 nextword
|= 0x40; /* No index reg. */
2793 if (opP
->index
.reg
>= ZDATA0
2794 && opP
->index
.reg
<= ZDATA7
)
2795 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2796 else if (opP
->index
.reg
>= ZADDR0
2797 || opP
->index
.reg
<= ZADDR7
)
2798 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2801 /* It isn't simple. */
2803 if (cpu_of_arch (current_architecture
) < m68020
2804 || arch_coldfire_p (current_architecture
))
2806 _("invalid operand mode for this architecture; needs 68020 or higher");
2809 /* If the guy specified a width, we assume that it is
2810 wide enough. Maybe it isn't. If so, we lose. */
2814 if (isvar (&opP
->disp
)
2816 : ! issword (baseo
))
2821 else if (! isvar (&opP
->disp
) && baseo
== 0)
2830 as_warn (_(":b not permitted; defaulting to :w"));
2840 /* Figure out inner displacement stuff. */
2841 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2843 if (cpu_of_arch (current_architecture
) & cpu32
)
2844 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2848 if (isvar (&opP
->odisp
)
2850 : ! issword (outro
))
2855 else if (! isvar (&opP
->odisp
) && outro
== 0)
2864 as_warn (_(":b not permitted; defaulting to :w"));
2873 if (opP
->mode
== POST
2874 && (nextword
& 0x40) == 0)
2879 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2881 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2882 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2884 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2886 if (siz1
== SIZE_LONG
)
2887 addword (baseo
>> 16);
2888 if (siz1
!= SIZE_UNSPEC
)
2891 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2892 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2893 if (siz2
== SIZE_LONG
)
2894 addword (outro
>> 16);
2895 if (siz2
!= SIZE_UNSPEC
)
2901 nextword
= get_num (&opP
->disp
, 90);
2902 switch (opP
->disp
.size
)
2907 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2909 tmpreg
= 0x38; /* 7.0 */
2913 if (isvar (&opP
->disp
)
2914 && !subs (&opP
->disp
)
2915 && adds (&opP
->disp
)
2916 /* If the displacement needs pic relocation it
2917 cannot be relaxed. */
2918 && opP
->disp
.pic_reloc
== pic_none
2920 && !strchr ("~%&$?", s
[0]))
2922 tmpreg
= 0x3A; /* 7.2 */
2923 add_frag (adds (&opP
->disp
),
2924 SEXT (offs (&opP
->disp
)),
2925 TAB (ABSTOPCREL
, SZ_UNDEF
));
2930 if (isvar (&opP
->disp
))
2931 add_fix ('l', &opP
->disp
, 0, 0);
2933 tmpreg
= 0x39;/* 7.1 mode */
2934 addword (nextword
>> 16);
2939 as_bad (_("unsupported byte value; use a different suffix"));
2943 if (isvar (&opP
->disp
))
2944 add_fix ('w', &opP
->disp
, 0, 0);
2946 tmpreg
= 0x38;/* 7.0 mode */
2954 as_bad (_("unknown/incorrect operand"));
2958 /* If s[0] is '4', then this is for the mac instructions
2959 that can have a trailing_ampersand set. If so, set 0x100
2960 bit on tmpreg so install_gen_operand can check for it and
2961 set the appropriate bit (word2, bit 5). */
2964 if (opP
->trailing_ampersand
)
2967 install_gen_operand (s
[1], tmpreg
);
2973 { /* JF: I hate floating point! */
2988 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2989 if (isvar (&opP
->disp
))
2990 add_fix (s
[1], &opP
->disp
, 0, 0);
2993 case 'b': /* Danger: These do no check for
2994 certain types of overflow.
2996 if (!isbyte (tmpreg
))
2997 opP
->error
= _("out of range");
2998 insop (tmpreg
, opcode
);
2999 if (isvar (&opP
->disp
))
3000 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
3001 (opcode
->m_codenum
) * 2 + 1;
3004 if (!issbyte (tmpreg
))
3005 opP
->error
= _("out of range");
3006 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
3007 if (isvar (&opP
->disp
))
3008 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
3011 if (!isword (tmpreg
))
3012 opP
->error
= _("out of range");
3013 insop (tmpreg
, opcode
);
3014 if (isvar (&opP
->disp
))
3015 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3018 if (!issword (tmpreg
))
3019 opP
->error
= _("out of range");
3020 insop (tmpreg
, opcode
);
3021 if (isvar (&opP
->disp
))
3022 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3025 /* Because of the way insop works, we put these two out
3027 insop (tmpreg
, opcode
);
3028 insop (tmpreg
>> 16, opcode
);
3029 if (isvar (&opP
->disp
))
3030 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3038 install_operand (s
[1], tmpreg
);
3049 install_operand (s
[1], opP
->reg
- ADDR
);
3053 tmpreg
= get_num (&opP
->disp
, 90);
3058 add_fix ('B', &opP
->disp
, 1, -1);
3061 add_fix ('w', &opP
->disp
, 1, 0);
3066 the_ins
.opcode
[0] |= 0xff;
3067 add_fix ('l', &opP
->disp
, 1, 0);
3071 case 'g': /* Conditional branch */
3072 have_disp
= HAVE_LONG_CALL (current_architecture
);
3075 case 'b': /* Unconditional branch */
3076 have_disp
= HAVE_LONG_BRANCH (current_architecture
);
3077 use_pl
= LONG_BRANCH_VIA_COND (current_architecture
);
3080 case 's': /* Unconditional subroutine */
3081 have_disp
= HAVE_LONG_CALL (current_architecture
);
3084 if (subs (&opP
->disp
) /* We can't relax it. */
3085 /* If the displacement needs pic relocation it cannot be
3087 || opP
->disp
.pic_reloc
!= pic_none
)
3090 as_warn (_("Can't use long branches on this architecture"));
3094 /* This could either be a symbol, or an absolute
3095 address. If it's an absolute address, turn it into
3096 an absolute jump right here and keep it out of the
3098 if (adds (&opP
->disp
) == 0)
3100 if (the_ins
.opcode
[0] == 0x6000) /* jbra */
3101 the_ins
.opcode
[0] = 0x4EF9;
3102 else if (the_ins
.opcode
[0] == 0x6100) /* jbsr */
3103 the_ins
.opcode
[0] = 0x4EB9;
3106 the_ins
.opcode
[0] ^= 0x0100;
3107 the_ins
.opcode
[0] |= 0x0006;
3110 add_fix ('l', &opP
->disp
, 0, 0);
3116 /* Now we know it's going into the relaxer. Now figure
3117 out which mode. We try in this order of preference:
3118 long branch, absolute jump, byte/word branches only. */
3120 add_frag (adds (&opP
->disp
),
3121 SEXT (offs (&opP
->disp
)),
3122 TAB (BRANCHBWL
, SZ_UNDEF
));
3123 else if (! flag_keep_pcrel
)
3125 if ((the_ins
.opcode
[0] == 0x6000)
3126 || (the_ins
.opcode
[0] == 0x6100))
3127 add_frag (adds (&opP
->disp
),
3128 SEXT (offs (&opP
->disp
)),
3129 TAB (BRABSJUNC
, SZ_UNDEF
));
3131 add_frag (adds (&opP
->disp
),
3132 SEXT (offs (&opP
->disp
)),
3133 TAB (BRABSJCOND
, SZ_UNDEF
));
3136 add_frag (adds (&opP
->disp
),
3137 SEXT (offs (&opP
->disp
)),
3138 (use_pl
? TAB (BRANCHBWPL
, SZ_UNDEF
)
3139 : TAB (BRANCHBW
, SZ_UNDEF
)));
3142 if (isvar (&opP
->disp
))
3144 /* Check for DBcc instructions. We can relax them,
3145 but only if we have long branches and/or absolute
3147 if (((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
3148 && (HAVE_LONG_BRANCH (current_architecture
)
3149 || ! flag_keep_pcrel
))
3151 if (HAVE_LONG_BRANCH (current_architecture
))
3152 add_frag (adds (&opP
->disp
),
3153 SEXT (offs (&opP
->disp
)),
3154 TAB (DBCCLBR
, SZ_UNDEF
));
3156 add_frag (adds (&opP
->disp
),
3157 SEXT (offs (&opP
->disp
)),
3158 TAB (DBCCABSJ
, SZ_UNDEF
));
3161 add_fix ('w', &opP
->disp
, 1, 0);
3165 case 'C': /* Fixed size LONG coproc branches. */
3166 add_fix ('l', &opP
->disp
, 1, 0);
3170 case 'c': /* Var size Coprocesssor branches. */
3171 if (subs (&opP
->disp
) || (adds (&opP
->disp
) == 0))
3173 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
3174 add_fix ('l', &opP
->disp
, 1, 0);
3179 add_frag (adds (&opP
->disp
),
3180 SEXT (offs (&opP
->disp
)),
3181 TAB (FBRANCH
, SZ_UNDEF
));
3188 case 'C': /* Ignore it. */
3191 case 'd': /* JF this is a kludge. */
3192 install_operand ('s', opP
->reg
- ADDR
);
3193 tmpreg
= get_num (&opP
->disp
, 90);
3194 if (!issword (tmpreg
))
3196 as_warn (_("Expression out of range, using 0"));
3203 install_operand (s
[1], opP
->reg
- DATA
);
3206 case 'e': /* EMAC ACCx, reg/reg. */
3207 install_operand (s
[1], opP
->reg
- ACC
);
3210 case 'E': /* Ignore it. */
3214 install_operand (s
[1], opP
->reg
- FP0
);
3217 case 'g': /* EMAC ACCEXTx. */
3218 install_operand (s
[1], opP
->reg
- ACCEXT01
);
3221 case 'G': /* Ignore it. */
3226 tmpreg
= opP
->reg
- COP0
;
3227 install_operand (s
[1], tmpreg
);
3230 case 'i': /* MAC/EMAC scale factor. */
3231 install_operand (s
[1], opP
->mode
== LSH
? 0x1 : 0x3);
3234 case 'J': /* JF foo. */
3277 tmpreg
= 0x00c + (opP
->reg
- ACR4
);
3384 install_operand (s
[1], tmpreg
);
3388 tmpreg
= get_num (&opP
->disp
, 55);
3389 install_operand (s
[1], tmpreg
& 0x7f);
3396 if (tmpreg
& 0x7FF0000)
3397 as_bad (_("Floating point register in register list"));
3398 insop (reverse_16_bits (tmpreg
), opcode
);
3402 if (tmpreg
& 0x700FFFF)
3403 as_bad (_("Wrong register in floating-point reglist"));
3404 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
3412 if (tmpreg
& 0x7FF0000)
3413 as_bad (_("Floating point register in register list"));
3414 insop (tmpreg
, opcode
);
3416 else if (s
[1] == '8')
3418 if (tmpreg
& 0x0FFFFFF)
3419 as_bad (_("incorrect register in reglist"));
3420 install_operand (s
[1], tmpreg
>> 24);
3424 if (tmpreg
& 0x700FFFF)
3425 as_bad (_("wrong register in floating-point reglist"));
3427 install_operand (s
[1], tmpreg
>> 16);
3432 install_operand (s
[1], get_num (&opP
->disp
, 60));
3436 tmpreg
= ((opP
->mode
== DREG
)
3437 ? 0x20 + (int) (opP
->reg
- DATA
)
3438 : (get_num (&opP
->disp
, 40) & 0x1F));
3439 install_operand (s
[1], tmpreg
);
3443 tmpreg
= get_num (&opP
->disp
, 10);
3446 install_operand (s
[1], tmpreg
);
3450 /* This depends on the fact that ADDR registers are eight
3451 more than their corresponding DATA regs, so the result
3452 will have the ADDR_REG bit set. */
3453 install_operand (s
[1], opP
->reg
- DATA
);
3457 if (opP
->mode
== AINDR
)
3458 install_operand (s
[1], opP
->reg
- DATA
);
3460 install_operand (s
[1], opP
->index
.reg
- DATA
);
3464 if (opP
->reg
== FPI
)
3466 else if (opP
->reg
== FPS
)
3468 else if (opP
->reg
== FPC
)
3472 install_operand (s
[1], tmpreg
);
3475 case 'S': /* Ignore it. */
3479 install_operand (s
[1], get_num (&opP
->disp
, 30));
3482 case 'U': /* Ignore it. */
3501 as_fatal (_("failed sanity check"));
3502 } /* switch on cache token. */
3503 install_operand (s
[1], tmpreg
);
3506 /* JF: These are out of order, I fear. */
3519 install_operand (s
[1], tmpreg
);
3545 install_operand (s
[1], tmpreg
);
3549 if (opP
->reg
== VAL
)
3568 install_operand (s
[1], tmpreg
);
3582 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3593 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3599 install_operand (s
[1], tmpreg
);
3602 know (opP
->reg
== PSR
);
3605 know (opP
->reg
== PCSR
);
3620 install_operand (s
[1], tmpreg
);
3623 tmpreg
= get_num (&opP
->disp
, 20);
3624 install_operand (s
[1], tmpreg
);
3626 case '_': /* used only for move16 absolute 32-bit address. */
3627 if (isvar (&opP
->disp
))
3628 add_fix ('l', &opP
->disp
, 0, 0);
3629 tmpreg
= get_num (&opP
->disp
, 90);
3630 addword (tmpreg
>> 16);
3631 addword (tmpreg
& 0xFFFF);
3634 install_operand (s
[1], opP
->reg
- DATA0L
);
3635 opP
->reg
-= (DATA0L
);
3636 opP
->reg
&= 0x0F; /* remove upper/lower bit. */
3639 tmpreg
= get_num (&opP
->disp
, 80);
3642 install_operand (s
[1], tmpreg
);
3645 tmpreg
= get_num (&opP
->disp
, 10);
3646 install_operand (s
[1], tmpreg
- 1);
3649 tmpreg
= get_num (&opP
->disp
, 65);
3650 install_operand (s
[1], tmpreg
);
3657 /* By the time when get here (FINALLY) the_ins contains the complete
3658 instruction, ready to be emitted. . . */
3662 reverse_16_bits (int in
)
3667 static int mask
[16] =
3669 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3670 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3672 for (n
= 0; n
< 16; n
++)
3675 out
|= mask
[15 - n
];
3678 } /* reverse_16_bits() */
3681 reverse_8_bits (int in
)
3686 static int mask
[8] =
3688 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3691 for (n
= 0; n
< 8; n
++)
3697 } /* reverse_8_bits() */
3699 /* Cause an extra frag to be generated here, inserting up to
3700 FRAG_VAR_SIZE bytes. TYPE is the subtype of the frag to be
3701 generated; its primary type is rs_machine_dependent.
3703 The TYPE parameter is also used by md_convert_frag_1 and
3704 md_estimate_size_before_relax. The appropriate type of fixup will
3705 be emitted by md_convert_frag_1.
3707 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3709 install_operand (int mode
, int val
)
3714 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge. */
3717 the_ins
.opcode
[0] |= val
<< 9;
3720 the_ins
.opcode
[1] |= val
<< 9;
3723 the_ins
.opcode
[1] |= val
<< 12;
3726 the_ins
.opcode
[1] |= val
<< 6;
3729 the_ins
.opcode
[1] |= val
;
3732 the_ins
.opcode
[2] |= val
<< 12;
3735 the_ins
.opcode
[2] |= val
<< 6;
3738 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3739 three words long! */
3741 the_ins
.opcode
[2] |= val
;
3744 the_ins
.opcode
[1] |= val
<< 7;
3747 the_ins
.opcode
[1] |= val
<< 10;
3751 the_ins
.opcode
[1] |= val
<< 5;
3756 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3759 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3762 the_ins
.opcode
[0] |= val
= 0xff;
3765 the_ins
.opcode
[0] |= val
<< 9;
3768 the_ins
.opcode
[1] |= val
;
3771 the_ins
.opcode
[1] |= val
;
3772 the_ins
.numo
++; /* What a hack. */
3775 the_ins
.opcode
[1] |= val
<< 4;
3783 the_ins
.opcode
[0] |= (val
<< 6);
3786 the_ins
.opcode
[1] = (val
>> 16);
3787 the_ins
.opcode
[2] = val
& 0xffff;
3790 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3791 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3792 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3794 case 'n': /* MAC/EMAC Rx on !load. */
3795 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3796 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3797 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3799 case 'o': /* MAC/EMAC Rx on load. */
3800 the_ins
.opcode
[1] |= val
<< 12;
3801 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3803 case 'M': /* MAC/EMAC Ry on !load. */
3804 the_ins
.opcode
[0] |= (val
& 0xF);
3805 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3807 case 'N': /* MAC/EMAC Ry on load. */
3808 the_ins
.opcode
[1] |= (val
& 0xF);
3809 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3812 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3815 the_ins
.opcode
[0] |= ((val
& 0x3) << 9);
3818 the_ins
.opcode
[0] |= ((val
& 0x3) << 0);
3820 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3821 the_ins
.opcode
[0] |= ((~val
& 0x1) << 7);
3822 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3824 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3825 the_ins
.opcode
[0] |= ((val
& 0x1) << 7);
3826 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3829 the_ins
.opcode
[1] |= ((val
& 0x3) << 9);
3832 the_ins
.opcode
[0] |= (val
& 0x1) <<10;
3836 as_fatal (_("failed sanity check."));
3841 install_gen_operand (int mode
, int val
)
3845 case '/': /* Special for mask loads for mac/msac insns with
3846 possible mask; trailing_ampersand set in bit 8. */
3847 the_ins
.opcode
[0] |= (val
& 0x3f);
3848 the_ins
.opcode
[1] |= (((val
& 0x100) >> 8) << 5);
3851 the_ins
.opcode
[0] |= val
;
3854 /* This is a kludge!!! */
3855 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3864 the_ins
.opcode
[0] |= val
;
3866 /* more stuff goes here. */
3868 as_fatal (_("failed sanity check."));
3872 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3873 then deal with the bitfield hack. */
3876 crack_operand (char *str
, struct m68k_op
*opP
)
3888 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3894 else if (*str
== ')')
3898 opP
->error
= _("Extra )");
3904 if (flag_mri
&& *str
== '\'')
3905 inquote
= ! inquote
;
3907 if (!*str
&& parens
)
3909 opP
->error
= _("Missing )");
3914 if (m68k_ip_op (beg_str
, opP
) != 0)
3921 c
= *++str
; /* JF bitfield hack. */
3926 as_bad (_("Missing operand"));
3929 /* Detect MRI REG symbols and convert them to REGLSTs. */
3930 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3933 opP
->mask
= ~(int)opP
->reg
;
3940 /* This is the guts of the machine-dependent assembler. STR points to a
3941 machine dependent instruction. This function is supposed to emit
3942 the frags/bytes it assembles to.
3946 insert_reg (const char *regname
, int regnum
)
3951 #ifdef REGISTER_PREFIX
3952 if (!flag_reg_prefix_optional
)
3954 buf
[0] = REGISTER_PREFIX
;
3955 strcpy (buf
+ 1, regname
);
3960 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3961 &zero_address_frag
));
3963 for (i
= 0; regname
[i
]; i
++)
3964 buf
[i
] = TOUPPER (regname
[i
]);
3967 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3968 &zero_address_frag
));
3977 static const struct init_entry init_table
[] =
4037 { "accext01", ACCEXT01
},
4038 { "accext23", ACCEXT23
},
4042 /* Control registers. */
4043 { "sfc", SFC
}, /* Source Function Code. */
4045 { "dfc", DFC
}, /* Destination Function Code. */
4047 { "cacr", CACR
}, /* Cache Control Register. */
4048 { "caar", CAAR
}, /* Cache Address Register. */
4049 { "cpucr", CPUCR
}, /* CPU Control Register. */
4051 { "usp", USP
}, /* User Stack Pointer. */
4052 { "vbr", VBR
}, /* Vector Base Register. */
4053 { "msp", MSP
}, /* Master Stack Pointer. */
4054 { "isp", ISP
}, /* Interrupt Stack Pointer. */
4056 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0. */
4057 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1. */
4058 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0. */
4059 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1. */
4061 /* 68ec040 versions of same */
4062 { "iacr0", ITT0
}, /* Instruction Access Control Register 0. */
4063 { "iacr1", ITT1
}, /* Instruction Access Control Register 0. */
4064 { "dacr0", DTT0
}, /* Data Access Control Register 0. */
4065 { "dacr1", DTT1
}, /* Data Access Control Register 0. */
4067 /* Coldfire versions of same. The ColdFire programmer's reference
4068 manual indicated that the order is 2,3,0,1, but Ken Rose
4069 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
4070 { "acr0", ACR0
}, /* Access Control Unit 0. */
4071 { "acr1", ACR1
}, /* Access Control Unit 1. */
4072 { "acr2", ACR2
}, /* Access Control Unit 2. */
4073 { "acr3", ACR3
}, /* Access Control Unit 3. */
4074 { "acr4", ACR4
}, /* Access Control Unit 4. */
4075 { "acr5", ACR5
}, /* Access Control Unit 5. */
4076 { "acr6", ACR6
}, /* Access Control Unit 6. */
4077 { "acr7", ACR7
}, /* Access Control Unit 7. */
4079 { "tc", TC
}, /* MMU Translation Control Register. */
4083 { "mmusr", MMUSR
}, /* MMU Status Register. */
4084 { "srp", SRP
}, /* User Root Pointer. */
4085 { "urp", URP
}, /* Supervisor Root Pointer. */
4088 { "mmubar", MMUBAR
},
4091 { "rombar", ROMBAR
}, /* ROM Base Address Register. */
4092 { "rambar0", RAMBAR0
}, /* ROM Base Address Register. */
4093 { "rambar1", RAMBAR1
}, /* ROM Base Address Register. */
4094 { "mbar", MBAR
}, /* Module Base Address Register. */
4096 { "mbar0", MBAR0
}, /* mcfv4e registers. */
4097 { "mbar1", MBAR1
}, /* mcfv4e registers. */
4098 { "rombar0", ROMBAR0
}, /* mcfv4e registers. */
4099 { "rombar1", ROMBAR1
}, /* mcfv4e registers. */
4100 { "mpcr", MPCR
}, /* mcfv4e registers. */
4101 { "edrambar", EDRAMBAR
}, /* mcfv4e registers. */
4102 { "secmbar", SECMBAR
}, /* mcfv4e registers. */
4103 { "asid", TC
}, /* mcfv4e registers. */
4104 { "mmubar", BUSCR
}, /* mcfv4e registers. */
4105 { "pcr1u0", PCR1U0
}, /* mcfv4e registers. */
4106 { "pcr1l0", PCR1L0
}, /* mcfv4e registers. */
4107 { "pcr2u0", PCR2U0
}, /* mcfv4e registers. */
4108 { "pcr2l0", PCR2L0
}, /* mcfv4e registers. */
4109 { "pcr3u0", PCR3U0
}, /* mcfv4e registers. */
4110 { "pcr3l0", PCR3L0
}, /* mcfv4e registers. */
4111 { "pcr1u1", PCR1U1
}, /* mcfv4e registers. */
4112 { "pcr1l1", PCR1L1
}, /* mcfv4e registers. */
4113 { "pcr2u1", PCR2U1
}, /* mcfv4e registers. */
4114 { "pcr2l1", PCR2L1
}, /* mcfv4e registers. */
4115 { "pcr3u1", PCR3U1
}, /* mcfv4e registers. */
4116 { "pcr3l1", PCR3L1
}, /* mcfv4e registers. */
4118 { "flashbar", FLASHBAR
}, /* mcf528x registers. */
4119 { "rambar", RAMBAR
}, /* mcf528x registers. */
4121 { "mbar2", MBAR2
}, /* mcf5249 registers. */
4123 { "rgpiobar", RGPIOBAR
}, /* mcf54418 registers. */
4125 { "cac", CAC
}, /* fido registers. */
4126 { "mbb", MBO
}, /* fido registers (obsolete). */
4127 { "mbo", MBO
}, /* fido registers. */
4128 /* End of control registers. */
4162 /* 68ec030 versions of same. */
4165 /* 68ec030 access control unit, identical to 030 MMU status reg. */
4168 /* Suppressed data and address registers. */
4186 /* Upper and lower data and address registers, used by macw and msacw. */
4227 init_regtable (void)
4230 for (i
= 0; init_table
[i
].name
; i
++)
4231 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
4235 md_assemble (char *str
)
4242 int shorts_this_frag
;
4245 if (!selected_cpu
&& !selected_arch
)
4247 /* We've not selected an architecture yet. Set the default
4248 now. We do this lazily so that an initial .cpu or .arch directive
4250 if (!m68k_set_cpu (TARGET_CPU
, 1, 1))
4251 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU
);
4256 /* In MRI mode, the instruction and operands are separated by a
4257 space. Anything following the operands is a comment. The label
4258 has already been removed. */
4266 for (s
= str
; *s
!= '\0'; s
++)
4268 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
4286 inquote
= ! inquote
;
4291 memset (&the_ins
, '\0', sizeof (the_ins
));
4296 for (n
= 0; n
< the_ins
.numargs
; n
++)
4297 if (the_ins
.operands
[n
].error
)
4299 er
= the_ins
.operands
[n
].error
;
4305 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
4309 /* If there is a current label, record that it marks an instruction. */
4310 if (current_label
!= NULL
)
4312 current_label
->text
= 1;
4313 current_label
= NULL
;
4316 /* Tie dwarf2 debug info to the address at the start of the insn. */
4317 dwarf2_emit_insn (0);
4319 if (the_ins
.nfrag
== 0)
4321 /* No frag hacking involved; just put it out. */
4322 toP
= frag_more (2 * the_ins
.numo
);
4323 fromP
= &the_ins
.opcode
[0];
4324 for (m
= the_ins
.numo
; m
; --m
)
4326 md_number_to_chars (toP
, (long) (*fromP
), 2);
4330 /* Put out symbol-dependent info. */
4331 for (m
= 0; m
< the_ins
.nrel
; m
++)
4333 switch (the_ins
.reloc
[m
].wid
)
4352 as_fatal (_("Don't know how to figure out width of %c in md_assemble()"),
4353 the_ins
.reloc
[m
].wid
);
4356 fixP
= fix_new_exp (frag_now
,
4357 ((toP
- frag_now
->fr_literal
)
4358 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4360 &the_ins
.reloc
[m
].exp
,
4361 the_ins
.reloc
[m
].pcrel
,
4362 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
4363 the_ins
.reloc
[m
].pic_reloc
));
4364 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4365 if (the_ins
.reloc
[m
].wid
== 'B')
4366 fixP
->fx_signed
= 1;
4371 /* There's some frag hacking. */
4373 /* Calculate the max frag size. */
4376 wid
= 2 * the_ins
.fragb
[0].fragoff
;
4377 for (n
= 1; n
< the_ins
.nfrag
; n
++)
4378 wid
+= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4379 /* frag_var part. */
4380 wid
+= FRAG_VAR_SIZE
;
4381 /* Make sure the whole insn fits in one chunk, in particular that
4382 the var part is attached, as we access one byte before the
4383 variable frag for byte branches. */
4387 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
4392 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
4394 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4395 toP
= frag_more (wid
);
4397 shorts_this_frag
= 0;
4398 for (m
= wid
/ 2; m
; --m
)
4400 md_number_to_chars (toP
, (long) (*fromP
), 2);
4405 for (m
= 0; m
< the_ins
.nrel
; m
++)
4407 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
4409 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
4412 wid
= the_ins
.reloc
[m
].wid
;
4415 the_ins
.reloc
[m
].wid
= 0;
4416 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4418 fixP
= fix_new_exp (frag_now
,
4419 ((toP
- frag_now
->fr_literal
)
4420 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4422 &the_ins
.reloc
[m
].exp
,
4423 the_ins
.reloc
[m
].pcrel
,
4424 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4425 the_ins
.reloc
[m
].pic_reloc
));
4426 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4428 (void) frag_var (rs_machine_dependent
, FRAG_VAR_SIZE
, 0,
4429 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
4430 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
4432 gas_assert (the_ins
.nfrag
>= 1);
4433 n
= the_ins
.numo
- the_ins
.fragb
[the_ins
.nfrag
- 1].fragoff
;
4434 shorts_this_frag
= 0;
4437 toP
= frag_more (n
* 2);
4440 md_number_to_chars (toP
, (long) (*fromP
), 2);
4446 for (m
= 0; m
< the_ins
.nrel
; m
++)
4450 wid
= the_ins
.reloc
[m
].wid
;
4453 the_ins
.reloc
[m
].wid
= 0;
4454 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4456 fixP
= fix_new_exp (frag_now
,
4457 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
4458 - shorts_this_frag
* 2),
4460 &the_ins
.reloc
[m
].exp
,
4461 the_ins
.reloc
[m
].pcrel
,
4462 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4463 the_ins
.reloc
[m
].pic_reloc
));
4464 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4468 /* Comparison function used by qsort to rank the opcode entries by name. */
4471 m68k_compare_opcode (const void * v1
, const void * v2
)
4473 struct m68k_opcode
* op1
, * op2
;
4479 op1
= *(struct m68k_opcode
**) v1
;
4480 op2
= *(struct m68k_opcode
**) v2
;
4482 /* Compare the two names. If different, return the comparison.
4483 If the same, return the order they are in the opcode table. */
4484 ret
= strcmp (op1
->name
, op2
->name
);
4495 const struct m68k_opcode
*ins
;
4496 struct m68k_incant
*hack
, *slak
;
4497 const char *retval
= 0; /* Empty string, or error msg text. */
4500 /* Set up hash tables with 68000 instructions.
4501 similar to what the vax assembler does. */
4502 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4503 a copy of it at runtime, adding in the information we want but isn't
4504 there. I think it'd be better to have an awk script hack the table
4505 at compile time. Or even just xstr the table and use it as-is. But
4506 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4511 flag_reg_prefix_optional
= 1;
4513 if (! m68k_rel32_from_cmdline
)
4517 /* First sort the opcode table into alphabetical order to separate
4518 the order that the assembler wants to see the opcodes from the
4519 order that the disassembler wants to see them. */
4520 m68k_sorted_opcodes
= XNEWVEC (const struct m68k_opcode
*, m68k_numopcodes
);
4522 for (i
= m68k_numopcodes
; i
--;)
4523 m68k_sorted_opcodes
[i
] = m68k_opcodes
+ i
;
4525 qsort (m68k_sorted_opcodes
, m68k_numopcodes
,
4526 sizeof (m68k_sorted_opcodes
[0]), m68k_compare_opcode
);
4528 op_hash
= hash_new ();
4530 obstack_begin (&robyn
, 4000);
4531 for (i
= 0; i
< m68k_numopcodes
; i
++)
4533 hack
= slak
= XOBNEW (&robyn
, struct m68k_incant
);
4536 ins
= m68k_sorted_opcodes
[i
];
4538 /* We must enter all insns into the table, because .arch and
4539 .cpu directives can change things. */
4540 slak
->m_operands
= ins
->args
;
4541 slak
->m_arch
= ins
->arch
;
4542 slak
->m_opcode
= ins
->opcode
;
4544 /* In most cases we can determine the number of opcode words
4545 by checking the second word of the mask. Unfortunately
4546 some instructions have 2 opcode words, but no fixed bits
4547 in the second word. A leading dot in the operands
4548 string also indicates 2 opcodes. */
4549 if (*slak
->m_operands
== '.')
4552 slak
->m_codenum
= 2;
4554 else if (ins
->match
& 0xffffL
)
4555 slak
->m_codenum
= 2;
4557 slak
->m_codenum
= 1;
4558 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
4560 if (i
+ 1 != m68k_numopcodes
4561 && !strcmp (ins
->name
, m68k_sorted_opcodes
[i
+ 1]->name
))
4563 slak
->m_next
= XOBNEW (&robyn
, struct m68k_incant
);
4568 slak
= slak
->m_next
;
4572 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
4574 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
4577 for (i
= 0; i
< m68k_numaliases
; i
++)
4579 const char *name
= m68k_opcode_aliases
[i
].primary
;
4580 const char *alias
= m68k_opcode_aliases
[i
].alias
;
4581 void *val
= hash_find (op_hash
, name
);
4584 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4585 retval
= hash_insert (op_hash
, alias
, val
);
4587 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4590 /* In MRI mode, all unsized branches are variable sized. Normally,
4591 they are word sized. */
4594 static struct m68k_opcode_alias mri_aliases
[] =
4615 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
4618 const char *name
= mri_aliases
[i
].primary
;
4619 const char *alias
= mri_aliases
[i
].alias
;
4620 void *val
= hash_find (op_hash
, name
);
4623 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4624 retval
= hash_jam (op_hash
, alias
, val
);
4626 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4630 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
4632 notend_table
[i
] = 0;
4633 alt_notend_table
[i
] = 0;
4636 notend_table
[','] = 1;
4637 notend_table
['{'] = 1;
4638 notend_table
['}'] = 1;
4639 alt_notend_table
['a'] = 1;
4640 alt_notend_table
['A'] = 1;
4641 alt_notend_table
['d'] = 1;
4642 alt_notend_table
['D'] = 1;
4643 alt_notend_table
['#'] = 1;
4644 alt_notend_table
['&'] = 1;
4645 alt_notend_table
['f'] = 1;
4646 alt_notend_table
['F'] = 1;
4647 #ifdef REGISTER_PREFIX
4648 alt_notend_table
[REGISTER_PREFIX
] = 1;
4651 /* We need to put '(' in alt_notend_table to handle
4652 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4653 alt_notend_table
['('] = 1;
4655 /* We need to put '@' in alt_notend_table to handle
4656 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4657 alt_notend_table
['@'] = 1;
4659 /* We need to put digits in alt_notend_table to handle
4660 bfextu %d0{24:1},%d0 */
4661 alt_notend_table
['0'] = 1;
4662 alt_notend_table
['1'] = 1;
4663 alt_notend_table
['2'] = 1;
4664 alt_notend_table
['3'] = 1;
4665 alt_notend_table
['4'] = 1;
4666 alt_notend_table
['5'] = 1;
4667 alt_notend_table
['6'] = 1;
4668 alt_notend_table
['7'] = 1;
4669 alt_notend_table
['8'] = 1;
4670 alt_notend_table
['9'] = 1;
4672 #ifndef MIT_SYNTAX_ONLY
4673 /* Insert pseudo ops, these have to go into the opcode table since
4674 gas expects pseudo ops to start with a dot. */
4678 while (mote_pseudo_table
[n
].poc_name
)
4680 hack
= XOBNEW (&robyn
, struct m68k_incant
);
4681 hash_insert (op_hash
,
4682 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
4683 hack
->m_operands
= 0;
4692 record_alignment (text_section
, 2);
4693 record_alignment (data_section
, 2);
4694 record_alignment (bss_section
, 2);
4698 /* This is called when a label is defined. */
4701 m68k_frob_label (symbolS
*sym
)
4703 struct label_line
*n
;
4705 n
= XNEW (struct label_line
);
4708 n
->file
= as_where (&n
->line
);
4713 dwarf2_emit_label (sym
);
4716 /* This is called when a value that is not an instruction is emitted. */
4719 m68k_flush_pending_output (void)
4721 current_label
= NULL
;
4724 /* This is called at the end of the assembly, when the final value of
4725 the label is known. We warn if this is a text symbol aligned at an
4729 m68k_frob_symbol (symbolS
*sym
)
4731 if (S_GET_SEGMENT (sym
) == reg_section
4732 && (int) S_GET_VALUE (sym
) < 0)
4734 S_SET_SEGMENT (sym
, absolute_section
);
4735 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4737 else if ((S_GET_VALUE (sym
) & 1) != 0)
4739 struct label_line
*l
;
4741 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4743 if (l
->label
== sym
)
4746 as_warn_where (l
->file
, l
->line
,
4747 _("text label `%s' aligned to odd boundary"),
4755 /* This is called if we go in or out of MRI mode because of the .mri
4759 m68k_mri_mode_change (int on
)
4763 if (! flag_reg_prefix_optional
)
4765 flag_reg_prefix_optional
= 1;
4766 #ifdef REGISTER_PREFIX
4771 if (! m68k_rel32_from_cmdline
)
4776 if (! reg_prefix_optional_seen
)
4778 #ifdef REGISTER_PREFIX_OPTIONAL
4779 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4781 flag_reg_prefix_optional
= 0;
4783 #ifdef REGISTER_PREFIX
4788 if (! m68k_rel32_from_cmdline
)
4794 md_atof (int type
, char *litP
, int *sizeP
)
4796 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
4800 md_number_to_chars (char *buf
, valueT val
, int n
)
4802 number_to_chars_bigendian (buf
, val
, n
);
4806 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
4808 offsetT val
= *valP
;
4809 addressT upper_limit
;
4810 offsetT lower_limit
;
4812 /* This is unnecessary but it convinces the native rs6000 compiler
4813 to generate the code we want. */
4814 char *buf
= fixP
->fx_frag
->fr_literal
;
4815 buf
+= fixP
->fx_where
;
4816 /* End ibm compiler workaround. */
4820 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4825 memset (buf
, 0, fixP
->fx_size
);
4826 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4828 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4829 && !S_IS_DEFINED (fixP
->fx_addsy
)
4830 && !S_IS_WEAK (fixP
->fx_addsy
))
4831 S_SET_WEAK (fixP
->fx_addsy
);
4833 switch (fixP
->fx_r_type
)
4835 case BFD_RELOC_68K_TLS_GD32
:
4836 case BFD_RELOC_68K_TLS_GD16
:
4837 case BFD_RELOC_68K_TLS_GD8
:
4838 case BFD_RELOC_68K_TLS_LDM32
:
4839 case BFD_RELOC_68K_TLS_LDM16
:
4840 case BFD_RELOC_68K_TLS_LDM8
:
4841 case BFD_RELOC_68K_TLS_LDO32
:
4842 case BFD_RELOC_68K_TLS_LDO16
:
4843 case BFD_RELOC_68K_TLS_LDO8
:
4844 case BFD_RELOC_68K_TLS_IE32
:
4845 case BFD_RELOC_68K_TLS_IE16
:
4846 case BFD_RELOC_68K_TLS_IE8
:
4847 case BFD_RELOC_68K_TLS_LE32
:
4848 case BFD_RELOC_68K_TLS_LE16
:
4849 case BFD_RELOC_68K_TLS_LE8
:
4850 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
4860 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4861 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4864 switch (fixP
->fx_size
)
4866 /* The cast to offsetT below are necessary to make code
4867 correct for machines where ints are smaller than offsetT. */
4871 lower_limit
= - (offsetT
) 0x80;
4874 *buf
++ = (val
>> 8);
4876 upper_limit
= 0x7fff;
4877 lower_limit
= - (offsetT
) 0x8000;
4880 *buf
++ = (val
>> 24);
4881 *buf
++ = (val
>> 16);
4882 *buf
++ = (val
>> 8);
4884 upper_limit
= 0x7fffffff;
4885 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* Avoid constant overflow. */
4888 BAD_CASE (fixP
->fx_size
);
4891 /* Fix up a negative reloc. */
4892 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4894 fixP
->fx_addsy
= fixP
->fx_subsy
;
4895 fixP
->fx_subsy
= NULL
;
4899 /* For non-pc-relative values, it's conceivable we might get something
4900 like "0xff" for a byte field. So extend the upper part of the range
4901 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4902 so that we can do any range checking at all. */
4903 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4904 upper_limit
= upper_limit
* 2 + 1;
4906 if ((addressT
) val
> upper_limit
4907 && (val
> 0 || val
< lower_limit
))
4908 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4909 _("value %ld out of range"), (long)val
);
4911 /* A one byte PC-relative reloc means a short branch. We can't use
4912 a short branch with a value of 0 or -1, because those indicate
4913 different opcodes (branches with longer offsets). fixup_segment
4914 in write.c may have clobbered fx_pcrel, so we need to examine the
4917 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
4918 && fixP
->fx_size
== 1
4919 && (fixP
->fx_addsy
== NULL
4920 || S_IS_DEFINED (fixP
->fx_addsy
))
4921 && (val
== 0 || val
== -1))
4922 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4923 _("invalid byte branch offset"));
4926 /* *fragP has been relaxed to its final size, and now needs to have
4927 the bytes inside it modified to conform to the new size There is UGLY
4931 md_convert_frag_1 (fragS
*fragP
)
4936 /* Address in object code of the displacement. */
4937 int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4939 /* Address in gas core of the place to store the displacement. */
4940 /* This convinces the native rs6000 compiler to generate the code we
4942 char *buffer_address
= fragP
->fr_literal
;
4943 buffer_address
+= fragP
->fr_fix
;
4944 /* End ibm compiler workaround. */
4946 /* The displacement of the address, from current location. */
4947 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4948 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4950 switch (fragP
->fr_subtype
)
4952 case TAB (BRANCHBWL
, BYTE
):
4953 case TAB (BRABSJUNC
, BYTE
):
4954 case TAB (BRABSJCOND
, BYTE
):
4955 case TAB (BRANCHBW
, BYTE
):
4956 case TAB (BRANCHBWPL
, BYTE
):
4957 know (issbyte (disp
));
4959 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
4960 _("short branch with zero offset: use :w"));
4961 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4962 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4963 fixP
->fx_pcrel_adjust
= -1;
4965 case TAB (BRANCHBWL
, SHORT
):
4966 case TAB (BRABSJUNC
, SHORT
):
4967 case TAB (BRABSJCOND
, SHORT
):
4968 case TAB (BRANCHBW
, SHORT
):
4969 case TAB (BRANCHBWPL
, SHORT
):
4970 fragP
->fr_opcode
[1] = 0x00;
4971 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4972 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4975 case TAB (BRANCHBWL
, LONG
):
4976 fragP
->fr_opcode
[1] = (char) 0xFF;
4977 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4978 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4981 case TAB (BRANCHBWPL
, LONG
):
4982 /* Here we are converting an unconditional branch into a pair of
4983 conditional branches, in order to get the range. */
4984 fragP
->fr_opcode
[0] = 0x66; /* bne */
4985 fragP
->fr_opcode
[1] = 0xFF;
4986 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4987 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4988 fixP
->fx_file
= fragP
->fr_file
;
4989 fixP
->fx_line
= fragP
->fr_line
;
4990 fragP
->fr_fix
+= 4; /* Skip first offset */
4991 buffer_address
+= 4;
4992 *buffer_address
++ = 0x67; /* beq */
4993 *buffer_address
++ = 0xff;
4994 fragP
->fr_fix
+= 2; /* Skip second branch opcode */
4995 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4996 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4999 case TAB (BRABSJUNC
, LONG
):
5000 if (fragP
->fr_opcode
[0] == 0x61) /* jbsr */
5002 if (flag_keep_pcrel
)
5003 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5004 _("Conversion of PC relative BSR to absolute JSR"));
5005 fragP
->fr_opcode
[0] = 0x4E;
5006 fragP
->fr_opcode
[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
5007 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5008 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5011 else if (fragP
->fr_opcode
[0] == 0x60) /* jbra */
5013 if (flag_keep_pcrel
)
5014 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5015 _("Conversion of PC relative branch to absolute jump"));
5016 fragP
->fr_opcode
[0] = 0x4E;
5017 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
5018 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5019 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5024 /* This cannot happen, because jbsr and jbra are the only two
5025 unconditional branches. */
5029 case TAB (BRABSJCOND
, LONG
):
5030 if (flag_keep_pcrel
)
5031 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5032 _("Conversion of PC relative conditional branch to absolute jump"));
5034 /* Only Bcc 68000 instructions can come here
5035 Change bcc into b!cc/jmp absl long. */
5036 fragP
->fr_opcode
[0] ^= 0x01; /* Invert bcc. */
5037 fragP
->fr_opcode
[1] = 0x06; /* Branch offset = 6. */
5039 /* JF: these used to be fr_opcode[2,3], but they may be in a
5040 different frag, in which case referring to them is a no-no.
5041 Only fr_opcode[0,1] are guaranteed to work. */
5042 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
5043 *buffer_address
++ = (char) 0xf9;
5044 fragP
->fr_fix
+= 2; /* Account for jmp instruction. */
5045 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5046 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5049 case TAB (FBRANCH
, SHORT
):
5050 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
5051 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5052 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5055 case TAB (FBRANCH
, LONG
):
5056 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit. */
5057 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5058 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5061 case TAB (DBCCLBR
, SHORT
):
5062 case TAB (DBCCABSJ
, SHORT
):
5063 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5064 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5067 case TAB (DBCCLBR
, LONG
):
5068 /* Only DBcc instructions can come here.
5069 Change dbcc into dbcc/bral.
5070 JF: these used to be fr_opcode[2-7], but that's wrong. */
5071 *buffer_address
++ = 0x00; /* Branch offset = 4. */
5072 *buffer_address
++ = 0x04;
5073 *buffer_address
++ = 0x60; /* Put in bra pc+6. */
5074 *buffer_address
++ = 0x06;
5075 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
5076 *buffer_address
++ = (char) 0xff;
5078 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
5079 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5080 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5083 case TAB (DBCCABSJ
, LONG
):
5084 /* Only DBcc instructions can come here.
5085 Change dbcc into dbcc/jmp.
5086 JF: these used to be fr_opcode[2-7], but that's wrong. */
5087 if (flag_keep_pcrel
)
5088 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5089 _("Conversion of PC relative conditional branch to absolute jump"));
5091 *buffer_address
++ = 0x00; /* Branch offset = 4. */
5092 *buffer_address
++ = 0x04;
5093 *buffer_address
++ = 0x60; /* Put in bra pc + 6. */
5094 *buffer_address
++ = 0x06;
5095 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
5096 *buffer_address
++ = (char) 0xf9;
5098 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
5099 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5100 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5103 case TAB (PCREL1632
, SHORT
):
5104 fragP
->fr_opcode
[1] &= ~0x3F;
5105 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
5106 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
5107 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5110 case TAB (PCREL1632
, LONG
):
5111 /* Already set to mode 7.3; this indicates: PC indirect with
5112 suppressed index, 32-bit displacement. */
5113 *buffer_address
++ = 0x01;
5114 *buffer_address
++ = 0x70;
5116 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
5117 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5118 fixP
->fx_pcrel_adjust
= 2;
5121 case TAB (PCINDEX
, BYTE
):
5122 gas_assert (fragP
->fr_fix
>= 2);
5123 buffer_address
[-2] &= ~1;
5124 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
5125 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
5126 fixP
->fx_pcrel_adjust
= 1;
5128 case TAB (PCINDEX
, SHORT
):
5129 gas_assert (fragP
->fr_fix
>= 2);
5130 buffer_address
[-2] |= 0x1;
5131 buffer_address
[-1] = 0x20;
5132 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
5133 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5134 fixP
->fx_pcrel_adjust
= 2;
5137 case TAB (PCINDEX
, LONG
):
5138 gas_assert (fragP
->fr_fix
>= 2);
5139 buffer_address
[-2] |= 0x1;
5140 buffer_address
[-1] = 0x30;
5141 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
5142 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5143 fixP
->fx_pcrel_adjust
= 2;
5146 case TAB (ABSTOPCREL
, SHORT
):
5147 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5148 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5151 case TAB (ABSTOPCREL
, LONG
):
5152 if (flag_keep_pcrel
)
5153 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5154 _("Conversion of PC relative displacement to absolute"));
5155 /* The thing to do here is force it to ABSOLUTE LONG, since
5156 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
5157 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
5159 fragP
->fr_opcode
[1] &= ~0x3F;
5160 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
5161 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5162 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5168 fixP
->fx_file
= fragP
->fr_file
;
5169 fixP
->fx_line
= fragP
->fr_line
;
5174 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5175 segT sec ATTRIBUTE_UNUSED
,
5178 md_convert_frag_1 (fragP
);
5181 /* Force truly undefined symbols to their maximum size, and generally set up
5182 the frag list to be relaxed
5185 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
5187 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
5188 switch (fragP
->fr_subtype
)
5190 case TAB (BRANCHBWL
, SZ_UNDEF
):
5191 case TAB (BRANCHBWPL
, SZ_UNDEF
):
5192 case TAB (BRABSJUNC
, SZ_UNDEF
):
5193 case TAB (BRABSJCOND
, SZ_UNDEF
):
5195 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5196 && relaxable_symbol (fragP
->fr_symbol
))
5198 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5200 else if (flag_short_refs
)
5202 /* Symbol is undefined and we want short ref. */
5203 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5207 /* Symbol is still undefined. Make it LONG. */
5208 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5213 case TAB (BRANCHBW
, SZ_UNDEF
):
5215 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5216 && relaxable_symbol (fragP
->fr_symbol
))
5218 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5222 /* Symbol is undefined and we don't have long branches. */
5223 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5228 case TAB (FBRANCH
, SZ_UNDEF
):
5229 case TAB (DBCCLBR
, SZ_UNDEF
):
5230 case TAB (DBCCABSJ
, SZ_UNDEF
):
5231 case TAB (PCREL1632
, SZ_UNDEF
):
5233 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5234 && relaxable_symbol (fragP
->fr_symbol
))
5237 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5241 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5246 case TAB (PCINDEX
, SZ_UNDEF
):
5247 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5248 && relaxable_symbol (fragP
->fr_symbol
)))
5250 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
5254 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
5258 case TAB (ABSTOPCREL
, SZ_UNDEF
):
5260 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5261 && relaxable_symbol (fragP
->fr_symbol
)))
5263 fragP
->fr_subtype
= TAB (ABSTOPCREL
, SHORT
);
5267 fragP
->fr_subtype
= TAB (ABSTOPCREL
, LONG
);
5276 /* Now that SZ_UNDEF are taken care of, check others. */
5277 switch (fragP
->fr_subtype
)
5279 case TAB (BRANCHBWL
, BYTE
):
5280 case TAB (BRABSJUNC
, BYTE
):
5281 case TAB (BRABSJCOND
, BYTE
):
5282 case TAB (BRANCHBW
, BYTE
):
5283 /* We can't do a short jump to the next instruction, so in that
5284 case we force word mode. If the symbol is at the start of a
5285 frag, and it is the next frag with any data in it (usually
5286 this is just the next frag, but assembler listings may
5287 introduce empty frags), we must use word mode. */
5288 if (fragP
->fr_symbol
)
5292 sym_frag
= symbol_get_frag (fragP
->fr_symbol
);
5293 if (S_GET_VALUE (fragP
->fr_symbol
) == sym_frag
->fr_address
)
5297 for (l
= fragP
->fr_next
; l
&& l
!= sym_frag
; l
= l
->fr_next
)
5301 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5308 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5311 #ifndef WORKING_DOT_WORD
5312 int md_short_jump_size
= 4;
5313 int md_long_jump_size
= 6;
5316 md_create_short_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5317 fragS
*frag ATTRIBUTE_UNUSED
,
5318 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
5322 offset
= to_addr
- (from_addr
+ 2);
5324 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
5325 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
5329 md_create_long_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5330 fragS
*frag
, symbolS
*to_symbol
)
5334 if (!HAVE_LONG_BRANCH (current_architecture
))
5336 if (flag_keep_pcrel
)
5337 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5338 offset
= to_addr
- S_GET_VALUE (to_symbol
);
5339 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
5340 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5341 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
5346 offset
= to_addr
- (from_addr
+ 2);
5347 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
5348 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5354 /* Different values of OK tell what it's OK to return. Things that
5355 aren't OK are an error (what a shock, no?)
5358 10: Absolute 1:8 only
5359 20: Absolute 0:7 only
5360 30: absolute 0:15 only
5361 40: Absolute 0:31 only
5362 50: absolute 0:127 only
5363 55: absolute -64:63 only
5364 60: absolute -128:127 only
5365 65: absolute 0:511 only
5366 70: absolute 0:4095 only
5367 80: absolute -1, 1:7 only
5371 get_num (struct m68k_exp
*exp
, int ok
)
5373 if (exp
->exp
.X_op
== O_absent
)
5375 /* Do the same thing the VAX asm does. */
5376 op (exp
) = O_constant
;
5382 as_warn (_("expression out of range: defaulting to 1"));
5386 else if (exp
->exp
.X_op
== O_constant
)
5391 if ((valueT
) TRUNC (offs (exp
)) - 1 > 7)
5393 as_warn (_("expression out of range: defaulting to 1"));
5398 if ((valueT
) TRUNC (offs (exp
)) > 7)
5402 if ((valueT
) TRUNC (offs (exp
)) > 15)
5406 if ((valueT
) TRUNC (offs (exp
)) > 32)
5410 if ((valueT
) TRUNC (offs (exp
)) > 127)
5414 if ((valueT
) SEXT (offs (exp
)) + 64 > 127)
5418 if ((valueT
) SEXT (offs (exp
)) + 128 > 255)
5422 if ((valueT
) TRUNC (offs (exp
)) > 511)
5426 if ((valueT
) TRUNC (offs (exp
)) > 4095)
5429 as_warn (_("expression out of range: defaulting to 0"));
5434 if ((valueT
) TRUNC (offs (exp
)) != 0xffffffff
5435 && (valueT
) TRUNC (offs (exp
)) - 1 > 6)
5437 as_warn (_("expression out of range: defaulting to 1"));
5445 else if (exp
->exp
.X_op
== O_big
)
5447 if (offs (exp
) <= 0 /* flonum. */
5448 && (ok
== 90 /* no bignums */
5449 || (ok
> 10 /* Small-int ranges including 0 ok. */
5450 /* If we have a flonum zero, a zero integer should
5451 do as well (e.g., in moveq). */
5452 && generic_floating_point_number
.exponent
== 0
5453 && generic_floating_point_number
.low
[0] == 0)))
5455 /* HACK! Turn it into a long. */
5456 LITTLENUM_TYPE words
[6];
5458 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5459 op (exp
) = O_constant
;
5462 offs (exp
) = words
[1] | (words
[0] << 16);
5466 op (exp
) = O_constant
;
5469 offs (exp
) = (ok
== 10) ? 1 : 0;
5470 as_warn (_("Can't deal with expression; defaulting to %ld"),
5476 if (ok
>= 10 && ok
<= 80)
5478 op (exp
) = O_constant
;
5481 offs (exp
) = (ok
== 10) ? 1 : 0;
5482 as_warn (_("Can't deal with expression; defaulting to %ld"),
5487 if (exp
->size
!= SIZE_UNSPEC
)
5495 if (!isbyte (offs (exp
)))
5496 as_warn (_("expression doesn't fit in BYTE"));
5499 if (!isword (offs (exp
)))
5500 as_warn (_("expression doesn't fit in WORD"));
5508 /* These are the back-ends for the various machine dependent pseudo-ops. */
5511 s_data1 (int ignore ATTRIBUTE_UNUSED
)
5513 subseg_set (data_section
, 1);
5514 demand_empty_rest_of_line ();
5518 s_data2 (int ignore ATTRIBUTE_UNUSED
)
5520 subseg_set (data_section
, 2);
5521 demand_empty_rest_of_line ();
5525 s_bss (int ignore ATTRIBUTE_UNUSED
)
5527 /* We don't support putting frags in the BSS segment, we fake it
5528 by marking in_bss, then looking at s_skip for clues. */
5530 subseg_set (bss_section
, 0);
5531 demand_empty_rest_of_line ();
5535 s_even (int ignore ATTRIBUTE_UNUSED
)
5540 temp
= 1; /* JF should be 2? */
5541 temp_fill
= get_absolute_expression ();
5542 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5543 frag_align (temp
, (int) temp_fill
, 0);
5544 demand_empty_rest_of_line ();
5545 record_alignment (now_seg
, temp
);
5549 s_proc (int ignore ATTRIBUTE_UNUSED
)
5551 demand_empty_rest_of_line ();
5554 /* Pseudo-ops handled for MRI compatibility. */
5556 /* This function returns non-zero if the argument is a conditional
5557 pseudo-op. This is called when checking whether a pending
5558 alignment is needed. */
5561 m68k_conditional_pseudoop (pseudo_typeS
*pop
)
5563 return (pop
->poc_handler
== s_mri_if
5564 || pop
->poc_handler
== s_mri_else
);
5567 /* Handle an MRI style chip specification. */
5576 s
= input_line_pointer
;
5577 /* We can't use get_symbol_name since the processor names are not proper
5579 while (is_part_of_name (c
= *input_line_pointer
++))
5581 *--input_line_pointer
= 0;
5582 for (i
= 0; m68k_cpus
[i
].name
; i
++)
5583 if (strcasecmp (s
, m68k_cpus
[i
].name
) == 0)
5585 if (!m68k_cpus
[i
].name
)
5587 as_bad (_("%s: unrecognized processor name"), s
);
5588 *input_line_pointer
= c
;
5589 ignore_rest_of_line ();
5592 *input_line_pointer
= c
;
5594 if (*input_line_pointer
== '/')
5595 current_architecture
= 0;
5597 current_architecture
&= m68881
| m68851
;
5598 current_architecture
|= m68k_cpus
[i
].arch
& ~(m68881
| m68851
);
5599 control_regs
= m68k_cpus
[i
].control_regs
;
5601 while (*input_line_pointer
== '/')
5603 ++input_line_pointer
;
5604 s
= input_line_pointer
;
5605 /* We can't use get_symbol_name since the processor names are not
5607 while (is_part_of_name (c
= *input_line_pointer
++))
5609 *--input_line_pointer
= 0;
5610 if (strcmp (s
, "68881") == 0)
5611 current_architecture
|= m68881
;
5612 else if (strcmp (s
, "68851") == 0)
5613 current_architecture
|= m68851
;
5614 *input_line_pointer
= c
;
5618 /* The MRI CHIP pseudo-op. */
5621 s_chip (int ignore ATTRIBUTE_UNUSED
)
5627 stop
= mri_comment_field (&stopc
);
5630 mri_comment_end (stop
, stopc
);
5631 demand_empty_rest_of_line ();
5634 /* The MRI FOPT pseudo-op. */
5637 s_fopt (int ignore ATTRIBUTE_UNUSED
)
5641 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5645 input_line_pointer
+= 3;
5646 temp
= get_absolute_expression ();
5647 if (temp
< 0 || temp
> 7)
5648 as_bad (_("bad coprocessor id"));
5650 m68k_float_copnum
= COP0
+ temp
;
5654 as_bad (_("unrecognized fopt option"));
5655 ignore_rest_of_line ();
5659 demand_empty_rest_of_line ();
5662 /* The structure used to handle the MRI OPT pseudo-op. */
5666 /* The name of the option. */
5669 /* If this is not NULL, just call this function. The first argument
5670 is the ARG field of this structure, the second argument is
5671 whether the option was negated. */
5672 void (*pfn
) (int arg
, int on
);
5674 /* If this is not NULL, and the PFN field is NULL, set the variable
5675 this points to. Set it to the ARG field if the option was not
5676 negated, and the NOTARG field otherwise. */
5679 /* The value to pass to PFN or to assign to *PVAR. */
5682 /* The value to assign to *PVAR if the option is negated. If PFN is
5683 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5684 the option may not be negated. */
5688 /* The table used to handle the MRI OPT pseudo-op. */
5690 static void skip_to_comma (int, int);
5691 static void opt_nest (int, int);
5692 static void opt_chip (int, int);
5693 static void opt_list (int, int);
5694 static void opt_list_symbols (int, int);
5696 static const struct opt_action opt_table
[] =
5698 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5700 /* We do relaxing, so there is little use for these options. */
5701 { "b", 0, 0, 0, 0 },
5702 { "brs", 0, 0, 0, 0 },
5703 { "brb", 0, 0, 0, 0 },
5704 { "brl", 0, 0, 0, 0 },
5705 { "brw", 0, 0, 0, 0 },
5707 { "c", 0, 0, 0, 0 },
5708 { "cex", 0, 0, 0, 0 },
5709 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5710 { "cl", 0, 0, 0, 0 },
5711 { "cre", 0, 0, 0, 0 },
5712 { "d", 0, &flag_keep_locals
, 1, 0 },
5713 { "e", 0, 0, 0, 0 },
5714 { "f", 0, &flag_short_refs
, 1, 0 },
5715 { "frs", 0, &flag_short_refs
, 1, 0 },
5716 { "frl", 0, &flag_short_refs
, 0, 1 },
5717 { "g", 0, 0, 0, 0 },
5718 { "i", 0, 0, 0, 0 },
5719 { "m", 0, 0, 0, 0 },
5720 { "mex", 0, 0, 0, 0 },
5721 { "mc", 0, 0, 0, 0 },
5722 { "md", 0, 0, 0, 0 },
5723 { "nest", opt_nest
, 0, 0, 0 },
5724 { "next", skip_to_comma
, 0, 0, 0 },
5725 { "o", 0, 0, 0, 0 },
5726 { "old", 0, 0, 0, 0 },
5727 { "op", skip_to_comma
, 0, 0, 0 },
5728 { "pco", 0, 0, 0, 0 },
5729 { "p", opt_chip
, 0, 0, 0 },
5730 { "pcr", 0, 0, 0, 0 },
5731 { "pcs", 0, 0, 0, 0 },
5732 { "r", 0, 0, 0, 0 },
5733 { "quick", 0, &m68k_quick
, 1, 0 },
5734 { "rel32", 0, &m68k_rel32
, 1, 0 },
5735 { "s", opt_list
, 0, 0, 0 },
5736 { "t", opt_list_symbols
, 0, 0, 0 },
5737 { "w", 0, &flag_no_warnings
, 0, 1 },
5741 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5743 /* The MRI OPT pseudo-op. */
5746 s_opt (int ignore ATTRIBUTE_UNUSED
)
5754 const struct opt_action
*o
;
5759 if (*input_line_pointer
== '-')
5761 ++input_line_pointer
;
5764 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5766 input_line_pointer
+= 2;
5770 c
= get_symbol_name (&s
);
5772 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5774 if (strcasecmp (s
, o
->name
) == 0)
5778 /* Restore input_line_pointer now in case the option
5780 (void) restore_line_pointer (c
);
5781 (*o
->pfn
) (o
->arg
, t
);
5783 else if (o
->pvar
!= NULL
)
5785 if (! t
&& o
->arg
== o
->notarg
)
5786 as_bad (_("option `%s' may not be negated"), s
);
5787 restore_line_pointer (c
);
5788 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5791 *input_line_pointer
= c
;
5797 as_bad (_("option `%s' not recognized"), s
);
5798 restore_line_pointer (c
);
5801 while (*input_line_pointer
++ == ',');
5803 /* Move back to terminating character. */
5804 --input_line_pointer
;
5805 demand_empty_rest_of_line ();
5808 /* Skip ahead to a comma. This is used for OPT options which we do
5809 not support and which take arguments. */
5812 skip_to_comma (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5814 while (*input_line_pointer
!= ','
5815 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5816 ++input_line_pointer
;
5819 /* Handle the OPT NEST=depth option. */
5822 opt_nest (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5824 if (*input_line_pointer
!= '=')
5826 as_bad (_("bad format of OPT NEST=depth"));
5830 ++input_line_pointer
;
5831 max_macro_nest
= get_absolute_expression ();
5834 /* Handle the OPT P=chip option. */
5837 opt_chip (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5839 if (*input_line_pointer
!= '=')
5841 /* This is just OPT P, which we do not support. */
5845 ++input_line_pointer
;
5849 /* Handle the OPT S option. */
5852 opt_list (int arg ATTRIBUTE_UNUSED
, int on
)
5857 /* Handle the OPT T option. */
5860 opt_list_symbols (int arg ATTRIBUTE_UNUSED
, int on
)
5863 listing
|= LISTING_SYMBOLS
;
5865 listing
&= ~LISTING_SYMBOLS
;
5868 /* Handle the MRI REG pseudo-op. */
5871 s_reg (int ignore ATTRIBUTE_UNUSED
)
5880 if (line_label
== NULL
)
5882 as_bad (_("missing label"));
5883 ignore_rest_of_line ();
5888 stop
= mri_comment_field (&stopc
);
5892 s
= input_line_pointer
;
5893 while (ISALNUM (*input_line_pointer
)
5894 #ifdef REGISTER_PREFIX
5895 || *input_line_pointer
== REGISTER_PREFIX
5897 || *input_line_pointer
== '/'
5898 || *input_line_pointer
== '-')
5899 ++input_line_pointer
;
5900 c
= *input_line_pointer
;
5901 *input_line_pointer
= '\0';
5903 if (m68k_ip_op (s
, &rop
) != 0)
5905 if (rop
.error
== NULL
)
5906 as_bad (_("bad register list"));
5908 as_bad (_("bad register list: %s"), rop
.error
);
5909 *input_line_pointer
= c
;
5910 ignore_rest_of_line ();
5914 *input_line_pointer
= c
;
5916 if (rop
.mode
== REGLST
)
5918 else if (rop
.mode
== DREG
)
5919 mask
= 1 << (rop
.reg
- DATA0
);
5920 else if (rop
.mode
== AREG
)
5921 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5922 else if (rop
.mode
== FPREG
)
5923 mask
= 1 << (rop
.reg
- FP0
+ 16);
5924 else if (rop
.mode
== CONTROL
5927 else if (rop
.mode
== CONTROL
5930 else if (rop
.mode
== CONTROL
5935 as_bad (_("bad register list"));
5936 ignore_rest_of_line ();
5940 S_SET_SEGMENT (line_label
, reg_section
);
5941 S_SET_VALUE (line_label
, ~mask
);
5942 symbol_set_frag (line_label
, &zero_address_frag
);
5945 mri_comment_end (stop
, stopc
);
5947 demand_empty_rest_of_line ();
5950 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5954 struct save_opts
*next
;
5956 int symbols_case_sensitive
;
5960 const enum m68k_register
*control_regs
;
5965 /* FIXME: We don't save OPT S. */
5968 /* This variable holds the stack of saved options. */
5970 static struct save_opts
*save_stack
;
5972 /* The MRI SAVE pseudo-op. */
5975 s_save (int ignore ATTRIBUTE_UNUSED
)
5977 struct save_opts
*s
;
5979 s
= XNEW (struct save_opts
);
5980 s
->abspcadd
= m68k_abspcadd
;
5981 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5982 s
->keep_locals
= flag_keep_locals
;
5983 s
->short_refs
= flag_short_refs
;
5984 s
->architecture
= current_architecture
;
5985 s
->control_regs
= control_regs
;
5986 s
->quick
= m68k_quick
;
5987 s
->rel32
= m68k_rel32
;
5988 s
->listing
= listing
;
5989 s
->no_warnings
= flag_no_warnings
;
5991 s
->next
= save_stack
;
5994 demand_empty_rest_of_line ();
5997 /* The MRI RESTORE pseudo-op. */
6000 s_restore (int ignore ATTRIBUTE_UNUSED
)
6002 struct save_opts
*s
;
6004 if (save_stack
== NULL
)
6006 as_bad (_("restore without save"));
6007 ignore_rest_of_line ();
6012 save_stack
= s
->next
;
6014 m68k_abspcadd
= s
->abspcadd
;
6015 symbols_case_sensitive
= s
->symbols_case_sensitive
;
6016 flag_keep_locals
= s
->keep_locals
;
6017 flag_short_refs
= s
->short_refs
;
6018 current_architecture
= s
->architecture
;
6019 control_regs
= s
->control_regs
;
6020 m68k_quick
= s
->quick
;
6021 m68k_rel32
= s
->rel32
;
6022 listing
= s
->listing
;
6023 flag_no_warnings
= s
->no_warnings
;
6027 demand_empty_rest_of_line ();
6030 /* Types of MRI structured control directives. */
6032 enum mri_control_type
6040 /* This structure is used to stack the MRI structured control
6043 struct mri_control_info
6045 /* The directive within which this one is enclosed. */
6046 struct mri_control_info
*outer
;
6048 /* The type of directive. */
6049 enum mri_control_type type
;
6051 /* Whether an ELSE has been in an IF. */
6054 /* The add or sub statement at the end of a FOR. */
6057 /* The label of the top of a FOR or REPEAT loop. */
6060 /* The label to jump to for the next iteration, or the else
6061 expression of a conditional. */
6064 /* The label to jump to to break out of the loop, or the label past
6065 the end of a conditional. */
6069 /* The stack of MRI structured control directives. */
6071 static struct mri_control_info
*mri_control_stack
;
6073 /* The current MRI structured control directive index number, used to
6074 generate label names. */
6076 static int mri_control_index
;
6078 /* Assemble an instruction for an MRI structured control directive. */
6081 mri_assemble (char *str
)
6085 /* md_assemble expects the opcode to be in lower case. */
6086 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
6092 /* Generate a new MRI label structured control directive label name. */
6095 mri_control_label (void)
6099 n
= XNEWVEC (char, 20);
6100 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
6101 ++mri_control_index
;
6105 /* Create a new MRI structured control directive. */
6107 static struct mri_control_info
*
6108 push_mri_control (enum mri_control_type type
)
6110 struct mri_control_info
*n
;
6112 n
= XNEW (struct mri_control_info
);
6116 if (type
== mri_if
|| type
== mri_while
)
6119 n
->top
= mri_control_label ();
6120 n
->next
= mri_control_label ();
6121 n
->bottom
= mri_control_label ();
6123 n
->outer
= mri_control_stack
;
6124 mri_control_stack
= n
;
6129 /* Pop off the stack of MRI structured control directives. */
6132 pop_mri_control (void)
6134 struct mri_control_info
*n
;
6136 n
= mri_control_stack
;
6137 mri_control_stack
= n
->outer
;
6145 /* Recognize a condition code in an MRI structured control expression. */
6148 parse_mri_condition (int *pcc
)
6152 know (*input_line_pointer
== '<');
6154 ++input_line_pointer
;
6155 c1
= *input_line_pointer
++;
6156 c2
= *input_line_pointer
++;
6158 if (*input_line_pointer
!= '>')
6160 as_bad (_("syntax error in structured control directive"));
6164 ++input_line_pointer
;
6170 *pcc
= (c1
<< 8) | c2
;
6175 /* Parse a single operand in an MRI structured control expression. */
6178 parse_mri_control_operand (int *pcc
, char **leftstart
, char **leftstop
,
6179 char **rightstart
, char **rightstop
)
6191 if (*input_line_pointer
== '<')
6193 /* It's just a condition code. */
6194 return parse_mri_condition (pcc
);
6197 /* Look ahead for the condition code. */
6198 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6200 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
6205 as_bad (_("missing condition code in structured control directive"));
6209 *leftstart
= input_line_pointer
;
6211 if (*leftstop
> *leftstart
6212 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
6215 input_line_pointer
= s
;
6216 if (! parse_mri_condition (pcc
))
6219 /* Look ahead for AND or OR or end of line. */
6220 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6222 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6223 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6225 if ((s
== input_line_pointer
6228 && ((strncasecmp (s
, "AND", 3) == 0
6229 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
6230 || (strncasecmp (s
, "OR", 2) == 0
6231 && (s
[2] == '.' || ! is_part_of_name (s
[2])))))
6235 *rightstart
= input_line_pointer
;
6237 if (*rightstop
> *rightstart
6238 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
6241 input_line_pointer
= s
;
6246 #define MCC(b1, b2) (((b1) << 8) | (b2))
6248 /* Swap the sense of a condition. This changes the condition so that
6249 it generates the same result when the operands are swapped. */
6252 swap_mri_condition (int cc
)
6256 case MCC ('h', 'i'): return MCC ('c', 's');
6257 case MCC ('l', 's'): return MCC ('c', 'c');
6258 /* <HS> is an alias for <CC>. */
6259 case MCC ('h', 's'):
6260 case MCC ('c', 'c'): return MCC ('l', 's');
6261 /* <LO> is an alias for <CS>. */
6262 case MCC ('l', 'o'):
6263 case MCC ('c', 's'): return MCC ('h', 'i');
6264 case MCC ('p', 'l'): return MCC ('m', 'i');
6265 case MCC ('m', 'i'): return MCC ('p', 'l');
6266 case MCC ('g', 'e'): return MCC ('l', 'e');
6267 case MCC ('l', 't'): return MCC ('g', 't');
6268 case MCC ('g', 't'): return MCC ('l', 't');
6269 case MCC ('l', 'e'): return MCC ('g', 'e');
6270 /* Issue a warning for conditions we can not swap. */
6271 case MCC ('n', 'e'): return MCC ('n', 'e'); /* no problem here */
6272 case MCC ('e', 'q'): return MCC ('e', 'q'); /* also no problem */
6273 case MCC ('v', 'c'):
6274 case MCC ('v', 's'):
6276 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6277 (char) (cc
>> 8), (char) (cc
));
6283 /* Reverse the sense of a condition. */
6286 reverse_mri_condition (int cc
)
6290 case MCC ('h', 'i'): return MCC ('l', 's');
6291 case MCC ('l', 's'): return MCC ('h', 'i');
6292 /* <HS> is an alias for <CC> */
6293 case MCC ('h', 's'): return MCC ('l', 'o');
6294 case MCC ('c', 'c'): return MCC ('c', 's');
6295 /* <LO> is an alias for <CS> */
6296 case MCC ('l', 'o'): return MCC ('h', 's');
6297 case MCC ('c', 's'): return MCC ('c', 'c');
6298 case MCC ('n', 'e'): return MCC ('e', 'q');
6299 case MCC ('e', 'q'): return MCC ('n', 'e');
6300 case MCC ('v', 'c'): return MCC ('v', 's');
6301 case MCC ('v', 's'): return MCC ('v', 'c');
6302 case MCC ('p', 'l'): return MCC ('m', 'i');
6303 case MCC ('m', 'i'): return MCC ('p', 'l');
6304 case MCC ('g', 'e'): return MCC ('l', 't');
6305 case MCC ('l', 't'): return MCC ('g', 'e');
6306 case MCC ('g', 't'): return MCC ('l', 'e');
6307 case MCC ('l', 'e'): return MCC ('g', 't');
6312 /* Build an MRI structured control expression. This generates test
6313 and branch instructions. It goes to TRUELAB if the condition is
6314 true, and to FALSELAB if the condition is false. Exactly one of
6315 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6316 is the size qualifier for the expression. EXTENT is the size to
6317 use for the branch. */
6320 build_mri_control_operand (int qual
, int cc
, char *leftstart
, char *leftstop
,
6321 char *rightstart
, char *rightstop
,
6322 const char *truelab
, const char *falselab
,
6328 if (leftstart
!= NULL
)
6330 struct m68k_op leftop
, rightop
;
6333 /* Swap the compare operands, if necessary, to produce a legal
6334 m68k compare instruction. Comparing a register operand with
6335 a non-register operand requires the register to be on the
6336 right (cmp, cmpa). Comparing an immediate value with
6337 anything requires the immediate value to be on the left
6342 (void) m68k_ip_op (leftstart
, &leftop
);
6347 (void) m68k_ip_op (rightstart
, &rightop
);
6350 if (rightop
.mode
== IMMED
6351 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
6352 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
6356 /* Correct conditional handling:
6357 if #1 <lt> d0 then ;means if (1 < d0)
6363 cmp #1,d0 if we do *not* swap the operands
6364 bgt true we need the swapped condition!
6371 leftstart
= rightstart
;
6374 leftstop
= rightstop
;
6379 cc
= swap_mri_condition (cc
);
6383 if (truelab
== NULL
)
6385 cc
= reverse_mri_condition (cc
);
6389 if (leftstart
!= NULL
)
6391 buf
= XNEWVEC (char, (20
6392 + (leftstop
- leftstart
)
6393 + (rightstop
- rightstart
)));
6399 *s
++ = TOLOWER (qual
);
6401 memcpy (s
, leftstart
, leftstop
- leftstart
);
6402 s
+= leftstop
- leftstart
;
6404 memcpy (s
, rightstart
, rightstop
- rightstart
);
6405 s
+= rightstop
- rightstart
;
6411 buf
= XNEWVEC (char, 20 + strlen (truelab
));
6417 *s
++ = TOLOWER (extent
);
6419 strcpy (s
, truelab
);
6424 /* Parse an MRI structured control expression. This generates test
6425 and branch instructions. STOP is where the expression ends. It
6426 goes to TRUELAB if the condition is true, and to FALSELAB if the
6427 condition is false. Exactly one of TRUELAB and FALSELAB will be
6428 NULL, meaning to fall through. QUAL is the size qualifier for the
6429 expression. EXTENT is the size to use for the branch. */
6432 parse_mri_control_expression (char *stop
, int qual
, const char *truelab
,
6433 const char *falselab
, int extent
)
6445 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6446 &rightstart
, &rightstop
))
6452 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6456 if (falselab
!= NULL
)
6459 flab
= mri_control_label ();
6461 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6462 rightstop
, (const char *) NULL
, flab
, extent
);
6464 input_line_pointer
+= 3;
6465 if (*input_line_pointer
!= '.'
6466 || input_line_pointer
[1] == '\0')
6470 qual
= input_line_pointer
[1];
6471 input_line_pointer
+= 2;
6474 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6475 &rightstart
, &rightstop
))
6481 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6482 rightstop
, truelab
, falselab
, extent
);
6484 if (falselab
== NULL
)
6487 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6491 if (truelab
!= NULL
)
6494 tlab
= mri_control_label ();
6496 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6497 rightstop
, tlab
, (const char *) NULL
, extent
);
6499 input_line_pointer
+= 2;
6500 if (*input_line_pointer
!= '.'
6501 || input_line_pointer
[1] == '\0')
6505 qual
= input_line_pointer
[1];
6506 input_line_pointer
+= 2;
6509 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6510 &rightstart
, &rightstop
))
6516 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6517 rightstop
, truelab
, falselab
, extent
);
6519 if (truelab
== NULL
)
6524 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6525 rightstop
, truelab
, falselab
, extent
);
6529 if (input_line_pointer
!= stop
)
6530 as_bad (_("syntax error in structured control directive"));
6533 /* Handle the MRI IF pseudo-op. This may be a structured control
6534 directive, or it may be a regular assembler conditional, depending
6542 struct mri_control_info
*n
;
6544 /* A structured control directive must end with THEN with an
6545 optional qualifier. */
6546 s
= input_line_pointer
;
6547 /* We only accept '*' as introduction of comments if preceded by white space
6548 or at first column of a line (I think this can't actually happen here?)
6549 This is important when assembling:
6550 if d0 <ne> 12(a0,d0*2) then
6551 if d0 <ne> #CONST*20 then. */
6552 while (! (is_end_of_line
[(unsigned char) *s
]
6555 && (s
== input_line_pointer
6557 || *(s
-1) == '\t'))))
6560 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6563 if (s
- input_line_pointer
> 1
6567 if (s
- input_line_pointer
< 3
6568 || strncasecmp (s
- 3, "THEN", 4) != 0)
6572 as_bad (_("missing then"));
6573 ignore_rest_of_line ();
6577 /* It's a conditional. */
6582 /* Since this might be a conditional if, this pseudo-op will be
6583 called even if we are supported to be ignoring input. Double
6584 check now. Clobber *input_line_pointer so that ignore_input
6585 thinks that this is not a special pseudo-op. */
6586 c
= *input_line_pointer
;
6587 *input_line_pointer
= 0;
6588 if (ignore_input ())
6590 *input_line_pointer
= c
;
6591 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6592 ++input_line_pointer
;
6593 demand_empty_rest_of_line ();
6596 *input_line_pointer
= c
;
6598 n
= push_mri_control (mri_if
);
6600 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6601 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6604 input_line_pointer
= s
+ 3;
6606 input_line_pointer
= s
+ 1;
6610 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6611 ++input_line_pointer
;
6614 demand_empty_rest_of_line ();
6617 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6618 structured IF, associate the ELSE with the IF. Otherwise, assume
6619 it is a conditional else. */
6622 s_mri_else (int qual
)
6629 && (mri_control_stack
== NULL
6630 || mri_control_stack
->type
!= mri_if
6631 || mri_control_stack
->else_seen
))
6637 c
= *input_line_pointer
;
6638 *input_line_pointer
= 0;
6639 if (ignore_input ())
6641 *input_line_pointer
= c
;
6642 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6643 ++input_line_pointer
;
6644 demand_empty_rest_of_line ();
6647 *input_line_pointer
= c
;
6649 if (mri_control_stack
== NULL
6650 || mri_control_stack
->type
!= mri_if
6651 || mri_control_stack
->else_seen
)
6653 as_bad (_("else without matching if"));
6654 ignore_rest_of_line ();
6658 mri_control_stack
->else_seen
= 1;
6660 buf
= XNEWVEC (char, 20 + strlen (mri_control_stack
->bottom
));
6661 q
[0] = TOLOWER (qual
);
6663 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6667 colon (mri_control_stack
->next
);
6671 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6672 ++input_line_pointer
;
6675 demand_empty_rest_of_line ();
6678 /* Handle the MRI ENDI pseudo-op. */
6681 s_mri_endi (int ignore ATTRIBUTE_UNUSED
)
6683 if (mri_control_stack
== NULL
6684 || mri_control_stack
->type
!= mri_if
)
6686 as_bad (_("endi without matching if"));
6687 ignore_rest_of_line ();
6691 /* ignore_input will not return true for ENDI, so we don't need to
6692 worry about checking it again here. */
6694 if (! mri_control_stack
->else_seen
)
6695 colon (mri_control_stack
->next
);
6696 colon (mri_control_stack
->bottom
);
6702 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6703 ++input_line_pointer
;
6706 demand_empty_rest_of_line ();
6709 /* Handle the MRI BREAK pseudo-op. */
6712 s_mri_break (int extent
)
6714 struct mri_control_info
*n
;
6718 n
= mri_control_stack
;
6720 && n
->type
!= mri_for
6721 && n
->type
!= mri_repeat
6722 && n
->type
!= mri_while
)
6726 as_bad (_("break outside of structured loop"));
6727 ignore_rest_of_line ();
6731 buf
= XNEWVEC (char, 20 + strlen (n
->bottom
));
6732 ex
[0] = TOLOWER (extent
);
6734 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6740 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6741 ++input_line_pointer
;
6744 demand_empty_rest_of_line ();
6747 /* Handle the MRI NEXT pseudo-op. */
6750 s_mri_next (int extent
)
6752 struct mri_control_info
*n
;
6756 n
= mri_control_stack
;
6758 && n
->type
!= mri_for
6759 && n
->type
!= mri_repeat
6760 && n
->type
!= mri_while
)
6764 as_bad (_("next outside of structured loop"));
6765 ignore_rest_of_line ();
6769 buf
= XNEWVEC (char, 20 + strlen (n
->next
));
6770 ex
[0] = TOLOWER (extent
);
6772 sprintf (buf
, "bra%s %s", ex
, n
->next
);
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 FOR pseudo-op. */
6788 s_mri_for (int qual
)
6790 const char *varstart
, *varstop
;
6791 const char *initstart
, *initstop
;
6792 const char *endstart
, *endstop
;
6793 const char *bystart
, *bystop
;
6797 struct mri_control_info
*n
;
6803 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6807 varstart
= input_line_pointer
;
6809 /* Look for the '='. */
6810 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6811 && *input_line_pointer
!= '=')
6812 ++input_line_pointer
;
6813 if (*input_line_pointer
!= '=')
6815 as_bad (_("missing ="));
6816 ignore_rest_of_line ();
6820 varstop
= input_line_pointer
;
6821 if (varstop
> varstart
6822 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6825 ++input_line_pointer
;
6827 initstart
= input_line_pointer
;
6829 /* Look for TO or DOWNTO. */
6832 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6834 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6835 && ! is_part_of_name (input_line_pointer
[2]))
6837 initstop
= input_line_pointer
;
6838 input_line_pointer
+= 2;
6841 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6842 && ! is_part_of_name (input_line_pointer
[6]))
6844 initstop
= input_line_pointer
;
6846 input_line_pointer
+= 6;
6849 ++input_line_pointer
;
6851 if (initstop
== NULL
)
6853 as_bad (_("missing to or downto"));
6854 ignore_rest_of_line ();
6857 if (initstop
> initstart
6858 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6862 endstart
= input_line_pointer
;
6864 /* Look for BY or DO. */
6867 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6869 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6870 && ! is_part_of_name (input_line_pointer
[2]))
6872 endstop
= input_line_pointer
;
6874 input_line_pointer
+= 2;
6877 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6878 && (input_line_pointer
[2] == '.'
6879 || ! is_part_of_name (input_line_pointer
[2])))
6881 endstop
= input_line_pointer
;
6882 input_line_pointer
+= 2;
6885 ++input_line_pointer
;
6887 if (endstop
== NULL
)
6889 as_bad (_("missing do"));
6890 ignore_rest_of_line ();
6893 if (endstop
> endstart
6894 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6900 bystop
= bystart
+ 2;
6905 bystart
= input_line_pointer
;
6909 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6911 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6912 && (input_line_pointer
[2] == '.'
6913 || ! is_part_of_name (input_line_pointer
[2])))
6915 bystop
= input_line_pointer
;
6916 input_line_pointer
+= 2;
6919 ++input_line_pointer
;
6923 as_bad (_("missing do"));
6924 ignore_rest_of_line ();
6927 if (bystop
> bystart
6928 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6932 if (*input_line_pointer
!= '.')
6936 extent
= input_line_pointer
[1];
6937 input_line_pointer
+= 2;
6940 /* We have fully parsed the FOR operands. Now build the loop. */
6941 n
= push_mri_control (mri_for
);
6943 buf
= XNEWVEC (char, 50 + (input_line_pointer
- varstart
));
6945 /* Move init,var. */
6952 *s
++ = TOLOWER (qual
);
6954 memcpy (s
, initstart
, initstop
- initstart
);
6955 s
+= initstop
- initstart
;
6957 memcpy (s
, varstart
, varstop
- varstart
);
6958 s
+= varstop
- varstart
;
6970 *s
++ = TOLOWER (qual
);
6972 memcpy (s
, endstart
, endstop
- endstart
);
6973 s
+= endstop
- endstart
;
6975 memcpy (s
, varstart
, varstop
- varstart
);
6976 s
+= varstop
- varstart
;
6981 ex
[0] = TOLOWER (extent
);
6984 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6986 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6989 /* Put together the add or sub instruction used by ENDF. */
6997 *s
++ = TOLOWER (qual
);
6999 memcpy (s
, bystart
, bystop
- bystart
);
7000 s
+= bystop
- bystart
;
7002 memcpy (s
, varstart
, varstop
- varstart
);
7003 s
+= varstop
- varstart
;
7009 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7010 ++input_line_pointer
;
7013 demand_empty_rest_of_line ();
7016 /* Handle the MRI ENDF pseudo-op. */
7019 s_mri_endf (int ignore ATTRIBUTE_UNUSED
)
7021 if (mri_control_stack
== NULL
7022 || mri_control_stack
->type
!= mri_for
)
7024 as_bad (_("endf without for"));
7025 ignore_rest_of_line ();
7029 colon (mri_control_stack
->next
);
7031 mri_assemble (mri_control_stack
->incr
);
7033 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
7034 mri_assemble (mri_control_stack
->incr
);
7036 free (mri_control_stack
->incr
);
7038 colon (mri_control_stack
->bottom
);
7044 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7045 ++input_line_pointer
;
7048 demand_empty_rest_of_line ();
7051 /* Handle the MRI REPEAT pseudo-op. */
7054 s_mri_repeat (int ignore ATTRIBUTE_UNUSED
)
7056 struct mri_control_info
*n
;
7058 n
= push_mri_control (mri_repeat
);
7062 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7063 ++input_line_pointer
;
7065 demand_empty_rest_of_line ();
7068 /* Handle the MRI UNTIL pseudo-op. */
7071 s_mri_until (int qual
)
7075 if (mri_control_stack
== NULL
7076 || mri_control_stack
->type
!= mri_repeat
)
7078 as_bad (_("until without repeat"));
7079 ignore_rest_of_line ();
7083 colon (mri_control_stack
->next
);
7085 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
7088 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
7089 mri_control_stack
->top
, '\0');
7091 colon (mri_control_stack
->bottom
);
7093 input_line_pointer
= s
;
7099 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7100 ++input_line_pointer
;
7103 demand_empty_rest_of_line ();
7106 /* Handle the MRI WHILE pseudo-op. */
7109 s_mri_while (int qual
)
7113 struct mri_control_info
*n
;
7115 s
= input_line_pointer
;
7116 /* We only accept '*' as introduction of comments if preceded by white space
7117 or at first column of a line (I think this can't actually happen here?)
7118 This is important when assembling:
7119 while d0 <ne> 12(a0,d0*2) do
7120 while d0 <ne> #CONST*20 do. */
7121 while (! (is_end_of_line
[(unsigned char) *s
]
7124 && (s
== input_line_pointer
7126 || *(s
-1) == '\t'))))
7129 while (*s
== ' ' || *s
== '\t')
7131 if (s
- input_line_pointer
> 1
7134 if (s
- input_line_pointer
< 2
7135 || strncasecmp (s
- 1, "DO", 2) != 0)
7137 as_bad (_("missing do"));
7138 ignore_rest_of_line ();
7142 n
= push_mri_control (mri_while
);
7146 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
7147 s
[1] == '.' ? s
[2] : '\0');
7149 input_line_pointer
= s
+ 1;
7150 if (*input_line_pointer
== '.')
7151 input_line_pointer
+= 2;
7155 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7156 ++input_line_pointer
;
7159 demand_empty_rest_of_line ();
7162 /* Handle the MRI ENDW pseudo-op. */
7165 s_mri_endw (int ignore ATTRIBUTE_UNUSED
)
7169 if (mri_control_stack
== NULL
7170 || mri_control_stack
->type
!= mri_while
)
7172 as_bad (_("endw without while"));
7173 ignore_rest_of_line ();
7177 buf
= XNEWVEC (char, 20 + strlen (mri_control_stack
->next
));
7178 sprintf (buf
, "bra %s", mri_control_stack
->next
);
7182 colon (mri_control_stack
->bottom
);
7188 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7189 ++input_line_pointer
;
7192 demand_empty_rest_of_line ();
7195 /* Parse a .cpu directive. */
7198 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED
)
7205 as_bad (_("already assembled instructions"));
7206 ignore_rest_of_line ();
7210 name
= input_line_pointer
;
7211 while (*input_line_pointer
&& !ISSPACE(*input_line_pointer
))
7212 input_line_pointer
++;
7213 saved_char
= *input_line_pointer
;
7214 *input_line_pointer
= 0;
7216 m68k_set_cpu (name
, 1, 0);
7218 *input_line_pointer
= saved_char
;
7219 demand_empty_rest_of_line ();
7223 /* Parse a .arch directive. */
7226 s_m68k_arch (int ignored ATTRIBUTE_UNUSED
)
7233 as_bad (_("already assembled instructions"));
7234 ignore_rest_of_line ();
7238 name
= input_line_pointer
;
7239 while (*input_line_pointer
&& *input_line_pointer
!= ','
7240 && !ISSPACE (*input_line_pointer
))
7241 input_line_pointer
++;
7242 saved_char
= *input_line_pointer
;
7243 *input_line_pointer
= 0;
7245 if (m68k_set_arch (name
, 1, 0))
7247 /* Scan extensions. */
7250 *input_line_pointer
++ = saved_char
;
7251 if (!*input_line_pointer
|| ISSPACE (*input_line_pointer
))
7253 name
= input_line_pointer
;
7254 while (*input_line_pointer
&& *input_line_pointer
!= ','
7255 && !ISSPACE (*input_line_pointer
))
7256 input_line_pointer
++;
7257 saved_char
= *input_line_pointer
;
7258 *input_line_pointer
= 0;
7260 while (m68k_set_extension (name
, 1, 0));
7263 *input_line_pointer
= saved_char
;
7264 demand_empty_rest_of_line ();
7268 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
7269 if none is found, the caller is responsible for emitting an error
7270 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
7271 cpu name, if it begins with a '6' (possibly skipping an intervening
7272 'c'. We also allow a 'c' in the same place. if NEGATED is
7273 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
7274 the option is indeed negated. */
7276 static const struct m68k_cpu
*
7277 m68k_lookup_cpu (const char *arg
, const struct m68k_cpu
*table
,
7278 int allow_m
, int *negated
)
7280 /* allow negated value? */
7285 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
7292 /* Remove 'm' or 'mc' prefix from 68k variants. */
7299 else if (arg
[1] == 'c' && arg
[2] == '6')
7303 else if (arg
[0] == 'c' && arg
[1] == '6')
7306 for (; table
->name
; table
++)
7307 if (!strcmp (arg
, table
->name
))
7309 if (table
->alias
< -1 || table
->alias
> 1)
7310 as_bad (_("`%s' is deprecated, use `%s'"),
7311 table
->name
, table
[table
->alias
< 0 ? 1 : -1].name
);
7317 /* Set the cpu, issuing errors if it is unrecognized. */
7320 m68k_set_cpu (char const *name
, int allow_m
, int silent
)
7322 const struct m68k_cpu
*cpu
;
7324 cpu
= m68k_lookup_cpu (name
, m68k_cpus
, allow_m
, NULL
);
7329 as_bad (_("cpu `%s' unrecognized"), name
);
7336 /* Set the architecture, issuing errors if it is unrecognized. */
7339 m68k_set_arch (char const *name
, int allow_m
, int silent
)
7341 const struct m68k_cpu
*arch
;
7343 arch
= m68k_lookup_cpu (name
, m68k_archs
, allow_m
, NULL
);
7348 as_bad (_("architecture `%s' unrecognized"), name
);
7351 selected_arch
= arch
;
7355 /* Set the architecture extension, issuing errors if it is
7356 unrecognized, or invalid */
7359 m68k_set_extension (char const *name
, int allow_m
, int silent
)
7362 const struct m68k_cpu
*ext
;
7364 ext
= m68k_lookup_cpu (name
, m68k_extensions
, allow_m
, &negated
);
7369 as_bad (_("extension `%s' unrecognized"), name
);
7374 not_current_architecture
|= (ext
->control_regs
7375 ? *(unsigned *)ext
->control_regs
: ext
->arch
);
7377 current_architecture
|= ext
->arch
;
7382 Invocation line includes a switch not recognized by the base assembler.
7385 const char *md_shortopts
= "lSA:m:kQ:V";
7387 struct option md_longopts
[] = {
7388 #define OPTION_PIC (OPTION_MD_BASE)
7389 {"pic", no_argument
, NULL
, OPTION_PIC
},
7390 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7391 {"register-prefix-optional", no_argument
, NULL
,
7392 OPTION_REGISTER_PREFIX_OPTIONAL
},
7393 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7394 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
7395 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7396 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
7397 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7398 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
7399 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7400 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
7401 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7402 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
7403 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7404 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
7405 {NULL
, no_argument
, NULL
, 0}
7407 size_t md_longopts_size
= sizeof (md_longopts
);
7410 md_parse_option (int c
, const char *arg
)
7414 case 'l': /* -l means keep external to 2 bit offset
7415 rather than 16 bit one. */
7416 flag_short_refs
= 1;
7419 case 'S': /* -S means that jbsr's always turn into
7421 flag_long_jumps
= 1;
7424 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
7425 branches into absolute jumps. */
7426 flag_keep_pcrel
= 1;
7432 break; /* -pic, Position Independent Code. */
7434 case OPTION_REGISTER_PREFIX_OPTIONAL
:
7435 flag_reg_prefix_optional
= 1;
7436 reg_prefix_optional_seen
= 1;
7439 /* -V: SVR4 argument to print version ID. */
7441 print_version_id ();
7444 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7445 should be emitted or not. FIXME: Not implemented. */
7449 case OPTION_BITWISE_OR
:
7454 n
= XNEWVEC (char, strlen (m68k_comment_chars
) + 1);
7456 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
7460 m68k_comment_chars
= n
;
7464 case OPTION_BASE_SIZE_DEFAULT_16
:
7465 m68k_index_width_default
= SIZE_WORD
;
7468 case OPTION_BASE_SIZE_DEFAULT_32
:
7469 m68k_index_width_default
= SIZE_LONG
;
7472 case OPTION_DISP_SIZE_DEFAULT_16
:
7474 m68k_rel32_from_cmdline
= 1;
7477 case OPTION_DISP_SIZE_DEFAULT_32
:
7479 m68k_rel32_from_cmdline
= 1;
7484 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7487 /* Intentional fall-through. */
7489 if (!strncmp (arg
, "arch=", 5))
7490 m68k_set_arch (arg
+ 5, 1, 0);
7491 else if (!strncmp (arg
, "cpu=", 4))
7492 m68k_set_cpu (arg
+ 4, 1, 0);
7493 else if (m68k_set_extension (arg
, 0, 1))
7495 else if (m68k_set_arch (arg
, 0, 1))
7497 else if (m68k_set_cpu (arg
, 0, 1))
7510 /* Setup tables from the selected arch and/or cpu */
7513 m68k_init_arch (void)
7515 if (not_current_architecture
& current_architecture
)
7517 as_bad (_("architecture features both enabled and disabled"));
7518 not_current_architecture
&= ~current_architecture
;
7522 current_architecture
|= selected_arch
->arch
;
7523 control_regs
= selected_arch
->control_regs
;
7526 current_architecture
|= selected_cpu
->arch
;
7528 current_architecture
&= ~not_current_architecture
;
7530 if ((current_architecture
& (cfloat
| m68881
)) == (cfloat
| m68881
))
7532 /* Determine which float is really meant. */
7533 if (current_architecture
& (m68k_mask
& ~m68881
))
7534 current_architecture
^= cfloat
;
7536 current_architecture
^= m68881
;
7541 control_regs
= selected_cpu
->control_regs
;
7542 if (current_architecture
& ~selected_cpu
->arch
)
7544 as_bad (_("selected processor does not have all features of selected architecture"));
7545 current_architecture
7546 = selected_cpu
->arch
& ~not_current_architecture
;
7550 if ((current_architecture
& m68k_mask
)
7551 && (current_architecture
& ~m68k_mask
))
7553 as_bad (_ ("m68k and cf features both selected"));
7554 if (current_architecture
& m68k_mask
)
7555 current_architecture
&= m68k_mask
;
7557 current_architecture
&= ~m68k_mask
;
7560 /* Permit m68881 specification with all cpus; those that can't work
7561 with a coprocessor could be doing emulation. */
7562 if (current_architecture
& m68851
)
7564 if (current_architecture
& m68040
)
7565 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7567 /* What other incompatibilities could we check for? */
7569 if (cpu_of_arch (current_architecture
) < m68020
7570 || arch_coldfire_p (current_architecture
))
7571 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
7577 md_show_usage (FILE *stream
)
7579 const char *default_cpu
= TARGET_CPU
;
7582 /* Get the canonical name for the default target CPU. */
7583 if (*default_cpu
== 'm')
7585 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7587 if (strcasecmp (default_cpu
, m68k_cpus
[i
].name
) == 0)
7589 while (m68k_cpus
[i
].alias
> 0)
7591 while (m68k_cpus
[i
].alias
< 0)
7593 default_cpu
= m68k_cpus
[i
].name
;
7597 fprintf (stream
, _("\
7598 -march=<arch> set architecture\n\
7599 -mcpu=<cpu> set cpu [default %s]\n\
7601 for (i
= 0; m68k_extensions
[i
].name
; i
++)
7602 fprintf (stream
, _("\
7603 -m[no-]%-16s enable/disable %s architecture extension\n\
7604 "), m68k_extensions
[i
].name
,
7605 m68k_extensions
[i
].alias
> 0 ? " ColdFire"
7606 : m68k_extensions
[i
].alias
< 0 ? " m68k" : "");
7608 fprintf (stream
, _("\
7609 -l use 1 word for refs to undefined symbols [default 2]\n\
7610 -pic, -k generate position independent code\n\
7611 -S turn jbsr into jsr\n\
7612 --pcrel never turn PC-relative branches into absolute jumps\n\
7613 --register-prefix-optional\n\
7614 recognize register names without prefix character\n\
7615 --bitwise-or do not treat `|' as a comment character\n\
7616 --base-size-default-16 base reg without size is 16 bits\n\
7617 --base-size-default-32 base reg without size is 32 bits (default)\n\
7618 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7619 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7622 fprintf (stream
, _("Architecture variants are: "));
7623 for (i
= 0; m68k_archs
[i
].name
; i
++)
7626 fprintf (stream
, " | ");
7627 fprintf (stream
, "%s", m68k_archs
[i
].name
);
7629 fprintf (stream
, "\n");
7631 fprintf (stream
, _("Processor variants are: "));
7632 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7635 fprintf (stream
, " | ");
7636 fprintf (stream
, "%s", m68k_cpus
[i
].name
);
7638 fprintf (stream
, _("\n"));
7643 /* TEST2: Test md_assemble() */
7644 /* Warning, this routine probably doesn't work anymore. */
7648 struct m68k_it the_ins
;
7656 if (!gets (buf
) || !*buf
)
7658 if (buf
[0] == '|' || buf
[1] == '.')
7660 for (cp
= buf
; *cp
; cp
++)
7665 memset (&the_ins
, '\0', sizeof (the_ins
));
7666 m68k_ip (&the_ins
, buf
);
7669 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7673 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7674 for (n
= 0; n
< the_ins
.numo
; n
++)
7675 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7677 print_the_insn (&the_ins
.opcode
[0], stdout
);
7678 (void) putchar ('\n');
7680 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7682 if (the_ins
.operands
[n
].error
)
7684 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7687 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
,
7688 the_ins
.operands
[n
].reg
);
7689 if (the_ins
.operands
[n
].b_const
)
7690 printf ("Constant: '%.*s', ",
7691 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
,
7692 the_ins
.operands
[n
].b_const
);
7693 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
,
7694 the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7695 if (the_ins
.operands
[n
].b_iadd
)
7696 printf ("Iadd: '%.*s',",
7697 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
,
7698 the_ins
.operands
[n
].b_iadd
);
7707 is_label (char *str
)
7711 while (*str
&& *str
!= ' ')
7713 if (str
[-1] == ':' || str
[1] == '=')
7720 /* Possible states for relaxation:
7722 0 0 branch offset byte (bra, etc)
7726 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7730 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7737 /* We have no need to default values of symbols. */
7740 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
7745 /* Round up a section size to the appropriate boundary. */
7747 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
7752 /* Exactly what point is a PC-relative offset relative TO?
7753 On the 68k, it is relative to the address of the first extension
7754 word. The difference between the addresses of the offset and the
7755 first extension word is stored in fx_pcrel_adjust. */
7757 md_pcrel_from (fixS
*fixP
)
7761 adjust
= fixP
->fx_pcrel_adjust
;
7764 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7768 m68k_elf_final_processing (void)
7772 if (arch_coldfire_fpu (current_architecture
))
7773 flags
|= EF_M68K_CFV4E
;
7774 /* Set file-specific flags if this is a cpu32 processor. */
7775 if (cpu_of_arch (current_architecture
) & cpu32
)
7776 flags
|= EF_M68K_CPU32
;
7777 else if (cpu_of_arch (current_architecture
) & fido_a
)
7778 flags
|= EF_M68K_FIDO
;
7779 else if ((cpu_of_arch (current_architecture
) & m68000up
)
7780 && !(cpu_of_arch (current_architecture
) & m68020up
))
7781 flags
|= EF_M68K_M68000
;
7783 if (current_architecture
& mcfisa_a
)
7785 static const unsigned isa_features
[][2] =
7787 {EF_M68K_CF_ISA_A_NODIV
,mcfisa_a
},
7788 {EF_M68K_CF_ISA_A
, mcfisa_a
|mcfhwdiv
},
7789 {EF_M68K_CF_ISA_A_PLUS
, mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
},
7790 {EF_M68K_CF_ISA_B_NOUSP
,mcfisa_a
|mcfisa_b
|mcfhwdiv
},
7791 {EF_M68K_CF_ISA_B
, mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfusp
},
7792 {EF_M68K_CF_ISA_C
, mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfusp
},
7793 {EF_M68K_CF_ISA_C_NODIV
,mcfisa_a
|mcfisa_c
|mcfusp
},
7796 static const unsigned mac_features
[][2] =
7798 {EF_M68K_CF_MAC
, mcfmac
},
7799 {EF_M68K_CF_EMAC
, mcfemac
},
7805 pattern
= (current_architecture
7806 & (mcfisa_a
|mcfisa_aa
|mcfisa_b
|mcfisa_c
|mcfhwdiv
|mcfusp
));
7807 for (ix
= 0; isa_features
[ix
][1]; ix
++)
7809 if (pattern
== isa_features
[ix
][1])
7811 flags
|= isa_features
[ix
][0];
7815 if (!isa_features
[ix
][1])
7818 as_warn (_("Not a defined coldfire architecture"));
7822 if (current_architecture
& cfloat
)
7823 flags
|= EF_M68K_CF_FLOAT
| EF_M68K_CFV4E
;
7825 pattern
= current_architecture
& (mcfmac
|mcfemac
);
7828 for (ix
= 0; mac_features
[ix
][1]; ix
++)
7830 if (pattern
== mac_features
[ix
][1])
7832 flags
|= mac_features
[ix
][0];
7836 if (!mac_features
[ix
][1])
7841 elf_elfheader (stdoutput
)->e_flags
|= flags
;
7844 /* Parse @TLSLDO and return the desired relocation. */
7845 static bfd_reloc_code_real_type
7846 m68k_elf_suffix (char **str_p
, expressionS
*exp_p
)
7855 return BFD_RELOC_UNUSED
;
7857 for (ch
= *str
, str2
= ident
;
7858 (str2
< ident
+ sizeof (ident
) - 1
7859 && (ISALNUM (ch
) || ch
== '@'));
7868 if (strncmp (ident
, "TLSLDO", 6) == 0
7871 /* Now check for identifier@suffix+constant. */
7872 if (*str
== '-' || *str
== '+')
7874 char *orig_line
= input_line_pointer
;
7875 expressionS new_exp
;
7877 input_line_pointer
= str
;
7878 expression (&new_exp
);
7879 if (new_exp
.X_op
== O_constant
)
7881 exp_p
->X_add_number
+= new_exp
.X_add_number
;
7882 str
= input_line_pointer
;
7885 if (&input_line_pointer
!= str_p
)
7886 input_line_pointer
= orig_line
;
7890 return BFD_RELOC_68K_TLS_LDO32
;
7893 return BFD_RELOC_UNUSED
;
7896 /* Handles .long <tls_symbol>+0x8000 debug info.
7897 Clobbers input_line_pointer, checks end-of-line.
7898 Adapted from tc-ppc.c:ppc_elf_cons. */
7900 m68k_elf_cons (int nbytes
/* 4=.long */)
7902 if (is_it_end_of_statement ())
7904 demand_empty_rest_of_line ();
7911 bfd_reloc_code_real_type reloc
;
7914 if (exp
.X_op
== O_symbol
7915 && *input_line_pointer
== '@'
7916 && (reloc
= m68k_elf_suffix (&input_line_pointer
,
7917 &exp
)) != BFD_RELOC_UNUSED
)
7919 reloc_howto_type
*reloc_howto
;
7922 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
7923 size
= bfd_get_reloc_size (reloc_howto
);
7927 as_bad (ngettext ("%s relocations do not fit in %u byte",
7928 "%s relocations do not fit in %u bytes",
7930 reloc_howto
->name
, nbytes
);
7937 p
= frag_more (nbytes
);
7939 if (target_big_endian
)
7940 offset
= nbytes
- size
;
7941 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
7946 emit_expr (&exp
, (unsigned int) nbytes
);
7948 while (*input_line_pointer
++ == ',');
7950 /* Put terminator back into stream. */
7951 input_line_pointer
--;
7952 demand_empty_rest_of_line ();
7956 tc_m68k_regname_to_dw2regnum (const char *regname
)
7958 unsigned int regnum
;
7959 static const char *const regnames
[] =
7961 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7962 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7963 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7967 for (regnum
= 0; regnum
< ARRAY_SIZE (regnames
); regnum
++)
7968 if (strcmp (regname
, regnames
[regnum
]) == 0)
7975 tc_m68k_frame_initial_instructions (void)
7977 static int sp_regno
= -1;
7980 sp_regno
= tc_m68k_regname_to_dw2regnum ("sp");
7982 cfi_add_CFA_def_cfa (sp_regno
, -DWARF2_CIE_DATA_ALIGNMENT
);
7983 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN
, DWARF2_CIE_DATA_ALIGNMENT
);
7986 /* Check and emit error if broken-word handling has failed to fix up a
7987 case-table. This is called from write.c, after doing everything it
7988 knows about how to handle broken words. */
7991 tc_m68k_check_adjusted_broken_word (offsetT new_offset
, struct broken_word
*brokwP
)
7993 if (new_offset
> 32767 || new_offset
< -32768)
7994 as_bad_where (brokwP
->frag
->fr_file
, brokwP
->frag
->fr_line
,
7995 _("Adjusted signed .word (%#lx) overflows: `switch'-statement too large."),