1 /* All the m68k specific stuff in one convenient, huge, slow to
2 compile, easy to find file.
4 Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* The opcode table is too big for some versions of gcc, which require
28 exponential(?) space at compile time for initialized arrays. */
30 #define DO_BREAK_UP_BIG_DECL
31 #define BREAK_UP_BIG_DECL }; struct m68k_opcode m68k_opcodes_2[] = {
32 #define AND_OTHER_PART sizeof (m68k_opcodes_2)
35 /* Note that this file includes real declarations and thus can only be
36 included by one source file per executable. */
37 #include "opcode/m68k.h"
39 /* This array holds the chars that always start a comment. If the
40 pre-processor is disabled, these aren't very useful */
41 CONST
char comment_chars
[] = "|";
43 /* This array holds the chars that only start a comment at the beginning of
44 a line. If the line seems to have the form '# 123 filename'
45 .line and .file directives will appear in the pre-processed output */
46 /* Note that input_file.c hand checks for '#' at the beginning of the
47 first line of the input file. This is because the compiler outputs
48 #NO_APP at the beginning of its output. */
49 /* Also note that comments like this one will always work. */
50 CONST
char line_comment_chars
[] = "#";
52 CONST
char line_separator_chars
[] = "";
54 /* Chars that can be used to separate mant from exp in floating point nums */
55 CONST
char EXP_CHARS
[] = "eE";
57 /* Chars that mean this number is a floating point constant, as
58 in "0f12.456" or "0d1.2345e12". */
60 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
62 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
63 changed in read.c . Ideally it shouldn't have to know about it at all,
64 but nothing is ideal around here. */
66 const int md_reloc_size
= 8; /* Size of relocation record */
68 /* Are we trying to generate PIC code? If so, absolute references
69 ought to be made into linkage table references or pc-relative
73 static int flag_short_refs
; /* -l option */
74 static int flag_long_jumps
; /* -S option */
76 #ifdef REGISTER_PREFIX_OPTIONAL
77 int flag_reg_prefix_optional
= REGISTER_PREFIX_OPTIONAL
;
79 int flag_reg_prefix_optional
;
82 /* Its an arbitrary name: This means I don't approve of it */
83 /* See flames below */
84 static struct obstack robyn
;
86 #define TAB(x,y) (((x)<<2)+(y))
87 #define TABTYPE(xy) ((xy) >> 2)
103 unsigned long m_opcode
;
107 struct m68k_incant
*m_next
;
110 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
111 #define gettwo(x) (((x)->m_opcode)&0xffff)
113 /* Operands we can parse: (And associated modes)
119 reg: address or data register
120 areg: address register
121 apc: address register, PC, ZPC or empty string
122 num: 16 or 32 bit num
124 sz: w or l if omitted, l assumed
125 scale: 1 2 4 or 8 if omitted, 1 assumed
127 7.4 IMMED #num --> NUM
128 0.? DREG dreg --> dreg
129 1.? AREG areg --> areg
130 2.? AINDR areg@ --> *(areg)
131 3.? AINC areg@+ --> *(areg++)
132 4.? ADEC areg@- --> *(--areg)
133 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
134 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
135 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
136 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
137 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
138 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
139 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
140 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
141 7.0 ABSL num:sz --> *(num)
142 num --> *(num) (sz L assumed)
143 *** MSCR otherreg --> Magic
145 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
146 ?.? DINDR dreg@ --> (dreg) -- cas2 only
156 a1@(5,d2:w:1) @(45,d6:l:4)
161 #name@(numw) -->turn into PC rel mode
162 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
192 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
195 /* DATA and ADDR have to be contiguous, so that reg-DATA gives
196 0-7==data reg, 8-15==addr reg for operands that take both types.
198 We don't use forms like "ADDR0 = ADDR" here because this file is
199 likely to be used on an Apollo, and the broken Apollo compiler
200 gives an `undefined variable' error if we do that, according to
201 troy@cbme.unsw.edu.au. */
213 DATA0
= 1, /* 1- 8 == data registers 0-7 */
231 FP0
, /* Eight FP registers */
240 /* Note that COP0==processor #1 -- COP0+7==#8, which stores as 000 */
243 COP0
, /* Co-processor #1-#8 */
252 PC
, /* Program counter */
253 ZPC
, /* Hack for Program space, but 0 addressing */
255 CCR
, /* Condition code Reg */
257 /* These have to be grouped together for the movec instruction to work. */
258 USP
, /* User Stack Pointer */
259 ISP
, /* Interrupt stack pointer */
274 BUSCR
, /* 68060 added these */
276 #define last_movec_reg PCR
277 /* end of movec ordering constraints */
283 DRP
, /* 68851 or 68030 MMU regs */
305 PSR
, /* aka MMUSR on 68030 (but not MMUSR on 68040)
306 and ACUSR on 68ec030 */
309 IC
, /* instruction cache token */
310 DC
, /* data cache token */
311 NC
, /* no cache token */
312 BC
, /* both caches token */
314 TT0
, /* 68030 access control unit regs */
318 static const enum _register m68000_control_regs
[] = { 0 };
319 static const enum _register m68010_control_regs
[] = {
323 static const enum _register m68020_control_regs
[] = {
324 SFC
, DFC
, USP
, VBR
, CACR
, CAAR
, MSP
, ISP
,
327 static const enum _register m68040_control_regs
[] = {
328 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
,
329 USP
, VBR
, MSP
, ISP
, MMUSR
, URP
, SRP
,
332 static const enum _register m68060_control_regs
[] = {
333 SFC
, DFC
, CACR
, TC
, ITT0
, ITT1
, DTT0
, DTT1
, BUSCR
,
334 USP
, VBR
, URP
, SRP
, PCR
,
337 #define cpu32_control_regs m68010_control_regs
339 static const enum _register
*control_regs
;
341 /* Internal form of an operand. */
344 char *error
; /* Couldn't parse it */
345 enum operand_type mode
; /* What mode this instruction is in. */
346 enum _register reg
; /* Base register */
347 struct m68k_exp
*con1
;
348 int ireg
; /* Index register */
349 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
350 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
351 struct m68k_exp
*con2
;
354 /* internal form of a 68020 instruction */
358 char *args
; /* list of opcode info */
361 int numo
; /* Number of shorts in opcode */
364 struct m68k_op operands
[6];
366 int nexp
; /* number of exprs in use */
367 struct m68k_exp exprs
[4];
369 int nfrag
; /* Number of frags we have to produce */
372 int fragoff
; /* Where in the current opcode[] the frag ends */
379 int nrel
; /* Num of reloc strucs in use */
387 reloc
[5]; /* Five is enough??? */
390 #define cpu_of_arch(x) ((x) & m68000up)
391 #define float_of_arch(x) ((x) & mfloat)
392 #define mmu_of_arch(x) ((x) & mmmu)
394 static struct m68k_it the_ins
; /* the instruction being assembled */
396 #define seg(exp) ((exp)->e_seg)
397 #define op(exp) ((exp)->e_exp.X_op)
398 #define adds(exp) ((exp)->e_exp.X_add_symbol)
399 #define subs(exp) ((exp)->e_exp.X_op_symbol)
400 #define offs(exp) ((exp)->e_exp.X_add_number)
402 /* Macros for adding things to the m68k_it struct */
404 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
406 /* Like addword, but goes BEFORE general operands */
410 struct m68k_incant
*opcode
;
413 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
414 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
415 for(z
=0;z
<the_ins
.nrel
;z
++)
416 the_ins
.reloc
[z
].n
+=2;
417 the_ins
.opcode
[opcode
->m_codenum
]=w
;
421 static struct m68k_exp
*
426 the_ins
.exprs
[the_ins
.nexp
].e_beg
=beg
;
427 the_ins
.exprs
[the_ins
.nexp
].e_end
=end
;
428 return &the_ins
.exprs
[the_ins
.nexp
++];
432 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
435 add_fix (width
, exp
, pc_rel
)
437 struct m68k_exp
*exp
;
440 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
443 ? ((the_ins
.numo
-1)*2)
444 : (the_ins
.numo
*2)));
445 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->e_exp
;
446 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
447 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
451 add_frag(add
,off
,type
)
456 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
457 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
458 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
459 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
463 ((exp) && op (exp) != O_constant && op (exp) != O_big)
465 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
466 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
467 static int get_regs
PARAMS ((int i
, char *str
, struct m68k_op
*opP
));
468 static int reverse_16_bits
PARAMS ((int in
));
469 static int reverse_8_bits
PARAMS ((int in
));
470 static int try_index
PARAMS ((char **s
, struct m68k_op
*opP
));
471 static void install_gen_operand
PARAMS ((int mode
, int val
));
472 static void install_operand
PARAMS ((int mode
, int val
));
473 static void s_bss
PARAMS ((int));
474 static void s_data1
PARAMS ((int));
475 static void s_data2
PARAMS ((int));
476 static void s_even
PARAMS ((int));
477 static void s_proc
PARAMS ((int));
479 static int current_architecture
;
486 static const struct m68k_cpu archs
[] = {
496 /* Aliases (effectively, so far as gas is concerned) for the above
508 static const int n_archs
= sizeof (archs
) / sizeof (archs
[0]);
510 /* BCC68000 is for patching in an extra jmp instruction for long offsets
511 on the 68000. The 68000 doesn't support long branches with branchs */
513 /* This table desribes how you change sizes for the various types of variable
514 size expressions. This version only supports two kinds. */
516 /* Note that calls to frag_var need to specify the maximum expansion
517 needed; this is currently 10 bytes for DBCC. */
520 How far Forward this mode will reach:
521 How far Backward this mode will reach:
522 How many bytes this mode will add to the size of the frag
523 Which mode to go to if the offset won't fit in this one
525 CONST relax_typeS md_relax_table
[] =
527 {1, 1, 0, 0}, /* First entries aren't used */
528 {1, 1, 0, 0}, /* For no good reason except */
529 {1, 1, 0, 0}, /* that the VAX doesn't either */
532 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
533 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
537 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
538 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
542 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
543 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
547 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
548 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
549 {0, 0, 6, 0}, /* jmp long space */
552 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
553 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
554 {0, 0, 10, 0}, /* bra/jmp long space */
557 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
558 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
564 /* These are the machine dependent pseudo-ops. These are included so
565 the assembler can work on the output from the SUN C compiler, which
569 /* This table describes all the machine specific pseudo-ops the assembler
570 has to support. The fields are:
571 pseudo-op name without dot
572 function to call to execute this pseudo-op
573 Integer arg to pass to the function
575 CONST pseudo_typeS md_pseudo_table
[] =
577 {"data1", s_data1
, 0},
578 {"data2", s_data2
, 0},
581 {"skip", s_space
, 0},
584 {"align", s_align_bytes
, 0},
590 /* The mote pseudo ops are put into the opcode table, since they
591 don't start with a . they look like opcodes to gas.
593 extern void obj_coff_section ();
595 CONST pseudo_typeS mote_pseudo_table
[] =
608 {"xdef", s_globl
, 0},
609 {"align", s_align_ptwo
, 0},
611 {"sect", obj_coff_section
, 0},
612 {"section", obj_coff_section
, 0},
617 #define issbyte(x) ((x)>=-128 && (x)<=127)
618 #define isubyte(x) ((x)>=0 && (x)<=255)
619 #define issword(x) ((x)>=-32768 && (x)<=32767)
620 #define isuword(x) ((x)>=0 && (x)<=65535)
622 #define isbyte(x) ((x)>= -255 && (x)<=255)
623 #define isword(x) ((x)>=-32768 && (x)<=65535)
624 #define islong(x) (1)
626 extern char *input_line_pointer
;
634 static char mklower_table
[256];
635 #define mklower(c) (mklower_table[(unsigned char)(c)])
636 static char notend_table
[256];
637 static char alt_notend_table
[256];
638 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
639 alt_notend_table[(unsigned char)(s[1])])))
641 /* JF modified this to handle cases where the first part of a symbol name
642 looks like a register */
645 * m68k_reg_parse() := if it looks like a register, return it's token &
646 * advance the pointer.
658 if (flag_reg_prefix_optional
)
660 if (*start
== REGISTER_PREFIX
)
666 if (*start
!= REGISTER_PREFIX
)
671 if (!isalpha (*p
) || !is_name_beginner (*p
))
675 while (isalpha (c
) || isdigit (c
) || c
== '_')
681 symbolP
= symbol_find (start
);
684 if (symbolP
&& S_GET_SEGMENT (symbolP
) == reg_section
)
687 return S_GET_VALUE (symbolP
);
693 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
694 #define SKIP_W() { ss++; if(*ss==' ') ss++;}
696 /* Parse an index specification using Motorola syntax. */
699 try_moto_index (s
, opP
)
710 i
= m68k_reg_parse (&ss
);
711 if (!(i
>= DATA
+ 0 && i
<= ADDR
+ 7))
712 { /* if i is not DATA or ADDR reg */
713 opP
->error
= "Invalid index register";
729 opP
->error
= "Missing . in index register";
734 if (mklower (*ss
) == 'w')
736 else if (mklower (*ss
) == 'l')
740 opP
->error
= "Size spec not .W or .L";
745 if (*ss
== '.' || *ss
== '*')
754 opP
->imul
= *ss
- '0';
757 opP
->error
= "index multiplier not 1, 2, 4 or 8";
767 opP
->error
= "Missing )";
778 * try_index := data_or_address_register + ')' + SKIP_W
779 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
781 * multiplier := <empty>
782 * | ':' + multiplier_number
785 * multiplier_number := '1' | '2' | '4' | '8' ;
787 * size_spec := 'l' | 'L' | 'w' | 'W' ;
789 * SKIP_W := <empty> | ' ' ;
803 i
= m68k_reg_parse (&ss
);
804 if (!(i
>= DATA
+ 0 && i
<= ADDR
+ 7))
805 { /* if i is not DATA or ADDR reg */
821 opP
->error
= "Missing : in index register";
837 opP
->error
= "Index register size spec not :w or :l";
851 if (cpu_of_arch (current_architecture
) < m68020
)
853 opP
->error
= "no index scaling in pre-68020's";
857 opP
->imul
= *ss
- '0';
860 opP
->error
= "index multiplier not 1, 2, 4 or 8";
870 opP
->error
= "Missing )";
879 /* Ian Taylor expanded this function to accept both MIT and Motorola
880 syntax. I removed the old comment, since it was wrong. The syntax
881 this accepted even before my changes was complex and undocumented.
882 I mainly added a large case when the operand string does not
883 contain an '@', since the Motorola syntax does not use the '@'
887 m68k_ip_op (str
, opP
)
889 register struct m68k_op
*opP
;
893 char *parse_index ();
899 } /* Find the beginning of the string */
903 opP
->error
= "Missing operand";
907 for (strend
= str
; *strend
; strend
++)
911 if (*str
== '#' || *str
== '&')
914 opP
->con1
= add_exp (str
, strend
);
917 } /* Guess what: A constant. Shar and enjoy */
919 i
= m68k_reg_parse (&str
);
923 if (*str
== '/' || *str
== '-')
925 /* "Rm-Rn/Ro-Rp" Register list for MOVEM instruction */
927 return get_regs (i
, str
, opP
);
932 /* "Rn" Register Direct mode */
933 if (i
>= DATA
+ 0 && i
<= DATA
+ 7)
935 else if (i
>= ADDR
+ 0 && i
<= ADDR
+ 7)
947 if ((stmp
= strchr (str
, '@')) != 0)
949 opP
->con1
= add_exp (str
, stmp
- 1);
956 if ((current_architecture
& m68020up
) == 0)
959 } /* if target is not a '20 or better */
962 if (*stmp
++ != '(' || *strend
-- != ')')
964 opP
->error
= "Malformed operand";
967 i
= try_index (&stmp
, opP
);
968 opP
->con2
= add_exp (stmp
, strend
);
979 } /* if there's an '@' */
981 #ifndef MIT_SYNTAX_ONLY
982 /* The operand has no '@'. Try to parse it using
984 /* Logic of the parsing switch(*str):
988 REG AREG or DREG or MSCR 3 or 2 or 13
989 REG- or REG/ REGLST 14
994 (EXPR,REG,INDX) AINDX 8
997 EXP2(REG,INDX) AINDX 8
1000 REG means truth(m68k_reg_parse(&str))
1001 INDX means truth(try_moto_index(&str,opP))
1003 EXP2 means not REG and not '(' and not '-('
1009 i
= m68k_reg_parse (&str
);
1010 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7)
1011 && (i
< DATA
+ 0 || i
> DATA
+ 7
1012 || *str
!= ')' || str
[1] != '0')
1013 && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
)
1015 /* Can't indirect off non address regs */
1016 opP
->error
= "Invalid indirect register";
1027 /* "(An)" Address Register Indirect mode
1028 or "(Dn)" for cas2. */
1029 if (i
>= DATA
+ 0 && i
<= DATA
+ 7)
1039 /* "(An)+" Register Indirect w Postincrement */
1044 opP
->error
= "Junk after indirect";
1050 i
= try_moto_index (&str
, opP
);
1053 /* "(An,Rn)" Register Indirect with Index mode*/
1059 opP
->error
= "Bad indirect syntax";
1065 /* "(EXPR,..." , a displacement */
1068 if ((stmp
= strchr (str
, ',')) != NULL
)
1070 opP
->con1
= add_exp (str
, stmp
- 1);
1073 i
= m68k_reg_parse (&str
);
1074 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
)
1076 /* Can't indirect off non address regs */
1077 opP
->error
= "Invalid indirect register";
1085 /* "(d,An)" Register Indirect w Displacement */
1092 i
= try_moto_index (&str
, opP
);
1095 /* "(d,An,Rn)" Register Indirect with Index */
1101 opP
->error
= "Bad indirect syntax";
1107 opP
->error
= "Invalid register";
1114 opP
->con1
= add_exp (str
- 1, strend
);
1125 i
= m68k_reg_parse (&str
);
1126 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
)
1128 /* Can't indirect off non address regs */
1129 opP
->error
= "Invalid indirect register";
1140 /* "-(An)" Register Indirect with Predecrement */
1144 opP
->error
= "Junk after indirect";
1147 opP
->error
= "Bad indirect syntax";
1151 opP
->con1
= add_exp (str
- 2, strend
);
1154 /* if '-' but not "-(', do nothing */
1157 /* whether *str=='-' or not */
1159 /* "EXP2" or "EXP2(REG..." */
1161 if ((stmp
= strchr (str
, '(')) != NULL
)
1165 opP
->con1
= add_exp (str
, stmp
- 1);
1167 i
= m68k_reg_parse (&str
);
1168 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
1169 && i
!= ZPC
&& i
!= FAIL
)
1171 /* Can't indirect off non address regs */
1172 opP
->error
= "Invalid indirect register";
1180 /* "d(An)" Register Indirect w Displacement */
1187 i
= try_moto_index (&str
, opP
);
1190 /* "d(An,Rn)" Register Indirect with Index */
1196 opP
->error
= "Bad indirect syntax";
1203 opP
->con1
= add_exp (ostr
, strend
);
1209 /* "EXP2" Absolute */
1212 if (strend
[-1] == '.' || strend
[-1] == ':')
1214 /* mode ==foo.[wl] */
1227 opP
->con1
= add_exp (str
, strend
);
1232 #else /* defined (MIT_SYNTAX_ONLY) */
1234 opP
->con1
= add_exp (str
, strend
);
1236 #endif /* defined (MIT_SYNTAX_ONLY) */
1241 /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
1242 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
1243 && (str
[1] != '\0' || i
< DATA
+ 0 || i
> DATA
+ 7))
1245 opP
->error
= "Invalid indirect register";
1254 if (i
< DATA
+ 0 || i
> DATA
+ 7)
1269 opP
->error
= "Junk after indirect";
1272 /* Some kind of indexing involved. Lets find out how bad it is */
1273 i
= try_index (&str
, opP
);
1274 /* Didn't start with an index reg, maybe its offset or offset,reg */
1285 opP
->error
= "Missing )";
1298 opP
->con1
= add_exp (beg_str
, str
- 2);
1299 /* Should be offset,reg */
1302 i
= try_index (&str
, opP
);
1305 opP
->error
= "Malformed index reg";
1310 /* We've now got offset) offset,reg) or reg) */
1314 /* Th-the-thats all folks */
1315 if (opP
->reg
== FAIL
)
1316 opP
->mode
= AINDX
; /* Other form of indirect */
1317 else if (opP
->ireg
== FAIL
)
1323 /* Next thing had better be another @ */
1338 if ((current_architecture
& m68020up
) == 0)
1341 } /* if target is not a '20 or better */
1344 if (opP
->ireg
!= FAIL
)
1348 i
= try_index (&str
, opP
);
1351 opP
->error
= "Two index registers! not allowed!";
1357 i
= try_index (&str
, opP
);
1372 opP
->error
= "Missing )";
1387 opP
->con2
= add_exp (beg_str
, str
- 2);
1391 if (opP
->ireg
!= FAIL
)
1393 opP
->error
= "Can't have two index regs";
1397 i
= try_index (&str
, opP
);
1401 opP
->error
= "malformed index reg";
1407 else if (opP
->ireg
!= FAIL
)
1423 opP
->error
= "Junk after indirect";
1430 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
1432 #ifdef NO_PCREL_RELOCS
1435 make_pcrel_absolute(fixP
, add_number
)
1439 register unsigned char *opcode
= fixP
->fx_frag
->fr_opcode
;
1441 /* rewrite the PC relative instructions to absolute address ones.
1442 * these are rumoured to be faster, and the apollo linker refuses
1443 * to deal with the PC relative relocations.
1445 if (opcode
[0] == 0x60 && opcode
[1] == 0xff) /* BRA -> JMP */
1450 else if (opcode
[0] == 0x61 && opcode
[1] == 0xff) /* BSR -> JSR */
1456 as_fatal ("Unknown PC relative instruction");
1461 #endif /* NO_PCREL_RELOCS */
1464 tc_coff_fix2rtype (fixP
)
1467 #ifdef NO_PCREL_RELOCS
1468 know (fixP
->fx_pcrel
== 0);
1469 return (fixP
->fx_size
== 1 ? R_RELBYTE
1470 : fixP
->fx_size
== 2 ? R_DIR16
1473 return (fixP
->fx_pcrel
?
1474 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
1475 fixP
->fx_size
== 2 ? R_PCRWORD
:
1477 (fixP
->fx_size
== 1 ? R_RELBYTE
:
1478 fixP
->fx_size
== 2 ? R_RELWORD
:
1485 #ifdef BFD_ASSEMBLER
1488 tc_gen_reloc (section
, fixp
)
1493 bfd_reloc_code_real_type code
;
1495 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1496 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1498 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1499 MAP (1, 0, BFD_RELOC_8
);
1500 MAP (2, 0, BFD_RELOC_16
);
1501 MAP (4, 0, BFD_RELOC_32
);
1502 MAP (1, 1, BFD_RELOC_8_PCREL
);
1503 MAP (2, 1, BFD_RELOC_16_PCREL
);
1504 MAP (4, 1, BFD_RELOC_32_PCREL
);
1509 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
1510 assert (reloc
!= 0);
1511 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1512 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1514 reloc
->addend
= fixp
->fx_addnumber
;
1518 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1519 assert (reloc
->howto
!= 0);
1524 #endif /* BFD_ASSEMBLER */
1526 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1530 struct m68k_op thark
;
1536 memset (&thark
, '\0', sizeof (thark
));
1537 if (!m68k_ip_op (buf
, &thark
))
1540 printf ("op1 error %s in %s\n", thark
.error
, buf
);
1541 printf ("mode %d, reg %d, ", thark
.mode
, thark
.reg
);
1543 printf ("Constant: '%.*s',", 1 + thark
.e_const
- thark
.b_const
, thark
.b_const
);
1544 printf ("ireg %d, isiz %d, imul %d ", thark
.ireg
, thark
.isiz
, thark
.imul
);
1546 printf ("Iadd: '%.*s'", 1 + thark
.e_iadd
- thark
.b_iadd
, thark
.b_iadd
);
1549 exit (EXIT_SUCCESS
);
1555 /* Handle of the OPCODE hash table. NULL means any use before
1556 m68k_ip_begin() will crash. */
1557 static struct hash_control
*op_hash
;
1563 * This converts a string into a 68k instruction.
1564 * The string must be a bare single instruction in sun format
1565 * with RMS-style 68020 indirects
1568 * It provides some error messages: at most one fatal error message (which
1569 * stops the scan) and at most one warning message for each operand.
1570 * The 68k instruction is returned in exploded form, since we have no
1571 * knowledge of how you parse (or evaluate) your expressions.
1572 * We do however strip off and decode addressing modes and operation
1575 * This function's value is a string. If it is not "" then an internal
1576 * logic error was found: read this code to assign meaning to the string.
1577 * No argument string should generate such an error string:
1578 * it means a bug in our code, not in the user's text.
1580 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1584 /* JF this function no longer returns a useful value. Sorry */
1590 register struct m68k_op
*opP
;
1591 register struct m68k_incant
*opcode
;
1593 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1594 char *pdot
, *pdotmove
;
1599 char *crack_operand ();
1600 LITTLENUM_TYPE words
[6];
1601 LITTLENUM_TYPE
*wordp
;
1602 unsigned long ok_arch
= 0;
1604 if (*instring
== ' ')
1605 instring
++; /* skip leading whitespace */
1607 /* Scan up to end of operation-code, which MUST end in end-of-string
1608 or exactly 1 space. */
1610 for (p
= instring
; *p
!= '\0'; p
++)
1620 the_ins
.error
= "No operator";
1621 the_ins
.opcode
[0] = 0;
1622 /* the_ins.numo=1; */
1626 /* p now points to the end of the opcode name, probably whitespace.
1627 make sure the name is null terminated by clobbering the whitespace,
1628 look it up in the hash table, then fix it back.
1629 Remove a dot, first, since the opcode tables have none. */
1632 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1633 *pdotmove
= pdotmove
[1];
1639 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
1644 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1645 *pdotmove
= pdotmove
[-1];
1652 the_ins
.error
= "Unknown operator";
1653 the_ins
.opcode
[0] = 0;
1654 /* the_ins.numo=1; */
1658 /* found a legitimate opcode, start matching operands */
1663 if (opcode
->m_operands
== 0)
1665 char *old
= input_line_pointer
;
1667 input_line_pointer
= p
;
1668 /* Ahh - it's a motorola style psuedo op */
1669 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1670 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1671 input_line_pointer
= old
;
1677 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1680 p
= crack_operand (p
, opP
);
1684 the_ins
.error
= opP
->error
;
1689 opsfound
= opP
- &the_ins
.operands
[0];
1691 /* This ugly hack is to support the floating pt opcodes in their standard form */
1692 /* Essentially, we fake a first enty of type COP#1 */
1693 if (opcode
->m_operands
[0] == 'I')
1697 for (n
= opsfound
; n
> 0; --n
)
1698 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1700 memset ((char *) (&the_ins
.operands
[0]), '\0', sizeof (the_ins
.operands
[0]));
1701 the_ins
.operands
[0].mode
= MSCR
;
1702 the_ins
.operands
[0].reg
= COPNUM
; /* COP #1 */
1706 /* We've got the operands. Find an opcode that'll accept them */
1709 /* If we didn't get the right number of ops, or we have no
1710 common model with this pattern then reject this pattern. */
1712 if (opsfound
!= opcode
->m_opnum
1713 || ((opcode
->m_arch
& current_architecture
) == 0))
1716 ok_arch
|= opcode
->m_arch
;
1720 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++)
1722 /* Warning: this switch is huge! */
1723 /* I've tried to organize the cases into this order:
1724 non-alpha first, then alpha by letter. Lower-case
1725 goes directly before uppercase counterpart. */
1726 /* Code with multiple case ...: gets sorted by the lowest
1727 case ... it belongs to. I hope this makes sense. */
1731 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1732 || opP
->mode
== DREG
|| opP
->mode
== AREG
1733 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1734 || opP
->mode
== REGLST
)
1756 if (opP
->mode
!= IMMED
)
1762 t
= get_num (opP
->con1
, 80);
1763 if (s
[1] == 'b' && !isbyte (t
))
1765 else if (s
[1] == 'w' && !isword (t
))
1772 if (opP
->mode
!= IMMED
)
1777 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1778 opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1783 if (opP
->mode
== MSCR
|| opP
->reg
== PC
||
1784 opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1790 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1791 opP
->mode
== AREG
|| opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
||
1792 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== REGLST
)
1797 if (opP
->mode
== MSCR
|| opP
->mode
== REGLST
)
1802 if (opP
->mode
!= AINC
)
1807 if (opP
->mode
!= ADEC
)
1812 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1813 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== IMMED
|| opP
->mode
== REGLST
)
1818 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
|| opP
->mode
== REGLST
)
1823 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1824 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== IMMED
|| opP
->reg
== PC
||
1825 opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1830 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1831 opP
->mode
== IMMED
|| opP
->mode
== REGLST
)
1835 case '~': /* For now! (JF FOO is this right?) */
1836 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1837 opP
->mode
== AREG
|| opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1842 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1847 if (opP
->mode
!= AREG
)
1851 if (opP
->mode
!= AINDR
)
1854 } /* if not address register indirect */
1857 if (opP
->mode
!= ABSL
|| (flag_long_jumps
&& instring
[0] == 'j'
1858 && instring
[1] == 'b'
1859 && instring
[2] == 's'
1860 && instring
[3] == 'r'))
1865 if (opP
->mode
!= MSCR
|| opP
->reg
!= CCR
)
1869 case 'd': /* FOO This mode is a KLUDGE!! */
1870 if (opP
->mode
!= AOFF
&& (opP
->mode
!= ABSL
||
1871 opP
->con1
->e_beg
[0] != '(' || opP
->con1
->e_end
[0] != ')'))
1876 if (opP
->mode
!= DREG
)
1881 if (opP
->mode
!= MSCR
|| opP
->reg
< (FPREG
+ 0) || opP
->reg
> (FPREG
+ 7))
1886 if (opP
->mode
!= MSCR
|| opP
->reg
< COPNUM
||
1887 opP
->reg
>= COPNUM
+ 7)
1892 if (opP
->mode
!= MSCR
1894 || opP
->reg
> last_movec_reg
)
1898 const enum _register
*rp
;
1899 for (rp
= control_regs
; *rp
; rp
++)
1900 if (*rp
== opP
->reg
)
1908 if (opP
->mode
!= IMMED
)
1914 if (opP
->mode
== DREG
|| opP
->mode
== AREG
|| opP
->mode
== FPREG
)
1921 opP
->reg
= 1 << (opP
->reg
- DATA
);
1924 else if (opP
->mode
!= REGLST
)
1928 else if (s
[1] == '8' && opP
->reg
& 0x0FFffFF)
1930 else if (s
[1] == '3' && opP
->reg
& 0x7000000)
1935 if (opP
->mode
!= IMMED
)
1941 t
= get_num (opP
->con1
, 0);
1943 || isvar (opP
->con1
))
1949 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1954 if (opP
->mode
!= IMMED
)
1960 t
= get_num (opP
->con1
, 80);
1961 if (t
< 1 || t
> 8 || isvar (opP
->con1
))
1967 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1972 if (opP
->mode
!= AINDR
&& opP
->mode
!= DINDR
)
1977 if (opP
->mode
!= MSCR
|| !(opP
->reg
== FPI
|| opP
->reg
== FPS
|| opP
->reg
== FPC
))
1982 if (opP
->mode
!= MSCR
|| opP
->reg
!= SR
)
1987 if (opP
->mode
!= IMMED
)
1991 long t
= get_num (opP
->con1
, 80);
1992 if (t
< 0 || t
> 7 || isvar (opP
->con1
))
1998 if (opP
->mode
!= MSCR
|| opP
->reg
!= USP
)
2002 /* JF these are out of order. We could put them
2003 in order if we were willing to put up with
2004 bunches of #ifdef m68851s in the code.
2006 Don't forget that you need these operands
2007 to use 68030 MMU instructions. */
2009 /* Memory addressing mode used by pflushr */
2011 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
2012 opP
->mode
== AREG
|| opP
->mode
== REGLST
)
2017 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
2022 if (opP
->mode
!= MSCR
2023 || (opP
->reg
!= TC
&& opP
->reg
!= CAL
2024 && opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
2029 if (opP
->reg
!= VAL
)
2034 if (opP
->mode
!= MSCR
2035 || (opP
->reg
!= DRP
&& opP
->reg
!= SRP
2036 && opP
->reg
!= CRP
))
2041 if (opP
->mode
!= MSCR
||
2042 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7) &&
2043 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
2048 if (opP
->reg
!= PSR
)
2053 if (opP
->reg
!= PCSR
)
2064 } /* not a cache specifier. */
2068 if (opP
->mode
!= ABSL
)
2071 } /* not absolute */
2075 as_fatal ("Internal error: Operand mode %c unknown in line %d of file \"%s\"",
2076 *s
, __LINE__
, __FILE__
);
2077 } /* switch on type of operand */
2081 } /* for each operand */
2082 } /* if immediately wrong */
2089 opcode
= opcode
->m_next
;
2094 && !(ok_arch
& current_architecture
))
2098 strcpy (buf
, "invalid instruction for this architecture; needs ");
2099 cp
= buf
+ strlen (buf
);
2103 strcpy (cp
, "fpu (68040, 68060 or 68881/68882)");
2106 strcpy (cp
, "mmu (68030 or 68851)");
2109 strcpy (cp
, "68020 or higher");
2112 strcpy (cp
, "68000 or higher");
2115 strcpy (cp
, "68010 or higher");
2119 int got_one
= 0, idx
;
2120 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]); idx
++)
2122 if (archs
[idx
].arch
& ok_arch
)
2126 strcpy (cp
, " or ");
2130 strcpy (cp
, archs
[idx
].name
);
2142 the_ins
.error
= "operands mismatch";
2144 } /* Fell off the end */
2149 /* now assemble it */
2151 the_ins
.args
= opcode
->m_operands
;
2152 the_ins
.numargs
= opcode
->m_opnum
;
2153 the_ins
.numo
= opcode
->m_codenum
;
2154 the_ins
.opcode
[0] = getone (opcode
);
2155 the_ins
.opcode
[1] = gettwo (opcode
);
2157 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2159 /* This switch is a doozy.
2160 Watch the first step; its a big one! */
2181 tmpreg
= 0x3c; /* 7.4 */
2182 if (strchr ("bwl", s
[1]))
2183 nextword
= get_num (opP
->con1
, 80);
2185 nextword
= get_num (opP
->con1
, 0);
2186 if (isvar (opP
->con1
))
2187 add_fix (s
[1], opP
->con1
, 0);
2191 if (!isbyte (nextword
))
2192 opP
->error
= "operand out of range";
2197 if (!isword (nextword
))
2198 opP
->error
= "operand out of range";
2203 addword (nextword
>> 16);
2225 as_fatal ("Internal error: Can't decode %c%c in line %d of file \"%s\"",
2226 *s
, s
[1], __LINE__
, __FILE__
);
2231 /* We gotta put out some float */
2232 if (op (opP
->con1
) != O_big
)
2237 /* Can other cases happen here? */
2238 if (op (opP
->con1
) != O_constant
)
2241 val
= (valueT
) offs (opP
->con1
);
2245 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2246 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2250 offs (opP
->con1
) = gencnt
;
2252 if (offs (opP
->con1
) > 0)
2254 if (offs (opP
->con1
) > baseo
)
2256 as_warn ("Bignum too big for %c format; truncated", s
[1]);
2257 offs (opP
->con1
) = baseo
;
2259 baseo
-= offs (opP
->con1
);
2262 for (wordp
= generic_bignum
+ offs (opP
->con1
) - 1; offs (opP
->con1
)--; --wordp
)
2266 gen_to_words (words
, baseo
, (long) outro
);
2267 for (wordp
= words
; baseo
--; wordp
++)
2271 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2274 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2277 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2280 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2283 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2287 nextword
= get_num (opP
->con1
, 80);
2288 /* Force into index mode. Hope this works */
2290 /* We do the first bit for 32-bit displacements, and the
2291 second bit for 16 bit ones. It is possible that we
2292 should make the default be WORD instead of LONG, but
2293 I think that'd break GCC, so we put up with a little
2294 inefficiency for the sake of working output. */
2296 if (!issword (nextword
)
2297 || (isvar (opP
->con1
)
2298 && ((opP
->con1
->e_siz
== 0
2299 && flag_short_refs
== 0
2300 && cpu_of_arch (current_architecture
) >= m68020
)
2301 || opP
->con1
->e_siz
== 3)))
2305 tmpreg
= 0x3B; /* 7.3 */
2307 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2308 if (isvar (opP
->con1
))
2313 opP
->con1
->e_exp
.X_add_number
+= 6;
2314 add_fix ('l', opP
->con1
, 1);
2315 addword (0), addword (0);
2321 add_fix ('l', opP
->con1
, 0);
2326 addword (nextword
>> 16);
2331 tmpreg
= 0x3A; /* 7.2 */
2333 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2335 if (isvar (opP
->con1
))
2339 opP
->con1
->e_exp
.X_add_number
+= 2;
2340 add_fix ('w', opP
->con1
, 1);
2343 add_fix ('w', opP
->con1
, 0);
2352 know (current_architecture
& m68020up
);
2353 /* intentional fall-through */
2356 baseo
= get_num (opP
->con1
, 80);
2357 outro
= get_num (opP
->con2
, 80);
2358 /* Figure out the `addressing mode'.
2359 Also turn on the BASE_DISABLE bit, if needed. */
2360 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2362 tmpreg
= 0x3b;/* 7.3 */
2363 if (opP
->reg
== ZPC
)
2366 else if (opP
->reg
== FAIL
)
2369 tmpreg
= 0x30;/* 6.garbage */
2372 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2374 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
2375 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
2377 /* Index register stuff */
2378 if (opP
->ireg
>= DATA
+ 0 && opP
->ireg
<= ADDR
+ 7)
2380 nextword
|= (opP
->ireg
- DATA
) << 12;
2382 if (opP
->isiz
== 0 || opP
->isiz
== 3)
2398 as_fatal ("failed sanity check.");
2401 GET US OUT OF HERE! */
2403 /* Must be INDEX, with an index
2404 register. Address register
2405 cannot be ZERO-PC, and either
2406 :b was forced, or we know
2408 if (opP
->mode
== AINDX
2412 || cpu_of_arch (current_architecture
) < m68020
2414 && !isvar (opP
->con1
))))
2416 nextword
+= baseo
& 0xff;
2418 if (isvar (opP
->con1
))
2419 add_fix ('B', opP
->con1
, 0);
2424 nextword
|= 0x40; /* No index reg */
2426 /* It isn't simple. */
2428 /* If the guy specified a width, we assume that it is
2429 wide enough. Maybe it isn't. If so, we lose. */
2433 if (isvar (opP
->con1
) || !issword (baseo
))
2438 else if (baseo
== 0)
2447 as_warn ("Byte dispacement won't work. Defaulting to :w");
2456 /* Figure out innner displacement stuff */
2457 if (opP
->mode
!= AINDX
)
2462 if (isvar (opP
->con2
) || !issword (outro
))
2467 else if (outro
== 0)
2476 as_warn ("Byte dispacement won't work. Defaulting to :w");
2484 if (opP
->mode
== APODX
)
2486 else if (opP
->mode
== AMIND
)
2491 if (isvar (opP
->con1
))
2493 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2495 opP
->con1
->e_exp
.X_add_number
+= 6;
2496 add_fix (siz1
== 3 ? 'l' : 'w', opP
->con1
, 1);
2499 add_fix (siz1
== 3 ? 'l' : 'w', opP
->con1
, 0);
2502 addword (baseo
>> 16);
2506 if (isvar (opP
->con2
))
2508 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2510 opP
->con1
->e_exp
.X_add_number
+= 6;
2511 add_fix (siz2
== 3 ? 'l' : 'w', opP
->con2
, 1);
2514 add_fix (siz2
== 3 ? 'l' : 'w', opP
->con2
, 0);
2517 addword (outro
>> 16);
2524 nextword
= get_num (opP
->con1
, 80);
2525 switch (opP
->con1
->e_siz
)
2528 as_warn ("Unknown size for absolute reference");
2530 if (!isvar (opP
->con1
) && issword (offs (opP
->con1
)))
2532 tmpreg
= 0x38; /* 7.0 */
2536 /* Don't generate pc relative code on 68010 and
2538 if (isvar (opP
->con1
)
2539 && !subs (opP
->con1
)
2540 && seg (opP
->con1
) == text_section
2541 && now_seg
== text_section
2542 && cpu_of_arch (current_architecture
) >= m68020
2544 && !strchr ("~%&$?", s
[0]))
2546 tmpreg
= 0x3A; /* 7.2 */
2547 add_frag (adds (opP
->con1
),
2549 TAB (PCREL
, SZ_UNDEF
));
2552 case 3: /* Fall through into long */
2553 if (isvar (opP
->con1
))
2554 add_fix ('l', opP
->con1
, 0);
2556 tmpreg
= 0x39;/* 7.1 mode */
2557 addword (nextword
>> 16);
2562 if (isvar (opP
->con1
))
2563 add_fix ('w', opP
->con1
, 0);
2565 tmpreg
= 0x38;/* 7.0 mode */
2571 as_bad ("invalid indirect register");
2575 as_bad ("unknown/incorrect operand");
2578 install_gen_operand (s
[1], tmpreg
);
2584 { /* JF: I hate floating point! */
2599 tmpreg
= get_num (opP
->con1
, tmpreg
);
2600 if (isvar (opP
->con1
))
2601 add_fix (s
[1], opP
->con1
, 0);
2604 case 'b': /* Danger: These do no check for
2605 certain types of overflow.
2607 if (!isbyte (tmpreg
))
2608 opP
->error
= "out of range";
2609 insop (tmpreg
, opcode
);
2610 if (isvar (opP
->con1
))
2611 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2614 if (!isword (tmpreg
))
2615 opP
->error
= "out of range";
2616 insop (tmpreg
, opcode
);
2617 if (isvar (opP
->con1
))
2618 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2621 /* Because of the way insop works, we put these two out
2623 insop (tmpreg
, opcode
);
2624 insop (tmpreg
>> 16, opcode
);
2625 if (isvar (opP
->con1
))
2626 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2632 install_operand (s
[1], tmpreg
);
2635 as_fatal ("Internal error: Unknown mode #%c in line %d of file \"%s\"", s
[1], __LINE__
, __FILE__
);
2643 install_operand (s
[1], opP
->reg
- ADDR
);
2647 tmpreg
= get_num (opP
->con1
, 80);
2651 /* Needs no offsetting */
2652 add_fix ('B', opP
->con1
, 1);
2655 /* Offset the displacement to be relative to byte disp location */
2656 opP
->con1
->e_exp
.X_add_number
+= 2;
2657 add_fix ('w', opP
->con1
, 1);
2662 if (cpu_of_arch (current_architecture
) < m68020
) /* 68000 or 010 */
2663 as_warn ("Can't use long branches on 68000/68010");
2664 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2665 /* Offset the displacement to be relative to byte disp location */
2666 opP
->con1
->e_exp
.X_add_number
+= 4;
2667 add_fix ('l', opP
->con1
, 1);
2672 if (subs (opP
->con1
)) /* We can't relax it */
2675 /* This could either be a symbol, or an
2676 absolute address. No matter, the
2677 frag hacking will finger it out.
2678 Not quite: it can't switch from
2679 BRANCH to BCC68000 for the case
2680 where opnd is absolute (it needs
2681 to use the 68000 hack since no
2682 conditional abs jumps). */
2683 if (((cpu_of_arch (current_architecture
) < m68020
)
2684 || (0 == adds (opP
->con1
)))
2685 && (the_ins
.opcode
[0] >= 0x6200)
2686 && (the_ins
.opcode
[0] <= 0x6f00))
2688 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (BCC68000
, SZ_UNDEF
));
2692 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (ABRANCH
, SZ_UNDEF
));
2696 if (isvar (opP
->con1
))
2699 /* check for DBcc instruction */
2700 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2702 /* size varies if patch */
2703 /* needed for long form */
2704 add_frag (adds (opP
->con1
), offs (opP
->con1
),
2705 TAB (DBCC
, SZ_UNDEF
));
2710 opP
->con1
->e_exp
.X_add_number
+= 2;
2711 add_fix ('w', opP
->con1
, 1);
2715 case 'C': /* Fixed size LONG coproc branches */
2716 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2717 /* Offset the displacement to be relative to byte disp location */
2718 /* Coproc branches don't have a byte disp option, but they are
2719 compatible with the ordinary branches, which do... */
2720 opP
->con1
->e_exp
.X_add_number
+= 4;
2721 add_fix ('l', opP
->con1
, 1);
2725 case 'c': /* Var size Coprocesssor branches */
2726 if (subs (opP
->con1
))
2728 add_fix ('l', opP
->con1
, 1);
2729 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2731 else if (adds (opP
->con1
))
2733 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (FBRANCH
, SZ_UNDEF
));
2737 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2738 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2739 add_fix ('l', opP
->con1
, 1);
2745 as_fatal ("Internal error: operand type B%c unknown in line %d of file \"%s\"",
2746 s
[1], __LINE__
, __FILE__
);
2750 case 'C': /* Ignore it */
2753 case 'd': /* JF this is a kludge */
2754 if (opP
->mode
== AOFF
)
2756 install_operand ('s', opP
->reg
- ADDR
);
2762 tmpP
= opP
->con1
->e_end
- 2;
2764 opP
->con1
->e_end
-= 4; /* point to the , */
2765 baseo
= m68k_reg_parse (&tmpP
);
2766 if (baseo
< ADDR
+ 0 || baseo
> ADDR
+ 7)
2768 as_bad ("Unknown address reg, using A0");
2773 install_operand ('s', baseo
);
2775 tmpreg
= get_num (opP
->con1
, 80);
2776 if (!issword (tmpreg
))
2778 as_warn ("Expression out of range, using 0");
2785 install_operand (s
[1], opP
->reg
- DATA
);
2789 install_operand (s
[1], opP
->reg
- FPREG
);
2793 tmpreg
= 1 + opP
->reg
- COPNUM
;
2796 install_operand (s
[1], tmpreg
);
2799 case 'J': /* JF foo */
2858 as_fatal ("failed sanity check.");
2860 install_operand (s
[1], tmpreg
);
2864 tmpreg
= get_num (opP
->con1
, 55);
2865 install_operand (s
[1], tmpreg
& 0x7f);
2872 if (tmpreg
& 0x7FF0000)
2873 as_bad ("Floating point register in register list");
2874 insop (reverse_16_bits (tmpreg
), opcode
);
2878 if (tmpreg
& 0x700FFFF)
2879 as_bad ("Wrong register in floating-point reglist");
2880 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2888 if (tmpreg
& 0x7FF0000)
2889 as_bad ("Floating point register in register list");
2890 insop (tmpreg
, opcode
);
2892 else if (s
[1] == '8')
2894 if (tmpreg
& 0x0FFFFFF)
2895 as_bad ("incorrect register in reglist");
2896 install_operand (s
[1], tmpreg
>> 24);
2900 if (tmpreg
& 0x700FFFF)
2901 as_bad ("wrong register in floating-point reglist");
2903 install_operand (s
[1], tmpreg
>> 16);
2908 install_operand (s
[1], get_num (opP
->con1
, 60));
2912 tmpreg
= (opP
->mode
== DREG
)
2913 ? 0x20 + opP
->reg
- DATA
2914 : (get_num (opP
->con1
, 40) & 0x1F);
2915 install_operand (s
[1], tmpreg
);
2919 tmpreg
= get_num (opP
->con1
, 10);
2922 install_operand (s
[1], tmpreg
);
2927 /* This depends on the fact that ADDR registers are
2928 eight more than their corresponding DATA regs, so
2929 the result will have the ADDR_REG bit set */
2930 install_operand (s
[1], opP
->reg
- DATA
);
2934 if (opP
->reg
== FPI
)
2936 else if (opP
->reg
== FPS
)
2938 else if (opP
->reg
== FPC
)
2941 as_fatal ("failed sanity check.");
2942 install_operand (s
[1], tmpreg
);
2945 case 'S': /* Ignore it */
2949 install_operand (s
[1], get_num (opP
->con1
, 30));
2952 case 'U': /* Ignore it */
2971 as_fatal ("failed sanity check");
2972 } /* switch on cache token */
2973 install_operand (s
[1], tmpreg
);
2976 /* JF: These are out of order, I fear. */
2987 as_fatal ("failed sanity check.");
2989 install_operand (s
[1], tmpreg
);
3011 as_fatal ("failed sanity check.");
3013 install_operand (s
[1], tmpreg
);
3017 if (opP
->reg
== VAL
)
3019 as_fatal ("failed sanity check.");
3035 as_fatal ("failed sanity check.");
3037 install_operand (s
[1], tmpreg
);
3051 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3062 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3066 as_fatal ("failed sanity check.");
3068 install_operand (s
[1], tmpreg
);
3071 know (opP
->reg
== PSR
);
3074 know (opP
->reg
== PCSR
);
3087 as_fatal ("failed sanity check");
3089 install_operand (s
[1], tmpreg
);
3092 tmpreg
= get_num (opP
->con1
, 20);
3093 install_operand (s
[1], tmpreg
);
3095 case '_': /* used only for move16 absolute 32-bit address */
3096 tmpreg
= get_num (opP
->con1
, 80);
3097 addword (tmpreg
>> 16);
3098 addword (tmpreg
& 0xFFFF);
3101 as_fatal ("Internal error: Operand type %c unknown in line %d of file \"%s\"",
3102 s
[0], __LINE__
, __FILE__
);
3106 /* By the time whe get here (FINALLY) the_ins contains the complete
3107 instruction, ready to be emitted. . . */
3111 * get_regs := '/' + ?
3112 * | '-' + <register>
3113 * | '-' + <register> + ?
3118 * The idea here must be to scan in a set of registers but I don't
3119 * understand it. Looks awfully sloppy to me but I don't have any doc on
3127 get_regs (i
, str
, opP
)
3129 struct m68k_op
*opP
;
3132 /* 26, 25, 24, 23-16, 15-8, 0-7 */
3133 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
3134 unsigned long cur_regs
= 0;
3137 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
3138 else if(x==FPS) cur_regs|=(1<<25);\
3139 else if(x==FPC) cur_regs|=(1<<26);\
3140 else cur_regs|=(1<<(x-1)); }
3150 else if (*str
== '-')
3153 reg2
= m68k_reg_parse (&str
);
3154 if (reg2
< DATA
|| reg2
>= FPREG
+ 8 || reg1
== FPI
|| reg1
== FPS
|| reg1
== FPC
)
3156 opP
->error
= "unknown register in register list";
3159 while (reg1
<= reg2
)
3167 else if (*str
== '\0')
3174 opP
->error
= "unknow character in register list";
3177 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
3180 reg1
= m68k_reg_parse (&str
);
3181 if ((reg1
< DATA
|| reg1
>= FPREG
+ 8) && !(reg1
== FPI
|| reg1
== FPS
|| reg1
== FPC
))
3183 opP
->error
= "unknown register in register list";
3187 opP
->reg
= cur_regs
;
3192 reverse_16_bits (in
)
3198 static int mask
[16] =
3200 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3201 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3203 for (n
= 0; n
< 16; n
++)
3206 out
|= mask
[15 - n
];
3209 } /* reverse_16_bits() */
3218 static int mask
[8] =
3220 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3223 for (n
= 0; n
< 8; n
++)
3229 } /* reverse_8_bits() */
3232 install_operand (mode
, val
)
3239 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
3242 the_ins
.opcode
[0] |= val
<< 9;
3245 the_ins
.opcode
[1] |= val
<< 12;
3248 the_ins
.opcode
[1] |= val
<< 6;
3251 the_ins
.opcode
[1] |= val
;
3254 the_ins
.opcode
[2] |= val
<< 12;
3257 the_ins
.opcode
[2] |= val
<< 6;
3260 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3261 three words long! */
3263 the_ins
.opcode
[2] |= val
;
3266 the_ins
.opcode
[1] |= val
<< 7;
3269 the_ins
.opcode
[1] |= val
<< 10;
3273 the_ins
.opcode
[1] |= val
<< 5;
3278 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3281 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3284 the_ins
.opcode
[0] |= val
= 0xff;
3287 the_ins
.opcode
[0] |= val
<< 9;
3290 the_ins
.opcode
[1] |= val
;
3293 the_ins
.opcode
[1] |= val
;
3294 the_ins
.numo
++; /* What a hack */
3297 the_ins
.opcode
[1] |= val
<< 4;
3304 the_ins
.opcode
[0] |= (val
<< 6);
3307 the_ins
.opcode
[1] = (val
>> 16);
3308 the_ins
.opcode
[2] = val
& 0xffff;
3312 as_fatal ("failed sanity check.");
3314 } /* install_operand() */
3317 install_gen_operand (mode
, val
)
3324 the_ins
.opcode
[0] |= val
;
3327 /* This is a kludge!!! */
3328 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3337 the_ins
.opcode
[0] |= val
;
3339 /* more stuff goes here */
3341 as_fatal ("failed sanity check.");
3343 } /* install_gen_operand() */
3346 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3347 * then deal with the bitfield hack.
3351 crack_operand (str
, opP
)
3353 register struct m68k_op
*opP
;
3355 register int parens
;
3357 register char *beg_str
;
3364 for (parens
= 0; *str
&& (parens
> 0 || notend (str
)); str
++)
3368 else if (*str
== ')')
3372 opP
->error
= "Extra )";
3378 if (!*str
&& parens
)
3380 opP
->error
= "Missing )";
3385 if (m68k_ip_op (beg_str
, opP
) == FAIL
)
3392 c
= *++str
; /* JF bitfield hack */
3397 as_bad ("Missing operand");
3402 /* This is the guts of the machine-dependent assembler. STR points to a
3403 machine dependent instruction. This function is supposed to emit
3404 the frags/bytes it assembles to.
3408 insert_reg (regname
, regnum
)
3415 #ifdef REGISTER_PREFIX
3416 if (!flag_reg_prefix_optional
)
3418 buf
[0] = REGISTER_PREFIX
;
3419 strcpy (buf
+ 1, regname
);
3424 symbol_table_insert (symbol_new (regname
, reg_section
, regnum
,
3425 &zero_address_frag
));
3427 for (i
= 0; regname
[i
]; i
++)
3428 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3431 symbol_table_insert (symbol_new (buf
, reg_section
, regnum
,
3432 &zero_address_frag
));
3441 static const struct init_entry init_table
[] =
3545 /* 68ec030 versions of same */
3548 /* 68ec030 access control unit, identical to 030 MMU status reg */
3558 for (i
= 0; init_table
[i
].name
; i
++)
3559 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3562 static int no_68851
, no_68881
;
3565 /* a.out machine type. Default to 68020. */
3566 int m68k_aout_machtype
= 2;
3578 int shorts_this_frag
;
3580 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3585 for (n
= the_ins
.numargs
; n
; --n
)
3586 if (the_ins
.operands
[n
].error
)
3588 er
= the_ins
.operands
[n
].error
;
3594 as_bad ("%s -- statement `%s' ignored", er
, str
);
3598 if (the_ins
.nfrag
== 0)
3600 /* No frag hacking involved; just put it out */
3601 toP
= frag_more (2 * the_ins
.numo
);
3602 fromP
= &the_ins
.opcode
[0];
3603 for (m
= the_ins
.numo
; m
; --m
)
3605 md_number_to_chars (toP
, (long) (*fromP
), 2);
3609 /* put out symbol-dependent info */
3610 for (m
= 0; m
< the_ins
.nrel
; m
++)
3612 switch (the_ins
.reloc
[m
].wid
)
3630 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3631 the_ins
.reloc
[m
].wid
);
3634 fix_new_exp (frag_now
,
3635 ((toP
- frag_now
->fr_literal
)
3636 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3638 &the_ins
.reloc
[m
].exp
,
3639 the_ins
.reloc
[m
].pcrel
,
3645 /* There's some frag hacking */
3646 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3651 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3653 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3654 toP
= frag_more (wid
);
3656 shorts_this_frag
= 0;
3657 for (m
= wid
/ 2; m
; --m
)
3659 md_number_to_chars (toP
, (long) (*fromP
), 2);
3664 for (m
= 0; m
< the_ins
.nrel
; m
++)
3666 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3668 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3671 wid
= the_ins
.reloc
[m
].wid
;
3674 the_ins
.reloc
[m
].wid
= 0;
3675 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3677 fix_new_exp (frag_now
,
3678 ((toP
- frag_now
->fr_literal
)
3679 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3681 &the_ins
.reloc
[m
].exp
,
3682 the_ins
.reloc
[m
].pcrel
,
3685 (void) frag_var (rs_machine_dependent
, 10, 0,
3686 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3687 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3689 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3690 shorts_this_frag
= 0;
3693 toP
= frag_more (n
* sizeof (short));
3696 md_number_to_chars (toP
, (long) (*fromP
), 2);
3702 for (m
= 0; m
< the_ins
.nrel
; m
++)
3706 wid
= the_ins
.reloc
[m
].wid
;
3709 the_ins
.reloc
[m
].wid
= 0;
3710 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3712 fix_new_exp (frag_now
,
3713 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3714 - shorts_this_frag
* 2),
3716 &the_ins
.reloc
[m
].exp
,
3717 the_ins
.reloc
[m
].pcrel
,
3722 /* See BREAK_UP_BIG_DECL definition, above. */
3723 static const struct m68k_opcode
*
3727 #ifdef DO_BREAK_UP_BIG_DECL
3728 int lim1
= sizeof (m68k_opcodes
) / sizeof (m68k_opcodes
[0]);
3730 return m68k_opcodes_2
+ (i
- lim1
);
3732 return m68k_opcodes
+ i
;
3739 * md_begin -- set up hash tables with 68000 instructions.
3740 * similar to what the vax assembler does. ---phr
3742 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3743 a copy of it at runtime, adding in the information we want but isn't
3744 there. I think it'd be better to have an awk script hack the table
3745 at compile time. Or even just xstr the table and use it as-is. But
3746 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3749 register const struct m68k_opcode
*ins
;
3750 register struct m68k_incant
*hack
, *slak
;
3751 register const char *retval
= 0; /* empty string, or error msg text */
3752 register unsigned int i
;
3755 op_hash
= hash_new ();
3757 obstack_begin (&robyn
, 4000);
3758 for (i
= 0; i
< numopcodes
; i
++)
3760 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3763 ins
= opcode_ptr (i
);
3764 /* We *could* ignore insns that don't match our arch here
3765 but just leaving them out of the hash. */
3766 slak
->m_operands
= ins
->args
;
3767 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3768 slak
->m_arch
= ins
->arch
;
3769 slak
->m_opcode
= ins
->opcode
;
3770 /* This is kludgey */
3771 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3772 if (i
+ 1 != numopcodes
3773 && !strcmp (ins
->name
, opcode_ptr (i
+ 1)->name
))
3775 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3780 slak
= slak
->m_next
;
3784 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3786 as_fatal ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3789 for (i
= 0; i
< numaliases
; i
++)
3791 const char *name
= m68k_opcode_aliases
[i
].primary
;
3792 const char *alias
= m68k_opcode_aliases
[i
].alias
;
3793 PTR val
= hash_find (op_hash
, name
);
3795 as_fatal ("Internal Error: Can't find %s in hash table", name
);
3796 retval
= hash_insert (op_hash
, alias
, val
);
3798 as_fatal ("Internal Error: Can't hash %s: %s", alias
, retval
);
3801 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3802 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3804 for (i
= 0; i
< sizeof (notend_table
); i
++)
3806 notend_table
[i
] = 0;
3807 alt_notend_table
[i
] = 0;
3809 notend_table
[','] = 1;
3810 notend_table
['{'] = 1;
3811 notend_table
['}'] = 1;
3812 alt_notend_table
['a'] = 1;
3813 alt_notend_table
['A'] = 1;
3814 alt_notend_table
['d'] = 1;
3815 alt_notend_table
['D'] = 1;
3816 alt_notend_table
['#'] = 1;
3817 alt_notend_table
['f'] = 1;
3818 alt_notend_table
['F'] = 1;
3819 #ifdef REGISTER_PREFIX
3820 alt_notend_table
[REGISTER_PREFIX
] = 1;
3823 #ifndef MIT_SYNTAX_ONLY
3824 /* Insert pseudo ops, these have to go into the opcode table since
3825 gas expects pseudo ops to start with a dot */
3828 while (mote_pseudo_table
[n
].poc_name
)
3830 hack
= (struct m68k_incant
*)
3831 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3832 hash_insert (op_hash
,
3833 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3834 hack
->m_operands
= 0;
3845 m68k_init_after_args ()
3847 if (cpu_of_arch (current_architecture
) == 0)
3850 const char *default_cpu
= TARGET_CPU
;
3852 if (*default_cpu
== 'm')
3854 for (i
= 0; i
< n_archs
; i
++)
3855 if (!strcmp (default_cpu
, archs
[i
].name
))
3859 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU
);
3860 current_architecture
|= m68020
;
3863 current_architecture
|= archs
[i
].arch
;
3865 /* Permit m68881 specification with all cpus; those that can't work
3866 with a coprocessor could be doing emulation. */
3867 if (current_architecture
& m68851
)
3869 if (current_architecture
& m68040
)
3871 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3874 /* What other incompatibilities could we check for? */
3876 /* Toss in some default assumptions about coprocessors. */
3878 && (cpu_of_arch (current_architecture
)
3879 /* Can CPU32 have a 68881 coprocessor?? */
3880 & (m68020
| m68030
| cpu32
)))
3882 current_architecture
|= m68881
;
3885 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3886 && (cpu_of_arch (current_architecture
) & m68040up
) == 0)
3888 current_architecture
|= m68851
;
3890 if (no_68881
&& (current_architecture
& m68881
))
3891 as_bad ("options for 68881 and no-68881 both given");
3892 if (no_68851
&& (current_architecture
& m68851
))
3893 as_bad ("options for 68851 and no-68851 both given");
3896 /* Work out the magic number. This isn't very general. */
3897 if (current_architecture
& m68000
)
3898 m68k_aout_machtype
= 0;
3899 else if (current_architecture
& m68010
)
3900 m68k_aout_machtype
= 1;
3901 else if (current_architecture
& m68020
)
3902 m68k_aout_machtype
= 2;
3904 m68k_aout_machtype
= 2;
3907 /* Note which set of "movec" control registers is available. */
3908 switch (cpu_of_arch (current_architecture
))
3911 control_regs
= m68000_control_regs
;
3914 control_regs
= m68010_control_regs
;
3918 control_regs
= m68020_control_regs
;
3921 control_regs
= m68040_control_regs
;
3924 control_regs
= m68060_control_regs
;
3927 control_regs
= cpu32_control_regs
;
3934 /* Equal to MAX_PRECISION in atof-ieee.c */
3935 #define MAX_LITTLENUMS 6
3937 /* Turn a string in input_line_pointer into a floating point constant of type
3938 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3939 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
3942 md_atof (type
, litP
, sizeP
)
3948 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3949 LITTLENUM_TYPE
*wordP
;
3981 return "Bad call to MD_ATOF()";
3983 t
= atof_ieee (input_line_pointer
, type
, words
);
3985 input_line_pointer
= t
;
3987 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3988 for (wordP
= words
; prec
--;)
3990 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3991 litP
+= sizeof (LITTLENUM_TYPE
);
3997 md_number_to_chars (buf
, val
, n
)
4002 number_to_chars_bigendian (buf
, val
, n
);
4006 md_apply_fix_2 (fixP
, val
)
4010 addressT upper_limit
;
4011 offsetT lower_limit
;
4013 /* This is unnecessary but it convinces the native rs6000 compiler
4014 to generate the code we want. */
4015 char *buf
= fixP
->fx_frag
->fr_literal
;
4016 buf
+= fixP
->fx_where
;
4017 /* end ibm compiler workaround */
4019 if (val
& 0x80000000)
4020 val
|= ~(addressT
)0x7fffffff;
4024 switch (fixP
->fx_size
)
4026 /* The cast to offsetT below are necessary to make code correct for
4027 machines where ints are smaller than offsetT */
4031 lower_limit
= - (offsetT
) 0x80;
4034 *buf
++ = (val
>> 8);
4036 upper_limit
= 0x7fff;
4037 lower_limit
= - (offsetT
) 0x8000;
4040 *buf
++ = (val
>> 24);
4041 *buf
++ = (val
>> 16);
4042 *buf
++ = (val
>> 8);
4044 upper_limit
= 0x7fffffff;
4045 lower_limit
= - (offsetT
) 0x7fffffff - 1; /* avoid constant overflow */
4048 BAD_CASE (fixP
->fx_size
);
4051 /* For non-pc-relative values, it's conceivable we might get something
4052 like "0xff" for a byte field. So extend the upper part of the range
4053 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4054 so that we can do any range checking at all. */
4055 if (!fixP
->fx_pcrel
)
4056 upper_limit
= upper_limit
* 2 + 1;
4058 if ((addressT
) val
> upper_limit
4059 && (val
> 0 || val
< lower_limit
))
4060 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "value out of range");
4062 /* A one byte PC-relative reloc means a short branch. We can't use
4063 a short branch with a value of 0 or -1, because those indicate
4064 different opcodes (branches with longer offsets). */
4066 && fixP
->fx_size
== 1
4067 && (fixP
->fx_addsy
== NULL
4068 || S_IS_DEFINED (fixP
->fx_addsy
))
4069 && (val
== 0 || val
== -1))
4070 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, "invalid byte branch offset");
4073 #ifdef BFD_ASSEMBLER
4075 md_apply_fix (fixP
, valp
)
4079 md_apply_fix_2 (fixP
, (addressT
) *valp
);
4083 void md_apply_fix (fixP
, val
)
4087 md_apply_fix_2 (fixP
, (addressT
) val
);
4091 /* *fragP has been relaxed to its final size, and now needs to have
4092 the bytes inside it modified to conform to the new size There is UGLY
4096 md_convert_frag_1 (fragP
)
4097 register fragS
*fragP
;
4102 /* Address in object code of the displacement. */
4103 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4105 /* Address in gas core of the place to store the displacement. */
4106 /* This convinces the native rs6000 compiler to generate the code we
4108 register char *buffer_address
= fragP
->fr_literal
;
4109 buffer_address
+= fragP
->fr_fix
;
4110 /* end ibm compiler workaround */
4112 /* The displacement of the address, from current location. */
4113 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4114 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4116 switch (fragP
->fr_subtype
)
4118 case TAB (BCC68000
, BYTE
):
4119 case TAB (ABRANCH
, BYTE
):
4120 know (issbyte (disp
));
4122 as_bad ("short branch with zero offset: use :w");
4123 fragP
->fr_opcode
[1] = disp
;
4126 case TAB (DBCC
, SHORT
):
4127 know (issword (disp
));
4130 case TAB (BCC68000
, SHORT
):
4131 case TAB (ABRANCH
, SHORT
):
4132 know (issword (disp
));
4133 fragP
->fr_opcode
[1] = 0x00;
4136 case TAB (ABRANCH
, LONG
):
4137 if (cpu_of_arch (current_architecture
) < m68020
)
4139 if (fragP
->fr_opcode
[0] == 0x61)
4141 fragP
->fr_opcode
[0] = 0x4E;
4142 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4143 subseg_change (text_section
, 0); /* @@ */
4156 else if (fragP
->fr_opcode
[0] == 0x60)
4158 fragP
->fr_opcode
[0] = 0x4E;
4159 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4160 subseg_change (text_section
, 0); /* @@ */
4161 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4162 fragP
->fr_offset
, 0, NO_RELOC
);
4168 as_bad ("Long branch offset not supported.");
4173 fragP
->fr_opcode
[1] = (char) 0xff;
4177 case TAB (BCC68000
, LONG
):
4178 /* only Bcc 68000 instructions can come here */
4179 /* change bcc into b!cc/jmp absl long */
4180 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4181 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4183 /* JF: these used to be fr_opcode[2,3], but they may be in a
4184 different frag, in which case refering to them is a no-no.
4185 Only fr_opcode[0,1] are guaranteed to work. */
4186 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4187 *buffer_address
++ = (char) 0xf9;
4188 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4189 subseg_change (text_section
, 0);
4190 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4191 fragP
->fr_offset
, 0, NO_RELOC
);
4195 case TAB (DBCC
, LONG
):
4196 /* only DBcc 68000 instructions can come here */
4197 /* change dbcc into dbcc/jmp absl long */
4198 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4199 *buffer_address
++ = 0x00; /* branch offset = 4 */
4200 *buffer_address
++ = 0x04;
4201 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4202 *buffer_address
++ = 0x06;
4203 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4204 *buffer_address
++ = (char) 0xf9;
4206 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4207 subseg_change (text_section
, 0);
4208 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4209 fragP
->fr_offset
, 0, NO_RELOC
);
4213 case TAB (FBRANCH
, SHORT
):
4214 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4217 case TAB (FBRANCH
, LONG
):
4218 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4221 case TAB (PCREL
, SHORT
):
4224 case TAB (PCREL
, LONG
):
4225 /* The thing to do here is force it to ABSOLUTE LONG, since
4226 PCREL is really trying to shorten an ABSOLUTE address anyway */
4227 /* JF FOO This code has not been tested */
4228 subseg_change (text_section
, 0);
4229 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4231 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4232 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
4233 (unsigned) fragP
->fr_opcode
[0],
4234 (unsigned long) fragP
->fr_address
);
4235 fragP
->fr_opcode
[1] &= ~0x3F;
4236 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4240 case TAB (PCLEA
, SHORT
):
4241 subseg_change (text_section
, 0);
4242 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4243 fragP
->fr_offset
, 1, NO_RELOC
);
4244 fragP
->fr_opcode
[1] &= ~0x3F;
4245 fragP
->fr_opcode
[1] |= 0x3A;
4248 case TAB (PCLEA
, LONG
):
4249 subseg_change (text_section
, 0);
4250 fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4251 fragP
->fr_offset
+ 2, 1, NO_RELOC
);
4252 *buffer_address
++ = 0x01;
4253 *buffer_address
++ = 0x70;
4261 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4262 fragP
->fr_fix
+= ext
;
4266 #ifndef BFD_ASSEMBLER
4269 md_convert_frag (headers
, fragP
)
4270 object_headers
*headers
;
4273 md_convert_frag_1 (fragP
);
4279 md_convert_frag (abfd
, sec
, fragP
)
4284 md_convert_frag_1 (fragP
);
4288 /* Force truly undefined symbols to their maximum size, and generally set up
4289 the frag list to be relaxed
4292 md_estimate_size_before_relax (fragP
, segment
)
4293 register fragS
*fragP
;
4297 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4299 old_fix
= fragP
->fr_fix
;
4301 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4302 switch (fragP
->fr_subtype
)
4305 case TAB (ABRANCH
, SZ_UNDEF
):
4307 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4308 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4310 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4313 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
4315 /* On 68000, or for absolute value, switch to abs long */
4316 /* FIXME, we should check abs val, pick short or long */
4317 if (fragP
->fr_opcode
[0] == 0x61)
4319 fragP
->fr_opcode
[0] = 0x4E;
4320 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4321 subseg_change (text_section
, 0);
4322 fix_new (fragP
, fragP
->fr_fix
, 4,
4323 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4327 else if (fragP
->fr_opcode
[0] == 0x60)
4329 fragP
->fr_opcode
[0] = 0x4E;
4330 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4331 subseg_change (text_section
, 0);
4332 fix_new (fragP
, fragP
->fr_fix
, 4,
4333 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4339 as_warn ("Long branch offset to extern symbol not supported.");
4343 { /* Symbol is still undefined. Make it simple */
4344 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4345 fragP
->fr_offset
+ 4, 1, NO_RELOC
);
4347 fragP
->fr_opcode
[1] = (char) 0xff;
4353 } /* case TAB(ABRANCH,SZ_UNDEF) */
4355 case TAB (FBRANCH
, SZ_UNDEF
):
4357 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flag_short_refs
)
4359 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4364 fragP
->fr_subtype
= TAB (FBRANCH
, LONG
);
4368 } /* TAB(FBRANCH,SZ_UNDEF) */
4370 case TAB (PCREL
, SZ_UNDEF
):
4372 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
4374 || cpu_of_arch (current_architecture
) < m68020
)
4376 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4381 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4385 } /* TAB(PCREL,SZ_UNDEF) */
4387 case TAB (BCC68000
, SZ_UNDEF
):
4389 if ((fragP
->fr_symbol
!= NULL
)
4390 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4392 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4395 /* only Bcc 68000 instructions can come here */
4396 /* change bcc into b!cc/jmp absl long */
4397 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4398 if (flag_short_refs
)
4400 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4401 /* JF: these were fr_opcode[2,3] */
4402 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4403 buffer_address
[1] = (char) 0xf8;
4404 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4405 subseg_change (text_section
, 0);
4406 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4407 fragP
->fr_offset
, 0, NO_RELOC
);
4412 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4413 /* JF: these were fr_opcode[2,3] */
4414 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4415 buffer_address
[1] = (char) 0xf9;
4416 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4417 subseg_change (text_section
, 0);
4418 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4419 fragP
->fr_offset
, 0, NO_RELOC
);
4424 } /* case TAB(BCC68000,SZ_UNDEF) */
4426 case TAB (DBCC
, SZ_UNDEF
):
4428 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4430 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4434 /* only DBcc 68000 instructions can come here */
4435 /* change dbcc into dbcc/jmp absl long */
4436 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4437 buffer_address
[0] = 0x00; /* branch offset = 4 */
4438 buffer_address
[1] = 0x04;
4439 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4441 if (flag_short_refs
)
4443 /* JF: these were fr_opcode[5-7] */
4444 buffer_address
[3] = 0x04; /* plus 4 */
4445 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4446 buffer_address
[5] = (char) 0xf8;
4447 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4448 subseg_change (text_section
, 0);
4449 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4450 fragP
->fr_offset
, 0, NO_RELOC
);
4455 /* JF: these were fr_opcode[5-7] */
4456 buffer_address
[3] = 0x06; /* Plus 6 */
4457 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4458 buffer_address
[5] = (char) 0xf9;
4459 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4460 subseg_change (text_section
, 0);
4461 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4462 fragP
->fr_offset
, 0, NO_RELOC
);
4468 } /* case TAB(DBCC,SZ_UNDEF) */
4470 case TAB (PCLEA
, SZ_UNDEF
):
4472 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
4474 || cpu_of_arch (current_architecture
) < m68020
)
4476 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4481 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4485 } /* TAB(PCLEA,SZ_UNDEF) */
4490 } /* switch on subtype looking for SZ_UNDEF's. */
4492 /* now that SZ_UNDEF are taken care of, check others */
4493 switch (fragP
->fr_subtype
)
4495 case TAB (BCC68000
, BYTE
):
4496 case TAB (ABRANCH
, BYTE
):
4497 /* We can't do a short jump to the next instruction,
4498 so we force word mode. */
4499 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
4500 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
4502 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4509 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4512 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4513 /* the bit-field entries in the relocation_info struct plays hell
4514 with the byte-order problems of cross-assembly. So as a hack,
4515 I added this mach. dependent ri twiddler. Ugly, but it gets
4517 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4518 are symbolnum, most sig. byte first. Last byte is broken up with
4519 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4520 nibble as nuthin. (on Sun 3 at least) */
4521 /* Translate the internal relocation information into target-specific
4525 md_ri_to_chars (the_bytes
, ri
)
4527 struct reloc_info_generic
*ri
;
4530 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4531 /* now the fun stuff */
4532 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4533 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4534 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4535 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4536 ((ri
->r_extern
<< 4) & 0x10));
4539 #endif /* comment */
4541 #ifndef BFD_ASSEMBLER
4543 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4546 relax_addressT segment_address_in_file
;
4549 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4550 * Out: GNU LD relocation length code: 0, 1, or 2.
4553 static CONST
unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
4556 know (fixP
->fx_addsy
!= NULL
);
4558 md_number_to_chars (where
,
4559 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4562 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4563 ? S_GET_TYPE (fixP
->fx_addsy
)
4564 : fixP
->fx_addsy
->sy_number
);
4566 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4567 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4568 where
[6] = r_symbolnum
& 0x0ff;
4569 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4570 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4574 #endif /* OBJ_AOUT or OBJ_BOUT */
4576 #ifndef WORKING_DOT_WORD
4577 CONST
int md_short_jump_size
= 4;
4578 CONST
int md_long_jump_size
= 6;
4581 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4583 addressT from_addr
, to_addr
;
4589 offset
= to_addr
- (from_addr
+ 2);
4591 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4592 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4596 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4598 addressT from_addr
, to_addr
;
4604 if (cpu_of_arch (current_architecture
) < m68020
)
4606 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4607 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4608 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4609 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4614 offset
= to_addr
- (from_addr
+ 2);
4615 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4616 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4621 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
4624 10: Absolute 1:8 only
4625 20: Absolute 0:7 only
4626 30: absolute 0:15 only
4627 40: Absolute 0:31 only
4628 50: absolute 0:127 only
4629 55: absolute -64:63 only
4630 60: absolute -128:127 only
4631 70: absolute 0:4095 only
4638 struct m68k_exp
*exp
;
4646 if (*exp
->e_beg
== '0')
4648 if (exp
->e_beg
[1] == 'x')
4649 sscanf (exp
->e_beg
+ 2, "%x", &l
);
4651 sscanf (exp
->e_beg
+ 1, "%O", &l
);
4654 return atol (exp
->e_beg
);
4662 /* Can't do anything */
4665 if (!exp
->e_beg
|| !exp
->e_end
)
4667 seg (exp
) = absolute_section
;
4670 offs (exp
) = (ok
== 10) ? 1 : 0;
4671 as_warn ("Null expression defaults to %ld", offs (exp
));
4676 if ( /* ok!=80 && */ (exp
->e_end
[-1] == ':' || exp
->e_end
[-1] == '.')
4677 && (exp
->e_end
- exp
->e_beg
) >= 2)
4679 switch (exp
->e_end
[0])
4699 if (exp
->e_end
[-1] == ':')
4700 as_bad ("Unknown size for expression \"%c\"", exp
->e_end
[0]);
4704 c_save
= exp
->e_end
[1];
4705 exp
->e_end
[1] = '\0';
4706 save_in
= input_line_pointer
;
4707 input_line_pointer
= exp
->e_beg
;
4708 section
= expression (&exp
->e_exp
);
4709 seg (exp
) = section
;
4710 if (exp
->e_exp
.X_op
== O_absent
)
4712 /* Do the same thing the VAX asm does */
4713 seg (exp
) = absolute_section
;
4714 op (exp
) = O_constant
;
4720 as_warn ("expression out of range: defaulting to 1");
4724 else if (exp
->e_exp
.X_op
== O_constant
)
4729 if (offs (exp
) < 1 || offs (exp
) > 8)
4731 as_warn ("expression out of range: defaulting to 1");
4736 if (offs (exp
) < 0 || offs (exp
) > 7)
4740 if (offs (exp
) < 0 || offs (exp
) > 15)
4744 if (offs (exp
) < 0 || offs (exp
) > 32)
4748 if (offs (exp
) < 0 || offs (exp
) > 127)
4752 if (offs (exp
) < -64 || offs (exp
) > 63)
4756 if (offs (exp
) < -128 || offs (exp
) > 127)
4760 if (offs (exp
) < 0 || offs (exp
) > 4095)
4763 as_warn ("expression out of range: defaulting to 0");
4771 else if (exp
->e_exp
.X_op
== O_big
)
4773 if (offs (exp
) <= 0 /* flonum */
4774 && (ok
== 80 /* no bignums */
4775 || (ok
> 10 /* small-int ranges including 0 ok */
4776 /* If we have a flonum zero, a zero integer should
4777 do as well (e.g., in moveq). */
4778 && generic_floating_point_number
.exponent
== 0
4779 && generic_floating_point_number
.low
[0] == 0)))
4781 /* HACK! Turn it into a long */
4782 LITTLENUM_TYPE words
[6];
4784 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4785 seg (exp
) = absolute_section
;
4786 op (exp
) = O_constant
;
4789 offs (exp
) = words
[1] | (words
[0] << 16);
4793 seg (exp
) = absolute_section
;
4794 op (exp
) = O_constant
;
4797 offs (exp
) = (ok
== 10) ? 1 : 0;
4798 as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp
->e_beg
, offs (exp
));
4803 if (ok
>= 10 && ok
<= 70)
4805 seg (exp
) = absolute_section
;
4806 op (exp
) = O_constant
;
4809 offs (exp
) = (ok
== 10) ? 1 : 0;
4810 as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp
->e_beg
, offs (exp
));
4814 if (input_line_pointer
!= exp
->e_end
+ 1)
4815 as_bad ("Ignoring junk after expression");
4816 exp
->e_end
[1] = c_save
;
4817 input_line_pointer
= save_in
;
4823 if (!isbyte (offs (exp
)))
4824 as_warn ("expression doesn't fit in BYTE");
4827 if (!isword (offs (exp
)))
4828 as_warn ("expression doesn't fit in WORD");
4836 /* These are the back-ends for the various machine dependent pseudo-ops. */
4837 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4843 subseg_set (data_section
, 1);
4844 demand_empty_rest_of_line ();
4851 subseg_set (data_section
, 2);
4852 demand_empty_rest_of_line ();
4859 /* We don't support putting frags in the BSS segment, we fake it
4860 by marking in_bss, then looking at s_skip for clues. */
4862 subseg_set (bss_section
, 0);
4863 demand_empty_rest_of_line ();
4871 register long temp_fill
;
4873 temp
= 1; /* JF should be 2? */
4874 temp_fill
= get_absolute_expression ();
4875 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4876 frag_align (temp
, (int) temp_fill
);
4877 demand_empty_rest_of_line ();
4884 demand_empty_rest_of_line ();
4887 /* s_space is defined in read.c .skip is simply an alias to it. */
4892 * Invocation line includes a switch not recognized by the base assembler.
4893 * See if it's a processor-specific option. These are:
4895 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4896 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4897 * Select the architecture. Instructions or features not
4898 * supported by the selected architecture cause fatal
4899 * errors. More than one may be specified. The default is
4900 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4901 * for -m68000, and -m68882 is a synonym for -m68881.
4902 * -[A]m[c]no-68851, -[A]m[c]no-68881
4903 * Don't accept 688?1 instructions. (The "c" is kind of silly,
4904 * so don't use or document it, but that's the way the parsing
4907 * -pic Indicates PIC.
4908 * -k Indicates PIC. (Sun 3 only.)
4912 CONST
char *md_shortopts
= "lSA:m:k";
4913 struct option md_longopts
[] = {
4914 #define OPTION_PIC (OPTION_MD_BASE)
4915 {"pic", no_argument
, NULL
, OPTION_PIC
},
4916 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
4917 {"register-prefix-optional", no_argument
, NULL
,
4918 OPTION_REGISTER_PREFIX_OPTIONAL
},
4919 {NULL
, no_argument
, NULL
, 0}
4921 size_t md_longopts_size
= sizeof(md_longopts
);
4924 md_parse_option (c
, arg
)
4933 case 'l': /* -l means keep external to 2 bit offset
4934 rather than 16 bit one */
4935 flag_short_refs
= 1;
4938 case 'S': /* -S means that jbsr's always turn into
4940 flag_long_jumps
= 1;
4946 /* intentional fall-through */
4949 if (arg
[0] == 'n' && arg
[1] == 'o' && arg
[2] == '-')
4952 const char *oarg
= arg
;
4958 if (arg
[0] == 'c' && arg
[1] == '6')
4961 for (i
= 0; i
< n_archs
; i
++)
4962 if (!strcmp (arg
, archs
[i
].name
))
4967 as_bad ("unrecognized option `%s'", oarg
);
4970 arch
= archs
[i
].arch
;
4973 else if (arch
== m68851
)
4982 if (arg
[0] == 'c' && arg
[1] == '6')
4985 for (i
= 0; i
< n_archs
; i
++)
4986 if (!strcmp (arg
, archs
[i
].name
))
4988 unsigned long arch
= archs
[i
].arch
;
4989 if (cpu_of_arch (arch
))
4990 /* It's a cpu spec. */
4992 current_architecture
&= ~m68000up
;
4993 current_architecture
|= arch
;
4995 else if (arch
== m68881
)
4997 current_architecture
|= m68881
;
5000 else if (arch
== m68851
)
5002 current_architecture
|= m68851
;
5012 as_bad ("unrecognized architecture specification `%s'", arg
);
5021 break; /* -pic, Position Independent Code */
5023 case OPTION_REGISTER_PREFIX_OPTIONAL
:
5024 flag_reg_prefix_optional
= 1;
5035 md_show_usage (stream
)
5040 -l use 1 word for refs to undefined symbols [default 2]\n\
5041 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040\n\
5042 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -mcpu32\n\
5043 specify variant of 680X0 architecture [default 68020]\n\
5044 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
5045 target has/lacks floating-point coprocessor\n\
5046 [default yes for 68020, 68030, and cpu32]\n\
5047 -m68851 | -mno-68851\n\
5048 target has/lacks memory-management unit coprocessor\n\
5049 [default yes for 68020 and up]\n\
5050 -pic, -k generate position independent code\n\
5051 -S turn jbsr into jsr\n\
5052 --register-prefix-optional\n\
5053 recognize register names without prefix character\n");
5058 /* TEST2: Test md_assemble() */
5059 /* Warning, this routine probably doesn't work anymore */
5063 struct m68k_it the_ins
;
5071 if (!gets (buf
) || !*buf
)
5073 if (buf
[0] == '|' || buf
[1] == '.')
5075 for (cp
= buf
; *cp
; cp
++)
5080 memset (&the_ins
, '\0', sizeof (the_ins
));
5081 m68k_ip (&the_ins
, buf
);
5084 printf ("Error %s in %s\n", the_ins
.error
, buf
);
5088 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
5089 for (n
= 0; n
< the_ins
.numo
; n
++)
5090 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
5092 print_the_insn (&the_ins
.opcode
[0], stdout
);
5093 (void) putchar ('\n');
5095 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
5097 if (the_ins
.operands
[n
].error
)
5099 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
5102 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
5103 if (the_ins
.operands
[n
].b_const
)
5104 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
5105 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
5106 if (the_ins
.operands
[n
].b_iadd
)
5107 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
5108 (void) putchar ('\n');
5120 while (*str
&& *str
!= ' ')
5122 if (str
[-1] == ':' || str
[1] == '=')
5129 /* Possible states for relaxation:
5131 0 0 branch offset byte (bra, etc)
5135 1 0 indexed offsets byte a0@(32,d4:w:1) etc
5139 2 0 two-offset index word-word a0@(32,d4)@(45) etc
5146 /* We have no need to default values of symbols. */
5150 md_undefined_symbol (name
)
5156 /* Round up a section size to the appropriate boundary. */
5158 md_section_align (segment
, size
)
5162 return size
; /* Byte alignment is fine */
5165 /* Exactly what point is a PC-relative offset relative TO?
5166 On the 68k, they're relative to the address of the offset, plus
5167 its size. (??? Is this right? FIXME-SOON!) */
5169 md_pcrel_from (fixP
)
5172 return (fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
5175 #ifndef BFD_ASSEMBLER
5178 tc_coff_symbol_emit_hook (ignore
)
5184 tc_coff_sizemachdep (frag
)
5187 switch (frag
->fr_subtype
& 0x3)
5201 /* end of tc-m68k.c */