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
);
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
)
545 if (isalpha(*start
) && is_name_beginner(*start
))
551 while (is_part_of_name(c
= *p
++))
554 symbolP
= symbol_find(start
);
557 if (symbolP
&& S_GET_SEGMENT(symbolP
) == SEG_REGISTER
)
560 return S_GET_VALUE(symbolP
);
568 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
571 * m68k_ip_op := '#' + <anything>
572 * | <register> + range_sep + get_regs
575 * range_sep := '/' | '-' ;
577 * SKIP_WHITE := <empty> | ' ' ;
584 register struct m68k_op
*opP
;
592 } /* Find the beginning of the string */
595 opP
->error
="Missing operand";
599 for(strend
= str
; *strend
; strend
++) ;;
605 opP
->con1
=add_exp(str
,strend
);
608 } /* Guess what: A constant. Shar and enjoy */
610 i
= m68k_reg_parse(&str
);
612 /* is a register, is exactly a register, and is followed by '@' */
614 if((i
==FAIL
|| *str
!='\0') && *str
!='@') {
617 if(i
!=FAIL
&& (*str
=='/' || *str
=='-')) {
619 return(get_regs(i
,str
,opP
));
621 if ((stmp
=strchr(str
,'@')) != '\0') {
622 opP
->con1
=add_exp(str
,stmp
-1);
628 if ((current_architecture
& m68020up
) == 0) {
630 } /* if target is not a '20 or better */
633 if(*stmp
++!='(' || *strend
--!=')') {
634 opP
->error
="Malformed operand";
637 i
=try_index(&stmp
,opP
);
638 opP
->con2
=add_exp(stmp
,strend
);
646 } /* if there's an '@' */
648 opP
->con1
= add_exp(str
,strend
);
650 } /* not a register, not exactly a register, or no '@' */
655 if(i
>=DATA
+0 && i
<=DATA
+7)
657 else if(i
>=ADDR
+0 && i
<=ADDR
+7)
664 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
) { /* Can't indirect off non address regs */
665 opP
->error
="Invalid indirect register";
685 opP
->error
="Junk after indirect";
688 /* Some kind of indexing involved. Lets find out how bad it is */
689 i
=try_index(&str
,opP
);
690 /* Didn't start with an index reg, maybe its offset or offset,reg */
698 opP
->error
="Missing )";
700 case ',': i
=0; break;
701 case '(': i
++; break;
702 case ')': --i
; break;
705 /* if(str[-3]==':') {
722 opP->error="Specified size isn't :w or :l";
725 opP->con1=add_exp(beg_str,str-4);
726 opP->con1->e_siz=siz;
728 opP
->con1
=add_exp(beg_str
,str
-2);
729 /* Should be offset,reg */
731 i
=try_index(&str
,opP
);
733 opP
->error
="Malformed index reg";
738 /* We've now got offset) offset,reg) or reg) */
741 /* Th-the-thats all folks */
742 if (opP
->reg
== FAIL
) opP
->mode
= AINDX
; /* Other form of indirect */
743 else if(opP
->ireg
== FAIL
) opP
->mode
= AOFF
;
744 else opP
->mode
= AINDX
;
747 /* Next thing had better be another @ */
759 if ((current_architecture
& m68020up
) == 0) {
761 } /* if target is not a '20 or better */
764 if(opP
->ireg
!= FAIL
) {
767 i
= try_index(&str
, opP
);
769 opP
->error
= "Two index registers! not allowed!";
773 i
= try_index(&str
, opP
);
785 opP
->error
="Missing )";
788 case ',': i
=0; break;
789 case '(': i
++; break;
790 case ')': --i
; break;
794 opP
->con2
=add_exp(beg_str
,str
-2);
796 if (str
[-1] == ',') {
797 if (opP
->ireg
!= FAIL
) {
798 opP
->error
= "Can't have two index regs";
802 i
= try_index(&str
, opP
);
805 opP
->error
= "malformed index reg";
810 } else if (opP
->ireg
!= FAIL
) {
820 opP
->error
="Junk after indirect";
828 * try_index := data_or_address_register + ')' + SKIP_W
829 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
831 * multiplier := <empty>
832 * | ':' + multiplier_number
835 * multiplier_number := '1' | '2' | '4' | '8' ;
837 * size_spec := 'l' | 'L' | 'w' | 'W' ;
839 * SKIP_W := <empty> | ' ' ;
843 static int try_index(s
,opP
)
849 #define SKIP_W() { ss++; if (*ss==' ') ss++;}
853 i
=m68k_reg_parse(&ss
);
854 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
868 opP
->error
="Missing : in index register";
883 opP
->error
="Index register size spec not :w or :l";
898 opP
->error
="index multiplier not 1, 2, 4 or 8";
905 opP
->error
="Missing )";
914 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
918 struct m68k_op thark
;
923 memset(&thark
, '\0', sizeof(thark
));
924 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
926 printf("op1 error %s in %s\n",thark
.error
,buf
);
927 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
929 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
930 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
932 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
941 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
942 NULL means any use before m68k_ip_begin()
949 * This converts a string into a 68k instruction.
950 * The string must be a bare single instruction in sun format
951 * with RMS-style 68020 indirects
954 * It provides some error messages: at most one fatal error message (which
955 * stops the scan) and at most one warning message for each operand.
956 * The 68k instruction is returned in exploded form, since we have no
957 * knowledge of how you parse (or evaluate) your expressions.
958 * We do however strip off and decode addressing modes and operation
961 * This function's value is a string. If it is not "" then an internal
962 * logic error was found: read this code to assign meaning to the string.
963 * No argument string should generate such an error string:
964 * it means a bug in our code, not in the user's text.
966 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
970 /* JF this function no longer returns a useful value. Sorry */
971 void m68k_ip (instring
)
975 register struct m68k_op
*opP
;
976 register struct m68k_incant
*opcode
;
978 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
983 char *crack_operand();
984 LITTLENUM_TYPE words
[6];
985 LITTLENUM_TYPE
*wordp
;
987 if (*instring
== ' ')
988 instring
++; /* skip leading whitespace */
990 /* Scan up to end of operation-code, which MUST end in end-of-string
991 or exactly 1 space. */
992 for (p
= instring
; *p
!= '\0'; p
++)
998 the_ins
.error
= "No operator";
999 the_ins
.opcode
[0] = NULL
;
1000 /* the_ins.numo=1; */
1004 /* p now points to the end of the opcode name, probably whitespace.
1005 make sure the name is null terminated by clobbering the whitespace,
1006 look it up in the hash table, then fix it back. */
1009 opcode
= (struct m68k_incant
*)hash_find (op_hash
, instring
);
1012 if (opcode
== NULL
) {
1013 the_ins
.error
= "Unknown operator";
1014 the_ins
.opcode
[0] = NULL
;
1015 /* the_ins.numo=1; */
1019 /* found a legitimate opcode, start matching operands */
1020 while (*p
== ' ') ++p
;
1022 for(opP
= &the_ins
.operands
[0]; *p
; opP
++) {
1024 p
= crack_operand(p
, opP
);
1027 the_ins
.error
=opP
->error
;
1032 opsfound
= opP
- &the_ins
.operands
[0];
1034 /* This ugly hack is to support the floating pt opcodes in their standard form */
1035 /* Essentially, we fake a first enty of type COP#1 */
1036 if (opcode
->m_operands
[0]=='I') {
1039 for(n
=opsfound
;n
>0;--n
)
1040 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1042 /* memcpy((char *)(&the_ins.operands[1]), (char *)(&the_ins.operands[0]), opsfound*sizeof(the_ins.operands[0])); */
1043 memset((char *)(&the_ins
.operands
[0]), '\0', sizeof(the_ins
.operands
[0]));
1044 the_ins
.operands
[0].mode
=MSCR
;
1045 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1049 /* We've got the operands. Find an opcode that'll accept them */
1050 for (losing
= 0; ; ) {
1051 /* if we didn't get the right number of ops,
1052 or we have no common model with this pattern
1053 then reject this pattern. */
1055 if (opsfound
!= opcode
->m_opnum
1056 || ((opcode
->m_arch
& current_architecture
) == 0)) {
1061 for (s
=opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++) {
1062 /* Warning: this switch is huge! */
1063 /* I've tried to organize the cases into this order:
1064 non-alpha first, then alpha by letter. lower-case goes directly
1065 before uppercase counterpart. */
1066 /* Code with multiple case ...: gets sorted by the lowest case ...
1067 it belongs to. I hope this makes sense. */
1070 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1071 || opP
->mode
== DREG
|| opP
->mode
== AREG
1072 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1073 || opP
->mode
== REGLST
)
1078 if(opP
->mode
!=IMMED
)
1083 t
=get_num(opP
->con1
,80);
1084 if(s
[1]=='b' && !isbyte(t
))
1086 else if(s
[1]=='w' && !isword(t
))
1093 if(opP
->mode
!=IMMED
)
1098 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1099 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1104 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1105 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1111 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1112 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1113 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1118 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1133 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1134 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1139 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1144 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1145 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1146 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1151 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1152 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1156 case '~': /* For now! (JF FOO is this right?) */
1157 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1158 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1167 if (opP
->mode
!= AINDR
) {
1169 } /* if not address register indirect */
1172 if(opP
->mode
!=ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1173 && instring
[1] == 'b'
1174 && instring
[2] == 's'
1175 && instring
[3] == 'r'))
1180 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1184 case 'd': /* FOO This mode is a KLUDGE!! */
1185 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1186 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1196 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1201 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1207 if (opP
->mode
!= MSCR
1210 || cpu_of_arch(current_architecture
) < m68010
/* before 68010 had none */
1211 || (cpu_of_arch(current_architecture
) < m68020
1215 && opP
->reg
!= VBR
) /* 68010's had only these */
1216 || (cpu_of_arch(current_architecture
) < m68040
1224 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1225 || (cpu_of_arch(current_architecture
) == m68040
/* 68040 has all but this */
1226 && opP
->reg
== CAAR
)) {
1228 } /* doesn't cut it */
1232 if(opP
->mode
!=IMMED
)
1238 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1243 opP
->reg
=1<<(opP
->reg
-DATA
);
1245 } else if(opP
->mode
!=REGLST
) {
1247 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1249 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1254 if(opP
->mode
!=IMMED
)
1259 t
=get_num(opP
->con1
,80);
1260 if(!issbyte(t
) || isvar(opP
->con1
))
1266 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1271 if(opP
->mode
!=IMMED
)
1276 t
=get_num(opP
->con1
,80);
1277 if(t
<1 || t
>8 || isvar(opP
->con1
))
1283 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1288 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1293 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1298 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1302 /* JF these are out of order. We could put them
1303 in order if we were willing to put up with
1304 bunches of #ifdef m68851s in the code */
1306 /* Memory addressing mode used by pflushr */
1308 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1309 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1314 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1319 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TC
&& opP
->reg
!= CAL
&&
1320 opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1325 if (opP
->reg
!= VAL
)
1330 if (opP
->mode
!= MSCR
|| (opP
->reg
!= DRP
&& opP
->reg
!= SRP
&&
1336 if (opP
->mode
!= MSCR
||
1337 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1338 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1343 if (opP
->reg
!= PSR
)
1348 if (opP
->reg
!= PCSR
)
1356 && opP
->reg
!= BC
) {
1358 } /* not a cache specifier. */
1362 if (opP
->mode
!= ABSL
) {
1364 } /* not absolute */
1368 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1369 *s
, __LINE__
, __FILE__
);
1370 } /* switch on type of operand */
1373 } /* for each operand */
1374 } /* if immediately wrong */
1380 opcode
= opcode
->m_next
;
1383 the_ins
.error
= "instruction/operands mismatch or invalid\n instruction for this architecture";
1385 } /* Fell off the end */
1390 /* now assemble it */
1392 the_ins
.args
=opcode
->m_operands
;
1393 the_ins
.numargs
=opcode
->m_opnum
;
1394 the_ins
.numo
=opcode
->m_codenum
;
1395 the_ins
.opcode
[0]=getone(opcode
);
1396 the_ins
.opcode
[1]=gettwo(opcode
);
1398 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++) {
1399 /* This switch is a doozy.
1400 Watch the first step; its a big one! */
1418 tmpreg
=0x3c; /* 7.4 */
1419 if (strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1420 else nextword
=nextword
=get_num(opP
->con1
,0);
1421 if(isvar(opP
->con1
))
1422 add_fix(s
[1],opP
->con1
,0);
1425 if(!isbyte(nextword
))
1426 opP
->error
="operand out of range";
1431 if(!isword(nextword
))
1432 opP
->error
="operand out of range";
1437 addword(nextword
>>16);
1459 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1460 *s
, s
[1], __LINE__
, __FILE__
);
1465 /* We gotta put out some float */
1466 if(seg(opP
->con1
)!=SEG_BIG
) {
1467 int_to_gen(nextword
);
1468 gen_to_words(words
,baseo
,(long int)outro
);
1469 for(wordp
=words
;baseo
--;wordp
++)
1473 if(offs(opP
->con1
)>0) {
1474 as_warn("Bignum assumed to be binary bit-pattern");
1475 if(offs(opP
->con1
)>baseo
) {
1476 as_warn("Bignum too big for %c format; truncated",s
[1]);
1477 offs(opP
->con1
)=baseo
;
1479 baseo
-=offs(opP
->con1
);
1480 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1486 gen_to_words(words
,baseo
,(long)outro
);
1487 for (wordp
=words
;baseo
--;wordp
++)
1491 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1494 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1497 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1500 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1503 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1507 nextword
=get_num(opP
->con1
,80);
1508 /* Force into index mode. Hope this works */
1510 /* We do the first bit for 32-bit displacements,
1511 and the second bit for 16 bit ones. It is
1512 possible that we should make the default be
1513 WORD instead of LONG, but I think that'd
1514 break GCC, so we put up with a little
1515 inefficiency for the sake of working output.
1518 if( !issword(nextword
)
1519 || ( isvar(opP
->con1
)
1520 && ( ( opP
->con1
->e_siz
==0
1521 && flagseen
['l']==0)
1522 || opP
->con1
->e_siz
==3))) {
1525 tmpreg
=0x3B; /* 7.3 */
1527 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1528 if(isvar(opP
->con1
)) {
1530 add_frag(adds(opP
->con1
),
1532 TAB(PCLEA
,SZ_UNDEF
));
1536 add_fix('l',opP
->con1
,1);
1540 addword(nextword
>>16);
1543 tmpreg
=0x3A; /* 7.2 */
1545 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
1547 if(isvar(opP
->con1
)) {
1549 add_fix('w',opP
->con1
,1);
1551 add_fix('w',opP
->con1
,0);
1560 know(current_architecture
& m68020up
);
1561 /* intentional fall-through */
1564 baseo
=get_num(opP
->con1
,80);
1565 outro
=get_num(opP
->con2
,80);
1566 /* Figure out the 'addressing mode' */
1567 /* Also turn on the BASE_DISABLE bit, if needed */
1568 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1569 tmpreg
=0x3b; /* 7.3 */
1572 } else if(opP
->reg
==FAIL
) {
1574 tmpreg
=0x30; /* 6.garbage */
1575 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1577 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
1578 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
1580 /* Index register stuff */
1581 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
1582 nextword
|=(opP
->ireg
-DATA
)<<12;
1584 if(opP
->isiz
==0 || opP
->isiz
==3)
1588 case 2: nextword
|=0x200; break;
1589 case 4: nextword
|=0x400; break;
1590 case 8: nextword
|=0x600; break;
1591 default: as_fatal("failed sanity check.");
1594 GET US OUT OF HERE! */
1596 /* Must be INDEX, with an index
1597 register. Address register
1598 cannot be ZERO-PC, and either
1599 :b was forced, or we know
1601 if( opP
->mode
==AINDX
1606 && !isvar(opP
->con1
)))) {
1607 nextword
+=baseo
&0xff;
1609 if(isvar(opP
->con1
))
1610 add_fix('B',opP
->con1
,0);
1614 nextword
|=0x40; /* No index reg */
1616 /* It aint simple */
1618 /* If the guy specified a width, we assume that
1619 it is wide enough. Maybe it isn't. If so, we lose
1623 if(isvar(opP
->con1
) || !issword(baseo
)) {
1634 as_warn("Byte dispacement won't work. Defaulting to :w");
1643 /* Figure out innner displacement stuff */
1644 if(opP
->mode
!=AINDX
) {
1647 if(isvar(opP
->con2
) || !issword(outro
)) {
1658 as_warn("Byte dispacement won't work. Defaulting to :w");
1666 if(opP
->mode
==APODX
) nextword
|=0x04;
1667 else if(opP
->mode
==AMIND
) nextword
|=0x40;
1671 if(isvar(opP
->con1
)) {
1672 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1673 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
1674 opP
->con1
->e_exp
.X_add_number
+=6;
1676 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
1683 if(isvar(opP
->con2
)) {
1684 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1685 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
1686 opP
->con1
->e_exp
.X_add_number
+=6;
1688 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
1698 nextword
=get_num(opP
->con1
,80);
1699 switch(opP
->con1
->e_siz
) {
1701 as_warn("Unknown size for absolute reference");
1703 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
1704 tmpreg
=0x38; /* 7.0 */
1708 /* Don't generate pc relative code
1709 on 68010 and 68000 */
1712 && seg(opP
->con1
) == SEG_TEXT
1713 && now_seg
== SEG_TEXT
1714 && cpu_of_arch(current_architecture
) >= m68020
1716 && !strchr("~%&$?", s
[0])) {
1717 tmpreg
=0x3A; /* 7.2 */
1718 add_frag(adds(opP
->con1
),
1720 TAB(PCREL
,SZ_UNDEF
));
1723 case 3: /* Fall through into long */
1724 if(isvar(opP
->con1
))
1725 add_fix('l',opP
->con1
,0);
1727 tmpreg
=0x39; /* 7.1 mode */
1728 addword(nextword
>>16);
1733 if(isvar(opP
->con1
))
1734 add_fix('w',opP
->con1
,0);
1736 tmpreg
=0x38; /* 7.0 mode */
1743 as_bad("unknown/incorrect operand");
1746 install_gen_operand(s
[1],tmpreg
);
1751 switch(s
[1]) { /* JF: I hate floating point! */
1766 tmpreg
=get_num(opP
->con1
,tmpreg
);
1767 if(isvar(opP
->con1
))
1768 add_fix(s
[1],opP
->con1
,0);
1770 case 'b': /* Danger: These do no check for
1771 certain types of overflow.
1774 opP
->error
="out of range";
1776 if(isvar(opP
->con1
))
1777 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1781 opP
->error
="out of range";
1783 if(isvar(opP
->con1
))
1784 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1787 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
1789 if(isvar(opP
->con1
))
1790 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1796 install_operand(s
[1],tmpreg
);
1799 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
1807 install_operand(s
[1],opP
->reg
-ADDR
);
1811 tmpreg
=get_num(opP
->con1
,80);
1814 /* Needs no offsetting */
1815 add_fix('B',opP
->con1
,1);
1818 /* Offset the displacement to be relative to byte disp location */
1819 opP
->con1
->e_exp
.X_add_number
+=2;
1820 add_fix('w',opP
->con1
,1);
1825 if (cpu_of_arch(current_architecture
) < m68020
) /* 68000 or 010 */
1826 as_warn("Can't use long branches on 68000/68010");
1827 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
1828 /* Offset the displacement to be relative to byte disp location */
1829 opP
->con1
->e_exp
.X_add_number
+=4;
1830 add_fix('l',opP
->con1
,1);
1835 if(subs(opP
->con1
)) /* We can't relax it */
1838 /* This could either be a symbol, or an
1839 absolute address. No matter, the
1840 frag hacking will finger it out.
1841 Not quite: it can't switch from
1842 BRANCH to BCC68000 for the case
1843 where opnd is absolute (it needs
1844 to use the 68000 hack since no
1845 conditional abs jumps). */
1846 if (((cpu_of_arch(current_architecture
) < m68020
) || (0==adds(opP
->con1
)))
1847 && (the_ins
.opcode
[0] >= 0x6200)
1848 && (the_ins
.opcode
[0] <= 0x6f00)) {
1849 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
1851 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BRANCH
,SZ_UNDEF
));
1855 if(isvar(opP
->con1
)) {
1856 /* check for DBcc instruction */
1857 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
1858 /* size varies if patch */
1859 /* needed for long form */
1860 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
1865 opP
->con1
->e_exp
.X_add_number
+=2;
1866 add_fix('w',opP
->con1
,1);
1870 case 'C': /* Fixed size LONG coproc branches */
1871 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1872 /* Offset the displacement to be relative to byte disp location */
1873 /* Coproc branches don't have a byte disp option, but they are
1874 compatible with the ordinary branches, which do... */
1875 opP
->con1
->e_exp
.X_add_number
+=4;
1876 add_fix('l',opP
->con1
,1);
1880 case 'c': /* Var size Coprocesssor branches */
1881 if(subs(opP
->con1
)) {
1882 add_fix('l',opP
->con1
,1);
1883 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
1884 } else if(adds(opP
->con1
)) {
1885 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
1887 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
1888 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1889 add_fix('l',opP
->con1
,1);
1895 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
1896 s
[1], __LINE__
, __FILE__
);
1900 case 'C': /* Ignore it */
1903 case 'd': /* JF this is a kludge */
1904 if(opP
->mode
==AOFF
) {
1905 install_operand('s',opP
->reg
-ADDR
);
1909 tmpP
=opP
->con1
->e_end
-2;
1911 opP
->con1
->e_end
-=4; /* point to the , */
1912 baseo
=m68k_reg_parse(&tmpP
);
1913 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
1914 as_bad("Unknown address reg, using A0");
1917 install_operand('s',baseo
);
1919 tmpreg
=get_num(opP
->con1
,80);
1920 if(!issword(tmpreg
)) {
1921 as_warn("Expression out of range, using 0");
1928 install_operand(s
[1],opP
->reg
-DATA
);
1932 install_operand(s
[1],opP
->reg
-FPREG
);
1936 tmpreg
=1+opP
->reg
-COPNUM
;
1939 install_operand(s
[1],tmpreg
);
1942 case 'J': /* JF foo */
1944 case SFC
: tmpreg
=0x000; break;
1945 case DFC
: tmpreg
=0x001; break;
1946 case CACR
: tmpreg
=0x002; break;
1947 case TC
: tmpreg
=0x003; break;
1948 case ITT0
: tmpreg
=0x004; break;
1949 case ITT1
: tmpreg
=0x005; break;
1950 case DTT0
: tmpreg
=0x006; break;
1951 case DTT1
: tmpreg
=0x007; break;
1953 case USP
: tmpreg
=0x800; break;
1954 case VBR
: tmpreg
=0x801; break;
1955 case CAAR
: tmpreg
=0x802; break;
1956 case MSP
: tmpreg
=0x803; break;
1957 case ISP
: tmpreg
=0x804; break;
1958 case MMUSR
: tmpreg
=0x805; break;
1959 case URP
: tmpreg
=0x806; break;
1960 case SRP
: tmpreg
=0x807; break;
1962 as_fatal("failed sanity check.");
1964 install_operand(s
[1],tmpreg
);
1968 tmpreg
=get_num(opP
->con1
,55);
1969 install_operand(s
[1],tmpreg
&0x7f);
1975 if(tmpreg
&0x7FF0000)
1976 as_bad("Floating point register in register list");
1977 insop(reverse_16_bits(tmpreg
));
1979 if(tmpreg
&0x700FFFF)
1980 as_bad("Wrong register in floating-point reglist");
1981 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
1988 if(tmpreg
&0x7FF0000)
1989 as_bad("Floating point register in register list");
1991 } else if(s
[1]=='8') {
1992 if(tmpreg
&0x0FFFFFF)
1993 as_bad("incorrect register in reglist");
1994 install_operand(s
[1],tmpreg
>>24);
1996 if(tmpreg
&0x700FFFF)
1997 as_bad("wrong register in floating-point reglist");
1999 install_operand(s
[1],tmpreg
>>16);
2004 install_operand(s
[1],get_num(opP
->con1
,60));
2008 tmpreg
= (opP
->mode
==DREG
)
2009 ? 0x20+opP
->reg
-DATA
2010 : (get_num(opP
->con1
,40)&0x1F);
2011 install_operand(s
[1],tmpreg
);
2015 tmpreg
=get_num(opP
->con1
,10);
2018 install_operand(s
[1],tmpreg
);
2022 /* This depends on the fact that ADDR registers are
2023 eight more than their corresponding DATA regs, so
2024 the result will have the ADDR_REG bit set */
2025 install_operand(s
[1],opP
->reg
-DATA
);
2029 if(opP
->reg
==FPI
) tmpreg
=0x1;
2030 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2031 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2032 else as_fatal("failed sanity check.");
2033 install_operand(s
[1],tmpreg
);
2036 case 'S': /* Ignore it */
2040 install_operand(s
[1],get_num(opP
->con1
,30));
2043 case 'U': /* Ignore it */
2048 case NC
: tmpreg
= 0; break;
2049 case DC
: tmpreg
= 1; break;
2050 case IC
: tmpreg
= 2; break;
2051 case BC
: tmpreg
= 3; break;
2053 as_fatal("failed sanity check");
2054 } /* switch on cache token */
2055 install_operand(s
[1], tmpreg
);
2058 /* JF: These are out of order, I fear. */
2068 as_fatal("failed sanity check.");
2070 install_operand(s
[1],tmpreg
);
2091 as_fatal("failed sanity check.");
2093 install_operand(s
[1],tmpreg
);
2097 if (opP
->reg
== VAL
)
2099 as_fatal("failed sanity check.");
2114 as_fatal("failed sanity check.");
2116 install_operand(s
[1],tmpreg
);
2121 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2122 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2123 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2126 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2127 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2128 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2132 as_fatal("failed sanity check.");
2134 install_operand(s
[1], tmpreg
);
2137 know(opP
->reg
== PSR
);
2140 know(opP
->reg
== PCSR
);
2144 tmpreg
=get_num(opP
->con1
,80);
2145 install_operand(s
[1], tmpreg
);
2148 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s
[0], __LINE__
, __FILE__
);
2151 /* By the time whe get here (FINALLY) the_ins contains the complete
2152 instruction, ready to be emitted. . . */
2156 * get_regs := '/' + ?
2157 * | '-' + <register>
2158 * | '-' + <register> + ?
2163 * The idea here must be to scan in a set of registers but I don't
2164 * understand it. Looks awfully sloppy to me but I don't have any doc on
2171 static int get_regs(i
,str
,opP
)
2173 struct m68k_op
*opP
;
2176 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2177 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2178 unsigned long cur_regs
= 0;
2182 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2183 else if(x==FPS) cur_regs|=(1<<25);\
2184 else if(x==FPC) cur_regs|=(1<<26);\
2185 else cur_regs|=(1<<(x-1)); }
2192 } else if(*str
=='-') {
2194 reg2
=m68k_reg_parse(&str
);
2195 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2196 opP
->error
="unknown register in register list";
2205 } else if(*str
=='\0') {
2209 opP
->error
="unknow character in register list";
2212 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2215 reg1
=m68k_reg_parse(&str
);
2216 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2217 opP
->error
="unknown register in register list";
2225 static int reverse_16_bits(in
)
2231 static int mask
[16] = {
2232 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2233 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2240 } /* reverse_16_bits() */
2242 static int reverse_8_bits(in
)
2248 static int mask
[8] = {
2249 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2257 } /* reverse_8_bits() */
2259 static void install_operand(mode
,val
)
2265 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2268 the_ins
.opcode
[0]|=val
<<9;
2271 the_ins
.opcode
[1]|=val
<<12;
2274 the_ins
.opcode
[1]|=val
<<6;
2277 the_ins
.opcode
[1]|=val
;
2280 the_ins
.opcode
[2]|=val
<<12;
2283 the_ins
.opcode
[2]|=val
<<6;
2286 /* DANGER! This is a hack to force cas2l and cas2w cmds
2287 to be three words long! */
2289 the_ins
.opcode
[2]|=val
;
2292 the_ins
.opcode
[1]|=val
<<7;
2295 the_ins
.opcode
[1]|=val
<<10;
2299 the_ins
.opcode
[1]|=val
<<5;
2304 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2307 the_ins
.opcode
[1]|=(val
<<12)|val
;
2310 the_ins
.opcode
[0]|=val
=0xff;
2313 the_ins
.opcode
[0]|=val
<<9;
2316 the_ins
.opcode
[1]|=val
;
2319 the_ins
.opcode
[1]|=val
;
2320 the_ins
.numo
++; /* What a hack */
2323 the_ins
.opcode
[1]|=val
<<4;
2330 the_ins
.opcode
[0] |= (val
<< 6);
2333 the_ins
.opcode
[1] = (val
>> 16);
2334 the_ins
.opcode
[2] = val
& 0xffff;
2338 as_fatal("failed sanity check.");
2340 } /* install_operand() */
2342 static void install_gen_operand(mode
,val
)
2348 the_ins
.opcode
[0]|=val
;
2351 /* This is a kludge!!! */
2352 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2361 the_ins
.opcode
[0]|=val
;
2363 /* more stuff goes here */
2365 as_fatal("failed sanity check.");
2367 } /* install_gen_operand() */
2370 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2371 * then deal with the bitfield hack.
2374 static char *crack_operand(str
,opP
)
2376 register struct m68k_op
*opP
;
2378 register int parens
;
2380 register char *beg_str
;
2386 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2387 if(*str
=='(') parens
++;
2388 else if(*str
==')') {
2389 if(!parens
) { /* ERROR */
2390 opP
->error
="Extra )";
2396 if(!*str
&& parens
) { /* ERROR */
2397 opP
->error
="Missing )";
2402 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2408 c
= *++str
; /* JF bitfield hack */
2412 as_bad("Missing operand");
2417 /* See the comment up above where the #define notend(... is */
2422 if(*s
==',') return 0;
2423 if(*s
=='{' || *s
=='}')
2425 if(*s
!=':') return 1;
2426 /* This kludge here is for the division cmd, which is a kludge */
2427 if(index("aAdD#",s
[1])) return 0;
2432 /* This is the guts of the machine-dependent assembler. STR points to a
2433 machine dependent instruction. This function is supposed to emit
2434 the frags/bytes it assembles to.
2438 insert_reg(regname
, regnum
)
2444 symbol_table_insert(symbol_new(regname
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2446 for (i
= 0; regname
[i
]; i
++)
2447 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2450 symbol_table_insert(symbol_new(buf
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2567 for (i
= 0; init_table
[i
].name
; i
++)
2569 insert_reg(init_table
[i
].name
, init_table
[i
].number
);
2583 int shorts_this_frag
;
2586 if (current_architecture
== 0)
2587 current_architecture
= (m68020
2595 /* If only float and mmu were specified, default cpu. */
2596 else if (cpu_of_arch (current_architecture
) == 0)
2597 current_architecture
|= m68020
;
2599 memset((char *)(&the_ins
), '\0', sizeof(the_ins
)); /* JF for paranoia sake */
2603 for(n
=the_ins
.numargs
;n
;--n
)
2604 if(the_ins
.operands
[n
].error
) {
2605 er
=the_ins
.operands
[n
].error
;
2610 as_bad("%s -- statement `%s' ignored",er
,str
);
2614 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
2615 toP
=frag_more(2*the_ins
.numo
);
2616 fromP
= &the_ins
.opcode
[0];
2617 for(m
=the_ins
.numo
;m
;--m
) {
2618 md_number_to_chars(toP
,(long)(*fromP
),2);
2622 /* put out symbol-dependent info */
2623 for(m
=0;m
<the_ins
.nrel
;m
++) {
2624 switch(the_ins
.reloc
[m
].wid
) {
2641 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
2645 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2647 the_ins
.reloc
[m
].add
,
2648 the_ins
.reloc
[m
].sub
,
2649 the_ins
.reloc
[m
].off
,
2650 the_ins
.reloc
[m
].pcrel
,
2656 /* There's some frag hacking */
2657 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
2660 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
2661 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2665 for(m
=wid
/2;m
;--m
) {
2666 md_number_to_chars(toP
,(long)(*fromP
),2);
2671 for(m
=0;m
<the_ins
.nrel
;m
++) {
2672 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
2673 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
2676 wid
=the_ins
.reloc
[m
].wid
;
2679 the_ins
.reloc
[m
].wid
=0;
2680 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2683 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2685 the_ins
.reloc
[m
].add
,
2686 the_ins
.reloc
[m
].sub
,
2687 the_ins
.reloc
[m
].off
,
2688 the_ins
.reloc
[m
].pcrel
,
2691 /* know(the_ins.fragb[n].fadd); */
2692 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
2693 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
2695 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2698 toP
=frag_more(n
*sizeof(short));
2700 md_number_to_chars(toP
,(long)(*fromP
),2);
2706 for(m
=0;m
<the_ins
.nrel
;m
++) {
2709 wid
=the_ins
.reloc
[m
].wid
;
2712 the_ins
.reloc
[m
].wid
=0;
2713 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2716 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
2718 the_ins
.reloc
[m
].add
,
2719 the_ins
.reloc
[m
].sub
,
2720 the_ins
.reloc
[m
].off
,
2721 the_ins
.reloc
[m
].pcrel
,
2734 * md_begin -- set up hash tables with 68000 instructions.
2735 * similar to what the vax assembler does. ---phr
2737 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2738 a copy of it at runtime, adding in the information we want but isn't
2739 there. I think it'd be better to have an awk script hack the table
2740 at compile time. Or even just xstr the table and use it as-is. But
2741 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2744 register const struct m68k_opcode
*ins
;
2745 register struct m68k_incant
*hack
,
2747 register char *retval
= 0; /* empty string, or error msg text */
2748 register unsigned int i
;
2751 if ((op_hash
= hash_new()) == NULL
)
2752 as_fatal("Virtual memory exhausted");
2754 obstack_begin(&robyn
,4000);
2755 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
2756 hack
=slak
=(struct m68k_incant
*)obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2758 /* we *could* ignore insns that don't match our
2759 arch here but just leaving them out of the
2761 slak
->m_operands
=ins
->args
;
2762 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
2763 slak
->m_arch
= ins
->arch
;
2764 slak
->m_opcode
=ins
->opcode
;
2765 /* This is kludgey */
2766 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
2767 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
2768 slak
->m_next
=(struct m68k_incant
*) obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2775 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
2776 /* Didn't his mommy tell him about null pointers? */
2777 if(retval
&& *retval
)
2778 as_fatal("Internal Error: Can't hash %s: %s",ins
->name
,retval
);
2781 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
2782 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
2784 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
2785 notend_table
[i
] = 0;
2786 alt_notend_table
[i
] = 0;
2788 notend_table
[','] = 1;
2789 notend_table
['{'] = 1;
2790 notend_table
['}'] = 1;
2791 alt_notend_table
['a'] = 1;
2792 alt_notend_table
['A'] = 1;
2793 alt_notend_table
['d'] = 1;
2794 alt_notend_table
['D'] = 1;
2795 alt_notend_table
['#'] = 1;
2796 alt_notend_table
['f'] = 1;
2797 alt_notend_table
['F'] = 1;
2798 #ifdef REGISTER_PREFIX
2799 alt_notend_table
[REGISTER_PREFIX
] = 1;
2806 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2807 || (*s == ':' && strchr("aAdD#", s[1]))) \
2811 /* This funciton is called once, before the assembler exits. It is
2812 supposed to do any final cleanup for this part of the assembler.
2819 /* Equal to MAX_PRECISION in atof-ieee.c */
2820 #define MAX_LITTLENUMS 6
2822 /* Turn a string in input_line_pointer into a floating point constant of type
2823 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2824 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2827 md_atof(type
,litP
,sizeP
)
2833 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2834 LITTLENUM_TYPE
*wordP
;
2865 return "Bad call to MD_ATOF()";
2867 t
=atof_ieee(input_line_pointer
,type
,words
);
2869 input_line_pointer
=t
;
2871 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
2872 for(wordP
=words
;prec
--;) {
2873 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
2874 litP
+=sizeof(LITTLENUM_TYPE
);
2876 return ""; /* Someone should teach Dean about null pointers */
2879 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2880 for use in the a.out file, and stores them in the array pointed to by buf.
2881 This knows about the endian-ness of the target machine and does
2882 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2883 2 (short) and 4 (long) Floating numbers are put out as a series of
2884 LITTLENUMS (shorts, here at least)
2887 md_number_to_chars(buf
,val
,n
)
2907 as_fatal("failed sanity check.");
2912 md_apply_fix(fixP
, val
)
2916 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2918 switch(fixP
->fx_size
) {
2933 BAD_CASE (fixP
->fx_size
);
2938 /* *fragP has been relaxed to its final size, and now needs to have
2939 the bytes inside it modified to conform to the new size There is UGLY
2943 md_convert_frag(headers
, fragP
)
2944 object_headers
*headers
;
2945 register fragS
*fragP
;
2950 /* Address in object code of the displacement. */
2951 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
2953 #ifdef IBM_COMPILER_SUX
2954 /* This is wrong but it convinces the native rs6000 compiler to
2955 generate the code we want. */
2956 register char *buffer_address
= fragP
-> fr_literal
;
2957 buffer_address
+= fragP
-> fr_fix
;
2958 #else /* IBM_COMPILER_SUX */
2959 /* Address in gas core of the place to store the displacement. */
2960 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2961 #endif /* IBM_COMPILER_SUX */
2963 /* No longer true: know(fragP->fr_symbol); */
2965 /* The displacement of the address, from current location. */
2966 disp
= fragP
->fr_symbol
? S_GET_VALUE(fragP
->fr_symbol
) : 0;
2967 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
2969 switch(fragP
->fr_subtype
) {
2970 case TAB(BCC68000
,BYTE
):
2971 case TAB(BRANCH
,BYTE
):
2972 know(issbyte(disp
));
2974 as_bad("short branch with zero offset: use :w");
2975 fragP
->fr_opcode
[1]=disp
;
2978 case TAB(DBCC
,SHORT
):
2979 know(issword(disp
));
2982 case TAB(BCC68000
,SHORT
):
2983 case TAB(BRANCH
,SHORT
):
2984 know(issword(disp
));
2985 fragP
->fr_opcode
[1]=0x00;
2988 case TAB(BRANCH
,LONG
):
2989 if (cpu_of_arch(current_architecture
) < m68020
) {
2990 if (fragP
->fr_opcode
[0]==0x61) {
2991 fragP
->fr_opcode
[0]= 0x4E;
2992 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
2993 subseg_change(SEG_TEXT
, 0);
3006 } else if (fragP
->fr_opcode
[0]==0x60) {
3007 fragP
->fr_opcode
[0]= 0x4E;
3008 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3009 subseg_change(SEG_TEXT
, 0);
3010 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
3015 as_bad("Long branch offset not supported.");
3018 fragP
->fr_opcode
[1]=0xff;
3022 case TAB(BCC68000
,LONG
):
3023 /* only Bcc 68000 instructions can come here */
3024 /* change bcc into b!cc/jmp absl long */
3025 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3026 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
3028 /* JF: these used to be fr_opcode[2,3], but they may be in a
3029 different frag, in which case refering to them is a no-no.
3030 Only fr_opcode[0,1] are guaranteed to work. */
3031 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3032 *buffer_address
++ = 0xf9;
3033 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3034 subseg_change(SEG_TEXT
,0);
3035 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3041 case TAB(DBCC
,LONG
):
3042 /* only DBcc 68000 instructions can come here */
3043 /* change dbcc into dbcc/jmp absl long */
3044 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3045 *buffer_address
++ = 0x00; /* branch offset = 4 */
3046 *buffer_address
++ = 0x04;
3047 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3048 *buffer_address
++ = 0x06;
3049 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3050 *buffer_address
++ = 0xf9;
3052 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3053 subseg_change(SEG_TEXT
,0);
3054 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3060 case TAB(FBRANCH
,SHORT
):
3061 know((fragP
->fr_opcode
[1]&0x40)==0);
3064 case TAB(FBRANCH
,LONG
):
3065 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
3068 case TAB(PCREL
,SHORT
):
3071 case TAB(PCREL
,LONG
):
3072 /* The thing to do here is force it to ABSOLUTE LONG, since
3073 PCREL is really trying to shorten an ABSOLUTE address anyway */
3074 /* JF FOO This code has not been tested */
3075 subseg_change(SEG_TEXT
,0);
3076 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3077 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3078 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3079 fragP
->fr_opcode
[0],fragP
->fr_address
);
3080 fragP
->fr_opcode
[1]&= ~0x3F;
3081 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
3083 /* md_number_to_chars(buffer_address,
3084 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3088 case TAB(PCLEA
,SHORT
):
3089 subseg_change(SEG_TEXT
,0);
3090 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
3092 fragP
->fr_opcode
[1] &= ~0x3F;
3093 fragP
->fr_opcode
[1] |= 0x3A;
3096 case TAB(PCLEA
,LONG
):
3097 subseg_change(SEG_TEXT
,0);
3098 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
3100 *buffer_address
++ = 0x01;
3101 *buffer_address
++ = 0x70;
3103 /* buffer_address+=2; */
3107 } /* switch on subtype */
3110 md_number_to_chars(buffer_address
, (long) disp
, (int) ext
);
3111 fragP
->fr_fix
+= ext
;
3112 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3113 } /* if extending */
3116 } /* md_convert_frag() */
3118 /* Force truly undefined symbols to their maximum size, and generally set up
3119 the frag list to be relaxed
3121 int md_estimate_size_before_relax(fragP
, segment
)
3122 register fragS
*fragP
;
3126 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3128 old_fix
= fragP
->fr_fix
;
3130 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3131 switch (fragP
->fr_subtype
) {
3133 case TAB(BRANCH
,SZ_UNDEF
): {
3134 if((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3135 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3136 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
3138 } else if((fragP
->fr_symbol
== 0) || (cpu_of_arch(current_architecture
) < m68020
)) {
3139 /* On 68000, or for absolute value, switch to abs long */
3140 /* FIXME, we should check abs val, pick short or long */
3141 if(fragP
->fr_opcode
[0]==0x61) {
3142 fragP
->fr_opcode
[0]= 0x4E;
3143 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3144 subseg_change(SEG_TEXT
, 0);
3145 fix_new(fragP
, fragP
->fr_fix
, 4,
3146 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3149 } else if(fragP
->fr_opcode
[0]==0x60) {
3150 fragP
->fr_opcode
[0]= 0x4E;
3151 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3152 subseg_change(SEG_TEXT
, 0);
3153 fix_new(fragP
, fragP
->fr_fix
, 4,
3154 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3158 as_warn("Long branch offset to extern symbol not supported.");
3160 } else { /* Symbol is still undefined. Make it simple */
3161 fix_new(fragP
, (int)(fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3162 (symbolS
*)0, fragP
->fr_offset
+4, 1, NO_RELOC
);
3164 fragP
->fr_opcode
[1]=0xff;
3170 } /* case TAB(BRANCH,SZ_UNDEF) */
3172 case TAB(FBRANCH
,SZ_UNDEF
): {
3173 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3174 fragP
->fr_subtype
= TAB(FBRANCH
,SHORT
);
3177 fragP
->fr_subtype
= TAB(FBRANCH
,LONG
);
3181 } /* TAB(FBRANCH,SZ_UNDEF) */
3183 case TAB(PCREL
,SZ_UNDEF
): {
3184 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3185 fragP
->fr_subtype
= TAB(PCREL
,SHORT
);
3188 fragP
->fr_subtype
= TAB(PCREL
,LONG
);
3192 } /* TAB(PCREL,SZ_UNDEF) */
3194 case TAB(BCC68000
,SZ_UNDEF
): {
3195 if((fragP
->fr_symbol
!= NULL
)
3196 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3197 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
3200 /* only Bcc 68000 instructions can come here */
3201 /* change bcc into b!cc/jmp absl long */
3202 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3204 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3205 /* JF: these were fr_opcode[2,3] */
3206 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3207 buffer_address
[1] = 0xf8;
3208 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3209 subseg_change(SEG_TEXT
,0);
3210 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3211 fragP
->fr_offset
, 0, NO_RELOC
);
3214 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3215 /* JF: these were fr_opcode[2,3] */
3216 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3217 buffer_address
[1] = 0xf9;
3218 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3219 subseg_change(SEG_TEXT
,0);
3220 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3221 fragP
->fr_offset
, 0, NO_RELOC
);
3226 } /* case TAB(BCC68000,SZ_UNDEF) */
3228 case TAB(DBCC
,SZ_UNDEF
): {
3229 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3230 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3234 /* only DBcc 68000 instructions can come here */
3235 /* change dbcc into dbcc/jmp absl long */
3236 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3237 buffer_address
[0] = 0x00; /* branch offset = 4 */
3238 buffer_address
[1] = 0x04;
3239 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3242 /* JF: these were fr_opcode[5-7] */
3243 buffer_address
[3] = 0x04; /* plus 4 */
3244 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3245 buffer_address
[5] = 0xf8;
3246 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3247 subseg_change(SEG_TEXT
,0);
3248 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3251 fragP
->fr_offset
, 0, NO_RELOC
);
3254 /* JF: these were fr_opcode[5-7] */
3255 buffer_address
[3] = 0x06; /* Plus 6 */
3256 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3257 buffer_address
[5] = 0xf9;
3258 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3259 subseg_change(SEG_TEXT
,0);
3260 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3261 fragP
->fr_offset
, 0, NO_RELOC
);
3267 } /* case TAB(DBCC,SZ_UNDEF) */
3269 case TAB(PCLEA
,SZ_UNDEF
): {
3270 if ((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3271 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3274 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3278 } /* TAB(PCLEA,SZ_UNDEF) */
3283 } /* switch on subtype looking for SZ_UNDEF's. */
3285 /* now that SZ_UNDEF are taken care of, check others */
3286 switch (fragP
->fr_subtype
) {
3287 case TAB(BCC68000
,BYTE
):
3288 case TAB(BRANCH
,BYTE
):
3289 /* We can't do a short jump to the next instruction,
3290 so we force word mode. */
3291 if (fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3292 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3293 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3300 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3303 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3304 /* the bit-field entries in the relocation_info struct plays hell
3305 with the byte-order problems of cross-assembly. So as a hack,
3306 I added this mach. dependent ri twiddler. Ugly, but it gets
3308 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3309 are symbolnum, most sig. byte first. Last byte is broken up with
3310 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3311 nibble as nuthin. (on Sun 3 at least) */
3312 /* Translate the internal relocation information into target-specific
3316 md_ri_to_chars(the_bytes
, ri
)
3318 struct reloc_info_generic
*ri
;
3321 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3322 /* now the fun stuff */
3323 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3324 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3325 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3326 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3327 ((ri
->r_extern
<< 4) & 0x10));
3329 #endif /* comment */
3331 void tc_aout_fix_to_chars(where
, fixP
, segment_address_in_file
)
3334 relax_addressT segment_address_in_file
;
3337 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3338 * Out: GNU LD relocation length code: 0, 1, or 2.
3341 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
3344 know(fixP
->fx_addsy
!= NULL
);
3346 md_number_to_chars(where
,
3347 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3350 r_symbolnum
= (S_IS_DEFINED(fixP
->fx_addsy
)
3351 ? S_GET_TYPE(fixP
->fx_addsy
)
3352 : fixP
->fx_addsy
->sy_number
);
3354 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3355 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3356 where
[6] = r_symbolnum
& 0x0ff;
3357 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3358 (((!S_IS_DEFINED(fixP
->fx_addsy
)) << 4) & 0x10));
3361 } /* tc_aout_fix_to_chars() */
3363 #endif /* OBJ_AOUT or OBJ_BOUT */
3365 #ifndef WORKING_DOT_WORD
3366 const int md_short_jump_size
= 4;
3367 const int md_long_jump_size
= 6;
3370 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3379 offset
= to_addr
- (from_addr
+2);
3381 md_number_to_chars(ptr
,(long)0x6000,2);
3382 md_number_to_chars(ptr
+2,(long)offset
,2);
3386 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3395 if (cpu_of_arch(current_architecture
) < m68020
) {
3396 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3397 md_number_to_chars(ptr
,(long)0x4EF9,2);
3398 md_number_to_chars(ptr
+2,(long)offset
,4);
3399 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3402 offset
=to_addr
- (from_addr
+2);
3403 md_number_to_chars(ptr
,(long)0x60ff,2);
3404 md_number_to_chars(ptr
+2,(long)offset
,4);
3409 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3412 10: Absolute 1:8 only
3413 20: Absolute 0:7 only
3414 30: absolute 0:15 only
3415 40: Absolute 0:31 only
3416 50: absolute 0:127 only
3417 55: absolute -64:63 only
3418 60: absolute -128:127 only
3419 70: absolute 0:4095 only
3424 static int get_num(exp
,ok
)
3425 struct m68k_exp
*exp
;
3433 if(*exp
->e_beg
=='0') {
3434 if(exp
->e_beg
[1]=='x')
3435 sscanf(exp
->e_beg
+2,"%x",&l
);
3437 sscanf(exp
->e_beg
+1,"%O",&l
);
3440 return atol(exp
->e_beg
);
3446 /* Can't do anything */
3449 if(!exp
->e_beg
|| !exp
->e_end
) {
3450 seg(exp
)=SEG_ABSOLUTE
;
3453 offs(exp
)= (ok
==10) ? 1 : 0;
3454 as_warn("Null expression defaults to %ld",offs(exp
));
3459 if(/* ok!=80 && */exp
->e_end
[-1]==':' && (exp
->e_end
-exp
->e_beg
)>=2) {
3460 switch(exp
->e_end
[0]) {
3476 as_bad("Unknown size for expression \"%c\"",exp
->e_end
[0]);
3480 c_save
=exp
->e_end
[1];
3482 save_in
=input_line_pointer
;
3483 input_line_pointer
=exp
->e_beg
;
3484 switch(expression(&(exp
->e_exp
))) {
3486 seg(exp
)=SEG_ABSOLUTE
;
3489 offs(exp
)= (ok
==10) ? 1 : 0;
3490 as_warn("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
3494 /* Do the same thing the VAX asm does */
3495 seg(exp
)=SEG_ABSOLUTE
;
3500 as_warn("expression out of range: defaulting to 1");
3507 if(offs(exp
)<1 || offs(exp
)>8) {
3508 as_warn("expression out of range: defaulting to 1");
3513 if(offs(exp
)<0 || offs(exp
)>7)
3517 if(offs(exp
)<0 || offs(exp
)>15)
3521 if(offs(exp
)<0 || offs(exp
)>32)
3525 if(offs(exp
)<0 || offs(exp
)>127)
3529 if(offs(exp
)<-64 || offs(exp
)>63)
3533 if(offs(exp
)<-128 || offs(exp
)>127)
3537 if(offs(exp
)<0 || offs(exp
)>4095) {
3539 as_warn("expression out of range: defaulting to 0");
3551 case SEG_DIFFERENCE
:
3552 if(ok
>=10 && ok
<=70) {
3553 seg(exp
)=SEG_ABSOLUTE
;
3556 offs(exp
)= (ok
==10) ? 1 : 0;
3557 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3561 if(ok
==80 && offs(exp
)<0) { /* HACK! Turn it into a long */
3562 LITTLENUM_TYPE words
[6];
3564 gen_to_words(words
,2,8L);/* These numbers are magic! */
3565 seg(exp
)=SEG_ABSOLUTE
;
3568 offs(exp
)=words
[1]|(words
[0]<<16);
3570 seg(exp
)=SEG_ABSOLUTE
;
3573 offs(exp
)= (ok
==10) ? 1 : 0;
3574 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3578 as_fatal("failed sanity check.");
3580 if(input_line_pointer
!=exp
->e_end
+1)
3581 as_bad("Ignoring junk after expression");
3582 exp
->e_end
[1]=c_save
;
3583 input_line_pointer
=save_in
;
3585 switch(exp
->e_siz
) {
3587 if(!isbyte(offs(exp
)))
3588 as_warn("expression doesn't fit in BYTE");
3591 if(!isword(offs(exp
)))
3592 as_warn("expression doesn't fit in WORD");
3600 /* These are the back-ends for the various machine dependent pseudo-ops. */
3601 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
3603 static void s_data1() {
3604 subseg_new(SEG_DATA
,1);
3605 demand_empty_rest_of_line();
3608 static void s_data2() {
3609 subseg_new(SEG_DATA
,2);
3610 demand_empty_rest_of_line();
3615 /* We don't support putting frags in the BSS segment, we fake it
3616 by marking in_bss, then looking at s_skip for clues */
3618 subseg_new(SEG_BSS
, 0);
3619 demand_empty_rest_of_line();
3622 static void s_even() {
3624 register long temp_fill
;
3626 temp
= 1; /* JF should be 2? */
3627 temp_fill
= get_absolute_expression ();
3628 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
3629 frag_align (temp
, (int)temp_fill
);
3630 demand_empty_rest_of_line();
3633 static void s_proc() {
3634 demand_empty_rest_of_line();
3637 /* s_space is defined in read.c .skip is simply an alias to it. */
3641 * Invocation line includes a switch not recognized by the base assembler.
3642 * See if it's a processor-specific option. These are:
3644 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3645 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3646 * Select the architecture. Instructions or features not
3647 * supported by the selected architecture cause fatal
3648 * errors. More than one may be specified. The default is
3649 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3650 * for -m68000, and -m68882 is a synonym for -m68881.
3652 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
3653 * (e.g. m68020) also requests that float instructions be included. This
3654 * is the default setup, mostly to avoid hassling users. A better
3655 * rearrangement of this structure would be to add an option to DENY
3656 * floating point opcodes, for people who want to really know there's none
3657 * of that funny floaty stuff going on. FIXME-later.
3659 #ifndef MAYBE_FLOAT_TOO
3660 #define MAYBE_FLOAT_TOO m68881
3663 int md_parse_option(argP
,cntP
,vecP
)
3669 case 'l': /* -l means keep external to 2 bit offset
3670 rather than 16 bit one */
3673 case 'S': /* -S means that jbsr's always turn into jsr's. */
3678 /* intentional fall-through */
3684 } /* allow an optional "c" */
3686 if (!strcmp(*argP
, "68000")
3687 || !strcmp(*argP
, "68008")) {
3688 current_architecture
|= m68000
;
3689 } else if (!strcmp(*argP
, "68010")) {
3691 omagic
= 1<<16|OMAGIC
;
3693 current_architecture
|= m68010
;
3695 } else if (!strcmp(*argP
, "68020")) {
3696 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
3698 } else if (!strcmp(*argP
, "68030")) {
3699 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
3701 } else if (!strcmp(*argP
, "68040")) {
3702 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
3705 } else if (!strcmp(*argP
, "68881")) {
3706 current_architecture
|= m68881
;
3708 } else if (!strcmp(*argP
, "68882")) {
3709 current_architecture
|= m68882
;
3711 #endif /* NO_68881 */
3713 } else if (!strcmp(*argP
,"68851")) {
3714 current_architecture
|= m68851
;
3716 #endif /* NO_68851 */
3718 as_warn("Unknown architecture, \"%s\". option ignored", *argP
);
3719 } /* switch on architecture */
3721 while(**argP
) (*argP
)++;
3726 if (!strcmp(*argP
,"pic")) {
3728 break; /* -pic, Position Independent Code */
3742 /* TEST2: Test md_assemble() */
3743 /* Warning, this routine probably doesn't work anymore */
3747 struct m68k_it the_ins
;
3754 if(!gets(buf
) || !*buf
)
3756 if(buf
[0]=='|' || buf
[1]=='.')
3758 for(cp
=buf
;*cp
;cp
++)
3763 memset(&the_ins
, '\0', sizeof(the_ins
));
3764 m68k_ip(&the_ins
,buf
);
3766 printf("Error %s in %s\n",the_ins
.error
,buf
);
3768 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
3769 for(n
=0;n
<the_ins
.numo
;n
++)
3770 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
3772 print_the_insn(&the_ins
.opcode
[0],stdout
);
3773 (void)putchar('\n');
3775 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
3776 if(the_ins
.operands
[n
].error
) {
3777 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
3780 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
3781 if(the_ins
.operands
[n
].b_const
)
3782 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
3783 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
3784 if(the_ins
.operands
[n
].b_iadd
)
3785 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
3786 (void)putchar('\n');
3798 while(*str
&& *str
!=' ')
3800 if(str
[-1]==':' || str
[1]=='=')
3807 /* Possible states for relaxation:
3809 0 0 branch offset byte (bra, etc)
3813 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3817 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3836 extern fragS
*text_frag_root
;
3838 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
3839 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3840 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
3841 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
3853 fputs("Internal error:",stderr
);
3854 _doprnt(format
,&args
,stderr
);
3855 (void)putc('\n',stderr
);
3861 /* We have no need to default values of symbols. */
3865 md_undefined_symbol (name
)
3871 /* Parse an operand that is machine-specific.
3872 We just return without modifying the expression if we have nothing
3877 md_operand (expressionP
)
3878 expressionS
*expressionP
;
3882 /* Round up a section size to the appropriate boundary. */
3884 md_section_align (segment
, size
)
3888 return size
; /* Byte alignment is fine */
3891 /* Exactly what point is a PC-relative offset relative TO?
3892 On the 68k, they're relative to the address of the offset, plus
3893 its size. (??? Is this right? FIXME-SOON!) */
3895 md_pcrel_from (fixP
)
3898 return(fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
3908 /* end of tc-m68k.c */