1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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_ctrl[] = { 0 };
156 static const enum m68k_register m68010_ctrl[] = {
160 static const enum m68k_register m68020_ctrl[] = {
161 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
164 static const enum m68k_register m68040_ctrl[] = {
165 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
166 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
169 static const enum m68k_register m68060_ctrl[] = {
170 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
171 USP, VBR, URP, SRP, PCR,
174 static const enum m68k_register mcf_ctrl[] = {
175 CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
176 RAMBAR0, RAMBAR1, RAMBAR, MBAR,
179 static const enum m68k_register mcf5206_ctrl[] = {
180 CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR_ALT, MBAR,
183 static const enum m68k_register mcf5208_ctrl[] = {
184 CACR, ACR0, ACR1, VBR, RAMBAR, RAMBAR1,
187 static const enum m68k_register mcf5210a_ctrl[] = {
188 VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR, RAMBAR1, MBAR,
191 static const enum m68k_register mcf5213_ctrl[] = {
192 VBR, RAMBAR, RAMBAR1, FLASHBAR,
195 static const enum m68k_register mcf5216_ctrl[] = {
196 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
199 static const enum m68k_register mcf52223_ctrl[] = {
200 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
203 static const enum m68k_register mcf52235_ctrl[] = {
204 VBR, FLASHBAR, RAMBAR, RAMBAR1,
207 static const enum m68k_register mcf5225_ctrl[] = {
208 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, MBAR, RAMBAR1,
211 static const enum m68k_register mcf5235_ctrl[] = {
212 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
215 static const enum m68k_register mcf5249_ctrl[] = {
216 VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, RAMBAR, MBAR, MBAR2,
219 static const enum m68k_register mcf5250_ctrl[] = {
223 static const enum m68k_register mcf5253_ctrl[] = {
224 VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, MBAR,
227 static const enum m68k_register mcf5271_ctrl[] = {
228 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
231 static const enum m68k_register mcf5272_ctrl[] = {
232 VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR_ALT, RAMBAR0, MBAR,
235 static const enum m68k_register mcf5275_ctrl[] = {
236 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
239 static const enum m68k_register mcf5282_ctrl[] = {
240 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
243 static const enum m68k_register mcf5307_ctrl[] = {
244 CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR_ALT, MBAR,
247 static const enum m68k_register mcf5329_ctrl[] = {
248 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
251 static const enum m68k_register mcf5373_ctrl[] = {
252 VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
255 static const enum m68k_register mcfv4e_ctrl[] = {
256 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
257 VBR, PC, ROMBAR0, ROMBAR1, RAMBAR0, RAMBAR1,
259 MPCR /* Multiprocessor Control register */,
260 EDRAMBAR /* Embedded DRAM Base Address Register */,
261 /* Permutation control registers. */
262 PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
263 PCR3U0, PCR3L0, PCR3U1, PCR3L1,
265 TC /* ASID */, BUSCR /* MMUBAR */,
266 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
267 MBAR1 /* MBAR */, MBAR2 /* SECMBAR */, MBAR0 /* SECMBAR */,
268 ROMBAR /* ROMBAR0 */, RAMBAR /* RAMBAR1 */,
271 static const enum m68k_register mcf54455_ctrl[] = {
272 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
273 VBR, PC, RAMBAR1, MBAR,
275 TC /* ASID */, BUSCR /* MMUBAR */,
276 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
277 MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
280 static const enum m68k_register mcf5475_ctrl[] = {
281 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
282 VBR, PC, RAMBAR0, RAMBAR1, MBAR,
284 TC /* ASID */, BUSCR /* MMUBAR */,
285 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
286 MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
289 static const enum m68k_register mcf5485_ctrl[] = {
290 CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
291 VBR, PC, RAMBAR0, RAMBAR1, MBAR,
293 TC /* ASID */, BUSCR /* MMUBAR */,
294 ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
295 MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
298 static const enum m68k_register fido_ctrl[] = {
299 SFC, DFC, USP, VBR, CAC, MBB,
302 #define cpu32_ctrl m68010_ctrl
304 static const enum m68k_register *control_regs;
306 /* Internal form of a 68020 instruction. */
310 const char *args; /* List of opcode info. */
313 int numo; /* Number of shorts in opcode. */
316 struct m68k_op operands[6];
318 int nexp; /* Number of exprs in use. */
319 struct m68k_exp exprs[4];
321 int nfrag; /* Number of frags we have to produce. */
324 int fragoff; /* Where in the current opcode the frag ends. */
331 int nrel; /* Num of reloc strucs in use. */
338 /* In a pc relative address the difference between the address
339 of the offset and the address that the offset is relative
340 to. This depends on the addressing mode. Basically this
341 is the value to put in the offset field to address the
342 first byte of the offset, without regarding the special
343 significance of some values (in the branch instruction, for
347 /* Whether this expression needs special pic relocation, and if
349 enum pic_relocation pic_reloc;
352 reloc[5]; /* Five is enough??? */
355 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a | fido_a))
356 #define float_of_arch(x) ((x) & mfloat)
357 #define mmu_of_arch(x) ((x) & mmmu)
358 #define arch_coldfire_p(x) ((x) & mcfisa_a)
359 #define arch_coldfire_fpu(x) ((x) & cfloat)
361 /* Macros for determining if cpu supports a specific addressing mode. */
362 #define HAVE_LONG_DISP(x) \
363 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
364 #define HAVE_LONG_CALL(x) \
365 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
366 #define HAVE_LONG_COND(x) \
367 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
368 #define HAVE_LONG_BRANCH(x) \
369 ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b))
371 static struct m68k_it the_ins; /* The instruction being assembled. */
373 #define op(ex) ((ex)->exp.X_op)
374 #define adds(ex) ((ex)->exp.X_add_symbol)
375 #define subs(ex) ((ex)->exp.X_op_symbol)
376 #define offs(ex) ((ex)->exp.X_add_number)
378 /* Macros for adding things to the m68k_it struct. */
379 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
381 /* Like addword, but goes BEFORE general operands. */
384 insop (int w, const struct m68k_incant *opcode)
387 for (z = the_ins.numo; z > opcode->m_codenum; --z)
388 the_ins.opcode[z] = the_ins.opcode[z - 1];
389 for (z = 0; z < the_ins.nrel; z++)
390 the_ins.reloc[z].n += 2;
391 for (z = 0; z < the_ins.nfrag; z++)
392 the_ins.fragb[z].fragoff++;
393 the_ins.opcode[opcode->m_codenum] = w;
397 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
400 add_fix (int width, struct m68k_exp *exp, int pc_rel, int pc_fix)
402 the_ins.reloc[the_ins.nrel].n = (width == 'B' || width == '3'
403 ? the_ins.numo * 2 - 1
405 ? the_ins.numo * 2 + 1
406 : the_ins.numo * 2));
407 the_ins.reloc[the_ins.nrel].exp = exp->exp;
408 the_ins.reloc[the_ins.nrel].wid = width;
409 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
411 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
413 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
416 /* Cause an extra frag to be generated here, inserting up to 10 bytes
417 (that value is chosen in the frag_var call in md_assemble). TYPE
418 is the subtype of the frag to be generated; its primary type is
419 rs_machine_dependent.
421 The TYPE parameter is also used by md_convert_frag_1 and
422 md_estimate_size_before_relax. The appropriate type of fixup will
423 be emitted by md_convert_frag_1.
425 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
427 add_frag (symbolS *add, offsetT off, int type)
429 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
430 the_ins.fragb[the_ins.nfrag].fadd = add;
431 the_ins.fragb[the_ins.nfrag].foff = off;
432 the_ins.fragb[the_ins.nfrag++].fragty = type;
436 (op (ex) != O_constant && op (ex) != O_big)
438 static char *crack_operand (char *str, struct m68k_op *opP);
439 static int get_num (struct m68k_exp *exp, int ok);
440 static int reverse_16_bits (int in);
441 static int reverse_8_bits (int in);
442 static void install_gen_operand (int mode, int val);
443 static void install_operand (int mode, int val);
444 static void s_bss (int);
445 static void s_data1 (int);
446 static void s_data2 (int);
447 static void s_even (int);
448 static void s_proc (int);
449 static void s_chip (int);
450 static void s_fopt (int);
451 static void s_opt (int);
452 static void s_reg (int);
453 static void s_restore (int);
454 static void s_save (int);
455 static void s_mri_if (int);
456 static void s_mri_else (int);
457 static void s_mri_endi (int);
458 static void s_mri_break (int);
459 static void s_mri_next (int);
460 static void s_mri_for (int);
461 static void s_mri_endf (int);
462 static void s_mri_repeat (int);
463 static void s_mri_until (int);
464 static void s_mri_while (int);
465 static void s_mri_endw (int);
466 static void s_m68k_cpu (int);
467 static void s_m68k_arch (int);
471 unsigned long arch; /* Architecture features. */
472 const enum m68k_register *control_regs; /* Control regs on chip */
473 const char *name; /* Name */
474 int alias; /* Alias for a cannonical name. If 1, then
475 succeeds canonical name, if -1 then
476 succeeds canonical name, if <-1 ||>1 this is a
477 deprecated name, and the next/previous name
481 /* We hold flags for features explicitly enabled and explicitly
483 static int current_architecture;
484 static int not_current_architecture;
485 static const struct m68k_cpu *selected_arch;
486 static const struct m68k_cpu *selected_cpu;
487 static int initialized;
489 /* Architecture models. */
490 static const struct m68k_cpu m68k_archs[] =
492 {m68000, m68000_ctrl, "68000", 0},
493 {m68010, m68010_ctrl, "68010", 0},
494 {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
495 {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
496 {m68040, m68040_ctrl, "68040", 0},
497 {m68060, m68060_ctrl, "68060", 0},
498 {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
499 {fido_a, fido_ctrl, "fidoa", 0},
500 {mcfisa_a|mcfhwdiv, NULL, "isaa", 0},
501 {mcfisa_a|mcfhwdiv|mcfisa_aa|mcfusp, NULL, "isaaplus", 0},
502 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp, NULL, "isab", 0},
503 {mcfisa_a|mcfhwdiv|mcfisa_c|mcfusp, NULL, "isac", 0},
504 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac|mcfusp, mcf_ctrl, "cfv4", 0},
505 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "cfv4e", 0},
509 /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
511 static const struct m68k_cpu m68k_extensions[] =
513 {m68851, NULL, "68851", -1},
514 {m68881, NULL, "68881", -1},
515 {m68881, NULL, "68882", -1},
517 {cfloat|m68881, NULL, "float", 0},
519 {mcfhwdiv, NULL, "div", 1},
520 {mcfusp, NULL, "usp", 1},
521 {mcfmac, NULL, "mac", 1},
522 {mcfemac, NULL, "emac", 1},
528 static const struct m68k_cpu m68k_cpus[] =
530 {m68000, m68000_ctrl, "68000", 0},
531 {m68000, m68000_ctrl, "68ec000", 1},
532 {m68000, m68000_ctrl, "68hc000", 1},
533 {m68000, m68000_ctrl, "68hc001", 1},
534 {m68000, m68000_ctrl, "68008", 1},
535 {m68000, m68000_ctrl, "68302", 1},
536 {m68000, m68000_ctrl, "68306", 1},
537 {m68000, m68000_ctrl, "68307", 1},
538 {m68000, m68000_ctrl, "68322", 1},
539 {m68000, m68000_ctrl, "68356", 1},
540 {m68010, m68010_ctrl, "68010", 0},
541 {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
542 {m68020|m68881|m68851, m68020_ctrl, "68k", 1},
543 {m68020|m68881|m68851, m68020_ctrl, "68ec020", 1},
544 {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
545 {m68030|m68881|m68851, m68020_ctrl, "68ec030", 1},
546 {m68040, m68040_ctrl, "68040", 0},
547 {m68040, m68040_ctrl, "68ec040", 1},
548 {m68060, m68060_ctrl, "68060", 0},
549 {m68060, m68060_ctrl, "68ec060", 1},
551 {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
552 {cpu32|m68881, cpu32_ctrl, "68330", 1},
553 {cpu32|m68881, cpu32_ctrl, "68331", 1},
554 {cpu32|m68881, cpu32_ctrl, "68332", 1},
555 {cpu32|m68881, cpu32_ctrl, "68333", 1},
556 {cpu32|m68881, cpu32_ctrl, "68334", 1},
557 {cpu32|m68881, cpu32_ctrl, "68336", 1},
558 {cpu32|m68881, cpu32_ctrl, "68340", 1},
559 {cpu32|m68881, cpu32_ctrl, "68341", 1},
560 {cpu32|m68881, cpu32_ctrl, "68349", 1},
561 {cpu32|m68881, cpu32_ctrl, "68360", 1},
563 {mcfisa_a, mcf_ctrl, "5200", 0},
564 {mcfisa_a, mcf_ctrl, "5202", 1},
565 {mcfisa_a, mcf_ctrl, "5204", 1},
566 {mcfisa_a, mcf5206_ctrl, "5206", 1},
568 {mcfisa_a|mcfhwdiv|mcfmac, mcf5206_ctrl, "5206e", 0},
570 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5207", -1},
571 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5208", 0},
573 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5210a_ctrl, "5210a", 0},
574 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5210a_ctrl, "5211a", 1},
576 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5211", -1},
577 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5212", -1},
578 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5213", 0},
580 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5214", -1},
581 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5216", 0},
582 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "521x", 2},
584 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf52223_ctrl, "52221", -1},
585 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf52223_ctrl, "52223", 0},
587 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52230", -1},
588 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52233", -1},
589 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52234", -1},
590 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52235", 0},
592 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5225_ctrl, "5224", -1},
593 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5225_ctrl, "5225", 0},
595 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5232", -1},
596 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5233", -1},
597 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5234", -1},
598 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5235", -1},
599 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "523x", 0},
601 {mcfisa_a|mcfhwdiv|mcfemac, mcf5249_ctrl, "5249", 0},
602 {mcfisa_a|mcfhwdiv|mcfemac, mcf5250_ctrl, "5250", 0},
603 {mcfisa_a|mcfhwdiv|mcfemac, mcf5253_ctrl, "5253", 0},
605 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5270", -1},
606 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5271", 0},
608 {mcfisa_a|mcfhwdiv|mcfmac, mcf5272_ctrl, "5272", 0},
610 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5274", -1},
611 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5275", 0},
613 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5280", -1},
614 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5281", -1},
615 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5282", -1},
616 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "528x", 0},
618 {mcfisa_a|mcfhwdiv|mcfmac, mcf5307_ctrl, "5307", 0},
620 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5327", -1},
621 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5328", -1},
622 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5329", -1},
623 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "532x", 0},
625 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5372", -1},
626 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5373", -1},
627 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "537x", 0},
629 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfmac, mcf_ctrl, "5407",0},
631 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54450", -1},
632 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54451", -1},
633 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54452", -1},
634 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54453", -1},
635 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54454", -1},
636 {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54455", 0},
638 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5470", -1},
639 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5471", -1},
640 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5472", -1},
641 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5473", -1},
642 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5474", -1},
643 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5475", -1},
644 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "547x", 0},
646 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5480", -1},
647 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5481", -1},
648 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5482", -1},
649 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5483", -1},
650 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5484", -1},
651 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5485", -1},
652 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "548x", 0},
654 {fido_a, fido_ctrl, "fidoa", 0},
655 {fido_a, fido_ctrl, "fido", 1},
660 static const struct m68k_cpu *m68k_lookup_cpu
661 (const char *, const struct m68k_cpu *, int, int *);
662 static int m68k_set_arch (const char *, int, int);
663 static int m68k_set_cpu (const char *, int, int);
664 static int m68k_set_extension (const char *, int, int);
665 static void m68k_init_arch (void);
667 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
668 architecture and we have a lot of relaxation modes. */
670 /* Macros used in the relaxation code. */
671 #define TAB(x,y) (((x) << 2) + (y))
672 #define TABTYPE(x) ((x) >> 2)
674 /* Relaxation states. */
680 /* Here are all the relaxation modes we support. First we can relax ordinary
681 branches. On 68020 and higher and on CPU32 all branch instructions take
682 three forms, so on these CPUs all branches always remain as such. When we
683 have to expand to the LONG form on a 68000, though, we substitute an
684 absolute jump instead. This is a direct replacement for unconditional
685 branches and a branch over a jump for conditional branches. However, if the
686 user requires PIC and disables this with --pcrel, we can only relax between
687 BYTE and SHORT forms, punting if that isn't enough. This gives us four
688 different relaxation modes for branches: */
690 #define BRANCHBWL 0 /* Branch byte, word, or long. */
691 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
692 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
693 #define BRANCHBW 3 /* Branch byte or word. */
695 /* We also relax coprocessor branches and DBcc's. All CPUs that support
696 coprocessor branches support them in word and long forms, so we have only
697 one relaxation mode for them. DBcc's are word only on all CPUs. We can
698 relax them to the LONG form with a branch-around sequence. This sequence
699 can use a long branch (if available) or an absolute jump (if acceptable).
700 This gives us two relaxation modes. If long branches are not available and
701 absolute jumps are not acceptable, we don't relax DBcc's. */
703 #define FBRANCH 4 /* Coprocessor branch. */
704 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
705 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
707 /* That's all for instruction relaxation. However, we also relax PC-relative
708 operands. Specifically, we have three operand relaxation modes. On the
709 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
710 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
711 two. Also PC+displacement+index operands in their simple form (with a non-
712 suppressed index without memory indirection) are supported on all CPUs, but
713 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
714 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
715 form of the PC+displacement+index operand. Finally, some absolute operands
716 can be relaxed down to 16-bit PC-relative. */
718 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
719 #define PCINDEX 8 /* PC + displacement + index. */
720 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
722 /* Note that calls to frag_var need to specify the maximum expansion
723 needed; this is currently 10 bytes for DBCC. */
726 How far Forward this mode will reach:
727 How far Backward this mode will reach:
728 How many bytes this mode will add to the size of the frag
729 Which mode to go to if the offset won't fit in this one
731 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
732 relax_typeS md_relax_table[] =
734 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
735 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
739 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
740 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
744 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
745 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
749 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
754 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
755 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
759 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
760 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
764 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
765 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
769 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
770 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
774 { 125, -130, 0, TAB (PCINDEX, SHORT) },
775 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
779 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
780 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
785 /* These are the machine dependent pseudo-ops. These are included so
786 the assembler can work on the output from the SUN C compiler, which
789 /* This table describes all the machine specific pseudo-ops the assembler
790 has to support. The fields are:
791 pseudo-op name without dot
792 function to call to execute this pseudo-op
793 Integer arg to pass to the function. */
794 const pseudo_typeS md_pseudo_table[] =
796 {"data1", s_data1, 0},
797 {"data2", s_data2, 0},
800 {"skip", s_space, 0},
802 #if defined (TE_SUN3) || defined (OBJ_ELF)
803 {"align", s_align_bytes, 0},
806 {"swbeg", s_ignore, 0},
808 {"extend", float_cons, 'x'},
809 {"ldouble", float_cons, 'x'},
811 {"arch", s_m68k_arch, 0},
812 {"cpu", s_m68k_cpu, 0},
814 /* The following pseudo-ops are supported for MRI compatibility. */
816 {"comline", s_space, 1},
818 {"mask2", s_ignore, 0},
821 {"restore", s_restore, 0},
825 {"if.b", s_mri_if, 'b'},
826 {"if.w", s_mri_if, 'w'},
827 {"if.l", s_mri_if, 'l'},
828 {"else", s_mri_else, 0},
829 {"else.s", s_mri_else, 's'},
830 {"else.l", s_mri_else, 'l'},
831 {"endi", s_mri_endi, 0},
832 {"break", s_mri_break, 0},
833 {"break.s", s_mri_break, 's'},
834 {"break.l", s_mri_break, 'l'},
835 {"next", s_mri_next, 0},
836 {"next.s", s_mri_next, 's'},
837 {"next.l", s_mri_next, 'l'},
838 {"for", s_mri_for, 0},
839 {"for.b", s_mri_for, 'b'},
840 {"for.w", s_mri_for, 'w'},
841 {"for.l", s_mri_for, 'l'},
842 {"endf", s_mri_endf, 0},
843 {"repeat", s_mri_repeat, 0},
844 {"until", s_mri_until, 0},
845 {"until.b", s_mri_until, 'b'},
846 {"until.w", s_mri_until, 'w'},
847 {"until.l", s_mri_until, 'l'},
848 {"while", s_mri_while, 0},
849 {"while.b", s_mri_while, 'b'},
850 {"while.w", s_mri_while, 'w'},
851 {"while.l", s_mri_while, 'l'},
852 {"endw", s_mri_endw, 0},
857 /* The mote pseudo ops are put into the opcode table, since they
858 don't start with a . they look like opcodes to gas. */
860 const pseudo_typeS mote_pseudo_table[] =
873 {"xdef", s_globl, 0},
875 {"align", s_align_bytes, 0},
877 {"align", s_align_ptwo, 0},
880 {"sect", obj_coff_section, 0},
881 {"section", obj_coff_section, 0},
886 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
887 gives identical results to a 32-bit host. */
888 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
889 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
891 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
892 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
893 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
894 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
896 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
897 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
898 #define islong(x) (1)
900 static char notend_table[256];
901 static char alt_notend_table[256];
903 (! (notend_table[(unsigned char) *s] \
905 && alt_notend_table[(unsigned char) s[1]])))
909 /* Return zero if the reference to SYMBOL from within the same segment may
912 /* On an ELF system, we can't relax an externally visible symbol,
913 because it may be overridden by a shared library. However, if
914 TARGET_OS is "elf", then we presume that we are assembling for an
915 embedded system, in which case we don't have to worry about shared
916 libraries, and we can relax any external sym. */
918 #define relaxable_symbol(symbol) \
919 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
920 || S_IS_WEAK (symbol)))
922 /* Compute the relocation code for a fixup of SIZE bytes, using pc
923 relative relocation if PCREL is non-zero. PIC says whether a special
924 pic relocation was requested. */
926 static bfd_reloc_code_real_type
927 get_reloc_code (int size, int pcrel, enum pic_relocation pic)
935 return BFD_RELOC_8_GOT_PCREL;
937 return BFD_RELOC_16_GOT_PCREL;
939 return BFD_RELOC_32_GOT_PCREL;
947 return BFD_RELOC_8_GOTOFF;
949 return BFD_RELOC_16_GOTOFF;
951 return BFD_RELOC_32_GOTOFF;
959 return BFD_RELOC_8_PLT_PCREL;
961 return BFD_RELOC_16_PLT_PCREL;
963 return BFD_RELOC_32_PLT_PCREL;
971 return BFD_RELOC_8_PLTOFF;
973 return BFD_RELOC_16_PLTOFF;
975 return BFD_RELOC_32_PLTOFF;
985 return BFD_RELOC_8_PCREL;
987 return BFD_RELOC_16_PCREL;
989 return BFD_RELOC_32_PCREL;
1001 return BFD_RELOC_32;
1008 if (pic == pic_none)
1009 as_bad (_("Can not do %d byte pc-relative relocation"), size);
1011 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
1015 if (pic == pic_none)
1016 as_bad (_("Can not do %d byte relocation"), size);
1018 as_bad (_("Can not do %d byte pic relocation"), size);
1021 return BFD_RELOC_NONE;
1024 /* Here we decide which fixups can be adjusted to make them relative
1025 to the beginning of the section instead of the symbol. Basically
1026 we need to make sure that the dynamic relocations are done
1027 correctly, so in some cases we force the original symbol to be
1030 tc_m68k_fix_adjustable (fixS *fixP)
1032 /* Adjust_reloc_syms doesn't know about the GOT. */
1033 switch (fixP->fx_r_type)
1035 case BFD_RELOC_8_GOT_PCREL:
1036 case BFD_RELOC_16_GOT_PCREL:
1037 case BFD_RELOC_32_GOT_PCREL:
1038 case BFD_RELOC_8_GOTOFF:
1039 case BFD_RELOC_16_GOTOFF:
1040 case BFD_RELOC_32_GOTOFF:
1041 case BFD_RELOC_8_PLT_PCREL:
1042 case BFD_RELOC_16_PLT_PCREL:
1043 case BFD_RELOC_32_PLT_PCREL:
1044 case BFD_RELOC_8_PLTOFF:
1045 case BFD_RELOC_16_PLTOFF:
1046 case BFD_RELOC_32_PLTOFF:
1049 case BFD_RELOC_VTABLE_INHERIT:
1050 case BFD_RELOC_VTABLE_ENTRY:
1058 #else /* !OBJ_ELF */
1060 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
1062 /* PR gas/3041 Weak symbols are not relaxable
1063 because they must be treated as extern. */
1064 #define relaxable_symbol(symbol) (!(S_IS_WEAK (symbol)))
1066 #endif /* OBJ_ELF */
1069 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
1072 bfd_reloc_code_real_type code;
1074 /* If the tcbit is set, then this was a fixup of a negative value
1075 that was never resolved. We do not have a reloc to handle this,
1076 so just return. We assume that other code will have detected this
1077 situation and produced a helpful error message, so we just tell the
1078 user that the reloc cannot be produced. */
1082 as_bad_where (fixp->fx_file, fixp->fx_line,
1083 _("Unable to produce reloc against symbol '%s'"),
1084 S_GET_NAME (fixp->fx_addsy));
1088 if (fixp->fx_r_type != BFD_RELOC_NONE)
1090 code = fixp->fx_r_type;
1092 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1093 that fixup_segment converted a non-PC relative reloc into a
1094 PC relative reloc. In such a case, we need to convert the
1101 code = BFD_RELOC_8_PCREL;
1104 code = BFD_RELOC_16_PCREL;
1107 code = BFD_RELOC_32_PCREL;
1109 case BFD_RELOC_8_PCREL:
1110 case BFD_RELOC_16_PCREL:
1111 case BFD_RELOC_32_PCREL:
1112 case BFD_RELOC_8_GOT_PCREL:
1113 case BFD_RELOC_16_GOT_PCREL:
1114 case BFD_RELOC_32_GOT_PCREL:
1115 case BFD_RELOC_8_GOTOFF:
1116 case BFD_RELOC_16_GOTOFF:
1117 case BFD_RELOC_32_GOTOFF:
1118 case BFD_RELOC_8_PLT_PCREL:
1119 case BFD_RELOC_16_PLT_PCREL:
1120 case BFD_RELOC_32_PLT_PCREL:
1121 case BFD_RELOC_8_PLTOFF:
1122 case BFD_RELOC_16_PLTOFF:
1123 case BFD_RELOC_32_PLTOFF:
1126 as_bad_where (fixp->fx_file, fixp->fx_line,
1127 _("Cannot make %s relocation PC relative"),
1128 bfd_get_reloc_code_name (code));
1134 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1135 switch (F (fixp->fx_size, fixp->fx_pcrel))
1137 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1138 MAP (1, 0, BFD_RELOC_8);
1139 MAP (2, 0, BFD_RELOC_16);
1140 MAP (4, 0, BFD_RELOC_32);
1141 MAP (1, 1, BFD_RELOC_8_PCREL);
1142 MAP (2, 1, BFD_RELOC_16_PCREL);
1143 MAP (4, 1, BFD_RELOC_32_PCREL);
1151 reloc = (arelent *) xmalloc (sizeof (arelent));
1152 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1153 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1154 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1157 reloc->addend = fixp->fx_addnumber;
1158 else if (OUTPUT_FLAVOR == bfd_target_aout_flavour
1160 && S_IS_WEAK (fixp->fx_addsy)
1161 && ! bfd_is_und_section (S_GET_SEGMENT (fixp->fx_addsy)))
1162 /* PR gas/3041 Adjust addend in order to force bfd_install_relocation()
1163 to put a zero value into frags referencing a weak symbol. */
1164 reloc->addend = - S_GET_VALUE (fixp->fx_addsy);
1168 if (!fixp->fx_pcrel)
1169 reloc->addend = fixp->fx_addnumber;
1171 reloc->addend = (section->vma
1172 /* Explicit sign extension in case char is
1174 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
1175 + fixp->fx_addnumber
1176 + md_pcrel_from (fixp));
1179 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1180 assert (reloc->howto != 0);
1185 /* Handle of the OPCODE hash table. NULL means any use before
1186 m68k_ip_begin() will crash. */
1187 static struct hash_control *op_hash;
1189 /* Assemble an m68k instruction. */
1192 m68k_ip (char *instring)
1195 register struct m68k_op *opP;
1196 register const struct m68k_incant *opcode;
1197 register const char *s;
1198 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1199 char *pdot, *pdotmove;
1200 enum m68k_size siz1, siz2;
1204 struct m68k_op operands_backup[6];
1205 LITTLENUM_TYPE words[6];
1206 LITTLENUM_TYPE *wordp;
1207 unsigned long ok_arch = 0;
1209 if (*instring == ' ')
1210 instring++; /* Skip leading whitespace. */
1212 /* Scan up to end of operation-code, which MUST end in end-of-string
1213 or exactly 1 space. */
1215 for (p = instring; *p != '\0'; p++)
1225 the_ins.error = _("No operator");
1229 /* p now points to the end of the opcode name, probably whitespace.
1230 Make sure the name is null terminated by clobbering the
1231 whitespace, look it up in the hash table, then fix it back.
1232 Remove a dot, first, since the opcode tables have none. */
1235 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1236 *pdotmove = pdotmove[1];
1242 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1247 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1248 *pdotmove = pdotmove[-1];
1255 the_ins.error = _("Unknown operator");
1259 /* Found a legitimate opcode, start matching operands. */
1263 if (opcode->m_operands == 0)
1265 char *old = input_line_pointer;
1267 input_line_pointer = p;
1268 /* Ahh - it's a motorola style psuedo op. */
1269 mote_pseudo_table[opcode->m_opnum].poc_handler
1270 (mote_pseudo_table[opcode->m_opnum].poc_val);
1271 input_line_pointer = old;
1277 if (flag_mri && opcode->m_opnum == 0)
1279 /* In MRI mode, random garbage is allowed after an instruction
1280 which accepts no operands. */
1281 the_ins.args = opcode->m_operands;
1282 the_ins.numargs = opcode->m_opnum;
1283 the_ins.numo = opcode->m_codenum;
1284 the_ins.opcode[0] = getone (opcode);
1285 the_ins.opcode[1] = gettwo (opcode);
1289 for (opP = &the_ins.operands[0]; *p; opP++)
1291 p = crack_operand (p, opP);
1295 the_ins.error = opP->error;
1300 opsfound = opP - &the_ins.operands[0];
1302 /* This ugly hack is to support the floating pt opcodes in their
1303 standard form. Essentially, we fake a first enty of type COP#1 */
1304 if (opcode->m_operands[0] == 'I')
1308 for (n = opsfound; n > 0; --n)
1309 the_ins.operands[n] = the_ins.operands[n - 1];
1311 memset (&the_ins.operands[0], '\0', sizeof (the_ins.operands[0]));
1312 the_ins.operands[0].mode = CONTROL;
1313 the_ins.operands[0].reg = m68k_float_copnum;
1317 /* We've got the operands. Find an opcode that'll accept them. */
1320 /* If we didn't get the right number of ops, or we have no
1321 common model with this pattern then reject this pattern. */
1323 ok_arch |= opcode->m_arch;
1324 if (opsfound != opcode->m_opnum
1325 || ((opcode->m_arch & current_architecture) == 0))
1331 /* Make a copy of the operands of this insn so that
1332 we can modify them safely, should we want to. */
1333 assert (opsfound <= (int) ARRAY_SIZE (operands_backup));
1334 for (i = 0; i < opsfound; i++)
1335 operands_backup[i] = the_ins.operands[i];
1337 for (s = opcode->m_operands, opP = &operands_backup[0];
1341 /* Warning: this switch is huge! */
1342 /* I've tried to organize the cases into this order:
1343 non-alpha first, then alpha by letter. Lower-case
1344 goes directly before uppercase counterpart. */
1345 /* Code with multiple case ...: gets sorted by the lowest
1346 case ... it belongs to. I hope this makes sense. */
1452 if (opP->reg == PC || opP->reg == ZPC)
1469 if (opP->reg == PC || opP->reg == ZPC)
1488 if (opP->reg == PC || opP->reg == ZPC)
1498 if (opP->mode != IMMED)
1500 else if (s[1] == 'b'
1501 && ! isvar (&opP->disp)
1502 && (opP->disp.exp.X_op != O_constant
1503 || ! isbyte (opP->disp.exp.X_add_number)))
1505 else if (s[1] == 'B'
1506 && ! isvar (&opP->disp)
1507 && (opP->disp.exp.X_op != O_constant
1508 || ! issbyte (opP->disp.exp.X_add_number)))
1510 else if (s[1] == 'w'
1511 && ! isvar (&opP->disp)
1512 && (opP->disp.exp.X_op != O_constant
1513 || ! isword (opP->disp.exp.X_add_number)))
1515 else if (s[1] == 'W'
1516 && ! isvar (&opP->disp)
1517 && (opP->disp.exp.X_op != O_constant
1518 || ! issword (opP->disp.exp.X_add_number)))
1524 if (opP->mode != IMMED)
1529 if (opP->mode == AREG
1530 || opP->mode == CONTROL
1531 || opP->mode == FPREG
1532 || opP->mode == IMMED
1533 || opP->mode == REGLST
1534 || (opP->mode != ABSL
1536 || opP->reg == ZPC)))
1541 if (opP->mode == CONTROL
1542 || opP->mode == FPREG
1543 || opP->mode == REGLST
1544 || opP->mode == IMMED
1545 || (opP->mode != ABSL
1547 || opP->reg == ZPC)))
1575 if (opP->mode == CONTROL
1576 || opP->mode == FPREG
1577 || opP->mode == REGLST)
1582 if (opP->mode != AINC)
1587 if (opP->mode != ADEC)
1637 if (opP->reg == PC || opP->reg == ZPC)
1658 case '~': /* For now! (JF FOO is this right?) */
1680 if (opP->mode != CONTROL
1681 || (opP->reg != TT0 && opP->reg != TT1))
1686 if (opP->mode != AREG)
1691 if (opP->mode != AINDR)
1696 if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
1697 && (opP->mode != DISP
1699 || opP->reg > ADDR7))
1704 if (opP->mode != ABSL
1706 && strncmp (instring, "jbsr", 4) == 0))
1729 if (opP->mode != CONTROL || opP->reg != CCR)
1734 if (opP->mode != DISP
1736 || opP->reg > ADDR7)
1741 if (opP->mode != DREG)
1746 if (opP->reg != ACC)
1751 if (opP->reg != ACC && opP->reg != ACC1
1752 && opP->reg != ACC2 && opP->reg != ACC3)
1757 if (opP->mode != FPREG)
1762 if (opP->reg != MACSR)
1767 if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
1772 if (opP->reg != MASK)
1777 if (opP->mode != CONTROL
1784 if (opP->mode != LSH && opP->mode != RSH)
1789 if (opP->mode != CONTROL
1791 || opP->reg > last_movec_reg
1796 const enum m68k_register *rp;
1798 for (rp = control_regs; *rp; rp++)
1800 if (*rp == opP->reg)
1802 /* In most CPUs RAMBAR refers to control reg
1803 c05 (RAMBAR1), but a few CPUs have it
1804 refer to c04 (RAMBAR0). */
1805 else if (*rp == RAMBAR_ALT && opP->reg == RAMBAR)
1807 opP->reg = RAMBAR_ALT;
1817 if (opP->mode != IMMED)
1823 if (opP->mode == DREG
1824 || opP->mode == AREG
1825 || opP->mode == FPREG)
1834 opP->mask = 1 << (opP->reg - DATA0);
1837 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1840 opP->mask = 1 << (opP->reg - FP0 + 16);
1848 else if (opP->mode == CONTROL)
1857 opP->mask = 1 << 24;
1860 opP->mask = 1 << 25;
1863 opP->mask = 1 << 26;
1872 else if (opP->mode != REGLST)
1874 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1876 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1881 if (opP->mode != IMMED)
1883 else if (opP->disp.exp.X_op != O_constant
1884 || ! issbyte (opP->disp.exp.X_add_number))
1886 else if (! m68k_quick
1887 && instring[3] != 'q'
1888 && instring[4] != 'q')
1893 if (opP->mode != DREG
1894 && opP->mode != IMMED
1895 && opP->mode != ABSL)
1900 if (opP->mode != IMMED)
1902 else if (opP->disp.exp.X_op != O_constant
1903 || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
1905 else if (! m68k_quick
1906 && (strncmp (instring, "add", 3) == 0
1907 || strncmp (instring, "sub", 3) == 0)
1908 && instring[3] != 'q')
1913 if (opP->mode != DREG && opP->mode != AREG)
1918 if (opP->mode != AINDR
1919 && (opP->mode != BASE
1921 && opP->reg != ZADDR0)
1922 || opP->disp.exp.X_op != O_absent
1923 || ((opP->index.reg < DATA0
1924 || opP->index.reg > DATA7)
1925 && (opP->index.reg < ADDR0
1926 || opP->index.reg > ADDR7))
1927 || opP->index.size != SIZE_UNSPEC
1928 || opP->index.scale != 1))
1933 if (opP->mode != CONTROL
1934 || ! (opP->reg == FPI
1936 || opP->reg == FPC))
1941 if (opP->mode != CONTROL || opP->reg != SR)
1946 if (opP->mode != IMMED)
1948 else if (opP->disp.exp.X_op != O_constant
1949 || TRUNC (opP->disp.exp.X_add_number) > 7)
1954 if (opP->mode != CONTROL || opP->reg != USP)
1959 if (opP->mode != IMMED)
1961 else if (opP->disp.exp.X_op != O_constant
1962 || (TRUNC (opP->disp.exp.X_add_number) != 0xffffffff
1963 && TRUNC (opP->disp.exp.X_add_number) - 1 > 6))
1967 /* JF these are out of order. We could put them
1968 in order if we were willing to put up with
1969 bunches of #ifdef m68851s in the code.
1971 Don't forget that you need these operands
1972 to use 68030 MMU instructions. */
1974 /* Memory addressing mode used by pflushr. */
1976 if (opP->mode == CONTROL
1977 || opP->mode == FPREG
1978 || opP->mode == DREG
1979 || opP->mode == AREG
1980 || opP->mode == REGLST)
1982 /* We should accept immediate operands, but they
1983 supposedly have to be quad word, and we don't
1984 handle that. I would like to see what a Motorola
1985 assembler does before doing something here. */
1986 if (opP->mode == IMMED)
1991 if (opP->mode != CONTROL
1992 || (opP->reg != SFC && opP->reg != DFC))
1997 if (opP->mode != CONTROL || opP->reg != TC)
2002 if (opP->mode != CONTROL || opP->reg != AC)
2007 if (opP->mode != CONTROL
2010 && opP->reg != SCC))
2015 if (opP->mode != CONTROL
2021 if (opP->mode != CONTROL
2024 && opP->reg != CRP))
2048 if (opP->mode != CONTROL
2049 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
2050 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
2055 if (opP->mode != CONTROL || opP->reg != PSR)
2060 if (opP->mode != CONTROL || opP->reg != PCSR)
2065 if (opP->mode != CONTROL
2074 if (opP->mode != ABSL)
2079 if (opP->reg < DATA0L || opP->reg > ADDR7U)
2081 /* FIXME: kludge instead of fixing parser:
2082 upper/lower registers are *not* CONTROL
2083 registers, but ordinary ones. */
2084 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
2085 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
2092 if (!(opP->mode == AINDR
2093 || (opP->mode == DISP
2094 && !(opP->reg == PC || opP->reg == ZPC))))
2099 if (!(opP->mode == AINDR || opP->mode == DISP))
2111 /* Since we have found the correct instruction, copy
2112 in the modifications that we may have made. */
2114 for (i = 0; i < opsfound; i++)
2115 the_ins.operands[i] = operands_backup[i];
2121 opcode = opcode->m_next;
2126 && !(ok_arch & current_architecture))
2128 const struct m68k_cpu *cpu;
2131 char *buf = xmalloc (space + 1);
2135 the_ins.error = buf;
2136 /* Make sure there's a NUL at the end of the buffer -- strncpy
2137 won't write one when it runs out of buffer */
2139 #define APPEND(STRING) \
2140 (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
2142 APPEND (_("invalid instruction for this architecture; needs "));
2146 APPEND (_("ColdFire ISA_A"));
2149 APPEND (_("ColdFire hardware divide"));
2152 APPEND (_("ColdFire ISA_A+"));
2155 APPEND (_("ColdFire ISA_B"));
2158 APPEND (_("ColdFire fpu"));
2161 APPEND (_("M68K fpu"));
2164 APPEND (_("M68K mmu"));
2167 APPEND (_("68020 or higher"));
2170 APPEND (_("68000 or higher"));
2173 APPEND (_("68010 or higher"));
2181 for (cpu = m68k_cpus; cpu->name; cpu++)
2182 if (!cpu->alias && (cpu->arch & ok_arch))
2184 const struct m68k_cpu *alias;
2185 int seen_master = 0;
2191 for (alias = cpu; alias != m68k_cpus; alias--)
2192 if (alias[-1].alias >= 0)
2194 for (; !seen_master || alias->alias > 0; alias++)
2204 APPEND (alias->name);
2217 /* we ran out of space, so replace the end of the list
2222 strcpy (buf, " ...");
2226 the_ins.error = _("operands mismatch");
2233 /* Now assemble it. */
2234 the_ins.args = opcode->m_operands;
2235 the_ins.numargs = opcode->m_opnum;
2236 the_ins.numo = opcode->m_codenum;
2237 the_ins.opcode[0] = getone (opcode);
2238 the_ins.opcode[1] = gettwo (opcode);
2240 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
2244 /* This switch is a doozy.
2245 Watch the first step; its a big one! */
2278 tmpreg = 0x3c; /* 7.4 */
2279 if (strchr ("bwl", s[1]))
2280 nextword = get_num (&opP->disp, 90);
2282 nextword = get_num (&opP->disp, 0);
2283 if (isvar (&opP->disp))
2284 add_fix (s[1], &opP->disp, 0, 0);
2288 if (!isbyte (nextword))
2289 opP->error = _("operand out of range");
2294 if (!isword (nextword))
2295 opP->error = _("operand out of range");
2300 if (!issword (nextword))
2301 opP->error = _("operand out of range");
2306 addword (nextword >> 16);
2333 /* We gotta put out some float. */
2334 if (op (&opP->disp) != O_big)
2339 /* Can other cases happen here? */
2340 if (op (&opP->disp) != O_constant)
2343 val = (valueT) offs (&opP->disp);
2347 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2348 val >>= LITTLENUM_NUMBER_OF_BITS;
2352 offs (&opP->disp) = gencnt;
2354 if (offs (&opP->disp) > 0)
2356 if (offs (&opP->disp) > baseo)
2358 as_warn (_("Bignum too big for %c format; truncated"),
2360 offs (&opP->disp) = baseo;
2362 baseo -= offs (&opP->disp);
2365 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2366 offs (&opP->disp)--;
2371 gen_to_words (words, baseo, (long) outro);
2372 for (wordp = words; baseo--; wordp++)
2376 tmpreg = opP->reg - DATA; /* 0.dreg */
2379 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2382 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2385 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2388 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2392 nextword = get_num (&opP->disp, 90);
2394 /* Convert mode 5 addressing with a zero offset into
2395 mode 2 addressing to reduce the instruction size by a
2397 if (! isvar (&opP->disp)
2399 && (opP->disp.size == SIZE_UNSPEC)
2400 && (opP->reg >= ADDR0)
2401 && (opP->reg <= ADDR7))
2403 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2408 && ! isvar (&opP->disp)
2411 opP->disp.exp.X_op = O_symbol;
2412 opP->disp.exp.X_add_symbol =
2413 section_symbol (absolute_section);
2416 /* Force into index mode. Hope this works. */
2418 /* We do the first bit for 32-bit displacements, and the
2419 second bit for 16 bit ones. It is possible that we
2420 should make the default be WORD instead of LONG, but
2421 I think that'd break GCC, so we put up with a little
2422 inefficiency for the sake of working output. */
2424 if (!issword (nextword)
2425 || (isvar (&opP->disp)
2426 && ((opP->disp.size == SIZE_UNSPEC
2427 && flag_short_refs == 0
2428 && cpu_of_arch (current_architecture) >= m68020
2429 && ! arch_coldfire_p (current_architecture))
2430 || opP->disp.size == SIZE_LONG)))
2432 if (cpu_of_arch (current_architecture) < m68020
2433 || arch_coldfire_p (current_architecture))
2435 _("displacement too large for this architecture; needs 68020 or higher");
2437 tmpreg = 0x3B; /* 7.3 */
2439 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2440 if (isvar (&opP->disp))
2444 if (opP->disp.size == SIZE_LONG
2446 /* If the displacement needs pic
2447 relocation it cannot be relaxed. */
2448 || opP->disp.pic_reloc != pic_none
2453 add_fix ('l', &opP->disp, 1, 2);
2457 add_frag (adds (&opP->disp),
2458 SEXT (offs (&opP->disp)),
2459 TAB (PCREL1632, SZ_UNDEF));
2466 add_fix ('l', &opP->disp, 0, 0);
2471 addword (nextword >> 16);
2476 tmpreg = 0x3A; /* 7.2 */
2478 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2480 if (isvar (&opP->disp))
2484 add_fix ('w', &opP->disp, 1, 0);
2487 add_fix ('w', &opP->disp, 0, 0);
2497 baseo = get_num (&opP->disp, 90);
2498 if (opP->mode == POST || opP->mode == PRE)
2499 outro = get_num (&opP->odisp, 90);
2500 /* Figure out the `addressing mode'.
2501 Also turn on the BASE_DISABLE bit, if needed. */
2502 if (opP->reg == PC || opP->reg == ZPC)
2504 tmpreg = 0x3b; /* 7.3 */
2505 if (opP->reg == ZPC)
2508 else if (opP->reg == 0)
2511 tmpreg = 0x30; /* 6.garbage */
2513 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2516 tmpreg = 0x30 + opP->reg - ZADDR0;
2519 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2521 siz1 = opP->disp.size;
2522 if (opP->mode == POST || opP->mode == PRE)
2523 siz2 = opP->odisp.size;
2527 /* Index register stuff. */
2528 if (opP->index.reg != 0
2529 && opP->index.reg >= DATA
2530 && opP->index.reg <= ADDR7)
2532 nextword |= (opP->index.reg - DATA) << 12;
2534 if (opP->index.size == SIZE_LONG
2535 || (opP->index.size == SIZE_UNSPEC
2536 && m68k_index_width_default == SIZE_LONG))
2539 if ((opP->index.scale != 1
2540 && cpu_of_arch (current_architecture) < m68020)
2541 || (opP->index.scale == 8
2542 && (arch_coldfire_p (current_architecture)
2543 && !arch_coldfire_fpu (current_architecture))))
2546 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2549 if (arch_coldfire_p (current_architecture)
2550 && opP->index.size == SIZE_WORD)
2551 opP->error = _("invalid index size for coldfire");
2553 switch (opP->index.scale)
2570 GET US OUT OF HERE! */
2572 /* Must be INDEX, with an index register. Address
2573 register cannot be ZERO-PC, and either :b was
2574 forced, or we know it will fit. For a 68000 or
2575 68010, force this mode anyways, because the
2576 larger modes aren't supported. */
2577 if (opP->mode == BASE
2578 && ((opP->reg >= ADDR0
2579 && opP->reg <= ADDR7)
2582 if (siz1 == SIZE_BYTE
2583 || cpu_of_arch (current_architecture) < m68020
2584 || arch_coldfire_p (current_architecture)
2585 || (siz1 == SIZE_UNSPEC
2586 && ! isvar (&opP->disp)
2587 && issbyte (baseo)))
2589 nextword += baseo & 0xff;
2591 if (isvar (&opP->disp))
2593 /* Do a byte relocation. If it doesn't
2594 fit (possible on m68000) let the
2595 fixup processing complain later. */
2597 add_fix ('B', &opP->disp, 1, 1);
2599 add_fix ('B', &opP->disp, 0, 0);
2601 else if (siz1 != SIZE_BYTE)
2603 if (siz1 != SIZE_UNSPEC)
2604 as_warn (_("Forcing byte displacement"));
2605 if (! issbyte (baseo))
2606 opP->error = _("byte displacement out of range");
2611 else if (siz1 == SIZE_UNSPEC
2613 && isvar (&opP->disp)
2614 && subs (&opP->disp) == NULL
2616 /* If the displacement needs pic
2617 relocation it cannot be relaxed. */
2618 && opP->disp.pic_reloc == pic_none
2622 /* The code in md_convert_frag_1 needs to be
2623 able to adjust nextword. Call frag_grow
2624 to ensure that we have enough space in
2625 the frag obstack to make all the bytes
2628 nextword += baseo & 0xff;
2630 add_frag (adds (&opP->disp),
2631 SEXT (offs (&opP->disp)),
2632 TAB (PCINDEX, SZ_UNDEF));
2640 nextword |= 0x40; /* No index reg. */
2641 if (opP->index.reg >= ZDATA0
2642 && opP->index.reg <= ZDATA7)
2643 nextword |= (opP->index.reg - ZDATA0) << 12;
2644 else if (opP->index.reg >= ZADDR0
2645 || opP->index.reg <= ZADDR7)
2646 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2649 /* It isn't simple. */
2651 if (cpu_of_arch (current_architecture) < m68020
2652 || arch_coldfire_p (current_architecture))
2654 _("invalid operand mode for this architecture; needs 68020 or higher");
2657 /* If the guy specified a width, we assume that it is
2658 wide enough. Maybe it isn't. If so, we lose. */
2662 if (isvar (&opP->disp)
2664 : ! issword (baseo))
2669 else if (! isvar (&opP->disp) && baseo == 0)
2678 as_warn (_(":b not permitted; defaulting to :w"));
2688 /* Figure out inner displacement stuff. */
2689 if (opP->mode == POST || opP->mode == PRE)
2691 if (cpu_of_arch (current_architecture) & cpu32)
2692 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2696 if (isvar (&opP->odisp)
2698 : ! issword (outro))
2703 else if (! isvar (&opP->odisp) && outro == 0)
2712 as_warn (_(":b not permitted; defaulting to :w"));
2721 if (opP->mode == POST
2722 && (nextword & 0x40) == 0)
2727 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2729 if (opP->reg == PC || opP->reg == ZPC)
2730 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2732 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2734 if (siz1 == SIZE_LONG)
2735 addword (baseo >> 16);
2736 if (siz1 != SIZE_UNSPEC)
2739 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2740 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2741 if (siz2 == SIZE_LONG)
2742 addword (outro >> 16);
2743 if (siz2 != SIZE_UNSPEC)
2749 nextword = get_num (&opP->disp, 90);
2750 switch (opP->disp.size)
2755 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2757 tmpreg = 0x38; /* 7.0 */
2761 if (isvar (&opP->disp)
2762 && !subs (&opP->disp)
2763 && adds (&opP->disp)
2765 /* If the displacement needs pic relocation it
2766 cannot be relaxed. */
2767 && opP->disp.pic_reloc == pic_none
2770 && !strchr ("~%&$?", s[0]))
2772 tmpreg = 0x3A; /* 7.2 */
2773 add_frag (adds (&opP->disp),
2774 SEXT (offs (&opP->disp)),
2775 TAB (ABSTOPCREL, SZ_UNDEF));
2778 /* Fall through into long. */
2780 if (isvar (&opP->disp))
2781 add_fix ('l', &opP->disp, 0, 0);
2783 tmpreg = 0x39;/* 7.1 mode */
2784 addword (nextword >> 16);
2789 as_bad (_("unsupported byte value; use a different suffix"));
2793 if (isvar (&opP->disp))
2794 add_fix ('w', &opP->disp, 0, 0);
2796 tmpreg = 0x38;/* 7.0 mode */
2804 as_bad (_("unknown/incorrect operand"));
2808 /* If s[0] is '4', then this is for the mac instructions
2809 that can have a trailing_ampersand set. If so, set 0x100
2810 bit on tmpreg so install_gen_operand can check for it and
2811 set the appropriate bit (word2, bit 5). */
2814 if (opP->trailing_ampersand)
2817 install_gen_operand (s[1], tmpreg);
2823 { /* JF: I hate floating point! */
2838 tmpreg = get_num (&opP->disp, tmpreg);
2839 if (isvar (&opP->disp))
2840 add_fix (s[1], &opP->disp, 0, 0);
2843 case 'b': /* Danger: These do no check for
2844 certain types of overflow.
2846 if (!isbyte (tmpreg))
2847 opP->error = _("out of range");
2848 insop (tmpreg, opcode);
2849 if (isvar (&opP->disp))
2850 the_ins.reloc[the_ins.nrel - 1].n =
2851 (opcode->m_codenum) * 2 + 1;
2854 if (!issbyte (tmpreg))
2855 opP->error = _("out of range");
2856 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2857 if (isvar (&opP->disp))
2858 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2861 if (!isword (tmpreg))
2862 opP->error = _("out of range");
2863 insop (tmpreg, opcode);
2864 if (isvar (&opP->disp))
2865 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2868 if (!issword (tmpreg))
2869 opP->error = _("out of range");
2870 insop (tmpreg, opcode);
2871 if (isvar (&opP->disp))
2872 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2875 /* Because of the way insop works, we put these two out
2877 insop (tmpreg, opcode);
2878 insop (tmpreg >> 16, opcode);
2879 if (isvar (&opP->disp))
2880 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2887 install_operand (s[1], tmpreg);
2898 install_operand (s[1], opP->reg - ADDR);
2902 tmpreg = get_num (&opP->disp, 90);
2907 add_fix ('B', &opP->disp, 1, -1);
2910 add_fix ('w', &opP->disp, 1, 0);
2915 the_ins.opcode[0] |= 0xff;
2916 add_fix ('l', &opP->disp, 1, 0);
2920 case 'g': /* Conditional branch */
2921 have_disp = HAVE_LONG_CALL (current_architecture);
2924 case 'b': /* Unconditional branch */
2925 have_disp = HAVE_LONG_BRANCH (current_architecture);
2928 case 's': /* Unconditional subroutine */
2929 have_disp = HAVE_LONG_CALL (current_architecture);
2932 if (subs (&opP->disp) /* We can't relax it. */
2934 /* If the displacement needs pic relocation it cannot be
2936 || opP->disp.pic_reloc != pic_none
2941 as_warn (_("Can't use long branches on this architecture"));
2945 /* This could either be a symbol, or an absolute
2946 address. If it's an absolute address, turn it into
2947 an absolute jump right here and keep it out of the
2949 if (adds (&opP->disp) == 0)
2951 if (the_ins.opcode[0] == 0x6000) /* jbra */
2952 the_ins.opcode[0] = 0x4EF9;
2953 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2954 the_ins.opcode[0] = 0x4EB9;
2957 the_ins.opcode[0] ^= 0x0100;
2958 the_ins.opcode[0] |= 0x0006;
2961 add_fix ('l', &opP->disp, 0, 0);
2967 /* Now we know it's going into the relaxer. Now figure
2968 out which mode. We try in this order of preference:
2969 long branch, absolute jump, byte/word branches only. */
2971 add_frag (adds (&opP->disp),
2972 SEXT (offs (&opP->disp)),
2973 TAB (BRANCHBWL, SZ_UNDEF));
2974 else if (! flag_keep_pcrel)
2976 if ((the_ins.opcode[0] == 0x6000)
2977 || (the_ins.opcode[0] == 0x6100))
2978 add_frag (adds (&opP->disp),
2979 SEXT (offs (&opP->disp)),
2980 TAB (BRABSJUNC, SZ_UNDEF));
2982 add_frag (adds (&opP->disp),
2983 SEXT (offs (&opP->disp)),
2984 TAB (BRABSJCOND, SZ_UNDEF));
2987 add_frag (adds (&opP->disp),
2988 SEXT (offs (&opP->disp)),
2989 TAB (BRANCHBW, SZ_UNDEF));
2992 if (isvar (&opP->disp))
2994 /* Check for DBcc instructions. We can relax them,
2995 but only if we have long branches and/or absolute
2997 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2998 && (HAVE_LONG_BRANCH (current_architecture)
2999 || ! flag_keep_pcrel))
3001 if (HAVE_LONG_BRANCH (current_architecture))
3002 add_frag (adds (&opP->disp),
3003 SEXT (offs (&opP->disp)),
3004 TAB (DBCCLBR, SZ_UNDEF));
3006 add_frag (adds (&opP->disp),
3007 SEXT (offs (&opP->disp)),
3008 TAB (DBCCABSJ, SZ_UNDEF));
3011 add_fix ('w', &opP->disp, 1, 0);
3015 case 'C': /* Fixed size LONG coproc branches. */
3016 add_fix ('l', &opP->disp, 1, 0);
3020 case 'c': /* Var size Coprocesssor branches. */
3021 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
3023 the_ins.opcode[the_ins.numo - 1] |= 0x40;
3024 add_fix ('l', &opP->disp, 1, 0);
3029 add_frag (adds (&opP->disp),
3030 SEXT (offs (&opP->disp)),
3031 TAB (FBRANCH, SZ_UNDEF));
3038 case 'C': /* Ignore it. */
3041 case 'd': /* JF this is a kludge. */
3042 install_operand ('s', opP->reg - ADDR);
3043 tmpreg = get_num (&opP->disp, 90);
3044 if (!issword (tmpreg))
3046 as_warn (_("Expression out of range, using 0"));
3053 install_operand (s[1], opP->reg - DATA);
3056 case 'e': /* EMAC ACCx, reg/reg. */
3057 install_operand (s[1], opP->reg - ACC);
3060 case 'E': /* Ignore it. */
3064 install_operand (s[1], opP->reg - FP0);
3067 case 'g': /* EMAC ACCEXTx. */
3068 install_operand (s[1], opP->reg - ACCEXT01);
3071 case 'G': /* Ignore it. */
3076 tmpreg = opP->reg - COP0;
3077 install_operand (s[1], tmpreg);
3080 case 'i': /* MAC/EMAC scale factor. */
3081 install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
3084 case 'J': /* JF foo. */
3224 install_operand (s[1], tmpreg);
3228 tmpreg = get_num (&opP->disp, 55);
3229 install_operand (s[1], tmpreg & 0x7f);
3236 if (tmpreg & 0x7FF0000)
3237 as_bad (_("Floating point register in register list"));
3238 insop (reverse_16_bits (tmpreg), opcode);
3242 if (tmpreg & 0x700FFFF)
3243 as_bad (_("Wrong register in floating-point reglist"));
3244 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
3252 if (tmpreg & 0x7FF0000)
3253 as_bad (_("Floating point register in register list"));
3254 insop (tmpreg, opcode);
3256 else if (s[1] == '8')
3258 if (tmpreg & 0x0FFFFFF)
3259 as_bad (_("incorrect register in reglist"));
3260 install_operand (s[1], tmpreg >> 24);
3264 if (tmpreg & 0x700FFFF)
3265 as_bad (_("wrong register in floating-point reglist"));
3267 install_operand (s[1], tmpreg >> 16);
3272 install_operand (s[1], get_num (&opP->disp, 60));
3276 tmpreg = ((opP->mode == DREG)
3277 ? 0x20 + (int) (opP->reg - DATA)
3278 : (get_num (&opP->disp, 40) & 0x1F));
3279 install_operand (s[1], tmpreg);
3283 tmpreg = get_num (&opP->disp, 10);
3286 install_operand (s[1], tmpreg);
3290 /* This depends on the fact that ADDR registers are eight
3291 more than their corresponding DATA regs, so the result
3292 will have the ADDR_REG bit set. */
3293 install_operand (s[1], opP->reg - DATA);
3297 if (opP->mode == AINDR)
3298 install_operand (s[1], opP->reg - DATA);
3300 install_operand (s[1], opP->index.reg - DATA);
3304 if (opP->reg == FPI)
3306 else if (opP->reg == FPS)
3308 else if (opP->reg == FPC)
3312 install_operand (s[1], tmpreg);
3315 case 'S': /* Ignore it. */
3319 install_operand (s[1], get_num (&opP->disp, 30));
3322 case 'U': /* Ignore it. */
3341 as_fatal (_("failed sanity check"));
3342 } /* switch on cache token. */
3343 install_operand (s[1], tmpreg);
3346 /* JF: These are out of order, I fear. */
3359 install_operand (s[1], tmpreg);
3385 install_operand (s[1], tmpreg);
3389 if (opP->reg == VAL)
3408 install_operand (s[1], tmpreg);
3422 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
3433 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
3439 install_operand (s[1], tmpreg);
3442 know (opP->reg == PSR);
3445 know (opP->reg == PCSR);
3460 install_operand (s[1], tmpreg);
3463 tmpreg = get_num (&opP->disp, 20);
3464 install_operand (s[1], tmpreg);
3466 case '_': /* used only for move16 absolute 32-bit address. */
3467 if (isvar (&opP->disp))
3468 add_fix ('l', &opP->disp, 0, 0);
3469 tmpreg = get_num (&opP->disp, 90);
3470 addword (tmpreg >> 16);
3471 addword (tmpreg & 0xFFFF);
3474 install_operand (s[1], opP->reg - DATA0L);
3475 opP->reg -= (DATA0L);
3476 opP->reg &= 0x0F; /* remove upper/lower bit. */
3479 tmpreg = get_num (&opP->disp, 80);
3482 install_operand (s[1], tmpreg);
3489 /* By the time whe get here (FINALLY) the_ins contains the complete
3490 instruction, ready to be emitted. . . */
3494 reverse_16_bits (int in)
3499 static int mask[16] =
3501 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3502 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3504 for (n = 0; n < 16; n++)
3507 out |= mask[15 - n];
3510 } /* reverse_16_bits() */
3513 reverse_8_bits (int in)
3518 static int mask[8] =
3520 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3523 for (n = 0; n < 8; n++)
3529 } /* reverse_8_bits() */
3531 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3532 (that value is chosen in the frag_var call in md_assemble). TYPE
3533 is the subtype of the frag to be generated; its primary type is
3534 rs_machine_dependent.
3536 The TYPE parameter is also used by md_convert_frag_1 and
3537 md_estimate_size_before_relax. The appropriate type of fixup will
3538 be emitted by md_convert_frag_1.
3540 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3542 install_operand (int mode, int val)
3547 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
3550 the_ins.opcode[0] |= val << 9;
3553 the_ins.opcode[1] |= val << 12;
3556 the_ins.opcode[1] |= val << 6;
3559 the_ins.opcode[1] |= val;
3562 the_ins.opcode[2] |= val << 12;
3565 the_ins.opcode[2] |= val << 6;
3568 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3569 three words long! */
3571 the_ins.opcode[2] |= val;
3574 the_ins.opcode[1] |= val << 7;
3577 the_ins.opcode[1] |= val << 10;
3581 the_ins.opcode[1] |= val << 5;
3586 the_ins.opcode[1] |= (val << 10) | (val << 7);
3589 the_ins.opcode[1] |= (val << 12) | val;
3592 the_ins.opcode[0] |= val = 0xff;
3595 the_ins.opcode[0] |= val << 9;
3598 the_ins.opcode[1] |= val;
3601 the_ins.opcode[1] |= val;
3602 the_ins.numo++; /* What a hack. */
3605 the_ins.opcode[1] |= val << 4;
3613 the_ins.opcode[0] |= (val << 6);
3616 the_ins.opcode[1] = (val >> 16);
3617 the_ins.opcode[2] = val & 0xffff;
3620 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3621 the_ins.opcode[0] |= ((val & 0x7) << 9);
3622 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3624 case 'n': /* MAC/EMAC Rx on !load. */
3625 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3626 the_ins.opcode[0] |= ((val & 0x7) << 9);
3627 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3629 case 'o': /* MAC/EMAC Rx on load. */
3630 the_ins.opcode[1] |= val << 12;
3631 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3633 case 'M': /* MAC/EMAC Ry on !load. */
3634 the_ins.opcode[0] |= (val & 0xF);
3635 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3637 case 'N': /* MAC/EMAC Ry on load. */
3638 the_ins.opcode[1] |= (val & 0xF);
3639 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3642 the_ins.opcode[1] |= ((val != 1) << 10);
3645 the_ins.opcode[0] |= ((val & 0x3) << 9);
3648 the_ins.opcode[0] |= ((val & 0x3) << 0);
3650 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3651 the_ins.opcode[0] |= ((~val & 0x1) << 7);
3652 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3654 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3655 the_ins.opcode[0] |= ((val & 0x1) << 7);
3656 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3659 the_ins.opcode[1] |= ((val & 0x3) << 9);
3662 the_ins.opcode[0] |= (val & 0x1) <<10;
3666 as_fatal (_("failed sanity check."));
3671 install_gen_operand (int mode, int val)
3675 case '/': /* Special for mask loads for mac/msac insns with
3676 possible mask; trailing_ampersend set in bit 8. */
3677 the_ins.opcode[0] |= (val & 0x3f);
3678 the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
3681 the_ins.opcode[0] |= val;
3684 /* This is a kludge!!! */
3685 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3694 the_ins.opcode[0] |= val;
3696 /* more stuff goes here. */
3698 as_fatal (_("failed sanity check."));
3702 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3703 then deal with the bitfield hack. */
3706 crack_operand (char *str, struct m68k_op *opP)
3708 register int parens;
3710 register char *beg_str;
3718 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3724 else if (*str == ')')
3728 opP->error = _("Extra )");
3734 if (flag_mri && *str == '\'')
3735 inquote = ! inquote;
3737 if (!*str && parens)
3739 opP->error = _("Missing )");
3744 if (m68k_ip_op (beg_str, opP) != 0)
3751 c = *++str; /* JF bitfield hack. */
3756 as_bad (_("Missing operand"));
3759 /* Detect MRI REG symbols and convert them to REGLSTs. */
3760 if (opP->mode == CONTROL && (int)opP->reg < 0)
3763 opP->mask = ~(int)opP->reg;
3770 /* This is the guts of the machine-dependent assembler. STR points to a
3771 machine dependent instruction. This function is supposed to emit
3772 the frags/bytes it assembles to.
3776 insert_reg (const char *regname, int regnum)
3781 #ifdef REGISTER_PREFIX
3782 if (!flag_reg_prefix_optional)
3784 buf[0] = REGISTER_PREFIX;
3785 strcpy (buf + 1, regname);
3790 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3791 &zero_address_frag));
3793 for (i = 0; regname[i]; i++)
3794 buf[i] = TOUPPER (regname[i]);
3797 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3798 &zero_address_frag));
3807 static const struct init_entry init_table[] =
3867 { "accext01", ACCEXT01 },
3868 { "accext23", ACCEXT23 },
3872 /* Control registers. */
3873 { "sfc", SFC }, /* Source Function Code. */
3875 { "dfc", DFC }, /* Destination Function Code. */
3877 { "cacr", CACR }, /* Cache Control Register. */
3878 { "caar", CAAR }, /* Cache Address Register. */
3880 { "usp", USP }, /* User Stack Pointer. */
3881 { "vbr", VBR }, /* Vector Base Register. */
3882 { "msp", MSP }, /* Master Stack Pointer. */
3883 { "isp", ISP }, /* Interrupt Stack Pointer. */
3885 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
3886 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
3887 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
3888 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
3890 /* 68ec040 versions of same */
3891 { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
3892 { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
3893 { "dacr0", DTT0 }, /* Data Access Control Register 0. */
3894 { "dacr1", DTT1 }, /* Data Access Control Register 0. */
3896 /* Coldfire versions of same. The ColdFire programmer's reference
3897 manual indicated that the order is 2,3,0,1, but Ken Rose
3898 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3899 { "acr0", ACR0 }, /* Access Control Unit 0. */
3900 { "acr1", ACR1 }, /* Access Control Unit 1. */
3901 { "acr2", ACR2 }, /* Access Control Unit 2. */
3902 { "acr3", ACR3 }, /* Access Control Unit 3. */
3904 { "tc", TC }, /* MMU Translation Control Register. */
3908 { "mmusr", MMUSR }, /* MMU Status Register. */
3909 { "srp", SRP }, /* User Root Pointer. */
3910 { "urp", URP }, /* Supervisor Root Pointer. */
3913 { "mmubar", MMUBAR },
3916 { "rombar", ROMBAR }, /* ROM Base Address Register. */
3917 { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
3918 { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
3919 { "mbar", MBAR }, /* Module Base Address Register. */
3921 { "mbar0", MBAR0 }, /* mcfv4e registers. */
3922 { "mbar1", MBAR1 }, /* mcfv4e registers. */
3923 { "rombar0", ROMBAR0 }, /* mcfv4e registers. */
3924 { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
3925 { "mpcr", MPCR }, /* mcfv4e registers. */
3926 { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
3927 { "secmbar", SECMBAR }, /* mcfv4e registers. */
3928 { "asid", TC }, /* mcfv4e registers. */
3929 { "mmubar", BUSCR }, /* mcfv4e registers. */
3930 { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
3931 { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
3932 { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
3933 { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
3934 { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
3935 { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
3936 { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
3937 { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
3938 { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
3939 { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
3940 { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
3941 { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
3943 { "flashbar", FLASHBAR }, /* mcf528x registers. */
3944 { "rambar", RAMBAR }, /* mcf528x registers. */
3946 { "mbar2", MBAR2 }, /* mcf5249 registers. */
3948 { "cac", CAC }, /* fido registers. */
3949 { "mbb", MBB }, /* fido registers. */
3950 /* End of control registers. */
3984 /* 68ec030 versions of same. */
3987 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3990 /* Suppressed data and address registers. */
4008 /* Upper and lower data and address registers, used by macw and msacw. */
4049 init_regtable (void)
4052 for (i = 0; init_table[i].name; i++)
4053 insert_reg (init_table[i].name, init_table[i].number);
4057 md_assemble (char *str)
4064 int shorts_this_frag;
4067 if (!selected_cpu && !selected_arch)
4069 /* We've not selected an architecture yet. Set the default
4070 now. We do this lazily so that an initial .cpu or .arch directive
4072 if (!m68k_set_cpu (TARGET_CPU, 1, 1))
4073 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU);
4078 /* In MRI mode, the instruction and operands are separated by a
4079 space. Anything following the operands is a comment. The label
4080 has already been removed. */
4088 for (s = str; *s != '\0'; s++)
4090 if ((*s == ' ' || *s == '\t') && ! inquote)
4108 inquote = ! inquote;
4113 memset (&the_ins, '\0', sizeof (the_ins));
4118 for (n = 0; n < the_ins.numargs; n++)
4119 if (the_ins.operands[n].error)
4121 er = the_ins.operands[n].error;
4127 as_bad (_("%s -- statement `%s' ignored"), er, str);
4131 /* If there is a current label, record that it marks an instruction. */
4132 if (current_label != NULL)
4134 current_label->text = 1;
4135 current_label = NULL;
4139 /* Tie dwarf2 debug info to the address at the start of the insn. */
4140 dwarf2_emit_insn (0);
4143 if (the_ins.nfrag == 0)
4145 /* No frag hacking involved; just put it out. */
4146 toP = frag_more (2 * the_ins.numo);
4147 fromP = &the_ins.opcode[0];
4148 for (m = the_ins.numo; m; --m)
4150 md_number_to_chars (toP, (long) (*fromP), 2);
4154 /* Put out symbol-dependent info. */
4155 for (m = 0; m < the_ins.nrel; m++)
4157 switch (the_ins.reloc[m].wid)
4176 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4177 the_ins.reloc[m].wid);
4180 fixP = fix_new_exp (frag_now,
4181 ((toP - frag_now->fr_literal)
4182 - the_ins.numo * 2 + the_ins.reloc[m].n),
4184 &the_ins.reloc[m].exp,
4185 the_ins.reloc[m].pcrel,
4186 get_reloc_code (n, the_ins.reloc[m].pcrel,
4187 the_ins.reloc[m].pic_reloc));
4188 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4189 if (the_ins.reloc[m].wid == 'B')
4190 fixP->fx_signed = 1;
4195 /* There's some frag hacking. */
4197 /* Calculate the max frag size. */
4200 wid = 2 * the_ins.fragb[0].fragoff;
4201 for (n = 1; n < the_ins.nfrag; n++)
4202 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4203 /* frag_var part. */
4205 /* Make sure the whole insn fits in one chunk, in particular that
4206 the var part is attached, as we access one byte before the
4207 variable frag for byte branches. */
4211 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
4216 wid = 2 * the_ins.fragb[n].fragoff;
4218 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4219 toP = frag_more (wid);
4221 shorts_this_frag = 0;
4222 for (m = wid / 2; m; --m)
4224 md_number_to_chars (toP, (long) (*fromP), 2);
4229 for (m = 0; m < the_ins.nrel; m++)
4231 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
4233 the_ins.reloc[m].n -= 2 * shorts_this_frag;
4236 wid = the_ins.reloc[m].wid;
4239 the_ins.reloc[m].wid = 0;
4240 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4242 fixP = fix_new_exp (frag_now,
4243 ((toP - frag_now->fr_literal)
4244 - the_ins.numo * 2 + the_ins.reloc[m].n),
4246 &the_ins.reloc[m].exp,
4247 the_ins.reloc[m].pcrel,
4248 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4249 the_ins.reloc[m].pic_reloc));
4250 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4252 (void) frag_var (rs_machine_dependent, 10, 0,
4253 (relax_substateT) (the_ins.fragb[n].fragty),
4254 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
4256 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4257 shorts_this_frag = 0;
4260 toP = frag_more (n * 2);
4263 md_number_to_chars (toP, (long) (*fromP), 2);
4269 for (m = 0; m < the_ins.nrel; m++)
4273 wid = the_ins.reloc[m].wid;
4276 the_ins.reloc[m].wid = 0;
4277 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4279 fixP = fix_new_exp (frag_now,
4280 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
4281 - shorts_this_frag * 2),
4283 &the_ins.reloc[m].exp,
4284 the_ins.reloc[m].pcrel,
4285 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4286 the_ins.reloc[m].pic_reloc));
4287 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4291 /* Comparison function used by qsort to rank the opcode entries by name. */
4294 m68k_compare_opcode (const void * v1, const void * v2)
4296 struct m68k_opcode * op1, * op2;
4302 op1 = *(struct m68k_opcode **) v1;
4303 op2 = *(struct m68k_opcode **) v2;
4305 /* Compare the two names. If different, return the comparison.
4306 If the same, return the order they are in the opcode table. */
4307 ret = strcmp (op1->name, op2->name);
4318 const struct m68k_opcode *ins;
4319 struct m68k_incant *hack, *slak;
4320 const char *retval = 0; /* Empty string, or error msg text. */
4323 /* Set up hash tables with 68000 instructions.
4324 similar to what the vax assembler does. */
4325 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4326 a copy of it at runtime, adding in the information we want but isn't
4327 there. I think it'd be better to have an awk script hack the table
4328 at compile time. Or even just xstr the table and use it as-is. But
4329 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4334 flag_reg_prefix_optional = 1;
4336 if (! m68k_rel32_from_cmdline)
4340 /* First sort the opcode table into alphabetical order to seperate
4341 the order that the assembler wants to see the opcodes from the
4342 order that the disassembler wants to see them. */
4343 m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4344 if (!m68k_sorted_opcodes)
4345 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4346 m68k_numopcodes * ((int) sizeof (* m68k_sorted_opcodes)));
4348 for (i = m68k_numopcodes; i--;)
4349 m68k_sorted_opcodes[i] = m68k_opcodes + i;
4351 qsort (m68k_sorted_opcodes, m68k_numopcodes,
4352 sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
4354 op_hash = hash_new ();
4356 obstack_begin (&robyn, 4000);
4357 for (i = 0; i < m68k_numopcodes; i++)
4359 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
4362 ins = m68k_sorted_opcodes[i];
4364 /* We *could* ignore insns that don't match our
4365 arch here by just leaving them out of the hash. */
4366 slak->m_operands = ins->args;
4367 slak->m_opnum = strlen (slak->m_operands) / 2;
4368 slak->m_arch = ins->arch;
4369 slak->m_opcode = ins->opcode;
4370 /* This is kludgey. */
4371 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
4372 if (i + 1 != m68k_numopcodes
4373 && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
4375 slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4380 slak = slak->m_next;
4384 retval = hash_insert (op_hash, ins->name, (char *) hack);
4386 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
4389 for (i = 0; i < m68k_numaliases; i++)
4391 const char *name = m68k_opcode_aliases[i].primary;
4392 const char *alias = m68k_opcode_aliases[i].alias;
4393 PTR val = hash_find (op_hash, name);
4396 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4397 retval = hash_insert (op_hash, alias, val);
4399 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4402 /* In MRI mode, all unsized branches are variable sized. Normally,
4403 they are word sized. */
4406 static struct m68k_opcode_alias mri_aliases[] =
4427 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
4430 const char *name = mri_aliases[i].primary;
4431 const char *alias = mri_aliases[i].alias;
4432 PTR val = hash_find (op_hash, name);
4435 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4436 retval = hash_jam (op_hash, alias, val);
4438 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4442 for (i = 0; i < (int) sizeof (notend_table); i++)
4444 notend_table[i] = 0;
4445 alt_notend_table[i] = 0;
4448 notend_table[','] = 1;
4449 notend_table['{'] = 1;
4450 notend_table['}'] = 1;
4451 alt_notend_table['a'] = 1;
4452 alt_notend_table['A'] = 1;
4453 alt_notend_table['d'] = 1;
4454 alt_notend_table['D'] = 1;
4455 alt_notend_table['#'] = 1;
4456 alt_notend_table['&'] = 1;
4457 alt_notend_table['f'] = 1;
4458 alt_notend_table['F'] = 1;
4459 #ifdef REGISTER_PREFIX
4460 alt_notend_table[REGISTER_PREFIX] = 1;
4463 /* We need to put '(' in alt_notend_table to handle
4464 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4465 alt_notend_table['('] = 1;
4467 /* We need to put '@' in alt_notend_table to handle
4468 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4469 alt_notend_table['@'] = 1;
4471 /* We need to put digits in alt_notend_table to handle
4472 bfextu %d0{24:1},%d0 */
4473 alt_notend_table['0'] = 1;
4474 alt_notend_table['1'] = 1;
4475 alt_notend_table['2'] = 1;
4476 alt_notend_table['3'] = 1;
4477 alt_notend_table['4'] = 1;
4478 alt_notend_table['5'] = 1;
4479 alt_notend_table['6'] = 1;
4480 alt_notend_table['7'] = 1;
4481 alt_notend_table['8'] = 1;
4482 alt_notend_table['9'] = 1;
4484 #ifndef MIT_SYNTAX_ONLY
4485 /* Insert pseudo ops, these have to go into the opcode table since
4486 gas expects pseudo ops to start with a dot. */
4490 while (mote_pseudo_table[n].poc_name)
4492 hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4493 hash_insert (op_hash,
4494 mote_pseudo_table[n].poc_name, (char *) hack);
4495 hack->m_operands = 0;
4505 record_alignment (text_section, 2);
4506 record_alignment (data_section, 2);
4507 record_alignment (bss_section, 2);
4512 /* This is called when a label is defined. */
4515 m68k_frob_label (symbolS *sym)
4517 struct label_line *n;
4519 n = (struct label_line *) xmalloc (sizeof *n);
4522 as_where (&n->file, &n->line);
4528 dwarf2_emit_label (sym);
4532 /* This is called when a value that is not an instruction is emitted. */
4535 m68k_flush_pending_output (void)
4537 current_label = NULL;
4540 /* This is called at the end of the assembly, when the final value of
4541 the label is known. We warn if this is a text symbol aligned at an
4545 m68k_frob_symbol (symbolS *sym)
4547 if (S_GET_SEGMENT (sym) == reg_section
4548 && (int) S_GET_VALUE (sym) < 0)
4550 S_SET_SEGMENT (sym, absolute_section);
4551 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4553 else if ((S_GET_VALUE (sym) & 1) != 0)
4555 struct label_line *l;
4557 for (l = labels; l != NULL; l = l->next)
4559 if (l->label == sym)
4562 as_warn_where (l->file, l->line,
4563 _("text label `%s' aligned to odd boundary"),
4571 /* This is called if we go in or out of MRI mode because of the .mri
4575 m68k_mri_mode_change (int on)
4579 if (! flag_reg_prefix_optional)
4581 flag_reg_prefix_optional = 1;
4582 #ifdef REGISTER_PREFIX
4587 if (! m68k_rel32_from_cmdline)
4592 if (! reg_prefix_optional_seen)
4594 #ifdef REGISTER_PREFIX_OPTIONAL
4595 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4597 flag_reg_prefix_optional = 0;
4599 #ifdef REGISTER_PREFIX
4604 if (! m68k_rel32_from_cmdline)
4609 /* Equal to MAX_PRECISION in atof-ieee.c. */
4610 #define MAX_LITTLENUMS 6
4612 /* Turn a string in input_line_pointer into a floating point constant
4613 of type TYPE, and store the appropriate bytes in *LITP. The number
4614 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4615 returned, or NULL on OK. */
4618 md_atof (int type, char *litP, int *sizeP)
4621 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4622 LITTLENUM_TYPE *wordP;
4653 return _("Bad call to MD_ATOF()");
4655 t = atof_ieee (input_line_pointer, type, words);
4657 input_line_pointer = t;
4659 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4660 for (wordP = words; prec--;)
4662 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4663 litP += sizeof (LITTLENUM_TYPE);
4669 md_number_to_chars (char *buf, valueT val, int n)
4671 number_to_chars_bigendian (buf, val, n);
4675 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
4677 offsetT val = *valP;
4678 addressT upper_limit;
4679 offsetT lower_limit;
4681 /* This is unnecessary but it convinces the native rs6000 compiler
4682 to generate the code we want. */
4683 char *buf = fixP->fx_frag->fr_literal;
4684 buf += fixP->fx_where;
4685 /* End ibm compiler workaround. */
4689 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
4695 memset (buf, 0, fixP->fx_size);
4696 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4698 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4699 && !S_IS_DEFINED (fixP->fx_addsy)
4700 && !S_IS_WEAK (fixP->fx_addsy))
4701 S_SET_WEAK (fixP->fx_addsy);
4704 #elif defined(OBJ_AOUT)
4705 /* PR gas/3041 Always put zero values into frags referencing a weak symbol. */
4706 if (fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy))
4708 memset (buf, 0, fixP->fx_size);
4713 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4714 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4717 switch (fixP->fx_size)
4719 /* The cast to offsetT below are necessary to make code
4720 correct for machines where ints are smaller than offsetT. */
4724 lower_limit = - (offsetT) 0x80;
4727 *buf++ = (val >> 8);
4729 upper_limit = 0x7fff;
4730 lower_limit = - (offsetT) 0x8000;
4733 *buf++ = (val >> 24);
4734 *buf++ = (val >> 16);
4735 *buf++ = (val >> 8);
4737 upper_limit = 0x7fffffff;
4738 lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
4741 BAD_CASE (fixP->fx_size);
4744 /* Fix up a negative reloc. */
4745 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4747 fixP->fx_addsy = fixP->fx_subsy;
4748 fixP->fx_subsy = NULL;
4752 /* For non-pc-relative values, it's conceivable we might get something
4753 like "0xff" for a byte field. So extend the upper part of the range
4754 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4755 so that we can do any range checking at all. */
4756 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4757 upper_limit = upper_limit * 2 + 1;
4759 if ((addressT) val > upper_limit
4760 && (val > 0 || val < lower_limit))
4761 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4763 /* A one byte PC-relative reloc means a short branch. We can't use
4764 a short branch with a value of 0 or -1, because those indicate
4765 different opcodes (branches with longer offsets). fixup_segment
4766 in write.c may have clobbered fx_pcrel, so we need to examine the
4769 || fixP->fx_r_type == BFD_RELOC_8_PCREL)
4770 && fixP->fx_size == 1
4771 && (fixP->fx_addsy == NULL
4772 || S_IS_DEFINED (fixP->fx_addsy))
4773 && (val == 0 || val == -1))
4774 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4777 /* *fragP has been relaxed to its final size, and now needs to have
4778 the bytes inside it modified to conform to the new size There is UGLY
4782 md_convert_frag_1 (fragS *fragP)
4787 /* Address in object code of the displacement. */
4788 register int object_address = fragP->fr_fix + fragP->fr_address;
4790 /* Address in gas core of the place to store the displacement. */
4791 /* This convinces the native rs6000 compiler to generate the code we
4793 register char *buffer_address = fragP->fr_literal;
4794 buffer_address += fragP->fr_fix;
4795 /* End ibm compiler workaround. */
4797 /* The displacement of the address, from current location. */
4798 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4799 disp = (disp + fragP->fr_offset) - object_address;
4801 switch (fragP->fr_subtype)
4803 case TAB (BRANCHBWL, BYTE):
4804 case TAB (BRABSJUNC, BYTE):
4805 case TAB (BRABSJCOND, BYTE):
4806 case TAB (BRANCHBW, BYTE):
4807 know (issbyte (disp));
4809 as_bad_where (fragP->fr_file, fragP->fr_line,
4810 _("short branch with zero offset: use :w"));
4811 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4812 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4813 fixP->fx_pcrel_adjust = -1;
4815 case TAB (BRANCHBWL, SHORT):
4816 case TAB (BRABSJUNC, SHORT):
4817 case TAB (BRABSJCOND, SHORT):
4818 case TAB (BRANCHBW, SHORT):
4819 fragP->fr_opcode[1] = 0x00;
4820 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4821 1, RELAX_RELOC_PC16);
4824 case TAB (BRANCHBWL, LONG):
4825 fragP->fr_opcode[1] = (char) 0xFF;
4826 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4827 1, RELAX_RELOC_PC32);
4830 case TAB (BRABSJUNC, LONG):
4831 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4833 if (flag_keep_pcrel)
4834 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4835 fragP->fr_opcode[0] = 0x4E;
4836 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4837 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4838 0, RELAX_RELOC_ABS32);
4841 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4843 if (flag_keep_pcrel)
4844 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4845 fragP->fr_opcode[0] = 0x4E;
4846 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4847 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4848 0, RELAX_RELOC_ABS32);
4853 /* This cannot happen, because jbsr and jbra are the only two
4854 unconditional branches. */
4858 case TAB (BRABSJCOND, LONG):
4859 if (flag_keep_pcrel)
4860 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4862 /* Only Bcc 68000 instructions can come here
4863 Change bcc into b!cc/jmp absl long. */
4864 fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
4865 fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
4867 /* JF: these used to be fr_opcode[2,3], but they may be in a
4868 different frag, in which case referring to them is a no-no.
4869 Only fr_opcode[0,1] are guaranteed to work. */
4870 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4871 *buffer_address++ = (char) 0xf9;
4872 fragP->fr_fix += 2; /* Account for jmp instruction. */
4873 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4874 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4877 case TAB (FBRANCH, SHORT):
4878 know ((fragP->fr_opcode[1] & 0x40) == 0);
4879 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4880 1, RELAX_RELOC_PC16);
4883 case TAB (FBRANCH, LONG):
4884 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
4885 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4886 1, RELAX_RELOC_PC32);
4889 case TAB (DBCCLBR, SHORT):
4890 case TAB (DBCCABSJ, SHORT):
4891 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4892 1, RELAX_RELOC_PC16);
4895 case TAB (DBCCLBR, LONG):
4896 /* Only DBcc instructions can come here.
4897 Change dbcc into dbcc/bral.
4898 JF: these used to be fr_opcode[2-7], but that's wrong. */
4899 if (flag_keep_pcrel)
4900 as_fatal (_("Tried to convert DBcc to absolute jump"));
4902 *buffer_address++ = 0x00; /* Branch offset = 4. */
4903 *buffer_address++ = 0x04;
4904 *buffer_address++ = 0x60; /* Put in bra pc+6. */
4905 *buffer_address++ = 0x06;
4906 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4907 *buffer_address++ = (char) 0xff;
4909 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4910 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4914 case TAB (DBCCABSJ, LONG):
4915 /* Only DBcc instructions can come here.
4916 Change dbcc into dbcc/jmp.
4917 JF: these used to be fr_opcode[2-7], but that's wrong. */
4918 if (flag_keep_pcrel)
4919 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4921 *buffer_address++ = 0x00; /* Branch offset = 4. */
4922 *buffer_address++ = 0x04;
4923 *buffer_address++ = 0x60; /* Put in bra pc + 6. */
4924 *buffer_address++ = 0x06;
4925 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4926 *buffer_address++ = (char) 0xf9;
4928 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4929 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4933 case TAB (PCREL1632, SHORT):
4934 fragP->fr_opcode[1] &= ~0x3F;
4935 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4936 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4937 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4940 case TAB (PCREL1632, LONG):
4941 /* Already set to mode 7.3; this indicates: PC indirect with
4942 suppressed index, 32-bit displacement. */
4943 *buffer_address++ = 0x01;
4944 *buffer_address++ = 0x70;
4946 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4947 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4948 fixP->fx_pcrel_adjust = 2;
4951 case TAB (PCINDEX, BYTE):
4952 assert (fragP->fr_fix >= 2);
4953 buffer_address[-2] &= ~1;
4954 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4955 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4956 fixP->fx_pcrel_adjust = 1;
4958 case TAB (PCINDEX, SHORT):
4959 assert (fragP->fr_fix >= 2);
4960 buffer_address[-2] |= 0x1;
4961 buffer_address[-1] = 0x20;
4962 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4963 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4964 fixP->fx_pcrel_adjust = 2;
4967 case TAB (PCINDEX, LONG):
4968 assert (fragP->fr_fix >= 2);
4969 buffer_address[-2] |= 0x1;
4970 buffer_address[-1] = 0x30;
4971 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4972 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4973 fixP->fx_pcrel_adjust = 2;
4976 case TAB (ABSTOPCREL, SHORT):
4977 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4978 1, RELAX_RELOC_PC16);
4981 case TAB (ABSTOPCREL, LONG):
4982 if (flag_keep_pcrel)
4983 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4984 /* The thing to do here is force it to ABSOLUTE LONG, since
4985 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4986 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4988 fragP->fr_opcode[1] &= ~0x3F;
4989 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4990 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4991 0, RELAX_RELOC_ABS32);
4998 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
4999 segT sec ATTRIBUTE_UNUSED,
5002 md_convert_frag_1 (fragP);
5005 /* Force truly undefined symbols to their maximum size, and generally set up
5006 the frag list to be relaxed
5009 md_estimate_size_before_relax (fragS *fragP, segT segment)
5011 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
5012 switch (fragP->fr_subtype)
5014 case TAB (BRANCHBWL, SZ_UNDEF):
5015 case TAB (BRABSJUNC, SZ_UNDEF):
5016 case TAB (BRABSJCOND, SZ_UNDEF):
5018 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5019 && relaxable_symbol (fragP->fr_symbol))
5021 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5023 else if (flag_short_refs)
5025 /* Symbol is undefined and we want short ref. */
5026 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5030 /* Symbol is still undefined. Make it LONG. */
5031 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5036 case TAB (BRANCHBW, SZ_UNDEF):
5038 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5039 && relaxable_symbol (fragP->fr_symbol))
5041 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5045 /* Symbol is undefined and we don't have long branches. */
5046 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5051 case TAB (FBRANCH, SZ_UNDEF):
5052 case TAB (DBCCLBR, SZ_UNDEF):
5053 case TAB (DBCCABSJ, SZ_UNDEF):
5054 case TAB (PCREL1632, SZ_UNDEF):
5056 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5057 && relaxable_symbol (fragP->fr_symbol))
5060 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5064 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5069 case TAB (PCINDEX, SZ_UNDEF):
5070 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5071 && relaxable_symbol (fragP->fr_symbol)))
5073 fragP->fr_subtype = TAB (PCINDEX, BYTE);
5077 fragP->fr_subtype = TAB (PCINDEX, LONG);
5081 case TAB (ABSTOPCREL, SZ_UNDEF):
5083 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5084 && relaxable_symbol (fragP->fr_symbol)))
5086 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
5090 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
5099 /* Now that SZ_UNDEF are taken care of, check others. */
5100 switch (fragP->fr_subtype)
5102 case TAB (BRANCHBWL, BYTE):
5103 case TAB (BRABSJUNC, BYTE):
5104 case TAB (BRABSJCOND, BYTE):
5105 case TAB (BRANCHBW, BYTE):
5106 /* We can't do a short jump to the next instruction, so in that
5107 case we force word mode. If the symbol is at the start of a
5108 frag, and it is the next frag with any data in it (usually
5109 this is just the next frag, but assembler listings may
5110 introduce empty frags), we must use word mode. */
5111 if (fragP->fr_symbol)
5115 sym_frag = symbol_get_frag (fragP->fr_symbol);
5116 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
5120 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
5124 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5131 return md_relax_table[fragP->fr_subtype].rlx_length;
5134 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5135 /* the bit-field entries in the relocation_info struct plays hell
5136 with the byte-order problems of cross-assembly. So as a hack,
5137 I added this mach. dependent ri twiddler. Ugly, but it gets
5139 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5140 are symbolnum, most sig. byte first. Last byte is broken up with
5141 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5142 nibble as nuthin. (on Sun 3 at least) */
5143 /* Translate the internal relocation information into target-specific
5147 md_ri_to_chars (char *the_bytes, struct reloc_info_generic *ri)
5150 md_number_to_chars (the_bytes, ri->r_address, 4);
5151 /* Now the fun stuff. */
5152 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
5153 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
5154 the_bytes[6] = ri->r_symbolnum & 0x0ff;
5155 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80)
5156 | ((ri->r_length << 5) & 0x60)
5157 | ((ri->r_extern << 4) & 0x10));
5162 #endif /* OBJ_AOUT or OBJ_BOUT */
5164 #ifndef WORKING_DOT_WORD
5165 int md_short_jump_size = 4;
5166 int md_long_jump_size = 6;
5169 md_create_short_jump (char *ptr, addressT from_addr, addressT to_addr,
5170 fragS *frag ATTRIBUTE_UNUSED,
5171 symbolS *to_symbol ATTRIBUTE_UNUSED)
5175 offset = to_addr - (from_addr + 2);
5177 md_number_to_chars (ptr, (valueT) 0x6000, 2);
5178 md_number_to_chars (ptr + 2, (valueT) offset, 2);
5182 md_create_long_jump (char *ptr, addressT from_addr, addressT to_addr,
5183 fragS *frag, symbolS *to_symbol)
5187 if (!HAVE_LONG_BRANCH (current_architecture))
5189 if (flag_keep_pcrel)
5190 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5191 offset = to_addr - S_GET_VALUE (to_symbol);
5192 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
5193 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5194 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
5199 offset = to_addr - (from_addr + 2);
5200 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
5201 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5207 /* Different values of OK tell what its OK to return. Things that
5208 aren't OK are an error (what a shock, no?)
5211 10: Absolute 1:8 only
5212 20: Absolute 0:7 only
5213 30: absolute 0:15 only
5214 40: Absolute 0:31 only
5215 50: absolute 0:127 only
5216 55: absolute -64:63 only
5217 60: absolute -128:127 only
5218 70: absolute 0:4095 only
5219 80: absolute -1, 1:7 only
5223 get_num (struct m68k_exp *exp, int ok)
5225 if (exp->exp.X_op == O_absent)
5227 /* Do the same thing the VAX asm does. */
5228 op (exp) = O_constant;
5234 as_warn (_("expression out of range: defaulting to 1"));
5238 else if (exp->exp.X_op == O_constant)
5243 if ((valueT) TRUNC (offs (exp)) - 1 > 7)
5245 as_warn (_("expression out of range: defaulting to 1"));
5250 if ((valueT) TRUNC (offs (exp)) > 7)
5254 if ((valueT) TRUNC (offs (exp)) > 15)
5258 if ((valueT) TRUNC (offs (exp)) > 32)
5262 if ((valueT) TRUNC (offs (exp)) > 127)
5266 if ((valueT) SEXT (offs (exp)) + 64 > 127)
5270 if ((valueT) SEXT (offs (exp)) + 128 > 255)
5274 if ((valueT) TRUNC (offs (exp)) > 4095)
5277 as_warn (_("expression out of range: defaulting to 0"));
5282 if ((valueT) TRUNC (offs (exp)) != 0xffffffff
5283 && (valueT) TRUNC (offs (exp)) - 1 > 6)
5285 as_warn (_("expression out of range: defaulting to 1"));
5293 else if (exp->exp.X_op == O_big)
5295 if (offs (exp) <= 0 /* flonum. */
5296 && (ok == 90 /* no bignums */
5297 || (ok > 10 /* Small-int ranges including 0 ok. */
5298 /* If we have a flonum zero, a zero integer should
5299 do as well (e.g., in moveq). */
5300 && generic_floating_point_number.exponent == 0
5301 && generic_floating_point_number.low[0] == 0)))
5303 /* HACK! Turn it into a long. */
5304 LITTLENUM_TYPE words[6];
5306 gen_to_words (words, 2, 8L); /* These numbers are magic! */
5307 op (exp) = O_constant;
5310 offs (exp) = words[1] | (words[0] << 16);
5314 op (exp) = O_constant;
5317 offs (exp) = (ok == 10) ? 1 : 0;
5318 as_warn (_("Can't deal with expression; defaulting to %ld"),
5324 if (ok >= 10 && ok <= 80)
5326 op (exp) = O_constant;
5329 offs (exp) = (ok == 10) ? 1 : 0;
5330 as_warn (_("Can't deal with expression; defaulting to %ld"),
5335 if (exp->size != SIZE_UNSPEC)
5343 if (!isbyte (offs (exp)))
5344 as_warn (_("expression doesn't fit in BYTE"));
5347 if (!isword (offs (exp)))
5348 as_warn (_("expression doesn't fit in WORD"));
5356 /* These are the back-ends for the various machine dependent pseudo-ops. */
5359 s_data1 (int ignore ATTRIBUTE_UNUSED)
5361 subseg_set (data_section, 1);
5362 demand_empty_rest_of_line ();
5366 s_data2 (int ignore ATTRIBUTE_UNUSED)
5368 subseg_set (data_section, 2);
5369 demand_empty_rest_of_line ();
5373 s_bss (int ignore ATTRIBUTE_UNUSED)
5375 /* We don't support putting frags in the BSS segment, we fake it
5376 by marking in_bss, then looking at s_skip for clues. */
5378 subseg_set (bss_section, 0);
5379 demand_empty_rest_of_line ();
5383 s_even (int ignore ATTRIBUTE_UNUSED)
5386 register long temp_fill;
5388 temp = 1; /* JF should be 2? */
5389 temp_fill = get_absolute_expression ();
5390 if (!need_pass_2) /* Never make frag if expect extra pass. */
5391 frag_align (temp, (int) temp_fill, 0);
5392 demand_empty_rest_of_line ();
5393 record_alignment (now_seg, temp);
5397 s_proc (int ignore ATTRIBUTE_UNUSED)
5399 demand_empty_rest_of_line ();
5402 /* Pseudo-ops handled for MRI compatibility. */
5404 /* This function returns non-zero if the argument is a conditional
5405 pseudo-op. This is called when checking whether a pending
5406 alignment is needed. */
5409 m68k_conditional_pseudoop (pseudo_typeS *pop)
5411 return (pop->poc_handler == s_mri_if
5412 || pop->poc_handler == s_mri_else);
5415 /* Handle an MRI style chip specification. */
5424 s = input_line_pointer;
5425 /* We can't use get_symbol_end since the processor names are not proper
5427 while (is_part_of_name (c = *input_line_pointer++))
5429 *--input_line_pointer = 0;
5430 for (i = 0; m68k_cpus[i].name; i++)
5431 if (strcasecmp (s, m68k_cpus[i].name) == 0)
5433 if (!m68k_cpus[i].name)
5435 as_bad (_("%s: unrecognized processor name"), s);
5436 *input_line_pointer = c;
5437 ignore_rest_of_line ();
5440 *input_line_pointer = c;
5442 if (*input_line_pointer == '/')
5443 current_architecture = 0;
5445 current_architecture &= m68881 | m68851;
5446 current_architecture |= m68k_cpus[i].arch & ~(m68881 | m68851);
5447 control_regs = m68k_cpus[i].control_regs;
5449 while (*input_line_pointer == '/')
5451 ++input_line_pointer;
5452 s = input_line_pointer;
5453 /* We can't use get_symbol_end since the processor names are not
5455 while (is_part_of_name (c = *input_line_pointer++))
5457 *--input_line_pointer = 0;
5458 if (strcmp (s, "68881") == 0)
5459 current_architecture |= m68881;
5460 else if (strcmp (s, "68851") == 0)
5461 current_architecture |= m68851;
5462 *input_line_pointer = c;
5466 /* The MRI CHIP pseudo-op. */
5469 s_chip (int ignore ATTRIBUTE_UNUSED)
5475 stop = mri_comment_field (&stopc);
5478 mri_comment_end (stop, stopc);
5479 demand_empty_rest_of_line ();
5482 /* The MRI FOPT pseudo-op. */
5485 s_fopt (int ignore ATTRIBUTE_UNUSED)
5489 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5493 input_line_pointer += 3;
5494 temp = get_absolute_expression ();
5495 if (temp < 0 || temp > 7)
5496 as_bad (_("bad coprocessor id"));
5498 m68k_float_copnum = COP0 + temp;
5502 as_bad (_("unrecognized fopt option"));
5503 ignore_rest_of_line ();
5507 demand_empty_rest_of_line ();
5510 /* The structure used to handle the MRI OPT pseudo-op. */
5514 /* The name of the option. */
5517 /* If this is not NULL, just call this function. The first argument
5518 is the ARG field of this structure, the second argument is
5519 whether the option was negated. */
5520 void (*pfn) (int arg, int on);
5522 /* If this is not NULL, and the PFN field is NULL, set the variable
5523 this points to. Set it to the ARG field if the option was not
5524 negated, and the NOTARG field otherwise. */
5527 /* The value to pass to PFN or to assign to *PVAR. */
5530 /* The value to assign to *PVAR if the option is negated. If PFN is
5531 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5532 the option may not be negated. */
5536 /* The table used to handle the MRI OPT pseudo-op. */
5538 static void skip_to_comma (int, int);
5539 static void opt_nest (int, int);
5540 static void opt_chip (int, int);
5541 static void opt_list (int, int);
5542 static void opt_list_symbols (int, int);
5544 static const struct opt_action opt_table[] =
5546 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5548 /* We do relaxing, so there is little use for these options. */
5549 { "b", 0, 0, 0, 0 },
5550 { "brs", 0, 0, 0, 0 },
5551 { "brb", 0, 0, 0, 0 },
5552 { "brl", 0, 0, 0, 0 },
5553 { "brw", 0, 0, 0, 0 },
5555 { "c", 0, 0, 0, 0 },
5556 { "cex", 0, 0, 0, 0 },
5557 { "case", 0, &symbols_case_sensitive, 1, 0 },
5558 { "cl", 0, 0, 0, 0 },
5559 { "cre", 0, 0, 0, 0 },
5560 { "d", 0, &flag_keep_locals, 1, 0 },
5561 { "e", 0, 0, 0, 0 },
5562 { "f", 0, &flag_short_refs, 1, 0 },
5563 { "frs", 0, &flag_short_refs, 1, 0 },
5564 { "frl", 0, &flag_short_refs, 0, 1 },
5565 { "g", 0, 0, 0, 0 },
5566 { "i", 0, 0, 0, 0 },
5567 { "m", 0, 0, 0, 0 },
5568 { "mex", 0, 0, 0, 0 },
5569 { "mc", 0, 0, 0, 0 },
5570 { "md", 0, 0, 0, 0 },
5571 { "nest", opt_nest, 0, 0, 0 },
5572 { "next", skip_to_comma, 0, 0, 0 },
5573 { "o", 0, 0, 0, 0 },
5574 { "old", 0, 0, 0, 0 },
5575 { "op", skip_to_comma, 0, 0, 0 },
5576 { "pco", 0, 0, 0, 0 },
5577 { "p", opt_chip, 0, 0, 0 },
5578 { "pcr", 0, 0, 0, 0 },
5579 { "pcs", 0, 0, 0, 0 },
5580 { "r", 0, 0, 0, 0 },
5581 { "quick", 0, &m68k_quick, 1, 0 },
5582 { "rel32", 0, &m68k_rel32, 1, 0 },
5583 { "s", opt_list, 0, 0, 0 },
5584 { "t", opt_list_symbols, 0, 0, 0 },
5585 { "w", 0, &flag_no_warnings, 0, 1 },
5589 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5591 /* The MRI OPT pseudo-op. */
5594 s_opt (int ignore ATTRIBUTE_UNUSED)
5602 const struct opt_action *o;
5607 if (*input_line_pointer == '-')
5609 ++input_line_pointer;
5612 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5614 input_line_pointer += 2;
5618 s = input_line_pointer;
5619 c = get_symbol_end ();
5621 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5623 if (strcasecmp (s, o->name) == 0)
5627 /* Restore input_line_pointer now in case the option
5629 *input_line_pointer = c;
5630 (*o->pfn) (o->arg, t);
5632 else if (o->pvar != NULL)
5634 if (! t && o->arg == o->notarg)
5635 as_bad (_("option `%s' may not be negated"), s);
5636 *input_line_pointer = c;
5637 *o->pvar = t ? o->arg : o->notarg;
5640 *input_line_pointer = c;
5646 as_bad (_("option `%s' not recognized"), s);
5647 *input_line_pointer = c;
5650 while (*input_line_pointer++ == ',');
5652 /* Move back to terminating character. */
5653 --input_line_pointer;
5654 demand_empty_rest_of_line ();
5657 /* Skip ahead to a comma. This is used for OPT options which we do
5658 not support and which take arguments. */
5661 skip_to_comma (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5663 while (*input_line_pointer != ','
5664 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5665 ++input_line_pointer;
5668 /* Handle the OPT NEST=depth option. */
5671 opt_nest (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5673 if (*input_line_pointer != '=')
5675 as_bad (_("bad format of OPT NEST=depth"));
5679 ++input_line_pointer;
5680 max_macro_nest = get_absolute_expression ();
5683 /* Handle the OPT P=chip option. */
5686 opt_chip (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5688 if (*input_line_pointer != '=')
5690 /* This is just OPT P, which we do not support. */
5694 ++input_line_pointer;
5698 /* Handle the OPT S option. */
5701 opt_list (int arg ATTRIBUTE_UNUSED, int on)
5706 /* Handle the OPT T option. */
5709 opt_list_symbols (int arg ATTRIBUTE_UNUSED, int on)
5712 listing |= LISTING_SYMBOLS;
5714 listing &= ~LISTING_SYMBOLS;
5717 /* Handle the MRI REG pseudo-op. */
5720 s_reg (int ignore ATTRIBUTE_UNUSED)
5729 if (line_label == NULL)
5731 as_bad (_("missing label"));
5732 ignore_rest_of_line ();
5737 stop = mri_comment_field (&stopc);
5741 s = input_line_pointer;
5742 while (ISALNUM (*input_line_pointer)
5743 #ifdef REGISTER_PREFIX
5744 || *input_line_pointer == REGISTER_PREFIX
5746 || *input_line_pointer == '/'
5747 || *input_line_pointer == '-')
5748 ++input_line_pointer;
5749 c = *input_line_pointer;
5750 *input_line_pointer = '\0';
5752 if (m68k_ip_op (s, &rop) != 0)
5754 if (rop.error == NULL)
5755 as_bad (_("bad register list"));
5757 as_bad (_("bad register list: %s"), rop.error);
5758 *input_line_pointer = c;
5759 ignore_rest_of_line ();
5763 *input_line_pointer = c;
5765 if (rop.mode == REGLST)
5767 else if (rop.mode == DREG)
5768 mask = 1 << (rop.reg - DATA0);
5769 else if (rop.mode == AREG)
5770 mask = 1 << (rop.reg - ADDR0 + 8);
5771 else if (rop.mode == FPREG)
5772 mask = 1 << (rop.reg - FP0 + 16);
5773 else if (rop.mode == CONTROL
5776 else if (rop.mode == CONTROL
5779 else if (rop.mode == CONTROL
5784 as_bad (_("bad register list"));
5785 ignore_rest_of_line ();
5789 S_SET_SEGMENT (line_label, reg_section);
5790 S_SET_VALUE (line_label, ~mask);
5791 symbol_set_frag (line_label, &zero_address_frag);
5794 mri_comment_end (stop, stopc);
5796 demand_empty_rest_of_line ();
5799 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5803 struct save_opts *next;
5805 int symbols_case_sensitive;
5809 const enum m68k_register *control_regs;
5814 /* FIXME: We don't save OPT S. */
5817 /* This variable holds the stack of saved options. */
5819 static struct save_opts *save_stack;
5821 /* The MRI SAVE pseudo-op. */
5824 s_save (int ignore ATTRIBUTE_UNUSED)
5826 struct save_opts *s;
5828 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5829 s->abspcadd = m68k_abspcadd;
5830 s->symbols_case_sensitive = symbols_case_sensitive;
5831 s->keep_locals = flag_keep_locals;
5832 s->short_refs = flag_short_refs;
5833 s->architecture = current_architecture;
5834 s->control_regs = control_regs;
5835 s->quick = m68k_quick;
5836 s->rel32 = m68k_rel32;
5837 s->listing = listing;
5838 s->no_warnings = flag_no_warnings;
5840 s->next = save_stack;
5843 demand_empty_rest_of_line ();
5846 /* The MRI RESTORE pseudo-op. */
5849 s_restore (int ignore ATTRIBUTE_UNUSED)
5851 struct save_opts *s;
5853 if (save_stack == NULL)
5855 as_bad (_("restore without save"));
5856 ignore_rest_of_line ();
5861 save_stack = s->next;
5863 m68k_abspcadd = s->abspcadd;
5864 symbols_case_sensitive = s->symbols_case_sensitive;
5865 flag_keep_locals = s->keep_locals;
5866 flag_short_refs = s->short_refs;
5867 current_architecture = s->architecture;
5868 control_regs = s->control_regs;
5869 m68k_quick = s->quick;
5870 m68k_rel32 = s->rel32;
5871 listing = s->listing;
5872 flag_no_warnings = s->no_warnings;
5876 demand_empty_rest_of_line ();
5879 /* Types of MRI structured control directives. */
5881 enum mri_control_type
5889 /* This structure is used to stack the MRI structured control
5892 struct mri_control_info
5894 /* The directive within which this one is enclosed. */
5895 struct mri_control_info *outer;
5897 /* The type of directive. */
5898 enum mri_control_type type;
5900 /* Whether an ELSE has been in an IF. */
5903 /* The add or sub statement at the end of a FOR. */
5906 /* The label of the top of a FOR or REPEAT loop. */
5909 /* The label to jump to for the next iteration, or the else
5910 expression of a conditional. */
5913 /* The label to jump to to break out of the loop, or the label past
5914 the end of a conditional. */
5918 /* The stack of MRI structured control directives. */
5920 static struct mri_control_info *mri_control_stack;
5922 /* The current MRI structured control directive index number, used to
5923 generate label names. */
5925 static int mri_control_index;
5927 /* Assemble an instruction for an MRI structured control directive. */
5930 mri_assemble (char *str)
5934 /* md_assemble expects the opcode to be in lower case. */
5935 for (s = str; *s != ' ' && *s != '\0'; s++)
5941 /* Generate a new MRI label structured control directive label name. */
5944 mri_control_label (void)
5948 n = (char *) xmalloc (20);
5949 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5950 ++mri_control_index;
5954 /* Create a new MRI structured control directive. */
5956 static struct mri_control_info *
5957 push_mri_control (enum mri_control_type type)
5959 struct mri_control_info *n;
5961 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5965 if (type == mri_if || type == mri_while)
5968 n->top = mri_control_label ();
5969 n->next = mri_control_label ();
5970 n->bottom = mri_control_label ();
5972 n->outer = mri_control_stack;
5973 mri_control_stack = n;
5978 /* Pop off the stack of MRI structured control directives. */
5981 pop_mri_control (void)
5983 struct mri_control_info *n;
5985 n = mri_control_stack;
5986 mri_control_stack = n->outer;
5994 /* Recognize a condition code in an MRI structured control expression. */
5997 parse_mri_condition (int *pcc)
6001 know (*input_line_pointer == '<');
6003 ++input_line_pointer;
6004 c1 = *input_line_pointer++;
6005 c2 = *input_line_pointer++;
6007 if (*input_line_pointer != '>')
6009 as_bad (_("syntax error in structured control directive"));
6013 ++input_line_pointer;
6019 *pcc = (c1 << 8) | c2;
6024 /* Parse a single operand in an MRI structured control expression. */
6027 parse_mri_control_operand (int *pcc, char **leftstart, char **leftstop,
6028 char **rightstart, char **rightstop)
6040 if (*input_line_pointer == '<')
6042 /* It's just a condition code. */
6043 return parse_mri_condition (pcc);
6046 /* Look ahead for the condition code. */
6047 for (s = input_line_pointer; *s != '\0'; ++s)
6049 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
6054 as_bad (_("missing condition code in structured control directive"));
6058 *leftstart = input_line_pointer;
6060 if (*leftstop > *leftstart
6061 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
6064 input_line_pointer = s;
6065 if (! parse_mri_condition (pcc))
6068 /* Look ahead for AND or OR or end of line. */
6069 for (s = input_line_pointer; *s != '\0'; ++s)
6071 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6072 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6074 if ((s == input_line_pointer
6077 && ((strncasecmp (s, "AND", 3) == 0
6078 && (s[3] == '.' || ! is_part_of_name (s[3])))
6079 || (strncasecmp (s, "OR", 2) == 0
6080 && (s[2] == '.' || ! is_part_of_name (s[2])))))
6084 *rightstart = input_line_pointer;
6086 if (*rightstop > *rightstart
6087 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
6090 input_line_pointer = s;
6095 #define MCC(b1, b2) (((b1) << 8) | (b2))
6097 /* Swap the sense of a condition. This changes the condition so that
6098 it generates the same result when the operands are swapped. */
6101 swap_mri_condition (int cc)
6105 case MCC ('h', 'i'): return MCC ('c', 's');
6106 case MCC ('l', 's'): return MCC ('c', 'c');
6107 /* <HS> is an alias for <CC>. */
6108 case MCC ('h', 's'):
6109 case MCC ('c', 'c'): return MCC ('l', 's');
6110 /* <LO> is an alias for <CS>. */
6111 case MCC ('l', 'o'):
6112 case MCC ('c', 's'): return MCC ('h', 'i');
6113 case MCC ('p', 'l'): return MCC ('m', 'i');
6114 case MCC ('m', 'i'): return MCC ('p', 'l');
6115 case MCC ('g', 'e'): return MCC ('l', 'e');
6116 case MCC ('l', 't'): return MCC ('g', 't');
6117 case MCC ('g', 't'): return MCC ('l', 't');
6118 case MCC ('l', 'e'): return MCC ('g', 'e');
6119 /* Issue a warning for conditions we can not swap. */
6120 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
6121 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
6122 case MCC ('v', 'c'):
6123 case MCC ('v', 's'):
6125 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6126 (char) (cc >> 8), (char) (cc));
6132 /* Reverse the sense of a condition. */
6135 reverse_mri_condition (int cc)
6139 case MCC ('h', 'i'): return MCC ('l', 's');
6140 case MCC ('l', 's'): return MCC ('h', 'i');
6141 /* <HS> is an alias for <CC> */
6142 case MCC ('h', 's'): return MCC ('l', 'o');
6143 case MCC ('c', 'c'): return MCC ('c', 's');
6144 /* <LO> is an alias for <CS> */
6145 case MCC ('l', 'o'): return MCC ('h', 's');
6146 case MCC ('c', 's'): return MCC ('c', 'c');
6147 case MCC ('n', 'e'): return MCC ('e', 'q');
6148 case MCC ('e', 'q'): return MCC ('n', 'e');
6149 case MCC ('v', 'c'): return MCC ('v', 's');
6150 case MCC ('v', 's'): return MCC ('v', 'c');
6151 case MCC ('p', 'l'): return MCC ('m', 'i');
6152 case MCC ('m', 'i'): return MCC ('p', 'l');
6153 case MCC ('g', 'e'): return MCC ('l', 't');
6154 case MCC ('l', 't'): return MCC ('g', 'e');
6155 case MCC ('g', 't'): return MCC ('l', 'e');
6156 case MCC ('l', 'e'): return MCC ('g', 't');
6161 /* Build an MRI structured control expression. This generates test
6162 and branch instructions. It goes to TRUELAB if the condition is
6163 true, and to FALSELAB if the condition is false. Exactly one of
6164 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6165 is the size qualifier for the expression. EXTENT is the size to
6166 use for the branch. */
6169 build_mri_control_operand (int qual, int cc, char *leftstart, char *leftstop,
6170 char *rightstart, char *rightstop,
6171 const char *truelab, const char *falselab,
6177 if (leftstart != NULL)
6179 struct m68k_op leftop, rightop;
6182 /* Swap the compare operands, if necessary, to produce a legal
6183 m68k compare instruction. Comparing a register operand with
6184 a non-register operand requires the register to be on the
6185 right (cmp, cmpa). Comparing an immediate value with
6186 anything requires the immediate value to be on the left
6191 (void) m68k_ip_op (leftstart, &leftop);
6196 (void) m68k_ip_op (rightstart, &rightop);
6199 if (rightop.mode == IMMED
6200 || ((leftop.mode == DREG || leftop.mode == AREG)
6201 && (rightop.mode != DREG && rightop.mode != AREG)))
6205 /* Correct conditional handling:
6206 if #1 <lt> d0 then ;means if (1 < d0)
6212 cmp #1,d0 if we do *not* swap the operands
6213 bgt true we need the swapped condition!
6220 leftstart = rightstart;
6223 leftstop = rightstop;
6228 cc = swap_mri_condition (cc);
6232 if (truelab == NULL)
6234 cc = reverse_mri_condition (cc);
6238 if (leftstart != NULL)
6240 buf = (char *) xmalloc (20
6241 + (leftstop - leftstart)
6242 + (rightstop - rightstart));
6248 *s++ = TOLOWER (qual);
6250 memcpy (s, leftstart, leftstop - leftstart);
6251 s += leftstop - leftstart;
6253 memcpy (s, rightstart, rightstop - rightstart);
6254 s += rightstop - rightstart;
6260 buf = (char *) xmalloc (20 + strlen (truelab));
6266 *s++ = TOLOWER (extent);
6268 strcpy (s, truelab);
6273 /* Parse an MRI structured control expression. This generates test
6274 and branch instructions. STOP is where the expression ends. It
6275 goes to TRUELAB if the condition is true, and to FALSELAB if the
6276 condition is false. Exactly one of TRUELAB and FALSELAB will be
6277 NULL, meaning to fall through. QUAL is the size qualifier for the
6278 expression. EXTENT is the size to use for the branch. */
6281 parse_mri_control_expression (char *stop, int qual, const char *truelab,
6282 const char *falselab, int extent)
6294 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6295 &rightstart, &rightstop))
6301 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
6305 if (falselab != NULL)
6308 flab = mri_control_label ();
6310 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6311 rightstop, (const char *) NULL, flab, extent);
6313 input_line_pointer += 3;
6314 if (*input_line_pointer != '.'
6315 || input_line_pointer[1] == '\0')
6319 qual = input_line_pointer[1];
6320 input_line_pointer += 2;
6323 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6324 &rightstart, &rightstop))
6330 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6331 rightstop, truelab, falselab, extent);
6333 if (falselab == NULL)
6336 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6340 if (truelab != NULL)
6343 tlab = mri_control_label ();
6345 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6346 rightstop, tlab, (const char *) NULL, extent);
6348 input_line_pointer += 2;
6349 if (*input_line_pointer != '.'
6350 || input_line_pointer[1] == '\0')
6354 qual = input_line_pointer[1];
6355 input_line_pointer += 2;
6358 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6359 &rightstart, &rightstop))
6365 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6366 rightstop, truelab, falselab, extent);
6368 if (truelab == NULL)
6373 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6374 rightstop, truelab, falselab, extent);
6378 if (input_line_pointer != stop)
6379 as_bad (_("syntax error in structured control directive"));
6382 /* Handle the MRI IF pseudo-op. This may be a structured control
6383 directive, or it may be a regular assembler conditional, depending
6391 struct mri_control_info *n;
6393 /* A structured control directive must end with THEN with an
6394 optional qualifier. */
6395 s = input_line_pointer;
6396 /* We only accept '*' as introduction of comments if preceded by white space
6397 or at first column of a line (I think this can't actually happen here?)
6398 This is important when assembling:
6399 if d0 <ne> 12(a0,d0*2) then
6400 if d0 <ne> #CONST*20 then. */
6401 while (! (is_end_of_line[(unsigned char) *s]
6404 && (s == input_line_pointer
6406 || *(s-1) == '\t'))))
6409 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6412 if (s - input_line_pointer > 1
6416 if (s - input_line_pointer < 3
6417 || strncasecmp (s - 3, "THEN", 4) != 0)
6421 as_bad (_("missing then"));
6422 ignore_rest_of_line ();
6426 /* It's a conditional. */
6431 /* Since this might be a conditional if, this pseudo-op will be
6432 called even if we are supported to be ignoring input. Double
6433 check now. Clobber *input_line_pointer so that ignore_input
6434 thinks that this is not a special pseudo-op. */
6435 c = *input_line_pointer;
6436 *input_line_pointer = 0;
6437 if (ignore_input ())
6439 *input_line_pointer = c;
6440 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6441 ++input_line_pointer;
6442 demand_empty_rest_of_line ();
6445 *input_line_pointer = c;
6447 n = push_mri_control (mri_if);
6449 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6450 n->next, s[1] == '.' ? s[2] : '\0');
6453 input_line_pointer = s + 3;
6455 input_line_pointer = s + 1;
6459 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6460 ++input_line_pointer;
6463 demand_empty_rest_of_line ();
6466 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6467 structured IF, associate the ELSE with the IF. Otherwise, assume
6468 it is a conditional else. */
6471 s_mri_else (int qual)
6478 && (mri_control_stack == NULL
6479 || mri_control_stack->type != mri_if
6480 || mri_control_stack->else_seen))
6486 c = *input_line_pointer;
6487 *input_line_pointer = 0;
6488 if (ignore_input ())
6490 *input_line_pointer = c;
6491 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6492 ++input_line_pointer;
6493 demand_empty_rest_of_line ();
6496 *input_line_pointer = c;
6498 if (mri_control_stack == NULL
6499 || mri_control_stack->type != mri_if
6500 || mri_control_stack->else_seen)
6502 as_bad (_("else without matching if"));
6503 ignore_rest_of_line ();
6507 mri_control_stack->else_seen = 1;
6509 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6510 q[0] = TOLOWER (qual);
6512 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6516 colon (mri_control_stack->next);
6520 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6521 ++input_line_pointer;
6524 demand_empty_rest_of_line ();
6527 /* Handle the MRI ENDI pseudo-op. */
6530 s_mri_endi (int ignore ATTRIBUTE_UNUSED)
6532 if (mri_control_stack == NULL
6533 || mri_control_stack->type != mri_if)
6535 as_bad (_("endi without matching if"));
6536 ignore_rest_of_line ();
6540 /* ignore_input will not return true for ENDI, so we don't need to
6541 worry about checking it again here. */
6543 if (! mri_control_stack->else_seen)
6544 colon (mri_control_stack->next);
6545 colon (mri_control_stack->bottom);
6551 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6552 ++input_line_pointer;
6555 demand_empty_rest_of_line ();
6558 /* Handle the MRI BREAK pseudo-op. */
6561 s_mri_break (int extent)
6563 struct mri_control_info *n;
6567 n = mri_control_stack;
6569 && n->type != mri_for
6570 && n->type != mri_repeat
6571 && n->type != mri_while)
6575 as_bad (_("break outside of structured loop"));
6576 ignore_rest_of_line ();
6580 buf = (char *) xmalloc (20 + strlen (n->bottom));
6581 ex[0] = TOLOWER (extent);
6583 sprintf (buf, "bra%s %s", ex, n->bottom);
6589 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6590 ++input_line_pointer;
6593 demand_empty_rest_of_line ();
6596 /* Handle the MRI NEXT pseudo-op. */
6599 s_mri_next (int extent)
6601 struct mri_control_info *n;
6605 n = mri_control_stack;
6607 && n->type != mri_for
6608 && n->type != mri_repeat
6609 && n->type != mri_while)
6613 as_bad (_("next outside of structured loop"));
6614 ignore_rest_of_line ();
6618 buf = (char *) xmalloc (20 + strlen (n->next));
6619 ex[0] = TOLOWER (extent);
6621 sprintf (buf, "bra%s %s", ex, n->next);
6627 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6628 ++input_line_pointer;
6631 demand_empty_rest_of_line ();
6634 /* Handle the MRI FOR pseudo-op. */
6637 s_mri_for (int qual)
6639 const char *varstart, *varstop;
6640 const char *initstart, *initstop;
6641 const char *endstart, *endstop;
6642 const char *bystart, *bystop;
6646 struct mri_control_info *n;
6652 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6656 varstart = input_line_pointer;
6658 /* Look for the '='. */
6659 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6660 && *input_line_pointer != '=')
6661 ++input_line_pointer;
6662 if (*input_line_pointer != '=')
6664 as_bad (_("missing ="));
6665 ignore_rest_of_line ();
6669 varstop = input_line_pointer;
6670 if (varstop > varstart
6671 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6674 ++input_line_pointer;
6676 initstart = input_line_pointer;
6678 /* Look for TO or DOWNTO. */
6681 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6683 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6684 && ! is_part_of_name (input_line_pointer[2]))
6686 initstop = input_line_pointer;
6687 input_line_pointer += 2;
6690 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6691 && ! is_part_of_name (input_line_pointer[6]))
6693 initstop = input_line_pointer;
6695 input_line_pointer += 6;
6698 ++input_line_pointer;
6700 if (initstop == NULL)
6702 as_bad (_("missing to or downto"));
6703 ignore_rest_of_line ();
6706 if (initstop > initstart
6707 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6711 endstart = input_line_pointer;
6713 /* Look for BY or DO. */
6716 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6718 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6719 && ! is_part_of_name (input_line_pointer[2]))
6721 endstop = input_line_pointer;
6723 input_line_pointer += 2;
6726 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6727 && (input_line_pointer[2] == '.'
6728 || ! is_part_of_name (input_line_pointer[2])))
6730 endstop = input_line_pointer;
6731 input_line_pointer += 2;
6734 ++input_line_pointer;
6736 if (endstop == NULL)
6738 as_bad (_("missing do"));
6739 ignore_rest_of_line ();
6742 if (endstop > endstart
6743 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6749 bystop = bystart + 2;
6754 bystart = input_line_pointer;
6758 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6760 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6761 && (input_line_pointer[2] == '.'
6762 || ! is_part_of_name (input_line_pointer[2])))
6764 bystop = input_line_pointer;
6765 input_line_pointer += 2;
6768 ++input_line_pointer;
6772 as_bad (_("missing do"));
6773 ignore_rest_of_line ();
6776 if (bystop > bystart
6777 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6781 if (*input_line_pointer != '.')
6785 extent = input_line_pointer[1];
6786 input_line_pointer += 2;
6789 /* We have fully parsed the FOR operands. Now build the loop. */
6790 n = push_mri_control (mri_for);
6792 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6794 /* Move init,var. */
6801 *s++ = TOLOWER (qual);
6803 memcpy (s, initstart, initstop - initstart);
6804 s += initstop - initstart;
6806 memcpy (s, varstart, varstop - varstart);
6807 s += varstop - varstart;
6819 *s++ = TOLOWER (qual);
6821 memcpy (s, endstart, endstop - endstart);
6822 s += endstop - endstart;
6824 memcpy (s, varstart, varstop - varstart);
6825 s += varstop - varstart;
6830 ex[0] = TOLOWER (extent);
6833 sprintf (buf, "blt%s %s", ex, n->bottom);
6835 sprintf (buf, "bgt%s %s", ex, n->bottom);
6838 /* Put together the add or sub instruction used by ENDF. */
6846 *s++ = TOLOWER (qual);
6848 memcpy (s, bystart, bystop - bystart);
6849 s += bystop - bystart;
6851 memcpy (s, varstart, varstop - varstart);
6852 s += varstop - varstart;
6858 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6859 ++input_line_pointer;
6862 demand_empty_rest_of_line ();
6865 /* Handle the MRI ENDF pseudo-op. */
6868 s_mri_endf (int ignore ATTRIBUTE_UNUSED)
6870 if (mri_control_stack == NULL
6871 || mri_control_stack->type != mri_for)
6873 as_bad (_("endf without for"));
6874 ignore_rest_of_line ();
6878 colon (mri_control_stack->next);
6880 mri_assemble (mri_control_stack->incr);
6882 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6883 mri_assemble (mri_control_stack->incr);
6885 free (mri_control_stack->incr);
6887 colon (mri_control_stack->bottom);
6893 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6894 ++input_line_pointer;
6897 demand_empty_rest_of_line ();
6900 /* Handle the MRI REPEAT pseudo-op. */
6903 s_mri_repeat (int ignore ATTRIBUTE_UNUSED)
6905 struct mri_control_info *n;
6907 n = push_mri_control (mri_repeat);
6911 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6912 ++input_line_pointer;
6914 demand_empty_rest_of_line ();
6917 /* Handle the MRI UNTIL pseudo-op. */
6920 s_mri_until (int qual)
6924 if (mri_control_stack == NULL
6925 || mri_control_stack->type != mri_repeat)
6927 as_bad (_("until without repeat"));
6928 ignore_rest_of_line ();
6932 colon (mri_control_stack->next);
6934 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6937 parse_mri_control_expression (s, qual, (const char *) NULL,
6938 mri_control_stack->top, '\0');
6940 colon (mri_control_stack->bottom);
6942 input_line_pointer = s;
6948 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6949 ++input_line_pointer;
6952 demand_empty_rest_of_line ();
6955 /* Handle the MRI WHILE pseudo-op. */
6958 s_mri_while (int qual)
6962 struct mri_control_info *n;
6964 s = input_line_pointer;
6965 /* We only accept '*' as introduction of comments if preceded by white space
6966 or at first column of a line (I think this can't actually happen here?)
6967 This is important when assembling:
6968 while d0 <ne> 12(a0,d0*2) do
6969 while d0 <ne> #CONST*20 do. */
6970 while (! (is_end_of_line[(unsigned char) *s]
6973 && (s == input_line_pointer
6975 || *(s-1) == '\t'))))
6978 while (*s == ' ' || *s == '\t')
6980 if (s - input_line_pointer > 1
6983 if (s - input_line_pointer < 2
6984 || strncasecmp (s - 1, "DO", 2) != 0)
6986 as_bad (_("missing do"));
6987 ignore_rest_of_line ();
6991 n = push_mri_control (mri_while);
6995 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6996 s[1] == '.' ? s[2] : '\0');
6998 input_line_pointer = s + 1;
6999 if (*input_line_pointer == '.')
7000 input_line_pointer += 2;
7004 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7005 ++input_line_pointer;
7008 demand_empty_rest_of_line ();
7011 /* Handle the MRI ENDW pseudo-op. */
7014 s_mri_endw (int ignore ATTRIBUTE_UNUSED)
7018 if (mri_control_stack == NULL
7019 || mri_control_stack->type != mri_while)
7021 as_bad (_("endw without while"));
7022 ignore_rest_of_line ();
7026 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
7027 sprintf (buf, "bra %s", mri_control_stack->next);
7031 colon (mri_control_stack->bottom);
7037 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7038 ++input_line_pointer;
7041 demand_empty_rest_of_line ();
7044 /* Parse a .cpu directive. */
7047 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED)
7054 as_bad (_("already assembled instructions"));
7055 ignore_rest_of_line ();
7059 name = input_line_pointer;
7060 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
7061 input_line_pointer++;
7062 saved_char = *input_line_pointer;
7063 *input_line_pointer = 0;
7065 m68k_set_cpu (name, 1, 0);
7067 *input_line_pointer = saved_char;
7068 demand_empty_rest_of_line ();
7072 /* Parse a .arch directive. */
7075 s_m68k_arch (int ignored ATTRIBUTE_UNUSED)
7082 as_bad (_("already assembled instructions"));
7083 ignore_rest_of_line ();
7087 name = input_line_pointer;
7088 while (*input_line_pointer && *input_line_pointer != ','
7089 && !ISSPACE (*input_line_pointer))
7090 input_line_pointer++;
7091 saved_char = *input_line_pointer;
7092 *input_line_pointer = 0;
7094 if (m68k_set_arch (name, 1, 0))
7096 /* Scan extensions. */
7099 *input_line_pointer++ = saved_char;
7100 if (!*input_line_pointer || ISSPACE (*input_line_pointer))
7102 name = input_line_pointer;
7103 while (*input_line_pointer && *input_line_pointer != ','
7104 && !ISSPACE (*input_line_pointer))
7105 input_line_pointer++;
7106 saved_char = *input_line_pointer;
7107 *input_line_pointer = 0;
7109 while (m68k_set_extension (name, 1, 0));
7112 *input_line_pointer = saved_char;
7113 demand_empty_rest_of_line ();
7117 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
7118 if none is found, the caller is responsible for emitting an error
7119 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
7120 cpu name, if it begins with a '6' (possibly skipping an intervening
7121 'c'. We also allow a 'c' in the same place. if NEGATED is
7122 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
7123 the option is indeed negated. */
7125 static const struct m68k_cpu *
7126 m68k_lookup_cpu (const char *arg, const struct m68k_cpu *table,
7127 int allow_m, int *negated)
7129 /* allow negated value? */
7134 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
7141 /* Remove 'm' or 'mc' prefix from 68k variants. */
7148 else if (arg[1] == 'c' && arg[2] == '6')
7152 else if (arg[0] == 'c' && arg[1] == '6')
7155 for (; table->name; table++)
7156 if (!strcmp (arg, table->name))
7158 if (table->alias < -1 || table->alias > 1)
7159 as_bad (_("`%s' is deprecated, use `%s'"),
7160 table->name, table[table->alias < 0 ? 1 : -1].name);
7166 /* Set the cpu, issuing errors if it is unrecognized, or invalid */
7169 m68k_set_cpu (char const *name, int allow_m, int silent)
7171 const struct m68k_cpu *cpu;
7173 cpu = m68k_lookup_cpu (name, m68k_cpus, allow_m, NULL);
7178 as_bad (_("cpu `%s' unrecognized"), name);
7182 if (selected_cpu && selected_cpu != cpu)
7184 as_bad (_("already selected `%s' processor"),
7185 selected_cpu->name);
7192 /* Set the architecture, issuing errors if it is unrecognized, or invalid */
7195 m68k_set_arch (char const *name, int allow_m, int silent)
7197 const struct m68k_cpu *arch;
7199 arch = m68k_lookup_cpu (name, m68k_archs, allow_m, NULL);
7204 as_bad (_("architecture `%s' unrecognized"), name);
7208 if (selected_arch && selected_arch != arch)
7210 as_bad (_("already selected `%s' architecture"),
7211 selected_arch->name);
7215 selected_arch = arch;
7219 /* Set the architecture extension, issuing errors if it is
7220 unrecognized, or invalid */
7223 m68k_set_extension (char const *name, int allow_m, int silent)
7226 const struct m68k_cpu *ext;
7228 ext = m68k_lookup_cpu (name, m68k_extensions, allow_m, &negated);
7233 as_bad (_("extension `%s' unrecognized"), name);
7238 not_current_architecture |= ext->arch;
7240 current_architecture |= ext->arch;
7245 Invocation line includes a switch not recognized by the base assembler.
7249 const char *md_shortopts = "lSA:m:kQ:V";
7251 const char *md_shortopts = "lSA:m:k";
7254 struct option md_longopts[] = {
7255 #define OPTION_PIC (OPTION_MD_BASE)
7256 {"pic", no_argument, NULL, OPTION_PIC},
7257 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7258 {"register-prefix-optional", no_argument, NULL,
7259 OPTION_REGISTER_PREFIX_OPTIONAL},
7260 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7261 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
7262 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7263 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
7264 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7265 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
7266 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7267 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
7268 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7269 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
7270 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7271 {"pcrel", no_argument, NULL, OPTION_PCREL},
7272 {NULL, no_argument, NULL, 0}
7274 size_t md_longopts_size = sizeof (md_longopts);
7277 md_parse_option (int c, char *arg)
7281 case 'l': /* -l means keep external to 2 bit offset
7282 rather than 16 bit one. */
7283 flag_short_refs = 1;
7286 case 'S': /* -S means that jbsr's always turn into
7288 flag_long_jumps = 1;
7291 case OPTION_PCREL: /* --pcrel means never turn PC-relative
7292 branches into absolute jumps. */
7293 flag_keep_pcrel = 1;
7299 break; /* -pic, Position Independent Code. */
7301 case OPTION_REGISTER_PREFIX_OPTIONAL:
7302 flag_reg_prefix_optional = 1;
7303 reg_prefix_optional_seen = 1;
7306 /* -V: SVR4 argument to print version ID. */
7308 print_version_id ();
7311 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7312 should be emitted or not. FIXME: Not implemented. */
7316 case OPTION_BITWISE_OR:
7321 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
7323 for (s = m68k_comment_chars; *s != '\0'; s++)
7327 m68k_comment_chars = n;
7331 case OPTION_BASE_SIZE_DEFAULT_16:
7332 m68k_index_width_default = SIZE_WORD;
7335 case OPTION_BASE_SIZE_DEFAULT_32:
7336 m68k_index_width_default = SIZE_LONG;
7339 case OPTION_DISP_SIZE_DEFAULT_16:
7341 m68k_rel32_from_cmdline = 1;
7344 case OPTION_DISP_SIZE_DEFAULT_32:
7346 m68k_rel32_from_cmdline = 1;
7351 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7354 /* Intentional fall-through. */
7356 if (!strncmp (arg, "arch=", 5))
7357 m68k_set_arch (arg + 5, 1, 0);
7358 else if (!strncmp (arg, "cpu=", 4))
7359 m68k_set_cpu (arg + 4, 1, 0);
7360 else if (m68k_set_extension (arg, 0, 1))
7362 else if (m68k_set_arch (arg, 0, 1))
7364 else if (m68k_set_cpu (arg, 0, 1))
7377 /* Setup tables from the selected arch and/or cpu */
7380 m68k_init_arch (void)
7382 if (not_current_architecture & current_architecture)
7384 as_bad (_("architecture features both enabled and disabled"));
7385 not_current_architecture &= ~current_architecture;
7389 current_architecture |= selected_arch->arch;
7390 control_regs = selected_arch->control_regs;
7393 current_architecture |= selected_cpu->arch;
7395 current_architecture &= ~not_current_architecture;
7397 if ((current_architecture & (cfloat | m68881)) == (cfloat | m68881))
7399 /* Determine which float is really meant. */
7400 if (current_architecture & (m68k_mask & ~m68881))
7401 current_architecture ^= cfloat;
7403 current_architecture ^= m68881;
7408 control_regs = selected_cpu->control_regs;
7409 if (current_architecture & ~selected_cpu->arch)
7411 as_bad (_("selected processor does not have all features of selected architecture"));
7412 current_architecture
7413 = selected_cpu->arch & ~not_current_architecture;
7417 if ((current_architecture & m68k_mask)
7418 && (current_architecture & ~m68k_mask))
7420 as_bad (_ ("m68k and cf features both selected"));
7421 if (current_architecture & m68k_mask)
7422 current_architecture &= m68k_mask;
7424 current_architecture &= ~m68k_mask;
7427 /* Permit m68881 specification with all cpus; those that can't work
7428 with a coprocessor could be doing emulation. */
7429 if (current_architecture & m68851)
7431 if (current_architecture & m68040)
7432 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7434 /* What other incompatibilities could we check for? */
7436 if (cpu_of_arch (current_architecture) < m68020
7437 || arch_coldfire_p (current_architecture))
7438 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
7444 md_show_usage (FILE *stream)
7446 const char *default_cpu = TARGET_CPU;
7448 unsigned int default_arch;
7450 /* Get the canonical name for the default target CPU. */
7451 if (*default_cpu == 'm')
7453 for (i = 0; m68k_cpus[i].name; i++)
7455 if (strcasecmp (default_cpu, m68k_cpus[i].name) == 0)
7457 default_arch = m68k_cpus[i].arch;
7458 while (m68k_cpus[i].alias > 0)
7460 while (m68k_cpus[i].alias < 0)
7462 default_cpu = m68k_cpus[i].name;
7466 fprintf (stream, _("\
7467 -march=<arch> set architecture\n\
7468 -mcpu=<cpu> set cpu [default %s]\n\
7470 for (i = 0; m68k_extensions[i].name; i++)
7471 fprintf (stream, _("\
7472 -m[no-]%-16s enable/disable%s architecture extension\n\
7473 "), m68k_extensions[i].name,
7474 m68k_extensions[i].alias > 0 ? " ColdFire"
7475 : m68k_extensions[i].alias < 0 ? " m68k" : "");
7477 fprintf (stream, _("\
7478 -l use 1 word for refs to undefined symbols [default 2]\n\
7479 -pic, -k generate position independent code\n\
7480 -S turn jbsr into jsr\n\
7481 --pcrel never turn PC-relative branches into absolute jumps\n\
7482 --register-prefix-optional\n\
7483 recognize register names without prefix character\n\
7484 --bitwise-or do not treat `|' as a comment character\n\
7485 --base-size-default-16 base reg without size is 16 bits\n\
7486 --base-size-default-32 base reg without size is 32 bits (default)\n\
7487 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7488 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7491 fprintf (stream, _("Architecture variants are: "));
7492 for (i = 0; m68k_archs[i].name; i++)
7495 fprintf (stream, " | ");
7496 fprintf (stream, m68k_archs[i].name);
7498 fprintf (stream, "\n");
7500 fprintf (stream, _("Processor variants are: "));
7501 for (i = 0; m68k_cpus[i].name; i++)
7504 fprintf (stream, " | ");
7505 fprintf (stream, m68k_cpus[i].name);
7507 fprintf (stream, _("\n"));
7512 /* TEST2: Test md_assemble() */
7513 /* Warning, this routine probably doesn't work anymore. */
7517 struct m68k_it the_ins;
7525 if (!gets (buf) || !*buf)
7527 if (buf[0] == '|' || buf[1] == '.')
7529 for (cp = buf; *cp; cp++)
7534 memset (&the_ins, '\0', sizeof (the_ins));
7535 m68k_ip (&the_ins, buf);
7538 printf (_("Error %s in %s\n"), the_ins.error, buf);
7542 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7543 for (n = 0; n < the_ins.numo; n++)
7544 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7546 print_the_insn (&the_ins.opcode[0], stdout);
7547 (void) putchar ('\n');
7549 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7551 if (the_ins.operands[n].error)
7553 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7556 printf ("mode %d, reg %d, ", the_ins.operands[n].mode,
7557 the_ins.operands[n].reg);
7558 if (the_ins.operands[n].b_const)
7559 printf ("Constant: '%.*s', ",
7560 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const,
7561 the_ins.operands[n].b_const);
7562 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg,
7563 the_ins.operands[n].isiz, the_ins.operands[n].imul);
7564 if (the_ins.operands[n].b_iadd)
7565 printf ("Iadd: '%.*s',",
7566 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd,
7567 the_ins.operands[n].b_iadd);
7576 is_label (char *str)
7580 while (*str && *str != ' ')
7582 if (str[-1] == ':' || str[1] == '=')
7589 /* Possible states for relaxation:
7591 0 0 branch offset byte (bra, etc)
7595 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7599 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7606 /* We have no need to default values of symbols. */
7609 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
7614 /* Round up a section size to the appropriate boundary. */
7616 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
7619 /* For a.out, force the section size to be aligned. If we don't do
7620 this, BFD will align it for us, but it will not write out the
7621 final bytes of the section. This may be a bug in BFD, but it is
7622 easier to fix it here since that is how the other a.out targets
7626 align = bfd_get_section_alignment (stdoutput, segment);
7627 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7633 /* Exactly what point is a PC-relative offset relative TO?
7634 On the 68k, it is relative to the address of the first extension
7635 word. The difference between the addresses of the offset and the
7636 first extension word is stored in fx_pcrel_adjust. */
7638 md_pcrel_from (fixS *fixP)
7642 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7643 sign extend the value here. */
7644 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7647 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7652 m68k_elf_final_processing (void)
7656 if (arch_coldfire_fpu (current_architecture))
7657 flags |= EF_M68K_CFV4E;
7658 /* Set file-specific flags if this is a cpu32 processor. */
7659 if (cpu_of_arch (current_architecture) & cpu32)
7660 flags |= EF_M68K_CPU32;
7661 else if (cpu_of_arch (current_architecture) & fido_a)
7662 flags |= EF_M68K_FIDO;
7663 else if ((cpu_of_arch (current_architecture) & m68000up)
7664 && !(cpu_of_arch (current_architecture) & m68020up))
7665 flags |= EF_M68K_M68000;
7667 if (current_architecture & mcfisa_a)
7669 static const unsigned isa_features[][2] =
7671 {EF_M68K_CF_ISA_A_NODIV,mcfisa_a},
7672 {EF_M68K_CF_ISA_A, mcfisa_a|mcfhwdiv},
7673 {EF_M68K_CF_ISA_A_PLUS, mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp},
7674 {EF_M68K_CF_ISA_B_NOUSP,mcfisa_a|mcfisa_b|mcfhwdiv},
7675 {EF_M68K_CF_ISA_B, mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp},
7676 {EF_M68K_CF_ISA_C, mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp},
7679 static const unsigned mac_features[][2] =
7681 {EF_M68K_CF_MAC, mcfmac},
7682 {EF_M68K_CF_EMAC, mcfemac},
7688 pattern = (current_architecture
7689 & (mcfisa_a|mcfisa_aa|mcfisa_b|mcfisa_c|mcfhwdiv|mcfusp));
7690 for (ix = 0; isa_features[ix][1]; ix++)
7692 if (pattern == isa_features[ix][1])
7694 flags |= isa_features[ix][0];
7698 if (!isa_features[ix][1])
7701 as_warn (_("Not a defined coldfire architecture"));
7705 if (current_architecture & cfloat)
7706 flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
7708 pattern = current_architecture & (mcfmac|mcfemac);
7711 for (ix = 0; mac_features[ix][1]; ix++)
7713 if (pattern == mac_features[ix][1])
7715 flags |= mac_features[ix][0];
7719 if (!mac_features[ix][1])
7724 elf_elfheader (stdoutput)->e_flags |= flags;
7729 tc_m68k_regname_to_dw2regnum (char *regname)
7731 unsigned int regnum;
7732 static const char *const regnames[] =
7734 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7735 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7736 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7740 for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
7741 if (strcmp (regname, regnames[regnum]) == 0)
7748 tc_m68k_frame_initial_instructions (void)
7750 static int sp_regno = -1;
7753 sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
7755 cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
7756 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);