1 /* tc-m68k.c All the m68020 specific stuff in one convenient, huge,
2 slow to compile, easy to find file.
4 Copyright (C) 1987, 1991, 1992, 1993 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. */
31 /* The opcode table is too big for gcc, which (currently) requires
32 exponential space at compile time for initialized arrays. */
34 #define DO_BREAK_UP_BIG_DECL
35 #define BREAK_UP_BIG_DECL }; struct m68k_opcode m68k_opcodes_2[] = {
36 #define AND_OTHER_PART sizeof (m68k_opcodes_2)
39 /* Note that this file includes real declarations and thus can only be
40 included by one source file per executable. */
41 #include "opcode/m68k.h"
45 /* This variable contains the value to write out at the beginning of
46 the a.out file. The 2<<16 means that this is a 68020 file instead
47 of an old-style 68000 file */
49 long omagic
= 2 << 16 | OMAGIC
; /* Magic byte for header file */
55 /* This array holds the chars that always start a comment. If the
56 pre-processor is disabled, these aren't very useful */
57 CONST
char comment_chars
[] = "|";
59 /* This array holds the chars that only start a comment at the beginning of
60 a line. If the line seems to have the form '# 123 filename'
61 .line and .file directives will appear in the pre-processed output */
62 /* Note that input_file.c hand checks for '#' at the beginning of the
63 first line of the input file. This is because the compiler outputs
64 #NO_APP at the beginning of its output. */
65 /* Also note that comments like this one will always work. */
66 CONST
char line_comment_chars
[] = "#";
68 CONST
char line_separator_chars
[] = "";
70 /* Chars that can be used to separate mant from exp in floating point nums */
71 CONST
char EXP_CHARS
[] = "eE";
73 /* Chars that mean this number is a floating point constant, as
74 in "0f12.456" or "0d1.2345e12". */
76 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
78 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
79 changed in read.c . Ideally it shouldn't have to know about it at all,
80 but nothing is ideal around here. */
82 const int md_reloc_size
= 8; /* Size of relocation record */
84 /* Its an arbitrary name: This means I don't approve of it */
85 /* See flames below */
86 static struct obstack robyn
;
88 #define TAB(x,y) (((x)<<2)+(y))
89 #define TABTYPE(xy) ((xy) >> 2)
105 unsigned long m_opcode
;
109 struct m68k_incant
*m_next
;
112 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
113 #define gettwo(x) (((x)->m_opcode)&0xffff)
115 /* Operands we can parse: (And associated modes)
121 reg: address or data register
122 areg: address register
123 apc: address register, PC, ZPC or empty string
124 num: 16 or 32 bit num
126 sz: w or l if omitted, l assumed
127 scale: 1 2 4 or 8 if omitted, 1 assumed
129 7.4 IMMED #num --> NUM
130 0.? DREG dreg --> dreg
131 1.? AREG areg --> areg
132 2.? AINDR areg@ --> *(areg)
133 3.? AINC areg@+ --> *(areg++)
134 4.? ADEC areg@- --> *(--areg)
135 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
136 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
137 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
138 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
139 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
140 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
141 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
142 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
143 7.0 ABSL num:sz --> *(num)
144 num --> *(num) (sz L assumed)
145 *** MSCR otherreg --> Magic
147 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
148 ?.? DINDR dreg@ --> (dreg) -- cas2 only
158 a1@(5,d2:w:1) @(45,d6:l:4)
163 #name@(numw) -->turn into PC rel mode
164 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
194 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
197 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
198 8-15==addr reg for operands that take both types */
202 DATA
= 1, /* 1- 8 == data registers 0-7 */
222 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
227 FPREG
, /* Eight FP registers */
236 COPNUM
= (FPREG
+ 8), /* Co-processor #1-#8 */
245 PC
, /* Program counter */
246 ZPC
, /* Hack for Program space, but 0 addressing */
248 CCR
, /* Condition code Reg */
250 /* These have to be in order for the movec instruction to work. */
251 USP
, /* User Stack Pointer */
252 ISP
, /* Interrupt stack pointer */
267 /* end of movec ordering constraints */
273 DRP
, /* 68851 or 68030 MMU regs */
297 PSR
, /* aka MMUSR on 68030 (but not MMUSR on 68040)
298 and ACUSR on 68ec030 */
301 IC
, /* instruction cache token */
302 DC
, /* data cache token */
303 NC
, /* no cache token */
304 BC
, /* both caches token */
306 TT0
, /* 68030 access control unit regs */
310 /* Internal form of an operand. */
313 char *error
; /* Couldn't parse it */
314 enum operand_type mode
; /* What mode this instruction is in. */
315 enum _register reg
; /* Base register */
316 struct m68k_exp
*con1
;
317 int ireg
; /* Index register */
318 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
319 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
320 struct m68k_exp
*con2
;
323 /* internal form of a 68020 instruction */
327 char *args
; /* list of opcode info */
330 int numo
; /* Number of shorts in opcode */
333 struct m68k_op operands
[6];
335 int nexp
; /* number of exprs in use */
336 struct m68k_exp exprs
[4];
338 int nfrag
; /* Number of frags we have to produce */
341 int fragoff
; /* Where in the current opcode[] the frag ends */
348 int nrel
; /* Num of reloc strucs in use */
356 reloc
[5]; /* Five is enough??? */
359 #define cpu_of_arch(x) ((x) & m68000up)
360 #define float_of_arch(x) ((x) & mfloat)
361 #define mmu_of_arch(x) ((x) & mmmu)
363 static struct m68k_it the_ins
; /* the instruction being assembled */
365 #define seg(exp) ((exp)->e_seg)
366 #define op(exp) ((exp)->e_exp.X_op)
367 #define adds(exp) ((exp)->e_exp.X_add_symbol)
368 #define subs(exp) ((exp)->e_exp.X_op_symbol)
369 #define offs(exp) ((exp)->e_exp.X_add_number)
371 /* Macros for adding things to the m68k_it struct */
373 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
375 /* Like addword, but goes BEFORE general operands */
379 struct m68k_incant
*opcode
;
382 for(z
=the_ins
.numo
;z
>opcode
->m_codenum
;--z
)
383 the_ins
.opcode
[z
]=the_ins
.opcode
[z
-1];
384 for(z
=0;z
<the_ins
.nrel
;z
++)
385 the_ins
.reloc
[z
].n
+=2;
386 the_ins
.opcode
[opcode
->m_codenum
]=w
;
390 static struct m68k_exp
*
395 the_ins
.exprs
[the_ins
.nexp
].e_beg
=beg
;
396 the_ins
.exprs
[the_ins
.nexp
].e_end
=end
;
397 return &the_ins
.exprs
[the_ins
.nexp
++];
401 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
404 add_fix (width
, exp
, pc_rel
)
406 struct m68k_exp
*exp
;
409 the_ins
.reloc
[the_ins
.nrel
].n
= (((width
)=='B')
412 ? ((the_ins
.numo
-1)*2)
413 : (the_ins
.numo
*2)));
414 the_ins
.reloc
[the_ins
.nrel
].exp
= exp
->e_exp
;
415 the_ins
.reloc
[the_ins
.nrel
].wid
= width
;
416 the_ins
.reloc
[the_ins
.nrel
++].pcrel
= pc_rel
;
420 add_frag(add
,off
,type
)
425 the_ins
.fragb
[the_ins
.nfrag
].fragoff
=the_ins
.numo
;
426 the_ins
.fragb
[the_ins
.nfrag
].fadd
=add
;
427 the_ins
.fragb
[the_ins
.nfrag
].foff
=off
;
428 the_ins
.fragb
[the_ins
.nfrag
++].fragty
=type
;
432 ((exp) && op (exp) != O_constant && op (exp) != O_big)
434 static char *crack_operand
PARAMS ((char *str
, struct m68k_op
*opP
));
435 static int get_num
PARAMS ((struct m68k_exp
*exp
, int ok
));
436 static int get_regs
PARAMS ((int i
, char *str
, struct m68k_op
*opP
));
437 static int reverse_16_bits
PARAMS ((int in
));
438 static int reverse_8_bits
PARAMS ((int in
));
439 static int try_index
PARAMS ((char **s
, struct m68k_op
*opP
));
440 static void install_gen_operand
PARAMS ((int mode
, int val
));
441 static void install_operand
PARAMS ((int mode
, int val
));
442 static void s_bss
PARAMS ((int));
443 static void s_data1
PARAMS ((int));
444 static void s_data2
PARAMS ((int));
445 static void s_even
PARAMS ((int));
446 static void s_proc
PARAMS ((int));
448 static int current_architecture
;
450 /* BCC68000 is for patching in an extra jmp instruction for long offsets
451 on the 68000. The 68000 doesn't support long branches with branchs */
453 /* This table desribes how you change sizes for the various types of variable
454 size expressions. This version only supports two kinds. */
456 /* Note that calls to frag_var need to specify the maximum expansion
457 needed; this is currently 10 bytes for DBCC. */
460 How far Forward this mode will reach:
461 How far Backward this mode will reach:
462 How many bytes this mode will add to the size of the frag
463 Which mode to go to if the offset won't fit in this one
465 CONST relax_typeS md_relax_table
[] =
467 {1, 1, 0, 0}, /* First entries aren't used */
468 {1, 1, 0, 0}, /* For no good reason except */
469 {1, 1, 0, 0}, /* that the VAX doesn't either */
472 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
473 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
477 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
478 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
482 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
483 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
487 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
488 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
489 {0, 0, 6, 0}, /* jmp long space */
492 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
493 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
494 {0, 0, 10, 0}, /* bra/jmp long space */
497 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
498 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
504 /* These are the machine dependent pseudo-ops. These are included so
505 the assembler can work on the output from the SUN C compiler, which
509 /* This table describes all the machine specific pseudo-ops the assembler
510 has to support. The fields are:
511 pseudo-op name without dot
512 function to call to execute this pseudo-op
513 Integer arg to pass to the function
515 CONST pseudo_typeS md_pseudo_table
[] =
517 {"data1", s_data1
, 0},
518 {"data2", s_data2
, 0},
521 {"skip", s_space
, 0},
524 {"align", s_align_bytes
, 0},
530 /* The mote pseudo ops are put into the opcode table, since they
531 don't start with a . they look like opcodes to gas.
533 extern void obj_coff_section ();
535 CONST pseudo_typeS mote_pseudo_table
[] =
543 {"ds.l", s_space
, 4},
545 {"ds.w", s_space
, 2},
546 {"ds.b", s_space
, 1},
548 {"xdef", s_globl
, 0},
549 {"align", s_align_ptwo
, 0},
551 {"sect", obj_coff_section
, 0},
552 {"section", obj_coff_section
, 0},
557 #define issbyte(x) ((x)>=-128 && (x)<=127)
558 #define isubyte(x) ((x)>=0 && (x)<=255)
559 #define issword(x) ((x)>=-32768 && (x)<=32767)
560 #define isuword(x) ((x)>=0 && (x)<=65535)
562 #define isbyte(x) ((x)>= -255 && (x)<=255)
563 #define isword(x) ((x)>=-32768 && (x)<=65535)
564 #define islong(x) (1)
566 extern char *input_line_pointer
;
574 /* JF these tables here are for speed at the expense of size */
575 /* You can replace them with the #if 0 versions if you really
576 need space and don't mind it running a bit slower */
578 static char mklower_table
[256];
579 #define mklower(c) (mklower_table[(unsigned char)(c)])
580 static char notend_table
[256];
581 static char alt_notend_table
[256];
582 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
583 alt_notend_table[(unsigned char)(s[1])])))
586 #define mklower(c) (isupper(c) ? tolower(c) : c)
590 /* JF modified this to handle cases where the first part of a symbol name
591 looks like a register */
594 * m68k_reg_parse() := if it looks like a register, return it's token &
595 * advance the pointer.
607 #ifdef REGISTER_PREFIX
608 if (*start
!= REGISTER_PREFIX
)
613 if (*p
== OPTIONAL_REGISTER_PREFIX
)
616 if (!isalpha (*p
) || !is_name_beginner (*p
))
620 while (isalpha (c
) || isdigit (c
) || c
== '_')
626 symbolP
= symbol_find (start
);
629 if (symbolP
&& S_GET_SEGMENT (symbolP
) == reg_section
)
632 return S_GET_VALUE (symbolP
);
638 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
639 #define SKIP_W() { ss++; if(*ss==' ') ss++;}
641 /* Parse an index specification using Motorola syntax. */
644 try_moto_index (s
, opP
)
655 i
= m68k_reg_parse (&ss
);
656 if (!(i
>= DATA
+ 0 && i
<= ADDR
+ 7))
657 { /* if i is not DATA or ADDR reg */
658 opP
->error
= "Invalid index register";
674 opP
->error
= "Missing . in index register";
679 if (mklower (*ss
) == 'w')
681 else if (mklower (*ss
) == 'l')
685 opP
->error
= "Size spec not .W or .L";
690 if (*ss
== '.' || *ss
== '*')
699 opP
->imul
= *ss
- '0';
702 opP
->error
= "index multiplier not 1, 2, 4 or 8";
712 opP
->error
= "Missing )";
723 * try_index := data_or_address_register + ')' + SKIP_W
724 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
726 * multiplier := <empty>
727 * | ':' + multiplier_number
730 * multiplier_number := '1' | '2' | '4' | '8' ;
732 * size_spec := 'l' | 'L' | 'w' | 'W' ;
734 * SKIP_W := <empty> | ' ' ;
748 i
= m68k_reg_parse (&ss
);
749 if (!(i
>= DATA
+ 0 && i
<= ADDR
+ 7))
750 { /* if i is not DATA or ADDR reg */
766 opP
->error
= "Missing : in index register";
782 opP
->error
= "Index register size spec not :w or :l";
796 if (cpu_of_arch (current_architecture
) < m68020
)
798 opP
->error
= "no index scaling in pre-68020's";
802 opP
->imul
= *ss
- '0';
805 opP
->error
= "index multiplier not 1, 2, 4 or 8";
815 opP
->error
= "Missing )";
824 /* Ian Taylor expanded this function to accept both MIT and Motorola
825 syntax. I removed the old comment, since it was wrong. The syntax
826 this accepted even before my changes was complex and undocumented.
827 I mainly added a large case when the operand string does not
828 contain an '@', since the Motorola syntax does not use the '@'
832 m68k_ip_op (str
, opP
)
834 register struct m68k_op
*opP
;
838 char *parse_index ();
844 } /* Find the beginning of the string */
848 opP
->error
= "Missing operand";
852 for (strend
= str
; *strend
; strend
++)
859 opP
->con1
= add_exp (str
, strend
);
862 } /* Guess what: A constant. Shar and enjoy */
864 i
= m68k_reg_parse (&str
);
868 if (*str
== '/' || *str
== '-')
870 /* "Rm-Rn/Ro-Rp" Register list for MOVEM instruction */
872 return get_regs (i
, str
, opP
);
877 /* "Rn" Register Direct mode */
878 if (i
>= DATA
+ 0 && i
<= DATA
+ 7)
880 else if (i
>= ADDR
+ 0 && i
<= ADDR
+ 7)
892 if ((stmp
= strchr (str
, '@')) != 0)
894 opP
->con1
= add_exp (str
, stmp
- 1);
901 if ((current_architecture
& m68020up
) == 0)
904 } /* if target is not a '20 or better */
907 if (*stmp
++ != '(' || *strend
-- != ')')
909 opP
->error
= "Malformed operand";
912 i
= try_index (&stmp
, opP
);
913 opP
->con2
= add_exp (stmp
, strend
);
924 } /* if there's an '@' */
926 #ifndef MIT_SYNTAX_ONLY
927 /* The operand has no '@'. Try to parse it using
929 /* Logic of the parsing switch(*str):
933 REG AREG or DREG or MSCR 3 or 2 or 13
934 REG- or REG/ REGLST 14
939 (EXPR,REG,INDX) AINDX 8
942 EXP2(REG,INDX) AINDX 8
945 REG means truth(m68k_reg_parse(&str))
946 INDX means truth(try_moto_index(&str,opP))
948 EXP2 means not REG and not '(' and not '-('
954 i
= m68k_reg_parse (&str
);
955 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7)
956 && (i
< DATA
+ 0 || i
> DATA
+ 7
957 || *str
!= ')' || str
[1] != '0')
958 && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
)
960 /* Can't indirect off non address regs */
961 opP
->error
= "Invalid indirect register";
972 /* "(An)" Address Register Indirect mode
973 or "(Dn)" for cas2. */
974 if (i
>= DATA
+ 0 && i
<= DATA
+ 7)
984 /* "(An)+" Register Indirect w Postincrement */
989 opP
->error
= "Junk after indirect";
995 i
= try_moto_index (&str
, opP
);
998 /* "(An,Rn)" Register Indirect with Index mode*/
1004 opP
->error
= "Bad indirect syntax";
1010 /* "(EXPR,..." , a displacement */
1014 if ((stmp
= index (str
, ',')) != NULL
)
1016 opP
->con1
= add_exp (str
, stmp
- 1);
1019 i
= m68k_reg_parse (&str
);
1020 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
)
1022 /* Can't indirect off non address regs */
1023 opP
->error
= "Invalid indirect register";
1031 /* "(d,An)" Register Indirect w Displacement */
1038 i
= try_moto_index (&str
, opP
);
1041 /* "(d,An,Rn)" Register Indirect with Index */
1047 opP
->error
= "Bad indirect syntax";
1053 opP
->error
= "Invalid register";
1060 opP
->con1
= add_exp (str
- 1, strend
);
1071 i
= m68k_reg_parse (&str
);
1072 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
)
1074 /* Can't indirect off non address regs */
1075 opP
->error
= "Invalid indirect register";
1086 /* "-(An)" Register Indirect with Predecrement */
1090 opP
->error
= "Junk after indirect";
1093 opP
->error
= "Bad indirect syntax";
1097 opP
->con1
= add_exp (str
- 2, strend
);
1100 /* if '-' but not "-(', do nothing */
1103 /* whether *str=='-' or not */
1105 /* "EXP2" or "EXP2(REG..." */
1108 if ((stmp
= index (str
, '(')) != NULL
)
1112 opP
->con1
= add_exp (str
, stmp
- 1);
1114 i
= m68k_reg_parse (&str
);
1115 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
1116 && i
!= ZPC
&& i
!= FAIL
)
1118 /* Can't indirect off non address regs */
1119 opP
->error
= "Invalid indirect register";
1127 /* "d(An)" Register Indirect w Displacement */
1134 i
= try_moto_index (&str
, opP
);
1137 /* "d(An,Rn)" Register Indirect with Index */
1143 opP
->error
= "Bad indirect syntax";
1150 opP
->con1
= add_exp (ostr
, strend
);
1156 /* "EXP2" Absolute */
1159 if (strend
[-1] == '.' || strend
[-1] == ':')
1161 /* mode ==foo.[wl] */
1174 opP
->con1
= add_exp (str
, strend
);
1179 #else /* defined (MIT_SYNTAX_ONLY) */
1181 opP
->con1
= add_exp (str
, strend
);
1183 #endif /* defined (MIT_SYNTAX_ONLY) */
1188 /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
1189 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
1190 && (str
[1] != '\0' || i
< DATA
+ 0 || i
> DATA
+ 7))
1192 opP
->error
= "Invalid indirect register";
1201 if (i
< DATA
+ 0 || i
> DATA
+ 7)
1216 opP
->error
= "Junk after indirect";
1219 /* Some kind of indexing involved. Lets find out how bad it is */
1220 i
= try_index (&str
, opP
);
1221 /* Didn't start with an index reg, maybe its offset or offset,reg */
1232 opP
->error
= "Missing )";
1265 opP
->error
="Specified size isn't :w or :l";
1268 opP
->con1
=add_exp(beg_str
,str
-4);
1269 opP
->con1
->e_siz
=siz
;
1273 opP
->con1
= add_exp (beg_str
, str
- 2);
1274 /* Should be offset,reg */
1277 i
= try_index (&str
, opP
);
1280 opP
->error
= "Malformed index reg";
1285 /* We've now got offset) offset,reg) or reg) */
1289 /* Th-the-thats all folks */
1290 if (opP
->reg
== FAIL
)
1291 opP
->mode
= AINDX
; /* Other form of indirect */
1292 else if (opP
->ireg
== FAIL
)
1298 /* Next thing had better be another @ */
1313 if ((current_architecture
& m68020up
) == 0)
1316 } /* if target is not a '20 or better */
1319 if (opP
->ireg
!= FAIL
)
1323 i
= try_index (&str
, opP
);
1326 opP
->error
= "Two index registers! not allowed!";
1332 i
= try_index (&str
, opP
);
1347 opP
->error
= "Missing )";
1362 opP
->con2
= add_exp (beg_str
, str
- 2);
1366 if (opP
->ireg
!= FAIL
)
1368 opP
->error
= "Can't have two index regs";
1372 i
= try_index (&str
, opP
);
1376 opP
->error
= "malformed index reg";
1382 else if (opP
->ireg
!= FAIL
)
1398 opP
->error
= "Junk after indirect";
1402 } /* m68k_ip_op() */
1405 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
1408 tc_coff_fix2rtype (fixP
)
1411 return (fixP
->fx_pcrel
?
1412 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
1413 fixP
->fx_size
== 2 ? R_PCRWORD
:
1415 (fixP
->fx_size
== 1 ? R_RELBYTE
:
1416 fixP
->fx_size
== 2 ? R_RELWORD
:
1424 #ifdef BFD_ASSEMBLER
1427 tc_gen_reloc (section
, fixp
)
1432 bfd_reloc_code_real_type code
;
1434 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1435 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
1437 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1438 MAP (1, 0, BFD_RELOC_8
);
1439 MAP (2, 0, BFD_RELOC_16
);
1440 MAP (4, 0, BFD_RELOC_32
);
1441 MAP (1, 1, BFD_RELOC_8_PCREL
);
1442 MAP (2, 1, BFD_RELOC_16_PCREL
);
1443 MAP (4, 1, BFD_RELOC_32_PCREL
);
1448 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
1449 assert (reloc
!= 0);
1450 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1451 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1453 reloc
->addend
= fixp
->fx_addnumber
;
1457 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1458 assert (reloc
->howto
!= 0);
1463 #endif /* BFD_ASSEMBLER */
1465 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1469 struct m68k_op thark
;
1475 memset (&thark
, '\0', sizeof (thark
));
1476 if (!m68k_ip_op (buf
, &thark
))
1479 printf ("op1 error %s in %s\n", thark
.error
, buf
);
1480 printf ("mode %d, reg %d, ", thark
.mode
, thark
.reg
);
1482 printf ("Constant: '%.*s',", 1 + thark
.e_const
- thark
.b_const
, thark
.b_const
);
1483 printf ("ireg %d, isiz %d, imul %d ", thark
.ireg
, thark
.isiz
, thark
.imul
);
1485 printf ("Iadd: '%.*s'", 1 + thark
.e_iadd
- thark
.b_iadd
, thark
.b_iadd
);
1494 /* Handle of the OPCODE hash table. NULL means any use before
1495 m68k_ip_begin() will crash. */
1496 static struct hash_control
*op_hash
;
1502 * This converts a string into a 68k instruction.
1503 * The string must be a bare single instruction in sun format
1504 * with RMS-style 68020 indirects
1507 * It provides some error messages: at most one fatal error message (which
1508 * stops the scan) and at most one warning message for each operand.
1509 * The 68k instruction is returned in exploded form, since we have no
1510 * knowledge of how you parse (or evaluate) your expressions.
1511 * We do however strip off and decode addressing modes and operation
1514 * This function's value is a string. If it is not "" then an internal
1515 * logic error was found: read this code to assign meaning to the string.
1516 * No argument string should generate such an error string:
1517 * it means a bug in our code, not in the user's text.
1519 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1523 /* JF this function no longer returns a useful value. Sorry */
1529 register struct m68k_op
*opP
;
1530 register struct m68k_incant
*opcode
;
1532 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1533 char *pdot
, *pdotmove
;
1538 char *crack_operand ();
1539 LITTLENUM_TYPE words
[6];
1540 LITTLENUM_TYPE
*wordp
;
1541 unsigned long ok_arch
= 0;
1543 if (*instring
== ' ')
1544 instring
++; /* skip leading whitespace */
1546 /* Scan up to end of operation-code, which MUST end in end-of-string
1547 or exactly 1 space. */
1549 for (p
= instring
; *p
!= '\0'; p
++)
1559 the_ins
.error
= "No operator";
1560 the_ins
.opcode
[0] = 0;
1561 /* the_ins.numo=1; */
1565 /* p now points to the end of the opcode name, probably whitespace.
1566 make sure the name is null terminated by clobbering the whitespace,
1567 look it up in the hash table, then fix it back.
1568 Remove a dot, first, since the opcode tables have none. */
1571 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1572 *pdotmove
= pdotmove
[1];
1578 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
1583 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1584 *pdotmove
= pdotmove
[-1];
1591 the_ins
.error
= "Unknown operator";
1592 the_ins
.opcode
[0] = 0;
1593 /* the_ins.numo=1; */
1597 /* found a legitimate opcode, start matching operands */
1602 if (opcode
->m_operands
== 0)
1604 char *old
= input_line_pointer
;
1606 input_line_pointer
= p
;
1607 /* Ahh - it's a motorola style psuedo op */
1608 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1609 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1610 input_line_pointer
= old
;
1616 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1619 p
= crack_operand (p
, opP
);
1623 the_ins
.error
= opP
->error
;
1628 opsfound
= opP
- &the_ins
.operands
[0];
1630 /* This ugly hack is to support the floating pt opcodes in their standard form */
1631 /* Essentially, we fake a first enty of type COP#1 */
1632 if (opcode
->m_operands
[0] == 'I')
1636 for (n
= opsfound
; n
> 0; --n
)
1637 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1639 memset ((char *) (&the_ins
.operands
[0]), '\0', sizeof (the_ins
.operands
[0]));
1640 the_ins
.operands
[0].mode
= MSCR
;
1641 the_ins
.operands
[0].reg
= COPNUM
; /* COP #1 */
1645 /* We've got the operands. Find an opcode that'll accept them */
1648 /* If we didn't get the right number of ops, or we have no
1649 common model with this pattern then reject this pattern. */
1651 if (opsfound
!= opcode
->m_opnum
1652 || ((opcode
->m_arch
& current_architecture
) == 0))
1655 ok_arch
|= opcode
->m_arch
;
1659 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++)
1661 /* Warning: this switch is huge! */
1662 /* I've tried to organize the cases into this order:
1663 non-alpha first, then alpha by letter. Lower-case
1664 goes directly before uppercase counterpart. */
1665 /* Code with multiple case ...: gets sorted by the lowest
1666 case ... it belongs to. I hope this makes sense. */
1670 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1671 || opP
->mode
== DREG
|| opP
->mode
== AREG
1672 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1673 || opP
->mode
== REGLST
)
1695 if (opP
->mode
!= IMMED
)
1701 t
= get_num (opP
->con1
, 80);
1702 if (s
[1] == 'b' && !isbyte (t
))
1704 else if (s
[1] == 'w' && !isword (t
))
1711 if (opP
->mode
!= IMMED
)
1716 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1717 opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1722 if (opP
->mode
== MSCR
|| opP
->reg
== PC
||
1723 opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1729 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1730 opP
->mode
== AREG
|| opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
||
1731 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== REGLST
)
1736 if (opP
->mode
== MSCR
|| opP
->mode
== REGLST
)
1741 if (opP
->mode
!= AINC
)
1746 if (opP
->mode
!= ADEC
)
1751 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1752 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== IMMED
|| opP
->mode
== REGLST
)
1757 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
|| opP
->mode
== REGLST
)
1762 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1763 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== IMMED
|| opP
->reg
== PC
||
1764 opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1769 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1770 opP
->mode
== IMMED
|| opP
->mode
== REGLST
)
1774 case '~': /* For now! (JF FOO is this right?) */
1775 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1776 opP
->mode
== AREG
|| opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1781 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1786 if (opP
->mode
!= AREG
)
1790 if (opP
->mode
!= AINDR
)
1793 } /* if not address register indirect */
1796 if (opP
->mode
!= ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1797 && instring
[1] == 'b'
1798 && instring
[2] == 's'
1799 && instring
[3] == 'r'))
1804 if (opP
->mode
!= MSCR
|| opP
->reg
!= CCR
)
1808 case 'd': /* FOO This mode is a KLUDGE!! */
1809 if (opP
->mode
!= AOFF
&& (opP
->mode
!= ABSL
||
1810 opP
->con1
->e_beg
[0] != '(' || opP
->con1
->e_end
[0] != ')'))
1815 if (opP
->mode
!= DREG
)
1820 if (opP
->mode
!= MSCR
|| opP
->reg
< (FPREG
+ 0) || opP
->reg
> (FPREG
+ 7))
1825 if (opP
->mode
!= MSCR
|| opP
->reg
< COPNUM
||
1826 opP
->reg
>= COPNUM
+ 7)
1831 if (opP
->mode
!= MSCR
1834 || cpu_of_arch (current_architecture
) < m68010
/* before 68010 had none */
1835 || (cpu_of_arch (current_architecture
) < m68020
1839 && opP
->reg
!= VBR
) /* 68010's had only these */
1840 || (cpu_of_arch (current_architecture
) < m68040
1848 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1849 || (cpu_of_arch (current_architecture
) == m68040
/* 68040 has all but this */
1850 && opP
->reg
== CAAR
))
1853 } /* doesn't cut it */
1857 if (opP
->mode
!= IMMED
)
1863 if (opP
->mode
== DREG
|| opP
->mode
== AREG
|| opP
->mode
== FPREG
)
1870 opP
->reg
= 1 << (opP
->reg
- DATA
);
1873 else if (opP
->mode
!= REGLST
)
1877 else if (s
[1] == '8' && opP
->reg
& 0x0FFffFF)
1879 else if (s
[1] == '3' && opP
->reg
& 0x7000000)
1884 if (opP
->mode
!= IMMED
)
1890 t
= get_num (opP
->con1
, 0);
1892 || isvar (opP
->con1
))
1898 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1903 if (opP
->mode
!= IMMED
)
1909 t
= get_num (opP
->con1
, 80);
1910 if (t
< 1 || t
> 8 || isvar (opP
->con1
))
1916 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1921 if (opP
->mode
!= AINDR
&& opP
->mode
!= DINDR
)
1926 if (opP
->mode
!= MSCR
|| !(opP
->reg
== FPI
|| opP
->reg
== FPS
|| opP
->reg
== FPC
))
1931 if (opP
->mode
!= MSCR
|| opP
->reg
!= SR
)
1936 if (opP
->mode
!= IMMED
)
1940 long t
= get_num (opP
->con1
, 80);
1941 if (t
< 0 || t
> 7 || isvar (opP
->con1
))
1947 if (opP
->mode
!= MSCR
|| opP
->reg
!= USP
)
1951 /* JF these are out of order. We could put them
1952 in order if we were willing to put up with
1953 bunches of #ifdef m68851s in the code.
1955 Don't forget that you need these operands
1956 to use 68030 MMU instructions. */
1958 /* Memory addressing mode used by pflushr */
1960 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1961 opP
->mode
== AREG
|| opP
->mode
== REGLST
)
1966 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1971 if (opP
->mode
!= MSCR
1972 || (opP
->reg
!= TC
&& opP
->reg
!= CAL
1973 && opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1978 if (opP
->reg
!= VAL
)
1983 if (opP
->mode
!= MSCR
1984 || (opP
->reg
!= DRP
&& opP
->reg
!= SRP
1985 && opP
->reg
!= CRP
))
1990 if (opP
->mode
!= MSCR
||
1991 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7) &&
1992 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1997 if (opP
->reg
!= PSR
)
2002 if (opP
->reg
!= PCSR
)
2013 } /* not a cache specifier. */
2017 if (opP
->mode
!= ABSL
)
2020 } /* not absolute */
2024 as_fatal ("Internal error: Operand mode %c unknown in line %d of file \"%s\"",
2025 *s
, __LINE__
, __FILE__
);
2026 } /* switch on type of operand */
2030 } /* for each operand */
2031 } /* if immediately wrong */
2038 opcode
= opcode
->m_next
;
2043 && !(ok_arch
& current_architecture
))
2047 strcpy (buf
, "invalid instruction for this architecture; needs ");
2048 cp
= buf
+ strlen (buf
);
2052 strcpy (cp
, "fpu (68040 or 68881/68882)");
2055 strcpy (cp
, "mmu (68030 or 68851)");
2058 strcpy (cp
, "68020 or higher");
2061 strcpy (cp
, "68000 or higher");
2064 strcpy (cp
, "68010 or higher");
2068 int got_one
= 0, idx
;
2076 { m68000
, "68000" },
2077 { m68010
, "68010" },
2078 { m68020
, "68020" },
2079 { m68030
, "68030" },
2080 { m68040
, "68040" },
2082 { m68881
, "68881" },
2085 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]); idx
++)
2087 if (archs
[idx
].arch
& ok_arch
)
2091 strcpy (cp
, " or ");
2095 strcpy (cp
, archs
[idx
].name
);
2107 the_ins
.error
= "operands mismatch";
2109 } /* Fell off the end */
2114 /* now assemble it */
2116 the_ins
.args
= opcode
->m_operands
;
2117 the_ins
.numargs
= opcode
->m_opnum
;
2118 the_ins
.numo
= opcode
->m_codenum
;
2119 the_ins
.opcode
[0] = getone (opcode
);
2120 the_ins
.opcode
[1] = gettwo (opcode
);
2122 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2124 /* This switch is a doozy.
2125 Watch the first step; its a big one! */
2146 tmpreg
= 0x3c; /* 7.4 */
2147 if (strchr ("bwl", s
[1]))
2148 nextword
= get_num (opP
->con1
, 80);
2150 nextword
= get_num (opP
->con1
, 0);
2151 if (isvar (opP
->con1
))
2152 add_fix (s
[1], opP
->con1
, 0);
2156 if (!isbyte (nextword
))
2157 opP
->error
= "operand out of range";
2162 if (!isword (nextword
))
2163 opP
->error
= "operand out of range";
2168 addword (nextword
>> 16);
2190 as_fatal ("Internal error: Can't decode %c%c in line %d of file \"%s\"",
2191 *s
, s
[1], __LINE__
, __FILE__
);
2196 /* We gotta put out some float */
2197 if (op (opP
->con1
) != O_big
)
2202 /* Can other cases happen here? */
2203 if (op (opP
->con1
) != O_constant
)
2206 val
= (valueT
) offs (opP
->con1
);
2210 generic_bignum
[gencnt
] = (LITTLENUM_TYPE
) val
;
2211 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2215 offs (opP
->con1
) = gencnt
;
2217 if (offs (opP
->con1
) > 0)
2219 if (offs (opP
->con1
) > baseo
)
2221 as_warn ("Bignum too big for %c format; truncated", s
[1]);
2222 offs (opP
->con1
) = baseo
;
2224 baseo
-= offs (opP
->con1
);
2227 for (wordp
= generic_bignum
+ offs (opP
->con1
) - 1; offs (opP
->con1
)--; --wordp
)
2231 gen_to_words (words
, baseo
, (long) outro
);
2232 for (wordp
= words
; baseo
--; wordp
++)
2236 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2239 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2242 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2245 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2248 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2252 nextword
= get_num (opP
->con1
, 80);
2253 /* Force into index mode. Hope this works */
2255 /* We do the first bit for 32-bit displacements, and the
2256 second bit for 16 bit ones. It is possible that we
2257 should make the default be WORD instead of LONG, but
2258 I think that'd break GCC, so we put up with a little
2259 inefficiency for the sake of working output. */
2261 if (!issword (nextword
)
2262 || (isvar (opP
->con1
)
2263 && ((opP
->con1
->e_siz
== 0
2264 && flagseen
['l'] == 0)
2265 || opP
->con1
->e_siz
== 3)))
2269 tmpreg
= 0x3B; /* 7.3 */
2271 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2272 if (isvar (opP
->con1
))
2276 add_frag (adds (opP
->con1
),
2277 offs (opP
->con1
) + 2,
2278 TAB (PCLEA
, SZ_UNDEF
));
2284 add_fix ('l', opP
->con1
, 0);
2289 addword (nextword
>> 16);
2294 tmpreg
= 0x3A; /* 7.2 */
2296 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2298 if (isvar (opP
->con1
))
2302 add_fix ('w', opP
->con1
, 1);
2305 add_fix ('w', opP
->con1
, 0);
2314 know (current_architecture
& m68020up
);
2315 /* intentional fall-through */
2318 baseo
= get_num (opP
->con1
, 80);
2319 outro
= get_num (opP
->con2
, 80);
2320 /* Figure out the `addressing mode'.
2321 Also turn on the BASE_DISABLE bit, if needed. */
2322 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2324 tmpreg
= 0x3b;/* 7.3 */
2325 if (opP
->reg
== ZPC
)
2328 else if (opP
->reg
== FAIL
)
2331 tmpreg
= 0x30;/* 6.garbage */
2334 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2336 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
2337 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
2339 /* Index register stuff */
2340 if (opP
->ireg
>= DATA
+ 0 && opP
->ireg
<= ADDR
+ 7)
2342 nextword
|= (opP
->ireg
- DATA
) << 12;
2344 if (opP
->isiz
== 0 || opP
->isiz
== 3)
2360 as_fatal ("failed sanity check.");
2363 GET US OUT OF HERE! */
2365 /* Must be INDEX, with an index
2366 register. Address register
2367 cannot be ZERO-PC, and either
2368 :b was forced, or we know
2370 if (opP
->mode
== AINDX
2375 && !isvar (opP
->con1
))))
2377 nextword
+= baseo
& 0xff;
2379 if (isvar (opP
->con1
))
2380 add_fix ('B', opP
->con1
, 0);
2385 nextword
|= 0x40; /* No index reg */
2387 /* It isn't simple. */
2389 /* If the guy specified a width, we assume that it is
2390 wide enough. Maybe it isn't. If so, we lose. */
2394 if (isvar (opP
->con1
) || !issword (baseo
))
2399 else if (baseo
== 0)
2408 as_warn ("Byte dispacement won't work. Defaulting to :w");
2417 /* Figure out innner displacement stuff */
2418 if (opP
->mode
!= AINDX
)
2423 if (isvar (opP
->con2
) || !issword (outro
))
2428 else if (outro
== 0)
2437 as_warn ("Byte dispacement won't work. Defaulting to :w");
2445 if (opP
->mode
== APODX
)
2447 else if (opP
->mode
== AMIND
)
2452 if (isvar (opP
->con1
))
2454 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2456 opP
->con1
->e_exp
.X_add_number
+= 6;
2457 add_fix (siz1
== 3 ? 'l' : 'w', opP
->con1
, 1);
2460 add_fix (siz1
== 3 ? 'l' : 'w', opP
->con1
, 0);
2463 addword (baseo
>> 16);
2467 if (isvar (opP
->con2
))
2469 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2471 opP
->con1
->e_exp
.X_add_number
+= 6;
2472 add_fix (siz2
== 3 ? 'l' : 'w', opP
->con2
, 1);
2475 add_fix (siz2
== 3 ? 'l' : 'w', opP
->con2
, 0);
2478 addword (outro
>> 16);
2485 nextword
= get_num (opP
->con1
, 80);
2486 switch (opP
->con1
->e_siz
)
2489 as_warn ("Unknown size for absolute reference");
2491 if (!isvar (opP
->con1
) && issword (offs (opP
->con1
)))
2493 tmpreg
= 0x38; /* 7.0 */
2497 /* Don't generate pc relative code on 68010 and
2499 if (isvar (opP
->con1
)
2500 && !subs (opP
->con1
)
2501 && seg (opP
->con1
) == text_section
2502 && now_seg
== text_section
2503 && cpu_of_arch (current_architecture
) >= m68020
2505 && !strchr ("~%&$?", s
[0]))
2507 tmpreg
= 0x3A; /* 7.2 */
2508 add_frag (adds (opP
->con1
),
2510 TAB (PCREL
, SZ_UNDEF
));
2513 case 3: /* Fall through into long */
2514 if (isvar (opP
->con1
))
2515 add_fix ('l', opP
->con1
, 0);
2517 tmpreg
= 0x39;/* 7.1 mode */
2518 addword (nextword
>> 16);
2523 if (isvar (opP
->con1
))
2524 add_fix ('w', opP
->con1
, 0);
2526 tmpreg
= 0x38;/* 7.0 mode */
2532 as_bad ("invalid indirect register");
2536 as_bad ("unknown/incorrect operand");
2539 install_gen_operand (s
[1], tmpreg
);
2545 { /* JF: I hate floating point! */
2560 tmpreg
= get_num (opP
->con1
, tmpreg
);
2561 if (isvar (opP
->con1
))
2562 add_fix (s
[1], opP
->con1
, 0);
2565 case 'b': /* Danger: These do no check for
2566 certain types of overflow.
2568 if (!isbyte (tmpreg
))
2569 opP
->error
= "out of range";
2570 insop (tmpreg
, opcode
);
2571 if (isvar (opP
->con1
))
2572 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2575 if (!isword (tmpreg
))
2576 opP
->error
= "out of range";
2577 insop (tmpreg
, opcode
);
2578 if (isvar (opP
->con1
))
2579 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2582 /* Because of the way insop works, we put these two out
2584 insop (tmpreg
, opcode
);
2585 insop (tmpreg
>> 16, opcode
);
2586 if (isvar (opP
->con1
))
2587 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2593 install_operand (s
[1], tmpreg
);
2596 as_fatal ("Internal error: Unknown mode #%c in line %d of file \"%s\"", s
[1], __LINE__
, __FILE__
);
2604 install_operand (s
[1], opP
->reg
- ADDR
);
2608 tmpreg
= get_num (opP
->con1
, 80);
2612 /* Needs no offsetting */
2613 add_fix ('B', opP
->con1
, 1);
2616 /* Offset the displacement to be relative to byte disp location */
2617 opP
->con1
->e_exp
.X_add_number
+= 2;
2618 add_fix ('w', opP
->con1
, 1);
2623 if (cpu_of_arch (current_architecture
) < m68020
) /* 68000 or 010 */
2624 as_warn ("Can't use long branches on 68000/68010");
2625 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2626 /* Offset the displacement to be relative to byte disp location */
2627 opP
->con1
->e_exp
.X_add_number
+= 4;
2628 add_fix ('l', opP
->con1
, 1);
2633 if (subs (opP
->con1
)) /* We can't relax it */
2636 /* This could either be a symbol, or an
2637 absolute address. No matter, the
2638 frag hacking will finger it out.
2639 Not quite: it can't switch from
2640 BRANCH to BCC68000 for the case
2641 where opnd is absolute (it needs
2642 to use the 68000 hack since no
2643 conditional abs jumps). */
2644 if (((cpu_of_arch (current_architecture
) < m68020
) || (0 == adds (opP
->con1
)))
2645 && (the_ins
.opcode
[0] >= 0x6200)
2646 && (the_ins
.opcode
[0] <= 0x6f00))
2648 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (BCC68000
, SZ_UNDEF
));
2652 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (ABRANCH
, SZ_UNDEF
));
2656 if (isvar (opP
->con1
))
2659 /* check for DBcc instruction */
2660 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2662 /* size varies if patch */
2663 /* needed for long form */
2664 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (DBCC
, SZ_UNDEF
));
2669 opP
->con1
->e_exp
.X_add_number
+= 2;
2670 add_fix ('w', opP
->con1
, 1);
2674 case 'C': /* Fixed size LONG coproc branches */
2675 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2676 /* Offset the displacement to be relative to byte disp location */
2677 /* Coproc branches don't have a byte disp option, but they are
2678 compatible with the ordinary branches, which do... */
2679 opP
->con1
->e_exp
.X_add_number
+= 4;
2680 add_fix ('l', opP
->con1
, 1);
2684 case 'c': /* Var size Coprocesssor branches */
2685 if (subs (opP
->con1
))
2687 add_fix ('l', opP
->con1
, 1);
2688 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2690 else if (adds (opP
->con1
))
2692 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (FBRANCH
, SZ_UNDEF
));
2696 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2697 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2698 add_fix ('l', opP
->con1
, 1);
2704 as_fatal ("Internal error: operand type B%c unknown in line %d of file \"%s\"",
2705 s
[1], __LINE__
, __FILE__
);
2709 case 'C': /* Ignore it */
2712 case 'd': /* JF this is a kludge */
2713 if (opP
->mode
== AOFF
)
2715 install_operand ('s', opP
->reg
- ADDR
);
2721 tmpP
= opP
->con1
->e_end
- 2;
2723 opP
->con1
->e_end
-= 4; /* point to the , */
2724 baseo
= m68k_reg_parse (&tmpP
);
2725 if (baseo
< ADDR
+ 0 || baseo
> ADDR
+ 7)
2727 as_bad ("Unknown address reg, using A0");
2732 install_operand ('s', baseo
);
2734 tmpreg
= get_num (opP
->con1
, 80);
2735 if (!issword (tmpreg
))
2737 as_warn ("Expression out of range, using 0");
2744 install_operand (s
[1], opP
->reg
- DATA
);
2748 install_operand (s
[1], opP
->reg
- FPREG
);
2752 tmpreg
= 1 + opP
->reg
- COPNUM
;
2755 install_operand (s
[1], tmpreg
);
2758 case 'J': /* JF foo */
2811 as_fatal ("failed sanity check.");
2813 install_operand (s
[1], tmpreg
);
2817 tmpreg
= get_num (opP
->con1
, 55);
2818 install_operand (s
[1], tmpreg
& 0x7f);
2825 if (tmpreg
& 0x7FF0000)
2826 as_bad ("Floating point register in register list");
2827 insop (reverse_16_bits (tmpreg
), opcode
);
2831 if (tmpreg
& 0x700FFFF)
2832 as_bad ("Wrong register in floating-point reglist");
2833 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2841 if (tmpreg
& 0x7FF0000)
2842 as_bad ("Floating point register in register list");
2843 insop (tmpreg
, opcode
);
2845 else if (s
[1] == '8')
2847 if (tmpreg
& 0x0FFFFFF)
2848 as_bad ("incorrect register in reglist");
2849 install_operand (s
[1], tmpreg
>> 24);
2853 if (tmpreg
& 0x700FFFF)
2854 as_bad ("wrong register in floating-point reglist");
2856 install_operand (s
[1], tmpreg
>> 16);
2861 install_operand (s
[1], get_num (opP
->con1
, 60));
2865 tmpreg
= (opP
->mode
== DREG
)
2866 ? 0x20 + opP
->reg
- DATA
2867 : (get_num (opP
->con1
, 40) & 0x1F);
2868 install_operand (s
[1], tmpreg
);
2872 tmpreg
= get_num (opP
->con1
, 10);
2875 install_operand (s
[1], tmpreg
);
2880 /* This depends on the fact that ADDR registers are
2881 eight more than their corresponding DATA regs, so
2882 the result will have the ADDR_REG bit set */
2883 install_operand (s
[1], opP
->reg
- DATA
);
2887 if (opP
->reg
== FPI
)
2889 else if (opP
->reg
== FPS
)
2891 else if (opP
->reg
== FPC
)
2894 as_fatal ("failed sanity check.");
2895 install_operand (s
[1], tmpreg
);
2898 case 'S': /* Ignore it */
2902 install_operand (s
[1], get_num (opP
->con1
, 30));
2905 case 'U': /* Ignore it */
2924 as_fatal ("failed sanity check");
2925 } /* switch on cache token */
2926 install_operand (s
[1], tmpreg
);
2929 /* JF: These are out of order, I fear. */
2940 as_fatal ("failed sanity check.");
2942 install_operand (s
[1], tmpreg
);
2964 as_fatal ("failed sanity check.");
2966 install_operand (s
[1], tmpreg
);
2970 if (opP
->reg
== VAL
)
2972 as_fatal ("failed sanity check.");
2988 as_fatal ("failed sanity check.");
2990 install_operand (s
[1], tmpreg
);
3004 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
3015 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
3019 as_fatal ("failed sanity check.");
3021 install_operand (s
[1], tmpreg
);
3024 know (opP
->reg
== PSR
);
3027 know (opP
->reg
== PCSR
);
3040 as_fatal ("failed sanity check");
3042 install_operand (s
[1], tmpreg
);
3045 tmpreg
= get_num (opP
->con1
, 20);
3046 install_operand (s
[1], tmpreg
);
3048 case '_': /* used only for move16 absolute 32-bit address */
3049 tmpreg
= get_num (opP
->con1
, 80);
3050 addword (tmpreg
>> 16);
3051 addword (tmpreg
& 0xFFFF);
3054 as_fatal ("Internal error: Operand type %c unknown in line %d of file \"%s\"",
3055 s
[0], __LINE__
, __FILE__
);
3059 /* By the time whe get here (FINALLY) the_ins contains the complete
3060 instruction, ready to be emitted. . . */
3064 * get_regs := '/' + ?
3065 * | '-' + <register>
3066 * | '-' + <register> + ?
3071 * The idea here must be to scan in a set of registers but I don't
3072 * understand it. Looks awfully sloppy to me but I don't have any doc on
3080 get_regs (i
, str
, opP
)
3082 struct m68k_op
*opP
;
3085 /* 26, 25, 24, 23-16, 15-8, 0-7 */
3086 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
3087 unsigned long cur_regs
= 0;
3090 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
3091 else if(x==FPS) cur_regs|=(1<<25);\
3092 else if(x==FPC) cur_regs|=(1<<26);\
3093 else cur_regs|=(1<<(x-1)); }
3103 else if (*str
== '-')
3106 reg2
= m68k_reg_parse (&str
);
3107 if (reg2
< DATA
|| reg2
>= FPREG
+ 8 || reg1
== FPI
|| reg1
== FPS
|| reg1
== FPC
)
3109 opP
->error
= "unknown register in register list";
3112 while (reg1
<= reg2
)
3120 else if (*str
== '\0')
3127 opP
->error
= "unknow character in register list";
3130 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
3133 reg1
= m68k_reg_parse (&str
);
3134 if ((reg1
< DATA
|| reg1
>= FPREG
+ 8) && !(reg1
== FPI
|| reg1
== FPS
|| reg1
== FPC
))
3136 opP
->error
= "unknown register in register list";
3140 opP
->reg
= cur_regs
;
3145 reverse_16_bits (in
)
3151 static int mask
[16] =
3153 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3154 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3156 for (n
= 0; n
< 16; n
++)
3159 out
|= mask
[15 - n
];
3162 } /* reverse_16_bits() */
3171 static int mask
[8] =
3173 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3176 for (n
= 0; n
< 8; n
++)
3182 } /* reverse_8_bits() */
3185 install_operand (mode
, val
)
3192 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
3195 the_ins
.opcode
[0] |= val
<< 9;
3198 the_ins
.opcode
[1] |= val
<< 12;
3201 the_ins
.opcode
[1] |= val
<< 6;
3204 the_ins
.opcode
[1] |= val
;
3207 the_ins
.opcode
[2] |= val
<< 12;
3210 the_ins
.opcode
[2] |= val
<< 6;
3213 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3214 three words long! */
3216 the_ins
.opcode
[2] |= val
;
3219 the_ins
.opcode
[1] |= val
<< 7;
3222 the_ins
.opcode
[1] |= val
<< 10;
3226 the_ins
.opcode
[1] |= val
<< 5;
3231 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3234 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3237 the_ins
.opcode
[0] |= val
= 0xff;
3240 the_ins
.opcode
[0] |= val
<< 9;
3243 the_ins
.opcode
[1] |= val
;
3246 the_ins
.opcode
[1] |= val
;
3247 the_ins
.numo
++; /* What a hack */
3250 the_ins
.opcode
[1] |= val
<< 4;
3257 the_ins
.opcode
[0] |= (val
<< 6);
3260 the_ins
.opcode
[1] = (val
>> 16);
3261 the_ins
.opcode
[2] = val
& 0xffff;
3265 as_fatal ("failed sanity check.");
3267 } /* install_operand() */
3270 install_gen_operand (mode
, val
)
3277 the_ins
.opcode
[0] |= val
;
3280 /* This is a kludge!!! */
3281 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3290 the_ins
.opcode
[0] |= val
;
3292 /* more stuff goes here */
3294 as_fatal ("failed sanity check.");
3296 } /* install_gen_operand() */
3299 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3300 * then deal with the bitfield hack.
3304 crack_operand (str
, opP
)
3306 register struct m68k_op
*opP
;
3308 register int parens
;
3310 register char *beg_str
;
3317 for (parens
= 0; *str
&& (parens
> 0 || notend (str
)); str
++)
3321 else if (*str
== ')')
3325 opP
->error
= "Extra )";
3331 if (!*str
&& parens
)
3333 opP
->error
= "Missing )";
3338 if (m68k_ip_op (beg_str
, opP
) == FAIL
)
3345 c
= *++str
; /* JF bitfield hack */
3350 as_bad ("Missing operand");
3355 /* See the comment up above where the #define notend(... is */
3362 if (*s
== '{' || *s
== '}')
3366 /* This kludge here is for the division cmd, which is a kludge */
3367 if (index ("aAdD#", s
[1]))
3374 /* This is the guts of the machine-dependent assembler. STR points to a
3375 machine dependent instruction. This function is supposed to emit
3376 the frags/bytes it assembles to.
3380 insert_reg (regname
, regnum
)
3388 #ifdef REGISTER_PREFIX
3389 buf
[0] = REGISTER_PREFIX
;
3390 strcpy (buf
+ 1, regname
);
3394 symbol_table_insert (s
= symbol_new (regname
, reg_section
, regnum
, &zero_address_frag
));
3396 verify_symbol_chain_2 (s
);
3398 for (i
= 0; regname
[i
]; i
++)
3399 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3402 symbol_table_insert (s
= symbol_new (buf
, reg_section
, regnum
, &zero_address_frag
));
3403 verify_symbol_chain_2 (s
);
3412 static const struct init_entry init_table
[] =
3514 /* 68ec030 versions of same */
3517 /* 68ec030 access control unit, identical to 030 MMU status reg */
3527 for (i
= 0; init_table
[i
].name
; i
++)
3528 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3531 static int no_68851
, no_68881
;
3542 int shorts_this_frag
;
3543 static int done_first_time
;
3545 if (!done_first_time
)
3547 done_first_time
= 1;
3549 if (cpu_of_arch (current_architecture
) == 0)
3553 if (strcmp (TARGET_CPU
, "m68000") == 0
3554 || strcmp (TARGET_CPU
, "m68302") == 0)
3556 else if (strcmp (TARGET_CPU
, "m68010") == 0)
3558 else if (strcmp (TARGET_CPU
, "m68020") == 0
3559 || strcmp (TARGET_CPU
, "m68k") == 0)
3561 else if (strcmp (TARGET_CPU
, "m68030") == 0)
3563 else if (strcmp (TARGET_CPU
, "m68040") == 0)
3565 else if (strcmp (TARGET_CPU
, "cpu32") == 0
3566 || strcmp (TARGET_CPU
, "m68331") == 0
3567 || strcmp (TARGET_CPU
, "m68332") == 0
3568 || strcmp (TARGET_CPU
, "m68333") == 0
3569 || strcmp (TARGET_CPU
, "m68340") == 0)
3574 current_architecture
|= cpu_type
;
3576 #if 0 /* Could be doing emulation. */
3577 if (current_architecture
& m68881
)
3579 if (current_architecture
& m68000
)
3580 as_bad ("incompatible processors 68000 and 68881/2 specified");
3581 if (current_architecture
& m68010
)
3582 as_bad ("incompatible processors 68010 and 68881/2 specified");
3583 if (current_architecture
& m68040
)
3584 as_bad ("incompatible processors 68040 and 68881/2 specified");
3587 /* What other incompatibilities could we check for? */
3589 /* Toss in some default assumptions about coprocessors. */
3591 && (cpu_of_arch (current_architecture
)
3592 /* Can CPU32 have a 68881 coprocessor?? */
3593 & (m68020
| m68030
| cpu32
)))
3595 current_architecture
|= m68881
;
3598 && (cpu_of_arch (current_architecture
) & m68020up
) != 0
3599 && cpu_of_arch (current_architecture
) != m68040
)
3601 current_architecture
|= m68851
;
3603 if (no_68881
&& (current_architecture
& m68881
))
3604 as_bad ("options for 68881 and no-68881 both given");
3605 if (no_68851
&& (current_architecture
& m68851
))
3606 as_bad ("options for 68851 and no-68851 both given");
3607 done_first_time
= 1;
3610 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
));
3615 for (n
= the_ins
.numargs
; n
; --n
)
3616 if (the_ins
.operands
[n
].error
)
3618 er
= the_ins
.operands
[n
].error
;
3624 as_bad ("%s -- statement `%s' ignored", er
, str
);
3628 if (the_ins
.nfrag
== 0)
3630 /* No frag hacking involved; just put it out */
3631 toP
= frag_more (2 * the_ins
.numo
);
3632 fromP
= &the_ins
.opcode
[0];
3633 for (m
= the_ins
.numo
; m
; --m
)
3635 md_number_to_chars (toP
, (long) (*fromP
), 2);
3639 /* put out symbol-dependent info */
3640 for (m
= 0; m
< the_ins
.nrel
; m
++)
3642 switch (the_ins
.reloc
[m
].wid
)
3660 as_fatal ("Don't know how to figure width of %c in md_assemble()",
3661 the_ins
.reloc
[m
].wid
);
3664 fix_new_exp (frag_now
,
3665 ((toP
- frag_now
->fr_literal
)
3666 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3668 &the_ins
.reloc
[m
].exp
,
3669 the_ins
.reloc
[m
].pcrel
,
3675 /* There's some frag hacking */
3676 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3681 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3683 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3684 toP
= frag_more (wid
);
3686 shorts_this_frag
= 0;
3687 for (m
= wid
/ 2; m
; --m
)
3689 md_number_to_chars (toP
, (long) (*fromP
), 2);
3694 for (m
= 0; m
< the_ins
.nrel
; m
++)
3696 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
)
3698 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
;
3701 wid
= the_ins
.reloc
[m
].wid
;
3704 the_ins
.reloc
[m
].wid
= 0;
3705 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3707 fix_new_exp (frag_now
,
3708 ((toP
- frag_now
->fr_literal
)
3709 - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
),
3711 &the_ins
.reloc
[m
].exp
,
3712 the_ins
.reloc
[m
].pcrel
,
3715 (void) frag_var (rs_machine_dependent
, 10, 0,
3716 (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3717 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3719 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3720 shorts_this_frag
= 0;
3723 toP
= frag_more (n
* sizeof (short));
3726 md_number_to_chars (toP
, (long) (*fromP
), 2);
3732 for (m
= 0; m
< the_ins
.nrel
; m
++)
3736 wid
= the_ins
.reloc
[m
].wid
;
3739 the_ins
.reloc
[m
].wid
= 0;
3740 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3742 fix_new_exp (frag_now
,
3743 ((the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
)
3744 - shorts_this_frag
* 2),
3746 &the_ins
.reloc
[m
].exp
,
3747 the_ins
.reloc
[m
].pcrel
,
3752 /* See BREAK_UP_BIG_DECL definition, above. */
3753 static struct m68k_opcode
*
3757 #ifdef DO_BREAK_UP_BIG_DECL
3758 int lim1
= sizeof (m68k_opcodes
) / sizeof (m68k_opcodes
[0]);
3760 return m68k_opcodes_2
+ (i
- lim1
);
3762 return m68k_opcodes
+ i
;
3769 * md_begin -- set up hash tables with 68000 instructions.
3770 * similar to what the vax assembler does. ---phr
3772 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3773 a copy of it at runtime, adding in the information we want but isn't
3774 there. I think it'd be better to have an awk script hack the table
3775 at compile time. Or even just xstr the table and use it as-is. But
3776 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3779 register CONST
struct m68k_opcode
*ins
;
3780 register struct m68k_incant
*hack
, *slak
;
3781 register const char *retval
= 0; /* empty string, or error msg text */
3782 register unsigned int i
;
3785 if ((op_hash
= hash_new ()) == NULL
)
3786 as_fatal ("Virtual memory exhausted");
3788 obstack_begin (&robyn
, 4000);
3789 for (i
= 0; i
< numopcodes
; i
++)
3791 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3794 ins
= opcode_ptr (i
);
3795 /* We *could* ignore insns that don't match our arch here
3796 but just leaving them out of the hash. */
3797 slak
->m_operands
= ins
->args
;
3798 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3799 slak
->m_arch
= ins
->arch
;
3800 slak
->m_opcode
= ins
->opcode
;
3801 /* This is kludgey */
3802 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3803 if (i
+ 1 != numopcodes
3804 && !strcmp (ins
->name
, opcode_ptr (i
+ 1)->name
))
3806 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3811 slak
= slak
->m_next
;
3815 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3816 /* Didn't his mommy tell him about null pointers? */
3817 if (retval
&& *retval
)
3818 as_bad ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3821 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3822 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3824 for (i
= 0; i
< sizeof (notend_table
); i
++)
3826 notend_table
[i
] = 0;
3827 alt_notend_table
[i
] = 0;
3829 notend_table
[','] = 1;
3830 notend_table
['{'] = 1;
3831 notend_table
['}'] = 1;
3832 alt_notend_table
['a'] = 1;
3833 alt_notend_table
['A'] = 1;
3834 alt_notend_table
['d'] = 1;
3835 alt_notend_table
['D'] = 1;
3836 alt_notend_table
['#'] = 1;
3837 alt_notend_table
['f'] = 1;
3838 alt_notend_table
['F'] = 1;
3839 #ifdef REGISTER_PREFIX
3840 alt_notend_table
[REGISTER_PREFIX
] = 1;
3842 #ifdef OPTIONAL_REGISTER_PREFIX
3843 alt_notend_table
[OPTIONAL_REGISTER_PREFIX
] = 1;
3846 #ifndef MIT_SYNTAX_ONLY
3847 /* Insert pseudo ops, these have to go into the opcode table since
3848 gas expects pseudo ops to start with a dot */
3851 while (mote_pseudo_table
[n
].poc_name
)
3853 hack
= (struct m68k_incant
*)
3854 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3855 hash_insert (op_hash
,
3856 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3857 hack
->m_operands
= 0;
3868 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
3869 || (*s == ':' && strchr("aAdD#", s[1]))) \
3873 /* This funciton is called once, before the assembler exits. It is
3874 supposed to do any final cleanup for this part of the assembler.
3881 /* Equal to MAX_PRECISION in atof-ieee.c */
3882 #define MAX_LITTLENUMS 6
3884 /* Turn a string in input_line_pointer into a floating point constant of type
3885 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3886 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
3889 md_atof (type
, litP
, sizeP
)
3895 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3896 LITTLENUM_TYPE
*wordP
;
3928 return "Bad call to MD_ATOF()";
3930 t
= atof_ieee (input_line_pointer
, type
, words
);
3932 input_line_pointer
= t
;
3934 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3935 for (wordP
= words
; prec
--;)
3937 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3938 litP
+= sizeof (LITTLENUM_TYPE
);
3943 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
3944 for use in the a.out file, and stores them in the array pointed to by buf.
3945 This knows about the endian-ness of the target machine and does
3946 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
3947 2 (short) and 4 (long) Floating numbers are put out as a series of
3948 LITTLENUMS (shorts, here at least)
3951 md_number_to_chars (buf
, val
, n
)
3962 *buf
++ = (val
>> 8);
3966 *buf
++ = (val
>> 24);
3967 *buf
++ = (val
>> 16);
3968 *buf
++ = (val
>> 8);
3972 as_fatal ("failed sanity check.");
3977 md_apply_fix_2 (fixP
, val
)
3981 unsigned long upper_limit
;
3984 #ifdef IBM_COMPILER_SUX
3985 /* This is unnecessary but it convinces the native rs6000
3986 compiler to generate the code we want. */
3987 char *buf
= fixP
->fx_frag
->fr_literal
;
3988 buf
+= fixP
->fx_where
;
3989 #else /* IBM_COMPILER_SUX */
3990 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3991 #endif /* IBM_COMPILER_SUX */
3993 switch (fixP
->fx_size
)
3998 lower_limit
= -0x80;
4001 *buf
++ = (val
>> 8);
4003 upper_limit
= 0x7fff;
4004 lower_limit
= -0x8000;
4007 *buf
++ = (val
>> 24);
4008 *buf
++ = (val
>> 16);
4009 *buf
++ = (val
>> 8);
4011 upper_limit
= 0x7fffffff;
4012 lower_limit
= -0x80000000;
4015 BAD_CASE (fixP
->fx_size
);
4018 /* For non-pc-relative values, it's conceivable we might get something
4019 like "0xff" for a byte field. So extend the upper part of the range
4020 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4021 so that we can do any range checking at all. */
4022 if (!fixP
->fx_pcrel
)
4023 upper_limit
= upper_limit
* 2 + 1;
4025 if ((unsigned) val
> upper_limit
&& (val
> 0 || val
< lower_limit
))
4026 as_bad ("value out of range");
4029 #ifdef BFD_ASSEMBLER
4031 md_apply_fix (fixP
, valp
)
4035 md_apply_fix_2 (fixP
, *valp
);
4039 void md_apply_fix (fixP
, val
)
4043 md_apply_fix_2 (fixP
, val
);
4047 /* *fragP has been relaxed to its final size, and now needs to have
4048 the bytes inside it modified to conform to the new size There is UGLY
4052 md_convert_frag_1 (fragP
)
4053 register fragS
*fragP
;
4058 /* Address in object code of the displacement. */
4059 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
4061 #ifdef IBM_COMPILER_SUX
4062 /* This is wrong but it convinces the native rs6000 compiler to
4063 generate the code we want. */
4064 register char *buffer_address
= fragP
->fr_literal
;
4065 buffer_address
+= fragP
->fr_fix
;
4066 #else /* IBM_COMPILER_SUX */
4067 /* Address in gas core of the place to store the displacement. */
4068 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4069 #endif /* IBM_COMPILER_SUX */
4071 /* No longer true: know(fragP->fr_symbol); */
4073 /* The displacement of the address, from current location. */
4074 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
4075 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
4077 switch (fragP
->fr_subtype
)
4079 case TAB (BCC68000
, BYTE
):
4080 case TAB (ABRANCH
, BYTE
):
4081 know (issbyte (disp
));
4083 as_bad ("short branch with zero offset: use :w");
4084 fragP
->fr_opcode
[1] = disp
;
4087 case TAB (DBCC
, SHORT
):
4088 know (issword (disp
));
4091 case TAB (BCC68000
, SHORT
):
4092 case TAB (ABRANCH
, SHORT
):
4093 know (issword (disp
));
4094 fragP
->fr_opcode
[1] = 0x00;
4097 case TAB (ABRANCH
, LONG
):
4098 if (cpu_of_arch (current_architecture
) < m68020
)
4100 if (fragP
->fr_opcode
[0] == 0x61)
4102 fragP
->fr_opcode
[0] = 0x4E;
4103 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4104 subseg_change (text_section
, 0); /* @@ */
4117 else if (fragP
->fr_opcode
[0] == 0x60)
4119 fragP
->fr_opcode
[0] = 0x4E;
4120 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4121 subseg_change (text_section
, 0); /* @@ */
4122 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4123 fragP
->fr_offset
, 0, NO_RELOC
);
4129 as_bad ("Long branch offset not supported.");
4134 fragP
->fr_opcode
[1] = (char) 0xff;
4138 case TAB (BCC68000
, LONG
):
4139 /* only Bcc 68000 instructions can come here */
4140 /* change bcc into b!cc/jmp absl long */
4141 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4142 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4144 /* JF: these used to be fr_opcode[2,3], but they may be in a
4145 different frag, in which case refering to them is a no-no.
4146 Only fr_opcode[0,1] are guaranteed to work. */
4147 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4148 *buffer_address
++ = (char) 0xf9;
4149 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4150 subseg_change (text_section
, 0);
4151 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4152 fragP
->fr_offset
, 0, NO_RELOC
);
4156 case TAB (DBCC
, LONG
):
4157 /* only DBcc 68000 instructions can come here */
4158 /* change dbcc into dbcc/jmp absl long */
4159 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4160 *buffer_address
++ = 0x00; /* branch offset = 4 */
4161 *buffer_address
++ = 0x04;
4162 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4163 *buffer_address
++ = 0x06;
4164 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4165 *buffer_address
++ = (char) 0xf9;
4167 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4168 subseg_change (text_section
, 0);
4169 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4170 fragP
->fr_offset
, 0, NO_RELOC
);
4174 case TAB (FBRANCH
, SHORT
):
4175 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4178 case TAB (FBRANCH
, LONG
):
4179 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4182 case TAB (PCREL
, SHORT
):
4185 case TAB (PCREL
, LONG
):
4186 /* The thing to do here is force it to ABSOLUTE LONG, since
4187 PCREL is really trying to shorten an ABSOLUTE address anyway */
4188 /* JF FOO This code has not been tested */
4189 subseg_change (text_section
, 0);
4190 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, fragP
->fr_offset
,
4192 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4193 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
4194 (unsigned) fragP
->fr_opcode
[0],
4195 (unsigned long) fragP
->fr_address
);
4196 fragP
->fr_opcode
[1] &= ~0x3F;
4197 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4201 case TAB (PCLEA
, SHORT
):
4202 subseg_change (text_section
, 0);
4203 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
,
4204 fragP
->fr_offset
, 1, NO_RELOC
);
4205 fragP
->fr_opcode
[1] &= ~0x3F;
4206 fragP
->fr_opcode
[1] |= 0x3A;
4209 case TAB (PCLEA
, LONG
):
4210 subseg_change (text_section
, 0);
4211 fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
,
4212 fragP
->fr_offset
+ 2, 1, NO_RELOC
);
4213 *buffer_address
++ = 0x01;
4214 *buffer_address
++ = 0x70;
4222 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4223 fragP
->fr_fix
+= ext
;
4227 #ifndef BFD_ASSEMBLER
4230 md_convert_frag (headers
, fragP
)
4231 object_headers
*headers
;
4234 md_convert_frag_1 (fragP
);
4240 md_convert_frag (abfd
, sec
, fragP
)
4245 md_convert_frag_1 (fragP
);
4249 /* Force truly undefined symbols to their maximum size, and generally set up
4250 the frag list to be relaxed
4253 md_estimate_size_before_relax (fragP
, segment
)
4254 register fragS
*fragP
;
4258 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4260 old_fix
= fragP
->fr_fix
;
4262 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4263 switch (fragP
->fr_subtype
)
4266 case TAB (ABRANCH
, SZ_UNDEF
):
4268 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4269 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4271 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4274 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
4276 /* On 68000, or for absolute value, switch to abs long */
4277 /* FIXME, we should check abs val, pick short or long */
4278 if (fragP
->fr_opcode
[0] == 0x61)
4280 fragP
->fr_opcode
[0] = 0x4E;
4281 fragP
->fr_opcode
[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
4282 subseg_change (text_section
, 0);
4283 fix_new (fragP
, fragP
->fr_fix
, 4,
4284 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4288 else if (fragP
->fr_opcode
[0] == 0x60)
4290 fragP
->fr_opcode
[0] = 0x4E;
4291 fragP
->fr_opcode
[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
4292 subseg_change (text_section
, 0);
4293 fix_new (fragP
, fragP
->fr_fix
, 4,
4294 fragP
->fr_symbol
, fragP
->fr_offset
, 0, NO_RELOC
);
4300 as_warn ("Long branch offset to extern symbol not supported.");
4304 { /* Symbol is still undefined. Make it simple */
4305 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4306 fragP
->fr_offset
+ 4, 1, NO_RELOC
);
4308 fragP
->fr_opcode
[1] = (char) 0xff;
4314 } /* case TAB(ABRANCH,SZ_UNDEF) */
4316 case TAB (FBRANCH
, SZ_UNDEF
):
4318 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flagseen
['l'])
4320 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4325 fragP
->fr_subtype
= TAB (FBRANCH
, LONG
);
4329 } /* TAB(FBRANCH,SZ_UNDEF) */
4331 case TAB (PCREL
, SZ_UNDEF
):
4333 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flagseen
['l'])
4335 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4340 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4344 } /* TAB(PCREL,SZ_UNDEF) */
4346 case TAB (BCC68000
, SZ_UNDEF
):
4348 if ((fragP
->fr_symbol
!= NULL
)
4349 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4351 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4354 /* only Bcc 68000 instructions can come here */
4355 /* change bcc into b!cc/jmp absl long */
4356 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4359 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4360 /* JF: these were fr_opcode[2,3] */
4361 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4362 buffer_address
[1] = (char) 0xf8;
4363 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4364 subseg_change (text_section
, 0);
4365 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4366 fragP
->fr_offset
, 0, NO_RELOC
);
4371 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4372 /* JF: these were fr_opcode[2,3] */
4373 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4374 buffer_address
[1] = (char) 0xf9;
4375 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4376 subseg_change (text_section
, 0);
4377 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4378 fragP
->fr_offset
, 0, NO_RELOC
);
4383 } /* case TAB(BCC68000,SZ_UNDEF) */
4385 case TAB (DBCC
, SZ_UNDEF
):
4387 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4389 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4393 /* only DBcc 68000 instructions can come here */
4394 /* change dbcc into dbcc/jmp absl long */
4395 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4396 buffer_address
[0] = 0x00; /* branch offset = 4 */
4397 buffer_address
[1] = 0x04;
4398 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4402 /* JF: these were fr_opcode[5-7] */
4403 buffer_address
[3] = 0x04; /* plus 4 */
4404 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4405 buffer_address
[5] = (char) 0xf8;
4406 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4407 subseg_change (text_section
, 0);
4408 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
4409 fragP
->fr_offset
, 0, NO_RELOC
);
4414 /* JF: these were fr_opcode[5-7] */
4415 buffer_address
[3] = 0x06; /* Plus 6 */
4416 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4417 buffer_address
[5] = (char) 0xf9;
4418 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4419 subseg_change (text_section
, 0);
4420 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
4421 fragP
->fr_offset
, 0, NO_RELOC
);
4427 } /* case TAB(DBCC,SZ_UNDEF) */
4429 case TAB (PCLEA
, SZ_UNDEF
):
4431 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
|| flagseen
['l'])
4433 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4438 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4442 } /* TAB(PCLEA,SZ_UNDEF) */
4447 } /* switch on subtype looking for SZ_UNDEF's. */
4449 /* now that SZ_UNDEF are taken care of, check others */
4450 switch (fragP
->fr_subtype
)
4452 case TAB (BCC68000
, BYTE
):
4453 case TAB (ABRANCH
, BYTE
):
4454 /* We can't do a short jump to the next instruction,
4455 so we force word mode. */
4456 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
4457 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
4459 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4466 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4469 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4470 /* the bit-field entries in the relocation_info struct plays hell
4471 with the byte-order problems of cross-assembly. So as a hack,
4472 I added this mach. dependent ri twiddler. Ugly, but it gets
4474 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4475 are symbolnum, most sig. byte first. Last byte is broken up with
4476 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4477 nibble as nuthin. (on Sun 3 at least) */
4478 /* Translate the internal relocation information into target-specific
4482 md_ri_to_chars (the_bytes
, ri
)
4484 struct reloc_info_generic
*ri
;
4487 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4488 /* now the fun stuff */
4489 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4490 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4491 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4492 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4493 ((ri
->r_extern
<< 4) & 0x10));
4496 #endif /* comment */
4498 #ifndef BFD_ASSEMBLER
4500 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4503 relax_addressT segment_address_in_file
;
4506 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4507 * Out: GNU LD relocation length code: 0, 1, or 2.
4510 static CONST
unsigned char nbytes_r_length
[] =
4514 know (fixP
->fx_addsy
!= NULL
);
4516 md_number_to_chars (where
,
4517 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4520 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4521 ? S_GET_TYPE (fixP
->fx_addsy
)
4522 : fixP
->fx_addsy
->sy_number
);
4524 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4525 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4526 where
[6] = r_symbolnum
& 0x0ff;
4527 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4528 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4534 #endif /* OBJ_AOUT or OBJ_BOUT */
4536 #ifndef WORKING_DOT_WORD
4537 CONST
int md_short_jump_size
= 4;
4538 CONST
int md_long_jump_size
= 6;
4541 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4543 addressT from_addr
, to_addr
;
4549 offset
= to_addr
- (from_addr
+ 2);
4551 md_number_to_chars (ptr
, (valueT
) 0x6000, 2);
4552 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 2);
4556 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4558 addressT from_addr
, to_addr
;
4564 if (cpu_of_arch (current_architecture
) < m68020
)
4566 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4567 md_number_to_chars (ptr
, (valueT
) 0x4EF9, 2);
4568 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4569 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (offsetT
) 0,
4574 offset
= to_addr
- (from_addr
+ 2);
4575 md_number_to_chars (ptr
, (valueT
) 0x60ff, 2);
4576 md_number_to_chars (ptr
+ 2, (valueT
) offset
, 4);
4581 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
4584 10: Absolute 1:8 only
4585 20: Absolute 0:7 only
4586 30: absolute 0:15 only
4587 40: Absolute 0:31 only
4588 50: absolute 0:127 only
4589 55: absolute -64:63 only
4590 60: absolute -128:127 only
4591 70: absolute 0:4095 only
4598 struct m68k_exp
*exp
;
4606 if (*exp
->e_beg
== '0')
4608 if (exp
->e_beg
[1] == 'x')
4609 sscanf (exp
->e_beg
+ 2, "%x", &l
);
4611 sscanf (exp
->e_beg
+ 1, "%O", &l
);
4614 return atol (exp
->e_beg
);
4622 /* Can't do anything */
4625 if (!exp
->e_beg
|| !exp
->e_end
)
4627 seg (exp
) = absolute_section
;
4630 offs (exp
) = (ok
== 10) ? 1 : 0;
4631 as_warn ("Null expression defaults to %ld", offs (exp
));
4636 if ( /* ok!=80 && */ (exp
->e_end
[-1] == ':' || exp
->e_end
[-1] == '.')
4637 && (exp
->e_end
- exp
->e_beg
) >= 2)
4639 switch (exp
->e_end
[0])
4659 if (exp
->e_end
[-1] == ':')
4660 as_bad ("Unknown size for expression \"%c\"", exp
->e_end
[0]);
4664 c_save
= exp
->e_end
[1];
4665 exp
->e_end
[1] = '\0';
4666 save_in
= input_line_pointer
;
4667 input_line_pointer
= exp
->e_beg
;
4668 section
= expression (&exp
->e_exp
);
4669 seg (exp
) = section
;
4670 if (exp
->e_exp
.X_op
== O_absent
)
4672 /* Do the same thing the VAX asm does */
4673 seg (exp
) = absolute_section
;
4674 op (exp
) = O_constant
;
4680 as_warn ("expression out of range: defaulting to 1");
4684 else if (exp
->e_exp
.X_op
== O_constant
)
4689 if (offs (exp
) < 1 || offs (exp
) > 8)
4691 as_warn ("expression out of range: defaulting to 1");
4696 if (offs (exp
) < 0 || offs (exp
) > 7)
4700 if (offs (exp
) < 0 || offs (exp
) > 15)
4704 if (offs (exp
) < 0 || offs (exp
) > 32)
4708 if (offs (exp
) < 0 || offs (exp
) > 127)
4712 if (offs (exp
) < -64 || offs (exp
) > 63)
4716 if (offs (exp
) < -128 || offs (exp
) > 127)
4720 if (offs (exp
) < 0 || offs (exp
) > 4095)
4723 as_warn ("expression out of range: defaulting to 0");
4731 else if (exp
->e_exp
.X_op
== O_big
)
4733 if (offs (exp
) <= 0 /* flonum */
4734 && (ok
== 80 /* no bignums */
4735 || (ok
> 10 /* small-int ranges including 0 ok */
4736 /* If we have a flonum zero, a zero integer should
4737 do as well (e.g., in moveq). */
4738 && generic_floating_point_number
.exponent
== 0
4739 && generic_floating_point_number
.low
[0] == 0)))
4741 /* HACK! Turn it into a long */
4742 LITTLENUM_TYPE words
[6];
4744 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4745 seg (exp
) = absolute_section
;
4746 op (exp
) = O_constant
;
4749 offs (exp
) = words
[1] | (words
[0] << 16);
4753 seg (exp
) = absolute_section
;
4754 op (exp
) = O_constant
;
4757 offs (exp
) = (ok
== 10) ? 1 : 0;
4758 as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp
->e_beg
, offs (exp
));
4763 if (ok
>= 10 && ok
<= 70)
4765 seg (exp
) = absolute_section
;
4766 op (exp
) = O_constant
;
4769 offs (exp
) = (ok
== 10) ? 1 : 0;
4770 as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp
->e_beg
, offs (exp
));
4774 if (input_line_pointer
!= exp
->e_end
+ 1)
4775 as_bad ("Ignoring junk after expression");
4776 exp
->e_end
[1] = c_save
;
4777 input_line_pointer
= save_in
;
4783 if (!isbyte (offs (exp
)))
4784 as_warn ("expression doesn't fit in BYTE");
4787 if (!isword (offs (exp
)))
4788 as_warn ("expression doesn't fit in WORD");
4796 /* These are the back-ends for the various machine dependent pseudo-ops. */
4797 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4803 subseg_set (data_section
, 1);
4804 demand_empty_rest_of_line ();
4811 subseg_set (data_section
, 2);
4812 demand_empty_rest_of_line ();
4819 /* We don't support putting frags in the BSS segment, we fake it
4820 by marking in_bss, then looking at s_skip for clues. */
4822 subseg_set (bss_section
, 0);
4823 demand_empty_rest_of_line ();
4831 register long temp_fill
;
4833 temp
= 1; /* JF should be 2? */
4834 temp_fill
= get_absolute_expression ();
4835 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4836 frag_align (temp
, (int) temp_fill
);
4837 demand_empty_rest_of_line ();
4844 demand_empty_rest_of_line ();
4847 /* s_space is defined in read.c .skip is simply an alias to it. */
4851 * Invocation line includes a switch not recognized by the base assembler.
4852 * See if it's a processor-specific option. These are:
4854 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4855 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4856 * Select the architecture. Instructions or features not
4857 * supported by the selected architecture cause fatal
4858 * errors. More than one may be specified. The default is
4859 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4860 * for -m68000, and -m68882 is a synonym for -m68881.
4861 * -[A]m[c]no-68851, -[A]m[c]no-68881
4862 * Don't accept 688?1 instructions. (The "c" is kind of silly,
4863 * so don't use or document it, but that's the way the parsing
4866 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
4867 * (e.g. m68020) also requests that float instructions be included. This
4868 * is the default setup, mostly to avoid hassling users. A better
4869 * rearrangement of this structure would be to add an option to DENY
4870 * floating point opcodes, for people who want to really know there's none
4871 * of that funny floaty stuff going on. FIXME-later.
4873 #ifndef MAYBE_FLOAT_TOO
4874 #define MAYBE_FLOAT_TOO /* m68881 */ 0 /* this is handled later */
4878 md_parse_option (argP
, cntP
, vecP
)
4885 case 'l': /* -l means keep external to 2 bit offset
4886 rather than 16 bit one */
4889 case 'S': /* -S means that jbsr's always turn into
4895 /* intentional fall-through */
4902 } /* allow an optional "c" */
4904 if (!strcmp (*argP
, "68000")
4905 || !strcmp (*argP
, "68008")
4906 || !strcmp (*argP
, "68302"))
4908 current_architecture
|= m68000
;
4910 else if (!strcmp (*argP
, "68010"))
4913 omagic
= 1 << 16 | OMAGIC
;
4915 current_architecture
|= m68010
;
4917 else if (!strcmp (*argP
, "68020"))
4919 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
4921 else if (!strcmp (*argP
, "68030"))
4923 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
4925 else if (!strcmp (*argP
, "68040"))
4927 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
4930 else if (!strcmp (*argP
, "68881"))
4932 current_architecture
|= m68881
;
4934 else if (!strcmp (*argP
, "68882"))
4936 current_architecture
|= m68882
;
4938 #endif /* NO_68881 */
4939 /* Even if we aren't configured to support the processor,
4940 it should still be possible to assert that the user
4941 doesn't have it... */
4942 else if (!strcmp (*argP
, "no-68881")
4943 || !strcmp (*argP
, "no-68882"))
4948 else if (!strcmp (*argP
, "68851"))
4950 current_architecture
|= m68851
;
4952 #endif /* NO_68851 */
4953 else if (!strcmp (*argP
, "no-68851"))
4957 else if (!strcmp (*argP
, "pu32") /* "cpu32" minus 'c' */
4958 || !strcmp (*argP
, "68331")
4959 || !strcmp (*argP
, "68332")
4960 || !strcmp (*argP
, "68333")
4961 || !strcmp (*argP
, "68340"))
4963 current_architecture
|= cpu32
;
4967 as_warn ("Unknown architecture, \"%s\". option ignored", *argP
);
4968 } /* switch on architecture */
4976 if (!strcmp (*argP
, "pic"))
4979 break; /* -pic, Position Independent Code */
4995 /* TEST2: Test md_assemble() */
4996 /* Warning, this routine probably doesn't work anymore */
5000 struct m68k_it the_ins
;
5008 if (!gets (buf
) || !*buf
)
5010 if (buf
[0] == '|' || buf
[1] == '.')
5012 for (cp
= buf
; *cp
; cp
++)
5017 memset (&the_ins
, '\0', sizeof (the_ins
));
5018 m68k_ip (&the_ins
, buf
);
5021 printf ("Error %s in %s\n", the_ins
.error
, buf
);
5025 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
5026 for (n
= 0; n
< the_ins
.numo
; n
++)
5027 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
5029 print_the_insn (&the_ins
.opcode
[0], stdout
);
5030 (void) putchar ('\n');
5032 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
5034 if (the_ins
.operands
[n
].error
)
5036 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
5039 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
5040 if (the_ins
.operands
[n
].b_const
)
5041 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
5042 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
5043 if (the_ins
.operands
[n
].b_iadd
)
5044 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
5045 (void) putchar ('\n');
5057 while (*str
&& *str
!= ' ')
5059 if (str
[-1] == ':' || str
[1] == '=')
5066 /* Possible states for relaxation:
5068 0 0 branch offset byte (bra, etc)
5072 1 0 indexed offsets byte a0@(32,d4:w:1) etc
5076 2 0 two-offset index word-word a0@(32,d4)@(45) etc
5083 /* We have no need to default values of symbols. */
5087 md_undefined_symbol (name
)
5093 /* Parse an operand that is machine-specific.
5094 We just return without modifying the expression if we have nothing
5099 md_operand (expressionP
)
5100 expressionS
*expressionP
;
5104 /* Round up a section size to the appropriate boundary. */
5106 md_section_align (segment
, size
)
5110 return size
; /* Byte alignment is fine */
5113 /* Exactly what point is a PC-relative offset relative TO?
5114 On the 68k, they're relative to the address of the offset, plus
5115 its size. (??? Is this right? FIXME-SOON!) */
5117 md_pcrel_from (fixP
)
5120 return (fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
5123 #ifndef BFD_ASSEMBLER
5125 tc_coff_symbol_emit_hook ()
5130 tc_coff_sizemachdep (frag
)
5133 switch (frag
->fr_subtype
& 0x3)
5147 /* end of tc-m68k.c */