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 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. */
28 /* note that this file includes real declarations and thus can only be included by one source file per executable. */
29 #include "opcode/m68k.h"
31 /* This variable contains the value to write out at the beginning of
32 the a.out file. The 2<<16 means that this is a 68020 file instead
33 of an old-style 68000 file */
35 long omagic
= 2<<16|OMAGIC
; /* Magic byte for header file */
40 /* This array holds the chars that always start a comment. If the
41 pre-processor is disabled, these aren't very useful */
42 const char comment_chars
[] = "|";
44 /* This array holds the chars that only start a comment at the beginning of
45 a line. If the line seems to have the form '# 123 filename'
46 .line and .file directives will appear in the pre-processed output */
47 /* Note that input_file.c hand checks for '#' at the beginning of the
48 first line of the input file. This is because the compiler outputs
49 #NO_APP at the beginning of its output. */
50 /* Also note that comments like this one will always work. */
51 const char line_comment_chars
[] = "#";
53 /* Chars that can be used to separate mant from exp in floating point nums */
54 const char EXP_CHARS
[] = "eE";
56 /* Chars that mean this number is a floating point constant */
60 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
62 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
63 changed in read.c . Ideally it shouldn't have to know about it at all,
64 but nothing is ideal around here.
67 int md_reloc_size
= 8; /* Size of relocation record */
69 /* Its an arbitrary name: This means I don't approve of it */
70 /* See flames below */
71 static struct obstack robyn
;
73 #define TAB(x,y) (((x)<<2)+(y))
74 #define TABTYPE(xy) ((xy) >> 2)
87 /* Operands we can parse: (And associated modes)
93 reg: address or data register
94 areg: address register
95 apc: address register, PC, ZPC or empty string
98 sz: w or l if omitted, l assumed
99 scale: 1 2 4 or 8 if omitted, 1 assumed
101 7.4 IMMED #num --> NUM
102 0.? DREG dreg --> dreg
103 1.? AREG areg --> areg
104 2.? AINDR areg@ --> *(areg)
105 3.? AINC areg@+ --> *(areg++)
106 4.? ADEC areg@- --> *(--areg)
107 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
108 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
109 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
110 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
111 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
112 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
113 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
114 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
115 7.0 ABSL num:sz --> *(num)
116 num --> *(num) (sz L assumed)
117 *** MSCR otherreg --> Magic
119 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
129 a1@(5,d2:w:1) @(45,d6:l:4)
134 #name@(numw) -->turn into PC rel mode
135 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
161 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
164 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
165 8-15==addr reg for operands that take both types */
168 DATA
= 1, /* 1- 8 == data registers 0-7 */
188 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
193 FPREG
, /* Eight FP registers */
202 COPNUM
= (FPREG
+8), /* Co-processor #1-#8 */
211 PC
, /* Program counter */
212 ZPC
, /* Hack for Program space, but 0 addressing */
214 CCR
, /* Condition code Reg */
216 /* These have to be in order for the movec instruction to work. */
217 USP
, /* User Stack Pointer */
218 ISP
, /* Interrupt stack pointer */
233 /* end of movec ordering constraints */
266 IC
, /* instruction cache token */
267 DC
, /* data cache token */
268 NC
, /* no cache token */
269 BC
, /* both caches token */
273 /* Internal form of an operand. */
275 char *error
; /* Couldn't parse it */
276 enum operand_type mode
; /* What mode this instruction is in. */
277 enum _register reg
; /* Base register */
278 struct m68k_exp
*con1
;
279 int ireg
; /* Index register */
280 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
281 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
282 struct m68k_exp
*con2
;
285 /* internal form of a 68020 instruction */
288 char *args
; /* list of opcode info */
291 int numo
; /* Number of shorts in opcode */
294 struct m68k_op operands
[6];
296 int nexp
; /* number of exprs in use */
297 struct m68k_exp exprs
[4];
299 int nfrag
; /* Number of frags we have to produce */
301 int fragoff
; /* Where in the current opcode[] the frag ends */
307 int nrel
; /* Num of reloc strucs in use */
315 } reloc
[5]; /* Five is enough??? */
318 #define cpu_of_arch(x) ((x) & m68000up)
319 #define float_of_arch(x) ((x) & mfloat)
320 #define mmu_of_arch(x) ((x) & mmmu)
322 static struct m68k_it the_ins
; /* the instruction being assembled */
324 /* Macros for adding things to the m68k_it struct */
326 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
328 /* Like addword, but goes BEFORE general operands */
329 #define insop(w) {int z;\
330 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
331 the_ins.opcode[z]=the_ins.opcode[z-1];\
332 for(z=0;z<the_ins.nrel;z++)\
333 the_ins.reloc[z].n+=2;\
334 the_ins.opcode[opcode->m_codenum]=w;\
339 #define add_exp(beg,end) (\
340 the_ins.exprs[the_ins.nexp].e_beg=beg,\
341 the_ins.exprs[the_ins.nexp].e_end=end,\
342 &the_ins.exprs[the_ins.nexp++]\
346 /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
347 #define add_fix(width,exp,pc_rel) {\
348 the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
349 (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
350 the_ins.reloc[the_ins.nrel].add=adds((exp));\
351 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
352 the_ins.reloc[the_ins.nrel].off=offs((exp));\
353 the_ins.reloc[the_ins.nrel].wid=width;\
354 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
357 #define add_frag(add,off,type) {\
358 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
359 the_ins.fragb[the_ins.nfrag].fadd=add;\
360 the_ins.fragb[the_ins.nfrag].foff=off;\
361 the_ins.fragb[the_ins.nfrag++].fragty=type;\
364 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
366 #define seg(exp) ((exp)->e_exp.X_seg)
367 #define adds(exp) ((exp)->e_exp.X_add_symbol)
368 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
369 #define offs(exp) ((exp)->e_exp.X_add_number)
374 unsigned long m_opcode
;
377 enum m68k_architecture m_arch
;
378 struct m68k_incant
*m_next
;
381 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
382 #define gettwo(x) (((x)->m_opcode)&0xffff)
387 static char *crack_operand(char *str
, struct m68k_op
*opP
);
388 static int get_num(struct m68k_exp
*exp
, int ok
);
389 static int get_regs(int i
, char *str
, struct m68k_op
*opP
);
390 static int reverse_16_bits(int in
);
391 static int reverse_8_bits(int in
);
392 static int try_index(char **s
, struct m68k_op
*opP
);
393 static void install_gen_operand(int mode
, int val
);
394 static void install_operand(int mode
, int val
);
395 static void s_bss(void);
396 static void s_data1(void);
397 static void s_data2(void);
398 static void s_even(void);
399 static void s_proc(void);
401 #else /* not __STDC__ */
403 static char *crack_operand();
404 static int get_num();
405 static int get_regs();
406 static int reverse_16_bits();
407 static int reverse_8_bits();
408 static int try_index();
409 static void install_gen_operand();
410 static void install_operand();
412 static void s_data1();
413 static void s_data2();
414 static void s_even();
415 static void s_proc();
417 #endif /* not __STDC__ */
419 static enum m68k_architecture current_architecture
= 0;
421 /* BCC68000 is for patching in an extra jmp instruction for long offsets
422 on the 68000. The 68000 doesn't support long branches with branchs */
424 /* This table desribes how you change sizes for the various types of variable
425 size expressions. This version only supports two kinds. */
427 /* Note that calls to frag_var need to specify the maximum expansion needed */
428 /* This is currently 10 bytes for DBCC */
431 How far Forward this mode will reach:
432 How far Backward this mode will reach:
433 How many bytes this mode will add to the size of the frag
434 Which mode to go to if the offset won't fit in this one
438 { 1, 1, 0, 0 }, /* First entries aren't used */
439 { 1, 1, 0, 0 }, /* For no good reason except */
440 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
443 { (127), (-128), 0, TAB(BRANCH
,SHORT
)},
444 { (32767), (-32768), 2, TAB(BRANCH
,LONG
) },
448 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
449 { (32767), (-32768), 2, TAB(FBRANCH
,LONG
)},
453 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
454 { (32767), (-32768), 2, TAB(PCREL
,LONG
)},
458 { (127), (-128), 0, TAB(BCC68000
,SHORT
)},
459 { (32767), (-32768), 2, TAB(BCC68000
,LONG
) },
460 { 0, 0, 6, 0 }, /* jmp long space */
463 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
464 { (32767), (-32768), 2, TAB(DBCC
,LONG
) },
465 { 0, 0, 10, 0 }, /* bra/jmp long space */
468 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
469 { 32767, -32768, 2, TAB(PCLEA
,LONG
) },
475 /* These are the machine dependent pseudo-ops. These are included so
476 the assembler can work on the output from the SUN C compiler, which
480 /* This table describes all the machine specific pseudo-ops the assembler
481 has to support. The fields are:
482 pseudo-op name without dot
483 function to call to execute this pseudo-op
484 Integer arg to pass to the function
486 const pseudo_typeS md_pseudo_table
[] = {
487 { "data1", s_data1
, 0 },
488 { "data2", s_data2
, 0 },
490 { "even", s_even
, 0 },
491 { "skip", s_space
, 0 },
492 { "proc", s_proc
, 0 },
497 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
498 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
500 #define issbyte(x) ((x)>=-128 && (x)<=127)
501 #define isubyte(x) ((x)>=0 && (x)<=255)
502 #define issword(x) ((x)>=-32768 && (x)<=32767)
503 #define isuword(x) ((x)>=0 && (x)<=65535)
505 #define isbyte(x) ((x)>=-128 && (x)<=255)
506 #define isword(x) ((x)>=-32768 && (x)<=65535)
507 #define islong(x) (1)
509 extern char *input_line_pointer
;
516 /* JF these tables here are for speed at the expense of size */
517 /* You can replace them with the #if 0 versions if you really
518 need space and don't mind it running a bit slower */
520 static char mklower_table
[256];
521 #define mklower(c) (mklower_table[(unsigned char)(c)])
522 static char notend_table
[256];
523 static char alt_notend_table
[256];
524 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
525 alt_notend_table[(unsigned char)(s[1])])))
528 #define mklower(c) (isupper(c) ? tolower(c) : c)
532 /* JF modified this to handle cases where the first part of a symbol name
533 looks like a register */
536 * m68k_reg_parse() := if it looks like a register, return it's token &
537 * advance the pointer.
540 enum _register
m68k_reg_parse(ccp
)
543 #ifndef MAX_REG_NAME_LEN
544 #define MAX_REG_NAME_LEN (6)
545 #endif /* MAX_REG_NAME_LEN */
546 register char c
[MAX_REG_NAME_LEN
];
551 c
[0] = mklower(ccp
[0][0]);
552 #ifdef REGISTER_PREFIX
553 if (c
[0] != REGISTER_PREFIX
) {
558 for (p
= c
, q
= ccp
[0]; p
< c
+ MAX_REG_NAME_LEN
; ++p
, ++q
)
571 if(c
[1]>='0' && c
[1]<='7') {
576 else if (c
[1] == 'c') {
586 if (c
[3] >= '0' && c
[3] <= '7') {
588 ret
= BAD
+ c
[3] - '0';
592 if (c
[3] >= '0' && c
[3] <= '7') {
594 ret
= BAC
+ c
[3] - '0';
597 } else if (c
[1] == 'c') {
605 if (c
[1] == 'a' && c
[2] == 'l') {
610 /* This supports both CCR and CC as the ccr reg. */
611 if(c
[1]=='c' && c
[2]=='r') {
614 } else if(c
[1]=='c') {
617 } else if(c
[1]=='a' && (c
[2]=='a' || c
[2]=='c') && c
[3]=='r') {
619 ret
= c
[2]=='a' ? CAAR
: CACR
;
622 else if (c
[1] == 'r' && c
[2] == 'p') {
629 if (c
[1] >= '0' && c
[1] <= '7') {
631 ret
= DATA
+ c
[1] - '0';
632 } else if (c
[1] == 'f' && c
[2] == 'c') {
635 } else if (c
[1] == 'c') {
638 } else if (c
[1] == 't' && c
[2] == 't') {
639 if ('0' <= c
[3] && c
[3] <= '1') {
641 ret
= DTT0
+ (c
[3] - '0');
645 else if (c
[1] == 'r' && c
[2] == 'p') {
653 if(c
[2]>='0' && c
[2]<='7') {
655 ret
= FPREG
+c
[2]-'0';
658 } else if(c
[2]=='i') {
661 } else if(c
[2]=='s') {
662 n
= (c
[3] == 'r' ? 4 : 3);
664 } else if(c
[2]=='c') {
665 n
= (c
[3] == 'r' ? 4 : 3);
671 if (c
[1] == 's' && c
[2] == 'p') {
674 } else if (c
[1] == 'c') {
677 } else if (c
[1] == 't' && c
[2] == 't') {
678 if ('0' <= c
[3] && c
[3] <= '1') {
680 ret
= ITT0
+ (c
[3] - '0');
685 if (c
[1] == 's' && c
[2] == 'p') {
688 } else if (c
[1] == 'm' && c
[2] == 'u' && c
[3] == 's' && c
[4] == 'r') {
702 if(c
[2] == 's' && c
[3]=='r') {
713 else if (c
[1] == 's' && c
[2] == 'r') {
721 if (c
[1] == 'c' && c
[2] == 'c') {
734 } else if (c
[1] == 'p') {
737 } else if (c
[1] == 'f' && c
[2] == 'c') {
749 if (c
[1] == 's' && c
[2] == 'p') {
752 } else if (c
[1] == 'r' && c
[2] == 'p') {
759 if (c
[1] == 'a' && c
[2] == 'l') {
764 if(c
[1]=='b' && c
[2]=='r') {
770 if(c
[1]=='p' && c
[2]=='c') {
779 #ifdef REGISTER_PREFIX
782 if(isalnum(ccp
[0][n
]) || ccp
[0][n
]=='_')
791 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
794 * m68k_ip_op := '#' + <anything>
795 * | <register> + range_sep + get_regs
798 * range_sep := '/' | '-' ;
800 * SKIP_WHITE := <empty> | ' ' ;
807 register struct m68k_op
*opP
;
815 } /* Find the beginning of the string */
818 opP
->error
="Missing operand";
822 for(strend
= str
; *strend
; strend
++) ;;
828 opP
->con1
=add_exp(str
,strend
);
831 } /* Guess what: A constant. Shar and enjoy */
833 i
= m68k_reg_parse(&str
);
835 /* is a register, is exactly a register, and is followed by '@' */
837 if((i
==FAIL
|| *str
!='\0') && *str
!='@') {
840 if(i
!=FAIL
&& (*str
=='/' || *str
=='-')) {
842 return(get_regs(i
,str
,opP
));
844 if ((stmp
=strchr(str
,'@')) != '\0') {
845 opP
->con1
=add_exp(str
,stmp
-1);
851 if ((current_architecture
& m68020up
) == 0) {
853 } /* if target is not a '20 or better */
856 if(*stmp
++!='(' || *strend
--!=')') {
857 opP
->error
="Malformed operand";
860 i
=try_index(&stmp
,opP
);
861 opP
->con2
=add_exp(stmp
,strend
);
869 } /* if there's an '@' */
871 opP
->con1
= add_exp(str
,strend
);
873 } /* not a register, not exactly a register, or no '@' */
878 if(i
>=DATA
+0 && i
<=DATA
+7)
880 else if(i
>=ADDR
+0 && i
<=ADDR
+7)
887 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
) { /* Can't indirect off non address regs */
888 opP
->error
="Invalid indirect register";
908 opP
->error
="Junk after indirect";
911 /* Some kind of indexing involved. Lets find out how bad it is */
912 i
=try_index(&str
,opP
);
913 /* Didn't start with an index reg, maybe its offset or offset,reg */
921 opP
->error
="Missing )";
923 case ',': i
=0; break;
924 case '(': i
++; break;
925 case ')': --i
; break;
928 /* if(str[-3]==':') {
945 opP->error="Specified size isn't :w or :l";
948 opP->con1=add_exp(beg_str,str-4);
949 opP->con1->e_siz=siz;
951 opP
->con1
=add_exp(beg_str
,str
-2);
952 /* Should be offset,reg */
954 i
=try_index(&str
,opP
);
956 opP
->error
="Malformed index reg";
961 /* We've now got offset) offset,reg) or reg) */
964 /* Th-the-thats all folks */
965 if (opP
->reg
== FAIL
) opP
->mode
= AINDX
; /* Other form of indirect */
966 else if(opP
->ireg
== FAIL
) opP
->mode
= AOFF
;
967 else opP
->mode
= AINDX
;
970 /* Next thing had better be another @ */
971 if(*str
!='@' || str
[1]!='(') {
972 opP
->error
= "junk after indirect";
976 if ((current_architecture
& m68020up
) == 0) {
978 } /* if target is not a '20 or better */
982 if(opP
->ireg
!= FAIL
) {
985 i
= try_index(&str
, opP
);
987 opP
->error
= "Two index registers! not allowed!";
991 i
= try_index(&str
, opP
);
1002 opP
->error
="Missing )";
1004 case ',': i
=0; break;
1005 case '(': i
++; break;
1006 case ')': --i
; break;
1010 opP
->con2
=add_exp(beg_str
,str
-2);
1012 if (str
[-1] == ',') {
1013 if (opP
->ireg
!= FAIL
) {
1014 opP
->error
= "Can't have two index regs";
1018 i
= try_index(&str
, opP
);
1021 opP
->error
= "malformed index reg";
1026 } else if (opP
->ireg
!= FAIL
) {
1036 opP
->error
="Junk after indirect";
1040 } /* m68k_ip_op() */
1044 * try_index := data_or_address_register + ')' + SKIP_W
1045 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
1047 * multiplier := <empty>
1048 * | ':' + multiplier_number
1051 * multiplier_number := '1' | '2' | '4' | '8' ;
1053 * size_spec := 'l' | 'L' | 'w' | 'W' ;
1055 * SKIP_W := <empty> | ' ' ;
1059 static int try_index(s
,opP
)
1061 struct m68k_op
*opP
;
1065 #define SKIP_W() { ss++; if (*ss==' ') ss++;}
1069 i
=m68k_reg_parse(&ss
);
1070 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
1084 opP
->error
="Missing : in index register";
1099 opP
->error
="Index register size spec not :w or :l";
1114 opP
->error
="index multiplier not 1, 2, 4 or 8";
1121 opP
->error
="Missing )";
1130 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1134 struct m68k_op thark
;
1139 bzero(&thark
,sizeof(thark
));
1140 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
1142 printf("op1 error %s in %s\n",thark
.error
,buf
);
1143 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
1145 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
1146 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
1148 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
1157 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
1158 NULL means any use before m68k_ip_begin()
1165 * This converts a string into a 68k instruction.
1166 * The string must be a bare single instruction in sun format
1167 * with RMS-style 68020 indirects
1170 * It provides some error messages: at most one fatal error message (which
1171 * stops the scan) and at most one warning message for each operand.
1172 * The 68k instruction is returned in exploded form, since we have no
1173 * knowledge of how you parse (or evaluate) your expressions.
1174 * We do however strip off and decode addressing modes and operation
1177 * This function's value is a string. If it is not "" then an internal
1178 * logic error was found: read this code to assign meaning to the string.
1179 * No argument string should generate such an error string:
1180 * it means a bug in our code, not in the user's text.
1182 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1186 /* JF this function no longer returns a useful value. Sorry */
1187 void m68k_ip (instring
)
1191 register struct m68k_op
*opP
;
1192 register struct m68k_incant
*opcode
;
1194 register int tmpreg
= 0,
1203 char *crack_operand();
1204 LITTLENUM_TYPE words
[6];
1205 LITTLENUM_TYPE
*wordp
;
1207 if (*instring
== ' ')
1208 instring
++; /* skip leading whitespace */
1210 /* Scan up to end of operation-code, which MUST end in end-of-string
1211 or exactly 1 space. */
1212 for (p
= instring
; *p
!= '\0'; p
++)
1217 if (p
== instring
) {
1218 the_ins
.error
= "No operator";
1219 the_ins
.opcode
[0] = NULL
;
1220 /* the_ins.numo=1; */
1224 /* p now points to the end of the opcode name, probably whitespace.
1225 make sure the name is null terminated by clobbering the whitespace,
1226 look it up in the hash table, then fix it back. */
1229 opcode
= (struct m68k_incant
*)hash_find (op_hash
, instring
);
1232 if (opcode
== NULL
) {
1233 the_ins
.error
= "Unknown operator";
1234 the_ins
.opcode
[0] = NULL
;
1235 /* the_ins.numo=1; */
1239 /* found a legitimate opcode, start matching operands */
1240 while (*p
== ' ') ++p
;
1242 for(opP
= &the_ins
.operands
[0]; *p
; opP
++) {
1244 p
= crack_operand(p
, opP
);
1247 the_ins
.error
=opP
->error
;
1252 opsfound
= opP
- &the_ins
.operands
[0];
1254 /* This ugly hack is to support the floating pt opcodes in their standard form */
1255 /* Essentially, we fake a first enty of type COP#1 */
1256 if (opcode
->m_operands
[0]=='I') {
1259 for(n
=opsfound
;n
>0;--n
)
1260 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1262 /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
1263 bzero((char *)(&the_ins
.operands
[0]),sizeof(the_ins
.operands
[0]));
1264 the_ins
.operands
[0].mode
=MSCR
;
1265 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1269 /* We've got the operands. Find an opcode that'll accept them */
1270 for (losing
= 0; ; ) {
1271 /* if we didn't get the right number of ops,
1272 or we have no common model with this pattern
1273 then reject this pattern. */
1275 if (opsfound
!= opcode
->m_opnum
1276 || ((opcode
->m_arch
& current_architecture
) == 0)) {
1281 for (s
=opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++) {
1282 /* Warning: this switch is huge! */
1283 /* I've tried to organize the cases into this order:
1284 non-alpha first, then alpha by letter. lower-case goes directly
1285 before uppercase counterpart. */
1286 /* Code with multiple case ...: gets sorted by the lowest case ...
1287 it belongs to. I hope this makes sense. */
1290 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1291 || opP
->mode
== DREG
|| opP
->mode
== AREG
1292 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1293 || opP
->mode
== REGLST
)
1298 if(opP
->mode
!=IMMED
)
1303 t
=get_num(opP
->con1
,80);
1304 if(s
[1]=='b' && !isbyte(t
))
1306 else if(s
[1]=='w' && !isword(t
))
1313 if(opP
->mode
!=IMMED
)
1318 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1319 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1324 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1325 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1331 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1332 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1333 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1338 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1353 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1354 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1359 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1364 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1365 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1366 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1371 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1372 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1376 case '~': /* For now! (JF FOO is this right?) */
1377 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1378 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1387 if (opP
->mode
!= AINDR
) {
1389 } /* if not address register indirect */
1392 if(opP
->mode
!=ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1393 && instring
[1] == 'b'
1394 && instring
[2] == 's'
1395 && instring
[3] == 'r'))
1400 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1404 case 'd': /* FOO This mode is a KLUDGE!! */
1405 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1406 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1416 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1421 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1427 if (opP
->mode
!= MSCR
1430 || cpu_of_arch(current_architecture
) < m68010
/* before 68010 had none */
1431 || (cpu_of_arch(current_architecture
) < m68020
1435 && opP
->reg
!= VBR
) /* 68010's had only these */
1436 || (cpu_of_arch(current_architecture
) < m68040
1444 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1445 || (cpu_of_arch(current_architecture
) == m68040
/* 68040 has all but this */
1446 && opP
->reg
== CAAR
)) {
1448 } /* doesn't cut it */
1452 if(opP
->mode
!=IMMED
)
1458 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1463 opP
->reg
=1<<(opP
->reg
-DATA
);
1465 } else if(opP
->mode
!=REGLST
) {
1467 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1469 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1474 if(opP
->mode
!=IMMED
)
1479 t
=get_num(opP
->con1
,80);
1480 if(!issbyte(t
) || isvar(opP
->con1
))
1486 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1491 if(opP
->mode
!=IMMED
)
1496 t
=get_num(opP
->con1
,80);
1497 if(t
<1 || t
>8 || isvar(opP
->con1
))
1503 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1508 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1513 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1518 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1522 /* JF these are out of order. We could put them
1523 in order if we were willing to put up with
1524 bunches of #ifdef m68851s in the code */
1526 /* Memory addressing mode used by pflushr */
1528 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1529 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1534 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1539 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TC
&& opP
->reg
!= CAL
&&
1540 opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1545 if (opP
->reg
!= VAL
)
1550 if (opP
->mode
!= MSCR
|| (opP
->reg
!= DRP
&& opP
->reg
!= SRP
&&
1556 if (opP
->mode
!= MSCR
||
1557 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1558 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1563 if (opP
->reg
!= PSR
)
1568 if (opP
->reg
!= PCSR
)
1576 && opP
->reg
!= BC
) {
1578 } /* not a cache specifier. */
1582 if (opP
->mode
!= ABSL
) {
1584 } /* not absolute */
1588 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1589 *s
, __LINE__
, __FILE__
);
1590 } /* switch on type of operand */
1593 } /* for each operand */
1594 } /* if immediately wrong */
1600 opcode
= opcode
->m_next
;
1603 the_ins
.error
= "instruction/operands mismatch";
1605 } /* Fell off the end */
1610 /* now assemble it */
1612 the_ins
.args
=opcode
->m_operands
;
1613 the_ins
.numargs
=opcode
->m_opnum
;
1614 the_ins
.numo
=opcode
->m_codenum
;
1615 the_ins
.opcode
[0]=getone(opcode
);
1616 the_ins
.opcode
[1]=gettwo(opcode
);
1618 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++) {
1619 /* This switch is a doozy.
1620 Watch the first step; its a big one! */
1638 tmpreg
=0x3c; /* 7.4 */
1639 if (strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1640 else nextword
=nextword
=get_num(opP
->con1
,0);
1641 if(isvar(opP
->con1
))
1642 add_fix(s
[1],opP
->con1
,0);
1645 if(!isbyte(nextword
))
1646 opP
->error
="operand out of range";
1651 if(!isword(nextword
))
1652 opP
->error
="operand out of range";
1657 addword(nextword
>>16);
1679 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1680 *s
, s
[1], __LINE__
, __FILE__
);
1685 /* We gotta put out some float */
1686 if(seg(opP
->con1
)!=SEG_BIG
) {
1687 int_to_gen(nextword
);
1688 gen_to_words(words
,baseo
,(long int)outro
);
1689 for(wordp
=words
;baseo
--;wordp
++)
1693 if(offs(opP
->con1
)>0) {
1694 as_warn("Bignum assumed to be binary bit-pattern");
1695 if(offs(opP
->con1
)>baseo
) {
1696 as_warn("Bignum too big for %c format; truncated",s
[1]);
1697 offs(opP
->con1
)=baseo
;
1699 baseo
-=offs(opP
->con1
);
1700 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1706 gen_to_words(words
,baseo
,(long)outro
);
1707 for (wordp
=words
;baseo
--;wordp
++)
1711 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1714 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1717 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1720 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1723 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1727 nextword
=get_num(opP
->con1
,80);
1728 /* Force into index mode. Hope this works */
1730 /* We do the first bit for 32-bit displacements,
1731 and the second bit for 16 bit ones. It is
1732 possible that we should make the default be
1733 WORD instead of LONG, but I think that'd
1734 break GCC, so we put up with a little
1735 inefficiency for the sake of working output.
1738 if( !issword(nextword
)
1739 || ( isvar(opP
->con1
)
1740 && ( ( opP
->con1
->e_siz
==0
1741 && flagseen
['l']==0)
1742 || opP
->con1
->e_siz
==3))) {
1745 tmpreg
=0x3B; /* 7.3 */
1747 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1748 if(isvar(opP
->con1
)) {
1750 add_frag(adds(opP
->con1
),
1752 TAB(PCLEA
,SZ_UNDEF
));
1756 add_fix('l',opP
->con1
,1);
1760 addword(nextword
>>16);
1763 tmpreg
=0x3A; /* 7.2 */
1765 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
1767 if(isvar(opP
->con1
)) {
1769 add_fix('w',opP
->con1
,1);
1771 add_fix('w',opP
->con1
,0);
1780 know(current_architecture
& m68020up
);
1781 /* intentional fall-through */
1784 baseo
=get_num(opP
->con1
,80);
1785 outro
=get_num(opP
->con2
,80);
1786 /* Figure out the 'addressing mode' */
1787 /* Also turn on the BASE_DISABLE bit, if needed */
1788 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1789 tmpreg
=0x3b; /* 7.3 */
1792 } else if(opP
->reg
==FAIL
) {
1794 tmpreg
=0x30; /* 6.garbage */
1795 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1797 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
1798 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
1800 /* Index register stuff */
1801 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
1802 nextword
|=(opP
->ireg
-DATA
)<<12;
1804 if(opP
->isiz
==0 || opP
->isiz
==3)
1808 case 2: nextword
|=0x200; break;
1809 case 4: nextword
|=0x400; break;
1810 case 8: nextword
|=0x600; break;
1811 default: as_fatal("failed sanity check.");
1814 GET US OUT OF HERE! */
1816 /* Must be INDEX, with an index
1817 register. Address register
1818 cannot be ZERO-PC, and either
1819 :b was forced, or we know
1821 if( opP
->mode
==AINDX
1826 && !isvar(opP
->con1
)))) {
1827 nextword
+=baseo
&0xff;
1829 if(isvar(opP
->con1
))
1830 add_fix('B',opP
->con1
,0);
1834 nextword
|=0x40; /* No index reg */
1836 /* It aint simple */
1838 /* If the guy specified a width, we assume that
1839 it is wide enough. Maybe it isn't. If so, we lose
1843 if(isvar(opP
->con1
) || !issword(baseo
)) {
1854 as_warn("Byte dispacement won't work. Defaulting to :w");
1863 /* Figure out innner displacement stuff */
1864 if(opP
->mode
!=AINDX
) {
1867 if(isvar(opP
->con2
) || !issword(outro
)) {
1878 as_warn("Byte dispacement won't work. Defaulting to :w");
1886 if(opP
->mode
==APODX
) nextword
|=0x04;
1887 else if(opP
->mode
==AMIND
) nextword
|=0x40;
1891 if(isvar(opP
->con1
)) {
1892 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1893 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
1894 opP
->con1
->e_exp
.X_add_number
+=6;
1896 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
1903 if(isvar(opP
->con2
)) {
1904 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1905 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
1906 opP
->con1
->e_exp
.X_add_number
+=6;
1908 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
1918 nextword
=get_num(opP
->con1
,80);
1919 switch(opP
->con1
->e_siz
) {
1921 as_warn("Unknown size for absolute reference");
1923 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
1924 tmpreg
=0x38; /* 7.0 */
1928 /* Don't generate pc relative code
1929 on 68010 and 68000 */
1932 && seg(opP
->con1
) == SEG_TEXT
1933 && now_seg
== SEG_TEXT
1934 && cpu_of_arch(current_architecture
) < m68020
1936 && !strchr("~%&$?", s
[0])) {
1937 tmpreg
=0x3A; /* 7.2 */
1938 add_frag(adds(opP
->con1
),
1940 TAB(PCREL
,SZ_UNDEF
));
1943 case 3: /* Fall through into long */
1944 if(isvar(opP
->con1
))
1945 add_fix('l',opP
->con1
,0);
1947 tmpreg
=0x39; /* 7.1 mode */
1948 addword(nextword
>>16);
1953 if(isvar(opP
->con1
))
1954 add_fix('w',opP
->con1
,0);
1956 tmpreg
=0x38; /* 7.0 mode */
1963 as_bad("unknown/incorrect operand");
1966 install_gen_operand(s
[1],tmpreg
);
1971 switch(s
[1]) { /* JF: I hate floating point! */
1986 tmpreg
=get_num(opP
->con1
,tmpreg
);
1987 if(isvar(opP
->con1
))
1988 add_fix(s
[1],opP
->con1
,0);
1990 case 'b': /* Danger: These do no check for
1991 certain types of overflow.
1994 opP
->error
="out of range";
1996 if(isvar(opP
->con1
))
1997 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
2001 opP
->error
="out of range";
2003 if(isvar(opP
->con1
))
2004 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
2007 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
2009 if(isvar(opP
->con1
))
2010 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
2016 install_operand(s
[1],tmpreg
);
2019 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
2027 install_operand(s
[1],opP
->reg
-ADDR
);
2031 tmpreg
=get_num(opP
->con1
,80);
2034 /* Needs no offsetting */
2035 add_fix('B',opP
->con1
,1);
2038 /* Offset the displacement to be relative to byte disp location */
2039 opP
->con1
->e_exp
.X_add_number
+=2;
2040 add_fix('w',opP
->con1
,1);
2045 if (cpu_of_arch(current_architecture
) < m68020
) /* 68000 or 010 */
2046 as_warn("Can't use long branches on 68000/68010");
2047 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
2048 /* Offset the displacement to be relative to byte disp location */
2049 opP
->con1
->e_exp
.X_add_number
+=4;
2050 add_fix('l',opP
->con1
,1);
2055 if(subs(opP
->con1
)) /* We can't relax it */
2058 /* This could either be a symbol, or an
2059 absolute address. No matter, the
2060 frag hacking will finger it out.
2061 Not quite: it can't switch from
2062 BRANCH to BCC68000 for the case
2063 where opnd is absolute (it needs
2064 to use the 68000 hack since no
2065 conditional abs jumps). */
2066 if (((cpu_of_arch(current_architecture
) < m68020
) || (0==adds(opP
->con1
)))
2067 && (the_ins
.opcode
[0] >= 0x6200)
2068 && (the_ins
.opcode
[0] <= 0x6f00)) {
2069 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
2071 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BRANCH
,SZ_UNDEF
));
2075 if(isvar(opP
->con1
)) {
2076 /* check for DBcc instruction */
2077 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
2078 /* size varies if patch */
2079 /* needed for long form */
2080 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
2085 opP
->con1
->e_exp
.X_add_number
+=2;
2086 add_fix('w',opP
->con1
,1);
2090 case 'C': /* Fixed size LONG coproc branches */
2091 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
2092 /* Offset the displacement to be relative to byte disp location */
2093 /* Coproc branches don't have a byte disp option, but they are
2094 compatible with the ordinary branches, which do... */
2095 opP
->con1
->e_exp
.X_add_number
+=4;
2096 add_fix('l',opP
->con1
,1);
2100 case 'c': /* Var size Coprocesssor branches */
2101 if(subs(opP
->con1
)) {
2102 add_fix('l',opP
->con1
,1);
2103 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
2104 } else if(adds(opP
->con1
)) {
2105 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
2107 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2108 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
2109 add_fix('l',opP
->con1
,1);
2115 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
2116 s
[1], __LINE__
, __FILE__
);
2120 case 'C': /* Ignore it */
2123 case 'd': /* JF this is a kludge */
2124 if(opP
->mode
==AOFF
) {
2125 install_operand('s',opP
->reg
-ADDR
);
2129 tmpP
=opP
->con1
->e_end
-2;
2131 opP
->con1
->e_end
-=4; /* point to the , */
2132 baseo
=m68k_reg_parse(&tmpP
);
2133 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
2134 as_bad("Unknown address reg, using A0");
2137 install_operand('s',baseo
);
2139 tmpreg
=get_num(opP
->con1
,80);
2140 if(!issword(tmpreg
)) {
2141 as_warn("Expression out of range, using 0");
2148 install_operand(s
[1],opP
->reg
-DATA
);
2152 install_operand(s
[1],opP
->reg
-FPREG
);
2156 tmpreg
=1+opP
->reg
-COPNUM
;
2159 install_operand(s
[1],tmpreg
);
2162 case 'J': /* JF foo */
2164 case SFC
: tmpreg
=0x000; break;
2165 case DFC
: tmpreg
=0x001; break;
2166 case CACR
: tmpreg
=0x002; break;
2167 case TC
: tmpreg
=0x003; break;
2168 case ITT0
: tmpreg
=0x004; break;
2169 case ITT1
: tmpreg
=0x005; break;
2170 case DTT0
: tmpreg
=0x006; break;
2171 case DTT1
: tmpreg
=0x007; break;
2173 case USP
: tmpreg
=0x800; break;
2174 case VBR
: tmpreg
=0x801; break;
2175 case CAAR
: tmpreg
=0x802; break;
2176 case MSP
: tmpreg
=0x803; break;
2177 case ISP
: tmpreg
=0x804; break;
2178 case MMUSR
: tmpreg
=0x805; break;
2179 case URP
: tmpreg
=0x806; break;
2180 case SRP
: tmpreg
=0x807; break;
2182 as_fatal("failed sanity check.");
2184 install_operand(s
[1],tmpreg
);
2188 tmpreg
=get_num(opP
->con1
,55);
2189 install_operand(s
[1],tmpreg
&0x7f);
2195 if(tmpreg
&0x7FF0000)
2196 as_bad("Floating point register in register list");
2197 insop(reverse_16_bits(tmpreg
));
2199 if(tmpreg
&0x700FFFF)
2200 as_bad("Wrong register in floating-point reglist");
2201 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
2208 if(tmpreg
&0x7FF0000)
2209 as_bad("Floating point register in register list");
2211 } else if(s
[1]=='8') {
2212 if(tmpreg
&0x0FFFFFF)
2213 as_bad("incorrect register in reglist");
2214 install_operand(s
[1],tmpreg
>>24);
2216 if(tmpreg
&0x700FFFF)
2217 as_bad("wrong register in floating-point reglist");
2219 install_operand(s
[1],tmpreg
>>16);
2224 install_operand(s
[1],get_num(opP
->con1
,60));
2228 tmpreg
= (opP
->mode
==DREG
)
2229 ? 0x20+opP
->reg
-DATA
2230 : (get_num(opP
->con1
,40)&0x1F);
2231 install_operand(s
[1],tmpreg
);
2235 tmpreg
=get_num(opP
->con1
,10);
2238 install_operand(s
[1],tmpreg
);
2242 /* This depends on the fact that ADDR registers are
2243 eight more than their corresponding DATA regs, so
2244 the result will have the ADDR_REG bit set */
2245 install_operand(s
[1],opP
->reg
-DATA
);
2249 if(opP
->reg
==FPI
) tmpreg
=0x1;
2250 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2251 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2252 else as_fatal("failed sanity check.");
2253 install_operand(s
[1],tmpreg
);
2256 case 'S': /* Ignore it */
2260 install_operand(s
[1],get_num(opP
->con1
,30));
2263 case 'U': /* Ignore it */
2268 case NC
: tmpreg
= 0; break;
2269 case DC
: tmpreg
= 1; break;
2270 case IC
: tmpreg
= 2; break;
2271 case BC
: tmpreg
= 3; break;
2273 as_fatal("failed sanity check");
2274 } /* switch on cache token */
2275 install_operand(s
[1], tmpreg
);
2278 /* JF: These are out of order, I fear. */
2288 as_fatal("failed sanity check.");
2290 install_operand(s
[1],tmpreg
);
2311 as_fatal("failed sanity check.");
2313 install_operand(s
[1],tmpreg
);
2317 if (opP
->reg
== VAL
)
2319 as_fatal("failed sanity check.");
2334 as_fatal("failed sanity check.");
2336 install_operand(s
[1],tmpreg
);
2341 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2342 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2343 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2346 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2347 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2348 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2352 as_fatal("failed sanity check.");
2354 install_operand(s
[1], tmpreg
);
2357 know(opP
->reg
== PSR
);
2360 know(opP
->reg
== PCSR
);
2364 tmpreg
=get_num(opP
->con1
,80);
2365 install_operand(s
[1], tmpreg
);
2368 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s
[0], __LINE__
, __FILE__
);
2371 /* By the time whe get here (FINALLY) the_ins contains the complete
2372 instruction, ready to be emitted. . . */
2376 * get_regs := '/' + ?
2377 * | '-' + <register>
2378 * | '-' + <register> + ?
2383 * The idea here must be to scan in a set of registers but I don't
2384 * understand it. Looks awfully sloppy to me but I don't have any doc on
2391 static int get_regs(i
,str
,opP
)
2393 struct m68k_op
*opP
;
2396 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2397 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2398 unsigned long cur_regs
= 0;
2402 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2403 else if(x==FPS) cur_regs|=(1<<25);\
2404 else if(x==FPC) cur_regs|=(1<<26);\
2405 else cur_regs|=(1<<(x-1)); }
2412 } else if(*str
=='-') {
2414 reg2
=m68k_reg_parse(&str
);
2415 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2416 opP
->error
="unknown register in register list";
2425 } else if(*str
=='\0') {
2429 opP
->error
="unknow character in register list";
2432 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2435 reg1
=m68k_reg_parse(&str
);
2436 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2437 opP
->error
="unknown register in register list";
2445 static int reverse_16_bits(in
)
2451 static int mask
[16] = {
2452 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2453 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2460 } /* reverse_16_bits() */
2462 static int reverse_8_bits(in
)
2468 static int mask
[8] = {
2469 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2477 } /* reverse_8_bits() */
2479 static void install_operand(mode
,val
)
2485 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2488 the_ins
.opcode
[0]|=val
<<9;
2491 the_ins
.opcode
[1]|=val
<<12;
2494 the_ins
.opcode
[1]|=val
<<6;
2497 the_ins
.opcode
[1]|=val
;
2500 the_ins
.opcode
[2]|=val
<<12;
2503 the_ins
.opcode
[2]|=val
<<6;
2506 /* DANGER! This is a hack to force cas2l and cas2w cmds
2507 to be three words long! */
2509 the_ins
.opcode
[2]|=val
;
2512 the_ins
.opcode
[1]|=val
<<7;
2515 the_ins
.opcode
[1]|=val
<<10;
2519 the_ins
.opcode
[1]|=val
<<5;
2524 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2527 the_ins
.opcode
[1]|=(val
<<12)|val
;
2530 the_ins
.opcode
[0]|=val
=0xff;
2533 the_ins
.opcode
[0]|=val
<<9;
2536 the_ins
.opcode
[1]|=val
;
2539 the_ins
.opcode
[1]|=val
;
2540 the_ins
.numo
++; /* What a hack */
2543 the_ins
.opcode
[1]|=val
<<4;
2550 the_ins
.opcode
[0] |= (val
<< 6);
2553 the_ins
.opcode
[1] = (val
>> 16);
2554 the_ins
.opcode
[2] = val
& 0xffff;
2558 as_fatal("failed sanity check.");
2560 } /* install_operand() */
2562 static void install_gen_operand(mode
,val
)
2568 the_ins
.opcode
[0]|=val
;
2571 /* This is a kludge!!! */
2572 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2581 the_ins
.opcode
[0]|=val
;
2583 /* more stuff goes here */
2585 as_fatal("failed sanity check.");
2587 } /* install_gen_operand() */
2590 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2591 * then deal with the bitfield hack.
2594 static char *crack_operand(str
,opP
)
2596 register struct m68k_op
*opP
;
2598 register int parens
;
2600 register char *beg_str
;
2606 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2607 if(*str
=='(') parens
++;
2608 else if(*str
==')') {
2609 if(!parens
) { /* ERROR */
2610 opP
->error
="Extra )";
2616 if(!*str
&& parens
) { /* ERROR */
2617 opP
->error
="Missing )";
2622 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2628 c
= *++str
; /* JF bitfield hack */
2632 as_bad("Missing operand");
2637 /* See the comment up above where the #define notend(... is */
2642 if(*s
==',') return 0;
2643 if(*s
=='{' || *s
=='}')
2645 if(*s
!=':') return 1;
2646 /* This kludge here is for the division cmd, which is a kludge */
2647 if(index("aAdD#",s
[1])) return 0;
2652 /* This is the guts of the machine-dependent assembler. STR points to a
2653 machine dependent instruction. This function is supposed to emit
2654 the frags/bytes it assembles to.
2665 int shorts_this_frag
;
2668 if (current_architecture
== 0) {
2669 current_architecture
= (m68020
2677 } /* default current_architecture */
2679 bzero((char *)(&the_ins
),sizeof(the_ins
)); /* JF for paranoia sake */
2683 for(n
=the_ins
.numargs
;n
;--n
)
2684 if(the_ins
.operands
[n
].error
) {
2685 er
=the_ins
.operands
[n
].error
;
2690 as_bad("\"%s\" -- Statement '%s' ignored",er
,str
);
2694 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
2695 toP
=frag_more(2*the_ins
.numo
);
2696 fromP
= &the_ins
.opcode
[0];
2697 for(m
=the_ins
.numo
;m
;--m
) {
2698 md_number_to_chars(toP
,(long)(*fromP
),2);
2702 /* put out symbol-dependent info */
2703 for(m
=0;m
<the_ins
.nrel
;m
++) {
2704 switch(the_ins
.reloc
[m
].wid
) {
2721 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
2725 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2727 the_ins
.reloc
[m
].add
,
2728 the_ins
.reloc
[m
].sub
,
2729 the_ins
.reloc
[m
].off
,
2730 the_ins
.reloc
[m
].pcrel
,
2736 /* There's some frag hacking */
2737 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
2740 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
2741 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2745 for(m
=wid
/2;m
;--m
) {
2746 md_number_to_chars(toP
,(long)(*fromP
),2);
2751 for(m
=0;m
<the_ins
.nrel
;m
++) {
2752 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
2753 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
2756 wid
=the_ins
.reloc
[m
].wid
;
2759 the_ins
.reloc
[m
].wid
=0;
2760 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2763 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2765 the_ins
.reloc
[m
].add
,
2766 the_ins
.reloc
[m
].sub
,
2767 the_ins
.reloc
[m
].off
,
2768 the_ins
.reloc
[m
].pcrel
,
2771 /* know(the_ins.fragb[n].fadd); */
2772 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
2773 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
2775 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2778 toP
=frag_more(n
*sizeof(short));
2780 md_number_to_chars(toP
,(long)(*fromP
),2);
2786 for(m
=0;m
<the_ins
.nrel
;m
++) {
2789 wid
=the_ins
.reloc
[m
].wid
;
2792 the_ins
.reloc
[m
].wid
=0;
2793 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2796 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
2798 the_ins
.reloc
[m
].add
,
2799 the_ins
.reloc
[m
].sub
,
2800 the_ins
.reloc
[m
].off
,
2801 the_ins
.reloc
[m
].pcrel
,
2806 /* This function is called once, at assembler startup time. This should
2807 set up all the tables, etc that the MD part of the assembler needs
2813 * md_begin -- set up hash tables with 68000 instructions.
2814 * similar to what the vax assembler does. ---phr
2816 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2817 a copy of it at runtime, adding in the information we want but isn't
2818 there. I think it'd be better to have an awk script hack the table
2819 at compile time. Or even just xstr the table and use it as-is. But
2820 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2823 register const struct m68k_opcode
*ins
;
2824 register struct m68k_incant
*hack
,
2826 register char *retval
= 0; /* empty string, or error msg text */
2827 register unsigned int i
;
2830 if ((op_hash
= hash_new()) == NULL
)
2831 as_fatal("Virtual memory exhausted");
2833 obstack_begin(&robyn
,4000);
2834 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
2835 hack
=slak
=(struct m68k_incant
*)obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2837 /* we *could* ignore insns that don't match our
2838 arch here but just leaving them out of the
2840 slak
->m_operands
=ins
->args
;
2841 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
2842 slak
->m_arch
= ins
->arch
;
2843 slak
->m_opcode
=ins
->opcode
;
2844 /* This is kludgey */
2845 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
2846 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
2847 slak
->m_next
=(struct m68k_incant
*) obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2854 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
2855 /* Didn't his mommy tell him about null pointers? */
2856 if(retval
&& *retval
)
2857 as_fatal("Internal Error: Can't hash %s: %s",ins
->name
,retval
);
2860 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
2861 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
2863 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
2864 notend_table
[i
] = 0;
2865 alt_notend_table
[i
] = 0;
2867 notend_table
[','] = 1;
2868 notend_table
['{'] = 1;
2869 notend_table
['}'] = 1;
2870 alt_notend_table
['a'] = 1;
2871 alt_notend_table
['A'] = 1;
2872 alt_notend_table
['d'] = 1;
2873 alt_notend_table
['D'] = 1;
2874 alt_notend_table
['#'] = 1;
2875 alt_notend_table
['f'] = 1;
2876 alt_notend_table
['F'] = 1;
2877 #ifdef REGISTER_PREFIX
2878 alt_notend_table
[REGISTER_PREFIX
] = 1;
2883 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2884 || (*s == ':' && strchr("aAdD#", s[1]))) \
2888 /* This funciton is called once, before the assembler exits. It is
2889 supposed to do any final cleanup for this part of the assembler.
2896 /* Equal to MAX_PRECISION in atof-ieee.c */
2897 #define MAX_LITTLENUMS 6
2899 /* Turn a string in input_line_pointer into a floating point constant of type
2900 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2901 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2904 md_atof(type
,litP
,sizeP
)
2910 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2911 LITTLENUM_TYPE
*wordP
;
2942 return "Bad call to MD_ATOF()";
2944 t
=atof_ieee(input_line_pointer
,type
,words
);
2946 input_line_pointer
=t
;
2948 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
2949 for(wordP
=words
;prec
--;) {
2950 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
2951 litP
+=sizeof(LITTLENUM_TYPE
);
2953 return ""; /* Someone should teach Dean about null pointers */
2956 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2957 for use in the a.out file, and stores them in the array pointed to by buf.
2958 This knows about the endian-ness of the target machine and does
2959 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2960 2 (short) and 4 (long) Floating numbers are put out as a series of
2961 LITTLENUMS (shorts, here at least)
2964 md_number_to_chars(buf
,val
,n
)
2984 as_fatal("failed sanity check.");
2989 md_apply_fix(fixP
, val
)
2993 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2995 switch(fixP
->fx_size
) {
3010 BAD_CASE (fixP
->fx_size
);
3015 /* *fragP has been relaxed to its final size, and now needs to have
3016 the bytes inside it modified to conform to the new size There is UGLY
3020 md_convert_frag(headers
, fragP
)
3021 object_headers
*headers
;
3022 register fragS
*fragP
;
3027 /* Address in object code of the displacement. */
3028 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
3030 #ifdef IBM_COMPILER_SUX
3031 /* This is wrong but it convinces the native rs6000 compiler to
3032 generate the code we want. */
3033 register char *buffer_address
= fragP
-> fr_literal
;
3034 buffer_address
+= fragP
-> fr_fix
;
3035 #else /* IBM_COMPILER_SUX */
3036 /* Address in gas core of the place to store the displacement. */
3037 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3038 #endif /* IBM_COMPILER_SUX */
3040 /* No longer true: know(fragP->fr_symbol); */
3042 /* The displacement of the address, from current location. */
3043 disp
= fragP
->fr_symbol
? S_GET_VALUE(fragP
->fr_symbol
) : 0;
3044 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3046 switch(fragP
->fr_subtype
) {
3047 case TAB(BCC68000
,BYTE
):
3048 case TAB(BRANCH
,BYTE
):
3049 know(issbyte(disp
));
3051 as_bad("short branch with zero offset: use :w");
3052 fragP
->fr_opcode
[1]=disp
;
3055 case TAB(DBCC
,SHORT
):
3056 know(issword(disp
));
3059 case TAB(BCC68000
,SHORT
):
3060 case TAB(BRANCH
,SHORT
):
3061 know(issword(disp
));
3062 fragP
->fr_opcode
[1]=0x00;
3065 case TAB(BRANCH
,LONG
):
3066 if (cpu_of_arch(current_architecture
) < m68020
) {
3067 if (fragP
->fr_opcode
[0]==0x61) {
3068 fragP
->fr_opcode
[0]= 0x4E;
3069 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3070 subseg_change(SEG_TEXT
, 0);
3083 } else if (fragP
->fr_opcode
[0]==0x60) {
3084 fragP
->fr_opcode
[0]= 0x4E;
3085 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3086 subseg_change(SEG_TEXT
, 0);
3087 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
3092 as_bad("Long branch offset not supported.");
3095 fragP
->fr_opcode
[1]=0xff;
3099 case TAB(BCC68000
,LONG
):
3100 /* only Bcc 68000 instructions can come here */
3101 /* change bcc into b!cc/jmp absl long */
3102 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3103 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
3105 /* JF: these used to be fr_opcode[2,3], but they may be in a
3106 different frag, in which case refering to them is a no-no.
3107 Only fr_opcode[0,1] are guaranteed to work. */
3108 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3109 *buffer_address
++ = 0xf9;
3110 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3111 subseg_change(SEG_TEXT
,0);
3112 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3118 case TAB(DBCC
,LONG
):
3119 /* only DBcc 68000 instructions can come here */
3120 /* change dbcc into dbcc/jmp absl long */
3121 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3122 *buffer_address
++ = 0x00; /* branch offset = 4 */
3123 *buffer_address
++ = 0x04;
3124 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3125 *buffer_address
++ = 0x06;
3126 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3127 *buffer_address
++ = 0xf9;
3129 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3130 subseg_change(SEG_TEXT
,0);
3131 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3137 case TAB(FBRANCH
,SHORT
):
3138 know((fragP
->fr_opcode
[1]&0x40)==0);
3141 case TAB(FBRANCH
,LONG
):
3142 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
3145 case TAB(PCREL
,SHORT
):
3148 case TAB(PCREL
,LONG
):
3149 /* The thing to do here is force it to ABSOLUTE LONG, since
3150 PCREL is really trying to shorten an ABSOLUTE address anyway */
3151 /* JF FOO This code has not been tested */
3152 subseg_change(SEG_TEXT
,0);
3153 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3154 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3155 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3156 fragP
->fr_opcode
[0],fragP
->fr_address
);
3157 fragP
->fr_opcode
[1]&= ~0x3F;
3158 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
3160 /* md_number_to_chars(buffer_address,
3161 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3165 case TAB(PCLEA
,SHORT
):
3166 subseg_change(SEG_TEXT
,0);
3167 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
3169 fragP
->fr_opcode
[1] &= ~0x3F;
3170 fragP
->fr_opcode
[1] |= 0x3A;
3173 case TAB(PCLEA
,LONG
):
3174 subseg_change(SEG_TEXT
,0);
3175 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
3177 *buffer_address
++ = 0x01;
3178 *buffer_address
++ = 0x70;
3180 /* buffer_address+=2; */
3184 } /* switch on subtype */
3187 md_number_to_chars(buffer_address
, (long) disp
, (int) ext
);
3188 fragP
->fr_fix
+= ext
;
3189 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3190 } /* if extending */
3193 } /* md_convert_frag() */
3195 /* Force truly undefined symbols to their maximum size, and generally set up
3196 the frag list to be relaxed
3198 int md_estimate_size_before_relax(fragP
, segment
)
3199 register fragS
*fragP
;
3203 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3205 old_fix
= fragP
->fr_fix
;
3207 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3208 switch(fragP
->fr_subtype
) {
3210 case TAB(BRANCH
,SZ_UNDEF
): {
3211 if((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3212 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3213 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
3215 } else if((fragP
->fr_symbol
== 0) || (cpu_of_arch(current_architecture
) < m68020
)) {
3216 /* On 68000, or for absolute value, switch to abs long */
3217 /* FIXME, we should check abs val, pick short or long */
3218 if(fragP
->fr_opcode
[0]==0x61) {
3219 fragP
->fr_opcode
[0]= 0x4E;
3220 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3221 subseg_change(SEG_TEXT
, 0);
3222 fix_new(fragP
, fragP
->fr_fix
, 4,
3223 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3226 } else if(fragP
->fr_opcode
[0]==0x60) {
3227 fragP
->fr_opcode
[0]= 0x4E;
3228 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3229 subseg_change(SEG_TEXT
, 0);
3230 fix_new(fragP
, fragP
->fr_fix
, 4,
3231 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3235 as_warn("Long branch offset to extern symbol not supported.");
3237 } else { /* Symbol is still undefined. Make it simple */
3238 fix_new(fragP
, (int)(fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3239 (symbolS
*)0, fragP
->fr_offset
+4, 1, NO_RELOC
);
3241 fragP
->fr_opcode
[1]=0xff;
3247 } /* case TAB(BRANCH,SZ_UNDEF) */
3249 case TAB(FBRANCH
,SZ_UNDEF
): {
3250 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3251 fragP
->fr_subtype
= TAB(FBRANCH
,SHORT
);
3254 fragP
->fr_subtype
= TAB(FBRANCH
,LONG
);
3258 } /* TAB(FBRANCH,SZ_UNDEF) */
3260 case TAB(PCREL
,SZ_UNDEF
): {
3261 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3262 fragP
->fr_subtype
= TAB(PCREL
,SHORT
);
3265 fragP
->fr_subtype
= TAB(PCREL
,LONG
);
3269 } /* TAB(PCREL,SZ_UNDEF) */
3271 case TAB(BCC68000
,SZ_UNDEF
): {
3272 if((fragP
->fr_symbol
!= NULL
)
3273 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3274 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
3277 /* only Bcc 68000 instructions can come here */
3278 /* change bcc into b!cc/jmp absl long */
3279 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3281 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3282 /* JF: these were fr_opcode[2,3] */
3283 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3284 buffer_address
[1] = 0xf8;
3285 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3286 subseg_change(SEG_TEXT
,0);
3287 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3288 fragP
->fr_offset
, 0, NO_RELOC
);
3291 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3292 /* JF: these were fr_opcode[2,3] */
3293 buffer_address
[2] = 0x4e; /* put in jmp long (0x4ef9) */
3294 buffer_address
[3] = 0xf9;
3295 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3296 subseg_change(SEG_TEXT
,0);
3297 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3298 fragP
->fr_offset
, 0, NO_RELOC
);
3303 } /* case TAB(BCC68000,SZ_UNDEF) */
3305 case TAB(DBCC
,SZ_UNDEF
): {
3306 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3307 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3311 /* only DBcc 68000 instructions can come here */
3312 /* change dbcc into dbcc/jmp absl long */
3313 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3314 buffer_address
[0] = 0x00; /* branch offset = 4 */
3315 buffer_address
[1] = 0x04;
3316 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3319 /* JF: these were fr_opcode[5-7] */
3320 buffer_address
[3] = 0x04; /* plus 4 */
3321 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3322 buffer_address
[5] = 0xf8;
3323 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3324 subseg_change(SEG_TEXT
,0);
3325 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3326 fragP
->fr_offset
, 0, NO_RELOC
);
3329 /* JF: these were fr_opcode[5-7] */
3330 buffer_address
[3] = 0x06; /* Plus 6 */
3331 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3332 buffer_address
[5] = 0xf9;
3333 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3334 subseg_change(SEG_TEXT
,0);
3335 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3336 fragP
->fr_offset
, 0, NO_RELOC
);
3342 } /* case TAB(DBCC,SZ_UNDEF) */
3344 case TAB(PCLEA
,SZ_UNDEF
): {
3345 if ((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3346 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3349 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3353 } /* TAB(PCLEA,SZ_UNDEF) */
3358 } /* switch on subtype looking for SZ_UNDEF's. */
3360 /* now that SZ_UNDEF are taken care of, check others */
3361 switch(fragP
->fr_subtype
) {
3362 case TAB(BCC68000
,BYTE
):
3363 case TAB(BRANCH
,BYTE
):
3364 /* We can't do a short jump to the next instruction,
3365 so we force word mode. */
3366 if (fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3367 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3368 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3375 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3378 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3379 /* the bit-field entries in the relocation_info struct plays hell
3380 with the byte-order problems of cross-assembly. So as a hack,
3381 I added this mach. dependent ri twiddler. Ugly, but it gets
3383 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3384 are symbolnum, most sig. byte first. Last byte is broken up with
3385 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3386 nibble as nuthin. (on Sun 3 at least) */
3387 /* Translate the internal relocation information into target-specific
3391 md_ri_to_chars(the_bytes
, ri
)
3393 struct reloc_info_generic
*ri
;
3396 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3397 /* now the fun stuff */
3398 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3399 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3400 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3401 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3402 ((ri
->r_extern
<< 4) & 0x10));
3404 #endif /* comment */
3406 void tc_aout_fix_to_chars(where
, fixP
, segment_address_in_file
)
3409 relax_addressT segment_address_in_file
;
3412 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3413 * Out: GNU LD relocation length code: 0, 1, or 2.
3416 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
3422 md_number_to_chars(where
,
3423 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3426 /* now the fun stuff */
3427 if (S_GET_TYPE(fixP
->fx_addsy
) == N_UNDF
) {
3429 r_symbolnum
= fixP
->fx_addsy
->sy_number
;
3432 r_symbolnum
= S_GET_TYPE(fixP
->fx_addsy
);
3435 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3436 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3437 where
[6] = r_symbolnum
& 0x0ff;
3438 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3439 ((r_extern
<< 4) & 0x10));
3442 } /* tc_aout_fix_to_chars() */
3444 #endif /* OBJ_AOUT or OBJ_BOUT */
3446 #ifndef WORKING_DOT_WORD
3447 const int md_short_jump_size
= 4;
3448 const int md_long_jump_size
= 6;
3451 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3460 offset
= to_addr
- (from_addr
+2);
3462 md_number_to_chars(ptr
,(long)0x6000,2);
3463 md_number_to_chars(ptr
+2,(long)offset
,2);
3467 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3476 if (cpu_of_arch(current_architecture
) < m68020
) {
3477 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3478 md_number_to_chars(ptr
,(long)0x4EF9,2);
3479 md_number_to_chars(ptr
+2,(long)offset
,4);
3480 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3483 offset
=to_addr
- (from_addr
+2);
3484 md_number_to_chars(ptr
,(long)0x60ff,2);
3485 md_number_to_chars(ptr
+2,(long)offset
,4);
3490 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3493 10: Absolute 1:8 only
3494 20: Absolute 0:7 only
3495 30: absolute 0:15 only
3496 40: Absolute 0:31 only
3497 50: absolute 0:127 only
3498 55: absolute -64:63 only
3499 60: absolute -128:127 only
3500 70: absolute 0:4095 only
3505 static int get_num(exp
,ok
)
3506 struct m68k_exp
*exp
;
3514 if(*exp
->e_beg
=='0') {
3515 if(exp
->e_beg
[1]=='x')
3516 sscanf(exp
->e_beg
+2,"%x",&l
);
3518 sscanf(exp
->e_beg
+1,"%O",&l
);
3521 return atol(exp
->e_beg
);
3527 /* Can't do anything */
3530 if(!exp
->e_beg
|| !exp
->e_end
) {
3531 seg(exp
)=SEG_ABSOLUTE
;
3534 offs(exp
)= (ok
==10) ? 1 : 0;
3535 as_warn("Null expression defaults to %ld",offs(exp
));
3540 if(/* ok!=80 && */exp
->e_end
[-1]==':' && (exp
->e_end
-exp
->e_beg
)>=2) {
3541 switch(exp
->e_end
[0]) {
3557 as_bad("Unknown size for expression \"%c\"",exp
->e_end
[0]);
3561 c_save
=exp
->e_end
[1];
3563 save_in
=input_line_pointer
;
3564 input_line_pointer
=exp
->e_beg
;
3565 switch(expression(&(exp
->e_exp
))) {
3567 seg(exp
)=SEG_ABSOLUTE
;
3570 offs(exp
)= (ok
==10) ? 1 : 0;
3571 as_warn("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
3575 /* Do the same thing the VAX asm does */
3576 seg(exp
)=SEG_ABSOLUTE
;
3581 as_warn("expression out of range: defaulting to 1");
3588 if(offs(exp
)<1 || offs(exp
)>8) {
3589 as_warn("expression out of range: defaulting to 1");
3594 if(offs(exp
)<0 || offs(exp
)>7)
3598 if(offs(exp
)<0 || offs(exp
)>15)
3602 if(offs(exp
)<0 || offs(exp
)>32)
3606 if(offs(exp
)<0 || offs(exp
)>127)
3610 if(offs(exp
)<-64 || offs(exp
)>63)
3614 if(offs(exp
)<-128 || offs(exp
)>127)
3618 if(offs(exp
)<0 || offs(exp
)>4095) {
3620 as_warn("expression out of range: defaulting to 0");
3632 case SEG_DIFFERENCE
:
3633 if(ok
>=10 && ok
<=70) {
3634 seg(exp
)=SEG_ABSOLUTE
;
3637 offs(exp
)= (ok
==10) ? 1 : 0;
3638 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3642 if(ok
==80 && offs(exp
)<0) { /* HACK! Turn it into a long */
3643 LITTLENUM_TYPE words
[6];
3645 gen_to_words(words
,2,8L);/* These numbers are magic! */
3646 seg(exp
)=SEG_ABSOLUTE
;
3649 offs(exp
)=words
[1]|(words
[0]<<16);
3651 seg(exp
)=SEG_ABSOLUTE
;
3654 offs(exp
)= (ok
==10) ? 1 : 0;
3655 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3659 as_fatal("failed sanity check.");
3661 if(input_line_pointer
!=exp
->e_end
+1)
3662 as_bad("Ignoring junk after expression");
3663 exp
->e_end
[1]=c_save
;
3664 input_line_pointer
=save_in
;
3666 switch(exp
->e_siz
) {
3668 if(!isbyte(offs(exp
)))
3669 as_warn("expression doesn't fit in BYTE");
3672 if(!isword(offs(exp
)))
3673 as_warn("expression doesn't fit in WORD");
3681 /* These are the back-ends for the various machine dependent pseudo-ops. */
3682 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
3684 static void s_data1() {
3685 subseg_new(SEG_DATA
,1);
3686 demand_empty_rest_of_line();
3689 static void s_data2() {
3690 subseg_new(SEG_DATA
,2);
3691 demand_empty_rest_of_line();
3694 static void s_bss() {
3695 /* We don't support putting frags in the BSS segment, but we
3696 can put them into initialized data for now... */
3697 subseg_new(SEG_DATA
,255); /* FIXME-SOON */
3698 demand_empty_rest_of_line();
3701 static void s_even() {
3703 register long temp_fill
;
3705 temp
= 1; /* JF should be 2? */
3706 temp_fill
= get_absolute_expression ();
3707 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
3708 frag_align (temp
, (int)temp_fill
);
3709 demand_empty_rest_of_line();
3712 static void s_proc() {
3713 demand_empty_rest_of_line();
3716 /* s_space is defined in read.c .skip is simply an alias to it. */
3720 * Invocation line includes a switch not recognized by the base assembler.
3721 * See if it's a processor-specific option. These are:
3723 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3724 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3725 * Select the architecture. Instructions or features not
3726 * supported by the selected architecture cause fatal
3727 * errors. More than one may be specified. The default is
3728 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3729 * for -m68000, and -m68882 is a synonym for -m68881.
3731 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
3732 * (e.g. m68020) also requests that float instructions be included. This
3733 * is the default setup, mostly to avoid hassling users. A better
3734 * rearrangement of this structure would be to add an option to DENY
3735 * floating point opcodes, for people who want to really know there's none
3736 * of that funny floaty stuff going on. FIXME-later.
3738 #ifndef MAYBE_FLOAT_TOO
3739 #define MAYBE_FLOAT_TOO m68881
3742 int md_parse_option(argP
,cntP
,vecP
)
3748 case 'l': /* -l means keep external to 2 bit offset
3749 rather than 16 bit one */
3752 case 'S': /* -S means that jbsr's always turn into jsr's. */
3757 /* intentional fall-through */
3763 } /* allow an optional "c" */
3765 if (!strcmp(*argP
, "68000")
3766 || !strcmp(*argP
, "68008")) {
3767 current_architecture
|= m68000
;
3768 } else if (!strcmp(*argP
, "68010")) {
3770 omagic
= 1<<16|OMAGIC
;
3772 current_architecture
|= m68010
;
3774 } else if (!strcmp(*argP
, "68020")) {
3775 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
3777 } else if (!strcmp(*argP
, "68030")) {
3778 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
3780 } else if (!strcmp(*argP
, "68040")) {
3781 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
3784 } else if (!strcmp(*argP
, "68881")) {
3785 current_architecture
|= m68881
;
3787 } else if (!strcmp(*argP
, "68882")) {
3788 current_architecture
|= m68882
;
3790 #endif /* NO_68881 */
3792 } else if (!strcmp(*argP
,"68851")) {
3793 current_architecture
|= m68851
;
3795 #endif /* NO_68851 */
3797 as_warn("Unknown architecture, \"%s\". option ignored", *argP
);
3798 } /* switch on architecture */
3800 while(**argP
) (*argP
)++;
3805 if (!strcmp(*argP
,"pic")) {
3807 break; /* -pic, Position Independent Code */
3821 /* TEST2: Test md_assemble() */
3822 /* Warning, this routine probably doesn't work anymore */
3826 struct m68k_it the_ins
;
3833 if(!gets(buf
) || !*buf
)
3835 if(buf
[0]=='|' || buf
[1]=='.')
3837 for(cp
=buf
;*cp
;cp
++)
3842 bzero(&the_ins
,sizeof(the_ins
));
3843 m68k_ip(&the_ins
,buf
);
3845 printf("Error %s in %s\n",the_ins
.error
,buf
);
3847 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
3848 for(n
=0;n
<the_ins
.numo
;n
++)
3849 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
3851 print_the_insn(&the_ins
.opcode
[0],stdout
);
3852 (void)putchar('\n');
3854 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
3855 if(the_ins
.operands
[n
].error
) {
3856 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
3859 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
3860 if(the_ins
.operands
[n
].b_const
)
3861 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
3862 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
3863 if(the_ins
.operands
[n
].b_iadd
)
3864 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
3865 (void)putchar('\n');
3877 while(*str
&& *str
!=' ')
3879 if(str
[-1]==':' || str
[1]=='=')
3886 /* Possible states for relaxation:
3888 0 0 branch offset byte (bra, etc)
3892 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3896 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3932 extern fragS
*text_frag_root
;
3934 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
3935 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3936 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
3937 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
3949 fputs("Internal error:",stderr
);
3950 _doprnt(format
,&args
,stderr
);
3951 (void)putc('\n',stderr
);
3957 /* We have no need to default values of symbols. */
3961 md_undefined_symbol (name
)
3967 /* Parse an operand that is machine-specific.
3968 We just return without modifying the expression if we have nothing
3973 md_operand (expressionP
)
3974 expressionS
*expressionP
;
3978 /* Round up a section size to the appropriate boundary. */
3980 md_section_align (segment
, size
)
3984 return size
; /* Byte alignment is fine */
3987 /* Exactly what point is a PC-relative offset relative TO?
3988 On the 68k, they're relative to the address of the offset, plus
3989 its size. (??? Is this right? FIXME-SOON!) */
3991 md_pcrel_from (fixP
)
3994 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
4004 /* end of tc-m68k.c */