1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/m68k.h"
28 #include "m68k-parse.h"
30 /* This array holds the chars that always start a comment. If the
31 pre-processor is disabled, these aren't very useful */
33 CONST
char comment_chars
[] = "|#";
35 CONST
char comment_chars
[] = "|";
38 /* This array holds the chars that only start a comment at the beginning of
39 a line. If the line seems to have the form '# 123 filename'
40 .line and .file directives will appear in the pre-processed output */
41 /* Note that input_file.c hand checks for '#' at the beginning of the
42 first line of the input file. This is because the compiler outputs
43 #NO_APP at the beginning of its output. */
44 /* Also note that comments like this one will always work. */
45 CONST
char line_comment_chars
[] = "#";
47 CONST
char line_separator_chars
[] = "";
49 /* Chars that can be used to separate mant from exp in floating point nums */
50 CONST
char EXP_CHARS
[] = "eE";
52 /* Chars that mean this number is a floating point constant, as
53 in "0f12.456" or "0d1.2345e12". */
55 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
57 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
58 changed in read.c . Ideally it shouldn't have to know about it at all,
59 but nothing is ideal around here. */
61 const int md_reloc_size
= 8; /* Size of relocation record */
63 /* Are we trying to generate PIC code? If so, absolute references
64 ought to be made into linkage table references or pc-relative
68 static int flag_short_refs
; /* -l option */
69 static int flag_long_jumps
; /* -S option */
71 #ifdef REGISTER_PREFIX_OPTIONAL
72 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
74 int flag_reg_prefix_optional
;
77 /* The floating point coprocessor to use by default. */
78 static enum m68k_register m68k_float_copnum
= COP1
;
80 /* If this is non-zero, then references to number(%pc) will be taken
81 to refer to number, rather than to %pc + number. */
82 static int m68k_abspcadd
;
84 /* If this is non-zero, then the quick forms of the move, add, and sub
85 instructions are used when possible. */
86 static int m68k_quick
= 1;
88 /* If this is non-zero, then if the size is not specified for a base
89 or outer displacement, the assembler assumes that the size should
91 static int m68k_rel32
= 1;
93 /* Its an arbitrary name: This means I don't approve of it */
94 /* See flames below */
95 static struct obstack robyn
;
97 #define TAB(x,y) (((x)<<2)+(y))
98 #define TABTYPE(xy) ((xy) >> 2)
104 /* Case `g' except when BCC68000 is applicable. */
106 /* Coprocessor branches. */
108 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
109 supported on all cpus. Widens to 32-bit absolute. */
111 /* For inserting an extra jmp instruction with long offset on 68000,
112 for expanding conditional branches. (Not bsr or bra.) Since the
113 68000 doesn't support 32-bit displacements for conditional
114 branches, we fake it by reversing the condition and branching
115 around a jmp with an absolute long operand. */
117 /* For the DBcc "instructions". If the displacement requires 32 bits,
118 the branch-around-a-jump game is played here too. */
120 /* Not currently used? */
122 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
128 const char *m_operands
;
129 unsigned long m_opcode
;
133 struct m68k_incant
*m_next
;
136 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
137 #define gettwo(x) (((x)->m_opcode)&0xffff)
139 static const enum m68k_register m68000_control_regs
[] = { 0 };
140 static const enum m68k_register m68010_control_regs
[] = {
144 static const enum m68k_register m68020_control_regs
[] = {
145 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
148 static const enum m68k_register m68040_control_regs
[] = {
149 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
150 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
153 static const enum m68k_register m68060_control_regs
[] = {
154 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
155 USP
, VBR
, URP
, SRP
, PCR
,
158 #define cpu32_control_regs m68010_control_regs
160 static const enum m68k_register
*control_regs
;
162 /* internal form of a 68020 instruction */
166 const char *args
; /* list of opcode info */
169 int numo
; /* Number of shorts in opcode */
172 struct m68k_op operands
[6];
174 int nexp
; /* number of exprs in use */
175 struct m68k_exp exprs
[4];
177 int nfrag
; /* Number of frags we have to produce */
180 int fragoff
; /* Where in the current opcode the frag ends */
187 int nrel
; /* Num of reloc strucs in use */
194 /* In a pc relative address the difference between the address
195 of the offset and the address that the offset is relative
196 to. This depends on the addressing mode. Basically this
197 is the value to put in the offset field to address the
198 first byte of the offset, without regarding the special
199 significance of some values (in the branch instruction, for
203 reloc
[5]; /* Five is enough??? */
206 #define cpu_of_arch(x) ((x) & m68000up)
207 #define float_of_arch(x) ((x) & mfloat)
208 #define mmu_of_arch(x) ((x) & mmmu)
210 static struct m68k_it the_ins
; /* the instruction being assembled */
212 #define op(ex) ((ex)->exp.X_op)
213 #define adds(ex) ((ex)->exp.X_add_symbol)
214 #define subs(ex) ((ex)->exp.X_op_symbol)
215 #define offs(ex) ((ex)->exp.X_add_number)
217 /* Macros for adding things to the m68k_it struct */
219 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
221 /* Like addword, but goes BEFORE general operands */
225 struct m68k_incant
*opcode
;
228 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
229 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
230 for(z
=0;z
<the_ins
.nrel
;z
++)
231 the_ins
.reloc
[z
].n
+=2;
232 for (z
= 0; z
< the_ins
.nfrag
; z
++)
233 the_ins
.fragb
[z
].fragoff
++;
234 the_ins
.opcode
[opcode
->m_codenum
]=w
;
238 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
241 add_fix (width
, exp
, pc_rel
, pc_fix
)
243 struct m68k_exp
*exp
;
247 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
251 : (the_ins
.numo
*2)));
252 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
253 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
254 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
255 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
258 /* Cause an extra frag to be generated here, inserting up to 10 bytes
259 (that value is chosen in the frag_var call in md_assemble). TYPE
260 is the subtype of the frag to be generated; its primary type is
261 rs_machine_dependent.
263 The TYPE parameter is also used by md_convert_frag_1 and
264 md_estimate_size_before_relax. The appropriate type of fixup will
265 be emitted by md_convert_frag_1.
267 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
269 add_frag(add
,off
,type
)
274 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
275 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
276 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
277 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
281 (op (ex) != O_constant && op (ex) != O_big)
283 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
284 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
285 static int reverse_16_bits
PARAMS ((int in
));
286 static int reverse_8_bits
PARAMS ((int in
));
287 static void install_gen_operand
PARAMS ((int mode
, int val
));
288 static void install_operand
PARAMS ((int mode
, int val
));
289 static void s_bss
PARAMS ((int));
290 static void s_data1
PARAMS ((int));
291 static void s_data2
PARAMS ((int));
292 static void s_even
PARAMS ((int));
293 static void s_proc
PARAMS ((int));
294 static void mri_chip
PARAMS ((void));
295 static void s_chip
PARAMS ((int));
296 static void s_fopt
PARAMS ((int));
297 static void s_opt
PARAMS ((int));
298 static void s_reg
PARAMS ((int));
299 static void s_restore
PARAMS ((int));
300 static void s_save
PARAMS ((int));
301 static void s_mri_if
PARAMS ((int));
302 static void s_mri_else
PARAMS ((int));
303 static void s_mri_endi
PARAMS ((int));
304 static void s_mri_break
PARAMS ((int));
305 static void s_mri_next
PARAMS ((int));
306 static void s_mri_for
PARAMS ((int));
307 static void s_mri_endf
PARAMS ((int));
308 static void s_mri_repeat
PARAMS ((int));
309 static void s_mri_until
PARAMS ((int));
310 static void s_mri_while
PARAMS ((int));
311 static void s_mri_endw
PARAMS ((int));
313 static int current_architecture
;
320 static const struct m68k_cpu archs
[] = {
330 /* Aliases (effectively, so far as gas is concerned) for the above
335 { m68000
, "68ec000" },
336 { m68000
, "68hc000" },
337 { m68000
, "68hc001" },
338 { m68020
, "68ec020" },
339 { m68030
, "68ec030" },
340 { m68040
, "68ec040" },
350 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
352 /* BCC68000 is for patching in an extra jmp instruction for long offsets
353 on the 68000. The 68000 doesn't support long branches with branchs */
355 /* This table desribes how you change sizes for the various types of variable
356 size expressions. This version only supports two kinds. */
358 /* Note that calls to frag_var need to specify the maximum expansion
359 needed; this is currently 10 bytes for DBCC. */
362 How far Forward this mode will reach:
363 How far Backward this mode will reach:
364 How many bytes this mode will add to the size of the frag
365 Which mode to go to if the offset won't fit in this one
367 relax_typeS md_relax_table
[] =
369 {1, 1, 0, 0}, /* First entries aren't used */
370 {1, 1, 0, 0}, /* For no good reason except */
371 {1, 1, 0, 0}, /* that the VAX doesn't either */
374 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
375 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
379 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
380 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
384 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
385 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
389 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
390 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
391 {0, 0, 6, 0}, /* jmp long space */
394 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
395 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
396 {0, 0, 10, 0}, /* bra/jmp long space */
399 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
400 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
404 /* For, e.g., jmp pcrel indexed. */
405 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
406 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
411 /* These are the machine dependent pseudo-ops. These are included so
412 the assembler can work on the output from the SUN C compiler, which
416 /* This table describes all the machine specific pseudo-ops the assembler
417 has to support. The fields are:
418 pseudo-op name without dot
419 function to call to execute this pseudo-op
420 Integer arg to pass to the function
422 CONST pseudo_typeS md_pseudo_table
[] =
424 {"data1", s_data1
, 0},
425 {"data2", s_data2
, 0},
428 {"skip", s_space
, 0},
431 {"align", s_align_bytes
, 0},
434 {"swbeg", s_ignore
, 0},
437 /* The following pseudo-ops are supported for MRI compatibility. */
439 {"comline", s_space
, 1},
441 {"mask2", s_ignore
, 0},
444 {"restore", s_restore
, 0},
448 {"if.b", s_mri_if
, 'b'},
449 {"if.w", s_mri_if
, 'w'},
450 {"if.l", s_mri_if
, 'l'},
451 {"else", s_mri_else
, 0},
452 {"else.s", s_mri_else
, 's'},
453 {"else.l", s_mri_else
, 'l'},
454 {"endi", s_mri_endi
, 0},
455 {"break", s_mri_break
, 0},
456 {"break.s", s_mri_break
, 's'},
457 {"break.l", s_mri_break
, 'l'},
458 {"next", s_mri_next
, 0},
459 {"next.s", s_mri_next
, 's'},
460 {"next.l", s_mri_next
, 'l'},
461 {"for", s_mri_for
, 0},
462 {"for.b", s_mri_for
, 'b'},
463 {"for.w", s_mri_for
, 'w'},
464 {"for.l", s_mri_for
, 'l'},
465 {"endf", s_mri_endf
, 0},
466 {"repeat", s_mri_repeat
, 0},
467 {"until", s_mri_until
, 0},
468 {"until.b", s_mri_until
, 'b'},
469 {"until.w", s_mri_until
, 'w'},
470 {"until.l", s_mri_until
, 'l'},
471 {"while", s_mri_while
, 0},
472 {"while.b", s_mri_while
, 'b'},
473 {"while.w", s_mri_while
, 'w'},
474 {"while.l", s_mri_while
, 'l'},
475 {"endw", s_mri_endw
, 0},
481 /* The mote pseudo ops are put into the opcode table, since they
482 don't start with a . they look like opcodes to gas.
484 extern void obj_coff_section ();
486 CONST pseudo_typeS mote_pseudo_table
[] =
499 {"xdef", s_globl
, 0},
500 {"align", s_align_ptwo
, 0},
502 {"sect", obj_coff_section
, 0},
503 {"section", obj_coff_section
, 0},
508 #define issbyte(x) ((x)>=-128 && (x)<=127)
509 #define isubyte(x) ((x)>=0 && (x)<=255)
510 #define issword(x) ((x)>=-32768 && (x)<=32767)
511 #define isuword(x) ((x)>=0 && (x)<=65535)
513 #define isbyte(x) ((x)>= -255 && (x)<=255)
514 #define isword(x) ((x)>=-32768 && (x)<=65535)
515 #define islong(x) (1)
517 extern char *input_line_pointer
;
519 static char mklower_table
[256];
520 #define mklower(c) (mklower_table[(unsigned char)(c)])
521 static char notend_table
[256];
522 static char alt_notend_table
[256];
524 (! (notend_table[(unsigned char) *s] \
526 && alt_notend_table[(unsigned char) s[1]])))
528 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
530 #ifdef NO_PCREL_RELOCS
533 make_pcrel_absolute(fixP
, add_number
)
537 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
539 /* rewrite the PC relative instructions to absolute address ones.
540 * these are rumoured to be faster, and the apollo linker refuses
541 * to deal with the PC relative relocations.
543 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
548 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
554 as_fatal ("Unknown PC relative instruction");
559 #endif /* NO_PCREL_RELOCS */
562 tc_coff_fix2rtype (fixP
)
565 #ifdef NO_PCREL_RELOCS
566 know (fixP
->fx_pcrel
== 0);
567 return (fixP
->fx_size
== 1 ? R_RELBYTE
568 : fixP
->fx_size
== 2 ? R_DIR16
571 return (fixP
->fx_pcrel
?
572 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
573 fixP
->fx_size
== 2 ? R_PCRWORD
:
575 (fixP
->fx_size
== 1 ? R_RELBYTE
:
576 fixP
->fx_size
== 2 ? R_RELWORD
:
586 tc_gen_reloc (section
, fixp
)
591 bfd_reloc_code_real_type code
;
593 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
594 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
596 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
597 MAP (1, 0, BFD_RELOC_8
);
598 MAP (2, 0, BFD_RELOC_16
);
599 MAP (4, 0, BFD_RELOC_32
);
600 MAP (1, 1, BFD_RELOC_8_PCREL
);
601 MAP (2, 1, BFD_RELOC_16_PCREL
);
602 MAP (4, 1, BFD_RELOC_32_PCREL
);
607 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
609 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
610 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
612 reloc
->addend
= fixp
->fx_addnumber
;
616 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
617 assert (reloc
->howto
!= 0);
622 #endif /* BFD_ASSEMBLER */
624 /* Handle of the OPCODE hash table. NULL means any use before
625 m68k_ip_begin() will crash. */
626 static struct hash_control
*op_hash
;
628 /* Assemble an m68k instruction. */
635 register struct m68k_op
*opP
;
636 register struct m68k_incant
*opcode
;
637 register const char *s
;
638 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
639 char *pdot
, *pdotmove
;
640 enum m68k_size siz1
, siz2
;
644 char *crack_operand ();
645 LITTLENUM_TYPE words
[6];
646 LITTLENUM_TYPE
*wordp
;
647 unsigned long ok_arch
= 0;
649 if (*instring
== ' ')
650 instring
++; /* skip leading whitespace */
652 /* Scan up to end of operation-code, which MUST end in end-of-string
653 or exactly 1 space. */
655 for (p
= instring
; *p
!= '\0'; p
++)
665 the_ins
.error
= "No operator";
669 /* p now points to the end of the opcode name, probably whitespace.
670 Make sure the name is null terminated by clobbering the
671 whitespace, look it up in the hash table, then fix it back.
672 Remove a dot, first, since the opcode tables have none. */
675 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
676 *pdotmove
= pdotmove
[1];
682 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
687 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
688 *pdotmove
= pdotmove
[-1];
695 the_ins
.error
= "Unknown operator";
699 /* found a legitimate opcode, start matching operands */
703 if (opcode
->m_operands
== 0)
705 char *old
= input_line_pointer
;
707 input_line_pointer
= p
;
708 /* Ahh - it's a motorola style psuedo op */
709 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
710 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
711 input_line_pointer
= old
;
717 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
719 p
= crack_operand (p
, opP
);
723 the_ins
.error
= opP
->error
;
728 opsfound
= opP
- &the_ins
.operands
[0];
730 /* This ugly hack is to support the floating pt opcodes in their
731 standard form. Essentially, we fake a first enty of type COP#1 */
732 if (opcode
->m_operands
[0] == 'I')
736 for (n
= opsfound
; n
> 0; --n
)
737 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
739 memset ((char *) (&the_ins
.operands
[0]), '\0',
740 sizeof (the_ins
.operands
[0]));
741 the_ins
.operands
[0].mode
= CONTROL
;
742 the_ins
.operands
[0].reg
= m68k_float_copnum
;
746 /* We've got the operands. Find an opcode that'll accept them */
749 /* If we didn't get the right number of ops, or we have no
750 common model with this pattern then reject this pattern. */
752 if (opsfound
!= opcode
->m_opnum
753 || ((opcode
->m_arch
& current_architecture
) == 0))
756 ok_arch
|= opcode
->m_arch
;
760 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
764 /* Warning: this switch is huge! */
765 /* I've tried to organize the cases into this order:
766 non-alpha first, then alpha by letter. Lower-case
767 goes directly before uppercase counterpart. */
768 /* Code with multiple case ...: gets sorted by the lowest
769 case ... it belongs to. I hope this makes sense. */
809 if (opP
->mode
!= IMMED
)
812 && ! isvar (&opP
->disp
)
813 && (opP
->disp
.exp
.X_op
!= O_constant
814 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
817 && ! isvar (&opP
->disp
)
818 && (opP
->disp
.exp
.X_op
!= O_constant
819 || ! isword (opP
->disp
.exp
.X_add_number
)))
825 if (opP
->mode
!= IMMED
)
830 if (opP
->mode
== AREG
831 || opP
->mode
== CONTROL
832 || opP
->mode
== FPREG
833 || opP
->mode
== IMMED
834 || opP
->mode
== REGLST
835 || (opP
->mode
!= ABSL
837 || opP
->reg
== ZPC
)))
842 if (opP
->mode
== CONTROL
843 || opP
->mode
== FPREG
844 || opP
->mode
== REGLST
845 || (opP
->mode
!= ABSL
846 && opP
->mode
!= IMMED
848 || opP
->reg
== ZPC
)))
876 if (opP
->mode
== CONTROL
877 || opP
->mode
== FPREG
878 || opP
->mode
== REGLST
)
883 if (opP
->mode
!= AINC
)
888 if (opP
->mode
!= ADEC
)
938 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
959 case '~': /* For now! (JF FOO is this right?) */
981 if (opP
->mode
!= CONTROL
982 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
987 if (opP
->mode
!= AREG
)
992 if (opP
->mode
!= AINDR
)
997 if (opP
->mode
!= ABSL
999 && strncmp (instring
, "jbsr", 4) == 0))
1004 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
1009 if (opP
->mode
!= DISP
1011 || opP
->reg
> ADDR7
)
1016 if (opP
->mode
!= DREG
)
1021 if (opP
->mode
!= FPREG
)
1026 if (opP
->mode
!= CONTROL
1033 if (opP
->mode
!= CONTROL
1035 || opP
->reg
> last_movec_reg
)
1039 const enum m68k_register
*rp
;
1040 for (rp
= control_regs
; *rp
; rp
++)
1041 if (*rp
== opP
->reg
)
1049 if (opP
->mode
!= IMMED
)
1055 if (opP
->mode
== DREG
1056 || opP
->mode
== AREG
1057 || opP
->mode
== FPREG
)
1066 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1069 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1072 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1080 else if (opP
->mode
== CONTROL
)
1089 opP
->mask
= 1 << 24;
1092 opP
->mask
= 1 << 25;
1095 opP
->mask
= 1 << 26;
1104 else if (opP
->mode
== ABSL
1105 && opP
->disp
.size
== SIZE_UNSPEC
1106 && opP
->disp
.exp
.X_op
== O_constant
)
1108 /* This is what the MRI REG pseudo-op generates. */
1110 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1112 else if (opP
->mode
!= REGLST
)
1114 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1116 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1121 if (opP
->mode
!= IMMED
)
1123 else if (opP
->disp
.exp
.X_op
!= O_constant
1124 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1126 else if (! m68k_quick
1127 && instring
[3] != 'q'
1128 && instring
[4] != 'q')
1133 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1138 if (opP
->mode
!= IMMED
)
1140 else if (opP
->disp
.exp
.X_op
!= O_constant
1141 || opP
->disp
.exp
.X_add_number
< 1
1142 || opP
->disp
.exp
.X_add_number
> 8)
1144 else if (! m68k_quick
1145 && (strncmp (instring
, "add", 3) == 0
1146 || strncmp (instring
, "sub", 3) == 0)
1147 && instring
[3] != 'q')
1152 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1157 if (opP
->mode
!= AINDR
1158 && (opP
->mode
!= BASE
1160 && opP
->reg
!= ZADDR0
)
1161 || opP
->disp
.exp
.X_op
!= O_absent
1162 || ((opP
->index
.reg
< DATA0
1163 || opP
->index
.reg
> DATA7
)
1164 && (opP
->index
.reg
< ADDR0
1165 || opP
->index
.reg
> ADDR7
))
1166 || opP
->index
.size
!= SIZE_UNSPEC
1167 || opP
->index
.scale
!= 1))
1172 if (opP
->mode
!= CONTROL
1173 || ! (opP
->reg
== FPI
1175 || opP
->reg
== FPC
))
1180 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1185 if (opP
->mode
!= IMMED
)
1187 else if (opP
->disp
.exp
.X_op
!= O_constant
1188 || opP
->disp
.exp
.X_add_number
< 0
1189 || opP
->disp
.exp
.X_add_number
> 7)
1194 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1198 /* JF these are out of order. We could put them
1199 in order if we were willing to put up with
1200 bunches of #ifdef m68851s in the code.
1202 Don't forget that you need these operands
1203 to use 68030 MMU instructions. */
1205 /* Memory addressing mode used by pflushr */
1207 if (opP
->mode
== CONTROL
1208 || opP
->mode
== FPREG
1209 || opP
->mode
== DREG
1210 || opP
->mode
== AREG
1211 || opP
->mode
== REGLST
)
1216 if (opP
->mode
!= CONTROL
1217 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1222 if (opP
->mode
!= CONTROL
1232 if (opP
->mode
!= CONTROL
1238 if (opP
->mode
!= CONTROL
1241 && opP
->reg
!= CRP
))
1246 if (opP
->mode
!= CONTROL
1247 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1248 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1253 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1258 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1263 if (opP
->mode
!= CONTROL
1270 } /* not a cache specifier. */
1274 if (opP
->mode
!= ABSL
)
1280 } /* switch on type of operand */
1284 } /* for each operand */
1285 } /* if immediately wrong */
1292 opcode
= opcode
->m_next
;
1297 && !(ok_arch
& current_architecture
))
1302 "invalid instruction for this architecture; needs ");
1303 cp
= buf
+ strlen (buf
);
1307 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1310 strcpy (cp
, "mmu (68030 or 68851)");
1313 strcpy (cp
, "68020 or higher");
1316 strcpy (cp
, "68000 or higher");
1319 strcpy (cp
, "68010 or higher");
1323 int got_one
= 0, idx
;
1324 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1327 if (archs
[idx
].arch
& ok_arch
)
1331 strcpy (cp
, " or ");
1335 strcpy (cp
, archs
[idx
].name
);
1347 the_ins
.error
= "operands mismatch";
1349 } /* Fell off the end */
1354 /* now assemble it */
1356 the_ins
.args
= opcode
->m_operands
;
1357 the_ins
.numargs
= opcode
->m_opnum
;
1358 the_ins
.numo
= opcode
->m_codenum
;
1359 the_ins
.opcode
[0] = getone (opcode
);
1360 the_ins
.opcode
[1] = gettwo (opcode
);
1362 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1364 /* This switch is a doozy.
1365 Watch the first step; its a big one! */
1386 tmpreg
= 0x3c; /* 7.4 */
1387 if (strchr ("bwl", s
[1]))
1388 nextword
= get_num (&opP
->disp
, 80);
1390 nextword
= get_num (&opP
->disp
, 0);
1391 if (isvar (&opP
->disp
))
1392 add_fix (s
[1], &opP
->disp
, 0, 0);
1396 if (!isbyte (nextword
))
1397 opP
->error
= "operand out of range";
1402 if (!isword (nextword
))
1403 opP
->error
= "operand out of range";
1408 addword (nextword
>> 16);
1435 /* We gotta put out some float */
1436 if (op (&opP
->disp
) != O_big
)
1441 /* Can other cases happen here? */
1442 if (op (&opP
->disp
) != O_constant
)
1445 val
= (valueT
) offs (&opP
->disp
);
1449 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1450 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1454 offs (&opP
->disp
) = gencnt
;
1456 if (offs (&opP
->disp
) > 0)
1458 if (offs (&opP
->disp
) > baseo
)
1460 as_warn ("Bignum too big for %c format; truncated",
1462 offs (&opP
->disp
) = baseo
;
1464 baseo
-= offs (&opP
->disp
);
1467 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1468 offs (&opP
->disp
)--;
1473 gen_to_words (words
, baseo
, (long) outro
);
1474 for (wordp
= words
; baseo
--; wordp
++)
1478 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1481 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1484 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1487 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1490 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1494 nextword
= get_num (&opP
->disp
, 80);
1497 && ! isvar (&opP
->disp
)
1500 opP
->disp
.exp
.X_op
= O_symbol
;
1501 #ifndef BFD_ASSEMBLER
1502 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1504 opP
->disp
.exp
.X_add_symbol
=
1505 section_symbol (absolute_section
);
1509 /* Force into index mode. Hope this works */
1511 /* We do the first bit for 32-bit displacements, and the
1512 second bit for 16 bit ones. It is possible that we
1513 should make the default be WORD instead of LONG, but
1514 I think that'd break GCC, so we put up with a little
1515 inefficiency for the sake of working output. */
1517 if (!issword (nextword
)
1518 || (isvar (&opP
->disp
)
1519 && ((opP
->disp
.size
== SIZE_UNSPEC
1520 && flag_short_refs
== 0
1521 && cpu_of_arch (current_architecture
) >= m68020
)
1522 || opP
->disp
.size
== SIZE_LONG
)))
1525 tmpreg
= 0x3B; /* 7.3 */
1527 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1528 if (isvar (&opP
->disp
))
1534 add_fix ('l', &opP
->disp
, 1, 2);
1535 addword (0), addword (0);
1537 add_frag (adds (&opP
->disp
),
1539 TAB (PCLEA
, SZ_UNDEF
));
1546 add_fix ('l', &opP
->disp
, 0, 0);
1551 addword (nextword
>> 16);
1556 tmpreg
= 0x3A; /* 7.2 */
1558 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1560 if (isvar (&opP
->disp
))
1564 add_fix ('w', &opP
->disp
, 1, 0);
1567 add_fix ('w', &opP
->disp
, 0, 0);
1577 baseo
= get_num (&opP
->disp
, 80);
1578 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1579 outro
= get_num (&opP
->odisp
, 80);
1580 /* Figure out the `addressing mode'.
1581 Also turn on the BASE_DISABLE bit, if needed. */
1582 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1584 tmpreg
= 0x3b; /* 7.3 */
1585 if (opP
->reg
== ZPC
)
1588 else if (opP
->reg
== 0)
1591 tmpreg
= 0x30; /* 6.garbage */
1593 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
1596 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
1599 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1601 siz1
= opP
->disp
.size
;
1602 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1603 siz2
= opP
->odisp
.size
;
1607 /* Index register stuff */
1608 if (opP
->index
.reg
!= 0
1609 && opP
->index
.reg
>= DATA
1610 && opP
->index
.reg
<= ADDR7
)
1612 nextword
|= (opP
->index
.reg
- DATA
) << 12;
1614 if (opP
->index
.size
== SIZE_UNSPEC
1615 || opP
->index
.size
== SIZE_LONG
)
1618 if (cpu_of_arch (current_architecture
) < m68020
)
1620 if (opP
->index
.scale
!= 1)
1623 "scale factor invalid on this architecture; needs 68020 or higher";
1627 switch (opP
->index
.scale
)
1644 GET US OUT OF HERE! */
1646 /* Must be INDEX, with an index register. Address
1647 register cannot be ZERO-PC, and either :b was
1648 forced, or we know it will fit. For a 68000 or
1649 68010, force this mode anyways, because the
1650 larger modes aren't supported. */
1651 if (opP
->mode
== BASE
1652 && ((opP
->reg
>= ADDR0
1653 && opP
->reg
<= ADDR7
)
1656 if (siz1
== SIZE_BYTE
1657 || cpu_of_arch (current_architecture
) < m68020
1658 || (siz1
== SIZE_UNSPEC
1659 && ! isvar (&opP
->disp
)
1660 && issbyte (baseo
)))
1662 nextword
+= baseo
& 0xff;
1664 if (isvar (&opP
->disp
))
1666 /* Do a byte relocation. If it doesn't
1667 fit (possible on m68000) let the
1668 fixup processing complain later. */
1670 add_fix ('B', &opP
->disp
, 1, 1);
1672 add_fix ('B', &opP
->disp
, 0, 0);
1674 else if (siz1
!= SIZE_BYTE
)
1676 if (siz1
!= SIZE_UNSPEC
)
1677 as_warn ("Forcing byte displacement");
1678 if (! issbyte (baseo
))
1679 opP
->error
= "byte displacement out of range";
1684 else if (siz1
== SIZE_UNSPEC
1686 && isvar (&opP
->disp
)
1687 && subs (&opP
->disp
) == NULL
)
1689 nextword
+= baseo
& 0xff;
1691 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1692 TAB (PCINDEX
, SZ_UNDEF
));
1700 nextword
|= 0x40; /* No index reg */
1701 if (opP
->index
.reg
>= ZDATA0
1702 && opP
->index
.reg
<= ZDATA7
)
1703 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
1704 else if (opP
->index
.reg
>= ZADDR0
1705 || opP
->index
.reg
<= ZADDR7
)
1706 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
1709 /* It isn't simple. */
1711 if (cpu_of_arch (current_architecture
) < m68020
)
1713 "invalid operand mode for this architecture; needs 68020 or higher";
1716 /* If the guy specified a width, we assume that it is
1717 wide enough. Maybe it isn't. If so, we lose. */
1721 if (isvar (&opP
->disp
)
1723 : ! issword (baseo
))
1728 else if (! isvar (&opP
->disp
) && baseo
== 0)
1737 as_warn (":b not permitted; defaulting to :w");
1747 /* Figure out innner displacement stuff */
1748 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1753 if (isvar (&opP
->odisp
)
1755 : ! issword (outro
))
1760 else if (! isvar (&opP
->disp
) && outro
== 0)
1769 as_warn (":b not permitted; defaulting to :w");
1778 if (opP
->mode
== POST
)
1783 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
1785 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1786 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
1788 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
1790 if (siz1
== SIZE_LONG
)
1791 addword (baseo
>> 16);
1792 if (siz1
!= SIZE_UNSPEC
)
1795 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
1796 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
1797 if (siz2
== SIZE_LONG
)
1798 addword (outro
>> 16);
1799 if (siz2
!= SIZE_UNSPEC
)
1805 nextword
= get_num (&opP
->disp
, 80);
1806 switch (opP
->disp
.size
)
1811 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
1813 tmpreg
= 0x38; /* 7.0 */
1817 /* Don't generate pc relative code on 68010 and
1819 if (isvar (&opP
->disp
)
1820 && !subs (&opP
->disp
)
1821 && adds (&opP
->disp
)
1822 && (S_GET_SEGMENT (adds (&opP
->disp
)) == text_section
)
1823 && now_seg
== text_section
1824 && cpu_of_arch (current_architecture
) >= m68020
1826 && !strchr ("~%&$?", s
[0]))
1828 tmpreg
= 0x3A; /* 7.2 */
1829 add_frag (adds (&opP
->disp
),
1831 TAB (PCREL
, SZ_UNDEF
));
1834 /* Fall through into long */
1836 if (isvar (&opP
->disp
))
1837 add_fix ('l', &opP
->disp
, 0, 0);
1839 tmpreg
= 0x39;/* 7.1 mode */
1840 addword (nextword
>> 16);
1844 case SIZE_WORD
: /* Word */
1845 if (isvar (&opP
->disp
))
1846 add_fix ('w', &opP
->disp
, 0, 0);
1848 tmpreg
= 0x38;/* 7.0 mode */
1856 as_bad ("unknown/incorrect operand");
1859 install_gen_operand (s
[1], tmpreg
);
1865 { /* JF: I hate floating point! */
1880 tmpreg
= get_num (&opP
->disp
, tmpreg
);
1881 if (isvar (&opP
->disp
))
1882 add_fix (s
[1], &opP
->disp
, 0, 0);
1885 case 'b': /* Danger: These do no check for
1886 certain types of overflow.
1888 if (!isbyte (tmpreg
))
1889 opP
->error
= "out of range";
1890 insop (tmpreg
, opcode
);
1891 if (isvar (&opP
->disp
))
1892 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1895 if (!isword (tmpreg
))
1896 opP
->error
= "out of range";
1897 insop (tmpreg
, opcode
);
1898 if (isvar (&opP
->disp
))
1899 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1902 /* Because of the way insop works, we put these two out
1904 insop (tmpreg
, opcode
);
1905 insop (tmpreg
>> 16, opcode
);
1906 if (isvar (&opP
->disp
))
1907 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1913 install_operand (s
[1], tmpreg
);
1924 install_operand (s
[1], opP
->reg
- ADDR
);
1928 tmpreg
= get_num (&opP
->disp
, 80);
1932 /* The pc_fix argument winds up in fx_pcrel_adjust,
1933 which is a char, and may therefore be unsigned. We
1934 want to pass -1, but we pass 64 instead, and convert
1935 back in md_pcrel_from. */
1936 add_fix ('B', &opP
->disp
, 1, 64);
1939 add_fix ('w', &opP
->disp
, 1, 0);
1944 if (cpu_of_arch (current_architecture
) < m68020
)
1945 as_warn ("Can't use long branches on 68000/68010");
1946 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
1947 add_fix ('l', &opP
->disp
, 1, 0);
1952 if (subs (&opP
->disp
)) /* We can't relax it */
1955 /* This could either be a symbol, or an absolute
1956 address. No matter, the frag hacking will finger it
1957 out. Not quite: it can't switch from BRANCH to
1958 BCC68000 for the case where opnd is absolute (it
1959 needs to use the 68000 hack since no conditional abs
1961 if (((cpu_of_arch (current_architecture
) < m68020
)
1962 || (0 == adds (&opP
->disp
)))
1963 && (the_ins
.opcode
[0] >= 0x6200)
1964 && (the_ins
.opcode
[0] <= 0x6f00))
1965 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1966 TAB (BCC68000
, SZ_UNDEF
));
1968 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1969 TAB (ABRANCH
, SZ_UNDEF
));
1972 if (isvar (&opP
->disp
))
1975 /* check for DBcc instruction */
1976 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
1978 /* size varies if patch */
1979 /* needed for long form */
1980 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1981 TAB (DBCC
, SZ_UNDEF
));
1985 add_fix ('w', &opP
->disp
, 1, 0);
1989 case 'C': /* Fixed size LONG coproc branches */
1990 add_fix ('l', &opP
->disp
, 1, 0);
1994 case 'c': /* Var size Coprocesssor branches */
1995 if (subs (&opP
->disp
))
1997 add_fix ('l', &opP
->disp
, 1, 0);
1998 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2000 else if (adds (&opP
->disp
))
2001 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
2002 TAB (FBRANCH
, SZ_UNDEF
));
2005 /* add_frag((symbolS *) 0, offs(&opP->disp),
2006 TAB(FBRANCH,SHORT)); */
2007 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2008 add_fix ('l', &opP
->disp
, 1, 0);
2018 case 'C': /* Ignore it */
2021 case 'd': /* JF this is a kludge */
2022 install_operand ('s', opP
->reg
- ADDR
);
2023 tmpreg
= get_num (&opP
->disp
, 80);
2024 if (!issword (tmpreg
))
2026 as_warn ("Expression out of range, using 0");
2033 install_operand (s
[1], opP
->reg
- DATA
);
2037 install_operand (s
[1], opP
->reg
- FP0
);
2041 tmpreg
= opP
->reg
- COP0
;
2042 install_operand (s
[1], tmpreg
);
2045 case 'J': /* JF foo */
2106 install_operand (s
[1], tmpreg
);
2110 tmpreg
= get_num (&opP
->disp
, 55);
2111 install_operand (s
[1], tmpreg
& 0x7f);
2118 if (tmpreg
& 0x7FF0000)
2119 as_bad ("Floating point register in register list");
2120 insop (reverse_16_bits (tmpreg
), opcode
);
2124 if (tmpreg
& 0x700FFFF)
2125 as_bad ("Wrong register in floating-point reglist");
2126 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2134 if (tmpreg
& 0x7FF0000)
2135 as_bad ("Floating point register in register list");
2136 insop (tmpreg
, opcode
);
2138 else if (s
[1] == '8')
2140 if (tmpreg
& 0x0FFFFFF)
2141 as_bad ("incorrect register in reglist");
2142 install_operand (s
[1], tmpreg
>> 24);
2146 if (tmpreg
& 0x700FFFF)
2147 as_bad ("wrong register in floating-point reglist");
2149 install_operand (s
[1], tmpreg
>> 16);
2154 install_operand (s
[1], get_num (&opP
->disp
, 60));
2158 tmpreg
= ((opP
->mode
== DREG
)
2159 ? 0x20 + opP
->reg
- DATA
2160 : (get_num (&opP
->disp
, 40) & 0x1F));
2161 install_operand (s
[1], tmpreg
);
2165 tmpreg
= get_num (&opP
->disp
, 10);
2168 install_operand (s
[1], tmpreg
);
2172 /* This depends on the fact that ADDR registers are eight
2173 more than their corresponding DATA regs, so the result
2174 will have the ADDR_REG bit set */
2175 install_operand (s
[1], opP
->reg
- DATA
);
2179 if (opP
->mode
== AINDR
)
2180 install_operand (s
[1], opP
->reg
- DATA
);
2182 install_operand (s
[1], opP
->index
.reg
- DATA
);
2186 if (opP
->reg
== FPI
)
2188 else if (opP
->reg
== FPS
)
2190 else if (opP
->reg
== FPC
)
2194 install_operand (s
[1], tmpreg
);
2197 case 'S': /* Ignore it */
2201 install_operand (s
[1], get_num (&opP
->disp
, 30));
2204 case 'U': /* Ignore it */
2223 as_fatal ("failed sanity check");
2224 } /* switch on cache token */
2225 install_operand (s
[1], tmpreg
);
2228 /* JF: These are out of order, I fear. */
2241 install_operand (s
[1], tmpreg
);
2265 install_operand (s
[1], tmpreg
);
2269 if (opP
->reg
== VAL
)
2288 install_operand (s
[1], tmpreg
);
2302 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2313 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2319 install_operand (s
[1], tmpreg
);
2322 know (opP
->reg
== PSR
);
2325 know (opP
->reg
== PCSR
);
2340 install_operand (s
[1], tmpreg
);
2343 tmpreg
= get_num (&opP
->disp
, 20);
2344 install_operand (s
[1], tmpreg
);
2346 case '_': /* used only for move16 absolute 32-bit address */
2347 tmpreg
= get_num (&opP
->disp
, 80);
2348 addword (tmpreg
>> 16);
2349 addword (tmpreg
& 0xFFFF);
2356 /* By the time whe get here (FINALLY) the_ins contains the complete
2357 instruction, ready to be emitted. . . */
2361 reverse_16_bits (in
)
2367 static int mask
[16] =
2369 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2370 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2372 for (n
= 0; n
< 16; n
++)
2375 out
|= mask
[15 - n
];
2378 } /* reverse_16_bits() */
2387 static int mask
[8] =
2389 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2392 for (n
= 0; n
< 8; n
++)
2398 } /* reverse_8_bits() */
2400 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2401 (that value is chosen in the frag_var call in md_assemble). TYPE
2402 is the subtype of the frag to be generated; its primary type is
2403 rs_machine_dependent.
2405 The TYPE parameter is also used by md_convert_frag_1 and
2406 md_estimate_size_before_relax. The appropriate type of fixup will
2407 be emitted by md_convert_frag_1.
2409 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2411 install_operand (mode
, val
)
2418 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2421 the_ins
.opcode
[0] |= val
<< 9;
2424 the_ins
.opcode
[1] |= val
<< 12;
2427 the_ins
.opcode
[1] |= val
<< 6;
2430 the_ins
.opcode
[1] |= val
;
2433 the_ins
.opcode
[2] |= val
<< 12;
2436 the_ins
.opcode
[2] |= val
<< 6;
2439 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2440 three words long! */
2442 the_ins
.opcode
[2] |= val
;
2445 the_ins
.opcode
[1] |= val
<< 7;
2448 the_ins
.opcode
[1] |= val
<< 10;
2452 the_ins
.opcode
[1] |= val
<< 5;
2457 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2460 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2463 the_ins
.opcode
[0] |= val
= 0xff;
2466 the_ins
.opcode
[0] |= val
<< 9;
2469 the_ins
.opcode
[1] |= val
;
2472 the_ins
.opcode
[1] |= val
;
2473 the_ins
.numo
++; /* What a hack */
2476 the_ins
.opcode
[1] |= val
<< 4;
2483 the_ins
.opcode
[0] |= (val
<< 6);
2486 the_ins
.opcode
[1] = (val
>> 16);
2487 the_ins
.opcode
[2] = val
& 0xffff;
2491 as_fatal ("failed sanity check.");
2493 } /* install_operand() */
2496 install_gen_operand (mode
, val
)
2503 the_ins
.opcode
[0] |= val
;
2506 /* This is a kludge!!! */
2507 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2516 the_ins
.opcode
[0] |= val
;
2518 /* more stuff goes here */
2520 as_fatal ("failed sanity check.");
2522 } /* install_gen_operand() */
2525 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2526 * then deal with the bitfield hack.
2530 crack_operand (str
, opP
)
2532 register struct m68k_op
*opP
;
2534 register int parens
;
2536 register char *beg_str
;
2544 for (parens
= 0; *str
&& (parens
> 0 || inquote
|| notend (str
)); str
++)
2550 else if (*str
== ')')
2554 opP
->error
= "Extra )";
2560 if (flag_mri
&& *str
== '\'')
2561 inquote
= ! inquote
;
2563 if (!*str
&& parens
)
2565 opP
->error
= "Missing )";
2570 if (m68k_ip_op (beg_str
, opP
) != 0)
2577 c
= *++str
; /* JF bitfield hack */
2582 as_bad ("Missing operand");
2587 /* This is the guts of the machine-dependent assembler. STR points to a
2588 machine dependent instruction. This function is supposed to emit
2589 the frags/bytes it assembles to.
2593 insert_reg (regname
, regnum
)
2600 #ifdef REGISTER_PREFIX
2601 if (!flag_reg_prefix_optional
)
2603 buf
[0] = REGISTER_PREFIX
;
2604 strcpy (buf
+ 1, regname
);
2609 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
2610 &zero_address_frag
));
2612 for (i
= 0; regname
[i
]; i
++)
2613 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2616 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
2617 &zero_address_frag
));
2626 static const struct init_entry init_table
[] =
2736 /* 68ec030 versions of same */
2739 /* 68ec030 access control unit, identical to 030 MMU status reg */
2742 /* Suppressed data and address registers. */
2767 for (i
= 0; init_table
[i
].name
; i
++)
2768 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
2771 static int no_68851
, no_68881
;
2774 /* a.out machine type. Default to 68020. */
2775 int m68k_aout_machtype
= 2;
2787 int shorts_this_frag
;
2790 /* In MRI mode, the instruction and operands are separated by a
2791 space. Anything following the operands is a comment. The label
2792 has already been removed. */
2800 for (s
= str
; *s
!= '\0'; s
++)
2802 if ((*s
== ' ' || *s
== '\t') && ! inquote
)
2820 inquote
= ! inquote
;
2825 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
2830 for (n
= 0; n
< the_ins
.numargs
; n
++)
2831 if (the_ins
.operands
[n
].error
)
2833 er
= the_ins
.operands
[n
].error
;
2839 as_bad ("%s -- statement `%s' ignored", er
, str
);
2843 if (the_ins
.nfrag
== 0)
2845 /* No frag hacking involved; just put it out */
2846 toP
= frag_more (2 * the_ins
.numo
);
2847 fromP
= &the_ins
.opcode
[0];
2848 for (m
= the_ins
.numo
; m
; --m
)
2850 md_number_to_chars (toP
, (long) (*fromP
), 2);
2854 /* put out symbol-dependent info */
2855 for (m
= 0; m
< the_ins
.nrel
; m
++)
2857 switch (the_ins
.reloc
[m
].wid
)
2875 as_fatal ("Don't know how to figure width of %c in md_assemble()",
2876 the_ins
.reloc
[m
].wid
);
2879 fixP
= fix_new_exp (frag_now
,
2880 ((toP
- frag_now
->fr_literal
)
2881 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
2883 &the_ins
.reloc
[m
].exp
,
2884 the_ins
.reloc
[m
].pcrel
,
2886 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2891 /* There's some frag hacking */
2892 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
2897 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
2899 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
2900 toP
= frag_more (wid
);
2902 shorts_this_frag
= 0;
2903 for (m
= wid
/ 2; m
; --m
)
2905 md_number_to_chars (toP
, (long) (*fromP
), 2);
2910 for (m
= 0; m
< the_ins
.nrel
; m
++)
2912 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
2914 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
2917 wid
= the_ins
.reloc
[m
].wid
;
2920 the_ins
.reloc
[m
].wid
= 0;
2921 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
2923 fixP
= fix_new_exp (frag_now
,
2924 ((toP
- frag_now
->fr_literal
)
2925 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
2927 &the_ins
.reloc
[m
].exp
,
2928 the_ins
.reloc
[m
].pcrel
,
2930 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2932 (void) frag_var (rs_machine_dependent
, 10, 0,
2933 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
2934 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
2936 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
2937 shorts_this_frag
= 0;
2940 toP
= frag_more (n
* sizeof (short));
2943 md_number_to_chars (toP
, (long) (*fromP
), 2);
2949 for (m
= 0; m
< the_ins
.nrel
; m
++)
2953 wid
= the_ins
.reloc
[m
].wid
;
2956 the_ins
.reloc
[m
].wid
= 0;
2957 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
2959 fixP
= fix_new_exp (frag_now
,
2960 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
2961 - shorts_this_frag
* 2),
2963 &the_ins
.reloc
[m
].exp
,
2964 the_ins
.reloc
[m
].pcrel
,
2966 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2974 * md_begin -- set up hash tables with 68000 instructions.
2975 * similar to what the vax assembler does. ---phr
2977 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2978 a copy of it at runtime, adding in the information we want but isn't
2979 there. I think it'd be better to have an awk script hack the table
2980 at compile time. Or even just xstr the table and use it as-is. But
2981 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2984 register const struct m68k_opcode
*ins
;
2985 register struct m68k_incant
*hack
, *slak
;
2986 register const char *retval
= 0; /* empty string, or error msg text */
2987 register unsigned int i
;
2992 flag_reg_prefix_optional
= 1;
2997 op_hash
= hash_new ();
2999 obstack_begin (&robyn
, 4000);
3000 for (i
= 0; i
< m68k_numopcodes
; i
++)
3002 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3005 ins
= &m68k_opcodes
[i
];
3006 /* We *could* ignore insns that don't match our arch here
3007 but just leaving them out of the hash. */
3008 slak
->m_operands
= ins
->args
;
3009 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3010 slak
->m_arch
= ins
->arch
;
3011 slak
->m_opcode
= ins
->opcode
;
3012 /* This is kludgey */
3013 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3014 if (i
+ 1 != m68k_numopcodes
3015 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
3017 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3022 slak
= slak
->m_next
;
3026 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3028 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3031 for (i
= 0; i
< m68k_numaliases
; i
++)
3033 const char *name
= m68k_opcode_aliases
[i
].primary
;
3034 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3035 PTR val
= hash_find (op_hash
, name
);
3037 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3038 retval
= hash_insert (op_hash
, alias
, val
);
3040 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3043 /* In MRI mode, all unsized branches are variable sized. Normally,
3044 they are word sized. */
3047 static struct m68k_opcode_alias mri_aliases
[] =
3067 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
3069 const char *name
= mri_aliases
[i
].primary
;
3070 const char *alias
= mri_aliases
[i
].alias
;
3071 PTR val
= hash_find (op_hash
, name
);
3073 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3074 retval
= hash_jam (op_hash
, alias
, val
);
3076 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3080 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3081 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3083 for (i
= 0; i
< sizeof (notend_table
); i
++)
3085 notend_table
[i
] = 0;
3086 alt_notend_table
[i
] = 0;
3088 notend_table
[','] = 1;
3089 notend_table
['{'] = 1;
3090 notend_table
['}'] = 1;
3091 alt_notend_table
['a'] = 1;
3092 alt_notend_table
['A'] = 1;
3093 alt_notend_table
['d'] = 1;
3094 alt_notend_table
['D'] = 1;
3095 alt_notend_table
['#'] = 1;
3096 alt_notend_table
['&'] = 1;
3097 alt_notend_table
['f'] = 1;
3098 alt_notend_table
['F'] = 1;
3099 #ifdef REGISTER_PREFIX
3100 alt_notend_table
[REGISTER_PREFIX
] = 1;
3103 /* We need to put '(' in alt_notend_table to handle
3104 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3106 alt_notend_table
['('] = 1;
3108 /* We need to put '@' in alt_notend_table to handle
3109 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3111 alt_notend_table
['@'] = 1;
3113 #ifndef MIT_SYNTAX_ONLY
3114 /* Insert pseudo ops, these have to go into the opcode table since
3115 gas expects pseudo ops to start with a dot */
3118 while (mote_pseudo_table
[n
].poc_name
)
3120 hack
= (struct m68k_incant
*)
3121 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3122 hash_insert (op_hash
,
3123 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3124 hack
->m_operands
= 0;
3135 m68k_init_after_args ()
3137 if (cpu_of_arch (current_architecture
) == 0)
3140 const char *default_cpu
= TARGET_CPU
;
3142 if (*default_cpu
== 'm')
3144 for (i
= 0; i
< n_archs
; i
++)
3145 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3149 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3150 current_architecture
|= m68020
;
3153 current_architecture
|= archs
[i
].arch
;
3155 /* Permit m68881 specification with all cpus; those that can't work
3156 with a coprocessor could be doing emulation. */
3157 if (current_architecture
& m68851
)
3159 if (current_architecture
& m68040
)
3161 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3164 /* What other incompatibilities could we check for? */
3166 /* Toss in some default assumptions about coprocessors. */
3168 && (cpu_of_arch (current_architecture
)
3169 /* Can CPU32 have a 68881 coprocessor?? */
3170 & (m68020
| m68030
| cpu32
)))
3172 current_architecture
|= m68881
;
3175 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3176 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3178 current_architecture
|= m68851
;
3180 if (no_68881
&& (current_architecture
& m68881
))
3181 as_bad ("options for 68881 and no-68881 both given");
3182 if (no_68851
&& (current_architecture
& m68851
))
3183 as_bad ("options for 68851 and no-68851 both given");
3186 /* Work out the magic number. This isn't very general. */
3187 if (current_architecture
& m68000
)
3188 m68k_aout_machtype
= 0;
3189 else if (current_architecture
& m68010
)
3190 m68k_aout_machtype
= 1;
3191 else if (current_architecture
& m68020
)
3192 m68k_aout_machtype
= 2;
3194 m68k_aout_machtype
= 2;
3197 /* Note which set of "movec" control registers is available. */
3198 switch (cpu_of_arch (current_architecture
))
3201 control_regs
= m68000_control_regs
;
3204 control_regs
= m68010_control_regs
;
3208 control_regs
= m68020_control_regs
;
3211 control_regs
= m68040_control_regs
;
3214 control_regs
= m68060_control_regs
;
3217 control_regs
= cpu32_control_regs
;
3223 if (cpu_of_arch (current_architecture
) < m68020
)
3224 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3227 /* Equal to MAX_PRECISION in atof-ieee.c */
3228 #define MAX_LITTLENUMS 6
3230 /* Turn a string in input_line_pointer into a floating point constant
3231 of type type, and store the appropriate bytes in *litP. The number
3232 of LITTLENUMS emitted is stored in *sizeP . An error message is
3233 returned, or NULL on OK. */
3236 md_atof (type
, litP
, sizeP
)
3242 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3243 LITTLENUM_TYPE
*wordP
;
3275 return "Bad call to MD_ATOF()";
3277 t
= atof_ieee (input_line_pointer
, type
, words
);
3279 input_line_pointer
= t
;
3281 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3282 for (wordP
= words
; prec
--;)
3284 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3285 litP
+= sizeof (LITTLENUM_TYPE
);
3291 md_number_to_chars (buf
, val
, n
)
3296 number_to_chars_bigendian (buf
, val
, n
);
3300 md_apply_fix_2 (fixP
, val
)
3304 addressT upper_limit
;
3305 offsetT lower_limit
;
3307 /* This is unnecessary but it convinces the native rs6000 compiler
3308 to generate the code we want. */
3309 char *buf
= fixP
->fx_frag
->fr_literal
;
3310 buf
+= fixP
->fx_where
;
3311 /* end ibm compiler workaround */
3313 if (val
& 0x80000000)
3314 val
|= ~(addressT
)0x7fffffff;
3318 switch (fixP
->fx_size
)
3320 /* The cast to offsetT below are necessary to make code correct for
3321 machines where ints are smaller than offsetT */
3325 lower_limit
= - (offsetT
) 0x80;
3328 *buf
++ = (val
>> 8);
3330 upper_limit
= 0x7fff;
3331 lower_limit
= - (offsetT
) 0x8000;
3334 *buf
++ = (val
>> 24);
3335 *buf
++ = (val
>> 16);
3336 *buf
++ = (val
>> 8);
3338 upper_limit
= 0x7fffffff;
3339 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3342 BAD_CASE (fixP
->fx_size
);
3345 /* For non-pc-relative values, it's conceivable we might get something
3346 like "0xff" for a byte field. So extend the upper part of the range
3347 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3348 so that we can do any range checking at all. */
3349 if (!fixP
->fx_pcrel
)
3350 upper_limit
= upper_limit
* 2 + 1;
3352 if ((addressT
) val
> upper_limit
3353 && (val
> 0 || val
< lower_limit
))
3354 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
3356 /* A one byte PC-relative reloc means a short branch. We can't use
3357 a short branch with a value of 0 or -1, because those indicate
3358 different opcodes (branches with longer offsets). */
3360 && fixP
->fx_size
== 1
3361 && (fixP
->fx_addsy
== NULL
3362 || S_IS_DEFINED (fixP
->fx_addsy
))
3363 && (val
== 0 || val
== -1))
3364 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
3367 #ifdef BFD_ASSEMBLER
3369 md_apply_fix (fixP
, valp
)
3373 md_apply_fix_2 (fixP
, (addressT
) *valp
);
3377 void md_apply_fix (fixP
, val
)
3381 md_apply_fix_2 (fixP
, (addressT
) val
);
3385 /* *fragP has been relaxed to its final size, and now needs to have
3386 the bytes inside it modified to conform to the new size There is UGLY
3390 md_convert_frag_1 (fragP
)
3391 register fragS
*fragP
;
3397 /* Address in object code of the displacement. */
3398 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3400 /* Address in gas core of the place to store the displacement. */
3401 /* This convinces the native rs6000 compiler to generate the code we
3403 register char *buffer_address
= fragP
->fr_literal
;
3404 buffer_address
+= fragP
->fr_fix
;
3405 /* end ibm compiler workaround */
3407 /* The displacement of the address, from current location. */
3408 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3409 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3411 #ifdef BFD_ASSEMBLER
3412 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
3415 switch (fragP
->fr_subtype
)
3417 case TAB (BCC68000
, BYTE
):
3418 case TAB (ABRANCH
, BYTE
):
3419 know (issbyte (disp
));
3421 as_bad ("short branch with zero offset: use :w");
3422 fragP
->fr_opcode
[1] = disp
;
3425 case TAB (DBCC
, SHORT
):
3426 know (issword (disp
));
3429 case TAB (BCC68000
, SHORT
):
3430 case TAB (ABRANCH
, SHORT
):
3431 know (issword (disp
));
3432 fragP
->fr_opcode
[1] = 0x00;
3435 case TAB (ABRANCH
, LONG
):
3436 if (cpu_of_arch (current_architecture
) < m68020
)
3438 if (fragP
->fr_opcode
[0] == 0x61)
3441 fragP
->fr_opcode
[0] = 0x4E;
3442 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3443 subseg_change (text_section
, 0); /* @@ */
3457 else if (fragP
->fr_opcode
[0] == 0x60)
3459 fragP
->fr_opcode
[0] = 0x4E;
3460 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3461 subseg_change (text_section
, 0); /* @@ */
3462 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3463 fragP
->fr_offset
, 0, NO_RELOC
);
3469 as_bad ("Long branch offset not supported.");
3474 fragP
->fr_opcode
[1] = (char) 0xff;
3478 case TAB (BCC68000
, LONG
):
3479 /* only Bcc 68000 instructions can come here */
3480 /* change bcc into b!cc/jmp absl long */
3481 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3482 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
3484 /* JF: these used to be fr_opcode[2,3], but they may be in a
3485 different frag, in which case refering to them is a no-no.
3486 Only fr_opcode[0,1] are guaranteed to work. */
3487 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3488 *buffer_address
++ = (char) 0xf9;
3489 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3490 subseg_change (text_section
, 0);
3491 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3492 fragP
->fr_offset
, 0, NO_RELOC
);
3496 case TAB (DBCC
, LONG
):
3497 /* only DBcc 68000 instructions can come here */
3498 /* change dbcc into dbcc/jmp absl long */
3499 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3500 *buffer_address
++ = 0x00; /* branch offset = 4 */
3501 *buffer_address
++ = 0x04;
3502 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3503 *buffer_address
++ = 0x06;
3504 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3505 *buffer_address
++ = (char) 0xf9;
3507 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3508 subseg_change (text_section
, 0);
3509 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3510 fragP
->fr_offset
, 0, NO_RELOC
);
3514 case TAB (FBRANCH
, SHORT
):
3515 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
3518 case TAB (FBRANCH
, LONG
):
3519 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3522 case TAB (PCREL
, SHORT
):
3525 case TAB (PCREL
, LONG
):
3526 /* The thing to do here is force it to ABSOLUTE LONG, since
3527 PCREL is really trying to shorten an ABSOLUTE address anyway */
3528 /* JF FOO This code has not been tested */
3529 subseg_change (text_section
, 0);
3530 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
3532 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3533 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
3534 (unsigned) fragP
->fr_opcode
[0],
3535 (unsigned long) fragP
->fr_address
);
3536 fragP
->fr_opcode
[1] &= ~0x3F;
3537 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
3541 case TAB (PCLEA
, SHORT
):
3542 subseg_change (text_section
, 0);
3543 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3544 fragP
->fr_offset
, 1, NO_RELOC
);
3545 fragP
->fr_opcode
[1] &= ~0x3F;
3546 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
3549 case TAB (PCLEA
, LONG
):
3550 subseg_change (text_section
, 0);
3551 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
3552 fragP
->fr_offset
, 1, NO_RELOC
);
3553 fixP
->fx_pcrel_adjust
= 2;
3554 /* Already set to mode 7.3; this indicates: PC indirect with
3555 suppressed index, 32-bit displacement. */
3556 *buffer_address
++ = 0x01;
3557 *buffer_address
++ = 0x70;
3562 case TAB (PCINDEX
, BYTE
):
3564 if (!issbyte (disp
))
3566 as_bad ("displacement doesn't fit in one byte");
3569 assert (fragP
->fr_fix
>= 2);
3570 buffer_address
[-2] &= ~1;
3571 buffer_address
[-1] = disp
;
3574 case TAB (PCINDEX
, SHORT
):
3575 subseg_change (text_section
, 0);
3577 assert (issword (disp
));
3578 assert (fragP
->fr_fix
>= 2);
3579 buffer_address
[-2] |= 0x1;
3580 buffer_address
[-1] = 0x20;
3581 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3582 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3584 fixP
->fx_pcrel_adjust
= 2;
3587 case TAB (PCINDEX
, LONG
):
3588 subseg_change (text_section
, 0);
3590 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3591 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3593 fixP
->fx_pcrel_adjust
= 2;
3594 assert (fragP
->fr_fix
>= 2);
3595 buffer_address
[-2] |= 0x1;
3596 buffer_address
[-1] = 0x30;
3603 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
3604 fragP
->fr_fix
+= ext
;
3608 #ifndef BFD_ASSEMBLER
3611 md_convert_frag (headers
, sec
, fragP
)
3612 object_headers
*headers
;
3616 md_convert_frag_1 (fragP
);
3622 md_convert_frag (abfd
, sec
, fragP
)
3627 md_convert_frag_1 (fragP
);
3631 /* Force truly undefined symbols to their maximum size, and generally set up
3632 the frag list to be relaxed
3635 md_estimate_size_before_relax (fragP
, segment
)
3636 register fragS
*fragP
;
3640 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3642 old_fix
= fragP
->fr_fix
;
3644 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3645 switch (fragP
->fr_subtype
)
3648 case TAB (ABRANCH
, SZ_UNDEF
):
3650 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3651 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3653 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
3656 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
3658 /* On 68000, or for absolute value, switch to abs long */
3659 /* FIXME, we should check abs val, pick short or long */
3660 if (fragP
->fr_opcode
[0] == 0x61)
3662 fragP
->fr_opcode
[0] = 0x4E;
3663 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3664 subseg_change (text_section
, 0);
3665 fix_new (fragP
, fragP
->fr_fix
, 4,
3666 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3670 else if (fragP
->fr_opcode
[0] == 0x60)
3672 fragP
->fr_opcode
[0] = 0x4E;
3673 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3674 subseg_change (text_section
, 0);
3675 fix_new (fragP
, fragP
->fr_fix
, 4,
3676 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3682 as_warn ("Long branch offset to extern symbol not supported.");
3686 { /* Symbol is still undefined. Make it simple */
3687 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3688 fragP
->fr_offset
, 1, NO_RELOC
);
3690 fragP
->fr_opcode
[1] = (char) 0xff;
3696 } /* case TAB(ABRANCH,SZ_UNDEF) */
3698 case TAB (FBRANCH
, SZ_UNDEF
):
3700 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
3702 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
3707 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3708 fragP
->fr_offset
, 1, NO_RELOC
);
3710 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3714 } /* TAB(FBRANCH,SZ_UNDEF) */
3716 case TAB (PCREL
, SZ_UNDEF
):
3718 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3720 || cpu_of_arch (current_architecture
) < m68020
)
3722 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
3727 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
3731 } /* TAB(PCREL,SZ_UNDEF) */
3733 case TAB (BCC68000
, SZ_UNDEF
):
3735 if ((fragP
->fr_symbol
!= NULL
)
3736 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3738 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
3741 /* only Bcc 68000 instructions can come here */
3742 /* change bcc into b!cc/jmp absl long */
3743 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3744 if (flag_short_refs
)
3746 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3747 /* JF: these were fr_opcode[2,3] */
3748 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3749 buffer_address
[1] = (char) 0xf8;
3750 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3751 subseg_change (text_section
, 0);
3752 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3753 fragP
->fr_offset
, 0, NO_RELOC
);
3758 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3759 /* JF: these were fr_opcode[2,3] */
3760 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3761 buffer_address
[1] = (char) 0xf9;
3762 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3763 subseg_change (text_section
, 0);
3764 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3765 fragP
->fr_offset
, 0, NO_RELOC
);
3770 } /* case TAB(BCC68000,SZ_UNDEF) */
3772 case TAB (DBCC
, SZ_UNDEF
):
3774 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3776 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
3780 /* only DBcc 68000 instructions can come here */
3781 /* change dbcc into dbcc/jmp absl long */
3782 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3783 buffer_address
[0] = 0x00; /* branch offset = 4 */
3784 buffer_address
[1] = 0x04;
3785 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3787 if (flag_short_refs
)
3789 /* JF: these were fr_opcode[5-7] */
3790 buffer_address
[3] = 0x04; /* plus 4 */
3791 buffer_address
[4] = 0x4e; /* Put in Jump Word */
3792 buffer_address
[5] = (char) 0xf8;
3793 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3794 subseg_change (text_section
, 0);
3795 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3796 fragP
->fr_offset
, 0, NO_RELOC
);
3801 /* JF: these were fr_opcode[5-7] */
3802 buffer_address
[3] = 0x06; /* Plus 6 */
3803 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3804 buffer_address
[5] = (char) 0xf9;
3805 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3806 subseg_change (text_section
, 0);
3807 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3808 fragP
->fr_offset
, 0, NO_RELOC
);
3814 } /* case TAB(DBCC,SZ_UNDEF) */
3816 case TAB (PCLEA
, SZ_UNDEF
):
3818 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
3820 || cpu_of_arch (current_architecture
) < m68020
)
3822 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
3827 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
3831 } /* TAB(PCLEA,SZ_UNDEF) */
3833 case TAB (PCINDEX
, SZ_UNDEF
):
3834 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3835 || cpu_of_arch (current_architecture
) < m68020
)
3837 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
3841 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
3850 /* now that SZ_UNDEF are taken care of, check others */
3851 switch (fragP
->fr_subtype
)
3853 case TAB (BCC68000
, BYTE
):
3854 case TAB (ABRANCH
, BYTE
):
3855 /* We can't do a short jump to the next instruction,
3856 so we force word mode. */
3857 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
3858 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
3860 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
3867 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3870 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3871 /* the bit-field entries in the relocation_info struct plays hell
3872 with the byte-order problems of cross-assembly. So as a hack,
3873 I added this mach. dependent ri twiddler. Ugly, but it gets
3875 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3876 are symbolnum, most sig. byte first. Last byte is broken up with
3877 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3878 nibble as nuthin. (on Sun 3 at least) */
3879 /* Translate the internal relocation information into target-specific
3883 md_ri_to_chars (the_bytes
, ri
)
3885 struct reloc_info_generic
*ri
;
3888 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
3889 /* now the fun stuff */
3890 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3891 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3892 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3893 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3894 ((ri
->r_extern
<< 4) & 0x10));
3897 #endif /* comment */
3899 #ifndef BFD_ASSEMBLER
3901 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
3904 relax_addressT segment_address_in_file
;
3907 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3908 * Out: GNU LD relocation length code: 0, 1, or 2.
3911 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
3914 know (fixP
->fx_addsy
!= NULL
);
3916 md_number_to_chars (where
,
3917 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3920 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
3921 ? S_GET_TYPE (fixP
->fx_addsy
)
3922 : fixP
->fx_addsy
->sy_number
);
3924 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3925 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3926 where
[6] = r_symbolnum
& 0x0ff;
3927 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3928 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
3932 #endif /* OBJ_AOUT or OBJ_BOUT */
3934 #ifndef WORKING_DOT_WORD
3935 CONST
int md_short_jump_size
= 4;
3936 CONST
int md_long_jump_size
= 6;
3939 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3941 addressT from_addr
, to_addr
;
3947 offset
= to_addr
- (from_addr
+ 2);
3949 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
3950 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
3954 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3956 addressT from_addr
, to_addr
;
3962 if (cpu_of_arch (current_architecture
) < m68020
)
3964 offset
= to_addr
- S_GET_VALUE (to_symbol
);
3965 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
3966 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
3967 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
3972 offset
= to_addr
- (from_addr
+ 2);
3973 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
3974 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
3980 /* Different values of OK tell what its OK to return. Things that
3981 aren't OK are an error (what a shock, no?)
3984 10: Absolute 1:8 only
3985 20: Absolute 0:7 only
3986 30: absolute 0:15 only
3987 40: Absolute 0:31 only
3988 50: absolute 0:127 only
3989 55: absolute -64:63 only
3990 60: absolute -128:127 only
3991 70: absolute 0:4095 only
3998 struct m68k_exp
*exp
;
4001 if (exp
->exp
.X_op
== O_absent
)
4003 /* Do the same thing the VAX asm does */
4004 op (exp
) = O_constant
;
4010 as_warn ("expression out of range: defaulting to 1");
4014 else if (exp
->exp
.X_op
== O_constant
)
4019 if (offs (exp
) < 1 || offs (exp
) > 8)
4021 as_warn ("expression out of range: defaulting to 1");
4026 if (offs (exp
) < 0 || offs (exp
) > 7)
4030 if (offs (exp
) < 0 || offs (exp
) > 15)
4034 if (offs (exp
) < 0 || offs (exp
) > 32)
4038 if (offs (exp
) < 0 || offs (exp
) > 127)
4042 if (offs (exp
) < -64 || offs (exp
) > 63)
4046 if (offs (exp
) < -128 || offs (exp
) > 127)
4050 if (offs (exp
) < 0 || offs (exp
) > 4095)
4053 as_warn ("expression out of range: defaulting to 0");
4061 else if (exp
->exp
.X_op
== O_big
)
4063 if (offs (exp
) <= 0 /* flonum */
4064 && (ok
== 80 /* no bignums */
4065 || (ok
> 10 /* small-int ranges including 0 ok */
4066 /* If we have a flonum zero, a zero integer should
4067 do as well (e.g., in moveq). */
4068 && generic_floating_point_number
.exponent
== 0
4069 && generic_floating_point_number
.low
[0] == 0)))
4071 /* HACK! Turn it into a long */
4072 LITTLENUM_TYPE words
[6];
4074 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4075 op (exp
) = O_constant
;
4078 offs (exp
) = words
[1] | (words
[0] << 16);
4082 op (exp
) = O_constant
;
4085 offs (exp
) = (ok
== 10) ? 1 : 0;
4086 as_warn ("Can't deal with expression; defaulting to %ld",
4092 if (ok
>= 10 && ok
<= 70)
4094 op (exp
) = O_constant
;
4097 offs (exp
) = (ok
== 10) ? 1 : 0;
4098 as_warn ("Can't deal with expression; defaulting to %ld",
4103 if (exp
->size
!= SIZE_UNSPEC
)
4111 if (!isbyte (offs (exp
)))
4112 as_warn ("expression doesn't fit in BYTE");
4115 if (!isword (offs (exp
)))
4116 as_warn ("expression doesn't fit in WORD");
4124 /* These are the back-ends for the various machine dependent pseudo-ops. */
4125 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4131 subseg_set (data_section
, 1);
4132 demand_empty_rest_of_line ();
4139 subseg_set (data_section
, 2);
4140 demand_empty_rest_of_line ();
4147 /* We don't support putting frags in the BSS segment, we fake it
4148 by marking in_bss, then looking at s_skip for clues. */
4150 subseg_set (bss_section
, 0);
4151 demand_empty_rest_of_line ();
4159 register long temp_fill
;
4161 temp
= 1; /* JF should be 2? */
4162 temp_fill
= get_absolute_expression ();
4163 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4164 frag_align (temp
, (int) temp_fill
);
4165 demand_empty_rest_of_line ();
4172 demand_empty_rest_of_line ();
4175 /* Pseudo-ops handled for MRI compatibility. */
4177 /* Handle an MRI style chip specification. */
4186 s
= input_line_pointer
;
4187 c
= get_symbol_end ();
4188 for (i
= 0; i
< n_archs
; i
++)
4189 if (strcasecmp (s
, archs
[i
].name
) == 0)
4193 as_bad ("%s: unrecognized processor name", s
);
4194 *input_line_pointer
= c
;
4195 ignore_rest_of_line ();
4198 *input_line_pointer
= c
;
4200 if (*input_line_pointer
== '/')
4201 current_architecture
= 0;
4203 current_architecture
&= m68881
| m68851
;
4204 current_architecture
|= archs
[i
].arch
;
4206 while (*input_line_pointer
== '/')
4208 ++input_line_pointer
;
4209 s
= input_line_pointer
;
4210 c
= get_symbol_end ();
4211 if (strcmp (s
, "68881") == 0)
4212 current_architecture
|= m68881
;
4213 else if (strcmp (s
, "68851") == 0)
4214 current_architecture
|= m68851
;
4215 *input_line_pointer
= c
;
4219 /* The MRI CHIP pseudo-op. */
4226 demand_empty_rest_of_line ();
4229 /* The MRI FOPT pseudo-op. */
4237 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4241 input_line_pointer
+= 3;
4242 temp
= get_absolute_expression ();
4243 if (temp
< 0 || temp
> 7)
4244 as_bad ("bad coprocessor id");
4246 m68k_float_copnum
= COP0
+ temp
;
4250 as_bad ("unrecognized fopt option");
4251 ignore_rest_of_line ();
4255 demand_empty_rest_of_line ();
4258 /* The structure used to handle the MRI OPT pseudo-op. */
4262 /* The name of the option. */
4265 /* If this is not NULL, just call this function. The first argument
4266 is the ARG field of this structure, the second argument is
4267 whether the option was negated. */
4268 void (*pfn
) PARAMS ((int arg
, int on
));
4270 /* If this is not NULL, and the PFN field is NULL, set the variable
4271 this points to. Set it to the ARG field if the option was not
4272 negated, and the NOTARG field otherwise. */
4275 /* The value to pass to PFN or to assign to *PVAR. */
4278 /* The value to assign to *PVAR if the option is negated. If PFN is
4279 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4280 the option may not be negated. */
4284 /* The table used to handle the MRI OPT pseudo-op. */
4286 static void skip_to_comma
PARAMS ((int, int));
4287 static void opt_nest
PARAMS ((int, int));
4288 static void opt_chip
PARAMS ((int, int));
4289 static void opt_list
PARAMS ((int, int));
4290 static void opt_list_symbols
PARAMS ((int, int));
4292 static const struct opt_action opt_table
[] =
4294 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
4296 /* We do relaxing, so there is little use for these options. */
4297 { "b", 0, 0, 0, 0 },
4298 { "brs", 0, 0, 0, 0 },
4299 { "brb", 0, 0, 0, 0 },
4300 { "brl", 0, 0, 0, 0 },
4301 { "brw", 0, 0, 0, 0 },
4303 { "c", 0, 0, 0, 0 },
4304 { "cex", 0, 0, 0, 0 },
4305 { "case", 0, &symbols_case_sensitive
, 1, 0 },
4306 { "cl", 0, 0, 0, 0 },
4307 { "cre", 0, 0, 0, 0 },
4308 { "d", 0, &flag_keep_locals
, 1, 0 },
4309 { "e", 0, 0, 0, 0 },
4310 { "f", 0, &flag_short_refs
, 1, 0 },
4311 { "frs", 0, &flag_short_refs
, 1, 0 },
4312 { "frl", 0, &flag_short_refs
, 0, 1 },
4313 { "g", 0, 0, 0, 0 },
4314 { "i", 0, 0, 0, 0 },
4315 { "m", 0, 0, 0, 0 },
4316 { "mex", 0, 0, 0, 0 },
4317 { "mc", 0, 0, 0, 0 },
4318 { "md", 0, 0, 0, 0 },
4319 { "nest", opt_nest
, 0, 0, 0 },
4320 { "next", skip_to_comma
, 0, 0, 0 },
4321 { "o", 0, 0, 0, 0 },
4322 { "old", 0, 0, 0, 0 },
4323 { "op", skip_to_comma
, 0, 0, 0 },
4324 { "pco", 0, 0, 0, 0 },
4325 { "p", opt_chip
, 0, 0, 0 },
4326 { "pcr", 0, 0, 0, 0 },
4327 { "pcs", 0, 0, 0, 0 },
4328 { "r", 0, 0, 0, 0 },
4329 { "quick", 0, &m68k_quick
, 1, 0 },
4330 { "rel32", 0, &m68k_rel32
, 1, 0 },
4331 { "s", opt_list
, 0, 0, 0 },
4332 { "t", opt_list_symbols
, 0, 0, 0 },
4333 { "w", 0, &flag_no_warnings
, 0, 1 },
4337 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4339 /* The MRI OPT pseudo-op. */
4351 const struct opt_action
*o
;
4356 if (*input_line_pointer
== '-')
4358 ++input_line_pointer
;
4361 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
4363 input_line_pointer
+= 2;
4367 s
= input_line_pointer
;
4368 c
= get_symbol_end ();
4370 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
4372 if (strcasecmp (s
, o
->name
) == 0)
4376 /* Restore input_line_pointer now in case the option
4378 *input_line_pointer
= c
;
4379 (*o
->pfn
) (o
->arg
, t
);
4381 else if (o
->pvar
!= NULL
)
4383 if (! t
&& o
->arg
== o
->notarg
)
4384 as_bad ("option `%s' may not be negated", s
);
4385 *input_line_pointer
= c
;
4386 *o
->pvar
= t
? o
->arg
: o
->notarg
;
4389 *input_line_pointer
= c
;
4395 as_bad ("option `%s' not recognized", s
);
4396 *input_line_pointer
= c
;
4399 while (*input_line_pointer
++ == ',');
4401 /* Move back to terminating character. */
4402 --input_line_pointer
;
4403 demand_empty_rest_of_line ();
4406 /* Skip ahead to a comma. This is used for OPT options which we do
4407 not suppor tand which take arguments. */
4410 skip_to_comma (arg
, on
)
4414 while (*input_line_pointer
!= ','
4415 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4416 ++input_line_pointer
;
4419 /* Handle the OPT NEST=depth option. */
4426 if (*input_line_pointer
!= '=')
4428 as_bad ("bad format of OPT NEST=depth");
4432 ++input_line_pointer
;
4433 max_macro_nest
= get_absolute_expression ();
4436 /* Handle the OPT P=chip option. */
4443 if (*input_line_pointer
!= '=')
4445 /* This is just OPT P, which we do not support. */
4449 ++input_line_pointer
;
4453 /* Handle the OPT S option. */
4463 /* Handle the OPT T option. */
4466 opt_list_symbols (arg
, on
)
4471 listing
|= LISTING_SYMBOLS
;
4473 listing
&=~ LISTING_SYMBOLS
;
4476 /* Handle the MRI REG pseudo-op. */
4487 if (line_label
== NULL
)
4489 as_bad ("missing label");
4490 ignore_rest_of_line ();
4496 s
= input_line_pointer
;
4497 while (isalnum ((unsigned char) *input_line_pointer
)
4498 #ifdef REGISTER_PREFIX
4499 || *input_line_pointer
== REGISTER_PREFIX
4501 || *input_line_pointer
== '/'
4502 || *input_line_pointer
== '-')
4503 ++input_line_pointer
;
4504 c
= *input_line_pointer
;
4505 *input_line_pointer
= '\0';
4507 if (m68k_ip_op (s
, &rop
) != 0)
4509 if (rop
.error
== NULL
)
4510 as_bad ("bad register list");
4512 as_bad ("bad register list: %s", rop
.error
);
4513 *input_line_pointer
= c
;
4514 ignore_rest_of_line ();
4518 *input_line_pointer
= c
;
4520 if (rop
.mode
== REGLST
)
4522 else if (rop
.mode
== DREG
)
4523 mask
= 1 << (rop
.reg
- DATA0
);
4524 else if (rop
.mode
== AREG
)
4525 mask
= 1 << (rop
.reg
- ADDR0
+ 8);
4526 else if (rop
.mode
== FPREG
)
4527 mask
= 1 << (rop
.reg
- FP0
+ 16);
4528 else if (rop
.mode
== CONTROL
4531 else if (rop
.mode
== CONTROL
4534 else if (rop
.mode
== CONTROL
4539 as_bad ("bad register list");
4540 ignore_rest_of_line ();
4544 S_SET_SEGMENT (line_label
, absolute_section
);
4545 S_SET_VALUE (line_label
, mask
);
4546 line_label
->sy_frag
= &zero_address_frag
;
4548 demand_empty_rest_of_line ();
4551 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
4555 struct save_opts
*next
;
4557 int symbols_case_sensitive
;
4565 /* FIXME: We don't save OPT S. */
4568 /* This variable holds the stack of saved options. */
4570 static struct save_opts
*save_stack
;
4572 /* The MRI SAVE pseudo-op. */
4578 struct save_opts
*s
;
4580 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
4581 s
->abspcadd
= m68k_abspcadd
;
4582 s
->symbols_case_sensitive
= symbols_case_sensitive
;
4583 s
->keep_locals
= flag_keep_locals
;
4584 s
->short_refs
= flag_short_refs
;
4585 s
->architecture
= current_architecture
;
4586 s
->quick
= m68k_quick
;
4587 s
->rel32
= m68k_rel32
;
4588 s
->listing
= listing
;
4589 s
->no_warnings
= flag_no_warnings
;
4591 s
->next
= save_stack
;
4594 demand_empty_rest_of_line ();
4597 /* The MRI RESTORE pseudo-op. */
4603 struct save_opts
*s
;
4605 if (save_stack
== NULL
)
4607 as_bad ("restore without save");
4608 ignore_rest_of_line ();
4613 save_stack
= s
->next
;
4615 m68k_abspcadd
= s
->abspcadd
;
4616 symbols_case_sensitive
= s
->symbols_case_sensitive
;
4617 flag_keep_locals
= s
->keep_locals
;
4618 flag_short_refs
= s
->short_refs
;
4619 current_architecture
= s
->architecture
;
4620 m68k_quick
= s
->quick
;
4621 m68k_rel32
= s
->rel32
;
4622 listing
= s
->listing
;
4623 flag_no_warnings
= s
->no_warnings
;
4627 demand_empty_rest_of_line ();
4630 /* Types of MRI structured control directives. */
4632 enum mri_control_type
4640 /* This structure is used to stack the MRI structured control
4643 struct mri_control_info
4645 /* The directive within which this one is enclosed. */
4646 struct mri_control_info
*outer
;
4648 /* The type of directive. */
4649 enum mri_control_type type
;
4651 /* Whether an ELSE has been in an IF. */
4654 /* The add or sub statement at the end of a FOR. */
4657 /* The label of the top of a FOR or REPEAT loop. */
4660 /* The label to jump to for the next iteration, or the else
4661 expression of a conditional. */
4664 /* The label to jump to to break out of the loop, or the label past
4665 the end of a conditional. */
4669 /* The stack of MRI structured control directives. */
4671 static struct mri_control_info
*mri_control_stack
;
4673 /* The current MRI structured control directive index number, used to
4674 generate label names. */
4676 static int mri_control_index
;
4678 /* Some function prototypes. */
4680 static char *mri_control_label
PARAMS ((void));
4681 static struct mri_control_info
*push_mri_control
4682 PARAMS ((enum mri_control_type
));
4683 static void pop_mri_control
PARAMS ((void));
4684 static int parse_mri_condition
PARAMS ((int *));
4685 static int parse_mri_control_operand
4686 PARAMS ((int *, const char **, const char **, const char **, const char **));
4687 static int swap_mri_condition
PARAMS ((int));
4688 static int reverse_mri_condition
PARAMS ((int));
4689 static void build_mri_control_operand
4690 PARAMS ((int, int, const char *, const char *, const char *, const char *,
4691 const char *, const char *, int));
4692 static void parse_mri_control_expression
4693 PARAMS ((char *, int, const char *, const char *, int));
4695 /* Generate a new MRI label structured control directive label name. */
4698 mri_control_label ()
4702 n
= (char *) xmalloc (20);
4703 sprintf (n
, "%smc%d", FAKE_LABEL_NAME
, mri_control_index
);
4704 ++mri_control_index
;
4708 /* Create a new MRI structured control directive. */
4710 static struct mri_control_info
*
4711 push_mri_control (type
)
4712 enum mri_control_type type
;
4714 struct mri_control_info
*n
;
4716 n
= (struct mri_control_info
*) xmalloc (sizeof (struct mri_control_info
));
4720 if (type
== mri_if
|| type
== mri_while
)
4723 n
->top
= mri_control_label ();
4724 n
->next
= mri_control_label ();
4725 n
->bottom
= mri_control_label ();
4727 n
->outer
= mri_control_stack
;
4728 mri_control_stack
= n
;
4733 /* Pop off the stack of MRI structured control directives. */
4738 struct mri_control_info
*n
;
4740 n
= mri_control_stack
;
4741 mri_control_stack
= n
->outer
;
4749 /* Recognize a condition code in an MRI structured control expression. */
4752 parse_mri_condition (pcc
)
4757 know (*input_line_pointer
== '<');
4759 ++input_line_pointer
;
4760 c1
= *input_line_pointer
++;
4761 c2
= *input_line_pointer
++;
4763 if (*input_line_pointer
!= '>')
4765 as_bad ("syntax error in structured control directive");
4769 ++input_line_pointer
;
4777 *pcc
= (c1
<< 8) | c2
;
4782 /* Parse a single operand in an MRI structured control expression. */
4785 parse_mri_control_operand (pcc
, leftstart
, leftstop
, rightstart
, rightstop
)
4787 const char **leftstart
;
4788 const char **leftstop
;
4789 const char **rightstart
;
4790 const char **rightstop
;
4802 if (*input_line_pointer
== '<')
4804 /* It's just a condition code. */
4805 return parse_mri_condition (pcc
);
4808 /* Look ahead for the condition code. */
4809 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
4811 if (*s
== '<' && s
[1] != '\0' && s
[2] != '\0' && s
[3] == '>')
4816 as_bad ("missing condition code in structured control directive");
4820 *leftstart
= input_line_pointer
;
4822 if (*leftstop
> *leftstart
4823 && ((*leftstop
)[-1] == ' ' || (*leftstop
)[-1] == '\t'))
4826 input_line_pointer
= s
;
4827 if (! parse_mri_condition (pcc
))
4830 /* Look ahead for AND or OR or end of line. */
4831 for (s
= input_line_pointer
; *s
!= '\0'; ++s
)
4833 if ((strncasecmp (s
, "AND", 3) == 0
4834 && (s
[3] == '.' || ! is_part_of_name (s
[3])))
4835 || (strncasecmp (s
, "OR", 2) == 0
4836 && (s
[2] == '.' || ! is_part_of_name (s
[2]))))
4840 *rightstart
= input_line_pointer
;
4842 if (*rightstop
> *rightstart
4843 && ((*rightstop
)[-1] == ' ' || (*rightstop
)[-1] == '\t'))
4846 input_line_pointer
= s
;
4851 #define MCC(b1, b2) (((b1) << 8) | (b2))
4853 /* Swap the sense of a condition. This changes the condition so that
4854 it generates the same result when the operands are swapped. */
4857 swap_mri_condition (cc
)
4862 case MCC ('h', 'i'): return MCC ('c', 's');
4863 case MCC ('l', 's'): return MCC ('c', 'c');
4864 case MCC ('c', 'c'): return MCC ('l', 's');
4865 case MCC ('c', 's'): return MCC ('h', 'i');
4866 case MCC ('p', 'l'): return MCC ('m', 'i');
4867 case MCC ('m', 'i'): return MCC ('p', 'l');
4868 case MCC ('g', 'e'): return MCC ('l', 'e');
4869 case MCC ('l', 't'): return MCC ('g', 't');
4870 case MCC ('g', 't'): return MCC ('l', 't');
4871 case MCC ('l', 'e'): return MCC ('g', 'e');
4876 /* Reverse the sense of a condition. */
4879 reverse_mri_condition (cc
)
4884 case MCC ('h', 'i'): return MCC ('l', 's');
4885 case MCC ('l', 's'): return MCC ('h', 'i');
4886 case MCC ('c', 'c'): return MCC ('c', 's');
4887 case MCC ('c', 's'): return MCC ('c', 'c');
4888 case MCC ('n', 'e'): return MCC ('e', 'q');
4889 case MCC ('e', 'q'): return MCC ('n', 'e');
4890 case MCC ('v', 'c'): return MCC ('v', 's');
4891 case MCC ('v', 's'): return MCC ('v', 'c');
4892 case MCC ('p', 'l'): return MCC ('m', 'i');
4893 case MCC ('m', 'i'): return MCC ('p', 'l');
4894 case MCC ('g', 'e'): return MCC ('l', 't');
4895 case MCC ('l', 't'): return MCC ('g', 'e');
4896 case MCC ('g', 't'): return MCC ('l', 'e');
4897 case MCC ('l', 'e'): return MCC ('g', 't');
4902 /* Build an MRI structured control expression. This generates test
4903 and branch instructions. It goes to TRUELAB if the condition is
4904 true, and to FALSELAB if the condition is false. Exactly one of
4905 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
4906 is the size qualifier for the expression. EXTENT is the size to
4907 use for the branch. */
4910 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
4911 rightstop
, truelab
, falselab
, extent
)
4914 const char *leftstart
;
4915 const char *leftstop
;
4916 const char *rightstart
;
4917 const char *rightstop
;
4918 const char *truelab
;
4919 const char *falselab
;
4925 /* The 68k can't do a general comparision with an immediate operand
4926 on the right hand side. */
4927 if (rightstart
!= NULL
&& *rightstart
== '#')
4931 cc
= swap_mri_condition (cc
);
4933 leftstart
= rightstart
;
4936 leftstop
= rightstop
;
4940 if (truelab
== NULL
)
4942 cc
= reverse_mri_condition (cc
);
4946 if (leftstart
!= NULL
)
4948 buf
= (char *) xmalloc (20
4949 + (leftstop
- leftstart
)
4950 + (rightstop
- rightstart
));
4958 memcpy (s
, leftstart
, leftstop
- leftstart
);
4959 s
+= leftstop
- leftstart
;
4961 memcpy (s
, rightstart
, rightstop
- rightstart
);
4962 s
+= rightstop
- rightstart
;
4968 buf
= (char *) xmalloc (20 + strlen (truelab
));
4976 strcpy (s
, truelab
);
4981 /* Parse an MRI structured control expression. This generates test
4982 and branch instructions. STOP is where the expression ends. It
4983 goes to TRUELAB if the condition is true, and to FALSELAB if the
4984 condition is false. Exactly one of TRUELAB and FALSELAB will be
4985 NULL, meaning to fall through. QUAL is the size qualifier for the
4986 expression. EXTENT is the size to use for the branch. */
4989 parse_mri_control_expression (stop
, qual
, truelab
, falselab
, extent
)
4992 const char *truelab
;
4993 const char *falselab
;
4998 const char *leftstart
;
4999 const char *leftstop
;
5000 const char *rightstart
;
5001 const char *rightstop
;
5006 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5007 &rightstart
, &rightstop
))
5013 if (strncasecmp (input_line_pointer
, "AND", 3) == 0)
5017 if (falselab
!= NULL
)
5020 flab
= mri_control_label ();
5022 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5023 rightstop
, (const char *) NULL
, flab
, extent
);
5025 input_line_pointer
+= 3;
5026 if (*input_line_pointer
!= '.'
5027 || input_line_pointer
[1] == '\0')
5031 qual
= input_line_pointer
[1];
5032 input_line_pointer
+= 2;
5035 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5036 &rightstart
, &rightstop
))
5042 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5043 rightstop
, truelab
, falselab
, extent
);
5045 if (falselab
== NULL
)
5048 else if (strncasecmp (input_line_pointer
, "OR", 2) == 0)
5052 if (truelab
!= NULL
)
5055 tlab
= mri_control_label ();
5057 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5058 rightstop
, tlab
, (const char *) NULL
, extent
);
5060 input_line_pointer
+= 2;
5061 if (*input_line_pointer
!= '.'
5062 || input_line_pointer
[1] == '\0')
5066 qual
= input_line_pointer
[1];
5067 input_line_pointer
+= 2;
5070 if (! parse_mri_control_operand (&cc
, &leftstart
, &leftstop
,
5071 &rightstart
, &rightstop
))
5077 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5078 rightstop
, truelab
, falselab
, extent
);
5080 if (truelab
== NULL
)
5085 build_mri_control_operand (qual
, cc
, leftstart
, leftstop
, rightstart
,
5086 rightstop
, truelab
, falselab
, extent
);
5090 if (input_line_pointer
!= stop
)
5091 as_bad ("syntax error in structured control directive");
5094 /* Handle the MRI IF pseudo-op. This may be a structured control
5095 directive, or it may be a regular assembler conditional, depending
5104 struct mri_control_info
*n
;
5106 /* A structured control directive must end with THEN with an
5107 optional qualifier. */
5108 s
= input_line_pointer
;
5109 while (! is_end_of_line
[(unsigned char) *s
])
5112 while (s
> input_line_pointer
&& (*s
== ' ' || *s
== '\t'))
5115 if (s
- input_line_pointer
> 1
5119 if (s
- input_line_pointer
< 3
5120 || strncasecmp (s
- 3, "THEN", 4) != 0)
5124 as_bad ("missing then");
5125 ignore_rest_of_line ();
5129 /* It's a conditional. */
5134 /* Since this might be a conditional if, this pseudo-op will be
5135 called even if we are supported to be ignoring input. Double
5136 check now. Clobber *input_line_pointer so that ignore_input
5137 thinks that this is not a special pseudo-op. */
5138 c
= *input_line_pointer
;
5139 *input_line_pointer
= 0;
5140 if (ignore_input ())
5142 *input_line_pointer
= c
;
5143 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5144 ++input_line_pointer
;
5145 demand_empty_rest_of_line ();
5148 *input_line_pointer
= c
;
5150 n
= push_mri_control (mri_if
);
5152 parse_mri_control_expression (s
- 3, qual
, (const char *) NULL
,
5153 n
->next
, s
[1] == '.' ? s
[2] : '\0');
5156 input_line_pointer
= s
+ 3;
5158 input_line_pointer
= s
+ 1;
5160 demand_empty_rest_of_line ();
5163 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
5164 structured IF, associate the ELSE with the IF. Otherwise, assume
5165 it is a conditional else. */
5176 && (mri_control_stack
== NULL
5177 || mri_control_stack
->type
!= mri_if
5178 || mri_control_stack
->else_seen
))
5184 c
= *input_line_pointer
;
5185 *input_line_pointer
= 0;
5186 if (ignore_input ())
5188 *input_line_pointer
= c
;
5189 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5190 ++input_line_pointer
;
5191 demand_empty_rest_of_line ();
5194 *input_line_pointer
= c
;
5196 if (mri_control_stack
== NULL
5197 || mri_control_stack
->type
!= mri_if
5198 || mri_control_stack
->else_seen
)
5200 as_bad ("else without matching if");
5201 ignore_rest_of_line ();
5205 mri_control_stack
->else_seen
= 1;
5207 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->bottom
));
5210 sprintf (buf
, "bra%s %s", q
, mri_control_stack
->bottom
);
5214 colon (mri_control_stack
->next
);
5216 demand_empty_rest_of_line ();
5219 /* Handle the MRI ENDI pseudo-op. */
5225 if (mri_control_stack
== NULL
5226 || mri_control_stack
->type
!= mri_if
)
5228 as_bad ("endi without matching if");
5229 ignore_rest_of_line ();
5233 /* ignore_input will not return true for ENDI, so we don't need to
5234 worry about checking it again here. */
5236 if (! mri_control_stack
->else_seen
)
5237 colon (mri_control_stack
->next
);
5238 colon (mri_control_stack
->bottom
);
5242 demand_empty_rest_of_line ();
5245 /* Handle the MRI BREAK pseudo-op. */
5248 s_mri_break (extent
)
5251 struct mri_control_info
*n
;
5255 n
= mri_control_stack
;
5257 && n
->type
!= mri_for
5258 && n
->type
!= mri_repeat
5259 && n
->type
!= mri_while
)
5263 as_bad ("break outside of structured loop");
5264 ignore_rest_of_line ();
5268 buf
= (char *) xmalloc (20 + strlen (n
->bottom
));
5271 sprintf (buf
, "bra%s %s", ex
, n
->bottom
);
5275 demand_empty_rest_of_line ();
5278 /* Handle the MRI NEXT pseudo-op. */
5284 struct mri_control_info
*n
;
5288 n
= mri_control_stack
;
5290 && n
->type
!= mri_for
5291 && n
->type
!= mri_repeat
5292 && n
->type
!= mri_while
)
5296 as_bad ("next outside of structured loop");
5297 ignore_rest_of_line ();
5301 buf
= (char *) xmalloc (20 + strlen (n
->next
));
5304 sprintf (buf
, "bra%s %s", ex
, n
->next
);
5308 demand_empty_rest_of_line ();
5311 /* Handle the MRI FOR pseudo-op. */
5317 const char *varstart
, *varstop
;
5318 const char *initstart
, *initstop
;
5319 const char *endstart
, *endstop
;
5320 const char *bystart
, *bystop
;
5324 struct mri_control_info
*n
;
5330 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
5334 varstart
= input_line_pointer
;
5336 /* Look for the '='. */
5337 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
5338 && *input_line_pointer
!= '=')
5339 ++input_line_pointer
;
5340 if (*input_line_pointer
!= '=')
5342 as_bad ("missing =");
5343 ignore_rest_of_line ();
5347 varstop
= input_line_pointer
;
5348 if (varstop
> varstart
5349 && (varstop
[-1] == ' ' || varstop
[-1] == '\t'))
5352 ++input_line_pointer
;
5354 initstart
= input_line_pointer
;
5356 /* Look for TO or DOWNTO. */
5359 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5361 if (strncasecmp (input_line_pointer
, "TO", 2) == 0
5362 && ! is_part_of_name (input_line_pointer
[2]))
5364 initstop
= input_line_pointer
;
5365 input_line_pointer
+= 2;
5368 if (strncasecmp (input_line_pointer
, "DOWNTO", 6) == 0
5369 && ! is_part_of_name (input_line_pointer
[6]))
5371 initstop
= input_line_pointer
;
5373 input_line_pointer
+= 6;
5376 ++input_line_pointer
;
5378 if (initstop
== NULL
)
5380 as_bad ("missing to or downto");
5381 ignore_rest_of_line ();
5384 if (initstop
> initstart
5385 && (initstop
[-1] == ' ' || initstop
[-1] == '\t'))
5389 endstart
= input_line_pointer
;
5391 /* Look for BY or DO. */
5394 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5396 if (strncasecmp (input_line_pointer
, "BY", 2) == 0
5397 && ! is_part_of_name (input_line_pointer
[2]))
5399 endstop
= input_line_pointer
;
5401 input_line_pointer
+= 2;
5404 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
5405 && (input_line_pointer
[2] == '.'
5406 || ! is_part_of_name (input_line_pointer
[2])))
5408 endstop
= input_line_pointer
;
5409 input_line_pointer
+= 2;
5412 ++input_line_pointer
;
5414 if (endstop
== NULL
)
5416 as_bad ("missing do");
5417 ignore_rest_of_line ();
5420 if (endstop
> endstart
5421 && (endstop
[-1] == ' ' || endstop
[-1] == '\t'))
5427 bystop
= bystart
+ 2;
5432 bystart
= input_line_pointer
;
5436 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
5438 if (strncasecmp (input_line_pointer
, "DO", 2) == 0
5439 && (input_line_pointer
[2] == '.'
5440 || ! is_part_of_name (input_line_pointer
[2])))
5442 bystop
= input_line_pointer
;
5443 input_line_pointer
+= 2;
5446 ++input_line_pointer
;
5450 as_bad ("missing do");
5451 ignore_rest_of_line ();
5454 if (bystop
> bystart
5455 && (bystop
[-1] == ' ' || bystop
[-1] == '\t'))
5459 if (*input_line_pointer
!= '.')
5463 extent
= input_line_pointer
[1];
5464 input_line_pointer
+= 2;
5467 /* We have fully parsed the FOR operands. Now build the loop. */
5469 n
= push_mri_control (mri_for
);
5471 buf
= (char *) xmalloc (50 + (input_line_pointer
- varstart
));
5482 memcpy (s
, initstart
, initstop
- initstart
);
5483 s
+= initstop
- initstart
;
5485 memcpy (s
, varstart
, varstop
- varstart
);
5486 s
+= varstop
- varstart
;
5500 memcpy (s
, endstart
, endstop
- endstart
);
5501 s
+= endstop
- endstart
;
5503 memcpy (s
, varstart
, varstop
- varstart
);
5504 s
+= varstop
- varstart
;
5512 sprintf (buf
, "blt%s %s", ex
, n
->bottom
);
5514 sprintf (buf
, "bgt%s %s", ex
, n
->bottom
);
5517 /* Put together the add or sub instruction used by ENDF. */
5527 memcpy (s
, bystart
, bystop
- bystart
);
5528 s
+= bystop
- bystart
;
5530 memcpy (s
, varstart
, varstop
- varstart
);
5531 s
+= varstop
- varstart
;
5535 demand_empty_rest_of_line ();
5538 /* Handle the MRI ENDF pseudo-op. */
5544 if (mri_control_stack
== NULL
5545 || mri_control_stack
->type
!= mri_for
)
5547 as_bad ("endf without for");
5548 ignore_rest_of_line ();
5552 colon (mri_control_stack
->next
);
5554 md_assemble (mri_control_stack
->incr
);
5556 sprintf (mri_control_stack
->incr
, "bra %s", mri_control_stack
->top
);
5557 md_assemble (mri_control_stack
->incr
);
5559 free (mri_control_stack
->incr
);
5561 colon (mri_control_stack
->bottom
);
5565 demand_empty_rest_of_line ();
5568 /* Handle the MRI REPEAT pseudo-op. */
5571 s_mri_repeat (ignore
)
5574 struct mri_control_info
*n
;
5576 n
= push_mri_control (mri_repeat
);
5578 demand_empty_rest_of_line ();
5581 /* Handle the MRI UNTIL pseudo-op. */
5589 if (mri_control_stack
== NULL
5590 || mri_control_stack
->type
!= mri_repeat
)
5592 as_bad ("until without repeat");
5593 ignore_rest_of_line ();
5597 colon (mri_control_stack
->next
);
5599 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
5602 parse_mri_control_expression (s
, qual
, (const char *) NULL
,
5603 mri_control_stack
->top
, '\0');
5605 colon (mri_control_stack
->bottom
);
5607 input_line_pointer
= s
;
5609 demand_empty_rest_of_line ();
5612 /* Handle the MRI WHILE pseudo-op. */
5620 struct mri_control_info
*n
;
5622 s
= input_line_pointer
;
5623 while (! is_end_of_line
[(unsigned char) *s
])
5626 while (*s
== ' ' || *s
== '\t')
5628 if (s
- input_line_pointer
> 1
5631 if (s
- input_line_pointer
< 2
5632 || strncasecmp (s
- 1, "DO", 2) != 0)
5634 as_bad ("missing do");
5635 ignore_rest_of_line ();
5639 n
= push_mri_control (mri_while
);
5643 parse_mri_control_expression (s
- 1, qual
, (const char *) NULL
, n
->bottom
,
5644 s
[1] == '.' ? s
[2] : '\0');
5646 input_line_pointer
= s
+ 1;
5647 if (*input_line_pointer
== '.')
5648 input_line_pointer
+= 2;
5650 demand_empty_rest_of_line ();
5653 /* Handle the MRI ENDW pseudo-op. */
5661 if (mri_control_stack
== NULL
5662 || mri_control_stack
->type
!= mri_while
)
5664 as_bad ("endw without while");
5665 ignore_rest_of_line ();
5669 buf
= (char *) xmalloc (20 + strlen (mri_control_stack
->next
));
5670 sprintf (buf
, "bra %s", mri_control_stack
->next
);
5674 colon (mri_control_stack
->bottom
);
5678 demand_empty_rest_of_line ();
5683 * Invocation line includes a switch not recognized by the base assembler.
5684 * See if it's a processor-specific option. These are:
5686 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
5687 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
5688 * Select the architecture. Instructions or features not
5689 * supported by the selected architecture cause fatal
5690 * errors. More than one may be specified. The default is
5691 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
5692 * for -m68000, and -m68882 is a synonym for -m68881.
5693 * -[A]m[c]no-68851, -[A]m[c]no-68881
5694 * Don't accept 688?1 instructions. (The "c" is kind of silly,
5695 * so don't use or document it, but that's the way the parsing
5698 * -pic Indicates PIC.
5699 * -k Indicates PIC. (Sun 3 only.)
5704 CONST
char *md_shortopts
= "lSA:m:kQ:V";
5706 CONST
char *md_shortopts
= "lSA:m:k";
5709 struct option md_longopts
[] = {
5710 #define OPTION_PIC (OPTION_MD_BASE)
5711 {"pic", no_argument
, NULL
, OPTION_PIC
},
5712 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
5713 {"register-prefix-optional", no_argument
, NULL
,
5714 OPTION_REGISTER_PREFIX_OPTIONAL
},
5715 {NULL
, no_argument
, NULL
, 0}
5717 size_t md_longopts_size
= sizeof(md_longopts
);
5720 md_parse_option (c
, arg
)
5726 case 'l': /* -l means keep external to 2 bit offset
5727 rather than 16 bit one */
5728 flag_short_refs
= 1;
5731 case 'S': /* -S means that jbsr's always turn into
5733 flag_long_jumps
= 1;
5739 /* intentional fall-through */
5742 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
5746 const char *oarg
= arg
;
5752 if (arg
[0] == 'c' && arg
[1] == '6')
5755 for (i
= 0; i
< n_archs
; i
++)
5756 if (!strcmp (arg
, archs
[i
].name
))
5761 as_bad ("unrecognized option `%s'", oarg
);
5764 arch
= archs
[i
].arch
;
5767 else if (arch
== m68851
)
5776 if (arg
[0] == 'c' && arg
[1] == '6')
5779 for (i
= 0; i
< n_archs
; i
++)
5780 if (!strcmp (arg
, archs
[i
].name
))
5782 unsigned long arch
= archs
[i
].arch
;
5783 if (cpu_of_arch (arch
))
5784 /* It's a cpu spec. */
5786 current_architecture
&= ~m68000up
;
5787 current_architecture
|= arch
;
5789 else if (arch
== m68881
)
5791 current_architecture
|= m68881
;
5794 else if (arch
== m68851
)
5796 current_architecture
|= m68851
;
5806 as_bad ("unrecognized architecture specification `%s'", arg
);
5815 break; /* -pic, Position Independent Code */
5817 case OPTION_REGISTER_PREFIX_OPTIONAL
:
5818 flag_reg_prefix_optional
= 1;
5833 md_show_usage (stream
)
5838 -l use 1 word for refs to undefined symbols [default 2]\n\
5839 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
5840 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
5842 specify variant of 680X0 architecture [default 68020]\n\
5843 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
5844 target has/lacks floating-point coprocessor\n\
5845 [default yes for 68020, 68030, and cpu32]\n\
5846 -m68851 | -mno-68851\n\
5847 target has/lacks memory-management unit coprocessor\n\
5848 [default yes for 68020 and up]\n\
5849 -pic, -k generate position independent code\n\
5850 -S turn jbsr into jsr\n\
5851 --register-prefix-optional\n\
5852 recognize register names without prefix character\n");
5857 /* TEST2: Test md_assemble() */
5858 /* Warning, this routine probably doesn't work anymore */
5862 struct m68k_it the_ins
;
5870 if (!gets (buf
) || !*buf
)
5872 if (buf
[0] == '|' || buf
[1] == '.')
5874 for (cp
= buf
; *cp
; cp
++)
5879 memset (&the_ins
, '\0', sizeof (the_ins
));
5880 m68k_ip (&the_ins
, buf
);
5883 printf ("Error %s in %s\n", the_ins
.error
, buf
);
5887 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
5888 for (n
= 0; n
< the_ins
.numo
; n
++)
5889 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
5891 print_the_insn (&the_ins
.opcode
[0], stdout
);
5892 (void) putchar ('\n');
5894 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
5896 if (the_ins
.operands
[n
].error
)
5898 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
5901 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
5902 if (the_ins
.operands
[n
].b_const
)
5903 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
5904 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
5905 if (the_ins
.operands
[n
].b_iadd
)
5906 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
5907 (void) putchar ('\n');
5919 while (*str
&& *str
!= ' ')
5921 if (str
[-1] == ':' || str
[1] == '=')
5928 /* Possible states for relaxation:
5930 0 0 branch offset byte (bra, etc)
5934 1 0 indexed offsets byte a0@(32,d4:w:1) etc
5938 2 0 two-offset index word-word a0@(32,d4)@(45) etc
5945 /* We have no need to default values of symbols. */
5949 md_undefined_symbol (name
)
5955 /* Round up a section size to the appropriate boundary. */
5957 md_section_align (segment
, size
)
5961 return size
; /* Byte alignment is fine */
5964 /* Exactly what point is a PC-relative offset relative TO?
5965 On the 68k, it is relative to the address of the first extension
5966 word. The difference between the addresses of the offset and the
5967 first extension word is stored in fx_pcrel_adjust. */
5969 md_pcrel_from (fixP
)
5974 /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
5976 adjust
= fixP
->fx_pcrel_adjust
;
5979 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- adjust
;
5982 #ifndef BFD_ASSEMBLER
5985 tc_coff_symbol_emit_hook (ignore
)
5991 tc_coff_sizemachdep (frag
)
5994 switch (frag
->fr_subtype
& 0x3)
6009 /* end of tc-m68k.c */