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 /* Its an arbitrary name: This means I don't approve of it */
77 /* See flames below */
78 static struct obstack robyn
;
80 #define TAB(x,y) (((x)<<2)+(y))
81 #define TABTYPE(xy) ((xy) >> 2)
87 /* Case `g' except when BCC68000 is applicable. */
89 /* Coprocessor branches. */
91 /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
92 supported on all cpus. Widens to 32-bit absolute. */
94 /* For inserting an extra jmp instruction with long offset on 68000,
95 for expanding conditional branches. (Not bsr or bra.) Since the
96 68000 doesn't support 32-bit displacements for conditional
97 branches, we fake it by reversing the condition and branching
98 around a jmp with an absolute long operand. */
100 /* For the DBcc "instructions". If the displacement requires 32 bits,
101 the branch-around-a-jump game is played here too. */
103 /* Not currently used? */
105 /* Mode AINDX (apc-relative) using PC, with variable target, might fit
111 const char *m_operands
;
112 unsigned long m_opcode
;
116 struct m68k_incant
*m_next
;
119 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
120 #define gettwo(x) (((x)->m_opcode)&0xffff)
122 static const enum m68k_register m68000_control_regs
[] = { 0 };
123 static const enum m68k_register m68010_control_regs
[] = {
127 static const enum m68k_register m68020_control_regs
[] = {
128 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
131 static const enum m68k_register m68040_control_regs
[] = {
132 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
133 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
136 static const enum m68k_register m68060_control_regs
[] = {
137 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
138 USP
, VBR
, URP
, SRP
, PCR
,
141 #define cpu32_control_regs m68010_control_regs
143 static const enum m68k_register
*control_regs
;
145 /* internal form of a 68020 instruction */
149 const char *args
; /* list of opcode info */
152 int numo
; /* Number of shorts in opcode */
155 struct m68k_op operands
[6];
157 int nexp
; /* number of exprs in use */
158 struct m68k_exp exprs
[4];
160 int nfrag
; /* Number of frags we have to produce */
163 int fragoff
; /* Where in the current opcode the frag ends */
170 int nrel
; /* Num of reloc strucs in use */
177 /* In a pc relative address the difference between the address
178 of the offset and the address that the offset is relative
179 to. This depends on the addressing mode. Basically this
180 is the value to put in the offset field to address the
181 first byte of the offset, without regarding the special
182 significance of some values (in the branch instruction, for
186 reloc
[5]; /* Five is enough??? */
189 #define cpu_of_arch(x) ((x) & m68000up)
190 #define float_of_arch(x) ((x) & mfloat)
191 #define mmu_of_arch(x) ((x) & mmmu)
193 static struct m68k_it the_ins
; /* the instruction being assembled */
195 #define op(ex) ((ex)->exp.X_op)
196 #define adds(ex) ((ex)->exp.X_add_symbol)
197 #define subs(ex) ((ex)->exp.X_op_symbol)
198 #define offs(ex) ((ex)->exp.X_add_number)
200 /* Macros for adding things to the m68k_it struct */
202 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
204 /* Like addword, but goes BEFORE general operands */
208 struct m68k_incant
*opcode
;
211 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
212 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
213 for(z
=0;z
<the_ins
.nrel
;z
++)
214 the_ins
.reloc
[z
].n
+=2;
215 for (z
= 0; z
< the_ins
.nfrag
; z
++)
216 the_ins
.fragb
[z
].fragoff
++;
217 the_ins
.opcode
[opcode
->m_codenum
]=w
;
221 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
224 add_fix (width
, exp
, pc_rel
, pc_fix
)
226 struct m68k_exp
*exp
;
230 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
234 : (the_ins
.numo
*2)));
235 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->exp
;
236 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
237 the_ins
.reloc
[the_ins
.nrel
].pcrel_fix
= pc_fix
;
238 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
241 /* Cause an extra frag to be generated here, inserting up to 10 bytes
242 (that value is chosen in the frag_var call in md_assemble). TYPE
243 is the subtype of the frag to be generated; its primary type is
244 rs_machine_dependent.
246 The TYPE parameter is also used by md_convert_frag_1 and
247 md_estimate_size_before_relax. The appropriate type of fixup will
248 be emitted by md_convert_frag_1.
250 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
252 add_frag(add
,off
,type
)
257 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
258 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
259 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
260 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
264 (op (ex) != O_constant && op (ex) != O_big)
266 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
267 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
268 static int reverse_16_bits
PARAMS ((int in
));
269 static int reverse_8_bits
PARAMS ((int in
));
270 static void install_gen_operand
PARAMS ((int mode
, int val
));
271 static void install_operand
PARAMS ((int mode
, int val
));
272 static void s_bss
PARAMS ((int));
273 static void s_data1
PARAMS ((int));
274 static void s_data2
PARAMS ((int));
275 static void s_even
PARAMS ((int));
276 static void s_proc
PARAMS ((int));
278 static int current_architecture
;
285 static const struct m68k_cpu archs
[] = {
295 /* Aliases (effectively, so far as gas is concerned) for the above
308 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
310 /* BCC68000 is for patching in an extra jmp instruction for long offsets
311 on the 68000. The 68000 doesn't support long branches with branchs */
313 /* This table desribes how you change sizes for the various types of variable
314 size expressions. This version only supports two kinds. */
316 /* Note that calls to frag_var need to specify the maximum expansion
317 needed; this is currently 10 bytes for DBCC. */
320 How far Forward this mode will reach:
321 How far Backward this mode will reach:
322 How many bytes this mode will add to the size of the frag
323 Which mode to go to if the offset won't fit in this one
325 relax_typeS md_relax_table
[] =
327 {1, 1, 0, 0}, /* First entries aren't used */
328 {1, 1, 0, 0}, /* For no good reason except */
329 {1, 1, 0, 0}, /* that the VAX doesn't either */
332 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
333 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
337 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
338 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
342 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
343 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
347 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
348 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
349 {0, 0, 6, 0}, /* jmp long space */
352 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
353 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
354 {0, 0, 10, 0}, /* bra/jmp long space */
357 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
358 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
362 /* For, e.g., jmp pcrel indexed. */
363 {125, -130, 0, TAB (PCINDEX
, SHORT
)},
364 {32765, -32770, 2, TAB (PCINDEX
, LONG
)},
369 /* These are the machine dependent pseudo-ops. These are included so
370 the assembler can work on the output from the SUN C compiler, which
374 /* This table describes all the machine specific pseudo-ops the assembler
375 has to support. The fields are:
376 pseudo-op name without dot
377 function to call to execute this pseudo-op
378 Integer arg to pass to the function
380 CONST pseudo_typeS md_pseudo_table
[] =
382 {"data1", s_data1
, 0},
383 {"data2", s_data2
, 0},
386 {"skip", s_space
, 0},
389 {"align", s_align_bytes
, 0},
392 {"swbeg", s_ignore
, 0},
398 /* The mote pseudo ops are put into the opcode table, since they
399 don't start with a . they look like opcodes to gas.
401 extern void obj_coff_section ();
403 CONST pseudo_typeS mote_pseudo_table
[] =
416 {"xdef", s_globl
, 0},
417 {"align", s_align_ptwo
, 0},
419 {"sect", obj_coff_section
, 0},
420 {"section", obj_coff_section
, 0},
425 #define issbyte(x) ((x)>=-128 && (x)<=127)
426 #define isubyte(x) ((x)>=0 && (x)<=255)
427 #define issword(x) ((x)>=-32768 && (x)<=32767)
428 #define isuword(x) ((x)>=0 && (x)<=65535)
430 #define isbyte(x) ((x)>= -255 && (x)<=255)
431 #define isword(x) ((x)>=-32768 && (x)<=65535)
432 #define islong(x) (1)
434 extern char *input_line_pointer
;
436 static char mklower_table
[256];
437 #define mklower(c) (mklower_table[(unsigned char)(c)])
438 static char notend_table
[256];
439 static char alt_notend_table
[256];
441 (! (notend_table[(unsigned char) *s] \
443 && alt_notend_table[(unsigned char) s[1]])))
445 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
447 #ifdef NO_PCREL_RELOCS
450 make_pcrel_absolute(fixP
, add_number
)
454 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
456 /* rewrite the PC relative instructions to absolute address ones.
457 * these are rumoured to be faster, and the apollo linker refuses
458 * to deal with the PC relative relocations.
460 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
465 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
471 as_fatal ("Unknown PC relative instruction");
476 #endif /* NO_PCREL_RELOCS */
479 tc_coff_fix2rtype (fixP
)
482 #ifdef NO_PCREL_RELOCS
483 know (fixP
->fx_pcrel
== 0);
484 return (fixP
->fx_size
== 1 ? R_RELBYTE
485 : fixP
->fx_size
== 2 ? R_DIR16
488 return (fixP
->fx_pcrel
?
489 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
490 fixP
->fx_size
== 2 ? R_PCRWORD
:
492 (fixP
->fx_size
== 1 ? R_RELBYTE
:
493 fixP
->fx_size
== 2 ? R_RELWORD
:
503 tc_gen_reloc (section
, fixp
)
508 bfd_reloc_code_real_type code
;
510 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
511 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
513 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
514 MAP (1, 0, BFD_RELOC_8
);
515 MAP (2, 0, BFD_RELOC_16
);
516 MAP (4, 0, BFD_RELOC_32
);
517 MAP (1, 1, BFD_RELOC_8_PCREL
);
518 MAP (2, 1, BFD_RELOC_16_PCREL
);
519 MAP (4, 1, BFD_RELOC_32_PCREL
);
524 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
526 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
527 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
529 reloc
->addend
= fixp
->fx_addnumber
;
533 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
534 assert (reloc
->howto
!= 0);
539 #endif /* BFD_ASSEMBLER */
541 /* Handle of the OPCODE hash table. NULL means any use before
542 m68k_ip_begin() will crash. */
543 static struct hash_control
*op_hash
;
545 /* Assemble an m68k instruction. */
552 register struct m68k_op
*opP
;
553 register struct m68k_incant
*opcode
;
554 register const char *s
;
555 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
556 char *pdot
, *pdotmove
;
557 enum m68k_size siz1
, siz2
;
561 char *crack_operand ();
562 LITTLENUM_TYPE words
[6];
563 LITTLENUM_TYPE
*wordp
;
564 unsigned long ok_arch
= 0;
566 if (*instring
== ' ')
567 instring
++; /* skip leading whitespace */
569 /* Scan up to end of operation-code, which MUST end in end-of-string
570 or exactly 1 space. */
572 for (p
= instring
; *p
!= '\0'; p
++)
582 the_ins
.error
= "No operator";
586 /* p now points to the end of the opcode name, probably whitespace.
587 Make sure the name is null terminated by clobbering the
588 whitespace, look it up in the hash table, then fix it back.
589 Remove a dot, first, since the opcode tables have none. */
592 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
593 *pdotmove
= pdotmove
[1];
599 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
604 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
605 *pdotmove
= pdotmove
[-1];
612 the_ins
.error
= "Unknown operator";
616 /* found a legitimate opcode, start matching operands */
620 if (opcode
->m_operands
== 0)
622 char *old
= input_line_pointer
;
624 input_line_pointer
= p
;
625 /* Ahh - it's a motorola style psuedo op */
626 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
627 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
628 input_line_pointer
= old
;
634 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
636 p
= crack_operand (p
, opP
);
640 the_ins
.error
= opP
->error
;
645 opsfound
= opP
- &the_ins
.operands
[0];
647 /* This ugly hack is to support the floating pt opcodes in their
648 standard form. Essentially, we fake a first enty of type COP#1 */
649 if (opcode
->m_operands
[0] == 'I')
653 for (n
= opsfound
; n
> 0; --n
)
654 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
656 memset ((char *) (&the_ins
.operands
[0]), '\0',
657 sizeof (the_ins
.operands
[0]));
658 the_ins
.operands
[0].mode
= CONTROL
;
659 the_ins
.operands
[0].reg
= COPNUM
; /* COP #1 */
663 /* We've got the operands. Find an opcode that'll accept them */
666 /* If we didn't get the right number of ops, or we have no
667 common model with this pattern then reject this pattern. */
669 if (opsfound
!= opcode
->m_opnum
670 || ((opcode
->m_arch
& current_architecture
) == 0))
673 ok_arch
|= opcode
->m_arch
;
677 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0];
681 /* Warning: this switch is huge! */
682 /* I've tried to organize the cases into this order:
683 non-alpha first, then alpha by letter. Lower-case
684 goes directly before uppercase counterpart. */
685 /* Code with multiple case ...: gets sorted by the lowest
686 case ... it belongs to. I hope this makes sense. */
726 if (opP
->mode
!= IMMED
)
729 && ! isvar (&opP
->disp
)
730 && ! expr8 (&opP
->disp
))
733 && ! isvar (&opP
->disp
)
734 && ! expr16 (&opP
->disp
))
740 if (opP
->mode
!= IMMED
)
745 if (opP
->mode
== AREG
746 || opP
->mode
== CONTROL
747 || opP
->mode
== FPREG
748 || opP
->mode
== IMMED
749 || opP
->mode
== REGLST
750 || (opP
->mode
!= ABSL
752 || opP
->reg
== ZPC
)))
757 if (opP
->mode
== CONTROL
758 || opP
->mode
== FPREG
759 || opP
->mode
== REGLST
760 || (opP
->mode
!= ABSL
761 && opP
->mode
!= IMMED
763 || opP
->reg
== ZPC
)))
791 if (opP
->mode
== CONTROL
792 || opP
->mode
== FPREG
793 || opP
->mode
== REGLST
)
798 if (opP
->mode
!= AINC
)
803 if (opP
->mode
!= ADEC
)
853 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
874 case '~': /* For now! (JF FOO is this right?) */
896 if (opP
->mode
!= CONTROL
897 || (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
902 if (opP
->mode
!= AREG
)
907 if (opP
->mode
!= AINDR
)
912 if (opP
->mode
!= ABSL
914 && strncmp (instring
, "jbsr", 4) == 0))
919 if (opP
->mode
!= CONTROL
|| opP
->reg
!= CCR
)
924 if (opP
->mode
!= DISP
931 if (opP
->mode
!= DREG
)
936 if (opP
->mode
!= FPREG
)
941 if (opP
->mode
!= CONTROL
943 || opP
->reg
>= COPNUM
+ 7)
948 if (opP
->mode
!= CONTROL
950 || opP
->reg
> last_movec_reg
)
954 const enum m68k_register
*rp
;
955 for (rp
= control_regs
; *rp
; rp
++)
964 if (opP
->mode
!= IMMED
)
970 if (opP
->mode
== DREG
972 || opP
->mode
== FPREG
)
981 opP
->mask
= 1 << (opP
->reg
- DATA0
);
984 opP
->mask
= 1 << (opP
->reg
- ADDR0
+ 8);
987 opP
->mask
= 1 << (opP
->reg
- FP0
+ 16);
995 else if (opP
->mode
== CONTROL
)
1004 opP
->mask
= 1 << 24;
1007 opP
->mask
= 1 << 25;
1010 opP
->mask
= 1 << 26;
1019 else if (opP
->mode
!= REGLST
)
1021 else if (s
[1] == '8' && (opP
->mask
& 0x0ffffff) != 0)
1023 else if (s
[1] == '3' && (opP
->mask
& 0x7000000) != 0)
1028 if (opP
->mode
!= IMMED
)
1030 else if (! expr8 (&opP
->disp
))
1035 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1040 if (opP
->mode
!= IMMED
)
1042 else if (! expr8 (&opP
->disp
)
1043 || opP
->disp
.exp
.X_add_number
< 1
1044 || opP
->disp
.exp
.X_add_number
> 8)
1049 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1054 if (opP
->mode
!= AINDR
1055 && (opP
->mode
!= BASE
1057 && opP
->reg
!= ZADDR0
)
1058 || opP
->disp
.exp
.X_op
!= O_absent
1059 || ((opP
->index
.reg
< DATA0
1060 || opP
->index
.reg
> DATA7
)
1061 && (opP
->index
.reg
< ADDR0
1062 || opP
->index
.reg
> ADDR7
))
1063 || opP
->index
.size
!= SIZE_UNSPEC
1064 || opP
->index
.scale
!= 1))
1069 if (opP
->mode
!= CONTROL
1070 || ! (opP
->reg
== FPI
1072 || opP
->reg
== FPC
))
1077 if (opP
->mode
!= CONTROL
|| opP
->reg
!= SR
)
1082 if (opP
->mode
!= IMMED
)
1084 else if (! expr8 (&opP
->disp
)
1085 || opP
->disp
.exp
.X_add_number
< 0
1086 || opP
->disp
.exp
.X_add_number
> 7)
1091 if (opP
->mode
!= CONTROL
|| opP
->reg
!= USP
)
1095 /* JF these are out of order. We could put them
1096 in order if we were willing to put up with
1097 bunches of #ifdef m68851s in the code.
1099 Don't forget that you need these operands
1100 to use 68030 MMU instructions. */
1102 /* Memory addressing mode used by pflushr */
1104 if (opP
->mode
== CONTROL
1105 || opP
->mode
== FPREG
1106 || opP
->mode
== DREG
1107 || opP
->mode
== AREG
1108 || opP
->mode
== REGLST
)
1113 if (opP
->mode
!= CONTROL
1114 || (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1119 if (opP
->mode
!= CONTROL
1129 if (opP
->mode
!= CONTROL
1135 if (opP
->mode
!= CONTROL
1138 && opP
->reg
!= CRP
))
1143 if (opP
->mode
!= CONTROL
1144 || (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7)
1145 && !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1150 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PSR
)
1155 if (opP
->mode
!= CONTROL
|| opP
->reg
!= PCSR
)
1160 if (opP
->mode
!= CONTROL
1167 } /* not a cache specifier. */
1171 if (opP
->mode
!= ABSL
)
1177 } /* switch on type of operand */
1181 } /* for each operand */
1182 } /* if immediately wrong */
1189 opcode
= opcode
->m_next
;
1194 && !(ok_arch
& current_architecture
))
1199 "invalid instruction for this architecture; needs ");
1200 cp
= buf
+ strlen (buf
);
1204 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
1207 strcpy (cp
, "mmu (68030 or 68851)");
1210 strcpy (cp
, "68020 or higher");
1213 strcpy (cp
, "68000 or higher");
1216 strcpy (cp
, "68010 or higher");
1220 int got_one
= 0, idx
;
1221 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]);
1224 if (archs
[idx
].arch
& ok_arch
)
1228 strcpy (cp
, " or ");
1232 strcpy (cp
, archs
[idx
].name
);
1244 the_ins
.error
= "operands mismatch";
1246 } /* Fell off the end */
1251 /* now assemble it */
1253 the_ins
.args
= opcode
->m_operands
;
1254 the_ins
.numargs
= opcode
->m_opnum
;
1255 the_ins
.numo
= opcode
->m_codenum
;
1256 the_ins
.opcode
[0] = getone (opcode
);
1257 the_ins
.opcode
[1] = gettwo (opcode
);
1259 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
1261 /* This switch is a doozy.
1262 Watch the first step; its a big one! */
1283 tmpreg
= 0x3c; /* 7.4 */
1284 if (strchr ("bwl", s
[1]))
1285 nextword
= get_num (&opP
->disp
, 80);
1287 nextword
= get_num (&opP
->disp
, 0);
1288 if (isvar (&opP
->disp
))
1289 add_fix (s
[1], &opP
->disp
, 0, 0);
1293 if (!isbyte (nextword
))
1294 opP
->error
= "operand out of range";
1299 if (!isword (nextword
))
1300 opP
->error
= "operand out of range";
1305 addword (nextword
>> 16);
1332 /* We gotta put out some float */
1333 if (op (&opP
->disp
) != O_big
)
1338 /* Can other cases happen here? */
1339 if (op (&opP
->disp
) != O_constant
)
1342 val
= (valueT
) offs (&opP
->disp
);
1346 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
1347 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1351 offs (&opP
->disp
) = gencnt
;
1353 if (offs (&opP
->disp
) > 0)
1355 if (offs (&opP
->disp
) > baseo
)
1357 as_warn ("Bignum too big for %c format; truncated",
1359 offs (&opP
->disp
) = baseo
;
1361 baseo
-= offs (&opP
->disp
);
1364 for (wordp
= generic_bignum
+ offs (&opP
->disp
) - 1;
1365 offs (&opP
->disp
)--;
1370 gen_to_words (words
, baseo
, (long) outro
);
1371 for (wordp
= words
; baseo
--; wordp
++)
1375 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
1378 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
1381 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
1384 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
1387 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
1391 nextword
= get_num (&opP
->disp
, 80);
1392 /* Force into index mode. Hope this works */
1394 /* We do the first bit for 32-bit displacements, and the
1395 second bit for 16 bit ones. It is possible that we
1396 should make the default be WORD instead of LONG, but
1397 I think that'd break GCC, so we put up with a little
1398 inefficiency for the sake of working output. */
1400 if (!issword (nextword
)
1401 || (isvar (&opP
->disp
)
1402 && ((opP
->disp
.size
== SIZE_UNSPEC
1403 && flag_short_refs
== 0
1404 && cpu_of_arch (current_architecture
) >= m68020
)
1405 || opP
->disp
.size
== SIZE_LONG
)))
1408 tmpreg
= 0x3B; /* 7.3 */
1410 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1411 if (isvar (&opP
->disp
))
1417 add_fix ('l', &opP
->disp
, 1, 2);
1418 addword (0), addword (0);
1420 add_frag (adds (&opP
->disp
),
1422 TAB (PCLEA
, SZ_UNDEF
));
1429 add_fix ('l', &opP
->disp
, 0, 0);
1434 addword (nextword
>> 16);
1439 tmpreg
= 0x3A; /* 7.2 */
1441 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
1443 if (isvar (&opP
->disp
))
1447 add_fix ('w', &opP
->disp
, 1, 0);
1450 add_fix ('w', &opP
->disp
, 0, 0);
1460 baseo
= get_num (&opP
->disp
, 80);
1461 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1462 outro
= get_num (&opP
->odisp
, 80);
1463 /* Figure out the `addressing mode'.
1464 Also turn on the BASE_DISABLE bit, if needed. */
1465 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1467 tmpreg
= 0x3b; /* 7.3 */
1468 if (opP
->reg
== ZPC
)
1471 else if (opP
->reg
== 0)
1474 tmpreg
= 0x30; /* 6.garbage */
1476 else if (opP
->reg
>= ZADDR0
&& opP
->reg
<= ZADDR7
)
1479 tmpreg
= 0x30 + opP
->reg
- ZADDR0
;
1482 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
1484 siz1
= opP
->disp
.size
;
1485 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1486 siz2
= opP
->odisp
.size
;
1490 /* Index register stuff */
1491 if (opP
->index
.reg
!= 0
1492 && opP
->index
.reg
>= DATA
1493 && opP
->index
.reg
<= ADDR7
)
1495 nextword
|= (opP
->index
.reg
- DATA
) << 12;
1497 if (opP
->index
.size
== SIZE_UNSPEC
1498 || opP
->index
.size
== SIZE_LONG
)
1501 if (cpu_of_arch (current_architecture
) < m68020
)
1503 if (opP
->index
.scale
!= 1)
1506 "scale factor invalid on this architecture; needs 68020 or higher";
1510 switch (opP
->index
.scale
)
1527 GET US OUT OF HERE! */
1529 /* Must be INDEX, with an index register. Address
1530 register cannot be ZERO-PC, and either :b was
1531 forced, or we know it will fit. For a 68000 or
1532 68010, force this mode anyways, because the
1533 larger modes aren't supported. */
1534 if (opP
->mode
== BASE
1535 && ((opP
->reg
>= ADDR0
1536 && opP
->reg
<= ADDR7
)
1539 if (siz1
== SIZE_BYTE
1540 || cpu_of_arch (current_architecture
) < m68020
1541 || (siz1
== SIZE_UNSPEC
1542 && ! isvar (&opP
->disp
)
1543 && issbyte (baseo
)))
1545 nextword
+= baseo
& 0xff;
1547 if (isvar (&opP
->disp
))
1549 /* Do a byte relocation. If it doesn't
1550 fit (possible on m68000) let the
1551 fixup processing complain later. */
1553 add_fix ('B', &opP
->disp
, 1, 1);
1555 add_fix ('B', &opP
->disp
, 0, 0);
1557 else if (siz1
!= SIZE_BYTE
)
1559 if (siz1
!= SIZE_UNSPEC
)
1560 as_warn ("Forcing byte displacement");
1561 if (! issbyte (baseo
))
1562 opP
->error
= "byte displacement out of range";
1567 else if (siz1
== SIZE_UNSPEC
1569 && isvar (&opP
->disp
)
1570 && subs (&opP
->disp
) == NULL
)
1572 nextword
+= baseo
& 0xff;
1574 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1575 TAB (PCINDEX
, SZ_UNDEF
));
1583 nextword
|= 0x40; /* No index reg */
1584 if (opP
->index
.reg
>= ZDATA0
1585 && opP
->index
.reg
<= ZDATA7
)
1586 nextword
|= (opP
->index
.reg
- ZDATA0
) << 12;
1587 else if (opP
->index
.reg
>= ZADDR0
1588 || opP
->index
.reg
<= ZADDR7
)
1589 nextword
|= (opP
->index
.reg
- ZADDR0
+ 8) << 12;
1592 /* It isn't simple. */
1594 if (cpu_of_arch (current_architecture
) < m68020
)
1596 "invalid operand mode for this architecture; needs 68020 or higher";
1599 /* If the guy specified a width, we assume that it is
1600 wide enough. Maybe it isn't. If so, we lose. */
1604 if (isvar (&opP
->disp
) || !issword (baseo
))
1609 else if (baseo
== 0)
1618 as_warn (":b not permitted; defaulting to :w");
1628 /* Figure out innner displacement stuff */
1629 if (opP
->mode
== POST
|| opP
->mode
== PRE
)
1634 if (isvar (&opP
->odisp
) || !issword (outro
))
1639 else if (outro
== 0)
1648 as_warn (":b not permitted; defaulting to :w");
1657 if (opP
->mode
== POST
)
1662 if (siz1
!= SIZE_UNSPEC
&& isvar (&opP
->disp
))
1664 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
1665 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 1, 2);
1667 add_fix (siz1
== SIZE_LONG
? 'l' : 'w', &opP
->disp
, 0, 0);
1669 if (siz1
== SIZE_LONG
)
1670 addword (baseo
>> 16);
1671 if (siz1
!= SIZE_UNSPEC
)
1674 if (siz2
!= SIZE_UNSPEC
&& isvar (&opP
->odisp
))
1675 add_fix (siz2
== SIZE_LONG
? 'l' : 'w', &opP
->odisp
, 0, 0);
1676 if (siz2
== SIZE_LONG
)
1677 addword (outro
>> 16);
1678 if (siz2
!= SIZE_UNSPEC
)
1684 nextword
= get_num (&opP
->disp
, 80);
1685 switch (opP
->disp
.size
)
1690 if (!isvar (&opP
->disp
) && issword (offs (&opP
->disp
)))
1692 tmpreg
= 0x38; /* 7.0 */
1696 /* Don't generate pc relative code on 68010 and
1698 if (isvar (&opP
->disp
)
1699 && !subs (&opP
->disp
)
1700 && adds (&opP
->disp
)
1701 && (S_GET_SEGMENT (adds (&opP
->disp
)) == text_section
)
1702 && now_seg
== text_section
1703 && cpu_of_arch (current_architecture
) >= m68020
1705 && !strchr ("~%&$?", s
[0]))
1707 tmpreg
= 0x3A; /* 7.2 */
1708 add_frag (adds (&opP
->disp
),
1710 TAB (PCREL
, SZ_UNDEF
));
1713 /* Fall through into long */
1715 if (isvar (&opP
->disp
))
1716 add_fix ('l', &opP
->disp
, 0, 0);
1718 tmpreg
= 0x39;/* 7.1 mode */
1719 addword (nextword
>> 16);
1723 case SIZE_WORD
: /* Word */
1724 if (isvar (&opP
->disp
))
1725 add_fix ('w', &opP
->disp
, 0, 0);
1727 tmpreg
= 0x38;/* 7.0 mode */
1735 as_bad ("unknown/incorrect operand");
1738 install_gen_operand (s
[1], tmpreg
);
1744 { /* JF: I hate floating point! */
1759 tmpreg
= get_num (&opP
->disp
, tmpreg
);
1760 if (isvar (&opP
->disp
))
1761 add_fix (s
[1], &opP
->disp
, 0, 0);
1764 case 'b': /* Danger: These do no check for
1765 certain types of overflow.
1767 if (!isbyte (tmpreg
))
1768 opP
->error
= "out of range";
1769 insop (tmpreg
, opcode
);
1770 if (isvar (&opP
->disp
))
1771 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1774 if (!isword (tmpreg
))
1775 opP
->error
= "out of range";
1776 insop (tmpreg
, opcode
);
1777 if (isvar (&opP
->disp
))
1778 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1781 /* Because of the way insop works, we put these two out
1783 insop (tmpreg
, opcode
);
1784 insop (tmpreg
>> 16, opcode
);
1785 if (isvar (&opP
->disp
))
1786 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
1792 install_operand (s
[1], tmpreg
);
1803 install_operand (s
[1], opP
->reg
- ADDR
);
1807 tmpreg
= get_num (&opP
->disp
, 80);
1811 add_fix ('B', &opP
->disp
, 1, -1);
1814 add_fix ('w', &opP
->disp
, 1, 0);
1819 if (cpu_of_arch (current_architecture
) < m68020
)
1820 as_warn ("Can't use long branches on 68000/68010");
1821 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
1822 add_fix ('l', &opP
->disp
, 1, 0);
1827 if (subs (&opP
->disp
)) /* We can't relax it */
1830 /* This could either be a symbol, or an absolute
1831 address. No matter, the frag hacking will finger it
1832 out. Not quite: it can't switch from BRANCH to
1833 BCC68000 for the case where opnd is absolute (it
1834 needs to use the 68000 hack since no conditional abs
1836 if (((cpu_of_arch (current_architecture
) < m68020
)
1837 || (0 == adds (&opP
->disp
)))
1838 && (the_ins
.opcode
[0] >= 0x6200)
1839 && (the_ins
.opcode
[0] <= 0x6f00))
1840 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1841 TAB (BCC68000
, SZ_UNDEF
));
1843 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1844 TAB (ABRANCH
, SZ_UNDEF
));
1847 if (isvar (&opP
->disp
))
1850 /* check for DBcc instruction */
1851 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
1853 /* size varies if patch */
1854 /* needed for long form */
1855 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1856 TAB (DBCC
, SZ_UNDEF
));
1860 add_fix ('w', &opP
->disp
, 1, 0);
1864 case 'C': /* Fixed size LONG coproc branches */
1865 add_fix ('l', &opP
->disp
, 1, 0);
1869 case 'c': /* Var size Coprocesssor branches */
1870 if (subs (&opP
->disp
))
1872 add_fix ('l', &opP
->disp
, 1, 0);
1873 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
1875 else if (adds (&opP
->disp
))
1876 add_frag (adds (&opP
->disp
), offs (&opP
->disp
),
1877 TAB (FBRANCH
, SZ_UNDEF
));
1880 /* add_frag((symbolS *) 0, offs(&opP->disp),
1881 TAB(FBRANCH,SHORT)); */
1882 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
1883 add_fix ('l', &opP
->disp
, 1, 0);
1893 case 'C': /* Ignore it */
1896 case 'd': /* JF this is a kludge */
1897 install_operand ('s', opP
->reg
- ADDR
);
1898 tmpreg
= get_num (&opP
->disp
, 80);
1899 if (!issword (tmpreg
))
1901 as_warn ("Expression out of range, using 0");
1908 install_operand (s
[1], opP
->reg
- DATA
);
1912 install_operand (s
[1], opP
->reg
- FP0
);
1916 tmpreg
= 1 + opP
->reg
- COPNUM
;
1919 install_operand (s
[1], tmpreg
);
1922 case 'J': /* JF foo */
1983 install_operand (s
[1], tmpreg
);
1987 tmpreg
= get_num (&opP
->disp
, 55);
1988 install_operand (s
[1], tmpreg
& 0x7f);
1995 if (tmpreg
& 0x7FF0000)
1996 as_bad ("Floating point register in register list");
1997 insop (reverse_16_bits (tmpreg
), opcode
);
2001 if (tmpreg
& 0x700FFFF)
2002 as_bad ("Wrong register in floating-point reglist");
2003 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2011 if (tmpreg
& 0x7FF0000)
2012 as_bad ("Floating point register in register list");
2013 insop (tmpreg
, opcode
);
2015 else if (s
[1] == '8')
2017 if (tmpreg
& 0x0FFFFFF)
2018 as_bad ("incorrect register in reglist");
2019 install_operand (s
[1], tmpreg
>> 24);
2023 if (tmpreg
& 0x700FFFF)
2024 as_bad ("wrong register in floating-point reglist");
2026 install_operand (s
[1], tmpreg
>> 16);
2031 install_operand (s
[1], get_num (&opP
->disp
, 60));
2035 tmpreg
= ((opP
->mode
== DREG
)
2036 ? 0x20 + opP
->reg
- DATA
2037 : (get_num (&opP
->disp
, 40) & 0x1F));
2038 install_operand (s
[1], tmpreg
);
2042 tmpreg
= get_num (&opP
->disp
, 10);
2045 install_operand (s
[1], tmpreg
);
2049 /* This depends on the fact that ADDR registers are eight
2050 more than their corresponding DATA regs, so the result
2051 will have the ADDR_REG bit set */
2052 install_operand (s
[1], opP
->reg
- DATA
);
2056 if (opP
->mode
== AINDR
)
2057 install_operand (s
[1], opP
->reg
- DATA
);
2059 install_operand (s
[1], opP
->index
.reg
- DATA
);
2063 if (opP
->reg
== FPI
)
2065 else if (opP
->reg
== FPS
)
2067 else if (opP
->reg
== FPC
)
2071 install_operand (s
[1], tmpreg
);
2074 case 'S': /* Ignore it */
2078 install_operand (s
[1], get_num (&opP
->disp
, 30));
2081 case 'U': /* Ignore it */
2100 as_fatal ("failed sanity check");
2101 } /* switch on cache token */
2102 install_operand (s
[1], tmpreg
);
2105 /* JF: These are out of order, I fear. */
2118 install_operand (s
[1], tmpreg
);
2142 install_operand (s
[1], tmpreg
);
2146 if (opP
->reg
== VAL
)
2165 install_operand (s
[1], tmpreg
);
2179 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2190 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2196 install_operand (s
[1], tmpreg
);
2199 know (opP
->reg
== PSR
);
2202 know (opP
->reg
== PCSR
);
2217 install_operand (s
[1], tmpreg
);
2220 tmpreg
= get_num (&opP
->disp
, 20);
2221 install_operand (s
[1], tmpreg
);
2223 case '_': /* used only for move16 absolute 32-bit address */
2224 tmpreg
= get_num (&opP
->disp
, 80);
2225 addword (tmpreg
>> 16);
2226 addword (tmpreg
& 0xFFFF);
2233 /* By the time whe get here (FINALLY) the_ins contains the complete
2234 instruction, ready to be emitted. . . */
2238 reverse_16_bits (in
)
2244 static int mask
[16] =
2246 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2247 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2249 for (n
= 0; n
< 16; n
++)
2252 out
|= mask
[15 - n
];
2255 } /* reverse_16_bits() */
2264 static int mask
[8] =
2266 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2269 for (n
= 0; n
< 8; n
++)
2275 } /* reverse_8_bits() */
2277 /* Cause an extra frag to be generated here, inserting up to 10 bytes
2278 (that value is chosen in the frag_var call in md_assemble). TYPE
2279 is the subtype of the frag to be generated; its primary type is
2280 rs_machine_dependent.
2282 The TYPE parameter is also used by md_convert_frag_1 and
2283 md_estimate_size_before_relax. The appropriate type of fixup will
2284 be emitted by md_convert_frag_1.
2286 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
2288 install_operand (mode
, val
)
2295 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
2298 the_ins
.opcode
[0] |= val
<< 9;
2301 the_ins
.opcode
[1] |= val
<< 12;
2304 the_ins
.opcode
[1] |= val
<< 6;
2307 the_ins
.opcode
[1] |= val
;
2310 the_ins
.opcode
[2] |= val
<< 12;
2313 the_ins
.opcode
[2] |= val
<< 6;
2316 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2317 three words long! */
2319 the_ins
.opcode
[2] |= val
;
2322 the_ins
.opcode
[1] |= val
<< 7;
2325 the_ins
.opcode
[1] |= val
<< 10;
2329 the_ins
.opcode
[1] |= val
<< 5;
2334 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
2337 the_ins
.opcode
[1] |= (val
<< 12) | val
;
2340 the_ins
.opcode
[0] |= val
= 0xff;
2343 the_ins
.opcode
[0] |= val
<< 9;
2346 the_ins
.opcode
[1] |= val
;
2349 the_ins
.opcode
[1] |= val
;
2350 the_ins
.numo
++; /* What a hack */
2353 the_ins
.opcode
[1] |= val
<< 4;
2360 the_ins
.opcode
[0] |= (val
<< 6);
2363 the_ins
.opcode
[1] = (val
>> 16);
2364 the_ins
.opcode
[2] = val
& 0xffff;
2368 as_fatal ("failed sanity check.");
2370 } /* install_operand() */
2373 install_gen_operand (mode
, val
)
2380 the_ins
.opcode
[0] |= val
;
2383 /* This is a kludge!!! */
2384 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
2393 the_ins
.opcode
[0] |= val
;
2395 /* more stuff goes here */
2397 as_fatal ("failed sanity check.");
2399 } /* install_gen_operand() */
2402 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2403 * then deal with the bitfield hack.
2407 crack_operand (str
, opP
)
2409 register struct m68k_op
*opP
;
2411 register int parens
;
2413 register char *beg_str
;
2420 for (parens
= 0; *str
&& (parens
> 0 || notend (str
)); str
++)
2424 else if (*str
== ')')
2428 opP
->error
= "Extra )";
2434 if (!*str
&& parens
)
2436 opP
->error
= "Missing )";
2441 if (m68k_ip_op (beg_str
, opP
) != 0)
2448 c
= *++str
; /* JF bitfield hack */
2453 as_bad ("Missing operand");
2458 /* This is the guts of the machine-dependent assembler. STR points to a
2459 machine dependent instruction. This function is supposed to emit
2460 the frags/bytes it assembles to.
2464 insert_reg (regname
, regnum
)
2471 #ifdef REGISTER_PREFIX
2472 if (!flag_reg_prefix_optional
)
2474 buf
[0] = REGISTER_PREFIX
;
2475 strcpy (buf
+ 1, regname
);
2480 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
2481 &zero_address_frag
));
2483 for (i
= 0; regname
[i
]; i
++)
2484 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2487 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
2488 &zero_address_frag
));
2497 static const struct init_entry init_table
[] =
2607 /* 68ec030 versions of same */
2610 /* 68ec030 access control unit, identical to 030 MMU status reg */
2613 /* Suppressed data and address registers. */
2638 for (i
= 0; init_table
[i
].name
; i
++)
2639 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
2642 static int no_68851
, no_68881
;
2645 /* a.out machine type. Default to 68020. */
2646 int m68k_aout_machtype
= 2;
2658 int shorts_this_frag
;
2661 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
2666 for (n
= 0; n
< the_ins
.numargs
; n
++)
2667 if (the_ins
.operands
[n
].error
)
2669 er
= the_ins
.operands
[n
].error
;
2675 as_bad ("%s -- statement `%s' ignored", er
, str
);
2679 if (the_ins
.nfrag
== 0)
2681 /* No frag hacking involved; just put it out */
2682 toP
= frag_more (2 * the_ins
.numo
);
2683 fromP
= &the_ins
.opcode
[0];
2684 for (m
= the_ins
.numo
; m
; --m
)
2686 md_number_to_chars (toP
, (long) (*fromP
), 2);
2690 /* put out symbol-dependent info */
2691 for (m
= 0; m
< the_ins
.nrel
; m
++)
2693 switch (the_ins
.reloc
[m
].wid
)
2711 as_fatal ("Don't know how to figure width of %c in md_assemble()",
2712 the_ins
.reloc
[m
].wid
);
2715 fixP
= fix_new_exp (frag_now
,
2716 ((toP
- frag_now
->fr_literal
)
2717 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
2719 &the_ins
.reloc
[m
].exp
,
2720 the_ins
.reloc
[m
].pcrel
,
2722 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2727 /* There's some frag hacking */
2728 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
2733 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
2735 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
2736 toP
= frag_more (wid
);
2738 shorts_this_frag
= 0;
2739 for (m
= wid
/ 2; m
; --m
)
2741 md_number_to_chars (toP
, (long) (*fromP
), 2);
2746 for (m
= 0; m
< the_ins
.nrel
; m
++)
2748 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
2750 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
2753 wid
= the_ins
.reloc
[m
].wid
;
2756 the_ins
.reloc
[m
].wid
= 0;
2757 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
2759 fixP
= fix_new_exp (frag_now
,
2760 ((toP
- frag_now
->fr_literal
)
2761 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
2763 &the_ins
.reloc
[m
].exp
,
2764 the_ins
.reloc
[m
].pcrel
,
2766 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2768 (void) frag_var (rs_machine_dependent
, 10, 0,
2769 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
2770 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
2772 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
2773 shorts_this_frag
= 0;
2776 toP
= frag_more (n
* sizeof (short));
2779 md_number_to_chars (toP
, (long) (*fromP
), 2);
2785 for (m
= 0; m
< the_ins
.nrel
; m
++)
2789 wid
= the_ins
.reloc
[m
].wid
;
2792 the_ins
.reloc
[m
].wid
= 0;
2793 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
2795 fixP
= fix_new_exp (frag_now
,
2796 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
2797 - shorts_this_frag
* 2),
2799 &the_ins
.reloc
[m
].exp
,
2800 the_ins
.reloc
[m
].pcrel
,
2802 fixP
->fx_pcrel_adjust
= the_ins
.reloc
[m
].pcrel_fix
;
2810 * md_begin -- set up hash tables with 68000 instructions.
2811 * similar to what the vax assembler does. ---phr
2813 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2814 a copy of it at runtime, adding in the information we want but isn't
2815 there. I think it'd be better to have an awk script hack the table
2816 at compile time. Or even just xstr the table and use it as-is. But
2817 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2820 register const struct m68k_opcode
*ins
;
2821 register struct m68k_incant
*hack
, *slak
;
2822 register const char *retval
= 0; /* empty string, or error msg text */
2823 register unsigned int i
;
2827 flag_reg_prefix_optional
= 1;
2829 op_hash
= hash_new ();
2831 obstack_begin (&robyn
, 4000);
2832 for (i
= 0; i
< m68k_numopcodes
; i
++)
2834 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
2837 ins
= &m68k_opcodes
[i
];
2838 /* We *could* ignore insns that don't match our arch here
2839 but just leaving them out of the hash. */
2840 slak
->m_operands
= ins
->args
;
2841 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
2842 slak
->m_arch
= ins
->arch
;
2843 slak
->m_opcode
= ins
->opcode
;
2844 /* This is kludgey */
2845 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
2846 if (i
+ 1 != m68k_numopcodes
2847 && !strcmp (ins
->name
, m68k_opcodes
[i
+ 1].name
))
2849 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
2854 slak
= slak
->m_next
;
2858 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
2860 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
2863 for (i
= 0; i
< m68k_numaliases
; i
++)
2865 const char *name
= m68k_opcode_aliases
[i
].primary
;
2866 const char *alias
= m68k_opcode_aliases
[i
].alias
;
2867 PTR val
= hash_find (op_hash
, name
);
2869 as_fatal ("Internal Error: Can't find %s in hash table", name
);
2870 retval
= hash_insert (op_hash
, alias
, val
);
2872 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
2875 for (i
= 0; i
< sizeof (mklower_table
); i
++)
2876 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
2878 for (i
= 0; i
< sizeof (notend_table
); i
++)
2880 notend_table
[i
] = 0;
2881 alt_notend_table
[i
] = 0;
2883 notend_table
[','] = 1;
2884 notend_table
['{'] = 1;
2885 notend_table
['}'] = 1;
2886 alt_notend_table
['a'] = 1;
2887 alt_notend_table
['A'] = 1;
2888 alt_notend_table
['d'] = 1;
2889 alt_notend_table
['D'] = 1;
2890 alt_notend_table
['#'] = 1;
2891 alt_notend_table
['&'] = 1;
2892 alt_notend_table
['f'] = 1;
2893 alt_notend_table
['F'] = 1;
2894 #ifdef REGISTER_PREFIX
2895 alt_notend_table
[REGISTER_PREFIX
] = 1;
2898 /* We need to put '(' in alt_notend_table to handle
2899 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
2901 alt_notend_table
['('] = 1;
2903 /* We need to put '@' in alt_notend_table to handle
2904 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
2906 alt_notend_table
['@'] = 1;
2908 #ifndef MIT_SYNTAX_ONLY
2909 /* Insert pseudo ops, these have to go into the opcode table since
2910 gas expects pseudo ops to start with a dot */
2913 while (mote_pseudo_table
[n
].poc_name
)
2915 hack
= (struct m68k_incant
*)
2916 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
2917 hash_insert (op_hash
,
2918 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
2919 hack
->m_operands
= 0;
2930 m68k_init_after_args ()
2932 if (cpu_of_arch (current_architecture
) == 0)
2935 const char *default_cpu
= TARGET_CPU
;
2937 if (*default_cpu
== 'm')
2939 for (i
= 0; i
< n_archs
; i
++)
2940 if (!strcmp (default_cpu
, archs
[i
].name
))
2944 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
2945 current_architecture
|= m68020
;
2948 current_architecture
|= archs
[i
].arch
;
2950 /* Permit m68881 specification with all cpus; those that can't work
2951 with a coprocessor could be doing emulation. */
2952 if (current_architecture
& m68851
)
2954 if (current_architecture
& m68040
)
2956 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
2959 /* What other incompatibilities could we check for? */
2961 /* Toss in some default assumptions about coprocessors. */
2963 && (cpu_of_arch (current_architecture
)
2964 /* Can CPU32 have a 68881 coprocessor?? */
2965 & (m68020
| m68030
| cpu32
)))
2967 current_architecture
|= m68881
;
2970 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
2971 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
2973 current_architecture
|= m68851
;
2975 if (no_68881
&& (current_architecture
& m68881
))
2976 as_bad ("options for 68881 and no-68881 both given");
2977 if (no_68851
&& (current_architecture
& m68851
))
2978 as_bad ("options for 68851 and no-68851 both given");
2981 /* Work out the magic number. This isn't very general. */
2982 if (current_architecture
& m68000
)
2983 m68k_aout_machtype
= 0;
2984 else if (current_architecture
& m68010
)
2985 m68k_aout_machtype
= 1;
2986 else if (current_architecture
& m68020
)
2987 m68k_aout_machtype
= 2;
2989 m68k_aout_machtype
= 2;
2992 /* Note which set of "movec" control registers is available. */
2993 switch (cpu_of_arch (current_architecture
))
2996 control_regs
= m68000_control_regs
;
2999 control_regs
= m68010_control_regs
;
3003 control_regs
= m68020_control_regs
;
3006 control_regs
= m68040_control_regs
;
3009 control_regs
= m68060_control_regs
;
3012 control_regs
= cpu32_control_regs
;
3018 if (cpu_of_arch (current_architecture
) < m68020
)
3019 md_relax_table
[TAB (PCINDEX
, BYTE
)].rlx_more
= 0;
3022 /* Equal to MAX_PRECISION in atof-ieee.c */
3023 #define MAX_LITTLENUMS 6
3025 /* Turn a string in input_line_pointer into a floating point constant
3026 of type type, and store the appropriate bytes in *litP. The number
3027 of LITTLENUMS emitted is stored in *sizeP . An error message is
3028 returned, or NULL on OK. */
3031 md_atof (type
, litP
, sizeP
)
3037 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3038 LITTLENUM_TYPE
*wordP
;
3070 return "Bad call to MD_ATOF()";
3072 t
= atof_ieee (input_line_pointer
, type
, words
);
3074 input_line_pointer
= t
;
3076 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3077 for (wordP
= words
; prec
--;)
3079 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3080 litP
+= sizeof (LITTLENUM_TYPE
);
3086 md_number_to_chars (buf
, val
, n
)
3091 number_to_chars_bigendian (buf
, val
, n
);
3095 md_apply_fix_2 (fixP
, val
)
3099 addressT upper_limit
;
3100 offsetT lower_limit
;
3102 /* This is unnecessary but it convinces the native rs6000 compiler
3103 to generate the code we want. */
3104 char *buf
= fixP
->fx_frag
->fr_literal
;
3105 buf
+= fixP
->fx_where
;
3106 /* end ibm compiler workaround */
3108 if (val
& 0x80000000)
3109 val
|= ~(addressT
)0x7fffffff;
3113 switch (fixP
->fx_size
)
3115 /* The cast to offsetT below are necessary to make code correct for
3116 machines where ints are smaller than offsetT */
3120 lower_limit
= - (offsetT
) 0x80;
3123 *buf
++ = (val
>> 8);
3125 upper_limit
= 0x7fff;
3126 lower_limit
= - (offsetT
) 0x8000;
3129 *buf
++ = (val
>> 24);
3130 *buf
++ = (val
>> 16);
3131 *buf
++ = (val
>> 8);
3133 upper_limit
= 0x7fffffff;
3134 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
3137 BAD_CASE (fixP
->fx_size
);
3140 /* For non-pc-relative values, it's conceivable we might get something
3141 like "0xff" for a byte field. So extend the upper part of the range
3142 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3143 so that we can do any range checking at all. */
3144 if (!fixP
->fx_pcrel
)
3145 upper_limit
= upper_limit
* 2 + 1;
3147 if ((addressT
) val
> upper_limit
3148 && (val
> 0 || val
< lower_limit
))
3149 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
3151 /* A one byte PC-relative reloc means a short branch. We can't use
3152 a short branch with a value of 0 or -1, because those indicate
3153 different opcodes (branches with longer offsets). */
3155 && fixP
->fx_size
== 1
3156 && (fixP
->fx_addsy
== NULL
3157 || S_IS_DEFINED (fixP
->fx_addsy
))
3158 && (val
== 0 || val
== -1))
3159 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
3162 #ifdef BFD_ASSEMBLER
3164 md_apply_fix (fixP
, valp
)
3168 md_apply_fix_2 (fixP
, (addressT
) *valp
);
3172 void md_apply_fix (fixP
, val
)
3176 md_apply_fix_2 (fixP
, (addressT
) val
);
3180 /* *fragP has been relaxed to its final size, and now needs to have
3181 the bytes inside it modified to conform to the new size There is UGLY
3185 md_convert_frag_1 (fragP
)
3186 register fragS
*fragP
;
3192 /* Address in object code of the displacement. */
3193 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3195 /* Address in gas core of the place to store the displacement. */
3196 /* This convinces the native rs6000 compiler to generate the code we
3198 register char *buffer_address
= fragP
->fr_literal
;
3199 buffer_address
+= fragP
->fr_fix
;
3200 /* end ibm compiler workaround */
3202 /* The displacement of the address, from current location. */
3203 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3204 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3206 #ifdef BFD_ASSEMBLER
3207 disp
+= fragP
->fr_symbol
->sy_frag
->fr_address
;
3210 switch (fragP
->fr_subtype
)
3212 case TAB (BCC68000
, BYTE
):
3213 case TAB (ABRANCH
, BYTE
):
3214 know (issbyte (disp
));
3216 as_bad ("short branch with zero offset: use :w");
3217 fragP
->fr_opcode
[1] = disp
;
3220 case TAB (DBCC
, SHORT
):
3221 know (issword (disp
));
3224 case TAB (BCC68000
, SHORT
):
3225 case TAB (ABRANCH
, SHORT
):
3226 know (issword (disp
));
3227 fragP
->fr_opcode
[1] = 0x00;
3230 case TAB (ABRANCH
, LONG
):
3231 if (cpu_of_arch (current_architecture
) < m68020
)
3233 if (fragP
->fr_opcode
[0] == 0x61)
3236 fragP
->fr_opcode
[0] = 0x4E;
3237 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3238 subseg_change (text_section
, 0); /* @@ */
3252 else if (fragP
->fr_opcode
[0] == 0x60)
3254 fragP
->fr_opcode
[0] = 0x4E;
3255 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3256 subseg_change (text_section
, 0); /* @@ */
3257 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3258 fragP
->fr_offset
, 0, NO_RELOC
);
3264 as_bad ("Long branch offset not supported.");
3269 fragP
->fr_opcode
[1] = (char) 0xff;
3273 case TAB (BCC68000
, LONG
):
3274 /* only Bcc 68000 instructions can come here */
3275 /* change bcc into b!cc/jmp absl long */
3276 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3277 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
3279 /* JF: these used to be fr_opcode[2,3], but they may be in a
3280 different frag, in which case refering to them is a no-no.
3281 Only fr_opcode[0,1] are guaranteed to work. */
3282 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3283 *buffer_address
++ = (char) 0xf9;
3284 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3285 subseg_change (text_section
, 0);
3286 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3287 fragP
->fr_offset
, 0, NO_RELOC
);
3291 case TAB (DBCC
, LONG
):
3292 /* only DBcc 68000 instructions can come here */
3293 /* change dbcc into dbcc/jmp absl long */
3294 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3295 *buffer_address
++ = 0x00; /* branch offset = 4 */
3296 *buffer_address
++ = 0x04;
3297 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3298 *buffer_address
++ = 0x06;
3299 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3300 *buffer_address
++ = (char) 0xf9;
3302 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3303 subseg_change (text_section
, 0);
3304 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3305 fragP
->fr_offset
, 0, NO_RELOC
);
3309 case TAB (FBRANCH
, SHORT
):
3310 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
3313 case TAB (FBRANCH
, LONG
):
3314 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3317 case TAB (PCREL
, SHORT
):
3320 case TAB (PCREL
, LONG
):
3321 /* The thing to do here is force it to ABSOLUTE LONG, since
3322 PCREL is really trying to shorten an ABSOLUTE address anyway */
3323 /* JF FOO This code has not been tested */
3324 subseg_change (text_section
, 0);
3325 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
3327 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3328 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
3329 (unsigned) fragP
->fr_opcode
[0],
3330 (unsigned long) fragP
->fr_address
);
3331 fragP
->fr_opcode
[1] &= ~0x3F;
3332 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
3336 case TAB (PCLEA
, SHORT
):
3337 subseg_change (text_section
, 0);
3338 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3339 fragP
->fr_offset
, 1, NO_RELOC
);
3340 fragP
->fr_opcode
[1] &= ~0x3F;
3341 fragP
->fr_opcode
[1] |= 0x3A; /* 072 - mode 7.2 */
3344 case TAB (PCLEA
, LONG
):
3345 subseg_change (text_section
, 0);
3346 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
3347 fragP
->fr_offset
, 1, NO_RELOC
);
3348 fixP
->fx_pcrel_adjust
= 2;
3349 /* Already set to mode 7.3; this indicates: PC indirect with
3350 suppressed index, 32-bit displacement. */
3351 *buffer_address
++ = 0x01;
3352 *buffer_address
++ = 0x70;
3357 case TAB (PCINDEX
, BYTE
):
3359 if (!issbyte (disp
))
3361 as_bad ("displacement doesn't fit in one byte");
3364 assert (fragP
->fr_fix
>= 2);
3365 buffer_address
[-2] &= ~1;
3366 buffer_address
[-1] = disp
;
3369 case TAB (PCINDEX
, SHORT
):
3370 subseg_change (text_section
, 0);
3372 assert (issword (disp
));
3373 assert (fragP
->fr_fix
>= 2);
3374 buffer_address
[-2] |= 0x1;
3375 buffer_address
[-1] = 0x20;
3376 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
3377 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3379 fixP
->fx_pcrel_adjust
= 2;
3382 case TAB (PCINDEX
, LONG
):
3383 subseg_change (text_section
, 0);
3385 fixP
= fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3386 fragP
->fr_offset
, (fragP
->fr_opcode
[1] & 077) == 073,
3388 fixP
->fx_pcrel_adjust
= 2;
3389 assert (fragP
->fr_fix
>= 2);
3390 buffer_address
[-2] |= 0x1;
3391 buffer_address
[-1] = 0x30;
3398 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
3399 fragP
->fr_fix
+= ext
;
3403 #ifndef BFD_ASSEMBLER
3406 md_convert_frag (headers
, sec
, fragP
)
3407 object_headers
*headers
;
3411 md_convert_frag_1 (fragP
);
3417 md_convert_frag (abfd
, sec
, fragP
)
3422 md_convert_frag_1 (fragP
);
3426 /* Force truly undefined symbols to their maximum size, and generally set up
3427 the frag list to be relaxed
3430 md_estimate_size_before_relax (fragP
, segment
)
3431 register fragS
*fragP
;
3435 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3437 old_fix
= fragP
->fr_fix
;
3439 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3440 switch (fragP
->fr_subtype
)
3443 case TAB (ABRANCH
, SZ_UNDEF
):
3445 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3446 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3448 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
3451 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
3453 /* On 68000, or for absolute value, switch to abs long */
3454 /* FIXME, we should check abs val, pick short or long */
3455 if (fragP
->fr_opcode
[0] == 0x61)
3457 fragP
->fr_opcode
[0] = 0x4E;
3458 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
3459 subseg_change (text_section
, 0);
3460 fix_new (fragP
, fragP
->fr_fix
, 4,
3461 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3465 else if (fragP
->fr_opcode
[0] == 0x60)
3467 fragP
->fr_opcode
[0] = 0x4E;
3468 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
3469 subseg_change (text_section
, 0);
3470 fix_new (fragP
, fragP
->fr_fix
, 4,
3471 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
3477 as_warn ("Long branch offset to extern symbol not supported.");
3481 { /* Symbol is still undefined. Make it simple */
3482 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3483 fragP
->fr_offset
, 1, NO_RELOC
);
3485 fragP
->fr_opcode
[1] = (char) 0xff;
3491 } /* case TAB(ABRANCH,SZ_UNDEF) */
3493 case TAB (FBRANCH
, SZ_UNDEF
):
3495 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
3497 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
3502 fix_new (fragP
, (int) fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3503 fragP
->fr_offset
, 1, NO_RELOC
);
3505 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
3509 } /* TAB(FBRANCH,SZ_UNDEF) */
3511 case TAB (PCREL
, SZ_UNDEF
):
3513 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3515 || cpu_of_arch (current_architecture
) < m68020
)
3517 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
3522 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
3526 } /* TAB(PCREL,SZ_UNDEF) */
3528 case TAB (BCC68000
, SZ_UNDEF
):
3530 if ((fragP
->fr_symbol
!= NULL
)
3531 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3533 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
3536 /* only Bcc 68000 instructions can come here */
3537 /* change bcc into b!cc/jmp absl long */
3538 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3539 if (flag_short_refs
)
3541 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3542 /* JF: these were fr_opcode[2,3] */
3543 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3544 buffer_address
[1] = (char) 0xf8;
3545 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3546 subseg_change (text_section
, 0);
3547 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3548 fragP
->fr_offset
, 0, NO_RELOC
);
3553 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3554 /* JF: these were fr_opcode[2,3] */
3555 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3556 buffer_address
[1] = (char) 0xf9;
3557 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3558 subseg_change (text_section
, 0);
3559 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3560 fragP
->fr_offset
, 0, NO_RELOC
);
3565 } /* case TAB(BCC68000,SZ_UNDEF) */
3567 case TAB (DBCC
, SZ_UNDEF
):
3569 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
3571 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
3575 /* only DBcc 68000 instructions can come here */
3576 /* change dbcc into dbcc/jmp absl long */
3577 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3578 buffer_address
[0] = 0x00; /* branch offset = 4 */
3579 buffer_address
[1] = 0x04;
3580 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3582 if (flag_short_refs
)
3584 /* JF: these were fr_opcode[5-7] */
3585 buffer_address
[3] = 0x04; /* plus 4 */
3586 buffer_address
[4] = 0x4e; /* Put in Jump Word */
3587 buffer_address
[5] = (char) 0xf8;
3588 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3589 subseg_change (text_section
, 0);
3590 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3591 fragP
->fr_offset
, 0, NO_RELOC
);
3596 /* JF: these were fr_opcode[5-7] */
3597 buffer_address
[3] = 0x06; /* Plus 6 */
3598 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3599 buffer_address
[5] = (char) 0xf9;
3600 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3601 subseg_change (text_section
, 0);
3602 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
3603 fragP
->fr_offset
, 0, NO_RELOC
);
3609 } /* case TAB(DBCC,SZ_UNDEF) */
3611 case TAB (PCLEA
, SZ_UNDEF
):
3613 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
3615 || cpu_of_arch (current_architecture
) < m68020
)
3617 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
3622 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
3626 } /* TAB(PCLEA,SZ_UNDEF) */
3628 case TAB (PCINDEX
, SZ_UNDEF
):
3629 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
3630 || cpu_of_arch (current_architecture
) < m68020
)
3632 fragP
->fr_subtype
= TAB (PCINDEX
, BYTE
);
3636 fragP
->fr_subtype
= TAB (PCINDEX
, LONG
);
3645 /* now that SZ_UNDEF are taken care of, check others */
3646 switch (fragP
->fr_subtype
)
3648 case TAB (BCC68000
, BYTE
):
3649 case TAB (ABRANCH
, BYTE
):
3650 /* We can't do a short jump to the next instruction,
3651 so we force word mode. */
3652 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
3653 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
3655 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
3662 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3665 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3666 /* the bit-field entries in the relocation_info struct plays hell
3667 with the byte-order problems of cross-assembly. So as a hack,
3668 I added this mach. dependent ri twiddler. Ugly, but it gets
3670 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3671 are symbolnum, most sig. byte first. Last byte is broken up with
3672 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3673 nibble as nuthin. (on Sun 3 at least) */
3674 /* Translate the internal relocation information into target-specific
3678 md_ri_to_chars (the_bytes
, ri
)
3680 struct reloc_info_generic
*ri
;
3683 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
3684 /* now the fun stuff */
3685 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3686 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3687 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3688 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3689 ((ri
->r_extern
<< 4) & 0x10));
3692 #endif /* comment */
3694 #ifndef BFD_ASSEMBLER
3696 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
3699 relax_addressT segment_address_in_file
;
3702 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3703 * Out: GNU LD relocation length code: 0, 1, or 2.
3706 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
3709 know (fixP
->fx_addsy
!= NULL
);
3711 md_number_to_chars (where
,
3712 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3715 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
3716 ? S_GET_TYPE (fixP
->fx_addsy
)
3717 : fixP
->fx_addsy
->sy_number
);
3719 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3720 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3721 where
[6] = r_symbolnum
& 0x0ff;
3722 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3723 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
3727 #endif /* OBJ_AOUT or OBJ_BOUT */
3729 #ifndef WORKING_DOT_WORD
3730 CONST
int md_short_jump_size
= 4;
3731 CONST
int md_long_jump_size
= 6;
3734 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3736 addressT from_addr
, to_addr
;
3742 offset
= to_addr
- (from_addr
+ 2);
3744 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
3745 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
3749 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3751 addressT from_addr
, to_addr
;
3757 if (cpu_of_arch (current_architecture
) < m68020
)
3759 offset
= to_addr
- S_GET_VALUE (to_symbol
);
3760 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
3761 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
3762 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
3767 offset
= to_addr
- (from_addr
+ 2);
3768 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
3769 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
3775 /* Different values of OK tell what its OK to return. Things that
3776 aren't OK are an error (what a shock, no?)
3779 10: Absolute 1:8 only
3780 20: Absolute 0:7 only
3781 30: absolute 0:15 only
3782 40: Absolute 0:31 only
3783 50: absolute 0:127 only
3784 55: absolute -64:63 only
3785 60: absolute -128:127 only
3786 70: absolute 0:4095 only
3793 struct m68k_exp
*exp
;
3796 if (exp
->exp
.X_op
== O_absent
)
3798 /* Do the same thing the VAX asm does */
3799 op (exp
) = O_constant
;
3805 as_warn ("expression out of range: defaulting to 1");
3809 else if (exp
->exp
.X_op
== O_constant
)
3814 if (offs (exp
) < 1 || offs (exp
) > 8)
3816 as_warn ("expression out of range: defaulting to 1");
3821 if (offs (exp
) < 0 || offs (exp
) > 7)
3825 if (offs (exp
) < 0 || offs (exp
) > 15)
3829 if (offs (exp
) < 0 || offs (exp
) > 32)
3833 if (offs (exp
) < 0 || offs (exp
) > 127)
3837 if (offs (exp
) < -64 || offs (exp
) > 63)
3841 if (offs (exp
) < -128 || offs (exp
) > 127)
3845 if (offs (exp
) < 0 || offs (exp
) > 4095)
3848 as_warn ("expression out of range: defaulting to 0");
3856 else if (exp
->exp
.X_op
== O_big
)
3858 if (offs (exp
) <= 0 /* flonum */
3859 && (ok
== 80 /* no bignums */
3860 || (ok
> 10 /* small-int ranges including 0 ok */
3861 /* If we have a flonum zero, a zero integer should
3862 do as well (e.g., in moveq). */
3863 && generic_floating_point_number
.exponent
== 0
3864 && generic_floating_point_number
.low
[0] == 0)))
3866 /* HACK! Turn it into a long */
3867 LITTLENUM_TYPE words
[6];
3869 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
3870 op (exp
) = O_constant
;
3873 offs (exp
) = words
[1] | (words
[0] << 16);
3877 op (exp
) = O_constant
;
3880 offs (exp
) = (ok
== 10) ? 1 : 0;
3881 as_warn ("Can't deal with expression; defaulting to %ld",
3887 if (ok
>= 10 && ok
<= 70)
3889 op (exp
) = O_constant
;
3892 offs (exp
) = (ok
== 10) ? 1 : 0;
3893 as_warn ("Can't deal with expression; defaulting to %ld",
3898 if (exp
->size
!= SIZE_UNSPEC
)
3906 if (!isbyte (offs (exp
)))
3907 as_warn ("expression doesn't fit in BYTE");
3910 if (!isword (offs (exp
)))
3911 as_warn ("expression doesn't fit in WORD");
3919 /* These are the back-ends for the various machine dependent pseudo-ops. */
3920 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
3926 subseg_set (data_section
, 1);
3927 demand_empty_rest_of_line ();
3934 subseg_set (data_section
, 2);
3935 demand_empty_rest_of_line ();
3942 /* We don't support putting frags in the BSS segment, we fake it
3943 by marking in_bss, then looking at s_skip for clues. */
3945 subseg_set (bss_section
, 0);
3946 demand_empty_rest_of_line ();
3954 register long temp_fill
;
3956 temp
= 1; /* JF should be 2? */
3957 temp_fill
= get_absolute_expression ();
3958 if (!need_pass_2
) /* Never make frag if expect extra pass. */
3959 frag_align (temp
, (int) temp_fill
);
3960 demand_empty_rest_of_line ();
3967 demand_empty_rest_of_line ();
3970 /* s_space is defined in read.c .skip is simply an alias to it. */
3975 * Invocation line includes a switch not recognized by the base assembler.
3976 * See if it's a processor-specific option. These are:
3978 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3979 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3980 * Select the architecture. Instructions or features not
3981 * supported by the selected architecture cause fatal
3982 * errors. More than one may be specified. The default is
3983 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3984 * for -m68000, and -m68882 is a synonym for -m68881.
3985 * -[A]m[c]no-68851, -[A]m[c]no-68881
3986 * Don't accept 688?1 instructions. (The "c" is kind of silly,
3987 * so don't use or document it, but that's the way the parsing
3990 * -pic Indicates PIC.
3991 * -k Indicates PIC. (Sun 3 only.)
3996 CONST
char *md_shortopts
= "lSA:m:kQ:V";
3998 CONST
char *md_shortopts
= "lSA:m:k";
4001 struct option md_longopts
[] = {
4002 #define OPTION_PIC (OPTION_MD_BASE)
4003 {"pic", no_argument
, NULL
, OPTION_PIC
},
4004 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
4005 {"register-prefix-optional", no_argument
, NULL
,
4006 OPTION_REGISTER_PREFIX_OPTIONAL
},
4007 {NULL
, no_argument
, NULL
, 0}
4009 size_t md_longopts_size
= sizeof(md_longopts
);
4012 md_parse_option (c
, arg
)
4018 case 'l': /* -l means keep external to 2 bit offset
4019 rather than 16 bit one */
4020 flag_short_refs
= 1;
4023 case 'S': /* -S means that jbsr's always turn into
4025 flag_long_jumps
= 1;
4031 /* intentional fall-through */
4034 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
4038 const char *oarg
= arg
;
4044 if (arg
[0] == 'c' && arg
[1] == '6')
4047 for (i
= 0; i
< n_archs
; i
++)
4048 if (!strcmp (arg
, archs
[i
].name
))
4053 as_bad ("unrecognized option `%s'", oarg
);
4056 arch
= archs
[i
].arch
;
4059 else if (arch
== m68851
)
4068 if (arg
[0] == 'c' && arg
[1] == '6')
4071 for (i
= 0; i
< n_archs
; i
++)
4072 if (!strcmp (arg
, archs
[i
].name
))
4074 unsigned long arch
= archs
[i
].arch
;
4075 if (cpu_of_arch (arch
))
4076 /* It's a cpu spec. */
4078 current_architecture
&= ~m68000up
;
4079 current_architecture
|= arch
;
4081 else if (arch
== m68881
)
4083 current_architecture
|= m68881
;
4086 else if (arch
== m68851
)
4088 current_architecture
|= m68851
;
4098 as_bad ("unrecognized architecture specification `%s'", arg
);
4107 break; /* -pic, Position Independent Code */
4109 case OPTION_REGISTER_PREFIX_OPTIONAL
:
4110 flag_reg_prefix_optional
= 1;
4125 md_show_usage (stream
)
4130 -l use 1 word for refs to undefined symbols [default 2]\n\
4131 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
4132 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
4134 specify variant of 680X0 architecture [default 68020]\n\
4135 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
4136 target has/lacks floating-point coprocessor\n\
4137 [default yes for 68020, 68030, and cpu32]\n\
4138 -m68851 | -mno-68851\n\
4139 target has/lacks memory-management unit coprocessor\n\
4140 [default yes for 68020 and up]\n\
4141 -pic, -k generate position independent code\n\
4142 -S turn jbsr into jsr\n\
4143 --register-prefix-optional\n\
4144 recognize register names without prefix character\n");
4149 /* TEST2: Test md_assemble() */
4150 /* Warning, this routine probably doesn't work anymore */
4154 struct m68k_it the_ins
;
4162 if (!gets (buf
) || !*buf
)
4164 if (buf
[0] == '|' || buf
[1] == '.')
4166 for (cp
= buf
; *cp
; cp
++)
4171 memset (&the_ins
, '\0', sizeof (the_ins
));
4172 m68k_ip (&the_ins
, buf
);
4175 printf ("Error %s in %s\n", the_ins
.error
, buf
);
4179 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
4180 for (n
= 0; n
< the_ins
.numo
; n
++)
4181 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
4183 print_the_insn (&the_ins
.opcode
[0], stdout
);
4184 (void) putchar ('\n');
4186 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
4188 if (the_ins
.operands
[n
].error
)
4190 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
4193 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
4194 if (the_ins
.operands
[n
].b_const
)
4195 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
4196 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
4197 if (the_ins
.operands
[n
].b_iadd
)
4198 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
4199 (void) putchar ('\n');
4211 while (*str
&& *str
!= ' ')
4213 if (str
[-1] == ':' || str
[1] == '=')
4220 /* Possible states for relaxation:
4222 0 0 branch offset byte (bra, etc)
4226 1 0 indexed offsets byte a0@(32,d4:w:1) etc
4230 2 0 two-offset index word-word a0@(32,d4)@(45) etc
4237 /* We have no need to default values of symbols. */
4241 md_undefined_symbol (name
)
4247 /* Round up a section size to the appropriate boundary. */
4249 md_section_align (segment
, size
)
4253 return size
; /* Byte alignment is fine */
4256 /* Exactly what point is a PC-relative offset relative TO?
4257 On the 68k, it is relative to the address of the first extension
4258 word. The difference between the addresses of the offset and the
4259 first extension word is stored in fx_pcrel_adjust. */
4261 md_pcrel_from (fixP
)
4264 return (fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- fixP
->fx_pcrel_adjust
);
4267 #ifndef BFD_ASSEMBLER
4270 tc_coff_symbol_emit_hook (ignore
)
4276 tc_coff_sizemachdep (frag
)
4279 switch (frag
->fr_subtype
& 0x3)
4294 /* end of tc-m68k.c */