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 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "safe-ctype.h"
26 #include "dwarf2dbg.h"
27 #include "dw2gencfi.h"
29 #include "opcode/m68k.h"
30 #include "m68k-parse.h"
40 /* This string holds the chars that always start a comment. If the
41 pre-processor is disabled, these aren't very useful. The macro
42 tc_comment_chars points to this. We use this, rather than the
43 usual comment_chars, so that the --bitwise-or option will work. */
44 #if defined (TE_SVR4) || defined (TE_DELTA)
45 const char *m68k_comment_chars
= "|#";
47 const char *m68k_comment_chars
= "|";
50 /* This array holds the chars that only start a comment at the beginning of
51 a line. If the line seems to have the form '# 123 filename'
52 .line and .file directives will appear in the pre-processed output */
53 /* Note that input_file.c hand checks for '#' at the beginning of the
54 first line of the input file. This is because the compiler outputs
55 #NO_APP at the beginning of its output. */
56 /* Also note that comments like this one will always work. */
57 const char line_comment_chars
[] = "#*";
59 const char line_separator_chars
[] = ";";
61 /* Chars that can be used to separate mant from exp in floating point nums. */
62 const char EXP_CHARS
[] = "eE";
64 /* Chars that mean this number is a floating point constant, as
65 in "0f12.456" or "0d1.2345e12". */
67 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
69 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
70 changed in read.c . Ideally it shouldn't have to know about it at all,
71 but nothing is ideal around here. */
73 const int md_reloc_size
= 8; /* Size of relocation record. */
75 /* Are we trying to generate PIC code? If so, absolute references
76 ought to be made into linkage table references or pc-relative
77 references. Not implemented. For ELF there are other means
78 to denote pic relocations. */
81 static int flag_short_refs
; /* -l option. */
82 static int flag_long_jumps
; /* -S option. */
83 static int flag_keep_pcrel
; /* --pcrel option. */
85 #ifdef REGISTER_PREFIX_OPTIONAL
86 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
88 int flag_reg_prefix_optional
;
91 /* Whether --register-prefix-optional was used on the command line. */
92 static int reg_prefix_optional_seen
;
94 /* The floating point coprocessor to use by default. */
95 static enum m68k_register m68k_float_copnum
= COP1
;
97 /* If this is non-zero, then references to number(%pc) will be taken
98 to refer to number, rather than to %pc + number. */
99 static int m68k_abspcadd
;
101 /* If this is non-zero, then the quick forms of the move, add, and sub
102 instructions are used when possible. */
103 static int m68k_quick
= 1;
105 /* If this is non-zero, then if the size is not specified for a base
106 or outer displacement, the assembler assumes that the size should
108 static int m68k_rel32
= 1;
110 /* This is non-zero if m68k_rel32 was set from the command line. */
111 static int m68k_rel32_from_cmdline
;
113 /* The default width to use for an index register when using a base
115 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
117 /* We want to warn if any text labels are misaligned. In order to get
118 the right line number, we need to record the line number for each
122 struct label_line
*next
;
129 /* The list of labels. */
131 static struct label_line
*labels
;
133 /* The current label. */
135 static struct label_line
*current_label
;
137 /* Pointer to list holding the opcodes sorted by name. */
138 static struct m68k_opcode
const ** m68k_sorted_opcodes
;
140 /* Its an arbitrary name: This means I don't approve of it.
142 static struct obstack robyn
;
146 const char *m_operands
;
147 unsigned long m_opcode
;
151 struct m68k_incant
*m_next
;
154 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
155 #define gettwo(x) (((x)->m_opcode)&0xffff)
157 static const enum m68k_register m68000_control_regs
[] = { 0 };
158 static const enum m68k_register m68010_control_regs
[] = {
162 static const enum m68k_register m68020_control_regs
[] = {
163 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
166 static const enum m68k_register m68040_control_regs
[] = {
167 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
168 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
171 static const enum m68k_register m68060_control_regs
[] = {
172 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
173 USP
, VBR
, URP
, SRP
, PCR
,
176 static const enum m68k_register mcf_control_regs
[] = {
177 CACR
, TC
, ACR0
, ACR1
, ACR2
, ACR3
, VBR
, ROMBAR
,
178 RAMBAR0
, RAMBAR1
, MBAR
,
181 static const enum m68k_register mcf5249_control_regs
[] = {
182 CACR
, ACR0
, ACR1
, VBR
, RAMBAR0
, RAMBAR1
, MBAR
, MBAR2
,
185 static const enum m68k_register mcf528x_control_regs
[] = {
186 CACR
, ACR0
, ACR1
, VBR
, FLASHBAR
, RAMBAR
,
189 static const enum m68k_register mcfv4e_control_regs
[] = {
190 CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
, VBR
, PC
, ROMBAR
,
191 ROMBAR1
, RAMBAR0
, RAMBAR1
, MPCR
, EDRAMBAR
, SECMBAR
, MBAR
, MBAR0
, MBAR1
,
192 PCR1U0
, PCR1L0
, PCR1U1
, PCR1L1
, PCR2U0
, PCR2L0
, PCR2U1
, PCR2L1
,
193 PCR3U0
, PCR3L0
, PCR3U1
, PCR3L1
,
196 #define cpu32_control_regs m68010_control_regs
198 static const enum m68k_register
*control_regs
;
200 /* Internal form of a 68020 instruction. */
204 const char *args
; /* List of opcode info. */
207 int numo
; /* Number of shorts in opcode. */
210 struct m68k_op operands
[6];
212 int nexp
; /* Number of exprs in use. */
213 struct m68k_exp exprs
[4];
215 int nfrag
; /* Number of frags we have to produce. */
218 int fragoff
; /* Where in the current opcode the frag ends. */
225 int nrel
; /* Num of reloc strucs in use. */
232 /* In a pc relative address the difference between the address
233 of the offset and the address that the offset is relative
234 to. This depends on the addressing mode. Basically this
235 is the value to put in the offset field to address the
236 first byte of the offset, without regarding the special
237 significance of some values (in the branch instruction, for
241 /* Whether this expression needs special pic relocation, and if
243 enum pic_relocation pic_reloc
;
246 reloc
[5]; /* Five is enough??? */
249 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a))
250 #define float_of_arch(x) ((x) & mfloat)
251 #define mmu_of_arch(x) ((x) & mmmu)
252 #define arch_coldfire_p(x) ((x) & mcfisa_a)
253 #define arch_coldfire_fpu(x) ((x) & cfloat)
255 /* Macros for determining if cpu supports a specific addressing mode. */
256 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcfisa_b))
258 static struct m68k_it the_ins
; /* The instruction being assembled. */
260 #define op(ex) ((ex)->exp.X_op)
261 #define adds(ex) ((ex)->exp.X_add_symbol)
262 #define subs(ex) ((ex)->exp.X_op_symbol)
263 #define offs(ex) ((ex)->exp.X_add_number)
265 /* Macros for adding things to the m68k_it struct. */
266 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
268 /* Like addword, but goes BEFORE general operands. */
271 insop (int w
, const struct m68k_incant
*opcode
)
274 for (z
= the_ins
.numo
; z
> opcode
->m_codenum
; --z
)
275 the_ins
.opcode
[z
] = the_ins
.opcode
[z
- 1];
276 for (z
= 0; z
< the_ins
.nrel
; z
++)
277 the_ins
.reloc
[z
].n
+= 2;
278 for (z
= 0; z
< the_ins
.nfrag
; z
++)
279 the_ins
.fragb
[z
].fragoff
++;
280 the_ins
.opcode
[opcode
->m_codenum
] = w
;
284 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
287 add_fix (int width
, struct m68k_exp
*exp
, int pc_rel
, int pc_fix
)
289 the_ins
.reloc
[the_ins
.nrel
].n
= (width
== 'B' || width
== '3'
290 ? the_ins
.numo
* 2 - 1
292 ? the_ins
.numo
* 2 + 1
293 : the_ins
.numo
* 2));
294 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
295 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
296 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
298 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
300 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
303 /* Cause an extra frag to be generated here, inserting up to 10 bytes
304 (that value is chosen in the frag_var call in md_assemble). TYPE
305 is the subtype of the frag to be generated; its primary type is
306 rs_machine_dependent.
308 The TYPE parameter is also used by md_convert_frag_1 and
309 md_estimate_size_before_relax. The appropriate type of fixup will
310 be emitted by md_convert_frag_1.
312 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
314 add_frag (symbolS
*add
, offsetT off
, int type
)
316 the_ins
.fragb
[the_ins
.nfrag
].fragoff
= the_ins
.numo
;
317 the_ins
.fragb
[the_ins
.nfrag
].fadd
= add
;
318 the_ins
.fragb
[the_ins
.nfrag
].foff
= off
;
319 the_ins
.fragb
[the_ins
.nfrag
++].fragty
= type
;
323 (op (ex) != O_constant && op (ex) != O_big)
325 static char *crack_operand (char *str
, struct m68k_op
*opP
);
326 static int get_num (struct m68k_exp
*exp
, int ok
);
327 static int reverse_16_bits (int in
);
328 static int reverse_8_bits (int in
);
329 static void install_gen_operand (int mode
, int val
);
330 static void install_operand (int mode
, int val
);
331 static void s_bss (int);
332 static void s_data1 (int);
333 static void s_data2 (int);
334 static void s_even (int);
335 static void s_proc (int);
336 static void s_chip (int);
337 static void s_fopt (int);
338 static void s_opt (int);
339 static void s_reg (int);
340 static void s_restore (int);
341 static void s_save (int);
342 static void s_mri_if (int);
343 static void s_mri_else (int);
344 static void s_mri_endi (int);
345 static void s_mri_break (int);
346 static void s_mri_next (int);
347 static void s_mri_for (int);
348 static void s_mri_endf (int);
349 static void s_mri_repeat (int);
350 static void s_mri_until (int);
351 static void s_mri_while (int);
352 static void s_mri_endw (int);
354 static int current_architecture
;
355 static int current_chip
;
365 static const struct m68k_cpu archs
[] =
367 { m68000
, m68000
, "68000", 0 },
368 { m68010
, m68010
, "68010", 0 },
369 { m68020
, m68020
, "68020", 0 },
370 { m68030
, m68030
, "68030", 0 },
371 { m68040
, m68040
, "68040", 0 },
372 { m68060
, m68060
, "68060", 0 },
373 { cpu32
, cpu32
, "cpu32", 0 },
374 { m68881
, m68881
, "68881", 0 },
375 { m68851
, m68851
, "68851", 0 },
376 { mcfisa_a
, mcf5200
, "5200", 0 },
377 { mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5206e
, "5206e", 0 },
378 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf521x
, "521x", 0 },
379 { mcfisa_a
|mcfhwdiv
|mcfemac
, mcf5249
, "5249", 0 },
380 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
, mcf528x
, "528x", 0 },
381 { mcfisa_a
|mcfhwdiv
|mcfmac
, mcf5307
, "5307", 0 },
382 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
, mcf5407
, "5407", 0 },
383 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "547x", 0 },
384 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5480
, "548x", 0 },
385 /* Aliases (effectively, so far as gas is concerned) for the above
387 { m68020
, m68020
, "68k", 1 },
388 { m68000
, m68000
, "68008", 1 },
389 { m68000
, m68000
, "68302", 1 },
390 { m68000
, m68000
, "68306", 1 },
391 { m68000
, m68000
, "68307", 1 },
392 { m68000
, m68000
, "68322", 1 },
393 { m68000
, m68000
, "68356", 1 },
394 { m68000
, m68000
, "68ec000", 1 },
395 { m68000
, m68000
, "68hc000", 1 },
396 { m68000
, m68000
, "68hc001", 1 },
397 { m68020
, m68020
, "68ec020", 1 },
398 { m68030
, m68030
, "68ec030", 1 },
399 { m68040
, m68040
, "68ec040", 1 },
400 { m68060
, m68060
, "68ec060", 1 },
401 { cpu32
, cpu32
, "68330", 1 },
402 { cpu32
, cpu32
, "68331", 1 },
403 { cpu32
, cpu32
, "68332", 1 },
404 { cpu32
, cpu32
, "68333", 1 },
405 { cpu32
, cpu32
, "68334", 1 },
406 { cpu32
, cpu32
, "68336", 1 },
407 { cpu32
, cpu32
, "68340", 1 },
408 { cpu32
, cpu32
, "68341", 1 },
409 { cpu32
, cpu32
, "68349", 1 },
410 { cpu32
, cpu32
, "68360", 1 },
411 { m68881
, m68881
, "68882", 1 },
412 { mcfisa_a
, mcf5200
, "5202", 1 },
413 { mcfisa_a
, mcf5200
, "5204", 1 },
414 { mcfisa_a
, mcf5200
, "5206", 1 },
415 { mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfemac
, mcf521x
, "5214", 1 },
416 { mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfemac
, mcf521x
, "5216", 1 },
417 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, mcf528x
, "5280", 1 },
418 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, mcf528x
, "5281", 1 },
419 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, mcf528x
, "5282", 1 },
420 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
, mcf5407
, "cfv4", 1 },
421 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5470", 1 },
422 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5471", 1 },
423 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5472", 1 },
424 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5473", 1 },
425 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5474", 1 },
426 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5475", 1 },
427 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5480", 1 },
428 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5481", 1 },
429 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5482", 1 },
430 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5483", 1 },
431 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5484", 1 },
432 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "5485", 1 },
433 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
, mcf5470
, "cfv4e", 1 },
436 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
438 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
439 architecture and we have a lot of relaxation modes. */
441 /* Macros used in the relaxation code. */
442 #define TAB(x,y) (((x) << 2) + (y))
443 #define TABTYPE(x) ((x) >> 2)
445 /* Relaxation states. */
451 /* Here are all the relaxation modes we support. First we can relax ordinary
452 branches. On 68020 and higher and on CPU32 all branch instructions take
453 three forms, so on these CPUs all branches always remain as such. When we
454 have to expand to the LONG form on a 68000, though, we substitute an
455 absolute jump instead. This is a direct replacement for unconditional
456 branches and a branch over a jump for conditional branches. However, if the
457 user requires PIC and disables this with --pcrel, we can only relax between
458 BYTE and SHORT forms, punting if that isn't enough. This gives us four
459 different relaxation modes for branches: */
461 #define BRANCHBWL 0 /* Branch byte, word, or long. */
462 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
463 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
464 #define BRANCHBW 3 /* Branch byte or word. */
466 /* We also relax coprocessor branches and DBcc's. All CPUs that support
467 coprocessor branches support them in word and long forms, so we have only
468 one relaxation mode for them. DBcc's are word only on all CPUs. We can
469 relax them to the LONG form with a branch-around sequence. This sequence
470 can use a long branch (if available) or an absolute jump (if acceptable).
471 This gives us two relaxation modes. If long branches are not available and
472 absolute jumps are not acceptable, we don't relax DBcc's. */
474 #define FBRANCH 4 /* Coprocessor branch. */
475 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
476 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
478 /* That's all for instruction relaxation. However, we also relax PC-relative
479 operands. Specifically, we have three operand relaxation modes. On the
480 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
481 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
482 two. Also PC+displacement+index operands in their simple form (with a non-
483 suppressed index without memory indirection) are supported on all CPUs, but
484 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
485 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
486 form of the PC+displacement+index operand. Finally, some absolute operands
487 can be relaxed down to 16-bit PC-relative. */
489 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
490 #define PCINDEX 8 /* PC + displacement + index. */
491 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
493 /* Note that calls to frag_var need to specify the maximum expansion
494 needed; this is currently 10 bytes for DBCC. */
497 How far Forward this mode will reach:
498 How far Backward this mode will reach:
499 How many bytes this mode will add to the size of the frag
500 Which mode to go to if the offset won't fit in this one
502 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
503 relax_typeS md_relax_table
[] =
505 { 127, -128, 0, TAB (BRANCHBWL
, SHORT
) },
506 { 32767, -32768, 2, TAB (BRANCHBWL
, LONG
) },
510 { 127, -128, 0, TAB (BRABSJUNC
, SHORT
) },
511 { 32767, -32768, 2, TAB (BRABSJUNC
, LONG
) },
515 { 127, -128, 0, TAB (BRABSJCOND
, SHORT
) },
516 { 32767, -32768, 2, TAB (BRABSJCOND
, LONG
) },
520 { 127, -128, 0, TAB (BRANCHBW
, SHORT
) },
525 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
526 { 32767, -32768, 2, TAB (FBRANCH
, LONG
) },
530 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
531 { 32767, -32768, 2, TAB (DBCCLBR
, LONG
) },
535 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
536 { 32767, -32768, 2, TAB (DBCCABSJ
, LONG
) },
540 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
541 { 32767, -32768, 2, TAB (PCREL1632
, LONG
) },
545 { 125, -130, 0, TAB (PCINDEX
, SHORT
) },
546 { 32765, -32770, 2, TAB (PCINDEX
, LONG
) },
550 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
551 { 32767, -32768, 2, TAB (ABSTOPCREL
, LONG
) },
556 /* These are the machine dependent pseudo-ops. These are included so
557 the assembler can work on the output from the SUN C compiler, which
560 /* This table describes all the machine specific pseudo-ops the assembler
561 has to support. The fields are:
562 pseudo-op name without dot
563 function to call to execute this pseudo-op
564 Integer arg to pass to the function. */
565 const pseudo_typeS md_pseudo_table
[] =
567 {"data1", s_data1
, 0},
568 {"data2", s_data2
, 0},
571 {"skip", s_space
, 0},
573 #if defined (TE_SUN3) || defined (OBJ_ELF)
574 {"align", s_align_bytes
, 0},
577 {"swbeg", s_ignore
, 0},
579 {"extend", float_cons
, 'x'},
580 {"ldouble", float_cons
, 'x'},
582 /* The following pseudo-ops are supported for MRI compatibility. */
584 {"comline", s_space
, 1},
586 {"mask2", s_ignore
, 0},
589 {"restore", s_restore
, 0},
593 {"if.b", s_mri_if
, 'b'},
594 {"if.w", s_mri_if
, 'w'},
595 {"if.l", s_mri_if
, 'l'},
596 {"else", s_mri_else
, 0},
597 {"else.s", s_mri_else
, 's'},
598 {"else.l", s_mri_else
, 'l'},
599 {"endi", s_mri_endi
, 0},
600 {"break", s_mri_break
, 0},
601 {"break.s", s_mri_break
, 's'},
602 {"break.l", s_mri_break
, 'l'},
603 {"next", s_mri_next
, 0},
604 {"next.s", s_mri_next
, 's'},
605 {"next.l", s_mri_next
, 'l'},
606 {"for", s_mri_for
, 0},
607 {"for.b", s_mri_for
, 'b'},
608 {"for.w", s_mri_for
, 'w'},
609 {"for.l", s_mri_for
, 'l'},
610 {"endf", s_mri_endf
, 0},
611 {"repeat", s_mri_repeat
, 0},
612 {"until", s_mri_until
, 0},
613 {"until.b", s_mri_until
, 'b'},
614 {"until.w", s_mri_until
, 'w'},
615 {"until.l", s_mri_until
, 'l'},
616 {"while", s_mri_while
, 0},
617 {"while.b", s_mri_while
, 'b'},
618 {"while.w", s_mri_while
, 'w'},
619 {"while.l", s_mri_while
, 'l'},
620 {"endw", s_mri_endw
, 0},
625 /* The mote pseudo ops are put into the opcode table, since they
626 don't start with a . they look like opcodes to gas. */
628 const pseudo_typeS mote_pseudo_table
[] =
641 {"xdef", s_globl
, 0},
643 {"align", s_align_bytes
, 0},
645 {"align", s_align_ptwo
, 0},
648 {"sect", obj_coff_section
, 0},
649 {"section", obj_coff_section
, 0},
654 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
655 gives identical results to a 32-bit host. */
656 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
657 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
659 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
660 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
661 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
662 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
664 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
665 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
666 #define islong(x) (1)
668 static char notend_table
[256];
669 static char alt_notend_table
[256];
671 (! (notend_table[(unsigned char) *s] \
673 && alt_notend_table[(unsigned char) s[1]])))
675 /* Return a human readable string holding the list of chips that are
676 valid for a particular architecture, suppressing aliases (unless
677 there is only one of them). */
680 find_cf_chip (int architecture
)
682 static char buf
[1024];
683 int i
, j
, n_chips
, n_alias
;
687 cp
= buf
+ strlen (buf
);
689 for (i
= 0, n_chips
= 0, n_alias
= 0; i
< n_archs
; ++i
)
690 if (archs
[i
].arch
& architecture
)
698 as_fatal (_("no matching ColdFire architectures found"));
703 for (i
= 0, j
= 0; i
< n_archs
&& j
< n_chips
; ++i
)
704 if (archs
[i
].arch
& architecture
)
708 if ((j
== n_chips
- 1 && !(n_alias
> 1)) || ! n_alias
)
712 strncpy (cp
, _(" or "), (sizeof (buf
) - (cp
- buf
)));
717 strncpy (cp
, _(", or "), (sizeof (buf
) - (cp
- buf
)));
723 strncpy (cp
, ", ", (sizeof (buf
) - (cp
- buf
)));
727 strncpy (cp
, archs
[i
].name
, (sizeof (buf
) - (cp
- buf
)));
734 strncpy (cp
, _(", or aliases"), (sizeof (buf
) - (cp
- buf
)));
738 strncpy (cp
, ")", (sizeof (buf
) - (cp
- buf
)));
743 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
745 #ifdef NO_PCREL_RELOCS
748 make_pcrel_absolute (fixS
*fixP
, long *add_number
)
750 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
752 /* Rewrite the PC relative instructions to absolute address ones.
753 these are rumored to be faster, and the apollo linker refuses
754 to deal with the PC relative relocations. */
755 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP. */
758 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
762 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR. */
765 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
770 as_fatal (_("Unknown PC relative instruction"));
775 #endif /* NO_PCREL_RELOCS */
778 tc_coff_fix2rtype (fixS
*fixP
)
780 if (fixP
->fx_tcbit
&& fixP
->fx_size
== 4)
781 return R_RELLONG_NEG
;
782 #ifdef NO_PCREL_RELOCS
783 know (fixP
->fx_pcrel
== 0);
784 return (fixP
->fx_size
== 1 ? R_RELBYTE
785 : fixP
->fx_size
== 2 ? R_DIR16
788 return (fixP
->fx_pcrel
789 ? (fixP
->fx_size
== 1 ? R_PCRBYTE
790 : fixP
->fx_size
== 2 ? R_PCRWORD
792 : (fixP
->fx_size
== 1 ? R_RELBYTE
793 : fixP
->fx_size
== 2 ? R_RELWORD
802 /* Return zero if the reference to SYMBOL from within the same segment may
805 /* On an ELF system, we can't relax an externally visible symbol,
806 because it may be overridden by a shared library. However, if
807 TARGET_OS is "elf", then we presume that we are assembling for an
808 embedded system, in which case we don't have to worry about shared
809 libraries, and we can relax any external sym. */
811 #define relaxable_symbol(symbol) \
812 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
813 || S_IS_WEAK (symbol)))
815 /* Compute the relocation code for a fixup of SIZE bytes, using pc
816 relative relocation if PCREL is non-zero. PIC says whether a special
817 pic relocation was requested. */
819 static bfd_reloc_code_real_type
820 get_reloc_code (int size
, int pcrel
, enum pic_relocation pic
)
828 return BFD_RELOC_8_GOT_PCREL
;
830 return BFD_RELOC_16_GOT_PCREL
;
832 return BFD_RELOC_32_GOT_PCREL
;
840 return BFD_RELOC_8_GOTOFF
;
842 return BFD_RELOC_16_GOTOFF
;
844 return BFD_RELOC_32_GOTOFF
;
852 return BFD_RELOC_8_PLT_PCREL
;
854 return BFD_RELOC_16_PLT_PCREL
;
856 return BFD_RELOC_32_PLT_PCREL
;
864 return BFD_RELOC_8_PLTOFF
;
866 return BFD_RELOC_16_PLTOFF
;
868 return BFD_RELOC_32_PLTOFF
;
878 return BFD_RELOC_8_PCREL
;
880 return BFD_RELOC_16_PCREL
;
882 return BFD_RELOC_32_PCREL
;
902 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
904 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
909 as_bad (_("Can not do %d byte relocation"), size
);
911 as_bad (_("Can not do %d byte pic relocation"), size
);
914 return BFD_RELOC_NONE
;
917 /* Here we decide which fixups can be adjusted to make them relative
918 to the beginning of the section instead of the symbol. Basically
919 we need to make sure that the dynamic relocations are done
920 correctly, so in some cases we force the original symbol to be
923 tc_m68k_fix_adjustable (fixS
*fixP
)
925 /* Adjust_reloc_syms doesn't know about the GOT. */
926 switch (fixP
->fx_r_type
)
928 case BFD_RELOC_8_GOT_PCREL
:
929 case BFD_RELOC_16_GOT_PCREL
:
930 case BFD_RELOC_32_GOT_PCREL
:
931 case BFD_RELOC_8_GOTOFF
:
932 case BFD_RELOC_16_GOTOFF
:
933 case BFD_RELOC_32_GOTOFF
:
934 case BFD_RELOC_8_PLT_PCREL
:
935 case BFD_RELOC_16_PLT_PCREL
:
936 case BFD_RELOC_32_PLT_PCREL
:
937 case BFD_RELOC_8_PLTOFF
:
938 case BFD_RELOC_16_PLTOFF
:
939 case BFD_RELOC_32_PLTOFF
:
942 case BFD_RELOC_VTABLE_INHERIT
:
943 case BFD_RELOC_VTABLE_ENTRY
:
953 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
955 #define relaxable_symbol(symbol) 1
962 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
965 bfd_reloc_code_real_type code
;
967 /* If the tcbit is set, then this was a fixup of a negative value
968 that was never resolved. We do not have a reloc to handle this,
969 so just return. We assume that other code will have detected this
970 situation and produced a helpful error message, so we just tell the
971 user that the reloc cannot be produced. */
975 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
976 _("Unable to produce reloc against symbol '%s'"),
977 S_GET_NAME (fixp
->fx_addsy
));
981 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
983 code
= fixp
->fx_r_type
;
985 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
986 that fixup_segment converted a non-PC relative reloc into a
987 PC relative reloc. In such a case, we need to convert the
994 code
= BFD_RELOC_8_PCREL
;
997 code
= BFD_RELOC_16_PCREL
;
1000 code
= BFD_RELOC_32_PCREL
;
1002 case BFD_RELOC_8_PCREL
:
1003 case BFD_RELOC_16_PCREL
:
1004 case BFD_RELOC_32_PCREL
:
1005 case BFD_RELOC_8_GOT_PCREL
:
1006 case BFD_RELOC_16_GOT_PCREL
:
1007 case BFD_RELOC_32_GOT_PCREL
:
1008 case BFD_RELOC_8_GOTOFF
:
1009 case BFD_RELOC_16_GOTOFF
:
1010 case BFD_RELOC_32_GOTOFF
:
1011 case BFD_RELOC_8_PLT_PCREL
:
1012 case BFD_RELOC_16_PLT_PCREL
:
1013 case BFD_RELOC_32_PLT_PCREL
:
1014 case BFD_RELOC_8_PLTOFF
:
1015 case BFD_RELOC_16_PLTOFF
:
1016 case BFD_RELOC_32_PLTOFF
:
1019 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1020 _("Cannot make %s relocation PC relative"),
1021 bfd_get_reloc_code_name (code
));
1027 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1028 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1030 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1031 MAP (1, 0, BFD_RELOC_8
);
1032 MAP (2, 0, BFD_RELOC_16
);
1033 MAP (4, 0, BFD_RELOC_32
);
1034 MAP (1, 1, BFD_RELOC_8_PCREL
);
1035 MAP (2, 1, BFD_RELOC_16_PCREL
);
1036 MAP (4, 1, BFD_RELOC_32_PCREL
);
1044 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1045 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1046 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1047 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1050 reloc
->addend
= fixp
->fx_addnumber
;
1054 if (!fixp
->fx_pcrel
)
1055 reloc
->addend
= fixp
->fx_addnumber
;
1057 reloc
->addend
= (section
->vma
1058 /* Explicit sign extension in case char is
1060 + ((fixp
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80
1061 + fixp
->fx_addnumber
1062 + md_pcrel_from (fixp
));
1065 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1066 assert (reloc
->howto
!= 0);
1071 #endif /* BFD_ASSEMBLER */
1073 /* Handle of the OPCODE hash table. NULL means any use before
1074 m68k_ip_begin() will crash. */
1075 static struct hash_control
*op_hash
;
1077 /* Assemble an m68k instruction. */
1080 m68k_ip (char *instring
)
1083 register struct m68k_op
*opP
;
1084 register const struct m68k_incant
*opcode
;
1085 register const char *s
;
1086 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1087 char *pdot
, *pdotmove
;
1088 enum m68k_size siz1
, siz2
;
1092 LITTLENUM_TYPE words
[6];
1093 LITTLENUM_TYPE
*wordp
;
1094 unsigned long ok_arch
= 0;
1096 if (*instring
== ' ')
1097 instring
++; /* Skip leading whitespace. */
1099 /* Scan up to end of operation-code, which MUST end in end-of-string
1100 or exactly 1 space. */
1102 for (p
= instring
; *p
!= '\0'; p
++)
1112 the_ins
.error
= _("No operator");
1116 /* p now points to the end of the opcode name, probably whitespace.
1117 Make sure the name is null terminated by clobbering the
1118 whitespace, look it up in the hash table, then fix it back.
1119 Remove a dot, first, since the opcode tables have none. */
1122 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1123 *pdotmove
= pdotmove
[1];
1129 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1134 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1135 *pdotmove
= pdotmove
[-1];
1142 the_ins
.error
= _("Unknown operator");
1146 /* Found a legitimate opcode, start matching operands. */
1150 if (opcode
->m_operands
== 0)
1152 char *old
= input_line_pointer
;
1154 input_line_pointer
= p
;
1155 /* Ahh - it's a motorola style psuedo op. */
1156 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1157 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1158 input_line_pointer
= old
;
1164 if (flag_mri
&& opcode
->m_opnum
== 0)
1166 /* In MRI mode, random garbage is allowed after an instruction
1167 which accepts no operands. */
1168 the_ins
.args
= opcode
->m_operands
;
1169 the_ins
.numargs
= opcode
->m_opnum
;
1170 the_ins
.numo
= opcode
->m_codenum
;
1171 the_ins
.opcode
[0] = getone (opcode
);
1172 the_ins
.opcode
[1] = gettwo (opcode
);
1176 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1178 p
= crack_operand (p
, opP
);
1182 the_ins
.error
= opP
->error
;
1187 opsfound
= opP
- &the_ins
.operands
[0];
1189 /* This ugly hack is to support the floating pt opcodes in their
1190 standard form. Essentially, we fake a first enty of type COP#1 */
1191 if (opcode
->m_operands
[0] == 'I')
1195 for (n
= opsfound
; n
> 0; --n
)
1196 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1198 memset (&the_ins
.operands
[0], '\0', sizeof (the_ins
.operands
[0]));
1199 the_ins
.operands
[0].mode
= CONTROL
;
1200 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1204 /* We've got the operands. Find an opcode that'll accept them. */
1207 /* If we didn't get the right number of ops, or we have no
1208 common model with this pattern then reject this pattern. */
1210 ok_arch
|= opcode
->m_arch
;
1211 if (opsfound
!= opcode
->m_opnum
1212 || ((opcode
->m_arch
& current_architecture
) == 0))
1216 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
1220 /* Warning: this switch is huge! */
1221 /* I've tried to organize the cases into this order:
1222 non-alpha first, then alpha by letter. Lower-case
1223 goes directly before uppercase counterpart. */
1224 /* Code with multiple case ...: gets sorted by the lowest
1225 case ... it belongs to. I hope this makes sense. */
1331 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1348 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1367 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1377 if (opP
->mode
!= IMMED
)
1379 else if (s
[1] == 'b'
1380 && ! isvar (&opP
->disp
)
1381 && (opP
->disp
.exp
.X_op
!= O_constant
1382 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1384 else if (s
[1] == 'B'
1385 && ! isvar (&opP
->disp
)
1386 && (opP
->disp
.exp
.X_op
!= O_constant
1387 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1389 else if (s
[1] == 'w'
1390 && ! isvar (&opP
->disp
)
1391 && (opP
->disp
.exp
.X_op
!= O_constant
1392 || ! isword (opP
->disp
.exp
.X_add_number
)))
1394 else if (s
[1] == 'W'
1395 && ! isvar (&opP
->disp
)
1396 && (opP
->disp
.exp
.X_op
!= O_constant
1397 || ! issword (opP
->disp
.exp
.X_add_number
)))
1403 if (opP
->mode
!= IMMED
)
1408 if (opP
->mode
== AREG
1409 || opP
->mode
== CONTROL
1410 || opP
->mode
== FPREG
1411 || opP
->mode
== IMMED
1412 || opP
->mode
== REGLST
1413 || (opP
->mode
!= ABSL
1415 || opP
->reg
== ZPC
)))
1420 if (opP
->mode
== CONTROL
1421 || opP
->mode
== FPREG
1422 || opP
->mode
== REGLST
1423 || opP
->mode
== IMMED
1424 || (opP
->mode
!= ABSL
1426 || opP
->reg
== ZPC
)))
1454 if (opP
->mode
== CONTROL
1455 || opP
->mode
== FPREG
1456 || opP
->mode
== REGLST
)
1461 if (opP
->mode
!= AINC
)
1466 if (opP
->mode
!= ADEC
)
1516 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1537 case '~': /* For now! (JF FOO is this right?) */
1559 if (opP
->mode
!= CONTROL
1560 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1565 if (opP
->mode
!= AREG
)
1570 if (opP
->mode
!= AINDR
)
1575 if (opP
->mode
!= AINDR
&& opP
->mode
!= AINC
&& opP
->mode
!= ADEC
1576 && (opP
->mode
!= DISP
1578 || opP
->reg
> ADDR7
))
1583 if (opP
->mode
!= ABSL
1585 && strncmp (instring
, "jbsr", 4) == 0))
1608 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1613 if (opP
->mode
!= DISP
1615 || opP
->reg
> ADDR7
)
1620 if (opP
->mode
!= DREG
)
1625 if (opP
->reg
!= ACC
)
1630 if (opP
->reg
!= ACC
&& opP
->reg
!= ACC1
1631 && opP
->reg
!= ACC2
&& opP
->reg
!= ACC3
)
1636 if (opP
->mode
!= FPREG
)
1641 if (opP
->reg
!= MACSR
)
1646 if (opP
->reg
!= ACCEXT01
&& opP
->reg
!= ACCEXT23
)
1651 if (opP
->reg
!= MASK
)
1656 if (opP
->mode
!= CONTROL
1663 if (opP
->mode
!= LSH
&& opP
->mode
!= RSH
)
1668 if (opP
->mode
!= CONTROL
1670 || opP
->reg
> last_movec_reg
)
1674 const enum m68k_register
*rp
;
1675 for (rp
= control_regs
; *rp
; rp
++)
1676 if (*rp
== opP
->reg
)
1684 if (opP
->mode
!= IMMED
)
1690 if (opP
->mode
== DREG
1691 || opP
->mode
== AREG
1692 || opP
->mode
== FPREG
)
1701 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1704 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1707 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1715 else if (opP
->mode
== CONTROL
)
1724 opP
->mask
= 1 << 24;
1727 opP
->mask
= 1 << 25;
1730 opP
->mask
= 1 << 26;
1739 else if (opP
->mode
!= REGLST
)
1741 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1743 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1748 if (opP
->mode
!= IMMED
)
1750 else if (opP
->disp
.exp
.X_op
!= O_constant
1751 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1753 else if (! m68k_quick
1754 && instring
[3] != 'q'
1755 && instring
[4] != 'q')
1760 if (opP
->mode
!= DREG
1761 && opP
->mode
!= IMMED
1762 && opP
->mode
!= ABSL
)
1767 if (opP
->mode
!= IMMED
)
1769 else if (opP
->disp
.exp
.X_op
!= O_constant
1770 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
1772 else if (! m68k_quick
1773 && (strncmp (instring
, "add", 3) == 0
1774 || strncmp (instring
, "sub", 3) == 0)
1775 && instring
[3] != 'q')
1780 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1785 if (opP
->mode
!= AINDR
1786 && (opP
->mode
!= BASE
1788 && opP
->reg
!= ZADDR0
)
1789 || opP
->disp
.exp
.X_op
!= O_absent
1790 || ((opP
->index
.reg
< DATA0
1791 || opP
->index
.reg
> DATA7
)
1792 && (opP
->index
.reg
< ADDR0
1793 || opP
->index
.reg
> ADDR7
))
1794 || opP
->index
.size
!= SIZE_UNSPEC
1795 || opP
->index
.scale
!= 1))
1800 if (opP
->mode
!= CONTROL
1801 || ! (opP
->reg
== FPI
1803 || opP
->reg
== FPC
))
1808 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1813 if (opP
->mode
!= IMMED
)
1815 else if (opP
->disp
.exp
.X_op
!= O_constant
1816 || TRUNC (opP
->disp
.exp
.X_add_number
) > 7)
1821 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1826 if (opP
->mode
!= IMMED
)
1828 else if (opP
->disp
.exp
.X_op
!= O_constant
1829 || (TRUNC (opP
->disp
.exp
.X_add_number
) != 0xffffffff
1830 && TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 6))
1834 /* JF these are out of order. We could put them
1835 in order if we were willing to put up with
1836 bunches of #ifdef m68851s in the code.
1838 Don't forget that you need these operands
1839 to use 68030 MMU instructions. */
1841 /* Memory addressing mode used by pflushr. */
1843 if (opP
->mode
== CONTROL
1844 || opP
->mode
== FPREG
1845 || opP
->mode
== DREG
1846 || opP
->mode
== AREG
1847 || opP
->mode
== REGLST
)
1849 /* We should accept immediate operands, but they
1850 supposedly have to be quad word, and we don't
1851 handle that. I would like to see what a Motorola
1852 assembler does before doing something here. */
1853 if (opP
->mode
== IMMED
)
1858 if (opP
->mode
!= CONTROL
1859 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1864 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1869 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1874 if (opP
->mode
!= CONTROL
1877 && opP
->reg
!= SCC
))
1882 if (opP
->mode
!= CONTROL
1888 if (opP
->mode
!= CONTROL
1891 && opP
->reg
!= CRP
))
1915 if (opP
->mode
!= CONTROL
1916 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1917 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1922 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1927 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1932 if (opP
->mode
!= CONTROL
1941 if (opP
->mode
!= ABSL
)
1946 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
1948 /* FIXME: kludge instead of fixing parser:
1949 upper/lower registers are *not* CONTROL
1950 registers, but ordinary ones. */
1951 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
1952 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
1959 if (!(opP
->mode
== AINDR
1960 || (opP
->mode
== DISP
1961 && !(opP
->reg
== PC
|| opP
->reg
== ZPC
))))
1966 if (!(opP
->mode
== AINDR
|| opP
->mode
== DISP
))
1982 opcode
= opcode
->m_next
;
1987 && !(ok_arch
& current_architecture
))
1992 _("invalid instruction for this architecture; needs "),
1994 cp
= buf
+ strlen (buf
);
1998 strncpy (cp
, _("ColdFire ISA_A"),
1999 sizeof (buf
) - (cp
- buf
));
2001 strncpy (cp
, find_cf_chip (ok_arch
),
2002 sizeof (buf
) - (cp
- buf
));
2006 strncpy (cp
, _("ColdFire hardware divide"),
2007 sizeof (buf
) - (cp
- buf
));
2009 strncpy (cp
, find_cf_chip (ok_arch
),
2010 sizeof (buf
) - (cp
- buf
));
2014 strncpy (cp
, _("ColdFire ISA_A+"),
2015 sizeof (buf
) - (cp
- buf
));
2017 strncpy (cp
, find_cf_chip (ok_arch
),
2018 sizeof (buf
) - (cp
- buf
));
2022 strncpy (cp
, _("ColdFire ISA_B"),
2023 sizeof (buf
) - (cp
- buf
));
2025 strncpy (cp
, find_cf_chip (ok_arch
),
2026 sizeof (buf
) - (cp
- buf
));
2030 strncpy (cp
, _("ColdFire fpu"), sizeof (buf
) - (cp
- buf
));
2032 strncpy (cp
, find_cf_chip (ok_arch
),
2033 sizeof (buf
) - (cp
- buf
));
2037 strcpy (cp
, _("fpu (68040, 68060 or 68881/68882)"));
2040 strcpy (cp
, _("mmu (68030 or 68851)"));
2043 strcpy (cp
, _("68020 or higher"));
2046 strcpy (cp
, _("68000 or higher"));
2049 strcpy (cp
, _("68010 or higher"));
2053 int got_one
= 0, idx
;
2055 for (idx
= 0; idx
< n_archs
; idx
++)
2057 if ((archs
[idx
].arch
& ok_arch
)
2058 && ! archs
[idx
].alias
)
2062 strcpy (cp
, " or ");
2066 strcpy (cp
, archs
[idx
].name
);
2072 cp
= xmalloc (strlen (buf
) + 1);
2077 the_ins
.error
= _("operands mismatch");
2084 /* Now assemble it. */
2085 the_ins
.args
= opcode
->m_operands
;
2086 the_ins
.numargs
= opcode
->m_opnum
;
2087 the_ins
.numo
= opcode
->m_codenum
;
2088 the_ins
.opcode
[0] = getone (opcode
);
2089 the_ins
.opcode
[1] = gettwo (opcode
);
2091 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2093 /* This switch is a doozy.
2094 Watch the first step; its a big one! */
2127 tmpreg
= 0x3c; /* 7.4 */
2128 if (strchr ("bwl", s
[1]))
2129 nextword
= get_num (&opP
->disp
, 90);
2131 nextword
= get_num (&opP
->disp
, 0);
2132 if (isvar (&opP
->disp
))
2133 add_fix (s
[1], &opP
->disp
, 0, 0);
2137 if (!isbyte (nextword
))
2138 opP
->error
= _("operand out of range");
2143 if (!isword (nextword
))
2144 opP
->error
= _("operand out of range");
2149 if (!issword (nextword
))
2150 opP
->error
= _("operand out of range");
2155 addword (nextword
>> 16);
2182 /* We gotta put out some float. */
2183 if (op (&opP
->disp
) != O_big
)
2188 /* Can other cases happen here? */
2189 if (op (&opP
->disp
) != O_constant
)
2192 val
= (valueT
) offs (&opP
->disp
);
2196 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2197 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2201 offs (&opP
->disp
) = gencnt
;
2203 if (offs (&opP
->disp
) > 0)
2205 if (offs (&opP
->disp
) > baseo
)
2207 as_warn (_("Bignum too big for %c format; truncated"),
2209 offs (&opP
->disp
) = baseo
;
2211 baseo
-= offs (&opP
->disp
);
2214 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
2215 offs (&opP
->disp
)--;
2220 gen_to_words (words
, baseo
, (long) outro
);
2221 for (wordp
= words
; baseo
--; wordp
++)
2225 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2228 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2231 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2234 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2237 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2241 nextword
= get_num (&opP
->disp
, 90);
2243 /* Convert mode 5 addressing with a zero offset into
2244 mode 2 addressing to reduce the instruction size by a
2246 if (! isvar (&opP
->disp
)
2248 && (opP
->disp
.size
== SIZE_UNSPEC
)
2249 && (opP
->reg
>= ADDR0
)
2250 && (opP
->reg
<= ADDR7
))
2252 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2257 && ! isvar (&opP
->disp
)
2260 opP
->disp
.exp
.X_op
= O_symbol
;
2261 #ifndef BFD_ASSEMBLER
2262 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
2264 opP
->disp
.exp
.X_add_symbol
=
2265 section_symbol (absolute_section
);
2269 /* Force into index mode. Hope this works. */
2271 /* We do the first bit for 32-bit displacements, and the
2272 second bit for 16 bit ones. It is possible that we
2273 should make the default be WORD instead of LONG, but
2274 I think that'd break GCC, so we put up with a little
2275 inefficiency for the sake of working output. */
2277 if (!issword (nextword
)
2278 || (isvar (&opP
->disp
)
2279 && ((opP
->disp
.size
== SIZE_UNSPEC
2280 && flag_short_refs
== 0
2281 && cpu_of_arch (current_architecture
) >= m68020
2282 && ! arch_coldfire_p (current_architecture
))
2283 || opP
->disp
.size
== SIZE_LONG
)))
2285 if (cpu_of_arch (current_architecture
) < m68020
2286 || arch_coldfire_p (current_architecture
))
2288 _("displacement too large for this architecture; needs 68020 or higher");
2290 tmpreg
= 0x3B; /* 7.3 */
2292 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2293 if (isvar (&opP
->disp
))
2297 if (opP
->disp
.size
== SIZE_LONG
2299 /* If the displacement needs pic
2300 relocation it cannot be relaxed. */
2301 || opP
->disp
.pic_reloc
!= pic_none
2306 add_fix ('l', &opP
->disp
, 1, 2);
2310 add_frag (adds (&opP
->disp
),
2311 SEXT (offs (&opP
->disp
)),
2312 TAB (PCREL1632
, SZ_UNDEF
));
2319 add_fix ('l', &opP
->disp
, 0, 0);
2324 addword (nextword
>> 16);
2329 tmpreg
= 0x3A; /* 7.2 */
2331 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2333 if (isvar (&opP
->disp
))
2337 add_fix ('w', &opP
->disp
, 1, 0);
2340 add_fix ('w', &opP
->disp
, 0, 0);
2350 baseo
= get_num (&opP
->disp
, 90);
2351 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2352 outro
= get_num (&opP
->odisp
, 90);
2353 /* Figure out the `addressing mode'.
2354 Also turn on the BASE_DISABLE bit, if needed. */
2355 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2357 tmpreg
= 0x3b; /* 7.3 */
2358 if (opP
->reg
== ZPC
)
2361 else if (opP
->reg
== 0)
2364 tmpreg
= 0x30; /* 6.garbage */
2366 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2369 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2372 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2374 siz1
= opP
->disp
.size
;
2375 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2376 siz2
= opP
->odisp
.size
;
2380 /* Index register stuff. */
2381 if (opP
->index
.reg
!= 0
2382 && opP
->index
.reg
>= DATA
2383 && opP
->index
.reg
<= ADDR7
)
2385 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2387 if (opP
->index
.size
== SIZE_LONG
2388 || (opP
->index
.size
== SIZE_UNSPEC
2389 && m68k_index_width_default
== SIZE_LONG
))
2392 if ((opP
->index
.scale
!= 1
2393 && cpu_of_arch (current_architecture
) < m68020
)
2394 || (opP
->index
.scale
== 8
2395 && (arch_coldfire_p (current_architecture
)
2396 && !arch_coldfire_fpu (current_architecture
))))
2399 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2402 if (arch_coldfire_p (current_architecture
)
2403 && opP
->index
.size
== SIZE_WORD
)
2404 opP
->error
= _("invalid index size for coldfire");
2406 switch (opP
->index
.scale
)
2423 GET US OUT OF HERE! */
2425 /* Must be INDEX, with an index register. Address
2426 register cannot be ZERO-PC, and either :b was
2427 forced, or we know it will fit. For a 68000 or
2428 68010, force this mode anyways, because the
2429 larger modes aren't supported. */
2430 if (opP
->mode
== BASE
2431 && ((opP
->reg
>= ADDR0
2432 && opP
->reg
<= ADDR7
)
2435 if (siz1
== SIZE_BYTE
2436 || cpu_of_arch (current_architecture
) < m68020
2437 || arch_coldfire_p (current_architecture
)
2438 || (siz1
== SIZE_UNSPEC
2439 && ! isvar (&opP
->disp
)
2440 && issbyte (baseo
)))
2442 nextword
+= baseo
& 0xff;
2444 if (isvar (&opP
->disp
))
2446 /* Do a byte relocation. If it doesn't
2447 fit (possible on m68000) let the
2448 fixup processing complain later. */
2450 add_fix ('B', &opP
->disp
, 1, 1);
2452 add_fix ('B', &opP
->disp
, 0, 0);
2454 else if (siz1
!= SIZE_BYTE
)
2456 if (siz1
!= SIZE_UNSPEC
)
2457 as_warn (_("Forcing byte displacement"));
2458 if (! issbyte (baseo
))
2459 opP
->error
= _("byte displacement out of range");
2464 else if (siz1
== SIZE_UNSPEC
2466 && isvar (&opP
->disp
)
2467 && subs (&opP
->disp
) == NULL
2469 /* If the displacement needs pic
2470 relocation it cannot be relaxed. */
2471 && opP
->disp
.pic_reloc
== pic_none
2475 /* The code in md_convert_frag_1 needs to be
2476 able to adjust nextword. Call frag_grow
2477 to ensure that we have enough space in
2478 the frag obstack to make all the bytes
2481 nextword
+= baseo
& 0xff;
2483 add_frag (adds (&opP
->disp
),
2484 SEXT (offs (&opP
->disp
)),
2485 TAB (PCINDEX
, SZ_UNDEF
));
2493 nextword
|= 0x40; /* No index reg. */
2494 if (opP
->index
.reg
>= ZDATA0
2495 && opP
->index
.reg
<= ZDATA7
)
2496 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2497 else if (opP
->index
.reg
>= ZADDR0
2498 || opP
->index
.reg
<= ZADDR7
)
2499 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2502 /* It isn't simple. */
2504 if (cpu_of_arch (current_architecture
) < m68020
2505 || arch_coldfire_p (current_architecture
))
2507 _("invalid operand mode for this architecture; needs 68020 or higher");
2510 /* If the guy specified a width, we assume that it is
2511 wide enough. Maybe it isn't. If so, we lose. */
2515 if (isvar (&opP
->disp
)
2517 : ! issword (baseo
))
2522 else if (! isvar (&opP
->disp
) && baseo
== 0)
2531 as_warn (_(":b not permitted; defaulting to :w"));
2541 /* Figure out inner displacement stuff. */
2542 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2544 if (cpu_of_arch (current_architecture
) & cpu32
)
2545 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2549 if (isvar (&opP
->odisp
)
2551 : ! issword (outro
))
2556 else if (! isvar (&opP
->odisp
) && outro
== 0)
2565 as_warn (_(":b not permitted; defaulting to :w"));
2574 if (opP
->mode
== POST
2575 && (nextword
& 0x40) == 0)
2580 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2582 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2583 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2585 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2587 if (siz1
== SIZE_LONG
)
2588 addword (baseo
>> 16);
2589 if (siz1
!= SIZE_UNSPEC
)
2592 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2593 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2594 if (siz2
== SIZE_LONG
)
2595 addword (outro
>> 16);
2596 if (siz2
!= SIZE_UNSPEC
)
2602 nextword
= get_num (&opP
->disp
, 90);
2603 switch (opP
->disp
.size
)
2608 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2610 tmpreg
= 0x38; /* 7.0 */
2614 if (isvar (&opP
->disp
)
2615 && !subs (&opP
->disp
)
2616 && adds (&opP
->disp
)
2618 /* If the displacement needs pic relocation it
2619 cannot be relaxed. */
2620 && opP
->disp
.pic_reloc
== pic_none
2623 && !strchr ("~%&$?", s
[0]))
2625 tmpreg
= 0x3A; /* 7.2 */
2626 add_frag (adds (&opP
->disp
),
2627 SEXT (offs (&opP
->disp
)),
2628 TAB (ABSTOPCREL
, SZ_UNDEF
));
2631 /* Fall through into long. */
2633 if (isvar (&opP
->disp
))
2634 add_fix ('l', &opP
->disp
, 0, 0);
2636 tmpreg
= 0x39;/* 7.1 mode */
2637 addword (nextword
>> 16);
2642 as_bad (_("unsupported byte value; use a different suffix"));
2646 if (isvar (&opP
->disp
))
2647 add_fix ('w', &opP
->disp
, 0, 0);
2649 tmpreg
= 0x38;/* 7.0 mode */
2657 as_bad (_("unknown/incorrect operand"));
2661 /* If s[0] is '4', then this is for the mac instructions
2662 that can have a trailing_ampersand set. If so, set 0x100
2663 bit on tmpreg so install_gen_operand can check for it and
2664 set the appropriate bit (word2, bit 5). */
2667 if (opP
->trailing_ampersand
)
2670 install_gen_operand (s
[1], tmpreg
);
2676 { /* JF: I hate floating point! */
2691 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2692 if (isvar (&opP
->disp
))
2693 add_fix (s
[1], &opP
->disp
, 0, 0);
2696 case 'b': /* Danger: These do no check for
2697 certain types of overflow.
2699 if (!isbyte (tmpreg
))
2700 opP
->error
= _("out of range");
2701 insop (tmpreg
, opcode
);
2702 if (isvar (&opP
->disp
))
2703 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2704 (opcode
->m_codenum
) * 2 + 1;
2707 if (!issbyte (tmpreg
))
2708 opP
->error
= _("out of range");
2709 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
2710 if (isvar (&opP
->disp
))
2711 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2714 if (!isword (tmpreg
))
2715 opP
->error
= _("out of range");
2716 insop (tmpreg
, opcode
);
2717 if (isvar (&opP
->disp
))
2718 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2721 if (!issword (tmpreg
))
2722 opP
->error
= _("out of range");
2723 insop (tmpreg
, opcode
);
2724 if (isvar (&opP
->disp
))
2725 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2728 /* Because of the way insop works, we put these two out
2730 insop (tmpreg
, opcode
);
2731 insop (tmpreg
>> 16, opcode
);
2732 if (isvar (&opP
->disp
))
2733 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2740 install_operand (s
[1], tmpreg
);
2751 install_operand (s
[1], opP
->reg
- ADDR
);
2755 tmpreg
= get_num (&opP
->disp
, 90);
2759 add_fix ('B', &opP
->disp
, 1, -1);
2762 add_fix ('w', &opP
->disp
, 1, 0);
2767 if (! HAVE_LONG_BRANCH (current_architecture
))
2768 as_warn (_("Can't use long branches on 68000/68010/5200"));
2769 the_ins
.opcode
[0] |= 0xff;
2770 add_fix ('l', &opP
->disp
, 1, 0);
2775 if (subs (&opP
->disp
)) /* We can't relax it. */
2779 /* If the displacement needs pic relocation it cannot be
2781 if (opP
->disp
.pic_reloc
!= pic_none
)
2784 /* This could either be a symbol, or an absolute
2785 address. If it's an absolute address, turn it into
2786 an absolute jump right here and keep it out of the
2788 if (adds (&opP
->disp
) == 0)
2790 if (the_ins
.opcode
[0] == 0x6000) /* jbra */
2791 the_ins
.opcode
[0] = 0x4EF9;
2792 else if (the_ins
.opcode
[0] == 0x6100) /* jbsr */
2793 the_ins
.opcode
[0] = 0x4EB9;
2796 the_ins
.opcode
[0] ^= 0x0100;
2797 the_ins
.opcode
[0] |= 0x0006;
2800 add_fix ('l', &opP
->disp
, 0, 0);
2806 /* Now we know it's going into the relaxer. Now figure
2807 out which mode. We try in this order of preference:
2808 long branch, absolute jump, byte/word branches only. */
2809 if (HAVE_LONG_BRANCH (current_architecture
))
2810 add_frag (adds (&opP
->disp
),
2811 SEXT (offs (&opP
->disp
)),
2812 TAB (BRANCHBWL
, SZ_UNDEF
));
2813 else if (! flag_keep_pcrel
)
2815 if ((the_ins
.opcode
[0] == 0x6000)
2816 || (the_ins
.opcode
[0] == 0x6100))
2817 add_frag (adds (&opP
->disp
),
2818 SEXT (offs (&opP
->disp
)),
2819 TAB (BRABSJUNC
, SZ_UNDEF
));
2821 add_frag (adds (&opP
->disp
),
2822 SEXT (offs (&opP
->disp
)),
2823 TAB (BRABSJCOND
, SZ_UNDEF
));
2826 add_frag (adds (&opP
->disp
),
2827 SEXT (offs (&opP
->disp
)),
2828 TAB (BRANCHBW
, SZ_UNDEF
));
2831 if (isvar (&opP
->disp
))
2833 /* Check for DBcc instructions. We can relax them,
2834 but only if we have long branches and/or absolute
2836 if (((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2837 && (HAVE_LONG_BRANCH (current_architecture
)
2838 || (! flag_keep_pcrel
)))
2840 if (HAVE_LONG_BRANCH (current_architecture
))
2841 add_frag (adds (&opP
->disp
),
2842 SEXT (offs (&opP
->disp
)),
2843 TAB (DBCCLBR
, SZ_UNDEF
));
2845 add_frag (adds (&opP
->disp
),
2846 SEXT (offs (&opP
->disp
)),
2847 TAB (DBCCABSJ
, SZ_UNDEF
));
2850 add_fix ('w', &opP
->disp
, 1, 0);
2854 case 'C': /* Fixed size LONG coproc branches. */
2855 add_fix ('l', &opP
->disp
, 1, 0);
2859 case 'c': /* Var size Coprocesssor branches. */
2860 if (subs (&opP
->disp
) || (adds (&opP
->disp
) == 0))
2862 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2863 add_fix ('l', &opP
->disp
, 1, 0);
2868 add_frag (adds (&opP
->disp
),
2869 SEXT (offs (&opP
->disp
)),
2870 TAB (FBRANCH
, SZ_UNDEF
));
2877 case 'C': /* Ignore it. */
2880 case 'd': /* JF this is a kludge. */
2881 install_operand ('s', opP
->reg
- ADDR
);
2882 tmpreg
= get_num (&opP
->disp
, 90);
2883 if (!issword (tmpreg
))
2885 as_warn (_("Expression out of range, using 0"));
2892 install_operand (s
[1], opP
->reg
- DATA
);
2895 case 'e': /* EMAC ACCx, reg/reg. */
2896 install_operand (s
[1], opP
->reg
- ACC
);
2899 case 'E': /* Ignore it. */
2903 install_operand (s
[1], opP
->reg
- FP0
);
2906 case 'g': /* EMAC ACCEXTx. */
2907 install_operand (s
[1], opP
->reg
- ACCEXT01
);
2910 case 'G': /* Ignore it. */
2915 tmpreg
= opP
->reg
- COP0
;
2916 install_operand (s
[1], tmpreg
);
2919 case 'i': /* MAC/EMAC scale factor. */
2920 install_operand (s
[1], opP
->mode
== LSH
? 0x1 : 0x3);
2923 case 'J': /* JF foo. */
3053 install_operand (s
[1], tmpreg
);
3057 tmpreg
= get_num (&opP
->disp
, 55);
3058 install_operand (s
[1], tmpreg
& 0x7f);
3065 if (tmpreg
& 0x7FF0000)
3066 as_bad (_("Floating point register in register list"));
3067 insop (reverse_16_bits (tmpreg
), opcode
);
3071 if (tmpreg
& 0x700FFFF)
3072 as_bad (_("Wrong register in floating-point reglist"));
3073 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
3081 if (tmpreg
& 0x7FF0000)
3082 as_bad (_("Floating point register in register list"));
3083 insop (tmpreg
, opcode
);
3085 else if (s
[1] == '8')
3087 if (tmpreg
& 0x0FFFFFF)
3088 as_bad (_("incorrect register in reglist"));
3089 install_operand (s
[1], tmpreg
>> 24);
3093 if (tmpreg
& 0x700FFFF)
3094 as_bad (_("wrong register in floating-point reglist"));
3096 install_operand (s
[1], tmpreg
>> 16);
3101 install_operand (s
[1], get_num (&opP
->disp
, 60));
3105 tmpreg
= ((opP
->mode
== DREG
)
3106 ? 0x20 + (int) (opP
->reg
- DATA
)
3107 : (get_num (&opP
->disp
, 40) & 0x1F));
3108 install_operand (s
[1], tmpreg
);
3112 tmpreg
= get_num (&opP
->disp
, 10);
3115 install_operand (s
[1], tmpreg
);
3119 /* This depends on the fact that ADDR registers are eight
3120 more than their corresponding DATA regs, so the result
3121 will have the ADDR_REG bit set. */
3122 install_operand (s
[1], opP
->reg
- DATA
);
3126 if (opP
->mode
== AINDR
)
3127 install_operand (s
[1], opP
->reg
- DATA
);
3129 install_operand (s
[1], opP
->index
.reg
- DATA
);
3133 if (opP
->reg
== FPI
)
3135 else if (opP
->reg
== FPS
)
3137 else if (opP
->reg
== FPC
)
3141 install_operand (s
[1], tmpreg
);
3144 case 'S': /* Ignore it. */
3148 install_operand (s
[1], get_num (&opP
->disp
, 30));
3151 case 'U': /* Ignore it. */
3170 as_fatal (_("failed sanity check"));
3171 } /* switch on cache token. */
3172 install_operand (s
[1], tmpreg
);
3175 /* JF: These are out of order, I fear. */
3188 install_operand (s
[1], tmpreg
);
3214 install_operand (s
[1], tmpreg
);
3218 if (opP
->reg
== VAL
)
3237 install_operand (s
[1], tmpreg
);
3251 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3262 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3268 install_operand (s
[1], tmpreg
);
3271 know (opP
->reg
== PSR
);
3274 know (opP
->reg
== PCSR
);
3289 install_operand (s
[1], tmpreg
);
3292 tmpreg
= get_num (&opP
->disp
, 20);
3293 install_operand (s
[1], tmpreg
);
3295 case '_': /* used only for move16 absolute 32-bit address. */
3296 if (isvar (&opP
->disp
))
3297 add_fix ('l', &opP
->disp
, 0, 0);
3298 tmpreg
= get_num (&opP
->disp
, 90);
3299 addword (tmpreg
>> 16);
3300 addword (tmpreg
& 0xFFFF);
3303 install_operand (s
[1], opP
->reg
- DATA0L
);
3304 opP
->reg
-= (DATA0L
);
3305 opP
->reg
&= 0x0F; /* remove upper/lower bit. */
3308 tmpreg
= get_num (&opP
->disp
, 80);
3311 install_operand (s
[1], tmpreg
);
3318 /* By the time whe get here (FINALLY) the_ins contains the complete
3319 instruction, ready to be emitted. . . */
3323 reverse_16_bits (int in
)
3328 static int mask
[16] =
3330 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3331 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3333 for (n
= 0; n
< 16; n
++)
3336 out
|= mask
[15 - n
];
3339 } /* reverse_16_bits() */
3342 reverse_8_bits (int in
)
3347 static int mask
[8] =
3349 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3352 for (n
= 0; n
< 8; n
++)
3358 } /* reverse_8_bits() */
3360 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3361 (that value is chosen in the frag_var call in md_assemble). TYPE
3362 is the subtype of the frag to be generated; its primary type is
3363 rs_machine_dependent.
3365 The TYPE parameter is also used by md_convert_frag_1 and
3366 md_estimate_size_before_relax. The appropriate type of fixup will
3367 be emitted by md_convert_frag_1.
3369 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3371 install_operand (int mode
, int val
)
3376 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge. */
3379 the_ins
.opcode
[0] |= val
<< 9;
3382 the_ins
.opcode
[1] |= val
<< 12;
3385 the_ins
.opcode
[1] |= val
<< 6;
3388 the_ins
.opcode
[1] |= val
;
3391 the_ins
.opcode
[2] |= val
<< 12;
3394 the_ins
.opcode
[2] |= val
<< 6;
3397 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3398 three words long! */
3400 the_ins
.opcode
[2] |= val
;
3403 the_ins
.opcode
[1] |= val
<< 7;
3406 the_ins
.opcode
[1] |= val
<< 10;
3410 the_ins
.opcode
[1] |= val
<< 5;
3415 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3418 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3421 the_ins
.opcode
[0] |= val
= 0xff;
3424 the_ins
.opcode
[0] |= val
<< 9;
3427 the_ins
.opcode
[1] |= val
;
3430 the_ins
.opcode
[1] |= val
;
3431 the_ins
.numo
++; /* What a hack. */
3434 the_ins
.opcode
[1] |= val
<< 4;
3442 the_ins
.opcode
[0] |= (val
<< 6);
3445 the_ins
.opcode
[1] = (val
>> 16);
3446 the_ins
.opcode
[2] = val
& 0xffff;
3449 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3450 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3451 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3453 case 'n': /* MAC/EMAC Rx on !load. */
3454 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3455 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3456 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3458 case 'o': /* MAC/EMAC Rx on load. */
3459 the_ins
.opcode
[1] |= val
<< 12;
3460 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3462 case 'M': /* MAC/EMAC Ry on !load. */
3463 the_ins
.opcode
[0] |= (val
& 0xF);
3464 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3466 case 'N': /* MAC/EMAC Ry on load. */
3467 the_ins
.opcode
[1] |= (val
& 0xF);
3468 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3471 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3474 the_ins
.opcode
[0] |= ((val
& 0x3) << 9);
3477 the_ins
.opcode
[0] |= ((val
& 0x3) << 0);
3479 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3480 the_ins
.opcode
[0] |= ((~val
& 0x1) << 7);
3481 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3483 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3484 the_ins
.opcode
[0] |= ((val
& 0x1) << 7);
3485 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3488 the_ins
.opcode
[1] |= ((val
& 0x3) << 9);
3491 the_ins
.opcode
[0] |= (val
& 0x1) <<10;
3495 as_fatal (_("failed sanity check."));
3500 install_gen_operand (int mode
, int val
)
3504 case '/': /* Special for mask loads for mac/msac insns with
3505 possible mask; trailing_ampersend set in bit 8. */
3506 the_ins
.opcode
[0] |= (val
& 0x3f);
3507 the_ins
.opcode
[1] |= (((val
& 0x100) >> 8) << 5);
3510 the_ins
.opcode
[0] |= val
;
3513 /* This is a kludge!!! */
3514 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3523 the_ins
.opcode
[0] |= val
;
3525 /* more stuff goes here. */
3527 as_fatal (_("failed sanity check."));
3531 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3532 then deal with the bitfield hack. */
3535 crack_operand (char *str
, struct m68k_op
*opP
)
3537 register int parens
;
3539 register char *beg_str
;
3547 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3553 else if (*str
== ')')
3557 opP
->error
= _("Extra )");
3563 if (flag_mri
&& *str
== '\'')
3564 inquote
= ! inquote
;
3566 if (!*str
&& parens
)
3568 opP
->error
= _("Missing )");
3573 if (m68k_ip_op (beg_str
, opP
) != 0)
3580 c
= *++str
; /* JF bitfield hack. */
3585 as_bad (_("Missing operand"));
3588 /* Detect MRI REG symbols and convert them to REGLSTs. */
3589 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3592 opP
->mask
= ~(int)opP
->reg
;
3599 /* This is the guts of the machine-dependent assembler. STR points to a
3600 machine dependent instruction. This function is supposed to emit
3601 the frags/bytes it assembles to.
3605 insert_reg (const char *regname
, int regnum
)
3610 #ifdef REGISTER_PREFIX
3611 if (!flag_reg_prefix_optional
)
3613 buf
[0] = REGISTER_PREFIX
;
3614 strcpy (buf
+ 1, regname
);
3619 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3620 &zero_address_frag
));
3622 for (i
= 0; regname
[i
]; i
++)
3623 buf
[i
] = TOUPPER (regname
[i
]);
3626 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3627 &zero_address_frag
));
3636 static const struct init_entry init_table
[] =
3696 { "accext01", ACCEXT01
},
3697 { "accext23", ACCEXT23
},
3701 /* Control registers. */
3702 { "sfc", SFC
}, /* Source Function Code. */
3704 { "dfc", DFC
}, /* Destination Function Code. */
3706 { "cacr", CACR
}, /* Cache Control Register. */
3707 { "caar", CAAR
}, /* Cache Address Register. */
3709 { "usp", USP
}, /* User Stack Pointer. */
3710 { "vbr", VBR
}, /* Vector Base Register. */
3711 { "msp", MSP
}, /* Master Stack Pointer. */
3712 { "isp", ISP
}, /* Interrupt Stack Pointer. */
3714 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0. */
3715 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1. */
3716 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0. */
3717 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1. */
3719 /* 68ec040 versions of same */
3720 { "iacr0", ITT0
}, /* Instruction Access Control Register 0. */
3721 { "iacr1", ITT1
}, /* Instruction Access Control Register 0. */
3722 { "dacr0", DTT0
}, /* Data Access Control Register 0. */
3723 { "dacr1", DTT1
}, /* Data Access Control Register 0. */
3725 /* mcf5200 versions of same. The ColdFire programmer's reference
3726 manual indicated that the order is 2,3,0,1, but Ken Rose
3727 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3728 { "acr0", ACR0
}, /* Access Control Unit 0. */
3729 { "acr1", ACR1
}, /* Access Control Unit 1. */
3730 { "acr2", ACR2
}, /* Access Control Unit 2. */
3731 { "acr3", ACR3
}, /* Access Control Unit 3. */
3733 { "tc", TC
}, /* MMU Translation Control Register. */
3736 { "mmusr", MMUSR
}, /* MMU Status Register. */
3737 { "srp", SRP
}, /* User Root Pointer. */
3738 { "urp", URP
}, /* Supervisor Root Pointer. */
3743 { "rombar", ROMBAR
}, /* ROM Base Address Register. */
3744 { "rambar0", RAMBAR0
}, /* ROM Base Address Register. */
3745 { "rambar1", RAMBAR1
}, /* ROM Base Address Register. */
3746 { "mbar", MBAR
}, /* Module Base Address Register. */
3748 { "mbar0", MBAR0
}, /* mcfv4e registers. */
3749 { "mbar1", MBAR1
}, /* mcfv4e registers. */
3750 { "rombar0", ROMBAR
}, /* mcfv4e registers. */
3751 { "rombar1", ROMBAR1
}, /* mcfv4e registers. */
3752 { "mpcr", MPCR
}, /* mcfv4e registers. */
3753 { "edrambar", EDRAMBAR
}, /* mcfv4e registers. */
3754 { "secmbar", SECMBAR
}, /* mcfv4e registers. */
3755 { "asid", TC
}, /* mcfv4e registers. */
3756 { "mmubar", BUSCR
}, /* mcfv4e registers. */
3757 { "pcr1u0", PCR1U0
}, /* mcfv4e registers. */
3758 { "pcr1l0", PCR1L0
}, /* mcfv4e registers. */
3759 { "pcr2u0", PCR2U0
}, /* mcfv4e registers. */
3760 { "pcr2l0", PCR2L0
}, /* mcfv4e registers. */
3761 { "pcr3u0", PCR3U0
}, /* mcfv4e registers. */
3762 { "pcr3l0", PCR3L0
}, /* mcfv4e registers. */
3763 { "pcr1u1", PCR1U1
}, /* mcfv4e registers. */
3764 { "pcr1l1", PCR1L1
}, /* mcfv4e registers. */
3765 { "pcr2u1", PCR2U1
}, /* mcfv4e registers. */
3766 { "pcr2l1", PCR2L1
}, /* mcfv4e registers. */
3767 { "pcr3u1", PCR3U1
}, /* mcfv4e registers. */
3768 { "pcr3l1", PCR3L1
}, /* mcfv4e registers. */
3770 { "flashbar", FLASHBAR
}, /* mcf528x registers. */
3771 { "rambar", RAMBAR
}, /* mcf528x registers. */
3773 { "mbar2", MBAR2
}, /* mcf5249 registers. */
3774 /* End of control registers. */
3808 /* 68ec030 versions of same. */
3811 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3814 /* Suppressed data and address registers. */
3832 /* Upper and lower data and address registers, used by macw and msacw. */
3873 init_regtable (void)
3876 for (i
= 0; init_table
[i
].name
; i
++)
3877 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3880 static int no_68851
, no_68881
;
3883 /* a.out machine type. Default to 68020. */
3884 int m68k_aout_machtype
= 2;
3888 md_assemble (char *str
)
3895 int shorts_this_frag
;
3898 /* In MRI mode, the instruction and operands are separated by a
3899 space. Anything following the operands is a comment. The label
3900 has already been removed. */
3908 for (s
= str
; *s
!= '\0'; s
++)
3910 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3928 inquote
= ! inquote
;
3933 memset (&the_ins
, '\0', sizeof (the_ins
));
3938 for (n
= 0; n
< the_ins
.numargs
; n
++)
3939 if (the_ins
.operands
[n
].error
)
3941 er
= the_ins
.operands
[n
].error
;
3947 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
3951 /* If there is a current label, record that it marks an instruction. */
3952 if (current_label
!= NULL
)
3954 current_label
->text
= 1;
3955 current_label
= NULL
;
3959 /* Tie dwarf2 debug info to the address at the start of the insn. */
3960 dwarf2_emit_insn (0);
3963 if (the_ins
.nfrag
== 0)
3965 /* No frag hacking involved; just put it out. */
3966 toP
= frag_more (2 * the_ins
.numo
);
3967 fromP
= &the_ins
.opcode
[0];
3968 for (m
= the_ins
.numo
; m
; --m
)
3970 md_number_to_chars (toP
, (long) (*fromP
), 2);
3974 /* Put out symbol-dependent info. */
3975 for (m
= 0; m
< the_ins
.nrel
; m
++)
3977 switch (the_ins
.reloc
[m
].wid
)
3996 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3997 the_ins
.reloc
[m
].wid
);
4000 fixP
= fix_new_exp (frag_now
,
4001 ((toP
- frag_now
->fr_literal
)
4002 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4004 &the_ins
.reloc
[m
].exp
,
4005 the_ins
.reloc
[m
].pcrel
,
4006 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
4007 the_ins
.reloc
[m
].pic_reloc
));
4008 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4009 if (the_ins
.reloc
[m
].wid
== 'B')
4010 fixP
->fx_signed
= 1;
4015 /* There's some frag hacking. */
4017 /* Calculate the max frag size. */
4020 wid
= 2 * the_ins
.fragb
[0].fragoff
;
4021 for (n
= 1; n
< the_ins
.nfrag
; n
++)
4022 wid
+= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4023 /* frag_var part. */
4025 /* Make sure the whole insn fits in one chunk, in particular that
4026 the var part is attached, as we access one byte before the
4027 variable frag for byte branches. */
4031 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
4036 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
4038 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4039 toP
= frag_more (wid
);
4041 shorts_this_frag
= 0;
4042 for (m
= wid
/ 2; m
; --m
)
4044 md_number_to_chars (toP
, (long) (*fromP
), 2);
4049 for (m
= 0; m
< the_ins
.nrel
; m
++)
4051 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
4053 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
4056 wid
= the_ins
.reloc
[m
].wid
;
4059 the_ins
.reloc
[m
].wid
= 0;
4060 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4062 fixP
= fix_new_exp (frag_now
,
4063 ((toP
- frag_now
->fr_literal
)
4064 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4066 &the_ins
.reloc
[m
].exp
,
4067 the_ins
.reloc
[m
].pcrel
,
4068 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4069 the_ins
.reloc
[m
].pic_reloc
));
4070 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4072 (void) frag_var (rs_machine_dependent
, 10, 0,
4073 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
4074 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
4076 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4077 shorts_this_frag
= 0;
4080 toP
= frag_more (n
* 2);
4083 md_number_to_chars (toP
, (long) (*fromP
), 2);
4089 for (m
= 0; m
< the_ins
.nrel
; m
++)
4093 wid
= the_ins
.reloc
[m
].wid
;
4096 the_ins
.reloc
[m
].wid
= 0;
4097 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4099 fixP
= fix_new_exp (frag_now
,
4100 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
4101 - shorts_this_frag
* 2),
4103 &the_ins
.reloc
[m
].exp
,
4104 the_ins
.reloc
[m
].pcrel
,
4105 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4106 the_ins
.reloc
[m
].pic_reloc
));
4107 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4111 /* Comparison function used by qsort to rank the opcode entries by name. */
4114 m68k_compare_opcode (const void * v1
, const void * v2
)
4116 struct m68k_opcode
* op1
, * op2
;
4119 op1
= *(struct m68k_opcode
**) v1
;
4120 op2
= *(struct m68k_opcode
**) v2
;
4122 /* Compare the two names. If different, return the comparison.
4123 If the same, return the order they are in the opcode table. */
4124 ret
= strcmp (op1
->name
, op2
->name
);
4135 const struct m68k_opcode
*ins
;
4136 struct m68k_incant
*hack
, *slak
;
4137 const char *retval
= 0; /* Empty string, or error msg text. */
4140 /* Set up hash tables with 68000 instructions.
4141 similar to what the vax assembler does. */
4142 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4143 a copy of it at runtime, adding in the information we want but isn't
4144 there. I think it'd be better to have an awk script hack the table
4145 at compile time. Or even just xstr the table and use it as-is. But
4146 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4151 flag_reg_prefix_optional
= 1;
4153 if (! m68k_rel32_from_cmdline
)
4157 /* First sort the opcode table into alphabetical order to seperate
4158 the order that the assembler wants to see the opcodes from the
4159 order that the disassembler wants to see them. */
4160 m68k_sorted_opcodes
= xmalloc (m68k_numopcodes
* sizeof (* m68k_sorted_opcodes
));
4161 if (!m68k_sorted_opcodes
)
4162 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4163 m68k_numopcodes
* ((int) sizeof (* m68k_sorted_opcodes
)));
4165 for (i
= m68k_numopcodes
; i
--;)
4166 m68k_sorted_opcodes
[i
] = m68k_opcodes
+ i
;
4168 qsort (m68k_sorted_opcodes
, m68k_numopcodes
,
4169 sizeof (m68k_sorted_opcodes
[0]), m68k_compare_opcode
);
4171 op_hash
= hash_new ();
4173 obstack_begin (&robyn
, 4000);
4174 for (i
= 0; i
< m68k_numopcodes
; i
++)
4176 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4179 ins
= m68k_sorted_opcodes
[i
];
4181 /* We *could* ignore insns that don't match our
4182 arch here by just leaving them out of the hash. */
4183 slak
->m_operands
= ins
->args
;
4184 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
4185 slak
->m_arch
= ins
->arch
;
4186 slak
->m_opcode
= ins
->opcode
;
4187 /* This is kludgey. */
4188 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
4189 if (i
+ 1 != m68k_numopcodes
4190 && !strcmp (ins
->name
, m68k_sorted_opcodes
[i
+ 1]->name
))
4192 slak
->m_next
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4197 slak
= slak
->m_next
;
4201 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
4203 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
4206 for (i
= 0; i
< m68k_numaliases
; i
++)
4208 const char *name
= m68k_opcode_aliases
[i
].primary
;
4209 const char *alias
= m68k_opcode_aliases
[i
].alias
;
4210 PTR val
= hash_find (op_hash
, name
);
4213 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4214 retval
= hash_insert (op_hash
, alias
, val
);
4216 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4219 /* In MRI mode, all unsized branches are variable sized. Normally,
4220 they are word sized. */
4223 static struct m68k_opcode_alias mri_aliases
[] =
4244 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
4247 const char *name
= mri_aliases
[i
].primary
;
4248 const char *alias
= mri_aliases
[i
].alias
;
4249 PTR val
= hash_find (op_hash
, name
);
4252 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4253 retval
= hash_jam (op_hash
, alias
, val
);
4255 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4259 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
4261 notend_table
[i
] = 0;
4262 alt_notend_table
[i
] = 0;
4265 notend_table
[','] = 1;
4266 notend_table
['{'] = 1;
4267 notend_table
['}'] = 1;
4268 alt_notend_table
['a'] = 1;
4269 alt_notend_table
['A'] = 1;
4270 alt_notend_table
['d'] = 1;
4271 alt_notend_table
['D'] = 1;
4272 alt_notend_table
['#'] = 1;
4273 alt_notend_table
['&'] = 1;
4274 alt_notend_table
['f'] = 1;
4275 alt_notend_table
['F'] = 1;
4276 #ifdef REGISTER_PREFIX
4277 alt_notend_table
[REGISTER_PREFIX
] = 1;
4280 /* We need to put '(' in alt_notend_table to handle
4281 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4282 alt_notend_table
['('] = 1;
4284 /* We need to put '@' in alt_notend_table to handle
4285 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4286 alt_notend_table
['@'] = 1;
4288 /* We need to put digits in alt_notend_table to handle
4289 bfextu %d0{24:1},%d0 */
4290 alt_notend_table
['0'] = 1;
4291 alt_notend_table
['1'] = 1;
4292 alt_notend_table
['2'] = 1;
4293 alt_notend_table
['3'] = 1;
4294 alt_notend_table
['4'] = 1;
4295 alt_notend_table
['5'] = 1;
4296 alt_notend_table
['6'] = 1;
4297 alt_notend_table
['7'] = 1;
4298 alt_notend_table
['8'] = 1;
4299 alt_notend_table
['9'] = 1;
4301 #ifndef MIT_SYNTAX_ONLY
4302 /* Insert pseudo ops, these have to go into the opcode table since
4303 gas expects pseudo ops to start with a dot. */
4307 while (mote_pseudo_table
[n
].poc_name
)
4309 hack
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4310 hash_insert (op_hash
,
4311 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
4312 hack
->m_operands
= 0;
4322 record_alignment (text_section
, 2);
4323 record_alignment (data_section
, 2);
4324 record_alignment (bss_section
, 2);
4329 select_control_regs (void)
4331 /* Note which set of "movec" control registers is available. */
4332 switch (current_chip
)
4336 as_warn (_("architecture not yet selected: defaulting to 68020"));
4337 control_regs
= m68020_control_regs
;
4341 control_regs
= m68000_control_regs
;
4344 control_regs
= m68010_control_regs
;
4348 control_regs
= m68020_control_regs
;
4351 control_regs
= m68040_control_regs
;
4354 control_regs
= m68060_control_regs
;
4357 control_regs
= cpu32_control_regs
;
4363 control_regs
= mcf_control_regs
;
4366 control_regs
= mcf5249_control_regs
;
4370 control_regs
= mcf528x_control_regs
;
4374 control_regs
= mcfv4e_control_regs
;
4382 m68k_init_after_args (void)
4384 if (cpu_of_arch (current_architecture
) == 0)
4387 const char *default_cpu
= TARGET_CPU
;
4389 if (*default_cpu
== 'm')
4391 for (i
= 0; i
< n_archs
; i
++)
4392 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
4396 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU
);
4397 current_architecture
|= m68020
;
4400 current_architecture
|= archs
[i
].arch
;
4402 /* Permit m68881 specification with all cpus; those that can't work
4403 with a coprocessor could be doing emulation. */
4404 if (current_architecture
& m68851
)
4406 if (current_architecture
& m68040
)
4407 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4409 /* What other incompatibilities could we check for? */
4411 /* Toss in some default assumptions about coprocessors. */
4413 && (cpu_of_arch (current_architecture
)
4414 /* Can CPU32 have a 68881 coprocessor?? */
4415 & (m68020
| m68030
| cpu32
)))
4416 current_architecture
|= m68881
;
4419 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
4420 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
4421 current_architecture
|= m68851
;
4423 if (no_68881
&& (current_architecture
& m68881
))
4424 as_bad (_("options for 68881 and no-68881 both given"));
4426 if (no_68851
&& (current_architecture
& m68851
))
4427 as_bad (_("options for 68851 and no-68851 both given"));
4430 /* Work out the magic number. This isn't very general. */
4431 if (current_architecture
& m68000
)
4432 m68k_aout_machtype
= 0;
4433 else if (current_architecture
& m68010
)
4434 m68k_aout_machtype
= 1;
4435 else if (current_architecture
& m68020
)
4436 m68k_aout_machtype
= 2;
4438 m68k_aout_machtype
= 2;
4441 /* Note which set of "movec" control registers is available. */
4442 select_control_regs ();
4444 if (cpu_of_arch (current_architecture
) < m68020
4445 || arch_coldfire_p (current_architecture
))
4446 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
4449 /* This is called when a label is defined. */
4452 m68k_frob_label (symbolS
*sym
)
4454 struct label_line
*n
;
4456 n
= (struct label_line
*) xmalloc (sizeof *n
);
4459 as_where (&n
->file
, &n
->line
);
4465 /* This is called when a value that is not an instruction is emitted. */
4468 m68k_flush_pending_output (void)
4470 current_label
= NULL
;
4473 /* This is called at the end of the assembly, when the final value of
4474 the label is known. We warn if this is a text symbol aligned at an
4478 m68k_frob_symbol (symbolS
*sym
)
4480 if (S_GET_SEGMENT (sym
) == reg_section
4481 && (int) S_GET_VALUE (sym
) < 0)
4483 S_SET_SEGMENT (sym
, absolute_section
);
4484 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4486 else if ((S_GET_VALUE (sym
) & 1) != 0)
4488 struct label_line
*l
;
4490 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4492 if (l
->label
== sym
)
4495 as_warn_where (l
->file
, l
->line
,
4496 _("text label `%s' aligned to odd boundary"),
4504 /* This is called if we go in or out of MRI mode because of the .mri
4508 m68k_mri_mode_change (int on
)
4512 if (! flag_reg_prefix_optional
)
4514 flag_reg_prefix_optional
= 1;
4515 #ifdef REGISTER_PREFIX
4520 if (! m68k_rel32_from_cmdline
)
4525 if (! reg_prefix_optional_seen
)
4527 #ifdef REGISTER_PREFIX_OPTIONAL
4528 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4530 flag_reg_prefix_optional
= 0;
4532 #ifdef REGISTER_PREFIX
4537 if (! m68k_rel32_from_cmdline
)
4542 /* Equal to MAX_PRECISION in atof-ieee.c. */
4543 #define MAX_LITTLENUMS 6
4545 /* Turn a string in input_line_pointer into a floating point constant
4546 of type TYPE, and store the appropriate bytes in *LITP. The number
4547 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4548 returned, or NULL on OK. */
4551 md_atof (int type
, char *litP
, int *sizeP
)
4554 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
4555 LITTLENUM_TYPE
*wordP
;
4586 return _("Bad call to MD_ATOF()");
4588 t
= atof_ieee (input_line_pointer
, type
, words
);
4590 input_line_pointer
= t
;
4592 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
4593 for (wordP
= words
; prec
--;)
4595 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
4596 litP
+= sizeof (LITTLENUM_TYPE
);
4602 md_number_to_chars (char *buf
, valueT val
, int n
)
4604 number_to_chars_bigendian (buf
, val
, n
);
4608 md_apply_fix3 (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
4610 offsetT val
= *valP
;
4611 addressT upper_limit
;
4612 offsetT lower_limit
;
4614 /* This is unnecessary but it convinces the native rs6000 compiler
4615 to generate the code we want. */
4616 char *buf
= fixP
->fx_frag
->fr_literal
;
4617 buf
+= fixP
->fx_where
;
4618 /* End ibm compiler workaround. */
4622 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4628 memset (buf
, 0, fixP
->fx_size
);
4629 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4631 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4632 && !S_IS_DEFINED (fixP
->fx_addsy
)
4633 && !S_IS_WEAK (fixP
->fx_addsy
))
4634 S_SET_WEAK (fixP
->fx_addsy
);
4639 #ifdef BFD_ASSEMBLER
4640 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4641 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4645 switch (fixP
->fx_size
)
4647 /* The cast to offsetT below are necessary to make code
4648 correct for machines where ints are smaller than offsetT. */
4652 lower_limit
= - (offsetT
) 0x80;
4655 *buf
++ = (val
>> 8);
4657 upper_limit
= 0x7fff;
4658 lower_limit
= - (offsetT
) 0x8000;
4661 *buf
++ = (val
>> 24);
4662 *buf
++ = (val
>> 16);
4663 *buf
++ = (val
>> 8);
4665 upper_limit
= 0x7fffffff;
4666 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* Avoid constant overflow. */
4669 BAD_CASE (fixP
->fx_size
);
4672 /* Fix up a negative reloc. */
4673 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4675 fixP
->fx_addsy
= fixP
->fx_subsy
;
4676 fixP
->fx_subsy
= NULL
;
4680 /* For non-pc-relative values, it's conceivable we might get something
4681 like "0xff" for a byte field. So extend the upper part of the range
4682 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4683 so that we can do any range checking at all. */
4684 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4685 upper_limit
= upper_limit
* 2 + 1;
4687 if ((addressT
) val
> upper_limit
4688 && (val
> 0 || val
< lower_limit
))
4689 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("value out of range"));
4691 /* A one byte PC-relative reloc means a short branch. We can't use
4692 a short branch with a value of 0 or -1, because those indicate
4693 different opcodes (branches with longer offsets). fixup_segment
4694 in write.c may have clobbered fx_pcrel, so we need to examine the
4697 #ifdef BFD_ASSEMBLER
4698 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
4701 && fixP
->fx_size
== 1
4702 && (fixP
->fx_addsy
== NULL
4703 || S_IS_DEFINED (fixP
->fx_addsy
))
4704 && (val
== 0 || val
== -1))
4705 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("invalid byte branch offset"));
4708 /* *fragP has been relaxed to its final size, and now needs to have
4709 the bytes inside it modified to conform to the new size There is UGLY
4713 md_convert_frag_1 (fragS
*fragP
)
4718 /* Address in object code of the displacement. */
4719 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4721 /* Address in gas core of the place to store the displacement. */
4722 /* This convinces the native rs6000 compiler to generate the code we
4724 register char *buffer_address
= fragP
->fr_literal
;
4725 buffer_address
+= fragP
->fr_fix
;
4726 /* End ibm compiler workaround. */
4728 /* The displacement of the address, from current location. */
4729 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4730 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4732 switch (fragP
->fr_subtype
)
4734 case TAB (BRANCHBWL
, BYTE
):
4735 case TAB (BRABSJUNC
, BYTE
):
4736 case TAB (BRABSJCOND
, BYTE
):
4737 case TAB (BRANCHBW
, BYTE
):
4738 know (issbyte (disp
));
4740 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
4741 _("short branch with zero offset: use :w"));
4742 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4743 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4744 fixP
->fx_pcrel_adjust
= -1;
4746 case TAB (BRANCHBWL
, SHORT
):
4747 case TAB (BRABSJUNC
, SHORT
):
4748 case TAB (BRABSJCOND
, SHORT
):
4749 case TAB (BRANCHBW
, SHORT
):
4750 fragP
->fr_opcode
[1] = 0x00;
4751 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4752 1, RELAX_RELOC_PC16
);
4755 case TAB (BRANCHBWL
, LONG
):
4756 fragP
->fr_opcode
[1] = (char) 0xFF;
4757 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4758 1, RELAX_RELOC_PC32
);
4761 case TAB (BRABSJUNC
, LONG
):
4762 if (fragP
->fr_opcode
[0] == 0x61) /* jbsr */
4764 if (flag_keep_pcrel
)
4765 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4766 fragP
->fr_opcode
[0] = 0x4E;
4767 fragP
->fr_opcode
[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4768 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4769 0, RELAX_RELOC_ABS32
);
4772 else if (fragP
->fr_opcode
[0] == 0x60) /* jbra */
4774 if (flag_keep_pcrel
)
4775 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4776 fragP
->fr_opcode
[0] = 0x4E;
4777 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4778 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4779 0, RELAX_RELOC_ABS32
);
4784 /* This cannot happen, because jbsr and jbra are the only two
4785 unconditional branches. */
4789 case TAB (BRABSJCOND
, LONG
):
4790 if (flag_keep_pcrel
)
4791 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4793 /* Only Bcc 68000 instructions can come here
4794 Change bcc into b!cc/jmp absl long. */
4795 fragP
->fr_opcode
[0] ^= 0x01; /* Invert bcc. */
4796 fragP
->fr_opcode
[1] = 0x06; /* Branch offset = 6. */
4798 /* JF: these used to be fr_opcode[2,3], but they may be in a
4799 different frag, in which case referring to them is a no-no.
4800 Only fr_opcode[0,1] are guaranteed to work. */
4801 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4802 *buffer_address
++ = (char) 0xf9;
4803 fragP
->fr_fix
+= 2; /* Account for jmp instruction. */
4804 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4805 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
4808 case TAB (FBRANCH
, SHORT
):
4809 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4810 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4811 1, RELAX_RELOC_PC16
);
4814 case TAB (FBRANCH
, LONG
):
4815 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit. */
4816 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4817 1, RELAX_RELOC_PC32
);
4820 case TAB (DBCCLBR
, SHORT
):
4821 case TAB (DBCCABSJ
, SHORT
):
4822 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4823 1, RELAX_RELOC_PC16
);
4826 case TAB (DBCCLBR
, LONG
):
4827 /* Only DBcc instructions can come here.
4828 Change dbcc into dbcc/bral.
4829 JF: these used to be fr_opcode[2-7], but that's wrong. */
4830 if (flag_keep_pcrel
)
4831 as_fatal (_("Tried to convert DBcc to absolute jump"));
4833 *buffer_address
++ = 0x00; /* Branch offset = 4. */
4834 *buffer_address
++ = 0x04;
4835 *buffer_address
++ = 0x60; /* Put in bra pc+6. */
4836 *buffer_address
++ = 0x06;
4837 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
4838 *buffer_address
++ = (char) 0xff;
4840 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
4841 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
, 1,
4845 case TAB (DBCCABSJ
, LONG
):
4846 /* Only DBcc instructions can come here.
4847 Change dbcc into dbcc/jmp.
4848 JF: these used to be fr_opcode[2-7], but that's wrong. */
4849 if (flag_keep_pcrel
)
4850 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4852 *buffer_address
++ = 0x00; /* Branch offset = 4. */
4853 *buffer_address
++ = 0x04;
4854 *buffer_address
++ = 0x60; /* Put in bra pc + 6. */
4855 *buffer_address
++ = 0x06;
4856 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
4857 *buffer_address
++ = (char) 0xf9;
4859 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
4860 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
, 0,
4864 case TAB (PCREL1632
, SHORT
):
4865 fragP
->fr_opcode
[1] &= ~0x3F;
4866 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4867 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4868 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4871 case TAB (PCREL1632
, LONG
):
4872 /* Already set to mode 7.3; this indicates: PC indirect with
4873 suppressed index, 32-bit displacement. */
4874 *buffer_address
++ = 0x01;
4875 *buffer_address
++ = 0x70;
4877 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4878 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4879 fixP
->fx_pcrel_adjust
= 2;
4882 case TAB (PCINDEX
, BYTE
):
4883 assert (fragP
->fr_fix
>= 2);
4884 buffer_address
[-2] &= ~1;
4885 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4886 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4887 fixP
->fx_pcrel_adjust
= 1;
4889 case TAB (PCINDEX
, SHORT
):
4890 assert (fragP
->fr_fix
>= 2);
4891 buffer_address
[-2] |= 0x1;
4892 buffer_address
[-1] = 0x20;
4893 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4894 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4895 fixP
->fx_pcrel_adjust
= 2;
4898 case TAB (PCINDEX
, LONG
):
4899 assert (fragP
->fr_fix
>= 2);
4900 buffer_address
[-2] |= 0x1;
4901 buffer_address
[-1] = 0x30;
4902 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4903 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4904 fixP
->fx_pcrel_adjust
= 2;
4907 case TAB (ABSTOPCREL
, SHORT
):
4908 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4909 1, RELAX_RELOC_PC16
);
4912 case TAB (ABSTOPCREL
, LONG
):
4913 if (flag_keep_pcrel
)
4914 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4915 /* The thing to do here is force it to ABSOLUTE LONG, since
4916 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4917 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4919 fragP
->fr_opcode
[1] &= ~0x3F;
4920 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4921 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4922 0, RELAX_RELOC_ABS32
);
4928 #ifndef BFD_ASSEMBLER
4931 md_convert_frag (object_headers
*headers ATTRIBUTE_UNUSED
,
4932 segT sec ATTRIBUTE_UNUSED
,
4935 md_convert_frag_1 (fragP
);
4941 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
4942 segT sec ATTRIBUTE_UNUSED
,
4945 md_convert_frag_1 (fragP
);
4949 /* Force truly undefined symbols to their maximum size, and generally set up
4950 the frag list to be relaxed
4953 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
4955 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4956 switch (fragP
->fr_subtype
)
4958 case TAB (BRANCHBWL
, SZ_UNDEF
):
4959 case TAB (BRABSJUNC
, SZ_UNDEF
):
4960 case TAB (BRABSJCOND
, SZ_UNDEF
):
4962 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4963 && relaxable_symbol (fragP
->fr_symbol
))
4965 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4967 else if (flag_short_refs
)
4969 /* Symbol is undefined and we want short ref. */
4970 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4974 /* Symbol is still undefined. Make it LONG. */
4975 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
4980 case TAB (BRANCHBW
, SZ_UNDEF
):
4982 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4983 && relaxable_symbol (fragP
->fr_symbol
))
4985 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4989 /* Symbol is undefined and we don't have long branches. */
4990 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4995 case TAB (FBRANCH
, SZ_UNDEF
):
4996 case TAB (DBCCLBR
, SZ_UNDEF
):
4997 case TAB (DBCCABSJ
, SZ_UNDEF
):
4998 case TAB (PCREL1632
, SZ_UNDEF
):
5000 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5001 && relaxable_symbol (fragP
->fr_symbol
))
5004 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5008 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5013 case TAB (PCINDEX
, SZ_UNDEF
):
5014 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5015 && relaxable_symbol (fragP
->fr_symbol
)))
5017 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
5021 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
5025 case TAB (ABSTOPCREL
, SZ_UNDEF
):
5027 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5028 && relaxable_symbol (fragP
->fr_symbol
)))
5030 fragP
->fr_subtype
= TAB (ABSTOPCREL
, SHORT
);
5034 fragP
->fr_subtype
= TAB (ABSTOPCREL
, LONG
);
5043 /* Now that SZ_UNDEF are taken care of, check others. */
5044 switch (fragP
->fr_subtype
)
5046 case TAB (BRANCHBWL
, BYTE
):
5047 case TAB (BRABSJUNC
, BYTE
):
5048 case TAB (BRABSJCOND
, BYTE
):
5049 case TAB (BRANCHBW
, BYTE
):
5050 /* We can't do a short jump to the next instruction, so in that
5051 case we force word mode. If the symbol is at the start of a
5052 frag, and it is the next frag with any data in it (usually
5053 this is just the next frag, but assembler listings may
5054 introduce empty frags), we must use word mode. */
5055 if (fragP
->fr_symbol
)
5059 sym_frag
= symbol_get_frag (fragP
->fr_symbol
);
5060 if (S_GET_VALUE (fragP
->fr_symbol
) == sym_frag
->fr_address
)
5064 for (l
= fragP
->fr_next
; l
&& l
!= sym_frag
; l
= l
->fr_next
)
5068 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5075 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5078 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5079 /* the bit-field entries in the relocation_info struct plays hell
5080 with the byte-order problems of cross-assembly. So as a hack,
5081 I added this mach. dependent ri twiddler. Ugly, but it gets
5083 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5084 are symbolnum, most sig. byte first. Last byte is broken up with
5085 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5086 nibble as nuthin. (on Sun 3 at least) */
5087 /* Translate the internal relocation information into target-specific
5091 md_ri_to_chars (char *the_bytes
, struct reloc_info_generic
*ri
)
5094 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
5095 /* Now the fun stuff. */
5096 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
5097 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
5098 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
5099 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80)
5100 | ((ri
->r_length
<< 5) & 0x60)
5101 | ((ri
->r_extern
<< 4) & 0x10));
5106 #ifndef BFD_ASSEMBLER
5108 tc_aout_fix_to_chars (char *where
, fixS
*fixP
,
5109 relax_addressT segment_address_in_file
)
5112 * In: length of relocation (or of address) in chars: 1, 2 or 4.
5113 * Out: GNU LD relocation length code: 0, 1, or 2.
5116 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
5119 know (fixP
->fx_addsy
!= NULL
);
5121 md_number_to_chars (where
,
5122 (fixP
->fx_frag
->fr_address
5123 + fixP
->fx_where
- segment_address_in_file
), 4);
5125 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
5126 ? S_GET_TYPE (fixP
->fx_addsy
)
5127 : fixP
->fx_addsy
->sy_number
);
5129 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
5130 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
5131 where
[6] = r_symbolnum
& 0x0ff;
5132 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80)
5133 | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60)
5134 | ((!S_IS_DEFINED (fixP
->fx_addsy
) << 4) & 0x10));
5138 #endif /* OBJ_AOUT or OBJ_BOUT */
5140 #ifndef WORKING_DOT_WORD
5141 int md_short_jump_size
= 4;
5142 int md_long_jump_size
= 6;
5145 md_create_short_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5146 fragS
*frag ATTRIBUTE_UNUSED
,
5147 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
5151 offset
= to_addr
- (from_addr
+ 2);
5153 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
5154 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
5158 md_create_long_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5159 fragS
*frag
, symbolS
*to_symbol
)
5163 if (!HAVE_LONG_BRANCH (current_architecture
))
5165 if (flag_keep_pcrel
)
5166 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5167 offset
= to_addr
- S_GET_VALUE (to_symbol
);
5168 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
5169 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5170 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
5175 offset
= to_addr
- (from_addr
+ 2);
5176 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
5177 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5183 /* Different values of OK tell what its OK to return. Things that
5184 aren't OK are an error (what a shock, no?)
5187 10: Absolute 1:8 only
5188 20: Absolute 0:7 only
5189 30: absolute 0:15 only
5190 40: Absolute 0:31 only
5191 50: absolute 0:127 only
5192 55: absolute -64:63 only
5193 60: absolute -128:127 only
5194 70: absolute 0:4095 only
5195 80: absolute -1, 1:7 only
5199 get_num (struct m68k_exp
*exp
, int ok
)
5201 if (exp
->exp
.X_op
== O_absent
)
5203 /* Do the same thing the VAX asm does. */
5204 op (exp
) = O_constant
;
5210 as_warn (_("expression out of range: defaulting to 1"));
5214 else if (exp
->exp
.X_op
== O_constant
)
5219 if ((valueT
) TRUNC (offs (exp
)) - 1 > 7)
5221 as_warn (_("expression out of range: defaulting to 1"));
5226 if ((valueT
) TRUNC (offs (exp
)) > 7)
5230 if ((valueT
) TRUNC (offs (exp
)) > 15)
5234 if ((valueT
) TRUNC (offs (exp
)) > 32)
5238 if ((valueT
) TRUNC (offs (exp
)) > 127)
5242 if ((valueT
) SEXT (offs (exp
)) + 64 > 127)
5246 if ((valueT
) SEXT (offs (exp
)) + 128 > 255)
5250 if ((valueT
) TRUNC (offs (exp
)) > 4095)
5253 as_warn (_("expression out of range: defaulting to 0"));
5258 if ((valueT
) TRUNC (offs (exp
)) != 0xffffffff
5259 && (valueT
) TRUNC (offs (exp
)) - 1 > 6)
5261 as_warn (_("expression out of range: defaulting to 1"));
5269 else if (exp
->exp
.X_op
== O_big
)
5271 if (offs (exp
) <= 0 /* flonum. */
5272 && (ok
== 90 /* no bignums */
5273 || (ok
> 10 /* Small-int ranges including 0 ok. */
5274 /* If we have a flonum zero, a zero integer should
5275 do as well (e.g., in moveq). */
5276 && generic_floating_point_number
.exponent
== 0
5277 && generic_floating_point_number
.low
[0] == 0)))
5279 /* HACK! Turn it into a long. */
5280 LITTLENUM_TYPE words
[6];
5282 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5283 op (exp
) = O_constant
;
5286 offs (exp
) = words
[1] | (words
[0] << 16);
5290 op (exp
) = O_constant
;
5293 offs (exp
) = (ok
== 10) ? 1 : 0;
5294 as_warn (_("Can't deal with expression; defaulting to %ld"),
5300 if (ok
>= 10 && ok
<= 80)
5302 op (exp
) = O_constant
;
5305 offs (exp
) = (ok
== 10) ? 1 : 0;
5306 as_warn (_("Can't deal with expression; defaulting to %ld"),
5311 if (exp
->size
!= SIZE_UNSPEC
)
5319 if (!isbyte (offs (exp
)))
5320 as_warn (_("expression doesn't fit in BYTE"));
5323 if (!isword (offs (exp
)))
5324 as_warn (_("expression doesn't fit in WORD"));
5332 /* These are the back-ends for the various machine dependent pseudo-ops. */
5335 s_data1 (int ignore ATTRIBUTE_UNUSED
)
5337 subseg_set (data_section
, 1);
5338 demand_empty_rest_of_line ();
5342 s_data2 (int ignore ATTRIBUTE_UNUSED
)
5344 subseg_set (data_section
, 2);
5345 demand_empty_rest_of_line ();
5349 s_bss (int ignore ATTRIBUTE_UNUSED
)
5351 /* We don't support putting frags in the BSS segment, we fake it
5352 by marking in_bss, then looking at s_skip for clues. */
5354 subseg_set (bss_section
, 0);
5355 demand_empty_rest_of_line ();
5359 s_even (int ignore ATTRIBUTE_UNUSED
)
5362 register long temp_fill
;
5364 temp
= 1; /* JF should be 2? */
5365 temp_fill
= get_absolute_expression ();
5366 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5367 frag_align (temp
, (int) temp_fill
, 0);
5368 demand_empty_rest_of_line ();
5369 record_alignment (now_seg
, temp
);
5373 s_proc (int ignore ATTRIBUTE_UNUSED
)
5375 demand_empty_rest_of_line ();
5378 /* Pseudo-ops handled for MRI compatibility. */
5380 /* This function returns non-zero if the argument is a conditional
5381 pseudo-op. This is called when checking whether a pending
5382 alignment is needed. */
5385 m68k_conditional_pseudoop (pseudo_typeS
*pop
)
5387 return (pop
->poc_handler
== s_mri_if
5388 || pop
->poc_handler
== s_mri_else
);
5391 /* Handle an MRI style chip specification. */
5400 s
= input_line_pointer
;
5401 /* We can't use get_symbol_end since the processor names are not proper
5403 while (is_part_of_name (c
= *input_line_pointer
++))
5405 *--input_line_pointer
= 0;
5406 for (i
= 0; i
< n_archs
; i
++)
5407 if (strcasecmp (s
, archs
[i
].name
) == 0)
5411 as_bad (_("%s: unrecognized processor name"), s
);
5412 *input_line_pointer
= c
;
5413 ignore_rest_of_line ();
5416 *input_line_pointer
= c
;
5418 if (*input_line_pointer
== '/')
5419 current_architecture
= 0;
5421 current_architecture
&= m68881
| m68851
;
5422 current_architecture
|= archs
[i
].arch
;
5423 current_chip
= archs
[i
].chip
;
5425 while (*input_line_pointer
== '/')
5427 ++input_line_pointer
;
5428 s
= input_line_pointer
;
5429 /* We can't use get_symbol_end since the processor names are not
5431 while (is_part_of_name (c
= *input_line_pointer
++))
5433 *--input_line_pointer
= 0;
5434 if (strcmp (s
, "68881") == 0)
5435 current_architecture
|= m68881
;
5436 else if (strcmp (s
, "68851") == 0)
5437 current_architecture
|= m68851
;
5438 *input_line_pointer
= c
;
5441 /* Update info about available control registers. */
5442 select_control_regs ();
5445 /* The MRI CHIP pseudo-op. */
5448 s_chip (int ignore ATTRIBUTE_UNUSED
)
5454 stop
= mri_comment_field (&stopc
);
5457 mri_comment_end (stop
, stopc
);
5458 demand_empty_rest_of_line ();
5461 /* The MRI FOPT pseudo-op. */
5464 s_fopt (int ignore ATTRIBUTE_UNUSED
)
5468 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5472 input_line_pointer
+= 3;
5473 temp
= get_absolute_expression ();
5474 if (temp
< 0 || temp
> 7)
5475 as_bad (_("bad coprocessor id"));
5477 m68k_float_copnum
= COP0
+ temp
;
5481 as_bad (_("unrecognized fopt option"));
5482 ignore_rest_of_line ();
5486 demand_empty_rest_of_line ();
5489 /* The structure used to handle the MRI OPT pseudo-op. */
5493 /* The name of the option. */
5496 /* If this is not NULL, just call this function. The first argument
5497 is the ARG field of this structure, the second argument is
5498 whether the option was negated. */
5499 void (*pfn
) (int arg
, int on
);
5501 /* If this is not NULL, and the PFN field is NULL, set the variable
5502 this points to. Set it to the ARG field if the option was not
5503 negated, and the NOTARG field otherwise. */
5506 /* The value to pass to PFN or to assign to *PVAR. */
5509 /* The value to assign to *PVAR if the option is negated. If PFN is
5510 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5511 the option may not be negated. */
5515 /* The table used to handle the MRI OPT pseudo-op. */
5517 static void skip_to_comma (int, int);
5518 static void opt_nest (int, int);
5519 static void opt_chip (int, int);
5520 static void opt_list (int, int);
5521 static void opt_list_symbols (int, int);
5523 static const struct opt_action opt_table
[] =
5525 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5527 /* We do relaxing, so there is little use for these options. */
5528 { "b", 0, 0, 0, 0 },
5529 { "brs", 0, 0, 0, 0 },
5530 { "brb", 0, 0, 0, 0 },
5531 { "brl", 0, 0, 0, 0 },
5532 { "brw", 0, 0, 0, 0 },
5534 { "c", 0, 0, 0, 0 },
5535 { "cex", 0, 0, 0, 0 },
5536 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5537 { "cl", 0, 0, 0, 0 },
5538 { "cre", 0, 0, 0, 0 },
5539 { "d", 0, &flag_keep_locals
, 1, 0 },
5540 { "e", 0, 0, 0, 0 },
5541 { "f", 0, &flag_short_refs
, 1, 0 },
5542 { "frs", 0, &flag_short_refs
, 1, 0 },
5543 { "frl", 0, &flag_short_refs
, 0, 1 },
5544 { "g", 0, 0, 0, 0 },
5545 { "i", 0, 0, 0, 0 },
5546 { "m", 0, 0, 0, 0 },
5547 { "mex", 0, 0, 0, 0 },
5548 { "mc", 0, 0, 0, 0 },
5549 { "md", 0, 0, 0, 0 },
5550 { "nest", opt_nest
, 0, 0, 0 },
5551 { "next", skip_to_comma
, 0, 0, 0 },
5552 { "o", 0, 0, 0, 0 },
5553 { "old", 0, 0, 0, 0 },
5554 { "op", skip_to_comma
, 0, 0, 0 },
5555 { "pco", 0, 0, 0, 0 },
5556 { "p", opt_chip
, 0, 0, 0 },
5557 { "pcr", 0, 0, 0, 0 },
5558 { "pcs", 0, 0, 0, 0 },
5559 { "r", 0, 0, 0, 0 },
5560 { "quick", 0, &m68k_quick
, 1, 0 },
5561 { "rel32", 0, &m68k_rel32
, 1, 0 },
5562 { "s", opt_list
, 0, 0, 0 },
5563 { "t", opt_list_symbols
, 0, 0, 0 },
5564 { "w", 0, &flag_no_warnings
, 0, 1 },
5568 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5570 /* The MRI OPT pseudo-op. */
5573 s_opt (int ignore ATTRIBUTE_UNUSED
)
5581 const struct opt_action
*o
;
5586 if (*input_line_pointer
== '-')
5588 ++input_line_pointer
;
5591 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5593 input_line_pointer
+= 2;
5597 s
= input_line_pointer
;
5598 c
= get_symbol_end ();
5600 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5602 if (strcasecmp (s
, o
->name
) == 0)
5606 /* Restore input_line_pointer now in case the option
5608 *input_line_pointer
= c
;
5609 (*o
->pfn
) (o
->arg
, t
);
5611 else if (o
->pvar
!= NULL
)
5613 if (! t
&& o
->arg
== o
->notarg
)
5614 as_bad (_("option `%s' may not be negated"), s
);
5615 *input_line_pointer
= c
;
5616 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5619 *input_line_pointer
= c
;
5625 as_bad (_("option `%s' not recognized"), s
);
5626 *input_line_pointer
= c
;
5629 while (*input_line_pointer
++ == ',');
5631 /* Move back to terminating character. */
5632 --input_line_pointer
;
5633 demand_empty_rest_of_line ();
5636 /* Skip ahead to a comma. This is used for OPT options which we do
5637 not support and which take arguments. */
5640 skip_to_comma (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5642 while (*input_line_pointer
!= ','
5643 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5644 ++input_line_pointer
;
5647 /* Handle the OPT NEST=depth option. */
5650 opt_nest (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5652 if (*input_line_pointer
!= '=')
5654 as_bad (_("bad format of OPT NEST=depth"));
5658 ++input_line_pointer
;
5659 max_macro_nest
= get_absolute_expression ();
5662 /* Handle the OPT P=chip option. */
5665 opt_chip (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5667 if (*input_line_pointer
!= '=')
5669 /* This is just OPT P, which we do not support. */
5673 ++input_line_pointer
;
5677 /* Handle the OPT S option. */
5680 opt_list (int arg ATTRIBUTE_UNUSED
, int on
)
5685 /* Handle the OPT T option. */
5688 opt_list_symbols (int arg ATTRIBUTE_UNUSED
, int on
)
5691 listing
|= LISTING_SYMBOLS
;
5693 listing
&= ~LISTING_SYMBOLS
;
5696 /* Handle the MRI REG pseudo-op. */
5699 s_reg (int ignore ATTRIBUTE_UNUSED
)
5708 if (line_label
== NULL
)
5710 as_bad (_("missing label"));
5711 ignore_rest_of_line ();
5716 stop
= mri_comment_field (&stopc
);
5720 s
= input_line_pointer
;
5721 while (ISALNUM (*input_line_pointer
)
5722 #ifdef REGISTER_PREFIX
5723 || *input_line_pointer
== REGISTER_PREFIX
5725 || *input_line_pointer
== '/'
5726 || *input_line_pointer
== '-')
5727 ++input_line_pointer
;
5728 c
= *input_line_pointer
;
5729 *input_line_pointer
= '\0';
5731 if (m68k_ip_op (s
, &rop
) != 0)
5733 if (rop
.error
== NULL
)
5734 as_bad (_("bad register list"));
5736 as_bad (_("bad register list: %s"), rop
.error
);
5737 *input_line_pointer
= c
;
5738 ignore_rest_of_line ();
5742 *input_line_pointer
= c
;
5744 if (rop
.mode
== REGLST
)
5746 else if (rop
.mode
== DREG
)
5747 mask
= 1 << (rop
.reg
- DATA0
);
5748 else if (rop
.mode
== AREG
)
5749 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5750 else if (rop
.mode
== FPREG
)
5751 mask
= 1 << (rop
.reg
- FP0
+ 16);
5752 else if (rop
.mode
== CONTROL
5755 else if (rop
.mode
== CONTROL
5758 else if (rop
.mode
== CONTROL
5763 as_bad (_("bad register list"));
5764 ignore_rest_of_line ();
5768 S_SET_SEGMENT (line_label
, reg_section
);
5769 S_SET_VALUE (line_label
, ~mask
);
5770 symbol_set_frag (line_label
, &zero_address_frag
);
5773 mri_comment_end (stop
, stopc
);
5775 demand_empty_rest_of_line ();
5778 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5782 struct save_opts
*next
;
5784 int symbols_case_sensitive
;
5793 /* FIXME: We don't save OPT S. */
5796 /* This variable holds the stack of saved options. */
5798 static struct save_opts
*save_stack
;
5800 /* The MRI SAVE pseudo-op. */
5803 s_save (int ignore ATTRIBUTE_UNUSED
)
5805 struct save_opts
*s
;
5807 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5808 s
->abspcadd
= m68k_abspcadd
;
5809 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5810 s
->keep_locals
= flag_keep_locals
;
5811 s
->short_refs
= flag_short_refs
;
5812 s
->architecture
= current_architecture
;
5813 s
->chip
= current_chip
;
5814 s
->quick
= m68k_quick
;
5815 s
->rel32
= m68k_rel32
;
5816 s
->listing
= listing
;
5817 s
->no_warnings
= flag_no_warnings
;
5819 s
->next
= save_stack
;
5822 demand_empty_rest_of_line ();
5825 /* The MRI RESTORE pseudo-op. */
5828 s_restore (int ignore ATTRIBUTE_UNUSED
)
5830 struct save_opts
*s
;
5832 if (save_stack
== NULL
)
5834 as_bad (_("restore without save"));
5835 ignore_rest_of_line ();
5840 save_stack
= s
->next
;
5842 m68k_abspcadd
= s
->abspcadd
;
5843 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5844 flag_keep_locals
= s
->keep_locals
;
5845 flag_short_refs
= s
->short_refs
;
5846 current_architecture
= s
->architecture
;
5847 current_chip
= s
->chip
;
5848 m68k_quick
= s
->quick
;
5849 m68k_rel32
= s
->rel32
;
5850 listing
= s
->listing
;
5851 flag_no_warnings
= s
->no_warnings
;
5855 demand_empty_rest_of_line ();
5858 /* Types of MRI structured control directives. */
5860 enum mri_control_type
5868 /* This structure is used to stack the MRI structured control
5871 struct mri_control_info
5873 /* The directive within which this one is enclosed. */
5874 struct mri_control_info
*outer
;
5876 /* The type of directive. */
5877 enum mri_control_type type
;
5879 /* Whether an ELSE has been in an IF. */
5882 /* The add or sub statement at the end of a FOR. */
5885 /* The label of the top of a FOR or REPEAT loop. */
5888 /* The label to jump to for the next iteration, or the else
5889 expression of a conditional. */
5892 /* The label to jump to to break out of the loop, or the label past
5893 the end of a conditional. */
5897 /* The stack of MRI structured control directives. */
5899 static struct mri_control_info
*mri_control_stack
;
5901 /* The current MRI structured control directive index number, used to
5902 generate label names. */
5904 static int mri_control_index
;
5906 /* Assemble an instruction for an MRI structured control directive. */
5909 mri_assemble (char *str
)
5913 /* md_assemble expects the opcode to be in lower case. */
5914 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
5920 /* Generate a new MRI label structured control directive label name. */
5923 mri_control_label (void)
5927 n
= (char *) xmalloc (20);
5928 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5929 ++mri_control_index
;
5933 /* Create a new MRI structured control directive. */
5935 static struct mri_control_info
*
5936 push_mri_control (enum mri_control_type type
)
5938 struct mri_control_info
*n
;
5940 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5944 if (type
== mri_if
|| type
== mri_while
)
5947 n
->top
= mri_control_label ();
5948 n
->next
= mri_control_label ();
5949 n
->bottom
= mri_control_label ();
5951 n
->outer
= mri_control_stack
;
5952 mri_control_stack
= n
;
5957 /* Pop off the stack of MRI structured control directives. */
5960 pop_mri_control (void)
5962 struct mri_control_info
*n
;
5964 n
= mri_control_stack
;
5965 mri_control_stack
= n
->outer
;
5973 /* Recognize a condition code in an MRI structured control expression. */
5976 parse_mri_condition (int *pcc
)
5980 know (*input_line_pointer
== '<');
5982 ++input_line_pointer
;
5983 c1
= *input_line_pointer
++;
5984 c2
= *input_line_pointer
++;
5986 if (*input_line_pointer
!= '>')
5988 as_bad (_("syntax error in structured control directive"));
5992 ++input_line_pointer
;
5998 *pcc
= (c1
<< 8) | c2
;
6003 /* Parse a single operand in an MRI structured control expression. */
6006 parse_mri_control_operand (int *pcc
, char **leftstart
, char **leftstop
,
6007 char **rightstart
, char **rightstop
)
6019 if (*input_line_pointer
== '<')
6021 /* It's just a condition code. */
6022 return parse_mri_condition (pcc
);
6025 /* Look ahead for the condition code. */
6026 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6028 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
6033 as_bad (_("missing condition code in structured control directive"));
6037 *leftstart
= input_line_pointer
;
6039 if (*leftstop
> *leftstart
6040 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
6043 input_line_pointer
= s
;
6044 if (! parse_mri_condition (pcc
))
6047 /* Look ahead for AND or OR or end of line. */
6048 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6050 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6051 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6053 if ((s
== input_line_pointer
6056 && ((strncasecmp (s
, "AND", 3) == 0
6057 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
6058 || (strncasecmp (s
, "OR", 2) == 0
6059 && (s
[2] == '.' || ! is_part_of_name (s
[2])))))
6063 *rightstart
= input_line_pointer
;
6065 if (*rightstop
> *rightstart
6066 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
6069 input_line_pointer
= s
;
6074 #define MCC(b1, b2) (((b1) << 8) | (b2))
6076 /* Swap the sense of a condition. This changes the condition so that
6077 it generates the same result when the operands are swapped. */
6080 swap_mri_condition (int cc
)
6084 case MCC ('h', 'i'): return MCC ('c', 's');
6085 case MCC ('l', 's'): return MCC ('c', 'c');
6086 /* <HS> is an alias for <CC>. */
6087 case MCC ('h', 's'):
6088 case MCC ('c', 'c'): return MCC ('l', 's');
6089 /* <LO> is an alias for <CS>. */
6090 case MCC ('l', 'o'):
6091 case MCC ('c', 's'): return MCC ('h', 'i');
6092 case MCC ('p', 'l'): return MCC ('m', 'i');
6093 case MCC ('m', 'i'): return MCC ('p', 'l');
6094 case MCC ('g', 'e'): return MCC ('l', 'e');
6095 case MCC ('l', 't'): return MCC ('g', 't');
6096 case MCC ('g', 't'): return MCC ('l', 't');
6097 case MCC ('l', 'e'): return MCC ('g', 'e');
6098 /* Issue a warning for conditions we can not swap. */
6099 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
6100 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
6101 case MCC ('v', 'c'):
6102 case MCC ('v', 's'):
6104 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6105 (char) (cc
>> 8), (char) (cc
));
6111 /* Reverse the sense of a condition. */
6114 reverse_mri_condition (int cc
)
6118 case MCC ('h', 'i'): return MCC ('l', 's');
6119 case MCC ('l', 's'): return MCC ('h', 'i');
6120 /* <HS> is an alias for <CC> */
6121 case MCC ('h', 's'): return MCC ('l', 'o');
6122 case MCC ('c', 'c'): return MCC ('c', 's');
6123 /* <LO> is an alias for <CS> */
6124 case MCC ('l', 'o'): return MCC ('h', 's');
6125 case MCC ('c', 's'): return MCC ('c', 'c');
6126 case MCC ('n', 'e'): return MCC ('e', 'q');
6127 case MCC ('e', 'q'): return MCC ('n', 'e');
6128 case MCC ('v', 'c'): return MCC ('v', 's');
6129 case MCC ('v', 's'): return MCC ('v', 'c');
6130 case MCC ('p', 'l'): return MCC ('m', 'i');
6131 case MCC ('m', 'i'): return MCC ('p', 'l');
6132 case MCC ('g', 'e'): return MCC ('l', 't');
6133 case MCC ('l', 't'): return MCC ('g', 'e');
6134 case MCC ('g', 't'): return MCC ('l', 'e');
6135 case MCC ('l', 'e'): return MCC ('g', 't');
6140 /* Build an MRI structured control expression. This generates test
6141 and branch instructions. It goes to TRUELAB if the condition is
6142 true, and to FALSELAB if the condition is false. Exactly one of
6143 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6144 is the size qualifier for the expression. EXTENT is the size to
6145 use for the branch. */
6148 build_mri_control_operand (int qual
, int cc
, char *leftstart
, char *leftstop
,
6149 char *rightstart
, char *rightstop
,
6150 const char *truelab
, const char *falselab
,
6156 if (leftstart
!= NULL
)
6158 struct m68k_op leftop
, rightop
;
6161 /* Swap the compare operands, if necessary, to produce a legal
6162 m68k compare instruction. Comparing a register operand with
6163 a non-register operand requires the register to be on the
6164 right (cmp, cmpa). Comparing an immediate value with
6165 anything requires the immediate value to be on the left
6170 (void) m68k_ip_op (leftstart
, &leftop
);
6175 (void) m68k_ip_op (rightstart
, &rightop
);
6178 if (rightop
.mode
== IMMED
6179 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
6180 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
6184 /* Correct conditional handling:
6185 if #1 <lt> d0 then ;means if (1 < d0)
6191 cmp #1,d0 if we do *not* swap the operands
6192 bgt true we need the swapped condition!
6199 leftstart
= rightstart
;
6202 leftstop
= rightstop
;
6207 cc
= swap_mri_condition (cc
);
6211 if (truelab
== NULL
)
6213 cc
= reverse_mri_condition (cc
);
6217 if (leftstart
!= NULL
)
6219 buf
= (char *) xmalloc (20
6220 + (leftstop
- leftstart
)
6221 + (rightstop
- rightstart
));
6227 *s
++ = TOLOWER (qual
);
6229 memcpy (s
, leftstart
, leftstop
- leftstart
);
6230 s
+= leftstop
- leftstart
;
6232 memcpy (s
, rightstart
, rightstop
- rightstart
);
6233 s
+= rightstop
- rightstart
;
6239 buf
= (char *) xmalloc (20 + strlen (truelab
));
6245 *s
++ = TOLOWER (extent
);
6247 strcpy (s
, truelab
);
6252 /* Parse an MRI structured control expression. This generates test
6253 and branch instructions. STOP is where the expression ends. It
6254 goes to TRUELAB if the condition is true, and to FALSELAB if the
6255 condition is false. Exactly one of TRUELAB and FALSELAB will be
6256 NULL, meaning to fall through. QUAL is the size qualifier for the
6257 expression. EXTENT is the size to use for the branch. */
6260 parse_mri_control_expression (char *stop
, int qual
, const char *truelab
,
6261 const char *falselab
, int extent
)
6273 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6274 &rightstart
, &rightstop
))
6280 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6284 if (falselab
!= NULL
)
6287 flab
= mri_control_label ();
6289 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6290 rightstop
, (const char *) NULL
, flab
, extent
);
6292 input_line_pointer
+= 3;
6293 if (*input_line_pointer
!= '.'
6294 || input_line_pointer
[1] == '\0')
6298 qual
= input_line_pointer
[1];
6299 input_line_pointer
+= 2;
6302 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6303 &rightstart
, &rightstop
))
6309 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6310 rightstop
, truelab
, falselab
, extent
);
6312 if (falselab
== NULL
)
6315 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6319 if (truelab
!= NULL
)
6322 tlab
= mri_control_label ();
6324 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6325 rightstop
, tlab
, (const char *) NULL
, extent
);
6327 input_line_pointer
+= 2;
6328 if (*input_line_pointer
!= '.'
6329 || input_line_pointer
[1] == '\0')
6333 qual
= input_line_pointer
[1];
6334 input_line_pointer
+= 2;
6337 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6338 &rightstart
, &rightstop
))
6344 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6345 rightstop
, truelab
, falselab
, extent
);
6347 if (truelab
== NULL
)
6352 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6353 rightstop
, truelab
, falselab
, extent
);
6357 if (input_line_pointer
!= stop
)
6358 as_bad (_("syntax error in structured control directive"));
6361 /* Handle the MRI IF pseudo-op. This may be a structured control
6362 directive, or it may be a regular assembler conditional, depending
6370 struct mri_control_info
*n
;
6372 /* A structured control directive must end with THEN with an
6373 optional qualifier. */
6374 s
= input_line_pointer
;
6375 /* We only accept '*' as introduction of comments if preceded by white space
6376 or at first column of a line (I think this can't actually happen here?)
6377 This is important when assembling:
6378 if d0 <ne> 12(a0,d0*2) then
6379 if d0 <ne> #CONST*20 then. */
6380 while (! (is_end_of_line
[(unsigned char) *s
]
6383 && (s
== input_line_pointer
6385 || *(s
-1) == '\t'))))
6388 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6391 if (s
- input_line_pointer
> 1
6395 if (s
- input_line_pointer
< 3
6396 || strncasecmp (s
- 3, "THEN", 4) != 0)
6400 as_bad (_("missing then"));
6401 ignore_rest_of_line ();
6405 /* It's a conditional. */
6410 /* Since this might be a conditional if, this pseudo-op will be
6411 called even if we are supported to be ignoring input. Double
6412 check now. Clobber *input_line_pointer so that ignore_input
6413 thinks that this is not a special pseudo-op. */
6414 c
= *input_line_pointer
;
6415 *input_line_pointer
= 0;
6416 if (ignore_input ())
6418 *input_line_pointer
= c
;
6419 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6420 ++input_line_pointer
;
6421 demand_empty_rest_of_line ();
6424 *input_line_pointer
= c
;
6426 n
= push_mri_control (mri_if
);
6428 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6429 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6432 input_line_pointer
= s
+ 3;
6434 input_line_pointer
= s
+ 1;
6438 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6439 ++input_line_pointer
;
6442 demand_empty_rest_of_line ();
6445 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6446 structured IF, associate the ELSE with the IF. Otherwise, assume
6447 it is a conditional else. */
6450 s_mri_else (int qual
)
6457 && (mri_control_stack
== NULL
6458 || mri_control_stack
->type
!= mri_if
6459 || mri_control_stack
->else_seen
))
6465 c
= *input_line_pointer
;
6466 *input_line_pointer
= 0;
6467 if (ignore_input ())
6469 *input_line_pointer
= c
;
6470 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6471 ++input_line_pointer
;
6472 demand_empty_rest_of_line ();
6475 *input_line_pointer
= c
;
6477 if (mri_control_stack
== NULL
6478 || mri_control_stack
->type
!= mri_if
6479 || mri_control_stack
->else_seen
)
6481 as_bad (_("else without matching if"));
6482 ignore_rest_of_line ();
6486 mri_control_stack
->else_seen
= 1;
6488 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6489 q
[0] = TOLOWER (qual
);
6491 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6495 colon (mri_control_stack
->next
);
6499 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6500 ++input_line_pointer
;
6503 demand_empty_rest_of_line ();
6506 /* Handle the MRI ENDI pseudo-op. */
6509 s_mri_endi (int ignore ATTRIBUTE_UNUSED
)
6511 if (mri_control_stack
== NULL
6512 || mri_control_stack
->type
!= mri_if
)
6514 as_bad (_("endi without matching if"));
6515 ignore_rest_of_line ();
6519 /* ignore_input will not return true for ENDI, so we don't need to
6520 worry about checking it again here. */
6522 if (! mri_control_stack
->else_seen
)
6523 colon (mri_control_stack
->next
);
6524 colon (mri_control_stack
->bottom
);
6530 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6531 ++input_line_pointer
;
6534 demand_empty_rest_of_line ();
6537 /* Handle the MRI BREAK pseudo-op. */
6540 s_mri_break (int extent
)
6542 struct mri_control_info
*n
;
6546 n
= mri_control_stack
;
6548 && n
->type
!= mri_for
6549 && n
->type
!= mri_repeat
6550 && n
->type
!= mri_while
)
6554 as_bad (_("break outside of structured loop"));
6555 ignore_rest_of_line ();
6559 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6560 ex
[0] = TOLOWER (extent
);
6562 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6568 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6569 ++input_line_pointer
;
6572 demand_empty_rest_of_line ();
6575 /* Handle the MRI NEXT pseudo-op. */
6578 s_mri_next (int extent
)
6580 struct mri_control_info
*n
;
6584 n
= mri_control_stack
;
6586 && n
->type
!= mri_for
6587 && n
->type
!= mri_repeat
6588 && n
->type
!= mri_while
)
6592 as_bad (_("next outside of structured loop"));
6593 ignore_rest_of_line ();
6597 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6598 ex
[0] = TOLOWER (extent
);
6600 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6606 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6607 ++input_line_pointer
;
6610 demand_empty_rest_of_line ();
6613 /* Handle the MRI FOR pseudo-op. */
6616 s_mri_for (int qual
)
6618 const char *varstart
, *varstop
;
6619 const char *initstart
, *initstop
;
6620 const char *endstart
, *endstop
;
6621 const char *bystart
, *bystop
;
6625 struct mri_control_info
*n
;
6631 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6635 varstart
= input_line_pointer
;
6637 /* Look for the '='. */
6638 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6639 && *input_line_pointer
!= '=')
6640 ++input_line_pointer
;
6641 if (*input_line_pointer
!= '=')
6643 as_bad (_("missing ="));
6644 ignore_rest_of_line ();
6648 varstop
= input_line_pointer
;
6649 if (varstop
> varstart
6650 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6653 ++input_line_pointer
;
6655 initstart
= input_line_pointer
;
6657 /* Look for TO or DOWNTO. */
6660 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6662 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6663 && ! is_part_of_name (input_line_pointer
[2]))
6665 initstop
= input_line_pointer
;
6666 input_line_pointer
+= 2;
6669 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6670 && ! is_part_of_name (input_line_pointer
[6]))
6672 initstop
= input_line_pointer
;
6674 input_line_pointer
+= 6;
6677 ++input_line_pointer
;
6679 if (initstop
== NULL
)
6681 as_bad (_("missing to or downto"));
6682 ignore_rest_of_line ();
6685 if (initstop
> initstart
6686 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6690 endstart
= input_line_pointer
;
6692 /* Look for BY or DO. */
6695 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6697 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6698 && ! is_part_of_name (input_line_pointer
[2]))
6700 endstop
= input_line_pointer
;
6702 input_line_pointer
+= 2;
6705 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6706 && (input_line_pointer
[2] == '.'
6707 || ! is_part_of_name (input_line_pointer
[2])))
6709 endstop
= input_line_pointer
;
6710 input_line_pointer
+= 2;
6713 ++input_line_pointer
;
6715 if (endstop
== NULL
)
6717 as_bad (_("missing do"));
6718 ignore_rest_of_line ();
6721 if (endstop
> endstart
6722 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6728 bystop
= bystart
+ 2;
6733 bystart
= input_line_pointer
;
6737 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6739 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6740 && (input_line_pointer
[2] == '.'
6741 || ! is_part_of_name (input_line_pointer
[2])))
6743 bystop
= input_line_pointer
;
6744 input_line_pointer
+= 2;
6747 ++input_line_pointer
;
6751 as_bad (_("missing do"));
6752 ignore_rest_of_line ();
6755 if (bystop
> bystart
6756 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6760 if (*input_line_pointer
!= '.')
6764 extent
= input_line_pointer
[1];
6765 input_line_pointer
+= 2;
6768 /* We have fully parsed the FOR operands. Now build the loop. */
6769 n
= push_mri_control (mri_for
);
6771 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6773 /* Move init,var. */
6780 *s
++ = TOLOWER (qual
);
6782 memcpy (s
, initstart
, initstop
- initstart
);
6783 s
+= initstop
- initstart
;
6785 memcpy (s
, varstart
, varstop
- varstart
);
6786 s
+= varstop
- varstart
;
6798 *s
++ = TOLOWER (qual
);
6800 memcpy (s
, endstart
, endstop
- endstart
);
6801 s
+= endstop
- endstart
;
6803 memcpy (s
, varstart
, varstop
- varstart
);
6804 s
+= varstop
- varstart
;
6809 ex
[0] = TOLOWER (extent
);
6812 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6814 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6817 /* Put together the add or sub instruction used by ENDF. */
6825 *s
++ = TOLOWER (qual
);
6827 memcpy (s
, bystart
, bystop
- bystart
);
6828 s
+= bystop
- bystart
;
6830 memcpy (s
, varstart
, varstop
- varstart
);
6831 s
+= varstop
- varstart
;
6837 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6838 ++input_line_pointer
;
6841 demand_empty_rest_of_line ();
6844 /* Handle the MRI ENDF pseudo-op. */
6847 s_mri_endf (int ignore ATTRIBUTE_UNUSED
)
6849 if (mri_control_stack
== NULL
6850 || mri_control_stack
->type
!= mri_for
)
6852 as_bad (_("endf without for"));
6853 ignore_rest_of_line ();
6857 colon (mri_control_stack
->next
);
6859 mri_assemble (mri_control_stack
->incr
);
6861 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6862 mri_assemble (mri_control_stack
->incr
);
6864 free (mri_control_stack
->incr
);
6866 colon (mri_control_stack
->bottom
);
6872 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6873 ++input_line_pointer
;
6876 demand_empty_rest_of_line ();
6879 /* Handle the MRI REPEAT pseudo-op. */
6882 s_mri_repeat (int ignore ATTRIBUTE_UNUSED
)
6884 struct mri_control_info
*n
;
6886 n
= push_mri_control (mri_repeat
);
6890 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6891 ++input_line_pointer
;
6893 demand_empty_rest_of_line ();
6896 /* Handle the MRI UNTIL pseudo-op. */
6899 s_mri_until (int qual
)
6903 if (mri_control_stack
== NULL
6904 || mri_control_stack
->type
!= mri_repeat
)
6906 as_bad (_("until without repeat"));
6907 ignore_rest_of_line ();
6911 colon (mri_control_stack
->next
);
6913 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6916 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6917 mri_control_stack
->top
, '\0');
6919 colon (mri_control_stack
->bottom
);
6921 input_line_pointer
= s
;
6927 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6928 ++input_line_pointer
;
6931 demand_empty_rest_of_line ();
6934 /* Handle the MRI WHILE pseudo-op. */
6937 s_mri_while (int qual
)
6941 struct mri_control_info
*n
;
6943 s
= input_line_pointer
;
6944 /* We only accept '*' as introduction of comments if preceded by white space
6945 or at first column of a line (I think this can't actually happen here?)
6946 This is important when assembling:
6947 while d0 <ne> 12(a0,d0*2) do
6948 while d0 <ne> #CONST*20 do. */
6949 while (! (is_end_of_line
[(unsigned char) *s
]
6952 && (s
== input_line_pointer
6954 || *(s
-1) == '\t'))))
6957 while (*s
== ' ' || *s
== '\t')
6959 if (s
- input_line_pointer
> 1
6962 if (s
- input_line_pointer
< 2
6963 || strncasecmp (s
- 1, "DO", 2) != 0)
6965 as_bad (_("missing do"));
6966 ignore_rest_of_line ();
6970 n
= push_mri_control (mri_while
);
6974 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6975 s
[1] == '.' ? s
[2] : '\0');
6977 input_line_pointer
= s
+ 1;
6978 if (*input_line_pointer
== '.')
6979 input_line_pointer
+= 2;
6983 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6984 ++input_line_pointer
;
6987 demand_empty_rest_of_line ();
6990 /* Handle the MRI ENDW pseudo-op. */
6993 s_mri_endw (int ignore ATTRIBUTE_UNUSED
)
6997 if (mri_control_stack
== NULL
6998 || mri_control_stack
->type
!= mri_while
)
7000 as_bad (_("endw without while"));
7001 ignore_rest_of_line ();
7005 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
7006 sprintf (buf
, "bra %s", mri_control_stack
->next
);
7010 colon (mri_control_stack
->bottom
);
7016 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7017 ++input_line_pointer
;
7020 demand_empty_rest_of_line ();
7024 Invocation line includes a switch not recognized by the base assembler.
7025 See if it's a processor-specific option. These are:
7027 -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
7028 -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
7029 Select the architecture. Instructions or features not
7030 supported by the selected architecture cause fatal
7031 errors. More than one may be specified. The default is
7032 -m68020 -m68851 -m68881. Note that -m68008 is a synonym
7033 for -m68000, and -m68882 is a synonym for -m68881.
7034 -[A]m[c]no-68851, -[A]m[c]no-68881
7035 Don't accept 688?1 instructions. (The "c" is kind of silly,
7036 so don't use or document it, but that's the way the parsing
7040 -k Indicates PIC. (Sun 3 only.)
7042 Never turn PC-relative branches into absolute jumps.
7044 Permit `|' to be used in expressions. */
7047 const char *md_shortopts
= "lSA:m:kQ:V";
7049 const char *md_shortopts
= "lSA:m:k";
7052 struct option md_longopts
[] = {
7053 #define OPTION_PIC (OPTION_MD_BASE)
7054 {"pic", no_argument
, NULL
, OPTION_PIC
},
7055 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7056 {"register-prefix-optional", no_argument
, NULL
,
7057 OPTION_REGISTER_PREFIX_OPTIONAL
},
7058 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7059 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
7060 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7061 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
7062 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7063 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
7064 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7065 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
7066 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7067 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
7068 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7069 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
7070 {NULL
, no_argument
, NULL
, 0}
7072 size_t md_longopts_size
= sizeof (md_longopts
);
7075 md_parse_option (int c
, char *arg
)
7079 case 'l': /* -l means keep external to 2 bit offset
7080 rather than 16 bit one. */
7081 flag_short_refs
= 1;
7084 case 'S': /* -S means that jbsr's always turn into
7086 flag_long_jumps
= 1;
7089 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
7090 branches into absolute jumps. */
7091 flag_keep_pcrel
= 1;
7097 /* Intentional fall-through. */
7100 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
7109 if (arg
[0] == 'c' && arg
[1] == '6')
7112 for (i
= 0; i
< n_archs
; i
++)
7113 if (!strcmp (arg
, archs
[i
].name
))
7118 arch
= archs
[i
].arch
;
7121 else if (arch
== m68851
)
7130 if (arg
[0] == 'c' && arg
[1] == '6')
7133 for (i
= 0; i
< n_archs
; i
++)
7134 if (!strcmp (arg
, archs
[i
].name
))
7136 unsigned long arch
= archs
[i
].arch
;
7138 if (cpu_of_arch (arch
))
7139 /* It's a cpu spec. */
7141 current_architecture
&= ~m68000up
;
7142 current_architecture
|= arch
;
7143 current_chip
= archs
[i
].chip
;
7145 else if (arch
== m68881
)
7147 current_architecture
|= m68881
;
7150 else if (arch
== m68851
)
7152 current_architecture
|= m68851
;
7162 as_bad (_("unrecognized architecture specification `%s'"), arg
);
7171 break; /* -pic, Position Independent Code. */
7173 case OPTION_REGISTER_PREFIX_OPTIONAL
:
7174 flag_reg_prefix_optional
= 1;
7175 reg_prefix_optional_seen
= 1;
7178 /* -V: SVR4 argument to print version ID. */
7180 print_version_id ();
7183 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7184 should be emitted or not. FIXME: Not implemented. */
7188 case OPTION_BITWISE_OR
:
7193 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
7195 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
7199 m68k_comment_chars
= n
;
7203 case OPTION_BASE_SIZE_DEFAULT_16
:
7204 m68k_index_width_default
= SIZE_WORD
;
7207 case OPTION_BASE_SIZE_DEFAULT_32
:
7208 m68k_index_width_default
= SIZE_LONG
;
7211 case OPTION_DISP_SIZE_DEFAULT_16
:
7213 m68k_rel32_from_cmdline
= 1;
7216 case OPTION_DISP_SIZE_DEFAULT_32
:
7218 m68k_rel32_from_cmdline
= 1;
7229 md_show_usage (FILE *stream
)
7231 const char *default_cpu
= TARGET_CPU
;
7233 unsigned int default_arch
;
7235 /* Get the canonical name for the default target CPU. */
7236 if (*default_cpu
== 'm')
7238 for (i
= 0; i
< n_archs
; i
++)
7240 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
7242 default_arch
= archs
[i
].arch
;
7243 for (i
= 0; i
< n_archs
; i
++)
7245 if (archs
[i
].arch
== default_arch
7248 default_cpu
= archs
[i
].name
;
7255 fprintf (stream
, _("\
7257 -l use 1 word for refs to undefined symbols [default 2]\n\
7258 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
7259 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
7260 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m521x | -m5249 |\n\
7261 -m528x | -m5307 | -m5407 | -m547x | -m548x | -mcfv4 | -mcfv4e\n\
7262 specify variant of 680X0 architecture [default %s]\n\
7263 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
7264 target has/lacks floating-point coprocessor\n\
7265 [default yes for 68020, 68030, and cpu32]\n"),
7267 fprintf (stream
, _("\
7268 -m68851 | -mno-68851\n\
7269 target has/lacks memory-management unit coprocessor\n\
7270 [default yes for 68020 and up]\n\
7271 -pic, -k generate position independent code\n\
7272 -S turn jbsr into jsr\n\
7273 --pcrel never turn PC-relative branches into absolute jumps\n\
7274 --register-prefix-optional\n\
7275 recognize register names without prefix character\n\
7276 --bitwise-or do not treat `|' as a comment character\n"));
7277 fprintf (stream
, _("\
7278 --base-size-default-16 base reg without size is 16 bits\n\
7279 --base-size-default-32 base reg without size is 32 bits (default)\n\
7280 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7281 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
7286 /* TEST2: Test md_assemble() */
7287 /* Warning, this routine probably doesn't work anymore. */
7291 struct m68k_it the_ins
;
7299 if (!gets (buf
) || !*buf
)
7301 if (buf
[0] == '|' || buf
[1] == '.')
7303 for (cp
= buf
; *cp
; cp
++)
7308 memset (&the_ins
, '\0', sizeof (the_ins
));
7309 m68k_ip (&the_ins
, buf
);
7312 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7316 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7317 for (n
= 0; n
< the_ins
.numo
; n
++)
7318 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7320 print_the_insn (&the_ins
.opcode
[0], stdout
);
7321 (void) putchar ('\n');
7323 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7325 if (the_ins
.operands
[n
].error
)
7327 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7330 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
,
7331 the_ins
.operands
[n
].reg
);
7332 if (the_ins
.operands
[n
].b_const
)
7333 printf ("Constant: '%.*s', ",
7334 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
,
7335 the_ins
.operands
[n
].b_const
);
7336 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
,
7337 the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7338 if (the_ins
.operands
[n
].b_iadd
)
7339 printf ("Iadd: '%.*s',",
7340 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
,
7341 the_ins
.operands
[n
].b_iadd
);
7350 is_label (char *str
)
7354 while (*str
&& *str
!= ' ')
7356 if (str
[-1] == ':' || str
[1] == '=')
7363 /* Possible states for relaxation:
7365 0 0 branch offset byte (bra, etc)
7369 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7373 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7380 /* We have no need to default values of symbols. */
7383 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
7388 /* Round up a section size to the appropriate boundary. */
7390 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
7393 #ifdef BFD_ASSEMBLER
7394 /* For a.out, force the section size to be aligned. If we don't do
7395 this, BFD will align it for us, but it will not write out the
7396 final bytes of the section. This may be a bug in BFD, but it is
7397 easier to fix it here since that is how the other a.out targets
7401 align
= bfd_get_section_alignment (stdoutput
, segment
);
7402 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
7409 /* Exactly what point is a PC-relative offset relative TO?
7410 On the 68k, it is relative to the address of the first extension
7411 word. The difference between the addresses of the offset and the
7412 first extension word is stored in fx_pcrel_adjust. */
7414 md_pcrel_from (fixS
*fixP
)
7418 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7419 sign extend the value here. */
7420 adjust
= ((fixP
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80;
7423 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7426 #ifndef BFD_ASSEMBLER
7430 tc_coff_symbol_emit_hook (symbolS
*ignore ATTRIBUTE_UNUSED
)
7435 tc_coff_sizemachdep (fragS
*frag
)
7437 switch (frag
->fr_subtype
& 0x3)
7456 m68k_elf_final_processing (void)
7458 /* Set file-specific flags if this is a cpu32 processor. */
7459 if (arch_coldfire_fpu (current_architecture
))
7460 elf_elfheader (stdoutput
)->e_flags
|= EF_CFV4E
;
7461 if (cpu_of_arch (current_architecture
) & cpu32
)
7462 elf_elfheader (stdoutput
)->e_flags
|= EF_CPU32
;
7463 else if ((cpu_of_arch (current_architecture
) & m68000up
)
7464 && !(cpu_of_arch (current_architecture
) & m68020up
))
7465 elf_elfheader (stdoutput
)->e_flags
|= EF_M68000
;
7470 tc_m68k_regname_to_dw2regnum (const char *regname
)
7472 unsigned int regnum
;
7473 static const char *const regnames
[] =
7475 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7476 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7477 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7481 for (regnum
= 0; regnum
< ARRAY_SIZE (regnames
); regnum
++)
7482 if (strcmp (regname
, regnames
[regnum
]) == 0)
7489 tc_m68k_frame_initial_instructions (void)
7491 static int sp_regno
= -1;
7494 sp_regno
= tc_m68k_regname_to_dw2regnum ("sp");
7496 cfi_add_CFA_def_cfa (sp_regno
, -DWARF2_CIE_DATA_ALIGNMENT
);
7497 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN
, DWARF2_CIE_DATA_ALIGNMENT
);