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 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, 59 Temple Place - Suite 330, 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"
36 /* This string holds the chars that always start a comment. If the
37 pre-processor is disabled, these aren't very useful. The macro
38 tc_comment_chars points to this. We use this, rather than the
39 usual comment_chars, so that the --bitwise-or option will work. */
40 #if defined (TE_SVR4) || defined (TE_DELTA)
41 const char *m68k_comment_chars = "|#";
43 const char *m68k_comment_chars = "|";
46 /* This array holds the chars that only start a comment at the beginning of
47 a line. If the line seems to have the form '# 123 filename'
48 .line and .file directives will appear in the pre-processed output */
49 /* Note that input_file.c hand checks for '#' at the beginning of the
50 first line of the input file. This is because the compiler outputs
51 #NO_APP at the beginning of its output. */
52 /* Also note that comments like this one will always work. */
53 const char line_comment_chars[] = "#*";
55 const char line_separator_chars[] = ";";
57 /* Chars that can be used to separate mant from exp in floating point nums. */
58 const char EXP_CHARS[] = "eE";
60 /* Chars that mean this number is a floating point constant, as
61 in "0f12.456" or "0d1.2345e12". */
63 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
65 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
66 changed in read.c . Ideally it shouldn't have to know about it at all,
67 but nothing is ideal around here. */
69 const int md_reloc_size = 8; /* Size of relocation record. */
71 /* Are we trying to generate PIC code? If so, absolute references
72 ought to be made into linkage table references or pc-relative
73 references. Not implemented. For ELF there are other means
74 to denote pic relocations. */
77 static int flag_short_refs; /* -l option. */
78 static int flag_long_jumps; /* -S option. */
79 static int flag_keep_pcrel; /* --pcrel option. */
81 #ifdef REGISTER_PREFIX_OPTIONAL
82 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
84 int flag_reg_prefix_optional;
87 /* Whether --register-prefix-optional was used on the command line. */
88 static int reg_prefix_optional_seen;
90 /* The floating point coprocessor to use by default. */
91 static enum m68k_register m68k_float_copnum = COP1;
93 /* If this is non-zero, then references to number(%pc) will be taken
94 to refer to number, rather than to %pc + number. */
95 static int m68k_abspcadd;
97 /* If this is non-zero, then the quick forms of the move, add, and sub
98 instructions are used when possible. */
99 static int m68k_quick = 1;
101 /* If this is non-zero, then if the size is not specified for a base
102 or outer displacement, the assembler assumes that the size should
104 static int m68k_rel32 = 1;
106 /* This is non-zero if m68k_rel32 was set from the command line. */
107 static int m68k_rel32_from_cmdline;
109 /* The default width to use for an index register when using a base
111 static enum m68k_size m68k_index_width_default = SIZE_LONG;
113 /* We want to warn if any text labels are misaligned. In order to get
114 the right line number, we need to record the line number for each
118 struct label_line *next;
125 /* The list of labels. */
127 static struct label_line *labels;
129 /* The current label. */
131 static struct label_line *current_label;
133 /* Pointer to list holding the opcodes sorted by name. */
134 static struct m68k_opcode const ** m68k_sorted_opcodes;
136 /* Its an arbitrary name: This means I don't approve of it.
138 static struct obstack robyn;
142 const char *m_operands;
143 unsigned long m_opcode;
147 struct m68k_incant *m_next;
150 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
151 #define gettwo(x) (((x)->m_opcode)&0xffff)
153 static const enum m68k_register m68000_control_regs[] = { 0 };
154 static const enum m68k_register m68010_control_regs[] = {
158 static const enum m68k_register m68020_control_regs[] = {
159 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
162 static const enum m68k_register m68040_control_regs[] = {
163 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
164 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
167 static const enum m68k_register m68060_control_regs[] = {
168 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
169 USP, VBR, URP, SRP, PCR,
172 static const enum m68k_register mcf_control_regs[] = {
173 CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
174 RAMBAR0, RAMBAR1, MBAR,
177 static const enum m68k_register mcf528x_control_regs[] = {
178 CACR, ACR0, ACR1, VBR, FLASHBAR, RAMBAR,
181 static const enum m68k_register mcfv4e_control_regs[] = {
182 CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
183 ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
184 PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
185 PCR3U0, PCR3L0, PCR3U1, PCR3L1,
188 #define cpu32_control_regs m68010_control_regs
190 static const enum m68k_register *control_regs;
192 /* Internal form of a 68020 instruction. */
196 const char *args; /* List of opcode info. */
199 int numo; /* Number of shorts in opcode. */
202 struct m68k_op operands[6];
204 int nexp; /* Number of exprs in use. */
205 struct m68k_exp exprs[4];
207 int nfrag; /* Number of frags we have to produce. */
210 int fragoff; /* Where in the current opcode the frag ends. */
217 int nrel; /* Num of reloc strucs in use. */
224 /* In a pc relative address the difference between the address
225 of the offset and the address that the offset is relative
226 to. This depends on the addressing mode. Basically this
227 is the value to put in the offset field to address the
228 first byte of the offset, without regarding the special
229 significance of some values (in the branch instruction, for
233 /* Whether this expression needs special pic relocation, and if
235 enum pic_relocation pic_reloc;
238 reloc[5]; /* Five is enough??? */
241 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a))
242 #define float_of_arch(x) ((x) & mfloat)
243 #define mmu_of_arch(x) ((x) & mmmu)
244 #define arch_coldfire_p(x) ((x) & mcfisa_a)
245 #define arch_coldfire_fpu(x) ((x) & cfloat)
247 /* Macros for determining if cpu supports a specific addressing mode. */
248 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcfisa_b))
250 static struct m68k_it the_ins; /* The instruction being assembled. */
252 #define op(ex) ((ex)->exp.X_op)
253 #define adds(ex) ((ex)->exp.X_add_symbol)
254 #define subs(ex) ((ex)->exp.X_op_symbol)
255 #define offs(ex) ((ex)->exp.X_add_number)
257 /* Macros for adding things to the m68k_it struct. */
258 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
260 /* Static functions. */
261 static void insop PARAMS ((int, const struct m68k_incant *));
262 static void add_fix PARAMS ((int, struct m68k_exp *, int, int));
263 static void add_frag PARAMS ((symbolS *, offsetT, int));
265 /* Like addword, but goes BEFORE general operands. */
270 const struct m68k_incant *opcode;
273 for (z = the_ins.numo; z > opcode->m_codenum; --z)
274 the_ins.opcode[z] = the_ins.opcode[z - 1];
275 for (z = 0; z < the_ins.nrel; z++)
276 the_ins.reloc[z].n += 2;
277 for (z = 0; z < the_ins.nfrag; z++)
278 the_ins.fragb[z].fragoff++;
279 the_ins.opcode[opcode->m_codenum] = w;
283 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
286 add_fix (width, exp, pc_rel, pc_fix)
288 struct m68k_exp *exp;
292 the_ins.reloc[the_ins.nrel].n = ((width == 'B' || width == '3')
296 : (the_ins.numo*2)));
297 the_ins.reloc[the_ins.nrel].exp = exp->exp;
298 the_ins.reloc[the_ins.nrel].wid = width;
299 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
301 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
303 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
306 /* Cause an extra frag to be generated here, inserting up to 10 bytes
307 (that value is chosen in the frag_var call in md_assemble). TYPE
308 is the subtype of the frag to be generated; its primary type is
309 rs_machine_dependent.
311 The TYPE parameter is also used by md_convert_frag_1 and
312 md_estimate_size_before_relax. The appropriate type of fixup will
313 be emitted by md_convert_frag_1.
315 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
317 add_frag (add, off, type)
322 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
323 the_ins.fragb[the_ins.nfrag].fadd = add;
324 the_ins.fragb[the_ins.nfrag].foff = off;
325 the_ins.fragb[the_ins.nfrag++].fragty = type;
329 (op (ex) != O_constant && op (ex) != O_big)
331 static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
332 static int get_num PARAMS ((struct m68k_exp *exp, int ok));
333 static void m68k_ip PARAMS ((char *));
334 static void insert_reg PARAMS ((const char *, int));
335 static void select_control_regs PARAMS ((void));
336 static void init_regtable PARAMS ((void));
337 static int reverse_16_bits PARAMS ((int in));
338 static int reverse_8_bits PARAMS ((int in));
339 static void install_gen_operand PARAMS ((int mode, int val));
340 static void install_operand PARAMS ((int mode, int val));
341 static void s_bss PARAMS ((int));
342 static void s_data1 PARAMS ((int));
343 static void s_data2 PARAMS ((int));
344 static void s_even PARAMS ((int));
345 static void s_proc PARAMS ((int));
346 static void mri_chip PARAMS ((void));
347 static void s_chip PARAMS ((int));
348 static void s_fopt PARAMS ((int));
349 static void s_opt PARAMS ((int));
350 static void s_reg PARAMS ((int));
351 static void s_restore PARAMS ((int));
352 static void s_save PARAMS ((int));
353 static void s_mri_if PARAMS ((int));
354 static void s_mri_else PARAMS ((int));
355 static void s_mri_endi PARAMS ((int));
356 static void s_mri_break PARAMS ((int));
357 static void s_mri_next PARAMS ((int));
358 static void s_mri_for PARAMS ((int));
359 static void s_mri_endf PARAMS ((int));
360 static void s_mri_repeat PARAMS ((int));
361 static void s_mri_until PARAMS ((int));
362 static void s_mri_while PARAMS ((int));
363 static void s_mri_endw PARAMS ((int));
364 static void md_convert_frag_1 PARAMS ((fragS *));
366 static int current_architecture;
367 static int current_chip;
377 static const struct m68k_cpu archs[] =
379 { m68000, m68000, "68000", 0 },
380 { m68010, m68010, "68010", 0 },
381 { m68020, m68020, "68020", 0 },
382 { m68030, m68030, "68030", 0 },
383 { m68040, m68040, "68040", 0 },
384 { m68060, m68060, "68060", 0 },
385 { cpu32, cpu32, "cpu32", 0 },
386 { m68881, m68881, "68881", 0 },
387 { m68851, m68851, "68851", 0 },
388 { mcfisa_a, mcf5200, "5200", 0 },
389 { mcfisa_a|mcfhwdiv|mcfmac, mcf5206e, "5206e", 0 },
390 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf521x, "521x", 0 },
391 { mcfisa_a|mcfhwdiv|mcfemac, mcf5249, "5249", 0 },
392 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf528x, "528x", 0 },
393 { mcfisa_a|mcfhwdiv|mcfmac, mcf5307, "5307", 0 },
394 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac, mcf5407, "5407", 0 },
395 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "547x", 0 },
396 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5480, "548x", 0 },
397 /* Aliases (effectively, so far as gas is concerned) for the above
399 { m68020, m68020, "68k", 1 },
400 { m68000, m68000, "68008", 1 },
401 { m68000, m68000, "68302", 1 },
402 { m68000, m68000, "68306", 1 },
403 { m68000, m68000, "68307", 1 },
404 { m68000, m68000, "68322", 1 },
405 { m68000, m68000, "68356", 1 },
406 { m68000, m68000, "68ec000", 1 },
407 { m68000, m68000, "68hc000", 1 },
408 { m68000, m68000, "68hc001", 1 },
409 { m68020, m68020, "68ec020", 1 },
410 { m68030, m68030, "68ec030", 1 },
411 { m68040, m68040, "68ec040", 1 },
412 { m68060, m68060, "68ec060", 1 },
413 { cpu32, cpu32, "68330", 1 },
414 { cpu32, cpu32, "68331", 1 },
415 { cpu32, cpu32, "68332", 1 },
416 { cpu32, cpu32, "68333", 1 },
417 { cpu32, cpu32, "68334", 1 },
418 { cpu32, cpu32, "68336", 1 },
419 { cpu32, cpu32, "68340", 1 },
420 { cpu32, cpu32, "68341", 1 },
421 { cpu32, cpu32, "68349", 1 },
422 { cpu32, cpu32, "68360", 1 },
423 { m68881, m68881, "68882", 1 },
424 { mcfisa_a, mcf5200, "5202", 1 },
425 { mcfisa_a, mcf5200, "5204", 1 },
426 { mcfisa_a, mcf5200, "5206", 1 },
427 { mcfisa_a|mcfhwdiv|mcfisa_aa|mcfemac, mcf521x, "5214", 1 },
428 { mcfisa_a|mcfhwdiv|mcfisa_aa|mcfemac, mcf521x, "5216", 1 },
429 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5280", 1 },
430 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5281", 1 },
431 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5282", 1 },
432 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac, mcf5407, "cfv4", 1 },
433 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5470", 1 },
434 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5471", 1 },
435 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5472", 1 },
436 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5473", 1 },
437 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5474", 1 },
438 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5475", 1 },
439 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5480", 1 },
440 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5481", 1 },
441 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5482", 1 },
442 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5483", 1 },
443 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5484", 1 },
444 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5485", 1 },
445 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "cfv4e", 1 },
448 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
450 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
451 architecture and we have a lot of relaxation modes. */
453 /* Macros used in the relaxation code. */
454 #define TAB(x,y) (((x) << 2) + (y))
455 #define TABTYPE(x) ((x) >> 2)
457 /* Relaxation states. */
463 /* Here are all the relaxation modes we support. First we can relax ordinary
464 branches. On 68020 and higher and on CPU32 all branch instructions take
465 three forms, so on these CPUs all branches always remain as such. When we
466 have to expand to the LONG form on a 68000, though, we substitute an
467 absolute jump instead. This is a direct replacement for unconditional
468 branches and a branch over a jump for conditional branches. However, if the
469 user requires PIC and disables this with --pcrel, we can only relax between
470 BYTE and SHORT forms, punting if that isn't enough. This gives us four
471 different relaxation modes for branches: */
473 #define BRANCHBWL 0 /* Branch byte, word, or long. */
474 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
475 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
476 #define BRANCHBW 3 /* Branch byte or word. */
478 /* We also relax coprocessor branches and DBcc's. All CPUs that support
479 coprocessor branches support them in word and long forms, so we have only
480 one relaxation mode for them. DBcc's are word only on all CPUs. We can
481 relax them to the LONG form with a branch-around sequence. This sequence
482 can use a long branch (if available) or an absolute jump (if acceptable).
483 This gives us two relaxation modes. If long branches are not available and
484 absolute jumps are not acceptable, we don't relax DBcc's. */
486 #define FBRANCH 4 /* Coprocessor branch. */
487 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
488 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
490 /* That's all for instruction relaxation. However, we also relax PC-relative
491 operands. Specifically, we have three operand relaxation modes. On the
492 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
493 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
494 two. Also PC+displacement+index operands in their simple form (with a non-
495 suppressed index without memory indirection) are supported on all CPUs, but
496 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
497 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
498 form of the PC+displacement+index operand. Finally, some absolute operands
499 can be relaxed down to 16-bit PC-relative. */
501 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
502 #define PCINDEX 8 /* PC + displacement + index. */
503 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
505 /* Note that calls to frag_var need to specify the maximum expansion
506 needed; this is currently 10 bytes for DBCC. */
509 How far Forward this mode will reach:
510 How far Backward this mode will reach:
511 How many bytes this mode will add to the size of the frag
512 Which mode to go to if the offset won't fit in this one
514 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
515 relax_typeS md_relax_table[] =
517 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
518 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
522 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
523 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
527 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
528 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
532 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
537 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
538 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
542 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
543 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
547 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
548 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
552 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
553 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
557 { 125, -130, 0, TAB (PCINDEX, SHORT) },
558 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
562 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
563 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
568 /* These are the machine dependent pseudo-ops. These are included so
569 the assembler can work on the output from the SUN C compiler, which
572 /* This table describes all the machine specific pseudo-ops the assembler
573 has to support. The fields are:
574 pseudo-op name without dot
575 function to call to execute this pseudo-op
576 Integer arg to pass to the function. */
577 const pseudo_typeS md_pseudo_table[] =
579 {"data1", s_data1, 0},
580 {"data2", s_data2, 0},
583 {"skip", s_space, 0},
585 #if defined (TE_SUN3) || defined (OBJ_ELF)
586 {"align", s_align_bytes, 0},
589 {"swbeg", s_ignore, 0},
591 {"extend", float_cons, 'x'},
592 {"ldouble", float_cons, 'x'},
594 /* The following pseudo-ops are supported for MRI compatibility. */
596 {"comline", s_space, 1},
598 {"mask2", s_ignore, 0},
601 {"restore", s_restore, 0},
605 {"if.b", s_mri_if, 'b'},
606 {"if.w", s_mri_if, 'w'},
607 {"if.l", s_mri_if, 'l'},
608 {"else", s_mri_else, 0},
609 {"else.s", s_mri_else, 's'},
610 {"else.l", s_mri_else, 'l'},
611 {"endi", s_mri_endi, 0},
612 {"break", s_mri_break, 0},
613 {"break.s", s_mri_break, 's'},
614 {"break.l", s_mri_break, 'l'},
615 {"next", s_mri_next, 0},
616 {"next.s", s_mri_next, 's'},
617 {"next.l", s_mri_next, 'l'},
618 {"for", s_mri_for, 0},
619 {"for.b", s_mri_for, 'b'},
620 {"for.w", s_mri_for, 'w'},
621 {"for.l", s_mri_for, 'l'},
622 {"endf", s_mri_endf, 0},
623 {"repeat", s_mri_repeat, 0},
624 {"until", s_mri_until, 0},
625 {"until.b", s_mri_until, 'b'},
626 {"until.w", s_mri_until, 'w'},
627 {"until.l", s_mri_until, 'l'},
628 {"while", s_mri_while, 0},
629 {"while.b", s_mri_while, 'b'},
630 {"while.w", s_mri_while, 'w'},
631 {"while.l", s_mri_while, 'l'},
632 {"endw", s_mri_endw, 0},
637 /* The mote pseudo ops are put into the opcode table, since they
638 don't start with a . they look like opcodes to gas.
642 extern void obj_coff_section PARAMS ((int));
645 const pseudo_typeS mote_pseudo_table[] =
658 {"xdef", s_globl, 0},
660 {"align", s_align_bytes, 0},
662 {"align", s_align_ptwo, 0},
665 {"sect", obj_coff_section, 0},
666 {"section", obj_coff_section, 0},
671 #define issbyte(x) ((x)>=-128 && (x)<=127)
672 #define isubyte(x) ((x)>=0 && (x)<=255)
673 #define issword(x) ((x)>=-32768 && (x)<=32767)
674 #define isuword(x) ((x)>=0 && (x)<=65535)
676 #define isbyte(x) ((x)>= -255 && (x)<=255)
677 #define isword(x) ((x)>=-65536 && (x)<=65535)
678 #define islong(x) (1)
680 extern char *input_line_pointer;
682 static char notend_table[256];
683 static char alt_notend_table[256];
685 (! (notend_table[(unsigned char) *s] \
687 && alt_notend_table[(unsigned char) s[1]])))
689 /* Return a human readable string holding the list of chips that are
690 valid for a particular architecture, suppressing aliases (unless
691 there is only one of them). */
694 find_cf_chip (int architecture)
696 static char buf[1024];
697 int i, j, n_chips, n_alias;
701 cp = buf + strlen (buf);
703 for (i = 0, n_chips = 0, n_alias = 0; i < n_archs; ++i)
704 if (archs[i].arch & architecture)
712 as_fatal (_("no matching ColdFire architectures found"));
717 for (i = 0, j = 0; i < n_archs && j < n_chips; ++i)
718 if (archs[i].arch & architecture)
722 if (((j == n_chips - 1) && !(n_alias > 1))|| ! n_alias)
726 strncpy (cp, _(" or "), (sizeof (buf) - (cp - buf)));
731 strncpy (cp, _(", or "), (sizeof (buf) - (cp - buf)));
737 strncpy (cp, ", ", (sizeof (buf) - (cp - buf)));
741 strncpy (cp, archs[i].name, (sizeof (buf) - (cp - buf)));
748 strncpy (cp, _(", or aliases"), (sizeof (buf) - (cp - buf)));
752 strncpy (cp, ")", (sizeof (buf) - (cp - buf)));
757 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
759 #ifdef NO_PCREL_RELOCS
762 make_pcrel_absolute (fixP, add_number)
766 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
768 /* Rewrite the PC relative instructions to absolute address ones.
769 these are rumored to be faster, and the apollo linker refuses
770 to deal with the PC relative relocations. */
771 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP. */
774 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
778 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR. */
781 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
786 as_fatal (_("Unknown PC relative instruction"));
791 #endif /* NO_PCREL_RELOCS */
794 tc_coff_fix2rtype (fixP)
797 if (fixP->fx_tcbit && fixP->fx_size == 4)
798 return R_RELLONG_NEG;
799 #ifdef NO_PCREL_RELOCS
800 know (fixP->fx_pcrel == 0);
801 return (fixP->fx_size == 1 ? R_RELBYTE
802 : fixP->fx_size == 2 ? R_DIR16
805 return (fixP->fx_pcrel ?
806 (fixP->fx_size == 1 ? R_PCRBYTE :
807 fixP->fx_size == 2 ? R_PCRWORD :
809 (fixP->fx_size == 1 ? R_RELBYTE :
810 fixP->fx_size == 2 ? R_RELWORD :
819 /* Return zero if the reference to SYMBOL from within the same segment may
822 /* On an ELF system, we can't relax an externally visible symbol,
823 because it may be overridden by a shared library. However, if
824 TARGET_OS is "elf", then we presume that we are assembling for an
825 embedded system, in which case we don't have to worry about shared
826 libraries, and we can relax any external sym. */
828 #define relaxable_symbol(symbol) \
829 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
830 || S_IS_WEAK (symbol)))
832 /* Compute the relocation code for a fixup of SIZE bytes, using pc
833 relative relocation if PCREL is non-zero. PIC says whether a special
834 pic relocation was requested. */
836 static bfd_reloc_code_real_type get_reloc_code
837 PARAMS ((int, int, enum pic_relocation));
839 static bfd_reloc_code_real_type
840 get_reloc_code (size, pcrel, pic)
843 enum pic_relocation pic;
851 return BFD_RELOC_8_GOT_PCREL;
853 return BFD_RELOC_16_GOT_PCREL;
855 return BFD_RELOC_32_GOT_PCREL;
863 return BFD_RELOC_8_GOTOFF;
865 return BFD_RELOC_16_GOTOFF;
867 return BFD_RELOC_32_GOTOFF;
875 return BFD_RELOC_8_PLT_PCREL;
877 return BFD_RELOC_16_PLT_PCREL;
879 return BFD_RELOC_32_PLT_PCREL;
887 return BFD_RELOC_8_PLTOFF;
889 return BFD_RELOC_16_PLTOFF;
891 return BFD_RELOC_32_PLTOFF;
901 return BFD_RELOC_8_PCREL;
903 return BFD_RELOC_16_PCREL;
905 return BFD_RELOC_32_PCREL;
925 as_bad (_("Can not do %d byte pc-relative relocation"), size);
927 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
932 as_bad (_("Can not do %d byte relocation"), size);
934 as_bad (_("Can not do %d byte pic relocation"), size);
937 return BFD_RELOC_NONE;
940 /* Here we decide which fixups can be adjusted to make them relative
941 to the beginning of the section instead of the symbol. Basically
942 we need to make sure that the dynamic relocations are done
943 correctly, so in some cases we force the original symbol to be
946 tc_m68k_fix_adjustable (fixP)
949 /* Adjust_reloc_syms doesn't know about the GOT. */
950 switch (fixP->fx_r_type)
952 case BFD_RELOC_8_GOT_PCREL:
953 case BFD_RELOC_16_GOT_PCREL:
954 case BFD_RELOC_32_GOT_PCREL:
955 case BFD_RELOC_8_GOTOFF:
956 case BFD_RELOC_16_GOTOFF:
957 case BFD_RELOC_32_GOTOFF:
958 case BFD_RELOC_8_PLT_PCREL:
959 case BFD_RELOC_16_PLT_PCREL:
960 case BFD_RELOC_32_PLT_PCREL:
961 case BFD_RELOC_8_PLTOFF:
962 case BFD_RELOC_16_PLTOFF:
963 case BFD_RELOC_32_PLTOFF:
966 case BFD_RELOC_VTABLE_INHERIT:
967 case BFD_RELOC_VTABLE_ENTRY:
977 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
979 #define relaxable_symbol(symbol) 1
986 tc_gen_reloc (section, fixp)
987 asection *section ATTRIBUTE_UNUSED;
991 bfd_reloc_code_real_type code;
993 /* If the tcbit is set, then this was a fixup of a negative value
994 that was never resolved. We do not have a reloc to handle this,
995 so just return. We assume that other code will have detected this
996 situation and produced a helpful error message, so we just tell the
997 user that the reloc cannot be produced. */
1001 as_bad_where (fixp->fx_file, fixp->fx_line,
1002 _("Unable to produce reloc against symbol '%s'"),
1003 S_GET_NAME (fixp->fx_addsy));
1007 if (fixp->fx_r_type != BFD_RELOC_NONE)
1009 code = fixp->fx_r_type;
1011 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1012 that fixup_segment converted a non-PC relative reloc into a
1013 PC relative reloc. In such a case, we need to convert the
1020 code = BFD_RELOC_8_PCREL;
1023 code = BFD_RELOC_16_PCREL;
1026 code = BFD_RELOC_32_PCREL;
1028 case BFD_RELOC_8_PCREL:
1029 case BFD_RELOC_16_PCREL:
1030 case BFD_RELOC_32_PCREL:
1031 case BFD_RELOC_8_GOT_PCREL:
1032 case BFD_RELOC_16_GOT_PCREL:
1033 case BFD_RELOC_32_GOT_PCREL:
1034 case BFD_RELOC_8_GOTOFF:
1035 case BFD_RELOC_16_GOTOFF:
1036 case BFD_RELOC_32_GOTOFF:
1037 case BFD_RELOC_8_PLT_PCREL:
1038 case BFD_RELOC_16_PLT_PCREL:
1039 case BFD_RELOC_32_PLT_PCREL:
1040 case BFD_RELOC_8_PLTOFF:
1041 case BFD_RELOC_16_PLTOFF:
1042 case BFD_RELOC_32_PLTOFF:
1045 as_bad_where (fixp->fx_file, fixp->fx_line,
1046 _("Cannot make %s relocation PC relative"),
1047 bfd_get_reloc_code_name (code));
1053 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1054 switch (F (fixp->fx_size, fixp->fx_pcrel))
1056 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1057 MAP (1, 0, BFD_RELOC_8);
1058 MAP (2, 0, BFD_RELOC_16);
1059 MAP (4, 0, BFD_RELOC_32);
1060 MAP (1, 1, BFD_RELOC_8_PCREL);
1061 MAP (2, 1, BFD_RELOC_16_PCREL);
1062 MAP (4, 1, BFD_RELOC_32_PCREL);
1070 reloc = (arelent *) xmalloc (sizeof (arelent));
1071 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1072 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1073 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1076 reloc->addend = fixp->fx_addnumber;
1080 if (!fixp->fx_pcrel)
1081 reloc->addend = fixp->fx_addnumber;
1083 reloc->addend = (section->vma
1084 /* Explicit sign extension in case char is
1086 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
1087 + fixp->fx_addnumber
1088 + md_pcrel_from (fixp));
1091 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1092 assert (reloc->howto != 0);
1097 #endif /* BFD_ASSEMBLER */
1099 /* Handle of the OPCODE hash table. NULL means any use before
1100 m68k_ip_begin() will crash. */
1101 static struct hash_control *op_hash;
1103 /* Assemble an m68k instruction. */
1110 register struct m68k_op *opP;
1111 register const struct m68k_incant *opcode;
1112 register const char *s;
1113 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1114 char *pdot, *pdotmove;
1115 enum m68k_size siz1, siz2;
1119 LITTLENUM_TYPE words[6];
1120 LITTLENUM_TYPE *wordp;
1121 unsigned long ok_arch = 0;
1123 if (*instring == ' ')
1124 instring++; /* Skip leading whitespace. */
1126 /* Scan up to end of operation-code, which MUST end in end-of-string
1127 or exactly 1 space. */
1129 for (p = instring; *p != '\0'; p++)
1139 the_ins.error = _("No operator");
1143 /* p now points to the end of the opcode name, probably whitespace.
1144 Make sure the name is null terminated by clobbering the
1145 whitespace, look it up in the hash table, then fix it back.
1146 Remove a dot, first, since the opcode tables have none. */
1149 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1150 *pdotmove = pdotmove[1];
1156 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1161 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1162 *pdotmove = pdotmove[-1];
1169 the_ins.error = _("Unknown operator");
1173 /* Found a legitimate opcode, start matching operands. */
1177 if (opcode->m_operands == 0)
1179 char *old = input_line_pointer;
1181 input_line_pointer = p;
1182 /* Ahh - it's a motorola style psuedo op. */
1183 mote_pseudo_table[opcode->m_opnum].poc_handler
1184 (mote_pseudo_table[opcode->m_opnum].poc_val);
1185 input_line_pointer = old;
1191 if (flag_mri && opcode->m_opnum == 0)
1193 /* In MRI mode, random garbage is allowed after an instruction
1194 which accepts no operands. */
1195 the_ins.args = opcode->m_operands;
1196 the_ins.numargs = opcode->m_opnum;
1197 the_ins.numo = opcode->m_codenum;
1198 the_ins.opcode[0] = getone (opcode);
1199 the_ins.opcode[1] = gettwo (opcode);
1203 for (opP = &the_ins.operands[0]; *p; opP++)
1205 p = crack_operand (p, opP);
1209 the_ins.error = opP->error;
1214 opsfound = opP - &the_ins.operands[0];
1216 /* This ugly hack is to support the floating pt opcodes in their
1217 standard form. Essentially, we fake a first enty of type COP#1 */
1218 if (opcode->m_operands[0] == 'I')
1222 for (n = opsfound; n > 0; --n)
1223 the_ins.operands[n] = the_ins.operands[n - 1];
1225 memset ((char *) (&the_ins.operands[0]), '\0',
1226 sizeof (the_ins.operands[0]));
1227 the_ins.operands[0].mode = CONTROL;
1228 the_ins.operands[0].reg = m68k_float_copnum;
1232 /* We've got the operands. Find an opcode that'll accept them. */
1235 /* If we didn't get the right number of ops, or we have no
1236 common model with this pattern then reject this pattern. */
1238 ok_arch |= opcode->m_arch;
1239 if (opsfound != opcode->m_opnum
1240 || ((opcode->m_arch & current_architecture) == 0))
1244 for (s = opcode->m_operands, opP = &the_ins.operands[0];
1248 /* Warning: this switch is huge! */
1249 /* I've tried to organize the cases into this order:
1250 non-alpha first, then alpha by letter. Lower-case
1251 goes directly before uppercase counterpart. */
1252 /* Code with multiple case ...: gets sorted by the lowest
1253 case ... it belongs to. I hope this makes sense. */
1359 if (opP->reg == PC || opP->reg == ZPC)
1376 if (opP->reg == PC || opP->reg == ZPC)
1395 if (opP->reg == PC || opP->reg == ZPC)
1405 if (opP->mode != IMMED)
1407 else if (s[1] == 'b'
1408 && ! isvar (&opP->disp)
1409 && (opP->disp.exp.X_op != O_constant
1410 || ! isbyte (opP->disp.exp.X_add_number)))
1412 else if (s[1] == 'B'
1413 && ! isvar (&opP->disp)
1414 && (opP->disp.exp.X_op != O_constant
1415 || ! issbyte (opP->disp.exp.X_add_number)))
1417 else if (s[1] == 'w'
1418 && ! isvar (&opP->disp)
1419 && (opP->disp.exp.X_op != O_constant
1420 || ! isword (opP->disp.exp.X_add_number)))
1422 else if (s[1] == 'W'
1423 && ! isvar (&opP->disp)
1424 && (opP->disp.exp.X_op != O_constant
1425 || ! issword (opP->disp.exp.X_add_number)))
1431 if (opP->mode != IMMED)
1436 if (opP->mode == AREG
1437 || opP->mode == CONTROL
1438 || opP->mode == FPREG
1439 || opP->mode == IMMED
1440 || opP->mode == REGLST
1441 || (opP->mode != ABSL
1443 || opP->reg == ZPC)))
1448 if (opP->mode == CONTROL
1449 || opP->mode == FPREG
1450 || opP->mode == REGLST
1451 || opP->mode == IMMED
1452 || (opP->mode != ABSL
1454 || opP->reg == ZPC)))
1482 if (opP->mode == CONTROL
1483 || opP->mode == FPREG
1484 || opP->mode == REGLST)
1489 if (opP->mode != AINC)
1494 if (opP->mode != ADEC)
1544 if (opP->reg == PC || opP->reg == ZPC)
1565 case '~': /* For now! (JF FOO is this right?) */
1587 if (opP->mode != CONTROL
1588 || (opP->reg != TT0 && opP->reg != TT1))
1593 if (opP->mode != AREG)
1598 if (opP->mode != AINDR)
1603 if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
1604 && (opP->mode != DISP
1606 || opP->reg > ADDR7))
1611 if (opP->mode != ABSL
1613 && strncmp (instring, "jbsr", 4) == 0))
1636 if (opP->mode != CONTROL || opP->reg != CCR)
1641 if (opP->mode != DISP
1643 || opP->reg > ADDR7)
1648 if (opP->mode != DREG)
1653 if (opP->reg != ACC)
1658 if (opP->reg != ACC && opP->reg != ACC1
1659 && opP->reg != ACC2 && opP->reg != ACC3)
1664 if (opP->mode != FPREG)
1669 if (opP->reg != MACSR)
1674 if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
1679 if (opP->reg != MASK)
1684 if (opP->mode != CONTROL
1691 if (opP->mode != LSH && opP->mode != RSH)
1696 if (opP->mode != CONTROL
1698 || opP->reg > last_movec_reg)
1702 const enum m68k_register *rp;
1703 for (rp = control_regs; *rp; rp++)
1704 if (*rp == opP->reg)
1712 if (opP->mode != IMMED)
1718 if (opP->mode == DREG
1719 || opP->mode == AREG
1720 || opP->mode == FPREG)
1729 opP->mask = 1 << (opP->reg - DATA0);
1732 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1735 opP->mask = 1 << (opP->reg - FP0 + 16);
1743 else if (opP->mode == CONTROL)
1752 opP->mask = 1 << 24;
1755 opP->mask = 1 << 25;
1758 opP->mask = 1 << 26;
1767 else if (opP->mode != REGLST)
1769 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1771 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1776 if (opP->mode != IMMED)
1778 else if (opP->disp.exp.X_op != O_constant
1779 || ! issbyte (opP->disp.exp.X_add_number))
1781 else if (! m68k_quick
1782 && instring[3] != 'q'
1783 && instring[4] != 'q')
1788 if (opP->mode != DREG
1789 && opP->mode != IMMED
1790 && opP->mode != ABSL)
1795 if (opP->mode != IMMED)
1797 else if (opP->disp.exp.X_op != O_constant
1798 || opP->disp.exp.X_add_number < 1
1799 || opP->disp.exp.X_add_number > 8)
1801 else if (! m68k_quick
1802 && (strncmp (instring, "add", 3) == 0
1803 || strncmp (instring, "sub", 3) == 0)
1804 && instring[3] != 'q')
1809 if (opP->mode != DREG && opP->mode != AREG)
1814 if (opP->mode != AINDR
1815 && (opP->mode != BASE
1817 && opP->reg != ZADDR0)
1818 || opP->disp.exp.X_op != O_absent
1819 || ((opP->index.reg < DATA0
1820 || opP->index.reg > DATA7)
1821 && (opP->index.reg < ADDR0
1822 || opP->index.reg > ADDR7))
1823 || opP->index.size != SIZE_UNSPEC
1824 || opP->index.scale != 1))
1829 if (opP->mode != CONTROL
1830 || ! (opP->reg == FPI
1832 || opP->reg == FPC))
1837 if (opP->mode != CONTROL || opP->reg != SR)
1842 if (opP->mode != IMMED)
1844 else if (opP->disp.exp.X_op != O_constant
1845 || opP->disp.exp.X_add_number < 0
1846 || opP->disp.exp.X_add_number > 7)
1851 if (opP->mode != CONTROL || opP->reg != USP)
1856 if (opP->mode != IMMED)
1858 else if (opP->disp.exp.X_op != O_constant
1859 || opP->disp.exp.X_add_number < -1
1860 || opP->disp.exp.X_add_number > 7
1861 || opP->disp.exp.X_add_number == 0)
1865 /* JF these are out of order. We could put them
1866 in order if we were willing to put up with
1867 bunches of #ifdef m68851s in the code.
1869 Don't forget that you need these operands
1870 to use 68030 MMU instructions. */
1872 /* Memory addressing mode used by pflushr. */
1874 if (opP->mode == CONTROL
1875 || opP->mode == FPREG
1876 || opP->mode == DREG
1877 || opP->mode == AREG
1878 || opP->mode == REGLST)
1880 /* We should accept immediate operands, but they
1881 supposedly have to be quad word, and we don't
1882 handle that. I would like to see what a Motorola
1883 assembler does before doing something here. */
1884 if (opP->mode == IMMED)
1889 if (opP->mode != CONTROL
1890 || (opP->reg != SFC && opP->reg != DFC))
1895 if (opP->mode != CONTROL || opP->reg != TC)
1900 if (opP->mode != CONTROL || opP->reg != AC)
1905 if (opP->mode != CONTROL
1908 && opP->reg != SCC))
1913 if (opP->mode != CONTROL
1919 if (opP->mode != CONTROL
1922 && opP->reg != CRP))
1946 if (opP->mode != CONTROL
1947 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1948 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1953 if (opP->mode != CONTROL || opP->reg != PSR)
1958 if (opP->mode != CONTROL || opP->reg != PCSR)
1963 if (opP->mode != CONTROL
1972 if (opP->mode != ABSL)
1977 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1979 /* FIXME: kludge instead of fixing parser:
1980 upper/lower registers are *not* CONTROL
1981 registers, but ordinary ones. */
1982 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1983 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1990 if (!(opP->mode == AINDR
1991 || (opP->mode == DISP && !(opP->reg == PC ||
1997 if (!(opP->mode == AINDR || opP->mode == DISP))
2013 opcode = opcode->m_next;
2018 && !(ok_arch & current_architecture))
2023 _("invalid instruction for this architecture; needs "), sizeof (buf));
2024 cp = buf + strlen (buf);
2028 strncpy (cp, _("ColdFire ISA_A"), (sizeof (buf) - (cp - buf)));
2030 strncpy (cp, find_cf_chip (ok_arch), (sizeof (buf) - (cp - buf)));
2034 strncpy (cp, _("ColdFire hardware divide"), (sizeof (buf) - (cp - buf)));
2036 strncpy (cp, find_cf_chip (ok_arch), (sizeof (buf) - (cp - buf)));
2040 strncpy (cp, _("ColdFire ISA_A+"), (sizeof (buf) - (cp - buf)));
2042 strncpy (cp, find_cf_chip (ok_arch), (sizeof (buf) - (cp - buf)));
2046 strncpy (cp, _("ColdFire ISA_B"), (sizeof (buf) - (cp - buf)));
2048 strncpy (cp, find_cf_chip (ok_arch), (sizeof (buf) - (cp - buf)));
2052 strncpy (cp, _("ColdFire fpu"), (sizeof (buf) - (cp - buf)));
2054 strncpy (cp, find_cf_chip (ok_arch), (sizeof (buf) - (cp - buf)));
2058 strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
2061 strcpy (cp, _("mmu (68030 or 68851)"));
2064 strcpy (cp, _("68020 or higher"));
2067 strcpy (cp, _("68000 or higher"));
2070 strcpy (cp, _("68010 or higher"));
2074 int got_one = 0, idx;
2076 for (idx = 0; idx < n_archs; idx++)
2078 if ((archs[idx].arch & ok_arch)
2079 && ! archs[idx].alias)
2083 strcpy (cp, " or ");
2087 strcpy (cp, archs[idx].name);
2093 cp = xmalloc (strlen (buf) + 1);
2098 the_ins.error = _("operands mismatch");
2105 /* Now assemble it. */
2106 the_ins.args = opcode->m_operands;
2107 the_ins.numargs = opcode->m_opnum;
2108 the_ins.numo = opcode->m_codenum;
2109 the_ins.opcode[0] = getone (opcode);
2110 the_ins.opcode[1] = gettwo (opcode);
2112 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
2114 /* This switch is a doozy.
2115 Watch the first step; its a big one! */
2148 tmpreg = 0x3c; /* 7.4 */
2149 if (strchr ("bwl", s[1]))
2150 nextword = get_num (&opP->disp, 90);
2152 nextword = get_num (&opP->disp, 0);
2153 if (isvar (&opP->disp))
2154 add_fix (s[1], &opP->disp, 0, 0);
2158 if (!isbyte (nextword))
2159 opP->error = _("operand out of range");
2164 if (!isword (nextword))
2165 opP->error = _("operand out of range");
2170 if (!issword (nextword))
2171 opP->error = _("operand out of range");
2176 addword (nextword >> 16);
2203 /* We gotta put out some float. */
2204 if (op (&opP->disp) != O_big)
2209 /* Can other cases happen here? */
2210 if (op (&opP->disp) != O_constant)
2213 val = (valueT) offs (&opP->disp);
2217 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2218 val >>= LITTLENUM_NUMBER_OF_BITS;
2222 offs (&opP->disp) = gencnt;
2224 if (offs (&opP->disp) > 0)
2226 if (offs (&opP->disp) > baseo)
2228 as_warn (_("Bignum too big for %c format; truncated"),
2230 offs (&opP->disp) = baseo;
2232 baseo -= offs (&opP->disp);
2235 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2236 offs (&opP->disp)--;
2241 gen_to_words (words, baseo, (long) outro);
2242 for (wordp = words; baseo--; wordp++)
2246 tmpreg = opP->reg - DATA; /* 0.dreg */
2249 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2252 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2255 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2258 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2262 nextword = get_num (&opP->disp, 90);
2264 /* Convert mode 5 addressing with a zero offset into
2265 mode 2 addressing to reduce the instruction size by a
2267 if (! isvar (&opP->disp)
2269 && (opP->disp.size == SIZE_UNSPEC)
2270 && (opP->reg >= ADDR0)
2271 && (opP->reg <= ADDR7))
2273 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2278 && ! isvar (&opP->disp)
2281 opP->disp.exp.X_op = O_symbol;
2282 #ifndef BFD_ASSEMBLER
2283 opP->disp.exp.X_add_symbol = &abs_symbol;
2285 opP->disp.exp.X_add_symbol =
2286 section_symbol (absolute_section);
2290 /* Force into index mode. Hope this works. */
2292 /* We do the first bit for 32-bit displacements, and the
2293 second bit for 16 bit ones. It is possible that we
2294 should make the default be WORD instead of LONG, but
2295 I think that'd break GCC, so we put up with a little
2296 inefficiency for the sake of working output. */
2298 if (!issword (nextword)
2299 || (isvar (&opP->disp)
2300 && ((opP->disp.size == SIZE_UNSPEC
2301 && flag_short_refs == 0
2302 && cpu_of_arch (current_architecture) >= m68020
2303 && ! arch_coldfire_p (current_architecture))
2304 || opP->disp.size == SIZE_LONG)))
2306 if (cpu_of_arch (current_architecture) < m68020
2307 || arch_coldfire_p (current_architecture))
2309 _("displacement too large for this architecture; needs 68020 or higher");
2311 tmpreg = 0x3B; /* 7.3 */
2313 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2314 if (isvar (&opP->disp))
2318 if (opP->disp.size == SIZE_LONG
2320 /* If the displacement needs pic
2321 relocation it cannot be relaxed. */
2322 || opP->disp.pic_reloc != pic_none
2327 add_fix ('l', &opP->disp, 1, 2);
2331 add_frag (adds (&opP->disp),
2333 TAB (PCREL1632, SZ_UNDEF));
2340 add_fix ('l', &opP->disp, 0, 0);
2345 addword (nextword >> 16);
2350 tmpreg = 0x3A; /* 7.2 */
2352 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2354 if (isvar (&opP->disp))
2358 add_fix ('w', &opP->disp, 1, 0);
2361 add_fix ('w', &opP->disp, 0, 0);
2371 baseo = get_num (&opP->disp, 90);
2372 if (opP->mode == POST || opP->mode == PRE)
2373 outro = get_num (&opP->odisp, 90);
2374 /* Figure out the `addressing mode'.
2375 Also turn on the BASE_DISABLE bit, if needed. */
2376 if (opP->reg == PC || opP->reg == ZPC)
2378 tmpreg = 0x3b; /* 7.3 */
2379 if (opP->reg == ZPC)
2382 else if (opP->reg == 0)
2385 tmpreg = 0x30; /* 6.garbage */
2387 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2390 tmpreg = 0x30 + opP->reg - ZADDR0;
2393 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2395 siz1 = opP->disp.size;
2396 if (opP->mode == POST || opP->mode == PRE)
2397 siz2 = opP->odisp.size;
2401 /* Index register stuff. */
2402 if (opP->index.reg != 0
2403 && opP->index.reg >= DATA
2404 && opP->index.reg <= ADDR7)
2406 nextword |= (opP->index.reg - DATA) << 12;
2408 if (opP->index.size == SIZE_LONG
2409 || (opP->index.size == SIZE_UNSPEC
2410 && m68k_index_width_default == SIZE_LONG))
2413 if ((opP->index.scale != 1
2414 && cpu_of_arch (current_architecture) < m68020)
2415 || (opP->index.scale == 8
2416 && (arch_coldfire_p (current_architecture)
2417 && !arch_coldfire_fpu (current_architecture))))
2420 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2423 if (arch_coldfire_p (current_architecture)
2424 && opP->index.size == SIZE_WORD)
2425 opP->error = _("invalid index size for coldfire");
2427 switch (opP->index.scale)
2444 GET US OUT OF HERE! */
2446 /* Must be INDEX, with an index register. Address
2447 register cannot be ZERO-PC, and either :b was
2448 forced, or we know it will fit. For a 68000 or
2449 68010, force this mode anyways, because the
2450 larger modes aren't supported. */
2451 if (opP->mode == BASE
2452 && ((opP->reg >= ADDR0
2453 && opP->reg <= ADDR7)
2456 if (siz1 == SIZE_BYTE
2457 || cpu_of_arch (current_architecture) < m68020
2458 || arch_coldfire_p (current_architecture)
2459 || (siz1 == SIZE_UNSPEC
2460 && ! isvar (&opP->disp)
2461 && issbyte (baseo)))
2463 nextword += baseo & 0xff;
2465 if (isvar (&opP->disp))
2467 /* Do a byte relocation. If it doesn't
2468 fit (possible on m68000) let the
2469 fixup processing complain later. */
2471 add_fix ('B', &opP->disp, 1, 1);
2473 add_fix ('B', &opP->disp, 0, 0);
2475 else if (siz1 != SIZE_BYTE)
2477 if (siz1 != SIZE_UNSPEC)
2478 as_warn (_("Forcing byte displacement"));
2479 if (! issbyte (baseo))
2480 opP->error = _("byte displacement out of range");
2485 else if (siz1 == SIZE_UNSPEC
2487 && isvar (&opP->disp)
2488 && subs (&opP->disp) == NULL
2490 /* If the displacement needs pic
2491 relocation it cannot be relaxed. */
2492 && opP->disp.pic_reloc == pic_none
2496 /* The code in md_convert_frag_1 needs to be
2497 able to adjust nextword. Call frag_grow
2498 to ensure that we have enough space in
2499 the frag obstack to make all the bytes
2502 nextword += baseo & 0xff;
2504 add_frag (adds (&opP->disp), offs (&opP->disp),
2505 TAB (PCINDEX, SZ_UNDEF));
2513 nextword |= 0x40; /* No index reg. */
2514 if (opP->index.reg >= ZDATA0
2515 && opP->index.reg <= ZDATA7)
2516 nextword |= (opP->index.reg - ZDATA0) << 12;
2517 else if (opP->index.reg >= ZADDR0
2518 || opP->index.reg <= ZADDR7)
2519 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2522 /* It isn't simple. */
2524 if (cpu_of_arch (current_architecture) < m68020
2525 || arch_coldfire_p (current_architecture))
2527 _("invalid operand mode for this architecture; needs 68020 or higher");
2530 /* If the guy specified a width, we assume that it is
2531 wide enough. Maybe it isn't. If so, we lose. */
2535 if (isvar (&opP->disp)
2537 : ! issword (baseo))
2542 else if (! isvar (&opP->disp) && baseo == 0)
2551 as_warn (_(":b not permitted; defaulting to :w"));
2561 /* Figure out inner displacement stuff. */
2562 if (opP->mode == POST || opP->mode == PRE)
2564 if (cpu_of_arch (current_architecture) & cpu32)
2565 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2569 if (isvar (&opP->odisp)
2571 : ! issword (outro))
2576 else if (! isvar (&opP->odisp) && outro == 0)
2585 as_warn (_(":b not permitted; defaulting to :w"));
2594 if (opP->mode == POST
2595 && (nextword & 0x40) == 0)
2600 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2602 if (opP->reg == PC || opP->reg == ZPC)
2603 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2605 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2607 if (siz1 == SIZE_LONG)
2608 addword (baseo >> 16);
2609 if (siz1 != SIZE_UNSPEC)
2612 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2613 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2614 if (siz2 == SIZE_LONG)
2615 addword (outro >> 16);
2616 if (siz2 != SIZE_UNSPEC)
2622 nextword = get_num (&opP->disp, 90);
2623 switch (opP->disp.size)
2628 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2630 tmpreg = 0x38; /* 7.0 */
2634 if (isvar (&opP->disp)
2635 && !subs (&opP->disp)
2636 && adds (&opP->disp)
2638 /* If the displacement needs pic relocation it
2639 cannot be relaxed. */
2640 && opP->disp.pic_reloc == pic_none
2643 && !strchr ("~%&$?", s[0]))
2645 tmpreg = 0x3A; /* 7.2 */
2646 add_frag (adds (&opP->disp),
2648 TAB (ABSTOPCREL, SZ_UNDEF));
2651 /* Fall through into long. */
2653 if (isvar (&opP->disp))
2654 add_fix ('l', &opP->disp, 0, 0);
2656 tmpreg = 0x39;/* 7.1 mode */
2657 addword (nextword >> 16);
2662 as_bad (_("unsupported byte value; use a different suffix"));
2666 if (isvar (&opP->disp))
2667 add_fix ('w', &opP->disp, 0, 0);
2669 tmpreg = 0x38;/* 7.0 mode */
2677 as_bad (_("unknown/incorrect operand"));
2681 /* If s[0] is '4', then this is for the mac instructions
2682 that can have a trailing_ampersand set. If so, set 0x100
2683 bit on tmpreg so install_gen_operand can check for it and
2684 set the appropriate bit (word2, bit 5). */
2687 if (opP->trailing_ampersand)
2690 install_gen_operand (s[1], tmpreg);
2696 { /* JF: I hate floating point! */
2711 tmpreg = get_num (&opP->disp, tmpreg);
2712 if (isvar (&opP->disp))
2713 add_fix (s[1], &opP->disp, 0, 0);
2716 case 'b': /* Danger: These do no check for
2717 certain types of overflow.
2719 if (!isbyte (tmpreg))
2720 opP->error = _("out of range");
2721 insop (tmpreg, opcode);
2722 if (isvar (&opP->disp))
2723 the_ins.reloc[the_ins.nrel - 1].n =
2724 (opcode->m_codenum) * 2 + 1;
2727 if (!issbyte (tmpreg))
2728 opP->error = _("out of range");
2729 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2730 if (isvar (&opP->disp))
2731 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2734 if (!isword (tmpreg))
2735 opP->error = _("out of range");
2736 insop (tmpreg, opcode);
2737 if (isvar (&opP->disp))
2738 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2741 if (!issword (tmpreg))
2742 opP->error = _("out of range");
2743 insop (tmpreg, opcode);
2744 if (isvar (&opP->disp))
2745 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2748 /* Because of the way insop works, we put these two out
2750 insop (tmpreg, opcode);
2751 insop (tmpreg >> 16, opcode);
2752 if (isvar (&opP->disp))
2753 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2760 install_operand (s[1], tmpreg);
2771 install_operand (s[1], opP->reg - ADDR);
2775 tmpreg = get_num (&opP->disp, 90);
2779 add_fix ('B', &opP->disp, 1, -1);
2782 add_fix ('w', &opP->disp, 1, 0);
2787 if (! HAVE_LONG_BRANCH (current_architecture))
2788 as_warn (_("Can't use long branches on 68000/68010/5200"));
2789 the_ins.opcode[0] |= 0xff;
2790 add_fix ('l', &opP->disp, 1, 0);
2795 if (subs (&opP->disp)) /* We can't relax it. */
2799 /* If the displacement needs pic relocation it cannot be
2801 if (opP->disp.pic_reloc != pic_none)
2804 /* This could either be a symbol, or an absolute
2805 address. If it's an absolute address, turn it into
2806 an absolute jump right here and keep it out of the
2808 if (adds (&opP->disp) == 0)
2810 if (the_ins.opcode[0] == 0x6000) /* jbra */
2811 the_ins.opcode[0] = 0x4EF9;
2812 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2813 the_ins.opcode[0] = 0x4EB9;
2816 the_ins.opcode[0] ^= 0x0100;
2817 the_ins.opcode[0] |= 0x0006;
2820 add_fix ('l', &opP->disp, 0, 0);
2826 /* Now we know it's going into the relaxer. Now figure
2827 out which mode. We try in this order of preference:
2828 long branch, absolute jump, byte/word branches only. */
2829 if (HAVE_LONG_BRANCH (current_architecture))
2830 add_frag (adds (&opP->disp), offs (&opP->disp),
2831 TAB (BRANCHBWL, SZ_UNDEF));
2832 else if (! flag_keep_pcrel)
2834 if ((the_ins.opcode[0] == 0x6000)
2835 || (the_ins.opcode[0] == 0x6100))
2836 add_frag (adds (&opP->disp), offs (&opP->disp),
2837 TAB (BRABSJUNC, SZ_UNDEF));
2839 add_frag (adds (&opP->disp), offs (&opP->disp),
2840 TAB (BRABSJCOND, SZ_UNDEF));
2843 add_frag (adds (&opP->disp), offs (&opP->disp),
2844 TAB (BRANCHBW, SZ_UNDEF));
2847 if (isvar (&opP->disp))
2849 /* Check for DBcc instructions. We can relax them,
2850 but only if we have long branches and/or absolute
2852 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2853 && (HAVE_LONG_BRANCH (current_architecture)
2854 || (! flag_keep_pcrel)))
2856 if (HAVE_LONG_BRANCH (current_architecture))
2857 add_frag (adds (&opP->disp), offs (&opP->disp),
2858 TAB (DBCCLBR, SZ_UNDEF));
2860 add_frag (adds (&opP->disp), offs (&opP->disp),
2861 TAB (DBCCABSJ, SZ_UNDEF));
2864 add_fix ('w', &opP->disp, 1, 0);
2868 case 'C': /* Fixed size LONG coproc branches. */
2869 add_fix ('l', &opP->disp, 1, 0);
2873 case 'c': /* Var size Coprocesssor branches. */
2874 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
2876 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2877 add_fix ('l', &opP->disp, 1, 0);
2882 add_frag (adds (&opP->disp), offs (&opP->disp),
2883 TAB (FBRANCH, SZ_UNDEF));
2890 case 'C': /* Ignore it. */
2893 case 'd': /* JF this is a kludge. */
2894 install_operand ('s', opP->reg - ADDR);
2895 tmpreg = get_num (&opP->disp, 90);
2896 if (!issword (tmpreg))
2898 as_warn (_("Expression out of range, using 0"));
2905 install_operand (s[1], opP->reg - DATA);
2908 case 'e': /* EMAC ACCx, reg/reg. */
2909 install_operand (s[1], opP->reg - ACC);
2912 case 'E': /* Ignore it. */
2916 install_operand (s[1], opP->reg - FP0);
2919 case 'g': /* EMAC ACCEXTx. */
2920 install_operand (s[1], opP->reg - ACCEXT01);
2923 case 'G': /* Ignore it. */
2928 tmpreg = opP->reg - COP0;
2929 install_operand (s[1], tmpreg);
2932 case 'i': /* MAC/EMAC scale factor. */
2933 install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
2936 case 'J': /* JF foo. */
3065 install_operand (s[1], tmpreg);
3069 tmpreg = get_num (&opP->disp, 55);
3070 install_operand (s[1], tmpreg & 0x7f);
3077 if (tmpreg & 0x7FF0000)
3078 as_bad (_("Floating point register in register list"));
3079 insop (reverse_16_bits (tmpreg), opcode);
3083 if (tmpreg & 0x700FFFF)
3084 as_bad (_("Wrong register in floating-point reglist"));
3085 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
3093 if (tmpreg & 0x7FF0000)
3094 as_bad (_("Floating point register in register list"));
3095 insop (tmpreg, opcode);
3097 else if (s[1] == '8')
3099 if (tmpreg & 0x0FFFFFF)
3100 as_bad (_("incorrect register in reglist"));
3101 install_operand (s[1], tmpreg >> 24);
3105 if (tmpreg & 0x700FFFF)
3106 as_bad (_("wrong register in floating-point reglist"));
3108 install_operand (s[1], tmpreg >> 16);
3113 install_operand (s[1], get_num (&opP->disp, 60));
3117 tmpreg = ((opP->mode == DREG)
3118 ? 0x20 + (int) (opP->reg - DATA)
3119 : (get_num (&opP->disp, 40) & 0x1F));
3120 install_operand (s[1], tmpreg);
3124 tmpreg = get_num (&opP->disp, 10);
3127 install_operand (s[1], tmpreg);
3131 /* This depends on the fact that ADDR registers are eight
3132 more than their corresponding DATA regs, so the result
3133 will have the ADDR_REG bit set. */
3134 install_operand (s[1], opP->reg - DATA);
3138 if (opP->mode == AINDR)
3139 install_operand (s[1], opP->reg - DATA);
3141 install_operand (s[1], opP->index.reg - DATA);
3145 if (opP->reg == FPI)
3147 else if (opP->reg == FPS)
3149 else if (opP->reg == FPC)
3153 install_operand (s[1], tmpreg);
3156 case 'S': /* Ignore it. */
3160 install_operand (s[1], get_num (&opP->disp, 30));
3163 case 'U': /* Ignore it. */
3182 as_fatal (_("failed sanity check"));
3183 } /* switch on cache token. */
3184 install_operand (s[1], tmpreg);
3187 /* JF: These are out of order, I fear. */
3200 install_operand (s[1], tmpreg);
3226 install_operand (s[1], tmpreg);
3230 if (opP->reg == VAL)
3249 install_operand (s[1], tmpreg);
3263 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
3274 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
3280 install_operand (s[1], tmpreg);
3283 know (opP->reg == PSR);
3286 know (opP->reg == PCSR);
3301 install_operand (s[1], tmpreg);
3304 tmpreg = get_num (&opP->disp, 20);
3305 install_operand (s[1], tmpreg);
3307 case '_': /* used only for move16 absolute 32-bit address. */
3308 if (isvar (&opP->disp))
3309 add_fix ('l', &opP->disp, 0, 0);
3310 tmpreg = get_num (&opP->disp, 90);
3311 addword (tmpreg >> 16);
3312 addword (tmpreg & 0xFFFF);
3315 install_operand (s[1], opP->reg - DATA0L);
3316 opP->reg -= (DATA0L);
3317 opP->reg &= 0x0F; /* remove upper/lower bit. */
3320 tmpreg = get_num (&opP->disp, 80);
3323 install_operand (s[1], tmpreg);
3330 /* By the time whe get here (FINALLY) the_ins contains the complete
3331 instruction, ready to be emitted. . . */
3335 reverse_16_bits (in)
3341 static int mask[16] =
3343 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3344 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3346 for (n = 0; n < 16; n++)
3349 out |= mask[15 - n];
3352 } /* reverse_16_bits() */
3361 static int mask[8] =
3363 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3366 for (n = 0; n < 8; n++)
3372 } /* reverse_8_bits() */
3374 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3375 (that value is chosen in the frag_var call in md_assemble). TYPE
3376 is the subtype of the frag to be generated; its primary type is
3377 rs_machine_dependent.
3379 The TYPE parameter is also used by md_convert_frag_1 and
3380 md_estimate_size_before_relax. The appropriate type of fixup will
3381 be emitted by md_convert_frag_1.
3383 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3385 install_operand (mode, val)
3392 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
3395 the_ins.opcode[0] |= val << 9;
3398 the_ins.opcode[1] |= val << 12;
3401 the_ins.opcode[1] |= val << 6;
3404 the_ins.opcode[1] |= val;
3407 the_ins.opcode[2] |= val << 12;
3410 the_ins.opcode[2] |= val << 6;
3413 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3414 three words long! */
3416 the_ins.opcode[2] |= val;
3419 the_ins.opcode[1] |= val << 7;
3422 the_ins.opcode[1] |= val << 10;
3426 the_ins.opcode[1] |= val << 5;
3431 the_ins.opcode[1] |= (val << 10) | (val << 7);
3434 the_ins.opcode[1] |= (val << 12) | val;
3437 the_ins.opcode[0] |= val = 0xff;
3440 the_ins.opcode[0] |= val << 9;
3443 the_ins.opcode[1] |= val;
3446 the_ins.opcode[1] |= val;
3447 the_ins.numo++; /* What a hack. */
3450 the_ins.opcode[1] |= val << 4;
3458 the_ins.opcode[0] |= (val << 6);
3461 the_ins.opcode[1] = (val >> 16);
3462 the_ins.opcode[2] = val & 0xffff;
3465 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3466 the_ins.opcode[0] |= ((val & 0x7) << 9);
3467 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3469 case 'n': /* MAC/EMAC Rx on !load. */
3470 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3471 the_ins.opcode[0] |= ((val & 0x7) << 9);
3472 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3474 case 'o': /* MAC/EMAC Rx on load. */
3475 the_ins.opcode[1] |= val << 12;
3476 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3478 case 'M': /* MAC/EMAC Ry on !load. */
3479 the_ins.opcode[0] |= (val & 0xF);
3480 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3482 case 'N': /* MAC/EMAC Ry on load. */
3483 the_ins.opcode[1] |= (val & 0xF);
3484 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3487 the_ins.opcode[1] |= ((val != 1) << 10);
3490 the_ins.opcode[0] |= ((val & 0x3) << 9);
3493 the_ins.opcode[0] |= ((val & 0x3) << 0);
3495 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3496 the_ins.opcode[0] |= ((~val & 0x1) << 7);
3497 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3499 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3500 the_ins.opcode[0] |= ((val & 0x1) << 7);
3501 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3504 the_ins.opcode[1] |= ((val & 0x3) << 9);
3507 the_ins.opcode[0] |= (val & 0x1) <<10;
3511 as_fatal (_("failed sanity check."));
3516 install_gen_operand (mode, val)
3522 case '/': /* Special for mask loads for mac/msac insns with
3523 possible mask; trailing_ampersend set in bit 8. */
3524 the_ins.opcode[0] |= (val & 0x3f);
3525 the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
3528 the_ins.opcode[0] |= val;
3531 /* This is a kludge!!! */
3532 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3541 the_ins.opcode[0] |= val;
3543 /* more stuff goes here. */
3545 as_fatal (_("failed sanity check."));
3549 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3550 then deal with the bitfield hack. */
3553 crack_operand (str, opP)
3555 register struct m68k_op *opP;
3557 register int parens;
3559 register char *beg_str;
3567 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3573 else if (*str == ')')
3577 opP->error = _("Extra )");
3583 if (flag_mri && *str == '\'')
3584 inquote = ! inquote;
3586 if (!*str && parens)
3588 opP->error = _("Missing )");
3593 if (m68k_ip_op (beg_str, opP) != 0)
3600 c = *++str; /* JF bitfield hack. */
3605 as_bad (_("Missing operand"));
3608 /* Detect MRI REG symbols and convert them to REGLSTs. */
3609 if (opP->mode == CONTROL && (int)opP->reg < 0)
3612 opP->mask = ~(int)opP->reg;
3619 /* This is the guts of the machine-dependent assembler. STR points to a
3620 machine dependent instruction. This function is supposed to emit
3621 the frags/bytes it assembles to.
3625 insert_reg (regname, regnum)
3626 const char *regname;
3632 #ifdef REGISTER_PREFIX
3633 if (!flag_reg_prefix_optional)
3635 buf[0] = REGISTER_PREFIX;
3636 strcpy (buf + 1, regname);
3641 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3642 &zero_address_frag));
3644 for (i = 0; regname[i]; i++)
3645 buf[i] = TOUPPER (regname[i]);
3648 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3649 &zero_address_frag));
3658 static const struct init_entry init_table[] =
3718 { "accext01", ACCEXT01 },
3719 { "accext23", ACCEXT23 },
3723 /* Control registers. */
3724 { "sfc", SFC }, /* Source Function Code. */
3726 { "dfc", DFC }, /* Destination Function Code. */
3728 { "cacr", CACR }, /* Cache Control Register. */
3729 { "caar", CAAR }, /* Cache Address Register. */
3731 { "usp", USP }, /* User Stack Pointer. */
3732 { "vbr", VBR }, /* Vector Base Register. */
3733 { "msp", MSP }, /* Master Stack Pointer. */
3734 { "isp", ISP }, /* Interrupt Stack Pointer. */
3736 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
3737 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
3738 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
3739 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
3741 /* 68ec040 versions of same */
3742 { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
3743 { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
3744 { "dacr0", DTT0 }, /* Data Access Control Register 0. */
3745 { "dacr1", DTT1 }, /* Data Access Control Register 0. */
3747 /* mcf5200 versions of same. The ColdFire programmer's reference
3748 manual indicated that the order is 2,3,0,1, but Ken Rose
3749 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3750 { "acr0", ACR0 }, /* Access Control Unit 0. */
3751 { "acr1", ACR1 }, /* Access Control Unit 1. */
3752 { "acr2", ACR2 }, /* Access Control Unit 2. */
3753 { "acr3", ACR3 }, /* Access Control Unit 3. */
3755 { "tc", TC }, /* MMU Translation Control Register. */
3758 { "mmusr", MMUSR }, /* MMU Status Register. */
3759 { "srp", SRP }, /* User Root Pointer. */
3760 { "urp", URP }, /* Supervisor Root Pointer. */
3765 { "rombar", ROMBAR }, /* ROM Base Address Register. */
3766 { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
3767 { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
3768 { "mbar", MBAR }, /* Module Base Address Register. */
3770 { "mbar0", MBAR0 }, /* mcfv4e registers. */
3771 { "mbar1", MBAR1 }, /* mcfv4e registers. */
3772 { "rombar0", ROMBAR }, /* mcfv4e registers. */
3773 { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
3774 { "mpcr", MPCR }, /* mcfv4e registers. */
3775 { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
3776 { "secmbar", SECMBAR }, /* mcfv4e registers. */
3777 { "asid", TC }, /* mcfv4e registers. */
3778 { "mmubar", BUSCR }, /* mcfv4e registers. */
3779 { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
3780 { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
3781 { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
3782 { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
3783 { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
3784 { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
3785 { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
3786 { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
3787 { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
3788 { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
3789 { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
3790 { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
3792 { "flashbar", FLASHBAR }, /* mcf528x registers. */
3793 { "rambar", RAMBAR }, /* mcf528x registers. */
3794 /* End of control registers. */
3828 /* 68ec030 versions of same. */
3831 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3834 /* Suppressed data and address registers. */
3852 /* Upper and lower data and address registers, used by macw and msacw. */
3896 for (i = 0; init_table[i].name; i++)
3897 insert_reg (init_table[i].name, init_table[i].number);
3900 static int no_68851, no_68881;
3903 /* a.out machine type. Default to 68020. */
3904 int m68k_aout_machtype = 2;
3916 int shorts_this_frag;
3919 /* In MRI mode, the instruction and operands are separated by a
3920 space. Anything following the operands is a comment. The label
3921 has already been removed. */
3929 for (s = str; *s != '\0'; s++)
3931 if ((*s == ' ' || *s == '\t') && ! inquote)
3949 inquote = ! inquote;
3954 memset ((char *) (&the_ins), '\0', sizeof (the_ins));
3959 for (n = 0; n < the_ins.numargs; n++)
3960 if (the_ins.operands[n].error)
3962 er = the_ins.operands[n].error;
3968 as_bad (_("%s -- statement `%s' ignored"), er, str);
3972 /* If there is a current label, record that it marks an instruction. */
3973 if (current_label != NULL)
3975 current_label->text = 1;
3976 current_label = NULL;
3980 /* Tie dwarf2 debug info to the address at the start of the insn. */
3981 dwarf2_emit_insn (0);
3984 if (the_ins.nfrag == 0)
3986 /* No frag hacking involved; just put it out. */
3987 toP = frag_more (2 * the_ins.numo);
3988 fromP = &the_ins.opcode[0];
3989 for (m = the_ins.numo; m; --m)
3991 md_number_to_chars (toP, (long) (*fromP), 2);
3995 /* Put out symbol-dependent info. */
3996 for (m = 0; m < the_ins.nrel; m++)
3998 switch (the_ins.reloc[m].wid)
4017 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4018 the_ins.reloc[m].wid);
4021 fixP = fix_new_exp (frag_now,
4022 ((toP - frag_now->fr_literal)
4023 - the_ins.numo * 2 + the_ins.reloc[m].n),
4025 &the_ins.reloc[m].exp,
4026 the_ins.reloc[m].pcrel,
4027 get_reloc_code (n, the_ins.reloc[m].pcrel,
4028 the_ins.reloc[m].pic_reloc));
4029 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4030 if (the_ins.reloc[m].wid == 'B')
4031 fixP->fx_signed = 1;
4036 /* There's some frag hacking. */
4038 /* Calculate the max frag size. */
4041 wid = 2 * the_ins.fragb[0].fragoff;
4042 for (n = 1; n < the_ins.nfrag; n++)
4043 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4044 /* frag_var part. */
4046 /* Make sure the whole insn fits in one chunk, in particular that
4047 the var part is attached, as we access one byte before the
4048 variable frag for byte branches. */
4052 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
4057 wid = 2 * the_ins.fragb[n].fragoff;
4059 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4060 toP = frag_more (wid);
4062 shorts_this_frag = 0;
4063 for (m = wid / 2; m; --m)
4065 md_number_to_chars (toP, (long) (*fromP), 2);
4070 for (m = 0; m < the_ins.nrel; m++)
4072 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
4074 the_ins.reloc[m].n -= 2 * shorts_this_frag;
4077 wid = the_ins.reloc[m].wid;
4080 the_ins.reloc[m].wid = 0;
4081 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4083 fixP = fix_new_exp (frag_now,
4084 ((toP - frag_now->fr_literal)
4085 - the_ins.numo * 2 + the_ins.reloc[m].n),
4087 &the_ins.reloc[m].exp,
4088 the_ins.reloc[m].pcrel,
4089 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4090 the_ins.reloc[m].pic_reloc));
4091 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4093 (void) frag_var (rs_machine_dependent, 10, 0,
4094 (relax_substateT) (the_ins.fragb[n].fragty),
4095 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
4097 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4098 shorts_this_frag = 0;
4101 toP = frag_more (n * sizeof (short));
4104 md_number_to_chars (toP, (long) (*fromP), 2);
4110 for (m = 0; m < the_ins.nrel; m++)
4114 wid = the_ins.reloc[m].wid;
4117 the_ins.reloc[m].wid = 0;
4118 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4120 fixP = fix_new_exp (frag_now,
4121 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
4122 - shorts_this_frag * 2),
4124 &the_ins.reloc[m].exp,
4125 the_ins.reloc[m].pcrel,
4126 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4127 the_ins.reloc[m].pic_reloc));
4128 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4132 /* Comparison function used by qsort to rank the opcode entries by name. */
4135 m68k_compare_opcode (const void * v1, const void * v2)
4137 struct m68k_opcode * op1, * op2;
4140 op1 = *(struct m68k_opcode **) v1;
4141 op2 = *(struct m68k_opcode **) v2;
4143 /* Compare the two names. If different, return the comparison.
4144 If the same, return the order they are in the opcode table. */
4145 ret = strcmp (op1->name, op2->name);
4156 const struct m68k_opcode *ins;
4157 struct m68k_incant *hack, *slak;
4158 const char *retval = 0; /* Empty string, or error msg text. */
4161 /* Set up hash tables with 68000 instructions.
4162 similar to what the vax assembler does. */
4163 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4164 a copy of it at runtime, adding in the information we want but isn't
4165 there. I think it'd be better to have an awk script hack the table
4166 at compile time. Or even just xstr the table and use it as-is. But
4167 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4172 flag_reg_prefix_optional = 1;
4174 if (! m68k_rel32_from_cmdline)
4178 /* First sort the opcode table into alphabetical order to seperate
4179 the order that the assembler wants to see the opcodes from the
4180 order that the disassembler wants to see them. */
4181 m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4182 if (!m68k_sorted_opcodes)
4183 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4184 m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4186 for (i = m68k_numopcodes; i--;)
4187 m68k_sorted_opcodes[i] = m68k_opcodes + i;
4189 qsort (m68k_sorted_opcodes, m68k_numopcodes,
4190 sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
4192 op_hash = hash_new ();
4194 obstack_begin (&robyn, 4000);
4195 for (i = 0; i < m68k_numopcodes; i++)
4197 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
4200 ins = m68k_sorted_opcodes[i];
4202 /* We *could* ignore insns that don't match our
4203 arch here by just leaving them out of the hash. */
4204 slak->m_operands = ins->args;
4205 slak->m_opnum = strlen (slak->m_operands) / 2;
4206 slak->m_arch = ins->arch;
4207 slak->m_opcode = ins->opcode;
4208 /* This is kludgey. */
4209 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
4210 if (i + 1 != m68k_numopcodes
4211 && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
4213 slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4218 slak = slak->m_next;
4222 retval = hash_insert (op_hash, ins->name, (char *) hack);
4224 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
4227 for (i = 0; i < m68k_numaliases; i++)
4229 const char *name = m68k_opcode_aliases[i].primary;
4230 const char *alias = m68k_opcode_aliases[i].alias;
4231 PTR val = hash_find (op_hash, name);
4234 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4235 retval = hash_insert (op_hash, alias, val);
4237 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4240 /* In MRI mode, all unsized branches are variable sized. Normally,
4241 they are word sized. */
4244 static struct m68k_opcode_alias mri_aliases[] =
4265 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
4268 const char *name = mri_aliases[i].primary;
4269 const char *alias = mri_aliases[i].alias;
4270 PTR val = hash_find (op_hash, name);
4273 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4274 retval = hash_jam (op_hash, alias, val);
4276 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4280 for (i = 0; i < (int) sizeof (notend_table); i++)
4282 notend_table[i] = 0;
4283 alt_notend_table[i] = 0;
4286 notend_table[','] = 1;
4287 notend_table['{'] = 1;
4288 notend_table['}'] = 1;
4289 alt_notend_table['a'] = 1;
4290 alt_notend_table['A'] = 1;
4291 alt_notend_table['d'] = 1;
4292 alt_notend_table['D'] = 1;
4293 alt_notend_table['#'] = 1;
4294 alt_notend_table['&'] = 1;
4295 alt_notend_table['f'] = 1;
4296 alt_notend_table['F'] = 1;
4297 #ifdef REGISTER_PREFIX
4298 alt_notend_table[REGISTER_PREFIX] = 1;
4301 /* We need to put '(' in alt_notend_table to handle
4302 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4303 alt_notend_table['('] = 1;
4305 /* We need to put '@' in alt_notend_table to handle
4306 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4307 alt_notend_table['@'] = 1;
4309 /* We need to put digits in alt_notend_table to handle
4310 bfextu %d0{24:1},%d0 */
4311 alt_notend_table['0'] = 1;
4312 alt_notend_table['1'] = 1;
4313 alt_notend_table['2'] = 1;
4314 alt_notend_table['3'] = 1;
4315 alt_notend_table['4'] = 1;
4316 alt_notend_table['5'] = 1;
4317 alt_notend_table['6'] = 1;
4318 alt_notend_table['7'] = 1;
4319 alt_notend_table['8'] = 1;
4320 alt_notend_table['9'] = 1;
4322 #ifndef MIT_SYNTAX_ONLY
4323 /* Insert pseudo ops, these have to go into the opcode table since
4324 gas expects pseudo ops to start with a dot. */
4328 while (mote_pseudo_table[n].poc_name)
4330 hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4331 hash_insert (op_hash,
4332 mote_pseudo_table[n].poc_name, (char *) hack);
4333 hack->m_operands = 0;
4343 record_alignment (text_section, 2);
4344 record_alignment (data_section, 2);
4345 record_alignment (bss_section, 2);
4350 select_control_regs ()
4352 /* Note which set of "movec" control registers is available. */
4353 switch (current_chip)
4357 as_warn (_("architecture not yet selected: defaulting to 68020"));
4358 control_regs = m68020_control_regs;
4362 control_regs = m68000_control_regs;
4365 control_regs = m68010_control_regs;
4369 control_regs = m68020_control_regs;
4372 control_regs = m68040_control_regs;
4375 control_regs = m68060_control_regs;
4378 control_regs = cpu32_control_regs;
4384 control_regs = mcf_control_regs;
4388 control_regs = mcf528x_control_regs;
4392 control_regs = mcfv4e_control_regs;
4400 m68k_init_after_args ()
4402 if (cpu_of_arch (current_architecture) == 0)
4405 const char *default_cpu = TARGET_CPU;
4407 if (*default_cpu == 'm')
4409 for (i = 0; i < n_archs; i++)
4410 if (strcasecmp (default_cpu, archs[i].name) == 0)
4414 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU);
4415 current_architecture |= m68020;
4418 current_architecture |= archs[i].arch;
4420 /* Permit m68881 specification with all cpus; those that can't work
4421 with a coprocessor could be doing emulation. */
4422 if (current_architecture & m68851)
4424 if (current_architecture & m68040)
4425 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4427 /* What other incompatibilities could we check for? */
4429 /* Toss in some default assumptions about coprocessors. */
4431 && (cpu_of_arch (current_architecture)
4432 /* Can CPU32 have a 68881 coprocessor?? */
4433 & (m68020 | m68030 | cpu32)))
4434 current_architecture |= m68881;
4437 && (cpu_of_arch (current_architecture) & m68020up) != 0
4438 && (cpu_of_arch (current_architecture) & m68040up) == 0)
4439 current_architecture |= m68851;
4441 if (no_68881 && (current_architecture & m68881))
4442 as_bad (_("options for 68881 and no-68881 both given"));
4444 if (no_68851 && (current_architecture & m68851))
4445 as_bad (_("options for 68851 and no-68851 both given"));
4448 /* Work out the magic number. This isn't very general. */
4449 if (current_architecture & m68000)
4450 m68k_aout_machtype = 0;
4451 else if (current_architecture & m68010)
4452 m68k_aout_machtype = 1;
4453 else if (current_architecture & m68020)
4454 m68k_aout_machtype = 2;
4456 m68k_aout_machtype = 2;
4459 /* Note which set of "movec" control registers is available. */
4460 select_control_regs ();
4462 if (cpu_of_arch (current_architecture) < m68020
4463 || arch_coldfire_p (current_architecture))
4464 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
4467 /* This is called when a label is defined. */
4470 m68k_frob_label (sym)
4473 struct label_line *n;
4475 n = (struct label_line *) xmalloc (sizeof *n);
4478 as_where (&n->file, &n->line);
4484 /* This is called when a value that is not an instruction is emitted. */
4487 m68k_flush_pending_output ()
4489 current_label = NULL;
4492 /* This is called at the end of the assembly, when the final value of
4493 the label is known. We warn if this is a text symbol aligned at an
4497 m68k_frob_symbol (sym)
4500 if (S_GET_SEGMENT (sym) == reg_section
4501 && (int) S_GET_VALUE (sym) < 0)
4503 S_SET_SEGMENT (sym, absolute_section);
4504 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4506 else if ((S_GET_VALUE (sym) & 1) != 0)
4508 struct label_line *l;
4510 for (l = labels; l != NULL; l = l->next)
4512 if (l->label == sym)
4515 as_warn_where (l->file, l->line,
4516 _("text label `%s' aligned to odd boundary"),
4524 /* This is called if we go in or out of MRI mode because of the .mri
4528 m68k_mri_mode_change (on)
4533 if (! flag_reg_prefix_optional)
4535 flag_reg_prefix_optional = 1;
4536 #ifdef REGISTER_PREFIX
4541 if (! m68k_rel32_from_cmdline)
4546 if (! reg_prefix_optional_seen)
4548 #ifdef REGISTER_PREFIX_OPTIONAL
4549 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4551 flag_reg_prefix_optional = 0;
4553 #ifdef REGISTER_PREFIX
4558 if (! m68k_rel32_from_cmdline)
4563 /* Equal to MAX_PRECISION in atof-ieee.c. */
4564 #define MAX_LITTLENUMS 6
4566 /* Turn a string in input_line_pointer into a floating point constant
4567 of type TYPE, and store the appropriate bytes in *LITP. The number
4568 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4569 returned, or NULL on OK. */
4572 md_atof (type, litP, sizeP)
4578 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4579 LITTLENUM_TYPE *wordP;
4610 return _("Bad call to MD_ATOF()");
4612 t = atof_ieee (input_line_pointer, type, words);
4614 input_line_pointer = t;
4616 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4617 for (wordP = words; prec--;)
4619 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4620 litP += sizeof (LITTLENUM_TYPE);
4626 md_number_to_chars (buf, val, n)
4631 number_to_chars_bigendian (buf, val, n);
4635 md_apply_fix3 (fixP, valP, seg)
4638 segT seg ATTRIBUTE_UNUSED;
4640 offsetT val = *valP;
4641 addressT upper_limit;
4642 offsetT lower_limit;
4644 /* This is unnecessary but it convinces the native rs6000 compiler
4645 to generate the code we want. */
4646 char *buf = fixP->fx_frag->fr_literal;
4647 buf += fixP->fx_where;
4648 /* End ibm compiler workaround. */
4650 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
4652 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
4658 memset (buf, 0, fixP->fx_size);
4659 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4661 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4662 && !S_IS_DEFINED (fixP->fx_addsy)
4663 && !S_IS_WEAK (fixP->fx_addsy))
4664 S_SET_WEAK (fixP->fx_addsy);
4669 #ifdef BFD_ASSEMBLER
4670 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4671 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4675 switch (fixP->fx_size)
4677 /* The cast to offsetT below are necessary to make code
4678 correct for machines where ints are smaller than offsetT. */
4682 lower_limit = - (offsetT) 0x80;
4685 *buf++ = (val >> 8);
4687 upper_limit = 0x7fff;
4688 lower_limit = - (offsetT) 0x8000;
4691 *buf++ = (val >> 24);
4692 *buf++ = (val >> 16);
4693 *buf++ = (val >> 8);
4695 upper_limit = 0x7fffffff;
4696 lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
4699 BAD_CASE (fixP->fx_size);
4702 /* Fix up a negative reloc. */
4703 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4705 fixP->fx_addsy = fixP->fx_subsy;
4706 fixP->fx_subsy = NULL;
4710 /* For non-pc-relative values, it's conceivable we might get something
4711 like "0xff" for a byte field. So extend the upper part of the range
4712 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4713 so that we can do any range checking at all. */
4714 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4715 upper_limit = upper_limit * 2 + 1;
4717 if ((addressT) val > upper_limit
4718 && (val > 0 || val < lower_limit))
4719 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4721 /* A one byte PC-relative reloc means a short branch. We can't use
4722 a short branch with a value of 0 or -1, because those indicate
4723 different opcodes (branches with longer offsets). fixup_segment
4724 in write.c may have clobbered fx_pcrel, so we need to examine the
4727 #ifdef BFD_ASSEMBLER
4728 || fixP->fx_r_type == BFD_RELOC_8_PCREL
4731 && fixP->fx_size == 1
4732 && (fixP->fx_addsy == NULL
4733 || S_IS_DEFINED (fixP->fx_addsy))
4734 && (val == 0 || val == -1))
4735 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4738 /* *fragP has been relaxed to its final size, and now needs to have
4739 the bytes inside it modified to conform to the new size There is UGLY
4743 md_convert_frag_1 (fragP)
4744 register fragS *fragP;
4749 /* Address in object code of the displacement. */
4750 register int object_address = fragP->fr_fix + fragP->fr_address;
4752 /* Address in gas core of the place to store the displacement. */
4753 /* This convinces the native rs6000 compiler to generate the code we
4755 register char *buffer_address = fragP->fr_literal;
4756 buffer_address += fragP->fr_fix;
4757 /* End ibm compiler workaround. */
4759 /* The displacement of the address, from current location. */
4760 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4761 disp = (disp + fragP->fr_offset) - object_address;
4763 switch (fragP->fr_subtype)
4765 case TAB (BRANCHBWL, BYTE):
4766 case TAB (BRABSJUNC, BYTE):
4767 case TAB (BRABSJCOND, BYTE):
4768 case TAB (BRANCHBW, BYTE):
4769 know (issbyte (disp));
4771 as_bad_where (fragP->fr_file, fragP->fr_line,
4772 _("short branch with zero offset: use :w"));
4773 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4774 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4775 fixP->fx_pcrel_adjust = -1;
4777 case TAB (BRANCHBWL, SHORT):
4778 case TAB (BRABSJUNC, SHORT):
4779 case TAB (BRABSJCOND, SHORT):
4780 case TAB (BRANCHBW, SHORT):
4781 fragP->fr_opcode[1] = 0x00;
4782 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4783 1, RELAX_RELOC_PC16);
4786 case TAB (BRANCHBWL, LONG):
4787 fragP->fr_opcode[1] = (char) 0xFF;
4788 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4789 1, RELAX_RELOC_PC32);
4792 case TAB (BRABSJUNC, LONG):
4793 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4795 if (flag_keep_pcrel)
4796 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4797 fragP->fr_opcode[0] = 0x4E;
4798 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4799 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4800 0, RELAX_RELOC_ABS32);
4803 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4805 if (flag_keep_pcrel)
4806 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4807 fragP->fr_opcode[0] = 0x4E;
4808 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4809 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4810 0, RELAX_RELOC_ABS32);
4815 /* This cannot happen, because jbsr and jbra are the only two
4816 unconditional branches. */
4820 case TAB (BRABSJCOND, LONG):
4821 if (flag_keep_pcrel)
4822 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4824 /* Only Bcc 68000 instructions can come here
4825 Change bcc into b!cc/jmp absl long. */
4826 fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
4827 fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
4829 /* JF: these used to be fr_opcode[2,3], but they may be in a
4830 different frag, in which case referring to them is a no-no.
4831 Only fr_opcode[0,1] are guaranteed to work. */
4832 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4833 *buffer_address++ = (char) 0xf9;
4834 fragP->fr_fix += 2; /* Account for jmp instruction. */
4835 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4836 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4839 case TAB (FBRANCH, SHORT):
4840 know ((fragP->fr_opcode[1] & 0x40) == 0);
4841 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4842 1, RELAX_RELOC_PC16);
4845 case TAB (FBRANCH, LONG):
4846 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
4847 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4848 1, RELAX_RELOC_PC32);
4851 case TAB (DBCCLBR, SHORT):
4852 case TAB (DBCCABSJ, SHORT):
4853 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4854 1, RELAX_RELOC_PC16);
4857 case TAB (DBCCLBR, LONG):
4858 /* Only DBcc instructions can come here.
4859 Change dbcc into dbcc/bral.
4860 JF: these used to be fr_opcode[2-7], but that's wrong. */
4861 if (flag_keep_pcrel)
4862 as_fatal (_("Tried to convert DBcc to absolute jump"));
4864 *buffer_address++ = 0x00; /* Branch offset = 4. */
4865 *buffer_address++ = 0x04;
4866 *buffer_address++ = 0x60; /* Put in bra pc+6. */
4867 *buffer_address++ = 0x06;
4868 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4869 *buffer_address++ = (char) 0xff;
4871 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4872 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4876 case TAB (DBCCABSJ, LONG):
4877 /* Only DBcc instructions can come here.
4878 Change dbcc into dbcc/jmp.
4879 JF: these used to be fr_opcode[2-7], but that's wrong. */
4880 if (flag_keep_pcrel)
4881 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4883 *buffer_address++ = 0x00; /* Branch offset = 4. */
4884 *buffer_address++ = 0x04;
4885 *buffer_address++ = 0x60; /* Put in bra pc + 6. */
4886 *buffer_address++ = 0x06;
4887 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4888 *buffer_address++ = (char) 0xf9;
4890 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4891 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4895 case TAB (PCREL1632, SHORT):
4896 fragP->fr_opcode[1] &= ~0x3F;
4897 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4898 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4899 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4902 case TAB (PCREL1632, LONG):
4903 /* Already set to mode 7.3; this indicates: PC indirect with
4904 suppressed index, 32-bit displacement. */
4905 *buffer_address++ = 0x01;
4906 *buffer_address++ = 0x70;
4908 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4909 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4910 fixP->fx_pcrel_adjust = 2;
4913 case TAB (PCINDEX, BYTE):
4914 assert (fragP->fr_fix >= 2);
4915 buffer_address[-2] &= ~1;
4916 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4917 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4918 fixP->fx_pcrel_adjust = 1;
4920 case TAB (PCINDEX, SHORT):
4921 assert (fragP->fr_fix >= 2);
4922 buffer_address[-2] |= 0x1;
4923 buffer_address[-1] = 0x20;
4924 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4925 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4926 fixP->fx_pcrel_adjust = 2;
4929 case TAB (PCINDEX, LONG):
4930 assert (fragP->fr_fix >= 2);
4931 buffer_address[-2] |= 0x1;
4932 buffer_address[-1] = 0x30;
4933 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4934 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4935 fixP->fx_pcrel_adjust = 2;
4938 case TAB (ABSTOPCREL, SHORT):
4939 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4940 1, RELAX_RELOC_PC16);
4943 case TAB (ABSTOPCREL, LONG):
4944 if (flag_keep_pcrel)
4945 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4946 /* The thing to do here is force it to ABSOLUTE LONG, since
4947 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4948 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4950 fragP->fr_opcode[1] &= ~0x3F;
4951 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4952 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4953 0, RELAX_RELOC_ABS32);
4959 #ifndef BFD_ASSEMBLER
4962 md_convert_frag (headers, sec, fragP)
4963 object_headers *headers ATTRIBUTE_UNUSED;
4964 segT sec ATTRIBUTE_UNUSED;
4967 md_convert_frag_1 (fragP);
4973 md_convert_frag (abfd, sec, fragP)
4974 bfd *abfd ATTRIBUTE_UNUSED;
4975 segT sec ATTRIBUTE_UNUSED;
4978 md_convert_frag_1 (fragP);
4982 /* Force truly undefined symbols to their maximum size, and generally set up
4983 the frag list to be relaxed
4986 md_estimate_size_before_relax (fragP, segment)
4987 register fragS *fragP;
4990 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4991 switch (fragP->fr_subtype)
4993 case TAB (BRANCHBWL, SZ_UNDEF):
4994 case TAB (BRABSJUNC, SZ_UNDEF):
4995 case TAB (BRABSJCOND, SZ_UNDEF):
4997 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4998 && relaxable_symbol (fragP->fr_symbol))
5000 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5002 else if (flag_short_refs)
5004 /* Symbol is undefined and we want short ref. */
5005 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5009 /* Symbol is still undefined. Make it LONG. */
5010 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5015 case TAB (BRANCHBW, SZ_UNDEF):
5017 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5018 && relaxable_symbol (fragP->fr_symbol))
5020 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5024 /* Symbol is undefined and we don't have long branches. */
5025 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5030 case TAB (FBRANCH, SZ_UNDEF):
5031 case TAB (DBCCLBR, SZ_UNDEF):
5032 case TAB (DBCCABSJ, SZ_UNDEF):
5033 case TAB (PCREL1632, SZ_UNDEF):
5035 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5036 && relaxable_symbol (fragP->fr_symbol))
5039 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5043 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5048 case TAB (PCINDEX, SZ_UNDEF):
5049 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5050 && relaxable_symbol (fragP->fr_symbol)))
5052 fragP->fr_subtype = TAB (PCINDEX, BYTE);
5056 fragP->fr_subtype = TAB (PCINDEX, LONG);
5060 case TAB (ABSTOPCREL, SZ_UNDEF):
5062 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5063 && relaxable_symbol (fragP->fr_symbol)))
5065 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
5069 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
5078 /* Now that SZ_UNDEF are taken care of, check others. */
5079 switch (fragP->fr_subtype)
5081 case TAB (BRANCHBWL, BYTE):
5082 case TAB (BRABSJUNC, BYTE):
5083 case TAB (BRABSJCOND, BYTE):
5084 case TAB (BRANCHBW, BYTE):
5085 /* We can't do a short jump to the next instruction, so in that
5086 case we force word mode. If the symbol is at the start of a
5087 frag, and it is the next frag with any data in it (usually
5088 this is just the next frag, but assembler listings may
5089 introduce empty frags), we must use word mode. */
5090 if (fragP->fr_symbol)
5094 sym_frag = symbol_get_frag (fragP->fr_symbol);
5095 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
5099 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
5103 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5110 return md_relax_table[fragP->fr_subtype].rlx_length;
5113 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5114 /* the bit-field entries in the relocation_info struct plays hell
5115 with the byte-order problems of cross-assembly. So as a hack,
5116 I added this mach. dependent ri twiddler. Ugly, but it gets
5118 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5119 are symbolnum, most sig. byte first. Last byte is broken up with
5120 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5121 nibble as nuthin. (on Sun 3 at least) */
5122 /* Translate the internal relocation information into target-specific
5126 md_ri_to_chars (the_bytes, ri)
5128 struct reloc_info_generic *ri;
5131 md_number_to_chars (the_bytes, ri->r_address, 4);
5132 /* Now the fun stuff. */
5133 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
5134 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
5135 the_bytes[6] = ri->r_symbolnum & 0x0ff;
5136 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
5137 ((ri->r_extern << 4) & 0x10));
5142 #ifndef BFD_ASSEMBLER
5144 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
5147 relax_addressT segment_address_in_file;
5150 * In: length of relocation (or of address) in chars: 1, 2 or 4.
5151 * Out: GNU LD relocation length code: 0, 1, or 2.
5154 static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
5157 know (fixP->fx_addsy != NULL);
5159 md_number_to_chars (where,
5160 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
5163 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
5164 ? S_GET_TYPE (fixP->fx_addsy)
5165 : fixP->fx_addsy->sy_number);
5167 where[4] = (r_symbolnum >> 16) & 0x0ff;
5168 where[5] = (r_symbolnum >> 8) & 0x0ff;
5169 where[6] = r_symbolnum & 0x0ff;
5170 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
5171 (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
5175 #endif /* OBJ_AOUT or OBJ_BOUT */
5177 #ifndef WORKING_DOT_WORD
5178 const int md_short_jump_size = 4;
5179 const int md_long_jump_size = 6;
5182 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
5184 addressT from_addr, to_addr;
5185 fragS *frag ATTRIBUTE_UNUSED;
5186 symbolS *to_symbol ATTRIBUTE_UNUSED;
5190 offset = to_addr - (from_addr + 2);
5192 md_number_to_chars (ptr, (valueT) 0x6000, 2);
5193 md_number_to_chars (ptr + 2, (valueT) offset, 2);
5197 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
5199 addressT from_addr, to_addr;
5205 if (!HAVE_LONG_BRANCH (current_architecture))
5207 if (flag_keep_pcrel)
5208 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5209 offset = to_addr - S_GET_VALUE (to_symbol);
5210 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
5211 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5212 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
5217 offset = to_addr - (from_addr + 2);
5218 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
5219 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5225 /* Different values of OK tell what its OK to return. Things that
5226 aren't OK are an error (what a shock, no?)
5229 10: Absolute 1:8 only
5230 20: Absolute 0:7 only
5231 30: absolute 0:15 only
5232 40: Absolute 0:31 only
5233 50: absolute 0:127 only
5234 55: absolute -64:63 only
5235 60: absolute -128:127 only
5236 70: absolute 0:4095 only
5237 80: absolute -1, 1:7 only
5242 struct m68k_exp *exp;
5245 if (exp->exp.X_op == O_absent)
5247 /* Do the same thing the VAX asm does. */
5248 op (exp) = O_constant;
5254 as_warn (_("expression out of range: defaulting to 1"));
5258 else if (exp->exp.X_op == O_constant)
5263 if (offs (exp) < 1 || offs (exp) > 8)
5265 as_warn (_("expression out of range: defaulting to 1"));
5270 if (offs (exp) < 0 || offs (exp) > 7)
5274 if (offs (exp) < 0 || offs (exp) > 15)
5278 if (offs (exp) < 0 || offs (exp) > 32)
5282 if (offs (exp) < 0 || offs (exp) > 127)
5286 if (offs (exp) < -64 || offs (exp) > 63)
5290 if (offs (exp) < -128 || offs (exp) > 127)
5294 if (offs (exp) < 0 || offs (exp) > 4095)
5297 as_warn (_("expression out of range: defaulting to 0"));
5306 as_warn (_("expression out of range: defaulting to 1"));
5314 else if (exp->exp.X_op == O_big)
5316 if (offs (exp) <= 0 /* flonum. */
5317 && (ok == 90 /* no bignums */
5318 || (ok > 10 /* Small-int ranges including 0 ok. */
5319 /* If we have a flonum zero, a zero integer should
5320 do as well (e.g., in moveq). */
5321 && generic_floating_point_number.exponent == 0
5322 && generic_floating_point_number.low[0] == 0)))
5324 /* HACK! Turn it into a long. */
5325 LITTLENUM_TYPE words[6];
5327 gen_to_words (words, 2, 8L); /* These numbers are magic! */
5328 op (exp) = O_constant;
5331 offs (exp) = words[1] | (words[0] << 16);
5335 op (exp) = O_constant;
5338 offs (exp) = (ok == 10) ? 1 : 0;
5339 as_warn (_("Can't deal with expression; defaulting to %ld"),
5345 if (ok >= 10 && ok <= 80)
5347 op (exp) = O_constant;
5350 offs (exp) = (ok == 10) ? 1 : 0;
5351 as_warn (_("Can't deal with expression; defaulting to %ld"),
5356 if (exp->size != SIZE_UNSPEC)
5364 if (!isbyte (offs (exp)))
5365 as_warn (_("expression doesn't fit in BYTE"));
5368 if (!isword (offs (exp)))
5369 as_warn (_("expression doesn't fit in WORD"));
5377 /* These are the back-ends for the various machine dependent pseudo-ops. */
5381 int ignore ATTRIBUTE_UNUSED;
5383 subseg_set (data_section, 1);
5384 demand_empty_rest_of_line ();
5389 int ignore ATTRIBUTE_UNUSED;
5391 subseg_set (data_section, 2);
5392 demand_empty_rest_of_line ();
5397 int ignore ATTRIBUTE_UNUSED;
5399 /* We don't support putting frags in the BSS segment, we fake it
5400 by marking in_bss, then looking at s_skip for clues. */
5402 subseg_set (bss_section, 0);
5403 demand_empty_rest_of_line ();
5408 int ignore ATTRIBUTE_UNUSED;
5411 register long temp_fill;
5413 temp = 1; /* JF should be 2? */
5414 temp_fill = get_absolute_expression ();
5415 if (!need_pass_2) /* Never make frag if expect extra pass. */
5416 frag_align (temp, (int) temp_fill, 0);
5417 demand_empty_rest_of_line ();
5418 record_alignment (now_seg, temp);
5423 int ignore ATTRIBUTE_UNUSED;
5425 demand_empty_rest_of_line ();
5428 /* Pseudo-ops handled for MRI compatibility. */
5430 /* This function returns non-zero if the argument is a conditional
5431 pseudo-op. This is called when checking whether a pending
5432 alignment is needed. */
5435 m68k_conditional_pseudoop (pop)
5438 return (pop->poc_handler == s_mri_if
5439 || pop->poc_handler == s_mri_else);
5442 /* Handle an MRI style chip specification. */
5451 s = input_line_pointer;
5452 /* We can't use get_symbol_end since the processor names are not proper
5454 while (is_part_of_name (c = *input_line_pointer++))
5456 *--input_line_pointer = 0;
5457 for (i = 0; i < n_archs; i++)
5458 if (strcasecmp (s, archs[i].name) == 0)
5462 as_bad (_("%s: unrecognized processor name"), s);
5463 *input_line_pointer = c;
5464 ignore_rest_of_line ();
5467 *input_line_pointer = c;
5469 if (*input_line_pointer == '/')
5470 current_architecture = 0;
5472 current_architecture &= m68881 | m68851;
5473 current_architecture |= archs[i].arch;
5474 current_chip = archs[i].chip;
5476 while (*input_line_pointer == '/')
5478 ++input_line_pointer;
5479 s = input_line_pointer;
5480 /* We can't use get_symbol_end since the processor names are not
5482 while (is_part_of_name (c = *input_line_pointer++))
5484 *--input_line_pointer = 0;
5485 if (strcmp (s, "68881") == 0)
5486 current_architecture |= m68881;
5487 else if (strcmp (s, "68851") == 0)
5488 current_architecture |= m68851;
5489 *input_line_pointer = c;
5492 /* Update info about available control registers. */
5493 select_control_regs ();
5496 /* The MRI CHIP pseudo-op. */
5500 int ignore ATTRIBUTE_UNUSED;
5506 stop = mri_comment_field (&stopc);
5509 mri_comment_end (stop, stopc);
5510 demand_empty_rest_of_line ();
5513 /* The MRI FOPT pseudo-op. */
5517 int ignore ATTRIBUTE_UNUSED;
5521 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5525 input_line_pointer += 3;
5526 temp = get_absolute_expression ();
5527 if (temp < 0 || temp > 7)
5528 as_bad (_("bad coprocessor id"));
5530 m68k_float_copnum = COP0 + temp;
5534 as_bad (_("unrecognized fopt option"));
5535 ignore_rest_of_line ();
5539 demand_empty_rest_of_line ();
5542 /* The structure used to handle the MRI OPT pseudo-op. */
5546 /* The name of the option. */
5549 /* If this is not NULL, just call this function. The first argument
5550 is the ARG field of this structure, the second argument is
5551 whether the option was negated. */
5552 void (*pfn) PARAMS ((int arg, int on));
5554 /* If this is not NULL, and the PFN field is NULL, set the variable
5555 this points to. Set it to the ARG field if the option was not
5556 negated, and the NOTARG field otherwise. */
5559 /* The value to pass to PFN or to assign to *PVAR. */
5562 /* The value to assign to *PVAR if the option is negated. If PFN is
5563 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5564 the option may not be negated. */
5568 /* The table used to handle the MRI OPT pseudo-op. */
5570 static void skip_to_comma PARAMS ((int, int));
5571 static void opt_nest PARAMS ((int, int));
5572 static void opt_chip PARAMS ((int, int));
5573 static void opt_list PARAMS ((int, int));
5574 static void opt_list_symbols PARAMS ((int, int));
5576 static const struct opt_action opt_table[] =
5578 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5580 /* We do relaxing, so there is little use for these options. */
5581 { "b", 0, 0, 0, 0 },
5582 { "brs", 0, 0, 0, 0 },
5583 { "brb", 0, 0, 0, 0 },
5584 { "brl", 0, 0, 0, 0 },
5585 { "brw", 0, 0, 0, 0 },
5587 { "c", 0, 0, 0, 0 },
5588 { "cex", 0, 0, 0, 0 },
5589 { "case", 0, &symbols_case_sensitive, 1, 0 },
5590 { "cl", 0, 0, 0, 0 },
5591 { "cre", 0, 0, 0, 0 },
5592 { "d", 0, &flag_keep_locals, 1, 0 },
5593 { "e", 0, 0, 0, 0 },
5594 { "f", 0, &flag_short_refs, 1, 0 },
5595 { "frs", 0, &flag_short_refs, 1, 0 },
5596 { "frl", 0, &flag_short_refs, 0, 1 },
5597 { "g", 0, 0, 0, 0 },
5598 { "i", 0, 0, 0, 0 },
5599 { "m", 0, 0, 0, 0 },
5600 { "mex", 0, 0, 0, 0 },
5601 { "mc", 0, 0, 0, 0 },
5602 { "md", 0, 0, 0, 0 },
5603 { "nest", opt_nest, 0, 0, 0 },
5604 { "next", skip_to_comma, 0, 0, 0 },
5605 { "o", 0, 0, 0, 0 },
5606 { "old", 0, 0, 0, 0 },
5607 { "op", skip_to_comma, 0, 0, 0 },
5608 { "pco", 0, 0, 0, 0 },
5609 { "p", opt_chip, 0, 0, 0 },
5610 { "pcr", 0, 0, 0, 0 },
5611 { "pcs", 0, 0, 0, 0 },
5612 { "r", 0, 0, 0, 0 },
5613 { "quick", 0, &m68k_quick, 1, 0 },
5614 { "rel32", 0, &m68k_rel32, 1, 0 },
5615 { "s", opt_list, 0, 0, 0 },
5616 { "t", opt_list_symbols, 0, 0, 0 },
5617 { "w", 0, &flag_no_warnings, 0, 1 },
5621 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5623 /* The MRI OPT pseudo-op. */
5627 int ignore ATTRIBUTE_UNUSED;
5635 const struct opt_action *o;
5640 if (*input_line_pointer == '-')
5642 ++input_line_pointer;
5645 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5647 input_line_pointer += 2;
5651 s = input_line_pointer;
5652 c = get_symbol_end ();
5654 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5656 if (strcasecmp (s, o->name) == 0)
5660 /* Restore input_line_pointer now in case the option
5662 *input_line_pointer = c;
5663 (*o->pfn) (o->arg, t);
5665 else if (o->pvar != NULL)
5667 if (! t && o->arg == o->notarg)
5668 as_bad (_("option `%s' may not be negated"), s);
5669 *input_line_pointer = c;
5670 *o->pvar = t ? o->arg : o->notarg;
5673 *input_line_pointer = c;
5679 as_bad (_("option `%s' not recognized"), s);
5680 *input_line_pointer = c;
5683 while (*input_line_pointer++ == ',');
5685 /* Move back to terminating character. */
5686 --input_line_pointer;
5687 demand_empty_rest_of_line ();
5690 /* Skip ahead to a comma. This is used for OPT options which we do
5691 not support and which take arguments. */
5694 skip_to_comma (arg, on)
5695 int arg ATTRIBUTE_UNUSED;
5696 int on ATTRIBUTE_UNUSED;
5698 while (*input_line_pointer != ','
5699 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5700 ++input_line_pointer;
5703 /* Handle the OPT NEST=depth option. */
5707 int arg ATTRIBUTE_UNUSED;
5708 int on ATTRIBUTE_UNUSED;
5710 if (*input_line_pointer != '=')
5712 as_bad (_("bad format of OPT NEST=depth"));
5716 ++input_line_pointer;
5717 max_macro_nest = get_absolute_expression ();
5720 /* Handle the OPT P=chip option. */
5724 int arg ATTRIBUTE_UNUSED;
5725 int on ATTRIBUTE_UNUSED;
5727 if (*input_line_pointer != '=')
5729 /* This is just OPT P, which we do not support. */
5733 ++input_line_pointer;
5737 /* Handle the OPT S option. */
5741 int arg ATTRIBUTE_UNUSED;
5747 /* Handle the OPT T option. */
5750 opt_list_symbols (arg, on)
5751 int arg ATTRIBUTE_UNUSED;
5755 listing |= LISTING_SYMBOLS;
5757 listing &= ~LISTING_SYMBOLS;
5760 /* Handle the MRI REG pseudo-op. */
5764 int ignore ATTRIBUTE_UNUSED;
5773 if (line_label == NULL)
5775 as_bad (_("missing label"));
5776 ignore_rest_of_line ();
5781 stop = mri_comment_field (&stopc);
5785 s = input_line_pointer;
5786 while (ISALNUM (*input_line_pointer)
5787 #ifdef REGISTER_PREFIX
5788 || *input_line_pointer == REGISTER_PREFIX
5790 || *input_line_pointer == '/'
5791 || *input_line_pointer == '-')
5792 ++input_line_pointer;
5793 c = *input_line_pointer;
5794 *input_line_pointer = '\0';
5796 if (m68k_ip_op (s, &rop) != 0)
5798 if (rop.error == NULL)
5799 as_bad (_("bad register list"));
5801 as_bad (_("bad register list: %s"), rop.error);
5802 *input_line_pointer = c;
5803 ignore_rest_of_line ();
5807 *input_line_pointer = c;
5809 if (rop.mode == REGLST)
5811 else if (rop.mode == DREG)
5812 mask = 1 << (rop.reg - DATA0);
5813 else if (rop.mode == AREG)
5814 mask = 1 << (rop.reg - ADDR0 + 8);
5815 else if (rop.mode == FPREG)
5816 mask = 1 << (rop.reg - FP0 + 16);
5817 else if (rop.mode == CONTROL
5820 else if (rop.mode == CONTROL
5823 else if (rop.mode == CONTROL
5828 as_bad (_("bad register list"));
5829 ignore_rest_of_line ();
5833 S_SET_SEGMENT (line_label, reg_section);
5834 S_SET_VALUE (line_label, ~mask);
5835 symbol_set_frag (line_label, &zero_address_frag);
5838 mri_comment_end (stop, stopc);
5840 demand_empty_rest_of_line ();
5843 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5847 struct save_opts *next;
5849 int symbols_case_sensitive;
5858 /* FIXME: We don't save OPT S. */
5861 /* This variable holds the stack of saved options. */
5863 static struct save_opts *save_stack;
5865 /* The MRI SAVE pseudo-op. */
5869 int ignore ATTRIBUTE_UNUSED;
5871 struct save_opts *s;
5873 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5874 s->abspcadd = m68k_abspcadd;
5875 s->symbols_case_sensitive = symbols_case_sensitive;
5876 s->keep_locals = flag_keep_locals;
5877 s->short_refs = flag_short_refs;
5878 s->architecture = current_architecture;
5879 s->chip = current_chip;
5880 s->quick = m68k_quick;
5881 s->rel32 = m68k_rel32;
5882 s->listing = listing;
5883 s->no_warnings = flag_no_warnings;
5885 s->next = save_stack;
5888 demand_empty_rest_of_line ();
5891 /* The MRI RESTORE pseudo-op. */
5895 int ignore ATTRIBUTE_UNUSED;
5897 struct save_opts *s;
5899 if (save_stack == NULL)
5901 as_bad (_("restore without save"));
5902 ignore_rest_of_line ();
5907 save_stack = s->next;
5909 m68k_abspcadd = s->abspcadd;
5910 symbols_case_sensitive = s->symbols_case_sensitive;
5911 flag_keep_locals = s->keep_locals;
5912 flag_short_refs = s->short_refs;
5913 current_architecture = s->architecture;
5914 current_chip = s->chip;
5915 m68k_quick = s->quick;
5916 m68k_rel32 = s->rel32;
5917 listing = s->listing;
5918 flag_no_warnings = s->no_warnings;
5922 demand_empty_rest_of_line ();
5925 /* Types of MRI structured control directives. */
5927 enum mri_control_type
5935 /* This structure is used to stack the MRI structured control
5938 struct mri_control_info
5940 /* The directive within which this one is enclosed. */
5941 struct mri_control_info *outer;
5943 /* The type of directive. */
5944 enum mri_control_type type;
5946 /* Whether an ELSE has been in an IF. */
5949 /* The add or sub statement at the end of a FOR. */
5952 /* The label of the top of a FOR or REPEAT loop. */
5955 /* The label to jump to for the next iteration, or the else
5956 expression of a conditional. */
5959 /* The label to jump to to break out of the loop, or the label past
5960 the end of a conditional. */
5964 /* The stack of MRI structured control directives. */
5966 static struct mri_control_info *mri_control_stack;
5968 /* The current MRI structured control directive index number, used to
5969 generate label names. */
5971 static int mri_control_index;
5973 /* Some function prototypes. */
5975 static void mri_assemble PARAMS ((char *));
5976 static char *mri_control_label PARAMS ((void));
5977 static struct mri_control_info *push_mri_control
5978 PARAMS ((enum mri_control_type));
5979 static void pop_mri_control PARAMS ((void));
5980 static int parse_mri_condition PARAMS ((int *));
5981 static int parse_mri_control_operand
5982 PARAMS ((int *, char **, char **, char **, char **));
5983 static int swap_mri_condition PARAMS ((int));
5984 static int reverse_mri_condition PARAMS ((int));
5985 static void build_mri_control_operand
5986 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5987 const char *, int));
5988 static void parse_mri_control_expression
5989 PARAMS ((char *, int, const char *, const char *, int));
5991 /* Assemble an instruction for an MRI structured control directive. */
5999 /* md_assemble expects the opcode to be in lower case. */
6000 for (s = str; *s != ' ' && *s != '\0'; s++)
6006 /* Generate a new MRI label structured control directive label name. */
6009 mri_control_label ()
6013 n = (char *) xmalloc (20);
6014 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
6015 ++mri_control_index;
6019 /* Create a new MRI structured control directive. */
6021 static struct mri_control_info *
6022 push_mri_control (type)
6023 enum mri_control_type type;
6025 struct mri_control_info *n;
6027 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
6031 if (type == mri_if || type == mri_while)
6034 n->top = mri_control_label ();
6035 n->next = mri_control_label ();
6036 n->bottom = mri_control_label ();
6038 n->outer = mri_control_stack;
6039 mri_control_stack = n;
6044 /* Pop off the stack of MRI structured control directives. */
6049 struct mri_control_info *n;
6051 n = mri_control_stack;
6052 mri_control_stack = n->outer;
6060 /* Recognize a condition code in an MRI structured control expression. */
6063 parse_mri_condition (pcc)
6068 know (*input_line_pointer == '<');
6070 ++input_line_pointer;
6071 c1 = *input_line_pointer++;
6072 c2 = *input_line_pointer++;
6074 if (*input_line_pointer != '>')
6076 as_bad (_("syntax error in structured control directive"));
6080 ++input_line_pointer;
6086 *pcc = (c1 << 8) | c2;
6091 /* Parse a single operand in an MRI structured control expression. */
6094 parse_mri_control_operand (pcc, leftstart, leftstop, rightstart, rightstop)
6111 if (*input_line_pointer == '<')
6113 /* It's just a condition code. */
6114 return parse_mri_condition (pcc);
6117 /* Look ahead for the condition code. */
6118 for (s = input_line_pointer; *s != '\0'; ++s)
6120 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
6125 as_bad (_("missing condition code in structured control directive"));
6129 *leftstart = input_line_pointer;
6131 if (*leftstop > *leftstart
6132 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
6135 input_line_pointer = s;
6136 if (! parse_mri_condition (pcc))
6139 /* Look ahead for AND or OR or end of line. */
6140 for (s = input_line_pointer; *s != '\0'; ++s)
6142 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6143 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6145 if ((s == input_line_pointer
6148 && ((strncasecmp (s, "AND", 3) == 0
6149 && (s[3] == '.' || ! is_part_of_name (s[3])))
6150 || (strncasecmp (s, "OR", 2) == 0
6151 && (s[2] == '.' || ! is_part_of_name (s[2])))))
6155 *rightstart = input_line_pointer;
6157 if (*rightstop > *rightstart
6158 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
6161 input_line_pointer = s;
6166 #define MCC(b1, b2) (((b1) << 8) | (b2))
6168 /* Swap the sense of a condition. This changes the condition so that
6169 it generates the same result when the operands are swapped. */
6172 swap_mri_condition (cc)
6177 case MCC ('h', 'i'): return MCC ('c', 's');
6178 case MCC ('l', 's'): return MCC ('c', 'c');
6179 /* <HS> is an alias for <CC>. */
6180 case MCC ('h', 's'):
6181 case MCC ('c', 'c'): return MCC ('l', 's');
6182 /* <LO> is an alias for <CS>. */
6183 case MCC ('l', 'o'):
6184 case MCC ('c', 's'): return MCC ('h', 'i');
6185 case MCC ('p', 'l'): return MCC ('m', 'i');
6186 case MCC ('m', 'i'): return MCC ('p', 'l');
6187 case MCC ('g', 'e'): return MCC ('l', 'e');
6188 case MCC ('l', 't'): return MCC ('g', 't');
6189 case MCC ('g', 't'): return MCC ('l', 't');
6190 case MCC ('l', 'e'): return MCC ('g', 'e');
6191 /* Issue a warning for conditions we can not swap. */
6192 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
6193 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
6194 case MCC ('v', 'c'):
6195 case MCC ('v', 's'):
6197 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6198 (char) (cc >> 8), (char) (cc));
6204 /* Reverse the sense of a condition. */
6207 reverse_mri_condition (cc)
6212 case MCC ('h', 'i'): return MCC ('l', 's');
6213 case MCC ('l', 's'): return MCC ('h', 'i');
6214 /* <HS> is an alias for <CC> */
6215 case MCC ('h', 's'): return MCC ('l', 'o');
6216 case MCC ('c', 'c'): return MCC ('c', 's');
6217 /* <LO> is an alias for <CS> */
6218 case MCC ('l', 'o'): return MCC ('h', 's');
6219 case MCC ('c', 's'): return MCC ('c', 'c');
6220 case MCC ('n', 'e'): return MCC ('e', 'q');
6221 case MCC ('e', 'q'): return MCC ('n', 'e');
6222 case MCC ('v', 'c'): return MCC ('v', 's');
6223 case MCC ('v', 's'): return MCC ('v', 'c');
6224 case MCC ('p', 'l'): return MCC ('m', 'i');
6225 case MCC ('m', 'i'): return MCC ('p', 'l');
6226 case MCC ('g', 'e'): return MCC ('l', 't');
6227 case MCC ('l', 't'): return MCC ('g', 'e');
6228 case MCC ('g', 't'): return MCC ('l', 'e');
6229 case MCC ('l', 'e'): return MCC ('g', 't');
6234 /* Build an MRI structured control expression. This generates test
6235 and branch instructions. It goes to TRUELAB if the condition is
6236 true, and to FALSELAB if the condition is false. Exactly one of
6237 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6238 is the size qualifier for the expression. EXTENT is the size to
6239 use for the branch. */
6242 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6243 rightstop, truelab, falselab, extent)
6250 const char *truelab;
6251 const char *falselab;
6257 if (leftstart != NULL)
6259 struct m68k_op leftop, rightop;
6262 /* Swap the compare operands, if necessary, to produce a legal
6263 m68k compare instruction. Comparing a register operand with
6264 a non-register operand requires the register to be on the
6265 right (cmp, cmpa). Comparing an immediate value with
6266 anything requires the immediate value to be on the left
6271 (void) m68k_ip_op (leftstart, &leftop);
6276 (void) m68k_ip_op (rightstart, &rightop);
6279 if (rightop.mode == IMMED
6280 || ((leftop.mode == DREG || leftop.mode == AREG)
6281 && (rightop.mode != DREG && rightop.mode != AREG)))
6285 /* Correct conditional handling:
6286 if #1 <lt> d0 then ;means if (1 < d0)
6292 cmp #1,d0 if we do *not* swap the operands
6293 bgt true we need the swapped condition!
6300 leftstart = rightstart;
6303 leftstop = rightstop;
6308 cc = swap_mri_condition (cc);
6312 if (truelab == NULL)
6314 cc = reverse_mri_condition (cc);
6318 if (leftstart != NULL)
6320 buf = (char *) xmalloc (20
6321 + (leftstop - leftstart)
6322 + (rightstop - rightstart));
6328 *s++ = TOLOWER (qual);
6330 memcpy (s, leftstart, leftstop - leftstart);
6331 s += leftstop - leftstart;
6333 memcpy (s, rightstart, rightstop - rightstart);
6334 s += rightstop - rightstart;
6340 buf = (char *) xmalloc (20 + strlen (truelab));
6346 *s++ = TOLOWER (extent);
6348 strcpy (s, truelab);
6353 /* Parse an MRI structured control expression. This generates test
6354 and branch instructions. STOP is where the expression ends. It
6355 goes to TRUELAB if the condition is true, and to FALSELAB if the
6356 condition is false. Exactly one of TRUELAB and FALSELAB will be
6357 NULL, meaning to fall through. QUAL is the size qualifier for the
6358 expression. EXTENT is the size to use for the branch. */
6361 parse_mri_control_expression (stop, qual, truelab, falselab, extent)
6364 const char *truelab;
6365 const char *falselab;
6378 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6379 &rightstart, &rightstop))
6385 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
6389 if (falselab != NULL)
6392 flab = mri_control_label ();
6394 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6395 rightstop, (const char *) NULL, flab, extent);
6397 input_line_pointer += 3;
6398 if (*input_line_pointer != '.'
6399 || input_line_pointer[1] == '\0')
6403 qual = input_line_pointer[1];
6404 input_line_pointer += 2;
6407 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6408 &rightstart, &rightstop))
6414 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6415 rightstop, truelab, falselab, extent);
6417 if (falselab == NULL)
6420 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6424 if (truelab != NULL)
6427 tlab = mri_control_label ();
6429 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6430 rightstop, tlab, (const char *) NULL, extent);
6432 input_line_pointer += 2;
6433 if (*input_line_pointer != '.'
6434 || input_line_pointer[1] == '\0')
6438 qual = input_line_pointer[1];
6439 input_line_pointer += 2;
6442 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6443 &rightstart, &rightstop))
6449 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6450 rightstop, truelab, falselab, extent);
6452 if (truelab == NULL)
6457 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6458 rightstop, truelab, falselab, extent);
6462 if (input_line_pointer != stop)
6463 as_bad (_("syntax error in structured control directive"));
6466 /* Handle the MRI IF pseudo-op. This may be a structured control
6467 directive, or it may be a regular assembler conditional, depending
6476 struct mri_control_info *n;
6478 /* A structured control directive must end with THEN with an
6479 optional qualifier. */
6480 s = input_line_pointer;
6481 /* We only accept '*' as introduction of comments if preceded by white space
6482 or at first column of a line (I think this can't actually happen here?)
6483 This is important when assembling:
6484 if d0 <ne> 12(a0,d0*2) then
6485 if d0 <ne> #CONST*20 then. */
6486 while ( ! ( is_end_of_line[(unsigned char) *s]
6489 && ( s == input_line_pointer
6491 || *(s-1) == '\t'))))
6494 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6497 if (s - input_line_pointer > 1
6501 if (s - input_line_pointer < 3
6502 || strncasecmp (s - 3, "THEN", 4) != 0)
6506 as_bad (_("missing then"));
6507 ignore_rest_of_line ();
6511 /* It's a conditional. */
6516 /* Since this might be a conditional if, this pseudo-op will be
6517 called even if we are supported to be ignoring input. Double
6518 check now. Clobber *input_line_pointer so that ignore_input
6519 thinks that this is not a special pseudo-op. */
6520 c = *input_line_pointer;
6521 *input_line_pointer = 0;
6522 if (ignore_input ())
6524 *input_line_pointer = c;
6525 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6526 ++input_line_pointer;
6527 demand_empty_rest_of_line ();
6530 *input_line_pointer = c;
6532 n = push_mri_control (mri_if);
6534 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6535 n->next, s[1] == '.' ? s[2] : '\0');
6538 input_line_pointer = s + 3;
6540 input_line_pointer = s + 1;
6544 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6545 ++input_line_pointer;
6548 demand_empty_rest_of_line ();
6551 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6552 structured IF, associate the ELSE with the IF. Otherwise, assume
6553 it is a conditional else. */
6564 && (mri_control_stack == NULL
6565 || mri_control_stack->type != mri_if
6566 || mri_control_stack->else_seen))
6572 c = *input_line_pointer;
6573 *input_line_pointer = 0;
6574 if (ignore_input ())
6576 *input_line_pointer = c;
6577 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6578 ++input_line_pointer;
6579 demand_empty_rest_of_line ();
6582 *input_line_pointer = c;
6584 if (mri_control_stack == NULL
6585 || mri_control_stack->type != mri_if
6586 || mri_control_stack->else_seen)
6588 as_bad (_("else without matching if"));
6589 ignore_rest_of_line ();
6593 mri_control_stack->else_seen = 1;
6595 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6596 q[0] = TOLOWER (qual);
6598 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6602 colon (mri_control_stack->next);
6606 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6607 ++input_line_pointer;
6610 demand_empty_rest_of_line ();
6613 /* Handle the MRI ENDI pseudo-op. */
6617 int ignore ATTRIBUTE_UNUSED;
6619 if (mri_control_stack == NULL
6620 || mri_control_stack->type != mri_if)
6622 as_bad (_("endi without matching if"));
6623 ignore_rest_of_line ();
6627 /* ignore_input will not return true for ENDI, so we don't need to
6628 worry about checking it again here. */
6630 if (! mri_control_stack->else_seen)
6631 colon (mri_control_stack->next);
6632 colon (mri_control_stack->bottom);
6638 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6639 ++input_line_pointer;
6642 demand_empty_rest_of_line ();
6645 /* Handle the MRI BREAK pseudo-op. */
6648 s_mri_break (extent)
6651 struct mri_control_info *n;
6655 n = mri_control_stack;
6657 && n->type != mri_for
6658 && n->type != mri_repeat
6659 && n->type != mri_while)
6663 as_bad (_("break outside of structured loop"));
6664 ignore_rest_of_line ();
6668 buf = (char *) xmalloc (20 + strlen (n->bottom));
6669 ex[0] = TOLOWER (extent);
6671 sprintf (buf, "bra%s %s", ex, n->bottom);
6677 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6678 ++input_line_pointer;
6681 demand_empty_rest_of_line ();
6684 /* Handle the MRI NEXT pseudo-op. */
6690 struct mri_control_info *n;
6694 n = mri_control_stack;
6696 && n->type != mri_for
6697 && n->type != mri_repeat
6698 && n->type != mri_while)
6702 as_bad (_("next outside of structured loop"));
6703 ignore_rest_of_line ();
6707 buf = (char *) xmalloc (20 + strlen (n->next));
6708 ex[0] = TOLOWER (extent);
6710 sprintf (buf, "bra%s %s", ex, n->next);
6716 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6717 ++input_line_pointer;
6720 demand_empty_rest_of_line ();
6723 /* Handle the MRI FOR pseudo-op. */
6729 const char *varstart, *varstop;
6730 const char *initstart, *initstop;
6731 const char *endstart, *endstop;
6732 const char *bystart, *bystop;
6736 struct mri_control_info *n;
6742 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6746 varstart = input_line_pointer;
6748 /* Look for the '='. */
6749 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6750 && *input_line_pointer != '=')
6751 ++input_line_pointer;
6752 if (*input_line_pointer != '=')
6754 as_bad (_("missing ="));
6755 ignore_rest_of_line ();
6759 varstop = input_line_pointer;
6760 if (varstop > varstart
6761 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6764 ++input_line_pointer;
6766 initstart = input_line_pointer;
6768 /* Look for TO or DOWNTO. */
6771 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6773 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6774 && ! is_part_of_name (input_line_pointer[2]))
6776 initstop = input_line_pointer;
6777 input_line_pointer += 2;
6780 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6781 && ! is_part_of_name (input_line_pointer[6]))
6783 initstop = input_line_pointer;
6785 input_line_pointer += 6;
6788 ++input_line_pointer;
6790 if (initstop == NULL)
6792 as_bad (_("missing to or downto"));
6793 ignore_rest_of_line ();
6796 if (initstop > initstart
6797 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6801 endstart = input_line_pointer;
6803 /* Look for BY or DO. */
6806 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6808 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6809 && ! is_part_of_name (input_line_pointer[2]))
6811 endstop = input_line_pointer;
6813 input_line_pointer += 2;
6816 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6817 && (input_line_pointer[2] == '.'
6818 || ! is_part_of_name (input_line_pointer[2])))
6820 endstop = input_line_pointer;
6821 input_line_pointer += 2;
6824 ++input_line_pointer;
6826 if (endstop == NULL)
6828 as_bad (_("missing do"));
6829 ignore_rest_of_line ();
6832 if (endstop > endstart
6833 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6839 bystop = bystart + 2;
6844 bystart = input_line_pointer;
6848 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6850 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6851 && (input_line_pointer[2] == '.'
6852 || ! is_part_of_name (input_line_pointer[2])))
6854 bystop = input_line_pointer;
6855 input_line_pointer += 2;
6858 ++input_line_pointer;
6862 as_bad (_("missing do"));
6863 ignore_rest_of_line ();
6866 if (bystop > bystart
6867 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6871 if (*input_line_pointer != '.')
6875 extent = input_line_pointer[1];
6876 input_line_pointer += 2;
6879 /* We have fully parsed the FOR operands. Now build the loop. */
6880 n = push_mri_control (mri_for);
6882 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6884 /* Move init,var. */
6891 *s++ = TOLOWER (qual);
6893 memcpy (s, initstart, initstop - initstart);
6894 s += initstop - initstart;
6896 memcpy (s, varstart, varstop - varstart);
6897 s += varstop - varstart;
6909 *s++ = TOLOWER (qual);
6911 memcpy (s, endstart, endstop - endstart);
6912 s += endstop - endstart;
6914 memcpy (s, varstart, varstop - varstart);
6915 s += varstop - varstart;
6920 ex[0] = TOLOWER (extent);
6923 sprintf (buf, "blt%s %s", ex, n->bottom);
6925 sprintf (buf, "bgt%s %s", ex, n->bottom);
6928 /* Put together the add or sub instruction used by ENDF. */
6936 *s++ = TOLOWER (qual);
6938 memcpy (s, bystart, bystop - bystart);
6939 s += bystop - bystart;
6941 memcpy (s, varstart, varstop - varstart);
6942 s += varstop - varstart;
6948 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6949 ++input_line_pointer;
6952 demand_empty_rest_of_line ();
6955 /* Handle the MRI ENDF pseudo-op. */
6959 int ignore ATTRIBUTE_UNUSED;
6961 if (mri_control_stack == NULL
6962 || mri_control_stack->type != mri_for)
6964 as_bad (_("endf without for"));
6965 ignore_rest_of_line ();
6969 colon (mri_control_stack->next);
6971 mri_assemble (mri_control_stack->incr);
6973 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6974 mri_assemble (mri_control_stack->incr);
6976 free (mri_control_stack->incr);
6978 colon (mri_control_stack->bottom);
6984 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6985 ++input_line_pointer;
6988 demand_empty_rest_of_line ();
6991 /* Handle the MRI REPEAT pseudo-op. */
6994 s_mri_repeat (ignore)
6995 int ignore ATTRIBUTE_UNUSED;
6997 struct mri_control_info *n;
6999 n = push_mri_control (mri_repeat);
7003 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7004 ++input_line_pointer;
7006 demand_empty_rest_of_line ();
7009 /* Handle the MRI UNTIL pseudo-op. */
7017 if (mri_control_stack == NULL
7018 || mri_control_stack->type != mri_repeat)
7020 as_bad (_("until without repeat"));
7021 ignore_rest_of_line ();
7025 colon (mri_control_stack->next);
7027 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
7030 parse_mri_control_expression (s, qual, (const char *) NULL,
7031 mri_control_stack->top, '\0');
7033 colon (mri_control_stack->bottom);
7035 input_line_pointer = s;
7041 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7042 ++input_line_pointer;
7045 demand_empty_rest_of_line ();
7048 /* Handle the MRI WHILE pseudo-op. */
7056 struct mri_control_info *n;
7058 s = input_line_pointer;
7059 /* We only accept '*' as introduction of comments if preceded by white space
7060 or at first column of a line (I think this can't actually happen here?)
7061 This is important when assembling:
7062 while d0 <ne> 12(a0,d0*2) do
7063 while d0 <ne> #CONST*20 do. */
7064 while (! (is_end_of_line[(unsigned char) *s]
7067 && (s == input_line_pointer
7069 || *(s-1) == '\t'))))
7072 while (*s == ' ' || *s == '\t')
7074 if (s - input_line_pointer > 1
7077 if (s - input_line_pointer < 2
7078 || strncasecmp (s - 1, "DO", 2) != 0)
7080 as_bad (_("missing do"));
7081 ignore_rest_of_line ();
7085 n = push_mri_control (mri_while);
7089 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
7090 s[1] == '.' ? s[2] : '\0');
7092 input_line_pointer = s + 1;
7093 if (*input_line_pointer == '.')
7094 input_line_pointer += 2;
7098 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7099 ++input_line_pointer;
7102 demand_empty_rest_of_line ();
7105 /* Handle the MRI ENDW pseudo-op. */
7109 int ignore ATTRIBUTE_UNUSED;
7113 if (mri_control_stack == NULL
7114 || mri_control_stack->type != mri_while)
7116 as_bad (_("endw without while"));
7117 ignore_rest_of_line ();
7121 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
7122 sprintf (buf, "bra %s", mri_control_stack->next);
7126 colon (mri_control_stack->bottom);
7132 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7133 ++input_line_pointer;
7136 demand_empty_rest_of_line ();
7141 * Invocation line includes a switch not recognized by the base assembler.
7142 * See if it's a processor-specific option. These are:
7144 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
7145 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
7146 * Select the architecture. Instructions or features not
7147 * supported by the selected architecture cause fatal
7148 * errors. More than one may be specified. The default is
7149 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
7150 * for -m68000, and -m68882 is a synonym for -m68881.
7151 * -[A]m[c]no-68851, -[A]m[c]no-68881
7152 * Don't accept 688?1 instructions. (The "c" is kind of silly,
7153 * so don't use or document it, but that's the way the parsing
7156 * -pic Indicates PIC.
7157 * -k Indicates PIC. (Sun 3 only.)
7158 * --pcrel Never turn PC-relative branches into absolute jumps.
7161 * Permit `|' to be used in expressions.
7166 const char *md_shortopts = "lSA:m:kQ:V";
7168 const char *md_shortopts = "lSA:m:k";
7171 struct option md_longopts[] = {
7172 #define OPTION_PIC (OPTION_MD_BASE)
7173 {"pic", no_argument, NULL, OPTION_PIC},
7174 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7175 {"register-prefix-optional", no_argument, NULL,
7176 OPTION_REGISTER_PREFIX_OPTIONAL},
7177 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7178 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
7179 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7180 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
7181 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7182 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
7183 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7184 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
7185 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7186 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
7187 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7188 {"pcrel", no_argument, NULL, OPTION_PCREL},
7189 {NULL, no_argument, NULL, 0}
7191 size_t md_longopts_size = sizeof (md_longopts);
7194 md_parse_option (c, arg)
7200 case 'l': /* -l means keep external to 2 bit offset
7201 rather than 16 bit one. */
7202 flag_short_refs = 1;
7205 case 'S': /* -S means that jbsr's always turn into
7207 flag_long_jumps = 1;
7210 case OPTION_PCREL: /* --pcrel means never turn PC-relative
7211 branches into absolute jumps. */
7212 flag_keep_pcrel = 1;
7218 /* Intentional fall-through. */
7221 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
7225 const char *oarg = arg;
7231 if (arg[0] == 'c' && arg[1] == '6')
7234 for (i = 0; i < n_archs; i++)
7235 if (!strcmp (arg, archs[i].name))
7240 as_bad (_("unrecognized option `%s'"), oarg);
7243 arch = archs[i].arch;
7246 else if (arch == m68851)
7255 if (arg[0] == 'c' && arg[1] == '6')
7258 for (i = 0; i < n_archs; i++)
7259 if (!strcmp (arg, archs[i].name))
7261 unsigned long arch = archs[i].arch;
7262 if (cpu_of_arch (arch))
7263 /* It's a cpu spec. */
7265 current_architecture &= ~m68000up;
7266 current_architecture |= arch;
7267 current_chip = archs[i].chip;
7269 else if (arch == m68881)
7271 current_architecture |= m68881;
7274 else if (arch == m68851)
7276 current_architecture |= m68851;
7286 as_bad (_("unrecognized architecture specification `%s'"), arg);
7295 break; /* -pic, Position Independent Code. */
7297 case OPTION_REGISTER_PREFIX_OPTIONAL:
7298 flag_reg_prefix_optional = 1;
7299 reg_prefix_optional_seen = 1;
7302 /* -V: SVR4 argument to print version ID. */
7304 print_version_id ();
7307 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7308 should be emitted or not. FIXME: Not implemented. */
7312 case OPTION_BITWISE_OR:
7317 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
7319 for (s = m68k_comment_chars; *s != '\0'; s++)
7323 m68k_comment_chars = n;
7327 case OPTION_BASE_SIZE_DEFAULT_16:
7328 m68k_index_width_default = SIZE_WORD;
7331 case OPTION_BASE_SIZE_DEFAULT_32:
7332 m68k_index_width_default = SIZE_LONG;
7335 case OPTION_DISP_SIZE_DEFAULT_16:
7337 m68k_rel32_from_cmdline = 1;
7340 case OPTION_DISP_SIZE_DEFAULT_32:
7342 m68k_rel32_from_cmdline = 1;
7353 md_show_usage (stream)
7356 const char *default_cpu = TARGET_CPU;
7358 unsigned int default_arch;
7360 /* Get the canonical name for the default target CPU. */
7361 if (*default_cpu == 'm')
7363 for (i = 0; i < n_archs; i++)
7365 if (strcasecmp (default_cpu, archs[i].name) == 0)
7367 default_arch = archs[i].arch;
7368 for (i = 0; i < n_archs; i++)
7370 if (archs[i].arch == default_arch
7373 default_cpu = archs[i].name;
7380 fprintf (stream, _("\
7382 -l use 1 word for refs to undefined symbols [default 2]\n\
7383 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
7384 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
7385 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m521x | -m5249 |\n\
7386 -m528x | -m5307 | -m5407 | -m547x | -m548x | -mcfv4 | -mcfv4e\n\
7387 specify variant of 680X0 architecture [default %s]\n\
7388 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
7389 target has/lacks floating-point coprocessor\n\
7390 [default yes for 68020, 68030, and cpu32]\n"),
7392 fprintf (stream, _("\
7393 -m68851 | -mno-68851\n\
7394 target has/lacks memory-management unit coprocessor\n\
7395 [default yes for 68020 and up]\n\
7396 -pic, -k generate position independent code\n\
7397 -S turn jbsr into jsr\n\
7398 --pcrel never turn PC-relative branches into absolute jumps\n\
7399 --register-prefix-optional\n\
7400 recognize register names without prefix character\n\
7401 --bitwise-or do not treat `|' as a comment character\n"));
7402 fprintf (stream, _("\
7403 --base-size-default-16 base reg without size is 16 bits\n\
7404 --base-size-default-32 base reg without size is 32 bits (default)\n\
7405 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7406 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
7411 /* TEST2: Test md_assemble() */
7412 /* Warning, this routine probably doesn't work anymore. */
7416 struct m68k_it the_ins;
7424 if (!gets (buf) || !*buf)
7426 if (buf[0] == '|' || buf[1] == '.')
7428 for (cp = buf; *cp; cp++)
7433 memset (&the_ins, '\0', sizeof (the_ins));
7434 m68k_ip (&the_ins, buf);
7437 printf (_("Error %s in %s\n"), the_ins.error, buf);
7441 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7442 for (n = 0; n < the_ins.numo; n++)
7443 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7445 print_the_insn (&the_ins.opcode[0], stdout);
7446 (void) putchar ('\n');
7448 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7450 if (the_ins.operands[n].error)
7452 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7455 printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
7456 if (the_ins.operands[n].b_const)
7457 printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
7458 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
7459 if (the_ins.operands[n].b_iadd)
7460 printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
7461 (void) putchar ('\n');
7473 while (*str && *str != ' ')
7475 if (str[-1] == ':' || str[1] == '=')
7482 /* Possible states for relaxation:
7484 0 0 branch offset byte (bra, etc)
7488 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7492 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7499 /* We have no need to default values of symbols. */
7502 md_undefined_symbol (name)
7503 char *name ATTRIBUTE_UNUSED;
7508 /* Round up a section size to the appropriate boundary. */
7510 md_section_align (segment, size)
7511 segT segment ATTRIBUTE_UNUSED;
7515 #ifdef BFD_ASSEMBLER
7516 /* For a.out, force the section size to be aligned. If we don't do
7517 this, BFD will align it for us, but it will not write out the
7518 final bytes of the section. This may be a bug in BFD, but it is
7519 easier to fix it here since that is how the other a.out targets
7523 align = bfd_get_section_alignment (stdoutput, segment);
7524 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7531 /* Exactly what point is a PC-relative offset relative TO?
7532 On the 68k, it is relative to the address of the first extension
7533 word. The difference between the addresses of the offset and the
7534 first extension word is stored in fx_pcrel_adjust. */
7536 md_pcrel_from (fixP)
7541 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7542 sign extend the value here. */
7543 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7546 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7549 #ifndef BFD_ASSEMBLER
7553 tc_coff_symbol_emit_hook (ignore)
7554 symbolS *ignore ATTRIBUTE_UNUSED;
7559 tc_coff_sizemachdep (frag)
7562 switch (frag->fr_subtype & 0x3)
7580 m68k_elf_final_processing ()
7582 /* Set file-specific flags if this is a cpu32 processor. */
7583 if (cpu_of_arch (current_architecture) & cpu32)
7584 elf_elfheader (stdoutput)->e_flags |= EF_CPU32;
7585 else if ((cpu_of_arch (current_architecture) & m68000up)
7586 && !(cpu_of_arch (current_architecture) & m68020up))
7587 elf_elfheader (stdoutput)->e_flags |= EF_M68000;
7592 tc_m68k_regname_to_dw2regnum (const char *regname)
7594 unsigned int regnum;
7595 static const char *const regnames[] =
7597 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7598 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7599 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7603 for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
7604 if (strcmp (regname, regnames[regnum]) == 0)
7611 tc_m68k_frame_initial_instructions (void)
7613 static int sp_regno = -1;
7616 sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
7618 cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
7619 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);