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
26 #include "opcode/m68k.h"
27 #include "m68k-parse.h"
29 /* This array holds the chars that always start a comment. If the
30 pre-processor is disabled, these aren't very useful */
32 CONST
char comment_chars
[] = "|#";
34 CONST
char comment_chars
[] = "|";
37 /* This array holds the chars that only start a comment at the beginning of
38 a line. If the line seems to have the form '# 123 filename'
39 .line and .file directives will appear in the pre-processed output */
40 /* Note that input_file.c hand checks for '#' at the beginning of the
41 first line of the input file. This is because the compiler outputs
42 #NO_APP at the beginning of its output. */
43 /* Also note that comments like this one will always work. */
44 CONST
char line_comment_chars
[] = "#";
46 CONST
char line_separator_chars
[] = "";
48 /* Chars that can be used to separate mant from exp in floating point nums */
49 CONST
char EXP_CHARS
[] = "eE";
51 /* Chars that mean this number is a floating point constant, as
52 in "0f12.456" or "0d1.2345e12". */
54 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
56 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
57 changed in read.c . Ideally it shouldn't have to know about it at all,
58 but nothing is ideal around here. */
60 const int md_reloc_size
= 8; /* Size of relocation record */
62 /* Are we trying to generate PIC code? If so, absolute references
63 ought to be made into linkage table references or pc-relative
67 static int flag_short_refs
; /* -l option */
68 static int flag_long_jumps
; /* -S option */
70 #ifdef REGISTER_PREFIX_OPTIONAL
71 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
73 int flag_reg_prefix_optional
;
76 /* The floating point coprocessor to use by default. */
77 static enum m68k_register m68k_float_copnum
= COP1
;
79 /* If this is non-zero, then references to number(%pc) will be taken
80 to refer to number, rather than to %pc + number. */
81 static int m68k_abspcadd
;
83 /* If this is non-zero, then the quick forms of the move, add, and sub
84 instructions are used when possible. */
85 static int m68k_quick
= 1;
87 /* If this is non-zero, then if the size is not specified for a base
88 or outer displacement, the assembler assumes that the size should
90 static int m68k_rel32
= 1;
92 /* Its an arbitrary name: This means I don't approve of it */
93 /* See flames below */
94 static struct obstack robyn
;
96 #define TAB(x,y) (((x)<<2)+(y))
97 #define TABTYPE(xy) ((xy) >> 2)
103 /* Case `g' except when BCC68000 is applicable. */
105 /* Coprocessor branches. */
107 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
108 supported on all cpus. Widens to 32-bit absolute. */
110 /* For inserting an extra jmp instruction with long offset on 68000,
111 for expanding conditional branches. (Not bsr or bra.) Since the
112 68000 doesn't support 32-bit displacements for conditional
113 branches, we fake it by reversing the condition and branching
114 around a jmp with an absolute long operand. */
116 /* For the DBcc "instructions". If the displacement requires 32 bits,
117 the branch-around-a-jump game is played here too. */
119 /* Not currently used? */
121 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
127 const char *m_operands
;
128 unsigned long m_opcode
;
132 struct m68k_incant
*m_next
;
135 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
136 #define gettwo(x) (((x)->m_opcode)&0xffff)
138 static const enum m68k_register m68000_control_regs
[] = { 0 };
139 static const enum m68k_register m68010_control_regs
[] = {
143 static const enum m68k_register m68020_control_regs
[] = {
144 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
147 static const enum m68k_register m68040_control_regs
[] = {
148 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
149 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
152 static const enum m68k_register m68060_control_regs
[] = {
153 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
154 USP
, VBR
, URP
, SRP
, PCR
,
157 #define cpu32_control_regs m68010_control_regs
159 static const enum m68k_register
*control_regs
;
161 /* internal form of a 68020 instruction */
165 const char *args
; /* list of opcode info */
168 int numo
; /* Number of shorts in opcode */
171 struct m68k_op operands
[6];
173 int nexp
; /* number of exprs in use */
174 struct m68k_exp exprs
[4];
176 int nfrag
; /* Number of frags we have to produce */
179 int fragoff
; /* Where in the current opcode the frag ends */
186 int nrel
; /* Num of reloc strucs in use */
193 /* In a pc relative address the difference between the address
194 of the offset and the address that the offset is relative
195 to. This depends on the addressing mode. Basically this
196 is the value to put in the offset field to address the
197 first byte of the offset, without regarding the special
198 significance of some values (in the branch instruction, for
202 reloc
[5]; /* Five is enough??? */
205 #define cpu_of_arch(x) ((x) & m68000up)
206 #define float_of_arch(x) ((x) & mfloat)
207 #define mmu_of_arch(x) ((x) & mmmu)
209 static struct m68k_it the_ins
; /* the instruction being assembled */
211 #define op(ex) ((ex)->exp.X_op)
212 #define adds(ex) ((ex)->exp.X_add_symbol)
213 #define subs(ex) ((ex)->exp.X_op_symbol)
214 #define offs(ex) ((ex)->exp.X_add_number)
216 /* Macros for adding things to the m68k_it struct */
218 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
220 /* Like addword, but goes BEFORE general operands */
224 struct m68k_incant
*opcode
;
227 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
228 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
229 for(z
=0;z
<the_ins
.nrel
;z
++)
230 the_ins
.reloc
[z
].n
+=2;
231 for (z
= 0; z
< the_ins
.nfrag
; z
++)
232 the_ins
.fragb
[z
].fragoff
++;
233 the_ins
.opcode
[opcode
->m_codenum
]=w
;
237 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
240 add_fix (width
, exp
, pc_rel
, pc_fix
)
242 struct m68k_exp
*exp
;
246 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
250 : (the_ins
.numo
*2)));
251 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
252 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
253 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
254 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
257 /* Cause an extra frag to be generated here, inserting up to 10 bytes
258 (that value is chosen in the frag_var call in md_assemble). TYPE
259 is the subtype of the frag to be generated; its primary type is
260 rs_machine_dependent.
262 The TYPE parameter is also used by md_convert_frag_1 and
263 md_estimate_size_before_relax. The appropriate type of fixup will
264 be emitted by md_convert_frag_1.
266 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
268 add_frag(add
,off
,type
)
273 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
274 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
275 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
276 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
280 (op (ex) != O_constant && op (ex) != O_big)
282 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
283 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
284 static int reverse_16_bits
PARAMS ((int in
));
285 static int reverse_8_bits
PARAMS ((int in
));
286 static void install_gen_operand
PARAMS ((int mode
, int val
));
287 static void install_operand
PARAMS ((int mode
, int val
));
288 static void s_bss
PARAMS ((int));
289 static void s_data1
PARAMS ((int));
290 static void s_data2
PARAMS ((int));
291 static void s_even
PARAMS ((int));
292 static void s_proc
PARAMS ((int));
293 static void mri_chip
PARAMS ((void));
294 static void s_chip
PARAMS ((int));
295 static void s_fopt
PARAMS ((int));
296 static void s_opt
PARAMS ((int));
297 static void s_reg
PARAMS ((int));
298 static void s_restore
PARAMS ((int));
299 static void s_save
PARAMS ((int));
301 static int current_architecture
;
308 static const struct m68k_cpu archs
[] = {
318 /* Aliases (effectively, so far as gas is concerned) for the above
323 { m68000
, "68ec000" },
324 { m68000
, "68hc000" },
325 { m68000
, "68hc001" },
326 { m68020
, "68ec020" },
327 { m68030
, "68ec030" },
328 { m68040
, "68ec040" },
338 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
340 /* BCC68000 is for patching in an extra jmp instruction for long offsets
341 on the 68000. The 68000 doesn't support long branches with branchs */
343 /* This table desribes how you change sizes for the various types of variable
344 size expressions. This version only supports two kinds. */
346 /* Note that calls to frag_var need to specify the maximum expansion
347 needed; this is currently 10 bytes for DBCC. */
350 How far Forward this mode will reach:
351 How far Backward this mode will reach:
352 How many bytes this mode will add to the size of the frag
353 Which mode to go to if the offset won't fit in this one
355 relax_typeS md_relax_table
[] =
357 {1, 1, 0, 0}, /* First entries aren't used */
358 {1, 1, 0, 0}, /* For no good reason except */
359 {1, 1, 0, 0}, /* that the VAX doesn't either */
362 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
363 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
367 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
368 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
372 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
373 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
377 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
378 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
379 {0, 0, 6, 0}, /* jmp long space */
382 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
383 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
384 {0, 0, 10, 0}, /* bra/jmp long space */
387 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
388 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
392 /* For, e.g., jmp pcrel indexed. */
393 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
394 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
399 /* These are the machine dependent pseudo-ops. These are included so
400 the assembler can work on the output from the SUN C compiler, which
404 /* This table describes all the machine specific pseudo-ops the assembler
405 has to support. The fields are:
406 pseudo-op name without dot
407 function to call to execute this pseudo-op
408 Integer arg to pass to the function
410 CONST pseudo_typeS md_pseudo_table
[] =
412 {"data1", s_data1
, 0},
413 {"data2", s_data2
, 0},
416 {"skip", s_space
, 0},
419 {"align", s_align_bytes
, 0},
422 {"swbeg", s_ignore
, 0},
425 /* The following pseudo-ops are supported for MRI compatibility. */
427 {"comline", s_space
, 1},
429 {"mask2", s_ignore
, 0},
432 {"restore", s_restore
, 0},
439 /* The mote pseudo ops are put into the opcode table, since they
440 don't start with a . they look like opcodes to gas.
442 extern void obj_coff_section ();
444 CONST pseudo_typeS mote_pseudo_table
[] =
457 {"xdef", s_globl
, 0},
458 {"align", s_align_ptwo
, 0},
460 {"sect", obj_coff_section
, 0},
461 {"section", obj_coff_section
, 0},
466 #define issbyte(x) ((x)>=-128 && (x)<=127)
467 #define isubyte(x) ((x)>=0 && (x)<=255)
468 #define issword(x) ((x)>=-32768 && (x)<=32767)
469 #define isuword(x) ((x)>=0 && (x)<=65535)
471 #define isbyte(x) ((x)>= -255 && (x)<=255)
472 #define isword(x) ((x)>=-32768 && (x)<=65535)
473 #define islong(x) (1)
475 extern char *input_line_pointer
;
477 static char mklower_table
[256];
478 #define mklower(c) (mklower_table[(unsigned char)(c)])
479 static char notend_table
[256];
480 static char alt_notend_table
[256];
482 (! (notend_table[(unsigned char) *s] \
484 && alt_notend_table[(unsigned char) s[1]])))
486 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
488 #ifdef NO_PCREL_RELOCS
491 make_pcrel_absolute(fixP
, add_number
)
495 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
497 /* rewrite the PC relative instructions to absolute address ones.
498 * these are rumoured to be faster, and the apollo linker refuses
499 * to deal with the PC relative relocations.
501 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
506 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
512 as_fatal ("Unknown PC relative instruction");
517 #endif /* NO_PCREL_RELOCS */
520 tc_coff_fix2rtype (fixP
)
523 #ifdef NO_PCREL_RELOCS
524 know (fixP
->fx_pcrel
== 0);
525 return (fixP
->fx_size
== 1 ? R_RELBYTE
526 : fixP
->fx_size
== 2 ? R_DIR16
529 return (fixP
->fx_pcrel
?
530 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
531 fixP
->fx_size
== 2 ? R_PCRWORD
:
533 (fixP
->fx_size
== 1 ? R_RELBYTE
:
534 fixP
->fx_size
== 2 ? R_RELWORD
:
544 tc_gen_reloc (section
, fixp
)
549 bfd_reloc_code_real_type code
;
551 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
552 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
554 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
555 MAP (1, 0, BFD_RELOC_8
);
556 MAP (2, 0, BFD_RELOC_16
);
557 MAP (4, 0, BFD_RELOC_32
);
558 MAP (1, 1, BFD_RELOC_8_PCREL
);
559 MAP (2, 1, BFD_RELOC_16_PCREL
);
560 MAP (4, 1, BFD_RELOC_32_PCREL
);
565 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
567 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
568 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
570 reloc
->addend
= fixp
->fx_addnumber
;
574 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
575 assert (reloc
->howto
!= 0);
580 #endif /* BFD_ASSEMBLER */
582 /* Handle of the OPCODE hash table. NULL means any use before
583 m68k_ip_begin() will crash. */
584 static struct hash_control
*op_hash
;
586 /* Assemble an m68k instruction. */
593 register struct m68k_op
*opP
;
594 register struct m68k_incant
*opcode
;
595 register const char *s
;
596 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
597 char *pdot
, *pdotmove
;
598 enum m68k_size siz1
, siz2
;
602 char *crack_operand ();
603 LITTLENUM_TYPE words
[6];
604 LITTLENUM_TYPE
*wordp
;
605 unsigned long ok_arch
= 0;
607 if (*instring
== ' ')
608 instring
++; /* skip leading whitespace */
610 /* Scan up to end of operation-code, which MUST end in end-of-string
611 or exactly 1 space. */
613 for (p
= instring
; *p
!= '\0'; p
++)
623 the_ins
.error
= "No operator";
627 /* p now points to the end of the opcode name, probably whitespace.
628 Make sure the name is null terminated by clobbering the
629 whitespace, look it up in the hash table, then fix it back.
630 Remove a dot, first, since the opcode tables have none. */
633 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
634 *pdotmove
= pdotmove
[1];
640 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
645 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
646 *pdotmove
= pdotmove
[-1];
653 the_ins
.error
= "Unknown operator";
657 /* found a legitimate opcode, start matching operands */
661 if (opcode
->m_operands
== 0)
663 char *old
= input_line_pointer
;
665 input_line_pointer
= p
;
666 /* Ahh - it's a motorola style psuedo op */
667 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
668 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
669 input_line_pointer
= old
;
675 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
677 p
= crack_operand (p
, opP
);
681 the_ins
.error
= opP
->error
;
686 opsfound
= opP
- &the_ins
.operands
[0];
688 /* This ugly hack is to support the floating pt opcodes in their
689 standard form. Essentially, we fake a first enty of type COP#1 */
690 if (opcode
->m_operands
[0] == 'I')
694 for (n
= opsfound
; n
> 0; --n
)
695 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
697 memset ((char *) (&the_ins
.operands
[0]), '\0',
698 sizeof (the_ins
.operands
[0]));
699 the_ins
.operands
[0].mode
= CONTROL
;
700 the_ins
.operands
[0].reg
= m68k_float_copnum
;
704 /* We've got the operands. Find an opcode that'll accept them */
707 /* If we didn't get the right number of ops, or we have no
708 common model with this pattern then reject this pattern. */
710 if (opsfound
!= opcode
->m_opnum
711 || ((opcode
->m_arch
& current_architecture
) == 0))
714 ok_arch
|= opcode
->m_arch
;
718 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
722 /* Warning: this switch is huge! */
723 /* I've tried to organize the cases into this order:
724 non-alpha first, then alpha by letter. Lower-case
725 goes directly before uppercase counterpart. */
726 /* Code with multiple case ...: gets sorted by the lowest
727 case ... it belongs to. I hope this makes sense. */
767 if (opP
->mode
!= IMMED
)
770 && ! isvar (&opP
->disp
)
771 && (opP
->disp
.exp
.X_op
!= O_constant
772 || ! isbyte (opP
->disp
.exp
.X_add_number
)))
775 && ! isvar (&opP
->disp
)
776 && (opP
->disp
.exp
.X_op
!= O_constant
777 || ! isword (opP
->disp
.exp
.X_add_number
)))
783 if (opP
->mode
!= IMMED
)
788 if (opP
->mode
== AREG
789 || opP
->mode
== CONTROL
790 || opP
->mode
== FPREG
791 || opP
->mode
== IMMED
792 || opP
->mode
== REGLST
793 || (opP
->mode
!= ABSL
795 || opP
->reg
== ZPC
)))
800 if (opP
->mode
== CONTROL
801 || opP
->mode
== FPREG
802 || opP
->mode
== REGLST
803 || (opP
->mode
!= ABSL
804 && opP
->mode
!= IMMED
806 || opP
->reg
== ZPC
)))
834 if (opP
->mode
== CONTROL
835 || opP
->mode
== FPREG
836 || opP
->mode
== REGLST
)
841 if (opP
->mode
!= AINC
)
846 if (opP
->mode
!= ADEC
)
896 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
917 case '~': /* For now! (JF FOO is this right?) */
939 if (opP
->mode
!= CONTROL
940 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
945 if (opP
->mode
!= AREG
)
950 if (opP
->mode
!= AINDR
)
955 if (opP
->mode
!= ABSL
957 && strncmp (instring
, "jbsr", 4) == 0))
962 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
967 if (opP
->mode
!= DISP
974 if (opP
->mode
!= DREG
)
979 if (opP
->mode
!= FPREG
)
984 if (opP
->mode
!= CONTROL
991 if (opP
->mode
!= CONTROL
993 || opP
->reg
> last_movec_reg
)
997 const enum m68k_register
*rp
;
998 for (rp
= control_regs
; *rp
; rp
++)
1007 if (opP
->mode
!= IMMED
)
1013 if (opP
->mode
== DREG
1014 || opP
->mode
== AREG
1015 || opP
->mode
== FPREG
)
1024 opP
->mask
= 1 << (opP
->reg
- DATA0
);
1027 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
1030 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
1038 else if (opP
->mode
== CONTROL
)
1047 opP
->mask
= 1 << 24;
1050 opP
->mask
= 1 << 25;
1053 opP
->mask
= 1 << 26;
1062 else if (opP
->mode
== ABSL
1063 && opP
->disp
.size
== SIZE_UNSPEC
1064 && opP
->disp
.exp
.X_op
== O_constant
)
1066 /* This is what the MRI REG pseudo-op generates. */
1068 opP
->mask
= opP
->disp
.exp
.X_add_number
;
1070 else if (opP
->mode
!= REGLST
)
1072 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1074 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1079 if (opP
->mode
!= IMMED
)
1081 else if (opP
->disp
.exp
.X_op
!= O_constant
1082 || ! issbyte (opP
->disp
.exp
.X_add_number
))
1084 else if (! m68k_quick
1085 && instring
[3] != 'q'
1086 && instring
[4] != 'q')
1091 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1096 if (opP
->mode
!= IMMED
)
1098 else if (opP
->disp
.exp
.X_op
!= O_constant
1099 || opP
->disp
.exp
.X_add_number
< 1
1100 || opP
->disp
.exp
.X_add_number
> 8)
1102 else if (! m68k_quick
1103 && (strncmp (instring
, "add", 3) == 0
1104 || strncmp (instring
, "sub", 3) == 0)
1105 && instring
[3] != 'q')
1110 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1115 if (opP
->mode
!= AINDR
1116 && (opP
->mode
!= BASE
1118 && opP
->reg
!= ZADDR0
)
1119 || opP
->disp
.exp
.X_op
!= O_absent
1120 || ((opP
->index
.reg
< DATA0
1121 || opP
->index
.reg
> DATA7
)
1122 && (opP
->index
.reg
< ADDR0
1123 || opP
->index
.reg
> ADDR7
))
1124 || opP
->index
.size
!= SIZE_UNSPEC
1125 || opP
->index
.scale
!= 1))
1130 if (opP
->mode
!= CONTROL
1131 || ! (opP
->reg
== FPI
1133 || opP
->reg
== FPC
))
1138 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1143 if (opP
->mode
!= IMMED
)
1145 else if (opP
->disp
.exp
.X_op
!= O_constant
1146 || opP
->disp
.exp
.X_add_number
< 0
1147 || opP
->disp
.exp
.X_add_number
> 7)
1152 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1156 /* JF these are out of order. We could put them
1157 in order if we were willing to put up with
1158 bunches of #ifdef m68851s in the code.
1160 Don't forget that you need these operands
1161 to use 68030 MMU instructions. */
1163 /* Memory addressing mode used by pflushr */
1165 if (opP
->mode
== CONTROL
1166 || opP
->mode
== FPREG
1167 || opP
->mode
== DREG
1168 || opP
->mode
== AREG
1169 || opP
->mode
== REGLST
)
1174 if (opP
->mode
!= CONTROL
1175 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1180 if (opP
->mode
!= CONTROL
1190 if (opP
->mode
!= CONTROL
1196 if (opP
->mode
!= CONTROL
1199 && opP
->reg
!= CRP
))
1204 if (opP
->mode
!= CONTROL
1205 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1206 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1211 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1216 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1221 if (opP
->mode
!= CONTROL
1228 } /* not a cache specifier. */
1232 if (opP
->mode
!= ABSL
)
1238 } /* switch on type of operand */
1242 } /* for each operand */
1243 } /* if immediately wrong */
1250 opcode
= opcode
->m_next
;
1255 && !(ok_arch
& current_architecture
))
1260 "invalid instruction for this architecture; needs ");
1261 cp
= buf
+ strlen (buf
);
1265 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1268 strcpy (cp
, "mmu (68030 or 68851)");
1271 strcpy (cp
, "68020 or higher");
1274 strcpy (cp
, "68000 or higher");
1277 strcpy (cp
, "68010 or higher");
1281 int got_one
= 0, idx
;
1282 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1285 if (archs
[idx
].arch
& ok_arch
)
1289 strcpy (cp
, " or ");
1293 strcpy (cp
, archs
[idx
].name
);
1305 the_ins
.error
= "operands mismatch";
1307 } /* Fell off the end */
1312 /* now assemble it */
1314 the_ins
.args
= opcode
->m_operands
;
1315 the_ins
.numargs
= opcode
->m_opnum
;
1316 the_ins
.numo
= opcode
->m_codenum
;
1317 the_ins
.opcode
[0] = getone (opcode
);
1318 the_ins
.opcode
[1] = gettwo (opcode
);
1320 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1322 /* This switch is a doozy.
1323 Watch the first step; its a big one! */
1344 tmpreg
= 0x3c; /* 7.4 */
1345 if (strchr ("bwl", s
[1]))
1346 nextword
= get_num (&opP
->disp
, 80);
1348 nextword
= get_num (&opP
->disp
, 0);
1349 if (isvar (&opP
->disp
))
1350 add_fix (s
[1], &opP
->disp
, 0, 0);
1354 if (!isbyte (nextword
))
1355 opP
->error
= "operand out of range";
1360 if (!isword (nextword
))
1361 opP
->error
= "operand out of range";
1366 addword (nextword
>> 16);
1393 /* We gotta put out some float */
1394 if (op (&opP
->disp
) != O_big
)
1399 /* Can other cases happen here? */
1400 if (op (&opP
->disp
) != O_constant
)
1403 val
= (valueT
) offs (&opP
->disp
);
1407 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1408 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1412 offs (&opP
->disp
) = gencnt
;
1414 if (offs (&opP
->disp
) > 0)
1416 if (offs (&opP
->disp
) > baseo
)
1418 as_warn ("Bignum too big for %c format; truncated",
1420 offs (&opP
->disp
) = baseo
;
1422 baseo
-= offs (&opP
->disp
);
1425 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1426 offs (&opP
->disp
)--;
1431 gen_to_words (words
, baseo
, (long) outro
);
1432 for (wordp
= words
; baseo
--; wordp
++)
1436 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1439 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1442 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1445 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1448 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1452 nextword
= get_num (&opP
->disp
, 80);
1455 && ! isvar (&opP
->disp
)
1458 opP
->disp
.exp
.X_op
= O_symbol
;
1459 #ifndef BFD_ASSEMBLER
1460 opP
->disp
.exp
.X_add_symbol
= &abs_symbol
;
1462 opP
->disp
.exp
.X_add_symbol
=
1463 section_symbol (absolute_section
);
1467 /* Force into index mode. Hope this works */
1469 /* We do the first bit for 32-bit displacements, and the
1470 second bit for 16 bit ones. It is possible that we
1471 should make the default be WORD instead of LONG, but
1472 I think that'd break GCC, so we put up with a little
1473 inefficiency for the sake of working output. */
1475 if (!issword (nextword
)
1476 || (isvar (&opP
->disp
)
1477 && ((opP
->disp
.size
== SIZE_UNSPEC
1478 && flag_short_refs
== 0
1479 && cpu_of_arch (current_architecture
) >= m68020
)
1480 || opP
->disp
.size
== SIZE_LONG
)))
1483 tmpreg
= 0x3B; /* 7.3 */
1485 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1486 if (isvar (&opP
->disp
))
1492 add_fix ('l', &opP
->disp
, 1, 2);
1493 addword (0), addword (0);
1495 add_frag (adds (&opP
->disp
),
1497 TAB (PCLEA
, SZ_UNDEF
));
1504 add_fix ('l', &opP
->disp
, 0, 0);
1509 addword (nextword
>> 16);
1514 tmpreg
= 0x3A; /* 7.2 */
1516 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1518 if (isvar (&opP
->disp
))
1522 add_fix ('w', &opP
->disp
, 1, 0);
1525 add_fix ('w', &opP
->disp
, 0, 0);
1535 baseo
= get_num (&opP
->disp
, 80);
1536 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1537 outro
= get_num (&opP
->odisp
, 80);
1538 /* Figure out the `addressing mode'.
1539 Also turn on the BASE_DISABLE bit, if needed. */
1540 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1542 tmpreg
= 0x3b; /* 7.3 */
1543 if (opP
->reg
== ZPC
)
1546 else if (opP
->reg
== 0)
1549 tmpreg
= 0x30; /* 6.garbage */
1551 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
1554 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
1557 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1559 siz1
= opP
->disp
.size
;
1560 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1561 siz2
= opP
->odisp
.size
;
1565 /* Index register stuff */
1566 if (opP
->index
.reg
!= 0
1567 && opP
->index
.reg
>= DATA
1568 && opP
->index
.reg
<= ADDR7
)
1570 nextword
|= (opP
->index
.reg
- DATA
) << 12;
1572 if (opP
->index
.size
== SIZE_UNSPEC
1573 || opP
->index
.size
== SIZE_LONG
)
1576 if (cpu_of_arch (current_architecture
) < m68020
)
1578 if (opP
->index
.scale
!= 1)
1581 "scale factor invalid on this architecture; needs 68020 or higher";
1585 switch (opP
->index
.scale
)
1602 GET US OUT OF HERE! */
1604 /* Must be INDEX, with an index register. Address
1605 register cannot be ZERO-PC, and either :b was
1606 forced, or we know it will fit. For a 68000 or
1607 68010, force this mode anyways, because the
1608 larger modes aren't supported. */
1609 if (opP
->mode
== BASE
1610 && ((opP
->reg
>= ADDR0
1611 && opP
->reg
<= ADDR7
)
1614 if (siz1
== SIZE_BYTE
1615 || cpu_of_arch (current_architecture
) < m68020
1616 || (siz1
== SIZE_UNSPEC
1617 && ! isvar (&opP
->disp
)
1618 && issbyte (baseo
)))
1620 nextword
+= baseo
& 0xff;
1622 if (isvar (&opP
->disp
))
1624 /* Do a byte relocation. If it doesn't
1625 fit (possible on m68000) let the
1626 fixup processing complain later. */
1628 add_fix ('B', &opP
->disp
, 1, 1);
1630 add_fix ('B', &opP
->disp
, 0, 0);
1632 else if (siz1
!= SIZE_BYTE
)
1634 if (siz1
!= SIZE_UNSPEC
)
1635 as_warn ("Forcing byte displacement");
1636 if (! issbyte (baseo
))
1637 opP
->error
= "byte displacement out of range";
1642 else if (siz1
== SIZE_UNSPEC
1644 && isvar (&opP
->disp
)
1645 && subs (&opP
->disp
) == NULL
)
1647 nextword
+= baseo
& 0xff;
1649 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1650 TAB (PCINDEX
, SZ_UNDEF
));
1658 nextword
|= 0x40; /* No index reg */
1659 if (opP
->index
.reg
>= ZDATA0
1660 && opP
->index
.reg
<= ZDATA7
)
1661 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
1662 else if (opP
->index
.reg
>= ZADDR0
1663 || opP
->index
.reg
<= ZADDR7
)
1664 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
1667 /* It isn't simple. */
1669 if (cpu_of_arch (current_architecture
) < m68020
)
1671 "invalid operand mode for this architecture; needs 68020 or higher";
1674 /* If the guy specified a width, we assume that it is
1675 wide enough. Maybe it isn't. If so, we lose. */
1679 if (isvar (&opP
->disp
)
1681 : ! issword (baseo
))
1686 else if (! isvar (&opP
->disp
) && baseo
== 0)
1695 as_warn (":b not permitted; defaulting to :w");
1705 /* Figure out innner displacement stuff */
1706 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1711 if (isvar (&opP
->odisp
)
1713 : ! issword (outro
))
1718 else if (! isvar (&opP
->disp
) && outro
== 0)
1727 as_warn (":b not permitted; defaulting to :w");
1736 if (opP
->mode
== POST
)
1741 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
1743 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1744 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
1746 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
1748 if (siz1
== SIZE_LONG
)
1749 addword (baseo
>> 16);
1750 if (siz1
!= SIZE_UNSPEC
)
1753 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
1754 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
1755 if (siz2
== SIZE_LONG
)
1756 addword (outro
>> 16);
1757 if (siz2
!= SIZE_UNSPEC
)
1763 nextword
= get_num (&opP
->disp
, 80);
1764 switch (opP
->disp
.size
)
1769 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
1771 tmpreg
= 0x38; /* 7.0 */
1775 /* Don't generate pc relative code on 68010 and
1777 if (isvar (&opP
->disp
)
1778 && !subs (&opP
->disp
)
1779 && adds (&opP
->disp
)
1780 && (S_GET_SEGMENT (adds (&opP
->disp
)) == text_section
)
1781 && now_seg
== text_section
1782 && cpu_of_arch (current_architecture
) >= m68020
1784 && !strchr ("~%&$?", s
[0]))
1786 tmpreg
= 0x3A; /* 7.2 */
1787 add_frag (adds (&opP
->disp
),
1789 TAB (PCREL
, SZ_UNDEF
));
1792 /* Fall through into long */
1794 if (isvar (&opP
->disp
))
1795 add_fix ('l', &opP
->disp
, 0, 0);
1797 tmpreg
= 0x39;/* 7.1 mode */
1798 addword (nextword
>> 16);
1802 case SIZE_WORD
: /* Word */
1803 if (isvar (&opP
->disp
))
1804 add_fix ('w', &opP
->disp
, 0, 0);
1806 tmpreg
= 0x38;/* 7.0 mode */
1814 as_bad ("unknown/incorrect operand");
1817 install_gen_operand (s
[1], tmpreg
);
1823 { /* JF: I hate floating point! */
1838 tmpreg
= get_num (&opP
->disp
, tmpreg
);
1839 if (isvar (&opP
->disp
))
1840 add_fix (s
[1], &opP
->disp
, 0, 0);
1843 case 'b': /* Danger: These do no check for
1844 certain types of overflow.
1846 if (!isbyte (tmpreg
))
1847 opP
->error
= "out of range";
1848 insop (tmpreg
, opcode
);
1849 if (isvar (&opP
->disp
))
1850 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1853 if (!isword (tmpreg
))
1854 opP
->error
= "out of range";
1855 insop (tmpreg
, opcode
);
1856 if (isvar (&opP
->disp
))
1857 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1860 /* Because of the way insop works, we put these two out
1862 insop (tmpreg
, opcode
);
1863 insop (tmpreg
>> 16, opcode
);
1864 if (isvar (&opP
->disp
))
1865 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1871 install_operand (s
[1], tmpreg
);
1882 install_operand (s
[1], opP
->reg
- ADDR
);
1886 tmpreg
= get_num (&opP
->disp
, 80);
1890 add_fix ('B', &opP
->disp
, 1, -1);
1893 add_fix ('w', &opP
->disp
, 1, 0);
1898 if (cpu_of_arch (current_architecture
) < m68020
)
1899 as_warn ("Can't use long branches on 68000/68010");
1900 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
1901 add_fix ('l', &opP
->disp
, 1, 0);
1906 if (subs (&opP
->disp
)) /* We can't relax it */
1909 /* This could either be a symbol, or an absolute
1910 address. No matter, the frag hacking will finger it
1911 out. Not quite: it can't switch from BRANCH to
1912 BCC68000 for the case where opnd is absolute (it
1913 needs to use the 68000 hack since no conditional abs
1915 if (((cpu_of_arch (current_architecture
) < m68020
)
1916 || (0 == adds (&opP
->disp
)))
1917 && (the_ins
.opcode
[0] >= 0x6200)
1918 && (the_ins
.opcode
[0] <= 0x6f00))
1919 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1920 TAB (BCC68000
, SZ_UNDEF
));
1922 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1923 TAB (ABRANCH
, SZ_UNDEF
));
1926 if (isvar (&opP
->disp
))
1929 /* check for DBcc instruction */
1930 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
1932 /* size varies if patch */
1933 /* needed for long form */
1934 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1935 TAB (DBCC
, SZ_UNDEF
));
1939 add_fix ('w', &opP
->disp
, 1, 0);
1943 case 'C': /* Fixed size LONG coproc branches */
1944 add_fix ('l', &opP
->disp
, 1, 0);
1948 case 'c': /* Var size Coprocesssor branches */
1949 if (subs (&opP
->disp
))
1951 add_fix ('l', &opP
->disp
, 1, 0);
1952 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
1954 else if (adds (&opP
->disp
))
1955 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1956 TAB (FBRANCH
, SZ_UNDEF
));
1959 /* add_frag((symbolS *) 0, offs(&opP->disp),
1960 TAB(FBRANCH,SHORT)); */
1961 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
1962 add_fix ('l', &opP
->disp
, 1, 0);
1972 case 'C': /* Ignore it */
1975 case 'd': /* JF this is a kludge */
1976 install_operand ('s', opP
->reg
- ADDR
);
1977 tmpreg
= get_num (&opP
->disp
, 80);
1978 if (!issword (tmpreg
))
1980 as_warn ("Expression out of range, using 0");
1987 install_operand (s
[1], opP
->reg
- DATA
);
1991 install_operand (s
[1], opP
->reg
- FP0
);
1995 tmpreg
= opP
->reg
- COP0
;
1996 install_operand (s
[1], tmpreg
);
1999 case 'J': /* JF foo */
2060 install_operand (s
[1], tmpreg
);
2064 tmpreg
= get_num (&opP
->disp
, 55);
2065 install_operand (s
[1], tmpreg
& 0x7f);
2072 if (tmpreg
& 0x7FF0000)
2073 as_bad ("Floating point register in register list");
2074 insop (reverse_16_bits (tmpreg
), opcode
);
2078 if (tmpreg
& 0x700FFFF)
2079 as_bad ("Wrong register in floating-point reglist");
2080 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2088 if (tmpreg
& 0x7FF0000)
2089 as_bad ("Floating point register in register list");
2090 insop (tmpreg
, opcode
);
2092 else if (s
[1] == '8')
2094 if (tmpreg
& 0x0FFFFFF)
2095 as_bad ("incorrect register in reglist");
2096 install_operand (s
[1], tmpreg
>> 24);
2100 if (tmpreg
& 0x700FFFF)
2101 as_bad ("wrong register in floating-point reglist");
2103 install_operand (s
[1], tmpreg
>> 16);
2108 install_operand (s
[1], get_num (&opP
->disp
, 60));
2112 tmpreg
= ((opP
->mode
== DREG
)
2113 ? 0x20 + opP
->reg
- DATA
2114 : (get_num (&opP
->disp
, 40) & 0x1F));
2115 install_operand (s
[1], tmpreg
);
2119 tmpreg
= get_num (&opP
->disp
, 10);
2122 install_operand (s
[1], tmpreg
);
2126 /* This depends on the fact that ADDR registers are eight
2127 more than their corresponding DATA regs, so the result
2128 will have the ADDR_REG bit set */
2129 install_operand (s
[1], opP
->reg
- DATA
);
2133 if (opP
->mode
== AINDR
)
2134 install_operand (s
[1], opP
->reg
- DATA
);
2136 install_operand (s
[1], opP
->index
.reg
- DATA
);
2140 if (opP
->reg
== FPI
)
2142 else if (opP
->reg
== FPS
)
2144 else if (opP
->reg
== FPC
)
2148 install_operand (s
[1], tmpreg
);
2151 case 'S': /* Ignore it */
2155 install_operand (s
[1], get_num (&opP
->disp
, 30));
2158 case 'U': /* Ignore it */
2177 as_fatal ("failed sanity check");
2178 } /* switch on cache token */
2179 install_operand (s
[1], tmpreg
);
2182 /* JF: These are out of order, I fear. */
2195 install_operand (s
[1], tmpreg
);
2219 install_operand (s
[1], tmpreg
);
2223 if (opP
->reg
== VAL
)
2242 install_operand (s
[1], tmpreg
);
2256 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2267 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2273 install_operand (s
[1], tmpreg
);
2276 know (opP
->reg
== PSR
);
2279 know (opP
->reg
== PCSR
);
2294 install_operand (s
[1], tmpreg
);
2297 tmpreg
= get_num (&opP
->disp
, 20);
2298 install_operand (s
[1], tmpreg
);
2300 case '_': /* used only for move16 absolute 32-bit address */
2301 tmpreg
= get_num (&opP
->disp
, 80);
2302 addword (tmpreg
>> 16);
2303 addword (tmpreg
& 0xFFFF);
2310 /* By the time whe get here (FINALLY) the_ins contains the complete
2311 instruction, ready to be emitted. . . */
2315 reverse_16_bits (in
)
2321 static int mask
[16] =
2323 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2324 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2326 for (n
= 0; n
< 16; n
++)
2329 out
|= mask
[15 - n
];
2332 } /* reverse_16_bits() */
2341 static int mask
[8] =
2343 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2346 for (n
= 0; n
< 8; n
++)
2352 } /* reverse_8_bits() */
2354 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2355 (that value is chosen in the frag_var call in md_assemble). TYPE
2356 is the subtype of the frag to be generated; its primary type is
2357 rs_machine_dependent.
2359 The TYPE parameter is also used by md_convert_frag_1 and
2360 md_estimate_size_before_relax. The appropriate type of fixup will
2361 be emitted by md_convert_frag_1.
2363 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2365 install_operand (mode
, val
)
2372 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2375 the_ins
.opcode
[0] |= val
<< 9;
2378 the_ins
.opcode
[1] |= val
<< 12;
2381 the_ins
.opcode
[1] |= val
<< 6;
2384 the_ins
.opcode
[1] |= val
;
2387 the_ins
.opcode
[2] |= val
<< 12;
2390 the_ins
.opcode
[2] |= val
<< 6;
2393 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2394 three words long! */
2396 the_ins
.opcode
[2] |= val
;
2399 the_ins
.opcode
[1] |= val
<< 7;
2402 the_ins
.opcode
[1] |= val
<< 10;
2406 the_ins
.opcode
[1] |= val
<< 5;
2411 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2414 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2417 the_ins
.opcode
[0] |= val
= 0xff;
2420 the_ins
.opcode
[0] |= val
<< 9;
2423 the_ins
.opcode
[1] |= val
;
2426 the_ins
.opcode
[1] |= val
;
2427 the_ins
.numo
++; /* What a hack */
2430 the_ins
.opcode
[1] |= val
<< 4;
2437 the_ins
.opcode
[0] |= (val
<< 6);
2440 the_ins
.opcode
[1] = (val
>> 16);
2441 the_ins
.opcode
[2] = val
& 0xffff;
2445 as_fatal ("failed sanity check.");
2447 } /* install_operand() */
2450 install_gen_operand (mode
, val
)
2457 the_ins
.opcode
[0] |= val
;
2460 /* This is a kludge!!! */
2461 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2470 the_ins
.opcode
[0] |= val
;
2472 /* more stuff goes here */
2474 as_fatal ("failed sanity check.");
2476 } /* install_gen_operand() */
2479 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2480 * then deal with the bitfield hack.
2484 crack_operand (str
, opP
)
2486 register struct m68k_op
*opP
;
2488 register int parens
;
2490 register char *beg_str
;
2497 for (parens
= 0; *str
&& (parens
> 0 || notend (str
)); str
++)
2501 else if (*str
== ')')
2505 opP
->error
= "Extra )";
2511 if (!*str
&& parens
)
2513 opP
->error
= "Missing )";
2518 if (m68k_ip_op (beg_str
, opP
) != 0)
2525 c
= *++str
; /* JF bitfield hack */
2530 as_bad ("Missing operand");
2535 /* This is the guts of the machine-dependent assembler. STR points to a
2536 machine dependent instruction. This function is supposed to emit
2537 the frags/bytes it assembles to.
2541 insert_reg (regname
, regnum
)
2548 #ifdef REGISTER_PREFIX
2549 if (!flag_reg_prefix_optional
)
2551 buf
[0] = REGISTER_PREFIX
;
2552 strcpy (buf
+ 1, regname
);
2557 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
2558 &zero_address_frag
));
2560 for (i
= 0; regname
[i
]; i
++)
2561 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2564 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
2565 &zero_address_frag
));
2574 static const struct init_entry init_table
[] =
2684 /* 68ec030 versions of same */
2687 /* 68ec030 access control unit, identical to 030 MMU status reg */
2690 /* Suppressed data and address registers. */
2715 for (i
= 0; init_table
[i
].name
; i
++)
2716 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
2719 static int no_68851
, no_68881
;
2722 /* a.out machine type. Default to 68020. */
2723 int m68k_aout_machtype
= 2;
2735 int shorts_this_frag
;
2738 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
2743 for (n
= 0; n
< the_ins
.numargs
; n
++)
2744 if (the_ins
.operands
[n
].error
)
2746 er
= the_ins
.operands
[n
].error
;
2752 as_bad ("%s -- statement `%s' ignored", er
, str
);
2756 if (the_ins
.nfrag
== 0)
2758 /* No frag hacking involved; just put it out */
2759 toP
= frag_more (2 * the_ins
.numo
);
2760 fromP
= &the_ins
.opcode
[0];
2761 for (m
= the_ins
.numo
; m
; --m
)
2763 md_number_to_chars (toP
, (long) (*fromP
), 2);
2767 /* put out symbol-dependent info */
2768 for (m
= 0; m
< the_ins
.nrel
; m
++)
2770 switch (the_ins
.reloc
[m
].wid
)
2788 as_fatal ("Don't know how to figure width of %c in md_assemble()",
2789 the_ins
.reloc
[m
].wid
);
2792 fixP
= fix_new_exp (frag_now
,
2793 ((toP
- frag_now
->fr_literal
)
2794 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
2796 &the_ins
.reloc
[m
].exp
,
2797 the_ins
.reloc
[m
].pcrel
,
2799 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2804 /* There's some frag hacking */
2805 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
2810 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
2812 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
2813 toP
= frag_more (wid
);
2815 shorts_this_frag
= 0;
2816 for (m
= wid
/ 2; m
; --m
)
2818 md_number_to_chars (toP
, (long) (*fromP
), 2);
2823 for (m
= 0; m
< the_ins
.nrel
; m
++)
2825 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
2827 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
2830 wid
= the_ins
.reloc
[m
].wid
;
2833 the_ins
.reloc
[m
].wid
= 0;
2834 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
2836 fixP
= fix_new_exp (frag_now
,
2837 ((toP
- frag_now
->fr_literal
)
2838 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
2840 &the_ins
.reloc
[m
].exp
,
2841 the_ins
.reloc
[m
].pcrel
,
2843 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2845 (void) frag_var (rs_machine_dependent
, 10, 0,
2846 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
2847 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
2849 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
2850 shorts_this_frag
= 0;
2853 toP
= frag_more (n
* sizeof (short));
2856 md_number_to_chars (toP
, (long) (*fromP
), 2);
2862 for (m
= 0; m
< the_ins
.nrel
; m
++)
2866 wid
= the_ins
.reloc
[m
].wid
;
2869 the_ins
.reloc
[m
].wid
= 0;
2870 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
2872 fixP
= fix_new_exp (frag_now
,
2873 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
2874 - shorts_this_frag
* 2),
2876 &the_ins
.reloc
[m
].exp
,
2877 the_ins
.reloc
[m
].pcrel
,
2879 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2887 * md_begin -- set up hash tables with 68000 instructions.
2888 * similar to what the vax assembler does. ---phr
2890 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2891 a copy of it at runtime, adding in the information we want but isn't
2892 there. I think it'd be better to have an awk script hack the table
2893 at compile time. Or even just xstr the table and use it as-is. But
2894 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2897 register const struct m68k_opcode
*ins
;
2898 register struct m68k_incant
*hack
, *slak
;
2899 register const char *retval
= 0; /* empty string, or error msg text */
2900 register unsigned int i
;
2905 flag_reg_prefix_optional
= 1;
2910 op_hash
= hash_new ();
2912 obstack_begin (&robyn
, 4000);
2913 for (i
= 0; i
< m68k_numopcodes
; i
++)
2915 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
2918 ins
= &m68k_opcodes
[i
];
2919 /* We *could* ignore insns that don't match our arch here
2920 but just leaving them out of the hash. */
2921 slak
->m_operands
= ins
->args
;
2922 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
2923 slak
->m_arch
= ins
->arch
;
2924 slak
->m_opcode
= ins
->opcode
;
2925 /* This is kludgey */
2926 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
2927 if (i
+ 1 != m68k_numopcodes
2928 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
2930 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
2935 slak
= slak
->m_next
;
2939 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
2941 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
2944 for (i
= 0; i
< m68k_numaliases
; i
++)
2946 const char *name
= m68k_opcode_aliases
[i
].primary
;
2947 const char *alias
= m68k_opcode_aliases
[i
].alias
;
2948 PTR val
= hash_find (op_hash
, name
);
2950 as_fatal ("Internal Error: Can't find %s in hash table", name
);
2951 retval
= hash_insert (op_hash
, alias
, val
);
2953 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
2956 /* In MRI mode, all unsized branches are variable sized. Normally,
2957 they are word sized. */
2960 static struct m68k_opcode_alias mri_aliases
[] =
2980 for (i
= 0; i
< sizeof mri_aliases
/ sizeof mri_aliases
[0]; i
++)
2982 const char *name
= mri_aliases
[i
].primary
;
2983 const char *alias
= mri_aliases
[i
].alias
;
2984 PTR val
= hash_find (op_hash
, name
);
2986 as_fatal ("Internal Error: Can't find %s in hash table", name
);
2987 retval
= hash_jam (op_hash
, alias
, val
);
2989 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
2993 for (i
= 0; i
< sizeof (mklower_table
); i
++)
2994 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
2996 for (i
= 0; i
< sizeof (notend_table
); i
++)
2998 notend_table
[i
] = 0;
2999 alt_notend_table
[i
] = 0;
3001 notend_table
[','] = 1;
3002 notend_table
['{'] = 1;
3003 notend_table
['}'] = 1;
3004 alt_notend_table
['a'] = 1;
3005 alt_notend_table
['A'] = 1;
3006 alt_notend_table
['d'] = 1;
3007 alt_notend_table
['D'] = 1;
3008 alt_notend_table
['#'] = 1;
3009 alt_notend_table
['&'] = 1;
3010 alt_notend_table
['f'] = 1;
3011 alt_notend_table
['F'] = 1;
3012 #ifdef REGISTER_PREFIX
3013 alt_notend_table
[REGISTER_PREFIX
] = 1;
3016 /* We need to put '(' in alt_notend_table to handle
3017 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3019 alt_notend_table
['('] = 1;
3021 /* We need to put '@' in alt_notend_table to handle
3022 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3024 alt_notend_table
['@'] = 1;
3026 #ifndef MIT_SYNTAX_ONLY
3027 /* Insert pseudo ops, these have to go into the opcode table since
3028 gas expects pseudo ops to start with a dot */
3031 while (mote_pseudo_table
[n
].poc_name
)
3033 hack
= (struct m68k_incant
*)
3034 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3035 hash_insert (op_hash
,
3036 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3037 hack
->m_operands
= 0;
3048 m68k_init_after_args ()
3050 if (cpu_of_arch (current_architecture
) == 0)
3053 const char *default_cpu
= TARGET_CPU
;
3055 if (*default_cpu
== 'm')
3057 for (i
= 0; i
< n_archs
; i
++)
3058 if (strcasecmp (default_cpu
, archs
[i
].name
) == 0)
3062 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3063 current_architecture
|= m68020
;
3066 current_architecture
|= archs
[i
].arch
;
3068 /* Permit m68881 specification with all cpus; those that can't work
3069 with a coprocessor could be doing emulation. */
3070 if (current_architecture
& m68851
)
3072 if (current_architecture
& m68040
)
3074 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3077 /* What other incompatibilities could we check for? */
3079 /* Toss in some default assumptions about coprocessors. */
3081 && (cpu_of_arch (current_architecture
)
3082 /* Can CPU32 have a 68881 coprocessor?? */
3083 & (m68020
| m68030
| cpu32
)))
3085 current_architecture
|= m68881
;
3088 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3089 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3091 current_architecture
|= m68851
;
3093 if (no_68881
&& (current_architecture
& m68881
))
3094 as_bad ("options for 68881 and no-68881 both given");
3095 if (no_68851
&& (current_architecture
& m68851
))
3096 as_bad ("options for 68851 and no-68851 both given");
3099 /* Work out the magic number. This isn't very general. */
3100 if (current_architecture
& m68000
)
3101 m68k_aout_machtype
= 0;
3102 else if (current_architecture
& m68010
)
3103 m68k_aout_machtype
= 1;
3104 else if (current_architecture
& m68020
)
3105 m68k_aout_machtype
= 2;
3107 m68k_aout_machtype
= 2;
3110 /* Note which set of "movec" control registers is available. */
3111 switch (cpu_of_arch (current_architecture
))
3114 control_regs
= m68000_control_regs
;
3117 control_regs
= m68010_control_regs
;
3121 control_regs
= m68020_control_regs
;
3124 control_regs
= m68040_control_regs
;
3127 control_regs
= m68060_control_regs
;
3130 control_regs
= cpu32_control_regs
;
3136 if (cpu_of_arch (current_architecture
) < m68020
)
3137 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3140 /* Equal to MAX_PRECISION in atof-ieee.c */
3141 #define MAX_LITTLENUMS 6
3143 /* Turn a string in input_line_pointer into a floating point constant
3144 of type type, and store the appropriate bytes in *litP. The number
3145 of LITTLENUMS emitted is stored in *sizeP . An error message is
3146 returned, or NULL on OK. */
3149 md_atof (type
, litP
, sizeP
)
3155 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3156 LITTLENUM_TYPE
*wordP
;
3188 return "Bad call to MD_ATOF()";
3190 t
= atof_ieee (input_line_pointer
, type
, words
);
3192 input_line_pointer
= t
;
3194 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3195 for (wordP
= words
; prec
--;)
3197 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3198 litP
+= sizeof (LITTLENUM_TYPE
);
3204 md_number_to_chars (buf
, val
, n
)
3209 number_to_chars_bigendian (buf
, val
, n
);
3213 md_apply_fix_2 (fixP
, val
)
3217 addressT upper_limit
;
3218 offsetT lower_limit
;
3220 /* This is unnecessary but it convinces the native rs6000 compiler
3221 to generate the code we want. */
3222 char *buf
= fixP
->fx_frag
->fr_literal
;
3223 buf
+= fixP
->fx_where
;
3224 /* end ibm compiler workaround */
3226 if (val
& 0x80000000)
3227 val
|= ~(addressT
)0x7fffffff;
3231 switch (fixP
->fx_size
)
3233 /* The cast to offsetT below are necessary to make code correct for
3234 machines where ints are smaller than offsetT */
3238 lower_limit
= - (offsetT
) 0x80;
3241 *buf
++ = (val
>> 8);
3243 upper_limit
= 0x7fff;
3244 lower_limit
= - (offsetT
) 0x8000;
3247 *buf
++ = (val
>> 24);
3248 *buf
++ = (val
>> 16);
3249 *buf
++ = (val
>> 8);
3251 upper_limit
= 0x7fffffff;
3252 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3255 BAD_CASE (fixP
->fx_size
);
3258 /* For non-pc-relative values, it's conceivable we might get something
3259 like "0xff" for a byte field. So extend the upper part of the range
3260 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3261 so that we can do any range checking at all. */
3262 if (!fixP
->fx_pcrel
)
3263 upper_limit
= upper_limit
* 2 + 1;
3265 if ((addressT
) val
> upper_limit
3266 && (val
> 0 || val
< lower_limit
))
3267 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
3269 /* A one byte PC-relative reloc means a short branch. We can't use
3270 a short branch with a value of 0 or -1, because those indicate
3271 different opcodes (branches with longer offsets). */
3273 && fixP
->fx_size
== 1
3274 && (fixP
->fx_addsy
== NULL
3275 || S_IS_DEFINED (fixP
->fx_addsy
))
3276 && (val
== 0 || val
== -1))
3277 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
3280 #ifdef BFD_ASSEMBLER
3282 md_apply_fix (fixP
, valp
)
3286 md_apply_fix_2 (fixP
, (addressT
) *valp
);
3290 void md_apply_fix (fixP
, val
)
3294 md_apply_fix_2 (fixP
, (addressT
) val
);
3298 /* *fragP has been relaxed to its final size, and now needs to have
3299 the bytes inside it modified to conform to the new size There is UGLY
3303 md_convert_frag_1 (fragP
)
3304 register fragS
*fragP
;
3310 /* Address in object code of the displacement. */
3311 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3313 /* Address in gas core of the place to store the displacement. */
3314 /* This convinces the native rs6000 compiler to generate the code we
3316 register char *buffer_address
= fragP
->fr_literal
;
3317 buffer_address
+= fragP
->fr_fix
;
3318 /* end ibm compiler workaround */
3320 /* The displacement of the address, from current location. */
3321 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3322 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3324 #ifdef BFD_ASSEMBLER
3325 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
3328 switch (fragP
->fr_subtype
)
3330 case TAB (BCC68000
, BYTE
):
3331 case TAB (ABRANCH
, BYTE
):
3332 know (issbyte (disp
));
3334 as_bad ("short branch with zero offset: use :w");
3335 fragP
->fr_opcode
[1] = disp
;
3338 case TAB (DBCC
, SHORT
):
3339 know (issword (disp
));
3342 case TAB (BCC68000
, SHORT
):
3343 case TAB (ABRANCH
, SHORT
):
3344 know (issword (disp
));
3345 fragP
->fr_opcode
[1] = 0x00;
3348 case TAB (ABRANCH
, LONG
):
3349 if (cpu_of_arch (current_architecture
) < m68020
)
3351 if (fragP
->fr_opcode
[0] == 0x61)
3354 fragP
->fr_opcode
[0] = 0x4E;
3355 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3356 subseg_change (text_section
, 0); /* @@ */
3370 else if (fragP
->fr_opcode
[0] == 0x60)
3372 fragP
->fr_opcode
[0] = 0x4E;
3373 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3374 subseg_change (text_section
, 0); /* @@ */
3375 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3376 fragP
->fr_offset
, 0, NO_RELOC
);
3382 as_bad ("Long branch offset not supported.");
3387 fragP
->fr_opcode
[1] = (char) 0xff;
3391 case TAB (BCC68000
, LONG
):
3392 /* only Bcc 68000 instructions can come here */
3393 /* change bcc into b!cc/jmp absl long */
3394 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3395 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
3397 /* JF: these used to be fr_opcode[2,3], but they may be in a
3398 different frag, in which case refering to them is a no-no.
3399 Only fr_opcode[0,1] are guaranteed to work. */
3400 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3401 *buffer_address
++ = (char) 0xf9;
3402 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3403 subseg_change (text_section
, 0);
3404 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3405 fragP
->fr_offset
, 0, NO_RELOC
);
3409 case TAB (DBCC
, LONG
):
3410 /* only DBcc 68000 instructions can come here */
3411 /* change dbcc into dbcc/jmp absl long */
3412 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3413 *buffer_address
++ = 0x00; /* branch offset = 4 */
3414 *buffer_address
++ = 0x04;
3415 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3416 *buffer_address
++ = 0x06;
3417 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3418 *buffer_address
++ = (char) 0xf9;
3420 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3421 subseg_change (text_section
, 0);
3422 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3423 fragP
->fr_offset
, 0, NO_RELOC
);
3427 case TAB (FBRANCH
, SHORT
):
3428 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
3431 case TAB (FBRANCH
, LONG
):
3432 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3435 case TAB (PCREL
, SHORT
):
3438 case TAB (PCREL
, LONG
):
3439 /* The thing to do here is force it to ABSOLUTE LONG, since
3440 PCREL is really trying to shorten an ABSOLUTE address anyway */
3441 /* JF FOO This code has not been tested */
3442 subseg_change (text_section
, 0);
3443 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
3445 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3446 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
3447 (unsigned) fragP
->fr_opcode
[0],
3448 (unsigned long) fragP
->fr_address
);
3449 fragP
->fr_opcode
[1] &= ~0x3F;
3450 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
3454 case TAB (PCLEA
, SHORT
):
3455 subseg_change (text_section
, 0);
3456 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3457 fragP
->fr_offset
, 1, NO_RELOC
);
3458 fragP
->fr_opcode
[1] &= ~0x3F;
3459 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
3462 case TAB (PCLEA
, LONG
):
3463 subseg_change (text_section
, 0);
3464 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
3465 fragP
->fr_offset
, 1, NO_RELOC
);
3466 fixP
->fx_pcrel_adjust
= 2;
3467 /* Already set to mode 7.3; this indicates: PC indirect with
3468 suppressed index, 32-bit displacement. */
3469 *buffer_address
++ = 0x01;
3470 *buffer_address
++ = 0x70;
3475 case TAB (PCINDEX
, BYTE
):
3477 if (!issbyte (disp
))
3479 as_bad ("displacement doesn't fit in one byte");
3482 assert (fragP
->fr_fix
>= 2);
3483 buffer_address
[-2] &= ~1;
3484 buffer_address
[-1] = disp
;
3487 case TAB (PCINDEX
, SHORT
):
3488 subseg_change (text_section
, 0);
3490 assert (issword (disp
));
3491 assert (fragP
->fr_fix
>= 2);
3492 buffer_address
[-2] |= 0x1;
3493 buffer_address
[-1] = 0x20;
3494 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3495 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3497 fixP
->fx_pcrel_adjust
= 2;
3500 case TAB (PCINDEX
, LONG
):
3501 subseg_change (text_section
, 0);
3503 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3504 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3506 fixP
->fx_pcrel_adjust
= 2;
3507 assert (fragP
->fr_fix
>= 2);
3508 buffer_address
[-2] |= 0x1;
3509 buffer_address
[-1] = 0x30;
3516 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
3517 fragP
->fr_fix
+= ext
;
3521 #ifndef BFD_ASSEMBLER
3524 md_convert_frag (headers
, sec
, fragP
)
3525 object_headers
*headers
;
3529 md_convert_frag_1 (fragP
);
3535 md_convert_frag (abfd
, sec
, fragP
)
3540 md_convert_frag_1 (fragP
);
3544 /* Force truly undefined symbols to their maximum size, and generally set up
3545 the frag list to be relaxed
3548 md_estimate_size_before_relax (fragP
, segment
)
3549 register fragS
*fragP
;
3553 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3555 old_fix
= fragP
->fr_fix
;
3557 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3558 switch (fragP
->fr_subtype
)
3561 case TAB (ABRANCH
, SZ_UNDEF
):
3563 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3564 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3566 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
3569 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
3571 /* On 68000, or for absolute value, switch to abs long */
3572 /* FIXME, we should check abs val, pick short or long */
3573 if (fragP
->fr_opcode
[0] == 0x61)
3575 fragP
->fr_opcode
[0] = 0x4E;
3576 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3577 subseg_change (text_section
, 0);
3578 fix_new (fragP
, fragP
->fr_fix
, 4,
3579 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3583 else if (fragP
->fr_opcode
[0] == 0x60)
3585 fragP
->fr_opcode
[0] = 0x4E;
3586 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3587 subseg_change (text_section
, 0);
3588 fix_new (fragP
, fragP
->fr_fix
, 4,
3589 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3595 as_warn ("Long branch offset to extern symbol not supported.");
3599 { /* Symbol is still undefined. Make it simple */
3600 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3601 fragP
->fr_offset
, 1, NO_RELOC
);
3603 fragP
->fr_opcode
[1] = (char) 0xff;
3609 } /* case TAB(ABRANCH,SZ_UNDEF) */
3611 case TAB (FBRANCH
, SZ_UNDEF
):
3613 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
3615 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
3620 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3621 fragP
->fr_offset
, 1, NO_RELOC
);
3623 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3627 } /* TAB(FBRANCH,SZ_UNDEF) */
3629 case TAB (PCREL
, SZ_UNDEF
):
3631 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3633 || cpu_of_arch (current_architecture
) < m68020
)
3635 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
3640 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
3644 } /* TAB(PCREL,SZ_UNDEF) */
3646 case TAB (BCC68000
, SZ_UNDEF
):
3648 if ((fragP
->fr_symbol
!= NULL
)
3649 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3651 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
3654 /* only Bcc 68000 instructions can come here */
3655 /* change bcc into b!cc/jmp absl long */
3656 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3657 if (flag_short_refs
)
3659 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3660 /* JF: these were fr_opcode[2,3] */
3661 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3662 buffer_address
[1] = (char) 0xf8;
3663 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3664 subseg_change (text_section
, 0);
3665 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3666 fragP
->fr_offset
, 0, NO_RELOC
);
3671 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3672 /* JF: these were fr_opcode[2,3] */
3673 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3674 buffer_address
[1] = (char) 0xf9;
3675 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3676 subseg_change (text_section
, 0);
3677 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3678 fragP
->fr_offset
, 0, NO_RELOC
);
3683 } /* case TAB(BCC68000,SZ_UNDEF) */
3685 case TAB (DBCC
, SZ_UNDEF
):
3687 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3689 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
3693 /* only DBcc 68000 instructions can come here */
3694 /* change dbcc into dbcc/jmp absl long */
3695 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3696 buffer_address
[0] = 0x00; /* branch offset = 4 */
3697 buffer_address
[1] = 0x04;
3698 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3700 if (flag_short_refs
)
3702 /* JF: these were fr_opcode[5-7] */
3703 buffer_address
[3] = 0x04; /* plus 4 */
3704 buffer_address
[4] = 0x4e; /* Put in Jump Word */
3705 buffer_address
[5] = (char) 0xf8;
3706 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3707 subseg_change (text_section
, 0);
3708 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3709 fragP
->fr_offset
, 0, NO_RELOC
);
3714 /* JF: these were fr_opcode[5-7] */
3715 buffer_address
[3] = 0x06; /* Plus 6 */
3716 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3717 buffer_address
[5] = (char) 0xf9;
3718 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3719 subseg_change (text_section
, 0);
3720 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3721 fragP
->fr_offset
, 0, NO_RELOC
);
3727 } /* case TAB(DBCC,SZ_UNDEF) */
3729 case TAB (PCLEA
, SZ_UNDEF
):
3731 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
3733 || cpu_of_arch (current_architecture
) < m68020
)
3735 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
3740 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
3744 } /* TAB(PCLEA,SZ_UNDEF) */
3746 case TAB (PCINDEX
, SZ_UNDEF
):
3747 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3748 || cpu_of_arch (current_architecture
) < m68020
)
3750 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
3754 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
3763 /* now that SZ_UNDEF are taken care of, check others */
3764 switch (fragP
->fr_subtype
)
3766 case TAB (BCC68000
, BYTE
):
3767 case TAB (ABRANCH
, BYTE
):
3768 /* We can't do a short jump to the next instruction,
3769 so we force word mode. */
3770 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
3771 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
3773 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
3780 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3783 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3784 /* the bit-field entries in the relocation_info struct plays hell
3785 with the byte-order problems of cross-assembly. So as a hack,
3786 I added this mach. dependent ri twiddler. Ugly, but it gets
3788 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3789 are symbolnum, most sig. byte first. Last byte is broken up with
3790 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3791 nibble as nuthin. (on Sun 3 at least) */
3792 /* Translate the internal relocation information into target-specific
3796 md_ri_to_chars (the_bytes
, ri
)
3798 struct reloc_info_generic
*ri
;
3801 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
3802 /* now the fun stuff */
3803 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3804 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3805 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3806 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3807 ((ri
->r_extern
<< 4) & 0x10));
3810 #endif /* comment */
3812 #ifndef BFD_ASSEMBLER
3814 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
3817 relax_addressT segment_address_in_file
;
3820 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3821 * Out: GNU LD relocation length code: 0, 1, or 2.
3824 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
3827 know (fixP
->fx_addsy
!= NULL
);
3829 md_number_to_chars (where
,
3830 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3833 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
3834 ? S_GET_TYPE (fixP
->fx_addsy
)
3835 : fixP
->fx_addsy
->sy_number
);
3837 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3838 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3839 where
[6] = r_symbolnum
& 0x0ff;
3840 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3841 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
3845 #endif /* OBJ_AOUT or OBJ_BOUT */
3847 #ifndef WORKING_DOT_WORD
3848 CONST
int md_short_jump_size
= 4;
3849 CONST
int md_long_jump_size
= 6;
3852 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3854 addressT from_addr
, to_addr
;
3860 offset
= to_addr
- (from_addr
+ 2);
3862 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
3863 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
3867 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3869 addressT from_addr
, to_addr
;
3875 if (cpu_of_arch (current_architecture
) < m68020
)
3877 offset
= to_addr
- S_GET_VALUE (to_symbol
);
3878 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
3879 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
3880 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
3885 offset
= to_addr
- (from_addr
+ 2);
3886 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
3887 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
3893 /* Different values of OK tell what its OK to return. Things that
3894 aren't OK are an error (what a shock, no?)
3897 10: Absolute 1:8 only
3898 20: Absolute 0:7 only
3899 30: absolute 0:15 only
3900 40: Absolute 0:31 only
3901 50: absolute 0:127 only
3902 55: absolute -64:63 only
3903 60: absolute -128:127 only
3904 70: absolute 0:4095 only
3911 struct m68k_exp
*exp
;
3914 if (exp
->exp
.X_op
== O_absent
)
3916 /* Do the same thing the VAX asm does */
3917 op (exp
) = O_constant
;
3923 as_warn ("expression out of range: defaulting to 1");
3927 else if (exp
->exp
.X_op
== O_constant
)
3932 if (offs (exp
) < 1 || offs (exp
) > 8)
3934 as_warn ("expression out of range: defaulting to 1");
3939 if (offs (exp
) < 0 || offs (exp
) > 7)
3943 if (offs (exp
) < 0 || offs (exp
) > 15)
3947 if (offs (exp
) < 0 || offs (exp
) > 32)
3951 if (offs (exp
) < 0 || offs (exp
) > 127)
3955 if (offs (exp
) < -64 || offs (exp
) > 63)
3959 if (offs (exp
) < -128 || offs (exp
) > 127)
3963 if (offs (exp
) < 0 || offs (exp
) > 4095)
3966 as_warn ("expression out of range: defaulting to 0");
3974 else if (exp
->exp
.X_op
== O_big
)
3976 if (offs (exp
) <= 0 /* flonum */
3977 && (ok
== 80 /* no bignums */
3978 || (ok
> 10 /* small-int ranges including 0 ok */
3979 /* If we have a flonum zero, a zero integer should
3980 do as well (e.g., in moveq). */
3981 && generic_floating_point_number
.exponent
== 0
3982 && generic_floating_point_number
.low
[0] == 0)))
3984 /* HACK! Turn it into a long */
3985 LITTLENUM_TYPE words
[6];
3987 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
3988 op (exp
) = O_constant
;
3991 offs (exp
) = words
[1] | (words
[0] << 16);
3995 op (exp
) = O_constant
;
3998 offs (exp
) = (ok
== 10) ? 1 : 0;
3999 as_warn ("Can't deal with expression; defaulting to %ld",
4005 if (ok
>= 10 && ok
<= 70)
4007 op (exp
) = O_constant
;
4010 offs (exp
) = (ok
== 10) ? 1 : 0;
4011 as_warn ("Can't deal with expression; defaulting to %ld",
4016 if (exp
->size
!= SIZE_UNSPEC
)
4024 if (!isbyte (offs (exp
)))
4025 as_warn ("expression doesn't fit in BYTE");
4028 if (!isword (offs (exp
)))
4029 as_warn ("expression doesn't fit in WORD");
4037 /* These are the back-ends for the various machine dependent pseudo-ops. */
4038 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4044 subseg_set (data_section
, 1);
4045 demand_empty_rest_of_line ();
4052 subseg_set (data_section
, 2);
4053 demand_empty_rest_of_line ();
4060 /* We don't support putting frags in the BSS segment, we fake it
4061 by marking in_bss, then looking at s_skip for clues. */
4063 subseg_set (bss_section
, 0);
4064 demand_empty_rest_of_line ();
4072 register long temp_fill
;
4074 temp
= 1; /* JF should be 2? */
4075 temp_fill
= get_absolute_expression ();
4076 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4077 frag_align (temp
, (int) temp_fill
);
4078 demand_empty_rest_of_line ();
4085 demand_empty_rest_of_line ();
4088 /* Pseudo-ops handled for MRI compatibility. */
4090 /* Handle an MRI style chip specification. */
4099 s
= input_line_pointer
;
4100 c
= get_symbol_end ();
4101 for (i
= 0; i
< n_archs
; i
++)
4102 if (strcasecmp (s
, archs
[i
].name
) == 0)
4106 as_bad ("%s: unrecognized processor name", s
);
4107 *input_line_pointer
= c
;
4108 ignore_rest_of_line ();
4111 *input_line_pointer
= c
;
4113 if (*input_line_pointer
== '/')
4114 current_architecture
= 0;
4116 current_architecture
&= m68881
| m68851
;
4117 current_architecture
|= archs
[i
].arch
;
4119 while (*input_line_pointer
== '/')
4121 ++input_line_pointer
;
4122 s
= input_line_pointer
;
4123 c
= get_symbol_end ();
4124 if (strcmp (s
, "68881") == 0)
4125 current_architecture
|= m68881
;
4126 else if (strcmp (s
, "68851") == 0)
4127 current_architecture
|= m68851
;
4128 *input_line_pointer
= c
;
4132 /* The MRI CHIP pseudo-op. */
4139 demand_empty_rest_of_line ();
4142 /* The MRI FOPT pseudo-op. */
4150 if (strncasecmp (input_line_pointer
, "ID=", 3) == 0)
4154 input_line_pointer
+= 3;
4155 temp
= get_absolute_expression ();
4156 if (temp
< 0 || temp
> 7)
4157 as_bad ("bad coprocessor id");
4159 m68k_float_copnum
= COP0
+ temp
;
4163 as_bad ("unrecognized fopt option");
4164 ignore_rest_of_line ();
4168 demand_empty_rest_of_line ();
4171 /* The structure used to handle the MRI OPT pseudo-op. */
4175 /* The name of the option. */
4178 /* If this is not NULL, just call this function. The first argument
4179 is the ARG field of this structure, the second argument is
4180 whether the option was negated. */
4181 void (*pfn
) PARAMS ((int arg
, int on
));
4183 /* If this is not NULL, and the PFN field is NULL, set the variable
4184 this points to. Set it to the ARG field if the option was not
4185 negated, and the NOTARG field otherwise. */
4188 /* The value to pass to PFN or to assign to *PVAR. */
4191 /* The value to assign to *PVAR if the option is negated. If PFN is
4192 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4193 the option may not be negated. */
4197 /* The table used to handle the MRI OPT pseudo-op. */
4199 static void skip_to_comma
PARAMS ((int, int));
4200 static void opt_chip
PARAMS ((int, int));
4201 static void opt_list
PARAMS ((int, int));
4202 static void opt_list_symbols
PARAMS ((int, int));
4204 static const struct opt_action opt_table
[] =
4206 { "abspcadd", 0, &m68k_abspcadd
, 1, 0 },
4208 /* We do relaxing, so there is little use for these options. */
4209 { "b", 0, 0, 0, 0 },
4210 { "brs", 0, 0, 0, 0 },
4211 { "brb", 0, 0, 0, 0 },
4212 { "brl", 0, 0, 0, 0 },
4213 { "brw", 0, 0, 0, 0 },
4215 { "c", 0, 0, 0, 0 },
4216 { "cex", 0, 0, 0, 0 },
4217 { "case", 0, &symbols_case_sensitive
, 1, 0 },
4218 { "cl", 0, 0, 0, 0 },
4219 { "cre", 0, 0, 0, 0 },
4220 { "d", 0, &flag_keep_locals
, 1, 0 },
4221 { "e", 0, 0, 0, 0 },
4222 { "f", 0, &flag_short_refs
, 1, 0 },
4223 { "frs", 0, &flag_short_refs
, 1, 0 },
4224 { "frl", 0, &flag_short_refs
, 0, 1 },
4225 { "g", 0, 0, 0, 0 },
4226 { "i", 0, 0, 0, 0 },
4227 { "m", 0, 0, 0, 0 },
4228 { "mex", 0, 0, 0, 0 },
4229 { "mc", 0, 0, 0, 0 },
4230 { "md", 0, 0, 0, 0 },
4231 { "next", skip_to_comma
, 0, 0, 0 },
4232 { "o", 0, 0, 0, 0 },
4233 { "old", 0, 0, 0, 0 },
4234 { "op", skip_to_comma
, 0, 0, 0 },
4235 { "pco", 0, 0, 0, 0 },
4236 { "p", opt_chip
, 0, 0, 0 },
4237 { "pcr", 0, 0, 0, 0 },
4238 { "pcs", 0, 0, 0, 0 },
4239 { "r", 0, 0, 0, 0 },
4240 { "quick", 0, &m68k_quick
, 1, 0 },
4241 { "rel32", 0, &m68k_rel32
, 1, 0 },
4242 { "s", opt_list
, 0, 0, 0 },
4243 { "t", opt_list_symbols
, 0, 0, 0 },
4244 { "w", 0, &flag_no_warnings
, 0, 1 },
4248 #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4250 /* The MRI OPT pseudo-op. */
4262 const struct opt_action
*o
;
4267 if (*input_line_pointer
== '-')
4269 ++input_line_pointer
;
4272 else if (strncasecmp (input_line_pointer
, "NO", 2) == 0)
4274 input_line_pointer
+= 2;
4278 s
= input_line_pointer
;
4279 c
= get_symbol_end ();
4281 for (i
= 0, o
= opt_table
; i
< OPTCOUNT
; i
++, o
++)
4283 if (strcasecmp (s
, o
->name
) == 0)
4287 /* Restore input_line_pointer now in case the option
4289 *input_line_pointer
= c
;
4290 (*o
->pfn
) (o
->arg
, t
);
4292 else if (o
->pvar
!= NULL
)
4294 if (! t
&& o
->arg
== o
->notarg
)
4295 as_bad ("option `%s' may not be negated", s
);
4296 *input_line_pointer
= c
;
4297 *o
->pvar
= t
? o
->arg
: o
->notarg
;
4304 as_bad ("option `%s' not recognized", s
);
4305 *input_line_pointer
= c
;
4308 while (*input_line_pointer
++ == ',');
4310 /* Move back to terminating character. */
4311 --input_line_pointer
;
4312 demand_empty_rest_of_line ();
4315 /* Skip ahead to a comma. This is used for OPT options which we do
4316 not suppor tand which take arguments. */
4319 skip_to_comma (arg
, on
)
4323 while (*input_line_pointer
!= ','
4324 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4325 ++input_line_pointer
;
4328 /* Handle the OPT P=chip option. */
4335 if (*input_line_pointer
!= '=')
4337 /* This is just OPT P, which we do not support. */
4341 ++input_line_pointer
;
4345 /* Handle the OPT S option. */
4355 /* Handle the OPT T option. */
4358 opt_list_symbols (arg
, on
)
4363 listing
|= LISTING_SYMBOLS
;
4365 listing
&=~ LISTING_SYMBOLS
;
4368 /* Handle the MRI REG pseudo-op. */
4379 if (mri_line_label
== NULL
)
4381 as_bad ("missing label");
4382 ignore_rest_of_line ();
4388 s
= input_line_pointer
;
4389 while (isalnum ((unsigned char) *input_line_pointer
)
4390 #ifdef REGISTER_PREFIX
4391 || *input_line_pointer
== REGISTER_PREFIX
4393 || *input_line_pointer
== '/'
4394 || *input_line_pointer
== '-')
4395 ++input_line_pointer
;
4396 c
= *input_line_pointer
;
4397 *input_line_pointer
= '\0';
4399 if (m68k_ip_op (s
, &op
) != 0)
4401 if (op
.error
== NULL
)
4402 as_bad ("bad register list");
4404 as_bad ("bad register list: %s", op
.error
);
4405 *input_line_pointer
= c
;
4406 ignore_rest_of_line ();
4410 *input_line_pointer
= c
;
4412 if (op
.mode
== REGLST
)
4414 else if (op
.mode
== DREG
)
4415 mask
= 1 << (op
.reg
- DATA0
);
4416 else if (op
.mode
== AREG
)
4417 mask
= 1 << (op
.reg
- ADDR0
+ 8);
4418 else if (op
.mode
== FPREG
)
4419 mask
= 1 << (op
.reg
- FP0
+ 16);
4420 else if (op
.mode
== CONTROL
4423 else if (op
.mode
== CONTROL
4426 else if (op
.mode
== CONTROL
4431 as_bad ("bad register list");
4432 ignore_rest_of_line ();
4436 S_SET_SEGMENT (mri_line_label
, absolute_section
);
4437 S_SET_VALUE (mri_line_label
, mask
);
4438 mri_line_label
->sy_frag
= &zero_address_frag
;
4440 demand_empty_rest_of_line ();
4443 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
4447 struct save_opts
*next
;
4449 int symbols_case_sensitive
;
4457 /* FIXME: We don't save OPT S. */
4460 /* This variable holds the stack of saved options. */
4462 static struct save_opts
*save_stack
;
4464 /* The MRI SAVE pseudo-op. */
4470 struct save_opts
*s
;
4472 s
= (struct save_opts
*) xmalloc (sizeof (struct save_opts
));
4473 s
->abspcadd
= m68k_abspcadd
;
4474 s
->symbols_case_sensitive
= symbols_case_sensitive
;
4475 s
->keep_locals
= flag_keep_locals
;
4476 s
->short_refs
= flag_short_refs
;
4477 s
->architecture
= current_architecture
;
4478 s
->quick
= m68k_quick
;
4479 s
->rel32
= m68k_rel32
;
4480 s
->listing
= listing
;
4481 s
->no_warnings
= flag_no_warnings
;
4483 s
->next
= save_stack
;
4486 demand_empty_rest_of_line ();
4489 /* The MRI RESTORE pseudo-op. */
4495 struct save_opts
*s
;
4497 if (save_stack
== NULL
)
4499 as_bad ("restore without save");
4500 ignore_rest_of_line ();
4505 save_stack
= s
->next
;
4507 m68k_abspcadd
= s
->abspcadd
;
4508 symbols_case_sensitive
= s
->symbols_case_sensitive
;
4509 flag_keep_locals
= s
->keep_locals
;
4510 flag_short_refs
= s
->short_refs
;
4511 current_architecture
= s
->architecture
;
4512 m68k_quick
= s
->quick
;
4513 m68k_rel32
= s
->rel32
;
4514 listing
= s
->listing
;
4515 flag_no_warnings
= s
->no_warnings
;
4519 demand_empty_rest_of_line ();
4524 * Invocation line includes a switch not recognized by the base assembler.
4525 * See if it's a processor-specific option. These are:
4527 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4528 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4529 * Select the architecture. Instructions or features not
4530 * supported by the selected architecture cause fatal
4531 * errors. More than one may be specified. The default is
4532 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4533 * for -m68000, and -m68882 is a synonym for -m68881.
4534 * -[A]m[c]no-68851, -[A]m[c]no-68881
4535 * Don't accept 688?1 instructions. (The "c" is kind of silly,
4536 * so don't use or document it, but that's the way the parsing
4539 * -pic Indicates PIC.
4540 * -k Indicates PIC. (Sun 3 only.)
4545 CONST
char *md_shortopts
= "lSA:m:kQ:V";
4547 CONST
char *md_shortopts
= "lSA:m:k";
4550 struct option md_longopts
[] = {
4551 #define OPTION_PIC (OPTION_MD_BASE)
4552 {"pic", no_argument
, NULL
, OPTION_PIC
},
4553 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
4554 {"register-prefix-optional", no_argument
, NULL
,
4555 OPTION_REGISTER_PREFIX_OPTIONAL
},
4556 {NULL
, no_argument
, NULL
, 0}
4558 size_t md_longopts_size
= sizeof(md_longopts
);
4561 md_parse_option (c
, arg
)
4567 case 'l': /* -l means keep external to 2 bit offset
4568 rather than 16 bit one */
4569 flag_short_refs
= 1;
4572 case 'S': /* -S means that jbsr's always turn into
4574 flag_long_jumps
= 1;
4580 /* intentional fall-through */
4583 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
4587 const char *oarg
= arg
;
4593 if (arg
[0] == 'c' && arg
[1] == '6')
4596 for (i
= 0; i
< n_archs
; i
++)
4597 if (!strcmp (arg
, archs
[i
].name
))
4602 as_bad ("unrecognized option `%s'", oarg
);
4605 arch
= archs
[i
].arch
;
4608 else if (arch
== m68851
)
4617 if (arg
[0] == 'c' && arg
[1] == '6')
4620 for (i
= 0; i
< n_archs
; i
++)
4621 if (!strcmp (arg
, archs
[i
].name
))
4623 unsigned long arch
= archs
[i
].arch
;
4624 if (cpu_of_arch (arch
))
4625 /* It's a cpu spec. */
4627 current_architecture
&= ~m68000up
;
4628 current_architecture
|= arch
;
4630 else if (arch
== m68881
)
4632 current_architecture
|= m68881
;
4635 else if (arch
== m68851
)
4637 current_architecture
|= m68851
;
4647 as_bad ("unrecognized architecture specification `%s'", arg
);
4656 break; /* -pic, Position Independent Code */
4658 case OPTION_REGISTER_PREFIX_OPTIONAL
:
4659 flag_reg_prefix_optional
= 1;
4674 md_show_usage (stream
)
4679 -l use 1 word for refs to undefined symbols [default 2]\n\
4680 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
4681 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
4683 specify variant of 680X0 architecture [default 68020]\n\
4684 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
4685 target has/lacks floating-point coprocessor\n\
4686 [default yes for 68020, 68030, and cpu32]\n\
4687 -m68851 | -mno-68851\n\
4688 target has/lacks memory-management unit coprocessor\n\
4689 [default yes for 68020 and up]\n\
4690 -pic, -k generate position independent code\n\
4691 -S turn jbsr into jsr\n\
4692 --register-prefix-optional\n\
4693 recognize register names without prefix character\n");
4698 /* TEST2: Test md_assemble() */
4699 /* Warning, this routine probably doesn't work anymore */
4703 struct m68k_it the_ins
;
4711 if (!gets (buf
) || !*buf
)
4713 if (buf
[0] == '|' || buf
[1] == '.')
4715 for (cp
= buf
; *cp
; cp
++)
4720 memset (&the_ins
, '\0', sizeof (the_ins
));
4721 m68k_ip (&the_ins
, buf
);
4724 printf ("Error %s in %s\n", the_ins
.error
, buf
);
4728 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
4729 for (n
= 0; n
< the_ins
.numo
; n
++)
4730 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
4732 print_the_insn (&the_ins
.opcode
[0], stdout
);
4733 (void) putchar ('\n');
4735 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
4737 if (the_ins
.operands
[n
].error
)
4739 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
4742 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
4743 if (the_ins
.operands
[n
].b_const
)
4744 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
4745 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
4746 if (the_ins
.operands
[n
].b_iadd
)
4747 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
4748 (void) putchar ('\n');
4760 while (*str
&& *str
!= ' ')
4762 if (str
[-1] == ':' || str
[1] == '=')
4769 /* Possible states for relaxation:
4771 0 0 branch offset byte (bra, etc)
4775 1 0 indexed offsets byte a0@(32,d4:w:1) etc
4779 2 0 two-offset index word-word a0@(32,d4)@(45) etc
4786 /* We have no need to default values of symbols. */
4790 md_undefined_symbol (name
)
4796 /* Round up a section size to the appropriate boundary. */
4798 md_section_align (segment
, size
)
4802 return size
; /* Byte alignment is fine */
4805 /* Exactly what point is a PC-relative offset relative TO?
4806 On the 68k, it is relative to the address of the first extension
4807 word. The difference between the addresses of the offset and the
4808 first extension word is stored in fx_pcrel_adjust. */
4810 md_pcrel_from (fixP
)
4813 return (fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- fixP
->fx_pcrel_adjust
);
4816 #ifndef BFD_ASSEMBLER
4819 tc_coff_symbol_emit_hook (ignore
)
4825 tc_coff_sizemachdep (frag
)
4828 switch (frag
->fr_subtype
& 0x3)
4843 /* end of tc-m68k.c */