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_apply_fix_2 PARAMS ((fixS *, offsetT));
352 static void md_convert_frag_1 PARAMS ((fragS *));
354 static int current_architecture;
363 static const struct m68k_cpu archs[] =
365 { m68000, "68000", 0 },
366 { m68010, "68010", 0 },
367 { m68020, "68020", 0 },
368 { m68030, "68030", 0 },
369 { m68040, "68040", 0 },
370 { m68060, "68060", 0 },
371 { cpu32, "cpu32", 0 },
372 { m68881, "68881", 0 },
373 { m68851, "68851", 0 },
374 { mcf5200, "5200", 0 },
375 { mcf5206e, "5206e", 0 },
376 { mcf5307, "5307", 0},
377 { mcf5407, "5407", 0},
378 /* Aliases (effectively, so far as gas is concerned) for the above
380 { m68020, "68k", 1 },
381 { m68000, "68008", 1 },
382 { m68000, "68302", 1 },
383 { m68000, "68306", 1 },
384 { m68000, "68307", 1 },
385 { m68000, "68322", 1 },
386 { m68000, "68356", 1 },
387 { m68000, "68ec000", 1 },
388 { m68000, "68hc000", 1 },
389 { m68000, "68hc001", 1 },
390 { m68020, "68ec020", 1 },
391 { m68030, "68ec030", 1 },
392 { m68040, "68ec040", 1 },
393 { m68060, "68ec060", 1 },
394 { cpu32, "68330", 1 },
395 { cpu32, "68331", 1 },
396 { cpu32, "68332", 1 },
397 { cpu32, "68333", 1 },
398 { cpu32, "68334", 1 },
399 { cpu32, "68336", 1 },
400 { cpu32, "68340", 1 },
401 { cpu32, "68341", 1 },
402 { cpu32, "68349", 1 },
403 { cpu32, "68360", 1 },
404 { m68881, "68882", 1 },
405 { mcf5200, "5202", 1 },
406 { mcf5200, "5204", 1 },
407 { mcf5200, "5206", 1 },
410 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
412 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
413 architecture and we have a lot of relaxation modes. */
415 /* Macros used in the relaxation code. */
416 #define TAB(x,y) (((x) << 2) + (y))
417 #define TABTYPE(x) ((x) >> 2)
419 /* Relaxation states. */
425 /* Here are all the relaxation modes we support. First we can relax ordinary
426 branches. On 68020 and higher and on CPU32 all branch instructions take
427 three forms, so on these CPUs all branches always remain as such. When we
428 have to expand to the LONG form on a 68000, though, we substitute an
429 absolute jump instead. This is a direct replacement for unconditional
430 branches and a branch over a jump for conditional branches. However, if the
431 user requires PIC and disables this with --pcrel, we can only relax between
432 BYTE and SHORT forms, punting if that isn't enough. This gives us four
433 different relaxation modes for branches: */
435 #define BRANCHBWL 0 /* branch byte, word, or long */
436 #define BRABSJUNC 1 /* absolute jump for LONG, unconditional */
437 #define BRABSJCOND 2 /* absolute jump for LONG, conditional */
438 #define BRANCHBW 3 /* branch byte or word */
440 /* We also relax coprocessor branches and DBcc's. All CPUs that support
441 coprocessor branches support them in word and long forms, so we have only
442 one relaxation mode for them. DBcc's are word only on all CPUs. We can
443 relax them to the LONG form with a branch-around sequence. This sequence
444 can use a long branch (if available) or an absolute jump (if acceptable).
445 This gives us two relaxation modes. If long branches are not available and
446 absolute jumps are not acceptable, we don't relax DBcc's. */
448 #define FBRANCH 4 /* coprocessor branch */
449 #define DBCCLBR 5 /* DBcc relaxable with a long branch */
450 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump */
452 /* That's all for instruction relaxation. However, we also relax PC-relative
453 operands. Specifically, we have three operand relaxation modes. On the
454 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
455 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
456 two. Also PC+displacement+index operands in their simple form (with a non-
457 suppressed index without memory indirection) are supported on all CPUs, but
458 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
459 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
460 form of the PC+displacement+index operand. Finally, some absolute operands
461 can be relaxed down to 16-bit PC-relative. */
463 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative */
464 #define PCINDEX 8 /* PC+displacement+index */
465 #define ABSTOPCREL 9 /* absolute relax down to 16-bit PC-relative */
467 /* Note that calls to frag_var need to specify the maximum expansion
468 needed; this is currently 10 bytes for DBCC. */
471 How far Forward this mode will reach:
472 How far Backward this mode will reach:
473 How many bytes this mode will add to the size of the frag
474 Which mode to go to if the offset won't fit in this one
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'},
558 /* Dwarf2 support for Gcc. */
559 {"file", dwarf2_directive_file, 0},
560 {"loc", dwarf2_directive_loc, 0},
563 /* The following pseudo-ops are supported for MRI compatibility. */
565 {"comline", s_space, 1},
567 {"mask2", s_ignore, 0},
570 {"restore", s_restore, 0},
574 {"if.b", s_mri_if, 'b'},
575 {"if.w", s_mri_if, 'w'},
576 {"if.l", s_mri_if, 'l'},
577 {"else", s_mri_else, 0},
578 {"else.s", s_mri_else, 's'},
579 {"else.l", s_mri_else, 'l'},
580 {"endi", s_mri_endi, 0},
581 {"break", s_mri_break, 0},
582 {"break.s", s_mri_break, 's'},
583 {"break.l", s_mri_break, 'l'},
584 {"next", s_mri_next, 0},
585 {"next.s", s_mri_next, 's'},
586 {"next.l", s_mri_next, 'l'},
587 {"for", s_mri_for, 0},
588 {"for.b", s_mri_for, 'b'},
589 {"for.w", s_mri_for, 'w'},
590 {"for.l", s_mri_for, 'l'},
591 {"endf", s_mri_endf, 0},
592 {"repeat", s_mri_repeat, 0},
593 {"until", s_mri_until, 0},
594 {"until.b", s_mri_until, 'b'},
595 {"until.w", s_mri_until, 'w'},
596 {"until.l", s_mri_until, 'l'},
597 {"while", s_mri_while, 0},
598 {"while.b", s_mri_while, 'b'},
599 {"while.w", s_mri_while, 'w'},
600 {"while.l", s_mri_while, 'l'},
601 {"endw", s_mri_endw, 0},
606 /* The mote pseudo ops are put into the opcode table, since they
607 don't start with a . they look like opcodes to gas.
611 extern void obj_coff_section PARAMS ((int));
614 CONST pseudo_typeS mote_pseudo_table[] =
627 {"xdef", s_globl, 0},
629 {"align", s_align_bytes, 0},
631 {"align", s_align_ptwo, 0},
634 {"sect", obj_coff_section, 0},
635 {"section", obj_coff_section, 0},
640 #define issbyte(x) ((x)>=-128 && (x)<=127)
641 #define isubyte(x) ((x)>=0 && (x)<=255)
642 #define issword(x) ((x)>=-32768 && (x)<=32767)
643 #define isuword(x) ((x)>=0 && (x)<=65535)
645 #define isbyte(x) ((x)>= -255 && (x)<=255)
646 #define isword(x) ((x)>=-65536 && (x)<=65535)
647 #define islong(x) (1)
649 extern char *input_line_pointer;
651 static char notend_table[256];
652 static char alt_notend_table[256];
654 (! (notend_table[(unsigned char) *s] \
656 && alt_notend_table[(unsigned char) s[1]])))
658 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
660 #ifdef NO_PCREL_RELOCS
663 make_pcrel_absolute(fixP, add_number)
667 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
669 /* rewrite the PC relative instructions to absolute address ones.
670 * these are rumoured to be faster, and the apollo linker refuses
671 * to deal with the PC relative relocations.
673 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
678 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
684 as_fatal (_("Unknown PC relative instruction"));
689 #endif /* NO_PCREL_RELOCS */
692 tc_coff_fix2rtype (fixP)
695 if (fixP->fx_tcbit && fixP->fx_size == 4)
696 return R_RELLONG_NEG;
697 #ifdef NO_PCREL_RELOCS
698 know (fixP->fx_pcrel == 0);
699 return (fixP->fx_size == 1 ? R_RELBYTE
700 : fixP->fx_size == 2 ? R_DIR16
703 return (fixP->fx_pcrel ?
704 (fixP->fx_size == 1 ? R_PCRBYTE :
705 fixP->fx_size == 2 ? R_PCRWORD :
707 (fixP->fx_size == 1 ? R_RELBYTE :
708 fixP->fx_size == 2 ? R_RELWORD :
717 /* Return zero if the reference to SYMBOL from within the same segment may
720 /* On an ELF system, we can't relax an externally visible symbol,
721 because it may be overridden by a shared library. However, if
722 TARGET_OS is "elf", then we presume that we are assembling for an
723 embedded system, in which case we don't have to worry about shared
724 libraries, and we can relax any external sym. */
726 #define relaxable_symbol(symbol) \
727 (!((S_IS_EXTERNAL (symbol) && strcmp (TARGET_OS, "elf") != 0) \
728 || S_IS_WEAK (symbol)))
730 /* Compute the relocation code for a fixup of SIZE bytes, using pc
731 relative relocation if PCREL is non-zero. PIC says whether a special
732 pic relocation was requested. */
734 static bfd_reloc_code_real_type get_reloc_code
735 PARAMS ((int, int, enum pic_relocation));
737 static bfd_reloc_code_real_type
738 get_reloc_code (size, pcrel, pic)
741 enum pic_relocation pic;
749 return BFD_RELOC_8_GOT_PCREL;
751 return BFD_RELOC_16_GOT_PCREL;
753 return BFD_RELOC_32_GOT_PCREL;
761 return BFD_RELOC_8_GOTOFF;
763 return BFD_RELOC_16_GOTOFF;
765 return BFD_RELOC_32_GOTOFF;
773 return BFD_RELOC_8_PLT_PCREL;
775 return BFD_RELOC_16_PLT_PCREL;
777 return BFD_RELOC_32_PLT_PCREL;
785 return BFD_RELOC_8_PLTOFF;
787 return BFD_RELOC_16_PLTOFF;
789 return BFD_RELOC_32_PLTOFF;
799 return BFD_RELOC_8_PCREL;
801 return BFD_RELOC_16_PCREL;
803 return BFD_RELOC_32_PCREL;
823 as_bad (_("Can not do %d byte pc-relative relocation"), size);
825 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
830 as_bad (_("Can not do %d byte relocation"), size);
832 as_bad (_("Can not do %d byte pic relocation"), size);
835 return BFD_RELOC_NONE;
838 /* Here we decide which fixups can be adjusted to make them relative
839 to the beginning of the section instead of the symbol. Basically
840 we need to make sure that the dynamic relocations are done
841 correctly, so in some cases we force the original symbol to be
844 tc_m68k_fix_adjustable (fixP)
847 /* Prevent all adjustments to global symbols. */
848 if (! relaxable_symbol (fixP->fx_addsy))
851 /* adjust_reloc_syms doesn't know about the GOT */
852 switch (fixP->fx_r_type)
854 case BFD_RELOC_8_GOT_PCREL:
855 case BFD_RELOC_16_GOT_PCREL:
856 case BFD_RELOC_32_GOT_PCREL:
857 case BFD_RELOC_8_GOTOFF:
858 case BFD_RELOC_16_GOTOFF:
859 case BFD_RELOC_32_GOTOFF:
860 case BFD_RELOC_8_PLT_PCREL:
861 case BFD_RELOC_16_PLT_PCREL:
862 case BFD_RELOC_32_PLT_PCREL:
863 case BFD_RELOC_8_PLTOFF:
864 case BFD_RELOC_16_PLTOFF:
865 case BFD_RELOC_32_PLTOFF:
868 case BFD_RELOC_VTABLE_INHERIT:
869 case BFD_RELOC_VTABLE_ENTRY:
879 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
881 #define relaxable_symbol(symbol) 1
888 tc_gen_reloc (section, fixp)
893 bfd_reloc_code_real_type code;
895 /* If the tcbit is set, then this was a fixup of a negative value
896 that was never resolved. We do not have a reloc to handle this,
897 so just return. We assume that other code will have detected this
898 situation and produced a helpful error message, so we just tell the
899 user that the reloc cannot be produced. */
903 as_bad_where (fixp->fx_file, fixp->fx_line,
904 _("Unable to produce reloc against symbol '%s'"),
905 S_GET_NAME (fixp->fx_addsy));
909 if (fixp->fx_r_type != BFD_RELOC_NONE)
911 code = fixp->fx_r_type;
913 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
914 that fixup_segment converted a non-PC relative reloc into a
915 PC relative reloc. In such a case, we need to convert the
922 code = BFD_RELOC_8_PCREL;
925 code = BFD_RELOC_16_PCREL;
928 code = BFD_RELOC_32_PCREL;
930 case BFD_RELOC_8_PCREL:
931 case BFD_RELOC_16_PCREL:
932 case BFD_RELOC_32_PCREL:
933 case BFD_RELOC_8_GOT_PCREL:
934 case BFD_RELOC_16_GOT_PCREL:
935 case BFD_RELOC_32_GOT_PCREL:
936 case BFD_RELOC_8_GOTOFF:
937 case BFD_RELOC_16_GOTOFF:
938 case BFD_RELOC_32_GOTOFF:
939 case BFD_RELOC_8_PLT_PCREL:
940 case BFD_RELOC_16_PLT_PCREL:
941 case BFD_RELOC_32_PLT_PCREL:
942 case BFD_RELOC_8_PLTOFF:
943 case BFD_RELOC_16_PLTOFF:
944 case BFD_RELOC_32_PLTOFF:
947 as_bad_where (fixp->fx_file, fixp->fx_line,
948 _("Cannot make %s relocation PC relative"),
949 bfd_get_reloc_code_name (code));
955 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
956 switch (F (fixp->fx_size, fixp->fx_pcrel))
958 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
959 MAP (1, 0, BFD_RELOC_8);
960 MAP (2, 0, BFD_RELOC_16);
961 MAP (4, 0, BFD_RELOC_32);
962 MAP (1, 1, BFD_RELOC_8_PCREL);
963 MAP (2, 1, BFD_RELOC_16_PCREL);
964 MAP (4, 1, BFD_RELOC_32_PCREL);
972 reloc = (arelent *) xmalloc (sizeof (arelent));
973 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
974 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
975 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
978 reloc->addend = fixp->fx_addnumber;
983 reloc->addend = fixp->fx_addnumber;
985 reloc->addend = (section->vma
986 /* Explicit sign extension in case char is
988 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
990 + md_pcrel_from (fixp));
993 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
994 assert (reloc->howto != 0);
999 #endif /* BFD_ASSEMBLER */
1001 /* Handle of the OPCODE hash table. NULL means any use before
1002 m68k_ip_begin() will crash. */
1003 static struct hash_control *op_hash;
1005 /* Assemble an m68k instruction. */
1012 register struct m68k_op *opP;
1013 register const struct m68k_incant *opcode;
1014 register const char *s;
1015 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1016 char *pdot, *pdotmove;
1017 enum m68k_size siz1, siz2;
1021 LITTLENUM_TYPE words[6];
1022 LITTLENUM_TYPE *wordp;
1023 unsigned long ok_arch = 0;
1025 if (*instring == ' ')
1026 instring++; /* skip leading whitespace */
1028 /* Scan up to end of operation-code, which MUST end in end-of-string
1029 or exactly 1 space. */
1031 for (p = instring; *p != '\0'; p++)
1041 the_ins.error = _("No operator");
1045 /* p now points to the end of the opcode name, probably whitespace.
1046 Make sure the name is null terminated by clobbering the
1047 whitespace, look it up in the hash table, then fix it back.
1048 Remove a dot, first, since the opcode tables have none. */
1051 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1052 *pdotmove = pdotmove[1];
1058 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1063 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1064 *pdotmove = pdotmove[-1];
1071 the_ins.error = _("Unknown operator");
1075 /* found a legitimate opcode, start matching operands */
1079 if (opcode->m_operands == 0)
1081 char *old = input_line_pointer;
1083 input_line_pointer = p;
1084 /* Ahh - it's a motorola style psuedo op */
1085 mote_pseudo_table[opcode->m_opnum].poc_handler
1086 (mote_pseudo_table[opcode->m_opnum].poc_val);
1087 input_line_pointer = old;
1093 if (flag_mri && opcode->m_opnum == 0)
1095 /* In MRI mode, random garbage is allowed after an instruction
1096 which accepts no operands. */
1097 the_ins.args = opcode->m_operands;
1098 the_ins.numargs = opcode->m_opnum;
1099 the_ins.numo = opcode->m_codenum;
1100 the_ins.opcode[0] = getone (opcode);
1101 the_ins.opcode[1] = gettwo (opcode);
1105 for (opP = &the_ins.operands[0]; *p; opP++)
1107 p = crack_operand (p, opP);
1111 the_ins.error = opP->error;
1116 opsfound = opP - &the_ins.operands[0];
1118 /* This ugly hack is to support the floating pt opcodes in their
1119 standard form. Essentially, we fake a first enty of type COP#1 */
1120 if (opcode->m_operands[0] == 'I')
1124 for (n = opsfound; n > 0; --n)
1125 the_ins.operands[n] = the_ins.operands[n - 1];
1127 memset ((char *) (&the_ins.operands[0]), '\0',
1128 sizeof (the_ins.operands[0]));
1129 the_ins.operands[0].mode = CONTROL;
1130 the_ins.operands[0].reg = m68k_float_copnum;
1134 /* We've got the operands. Find an opcode that'll accept them */
1137 /* If we didn't get the right number of ops, or we have no
1138 common model with this pattern then reject this pattern. */
1140 ok_arch |= opcode->m_arch;
1141 if (opsfound != opcode->m_opnum
1142 || ((opcode->m_arch & current_architecture) == 0))
1146 for (s = opcode->m_operands, opP = &the_ins.operands[0];
1150 /* Warning: this switch is huge! */
1151 /* I've tried to organize the cases into this order:
1152 non-alpha first, then alpha by letter. Lower-case
1153 goes directly before uppercase counterpart. */
1154 /* Code with multiple case ...: gets sorted by the lowest
1155 case ... it belongs to. I hope this makes sense. */
1261 if (opP->reg == PC || opP->reg == ZPC)
1278 if (opP->reg == PC || opP->reg == ZPC)
1297 if (opP->reg == PC || opP->reg == ZPC)
1307 if (opP->mode != IMMED)
1309 else if (s[1] == 'b'
1310 && ! isvar (&opP->disp)
1311 && (opP->disp.exp.X_op != O_constant
1312 || ! isbyte (opP->disp.exp.X_add_number)))
1314 else if (s[1] == 'B'
1315 && ! isvar (&opP->disp)
1316 && (opP->disp.exp.X_op != O_constant
1317 || ! issbyte (opP->disp.exp.X_add_number)))
1319 else if (s[1] == 'w'
1320 && ! isvar (&opP->disp)
1321 && (opP->disp.exp.X_op != O_constant
1322 || ! isword (opP->disp.exp.X_add_number)))
1324 else if (s[1] == 'W'
1325 && ! isvar (&opP->disp)
1326 && (opP->disp.exp.X_op != O_constant
1327 || ! issword (opP->disp.exp.X_add_number)))
1333 if (opP->mode != IMMED)
1338 if (opP->mode == AREG
1339 || opP->mode == CONTROL
1340 || opP->mode == FPREG
1341 || opP->mode == IMMED
1342 || opP->mode == REGLST
1343 || (opP->mode != ABSL
1345 || opP->reg == ZPC)))
1350 if (opP->mode == CONTROL
1351 || opP->mode == FPREG
1352 || opP->mode == REGLST
1353 || opP->mode == IMMED
1354 || (opP->mode != ABSL
1356 || opP->reg == ZPC)))
1384 if (opP->mode == CONTROL
1385 || opP->mode == FPREG
1386 || opP->mode == REGLST)
1391 if (opP->mode != AINC)
1396 if (opP->mode != ADEC)
1446 if (opP->reg == PC || opP->reg == ZPC)
1467 case '~': /* For now! (JF FOO is this right?) */
1489 if (opP->mode != CONTROL
1490 || (opP->reg != TT0 && opP->reg != TT1))
1495 if (opP->mode != AREG)
1500 if (opP->mode != AINDR)
1505 if (opP->mode != ABSL
1507 && strncmp (instring, "jbsr", 4) == 0))
1512 if (opP->mode != CONTROL || opP->reg != CCR)
1517 if (opP->mode != DISP
1519 || opP->reg > ADDR7)
1524 if (opP->mode != DREG)
1529 if (opP->reg != ACC)
1534 if (opP->mode != FPREG)
1539 if (opP->reg != MACSR)
1544 if (opP->reg != MASK)
1549 if (opP->mode != CONTROL
1556 if (opP->mode != CONTROL
1558 || opP->reg > last_movec_reg)
1562 const enum m68k_register *rp;
1563 for (rp = control_regs; *rp; rp++)
1564 if (*rp == opP->reg)
1572 if (opP->mode != IMMED)
1578 if (opP->mode == DREG
1579 || opP->mode == AREG
1580 || opP->mode == FPREG)
1589 opP->mask = 1 << (opP->reg - DATA0);
1592 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1595 opP->mask = 1 << (opP->reg - FP0 + 16);
1603 else if (opP->mode == CONTROL)
1612 opP->mask = 1 << 24;
1615 opP->mask = 1 << 25;
1618 opP->mask = 1 << 26;
1627 else if (opP->mode != REGLST)
1629 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1631 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1636 if (opP->mode != IMMED)
1638 else if (opP->disp.exp.X_op != O_constant
1639 || ! issbyte (opP->disp.exp.X_add_number))
1641 else if (! m68k_quick
1642 && instring[3] != 'q'
1643 && instring[4] != 'q')
1648 if (opP->mode != DREG
1649 && opP->mode != IMMED
1650 && opP->mode != ABSL)
1655 if (opP->mode != IMMED)
1657 else if (opP->disp.exp.X_op != O_constant
1658 || opP->disp.exp.X_add_number < 1
1659 || opP->disp.exp.X_add_number > 8)
1661 else if (! m68k_quick
1662 && (strncmp (instring, "add", 3) == 0
1663 || strncmp (instring, "sub", 3) == 0)
1664 && instring[3] != 'q')
1669 if (opP->mode != DREG && opP->mode != AREG)
1674 if (opP->mode != AINDR
1675 && (opP->mode != BASE
1677 && opP->reg != ZADDR0)
1678 || opP->disp.exp.X_op != O_absent
1679 || ((opP->index.reg < DATA0
1680 || opP->index.reg > DATA7)
1681 && (opP->index.reg < ADDR0
1682 || opP->index.reg > ADDR7))
1683 || opP->index.size != SIZE_UNSPEC
1684 || opP->index.scale != 1))
1689 if (opP->mode != CONTROL
1690 || ! (opP->reg == FPI
1692 || opP->reg == FPC))
1697 if (opP->mode != CONTROL || opP->reg != SR)
1702 if (opP->mode != IMMED)
1704 else if (opP->disp.exp.X_op != O_constant
1705 || opP->disp.exp.X_add_number < 0
1706 || opP->disp.exp.X_add_number > 7)
1711 if (opP->mode != CONTROL || opP->reg != USP)
1715 /* JF these are out of order. We could put them
1716 in order if we were willing to put up with
1717 bunches of #ifdef m68851s in the code.
1719 Don't forget that you need these operands
1720 to use 68030 MMU instructions. */
1722 /* Memory addressing mode used by pflushr */
1724 if (opP->mode == CONTROL
1725 || opP->mode == FPREG
1726 || opP->mode == DREG
1727 || opP->mode == AREG
1728 || opP->mode == REGLST)
1730 /* We should accept immediate operands, but they
1731 supposedly have to be quad word, and we don't
1732 handle that. I would like to see what a Motorola
1733 assembler does before doing something here. */
1734 if (opP->mode == IMMED)
1739 if (opP->mode != CONTROL
1740 || (opP->reg != SFC && opP->reg != DFC))
1745 if (opP->mode != CONTROL || opP->reg != TC)
1750 if (opP->mode != CONTROL || opP->reg != AC)
1755 if (opP->mode != CONTROL
1758 && opP->reg != SCC))
1763 if (opP->mode != CONTROL
1769 if (opP->mode != CONTROL
1772 && opP->reg != CRP))
1777 if (opP->mode != CONTROL
1778 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1779 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1784 if (opP->mode != CONTROL || opP->reg != PSR)
1789 if (opP->mode != CONTROL || opP->reg != PCSR)
1794 if (opP->mode != CONTROL
1801 } /* not a cache specifier. */
1805 if (opP->mode != ABSL)
1810 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1812 /* FIXME: kludge instead of fixing parser:
1813 upper/lower registers are *not* CONTROL
1814 registers, but ordinary ones. */
1815 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1816 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1824 } /* switch on type of operand */
1828 } /* for each operand */
1829 } /* if immediately wrong */
1836 opcode = opcode->m_next;
1841 && !(ok_arch & current_architecture))
1846 _("invalid instruction for this architecture; needs "));
1847 cp = buf + strlen (buf);
1851 strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
1854 strcpy (cp, _("mmu (68030 or 68851)"));
1857 strcpy (cp, _("68020 or higher"));
1860 strcpy (cp, _("68000 or higher"));
1863 strcpy (cp, _("68010 or higher"));
1867 int got_one = 0, idx;
1869 idx < (int) (sizeof (archs) / sizeof (archs[0]));
1872 if ((archs[idx].arch & ok_arch)
1873 && ! archs[idx].alias)
1877 strcpy (cp, " or ");
1881 strcpy (cp, archs[idx].name);
1887 cp = xmalloc (strlen (buf) + 1);
1892 the_ins.error = _("operands mismatch");
1894 } /* Fell off the end */
1899 /* now assemble it */
1901 the_ins.args = opcode->m_operands;
1902 the_ins.numargs = opcode->m_opnum;
1903 the_ins.numo = opcode->m_codenum;
1904 the_ins.opcode[0] = getone (opcode);
1905 the_ins.opcode[1] = gettwo (opcode);
1907 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
1909 /* This switch is a doozy.
1910 Watch the first step; its a big one! */
1938 tmpreg = 0x3c; /* 7.4 */
1939 if (strchr ("bwl", s[1]))
1940 nextword = get_num (&opP->disp, 80);
1942 nextword = get_num (&opP->disp, 0);
1943 if (isvar (&opP->disp))
1944 add_fix (s[1], &opP->disp, 0, 0);
1948 if (!isbyte (nextword))
1949 opP->error = _("operand out of range");
1954 if (!isword (nextword))
1955 opP->error = _("operand out of range");
1960 if (!issword (nextword))
1961 opP->error = _("operand out of range");
1966 addword (nextword >> 16);
1993 /* We gotta put out some float */
1994 if (op (&opP->disp) != O_big)
1999 /* Can other cases happen here? */
2000 if (op (&opP->disp) != O_constant)
2003 val = (valueT) offs (&opP->disp);
2007 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2008 val >>= LITTLENUM_NUMBER_OF_BITS;
2012 offs (&opP->disp) = gencnt;
2014 if (offs (&opP->disp) > 0)
2016 if (offs (&opP->disp) > baseo)
2018 as_warn (_("Bignum too big for %c format; truncated"),
2020 offs (&opP->disp) = baseo;
2022 baseo -= offs (&opP->disp);
2025 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2026 offs (&opP->disp)--;
2031 gen_to_words (words, baseo, (long) outro);
2032 for (wordp = words; baseo--; wordp++)
2036 tmpreg = opP->reg - DATA; /* 0.dreg */
2039 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2042 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2045 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2048 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2052 nextword = get_num (&opP->disp, 80);
2055 && ! isvar (&opP->disp)
2058 opP->disp.exp.X_op = O_symbol;
2059 #ifndef BFD_ASSEMBLER
2060 opP->disp.exp.X_add_symbol = &abs_symbol;
2062 opP->disp.exp.X_add_symbol =
2063 section_symbol (absolute_section);
2067 /* Force into index mode. Hope this works */
2069 /* We do the first bit for 32-bit displacements, and the
2070 second bit for 16 bit ones. It is possible that we
2071 should make the default be WORD instead of LONG, but
2072 I think that'd break GCC, so we put up with a little
2073 inefficiency for the sake of working output. */
2075 if (!issword (nextword)
2076 || (isvar (&opP->disp)
2077 && ((opP->disp.size == SIZE_UNSPEC
2078 && flag_short_refs == 0
2079 && cpu_of_arch (current_architecture) >= m68020
2080 && ! arch_coldfire_p (current_architecture))
2081 || opP->disp.size == SIZE_LONG)))
2083 if (cpu_of_arch (current_architecture) < m68020
2084 || arch_coldfire_p (current_architecture))
2086 _("displacement too large for this architecture; needs 68020 or higher");
2088 tmpreg = 0x3B; /* 7.3 */
2090 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2091 if (isvar (&opP->disp))
2095 if (opP->disp.size == SIZE_LONG
2097 /* If the displacement needs pic
2098 relocation it cannot be relaxed. */
2099 || opP->disp.pic_reloc != pic_none
2104 add_fix ('l', &opP->disp, 1, 2);
2108 add_frag (adds (&opP->disp),
2110 TAB (PCREL1632, SZ_UNDEF));
2117 add_fix ('l', &opP->disp, 0, 0);
2122 addword (nextword >> 16);
2127 tmpreg = 0x3A; /* 7.2 */
2129 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2131 if (isvar (&opP->disp))
2135 add_fix ('w', &opP->disp, 1, 0);
2138 add_fix ('w', &opP->disp, 0, 0);
2148 baseo = get_num (&opP->disp, 80);
2149 if (opP->mode == POST || opP->mode == PRE)
2150 outro = get_num (&opP->odisp, 80);
2151 /* Figure out the `addressing mode'.
2152 Also turn on the BASE_DISABLE bit, if needed. */
2153 if (opP->reg == PC || opP->reg == ZPC)
2155 tmpreg = 0x3b; /* 7.3 */
2156 if (opP->reg == ZPC)
2159 else if (opP->reg == 0)
2162 tmpreg = 0x30; /* 6.garbage */
2164 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2167 tmpreg = 0x30 + opP->reg - ZADDR0;
2170 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2172 siz1 = opP->disp.size;
2173 if (opP->mode == POST || opP->mode == PRE)
2174 siz2 = opP->odisp.size;
2178 /* Index register stuff */
2179 if (opP->index.reg != 0
2180 && opP->index.reg >= DATA
2181 && opP->index.reg <= ADDR7)
2183 nextword |= (opP->index.reg - DATA) << 12;
2185 if (opP->index.size == SIZE_LONG
2186 || (opP->index.size == SIZE_UNSPEC
2187 && m68k_index_width_default == SIZE_LONG))
2190 if ((opP->index.scale != 1
2191 && cpu_of_arch (current_architecture) < m68020)
2192 || (opP->index.scale == 8
2193 && arch_coldfire_p (current_architecture)))
2196 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2199 if (arch_coldfire_p (current_architecture)
2200 && opP->index.size == SIZE_WORD)
2201 opP->error = _("invalid index size for coldfire");
2203 switch (opP->index.scale)
2220 GET US OUT OF HERE! */
2222 /* Must be INDEX, with an index register. Address
2223 register cannot be ZERO-PC, and either :b was
2224 forced, or we know it will fit. For a 68000 or
2225 68010, force this mode anyways, because the
2226 larger modes aren't supported. */
2227 if (opP->mode == BASE
2228 && ((opP->reg >= ADDR0
2229 && opP->reg <= ADDR7)
2232 if (siz1 == SIZE_BYTE
2233 || cpu_of_arch (current_architecture) < m68020
2234 || arch_coldfire_p (current_architecture)
2235 || (siz1 == SIZE_UNSPEC
2236 && ! isvar (&opP->disp)
2237 && issbyte (baseo)))
2239 nextword += baseo & 0xff;
2241 if (isvar (&opP->disp))
2243 /* Do a byte relocation. If it doesn't
2244 fit (possible on m68000) let the
2245 fixup processing complain later. */
2247 add_fix ('B', &opP->disp, 1, 1);
2249 add_fix ('B', &opP->disp, 0, 0);
2251 else if (siz1 != SIZE_BYTE)
2253 if (siz1 != SIZE_UNSPEC)
2254 as_warn (_("Forcing byte displacement"));
2255 if (! issbyte (baseo))
2256 opP->error = _("byte displacement out of range");
2261 else if (siz1 == SIZE_UNSPEC
2263 && isvar (&opP->disp)
2264 && subs (&opP->disp) == NULL
2266 /* If the displacement needs pic
2267 relocation it cannot be relaxed. */
2268 && opP->disp.pic_reloc == pic_none
2272 /* The code in md_convert_frag_1 needs to be
2273 able to adjust nextword. Call frag_grow
2274 to ensure that we have enough space in
2275 the frag obstack to make all the bytes
2278 nextword += baseo & 0xff;
2280 add_frag (adds (&opP->disp), offs (&opP->disp),
2281 TAB (PCINDEX, SZ_UNDEF));
2289 nextword |= 0x40; /* No index reg */
2290 if (opP->index.reg >= ZDATA0
2291 && opP->index.reg <= ZDATA7)
2292 nextword |= (opP->index.reg - ZDATA0) << 12;
2293 else if (opP->index.reg >= ZADDR0
2294 || opP->index.reg <= ZADDR7)
2295 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2298 /* It isn't simple. */
2300 if (cpu_of_arch (current_architecture) < m68020
2301 || arch_coldfire_p (current_architecture))
2303 _("invalid operand mode for this architecture; needs 68020 or higher");
2306 /* If the guy specified a width, we assume that it is
2307 wide enough. Maybe it isn't. If so, we lose. */
2311 if (isvar (&opP->disp)
2313 : ! issword (baseo))
2318 else if (! isvar (&opP->disp) && baseo == 0)
2327 as_warn (_(":b not permitted; defaulting to :w"));
2337 /* Figure out innner displacement stuff */
2338 if (opP->mode == POST || opP->mode == PRE)
2340 if (cpu_of_arch (current_architecture) & cpu32)
2341 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2345 if (isvar (&opP->odisp)
2347 : ! issword (outro))
2352 else if (! isvar (&opP->odisp) && outro == 0)
2361 as_warn (_(":b not permitted; defaulting to :w"));
2370 if (opP->mode == POST
2371 && (nextword & 0x40) == 0)
2376 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2378 if (opP->reg == PC || opP->reg == ZPC)
2379 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2381 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2383 if (siz1 == SIZE_LONG)
2384 addword (baseo >> 16);
2385 if (siz1 != SIZE_UNSPEC)
2388 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2389 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2390 if (siz2 == SIZE_LONG)
2391 addword (outro >> 16);
2392 if (siz2 != SIZE_UNSPEC)
2398 nextword = get_num (&opP->disp, 80);
2399 switch (opP->disp.size)
2404 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2406 tmpreg = 0x38; /* 7.0 */
2410 if (isvar (&opP->disp)
2411 && !subs (&opP->disp)
2412 && adds (&opP->disp)
2414 /* If the displacement needs pic relocation it
2415 cannot be relaxed. */
2416 && opP->disp.pic_reloc == pic_none
2419 && !strchr ("~%&$?", s[0]))
2421 tmpreg = 0x3A; /* 7.2 */
2422 add_frag (adds (&opP->disp),
2424 TAB (ABSTOPCREL, SZ_UNDEF));
2427 /* Fall through into long */
2429 if (isvar (&opP->disp))
2430 add_fix ('l', &opP->disp, 0, 0);
2432 tmpreg = 0x39;/* 7.1 mode */
2433 addword (nextword >> 16);
2438 as_bad (_("unsupported byte value; use a different suffix"));
2440 case SIZE_WORD: /* Word */
2441 if (isvar (&opP->disp))
2442 add_fix ('w', &opP->disp, 0, 0);
2444 tmpreg = 0x38;/* 7.0 mode */
2452 as_bad (_("unknown/incorrect operand"));
2455 install_gen_operand (s[1], tmpreg);
2461 { /* JF: I hate floating point! */
2476 tmpreg = get_num (&opP->disp, tmpreg);
2477 if (isvar (&opP->disp))
2478 add_fix (s[1], &opP->disp, 0, 0);
2481 case 'b': /* Danger: These do no check for
2482 certain types of overflow.
2484 if (!isbyte (tmpreg))
2485 opP->error = _("out of range");
2486 insop (tmpreg, opcode);
2487 if (isvar (&opP->disp))
2488 the_ins.reloc[the_ins.nrel - 1].n =
2489 (opcode->m_codenum) * 2 + 1;
2492 if (!issbyte (tmpreg))
2493 opP->error = _("out of range");
2494 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2495 if (isvar (&opP->disp))
2496 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2499 if (!isword (tmpreg))
2500 opP->error = _("out of range");
2501 insop (tmpreg, opcode);
2502 if (isvar (&opP->disp))
2503 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2506 if (!issword (tmpreg))
2507 opP->error = _("out of range");
2508 insop (tmpreg, opcode);
2509 if (isvar (&opP->disp))
2510 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2513 /* Because of the way insop works, we put these two out
2515 insop (tmpreg, opcode);
2516 insop (tmpreg >> 16, opcode);
2517 if (isvar (&opP->disp))
2518 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2525 install_operand (s[1], tmpreg);
2536 install_operand (s[1], opP->reg - ADDR);
2540 tmpreg = get_num (&opP->disp, 80);
2544 add_fix ('B', &opP->disp, 1, -1);
2547 add_fix ('w', &opP->disp, 1, 0);
2552 if (! HAVE_LONG_BRANCH (current_architecture))
2553 as_warn (_("Can't use long branches on 68000/68010/5200"));
2554 the_ins.opcode[0] |= 0xff;
2555 add_fix ('l', &opP->disp, 1, 0);
2560 if (subs (&opP->disp)) /* We can't relax it */
2564 /* If the displacement needs pic relocation it cannot be
2566 if (opP->disp.pic_reloc != pic_none)
2569 /* This could either be a symbol, or an absolute
2570 address. If it's an absolute address, turn it into
2571 an absolute jump right here and keep it out of the
2573 if (adds (&opP->disp) == 0)
2575 if (the_ins.opcode[0] == 0x6000) /* jbra */
2576 the_ins.opcode[0] = 0x4EF1;
2577 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2578 the_ins.opcode[0] = 0x4EB1;
2581 the_ins.opcode[0] ^= 0x0100;
2582 the_ins.opcode[0] |= 0x0006;
2585 add_fix ('l', &opP->disp, 0, 0);
2591 /* Now we know it's going into the relaxer. Now figure
2592 out which mode. We try in this order of preference:
2593 long branch, absolute jump, byte/word branches only. */
2594 if (HAVE_LONG_BRANCH (current_architecture))
2595 add_frag (adds (&opP->disp), offs (&opP->disp),
2596 TAB (BRANCHBWL, SZ_UNDEF));
2597 else if (! flag_keep_pcrel)
2599 if ((the_ins.opcode[0] == 0x6000)
2600 || (the_ins.opcode[0] == 0x6100))
2601 add_frag (adds (&opP->disp), offs (&opP->disp),
2602 TAB (BRABSJUNC, SZ_UNDEF));
2604 add_frag (adds (&opP->disp), offs (&opP->disp),
2605 TAB (BRABSJCOND, SZ_UNDEF));
2608 add_frag (adds (&opP->disp), offs (&opP->disp),
2609 TAB (BRANCHBW, SZ_UNDEF));
2612 if (isvar (&opP->disp))
2614 /* Check for DBcc instructions. We can relax them,
2615 but only if we have long branches and/or absolute
2617 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2618 && (HAVE_LONG_BRANCH (current_architecture)
2619 || (! flag_keep_pcrel)))
2621 if (HAVE_LONG_BRANCH (current_architecture))
2622 add_frag (adds (&opP->disp), offs (&opP->disp),
2623 TAB (DBCCLBR, SZ_UNDEF));
2625 add_frag (adds (&opP->disp), offs (&opP->disp),
2626 TAB (DBCCABSJ, SZ_UNDEF));
2629 add_fix ('w', &opP->disp, 1, 0);
2633 case 'C': /* Fixed size LONG coproc branches */
2634 add_fix ('l', &opP->disp, 1, 0);
2638 case 'c': /* Var size Coprocesssor branches */
2639 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
2641 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2642 add_fix ('l', &opP->disp, 1, 0);
2647 add_frag (adds (&opP->disp), offs (&opP->disp),
2648 TAB (FBRANCH, SZ_UNDEF));
2655 case 'C': /* Ignore it */
2658 case 'd': /* JF this is a kludge */
2659 install_operand ('s', opP->reg - ADDR);
2660 tmpreg = get_num (&opP->disp, 80);
2661 if (!issword (tmpreg))
2663 as_warn (_("Expression out of range, using 0"));
2670 install_operand (s[1], opP->reg - DATA);
2673 case 'E': /* Ignore it */
2677 install_operand (s[1], opP->reg - FP0);
2680 case 'G': /* Ignore it */
2685 tmpreg = opP->reg - COP0;
2686 install_operand (s[1], tmpreg);
2689 case 'J': /* JF foo */
2762 install_operand (s[1], tmpreg);
2766 tmpreg = get_num (&opP->disp, 55);
2767 install_operand (s[1], tmpreg & 0x7f);
2774 if (tmpreg & 0x7FF0000)
2775 as_bad (_("Floating point register in register list"));
2776 insop (reverse_16_bits (tmpreg), opcode);
2780 if (tmpreg & 0x700FFFF)
2781 as_bad (_("Wrong register in floating-point reglist"));
2782 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
2790 if (tmpreg & 0x7FF0000)
2791 as_bad (_("Floating point register in register list"));
2792 insop (tmpreg, opcode);
2794 else if (s[1] == '8')
2796 if (tmpreg & 0x0FFFFFF)
2797 as_bad (_("incorrect register in reglist"));
2798 install_operand (s[1], tmpreg >> 24);
2802 if (tmpreg & 0x700FFFF)
2803 as_bad (_("wrong register in floating-point reglist"));
2805 install_operand (s[1], tmpreg >> 16);
2810 install_operand (s[1], get_num (&opP->disp, 60));
2814 tmpreg = ((opP->mode == DREG)
2815 ? 0x20 + (int) (opP->reg - DATA)
2816 : (get_num (&opP->disp, 40) & 0x1F));
2817 install_operand (s[1], tmpreg);
2821 tmpreg = get_num (&opP->disp, 10);
2824 install_operand (s[1], tmpreg);
2828 /* This depends on the fact that ADDR registers are eight
2829 more than their corresponding DATA regs, so the result
2830 will have the ADDR_REG bit set */
2831 install_operand (s[1], opP->reg - DATA);
2835 if (opP->mode == AINDR)
2836 install_operand (s[1], opP->reg - DATA);
2838 install_operand (s[1], opP->index.reg - DATA);
2842 if (opP->reg == FPI)
2844 else if (opP->reg == FPS)
2846 else if (opP->reg == FPC)
2850 install_operand (s[1], tmpreg);
2853 case 'S': /* Ignore it */
2857 install_operand (s[1], get_num (&opP->disp, 30));
2860 case 'U': /* Ignore it */
2879 as_fatal (_("failed sanity check"));
2880 } /* switch on cache token */
2881 install_operand (s[1], tmpreg);
2884 /* JF: These are out of order, I fear. */
2897 install_operand (s[1], tmpreg);
2923 install_operand (s[1], tmpreg);
2927 if (opP->reg == VAL)
2946 install_operand (s[1], tmpreg);
2960 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2971 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2977 install_operand (s[1], tmpreg);
2980 know (opP->reg == PSR);
2983 know (opP->reg == PCSR);
2998 install_operand (s[1], tmpreg);
3001 tmpreg = get_num (&opP->disp, 20);
3002 install_operand (s[1], tmpreg);
3004 case '_': /* used only for move16 absolute 32-bit address */
3005 if (isvar (&opP->disp))
3006 add_fix ('l', &opP->disp, 0, 0);
3007 tmpreg = get_num (&opP->disp, 80);
3008 addword (tmpreg >> 16);
3009 addword (tmpreg & 0xFFFF);
3012 install_operand (s[1], opP->reg - DATA0L);
3013 opP->reg -= (DATA0L);
3014 opP->reg &= 0x0F; /* remove upper/lower bit */
3021 /* By the time whe get here (FINALLY) the_ins contains the complete
3022 instruction, ready to be emitted. . . */
3026 reverse_16_bits (in)
3032 static int mask[16] =
3034 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3035 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3037 for (n = 0; n < 16; n++)
3040 out |= mask[15 - n];
3043 } /* reverse_16_bits() */
3052 static int mask[8] =
3054 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3057 for (n = 0; n < 8; n++)
3063 } /* reverse_8_bits() */
3065 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3066 (that value is chosen in the frag_var call in md_assemble). TYPE
3067 is the subtype of the frag to be generated; its primary type is
3068 rs_machine_dependent.
3070 The TYPE parameter is also used by md_convert_frag_1 and
3071 md_estimate_size_before_relax. The appropriate type of fixup will
3072 be emitted by md_convert_frag_1.
3074 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3076 install_operand (mode, val)
3083 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge */
3086 the_ins.opcode[0] |= val << 9;
3089 the_ins.opcode[1] |= val << 12;
3092 the_ins.opcode[1] |= val << 6;
3095 the_ins.opcode[1] |= val;
3098 the_ins.opcode[2] |= val << 12;
3101 the_ins.opcode[2] |= val << 6;
3104 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3105 three words long! */
3107 the_ins.opcode[2] |= val;
3110 the_ins.opcode[1] |= val << 7;
3113 the_ins.opcode[1] |= val << 10;
3117 the_ins.opcode[1] |= val << 5;
3122 the_ins.opcode[1] |= (val << 10) | (val << 7);
3125 the_ins.opcode[1] |= (val << 12) | val;
3128 the_ins.opcode[0] |= val = 0xff;
3131 the_ins.opcode[0] |= val << 9;
3134 the_ins.opcode[1] |= val;
3137 the_ins.opcode[1] |= val;
3138 the_ins.numo++; /* What a hack */
3141 the_ins.opcode[1] |= val << 4;
3149 the_ins.opcode[0] |= (val << 6);
3152 the_ins.opcode[1] = (val >> 16);
3153 the_ins.opcode[2] = val & 0xffff;
3156 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3157 the_ins.opcode[0] |= ((val & 0x7) << 9);
3158 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3161 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3162 the_ins.opcode[0] |= ((val & 0x7) << 9);
3165 the_ins.opcode[1] |= val << 12;
3166 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3169 the_ins.opcode[0] |= (val & 0xF);
3170 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3173 the_ins.opcode[1] |= (val & 0xF);
3174 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3177 the_ins.opcode[1] |= ((val != 1) << 10);
3181 as_fatal (_("failed sanity check."));
3183 } /* install_operand() */
3186 install_gen_operand (mode, val)
3193 the_ins.opcode[0] |= val;
3196 /* This is a kludge!!! */
3197 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3206 the_ins.opcode[0] |= val;
3208 /* more stuff goes here */
3210 as_fatal (_("failed sanity check."));
3212 } /* install_gen_operand() */
3215 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3216 * then deal with the bitfield hack.
3220 crack_operand (str, opP)
3222 register struct m68k_op *opP;
3224 register int parens;
3226 register char *beg_str;
3234 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3240 else if (*str == ')')
3244 opP->error = _("Extra )");
3250 if (flag_mri && *str == '\'')
3251 inquote = ! inquote;
3253 if (!*str && parens)
3255 opP->error = _("Missing )");
3260 if (m68k_ip_op (beg_str, opP) != 0)
3267 c = *++str; /* JF bitfield hack */
3272 as_bad (_("Missing operand"));
3275 /* Detect MRI REG symbols and convert them to REGLSTs. */
3276 if (opP->mode == CONTROL && (int)opP->reg < 0)
3279 opP->mask = ~(int)opP->reg;
3286 /* This is the guts of the machine-dependent assembler. STR points to a
3287 machine dependent instruction. This function is supposed to emit
3288 the frags/bytes it assembles to.
3292 insert_reg (regname, regnum)
3293 const char *regname;
3299 #ifdef REGISTER_PREFIX
3300 if (!flag_reg_prefix_optional)
3302 buf[0] = REGISTER_PREFIX;
3303 strcpy (buf + 1, regname);
3308 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3309 &zero_address_frag));
3311 for (i = 0; regname[i]; i++)
3312 buf[i] = TOUPPER (regname[i]);
3315 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3316 &zero_address_frag));
3325 static const struct init_entry init_table[] =
3384 /* control registers */
3385 { "sfc", SFC }, /* Source Function Code */
3387 { "dfc", DFC }, /* Destination Function Code */
3389 { "cacr", CACR }, /* Cache Control Register */
3390 { "caar", CAAR }, /* Cache Address Register */
3392 { "usp", USP }, /* User Stack Pointer */
3393 { "vbr", VBR }, /* Vector Base Register */
3394 { "msp", MSP }, /* Master Stack Pointer */
3395 { "isp", ISP }, /* Interrupt Stack Pointer */
3397 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0 */
3398 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1 */
3399 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0 */
3400 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1 */
3402 /* 68ec040 versions of same */
3403 { "iacr0", ITT0 }, /* Instruction Access Control Register 0 */
3404 { "iacr1", ITT1 }, /* Instruction Access Control Register 0 */
3405 { "dacr0", DTT0 }, /* Data Access Control Register 0 */
3406 { "dacr1", DTT1 }, /* Data Access Control Register 0 */
3408 /* mcf5200 versions of same. The ColdFire programmer's reference
3409 manual indicated that the order is 2,3,0,1, but Ken Rose
3410 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3411 { "acr0", ITT0 }, /* Access Control Unit 0 */
3412 { "acr1", ITT1 }, /* Access Control Unit 1 */
3413 { "acr2", DTT0 }, /* Access Control Unit 2 */
3414 { "acr3", DTT1 }, /* Access Control Unit 3 */
3416 { "tc", TC }, /* MMU Translation Control Register */
3419 { "mmusr", MMUSR }, /* MMU Status Register */
3420 { "srp", SRP }, /* User Root Pointer */
3421 { "urp", URP }, /* Supervisor Root Pointer */
3426 { "rombar", ROMBAR }, /* ROM Base Address Register */
3427 { "rambar0", RAMBAR0 }, /* ROM Base Address Register */
3428 { "rambar1", RAMBAR1 }, /* ROM Base Address Register */
3429 { "mbar", MBAR }, /* Module Base Address Register */
3430 /* end of control registers */
3464 /* 68ec030 versions of same */
3467 /* 68ec030 access control unit, identical to 030 MMU status reg */
3470 /* Suppressed data and address registers. */
3488 /* Upper and lower data and address registers, used by macw and msacw. */
3532 for (i = 0; init_table[i].name; i++)
3533 insert_reg (init_table[i].name, init_table[i].number);
3536 static int no_68851, no_68881;
3539 /* a.out machine type. Default to 68020. */
3540 int m68k_aout_machtype = 2;
3552 int shorts_this_frag;
3555 /* In MRI mode, the instruction and operands are separated by a
3556 space. Anything following the operands is a comment. The label
3557 has already been removed. */
3565 for (s = str; *s != '\0'; s++)
3567 if ((*s == ' ' || *s == '\t') && ! inquote)
3585 inquote = ! inquote;
3590 memset ((char *) (&the_ins), '\0', sizeof (the_ins));
3595 for (n = 0; n < the_ins.numargs; n++)
3596 if (the_ins.operands[n].error)
3598 er = the_ins.operands[n].error;
3604 as_bad (_("%s -- statement `%s' ignored"), er, str);
3608 /* If there is a current label, record that it marks an instruction. */
3609 if (current_label != NULL)
3611 current_label->text = 1;
3612 current_label = NULL;
3616 /* Tie dwarf2 debug info to the address at the start of the insn. */
3617 dwarf2_emit_insn (0);
3620 if (the_ins.nfrag == 0)
3622 /* No frag hacking involved; just put it out */
3623 toP = frag_more (2 * the_ins.numo);
3624 fromP = &the_ins.opcode[0];
3625 for (m = the_ins.numo; m; --m)
3627 md_number_to_chars (toP, (long) (*fromP), 2);
3631 /* put out symbol-dependent info */
3632 for (m = 0; m < the_ins.nrel; m++)
3634 switch (the_ins.reloc[m].wid)
3653 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3654 the_ins.reloc[m].wid);
3657 fixP = fix_new_exp (frag_now,
3658 ((toP - frag_now->fr_literal)
3659 - the_ins.numo * 2 + the_ins.reloc[m].n),
3661 &the_ins.reloc[m].exp,
3662 the_ins.reloc[m].pcrel,
3663 get_reloc_code (n, the_ins.reloc[m].pcrel,
3664 the_ins.reloc[m].pic_reloc));
3665 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3666 if (the_ins.reloc[m].wid == 'B')
3667 fixP->fx_signed = 1;
3672 /* There's some frag hacking */
3674 /* Calculate the max frag size. */
3677 wid = 2 * the_ins.fragb[0].fragoff;
3678 for (n = 1; n < the_ins.nfrag; n++)
3679 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3680 /* frag_var part. */
3682 /* Make sure the whole insn fits in one chunk, in particular that
3683 the var part is attached, as we access one byte before the
3684 variable frag for byte branches. */
3688 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
3693 wid = 2 * the_ins.fragb[n].fragoff;
3695 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3696 toP = frag_more (wid);
3698 shorts_this_frag = 0;
3699 for (m = wid / 2; m; --m)
3701 md_number_to_chars (toP, (long) (*fromP), 2);
3706 for (m = 0; m < the_ins.nrel; m++)
3708 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
3710 the_ins.reloc[m].n -= 2 * shorts_this_frag;
3713 wid = the_ins.reloc[m].wid;
3716 the_ins.reloc[m].wid = 0;
3717 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3719 fixP = fix_new_exp (frag_now,
3720 ((toP - frag_now->fr_literal)
3721 - the_ins.numo * 2 + the_ins.reloc[m].n),
3723 &the_ins.reloc[m].exp,
3724 the_ins.reloc[m].pcrel,
3725 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3726 the_ins.reloc[m].pic_reloc));
3727 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3729 (void) frag_var (rs_machine_dependent, 10, 0,
3730 (relax_substateT) (the_ins.fragb[n].fragty),
3731 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
3733 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3734 shorts_this_frag = 0;
3737 toP = frag_more (n * sizeof (short));
3740 md_number_to_chars (toP, (long) (*fromP), 2);
3746 for (m = 0; m < the_ins.nrel; m++)
3750 wid = the_ins.reloc[m].wid;
3753 the_ins.reloc[m].wid = 0;
3754 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
3756 fixP = fix_new_exp (frag_now,
3757 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
3758 - shorts_this_frag * 2),
3760 &the_ins.reloc[m].exp,
3761 the_ins.reloc[m].pcrel,
3762 get_reloc_code (wid, the_ins.reloc[m].pcrel,
3763 the_ins.reloc[m].pic_reloc));
3764 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3772 * md_begin -- set up hash tables with 68000 instructions.
3773 * similar to what the vax assembler does. ---phr
3775 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3776 a copy of it at runtime, adding in the information we want but isn't
3777 there. I think it'd be better to have an awk script hack the table
3778 at compile time. Or even just xstr the table and use it as-is. But
3779 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3782 register const struct m68k_opcode *ins;
3783 register struct m68k_incant *hack, *slak;
3784 register const char *retval = 0; /* empty string, or error msg text */
3790 flag_reg_prefix_optional = 1;
3792 if (! m68k_rel32_from_cmdline)
3796 op_hash = hash_new ();
3798 obstack_begin (&robyn, 4000);
3799 for (i = 0; i < m68k_numopcodes; i++)
3801 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3804 ins = &m68k_opcodes[i];
3805 /* We *could* ignore insns that don't match our arch here
3806 but just leaving them out of the hash. */
3807 slak->m_operands = ins->args;
3808 slak->m_opnum = strlen (slak->m_operands) / 2;
3809 slak->m_arch = ins->arch;
3810 slak->m_opcode = ins->opcode;
3811 /* This is kludgey */
3812 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
3813 if (i + 1 != m68k_numopcodes
3814 && !strcmp (ins->name, m68k_opcodes[i + 1].name))
3816 slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
3821 slak = slak->m_next;
3825 retval = hash_insert (op_hash, ins->name, (char *) hack);
3827 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
3830 for (i = 0; i < m68k_numaliases; i++)
3832 const char *name = m68k_opcode_aliases[i].primary;
3833 const char *alias = m68k_opcode_aliases[i].alias;
3834 PTR val = hash_find (op_hash, name);
3836 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
3837 retval = hash_insert (op_hash, alias, val);
3839 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
3842 /* In MRI mode, all unsized branches are variable sized. Normally,
3843 they are word sized. */
3846 static struct m68k_opcode_alias mri_aliases[] =
3867 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
3870 const char *name = mri_aliases[i].primary;
3871 const char *alias = mri_aliases[i].alias;
3872 PTR val = hash_find (op_hash, name);
3874 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
3875 retval = hash_jam (op_hash, alias, val);
3877 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
3881 for (i = 0; i < (int) sizeof (notend_table); i++)
3883 notend_table[i] = 0;
3884 alt_notend_table[i] = 0;
3886 notend_table[','] = 1;
3887 notend_table['{'] = 1;
3888 notend_table['}'] = 1;
3889 alt_notend_table['a'] = 1;
3890 alt_notend_table['A'] = 1;
3891 alt_notend_table['d'] = 1;
3892 alt_notend_table['D'] = 1;
3893 alt_notend_table['#'] = 1;
3894 alt_notend_table['&'] = 1;
3895 alt_notend_table['f'] = 1;
3896 alt_notend_table['F'] = 1;
3897 #ifdef REGISTER_PREFIX
3898 alt_notend_table[REGISTER_PREFIX] = 1;
3901 /* We need to put '(' in alt_notend_table to handle
3902 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3904 alt_notend_table['('] = 1;
3906 /* We need to put '@' in alt_notend_table to handle
3907 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3909 alt_notend_table['@'] = 1;
3911 /* We need to put digits in alt_notend_table to handle
3912 bfextu %d0{24:1},%d0
3914 alt_notend_table['0'] = 1;
3915 alt_notend_table['1'] = 1;
3916 alt_notend_table['2'] = 1;
3917 alt_notend_table['3'] = 1;
3918 alt_notend_table['4'] = 1;
3919 alt_notend_table['5'] = 1;
3920 alt_notend_table['6'] = 1;
3921 alt_notend_table['7'] = 1;
3922 alt_notend_table['8'] = 1;
3923 alt_notend_table['9'] = 1;
3925 #ifndef MIT_SYNTAX_ONLY
3926 /* Insert pseudo ops, these have to go into the opcode table since
3927 gas expects pseudo ops to start with a dot */
3930 while (mote_pseudo_table[n].poc_name)
3932 hack = (struct m68k_incant *)
3933 obstack_alloc (&robyn, sizeof (struct m68k_incant));
3934 hash_insert (op_hash,
3935 mote_pseudo_table[n].poc_name, (char *) hack);
3936 hack->m_operands = 0;
3946 record_alignment (text_section, 2);
3947 record_alignment (data_section, 2);
3948 record_alignment (bss_section, 2);
3953 select_control_regs ()
3955 /* Note which set of "movec" control registers is available. */
3956 switch (cpu_of_arch (current_architecture))
3959 control_regs = m68000_control_regs;
3962 control_regs = m68010_control_regs;
3966 control_regs = m68020_control_regs;
3969 control_regs = m68040_control_regs;
3972 control_regs = m68060_control_regs;
3975 control_regs = cpu32_control_regs;
3981 control_regs = mcf_control_regs;
3989 m68k_init_after_args ()
3991 if (cpu_of_arch (current_architecture) == 0)
3994 const char *default_cpu = TARGET_CPU;
3996 if (*default_cpu == 'm')
3998 for (i = 0; i < n_archs; i++)
3999 if (strcasecmp (default_cpu, archs[i].name) == 0)
4003 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU);
4004 current_architecture |= m68020;
4007 current_architecture |= archs[i].arch;
4009 /* Permit m68881 specification with all cpus; those that can't work
4010 with a coprocessor could be doing emulation. */
4011 if (current_architecture & m68851)
4013 if (current_architecture & m68040)
4015 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4018 /* What other incompatibilities could we check for? */
4020 /* Toss in some default assumptions about coprocessors. */
4022 && (cpu_of_arch (current_architecture)
4023 /* Can CPU32 have a 68881 coprocessor?? */
4024 & (m68020 | m68030 | cpu32)))
4026 current_architecture |= m68881;
4029 && (cpu_of_arch (current_architecture) & m68020up) != 0
4030 && (cpu_of_arch (current_architecture) & m68040up) == 0)
4032 current_architecture |= m68851;
4034 if (no_68881 && (current_architecture & m68881))
4035 as_bad (_("options for 68881 and no-68881 both given"));
4036 if (no_68851 && (current_architecture & m68851))
4037 as_bad (_("options for 68851 and no-68851 both given"));
4040 /* Work out the magic number. This isn't very general. */
4041 if (current_architecture & m68000)
4042 m68k_aout_machtype = 0;
4043 else if (current_architecture & m68010)
4044 m68k_aout_machtype = 1;
4045 else if (current_architecture & m68020)
4046 m68k_aout_machtype = 2;
4048 m68k_aout_machtype = 2;
4051 /* Note which set of "movec" control registers is available. */
4052 select_control_regs ();
4054 if (cpu_of_arch (current_architecture) < m68020
4055 || arch_coldfire_p (current_architecture))
4056 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
4059 /* This is called when a label is defined. */
4062 m68k_frob_label (sym)
4065 struct label_line *n;
4067 n = (struct label_line *) xmalloc (sizeof *n);
4070 as_where (&n->file, &n->line);
4076 /* This is called when a value that is not an instruction is emitted. */
4079 m68k_flush_pending_output ()
4081 current_label = NULL;
4084 /* This is called at the end of the assembly, when the final value of
4085 the label is known. We warn if this is a text symbol aligned at an
4089 m68k_frob_symbol (sym)
4092 if (S_GET_SEGMENT (sym) == reg_section
4093 && (int) S_GET_VALUE (sym) < 0)
4095 S_SET_SEGMENT (sym, absolute_section);
4096 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4098 else if ((S_GET_VALUE (sym) & 1) != 0)
4100 struct label_line *l;
4102 for (l = labels; l != NULL; l = l->next)
4104 if (l->label == sym)
4107 as_warn_where (l->file, l->line,
4108 _("text label `%s' aligned to odd boundary"),
4116 /* This is called if we go in or out of MRI mode because of the .mri
4120 m68k_mri_mode_change (on)
4125 if (! flag_reg_prefix_optional)
4127 flag_reg_prefix_optional = 1;
4128 #ifdef REGISTER_PREFIX
4133 if (! m68k_rel32_from_cmdline)
4138 if (! reg_prefix_optional_seen)
4140 #ifdef REGISTER_PREFIX_OPTIONAL
4141 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4143 flag_reg_prefix_optional = 0;
4145 #ifdef REGISTER_PREFIX
4150 if (! m68k_rel32_from_cmdline)
4155 /* Equal to MAX_PRECISION in atof-ieee.c */
4156 #define MAX_LITTLENUMS 6
4158 /* Turn a string in input_line_pointer into a floating point constant
4159 of type TYPE, and store the appropriate bytes in *LITP. The number
4160 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4161 returned, or NULL on OK. */
4164 md_atof (type, litP, sizeP)
4170 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4171 LITTLENUM_TYPE *wordP;
4202 return _("Bad call to MD_ATOF()");
4204 t = atof_ieee (input_line_pointer, type, words);
4206 input_line_pointer = t;
4208 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4209 for (wordP = words; prec--;)
4211 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4212 litP += sizeof (LITTLENUM_TYPE);
4218 md_number_to_chars (buf, val, n)
4223 number_to_chars_bigendian (buf, val, n);
4227 md_apply_fix_2 (fixP, val)
4231 addressT upper_limit;
4232 offsetT lower_limit;
4234 /* This is unnecessary but it convinces the native rs6000 compiler
4235 to generate the code we want. */
4236 char *buf = fixP->fx_frag->fr_literal;
4237 buf += fixP->fx_where;
4238 /* end ibm compiler workaround */
4240 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
4245 memset (buf, 0, fixP->fx_size);
4246 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
4248 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4249 && !S_IS_DEFINED (fixP->fx_addsy)
4250 && !S_IS_WEAK (fixP->fx_addsy))
4251 S_SET_WEAK (fixP->fx_addsy);
4256 #ifdef BFD_ASSEMBLER
4257 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4258 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4262 switch (fixP->fx_size)
4264 /* The cast to offsetT below are necessary to make code correct for
4265 machines where ints are smaller than offsetT */
4269 lower_limit = - (offsetT) 0x80;
4272 *buf++ = (val >> 8);
4274 upper_limit = 0x7fff;
4275 lower_limit = - (offsetT) 0x8000;
4278 *buf++ = (val >> 24);
4279 *buf++ = (val >> 16);
4280 *buf++ = (val >> 8);
4282 upper_limit = 0x7fffffff;
4283 lower_limit = - (offsetT) 0x7fffffff - 1; /* avoid constant overflow */
4286 BAD_CASE (fixP->fx_size);
4289 /* Fix up a negative reloc. */
4290 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4292 fixP->fx_addsy = fixP->fx_subsy;
4293 fixP->fx_subsy = NULL;
4297 /* For non-pc-relative values, it's conceivable we might get something
4298 like "0xff" for a byte field. So extend the upper part of the range
4299 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4300 so that we can do any range checking at all. */
4301 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4302 upper_limit = upper_limit * 2 + 1;
4304 if ((addressT) val > upper_limit
4305 && (val > 0 || val < lower_limit))
4306 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4308 /* A one byte PC-relative reloc means a short branch. We can't use
4309 a short branch with a value of 0 or -1, because those indicate
4310 different opcodes (branches with longer offsets). fixup_segment
4311 in write.c may have clobbered fx_pcrel, so we need to examine the
4314 #ifdef BFD_ASSEMBLER
4315 || fixP->fx_r_type == BFD_RELOC_8_PCREL
4318 && fixP->fx_size == 1
4319 && (fixP->fx_addsy == NULL
4320 || S_IS_DEFINED (fixP->fx_addsy))
4321 && (val == 0 || val == -1))
4322 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4325 #ifdef BFD_ASSEMBLER
4327 md_apply_fix (fixP, valp)
4331 md_apply_fix_2 (fixP, (addressT) *valp);
4335 void md_apply_fix (fixP, val)
4339 md_apply_fix_2 (fixP, (addressT) val);
4343 /* *fragP has been relaxed to its final size, and now needs to have
4344 the bytes inside it modified to conform to the new size There is UGLY
4348 md_convert_frag_1 (fragP)
4349 register fragS *fragP;
4354 /* Address in object code of the displacement. */
4355 register int object_address = fragP->fr_fix + fragP->fr_address;
4357 /* Address in gas core of the place to store the displacement. */
4358 /* This convinces the native rs6000 compiler to generate the code we
4360 register char *buffer_address = fragP->fr_literal;
4361 buffer_address += fragP->fr_fix;
4362 /* end ibm compiler workaround */
4364 /* The displacement of the address, from current location. */
4365 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4366 disp = (disp + fragP->fr_offset) - object_address;
4368 switch (fragP->fr_subtype)
4370 case TAB (BRANCHBWL, BYTE):
4371 case TAB (BRABSJUNC, BYTE):
4372 case TAB (BRABSJCOND, BYTE):
4373 case TAB (BRANCHBW, BYTE):
4374 know (issbyte (disp));
4376 as_bad_where (fragP->fr_file, fragP->fr_line,
4377 _("short branch with zero offset: use :w"));
4378 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4379 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4380 fixP->fx_pcrel_adjust = -1;
4382 case TAB (BRANCHBWL, SHORT):
4383 case TAB (BRABSJUNC, SHORT):
4384 case TAB (BRABSJCOND, SHORT):
4385 case TAB (BRANCHBW, SHORT):
4386 fragP->fr_opcode[1] = 0x00;
4387 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4388 1, RELAX_RELOC_PC16);
4391 case TAB (BRANCHBWL, LONG):
4392 fragP->fr_opcode[1] = (char) 0xFF;
4393 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4394 1, RELAX_RELOC_PC32);
4397 case TAB (BRABSJUNC, LONG):
4398 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4400 fragP->fr_opcode[0] = 0x4E;
4401 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand */
4402 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4403 0, RELAX_RELOC_ABS32);
4406 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4408 fragP->fr_opcode[0] = 0x4E;
4409 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand */
4410 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4411 0, RELAX_RELOC_ABS32);
4416 /* This cannot happen, because jbsr and jbra are the only two
4417 unconditional branches. */
4421 case TAB (BRABSJCOND, LONG):
4422 /* Only Bcc 68000 instructions can come here. */
4423 /* Change bcc into b!cc/jmp absl long. */
4425 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
4426 fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
4428 /* JF: these used to be fr_opcode[2,3], but they may be in a
4429 different frag, in which case refering to them is a no-no.
4430 Only fr_opcode[0,1] are guaranteed to work. */
4431 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4432 *buffer_address++ = (char) 0xf9;
4433 fragP->fr_fix += 2; /* account for jmp instruction */
4434 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4435 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4438 case TAB (FBRANCH, SHORT):
4439 know ((fragP->fr_opcode[1] & 0x40) == 0);
4440 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4441 1, RELAX_RELOC_PC16);
4444 case TAB (FBRANCH, LONG):
4445 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
4446 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4447 1, RELAX_RELOC_PC32);
4450 case TAB (DBCCLBR, SHORT):
4451 case TAB (DBCCABSJ, SHORT):
4452 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4453 1, RELAX_RELOC_PC16);
4456 case TAB (DBCCLBR, LONG):
4457 /* only DBcc instructions can come here */
4458 /* Change dbcc into dbcc/bral. */
4460 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4461 *buffer_address++ = 0x00; /* branch offset = 4 */
4462 *buffer_address++ = 0x04;
4463 *buffer_address++ = 0x60; /* put in bra pc+6 */
4464 *buffer_address++ = 0x06;
4465 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4466 *buffer_address++ = (char) 0xff;
4468 fragP->fr_fix += 6; /* account for bra/jmp instructions */
4469 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4473 case TAB (DBCCABSJ, LONG):
4474 /* only DBcc instructions can come here */
4475 /* Change dbcc into dbcc/jmp. */
4477 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4478 *buffer_address++ = 0x00; /* branch offset = 4 */
4479 *buffer_address++ = 0x04;
4480 *buffer_address++ = 0x60; /* put in bra pc+6 */
4481 *buffer_address++ = 0x06;
4482 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4483 *buffer_address++ = (char) 0xf9;
4485 fragP->fr_fix += 6; /* account for bra/jmp instructions */
4486 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4490 case TAB (PCREL1632, SHORT):
4491 fragP->fr_opcode[1] &= ~0x3F;
4492 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4493 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4494 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4497 case TAB (PCREL1632, LONG):
4498 /* Already set to mode 7.3; this indicates: PC indirect with
4499 suppressed index, 32-bit displacement. */
4500 *buffer_address++ = 0x01;
4501 *buffer_address++ = 0x70;
4503 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4504 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4505 fixP->fx_pcrel_adjust = 2;
4508 case TAB (PCINDEX, BYTE):
4509 assert (fragP->fr_fix >= 2);
4510 buffer_address[-2] &= ~1;
4511 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4512 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4513 fixP->fx_pcrel_adjust = 1;
4515 case TAB (PCINDEX, SHORT):
4516 assert (fragP->fr_fix >= 2);
4517 buffer_address[-2] |= 0x1;
4518 buffer_address[-1] = 0x20;
4519 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4520 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4521 fixP->fx_pcrel_adjust = 2;
4524 case TAB (PCINDEX, LONG):
4525 assert (fragP->fr_fix >= 2);
4526 buffer_address[-2] |= 0x1;
4527 buffer_address[-1] = 0x30;
4528 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4529 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4530 fixP->fx_pcrel_adjust = 2;
4533 case TAB (ABSTOPCREL, SHORT):
4534 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4535 1, RELAX_RELOC_PC16);
4538 case TAB (ABSTOPCREL, LONG):
4539 /* The thing to do here is force it to ABSOLUTE LONG, since
4540 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway */
4541 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4543 fragP->fr_opcode[1] &= ~0x3F;
4544 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4545 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4546 0, RELAX_RELOC_ABS32);
4552 #ifndef BFD_ASSEMBLER
4555 md_convert_frag (headers, sec, fragP)
4556 object_headers *headers ATTRIBUTE_UNUSED;
4557 segT sec ATTRIBUTE_UNUSED;
4560 md_convert_frag_1 (fragP);
4566 md_convert_frag (abfd, sec, fragP)
4567 bfd *abfd ATTRIBUTE_UNUSED;
4568 segT sec ATTRIBUTE_UNUSED;
4571 md_convert_frag_1 (fragP);
4575 /* Force truly undefined symbols to their maximum size, and generally set up
4576 the frag list to be relaxed
4579 md_estimate_size_before_relax (fragP, segment)
4580 register fragS *fragP;
4583 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4584 switch (fragP->fr_subtype)
4586 case TAB (BRANCHBWL, SZ_UNDEF):
4587 case TAB (BRABSJUNC, SZ_UNDEF):
4588 case TAB (BRABSJCOND, SZ_UNDEF):
4590 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4591 && relaxable_symbol (fragP->fr_symbol))
4593 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4595 else if (flag_short_refs)
4597 /* Symbol is undefined and we want short ref. */
4598 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4602 /* Symbol is still undefined. Make it LONG. */
4603 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4608 case TAB (BRANCHBW, SZ_UNDEF):
4610 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4611 && relaxable_symbol (fragP->fr_symbol))
4613 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4617 /* Symbol is undefined and we don't have long branches. */
4618 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4623 case TAB (FBRANCH, SZ_UNDEF):
4624 case TAB (DBCCLBR, SZ_UNDEF):
4625 case TAB (DBCCABSJ, SZ_UNDEF):
4626 case TAB (PCREL1632, SZ_UNDEF):
4628 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4629 && relaxable_symbol (fragP->fr_symbol))
4632 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4636 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4641 case TAB (PCINDEX, SZ_UNDEF):
4642 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4643 && relaxable_symbol (fragP->fr_symbol)))
4645 fragP->fr_subtype = TAB (PCINDEX, BYTE);
4649 fragP->fr_subtype = TAB (PCINDEX, LONG);
4653 case TAB (ABSTOPCREL, SZ_UNDEF):
4655 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4656 && relaxable_symbol (fragP->fr_symbol)))
4658 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
4662 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
4671 /* Now that SZ_UNDEF are taken care of, check others. */
4672 switch (fragP->fr_subtype)
4674 case TAB (BRANCHBWL, BYTE):
4675 case TAB (BRABSJUNC, BYTE):
4676 case TAB (BRABSJCOND, BYTE):
4677 case TAB (BRANCHBW, BYTE):
4678 /* We can't do a short jump to the next instruction, so in that
4679 case we force word mode. If the symbol is at the start of a
4680 frag, and it is the next frag with any data in it (usually
4681 this is just the next frag, but assembler listings may
4682 introduce empty frags), we must use word mode. */
4683 if (fragP->fr_symbol)
4687 sym_frag = symbol_get_frag (fragP->fr_symbol);
4688 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
4692 for (l = fragP->fr_next; l != sym_frag; l = l->fr_next)
4696 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4703 return md_relax_table[fragP->fr_subtype].rlx_length;
4706 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4707 /* the bit-field entries in the relocation_info struct plays hell
4708 with the byte-order problems of cross-assembly. So as a hack,
4709 I added this mach. dependent ri twiddler. Ugly, but it gets
4711 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4712 are symbolnum, most sig. byte first. Last byte is broken up with
4713 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4714 nibble as nuthin. (on Sun 3 at least) */
4715 /* Translate the internal relocation information into target-specific
4719 md_ri_to_chars (the_bytes, ri)
4721 struct reloc_info_generic *ri;
4724 md_number_to_chars (the_bytes, ri->r_address, 4);
4725 /* now the fun stuff */
4726 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
4727 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
4728 the_bytes[6] = ri->r_symbolnum & 0x0ff;
4729 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
4730 ((ri->r_extern << 4) & 0x10));
4733 #endif /* comment */
4735 #ifndef BFD_ASSEMBLER
4737 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
4740 relax_addressT segment_address_in_file;
4743 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4744 * Out: GNU LD relocation length code: 0, 1, or 2.
4747 static CONST unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
4750 know (fixP->fx_addsy != NULL);
4752 md_number_to_chars (where,
4753 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
4756 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
4757 ? S_GET_TYPE (fixP->fx_addsy)
4758 : fixP->fx_addsy->sy_number);
4760 where[4] = (r_symbolnum >> 16) & 0x0ff;
4761 where[5] = (r_symbolnum >> 8) & 0x0ff;
4762 where[6] = r_symbolnum & 0x0ff;
4763 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
4764 (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
4768 #endif /* OBJ_AOUT or OBJ_BOUT */
4770 #ifndef WORKING_DOT_WORD
4771 CONST int md_short_jump_size = 4;
4772 CONST int md_long_jump_size = 6;
4775 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
4777 addressT from_addr, to_addr;
4778 fragS *frag ATTRIBUTE_UNUSED;
4779 symbolS *to_symbol ATTRIBUTE_UNUSED;
4783 offset = to_addr - (from_addr + 2);
4785 md_number_to_chars (ptr, (valueT) 0x6000, 2);
4786 md_number_to_chars (ptr + 2, (valueT) offset, 2);
4790 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
4792 addressT from_addr, to_addr;
4798 if (!HAVE_LONG_BRANCH(current_architecture))
4800 offset = to_addr - S_GET_VALUE (to_symbol);
4801 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
4802 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4803 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
4808 offset = to_addr - (from_addr + 2);
4809 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
4810 md_number_to_chars (ptr + 2, (valueT) offset, 4);
4816 /* Different values of OK tell what its OK to return. Things that
4817 aren't OK are an error (what a shock, no?)
4820 10: Absolute 1:8 only
4821 20: Absolute 0:7 only
4822 30: absolute 0:15 only
4823 40: Absolute 0:31 only
4824 50: absolute 0:127 only
4825 55: absolute -64:63 only
4826 60: absolute -128:127 only
4827 70: absolute 0:4095 only
4834 struct m68k_exp *exp;
4837 if (exp->exp.X_op == O_absent)
4839 /* Do the same thing the VAX asm does */
4840 op (exp) = O_constant;
4846 as_warn (_("expression out of range: defaulting to 1"));
4850 else if (exp->exp.X_op == O_constant)
4855 if (offs (exp) < 1 || offs (exp) > 8)
4857 as_warn (_("expression out of range: defaulting to 1"));
4862 if (offs (exp) < 0 || offs (exp) > 7)
4866 if (offs (exp) < 0 || offs (exp) > 15)
4870 if (offs (exp) < 0 || offs (exp) > 32)
4874 if (offs (exp) < 0 || offs (exp) > 127)
4878 if (offs (exp) < -64 || offs (exp) > 63)
4882 if (offs (exp) < -128 || offs (exp) > 127)
4886 if (offs (exp) < 0 || offs (exp) > 4095)
4889 as_warn (_("expression out of range: defaulting to 0"));
4897 else if (exp->exp.X_op == O_big)
4899 if (offs (exp) <= 0 /* flonum */
4900 && (ok == 80 /* no bignums */
4901 || (ok > 10 /* small-int ranges including 0 ok */
4902 /* If we have a flonum zero, a zero integer should
4903 do as well (e.g., in moveq). */
4904 && generic_floating_point_number.exponent == 0
4905 && generic_floating_point_number.low[0] == 0)))
4907 /* HACK! Turn it into a long */
4908 LITTLENUM_TYPE words[6];
4910 gen_to_words (words, 2, 8L); /* These numbers are magic! */
4911 op (exp) = O_constant;
4914 offs (exp) = words[1] | (words[0] << 16);
4918 op (exp) = O_constant;
4921 offs (exp) = (ok == 10) ? 1 : 0;
4922 as_warn (_("Can't deal with expression; defaulting to %ld"),
4928 if (ok >= 10 && ok <= 70)
4930 op (exp) = O_constant;
4933 offs (exp) = (ok == 10) ? 1 : 0;
4934 as_warn (_("Can't deal with expression; defaulting to %ld"),
4939 if (exp->size != SIZE_UNSPEC)
4947 if (!isbyte (offs (exp)))
4948 as_warn (_("expression doesn't fit in BYTE"));
4951 if (!isword (offs (exp)))
4952 as_warn (_("expression doesn't fit in WORD"));
4960 /* These are the back-ends for the various machine dependent pseudo-ops. */
4964 int ignore ATTRIBUTE_UNUSED;
4966 subseg_set (data_section, 1);
4967 demand_empty_rest_of_line ();
4972 int ignore ATTRIBUTE_UNUSED;
4974 subseg_set (data_section, 2);
4975 demand_empty_rest_of_line ();
4980 int ignore ATTRIBUTE_UNUSED;
4982 /* We don't support putting frags in the BSS segment, we fake it
4983 by marking in_bss, then looking at s_skip for clues. */
4985 subseg_set (bss_section, 0);
4986 demand_empty_rest_of_line ();
4991 int ignore ATTRIBUTE_UNUSED;
4994 register long temp_fill;
4996 temp = 1; /* JF should be 2? */
4997 temp_fill = get_absolute_expression ();
4998 if (!need_pass_2) /* Never make frag if expect extra pass. */
4999 frag_align (temp, (int) temp_fill, 0);
5000 demand_empty_rest_of_line ();
5001 record_alignment (now_seg, temp);
5006 int ignore ATTRIBUTE_UNUSED;
5008 demand_empty_rest_of_line ();
5011 /* Pseudo-ops handled for MRI compatibility. */
5013 /* This function returns non-zero if the argument is a conditional
5014 pseudo-op. This is called when checking whether a pending
5015 alignment is needed. */
5018 m68k_conditional_pseudoop (pop)
5021 return (pop->poc_handler == s_mri_if
5022 || pop->poc_handler == s_mri_else);
5025 /* Handle an MRI style chip specification. */
5034 s = input_line_pointer;
5035 /* We can't use get_symbol_end since the processor names are not proper
5037 while (is_part_of_name (c = *input_line_pointer++))
5039 *--input_line_pointer = 0;
5040 for (i = 0; i < n_archs; i++)
5041 if (strcasecmp (s, archs[i].name) == 0)
5045 as_bad (_("%s: unrecognized processor name"), s);
5046 *input_line_pointer = c;
5047 ignore_rest_of_line ();
5050 *input_line_pointer = c;
5052 if (*input_line_pointer == '/')
5053 current_architecture = 0;
5055 current_architecture &= m68881 | m68851;
5056 current_architecture |= archs[i].arch;
5058 while (*input_line_pointer == '/')
5060 ++input_line_pointer;
5061 s = input_line_pointer;
5062 /* We can't use get_symbol_end since the processor names are not
5064 while (is_part_of_name (c = *input_line_pointer++))
5066 *--input_line_pointer = 0;
5067 if (strcmp (s, "68881") == 0)
5068 current_architecture |= m68881;
5069 else if (strcmp (s, "68851") == 0)
5070 current_architecture |= m68851;
5071 *input_line_pointer = c;
5074 /* Update info about available control registers. */
5075 select_control_regs ();
5078 /* The MRI CHIP pseudo-op. */
5082 int ignore ATTRIBUTE_UNUSED;
5088 stop = mri_comment_field (&stopc);
5091 mri_comment_end (stop, stopc);
5092 demand_empty_rest_of_line ();
5095 /* The MRI FOPT pseudo-op. */
5099 int ignore ATTRIBUTE_UNUSED;
5103 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5107 input_line_pointer += 3;
5108 temp = get_absolute_expression ();
5109 if (temp < 0 || temp > 7)
5110 as_bad (_("bad coprocessor id"));
5112 m68k_float_copnum = COP0 + temp;
5116 as_bad (_("unrecognized fopt option"));
5117 ignore_rest_of_line ();
5121 demand_empty_rest_of_line ();
5124 /* The structure used to handle the MRI OPT pseudo-op. */
5128 /* The name of the option. */
5131 /* If this is not NULL, just call this function. The first argument
5132 is the ARG field of this structure, the second argument is
5133 whether the option was negated. */
5134 void (*pfn) PARAMS ((int arg, int on));
5136 /* If this is not NULL, and the PFN field is NULL, set the variable
5137 this points to. Set it to the ARG field if the option was not
5138 negated, and the NOTARG field otherwise. */
5141 /* The value to pass to PFN or to assign to *PVAR. */
5144 /* The value to assign to *PVAR if the option is negated. If PFN is
5145 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5146 the option may not be negated. */
5150 /* The table used to handle the MRI OPT pseudo-op. */
5152 static void skip_to_comma PARAMS ((int, int));
5153 static void opt_nest PARAMS ((int, int));
5154 static void opt_chip PARAMS ((int, int));
5155 static void opt_list PARAMS ((int, int));
5156 static void opt_list_symbols PARAMS ((int, int));
5158 static const struct opt_action opt_table[] =
5160 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5162 /* We do relaxing, so there is little use for these options. */
5163 { "b", 0, 0, 0, 0 },
5164 { "brs", 0, 0, 0, 0 },
5165 { "brb", 0, 0, 0, 0 },
5166 { "brl", 0, 0, 0, 0 },
5167 { "brw", 0, 0, 0, 0 },
5169 { "c", 0, 0, 0, 0 },
5170 { "cex", 0, 0, 0, 0 },
5171 { "case", 0, &symbols_case_sensitive, 1, 0 },
5172 { "cl", 0, 0, 0, 0 },
5173 { "cre", 0, 0, 0, 0 },
5174 { "d", 0, &flag_keep_locals, 1, 0 },
5175 { "e", 0, 0, 0, 0 },
5176 { "f", 0, &flag_short_refs, 1, 0 },
5177 { "frs", 0, &flag_short_refs, 1, 0 },
5178 { "frl", 0, &flag_short_refs, 0, 1 },
5179 { "g", 0, 0, 0, 0 },
5180 { "i", 0, 0, 0, 0 },
5181 { "m", 0, 0, 0, 0 },
5182 { "mex", 0, 0, 0, 0 },
5183 { "mc", 0, 0, 0, 0 },
5184 { "md", 0, 0, 0, 0 },
5185 { "nest", opt_nest, 0, 0, 0 },
5186 { "next", skip_to_comma, 0, 0, 0 },
5187 { "o", 0, 0, 0, 0 },
5188 { "old", 0, 0, 0, 0 },
5189 { "op", skip_to_comma, 0, 0, 0 },
5190 { "pco", 0, 0, 0, 0 },
5191 { "p", opt_chip, 0, 0, 0 },
5192 { "pcr", 0, 0, 0, 0 },
5193 { "pcs", 0, 0, 0, 0 },
5194 { "r", 0, 0, 0, 0 },
5195 { "quick", 0, &m68k_quick, 1, 0 },
5196 { "rel32", 0, &m68k_rel32, 1, 0 },
5197 { "s", opt_list, 0, 0, 0 },
5198 { "t", opt_list_symbols, 0, 0, 0 },
5199 { "w", 0, &flag_no_warnings, 0, 1 },
5203 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5205 /* The MRI OPT pseudo-op. */
5209 int ignore ATTRIBUTE_UNUSED;
5217 const struct opt_action *o;
5222 if (*input_line_pointer == '-')
5224 ++input_line_pointer;
5227 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5229 input_line_pointer += 2;
5233 s = input_line_pointer;
5234 c = get_symbol_end ();
5236 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5238 if (strcasecmp (s, o->name) == 0)
5242 /* Restore input_line_pointer now in case the option
5244 *input_line_pointer = c;
5245 (*o->pfn) (o->arg, t);
5247 else if (o->pvar != NULL)
5249 if (! t && o->arg == o->notarg)
5250 as_bad (_("option `%s' may not be negated"), s);
5251 *input_line_pointer = c;
5252 *o->pvar = t ? o->arg : o->notarg;
5255 *input_line_pointer = c;
5261 as_bad (_("option `%s' not recognized"), s);
5262 *input_line_pointer = c;
5265 while (*input_line_pointer++ == ',');
5267 /* Move back to terminating character. */
5268 --input_line_pointer;
5269 demand_empty_rest_of_line ();
5272 /* Skip ahead to a comma. This is used for OPT options which we do
5273 not suppor tand which take arguments. */
5276 skip_to_comma (arg, on)
5277 int arg ATTRIBUTE_UNUSED;
5278 int on ATTRIBUTE_UNUSED;
5280 while (*input_line_pointer != ','
5281 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5282 ++input_line_pointer;
5285 /* Handle the OPT NEST=depth option. */
5289 int arg ATTRIBUTE_UNUSED;
5290 int on ATTRIBUTE_UNUSED;
5292 if (*input_line_pointer != '=')
5294 as_bad (_("bad format of OPT NEST=depth"));
5298 ++input_line_pointer;
5299 max_macro_nest = get_absolute_expression ();
5302 /* Handle the OPT P=chip option. */
5306 int arg ATTRIBUTE_UNUSED;
5307 int on ATTRIBUTE_UNUSED;
5309 if (*input_line_pointer != '=')
5311 /* This is just OPT P, which we do not support. */
5315 ++input_line_pointer;
5319 /* Handle the OPT S option. */
5323 int arg ATTRIBUTE_UNUSED;
5329 /* Handle the OPT T option. */
5332 opt_list_symbols (arg, on)
5333 int arg ATTRIBUTE_UNUSED;
5337 listing |= LISTING_SYMBOLS;
5339 listing &=~ LISTING_SYMBOLS;
5342 /* Handle the MRI REG pseudo-op. */
5346 int ignore ATTRIBUTE_UNUSED;
5355 if (line_label == NULL)
5357 as_bad (_("missing label"));
5358 ignore_rest_of_line ();
5363 stop = mri_comment_field (&stopc);
5367 s = input_line_pointer;
5368 while (ISALNUM (*input_line_pointer)
5369 #ifdef REGISTER_PREFIX
5370 || *input_line_pointer == REGISTER_PREFIX
5372 || *input_line_pointer == '/'
5373 || *input_line_pointer == '-')
5374 ++input_line_pointer;
5375 c = *input_line_pointer;
5376 *input_line_pointer = '\0';
5378 if (m68k_ip_op (s, &rop) != 0)
5380 if (rop.error == NULL)
5381 as_bad (_("bad register list"));
5383 as_bad (_("bad register list: %s"), rop.error);
5384 *input_line_pointer = c;
5385 ignore_rest_of_line ();
5389 *input_line_pointer = c;
5391 if (rop.mode == REGLST)
5393 else if (rop.mode == DREG)
5394 mask = 1 << (rop.reg - DATA0);
5395 else if (rop.mode == AREG)
5396 mask = 1 << (rop.reg - ADDR0 + 8);
5397 else if (rop.mode == FPREG)
5398 mask = 1 << (rop.reg - FP0 + 16);
5399 else if (rop.mode == CONTROL
5402 else if (rop.mode == CONTROL
5405 else if (rop.mode == CONTROL
5410 as_bad (_("bad register list"));
5411 ignore_rest_of_line ();
5415 S_SET_SEGMENT (line_label, reg_section);
5416 S_SET_VALUE (line_label, ~mask);
5417 symbol_set_frag (line_label, &zero_address_frag);
5420 mri_comment_end (stop, stopc);
5422 demand_empty_rest_of_line ();
5425 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5429 struct save_opts *next;
5431 int symbols_case_sensitive;
5439 /* FIXME: We don't save OPT S. */
5442 /* This variable holds the stack of saved options. */
5444 static struct save_opts *save_stack;
5446 /* The MRI SAVE pseudo-op. */
5450 int ignore ATTRIBUTE_UNUSED;
5452 struct save_opts *s;
5454 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5455 s->abspcadd = m68k_abspcadd;
5456 s->symbols_case_sensitive = symbols_case_sensitive;
5457 s->keep_locals = flag_keep_locals;
5458 s->short_refs = flag_short_refs;
5459 s->architecture = current_architecture;
5460 s->quick = m68k_quick;
5461 s->rel32 = m68k_rel32;
5462 s->listing = listing;
5463 s->no_warnings = flag_no_warnings;
5465 s->next = save_stack;
5468 demand_empty_rest_of_line ();
5471 /* The MRI RESTORE pseudo-op. */
5475 int ignore ATTRIBUTE_UNUSED;
5477 struct save_opts *s;
5479 if (save_stack == NULL)
5481 as_bad (_("restore without save"));
5482 ignore_rest_of_line ();
5487 save_stack = s->next;
5489 m68k_abspcadd = s->abspcadd;
5490 symbols_case_sensitive = s->symbols_case_sensitive;
5491 flag_keep_locals = s->keep_locals;
5492 flag_short_refs = s->short_refs;
5493 current_architecture = s->architecture;
5494 m68k_quick = s->quick;
5495 m68k_rel32 = s->rel32;
5496 listing = s->listing;
5497 flag_no_warnings = s->no_warnings;
5501 demand_empty_rest_of_line ();
5504 /* Types of MRI structured control directives. */
5506 enum mri_control_type
5514 /* This structure is used to stack the MRI structured control
5517 struct mri_control_info
5519 /* The directive within which this one is enclosed. */
5520 struct mri_control_info *outer;
5522 /* The type of directive. */
5523 enum mri_control_type type;
5525 /* Whether an ELSE has been in an IF. */
5528 /* The add or sub statement at the end of a FOR. */
5531 /* The label of the top of a FOR or REPEAT loop. */
5534 /* The label to jump to for the next iteration, or the else
5535 expression of a conditional. */
5538 /* The label to jump to to break out of the loop, or the label past
5539 the end of a conditional. */
5543 /* The stack of MRI structured control directives. */
5545 static struct mri_control_info *mri_control_stack;
5547 /* The current MRI structured control directive index number, used to
5548 generate label names. */
5550 static int mri_control_index;
5552 /* Some function prototypes. */
5554 static void mri_assemble PARAMS ((char *));
5555 static char *mri_control_label PARAMS ((void));
5556 static struct mri_control_info *push_mri_control
5557 PARAMS ((enum mri_control_type));
5558 static void pop_mri_control PARAMS ((void));
5559 static int parse_mri_condition PARAMS ((int *));
5560 static int parse_mri_control_operand
5561 PARAMS ((int *, char **, char **, char **, char **));
5562 static int swap_mri_condition PARAMS ((int));
5563 static int reverse_mri_condition PARAMS ((int));
5564 static void build_mri_control_operand
5565 PARAMS ((int, int, char *, char *, char *, char *, const char *,
5566 const char *, int));
5567 static void parse_mri_control_expression
5568 PARAMS ((char *, int, const char *, const char *, int));
5570 /* Assemble an instruction for an MRI structured control directive. */
5578 /* md_assemble expects the opcode to be in lower case. */
5579 for (s = str; *s != ' ' && *s != '\0'; s++)
5585 /* Generate a new MRI label structured control directive label name. */
5588 mri_control_label ()
5592 n = (char *) xmalloc (20);
5593 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5594 ++mri_control_index;
5598 /* Create a new MRI structured control directive. */
5600 static struct mri_control_info *
5601 push_mri_control (type)
5602 enum mri_control_type type;
5604 struct mri_control_info *n;
5606 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5610 if (type == mri_if || type == mri_while)
5613 n->top = mri_control_label ();
5614 n->next = mri_control_label ();
5615 n->bottom = mri_control_label ();
5617 n->outer = mri_control_stack;
5618 mri_control_stack = n;
5623 /* Pop off the stack of MRI structured control directives. */
5628 struct mri_control_info *n;
5630 n = mri_control_stack;
5631 mri_control_stack = n->outer;
5639 /* Recognize a condition code in an MRI structured control expression. */
5642 parse_mri_condition (pcc)
5647 know (*input_line_pointer == '<');
5649 ++input_line_pointer;
5650 c1 = *input_line_pointer++;
5651 c2 = *input_line_pointer++;
5653 if (*input_line_pointer != '>')
5655 as_bad (_("syntax error in structured control directive"));
5659 ++input_line_pointer;
5665 *pcc = (c1 << 8) | c2;
5670 /* Parse a single operand in an MRI structured control expression. */
5673 parse_mri_control_operand (pcc, leftstart, leftstop, rightstart, rightstop)
5690 if (*input_line_pointer == '<')
5692 /* It's just a condition code. */
5693 return parse_mri_condition (pcc);
5696 /* Look ahead for the condition code. */
5697 for (s = input_line_pointer; *s != '\0'; ++s)
5699 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
5704 as_bad (_("missing condition code in structured control directive"));
5708 *leftstart = input_line_pointer;
5710 if (*leftstop > *leftstart
5711 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
5714 input_line_pointer = s;
5715 if (! parse_mri_condition (pcc))
5718 /* Look ahead for AND or OR or end of line. */
5719 for (s = input_line_pointer; *s != '\0'; ++s)
5721 /* We must make sure we don't misinterpret AND/OR at the end of labels!
5722 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
5724 if ( ( s == input_line_pointer
5727 && ( ( strncasecmp (s, "AND", 3) == 0
5728 && (s[3] == '.' || ! is_part_of_name (s[3])))
5729 || ( strncasecmp (s, "OR", 2) == 0
5730 && (s[2] == '.' || ! is_part_of_name (s[2])))))
5734 *rightstart = input_line_pointer;
5736 if (*rightstop > *rightstart
5737 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
5740 input_line_pointer = s;
5745 #define MCC(b1, b2) (((b1) << 8) | (b2))
5747 /* Swap the sense of a condition. This changes the condition so that
5748 it generates the same result when the operands are swapped. */
5751 swap_mri_condition (cc)
5756 case MCC ('h', 'i'): return MCC ('c', 's');
5757 case MCC ('l', 's'): return MCC ('c', 'c');
5758 /* <HS> is an alias for <CC> */
5759 case MCC ('h', 's'):
5760 case MCC ('c', 'c'): return MCC ('l', 's');
5761 /* <LO> is an alias for <CS> */
5762 case MCC ('l', 'o'):
5763 case MCC ('c', 's'): return MCC ('h', 'i');
5764 case MCC ('p', 'l'): return MCC ('m', 'i');
5765 case MCC ('m', 'i'): return MCC ('p', 'l');
5766 case MCC ('g', 'e'): return MCC ('l', 'e');
5767 case MCC ('l', 't'): return MCC ('g', 't');
5768 case MCC ('g', 't'): return MCC ('l', 't');
5769 case MCC ('l', 'e'): return MCC ('g', 'e');
5770 /* issue a warning for conditions we can not swap */
5771 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
5772 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
5773 case MCC ('v', 'c'):
5774 case MCC ('v', 's'):
5776 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
5777 (char) (cc >> 8), (char) (cc));
5783 /* Reverse the sense of a condition. */
5786 reverse_mri_condition (cc)
5791 case MCC ('h', 'i'): return MCC ('l', 's');
5792 case MCC ('l', 's'): return MCC ('h', 'i');
5793 /* <HS> is an alias for <CC> */
5794 case MCC ('h', 's'): return MCC ('l', 'o');
5795 case MCC ('c', 'c'): return MCC ('c', 's');
5796 /* <LO> is an alias for <CS> */
5797 case MCC ('l', 'o'): return MCC ('h', 's');
5798 case MCC ('c', 's'): return MCC ('c', 'c');
5799 case MCC ('n', 'e'): return MCC ('e', 'q');
5800 case MCC ('e', 'q'): return MCC ('n', 'e');
5801 case MCC ('v', 'c'): return MCC ('v', 's');
5802 case MCC ('v', 's'): return MCC ('v', 'c');
5803 case MCC ('p', 'l'): return MCC ('m', 'i');
5804 case MCC ('m', 'i'): return MCC ('p', 'l');
5805 case MCC ('g', 'e'): return MCC ('l', 't');
5806 case MCC ('l', 't'): return MCC ('g', 'e');
5807 case MCC ('g', 't'): return MCC ('l', 'e');
5808 case MCC ('l', 'e'): return MCC ('g', 't');
5813 /* Build an MRI structured control expression. This generates test
5814 and branch instructions. It goes to TRUELAB if the condition is
5815 true, and to FALSELAB if the condition is false. Exactly one of
5816 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
5817 is the size qualifier for the expression. EXTENT is the size to
5818 use for the branch. */
5821 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5822 rightstop, truelab, falselab, extent)
5829 const char *truelab;
5830 const char *falselab;
5836 if (leftstart != NULL)
5838 struct m68k_op leftop, rightop;
5841 /* Swap the compare operands, if necessary, to produce a legal
5842 m68k compare instruction. Comparing a register operand with
5843 a non-register operand requires the register to be on the
5844 right (cmp, cmpa). Comparing an immediate value with
5845 anything requires the immediate value to be on the left
5850 (void) m68k_ip_op (leftstart, &leftop);
5855 (void) m68k_ip_op (rightstart, &rightop);
5858 if (rightop.mode == IMMED
5859 || ((leftop.mode == DREG || leftop.mode == AREG)
5860 && (rightop.mode != DREG && rightop.mode != AREG)))
5864 /* Correct conditional handling:
5865 if #1 <lt> d0 then ;means if (1 < d0)
5871 cmp #1,d0 if we do *not* swap the operands
5872 bgt true we need the swapped condition!
5879 leftstart = rightstart;
5882 leftstop = rightstop;
5885 cc = swap_mri_condition (cc);
5889 if (truelab == NULL)
5891 cc = reverse_mri_condition (cc);
5895 if (leftstart != NULL)
5897 buf = (char *) xmalloc (20
5898 + (leftstop - leftstart)
5899 + (rightstop - rightstart));
5905 *s++ = TOLOWER (qual);
5907 memcpy (s, leftstart, leftstop - leftstart);
5908 s += leftstop - leftstart;
5910 memcpy (s, rightstart, rightstop - rightstart);
5911 s += rightstop - rightstart;
5917 buf = (char *) xmalloc (20 + strlen (truelab));
5923 *s++ = TOLOWER (extent);
5925 strcpy (s, truelab);
5930 /* Parse an MRI structured control expression. This generates test
5931 and branch instructions. STOP is where the expression ends. It
5932 goes to TRUELAB if the condition is true, and to FALSELAB if the
5933 condition is false. Exactly one of TRUELAB and FALSELAB will be
5934 NULL, meaning to fall through. QUAL is the size qualifier for the
5935 expression. EXTENT is the size to use for the branch. */
5938 parse_mri_control_expression (stop, qual, truelab, falselab, extent)
5941 const char *truelab;
5942 const char *falselab;
5955 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5956 &rightstart, &rightstop))
5962 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
5966 if (falselab != NULL)
5969 flab = mri_control_label ();
5971 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5972 rightstop, (const char *) NULL, flab, extent);
5974 input_line_pointer += 3;
5975 if (*input_line_pointer != '.'
5976 || input_line_pointer[1] == '\0')
5980 qual = input_line_pointer[1];
5981 input_line_pointer += 2;
5984 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
5985 &rightstart, &rightstop))
5991 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
5992 rightstop, truelab, falselab, extent);
5994 if (falselab == NULL)
5997 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6001 if (truelab != NULL)
6004 tlab = mri_control_label ();
6006 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6007 rightstop, tlab, (const char *) NULL, extent);
6009 input_line_pointer += 2;
6010 if (*input_line_pointer != '.'
6011 || input_line_pointer[1] == '\0')
6015 qual = input_line_pointer[1];
6016 input_line_pointer += 2;
6019 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6020 &rightstart, &rightstop))
6026 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6027 rightstop, truelab, falselab, extent);
6029 if (truelab == NULL)
6034 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6035 rightstop, truelab, falselab, extent);
6039 if (input_line_pointer != stop)
6040 as_bad (_("syntax error in structured control directive"));
6043 /* Handle the MRI IF pseudo-op. This may be a structured control
6044 directive, or it may be a regular assembler conditional, depending
6053 struct mri_control_info *n;
6055 /* A structured control directive must end with THEN with an
6056 optional qualifier. */
6057 s = input_line_pointer;
6058 /* We only accept '*' as introduction of comments if preceded by white space
6059 or at first column of a line (I think this can't actually happen here?)
6060 This is important when assembling:
6061 if d0 <ne> 12(a0,d0*2) then
6062 if d0 <ne> #CONST*20 then */
6063 while ( ! ( is_end_of_line[(unsigned char) *s]
6066 && ( s == input_line_pointer
6068 || *(s-1) == '\t'))))
6071 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6074 if (s - input_line_pointer > 1
6078 if (s - input_line_pointer < 3
6079 || strncasecmp (s - 3, "THEN", 4) != 0)
6083 as_bad (_("missing then"));
6084 ignore_rest_of_line ();
6088 /* It's a conditional. */
6093 /* Since this might be a conditional if, this pseudo-op will be
6094 called even if we are supported to be ignoring input. Double
6095 check now. Clobber *input_line_pointer so that ignore_input
6096 thinks that this is not a special pseudo-op. */
6097 c = *input_line_pointer;
6098 *input_line_pointer = 0;
6099 if (ignore_input ())
6101 *input_line_pointer = c;
6102 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6103 ++input_line_pointer;
6104 demand_empty_rest_of_line ();
6107 *input_line_pointer = c;
6109 n = push_mri_control (mri_if);
6111 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6112 n->next, s[1] == '.' ? s[2] : '\0');
6115 input_line_pointer = s + 3;
6117 input_line_pointer = s + 1;
6121 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6122 ++input_line_pointer;
6125 demand_empty_rest_of_line ();
6128 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6129 structured IF, associate the ELSE with the IF. Otherwise, assume
6130 it is a conditional else. */
6141 && (mri_control_stack == NULL
6142 || mri_control_stack->type != mri_if
6143 || mri_control_stack->else_seen))
6149 c = *input_line_pointer;
6150 *input_line_pointer = 0;
6151 if (ignore_input ())
6153 *input_line_pointer = c;
6154 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6155 ++input_line_pointer;
6156 demand_empty_rest_of_line ();
6159 *input_line_pointer = c;
6161 if (mri_control_stack == NULL
6162 || mri_control_stack->type != mri_if
6163 || mri_control_stack->else_seen)
6165 as_bad (_("else without matching if"));
6166 ignore_rest_of_line ();
6170 mri_control_stack->else_seen = 1;
6172 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6173 q[0] = TOLOWER (qual);
6175 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6179 colon (mri_control_stack->next);
6183 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6184 ++input_line_pointer;
6187 demand_empty_rest_of_line ();
6190 /* Handle the MRI ENDI pseudo-op. */
6194 int ignore ATTRIBUTE_UNUSED;
6196 if (mri_control_stack == NULL
6197 || mri_control_stack->type != mri_if)
6199 as_bad (_("endi without matching if"));
6200 ignore_rest_of_line ();
6204 /* ignore_input will not return true for ENDI, so we don't need to
6205 worry about checking it again here. */
6207 if (! mri_control_stack->else_seen)
6208 colon (mri_control_stack->next);
6209 colon (mri_control_stack->bottom);
6215 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6216 ++input_line_pointer;
6219 demand_empty_rest_of_line ();
6222 /* Handle the MRI BREAK pseudo-op. */
6225 s_mri_break (extent)
6228 struct mri_control_info *n;
6232 n = mri_control_stack;
6234 && n->type != mri_for
6235 && n->type != mri_repeat
6236 && n->type != mri_while)
6240 as_bad (_("break outside of structured loop"));
6241 ignore_rest_of_line ();
6245 buf = (char *) xmalloc (20 + strlen (n->bottom));
6246 ex[0] = TOLOWER (extent);
6248 sprintf (buf, "bra%s %s", ex, n->bottom);
6254 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6255 ++input_line_pointer;
6258 demand_empty_rest_of_line ();
6261 /* Handle the MRI NEXT pseudo-op. */
6267 struct mri_control_info *n;
6271 n = mri_control_stack;
6273 && n->type != mri_for
6274 && n->type != mri_repeat
6275 && n->type != mri_while)
6279 as_bad (_("next outside of structured loop"));
6280 ignore_rest_of_line ();
6284 buf = (char *) xmalloc (20 + strlen (n->next));
6285 ex[0] = TOLOWER (extent);
6287 sprintf (buf, "bra%s %s", ex, n->next);
6293 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6294 ++input_line_pointer;
6297 demand_empty_rest_of_line ();
6300 /* Handle the MRI FOR pseudo-op. */
6306 const char *varstart, *varstop;
6307 const char *initstart, *initstop;
6308 const char *endstart, *endstop;
6309 const char *bystart, *bystop;
6313 struct mri_control_info *n;
6319 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6323 varstart = input_line_pointer;
6325 /* Look for the '='. */
6326 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6327 && *input_line_pointer != '=')
6328 ++input_line_pointer;
6329 if (*input_line_pointer != '=')
6331 as_bad (_("missing ="));
6332 ignore_rest_of_line ();
6336 varstop = input_line_pointer;
6337 if (varstop > varstart
6338 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6341 ++input_line_pointer;
6343 initstart = input_line_pointer;
6345 /* Look for TO or DOWNTO. */
6348 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6350 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6351 && ! is_part_of_name (input_line_pointer[2]))
6353 initstop = input_line_pointer;
6354 input_line_pointer += 2;
6357 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6358 && ! is_part_of_name (input_line_pointer[6]))
6360 initstop = input_line_pointer;
6362 input_line_pointer += 6;
6365 ++input_line_pointer;
6367 if (initstop == NULL)
6369 as_bad (_("missing to or downto"));
6370 ignore_rest_of_line ();
6373 if (initstop > initstart
6374 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6378 endstart = input_line_pointer;
6380 /* Look for BY or DO. */
6383 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6385 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6386 && ! is_part_of_name (input_line_pointer[2]))
6388 endstop = input_line_pointer;
6390 input_line_pointer += 2;
6393 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6394 && (input_line_pointer[2] == '.'
6395 || ! is_part_of_name (input_line_pointer[2])))
6397 endstop = input_line_pointer;
6398 input_line_pointer += 2;
6401 ++input_line_pointer;
6403 if (endstop == NULL)
6405 as_bad (_("missing do"));
6406 ignore_rest_of_line ();
6409 if (endstop > endstart
6410 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6416 bystop = bystart + 2;
6421 bystart = input_line_pointer;
6425 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6427 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6428 && (input_line_pointer[2] == '.'
6429 || ! is_part_of_name (input_line_pointer[2])))
6431 bystop = input_line_pointer;
6432 input_line_pointer += 2;
6435 ++input_line_pointer;
6439 as_bad (_("missing do"));
6440 ignore_rest_of_line ();
6443 if (bystop > bystart
6444 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6448 if (*input_line_pointer != '.')
6452 extent = input_line_pointer[1];
6453 input_line_pointer += 2;
6456 /* We have fully parsed the FOR operands. Now build the loop. */
6458 n = push_mri_control (mri_for);
6460 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6469 *s++ = TOLOWER (qual);
6471 memcpy (s, initstart, initstop - initstart);
6472 s += initstop - initstart;
6474 memcpy (s, varstart, varstop - varstart);
6475 s += varstop - varstart;
6487 *s++ = TOLOWER (qual);
6489 memcpy (s, endstart, endstop - endstart);
6490 s += endstop - endstart;
6492 memcpy (s, varstart, varstop - varstart);
6493 s += varstop - varstart;
6498 ex[0] = TOLOWER (extent);
6501 sprintf (buf, "blt%s %s", ex, n->bottom);
6503 sprintf (buf, "bgt%s %s", ex, n->bottom);
6506 /* Put together the add or sub instruction used by ENDF. */
6514 *s++ = TOLOWER (qual);
6516 memcpy (s, bystart, bystop - bystart);
6517 s += bystop - bystart;
6519 memcpy (s, varstart, varstop - varstart);
6520 s += varstop - varstart;
6526 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6527 ++input_line_pointer;
6530 demand_empty_rest_of_line ();
6533 /* Handle the MRI ENDF pseudo-op. */
6537 int ignore ATTRIBUTE_UNUSED;
6539 if (mri_control_stack == NULL
6540 || mri_control_stack->type != mri_for)
6542 as_bad (_("endf without for"));
6543 ignore_rest_of_line ();
6547 colon (mri_control_stack->next);
6549 mri_assemble (mri_control_stack->incr);
6551 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6552 mri_assemble (mri_control_stack->incr);
6554 free (mri_control_stack->incr);
6556 colon (mri_control_stack->bottom);
6562 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6563 ++input_line_pointer;
6566 demand_empty_rest_of_line ();
6569 /* Handle the MRI REPEAT pseudo-op. */
6572 s_mri_repeat (ignore)
6573 int ignore ATTRIBUTE_UNUSED;
6575 struct mri_control_info *n;
6577 n = push_mri_control (mri_repeat);
6581 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6582 ++input_line_pointer;
6584 demand_empty_rest_of_line ();
6587 /* Handle the MRI UNTIL pseudo-op. */
6595 if (mri_control_stack == NULL
6596 || mri_control_stack->type != mri_repeat)
6598 as_bad (_("until without repeat"));
6599 ignore_rest_of_line ();
6603 colon (mri_control_stack->next);
6605 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6608 parse_mri_control_expression (s, qual, (const char *) NULL,
6609 mri_control_stack->top, '\0');
6611 colon (mri_control_stack->bottom);
6613 input_line_pointer = s;
6619 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6620 ++input_line_pointer;
6623 demand_empty_rest_of_line ();
6626 /* Handle the MRI WHILE pseudo-op. */
6634 struct mri_control_info *n;
6636 s = input_line_pointer;
6637 /* We only accept '*' as introduction of comments if preceded by white space
6638 or at first column of a line (I think this can't actually happen here?)
6639 This is important when assembling:
6640 while d0 <ne> 12(a0,d0*2) do
6641 while d0 <ne> #CONST*20 do */
6642 while ( ! ( is_end_of_line[(unsigned char) *s]
6645 && ( s == input_line_pointer
6647 || *(s-1) == '\t'))))
6650 while (*s == ' ' || *s == '\t')
6652 if (s - input_line_pointer > 1
6655 if (s - input_line_pointer < 2
6656 || strncasecmp (s - 1, "DO", 2) != 0)
6658 as_bad (_("missing do"));
6659 ignore_rest_of_line ();
6663 n = push_mri_control (mri_while);
6667 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6668 s[1] == '.' ? s[2] : '\0');
6670 input_line_pointer = s + 1;
6671 if (*input_line_pointer == '.')
6672 input_line_pointer += 2;
6676 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6677 ++input_line_pointer;
6680 demand_empty_rest_of_line ();
6683 /* Handle the MRI ENDW pseudo-op. */
6687 int ignore ATTRIBUTE_UNUSED;
6691 if (mri_control_stack == NULL
6692 || mri_control_stack->type != mri_while)
6694 as_bad (_("endw without while"));
6695 ignore_rest_of_line ();
6699 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
6700 sprintf (buf, "bra %s", mri_control_stack->next);
6704 colon (mri_control_stack->bottom);
6710 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6711 ++input_line_pointer;
6714 demand_empty_rest_of_line ();
6719 * Invocation line includes a switch not recognized by the base assembler.
6720 * See if it's a processor-specific option. These are:
6722 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6723 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6724 * Select the architecture. Instructions or features not
6725 * supported by the selected architecture cause fatal
6726 * errors. More than one may be specified. The default is
6727 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6728 * for -m68000, and -m68882 is a synonym for -m68881.
6729 * -[A]m[c]no-68851, -[A]m[c]no-68881
6730 * Don't accept 688?1 instructions. (The "c" is kind of silly,
6731 * so don't use or document it, but that's the way the parsing
6734 * -pic Indicates PIC.
6735 * -k Indicates PIC. (Sun 3 only.)
6736 * --pcrel Never turn PC-relative branches into absolute jumps.
6739 * Permit `|' to be used in expressions.
6744 CONST char *md_shortopts = "lSA:m:kQ:V";
6746 CONST char *md_shortopts = "lSA:m:k";
6749 struct option md_longopts[] = {
6750 #define OPTION_PIC (OPTION_MD_BASE)
6751 {"pic", no_argument, NULL, OPTION_PIC},
6752 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6753 {"register-prefix-optional", no_argument, NULL,
6754 OPTION_REGISTER_PREFIX_OPTIONAL},
6755 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6756 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
6757 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6758 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
6759 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6760 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
6761 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6762 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
6763 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6764 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
6765 #define OPTION_PCREL (OPTION_MD_BASE + 7)
6766 {"pcrel", no_argument, NULL, OPTION_PCREL},
6767 {NULL, no_argument, NULL, 0}
6769 size_t md_longopts_size = sizeof (md_longopts);
6772 md_parse_option (c, arg)
6778 case 'l': /* -l means keep external to 2 bit offset
6779 rather than 16 bit one */
6780 flag_short_refs = 1;
6783 case 'S': /* -S means that jbsr's always turn into
6785 flag_long_jumps = 1;
6788 case OPTION_PCREL: /* --pcrel means never turn PC-relative
6789 branches into absolute jumps. */
6790 flag_keep_pcrel = 1;
6796 /* intentional fall-through */
6799 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
6803 const char *oarg = arg;
6809 if (arg[0] == 'c' && arg[1] == '6')
6812 for (i = 0; i < n_archs; i++)
6813 if (!strcmp (arg, archs[i].name))
6818 as_bad (_("unrecognized option `%s'"), oarg);
6821 arch = archs[i].arch;
6824 else if (arch == m68851)
6833 if (arg[0] == 'c' && arg[1] == '6')
6836 for (i = 0; i < n_archs; i++)
6837 if (!strcmp (arg, archs[i].name))
6839 unsigned long arch = archs[i].arch;
6840 if (cpu_of_arch (arch))
6841 /* It's a cpu spec. */
6843 current_architecture &= ~m68000up;
6844 current_architecture |= arch;
6846 else if (arch == m68881)
6848 current_architecture |= m68881;
6851 else if (arch == m68851)
6853 current_architecture |= m68851;
6863 as_bad (_("unrecognized architecture specification `%s'"), arg);
6872 break; /* -pic, Position Independent Code */
6874 case OPTION_REGISTER_PREFIX_OPTIONAL:
6875 flag_reg_prefix_optional = 1;
6876 reg_prefix_optional_seen = 1;
6879 /* -V: SVR4 argument to print version ID. */
6881 print_version_id ();
6884 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6885 should be emitted or not. FIXME: Not implemented. */
6889 case OPTION_BITWISE_OR:
6894 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
6896 for (s = m68k_comment_chars; *s != '\0'; s++)
6900 m68k_comment_chars = n;
6904 case OPTION_BASE_SIZE_DEFAULT_16:
6905 m68k_index_width_default = SIZE_WORD;
6908 case OPTION_BASE_SIZE_DEFAULT_32:
6909 m68k_index_width_default = SIZE_LONG;
6912 case OPTION_DISP_SIZE_DEFAULT_16:
6914 m68k_rel32_from_cmdline = 1;
6917 case OPTION_DISP_SIZE_DEFAULT_32:
6919 m68k_rel32_from_cmdline = 1;
6930 md_show_usage (stream)
6933 fprintf (stream, _("\
6935 -l use 1 word for refs to undefined symbols [default 2]\n\
6936 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
6937 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
6938 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m5307 | -m5407\n\
6939 specify variant of 680X0 architecture [default 68020]\n\
6940 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
6941 target has/lacks floating-point coprocessor\n\
6942 [default yes for 68020, 68030, and cpu32]\n"));
6943 fprintf (stream, _("\
6944 -m68851 | -mno-68851\n\
6945 target has/lacks memory-management unit coprocessor\n\
6946 [default yes for 68020 and up]\n\
6947 -pic, -k generate position independent code\n\
6948 -S turn jbsr into jsr\n\
6949 --pcrel never turn PC-relative branches into absolute jumps\n\
6950 --register-prefix-optional\n\
6951 recognize register names without prefix character\n\
6952 --bitwise-or do not treat `|' as a comment character\n"));
6953 fprintf (stream, _("\
6954 --base-size-default-16 base reg without size is 16 bits\n\
6955 --base-size-default-32 base reg without size is 32 bits (default)\n\
6956 --disp-size-default-16 displacement with unknown size is 16 bits\n\
6957 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
6962 /* TEST2: Test md_assemble() */
6963 /* Warning, this routine probably doesn't work anymore */
6967 struct m68k_it the_ins;
6975 if (!gets (buf) || !*buf)
6977 if (buf[0] == '|' || buf[1] == '.')
6979 for (cp = buf; *cp; cp++)
6984 memset (&the_ins, '\0', sizeof (the_ins));
6985 m68k_ip (&the_ins, buf);
6988 printf (_("Error %s in %s\n"), the_ins.error, buf);
6992 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
6993 for (n = 0; n < the_ins.numo; n++)
6994 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
6996 print_the_insn (&the_ins.opcode[0], stdout);
6997 (void) putchar ('\n');
6999 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7001 if (the_ins.operands[n].error)
7003 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7006 printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
7007 if (the_ins.operands[n].b_const)
7008 printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
7009 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
7010 if (the_ins.operands[n].b_iadd)
7011 printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
7012 (void) putchar ('\n');
7024 while (*str && *str != ' ')
7026 if (str[-1] == ':' || str[1] == '=')
7033 /* Possible states for relaxation:
7035 0 0 branch offset byte (bra, etc)
7039 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7043 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7050 /* We have no need to default values of symbols. */
7053 md_undefined_symbol (name)
7054 char *name ATTRIBUTE_UNUSED;
7059 /* Round up a section size to the appropriate boundary. */
7061 md_section_align (segment, size)
7062 segT segment ATTRIBUTE_UNUSED;
7066 #ifdef BFD_ASSEMBLER
7067 /* For a.out, force the section size to be aligned. If we don't do
7068 this, BFD will align it for us, but it will not write out the
7069 final bytes of the section. This may be a bug in BFD, but it is
7070 easier to fix it here since that is how the other a.out targets
7074 align = bfd_get_section_alignment (stdoutput, segment);
7075 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7082 /* Exactly what point is a PC-relative offset relative TO?
7083 On the 68k, it is relative to the address of the first extension
7084 word. The difference between the addresses of the offset and the
7085 first extension word is stored in fx_pcrel_adjust. */
7087 md_pcrel_from (fixP)
7092 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7093 sign extend the value here. */
7094 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7097 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7100 #ifndef BFD_ASSEMBLER
7104 tc_coff_symbol_emit_hook (ignore)
7105 symbolS *ignore ATTRIBUTE_UNUSED;
7110 tc_coff_sizemachdep (frag)
7113 switch (frag->fr_subtype & 0x3)
7130 void m68k_elf_final_processing()
7132 /* Set file-specific flags if this is a cpu32 processor */
7133 if (cpu_of_arch (current_architecture) & cpu32)
7134 elf_elfheader (stdoutput)->e_flags |= EF_CPU32;