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 struct m68k_op operands_backup
[6];
1093 LITTLENUM_TYPE words
[6];
1094 LITTLENUM_TYPE
*wordp
;
1095 unsigned long ok_arch
= 0;
1097 if (*instring
== ' ')
1098 instring
++; /* Skip leading whitespace. */
1100 /* Scan up to end of operation-code, which MUST end in end-of-string
1101 or exactly 1 space. */
1103 for (p
= instring
; *p
!= '\0'; p
++)
1113 the_ins
.error
= _("No operator");
1117 /* p now points to the end of the opcode name, probably whitespace.
1118 Make sure the name is null terminated by clobbering the
1119 whitespace, look it up in the hash table, then fix it back.
1120 Remove a dot, first, since the opcode tables have none. */
1123 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1124 *pdotmove
= pdotmove
[1];
1130 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1135 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1136 *pdotmove
= pdotmove
[-1];
1143 the_ins
.error
= _("Unknown operator");
1147 /* Found a legitimate opcode, start matching operands. */
1151 if (opcode
->m_operands
== 0)
1153 char *old
= input_line_pointer
;
1155 input_line_pointer
= p
;
1156 /* Ahh - it's a motorola style psuedo op. */
1157 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1158 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1159 input_line_pointer
= old
;
1165 if (flag_mri
&& opcode
->m_opnum
== 0)
1167 /* In MRI mode, random garbage is allowed after an instruction
1168 which accepts no operands. */
1169 the_ins
.args
= opcode
->m_operands
;
1170 the_ins
.numargs
= opcode
->m_opnum
;
1171 the_ins
.numo
= opcode
->m_codenum
;
1172 the_ins
.opcode
[0] = getone (opcode
);
1173 the_ins
.opcode
[1] = gettwo (opcode
);
1177 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1179 p
= crack_operand (p
, opP
);
1183 the_ins
.error
= opP
->error
;
1188 opsfound
= opP
- &the_ins
.operands
[0];
1190 /* This ugly hack is to support the floating pt opcodes in their
1191 standard form. Essentially, we fake a first enty of type COP#1 */
1192 if (opcode
->m_operands
[0] == 'I')
1196 for (n
= opsfound
; n
> 0; --n
)
1197 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1199 memset (&the_ins
.operands
[0], '\0', sizeof (the_ins
.operands
[0]));
1200 the_ins
.operands
[0].mode
= CONTROL
;
1201 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1205 /* We've got the operands. Find an opcode that'll accept them. */
1208 /* If we didn't get the right number of ops, or we have no
1209 common model with this pattern then reject this pattern. */
1211 ok_arch
|= opcode
->m_arch
;
1212 if (opsfound
!= opcode
->m_opnum
1213 || ((opcode
->m_arch
& current_architecture
) == 0))
1219 /* Make a copy of the operands of this insn so that
1220 we can modify them safely, should we want to. */
1221 assert (opsfound
<= (int) ARRAY_SIZE (operands_backup
));
1222 for (i
= 0; i
< opsfound
; i
++)
1223 operands_backup
[i
] = the_ins
.operands
[i
];
1225 for (s
= opcode
->m_operands
, opP
= &operands_backup
[0];
1229 /* Warning: this switch is huge! */
1230 /* I've tried to organize the cases into this order:
1231 non-alpha first, then alpha by letter. Lower-case
1232 goes directly before uppercase counterpart. */
1233 /* Code with multiple case ...: gets sorted by the lowest
1234 case ... it belongs to. I hope this makes sense. */
1340 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1357 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1376 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1386 if (opP
->mode
!= IMMED
)
1388 else if (s
[1] == 'b'
1389 && ! isvar (&opP
->disp
)
1390 && (opP
->disp
.exp
.X_op
!= O_constant
1391 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1393 else if (s
[1] == 'B'
1394 && ! isvar (&opP
->disp
)
1395 && (opP
->disp
.exp
.X_op
!= O_constant
1396 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1398 else if (s
[1] == 'w'
1399 && ! isvar (&opP
->disp
)
1400 && (opP
->disp
.exp
.X_op
!= O_constant
1401 || ! isword (opP
->disp
.exp
.X_add_number
)))
1403 else if (s
[1] == 'W'
1404 && ! isvar (&opP
->disp
)
1405 && (opP
->disp
.exp
.X_op
!= O_constant
1406 || ! issword (opP
->disp
.exp
.X_add_number
)))
1412 if (opP
->mode
!= IMMED
)
1417 if (opP
->mode
== AREG
1418 || opP
->mode
== CONTROL
1419 || opP
->mode
== FPREG
1420 || opP
->mode
== IMMED
1421 || opP
->mode
== REGLST
1422 || (opP
->mode
!= ABSL
1424 || opP
->reg
== ZPC
)))
1429 if (opP
->mode
== CONTROL
1430 || opP
->mode
== FPREG
1431 || opP
->mode
== REGLST
1432 || opP
->mode
== IMMED
1433 || (opP
->mode
!= ABSL
1435 || opP
->reg
== ZPC
)))
1463 if (opP
->mode
== CONTROL
1464 || opP
->mode
== FPREG
1465 || opP
->mode
== REGLST
)
1470 if (opP
->mode
!= AINC
)
1475 if (opP
->mode
!= ADEC
)
1525 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1546 case '~': /* For now! (JF FOO is this right?) */
1568 if (opP
->mode
!= CONTROL
1569 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1574 if (opP
->mode
!= AREG
)
1579 if (opP
->mode
!= AINDR
)
1584 if (opP
->mode
!= AINDR
&& opP
->mode
!= AINC
&& opP
->mode
!= ADEC
1585 && (opP
->mode
!= DISP
1587 || opP
->reg
> ADDR7
))
1592 if (opP
->mode
!= ABSL
1594 && strncmp (instring
, "jbsr", 4) == 0))
1617 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1622 if (opP
->mode
!= DISP
1624 || opP
->reg
> ADDR7
)
1629 if (opP
->mode
!= DREG
)
1634 if (opP
->reg
!= ACC
)
1639 if (opP
->reg
!= ACC
&& opP
->reg
!= ACC1
1640 && opP
->reg
!= ACC2
&& opP
->reg
!= ACC3
)
1645 if (opP
->mode
!= FPREG
)
1650 if (opP
->reg
!= MACSR
)
1655 if (opP
->reg
!= ACCEXT01
&& opP
->reg
!= ACCEXT23
)
1660 if (opP
->reg
!= MASK
)
1665 if (opP
->mode
!= CONTROL
1672 if (opP
->mode
!= LSH
&& opP
->mode
!= RSH
)
1677 if (opP
->mode
!= CONTROL
1679 || opP
->reg
> last_movec_reg
)
1683 const enum m68k_register
*rp
;
1684 for (rp
= control_regs
; *rp
; rp
++)
1685 if (*rp
== opP
->reg
)
1693 if (opP
->mode
!= IMMED
)
1699 if (opP
->mode
== DREG
1700 || opP
->mode
== AREG
1701 || opP
->mode
== FPREG
)
1710 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1713 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1716 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1724 else if (opP
->mode
== CONTROL
)
1733 opP
->mask
= 1 << 24;
1736 opP
->mask
= 1 << 25;
1739 opP
->mask
= 1 << 26;
1748 else if (opP
->mode
!= REGLST
)
1750 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1752 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1757 if (opP
->mode
!= IMMED
)
1759 else if (opP
->disp
.exp
.X_op
!= O_constant
1760 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1762 else if (! m68k_quick
1763 && instring
[3] != 'q'
1764 && instring
[4] != 'q')
1769 if (opP
->mode
!= DREG
1770 && opP
->mode
!= IMMED
1771 && opP
->mode
!= ABSL
)
1776 if (opP
->mode
!= IMMED
)
1778 else if (opP
->disp
.exp
.X_op
!= O_constant
1779 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
1781 else if (! m68k_quick
1782 && (strncmp (instring
, "add", 3) == 0
1783 || strncmp (instring
, "sub", 3) == 0)
1784 && instring
[3] != 'q')
1789 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1794 if (opP
->mode
!= AINDR
1795 && (opP
->mode
!= BASE
1797 && opP
->reg
!= ZADDR0
)
1798 || opP
->disp
.exp
.X_op
!= O_absent
1799 || ((opP
->index
.reg
< DATA0
1800 || opP
->index
.reg
> DATA7
)
1801 && (opP
->index
.reg
< ADDR0
1802 || opP
->index
.reg
> ADDR7
))
1803 || opP
->index
.size
!= SIZE_UNSPEC
1804 || opP
->index
.scale
!= 1))
1809 if (opP
->mode
!= CONTROL
1810 || ! (opP
->reg
== FPI
1812 || opP
->reg
== FPC
))
1817 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1822 if (opP
->mode
!= IMMED
)
1824 else if (opP
->disp
.exp
.X_op
!= O_constant
1825 || TRUNC (opP
->disp
.exp
.X_add_number
) > 7)
1830 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1835 if (opP
->mode
!= IMMED
)
1837 else if (opP
->disp
.exp
.X_op
!= O_constant
1838 || (TRUNC (opP
->disp
.exp
.X_add_number
) != 0xffffffff
1839 && TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 6))
1843 /* JF these are out of order. We could put them
1844 in order if we were willing to put up with
1845 bunches of #ifdef m68851s in the code.
1847 Don't forget that you need these operands
1848 to use 68030 MMU instructions. */
1850 /* Memory addressing mode used by pflushr. */
1852 if (opP
->mode
== CONTROL
1853 || opP
->mode
== FPREG
1854 || opP
->mode
== DREG
1855 || opP
->mode
== AREG
1856 || opP
->mode
== REGLST
)
1858 /* We should accept immediate operands, but they
1859 supposedly have to be quad word, and we don't
1860 handle that. I would like to see what a Motorola
1861 assembler does before doing something here. */
1862 if (opP
->mode
== IMMED
)
1867 if (opP
->mode
!= CONTROL
1868 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1873 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1878 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1883 if (opP
->mode
!= CONTROL
1886 && opP
->reg
!= SCC
))
1891 if (opP
->mode
!= CONTROL
1897 if (opP
->mode
!= CONTROL
1900 && opP
->reg
!= CRP
))
1924 if (opP
->mode
!= CONTROL
1925 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1926 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1931 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1936 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1941 if (opP
->mode
!= CONTROL
1950 if (opP
->mode
!= ABSL
)
1955 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
1957 /* FIXME: kludge instead of fixing parser:
1958 upper/lower registers are *not* CONTROL
1959 registers, but ordinary ones. */
1960 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
1961 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
1968 if (!(opP
->mode
== AINDR
1969 || (opP
->mode
== DISP
1970 && !(opP
->reg
== PC
|| opP
->reg
== ZPC
))))
1975 if (!(opP
->mode
== AINDR
|| opP
->mode
== DISP
))
1987 /* Since we have found the correct instruction, copy
1988 in the modifications that we may have made. */
1990 for (i
= 0; i
< opsfound
; i
++)
1991 the_ins
.operands
[i
] = operands_backup
[i
];
1997 opcode
= opcode
->m_next
;
2002 && !(ok_arch
& current_architecture
))
2007 _("invalid instruction for this architecture; needs "),
2009 cp
= buf
+ strlen (buf
);
2013 strncpy (cp
, _("ColdFire ISA_A"),
2014 sizeof (buf
) - (cp
- buf
));
2016 strncpy (cp
, find_cf_chip (ok_arch
),
2017 sizeof (buf
) - (cp
- buf
));
2021 strncpy (cp
, _("ColdFire hardware divide"),
2022 sizeof (buf
) - (cp
- buf
));
2024 strncpy (cp
, find_cf_chip (ok_arch
),
2025 sizeof (buf
) - (cp
- buf
));
2029 strncpy (cp
, _("ColdFire ISA_A+"),
2030 sizeof (buf
) - (cp
- buf
));
2032 strncpy (cp
, find_cf_chip (ok_arch
),
2033 sizeof (buf
) - (cp
- buf
));
2037 strncpy (cp
, _("ColdFire ISA_B"),
2038 sizeof (buf
) - (cp
- buf
));
2040 strncpy (cp
, find_cf_chip (ok_arch
),
2041 sizeof (buf
) - (cp
- buf
));
2045 strncpy (cp
, _("ColdFire fpu"), sizeof (buf
) - (cp
- buf
));
2047 strncpy (cp
, find_cf_chip (ok_arch
),
2048 sizeof (buf
) - (cp
- buf
));
2052 strcpy (cp
, _("fpu (68040, 68060 or 68881/68882)"));
2055 strcpy (cp
, _("mmu (68030 or 68851)"));
2058 strcpy (cp
, _("68020 or higher"));
2061 strcpy (cp
, _("68000 or higher"));
2064 strcpy (cp
, _("68010 or higher"));
2068 int got_one
= 0, idx
;
2070 for (idx
= 0; idx
< n_archs
; idx
++)
2072 if ((archs
[idx
].arch
& ok_arch
)
2073 && ! archs
[idx
].alias
)
2077 strcpy (cp
, " or ");
2081 strcpy (cp
, archs
[idx
].name
);
2087 cp
= xmalloc (strlen (buf
) + 1);
2092 the_ins
.error
= _("operands mismatch");
2099 /* Now assemble it. */
2100 the_ins
.args
= opcode
->m_operands
;
2101 the_ins
.numargs
= opcode
->m_opnum
;
2102 the_ins
.numo
= opcode
->m_codenum
;
2103 the_ins
.opcode
[0] = getone (opcode
);
2104 the_ins
.opcode
[1] = gettwo (opcode
);
2106 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2108 /* This switch is a doozy.
2109 Watch the first step; its a big one! */
2142 tmpreg
= 0x3c; /* 7.4 */
2143 if (strchr ("bwl", s
[1]))
2144 nextword
= get_num (&opP
->disp
, 90);
2146 nextword
= get_num (&opP
->disp
, 0);
2147 if (isvar (&opP
->disp
))
2148 add_fix (s
[1], &opP
->disp
, 0, 0);
2152 if (!isbyte (nextword
))
2153 opP
->error
= _("operand out of range");
2158 if (!isword (nextword
))
2159 opP
->error
= _("operand out of range");
2164 if (!issword (nextword
))
2165 opP
->error
= _("operand out of range");
2170 addword (nextword
>> 16);
2197 /* We gotta put out some float. */
2198 if (op (&opP
->disp
) != O_big
)
2203 /* Can other cases happen here? */
2204 if (op (&opP
->disp
) != O_constant
)
2207 val
= (valueT
) offs (&opP
->disp
);
2211 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2212 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2216 offs (&opP
->disp
) = gencnt
;
2218 if (offs (&opP
->disp
) > 0)
2220 if (offs (&opP
->disp
) > baseo
)
2222 as_warn (_("Bignum too big for %c format; truncated"),
2224 offs (&opP
->disp
) = baseo
;
2226 baseo
-= offs (&opP
->disp
);
2229 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
2230 offs (&opP
->disp
)--;
2235 gen_to_words (words
, baseo
, (long) outro
);
2236 for (wordp
= words
; baseo
--; wordp
++)
2240 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2243 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2246 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2249 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2252 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2256 nextword
= get_num (&opP
->disp
, 90);
2258 /* Convert mode 5 addressing with a zero offset into
2259 mode 2 addressing to reduce the instruction size by a
2261 if (! isvar (&opP
->disp
)
2263 && (opP
->disp
.size
== SIZE_UNSPEC
)
2264 && (opP
->reg
>= ADDR0
)
2265 && (opP
->reg
<= ADDR7
))
2267 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2272 && ! isvar (&opP
->disp
)
2275 opP
->disp
.exp
.X_op
= O_symbol
;
2276 #ifndef BFD_ASSEMBLER
2277 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
2279 opP
->disp
.exp
.X_add_symbol
=
2280 section_symbol (absolute_section
);
2284 /* Force into index mode. Hope this works. */
2286 /* We do the first bit for 32-bit displacements, and the
2287 second bit for 16 bit ones. It is possible that we
2288 should make the default be WORD instead of LONG, but
2289 I think that'd break GCC, so we put up with a little
2290 inefficiency for the sake of working output. */
2292 if (!issword (nextword
)
2293 || (isvar (&opP
->disp
)
2294 && ((opP
->disp
.size
== SIZE_UNSPEC
2295 && flag_short_refs
== 0
2296 && cpu_of_arch (current_architecture
) >= m68020
2297 && ! arch_coldfire_p (current_architecture
))
2298 || opP
->disp
.size
== SIZE_LONG
)))
2300 if (cpu_of_arch (current_architecture
) < m68020
2301 || arch_coldfire_p (current_architecture
))
2303 _("displacement too large for this architecture; needs 68020 or higher");
2305 tmpreg
= 0x3B; /* 7.3 */
2307 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2308 if (isvar (&opP
->disp
))
2312 if (opP
->disp
.size
== SIZE_LONG
2314 /* If the displacement needs pic
2315 relocation it cannot be relaxed. */
2316 || opP
->disp
.pic_reloc
!= pic_none
2321 add_fix ('l', &opP
->disp
, 1, 2);
2325 add_frag (adds (&opP
->disp
),
2326 SEXT (offs (&opP
->disp
)),
2327 TAB (PCREL1632
, SZ_UNDEF
));
2334 add_fix ('l', &opP
->disp
, 0, 0);
2339 addword (nextword
>> 16);
2344 tmpreg
= 0x3A; /* 7.2 */
2346 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2348 if (isvar (&opP
->disp
))
2352 add_fix ('w', &opP
->disp
, 1, 0);
2355 add_fix ('w', &opP
->disp
, 0, 0);
2365 baseo
= get_num (&opP
->disp
, 90);
2366 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2367 outro
= get_num (&opP
->odisp
, 90);
2368 /* Figure out the `addressing mode'.
2369 Also turn on the BASE_DISABLE bit, if needed. */
2370 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2372 tmpreg
= 0x3b; /* 7.3 */
2373 if (opP
->reg
== ZPC
)
2376 else if (opP
->reg
== 0)
2379 tmpreg
= 0x30; /* 6.garbage */
2381 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2384 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2387 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2389 siz1
= opP
->disp
.size
;
2390 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2391 siz2
= opP
->odisp
.size
;
2395 /* Index register stuff. */
2396 if (opP
->index
.reg
!= 0
2397 && opP
->index
.reg
>= DATA
2398 && opP
->index
.reg
<= ADDR7
)
2400 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2402 if (opP
->index
.size
== SIZE_LONG
2403 || (opP
->index
.size
== SIZE_UNSPEC
2404 && m68k_index_width_default
== SIZE_LONG
))
2407 if ((opP
->index
.scale
!= 1
2408 && cpu_of_arch (current_architecture
) < m68020
)
2409 || (opP
->index
.scale
== 8
2410 && (arch_coldfire_p (current_architecture
)
2411 && !arch_coldfire_fpu (current_architecture
))))
2414 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2417 if (arch_coldfire_p (current_architecture
)
2418 && opP
->index
.size
== SIZE_WORD
)
2419 opP
->error
= _("invalid index size for coldfire");
2421 switch (opP
->index
.scale
)
2438 GET US OUT OF HERE! */
2440 /* Must be INDEX, with an index register. Address
2441 register cannot be ZERO-PC, and either :b was
2442 forced, or we know it will fit. For a 68000 or
2443 68010, force this mode anyways, because the
2444 larger modes aren't supported. */
2445 if (opP
->mode
== BASE
2446 && ((opP
->reg
>= ADDR0
2447 && opP
->reg
<= ADDR7
)
2450 if (siz1
== SIZE_BYTE
2451 || cpu_of_arch (current_architecture
) < m68020
2452 || arch_coldfire_p (current_architecture
)
2453 || (siz1
== SIZE_UNSPEC
2454 && ! isvar (&opP
->disp
)
2455 && issbyte (baseo
)))
2457 nextword
+= baseo
& 0xff;
2459 if (isvar (&opP
->disp
))
2461 /* Do a byte relocation. If it doesn't
2462 fit (possible on m68000) let the
2463 fixup processing complain later. */
2465 add_fix ('B', &opP
->disp
, 1, 1);
2467 add_fix ('B', &opP
->disp
, 0, 0);
2469 else if (siz1
!= SIZE_BYTE
)
2471 if (siz1
!= SIZE_UNSPEC
)
2472 as_warn (_("Forcing byte displacement"));
2473 if (! issbyte (baseo
))
2474 opP
->error
= _("byte displacement out of range");
2479 else if (siz1
== SIZE_UNSPEC
2481 && isvar (&opP
->disp
)
2482 && subs (&opP
->disp
) == NULL
2484 /* If the displacement needs pic
2485 relocation it cannot be relaxed. */
2486 && opP
->disp
.pic_reloc
== pic_none
2490 /* The code in md_convert_frag_1 needs to be
2491 able to adjust nextword. Call frag_grow
2492 to ensure that we have enough space in
2493 the frag obstack to make all the bytes
2496 nextword
+= baseo
& 0xff;
2498 add_frag (adds (&opP
->disp
),
2499 SEXT (offs (&opP
->disp
)),
2500 TAB (PCINDEX
, SZ_UNDEF
));
2508 nextword
|= 0x40; /* No index reg. */
2509 if (opP
->index
.reg
>= ZDATA0
2510 && opP
->index
.reg
<= ZDATA7
)
2511 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2512 else if (opP
->index
.reg
>= ZADDR0
2513 || opP
->index
.reg
<= ZADDR7
)
2514 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2517 /* It isn't simple. */
2519 if (cpu_of_arch (current_architecture
) < m68020
2520 || arch_coldfire_p (current_architecture
))
2522 _("invalid operand mode for this architecture; needs 68020 or higher");
2525 /* If the guy specified a width, we assume that it is
2526 wide enough. Maybe it isn't. If so, we lose. */
2530 if (isvar (&opP
->disp
)
2532 : ! issword (baseo
))
2537 else if (! isvar (&opP
->disp
) && baseo
== 0)
2546 as_warn (_(":b not permitted; defaulting to :w"));
2556 /* Figure out inner displacement stuff. */
2557 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2559 if (cpu_of_arch (current_architecture
) & cpu32
)
2560 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2564 if (isvar (&opP
->odisp
)
2566 : ! issword (outro
))
2571 else if (! isvar (&opP
->odisp
) && outro
== 0)
2580 as_warn (_(":b not permitted; defaulting to :w"));
2589 if (opP
->mode
== POST
2590 && (nextword
& 0x40) == 0)
2595 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2597 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2598 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2600 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2602 if (siz1
== SIZE_LONG
)
2603 addword (baseo
>> 16);
2604 if (siz1
!= SIZE_UNSPEC
)
2607 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2608 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2609 if (siz2
== SIZE_LONG
)
2610 addword (outro
>> 16);
2611 if (siz2
!= SIZE_UNSPEC
)
2617 nextword
= get_num (&opP
->disp
, 90);
2618 switch (opP
->disp
.size
)
2623 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2625 tmpreg
= 0x38; /* 7.0 */
2629 if (isvar (&opP
->disp
)
2630 && !subs (&opP
->disp
)
2631 && adds (&opP
->disp
)
2633 /* If the displacement needs pic relocation it
2634 cannot be relaxed. */
2635 && opP
->disp
.pic_reloc
== pic_none
2638 && !strchr ("~%&$?", s
[0]))
2640 tmpreg
= 0x3A; /* 7.2 */
2641 add_frag (adds (&opP
->disp
),
2642 SEXT (offs (&opP
->disp
)),
2643 TAB (ABSTOPCREL
, SZ_UNDEF
));
2646 /* Fall through into long. */
2648 if (isvar (&opP
->disp
))
2649 add_fix ('l', &opP
->disp
, 0, 0);
2651 tmpreg
= 0x39;/* 7.1 mode */
2652 addword (nextword
>> 16);
2657 as_bad (_("unsupported byte value; use a different suffix"));
2661 if (isvar (&opP
->disp
))
2662 add_fix ('w', &opP
->disp
, 0, 0);
2664 tmpreg
= 0x38;/* 7.0 mode */
2672 as_bad (_("unknown/incorrect operand"));
2676 /* If s[0] is '4', then this is for the mac instructions
2677 that can have a trailing_ampersand set. If so, set 0x100
2678 bit on tmpreg so install_gen_operand can check for it and
2679 set the appropriate bit (word2, bit 5). */
2682 if (opP
->trailing_ampersand
)
2685 install_gen_operand (s
[1], tmpreg
);
2691 { /* JF: I hate floating point! */
2706 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2707 if (isvar (&opP
->disp
))
2708 add_fix (s
[1], &opP
->disp
, 0, 0);
2711 case 'b': /* Danger: These do no check for
2712 certain types of overflow.
2714 if (!isbyte (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
=
2719 (opcode
->m_codenum
) * 2 + 1;
2722 if (!issbyte (tmpreg
))
2723 opP
->error
= _("out of range");
2724 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
2725 if (isvar (&opP
->disp
))
2726 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2729 if (!isword (tmpreg
))
2730 opP
->error
= _("out of range");
2731 insop (tmpreg
, opcode
);
2732 if (isvar (&opP
->disp
))
2733 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2736 if (!issword (tmpreg
))
2737 opP
->error
= _("out of range");
2738 insop (tmpreg
, opcode
);
2739 if (isvar (&opP
->disp
))
2740 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2743 /* Because of the way insop works, we put these two out
2745 insop (tmpreg
, opcode
);
2746 insop (tmpreg
>> 16, opcode
);
2747 if (isvar (&opP
->disp
))
2748 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2755 install_operand (s
[1], tmpreg
);
2766 install_operand (s
[1], opP
->reg
- ADDR
);
2770 tmpreg
= get_num (&opP
->disp
, 90);
2774 add_fix ('B', &opP
->disp
, 1, -1);
2777 add_fix ('w', &opP
->disp
, 1, 0);
2782 if (! HAVE_LONG_BRANCH (current_architecture
))
2783 as_warn (_("Can't use long branches on 68000/68010/5200"));
2784 the_ins
.opcode
[0] |= 0xff;
2785 add_fix ('l', &opP
->disp
, 1, 0);
2790 if (subs (&opP
->disp
)) /* We can't relax it. */
2794 /* If the displacement needs pic relocation it cannot be
2796 if (opP
->disp
.pic_reloc
!= pic_none
)
2799 /* This could either be a symbol, or an absolute
2800 address. If it's an absolute address, turn it into
2801 an absolute jump right here and keep it out of the
2803 if (adds (&opP
->disp
) == 0)
2805 if (the_ins
.opcode
[0] == 0x6000) /* jbra */
2806 the_ins
.opcode
[0] = 0x4EF9;
2807 else if (the_ins
.opcode
[0] == 0x6100) /* jbsr */
2808 the_ins
.opcode
[0] = 0x4EB9;
2811 the_ins
.opcode
[0] ^= 0x0100;
2812 the_ins
.opcode
[0] |= 0x0006;
2815 add_fix ('l', &opP
->disp
, 0, 0);
2821 /* Now we know it's going into the relaxer. Now figure
2822 out which mode. We try in this order of preference:
2823 long branch, absolute jump, byte/word branches only. */
2824 if (HAVE_LONG_BRANCH (current_architecture
))
2825 add_frag (adds (&opP
->disp
),
2826 SEXT (offs (&opP
->disp
)),
2827 TAB (BRANCHBWL
, SZ_UNDEF
));
2828 else if (! flag_keep_pcrel
)
2830 if ((the_ins
.opcode
[0] == 0x6000)
2831 || (the_ins
.opcode
[0] == 0x6100))
2832 add_frag (adds (&opP
->disp
),
2833 SEXT (offs (&opP
->disp
)),
2834 TAB (BRABSJUNC
, SZ_UNDEF
));
2836 add_frag (adds (&opP
->disp
),
2837 SEXT (offs (&opP
->disp
)),
2838 TAB (BRABSJCOND
, SZ_UNDEF
));
2841 add_frag (adds (&opP
->disp
),
2842 SEXT (offs (&opP
->disp
)),
2843 TAB (BRANCHBW
, SZ_UNDEF
));
2846 if (isvar (&opP
->disp
))
2848 /* Check for DBcc instructions. We can relax them,
2849 but only if we have long branches and/or absolute
2851 if (((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2852 && (HAVE_LONG_BRANCH (current_architecture
)
2853 || (! flag_keep_pcrel
)))
2855 if (HAVE_LONG_BRANCH (current_architecture
))
2856 add_frag (adds (&opP
->disp
),
2857 SEXT (offs (&opP
->disp
)),
2858 TAB (DBCCLBR
, SZ_UNDEF
));
2860 add_frag (adds (&opP
->disp
),
2861 SEXT (offs (&opP
->disp
)),
2862 TAB (DBCCABSJ
, SZ_UNDEF
));
2865 add_fix ('w', &opP
->disp
, 1, 0);
2869 case 'C': /* Fixed size LONG coproc branches. */
2870 add_fix ('l', &opP
->disp
, 1, 0);
2874 case 'c': /* Var size Coprocesssor branches. */
2875 if (subs (&opP
->disp
) || (adds (&opP
->disp
) == 0))
2877 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2878 add_fix ('l', &opP
->disp
, 1, 0);
2883 add_frag (adds (&opP
->disp
),
2884 SEXT (offs (&opP
->disp
)),
2885 TAB (FBRANCH
, SZ_UNDEF
));
2892 case 'C': /* Ignore it. */
2895 case 'd': /* JF this is a kludge. */
2896 install_operand ('s', opP
->reg
- ADDR
);
2897 tmpreg
= get_num (&opP
->disp
, 90);
2898 if (!issword (tmpreg
))
2900 as_warn (_("Expression out of range, using 0"));
2907 install_operand (s
[1], opP
->reg
- DATA
);
2910 case 'e': /* EMAC ACCx, reg/reg. */
2911 install_operand (s
[1], opP
->reg
- ACC
);
2914 case 'E': /* Ignore it. */
2918 install_operand (s
[1], opP
->reg
- FP0
);
2921 case 'g': /* EMAC ACCEXTx. */
2922 install_operand (s
[1], opP
->reg
- ACCEXT01
);
2925 case 'G': /* Ignore it. */
2930 tmpreg
= opP
->reg
- COP0
;
2931 install_operand (s
[1], tmpreg
);
2934 case 'i': /* MAC/EMAC scale factor. */
2935 install_operand (s
[1], opP
->mode
== LSH
? 0x1 : 0x3);
2938 case 'J': /* JF foo. */
3068 install_operand (s
[1], tmpreg
);
3072 tmpreg
= get_num (&opP
->disp
, 55);
3073 install_operand (s
[1], tmpreg
& 0x7f);
3080 if (tmpreg
& 0x7FF0000)
3081 as_bad (_("Floating point register in register list"));
3082 insop (reverse_16_bits (tmpreg
), opcode
);
3086 if (tmpreg
& 0x700FFFF)
3087 as_bad (_("Wrong register in floating-point reglist"));
3088 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
3096 if (tmpreg
& 0x7FF0000)
3097 as_bad (_("Floating point register in register list"));
3098 insop (tmpreg
, opcode
);
3100 else if (s
[1] == '8')
3102 if (tmpreg
& 0x0FFFFFF)
3103 as_bad (_("incorrect register in reglist"));
3104 install_operand (s
[1], tmpreg
>> 24);
3108 if (tmpreg
& 0x700FFFF)
3109 as_bad (_("wrong register in floating-point reglist"));
3111 install_operand (s
[1], tmpreg
>> 16);
3116 install_operand (s
[1], get_num (&opP
->disp
, 60));
3120 tmpreg
= ((opP
->mode
== DREG
)
3121 ? 0x20 + (int) (opP
->reg
- DATA
)
3122 : (get_num (&opP
->disp
, 40) & 0x1F));
3123 install_operand (s
[1], tmpreg
);
3127 tmpreg
= get_num (&opP
->disp
, 10);
3130 install_operand (s
[1], tmpreg
);
3134 /* This depends on the fact that ADDR registers are eight
3135 more than their corresponding DATA regs, so the result
3136 will have the ADDR_REG bit set. */
3137 install_operand (s
[1], opP
->reg
- DATA
);
3141 if (opP
->mode
== AINDR
)
3142 install_operand (s
[1], opP
->reg
- DATA
);
3144 install_operand (s
[1], opP
->index
.reg
- DATA
);
3148 if (opP
->reg
== FPI
)
3150 else if (opP
->reg
== FPS
)
3152 else if (opP
->reg
== FPC
)
3156 install_operand (s
[1], tmpreg
);
3159 case 'S': /* Ignore it. */
3163 install_operand (s
[1], get_num (&opP
->disp
, 30));
3166 case 'U': /* Ignore it. */
3185 as_fatal (_("failed sanity check"));
3186 } /* switch on cache token. */
3187 install_operand (s
[1], tmpreg
);
3190 /* JF: These are out of order, I fear. */
3203 install_operand (s
[1], tmpreg
);
3229 install_operand (s
[1], tmpreg
);
3233 if (opP
->reg
== VAL
)
3252 install_operand (s
[1], tmpreg
);
3266 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3277 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3283 install_operand (s
[1], tmpreg
);
3286 know (opP
->reg
== PSR
);
3289 know (opP
->reg
== PCSR
);
3304 install_operand (s
[1], tmpreg
);
3307 tmpreg
= get_num (&opP
->disp
, 20);
3308 install_operand (s
[1], tmpreg
);
3310 case '_': /* used only for move16 absolute 32-bit address. */
3311 if (isvar (&opP
->disp
))
3312 add_fix ('l', &opP
->disp
, 0, 0);
3313 tmpreg
= get_num (&opP
->disp
, 90);
3314 addword (tmpreg
>> 16);
3315 addword (tmpreg
& 0xFFFF);
3318 install_operand (s
[1], opP
->reg
- DATA0L
);
3319 opP
->reg
-= (DATA0L
);
3320 opP
->reg
&= 0x0F; /* remove upper/lower bit. */
3323 tmpreg
= get_num (&opP
->disp
, 80);
3326 install_operand (s
[1], tmpreg
);
3333 /* By the time whe get here (FINALLY) the_ins contains the complete
3334 instruction, ready to be emitted. . . */
3338 reverse_16_bits (int in
)
3343 static int mask
[16] =
3345 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3346 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3348 for (n
= 0; n
< 16; n
++)
3351 out
|= mask
[15 - n
];
3354 } /* reverse_16_bits() */
3357 reverse_8_bits (int in
)
3362 static int mask
[8] =
3364 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3367 for (n
= 0; n
< 8; n
++)
3373 } /* reverse_8_bits() */
3375 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3376 (that value is chosen in the frag_var call in md_assemble). TYPE
3377 is the subtype of the frag to be generated; its primary type is
3378 rs_machine_dependent.
3380 The TYPE parameter is also used by md_convert_frag_1 and
3381 md_estimate_size_before_relax. The appropriate type of fixup will
3382 be emitted by md_convert_frag_1.
3384 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3386 install_operand (int mode
, int val
)
3391 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge. */
3394 the_ins
.opcode
[0] |= val
<< 9;
3397 the_ins
.opcode
[1] |= val
<< 12;
3400 the_ins
.opcode
[1] |= val
<< 6;
3403 the_ins
.opcode
[1] |= val
;
3406 the_ins
.opcode
[2] |= val
<< 12;
3409 the_ins
.opcode
[2] |= val
<< 6;
3412 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3413 three words long! */
3415 the_ins
.opcode
[2] |= val
;
3418 the_ins
.opcode
[1] |= val
<< 7;
3421 the_ins
.opcode
[1] |= val
<< 10;
3425 the_ins
.opcode
[1] |= val
<< 5;
3430 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3433 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3436 the_ins
.opcode
[0] |= val
= 0xff;
3439 the_ins
.opcode
[0] |= val
<< 9;
3442 the_ins
.opcode
[1] |= val
;
3445 the_ins
.opcode
[1] |= val
;
3446 the_ins
.numo
++; /* What a hack. */
3449 the_ins
.opcode
[1] |= val
<< 4;
3457 the_ins
.opcode
[0] |= (val
<< 6);
3460 the_ins
.opcode
[1] = (val
>> 16);
3461 the_ins
.opcode
[2] = val
& 0xffff;
3464 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3465 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3466 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3468 case 'n': /* MAC/EMAC Rx on !load. */
3469 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3470 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3471 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3473 case 'o': /* MAC/EMAC Rx on load. */
3474 the_ins
.opcode
[1] |= val
<< 12;
3475 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3477 case 'M': /* MAC/EMAC Ry on !load. */
3478 the_ins
.opcode
[0] |= (val
& 0xF);
3479 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3481 case 'N': /* MAC/EMAC Ry on load. */
3482 the_ins
.opcode
[1] |= (val
& 0xF);
3483 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3486 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3489 the_ins
.opcode
[0] |= ((val
& 0x3) << 9);
3492 the_ins
.opcode
[0] |= ((val
& 0x3) << 0);
3494 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3495 the_ins
.opcode
[0] |= ((~val
& 0x1) << 7);
3496 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3498 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3499 the_ins
.opcode
[0] |= ((val
& 0x1) << 7);
3500 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3503 the_ins
.opcode
[1] |= ((val
& 0x3) << 9);
3506 the_ins
.opcode
[0] |= (val
& 0x1) <<10;
3510 as_fatal (_("failed sanity check."));
3515 install_gen_operand (int mode
, int val
)
3519 case '/': /* Special for mask loads for mac/msac insns with
3520 possible mask; trailing_ampersend set in bit 8. */
3521 the_ins
.opcode
[0] |= (val
& 0x3f);
3522 the_ins
.opcode
[1] |= (((val
& 0x100) >> 8) << 5);
3525 the_ins
.opcode
[0] |= val
;
3528 /* This is a kludge!!! */
3529 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3538 the_ins
.opcode
[0] |= val
;
3540 /* more stuff goes here. */
3542 as_fatal (_("failed sanity check."));
3546 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3547 then deal with the bitfield hack. */
3550 crack_operand (char *str
, struct m68k_op
*opP
)
3552 register int parens
;
3554 register char *beg_str
;
3562 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3568 else if (*str
== ')')
3572 opP
->error
= _("Extra )");
3578 if (flag_mri
&& *str
== '\'')
3579 inquote
= ! inquote
;
3581 if (!*str
&& parens
)
3583 opP
->error
= _("Missing )");
3588 if (m68k_ip_op (beg_str
, opP
) != 0)
3595 c
= *++str
; /* JF bitfield hack. */
3600 as_bad (_("Missing operand"));
3603 /* Detect MRI REG symbols and convert them to REGLSTs. */
3604 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3607 opP
->mask
= ~(int)opP
->reg
;
3614 /* This is the guts of the machine-dependent assembler. STR points to a
3615 machine dependent instruction. This function is supposed to emit
3616 the frags/bytes it assembles to.
3620 insert_reg (const char *regname
, int regnum
)
3625 #ifdef REGISTER_PREFIX
3626 if (!flag_reg_prefix_optional
)
3628 buf
[0] = REGISTER_PREFIX
;
3629 strcpy (buf
+ 1, regname
);
3634 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3635 &zero_address_frag
));
3637 for (i
= 0; regname
[i
]; i
++)
3638 buf
[i
] = TOUPPER (regname
[i
]);
3641 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3642 &zero_address_frag
));
3651 static const struct init_entry init_table
[] =
3711 { "accext01", ACCEXT01
},
3712 { "accext23", ACCEXT23
},
3716 /* Control registers. */
3717 { "sfc", SFC
}, /* Source Function Code. */
3719 { "dfc", DFC
}, /* Destination Function Code. */
3721 { "cacr", CACR
}, /* Cache Control Register. */
3722 { "caar", CAAR
}, /* Cache Address Register. */
3724 { "usp", USP
}, /* User Stack Pointer. */
3725 { "vbr", VBR
}, /* Vector Base Register. */
3726 { "msp", MSP
}, /* Master Stack Pointer. */
3727 { "isp", ISP
}, /* Interrupt Stack Pointer. */
3729 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0. */
3730 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1. */
3731 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0. */
3732 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1. */
3734 /* 68ec040 versions of same */
3735 { "iacr0", ITT0
}, /* Instruction Access Control Register 0. */
3736 { "iacr1", ITT1
}, /* Instruction Access Control Register 0. */
3737 { "dacr0", DTT0
}, /* Data Access Control Register 0. */
3738 { "dacr1", DTT1
}, /* Data Access Control Register 0. */
3740 /* mcf5200 versions of same. The ColdFire programmer's reference
3741 manual indicated that the order is 2,3,0,1, but Ken Rose
3742 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3743 { "acr0", ACR0
}, /* Access Control Unit 0. */
3744 { "acr1", ACR1
}, /* Access Control Unit 1. */
3745 { "acr2", ACR2
}, /* Access Control Unit 2. */
3746 { "acr3", ACR3
}, /* Access Control Unit 3. */
3748 { "tc", TC
}, /* MMU Translation Control Register. */
3751 { "mmusr", MMUSR
}, /* MMU Status Register. */
3752 { "srp", SRP
}, /* User Root Pointer. */
3753 { "urp", URP
}, /* Supervisor Root Pointer. */
3758 { "rombar", ROMBAR
}, /* ROM Base Address Register. */
3759 { "rambar0", RAMBAR0
}, /* ROM Base Address Register. */
3760 { "rambar1", RAMBAR1
}, /* ROM Base Address Register. */
3761 { "mbar", MBAR
}, /* Module Base Address Register. */
3763 { "mbar0", MBAR0
}, /* mcfv4e registers. */
3764 { "mbar1", MBAR1
}, /* mcfv4e registers. */
3765 { "rombar0", ROMBAR
}, /* mcfv4e registers. */
3766 { "rombar1", ROMBAR1
}, /* mcfv4e registers. */
3767 { "mpcr", MPCR
}, /* mcfv4e registers. */
3768 { "edrambar", EDRAMBAR
}, /* mcfv4e registers. */
3769 { "secmbar", SECMBAR
}, /* mcfv4e registers. */
3770 { "asid", TC
}, /* mcfv4e registers. */
3771 { "mmubar", BUSCR
}, /* mcfv4e registers. */
3772 { "pcr1u0", PCR1U0
}, /* mcfv4e registers. */
3773 { "pcr1l0", PCR1L0
}, /* mcfv4e registers. */
3774 { "pcr2u0", PCR2U0
}, /* mcfv4e registers. */
3775 { "pcr2l0", PCR2L0
}, /* mcfv4e registers. */
3776 { "pcr3u0", PCR3U0
}, /* mcfv4e registers. */
3777 { "pcr3l0", PCR3L0
}, /* mcfv4e registers. */
3778 { "pcr1u1", PCR1U1
}, /* mcfv4e registers. */
3779 { "pcr1l1", PCR1L1
}, /* mcfv4e registers. */
3780 { "pcr2u1", PCR2U1
}, /* mcfv4e registers. */
3781 { "pcr2l1", PCR2L1
}, /* mcfv4e registers. */
3782 { "pcr3u1", PCR3U1
}, /* mcfv4e registers. */
3783 { "pcr3l1", PCR3L1
}, /* mcfv4e registers. */
3785 { "flashbar", FLASHBAR
}, /* mcf528x registers. */
3786 { "rambar", RAMBAR
}, /* mcf528x registers. */
3788 { "mbar2", MBAR2
}, /* mcf5249 registers. */
3789 /* End of control registers. */
3823 /* 68ec030 versions of same. */
3826 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3829 /* Suppressed data and address registers. */
3847 /* Upper and lower data and address registers, used by macw and msacw. */
3888 init_regtable (void)
3891 for (i
= 0; init_table
[i
].name
; i
++)
3892 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3895 static int no_68851
, no_68881
;
3898 /* a.out machine type. Default to 68020. */
3899 int m68k_aout_machtype
= 2;
3903 md_assemble (char *str
)
3910 int shorts_this_frag
;
3913 /* In MRI mode, the instruction and operands are separated by a
3914 space. Anything following the operands is a comment. The label
3915 has already been removed. */
3923 for (s
= str
; *s
!= '\0'; s
++)
3925 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3943 inquote
= ! inquote
;
3948 memset (&the_ins
, '\0', sizeof (the_ins
));
3953 for (n
= 0; n
< the_ins
.numargs
; n
++)
3954 if (the_ins
.operands
[n
].error
)
3956 er
= the_ins
.operands
[n
].error
;
3962 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
3966 /* If there is a current label, record that it marks an instruction. */
3967 if (current_label
!= NULL
)
3969 current_label
->text
= 1;
3970 current_label
= NULL
;
3974 /* Tie dwarf2 debug info to the address at the start of the insn. */
3975 dwarf2_emit_insn (0);
3978 if (the_ins
.nfrag
== 0)
3980 /* No frag hacking involved; just put it out. */
3981 toP
= frag_more (2 * the_ins
.numo
);
3982 fromP
= &the_ins
.opcode
[0];
3983 for (m
= the_ins
.numo
; m
; --m
)
3985 md_number_to_chars (toP
, (long) (*fromP
), 2);
3989 /* Put out symbol-dependent info. */
3990 for (m
= 0; m
< the_ins
.nrel
; m
++)
3992 switch (the_ins
.reloc
[m
].wid
)
4011 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4012 the_ins
.reloc
[m
].wid
);
4015 fixP
= fix_new_exp (frag_now
,
4016 ((toP
- frag_now
->fr_literal
)
4017 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4019 &the_ins
.reloc
[m
].exp
,
4020 the_ins
.reloc
[m
].pcrel
,
4021 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
4022 the_ins
.reloc
[m
].pic_reloc
));
4023 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4024 if (the_ins
.reloc
[m
].wid
== 'B')
4025 fixP
->fx_signed
= 1;
4030 /* There's some frag hacking. */
4032 /* Calculate the max frag size. */
4035 wid
= 2 * the_ins
.fragb
[0].fragoff
;
4036 for (n
= 1; n
< the_ins
.nfrag
; n
++)
4037 wid
+= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4038 /* frag_var part. */
4040 /* Make sure the whole insn fits in one chunk, in particular that
4041 the var part is attached, as we access one byte before the
4042 variable frag for byte branches. */
4046 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
4051 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
4053 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4054 toP
= frag_more (wid
);
4056 shorts_this_frag
= 0;
4057 for (m
= wid
/ 2; m
; --m
)
4059 md_number_to_chars (toP
, (long) (*fromP
), 2);
4064 for (m
= 0; m
< the_ins
.nrel
; m
++)
4066 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
4068 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
4071 wid
= the_ins
.reloc
[m
].wid
;
4074 the_ins
.reloc
[m
].wid
= 0;
4075 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4077 fixP
= fix_new_exp (frag_now
,
4078 ((toP
- frag_now
->fr_literal
)
4079 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4081 &the_ins
.reloc
[m
].exp
,
4082 the_ins
.reloc
[m
].pcrel
,
4083 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4084 the_ins
.reloc
[m
].pic_reloc
));
4085 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4087 (void) frag_var (rs_machine_dependent
, 10, 0,
4088 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
4089 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
4091 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4092 shorts_this_frag
= 0;
4095 toP
= frag_more (n
* 2);
4098 md_number_to_chars (toP
, (long) (*fromP
), 2);
4104 for (m
= 0; m
< the_ins
.nrel
; m
++)
4108 wid
= the_ins
.reloc
[m
].wid
;
4111 the_ins
.reloc
[m
].wid
= 0;
4112 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4114 fixP
= fix_new_exp (frag_now
,
4115 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
4116 - shorts_this_frag
* 2),
4118 &the_ins
.reloc
[m
].exp
,
4119 the_ins
.reloc
[m
].pcrel
,
4120 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4121 the_ins
.reloc
[m
].pic_reloc
));
4122 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4126 /* Comparison function used by qsort to rank the opcode entries by name. */
4129 m68k_compare_opcode (const void * v1
, const void * v2
)
4131 struct m68k_opcode
* op1
, * op2
;
4137 op1
= *(struct m68k_opcode
**) v1
;
4138 op2
= *(struct m68k_opcode
**) v2
;
4140 /* Compare the two names. If different, return the comparison.
4141 If the same, return the order they are in the opcode table. */
4142 ret
= strcmp (op1
->name
, op2
->name
);
4153 const struct m68k_opcode
*ins
;
4154 struct m68k_incant
*hack
, *slak
;
4155 const char *retval
= 0; /* Empty string, or error msg text. */
4158 /* Set up hash tables with 68000 instructions.
4159 similar to what the vax assembler does. */
4160 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4161 a copy of it at runtime, adding in the information we want but isn't
4162 there. I think it'd be better to have an awk script hack the table
4163 at compile time. Or even just xstr the table and use it as-is. But
4164 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4169 flag_reg_prefix_optional
= 1;
4171 if (! m68k_rel32_from_cmdline
)
4175 /* First sort the opcode table into alphabetical order to seperate
4176 the order that the assembler wants to see the opcodes from the
4177 order that the disassembler wants to see them. */
4178 m68k_sorted_opcodes
= xmalloc (m68k_numopcodes
* sizeof (* m68k_sorted_opcodes
));
4179 if (!m68k_sorted_opcodes
)
4180 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4181 m68k_numopcodes
* ((int) sizeof (* m68k_sorted_opcodes
)));
4183 for (i
= m68k_numopcodes
; i
--;)
4184 m68k_sorted_opcodes
[i
] = m68k_opcodes
+ i
;
4186 qsort (m68k_sorted_opcodes
, m68k_numopcodes
,
4187 sizeof (m68k_sorted_opcodes
[0]), m68k_compare_opcode
);
4189 op_hash
= hash_new ();
4191 obstack_begin (&robyn
, 4000);
4192 for (i
= 0; i
< m68k_numopcodes
; i
++)
4194 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4197 ins
= m68k_sorted_opcodes
[i
];
4199 /* We *could* ignore insns that don't match our
4200 arch here by just leaving them out of the hash. */
4201 slak
->m_operands
= ins
->args
;
4202 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
4203 slak
->m_arch
= ins
->arch
;
4204 slak
->m_opcode
= ins
->opcode
;
4205 /* This is kludgey. */
4206 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
4207 if (i
+ 1 != m68k_numopcodes
4208 && !strcmp (ins
->name
, m68k_sorted_opcodes
[i
+ 1]->name
))
4210 slak
->m_next
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4215 slak
= slak
->m_next
;
4219 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
4221 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
4224 for (i
= 0; i
< m68k_numaliases
; i
++)
4226 const char *name
= m68k_opcode_aliases
[i
].primary
;
4227 const char *alias
= m68k_opcode_aliases
[i
].alias
;
4228 PTR val
= hash_find (op_hash
, name
);
4231 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4232 retval
= hash_insert (op_hash
, alias
, val
);
4234 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4237 /* In MRI mode, all unsized branches are variable sized. Normally,
4238 they are word sized. */
4241 static struct m68k_opcode_alias mri_aliases
[] =
4262 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
4265 const char *name
= mri_aliases
[i
].primary
;
4266 const char *alias
= mri_aliases
[i
].alias
;
4267 PTR val
= hash_find (op_hash
, name
);
4270 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4271 retval
= hash_jam (op_hash
, alias
, val
);
4273 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4277 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
4279 notend_table
[i
] = 0;
4280 alt_notend_table
[i
] = 0;
4283 notend_table
[','] = 1;
4284 notend_table
['{'] = 1;
4285 notend_table
['}'] = 1;
4286 alt_notend_table
['a'] = 1;
4287 alt_notend_table
['A'] = 1;
4288 alt_notend_table
['d'] = 1;
4289 alt_notend_table
['D'] = 1;
4290 alt_notend_table
['#'] = 1;
4291 alt_notend_table
['&'] = 1;
4292 alt_notend_table
['f'] = 1;
4293 alt_notend_table
['F'] = 1;
4294 #ifdef REGISTER_PREFIX
4295 alt_notend_table
[REGISTER_PREFIX
] = 1;
4298 /* We need to put '(' in alt_notend_table to handle
4299 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4300 alt_notend_table
['('] = 1;
4302 /* We need to put '@' in alt_notend_table to handle
4303 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4304 alt_notend_table
['@'] = 1;
4306 /* We need to put digits in alt_notend_table to handle
4307 bfextu %d0{24:1},%d0 */
4308 alt_notend_table
['0'] = 1;
4309 alt_notend_table
['1'] = 1;
4310 alt_notend_table
['2'] = 1;
4311 alt_notend_table
['3'] = 1;
4312 alt_notend_table
['4'] = 1;
4313 alt_notend_table
['5'] = 1;
4314 alt_notend_table
['6'] = 1;
4315 alt_notend_table
['7'] = 1;
4316 alt_notend_table
['8'] = 1;
4317 alt_notend_table
['9'] = 1;
4319 #ifndef MIT_SYNTAX_ONLY
4320 /* Insert pseudo ops, these have to go into the opcode table since
4321 gas expects pseudo ops to start with a dot. */
4325 while (mote_pseudo_table
[n
].poc_name
)
4327 hack
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4328 hash_insert (op_hash
,
4329 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
4330 hack
->m_operands
= 0;
4340 record_alignment (text_section
, 2);
4341 record_alignment (data_section
, 2);
4342 record_alignment (bss_section
, 2);
4347 select_control_regs (void)
4349 /* Note which set of "movec" control registers is available. */
4350 switch (current_chip
)
4354 as_warn (_("architecture not yet selected: defaulting to 68020"));
4355 control_regs
= m68020_control_regs
;
4359 control_regs
= m68000_control_regs
;
4362 control_regs
= m68010_control_regs
;
4366 control_regs
= m68020_control_regs
;
4369 control_regs
= m68040_control_regs
;
4372 control_regs
= m68060_control_regs
;
4375 control_regs
= cpu32_control_regs
;
4381 control_regs
= mcf_control_regs
;
4384 control_regs
= mcf5249_control_regs
;
4388 control_regs
= mcf528x_control_regs
;
4392 control_regs
= mcfv4e_control_regs
;
4400 m68k_init_after_args (void)
4402 if (cpu_of_arch (current_architecture
) == 0)
4405 const char *default_cpu
= TARGET_CPU
;
4407 if (*default_cpu
== 'm')
4409 for (i
= 0; i
< n_archs
; i
++)
4410 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
4414 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU
);
4415 current_architecture
|= m68020
;
4418 current_architecture
|= archs
[i
].arch
;
4420 /* Permit m68881 specification with all cpus; those that can't work
4421 with a coprocessor could be doing emulation. */
4422 if (current_architecture
& m68851
)
4424 if (current_architecture
& m68040
)
4425 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4427 /* What other incompatibilities could we check for? */
4429 /* Toss in some default assumptions about coprocessors. */
4431 && (cpu_of_arch (current_architecture
)
4432 /* Can CPU32 have a 68881 coprocessor?? */
4433 & (m68020
| m68030
| cpu32
)))
4434 current_architecture
|= m68881
;
4437 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
4438 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
4439 current_architecture
|= m68851
;
4441 if (no_68881
&& (current_architecture
& m68881
))
4442 as_bad (_("options for 68881 and no-68881 both given"));
4444 if (no_68851
&& (current_architecture
& m68851
))
4445 as_bad (_("options for 68851 and no-68851 both given"));
4448 /* Work out the magic number. This isn't very general. */
4449 if (current_architecture
& m68000
)
4450 m68k_aout_machtype
= 0;
4451 else if (current_architecture
& m68010
)
4452 m68k_aout_machtype
= 1;
4453 else if (current_architecture
& m68020
)
4454 m68k_aout_machtype
= 2;
4456 m68k_aout_machtype
= 2;
4459 /* Note which set of "movec" control registers is available. */
4460 select_control_regs ();
4462 if (cpu_of_arch (current_architecture
) < m68020
4463 || arch_coldfire_p (current_architecture
))
4464 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
4467 /* This is called when a label is defined. */
4470 m68k_frob_label (symbolS
*sym
)
4472 struct label_line
*n
;
4474 n
= (struct label_line
*) xmalloc (sizeof *n
);
4477 as_where (&n
->file
, &n
->line
);
4483 /* This is called when a value that is not an instruction is emitted. */
4486 m68k_flush_pending_output (void)
4488 current_label
= NULL
;
4491 /* This is called at the end of the assembly, when the final value of
4492 the label is known. We warn if this is a text symbol aligned at an
4496 m68k_frob_symbol (symbolS
*sym
)
4498 if (S_GET_SEGMENT (sym
) == reg_section
4499 && (int) S_GET_VALUE (sym
) < 0)
4501 S_SET_SEGMENT (sym
, absolute_section
);
4502 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4504 else if ((S_GET_VALUE (sym
) & 1) != 0)
4506 struct label_line
*l
;
4508 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4510 if (l
->label
== sym
)
4513 as_warn_where (l
->file
, l
->line
,
4514 _("text label `%s' aligned to odd boundary"),
4522 /* This is called if we go in or out of MRI mode because of the .mri
4526 m68k_mri_mode_change (int on
)
4530 if (! flag_reg_prefix_optional
)
4532 flag_reg_prefix_optional
= 1;
4533 #ifdef REGISTER_PREFIX
4538 if (! m68k_rel32_from_cmdline
)
4543 if (! reg_prefix_optional_seen
)
4545 #ifdef REGISTER_PREFIX_OPTIONAL
4546 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4548 flag_reg_prefix_optional
= 0;
4550 #ifdef REGISTER_PREFIX
4555 if (! m68k_rel32_from_cmdline
)
4560 /* Equal to MAX_PRECISION in atof-ieee.c. */
4561 #define MAX_LITTLENUMS 6
4563 /* Turn a string in input_line_pointer into a floating point constant
4564 of type TYPE, and store the appropriate bytes in *LITP. The number
4565 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4566 returned, or NULL on OK. */
4569 md_atof (int type
, char *litP
, int *sizeP
)
4572 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
4573 LITTLENUM_TYPE
*wordP
;
4604 return _("Bad call to MD_ATOF()");
4606 t
= atof_ieee (input_line_pointer
, type
, words
);
4608 input_line_pointer
= t
;
4610 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
4611 for (wordP
= words
; prec
--;)
4613 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
4614 litP
+= sizeof (LITTLENUM_TYPE
);
4620 md_number_to_chars (char *buf
, valueT val
, int n
)
4622 number_to_chars_bigendian (buf
, val
, n
);
4626 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
4628 offsetT val
= *valP
;
4629 addressT upper_limit
;
4630 offsetT lower_limit
;
4632 /* This is unnecessary but it convinces the native rs6000 compiler
4633 to generate the code we want. */
4634 char *buf
= fixP
->fx_frag
->fr_literal
;
4635 buf
+= fixP
->fx_where
;
4636 /* End ibm compiler workaround. */
4640 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4646 memset (buf
, 0, fixP
->fx_size
);
4647 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4649 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4650 && !S_IS_DEFINED (fixP
->fx_addsy
)
4651 && !S_IS_WEAK (fixP
->fx_addsy
))
4652 S_SET_WEAK (fixP
->fx_addsy
);
4657 #ifdef BFD_ASSEMBLER
4658 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4659 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4663 switch (fixP
->fx_size
)
4665 /* The cast to offsetT below are necessary to make code
4666 correct for machines where ints are smaller than offsetT. */
4670 lower_limit
= - (offsetT
) 0x80;
4673 *buf
++ = (val
>> 8);
4675 upper_limit
= 0x7fff;
4676 lower_limit
= - (offsetT
) 0x8000;
4679 *buf
++ = (val
>> 24);
4680 *buf
++ = (val
>> 16);
4681 *buf
++ = (val
>> 8);
4683 upper_limit
= 0x7fffffff;
4684 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* Avoid constant overflow. */
4687 BAD_CASE (fixP
->fx_size
);
4690 /* Fix up a negative reloc. */
4691 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4693 fixP
->fx_addsy
= fixP
->fx_subsy
;
4694 fixP
->fx_subsy
= NULL
;
4698 /* For non-pc-relative values, it's conceivable we might get something
4699 like "0xff" for a byte field. So extend the upper part of the range
4700 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4701 so that we can do any range checking at all. */
4702 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4703 upper_limit
= upper_limit
* 2 + 1;
4705 if ((addressT
) val
> upper_limit
4706 && (val
> 0 || val
< lower_limit
))
4707 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("value out of range"));
4709 /* A one byte PC-relative reloc means a short branch. We can't use
4710 a short branch with a value of 0 or -1, because those indicate
4711 different opcodes (branches with longer offsets). fixup_segment
4712 in write.c may have clobbered fx_pcrel, so we need to examine the
4715 #ifdef BFD_ASSEMBLER
4716 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
4719 && fixP
->fx_size
== 1
4720 && (fixP
->fx_addsy
== NULL
4721 || S_IS_DEFINED (fixP
->fx_addsy
))
4722 && (val
== 0 || val
== -1))
4723 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("invalid byte branch offset"));
4726 /* *fragP has been relaxed to its final size, and now needs to have
4727 the bytes inside it modified to conform to the new size There is UGLY
4731 md_convert_frag_1 (fragS
*fragP
)
4736 /* Address in object code of the displacement. */
4737 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4739 /* Address in gas core of the place to store the displacement. */
4740 /* This convinces the native rs6000 compiler to generate the code we
4742 register char *buffer_address
= fragP
->fr_literal
;
4743 buffer_address
+= fragP
->fr_fix
;
4744 /* End ibm compiler workaround. */
4746 /* The displacement of the address, from current location. */
4747 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4748 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4750 switch (fragP
->fr_subtype
)
4752 case TAB (BRANCHBWL
, BYTE
):
4753 case TAB (BRABSJUNC
, BYTE
):
4754 case TAB (BRABSJCOND
, BYTE
):
4755 case TAB (BRANCHBW
, BYTE
):
4756 know (issbyte (disp
));
4758 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
4759 _("short branch with zero offset: use :w"));
4760 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4761 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4762 fixP
->fx_pcrel_adjust
= -1;
4764 case TAB (BRANCHBWL
, SHORT
):
4765 case TAB (BRABSJUNC
, SHORT
):
4766 case TAB (BRABSJCOND
, SHORT
):
4767 case TAB (BRANCHBW
, SHORT
):
4768 fragP
->fr_opcode
[1] = 0x00;
4769 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4770 1, RELAX_RELOC_PC16
);
4773 case TAB (BRANCHBWL
, LONG
):
4774 fragP
->fr_opcode
[1] = (char) 0xFF;
4775 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4776 1, RELAX_RELOC_PC32
);
4779 case TAB (BRABSJUNC
, LONG
):
4780 if (fragP
->fr_opcode
[0] == 0x61) /* jbsr */
4782 if (flag_keep_pcrel
)
4783 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4784 fragP
->fr_opcode
[0] = 0x4E;
4785 fragP
->fr_opcode
[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4786 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4787 0, RELAX_RELOC_ABS32
);
4790 else if (fragP
->fr_opcode
[0] == 0x60) /* jbra */
4792 if (flag_keep_pcrel
)
4793 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4794 fragP
->fr_opcode
[0] = 0x4E;
4795 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4796 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4797 0, RELAX_RELOC_ABS32
);
4802 /* This cannot happen, because jbsr and jbra are the only two
4803 unconditional branches. */
4807 case TAB (BRABSJCOND
, LONG
):
4808 if (flag_keep_pcrel
)
4809 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4811 /* Only Bcc 68000 instructions can come here
4812 Change bcc into b!cc/jmp absl long. */
4813 fragP
->fr_opcode
[0] ^= 0x01; /* Invert bcc. */
4814 fragP
->fr_opcode
[1] = 0x06; /* Branch offset = 6. */
4816 /* JF: these used to be fr_opcode[2,3], but they may be in a
4817 different frag, in which case referring to them is a no-no.
4818 Only fr_opcode[0,1] are guaranteed to work. */
4819 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4820 *buffer_address
++ = (char) 0xf9;
4821 fragP
->fr_fix
+= 2; /* Account for jmp instruction. */
4822 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4823 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
4826 case TAB (FBRANCH
, SHORT
):
4827 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4828 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4829 1, RELAX_RELOC_PC16
);
4832 case TAB (FBRANCH
, LONG
):
4833 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit. */
4834 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4835 1, RELAX_RELOC_PC32
);
4838 case TAB (DBCCLBR
, SHORT
):
4839 case TAB (DBCCABSJ
, SHORT
):
4840 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4841 1, RELAX_RELOC_PC16
);
4844 case TAB (DBCCLBR
, LONG
):
4845 /* Only DBcc instructions can come here.
4846 Change dbcc into dbcc/bral.
4847 JF: these used to be fr_opcode[2-7], but that's wrong. */
4848 if (flag_keep_pcrel
)
4849 as_fatal (_("Tried to convert DBcc to absolute jump"));
4851 *buffer_address
++ = 0x00; /* Branch offset = 4. */
4852 *buffer_address
++ = 0x04;
4853 *buffer_address
++ = 0x60; /* Put in bra pc+6. */
4854 *buffer_address
++ = 0x06;
4855 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
4856 *buffer_address
++ = (char) 0xff;
4858 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
4859 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
, 1,
4863 case TAB (DBCCABSJ
, LONG
):
4864 /* Only DBcc instructions can come here.
4865 Change dbcc into dbcc/jmp.
4866 JF: these used to be fr_opcode[2-7], but that's wrong. */
4867 if (flag_keep_pcrel
)
4868 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4870 *buffer_address
++ = 0x00; /* Branch offset = 4. */
4871 *buffer_address
++ = 0x04;
4872 *buffer_address
++ = 0x60; /* Put in bra pc + 6. */
4873 *buffer_address
++ = 0x06;
4874 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
4875 *buffer_address
++ = (char) 0xf9;
4877 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
4878 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
, 0,
4882 case TAB (PCREL1632
, SHORT
):
4883 fragP
->fr_opcode
[1] &= ~0x3F;
4884 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4885 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4886 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4889 case TAB (PCREL1632
, LONG
):
4890 /* Already set to mode 7.3; this indicates: PC indirect with
4891 suppressed index, 32-bit displacement. */
4892 *buffer_address
++ = 0x01;
4893 *buffer_address
++ = 0x70;
4895 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4896 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4897 fixP
->fx_pcrel_adjust
= 2;
4900 case TAB (PCINDEX
, BYTE
):
4901 assert (fragP
->fr_fix
>= 2);
4902 buffer_address
[-2] &= ~1;
4903 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4904 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4905 fixP
->fx_pcrel_adjust
= 1;
4907 case TAB (PCINDEX
, SHORT
):
4908 assert (fragP
->fr_fix
>= 2);
4909 buffer_address
[-2] |= 0x1;
4910 buffer_address
[-1] = 0x20;
4911 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4912 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4913 fixP
->fx_pcrel_adjust
= 2;
4916 case TAB (PCINDEX
, LONG
):
4917 assert (fragP
->fr_fix
>= 2);
4918 buffer_address
[-2] |= 0x1;
4919 buffer_address
[-1] = 0x30;
4920 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4921 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4922 fixP
->fx_pcrel_adjust
= 2;
4925 case TAB (ABSTOPCREL
, SHORT
):
4926 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4927 1, RELAX_RELOC_PC16
);
4930 case TAB (ABSTOPCREL
, LONG
):
4931 if (flag_keep_pcrel
)
4932 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4933 /* The thing to do here is force it to ABSOLUTE LONG, since
4934 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4935 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4937 fragP
->fr_opcode
[1] &= ~0x3F;
4938 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4939 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4940 0, RELAX_RELOC_ABS32
);
4946 #ifndef BFD_ASSEMBLER
4949 md_convert_frag (object_headers
*headers ATTRIBUTE_UNUSED
,
4950 segT sec ATTRIBUTE_UNUSED
,
4953 md_convert_frag_1 (fragP
);
4959 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
4960 segT sec ATTRIBUTE_UNUSED
,
4963 md_convert_frag_1 (fragP
);
4967 /* Force truly undefined symbols to their maximum size, and generally set up
4968 the frag list to be relaxed
4971 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
4973 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4974 switch (fragP
->fr_subtype
)
4976 case TAB (BRANCHBWL
, SZ_UNDEF
):
4977 case TAB (BRABSJUNC
, SZ_UNDEF
):
4978 case TAB (BRABSJCOND
, SZ_UNDEF
):
4980 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4981 && relaxable_symbol (fragP
->fr_symbol
))
4983 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4985 else if (flag_short_refs
)
4987 /* Symbol is undefined and we want short ref. */
4988 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4992 /* Symbol is still undefined. Make it LONG. */
4993 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
4998 case TAB (BRANCHBW
, SZ_UNDEF
):
5000 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5001 && relaxable_symbol (fragP
->fr_symbol
))
5003 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
5007 /* Symbol is undefined and we don't have long branches. */
5008 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5013 case TAB (FBRANCH
, SZ_UNDEF
):
5014 case TAB (DBCCLBR
, SZ_UNDEF
):
5015 case TAB (DBCCABSJ
, SZ_UNDEF
):
5016 case TAB (PCREL1632
, SZ_UNDEF
):
5018 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5019 && relaxable_symbol (fragP
->fr_symbol
))
5022 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5026 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
5031 case TAB (PCINDEX
, SZ_UNDEF
):
5032 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5033 && relaxable_symbol (fragP
->fr_symbol
)))
5035 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
5039 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
5043 case TAB (ABSTOPCREL
, SZ_UNDEF
):
5045 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
5046 && relaxable_symbol (fragP
->fr_symbol
)))
5048 fragP
->fr_subtype
= TAB (ABSTOPCREL
, SHORT
);
5052 fragP
->fr_subtype
= TAB (ABSTOPCREL
, LONG
);
5061 /* Now that SZ_UNDEF are taken care of, check others. */
5062 switch (fragP
->fr_subtype
)
5064 case TAB (BRANCHBWL
, BYTE
):
5065 case TAB (BRABSJUNC
, BYTE
):
5066 case TAB (BRABSJCOND
, BYTE
):
5067 case TAB (BRANCHBW
, BYTE
):
5068 /* We can't do a short jump to the next instruction, so in that
5069 case we force word mode. If the symbol is at the start of a
5070 frag, and it is the next frag with any data in it (usually
5071 this is just the next frag, but assembler listings may
5072 introduce empty frags), we must use word mode. */
5073 if (fragP
->fr_symbol
)
5077 sym_frag
= symbol_get_frag (fragP
->fr_symbol
);
5078 if (S_GET_VALUE (fragP
->fr_symbol
) == sym_frag
->fr_address
)
5082 for (l
= fragP
->fr_next
; l
&& l
!= sym_frag
; l
= l
->fr_next
)
5086 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5093 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5096 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5097 /* the bit-field entries in the relocation_info struct plays hell
5098 with the byte-order problems of cross-assembly. So as a hack,
5099 I added this mach. dependent ri twiddler. Ugly, but it gets
5101 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5102 are symbolnum, most sig. byte first. Last byte is broken up with
5103 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5104 nibble as nuthin. (on Sun 3 at least) */
5105 /* Translate the internal relocation information into target-specific
5109 md_ri_to_chars (char *the_bytes
, struct reloc_info_generic
*ri
)
5112 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
5113 /* Now the fun stuff. */
5114 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
5115 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
5116 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
5117 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80)
5118 | ((ri
->r_length
<< 5) & 0x60)
5119 | ((ri
->r_extern
<< 4) & 0x10));
5124 #ifndef BFD_ASSEMBLER
5126 tc_aout_fix_to_chars (char *where
, fixS
*fixP
,
5127 relax_addressT segment_address_in_file
)
5130 * In: length of relocation (or of address) in chars: 1, 2 or 4.
5131 * Out: GNU LD relocation length code: 0, 1, or 2.
5134 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
5137 know (fixP
->fx_addsy
!= NULL
);
5139 md_number_to_chars (where
,
5140 (fixP
->fx_frag
->fr_address
5141 + fixP
->fx_where
- segment_address_in_file
), 4);
5143 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
5144 ? S_GET_TYPE (fixP
->fx_addsy
)
5145 : fixP
->fx_addsy
->sy_number
);
5147 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
5148 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
5149 where
[6] = r_symbolnum
& 0x0ff;
5150 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80)
5151 | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60)
5152 | ((!S_IS_DEFINED (fixP
->fx_addsy
) << 4) & 0x10));
5156 #endif /* OBJ_AOUT or OBJ_BOUT */
5158 #ifndef WORKING_DOT_WORD
5159 int md_short_jump_size
= 4;
5160 int md_long_jump_size
= 6;
5163 md_create_short_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5164 fragS
*frag ATTRIBUTE_UNUSED
,
5165 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
5169 offset
= to_addr
- (from_addr
+ 2);
5171 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
5172 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
5176 md_create_long_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5177 fragS
*frag
, symbolS
*to_symbol
)
5181 if (!HAVE_LONG_BRANCH (current_architecture
))
5183 if (flag_keep_pcrel
)
5184 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5185 offset
= to_addr
- S_GET_VALUE (to_symbol
);
5186 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
5187 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5188 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
5193 offset
= to_addr
- (from_addr
+ 2);
5194 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
5195 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5201 /* Different values of OK tell what its OK to return. Things that
5202 aren't OK are an error (what a shock, no?)
5205 10: Absolute 1:8 only
5206 20: Absolute 0:7 only
5207 30: absolute 0:15 only
5208 40: Absolute 0:31 only
5209 50: absolute 0:127 only
5210 55: absolute -64:63 only
5211 60: absolute -128:127 only
5212 70: absolute 0:4095 only
5213 80: absolute -1, 1:7 only
5217 get_num (struct m68k_exp
*exp
, int ok
)
5219 if (exp
->exp
.X_op
== O_absent
)
5221 /* Do the same thing the VAX asm does. */
5222 op (exp
) = O_constant
;
5228 as_warn (_("expression out of range: defaulting to 1"));
5232 else if (exp
->exp
.X_op
== O_constant
)
5237 if ((valueT
) TRUNC (offs (exp
)) - 1 > 7)
5239 as_warn (_("expression out of range: defaulting to 1"));
5244 if ((valueT
) TRUNC (offs (exp
)) > 7)
5248 if ((valueT
) TRUNC (offs (exp
)) > 15)
5252 if ((valueT
) TRUNC (offs (exp
)) > 32)
5256 if ((valueT
) TRUNC (offs (exp
)) > 127)
5260 if ((valueT
) SEXT (offs (exp
)) + 64 > 127)
5264 if ((valueT
) SEXT (offs (exp
)) + 128 > 255)
5268 if ((valueT
) TRUNC (offs (exp
)) > 4095)
5271 as_warn (_("expression out of range: defaulting to 0"));
5276 if ((valueT
) TRUNC (offs (exp
)) != 0xffffffff
5277 && (valueT
) TRUNC (offs (exp
)) - 1 > 6)
5279 as_warn (_("expression out of range: defaulting to 1"));
5287 else if (exp
->exp
.X_op
== O_big
)
5289 if (offs (exp
) <= 0 /* flonum. */
5290 && (ok
== 90 /* no bignums */
5291 || (ok
> 10 /* Small-int ranges including 0 ok. */
5292 /* If we have a flonum zero, a zero integer should
5293 do as well (e.g., in moveq). */
5294 && generic_floating_point_number
.exponent
== 0
5295 && generic_floating_point_number
.low
[0] == 0)))
5297 /* HACK! Turn it into a long. */
5298 LITTLENUM_TYPE words
[6];
5300 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5301 op (exp
) = O_constant
;
5304 offs (exp
) = words
[1] | (words
[0] << 16);
5308 op (exp
) = O_constant
;
5311 offs (exp
) = (ok
== 10) ? 1 : 0;
5312 as_warn (_("Can't deal with expression; defaulting to %ld"),
5318 if (ok
>= 10 && ok
<= 80)
5320 op (exp
) = O_constant
;
5323 offs (exp
) = (ok
== 10) ? 1 : 0;
5324 as_warn (_("Can't deal with expression; defaulting to %ld"),
5329 if (exp
->size
!= SIZE_UNSPEC
)
5337 if (!isbyte (offs (exp
)))
5338 as_warn (_("expression doesn't fit in BYTE"));
5341 if (!isword (offs (exp
)))
5342 as_warn (_("expression doesn't fit in WORD"));
5350 /* These are the back-ends for the various machine dependent pseudo-ops. */
5353 s_data1 (int ignore ATTRIBUTE_UNUSED
)
5355 subseg_set (data_section
, 1);
5356 demand_empty_rest_of_line ();
5360 s_data2 (int ignore ATTRIBUTE_UNUSED
)
5362 subseg_set (data_section
, 2);
5363 demand_empty_rest_of_line ();
5367 s_bss (int ignore ATTRIBUTE_UNUSED
)
5369 /* We don't support putting frags in the BSS segment, we fake it
5370 by marking in_bss, then looking at s_skip for clues. */
5372 subseg_set (bss_section
, 0);
5373 demand_empty_rest_of_line ();
5377 s_even (int ignore ATTRIBUTE_UNUSED
)
5380 register long temp_fill
;
5382 temp
= 1; /* JF should be 2? */
5383 temp_fill
= get_absolute_expression ();
5384 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5385 frag_align (temp
, (int) temp_fill
, 0);
5386 demand_empty_rest_of_line ();
5387 record_alignment (now_seg
, temp
);
5391 s_proc (int ignore ATTRIBUTE_UNUSED
)
5393 demand_empty_rest_of_line ();
5396 /* Pseudo-ops handled for MRI compatibility. */
5398 /* This function returns non-zero if the argument is a conditional
5399 pseudo-op. This is called when checking whether a pending
5400 alignment is needed. */
5403 m68k_conditional_pseudoop (pseudo_typeS
*pop
)
5405 return (pop
->poc_handler
== s_mri_if
5406 || pop
->poc_handler
== s_mri_else
);
5409 /* Handle an MRI style chip specification. */
5418 s
= input_line_pointer
;
5419 /* We can't use get_symbol_end since the processor names are not proper
5421 while (is_part_of_name (c
= *input_line_pointer
++))
5423 *--input_line_pointer
= 0;
5424 for (i
= 0; i
< n_archs
; i
++)
5425 if (strcasecmp (s
, archs
[i
].name
) == 0)
5429 as_bad (_("%s: unrecognized processor name"), s
);
5430 *input_line_pointer
= c
;
5431 ignore_rest_of_line ();
5434 *input_line_pointer
= c
;
5436 if (*input_line_pointer
== '/')
5437 current_architecture
= 0;
5439 current_architecture
&= m68881
| m68851
;
5440 current_architecture
|= archs
[i
].arch
;
5441 current_chip
= archs
[i
].chip
;
5443 while (*input_line_pointer
== '/')
5445 ++input_line_pointer
;
5446 s
= input_line_pointer
;
5447 /* We can't use get_symbol_end since the processor names are not
5449 while (is_part_of_name (c
= *input_line_pointer
++))
5451 *--input_line_pointer
= 0;
5452 if (strcmp (s
, "68881") == 0)
5453 current_architecture
|= m68881
;
5454 else if (strcmp (s
, "68851") == 0)
5455 current_architecture
|= m68851
;
5456 *input_line_pointer
= c
;
5459 /* Update info about available control registers. */
5460 select_control_regs ();
5463 /* The MRI CHIP pseudo-op. */
5466 s_chip (int ignore ATTRIBUTE_UNUSED
)
5472 stop
= mri_comment_field (&stopc
);
5475 mri_comment_end (stop
, stopc
);
5476 demand_empty_rest_of_line ();
5479 /* The MRI FOPT pseudo-op. */
5482 s_fopt (int ignore ATTRIBUTE_UNUSED
)
5486 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5490 input_line_pointer
+= 3;
5491 temp
= get_absolute_expression ();
5492 if (temp
< 0 || temp
> 7)
5493 as_bad (_("bad coprocessor id"));
5495 m68k_float_copnum
= COP0
+ temp
;
5499 as_bad (_("unrecognized fopt option"));
5500 ignore_rest_of_line ();
5504 demand_empty_rest_of_line ();
5507 /* The structure used to handle the MRI OPT pseudo-op. */
5511 /* The name of the option. */
5514 /* If this is not NULL, just call this function. The first argument
5515 is the ARG field of this structure, the second argument is
5516 whether the option was negated. */
5517 void (*pfn
) (int arg
, int on
);
5519 /* If this is not NULL, and the PFN field is NULL, set the variable
5520 this points to. Set it to the ARG field if the option was not
5521 negated, and the NOTARG field otherwise. */
5524 /* The value to pass to PFN or to assign to *PVAR. */
5527 /* The value to assign to *PVAR if the option is negated. If PFN is
5528 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5529 the option may not be negated. */
5533 /* The table used to handle the MRI OPT pseudo-op. */
5535 static void skip_to_comma (int, int);
5536 static void opt_nest (int, int);
5537 static void opt_chip (int, int);
5538 static void opt_list (int, int);
5539 static void opt_list_symbols (int, int);
5541 static const struct opt_action opt_table
[] =
5543 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5545 /* We do relaxing, so there is little use for these options. */
5546 { "b", 0, 0, 0, 0 },
5547 { "brs", 0, 0, 0, 0 },
5548 { "brb", 0, 0, 0, 0 },
5549 { "brl", 0, 0, 0, 0 },
5550 { "brw", 0, 0, 0, 0 },
5552 { "c", 0, 0, 0, 0 },
5553 { "cex", 0, 0, 0, 0 },
5554 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5555 { "cl", 0, 0, 0, 0 },
5556 { "cre", 0, 0, 0, 0 },
5557 { "d", 0, &flag_keep_locals
, 1, 0 },
5558 { "e", 0, 0, 0, 0 },
5559 { "f", 0, &flag_short_refs
, 1, 0 },
5560 { "frs", 0, &flag_short_refs
, 1, 0 },
5561 { "frl", 0, &flag_short_refs
, 0, 1 },
5562 { "g", 0, 0, 0, 0 },
5563 { "i", 0, 0, 0, 0 },
5564 { "m", 0, 0, 0, 0 },
5565 { "mex", 0, 0, 0, 0 },
5566 { "mc", 0, 0, 0, 0 },
5567 { "md", 0, 0, 0, 0 },
5568 { "nest", opt_nest
, 0, 0, 0 },
5569 { "next", skip_to_comma
, 0, 0, 0 },
5570 { "o", 0, 0, 0, 0 },
5571 { "old", 0, 0, 0, 0 },
5572 { "op", skip_to_comma
, 0, 0, 0 },
5573 { "pco", 0, 0, 0, 0 },
5574 { "p", opt_chip
, 0, 0, 0 },
5575 { "pcr", 0, 0, 0, 0 },
5576 { "pcs", 0, 0, 0, 0 },
5577 { "r", 0, 0, 0, 0 },
5578 { "quick", 0, &m68k_quick
, 1, 0 },
5579 { "rel32", 0, &m68k_rel32
, 1, 0 },
5580 { "s", opt_list
, 0, 0, 0 },
5581 { "t", opt_list_symbols
, 0, 0, 0 },
5582 { "w", 0, &flag_no_warnings
, 0, 1 },
5586 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5588 /* The MRI OPT pseudo-op. */
5591 s_opt (int ignore ATTRIBUTE_UNUSED
)
5599 const struct opt_action
*o
;
5604 if (*input_line_pointer
== '-')
5606 ++input_line_pointer
;
5609 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5611 input_line_pointer
+= 2;
5615 s
= input_line_pointer
;
5616 c
= get_symbol_end ();
5618 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5620 if (strcasecmp (s
, o
->name
) == 0)
5624 /* Restore input_line_pointer now in case the option
5626 *input_line_pointer
= c
;
5627 (*o
->pfn
) (o
->arg
, t
);
5629 else if (o
->pvar
!= NULL
)
5631 if (! t
&& o
->arg
== o
->notarg
)
5632 as_bad (_("option `%s' may not be negated"), s
);
5633 *input_line_pointer
= c
;
5634 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5637 *input_line_pointer
= c
;
5643 as_bad (_("option `%s' not recognized"), s
);
5644 *input_line_pointer
= c
;
5647 while (*input_line_pointer
++ == ',');
5649 /* Move back to terminating character. */
5650 --input_line_pointer
;
5651 demand_empty_rest_of_line ();
5654 /* Skip ahead to a comma. This is used for OPT options which we do
5655 not support and which take arguments. */
5658 skip_to_comma (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5660 while (*input_line_pointer
!= ','
5661 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5662 ++input_line_pointer
;
5665 /* Handle the OPT NEST=depth option. */
5668 opt_nest (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5670 if (*input_line_pointer
!= '=')
5672 as_bad (_("bad format of OPT NEST=depth"));
5676 ++input_line_pointer
;
5677 max_macro_nest
= get_absolute_expression ();
5680 /* Handle the OPT P=chip option. */
5683 opt_chip (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5685 if (*input_line_pointer
!= '=')
5687 /* This is just OPT P, which we do not support. */
5691 ++input_line_pointer
;
5695 /* Handle the OPT S option. */
5698 opt_list (int arg ATTRIBUTE_UNUSED
, int on
)
5703 /* Handle the OPT T option. */
5706 opt_list_symbols (int arg ATTRIBUTE_UNUSED
, int on
)
5709 listing
|= LISTING_SYMBOLS
;
5711 listing
&= ~LISTING_SYMBOLS
;
5714 /* Handle the MRI REG pseudo-op. */
5717 s_reg (int ignore ATTRIBUTE_UNUSED
)
5726 if (line_label
== NULL
)
5728 as_bad (_("missing label"));
5729 ignore_rest_of_line ();
5734 stop
= mri_comment_field (&stopc
);
5738 s
= input_line_pointer
;
5739 while (ISALNUM (*input_line_pointer
)
5740 #ifdef REGISTER_PREFIX
5741 || *input_line_pointer
== REGISTER_PREFIX
5743 || *input_line_pointer
== '/'
5744 || *input_line_pointer
== '-')
5745 ++input_line_pointer
;
5746 c
= *input_line_pointer
;
5747 *input_line_pointer
= '\0';
5749 if (m68k_ip_op (s
, &rop
) != 0)
5751 if (rop
.error
== NULL
)
5752 as_bad (_("bad register list"));
5754 as_bad (_("bad register list: %s"), rop
.error
);
5755 *input_line_pointer
= c
;
5756 ignore_rest_of_line ();
5760 *input_line_pointer
= c
;
5762 if (rop
.mode
== REGLST
)
5764 else if (rop
.mode
== DREG
)
5765 mask
= 1 << (rop
.reg
- DATA0
);
5766 else if (rop
.mode
== AREG
)
5767 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5768 else if (rop
.mode
== FPREG
)
5769 mask
= 1 << (rop
.reg
- FP0
+ 16);
5770 else if (rop
.mode
== CONTROL
5773 else if (rop
.mode
== CONTROL
5776 else if (rop
.mode
== CONTROL
5781 as_bad (_("bad register list"));
5782 ignore_rest_of_line ();
5786 S_SET_SEGMENT (line_label
, reg_section
);
5787 S_SET_VALUE (line_label
, ~mask
);
5788 symbol_set_frag (line_label
, &zero_address_frag
);
5791 mri_comment_end (stop
, stopc
);
5793 demand_empty_rest_of_line ();
5796 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5800 struct save_opts
*next
;
5802 int symbols_case_sensitive
;
5811 /* FIXME: We don't save OPT S. */
5814 /* This variable holds the stack of saved options. */
5816 static struct save_opts
*save_stack
;
5818 /* The MRI SAVE pseudo-op. */
5821 s_save (int ignore ATTRIBUTE_UNUSED
)
5823 struct save_opts
*s
;
5825 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5826 s
->abspcadd
= m68k_abspcadd
;
5827 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5828 s
->keep_locals
= flag_keep_locals
;
5829 s
->short_refs
= flag_short_refs
;
5830 s
->architecture
= current_architecture
;
5831 s
->chip
= current_chip
;
5832 s
->quick
= m68k_quick
;
5833 s
->rel32
= m68k_rel32
;
5834 s
->listing
= listing
;
5835 s
->no_warnings
= flag_no_warnings
;
5837 s
->next
= save_stack
;
5840 demand_empty_rest_of_line ();
5843 /* The MRI RESTORE pseudo-op. */
5846 s_restore (int ignore ATTRIBUTE_UNUSED
)
5848 struct save_opts
*s
;
5850 if (save_stack
== NULL
)
5852 as_bad (_("restore without save"));
5853 ignore_rest_of_line ();
5858 save_stack
= s
->next
;
5860 m68k_abspcadd
= s
->abspcadd
;
5861 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5862 flag_keep_locals
= s
->keep_locals
;
5863 flag_short_refs
= s
->short_refs
;
5864 current_architecture
= s
->architecture
;
5865 current_chip
= s
->chip
;
5866 m68k_quick
= s
->quick
;
5867 m68k_rel32
= s
->rel32
;
5868 listing
= s
->listing
;
5869 flag_no_warnings
= s
->no_warnings
;
5873 demand_empty_rest_of_line ();
5876 /* Types of MRI structured control directives. */
5878 enum mri_control_type
5886 /* This structure is used to stack the MRI structured control
5889 struct mri_control_info
5891 /* The directive within which this one is enclosed. */
5892 struct mri_control_info
*outer
;
5894 /* The type of directive. */
5895 enum mri_control_type type
;
5897 /* Whether an ELSE has been in an IF. */
5900 /* The add or sub statement at the end of a FOR. */
5903 /* The label of the top of a FOR or REPEAT loop. */
5906 /* The label to jump to for the next iteration, or the else
5907 expression of a conditional. */
5910 /* The label to jump to to break out of the loop, or the label past
5911 the end of a conditional. */
5915 /* The stack of MRI structured control directives. */
5917 static struct mri_control_info
*mri_control_stack
;
5919 /* The current MRI structured control directive index number, used to
5920 generate label names. */
5922 static int mri_control_index
;
5924 /* Assemble an instruction for an MRI structured control directive. */
5927 mri_assemble (char *str
)
5931 /* md_assemble expects the opcode to be in lower case. */
5932 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
5938 /* Generate a new MRI label structured control directive label name. */
5941 mri_control_label (void)
5945 n
= (char *) xmalloc (20);
5946 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5947 ++mri_control_index
;
5951 /* Create a new MRI structured control directive. */
5953 static struct mri_control_info
*
5954 push_mri_control (enum mri_control_type type
)
5956 struct mri_control_info
*n
;
5958 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5962 if (type
== mri_if
|| type
== mri_while
)
5965 n
->top
= mri_control_label ();
5966 n
->next
= mri_control_label ();
5967 n
->bottom
= mri_control_label ();
5969 n
->outer
= mri_control_stack
;
5970 mri_control_stack
= n
;
5975 /* Pop off the stack of MRI structured control directives. */
5978 pop_mri_control (void)
5980 struct mri_control_info
*n
;
5982 n
= mri_control_stack
;
5983 mri_control_stack
= n
->outer
;
5991 /* Recognize a condition code in an MRI structured control expression. */
5994 parse_mri_condition (int *pcc
)
5998 know (*input_line_pointer
== '<');
6000 ++input_line_pointer
;
6001 c1
= *input_line_pointer
++;
6002 c2
= *input_line_pointer
++;
6004 if (*input_line_pointer
!= '>')
6006 as_bad (_("syntax error in structured control directive"));
6010 ++input_line_pointer
;
6016 *pcc
= (c1
<< 8) | c2
;
6021 /* Parse a single operand in an MRI structured control expression. */
6024 parse_mri_control_operand (int *pcc
, char **leftstart
, char **leftstop
,
6025 char **rightstart
, char **rightstop
)
6037 if (*input_line_pointer
== '<')
6039 /* It's just a condition code. */
6040 return parse_mri_condition (pcc
);
6043 /* Look ahead for the condition code. */
6044 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6046 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
6051 as_bad (_("missing condition code in structured control directive"));
6055 *leftstart
= input_line_pointer
;
6057 if (*leftstop
> *leftstart
6058 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
6061 input_line_pointer
= s
;
6062 if (! parse_mri_condition (pcc
))
6065 /* Look ahead for AND or OR or end of line. */
6066 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
6068 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6069 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6071 if ((s
== input_line_pointer
6074 && ((strncasecmp (s
, "AND", 3) == 0
6075 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
6076 || (strncasecmp (s
, "OR", 2) == 0
6077 && (s
[2] == '.' || ! is_part_of_name (s
[2])))))
6081 *rightstart
= input_line_pointer
;
6083 if (*rightstop
> *rightstart
6084 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
6087 input_line_pointer
= s
;
6092 #define MCC(b1, b2) (((b1) << 8) | (b2))
6094 /* Swap the sense of a condition. This changes the condition so that
6095 it generates the same result when the operands are swapped. */
6098 swap_mri_condition (int cc
)
6102 case MCC ('h', 'i'): return MCC ('c', 's');
6103 case MCC ('l', 's'): return MCC ('c', 'c');
6104 /* <HS> is an alias for <CC>. */
6105 case MCC ('h', 's'):
6106 case MCC ('c', 'c'): return MCC ('l', 's');
6107 /* <LO> is an alias for <CS>. */
6108 case MCC ('l', 'o'):
6109 case MCC ('c', 's'): return MCC ('h', 'i');
6110 case MCC ('p', 'l'): return MCC ('m', 'i');
6111 case MCC ('m', 'i'): return MCC ('p', 'l');
6112 case MCC ('g', 'e'): return MCC ('l', 'e');
6113 case MCC ('l', 't'): return MCC ('g', 't');
6114 case MCC ('g', 't'): return MCC ('l', 't');
6115 case MCC ('l', 'e'): return MCC ('g', 'e');
6116 /* Issue a warning for conditions we can not swap. */
6117 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
6118 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
6119 case MCC ('v', 'c'):
6120 case MCC ('v', 's'):
6122 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6123 (char) (cc
>> 8), (char) (cc
));
6129 /* Reverse the sense of a condition. */
6132 reverse_mri_condition (int cc
)
6136 case MCC ('h', 'i'): return MCC ('l', 's');
6137 case MCC ('l', 's'): return MCC ('h', 'i');
6138 /* <HS> is an alias for <CC> */
6139 case MCC ('h', 's'): return MCC ('l', 'o');
6140 case MCC ('c', 'c'): return MCC ('c', 's');
6141 /* <LO> is an alias for <CS> */
6142 case MCC ('l', 'o'): return MCC ('h', 's');
6143 case MCC ('c', 's'): return MCC ('c', 'c');
6144 case MCC ('n', 'e'): return MCC ('e', 'q');
6145 case MCC ('e', 'q'): return MCC ('n', 'e');
6146 case MCC ('v', 'c'): return MCC ('v', 's');
6147 case MCC ('v', 's'): return MCC ('v', 'c');
6148 case MCC ('p', 'l'): return MCC ('m', 'i');
6149 case MCC ('m', 'i'): return MCC ('p', 'l');
6150 case MCC ('g', 'e'): return MCC ('l', 't');
6151 case MCC ('l', 't'): return MCC ('g', 'e');
6152 case MCC ('g', 't'): return MCC ('l', 'e');
6153 case MCC ('l', 'e'): return MCC ('g', 't');
6158 /* Build an MRI structured control expression. This generates test
6159 and branch instructions. It goes to TRUELAB if the condition is
6160 true, and to FALSELAB if the condition is false. Exactly one of
6161 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6162 is the size qualifier for the expression. EXTENT is the size to
6163 use for the branch. */
6166 build_mri_control_operand (int qual
, int cc
, char *leftstart
, char *leftstop
,
6167 char *rightstart
, char *rightstop
,
6168 const char *truelab
, const char *falselab
,
6174 if (leftstart
!= NULL
)
6176 struct m68k_op leftop
, rightop
;
6179 /* Swap the compare operands, if necessary, to produce a legal
6180 m68k compare instruction. Comparing a register operand with
6181 a non-register operand requires the register to be on the
6182 right (cmp, cmpa). Comparing an immediate value with
6183 anything requires the immediate value to be on the left
6188 (void) m68k_ip_op (leftstart
, &leftop
);
6193 (void) m68k_ip_op (rightstart
, &rightop
);
6196 if (rightop
.mode
== IMMED
6197 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
6198 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
6202 /* Correct conditional handling:
6203 if #1 <lt> d0 then ;means if (1 < d0)
6209 cmp #1,d0 if we do *not* swap the operands
6210 bgt true we need the swapped condition!
6217 leftstart
= rightstart
;
6220 leftstop
= rightstop
;
6225 cc
= swap_mri_condition (cc
);
6229 if (truelab
== NULL
)
6231 cc
= reverse_mri_condition (cc
);
6235 if (leftstart
!= NULL
)
6237 buf
= (char *) xmalloc (20
6238 + (leftstop
- leftstart
)
6239 + (rightstop
- rightstart
));
6245 *s
++ = TOLOWER (qual
);
6247 memcpy (s
, leftstart
, leftstop
- leftstart
);
6248 s
+= leftstop
- leftstart
;
6250 memcpy (s
, rightstart
, rightstop
- rightstart
);
6251 s
+= rightstop
- rightstart
;
6257 buf
= (char *) xmalloc (20 + strlen (truelab
));
6263 *s
++ = TOLOWER (extent
);
6265 strcpy (s
, truelab
);
6270 /* Parse an MRI structured control expression. This generates test
6271 and branch instructions. STOP is where the expression ends. It
6272 goes to TRUELAB if the condition is true, and to FALSELAB if the
6273 condition is false. Exactly one of TRUELAB and FALSELAB will be
6274 NULL, meaning to fall through. QUAL is the size qualifier for the
6275 expression. EXTENT is the size to use for the branch. */
6278 parse_mri_control_expression (char *stop
, int qual
, const char *truelab
,
6279 const char *falselab
, int extent
)
6291 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6292 &rightstart
, &rightstop
))
6298 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6302 if (falselab
!= NULL
)
6305 flab
= mri_control_label ();
6307 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6308 rightstop
, (const char *) NULL
, flab
, extent
);
6310 input_line_pointer
+= 3;
6311 if (*input_line_pointer
!= '.'
6312 || input_line_pointer
[1] == '\0')
6316 qual
= input_line_pointer
[1];
6317 input_line_pointer
+= 2;
6320 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6321 &rightstart
, &rightstop
))
6327 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6328 rightstop
, truelab
, falselab
, extent
);
6330 if (falselab
== NULL
)
6333 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6337 if (truelab
!= NULL
)
6340 tlab
= mri_control_label ();
6342 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6343 rightstop
, tlab
, (const char *) NULL
, extent
);
6345 input_line_pointer
+= 2;
6346 if (*input_line_pointer
!= '.'
6347 || input_line_pointer
[1] == '\0')
6351 qual
= input_line_pointer
[1];
6352 input_line_pointer
+= 2;
6355 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6356 &rightstart
, &rightstop
))
6362 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6363 rightstop
, truelab
, falselab
, extent
);
6365 if (truelab
== NULL
)
6370 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6371 rightstop
, truelab
, falselab
, extent
);
6375 if (input_line_pointer
!= stop
)
6376 as_bad (_("syntax error in structured control directive"));
6379 /* Handle the MRI IF pseudo-op. This may be a structured control
6380 directive, or it may be a regular assembler conditional, depending
6388 struct mri_control_info
*n
;
6390 /* A structured control directive must end with THEN with an
6391 optional qualifier. */
6392 s
= input_line_pointer
;
6393 /* We only accept '*' as introduction of comments if preceded by white space
6394 or at first column of a line (I think this can't actually happen here?)
6395 This is important when assembling:
6396 if d0 <ne> 12(a0,d0*2) then
6397 if d0 <ne> #CONST*20 then. */
6398 while (! (is_end_of_line
[(unsigned char) *s
]
6401 && (s
== input_line_pointer
6403 || *(s
-1) == '\t'))))
6406 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6409 if (s
- input_line_pointer
> 1
6413 if (s
- input_line_pointer
< 3
6414 || strncasecmp (s
- 3, "THEN", 4) != 0)
6418 as_bad (_("missing then"));
6419 ignore_rest_of_line ();
6423 /* It's a conditional. */
6428 /* Since this might be a conditional if, this pseudo-op will be
6429 called even if we are supported to be ignoring input. Double
6430 check now. Clobber *input_line_pointer so that ignore_input
6431 thinks that this is not a special pseudo-op. */
6432 c
= *input_line_pointer
;
6433 *input_line_pointer
= 0;
6434 if (ignore_input ())
6436 *input_line_pointer
= c
;
6437 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6438 ++input_line_pointer
;
6439 demand_empty_rest_of_line ();
6442 *input_line_pointer
= c
;
6444 n
= push_mri_control (mri_if
);
6446 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6447 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6450 input_line_pointer
= s
+ 3;
6452 input_line_pointer
= s
+ 1;
6456 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6457 ++input_line_pointer
;
6460 demand_empty_rest_of_line ();
6463 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6464 structured IF, associate the ELSE with the IF. Otherwise, assume
6465 it is a conditional else. */
6468 s_mri_else (int qual
)
6475 && (mri_control_stack
== NULL
6476 || mri_control_stack
->type
!= mri_if
6477 || mri_control_stack
->else_seen
))
6483 c
= *input_line_pointer
;
6484 *input_line_pointer
= 0;
6485 if (ignore_input ())
6487 *input_line_pointer
= c
;
6488 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6489 ++input_line_pointer
;
6490 demand_empty_rest_of_line ();
6493 *input_line_pointer
= c
;
6495 if (mri_control_stack
== NULL
6496 || mri_control_stack
->type
!= mri_if
6497 || mri_control_stack
->else_seen
)
6499 as_bad (_("else without matching if"));
6500 ignore_rest_of_line ();
6504 mri_control_stack
->else_seen
= 1;
6506 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6507 q
[0] = TOLOWER (qual
);
6509 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6513 colon (mri_control_stack
->next
);
6517 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6518 ++input_line_pointer
;
6521 demand_empty_rest_of_line ();
6524 /* Handle the MRI ENDI pseudo-op. */
6527 s_mri_endi (int ignore ATTRIBUTE_UNUSED
)
6529 if (mri_control_stack
== NULL
6530 || mri_control_stack
->type
!= mri_if
)
6532 as_bad (_("endi without matching if"));
6533 ignore_rest_of_line ();
6537 /* ignore_input will not return true for ENDI, so we don't need to
6538 worry about checking it again here. */
6540 if (! mri_control_stack
->else_seen
)
6541 colon (mri_control_stack
->next
);
6542 colon (mri_control_stack
->bottom
);
6548 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6549 ++input_line_pointer
;
6552 demand_empty_rest_of_line ();
6555 /* Handle the MRI BREAK pseudo-op. */
6558 s_mri_break (int extent
)
6560 struct mri_control_info
*n
;
6564 n
= mri_control_stack
;
6566 && n
->type
!= mri_for
6567 && n
->type
!= mri_repeat
6568 && n
->type
!= mri_while
)
6572 as_bad (_("break outside of structured loop"));
6573 ignore_rest_of_line ();
6577 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6578 ex
[0] = TOLOWER (extent
);
6580 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6586 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6587 ++input_line_pointer
;
6590 demand_empty_rest_of_line ();
6593 /* Handle the MRI NEXT pseudo-op. */
6596 s_mri_next (int extent
)
6598 struct mri_control_info
*n
;
6602 n
= mri_control_stack
;
6604 && n
->type
!= mri_for
6605 && n
->type
!= mri_repeat
6606 && n
->type
!= mri_while
)
6610 as_bad (_("next outside of structured loop"));
6611 ignore_rest_of_line ();
6615 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6616 ex
[0] = TOLOWER (extent
);
6618 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6624 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6625 ++input_line_pointer
;
6628 demand_empty_rest_of_line ();
6631 /* Handle the MRI FOR pseudo-op. */
6634 s_mri_for (int qual
)
6636 const char *varstart
, *varstop
;
6637 const char *initstart
, *initstop
;
6638 const char *endstart
, *endstop
;
6639 const char *bystart
, *bystop
;
6643 struct mri_control_info
*n
;
6649 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6653 varstart
= input_line_pointer
;
6655 /* Look for the '='. */
6656 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6657 && *input_line_pointer
!= '=')
6658 ++input_line_pointer
;
6659 if (*input_line_pointer
!= '=')
6661 as_bad (_("missing ="));
6662 ignore_rest_of_line ();
6666 varstop
= input_line_pointer
;
6667 if (varstop
> varstart
6668 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6671 ++input_line_pointer
;
6673 initstart
= input_line_pointer
;
6675 /* Look for TO or DOWNTO. */
6678 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6680 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6681 && ! is_part_of_name (input_line_pointer
[2]))
6683 initstop
= input_line_pointer
;
6684 input_line_pointer
+= 2;
6687 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6688 && ! is_part_of_name (input_line_pointer
[6]))
6690 initstop
= input_line_pointer
;
6692 input_line_pointer
+= 6;
6695 ++input_line_pointer
;
6697 if (initstop
== NULL
)
6699 as_bad (_("missing to or downto"));
6700 ignore_rest_of_line ();
6703 if (initstop
> initstart
6704 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6708 endstart
= input_line_pointer
;
6710 /* Look for BY or DO. */
6713 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6715 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6716 && ! is_part_of_name (input_line_pointer
[2]))
6718 endstop
= input_line_pointer
;
6720 input_line_pointer
+= 2;
6723 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6724 && (input_line_pointer
[2] == '.'
6725 || ! is_part_of_name (input_line_pointer
[2])))
6727 endstop
= input_line_pointer
;
6728 input_line_pointer
+= 2;
6731 ++input_line_pointer
;
6733 if (endstop
== NULL
)
6735 as_bad (_("missing do"));
6736 ignore_rest_of_line ();
6739 if (endstop
> endstart
6740 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6746 bystop
= bystart
+ 2;
6751 bystart
= input_line_pointer
;
6755 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6757 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6758 && (input_line_pointer
[2] == '.'
6759 || ! is_part_of_name (input_line_pointer
[2])))
6761 bystop
= input_line_pointer
;
6762 input_line_pointer
+= 2;
6765 ++input_line_pointer
;
6769 as_bad (_("missing do"));
6770 ignore_rest_of_line ();
6773 if (bystop
> bystart
6774 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6778 if (*input_line_pointer
!= '.')
6782 extent
= input_line_pointer
[1];
6783 input_line_pointer
+= 2;
6786 /* We have fully parsed the FOR operands. Now build the loop. */
6787 n
= push_mri_control (mri_for
);
6789 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6791 /* Move init,var. */
6798 *s
++ = TOLOWER (qual
);
6800 memcpy (s
, initstart
, initstop
- initstart
);
6801 s
+= initstop
- initstart
;
6803 memcpy (s
, varstart
, varstop
- varstart
);
6804 s
+= varstop
- varstart
;
6816 *s
++ = TOLOWER (qual
);
6818 memcpy (s
, endstart
, endstop
- endstart
);
6819 s
+= endstop
- endstart
;
6821 memcpy (s
, varstart
, varstop
- varstart
);
6822 s
+= varstop
- varstart
;
6827 ex
[0] = TOLOWER (extent
);
6830 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6832 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6835 /* Put together the add or sub instruction used by ENDF. */
6843 *s
++ = TOLOWER (qual
);
6845 memcpy (s
, bystart
, bystop
- bystart
);
6846 s
+= bystop
- bystart
;
6848 memcpy (s
, varstart
, varstop
- varstart
);
6849 s
+= varstop
- varstart
;
6855 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6856 ++input_line_pointer
;
6859 demand_empty_rest_of_line ();
6862 /* Handle the MRI ENDF pseudo-op. */
6865 s_mri_endf (int ignore ATTRIBUTE_UNUSED
)
6867 if (mri_control_stack
== NULL
6868 || mri_control_stack
->type
!= mri_for
)
6870 as_bad (_("endf without for"));
6871 ignore_rest_of_line ();
6875 colon (mri_control_stack
->next
);
6877 mri_assemble (mri_control_stack
->incr
);
6879 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6880 mri_assemble (mri_control_stack
->incr
);
6882 free (mri_control_stack
->incr
);
6884 colon (mri_control_stack
->bottom
);
6890 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6891 ++input_line_pointer
;
6894 demand_empty_rest_of_line ();
6897 /* Handle the MRI REPEAT pseudo-op. */
6900 s_mri_repeat (int ignore ATTRIBUTE_UNUSED
)
6902 struct mri_control_info
*n
;
6904 n
= push_mri_control (mri_repeat
);
6908 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6909 ++input_line_pointer
;
6911 demand_empty_rest_of_line ();
6914 /* Handle the MRI UNTIL pseudo-op. */
6917 s_mri_until (int qual
)
6921 if (mri_control_stack
== NULL
6922 || mri_control_stack
->type
!= mri_repeat
)
6924 as_bad (_("until without repeat"));
6925 ignore_rest_of_line ();
6929 colon (mri_control_stack
->next
);
6931 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6934 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6935 mri_control_stack
->top
, '\0');
6937 colon (mri_control_stack
->bottom
);
6939 input_line_pointer
= s
;
6945 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6946 ++input_line_pointer
;
6949 demand_empty_rest_of_line ();
6952 /* Handle the MRI WHILE pseudo-op. */
6955 s_mri_while (int qual
)
6959 struct mri_control_info
*n
;
6961 s
= input_line_pointer
;
6962 /* We only accept '*' as introduction of comments if preceded by white space
6963 or at first column of a line (I think this can't actually happen here?)
6964 This is important when assembling:
6965 while d0 <ne> 12(a0,d0*2) do
6966 while d0 <ne> #CONST*20 do. */
6967 while (! (is_end_of_line
[(unsigned char) *s
]
6970 && (s
== input_line_pointer
6972 || *(s
-1) == '\t'))))
6975 while (*s
== ' ' || *s
== '\t')
6977 if (s
- input_line_pointer
> 1
6980 if (s
- input_line_pointer
< 2
6981 || strncasecmp (s
- 1, "DO", 2) != 0)
6983 as_bad (_("missing do"));
6984 ignore_rest_of_line ();
6988 n
= push_mri_control (mri_while
);
6992 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6993 s
[1] == '.' ? s
[2] : '\0');
6995 input_line_pointer
= s
+ 1;
6996 if (*input_line_pointer
== '.')
6997 input_line_pointer
+= 2;
7001 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7002 ++input_line_pointer
;
7005 demand_empty_rest_of_line ();
7008 /* Handle the MRI ENDW pseudo-op. */
7011 s_mri_endw (int ignore ATTRIBUTE_UNUSED
)
7015 if (mri_control_stack
== NULL
7016 || mri_control_stack
->type
!= mri_while
)
7018 as_bad (_("endw without while"));
7019 ignore_rest_of_line ();
7023 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
7024 sprintf (buf
, "bra %s", mri_control_stack
->next
);
7028 colon (mri_control_stack
->bottom
);
7034 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
7035 ++input_line_pointer
;
7038 demand_empty_rest_of_line ();
7042 Invocation line includes a switch not recognized by the base assembler.
7043 See if it's a processor-specific option. These are:
7045 -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
7046 -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
7047 Select the architecture. Instructions or features not
7048 supported by the selected architecture cause fatal
7049 errors. More than one may be specified. The default is
7050 -m68020 -m68851 -m68881. Note that -m68008 is a synonym
7051 for -m68000, and -m68882 is a synonym for -m68881.
7052 -[A]m[c]no-68851, -[A]m[c]no-68881
7053 Don't accept 688?1 instructions. (The "c" is kind of silly,
7054 so don't use or document it, but that's the way the parsing
7058 -k Indicates PIC. (Sun 3 only.)
7060 Never turn PC-relative branches into absolute jumps.
7062 Permit `|' to be used in expressions. */
7065 const char *md_shortopts
= "lSA:m:kQ:V";
7067 const char *md_shortopts
= "lSA:m:k";
7070 struct option md_longopts
[] = {
7071 #define OPTION_PIC (OPTION_MD_BASE)
7072 {"pic", no_argument
, NULL
, OPTION_PIC
},
7073 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7074 {"register-prefix-optional", no_argument
, NULL
,
7075 OPTION_REGISTER_PREFIX_OPTIONAL
},
7076 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7077 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
7078 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7079 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
7080 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7081 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
7082 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7083 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
7084 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7085 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
7086 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7087 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
7088 {NULL
, no_argument
, NULL
, 0}
7090 size_t md_longopts_size
= sizeof (md_longopts
);
7093 md_parse_option (int c
, char *arg
)
7097 case 'l': /* -l means keep external to 2 bit offset
7098 rather than 16 bit one. */
7099 flag_short_refs
= 1;
7102 case 'S': /* -S means that jbsr's always turn into
7104 flag_long_jumps
= 1;
7107 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
7108 branches into absolute jumps. */
7109 flag_keep_pcrel
= 1;
7115 /* Intentional fall-through. */
7118 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
7127 if (arg
[0] == 'c' && arg
[1] == '6')
7130 for (i
= 0; i
< n_archs
; i
++)
7131 if (!strcmp (arg
, archs
[i
].name
))
7136 arch
= archs
[i
].arch
;
7139 else if (arch
== m68851
)
7148 if (arg
[0] == 'c' && arg
[1] == '6')
7151 for (i
= 0; i
< n_archs
; i
++)
7152 if (!strcmp (arg
, archs
[i
].name
))
7154 unsigned long arch
= archs
[i
].arch
;
7156 if (cpu_of_arch (arch
))
7157 /* It's a cpu spec. */
7159 current_architecture
&= ~m68000up
;
7160 current_architecture
|= arch
;
7161 current_chip
= archs
[i
].chip
;
7163 else if (arch
== m68881
)
7165 current_architecture
|= m68881
;
7168 else if (arch
== m68851
)
7170 current_architecture
|= m68851
;
7180 as_bad (_("unrecognized architecture specification `%s'"), arg
);
7189 break; /* -pic, Position Independent Code. */
7191 case OPTION_REGISTER_PREFIX_OPTIONAL
:
7192 flag_reg_prefix_optional
= 1;
7193 reg_prefix_optional_seen
= 1;
7196 /* -V: SVR4 argument to print version ID. */
7198 print_version_id ();
7201 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7202 should be emitted or not. FIXME: Not implemented. */
7206 case OPTION_BITWISE_OR
:
7211 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
7213 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
7217 m68k_comment_chars
= n
;
7221 case OPTION_BASE_SIZE_DEFAULT_16
:
7222 m68k_index_width_default
= SIZE_WORD
;
7225 case OPTION_BASE_SIZE_DEFAULT_32
:
7226 m68k_index_width_default
= SIZE_LONG
;
7229 case OPTION_DISP_SIZE_DEFAULT_16
:
7231 m68k_rel32_from_cmdline
= 1;
7234 case OPTION_DISP_SIZE_DEFAULT_32
:
7236 m68k_rel32_from_cmdline
= 1;
7247 md_show_usage (FILE *stream
)
7249 const char *default_cpu
= TARGET_CPU
;
7251 unsigned int default_arch
;
7253 /* Get the canonical name for the default target CPU. */
7254 if (*default_cpu
== 'm')
7256 for (i
= 0; i
< n_archs
; i
++)
7258 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
7260 default_arch
= archs
[i
].arch
;
7261 for (i
= 0; i
< n_archs
; i
++)
7263 if (archs
[i
].arch
== default_arch
7266 default_cpu
= archs
[i
].name
;
7273 fprintf (stream
, _("\
7275 -l use 1 word for refs to undefined symbols [default 2]\n\
7276 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
7277 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
7278 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m521x | -m5249 |\n\
7279 -m528x | -m5307 | -m5407 | -m547x | -m548x | -mcfv4 | -mcfv4e\n\
7280 specify variant of 680X0 architecture [default %s]\n\
7281 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
7282 target has/lacks floating-point coprocessor\n\
7283 [default yes for 68020, 68030, and cpu32]\n"),
7285 fprintf (stream
, _("\
7286 -m68851 | -mno-68851\n\
7287 target has/lacks memory-management unit coprocessor\n\
7288 [default yes for 68020 and up]\n\
7289 -pic, -k generate position independent code\n\
7290 -S turn jbsr into jsr\n\
7291 --pcrel never turn PC-relative branches into absolute jumps\n\
7292 --register-prefix-optional\n\
7293 recognize register names without prefix character\n\
7294 --bitwise-or do not treat `|' as a comment character\n"));
7295 fprintf (stream
, _("\
7296 --base-size-default-16 base reg without size is 16 bits\n\
7297 --base-size-default-32 base reg without size is 32 bits (default)\n\
7298 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7299 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
7304 /* TEST2: Test md_assemble() */
7305 /* Warning, this routine probably doesn't work anymore. */
7309 struct m68k_it the_ins
;
7317 if (!gets (buf
) || !*buf
)
7319 if (buf
[0] == '|' || buf
[1] == '.')
7321 for (cp
= buf
; *cp
; cp
++)
7326 memset (&the_ins
, '\0', sizeof (the_ins
));
7327 m68k_ip (&the_ins
, buf
);
7330 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7334 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7335 for (n
= 0; n
< the_ins
.numo
; n
++)
7336 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7338 print_the_insn (&the_ins
.opcode
[0], stdout
);
7339 (void) putchar ('\n');
7341 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7343 if (the_ins
.operands
[n
].error
)
7345 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7348 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
,
7349 the_ins
.operands
[n
].reg
);
7350 if (the_ins
.operands
[n
].b_const
)
7351 printf ("Constant: '%.*s', ",
7352 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
,
7353 the_ins
.operands
[n
].b_const
);
7354 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
,
7355 the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7356 if (the_ins
.operands
[n
].b_iadd
)
7357 printf ("Iadd: '%.*s',",
7358 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
,
7359 the_ins
.operands
[n
].b_iadd
);
7368 is_label (char *str
)
7372 while (*str
&& *str
!= ' ')
7374 if (str
[-1] == ':' || str
[1] == '=')
7381 /* Possible states for relaxation:
7383 0 0 branch offset byte (bra, etc)
7387 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7391 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7398 /* We have no need to default values of symbols. */
7401 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
7406 /* Round up a section size to the appropriate boundary. */
7408 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
7411 #ifdef BFD_ASSEMBLER
7412 /* For a.out, force the section size to be aligned. If we don't do
7413 this, BFD will align it for us, but it will not write out the
7414 final bytes of the section. This may be a bug in BFD, but it is
7415 easier to fix it here since that is how the other a.out targets
7419 align
= bfd_get_section_alignment (stdoutput
, segment
);
7420 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
7427 /* Exactly what point is a PC-relative offset relative TO?
7428 On the 68k, it is relative to the address of the first extension
7429 word. The difference between the addresses of the offset and the
7430 first extension word is stored in fx_pcrel_adjust. */
7432 md_pcrel_from (fixS
*fixP
)
7436 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7437 sign extend the value here. */
7438 adjust
= ((fixP
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80;
7441 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7444 #ifndef BFD_ASSEMBLER
7448 tc_coff_symbol_emit_hook (symbolS
*ignore ATTRIBUTE_UNUSED
)
7453 tc_coff_sizemachdep (fragS
*frag
)
7455 switch (frag
->fr_subtype
& 0x3)
7474 m68k_elf_final_processing (void)
7476 /* Set file-specific flags if this is a cpu32 processor. */
7477 if (arch_coldfire_fpu (current_architecture
))
7478 elf_elfheader (stdoutput
)->e_flags
|= EF_CFV4E
;
7479 if (cpu_of_arch (current_architecture
) & cpu32
)
7480 elf_elfheader (stdoutput
)->e_flags
|= EF_CPU32
;
7481 else if ((cpu_of_arch (current_architecture
) & m68000up
)
7482 && !(cpu_of_arch (current_architecture
) & m68020up
))
7483 elf_elfheader (stdoutput
)->e_flags
|= EF_M68000
;
7488 tc_m68k_regname_to_dw2regnum (const char *regname
)
7490 unsigned int regnum
;
7491 static const char *const regnames
[] =
7493 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7494 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7495 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7499 for (regnum
= 0; regnum
< ARRAY_SIZE (regnames
); regnum
++)
7500 if (strcmp (regname
, regnames
[regnum
]) == 0)
7507 tc_m68k_frame_initial_instructions (void)
7509 static int sp_regno
= -1;
7512 sp_regno
= tc_m68k_regname_to_dw2regnum ("sp");
7514 cfi_add_CFA_def_cfa (sp_regno
, -DWARF2_CIE_DATA_ALIGNMENT
);
7515 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN
, DWARF2_CIE_DATA_ALIGNMENT
);