1 /* m68k.c All the m68020 specific stuff in one convenient, huge,
2 slow to compile, easy to find file.
3 Copyright (C) 1987, 1991 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* note that this file includes real declarations and thus can only be included by one source file per executable. */
28 #include "m68k-opcode.h"
30 /* This array holds the chars that always start a comment. If the
31 pre-processor is disabled, these aren't very useful */
32 const char comment_chars
[] = "|";
34 /* This array holds the chars that only start a comment at the beginning of
35 a line. If the line seems to have the form '# 123 filename'
36 .line and .file directives will appear in the pre-processed output */
37 /* Note that input_file.c hand checks for '#' at the beginning of the
38 first line of the input file. This is because the compiler outputs
39 #NO_APP at the beginning of its output. */
40 /* Also note that comments like this one will always work. */
41 const char line_comment_chars
[] = "#";
43 /* Chars that can be used to separate mant from exp in floating point nums */
44 const char EXP_CHARS
[] = "eE";
46 /* Chars that mean this number is a floating point constant */
50 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
52 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
53 changed in read.c . Ideally it shouldn't have to know about it at all,
54 but nothing is ideal around here.
57 int md_reloc_size
= 8; /* Size of relocation record */
59 /* Its an arbitrary name: This means I don't approve of it */
60 /* See flames below */
61 static struct obstack robyn
;
63 #define TAB(x,y) (((x)<<2)+(y))
64 #define TABTYPE(xy) ((xy) >> 2)
81 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
84 /* Internal form of an operand. */
86 char *error
; /* Couldn't parse it */
87 int mode
; /* What mode this instruction is in. */
88 unsigned long reg
; /* Base register */
89 struct m68k_exp
*con1
;
90 int ireg
; /* Index register */
91 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
92 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
93 struct m68k_exp
*con2
;
96 /* internal form of a 68020 instruction */
99 char *args
; /* list of opcode info */
102 int numo
; /* Number of shorts in opcode */
105 struct m68k_op operands
[6];
107 int nexp
; /* number of exprs in use */
108 struct m68k_exp exprs
[4];
110 int nfrag
; /* Number of frags we have to produce */
112 int fragoff
; /* Where in the current opcode[] the frag ends */
118 int nrel
; /* Num of reloc strucs in use */
126 } reloc
[5]; /* Five is enough??? */
129 struct m68_it the_ins
; /* the instruction being assembled */
132 /* Macros for adding things to the m68_it struct */
134 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
136 /* Like addword, but goes BEFORE general operands */
137 #define insop(w) {int z;\
138 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
139 the_ins.opcode[z]=the_ins.opcode[z-1];\
140 for(z=0;z<the_ins.nrel;z++)\
141 the_ins.reloc[z].n+=2;\
142 the_ins.opcode[opcode->m_codenum]=w;\
147 #define add_exp(beg,end) (\
148 the_ins.exprs[the_ins.nexp].e_beg=beg,\
149 the_ins.exprs[the_ins.nexp].e_end=end,\
150 &the_ins.exprs[the_ins.nexp++]\
154 /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
155 #define add_fix(width,exp,pc_rel) {\
156 the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
157 (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
158 the_ins.reloc[the_ins.nrel].add=adds((exp));\
159 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
160 the_ins.reloc[the_ins.nrel].off=offs((exp));\
161 the_ins.reloc[the_ins.nrel].wid=width;\
162 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
165 #define add_frag(add,off,type) {\
166 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
167 the_ins.fragb[the_ins.nfrag].fadd=add;\
168 the_ins.fragb[the_ins.nfrag].foff=off;\
169 the_ins.fragb[the_ins.nfrag++].fragty=type;\
172 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
174 #define seg(exp) ((exp)->e_exp.X_seg)
175 #define adds(exp) ((exp)->e_exp.X_add_symbol)
176 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
177 #define offs(exp) ((exp)->e_exp.X_add_number)
182 unsigned long m_opcode
;
185 struct m68_incant
*m_next
;
188 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
189 #define gettwo(x) (((x)->m_opcode)&0xffff)
194 static char *crack_operand(char *str
, struct m68k_op
*opP
);
195 static int get_num(struct m68k_exp
*exp
, int ok
);
196 static int get_regs(int i
, char *str
, struct m68k_op
*opP
);
197 static int reverse_16_bits(int in
);
198 static int reverse_8_bits(int in
);
199 static int try_index(char **s
, struct m68k_op
*opP
);
200 static void install_gen_operand(int mode
, int val
);
201 static void install_operand(int mode
, int val
);
202 static void s_bss(void);
203 static void s_data1(void);
204 static void s_data2(void);
205 static void s_even(void);
206 static void s_proc(void);
210 static char *crack_operand();
211 static int get_num();
212 static int get_regs();
213 static int reverse_16_bits();
214 static int reverse_8_bits();
215 static int try_index();
216 static void install_gen_operand();
217 static void install_operand();
219 static void s_data1();
220 static void s_data2();
221 static void s_even();
222 static void s_proc();
224 #endif /* __STDC__ */
226 /* BCC68000 is for patching in an extra jmp instruction for long offsets
227 on the 68000. The 68000 doesn't support long branches with branchs */
229 /* This table desribes how you change sizes for the various types of variable
230 size expressions. This version only supports two kinds. */
232 /* Note that calls to frag_var need to specify the maximum expansion needed */
233 /* This is currently 10 bytes for DBCC */
236 How far Forward this mode will reach:
237 How far Backward this mode will reach:
238 How many bytes this mode will add to the size of the frag
239 Which mode to go to if the offset won't fit in this one
243 { 1, 1, 0, 0 }, /* First entries aren't used */
244 { 1, 1, 0, 0 }, /* For no good reason except */
245 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
248 { (127), (-128), 0, TAB(BRANCH
,SHORT
)},
249 { (32767), (-32768), 2, TAB(BRANCH
,LONG
) },
253 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
254 { (32767), (-32768), 2, TAB(FBRANCH
,LONG
)},
258 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
259 { (32767), (-32768), 2, TAB(PCREL
,LONG
)},
263 { (127), (-128), 0, TAB(BCC68000
,SHORT
)},
264 { (32767), (-32768), 2, TAB(BCC68000
,LONG
) },
265 { 0, 0, 6, 0 }, /* jmp long space */
268 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
269 { (32767), (-32768), 2, TAB(DBCC
,LONG
) },
270 { 0, 0, 10, 0 }, /* bra/jmp long space */
273 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
274 { 32767, -32768, 2, TAB(PCLEA
,LONG
) },
280 /* These are the machine dependent pseudo-ops. These are included so
281 the assembler can work on the output from the SUN C compiler, which
285 /* This table describes all the machine specific pseudo-ops the assembler
286 has to support. The fields are:
287 pseudo-op name without dot
288 function to call to execute this pseudo-op
289 Integer arg to pass to the function
291 const pseudo_typeS md_pseudo_table
[] = {
292 { "data1", s_data1
, 0 },
293 { "data2", s_data2
, 0 },
295 { "even", s_even
, 0 },
296 { "skip", s_space
, 0 },
297 { "proc", s_proc
, 0 },
302 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
303 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
305 #define issbyte(x) ((x)>=-128 && (x)<=127)
306 #define isubyte(x) ((x)>=0 && (x)<=255)
307 #define issword(x) ((x)>=-32768 && (x)<=32767)
308 #define isuword(x) ((x)>=0 && (x)<=65535)
310 #define isbyte(x) ((x)>=-128 && (x)<=255)
311 #define isword(x) ((x)>=-32768 && (x)<=65535)
312 #define islong(x) (1)
314 extern char *input_line_pointer
;
316 /* Operands we can parse: (And associated modes)
322 reg: address or data register
323 areg: address register
324 apc: address register, PC, ZPC or empty string
325 num: 16 or 32 bit num
327 sz: w or l if omitted, l assumed
328 scale: 1 2 4 or 8 if omitted, 1 assumed
330 7.4 IMMED #num --> NUM
331 0.? DREG dreg --> dreg
332 1.? AREG areg --> areg
333 2.? AINDR areg@ --> *(areg)
334 3.? AINC areg@+ --> *(areg++)
335 4.? ADEC areg@- --> *(--areg)
336 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
337 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
338 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
339 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
340 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
341 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
342 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
343 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
344 7.0 ABSL num:sz --> *(num)
345 num --> *(num) (sz L assumed)
346 *** MSCR otherreg --> Magic
348 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
358 a1@(5,d2:w:1) @(45,d6:l:4)
363 #name@(numw) -->turn into PC rel mode
364 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
386 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
387 8-15==addr reg for operands that take both types */
388 #define DATA 1 /* 1- 8 == data registers 0-7 */
389 #define ADDR (DATA+8) /* 9-16 == address regs 0-7 */
390 #define FPREG (ADDR+8) /* 17-24 Eight FP registers */
391 #define COPNUM (FPREG+8) /* 25-32 Co-processor #1-#8 */
393 #define PC (COPNUM+8) /* 33 Program counter */
394 #define ZPC (PC+1) /* 34 Hack for Program space, but 0 addressing */
395 #define SR (ZPC+1) /* 35 Status Reg */
396 #define CCR (SR+1) /* 36 Condition code Reg */
398 /* These have to be in order for the movec instruction to work. */
399 #define USP (CCR+1) /* 37 User Stack Pointer */
400 #define ISP (USP+1) /* 38 Interrupt stack pointer */
401 #define SFC (ISP+1) /* 39 */
402 #define DFC (SFC+1) /* 40 */
403 #define CACR (DFC+1) /* 41 */
404 #define VBR (CACR+1) /* 42 */
405 #define CAAR (VBR+1) /* 43 */
406 #define MSP (CAAR+1) /* 44 */
408 #define FPI (MSP+1) /* 45 */
409 #define FPS (FPI+1) /* 46 */
410 #define FPC (FPS+1) /* 47 */
412 * these defines should be in m68k.c but
413 * i put them here to keep all the m68851 stuff
415 * JF--Make sure these #s don't clash with the ones in m68k.c
418 #define TC (FPC+1) /* 48 */
419 #define DRP (TC+1) /* 49 */
420 #define SRP (DRP+1) /* 50 */
421 #define CRP (SRP+1) /* 51 */
422 #define CAL (CRP+1) /* 52 */
423 #define VAL (CAL+1) /* 53 */
424 #define SCC (VAL+1) /* 54 */
425 #define AC (SCC+1) /* 55 */
426 #define BAD (AC+1) /* 56,57,58,59, 60,61,62,63 */
427 #define BAC (BAD+8) /* 64,65,66,67, 68,69,70,71 */
428 #define PSR (BAC+8) /* 72 */
429 #define PCSR (PSR+1) /* 73 */
432 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
437 /* JF these tables here are for speed at the expense of size */
438 /* You can replace them with the #if 0 versions if you really
439 need space and don't mind it running a bit slower */
441 static char mklower_table
[256];
442 #define mklower(c) (mklower_table[(unsigned char)(c)])
443 static char notend_table
[256];
444 static char alt_notend_table
[256];
445 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
446 alt_notend_table[(unsigned char)(s[1])])))
449 #define mklower(c) (isupper(c) ? tolower(c) : c)
453 /* JF modified this to handle cases where the first part of a symbol name
454 looks like a register */
467 c1
=mklower(ccp
[0][0]);
468 #ifdef REGISTER_PREFIX
469 if(c1
!=REGISTER_PREFIX
)
471 c1
=mklower(ccp
[0][1]);
472 c2
=mklower(ccp
[0][2]);
473 c3
=mklower(ccp
[0][3]);
474 c4
=mklower(ccp
[0][4]);
476 c2
=mklower(ccp
[0][1]);
477 c3
=mklower(ccp
[0][2]);
478 c4
=mklower(ccp
[0][3]);
482 if(c2
>='0' && c2
<='7') {
487 else if (c2
== 'c') {
497 if (c4
>= '0' && c4
<= '7') {
499 ret
= BAD
+ c4
- '0';
503 if (c4
>= '0' && c4
<= '7') {
505 ret
= BAC
+ c4
- '0';
513 if (c2
== 'a' && c3
== 'l') {
518 /* This supports both CCR and CC as the ccr reg. */
519 if(c2
=='c' && c3
=='r') {
525 } else if(c2
=='a' && (c3
=='a' || c3
=='c') && c4
=='r') {
527 ret
= c3
=='a' ? CAAR
: CACR
;
530 else if (c2
== 'r' && c3
== 'p') {
537 if(c2
>='0' && c2
<='7') {
540 } else if(c2
=='f' && c3
=='c') {
545 else if (c2
== 'r' && c3
== 'p') {
553 if(c3
>='0' && c3
<='7') {
562 n
= (c4
== 'r' ? 4 : 3);
565 n
= (c4
== 'r' ? 4 : 3);
571 if(c2
=='s' && c3
=='p') {
577 if(c2
=='s' && c3
=='p') {
585 if(c3
== 's' && c4
=='r') {
596 else if (c2
== 's' && c3
== 'r') {
604 if (c2
== 'c' && c3
== 'c') {
607 } else if (c2
== 'r' && c3
== 'p') {
618 } else if(c2
=='f' && c3
=='c') {
632 if(c2
=='s' && c3
=='p') {
639 if (c2
== 'a' && c3
== 'l') {
644 if(c2
=='b' && c3
=='r') {
650 if(c2
=='p' && c3
=='c') {
659 #ifdef REGISTER_PREFIX
662 if(isalnum(ccp
[0][n
]) || ccp
[0][n
]=='_')
671 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
676 register struct m68k_op
*opP
;
683 /* Find the end of the string */
686 opP
->error
="Missing operand";
689 for(strend
=str
;*strend
;strend
++)
693 /* Guess what: A constant. Shar and enjoy */
696 opP
->con1
=add_exp(str
,strend
);
700 i
=m68k_reg_parse(&str
);
701 if((i
==FAIL
|| *str
!='\0') && *str
!='@') {
704 if(i
!=FAIL
&& (*str
=='/' || *str
=='-')) {
706 return get_regs(i
,str
,opP
);
708 if((stmp
=strchr(str
,'@')) != '\0') {
709 opP
->con1
=add_exp(str
,stmp
-1);
715 if(*stmp
++!='(' || *strend
--!=')') {
716 opP
->error
="Malformed operand";
719 i
=try_index(&stmp
,opP
);
720 opP
->con2
=add_exp(stmp
,strend
);
721 if(i
==FAIL
) opP
->mode
=AMIND
;
722 else opP
->mode
=APODX
;
726 opP
->con1
=add_exp(str
,strend
);
731 if(i
>=DATA
+0 && i
<=DATA
+7)
733 else if(i
>=ADDR
+0 && i
<=ADDR
+7)
739 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
) { /* Can't indirect off non address regs */
740 opP
->error
="Invalid indirect register";
760 opP
->error
="Junk after indirect";
763 /* Some kind of indexing involved. Lets find out how bad it is */
764 i
=try_index(&str
,opP
);
765 /* Didn't start with an index reg, maybe its offset or offset,reg */
773 opP
->error
="Missing )";
775 case ',': i
=0; break;
776 case '(': i
++; break;
777 case ')': --i
; break;
780 /* if(str[-3]==':') {
797 opP->error="Specified size isn't :w or :l";
800 opP->con1=add_exp(beg_str,str-4);
801 opP->con1->e_siz=siz;
803 opP
->con1
=add_exp(beg_str
,str
-2);
804 /* Should be offset,reg */
806 i
=try_index(&str
,opP
);
808 opP
->error
="Malformed index reg";
813 /* We've now got offset) offset,reg) or reg) */
816 /* Th-the-thats all folks */
817 if(opP
->reg
==FAIL
) opP
->mode
=AINDX
; /* Other form of indirect */
818 else if(opP
->ireg
==FAIL
) opP
->mode
=AOFF
;
819 else opP
->mode
=AINDX
;
822 /* Next thing had better be another @ */
823 if(*str
!='@' || str
[1]!='(') {
824 opP
->error
="junk after indirect";
828 if(opP
->ireg
!=FAIL
) {
830 i
=try_index(&str
,opP
);
832 opP
->error
="Two index registers! not allowed!";
836 i
=try_index(&str
,opP
);
844 opP
->error
="Missing )";
846 case ',': i
=0; break;
847 case '(': i
++; break;
848 case ')': --i
; break;
851 opP
->con2
=add_exp(beg_str
,str
-2);
853 if(opP
->ireg
!=FAIL
) {
854 opP
->error
="Can't have two index regs";
857 i
=try_index(&str
,opP
);
859 opP
->error
="malformed index reg";
863 } else if(opP
->ireg
!=FAIL
)
870 opP
->error
="Junk after indirect";
876 static int try_index(s
,opP
)
882 #define SKIP_W() { ss++; if(*ss==' ') ss++;}
886 i
=m68k_reg_parse(&ss
);
887 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
901 opP
->error
="Missing : in index register";
916 opP
->error
="Index register size spec not :w or :l";
931 opP
->error
="index multiplier not 1, 2, 4 or 8";
938 opP
->error
="Missing )";
947 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
951 struct m68k_op thark
;
956 bzero(&thark
,sizeof(thark
));
957 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
959 printf("op1 error %s in %s\n",thark
.error
,buf
);
960 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
962 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
963 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
965 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
974 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
975 NULL means any use before m68_ip_begin()
982 * This converts a string into a 68k instruction.
983 * The string must be a bare single instruction in sun format
984 * with RMS-style 68020 indirects
987 * It provides some error messages: at most one fatal error message (which
988 * stops the scan) and at most one warning message for each operand.
989 * The 68k instruction is returned in exploded form, since we have no
990 * knowledge of how you parse (or evaluate) your expressions.
991 * We do however strip off and decode addressing modes and operation
994 * This function's value is a string. If it is not "" then an internal
995 * logic error was found: read this code to assign meaning to the string.
996 * No argument string should generate such an error string:
997 * it means a bug in our code, not in the user's text.
999 * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
1003 /* JF this function no longer returns a useful value. Sorry */
1009 register struct m68k_op
*opP
;
1010 register struct m68_incant
*opcode
;
1012 register int tmpreg
,
1021 LITTLENUM_TYPE words
[6];
1022 LITTLENUM_TYPE
*wordp
;
1024 if (*instring
== ' ')
1025 instring
++; /* skip leading whitespace */
1027 /* Scan up to end of operation-code, which MUST end in end-of-string
1028 or exactly 1 space. */
1029 for (p
= instring
; *p
!= '\0'; p
++)
1034 if (p
== instring
) {
1035 the_ins
.error
= "No operator";
1036 the_ins
.opcode
[0] = (short) NULL
;
1037 /* the_ins.numo=1; */
1041 /* p now points to the end of the opcode name, probably whitespace.
1042 make sure the name is null terminated by clobbering the whitespace,
1043 look it up in the hash table, then fix it back. */
1046 opcode
= (struct m68_incant
*)hash_find (op_hash
, instring
);
1049 if (opcode
== NULL
) {
1050 the_ins
.error
= "Unknown operator";
1051 the_ins
.opcode
[0] = (short) NULL
;
1052 /* the_ins.numo=1; */
1056 /* found a legitimate opcode, start matching operands */
1057 for(opP
= &the_ins
.operands
[0];*p
;opP
++) {
1058 p
= crack_operand (p
, opP
);
1060 the_ins
.error
=opP
->error
;
1065 opsfound
=opP
- &the_ins
.operands
[0];
1066 /* This ugly hack is to support the floating pt opcodes in their standard form */
1067 /* Essentially, we fake a first enty of type COP#1 */
1068 if(opcode
->m_operands
[0]=='I') {
1071 for(n
=opsfound
;n
>0;--n
)
1072 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1074 /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
1075 bzero((char *)(&the_ins
.operands
[0]),sizeof(the_ins
.operands
[0]));
1076 the_ins
.operands
[0].mode
=MSCR
;
1077 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1080 /* We've got the operands. Find an opcode that'll
1083 if(opsfound
!=opcode
->m_opnum
)
1085 else for(s
=opcode
->m_operands
,opP
= &the_ins
.operands
[0];*s
&& !losing
;s
+=2,opP
++) {
1086 /* Warning: this switch is huge! */
1087 /* I've tried to organize the cases into this order:
1088 non-alpha first, then alpha by letter. lower-case goes directly
1089 before uppercase counterpart. */
1090 /* Code with multiple case ...: gets sorted by the lowest case ...
1091 it belongs to. I hope this makes sense. */
1094 if(opP
->mode
==MSCR
|| opP
->mode
==IMMED
||
1095 opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1100 if(opP
->mode
!=IMMED
)
1105 t
=get_num(opP
->con1
,80);
1106 if(s
[1]=='b' && !isbyte(t
))
1108 else if(s
[1]=='w' && !isword(t
))
1115 if(opP
->mode
!=IMMED
)
1120 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1121 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1126 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1127 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1133 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1134 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1135 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1140 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1155 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1156 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1161 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1166 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1167 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1168 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1173 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1174 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1178 case '~': /* For now! (JF FOO is this right?) */
1179 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1180 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1195 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1199 case 'd': /* FOO This mode is a KLUDGE!! */
1200 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1201 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1211 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1216 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1222 if(opP
->mode
!=MSCR
|| opP
->reg
<USP
|| opP
->reg
>MSP
)
1227 if(opP
->mode
!=IMMED
)
1233 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1238 opP
->reg
=1<<(opP
->reg
-DATA
);
1240 } else if(opP
->mode
!=REGLST
) {
1242 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1244 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1249 if(opP
->mode
!=IMMED
)
1254 t
=get_num(opP
->con1
,80);
1255 if(!issbyte(t
) || isvar(opP
->con1
))
1261 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1266 if(opP
->mode
!=IMMED
)
1271 t
=get_num(opP
->con1
,80);
1272 if(t
<1 || t
>8 || isvar(opP
->con1
))
1278 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1283 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1288 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1293 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1297 /* JF these are out of order. We could put them
1298 in order if we were willing to put up with
1299 bunches of #ifdef m68851s in the code */
1301 /* Memory addressing mode used by pflushr */
1303 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1304 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1309 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1314 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TC
&& opP
->reg
!= CAL
&&
1315 opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1320 if (opP
->reg
!= VAL
)
1325 if (opP
->mode
!= MSCR
|| (opP
->reg
!= DRP
&& opP
->reg
!= SRP
&&
1331 if (opP
->mode
!= MSCR
||
1332 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1333 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1338 if (opP
->reg
!= PSR
)
1343 if (opP
->reg
!= PCSR
)
1348 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1349 *s
, __LINE__
, __FILE__
);
1354 opcode
=opcode
->m_next
;
1355 if(!opcode
) { /* Fell off the end */
1356 the_ins
.error
="instruction/operands mismatch";
1361 the_ins
.args
=opcode
->m_operands
;
1362 the_ins
.numargs
=opcode
->m_opnum
;
1363 the_ins
.numo
=opcode
->m_codenum
;
1364 the_ins
.opcode
[0]=getone(opcode
);
1365 the_ins
.opcode
[1]=gettwo(opcode
);
1367 for(s
=the_ins
.args
,opP
= &the_ins
.operands
[0];*s
;s
+=2,opP
++) {
1368 /* This switch is a doozy.
1369 What the first step; its a big one! */
1387 tmpreg
=0x3c; /* 7.4 */
1388 if(strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1389 else nextword
=nextword
=get_num(opP
->con1
,0);
1390 if(isvar(opP
->con1
))
1391 add_fix(s
[1],opP
->con1
,0);
1394 if(!isbyte(nextword
))
1395 opP
->error
="operand out of range";
1400 if(!isword(nextword
))
1401 opP
->error
="operand out of range";
1406 addword(nextword
>>16);
1428 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1429 *s
, s
[1], __LINE__
, __FILE__
);
1434 /* We gotta put out some float */
1435 if(seg(opP
->con1
)!=SEG_BIG
) {
1436 int_to_gen(nextword
);
1437 gen_to_words(words
,baseo
,(long)outro
);
1438 for(wordp
=words
;baseo
--;wordp
++)
1442 if(offs(opP
->con1
)>0) {
1443 as_warn("Bignum assumed to be binary bit-pattern");
1444 if(offs(opP
->con1
)>baseo
) {
1445 as_bad("Bignum too big for %c format; truncated",s
[1]);
1446 offs(opP
->con1
)=baseo
;
1448 baseo
-=offs(opP
->con1
);
1449 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1455 gen_to_words(words
,baseo
,(long)outro
);
1456 for(wordp
=words
;baseo
--;wordp
++)
1460 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1463 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1466 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1469 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1472 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1476 nextword
=get_num(opP
->con1
,80);
1477 /* Force into index mode. Hope this works */
1479 /* We do the first bit for 32-bit displacements,
1480 and the second bit for 16 bit ones. It is
1481 possible that we should make the default be
1482 WORD instead of LONG, but I think that'd
1483 break GCC, so we put up with a little
1484 inefficiency for the sake of working output.
1487 if( !issword(nextword
)
1488 || ( isvar(opP
->con1
)
1489 && ( ( opP
->con1
->e_siz
==0
1490 && flagseen
['l']==0)
1491 || opP
->con1
->e_siz
==3))) {
1494 tmpreg
=0x3B; /* 7.3 */
1496 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1497 if(isvar(opP
->con1
)) {
1499 add_frag(adds(opP
->con1
),
1501 TAB(PCLEA
,SZ_UNDEF
));
1505 add_fix('l',opP
->con1
,1);
1509 addword(nextword
>>16);
1512 tmpreg
=0x3A; /* 7.2 */
1514 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
1516 if(isvar(opP
->con1
)) {
1518 add_fix('w',opP
->con1
,1);
1520 add_fix('w',opP
->con1
,0);
1530 baseo
=get_num(opP
->con1
,80);
1531 outro
=get_num(opP
->con2
,80);
1532 /* Figure out the 'addressing mode' */
1533 /* Also turn on the BASE_DISABLE bit, if needed */
1534 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1535 tmpreg
=0x3b; /* 7.3 */
1538 } else if(opP
->reg
==FAIL
) {
1540 tmpreg
=0x30; /* 6.garbage */
1541 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1543 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
1544 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
1546 /* Index register stuff */
1547 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
1548 nextword
|=(opP
->ireg
-DATA
)<<12;
1550 if(opP
->isiz
==0 || opP
->isiz
==3)
1554 case 2: nextword
|=0x200; break;
1555 case 4: nextword
|=0x400; break;
1556 case 8: nextword
|=0x600; break;
1560 GET US OUT OF HERE! */
1562 /* Must be INDEX, with an index
1563 register. Address register
1564 cannot be ZERO-PC, and either
1565 :b was forced, or we know
1567 if( opP
->mode
==AINDX
1572 && !isvar(opP
->con1
)))) {
1573 nextword
+=baseo
&0xff;
1575 if(isvar(opP
->con1
))
1576 add_fix('B',opP
->con1
,0);
1580 nextword
|=0x40; /* No index reg */
1582 /* It aint simple */
1584 /* If the guy specified a width, we assume that
1585 it is wide enough. Maybe it isn't. Ifso, we lose
1589 if(isvar(opP
->con1
) || !issword(baseo
)) {
1600 as_warn("Byte dispacement won't work. Defaulting to :w");
1609 /* Figure out innner displacement stuff */
1610 if(opP
->mode
!=AINDX
) {
1613 if(isvar(opP
->con2
) || !issword(outro
)) {
1624 as_warn("Byte dispacement won't work. Defaulting to :w");
1632 if(opP
->mode
==APODX
) nextword
|=0x04;
1633 else if(opP
->mode
==AMIND
) nextword
|=0x40;
1637 if(isvar(opP
->con1
)) {
1638 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1639 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
1640 opP
->con1
->e_exp
.X_add_number
+=6;
1642 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
1649 if(isvar(opP
->con2
)) {
1650 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1651 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
1652 opP
->con1
->e_exp
.X_add_number
+=6;
1654 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
1664 nextword
=get_num(opP
->con1
,80);
1665 switch(opP
->con1
->e_siz
) {
1667 as_bad("Unknown size for absolute reference");
1669 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
1670 tmpreg
=0x38; /* 7.0 */
1674 if(isvar(opP
->con1
) &&
1676 !strchr("~%&$?", s
[0])) {
1677 tmpreg
=0x3A; /* 7.2 */
1678 add_frag(adds(opP
->con1
),
1680 TAB(PCREL
,SZ_UNDEF
));
1683 case 3: /* Fall through into long */
1684 if(isvar(opP
->con1
))
1685 add_fix('l',opP
->con1
,0);
1687 tmpreg
=0x39; /* 7.1 mode */
1688 addword(nextword
>>16);
1693 if(isvar(opP
->con1
))
1694 add_fix('w',opP
->con1
,0);
1696 tmpreg
=0x38; /* 7.0 mode */
1703 as_bad("unknown/incorrect operand");
1706 install_gen_operand(s
[1],tmpreg
);
1711 switch(s
[1]) { /* JF: I hate floating point! */
1726 tmpreg
=get_num(opP
->con1
,tmpreg
);
1727 if(isvar(opP
->con1
))
1728 add_fix(s
[1],opP
->con1
,0);
1730 case 'b': /* Danger: These do no check for
1731 certain types of overflow.
1734 opP
->error
="out of range";
1736 if(isvar(opP
->con1
))
1737 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1741 opP
->error
="out of range";
1743 if(isvar(opP
->con1
))
1744 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1747 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
1749 if(isvar(opP
->con1
))
1750 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1756 install_operand(s
[1],tmpreg
);
1759 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
1766 install_operand(s
[1],opP
->reg
-ADDR
);
1770 tmpreg
=get_num(opP
->con1
,80);
1773 if(opP
->con1
->e_siz
) { /* Deal with fixed size stuff by hand */
1774 switch(opP
->con1
->e_siz
) {
1776 add_fix('b',opP
->con1
,1);
1779 add_fix('w',opP
->con1
,1);
1783 add_fix('l',opP
->con1
,1);
1788 as_bad("Bad size for expression %d", opP
->con1
->e_siz
);
1790 } else if(subs(opP
->con1
)) {
1791 /* We can't relax it */
1792 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
1793 add_fix('l',opP
->con1
,1);
1796 } else if(adds(opP
->con1
)) {
1797 if (flagseen
['m'] &&
1798 (the_ins
.opcode
[0] >= 0x6200) &&
1799 (the_ins
.opcode
[0] <= 0x6f00)) {
1800 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
1802 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BRANCH
,SZ_UNDEF
));
1805 /* JF: This is the WRONG thing to do
1806 add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
1807 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
1809 add_fix('l',opP
->con1
,1);
1815 if(isvar(opP
->con1
)) {
1816 /* check for DBcc instruction */
1817 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
1818 /* size varies if patch */
1819 /* needed for long form */
1820 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
1825 opP
->con1
->e_exp
.X_add_number
+=2;
1826 add_fix('w',opP
->con1
,1);
1831 if(opP
->con1
->e_siz
) {
1832 switch(opP
->con1
->e_siz
) {
1834 add_fix('w',opP
->con1
,1)
1838 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1839 add_fix('l',opP
->con1
,1);
1844 as_bad("Bad size for offset, must be word or long");
1847 } else if(subs(opP
->con1
)) {
1848 add_fix('l',opP
->con1
,1);
1849 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
1850 } else if(adds(opP
->con1
)) {
1851 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
1853 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
1854 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1855 add_fix('l',opP
->con1
,1);
1861 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
1862 s
[1], __LINE__
, __FILE__
);
1866 case 'C': /* Ignore it */
1869 case 'd': /* JF this is a kludge */
1870 if(opP
->mode
==AOFF
) {
1871 install_operand('s',opP
->reg
-ADDR
);
1875 tmpP
=opP
->con1
->e_end
-2;
1877 opP
->con1
->e_end
-=4; /* point to the , */
1878 baseo
=m68k_reg_parse(&tmpP
);
1879 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
1880 as_bad("Unknown address reg, using A0");
1883 install_operand('s',baseo
);
1885 tmpreg
=get_num(opP
->con1
,80);
1886 if(!issword(tmpreg
)) {
1887 as_bad("Expression out of range, using 0");
1894 install_operand(s
[1],opP
->reg
-DATA
);
1898 install_operand(s
[1],opP
->reg
-FPREG
);
1902 tmpreg
=1+opP
->reg
-COPNUM
;
1905 install_operand(s
[1],tmpreg
);
1908 case 'J': /* JF foo */
1937 install_operand(s
[1],tmpreg
);
1941 tmpreg
=get_num(opP
->con1
,55);
1942 install_operand(s
[1],tmpreg
&0x7f);
1948 if(tmpreg
&0x7FF0000)
1949 as_bad("Floating point register in register list");
1950 insop(reverse_16_bits(tmpreg
));
1952 if(tmpreg
&0x700FFFF)
1953 as_bad("Wrong register in floating-point reglist");
1954 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
1961 if(tmpreg
&0x7FF0000)
1962 as_bad("Floating point register in register list");
1964 } else if(s
[1]=='8') {
1965 if(tmpreg
&0x0FFFFFF)
1966 as_bad("incorrect register in reglist");
1967 install_operand(s
[1],tmpreg
>>24);
1969 if(tmpreg
&0x700FFFF)
1970 as_bad("wrong register in floating-point reglist");
1972 install_operand(s
[1],tmpreg
>>16);
1977 install_operand(s
[1],get_num(opP
->con1
,60));
1981 tmpreg
= (opP
->mode
==DREG
)
1982 ? 0x20+opP
->reg
-DATA
1983 : (get_num(opP
->con1
,40)&0x1F);
1984 install_operand(s
[1],tmpreg
);
1988 tmpreg
=get_num(opP
->con1
,10);
1991 install_operand(s
[1],tmpreg
);
1995 /* This depends on the fact that ADDR registers are
1996 eight more than their corresponding DATA regs, so
1997 the result will have the ADDR_REG bit set */
1998 install_operand(s
[1],opP
->reg
-DATA
);
2002 if(opP
->reg
==FPI
) tmpreg
=0x1;
2003 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2004 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2006 install_operand(s
[1],tmpreg
);
2009 case 'S': /* Ignore it */
2013 install_operand(s
[1],get_num(opP
->con1
,30));
2016 case 'U': /* Ignore it */
2020 /* JF: These are out of order, I fear. */
2032 install_operand(s
[1],tmpreg
);
2055 install_operand(s
[1],tmpreg
);
2059 if (opP
->reg
== VAL
)
2078 install_operand(s
[1],tmpreg
);
2083 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2084 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2085 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2088 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2089 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2090 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2096 install_operand(s
[1], tmpreg
);
2099 if (opP
->reg
== PSR
)
2104 if (opP
->reg
== PCSR
)
2109 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s
[0], __LINE__
, __FILE__
);
2112 /* By the time whe get here (FINALLY) the_ins contains the complete
2113 instruction, ready to be emitted. . . */
2116 static int get_regs(i
,str
,opP
)
2118 struct m68k_op
*opP
;
2121 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2122 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2123 unsigned long cur_regs
= 0;
2127 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2128 else if(x==FPS) cur_regs|=(1<<25);\
2129 else if(x==FPC) cur_regs|=(1<<26);\
2130 else cur_regs|=(1<<(x-1)); }
2137 } else if(*str
=='-') {
2139 reg2
=m68k_reg_parse(&str
);
2140 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2141 opP
->error
="unknown register in register list";
2150 } else if(*str
=='\0') {
2154 opP
->error
="unknow character in register list";
2157 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2160 reg1
=m68k_reg_parse(&str
);
2161 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2162 opP
->error
="unknown register in register list";
2170 static int reverse_16_bits(in
)
2176 static int mask
[16] = {
2177 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2178 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2185 } /* reverse_16_bits() */
2187 static int reverse_8_bits(in
)
2193 static int mask
[8] = {
2194 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2202 } /* reverse_8_bits() */
2204 static void install_operand(mode
,val
)
2210 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2213 the_ins
.opcode
[0]|=val
<<9;
2216 the_ins
.opcode
[1]|=val
<<12;
2219 the_ins
.opcode
[1]|=val
<<6;
2222 the_ins
.opcode
[1]|=val
;
2225 the_ins
.opcode
[2]|=val
<<12;
2228 the_ins
.opcode
[2]|=val
<<6;
2231 /* DANGER! This is a hack to force cas2l and cas2w cmds
2232 to be three words long! */
2234 the_ins
.opcode
[2]|=val
;
2237 the_ins
.opcode
[1]|=val
<<7;
2240 the_ins
.opcode
[1]|=val
<<10;
2244 the_ins
.opcode
[1]|=val
<<5;
2249 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2252 the_ins
.opcode
[1]|=(val
<<12)|val
;
2255 the_ins
.opcode
[0]|=val
=0xff;
2258 the_ins
.opcode
[0]|=val
<<9;
2261 the_ins
.opcode
[1]|=val
;
2264 the_ins
.opcode
[1]|=val
;
2265 the_ins
.numo
++; /* What a hack */
2268 the_ins
.opcode
[1]|=val
<<4;
2278 } /* install_operand() */
2280 static void install_gen_operand(mode
,val
)
2286 the_ins
.opcode
[0]|=val
;
2289 /* This is a kludge!!! */
2290 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2299 the_ins
.opcode
[0]|=val
;
2301 /* more stuff goes here */
2305 } /* install_gen_operand() */
2307 static char *crack_operand(str
,opP
)
2309 register struct m68k_op
*opP
;
2311 register int parens
;
2313 register char *beg_str
;
2319 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2320 if(*str
=='(') parens
++;
2321 else if(*str
==')') {
2322 if(!parens
) { /* ERROR */
2323 opP
->error
="Extra )";
2329 if(!*str
&& parens
) { /* ERROR */
2330 opP
->error
="Missing )";
2335 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2341 c
= *++str
; /* JF bitfield hack */
2345 as_bad("Missing operand");
2350 /* See the comment up above where the #define notend(... is */
2355 if(*s
==',') return 0;
2356 if(*s
=='{' || *s
=='}')
2358 if(*s
!=':') return 1;
2359 /* This kludge here is for the division cmd, which is a kludge */
2360 if(strchr("aAdD#",s
[1])) return 0;
2365 /* This is the guts of the machine-dependent assembler. STR points to a
2366 machine dependent instruction. This funciton is supposed to emit
2367 the frags/bytes it assembles to.
2378 int shorts_this_frag
;
2380 bzero((char *)(&the_ins
),sizeof(the_ins
)); /* JF for paranoia sake */
2384 for(n
=the_ins
.numargs
;n
;--n
)
2385 if(the_ins
.operands
[n
].error
) {
2386 er
=the_ins
.operands
[n
].error
;
2391 as_bad("\"%s\" -- Statement '%s' ignored",er
,str
);
2395 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
2396 toP
=frag_more(2*the_ins
.numo
);
2397 fromP
= &the_ins
.opcode
[0];
2398 for(m
=the_ins
.numo
;m
;--m
) {
2399 md_number_to_chars(toP
,(long)(*fromP
),2);
2403 /* put out symbol-dependent info */
2404 for(m
=0;m
<the_ins
.nrel
;m
++) {
2405 switch(the_ins
.reloc
[m
].wid
) {
2422 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
2426 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2428 the_ins
.reloc
[m
].add
,
2429 the_ins
.reloc
[m
].sub
,
2430 the_ins
.reloc
[m
].off
,
2431 the_ins
.reloc
[m
].pcrel
,
2437 /* There's some frag hacking */
2438 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
2441 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
2442 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2446 for(m
=wid
/2;m
;--m
) {
2447 md_number_to_chars(toP
,(long)(*fromP
),2);
2452 for(m
=0;m
<the_ins
.nrel
;m
++) {
2453 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
2454 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
2457 wid
=the_ins
.reloc
[m
].wid
;
2460 the_ins
.reloc
[m
].wid
=0;
2461 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2464 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2466 the_ins
.reloc
[m
].add
,
2467 the_ins
.reloc
[m
].sub
,
2468 the_ins
.reloc
[m
].off
,
2469 the_ins
.reloc
[m
].pcrel
,
2472 know(the_ins
.fragb
[n
].fadd
);
2473 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
2474 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
2476 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2479 toP
=frag_more(n
*sizeof(short));
2481 md_number_to_chars(toP
,(long)(*fromP
),2);
2487 for(m
=0;m
<the_ins
.nrel
;m
++) {
2490 wid
=the_ins
.reloc
[m
].wid
;
2493 the_ins
.reloc
[m
].wid
=0;
2494 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2497 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
2499 the_ins
.reloc
[m
].add
,
2500 the_ins
.reloc
[m
].sub
,
2501 the_ins
.reloc
[m
].off
,
2502 the_ins
.reloc
[m
].pcrel
,
2507 /* This function is called once, at assembler startup time. This should
2508 set up all the tables, etc that the MD part of the assembler needs
2514 * md_begin -- set up hash tables with 68000 instructions.
2515 * similar to what the vax assembler does. ---phr
2517 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2518 a copy of it at runtime, adding in the information we want but isn't
2519 there. I think it'd be better to have an awk script hack the table
2520 at compile time. Or even just xstr the table and use it as-is. But
2521 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2524 register const struct m68k_opcode
*ins
;
2525 register struct m68_incant
*hack
,
2527 register char *retval
= 0; /* empty string, or error msg text */
2528 register unsigned int i
;
2531 if ((op_hash
= hash_new()) == NULL
)
2532 as_fatal("Virtual memory exhausted");
2534 obstack_begin(&robyn
,4000);
2535 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
2536 hack
=slak
=(struct m68_incant
*)obstack_alloc(&robyn
,sizeof(struct m68_incant
));
2538 slak
->m_operands
=ins
->args
;
2539 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
2540 slak
->m_opcode
=ins
->opcode
;
2541 /* This is kludgey */
2542 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
2543 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
2544 slak
->m_next
=(struct m68_incant
*)
2545 obstack_alloc(&robyn
,sizeof(struct m68_incant
));
2552 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
2553 /* Didn't his mommy tell him about null pointers? */
2554 if(retval
&& *retval
)
2555 as_fatal("Internal Error: Can't hash %s: %s", ins
->name
,retval
);
2558 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
2559 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
2561 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
2562 notend_table
[i
] = 0;
2563 alt_notend_table
[i
] = 0;
2565 notend_table
[','] = 1;
2566 notend_table
['{'] = 1;
2567 notend_table
['}'] = 1;
2568 alt_notend_table
['a'] = 1;
2569 alt_notend_table
['A'] = 1;
2570 alt_notend_table
['d'] = 1;
2571 alt_notend_table
['D'] = 1;
2572 alt_notend_table
['#'] = 1;
2573 alt_notend_table
['f'] = 1;
2574 alt_notend_table
['F'] = 1;
2575 #ifdef REGISTER_PREFIX
2576 alt_notend_table
[REGISTER_PREFIX
] = 1;
2581 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2582 || (*s == ':' && strchr("aAdD#", s[1]))) \
2586 /* This funciton is called once, before the assembler exits. It is
2587 supposed to do any final cleanup for this part of the assembler.
2594 /* Equal to MAX_PRECISION in atof-ieee.c */
2595 #define MAX_LITTLENUMS 6
2597 /* Turn a string in input_line_pointer into a floating point constant of type
2598 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2599 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2602 md_atof(type
,litP
,sizeP
)
2608 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2609 LITTLENUM_TYPE
*wordP
;
2639 return "Bad call to MD_ATOF()";
2641 t
=atof_ieee(input_line_pointer
,type
,words
);
2643 input_line_pointer
=t
;
2645 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
2646 for(wordP
=words
;prec
--;) {
2647 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
2648 litP
+=sizeof(LITTLENUM_TYPE
);
2650 return ""; /* Someone should teach Dean about null pointers */
2653 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2654 for use in the a.out file, and stores them in the array pointed to by buf.
2655 This knows about the endian-ness of the target machine and does
2656 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2657 2 (short) and 4 (long) Floating numbers are put out as a series of
2658 LITTLENUMS (shorts, here at least)
2661 md_number_to_chars(buf
,val
,n
)
2686 md_apply_fix(fixP
, val
)
2690 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2692 switch(fixP
->fx_size
) {
2707 BAD_CASE (fixP
->fx_size
);
2712 /* *fragP has been relaxed to its final size, and now needs to have
2713 the bytes inside it modified to conform to the new size There is UGLY
2717 md_convert_frag(fragP
)
2718 register fragS
*fragP
;
2723 /* Address in gas core of the place to store the displacement. */
2724 register char *buffer_address
= fragP
-> fr_fix
+ fragP
-> fr_literal
;
2725 /* Address in object code of the displacement. */
2726 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
2728 know(fragP
->fr_symbol
);
2730 /* The displacement of the address, from current location. */
2731 disp
= (S_GET_VALUE(fragP
->fr_symbol
) + fragP
->fr_offset
) - object_address
;
2733 switch(fragP
->fr_subtype
) {
2734 case TAB(BCC68000
,BYTE
):
2735 case TAB(BRANCH
,BYTE
):
2736 know(issbyte(disp
));
2738 as_bad("short branch with zero offset: use :w");
2739 fragP
->fr_opcode
[1]=disp
;
2742 case TAB(DBCC
,SHORT
):
2743 know(issword(disp
));
2746 case TAB(BCC68000
,SHORT
):
2747 case TAB(BRANCH
,SHORT
):
2748 know(issword(disp
));
2749 fragP
->fr_opcode
[1]=0x00;
2752 case TAB(BRANCH
,LONG
):
2754 if(fragP
->fr_opcode
[0]==0x61) {
2755 fragP
->fr_opcode
[0]= 0x4E;
2756 fragP
->fr_opcode
[1]= 0xB9; /* JSR with ABSL LONG offset */
2757 subseg_change(SEG_TEXT
, 0);
2770 } else if(fragP
->fr_opcode
[0]==0x60) {
2771 fragP
->fr_opcode
[0]= 0x4E;
2772 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
2773 subseg_change(SEG_TEXT
, 0);
2774 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
2779 as_bad("Long branch offset not supported.");
2782 fragP
->fr_opcode
[1]=0xff;
2786 case TAB(BCC68000
,LONG
):
2787 /* only Bcc 68000 instructions can come here */
2788 /* change bcc into b!cc/jmp absl long */
2789 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
2790 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
2792 /* JF: these used to be fr_opcode[2,3], but they may be in a
2793 different frag, in which case refering to them is a no-no.
2794 Only fr_opcode[0,1] are guaranteed to work. */
2795 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
2796 *buffer_address
++ = 0xf9;
2797 fragP
->fr_fix
+= 2; /* account for jmp instruction */
2798 subseg_change(SEG_TEXT
,0);
2799 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
2805 case TAB(DBCC
,LONG
):
2806 /* only DBcc 68000 instructions can come here */
2807 /* change dbcc into dbcc/jmp absl long */
2808 /* JF: these used to be fr_opcode[2-7], but that's wrong */
2809 *buffer_address
++ = 0x00; /* branch offset = 4 */
2810 *buffer_address
++ = 0x04;
2811 *buffer_address
++ = 0x60; /* put in bra pc+6 */
2812 *buffer_address
++ = 0x06;
2813 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
2814 *buffer_address
++ = 0xf9;
2816 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
2817 subseg_change(SEG_TEXT
,0);
2818 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
2824 case TAB(FBRANCH
,SHORT
):
2825 know((fragP
->fr_opcode
[1]&0x40)==0);
2828 case TAB(FBRANCH
,LONG
):
2829 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
2832 case TAB(PCREL
,SHORT
):
2835 case TAB(PCREL
,LONG
):
2836 /* FIXME-SOMEDAY, this should allow pcrel-long to be generated if -pic is on.
2837 Else we can't handle position independent code. Pcrel-long costs an
2838 extra index word though. Doing it requires more relax tables and
2839 stuff elsewhere in this module though. */
2840 /* The thing to do here is force it to ABSOLUTE LONG, since
2841 PCREL is really trying to shorten an ABSOLUTE address anyway */
2842 subseg_change(SEG_TEXT
,0);
2843 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0,
2845 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
2846 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
2847 fragP
->fr_opcode
[0],fragP
->fr_address
);
2848 fragP
->fr_opcode
[1]&= ~0x3F;
2849 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
2853 case TAB(PCLEA
,SHORT
):
2854 subseg_change(SEG_TEXT
,0);
2855 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
2857 fragP
->fr_opcode
[1] &= ~0x3F;
2858 fragP
->fr_opcode
[1] |= 0x3A;
2861 case TAB(PCLEA
,LONG
):
2862 subseg_change(SEG_TEXT
,0);
2863 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
2865 *buffer_address
++ = 0x01;
2866 *buffer_address
++ = 0x70;
2868 /* buffer_address+=2; */
2874 md_number_to_chars(buffer_address
,(long)disp
,(int)ext
);
2879 /* Force truly undefined symbols to their maximum size, and generally set up
2880 the frag list to be relaxed
2882 int md_estimate_size_before_relax(fragP
, segment
)
2883 register fragS
*fragP
;
2887 register char *buffer_address
= fragP
-> fr_fix
+ fragP
-> fr_literal
;
2889 old_fix
=fragP
->fr_fix
;
2891 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
2892 switch(fragP
->fr_subtype
) {
2893 case TAB(BRANCH
,SZ_UNDEF
):
2894 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
2895 /* Symbol now defined; start at byte-size. */
2896 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
2898 } else if(!flagseen
['p'] || (!flagseen
['l'] && flagseen
['m'])) {
2899 /* Symbol in another segment, or undef.
2900 If we don't care about position independent code,
2901 or if we're using long displacements on a 68000,
2902 rewrite to short or long absolute. */
2903 if(fragP
->fr_opcode
[0]==0x61) {
2905 fragP
->fr_opcode
[0]= 0x4E;
2906 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL WORD offset */
2907 subseg_change(SEG_TEXT
, 0);
2908 fix_new(fragP
, fragP
->fr_fix
, 2,
2909 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0,
2913 fragP
->fr_opcode
[0]= 0x4E;
2914 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
2915 subseg_change(SEG_TEXT
, 0);
2916 fix_new(fragP
, fragP
->fr_fix
, 4,
2917 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0,
2922 } else if(fragP
->fr_opcode
[0]==0x60) {
2924 fragP
->fr_opcode
[0]= 0x4E;
2925 fragP
->fr_opcode
[1]= 0xF8; /* JMP with ABSL WORD offset */
2926 subseg_change(SEG_TEXT
, 0);
2927 fix_new(fragP
, fragP
->fr_fix
, 2,
2928 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0,
2932 fragP
->fr_opcode
[0]= 0x4E;
2933 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
2934 subseg_change(SEG_TEXT
, 0);
2935 fix_new(fragP
, fragP
->fr_fix
, 4,
2936 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0,
2942 as_bad("Long branch offset to extern symbol not supported.");
2944 } else if(flagseen
['l']) {
2945 /* Symbol in other seg or undefined, and user
2946 wants short pcrel offsets (-l). Set size to 2, fix
2947 pcrel displacement after relax. */
2948 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,
2949 (symbolS
*)0,fragP
->fr_offset
+2,1,
2952 fragP
->fr_opcode
[1]=0x00;
2955 /* Symbol in other seg or undefined, and user
2956 wants long pcrel offsets. Set size to 4, and fix
2957 pcrel displacement after relax. */
2958 fix_new(fragP
,(int)(fragP
->fr_fix
),4,fragP
->fr_symbol
,
2959 (symbolS
*)0,fragP
->fr_offset
+ 4,1,
2962 fragP
->fr_opcode
[1]=0xff;
2968 case TAB(FBRANCH
,SZ_UNDEF
):
2969 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
2971 fragP
->fr_subtype
=TAB(FBRANCH
,SHORT
);
2974 fragP
->fr_subtype
=TAB(FBRANCH
,LONG
);
2979 case TAB(PCREL
,SZ_UNDEF
):
2980 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
2982 fragP
->fr_subtype
=TAB(PCREL
,SHORT
);
2985 fragP
->fr_subtype
=TAB(PCREL
,LONG
);
2990 case TAB(BCC68000
,SZ_UNDEF
):
2991 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
2992 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
2995 /* only Bcc 68000 instructions can come here */
2996 /* change bcc into b!cc/jmp absl long */
2997 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
2999 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3000 /* JF: these were fr_opcode[2,3] */
3001 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3002 buffer_address
[1] = 0xf8;
3003 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3004 subseg_change(SEG_TEXT
,0);
3005 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3010 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3011 /* JF: these were fr_opcode[2,3] */
3012 buffer_address
[2] = 0x4e; /* put in jmp long (0x4ef9) */
3013 buffer_address
[3] = 0xf9;
3014 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3015 subseg_change(SEG_TEXT
,0);
3016 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3024 case TAB(DBCC
,SZ_UNDEF
):
3025 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3026 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3030 /* only DBcc 68000 instructions can come here */
3031 /* change dbcc into dbcc/jmp absl long */
3032 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3033 buffer_address
[0] = 0x00; /* branch offset = 4 */
3034 buffer_address
[1] = 0x04;
3035 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3037 /* JF: these were fr_opcode[5-7] */
3038 buffer_address
[3] = 0x04; /* plus 4 */
3039 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3040 buffer_address
[5] = 0xf8;
3041 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3042 subseg_change(SEG_TEXT
,0);
3043 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3048 /* JF: these were fr_opcode[5-7] */
3049 buffer_address
[3] = 0x06; /* Plus 6 */
3050 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3051 buffer_address
[5] = 0xf9;
3052 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3053 subseg_change(SEG_TEXT
,0);
3054 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3062 case TAB(PCLEA
,SZ_UNDEF
):
3063 if((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3064 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3067 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3076 /* now that SZ_UNDEF are taken care of, check others */
3077 switch(fragP
->fr_subtype
) {
3078 case TAB(BCC68000
,BYTE
):
3079 case TAB(BRANCH
,BYTE
):
3080 /* We can't do a short jump to the next instruction,
3081 so we force word mode. */
3082 if(fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3083 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3084 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3091 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3094 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3095 /* the bit-field entries in the relocation_info struct plays hell
3096 with the byte-order problems of cross-assembly. So as a hack,
3097 I added this mach. dependent ri twiddler. Ugly, but it gets
3099 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3100 are symbolnum, most sig. byte first. Last byte is broken up with
3101 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3102 nibble as nuthin. (on Sun 3 at least) */
3103 /* Translate the internal relocation information into target-specific
3106 md_ri_to_chars(the_bytes
, ri
)
3108 struct reloc_info_generic
*ri
;
3111 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3112 /* now the fun stuff */
3113 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3114 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3115 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3116 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3117 ((ri
->r_extern
<< 4) & 0x10));
3119 #endif /* OBJ_AOUT or OBJ_BOUT */
3121 #ifndef WORKING_DOT_WORD
3122 const int md_short_jump_size
= 4;
3123 const int md_long_jump_size
= 6;
3126 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3135 offset
= to_addr
- (from_addr
+2);
3137 md_number_to_chars(ptr
,(long)0x6000,2);
3138 md_number_to_chars(ptr
+2,(long)offset
,2);
3142 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3152 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3153 md_number_to_chars(ptr
,(long)0x4EF9,2);
3154 md_number_to_chars(ptr
+2,(long)offset
,4);
3155 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3158 offset
=to_addr
- (from_addr
+2);
3159 md_number_to_chars(ptr
,(long)0x60ff,2);
3160 md_number_to_chars(ptr
+2,(long)offset
,4);
3165 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3168 10: Absolute 1:8 only
3169 20: Absolute 0:7 only
3170 30: absolute 0:15 only
3171 40: Absolute 0:31 only
3172 50: absolute 0:127 only
3173 55: absolute -64:63 only
3174 60: absolute -128:127 only
3175 70: absolute 0:4095 only
3180 static int get_num(exp
,ok
)
3181 struct m68k_exp
*exp
;
3189 if(*exp
->e_beg
=='0') {
3190 if(exp
->e_beg
[1]=='x')
3191 sscanf(exp
->e_beg
+2,"%x",&l
);
3193 sscanf(exp
->e_beg
+1,"%O",&l
);
3196 return atol(exp
->e_beg
);
3202 /* Can't do anything */
3205 if(!exp
->e_beg
|| !exp
->e_end
) {
3206 seg(exp
)=SEG_ABSOLUTE
;
3209 offs(exp
)= (ok
==10) ? 1 : 0;
3210 as_bad("Null expression defaults to %ld", offs(exp
));
3215 if(/* ok!=80 && */exp
->e_end
[-1]==':' && (exp
->e_end
-exp
->e_beg
)>=2) {
3216 switch(exp
->e_end
[0]) {
3232 as_bad("Unknown size for expression \"%c\"", exp
->e_end
[0]);
3236 c_save
=exp
->e_end
[1];
3238 save_in
=input_line_pointer
;
3239 input_line_pointer
=exp
->e_beg
;
3240 switch(expression(&(exp
->e_exp
))) {
3242 seg(exp
)=SEG_ABSOLUTE
;
3245 offs(exp
)= (ok
==10) ? 1 : 0;
3246 as_bad("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
3250 /* Do the same thing the VAX asm does */
3251 seg(exp
)=SEG_ABSOLUTE
;
3256 as_bad("expression out of range: defaulting to 1");
3263 if(offs(exp
)<1 || offs(exp
)>8) {
3264 as_bad("expression out of range: defaulting to 1");
3269 if(offs(exp
)<0 || offs(exp
)>7)
3273 if(offs(exp
)<0 || offs(exp
)>15)
3277 if(offs(exp
)<0 || offs(exp
)>32)
3281 if(offs(exp
)<0 || offs(exp
)>127)
3285 if(offs(exp
)<-64 || offs(exp
)>63)
3289 if(offs(exp
)<-128 || offs(exp
)>127)
3293 if(offs(exp
)<0 || offs(exp
)>4095) {
3295 as_bad("expression out of range: defaulting to 0");
3307 case SEG_DIFFERENCE
:
3308 if(ok
>=10 && ok
<=70) {
3309 seg(exp
)=SEG_ABSOLUTE
;
3312 offs(exp
)= (ok
==10) ? 1 : 0;
3313 as_bad("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3317 if(ok
==80 && offs(exp
)<0) { /* HACK! Turn it into a long */
3318 LITTLENUM_TYPE words
[6];
3320 gen_to_words(words
,2,8L);/* These numbers are magic! */
3321 seg(exp
)=SEG_ABSOLUTE
;
3324 offs(exp
)=words
[1]|(words
[0]<<16);
3326 seg(exp
)=SEG_ABSOLUTE
;
3329 offs(exp
)= (ok
==10) ? 1 : 0;
3330 as_bad("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3336 if(input_line_pointer
!=exp
->e_end
+1)
3337 as_bad("Ignoring junk after expression");
3338 exp
->e_end
[1]=c_save
;
3339 input_line_pointer
=save_in
;
3341 switch(exp
->e_siz
) {
3343 if(!isbyte(offs(exp
)))
3344 as_bad("expression doesn't fit in BYTE");
3347 if(!isword(offs(exp
)))
3348 as_bad("expression doesn't fit in WORD");
3356 /* These are the back-ends for the various machine dependent pseudo-ops. */
3358 static void s_data1() {
3359 subseg_new(SEG_DATA
,1);
3360 demand_empty_rest_of_line();
3363 static void s_data2() {
3364 subseg_new(SEG_DATA
,2);
3365 demand_empty_rest_of_line();
3368 static void s_bss() {
3369 /* We don't support putting frags in the BSS segment, but we
3370 can put them into initialized data for now... */
3371 subseg_new(SEG_DATA
,255); /* FIXME-SOON */
3372 demand_empty_rest_of_line();
3375 static void s_even() {
3377 register long temp_fill
;
3379 temp
= 1; /* JF should be 2? */
3380 temp_fill
= get_absolute_expression ();
3381 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
3382 frag_align (temp
, (int)temp_fill
);
3383 demand_empty_rest_of_line();
3386 static void s_proc() {
3387 demand_empty_rest_of_line();
3390 /* s_space is defined in read.c .skip is simply an alias to it. */
3393 md_parse_option(argP
,cntP
,vecP
)
3399 case 'l': /* -l means keep externals to 2 byte branch offsets
3400 rather than 4 byte branch offsets */
3404 /* Gas almost ignores this option! */
3408 if(!strcmp(*argP
,"68000"))
3410 else if(!strcmp(*argP
,"68010")) {
3412 magic_number_for_object_file
= 1<<16|OMAGIC
;
3415 } else if(!strcmp(*argP
,"68020"))
3418 as_warn("Unknown -m option ignored");
3424 if (!strcmp(*argP
,"pic")) {
3426 break; /* -pic, Position Independent Code */
3439 /* TEST2: Test md_assemble() */
3440 /* Warning, this routine probably doesn't work anymore */
3444 struct m68_it the_ins
;
3451 if(!gets(buf
) || !*buf
)
3453 if(buf
[0]=='|' || buf
[1]=='.')
3455 for(cp
=buf
;*cp
;cp
++)
3460 bzero(&the_ins
,sizeof(the_ins
));
3461 m68_ip(&the_ins
,buf
);
3463 printf("Error %s in %s\n",the_ins
.error
,buf
);
3465 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
3466 for(n
=0;n
<the_ins
.numo
;n
++)
3467 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
3469 print_the_insn(&the_ins
.opcode
[0],stdout
);
3470 (void)putchar('\n');
3472 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
3473 if(the_ins
.operands
[n
].error
) {
3474 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
3477 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
3478 if(the_ins
.operands
[n
].b_const
)
3479 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
3480 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
3481 if(the_ins
.operands
[n
].b_iadd
)
3482 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
3483 (void)putchar('\n');
3495 while(*str
&& *str
!=' ')
3497 if(str
[-1]==':' || str
[1]=='=')
3504 /* Possible states for relaxation:
3506 0 0 branch offset byte (bra, etc)
3510 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3514 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3550 extern fragS
*text_frag_root
;
3552 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
3553 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3554 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
3555 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
3567 fputs("Internal error:",stderr
);
3568 _doprnt(format
,&args
,stderr
);
3569 (void)putc('\n',stderr
);
3575 /* We have no need to default values of symbols. */
3579 md_undefined_symbol (name
)
3585 /* Parse an operand that is machine-specific.
3586 We just return without modifying the expression if we have nothing
3591 md_operand (expressionP
)
3592 expressionS
*expressionP
;
3596 /* Round up a section size to the appropriate boundary. */
3598 md_section_align (segment
, size
)
3602 return size
; /* Byte alignment is fine */
3605 /* Exactly what point is a PC-relative offset relative TO?
3606 On the 68k, they're relative to the address of the offset, plus
3607 its size. (??? Is this right? FIXME-SOON!) */
3609 md_pcrel_from (fixP
)
3612 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3615 /* Opcode table for m68000/m68020 and m68881.
3616 Copyright (C) 1989, Free Software Foundation.
3618 This file is part of GDB, the GNU Debugger and GAS, the GNU Assembler.
3620 Both GDB and GAS are free software; you can redistribute and/or modify
3621 it under the terms of the GNU General Public License as published by
3622 the Free Software Foundation; either version 1, or (at your option)
3625 GDB and GAS are distributed in the hope that it will be useful,
3626 but WITHOUT ANY WARRANTY; without even the implied warranty of
3627 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3628 GNU General Public License for more details.
3630 You should have received a copy of the GNU General Public License
3631 along with GDB or GAS; see the file COPYING. If not, write to
3632 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
3634 /* We store four bytes of opcode for all opcodes because that
3635 is the most any of them need. The actual length of an instruction
3636 is always at least 2 bytes, and is as much longer as necessary to
3637 hold the operands it has.
3639 The match component is a mask saying which bits must match
3640 particular opcode in order for an instruction to be an instance
3643 The args component is a string containing two characters
3644 for each operand of the instruction. The first specifies
3645 the kind of operand; the second, the place it is stored. */
3647 /* Kinds of operands:
3648 D data register only. Stored as 3 bits.
3649 A address register only. Stored as 3 bits.
3650 R either kind of register. Stored as 4 bits.
3651 F floating point coprocessor register only. Stored as 3 bits.
3652 O an offset (or width): immediate data 0-31 or data register.
3653 Stored as 6 bits in special format for BF... insns.
3654 + autoincrement only. Stored as 3 bits (number of the address register).
3655 - autodecrement only. Stored as 3 bits (number of the address register).
3656 Q quick immediate data. Stored as 3 bits.
3657 This matches an immediate operand only when value is in range 1 .. 8.
3658 M moveq immediate data. Stored as 8 bits.
3659 This matches an immediate operand only when value is in range -128..127
3660 T trap vector immediate data. Stored as 4 bits.
3662 k K-factor for fmove.p instruction. Stored as a 7-bit constant or
3663 a three bit register offset, depending on the field type.
3665 # immediate data. Stored in special places (b, w or l)
3666 which say how many bits to store.
3667 ^ immediate data for floating point instructions. Special places
3668 are offset by 2 bytes from '#'...
3669 B pc-relative address, converted to an offset
3670 that is treated as immediate data.
3671 d displacement and register. Stores the register as 3 bits
3672 and stores the displacement in the entire second word.
3674 C the CCR. No need to store it; this is just for filtering validity.
3675 S the SR. No need to store, just as with CCR.
3676 U the USP. No need to store, just as with CCR.
3678 I Coprocessor ID. Not printed if 1. The Coprocessor ID is always
3679 extracted from the 'd' field of word one, which means that an extended
3680 coprocessor opcode can be skipped using the 'i' place, if needed.
3682 s System Control register for the floating point coprocessor.
3683 S List of system control registers for floating point coprocessor.
3685 J Misc register for movec instruction, stored in 'j' format.
3687 000 SFC Source Function Code reg
3688 001 DFC Data Function Code reg
3689 002 CACR Cache Control Register
3690 800 USP User Stack Pointer
3691 801 VBR Vector Base reg
3692 802 CAAR Cache Address Register
3693 803 MSP Master Stack Pointer
3694 804 ISP Interrupt Stack Pointer
3696 L Register list of the type d0-d7/a0-a7 etc.
3697 (New! Improved! Can also hold fp0-fp7, as well!)
3698 The assembler tries to see if the registers match the insn by
3699 looking at where the insn wants them stored.
3701 l Register list like L, but with all the bits reversed.
3702 Used for going the other way. . .
3704 They are all stored as 6 bits using an address mode and a register number;
3705 they differ in which addressing modes they match.
3707 * all (modes 0-6,7.*)
3708 ~ alterable memory (modes 2-6,7.0,7.1)(not 0,1,7.~)
3709 % alterable (modes 0-6,7.0,7.1)(not 7.~)
3710 ; data (modes 0,2-6,7.*)(not 1)
3711 @ data, but not immediate (modes 0,2-6,7.? ? ?)(not 1,7.?) This may really be ;, the 68020 book says it is
3712 ! control (modes 2,5,6,7.*-)(not 0,1,3,4,7.4)
3713 & alterable control (modes 2,5,6,7.0,7.1)(not 0,1,7.? ? ?)
3714 $ alterable data (modes 0,2-6,7.0,7.1)(not 1,7.~)
3715 ? alterable control, or data register (modes 0,2,5,6,7.0,7.1)(not 1,3,4,7.~)
3716 / control, or data register (modes 0,2,5,6,7.0,7.1,7.2,7.3)(not 1,3,4,7.4)
3719 /* JF: for the 68851 */
3721 I didn't use much imagination in choosing the
3722 following codes, so many of them aren't very
3727 000 TC Translation Control reg
3728 100 CAL Current Access Level
3729 101 VAL Validate Access Level
3730 110 SCC Stack Change Control
3731 111 AC Access Control
3733 W wide pmmu registers
3735 001 DRP Dma Root Pointer
3736 010 SRP Supervisor Root Pointer
3737 011 CRP Cpu Root Pointer
3739 f function code register
3746 100 BAD Breakpoint Acknowledge Data
3747 101 BAC Breakpoint Acknowledge Control
3752 | memory (modes 2-6, 7.*)
3756 /* Places to put an operand, for non-general operands:
3757 s source, low bits of first word.
3758 d dest, shifted 9 in first word
3759 1 second word, shifted 12
3760 2 second word, shifted 6
3761 3 second word, shifted 0
3762 4 third word, shifted 12
3763 5 third word, shifted 6
3764 6 third word, shifted 0
3765 7 second word, shifted 7
3766 8 second word, shifted 10
3767 D store in both place 1 and place 3; for divul and divsl.
3768 b second word, low byte
3769 w second word (entire)
3770 l second and third word (entire)
3771 g branch offset for bra and similar instructions.
3772 The place to store depends on the magnitude of offset.
3773 t store in both place 7 and place 8; for floating point operations
3774 c branch offset for cpBcc operations.
3775 The place to store is word two if bit six of word one is zero,
3776 and words two and three if bit six of word one is one.
3777 i Increment by two, to skip over coprocessor extended operands. Only
3778 works with the 'I' format.
3779 k Dynamic K-factor field. Bits 6-4 of word 2, used as a register number.
3780 Also used for dynamic fmovem instruction.
3781 C floating point coprocessor constant - 7 bits. Also used for static
3783 j Movec register #, stored in 12 low bits of second word.
3785 Places to put operand, for general operands:
3786 d destination, shifted 6 bits in first word
3787 b source, at low bit of first word, and immediate uses one byte
3788 w source, at low bit of first word, and immediate uses two bytes
3789 l source, at low bit of first word, and immediate uses four bytes
3790 s source, at low bit of first word.
3791 Used sometimes in contexts where immediate is not allowed anyway.
3792 f single precision float, low bit of 1st word, immediate uses 4 bytes
3793 F double precision float, low bit of 1st word, immediate uses 8 bytes
3794 x extended precision float, low bit of 1st word, immediate uses 12 bytes
3795 p packed float, low bit of 1st word, immediate uses 12 bytes
3798 #define one(x) ((x) << 16)
3799 #define two(x, y) (((x) << 16) + y)
3808 /* end of tc-m68k.c */