1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "safe-ctype.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "opcode/m68k.h"
31 #include "m68k-parse.h"
42 static void m68k_elf_cons (int);
45 /* This string holds the chars that always start a comment. If the
46 pre-processor is disabled, these aren't very useful. The macro
47 tc_comment_chars points to this. We use this, rather than the
48 usual comment_chars, so that the --bitwise-or option will work. */
49 #if defined (TE_SVR4) || defined (TE_DELTA)
50 const char *m68k_comment_chars
= "|#";
52 const char *m68k_comment_chars
= "|";
55 /* This array holds the chars that only start a comment at the beginning of
56 a line. If the line seems to have the form '# 123 filename'
57 .line and .file directives will appear in the pre-processed output */
58 /* Note that input_file.c hand checks for '#' at the beginning of the
59 first line of the input file. This is because the compiler outputs
60 #NO_APP at the beginning of its output. */
61 /* Also note that comments like this one will always work. */
62 const char line_comment_chars
[] = "#*";
64 const char line_separator_chars
[] = ";";
66 /* Chars that can be used to separate mant from exp in floating point nums. */
67 const char EXP_CHARS
[] = "eE";
69 /* Chars that mean this number is a floating point constant, as
70 in "0f12.456" or "0d1.2345e12". */
72 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
74 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
75 changed in read.c . Ideally it shouldn't have to know about it at all,
76 but nothing is ideal around here. */
78 /* Are we trying to generate PIC code? If so, absolute references
79 ought to be made into linkage table references or pc-relative
80 references. Not implemented. For ELF there are other means
81 to denote pic relocations. */
84 static int flag_short_refs
; /* -l option. */
85 static int flag_long_jumps
; /* -S option. */
86 static int flag_keep_pcrel
; /* --pcrel option. */
88 #ifdef REGISTER_PREFIX_OPTIONAL
89 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
91 int flag_reg_prefix_optional
;
94 /* Whether --register-prefix-optional was used on the command line. */
95 static int reg_prefix_optional_seen
;
97 /* The floating point coprocessor to use by default. */
98 static enum m68k_register m68k_float_copnum
= COP1
;
100 /* If this is non-zero, then references to number(%pc) will be taken
101 to refer to number, rather than to %pc + number. */
102 static int m68k_abspcadd
;
104 /* If this is non-zero, then the quick forms of the move, add, and sub
105 instructions are used when possible. */
106 static int m68k_quick
= 1;
108 /* If this is non-zero, then if the size is not specified for a base
109 or outer displacement, the assembler assumes that the size should
111 static int m68k_rel32
= 1;
113 /* This is non-zero if m68k_rel32 was set from the command line. */
114 static int m68k_rel32_from_cmdline
;
116 /* The default width to use for an index register when using a base
118 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
120 /* We want to warn if any text labels are misaligned. In order to get
121 the right line number, we need to record the line number for each
125 struct label_line
*next
;
132 /* The list of labels. */
134 static struct label_line
*labels
;
136 /* The current label. */
138 static struct label_line
*current_label
;
140 /* Pointer to list holding the opcodes sorted by name. */
141 static struct m68k_opcode
const ** m68k_sorted_opcodes
;
143 /* Its an arbitrary name: This means I don't approve of it.
145 static struct obstack robyn
;
149 const char *m_operands
;
150 unsigned long m_opcode
;
154 struct m68k_incant
*m_next
;
157 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
158 #define gettwo(x) (((x)->m_opcode)&0xffff)
160 static const enum m68k_register m68000_ctrl
[] = { 0 };
161 static const enum m68k_register m68010_ctrl
[] = {
165 static const enum m68k_register m68020_ctrl
[] = {
166 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
169 static const enum m68k_register m68040_ctrl
[] = {
170 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
171 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
174 static const enum m68k_register m68060_ctrl
[] = {
175 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
176 USP
, VBR
, URP
, SRP
, PCR
,
179 static const enum m68k_register mcf_ctrl
[] = {
180 CACR
, TC
, ACR0
, ACR1
, ACR2
, ACR3
, VBR
, ROMBAR
,
181 RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
,
184 static const enum m68k_register mcf51qe_ctrl
[] = {
188 static const enum m68k_register mcf5206_ctrl
[] = {
189 CACR
, ACR0
, ACR1
, VBR
, RAMBAR0
, RAMBAR_ALT
, MBAR
,
192 static const enum m68k_register mcf5208_ctrl
[] = {
193 CACR
, ACR0
, ACR1
, VBR
, RAMBAR
, RAMBAR1
,
196 static const enum m68k_register mcf5210a_ctrl
[] = {
197 VBR
, CACR
, ACR0
, ACR1
, ROMBAR
, RAMBAR
, RAMBAR1
, MBAR
,
200 static const enum m68k_register mcf5213_ctrl
[] = {
201 VBR
, RAMBAR
, RAMBAR1
, FLASHBAR
,
204 static const enum m68k_register mcf5216_ctrl
[] = {
205 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
208 static const enum m68k_register mcf52223_ctrl
[] = {
209 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
212 static const enum m68k_register mcf52235_ctrl
[] = {
213 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
216 static const enum m68k_register mcf5225_ctrl
[] = {
217 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, MBAR
, RAMBAR1
,
220 static const enum m68k_register mcf5235_ctrl
[] = {
221 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
224 static const enum m68k_register mcf5249_ctrl
[] = {
225 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
, MBAR2
,
228 static const enum m68k_register mcf5250_ctrl
[] = {
232 static const enum m68k_register mcf5253_ctrl
[] = {
233 VBR
, CACR
, ACR0
, ACR1
, RAMBAR0
, RAMBAR1
, RAMBAR
, MBAR
, MBAR2
,
236 static const enum m68k_register mcf5271_ctrl
[] = {
237 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
240 static const enum m68k_register mcf5272_ctrl
[] = {
241 VBR
, CACR
, ACR0
, ACR1
, ROMBAR
, RAMBAR_ALT
, RAMBAR0
, MBAR
,
244 static const enum m68k_register mcf5275_ctrl
[] = {
245 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
248 static const enum m68k_register mcf5282_ctrl
[] = {
249 VBR
, CACR
, ACR0
, ACR1
, FLASHBAR
, RAMBAR
, RAMBAR1
,
252 static const enum m68k_register mcf5307_ctrl
[] = {
253 CACR
, ACR0
, ACR1
, VBR
, RAMBAR0
, RAMBAR_ALT
, MBAR
,
256 static const enum m68k_register mcf5329_ctrl
[] = {
257 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
260 static const enum m68k_register mcf5373_ctrl
[] = {
261 VBR
, CACR
, ACR0
, ACR1
, RAMBAR
, RAMBAR1
,
264 static const enum m68k_register mcfv4e_ctrl
[] = {
265 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
266 VBR
, PC
, ROMBAR0
, ROMBAR1
, RAMBAR0
, RAMBAR1
,
268 MPCR
/* Multiprocessor Control register */,
269 EDRAMBAR
/* Embedded DRAM Base Address Register */,
270 /* Permutation control registers. */
271 PCR1U0
, PCR1L0
, PCR1U1
, PCR1L1
, PCR2U0
, PCR2L0
, PCR2U1
, PCR2L1
,
272 PCR3U0
, PCR3L0
, PCR3U1
, PCR3L1
,
274 TC
/* ASID */, BUSCR
/* MMUBAR */,
275 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
276 MBAR1
/* MBAR */, MBAR2
/* SECMBAR */, MBAR0
/* SECMBAR */,
277 ROMBAR
/* ROMBAR0 */, RAMBAR
/* RAMBAR1 */,
280 static const enum m68k_register mcf5407_ctrl
[] = {
281 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
,
282 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
285 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
286 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
289 static const enum m68k_register mcf54455_ctrl
[] = {
290 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
291 VBR
, PC
, RAMBAR1
, MBAR
,
293 TC
/* ASID */, BUSCR
/* MMUBAR */,
294 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
295 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
298 static const enum m68k_register mcf5475_ctrl
[] = {
299 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
300 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
302 TC
/* ASID */, BUSCR
/* MMUBAR */,
303 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
304 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
307 static const enum m68k_register mcf5485_ctrl
[] = {
308 CACR
, ASID
, ACR0
, ACR1
, ACR2
, ACR3
, MMUBAR
,
309 VBR
, PC
, RAMBAR0
, RAMBAR1
, MBAR
,
311 TC
/* ASID */, BUSCR
/* MMUBAR */,
312 ITT0
/* ACR0 */, ITT1
/* ACR1 */, DTT0
/* ACR2 */, DTT1
/* ACR3 */,
313 MBAR1
/* MBAR */, RAMBAR
/* RAMBAR1 */,
316 static const enum m68k_register fido_ctrl
[] = {
317 SFC
, DFC
, USP
, VBR
, CAC
, MBO
,
320 #define cpu32_ctrl m68010_ctrl
322 static const enum m68k_register
*control_regs
;
324 /* Internal form of a 68020 instruction. */
328 const char *args
; /* List of opcode info. */
331 int numo
; /* Number of shorts in opcode. */
334 struct m68k_op operands
[6];
336 int nexp
; /* Number of exprs in use. */
337 struct m68k_exp exprs
[4];
339 int nfrag
; /* Number of frags we have to produce. */
342 int fragoff
; /* Where in the current opcode the frag ends. */
349 int nrel
; /* Num of reloc strucs in use. */
356 /* In a pc relative address the difference between the address
357 of the offset and the address that the offset is relative
358 to. This depends on the addressing mode. Basically this
359 is the value to put in the offset field to address the
360 first byte of the offset, without regarding the special
361 significance of some values (in the branch instruction, for
365 /* Whether this expression needs special pic relocation, and if
367 enum pic_relocation pic_reloc
;
370 reloc
[5]; /* Five is enough??? */
373 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a | fido_a))
374 #define float_of_arch(x) ((x) & mfloat)
375 #define mmu_of_arch(x) ((x) & mmmu)
376 #define arch_coldfire_p(x) ((x) & mcfisa_a)
377 #define arch_coldfire_fpu(x) ((x) & cfloat)
379 /* Macros for determining if cpu supports a specific addressing mode. */
380 #define HAVE_LONG_DISP(x) \
381 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
382 #define HAVE_LONG_CALL(x) \
383 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
384 #define HAVE_LONG_COND(x) \
385 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
386 #define HAVE_LONG_BRANCH(x) \
387 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b))
388 #define LONG_BRANCH_VIA_COND(x) (HAVE_LONG_COND(x) && !HAVE_LONG_BRANCH(x))
390 static struct m68k_it the_ins
; /* The instruction being assembled. */
392 #define op(ex) ((ex)->exp.X_op)
393 #define adds(ex) ((ex)->exp.X_add_symbol)
394 #define subs(ex) ((ex)->exp.X_op_symbol)
395 #define offs(ex) ((ex)->exp.X_add_number)
397 /* Macros for adding things to the m68k_it struct. */
398 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
400 /* Like addword, but goes BEFORE general operands. */
403 insop (int w
, const struct m68k_incant
*opcode
)
406 for (z
= the_ins
.numo
; z
> opcode
->m_codenum
; --z
)
407 the_ins
.opcode
[z
] = the_ins
.opcode
[z
- 1];
408 for (z
= 0; z
< the_ins
.nrel
; z
++)
409 the_ins
.reloc
[z
].n
+= 2;
410 for (z
= 0; z
< the_ins
.nfrag
; z
++)
411 the_ins
.fragb
[z
].fragoff
++;
412 the_ins
.opcode
[opcode
->m_codenum
] = w
;
416 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
419 add_fix (int width
, struct m68k_exp
*exp
, int pc_rel
, int pc_fix
)
421 the_ins
.reloc
[the_ins
.nrel
].n
= (width
== 'B' || width
== '3'
422 ? the_ins
.numo
* 2 - 1
424 ? the_ins
.numo
* 2 + 1
425 : the_ins
.numo
* 2));
426 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
427 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
428 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
430 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
432 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
435 /* Cause an extra frag to be generated here, inserting up to 10 bytes
436 (that value is chosen in the frag_var call in md_assemble). TYPE
437 is the subtype of the frag to be generated; its primary type is
438 rs_machine_dependent.
440 The TYPE parameter is also used by md_convert_frag_1 and
441 md_estimate_size_before_relax. The appropriate type of fixup will
442 be emitted by md_convert_frag_1.
444 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
446 add_frag (symbolS
*add
, offsetT off
, int type
)
448 the_ins
.fragb
[the_ins
.nfrag
].fragoff
= the_ins
.numo
;
449 the_ins
.fragb
[the_ins
.nfrag
].fadd
= add
;
450 the_ins
.fragb
[the_ins
.nfrag
].foff
= off
;
451 the_ins
.fragb
[the_ins
.nfrag
++].fragty
= type
;
455 (op (ex) != O_constant && op (ex) != O_big)
457 static char *crack_operand (char *str
, struct m68k_op
*opP
);
458 static int get_num (struct m68k_exp
*exp
, int ok
);
459 static int reverse_16_bits (int in
);
460 static int reverse_8_bits (int in
);
461 static void install_gen_operand (int mode
, int val
);
462 static void install_operand (int mode
, int val
);
463 static void s_bss (int);
464 static void s_data1 (int);
465 static void s_data2 (int);
466 static void s_even (int);
467 static void s_proc (int);
468 static void s_chip (int);
469 static void s_fopt (int);
470 static void s_opt (int);
471 static void s_reg (int);
472 static void s_restore (int);
473 static void s_save (int);
474 static void s_mri_if (int);
475 static void s_mri_else (int);
476 static void s_mri_endi (int);
477 static void s_mri_break (int);
478 static void s_mri_next (int);
479 static void s_mri_for (int);
480 static void s_mri_endf (int);
481 static void s_mri_repeat (int);
482 static void s_mri_until (int);
483 static void s_mri_while (int);
484 static void s_mri_endw (int);
485 static void s_m68k_cpu (int);
486 static void s_m68k_arch (int);
490 unsigned long arch
; /* Architecture features. */
491 const enum m68k_register
*control_regs
; /* Control regs on chip */
492 const char *name
; /* Name */
493 int alias
; /* Alias for a cannonical name. If 1, then
494 succeeds canonical name, if -1 then
495 succeeds canonical name, if <-1 ||>1 this is a
496 deprecated name, and the next/previous name
500 /* We hold flags for features explicitly enabled and explicitly
502 static int current_architecture
;
503 static int not_current_architecture
;
504 static const struct m68k_cpu
*selected_arch
;
505 static const struct m68k_cpu
*selected_cpu
;
506 static int initialized
;
508 /* Architecture models. */
509 static const struct m68k_cpu m68k_archs
[] =
511 {m68000
, m68000_ctrl
, "68000", 0},
512 {m68010
, m68010_ctrl
, "68010", 0},
513 {m68020
|m68881
|m68851
, m68020_ctrl
, "68020", 0},
514 {m68030
|m68881
|m68851
, m68020_ctrl
, "68030", 0},
515 {m68040
, m68040_ctrl
, "68040", 0},
516 {m68060
, m68060_ctrl
, "68060", 0},
517 {cpu32
|m68881
, cpu32_ctrl
, "cpu32", 0},
518 {fido_a
, fido_ctrl
, "fidoa", 0},
519 {mcfisa_a
|mcfhwdiv
, NULL
, "isaa", 0},
520 {mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfusp
, NULL
, "isaaplus", 0},
521 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfusp
, NULL
, "isab", 0},
522 {mcfisa_a
|mcfhwdiv
|mcfisa_c
|mcfusp
, NULL
, "isac", 0},
523 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
|mcfusp
, mcf_ctrl
, "cfv4", 0},
524 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcfv4e_ctrl
, "cfv4e", 0},
528 /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
530 static const struct m68k_cpu m68k_extensions
[] =
532 {m68851
, NULL
, "68851", -1},
533 {m68881
, NULL
, "68881", -1},
534 {m68881
, NULL
, "68882", -1},
536 {cfloat
|m68881
, NULL
, "float", 0},
538 {mcfhwdiv
, NULL
, "div", 1},
539 {mcfusp
, NULL
, "usp", 1},
540 {mcfmac
, NULL
, "mac", 1},
541 {mcfemac
, NULL
, "emac", 1},
547 static const struct m68k_cpu m68k_cpus
[] =
549 {m68000
, m68000_ctrl
, "68000", 0},
550 {m68000
, m68000_ctrl
, "68ec000", 1},
551 {m68000
, m68000_ctrl
, "68hc000", 1},
552 {m68000
, m68000_ctrl
, "68hc001", 1},
553 {m68000
, m68000_ctrl
, "68008", 1},
554 {m68000
, m68000_ctrl
, "68302", 1},
555 {m68000
, m68000_ctrl
, "68306", 1},
556 {m68000
, m68000_ctrl
, "68307", 1},
557 {m68000
, m68000_ctrl
, "68322", 1},
558 {m68000
, m68000_ctrl
, "68356", 1},
559 {m68010
, m68010_ctrl
, "68010", 0},
560 {m68020
|m68881
|m68851
, m68020_ctrl
, "68020", 0},
561 {m68020
|m68881
|m68851
, m68020_ctrl
, "68k", 1},
562 {m68020
|m68881
|m68851
, m68020_ctrl
, "68ec020", 1},
563 {m68030
|m68881
|m68851
, m68020_ctrl
, "68030", 0},
564 {m68030
|m68881
|m68851
, m68020_ctrl
, "68ec030", 1},
565 {m68040
, m68040_ctrl
, "68040", 0},
566 {m68040
, m68040_ctrl
, "68ec040", 1},
567 {m68060
, m68060_ctrl
, "68060", 0},
568 {m68060
, m68060_ctrl
, "68ec060", 1},
570 {cpu32
|m68881
, cpu32_ctrl
, "cpu32", 0},
571 {cpu32
|m68881
, cpu32_ctrl
, "68330", 1},
572 {cpu32
|m68881
, cpu32_ctrl
, "68331", 1},
573 {cpu32
|m68881
, cpu32_ctrl
, "68332", 1},
574 {cpu32
|m68881
, cpu32_ctrl
, "68333", 1},
575 {cpu32
|m68881
, cpu32_ctrl
, "68334", 1},
576 {cpu32
|m68881
, cpu32_ctrl
, "68336", 1},
577 {cpu32
|m68881
, cpu32_ctrl
, "68340", 1},
578 {cpu32
|m68881
, cpu32_ctrl
, "68341", 1},
579 {cpu32
|m68881
, cpu32_ctrl
, "68349", 1},
580 {cpu32
|m68881
, cpu32_ctrl
, "68360", 1},
582 {mcfisa_a
|mcfisa_c
|mcfusp
, mcf51qe_ctrl
, "51qe", 0},
584 {mcfisa_a
, mcf_ctrl
, "5200", 0},
585 {mcfisa_a
, mcf_ctrl
, "5202", 1},
586 {mcfisa_a
, mcf_ctrl
, "5204", 1},
587 {mcfisa_a
, mcf5206_ctrl
, "5206", 1},
589 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5206_ctrl
, "5206e", 0},
591 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5208_ctrl
, "5207", -1},
592 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5208_ctrl
, "5208", 0},
594 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5210a_ctrl
, "5210a", 0},
595 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5210a_ctrl
, "5211a", 1},
597 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5211", -1},
598 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5212", -1},
599 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5213_ctrl
, "5213", 0},
601 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "5214", -1},
602 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "5216", 0},
603 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5216_ctrl
, "521x", 2},
605 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf52223_ctrl
, "52221", -1},
606 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf52223_ctrl
, "52223", 0},
608 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52230", -1},
609 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52233", -1},
610 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52234", -1},
611 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf52235_ctrl
, "52235", 0},
613 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5225_ctrl
, "5224", -1},
614 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
|mcfusp
, mcf5225_ctrl
, "5225", 0},
616 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5232", -1},
617 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5233", -1},
618 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5234", -1},
619 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "5235", -1},
620 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5235_ctrl
, "523x", 0},
622 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5249_ctrl
, "5249", 0},
623 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5250_ctrl
, "5250", 0},
624 {mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5253_ctrl
, "5253", 0},
626 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5271_ctrl
, "5270", -1},
627 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5271_ctrl
, "5271", 0},
629 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5272_ctrl
, "5272", 0},
631 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5275_ctrl
, "5274", -1},
632 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5275_ctrl
, "5275", 0},
634 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5280", -1},
635 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5281", -1},
636 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "5282", -1},
637 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5282_ctrl
, "528x", 0},
639 {mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5307_ctrl
, "5307", 0},
641 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5327", -1},
642 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5328", -1},
643 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "5329", -1},
644 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5329_ctrl
, "532x", 0},
646 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "5372", -1},
647 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "5373", -1},
648 {mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf5373_ctrl
, "537x", 0},
650 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfmac
, mcf5407_ctrl
, "5407",0},
652 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54450", -1},
653 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54451", -1},
654 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54452", -1},
655 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54453", -1},
656 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54454", -1},
657 {mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfemac
|mcfusp
, mcf54455_ctrl
, "54455", 0},
659 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5470", -1},
660 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5471", -1},
661 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5472", -1},
662 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5473", -1},
663 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5474", -1},
664 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "5475", -1},
665 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5475_ctrl
, "547x", 0},
667 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5480", -1},
668 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5481", -1},
669 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5482", -1},
670 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5483", -1},
671 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5484", -1},
672 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "5485", -1},
673 {mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfemac
|mcfusp
|cfloat
, mcf5485_ctrl
, "548x", 0},
675 {fido_a
, fido_ctrl
, "fidoa", 0},
676 {fido_a
, fido_ctrl
, "fido", 1},
681 static const struct m68k_cpu
*m68k_lookup_cpu
682 (const char *, const struct m68k_cpu
*, int, int *);
683 static int m68k_set_arch (const char *, int, int);
684 static int m68k_set_cpu (const char *, int, int);
685 static int m68k_set_extension (const char *, int, int);
686 static void m68k_init_arch (void);
688 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
689 architecture and we have a lot of relaxation modes. */
691 /* Macros used in the relaxation code. */
692 #define TAB(x,y) (((x) << 2) + (y))
693 #define TABTYPE(x) ((x) >> 2)
695 /* Relaxation states. */
701 /* Here are all the relaxation modes we support. First we can relax ordinary
702 branches. On 68020 and higher and on CPU32 all branch instructions take
703 three forms, so on these CPUs all branches always remain as such. When we
704 have to expand to the LONG form on a 68000, though, we substitute an
705 absolute jump instead. This is a direct replacement for unconditional
706 branches and a branch over a jump for conditional branches. However, if the
707 user requires PIC and disables this with --pcrel, we can only relax between
708 BYTE and SHORT forms, punting if that isn't enough. This gives us four
709 different relaxation modes for branches: */
711 #define BRANCHBWL 0 /* Branch byte, word, or long. */
712 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
713 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
714 #define BRANCHBW 3 /* Branch byte or word. */
716 /* We also relax coprocessor branches and DBcc's. All CPUs that support
717 coprocessor branches support them in word and long forms, so we have only
718 one relaxation mode for them. DBcc's are word only on all CPUs. We can
719 relax them to the LONG form with a branch-around sequence. This sequence
720 can use a long branch (if available) or an absolute jump (if acceptable).
721 This gives us two relaxation modes. If long branches are not available and
722 absolute jumps are not acceptable, we don't relax DBcc's. */
724 #define FBRANCH 4 /* Coprocessor branch. */
725 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
726 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
728 /* That's all for instruction relaxation. However, we also relax PC-relative
729 operands. Specifically, we have three operand relaxation modes. On the
730 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
731 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
732 two. Also PC+displacement+index operands in their simple form (with a non-
733 suppressed index without memory indirection) are supported on all CPUs, but
734 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
735 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
736 form of the PC+displacement+index operand. Finally, some absolute operands
737 can be relaxed down to 16-bit PC-relative. */
739 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
740 #define PCINDEX 8 /* PC + displacement + index. */
741 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
743 /* This relaxation is required for branches where there is no long
744 branch and we are in pcrel mode. We generate a bne/beq pair. */
745 #define BRANCHBWPL 10 /* Branch byte, word or pair of longs
748 /* Note that calls to frag_var need to specify the maximum expansion
749 needed; this is currently 12 bytes for bne/beq pair. */
750 #define FRAG_VAR_SIZE 12
753 How far Forward this mode will reach:
754 How far Backward this mode will reach:
755 How many bytes this mode will add to the size of the frag
756 Which mode to go to if the offset won't fit in this one
758 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
759 relax_typeS md_relax_table
[] =
761 { 127, -128, 0, TAB (BRANCHBWL
, SHORT
) },
762 { 32767, -32768, 2, TAB (BRANCHBWL
, LONG
) },
766 { 127, -128, 0, TAB (BRABSJUNC
, SHORT
) },
767 { 32767, -32768, 2, TAB (BRABSJUNC
, LONG
) },
771 { 127, -128, 0, TAB (BRABSJCOND
, SHORT
) },
772 { 32767, -32768, 2, TAB (BRABSJCOND
, LONG
) },
776 { 127, -128, 0, TAB (BRANCHBW
, SHORT
) },
781 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
782 { 32767, -32768, 2, TAB (FBRANCH
, LONG
) },
786 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
787 { 32767, -32768, 2, TAB (DBCCLBR
, LONG
) },
791 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
792 { 32767, -32768, 2, TAB (DBCCABSJ
, LONG
) },
796 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
797 { 32767, -32768, 2, TAB (PCREL1632
, LONG
) },
801 { 125, -130, 0, TAB (PCINDEX
, SHORT
) },
802 { 32765, -32770, 2, TAB (PCINDEX
, LONG
) },
806 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
807 { 32767, -32768, 2, TAB (ABSTOPCREL
, LONG
) },
811 { 127, -128, 0, TAB (BRANCHBWPL
, SHORT
) },
812 { 32767, -32768, 2, TAB (BRANCHBWPL
, LONG
) },
817 /* These are the machine dependent pseudo-ops. These are included so
818 the assembler can work on the output from the SUN C compiler, which
821 /* This table describes all the machine specific pseudo-ops the assembler
822 has to support. The fields are:
823 pseudo-op name without dot
824 function to call to execute this pseudo-op
825 Integer arg to pass to the function. */
826 const pseudo_typeS md_pseudo_table
[] =
828 {"data1", s_data1
, 0},
829 {"data2", s_data2
, 0},
832 {"skip", s_space
, 0},
834 #if defined (TE_SUN3) || defined (OBJ_ELF)
835 {"align", s_align_bytes
, 0},
838 {"swbeg", s_ignore
, 0},
839 {"long", m68k_elf_cons
, 4},
841 {"extend", float_cons
, 'x'},
842 {"ldouble", float_cons
, 'x'},
844 {"arch", s_m68k_arch
, 0},
845 {"cpu", s_m68k_cpu
, 0},
847 /* The following pseudo-ops are supported for MRI compatibility. */
849 {"comline", s_space
, 1},
851 {"mask2", s_ignore
, 0},
854 {"restore", s_restore
, 0},
858 {"if.b", s_mri_if
, 'b'},
859 {"if.w", s_mri_if
, 'w'},
860 {"if.l", s_mri_if
, 'l'},
861 {"else", s_mri_else
, 0},
862 {"else.s", s_mri_else
, 's'},
863 {"else.l", s_mri_else
, 'l'},
864 {"endi", s_mri_endi
, 0},
865 {"break", s_mri_break
, 0},
866 {"break.s", s_mri_break
, 's'},
867 {"break.l", s_mri_break
, 'l'},
868 {"next", s_mri_next
, 0},
869 {"next.s", s_mri_next
, 's'},
870 {"next.l", s_mri_next
, 'l'},
871 {"for", s_mri_for
, 0},
872 {"for.b", s_mri_for
, 'b'},
873 {"for.w", s_mri_for
, 'w'},
874 {"for.l", s_mri_for
, 'l'},
875 {"endf", s_mri_endf
, 0},
876 {"repeat", s_mri_repeat
, 0},
877 {"until", s_mri_until
, 0},
878 {"until.b", s_mri_until
, 'b'},
879 {"until.w", s_mri_until
, 'w'},
880 {"until.l", s_mri_until
, 'l'},
881 {"while", s_mri_while
, 0},
882 {"while.b", s_mri_while
, 'b'},
883 {"while.w", s_mri_while
, 'w'},
884 {"while.l", s_mri_while
, 'l'},
885 {"endw", s_mri_endw
, 0},
890 /* The mote pseudo ops are put into the opcode table, since they
891 don't start with a . they look like opcodes to gas. */
893 const pseudo_typeS mote_pseudo_table
[] =
906 {"xdef", s_globl
, 0},
908 {"align", s_align_bytes
, 0},
910 {"align", s_align_ptwo
, 0},
913 {"sect", obj_coff_section
, 0},
914 {"section", obj_coff_section
, 0},
919 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
920 gives identical results to a 32-bit host. */
921 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
922 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
924 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
925 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
926 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
927 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
929 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
930 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
931 #define islong(x) (1)
933 static char notend_table
[256];
934 static char alt_notend_table
[256];
936 (! (notend_table[(unsigned char) *s] \
938 && alt_notend_table[(unsigned char) s[1]])))
942 /* Return zero if the reference to SYMBOL from within the same segment may
945 /* On an ELF system, we can't relax an externally visible symbol,
946 because it may be overridden by a shared library. However, if
947 TARGET_OS is "elf", then we presume that we are assembling for an
948 embedded system, in which case we don't have to worry about shared
949 libraries, and we can relax any external sym. */
951 #define relaxable_symbol(symbol) \
952 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
953 || S_IS_WEAK (symbol)))
955 /* Compute the relocation code for a fixup of SIZE bytes, using pc
956 relative relocation if PCREL is non-zero. PIC says whether a special
957 pic relocation was requested. */
959 static bfd_reloc_code_real_type
960 get_reloc_code (int size
, int pcrel
, enum pic_relocation pic
)
968 return BFD_RELOC_8_GOT_PCREL
;
970 return BFD_RELOC_16_GOT_PCREL
;
972 return BFD_RELOC_32_GOT_PCREL
;
980 return BFD_RELOC_8_GOTOFF
;
982 return BFD_RELOC_16_GOTOFF
;
984 return BFD_RELOC_32_GOTOFF
;
992 return BFD_RELOC_8_PLT_PCREL
;
994 return BFD_RELOC_16_PLT_PCREL
;
996 return BFD_RELOC_32_PLT_PCREL
;
1004 return BFD_RELOC_8_PLTOFF
;
1006 return BFD_RELOC_16_PLTOFF
;
1008 return BFD_RELOC_32_PLTOFF
;
1016 return BFD_RELOC_68K_TLS_GD8
;
1018 return BFD_RELOC_68K_TLS_GD16
;
1020 return BFD_RELOC_68K_TLS_GD32
;
1028 return BFD_RELOC_68K_TLS_LDM8
;
1030 return BFD_RELOC_68K_TLS_LDM16
;
1032 return BFD_RELOC_68K_TLS_LDM32
;
1040 return BFD_RELOC_68K_TLS_LDO8
;
1042 return BFD_RELOC_68K_TLS_LDO16
;
1044 return BFD_RELOC_68K_TLS_LDO32
;
1052 return BFD_RELOC_68K_TLS_IE8
;
1054 return BFD_RELOC_68K_TLS_IE16
;
1056 return BFD_RELOC_68K_TLS_IE32
;
1064 return BFD_RELOC_68K_TLS_LE8
;
1066 return BFD_RELOC_68K_TLS_LE16
;
1068 return BFD_RELOC_68K_TLS_LE32
;
1078 return BFD_RELOC_8_PCREL
;
1080 return BFD_RELOC_16_PCREL
;
1082 return BFD_RELOC_32_PCREL
;
1092 return BFD_RELOC_16
;
1094 return BFD_RELOC_32
;
1101 if (pic
== pic_none
)
1102 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
1104 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
1108 if (pic
== pic_none
)
1109 as_bad (_("Can not do %d byte relocation"), size
);
1111 as_bad (_("Can not do %d byte pic relocation"), size
);
1114 return BFD_RELOC_NONE
;
1117 /* Here we decide which fixups can be adjusted to make them relative
1118 to the beginning of the section instead of the symbol. Basically
1119 we need to make sure that the dynamic relocations are done
1120 correctly, so in some cases we force the original symbol to be
1123 tc_m68k_fix_adjustable (fixS
*fixP
)
1125 /* Adjust_reloc_syms doesn't know about the GOT. */
1126 switch (fixP
->fx_r_type
)
1128 case BFD_RELOC_8_GOT_PCREL
:
1129 case BFD_RELOC_16_GOT_PCREL
:
1130 case BFD_RELOC_32_GOT_PCREL
:
1131 case BFD_RELOC_8_GOTOFF
:
1132 case BFD_RELOC_16_GOTOFF
:
1133 case BFD_RELOC_32_GOTOFF
:
1134 case BFD_RELOC_8_PLT_PCREL
:
1135 case BFD_RELOC_16_PLT_PCREL
:
1136 case BFD_RELOC_32_PLT_PCREL
:
1137 case BFD_RELOC_8_PLTOFF
:
1138 case BFD_RELOC_16_PLTOFF
:
1139 case BFD_RELOC_32_PLTOFF
:
1140 case BFD_RELOC_68K_TLS_GD32
:
1141 case BFD_RELOC_68K_TLS_GD16
:
1142 case BFD_RELOC_68K_TLS_GD8
:
1143 case BFD_RELOC_68K_TLS_LDM32
:
1144 case BFD_RELOC_68K_TLS_LDM16
:
1145 case BFD_RELOC_68K_TLS_LDM8
:
1146 case BFD_RELOC_68K_TLS_LDO32
:
1147 case BFD_RELOC_68K_TLS_LDO16
:
1148 case BFD_RELOC_68K_TLS_LDO8
:
1149 case BFD_RELOC_68K_TLS_IE32
:
1150 case BFD_RELOC_68K_TLS_IE16
:
1151 case BFD_RELOC_68K_TLS_IE8
:
1152 case BFD_RELOC_68K_TLS_LE32
:
1153 case BFD_RELOC_68K_TLS_LE16
:
1154 case BFD_RELOC_68K_TLS_LE8
:
1157 case BFD_RELOC_VTABLE_INHERIT
:
1158 case BFD_RELOC_VTABLE_ENTRY
:
1166 #else /* !OBJ_ELF */
1168 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
1170 /* PR gas/3041 Weak symbols are not relaxable
1171 because they must be treated as extern. */
1172 #define relaxable_symbol(symbol) (!(S_IS_WEAK (symbol)))
1174 #endif /* OBJ_ELF */
1177 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
1180 bfd_reloc_code_real_type code
;
1182 /* If the tcbit is set, then this was a fixup of a negative value
1183 that was never resolved. We do not have a reloc to handle this,
1184 so just return. We assume that other code will have detected this
1185 situation and produced a helpful error message, so we just tell the
1186 user that the reloc cannot be produced. */
1190 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1191 _("Unable to produce reloc against symbol '%s'"),
1192 S_GET_NAME (fixp
->fx_addsy
));
1196 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
1198 code
= fixp
->fx_r_type
;
1200 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1201 that fixup_segment converted a non-PC relative reloc into a
1202 PC relative reloc. In such a case, we need to convert the
1209 code
= BFD_RELOC_8_PCREL
;
1212 code
= BFD_RELOC_16_PCREL
;
1215 code
= BFD_RELOC_32_PCREL
;
1217 case BFD_RELOC_8_PCREL
:
1218 case BFD_RELOC_16_PCREL
:
1219 case BFD_RELOC_32_PCREL
:
1220 case BFD_RELOC_8_GOT_PCREL
:
1221 case BFD_RELOC_16_GOT_PCREL
:
1222 case BFD_RELOC_32_GOT_PCREL
:
1223 case BFD_RELOC_8_GOTOFF
:
1224 case BFD_RELOC_16_GOTOFF
:
1225 case BFD_RELOC_32_GOTOFF
:
1226 case BFD_RELOC_8_PLT_PCREL
:
1227 case BFD_RELOC_16_PLT_PCREL
:
1228 case BFD_RELOC_32_PLT_PCREL
:
1229 case BFD_RELOC_8_PLTOFF
:
1230 case BFD_RELOC_16_PLTOFF
:
1231 case BFD_RELOC_32_PLTOFF
:
1232 case BFD_RELOC_68K_TLS_GD32
:
1233 case BFD_RELOC_68K_TLS_GD16
:
1234 case BFD_RELOC_68K_TLS_GD8
:
1235 case BFD_RELOC_68K_TLS_LDM32
:
1236 case BFD_RELOC_68K_TLS_LDM16
:
1237 case BFD_RELOC_68K_TLS_LDM8
:
1238 case BFD_RELOC_68K_TLS_LDO32
:
1239 case BFD_RELOC_68K_TLS_LDO16
:
1240 case BFD_RELOC_68K_TLS_LDO8
:
1241 case BFD_RELOC_68K_TLS_IE32
:
1242 case BFD_RELOC_68K_TLS_IE16
:
1243 case BFD_RELOC_68K_TLS_IE8
:
1244 case BFD_RELOC_68K_TLS_LE32
:
1245 case BFD_RELOC_68K_TLS_LE16
:
1246 case BFD_RELOC_68K_TLS_LE8
:
1249 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1250 _("Cannot make %s relocation PC relative"),
1251 bfd_get_reloc_code_name (code
));
1257 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1258 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1260 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1261 MAP (1, 0, BFD_RELOC_8
);
1262 MAP (2, 0, BFD_RELOC_16
);
1263 MAP (4, 0, BFD_RELOC_32
);
1264 MAP (1, 1, BFD_RELOC_8_PCREL
);
1265 MAP (2, 1, BFD_RELOC_16_PCREL
);
1266 MAP (4, 1, BFD_RELOC_32_PCREL
);
1274 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1275 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1276 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1277 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1280 reloc
->addend
= fixp
->fx_addnumber
;
1281 else if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
1283 && S_IS_WEAK (fixp
->fx_addsy
)
1284 && ! bfd_is_und_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
1285 /* PR gas/3041 Adjust addend in order to force bfd_install_relocation()
1286 to put the symbol offset into frags referencing a weak symbol. */
1287 reloc
->addend
= fixp
->fx_addnumber
1288 - (S_GET_VALUE (fixp
->fx_addsy
) * 2);
1292 if (!fixp
->fx_pcrel
)
1293 reloc
->addend
= fixp
->fx_addnumber
;
1295 reloc
->addend
= (section
->vma
1296 /* Explicit sign extension in case char is
1298 + ((fixp
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80
1299 + fixp
->fx_addnumber
1300 + md_pcrel_from (fixp
));
1303 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1304 assert (reloc
->howto
!= 0);
1309 /* Handle of the OPCODE hash table. NULL means any use before
1310 m68k_ip_begin() will crash. */
1311 static struct hash_control
*op_hash
;
1313 /* Assemble an m68k instruction. */
1316 m68k_ip (char *instring
)
1319 register struct m68k_op
*opP
;
1320 register const struct m68k_incant
*opcode
;
1321 register const char *s
;
1322 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1323 char *pdot
, *pdotmove
;
1324 enum m68k_size siz1
, siz2
;
1328 struct m68k_op operands_backup
[6];
1329 LITTLENUM_TYPE words
[6];
1330 LITTLENUM_TYPE
*wordp
;
1331 unsigned long ok_arch
= 0;
1333 if (*instring
== ' ')
1334 instring
++; /* Skip leading whitespace. */
1336 /* Scan up to end of operation-code, which MUST end in end-of-string
1337 or exactly 1 space. */
1339 for (p
= instring
; *p
!= '\0'; p
++)
1349 the_ins
.error
= _("No operator");
1353 /* p now points to the end of the opcode name, probably whitespace.
1354 Make sure the name is null terminated by clobbering the
1355 whitespace, look it up in the hash table, then fix it back.
1356 Remove a dot, first, since the opcode tables have none. */
1359 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1360 *pdotmove
= pdotmove
[1];
1366 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1371 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1372 *pdotmove
= pdotmove
[-1];
1379 the_ins
.error
= _("Unknown operator");
1383 /* Found a legitimate opcode, start matching operands. */
1387 if (opcode
->m_operands
== 0)
1389 char *old
= input_line_pointer
;
1391 input_line_pointer
= p
;
1392 /* Ahh - it's a motorola style psuedo op. */
1393 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1394 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1395 input_line_pointer
= old
;
1401 if (flag_mri
&& opcode
->m_opnum
== 0)
1403 /* In MRI mode, random garbage is allowed after an instruction
1404 which accepts no operands. */
1405 the_ins
.args
= opcode
->m_operands
;
1406 the_ins
.numargs
= opcode
->m_opnum
;
1407 the_ins
.numo
= opcode
->m_codenum
;
1408 the_ins
.opcode
[0] = getone (opcode
);
1409 the_ins
.opcode
[1] = gettwo (opcode
);
1413 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1415 p
= crack_operand (p
, opP
);
1419 the_ins
.error
= opP
->error
;
1424 opsfound
= opP
- &the_ins
.operands
[0];
1426 /* This ugly hack is to support the floating pt opcodes in their
1427 standard form. Essentially, we fake a first enty of type COP#1 */
1428 if (opcode
->m_operands
[0] == 'I')
1432 for (n
= opsfound
; n
> 0; --n
)
1433 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1435 memset (&the_ins
.operands
[0], '\0', sizeof (the_ins
.operands
[0]));
1436 the_ins
.operands
[0].mode
= CONTROL
;
1437 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1441 /* We've got the operands. Find an opcode that'll accept them. */
1444 /* If we didn't get the right number of ops, or we have no
1445 common model with this pattern then reject this pattern. */
1447 ok_arch
|= opcode
->m_arch
;
1448 if (opsfound
!= opcode
->m_opnum
1449 || ((opcode
->m_arch
& current_architecture
) == 0))
1455 /* Make a copy of the operands of this insn so that
1456 we can modify them safely, should we want to. */
1457 assert (opsfound
<= (int) ARRAY_SIZE (operands_backup
));
1458 for (i
= 0; i
< opsfound
; i
++)
1459 operands_backup
[i
] = the_ins
.operands
[i
];
1461 for (s
= opcode
->m_operands
, opP
= &operands_backup
[0];
1465 /* Warning: this switch is huge! */
1466 /* I've tried to organize the cases into this order:
1467 non-alpha first, then alpha by letter. Lower-case
1468 goes directly before uppercase counterpart. */
1469 /* Code with multiple case ...: gets sorted by the lowest
1470 case ... it belongs to. I hope this makes sense. */
1576 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1593 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1612 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1622 if (opP
->mode
!= IMMED
)
1624 else if (s
[1] == 'b'
1625 && ! isvar (&opP
->disp
)
1626 && (opP
->disp
.exp
.X_op
!= O_constant
1627 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1629 else if (s
[1] == 'B'
1630 && ! isvar (&opP
->disp
)
1631 && (opP
->disp
.exp
.X_op
!= O_constant
1632 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1634 else if (s
[1] == 'w'
1635 && ! isvar (&opP
->disp
)
1636 && (opP
->disp
.exp
.X_op
!= O_constant
1637 || ! isword (opP
->disp
.exp
.X_add_number
)))
1639 else if (s
[1] == 'W'
1640 && ! isvar (&opP
->disp
)
1641 && (opP
->disp
.exp
.X_op
!= O_constant
1642 || ! issword (opP
->disp
.exp
.X_add_number
)))
1648 if (opP
->mode
!= IMMED
)
1653 if (opP
->mode
== AREG
1654 || opP
->mode
== CONTROL
1655 || opP
->mode
== FPREG
1656 || opP
->mode
== IMMED
1657 || opP
->mode
== REGLST
1658 || (opP
->mode
!= ABSL
1660 || opP
->reg
== ZPC
)))
1665 if (opP
->mode
== CONTROL
1666 || opP
->mode
== FPREG
1667 || opP
->mode
== REGLST
1668 || opP
->mode
== IMMED
1669 || (opP
->mode
!= ABSL
1671 || opP
->reg
== ZPC
)))
1699 if (opP
->mode
== CONTROL
1700 || opP
->mode
== FPREG
1701 || opP
->mode
== REGLST
)
1706 if (opP
->mode
!= AINC
)
1711 if (opP
->mode
!= ADEC
)
1761 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1782 case '~': /* For now! (JF FOO is this right?) */
1804 if (opP
->mode
!= CONTROL
1805 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1810 if (opP
->mode
!= AREG
)
1815 if (opP
->mode
!= AINDR
)
1820 if (opP
->mode
!= AINDR
&& opP
->mode
!= AINC
&& opP
->mode
!= ADEC
1821 && (opP
->mode
!= DISP
1823 || opP
->reg
> ADDR7
))
1828 if (opP
->mode
!= ABSL
1830 && strncmp (instring
, "jbsr", 4) == 0))
1853 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1858 if (opP
->mode
!= DISP
1860 || opP
->reg
> ADDR7
)
1865 if (opP
->mode
!= DREG
)
1870 if (opP
->reg
!= ACC
)
1875 if (opP
->reg
!= ACC
&& opP
->reg
!= ACC1
1876 && opP
->reg
!= ACC2
&& opP
->reg
!= ACC3
)
1881 if (opP
->mode
!= FPREG
)
1886 if (opP
->reg
!= MACSR
)
1891 if (opP
->reg
!= ACCEXT01
&& opP
->reg
!= ACCEXT23
)
1896 if (opP
->reg
!= MASK
)
1901 if (opP
->mode
!= CONTROL
1908 if (opP
->mode
!= LSH
&& opP
->mode
!= RSH
)
1913 if (opP
->mode
!= CONTROL
1915 || opP
->reg
> last_movec_reg
1920 const enum m68k_register
*rp
;
1922 for (rp
= control_regs
; *rp
; rp
++)
1924 if (*rp
== opP
->reg
)
1926 /* In most CPUs RAMBAR refers to control reg
1927 c05 (RAMBAR1), but a few CPUs have it
1928 refer to c04 (RAMBAR0). */
1929 else if (*rp
== RAMBAR_ALT
&& opP
->reg
== RAMBAR
)
1931 opP
->reg
= RAMBAR_ALT
;
1941 if (opP
->mode
!= IMMED
)
1947 if (opP
->mode
== DREG
1948 || opP
->mode
== AREG
1949 || opP
->mode
== FPREG
)
1958 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1961 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1964 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1972 else if (opP
->mode
== CONTROL
)
1981 opP
->mask
= 1 << 24;
1984 opP
->mask
= 1 << 25;
1987 opP
->mask
= 1 << 26;
1996 else if (opP
->mode
!= REGLST
)
1998 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
2000 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
2005 if (opP
->mode
!= IMMED
)
2007 else if (opP
->disp
.exp
.X_op
!= O_constant
2008 || ! issbyte (opP
->disp
.exp
.X_add_number
))
2010 else if (! m68k_quick
2011 && instring
[3] != 'q'
2012 && instring
[4] != 'q')
2017 if (opP
->mode
!= DREG
2018 && opP
->mode
!= IMMED
2019 && opP
->mode
!= ABSL
)
2024 if (opP
->mode
!= IMMED
)
2026 else if (opP
->disp
.exp
.X_op
!= O_constant
2027 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
2029 else if (! m68k_quick
2030 && (strncmp (instring
, "add", 3) == 0
2031 || strncmp (instring
, "sub", 3) == 0)
2032 && instring
[3] != 'q')
2037 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
2042 if (opP
->mode
!= AINDR
2043 && (opP
->mode
!= BASE
2045 && opP
->reg
!= ZADDR0
)
2046 || opP
->disp
.exp
.X_op
!= O_absent
2047 || ((opP
->index
.reg
< DATA0
2048 || opP
->index
.reg
> DATA7
)
2049 && (opP
->index
.reg
< ADDR0
2050 || opP
->index
.reg
> ADDR7
))
2051 || opP
->index
.size
!= SIZE_UNSPEC
2052 || opP
->index
.scale
!= 1))
2057 if (opP
->mode
!= CONTROL
2058 || ! (opP
->reg
== FPI
2060 || opP
->reg
== FPC
))
2065 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
2070 if (opP
->mode
!= IMMED
)
2072 else if (opP
->disp
.exp
.X_op
!= O_constant
2073 || TRUNC (opP
->disp
.exp
.X_add_number
) > 7)
2078 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
2083 if (opP
->mode
!= IMMED
)
2085 else if (opP
->disp
.exp
.X_op
!= O_constant
2086 || (TRUNC (opP
->disp
.exp
.X_add_number
) != 0xffffffff
2087 && TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 6))
2092 if (opP
->mode
!= IMMED
)
2094 else if (opP
->disp
.exp
.X_op
!= O_constant
2095 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
2100 if (opP
->mode
!= IMMED
)
2102 else if (opP
->disp
.exp
.X_op
!= O_constant
2103 || TRUNC (opP
->disp
.exp
.X_add_number
) > 511)
2107 /* JF these are out of order. We could put them
2108 in order if we were willing to put up with
2109 bunches of #ifdef m68851s in the code.
2111 Don't forget that you need these operands
2112 to use 68030 MMU instructions. */
2114 /* Memory addressing mode used by pflushr. */
2116 if (opP
->mode
== CONTROL
2117 || opP
->mode
== FPREG
2118 || opP
->mode
== DREG
2119 || opP
->mode
== AREG
2120 || opP
->mode
== REGLST
)
2122 /* We should accept immediate operands, but they
2123 supposedly have to be quad word, and we don't
2124 handle that. I would like to see what a Motorola
2125 assembler does before doing something here. */
2126 if (opP
->mode
== IMMED
)
2131 if (opP
->mode
!= CONTROL
2132 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
2137 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
2142 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
2147 if (opP
->mode
!= CONTROL
2150 && opP
->reg
!= SCC
))
2155 if (opP
->mode
!= CONTROL
2161 if (opP
->mode
!= CONTROL
2164 && opP
->reg
!= CRP
))
2188 if (opP
->mode
!= CONTROL
2189 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
2190 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
2195 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
2200 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
2205 if (opP
->mode
!= CONTROL
2214 if (opP
->mode
!= ABSL
)
2219 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
2221 /* FIXME: kludge instead of fixing parser:
2222 upper/lower registers are *not* CONTROL
2223 registers, but ordinary ones. */
2224 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
2225 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
2232 if (!(opP
->mode
== AINDR
2233 || (opP
->mode
== DISP
2234 && !(opP
->reg
== PC
|| opP
->reg
== ZPC
))))
2239 if (!(opP
->mode
== AINDR
|| opP
->mode
== DISP
))
2251 /* Since we have found the correct instruction, copy
2252 in the modifications that we may have made. */
2254 for (i
= 0; i
< opsfound
; i
++)
2255 the_ins
.operands
[i
] = operands_backup
[i
];
2261 opcode
= opcode
->m_next
;
2266 && !(ok_arch
& current_architecture
))
2268 const struct m68k_cpu
*cpu
;
2271 char *buf
= xmalloc (space
+ 1);
2275 the_ins
.error
= buf
;
2276 /* Make sure there's a NUL at the end of the buffer -- strncpy
2277 won't write one when it runs out of buffer. */
2279 #define APPEND(STRING) \
2280 (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
2282 APPEND (_("invalid instruction for this architecture; needs "));
2286 APPEND ("ColdFire ISA_A");
2289 APPEND ("ColdFire ");
2290 APPEND (_("hardware divide"));
2293 APPEND ("ColdFire ISA_A+");
2296 APPEND ("ColdFire ISA_B");
2299 APPEND ("ColdFire ISA_C");
2302 APPEND ("ColdFire fpu");
2305 APPEND ("M68K fpu");
2308 APPEND ("M68K mmu");
2312 APPEND (_("or higher"));
2316 APPEND (_("or higher"));
2320 APPEND (_("or higher"));
2328 for (cpu
= m68k_cpus
; cpu
->name
; cpu
++)
2329 if (!cpu
->alias
&& (cpu
->arch
& ok_arch
))
2331 const struct m68k_cpu
*alias
;
2332 int seen_master
= 0;
2338 for (alias
= cpu
; alias
!= m68k_cpus
; alias
--)
2339 if (alias
[-1].alias
>= 0)
2341 for (; !seen_master
|| alias
->alias
> 0; alias
++)
2351 APPEND (alias
->name
);
2364 /* We ran out of space, so replace the end of the list
2369 strcpy (buf
, " ...");
2373 the_ins
.error
= _("operands mismatch");
2380 /* Now assemble it. */
2381 the_ins
.args
= opcode
->m_operands
;
2382 the_ins
.numargs
= opcode
->m_opnum
;
2383 the_ins
.numo
= opcode
->m_codenum
;
2384 the_ins
.opcode
[0] = getone (opcode
);
2385 the_ins
.opcode
[1] = gettwo (opcode
);
2387 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2392 /* This switch is a doozy.
2393 Watch the first step; its a big one! */
2426 tmpreg
= 0x3c; /* 7.4 */
2427 if (strchr ("bwl", s
[1]))
2428 nextword
= get_num (&opP
->disp
, 90);
2430 nextword
= get_num (&opP
->disp
, 0);
2431 if (isvar (&opP
->disp
))
2432 add_fix (s
[1], &opP
->disp
, 0, 0);
2436 if (!isbyte (nextword
))
2437 opP
->error
= _("operand out of range");
2442 if (!isword (nextword
))
2443 opP
->error
= _("operand out of range");
2448 if (!issword (nextword
))
2449 opP
->error
= _("operand out of range");
2454 addword (nextword
>> 16);
2481 /* We gotta put out some float. */
2482 if (op (&opP
->disp
) != O_big
)
2487 /* Can other cases happen here? */
2488 if (op (&opP
->disp
) != O_constant
)
2491 val
= (valueT
) offs (&opP
->disp
);
2495 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2496 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2500 offs (&opP
->disp
) = gencnt
;
2502 if (offs (&opP
->disp
) > 0)
2504 if (offs (&opP
->disp
) > baseo
)
2506 as_warn (_("Bignum too big for %c format; truncated"),
2508 offs (&opP
->disp
) = baseo
;
2510 baseo
-= offs (&opP
->disp
);
2513 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
2514 offs (&opP
->disp
)--;
2519 gen_to_words (words
, baseo
, (long) outro
);
2520 for (wordp
= words
; baseo
--; wordp
++)
2524 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2527 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2530 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2533 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2536 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2540 nextword
= get_num (&opP
->disp
, 90);
2542 /* Convert mode 5 addressing with a zero offset into
2543 mode 2 addressing to reduce the instruction size by a
2545 if (! isvar (&opP
->disp
)
2547 && (opP
->disp
.size
== SIZE_UNSPEC
)
2548 && (opP
->reg
>= ADDR0
)
2549 && (opP
->reg
<= ADDR7
))
2551 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2556 && ! isvar (&opP
->disp
)
2559 opP
->disp
.exp
.X_op
= O_symbol
;
2560 opP
->disp
.exp
.X_add_symbol
=
2561 section_symbol (absolute_section
);
2564 /* Force into index mode. Hope this works. */
2566 /* We do the first bit for 32-bit displacements, and the
2567 second bit for 16 bit ones. It is possible that we
2568 should make the default be WORD instead of LONG, but
2569 I think that'd break GCC, so we put up with a little
2570 inefficiency for the sake of working output. */
2572 if (!issword (nextword
)
2573 || (isvar (&opP
->disp
)
2574 && ((opP
->disp
.size
== SIZE_UNSPEC
2575 && flag_short_refs
== 0
2576 && cpu_of_arch (current_architecture
) >= m68020
2577 && ! arch_coldfire_p (current_architecture
))
2578 || opP
->disp
.size
== SIZE_LONG
)))
2580 if (cpu_of_arch (current_architecture
) < m68020
2581 || arch_coldfire_p (current_architecture
))
2583 _("displacement too large for this architecture; needs 68020 or higher");
2585 tmpreg
= 0x3B; /* 7.3 */
2587 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2588 if (isvar (&opP
->disp
))
2592 if (opP
->disp
.size
== SIZE_LONG
2594 /* If the displacement needs pic
2595 relocation it cannot be relaxed. */
2596 || opP
->disp
.pic_reloc
!= pic_none
2601 add_fix ('l', &opP
->disp
, 1, 2);
2605 add_frag (adds (&opP
->disp
),
2606 SEXT (offs (&opP
->disp
)),
2607 TAB (PCREL1632
, SZ_UNDEF
));
2614 add_fix ('l', &opP
->disp
, 0, 0);
2619 addword (nextword
>> 16);
2624 tmpreg
= 0x3A; /* 7.2 */
2626 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2628 if (isvar (&opP
->disp
))
2632 add_fix ('w', &opP
->disp
, 1, 0);
2635 add_fix ('w', &opP
->disp
, 0, 0);
2645 baseo
= get_num (&opP
->disp
, 90);
2646 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2647 outro
= get_num (&opP
->odisp
, 90);
2648 /* Figure out the `addressing mode'.
2649 Also turn on the BASE_DISABLE bit, if needed. */
2650 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2652 tmpreg
= 0x3b; /* 7.3 */
2653 if (opP
->reg
== ZPC
)
2656 else if (opP
->reg
== 0)
2659 tmpreg
= 0x30; /* 6.garbage */
2661 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2664 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2667 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2669 siz1
= opP
->disp
.size
;
2670 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2671 siz2
= opP
->odisp
.size
;
2675 /* Index register stuff. */
2676 if (opP
->index
.reg
!= 0
2677 && opP
->index
.reg
>= DATA
2678 && opP
->index
.reg
<= ADDR7
)
2680 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2682 if (opP
->index
.size
== SIZE_LONG
2683 || (opP
->index
.size
== SIZE_UNSPEC
2684 && m68k_index_width_default
== SIZE_LONG
))
2687 if ((opP
->index
.scale
!= 1
2688 && cpu_of_arch (current_architecture
) < m68020
)
2689 || (opP
->index
.scale
== 8
2690 && (arch_coldfire_p (current_architecture
)
2691 && !arch_coldfire_fpu (current_architecture
))))
2694 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2697 if (arch_coldfire_p (current_architecture
)
2698 && opP
->index
.size
== SIZE_WORD
)
2699 opP
->error
= _("invalid index size for coldfire");
2701 switch (opP
->index
.scale
)
2718 GET US OUT OF HERE! */
2720 /* Must be INDEX, with an index register. Address
2721 register cannot be ZERO-PC, and either :b was
2722 forced, or we know it will fit. For a 68000 or
2723 68010, force this mode anyways, because the
2724 larger modes aren't supported. */
2725 if (opP
->mode
== BASE
2726 && ((opP
->reg
>= ADDR0
2727 && opP
->reg
<= ADDR7
)
2730 if (siz1
== SIZE_BYTE
2731 || cpu_of_arch (current_architecture
) < m68020
2732 || arch_coldfire_p (current_architecture
)
2733 || (siz1
== SIZE_UNSPEC
2734 && ! isvar (&opP
->disp
)
2735 && issbyte (baseo
)))
2737 nextword
+= baseo
& 0xff;
2739 if (isvar (&opP
->disp
))
2741 /* Do a byte relocation. If it doesn't
2742 fit (possible on m68000) let the
2743 fixup processing complain later. */
2745 add_fix ('B', &opP
->disp
, 1, 1);
2747 add_fix ('B', &opP
->disp
, 0, 0);
2749 else if (siz1
!= SIZE_BYTE
)
2751 if (siz1
!= SIZE_UNSPEC
)
2752 as_warn (_("Forcing byte displacement"));
2753 if (! issbyte (baseo
))
2754 opP
->error
= _("byte displacement out of range");
2759 else if (siz1
== SIZE_UNSPEC
2761 && isvar (&opP
->disp
)
2762 && subs (&opP
->disp
) == NULL
2764 /* If the displacement needs pic
2765 relocation it cannot be relaxed. */
2766 && opP
->disp
.pic_reloc
== pic_none
2770 /* The code in md_convert_frag_1 needs to be
2771 able to adjust nextword. Call frag_grow
2772 to ensure that we have enough space in
2773 the frag obstack to make all the bytes
2776 nextword
+= baseo
& 0xff;
2778 add_frag (adds (&opP
->disp
),
2779 SEXT (offs (&opP
->disp
)),
2780 TAB (PCINDEX
, SZ_UNDEF
));
2788 nextword
|= 0x40; /* No index reg. */
2789 if (opP
->index
.reg
>= ZDATA0
2790 && opP
->index
.reg
<= ZDATA7
)
2791 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2792 else if (opP
->index
.reg
>= ZADDR0
2793 || opP
->index
.reg
<= ZADDR7
)
2794 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2797 /* It isn't simple. */
2799 if (cpu_of_arch (current_architecture
) < m68020
2800 || arch_coldfire_p (current_architecture
))
2802 _("invalid operand mode for this architecture; needs 68020 or higher");
2805 /* If the guy specified a width, we assume that it is
2806 wide enough. Maybe it isn't. If so, we lose. */
2810 if (isvar (&opP
->disp
)
2812 : ! issword (baseo
))
2817 else if (! isvar (&opP
->disp
) && baseo
== 0)
2826 as_warn (_(":b not permitted; defaulting to :w"));
2836 /* Figure out inner displacement stuff. */
2837 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2839 if (cpu_of_arch (current_architecture
) & cpu32
)
2840 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2844 if (isvar (&opP
->odisp
)
2846 : ! issword (outro
))
2851 else if (! isvar (&opP
->odisp
) && outro
== 0)
2860 as_warn (_(":b not permitted; defaulting to :w"));
2869 if (opP
->mode
== POST
2870 && (nextword
& 0x40) == 0)
2875 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2877 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2878 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2880 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2882 if (siz1
== SIZE_LONG
)
2883 addword (baseo
>> 16);
2884 if (siz1
!= SIZE_UNSPEC
)
2887 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2888 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2889 if (siz2
== SIZE_LONG
)
2890 addword (outro
>> 16);
2891 if (siz2
!= SIZE_UNSPEC
)
2897 nextword
= get_num (&opP
->disp
, 90);
2898 switch (opP
->disp
.size
)
2903 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2905 tmpreg
= 0x38; /* 7.0 */
2909 if (isvar (&opP
->disp
)
2910 && !subs (&opP
->disp
)
2911 && adds (&opP
->disp
)
2913 /* If the displacement needs pic relocation it
2914 cannot be relaxed. */
2915 && opP
->disp
.pic_reloc
== pic_none
2918 && !strchr ("~%&$?", s
[0]))
2920 tmpreg
= 0x3A; /* 7.2 */
2921 add_frag (adds (&opP
->disp
),
2922 SEXT (offs (&opP
->disp
)),
2923 TAB (ABSTOPCREL
, SZ_UNDEF
));
2926 /* Fall through into long. */
2928 if (isvar (&opP
->disp
))
2929 add_fix ('l', &opP
->disp
, 0, 0);
2931 tmpreg
= 0x39;/* 7.1 mode */
2932 addword (nextword
>> 16);
2937 as_bad (_("unsupported byte value; use a different suffix"));
2941 if (isvar (&opP
->disp
))
2942 add_fix ('w', &opP
->disp
, 0, 0);
2944 tmpreg
= 0x38;/* 7.0 mode */
2952 as_bad (_("unknown/incorrect operand"));
2956 /* If s[0] is '4', then this is for the mac instructions
2957 that can have a trailing_ampersand set. If so, set 0x100
2958 bit on tmpreg so install_gen_operand can check for it and
2959 set the appropriate bit (word2, bit 5). */
2962 if (opP
->trailing_ampersand
)
2965 install_gen_operand (s
[1], tmpreg
);
2971 { /* JF: I hate floating point! */
2986 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2987 if (isvar (&opP
->disp
))
2988 add_fix (s
[1], &opP
->disp
, 0, 0);
2991 case 'b': /* Danger: These do no check for
2992 certain types of overflow.
2994 if (!isbyte (tmpreg
))
2995 opP
->error
= _("out of range");
2996 insop (tmpreg
, opcode
);
2997 if (isvar (&opP
->disp
))
2998 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2999 (opcode
->m_codenum
) * 2 + 1;
3002 if (!issbyte (tmpreg
))
3003 opP
->error
= _("out of range");
3004 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
3005 if (isvar (&opP
->disp
))
3006 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
3009 if (!isword (tmpreg
))
3010 opP
->error
= _("out of range");
3011 insop (tmpreg
, opcode
);
3012 if (isvar (&opP
->disp
))
3013 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3016 if (!issword (tmpreg
))
3017 opP
->error
= _("out of range");
3018 insop (tmpreg
, opcode
);
3019 if (isvar (&opP
->disp
))
3020 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3023 /* Because of the way insop works, we put these two out
3025 insop (tmpreg
, opcode
);
3026 insop (tmpreg
>> 16, opcode
);
3027 if (isvar (&opP
->disp
))
3028 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
3035 install_operand (s
[1], tmpreg
);
3046 install_operand (s
[1], opP
->reg
- ADDR
);
3050 tmpreg
= get_num (&opP
->disp
, 90);
3055 add_fix ('B', &opP
->disp
, 1, -1);
3058 add_fix ('w', &opP
->disp
, 1, 0);
3063 the_ins
.opcode
[0] |= 0xff;
3064 add_fix ('l', &opP
->disp
, 1, 0);
3068 case 'g': /* Conditional branch */
3069 have_disp
= HAVE_LONG_CALL (current_architecture
);
3072 case 'b': /* Unconditional branch */
3073 have_disp
= HAVE_LONG_BRANCH (current_architecture
);
3074 use_pl
= LONG_BRANCH_VIA_COND (current_architecture
);
3077 case 's': /* Unconditional subroutine */
3078 have_disp
= HAVE_LONG_CALL (current_architecture
);
3081 if (subs (&opP
->disp
) /* We can't relax it. */
3083 /* If the displacement needs pic relocation it cannot be
3085 || 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. */
3374 install_operand (s
[1], tmpreg
);
3378 tmpreg
= get_num (&opP
->disp
, 55);
3379 install_operand (s
[1], tmpreg
& 0x7f);
3386 if (tmpreg
& 0x7FF0000)
3387 as_bad (_("Floating point register in register list"));
3388 insop (reverse_16_bits (tmpreg
), opcode
);
3392 if (tmpreg
& 0x700FFFF)
3393 as_bad (_("Wrong register in floating-point reglist"));
3394 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
3402 if (tmpreg
& 0x7FF0000)
3403 as_bad (_("Floating point register in register list"));
3404 insop (tmpreg
, opcode
);
3406 else if (s
[1] == '8')
3408 if (tmpreg
& 0x0FFFFFF)
3409 as_bad (_("incorrect register in reglist"));
3410 install_operand (s
[1], tmpreg
>> 24);
3414 if (tmpreg
& 0x700FFFF)
3415 as_bad (_("wrong register in floating-point reglist"));
3417 install_operand (s
[1], tmpreg
>> 16);
3422 install_operand (s
[1], get_num (&opP
->disp
, 60));
3426 tmpreg
= ((opP
->mode
== DREG
)
3427 ? 0x20 + (int) (opP
->reg
- DATA
)
3428 : (get_num (&opP
->disp
, 40) & 0x1F));
3429 install_operand (s
[1], tmpreg
);
3433 tmpreg
= get_num (&opP
->disp
, 10);
3436 install_operand (s
[1], tmpreg
);
3440 /* This depends on the fact that ADDR registers are eight
3441 more than their corresponding DATA regs, so the result
3442 will have the ADDR_REG bit set. */
3443 install_operand (s
[1], opP
->reg
- DATA
);
3447 if (opP
->mode
== AINDR
)
3448 install_operand (s
[1], opP
->reg
- DATA
);
3450 install_operand (s
[1], opP
->index
.reg
- DATA
);
3454 if (opP
->reg
== FPI
)
3456 else if (opP
->reg
== FPS
)
3458 else if (opP
->reg
== FPC
)
3462 install_operand (s
[1], tmpreg
);
3465 case 'S': /* Ignore it. */
3469 install_operand (s
[1], get_num (&opP
->disp
, 30));
3472 case 'U': /* Ignore it. */
3491 as_fatal (_("failed sanity check"));
3492 } /* switch on cache token. */
3493 install_operand (s
[1], tmpreg
);
3496 /* JF: These are out of order, I fear. */
3509 install_operand (s
[1], tmpreg
);
3535 install_operand (s
[1], tmpreg
);
3539 if (opP
->reg
== VAL
)
3558 install_operand (s
[1], tmpreg
);
3572 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3583 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3589 install_operand (s
[1], tmpreg
);
3592 know (opP
->reg
== PSR
);
3595 know (opP
->reg
== PCSR
);
3610 install_operand (s
[1], tmpreg
);
3613 tmpreg
= get_num (&opP
->disp
, 20);
3614 install_operand (s
[1], tmpreg
);
3616 case '_': /* used only for move16 absolute 32-bit address. */
3617 if (isvar (&opP
->disp
))
3618 add_fix ('l', &opP
->disp
, 0, 0);
3619 tmpreg
= get_num (&opP
->disp
, 90);
3620 addword (tmpreg
>> 16);
3621 addword (tmpreg
& 0xFFFF);
3624 install_operand (s
[1], opP
->reg
- DATA0L
);
3625 opP
->reg
-= (DATA0L
);
3626 opP
->reg
&= 0x0F; /* remove upper/lower bit. */
3629 tmpreg
= get_num (&opP
->disp
, 80);
3632 install_operand (s
[1], tmpreg
);
3635 tmpreg
= get_num (&opP
->disp
, 10);
3636 install_operand (s
[1], tmpreg
- 1);
3639 tmpreg
= get_num (&opP
->disp
, 65);
3640 install_operand (s
[1], tmpreg
);
3647 /* By the time whe get here (FINALLY) the_ins contains the complete
3648 instruction, ready to be emitted. . . */
3652 reverse_16_bits (int in
)
3657 static int mask
[16] =
3659 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3660 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3662 for (n
= 0; n
< 16; n
++)
3665 out
|= mask
[15 - n
];
3668 } /* reverse_16_bits() */
3671 reverse_8_bits (int in
)
3676 static int mask
[8] =
3678 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3681 for (n
= 0; n
< 8; n
++)
3687 } /* reverse_8_bits() */
3689 /* Cause an extra frag to be generated here, inserting up to
3690 FRAG_VAR_SIZE bytes. TYPE is the subtype of the frag to be
3691 generated; its primary type is rs_machine_dependent.
3693 The TYPE parameter is also used by md_convert_frag_1 and
3694 md_estimate_size_before_relax. The appropriate type of fixup will
3695 be emitted by md_convert_frag_1.
3697 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3699 install_operand (int mode
, int val
)
3704 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge. */
3707 the_ins
.opcode
[0] |= val
<< 9;
3710 the_ins
.opcode
[1] |= val
<< 9;
3713 the_ins
.opcode
[1] |= val
<< 12;
3716 the_ins
.opcode
[1] |= val
<< 6;
3719 the_ins
.opcode
[1] |= val
;
3722 the_ins
.opcode
[2] |= val
<< 12;
3725 the_ins
.opcode
[2] |= val
<< 6;
3728 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3729 three words long! */
3731 the_ins
.opcode
[2] |= val
;
3734 the_ins
.opcode
[1] |= val
<< 7;
3737 the_ins
.opcode
[1] |= val
<< 10;
3741 the_ins
.opcode
[1] |= val
<< 5;
3746 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3749 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3752 the_ins
.opcode
[0] |= val
= 0xff;
3755 the_ins
.opcode
[0] |= val
<< 9;
3758 the_ins
.opcode
[1] |= val
;
3761 the_ins
.opcode
[1] |= val
;
3762 the_ins
.numo
++; /* What a hack. */
3765 the_ins
.opcode
[1] |= val
<< 4;
3773 the_ins
.opcode
[0] |= (val
<< 6);
3776 the_ins
.opcode
[1] = (val
>> 16);
3777 the_ins
.opcode
[2] = val
& 0xffff;
3780 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3781 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3782 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3784 case 'n': /* MAC/EMAC Rx on !load. */
3785 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3786 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3787 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3789 case 'o': /* MAC/EMAC Rx on load. */
3790 the_ins
.opcode
[1] |= val
<< 12;
3791 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3793 case 'M': /* MAC/EMAC Ry on !load. */
3794 the_ins
.opcode
[0] |= (val
& 0xF);
3795 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3797 case 'N': /* MAC/EMAC Ry on load. */
3798 the_ins
.opcode
[1] |= (val
& 0xF);
3799 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3802 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3805 the_ins
.opcode
[0] |= ((val
& 0x3) << 9);
3808 the_ins
.opcode
[0] |= ((val
& 0x3) << 0);
3810 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3811 the_ins
.opcode
[0] |= ((~val
& 0x1) << 7);
3812 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3814 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3815 the_ins
.opcode
[0] |= ((val
& 0x1) << 7);
3816 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3819 the_ins
.opcode
[1] |= ((val
& 0x3) << 9);
3822 the_ins
.opcode
[0] |= (val
& 0x1) <<10;
3826 as_fatal (_("failed sanity check."));
3831 install_gen_operand (int mode
, int val
)
3835 case '/': /* Special for mask loads for mac/msac insns with
3836 possible mask; trailing_ampersend set in bit 8. */
3837 the_ins
.opcode
[0] |= (val
& 0x3f);
3838 the_ins
.opcode
[1] |= (((val
& 0x100) >> 8) << 5);
3841 the_ins
.opcode
[0] |= val
;
3844 /* This is a kludge!!! */
3845 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3854 the_ins
.opcode
[0] |= val
;
3856 /* more stuff goes here. */
3858 as_fatal (_("failed sanity check."));
3862 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3863 then deal with the bitfield hack. */
3866 crack_operand (char *str
, struct m68k_op
*opP
)
3868 register int parens
;
3870 register char *beg_str
;
3878 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3884 else if (*str
== ')')
3888 opP
->error
= _("Extra )");
3894 if (flag_mri
&& *str
== '\'')
3895 inquote
= ! inquote
;
3897 if (!*str
&& parens
)
3899 opP
->error
= _("Missing )");
3904 if (m68k_ip_op (beg_str
, opP
) != 0)
3911 c
= *++str
; /* JF bitfield hack. */
3916 as_bad (_("Missing operand"));
3919 /* Detect MRI REG symbols and convert them to REGLSTs. */
3920 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3923 opP
->mask
= ~(int)opP
->reg
;
3930 /* This is the guts of the machine-dependent assembler. STR points to a
3931 machine dependent instruction. This function is supposed to emit
3932 the frags/bytes it assembles to.
3936 insert_reg (const char *regname
, int regnum
)
3941 #ifdef REGISTER_PREFIX
3942 if (!flag_reg_prefix_optional
)
3944 buf
[0] = REGISTER_PREFIX
;
3945 strcpy (buf
+ 1, regname
);
3950 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3951 &zero_address_frag
));
3953 for (i
= 0; regname
[i
]; i
++)
3954 buf
[i
] = TOUPPER (regname
[i
]);
3957 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3958 &zero_address_frag
));
3967 static const struct init_entry init_table
[] =
4027 { "accext01", ACCEXT01
},
4028 { "accext23", ACCEXT23
},
4032 /* Control registers. */
4033 { "sfc", SFC
}, /* Source Function Code. */
4035 { "dfc", DFC
}, /* Destination Function Code. */
4037 { "cacr", CACR
}, /* Cache Control Register. */
4038 { "caar", CAAR
}, /* Cache Address Register. */
4040 { "usp", USP
}, /* User Stack Pointer. */
4041 { "vbr", VBR
}, /* Vector Base Register. */
4042 { "msp", MSP
}, /* Master Stack Pointer. */
4043 { "isp", ISP
}, /* Interrupt Stack Pointer. */
4045 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0. */
4046 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1. */
4047 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0. */
4048 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1. */
4050 /* 68ec040 versions of same */
4051 { "iacr0", ITT0
}, /* Instruction Access Control Register 0. */
4052 { "iacr1", ITT1
}, /* Instruction Access Control Register 0. */
4053 { "dacr0", DTT0
}, /* Data Access Control Register 0. */
4054 { "dacr1", DTT1
}, /* Data Access Control Register 0. */
4056 /* Coldfire versions of same. The ColdFire programmer's reference
4057 manual indicated that the order is 2,3,0,1, but Ken Rose
4058 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
4059 { "acr0", ACR0
}, /* Access Control Unit 0. */
4060 { "acr1", ACR1
}, /* Access Control Unit 1. */
4061 { "acr2", ACR2
}, /* Access Control Unit 2. */
4062 { "acr3", ACR3
}, /* Access Control Unit 3. */
4064 { "tc", TC
}, /* MMU Translation Control Register. */
4068 { "mmusr", MMUSR
}, /* MMU Status Register. */
4069 { "srp", SRP
}, /* User Root Pointer. */
4070 { "urp", URP
}, /* Supervisor Root Pointer. */
4073 { "mmubar", MMUBAR
},
4076 { "rombar", ROMBAR
}, /* ROM Base Address Register. */
4077 { "rambar0", RAMBAR0
}, /* ROM Base Address Register. */
4078 { "rambar1", RAMBAR1
}, /* ROM Base Address Register. */
4079 { "mbar", MBAR
}, /* Module Base Address Register. */
4081 { "mbar0", MBAR0
}, /* mcfv4e registers. */
4082 { "mbar1", MBAR1
}, /* mcfv4e registers. */
4083 { "rombar0", ROMBAR0
}, /* mcfv4e registers. */
4084 { "rombar1", ROMBAR1
}, /* mcfv4e registers. */
4085 { "mpcr", MPCR
}, /* mcfv4e registers. */
4086 { "edrambar", EDRAMBAR
}, /* mcfv4e registers. */
4087 { "secmbar", SECMBAR
}, /* mcfv4e registers. */
4088 { "asid", TC
}, /* mcfv4e registers. */
4089 { "mmubar", BUSCR
}, /* mcfv4e registers. */
4090 { "pcr1u0", PCR1U0
}, /* mcfv4e registers. */
4091 { "pcr1l0", PCR1L0
}, /* mcfv4e registers. */
4092 { "pcr2u0", PCR2U0
}, /* mcfv4e registers. */
4093 { "pcr2l0", PCR2L0
}, /* mcfv4e registers. */
4094 { "pcr3u0", PCR3U0
}, /* mcfv4e registers. */
4095 { "pcr3l0", PCR3L0
}, /* mcfv4e registers. */
4096 { "pcr1u1", PCR1U1
}, /* mcfv4e registers. */
4097 { "pcr1l1", PCR1L1
}, /* mcfv4e registers. */
4098 { "pcr2u1", PCR2U1
}, /* mcfv4e registers. */
4099 { "pcr2l1", PCR2L1
}, /* mcfv4e registers. */
4100 { "pcr3u1", PCR3U1
}, /* mcfv4e registers. */
4101 { "pcr3l1", PCR3L1
}, /* mcfv4e registers. */
4103 { "flashbar", FLASHBAR
}, /* mcf528x registers. */
4104 { "rambar", RAMBAR
}, /* mcf528x registers. */
4106 { "mbar2", MBAR2
}, /* mcf5249 registers. */
4108 { "cac", CAC
}, /* fido registers. */
4109 { "mbb", MBO
}, /* fido registers (obsolete). */
4110 { "mbo", MBO
}, /* fido registers. */
4111 /* End of control registers. */
4145 /* 68ec030 versions of same. */
4148 /* 68ec030 access control unit, identical to 030 MMU status reg. */
4151 /* Suppressed data and address registers. */
4169 /* Upper and lower data and address registers, used by macw and msacw. */
4210 init_regtable (void)
4213 for (i
= 0; init_table
[i
].name
; i
++)
4214 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
4218 md_assemble (char *str
)
4225 int shorts_this_frag
;
4228 if (!selected_cpu
&& !selected_arch
)
4230 /* We've not selected an architecture yet. Set the default
4231 now. We do this lazily so that an initial .cpu or .arch directive
4233 if (!m68k_set_cpu (TARGET_CPU
, 1, 1))
4234 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU
);
4239 /* In MRI mode, the instruction and operands are separated by a
4240 space. Anything following the operands is a comment. The label
4241 has already been removed. */
4249 for (s
= str
; *s
!= '\0'; s
++)
4251 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
4269 inquote
= ! inquote
;
4274 memset (&the_ins
, '\0', sizeof (the_ins
));
4279 for (n
= 0; n
< the_ins
.numargs
; n
++)
4280 if (the_ins
.operands
[n
].error
)
4282 er
= the_ins
.operands
[n
].error
;
4288 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
4292 /* If there is a current label, record that it marks an instruction. */
4293 if (current_label
!= NULL
)
4295 current_label
->text
= 1;
4296 current_label
= NULL
;
4300 /* Tie dwarf2 debug info to the address at the start of the insn. */
4301 dwarf2_emit_insn (0);
4304 if (the_ins
.nfrag
== 0)
4306 /* No frag hacking involved; just put it out. */
4307 toP
= frag_more (2 * the_ins
.numo
);
4308 fromP
= &the_ins
.opcode
[0];
4309 for (m
= the_ins
.numo
; m
; --m
)
4311 md_number_to_chars (toP
, (long) (*fromP
), 2);
4315 /* Put out symbol-dependent info. */
4316 for (m
= 0; m
< the_ins
.nrel
; m
++)
4318 switch (the_ins
.reloc
[m
].wid
)
4337 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4338 the_ins
.reloc
[m
].wid
);
4341 fixP
= fix_new_exp (frag_now
,
4342 ((toP
- frag_now
->fr_literal
)
4343 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4345 &the_ins
.reloc
[m
].exp
,
4346 the_ins
.reloc
[m
].pcrel
,
4347 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
4348 the_ins
.reloc
[m
].pic_reloc
));
4349 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4350 if (the_ins
.reloc
[m
].wid
== 'B')
4351 fixP
->fx_signed
= 1;
4356 /* There's some frag hacking. */
4358 /* Calculate the max frag size. */
4361 wid
= 2 * the_ins
.fragb
[0].fragoff
;
4362 for (n
= 1; n
< the_ins
.nfrag
; n
++)
4363 wid
+= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4364 /* frag_var part. */
4365 wid
+= FRAG_VAR_SIZE
;
4366 /* Make sure the whole insn fits in one chunk, in particular that
4367 the var part is attached, as we access one byte before the
4368 variable frag for byte branches. */
4372 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
4377 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
4379 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4380 toP
= frag_more (wid
);
4382 shorts_this_frag
= 0;
4383 for (m
= wid
/ 2; m
; --m
)
4385 md_number_to_chars (toP
, (long) (*fromP
), 2);
4390 for (m
= 0; m
< the_ins
.nrel
; m
++)
4392 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
4394 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
4397 wid
= the_ins
.reloc
[m
].wid
;
4400 the_ins
.reloc
[m
].wid
= 0;
4401 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4403 fixP
= fix_new_exp (frag_now
,
4404 ((toP
- frag_now
->fr_literal
)
4405 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4407 &the_ins
.reloc
[m
].exp
,
4408 the_ins
.reloc
[m
].pcrel
,
4409 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4410 the_ins
.reloc
[m
].pic_reloc
));
4411 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4413 (void) frag_var (rs_machine_dependent
, FRAG_VAR_SIZE
, 0,
4414 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
4415 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
4417 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4418 shorts_this_frag
= 0;
4421 toP
= frag_more (n
* 2);
4424 md_number_to_chars (toP
, (long) (*fromP
), 2);
4430 for (m
= 0; m
< the_ins
.nrel
; m
++)
4434 wid
= the_ins
.reloc
[m
].wid
;
4437 the_ins
.reloc
[m
].wid
= 0;
4438 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4440 fixP
= fix_new_exp (frag_now
,
4441 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
4442 - shorts_this_frag
* 2),
4444 &the_ins
.reloc
[m
].exp
,
4445 the_ins
.reloc
[m
].pcrel
,
4446 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4447 the_ins
.reloc
[m
].pic_reloc
));
4448 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4452 /* Comparison function used by qsort to rank the opcode entries by name. */
4455 m68k_compare_opcode (const void * v1
, const void * v2
)
4457 struct m68k_opcode
* op1
, * op2
;
4463 op1
= *(struct m68k_opcode
**) v1
;
4464 op2
= *(struct m68k_opcode
**) v2
;
4466 /* Compare the two names. If different, return the comparison.
4467 If the same, return the order they are in the opcode table. */
4468 ret
= strcmp (op1
->name
, op2
->name
);
4479 const struct m68k_opcode
*ins
;
4480 struct m68k_incant
*hack
, *slak
;
4481 const char *retval
= 0; /* Empty string, or error msg text. */
4484 /* Set up hash tables with 68000 instructions.
4485 similar to what the vax assembler does. */
4486 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4487 a copy of it at runtime, adding in the information we want but isn't
4488 there. I think it'd be better to have an awk script hack the table
4489 at compile time. Or even just xstr the table and use it as-is. But
4490 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4495 flag_reg_prefix_optional
= 1;
4497 if (! m68k_rel32_from_cmdline
)
4501 /* First sort the opcode table into alphabetical order to seperate
4502 the order that the assembler wants to see the opcodes from the
4503 order that the disassembler wants to see them. */
4504 m68k_sorted_opcodes
= xmalloc (m68k_numopcodes
* sizeof (* m68k_sorted_opcodes
));
4505 if (!m68k_sorted_opcodes
)
4506 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4507 m68k_numopcodes
* ((int) sizeof (* m68k_sorted_opcodes
)));
4509 for (i
= m68k_numopcodes
; i
--;)
4510 m68k_sorted_opcodes
[i
] = m68k_opcodes
+ i
;
4512 qsort (m68k_sorted_opcodes
, m68k_numopcodes
,
4513 sizeof (m68k_sorted_opcodes
[0]), m68k_compare_opcode
);
4515 op_hash
= hash_new ();
4517 obstack_begin (&robyn
, 4000);
4518 for (i
= 0; i
< m68k_numopcodes
; i
++)
4520 hack
= slak
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4523 ins
= m68k_sorted_opcodes
[i
];
4525 /* We must enter all insns into the table, because .arch and
4526 .cpu directives can change things. */
4527 slak
->m_operands
= ins
->args
;
4528 slak
->m_arch
= ins
->arch
;
4529 slak
->m_opcode
= ins
->opcode
;
4531 /* In most cases we can determine the number of opcode words
4532 by checking the second word of the mask. Unfortunately
4533 some instructions have 2 opcode words, but no fixed bits
4534 in the second word. A leading dot in the operands
4535 string also indicates 2 opcodes. */
4536 if (*slak
->m_operands
== '.')
4539 slak
->m_codenum
= 2;
4541 else if (ins
->match
& 0xffffL
)
4542 slak
->m_codenum
= 2;
4544 slak
->m_codenum
= 1;
4545 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
4547 if (i
+ 1 != m68k_numopcodes
4548 && !strcmp (ins
->name
, m68k_sorted_opcodes
[i
+ 1]->name
))
4550 slak
->m_next
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4555 slak
= slak
->m_next
;
4559 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
4561 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
4564 for (i
= 0; i
< m68k_numaliases
; i
++)
4566 const char *name
= m68k_opcode_aliases
[i
].primary
;
4567 const char *alias
= m68k_opcode_aliases
[i
].alias
;
4568 void *val
= hash_find (op_hash
, name
);
4571 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4572 retval
= hash_insert (op_hash
, alias
, val
);
4574 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4577 /* In MRI mode, all unsized branches are variable sized. Normally,
4578 they are word sized. */
4581 static struct m68k_opcode_alias mri_aliases
[] =
4602 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
4605 const char *name
= mri_aliases
[i
].primary
;
4606 const char *alias
= mri_aliases
[i
].alias
;
4607 void *val
= hash_find (op_hash
, name
);
4610 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4611 retval
= hash_jam (op_hash
, alias
, val
);
4613 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4617 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
4619 notend_table
[i
] = 0;
4620 alt_notend_table
[i
] = 0;
4623 notend_table
[','] = 1;
4624 notend_table
['{'] = 1;
4625 notend_table
['}'] = 1;
4626 alt_notend_table
['a'] = 1;
4627 alt_notend_table
['A'] = 1;
4628 alt_notend_table
['d'] = 1;
4629 alt_notend_table
['D'] = 1;
4630 alt_notend_table
['#'] = 1;
4631 alt_notend_table
['&'] = 1;
4632 alt_notend_table
['f'] = 1;
4633 alt_notend_table
['F'] = 1;
4634 #ifdef REGISTER_PREFIX
4635 alt_notend_table
[REGISTER_PREFIX
] = 1;
4638 /* We need to put '(' in alt_notend_table to handle
4639 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4640 alt_notend_table
['('] = 1;
4642 /* We need to put '@' in alt_notend_table to handle
4643 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4644 alt_notend_table
['@'] = 1;
4646 /* We need to put digits in alt_notend_table to handle
4647 bfextu %d0{24:1},%d0 */
4648 alt_notend_table
['0'] = 1;
4649 alt_notend_table
['1'] = 1;
4650 alt_notend_table
['2'] = 1;
4651 alt_notend_table
['3'] = 1;
4652 alt_notend_table
['4'] = 1;
4653 alt_notend_table
['5'] = 1;
4654 alt_notend_table
['6'] = 1;
4655 alt_notend_table
['7'] = 1;
4656 alt_notend_table
['8'] = 1;
4657 alt_notend_table
['9'] = 1;
4659 #ifndef MIT_SYNTAX_ONLY
4660 /* Insert pseudo ops, these have to go into the opcode table since
4661 gas expects pseudo ops to start with a dot. */
4665 while (mote_pseudo_table
[n
].poc_name
)
4667 hack
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4668 hash_insert (op_hash
,
4669 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
4670 hack
->m_operands
= 0;
4680 record_alignment (text_section
, 2);
4681 record_alignment (data_section
, 2);
4682 record_alignment (bss_section
, 2);
4687 /* This is called when a label is defined. */
4690 m68k_frob_label (symbolS
*sym
)
4692 struct label_line
*n
;
4694 n
= (struct label_line
*) xmalloc (sizeof *n
);
4697 as_where (&n
->file
, &n
->line
);
4703 dwarf2_emit_label (sym
);
4707 /* This is called when a value that is not an instruction is emitted. */
4710 m68k_flush_pending_output (void)
4712 current_label
= NULL
;
4715 /* This is called at the end of the assembly, when the final value of
4716 the label is known. We warn if this is a text symbol aligned at an
4720 m68k_frob_symbol (symbolS
*sym
)
4722 if (S_GET_SEGMENT (sym
) == reg_section
4723 && (int) S_GET_VALUE (sym
) < 0)
4725 S_SET_SEGMENT (sym
, absolute_section
);
4726 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4728 else if ((S_GET_VALUE (sym
) & 1) != 0)
4730 struct label_line
*l
;
4732 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4734 if (l
->label
== sym
)
4737 as_warn_where (l
->file
, l
->line
,
4738 _("text label `%s' aligned to odd boundary"),
4746 /* This is called if we go in or out of MRI mode because of the .mri
4750 m68k_mri_mode_change (int on
)
4754 if (! flag_reg_prefix_optional
)
4756 flag_reg_prefix_optional
= 1;
4757 #ifdef REGISTER_PREFIX
4762 if (! m68k_rel32_from_cmdline
)
4767 if (! reg_prefix_optional_seen
)
4769 #ifdef REGISTER_PREFIX_OPTIONAL
4770 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4772 flag_reg_prefix_optional
= 0;
4774 #ifdef REGISTER_PREFIX
4779 if (! m68k_rel32_from_cmdline
)
4785 md_atof (int type
, char *litP
, int *sizeP
)
4787 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
4791 md_number_to_chars (char *buf
, valueT val
, int n
)
4793 number_to_chars_bigendian (buf
, val
, n
);
4797 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
4799 offsetT val
= *valP
;
4800 addressT upper_limit
;
4801 offsetT lower_limit
;
4803 /* This is unnecessary but it convinces the native rs6000 compiler
4804 to generate the code we want. */
4805 char *buf
= fixP
->fx_frag
->fr_literal
;
4806 buf
+= fixP
->fx_where
;
4807 /* End ibm compiler workaround. */
4811 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4817 memset (buf
, 0, fixP
->fx_size
);
4818 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4820 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4821 && !S_IS_DEFINED (fixP
->fx_addsy
)
4822 && !S_IS_WEAK (fixP
->fx_addsy
))
4823 S_SET_WEAK (fixP
->fx_addsy
);
4825 switch (fixP
->fx_r_type
)
4827 case BFD_RELOC_68K_TLS_GD32
:
4828 case BFD_RELOC_68K_TLS_GD16
:
4829 case BFD_RELOC_68K_TLS_GD8
:
4830 case BFD_RELOC_68K_TLS_LDM32
:
4831 case BFD_RELOC_68K_TLS_LDM16
:
4832 case BFD_RELOC_68K_TLS_LDM8
:
4833 case BFD_RELOC_68K_TLS_LDO32
:
4834 case BFD_RELOC_68K_TLS_LDO16
:
4835 case BFD_RELOC_68K_TLS_LDO8
:
4836 case BFD_RELOC_68K_TLS_IE32
:
4837 case BFD_RELOC_68K_TLS_IE16
:
4838 case BFD_RELOC_68K_TLS_IE8
:
4839 case BFD_RELOC_68K_TLS_LE32
:
4840 case BFD_RELOC_68K_TLS_LE16
:
4841 case BFD_RELOC_68K_TLS_LE8
:
4842 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
4851 #elif defined(OBJ_AOUT)
4852 /* PR gas/3041 Do not fix frags referencing a weak symbol. */
4853 if (fixP
->fx_addsy
&& S_IS_WEAK (fixP
->fx_addsy
))
4855 memset (buf
, 0, fixP
->fx_size
);
4856 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4861 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4862 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4865 switch (fixP
->fx_size
)
4867 /* The cast to offsetT below are necessary to make code
4868 correct for machines where ints are smaller than offsetT. */
4872 lower_limit
= - (offsetT
) 0x80;
4875 *buf
++ = (val
>> 8);
4877 upper_limit
= 0x7fff;
4878 lower_limit
= - (offsetT
) 0x8000;
4881 *buf
++ = (val
>> 24);
4882 *buf
++ = (val
>> 16);
4883 *buf
++ = (val
>> 8);
4885 upper_limit
= 0x7fffffff;
4886 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* Avoid constant overflow. */
4889 BAD_CASE (fixP
->fx_size
);
4892 /* Fix up a negative reloc. */
4893 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4895 fixP
->fx_addsy
= fixP
->fx_subsy
;
4896 fixP
->fx_subsy
= NULL
;
4900 /* For non-pc-relative values, it's conceivable we might get something
4901 like "0xff" for a byte field. So extend the upper part of the range
4902 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4903 so that we can do any range checking at all. */
4904 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4905 upper_limit
= upper_limit
* 2 + 1;
4907 if ((addressT
) val
> upper_limit
4908 && (val
> 0 || val
< lower_limit
))
4909 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4910 _("value %ld out of range"), (long)val
);
4912 /* A one byte PC-relative reloc means a short branch. We can't use
4913 a short branch with a value of 0 or -1, because those indicate
4914 different opcodes (branches with longer offsets). fixup_segment
4915 in write.c may have clobbered fx_pcrel, so we need to examine the
4918 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
4919 && fixP
->fx_size
== 1
4920 && (fixP
->fx_addsy
== NULL
4921 || S_IS_DEFINED (fixP
->fx_addsy
))
4922 && (val
== 0 || val
== -1))
4923 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4924 _("invalid byte branch offset"));
4927 /* *fragP has been relaxed to its final size, and now needs to have
4928 the bytes inside it modified to conform to the new size There is UGLY
4932 md_convert_frag_1 (fragS
*fragP
)
4937 /* Address in object code of the displacement. */
4938 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4940 /* Address in gas core of the place to store the displacement. */
4941 /* This convinces the native rs6000 compiler to generate the code we
4943 register char *buffer_address
= fragP
->fr_literal
;
4944 buffer_address
+= fragP
->fr_fix
;
4945 /* End ibm compiler workaround. */
4947 /* The displacement of the address, from current location. */
4948 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4949 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4951 switch (fragP
->fr_subtype
)
4953 case TAB (BRANCHBWL
, BYTE
):
4954 case TAB (BRABSJUNC
, BYTE
):
4955 case TAB (BRABSJCOND
, BYTE
):
4956 case TAB (BRANCHBW
, BYTE
):
4957 case TAB (BRANCHBWPL
, BYTE
):
4958 know (issbyte (disp
));
4960 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
4961 _("short branch with zero offset: use :w"));
4962 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4963 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4964 fixP
->fx_pcrel_adjust
= -1;
4966 case TAB (BRANCHBWL
, SHORT
):
4967 case TAB (BRABSJUNC
, SHORT
):
4968 case TAB (BRABSJCOND
, SHORT
):
4969 case TAB (BRANCHBW
, SHORT
):
4970 case TAB (BRANCHBWPL
, SHORT
):
4971 fragP
->fr_opcode
[1] = 0x00;
4972 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4973 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4976 case TAB (BRANCHBWL
, LONG
):
4977 fragP
->fr_opcode
[1] = (char) 0xFF;
4978 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4979 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4982 case TAB (BRANCHBWPL
, LONG
):
4983 /* Here we are converting an unconditional branch into a pair of
4984 conditional branches, in order to get the range. */
4985 fragP
->fr_opcode
[0] = 0x66; /* bne */
4986 fragP
->fr_opcode
[1] = 0xFF;
4987 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4988 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4989 fixP
->fx_file
= fragP
->fr_file
;
4990 fixP
->fx_line
= fragP
->fr_line
;
4991 fragP
->fr_fix
+= 4; /* Skip first offset */
4992 buffer_address
+= 4;
4993 *buffer_address
++ = 0x67; /* beq */
4994 *buffer_address
++ = 0xff;
4995 fragP
->fr_fix
+= 2; /* Skip second branch opcode */
4996 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4997 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5000 case TAB (BRABSJUNC
, LONG
):
5001 if (fragP
->fr_opcode
[0] == 0x61) /* jbsr */
5003 if (flag_keep_pcrel
)
5004 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5005 _("Conversion of PC relative BSR to absolute JSR"));
5006 fragP
->fr_opcode
[0] = 0x4E;
5007 fragP
->fr_opcode
[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
5008 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5009 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5012 else if (fragP
->fr_opcode
[0] == 0x60) /* jbra */
5014 if (flag_keep_pcrel
)
5015 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5016 _("Conversion of PC relative branch to absolute jump"));
5017 fragP
->fr_opcode
[0] = 0x4E;
5018 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
5019 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5020 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5025 /* This cannot happen, because jbsr and jbra are the only two
5026 unconditional branches. */
5030 case TAB (BRABSJCOND
, LONG
):
5031 if (flag_keep_pcrel
)
5032 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5033 _("Conversion of PC relative conditional branch to absolute jump"));
5035 /* Only Bcc 68000 instructions can come here
5036 Change bcc into b!cc/jmp absl long. */
5037 fragP
->fr_opcode
[0] ^= 0x01; /* Invert bcc. */
5038 fragP
->fr_opcode
[1] = 0x06; /* Branch offset = 6. */
5040 /* JF: these used to be fr_opcode[2,3], but they may be in a
5041 different frag, in which case referring to them is a no-no.
5042 Only fr_opcode[0,1] are guaranteed to work. */
5043 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
5044 *buffer_address
++ = (char) 0xf9;
5045 fragP
->fr_fix
+= 2; /* Account for jmp instruction. */
5046 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5047 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5050 case TAB (FBRANCH
, SHORT
):
5051 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
5052 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5053 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5056 case TAB (FBRANCH
, LONG
):
5057 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit. */
5058 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5059 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5062 case TAB (DBCCLBR
, SHORT
):
5063 case TAB (DBCCABSJ
, SHORT
):
5064 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5065 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5068 case TAB (DBCCLBR
, LONG
):
5069 /* Only DBcc instructions can come here.
5070 Change dbcc into dbcc/bral.
5071 JF: these used to be fr_opcode[2-7], but that's wrong. */
5072 if (flag_keep_pcrel
)
5073 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5074 _("Conversion of DBcc to absolute jump"));
5076 *buffer_address
++ = 0x00; /* Branch offset = 4. */
5077 *buffer_address
++ = 0x04;
5078 *buffer_address
++ = 0x60; /* Put in bra pc+6. */
5079 *buffer_address
++ = 0x06;
5080 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
5081 *buffer_address
++ = (char) 0xff;
5083 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
5084 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5085 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5088 case TAB (DBCCABSJ
, LONG
):
5089 /* Only DBcc instructions can come here.
5090 Change dbcc into dbcc/jmp.
5091 JF: these used to be fr_opcode[2-7], but that's wrong. */
5092 if (flag_keep_pcrel
)
5093 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5094 _("Conversion of PC relative conditional branch to absolute jump"));
5096 *buffer_address
++ = 0x00; /* Branch offset = 4. */
5097 *buffer_address
++ = 0x04;
5098 *buffer_address
++ = 0x60; /* Put in bra pc + 6. */
5099 *buffer_address
++ = 0x06;
5100 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
5101 *buffer_address
++ = (char) 0xf9;
5103 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
5104 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5105 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5108 case TAB (PCREL1632
, SHORT
):
5109 fragP
->fr_opcode
[1] &= ~0x3F;
5110 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
5111 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
5112 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5115 case TAB (PCREL1632
, LONG
):
5116 /* Already set to mode 7.3; this indicates: PC indirect with
5117 suppressed index, 32-bit displacement. */
5118 *buffer_address
++ = 0x01;
5119 *buffer_address
++ = 0x70;
5121 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
5122 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5123 fixP
->fx_pcrel_adjust
= 2;
5126 case TAB (PCINDEX
, BYTE
):
5127 assert (fragP
->fr_fix
>= 2);
5128 buffer_address
[-2] &= ~1;
5129 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
5130 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
5131 fixP
->fx_pcrel_adjust
= 1;
5133 case TAB (PCINDEX
, SHORT
):
5134 assert (fragP
->fr_fix
>= 2);
5135 buffer_address
[-2] |= 0x1;
5136 buffer_address
[-1] = 0x20;
5137 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
5138 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5139 fixP
->fx_pcrel_adjust
= 2;
5142 case TAB (PCINDEX
, LONG
):
5143 assert (fragP
->fr_fix
>= 2);
5144 buffer_address
[-2] |= 0x1;
5145 buffer_address
[-1] = 0x30;
5146 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
5147 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
5148 fixP
->fx_pcrel_adjust
= 2;
5151 case TAB (ABSTOPCREL
, SHORT
):
5152 fixP
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
5153 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
5156 case TAB (ABSTOPCREL
, LONG
):
5157 if (flag_keep_pcrel
)
5158 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5159 _("Conversion of PC relative displacement to absolute"));
5160 /* The thing to do here is force it to ABSOLUTE LONG, since
5161 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
5162 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
5164 fragP
->fr_opcode
[1] &= ~0x3F;
5165 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
5166 fixP
= fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
5167 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
5173 fixP
->fx_file
= fragP
->fr_file
;
5174 fixP
->fx_line
= fragP
->fr_line
;
5179 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5180 segT sec ATTRIBUTE_UNUSED
,
5183 md_convert_frag_1 (fragP
);
5186 /* Force truly undefined symbols to their maximum size, and generally set up
5187 the frag list to be relaxed
5190 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
5192 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
5193 switch (fragP
->fr_subtype
)
5195 case TAB (BRANCHBWL
, SZ_UNDEF
):
5196 case TAB (BRANCHBWPL
, SZ_UNDEF
):
5197 case TAB (BRABSJUNC
, SZ_UNDEF
):
5198 case TAB (BRABSJCOND
, SZ_UNDEF
):
5200 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5201 && relaxable_symbol (fragP
->fr_symbol
))
5203 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5205 else if (flag_short_refs
)
5207 /* Symbol is undefined and we want short ref. */
5208 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5212 /* Symbol is still undefined. Make it LONG. */
5213 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5218 case TAB (BRANCHBW
, SZ_UNDEF
):
5220 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5221 && relaxable_symbol (fragP
->fr_symbol
))
5223 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5227 /* Symbol is undefined and we don't have long branches. */
5228 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5233 case TAB (FBRANCH
, SZ_UNDEF
):
5234 case TAB (DBCCLBR
, SZ_UNDEF
):
5235 case TAB (DBCCABSJ
, SZ_UNDEF
):
5236 case TAB (PCREL1632
, SZ_UNDEF
):
5238 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5239 && relaxable_symbol (fragP
->fr_symbol
))
5242 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5246 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5251 case TAB (PCINDEX
, SZ_UNDEF
):
5252 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5253 && relaxable_symbol (fragP
->fr_symbol
)))
5255 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
5259 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
5263 case TAB (ABSTOPCREL
, SZ_UNDEF
):
5265 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5266 && relaxable_symbol (fragP
->fr_symbol
)))
5268 fragP
->fr_subtype
= TAB (ABSTOPCREL
, SHORT
);
5272 fragP
->fr_subtype
= TAB (ABSTOPCREL
, LONG
);
5281 /* Now that SZ_UNDEF are taken care of, check others. */
5282 switch (fragP
->fr_subtype
)
5284 case TAB (BRANCHBWL
, BYTE
):
5285 case TAB (BRABSJUNC
, BYTE
):
5286 case TAB (BRABSJCOND
, BYTE
):
5287 case TAB (BRANCHBW
, BYTE
):
5288 /* We can't do a short jump to the next instruction, so in that
5289 case we force word mode. If the symbol is at the start of a
5290 frag, and it is the next frag with any data in it (usually
5291 this is just the next frag, but assembler listings may
5292 introduce empty frags), we must use word mode. */
5293 if (fragP
->fr_symbol
)
5297 sym_frag
= symbol_get_frag (fragP
->fr_symbol
);
5298 if (S_GET_VALUE (fragP
->fr_symbol
) == sym_frag
->fr_address
)
5302 for (l
= fragP
->fr_next
; l
&& l
!= sym_frag
; l
= l
->fr_next
)
5306 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5313 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5316 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5317 /* the bit-field entries in the relocation_info struct plays hell
5318 with the byte-order problems of cross-assembly. So as a hack,
5319 I added this mach. dependent ri twiddler. Ugly, but it gets
5321 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5322 are symbolnum, most sig. byte first. Last byte is broken up with
5323 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5324 nibble as nuthin. (on Sun 3 at least) */
5325 /* Translate the internal relocation information into target-specific
5329 md_ri_to_chars (char *the_bytes
, struct reloc_info_generic
*ri
)
5332 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
5333 /* Now the fun stuff. */
5334 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
5335 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
5336 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
5337 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80)
5338 | ((ri
->r_length
<< 5) & 0x60)
5339 | ((ri
->r_extern
<< 4) & 0x10));
5344 #endif /* OBJ_AOUT or OBJ_BOUT */
5346 #ifndef WORKING_DOT_WORD
5347 int md_short_jump_size
= 4;
5348 int md_long_jump_size
= 6;
5351 md_create_short_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5352 fragS
*frag ATTRIBUTE_UNUSED
,
5353 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
5357 offset
= to_addr
- (from_addr
+ 2);
5359 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
5360 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
5364 md_create_long_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5365 fragS
*frag
, symbolS
*to_symbol
)
5369 if (!HAVE_LONG_BRANCH (current_architecture
))
5371 if (flag_keep_pcrel
)
5372 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5373 offset
= to_addr
- S_GET_VALUE (to_symbol
);
5374 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
5375 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5376 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
5381 offset
= to_addr
- (from_addr
+ 2);
5382 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
5383 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5389 /* Different values of OK tell what its OK to return. Things that
5390 aren't OK are an error (what a shock, no?)
5393 10: Absolute 1:8 only
5394 20: Absolute 0:7 only
5395 30: absolute 0:15 only
5396 40: Absolute 0:31 only
5397 50: absolute 0:127 only
5398 55: absolute -64:63 only
5399 60: absolute -128:127 only
5400 65: absolute 0:511 only
5401 70: absolute 0:4095 only
5402 80: absolute -1, 1:7 only
5406 get_num (struct m68k_exp
*exp
, int ok
)
5408 if (exp
->exp
.X_op
== O_absent
)
5410 /* Do the same thing the VAX asm does. */
5411 op (exp
) = O_constant
;
5417 as_warn (_("expression out of range: defaulting to 1"));
5421 else if (exp
->exp
.X_op
== O_constant
)
5426 if ((valueT
) TRUNC (offs (exp
)) - 1 > 7)
5428 as_warn (_("expression out of range: defaulting to 1"));
5433 if ((valueT
) TRUNC (offs (exp
)) > 7)
5437 if ((valueT
) TRUNC (offs (exp
)) > 15)
5441 if ((valueT
) TRUNC (offs (exp
)) > 32)
5445 if ((valueT
) TRUNC (offs (exp
)) > 127)
5449 if ((valueT
) SEXT (offs (exp
)) + 64 > 127)
5453 if ((valueT
) SEXT (offs (exp
)) + 128 > 255)
5457 if ((valueT
) TRUNC (offs (exp
)) > 511)
5461 if ((valueT
) TRUNC (offs (exp
)) > 4095)
5464 as_warn (_("expression out of range: defaulting to 0"));
5469 if ((valueT
) TRUNC (offs (exp
)) != 0xffffffff
5470 && (valueT
) TRUNC (offs (exp
)) - 1 > 6)
5472 as_warn (_("expression out of range: defaulting to 1"));
5480 else if (exp
->exp
.X_op
== O_big
)
5482 if (offs (exp
) <= 0 /* flonum. */
5483 && (ok
== 90 /* no bignums */
5484 || (ok
> 10 /* Small-int ranges including 0 ok. */
5485 /* If we have a flonum zero, a zero integer should
5486 do as well (e.g., in moveq). */
5487 && generic_floating_point_number
.exponent
== 0
5488 && generic_floating_point_number
.low
[0] == 0)))
5490 /* HACK! Turn it into a long. */
5491 LITTLENUM_TYPE words
[6];
5493 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5494 op (exp
) = O_constant
;
5497 offs (exp
) = words
[1] | (words
[0] << 16);
5501 op (exp
) = O_constant
;
5504 offs (exp
) = (ok
== 10) ? 1 : 0;
5505 as_warn (_("Can't deal with expression; defaulting to %ld"),
5511 if (ok
>= 10 && ok
<= 80)
5513 op (exp
) = O_constant
;
5516 offs (exp
) = (ok
== 10) ? 1 : 0;
5517 as_warn (_("Can't deal with expression; defaulting to %ld"),
5522 if (exp
->size
!= SIZE_UNSPEC
)
5530 if (!isbyte (offs (exp
)))
5531 as_warn (_("expression doesn't fit in BYTE"));
5534 if (!isword (offs (exp
)))
5535 as_warn (_("expression doesn't fit in WORD"));
5543 /* These are the back-ends for the various machine dependent pseudo-ops. */
5546 s_data1 (int ignore ATTRIBUTE_UNUSED
)
5548 subseg_set (data_section
, 1);
5549 demand_empty_rest_of_line ();
5553 s_data2 (int ignore ATTRIBUTE_UNUSED
)
5555 subseg_set (data_section
, 2);
5556 demand_empty_rest_of_line ();
5560 s_bss (int ignore ATTRIBUTE_UNUSED
)
5562 /* We don't support putting frags in the BSS segment, we fake it
5563 by marking in_bss, then looking at s_skip for clues. */
5565 subseg_set (bss_section
, 0);
5566 demand_empty_rest_of_line ();
5570 s_even (int ignore ATTRIBUTE_UNUSED
)
5573 register long temp_fill
;
5575 temp
= 1; /* JF should be 2? */
5576 temp_fill
= get_absolute_expression ();
5577 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5578 frag_align (temp
, (int) temp_fill
, 0);
5579 demand_empty_rest_of_line ();
5580 record_alignment (now_seg
, temp
);
5584 s_proc (int ignore ATTRIBUTE_UNUSED
)
5586 demand_empty_rest_of_line ();
5589 /* Pseudo-ops handled for MRI compatibility. */
5591 /* This function returns non-zero if the argument is a conditional
5592 pseudo-op. This is called when checking whether a pending
5593 alignment is needed. */
5596 m68k_conditional_pseudoop (pseudo_typeS
*pop
)
5598 return (pop
->poc_handler
== s_mri_if
5599 || pop
->poc_handler
== s_mri_else
);
5602 /* Handle an MRI style chip specification. */
5611 s
= input_line_pointer
;
5612 /* We can't use get_symbol_end since the processor names are not proper
5614 while (is_part_of_name (c
= *input_line_pointer
++))
5616 *--input_line_pointer
= 0;
5617 for (i
= 0; m68k_cpus
[i
].name
; i
++)
5618 if (strcasecmp (s
, m68k_cpus
[i
].name
) == 0)
5620 if (!m68k_cpus
[i
].name
)
5622 as_bad (_("%s: unrecognized processor name"), s
);
5623 *input_line_pointer
= c
;
5624 ignore_rest_of_line ();
5627 *input_line_pointer
= c
;
5629 if (*input_line_pointer
== '/')
5630 current_architecture
= 0;
5632 current_architecture
&= m68881
| m68851
;
5633 current_architecture
|= m68k_cpus
[i
].arch
& ~(m68881
| m68851
);
5634 control_regs
= m68k_cpus
[i
].control_regs
;
5636 while (*input_line_pointer
== '/')
5638 ++input_line_pointer
;
5639 s
= input_line_pointer
;
5640 /* We can't use get_symbol_end since the processor names are not
5642 while (is_part_of_name (c
= *input_line_pointer
++))
5644 *--input_line_pointer
= 0;
5645 if (strcmp (s
, "68881") == 0)
5646 current_architecture
|= m68881
;
5647 else if (strcmp (s
, "68851") == 0)
5648 current_architecture
|= m68851
;
5649 *input_line_pointer
= c
;
5653 /* The MRI CHIP pseudo-op. */
5656 s_chip (int ignore ATTRIBUTE_UNUSED
)
5662 stop
= mri_comment_field (&stopc
);
5665 mri_comment_end (stop
, stopc
);
5666 demand_empty_rest_of_line ();
5669 /* The MRI FOPT pseudo-op. */
5672 s_fopt (int ignore ATTRIBUTE_UNUSED
)
5676 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5680 input_line_pointer
+= 3;
5681 temp
= get_absolute_expression ();
5682 if (temp
< 0 || temp
> 7)
5683 as_bad (_("bad coprocessor id"));
5685 m68k_float_copnum
= COP0
+ temp
;
5689 as_bad (_("unrecognized fopt option"));
5690 ignore_rest_of_line ();
5694 demand_empty_rest_of_line ();
5697 /* The structure used to handle the MRI OPT pseudo-op. */
5701 /* The name of the option. */
5704 /* If this is not NULL, just call this function. The first argument
5705 is the ARG field of this structure, the second argument is
5706 whether the option was negated. */
5707 void (*pfn
) (int arg
, int on
);
5709 /* If this is not NULL, and the PFN field is NULL, set the variable
5710 this points to. Set it to the ARG field if the option was not
5711 negated, and the NOTARG field otherwise. */
5714 /* The value to pass to PFN or to assign to *PVAR. */
5717 /* The value to assign to *PVAR if the option is negated. If PFN is
5718 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5719 the option may not be negated. */
5723 /* The table used to handle the MRI OPT pseudo-op. */
5725 static void skip_to_comma (int, int);
5726 static void opt_nest (int, int);
5727 static void opt_chip (int, int);
5728 static void opt_list (int, int);
5729 static void opt_list_symbols (int, int);
5731 static const struct opt_action opt_table
[] =
5733 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5735 /* We do relaxing, so there is little use for these options. */
5736 { "b", 0, 0, 0, 0 },
5737 { "brs", 0, 0, 0, 0 },
5738 { "brb", 0, 0, 0, 0 },
5739 { "brl", 0, 0, 0, 0 },
5740 { "brw", 0, 0, 0, 0 },
5742 { "c", 0, 0, 0, 0 },
5743 { "cex", 0, 0, 0, 0 },
5744 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5745 { "cl", 0, 0, 0, 0 },
5746 { "cre", 0, 0, 0, 0 },
5747 { "d", 0, &flag_keep_locals
, 1, 0 },
5748 { "e", 0, 0, 0, 0 },
5749 { "f", 0, &flag_short_refs
, 1, 0 },
5750 { "frs", 0, &flag_short_refs
, 1, 0 },
5751 { "frl", 0, &flag_short_refs
, 0, 1 },
5752 { "g", 0, 0, 0, 0 },
5753 { "i", 0, 0, 0, 0 },
5754 { "m", 0, 0, 0, 0 },
5755 { "mex", 0, 0, 0, 0 },
5756 { "mc", 0, 0, 0, 0 },
5757 { "md", 0, 0, 0, 0 },
5758 { "nest", opt_nest
, 0, 0, 0 },
5759 { "next", skip_to_comma
, 0, 0, 0 },
5760 { "o", 0, 0, 0, 0 },
5761 { "old", 0, 0, 0, 0 },
5762 { "op", skip_to_comma
, 0, 0, 0 },
5763 { "pco", 0, 0, 0, 0 },
5764 { "p", opt_chip
, 0, 0, 0 },
5765 { "pcr", 0, 0, 0, 0 },
5766 { "pcs", 0, 0, 0, 0 },
5767 { "r", 0, 0, 0, 0 },
5768 { "quick", 0, &m68k_quick
, 1, 0 },
5769 { "rel32", 0, &m68k_rel32
, 1, 0 },
5770 { "s", opt_list
, 0, 0, 0 },
5771 { "t", opt_list_symbols
, 0, 0, 0 },
5772 { "w", 0, &flag_no_warnings
, 0, 1 },
5776 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5778 /* The MRI OPT pseudo-op. */
5781 s_opt (int ignore ATTRIBUTE_UNUSED
)
5789 const struct opt_action
*o
;
5794 if (*input_line_pointer
== '-')
5796 ++input_line_pointer
;
5799 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5801 input_line_pointer
+= 2;
5805 s
= input_line_pointer
;
5806 c
= get_symbol_end ();
5808 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5810 if (strcasecmp (s
, o
->name
) == 0)
5814 /* Restore input_line_pointer now in case the option
5816 *input_line_pointer
= c
;
5817 (*o
->pfn
) (o
->arg
, t
);
5819 else if (o
->pvar
!= NULL
)
5821 if (! t
&& o
->arg
== o
->notarg
)
5822 as_bad (_("option `%s' may not be negated"), s
);
5823 *input_line_pointer
= c
;
5824 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5827 *input_line_pointer
= c
;
5833 as_bad (_("option `%s' not recognized"), s
);
5834 *input_line_pointer
= c
;
5837 while (*input_line_pointer
++ == ',');
5839 /* Move back to terminating character. */
5840 --input_line_pointer
;
5841 demand_empty_rest_of_line ();
5844 /* Skip ahead to a comma. This is used for OPT options which we do
5845 not support and which take arguments. */
5848 skip_to_comma (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5850 while (*input_line_pointer
!= ','
5851 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5852 ++input_line_pointer
;
5855 /* Handle the OPT NEST=depth option. */
5858 opt_nest (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5860 if (*input_line_pointer
!= '=')
5862 as_bad (_("bad format of OPT NEST=depth"));
5866 ++input_line_pointer
;
5867 max_macro_nest
= get_absolute_expression ();
5870 /* Handle the OPT P=chip option. */
5873 opt_chip (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5875 if (*input_line_pointer
!= '=')
5877 /* This is just OPT P, which we do not support. */
5881 ++input_line_pointer
;
5885 /* Handle the OPT S option. */
5888 opt_list (int arg ATTRIBUTE_UNUSED
, int on
)
5893 /* Handle the OPT T option. */
5896 opt_list_symbols (int arg ATTRIBUTE_UNUSED
, int on
)
5899 listing
|= LISTING_SYMBOLS
;
5901 listing
&= ~LISTING_SYMBOLS
;
5904 /* Handle the MRI REG pseudo-op. */
5907 s_reg (int ignore ATTRIBUTE_UNUSED
)
5916 if (line_label
== NULL
)
5918 as_bad (_("missing label"));
5919 ignore_rest_of_line ();
5924 stop
= mri_comment_field (&stopc
);
5928 s
= input_line_pointer
;
5929 while (ISALNUM (*input_line_pointer
)
5930 #ifdef REGISTER_PREFIX
5931 || *input_line_pointer
== REGISTER_PREFIX
5933 || *input_line_pointer
== '/'
5934 || *input_line_pointer
== '-')
5935 ++input_line_pointer
;
5936 c
= *input_line_pointer
;
5937 *input_line_pointer
= '\0';
5939 if (m68k_ip_op (s
, &rop
) != 0)
5941 if (rop
.error
== NULL
)
5942 as_bad (_("bad register list"));
5944 as_bad (_("bad register list: %s"), rop
.error
);
5945 *input_line_pointer
= c
;
5946 ignore_rest_of_line ();
5950 *input_line_pointer
= c
;
5952 if (rop
.mode
== REGLST
)
5954 else if (rop
.mode
== DREG
)
5955 mask
= 1 << (rop
.reg
- DATA0
);
5956 else if (rop
.mode
== AREG
)
5957 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5958 else if (rop
.mode
== FPREG
)
5959 mask
= 1 << (rop
.reg
- FP0
+ 16);
5960 else if (rop
.mode
== CONTROL
5963 else if (rop
.mode
== CONTROL
5966 else if (rop
.mode
== CONTROL
5971 as_bad (_("bad register list"));
5972 ignore_rest_of_line ();
5976 S_SET_SEGMENT (line_label
, reg_section
);
5977 S_SET_VALUE (line_label
, ~mask
);
5978 symbol_set_frag (line_label
, &zero_address_frag
);
5981 mri_comment_end (stop
, stopc
);
5983 demand_empty_rest_of_line ();
5986 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5990 struct save_opts
*next
;
5992 int symbols_case_sensitive
;
5996 const enum m68k_register
*control_regs
;
6001 /* FIXME: We don't save OPT S. */
6004 /* This variable holds the stack of saved options. */
6006 static struct save_opts
*save_stack
;
6008 /* The MRI SAVE pseudo-op. */
6011 s_save (int ignore ATTRIBUTE_UNUSED
)
6013 struct save_opts
*s
;
6015 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
6016 s
->abspcadd
= m68k_abspcadd
;
6017 s
->symbols_case_sensitive
= symbols_case_sensitive
;
6018 s
->keep_locals
= flag_keep_locals
;
6019 s
->short_refs
= flag_short_refs
;
6020 s
->architecture
= current_architecture
;
6021 s
->control_regs
= control_regs
;
6022 s
->quick
= m68k_quick
;
6023 s
->rel32
= m68k_rel32
;
6024 s
->listing
= listing
;
6025 s
->no_warnings
= flag_no_warnings
;
6027 s
->next
= save_stack
;
6030 demand_empty_rest_of_line ();
6033 /* The MRI RESTORE pseudo-op. */
6036 s_restore (int ignore ATTRIBUTE_UNUSED
)
6038 struct save_opts
*s
;
6040 if (save_stack
== NULL
)
6042 as_bad (_("restore without save"));
6043 ignore_rest_of_line ();
6048 save_stack
= s
->next
;
6050 m68k_abspcadd
= s
->abspcadd
;
6051 symbols_case_sensitive
= s
->symbols_case_sensitive
;
6052 flag_keep_locals
= s
->keep_locals
;
6053 flag_short_refs
= s
->short_refs
;
6054 current_architecture
= s
->architecture
;
6055 control_regs
= s
->control_regs
;
6056 m68k_quick
= s
->quick
;
6057 m68k_rel32
= s
->rel32
;
6058 listing
= s
->listing
;
6059 flag_no_warnings
= s
->no_warnings
;
6063 demand_empty_rest_of_line ();
6066 /* Types of MRI structured control directives. */
6068 enum mri_control_type
6076 /* This structure is used to stack the MRI structured control
6079 struct mri_control_info
6081 /* The directive within which this one is enclosed. */
6082 struct mri_control_info
*outer
;
6084 /* The type of directive. */
6085 enum mri_control_type type
;
6087 /* Whether an ELSE has been in an IF. */
6090 /* The add or sub statement at the end of a FOR. */
6093 /* The label of the top of a FOR or REPEAT loop. */
6096 /* The label to jump to for the next iteration, or the else
6097 expression of a conditional. */
6100 /* The label to jump to to break out of the loop, or the label past
6101 the end of a conditional. */
6105 /* The stack of MRI structured control directives. */
6107 static struct mri_control_info
*mri_control_stack
;
6109 /* The current MRI structured control directive index number, used to
6110 generate label names. */
6112 static int mri_control_index
;
6114 /* Assemble an instruction for an MRI structured control directive. */
6117 mri_assemble (char *str
)
6121 /* md_assemble expects the opcode to be in lower case. */
6122 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
6128 /* Generate a new MRI label structured control directive label name. */
6131 mri_control_label (void)
6135 n
= (char *) xmalloc (20);
6136 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
6137 ++mri_control_index
;
6141 /* Create a new MRI structured control directive. */
6143 static struct mri_control_info
*
6144 push_mri_control (enum mri_control_type type
)
6146 struct mri_control_info
*n
;
6148 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
6152 if (type
== mri_if
|| type
== mri_while
)
6155 n
->top
= mri_control_label ();
6156 n
->next
= mri_control_label ();
6157 n
->bottom
= mri_control_label ();
6159 n
->outer
= mri_control_stack
;
6160 mri_control_stack
= n
;
6165 /* Pop off the stack of MRI structured control directives. */
6168 pop_mri_control (void)
6170 struct mri_control_info
*n
;
6172 n
= mri_control_stack
;
6173 mri_control_stack
= n
->outer
;
6181 /* Recognize a condition code in an MRI structured control expression. */
6184 parse_mri_condition (int *pcc
)
6188 know (*input_line_pointer
== '<');
6190 ++input_line_pointer
;
6191 c1
= *input_line_pointer
++;
6192 c2
= *input_line_pointer
++;
6194 if (*input_line_pointer
!= '>')
6196 as_bad (_("syntax error in structured control directive"));
6200 ++input_line_pointer
;
6206 *pcc
= (c1
<< 8) | c2
;
6211 /* Parse a single operand in an MRI structured control expression. */
6214 parse_mri_control_operand (int *pcc
, char **leftstart
, char **leftstop
,
6215 char **rightstart
, char **rightstop
)
6227 if (*input_line_pointer
== '<')
6229 /* It's just a condition code. */
6230 return parse_mri_condition (pcc
);
6233 /* Look ahead for the condition code. */
6234 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6236 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
6241 as_bad (_("missing condition code in structured control directive"));
6245 *leftstart
= input_line_pointer
;
6247 if (*leftstop
> *leftstart
6248 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
6251 input_line_pointer
= s
;
6252 if (! parse_mri_condition (pcc
))
6255 /* Look ahead for AND or OR or end of line. */
6256 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6258 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6259 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6261 if ((s
== input_line_pointer
6264 && ((strncasecmp (s
, "AND", 3) == 0
6265 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
6266 || (strncasecmp (s
, "OR", 2) == 0
6267 && (s
[2] == '.' || ! is_part_of_name (s
[2])))))
6271 *rightstart
= input_line_pointer
;
6273 if (*rightstop
> *rightstart
6274 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
6277 input_line_pointer
= s
;
6282 #define MCC(b1, b2) (((b1) << 8) | (b2))
6284 /* Swap the sense of a condition. This changes the condition so that
6285 it generates the same result when the operands are swapped. */
6288 swap_mri_condition (int cc
)
6292 case MCC ('h', 'i'): return MCC ('c', 's');
6293 case MCC ('l', 's'): return MCC ('c', 'c');
6294 /* <HS> is an alias for <CC>. */
6295 case MCC ('h', 's'):
6296 case MCC ('c', 'c'): return MCC ('l', 's');
6297 /* <LO> is an alias for <CS>. */
6298 case MCC ('l', 'o'):
6299 case MCC ('c', 's'): return MCC ('h', 'i');
6300 case MCC ('p', 'l'): return MCC ('m', 'i');
6301 case MCC ('m', 'i'): return MCC ('p', 'l');
6302 case MCC ('g', 'e'): return MCC ('l', 'e');
6303 case MCC ('l', 't'): return MCC ('g', 't');
6304 case MCC ('g', 't'): return MCC ('l', 't');
6305 case MCC ('l', 'e'): return MCC ('g', 'e');
6306 /* Issue a warning for conditions we can not swap. */
6307 case MCC ('n', 'e'): return MCC ('n', 'e'); /* no problem here */
6308 case MCC ('e', 'q'): return MCC ('e', 'q'); /* also no problem */
6309 case MCC ('v', 'c'):
6310 case MCC ('v', 's'):
6312 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6313 (char) (cc
>> 8), (char) (cc
));
6319 /* Reverse the sense of a condition. */
6322 reverse_mri_condition (int cc
)
6326 case MCC ('h', 'i'): return MCC ('l', 's');
6327 case MCC ('l', 's'): return MCC ('h', 'i');
6328 /* <HS> is an alias for <CC> */
6329 case MCC ('h', 's'): return MCC ('l', 'o');
6330 case MCC ('c', 'c'): return MCC ('c', 's');
6331 /* <LO> is an alias for <CS> */
6332 case MCC ('l', 'o'): return MCC ('h', 's');
6333 case MCC ('c', 's'): return MCC ('c', 'c');
6334 case MCC ('n', 'e'): return MCC ('e', 'q');
6335 case MCC ('e', 'q'): return MCC ('n', 'e');
6336 case MCC ('v', 'c'): return MCC ('v', 's');
6337 case MCC ('v', 's'): return MCC ('v', 'c');
6338 case MCC ('p', 'l'): return MCC ('m', 'i');
6339 case MCC ('m', 'i'): return MCC ('p', 'l');
6340 case MCC ('g', 'e'): return MCC ('l', 't');
6341 case MCC ('l', 't'): return MCC ('g', 'e');
6342 case MCC ('g', 't'): return MCC ('l', 'e');
6343 case MCC ('l', 'e'): return MCC ('g', 't');
6348 /* Build an MRI structured control expression. This generates test
6349 and branch instructions. It goes to TRUELAB if the condition is
6350 true, and to FALSELAB if the condition is false. Exactly one of
6351 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6352 is the size qualifier for the expression. EXTENT is the size to
6353 use for the branch. */
6356 build_mri_control_operand (int qual
, int cc
, char *leftstart
, char *leftstop
,
6357 char *rightstart
, char *rightstop
,
6358 const char *truelab
, const char *falselab
,
6364 if (leftstart
!= NULL
)
6366 struct m68k_op leftop
, rightop
;
6369 /* Swap the compare operands, if necessary, to produce a legal
6370 m68k compare instruction. Comparing a register operand with
6371 a non-register operand requires the register to be on the
6372 right (cmp, cmpa). Comparing an immediate value with
6373 anything requires the immediate value to be on the left
6378 (void) m68k_ip_op (leftstart
, &leftop
);
6383 (void) m68k_ip_op (rightstart
, &rightop
);
6386 if (rightop
.mode
== IMMED
6387 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
6388 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
6392 /* Correct conditional handling:
6393 if #1 <lt> d0 then ;means if (1 < d0)
6399 cmp #1,d0 if we do *not* swap the operands
6400 bgt true we need the swapped condition!
6407 leftstart
= rightstart
;
6410 leftstop
= rightstop
;
6415 cc
= swap_mri_condition (cc
);
6419 if (truelab
== NULL
)
6421 cc
= reverse_mri_condition (cc
);
6425 if (leftstart
!= NULL
)
6427 buf
= (char *) xmalloc (20
6428 + (leftstop
- leftstart
)
6429 + (rightstop
- rightstart
));
6435 *s
++ = TOLOWER (qual
);
6437 memcpy (s
, leftstart
, leftstop
- leftstart
);
6438 s
+= leftstop
- leftstart
;
6440 memcpy (s
, rightstart
, rightstop
- rightstart
);
6441 s
+= rightstop
- rightstart
;
6447 buf
= (char *) xmalloc (20 + strlen (truelab
));
6453 *s
++ = TOLOWER (extent
);
6455 strcpy (s
, truelab
);
6460 /* Parse an MRI structured control expression. This generates test
6461 and branch instructions. STOP is where the expression ends. It
6462 goes to TRUELAB if the condition is true, and to FALSELAB if the
6463 condition is false. Exactly one of TRUELAB and FALSELAB will be
6464 NULL, meaning to fall through. QUAL is the size qualifier for the
6465 expression. EXTENT is the size to use for the branch. */
6468 parse_mri_control_expression (char *stop
, int qual
, const char *truelab
,
6469 const char *falselab
, int extent
)
6481 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6482 &rightstart
, &rightstop
))
6488 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6492 if (falselab
!= NULL
)
6495 flab
= mri_control_label ();
6497 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6498 rightstop
, (const char *) NULL
, flab
, extent
);
6500 input_line_pointer
+= 3;
6501 if (*input_line_pointer
!= '.'
6502 || input_line_pointer
[1] == '\0')
6506 qual
= input_line_pointer
[1];
6507 input_line_pointer
+= 2;
6510 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6511 &rightstart
, &rightstop
))
6517 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6518 rightstop
, truelab
, falselab
, extent
);
6520 if (falselab
== NULL
)
6523 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6527 if (truelab
!= NULL
)
6530 tlab
= mri_control_label ();
6532 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6533 rightstop
, tlab
, (const char *) NULL
, extent
);
6535 input_line_pointer
+= 2;
6536 if (*input_line_pointer
!= '.'
6537 || input_line_pointer
[1] == '\0')
6541 qual
= input_line_pointer
[1];
6542 input_line_pointer
+= 2;
6545 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6546 &rightstart
, &rightstop
))
6552 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6553 rightstop
, truelab
, falselab
, extent
);
6555 if (truelab
== NULL
)
6560 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6561 rightstop
, truelab
, falselab
, extent
);
6565 if (input_line_pointer
!= stop
)
6566 as_bad (_("syntax error in structured control directive"));
6569 /* Handle the MRI IF pseudo-op. This may be a structured control
6570 directive, or it may be a regular assembler conditional, depending
6578 struct mri_control_info
*n
;
6580 /* A structured control directive must end with THEN with an
6581 optional qualifier. */
6582 s
= input_line_pointer
;
6583 /* We only accept '*' as introduction of comments if preceded by white space
6584 or at first column of a line (I think this can't actually happen here?)
6585 This is important when assembling:
6586 if d0 <ne> 12(a0,d0*2) then
6587 if d0 <ne> #CONST*20 then. */
6588 while (! (is_end_of_line
[(unsigned char) *s
]
6591 && (s
== input_line_pointer
6593 || *(s
-1) == '\t'))))
6596 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6599 if (s
- input_line_pointer
> 1
6603 if (s
- input_line_pointer
< 3
6604 || strncasecmp (s
- 3, "THEN", 4) != 0)
6608 as_bad (_("missing then"));
6609 ignore_rest_of_line ();
6613 /* It's a conditional. */
6618 /* Since this might be a conditional if, this pseudo-op will be
6619 called even if we are supported to be ignoring input. Double
6620 check now. Clobber *input_line_pointer so that ignore_input
6621 thinks that this is not a special pseudo-op. */
6622 c
= *input_line_pointer
;
6623 *input_line_pointer
= 0;
6624 if (ignore_input ())
6626 *input_line_pointer
= c
;
6627 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6628 ++input_line_pointer
;
6629 demand_empty_rest_of_line ();
6632 *input_line_pointer
= c
;
6634 n
= push_mri_control (mri_if
);
6636 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6637 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6640 input_line_pointer
= s
+ 3;
6642 input_line_pointer
= s
+ 1;
6646 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6647 ++input_line_pointer
;
6650 demand_empty_rest_of_line ();
6653 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6654 structured IF, associate the ELSE with the IF. Otherwise, assume
6655 it is a conditional else. */
6658 s_mri_else (int qual
)
6665 && (mri_control_stack
== NULL
6666 || mri_control_stack
->type
!= mri_if
6667 || mri_control_stack
->else_seen
))
6673 c
= *input_line_pointer
;
6674 *input_line_pointer
= 0;
6675 if (ignore_input ())
6677 *input_line_pointer
= c
;
6678 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6679 ++input_line_pointer
;
6680 demand_empty_rest_of_line ();
6683 *input_line_pointer
= c
;
6685 if (mri_control_stack
== NULL
6686 || mri_control_stack
->type
!= mri_if
6687 || mri_control_stack
->else_seen
)
6689 as_bad (_("else without matching if"));
6690 ignore_rest_of_line ();
6694 mri_control_stack
->else_seen
= 1;
6696 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6697 q
[0] = TOLOWER (qual
);
6699 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6703 colon (mri_control_stack
->next
);
6707 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6708 ++input_line_pointer
;
6711 demand_empty_rest_of_line ();
6714 /* Handle the MRI ENDI pseudo-op. */
6717 s_mri_endi (int ignore ATTRIBUTE_UNUSED
)
6719 if (mri_control_stack
== NULL
6720 || mri_control_stack
->type
!= mri_if
)
6722 as_bad (_("endi without matching if"));
6723 ignore_rest_of_line ();
6727 /* ignore_input will not return true for ENDI, so we don't need to
6728 worry about checking it again here. */
6730 if (! mri_control_stack
->else_seen
)
6731 colon (mri_control_stack
->next
);
6732 colon (mri_control_stack
->bottom
);
6738 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6739 ++input_line_pointer
;
6742 demand_empty_rest_of_line ();
6745 /* Handle the MRI BREAK pseudo-op. */
6748 s_mri_break (int extent
)
6750 struct mri_control_info
*n
;
6754 n
= mri_control_stack
;
6756 && n
->type
!= mri_for
6757 && n
->type
!= mri_repeat
6758 && n
->type
!= mri_while
)
6762 as_bad (_("break outside of structured loop"));
6763 ignore_rest_of_line ();
6767 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6768 ex
[0] = TOLOWER (extent
);
6770 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6776 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6777 ++input_line_pointer
;
6780 demand_empty_rest_of_line ();
6783 /* Handle the MRI NEXT pseudo-op. */
6786 s_mri_next (int extent
)
6788 struct mri_control_info
*n
;
6792 n
= mri_control_stack
;
6794 && n
->type
!= mri_for
6795 && n
->type
!= mri_repeat
6796 && n
->type
!= mri_while
)
6800 as_bad (_("next outside of structured loop"));
6801 ignore_rest_of_line ();
6805 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6806 ex
[0] = TOLOWER (extent
);
6808 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6814 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6815 ++input_line_pointer
;
6818 demand_empty_rest_of_line ();
6821 /* Handle the MRI FOR pseudo-op. */
6824 s_mri_for (int qual
)
6826 const char *varstart
, *varstop
;
6827 const char *initstart
, *initstop
;
6828 const char *endstart
, *endstop
;
6829 const char *bystart
, *bystop
;
6833 struct mri_control_info
*n
;
6839 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6843 varstart
= input_line_pointer
;
6845 /* Look for the '='. */
6846 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6847 && *input_line_pointer
!= '=')
6848 ++input_line_pointer
;
6849 if (*input_line_pointer
!= '=')
6851 as_bad (_("missing ="));
6852 ignore_rest_of_line ();
6856 varstop
= input_line_pointer
;
6857 if (varstop
> varstart
6858 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6861 ++input_line_pointer
;
6863 initstart
= input_line_pointer
;
6865 /* Look for TO or DOWNTO. */
6868 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6870 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6871 && ! is_part_of_name (input_line_pointer
[2]))
6873 initstop
= input_line_pointer
;
6874 input_line_pointer
+= 2;
6877 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6878 && ! is_part_of_name (input_line_pointer
[6]))
6880 initstop
= input_line_pointer
;
6882 input_line_pointer
+= 6;
6885 ++input_line_pointer
;
6887 if (initstop
== NULL
)
6889 as_bad (_("missing to or downto"));
6890 ignore_rest_of_line ();
6893 if (initstop
> initstart
6894 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6898 endstart
= input_line_pointer
;
6900 /* Look for BY or DO. */
6903 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6905 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6906 && ! is_part_of_name (input_line_pointer
[2]))
6908 endstop
= input_line_pointer
;
6910 input_line_pointer
+= 2;
6913 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6914 && (input_line_pointer
[2] == '.'
6915 || ! is_part_of_name (input_line_pointer
[2])))
6917 endstop
= input_line_pointer
;
6918 input_line_pointer
+= 2;
6921 ++input_line_pointer
;
6923 if (endstop
== NULL
)
6925 as_bad (_("missing do"));
6926 ignore_rest_of_line ();
6929 if (endstop
> endstart
6930 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6936 bystop
= bystart
+ 2;
6941 bystart
= input_line_pointer
;
6945 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6947 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6948 && (input_line_pointer
[2] == '.'
6949 || ! is_part_of_name (input_line_pointer
[2])))
6951 bystop
= input_line_pointer
;
6952 input_line_pointer
+= 2;
6955 ++input_line_pointer
;
6959 as_bad (_("missing do"));
6960 ignore_rest_of_line ();
6963 if (bystop
> bystart
6964 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6968 if (*input_line_pointer
!= '.')
6972 extent
= input_line_pointer
[1];
6973 input_line_pointer
+= 2;
6976 /* We have fully parsed the FOR operands. Now build the loop. */
6977 n
= push_mri_control (mri_for
);
6979 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6981 /* Move init,var. */
6988 *s
++ = TOLOWER (qual
);
6990 memcpy (s
, initstart
, initstop
- initstart
);
6991 s
+= initstop
- initstart
;
6993 memcpy (s
, varstart
, varstop
- varstart
);
6994 s
+= varstop
- varstart
;
7006 *s
++ = TOLOWER (qual
);
7008 memcpy (s
, endstart
, endstop
- endstart
);
7009 s
+= endstop
- endstart
;
7011 memcpy (s
, varstart
, varstop
- varstart
);
7012 s
+= varstop
- varstart
;
7017 ex
[0] = TOLOWER (extent
);
7020 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
7022 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
7025 /* Put together the add or sub instruction used by ENDF. */
7033 *s
++ = TOLOWER (qual
);
7035 memcpy (s
, bystart
, bystop
- bystart
);
7036 s
+= bystop
- bystart
;
7038 memcpy (s
, varstart
, varstop
- varstart
);
7039 s
+= varstop
- varstart
;
7045 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7046 ++input_line_pointer
;
7049 demand_empty_rest_of_line ();
7052 /* Handle the MRI ENDF pseudo-op. */
7055 s_mri_endf (int ignore ATTRIBUTE_UNUSED
)
7057 if (mri_control_stack
== NULL
7058 || mri_control_stack
->type
!= mri_for
)
7060 as_bad (_("endf without for"));
7061 ignore_rest_of_line ();
7065 colon (mri_control_stack
->next
);
7067 mri_assemble (mri_control_stack
->incr
);
7069 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
7070 mri_assemble (mri_control_stack
->incr
);
7072 free (mri_control_stack
->incr
);
7074 colon (mri_control_stack
->bottom
);
7080 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7081 ++input_line_pointer
;
7084 demand_empty_rest_of_line ();
7087 /* Handle the MRI REPEAT pseudo-op. */
7090 s_mri_repeat (int ignore ATTRIBUTE_UNUSED
)
7092 struct mri_control_info
*n
;
7094 n
= push_mri_control (mri_repeat
);
7098 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7099 ++input_line_pointer
;
7101 demand_empty_rest_of_line ();
7104 /* Handle the MRI UNTIL pseudo-op. */
7107 s_mri_until (int qual
)
7111 if (mri_control_stack
== NULL
7112 || mri_control_stack
->type
!= mri_repeat
)
7114 as_bad (_("until without repeat"));
7115 ignore_rest_of_line ();
7119 colon (mri_control_stack
->next
);
7121 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
7124 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
7125 mri_control_stack
->top
, '\0');
7127 colon (mri_control_stack
->bottom
);
7129 input_line_pointer
= s
;
7135 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7136 ++input_line_pointer
;
7139 demand_empty_rest_of_line ();
7142 /* Handle the MRI WHILE pseudo-op. */
7145 s_mri_while (int qual
)
7149 struct mri_control_info
*n
;
7151 s
= input_line_pointer
;
7152 /* We only accept '*' as introduction of comments if preceded by white space
7153 or at first column of a line (I think this can't actually happen here?)
7154 This is important when assembling:
7155 while d0 <ne> 12(a0,d0*2) do
7156 while d0 <ne> #CONST*20 do. */
7157 while (! (is_end_of_line
[(unsigned char) *s
]
7160 && (s
== input_line_pointer
7162 || *(s
-1) == '\t'))))
7165 while (*s
== ' ' || *s
== '\t')
7167 if (s
- input_line_pointer
> 1
7170 if (s
- input_line_pointer
< 2
7171 || strncasecmp (s
- 1, "DO", 2) != 0)
7173 as_bad (_("missing do"));
7174 ignore_rest_of_line ();
7178 n
= push_mri_control (mri_while
);
7182 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
7183 s
[1] == '.' ? s
[2] : '\0');
7185 input_line_pointer
= s
+ 1;
7186 if (*input_line_pointer
== '.')
7187 input_line_pointer
+= 2;
7191 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7192 ++input_line_pointer
;
7195 demand_empty_rest_of_line ();
7198 /* Handle the MRI ENDW pseudo-op. */
7201 s_mri_endw (int ignore ATTRIBUTE_UNUSED
)
7205 if (mri_control_stack
== NULL
7206 || mri_control_stack
->type
!= mri_while
)
7208 as_bad (_("endw without while"));
7209 ignore_rest_of_line ();
7213 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
7214 sprintf (buf
, "bra %s", mri_control_stack
->next
);
7218 colon (mri_control_stack
->bottom
);
7224 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7225 ++input_line_pointer
;
7228 demand_empty_rest_of_line ();
7231 /* Parse a .cpu directive. */
7234 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED
)
7241 as_bad (_("already assembled instructions"));
7242 ignore_rest_of_line ();
7246 name
= input_line_pointer
;
7247 while (*input_line_pointer
&& !ISSPACE(*input_line_pointer
))
7248 input_line_pointer
++;
7249 saved_char
= *input_line_pointer
;
7250 *input_line_pointer
= 0;
7252 m68k_set_cpu (name
, 1, 0);
7254 *input_line_pointer
= saved_char
;
7255 demand_empty_rest_of_line ();
7259 /* Parse a .arch directive. */
7262 s_m68k_arch (int ignored ATTRIBUTE_UNUSED
)
7269 as_bad (_("already assembled instructions"));
7270 ignore_rest_of_line ();
7274 name
= input_line_pointer
;
7275 while (*input_line_pointer
&& *input_line_pointer
!= ','
7276 && !ISSPACE (*input_line_pointer
))
7277 input_line_pointer
++;
7278 saved_char
= *input_line_pointer
;
7279 *input_line_pointer
= 0;
7281 if (m68k_set_arch (name
, 1, 0))
7283 /* Scan extensions. */
7286 *input_line_pointer
++ = saved_char
;
7287 if (!*input_line_pointer
|| ISSPACE (*input_line_pointer
))
7289 name
= input_line_pointer
;
7290 while (*input_line_pointer
&& *input_line_pointer
!= ','
7291 && !ISSPACE (*input_line_pointer
))
7292 input_line_pointer
++;
7293 saved_char
= *input_line_pointer
;
7294 *input_line_pointer
= 0;
7296 while (m68k_set_extension (name
, 1, 0));
7299 *input_line_pointer
= saved_char
;
7300 demand_empty_rest_of_line ();
7304 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
7305 if none is found, the caller is responsible for emitting an error
7306 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
7307 cpu name, if it begins with a '6' (possibly skipping an intervening
7308 'c'. We also allow a 'c' in the same place. if NEGATED is
7309 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
7310 the option is indeed negated. */
7312 static const struct m68k_cpu
*
7313 m68k_lookup_cpu (const char *arg
, const struct m68k_cpu
*table
,
7314 int allow_m
, int *negated
)
7316 /* allow negated value? */
7321 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
7328 /* Remove 'm' or 'mc' prefix from 68k variants. */
7335 else if (arg
[1] == 'c' && arg
[2] == '6')
7339 else if (arg
[0] == 'c' && arg
[1] == '6')
7342 for (; table
->name
; table
++)
7343 if (!strcmp (arg
, table
->name
))
7345 if (table
->alias
< -1 || table
->alias
> 1)
7346 as_bad (_("`%s' is deprecated, use `%s'"),
7347 table
->name
, table
[table
->alias
< 0 ? 1 : -1].name
);
7353 /* Set the cpu, issuing errors if it is unrecognized. */
7356 m68k_set_cpu (char const *name
, int allow_m
, int silent
)
7358 const struct m68k_cpu
*cpu
;
7360 cpu
= m68k_lookup_cpu (name
, m68k_cpus
, allow_m
, NULL
);
7365 as_bad (_("cpu `%s' unrecognized"), name
);
7372 /* Set the architecture, issuing errors if it is unrecognized. */
7375 m68k_set_arch (char const *name
, int allow_m
, int silent
)
7377 const struct m68k_cpu
*arch
;
7379 arch
= m68k_lookup_cpu (name
, m68k_archs
, allow_m
, NULL
);
7384 as_bad (_("architecture `%s' unrecognized"), name
);
7387 selected_arch
= arch
;
7391 /* Set the architecture extension, issuing errors if it is
7392 unrecognized, or invalid */
7395 m68k_set_extension (char const *name
, int allow_m
, int silent
)
7398 const struct m68k_cpu
*ext
;
7400 ext
= m68k_lookup_cpu (name
, m68k_extensions
, allow_m
, &negated
);
7405 as_bad (_("extension `%s' unrecognized"), name
);
7410 not_current_architecture
|= ext
->arch
;
7412 current_architecture
|= ext
->arch
;
7417 Invocation line includes a switch not recognized by the base assembler.
7421 const char *md_shortopts
= "lSA:m:kQ:V";
7423 const char *md_shortopts
= "lSA:m:k";
7426 struct option md_longopts
[] = {
7427 #define OPTION_PIC (OPTION_MD_BASE)
7428 {"pic", no_argument
, NULL
, OPTION_PIC
},
7429 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7430 {"register-prefix-optional", no_argument
, NULL
,
7431 OPTION_REGISTER_PREFIX_OPTIONAL
},
7432 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7433 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
7434 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7435 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
7436 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7437 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
7438 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7439 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
7440 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7441 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
7442 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7443 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
7444 {NULL
, no_argument
, NULL
, 0}
7446 size_t md_longopts_size
= sizeof (md_longopts
);
7449 md_parse_option (int c
, char *arg
)
7453 case 'l': /* -l means keep external to 2 bit offset
7454 rather than 16 bit one. */
7455 flag_short_refs
= 1;
7458 case 'S': /* -S means that jbsr's always turn into
7460 flag_long_jumps
= 1;
7463 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
7464 branches into absolute jumps. */
7465 flag_keep_pcrel
= 1;
7471 break; /* -pic, Position Independent Code. */
7473 case OPTION_REGISTER_PREFIX_OPTIONAL
:
7474 flag_reg_prefix_optional
= 1;
7475 reg_prefix_optional_seen
= 1;
7478 /* -V: SVR4 argument to print version ID. */
7480 print_version_id ();
7483 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7484 should be emitted or not. FIXME: Not implemented. */
7488 case OPTION_BITWISE_OR
:
7493 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
7495 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
7499 m68k_comment_chars
= n
;
7503 case OPTION_BASE_SIZE_DEFAULT_16
:
7504 m68k_index_width_default
= SIZE_WORD
;
7507 case OPTION_BASE_SIZE_DEFAULT_32
:
7508 m68k_index_width_default
= SIZE_LONG
;
7511 case OPTION_DISP_SIZE_DEFAULT_16
:
7513 m68k_rel32_from_cmdline
= 1;
7516 case OPTION_DISP_SIZE_DEFAULT_32
:
7518 m68k_rel32_from_cmdline
= 1;
7523 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7526 /* Intentional fall-through. */
7528 if (!strncmp (arg
, "arch=", 5))
7529 m68k_set_arch (arg
+ 5, 1, 0);
7530 else if (!strncmp (arg
, "cpu=", 4))
7531 m68k_set_cpu (arg
+ 4, 1, 0);
7532 else if (m68k_set_extension (arg
, 0, 1))
7534 else if (m68k_set_arch (arg
, 0, 1))
7536 else if (m68k_set_cpu (arg
, 0, 1))
7549 /* Setup tables from the selected arch and/or cpu */
7552 m68k_init_arch (void)
7554 if (not_current_architecture
& current_architecture
)
7556 as_bad (_("architecture features both enabled and disabled"));
7557 not_current_architecture
&= ~current_architecture
;
7561 current_architecture
|= selected_arch
->arch
;
7562 control_regs
= selected_arch
->control_regs
;
7565 current_architecture
|= selected_cpu
->arch
;
7567 current_architecture
&= ~not_current_architecture
;
7569 if ((current_architecture
& (cfloat
| m68881
)) == (cfloat
| m68881
))
7571 /* Determine which float is really meant. */
7572 if (current_architecture
& (m68k_mask
& ~m68881
))
7573 current_architecture
^= cfloat
;
7575 current_architecture
^= m68881
;
7580 control_regs
= selected_cpu
->control_regs
;
7581 if (current_architecture
& ~selected_cpu
->arch
)
7583 as_bad (_("selected processor does not have all features of selected architecture"));
7584 current_architecture
7585 = selected_cpu
->arch
& ~not_current_architecture
;
7589 if ((current_architecture
& m68k_mask
)
7590 && (current_architecture
& ~m68k_mask
))
7592 as_bad (_ ("m68k and cf features both selected"));
7593 if (current_architecture
& m68k_mask
)
7594 current_architecture
&= m68k_mask
;
7596 current_architecture
&= ~m68k_mask
;
7599 /* Permit m68881 specification with all cpus; those that can't work
7600 with a coprocessor could be doing emulation. */
7601 if (current_architecture
& m68851
)
7603 if (current_architecture
& m68040
)
7604 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7606 /* What other incompatibilities could we check for? */
7608 if (cpu_of_arch (current_architecture
) < m68020
7609 || arch_coldfire_p (current_architecture
))
7610 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
7616 md_show_usage (FILE *stream
)
7618 const char *default_cpu
= TARGET_CPU
;
7620 unsigned int default_arch
;
7622 /* Get the canonical name for the default target CPU. */
7623 if (*default_cpu
== 'm')
7625 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7627 if (strcasecmp (default_cpu
, m68k_cpus
[i
].name
) == 0)
7629 default_arch
= m68k_cpus
[i
].arch
;
7630 while (m68k_cpus
[i
].alias
> 0)
7632 while (m68k_cpus
[i
].alias
< 0)
7634 default_cpu
= m68k_cpus
[i
].name
;
7638 fprintf (stream
, _("\
7639 -march=<arch> set architecture\n\
7640 -mcpu=<cpu> set cpu [default %s]\n\
7642 for (i
= 0; m68k_extensions
[i
].name
; i
++)
7643 fprintf (stream
, _("\
7644 -m[no-]%-16s enable/disable%s architecture extension\n\
7645 "), m68k_extensions
[i
].name
,
7646 m68k_extensions
[i
].alias
> 0 ? " ColdFire"
7647 : m68k_extensions
[i
].alias
< 0 ? " m68k" : "");
7649 fprintf (stream
, _("\
7650 -l use 1 word for refs to undefined symbols [default 2]\n\
7651 -pic, -k generate position independent code\n\
7652 -S turn jbsr into jsr\n\
7653 --pcrel never turn PC-relative branches into absolute jumps\n\
7654 --register-prefix-optional\n\
7655 recognize register names without prefix character\n\
7656 --bitwise-or do not treat `|' as a comment character\n\
7657 --base-size-default-16 base reg without size is 16 bits\n\
7658 --base-size-default-32 base reg without size is 32 bits (default)\n\
7659 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7660 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7663 fprintf (stream
, _("Architecture variants are: "));
7664 for (i
= 0; m68k_archs
[i
].name
; i
++)
7667 fprintf (stream
, " | ");
7668 fprintf (stream
, m68k_archs
[i
].name
);
7670 fprintf (stream
, "\n");
7672 fprintf (stream
, _("Processor variants are: "));
7673 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7676 fprintf (stream
, " | ");
7677 fprintf (stream
, m68k_cpus
[i
].name
);
7679 fprintf (stream
, _("\n"));
7684 /* TEST2: Test md_assemble() */
7685 /* Warning, this routine probably doesn't work anymore. */
7689 struct m68k_it the_ins
;
7697 if (!gets (buf
) || !*buf
)
7699 if (buf
[0] == '|' || buf
[1] == '.')
7701 for (cp
= buf
; *cp
; cp
++)
7706 memset (&the_ins
, '\0', sizeof (the_ins
));
7707 m68k_ip (&the_ins
, buf
);
7710 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7714 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7715 for (n
= 0; n
< the_ins
.numo
; n
++)
7716 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7718 print_the_insn (&the_ins
.opcode
[0], stdout
);
7719 (void) putchar ('\n');
7721 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7723 if (the_ins
.operands
[n
].error
)
7725 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7728 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
,
7729 the_ins
.operands
[n
].reg
);
7730 if (the_ins
.operands
[n
].b_const
)
7731 printf ("Constant: '%.*s', ",
7732 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
,
7733 the_ins
.operands
[n
].b_const
);
7734 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
,
7735 the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7736 if (the_ins
.operands
[n
].b_iadd
)
7737 printf ("Iadd: '%.*s',",
7738 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
,
7739 the_ins
.operands
[n
].b_iadd
);
7748 is_label (char *str
)
7752 while (*str
&& *str
!= ' ')
7754 if (str
[-1] == ':' || str
[1] == '=')
7761 /* Possible states for relaxation:
7763 0 0 branch offset byte (bra, etc)
7767 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7771 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7778 /* We have no need to default values of symbols. */
7781 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
7786 /* Round up a section size to the appropriate boundary. */
7788 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
7791 /* For a.out, force the section size to be aligned. If we don't do
7792 this, BFD will align it for us, but it will not write out the
7793 final bytes of the section. This may be a bug in BFD, but it is
7794 easier to fix it here since that is how the other a.out targets
7798 align
= bfd_get_section_alignment (stdoutput
, segment
);
7799 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
7805 /* Exactly what point is a PC-relative offset relative TO?
7806 On the 68k, it is relative to the address of the first extension
7807 word. The difference between the addresses of the offset and the
7808 first extension word is stored in fx_pcrel_adjust. */
7810 md_pcrel_from (fixS
*fixP
)
7814 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7815 sign extend the value here. */
7816 adjust
= ((fixP
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80;
7819 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7824 m68k_elf_final_processing (void)
7828 if (arch_coldfire_fpu (current_architecture
))
7829 flags
|= EF_M68K_CFV4E
;
7830 /* Set file-specific flags if this is a cpu32 processor. */
7831 if (cpu_of_arch (current_architecture
) & cpu32
)
7832 flags
|= EF_M68K_CPU32
;
7833 else if (cpu_of_arch (current_architecture
) & fido_a
)
7834 flags
|= EF_M68K_FIDO
;
7835 else if ((cpu_of_arch (current_architecture
) & m68000up
)
7836 && !(cpu_of_arch (current_architecture
) & m68020up
))
7837 flags
|= EF_M68K_M68000
;
7839 if (current_architecture
& mcfisa_a
)
7841 static const unsigned isa_features
[][2] =
7843 {EF_M68K_CF_ISA_A_NODIV
,mcfisa_a
},
7844 {EF_M68K_CF_ISA_A
, mcfisa_a
|mcfhwdiv
},
7845 {EF_M68K_CF_ISA_A_PLUS
, mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfusp
},
7846 {EF_M68K_CF_ISA_B_NOUSP
,mcfisa_a
|mcfisa_b
|mcfhwdiv
},
7847 {EF_M68K_CF_ISA_B
, mcfisa_a
|mcfisa_b
|mcfhwdiv
|mcfusp
},
7848 {EF_M68K_CF_ISA_C
, mcfisa_a
|mcfisa_c
|mcfhwdiv
|mcfusp
},
7849 {EF_M68K_CF_ISA_C_NODIV
,mcfisa_a
|mcfisa_c
|mcfusp
},
7852 static const unsigned mac_features
[][2] =
7854 {EF_M68K_CF_MAC
, mcfmac
},
7855 {EF_M68K_CF_EMAC
, mcfemac
},
7861 pattern
= (current_architecture
7862 & (mcfisa_a
|mcfisa_aa
|mcfisa_b
|mcfisa_c
|mcfhwdiv
|mcfusp
));
7863 for (ix
= 0; isa_features
[ix
][1]; ix
++)
7865 if (pattern
== isa_features
[ix
][1])
7867 flags
|= isa_features
[ix
][0];
7871 if (!isa_features
[ix
][1])
7874 as_warn (_("Not a defined coldfire architecture"));
7878 if (current_architecture
& cfloat
)
7879 flags
|= EF_M68K_CF_FLOAT
| EF_M68K_CFV4E
;
7881 pattern
= current_architecture
& (mcfmac
|mcfemac
);
7884 for (ix
= 0; mac_features
[ix
][1]; ix
++)
7886 if (pattern
== mac_features
[ix
][1])
7888 flags
|= mac_features
[ix
][0];
7892 if (!mac_features
[ix
][1])
7897 elf_elfheader (stdoutput
)->e_flags
|= flags
;
7900 /* Parse @TLSLDO and return the desired relocation. */
7901 static bfd_reloc_code_real_type
7902 m68k_elf_suffix (char **str_p
, expressionS
*exp_p
)
7911 return BFD_RELOC_UNUSED
;
7913 for (ch
= *str
, str2
= ident
;
7914 (str2
< ident
+ sizeof (ident
) - 1
7915 && (ISALNUM (ch
) || ch
== '@'));
7924 if (strncmp (ident
, "TLSLDO", 6) == 0
7927 /* Now check for identifier@suffix+constant. */
7928 if (*str
== '-' || *str
== '+')
7930 char *orig_line
= input_line_pointer
;
7931 expressionS new_exp
;
7933 input_line_pointer
= str
;
7934 expression (&new_exp
);
7935 if (new_exp
.X_op
== O_constant
)
7937 exp_p
->X_add_number
+= new_exp
.X_add_number
;
7938 str
= input_line_pointer
;
7941 if (&input_line_pointer
!= str_p
)
7942 input_line_pointer
= orig_line
;
7946 return BFD_RELOC_68K_TLS_LDO32
;
7949 return BFD_RELOC_UNUSED
;
7952 /* Handles .long <tls_symbol>+0x8000 debug info.
7953 Clobbers input_line_pointer, checks end-of-line.
7954 Adapted from tc-ppc.c:ppc_elf_cons. */
7956 m68k_elf_cons (int nbytes
/* 4=.long */)
7958 if (is_it_end_of_statement ())
7960 demand_empty_rest_of_line ();
7967 bfd_reloc_code_real_type reloc
;
7970 if (exp
.X_op
== O_symbol
7971 && *input_line_pointer
== '@'
7972 && (reloc
= m68k_elf_suffix (&input_line_pointer
,
7973 &exp
)) != BFD_RELOC_UNUSED
)
7975 reloc_howto_type
*reloc_howto
;
7978 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
7979 size
= bfd_get_reloc_size (reloc_howto
);
7983 as_bad (_("%s relocations do not fit in %d bytes\n"),
7984 reloc_howto
->name
, nbytes
);
7991 p
= frag_more (nbytes
);
7993 if (target_big_endian
)
7994 offset
= nbytes
- size
;
7995 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
8000 emit_expr (&exp
, (unsigned int) nbytes
);
8002 while (*input_line_pointer
++ == ',');
8004 /* Put terminator back into stream. */
8005 input_line_pointer
--;
8006 demand_empty_rest_of_line ();
8011 tc_m68k_regname_to_dw2regnum (char *regname
)
8013 unsigned int regnum
;
8014 static const char *const regnames
[] =
8016 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
8017 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
8018 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
8022 for (regnum
= 0; regnum
< ARRAY_SIZE (regnames
); regnum
++)
8023 if (strcmp (regname
, regnames
[regnum
]) == 0)
8030 tc_m68k_frame_initial_instructions (void)
8032 static int sp_regno
= -1;
8035 sp_regno
= tc_m68k_regname_to_dw2regnum ("sp");
8037 cfi_add_CFA_def_cfa (sp_regno
, -DWARF2_CIE_DATA_ALIGNMENT
);
8038 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN
, DWARF2_CIE_DATA_ALIGNMENT
);