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";
895 if (cpu_of_arch(current_architecture
) < m68020
) {
896 opP
->error
="no index scaling in pre-68020's";
903 opP
->error
="index multiplier not 1, 2, 4 or 8";
910 opP
->error
="Missing )";
919 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
923 struct m68k_op thark
;
928 memset(&thark
, '\0', sizeof(thark
));
929 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
931 printf("op1 error %s in %s\n",thark
.error
,buf
);
932 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
934 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
935 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
937 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
946 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
947 NULL means any use before m68k_ip_begin()
954 * This converts a string into a 68k instruction.
955 * The string must be a bare single instruction in sun format
956 * with RMS-style 68020 indirects
959 * It provides some error messages: at most one fatal error message (which
960 * stops the scan) and at most one warning message for each operand.
961 * The 68k instruction is returned in exploded form, since we have no
962 * knowledge of how you parse (or evaluate) your expressions.
963 * We do however strip off and decode addressing modes and operation
966 * This function's value is a string. If it is not "" then an internal
967 * logic error was found: read this code to assign meaning to the string.
968 * No argument string should generate such an error string:
969 * it means a bug in our code, not in the user's text.
971 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
975 /* JF this function no longer returns a useful value. Sorry */
976 void m68k_ip (instring
)
980 register struct m68k_op
*opP
;
981 register struct m68k_incant
*opcode
;
983 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
988 char *crack_operand();
989 LITTLENUM_TYPE words
[6];
990 LITTLENUM_TYPE
*wordp
;
992 if (*instring
== ' ')
993 instring
++; /* skip leading whitespace */
995 /* Scan up to end of operation-code, which MUST end in end-of-string
996 or exactly 1 space. */
997 for (p
= instring
; *p
!= '\0'; p
++)
1002 if (p
== instring
) {
1003 the_ins
.error
= "No operator";
1004 the_ins
.opcode
[0] = NULL
;
1005 /* the_ins.numo=1; */
1009 /* p now points to the end of the opcode name, probably whitespace.
1010 make sure the name is null terminated by clobbering the whitespace,
1011 look it up in the hash table, then fix it back. */
1014 opcode
= (struct m68k_incant
*)hash_find (op_hash
, instring
);
1017 if (opcode
== NULL
) {
1018 the_ins
.error
= "Unknown operator";
1019 the_ins
.opcode
[0] = NULL
;
1020 /* the_ins.numo=1; */
1024 /* found a legitimate opcode, start matching operands */
1025 while (*p
== ' ') ++p
;
1027 for(opP
= &the_ins
.operands
[0]; *p
; opP
++) {
1029 p
= crack_operand(p
, opP
);
1032 the_ins
.error
=opP
->error
;
1037 opsfound
= opP
- &the_ins
.operands
[0];
1039 /* This ugly hack is to support the floating pt opcodes in their standard form */
1040 /* Essentially, we fake a first enty of type COP#1 */
1041 if (opcode
->m_operands
[0]=='I') {
1044 for(n
=opsfound
;n
>0;--n
)
1045 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1047 /* memcpy((char *)(&the_ins.operands[1]), (char *)(&the_ins.operands[0]), opsfound*sizeof(the_ins.operands[0])); */
1048 memset((char *)(&the_ins
.operands
[0]), '\0', sizeof(the_ins
.operands
[0]));
1049 the_ins
.operands
[0].mode
=MSCR
;
1050 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1054 /* We've got the operands. Find an opcode that'll accept them */
1055 for (losing
= 0; ; ) {
1056 /* if we didn't get the right number of ops,
1057 or we have no common model with this pattern
1058 then reject this pattern. */
1060 if (opsfound
!= opcode
->m_opnum
1061 || ((opcode
->m_arch
& current_architecture
) == 0)) {
1066 for (s
=opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++) {
1067 /* Warning: this switch is huge! */
1068 /* I've tried to organize the cases into this order:
1069 non-alpha first, then alpha by letter. lower-case goes directly
1070 before uppercase counterpart. */
1071 /* Code with multiple case ...: gets sorted by the lowest case ...
1072 it belongs to. I hope this makes sense. */
1075 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1076 || opP
->mode
== DREG
|| opP
->mode
== AREG
1077 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1078 || opP
->mode
== REGLST
)
1083 if(opP
->mode
!=IMMED
)
1088 t
=get_num(opP
->con1
,80);
1089 if(s
[1]=='b' && !isbyte(t
))
1091 else if(s
[1]=='w' && !isword(t
))
1098 if(opP
->mode
!=IMMED
)
1103 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1104 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1109 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1110 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1116 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1117 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1118 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1123 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1138 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1139 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1144 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1149 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1150 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1151 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1156 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1157 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1161 case '~': /* For now! (JF FOO is this right?) */
1162 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1163 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1172 if (opP
->mode
!= AINDR
) {
1174 } /* if not address register indirect */
1177 if(opP
->mode
!=ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1178 && instring
[1] == 'b'
1179 && instring
[2] == 's'
1180 && instring
[3] == 'r'))
1185 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1189 case 'd': /* FOO This mode is a KLUDGE!! */
1190 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1191 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1201 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1206 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1212 if (opP
->mode
!= MSCR
1215 || cpu_of_arch(current_architecture
) < m68010
/* before 68010 had none */
1216 || (cpu_of_arch(current_architecture
) < m68020
1220 && opP
->reg
!= VBR
) /* 68010's had only these */
1221 || (cpu_of_arch(current_architecture
) < m68040
1229 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1230 || (cpu_of_arch(current_architecture
) == m68040
/* 68040 has all but this */
1231 && opP
->reg
== CAAR
)) {
1233 } /* doesn't cut it */
1237 if(opP
->mode
!=IMMED
)
1243 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1248 opP
->reg
=1<<(opP
->reg
-DATA
);
1250 } else if(opP
->mode
!=REGLST
) {
1252 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1254 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1259 if(opP
->mode
!=IMMED
)
1264 t
=get_num(opP
->con1
,80);
1265 if(!issbyte(t
) || isvar(opP
->con1
))
1271 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1276 if(opP
->mode
!=IMMED
)
1281 t
=get_num(opP
->con1
,80);
1282 if(t
<1 || t
>8 || isvar(opP
->con1
))
1288 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1293 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1298 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1303 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1307 /* JF these are out of order. We could put them
1308 in order if we were willing to put up with
1309 bunches of #ifdef m68851s in the code */
1311 /* Memory addressing mode used by pflushr */
1313 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1314 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1319 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1324 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TC
&& opP
->reg
!= CAL
&&
1325 opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1330 if (opP
->reg
!= VAL
)
1335 if (opP
->mode
!= MSCR
|| (opP
->reg
!= DRP
&& opP
->reg
!= SRP
&&
1341 if (opP
->mode
!= MSCR
||
1342 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1343 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1348 if (opP
->reg
!= PSR
)
1353 if (opP
->reg
!= PCSR
)
1361 && opP
->reg
!= BC
) {
1363 } /* not a cache specifier. */
1367 if (opP
->mode
!= ABSL
) {
1369 } /* not absolute */
1373 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1374 *s
, __LINE__
, __FILE__
);
1375 } /* switch on type of operand */
1378 } /* for each operand */
1379 } /* if immediately wrong */
1385 opcode
= opcode
->m_next
;
1388 the_ins
.error
= "instruction/operands mismatch or invalid\n instruction for this architecture";
1390 } /* Fell off the end */
1395 /* now assemble it */
1397 the_ins
.args
=opcode
->m_operands
;
1398 the_ins
.numargs
=opcode
->m_opnum
;
1399 the_ins
.numo
=opcode
->m_codenum
;
1400 the_ins
.opcode
[0]=getone(opcode
);
1401 the_ins
.opcode
[1]=gettwo(opcode
);
1403 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++) {
1404 /* This switch is a doozy.
1405 Watch the first step; its a big one! */
1423 tmpreg
=0x3c; /* 7.4 */
1424 if (strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1425 else nextword
=nextword
=get_num(opP
->con1
,0);
1426 if(isvar(opP
->con1
))
1427 add_fix(s
[1],opP
->con1
,0);
1430 if(!isbyte(nextword
))
1431 opP
->error
="operand out of range";
1436 if(!isword(nextword
))
1437 opP
->error
="operand out of range";
1442 addword(nextword
>>16);
1464 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1465 *s
, s
[1], __LINE__
, __FILE__
);
1470 /* We gotta put out some float */
1471 if(seg(opP
->con1
)!=SEG_BIG
) {
1472 int_to_gen(nextword
);
1473 gen_to_words(words
,baseo
,(long int)outro
);
1474 for(wordp
=words
;baseo
--;wordp
++)
1478 if(offs(opP
->con1
)>0) {
1479 as_warn("Bignum assumed to be binary bit-pattern");
1480 if(offs(opP
->con1
)>baseo
) {
1481 as_warn("Bignum too big for %c format; truncated",s
[1]);
1482 offs(opP
->con1
)=baseo
;
1484 baseo
-=offs(opP
->con1
);
1485 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1491 gen_to_words(words
,baseo
,(long)outro
);
1492 for (wordp
=words
;baseo
--;wordp
++)
1496 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1499 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1502 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1505 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1508 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1512 nextword
=get_num(opP
->con1
,80);
1513 /* Force into index mode. Hope this works */
1515 /* We do the first bit for 32-bit displacements,
1516 and the second bit for 16 bit ones. It is
1517 possible that we should make the default be
1518 WORD instead of LONG, but I think that'd
1519 break GCC, so we put up with a little
1520 inefficiency for the sake of working output.
1523 if( !issword(nextword
)
1524 || ( isvar(opP
->con1
)
1525 && ( ( opP
->con1
->e_siz
==0
1526 && flagseen
['l']==0)
1527 || opP
->con1
->e_siz
==3))) {
1530 tmpreg
=0x3B; /* 7.3 */
1532 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1533 if(isvar(opP
->con1
)) {
1535 add_frag(adds(opP
->con1
),
1537 TAB(PCLEA
,SZ_UNDEF
));
1541 add_fix('l',opP
->con1
,1);
1545 addword(nextword
>>16);
1548 tmpreg
=0x3A; /* 7.2 */
1550 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
1552 if(isvar(opP
->con1
)) {
1554 add_fix('w',opP
->con1
,1);
1556 add_fix('w',opP
->con1
,0);
1565 know(current_architecture
& m68020up
);
1566 /* intentional fall-through */
1569 baseo
=get_num(opP
->con1
,80);
1570 outro
=get_num(opP
->con2
,80);
1571 /* Figure out the 'addressing mode' */
1572 /* Also turn on the BASE_DISABLE bit, if needed */
1573 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1574 tmpreg
=0x3b; /* 7.3 */
1577 } else if(opP
->reg
==FAIL
) {
1579 tmpreg
=0x30; /* 6.garbage */
1580 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1582 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
1583 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
1585 /* Index register stuff */
1586 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
1587 nextword
|=(opP
->ireg
-DATA
)<<12;
1589 if(opP
->isiz
==0 || opP
->isiz
==3)
1593 case 2: nextword
|=0x200; break;
1594 case 4: nextword
|=0x400; break;
1595 case 8: nextword
|=0x600; break;
1596 default: as_fatal("failed sanity check.");
1599 GET US OUT OF HERE! */
1601 /* Must be INDEX, with an index
1602 register. Address register
1603 cannot be ZERO-PC, and either
1604 :b was forced, or we know
1606 if( opP
->mode
==AINDX
1611 && !isvar(opP
->con1
)))) {
1612 nextword
+=baseo
&0xff;
1614 if(isvar(opP
->con1
))
1615 add_fix('B',opP
->con1
,0);
1619 nextword
|=0x40; /* No index reg */
1621 /* It aint simple */
1623 /* If the guy specified a width, we assume that
1624 it is wide enough. Maybe it isn't. If so, we lose
1628 if(isvar(opP
->con1
) || !issword(baseo
)) {
1639 as_warn("Byte dispacement won't work. Defaulting to :w");
1648 /* Figure out innner displacement stuff */
1649 if(opP
->mode
!=AINDX
) {
1652 if(isvar(opP
->con2
) || !issword(outro
)) {
1663 as_warn("Byte dispacement won't work. Defaulting to :w");
1671 if(opP
->mode
==APODX
) nextword
|=0x04;
1672 else if(opP
->mode
==AMIND
) nextword
|=0x40;
1676 if(isvar(opP
->con1
)) {
1677 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1678 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
1679 opP
->con1
->e_exp
.X_add_number
+=6;
1681 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
1688 if(isvar(opP
->con2
)) {
1689 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1690 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
1691 opP
->con1
->e_exp
.X_add_number
+=6;
1693 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
1703 nextword
=get_num(opP
->con1
,80);
1704 switch(opP
->con1
->e_siz
) {
1706 as_warn("Unknown size for absolute reference");
1708 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
1709 tmpreg
=0x38; /* 7.0 */
1713 /* Don't generate pc relative code
1714 on 68010 and 68000 */
1717 && seg(opP
->con1
) == SEG_TEXT
1718 && now_seg
== SEG_TEXT
1719 && cpu_of_arch(current_architecture
) >= m68020
1721 && !strchr("~%&$?", s
[0])) {
1722 tmpreg
=0x3A; /* 7.2 */
1723 add_frag(adds(opP
->con1
),
1725 TAB(PCREL
,SZ_UNDEF
));
1728 case 3: /* Fall through into long */
1729 if(isvar(opP
->con1
))
1730 add_fix('l',opP
->con1
,0);
1732 tmpreg
=0x39; /* 7.1 mode */
1733 addword(nextword
>>16);
1738 if(isvar(opP
->con1
))
1739 add_fix('w',opP
->con1
,0);
1741 tmpreg
=0x38; /* 7.0 mode */
1748 as_bad("unknown/incorrect operand");
1751 install_gen_operand(s
[1],tmpreg
);
1756 switch(s
[1]) { /* JF: I hate floating point! */
1771 tmpreg
=get_num(opP
->con1
,tmpreg
);
1772 if(isvar(opP
->con1
))
1773 add_fix(s
[1],opP
->con1
,0);
1775 case 'b': /* Danger: These do no check for
1776 certain types of overflow.
1779 opP
->error
="out of range";
1781 if(isvar(opP
->con1
))
1782 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1786 opP
->error
="out of range";
1788 if(isvar(opP
->con1
))
1789 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1792 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
1794 if(isvar(opP
->con1
))
1795 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1801 install_operand(s
[1],tmpreg
);
1804 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
1812 install_operand(s
[1],opP
->reg
-ADDR
);
1816 tmpreg
=get_num(opP
->con1
,80);
1819 /* Needs no offsetting */
1820 add_fix('B',opP
->con1
,1);
1823 /* Offset the displacement to be relative to byte disp location */
1824 opP
->con1
->e_exp
.X_add_number
+=2;
1825 add_fix('w',opP
->con1
,1);
1830 if (cpu_of_arch(current_architecture
) < m68020
) /* 68000 or 010 */
1831 as_warn("Can't use long branches on 68000/68010");
1832 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
1833 /* Offset the displacement to be relative to byte disp location */
1834 opP
->con1
->e_exp
.X_add_number
+=4;
1835 add_fix('l',opP
->con1
,1);
1840 if(subs(opP
->con1
)) /* We can't relax it */
1843 /* This could either be a symbol, or an
1844 absolute address. No matter, the
1845 frag hacking will finger it out.
1846 Not quite: it can't switch from
1847 BRANCH to BCC68000 for the case
1848 where opnd is absolute (it needs
1849 to use the 68000 hack since no
1850 conditional abs jumps). */
1851 if (((cpu_of_arch(current_architecture
) < m68020
) || (0==adds(opP
->con1
)))
1852 && (the_ins
.opcode
[0] >= 0x6200)
1853 && (the_ins
.opcode
[0] <= 0x6f00)) {
1854 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
1856 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BRANCH
,SZ_UNDEF
));
1860 if(isvar(opP
->con1
)) {
1861 /* check for DBcc instruction */
1862 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
1863 /* size varies if patch */
1864 /* needed for long form */
1865 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
1870 opP
->con1
->e_exp
.X_add_number
+=2;
1871 add_fix('w',opP
->con1
,1);
1875 case 'C': /* Fixed size LONG coproc branches */
1876 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1877 /* Offset the displacement to be relative to byte disp location */
1878 /* Coproc branches don't have a byte disp option, but they are
1879 compatible with the ordinary branches, which do... */
1880 opP
->con1
->e_exp
.X_add_number
+=4;
1881 add_fix('l',opP
->con1
,1);
1885 case 'c': /* Var size Coprocesssor branches */
1886 if(subs(opP
->con1
)) {
1887 add_fix('l',opP
->con1
,1);
1888 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
1889 } else if(adds(opP
->con1
)) {
1890 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
1892 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
1893 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1894 add_fix('l',opP
->con1
,1);
1900 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
1901 s
[1], __LINE__
, __FILE__
);
1905 case 'C': /* Ignore it */
1908 case 'd': /* JF this is a kludge */
1909 if(opP
->mode
==AOFF
) {
1910 install_operand('s',opP
->reg
-ADDR
);
1914 tmpP
=opP
->con1
->e_end
-2;
1916 opP
->con1
->e_end
-=4; /* point to the , */
1917 baseo
=m68k_reg_parse(&tmpP
);
1918 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
1919 as_bad("Unknown address reg, using A0");
1922 install_operand('s',baseo
);
1924 tmpreg
=get_num(opP
->con1
,80);
1925 if(!issword(tmpreg
)) {
1926 as_warn("Expression out of range, using 0");
1933 install_operand(s
[1],opP
->reg
-DATA
);
1937 install_operand(s
[1],opP
->reg
-FPREG
);
1941 tmpreg
=1+opP
->reg
-COPNUM
;
1944 install_operand(s
[1],tmpreg
);
1947 case 'J': /* JF foo */
1949 case SFC
: tmpreg
=0x000; break;
1950 case DFC
: tmpreg
=0x001; break;
1951 case CACR
: tmpreg
=0x002; break;
1952 case TC
: tmpreg
=0x003; break;
1953 case ITT0
: tmpreg
=0x004; break;
1954 case ITT1
: tmpreg
=0x005; break;
1955 case DTT0
: tmpreg
=0x006; break;
1956 case DTT1
: tmpreg
=0x007; break;
1958 case USP
: tmpreg
=0x800; break;
1959 case VBR
: tmpreg
=0x801; break;
1960 case CAAR
: tmpreg
=0x802; break;
1961 case MSP
: tmpreg
=0x803; break;
1962 case ISP
: tmpreg
=0x804; break;
1963 case MMUSR
: tmpreg
=0x805; break;
1964 case URP
: tmpreg
=0x806; break;
1965 case SRP
: tmpreg
=0x807; break;
1967 as_fatal("failed sanity check.");
1969 install_operand(s
[1],tmpreg
);
1973 tmpreg
=get_num(opP
->con1
,55);
1974 install_operand(s
[1],tmpreg
&0x7f);
1980 if(tmpreg
&0x7FF0000)
1981 as_bad("Floating point register in register list");
1982 insop(reverse_16_bits(tmpreg
));
1984 if(tmpreg
&0x700FFFF)
1985 as_bad("Wrong register in floating-point reglist");
1986 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
1993 if(tmpreg
&0x7FF0000)
1994 as_bad("Floating point register in register list");
1996 } else if(s
[1]=='8') {
1997 if(tmpreg
&0x0FFFFFF)
1998 as_bad("incorrect register in reglist");
1999 install_operand(s
[1],tmpreg
>>24);
2001 if(tmpreg
&0x700FFFF)
2002 as_bad("wrong register in floating-point reglist");
2004 install_operand(s
[1],tmpreg
>>16);
2009 install_operand(s
[1],get_num(opP
->con1
,60));
2013 tmpreg
= (opP
->mode
==DREG
)
2014 ? 0x20+opP
->reg
-DATA
2015 : (get_num(opP
->con1
,40)&0x1F);
2016 install_operand(s
[1],tmpreg
);
2020 tmpreg
=get_num(opP
->con1
,10);
2023 install_operand(s
[1],tmpreg
);
2027 /* This depends on the fact that ADDR registers are
2028 eight more than their corresponding DATA regs, so
2029 the result will have the ADDR_REG bit set */
2030 install_operand(s
[1],opP
->reg
-DATA
);
2034 if(opP
->reg
==FPI
) tmpreg
=0x1;
2035 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2036 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2037 else as_fatal("failed sanity check.");
2038 install_operand(s
[1],tmpreg
);
2041 case 'S': /* Ignore it */
2045 install_operand(s
[1],get_num(opP
->con1
,30));
2048 case 'U': /* Ignore it */
2053 case NC
: tmpreg
= 0; break;
2054 case DC
: tmpreg
= 1; break;
2055 case IC
: tmpreg
= 2; break;
2056 case BC
: tmpreg
= 3; break;
2058 as_fatal("failed sanity check");
2059 } /* switch on cache token */
2060 install_operand(s
[1], tmpreg
);
2063 /* JF: These are out of order, I fear. */
2073 as_fatal("failed sanity check.");
2075 install_operand(s
[1],tmpreg
);
2096 as_fatal("failed sanity check.");
2098 install_operand(s
[1],tmpreg
);
2102 if (opP
->reg
== VAL
)
2104 as_fatal("failed sanity check.");
2119 as_fatal("failed sanity check.");
2121 install_operand(s
[1],tmpreg
);
2126 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2127 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2128 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2131 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2132 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2133 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2137 as_fatal("failed sanity check.");
2139 install_operand(s
[1], tmpreg
);
2142 know(opP
->reg
== PSR
);
2145 know(opP
->reg
== PCSR
);
2149 tmpreg
=get_num(opP
->con1
,80);
2150 install_operand(s
[1], tmpreg
);
2153 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s
[0], __LINE__
, __FILE__
);
2156 /* By the time whe get here (FINALLY) the_ins contains the complete
2157 instruction, ready to be emitted. . . */
2161 * get_regs := '/' + ?
2162 * | '-' + <register>
2163 * | '-' + <register> + ?
2168 * The idea here must be to scan in a set of registers but I don't
2169 * understand it. Looks awfully sloppy to me but I don't have any doc on
2176 static int get_regs(i
,str
,opP
)
2178 struct m68k_op
*opP
;
2181 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2182 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2183 unsigned long cur_regs
= 0;
2187 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2188 else if(x==FPS) cur_regs|=(1<<25);\
2189 else if(x==FPC) cur_regs|=(1<<26);\
2190 else cur_regs|=(1<<(x-1)); }
2197 } else if(*str
=='-') {
2199 reg2
=m68k_reg_parse(&str
);
2200 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2201 opP
->error
="unknown register in register list";
2210 } else if(*str
=='\0') {
2214 opP
->error
="unknow character in register list";
2217 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2220 reg1
=m68k_reg_parse(&str
);
2221 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2222 opP
->error
="unknown register in register list";
2230 static int reverse_16_bits(in
)
2236 static int mask
[16] = {
2237 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2238 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2245 } /* reverse_16_bits() */
2247 static int reverse_8_bits(in
)
2253 static int mask
[8] = {
2254 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2262 } /* reverse_8_bits() */
2264 static void install_operand(mode
,val
)
2270 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2273 the_ins
.opcode
[0]|=val
<<9;
2276 the_ins
.opcode
[1]|=val
<<12;
2279 the_ins
.opcode
[1]|=val
<<6;
2282 the_ins
.opcode
[1]|=val
;
2285 the_ins
.opcode
[2]|=val
<<12;
2288 the_ins
.opcode
[2]|=val
<<6;
2291 /* DANGER! This is a hack to force cas2l and cas2w cmds
2292 to be three words long! */
2294 the_ins
.opcode
[2]|=val
;
2297 the_ins
.opcode
[1]|=val
<<7;
2300 the_ins
.opcode
[1]|=val
<<10;
2304 the_ins
.opcode
[1]|=val
<<5;
2309 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2312 the_ins
.opcode
[1]|=(val
<<12)|val
;
2315 the_ins
.opcode
[0]|=val
=0xff;
2318 the_ins
.opcode
[0]|=val
<<9;
2321 the_ins
.opcode
[1]|=val
;
2324 the_ins
.opcode
[1]|=val
;
2325 the_ins
.numo
++; /* What a hack */
2328 the_ins
.opcode
[1]|=val
<<4;
2335 the_ins
.opcode
[0] |= (val
<< 6);
2338 the_ins
.opcode
[1] = (val
>> 16);
2339 the_ins
.opcode
[2] = val
& 0xffff;
2343 as_fatal("failed sanity check.");
2345 } /* install_operand() */
2347 static void install_gen_operand(mode
,val
)
2353 the_ins
.opcode
[0]|=val
;
2356 /* This is a kludge!!! */
2357 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2366 the_ins
.opcode
[0]|=val
;
2368 /* more stuff goes here */
2370 as_fatal("failed sanity check.");
2372 } /* install_gen_operand() */
2375 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2376 * then deal with the bitfield hack.
2379 static char *crack_operand(str
,opP
)
2381 register struct m68k_op
*opP
;
2383 register int parens
;
2385 register char *beg_str
;
2391 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2392 if(*str
=='(') parens
++;
2393 else if(*str
==')') {
2394 if(!parens
) { /* ERROR */
2395 opP
->error
="Extra )";
2401 if(!*str
&& parens
) { /* ERROR */
2402 opP
->error
="Missing )";
2407 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2413 c
= *++str
; /* JF bitfield hack */
2417 as_bad("Missing operand");
2422 /* See the comment up above where the #define notend(... is */
2427 if(*s
==',') return 0;
2428 if(*s
=='{' || *s
=='}')
2430 if(*s
!=':') return 1;
2431 /* This kludge here is for the division cmd, which is a kludge */
2432 if(index("aAdD#",s
[1])) return 0;
2437 /* This is the guts of the machine-dependent assembler. STR points to a
2438 machine dependent instruction. This function is supposed to emit
2439 the frags/bytes it assembles to.
2443 insert_reg(regname
, regnum
)
2449 symbol_table_insert(symbol_new(regname
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2451 for (i
= 0; regname
[i
]; i
++)
2452 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2455 symbol_table_insert(symbol_new(buf
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2572 for (i
= 0; init_table
[i
].name
; i
++)
2574 insert_reg(init_table
[i
].name
, init_table
[i
].number
);
2588 int shorts_this_frag
;
2591 if (current_architecture
== 0)
2592 current_architecture
= (m68020
2600 /* If only float and mmu were specified, default cpu. */
2601 else if (cpu_of_arch (current_architecture
) == 0)
2602 current_architecture
|= m68020
;
2604 memset((char *)(&the_ins
), '\0', sizeof(the_ins
)); /* JF for paranoia sake */
2608 for(n
=the_ins
.numargs
;n
;--n
)
2609 if(the_ins
.operands
[n
].error
) {
2610 er
=the_ins
.operands
[n
].error
;
2615 as_bad("%s -- statement `%s' ignored",er
,str
);
2619 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
2620 toP
=frag_more(2*the_ins
.numo
);
2621 fromP
= &the_ins
.opcode
[0];
2622 for(m
=the_ins
.numo
;m
;--m
) {
2623 md_number_to_chars(toP
,(long)(*fromP
),2);
2627 /* put out symbol-dependent info */
2628 for(m
=0;m
<the_ins
.nrel
;m
++) {
2629 switch(the_ins
.reloc
[m
].wid
) {
2646 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
2650 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2652 the_ins
.reloc
[m
].add
,
2653 the_ins
.reloc
[m
].sub
,
2654 the_ins
.reloc
[m
].off
,
2655 the_ins
.reloc
[m
].pcrel
,
2661 /* There's some frag hacking */
2662 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
2665 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
2666 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2670 for(m
=wid
/2;m
;--m
) {
2671 md_number_to_chars(toP
,(long)(*fromP
),2);
2676 for(m
=0;m
<the_ins
.nrel
;m
++) {
2677 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
2678 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
2681 wid
=the_ins
.reloc
[m
].wid
;
2684 the_ins
.reloc
[m
].wid
=0;
2685 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2688 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2690 the_ins
.reloc
[m
].add
,
2691 the_ins
.reloc
[m
].sub
,
2692 the_ins
.reloc
[m
].off
,
2693 the_ins
.reloc
[m
].pcrel
,
2696 /* know(the_ins.fragb[n].fadd); */
2697 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
2698 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
2700 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2703 toP
=frag_more(n
*sizeof(short));
2705 md_number_to_chars(toP
,(long)(*fromP
),2);
2711 for(m
=0;m
<the_ins
.nrel
;m
++) {
2714 wid
=the_ins
.reloc
[m
].wid
;
2717 the_ins
.reloc
[m
].wid
=0;
2718 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2721 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
2723 the_ins
.reloc
[m
].add
,
2724 the_ins
.reloc
[m
].sub
,
2725 the_ins
.reloc
[m
].off
,
2726 the_ins
.reloc
[m
].pcrel
,
2739 * md_begin -- set up hash tables with 68000 instructions.
2740 * similar to what the vax assembler does. ---phr
2742 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2743 a copy of it at runtime, adding in the information we want but isn't
2744 there. I think it'd be better to have an awk script hack the table
2745 at compile time. Or even just xstr the table and use it as-is. But
2746 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2749 register const struct m68k_opcode
*ins
;
2750 register struct m68k_incant
*hack
,
2752 register char *retval
= 0; /* empty string, or error msg text */
2753 register unsigned int i
;
2756 if ((op_hash
= hash_new()) == NULL
)
2757 as_fatal("Virtual memory exhausted");
2759 obstack_begin(&robyn
,4000);
2760 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
2761 hack
=slak
=(struct m68k_incant
*)obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2763 /* we *could* ignore insns that don't match our
2764 arch here but just leaving them out of the
2766 slak
->m_operands
=ins
->args
;
2767 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
2768 slak
->m_arch
= ins
->arch
;
2769 slak
->m_opcode
=ins
->opcode
;
2770 /* This is kludgey */
2771 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
2772 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
2773 slak
->m_next
=(struct m68k_incant
*) obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2780 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
2781 /* Didn't his mommy tell him about null pointers? */
2782 if(retval
&& *retval
)
2783 as_fatal("Internal Error: Can't hash %s: %s",ins
->name
,retval
);
2786 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
2787 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
2789 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
2790 notend_table
[i
] = 0;
2791 alt_notend_table
[i
] = 0;
2793 notend_table
[','] = 1;
2794 notend_table
['{'] = 1;
2795 notend_table
['}'] = 1;
2796 alt_notend_table
['a'] = 1;
2797 alt_notend_table
['A'] = 1;
2798 alt_notend_table
['d'] = 1;
2799 alt_notend_table
['D'] = 1;
2800 alt_notend_table
['#'] = 1;
2801 alt_notend_table
['f'] = 1;
2802 alt_notend_table
['F'] = 1;
2803 #ifdef REGISTER_PREFIX
2804 alt_notend_table
[REGISTER_PREFIX
] = 1;
2811 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2812 || (*s == ':' && strchr("aAdD#", s[1]))) \
2816 /* This funciton is called once, before the assembler exits. It is
2817 supposed to do any final cleanup for this part of the assembler.
2824 /* Equal to MAX_PRECISION in atof-ieee.c */
2825 #define MAX_LITTLENUMS 6
2827 /* Turn a string in input_line_pointer into a floating point constant of type
2828 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2829 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2832 md_atof(type
,litP
,sizeP
)
2838 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2839 LITTLENUM_TYPE
*wordP
;
2870 return "Bad call to MD_ATOF()";
2872 t
=atof_ieee(input_line_pointer
,type
,words
);
2874 input_line_pointer
=t
;
2876 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
2877 for(wordP
=words
;prec
--;) {
2878 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
2879 litP
+=sizeof(LITTLENUM_TYPE
);
2881 return ""; /* Someone should teach Dean about null pointers */
2884 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2885 for use in the a.out file, and stores them in the array pointed to by buf.
2886 This knows about the endian-ness of the target machine and does
2887 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2888 2 (short) and 4 (long) Floating numbers are put out as a series of
2889 LITTLENUMS (shorts, here at least)
2892 md_number_to_chars(buf
,val
,n
)
2912 as_fatal("failed sanity check.");
2917 md_apply_fix(fixP
, val
)
2921 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2923 switch(fixP
->fx_size
) {
2938 BAD_CASE (fixP
->fx_size
);
2943 /* *fragP has been relaxed to its final size, and now needs to have
2944 the bytes inside it modified to conform to the new size There is UGLY
2948 md_convert_frag(headers
, fragP
)
2949 object_headers
*headers
;
2950 register fragS
*fragP
;
2955 /* Address in object code of the displacement. */
2956 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
2958 #ifdef IBM_COMPILER_SUX
2959 /* This is wrong but it convinces the native rs6000 compiler to
2960 generate the code we want. */
2961 register char *buffer_address
= fragP
-> fr_literal
;
2962 buffer_address
+= fragP
-> fr_fix
;
2963 #else /* IBM_COMPILER_SUX */
2964 /* Address in gas core of the place to store the displacement. */
2965 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2966 #endif /* IBM_COMPILER_SUX */
2968 /* No longer true: know(fragP->fr_symbol); */
2970 /* The displacement of the address, from current location. */
2971 disp
= fragP
->fr_symbol
? S_GET_VALUE(fragP
->fr_symbol
) : 0;
2972 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
2974 switch(fragP
->fr_subtype
) {
2975 case TAB(BCC68000
,BYTE
):
2976 case TAB(BRANCH
,BYTE
):
2977 know(issbyte(disp
));
2979 as_bad("short branch with zero offset: use :w");
2980 fragP
->fr_opcode
[1]=disp
;
2983 case TAB(DBCC
,SHORT
):
2984 know(issword(disp
));
2987 case TAB(BCC68000
,SHORT
):
2988 case TAB(BRANCH
,SHORT
):
2989 know(issword(disp
));
2990 fragP
->fr_opcode
[1]=0x00;
2993 case TAB(BRANCH
,LONG
):
2994 if (cpu_of_arch(current_architecture
) < m68020
) {
2995 if (fragP
->fr_opcode
[0]==0x61) {
2996 fragP
->fr_opcode
[0]= 0x4E;
2997 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
2998 subseg_change(SEG_TEXT
, 0);
3011 } else if (fragP
->fr_opcode
[0]==0x60) {
3012 fragP
->fr_opcode
[0]= 0x4E;
3013 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3014 subseg_change(SEG_TEXT
, 0);
3015 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
3020 as_bad("Long branch offset not supported.");
3023 fragP
->fr_opcode
[1]=0xff;
3027 case TAB(BCC68000
,LONG
):
3028 /* only Bcc 68000 instructions can come here */
3029 /* change bcc into b!cc/jmp absl long */
3030 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3031 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
3033 /* JF: these used to be fr_opcode[2,3], but they may be in a
3034 different frag, in which case refering to them is a no-no.
3035 Only fr_opcode[0,1] are guaranteed to work. */
3036 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3037 *buffer_address
++ = 0xf9;
3038 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3039 subseg_change(SEG_TEXT
,0);
3040 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3046 case TAB(DBCC
,LONG
):
3047 /* only DBcc 68000 instructions can come here */
3048 /* change dbcc into dbcc/jmp absl long */
3049 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3050 *buffer_address
++ = 0x00; /* branch offset = 4 */
3051 *buffer_address
++ = 0x04;
3052 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3053 *buffer_address
++ = 0x06;
3054 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3055 *buffer_address
++ = 0xf9;
3057 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3058 subseg_change(SEG_TEXT
,0);
3059 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3065 case TAB(FBRANCH
,SHORT
):
3066 know((fragP
->fr_opcode
[1]&0x40)==0);
3069 case TAB(FBRANCH
,LONG
):
3070 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
3073 case TAB(PCREL
,SHORT
):
3076 case TAB(PCREL
,LONG
):
3077 /* The thing to do here is force it to ABSOLUTE LONG, since
3078 PCREL is really trying to shorten an ABSOLUTE address anyway */
3079 /* JF FOO This code has not been tested */
3080 subseg_change(SEG_TEXT
,0);
3081 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3082 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3083 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3084 fragP
->fr_opcode
[0],fragP
->fr_address
);
3085 fragP
->fr_opcode
[1]&= ~0x3F;
3086 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
3088 /* md_number_to_chars(buffer_address,
3089 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3093 case TAB(PCLEA
,SHORT
):
3094 subseg_change(SEG_TEXT
,0);
3095 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
3097 fragP
->fr_opcode
[1] &= ~0x3F;
3098 fragP
->fr_opcode
[1] |= 0x3A;
3101 case TAB(PCLEA
,LONG
):
3102 subseg_change(SEG_TEXT
,0);
3103 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
3105 *buffer_address
++ = 0x01;
3106 *buffer_address
++ = 0x70;
3108 /* buffer_address+=2; */
3112 } /* switch on subtype */
3115 md_number_to_chars(buffer_address
, (long) disp
, (int) ext
);
3116 fragP
->fr_fix
+= ext
;
3117 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3118 } /* if extending */
3121 } /* md_convert_frag() */
3123 /* Force truly undefined symbols to their maximum size, and generally set up
3124 the frag list to be relaxed
3126 int md_estimate_size_before_relax(fragP
, segment
)
3127 register fragS
*fragP
;
3131 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3133 old_fix
= fragP
->fr_fix
;
3135 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3136 switch (fragP
->fr_subtype
) {
3138 case TAB(BRANCH
,SZ_UNDEF
): {
3139 if((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3140 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3141 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
3143 } else if((fragP
->fr_symbol
== 0) || (cpu_of_arch(current_architecture
) < m68020
)) {
3144 /* On 68000, or for absolute value, switch to abs long */
3145 /* FIXME, we should check abs val, pick short or long */
3146 if(fragP
->fr_opcode
[0]==0x61) {
3147 fragP
->fr_opcode
[0]= 0x4E;
3148 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3149 subseg_change(SEG_TEXT
, 0);
3150 fix_new(fragP
, fragP
->fr_fix
, 4,
3151 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3154 } else if(fragP
->fr_opcode
[0]==0x60) {
3155 fragP
->fr_opcode
[0]= 0x4E;
3156 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3157 subseg_change(SEG_TEXT
, 0);
3158 fix_new(fragP
, fragP
->fr_fix
, 4,
3159 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3163 as_warn("Long branch offset to extern symbol not supported.");
3165 } else { /* Symbol is still undefined. Make it simple */
3166 fix_new(fragP
, (int)(fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3167 (symbolS
*)0, fragP
->fr_offset
+4, 1, NO_RELOC
);
3169 fragP
->fr_opcode
[1]=0xff;
3175 } /* case TAB(BRANCH,SZ_UNDEF) */
3177 case TAB(FBRANCH
,SZ_UNDEF
): {
3178 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3179 fragP
->fr_subtype
= TAB(FBRANCH
,SHORT
);
3182 fragP
->fr_subtype
= TAB(FBRANCH
,LONG
);
3186 } /* TAB(FBRANCH,SZ_UNDEF) */
3188 case TAB(PCREL
,SZ_UNDEF
): {
3189 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3190 fragP
->fr_subtype
= TAB(PCREL
,SHORT
);
3193 fragP
->fr_subtype
= TAB(PCREL
,LONG
);
3197 } /* TAB(PCREL,SZ_UNDEF) */
3199 case TAB(BCC68000
,SZ_UNDEF
): {
3200 if((fragP
->fr_symbol
!= NULL
)
3201 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3202 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
3205 /* only Bcc 68000 instructions can come here */
3206 /* change bcc into b!cc/jmp absl long */
3207 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3209 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3210 /* JF: these were fr_opcode[2,3] */
3211 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3212 buffer_address
[1] = 0xf8;
3213 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3214 subseg_change(SEG_TEXT
,0);
3215 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3216 fragP
->fr_offset
, 0, NO_RELOC
);
3219 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3220 /* JF: these were fr_opcode[2,3] */
3221 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3222 buffer_address
[1] = 0xf9;
3223 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3224 subseg_change(SEG_TEXT
,0);
3225 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3226 fragP
->fr_offset
, 0, NO_RELOC
);
3231 } /* case TAB(BCC68000,SZ_UNDEF) */
3233 case TAB(DBCC
,SZ_UNDEF
): {
3234 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3235 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3239 /* only DBcc 68000 instructions can come here */
3240 /* change dbcc into dbcc/jmp absl long */
3241 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3242 buffer_address
[0] = 0x00; /* branch offset = 4 */
3243 buffer_address
[1] = 0x04;
3244 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3247 /* JF: these were fr_opcode[5-7] */
3248 buffer_address
[3] = 0x04; /* plus 4 */
3249 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3250 buffer_address
[5] = 0xf8;
3251 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3252 subseg_change(SEG_TEXT
,0);
3253 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3256 fragP
->fr_offset
, 0, NO_RELOC
);
3259 /* JF: these were fr_opcode[5-7] */
3260 buffer_address
[3] = 0x06; /* Plus 6 */
3261 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3262 buffer_address
[5] = 0xf9;
3263 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3264 subseg_change(SEG_TEXT
,0);
3265 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3266 fragP
->fr_offset
, 0, NO_RELOC
);
3272 } /* case TAB(DBCC,SZ_UNDEF) */
3274 case TAB(PCLEA
,SZ_UNDEF
): {
3275 if ((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3276 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3279 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3283 } /* TAB(PCLEA,SZ_UNDEF) */
3288 } /* switch on subtype looking for SZ_UNDEF's. */
3290 /* now that SZ_UNDEF are taken care of, check others */
3291 switch (fragP
->fr_subtype
) {
3292 case TAB(BCC68000
,BYTE
):
3293 case TAB(BRANCH
,BYTE
):
3294 /* We can't do a short jump to the next instruction,
3295 so we force word mode. */
3296 if (fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3297 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3298 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3305 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3308 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3309 /* the bit-field entries in the relocation_info struct plays hell
3310 with the byte-order problems of cross-assembly. So as a hack,
3311 I added this mach. dependent ri twiddler. Ugly, but it gets
3313 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3314 are symbolnum, most sig. byte first. Last byte is broken up with
3315 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3316 nibble as nuthin. (on Sun 3 at least) */
3317 /* Translate the internal relocation information into target-specific
3321 md_ri_to_chars(the_bytes
, ri
)
3323 struct reloc_info_generic
*ri
;
3326 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3327 /* now the fun stuff */
3328 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3329 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3330 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3331 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3332 ((ri
->r_extern
<< 4) & 0x10));
3334 #endif /* comment */
3336 void tc_aout_fix_to_chars(where
, fixP
, segment_address_in_file
)
3339 relax_addressT segment_address_in_file
;
3342 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3343 * Out: GNU LD relocation length code: 0, 1, or 2.
3346 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
3349 know(fixP
->fx_addsy
!= NULL
);
3351 md_number_to_chars(where
,
3352 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3355 r_symbolnum
= (S_IS_DEFINED(fixP
->fx_addsy
)
3356 ? S_GET_TYPE(fixP
->fx_addsy
)
3357 : fixP
->fx_addsy
->sy_number
);
3359 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3360 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3361 where
[6] = r_symbolnum
& 0x0ff;
3362 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3363 (((!S_IS_DEFINED(fixP
->fx_addsy
)) << 4) & 0x10));
3366 } /* tc_aout_fix_to_chars() */
3368 #endif /* OBJ_AOUT or OBJ_BOUT */
3370 #ifndef WORKING_DOT_WORD
3371 const int md_short_jump_size
= 4;
3372 const int md_long_jump_size
= 6;
3375 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3384 offset
= to_addr
- (from_addr
+2);
3386 md_number_to_chars(ptr
,(long)0x6000,2);
3387 md_number_to_chars(ptr
+2,(long)offset
,2);
3391 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3400 if (cpu_of_arch(current_architecture
) < m68020
) {
3401 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3402 md_number_to_chars(ptr
,(long)0x4EF9,2);
3403 md_number_to_chars(ptr
+2,(long)offset
,4);
3404 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3407 offset
=to_addr
- (from_addr
+2);
3408 md_number_to_chars(ptr
,(long)0x60ff,2);
3409 md_number_to_chars(ptr
+2,(long)offset
,4);
3414 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3417 10: Absolute 1:8 only
3418 20: Absolute 0:7 only
3419 30: absolute 0:15 only
3420 40: Absolute 0:31 only
3421 50: absolute 0:127 only
3422 55: absolute -64:63 only
3423 60: absolute -128:127 only
3424 70: absolute 0:4095 only
3429 static int get_num(exp
,ok
)
3430 struct m68k_exp
*exp
;
3438 if(*exp
->e_beg
=='0') {
3439 if(exp
->e_beg
[1]=='x')
3440 sscanf(exp
->e_beg
+2,"%x",&l
);
3442 sscanf(exp
->e_beg
+1,"%O",&l
);
3445 return atol(exp
->e_beg
);
3451 /* Can't do anything */
3454 if(!exp
->e_beg
|| !exp
->e_end
) {
3455 seg(exp
)=SEG_ABSOLUTE
;
3458 offs(exp
)= (ok
==10) ? 1 : 0;
3459 as_warn("Null expression defaults to %ld",offs(exp
));
3464 if(/* ok!=80 && */exp
->e_end
[-1]==':' && (exp
->e_end
-exp
->e_beg
)>=2) {
3465 switch(exp
->e_end
[0]) {
3481 as_bad("Unknown size for expression \"%c\"",exp
->e_end
[0]);
3485 c_save
=exp
->e_end
[1];
3487 save_in
=input_line_pointer
;
3488 input_line_pointer
=exp
->e_beg
;
3489 switch(expression(&(exp
->e_exp
))) {
3491 seg(exp
)=SEG_ABSOLUTE
;
3494 offs(exp
)= (ok
==10) ? 1 : 0;
3495 as_warn("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
3499 /* Do the same thing the VAX asm does */
3500 seg(exp
)=SEG_ABSOLUTE
;
3505 as_warn("expression out of range: defaulting to 1");
3512 if(offs(exp
)<1 || offs(exp
)>8) {
3513 as_warn("expression out of range: defaulting to 1");
3518 if(offs(exp
)<0 || offs(exp
)>7)
3522 if(offs(exp
)<0 || offs(exp
)>15)
3526 if(offs(exp
)<0 || offs(exp
)>32)
3530 if(offs(exp
)<0 || offs(exp
)>127)
3534 if(offs(exp
)<-64 || offs(exp
)>63)
3538 if(offs(exp
)<-128 || offs(exp
)>127)
3542 if(offs(exp
)<0 || offs(exp
)>4095) {
3544 as_warn("expression out of range: defaulting to 0");
3556 case SEG_DIFFERENCE
:
3557 if(ok
>=10 && ok
<=70) {
3558 seg(exp
)=SEG_ABSOLUTE
;
3561 offs(exp
)= (ok
==10) ? 1 : 0;
3562 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3566 if(ok
==80 && offs(exp
)<0) { /* HACK! Turn it into a long */
3567 LITTLENUM_TYPE words
[6];
3569 gen_to_words(words
,2,8L);/* These numbers are magic! */
3570 seg(exp
)=SEG_ABSOLUTE
;
3573 offs(exp
)=words
[1]|(words
[0]<<16);
3575 seg(exp
)=SEG_ABSOLUTE
;
3578 offs(exp
)= (ok
==10) ? 1 : 0;
3579 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3583 as_fatal("failed sanity check.");
3585 if(input_line_pointer
!=exp
->e_end
+1)
3586 as_bad("Ignoring junk after expression");
3587 exp
->e_end
[1]=c_save
;
3588 input_line_pointer
=save_in
;
3590 switch(exp
->e_siz
) {
3592 if(!isbyte(offs(exp
)))
3593 as_warn("expression doesn't fit in BYTE");
3596 if(!isword(offs(exp
)))
3597 as_warn("expression doesn't fit in WORD");
3605 /* These are the back-ends for the various machine dependent pseudo-ops. */
3606 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
3608 static void s_data1() {
3609 subseg_new(SEG_DATA
,1);
3610 demand_empty_rest_of_line();
3613 static void s_data2() {
3614 subseg_new(SEG_DATA
,2);
3615 demand_empty_rest_of_line();
3620 /* We don't support putting frags in the BSS segment, we fake it
3621 by marking in_bss, then looking at s_skip for clues */
3623 subseg_new(SEG_BSS
, 0);
3624 demand_empty_rest_of_line();
3627 static void s_even() {
3629 register long temp_fill
;
3631 temp
= 1; /* JF should be 2? */
3632 temp_fill
= get_absolute_expression ();
3633 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
3634 frag_align (temp
, (int)temp_fill
);
3635 demand_empty_rest_of_line();
3638 static void s_proc() {
3639 demand_empty_rest_of_line();
3642 /* s_space is defined in read.c .skip is simply an alias to it. */
3646 * Invocation line includes a switch not recognized by the base assembler.
3647 * See if it's a processor-specific option. These are:
3649 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3650 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3651 * Select the architecture. Instructions or features not
3652 * supported by the selected architecture cause fatal
3653 * errors. More than one may be specified. The default is
3654 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3655 * for -m68000, and -m68882 is a synonym for -m68881.
3657 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
3658 * (e.g. m68020) also requests that float instructions be included. This
3659 * is the default setup, mostly to avoid hassling users. A better
3660 * rearrangement of this structure would be to add an option to DENY
3661 * floating point opcodes, for people who want to really know there's none
3662 * of that funny floaty stuff going on. FIXME-later.
3664 #ifndef MAYBE_FLOAT_TOO
3665 #define MAYBE_FLOAT_TOO m68881
3668 int md_parse_option(argP
,cntP
,vecP
)
3674 case 'l': /* -l means keep external to 2 bit offset
3675 rather than 16 bit one */
3678 case 'S': /* -S means that jbsr's always turn into jsr's. */
3683 /* intentional fall-through */
3689 } /* allow an optional "c" */
3691 if (!strcmp(*argP
, "68000")
3692 || !strcmp(*argP
, "68008")) {
3693 current_architecture
|= m68000
;
3694 } else if (!strcmp(*argP
, "68010")) {
3696 omagic
= 1<<16|OMAGIC
;
3698 current_architecture
|= m68010
;
3700 } else if (!strcmp(*argP
, "68020")) {
3701 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
3703 } else if (!strcmp(*argP
, "68030")) {
3704 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
3706 } else if (!strcmp(*argP
, "68040")) {
3707 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
3710 } else if (!strcmp(*argP
, "68881")) {
3711 current_architecture
|= m68881
;
3713 } else if (!strcmp(*argP
, "68882")) {
3714 current_architecture
|= m68882
;
3716 #endif /* NO_68881 */
3718 } else if (!strcmp(*argP
,"68851")) {
3719 current_architecture
|= m68851
;
3721 #endif /* NO_68851 */
3723 as_warn("Unknown architecture, \"%s\". option ignored", *argP
);
3724 } /* switch on architecture */
3726 while(**argP
) (*argP
)++;
3731 if (!strcmp(*argP
,"pic")) {
3733 break; /* -pic, Position Independent Code */
3747 /* TEST2: Test md_assemble() */
3748 /* Warning, this routine probably doesn't work anymore */
3752 struct m68k_it the_ins
;
3759 if(!gets(buf
) || !*buf
)
3761 if(buf
[0]=='|' || buf
[1]=='.')
3763 for(cp
=buf
;*cp
;cp
++)
3768 memset(&the_ins
, '\0', sizeof(the_ins
));
3769 m68k_ip(&the_ins
,buf
);
3771 printf("Error %s in %s\n",the_ins
.error
,buf
);
3773 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
3774 for(n
=0;n
<the_ins
.numo
;n
++)
3775 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
3777 print_the_insn(&the_ins
.opcode
[0],stdout
);
3778 (void)putchar('\n');
3780 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
3781 if(the_ins
.operands
[n
].error
) {
3782 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
3785 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
3786 if(the_ins
.operands
[n
].b_const
)
3787 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
3788 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
3789 if(the_ins
.operands
[n
].b_iadd
)
3790 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
3791 (void)putchar('\n');
3803 while(*str
&& *str
!=' ')
3805 if(str
[-1]==':' || str
[1]=='=')
3812 /* Possible states for relaxation:
3814 0 0 branch offset byte (bra, etc)
3818 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3822 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3841 extern fragS
*text_frag_root
;
3843 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
3844 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3845 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
3846 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
3858 fputs("Internal error:",stderr
);
3859 _doprnt(format
,&args
,stderr
);
3860 (void)putc('\n',stderr
);
3866 /* We have no need to default values of symbols. */
3870 md_undefined_symbol (name
)
3876 /* Parse an operand that is machine-specific.
3877 We just return without modifying the expression if we have nothing
3882 md_operand (expressionP
)
3883 expressionS
*expressionP
;
3887 /* Round up a section size to the appropriate boundary. */
3889 md_section_align (segment
, size
)
3893 return size
; /* Byte alignment is fine */
3896 /* Exactly what point is a PC-relative offset relative TO?
3897 On the 68k, they're relative to the address of the offset, plus
3898 its size. (??? Is this right? FIXME-SOON!) */
3900 md_pcrel_from (fixP
)
3903 return(fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
3913 /* end of tc-m68k.c */