1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "safe-ctype.h"
26 #include "dwarf2dbg.h"
27 #include "dw2gencfi.h"
29 #include "opcode/m68k.h"
30 #include "m68k-parse.h"
40 /* This string holds the chars that always start a comment. If the
41 pre-processor is disabled, these aren't very useful. The macro
42 tc_comment_chars points to this. We use this, rather than the
43 usual comment_chars, so that the --bitwise-or option will work. */
44 #if defined (TE_SVR4) || defined (TE_DELTA)
45 const char *m68k_comment_chars = "|#";
47 const char *m68k_comment_chars = "|";
50 /* This array holds the chars that only start a comment at the beginning of
51 a line. If the line seems to have the form '# 123 filename'
52 .line and .file directives will appear in the pre-processed output */
53 /* Note that input_file.c hand checks for '#' at the beginning of the
54 first line of the input file. This is because the compiler outputs
55 #NO_APP at the beginning of its output. */
56 /* Also note that comments like this one will always work. */
57 const char line_comment_chars[] = "#*";
59 const char line_separator_chars[] = ";";
61 /* Chars that can be used to separate mant from exp in floating point nums. */
62 const char EXP_CHARS[] = "eE";
64 /* Chars that mean this number is a floating point constant, as
65 in "0f12.456" or "0d1.2345e12". */
67 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
69 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
70 changed in read.c . Ideally it shouldn't have to know about it at all,
71 but nothing is ideal around here. */
73 /* Are we trying to generate PIC code? If so, absolute references
74 ought to be made into linkage table references or pc-relative
75 references. Not implemented. For ELF there are other means
76 to denote pic relocations. */
79 static int flag_short_refs; /* -l option. */
80 static int flag_long_jumps; /* -S option. */
81 static int flag_keep_pcrel; /* --pcrel option. */
83 #ifdef REGISTER_PREFIX_OPTIONAL
84 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
86 int flag_reg_prefix_optional;
89 /* Whether --register-prefix-optional was used on the command line. */
90 static int reg_prefix_optional_seen;
92 /* The floating point coprocessor to use by default. */
93 static enum m68k_register m68k_float_copnum = COP1;
95 /* If this is non-zero, then references to number(%pc) will be taken
96 to refer to number, rather than to %pc + number. */
97 static int m68k_abspcadd;
99 /* If this is non-zero, then the quick forms of the move, add, and sub
100 instructions are used when possible. */
101 static int m68k_quick = 1;
103 /* If this is non-zero, then if the size is not specified for a base
104 or outer displacement, the assembler assumes that the size should
106 static int m68k_rel32 = 1;
108 /* This is non-zero if m68k_rel32 was set from the command line. */
109 static int m68k_rel32_from_cmdline;
111 /* The default width to use for an index register when using a base
113 static enum m68k_size m68k_index_width_default = SIZE_LONG;
115 /* We want to warn if any text labels are misaligned. In order to get
116 the right line number, we need to record the line number for each
120 struct label_line *next;
127 /* The list of labels. */
129 static struct label_line *labels;
131 /* The current label. */
133 static struct label_line *current_label;
135 /* Pointer to list holding the opcodes sorted by name. */
136 static struct m68k_opcode const ** m68k_sorted_opcodes;
138 /* Its an arbitrary name: This means I don't approve of it.
140 static struct obstack robyn;
144 const char *m_operands;
145 unsigned long m_opcode;
149 struct m68k_incant *m_next;
152 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
153 #define gettwo(x) (((x)->m_opcode)&0xffff)
155 static const enum m68k_register m68000_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, MBAR,
179 static const enum m68k_register mcf5208_ctrl[] = {
180 CACR, ACR0, ACR1, VBR, RAMBAR1,
183 static const enum m68k_register mcf5213_ctrl[] = {
184 VBR, RAMBAR, FLASHBAR,
187 static const enum m68k_register mcf5216_ctrl[] = {
188 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR,
191 static const enum m68k_register mcf5235_ctrl[] = {
192 VBR, CACR, ACR0, ACR1, RAMBAR,
195 static const enum m68k_register mcf5249_ctrl[] = {
196 VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, MBAR, MBAR2,
199 static const enum m68k_register mcf5250_ctrl[] = {
203 static const enum m68k_register mcf5271_ctrl[] = {
204 VBR, CACR, ACR0, ACR1, RAMBAR,
207 static const enum m68k_register mcf5272_ctrl[] = {
208 VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR, MBAR,
211 static const enum m68k_register mcf5275_ctrl[] = {
212 VBR, CACR, ACR0, ACR1, RAMBAR,
215 static const enum m68k_register mcf5282_ctrl[] = {
216 VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR,
219 static const enum m68k_register mcf5329_ctrl[] = {
220 VBR, CACR, ACR0, ACR1, RAMBAR,
223 static const enum m68k_register mcf5373_ctrl[] = {
224 VBR, CACR, ACR0, ACR1, RAMBAR,
227 static const enum m68k_register mcfv4e_ctrl[] = {
228 CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
229 ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
230 PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
231 PCR3U0, PCR3L0, PCR3U1, PCR3L1,
234 #define cpu32_ctrl m68010_ctrl
236 static const enum m68k_register *control_regs;
238 /* Internal form of a 68020 instruction. */
242 const char *args; /* List of opcode info. */
245 int numo; /* Number of shorts in opcode. */
248 struct m68k_op operands[6];
250 int nexp; /* Number of exprs in use. */
251 struct m68k_exp exprs[4];
253 int nfrag; /* Number of frags we have to produce. */
256 int fragoff; /* Where in the current opcode the frag ends. */
263 int nrel; /* Num of reloc strucs in use. */
270 /* In a pc relative address the difference between the address
271 of the offset and the address that the offset is relative
272 to. This depends on the addressing mode. Basically this
273 is the value to put in the offset field to address the
274 first byte of the offset, without regarding the special
275 significance of some values (in the branch instruction, for
279 /* Whether this expression needs special pic relocation, and if
281 enum pic_relocation pic_reloc;
284 reloc[5]; /* Five is enough??? */
287 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a))
288 #define float_of_arch(x) ((x) & mfloat)
289 #define mmu_of_arch(x) ((x) & mmmu)
290 #define arch_coldfire_p(x) ((x) & mcfisa_a)
291 #define arch_coldfire_fpu(x) ((x) & cfloat)
293 /* Macros for determining if cpu supports a specific addressing mode. */
294 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcfisa_b))
296 static struct m68k_it the_ins; /* The instruction being assembled. */
298 #define op(ex) ((ex)->exp.X_op)
299 #define adds(ex) ((ex)->exp.X_add_symbol)
300 #define subs(ex) ((ex)->exp.X_op_symbol)
301 #define offs(ex) ((ex)->exp.X_add_number)
303 /* Macros for adding things to the m68k_it struct. */
304 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
306 /* Like addword, but goes BEFORE general operands. */
309 insop (int w, const struct m68k_incant *opcode)
312 for (z = the_ins.numo; z > opcode->m_codenum; --z)
313 the_ins.opcode[z] = the_ins.opcode[z - 1];
314 for (z = 0; z < the_ins.nrel; z++)
315 the_ins.reloc[z].n += 2;
316 for (z = 0; z < the_ins.nfrag; z++)
317 the_ins.fragb[z].fragoff++;
318 the_ins.opcode[opcode->m_codenum] = w;
322 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
325 add_fix (int width, struct m68k_exp *exp, int pc_rel, int pc_fix)
327 the_ins.reloc[the_ins.nrel].n = (width == 'B' || width == '3'
328 ? the_ins.numo * 2 - 1
330 ? the_ins.numo * 2 + 1
331 : the_ins.numo * 2));
332 the_ins.reloc[the_ins.nrel].exp = exp->exp;
333 the_ins.reloc[the_ins.nrel].wid = width;
334 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
336 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
338 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
341 /* Cause an extra frag to be generated here, inserting up to 10 bytes
342 (that value is chosen in the frag_var call in md_assemble). TYPE
343 is the subtype of the frag to be generated; its primary type is
344 rs_machine_dependent.
346 The TYPE parameter is also used by md_convert_frag_1 and
347 md_estimate_size_before_relax. The appropriate type of fixup will
348 be emitted by md_convert_frag_1.
350 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
352 add_frag (symbolS *add, offsetT off, int type)
354 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
355 the_ins.fragb[the_ins.nfrag].fadd = add;
356 the_ins.fragb[the_ins.nfrag].foff = off;
357 the_ins.fragb[the_ins.nfrag++].fragty = type;
361 (op (ex) != O_constant && op (ex) != O_big)
363 static char *crack_operand (char *str, struct m68k_op *opP);
364 static int get_num (struct m68k_exp *exp, int ok);
365 static int reverse_16_bits (int in);
366 static int reverse_8_bits (int in);
367 static void install_gen_operand (int mode, int val);
368 static void install_operand (int mode, int val);
369 static void s_bss (int);
370 static void s_data1 (int);
371 static void s_data2 (int);
372 static void s_even (int);
373 static void s_proc (int);
374 static void s_chip (int);
375 static void s_fopt (int);
376 static void s_opt (int);
377 static void s_reg (int);
378 static void s_restore (int);
379 static void s_save (int);
380 static void s_mri_if (int);
381 static void s_mri_else (int);
382 static void s_mri_endi (int);
383 static void s_mri_break (int);
384 static void s_mri_next (int);
385 static void s_mri_for (int);
386 static void s_mri_endf (int);
387 static void s_mri_repeat (int);
388 static void s_mri_until (int);
389 static void s_mri_while (int);
390 static void s_mri_endw (int);
391 static void s_m68k_cpu (int);
392 static void s_m68k_arch (int);
396 unsigned long arch; /* Architecture features. */
397 const enum m68k_register *control_regs; /* Control regs on chip */
398 const char *name; /* Name */
399 int alias; /* Alias for a cannonical name. If 1, then
400 succeeds canonical name, if -1 then
401 succeeds canonical name, if <-1 ||>1 this is a
402 deprecated name, and the next/previous name
406 /* We hold flags for features explicitly enabled and explicitly
408 static int current_architecture;
409 static int not_current_architecture;
410 static const struct m68k_cpu *selected_arch;
411 static const struct m68k_cpu *selected_cpu;
412 static int initialized;
414 /* Architecture models. */
415 static const struct m68k_cpu m68k_archs[] =
417 {m68000, m68000_ctrl, "68000", 0},
418 {m68010, m68010_ctrl, "68010", 0},
419 {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
420 {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
421 {m68040, m68040_ctrl, "68040", 0},
422 {m68060, m68060_ctrl, "68060", 0},
423 {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
424 {mcfisa_a|mcfhwdiv, NULL, "isaa", 0},
425 {mcfisa_a|mcfhwdiv|mcfisa_aa|mcfusp, NULL, "isaaplus", 0},
426 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp, NULL, "isab", 0},
427 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac|mcfusp, mcf_ctrl, "cfv4", 0},
428 {mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "cfv4e", 0},
432 /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
434 static const struct m68k_cpu m68k_extensions[] =
436 {m68851, NULL, "68851", -1},
437 {m68881, NULL, "68881", -1},
438 {m68881, NULL, "68882", -1},
440 {cfloat|m68881, NULL, "float", 0},
442 {mcfhwdiv, NULL, "div", 1},
443 {mcfusp, NULL, "usp", 1},
444 {mcfmac, NULL, "mac", 1},
445 {mcfemac, NULL, "emac", 1},
451 static const struct m68k_cpu m68k_cpus[] =
453 {m68000, m68000_ctrl, "68000", 0},
454 {m68000, m68000_ctrl, "68ec000", 1},
455 {m68000, m68000_ctrl, "68hc000", 1},
456 {m68000, m68000_ctrl, "68hc001", 1},
457 {m68000, m68000_ctrl, "68008", 1},
458 {m68000, m68000_ctrl, "68302", 1},
459 {m68000, m68000_ctrl, "68306", 1},
460 {m68000, m68000_ctrl, "68307", 1},
461 {m68000, m68000_ctrl, "68322", 1},
462 {m68000, m68000_ctrl, "68356", 1},
463 {m68010, m68010_ctrl, "68010", 0},
464 {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
465 {m68020|m68881|m68851, m68020_ctrl, "68k", 1},
466 {m68020|m68881|m68851, m68020_ctrl, "68ec020", 1},
467 {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
468 {m68030|m68881|m68851, m68020_ctrl, "68ec030", 1},
469 {m68040, m68040_ctrl, "68040", 0},
470 {m68040, m68040_ctrl, "68ec040", 1},
471 {m68060, m68060_ctrl, "68060", 0},
472 {m68060, m68060_ctrl, "68ec060", 1},
474 {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
475 {cpu32|m68881, cpu32_ctrl, "68330", 1},
476 {cpu32|m68881, cpu32_ctrl, "68331", 1},
477 {cpu32|m68881, cpu32_ctrl, "68332", 1},
478 {cpu32|m68881, cpu32_ctrl, "68333", 1},
479 {cpu32|m68881, cpu32_ctrl, "68334", 1},
480 {cpu32|m68881, cpu32_ctrl, "68336", 1},
481 {cpu32|m68881, cpu32_ctrl, "68340", 1},
482 {cpu32|m68881, cpu32_ctrl, "68341", 1},
483 {cpu32|m68881, cpu32_ctrl, "68349", 1},
484 {cpu32|m68881, cpu32_ctrl, "68360", 1},
486 {mcfisa_a, mcf_ctrl, "5200", 0},
487 {mcfisa_a, mcf_ctrl, "5202", 1},
488 {mcfisa_a, mcf_ctrl, "5204", 1},
489 {mcfisa_a, mcf_ctrl, "5206", 1},
491 {mcfisa_a|mcfhwdiv|mcfmac, mcf_ctrl, "5206e", 0},
493 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5207", -1},
494 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5208", 0},
496 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5211", -1},
497 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5212", -1},
498 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5213", 0},
500 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5214", -1},
501 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5216", 0},
502 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "521x", 2},
504 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5232", -1},
505 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5233", -1},
506 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5234", -1},
507 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5235", -1},
508 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "523x", 0},
510 {mcfisa_a|mcfhwdiv|mcfemac, mcf5249_ctrl, "5249", 0},
511 {mcfisa_a|mcfhwdiv|mcfemac, mcf5250_ctrl, "5250", 0},
513 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5270", -1},
514 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5271", 0},
516 {mcfisa_a|mcfhwdiv|mcfmac, mcf5272_ctrl, "5272", 0},
518 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5274", -1},
519 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5275", 0},
521 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5280", -1},
522 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5281", -1},
523 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5282", -1},
524 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "528x", 0},
526 {mcfisa_a|mcfhwdiv|mcfmac, mcf_ctrl, "5307", 0},
528 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5327", -1},
529 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5328", -1},
530 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5329", -1},
531 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "532x", 0},
533 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5372", -1},
534 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5373", -1},
535 {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "537x", 0},
537 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfmac, mcf_ctrl, "5407",0},
539 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5470", -1},
540 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5471", -1},
541 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5472", -1},
542 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5473", -1},
543 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5474", -1},
544 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5475", -1},
545 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "547x", 0},
547 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5480", -1},
548 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5481", -1},
549 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5482", -1},
550 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5483", -1},
551 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5484", -1},
552 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "5485", -1},
553 {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "548x", 0},
558 static const struct m68k_cpu *m68k_lookup_cpu
559 (const char *, const struct m68k_cpu *, int, int *);
560 static int m68k_set_arch (const char *, int, int);
561 static int m68k_set_cpu (const char *, int, int);
562 static int m68k_set_extension (const char *, int, int);
563 static void m68k_init_arch (void);
565 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
566 architecture and we have a lot of relaxation modes. */
568 /* Macros used in the relaxation code. */
569 #define TAB(x,y) (((x) << 2) + (y))
570 #define TABTYPE(x) ((x) >> 2)
572 /* Relaxation states. */
578 /* Here are all the relaxation modes we support. First we can relax ordinary
579 branches. On 68020 and higher and on CPU32 all branch instructions take
580 three forms, so on these CPUs all branches always remain as such. When we
581 have to expand to the LONG form on a 68000, though, we substitute an
582 absolute jump instead. This is a direct replacement for unconditional
583 branches and a branch over a jump for conditional branches. However, if the
584 user requires PIC and disables this with --pcrel, we can only relax between
585 BYTE and SHORT forms, punting if that isn't enough. This gives us four
586 different relaxation modes for branches: */
588 #define BRANCHBWL 0 /* Branch byte, word, or long. */
589 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
590 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
591 #define BRANCHBW 3 /* Branch byte or word. */
593 /* We also relax coprocessor branches and DBcc's. All CPUs that support
594 coprocessor branches support them in word and long forms, so we have only
595 one relaxation mode for them. DBcc's are word only on all CPUs. We can
596 relax them to the LONG form with a branch-around sequence. This sequence
597 can use a long branch (if available) or an absolute jump (if acceptable).
598 This gives us two relaxation modes. If long branches are not available and
599 absolute jumps are not acceptable, we don't relax DBcc's. */
601 #define FBRANCH 4 /* Coprocessor branch. */
602 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
603 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
605 /* That's all for instruction relaxation. However, we also relax PC-relative
606 operands. Specifically, we have three operand relaxation modes. On the
607 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
608 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
609 two. Also PC+displacement+index operands in their simple form (with a non-
610 suppressed index without memory indirection) are supported on all CPUs, but
611 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
612 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
613 form of the PC+displacement+index operand. Finally, some absolute operands
614 can be relaxed down to 16-bit PC-relative. */
616 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
617 #define PCINDEX 8 /* PC + displacement + index. */
618 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
620 /* Note that calls to frag_var need to specify the maximum expansion
621 needed; this is currently 10 bytes for DBCC. */
624 How far Forward this mode will reach:
625 How far Backward this mode will reach:
626 How many bytes this mode will add to the size of the frag
627 Which mode to go to if the offset won't fit in this one
629 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
630 relax_typeS md_relax_table[] =
632 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
633 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
637 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
638 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
642 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
643 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
647 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
652 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
653 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
657 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
658 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
662 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
663 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
667 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
668 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
672 { 125, -130, 0, TAB (PCINDEX, SHORT) },
673 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
677 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
678 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
683 /* These are the machine dependent pseudo-ops. These are included so
684 the assembler can work on the output from the SUN C compiler, which
687 /* This table describes all the machine specific pseudo-ops the assembler
688 has to support. The fields are:
689 pseudo-op name without dot
690 function to call to execute this pseudo-op
691 Integer arg to pass to the function. */
692 const pseudo_typeS md_pseudo_table[] =
694 {"data1", s_data1, 0},
695 {"data2", s_data2, 0},
698 {"skip", s_space, 0},
700 #if defined (TE_SUN3) || defined (OBJ_ELF)
701 {"align", s_align_bytes, 0},
704 {"swbeg", s_ignore, 0},
706 {"extend", float_cons, 'x'},
707 {"ldouble", float_cons, 'x'},
709 {"arch", s_m68k_arch, 0},
710 {"cpu", s_m68k_cpu, 0},
712 /* The following pseudo-ops are supported for MRI compatibility. */
714 {"comline", s_space, 1},
716 {"mask2", s_ignore, 0},
719 {"restore", s_restore, 0},
723 {"if.b", s_mri_if, 'b'},
724 {"if.w", s_mri_if, 'w'},
725 {"if.l", s_mri_if, 'l'},
726 {"else", s_mri_else, 0},
727 {"else.s", s_mri_else, 's'},
728 {"else.l", s_mri_else, 'l'},
729 {"endi", s_mri_endi, 0},
730 {"break", s_mri_break, 0},
731 {"break.s", s_mri_break, 's'},
732 {"break.l", s_mri_break, 'l'},
733 {"next", s_mri_next, 0},
734 {"next.s", s_mri_next, 's'},
735 {"next.l", s_mri_next, 'l'},
736 {"for", s_mri_for, 0},
737 {"for.b", s_mri_for, 'b'},
738 {"for.w", s_mri_for, 'w'},
739 {"for.l", s_mri_for, 'l'},
740 {"endf", s_mri_endf, 0},
741 {"repeat", s_mri_repeat, 0},
742 {"until", s_mri_until, 0},
743 {"until.b", s_mri_until, 'b'},
744 {"until.w", s_mri_until, 'w'},
745 {"until.l", s_mri_until, 'l'},
746 {"while", s_mri_while, 0},
747 {"while.b", s_mri_while, 'b'},
748 {"while.w", s_mri_while, 'w'},
749 {"while.l", s_mri_while, 'l'},
750 {"endw", s_mri_endw, 0},
755 /* The mote pseudo ops are put into the opcode table, since they
756 don't start with a . they look like opcodes to gas. */
758 const pseudo_typeS mote_pseudo_table[] =
771 {"xdef", s_globl, 0},
773 {"align", s_align_bytes, 0},
775 {"align", s_align_ptwo, 0},
778 {"sect", obj_coff_section, 0},
779 {"section", obj_coff_section, 0},
784 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
785 gives identical results to a 32-bit host. */
786 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
787 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
789 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
790 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
791 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
792 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
794 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
795 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
796 #define islong(x) (1)
798 static char notend_table[256];
799 static char alt_notend_table[256];
801 (! (notend_table[(unsigned char) *s] \
803 && alt_notend_table[(unsigned char) s[1]])))
807 /* Return zero if the reference to SYMBOL from within the same segment may
810 /* On an ELF system, we can't relax an externally visible symbol,
811 because it may be overridden by a shared library. However, if
812 TARGET_OS is "elf", then we presume that we are assembling for an
813 embedded system, in which case we don't have to worry about shared
814 libraries, and we can relax any external sym. */
816 #define relaxable_symbol(symbol) \
817 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
818 || S_IS_WEAK (symbol)))
820 /* Compute the relocation code for a fixup of SIZE bytes, using pc
821 relative relocation if PCREL is non-zero. PIC says whether a special
822 pic relocation was requested. */
824 static bfd_reloc_code_real_type
825 get_reloc_code (int size, int pcrel, enum pic_relocation pic)
833 return BFD_RELOC_8_GOT_PCREL;
835 return BFD_RELOC_16_GOT_PCREL;
837 return BFD_RELOC_32_GOT_PCREL;
845 return BFD_RELOC_8_GOTOFF;
847 return BFD_RELOC_16_GOTOFF;
849 return BFD_RELOC_32_GOTOFF;
857 return BFD_RELOC_8_PLT_PCREL;
859 return BFD_RELOC_16_PLT_PCREL;
861 return BFD_RELOC_32_PLT_PCREL;
869 return BFD_RELOC_8_PLTOFF;
871 return BFD_RELOC_16_PLTOFF;
873 return BFD_RELOC_32_PLTOFF;
883 return BFD_RELOC_8_PCREL;
885 return BFD_RELOC_16_PCREL;
887 return BFD_RELOC_32_PCREL;
907 as_bad (_("Can not do %d byte pc-relative relocation"), size);
909 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
914 as_bad (_("Can not do %d byte relocation"), size);
916 as_bad (_("Can not do %d byte pic relocation"), size);
919 return BFD_RELOC_NONE;
922 /* Here we decide which fixups can be adjusted to make them relative
923 to the beginning of the section instead of the symbol. Basically
924 we need to make sure that the dynamic relocations are done
925 correctly, so in some cases we force the original symbol to be
928 tc_m68k_fix_adjustable (fixS *fixP)
930 /* Adjust_reloc_syms doesn't know about the GOT. */
931 switch (fixP->fx_r_type)
933 case BFD_RELOC_8_GOT_PCREL:
934 case BFD_RELOC_16_GOT_PCREL:
935 case BFD_RELOC_32_GOT_PCREL:
936 case BFD_RELOC_8_GOTOFF:
937 case BFD_RELOC_16_GOTOFF:
938 case BFD_RELOC_32_GOTOFF:
939 case BFD_RELOC_8_PLT_PCREL:
940 case BFD_RELOC_16_PLT_PCREL:
941 case BFD_RELOC_32_PLT_PCREL:
942 case BFD_RELOC_8_PLTOFF:
943 case BFD_RELOC_16_PLTOFF:
944 case BFD_RELOC_32_PLTOFF:
947 case BFD_RELOC_VTABLE_INHERIT:
948 case BFD_RELOC_VTABLE_ENTRY:
958 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
960 #define relaxable_symbol(symbol) 1
965 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
968 bfd_reloc_code_real_type code;
970 /* If the tcbit is set, then this was a fixup of a negative value
971 that was never resolved. We do not have a reloc to handle this,
972 so just return. We assume that other code will have detected this
973 situation and produced a helpful error message, so we just tell the
974 user that the reloc cannot be produced. */
978 as_bad_where (fixp->fx_file, fixp->fx_line,
979 _("Unable to produce reloc against symbol '%s'"),
980 S_GET_NAME (fixp->fx_addsy));
984 if (fixp->fx_r_type != BFD_RELOC_NONE)
986 code = fixp->fx_r_type;
988 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
989 that fixup_segment converted a non-PC relative reloc into a
990 PC relative reloc. In such a case, we need to convert the
997 code = BFD_RELOC_8_PCREL;
1000 code = BFD_RELOC_16_PCREL;
1003 code = BFD_RELOC_32_PCREL;
1005 case BFD_RELOC_8_PCREL:
1006 case BFD_RELOC_16_PCREL:
1007 case BFD_RELOC_32_PCREL:
1008 case BFD_RELOC_8_GOT_PCREL:
1009 case BFD_RELOC_16_GOT_PCREL:
1010 case BFD_RELOC_32_GOT_PCREL:
1011 case BFD_RELOC_8_GOTOFF:
1012 case BFD_RELOC_16_GOTOFF:
1013 case BFD_RELOC_32_GOTOFF:
1014 case BFD_RELOC_8_PLT_PCREL:
1015 case BFD_RELOC_16_PLT_PCREL:
1016 case BFD_RELOC_32_PLT_PCREL:
1017 case BFD_RELOC_8_PLTOFF:
1018 case BFD_RELOC_16_PLTOFF:
1019 case BFD_RELOC_32_PLTOFF:
1022 as_bad_where (fixp->fx_file, fixp->fx_line,
1023 _("Cannot make %s relocation PC relative"),
1024 bfd_get_reloc_code_name (code));
1030 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1031 switch (F (fixp->fx_size, fixp->fx_pcrel))
1033 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1034 MAP (1, 0, BFD_RELOC_8);
1035 MAP (2, 0, BFD_RELOC_16);
1036 MAP (4, 0, BFD_RELOC_32);
1037 MAP (1, 1, BFD_RELOC_8_PCREL);
1038 MAP (2, 1, BFD_RELOC_16_PCREL);
1039 MAP (4, 1, BFD_RELOC_32_PCREL);
1047 reloc = (arelent *) xmalloc (sizeof (arelent));
1048 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1049 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1050 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1053 reloc->addend = fixp->fx_addnumber;
1057 if (!fixp->fx_pcrel)
1058 reloc->addend = fixp->fx_addnumber;
1060 reloc->addend = (section->vma
1061 /* Explicit sign extension in case char is
1063 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
1064 + fixp->fx_addnumber
1065 + md_pcrel_from (fixp));
1068 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1069 assert (reloc->howto != 0);
1074 /* Handle of the OPCODE hash table. NULL means any use before
1075 m68k_ip_begin() will crash. */
1076 static struct hash_control *op_hash;
1078 /* Assemble an m68k instruction. */
1081 m68k_ip (char *instring)
1084 register struct m68k_op *opP;
1085 register const struct m68k_incant *opcode;
1086 register const char *s;
1087 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1088 char *pdot, *pdotmove;
1089 enum m68k_size siz1, siz2;
1093 struct m68k_op operands_backup[6];
1094 LITTLENUM_TYPE words[6];
1095 LITTLENUM_TYPE *wordp;
1096 unsigned long ok_arch = 0;
1098 if (*instring == ' ')
1099 instring++; /* Skip leading whitespace. */
1101 /* Scan up to end of operation-code, which MUST end in end-of-string
1102 or exactly 1 space. */
1104 for (p = instring; *p != '\0'; p++)
1114 the_ins.error = _("No operator");
1118 /* p now points to the end of the opcode name, probably whitespace.
1119 Make sure the name is null terminated by clobbering the
1120 whitespace, look it up in the hash table, then fix it back.
1121 Remove a dot, first, since the opcode tables have none. */
1124 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1125 *pdotmove = pdotmove[1];
1131 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1136 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1137 *pdotmove = pdotmove[-1];
1144 the_ins.error = _("Unknown operator");
1148 /* Found a legitimate opcode, start matching operands. */
1152 if (opcode->m_operands == 0)
1154 char *old = input_line_pointer;
1156 input_line_pointer = p;
1157 /* Ahh - it's a motorola style psuedo op. */
1158 mote_pseudo_table[opcode->m_opnum].poc_handler
1159 (mote_pseudo_table[opcode->m_opnum].poc_val);
1160 input_line_pointer = old;
1166 if (flag_mri && opcode->m_opnum == 0)
1168 /* In MRI mode, random garbage is allowed after an instruction
1169 which accepts no operands. */
1170 the_ins.args = opcode->m_operands;
1171 the_ins.numargs = opcode->m_opnum;
1172 the_ins.numo = opcode->m_codenum;
1173 the_ins.opcode[0] = getone (opcode);
1174 the_ins.opcode[1] = gettwo (opcode);
1178 for (opP = &the_ins.operands[0]; *p; opP++)
1180 p = crack_operand (p, opP);
1184 the_ins.error = opP->error;
1189 opsfound = opP - &the_ins.operands[0];
1191 /* This ugly hack is to support the floating pt opcodes in their
1192 standard form. Essentially, we fake a first enty of type COP#1 */
1193 if (opcode->m_operands[0] == 'I')
1197 for (n = opsfound; n > 0; --n)
1198 the_ins.operands[n] = the_ins.operands[n - 1];
1200 memset (&the_ins.operands[0], '\0', sizeof (the_ins.operands[0]));
1201 the_ins.operands[0].mode = CONTROL;
1202 the_ins.operands[0].reg = m68k_float_copnum;
1206 /* We've got the operands. Find an opcode that'll accept them. */
1209 /* If we didn't get the right number of ops, or we have no
1210 common model with this pattern then reject this pattern. */
1212 ok_arch |= opcode->m_arch;
1213 if (opsfound != opcode->m_opnum
1214 || ((opcode->m_arch & current_architecture) == 0))
1220 /* Make a copy of the operands of this insn so that
1221 we can modify them safely, should we want to. */
1222 assert (opsfound <= (int) ARRAY_SIZE (operands_backup));
1223 for (i = 0; i < opsfound; i++)
1224 operands_backup[i] = the_ins.operands[i];
1226 for (s = opcode->m_operands, opP = &operands_backup[0];
1230 /* Warning: this switch is huge! */
1231 /* I've tried to organize the cases into this order:
1232 non-alpha first, then alpha by letter. Lower-case
1233 goes directly before uppercase counterpart. */
1234 /* Code with multiple case ...: gets sorted by the lowest
1235 case ... it belongs to. I hope this makes sense. */
1341 if (opP->reg == PC || opP->reg == ZPC)
1358 if (opP->reg == PC || opP->reg == ZPC)
1377 if (opP->reg == PC || opP->reg == ZPC)
1387 if (opP->mode != IMMED)
1389 else if (s[1] == 'b'
1390 && ! isvar (&opP->disp)
1391 && (opP->disp.exp.X_op != O_constant
1392 || ! isbyte (opP->disp.exp.X_add_number)))
1394 else if (s[1] == 'B'
1395 && ! isvar (&opP->disp)
1396 && (opP->disp.exp.X_op != O_constant
1397 || ! issbyte (opP->disp.exp.X_add_number)))
1399 else if (s[1] == 'w'
1400 && ! isvar (&opP->disp)
1401 && (opP->disp.exp.X_op != O_constant
1402 || ! isword (opP->disp.exp.X_add_number)))
1404 else if (s[1] == 'W'
1405 && ! isvar (&opP->disp)
1406 && (opP->disp.exp.X_op != O_constant
1407 || ! issword (opP->disp.exp.X_add_number)))
1413 if (opP->mode != IMMED)
1418 if (opP->mode == AREG
1419 || opP->mode == CONTROL
1420 || opP->mode == FPREG
1421 || opP->mode == IMMED
1422 || opP->mode == REGLST
1423 || (opP->mode != ABSL
1425 || opP->reg == ZPC)))
1430 if (opP->mode == CONTROL
1431 || opP->mode == FPREG
1432 || opP->mode == REGLST
1433 || opP->mode == IMMED
1434 || (opP->mode != ABSL
1436 || opP->reg == ZPC)))
1464 if (opP->mode == CONTROL
1465 || opP->mode == FPREG
1466 || opP->mode == REGLST)
1471 if (opP->mode != AINC)
1476 if (opP->mode != ADEC)
1526 if (opP->reg == PC || opP->reg == ZPC)
1547 case '~': /* For now! (JF FOO is this right?) */
1569 if (opP->mode != CONTROL
1570 || (opP->reg != TT0 && opP->reg != TT1))
1575 if (opP->mode != AREG)
1580 if (opP->mode != AINDR)
1585 if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
1586 && (opP->mode != DISP
1588 || opP->reg > ADDR7))
1593 if (opP->mode != ABSL
1595 && strncmp (instring, "jbsr", 4) == 0))
1618 if (opP->mode != CONTROL || opP->reg != CCR)
1623 if (opP->mode != DISP
1625 || opP->reg > ADDR7)
1630 if (opP->mode != DREG)
1635 if (opP->reg != ACC)
1640 if (opP->reg != ACC && opP->reg != ACC1
1641 && opP->reg != ACC2 && opP->reg != ACC3)
1646 if (opP->mode != FPREG)
1651 if (opP->reg != MACSR)
1656 if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
1661 if (opP->reg != MASK)
1666 if (opP->mode != CONTROL
1673 if (opP->mode != LSH && opP->mode != RSH)
1678 if (opP->mode != CONTROL
1680 || opP->reg > last_movec_reg
1685 const enum m68k_register *rp;
1687 for (rp = control_regs; *rp; rp++)
1688 if (*rp == opP->reg)
1696 if (opP->mode != IMMED)
1702 if (opP->mode == DREG
1703 || opP->mode == AREG
1704 || opP->mode == FPREG)
1713 opP->mask = 1 << (opP->reg - DATA0);
1716 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1719 opP->mask = 1 << (opP->reg - FP0 + 16);
1727 else if (opP->mode == CONTROL)
1736 opP->mask = 1 << 24;
1739 opP->mask = 1 << 25;
1742 opP->mask = 1 << 26;
1751 else if (opP->mode != REGLST)
1753 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1755 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1760 if (opP->mode != IMMED)
1762 else if (opP->disp.exp.X_op != O_constant
1763 || ! issbyte (opP->disp.exp.X_add_number))
1765 else if (! m68k_quick
1766 && instring[3] != 'q'
1767 && instring[4] != 'q')
1772 if (opP->mode != DREG
1773 && opP->mode != IMMED
1774 && opP->mode != ABSL)
1779 if (opP->mode != IMMED)
1781 else if (opP->disp.exp.X_op != O_constant
1782 || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
1784 else if (! m68k_quick
1785 && (strncmp (instring, "add", 3) == 0
1786 || strncmp (instring, "sub", 3) == 0)
1787 && instring[3] != 'q')
1792 if (opP->mode != DREG && opP->mode != AREG)
1797 if (opP->mode != AINDR
1798 && (opP->mode != BASE
1800 && opP->reg != ZADDR0)
1801 || opP->disp.exp.X_op != O_absent
1802 || ((opP->index.reg < DATA0
1803 || opP->index.reg > DATA7)
1804 && (opP->index.reg < ADDR0
1805 || opP->index.reg > ADDR7))
1806 || opP->index.size != SIZE_UNSPEC
1807 || opP->index.scale != 1))
1812 if (opP->mode != CONTROL
1813 || ! (opP->reg == FPI
1815 || opP->reg == FPC))
1820 if (opP->mode != CONTROL || opP->reg != SR)
1825 if (opP->mode != IMMED)
1827 else if (opP->disp.exp.X_op != O_constant
1828 || TRUNC (opP->disp.exp.X_add_number) > 7)
1833 if (opP->mode != CONTROL || opP->reg != USP)
1838 if (opP->mode != IMMED)
1840 else if (opP->disp.exp.X_op != O_constant
1841 || (TRUNC (opP->disp.exp.X_add_number) != 0xffffffff
1842 && TRUNC (opP->disp.exp.X_add_number) - 1 > 6))
1846 /* JF these are out of order. We could put them
1847 in order if we were willing to put up with
1848 bunches of #ifdef m68851s in the code.
1850 Don't forget that you need these operands
1851 to use 68030 MMU instructions. */
1853 /* Memory addressing mode used by pflushr. */
1855 if (opP->mode == CONTROL
1856 || opP->mode == FPREG
1857 || opP->mode == DREG
1858 || opP->mode == AREG
1859 || opP->mode == REGLST)
1861 /* We should accept immediate operands, but they
1862 supposedly have to be quad word, and we don't
1863 handle that. I would like to see what a Motorola
1864 assembler does before doing something here. */
1865 if (opP->mode == IMMED)
1870 if (opP->mode != CONTROL
1871 || (opP->reg != SFC && opP->reg != DFC))
1876 if (opP->mode != CONTROL || opP->reg != TC)
1881 if (opP->mode != CONTROL || opP->reg != AC)
1886 if (opP->mode != CONTROL
1889 && opP->reg != SCC))
1894 if (opP->mode != CONTROL
1900 if (opP->mode != CONTROL
1903 && opP->reg != CRP))
1927 if (opP->mode != CONTROL
1928 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1929 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1934 if (opP->mode != CONTROL || opP->reg != PSR)
1939 if (opP->mode != CONTROL || opP->reg != PCSR)
1944 if (opP->mode != CONTROL
1953 if (opP->mode != ABSL)
1958 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1960 /* FIXME: kludge instead of fixing parser:
1961 upper/lower registers are *not* CONTROL
1962 registers, but ordinary ones. */
1963 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1964 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1971 if (!(opP->mode == AINDR
1972 || (opP->mode == DISP
1973 && !(opP->reg == PC || opP->reg == ZPC))))
1978 if (!(opP->mode == AINDR || opP->mode == DISP))
1990 /* Since we have found the correct instruction, copy
1991 in the modifications that we may have made. */
1993 for (i = 0; i < opsfound; i++)
1994 the_ins.operands[i] = operands_backup[i];
2000 opcode = opcode->m_next;
2005 && !(ok_arch & current_architecture))
2007 const struct m68k_cpu *cpu;
2010 char *buf = xmalloc (space + 1);
2014 the_ins.error = buf;
2015 /* Make sure there's a NUL at the end of the buffer -- strncpy
2016 won't write one when it runs out of buffer */
2018 #define APPEND(STRING) \
2019 (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
2021 APPEND (_("invalid instruction for this architecture; needs "));
2025 APPEND (_("ColdFire ISA_A"));
2028 APPEND (_("ColdFire hardware divide"));
2031 APPEND (_("ColdFire ISA_A+"));
2034 APPEND (_("ColdFire ISA_B"));
2037 APPEND (_("ColdFire fpu"));
2040 APPEND (_("M68K fpu"));
2043 APPEND (_("M68K mmu"));
2046 APPEND (_("68020 or higher"));
2049 APPEND (_("68000 or higher"));
2052 APPEND (_("68010 or higher"));
2060 for (cpu = m68k_cpus; cpu->name; cpu++)
2061 if (!cpu->alias && (cpu->arch & ok_arch))
2063 const struct m68k_cpu *alias;
2064 int seen_master = 0;
2070 for (alias = cpu; alias != m68k_cpus; alias--)
2071 if (alias[-1].alias >= 0)
2073 for (; !seen_master || alias->alias > 0; alias++)
2083 APPEND (alias->name);
2096 /* we ran out of space, so replace the end of the list
2101 strcpy (buf, " ...");
2105 the_ins.error = _("operands mismatch");
2112 /* Now assemble it. */
2113 the_ins.args = opcode->m_operands;
2114 the_ins.numargs = opcode->m_opnum;
2115 the_ins.numo = opcode->m_codenum;
2116 the_ins.opcode[0] = getone (opcode);
2117 the_ins.opcode[1] = gettwo (opcode);
2119 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
2121 /* This switch is a doozy.
2122 Watch the first step; its a big one! */
2155 tmpreg = 0x3c; /* 7.4 */
2156 if (strchr ("bwl", s[1]))
2157 nextword = get_num (&opP->disp, 90);
2159 nextword = get_num (&opP->disp, 0);
2160 if (isvar (&opP->disp))
2161 add_fix (s[1], &opP->disp, 0, 0);
2165 if (!isbyte (nextword))
2166 opP->error = _("operand out of range");
2171 if (!isword (nextword))
2172 opP->error = _("operand out of range");
2177 if (!issword (nextword))
2178 opP->error = _("operand out of range");
2183 addword (nextword >> 16);
2210 /* We gotta put out some float. */
2211 if (op (&opP->disp) != O_big)
2216 /* Can other cases happen here? */
2217 if (op (&opP->disp) != O_constant)
2220 val = (valueT) offs (&opP->disp);
2224 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2225 val >>= LITTLENUM_NUMBER_OF_BITS;
2229 offs (&opP->disp) = gencnt;
2231 if (offs (&opP->disp) > 0)
2233 if (offs (&opP->disp) > baseo)
2235 as_warn (_("Bignum too big for %c format; truncated"),
2237 offs (&opP->disp) = baseo;
2239 baseo -= offs (&opP->disp);
2242 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2243 offs (&opP->disp)--;
2248 gen_to_words (words, baseo, (long) outro);
2249 for (wordp = words; baseo--; wordp++)
2253 tmpreg = opP->reg - DATA; /* 0.dreg */
2256 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2259 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2262 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2265 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2269 nextword = get_num (&opP->disp, 90);
2271 /* Convert mode 5 addressing with a zero offset into
2272 mode 2 addressing to reduce the instruction size by a
2274 if (! isvar (&opP->disp)
2276 && (opP->disp.size == SIZE_UNSPEC)
2277 && (opP->reg >= ADDR0)
2278 && (opP->reg <= ADDR7))
2280 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2285 && ! isvar (&opP->disp)
2288 opP->disp.exp.X_op = O_symbol;
2289 opP->disp.exp.X_add_symbol =
2290 section_symbol (absolute_section);
2293 /* Force into index mode. Hope this works. */
2295 /* We do the first bit for 32-bit displacements, and the
2296 second bit for 16 bit ones. It is possible that we
2297 should make the default be WORD instead of LONG, but
2298 I think that'd break GCC, so we put up with a little
2299 inefficiency for the sake of working output. */
2301 if (!issword (nextword)
2302 || (isvar (&opP->disp)
2303 && ((opP->disp.size == SIZE_UNSPEC
2304 && flag_short_refs == 0
2305 && cpu_of_arch (current_architecture) >= m68020
2306 && ! arch_coldfire_p (current_architecture))
2307 || opP->disp.size == SIZE_LONG)))
2309 if (cpu_of_arch (current_architecture) < m68020
2310 || arch_coldfire_p (current_architecture))
2312 _("displacement too large for this architecture; needs 68020 or higher");
2314 tmpreg = 0x3B; /* 7.3 */
2316 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2317 if (isvar (&opP->disp))
2321 if (opP->disp.size == SIZE_LONG
2323 /* If the displacement needs pic
2324 relocation it cannot be relaxed. */
2325 || opP->disp.pic_reloc != pic_none
2330 add_fix ('l', &opP->disp, 1, 2);
2334 add_frag (adds (&opP->disp),
2335 SEXT (offs (&opP->disp)),
2336 TAB (PCREL1632, SZ_UNDEF));
2343 add_fix ('l', &opP->disp, 0, 0);
2348 addword (nextword >> 16);
2353 tmpreg = 0x3A; /* 7.2 */
2355 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2357 if (isvar (&opP->disp))
2361 add_fix ('w', &opP->disp, 1, 0);
2364 add_fix ('w', &opP->disp, 0, 0);
2374 baseo = get_num (&opP->disp, 90);
2375 if (opP->mode == POST || opP->mode == PRE)
2376 outro = get_num (&opP->odisp, 90);
2377 /* Figure out the `addressing mode'.
2378 Also turn on the BASE_DISABLE bit, if needed. */
2379 if (opP->reg == PC || opP->reg == ZPC)
2381 tmpreg = 0x3b; /* 7.3 */
2382 if (opP->reg == ZPC)
2385 else if (opP->reg == 0)
2388 tmpreg = 0x30; /* 6.garbage */
2390 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2393 tmpreg = 0x30 + opP->reg - ZADDR0;
2396 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2398 siz1 = opP->disp.size;
2399 if (opP->mode == POST || opP->mode == PRE)
2400 siz2 = opP->odisp.size;
2404 /* Index register stuff. */
2405 if (opP->index.reg != 0
2406 && opP->index.reg >= DATA
2407 && opP->index.reg <= ADDR7)
2409 nextword |= (opP->index.reg - DATA) << 12;
2411 if (opP->index.size == SIZE_LONG
2412 || (opP->index.size == SIZE_UNSPEC
2413 && m68k_index_width_default == SIZE_LONG))
2416 if ((opP->index.scale != 1
2417 && cpu_of_arch (current_architecture) < m68020)
2418 || (opP->index.scale == 8
2419 && (arch_coldfire_p (current_architecture)
2420 && !arch_coldfire_fpu (current_architecture))))
2423 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2426 if (arch_coldfire_p (current_architecture)
2427 && opP->index.size == SIZE_WORD)
2428 opP->error = _("invalid index size for coldfire");
2430 switch (opP->index.scale)
2447 GET US OUT OF HERE! */
2449 /* Must be INDEX, with an index register. Address
2450 register cannot be ZERO-PC, and either :b was
2451 forced, or we know it will fit. For a 68000 or
2452 68010, force this mode anyways, because the
2453 larger modes aren't supported. */
2454 if (opP->mode == BASE
2455 && ((opP->reg >= ADDR0
2456 && opP->reg <= ADDR7)
2459 if (siz1 == SIZE_BYTE
2460 || cpu_of_arch (current_architecture) < m68020
2461 || arch_coldfire_p (current_architecture)
2462 || (siz1 == SIZE_UNSPEC
2463 && ! isvar (&opP->disp)
2464 && issbyte (baseo)))
2466 nextword += baseo & 0xff;
2468 if (isvar (&opP->disp))
2470 /* Do a byte relocation. If it doesn't
2471 fit (possible on m68000) let the
2472 fixup processing complain later. */
2474 add_fix ('B', &opP->disp, 1, 1);
2476 add_fix ('B', &opP->disp, 0, 0);
2478 else if (siz1 != SIZE_BYTE)
2480 if (siz1 != SIZE_UNSPEC)
2481 as_warn (_("Forcing byte displacement"));
2482 if (! issbyte (baseo))
2483 opP->error = _("byte displacement out of range");
2488 else if (siz1 == SIZE_UNSPEC
2490 && isvar (&opP->disp)
2491 && subs (&opP->disp) == NULL
2493 /* If the displacement needs pic
2494 relocation it cannot be relaxed. */
2495 && opP->disp.pic_reloc == pic_none
2499 /* The code in md_convert_frag_1 needs to be
2500 able to adjust nextword. Call frag_grow
2501 to ensure that we have enough space in
2502 the frag obstack to make all the bytes
2505 nextword += baseo & 0xff;
2507 add_frag (adds (&opP->disp),
2508 SEXT (offs (&opP->disp)),
2509 TAB (PCINDEX, SZ_UNDEF));
2517 nextword |= 0x40; /* No index reg. */
2518 if (opP->index.reg >= ZDATA0
2519 && opP->index.reg <= ZDATA7)
2520 nextword |= (opP->index.reg - ZDATA0) << 12;
2521 else if (opP->index.reg >= ZADDR0
2522 || opP->index.reg <= ZADDR7)
2523 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2526 /* It isn't simple. */
2528 if (cpu_of_arch (current_architecture) < m68020
2529 || arch_coldfire_p (current_architecture))
2531 _("invalid operand mode for this architecture; needs 68020 or higher");
2534 /* If the guy specified a width, we assume that it is
2535 wide enough. Maybe it isn't. If so, we lose. */
2539 if (isvar (&opP->disp)
2541 : ! issword (baseo))
2546 else if (! isvar (&opP->disp) && baseo == 0)
2555 as_warn (_(":b not permitted; defaulting to :w"));
2565 /* Figure out inner displacement stuff. */
2566 if (opP->mode == POST || opP->mode == PRE)
2568 if (cpu_of_arch (current_architecture) & cpu32)
2569 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2573 if (isvar (&opP->odisp)
2575 : ! issword (outro))
2580 else if (! isvar (&opP->odisp) && outro == 0)
2589 as_warn (_(":b not permitted; defaulting to :w"));
2598 if (opP->mode == POST
2599 && (nextword & 0x40) == 0)
2604 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2606 if (opP->reg == PC || opP->reg == ZPC)
2607 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2609 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2611 if (siz1 == SIZE_LONG)
2612 addword (baseo >> 16);
2613 if (siz1 != SIZE_UNSPEC)
2616 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2617 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2618 if (siz2 == SIZE_LONG)
2619 addword (outro >> 16);
2620 if (siz2 != SIZE_UNSPEC)
2626 nextword = get_num (&opP->disp, 90);
2627 switch (opP->disp.size)
2632 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2634 tmpreg = 0x38; /* 7.0 */
2638 if (isvar (&opP->disp)
2639 && !subs (&opP->disp)
2640 && adds (&opP->disp)
2642 /* If the displacement needs pic relocation it
2643 cannot be relaxed. */
2644 && opP->disp.pic_reloc == pic_none
2647 && !strchr ("~%&$?", s[0]))
2649 tmpreg = 0x3A; /* 7.2 */
2650 add_frag (adds (&opP->disp),
2651 SEXT (offs (&opP->disp)),
2652 TAB (ABSTOPCREL, SZ_UNDEF));
2655 /* Fall through into long. */
2657 if (isvar (&opP->disp))
2658 add_fix ('l', &opP->disp, 0, 0);
2660 tmpreg = 0x39;/* 7.1 mode */
2661 addword (nextword >> 16);
2666 as_bad (_("unsupported byte value; use a different suffix"));
2670 if (isvar (&opP->disp))
2671 add_fix ('w', &opP->disp, 0, 0);
2673 tmpreg = 0x38;/* 7.0 mode */
2681 as_bad (_("unknown/incorrect operand"));
2685 /* If s[0] is '4', then this is for the mac instructions
2686 that can have a trailing_ampersand set. If so, set 0x100
2687 bit on tmpreg so install_gen_operand can check for it and
2688 set the appropriate bit (word2, bit 5). */
2691 if (opP->trailing_ampersand)
2694 install_gen_operand (s[1], tmpreg);
2700 { /* JF: I hate floating point! */
2715 tmpreg = get_num (&opP->disp, tmpreg);
2716 if (isvar (&opP->disp))
2717 add_fix (s[1], &opP->disp, 0, 0);
2720 case 'b': /* Danger: These do no check for
2721 certain types of overflow.
2723 if (!isbyte (tmpreg))
2724 opP->error = _("out of range");
2725 insop (tmpreg, opcode);
2726 if (isvar (&opP->disp))
2727 the_ins.reloc[the_ins.nrel - 1].n =
2728 (opcode->m_codenum) * 2 + 1;
2731 if (!issbyte (tmpreg))
2732 opP->error = _("out of range");
2733 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2734 if (isvar (&opP->disp))
2735 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2738 if (!isword (tmpreg))
2739 opP->error = _("out of range");
2740 insop (tmpreg, opcode);
2741 if (isvar (&opP->disp))
2742 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2745 if (!issword (tmpreg))
2746 opP->error = _("out of range");
2747 insop (tmpreg, opcode);
2748 if (isvar (&opP->disp))
2749 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2752 /* Because of the way insop works, we put these two out
2754 insop (tmpreg, opcode);
2755 insop (tmpreg >> 16, opcode);
2756 if (isvar (&opP->disp))
2757 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2764 install_operand (s[1], tmpreg);
2775 install_operand (s[1], opP->reg - ADDR);
2779 tmpreg = get_num (&opP->disp, 90);
2783 add_fix ('B', &opP->disp, 1, -1);
2786 add_fix ('w', &opP->disp, 1, 0);
2791 if (! HAVE_LONG_BRANCH (current_architecture))
2792 as_warn (_("Can't use long branches on 68000/68010/5200"));
2793 the_ins.opcode[0] |= 0xff;
2794 add_fix ('l', &opP->disp, 1, 0);
2799 if (subs (&opP->disp)) /* We can't relax it. */
2803 /* If the displacement needs pic relocation it cannot be
2805 if (opP->disp.pic_reloc != pic_none)
2808 /* This could either be a symbol, or an absolute
2809 address. If it's an absolute address, turn it into
2810 an absolute jump right here and keep it out of the
2812 if (adds (&opP->disp) == 0)
2814 if (the_ins.opcode[0] == 0x6000) /* jbra */
2815 the_ins.opcode[0] = 0x4EF9;
2816 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2817 the_ins.opcode[0] = 0x4EB9;
2820 the_ins.opcode[0] ^= 0x0100;
2821 the_ins.opcode[0] |= 0x0006;
2824 add_fix ('l', &opP->disp, 0, 0);
2830 /* Now we know it's going into the relaxer. Now figure
2831 out which mode. We try in this order of preference:
2832 long branch, absolute jump, byte/word branches only. */
2833 if (HAVE_LONG_BRANCH (current_architecture))
2834 add_frag (adds (&opP->disp),
2835 SEXT (offs (&opP->disp)),
2836 TAB (BRANCHBWL, SZ_UNDEF));
2837 else if (! flag_keep_pcrel)
2839 if ((the_ins.opcode[0] == 0x6000)
2840 || (the_ins.opcode[0] == 0x6100))
2841 add_frag (adds (&opP->disp),
2842 SEXT (offs (&opP->disp)),
2843 TAB (BRABSJUNC, SZ_UNDEF));
2845 add_frag (adds (&opP->disp),
2846 SEXT (offs (&opP->disp)),
2847 TAB (BRABSJCOND, SZ_UNDEF));
2850 add_frag (adds (&opP->disp),
2851 SEXT (offs (&opP->disp)),
2852 TAB (BRANCHBW, SZ_UNDEF));
2855 if (isvar (&opP->disp))
2857 /* Check for DBcc instructions. We can relax them,
2858 but only if we have long branches and/or absolute
2860 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2861 && (HAVE_LONG_BRANCH (current_architecture)
2862 || (! flag_keep_pcrel)))
2864 if (HAVE_LONG_BRANCH (current_architecture))
2865 add_frag (adds (&opP->disp),
2866 SEXT (offs (&opP->disp)),
2867 TAB (DBCCLBR, SZ_UNDEF));
2869 add_frag (adds (&opP->disp),
2870 SEXT (offs (&opP->disp)),
2871 TAB (DBCCABSJ, SZ_UNDEF));
2874 add_fix ('w', &opP->disp, 1, 0);
2878 case 'C': /* Fixed size LONG coproc branches. */
2879 add_fix ('l', &opP->disp, 1, 0);
2883 case 'c': /* Var size Coprocesssor branches. */
2884 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
2886 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2887 add_fix ('l', &opP->disp, 1, 0);
2892 add_frag (adds (&opP->disp),
2893 SEXT (offs (&opP->disp)),
2894 TAB (FBRANCH, SZ_UNDEF));
2901 case 'C': /* Ignore it. */
2904 case 'd': /* JF this is a kludge. */
2905 install_operand ('s', opP->reg - ADDR);
2906 tmpreg = get_num (&opP->disp, 90);
2907 if (!issword (tmpreg))
2909 as_warn (_("Expression out of range, using 0"));
2916 install_operand (s[1], opP->reg - DATA);
2919 case 'e': /* EMAC ACCx, reg/reg. */
2920 install_operand (s[1], opP->reg - ACC);
2923 case 'E': /* Ignore it. */
2927 install_operand (s[1], opP->reg - FP0);
2930 case 'g': /* EMAC ACCEXTx. */
2931 install_operand (s[1], opP->reg - ACCEXT01);
2934 case 'G': /* Ignore it. */
2939 tmpreg = opP->reg - COP0;
2940 install_operand (s[1], tmpreg);
2943 case 'i': /* MAC/EMAC scale factor. */
2944 install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
2947 case 'J': /* JF foo. */
3077 install_operand (s[1], tmpreg);
3081 tmpreg = get_num (&opP->disp, 55);
3082 install_operand (s[1], tmpreg & 0x7f);
3089 if (tmpreg & 0x7FF0000)
3090 as_bad (_("Floating point register in register list"));
3091 insop (reverse_16_bits (tmpreg), opcode);
3095 if (tmpreg & 0x700FFFF)
3096 as_bad (_("Wrong register in floating-point reglist"));
3097 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
3105 if (tmpreg & 0x7FF0000)
3106 as_bad (_("Floating point register in register list"));
3107 insop (tmpreg, opcode);
3109 else if (s[1] == '8')
3111 if (tmpreg & 0x0FFFFFF)
3112 as_bad (_("incorrect register in reglist"));
3113 install_operand (s[1], tmpreg >> 24);
3117 if (tmpreg & 0x700FFFF)
3118 as_bad (_("wrong register in floating-point reglist"));
3120 install_operand (s[1], tmpreg >> 16);
3125 install_operand (s[1], get_num (&opP->disp, 60));
3129 tmpreg = ((opP->mode == DREG)
3130 ? 0x20 + (int) (opP->reg - DATA)
3131 : (get_num (&opP->disp, 40) & 0x1F));
3132 install_operand (s[1], tmpreg);
3136 tmpreg = get_num (&opP->disp, 10);
3139 install_operand (s[1], tmpreg);
3143 /* This depends on the fact that ADDR registers are eight
3144 more than their corresponding DATA regs, so the result
3145 will have the ADDR_REG bit set. */
3146 install_operand (s[1], opP->reg - DATA);
3150 if (opP->mode == AINDR)
3151 install_operand (s[1], opP->reg - DATA);
3153 install_operand (s[1], opP->index.reg - DATA);
3157 if (opP->reg == FPI)
3159 else if (opP->reg == FPS)
3161 else if (opP->reg == FPC)
3165 install_operand (s[1], tmpreg);
3168 case 'S': /* Ignore it. */
3172 install_operand (s[1], get_num (&opP->disp, 30));
3175 case 'U': /* Ignore it. */
3194 as_fatal (_("failed sanity check"));
3195 } /* switch on cache token. */
3196 install_operand (s[1], tmpreg);
3199 /* JF: These are out of order, I fear. */
3212 install_operand (s[1], tmpreg);
3238 install_operand (s[1], tmpreg);
3242 if (opP->reg == VAL)
3261 install_operand (s[1], tmpreg);
3275 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
3286 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
3292 install_operand (s[1], tmpreg);
3295 know (opP->reg == PSR);
3298 know (opP->reg == PCSR);
3313 install_operand (s[1], tmpreg);
3316 tmpreg = get_num (&opP->disp, 20);
3317 install_operand (s[1], tmpreg);
3319 case '_': /* used only for move16 absolute 32-bit address. */
3320 if (isvar (&opP->disp))
3321 add_fix ('l', &opP->disp, 0, 0);
3322 tmpreg = get_num (&opP->disp, 90);
3323 addword (tmpreg >> 16);
3324 addword (tmpreg & 0xFFFF);
3327 install_operand (s[1], opP->reg - DATA0L);
3328 opP->reg -= (DATA0L);
3329 opP->reg &= 0x0F; /* remove upper/lower bit. */
3332 tmpreg = get_num (&opP->disp, 80);
3335 install_operand (s[1], tmpreg);
3342 /* By the time whe get here (FINALLY) the_ins contains the complete
3343 instruction, ready to be emitted. . . */
3347 reverse_16_bits (int in)
3352 static int mask[16] =
3354 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3355 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3357 for (n = 0; n < 16; n++)
3360 out |= mask[15 - n];
3363 } /* reverse_16_bits() */
3366 reverse_8_bits (int in)
3371 static int mask[8] =
3373 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3376 for (n = 0; n < 8; n++)
3382 } /* reverse_8_bits() */
3384 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3385 (that value is chosen in the frag_var call in md_assemble). TYPE
3386 is the subtype of the frag to be generated; its primary type is
3387 rs_machine_dependent.
3389 The TYPE parameter is also used by md_convert_frag_1 and
3390 md_estimate_size_before_relax. The appropriate type of fixup will
3391 be emitted by md_convert_frag_1.
3393 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3395 install_operand (int mode, int val)
3400 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
3403 the_ins.opcode[0] |= val << 9;
3406 the_ins.opcode[1] |= val << 12;
3409 the_ins.opcode[1] |= val << 6;
3412 the_ins.opcode[1] |= val;
3415 the_ins.opcode[2] |= val << 12;
3418 the_ins.opcode[2] |= val << 6;
3421 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3422 three words long! */
3424 the_ins.opcode[2] |= val;
3427 the_ins.opcode[1] |= val << 7;
3430 the_ins.opcode[1] |= val << 10;
3434 the_ins.opcode[1] |= val << 5;
3439 the_ins.opcode[1] |= (val << 10) | (val << 7);
3442 the_ins.opcode[1] |= (val << 12) | val;
3445 the_ins.opcode[0] |= val = 0xff;
3448 the_ins.opcode[0] |= val << 9;
3451 the_ins.opcode[1] |= val;
3454 the_ins.opcode[1] |= val;
3455 the_ins.numo++; /* What a hack. */
3458 the_ins.opcode[1] |= val << 4;
3466 the_ins.opcode[0] |= (val << 6);
3469 the_ins.opcode[1] = (val >> 16);
3470 the_ins.opcode[2] = val & 0xffff;
3473 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3474 the_ins.opcode[0] |= ((val & 0x7) << 9);
3475 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3477 case 'n': /* MAC/EMAC Rx on !load. */
3478 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3479 the_ins.opcode[0] |= ((val & 0x7) << 9);
3480 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3482 case 'o': /* MAC/EMAC Rx on load. */
3483 the_ins.opcode[1] |= val << 12;
3484 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3486 case 'M': /* MAC/EMAC Ry on !load. */
3487 the_ins.opcode[0] |= (val & 0xF);
3488 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3490 case 'N': /* MAC/EMAC Ry on load. */
3491 the_ins.opcode[1] |= (val & 0xF);
3492 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3495 the_ins.opcode[1] |= ((val != 1) << 10);
3498 the_ins.opcode[0] |= ((val & 0x3) << 9);
3501 the_ins.opcode[0] |= ((val & 0x3) << 0);
3503 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3504 the_ins.opcode[0] |= ((~val & 0x1) << 7);
3505 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3507 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3508 the_ins.opcode[0] |= ((val & 0x1) << 7);
3509 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3512 the_ins.opcode[1] |= ((val & 0x3) << 9);
3515 the_ins.opcode[0] |= (val & 0x1) <<10;
3519 as_fatal (_("failed sanity check."));
3524 install_gen_operand (int mode, int val)
3528 case '/': /* Special for mask loads for mac/msac insns with
3529 possible mask; trailing_ampersend set in bit 8. */
3530 the_ins.opcode[0] |= (val & 0x3f);
3531 the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
3534 the_ins.opcode[0] |= val;
3537 /* This is a kludge!!! */
3538 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3547 the_ins.opcode[0] |= val;
3549 /* more stuff goes here. */
3551 as_fatal (_("failed sanity check."));
3555 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3556 then deal with the bitfield hack. */
3559 crack_operand (char *str, struct m68k_op *opP)
3561 register int parens;
3563 register char *beg_str;
3571 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3577 else if (*str == ')')
3581 opP->error = _("Extra )");
3587 if (flag_mri && *str == '\'')
3588 inquote = ! inquote;
3590 if (!*str && parens)
3592 opP->error = _("Missing )");
3597 if (m68k_ip_op (beg_str, opP) != 0)
3604 c = *++str; /* JF bitfield hack. */
3609 as_bad (_("Missing operand"));
3612 /* Detect MRI REG symbols and convert them to REGLSTs. */
3613 if (opP->mode == CONTROL && (int)opP->reg < 0)
3616 opP->mask = ~(int)opP->reg;
3623 /* This is the guts of the machine-dependent assembler. STR points to a
3624 machine dependent instruction. This function is supposed to emit
3625 the frags/bytes it assembles to.
3629 insert_reg (const char *regname, int regnum)
3634 #ifdef REGISTER_PREFIX
3635 if (!flag_reg_prefix_optional)
3637 buf[0] = REGISTER_PREFIX;
3638 strcpy (buf + 1, regname);
3643 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3644 &zero_address_frag));
3646 for (i = 0; regname[i]; i++)
3647 buf[i] = TOUPPER (regname[i]);
3650 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3651 &zero_address_frag));
3660 static const struct init_entry init_table[] =
3720 { "accext01", ACCEXT01 },
3721 { "accext23", ACCEXT23 },
3725 /* Control registers. */
3726 { "sfc", SFC }, /* Source Function Code. */
3728 { "dfc", DFC }, /* Destination Function Code. */
3730 { "cacr", CACR }, /* Cache Control Register. */
3731 { "caar", CAAR }, /* Cache Address Register. */
3733 { "usp", USP }, /* User Stack Pointer. */
3734 { "vbr", VBR }, /* Vector Base Register. */
3735 { "msp", MSP }, /* Master Stack Pointer. */
3736 { "isp", ISP }, /* Interrupt Stack Pointer. */
3738 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
3739 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
3740 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
3741 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
3743 /* 68ec040 versions of same */
3744 { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
3745 { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
3746 { "dacr0", DTT0 }, /* Data Access Control Register 0. */
3747 { "dacr1", DTT1 }, /* Data Access Control Register 0. */
3749 /* mcf5200 versions of same. The ColdFire programmer's reference
3750 manual indicated that the order is 2,3,0,1, but Ken Rose
3751 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3752 { "acr0", ACR0 }, /* Access Control Unit 0. */
3753 { "acr1", ACR1 }, /* Access Control Unit 1. */
3754 { "acr2", ACR2 }, /* Access Control Unit 2. */
3755 { "acr3", ACR3 }, /* Access Control Unit 3. */
3757 { "tc", TC }, /* MMU Translation Control Register. */
3760 { "mmusr", MMUSR }, /* MMU Status Register. */
3761 { "srp", SRP }, /* User Root Pointer. */
3762 { "urp", URP }, /* Supervisor Root Pointer. */
3767 { "rombar", ROMBAR }, /* ROM Base Address Register. */
3768 { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
3769 { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
3770 { "mbar", MBAR }, /* Module Base Address Register. */
3772 { "mbar0", MBAR0 }, /* mcfv4e registers. */
3773 { "mbar1", MBAR1 }, /* mcfv4e registers. */
3774 { "rombar0", ROMBAR }, /* mcfv4e registers. */
3775 { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
3776 { "mpcr", MPCR }, /* mcfv4e registers. */
3777 { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
3778 { "secmbar", SECMBAR }, /* mcfv4e registers. */
3779 { "asid", TC }, /* mcfv4e registers. */
3780 { "mmubar", BUSCR }, /* mcfv4e registers. */
3781 { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
3782 { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
3783 { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
3784 { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
3785 { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
3786 { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
3787 { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
3788 { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
3789 { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
3790 { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
3791 { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
3792 { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
3794 { "flashbar", FLASHBAR }, /* mcf528x registers. */
3795 { "rambar", RAMBAR }, /* mcf528x registers. */
3797 { "mbar2", MBAR2 }, /* mcf5249 registers. */
3798 /* End of control registers. */
3832 /* 68ec030 versions of same. */
3835 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3838 /* Suppressed data and address registers. */
3856 /* Upper and lower data and address registers, used by macw and msacw. */
3897 init_regtable (void)
3900 for (i = 0; init_table[i].name; i++)
3901 insert_reg (init_table[i].name, init_table[i].number);
3905 md_assemble (char *str)
3912 int shorts_this_frag;
3915 if (!selected_cpu && !selected_arch)
3917 /* We've not selected an architecture yet. Set the default
3918 now. We do this lazily so that an initial .cpu or .arch directive
3920 if (!m68k_set_cpu (TARGET_CPU, 1, 1))
3921 as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU);
3926 /* In MRI mode, the instruction and operands are separated by a
3927 space. Anything following the operands is a comment. The label
3928 has already been removed. */
3936 for (s = str; *s != '\0'; s++)
3938 if ((*s == ' ' || *s == '\t') && ! inquote)
3956 inquote = ! inquote;
3961 memset (&the_ins, '\0', sizeof (the_ins));
3966 for (n = 0; n < the_ins.numargs; n++)
3967 if (the_ins.operands[n].error)
3969 er = the_ins.operands[n].error;
3975 as_bad (_("%s -- statement `%s' ignored"), er, str);
3979 /* If there is a current label, record that it marks an instruction. */
3980 if (current_label != NULL)
3982 current_label->text = 1;
3983 current_label = NULL;
3987 /* Tie dwarf2 debug info to the address at the start of the insn. */
3988 dwarf2_emit_insn (0);
3991 if (the_ins.nfrag == 0)
3993 /* No frag hacking involved; just put it out. */
3994 toP = frag_more (2 * the_ins.numo);
3995 fromP = &the_ins.opcode[0];
3996 for (m = the_ins.numo; m; --m)
3998 md_number_to_chars (toP, (long) (*fromP), 2);
4002 /* Put out symbol-dependent info. */
4003 for (m = 0; m < the_ins.nrel; m++)
4005 switch (the_ins.reloc[m].wid)
4024 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4025 the_ins.reloc[m].wid);
4028 fixP = fix_new_exp (frag_now,
4029 ((toP - frag_now->fr_literal)
4030 - the_ins.numo * 2 + the_ins.reloc[m].n),
4032 &the_ins.reloc[m].exp,
4033 the_ins.reloc[m].pcrel,
4034 get_reloc_code (n, the_ins.reloc[m].pcrel,
4035 the_ins.reloc[m].pic_reloc));
4036 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4037 if (the_ins.reloc[m].wid == 'B')
4038 fixP->fx_signed = 1;
4043 /* There's some frag hacking. */
4045 /* Calculate the max frag size. */
4048 wid = 2 * the_ins.fragb[0].fragoff;
4049 for (n = 1; n < the_ins.nfrag; n++)
4050 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4051 /* frag_var part. */
4053 /* Make sure the whole insn fits in one chunk, in particular that
4054 the var part is attached, as we access one byte before the
4055 variable frag for byte branches. */
4059 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
4064 wid = 2 * the_ins.fragb[n].fragoff;
4066 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4067 toP = frag_more (wid);
4069 shorts_this_frag = 0;
4070 for (m = wid / 2; m; --m)
4072 md_number_to_chars (toP, (long) (*fromP), 2);
4077 for (m = 0; m < the_ins.nrel; m++)
4079 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
4081 the_ins.reloc[m].n -= 2 * shorts_this_frag;
4084 wid = the_ins.reloc[m].wid;
4087 the_ins.reloc[m].wid = 0;
4088 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4090 fixP = fix_new_exp (frag_now,
4091 ((toP - frag_now->fr_literal)
4092 - the_ins.numo * 2 + the_ins.reloc[m].n),
4094 &the_ins.reloc[m].exp,
4095 the_ins.reloc[m].pcrel,
4096 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4097 the_ins.reloc[m].pic_reloc));
4098 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4100 (void) frag_var (rs_machine_dependent, 10, 0,
4101 (relax_substateT) (the_ins.fragb[n].fragty),
4102 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
4104 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4105 shorts_this_frag = 0;
4108 toP = frag_more (n * 2);
4111 md_number_to_chars (toP, (long) (*fromP), 2);
4117 for (m = 0; m < the_ins.nrel; m++)
4121 wid = the_ins.reloc[m].wid;
4124 the_ins.reloc[m].wid = 0;
4125 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4127 fixP = fix_new_exp (frag_now,
4128 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
4129 - shorts_this_frag * 2),
4131 &the_ins.reloc[m].exp,
4132 the_ins.reloc[m].pcrel,
4133 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4134 the_ins.reloc[m].pic_reloc));
4135 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4139 /* Comparison function used by qsort to rank the opcode entries by name. */
4142 m68k_compare_opcode (const void * v1, const void * v2)
4144 struct m68k_opcode * op1, * op2;
4150 op1 = *(struct m68k_opcode **) v1;
4151 op2 = *(struct m68k_opcode **) v2;
4153 /* Compare the two names. If different, return the comparison.
4154 If the same, return the order they are in the opcode table. */
4155 ret = strcmp (op1->name, op2->name);
4166 const struct m68k_opcode *ins;
4167 struct m68k_incant *hack, *slak;
4168 const char *retval = 0; /* Empty string, or error msg text. */
4171 /* Set up hash tables with 68000 instructions.
4172 similar to what the vax assembler does. */
4173 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4174 a copy of it at runtime, adding in the information we want but isn't
4175 there. I think it'd be better to have an awk script hack the table
4176 at compile time. Or even just xstr the table and use it as-is. But
4177 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4182 flag_reg_prefix_optional = 1;
4184 if (! m68k_rel32_from_cmdline)
4188 /* First sort the opcode table into alphabetical order to seperate
4189 the order that the assembler wants to see the opcodes from the
4190 order that the disassembler wants to see them. */
4191 m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4192 if (!m68k_sorted_opcodes)
4193 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4194 m68k_numopcodes * ((int) sizeof (* m68k_sorted_opcodes)));
4196 for (i = m68k_numopcodes; i--;)
4197 m68k_sorted_opcodes[i] = m68k_opcodes + i;
4199 qsort (m68k_sorted_opcodes, m68k_numopcodes,
4200 sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
4202 op_hash = hash_new ();
4204 obstack_begin (&robyn, 4000);
4205 for (i = 0; i < m68k_numopcodes; i++)
4207 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
4210 ins = m68k_sorted_opcodes[i];
4212 /* We *could* ignore insns that don't match our
4213 arch here by just leaving them out of the hash. */
4214 slak->m_operands = ins->args;
4215 slak->m_opnum = strlen (slak->m_operands) / 2;
4216 slak->m_arch = ins->arch;
4217 slak->m_opcode = ins->opcode;
4218 /* This is kludgey. */
4219 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
4220 if (i + 1 != m68k_numopcodes
4221 && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
4223 slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4228 slak = slak->m_next;
4232 retval = hash_insert (op_hash, ins->name, (char *) hack);
4234 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
4237 for (i = 0; i < m68k_numaliases; i++)
4239 const char *name = m68k_opcode_aliases[i].primary;
4240 const char *alias = m68k_opcode_aliases[i].alias;
4241 PTR val = hash_find (op_hash, name);
4244 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4245 retval = hash_insert (op_hash, alias, val);
4247 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4250 /* In MRI mode, all unsized branches are variable sized. Normally,
4251 they are word sized. */
4254 static struct m68k_opcode_alias mri_aliases[] =
4275 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
4278 const char *name = mri_aliases[i].primary;
4279 const char *alias = mri_aliases[i].alias;
4280 PTR val = hash_find (op_hash, name);
4283 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4284 retval = hash_jam (op_hash, alias, val);
4286 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4290 for (i = 0; i < (int) sizeof (notend_table); i++)
4292 notend_table[i] = 0;
4293 alt_notend_table[i] = 0;
4296 notend_table[','] = 1;
4297 notend_table['{'] = 1;
4298 notend_table['}'] = 1;
4299 alt_notend_table['a'] = 1;
4300 alt_notend_table['A'] = 1;
4301 alt_notend_table['d'] = 1;
4302 alt_notend_table['D'] = 1;
4303 alt_notend_table['#'] = 1;
4304 alt_notend_table['&'] = 1;
4305 alt_notend_table['f'] = 1;
4306 alt_notend_table['F'] = 1;
4307 #ifdef REGISTER_PREFIX
4308 alt_notend_table[REGISTER_PREFIX] = 1;
4311 /* We need to put '(' in alt_notend_table to handle
4312 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4313 alt_notend_table['('] = 1;
4315 /* We need to put '@' in alt_notend_table to handle
4316 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4317 alt_notend_table['@'] = 1;
4319 /* We need to put digits in alt_notend_table to handle
4320 bfextu %d0{24:1},%d0 */
4321 alt_notend_table['0'] = 1;
4322 alt_notend_table['1'] = 1;
4323 alt_notend_table['2'] = 1;
4324 alt_notend_table['3'] = 1;
4325 alt_notend_table['4'] = 1;
4326 alt_notend_table['5'] = 1;
4327 alt_notend_table['6'] = 1;
4328 alt_notend_table['7'] = 1;
4329 alt_notend_table['8'] = 1;
4330 alt_notend_table['9'] = 1;
4332 #ifndef MIT_SYNTAX_ONLY
4333 /* Insert pseudo ops, these have to go into the opcode table since
4334 gas expects pseudo ops to start with a dot. */
4338 while (mote_pseudo_table[n].poc_name)
4340 hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4341 hash_insert (op_hash,
4342 mote_pseudo_table[n].poc_name, (char *) hack);
4343 hack->m_operands = 0;
4353 record_alignment (text_section, 2);
4354 record_alignment (data_section, 2);
4355 record_alignment (bss_section, 2);
4360 /* This is called when a label is defined. */
4363 m68k_frob_label (symbolS *sym)
4365 struct label_line *n;
4367 n = (struct label_line *) xmalloc (sizeof *n);
4370 as_where (&n->file, &n->line);
4376 dwarf2_emit_label (sym);
4380 /* This is called when a value that is not an instruction is emitted. */
4383 m68k_flush_pending_output (void)
4385 current_label = NULL;
4388 /* This is called at the end of the assembly, when the final value of
4389 the label is known. We warn if this is a text symbol aligned at an
4393 m68k_frob_symbol (symbolS *sym)
4395 if (S_GET_SEGMENT (sym) == reg_section
4396 && (int) S_GET_VALUE (sym) < 0)
4398 S_SET_SEGMENT (sym, absolute_section);
4399 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4401 else if ((S_GET_VALUE (sym) & 1) != 0)
4403 struct label_line *l;
4405 for (l = labels; l != NULL; l = l->next)
4407 if (l->label == sym)
4410 as_warn_where (l->file, l->line,
4411 _("text label `%s' aligned to odd boundary"),
4419 /* This is called if we go in or out of MRI mode because of the .mri
4423 m68k_mri_mode_change (int on)
4427 if (! flag_reg_prefix_optional)
4429 flag_reg_prefix_optional = 1;
4430 #ifdef REGISTER_PREFIX
4435 if (! m68k_rel32_from_cmdline)
4440 if (! reg_prefix_optional_seen)
4442 #ifdef REGISTER_PREFIX_OPTIONAL
4443 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4445 flag_reg_prefix_optional = 0;
4447 #ifdef REGISTER_PREFIX
4452 if (! m68k_rel32_from_cmdline)
4457 /* Equal to MAX_PRECISION in atof-ieee.c. */
4458 #define MAX_LITTLENUMS 6
4460 /* Turn a string in input_line_pointer into a floating point constant
4461 of type TYPE, and store the appropriate bytes in *LITP. The number
4462 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4463 returned, or NULL on OK. */
4466 md_atof (int type, char *litP, int *sizeP)
4469 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4470 LITTLENUM_TYPE *wordP;
4501 return _("Bad call to MD_ATOF()");
4503 t = atof_ieee (input_line_pointer, type, words);
4505 input_line_pointer = t;
4507 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4508 for (wordP = words; prec--;)
4510 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4511 litP += sizeof (LITTLENUM_TYPE);
4517 md_number_to_chars (char *buf, valueT val, int n)
4519 number_to_chars_bigendian (buf, val, n);
4523 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
4525 offsetT val = *valP;
4526 addressT upper_limit;
4527 offsetT lower_limit;
4529 /* This is unnecessary but it convinces the native rs6000 compiler
4530 to generate the code we want. */
4531 char *buf = fixP->fx_frag->fr_literal;
4532 buf += fixP->fx_where;
4533 /* End ibm compiler workaround. */
4537 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
4543 memset (buf, 0, fixP->fx_size);
4544 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4546 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4547 && !S_IS_DEFINED (fixP->fx_addsy)
4548 && !S_IS_WEAK (fixP->fx_addsy))
4549 S_SET_WEAK (fixP->fx_addsy);
4554 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4555 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4558 switch (fixP->fx_size)
4560 /* The cast to offsetT below are necessary to make code
4561 correct for machines where ints are smaller than offsetT. */
4565 lower_limit = - (offsetT) 0x80;
4568 *buf++ = (val >> 8);
4570 upper_limit = 0x7fff;
4571 lower_limit = - (offsetT) 0x8000;
4574 *buf++ = (val >> 24);
4575 *buf++ = (val >> 16);
4576 *buf++ = (val >> 8);
4578 upper_limit = 0x7fffffff;
4579 lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
4582 BAD_CASE (fixP->fx_size);
4585 /* Fix up a negative reloc. */
4586 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4588 fixP->fx_addsy = fixP->fx_subsy;
4589 fixP->fx_subsy = NULL;
4593 /* For non-pc-relative values, it's conceivable we might get something
4594 like "0xff" for a byte field. So extend the upper part of the range
4595 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4596 so that we can do any range checking at all. */
4597 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4598 upper_limit = upper_limit * 2 + 1;
4600 if ((addressT) val > upper_limit
4601 && (val > 0 || val < lower_limit))
4602 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4604 /* A one byte PC-relative reloc means a short branch. We can't use
4605 a short branch with a value of 0 or -1, because those indicate
4606 different opcodes (branches with longer offsets). fixup_segment
4607 in write.c may have clobbered fx_pcrel, so we need to examine the
4610 || fixP->fx_r_type == BFD_RELOC_8_PCREL)
4611 && fixP->fx_size == 1
4612 && (fixP->fx_addsy == NULL
4613 || S_IS_DEFINED (fixP->fx_addsy))
4614 && (val == 0 || val == -1))
4615 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4618 /* *fragP has been relaxed to its final size, and now needs to have
4619 the bytes inside it modified to conform to the new size There is UGLY
4623 md_convert_frag_1 (fragS *fragP)
4628 /* Address in object code of the displacement. */
4629 register int object_address = fragP->fr_fix + fragP->fr_address;
4631 /* Address in gas core of the place to store the displacement. */
4632 /* This convinces the native rs6000 compiler to generate the code we
4634 register char *buffer_address = fragP->fr_literal;
4635 buffer_address += fragP->fr_fix;
4636 /* End ibm compiler workaround. */
4638 /* The displacement of the address, from current location. */
4639 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4640 disp = (disp + fragP->fr_offset) - object_address;
4642 switch (fragP->fr_subtype)
4644 case TAB (BRANCHBWL, BYTE):
4645 case TAB (BRABSJUNC, BYTE):
4646 case TAB (BRABSJCOND, BYTE):
4647 case TAB (BRANCHBW, BYTE):
4648 know (issbyte (disp));
4650 as_bad_where (fragP->fr_file, fragP->fr_line,
4651 _("short branch with zero offset: use :w"));
4652 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4653 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4654 fixP->fx_pcrel_adjust = -1;
4656 case TAB (BRANCHBWL, SHORT):
4657 case TAB (BRABSJUNC, SHORT):
4658 case TAB (BRABSJCOND, SHORT):
4659 case TAB (BRANCHBW, SHORT):
4660 fragP->fr_opcode[1] = 0x00;
4661 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4662 1, RELAX_RELOC_PC16);
4665 case TAB (BRANCHBWL, LONG):
4666 fragP->fr_opcode[1] = (char) 0xFF;
4667 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4668 1, RELAX_RELOC_PC32);
4671 case TAB (BRABSJUNC, LONG):
4672 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4674 if (flag_keep_pcrel)
4675 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4676 fragP->fr_opcode[0] = 0x4E;
4677 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4678 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4679 0, RELAX_RELOC_ABS32);
4682 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4684 if (flag_keep_pcrel)
4685 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4686 fragP->fr_opcode[0] = 0x4E;
4687 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4688 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4689 0, RELAX_RELOC_ABS32);
4694 /* This cannot happen, because jbsr and jbra are the only two
4695 unconditional branches. */
4699 case TAB (BRABSJCOND, LONG):
4700 if (flag_keep_pcrel)
4701 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4703 /* Only Bcc 68000 instructions can come here
4704 Change bcc into b!cc/jmp absl long. */
4705 fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
4706 fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
4708 /* JF: these used to be fr_opcode[2,3], but they may be in a
4709 different frag, in which case referring to them is a no-no.
4710 Only fr_opcode[0,1] are guaranteed to work. */
4711 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4712 *buffer_address++ = (char) 0xf9;
4713 fragP->fr_fix += 2; /* Account for jmp instruction. */
4714 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4715 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4718 case TAB (FBRANCH, SHORT):
4719 know ((fragP->fr_opcode[1] & 0x40) == 0);
4720 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4721 1, RELAX_RELOC_PC16);
4724 case TAB (FBRANCH, LONG):
4725 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
4726 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4727 1, RELAX_RELOC_PC32);
4730 case TAB (DBCCLBR, SHORT):
4731 case TAB (DBCCABSJ, SHORT):
4732 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4733 1, RELAX_RELOC_PC16);
4736 case TAB (DBCCLBR, LONG):
4737 /* Only DBcc instructions can come here.
4738 Change dbcc into dbcc/bral.
4739 JF: these used to be fr_opcode[2-7], but that's wrong. */
4740 if (flag_keep_pcrel)
4741 as_fatal (_("Tried to convert DBcc to absolute jump"));
4743 *buffer_address++ = 0x00; /* Branch offset = 4. */
4744 *buffer_address++ = 0x04;
4745 *buffer_address++ = 0x60; /* Put in bra pc+6. */
4746 *buffer_address++ = 0x06;
4747 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4748 *buffer_address++ = (char) 0xff;
4750 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4751 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4755 case TAB (DBCCABSJ, LONG):
4756 /* Only DBcc instructions can come here.
4757 Change dbcc into dbcc/jmp.
4758 JF: these used to be fr_opcode[2-7], but that's wrong. */
4759 if (flag_keep_pcrel)
4760 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4762 *buffer_address++ = 0x00; /* Branch offset = 4. */
4763 *buffer_address++ = 0x04;
4764 *buffer_address++ = 0x60; /* Put in bra pc + 6. */
4765 *buffer_address++ = 0x06;
4766 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4767 *buffer_address++ = (char) 0xf9;
4769 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4770 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4774 case TAB (PCREL1632, SHORT):
4775 fragP->fr_opcode[1] &= ~0x3F;
4776 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4777 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4778 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4781 case TAB (PCREL1632, LONG):
4782 /* Already set to mode 7.3; this indicates: PC indirect with
4783 suppressed index, 32-bit displacement. */
4784 *buffer_address++ = 0x01;
4785 *buffer_address++ = 0x70;
4787 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4788 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4789 fixP->fx_pcrel_adjust = 2;
4792 case TAB (PCINDEX, BYTE):
4793 assert (fragP->fr_fix >= 2);
4794 buffer_address[-2] &= ~1;
4795 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4796 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4797 fixP->fx_pcrel_adjust = 1;
4799 case TAB (PCINDEX, SHORT):
4800 assert (fragP->fr_fix >= 2);
4801 buffer_address[-2] |= 0x1;
4802 buffer_address[-1] = 0x20;
4803 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4804 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4805 fixP->fx_pcrel_adjust = 2;
4808 case TAB (PCINDEX, LONG):
4809 assert (fragP->fr_fix >= 2);
4810 buffer_address[-2] |= 0x1;
4811 buffer_address[-1] = 0x30;
4812 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4813 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4814 fixP->fx_pcrel_adjust = 2;
4817 case TAB (ABSTOPCREL, SHORT):
4818 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4819 1, RELAX_RELOC_PC16);
4822 case TAB (ABSTOPCREL, LONG):
4823 if (flag_keep_pcrel)
4824 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4825 /* The thing to do here is force it to ABSOLUTE LONG, since
4826 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4827 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4829 fragP->fr_opcode[1] &= ~0x3F;
4830 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4831 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4832 0, RELAX_RELOC_ABS32);
4839 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
4840 segT sec ATTRIBUTE_UNUSED,
4843 md_convert_frag_1 (fragP);
4846 /* Force truly undefined symbols to their maximum size, and generally set up
4847 the frag list to be relaxed
4850 md_estimate_size_before_relax (fragS *fragP, segT segment)
4852 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4853 switch (fragP->fr_subtype)
4855 case TAB (BRANCHBWL, SZ_UNDEF):
4856 case TAB (BRABSJUNC, SZ_UNDEF):
4857 case TAB (BRABSJCOND, SZ_UNDEF):
4859 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4860 && relaxable_symbol (fragP->fr_symbol))
4862 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4864 else if (flag_short_refs)
4866 /* Symbol is undefined and we want short ref. */
4867 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4871 /* Symbol is still undefined. Make it LONG. */
4872 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4877 case TAB (BRANCHBW, SZ_UNDEF):
4879 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4880 && relaxable_symbol (fragP->fr_symbol))
4882 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4886 /* Symbol is undefined and we don't have long branches. */
4887 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4892 case TAB (FBRANCH, SZ_UNDEF):
4893 case TAB (DBCCLBR, SZ_UNDEF):
4894 case TAB (DBCCABSJ, SZ_UNDEF):
4895 case TAB (PCREL1632, SZ_UNDEF):
4897 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4898 && relaxable_symbol (fragP->fr_symbol))
4901 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4905 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4910 case TAB (PCINDEX, SZ_UNDEF):
4911 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4912 && relaxable_symbol (fragP->fr_symbol)))
4914 fragP->fr_subtype = TAB (PCINDEX, BYTE);
4918 fragP->fr_subtype = TAB (PCINDEX, LONG);
4922 case TAB (ABSTOPCREL, SZ_UNDEF):
4924 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4925 && relaxable_symbol (fragP->fr_symbol)))
4927 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
4931 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
4940 /* Now that SZ_UNDEF are taken care of, check others. */
4941 switch (fragP->fr_subtype)
4943 case TAB (BRANCHBWL, BYTE):
4944 case TAB (BRABSJUNC, BYTE):
4945 case TAB (BRABSJCOND, BYTE):
4946 case TAB (BRANCHBW, BYTE):
4947 /* We can't do a short jump to the next instruction, so in that
4948 case we force word mode. If the symbol is at the start of a
4949 frag, and it is the next frag with any data in it (usually
4950 this is just the next frag, but assembler listings may
4951 introduce empty frags), we must use word mode. */
4952 if (fragP->fr_symbol)
4956 sym_frag = symbol_get_frag (fragP->fr_symbol);
4957 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
4961 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
4965 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4972 return md_relax_table[fragP->fr_subtype].rlx_length;
4975 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4976 /* the bit-field entries in the relocation_info struct plays hell
4977 with the byte-order problems of cross-assembly. So as a hack,
4978 I added this mach. dependent ri twiddler. Ugly, but it gets
4980 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4981 are symbolnum, most sig. byte first. Last byte is broken up with
4982 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4983 nibble as nuthin. (on Sun 3 at least) */
4984 /* Translate the internal relocation information into target-specific
4988 md_ri_to_chars (char *the_bytes, struct reloc_info_generic *ri)
4991 md_number_to_chars (the_bytes, ri->r_address, 4);
4992 /* Now the fun stuff. */
4993 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
4994 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
4995 the_bytes[6] = ri->r_symbolnum & 0x0ff;
4996 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80)
4997 | ((ri->r_length << 5) & 0x60)
4998 | ((ri->r_extern << 4) & 0x10));
5003 #endif /* OBJ_AOUT or OBJ_BOUT */
5005 #ifndef WORKING_DOT_WORD
5006 int md_short_jump_size = 4;
5007 int md_long_jump_size = 6;
5010 md_create_short_jump (char *ptr, addressT from_addr, addressT to_addr,
5011 fragS *frag ATTRIBUTE_UNUSED,
5012 symbolS *to_symbol ATTRIBUTE_UNUSED)
5016 offset = to_addr - (from_addr + 2);
5018 md_number_to_chars (ptr, (valueT) 0x6000, 2);
5019 md_number_to_chars (ptr + 2, (valueT) offset, 2);
5023 md_create_long_jump (char *ptr, addressT from_addr, addressT to_addr,
5024 fragS *frag, symbolS *to_symbol)
5028 if (!HAVE_LONG_BRANCH (current_architecture))
5030 if (flag_keep_pcrel)
5031 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5032 offset = to_addr - S_GET_VALUE (to_symbol);
5033 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
5034 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5035 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
5040 offset = to_addr - (from_addr + 2);
5041 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
5042 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5048 /* Different values of OK tell what its OK to return. Things that
5049 aren't OK are an error (what a shock, no?)
5052 10: Absolute 1:8 only
5053 20: Absolute 0:7 only
5054 30: absolute 0:15 only
5055 40: Absolute 0:31 only
5056 50: absolute 0:127 only
5057 55: absolute -64:63 only
5058 60: absolute -128:127 only
5059 70: absolute 0:4095 only
5060 80: absolute -1, 1:7 only
5064 get_num (struct m68k_exp *exp, int ok)
5066 if (exp->exp.X_op == O_absent)
5068 /* Do the same thing the VAX asm does. */
5069 op (exp) = O_constant;
5075 as_warn (_("expression out of range: defaulting to 1"));
5079 else if (exp->exp.X_op == O_constant)
5084 if ((valueT) TRUNC (offs (exp)) - 1 > 7)
5086 as_warn (_("expression out of range: defaulting to 1"));
5091 if ((valueT) TRUNC (offs (exp)) > 7)
5095 if ((valueT) TRUNC (offs (exp)) > 15)
5099 if ((valueT) TRUNC (offs (exp)) > 32)
5103 if ((valueT) TRUNC (offs (exp)) > 127)
5107 if ((valueT) SEXT (offs (exp)) + 64 > 127)
5111 if ((valueT) SEXT (offs (exp)) + 128 > 255)
5115 if ((valueT) TRUNC (offs (exp)) > 4095)
5118 as_warn (_("expression out of range: defaulting to 0"));
5123 if ((valueT) TRUNC (offs (exp)) != 0xffffffff
5124 && (valueT) TRUNC (offs (exp)) - 1 > 6)
5126 as_warn (_("expression out of range: defaulting to 1"));
5134 else if (exp->exp.X_op == O_big)
5136 if (offs (exp) <= 0 /* flonum. */
5137 && (ok == 90 /* no bignums */
5138 || (ok > 10 /* Small-int ranges including 0 ok. */
5139 /* If we have a flonum zero, a zero integer should
5140 do as well (e.g., in moveq). */
5141 && generic_floating_point_number.exponent == 0
5142 && generic_floating_point_number.low[0] == 0)))
5144 /* HACK! Turn it into a long. */
5145 LITTLENUM_TYPE words[6];
5147 gen_to_words (words, 2, 8L); /* These numbers are magic! */
5148 op (exp) = O_constant;
5151 offs (exp) = words[1] | (words[0] << 16);
5155 op (exp) = O_constant;
5158 offs (exp) = (ok == 10) ? 1 : 0;
5159 as_warn (_("Can't deal with expression; defaulting to %ld"),
5165 if (ok >= 10 && ok <= 80)
5167 op (exp) = O_constant;
5170 offs (exp) = (ok == 10) ? 1 : 0;
5171 as_warn (_("Can't deal with expression; defaulting to %ld"),
5176 if (exp->size != SIZE_UNSPEC)
5184 if (!isbyte (offs (exp)))
5185 as_warn (_("expression doesn't fit in BYTE"));
5188 if (!isword (offs (exp)))
5189 as_warn (_("expression doesn't fit in WORD"));
5197 /* These are the back-ends for the various machine dependent pseudo-ops. */
5200 s_data1 (int ignore ATTRIBUTE_UNUSED)
5202 subseg_set (data_section, 1);
5203 demand_empty_rest_of_line ();
5207 s_data2 (int ignore ATTRIBUTE_UNUSED)
5209 subseg_set (data_section, 2);
5210 demand_empty_rest_of_line ();
5214 s_bss (int ignore ATTRIBUTE_UNUSED)
5216 /* We don't support putting frags in the BSS segment, we fake it
5217 by marking in_bss, then looking at s_skip for clues. */
5219 subseg_set (bss_section, 0);
5220 demand_empty_rest_of_line ();
5224 s_even (int ignore ATTRIBUTE_UNUSED)
5227 register long temp_fill;
5229 temp = 1; /* JF should be 2? */
5230 temp_fill = get_absolute_expression ();
5231 if (!need_pass_2) /* Never make frag if expect extra pass. */
5232 frag_align (temp, (int) temp_fill, 0);
5233 demand_empty_rest_of_line ();
5234 record_alignment (now_seg, temp);
5238 s_proc (int ignore ATTRIBUTE_UNUSED)
5240 demand_empty_rest_of_line ();
5243 /* Pseudo-ops handled for MRI compatibility. */
5245 /* This function returns non-zero if the argument is a conditional
5246 pseudo-op. This is called when checking whether a pending
5247 alignment is needed. */
5250 m68k_conditional_pseudoop (pseudo_typeS *pop)
5252 return (pop->poc_handler == s_mri_if
5253 || pop->poc_handler == s_mri_else);
5256 /* Handle an MRI style chip specification. */
5265 s = input_line_pointer;
5266 /* We can't use get_symbol_end since the processor names are not proper
5268 while (is_part_of_name (c = *input_line_pointer++))
5270 *--input_line_pointer = 0;
5271 for (i = 0; m68k_cpus[i].name; i++)
5272 if (strcasecmp (s, m68k_cpus[i].name) == 0)
5274 if (!m68k_cpus[i].name)
5276 as_bad (_("%s: unrecognized processor name"), s);
5277 *input_line_pointer = c;
5278 ignore_rest_of_line ();
5281 *input_line_pointer = c;
5283 if (*input_line_pointer == '/')
5284 current_architecture = 0;
5286 current_architecture &= m68881 | m68851;
5287 current_architecture |= m68k_cpus[i].arch & ~(m68881 | m68851);
5288 control_regs = m68k_cpus[i].control_regs;
5290 while (*input_line_pointer == '/')
5292 ++input_line_pointer;
5293 s = input_line_pointer;
5294 /* We can't use get_symbol_end since the processor names are not
5296 while (is_part_of_name (c = *input_line_pointer++))
5298 *--input_line_pointer = 0;
5299 if (strcmp (s, "68881") == 0)
5300 current_architecture |= m68881;
5301 else if (strcmp (s, "68851") == 0)
5302 current_architecture |= m68851;
5303 *input_line_pointer = c;
5307 /* The MRI CHIP pseudo-op. */
5310 s_chip (int ignore ATTRIBUTE_UNUSED)
5316 stop = mri_comment_field (&stopc);
5319 mri_comment_end (stop, stopc);
5320 demand_empty_rest_of_line ();
5323 /* The MRI FOPT pseudo-op. */
5326 s_fopt (int ignore ATTRIBUTE_UNUSED)
5330 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5334 input_line_pointer += 3;
5335 temp = get_absolute_expression ();
5336 if (temp < 0 || temp > 7)
5337 as_bad (_("bad coprocessor id"));
5339 m68k_float_copnum = COP0 + temp;
5343 as_bad (_("unrecognized fopt option"));
5344 ignore_rest_of_line ();
5348 demand_empty_rest_of_line ();
5351 /* The structure used to handle the MRI OPT pseudo-op. */
5355 /* The name of the option. */
5358 /* If this is not NULL, just call this function. The first argument
5359 is the ARG field of this structure, the second argument is
5360 whether the option was negated. */
5361 void (*pfn) (int arg, int on);
5363 /* If this is not NULL, and the PFN field is NULL, set the variable
5364 this points to. Set it to the ARG field if the option was not
5365 negated, and the NOTARG field otherwise. */
5368 /* The value to pass to PFN or to assign to *PVAR. */
5371 /* The value to assign to *PVAR if the option is negated. If PFN is
5372 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5373 the option may not be negated. */
5377 /* The table used to handle the MRI OPT pseudo-op. */
5379 static void skip_to_comma (int, int);
5380 static void opt_nest (int, int);
5381 static void opt_chip (int, int);
5382 static void opt_list (int, int);
5383 static void opt_list_symbols (int, int);
5385 static const struct opt_action opt_table[] =
5387 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5389 /* We do relaxing, so there is little use for these options. */
5390 { "b", 0, 0, 0, 0 },
5391 { "brs", 0, 0, 0, 0 },
5392 { "brb", 0, 0, 0, 0 },
5393 { "brl", 0, 0, 0, 0 },
5394 { "brw", 0, 0, 0, 0 },
5396 { "c", 0, 0, 0, 0 },
5397 { "cex", 0, 0, 0, 0 },
5398 { "case", 0, &symbols_case_sensitive, 1, 0 },
5399 { "cl", 0, 0, 0, 0 },
5400 { "cre", 0, 0, 0, 0 },
5401 { "d", 0, &flag_keep_locals, 1, 0 },
5402 { "e", 0, 0, 0, 0 },
5403 { "f", 0, &flag_short_refs, 1, 0 },
5404 { "frs", 0, &flag_short_refs, 1, 0 },
5405 { "frl", 0, &flag_short_refs, 0, 1 },
5406 { "g", 0, 0, 0, 0 },
5407 { "i", 0, 0, 0, 0 },
5408 { "m", 0, 0, 0, 0 },
5409 { "mex", 0, 0, 0, 0 },
5410 { "mc", 0, 0, 0, 0 },
5411 { "md", 0, 0, 0, 0 },
5412 { "nest", opt_nest, 0, 0, 0 },
5413 { "next", skip_to_comma, 0, 0, 0 },
5414 { "o", 0, 0, 0, 0 },
5415 { "old", 0, 0, 0, 0 },
5416 { "op", skip_to_comma, 0, 0, 0 },
5417 { "pco", 0, 0, 0, 0 },
5418 { "p", opt_chip, 0, 0, 0 },
5419 { "pcr", 0, 0, 0, 0 },
5420 { "pcs", 0, 0, 0, 0 },
5421 { "r", 0, 0, 0, 0 },
5422 { "quick", 0, &m68k_quick, 1, 0 },
5423 { "rel32", 0, &m68k_rel32, 1, 0 },
5424 { "s", opt_list, 0, 0, 0 },
5425 { "t", opt_list_symbols, 0, 0, 0 },
5426 { "w", 0, &flag_no_warnings, 0, 1 },
5430 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5432 /* The MRI OPT pseudo-op. */
5435 s_opt (int ignore ATTRIBUTE_UNUSED)
5443 const struct opt_action *o;
5448 if (*input_line_pointer == '-')
5450 ++input_line_pointer;
5453 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5455 input_line_pointer += 2;
5459 s = input_line_pointer;
5460 c = get_symbol_end ();
5462 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5464 if (strcasecmp (s, o->name) == 0)
5468 /* Restore input_line_pointer now in case the option
5470 *input_line_pointer = c;
5471 (*o->pfn) (o->arg, t);
5473 else if (o->pvar != NULL)
5475 if (! t && o->arg == o->notarg)
5476 as_bad (_("option `%s' may not be negated"), s);
5477 *input_line_pointer = c;
5478 *o->pvar = t ? o->arg : o->notarg;
5481 *input_line_pointer = c;
5487 as_bad (_("option `%s' not recognized"), s);
5488 *input_line_pointer = c;
5491 while (*input_line_pointer++ == ',');
5493 /* Move back to terminating character. */
5494 --input_line_pointer;
5495 demand_empty_rest_of_line ();
5498 /* Skip ahead to a comma. This is used for OPT options which we do
5499 not support and which take arguments. */
5502 skip_to_comma (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5504 while (*input_line_pointer != ','
5505 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5506 ++input_line_pointer;
5509 /* Handle the OPT NEST=depth option. */
5512 opt_nest (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5514 if (*input_line_pointer != '=')
5516 as_bad (_("bad format of OPT NEST=depth"));
5520 ++input_line_pointer;
5521 max_macro_nest = get_absolute_expression ();
5524 /* Handle the OPT P=chip option. */
5527 opt_chip (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5529 if (*input_line_pointer != '=')
5531 /* This is just OPT P, which we do not support. */
5535 ++input_line_pointer;
5539 /* Handle the OPT S option. */
5542 opt_list (int arg ATTRIBUTE_UNUSED, int on)
5547 /* Handle the OPT T option. */
5550 opt_list_symbols (int arg ATTRIBUTE_UNUSED, int on)
5553 listing |= LISTING_SYMBOLS;
5555 listing &= ~LISTING_SYMBOLS;
5558 /* Handle the MRI REG pseudo-op. */
5561 s_reg (int ignore ATTRIBUTE_UNUSED)
5570 if (line_label == NULL)
5572 as_bad (_("missing label"));
5573 ignore_rest_of_line ();
5578 stop = mri_comment_field (&stopc);
5582 s = input_line_pointer;
5583 while (ISALNUM (*input_line_pointer)
5584 #ifdef REGISTER_PREFIX
5585 || *input_line_pointer == REGISTER_PREFIX
5587 || *input_line_pointer == '/'
5588 || *input_line_pointer == '-')
5589 ++input_line_pointer;
5590 c = *input_line_pointer;
5591 *input_line_pointer = '\0';
5593 if (m68k_ip_op (s, &rop) != 0)
5595 if (rop.error == NULL)
5596 as_bad (_("bad register list"));
5598 as_bad (_("bad register list: %s"), rop.error);
5599 *input_line_pointer = c;
5600 ignore_rest_of_line ();
5604 *input_line_pointer = c;
5606 if (rop.mode == REGLST)
5608 else if (rop.mode == DREG)
5609 mask = 1 << (rop.reg - DATA0);
5610 else if (rop.mode == AREG)
5611 mask = 1 << (rop.reg - ADDR0 + 8);
5612 else if (rop.mode == FPREG)
5613 mask = 1 << (rop.reg - FP0 + 16);
5614 else if (rop.mode == CONTROL
5617 else if (rop.mode == CONTROL
5620 else if (rop.mode == CONTROL
5625 as_bad (_("bad register list"));
5626 ignore_rest_of_line ();
5630 S_SET_SEGMENT (line_label, reg_section);
5631 S_SET_VALUE (line_label, ~mask);
5632 symbol_set_frag (line_label, &zero_address_frag);
5635 mri_comment_end (stop, stopc);
5637 demand_empty_rest_of_line ();
5640 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5644 struct save_opts *next;
5646 int symbols_case_sensitive;
5650 const enum m68k_register *control_regs;
5655 /* FIXME: We don't save OPT S. */
5658 /* This variable holds the stack of saved options. */
5660 static struct save_opts *save_stack;
5662 /* The MRI SAVE pseudo-op. */
5665 s_save (int ignore ATTRIBUTE_UNUSED)
5667 struct save_opts *s;
5669 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5670 s->abspcadd = m68k_abspcadd;
5671 s->symbols_case_sensitive = symbols_case_sensitive;
5672 s->keep_locals = flag_keep_locals;
5673 s->short_refs = flag_short_refs;
5674 s->architecture = current_architecture;
5675 s->control_regs = control_regs;
5676 s->quick = m68k_quick;
5677 s->rel32 = m68k_rel32;
5678 s->listing = listing;
5679 s->no_warnings = flag_no_warnings;
5681 s->next = save_stack;
5684 demand_empty_rest_of_line ();
5687 /* The MRI RESTORE pseudo-op. */
5690 s_restore (int ignore ATTRIBUTE_UNUSED)
5692 struct save_opts *s;
5694 if (save_stack == NULL)
5696 as_bad (_("restore without save"));
5697 ignore_rest_of_line ();
5702 save_stack = s->next;
5704 m68k_abspcadd = s->abspcadd;
5705 symbols_case_sensitive = s->symbols_case_sensitive;
5706 flag_keep_locals = s->keep_locals;
5707 flag_short_refs = s->short_refs;
5708 current_architecture = s->architecture;
5709 control_regs = s->control_regs;
5710 m68k_quick = s->quick;
5711 m68k_rel32 = s->rel32;
5712 listing = s->listing;
5713 flag_no_warnings = s->no_warnings;
5717 demand_empty_rest_of_line ();
5720 /* Types of MRI structured control directives. */
5722 enum mri_control_type
5730 /* This structure is used to stack the MRI structured control
5733 struct mri_control_info
5735 /* The directive within which this one is enclosed. */
5736 struct mri_control_info *outer;
5738 /* The type of directive. */
5739 enum mri_control_type type;
5741 /* Whether an ELSE has been in an IF. */
5744 /* The add or sub statement at the end of a FOR. */
5747 /* The label of the top of a FOR or REPEAT loop. */
5750 /* The label to jump to for the next iteration, or the else
5751 expression of a conditional. */
5754 /* The label to jump to to break out of the loop, or the label past
5755 the end of a conditional. */
5759 /* The stack of MRI structured control directives. */
5761 static struct mri_control_info *mri_control_stack;
5763 /* The current MRI structured control directive index number, used to
5764 generate label names. */
5766 static int mri_control_index;
5768 /* Assemble an instruction for an MRI structured control directive. */
5771 mri_assemble (char *str)
5775 /* md_assemble expects the opcode to be in lower case. */
5776 for (s = str; *s != ' ' && *s != '\0'; s++)
5782 /* Generate a new MRI label structured control directive label name. */
5785 mri_control_label (void)
5789 n = (char *) xmalloc (20);
5790 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5791 ++mri_control_index;
5795 /* Create a new MRI structured control directive. */
5797 static struct mri_control_info *
5798 push_mri_control (enum mri_control_type type)
5800 struct mri_control_info *n;
5802 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5806 if (type == mri_if || type == mri_while)
5809 n->top = mri_control_label ();
5810 n->next = mri_control_label ();
5811 n->bottom = mri_control_label ();
5813 n->outer = mri_control_stack;
5814 mri_control_stack = n;
5819 /* Pop off the stack of MRI structured control directives. */
5822 pop_mri_control (void)
5824 struct mri_control_info *n;
5826 n = mri_control_stack;
5827 mri_control_stack = n->outer;
5835 /* Recognize a condition code in an MRI structured control expression. */
5838 parse_mri_condition (int *pcc)
5842 know (*input_line_pointer == '<');
5844 ++input_line_pointer;
5845 c1 = *input_line_pointer++;
5846 c2 = *input_line_pointer++;
5848 if (*input_line_pointer != '>')
5850 as_bad (_("syntax error in structured control directive"));
5854 ++input_line_pointer;
5860 *pcc = (c1 << 8) | c2;
5865 /* Parse a single operand in an MRI structured control expression. */
5868 parse_mri_control_operand (int *pcc, char **leftstart, char **leftstop,
5869 char **rightstart, char **rightstop)
5881 if (*input_line_pointer == '<')
5883 /* It's just a condition code. */
5884 return parse_mri_condition (pcc);
5887 /* Look ahead for the condition code. */
5888 for (s = input_line_pointer; *s != '\0'; ++s)
5890 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
5895 as_bad (_("missing condition code in structured control directive"));
5899 *leftstart = input_line_pointer;
5901 if (*leftstop > *leftstart
5902 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
5905 input_line_pointer = s;
5906 if (! parse_mri_condition (pcc))
5909 /* Look ahead for AND or OR or end of line. */
5910 for (s = input_line_pointer; *s != '\0'; ++s)
5912 /* We must make sure we don't misinterpret AND/OR at the end of labels!
5913 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
5915 if ((s == input_line_pointer
5918 && ((strncasecmp (s, "AND", 3) == 0
5919 && (s[3] == '.' || ! is_part_of_name (s[3])))
5920 || (strncasecmp (s, "OR", 2) == 0
5921 && (s[2] == '.' || ! is_part_of_name (s[2])))))
5925 *rightstart = input_line_pointer;
5927 if (*rightstop > *rightstart
5928 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
5931 input_line_pointer = s;
5936 #define MCC(b1, b2) (((b1) << 8) | (b2))
5938 /* Swap the sense of a condition. This changes the condition so that
5939 it generates the same result when the operands are swapped. */
5942 swap_mri_condition (int cc)
5946 case MCC ('h', 'i'): return MCC ('c', 's');
5947 case MCC ('l', 's'): return MCC ('c', 'c');
5948 /* <HS> is an alias for <CC>. */
5949 case MCC ('h', 's'):
5950 case MCC ('c', 'c'): return MCC ('l', 's');
5951 /* <LO> is an alias for <CS>. */
5952 case MCC ('l', 'o'):
5953 case MCC ('c', 's'): return MCC ('h', 'i');
5954 case MCC ('p', 'l'): return MCC ('m', 'i');
5955 case MCC ('m', 'i'): return MCC ('p', 'l');
5956 case MCC ('g', 'e'): return MCC ('l', 'e');
5957 case MCC ('l', 't'): return MCC ('g', 't');
5958 case MCC ('g', 't'): return MCC ('l', 't');
5959 case MCC ('l', 'e'): return MCC ('g', 'e');
5960 /* Issue a warning for conditions we can not swap. */
5961 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
5962 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
5963 case MCC ('v', 'c'):
5964 case MCC ('v', 's'):
5966 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
5967 (char) (cc >> 8), (char) (cc));
5973 /* Reverse the sense of a condition. */
5976 reverse_mri_condition (int cc)
5980 case MCC ('h', 'i'): return MCC ('l', 's');
5981 case MCC ('l', 's'): return MCC ('h', 'i');
5982 /* <HS> is an alias for <CC> */
5983 case MCC ('h', 's'): return MCC ('l', 'o');
5984 case MCC ('c', 'c'): return MCC ('c', 's');
5985 /* <LO> is an alias for <CS> */
5986 case MCC ('l', 'o'): return MCC ('h', 's');
5987 case MCC ('c', 's'): return MCC ('c', 'c');
5988 case MCC ('n', 'e'): return MCC ('e', 'q');
5989 case MCC ('e', 'q'): return MCC ('n', 'e');
5990 case MCC ('v', 'c'): return MCC ('v', 's');
5991 case MCC ('v', 's'): return MCC ('v', 'c');
5992 case MCC ('p', 'l'): return MCC ('m', 'i');
5993 case MCC ('m', 'i'): return MCC ('p', 'l');
5994 case MCC ('g', 'e'): return MCC ('l', 't');
5995 case MCC ('l', 't'): return MCC ('g', 'e');
5996 case MCC ('g', 't'): return MCC ('l', 'e');
5997 case MCC ('l', 'e'): return MCC ('g', 't');
6002 /* Build an MRI structured control expression. This generates test
6003 and branch instructions. It goes to TRUELAB if the condition is
6004 true, and to FALSELAB if the condition is false. Exactly one of
6005 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6006 is the size qualifier for the expression. EXTENT is the size to
6007 use for the branch. */
6010 build_mri_control_operand (int qual, int cc, char *leftstart, char *leftstop,
6011 char *rightstart, char *rightstop,
6012 const char *truelab, const char *falselab,
6018 if (leftstart != NULL)
6020 struct m68k_op leftop, rightop;
6023 /* Swap the compare operands, if necessary, to produce a legal
6024 m68k compare instruction. Comparing a register operand with
6025 a non-register operand requires the register to be on the
6026 right (cmp, cmpa). Comparing an immediate value with
6027 anything requires the immediate value to be on the left
6032 (void) m68k_ip_op (leftstart, &leftop);
6037 (void) m68k_ip_op (rightstart, &rightop);
6040 if (rightop.mode == IMMED
6041 || ((leftop.mode == DREG || leftop.mode == AREG)
6042 && (rightop.mode != DREG && rightop.mode != AREG)))
6046 /* Correct conditional handling:
6047 if #1 <lt> d0 then ;means if (1 < d0)
6053 cmp #1,d0 if we do *not* swap the operands
6054 bgt true we need the swapped condition!
6061 leftstart = rightstart;
6064 leftstop = rightstop;
6069 cc = swap_mri_condition (cc);
6073 if (truelab == NULL)
6075 cc = reverse_mri_condition (cc);
6079 if (leftstart != NULL)
6081 buf = (char *) xmalloc (20
6082 + (leftstop - leftstart)
6083 + (rightstop - rightstart));
6089 *s++ = TOLOWER (qual);
6091 memcpy (s, leftstart, leftstop - leftstart);
6092 s += leftstop - leftstart;
6094 memcpy (s, rightstart, rightstop - rightstart);
6095 s += rightstop - rightstart;
6101 buf = (char *) xmalloc (20 + strlen (truelab));
6107 *s++ = TOLOWER (extent);
6109 strcpy (s, truelab);
6114 /* Parse an MRI structured control expression. This generates test
6115 and branch instructions. STOP is where the expression ends. It
6116 goes to TRUELAB if the condition is true, and to FALSELAB if the
6117 condition is false. Exactly one of TRUELAB and FALSELAB will be
6118 NULL, meaning to fall through. QUAL is the size qualifier for the
6119 expression. EXTENT is the size to use for the branch. */
6122 parse_mri_control_expression (char *stop, int qual, const char *truelab,
6123 const char *falselab, int extent)
6135 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6136 &rightstart, &rightstop))
6142 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
6146 if (falselab != NULL)
6149 flab = mri_control_label ();
6151 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6152 rightstop, (const char *) NULL, flab, extent);
6154 input_line_pointer += 3;
6155 if (*input_line_pointer != '.'
6156 || input_line_pointer[1] == '\0')
6160 qual = input_line_pointer[1];
6161 input_line_pointer += 2;
6164 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6165 &rightstart, &rightstop))
6171 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6172 rightstop, truelab, falselab, extent);
6174 if (falselab == NULL)
6177 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6181 if (truelab != NULL)
6184 tlab = mri_control_label ();
6186 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6187 rightstop, tlab, (const char *) NULL, extent);
6189 input_line_pointer += 2;
6190 if (*input_line_pointer != '.'
6191 || input_line_pointer[1] == '\0')
6195 qual = input_line_pointer[1];
6196 input_line_pointer += 2;
6199 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6200 &rightstart, &rightstop))
6206 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6207 rightstop, truelab, falselab, extent);
6209 if (truelab == NULL)
6214 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6215 rightstop, truelab, falselab, extent);
6219 if (input_line_pointer != stop)
6220 as_bad (_("syntax error in structured control directive"));
6223 /* Handle the MRI IF pseudo-op. This may be a structured control
6224 directive, or it may be a regular assembler conditional, depending
6232 struct mri_control_info *n;
6234 /* A structured control directive must end with THEN with an
6235 optional qualifier. */
6236 s = input_line_pointer;
6237 /* We only accept '*' as introduction of comments if preceded by white space
6238 or at first column of a line (I think this can't actually happen here?)
6239 This is important when assembling:
6240 if d0 <ne> 12(a0,d0*2) then
6241 if d0 <ne> #CONST*20 then. */
6242 while (! (is_end_of_line[(unsigned char) *s]
6245 && (s == input_line_pointer
6247 || *(s-1) == '\t'))))
6250 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6253 if (s - input_line_pointer > 1
6257 if (s - input_line_pointer < 3
6258 || strncasecmp (s - 3, "THEN", 4) != 0)
6262 as_bad (_("missing then"));
6263 ignore_rest_of_line ();
6267 /* It's a conditional. */
6272 /* Since this might be a conditional if, this pseudo-op will be
6273 called even if we are supported to be ignoring input. Double
6274 check now. Clobber *input_line_pointer so that ignore_input
6275 thinks that this is not a special pseudo-op. */
6276 c = *input_line_pointer;
6277 *input_line_pointer = 0;
6278 if (ignore_input ())
6280 *input_line_pointer = c;
6281 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6282 ++input_line_pointer;
6283 demand_empty_rest_of_line ();
6286 *input_line_pointer = c;
6288 n = push_mri_control (mri_if);
6290 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6291 n->next, s[1] == '.' ? s[2] : '\0');
6294 input_line_pointer = s + 3;
6296 input_line_pointer = s + 1;
6300 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6301 ++input_line_pointer;
6304 demand_empty_rest_of_line ();
6307 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6308 structured IF, associate the ELSE with the IF. Otherwise, assume
6309 it is a conditional else. */
6312 s_mri_else (int qual)
6319 && (mri_control_stack == NULL
6320 || mri_control_stack->type != mri_if
6321 || mri_control_stack->else_seen))
6327 c = *input_line_pointer;
6328 *input_line_pointer = 0;
6329 if (ignore_input ())
6331 *input_line_pointer = c;
6332 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6333 ++input_line_pointer;
6334 demand_empty_rest_of_line ();
6337 *input_line_pointer = c;
6339 if (mri_control_stack == NULL
6340 || mri_control_stack->type != mri_if
6341 || mri_control_stack->else_seen)
6343 as_bad (_("else without matching if"));
6344 ignore_rest_of_line ();
6348 mri_control_stack->else_seen = 1;
6350 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6351 q[0] = TOLOWER (qual);
6353 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6357 colon (mri_control_stack->next);
6361 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6362 ++input_line_pointer;
6365 demand_empty_rest_of_line ();
6368 /* Handle the MRI ENDI pseudo-op. */
6371 s_mri_endi (int ignore ATTRIBUTE_UNUSED)
6373 if (mri_control_stack == NULL
6374 || mri_control_stack->type != mri_if)
6376 as_bad (_("endi without matching if"));
6377 ignore_rest_of_line ();
6381 /* ignore_input will not return true for ENDI, so we don't need to
6382 worry about checking it again here. */
6384 if (! mri_control_stack->else_seen)
6385 colon (mri_control_stack->next);
6386 colon (mri_control_stack->bottom);
6392 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6393 ++input_line_pointer;
6396 demand_empty_rest_of_line ();
6399 /* Handle the MRI BREAK pseudo-op. */
6402 s_mri_break (int extent)
6404 struct mri_control_info *n;
6408 n = mri_control_stack;
6410 && n->type != mri_for
6411 && n->type != mri_repeat
6412 && n->type != mri_while)
6416 as_bad (_("break outside of structured loop"));
6417 ignore_rest_of_line ();
6421 buf = (char *) xmalloc (20 + strlen (n->bottom));
6422 ex[0] = TOLOWER (extent);
6424 sprintf (buf, "bra%s %s", ex, n->bottom);
6430 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6431 ++input_line_pointer;
6434 demand_empty_rest_of_line ();
6437 /* Handle the MRI NEXT pseudo-op. */
6440 s_mri_next (int extent)
6442 struct mri_control_info *n;
6446 n = mri_control_stack;
6448 && n->type != mri_for
6449 && n->type != mri_repeat
6450 && n->type != mri_while)
6454 as_bad (_("next outside of structured loop"));
6455 ignore_rest_of_line ();
6459 buf = (char *) xmalloc (20 + strlen (n->next));
6460 ex[0] = TOLOWER (extent);
6462 sprintf (buf, "bra%s %s", ex, n->next);
6468 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6469 ++input_line_pointer;
6472 demand_empty_rest_of_line ();
6475 /* Handle the MRI FOR pseudo-op. */
6478 s_mri_for (int qual)
6480 const char *varstart, *varstop;
6481 const char *initstart, *initstop;
6482 const char *endstart, *endstop;
6483 const char *bystart, *bystop;
6487 struct mri_control_info *n;
6493 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6497 varstart = input_line_pointer;
6499 /* Look for the '='. */
6500 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6501 && *input_line_pointer != '=')
6502 ++input_line_pointer;
6503 if (*input_line_pointer != '=')
6505 as_bad (_("missing ="));
6506 ignore_rest_of_line ();
6510 varstop = input_line_pointer;
6511 if (varstop > varstart
6512 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6515 ++input_line_pointer;
6517 initstart = input_line_pointer;
6519 /* Look for TO or DOWNTO. */
6522 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6524 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6525 && ! is_part_of_name (input_line_pointer[2]))
6527 initstop = input_line_pointer;
6528 input_line_pointer += 2;
6531 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6532 && ! is_part_of_name (input_line_pointer[6]))
6534 initstop = input_line_pointer;
6536 input_line_pointer += 6;
6539 ++input_line_pointer;
6541 if (initstop == NULL)
6543 as_bad (_("missing to or downto"));
6544 ignore_rest_of_line ();
6547 if (initstop > initstart
6548 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6552 endstart = input_line_pointer;
6554 /* Look for BY or DO. */
6557 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6559 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6560 && ! is_part_of_name (input_line_pointer[2]))
6562 endstop = input_line_pointer;
6564 input_line_pointer += 2;
6567 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6568 && (input_line_pointer[2] == '.'
6569 || ! is_part_of_name (input_line_pointer[2])))
6571 endstop = input_line_pointer;
6572 input_line_pointer += 2;
6575 ++input_line_pointer;
6577 if (endstop == NULL)
6579 as_bad (_("missing do"));
6580 ignore_rest_of_line ();
6583 if (endstop > endstart
6584 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6590 bystop = bystart + 2;
6595 bystart = input_line_pointer;
6599 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6601 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6602 && (input_line_pointer[2] == '.'
6603 || ! is_part_of_name (input_line_pointer[2])))
6605 bystop = input_line_pointer;
6606 input_line_pointer += 2;
6609 ++input_line_pointer;
6613 as_bad (_("missing do"));
6614 ignore_rest_of_line ();
6617 if (bystop > bystart
6618 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6622 if (*input_line_pointer != '.')
6626 extent = input_line_pointer[1];
6627 input_line_pointer += 2;
6630 /* We have fully parsed the FOR operands. Now build the loop. */
6631 n = push_mri_control (mri_for);
6633 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6635 /* Move init,var. */
6642 *s++ = TOLOWER (qual);
6644 memcpy (s, initstart, initstop - initstart);
6645 s += initstop - initstart;
6647 memcpy (s, varstart, varstop - varstart);
6648 s += varstop - varstart;
6660 *s++ = TOLOWER (qual);
6662 memcpy (s, endstart, endstop - endstart);
6663 s += endstop - endstart;
6665 memcpy (s, varstart, varstop - varstart);
6666 s += varstop - varstart;
6671 ex[0] = TOLOWER (extent);
6674 sprintf (buf, "blt%s %s", ex, n->bottom);
6676 sprintf (buf, "bgt%s %s", ex, n->bottom);
6679 /* Put together the add or sub instruction used by ENDF. */
6687 *s++ = TOLOWER (qual);
6689 memcpy (s, bystart, bystop - bystart);
6690 s += bystop - bystart;
6692 memcpy (s, varstart, varstop - varstart);
6693 s += varstop - varstart;
6699 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6700 ++input_line_pointer;
6703 demand_empty_rest_of_line ();
6706 /* Handle the MRI ENDF pseudo-op. */
6709 s_mri_endf (int ignore ATTRIBUTE_UNUSED)
6711 if (mri_control_stack == NULL
6712 || mri_control_stack->type != mri_for)
6714 as_bad (_("endf without for"));
6715 ignore_rest_of_line ();
6719 colon (mri_control_stack->next);
6721 mri_assemble (mri_control_stack->incr);
6723 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6724 mri_assemble (mri_control_stack->incr);
6726 free (mri_control_stack->incr);
6728 colon (mri_control_stack->bottom);
6734 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6735 ++input_line_pointer;
6738 demand_empty_rest_of_line ();
6741 /* Handle the MRI REPEAT pseudo-op. */
6744 s_mri_repeat (int ignore ATTRIBUTE_UNUSED)
6746 struct mri_control_info *n;
6748 n = push_mri_control (mri_repeat);
6752 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6753 ++input_line_pointer;
6755 demand_empty_rest_of_line ();
6758 /* Handle the MRI UNTIL pseudo-op. */
6761 s_mri_until (int qual)
6765 if (mri_control_stack == NULL
6766 || mri_control_stack->type != mri_repeat)
6768 as_bad (_("until without repeat"));
6769 ignore_rest_of_line ();
6773 colon (mri_control_stack->next);
6775 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6778 parse_mri_control_expression (s, qual, (const char *) NULL,
6779 mri_control_stack->top, '\0');
6781 colon (mri_control_stack->bottom);
6783 input_line_pointer = s;
6789 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6790 ++input_line_pointer;
6793 demand_empty_rest_of_line ();
6796 /* Handle the MRI WHILE pseudo-op. */
6799 s_mri_while (int qual)
6803 struct mri_control_info *n;
6805 s = input_line_pointer;
6806 /* We only accept '*' as introduction of comments if preceded by white space
6807 or at first column of a line (I think this can't actually happen here?)
6808 This is important when assembling:
6809 while d0 <ne> 12(a0,d0*2) do
6810 while d0 <ne> #CONST*20 do. */
6811 while (! (is_end_of_line[(unsigned char) *s]
6814 && (s == input_line_pointer
6816 || *(s-1) == '\t'))))
6819 while (*s == ' ' || *s == '\t')
6821 if (s - input_line_pointer > 1
6824 if (s - input_line_pointer < 2
6825 || strncasecmp (s - 1, "DO", 2) != 0)
6827 as_bad (_("missing do"));
6828 ignore_rest_of_line ();
6832 n = push_mri_control (mri_while);
6836 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6837 s[1] == '.' ? s[2] : '\0');
6839 input_line_pointer = s + 1;
6840 if (*input_line_pointer == '.')
6841 input_line_pointer += 2;
6845 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6846 ++input_line_pointer;
6849 demand_empty_rest_of_line ();
6852 /* Handle the MRI ENDW pseudo-op. */
6855 s_mri_endw (int ignore ATTRIBUTE_UNUSED)
6859 if (mri_control_stack == NULL
6860 || mri_control_stack->type != mri_while)
6862 as_bad (_("endw without while"));
6863 ignore_rest_of_line ();
6867 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
6868 sprintf (buf, "bra %s", mri_control_stack->next);
6872 colon (mri_control_stack->bottom);
6878 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6879 ++input_line_pointer;
6882 demand_empty_rest_of_line ();
6885 /* Parse a .cpu directive. */
6888 s_m68k_cpu (int ignored ATTRIBUTE_UNUSED)
6895 as_bad (_("already assembled instructions"));
6896 ignore_rest_of_line ();
6900 name = input_line_pointer;
6901 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
6902 input_line_pointer++;
6903 saved_char = *input_line_pointer;
6904 *input_line_pointer = 0;
6906 m68k_set_cpu (name, 1, 0);
6908 *input_line_pointer = saved_char;
6909 demand_empty_rest_of_line ();
6913 /* Parse a .arch directive. */
6916 s_m68k_arch (int ignored ATTRIBUTE_UNUSED)
6923 as_bad (_("already assembled instructions"));
6924 ignore_rest_of_line ();
6928 name = input_line_pointer;
6929 while (*input_line_pointer && *input_line_pointer != ','
6930 && !ISSPACE (*input_line_pointer))
6931 input_line_pointer++;
6932 saved_char = *input_line_pointer;
6933 *input_line_pointer = 0;
6935 if (m68k_set_arch (name, 1, 0))
6937 /* Scan extensions. */
6940 *input_line_pointer++ = saved_char;
6941 if (!*input_line_pointer || ISSPACE (*input_line_pointer))
6943 name = input_line_pointer;
6944 while (*input_line_pointer && *input_line_pointer != ','
6945 && !ISSPACE (*input_line_pointer))
6946 input_line_pointer++;
6947 saved_char = *input_line_pointer;
6948 *input_line_pointer = 0;
6950 while (m68k_set_extension (name, 1, 0));
6953 *input_line_pointer = saved_char;
6954 demand_empty_rest_of_line ();
6958 /* Lookup a cpu name in TABLE and return the slot found. Return NULL
6959 if none is found, the caller is responsible for emitting an error
6960 message. If ALLOW_M is non-zero, we allow an initial 'm' on the
6961 cpu name, if it begins with a '6' (possibly skipping an intervening
6962 'c'. We also allow a 'c' in the same place. if NEGATED is
6963 non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
6964 the option is indeed negated. */
6966 static const struct m68k_cpu *
6967 m68k_lookup_cpu (const char *arg, const struct m68k_cpu *table,
6968 int allow_m, int *negated)
6970 /* allow negated value? */
6975 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
6982 /* Remove 'm' or 'mc' prefix from 68k variants. */
6989 else if (arg[1] == 'c' && arg[2] == '6')
6993 else if (arg[0] == 'c' && arg[1] == '6')
6996 for (; table->name; table++)
6997 if (!strcmp (arg, table->name))
6999 if (table->alias < -1 || table->alias > 1)
7000 as_bad (_("`%s' is deprecated, use `%s'"),
7001 table->name, table[table->alias < 0 ? 1 : -1].name);
7007 /* Set the cpu, issuing errors if it is unrecognized, or invalid */
7010 m68k_set_cpu (char const *name, int allow_m, int silent)
7012 const struct m68k_cpu *cpu;
7014 cpu = m68k_lookup_cpu (name, m68k_cpus, allow_m, NULL);
7019 as_bad (_("cpu `%s' unrecognized"), name);
7023 if (selected_cpu && selected_cpu != cpu)
7025 as_bad (_("already selected `%s' processor"),
7026 selected_cpu->name);
7033 /* Set the architecture, issuing errors if it is unrecognized, or invalid */
7036 m68k_set_arch (char const *name, int allow_m, int silent)
7038 const struct m68k_cpu *arch;
7040 arch = m68k_lookup_cpu (name, m68k_archs, allow_m, NULL);
7045 as_bad (_("architecture `%s' unrecognized"), name);
7049 if (selected_arch && selected_arch != arch)
7051 as_bad (_("already selected `%s' architecture"),
7052 selected_arch->name);
7056 selected_arch = arch;
7060 /* Set the architecture extension, issuing errors if it is
7061 unrecognized, or invalid */
7064 m68k_set_extension (char const *name, int allow_m, int silent)
7067 const struct m68k_cpu *ext;
7069 ext = m68k_lookup_cpu (name, m68k_extensions, allow_m, &negated);
7074 as_bad (_("extension `%s' unrecognized"), name);
7079 not_current_architecture |= ext->arch;
7081 current_architecture |= ext->arch;
7086 Invocation line includes a switch not recognized by the base assembler.
7090 const char *md_shortopts = "lSA:m:kQ:V";
7092 const char *md_shortopts = "lSA:m:k";
7095 struct option md_longopts[] = {
7096 #define OPTION_PIC (OPTION_MD_BASE)
7097 {"pic", no_argument, NULL, OPTION_PIC},
7098 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7099 {"register-prefix-optional", no_argument, NULL,
7100 OPTION_REGISTER_PREFIX_OPTIONAL},
7101 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7102 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
7103 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7104 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
7105 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7106 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
7107 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7108 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
7109 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7110 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
7111 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7112 {"pcrel", no_argument, NULL, OPTION_PCREL},
7113 {NULL, no_argument, NULL, 0}
7115 size_t md_longopts_size = sizeof (md_longopts);
7118 md_parse_option (int c, char *arg)
7122 case 'l': /* -l means keep external to 2 bit offset
7123 rather than 16 bit one. */
7124 flag_short_refs = 1;
7127 case 'S': /* -S means that jbsr's always turn into
7129 flag_long_jumps = 1;
7132 case OPTION_PCREL: /* --pcrel means never turn PC-relative
7133 branches into absolute jumps. */
7134 flag_keep_pcrel = 1;
7140 break; /* -pic, Position Independent Code. */
7142 case OPTION_REGISTER_PREFIX_OPTIONAL:
7143 flag_reg_prefix_optional = 1;
7144 reg_prefix_optional_seen = 1;
7147 /* -V: SVR4 argument to print version ID. */
7149 print_version_id ();
7152 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7153 should be emitted or not. FIXME: Not implemented. */
7157 case OPTION_BITWISE_OR:
7162 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
7164 for (s = m68k_comment_chars; *s != '\0'; s++)
7168 m68k_comment_chars = n;
7172 case OPTION_BASE_SIZE_DEFAULT_16:
7173 m68k_index_width_default = SIZE_WORD;
7176 case OPTION_BASE_SIZE_DEFAULT_32:
7177 m68k_index_width_default = SIZE_LONG;
7180 case OPTION_DISP_SIZE_DEFAULT_16:
7182 m68k_rel32_from_cmdline = 1;
7185 case OPTION_DISP_SIZE_DEFAULT_32:
7187 m68k_rel32_from_cmdline = 1;
7192 as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
7195 /* Intentional fall-through. */
7197 if (!strncmp (arg, "arch=", 5))
7198 m68k_set_arch (arg + 5, 1, 0);
7199 else if (!strncmp (arg, "cpu=", 4))
7200 m68k_set_cpu (arg + 4, 1, 0);
7201 else if (m68k_set_extension (arg, 0, 1))
7203 else if (m68k_set_arch (arg, 0, 1))
7205 else if (m68k_set_cpu (arg, 0, 1))
7218 /* Setup tables from the selected arch and/or cpu */
7221 m68k_init_arch (void)
7223 if (not_current_architecture & current_architecture)
7225 as_bad (_("architecture features both enabled and disabled"));
7226 not_current_architecture &= ~current_architecture;
7230 current_architecture |= selected_arch->arch;
7231 control_regs = selected_arch->control_regs;
7234 current_architecture |= selected_cpu->arch;
7236 current_architecture &= ~not_current_architecture;
7238 if ((current_architecture & (cfloat | m68881)) == (cfloat | m68881))
7240 /* Determine which float is really meant. */
7241 if (current_architecture & (m68k_mask & ~m68881))
7242 current_architecture ^= cfloat;
7244 current_architecture ^= m68881;
7249 control_regs = selected_cpu->control_regs;
7250 if (current_architecture & ~selected_cpu->arch)
7252 as_bad (_("selected processor does not have all features of selected architecture"));
7253 current_architecture
7254 = selected_cpu->arch & ~not_current_architecture;
7258 if ((current_architecture & m68k_mask)
7259 && (current_architecture & ~m68k_mask))
7261 as_bad (_ ("m68k and cf features both selected"));
7262 if (current_architecture & m68k_mask)
7263 current_architecture &= m68k_mask;
7265 current_architecture &= ~m68k_mask;
7268 /* Permit m68881 specification with all cpus; those that can't work
7269 with a coprocessor could be doing emulation. */
7270 if (current_architecture & m68851)
7272 if (current_architecture & m68040)
7273 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
7275 /* What other incompatibilities could we check for? */
7277 if (cpu_of_arch (current_architecture) < m68020
7278 || arch_coldfire_p (current_architecture))
7279 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
7285 md_show_usage (FILE *stream)
7287 const char *default_cpu = TARGET_CPU;
7289 unsigned int default_arch;
7291 /* Get the canonical name for the default target CPU. */
7292 if (*default_cpu == 'm')
7294 for (i = 0; m68k_cpus[i].name; i++)
7296 if (strcasecmp (default_cpu, m68k_cpus[i].name) == 0)
7298 default_arch = m68k_cpus[i].arch;
7299 while (m68k_cpus[i].alias > 0)
7301 while (m68k_cpus[i].alias < 0)
7303 default_cpu = m68k_cpus[i].name;
7307 fprintf (stream, _("\
7308 -march=<arch> set architecture\n\
7309 -mcpu=<cpu> set cpu [default %s]\n\
7311 for (i = 0; m68k_extensions[i].name; i++)
7312 fprintf (stream, _("\
7313 -m[no-]%-16s enable/disable%s architecture extension\n\
7314 "), m68k_extensions[i].name,
7315 m68k_extensions[i].alias > 0 ? " ColdFire"
7316 : m68k_extensions[i].alias < 0 ? " m68k" : "");
7318 fprintf (stream, _("\
7319 -l use 1 word for refs to undefined symbols [default 2]\n\
7320 -pic, -k generate position independent code\n\
7321 -S turn jbsr into jsr\n\
7322 --pcrel never turn PC-relative branches into absolute jumps\n\
7323 --register-prefix-optional\n\
7324 recognize register names without prefix character\n\
7325 --bitwise-or do not treat `|' as a comment character\n\
7326 --base-size-default-16 base reg without size is 16 bits\n\
7327 --base-size-default-32 base reg without size is 32 bits (default)\n\
7328 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7329 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
7332 fprintf (stream, _("Architecture variants are: "));
7333 for (i = 0; m68k_archs[i].name; i++)
7336 fprintf (stream, " | ");
7337 fprintf (stream, m68k_archs[i].name);
7339 fprintf (stream, "\n");
7341 fprintf (stream, _("Processor variants are: "));
7342 for (i = 0; m68k_cpus[i].name; i++)
7345 fprintf (stream, " | ");
7346 fprintf (stream, m68k_cpus[i].name);
7348 fprintf (stream, _("\n"));
7353 /* TEST2: Test md_assemble() */
7354 /* Warning, this routine probably doesn't work anymore. */
7358 struct m68k_it the_ins;
7366 if (!gets (buf) || !*buf)
7368 if (buf[0] == '|' || buf[1] == '.')
7370 for (cp = buf; *cp; cp++)
7375 memset (&the_ins, '\0', sizeof (the_ins));
7376 m68k_ip (&the_ins, buf);
7379 printf (_("Error %s in %s\n"), the_ins.error, buf);
7383 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7384 for (n = 0; n < the_ins.numo; n++)
7385 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7387 print_the_insn (&the_ins.opcode[0], stdout);
7388 (void) putchar ('\n');
7390 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7392 if (the_ins.operands[n].error)
7394 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7397 printf ("mode %d, reg %d, ", the_ins.operands[n].mode,
7398 the_ins.operands[n].reg);
7399 if (the_ins.operands[n].b_const)
7400 printf ("Constant: '%.*s', ",
7401 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const,
7402 the_ins.operands[n].b_const);
7403 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg,
7404 the_ins.operands[n].isiz, the_ins.operands[n].imul);
7405 if (the_ins.operands[n].b_iadd)
7406 printf ("Iadd: '%.*s',",
7407 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd,
7408 the_ins.operands[n].b_iadd);
7417 is_label (char *str)
7421 while (*str && *str != ' ')
7423 if (str[-1] == ':' || str[1] == '=')
7430 /* Possible states for relaxation:
7432 0 0 branch offset byte (bra, etc)
7436 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7440 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7447 /* We have no need to default values of symbols. */
7450 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
7455 /* Round up a section size to the appropriate boundary. */
7457 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
7460 /* For a.out, force the section size to be aligned. If we don't do
7461 this, BFD will align it for us, but it will not write out the
7462 final bytes of the section. This may be a bug in BFD, but it is
7463 easier to fix it here since that is how the other a.out targets
7467 align = bfd_get_section_alignment (stdoutput, segment);
7468 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7474 /* Exactly what point is a PC-relative offset relative TO?
7475 On the 68k, it is relative to the address of the first extension
7476 word. The difference between the addresses of the offset and the
7477 first extension word is stored in fx_pcrel_adjust. */
7479 md_pcrel_from (fixS *fixP)
7483 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7484 sign extend the value here. */
7485 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7488 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7493 m68k_elf_final_processing (void)
7497 if (arch_coldfire_fpu (current_architecture))
7498 flags |= EF_M68K_CFV4E;
7499 /* Set file-specific flags if this is a cpu32 processor. */
7500 if (cpu_of_arch (current_architecture) & cpu32)
7501 flags |= EF_M68K_CPU32;
7502 else if ((cpu_of_arch (current_architecture) & m68000up)
7503 && !(cpu_of_arch (current_architecture) & m68020up))
7504 flags |= EF_M68K_M68000;
7506 if (current_architecture & mcfisa_a)
7508 static const unsigned isa_features[][2] =
7510 {EF_M68K_ISA_A_NODIV, mcfisa_a},
7511 {EF_M68K_ISA_A, mcfisa_a|mcfhwdiv},
7512 {EF_M68K_ISA_A_PLUS,mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp},
7513 {EF_M68K_ISA_B_NOUSP,mcfisa_a|mcfisa_b|mcfhwdiv},
7514 {EF_M68K_ISA_B, mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp},
7517 static const unsigned mac_features[][2] =
7519 {EF_M68K_MAC, mcfmac},
7520 {EF_M68K_EMAC, mcfemac},
7526 pattern = (current_architecture
7527 & (mcfisa_a|mcfisa_aa|mcfisa_b|mcfhwdiv|mcfusp));
7528 for (ix = 0; isa_features[ix][1]; ix++)
7530 if (pattern == isa_features[ix][1])
7532 flags |= isa_features[ix][0];
7536 if (!isa_features[ix][1])
7539 as_warn (_("Not a defined coldfire architecture"));
7543 if (current_architecture & cfloat)
7544 flags |= EF_M68K_FLOAT | EF_M68K_CFV4E;
7546 pattern = current_architecture & (mcfmac|mcfemac);
7549 for (ix = 0; mac_features[ix][1]; ix++)
7551 if (pattern == mac_features[ix][1])
7553 flags |= mac_features[ix][0];
7557 if (!mac_features[ix][1])
7562 elf_elfheader (stdoutput)->e_flags |= flags;
7567 tc_m68k_regname_to_dw2regnum (char *regname)
7569 unsigned int regnum;
7570 static const char *const regnames[] =
7572 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7573 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7574 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7578 for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
7579 if (strcmp (regname, regnames[regnum]) == 0)
7586 tc_m68k_frame_initial_instructions (void)
7588 static int sp_regno = -1;
7591 sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
7593 cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
7594 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);