1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "safe-ctype.h"
27 #include "dwarf2dbg.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
119 struct label_line *next;
126 /* The list of labels. */
128 static struct label_line *labels;
130 /* The current label. */
132 static struct label_line *current_label;
134 /* Its an arbitrary name: This means I don't approve of it */
135 /* See flames below */
136 static struct obstack robyn;
140 const char *m_operands;
141 unsigned long m_opcode;
145 struct m68k_incant *m_next;
148 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
149 #define gettwo(x) (((x)->m_opcode)&0xffff)
151 static const enum m68k_register m68000_control_regs[] = { 0 };
152 static const enum m68k_register m68010_control_regs[] = {
156 static const enum m68k_register m68020_control_regs[] = {
157 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
160 static const enum m68k_register m68040_control_regs[] = {
161 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
162 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
165 static const enum m68k_register m68060_control_regs[] = {
166 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
167 USP, VBR, URP, SRP, PCR,
170 static const enum m68k_register mcf_control_regs[] = {
171 CACR, TC, ITT0, ITT1, DTT0, DTT1, VBR, ROMBAR,
172 RAMBAR0, RAMBAR1, MBAR,
175 #define cpu32_control_regs m68010_control_regs
177 static const enum m68k_register *control_regs;
179 /* internal form of a 68020 instruction */
183 const char *args; /* list of opcode info */
186 int numo; /* Number of shorts in opcode */
189 struct m68k_op operands[6];
191 int nexp; /* number of exprs in use */
192 struct m68k_exp exprs[4];
194 int nfrag; /* Number of frags we have to produce */
197 int fragoff; /* Where in the current opcode the frag ends */
204 int nrel; /* Num of reloc strucs in use */
211 /* In a pc relative address the difference between the address
212 of the offset and the address that the offset is relative
213 to. This depends on the addressing mode. Basically this
214 is the value to put in the offset field to address the
215 first byte of the offset, without regarding the special
216 significance of some values (in the branch instruction, for
220 /* Whether this expression needs special pic relocation, and if
222 enum pic_relocation pic_reloc;
225 reloc[5]; /* Five is enough??? */
228 #define cpu_of_arch(x) ((x) & (m68000up|mcf))
229 #define float_of_arch(x) ((x) & mfloat)
230 #define mmu_of_arch(x) ((x) & mmmu)
231 #define arch_coldfire_p(x) (((x) & mcf) != 0)
233 /* Macros for determining if cpu supports a specific addressing mode */
234 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcf5407))
236 static struct m68k_it the_ins; /* the instruction being assembled */
238 #define op(ex) ((ex)->exp.X_op)
239 #define adds(ex) ((ex)->exp.X_add_symbol)
240 #define subs(ex) ((ex)->exp.X_op_symbol)
241 #define offs(ex) ((ex)->exp.X_add_number)
243 /* Macros for adding things to the m68k_it struct */
245 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
247 /* Static functions. */
249 static void insop PARAMS ((int, const struct m68k_incant *));
250 static void add_fix PARAMS ((int, struct m68k_exp *, int, int));
251 static void add_frag PARAMS ((symbolS *, offsetT, int));
253 /* Like addword, but goes BEFORE general operands */
257 const struct m68k_incant *opcode;
260 for (z = the_ins.numo; z > opcode->m_codenum; --z)
261 the_ins.opcode[z] = the_ins.opcode[z - 1];
262 for (z = 0; z < the_ins.nrel; z++)
263 the_ins.reloc[z].n += 2;
264 for (z = 0; z < the_ins.nfrag; z++)
265 the_ins.fragb[z].fragoff++;
266 the_ins.opcode[opcode->m_codenum] = w;
270 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
273 add_fix (width, exp, pc_rel, pc_fix)
275 struct m68k_exp *exp;
279 the_ins.reloc[the_ins.nrel].n = ((width == 'B' || width == '3')
283 : (the_ins.numo*2)));
284 the_ins.reloc[the_ins.nrel].exp = exp->exp;
285 the_ins.reloc[the_ins.nrel].wid = width;
286 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
288 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
290 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
293 /* Cause an extra frag to be generated here, inserting up to 10 bytes
294 (that value is chosen in the frag_var call in md_assemble). TYPE
295 is the subtype of the frag to be generated; its primary type is
296 rs_machine_dependent.
298 The TYPE parameter is also used by md_convert_frag_1 and
299 md_estimate_size_before_relax. The appropriate type of fixup will
300 be emitted by md_convert_frag_1.
302 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
304 add_frag (add, off, type)
309 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
310 the_ins.fragb[the_ins.nfrag].fadd = add;
311 the_ins.fragb[the_ins.nfrag].foff = off;
312 the_ins.fragb[the_ins.nfrag++].fragty = type;
316 (op (ex) != O_constant && op (ex) != O_big)
318 static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
319 static int get_num PARAMS ((struct m68k_exp *exp, int ok));
320 static void m68k_ip PARAMS ((char *));
321 static void insert_reg PARAMS ((const char *, int));
322 static void select_control_regs PARAMS ((void));
323 static void init_regtable PARAMS ((void));
324 static int reverse_16_bits PARAMS ((int in));
325 static int reverse_8_bits PARAMS ((int in));
326 static void install_gen_operand PARAMS ((int mode, int val));
327 static void install_operand PARAMS ((int mode, int val));
328 static void s_bss PARAMS ((int));
329 static void s_data1 PARAMS ((int));
330 static void s_data2 PARAMS ((int));
331 static void s_even PARAMS ((int));
332 static void s_proc PARAMS ((int));
333 static void mri_chip PARAMS ((void));
334 static void s_chip PARAMS ((int));
335 static void s_fopt PARAMS ((int));
336 static void s_opt PARAMS ((int));
337 static void s_reg PARAMS ((int));
338 static void s_restore PARAMS ((int));
339 static void s_save PARAMS ((int));
340 static void s_mri_if PARAMS ((int));
341 static void s_mri_else PARAMS ((int));
342 static void s_mri_endi PARAMS ((int));
343 static void s_mri_break PARAMS ((int));
344 static void s_mri_next PARAMS ((int));
345 static void s_mri_for PARAMS ((int));
346 static void s_mri_endf PARAMS ((int));
347 static void s_mri_repeat PARAMS ((int));
348 static void s_mri_until PARAMS ((int));
349 static void s_mri_while PARAMS ((int));
350 static void s_mri_endw PARAMS ((int));
351 static void md_convert_frag_1 PARAMS ((fragS *));
353 static int current_architecture;
362 static const struct m68k_cpu archs[] =
364 { m68000, "68000", 0 },
365 { m68010, "68010", 0 },
366 { m68020, "68020", 0 },
367 { m68030, "68030", 0 },
368 { m68040, "68040", 0 },
369 { m68060, "68060", 0 },
370 { cpu32, "cpu32", 0 },
371 { m68881, "68881", 0 },
372 { m68851, "68851", 0 },
373 { mcf5200, "5200", 0 },
374 { mcf5206e, "5206e", 0 },
375 { mcf5307, "5307", 0},
376 { mcf5407, "5407", 0},
377 /* Aliases (effectively, so far as gas is concerned) for the above
379 { m68020, "68k", 1 },
380 { m68000, "68008", 1 },
381 { m68000, "68302", 1 },
382 { m68000, "68306", 1 },
383 { m68000, "68307", 1 },
384 { m68000, "68322", 1 },
385 { m68000, "68356", 1 },
386 { m68000, "68ec000", 1 },
387 { m68000, "68hc000", 1 },
388 { m68000, "68hc001", 1 },
389 { m68020, "68ec020", 1 },
390 { m68030, "68ec030", 1 },
391 { m68040, "68ec040", 1 },
392 { m68060, "68ec060", 1 },
393 { cpu32, "68330", 1 },
394 { cpu32, "68331", 1 },
395 { cpu32, "68332", 1 },
396 { cpu32, "68333", 1 },
397 { cpu32, "68334", 1 },
398 { cpu32, "68336", 1 },
399 { cpu32, "68340", 1 },
400 { cpu32, "68341", 1 },
401 { cpu32, "68349", 1 },
402 { cpu32, "68360", 1 },
403 { m68881, "68882", 1 },
404 { mcf5200, "5202", 1 },
405 { mcf5200, "5204", 1 },
406 { mcf5200, "5206", 1 },
409 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
411 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
412 architecture and we have a lot of relaxation modes. */
414 /* Macros used in the relaxation code. */
415 #define TAB(x,y) (((x) << 2) + (y))
416 #define TABTYPE(x) ((x) >> 2)
418 /* Relaxation states. */
424 /* Here are all the relaxation modes we support. First we can relax ordinary
425 branches. On 68020 and higher and on CPU32 all branch instructions take
426 three forms, so on these CPUs all branches always remain as such. When we
427 have to expand to the LONG form on a 68000, though, we substitute an
428 absolute jump instead. This is a direct replacement for unconditional
429 branches and a branch over a jump for conditional branches. However, if the
430 user requires PIC and disables this with --pcrel, we can only relax between
431 BYTE and SHORT forms, punting if that isn't enough. This gives us four
432 different relaxation modes for branches: */
434 #define BRANCHBWL 0 /* branch byte, word, or long */
435 #define BRABSJUNC 1 /* absolute jump for LONG, unconditional */
436 #define BRABSJCOND 2 /* absolute jump for LONG, conditional */
437 #define BRANCHBW 3 /* branch byte or word */
439 /* We also relax coprocessor branches and DBcc's. All CPUs that support
440 coprocessor branches support them in word and long forms, so we have only
441 one relaxation mode for them. DBcc's are word only on all CPUs. We can
442 relax them to the LONG form with a branch-around sequence. This sequence
443 can use a long branch (if available) or an absolute jump (if acceptable).
444 This gives us two relaxation modes. If long branches are not available and
445 absolute jumps are not acceptable, we don't relax DBcc's. */
447 #define FBRANCH 4 /* coprocessor branch */
448 #define DBCCLBR 5 /* DBcc relaxable with a long branch */
449 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump */
451 /* That's all for instruction relaxation. However, we also relax PC-relative
452 operands. Specifically, we have three operand relaxation modes. On the
453 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
454 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
455 two. Also PC+displacement+index operands in their simple form (with a non-
456 suppressed index without memory indirection) are supported on all CPUs, but
457 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
458 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
459 form of the PC+displacement+index operand. Finally, some absolute operands
460 can be relaxed down to 16-bit PC-relative. */
462 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative */
463 #define PCINDEX 8 /* PC+displacement+index */
464 #define ABSTOPCREL 9 /* absolute relax down to 16-bit PC-relative */
466 /* Note that calls to frag_var need to specify the maximum expansion
467 needed; this is currently 10 bytes for DBCC. */
470 How far Forward this mode will reach:
471 How far Backward this mode will reach:
472 How many bytes this mode will add to the size of the frag
473 Which mode to go to if the offset won't fit in this one
475 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
476 relax_typeS md_relax_table[] =
478 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
479 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
483 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
484 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
488 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
489 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
493 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
498 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
499 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
503 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
504 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
508 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
509 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
513 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE */
514 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
518 { 125, -130, 0, TAB (PCINDEX, SHORT) },
519 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
523 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE */
524 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
529 /* These are the machine dependent pseudo-ops. These are included so
530 the assembler can work on the output from the SUN C compiler, which
534 /* This table describes all the machine specific pseudo-ops the assembler
535 has to support. The fields are:
536 pseudo-op name without dot
537 function to call to execute this pseudo-op
538 Integer arg to pass to the function
540 const pseudo_typeS md_pseudo_table[] =
542 {"data1", s_data1, 0},
543 {"data2", s_data2, 0},
546 {"skip", s_space, 0},
548 #if defined (TE_SUN3) || defined (OBJ_ELF)
549 {"align", s_align_bytes, 0},
552 {"swbeg", s_ignore, 0},
554 {"extend", float_cons, 'x'},
555 {"ldouble", float_cons, 'x'},
557 /* The following pseudo-ops are supported for MRI compatibility. */
559 {"comline", s_space, 1},
561 {"mask2", s_ignore, 0},
564 {"restore", s_restore, 0},
568 {"if.b", s_mri_if, 'b'},
569 {"if.w", s_mri_if, 'w'},
570 {"if.l", s_mri_if, 'l'},
571 {"else", s_mri_else, 0},
572 {"else.s", s_mri_else, 's'},
573 {"else.l", s_mri_else, 'l'},
574 {"endi", s_mri_endi, 0},
575 {"break", s_mri_break, 0},
576 {"break.s", s_mri_break, 's'},
577 {"break.l", s_mri_break, 'l'},
578 {"next", s_mri_next, 0},
579 {"next.s", s_mri_next, 's'},
580 {"next.l", s_mri_next, 'l'},
581 {"for", s_mri_for, 0},
582 {"for.b", s_mri_for, 'b'},
583 {"for.w", s_mri_for, 'w'},
584 {"for.l", s_mri_for, 'l'},
585 {"endf", s_mri_endf, 0},
586 {"repeat", s_mri_repeat, 0},
587 {"until", s_mri_until, 0},
588 {"until.b", s_mri_until, 'b'},
589 {"until.w", s_mri_until, 'w'},
590 {"until.l", s_mri_until, 'l'},
591 {"while", s_mri_while, 0},
592 {"while.b", s_mri_while, 'b'},
593 {"while.w", s_mri_while, 'w'},
594 {"while.l", s_mri_while, 'l'},
595 {"endw", s_mri_endw, 0},
600 /* The mote pseudo ops are put into the opcode table, since they
601 don't start with a . they look like opcodes to gas.
605 extern void obj_coff_section PARAMS ((int));
608 const pseudo_typeS mote_pseudo_table[] =
621 {"xdef", s_globl, 0},
623 {"align", s_align_bytes, 0},
625 {"align", s_align_ptwo, 0},
628 {"sect", obj_coff_section, 0},
629 {"section", obj_coff_section, 0},
634 #define issbyte(x) ((x)>=-128 && (x)<=127)
635 #define isubyte(x) ((x)>=0 && (x)<=255)
636 #define issword(x) ((x)>=-32768 && (x)<=32767)
637 #define isuword(x) ((x)>=0 && (x)<=65535)
639 #define isbyte(x) ((x)>= -255 && (x)<=255)
640 #define isword(x) ((x)>=-65536 && (x)<=65535)
641 #define islong(x) (1)
643 extern char *input_line_pointer;
645 static char notend_table[256];
646 static char alt_notend_table[256];
648 (! (notend_table[(unsigned char) *s] \
650 && alt_notend_table[(unsigned char) s[1]])))
652 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
654 #ifdef NO_PCREL_RELOCS
657 make_pcrel_absolute(fixP, add_number)
661 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
663 /* rewrite the PC relative instructions to absolute address ones.
664 * these are rumoured to be faster, and the apollo linker refuses
665 * to deal with the PC relative relocations.
667 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
672 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
678 as_fatal (_("Unknown PC relative instruction"));
683 #endif /* NO_PCREL_RELOCS */
686 tc_coff_fix2rtype (fixP)
689 if (fixP->fx_tcbit && fixP->fx_size == 4)
690 return R_RELLONG_NEG;
691 #ifdef NO_PCREL_RELOCS
692 know (fixP->fx_pcrel == 0);
693 return (fixP->fx_size == 1 ? R_RELBYTE
694 : fixP->fx_size == 2 ? R_DIR16
697 return (fixP->fx_pcrel ?
698 (fixP->fx_size == 1 ? R_PCRBYTE :
699 fixP->fx_size == 2 ? R_PCRWORD :
701 (fixP->fx_size == 1 ? R_RELBYTE :
702 fixP->fx_size == 2 ? R_RELWORD :
711 /* Return zero if the reference to SYMBOL from within the same segment may
714 /* On an ELF system, we can't relax an externally visible symbol,
715 because it may be overridden by a shared library. However, if
716 TARGET_OS is "elf", then we presume that we are assembling for an
717 embedded system, in which case we don't have to worry about shared
718 libraries, and we can relax any external sym. */
720 #define relaxable_symbol(symbol) \
721 (!((S_IS_EXTERNAL (symbol) && strcmp (TARGET_OS, "elf") != 0) \
722 || S_IS_WEAK (symbol)))
724 /* Compute the relocation code for a fixup of SIZE bytes, using pc
725 relative relocation if PCREL is non-zero. PIC says whether a special
726 pic relocation was requested. */
728 static bfd_reloc_code_real_type get_reloc_code
729 PARAMS ((int, int, enum pic_relocation));
731 static bfd_reloc_code_real_type
732 get_reloc_code (size, pcrel, pic)
735 enum pic_relocation pic;
743 return BFD_RELOC_8_GOT_PCREL;
745 return BFD_RELOC_16_GOT_PCREL;
747 return BFD_RELOC_32_GOT_PCREL;
755 return BFD_RELOC_8_GOTOFF;
757 return BFD_RELOC_16_GOTOFF;
759 return BFD_RELOC_32_GOTOFF;
767 return BFD_RELOC_8_PLT_PCREL;
769 return BFD_RELOC_16_PLT_PCREL;
771 return BFD_RELOC_32_PLT_PCREL;
779 return BFD_RELOC_8_PLTOFF;
781 return BFD_RELOC_16_PLTOFF;
783 return BFD_RELOC_32_PLTOFF;
793 return BFD_RELOC_8_PCREL;
795 return BFD_RELOC_16_PCREL;
797 return BFD_RELOC_32_PCREL;
817 as_bad (_("Can not do %d byte pc-relative relocation"), size);
819 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
824 as_bad (_("Can not do %d byte relocation"), size);
826 as_bad (_("Can not do %d byte pic relocation"), size);
829 return BFD_RELOC_NONE;
832 /* Here we decide which fixups can be adjusted to make them relative
833 to the beginning of the section instead of the symbol. Basically
834 we need to make sure that the dynamic relocations are done
835 correctly, so in some cases we force the original symbol to be
838 tc_m68k_fix_adjustable (fixP)
841 /* adjust_reloc_syms doesn't know about the GOT */
842 switch (fixP->fx_r_type)
844 case BFD_RELOC_8_GOT_PCREL:
845 case BFD_RELOC_16_GOT_PCREL:
846 case BFD_RELOC_32_GOT_PCREL:
847 case BFD_RELOC_8_GOTOFF:
848 case BFD_RELOC_16_GOTOFF:
849 case BFD_RELOC_32_GOTOFF:
850 case BFD_RELOC_8_PLT_PCREL:
851 case BFD_RELOC_16_PLT_PCREL:
852 case BFD_RELOC_32_PLT_PCREL:
853 case BFD_RELOC_8_PLTOFF:
854 case BFD_RELOC_16_PLTOFF:
855 case BFD_RELOC_32_PLTOFF:
858 case BFD_RELOC_VTABLE_INHERIT:
859 case BFD_RELOC_VTABLE_ENTRY:
869 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
871 #define relaxable_symbol(symbol) 1
878 tc_gen_reloc (section, fixp)
879 asection *section ATTRIBUTE_UNUSED;
883 bfd_reloc_code_real_type code;
885 /* If the tcbit is set, then this was a fixup of a negative value
886 that was never resolved. We do not have a reloc to handle this,
887 so just return. We assume that other code will have detected this
888 situation and produced a helpful error message, so we just tell the
889 user that the reloc cannot be produced. */
893 as_bad_where (fixp->fx_file, fixp->fx_line,
894 _("Unable to produce reloc against symbol '%s'"),
895 S_GET_NAME (fixp->fx_addsy));
899 if (fixp->fx_r_type != BFD_RELOC_NONE)
901 code = fixp->fx_r_type;
903 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
904 that fixup_segment converted a non-PC relative reloc into a
905 PC relative reloc. In such a case, we need to convert the
912 code = BFD_RELOC_8_PCREL;
915 code = BFD_RELOC_16_PCREL;
918 code = BFD_RELOC_32_PCREL;
920 case BFD_RELOC_8_PCREL:
921 case BFD_RELOC_16_PCREL:
922 case BFD_RELOC_32_PCREL:
923 case BFD_RELOC_8_GOT_PCREL:
924 case BFD_RELOC_16_GOT_PCREL:
925 case BFD_RELOC_32_GOT_PCREL:
926 case BFD_RELOC_8_GOTOFF:
927 case BFD_RELOC_16_GOTOFF:
928 case BFD_RELOC_32_GOTOFF:
929 case BFD_RELOC_8_PLT_PCREL:
930 case BFD_RELOC_16_PLT_PCREL:
931 case BFD_RELOC_32_PLT_PCREL:
932 case BFD_RELOC_8_PLTOFF:
933 case BFD_RELOC_16_PLTOFF:
934 case BFD_RELOC_32_PLTOFF:
937 as_bad_where (fixp->fx_file, fixp->fx_line,
938 _("Cannot make %s relocation PC relative"),
939 bfd_get_reloc_code_name (code));
945 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
946 switch (F (fixp->fx_size, fixp->fx_pcrel))
948 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
949 MAP (1, 0, BFD_RELOC_8);
950 MAP (2, 0, BFD_RELOC_16);
951 MAP (4, 0, BFD_RELOC_32);
952 MAP (1, 1, BFD_RELOC_8_PCREL);
953 MAP (2, 1, BFD_RELOC_16_PCREL);
954 MAP (4, 1, BFD_RELOC_32_PCREL);
962 reloc = (arelent *) xmalloc (sizeof (arelent));
963 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
964 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
965 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
968 reloc->addend = fixp->fx_addnumber;
973 reloc->addend = fixp->fx_addnumber;
975 reloc->addend = (section->vma
976 /* Explicit sign extension in case char is
978 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
980 + md_pcrel_from (fixp));
983 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
984 assert (reloc->howto != 0);
989 #endif /* BFD_ASSEMBLER */
991 /* Handle of the OPCODE hash table. NULL means any use before
992 m68k_ip_begin() will crash. */
993 static struct hash_control *op_hash;
995 /* Assemble an m68k instruction. */
1002 register struct m68k_op *opP;
1003 register const struct m68k_incant *opcode;
1004 register const char *s;
1005 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1006 char *pdot, *pdotmove;
1007 enum m68k_size siz1, siz2;
1011 LITTLENUM_TYPE words[6];
1012 LITTLENUM_TYPE *wordp;
1013 unsigned long ok_arch = 0;
1015 if (*instring == ' ')
1016 instring++; /* skip leading whitespace */
1018 /* Scan up to end of operation-code, which MUST end in end-of-string
1019 or exactly 1 space. */
1021 for (p = instring; *p != '\0'; p++)
1031 the_ins.error = _("No operator");
1035 /* p now points to the end of the opcode name, probably whitespace.
1036 Make sure the name is null terminated by clobbering the
1037 whitespace, look it up in the hash table, then fix it back.
1038 Remove a dot, first, since the opcode tables have none. */
1041 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1042 *pdotmove = pdotmove[1];
1048 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1053 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1054 *pdotmove = pdotmove[-1];
1061 the_ins.error = _("Unknown operator");
1065 /* found a legitimate opcode, start matching operands */
1069 if (opcode->m_operands == 0)
1071 char *old = input_line_pointer;
1073 input_line_pointer = p;
1074 /* Ahh - it's a motorola style psuedo op */
1075 mote_pseudo_table[opcode->m_opnum].poc_handler
1076 (mote_pseudo_table[opcode->m_opnum].poc_val);
1077 input_line_pointer = old;
1083 if (flag_mri && opcode->m_opnum == 0)
1085 /* In MRI mode, random garbage is allowed after an instruction
1086 which accepts no operands. */
1087 the_ins.args = opcode->m_operands;
1088 the_ins.numargs = opcode->m_opnum;
1089 the_ins.numo = opcode->m_codenum;
1090 the_ins.opcode[0] = getone (opcode);
1091 the_ins.opcode[1] = gettwo (opcode);
1095 for (opP = &the_ins.operands[0]; *p; opP++)
1097 p = crack_operand (p, opP);
1101 the_ins.error = opP->error;
1106 opsfound = opP - &the_ins.operands[0];
1108 /* This ugly hack is to support the floating pt opcodes in their
1109 standard form. Essentially, we fake a first enty of type COP#1 */
1110 if (opcode->m_operands[0] == 'I')
1114 for (n = opsfound; n > 0; --n)
1115 the_ins.operands[n] = the_ins.operands[n - 1];
1117 memset ((char *) (&the_ins.operands[0]), '\0',
1118 sizeof (the_ins.operands[0]));
1119 the_ins.operands[0].mode = CONTROL;
1120 the_ins.operands[0].reg = m68k_float_copnum;
1124 /* We've got the operands. Find an opcode that'll accept them */
1127 /* If we didn't get the right number of ops, or we have no
1128 common model with this pattern then reject this pattern. */
1130 ok_arch |= opcode->m_arch;
1131 if (opsfound != opcode->m_opnum
1132 || ((opcode->m_arch & current_architecture) == 0))
1136 for (s = opcode->m_operands, opP = &the_ins.operands[0];
1140 /* Warning: this switch is huge! */
1141 /* I've tried to organize the cases into this order:
1142 non-alpha first, then alpha by letter. Lower-case
1143 goes directly before uppercase counterpart. */
1144 /* Code with multiple case ...: gets sorted by the lowest
1145 case ... it belongs to. I hope this makes sense. */
1251 if (opP->reg == PC || opP->reg == ZPC)
1268 if (opP->reg == PC || opP->reg == ZPC)
1287 if (opP->reg == PC || opP->reg == ZPC)
1297 if (opP->mode != IMMED)
1299 else if (s[1] == 'b'
1300 && ! isvar (&opP->disp)
1301 && (opP->disp.exp.X_op != O_constant
1302 || ! isbyte (opP->disp.exp.X_add_number)))
1304 else if (s[1] == 'B'
1305 && ! isvar (&opP->disp)
1306 && (opP->disp.exp.X_op != O_constant
1307 || ! issbyte (opP->disp.exp.X_add_number)))
1309 else if (s[1] == 'w'
1310 && ! isvar (&opP->disp)
1311 && (opP->disp.exp.X_op != O_constant
1312 || ! isword (opP->disp.exp.X_add_number)))
1314 else if (s[1] == 'W'
1315 && ! isvar (&opP->disp)
1316 && (opP->disp.exp.X_op != O_constant
1317 || ! issword (opP->disp.exp.X_add_number)))
1323 if (opP->mode != IMMED)
1328 if (opP->mode == AREG
1329 || opP->mode == CONTROL
1330 || opP->mode == FPREG
1331 || opP->mode == IMMED
1332 || opP->mode == REGLST
1333 || (opP->mode != ABSL
1335 || opP->reg == ZPC)))
1340 if (opP->mode == CONTROL
1341 || opP->mode == FPREG
1342 || opP->mode == REGLST
1343 || opP->mode == IMMED
1344 || (opP->mode != ABSL
1346 || opP->reg == ZPC)))
1374 if (opP->mode == CONTROL
1375 || opP->mode == FPREG
1376 || opP->mode == REGLST)
1381 if (opP->mode != AINC)
1386 if (opP->mode != ADEC)
1436 if (opP->reg == PC || opP->reg == ZPC)
1457 case '~': /* For now! (JF FOO is this right?) */
1479 if (opP->mode != CONTROL
1480 || (opP->reg != TT0 && opP->reg != TT1))
1485 if (opP->mode != AREG)
1490 if (opP->mode != AINDR)
1495 if (opP->mode != ABSL
1497 && strncmp (instring, "jbsr", 4) == 0))
1502 if (opP->mode != CONTROL || opP->reg != CCR)
1507 if (opP->mode != DISP
1509 || opP->reg > ADDR7)
1514 if (opP->mode != DREG)
1519 if (opP->reg != ACC)
1524 if (opP->mode != FPREG)
1529 if (opP->reg != MACSR)
1534 if (opP->reg != MASK)
1539 if (opP->mode != CONTROL
1546 if (opP->mode != CONTROL
1548 || opP->reg > last_movec_reg)
1552 const enum m68k_register *rp;
1553 for (rp = control_regs; *rp; rp++)
1554 if (*rp == opP->reg)
1562 if (opP->mode != IMMED)
1568 if (opP->mode == DREG
1569 || opP->mode == AREG
1570 || opP->mode == FPREG)
1579 opP->mask = 1 << (opP->reg - DATA0);
1582 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1585 opP->mask = 1 << (opP->reg - FP0 + 16);
1593 else if (opP->mode == CONTROL)
1602 opP->mask = 1 << 24;
1605 opP->mask = 1 << 25;
1608 opP->mask = 1 << 26;
1617 else if (opP->mode != REGLST)
1619 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1621 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1626 if (opP->mode != IMMED)
1628 else if (opP->disp.exp.X_op != O_constant
1629 || ! issbyte (opP->disp.exp.X_add_number))
1631 else if (! m68k_quick
1632 && instring[3] != 'q'
1633 && instring[4] != 'q')
1638 if (opP->mode != DREG
1639 && opP->mode != IMMED
1640 && opP->mode != ABSL)
1645 if (opP->mode != IMMED)
1647 else if (opP->disp.exp.X_op != O_constant
1648 || opP->disp.exp.X_add_number < 1
1649 || opP->disp.exp.X_add_number > 8)
1651 else if (! m68k_quick
1652 && (strncmp (instring, "add", 3) == 0
1653 || strncmp (instring, "sub", 3) == 0)
1654 && instring[3] != 'q')
1659 if (opP->mode != DREG && opP->mode != AREG)
1664 if (opP->mode != AINDR
1665 && (opP->mode != BASE
1667 && opP->reg != ZADDR0)
1668 || opP->disp.exp.X_op != O_absent
1669 || ((opP->index.reg < DATA0
1670 || opP->index.reg > DATA7)
1671 && (opP->index.reg < ADDR0
1672 || opP->index.reg > ADDR7))
1673 || opP->index.size != SIZE_UNSPEC
1674 || opP->index.scale != 1))
1679 if (opP->mode != CONTROL
1680 || ! (opP->reg == FPI
1682 || opP->reg == FPC))
1687 if (opP->mode != CONTROL || opP->reg != SR)
1692 if (opP->mode != IMMED)
1694 else if (opP->disp.exp.X_op != O_constant
1695 || opP->disp.exp.X_add_number < 0
1696 || opP->disp.exp.X_add_number > 7)
1701 if (opP->mode != CONTROL || opP->reg != USP)
1705 /* JF these are out of order. We could put them
1706 in order if we were willing to put up with
1707 bunches of #ifdef m68851s in the code.
1709 Don't forget that you need these operands
1710 to use 68030 MMU instructions. */
1712 /* Memory addressing mode used by pflushr */
1714 if (opP->mode == CONTROL
1715 || opP->mode == FPREG
1716 || opP->mode == DREG
1717 || opP->mode == AREG
1718 || opP->mode == REGLST)
1720 /* We should accept immediate operands, but they
1721 supposedly have to be quad word, and we don't
1722 handle that. I would like to see what a Motorola
1723 assembler does before doing something here. */
1724 if (opP->mode == IMMED)
1729 if (opP->mode != CONTROL
1730 || (opP->reg != SFC && opP->reg != DFC))
1735 if (opP->mode != CONTROL || opP->reg != TC)
1740 if (opP->mode != CONTROL || opP->reg != AC)
1745 if (opP->mode != CONTROL
1748 && opP->reg != SCC))
1753 if (opP->mode != CONTROL
1759 if (opP->mode != CONTROL
1762 && opP->reg != CRP))
1767 if (opP->mode != CONTROL
1768 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1769 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1774 if (opP->mode != CONTROL || opP->reg != PSR)
1779 if (opP->mode != CONTROL || opP->reg != PCSR)
1784 if (opP->mode != CONTROL
1791 } /* not a cache specifier. */
1795 if (opP->mode != ABSL)
1800 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1802 /* FIXME: kludge instead of fixing parser:
1803 upper/lower registers are *not* CONTROL
1804 registers, but ordinary ones. */
1805 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1806 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1814 } /* switch on type of operand */
1818 } /* for each operand */
1819 } /* if immediately wrong */
1826 opcode = opcode->m_next;
1831 && !(ok_arch & current_architecture))
1836 _("invalid instruction for this architecture; needs "));
1837 cp = buf + strlen (buf);
1841 strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
1844 strcpy (cp, _("mmu (68030 or 68851)"));
1847 strcpy (cp, _("68020 or higher"));
1850 strcpy (cp, _("68000 or higher"));
1853 strcpy (cp, _("68010 or higher"));
1857 int got_one = 0, idx;
1859 idx < (int) (sizeof (archs) / sizeof (archs[0]));
1862 if ((archs[idx].arch & ok_arch)
1863 && ! archs[idx].alias)
1867 strcpy (cp, " or ");
1871 strcpy (cp, archs[idx].name);
1877 cp = xmalloc (strlen (buf) + 1);
1882 the_ins.error = _("operands mismatch");
1884 } /* Fell off the end */
1889 /* now assemble it */
1891 the_ins.args = opcode->m_operands;
1892 the_ins.numargs = opcode->m_opnum;
1893 the_ins.numo = opcode->m_codenum;
1894 the_ins.opcode[0] = getone (opcode);
1895 the_ins.opcode[1] = gettwo (opcode);
1897 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
1899 /* This switch is a doozy.
1900 Watch the first step; its a big one! */
1928 tmpreg = 0x3c; /* 7.4 */
1929 if (strchr ("bwl", s[1]))
1930 nextword = get_num (&opP->disp, 80);
1932 nextword = get_num (&opP->disp, 0);
1933 if (isvar (&opP->disp))
1934 add_fix (s[1], &opP->disp, 0, 0);
1938 if (!isbyte (nextword))
1939 opP->error = _("operand out of range");
1944 if (!isword (nextword))
1945 opP->error = _("operand out of range");
1950 if (!issword (nextword))
1951 opP->error = _("operand out of range");
1956 addword (nextword >> 16);
1983 /* We gotta put out some float */
1984 if (op (&opP->disp) != O_big)
1989 /* Can other cases happen here? */
1990 if (op (&opP->disp) != O_constant)
1993 val = (valueT) offs (&opP->disp);
1997 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
1998 val >>= LITTLENUM_NUMBER_OF_BITS;
2002 offs (&opP->disp) = gencnt;
2004 if (offs (&opP->disp) > 0)
2006 if (offs (&opP->disp) > baseo)
2008 as_warn (_("Bignum too big for %c format; truncated"),
2010 offs (&opP->disp) = baseo;
2012 baseo -= offs (&opP->disp);
2015 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2016 offs (&opP->disp)--;
2021 gen_to_words (words, baseo, (long) outro);
2022 for (wordp = words; baseo--; wordp++)
2026 tmpreg = opP->reg - DATA; /* 0.dreg */
2029 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2032 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2035 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2038 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2042 nextword = get_num (&opP->disp, 80);
2045 && ! isvar (&opP->disp)
2048 opP->disp.exp.X_op = O_symbol;
2049 #ifndef BFD_ASSEMBLER
2050 opP->disp.exp.X_add_symbol = &abs_symbol;
2052 opP->disp.exp.X_add_symbol =
2053 section_symbol (absolute_section);
2057 /* Force into index mode. Hope this works */
2059 /* We do the first bit for 32-bit displacements, and the
2060 second bit for 16 bit ones. It is possible that we
2061 should make the default be WORD instead of LONG, but
2062 I think that'd break GCC, so we put up with a little
2063 inefficiency for the sake of working output. */
2065 if (!issword (nextword)
2066 || (isvar (&opP->disp)
2067 && ((opP->disp.size == SIZE_UNSPEC
2068 && flag_short_refs == 0
2069 && cpu_of_arch (current_architecture) >= m68020
2070 && ! arch_coldfire_p (current_architecture))
2071 || opP->disp.size == SIZE_LONG)))
2073 if (cpu_of_arch (current_architecture) < m68020
2074 || arch_coldfire_p (current_architecture))
2076 _("displacement too large for this architecture; needs 68020 or higher");
2078 tmpreg = 0x3B; /* 7.3 */
2080 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2081 if (isvar (&opP->disp))
2085 if (opP->disp.size == SIZE_LONG
2087 /* If the displacement needs pic
2088 relocation it cannot be relaxed. */
2089 || opP->disp.pic_reloc != pic_none
2094 add_fix ('l', &opP->disp, 1, 2);
2098 add_frag (adds (&opP->disp),
2100 TAB (PCREL1632, SZ_UNDEF));
2107 add_fix ('l', &opP->disp, 0, 0);
2112 addword (nextword >> 16);
2117 tmpreg = 0x3A; /* 7.2 */
2119 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2121 if (isvar (&opP->disp))
2125 add_fix ('w', &opP->disp, 1, 0);
2128 add_fix ('w', &opP->disp, 0, 0);
2138 baseo = get_num (&opP->disp, 80);
2139 if (opP->mode == POST || opP->mode == PRE)
2140 outro = get_num (&opP->odisp, 80);
2141 /* Figure out the `addressing mode'.
2142 Also turn on the BASE_DISABLE bit, if needed. */
2143 if (opP->reg == PC || opP->reg == ZPC)
2145 tmpreg = 0x3b; /* 7.3 */
2146 if (opP->reg == ZPC)
2149 else if (opP->reg == 0)
2152 tmpreg = 0x30; /* 6.garbage */
2154 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2157 tmpreg = 0x30 + opP->reg - ZADDR0;
2160 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2162 siz1 = opP->disp.size;
2163 if (opP->mode == POST || opP->mode == PRE)
2164 siz2 = opP->odisp.size;
2168 /* Index register stuff */
2169 if (opP->index.reg != 0
2170 && opP->index.reg >= DATA
2171 && opP->index.reg <= ADDR7)
2173 nextword |= (opP->index.reg - DATA) << 12;
2175 if (opP->index.size == SIZE_LONG
2176 || (opP->index.size == SIZE_UNSPEC
2177 && m68k_index_width_default == SIZE_LONG))
2180 if ((opP->index.scale != 1
2181 && cpu_of_arch (current_architecture) < m68020)
2182 || (opP->index.scale == 8
2183 && arch_coldfire_p (current_architecture)))
2186 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2189 if (arch_coldfire_p (current_architecture)
2190 && opP->index.size == SIZE_WORD)
2191 opP->error = _("invalid index size for coldfire");
2193 switch (opP->index.scale)
2210 GET US OUT OF HERE! */
2212 /* Must be INDEX, with an index register. Address
2213 register cannot be ZERO-PC, and either :b was
2214 forced, or we know it will fit. For a 68000 or
2215 68010, force this mode anyways, because the
2216 larger modes aren't supported. */
2217 if (opP->mode == BASE
2218 && ((opP->reg >= ADDR0
2219 && opP->reg <= ADDR7)
2222 if (siz1 == SIZE_BYTE
2223 || cpu_of_arch (current_architecture) < m68020
2224 || arch_coldfire_p (current_architecture)
2225 || (siz1 == SIZE_UNSPEC
2226 && ! isvar (&opP->disp)
2227 && issbyte (baseo)))
2229 nextword += baseo & 0xff;
2231 if (isvar (&opP->disp))
2233 /* Do a byte relocation. If it doesn't
2234 fit (possible on m68000) let the
2235 fixup processing complain later. */
2237 add_fix ('B', &opP->disp, 1, 1);
2239 add_fix ('B', &opP->disp, 0, 0);
2241 else if (siz1 != SIZE_BYTE)
2243 if (siz1 != SIZE_UNSPEC)
2244 as_warn (_("Forcing byte displacement"));
2245 if (! issbyte (baseo))
2246 opP->error = _("byte displacement out of range");
2251 else if (siz1 == SIZE_UNSPEC
2253 && isvar (&opP->disp)
2254 && subs (&opP->disp) == NULL
2256 /* If the displacement needs pic
2257 relocation it cannot be relaxed. */
2258 && opP->disp.pic_reloc == pic_none
2262 /* The code in md_convert_frag_1 needs to be
2263 able to adjust nextword. Call frag_grow
2264 to ensure that we have enough space in
2265 the frag obstack to make all the bytes
2268 nextword += baseo & 0xff;
2270 add_frag (adds (&opP->disp), offs (&opP->disp),
2271 TAB (PCINDEX, SZ_UNDEF));
2279 nextword |= 0x40; /* No index reg */
2280 if (opP->index.reg >= ZDATA0
2281 && opP->index.reg <= ZDATA7)
2282 nextword |= (opP->index.reg - ZDATA0) << 12;
2283 else if (opP->index.reg >= ZADDR0
2284 || opP->index.reg <= ZADDR7)
2285 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2288 /* It isn't simple. */
2290 if (cpu_of_arch (current_architecture) < m68020
2291 || arch_coldfire_p (current_architecture))
2293 _("invalid operand mode for this architecture; needs 68020 or higher");
2296 /* If the guy specified a width, we assume that it is
2297 wide enough. Maybe it isn't. If so, we lose. */
2301 if (isvar (&opP->disp)
2303 : ! issword (baseo))
2308 else if (! isvar (&opP->disp) && baseo == 0)
2317 as_warn (_(":b not permitted; defaulting to :w"));
2327 /* Figure out innner displacement stuff */
2328 if (opP->mode == POST || opP->mode == PRE)
2330 if (cpu_of_arch (current_architecture) & cpu32)
2331 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2335 if (isvar (&opP->odisp)
2337 : ! issword (outro))
2342 else if (! isvar (&opP->odisp) && outro == 0)
2351 as_warn (_(":b not permitted; defaulting to :w"));
2360 if (opP->mode == POST
2361 && (nextword & 0x40) == 0)
2366 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2368 if (opP->reg == PC || opP->reg == ZPC)
2369 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2371 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2373 if (siz1 == SIZE_LONG)
2374 addword (baseo >> 16);
2375 if (siz1 != SIZE_UNSPEC)
2378 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2379 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2380 if (siz2 == SIZE_LONG)
2381 addword (outro >> 16);
2382 if (siz2 != SIZE_UNSPEC)
2388 nextword = get_num (&opP->disp, 80);
2389 switch (opP->disp.size)
2394 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2396 tmpreg = 0x38; /* 7.0 */
2400 if (isvar (&opP->disp)
2401 && !subs (&opP->disp)
2402 && adds (&opP->disp)
2404 /* If the displacement needs pic relocation it
2405 cannot be relaxed. */
2406 && opP->disp.pic_reloc == pic_none
2409 && !strchr ("~%&$?", s[0]))
2411 tmpreg = 0x3A; /* 7.2 */
2412 add_frag (adds (&opP->disp),
2414 TAB (ABSTOPCREL, SZ_UNDEF));
2417 /* Fall through into long */
2419 if (isvar (&opP->disp))
2420 add_fix ('l', &opP->disp, 0, 0);
2422 tmpreg = 0x39;/* 7.1 mode */
2423 addword (nextword >> 16);
2428 as_bad (_("unsupported byte value; use a different suffix"));
2430 case SIZE_WORD: /* Word */
2431 if (isvar (&opP->disp))
2432 add_fix ('w', &opP->disp, 0, 0);
2434 tmpreg = 0x38;/* 7.0 mode */
2442 as_bad (_("unknown/incorrect operand"));
2445 install_gen_operand (s[1], tmpreg);
2451 { /* JF: I hate floating point! */
2466 tmpreg = get_num (&opP->disp, tmpreg);
2467 if (isvar (&opP->disp))
2468 add_fix (s[1], &opP->disp, 0, 0);
2471 case 'b': /* Danger: These do no check for
2472 certain types of overflow.
2474 if (!isbyte (tmpreg))
2475 opP->error = _("out of range");
2476 insop (tmpreg, opcode);
2477 if (isvar (&opP->disp))
2478 the_ins.reloc[the_ins.nrel - 1].n =
2479 (opcode->m_codenum) * 2 + 1;
2482 if (!issbyte (tmpreg))
2483 opP->error = _("out of range");
2484 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2485 if (isvar (&opP->disp))
2486 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2489 if (!isword (tmpreg))
2490 opP->error = _("out of range");
2491 insop (tmpreg, opcode);
2492 if (isvar (&opP->disp))
2493 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2496 if (!issword (tmpreg))
2497 opP->error = _("out of range");
2498 insop (tmpreg, opcode);
2499 if (isvar (&opP->disp))
2500 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2503 /* Because of the way insop works, we put these two out
2505 insop (tmpreg, opcode);
2506 insop (tmpreg >> 16, opcode);
2507 if (isvar (&opP->disp))
2508 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2515 install_operand (s[1], tmpreg);
2526 install_operand (s[1], opP->reg - ADDR);
2530 tmpreg = get_num (&opP->disp, 80);
2534 add_fix ('B', &opP->disp, 1, -1);
2537 add_fix ('w', &opP->disp, 1, 0);
2542 if (! HAVE_LONG_BRANCH (current_architecture))
2543 as_warn (_("Can't use long branches on 68000/68010/5200"));
2544 the_ins.opcode[0] |= 0xff;
2545 add_fix ('l', &opP->disp, 1, 0);
2550 if (subs (&opP->disp)) /* We can't relax it */
2554 /* If the displacement needs pic relocation it cannot be
2556 if (opP->disp.pic_reloc != pic_none)
2559 /* This could either be a symbol, or an absolute
2560 address. If it's an absolute address, turn it into
2561 an absolute jump right here and keep it out of the
2563 if (adds (&opP->disp) == 0)
2565 if (the_ins.opcode[0] == 0x6000) /* jbra */
2566 the_ins.opcode[0] = 0x4EF9;
2567 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2568 the_ins.opcode[0] = 0x4EB9;
2571 the_ins.opcode[0] ^= 0x0100;
2572 the_ins.opcode[0] |= 0x0006;
2575 add_fix ('l', &opP->disp, 0, 0);
2581 /* Now we know it's going into the relaxer. Now figure
2582 out which mode. We try in this order of preference:
2583 long branch, absolute jump, byte/word branches only. */
2584 if (HAVE_LONG_BRANCH (current_architecture))
2585 add_frag (adds (&opP->disp), offs (&opP->disp),
2586 TAB (BRANCHBWL, SZ_UNDEF));
2587 else if (! flag_keep_pcrel)
2589 if ((the_ins.opcode[0] == 0x6000)
2590 || (the_ins.opcode[0] == 0x6100))
2591 add_frag (adds (&opP->disp), offs (&opP->disp),
2592 TAB (BRABSJUNC, SZ_UNDEF));
2594 add_frag (adds (&opP->disp), offs (&opP->disp),
2595 TAB (BRABSJCOND, SZ_UNDEF));
2598 add_frag (adds (&opP->disp), offs (&opP->disp),
2599 TAB (BRANCHBW, SZ_UNDEF));
2602 if (isvar (&opP->disp))
2604 /* Check for DBcc instructions. We can relax them,
2605 but only if we have long branches and/or absolute
2607 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2608 && (HAVE_LONG_BRANCH (current_architecture)
2609 || (! flag_keep_pcrel)))
2611 if (HAVE_LONG_BRANCH (current_architecture))
2612 add_frag (adds (&opP->disp), offs (&opP->disp),
2613 TAB (DBCCLBR, SZ_UNDEF));
2615 add_frag (adds (&opP->disp), offs (&opP->disp),
2616 TAB (DBCCABSJ, SZ_UNDEF));
2619 add_fix ('w', &opP->disp, 1, 0);
2623 case 'C': /* Fixed size LONG coproc branches */
2624 add_fix ('l', &opP->disp, 1, 0);
2628 case 'c': /* Var size Coprocesssor branches */
2629 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
2631 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2632 add_fix ('l', &opP->disp, 1, 0);
2637 add_frag (adds (&opP->disp), offs (&opP->disp),
2638 TAB (FBRANCH, SZ_UNDEF));
2645 case 'C': /* Ignore it */
2648 case 'd': /* JF this is a kludge */
2649 install_operand ('s', opP->reg - ADDR);
2650 tmpreg = get_num (&opP->disp, 80);
2651 if (!issword (tmpreg))
2653 as_warn (_("Expression out of range, using 0"));
2660 install_operand (s[1], opP->reg - DATA);
2663 case 'E': /* Ignore it */
2667 install_operand (s[1], opP->reg - FP0);
2670 case 'G': /* Ignore it */
2675 tmpreg = opP->reg - COP0;
2676 install_operand (s[1], tmpreg);
2679 case 'J': /* JF foo */
2752 install_operand (s[1], tmpreg);
2756 tmpreg = get_num (&opP->disp, 55);
2757 install_operand (s[1], tmpreg & 0x7f);
2764 if (tmpreg & 0x7FF0000)
2765 as_bad (_("Floating point register in register list"));
2766 insop (reverse_16_bits (tmpreg), opcode);
2770 if (tmpreg & 0x700FFFF)
2771 as_bad (_("Wrong register in floating-point reglist"));
2772 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
2780 if (tmpreg & 0x7FF0000)
2781 as_bad (_("Floating point register in register list"));
2782 insop (tmpreg, opcode);
2784 else if (s[1] == '8')
2786 if (tmpreg & 0x0FFFFFF)
2787 as_bad (_("incorrect register in reglist"));
2788 install_operand (s[1], tmpreg >> 24);
2792 if (tmpreg & 0x700FFFF)
2793 as_bad (_("wrong register in floating-point reglist"));
2795 install_operand (s[1], tmpreg >> 16);
2800 install_operand (s[1], get_num (&opP->disp, 60));
2804 tmpreg = ((opP->mode == DREG)
2805 ? 0x20 + (int) (opP->reg - DATA)
2806 : (get_num (&opP->disp, 40) & 0x1F));
2807 install_operand (s[1], tmpreg);
2811 tmpreg = get_num (&opP->disp, 10);
2814 install_operand (s[1], tmpreg);
2818 /* This depends on the fact that ADDR registers are eight
2819 more than their corresponding DATA regs, so the result
2820 will have the ADDR_REG bit set */
2821 install_operand (s[1], opP->reg - DATA);
2825 if (opP->mode == AINDR)
2826 install_operand (s[1], opP->reg - DATA);
2828 install_operand (s[1], opP->index.reg - DATA);
2832 if (opP->reg == FPI)
2834 else if (opP->reg == FPS)
2836 else if (opP->reg == FPC)
2840 install_operand (s[1], tmpreg);
2843 case 'S': /* Ignore it */
2847 install_operand (s[1], get_num (&opP->disp, 30));
2850 case 'U': /* Ignore it */
2869 as_fatal (_("failed sanity check"));
2870 } /* switch on cache token */
2871 install_operand (s[1], tmpreg);
2874 /* JF: These are out of order, I fear. */
2887 install_operand (s[1], tmpreg);
2913 install_operand (s[1], tmpreg);
2917 if (opP->reg == VAL)
2936 install_operand (s[1], tmpreg);
2950 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2961 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2967 install_operand (s[1], tmpreg);
2970 know (opP->reg == PSR);
2973 know (opP->reg == PCSR);
2988 install_operand (s[1], tmpreg);
2991 tmpreg = get_num (&opP->disp, 20);
2992 install_operand (s[1], tmpreg);
2994 case '_': /* used only for move16 absolute 32-bit address */
2995 if (isvar (&opP->disp))
2996 add_fix ('l', &opP->disp, 0, 0);
2997 tmpreg = get_num (&opP->disp, 80);
2998 addword (tmpreg >> 16);
2999 addword (tmpreg & 0xFFFF);
3002 install_operand (s[1], opP->reg - DATA0L);
3003 opP->reg -= (DATA0L);
3004 opP->reg &= 0x0F; /* remove upper/lower bit */
3011 /* By the time whe get here (FINALLY) the_ins contains the complete
3012 instruction, ready to be emitted. . . */
3016 reverse_16_bits (in)
3022 static int mask[16] =
3024 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3025 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3027 for (n = 0; n < 16; n++)
3030 out |= mask[15 - n];
3033 } /* reverse_16_bits() */
3042 static int mask[8] =
3044 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3047 for (n = 0; n < 8; n++)
3053 } /* reverse_8_bits() */
3055 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3056 (that value is chosen in the frag_var call in md_assemble). TYPE
3057 is the subtype of the frag to be generated; its primary type is
3058 rs_machine_dependent.
3060 The TYPE parameter is also used by md_convert_frag_1 and
3061 md_estimate_size_before_relax. The appropriate type of fixup will
3062 be emitted by md_convert_frag_1.
3064 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3066 install_operand (mode, val)
3073 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge */
3076 the_ins.opcode[0] |= val << 9;
3079 the_ins.opcode[1] |= val << 12;
3082 the_ins.opcode[1] |= val << 6;
3085 the_ins.opcode[1] |= val;
3088 the_ins.opcode[2] |= val << 12;
3091 the_ins.opcode[2] |= val << 6;
3094 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3095 three words long! */
3097 the_ins.opcode[2] |= val;
3100 the_ins.opcode[1] |= val << 7;
3103 the_ins.opcode[1] |= val << 10;
3107 the_ins.opcode[1] |= val << 5;
3112 the_ins.opcode[1] |= (val << 10) | (val << 7);
3115 the_ins.opcode[1] |= (val << 12) | val;
3118 the_ins.opcode[0] |= val = 0xff;
3121 the_ins.opcode[0] |= val << 9;
3124 the_ins.opcode[1] |= val;
3127 the_ins.opcode[1] |= val;
3128 the_ins.numo++; /* What a hack */
3131 the_ins.opcode[1] |= val << 4;
3139 the_ins.opcode[0] |= (val << 6);
3142 the_ins.opcode[1] = (val >> 16);
3143 the_ins.opcode[2] = val & 0xffff;
3146 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3147 the_ins.opcode[0] |= ((val & 0x7) << 9);
3148 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3151 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3152 the_ins.opcode[0] |= ((val & 0x7) << 9);
3155 the_ins.opcode[1] |= val << 12;
3156 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3159 the_ins.opcode[0] |= (val & 0xF);
3160 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3163 the_ins.opcode[1] |= (val & 0xF);
3164 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3167 the_ins.opcode[1] |= ((val != 1) << 10);
3171 as_fatal (_("failed sanity check."));
3173 } /* install_operand() */
3176 install_gen_operand (mode, val)
3183 the_ins.opcode[0] |= val;
3186 /* This is a kludge!!! */
3187 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3196 the_ins.opcode[0] |= val;
3198 /* more stuff goes here */
3200 as_fatal (_("failed sanity check."));
3202 } /* install_gen_operand() */
3205 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3206 * then deal with the bitfield hack.
3210 crack_operand (str, opP)
3212 register struct m68k_op *opP;
3214 register int parens;
3216 register char *beg_str;
3224 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3230 else if (*str == ')')
3234 opP->error = _("Extra )");
3240 if (flag_mri && *str == '\'')
3241 inquote = ! inquote;
3243 if (!*str && parens)
3245 opP->error = _("Missing )");
3250 if (m68k_ip_op (beg_str, opP) != 0)
3257 c = *++str; /* JF bitfield hack */
3262 as_bad (_("Missing operand"));
3265 /* Detect MRI REG symbols and convert them to REGLSTs. */
3266 if (opP->mode == CONTROL && (int)opP->reg < 0)
3269 opP->mask = ~(int)opP->reg;
3276 /* This is the guts of the machine-dependent assembler. STR points to a
3277 machine dependent instruction. This function is supposed to emit
3278 the frags/bytes it assembles to.
3282 insert_reg (regname, regnum)
3283 const char *regname;
3289 #ifdef REGISTER_PREFIX
3290 if (!flag_reg_prefix_optional)
3292 buf[0] = REGISTER_PREFIX;
3293 strcpy (buf + 1, regname);
3298 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3299 &zero_address_frag));
3301 for (i = 0; regname[i]; i++)
3302 buf[i] = TOUPPER (regname[i]);
3305 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3306 &zero_address_frag));
3315 static const struct init_entry init_table[] =
3374 /* control registers */
3375 { "sfc", SFC }, /* Source Function Code */
3377 { "dfc", DFC }, /* Destination Function Code */
3379 { "cacr", CACR }, /* Cache Control Register */
3380 { "caar", CAAR }, /* Cache Address Register */
3382 { "usp", USP }, /* User Stack Pointer */
3383 { "vbr", VBR }, /* Vector Base Register */
3384 { "msp", MSP }, /* Master Stack Pointer */
3385 { "isp", ISP }, /* Interrupt Stack Pointer */
3387 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0 */
3388 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1 */
3389 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0 */
3390 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1 */
3392 /* 68ec040 versions of same */
3393 { "iacr0", ITT0 }, /* Instruction Access Control Register 0 */
3394 { "iacr1", ITT1 }, /* Instruction Access Control Register 0 */
3395 { "dacr0", DTT0 }, /* Data Access Control Register 0 */
3396 { "dacr1", DTT1 }, /* Data Access Control Register 0 */
3398 /* mcf5200 versions of same. The ColdFire programmer's reference
3399 manual indicated that the order is 2,3,0,1, but Ken Rose
3401 { "acr0", ITT0 }, /* Access Control Unit 0 */
3402 { "acr1", ITT1 }, /* Access Control Unit 1 */
3403 { "acr2", DTT0 }, /* Access Control Unit 2 */
3404 { "acr3", DTT1 }, /* Access Control Unit 3 */
3406 { "tc", TC }, /* MMU Translation Control Register */
3409 { "mmusr", MMUSR }, /* MMU Status Register */
3410 { "srp", SRP }, /* User Root Pointer */
3411 { "urp", URP }, /* Supervisor Root Pointer */
3416 { "rombar", ROMBAR }, /* ROM Base Address Register */
3417 { "rambar0", RAMBAR0 }, /* ROM Base Address Register */
3418 { "rambar1", RAMBAR1 }, /* ROM Base Address Register */
3419 { "mbar", MBAR }, /* Module Base Address Register */
3420 /* end of control registers */
3454 /* 68ec030 versions of same */
3457 /* 68ec030 access control unit, identical to 030 MMU status reg */
3460 /* Suppressed data and address registers. */
3478 /* Upper and lower data and address registers, used by macw and msacw. */
3522 for (i = 0; init_table[i].name; i++)
3523 insert_reg (init_table[i].name, init_table[i].number);
3526 static int no_68851, no_68881;
3529 /* a.out machine type. Default to 68020. */
3530 int m68k_aout_machtype = 2;
3542 int shorts_this_frag;
3545 /* In MRI mode, the instruction and operands are separated by a
3546 space. Anything following the operands is a comment. The label
3547 has already been removed. */
3555 for (s = str; *s != '\0'; s++)
3557 if ((*s == ' ' || *s == '\t') && ! inquote)
3575 inquote = ! inquote;
3580 memset ((char *) (&the_ins), '\0', sizeof (the_ins));
3585 for (n = 0; n < the_ins.numargs; n++)
3586 if (the_ins.operands[n].error)
3588 er = the_ins.operands[n].error;
3594 as_bad (_("%s -- statement `%s' ignored"), er, str);
3598 /* If there is a current label, record that it marks an instruction. */
3599 if (current_label != NULL)
3601 current_label->text = 1;
3602 current_label = NULL;
3606 /* Tie dwarf2 debug info to the address at the start of the insn. */
3607 dwarf2_emit_insn (0);
3610 if (the_ins.nfrag == 0)
3612 /* No frag hacking involved; just put it out */
3613 toP = frag_more (2 * the_ins.numo);
3614 fromP = &the_ins.opcode[0];
3615 for (m = the_ins.numo; m; --m)
3617 md_number_to_chars (toP, (long) (*fromP), 2);
3621 /* put out symbol-dependent info */
3622 for (m = 0; m < the_ins.nrel; m++)
3624 switch (the_ins.reloc[m].wid)
3643 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3644 the_ins.reloc[m].wid);
3647 fixP = fix_new_exp (frag_now,
3648 ((toP - frag_now->fr_literal)
3649 - the_ins.numo * 2 + the_ins.reloc[m].n),
3651 &the_ins.reloc[m].exp,
3652 the_ins.reloc[m].pcrel,
3653 get_reloc_code (n, the_ins.reloc[m].pcrel,
3654 the_ins.reloc[m].pic_reloc));
3655 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3656 if (the_ins.reloc[m].wid == 'B')
3657 fixP->fx_signed = 1;
3662 /* There's some frag hacking */
3664 /* Calculate the max frag size. */
3667 wid = 2 * the_ins.fragb[0].fragoff;
3668 for (n = 1; n < the_ins.nfrag; n++)
3669 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3670 /* frag_var part. */
3672 /* Make sure the whole insn fits in one chunk, in particular that
3673 the var part is attached, as we access one byte before the
3674 variable frag for byte branches. */
3678 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
3683 wid = 2 * the_ins.fragb[n].fragoff;
3685 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3686 toP = frag_more (wid);
3688 shorts_this_frag = 0;
3689 for (m = wid / 2; m; --m)
3691 md_number_to_chars (toP, (long) (*fromP), 2);
3696 for (m = 0; m < the_ins.nrel; m++)
3698 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
3700 the_ins.reloc[m].n -= 2 * shorts_this_frag;
3703 wid = the_ins.reloc[m].wid;
3706 the_ins.reloc[m].wid = 0;
3707 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3709 fixP = fix_new_exp (frag_now,
3710 ((toP - frag_now->fr_literal)
3711 - the_ins.numo * 2 + the_ins.reloc[m].n),
3713 &the_ins.reloc[m].exp,
3714 the_ins.reloc[m].pcrel,
3715 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3716 the_ins.reloc[m].pic_reloc));
3717 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3719 (void) frag_var (rs_machine_dependent, 10, 0,
3720 (relax_substateT) (the_ins.fragb[n].fragty),
3721 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
3723 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3724 shorts_this_frag = 0;
3727 toP = frag_more (n * sizeof (short));
3730 md_number_to_chars (toP, (long) (*fromP), 2);
3736 for (m = 0; m < the_ins.nrel; m++)
3740 wid = the_ins.reloc[m].wid;
3743 the_ins.reloc[m].wid = 0;
3744 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3746 fixP = fix_new_exp (frag_now,
3747 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
3748 - shorts_this_frag * 2),
3750 &the_ins.reloc[m].exp,
3751 the_ins.reloc[m].pcrel,
3752 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3753 the_ins.reloc[m].pic_reloc));
3754 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3762 * md_begin -- set up hash tables with 68000 instructions.
3763 * similar to what the vax assembler does. ---phr
3765 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3766 a copy of it at runtime, adding in the information we want but isn't
3767 there. I think it'd be better to have an awk script hack the table
3768 at compile time. Or even just xstr the table and use it as-is. But
3769 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3772 const struct m68k_opcode *ins;
3773 struct m68k_incant *hack, *slak;
3774 const char *retval = 0; /* empty string, or error msg text */
3779 flag_reg_prefix_optional = 1;
3781 if (! m68k_rel32_from_cmdline)
3785 op_hash = hash_new ();
3787 obstack_begin (&robyn, 4000);
3788 for (i = 0; i < m68k_numopcodes; i++)
3790 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3793 ins = &m68k_opcodes[i];
3794 /* We *could* ignore insns that don't match our arch here
3795 but just leaving them out of the hash. */
3796 slak->m_operands = ins->args;
3797 slak->m_opnum = strlen (slak->m_operands) / 2;
3798 slak->m_arch = ins->arch;
3799 slak->m_opcode = ins->opcode;
3800 /* This is kludgey */
3801 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
3802 if (i + 1 != m68k_numopcodes
3803 && !strcmp (ins->name, m68k_opcodes[i + 1].name))
3805 slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3810 slak = slak->m_next;
3814 retval = hash_insert (op_hash, ins->name, (char *) hack);
3816 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
3819 for (i = 0; i < m68k_numaliases; i++)
3821 const char *name = m68k_opcode_aliases[i].primary;
3822 const char *alias = m68k_opcode_aliases[i].alias;
3823 PTR val = hash_find (op_hash, name);
3825 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
3826 retval = hash_insert (op_hash, alias, val);
3828 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
3831 /* In MRI mode, all unsized branches are variable sized. Normally,
3832 they are word sized. */
3835 static struct m68k_opcode_alias mri_aliases[] =
3856 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
3859 const char *name = mri_aliases[i].primary;
3860 const char *alias = mri_aliases[i].alias;
3861 PTR val = hash_find (op_hash, name);
3863 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
3864 retval = hash_jam (op_hash, alias, val);
3866 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
3870 for (i = 0; i < (int) sizeof (notend_table); i++)
3872 notend_table[i] = 0;
3873 alt_notend_table[i] = 0;
3875 notend_table[','] = 1;
3876 notend_table['{'] = 1;
3877 notend_table['}'] = 1;
3878 alt_notend_table['a'] = 1;
3879 alt_notend_table['A'] = 1;
3880 alt_notend_table['d'] = 1;
3881 alt_notend_table['D'] = 1;
3882 alt_notend_table['#'] = 1;
3883 alt_notend_table['&'] = 1;
3884 alt_notend_table['f'] = 1;
3885 alt_notend_table['F'] = 1;
3886 #ifdef REGISTER_PREFIX
3887 alt_notend_table[REGISTER_PREFIX] = 1;
3890 /* We need to put '(' in alt_notend_table to handle
3891 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3893 alt_notend_table['('] = 1;
3895 /* We need to put '@' in alt_notend_table to handle
3896 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3898 alt_notend_table['@'] = 1;
3900 /* We need to put digits in alt_notend_table to handle
3901 bfextu %d0{24:1},%d0
3903 alt_notend_table['0'] = 1;
3904 alt_notend_table['1'] = 1;
3905 alt_notend_table['2'] = 1;
3906 alt_notend_table['3'] = 1;
3907 alt_notend_table['4'] = 1;
3908 alt_notend_table['5'] = 1;
3909 alt_notend_table['6'] = 1;
3910 alt_notend_table['7'] = 1;
3911 alt_notend_table['8'] = 1;
3912 alt_notend_table['9'] = 1;
3914 #ifndef MIT_SYNTAX_ONLY
3915 /* Insert pseudo ops, these have to go into the opcode table since
3916 gas expects pseudo ops to start with a dot */
3919 while (mote_pseudo_table[n].poc_name)
3921 hack = (struct m68k_incant *)
3922 obstack_alloc (&robyn, sizeof (struct m68k_incant));
3923 hash_insert (op_hash,
3924 mote_pseudo_table[n].poc_name, (char *) hack);
3925 hack->m_operands = 0;
3935 record_alignment (text_section, 2);
3936 record_alignment (data_section, 2);
3937 record_alignment (bss_section, 2);
3942 select_control_regs ()
3944 /* Note which set of "movec" control registers is available. */
3945 switch (cpu_of_arch (current_architecture))
3948 as_warn (_("architecture not yet selected: defaulting to 68020"));
3949 control_regs = m68020_control_regs;
3953 control_regs = m68000_control_regs;
3956 control_regs = m68010_control_regs;
3960 control_regs = m68020_control_regs;
3963 control_regs = m68040_control_regs;
3966 control_regs = m68060_control_regs;
3969 control_regs = cpu32_control_regs;
3975 control_regs = mcf_control_regs;
3983 m68k_init_after_args ()
3985 if (cpu_of_arch (current_architecture) == 0)
3988 const char *default_cpu = TARGET_CPU;
3990 if (*default_cpu == 'm')
3992 for (i = 0; i < n_archs; i++)
3993 if (strcasecmp (default_cpu, archs[i].name) == 0)
3997 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU);
3998 current_architecture |= m68020;
4001 current_architecture |= archs[i].arch;
4003 /* Permit m68881 specification with all cpus; those that can't work
4004 with a coprocessor could be doing emulation. */
4005 if (current_architecture & m68851)
4007 if (current_architecture & m68040)
4009 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4012 /* What other incompatibilities could we check for? */
4014 /* Toss in some default assumptions about coprocessors. */
4016 && (cpu_of_arch (current_architecture)
4017 /* Can CPU32 have a 68881 coprocessor?? */
4018 & (m68020 | m68030 | cpu32)))
4020 current_architecture |= m68881;
4023 && (cpu_of_arch (current_architecture) & m68020up) != 0
4024 && (cpu_of_arch (current_architecture) & m68040up) == 0)
4026 current_architecture |= m68851;
4028 if (no_68881 && (current_architecture & m68881))
4029 as_bad (_("options for 68881 and no-68881 both given"));
4030 if (no_68851 && (current_architecture & m68851))
4031 as_bad (_("options for 68851 and no-68851 both given"));
4034 /* Work out the magic number. This isn't very general. */
4035 if (current_architecture & m68000)
4036 m68k_aout_machtype = 0;
4037 else if (current_architecture & m68010)
4038 m68k_aout_machtype = 1;
4039 else if (current_architecture & m68020)
4040 m68k_aout_machtype = 2;
4042 m68k_aout_machtype = 2;
4045 /* Note which set of "movec" control registers is available. */
4046 select_control_regs ();
4048 if (cpu_of_arch (current_architecture) < m68020
4049 || arch_coldfire_p (current_architecture))
4050 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
4053 /* This is called when a label is defined. */
4056 m68k_frob_label (sym)
4059 struct label_line *n;
4061 n = (struct label_line *) xmalloc (sizeof *n);
4064 as_where (&n->file, &n->line);
4070 /* This is called when a value that is not an instruction is emitted. */
4073 m68k_flush_pending_output ()
4075 current_label = NULL;
4078 /* This is called at the end of the assembly, when the final value of
4079 the label is known. We warn if this is a text symbol aligned at an
4083 m68k_frob_symbol (sym)
4086 if (S_GET_SEGMENT (sym) == reg_section
4087 && (int) S_GET_VALUE (sym) < 0)
4089 S_SET_SEGMENT (sym, absolute_section);
4090 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4092 else if ((S_GET_VALUE (sym) & 1) != 0)
4094 struct label_line *l;
4096 for (l = labels; l != NULL; l = l->next)
4098 if (l->label == sym)
4101 as_warn_where (l->file, l->line,
4102 _("text label `%s' aligned to odd boundary"),
4110 /* This is called if we go in or out of MRI mode because of the .mri
4114 m68k_mri_mode_change (on)
4119 if (! flag_reg_prefix_optional)
4121 flag_reg_prefix_optional = 1;
4122 #ifdef REGISTER_PREFIX
4127 if (! m68k_rel32_from_cmdline)
4132 if (! reg_prefix_optional_seen)
4134 #ifdef REGISTER_PREFIX_OPTIONAL
4135 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4137 flag_reg_prefix_optional = 0;
4139 #ifdef REGISTER_PREFIX
4144 if (! m68k_rel32_from_cmdline)
4149 /* Equal to MAX_PRECISION in atof-ieee.c */
4150 #define MAX_LITTLENUMS 6
4152 /* Turn a string in input_line_pointer into a floating point constant
4153 of type TYPE, and store the appropriate bytes in *LITP. The number
4154 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4155 returned, or NULL on OK. */
4158 md_atof (type, litP, sizeP)
4164 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4165 LITTLENUM_TYPE *wordP;
4196 return _("Bad call to MD_ATOF()");
4198 t = atof_ieee (input_line_pointer, type, words);
4200 input_line_pointer = t;
4202 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4203 for (wordP = words; prec--;)
4205 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4206 litP += sizeof (LITTLENUM_TYPE);
4212 md_number_to_chars (buf, val, n)
4217 number_to_chars_bigendian (buf, val, n);
4221 md_apply_fix3 (fixP, valP, seg)
4224 segT seg ATTRIBUTE_UNUSED;
4226 offsetT val = *valP;
4227 addressT upper_limit;
4228 offsetT lower_limit;
4230 /* This is unnecessary but it convinces the native rs6000 compiler
4231 to generate the code we want. */
4232 char *buf = fixP->fx_frag->fr_literal;
4233 buf += fixP->fx_where;
4234 /* end ibm compiler workaround */
4236 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
4238 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
4244 memset (buf, 0, fixP->fx_size);
4245 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
4247 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4248 && !S_IS_DEFINED (fixP->fx_addsy)
4249 && !S_IS_WEAK (fixP->fx_addsy))
4250 S_SET_WEAK (fixP->fx_addsy);
4255 #ifdef BFD_ASSEMBLER
4256 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4257 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4261 switch (fixP->fx_size)
4263 /* The cast to offsetT below are necessary to make code
4264 correct for machines where ints are smaller than offsetT. */
4268 lower_limit = - (offsetT) 0x80;
4271 *buf++ = (val >> 8);
4273 upper_limit = 0x7fff;
4274 lower_limit = - (offsetT) 0x8000;
4277 *buf++ = (val >> 24);
4278 *buf++ = (val >> 16);
4279 *buf++ = (val >> 8);
4281 upper_limit = 0x7fffffff;
4282 lower_limit = - (offsetT) 0x7fffffff - 1; /* avoid constant overflow */
4285 BAD_CASE (fixP->fx_size);
4288 /* Fix up a negative reloc. */
4289 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4291 fixP->fx_addsy = fixP->fx_subsy;
4292 fixP->fx_subsy = NULL;
4296 /* For non-pc-relative values, it's conceivable we might get something
4297 like "0xff" for a byte field. So extend the upper part of the range
4298 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4299 so that we can do any range checking at all. */
4300 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4301 upper_limit = upper_limit * 2 + 1;
4303 if ((addressT) val > upper_limit
4304 && (val > 0 || val < lower_limit))
4305 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4307 /* A one byte PC-relative reloc means a short branch. We can't use
4308 a short branch with a value of 0 or -1, because those indicate
4309 different opcodes (branches with longer offsets). fixup_segment
4310 in write.c may have clobbered fx_pcrel, so we need to examine the
4313 #ifdef BFD_ASSEMBLER
4314 || fixP->fx_r_type == BFD_RELOC_8_PCREL
4317 && fixP->fx_size == 1
4318 && (fixP->fx_addsy == NULL
4319 || S_IS_DEFINED (fixP->fx_addsy))
4320 && (val == 0 || val == -1))
4321 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4324 /* *fragP has been relaxed to its final size, and now needs to have
4325 the bytes inside it modified to conform to the new size There is UGLY
4329 md_convert_frag_1 (fragP)
4330 register fragS *fragP;
4335 /* Address in object code of the displacement. */
4336 register int object_address = fragP->fr_fix + fragP->fr_address;
4338 /* Address in gas core of the place to store the displacement. */
4339 /* This convinces the native rs6000 compiler to generate the code we
4341 register char *buffer_address = fragP->fr_literal;
4342 buffer_address += fragP->fr_fix;
4343 /* end ibm compiler workaround */
4345 /* The displacement of the address, from current location. */
4346 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4347 disp = (disp + fragP->fr_offset) - object_address;
4349 switch (fragP->fr_subtype)
4351 case TAB (BRANCHBWL, BYTE):
4352 case TAB (BRABSJUNC, BYTE):
4353 case TAB (BRABSJCOND, BYTE):
4354 case TAB (BRANCHBW, BYTE):
4355 know (issbyte (disp));
4357 as_bad_where (fragP->fr_file, fragP->fr_line,
4358 _("short branch with zero offset: use :w"));
4359 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4360 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4361 fixP->fx_pcrel_adjust = -1;
4363 case TAB (BRANCHBWL, SHORT):
4364 case TAB (BRABSJUNC, SHORT):
4365 case TAB (BRABSJCOND, SHORT):
4366 case TAB (BRANCHBW, SHORT):
4367 fragP->fr_opcode[1] = 0x00;
4368 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4369 1, RELAX_RELOC_PC16);
4372 case TAB (BRANCHBWL, LONG):
4373 fragP->fr_opcode[1] = (char) 0xFF;
4374 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4375 1, RELAX_RELOC_PC32);
4378 case TAB (BRABSJUNC, LONG):
4379 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4381 fragP->fr_opcode[0] = 0x4E;
4382 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand */
4383 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4384 0, RELAX_RELOC_ABS32);
4387 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4389 fragP->fr_opcode[0] = 0x4E;
4390 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand */
4391 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4392 0, RELAX_RELOC_ABS32);
4397 /* This cannot happen, because jbsr and jbra are the only two
4398 unconditional branches. */
4402 case TAB (BRABSJCOND, LONG):
4403 /* Only Bcc 68000 instructions can come here. */
4404 /* Change bcc into b!cc/jmp absl long. */
4406 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
4407 fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
4409 /* JF: these used to be fr_opcode[2,3], but they may be in a
4410 different frag, in which case refering to them is a no-no.
4411 Only fr_opcode[0,1] are guaranteed to work. */
4412 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4413 *buffer_address++ = (char) 0xf9;
4414 fragP->fr_fix += 2; /* account for jmp instruction */
4415 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4416 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4419 case TAB (FBRANCH, SHORT):
4420 know ((fragP->fr_opcode[1] & 0x40) == 0);
4421 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4422 1, RELAX_RELOC_PC16);
4425 case TAB (FBRANCH, LONG):
4426 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
4427 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4428 1, RELAX_RELOC_PC32);
4431 case TAB (DBCCLBR, SHORT):
4432 case TAB (DBCCABSJ, SHORT):
4433 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4434 1, RELAX_RELOC_PC16);
4437 case TAB (DBCCLBR, LONG):
4438 /* only DBcc instructions can come here */
4439 /* Change dbcc into dbcc/bral. */
4441 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4442 *buffer_address++ = 0x00; /* branch offset = 4 */
4443 *buffer_address++ = 0x04;
4444 *buffer_address++ = 0x60; /* put in bra pc+6 */
4445 *buffer_address++ = 0x06;
4446 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4447 *buffer_address++ = (char) 0xff;
4449 fragP->fr_fix += 6; /* account for bra/jmp instructions */
4450 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4454 case TAB (DBCCABSJ, LONG):
4455 /* only DBcc instructions can come here */
4456 /* Change dbcc into dbcc/jmp. */
4458 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4459 *buffer_address++ = 0x00; /* branch offset = 4 */
4460 *buffer_address++ = 0x04;
4461 *buffer_address++ = 0x60; /* put in bra pc+6 */
4462 *buffer_address++ = 0x06;
4463 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4464 *buffer_address++ = (char) 0xf9;
4466 fragP->fr_fix += 6; /* account for bra/jmp instructions */
4467 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4471 case TAB (PCREL1632, SHORT):
4472 fragP->fr_opcode[1] &= ~0x3F;
4473 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4474 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4475 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4478 case TAB (PCREL1632, LONG):
4479 /* Already set to mode 7.3; this indicates: PC indirect with
4480 suppressed index, 32-bit displacement. */
4481 *buffer_address++ = 0x01;
4482 *buffer_address++ = 0x70;
4484 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4485 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4486 fixP->fx_pcrel_adjust = 2;
4489 case TAB (PCINDEX, BYTE):
4490 assert (fragP->fr_fix >= 2);
4491 buffer_address[-2] &= ~1;
4492 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4493 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4494 fixP->fx_pcrel_adjust = 1;
4496 case TAB (PCINDEX, SHORT):
4497 assert (fragP->fr_fix >= 2);
4498 buffer_address[-2] |= 0x1;
4499 buffer_address[-1] = 0x20;
4500 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4501 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4502 fixP->fx_pcrel_adjust = 2;
4505 case TAB (PCINDEX, LONG):
4506 assert (fragP->fr_fix >= 2);
4507 buffer_address[-2] |= 0x1;
4508 buffer_address[-1] = 0x30;
4509 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4510 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4511 fixP->fx_pcrel_adjust = 2;
4514 case TAB (ABSTOPCREL, SHORT):
4515 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4516 1, RELAX_RELOC_PC16);
4519 case TAB (ABSTOPCREL, LONG):
4520 /* The thing to do here is force it to ABSOLUTE LONG, since
4521 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway */
4522 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4524 fragP->fr_opcode[1] &= ~0x3F;
4525 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4526 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4527 0, RELAX_RELOC_ABS32);
4533 #ifndef BFD_ASSEMBLER
4536 md_convert_frag (headers, sec, fragP)
4537 object_headers *headers ATTRIBUTE_UNUSED;
4538 segT sec ATTRIBUTE_UNUSED;
4541 md_convert_frag_1 (fragP);
4547 md_convert_frag (abfd, sec, fragP)
4548 bfd *abfd ATTRIBUTE_UNUSED;
4549 segT sec ATTRIBUTE_UNUSED;
4552 md_convert_frag_1 (fragP);
4556 /* Force truly undefined symbols to their maximum size, and generally set up
4557 the frag list to be relaxed
4560 md_estimate_size_before_relax (fragP, segment)
4561 register fragS *fragP;
4564 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4565 switch (fragP->fr_subtype)
4567 case TAB (BRANCHBWL, SZ_UNDEF):
4568 case TAB (BRABSJUNC, SZ_UNDEF):
4569 case TAB (BRABSJCOND, SZ_UNDEF):
4571 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4572 && relaxable_symbol (fragP->fr_symbol))
4574 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4576 else if (flag_short_refs)
4578 /* Symbol is undefined and we want short ref. */
4579 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4583 /* Symbol is still undefined. Make it LONG. */
4584 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4589 case TAB (BRANCHBW, SZ_UNDEF):
4591 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4592 && relaxable_symbol (fragP->fr_symbol))
4594 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4598 /* Symbol is undefined and we don't have long branches. */
4599 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4604 case TAB (FBRANCH, SZ_UNDEF):
4605 case TAB (DBCCLBR, SZ_UNDEF):
4606 case TAB (DBCCABSJ, SZ_UNDEF):
4607 case TAB (PCREL1632, SZ_UNDEF):
4609 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4610 && relaxable_symbol (fragP->fr_symbol))
4613 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4617 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4622 case TAB (PCINDEX, SZ_UNDEF):
4623 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4624 && relaxable_symbol (fragP->fr_symbol)))
4626 fragP->fr_subtype = TAB (PCINDEX, BYTE);
4630 fragP->fr_subtype = TAB (PCINDEX, LONG);
4634 case TAB (ABSTOPCREL, SZ_UNDEF):
4636 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4637 && relaxable_symbol (fragP->fr_symbol)))
4639 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
4643 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
4652 /* Now that SZ_UNDEF are taken care of, check others. */
4653 switch (fragP->fr_subtype)
4655 case TAB (BRANCHBWL, BYTE):
4656 case TAB (BRABSJUNC, BYTE):
4657 case TAB (BRABSJCOND, BYTE):
4658 case TAB (BRANCHBW, BYTE):
4659 /* We can't do a short jump to the next instruction, so in that
4660 case we force word mode. If the symbol is at the start of a
4661 frag, and it is the next frag with any data in it (usually
4662 this is just the next frag, but assembler listings may
4663 introduce empty frags), we must use word mode. */
4664 if (fragP->fr_symbol)
4668 sym_frag = symbol_get_frag (fragP->fr_symbol);
4669 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
4673 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
4677 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4684 return md_relax_table[fragP->fr_subtype].rlx_length;
4687 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4688 /* the bit-field entries in the relocation_info struct plays hell
4689 with the byte-order problems of cross-assembly. So as a hack,
4690 I added this mach. dependent ri twiddler. Ugly, but it gets
4692 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4693 are symbolnum, most sig. byte first. Last byte is broken up with
4694 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4695 nibble as nuthin. (on Sun 3 at least) */
4696 /* Translate the internal relocation information into target-specific
4700 md_ri_to_chars (the_bytes, ri)
4702 struct reloc_info_generic *ri;
4705 md_number_to_chars (the_bytes, ri->r_address, 4);
4706 /* now the fun stuff */
4707 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
4708 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
4709 the_bytes[6] = ri->r_symbolnum & 0x0ff;
4710 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
4711 ((ri->r_extern << 4) & 0x10));
4714 #endif /* comment */
4716 #ifndef BFD_ASSEMBLER
4718 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
4721 relax_addressT segment_address_in_file;
4724 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4725 * Out: GNU LD relocation length code: 0, 1, or 2.
4728 static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
4731 know (fixP->fx_addsy != NULL);
4733 md_number_to_chars (where,
4734 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
4737 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
4738 ? S_GET_TYPE (fixP->fx_addsy)
4739 : fixP->fx_addsy->sy_number);
4741 where[4] = (r_symbolnum >> 16) & 0x0ff;
4742 where[5] = (r_symbolnum >> 8) & 0x0ff;
4743 where[6] = r_symbolnum & 0x0ff;
4744 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
4745 (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
4749 #endif /* OBJ_AOUT or OBJ_BOUT */
4751 #ifndef WORKING_DOT_WORD
4752 const int md_short_jump_size = 4;
4753 const int md_long_jump_size = 6;
4756 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
4758 addressT from_addr, to_addr;
4759 fragS *frag ATTRIBUTE_UNUSED;
4760 symbolS *to_symbol ATTRIBUTE_UNUSED;
4764 offset = to_addr - (from_addr + 2);
4766 md_number_to_chars (ptr, (valueT) 0x6000, 2);
4767 md_number_to_chars (ptr + 2, (valueT) offset, 2);
4771 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
4773 addressT from_addr, to_addr;
4779 if (!HAVE_LONG_BRANCH(current_architecture))
4781 offset = to_addr - S_GET_VALUE (to_symbol);
4782 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
4783 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4784 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
4789 offset = to_addr - (from_addr + 2);
4790 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
4791 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4797 /* Different values of OK tell what its OK to return. Things that
4798 aren't OK are an error (what a shock, no?)
4801 10: Absolute 1:8 only
4802 20: Absolute 0:7 only
4803 30: absolute 0:15 only
4804 40: Absolute 0:31 only
4805 50: absolute 0:127 only
4806 55: absolute -64:63 only
4807 60: absolute -128:127 only
4808 70: absolute 0:4095 only
4815 struct m68k_exp *exp;
4818 if (exp->exp.X_op == O_absent)
4820 /* Do the same thing the VAX asm does */
4821 op (exp) = O_constant;
4827 as_warn (_("expression out of range: defaulting to 1"));
4831 else if (exp->exp.X_op == O_constant)
4836 if (offs (exp) < 1 || offs (exp) > 8)
4838 as_warn (_("expression out of range: defaulting to 1"));
4843 if (offs (exp) < 0 || offs (exp) > 7)
4847 if (offs (exp) < 0 || offs (exp) > 15)
4851 if (offs (exp) < 0 || offs (exp) > 32)
4855 if (offs (exp) < 0 || offs (exp) > 127)
4859 if (offs (exp) < -64 || offs (exp) > 63)
4863 if (offs (exp) < -128 || offs (exp) > 127)
4867 if (offs (exp) < 0 || offs (exp) > 4095)
4870 as_warn (_("expression out of range: defaulting to 0"));
4878 else if (exp->exp.X_op == O_big)
4880 if (offs (exp) <= 0 /* flonum */
4881 && (ok == 80 /* no bignums */
4882 || (ok > 10 /* small-int ranges including 0 ok */
4883 /* If we have a flonum zero, a zero integer should
4884 do as well (e.g., in moveq). */
4885 && generic_floating_point_number.exponent == 0
4886 && generic_floating_point_number.low[0] == 0)))
4888 /* HACK! Turn it into a long */
4889 LITTLENUM_TYPE words[6];
4891 gen_to_words (words, 2, 8L); /* These numbers are magic! */
4892 op (exp) = O_constant;
4895 offs (exp) = words[1] | (words[0] << 16);
4899 op (exp) = O_constant;
4902 offs (exp) = (ok == 10) ? 1 : 0;
4903 as_warn (_("Can't deal with expression; defaulting to %ld"),
4909 if (ok >= 10 && ok <= 70)
4911 op (exp) = O_constant;
4914 offs (exp) = (ok == 10) ? 1 : 0;
4915 as_warn (_("Can't deal with expression; defaulting to %ld"),
4920 if (exp->size != SIZE_UNSPEC)
4928 if (!isbyte (offs (exp)))
4929 as_warn (_("expression doesn't fit in BYTE"));
4932 if (!isword (offs (exp)))
4933 as_warn (_("expression doesn't fit in WORD"));
4941 /* These are the back-ends for the various machine dependent pseudo-ops. */
4945 int ignore ATTRIBUTE_UNUSED;
4947 subseg_set (data_section, 1);
4948 demand_empty_rest_of_line ();
4953 int ignore ATTRIBUTE_UNUSED;
4955 subseg_set (data_section, 2);
4956 demand_empty_rest_of_line ();
4961 int ignore ATTRIBUTE_UNUSED;
4963 /* We don't support putting frags in the BSS segment, we fake it
4964 by marking in_bss, then looking at s_skip for clues. */
4966 subseg_set (bss_section, 0);
4967 demand_empty_rest_of_line ();
4972 int ignore ATTRIBUTE_UNUSED;
4975 register long temp_fill;
4977 temp = 1; /* JF should be 2? */
4978 temp_fill = get_absolute_expression ();
4979 if (!need_pass_2) /* Never make frag if expect extra pass. */
4980 frag_align (temp, (int) temp_fill, 0);
4981 demand_empty_rest_of_line ();
4982 record_alignment (now_seg, temp);
4987 int ignore ATTRIBUTE_UNUSED;
4989 demand_empty_rest_of_line ();
4992 /* Pseudo-ops handled for MRI compatibility. */
4994 /* This function returns non-zero if the argument is a conditional
4995 pseudo-op. This is called when checking whether a pending
4996 alignment is needed. */
4999 m68k_conditional_pseudoop (pop)
5002 return (pop->poc_handler == s_mri_if
5003 || pop->poc_handler == s_mri_else);
5006 /* Handle an MRI style chip specification. */
5015 s = input_line_pointer;
5016 /* We can't use get_symbol_end since the processor names are not proper
5018 while (is_part_of_name (c = *input_line_pointer++))
5020 *--input_line_pointer = 0;
5021 for (i = 0; i < n_archs; i++)
5022 if (strcasecmp (s, archs[i].name) == 0)
5026 as_bad (_("%s: unrecognized processor name"), s);
5027 *input_line_pointer = c;
5028 ignore_rest_of_line ();
5031 *input_line_pointer = c;
5033 if (*input_line_pointer == '/')
5034 current_architecture = 0;
5036 current_architecture &= m68881 | m68851;
5037 current_architecture |= archs[i].arch;
5039 while (*input_line_pointer == '/')
5041 ++input_line_pointer;
5042 s = input_line_pointer;
5043 /* We can't use get_symbol_end since the processor names are not
5045 while (is_part_of_name (c = *input_line_pointer++))
5047 *--input_line_pointer = 0;
5048 if (strcmp (s, "68881") == 0)
5049 current_architecture |= m68881;
5050 else if (strcmp (s, "68851") == 0)
5051 current_architecture |= m68851;
5052 *input_line_pointer = c;
5055 /* Update info about available control registers. */
5056 select_control_regs ();
5059 /* The MRI CHIP pseudo-op. */
5063 int ignore ATTRIBUTE_UNUSED;
5069 stop = mri_comment_field (&stopc);
5072 mri_comment_end (stop, stopc);
5073 demand_empty_rest_of_line ();
5076 /* The MRI FOPT pseudo-op. */
5080 int ignore ATTRIBUTE_UNUSED;
5084 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5088 input_line_pointer += 3;
5089 temp = get_absolute_expression ();
5090 if (temp < 0 || temp > 7)
5091 as_bad (_("bad coprocessor id"));
5093 m68k_float_copnum = COP0 + temp;
5097 as_bad (_("unrecognized fopt option"));
5098 ignore_rest_of_line ();
5102 demand_empty_rest_of_line ();
5105 /* The structure used to handle the MRI OPT pseudo-op. */
5109 /* The name of the option. */
5112 /* If this is not NULL, just call this function. The first argument
5113 is the ARG field of this structure, the second argument is
5114 whether the option was negated. */
5115 void (*pfn) PARAMS ((int arg, int on));
5117 /* If this is not NULL, and the PFN field is NULL, set the variable
5118 this points to. Set it to the ARG field if the option was not
5119 negated, and the NOTARG field otherwise. */
5122 /* The value to pass to PFN or to assign to *PVAR. */
5125 /* The value to assign to *PVAR if the option is negated. If PFN is
5126 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5127 the option may not be negated. */
5131 /* The table used to handle the MRI OPT pseudo-op. */
5133 static void skip_to_comma PARAMS ((int, int));
5134 static void opt_nest PARAMS ((int, int));
5135 static void opt_chip PARAMS ((int, int));
5136 static void opt_list PARAMS ((int, int));
5137 static void opt_list_symbols PARAMS ((int, int));
5139 static const struct opt_action opt_table[] =
5141 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5143 /* We do relaxing, so there is little use for these options. */
5144 { "b", 0, 0, 0, 0 },
5145 { "brs", 0, 0, 0, 0 },
5146 { "brb", 0, 0, 0, 0 },
5147 { "brl", 0, 0, 0, 0 },
5148 { "brw", 0, 0, 0, 0 },
5150 { "c", 0, 0, 0, 0 },
5151 { "cex", 0, 0, 0, 0 },
5152 { "case", 0, &symbols_case_sensitive, 1, 0 },
5153 { "cl", 0, 0, 0, 0 },
5154 { "cre", 0, 0, 0, 0 },
5155 { "d", 0, &flag_keep_locals, 1, 0 },
5156 { "e", 0, 0, 0, 0 },
5157 { "f", 0, &flag_short_refs, 1, 0 },
5158 { "frs", 0, &flag_short_refs, 1, 0 },
5159 { "frl", 0, &flag_short_refs, 0, 1 },
5160 { "g", 0, 0, 0, 0 },
5161 { "i", 0, 0, 0, 0 },
5162 { "m", 0, 0, 0, 0 },
5163 { "mex", 0, 0, 0, 0 },
5164 { "mc", 0, 0, 0, 0 },
5165 { "md", 0, 0, 0, 0 },
5166 { "nest", opt_nest, 0, 0, 0 },
5167 { "next", skip_to_comma, 0, 0, 0 },
5168 { "o", 0, 0, 0, 0 },
5169 { "old", 0, 0, 0, 0 },
5170 { "op", skip_to_comma, 0, 0, 0 },
5171 { "pco", 0, 0, 0, 0 },
5172 { "p", opt_chip, 0, 0, 0 },
5173 { "pcr", 0, 0, 0, 0 },
5174 { "pcs", 0, 0, 0, 0 },
5175 { "r", 0, 0, 0, 0 },
5176 { "quick", 0, &m68k_quick, 1, 0 },
5177 { "rel32", 0, &m68k_rel32, 1, 0 },
5178 { "s", opt_list, 0, 0, 0 },
5179 { "t", opt_list_symbols, 0, 0, 0 },
5180 { "w", 0, &flag_no_warnings, 0, 1 },
5184 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5186 /* The MRI OPT pseudo-op. */
5190 int ignore ATTRIBUTE_UNUSED;
5198 const struct opt_action *o;
5203 if (*input_line_pointer == '-')
5205 ++input_line_pointer;
5208 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5210 input_line_pointer += 2;
5214 s = input_line_pointer;
5215 c = get_symbol_end ();
5217 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5219 if (strcasecmp (s, o->name) == 0)
5223 /* Restore input_line_pointer now in case the option
5225 *input_line_pointer = c;
5226 (*o->pfn) (o->arg, t);
5228 else if (o->pvar != NULL)
5230 if (! t && o->arg == o->notarg)
5231 as_bad (_("option `%s' may not be negated"), s);
5232 *input_line_pointer = c;
5233 *o->pvar = t ? o->arg : o->notarg;
5236 *input_line_pointer = c;
5242 as_bad (_("option `%s' not recognized"), s);
5243 *input_line_pointer = c;
5246 while (*input_line_pointer++ == ',');
5248 /* Move back to terminating character. */
5249 --input_line_pointer;
5250 demand_empty_rest_of_line ();
5253 /* Skip ahead to a comma. This is used for OPT options which we do
5254 not suppor tand which take arguments. */
5257 skip_to_comma (arg, on)
5258 int arg ATTRIBUTE_UNUSED;
5259 int on ATTRIBUTE_UNUSED;
5261 while (*input_line_pointer != ','
5262 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5263 ++input_line_pointer;
5266 /* Handle the OPT NEST=depth option. */
5270 int arg ATTRIBUTE_UNUSED;
5271 int on ATTRIBUTE_UNUSED;
5273 if (*input_line_pointer != '=')
5275 as_bad (_("bad format of OPT NEST=depth"));
5279 ++input_line_pointer;
5280 max_macro_nest = get_absolute_expression ();
5283 /* Handle the OPT P=chip option. */
5287 int arg ATTRIBUTE_UNUSED;
5288 int on ATTRIBUTE_UNUSED;
5290 if (*input_line_pointer != '=')
5292 /* This is just OPT P, which we do not support. */
5296 ++input_line_pointer;
5300 /* Handle the OPT S option. */
5304 int arg ATTRIBUTE_UNUSED;
5310 /* Handle the OPT T option. */
5313 opt_list_symbols (arg, on)
5314 int arg ATTRIBUTE_UNUSED;
5318 listing |= LISTING_SYMBOLS;
5320 listing &= ~LISTING_SYMBOLS;
5323 /* Handle the MRI REG pseudo-op. */
5327 int ignore ATTRIBUTE_UNUSED;
5336 if (line_label == NULL)
5338 as_bad (_("missing label"));
5339 ignore_rest_of_line ();
5344 stop = mri_comment_field (&stopc);
5348 s = input_line_pointer;
5349 while (ISALNUM (*input_line_pointer)
5350 #ifdef REGISTER_PREFIX
5351 || *input_line_pointer == REGISTER_PREFIX
5353 || *input_line_pointer == '/'
5354 || *input_line_pointer == '-')
5355 ++input_line_pointer;
5356 c = *input_line_pointer;
5357 *input_line_pointer = '\0';
5359 if (m68k_ip_op (s, &rop) != 0)
5361 if (rop.error == NULL)
5362 as_bad (_("bad register list"));
5364 as_bad (_("bad register list: %s"), rop.error);
5365 *input_line_pointer = c;
5366 ignore_rest_of_line ();
5370 *input_line_pointer = c;
5372 if (rop.mode == REGLST)
5374 else if (rop.mode == DREG)
5375 mask = 1 << (rop.reg - DATA0);
5376 else if (rop.mode == AREG)
5377 mask = 1 << (rop.reg - ADDR0 + 8);
5378 else if (rop.mode == FPREG)
5379 mask = 1 << (rop.reg - FP0 + 16);
5380 else if (rop.mode == CONTROL
5383 else if (rop.mode == CONTROL
5386 else if (rop.mode == CONTROL
5391 as_bad (_("bad register list"));
5392 ignore_rest_of_line ();
5396 S_SET_SEGMENT (line_label, reg_section);
5397 S_SET_VALUE (line_label, ~mask);
5398 symbol_set_frag (line_label, &zero_address_frag);
5401 mri_comment_end (stop, stopc);
5403 demand_empty_rest_of_line ();
5406 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5410 struct save_opts *next;
5412 int symbols_case_sensitive;
5420 /* FIXME: We don't save OPT S. */
5423 /* This variable holds the stack of saved options. */
5425 static struct save_opts *save_stack;
5427 /* The MRI SAVE pseudo-op. */
5431 int ignore ATTRIBUTE_UNUSED;
5433 struct save_opts *s;
5435 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5436 s->abspcadd = m68k_abspcadd;
5437 s->symbols_case_sensitive = symbols_case_sensitive;
5438 s->keep_locals = flag_keep_locals;
5439 s->short_refs = flag_short_refs;
5440 s->architecture = current_architecture;
5441 s->quick = m68k_quick;
5442 s->rel32 = m68k_rel32;
5443 s->listing = listing;
5444 s->no_warnings = flag_no_warnings;
5446 s->next = save_stack;
5449 demand_empty_rest_of_line ();
5452 /* The MRI RESTORE pseudo-op. */
5456 int ignore ATTRIBUTE_UNUSED;
5458 struct save_opts *s;
5460 if (save_stack == NULL)
5462 as_bad (_("restore without save"));
5463 ignore_rest_of_line ();
5468 save_stack = s->next;
5470 m68k_abspcadd = s->abspcadd;
5471 symbols_case_sensitive = s->symbols_case_sensitive;
5472 flag_keep_locals = s->keep_locals;
5473 flag_short_refs = s->short_refs;
5474 current_architecture = s->architecture;
5475 m68k_quick = s->quick;
5476 m68k_rel32 = s->rel32;
5477 listing = s->listing;
5478 flag_no_warnings = s->no_warnings;
5482 demand_empty_rest_of_line ();
5485 /* Types of MRI structured control directives. */
5487 enum mri_control_type
5495 /* This structure is used to stack the MRI structured control
5498 struct mri_control_info
5500 /* The directive within which this one is enclosed. */
5501 struct mri_control_info *outer;
5503 /* The type of directive. */
5504 enum mri_control_type type;
5506 /* Whether an ELSE has been in an IF. */
5509 /* The add or sub statement at the end of a FOR. */
5512 /* The label of the top of a FOR or REPEAT loop. */
5515 /* The label to jump to for the next iteration, or the else
5516 expression of a conditional. */
5519 /* The label to jump to to break out of the loop, or the label past
5520 the end of a conditional. */
5524 /* The stack of MRI structured control directives. */
5526 static struct mri_control_info *mri_control_stack;
5528 /* The current MRI structured control directive index number, used to
5529 generate label names. */
5531 static int mri_control_index;
5533 /* Some function prototypes. */
5535 static void mri_assemble PARAMS ((char *));
5536 static char *mri_control_label PARAMS ((void));
5537 static struct mri_control_info *push_mri_control
5538 PARAMS ((enum mri_control_type));
5539 static void pop_mri_control PARAMS ((void));
5540 static int parse_mri_condition PARAMS ((int *));
5541 static int parse_mri_control_operand
5542 PARAMS ((int *, char **, char **, char **, char **));
5543 static int swap_mri_condition PARAMS ((int));
5544 static int reverse_mri_condition PARAMS ((int));
5545 static void build_mri_control_operand
5546 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5547 const char *, int));
5548 static void parse_mri_control_expression
5549 PARAMS ((char *, int, const char *, const char *, int));
5551 /* Assemble an instruction for an MRI structured control directive. */
5559 /* md_assemble expects the opcode to be in lower case. */
5560 for (s = str; *s != ' ' && *s != '\0'; s++)
5566 /* Generate a new MRI label structured control directive label name. */
5569 mri_control_label ()
5573 n = (char *) xmalloc (20);
5574 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5575 ++mri_control_index;
5579 /* Create a new MRI structured control directive. */
5581 static struct mri_control_info *
5582 push_mri_control (type)
5583 enum mri_control_type type;
5585 struct mri_control_info *n;
5587 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5591 if (type == mri_if || type == mri_while)
5594 n->top = mri_control_label ();
5595 n->next = mri_control_label ();
5596 n->bottom = mri_control_label ();
5598 n->outer = mri_control_stack;
5599 mri_control_stack = n;
5604 /* Pop off the stack of MRI structured control directives. */
5609 struct mri_control_info *n;
5611 n = mri_control_stack;
5612 mri_control_stack = n->outer;
5620 /* Recognize a condition code in an MRI structured control expression. */
5623 parse_mri_condition (pcc)
5628 know (*input_line_pointer == '<');
5630 ++input_line_pointer;
5631 c1 = *input_line_pointer++;
5632 c2 = *input_line_pointer++;
5634 if (*input_line_pointer != '>')
5636 as_bad (_("syntax error in structured control directive"));
5640 ++input_line_pointer;
5646 *pcc = (c1 << 8) | c2;
5651 /* Parse a single operand in an MRI structured control expression. */
5654 parse_mri_control_operand (pcc, leftstart, leftstop, rightstart, rightstop)
5671 if (*input_line_pointer == '<')
5673 /* It's just a condition code. */
5674 return parse_mri_condition (pcc);
5677 /* Look ahead for the condition code. */
5678 for (s = input_line_pointer; *s != '\0'; ++s)
5680 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
5685 as_bad (_("missing condition code in structured control directive"));
5689 *leftstart = input_line_pointer;
5691 if (*leftstop > *leftstart
5692 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
5695 input_line_pointer = s;
5696 if (! parse_mri_condition (pcc))
5699 /* Look ahead for AND or OR or end of line. */
5700 for (s = input_line_pointer; *s != '\0'; ++s)
5702 /* We must make sure we don't misinterpret AND/OR at the end of labels!
5703 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
5705 if ((s == input_line_pointer
5708 && ((strncasecmp (s, "AND", 3) == 0
5709 && (s[3] == '.' || ! is_part_of_name (s[3])))
5710 || (strncasecmp (s, "OR", 2) == 0
5711 && (s[2] == '.' || ! is_part_of_name (s[2])))))
5715 *rightstart = input_line_pointer;
5717 if (*rightstop > *rightstart
5718 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
5721 input_line_pointer = s;
5726 #define MCC(b1, b2) (((b1) << 8) | (b2))
5728 /* Swap the sense of a condition. This changes the condition so that
5729 it generates the same result when the operands are swapped. */
5732 swap_mri_condition (cc)
5737 case MCC ('h', 'i'): return MCC ('c', 's');
5738 case MCC ('l', 's'): return MCC ('c', 'c');
5739 /* <HS> is an alias for <CC> */
5740 case MCC ('h', 's'):
5741 case MCC ('c', 'c'): return MCC ('l', 's');
5742 /* <LO> is an alias for <CS> */
5743 case MCC ('l', 'o'):
5744 case MCC ('c', 's'): return MCC ('h', 'i');
5745 case MCC ('p', 'l'): return MCC ('m', 'i');
5746 case MCC ('m', 'i'): return MCC ('p', 'l');
5747 case MCC ('g', 'e'): return MCC ('l', 'e');
5748 case MCC ('l', 't'): return MCC ('g', 't');
5749 case MCC ('g', 't'): return MCC ('l', 't');
5750 case MCC ('l', 'e'): return MCC ('g', 'e');
5751 /* issue a warning for conditions we can not swap */
5752 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
5753 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
5754 case MCC ('v', 'c'):
5755 case MCC ('v', 's'):
5757 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
5758 (char) (cc >> 8), (char) (cc));
5764 /* Reverse the sense of a condition. */
5767 reverse_mri_condition (cc)
5772 case MCC ('h', 'i'): return MCC ('l', 's');
5773 case MCC ('l', 's'): return MCC ('h', 'i');
5774 /* <HS> is an alias for <CC> */
5775 case MCC ('h', 's'): return MCC ('l', 'o');
5776 case MCC ('c', 'c'): return MCC ('c', 's');
5777 /* <LO> is an alias for <CS> */
5778 case MCC ('l', 'o'): return MCC ('h', 's');
5779 case MCC ('c', 's'): return MCC ('c', 'c');
5780 case MCC ('n', 'e'): return MCC ('e', 'q');
5781 case MCC ('e', 'q'): return MCC ('n', 'e');
5782 case MCC ('v', 'c'): return MCC ('v', 's');
5783 case MCC ('v', 's'): return MCC ('v', 'c');
5784 case MCC ('p', 'l'): return MCC ('m', 'i');
5785 case MCC ('m', 'i'): return MCC ('p', 'l');
5786 case MCC ('g', 'e'): return MCC ('l', 't');
5787 case MCC ('l', 't'): return MCC ('g', 'e');
5788 case MCC ('g', 't'): return MCC ('l', 'e');
5789 case MCC ('l', 'e'): return MCC ('g', 't');
5794 /* Build an MRI structured control expression. This generates test
5795 and branch instructions. It goes to TRUELAB if the condition is
5796 true, and to FALSELAB if the condition is false. Exactly one of
5797 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5798 is the size qualifier for the expression. EXTENT is the size to
5799 use for the branch. */
5802 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5803 rightstop, truelab, falselab, extent)
5810 const char *truelab;
5811 const char *falselab;
5817 if (leftstart != NULL)
5819 struct m68k_op leftop, rightop;
5822 /* Swap the compare operands, if necessary, to produce a legal
5823 m68k compare instruction. Comparing a register operand with
5824 a non-register operand requires the register to be on the
5825 right (cmp, cmpa). Comparing an immediate value with
5826 anything requires the immediate value to be on the left
5831 (void) m68k_ip_op (leftstart, &leftop);
5836 (void) m68k_ip_op (rightstart, &rightop);
5839 if (rightop.mode == IMMED
5840 || ((leftop.mode == DREG || leftop.mode == AREG)
5841 && (rightop.mode != DREG && rightop.mode != AREG)))
5845 /* Correct conditional handling:
5846 if #1 <lt> d0 then ;means if (1 < d0)
5852 cmp #1,d0 if we do *not* swap the operands
5853 bgt true we need the swapped condition!
5860 leftstart = rightstart;
5863 leftstop = rightstop;
5868 cc = swap_mri_condition (cc);
5872 if (truelab == NULL)
5874 cc = reverse_mri_condition (cc);
5878 if (leftstart != NULL)
5880 buf = (char *) xmalloc (20
5881 + (leftstop - leftstart)
5882 + (rightstop - rightstart));
5888 *s++ = TOLOWER (qual);
5890 memcpy (s, leftstart, leftstop - leftstart);
5891 s += leftstop - leftstart;
5893 memcpy (s, rightstart, rightstop - rightstart);
5894 s += rightstop - rightstart;
5900 buf = (char *) xmalloc (20 + strlen (truelab));
5906 *s++ = TOLOWER (extent);
5908 strcpy (s, truelab);
5913 /* Parse an MRI structured control expression. This generates test
5914 and branch instructions. STOP is where the expression ends. It
5915 goes to TRUELAB if the condition is true, and to FALSELAB if the
5916 condition is false. Exactly one of TRUELAB and FALSELAB will be
5917 NULL, meaning to fall through. QUAL is the size qualifier for the
5918 expression. EXTENT is the size to use for the branch. */
5921 parse_mri_control_expression (stop, qual, truelab, falselab, extent)
5924 const char *truelab;
5925 const char *falselab;
5938 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5939 &rightstart, &rightstop))
5945 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
5949 if (falselab != NULL)
5952 flab = mri_control_label ();
5954 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5955 rightstop, (const char *) NULL, flab, extent);
5957 input_line_pointer += 3;
5958 if (*input_line_pointer != '.'
5959 || input_line_pointer[1] == '\0')
5963 qual = input_line_pointer[1];
5964 input_line_pointer += 2;
5967 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5968 &rightstart, &rightstop))
5974 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5975 rightstop, truelab, falselab, extent);
5977 if (falselab == NULL)
5980 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
5984 if (truelab != NULL)
5987 tlab = mri_control_label ();
5989 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5990 rightstop, tlab, (const char *) NULL, extent);
5992 input_line_pointer += 2;
5993 if (*input_line_pointer != '.'
5994 || input_line_pointer[1] == '\0')
5998 qual = input_line_pointer[1];
5999 input_line_pointer += 2;
6002 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6003 &rightstart, &rightstop))
6009 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6010 rightstop, truelab, falselab, extent);
6012 if (truelab == NULL)
6017 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6018 rightstop, truelab, falselab, extent);
6022 if (input_line_pointer != stop)
6023 as_bad (_("syntax error in structured control directive"));
6026 /* Handle the MRI IF pseudo-op. This may be a structured control
6027 directive, or it may be a regular assembler conditional, depending
6036 struct mri_control_info *n;
6038 /* A structured control directive must end with THEN with an
6039 optional qualifier. */
6040 s = input_line_pointer;
6041 /* We only accept '*' as introduction of comments if preceded by white space
6042 or at first column of a line (I think this can't actually happen here?)
6043 This is important when assembling:
6044 if d0 <ne> 12(a0,d0*2) then
6045 if d0 <ne> #CONST*20 then */
6046 while ( ! ( is_end_of_line[(unsigned char) *s]
6049 && ( s == input_line_pointer
6051 || *(s-1) == '\t'))))
6054 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6057 if (s - input_line_pointer > 1
6061 if (s - input_line_pointer < 3
6062 || strncasecmp (s - 3, "THEN", 4) != 0)
6066 as_bad (_("missing then"));
6067 ignore_rest_of_line ();
6071 /* It's a conditional. */
6076 /* Since this might be a conditional if, this pseudo-op will be
6077 called even if we are supported to be ignoring input. Double
6078 check now. Clobber *input_line_pointer so that ignore_input
6079 thinks that this is not a special pseudo-op. */
6080 c = *input_line_pointer;
6081 *input_line_pointer = 0;
6082 if (ignore_input ())
6084 *input_line_pointer = c;
6085 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6086 ++input_line_pointer;
6087 demand_empty_rest_of_line ();
6090 *input_line_pointer = c;
6092 n = push_mri_control (mri_if);
6094 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6095 n->next, s[1] == '.' ? s[2] : '\0');
6098 input_line_pointer = s + 3;
6100 input_line_pointer = s + 1;
6104 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6105 ++input_line_pointer;
6108 demand_empty_rest_of_line ();
6111 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6112 structured IF, associate the ELSE with the IF. Otherwise, assume
6113 it is a conditional else. */
6124 && (mri_control_stack == NULL
6125 || mri_control_stack->type != mri_if
6126 || mri_control_stack->else_seen))
6132 c = *input_line_pointer;
6133 *input_line_pointer = 0;
6134 if (ignore_input ())
6136 *input_line_pointer = c;
6137 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6138 ++input_line_pointer;
6139 demand_empty_rest_of_line ();
6142 *input_line_pointer = c;
6144 if (mri_control_stack == NULL
6145 || mri_control_stack->type != mri_if
6146 || mri_control_stack->else_seen)
6148 as_bad (_("else without matching if"));
6149 ignore_rest_of_line ();
6153 mri_control_stack->else_seen = 1;
6155 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6156 q[0] = TOLOWER (qual);
6158 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6162 colon (mri_control_stack->next);
6166 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6167 ++input_line_pointer;
6170 demand_empty_rest_of_line ();
6173 /* Handle the MRI ENDI pseudo-op. */
6177 int ignore ATTRIBUTE_UNUSED;
6179 if (mri_control_stack == NULL
6180 || mri_control_stack->type != mri_if)
6182 as_bad (_("endi without matching if"));
6183 ignore_rest_of_line ();
6187 /* ignore_input will not return true for ENDI, so we don't need to
6188 worry about checking it again here. */
6190 if (! mri_control_stack->else_seen)
6191 colon (mri_control_stack->next);
6192 colon (mri_control_stack->bottom);
6198 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6199 ++input_line_pointer;
6202 demand_empty_rest_of_line ();
6205 /* Handle the MRI BREAK pseudo-op. */
6208 s_mri_break (extent)
6211 struct mri_control_info *n;
6215 n = mri_control_stack;
6217 && n->type != mri_for
6218 && n->type != mri_repeat
6219 && n->type != mri_while)
6223 as_bad (_("break outside of structured loop"));
6224 ignore_rest_of_line ();
6228 buf = (char *) xmalloc (20 + strlen (n->bottom));
6229 ex[0] = TOLOWER (extent);
6231 sprintf (buf, "bra%s %s", ex, n->bottom);
6237 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6238 ++input_line_pointer;
6241 demand_empty_rest_of_line ();
6244 /* Handle the MRI NEXT pseudo-op. */
6250 struct mri_control_info *n;
6254 n = mri_control_stack;
6256 && n->type != mri_for
6257 && n->type != mri_repeat
6258 && n->type != mri_while)
6262 as_bad (_("next outside of structured loop"));
6263 ignore_rest_of_line ();
6267 buf = (char *) xmalloc (20 + strlen (n->next));
6268 ex[0] = TOLOWER (extent);
6270 sprintf (buf, "bra%s %s", ex, n->next);
6276 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6277 ++input_line_pointer;
6280 demand_empty_rest_of_line ();
6283 /* Handle the MRI FOR pseudo-op. */
6289 const char *varstart, *varstop;
6290 const char *initstart, *initstop;
6291 const char *endstart, *endstop;
6292 const char *bystart, *bystop;
6296 struct mri_control_info *n;
6302 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6306 varstart = input_line_pointer;
6308 /* Look for the '='. */
6309 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6310 && *input_line_pointer != '=')
6311 ++input_line_pointer;
6312 if (*input_line_pointer != '=')
6314 as_bad (_("missing ="));
6315 ignore_rest_of_line ();
6319 varstop = input_line_pointer;
6320 if (varstop > varstart
6321 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6324 ++input_line_pointer;
6326 initstart = input_line_pointer;
6328 /* Look for TO or DOWNTO. */
6331 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6333 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6334 && ! is_part_of_name (input_line_pointer[2]))
6336 initstop = input_line_pointer;
6337 input_line_pointer += 2;
6340 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6341 && ! is_part_of_name (input_line_pointer[6]))
6343 initstop = input_line_pointer;
6345 input_line_pointer += 6;
6348 ++input_line_pointer;
6350 if (initstop == NULL)
6352 as_bad (_("missing to or downto"));
6353 ignore_rest_of_line ();
6356 if (initstop > initstart
6357 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6361 endstart = input_line_pointer;
6363 /* Look for BY or DO. */
6366 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6368 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6369 && ! is_part_of_name (input_line_pointer[2]))
6371 endstop = input_line_pointer;
6373 input_line_pointer += 2;
6376 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6377 && (input_line_pointer[2] == '.'
6378 || ! is_part_of_name (input_line_pointer[2])))
6380 endstop = input_line_pointer;
6381 input_line_pointer += 2;
6384 ++input_line_pointer;
6386 if (endstop == NULL)
6388 as_bad (_("missing do"));
6389 ignore_rest_of_line ();
6392 if (endstop > endstart
6393 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6399 bystop = bystart + 2;
6404 bystart = input_line_pointer;
6408 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6410 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6411 && (input_line_pointer[2] == '.'
6412 || ! is_part_of_name (input_line_pointer[2])))
6414 bystop = input_line_pointer;
6415 input_line_pointer += 2;
6418 ++input_line_pointer;
6422 as_bad (_("missing do"));
6423 ignore_rest_of_line ();
6426 if (bystop > bystart
6427 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6431 if (*input_line_pointer != '.')
6435 extent = input_line_pointer[1];
6436 input_line_pointer += 2;
6439 /* We have fully parsed the FOR operands. Now build the loop. */
6441 n = push_mri_control (mri_for);
6443 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6452 *s++ = TOLOWER (qual);
6454 memcpy (s, initstart, initstop - initstart);
6455 s += initstop - initstart;
6457 memcpy (s, varstart, varstop - varstart);
6458 s += varstop - varstart;
6470 *s++ = TOLOWER (qual);
6472 memcpy (s, endstart, endstop - endstart);
6473 s += endstop - endstart;
6475 memcpy (s, varstart, varstop - varstart);
6476 s += varstop - varstart;
6481 ex[0] = TOLOWER (extent);
6484 sprintf (buf, "blt%s %s", ex, n->bottom);
6486 sprintf (buf, "bgt%s %s", ex, n->bottom);
6489 /* Put together the add or sub instruction used by ENDF. */
6497 *s++ = TOLOWER (qual);
6499 memcpy (s, bystart, bystop - bystart);
6500 s += bystop - bystart;
6502 memcpy (s, varstart, varstop - varstart);
6503 s += varstop - varstart;
6509 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6510 ++input_line_pointer;
6513 demand_empty_rest_of_line ();
6516 /* Handle the MRI ENDF pseudo-op. */
6520 int ignore ATTRIBUTE_UNUSED;
6522 if (mri_control_stack == NULL
6523 || mri_control_stack->type != mri_for)
6525 as_bad (_("endf without for"));
6526 ignore_rest_of_line ();
6530 colon (mri_control_stack->next);
6532 mri_assemble (mri_control_stack->incr);
6534 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6535 mri_assemble (mri_control_stack->incr);
6537 free (mri_control_stack->incr);
6539 colon (mri_control_stack->bottom);
6545 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6546 ++input_line_pointer;
6549 demand_empty_rest_of_line ();
6552 /* Handle the MRI REPEAT pseudo-op. */
6555 s_mri_repeat (ignore)
6556 int ignore ATTRIBUTE_UNUSED;
6558 struct mri_control_info *n;
6560 n = push_mri_control (mri_repeat);
6564 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6565 ++input_line_pointer;
6567 demand_empty_rest_of_line ();
6570 /* Handle the MRI UNTIL pseudo-op. */
6578 if (mri_control_stack == NULL
6579 || mri_control_stack->type != mri_repeat)
6581 as_bad (_("until without repeat"));
6582 ignore_rest_of_line ();
6586 colon (mri_control_stack->next);
6588 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6591 parse_mri_control_expression (s, qual, (const char *) NULL,
6592 mri_control_stack->top, '\0');
6594 colon (mri_control_stack->bottom);
6596 input_line_pointer = s;
6602 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6603 ++input_line_pointer;
6606 demand_empty_rest_of_line ();
6609 /* Handle the MRI WHILE pseudo-op. */
6617 struct mri_control_info *n;
6619 s = input_line_pointer;
6620 /* We only accept '*' as introduction of comments if preceded by white space
6621 or at first column of a line (I think this can't actually happen here?)
6622 This is important when assembling:
6623 while d0 <ne> 12(a0,d0*2) do
6624 while d0 <ne> #CONST*20 do */
6625 while (! (is_end_of_line[(unsigned char) *s]
6628 && (s == input_line_pointer
6630 || *(s-1) == '\t'))))
6633 while (*s == ' ' || *s == '\t')
6635 if (s - input_line_pointer > 1
6638 if (s - input_line_pointer < 2
6639 || strncasecmp (s - 1, "DO", 2) != 0)
6641 as_bad (_("missing do"));
6642 ignore_rest_of_line ();
6646 n = push_mri_control (mri_while);
6650 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6651 s[1] == '.' ? s[2] : '\0');
6653 input_line_pointer = s + 1;
6654 if (*input_line_pointer == '.')
6655 input_line_pointer += 2;
6659 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6660 ++input_line_pointer;
6663 demand_empty_rest_of_line ();
6666 /* Handle the MRI ENDW pseudo-op. */
6670 int ignore ATTRIBUTE_UNUSED;
6674 if (mri_control_stack == NULL
6675 || mri_control_stack->type != mri_while)
6677 as_bad (_("endw without while"));
6678 ignore_rest_of_line ();
6682 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
6683 sprintf (buf, "bra %s", mri_control_stack->next);
6687 colon (mri_control_stack->bottom);
6693 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6694 ++input_line_pointer;
6697 demand_empty_rest_of_line ();
6702 * Invocation line includes a switch not recognized by the base assembler.
6703 * See if it's a processor-specific option. These are:
6705 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6706 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6707 * Select the architecture. Instructions or features not
6708 * supported by the selected architecture cause fatal
6709 * errors. More than one may be specified. The default is
6710 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6711 * for -m68000, and -m68882 is a synonym for -m68881.
6712 * -[A]m[c]no-68851, -[A]m[c]no-68881
6713 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6714 * so don't use or document it, but that's the way the parsing
6717 * -pic Indicates PIC.
6718 * -k Indicates PIC. (Sun 3 only.)
6719 * --pcrel Never turn PC-relative branches into absolute jumps.
6722 * Permit `|' to be used in expressions.
6727 const char *md_shortopts = "lSA:m:kQ:V";
6729 const char *md_shortopts = "lSA:m:k";
6732 struct option md_longopts[] = {
6733 #define OPTION_PIC (OPTION_MD_BASE)
6734 {"pic", no_argument, NULL, OPTION_PIC},
6735 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6736 {"register-prefix-optional", no_argument, NULL,
6737 OPTION_REGISTER_PREFIX_OPTIONAL},
6738 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6739 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
6740 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6741 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
6742 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6743 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
6744 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6745 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
6746 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6747 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
6748 #define OPTION_PCREL (OPTION_MD_BASE + 7)
6749 {"pcrel", no_argument, NULL, OPTION_PCREL},
6750 {NULL, no_argument, NULL, 0}
6752 size_t md_longopts_size = sizeof (md_longopts);
6755 md_parse_option (c, arg)
6761 case 'l': /* -l means keep external to 2 bit offset
6762 rather than 16 bit one */
6763 flag_short_refs = 1;
6766 case 'S': /* -S means that jbsr's always turn into
6768 flag_long_jumps = 1;
6771 case OPTION_PCREL: /* --pcrel means never turn PC-relative
6772 branches into absolute jumps. */
6773 flag_keep_pcrel = 1;
6779 /* intentional fall-through */
6782 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
6786 const char *oarg = arg;
6792 if (arg[0] == 'c' && arg[1] == '6')
6795 for (i = 0; i < n_archs; i++)
6796 if (!strcmp (arg, archs[i].name))
6801 as_bad (_("unrecognized option `%s'"), oarg);
6804 arch = archs[i].arch;
6807 else if (arch == m68851)
6816 if (arg[0] == 'c' && arg[1] == '6')
6819 for (i = 0; i < n_archs; i++)
6820 if (!strcmp (arg, archs[i].name))
6822 unsigned long arch = archs[i].arch;
6823 if (cpu_of_arch (arch))
6824 /* It's a cpu spec. */
6826 current_architecture &= ~m68000up;
6827 current_architecture |= arch;
6829 else if (arch == m68881)
6831 current_architecture |= m68881;
6834 else if (arch == m68851)
6836 current_architecture |= m68851;
6846 as_bad (_("unrecognized architecture specification `%s'"), arg);
6855 break; /* -pic, Position Independent Code */
6857 case OPTION_REGISTER_PREFIX_OPTIONAL:
6858 flag_reg_prefix_optional = 1;
6859 reg_prefix_optional_seen = 1;
6862 /* -V: SVR4 argument to print version ID. */
6864 print_version_id ();
6867 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6868 should be emitted or not. FIXME: Not implemented. */
6872 case OPTION_BITWISE_OR:
6877 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
6879 for (s = m68k_comment_chars; *s != '\0'; s++)
6883 m68k_comment_chars = n;
6887 case OPTION_BASE_SIZE_DEFAULT_16:
6888 m68k_index_width_default = SIZE_WORD;
6891 case OPTION_BASE_SIZE_DEFAULT_32:
6892 m68k_index_width_default = SIZE_LONG;
6895 case OPTION_DISP_SIZE_DEFAULT_16:
6897 m68k_rel32_from_cmdline = 1;
6900 case OPTION_DISP_SIZE_DEFAULT_32:
6902 m68k_rel32_from_cmdline = 1;
6913 md_show_usage (stream)
6916 const char *default_cpu = TARGET_CPU;
6918 unsigned int default_arch;
6920 /* Get the canonical name for the default target CPU. */
6921 if (*default_cpu == 'm')
6923 for (i = 0; i < n_archs; i++)
6925 if (strcasecmp (default_cpu, archs[i].name) == 0)
6927 default_arch = archs[i].arch;
6928 for (i = 0; i < n_archs; i++)
6930 if (archs[i].arch == default_arch
6933 default_cpu = archs[i].name;
6940 fprintf (stream, _("\
6942 -l use 1 word for refs to undefined symbols [default 2]\n\
6943 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
6944 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
6945 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m5307 | -m5407\n\
6946 specify variant of 680X0 architecture [default %s]\n\
6947 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6948 target has/lacks floating-point coprocessor\n\
6949 [default yes for 68020, 68030, and cpu32]\n"),
6951 fprintf (stream, _("\
6952 -m68851 | -mno-68851\n\
6953 target has/lacks memory-management unit coprocessor\n\
6954 [default yes for 68020 and up]\n\
6955 -pic, -k generate position independent code\n\
6956 -S turn jbsr into jsr\n\
6957 --pcrel never turn PC-relative branches into absolute jumps\n\
6958 --register-prefix-optional\n\
6959 recognize register names without prefix character\n\
6960 --bitwise-or do not treat `|' as a comment character\n"));
6961 fprintf (stream, _("\
6962 --base-size-default-16 base reg without size is 16 bits\n\
6963 --base-size-default-32 base reg without size is 32 bits (default)\n\
6964 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6965 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
6970 /* TEST2: Test md_assemble() */
6971 /* Warning, this routine probably doesn't work anymore */
6975 struct m68k_it the_ins;
6983 if (!gets (buf) || !*buf)
6985 if (buf[0] == '|' || buf[1] == '.')
6987 for (cp = buf; *cp; cp++)
6992 memset (&the_ins, '\0', sizeof (the_ins));
6993 m68k_ip (&the_ins, buf);
6996 printf (_("Error %s in %s\n"), the_ins.error, buf);
7000 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7001 for (n = 0; n < the_ins.numo; n++)
7002 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7004 print_the_insn (&the_ins.opcode[0], stdout);
7005 (void) putchar ('\n');
7007 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7009 if (the_ins.operands[n].error)
7011 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7014 printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
7015 if (the_ins.operands[n].b_const)
7016 printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
7017 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
7018 if (the_ins.operands[n].b_iadd)
7019 printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
7020 (void) putchar ('\n');
7032 while (*str && *str != ' ')
7034 if (str[-1] == ':' || str[1] == '=')
7041 /* Possible states for relaxation:
7043 0 0 branch offset byte (bra, etc)
7047 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7051 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7058 /* We have no need to default values of symbols. */
7061 md_undefined_symbol (name)
7062 char *name ATTRIBUTE_UNUSED;
7067 /* Round up a section size to the appropriate boundary. */
7069 md_section_align (segment, size)
7070 segT segment ATTRIBUTE_UNUSED;
7074 #ifdef BFD_ASSEMBLER
7075 /* For a.out, force the section size to be aligned. If we don't do
7076 this, BFD will align it for us, but it will not write out the
7077 final bytes of the section. This may be a bug in BFD, but it is
7078 easier to fix it here since that is how the other a.out targets
7082 align = bfd_get_section_alignment (stdoutput, segment);
7083 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7090 /* Exactly what point is a PC-relative offset relative TO?
7091 On the 68k, it is relative to the address of the first extension
7092 word. The difference between the addresses of the offset and the
7093 first extension word is stored in fx_pcrel_adjust. */
7095 md_pcrel_from (fixP)
7100 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7101 sign extend the value here. */
7102 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7105 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7108 #ifndef BFD_ASSEMBLER
7112 tc_coff_symbol_emit_hook (ignore)
7113 symbolS *ignore ATTRIBUTE_UNUSED;
7118 tc_coff_sizemachdep (frag)
7121 switch (frag->fr_subtype & 0x3)
7139 m68k_elf_final_processing ()
7141 /* Set file-specific flags if this is a cpu32 processor */
7142 if (cpu_of_arch (current_architecture) & cpu32)
7143 elf_elfheader (stdoutput)->e_flags |= EF_CPU32;
7144 else if ((cpu_of_arch (current_architecture) & m68000up)
7145 && !(cpu_of_arch (current_architecture) & m68020up))
7146 elf_elfheader (stdoutput)->e_flags |= EF_M68000;