1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006 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 /* Are we trying to generate PIC code? If so, absolute references
74 ought to be made into linkage table references or pc-relative
75 references. Not implemented. For ELF there are other means
76 to denote pic relocations. */
79 static int flag_short_refs
; /* -l option. */
80 static int flag_long_jumps
; /* -S option. */
81 static int flag_keep_pcrel
; /* --pcrel option. */
83 #ifdef REGISTER_PREFIX_OPTIONAL
84 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
86 int flag_reg_prefix_optional
;
89 /* Whether --register-prefix-optional was used on the command line. */
90 static int reg_prefix_optional_seen
;
92 /* The floating point coprocessor to use by default. */
93 static enum m68k_register m68k_float_copnum
= COP1
;
95 /* If this is non-zero, then references to number(%pc) will be taken
96 to refer to number, rather than to %pc + number. */
97 static int m68k_abspcadd
;
99 /* If this is non-zero, then the quick forms of the move, add, and sub
100 instructions are used when possible. */
101 static int m68k_quick
= 1;
103 /* If this is non-zero, then if the size is not specified for a base
104 or outer displacement, the assembler assumes that the size should
106 static int m68k_rel32
= 1;
108 /* This is non-zero if m68k_rel32 was set from the command line. */
109 static int m68k_rel32_from_cmdline
;
111 /* The default width to use for an index register when using a base
113 static enum m68k_size m68k_index_width_default
= SIZE_LONG
;
115 /* We want to warn if any text labels are misaligned. In order to get
116 the right line number, we need to record the line number for each
120 struct label_line
*next
;
127 /* The list of labels. */
129 static struct label_line
*labels
;
131 /* The current label. */
133 static struct label_line
*current_label
;
135 /* Pointer to list holding the opcodes sorted by name. */
136 static struct m68k_opcode
const ** m68k_sorted_opcodes
;
138 /* Its an arbitrary name: This means I don't approve of it.
140 static struct obstack robyn
;
144 const char *m_operands
;
145 unsigned long m_opcode
;
149 struct m68k_incant
*m_next
;
152 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
153 #define gettwo(x) (((x)->m_opcode)&0xffff)
155 static const enum m68k_register m68000_control_regs
[] = { 0 };
156 static const enum m68k_register m68010_control_regs
[] = {
160 static const enum m68k_register m68020_control_regs
[] = {
161 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
164 static const enum m68k_register m68040_control_regs
[] = {
165 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
166 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
169 static const enum m68k_register m68060_control_regs
[] = {
170 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
171 USP
, VBR
, URP
, SRP
, PCR
,
174 static const enum m68k_register mcf_control_regs
[] = {
175 CACR
, TC
, ACR0
, ACR1
, ACR2
, ACR3
, VBR
, ROMBAR
,
176 RAMBAR0
, RAMBAR1
, MBAR
,
179 static const enum m68k_register mcf5208_control_regs
[] = {
180 CACR
, ACR0
, ACR1
, VBR
, RAMBAR1
,
183 static const enum m68k_register mcf5213_control_regs
[] = {
184 VBR
, RAMBAR
, FLASHBAR
,
187 static const enum m68k_register mcf5329_control_regs
[] = {
188 CACR
, ACR0
, ACR1
, VBR
, RAMBAR
,
191 static const enum m68k_register mcf5249_control_regs
[] = {
192 CACR
, ACR0
, ACR1
, VBR
, RAMBAR0
, RAMBAR1
, MBAR
, MBAR2
,
195 static const enum m68k_register mcf528x_control_regs
[] = {
196 CACR
, ACR0
, ACR1
, VBR
, FLASHBAR
, RAMBAR
,
199 static const enum m68k_register mcfv4e_control_regs
[] = {
200 CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
, VBR
, PC
, ROMBAR
,
201 ROMBAR1
, RAMBAR0
, RAMBAR1
, MPCR
, EDRAMBAR
, SECMBAR
, MBAR
, MBAR0
, MBAR1
,
202 PCR1U0
, PCR1L0
, PCR1U1
, PCR1L1
, PCR2U0
, PCR2L0
, PCR2U1
, PCR2L1
,
203 PCR3U0
, PCR3L0
, PCR3U1
, PCR3L1
,
206 #define cpu32_control_regs m68010_control_regs
208 static const enum m68k_register
*control_regs
;
210 /* Internal form of a 68020 instruction. */
214 const char *args
; /* List of opcode info. */
217 int numo
; /* Number of shorts in opcode. */
220 struct m68k_op operands
[6];
222 int nexp
; /* Number of exprs in use. */
223 struct m68k_exp exprs
[4];
225 int nfrag
; /* Number of frags we have to produce. */
228 int fragoff
; /* Where in the current opcode the frag ends. */
235 int nrel
; /* Num of reloc strucs in use. */
242 /* In a pc relative address the difference between the address
243 of the offset and the address that the offset is relative
244 to. This depends on the addressing mode. Basically this
245 is the value to put in the offset field to address the
246 first byte of the offset, without regarding the special
247 significance of some values (in the branch instruction, for
251 /* Whether this expression needs special pic relocation, and if
253 enum pic_relocation pic_reloc
;
256 reloc
[5]; /* Five is enough??? */
259 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a))
260 #define float_of_arch(x) ((x) & mfloat)
261 #define mmu_of_arch(x) ((x) & mmmu)
262 #define arch_coldfire_p(x) ((x) & mcfisa_a)
263 #define arch_coldfire_fpu(x) ((x) & cfloat)
265 /* Macros for determining if cpu supports a specific addressing mode. */
266 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcfisa_b))
268 static struct m68k_it the_ins
; /* The instruction being assembled. */
270 #define op(ex) ((ex)->exp.X_op)
271 #define adds(ex) ((ex)->exp.X_add_symbol)
272 #define subs(ex) ((ex)->exp.X_op_symbol)
273 #define offs(ex) ((ex)->exp.X_add_number)
275 /* Macros for adding things to the m68k_it struct. */
276 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
278 /* Like addword, but goes BEFORE general operands. */
281 insop (int w
, const struct m68k_incant
*opcode
)
284 for (z
= the_ins
.numo
; z
> opcode
->m_codenum
; --z
)
285 the_ins
.opcode
[z
] = the_ins
.opcode
[z
- 1];
286 for (z
= 0; z
< the_ins
.nrel
; z
++)
287 the_ins
.reloc
[z
].n
+= 2;
288 for (z
= 0; z
< the_ins
.nfrag
; z
++)
289 the_ins
.fragb
[z
].fragoff
++;
290 the_ins
.opcode
[opcode
->m_codenum
] = w
;
294 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
297 add_fix (int width
, struct m68k_exp
*exp
, int pc_rel
, int pc_fix
)
299 the_ins
.reloc
[the_ins
.nrel
].n
= (width
== 'B' || width
== '3'
300 ? the_ins
.numo
* 2 - 1
302 ? the_ins
.numo
* 2 + 1
303 : the_ins
.numo
* 2));
304 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
305 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
306 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
308 the_ins
.reloc
[the_ins
.nrel
].pic_reloc
= exp
->pic_reloc
;
310 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
313 /* Cause an extra frag to be generated here, inserting up to 10 bytes
314 (that value is chosen in the frag_var call in md_assemble). TYPE
315 is the subtype of the frag to be generated; its primary type is
316 rs_machine_dependent.
318 The TYPE parameter is also used by md_convert_frag_1 and
319 md_estimate_size_before_relax. The appropriate type of fixup will
320 be emitted by md_convert_frag_1.
322 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
324 add_frag (symbolS
*add
, offsetT off
, int type
)
326 the_ins
.fragb
[the_ins
.nfrag
].fragoff
= the_ins
.numo
;
327 the_ins
.fragb
[the_ins
.nfrag
].fadd
= add
;
328 the_ins
.fragb
[the_ins
.nfrag
].foff
= off
;
329 the_ins
.fragb
[the_ins
.nfrag
++].fragty
= type
;
333 (op (ex) != O_constant && op (ex) != O_big)
335 static char *crack_operand (char *str
, struct m68k_op
*opP
);
336 static int get_num (struct m68k_exp
*exp
, int ok
);
337 static int reverse_16_bits (int in
);
338 static int reverse_8_bits (int in
);
339 static void install_gen_operand (int mode
, int val
);
340 static void install_operand (int mode
, int val
);
341 static void s_bss (int);
342 static void s_data1 (int);
343 static void s_data2 (int);
344 static void s_even (int);
345 static void s_proc (int);
346 static void s_chip (int);
347 static void s_fopt (int);
348 static void s_opt (int);
349 static void s_reg (int);
350 static void s_restore (int);
351 static void s_save (int);
352 static void s_mri_if (int);
353 static void s_mri_else (int);
354 static void s_mri_endi (int);
355 static void s_mri_break (int);
356 static void s_mri_next (int);
357 static void s_mri_for (int);
358 static void s_mri_endf (int);
359 static void s_mri_repeat (int);
360 static void s_mri_until (int);
361 static void s_mri_while (int);
362 static void s_mri_endw (int);
363 static void s_m68k_cpu (int);
364 static void s_m68k_arch (int);
368 unsigned long arch
; /* Architecture features. */
369 unsigned long chip
; /* Specific chip */
370 const char *name
; /* Name */
374 /* We hold flags for features explicitly enabled and explicitly
376 static int current_architecture
;
377 static int not_current_architecture
;
378 static int current_chip
;
379 static const struct m68k_cpu
*selected_arch
;
380 static const struct m68k_cpu
*selected_cpu
;
381 static int initialized
;
383 /* Architecture models. */
384 static const struct m68k_cpu m68k_archs
[] =
386 {m68000
, cpu_m68000
, "68000", 0},
387 {m68010
, cpu_m68010
, "68010", 0},
388 {m68020
|m68881
|m68851
, cpu_m68020
, "68020", 0},
389 {m68030
|m68881
|m68851
, cpu_m68030
, "68030", 0},
390 {m68040
, cpu_m68040
, "68040", 0},
391 {m68060
, cpu_m68060
, "68060", 0},
392 {cpu32
|m68881
, cpu_cpu32
, "cpu32", 0},
393 {mcfisa_a
|mcfhwdiv
, 0, "isaa", 0},
394 {mcfisa_a
|mcfhwdiv
|mcfisa_aa
, 0, "isaaplus", 0},
395 {mcfisa_a
|mcfhwdiv
|mcfisa_b
, 0, "isab", 0},
396 {mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
397 cpu_cf547x
, "cfv4e", 0},
401 /* Architecture extensions. */
402 static const struct m68k_cpu m68k_extensions
[] =
404 {m68851
, 0, "68851", 0},
405 {m68881
, 0, "68881", 0},
406 {m68881
, 0, "68882", 0},
408 {mcfhwdiv
, 0, "div", 1},
409 {mcfusp
, 0, "usp", 1},
410 {cfloat
, 0, "float", 1},
411 {mcfmac
, 0, "mac", 1},
412 {mcfemac
, 0, "emac", 1},
418 static const struct m68k_cpu m68k_cpus
[] =
420 { m68000
, cpu_m68000
, "68000", 0},
421 { m68010
, cpu_m68010
, "68010", 0},
422 { m68020
|m68881
|m68851
, cpu_m68020
, "68020", 0},
423 { m68030
|m68881
|m68851
, cpu_m68030
, "68030", 0},
424 { m68040
, cpu_m68040
, "68040", 0},
425 { m68060
, cpu_m68060
, "68060", 0},
426 { cpu32
|m68881
, cpu_cpu32
, "cpu32", 0},
427 { mcfisa_a
, cpu_cf5200
, "5200", 0},
428 { mcfisa_a
|mcfhwdiv
|mcfmac
, cpu_cf5206e
, "5206e", 0},
429 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
, cpu_cf5208
, "5208", 0},
430 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
, cpu_cf5213
, "5213", 0},
431 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
,cpu_cf521x
, "521x", 0},
432 { mcfisa_a
|mcfhwdiv
|mcfemac
, cpu_cf5249
, "5249", 0},
433 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
|mcfusp
,cpu_cf528x
, "528x", 0},
434 { mcfisa_a
|mcfhwdiv
|mcfmac
, cpu_cf5307
, "5307", 0},
435 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, cpu_cf5329
, "5329", 0},
436 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
, cpu_cf5407
, "5407",0},
437 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
438 cpu_cf547x
, "547x", 0},
439 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
440 cpu_cf548x
, "548x", 0},
441 /* Aliases (effectively, so far as gas is concerned) for the above
443 { m68020
|m68881
|m68851
, cpu_m68020
, "68k", 1},
444 { m68000
, cpu_m68000
, "68008", 1},
445 { m68000
, cpu_m68000
, "68302", 1},
446 { m68000
, cpu_m68000
, "68306", 1},
447 { m68000
, cpu_m68000
, "68307", 1},
448 { m68000
, cpu_m68000
, "68322", 1},
449 { m68000
, cpu_m68000
, "68356", 1},
450 { m68000
, cpu_m68000
, "68ec000", 1},
451 { m68000
, cpu_m68000
, "68hc000", 1},
452 { m68000
, cpu_m68000
, "68hc001", 1},
453 { m68020
|m68881
|m68851
, cpu_m68020
, "68ec020", 1},
454 { m68030
|m68881
|m68851
, cpu_m68030
, "68ec030", 1},
455 { m68040
, cpu_m68040
, "68ec040", 1},
456 { m68060
, cpu_m68060
, "68ec060", 1},
457 { cpu32
|m68881
, cpu_cpu32
, "68330", 1},
458 { cpu32
|m68881
, cpu_cpu32
, "68331", 1},
459 { cpu32
|m68881
, cpu_cpu32
, "68332", 1},
460 { cpu32
|m68881
, cpu_cpu32
, "68333", 1},
461 { cpu32
|m68881
, cpu_cpu32
, "68334", 1},
462 { cpu32
|m68881
, cpu_cpu32
, "68336", 1},
463 { cpu32
|m68881
, cpu_cpu32
, "68340", 1},
464 { cpu32
|m68881
, cpu_cpu32
, "68341", 1},
465 { cpu32
|m68881
, cpu_cpu32
, "68349", 1},
466 { cpu32
|m68881
, cpu_cpu32
, "68360", 1},
467 { mcfisa_a
, cpu_cf5200
, "5202", 1},
468 { mcfisa_a
, cpu_cf5200
, "5204", 1},
469 { mcfisa_a
, cpu_cf5200
, "5206", 1},
470 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
, cpu_cf5208
, "5207", 1},
471 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
, cpu_cf5213
, "5211", 1},
472 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfmac
, cpu_cf5213
, "5212", 1},
473 { mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfemac
, cpu_cf521x
, "5214", 1},
474 { mcfisa_a
|mcfhwdiv
|mcfisa_aa
|mcfemac
, cpu_cf521x
, "5216", 1},
475 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, cpu_cf5329
, "5327", 1},
476 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, cpu_cf5329
, "5328", 1},
477 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, cpu_cf528x
, "5280", 1},
478 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, cpu_cf528x
, "5281", 1},
479 { mcfisa_a
|mcfisa_aa
|mcfhwdiv
|mcfemac
, cpu_cf528x
, "5282", 1},
480 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfmac
, cpu_cf5407
, "cfv4", 1 },
481 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
482 cpu_cf547x
, "cfv4e", 1 },
483 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
484 cpu_cf547x
, "5470", 1 },
485 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
486 cpu_cf547x
, "5471", 1 },
487 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
488 cpu_cf547x
, "5472", 1 },
489 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
490 cpu_cf547x
, "5473", 1 },
491 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
492 cpu_cf547x
, "5474", 1 },
493 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
494 cpu_cf547x
, "5475", 1 },
495 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
496 cpu_cf548x
, "5480", 1 },
497 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
498 cpu_cf548x
, "5481", 1 },
499 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
500 cpu_cf548x
, "5482", 1 },
501 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
502 cpu_cf548x
, "5483", 1 },
503 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
504 cpu_cf548x
, "5484", 1 },
505 { mcfisa_a
|mcfhwdiv
|mcfisa_b
|mcfemac
|mcfusp
|cfloat
,
506 cpu_cf548x
, "5485", 1 },
510 #define CPU_ALLOW_MC 1
511 #define CPU_ALLOW_NEGATION 4
513 static const struct m68k_cpu
*m68k_lookup_cpu
514 (const char *, const struct m68k_cpu
*, int, int *);
515 static int m68k_set_arch (const char *, int, int);
516 static int m68k_set_cpu (const char *, int, int);
517 static int m68k_set_extension (const char *, int, int);
518 static void m68k_init_arch (void);
520 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
521 architecture and we have a lot of relaxation modes. */
523 /* Macros used in the relaxation code. */
524 #define TAB(x,y) (((x) << 2) + (y))
525 #define TABTYPE(x) ((x) >> 2)
527 /* Relaxation states. */
533 /* Here are all the relaxation modes we support. First we can relax ordinary
534 branches. On 68020 and higher and on CPU32 all branch instructions take
535 three forms, so on these CPUs all branches always remain as such. When we
536 have to expand to the LONG form on a 68000, though, we substitute an
537 absolute jump instead. This is a direct replacement for unconditional
538 branches and a branch over a jump for conditional branches. However, if the
539 user requires PIC and disables this with --pcrel, we can only relax between
540 BYTE and SHORT forms, punting if that isn't enough. This gives us four
541 different relaxation modes for branches: */
543 #define BRANCHBWL 0 /* Branch byte, word, or long. */
544 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
545 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
546 #define BRANCHBW 3 /* Branch byte or word. */
548 /* We also relax coprocessor branches and DBcc's. All CPUs that support
549 coprocessor branches support them in word and long forms, so we have only
550 one relaxation mode for them. DBcc's are word only on all CPUs. We can
551 relax them to the LONG form with a branch-around sequence. This sequence
552 can use a long branch (if available) or an absolute jump (if acceptable).
553 This gives us two relaxation modes. If long branches are not available and
554 absolute jumps are not acceptable, we don't relax DBcc's. */
556 #define FBRANCH 4 /* Coprocessor branch. */
557 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
558 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
560 /* That's all for instruction relaxation. However, we also relax PC-relative
561 operands. Specifically, we have three operand relaxation modes. On the
562 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
563 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
564 two. Also PC+displacement+index operands in their simple form (with a non-
565 suppressed index without memory indirection) are supported on all CPUs, but
566 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
567 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
568 form of the PC+displacement+index operand. Finally, some absolute operands
569 can be relaxed down to 16-bit PC-relative. */
571 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
572 #define PCINDEX 8 /* PC + displacement + index. */
573 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
575 /* Note that calls to frag_var need to specify the maximum expansion
576 needed; this is currently 10 bytes for DBCC. */
579 How far Forward this mode will reach:
580 How far Backward this mode will reach:
581 How many bytes this mode will add to the size of the frag
582 Which mode to go to if the offset won't fit in this one
584 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
585 relax_typeS md_relax_table
[] =
587 { 127, -128, 0, TAB (BRANCHBWL
, SHORT
) },
588 { 32767, -32768, 2, TAB (BRANCHBWL
, LONG
) },
592 { 127, -128, 0, TAB (BRABSJUNC
, SHORT
) },
593 { 32767, -32768, 2, TAB (BRABSJUNC
, LONG
) },
597 { 127, -128, 0, TAB (BRABSJCOND
, SHORT
) },
598 { 32767, -32768, 2, TAB (BRABSJCOND
, LONG
) },
602 { 127, -128, 0, TAB (BRANCHBW
, SHORT
) },
607 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
608 { 32767, -32768, 2, TAB (FBRANCH
, LONG
) },
612 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
613 { 32767, -32768, 2, TAB (DBCCLBR
, LONG
) },
617 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
618 { 32767, -32768, 2, TAB (DBCCABSJ
, LONG
) },
622 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
623 { 32767, -32768, 2, TAB (PCREL1632
, LONG
) },
627 { 125, -130, 0, TAB (PCINDEX
, SHORT
) },
628 { 32765, -32770, 2, TAB (PCINDEX
, LONG
) },
632 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
633 { 32767, -32768, 2, TAB (ABSTOPCREL
, LONG
) },
638 /* These are the machine dependent pseudo-ops. These are included so
639 the assembler can work on the output from the SUN C compiler, which
642 /* This table describes all the machine specific pseudo-ops the assembler
643 has to support. The fields are:
644 pseudo-op name without dot
645 function to call to execute this pseudo-op
646 Integer arg to pass to the function. */
647 const pseudo_typeS md_pseudo_table
[] =
649 {"data1", s_data1
, 0},
650 {"data2", s_data2
, 0},
653 {"skip", s_space
, 0},
655 #if defined (TE_SUN3) || defined (OBJ_ELF)
656 {"align", s_align_bytes
, 0},
659 {"swbeg", s_ignore
, 0},
661 {"extend", float_cons
, 'x'},
662 {"ldouble", float_cons
, 'x'},
664 {"arch", s_m68k_arch
, 0},
665 {"cpu", s_m68k_cpu
, 0},
667 /* The following pseudo-ops are supported for MRI compatibility. */
669 {"comline", s_space
, 1},
671 {"mask2", s_ignore
, 0},
674 {"restore", s_restore
, 0},
678 {"if.b", s_mri_if
, 'b'},
679 {"if.w", s_mri_if
, 'w'},
680 {"if.l", s_mri_if
, 'l'},
681 {"else", s_mri_else
, 0},
682 {"else.s", s_mri_else
, 's'},
683 {"else.l", s_mri_else
, 'l'},
684 {"endi", s_mri_endi
, 0},
685 {"break", s_mri_break
, 0},
686 {"break.s", s_mri_break
, 's'},
687 {"break.l", s_mri_break
, 'l'},
688 {"next", s_mri_next
, 0},
689 {"next.s", s_mri_next
, 's'},
690 {"next.l", s_mri_next
, 'l'},
691 {"for", s_mri_for
, 0},
692 {"for.b", s_mri_for
, 'b'},
693 {"for.w", s_mri_for
, 'w'},
694 {"for.l", s_mri_for
, 'l'},
695 {"endf", s_mri_endf
, 0},
696 {"repeat", s_mri_repeat
, 0},
697 {"until", s_mri_until
, 0},
698 {"until.b", s_mri_until
, 'b'},
699 {"until.w", s_mri_until
, 'w'},
700 {"until.l", s_mri_until
, 'l'},
701 {"while", s_mri_while
, 0},
702 {"while.b", s_mri_while
, 'b'},
703 {"while.w", s_mri_while
, 'w'},
704 {"while.l", s_mri_while
, 'l'},
705 {"endw", s_mri_endw
, 0},
710 /* The mote pseudo ops are put into the opcode table, since they
711 don't start with a . they look like opcodes to gas. */
713 const pseudo_typeS mote_pseudo_table
[] =
726 {"xdef", s_globl
, 0},
728 {"align", s_align_bytes
, 0},
730 {"align", s_align_ptwo
, 0},
733 {"sect", obj_coff_section
, 0},
734 {"section", obj_coff_section
, 0},
739 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
740 gives identical results to a 32-bit host. */
741 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
742 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
744 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
745 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
746 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
747 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
749 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
750 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
751 #define islong(x) (1)
753 static char notend_table
[256];
754 static char alt_notend_table
[256];
756 (! (notend_table[(unsigned char) *s] \
758 && alt_notend_table[(unsigned char) s[1]])))
760 /* Return a human readable string holding the list of chips that are
761 valid for a particular architecture, suppressing aliases (unless
762 there is only one of them). */
765 find_cf_chip (int architecture
)
767 static char buf
[1024];
768 int i
, j
, n_chips
, n_alias
;
772 cp
= buf
+ strlen (buf
);
774 for (i
= 0, n_chips
= 0, n_alias
= 0; m68k_cpus
[i
].name
; ++i
)
775 if (m68k_cpus
[i
].arch
& architecture
)
778 if (m68k_cpus
[i
].alias
)
783 as_fatal (_("no matching ColdFire architectures found"));
788 for (i
= 0, j
= 0; m68k_cpus
[i
].name
&& j
< n_chips
; ++i
)
789 if (m68k_cpus
[i
].arch
& architecture
)
793 if ((j
== n_chips
- 1 && !(n_alias
> 1)) || ! n_alias
)
797 strncpy (cp
, _(" or "), (sizeof (buf
) - (cp
- buf
)));
802 strncpy (cp
, _(", or "), (sizeof (buf
) - (cp
- buf
)));
808 strncpy (cp
, ", ", (sizeof (buf
) - (cp
- buf
)));
812 strncpy (cp
, m68k_cpus
[i
].name
, (sizeof (buf
) - (cp
- buf
)));
819 strncpy (cp
, _(", or aliases"), (sizeof (buf
) - (cp
- buf
)));
823 strncpy (cp
, ")", (sizeof (buf
) - (cp
- buf
)));
830 /* Return zero if the reference to SYMBOL from within the same segment may
833 /* On an ELF system, we can't relax an externally visible symbol,
834 because it may be overridden by a shared library. However, if
835 TARGET_OS is "elf", then we presume that we are assembling for an
836 embedded system, in which case we don't have to worry about shared
837 libraries, and we can relax any external sym. */
839 #define relaxable_symbol(symbol) \
840 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
841 || S_IS_WEAK (symbol)))
843 /* Compute the relocation code for a fixup of SIZE bytes, using pc
844 relative relocation if PCREL is non-zero. PIC says whether a special
845 pic relocation was requested. */
847 static bfd_reloc_code_real_type
848 get_reloc_code (int size
, int pcrel
, enum pic_relocation pic
)
856 return BFD_RELOC_8_GOT_PCREL
;
858 return BFD_RELOC_16_GOT_PCREL
;
860 return BFD_RELOC_32_GOT_PCREL
;
868 return BFD_RELOC_8_GOTOFF
;
870 return BFD_RELOC_16_GOTOFF
;
872 return BFD_RELOC_32_GOTOFF
;
880 return BFD_RELOC_8_PLT_PCREL
;
882 return BFD_RELOC_16_PLT_PCREL
;
884 return BFD_RELOC_32_PLT_PCREL
;
892 return BFD_RELOC_8_PLTOFF
;
894 return BFD_RELOC_16_PLTOFF
;
896 return BFD_RELOC_32_PLTOFF
;
906 return BFD_RELOC_8_PCREL
;
908 return BFD_RELOC_16_PCREL
;
910 return BFD_RELOC_32_PCREL
;
930 as_bad (_("Can not do %d byte pc-relative relocation"), size
);
932 as_bad (_("Can not do %d byte pc-relative pic relocation"), size
);
937 as_bad (_("Can not do %d byte relocation"), size
);
939 as_bad (_("Can not do %d byte pic relocation"), size
);
942 return BFD_RELOC_NONE
;
945 /* Here we decide which fixups can be adjusted to make them relative
946 to the beginning of the section instead of the symbol. Basically
947 we need to make sure that the dynamic relocations are done
948 correctly, so in some cases we force the original symbol to be
951 tc_m68k_fix_adjustable (fixS
*fixP
)
953 /* Adjust_reloc_syms doesn't know about the GOT. */
954 switch (fixP
->fx_r_type
)
956 case BFD_RELOC_8_GOT_PCREL
:
957 case BFD_RELOC_16_GOT_PCREL
:
958 case BFD_RELOC_32_GOT_PCREL
:
959 case BFD_RELOC_8_GOTOFF
:
960 case BFD_RELOC_16_GOTOFF
:
961 case BFD_RELOC_32_GOTOFF
:
962 case BFD_RELOC_8_PLT_PCREL
:
963 case BFD_RELOC_16_PLT_PCREL
:
964 case BFD_RELOC_32_PLT_PCREL
:
965 case BFD_RELOC_8_PLTOFF
:
966 case BFD_RELOC_16_PLTOFF
:
967 case BFD_RELOC_32_PLTOFF
:
970 case BFD_RELOC_VTABLE_INHERIT
:
971 case BFD_RELOC_VTABLE_ENTRY
:
981 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
983 #define relaxable_symbol(symbol) 1
988 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
991 bfd_reloc_code_real_type code
;
993 /* If the tcbit is set, then this was a fixup of a negative value
994 that was never resolved. We do not have a reloc to handle this,
995 so just return. We assume that other code will have detected this
996 situation and produced a helpful error message, so we just tell the
997 user that the reloc cannot be produced. */
1001 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1002 _("Unable to produce reloc against symbol '%s'"),
1003 S_GET_NAME (fixp
->fx_addsy
));
1007 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
1009 code
= fixp
->fx_r_type
;
1011 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1012 that fixup_segment converted a non-PC relative reloc into a
1013 PC relative reloc. In such a case, we need to convert the
1020 code
= BFD_RELOC_8_PCREL
;
1023 code
= BFD_RELOC_16_PCREL
;
1026 code
= BFD_RELOC_32_PCREL
;
1028 case BFD_RELOC_8_PCREL
:
1029 case BFD_RELOC_16_PCREL
:
1030 case BFD_RELOC_32_PCREL
:
1031 case BFD_RELOC_8_GOT_PCREL
:
1032 case BFD_RELOC_16_GOT_PCREL
:
1033 case BFD_RELOC_32_GOT_PCREL
:
1034 case BFD_RELOC_8_GOTOFF
:
1035 case BFD_RELOC_16_GOTOFF
:
1036 case BFD_RELOC_32_GOTOFF
:
1037 case BFD_RELOC_8_PLT_PCREL
:
1038 case BFD_RELOC_16_PLT_PCREL
:
1039 case BFD_RELOC_32_PLT_PCREL
:
1040 case BFD_RELOC_8_PLTOFF
:
1041 case BFD_RELOC_16_PLTOFF
:
1042 case BFD_RELOC_32_PLTOFF
:
1045 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1046 _("Cannot make %s relocation PC relative"),
1047 bfd_get_reloc_code_name (code
));
1053 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1054 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1056 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1057 MAP (1, 0, BFD_RELOC_8
);
1058 MAP (2, 0, BFD_RELOC_16
);
1059 MAP (4, 0, BFD_RELOC_32
);
1060 MAP (1, 1, BFD_RELOC_8_PCREL
);
1061 MAP (2, 1, BFD_RELOC_16_PCREL
);
1062 MAP (4, 1, BFD_RELOC_32_PCREL
);
1070 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1071 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1072 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1073 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1076 reloc
->addend
= fixp
->fx_addnumber
;
1080 if (!fixp
->fx_pcrel
)
1081 reloc
->addend
= fixp
->fx_addnumber
;
1083 reloc
->addend
= (section
->vma
1084 /* Explicit sign extension in case char is
1086 + ((fixp
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80
1087 + fixp
->fx_addnumber
1088 + md_pcrel_from (fixp
));
1091 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1092 assert (reloc
->howto
!= 0);
1097 /* Handle of the OPCODE hash table. NULL means any use before
1098 m68k_ip_begin() will crash. */
1099 static struct hash_control
*op_hash
;
1101 /* Assemble an m68k instruction. */
1104 m68k_ip (char *instring
)
1107 register struct m68k_op
*opP
;
1108 register const struct m68k_incant
*opcode
;
1109 register const char *s
;
1110 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1111 char *pdot
, *pdotmove
;
1112 enum m68k_size siz1
, siz2
;
1116 struct m68k_op operands_backup
[6];
1117 LITTLENUM_TYPE words
[6];
1118 LITTLENUM_TYPE
*wordp
;
1119 unsigned long ok_arch
= 0;
1121 if (*instring
== ' ')
1122 instring
++; /* Skip leading whitespace. */
1124 /* Scan up to end of operation-code, which MUST end in end-of-string
1125 or exactly 1 space. */
1127 for (p
= instring
; *p
!= '\0'; p
++)
1137 the_ins
.error
= _("No operator");
1141 /* p now points to the end of the opcode name, probably whitespace.
1142 Make sure the name is null terminated by clobbering the
1143 whitespace, look it up in the hash table, then fix it back.
1144 Remove a dot, first, since the opcode tables have none. */
1147 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1148 *pdotmove
= pdotmove
[1];
1154 opcode
= (const struct m68k_incant
*) hash_find (op_hash
, instring
);
1159 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1160 *pdotmove
= pdotmove
[-1];
1167 the_ins
.error
= _("Unknown operator");
1171 /* Found a legitimate opcode, start matching operands. */
1175 if (opcode
->m_operands
== 0)
1177 char *old
= input_line_pointer
;
1179 input_line_pointer
= p
;
1180 /* Ahh - it's a motorola style psuedo op. */
1181 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1182 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1183 input_line_pointer
= old
;
1189 if (flag_mri
&& opcode
->m_opnum
== 0)
1191 /* In MRI mode, random garbage is allowed after an instruction
1192 which accepts no operands. */
1193 the_ins
.args
= opcode
->m_operands
;
1194 the_ins
.numargs
= opcode
->m_opnum
;
1195 the_ins
.numo
= opcode
->m_codenum
;
1196 the_ins
.opcode
[0] = getone (opcode
);
1197 the_ins
.opcode
[1] = gettwo (opcode
);
1201 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1203 p
= crack_operand (p
, opP
);
1207 the_ins
.error
= opP
->error
;
1212 opsfound
= opP
- &the_ins
.operands
[0];
1214 /* This ugly hack is to support the floating pt opcodes in their
1215 standard form. Essentially, we fake a first enty of type COP#1 */
1216 if (opcode
->m_operands
[0] == 'I')
1220 for (n
= opsfound
; n
> 0; --n
)
1221 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1223 memset (&the_ins
.operands
[0], '\0', sizeof (the_ins
.operands
[0]));
1224 the_ins
.operands
[0].mode
= CONTROL
;
1225 the_ins
.operands
[0].reg
= m68k_float_copnum
;
1229 /* We've got the operands. Find an opcode that'll accept them. */
1232 /* If we didn't get the right number of ops, or we have no
1233 common model with this pattern then reject this pattern. */
1235 ok_arch
|= opcode
->m_arch
;
1236 if (opsfound
!= opcode
->m_opnum
1237 || ((opcode
->m_arch
& current_architecture
) == 0))
1243 /* Make a copy of the operands of this insn so that
1244 we can modify them safely, should we want to. */
1245 assert (opsfound
<= (int) ARRAY_SIZE (operands_backup
));
1246 for (i
= 0; i
< opsfound
; i
++)
1247 operands_backup
[i
] = the_ins
.operands
[i
];
1249 for (s
= opcode
->m_operands
, opP
= &operands_backup
[0];
1253 /* Warning: this switch is huge! */
1254 /* I've tried to organize the cases into this order:
1255 non-alpha first, then alpha by letter. Lower-case
1256 goes directly before uppercase counterpart. */
1257 /* Code with multiple case ...: gets sorted by the lowest
1258 case ... it belongs to. I hope this makes sense. */
1364 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1381 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1400 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1410 if (opP
->mode
!= IMMED
)
1412 else if (s
[1] == 'b'
1413 && ! isvar (&opP
->disp
)
1414 && (opP
->disp
.exp
.X_op
!= O_constant
1415 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
1417 else if (s
[1] == 'B'
1418 && ! isvar (&opP
->disp
)
1419 && (opP
->disp
.exp
.X_op
!= O_constant
1420 || ! issbyte (opP
->disp
.exp
.X_add_number
)))
1422 else if (s
[1] == 'w'
1423 && ! isvar (&opP
->disp
)
1424 && (opP
->disp
.exp
.X_op
!= O_constant
1425 || ! isword (opP
->disp
.exp
.X_add_number
)))
1427 else if (s
[1] == 'W'
1428 && ! isvar (&opP
->disp
)
1429 && (opP
->disp
.exp
.X_op
!= O_constant
1430 || ! issword (opP
->disp
.exp
.X_add_number
)))
1436 if (opP
->mode
!= IMMED
)
1441 if (opP
->mode
== AREG
1442 || opP
->mode
== CONTROL
1443 || opP
->mode
== FPREG
1444 || opP
->mode
== IMMED
1445 || opP
->mode
== REGLST
1446 || (opP
->mode
!= ABSL
1448 || opP
->reg
== ZPC
)))
1453 if (opP
->mode
== CONTROL
1454 || opP
->mode
== FPREG
1455 || opP
->mode
== REGLST
1456 || opP
->mode
== IMMED
1457 || (opP
->mode
!= ABSL
1459 || opP
->reg
== ZPC
)))
1487 if (opP
->mode
== CONTROL
1488 || opP
->mode
== FPREG
1489 || opP
->mode
== REGLST
)
1494 if (opP
->mode
!= AINC
)
1499 if (opP
->mode
!= ADEC
)
1549 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1570 case '~': /* For now! (JF FOO is this right?) */
1592 if (opP
->mode
!= CONTROL
1593 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1598 if (opP
->mode
!= AREG
)
1603 if (opP
->mode
!= AINDR
)
1608 if (opP
->mode
!= AINDR
&& opP
->mode
!= AINC
&& opP
->mode
!= ADEC
1609 && (opP
->mode
!= DISP
1611 || opP
->reg
> ADDR7
))
1616 if (opP
->mode
!= ABSL
1618 && strncmp (instring
, "jbsr", 4) == 0))
1641 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1646 if (opP
->mode
!= DISP
1648 || opP
->reg
> ADDR7
)
1653 if (opP
->mode
!= DREG
)
1658 if (opP
->reg
!= ACC
)
1663 if (opP
->reg
!= ACC
&& opP
->reg
!= ACC1
1664 && opP
->reg
!= ACC2
&& opP
->reg
!= ACC3
)
1669 if (opP
->mode
!= FPREG
)
1674 if (opP
->reg
!= MACSR
)
1679 if (opP
->reg
!= ACCEXT01
&& opP
->reg
!= ACCEXT23
)
1684 if (opP
->reg
!= MASK
)
1689 if (opP
->mode
!= CONTROL
1696 if (opP
->mode
!= LSH
&& opP
->mode
!= RSH
)
1701 if (opP
->mode
!= CONTROL
1703 || opP
->reg
> last_movec_reg
)
1707 const enum m68k_register
*rp
;
1708 for (rp
= control_regs
; *rp
; rp
++)
1709 if (*rp
== opP
->reg
)
1717 if (opP
->mode
!= IMMED
)
1723 if (opP
->mode
== DREG
1724 || opP
->mode
== AREG
1725 || opP
->mode
== FPREG
)
1734 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1737 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1740 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1748 else if (opP
->mode
== CONTROL
)
1757 opP
->mask
= 1 << 24;
1760 opP
->mask
= 1 << 25;
1763 opP
->mask
= 1 << 26;
1772 else if (opP
->mode
!= REGLST
)
1774 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1776 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1781 if (opP
->mode
!= IMMED
)
1783 else if (opP
->disp
.exp
.X_op
!= O_constant
1784 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1786 else if (! m68k_quick
1787 && instring
[3] != 'q'
1788 && instring
[4] != 'q')
1793 if (opP
->mode
!= DREG
1794 && opP
->mode
!= IMMED
1795 && opP
->mode
!= ABSL
)
1800 if (opP
->mode
!= IMMED
)
1802 else if (opP
->disp
.exp
.X_op
!= O_constant
1803 || TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 7)
1805 else if (! m68k_quick
1806 && (strncmp (instring
, "add", 3) == 0
1807 || strncmp (instring
, "sub", 3) == 0)
1808 && instring
[3] != 'q')
1813 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1818 if (opP
->mode
!= AINDR
1819 && (opP
->mode
!= BASE
1821 && opP
->reg
!= ZADDR0
)
1822 || opP
->disp
.exp
.X_op
!= O_absent
1823 || ((opP
->index
.reg
< DATA0
1824 || opP
->index
.reg
> DATA7
)
1825 && (opP
->index
.reg
< ADDR0
1826 || opP
->index
.reg
> ADDR7
))
1827 || opP
->index
.size
!= SIZE_UNSPEC
1828 || opP
->index
.scale
!= 1))
1833 if (opP
->mode
!= CONTROL
1834 || ! (opP
->reg
== FPI
1836 || opP
->reg
== FPC
))
1841 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1846 if (opP
->mode
!= IMMED
)
1848 else if (opP
->disp
.exp
.X_op
!= O_constant
1849 || TRUNC (opP
->disp
.exp
.X_add_number
) > 7)
1854 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1859 if (opP
->mode
!= IMMED
)
1861 else if (opP
->disp
.exp
.X_op
!= O_constant
1862 || (TRUNC (opP
->disp
.exp
.X_add_number
) != 0xffffffff
1863 && TRUNC (opP
->disp
.exp
.X_add_number
) - 1 > 6))
1867 /* JF these are out of order. We could put them
1868 in order if we were willing to put up with
1869 bunches of #ifdef m68851s in the code.
1871 Don't forget that you need these operands
1872 to use 68030 MMU instructions. */
1874 /* Memory addressing mode used by pflushr. */
1876 if (opP
->mode
== CONTROL
1877 || opP
->mode
== FPREG
1878 || opP
->mode
== DREG
1879 || opP
->mode
== AREG
1880 || opP
->mode
== REGLST
)
1882 /* We should accept immediate operands, but they
1883 supposedly have to be quad word, and we don't
1884 handle that. I would like to see what a Motorola
1885 assembler does before doing something here. */
1886 if (opP
->mode
== IMMED
)
1891 if (opP
->mode
!= CONTROL
1892 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1897 if (opP
->mode
!= CONTROL
|| opP
->reg
!= TC
)
1902 if (opP
->mode
!= CONTROL
|| opP
->reg
!= AC
)
1907 if (opP
->mode
!= CONTROL
1910 && opP
->reg
!= SCC
))
1915 if (opP
->mode
!= CONTROL
1921 if (opP
->mode
!= CONTROL
1924 && opP
->reg
!= CRP
))
1948 if (opP
->mode
!= CONTROL
1949 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1950 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1955 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1960 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1965 if (opP
->mode
!= CONTROL
1974 if (opP
->mode
!= ABSL
)
1979 if (opP
->reg
< DATA0L
|| opP
->reg
> ADDR7U
)
1981 /* FIXME: kludge instead of fixing parser:
1982 upper/lower registers are *not* CONTROL
1983 registers, but ordinary ones. */
1984 if ((opP
->reg
>= DATA0L
&& opP
->reg
<= DATA7L
)
1985 || (opP
->reg
>= DATA0U
&& opP
->reg
<= DATA7U
))
1992 if (!(opP
->mode
== AINDR
1993 || (opP
->mode
== DISP
1994 && !(opP
->reg
== PC
|| opP
->reg
== ZPC
))))
1999 if (!(opP
->mode
== AINDR
|| opP
->mode
== DISP
))
2011 /* Since we have found the correct instruction, copy
2012 in the modifications that we may have made. */
2014 for (i
= 0; i
< opsfound
; i
++)
2015 the_ins
.operands
[i
] = operands_backup
[i
];
2021 opcode
= opcode
->m_next
;
2026 && !(ok_arch
& current_architecture
))
2031 _("invalid instruction for this architecture; needs "),
2033 cp
= buf
+ strlen (buf
);
2037 strncpy (cp
, _("ColdFire ISA_A"),
2038 sizeof (buf
) - (cp
- buf
));
2040 strncpy (cp
, find_cf_chip (ok_arch
),
2041 sizeof (buf
) - (cp
- buf
));
2045 strncpy (cp
, _("ColdFire hardware divide"),
2046 sizeof (buf
) - (cp
- buf
));
2048 strncpy (cp
, find_cf_chip (ok_arch
),
2049 sizeof (buf
) - (cp
- buf
));
2053 strncpy (cp
, _("ColdFire ISA_A+"),
2054 sizeof (buf
) - (cp
- buf
));
2056 strncpy (cp
, find_cf_chip (ok_arch
),
2057 sizeof (buf
) - (cp
- buf
));
2061 strncpy (cp
, _("ColdFire ISA_B"),
2062 sizeof (buf
) - (cp
- buf
));
2064 strncpy (cp
, find_cf_chip (ok_arch
),
2065 sizeof (buf
) - (cp
- buf
));
2069 strncpy (cp
, _("ColdFire fpu"), sizeof (buf
) - (cp
- buf
));
2071 strncpy (cp
, find_cf_chip (ok_arch
),
2072 sizeof (buf
) - (cp
- buf
));
2076 strcpy (cp
, _("fpu (68040, 68060 or 68881/68882)"));
2079 strcpy (cp
, _("mmu (68030 or 68851)"));
2082 strcpy (cp
, _("68020 or higher"));
2085 strcpy (cp
, _("68000 or higher"));
2088 strcpy (cp
, _("68010 or higher"));
2092 int got_one
= 0, idx
;
2094 for (idx
= 0; m68k_cpus
[idx
].name
; idx
++)
2096 if ((m68k_cpus
[idx
].arch
& ok_arch
)
2097 && ! m68k_cpus
[idx
].alias
)
2101 strcpy (cp
, " or ");
2105 strcpy (cp
, m68k_cpus
[idx
].name
);
2111 cp
= xmalloc (strlen (buf
) + 1);
2116 the_ins
.error
= _("operands mismatch");
2123 /* Now assemble it. */
2124 the_ins
.args
= opcode
->m_operands
;
2125 the_ins
.numargs
= opcode
->m_opnum
;
2126 the_ins
.numo
= opcode
->m_codenum
;
2127 the_ins
.opcode
[0] = getone (opcode
);
2128 the_ins
.opcode
[1] = gettwo (opcode
);
2130 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2132 /* This switch is a doozy.
2133 Watch the first step; its a big one! */
2166 tmpreg
= 0x3c; /* 7.4 */
2167 if (strchr ("bwl", s
[1]))
2168 nextword
= get_num (&opP
->disp
, 90);
2170 nextword
= get_num (&opP
->disp
, 0);
2171 if (isvar (&opP
->disp
))
2172 add_fix (s
[1], &opP
->disp
, 0, 0);
2176 if (!isbyte (nextword
))
2177 opP
->error
= _("operand out of range");
2182 if (!isword (nextword
))
2183 opP
->error
= _("operand out of range");
2188 if (!issword (nextword
))
2189 opP
->error
= _("operand out of range");
2194 addword (nextword
>> 16);
2221 /* We gotta put out some float. */
2222 if (op (&opP
->disp
) != O_big
)
2227 /* Can other cases happen here? */
2228 if (op (&opP
->disp
) != O_constant
)
2231 val
= (valueT
) offs (&opP
->disp
);
2235 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2236 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2240 offs (&opP
->disp
) = gencnt
;
2242 if (offs (&opP
->disp
) > 0)
2244 if (offs (&opP
->disp
) > baseo
)
2246 as_warn (_("Bignum too big for %c format; truncated"),
2248 offs (&opP
->disp
) = baseo
;
2250 baseo
-= offs (&opP
->disp
);
2253 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
2254 offs (&opP
->disp
)--;
2259 gen_to_words (words
, baseo
, (long) outro
);
2260 for (wordp
= words
; baseo
--; wordp
++)
2264 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2267 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2270 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2273 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2276 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2280 nextword
= get_num (&opP
->disp
, 90);
2282 /* Convert mode 5 addressing with a zero offset into
2283 mode 2 addressing to reduce the instruction size by a
2285 if (! isvar (&opP
->disp
)
2287 && (opP
->disp
.size
== SIZE_UNSPEC
)
2288 && (opP
->reg
>= ADDR0
)
2289 && (opP
->reg
<= ADDR7
))
2291 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2296 && ! isvar (&opP
->disp
)
2299 opP
->disp
.exp
.X_op
= O_symbol
;
2300 opP
->disp
.exp
.X_add_symbol
=
2301 section_symbol (absolute_section
);
2304 /* Force into index mode. Hope this works. */
2306 /* We do the first bit for 32-bit displacements, and the
2307 second bit for 16 bit ones. It is possible that we
2308 should make the default be WORD instead of LONG, but
2309 I think that'd break GCC, so we put up with a little
2310 inefficiency for the sake of working output. */
2312 if (!issword (nextword
)
2313 || (isvar (&opP
->disp
)
2314 && ((opP
->disp
.size
== SIZE_UNSPEC
2315 && flag_short_refs
== 0
2316 && cpu_of_arch (current_architecture
) >= m68020
2317 && ! arch_coldfire_p (current_architecture
))
2318 || opP
->disp
.size
== SIZE_LONG
)))
2320 if (cpu_of_arch (current_architecture
) < m68020
2321 || arch_coldfire_p (current_architecture
))
2323 _("displacement too large for this architecture; needs 68020 or higher");
2325 tmpreg
= 0x3B; /* 7.3 */
2327 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2328 if (isvar (&opP
->disp
))
2332 if (opP
->disp
.size
== SIZE_LONG
2334 /* If the displacement needs pic
2335 relocation it cannot be relaxed. */
2336 || opP
->disp
.pic_reloc
!= pic_none
2341 add_fix ('l', &opP
->disp
, 1, 2);
2345 add_frag (adds (&opP
->disp
),
2346 SEXT (offs (&opP
->disp
)),
2347 TAB (PCREL1632
, SZ_UNDEF
));
2354 add_fix ('l', &opP
->disp
, 0, 0);
2359 addword (nextword
>> 16);
2364 tmpreg
= 0x3A; /* 7.2 */
2366 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2368 if (isvar (&opP
->disp
))
2372 add_fix ('w', &opP
->disp
, 1, 0);
2375 add_fix ('w', &opP
->disp
, 0, 0);
2385 baseo
= get_num (&opP
->disp
, 90);
2386 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2387 outro
= get_num (&opP
->odisp
, 90);
2388 /* Figure out the `addressing mode'.
2389 Also turn on the BASE_DISABLE bit, if needed. */
2390 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2392 tmpreg
= 0x3b; /* 7.3 */
2393 if (opP
->reg
== ZPC
)
2396 else if (opP
->reg
== 0)
2399 tmpreg
= 0x30; /* 6.garbage */
2401 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
2404 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
2407 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2409 siz1
= opP
->disp
.size
;
2410 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2411 siz2
= opP
->odisp
.size
;
2415 /* Index register stuff. */
2416 if (opP
->index
.reg
!= 0
2417 && opP
->index
.reg
>= DATA
2418 && opP
->index
.reg
<= ADDR7
)
2420 nextword
|= (opP
->index
.reg
- DATA
) << 12;
2422 if (opP
->index
.size
== SIZE_LONG
2423 || (opP
->index
.size
== SIZE_UNSPEC
2424 && m68k_index_width_default
== SIZE_LONG
))
2427 if ((opP
->index
.scale
!= 1
2428 && cpu_of_arch (current_architecture
) < m68020
)
2429 || (opP
->index
.scale
== 8
2430 && (arch_coldfire_p (current_architecture
)
2431 && !arch_coldfire_fpu (current_architecture
))))
2434 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2437 if (arch_coldfire_p (current_architecture
)
2438 && opP
->index
.size
== SIZE_WORD
)
2439 opP
->error
= _("invalid index size for coldfire");
2441 switch (opP
->index
.scale
)
2458 GET US OUT OF HERE! */
2460 /* Must be INDEX, with an index register. Address
2461 register cannot be ZERO-PC, and either :b was
2462 forced, or we know it will fit. For a 68000 or
2463 68010, force this mode anyways, because the
2464 larger modes aren't supported. */
2465 if (opP
->mode
== BASE
2466 && ((opP
->reg
>= ADDR0
2467 && opP
->reg
<= ADDR7
)
2470 if (siz1
== SIZE_BYTE
2471 || cpu_of_arch (current_architecture
) < m68020
2472 || arch_coldfire_p (current_architecture
)
2473 || (siz1
== SIZE_UNSPEC
2474 && ! isvar (&opP
->disp
)
2475 && issbyte (baseo
)))
2477 nextword
+= baseo
& 0xff;
2479 if (isvar (&opP
->disp
))
2481 /* Do a byte relocation. If it doesn't
2482 fit (possible on m68000) let the
2483 fixup processing complain later. */
2485 add_fix ('B', &opP
->disp
, 1, 1);
2487 add_fix ('B', &opP
->disp
, 0, 0);
2489 else if (siz1
!= SIZE_BYTE
)
2491 if (siz1
!= SIZE_UNSPEC
)
2492 as_warn (_("Forcing byte displacement"));
2493 if (! issbyte (baseo
))
2494 opP
->error
= _("byte displacement out of range");
2499 else if (siz1
== SIZE_UNSPEC
2501 && isvar (&opP
->disp
)
2502 && subs (&opP
->disp
) == NULL
2504 /* If the displacement needs pic
2505 relocation it cannot be relaxed. */
2506 && opP
->disp
.pic_reloc
== pic_none
2510 /* The code in md_convert_frag_1 needs to be
2511 able to adjust nextword. Call frag_grow
2512 to ensure that we have enough space in
2513 the frag obstack to make all the bytes
2516 nextword
+= baseo
& 0xff;
2518 add_frag (adds (&opP
->disp
),
2519 SEXT (offs (&opP
->disp
)),
2520 TAB (PCINDEX
, SZ_UNDEF
));
2528 nextword
|= 0x40; /* No index reg. */
2529 if (opP
->index
.reg
>= ZDATA0
2530 && opP
->index
.reg
<= ZDATA7
)
2531 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
2532 else if (opP
->index
.reg
>= ZADDR0
2533 || opP
->index
.reg
<= ZADDR7
)
2534 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
2537 /* It isn't simple. */
2539 if (cpu_of_arch (current_architecture
) < m68020
2540 || arch_coldfire_p (current_architecture
))
2542 _("invalid operand mode for this architecture; needs 68020 or higher");
2545 /* If the guy specified a width, we assume that it is
2546 wide enough. Maybe it isn't. If so, we lose. */
2550 if (isvar (&opP
->disp
)
2552 : ! issword (baseo
))
2557 else if (! isvar (&opP
->disp
) && baseo
== 0)
2566 as_warn (_(":b not permitted; defaulting to :w"));
2576 /* Figure out inner displacement stuff. */
2577 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
2579 if (cpu_of_arch (current_architecture
) & cpu32
)
2580 opP
->error
= _("invalid operand mode for this architecture; needs 68020 or higher");
2584 if (isvar (&opP
->odisp
)
2586 : ! issword (outro
))
2591 else if (! isvar (&opP
->odisp
) && outro
== 0)
2600 as_warn (_(":b not permitted; defaulting to :w"));
2609 if (opP
->mode
== POST
2610 && (nextword
& 0x40) == 0)
2615 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
2617 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2618 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
2620 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
2622 if (siz1
== SIZE_LONG
)
2623 addword (baseo
>> 16);
2624 if (siz1
!= SIZE_UNSPEC
)
2627 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
2628 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
2629 if (siz2
== SIZE_LONG
)
2630 addword (outro
>> 16);
2631 if (siz2
!= SIZE_UNSPEC
)
2637 nextword
= get_num (&opP
->disp
, 90);
2638 switch (opP
->disp
.size
)
2643 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
2645 tmpreg
= 0x38; /* 7.0 */
2649 if (isvar (&opP
->disp
)
2650 && !subs (&opP
->disp
)
2651 && adds (&opP
->disp
)
2653 /* If the displacement needs pic relocation it
2654 cannot be relaxed. */
2655 && opP
->disp
.pic_reloc
== pic_none
2658 && !strchr ("~%&$?", s
[0]))
2660 tmpreg
= 0x3A; /* 7.2 */
2661 add_frag (adds (&opP
->disp
),
2662 SEXT (offs (&opP
->disp
)),
2663 TAB (ABSTOPCREL
, SZ_UNDEF
));
2666 /* Fall through into long. */
2668 if (isvar (&opP
->disp
))
2669 add_fix ('l', &opP
->disp
, 0, 0);
2671 tmpreg
= 0x39;/* 7.1 mode */
2672 addword (nextword
>> 16);
2677 as_bad (_("unsupported byte value; use a different suffix"));
2681 if (isvar (&opP
->disp
))
2682 add_fix ('w', &opP
->disp
, 0, 0);
2684 tmpreg
= 0x38;/* 7.0 mode */
2692 as_bad (_("unknown/incorrect operand"));
2696 /* If s[0] is '4', then this is for the mac instructions
2697 that can have a trailing_ampersand set. If so, set 0x100
2698 bit on tmpreg so install_gen_operand can check for it and
2699 set the appropriate bit (word2, bit 5). */
2702 if (opP
->trailing_ampersand
)
2705 install_gen_operand (s
[1], tmpreg
);
2711 { /* JF: I hate floating point! */
2726 tmpreg
= get_num (&opP
->disp
, tmpreg
);
2727 if (isvar (&opP
->disp
))
2728 add_fix (s
[1], &opP
->disp
, 0, 0);
2731 case 'b': /* Danger: These do no check for
2732 certain types of overflow.
2734 if (!isbyte (tmpreg
))
2735 opP
->error
= _("out of range");
2736 insop (tmpreg
, opcode
);
2737 if (isvar (&opP
->disp
))
2738 the_ins
.reloc
[the_ins
.nrel
- 1].n
=
2739 (opcode
->m_codenum
) * 2 + 1;
2742 if (!issbyte (tmpreg
))
2743 opP
->error
= _("out of range");
2744 the_ins
.opcode
[the_ins
.numo
- 1] |= tmpreg
& 0xff;
2745 if (isvar (&opP
->disp
))
2746 the_ins
.reloc
[the_ins
.nrel
- 1].n
= opcode
->m_codenum
* 2 - 1;
2749 if (!isword (tmpreg
))
2750 opP
->error
= _("out of range");
2751 insop (tmpreg
, opcode
);
2752 if (isvar (&opP
->disp
))
2753 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2756 if (!issword (tmpreg
))
2757 opP
->error
= _("out of range");
2758 insop (tmpreg
, opcode
);
2759 if (isvar (&opP
->disp
))
2760 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2763 /* Because of the way insop works, we put these two out
2765 insop (tmpreg
, opcode
);
2766 insop (tmpreg
>> 16, opcode
);
2767 if (isvar (&opP
->disp
))
2768 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2775 install_operand (s
[1], tmpreg
);
2786 install_operand (s
[1], opP
->reg
- ADDR
);
2790 tmpreg
= get_num (&opP
->disp
, 90);
2794 add_fix ('B', &opP
->disp
, 1, -1);
2797 add_fix ('w', &opP
->disp
, 1, 0);
2802 if (! HAVE_LONG_BRANCH (current_architecture
))
2803 as_warn (_("Can't use long branches on 68000/68010/5200"));
2804 the_ins
.opcode
[0] |= 0xff;
2805 add_fix ('l', &opP
->disp
, 1, 0);
2810 if (subs (&opP
->disp
)) /* We can't relax it. */
2814 /* If the displacement needs pic relocation it cannot be
2816 if (opP
->disp
.pic_reloc
!= pic_none
)
2819 /* This could either be a symbol, or an absolute
2820 address. If it's an absolute address, turn it into
2821 an absolute jump right here and keep it out of the
2823 if (adds (&opP
->disp
) == 0)
2825 if (the_ins
.opcode
[0] == 0x6000) /* jbra */
2826 the_ins
.opcode
[0] = 0x4EF9;
2827 else if (the_ins
.opcode
[0] == 0x6100) /* jbsr */
2828 the_ins
.opcode
[0] = 0x4EB9;
2831 the_ins
.opcode
[0] ^= 0x0100;
2832 the_ins
.opcode
[0] |= 0x0006;
2835 add_fix ('l', &opP
->disp
, 0, 0);
2841 /* Now we know it's going into the relaxer. Now figure
2842 out which mode. We try in this order of preference:
2843 long branch, absolute jump, byte/word branches only. */
2844 if (HAVE_LONG_BRANCH (current_architecture
))
2845 add_frag (adds (&opP
->disp
),
2846 SEXT (offs (&opP
->disp
)),
2847 TAB (BRANCHBWL
, SZ_UNDEF
));
2848 else if (! flag_keep_pcrel
)
2850 if ((the_ins
.opcode
[0] == 0x6000)
2851 || (the_ins
.opcode
[0] == 0x6100))
2852 add_frag (adds (&opP
->disp
),
2853 SEXT (offs (&opP
->disp
)),
2854 TAB (BRABSJUNC
, SZ_UNDEF
));
2856 add_frag (adds (&opP
->disp
),
2857 SEXT (offs (&opP
->disp
)),
2858 TAB (BRABSJCOND
, SZ_UNDEF
));
2861 add_frag (adds (&opP
->disp
),
2862 SEXT (offs (&opP
->disp
)),
2863 TAB (BRANCHBW
, SZ_UNDEF
));
2866 if (isvar (&opP
->disp
))
2868 /* Check for DBcc instructions. We can relax them,
2869 but only if we have long branches and/or absolute
2871 if (((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2872 && (HAVE_LONG_BRANCH (current_architecture
)
2873 || (! flag_keep_pcrel
)))
2875 if (HAVE_LONG_BRANCH (current_architecture
))
2876 add_frag (adds (&opP
->disp
),
2877 SEXT (offs (&opP
->disp
)),
2878 TAB (DBCCLBR
, SZ_UNDEF
));
2880 add_frag (adds (&opP
->disp
),
2881 SEXT (offs (&opP
->disp
)),
2882 TAB (DBCCABSJ
, SZ_UNDEF
));
2885 add_fix ('w', &opP
->disp
, 1, 0);
2889 case 'C': /* Fixed size LONG coproc branches. */
2890 add_fix ('l', &opP
->disp
, 1, 0);
2894 case 'c': /* Var size Coprocesssor branches. */
2895 if (subs (&opP
->disp
) || (adds (&opP
->disp
) == 0))
2897 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2898 add_fix ('l', &opP
->disp
, 1, 0);
2903 add_frag (adds (&opP
->disp
),
2904 SEXT (offs (&opP
->disp
)),
2905 TAB (FBRANCH
, SZ_UNDEF
));
2912 case 'C': /* Ignore it. */
2915 case 'd': /* JF this is a kludge. */
2916 install_operand ('s', opP
->reg
- ADDR
);
2917 tmpreg
= get_num (&opP
->disp
, 90);
2918 if (!issword (tmpreg
))
2920 as_warn (_("Expression out of range, using 0"));
2927 install_operand (s
[1], opP
->reg
- DATA
);
2930 case 'e': /* EMAC ACCx, reg/reg. */
2931 install_operand (s
[1], opP
->reg
- ACC
);
2934 case 'E': /* Ignore it. */
2938 install_operand (s
[1], opP
->reg
- FP0
);
2941 case 'g': /* EMAC ACCEXTx. */
2942 install_operand (s
[1], opP
->reg
- ACCEXT01
);
2945 case 'G': /* Ignore it. */
2950 tmpreg
= opP
->reg
- COP0
;
2951 install_operand (s
[1], tmpreg
);
2954 case 'i': /* MAC/EMAC scale factor. */
2955 install_operand (s
[1], opP
->mode
== LSH
? 0x1 : 0x3);
2958 case 'J': /* JF foo. */
3088 install_operand (s
[1], tmpreg
);
3092 tmpreg
= get_num (&opP
->disp
, 55);
3093 install_operand (s
[1], tmpreg
& 0x7f);
3100 if (tmpreg
& 0x7FF0000)
3101 as_bad (_("Floating point register in register list"));
3102 insop (reverse_16_bits (tmpreg
), opcode
);
3106 if (tmpreg
& 0x700FFFF)
3107 as_bad (_("Wrong register in floating-point reglist"));
3108 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
3116 if (tmpreg
& 0x7FF0000)
3117 as_bad (_("Floating point register in register list"));
3118 insop (tmpreg
, opcode
);
3120 else if (s
[1] == '8')
3122 if (tmpreg
& 0x0FFFFFF)
3123 as_bad (_("incorrect register in reglist"));
3124 install_operand (s
[1], tmpreg
>> 24);
3128 if (tmpreg
& 0x700FFFF)
3129 as_bad (_("wrong register in floating-point reglist"));
3131 install_operand (s
[1], tmpreg
>> 16);
3136 install_operand (s
[1], get_num (&opP
->disp
, 60));
3140 tmpreg
= ((opP
->mode
== DREG
)
3141 ? 0x20 + (int) (opP
->reg
- DATA
)
3142 : (get_num (&opP
->disp
, 40) & 0x1F));
3143 install_operand (s
[1], tmpreg
);
3147 tmpreg
= get_num (&opP
->disp
, 10);
3150 install_operand (s
[1], tmpreg
);
3154 /* This depends on the fact that ADDR registers are eight
3155 more than their corresponding DATA regs, so the result
3156 will have the ADDR_REG bit set. */
3157 install_operand (s
[1], opP
->reg
- DATA
);
3161 if (opP
->mode
== AINDR
)
3162 install_operand (s
[1], opP
->reg
- DATA
);
3164 install_operand (s
[1], opP
->index
.reg
- DATA
);
3168 if (opP
->reg
== FPI
)
3170 else if (opP
->reg
== FPS
)
3172 else if (opP
->reg
== FPC
)
3176 install_operand (s
[1], tmpreg
);
3179 case 'S': /* Ignore it. */
3183 install_operand (s
[1], get_num (&opP
->disp
, 30));
3186 case 'U': /* Ignore it. */
3205 as_fatal (_("failed sanity check"));
3206 } /* switch on cache token. */
3207 install_operand (s
[1], tmpreg
);
3210 /* JF: These are out of order, I fear. */
3223 install_operand (s
[1], tmpreg
);
3249 install_operand (s
[1], tmpreg
);
3253 if (opP
->reg
== VAL
)
3272 install_operand (s
[1], tmpreg
);
3286 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3297 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3303 install_operand (s
[1], tmpreg
);
3306 know (opP
->reg
== PSR
);
3309 know (opP
->reg
== PCSR
);
3324 install_operand (s
[1], tmpreg
);
3327 tmpreg
= get_num (&opP
->disp
, 20);
3328 install_operand (s
[1], tmpreg
);
3330 case '_': /* used only for move16 absolute 32-bit address. */
3331 if (isvar (&opP
->disp
))
3332 add_fix ('l', &opP
->disp
, 0, 0);
3333 tmpreg
= get_num (&opP
->disp
, 90);
3334 addword (tmpreg
>> 16);
3335 addword (tmpreg
& 0xFFFF);
3338 install_operand (s
[1], opP
->reg
- DATA0L
);
3339 opP
->reg
-= (DATA0L
);
3340 opP
->reg
&= 0x0F; /* remove upper/lower bit. */
3343 tmpreg
= get_num (&opP
->disp
, 80);
3346 install_operand (s
[1], tmpreg
);
3353 /* By the time whe get here (FINALLY) the_ins contains the complete
3354 instruction, ready to be emitted. . . */
3358 reverse_16_bits (int in
)
3363 static int mask
[16] =
3365 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3366 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3368 for (n
= 0; n
< 16; n
++)
3371 out
|= mask
[15 - n
];
3374 } /* reverse_16_bits() */
3377 reverse_8_bits (int in
)
3382 static int mask
[8] =
3384 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3387 for (n
= 0; n
< 8; n
++)
3393 } /* reverse_8_bits() */
3395 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3396 (that value is chosen in the frag_var call in md_assemble). TYPE
3397 is the subtype of the frag to be generated; its primary type is
3398 rs_machine_dependent.
3400 The TYPE parameter is also used by md_convert_frag_1 and
3401 md_estimate_size_before_relax. The appropriate type of fixup will
3402 be emitted by md_convert_frag_1.
3404 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3406 install_operand (int mode
, int val
)
3411 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge. */
3414 the_ins
.opcode
[0] |= val
<< 9;
3417 the_ins
.opcode
[1] |= val
<< 12;
3420 the_ins
.opcode
[1] |= val
<< 6;
3423 the_ins
.opcode
[1] |= val
;
3426 the_ins
.opcode
[2] |= val
<< 12;
3429 the_ins
.opcode
[2] |= val
<< 6;
3432 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3433 three words long! */
3435 the_ins
.opcode
[2] |= val
;
3438 the_ins
.opcode
[1] |= val
<< 7;
3441 the_ins
.opcode
[1] |= val
<< 10;
3445 the_ins
.opcode
[1] |= val
<< 5;
3450 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3453 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3456 the_ins
.opcode
[0] |= val
= 0xff;
3459 the_ins
.opcode
[0] |= val
<< 9;
3462 the_ins
.opcode
[1] |= val
;
3465 the_ins
.opcode
[1] |= val
;
3466 the_ins
.numo
++; /* What a hack. */
3469 the_ins
.opcode
[1] |= val
<< 4;
3477 the_ins
.opcode
[0] |= (val
<< 6);
3480 the_ins
.opcode
[1] = (val
>> 16);
3481 the_ins
.opcode
[2] = val
& 0xffff;
3484 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3485 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3486 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3488 case 'n': /* MAC/EMAC Rx on !load. */
3489 the_ins
.opcode
[0] |= ((val
& 0x8) << (6 - 3));
3490 the_ins
.opcode
[0] |= ((val
& 0x7) << 9);
3491 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3493 case 'o': /* MAC/EMAC Rx on load. */
3494 the_ins
.opcode
[1] |= val
<< 12;
3495 the_ins
.opcode
[1] |= ((val
& 0x10) << (7 - 4));
3497 case 'M': /* MAC/EMAC Ry on !load. */
3498 the_ins
.opcode
[0] |= (val
& 0xF);
3499 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3501 case 'N': /* MAC/EMAC Ry on load. */
3502 the_ins
.opcode
[1] |= (val
& 0xF);
3503 the_ins
.opcode
[1] |= ((val
& 0x10) << (6 - 4));
3506 the_ins
.opcode
[1] |= ((val
!= 1) << 10);
3509 the_ins
.opcode
[0] |= ((val
& 0x3) << 9);
3512 the_ins
.opcode
[0] |= ((val
& 0x3) << 0);
3514 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3515 the_ins
.opcode
[0] |= ((~val
& 0x1) << 7);
3516 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3518 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3519 the_ins
.opcode
[0] |= ((val
& 0x1) << 7);
3520 the_ins
.opcode
[1] |= ((val
& 0x2) << (4 - 1));
3523 the_ins
.opcode
[1] |= ((val
& 0x3) << 9);
3526 the_ins
.opcode
[0] |= (val
& 0x1) <<10;
3530 as_fatal (_("failed sanity check."));
3535 install_gen_operand (int mode
, int val
)
3539 case '/': /* Special for mask loads for mac/msac insns with
3540 possible mask; trailing_ampersend set in bit 8. */
3541 the_ins
.opcode
[0] |= (val
& 0x3f);
3542 the_ins
.opcode
[1] |= (((val
& 0x100) >> 8) << 5);
3545 the_ins
.opcode
[0] |= val
;
3548 /* This is a kludge!!! */
3549 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3558 the_ins
.opcode
[0] |= val
;
3560 /* more stuff goes here. */
3562 as_fatal (_("failed sanity check."));
3566 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3567 then deal with the bitfield hack. */
3570 crack_operand (char *str
, struct m68k_op
*opP
)
3572 register int parens
;
3574 register char *beg_str
;
3582 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
3588 else if (*str
== ')')
3592 opP
->error
= _("Extra )");
3598 if (flag_mri
&& *str
== '\'')
3599 inquote
= ! inquote
;
3601 if (!*str
&& parens
)
3603 opP
->error
= _("Missing )");
3608 if (m68k_ip_op (beg_str
, opP
) != 0)
3615 c
= *++str
; /* JF bitfield hack. */
3620 as_bad (_("Missing operand"));
3623 /* Detect MRI REG symbols and convert them to REGLSTs. */
3624 if (opP
->mode
== CONTROL
&& (int)opP
->reg
< 0)
3627 opP
->mask
= ~(int)opP
->reg
;
3634 /* This is the guts of the machine-dependent assembler. STR points to a
3635 machine dependent instruction. This function is supposed to emit
3636 the frags/bytes it assembles to.
3640 insert_reg (const char *regname
, int regnum
)
3645 #ifdef REGISTER_PREFIX
3646 if (!flag_reg_prefix_optional
)
3648 buf
[0] = REGISTER_PREFIX
;
3649 strcpy (buf
+ 1, regname
);
3654 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3655 &zero_address_frag
));
3657 for (i
= 0; regname
[i
]; i
++)
3658 buf
[i
] = TOUPPER (regname
[i
]);
3661 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3662 &zero_address_frag
));
3671 static const struct init_entry init_table
[] =
3731 { "accext01", ACCEXT01
},
3732 { "accext23", ACCEXT23
},
3736 /* Control registers. */
3737 { "sfc", SFC
}, /* Source Function Code. */
3739 { "dfc", DFC
}, /* Destination Function Code. */
3741 { "cacr", CACR
}, /* Cache Control Register. */
3742 { "caar", CAAR
}, /* Cache Address Register. */
3744 { "usp", USP
}, /* User Stack Pointer. */
3745 { "vbr", VBR
}, /* Vector Base Register. */
3746 { "msp", MSP
}, /* Master Stack Pointer. */
3747 { "isp", ISP
}, /* Interrupt Stack Pointer. */
3749 { "itt0", ITT0
}, /* Instruction Transparent Translation Reg 0. */
3750 { "itt1", ITT1
}, /* Instruction Transparent Translation Reg 1. */
3751 { "dtt0", DTT0
}, /* Data Transparent Translation Register 0. */
3752 { "dtt1", DTT1
}, /* Data Transparent Translation Register 1. */
3754 /* 68ec040 versions of same */
3755 { "iacr0", ITT0
}, /* Instruction Access Control Register 0. */
3756 { "iacr1", ITT1
}, /* Instruction Access Control Register 0. */
3757 { "dacr0", DTT0
}, /* Data Access Control Register 0. */
3758 { "dacr1", DTT1
}, /* Data Access Control Register 0. */
3760 /* mcf5200 versions of same. The ColdFire programmer's reference
3761 manual indicated that the order is 2,3,0,1, but Ken Rose
3762 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3763 { "acr0", ACR0
}, /* Access Control Unit 0. */
3764 { "acr1", ACR1
}, /* Access Control Unit 1. */
3765 { "acr2", ACR2
}, /* Access Control Unit 2. */
3766 { "acr3", ACR3
}, /* Access Control Unit 3. */
3768 { "tc", TC
}, /* MMU Translation Control Register. */
3771 { "mmusr", MMUSR
}, /* MMU Status Register. */
3772 { "srp", SRP
}, /* User Root Pointer. */
3773 { "urp", URP
}, /* Supervisor Root Pointer. */
3778 { "rombar", ROMBAR
}, /* ROM Base Address Register. */
3779 { "rambar0", RAMBAR0
}, /* ROM Base Address Register. */
3780 { "rambar1", RAMBAR1
}, /* ROM Base Address Register. */
3781 { "mbar", MBAR
}, /* Module Base Address Register. */
3783 { "mbar0", MBAR0
}, /* mcfv4e registers. */
3784 { "mbar1", MBAR1
}, /* mcfv4e registers. */
3785 { "rombar0", ROMBAR
}, /* mcfv4e registers. */
3786 { "rombar1", ROMBAR1
}, /* mcfv4e registers. */
3787 { "mpcr", MPCR
}, /* mcfv4e registers. */
3788 { "edrambar", EDRAMBAR
}, /* mcfv4e registers. */
3789 { "secmbar", SECMBAR
}, /* mcfv4e registers. */
3790 { "asid", TC
}, /* mcfv4e registers. */
3791 { "mmubar", BUSCR
}, /* mcfv4e registers. */
3792 { "pcr1u0", PCR1U0
}, /* mcfv4e registers. */
3793 { "pcr1l0", PCR1L0
}, /* mcfv4e registers. */
3794 { "pcr2u0", PCR2U0
}, /* mcfv4e registers. */
3795 { "pcr2l0", PCR2L0
}, /* mcfv4e registers. */
3796 { "pcr3u0", PCR3U0
}, /* mcfv4e registers. */
3797 { "pcr3l0", PCR3L0
}, /* mcfv4e registers. */
3798 { "pcr1u1", PCR1U1
}, /* mcfv4e registers. */
3799 { "pcr1l1", PCR1L1
}, /* mcfv4e registers. */
3800 { "pcr2u1", PCR2U1
}, /* mcfv4e registers. */
3801 { "pcr2l1", PCR2L1
}, /* mcfv4e registers. */
3802 { "pcr3u1", PCR3U1
}, /* mcfv4e registers. */
3803 { "pcr3l1", PCR3L1
}, /* mcfv4e registers. */
3805 { "flashbar", FLASHBAR
}, /* mcf528x registers. */
3806 { "rambar", RAMBAR
}, /* mcf528x registers. */
3808 { "mbar2", MBAR2
}, /* mcf5249 registers. */
3809 /* End of control registers. */
3843 /* 68ec030 versions of same. */
3846 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3849 /* Suppressed data and address registers. */
3867 /* Upper and lower data and address registers, used by macw and msacw. */
3908 init_regtable (void)
3911 for (i
= 0; init_table
[i
].name
; i
++)
3912 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3916 md_assemble (char *str
)
3923 int shorts_this_frag
;
3926 if (!selected_cpu
&& !selected_arch
)
3928 /* We've not selected an architecture yet. Set the default
3929 now. We do this lazily so that an initial .cpu or .arch directive
3931 if (!m68k_set_cpu (TARGET_CPU
, 1, 1))
3932 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU
);
3937 /* In MRI mode, the instruction and operands are separated by a
3938 space. Anything following the operands is a comment. The label
3939 has already been removed. */
3947 for (s
= str
; *s
!= '\0'; s
++)
3949 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
3967 inquote
= ! inquote
;
3972 memset (&the_ins
, '\0', sizeof (the_ins
));
3977 for (n
= 0; n
< the_ins
.numargs
; n
++)
3978 if (the_ins
.operands
[n
].error
)
3980 er
= the_ins
.operands
[n
].error
;
3986 as_bad (_("%s -- statement `%s' ignored"), er
, str
);
3990 /* If there is a current label, record that it marks an instruction. */
3991 if (current_label
!= NULL
)
3993 current_label
->text
= 1;
3994 current_label
= NULL
;
3998 /* Tie dwarf2 debug info to the address at the start of the insn. */
3999 dwarf2_emit_insn (0);
4002 if (the_ins
.nfrag
== 0)
4004 /* No frag hacking involved; just put it out. */
4005 toP
= frag_more (2 * the_ins
.numo
);
4006 fromP
= &the_ins
.opcode
[0];
4007 for (m
= the_ins
.numo
; m
; --m
)
4009 md_number_to_chars (toP
, (long) (*fromP
), 2);
4013 /* Put out symbol-dependent info. */
4014 for (m
= 0; m
< the_ins
.nrel
; m
++)
4016 switch (the_ins
.reloc
[m
].wid
)
4035 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4036 the_ins
.reloc
[m
].wid
);
4039 fixP
= fix_new_exp (frag_now
,
4040 ((toP
- frag_now
->fr_literal
)
4041 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4043 &the_ins
.reloc
[m
].exp
,
4044 the_ins
.reloc
[m
].pcrel
,
4045 get_reloc_code (n
, the_ins
.reloc
[m
].pcrel
,
4046 the_ins
.reloc
[m
].pic_reloc
));
4047 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4048 if (the_ins
.reloc
[m
].wid
== 'B')
4049 fixP
->fx_signed
= 1;
4054 /* There's some frag hacking. */
4056 /* Calculate the max frag size. */
4059 wid
= 2 * the_ins
.fragb
[0].fragoff
;
4060 for (n
= 1; n
< the_ins
.nfrag
; n
++)
4061 wid
+= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4062 /* frag_var part. */
4064 /* Make sure the whole insn fits in one chunk, in particular that
4065 the var part is attached, as we access one byte before the
4066 variable frag for byte branches. */
4070 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
4075 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
4077 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4078 toP
= frag_more (wid
);
4080 shorts_this_frag
= 0;
4081 for (m
= wid
/ 2; m
; --m
)
4083 md_number_to_chars (toP
, (long) (*fromP
), 2);
4088 for (m
= 0; m
< the_ins
.nrel
; m
++)
4090 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
4092 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
4095 wid
= the_ins
.reloc
[m
].wid
;
4098 the_ins
.reloc
[m
].wid
= 0;
4099 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4101 fixP
= fix_new_exp (frag_now
,
4102 ((toP
- frag_now
->fr_literal
)
4103 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
4105 &the_ins
.reloc
[m
].exp
,
4106 the_ins
.reloc
[m
].pcrel
,
4107 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4108 the_ins
.reloc
[m
].pic_reloc
));
4109 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4111 (void) frag_var (rs_machine_dependent
, 10, 0,
4112 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
4113 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
4115 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
4116 shorts_this_frag
= 0;
4119 toP
= frag_more (n
* 2);
4122 md_number_to_chars (toP
, (long) (*fromP
), 2);
4128 for (m
= 0; m
< the_ins
.nrel
; m
++)
4132 wid
= the_ins
.reloc
[m
].wid
;
4135 the_ins
.reloc
[m
].wid
= 0;
4136 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
4138 fixP
= fix_new_exp (frag_now
,
4139 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
4140 - shorts_this_frag
* 2),
4142 &the_ins
.reloc
[m
].exp
,
4143 the_ins
.reloc
[m
].pcrel
,
4144 get_reloc_code (wid
, the_ins
.reloc
[m
].pcrel
,
4145 the_ins
.reloc
[m
].pic_reloc
));
4146 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
4150 /* Comparison function used by qsort to rank the opcode entries by name. */
4153 m68k_compare_opcode (const void * v1
, const void * v2
)
4155 struct m68k_opcode
* op1
, * op2
;
4161 op1
= *(struct m68k_opcode
**) v1
;
4162 op2
= *(struct m68k_opcode
**) v2
;
4164 /* Compare the two names. If different, return the comparison.
4165 If the same, return the order they are in the opcode table. */
4166 ret
= strcmp (op1
->name
, op2
->name
);
4177 const struct m68k_opcode
*ins
;
4178 struct m68k_incant
*hack
, *slak
;
4179 const char *retval
= 0; /* Empty string, or error msg text. */
4182 /* Set up hash tables with 68000 instructions.
4183 similar to what the vax assembler does. */
4184 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4185 a copy of it at runtime, adding in the information we want but isn't
4186 there. I think it'd be better to have an awk script hack the table
4187 at compile time. Or even just xstr the table and use it as-is. But
4188 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4193 flag_reg_prefix_optional
= 1;
4195 if (! m68k_rel32_from_cmdline
)
4199 /* First sort the opcode table into alphabetical order to seperate
4200 the order that the assembler wants to see the opcodes from the
4201 order that the disassembler wants to see them. */
4202 m68k_sorted_opcodes
= xmalloc (m68k_numopcodes
* sizeof (* m68k_sorted_opcodes
));
4203 if (!m68k_sorted_opcodes
)
4204 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4205 m68k_numopcodes
* ((int) sizeof (* m68k_sorted_opcodes
)));
4207 for (i
= m68k_numopcodes
; i
--;)
4208 m68k_sorted_opcodes
[i
] = m68k_opcodes
+ i
;
4210 qsort (m68k_sorted_opcodes
, m68k_numopcodes
,
4211 sizeof (m68k_sorted_opcodes
[0]), m68k_compare_opcode
);
4213 op_hash
= hash_new ();
4215 obstack_begin (&robyn
, 4000);
4216 for (i
= 0; i
< m68k_numopcodes
; i
++)
4218 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4221 ins
= m68k_sorted_opcodes
[i
];
4223 /* We *could* ignore insns that don't match our
4224 arch here by just leaving them out of the hash. */
4225 slak
->m_operands
= ins
->args
;
4226 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
4227 slak
->m_arch
= ins
->arch
;
4228 slak
->m_opcode
= ins
->opcode
;
4229 /* This is kludgey. */
4230 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
4231 if (i
+ 1 != m68k_numopcodes
4232 && !strcmp (ins
->name
, m68k_sorted_opcodes
[i
+ 1]->name
))
4234 slak
->m_next
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4239 slak
= slak
->m_next
;
4243 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
4245 as_fatal (_("Internal Error: Can't hash %s: %s"), ins
->name
, retval
);
4248 for (i
= 0; i
< m68k_numaliases
; i
++)
4250 const char *name
= m68k_opcode_aliases
[i
].primary
;
4251 const char *alias
= m68k_opcode_aliases
[i
].alias
;
4252 PTR val
= hash_find (op_hash
, name
);
4255 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4256 retval
= hash_insert (op_hash
, alias
, val
);
4258 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4261 /* In MRI mode, all unsized branches are variable sized. Normally,
4262 they are word sized. */
4265 static struct m68k_opcode_alias mri_aliases
[] =
4286 i
< (int) (sizeof mri_aliases
/ sizeof mri_aliases
[0]);
4289 const char *name
= mri_aliases
[i
].primary
;
4290 const char *alias
= mri_aliases
[i
].alias
;
4291 PTR val
= hash_find (op_hash
, name
);
4294 as_fatal (_("Internal Error: Can't find %s in hash table"), name
);
4295 retval
= hash_jam (op_hash
, alias
, val
);
4297 as_fatal (_("Internal Error: Can't hash %s: %s"), alias
, retval
);
4301 for (i
= 0; i
< (int) sizeof (notend_table
); i
++)
4303 notend_table
[i
] = 0;
4304 alt_notend_table
[i
] = 0;
4307 notend_table
[','] = 1;
4308 notend_table
['{'] = 1;
4309 notend_table
['}'] = 1;
4310 alt_notend_table
['a'] = 1;
4311 alt_notend_table
['A'] = 1;
4312 alt_notend_table
['d'] = 1;
4313 alt_notend_table
['D'] = 1;
4314 alt_notend_table
['#'] = 1;
4315 alt_notend_table
['&'] = 1;
4316 alt_notend_table
['f'] = 1;
4317 alt_notend_table
['F'] = 1;
4318 #ifdef REGISTER_PREFIX
4319 alt_notend_table
[REGISTER_PREFIX
] = 1;
4322 /* We need to put '(' in alt_notend_table to handle
4323 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4324 alt_notend_table
['('] = 1;
4326 /* We need to put '@' in alt_notend_table to handle
4327 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4328 alt_notend_table
['@'] = 1;
4330 /* We need to put digits in alt_notend_table to handle
4331 bfextu %d0{24:1},%d0 */
4332 alt_notend_table
['0'] = 1;
4333 alt_notend_table
['1'] = 1;
4334 alt_notend_table
['2'] = 1;
4335 alt_notend_table
['3'] = 1;
4336 alt_notend_table
['4'] = 1;
4337 alt_notend_table
['5'] = 1;
4338 alt_notend_table
['6'] = 1;
4339 alt_notend_table
['7'] = 1;
4340 alt_notend_table
['8'] = 1;
4341 alt_notend_table
['9'] = 1;
4343 #ifndef MIT_SYNTAX_ONLY
4344 /* Insert pseudo ops, these have to go into the opcode table since
4345 gas expects pseudo ops to start with a dot. */
4349 while (mote_pseudo_table
[n
].poc_name
)
4351 hack
= obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
4352 hash_insert (op_hash
,
4353 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
4354 hack
->m_operands
= 0;
4364 record_alignment (text_section
, 2);
4365 record_alignment (data_section
, 2);
4366 record_alignment (bss_section
, 2);
4371 select_control_regs (void)
4373 /* Note which set of "movec" control registers is available. */
4374 switch (current_chip
)
4378 as_warn (_("architecture not yet selected: defaulting to 68020"));
4379 control_regs
= m68020_control_regs
;
4383 control_regs
= m68000_control_regs
;
4386 control_regs
= m68010_control_regs
;
4390 control_regs
= m68020_control_regs
;
4393 control_regs
= m68040_control_regs
;
4396 control_regs
= m68060_control_regs
;
4399 control_regs
= cpu32_control_regs
;
4405 control_regs
= mcf_control_regs
;
4408 control_regs
= mcf5249_control_regs
;
4412 control_regs
= mcf528x_control_regs
;
4416 control_regs
= mcfv4e_control_regs
;
4419 control_regs
= mcf5208_control_regs
;
4422 control_regs
= mcf5213_control_regs
;
4425 control_regs
= mcf5329_control_regs
;
4433 /* This is called when a label is defined. */
4436 m68k_frob_label (symbolS
*sym
)
4438 struct label_line
*n
;
4440 n
= (struct label_line
*) xmalloc (sizeof *n
);
4443 as_where (&n
->file
, &n
->line
);
4449 dwarf2_emit_label (sym
);
4453 /* This is called when a value that is not an instruction is emitted. */
4456 m68k_flush_pending_output (void)
4458 current_label
= NULL
;
4461 /* This is called at the end of the assembly, when the final value of
4462 the label is known. We warn if this is a text symbol aligned at an
4466 m68k_frob_symbol (symbolS
*sym
)
4468 if (S_GET_SEGMENT (sym
) == reg_section
4469 && (int) S_GET_VALUE (sym
) < 0)
4471 S_SET_SEGMENT (sym
, absolute_section
);
4472 S_SET_VALUE (sym
, ~(int)S_GET_VALUE (sym
));
4474 else if ((S_GET_VALUE (sym
) & 1) != 0)
4476 struct label_line
*l
;
4478 for (l
= labels
; l
!= NULL
; l
= l
->next
)
4480 if (l
->label
== sym
)
4483 as_warn_where (l
->file
, l
->line
,
4484 _("text label `%s' aligned to odd boundary"),
4492 /* This is called if we go in or out of MRI mode because of the .mri
4496 m68k_mri_mode_change (int on
)
4500 if (! flag_reg_prefix_optional
)
4502 flag_reg_prefix_optional
= 1;
4503 #ifdef REGISTER_PREFIX
4508 if (! m68k_rel32_from_cmdline
)
4513 if (! reg_prefix_optional_seen
)
4515 #ifdef REGISTER_PREFIX_OPTIONAL
4516 flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
4518 flag_reg_prefix_optional
= 0;
4520 #ifdef REGISTER_PREFIX
4525 if (! m68k_rel32_from_cmdline
)
4530 /* Equal to MAX_PRECISION in atof-ieee.c. */
4531 #define MAX_LITTLENUMS 6
4533 /* Turn a string in input_line_pointer into a floating point constant
4534 of type TYPE, and store the appropriate bytes in *LITP. The number
4535 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4536 returned, or NULL on OK. */
4539 md_atof (int type
, char *litP
, int *sizeP
)
4542 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
4543 LITTLENUM_TYPE
*wordP
;
4574 return _("Bad call to MD_ATOF()");
4576 t
= atof_ieee (input_line_pointer
, type
, words
);
4578 input_line_pointer
= t
;
4580 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
4581 for (wordP
= words
; prec
--;)
4583 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
4584 litP
+= sizeof (LITTLENUM_TYPE
);
4590 md_number_to_chars (char *buf
, valueT val
, int n
)
4592 number_to_chars_bigendian (buf
, val
, n
);
4596 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
4598 offsetT val
= *valP
;
4599 addressT upper_limit
;
4600 offsetT lower_limit
;
4602 /* This is unnecessary but it convinces the native rs6000 compiler
4603 to generate the code we want. */
4604 char *buf
= fixP
->fx_frag
->fr_literal
;
4605 buf
+= fixP
->fx_where
;
4606 /* End ibm compiler workaround. */
4610 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4616 memset (buf
, 0, fixP
->fx_size
);
4617 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
4619 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4620 && !S_IS_DEFINED (fixP
->fx_addsy
)
4621 && !S_IS_WEAK (fixP
->fx_addsy
))
4622 S_SET_WEAK (fixP
->fx_addsy
);
4627 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
4628 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
4631 switch (fixP
->fx_size
)
4633 /* The cast to offsetT below are necessary to make code
4634 correct for machines where ints are smaller than offsetT. */
4638 lower_limit
= - (offsetT
) 0x80;
4641 *buf
++ = (val
>> 8);
4643 upper_limit
= 0x7fff;
4644 lower_limit
= - (offsetT
) 0x8000;
4647 *buf
++ = (val
>> 24);
4648 *buf
++ = (val
>> 16);
4649 *buf
++ = (val
>> 8);
4651 upper_limit
= 0x7fffffff;
4652 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* Avoid constant overflow. */
4655 BAD_CASE (fixP
->fx_size
);
4658 /* Fix up a negative reloc. */
4659 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
!= NULL
)
4661 fixP
->fx_addsy
= fixP
->fx_subsy
;
4662 fixP
->fx_subsy
= NULL
;
4666 /* For non-pc-relative values, it's conceivable we might get something
4667 like "0xff" for a byte field. So extend the upper part of the range
4668 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4669 so that we can do any range checking at all. */
4670 if (! fixP
->fx_pcrel
&& ! fixP
->fx_signed
)
4671 upper_limit
= upper_limit
* 2 + 1;
4673 if ((addressT
) val
> upper_limit
4674 && (val
> 0 || val
< lower_limit
))
4675 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("value out of range"));
4677 /* A one byte PC-relative reloc means a short branch. We can't use
4678 a short branch with a value of 0 or -1, because those indicate
4679 different opcodes (branches with longer offsets). fixup_segment
4680 in write.c may have clobbered fx_pcrel, so we need to examine the
4683 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
4684 && fixP
->fx_size
== 1
4685 && (fixP
->fx_addsy
== NULL
4686 || S_IS_DEFINED (fixP
->fx_addsy
))
4687 && (val
== 0 || val
== -1))
4688 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("invalid byte branch offset"));
4691 /* *fragP has been relaxed to its final size, and now needs to have
4692 the bytes inside it modified to conform to the new size There is UGLY
4696 md_convert_frag_1 (fragS
*fragP
)
4701 /* Address in object code of the displacement. */
4702 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4704 /* Address in gas core of the place to store the displacement. */
4705 /* This convinces the native rs6000 compiler to generate the code we
4707 register char *buffer_address
= fragP
->fr_literal
;
4708 buffer_address
+= fragP
->fr_fix
;
4709 /* End ibm compiler workaround. */
4711 /* The displacement of the address, from current location. */
4712 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4713 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4715 switch (fragP
->fr_subtype
)
4717 case TAB (BRANCHBWL
, BYTE
):
4718 case TAB (BRABSJUNC
, BYTE
):
4719 case TAB (BRABSJCOND
, BYTE
):
4720 case TAB (BRANCHBW
, BYTE
):
4721 know (issbyte (disp
));
4723 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
4724 _("short branch with zero offset: use :w"));
4725 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4726 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4727 fixP
->fx_pcrel_adjust
= -1;
4729 case TAB (BRANCHBWL
, SHORT
):
4730 case TAB (BRABSJUNC
, SHORT
):
4731 case TAB (BRABSJCOND
, SHORT
):
4732 case TAB (BRANCHBW
, SHORT
):
4733 fragP
->fr_opcode
[1] = 0x00;
4734 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4735 1, RELAX_RELOC_PC16
);
4738 case TAB (BRANCHBWL
, LONG
):
4739 fragP
->fr_opcode
[1] = (char) 0xFF;
4740 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4741 1, RELAX_RELOC_PC32
);
4744 case TAB (BRABSJUNC
, LONG
):
4745 if (fragP
->fr_opcode
[0] == 0x61) /* jbsr */
4747 if (flag_keep_pcrel
)
4748 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4749 fragP
->fr_opcode
[0] = 0x4E;
4750 fragP
->fr_opcode
[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4751 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4752 0, RELAX_RELOC_ABS32
);
4755 else if (fragP
->fr_opcode
[0] == 0x60) /* jbra */
4757 if (flag_keep_pcrel
)
4758 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4759 fragP
->fr_opcode
[0] = 0x4E;
4760 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4761 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4762 0, RELAX_RELOC_ABS32
);
4767 /* This cannot happen, because jbsr and jbra are the only two
4768 unconditional branches. */
4772 case TAB (BRABSJCOND
, LONG
):
4773 if (flag_keep_pcrel
)
4774 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4776 /* Only Bcc 68000 instructions can come here
4777 Change bcc into b!cc/jmp absl long. */
4778 fragP
->fr_opcode
[0] ^= 0x01; /* Invert bcc. */
4779 fragP
->fr_opcode
[1] = 0x06; /* Branch offset = 6. */
4781 /* JF: these used to be fr_opcode[2,3], but they may be in a
4782 different frag, in which case referring to them is a no-no.
4783 Only fr_opcode[0,1] are guaranteed to work. */
4784 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4785 *buffer_address
++ = (char) 0xf9;
4786 fragP
->fr_fix
+= 2; /* Account for jmp instruction. */
4787 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4788 fragP
->fr_offset
, 0, RELAX_RELOC_ABS32
);
4791 case TAB (FBRANCH
, SHORT
):
4792 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4793 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4794 1, RELAX_RELOC_PC16
);
4797 case TAB (FBRANCH
, LONG
):
4798 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit. */
4799 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4800 1, RELAX_RELOC_PC32
);
4803 case TAB (DBCCLBR
, SHORT
):
4804 case TAB (DBCCABSJ
, SHORT
):
4805 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4806 1, RELAX_RELOC_PC16
);
4809 case TAB (DBCCLBR
, LONG
):
4810 /* Only DBcc instructions can come here.
4811 Change dbcc into dbcc/bral.
4812 JF: these used to be fr_opcode[2-7], but that's wrong. */
4813 if (flag_keep_pcrel
)
4814 as_fatal (_("Tried to convert DBcc to absolute jump"));
4816 *buffer_address
++ = 0x00; /* Branch offset = 4. */
4817 *buffer_address
++ = 0x04;
4818 *buffer_address
++ = 0x60; /* Put in bra pc+6. */
4819 *buffer_address
++ = 0x06;
4820 *buffer_address
++ = 0x60; /* Put in bral (0x60ff). */
4821 *buffer_address
++ = (char) 0xff;
4823 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
4824 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
, 1,
4828 case TAB (DBCCABSJ
, LONG
):
4829 /* Only DBcc instructions can come here.
4830 Change dbcc into dbcc/jmp.
4831 JF: these used to be fr_opcode[2-7], but that's wrong. */
4832 if (flag_keep_pcrel
)
4833 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4835 *buffer_address
++ = 0x00; /* Branch offset = 4. */
4836 *buffer_address
++ = 0x04;
4837 *buffer_address
++ = 0x60; /* Put in bra pc + 6. */
4838 *buffer_address
++ = 0x06;
4839 *buffer_address
++ = 0x4e; /* Put in jmp long (0x4ef9). */
4840 *buffer_address
++ = (char) 0xf9;
4842 fragP
->fr_fix
+= 6; /* Account for bra/jmp instructions. */
4843 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
, 0,
4847 case TAB (PCREL1632
, SHORT
):
4848 fragP
->fr_opcode
[1] &= ~0x3F;
4849 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
4850 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4851 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4854 case TAB (PCREL1632
, LONG
):
4855 /* Already set to mode 7.3; this indicates: PC indirect with
4856 suppressed index, 32-bit displacement. */
4857 *buffer_address
++ = 0x01;
4858 *buffer_address
++ = 0x70;
4860 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4861 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4862 fixP
->fx_pcrel_adjust
= 2;
4865 case TAB (PCINDEX
, BYTE
):
4866 assert (fragP
->fr_fix
>= 2);
4867 buffer_address
[-2] &= ~1;
4868 fixP
= fix_new (fragP
, fragP
->fr_fix
- 1, 1, fragP
->fr_symbol
,
4869 fragP
->fr_offset
, 1, RELAX_RELOC_PC8
);
4870 fixP
->fx_pcrel_adjust
= 1;
4872 case TAB (PCINDEX
, SHORT
):
4873 assert (fragP
->fr_fix
>= 2);
4874 buffer_address
[-2] |= 0x1;
4875 buffer_address
[-1] = 0x20;
4876 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4877 fragP
->fr_offset
, 1, RELAX_RELOC_PC16
);
4878 fixP
->fx_pcrel_adjust
= 2;
4881 case TAB (PCINDEX
, LONG
):
4882 assert (fragP
->fr_fix
>= 2);
4883 buffer_address
[-2] |= 0x1;
4884 buffer_address
[-1] = 0x30;
4885 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4886 fragP
->fr_offset
, 1, RELAX_RELOC_PC32
);
4887 fixP
->fx_pcrel_adjust
= 2;
4890 case TAB (ABSTOPCREL
, SHORT
):
4891 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
4892 1, RELAX_RELOC_PC16
);
4895 case TAB (ABSTOPCREL
, LONG
):
4896 if (flag_keep_pcrel
)
4897 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4898 /* The thing to do here is force it to ABSOLUTE LONG, since
4899 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4900 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4902 fragP
->fr_opcode
[1] &= ~0x3F;
4903 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4904 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4905 0, RELAX_RELOC_ABS32
);
4912 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
4913 segT sec ATTRIBUTE_UNUSED
,
4916 md_convert_frag_1 (fragP
);
4919 /* Force truly undefined symbols to their maximum size, and generally set up
4920 the frag list to be relaxed
4923 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
4925 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4926 switch (fragP
->fr_subtype
)
4928 case TAB (BRANCHBWL
, SZ_UNDEF
):
4929 case TAB (BRABSJUNC
, SZ_UNDEF
):
4930 case TAB (BRABSJCOND
, SZ_UNDEF
):
4932 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4933 && relaxable_symbol (fragP
->fr_symbol
))
4935 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4937 else if (flag_short_refs
)
4939 /* Symbol is undefined and we want short ref. */
4940 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4944 /* Symbol is still undefined. Make it LONG. */
4945 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
4950 case TAB (BRANCHBW
, SZ_UNDEF
):
4952 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4953 && relaxable_symbol (fragP
->fr_symbol
))
4955 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4959 /* Symbol is undefined and we don't have long branches. */
4960 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4965 case TAB (FBRANCH
, SZ_UNDEF
):
4966 case TAB (DBCCLBR
, SZ_UNDEF
):
4967 case TAB (DBCCABSJ
, SZ_UNDEF
):
4968 case TAB (PCREL1632
, SZ_UNDEF
):
4970 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4971 && relaxable_symbol (fragP
->fr_symbol
))
4974 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4978 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), LONG
);
4983 case TAB (PCINDEX
, SZ_UNDEF
):
4984 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4985 && relaxable_symbol (fragP
->fr_symbol
)))
4987 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
4991 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
4995 case TAB (ABSTOPCREL
, SZ_UNDEF
):
4997 if ((S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4998 && relaxable_symbol (fragP
->fr_symbol
)))
5000 fragP
->fr_subtype
= TAB (ABSTOPCREL
, SHORT
);
5004 fragP
->fr_subtype
= TAB (ABSTOPCREL
, LONG
);
5013 /* Now that SZ_UNDEF are taken care of, check others. */
5014 switch (fragP
->fr_subtype
)
5016 case TAB (BRANCHBWL
, BYTE
):
5017 case TAB (BRABSJUNC
, BYTE
):
5018 case TAB (BRABSJCOND
, BYTE
):
5019 case TAB (BRANCHBW
, BYTE
):
5020 /* We can't do a short jump to the next instruction, so in that
5021 case we force word mode. If the symbol is at the start of a
5022 frag, and it is the next frag with any data in it (usually
5023 this is just the next frag, but assembler listings may
5024 introduce empty frags), we must use word mode. */
5025 if (fragP
->fr_symbol
)
5029 sym_frag
= symbol_get_frag (fragP
->fr_symbol
);
5030 if (S_GET_VALUE (fragP
->fr_symbol
) == sym_frag
->fr_address
)
5034 for (l
= fragP
->fr_next
; l
&& l
!= sym_frag
; l
= l
->fr_next
)
5038 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
5045 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5048 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5049 /* the bit-field entries in the relocation_info struct plays hell
5050 with the byte-order problems of cross-assembly. So as a hack,
5051 I added this mach. dependent ri twiddler. Ugly, but it gets
5053 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5054 are symbolnum, most sig. byte first. Last byte is broken up with
5055 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5056 nibble as nuthin. (on Sun 3 at least) */
5057 /* Translate the internal relocation information into target-specific
5061 md_ri_to_chars (char *the_bytes
, struct reloc_info_generic
*ri
)
5064 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
5065 /* Now the fun stuff. */
5066 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
5067 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
5068 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
5069 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80)
5070 | ((ri
->r_length
<< 5) & 0x60)
5071 | ((ri
->r_extern
<< 4) & 0x10));
5076 #endif /* OBJ_AOUT or OBJ_BOUT */
5078 #ifndef WORKING_DOT_WORD
5079 int md_short_jump_size
= 4;
5080 int md_long_jump_size
= 6;
5083 md_create_short_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5084 fragS
*frag ATTRIBUTE_UNUSED
,
5085 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
5089 offset
= to_addr
- (from_addr
+ 2);
5091 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
5092 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
5096 md_create_long_jump (char *ptr
, addressT from_addr
, addressT to_addr
,
5097 fragS
*frag
, symbolS
*to_symbol
)
5101 if (!HAVE_LONG_BRANCH (current_architecture
))
5103 if (flag_keep_pcrel
)
5104 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5105 offset
= to_addr
- S_GET_VALUE (to_symbol
);
5106 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
5107 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5108 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
5113 offset
= to_addr
- (from_addr
+ 2);
5114 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
5115 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
5121 /* Different values of OK tell what its OK to return. Things that
5122 aren't OK are an error (what a shock, no?)
5125 10: Absolute 1:8 only
5126 20: Absolute 0:7 only
5127 30: absolute 0:15 only
5128 40: Absolute 0:31 only
5129 50: absolute 0:127 only
5130 55: absolute -64:63 only
5131 60: absolute -128:127 only
5132 70: absolute 0:4095 only
5133 80: absolute -1, 1:7 only
5137 get_num (struct m68k_exp
*exp
, int ok
)
5139 if (exp
->exp
.X_op
== O_absent
)
5141 /* Do the same thing the VAX asm does. */
5142 op (exp
) = O_constant
;
5148 as_warn (_("expression out of range: defaulting to 1"));
5152 else if (exp
->exp
.X_op
== O_constant
)
5157 if ((valueT
) TRUNC (offs (exp
)) - 1 > 7)
5159 as_warn (_("expression out of range: defaulting to 1"));
5164 if ((valueT
) TRUNC (offs (exp
)) > 7)
5168 if ((valueT
) TRUNC (offs (exp
)) > 15)
5172 if ((valueT
) TRUNC (offs (exp
)) > 32)
5176 if ((valueT
) TRUNC (offs (exp
)) > 127)
5180 if ((valueT
) SEXT (offs (exp
)) + 64 > 127)
5184 if ((valueT
) SEXT (offs (exp
)) + 128 > 255)
5188 if ((valueT
) TRUNC (offs (exp
)) > 4095)
5191 as_warn (_("expression out of range: defaulting to 0"));
5196 if ((valueT
) TRUNC (offs (exp
)) != 0xffffffff
5197 && (valueT
) TRUNC (offs (exp
)) - 1 > 6)
5199 as_warn (_("expression out of range: defaulting to 1"));
5207 else if (exp
->exp
.X_op
== O_big
)
5209 if (offs (exp
) <= 0 /* flonum. */
5210 && (ok
== 90 /* no bignums */
5211 || (ok
> 10 /* Small-int ranges including 0 ok. */
5212 /* If we have a flonum zero, a zero integer should
5213 do as well (e.g., in moveq). */
5214 && generic_floating_point_number
.exponent
== 0
5215 && generic_floating_point_number
.low
[0] == 0)))
5217 /* HACK! Turn it into a long. */
5218 LITTLENUM_TYPE words
[6];
5220 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
5221 op (exp
) = O_constant
;
5224 offs (exp
) = words
[1] | (words
[0] << 16);
5228 op (exp
) = O_constant
;
5231 offs (exp
) = (ok
== 10) ? 1 : 0;
5232 as_warn (_("Can't deal with expression; defaulting to %ld"),
5238 if (ok
>= 10 && ok
<= 80)
5240 op (exp
) = O_constant
;
5243 offs (exp
) = (ok
== 10) ? 1 : 0;
5244 as_warn (_("Can't deal with expression; defaulting to %ld"),
5249 if (exp
->size
!= SIZE_UNSPEC
)
5257 if (!isbyte (offs (exp
)))
5258 as_warn (_("expression doesn't fit in BYTE"));
5261 if (!isword (offs (exp
)))
5262 as_warn (_("expression doesn't fit in WORD"));
5270 /* These are the back-ends for the various machine dependent pseudo-ops. */
5273 s_data1 (int ignore ATTRIBUTE_UNUSED
)
5275 subseg_set (data_section
, 1);
5276 demand_empty_rest_of_line ();
5280 s_data2 (int ignore ATTRIBUTE_UNUSED
)
5282 subseg_set (data_section
, 2);
5283 demand_empty_rest_of_line ();
5287 s_bss (int ignore ATTRIBUTE_UNUSED
)
5289 /* We don't support putting frags in the BSS segment, we fake it
5290 by marking in_bss, then looking at s_skip for clues. */
5292 subseg_set (bss_section
, 0);
5293 demand_empty_rest_of_line ();
5297 s_even (int ignore ATTRIBUTE_UNUSED
)
5300 register long temp_fill
;
5302 temp
= 1; /* JF should be 2? */
5303 temp_fill
= get_absolute_expression ();
5304 if (!need_pass_2
) /* Never make frag if expect extra pass. */
5305 frag_align (temp
, (int) temp_fill
, 0);
5306 demand_empty_rest_of_line ();
5307 record_alignment (now_seg
, temp
);
5311 s_proc (int ignore ATTRIBUTE_UNUSED
)
5313 demand_empty_rest_of_line ();
5316 /* Pseudo-ops handled for MRI compatibility. */
5318 /* This function returns non-zero if the argument is a conditional
5319 pseudo-op. This is called when checking whether a pending
5320 alignment is needed. */
5323 m68k_conditional_pseudoop (pseudo_typeS
*pop
)
5325 return (pop
->poc_handler
== s_mri_if
5326 || pop
->poc_handler
== s_mri_else
);
5329 /* Handle an MRI style chip specification. */
5338 s
= input_line_pointer
;
5339 /* We can't use get_symbol_end since the processor names are not proper
5341 while (is_part_of_name (c
= *input_line_pointer
++))
5343 *--input_line_pointer
= 0;
5344 for (i
= 0; m68k_cpus
[i
].name
; i
++)
5345 if (strcasecmp (s
, m68k_cpus
[i
].name
) == 0)
5347 if (!m68k_cpus
[i
].name
)
5349 as_bad (_("%s: unrecognized processor name"), s
);
5350 *input_line_pointer
= c
;
5351 ignore_rest_of_line ();
5354 *input_line_pointer
= c
;
5356 if (*input_line_pointer
== '/')
5357 current_architecture
= 0;
5359 current_architecture
&= m68881
| m68851
;
5360 current_architecture
|= m68k_cpus
[i
].arch
& ~(m68881
| m68851
);
5361 current_chip
= m68k_cpus
[i
].chip
;
5363 while (*input_line_pointer
== '/')
5365 ++input_line_pointer
;
5366 s
= input_line_pointer
;
5367 /* We can't use get_symbol_end since the processor names are not
5369 while (is_part_of_name (c
= *input_line_pointer
++))
5371 *--input_line_pointer
= 0;
5372 if (strcmp (s
, "68881") == 0)
5373 current_architecture
|= m68881
;
5374 else if (strcmp (s
, "68851") == 0)
5375 current_architecture
|= m68851
;
5376 *input_line_pointer
= c
;
5379 /* Update info about available control registers. */
5380 select_control_regs ();
5383 /* The MRI CHIP pseudo-op. */
5386 s_chip (int ignore ATTRIBUTE_UNUSED
)
5392 stop
= mri_comment_field (&stopc
);
5395 mri_comment_end (stop
, stopc
);
5396 demand_empty_rest_of_line ();
5399 /* The MRI FOPT pseudo-op. */
5402 s_fopt (int ignore ATTRIBUTE_UNUSED
)
5406 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
5410 input_line_pointer
+= 3;
5411 temp
= get_absolute_expression ();
5412 if (temp
< 0 || temp
> 7)
5413 as_bad (_("bad coprocessor id"));
5415 m68k_float_copnum
= COP0
+ temp
;
5419 as_bad (_("unrecognized fopt option"));
5420 ignore_rest_of_line ();
5424 demand_empty_rest_of_line ();
5427 /* The structure used to handle the MRI OPT pseudo-op. */
5431 /* The name of the option. */
5434 /* If this is not NULL, just call this function. The first argument
5435 is the ARG field of this structure, the second argument is
5436 whether the option was negated. */
5437 void (*pfn
) (int arg
, int on
);
5439 /* If this is not NULL, and the PFN field is NULL, set the variable
5440 this points to. Set it to the ARG field if the option was not
5441 negated, and the NOTARG field otherwise. */
5444 /* The value to pass to PFN or to assign to *PVAR. */
5447 /* The value to assign to *PVAR if the option is negated. If PFN is
5448 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5449 the option may not be negated. */
5453 /* The table used to handle the MRI OPT pseudo-op. */
5455 static void skip_to_comma (int, int);
5456 static void opt_nest (int, int);
5457 static void opt_chip (int, int);
5458 static void opt_list (int, int);
5459 static void opt_list_symbols (int, int);
5461 static const struct opt_action opt_table
[] =
5463 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
5465 /* We do relaxing, so there is little use for these options. */
5466 { "b", 0, 0, 0, 0 },
5467 { "brs", 0, 0, 0, 0 },
5468 { "brb", 0, 0, 0, 0 },
5469 { "brl", 0, 0, 0, 0 },
5470 { "brw", 0, 0, 0, 0 },
5472 { "c", 0, 0, 0, 0 },
5473 { "cex", 0, 0, 0, 0 },
5474 { "case", 0, &symbols_case_sensitive
, 1, 0 },
5475 { "cl", 0, 0, 0, 0 },
5476 { "cre", 0, 0, 0, 0 },
5477 { "d", 0, &flag_keep_locals
, 1, 0 },
5478 { "e", 0, 0, 0, 0 },
5479 { "f", 0, &flag_short_refs
, 1, 0 },
5480 { "frs", 0, &flag_short_refs
, 1, 0 },
5481 { "frl", 0, &flag_short_refs
, 0, 1 },
5482 { "g", 0, 0, 0, 0 },
5483 { "i", 0, 0, 0, 0 },
5484 { "m", 0, 0, 0, 0 },
5485 { "mex", 0, 0, 0, 0 },
5486 { "mc", 0, 0, 0, 0 },
5487 { "md", 0, 0, 0, 0 },
5488 { "nest", opt_nest
, 0, 0, 0 },
5489 { "next", skip_to_comma
, 0, 0, 0 },
5490 { "o", 0, 0, 0, 0 },
5491 { "old", 0, 0, 0, 0 },
5492 { "op", skip_to_comma
, 0, 0, 0 },
5493 { "pco", 0, 0, 0, 0 },
5494 { "p", opt_chip
, 0, 0, 0 },
5495 { "pcr", 0, 0, 0, 0 },
5496 { "pcs", 0, 0, 0, 0 },
5497 { "r", 0, 0, 0, 0 },
5498 { "quick", 0, &m68k_quick
, 1, 0 },
5499 { "rel32", 0, &m68k_rel32
, 1, 0 },
5500 { "s", opt_list
, 0, 0, 0 },
5501 { "t", opt_list_symbols
, 0, 0, 0 },
5502 { "w", 0, &flag_no_warnings
, 0, 1 },
5506 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5508 /* The MRI OPT pseudo-op. */
5511 s_opt (int ignore ATTRIBUTE_UNUSED
)
5519 const struct opt_action
*o
;
5524 if (*input_line_pointer
== '-')
5526 ++input_line_pointer
;
5529 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
5531 input_line_pointer
+= 2;
5535 s
= input_line_pointer
;
5536 c
= get_symbol_end ();
5538 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
5540 if (strcasecmp (s
, o
->name
) == 0)
5544 /* Restore input_line_pointer now in case the option
5546 *input_line_pointer
= c
;
5547 (*o
->pfn
) (o
->arg
, t
);
5549 else if (o
->pvar
!= NULL
)
5551 if (! t
&& o
->arg
== o
->notarg
)
5552 as_bad (_("option `%s' may not be negated"), s
);
5553 *input_line_pointer
= c
;
5554 *o
->pvar
= t
? o
->arg
: o
->notarg
;
5557 *input_line_pointer
= c
;
5563 as_bad (_("option `%s' not recognized"), s
);
5564 *input_line_pointer
= c
;
5567 while (*input_line_pointer
++ == ',');
5569 /* Move back to terminating character. */
5570 --input_line_pointer
;
5571 demand_empty_rest_of_line ();
5574 /* Skip ahead to a comma. This is used for OPT options which we do
5575 not support and which take arguments. */
5578 skip_to_comma (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5580 while (*input_line_pointer
!= ','
5581 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5582 ++input_line_pointer
;
5585 /* Handle the OPT NEST=depth option. */
5588 opt_nest (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5590 if (*input_line_pointer
!= '=')
5592 as_bad (_("bad format of OPT NEST=depth"));
5596 ++input_line_pointer
;
5597 max_macro_nest
= get_absolute_expression ();
5600 /* Handle the OPT P=chip option. */
5603 opt_chip (int arg ATTRIBUTE_UNUSED
, int on ATTRIBUTE_UNUSED
)
5605 if (*input_line_pointer
!= '=')
5607 /* This is just OPT P, which we do not support. */
5611 ++input_line_pointer
;
5615 /* Handle the OPT S option. */
5618 opt_list (int arg ATTRIBUTE_UNUSED
, int on
)
5623 /* Handle the OPT T option. */
5626 opt_list_symbols (int arg ATTRIBUTE_UNUSED
, int on
)
5629 listing
|= LISTING_SYMBOLS
;
5631 listing
&= ~LISTING_SYMBOLS
;
5634 /* Handle the MRI REG pseudo-op. */
5637 s_reg (int ignore ATTRIBUTE_UNUSED
)
5646 if (line_label
== NULL
)
5648 as_bad (_("missing label"));
5649 ignore_rest_of_line ();
5654 stop
= mri_comment_field (&stopc
);
5658 s
= input_line_pointer
;
5659 while (ISALNUM (*input_line_pointer
)
5660 #ifdef REGISTER_PREFIX
5661 || *input_line_pointer
== REGISTER_PREFIX
5663 || *input_line_pointer
== '/'
5664 || *input_line_pointer
== '-')
5665 ++input_line_pointer
;
5666 c
= *input_line_pointer
;
5667 *input_line_pointer
= '\0';
5669 if (m68k_ip_op (s
, &rop
) != 0)
5671 if (rop
.error
== NULL
)
5672 as_bad (_("bad register list"));
5674 as_bad (_("bad register list: %s"), rop
.error
);
5675 *input_line_pointer
= c
;
5676 ignore_rest_of_line ();
5680 *input_line_pointer
= c
;
5682 if (rop
.mode
== REGLST
)
5684 else if (rop
.mode
== DREG
)
5685 mask
= 1 << (rop
.reg
- DATA0
);
5686 else if (rop
.mode
== AREG
)
5687 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
5688 else if (rop
.mode
== FPREG
)
5689 mask
= 1 << (rop
.reg
- FP0
+ 16);
5690 else if (rop
.mode
== CONTROL
5693 else if (rop
.mode
== CONTROL
5696 else if (rop
.mode
== CONTROL
5701 as_bad (_("bad register list"));
5702 ignore_rest_of_line ();
5706 S_SET_SEGMENT (line_label
, reg_section
);
5707 S_SET_VALUE (line_label
, ~mask
);
5708 symbol_set_frag (line_label
, &zero_address_frag
);
5711 mri_comment_end (stop
, stopc
);
5713 demand_empty_rest_of_line ();
5716 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5720 struct save_opts
*next
;
5722 int symbols_case_sensitive
;
5731 /* FIXME: We don't save OPT S. */
5734 /* This variable holds the stack of saved options. */
5736 static struct save_opts
*save_stack
;
5738 /* The MRI SAVE pseudo-op. */
5741 s_save (int ignore ATTRIBUTE_UNUSED
)
5743 struct save_opts
*s
;
5745 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
5746 s
->abspcadd
= m68k_abspcadd
;
5747 s
->symbols_case_sensitive
= symbols_case_sensitive
;
5748 s
->keep_locals
= flag_keep_locals
;
5749 s
->short_refs
= flag_short_refs
;
5750 s
->architecture
= current_architecture
;
5751 s
->chip
= current_chip
;
5752 s
->quick
= m68k_quick
;
5753 s
->rel32
= m68k_rel32
;
5754 s
->listing
= listing
;
5755 s
->no_warnings
= flag_no_warnings
;
5757 s
->next
= save_stack
;
5760 demand_empty_rest_of_line ();
5763 /* The MRI RESTORE pseudo-op. */
5766 s_restore (int ignore ATTRIBUTE_UNUSED
)
5768 struct save_opts
*s
;
5770 if (save_stack
== NULL
)
5772 as_bad (_("restore without save"));
5773 ignore_rest_of_line ();
5778 save_stack
= s
->next
;
5780 m68k_abspcadd
= s
->abspcadd
;
5781 symbols_case_sensitive
= s
->symbols_case_sensitive
;
5782 flag_keep_locals
= s
->keep_locals
;
5783 flag_short_refs
= s
->short_refs
;
5784 current_architecture
= s
->architecture
;
5785 current_chip
= s
->chip
;
5786 m68k_quick
= s
->quick
;
5787 m68k_rel32
= s
->rel32
;
5788 listing
= s
->listing
;
5789 flag_no_warnings
= s
->no_warnings
;
5793 demand_empty_rest_of_line ();
5796 /* Types of MRI structured control directives. */
5798 enum mri_control_type
5806 /* This structure is used to stack the MRI structured control
5809 struct mri_control_info
5811 /* The directive within which this one is enclosed. */
5812 struct mri_control_info
*outer
;
5814 /* The type of directive. */
5815 enum mri_control_type type
;
5817 /* Whether an ELSE has been in an IF. */
5820 /* The add or sub statement at the end of a FOR. */
5823 /* The label of the top of a FOR or REPEAT loop. */
5826 /* The label to jump to for the next iteration, or the else
5827 expression of a conditional. */
5830 /* The label to jump to to break out of the loop, or the label past
5831 the end of a conditional. */
5835 /* The stack of MRI structured control directives. */
5837 static struct mri_control_info
*mri_control_stack
;
5839 /* The current MRI structured control directive index number, used to
5840 generate label names. */
5842 static int mri_control_index
;
5844 /* Assemble an instruction for an MRI structured control directive. */
5847 mri_assemble (char *str
)
5851 /* md_assemble expects the opcode to be in lower case. */
5852 for (s
= str
; *s
!= ' ' && *s
!= '\0'; s
++)
5858 /* Generate a new MRI label structured control directive label name. */
5861 mri_control_label (void)
5865 n
= (char *) xmalloc (20);
5866 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
5867 ++mri_control_index
;
5871 /* Create a new MRI structured control directive. */
5873 static struct mri_control_info
*
5874 push_mri_control (enum mri_control_type type
)
5876 struct mri_control_info
*n
;
5878 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
5882 if (type
== mri_if
|| type
== mri_while
)
5885 n
->top
= mri_control_label ();
5886 n
->next
= mri_control_label ();
5887 n
->bottom
= mri_control_label ();
5889 n
->outer
= mri_control_stack
;
5890 mri_control_stack
= n
;
5895 /* Pop off the stack of MRI structured control directives. */
5898 pop_mri_control (void)
5900 struct mri_control_info
*n
;
5902 n
= mri_control_stack
;
5903 mri_control_stack
= n
->outer
;
5911 /* Recognize a condition code in an MRI structured control expression. */
5914 parse_mri_condition (int *pcc
)
5918 know (*input_line_pointer
== '<');
5920 ++input_line_pointer
;
5921 c1
= *input_line_pointer
++;
5922 c2
= *input_line_pointer
++;
5924 if (*input_line_pointer
!= '>')
5926 as_bad (_("syntax error in structured control directive"));
5930 ++input_line_pointer
;
5936 *pcc
= (c1
<< 8) | c2
;
5941 /* Parse a single operand in an MRI structured control expression. */
5944 parse_mri_control_operand (int *pcc
, char **leftstart
, char **leftstop
,
5945 char **rightstart
, char **rightstop
)
5957 if (*input_line_pointer
== '<')
5959 /* It's just a condition code. */
5960 return parse_mri_condition (pcc
);
5963 /* Look ahead for the condition code. */
5964 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5966 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
5971 as_bad (_("missing condition code in structured control directive"));
5975 *leftstart
= input_line_pointer
;
5977 if (*leftstop
> *leftstart
5978 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
5981 input_line_pointer
= s
;
5982 if (! parse_mri_condition (pcc
))
5985 /* Look ahead for AND or OR or end of line. */
5986 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
5988 /* We must make sure we don't misinterpret AND/OR at the end of labels!
5989 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
5991 if ((s
== input_line_pointer
5994 && ((strncasecmp (s
, "AND", 3) == 0
5995 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
5996 || (strncasecmp (s
, "OR", 2) == 0
5997 && (s
[2] == '.' || ! is_part_of_name (s
[2])))))
6001 *rightstart
= input_line_pointer
;
6003 if (*rightstop
> *rightstart
6004 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
6007 input_line_pointer
= s
;
6012 #define MCC(b1, b2) (((b1) << 8) | (b2))
6014 /* Swap the sense of a condition. This changes the condition so that
6015 it generates the same result when the operands are swapped. */
6018 swap_mri_condition (int cc
)
6022 case MCC ('h', 'i'): return MCC ('c', 's');
6023 case MCC ('l', 's'): return MCC ('c', 'c');
6024 /* <HS> is an alias for <CC>. */
6025 case MCC ('h', 's'):
6026 case MCC ('c', 'c'): return MCC ('l', 's');
6027 /* <LO> is an alias for <CS>. */
6028 case MCC ('l', 'o'):
6029 case MCC ('c', 's'): return MCC ('h', 'i');
6030 case MCC ('p', 'l'): return MCC ('m', 'i');
6031 case MCC ('m', 'i'): return MCC ('p', 'l');
6032 case MCC ('g', 'e'): return MCC ('l', 'e');
6033 case MCC ('l', 't'): return MCC ('g', 't');
6034 case MCC ('g', 't'): return MCC ('l', 't');
6035 case MCC ('l', 'e'): return MCC ('g', 'e');
6036 /* Issue a warning for conditions we can not swap. */
6037 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
6038 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
6039 case MCC ('v', 'c'):
6040 case MCC ('v', 's'):
6042 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6043 (char) (cc
>> 8), (char) (cc
));
6049 /* Reverse the sense of a condition. */
6052 reverse_mri_condition (int cc
)
6056 case MCC ('h', 'i'): return MCC ('l', 's');
6057 case MCC ('l', 's'): return MCC ('h', 'i');
6058 /* <HS> is an alias for <CC> */
6059 case MCC ('h', 's'): return MCC ('l', 'o');
6060 case MCC ('c', 'c'): return MCC ('c', 's');
6061 /* <LO> is an alias for <CS> */
6062 case MCC ('l', 'o'): return MCC ('h', 's');
6063 case MCC ('c', 's'): return MCC ('c', 'c');
6064 case MCC ('n', 'e'): return MCC ('e', 'q');
6065 case MCC ('e', 'q'): return MCC ('n', 'e');
6066 case MCC ('v', 'c'): return MCC ('v', 's');
6067 case MCC ('v', 's'): return MCC ('v', 'c');
6068 case MCC ('p', 'l'): return MCC ('m', 'i');
6069 case MCC ('m', 'i'): return MCC ('p', 'l');
6070 case MCC ('g', 'e'): return MCC ('l', 't');
6071 case MCC ('l', 't'): return MCC ('g', 'e');
6072 case MCC ('g', 't'): return MCC ('l', 'e');
6073 case MCC ('l', 'e'): return MCC ('g', 't');
6078 /* Build an MRI structured control expression. This generates test
6079 and branch instructions. It goes to TRUELAB if the condition is
6080 true, and to FALSELAB if the condition is false. Exactly one of
6081 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6082 is the size qualifier for the expression. EXTENT is the size to
6083 use for the branch. */
6086 build_mri_control_operand (int qual
, int cc
, char *leftstart
, char *leftstop
,
6087 char *rightstart
, char *rightstop
,
6088 const char *truelab
, const char *falselab
,
6094 if (leftstart
!= NULL
)
6096 struct m68k_op leftop
, rightop
;
6099 /* Swap the compare operands, if necessary, to produce a legal
6100 m68k compare instruction. Comparing a register operand with
6101 a non-register operand requires the register to be on the
6102 right (cmp, cmpa). Comparing an immediate value with
6103 anything requires the immediate value to be on the left
6108 (void) m68k_ip_op (leftstart
, &leftop
);
6113 (void) m68k_ip_op (rightstart
, &rightop
);
6116 if (rightop
.mode
== IMMED
6117 || ((leftop
.mode
== DREG
|| leftop
.mode
== AREG
)
6118 && (rightop
.mode
!= DREG
&& rightop
.mode
!= AREG
)))
6122 /* Correct conditional handling:
6123 if #1 <lt> d0 then ;means if (1 < d0)
6129 cmp #1,d0 if we do *not* swap the operands
6130 bgt true we need the swapped condition!
6137 leftstart
= rightstart
;
6140 leftstop
= rightstop
;
6145 cc
= swap_mri_condition (cc
);
6149 if (truelab
== NULL
)
6151 cc
= reverse_mri_condition (cc
);
6155 if (leftstart
!= NULL
)
6157 buf
= (char *) xmalloc (20
6158 + (leftstop
- leftstart
)
6159 + (rightstop
- rightstart
));
6165 *s
++ = TOLOWER (qual
);
6167 memcpy (s
, leftstart
, leftstop
- leftstart
);
6168 s
+= leftstop
- leftstart
;
6170 memcpy (s
, rightstart
, rightstop
- rightstart
);
6171 s
+= rightstop
- rightstart
;
6177 buf
= (char *) xmalloc (20 + strlen (truelab
));
6183 *s
++ = TOLOWER (extent
);
6185 strcpy (s
, truelab
);
6190 /* Parse an MRI structured control expression. This generates test
6191 and branch instructions. STOP is where the expression ends. It
6192 goes to TRUELAB if the condition is true, and to FALSELAB if the
6193 condition is false. Exactly one of TRUELAB and FALSELAB will be
6194 NULL, meaning to fall through. QUAL is the size qualifier for the
6195 expression. EXTENT is the size to use for the branch. */
6198 parse_mri_control_expression (char *stop
, int qual
, const char *truelab
,
6199 const char *falselab
, int extent
)
6211 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6212 &rightstart
, &rightstop
))
6218 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
6222 if (falselab
!= NULL
)
6225 flab
= mri_control_label ();
6227 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6228 rightstop
, (const char *) NULL
, flab
, extent
);
6230 input_line_pointer
+= 3;
6231 if (*input_line_pointer
!= '.'
6232 || input_line_pointer
[1] == '\0')
6236 qual
= input_line_pointer
[1];
6237 input_line_pointer
+= 2;
6240 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6241 &rightstart
, &rightstop
))
6247 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6248 rightstop
, truelab
, falselab
, extent
);
6250 if (falselab
== NULL
)
6253 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
6257 if (truelab
!= NULL
)
6260 tlab
= mri_control_label ();
6262 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6263 rightstop
, tlab
, (const char *) NULL
, extent
);
6265 input_line_pointer
+= 2;
6266 if (*input_line_pointer
!= '.'
6267 || input_line_pointer
[1] == '\0')
6271 qual
= input_line_pointer
[1];
6272 input_line_pointer
+= 2;
6275 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
6276 &rightstart
, &rightstop
))
6282 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6283 rightstop
, truelab
, falselab
, extent
);
6285 if (truelab
== NULL
)
6290 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
6291 rightstop
, truelab
, falselab
, extent
);
6295 if (input_line_pointer
!= stop
)
6296 as_bad (_("syntax error in structured control directive"));
6299 /* Handle the MRI IF pseudo-op. This may be a structured control
6300 directive, or it may be a regular assembler conditional, depending
6308 struct mri_control_info
*n
;
6310 /* A structured control directive must end with THEN with an
6311 optional qualifier. */
6312 s
= input_line_pointer
;
6313 /* We only accept '*' as introduction of comments if preceded by white space
6314 or at first column of a line (I think this can't actually happen here?)
6315 This is important when assembling:
6316 if d0 <ne> 12(a0,d0*2) then
6317 if d0 <ne> #CONST*20 then. */
6318 while (! (is_end_of_line
[(unsigned char) *s
]
6321 && (s
== input_line_pointer
6323 || *(s
-1) == '\t'))))
6326 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
6329 if (s
- input_line_pointer
> 1
6333 if (s
- input_line_pointer
< 3
6334 || strncasecmp (s
- 3, "THEN", 4) != 0)
6338 as_bad (_("missing then"));
6339 ignore_rest_of_line ();
6343 /* It's a conditional. */
6348 /* Since this might be a conditional if, this pseudo-op will be
6349 called even if we are supported to be ignoring input. Double
6350 check now. Clobber *input_line_pointer so that ignore_input
6351 thinks that this is not a special pseudo-op. */
6352 c
= *input_line_pointer
;
6353 *input_line_pointer
= 0;
6354 if (ignore_input ())
6356 *input_line_pointer
= c
;
6357 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6358 ++input_line_pointer
;
6359 demand_empty_rest_of_line ();
6362 *input_line_pointer
= c
;
6364 n
= push_mri_control (mri_if
);
6366 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
6367 n
->next
, s
[1] == '.' ? s
[2] : '\0');
6370 input_line_pointer
= s
+ 3;
6372 input_line_pointer
= s
+ 1;
6376 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6377 ++input_line_pointer
;
6380 demand_empty_rest_of_line ();
6383 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6384 structured IF, associate the ELSE with the IF. Otherwise, assume
6385 it is a conditional else. */
6388 s_mri_else (int qual
)
6395 && (mri_control_stack
== NULL
6396 || mri_control_stack
->type
!= mri_if
6397 || mri_control_stack
->else_seen
))
6403 c
= *input_line_pointer
;
6404 *input_line_pointer
= 0;
6405 if (ignore_input ())
6407 *input_line_pointer
= c
;
6408 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6409 ++input_line_pointer
;
6410 demand_empty_rest_of_line ();
6413 *input_line_pointer
= c
;
6415 if (mri_control_stack
== NULL
6416 || mri_control_stack
->type
!= mri_if
6417 || mri_control_stack
->else_seen
)
6419 as_bad (_("else without matching if"));
6420 ignore_rest_of_line ();
6424 mri_control_stack
->else_seen
= 1;
6426 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
6427 q
[0] = TOLOWER (qual
);
6429 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
6433 colon (mri_control_stack
->next
);
6437 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6438 ++input_line_pointer
;
6441 demand_empty_rest_of_line ();
6444 /* Handle the MRI ENDI pseudo-op. */
6447 s_mri_endi (int ignore ATTRIBUTE_UNUSED
)
6449 if (mri_control_stack
== NULL
6450 || mri_control_stack
->type
!= mri_if
)
6452 as_bad (_("endi without matching if"));
6453 ignore_rest_of_line ();
6457 /* ignore_input will not return true for ENDI, so we don't need to
6458 worry about checking it again here. */
6460 if (! mri_control_stack
->else_seen
)
6461 colon (mri_control_stack
->next
);
6462 colon (mri_control_stack
->bottom
);
6468 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6469 ++input_line_pointer
;
6472 demand_empty_rest_of_line ();
6475 /* Handle the MRI BREAK pseudo-op. */
6478 s_mri_break (int extent
)
6480 struct mri_control_info
*n
;
6484 n
= mri_control_stack
;
6486 && n
->type
!= mri_for
6487 && n
->type
!= mri_repeat
6488 && n
->type
!= mri_while
)
6492 as_bad (_("break outside of structured loop"));
6493 ignore_rest_of_line ();
6497 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
6498 ex
[0] = TOLOWER (extent
);
6500 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
6506 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6507 ++input_line_pointer
;
6510 demand_empty_rest_of_line ();
6513 /* Handle the MRI NEXT pseudo-op. */
6516 s_mri_next (int extent
)
6518 struct mri_control_info
*n
;
6522 n
= mri_control_stack
;
6524 && n
->type
!= mri_for
6525 && n
->type
!= mri_repeat
6526 && n
->type
!= mri_while
)
6530 as_bad (_("next outside of structured loop"));
6531 ignore_rest_of_line ();
6535 buf
= (char *) xmalloc (20 + strlen (n
->next
));
6536 ex
[0] = TOLOWER (extent
);
6538 sprintf (buf
, "bra%s %s", ex
, n
->next
);
6544 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6545 ++input_line_pointer
;
6548 demand_empty_rest_of_line ();
6551 /* Handle the MRI FOR pseudo-op. */
6554 s_mri_for (int qual
)
6556 const char *varstart
, *varstop
;
6557 const char *initstart
, *initstop
;
6558 const char *endstart
, *endstop
;
6559 const char *bystart
, *bystop
;
6563 struct mri_control_info
*n
;
6569 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6573 varstart
= input_line_pointer
;
6575 /* Look for the '='. */
6576 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
6577 && *input_line_pointer
!= '=')
6578 ++input_line_pointer
;
6579 if (*input_line_pointer
!= '=')
6581 as_bad (_("missing ="));
6582 ignore_rest_of_line ();
6586 varstop
= input_line_pointer
;
6587 if (varstop
> varstart
6588 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
6591 ++input_line_pointer
;
6593 initstart
= input_line_pointer
;
6595 /* Look for TO or DOWNTO. */
6598 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6600 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
6601 && ! is_part_of_name (input_line_pointer
[2]))
6603 initstop
= input_line_pointer
;
6604 input_line_pointer
+= 2;
6607 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
6608 && ! is_part_of_name (input_line_pointer
[6]))
6610 initstop
= input_line_pointer
;
6612 input_line_pointer
+= 6;
6615 ++input_line_pointer
;
6617 if (initstop
== NULL
)
6619 as_bad (_("missing to or downto"));
6620 ignore_rest_of_line ();
6623 if (initstop
> initstart
6624 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
6628 endstart
= input_line_pointer
;
6630 /* Look for BY or DO. */
6633 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6635 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
6636 && ! is_part_of_name (input_line_pointer
[2]))
6638 endstop
= input_line_pointer
;
6640 input_line_pointer
+= 2;
6643 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6644 && (input_line_pointer
[2] == '.'
6645 || ! is_part_of_name (input_line_pointer
[2])))
6647 endstop
= input_line_pointer
;
6648 input_line_pointer
+= 2;
6651 ++input_line_pointer
;
6653 if (endstop
== NULL
)
6655 as_bad (_("missing do"));
6656 ignore_rest_of_line ();
6659 if (endstop
> endstart
6660 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
6666 bystop
= bystart
+ 2;
6671 bystart
= input_line_pointer
;
6675 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6677 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
6678 && (input_line_pointer
[2] == '.'
6679 || ! is_part_of_name (input_line_pointer
[2])))
6681 bystop
= input_line_pointer
;
6682 input_line_pointer
+= 2;
6685 ++input_line_pointer
;
6689 as_bad (_("missing do"));
6690 ignore_rest_of_line ();
6693 if (bystop
> bystart
6694 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
6698 if (*input_line_pointer
!= '.')
6702 extent
= input_line_pointer
[1];
6703 input_line_pointer
+= 2;
6706 /* We have fully parsed the FOR operands. Now build the loop. */
6707 n
= push_mri_control (mri_for
);
6709 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
6711 /* Move init,var. */
6718 *s
++ = TOLOWER (qual
);
6720 memcpy (s
, initstart
, initstop
- initstart
);
6721 s
+= initstop
- initstart
;
6723 memcpy (s
, varstart
, varstop
- varstart
);
6724 s
+= varstop
- varstart
;
6736 *s
++ = TOLOWER (qual
);
6738 memcpy (s
, endstart
, endstop
- endstart
);
6739 s
+= endstop
- endstart
;
6741 memcpy (s
, varstart
, varstop
- varstart
);
6742 s
+= varstop
- varstart
;
6747 ex
[0] = TOLOWER (extent
);
6750 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
6752 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
6755 /* Put together the add or sub instruction used by ENDF. */
6763 *s
++ = TOLOWER (qual
);
6765 memcpy (s
, bystart
, bystop
- bystart
);
6766 s
+= bystop
- bystart
;
6768 memcpy (s
, varstart
, varstop
- varstart
);
6769 s
+= varstop
- varstart
;
6775 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6776 ++input_line_pointer
;
6779 demand_empty_rest_of_line ();
6782 /* Handle the MRI ENDF pseudo-op. */
6785 s_mri_endf (int ignore ATTRIBUTE_UNUSED
)
6787 if (mri_control_stack
== NULL
6788 || mri_control_stack
->type
!= mri_for
)
6790 as_bad (_("endf without for"));
6791 ignore_rest_of_line ();
6795 colon (mri_control_stack
->next
);
6797 mri_assemble (mri_control_stack
->incr
);
6799 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
6800 mri_assemble (mri_control_stack
->incr
);
6802 free (mri_control_stack
->incr
);
6804 colon (mri_control_stack
->bottom
);
6810 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6811 ++input_line_pointer
;
6814 demand_empty_rest_of_line ();
6817 /* Handle the MRI REPEAT pseudo-op. */
6820 s_mri_repeat (int ignore ATTRIBUTE_UNUSED
)
6822 struct mri_control_info
*n
;
6824 n
= push_mri_control (mri_repeat
);
6828 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6829 ++input_line_pointer
;
6831 demand_empty_rest_of_line ();
6834 /* Handle the MRI UNTIL pseudo-op. */
6837 s_mri_until (int qual
)
6841 if (mri_control_stack
== NULL
6842 || mri_control_stack
->type
!= mri_repeat
)
6844 as_bad (_("until without repeat"));
6845 ignore_rest_of_line ();
6849 colon (mri_control_stack
->next
);
6851 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
6854 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
6855 mri_control_stack
->top
, '\0');
6857 colon (mri_control_stack
->bottom
);
6859 input_line_pointer
= s
;
6865 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6866 ++input_line_pointer
;
6869 demand_empty_rest_of_line ();
6872 /* Handle the MRI WHILE pseudo-op. */
6875 s_mri_while (int qual
)
6879 struct mri_control_info
*n
;
6881 s
= input_line_pointer
;
6882 /* We only accept '*' as introduction of comments if preceded by white space
6883 or at first column of a line (I think this can't actually happen here?)
6884 This is important when assembling:
6885 while d0 <ne> 12(a0,d0*2) do
6886 while d0 <ne> #CONST*20 do. */
6887 while (! (is_end_of_line
[(unsigned char) *s
]
6890 && (s
== input_line_pointer
6892 || *(s
-1) == '\t'))))
6895 while (*s
== ' ' || *s
== '\t')
6897 if (s
- input_line_pointer
> 1
6900 if (s
- input_line_pointer
< 2
6901 || strncasecmp (s
- 1, "DO", 2) != 0)
6903 as_bad (_("missing do"));
6904 ignore_rest_of_line ();
6908 n
= push_mri_control (mri_while
);
6912 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
6913 s
[1] == '.' ? s
[2] : '\0');
6915 input_line_pointer
= s
+ 1;
6916 if (*input_line_pointer
== '.')
6917 input_line_pointer
+= 2;
6921 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6922 ++input_line_pointer
;
6925 demand_empty_rest_of_line ();
6928 /* Handle the MRI ENDW pseudo-op. */
6931 s_mri_endw (int ignore ATTRIBUTE_UNUSED
)
6935 if (mri_control_stack
== NULL
6936 || mri_control_stack
->type
!= mri_while
)
6938 as_bad (_("endw without while"));
6939 ignore_rest_of_line ();
6943 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
6944 sprintf (buf
, "bra %s", mri_control_stack
->next
);
6948 colon (mri_control_stack
->bottom
);
6954 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
6955 ++input_line_pointer
;
6958 demand_empty_rest_of_line ();
6961 /* Parse a .cpu directive. */
6964 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED
)
6971 as_bad (_("already assembled instructions"));
6972 ignore_rest_of_line ();
6976 name
= input_line_pointer
;
6977 while (*input_line_pointer
&& !ISSPACE(*input_line_pointer
))
6978 input_line_pointer
++;
6979 saved_char
= *input_line_pointer
;
6980 *input_line_pointer
= 0;
6982 m68k_set_cpu (name
, 1, 0);
6984 *input_line_pointer
= saved_char
;
6985 demand_empty_rest_of_line ();
6989 /* Parse a .arch directive. */
6992 s_m68k_arch (int ignored ATTRIBUTE_UNUSED
)
6999 as_bad (_("already assembled instructions"));
7000 ignore_rest_of_line ();
7004 name
= input_line_pointer
;
7005 while (*input_line_pointer
&& *input_line_pointer
!= ','
7006 && !ISSPACE (*input_line_pointer
))
7007 input_line_pointer
++;
7008 saved_char
= *input_line_pointer
;
7009 *input_line_pointer
= 0;
7011 if (m68k_set_arch (name
, 1, 0))
7013 /* Scan extensions. */
7016 *input_line_pointer
++ = saved_char
;
7017 if (!*input_line_pointer
|| ISSPACE (*input_line_pointer
))
7019 name
= input_line_pointer
;
7020 while (*input_line_pointer
&& *input_line_pointer
!= ','
7021 && !ISSPACE (*input_line_pointer
))
7022 input_line_pointer
++;
7023 saved_char
= *input_line_pointer
;
7024 *input_line_pointer
= 0;
7026 while (m68k_set_extension (name
, 1, 0));
7029 *input_line_pointer
= saved_char
;
7030 demand_empty_rest_of_line ();
7034 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
7035 if none is found, the caller is responsible for emitting an error
7036 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
7037 cpu name, if it begins with a '6' (possibly skipping an intervening
7038 'c'. We also allow a 'c' in the same place. if NEGATED is
7039 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
7040 the option is indeed negated. */
7042 static const struct m68k_cpu
*
7043 m68k_lookup_cpu (const char *arg
, const struct m68k_cpu
*table
,
7044 int allow_m
, int *negated
)
7046 /* allow negated value? */
7051 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
7058 /* Remove 'm' or 'mc' prefix from 68k variants. */
7065 else if (arg
[1] == 'c' && arg
[2] == '6')
7069 else if (arg
[0] == 'c' && arg
[1] == '6')
7072 for (; table
->name
; table
++)
7073 if (!strcmp (arg
, table
->name
))
7078 /* Set the cpu, issuing errors if it is unrecognized, or invalid */
7081 m68k_set_cpu (char const *name
, int allow_m
, int silent
)
7083 const struct m68k_cpu
*cpu
;
7085 cpu
= m68k_lookup_cpu (name
, m68k_cpus
, allow_m
, NULL
);
7090 as_bad (_("cpu `%s' unrecognized"), name
);
7094 if (selected_cpu
&& selected_cpu
!= cpu
)
7096 as_bad (_("already selected `%s' processor"),
7097 selected_cpu
->name
);
7104 /* Set the architecture, issuing errors if it is unrecognized, or invalid */
7107 m68k_set_arch (char const *name
, int allow_m
, int silent
)
7109 const struct m68k_cpu
*arch
;
7111 arch
= m68k_lookup_cpu (name
, m68k_archs
, allow_m
, NULL
);
7116 as_bad (_("architecture `%s' unrecognized"), name
);
7120 if (selected_arch
&& selected_arch
!= arch
)
7122 as_bad (_("already selected `%s' architecture"),
7123 selected_arch
->name
);
7127 selected_arch
= arch
;
7131 /* Set the architecture extension, issuing errors if it is
7132 unrecognized, or invalid */
7135 m68k_set_extension (char const *name
, int allow_m
, int silent
)
7138 const struct m68k_cpu
*ext
;
7140 ext
= m68k_lookup_cpu (name
, m68k_extensions
, allow_m
, &negated
);
7145 as_bad (_("extension `%s' unrecognized"), name
);
7150 not_current_architecture
|= ext
->arch
;
7152 current_architecture
|= ext
->arch
;
7157 Invocation line includes a switch not recognized by the base assembler.
7161 const char *md_shortopts
= "lSA:m:kQ:V";
7163 const char *md_shortopts
= "lSA:m:k";
7166 struct option md_longopts
[] = {
7167 #define OPTION_PIC (OPTION_MD_BASE)
7168 {"pic", no_argument
, NULL
, OPTION_PIC
},
7169 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7170 {"register-prefix-optional", no_argument
, NULL
,
7171 OPTION_REGISTER_PREFIX_OPTIONAL
},
7172 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7173 {"bitwise-or", no_argument
, NULL
, OPTION_BITWISE_OR
},
7174 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7175 {"base-size-default-16", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_16
},
7176 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7177 {"base-size-default-32", no_argument
, NULL
, OPTION_BASE_SIZE_DEFAULT_32
},
7178 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7179 {"disp-size-default-16", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_16
},
7180 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7181 {"disp-size-default-32", no_argument
, NULL
, OPTION_DISP_SIZE_DEFAULT_32
},
7182 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7183 {"pcrel", no_argument
, NULL
, OPTION_PCREL
},
7184 {NULL
, no_argument
, NULL
, 0}
7186 size_t md_longopts_size
= sizeof (md_longopts
);
7189 md_parse_option (int c
, char *arg
)
7193 case 'l': /* -l means keep external to 2 bit offset
7194 rather than 16 bit one. */
7195 flag_short_refs
= 1;
7198 case 'S': /* -S means that jbsr's always turn into
7200 flag_long_jumps
= 1;
7203 case OPTION_PCREL
: /* --pcrel means never turn PC-relative
7204 branches into absolute jumps. */
7205 flag_keep_pcrel
= 1;
7211 break; /* -pic, Position Independent Code. */
7213 case OPTION_REGISTER_PREFIX_OPTIONAL
:
7214 flag_reg_prefix_optional
= 1;
7215 reg_prefix_optional_seen
= 1;
7218 /* -V: SVR4 argument to print version ID. */
7220 print_version_id ();
7223 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7224 should be emitted or not. FIXME: Not implemented. */
7228 case OPTION_BITWISE_OR
:
7233 n
= (char *) xmalloc (strlen (m68k_comment_chars
) + 1);
7235 for (s
= m68k_comment_chars
; *s
!= '\0'; s
++)
7239 m68k_comment_chars
= n
;
7243 case OPTION_BASE_SIZE_DEFAULT_16
:
7244 m68k_index_width_default
= SIZE_WORD
;
7247 case OPTION_BASE_SIZE_DEFAULT_32
:
7248 m68k_index_width_default
= SIZE_LONG
;
7251 case OPTION_DISP_SIZE_DEFAULT_16
:
7253 m68k_rel32_from_cmdline
= 1;
7256 case OPTION_DISP_SIZE_DEFAULT_32
:
7258 m68k_rel32_from_cmdline
= 1;
7263 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7266 /* Intentional fall-through. */
7268 if (!strncmp (arg
, "arch=", 5))
7269 m68k_set_arch (arg
+ 5, 1, 0);
7270 else if (!strncmp (arg
, "cpu=", 4))
7271 m68k_set_cpu (arg
+ 4, 1, 0);
7272 else if (m68k_set_extension (arg
, 0, 1))
7274 else if (m68k_set_cpu (arg
, 0, 1))
7287 /* Setup tables from the selected arch and/or cpu */
7290 m68k_init_arch (void)
7292 unsigned arch_of_chip
= 0;
7294 if (not_current_architecture
& current_architecture
)
7296 as_bad (_("architecture features both enabled and disabled"));
7297 not_current_architecture
&= ~current_architecture
;
7301 arch_of_chip
= selected_arch
->arch
;
7302 current_chip
= selected_arch
->chip
;
7303 if (selected_cpu
&& (arch_of_chip
& ~selected_cpu
->arch
))
7305 as_bad (_("selected processor is not from selected architecture"));
7306 arch_of_chip
= selected_cpu
->arch
;
7310 arch_of_chip
= selected_cpu
->arch
;
7312 current_chip
= selected_cpu
->chip
;
7314 current_architecture
|= arch_of_chip
;
7315 current_architecture
&= ~not_current_architecture
;
7316 if ((current_architecture
& m68k_mask
)
7317 && (current_architecture
& ~m68k_mask
))
7319 as_bad (_ ("m68k and cf features both selected"));
7320 if (arch_of_chip
& m68k_mask
)
7321 current_architecture
&= m68k_mask
;
7323 current_architecture
&= ~m68k_mask
;
7326 /* Permit m68881 specification with all cpus; those that can't work
7327 with a coprocessor could be doing emulation. */
7328 if (current_architecture
& m68851
)
7330 if (current_architecture
& m68040
)
7331 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7333 /* What other incompatibilities could we check for? */
7335 /* Note which set of "movec" control registers is available. */
7336 select_control_regs ();
7338 if (cpu_of_arch (current_architecture
) < m68020
7339 || arch_coldfire_p (current_architecture
))
7340 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
7346 md_show_usage (FILE *stream
)
7348 const char *default_cpu
= TARGET_CPU
;
7350 unsigned int default_arch
;
7352 /* Get the canonical name for the default target CPU. */
7353 if (*default_cpu
== 'm')
7355 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7357 if (strcasecmp (default_cpu
, m68k_cpus
[i
].name
) == 0)
7359 default_arch
= m68k_cpus
[i
].arch
;
7360 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7362 if (m68k_cpus
[i
].arch
== default_arch
7363 && !m68k_cpus
[i
].alias
)
7365 default_cpu
= m68k_cpus
[i
].name
;
7372 fprintf (stream
, _("\
7373 -march=<arch> set architecture\n\
7374 -mcpu=<cpu> set cpu [default %s]\n\
7376 for (i
= 0; m68k_extensions
[i
].name
; i
++)
7377 fprintf (stream
, _("\
7378 -m[no-]%-16s enable/disable %s architecture extension\n\
7379 "), m68k_extensions
[i
].name
, m68k_extensions
[i
].alias
? "ColdFire" : "m68k");
7381 fprintf (stream
, _("\
7382 -l use 1 word for refs to undefined symbols [default 2]\n\
7383 -pic, -k generate position independent code\n\
7384 -S turn jbsr into jsr\n\
7385 --pcrel never turn PC-relative branches into absolute jumps\n\
7386 --register-prefix-optional\n\
7387 recognize register names without prefix character\n\
7388 --bitwise-or do not treat `|' as a comment character\n\
7389 --base-size-default-16 base reg without size is 16 bits\n\
7390 --base-size-default-32 base reg without size is 32 bits (default)\n\
7391 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7392 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7395 fprintf (stream
, _("Architecture variants are: "));
7396 for (i
= 0; m68k_archs
[i
].name
; i
++)
7399 fprintf (stream
, " | ");
7400 fprintf (stream
, m68k_archs
[i
].name
);
7402 fprintf (stream
, "\n");
7404 fprintf (stream
, _("Processor variants are: "));
7405 for (i
= 0; m68k_cpus
[i
].name
; i
++)
7408 fprintf (stream
, " | ");
7409 fprintf (stream
, m68k_cpus
[i
].name
);
7411 fprintf (stream
, _("\n"));
7416 /* TEST2: Test md_assemble() */
7417 /* Warning, this routine probably doesn't work anymore. */
7421 struct m68k_it the_ins
;
7429 if (!gets (buf
) || !*buf
)
7431 if (buf
[0] == '|' || buf
[1] == '.')
7433 for (cp
= buf
; *cp
; cp
++)
7438 memset (&the_ins
, '\0', sizeof (the_ins
));
7439 m68k_ip (&the_ins
, buf
);
7442 printf (_("Error %s in %s\n"), the_ins
.error
, buf
);
7446 printf (_("Opcode(%d.%s): "), the_ins
.numo
, the_ins
.args
);
7447 for (n
= 0; n
< the_ins
.numo
; n
++)
7448 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
7450 print_the_insn (&the_ins
.opcode
[0], stdout
);
7451 (void) putchar ('\n');
7453 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
7455 if (the_ins
.operands
[n
].error
)
7457 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
7460 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
,
7461 the_ins
.operands
[n
].reg
);
7462 if (the_ins
.operands
[n
].b_const
)
7463 printf ("Constant: '%.*s', ",
7464 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
,
7465 the_ins
.operands
[n
].b_const
);
7466 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
,
7467 the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
7468 if (the_ins
.operands
[n
].b_iadd
)
7469 printf ("Iadd: '%.*s',",
7470 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
,
7471 the_ins
.operands
[n
].b_iadd
);
7480 is_label (char *str
)
7484 while (*str
&& *str
!= ' ')
7486 if (str
[-1] == ':' || str
[1] == '=')
7493 /* Possible states for relaxation:
7495 0 0 branch offset byte (bra, etc)
7499 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7503 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7510 /* We have no need to default values of symbols. */
7513 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
7518 /* Round up a section size to the appropriate boundary. */
7520 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
7523 /* For a.out, force the section size to be aligned. If we don't do
7524 this, BFD will align it for us, but it will not write out the
7525 final bytes of the section. This may be a bug in BFD, but it is
7526 easier to fix it here since that is how the other a.out targets
7530 align
= bfd_get_section_alignment (stdoutput
, segment
);
7531 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
7537 /* Exactly what point is a PC-relative offset relative TO?
7538 On the 68k, it is relative to the address of the first extension
7539 word. The difference between the addresses of the offset and the
7540 first extension word is stored in fx_pcrel_adjust. */
7542 md_pcrel_from (fixS
*fixP
)
7546 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7547 sign extend the value here. */
7548 adjust
= ((fixP
->fx_pcrel_adjust
& 0xff) ^ 0x80) - 0x80;
7551 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
7556 m68k_elf_final_processing (void)
7560 if (arch_coldfire_fpu (current_architecture
))
7561 flags
|= EF_M68K_CFV4E
;
7562 /* Set file-specific flags if this is a cpu32 processor. */
7563 if (cpu_of_arch (current_architecture
) & cpu32
)
7564 flags
|= EF_M68K_CPU32
;
7565 else if ((cpu_of_arch (current_architecture
) & m68000up
)
7566 && !(cpu_of_arch (current_architecture
) & m68020up
))
7567 flags
|= EF_M68K_M68000
;
7569 if (current_architecture
& mcfisa_a
)
7571 /* Set coldfire specific elf flags */
7572 if (current_architecture
& mcfisa_b
)
7573 flags
|= EF_M68K_ISA_B
;
7574 else if (current_architecture
& mcfisa_aa
)
7575 flags
|= EF_M68K_ISA_A_PLUS
;
7577 flags
|= EF_M68K_ISA_A
;
7579 if (current_architecture
& mcfhwdiv
)
7580 flags
|= EF_M68K_HW_DIV
;
7582 if (current_architecture
& mcfusp
)
7583 flags
|= EF_M68K_USP
;
7585 if (current_architecture
& cfloat
)
7586 flags
|= EF_M68K_FLOAT
;
7588 if (current_architecture
& mcfmac
)
7589 flags
|= EF_M68K_MAC
;
7590 else if (current_architecture
& mcfemac
)
7591 flags
|= EF_M68K_EMAC
;
7593 elf_elfheader (stdoutput
)->e_flags
|= flags
;
7598 tc_m68k_regname_to_dw2regnum (const char *regname
)
7600 unsigned int regnum
;
7601 static const char *const regnames
[] =
7603 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7604 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7605 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7609 for (regnum
= 0; regnum
< ARRAY_SIZE (regnames
); regnum
++)
7610 if (strcmp (regname
, regnames
[regnum
]) == 0)
7617 tc_m68k_frame_initial_instructions (void)
7619 static int sp_regno
= -1;
7622 sp_regno
= tc_m68k_regname_to_dw2regnum ("sp");
7624 cfi_add_CFA_def_cfa (sp_regno
, -DWARF2_CIE_DATA_ALIGNMENT
);
7625 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN
, DWARF2_CIE_DATA_ALIGNMENT
);