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
120 ?.? DINDR dreg@ --> (dreg) -- cas2 only
130 a1@(5,d2:w:1) @(45,d6:l:4)
135 #name@(numw) -->turn into PC rel mode
136 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
163 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
166 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
167 8-15==addr reg for operands that take both types */
170 DATA
= 1, /* 1- 8 == data registers 0-7 */
190 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
195 FPREG
, /* Eight FP registers */
204 COPNUM
= (FPREG
+8), /* Co-processor #1-#8 */
213 PC
, /* Program counter */
214 ZPC
, /* Hack for Program space, but 0 addressing */
216 CCR
, /* Condition code Reg */
218 /* These have to be in order for the movec instruction to work. */
219 USP
, /* User Stack Pointer */
220 ISP
, /* Interrupt stack pointer */
235 /* end of movec ordering constraints */
268 IC
, /* instruction cache token */
269 DC
, /* data cache token */
270 NC
, /* no cache token */
271 BC
, /* both caches token */
275 /* Internal form of an operand. */
277 char *error
; /* Couldn't parse it */
278 enum operand_type mode
; /* What mode this instruction is in. */
279 enum _register reg
; /* Base register */
280 struct m68k_exp
*con1
;
281 int ireg
; /* Index register */
282 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
283 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
284 struct m68k_exp
*con2
;
287 /* internal form of a 68020 instruction */
290 char *args
; /* list of opcode info */
293 int numo
; /* Number of shorts in opcode */
296 struct m68k_op operands
[6];
298 int nexp
; /* number of exprs in use */
299 struct m68k_exp exprs
[4];
301 int nfrag
; /* Number of frags we have to produce */
303 int fragoff
; /* Where in the current opcode[] the frag ends */
309 int nrel
; /* Num of reloc strucs in use */
317 } reloc
[5]; /* Five is enough??? */
320 #define cpu_of_arch(x) ((x) & m68000up)
321 #define float_of_arch(x) ((x) & mfloat)
322 #define mmu_of_arch(x) ((x) & mmmu)
324 static struct m68k_it the_ins
; /* the instruction being assembled */
326 /* Macros for adding things to the m68k_it struct */
328 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
330 /* Like addword, but goes BEFORE general operands */
331 #define insop(w) {int z;\
332 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
333 the_ins.opcode[z]=the_ins.opcode[z-1];\
334 for(z=0;z<the_ins.nrel;z++)\
335 the_ins.reloc[z].n+=2;\
336 the_ins.opcode[opcode->m_codenum]=w;\
341 #define add_exp(beg,end) (\
342 the_ins.exprs[the_ins.nexp].e_beg=beg,\
343 the_ins.exprs[the_ins.nexp].e_end=end,\
344 &the_ins.exprs[the_ins.nexp++]\
348 /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
349 #define add_fix(width,exp,pc_rel) {\
350 the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
351 (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
352 the_ins.reloc[the_ins.nrel].add=adds((exp));\
353 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
354 the_ins.reloc[the_ins.nrel].off=offs((exp));\
355 the_ins.reloc[the_ins.nrel].wid=width;\
356 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
359 #define add_frag(add,off,type) {\
360 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
361 the_ins.fragb[the_ins.nfrag].fadd=add;\
362 the_ins.fragb[the_ins.nfrag].foff=off;\
363 the_ins.fragb[the_ins.nfrag++].fragty=type;\
366 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
368 #define seg(exp) ((exp)->e_exp.X_seg)
369 #define adds(exp) ((exp)->e_exp.X_add_symbol)
370 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
371 #define offs(exp) ((exp)->e_exp.X_add_number)
376 unsigned long m_opcode
;
379 enum m68k_architecture m_arch
;
380 struct m68k_incant
*m_next
;
383 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
384 #define gettwo(x) (((x)->m_opcode)&0xffff)
389 static char *crack_operand(char *str
, struct m68k_op
*opP
);
390 static int get_num(struct m68k_exp
*exp
, int ok
);
391 static int get_regs(int i
, char *str
, struct m68k_op
*opP
);
392 static int reverse_16_bits(int in
);
393 static int reverse_8_bits(int in
);
394 static int try_index(char **s
, struct m68k_op
*opP
);
395 static void install_gen_operand(int mode
, int val
);
396 static void install_operand(int mode
, int val
);
398 static void s_data1(void);
399 static void s_data2(void);
400 static void s_even(void);
401 static void s_proc(void);
403 #else /* not __STDC__ */
405 static char *crack_operand();
406 static int get_num();
407 static int get_regs();
408 static int reverse_16_bits();
409 static int reverse_8_bits();
410 static int try_index();
411 static void install_gen_operand();
412 static void install_operand();
414 void s_align_bytes();
415 static void s_data1();
416 static void s_data2();
417 static void s_even();
418 static void s_proc();
420 #endif /* not __STDC__ */
422 static enum m68k_architecture current_architecture
= 0;
424 /* BCC68000 is for patching in an extra jmp instruction for long offsets
425 on the 68000. The 68000 doesn't support long branches with branchs */
427 /* This table desribes how you change sizes for the various types of variable
428 size expressions. This version only supports two kinds. */
430 /* Note that calls to frag_var need to specify the maximum expansion needed */
431 /* This is currently 10 bytes for DBCC */
434 How far Forward this mode will reach:
435 How far Backward this mode will reach:
436 How many bytes this mode will add to the size of the frag
437 Which mode to go to if the offset won't fit in this one
441 { 1, 1, 0, 0 }, /* First entries aren't used */
442 { 1, 1, 0, 0 }, /* For no good reason except */
443 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
446 { (127), (-128), 0, TAB(BRANCH
,SHORT
)},
447 { (32767), (-32768), 2, TAB(BRANCH
,LONG
) },
451 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
452 { (32767), (-32768), 2, TAB(FBRANCH
,LONG
)},
456 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
457 { (32767), (-32768), 2, TAB(PCREL
,LONG
)},
461 { (127), (-128), 0, TAB(BCC68000
,SHORT
)},
462 { (32767), (-32768), 2, TAB(BCC68000
,LONG
) },
463 { 0, 0, 6, 0 }, /* jmp long space */
466 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
467 { (32767), (-32768), 2, TAB(DBCC
,LONG
) },
468 { 0, 0, 10, 0 }, /* bra/jmp long space */
471 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
472 { 32767, -32768, 2, TAB(PCLEA
,LONG
) },
478 /* These are the machine dependent pseudo-ops. These are included so
479 the assembler can work on the output from the SUN C compiler, which
483 /* This table describes all the machine specific pseudo-ops the assembler
484 has to support. The fields are:
485 pseudo-op name without dot
486 function to call to execute this pseudo-op
487 Integer arg to pass to the function
489 const pseudo_typeS md_pseudo_table
[] = {
490 { "data1", s_data1
, 0 },
491 { "data2", s_data2
, 0 },
493 { "even", s_even
, 0 },
494 { "skip", s_space
, 0 },
495 { "proc", s_proc
, 0 },
497 { "align", s_align_bytes
, 0 },
503 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
504 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
506 #define issbyte(x) ((x)>=-128 && (x)<=127)
507 #define isubyte(x) ((x)>=0 && (x)<=255)
508 #define issword(x) ((x)>=-32768 && (x)<=32767)
509 #define isuword(x) ((x)>=0 && (x)<=65535)
511 #define isbyte(x) ((x)>=-128 && (x)<=255)
512 #define isword(x) ((x)>=-32768 && (x)<=65535)
513 #define islong(x) (1)
515 extern char *input_line_pointer
;
522 /* JF these tables here are for speed at the expense of size */
523 /* You can replace them with the #if 0 versions if you really
524 need space and don't mind it running a bit slower */
526 static char mklower_table
[256];
527 #define mklower(c) (mklower_table[(unsigned char)(c)])
528 static char notend_table
[256];
529 static char alt_notend_table
[256];
530 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
531 alt_notend_table[(unsigned char)(s[1])])))
534 #define mklower(c) (isupper(c) ? tolower(c) : c)
538 /* JF modified this to handle cases where the first part of a symbol name
539 looks like a register */
542 * m68k_reg_parse() := if it looks like a register, return it's token &
543 * advance the pointer.
546 enum _register
m68k_reg_parse(ccp
)
551 if (isalpha(*start
) && is_name_beginner(*start
))
557 while (is_part_of_name(c
= *p
++))
560 symbolP
= symbol_find(start
);
563 if (symbolP
&& S_GET_SEGMENT(symbolP
) == SEG_REGISTER
)
566 return S_GET_VALUE(symbolP
);
574 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
577 * m68k_ip_op := '#' + <anything>
578 * | <register> + range_sep + get_regs
581 * range_sep := '/' | '-' ;
583 * SKIP_WHITE := <empty> | ' ' ;
590 register struct m68k_op
*opP
;
598 } /* Find the beginning of the string */
601 opP
->error
="Missing operand";
605 for(strend
= str
; *strend
; strend
++) ;;
611 opP
->con1
=add_exp(str
,strend
);
614 } /* Guess what: A constant. Shar and enjoy */
616 i
= m68k_reg_parse(&str
);
618 /* is a register, is exactly a register, and is followed by '@' */
620 if((i
==FAIL
|| *str
!='\0') && *str
!='@') {
623 if(i
!=FAIL
&& (*str
=='/' || *str
=='-')) {
625 return(get_regs(i
,str
,opP
));
627 if ((stmp
=strchr(str
,'@')) != '\0') {
628 opP
->con1
=add_exp(str
,stmp
-1);
634 if ((current_architecture
& m68020up
) == 0) {
636 } /* if target is not a '20 or better */
639 if(*stmp
++!='(' || *strend
--!=')') {
640 opP
->error
="Malformed operand";
643 i
=try_index(&stmp
,opP
);
644 opP
->con2
=add_exp(stmp
,strend
);
652 } /* if there's an '@' */
654 opP
->con1
= add_exp(str
,strend
);
656 } /* not a register, not exactly a register, or no '@' */
661 if(i
>=DATA
+0 && i
<=DATA
+7)
663 else if(i
>=ADDR
+0 && i
<=ADDR
+7)
670 /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
671 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
672 && (str
[1] != '\0' || i
<DATA
+0 || i
>DATA
+7)) {
673 opP
->error
="Invalid indirect register";
681 if (i
< DATA
+ 0 || i
> DATA
+ 7)
696 opP
->error
="Junk after indirect";
699 /* Some kind of indexing involved. Lets find out how bad it is */
700 i
=try_index(&str
,opP
);
701 /* Didn't start with an index reg, maybe its offset or offset,reg */
709 opP
->error
="Missing )";
711 case ',': i
=0; break;
712 case '(': i
++; break;
713 case ')': --i
; break;
716 /* if(str[-3]==':') {
733 opP->error="Specified size isn't :w or :l";
736 opP->con1=add_exp(beg_str,str-4);
737 opP->con1->e_siz=siz;
739 opP
->con1
=add_exp(beg_str
,str
-2);
740 /* Should be offset,reg */
742 i
=try_index(&str
,opP
);
744 opP
->error
="Malformed index reg";
749 /* We've now got offset) offset,reg) or reg) */
752 /* Th-the-thats all folks */
753 if (opP
->reg
== FAIL
) opP
->mode
= AINDX
; /* Other form of indirect */
754 else if(opP
->ireg
== FAIL
) opP
->mode
= AOFF
;
755 else opP
->mode
= AINDX
;
758 /* Next thing had better be another @ */
770 if ((current_architecture
& m68020up
) == 0) {
772 } /* if target is not a '20 or better */
775 if(opP
->ireg
!= FAIL
) {
778 i
= try_index(&str
, opP
);
780 opP
->error
= "Two index registers! not allowed!";
784 i
= try_index(&str
, opP
);
796 opP
->error
="Missing )";
799 case ',': i
=0; break;
800 case '(': i
++; break;
801 case ')': --i
; break;
805 opP
->con2
=add_exp(beg_str
,str
-2);
807 if (str
[-1] == ',') {
808 if (opP
->ireg
!= FAIL
) {
809 opP
->error
= "Can't have two index regs";
813 i
= try_index(&str
, opP
);
816 opP
->error
= "malformed index reg";
821 } else if (opP
->ireg
!= FAIL
) {
831 opP
->error
="Junk after indirect";
839 * try_index := data_or_address_register + ')' + SKIP_W
840 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
842 * multiplier := <empty>
843 * | ':' + multiplier_number
846 * multiplier_number := '1' | '2' | '4' | '8' ;
848 * size_spec := 'l' | 'L' | 'w' | 'W' ;
850 * SKIP_W := <empty> | ' ' ;
854 static int try_index(s
,opP
)
860 #define SKIP_W() { ss++; if (*ss==' ') ss++;}
864 i
=m68k_reg_parse(&ss
);
865 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
879 opP
->error
="Missing : in index register";
894 opP
->error
="Index register size spec not :w or :l";
906 if (cpu_of_arch(current_architecture
) < m68020
) {
907 opP
->error
="no index scaling in pre-68020's";
914 opP
->error
="index multiplier not 1, 2, 4 or 8";
921 opP
->error
="Missing )";
930 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
934 struct m68k_op thark
;
939 memset(&thark
, '\0', sizeof(thark
));
940 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
942 printf("op1 error %s in %s\n",thark
.error
,buf
);
943 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
945 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
946 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
948 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
957 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
958 NULL means any use before m68k_ip_begin()
965 * This converts a string into a 68k instruction.
966 * The string must be a bare single instruction in sun format
967 * with RMS-style 68020 indirects
970 * It provides some error messages: at most one fatal error message (which
971 * stops the scan) and at most one warning message for each operand.
972 * The 68k instruction is returned in exploded form, since we have no
973 * knowledge of how you parse (or evaluate) your expressions.
974 * We do however strip off and decode addressing modes and operation
977 * This function's value is a string. If it is not "" then an internal
978 * logic error was found: read this code to assign meaning to the string.
979 * No argument string should generate such an error string:
980 * it means a bug in our code, not in the user's text.
982 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
986 /* JF this function no longer returns a useful value. Sorry */
987 void m68k_ip (instring
)
991 register struct m68k_op
*opP
;
992 register struct m68k_incant
*opcode
;
994 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
999 char *crack_operand();
1000 LITTLENUM_TYPE words
[6];
1001 LITTLENUM_TYPE
*wordp
;
1002 unsigned long ok_arch
= 0;
1004 if (*instring
== ' ')
1005 instring
++; /* skip leading whitespace */
1007 /* Scan up to end of operation-code, which MUST end in end-of-string
1008 or exactly 1 space. */
1009 for (p
= instring
; *p
!= '\0'; p
++)
1014 if (p
== instring
) {
1015 the_ins
.error
= "No operator";
1016 the_ins
.opcode
[0] = NULL
;
1017 /* the_ins.numo=1; */
1021 /* p now points to the end of the opcode name, probably whitespace.
1022 make sure the name is null terminated by clobbering the whitespace,
1023 look it up in the hash table, then fix it back. */
1026 opcode
= (struct m68k_incant
*)hash_find (op_hash
, instring
);
1029 if (opcode
== NULL
) {
1030 the_ins
.error
= "Unknown operator";
1031 the_ins
.opcode
[0] = NULL
;
1032 /* the_ins.numo=1; */
1036 /* found a legitimate opcode, start matching operands */
1037 while (*p
== ' ') ++p
;
1039 for(opP
= &the_ins
.operands
[0]; *p
; opP
++) {
1041 p
= crack_operand(p
, opP
);
1044 the_ins
.error
=opP
->error
;
1049 opsfound
= opP
- &the_ins
.operands
[0];
1051 /* This ugly hack is to support the floating pt opcodes in their standard form */
1052 /* Essentially, we fake a first enty of type COP#1 */
1053 if (opcode
->m_operands
[0]=='I') {
1056 for(n
=opsfound
;n
>0;--n
)
1057 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1059 memset((char *)(&the_ins
.operands
[0]), '\0', sizeof(the_ins
.operands
[0]));
1060 the_ins
.operands
[0].mode
=MSCR
;
1061 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1065 /* We've got the operands. Find an opcode that'll accept them */
1066 for (losing
= 0; ; ) {
1067 /* if we didn't get the right number of ops,
1068 or we have no common model with this pattern
1069 then reject this pattern. */
1071 if (opsfound
!= opcode
->m_opnum
1072 || ((opcode
->m_arch
& current_architecture
) == 0))
1075 ok_arch
|= opcode
->m_arch
;
1078 for (s
=opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++) {
1079 /* Warning: this switch is huge! */
1080 /* I've tried to organize the cases into this order:
1081 non-alpha first, then alpha by letter. lower-case goes directly
1082 before uppercase counterpart. */
1083 /* Code with multiple case ...: gets sorted by the lowest case ...
1084 it belongs to. I hope this makes sense. */
1087 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1088 || opP
->mode
== DREG
|| opP
->mode
== AREG
1089 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1090 || opP
->mode
== REGLST
)
1095 if(opP
->mode
!=IMMED
)
1100 t
=get_num(opP
->con1
,80);
1101 if(s
[1]=='b' && !isbyte(t
))
1103 else if(s
[1]=='w' && !isword(t
))
1110 if(opP
->mode
!=IMMED
)
1115 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1116 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1121 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1122 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1128 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1129 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1130 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1135 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1150 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1151 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1156 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1161 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1162 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1163 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1168 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1169 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1173 case '~': /* For now! (JF FOO is this right?) */
1174 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1175 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1184 if (opP
->mode
!= AINDR
) {
1186 } /* if not address register indirect */
1189 if(opP
->mode
!=ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1190 && instring
[1] == 'b'
1191 && instring
[2] == 's'
1192 && instring
[3] == 'r'))
1197 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1201 case 'd': /* FOO This mode is a KLUDGE!! */
1202 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1203 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1213 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1218 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1224 if (opP
->mode
!= MSCR
1227 || cpu_of_arch(current_architecture
) < m68010
/* before 68010 had none */
1228 || (cpu_of_arch(current_architecture
) < m68020
1232 && opP
->reg
!= VBR
) /* 68010's had only these */
1233 || (cpu_of_arch(current_architecture
) < m68040
1241 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1242 || (cpu_of_arch(current_architecture
) == m68040
/* 68040 has all but this */
1243 && opP
->reg
== CAAR
)) {
1245 } /* doesn't cut it */
1249 if(opP
->mode
!=IMMED
)
1255 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1260 opP
->reg
=1<<(opP
->reg
-DATA
);
1262 } else if(opP
->mode
!=REGLST
) {
1264 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1266 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1271 if(opP
->mode
!=IMMED
)
1276 t
=get_num(opP
->con1
,80);
1277 if(!issbyte(t
) || isvar(opP
->con1
))
1283 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1288 if(opP
->mode
!=IMMED
)
1293 t
=get_num(opP
->con1
,80);
1294 if(t
<1 || t
>8 || isvar(opP
->con1
))
1300 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1305 if (opP
->mode
!=AINDR
&& opP
->mode
!=DINDR
)
1310 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1315 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1320 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1324 /* JF these are out of order. We could put them
1325 in order if we were willing to put up with
1326 bunches of #ifdef m68851s in the code */
1328 /* Memory addressing mode used by pflushr */
1330 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1331 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1336 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1341 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TC
&& opP
->reg
!= CAL
&&
1342 opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1347 if (opP
->reg
!= VAL
)
1352 if (opP
->mode
!= MSCR
|| (opP
->reg
!= DRP
&& opP
->reg
!= SRP
&&
1358 if (opP
->mode
!= MSCR
||
1359 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1360 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1365 if (opP
->reg
!= PSR
)
1370 if (opP
->reg
!= PCSR
)
1378 && opP
->reg
!= BC
) {
1380 } /* not a cache specifier. */
1384 if (opP
->mode
!= ABSL
) {
1386 } /* not absolute */
1390 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1391 *s
, __LINE__
, __FILE__
);
1392 } /* switch on type of operand */
1396 } /* for each operand */
1397 } /* if immediately wrong */
1403 opcode
= opcode
->m_next
;
1410 strcpy (buf
, "invalid instruction for this architecture; needs ");
1411 cp
= buf
+ strlen (buf
);
1421 strcpy (cp
, "68020 or higher");
1424 strcpy (cp
, "68000 or higher");
1427 strcpy (cp
, "68010 or higher");
1431 int got_one
= 0, idx
;
1432 const static struct {
1433 enum m68k_architecture arch
;
1444 for (idx
= 0; idx
< sizeof (archs
)/sizeof (archs
[0]); idx
++)
1446 if (archs
[idx
].arch
& ok_arch
)
1450 strcpy (cp
, " or ");
1454 strcpy (cp
, archs
[idx
].name
);
1466 the_ins
.error
= "operands mismatch";
1468 } /* Fell off the end */
1473 /* now assemble it */
1475 the_ins
.args
=opcode
->m_operands
;
1476 the_ins
.numargs
=opcode
->m_opnum
;
1477 the_ins
.numo
=opcode
->m_codenum
;
1478 the_ins
.opcode
[0]=getone(opcode
);
1479 the_ins
.opcode
[1]=gettwo(opcode
);
1481 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++) {
1482 /* This switch is a doozy.
1483 Watch the first step; its a big one! */
1501 tmpreg
=0x3c; /* 7.4 */
1502 if (strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1503 else nextword
=nextword
=get_num(opP
->con1
,0);
1504 if(isvar(opP
->con1
))
1505 add_fix(s
[1],opP
->con1
,0);
1508 if(!isbyte(nextword
))
1509 opP
->error
="operand out of range";
1514 if(!isword(nextword
))
1515 opP
->error
="operand out of range";
1520 addword(nextword
>>16);
1542 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1543 *s
, s
[1], __LINE__
, __FILE__
);
1548 /* We gotta put out some float */
1549 if(seg(opP
->con1
)!=SEG_BIG
) {
1550 int_to_gen(nextword
);
1551 gen_to_words(words
,baseo
,(long int)outro
);
1552 for(wordp
=words
;baseo
--;wordp
++)
1556 if(offs(opP
->con1
)>0) {
1557 as_warn("Bignum assumed to be binary bit-pattern");
1558 if(offs(opP
->con1
)>baseo
) {
1559 as_warn("Bignum too big for %c format; truncated",s
[1]);
1560 offs(opP
->con1
)=baseo
;
1562 baseo
-=offs(opP
->con1
);
1563 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1569 gen_to_words(words
,baseo
,(long)outro
);
1570 for (wordp
=words
;baseo
--;wordp
++)
1574 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1577 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1580 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1583 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1586 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1590 nextword
=get_num(opP
->con1
,80);
1591 /* Force into index mode. Hope this works */
1593 /* We do the first bit for 32-bit displacements,
1594 and the second bit for 16 bit ones. It is
1595 possible that we should make the default be
1596 WORD instead of LONG, but I think that'd
1597 break GCC, so we put up with a little
1598 inefficiency for the sake of working output.
1601 if( !issword(nextword
)
1602 || ( isvar(opP
->con1
)
1603 && ( ( opP
->con1
->e_siz
==0
1604 && flagseen
['l']==0)
1605 || opP
->con1
->e_siz
==3))) {
1608 tmpreg
=0x3B; /* 7.3 */
1610 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1611 if(isvar(opP
->con1
)) {
1613 add_frag(adds(opP
->con1
),
1615 TAB(PCLEA
,SZ_UNDEF
));
1619 add_fix('l',opP
->con1
,1);
1623 addword(nextword
>>16);
1626 tmpreg
=0x3A; /* 7.2 */
1628 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
1630 if(isvar(opP
->con1
)) {
1632 add_fix('w',opP
->con1
,1);
1634 add_fix('w',opP
->con1
,0);
1643 know(current_architecture
& m68020up
);
1644 /* intentional fall-through */
1647 baseo
=get_num(opP
->con1
,80);
1648 outro
=get_num(opP
->con2
,80);
1649 /* Figure out the 'addressing mode' */
1650 /* Also turn on the BASE_DISABLE bit, if needed */
1651 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1652 tmpreg
=0x3b; /* 7.3 */
1655 } else if(opP
->reg
==FAIL
) {
1657 tmpreg
=0x30; /* 6.garbage */
1658 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1660 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
1661 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
1663 /* Index register stuff */
1664 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
1665 nextword
|=(opP
->ireg
-DATA
)<<12;
1667 if(opP
->isiz
==0 || opP
->isiz
==3)
1671 case 2: nextword
|=0x200; break;
1672 case 4: nextword
|=0x400; break;
1673 case 8: nextword
|=0x600; break;
1674 default: as_fatal("failed sanity check.");
1677 GET US OUT OF HERE! */
1679 /* Must be INDEX, with an index
1680 register. Address register
1681 cannot be ZERO-PC, and either
1682 :b was forced, or we know
1684 if( opP
->mode
==AINDX
1689 && !isvar(opP
->con1
)))) {
1690 nextword
+=baseo
&0xff;
1692 if(isvar(opP
->con1
))
1693 add_fix('B',opP
->con1
,0);
1697 nextword
|=0x40; /* No index reg */
1699 /* It aint simple */
1701 /* If the guy specified a width, we assume that
1702 it is wide enough. Maybe it isn't. If so, we lose
1706 if(isvar(opP
->con1
) || !issword(baseo
)) {
1717 as_warn("Byte dispacement won't work. Defaulting to :w");
1726 /* Figure out innner displacement stuff */
1727 if(opP
->mode
!=AINDX
) {
1730 if(isvar(opP
->con2
) || !issword(outro
)) {
1741 as_warn("Byte dispacement won't work. Defaulting to :w");
1749 if(opP
->mode
==APODX
) nextword
|=0x04;
1750 else if(opP
->mode
==AMIND
) nextword
|=0x40;
1754 if(isvar(opP
->con1
)) {
1755 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1756 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
1757 opP
->con1
->e_exp
.X_add_number
+=6;
1759 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
1766 if(isvar(opP
->con2
)) {
1767 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1768 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
1769 opP
->con1
->e_exp
.X_add_number
+=6;
1771 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
1781 nextword
=get_num(opP
->con1
,80);
1782 switch(opP
->con1
->e_siz
) {
1784 as_warn("Unknown size for absolute reference");
1786 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
1787 tmpreg
=0x38; /* 7.0 */
1791 /* Don't generate pc relative code
1792 on 68010 and 68000 */
1795 && seg(opP
->con1
) == SEG_TEXT
1796 && now_seg
== SEG_TEXT
1797 && cpu_of_arch(current_architecture
) >= m68020
1799 && !strchr("~%&$?", s
[0])) {
1800 tmpreg
=0x3A; /* 7.2 */
1801 add_frag(adds(opP
->con1
),
1803 TAB(PCREL
,SZ_UNDEF
));
1806 case 3: /* Fall through into long */
1807 if(isvar(opP
->con1
))
1808 add_fix('l',opP
->con1
,0);
1810 tmpreg
=0x39; /* 7.1 mode */
1811 addword(nextword
>>16);
1816 if(isvar(opP
->con1
))
1817 add_fix('w',opP
->con1
,0);
1819 tmpreg
=0x38; /* 7.0 mode */
1825 as_bad("invalid indirect register");
1829 as_bad("unknown/incorrect operand");
1832 install_gen_operand(s
[1],tmpreg
);
1837 switch(s
[1]) { /* JF: I hate floating point! */
1852 tmpreg
=get_num(opP
->con1
,tmpreg
);
1853 if(isvar(opP
->con1
))
1854 add_fix(s
[1],opP
->con1
,0);
1856 case 'b': /* Danger: These do no check for
1857 certain types of overflow.
1860 opP
->error
="out of range";
1862 if(isvar(opP
->con1
))
1863 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1867 opP
->error
="out of range";
1869 if(isvar(opP
->con1
))
1870 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1873 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
1875 if(isvar(opP
->con1
))
1876 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1882 install_operand(s
[1],tmpreg
);
1885 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
1893 install_operand(s
[1],opP
->reg
-ADDR
);
1897 tmpreg
=get_num(opP
->con1
,80);
1900 /* Needs no offsetting */
1901 add_fix('B',opP
->con1
,1);
1904 /* Offset the displacement to be relative to byte disp location */
1905 opP
->con1
->e_exp
.X_add_number
+=2;
1906 add_fix('w',opP
->con1
,1);
1911 if (cpu_of_arch(current_architecture
) < m68020
) /* 68000 or 010 */
1912 as_warn("Can't use long branches on 68000/68010");
1913 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
1914 /* Offset the displacement to be relative to byte disp location */
1915 opP
->con1
->e_exp
.X_add_number
+=4;
1916 add_fix('l',opP
->con1
,1);
1921 if(subs(opP
->con1
)) /* We can't relax it */
1924 /* This could either be a symbol, or an
1925 absolute address. No matter, the
1926 frag hacking will finger it out.
1927 Not quite: it can't switch from
1928 BRANCH to BCC68000 for the case
1929 where opnd is absolute (it needs
1930 to use the 68000 hack since no
1931 conditional abs jumps). */
1932 if (((cpu_of_arch(current_architecture
) < m68020
) || (0==adds(opP
->con1
)))
1933 && (the_ins
.opcode
[0] >= 0x6200)
1934 && (the_ins
.opcode
[0] <= 0x6f00)) {
1935 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
1937 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BRANCH
,SZ_UNDEF
));
1941 if(isvar(opP
->con1
)) {
1942 /* check for DBcc instruction */
1943 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
1944 /* size varies if patch */
1945 /* needed for long form */
1946 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
1951 opP
->con1
->e_exp
.X_add_number
+=2;
1952 add_fix('w',opP
->con1
,1);
1956 case 'C': /* Fixed size LONG coproc branches */
1957 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1958 /* Offset the displacement to be relative to byte disp location */
1959 /* Coproc branches don't have a byte disp option, but they are
1960 compatible with the ordinary branches, which do... */
1961 opP
->con1
->e_exp
.X_add_number
+=4;
1962 add_fix('l',opP
->con1
,1);
1966 case 'c': /* Var size Coprocesssor branches */
1967 if(subs(opP
->con1
)) {
1968 add_fix('l',opP
->con1
,1);
1969 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
1970 } else if(adds(opP
->con1
)) {
1971 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
1973 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
1974 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1975 add_fix('l',opP
->con1
,1);
1981 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
1982 s
[1], __LINE__
, __FILE__
);
1986 case 'C': /* Ignore it */
1989 case 'd': /* JF this is a kludge */
1990 if(opP
->mode
==AOFF
) {
1991 install_operand('s',opP
->reg
-ADDR
);
1995 tmpP
=opP
->con1
->e_end
-2;
1997 opP
->con1
->e_end
-=4; /* point to the , */
1998 baseo
=m68k_reg_parse(&tmpP
);
1999 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
2000 as_bad("Unknown address reg, using A0");
2003 install_operand('s',baseo
);
2005 tmpreg
=get_num(opP
->con1
,80);
2006 if(!issword(tmpreg
)) {
2007 as_warn("Expression out of range, using 0");
2014 install_operand(s
[1],opP
->reg
-DATA
);
2018 install_operand(s
[1],opP
->reg
-FPREG
);
2022 tmpreg
=1+opP
->reg
-COPNUM
;
2025 install_operand(s
[1],tmpreg
);
2028 case 'J': /* JF foo */
2030 case SFC
: tmpreg
=0x000; break;
2031 case DFC
: tmpreg
=0x001; break;
2032 case CACR
: tmpreg
=0x002; break;
2033 case TC
: tmpreg
=0x003; break;
2034 case ITT0
: tmpreg
=0x004; break;
2035 case ITT1
: tmpreg
=0x005; break;
2036 case DTT0
: tmpreg
=0x006; break;
2037 case DTT1
: tmpreg
=0x007; break;
2039 case USP
: tmpreg
=0x800; break;
2040 case VBR
: tmpreg
=0x801; break;
2041 case CAAR
: tmpreg
=0x802; break;
2042 case MSP
: tmpreg
=0x803; break;
2043 case ISP
: tmpreg
=0x804; break;
2044 case MMUSR
: tmpreg
=0x805; break;
2045 case URP
: tmpreg
=0x806; break;
2046 case SRP
: tmpreg
=0x807; break;
2048 as_fatal("failed sanity check.");
2050 install_operand(s
[1],tmpreg
);
2054 tmpreg
=get_num(opP
->con1
,55);
2055 install_operand(s
[1],tmpreg
&0x7f);
2061 if(tmpreg
&0x7FF0000)
2062 as_bad("Floating point register in register list");
2063 insop(reverse_16_bits(tmpreg
));
2065 if(tmpreg
&0x700FFFF)
2066 as_bad("Wrong register in floating-point reglist");
2067 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
2074 if(tmpreg
&0x7FF0000)
2075 as_bad("Floating point register in register list");
2077 } else if(s
[1]=='8') {
2078 if(tmpreg
&0x0FFFFFF)
2079 as_bad("incorrect register in reglist");
2080 install_operand(s
[1],tmpreg
>>24);
2082 if(tmpreg
&0x700FFFF)
2083 as_bad("wrong register in floating-point reglist");
2085 install_operand(s
[1],tmpreg
>>16);
2090 install_operand(s
[1],get_num(opP
->con1
,60));
2094 tmpreg
= (opP
->mode
==DREG
)
2095 ? 0x20+opP
->reg
-DATA
2096 : (get_num(opP
->con1
,40)&0x1F);
2097 install_operand(s
[1],tmpreg
);
2101 tmpreg
=get_num(opP
->con1
,10);
2104 install_operand(s
[1],tmpreg
);
2109 /* This depends on the fact that ADDR registers are
2110 eight more than their corresponding DATA regs, so
2111 the result will have the ADDR_REG bit set */
2112 install_operand(s
[1],opP
->reg
-DATA
);
2116 if(opP
->reg
==FPI
) tmpreg
=0x1;
2117 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2118 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2119 else as_fatal("failed sanity check.");
2120 install_operand(s
[1],tmpreg
);
2123 case 'S': /* Ignore it */
2127 install_operand(s
[1],get_num(opP
->con1
,30));
2130 case 'U': /* Ignore it */
2135 case NC
: tmpreg
= 0; break;
2136 case DC
: tmpreg
= 1; break;
2137 case IC
: tmpreg
= 2; break;
2138 case BC
: tmpreg
= 3; break;
2140 as_fatal("failed sanity check");
2141 } /* switch on cache token */
2142 install_operand(s
[1], tmpreg
);
2145 /* JF: These are out of order, I fear. */
2155 as_fatal("failed sanity check.");
2157 install_operand(s
[1],tmpreg
);
2178 as_fatal("failed sanity check.");
2180 install_operand(s
[1],tmpreg
);
2184 if (opP
->reg
== VAL
)
2186 as_fatal("failed sanity check.");
2201 as_fatal("failed sanity check.");
2203 install_operand(s
[1],tmpreg
);
2208 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2209 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2210 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2213 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2214 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2215 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2219 as_fatal("failed sanity check.");
2221 install_operand(s
[1], tmpreg
);
2224 know(opP
->reg
== PSR
);
2227 know(opP
->reg
== PCSR
);
2231 tmpreg
=get_num(opP
->con1
,80);
2232 install_operand(s
[1], tmpreg
);
2235 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s
[0], __LINE__
, __FILE__
);
2238 /* By the time whe get here (FINALLY) the_ins contains the complete
2239 instruction, ready to be emitted. . . */
2243 * get_regs := '/' + ?
2244 * | '-' + <register>
2245 * | '-' + <register> + ?
2250 * The idea here must be to scan in a set of registers but I don't
2251 * understand it. Looks awfully sloppy to me but I don't have any doc on
2258 static int get_regs(i
,str
,opP
)
2260 struct m68k_op
*opP
;
2263 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2264 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2265 unsigned long cur_regs
= 0;
2269 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2270 else if(x==FPS) cur_regs|=(1<<25);\
2271 else if(x==FPC) cur_regs|=(1<<26);\
2272 else cur_regs|=(1<<(x-1)); }
2279 } else if(*str
=='-') {
2281 reg2
=m68k_reg_parse(&str
);
2282 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2283 opP
->error
="unknown register in register list";
2292 } else if(*str
=='\0') {
2296 opP
->error
="unknow character in register list";
2299 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2302 reg1
=m68k_reg_parse(&str
);
2303 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2304 opP
->error
="unknown register in register list";
2312 static int reverse_16_bits(in
)
2318 static int mask
[16] = {
2319 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2320 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2327 } /* reverse_16_bits() */
2329 static int reverse_8_bits(in
)
2335 static int mask
[8] = {
2336 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2344 } /* reverse_8_bits() */
2346 static void install_operand(mode
,val
)
2352 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2355 the_ins
.opcode
[0]|=val
<<9;
2358 the_ins
.opcode
[1]|=val
<<12;
2361 the_ins
.opcode
[1]|=val
<<6;
2364 the_ins
.opcode
[1]|=val
;
2367 the_ins
.opcode
[2]|=val
<<12;
2370 the_ins
.opcode
[2]|=val
<<6;
2373 /* DANGER! This is a hack to force cas2l and cas2w cmds
2374 to be three words long! */
2376 the_ins
.opcode
[2]|=val
;
2379 the_ins
.opcode
[1]|=val
<<7;
2382 the_ins
.opcode
[1]|=val
<<10;
2386 the_ins
.opcode
[1]|=val
<<5;
2391 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2394 the_ins
.opcode
[1]|=(val
<<12)|val
;
2397 the_ins
.opcode
[0]|=val
=0xff;
2400 the_ins
.opcode
[0]|=val
<<9;
2403 the_ins
.opcode
[1]|=val
;
2406 the_ins
.opcode
[1]|=val
;
2407 the_ins
.numo
++; /* What a hack */
2410 the_ins
.opcode
[1]|=val
<<4;
2417 the_ins
.opcode
[0] |= (val
<< 6);
2420 the_ins
.opcode
[1] = (val
>> 16);
2421 the_ins
.opcode
[2] = val
& 0xffff;
2425 as_fatal("failed sanity check.");
2427 } /* install_operand() */
2429 static void install_gen_operand(mode
,val
)
2435 the_ins
.opcode
[0]|=val
;
2438 /* This is a kludge!!! */
2439 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2448 the_ins
.opcode
[0]|=val
;
2450 /* more stuff goes here */
2452 as_fatal("failed sanity check.");
2454 } /* install_gen_operand() */
2457 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2458 * then deal with the bitfield hack.
2461 static char *crack_operand(str
,opP
)
2463 register struct m68k_op
*opP
;
2465 register int parens
;
2467 register char *beg_str
;
2473 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2474 if(*str
=='(') parens
++;
2475 else if(*str
==')') {
2476 if(!parens
) { /* ERROR */
2477 opP
->error
="Extra )";
2483 if(!*str
&& parens
) { /* ERROR */
2484 opP
->error
="Missing )";
2489 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2495 c
= *++str
; /* JF bitfield hack */
2499 as_bad("Missing operand");
2504 /* See the comment up above where the #define notend(... is */
2509 if(*s
==',') return 0;
2510 if(*s
=='{' || *s
=='}')
2512 if(*s
!=':') return 1;
2513 /* This kludge here is for the division cmd, which is a kludge */
2514 if(index("aAdD#",s
[1])) return 0;
2519 /* This is the guts of the machine-dependent assembler. STR points to a
2520 machine dependent instruction. This function is supposed to emit
2521 the frags/bytes it assembles to.
2525 insert_reg(regname
, regnum
)
2531 symbol_table_insert(symbol_new(regname
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2533 for (i
= 0; regname
[i
]; i
++)
2534 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2537 symbol_table_insert(symbol_new(buf
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2654 for (i
= 0; init_table
[i
].name
; i
++)
2656 insert_reg(init_table
[i
].name
, init_table
[i
].number
);
2670 int shorts_this_frag
;
2673 if (cpu_of_arch (current_architecture
) == 0)
2675 enum m68k_architecture cpu_type
;
2680 if (strcmp (TARGET_CPU
, "m68000") == 0)
2682 else if (strcmp (TARGET_CPU
, "m68010") == 0)
2684 else if (strcmp (TARGET_CPU
, "m68020") == 0
2685 || strcmp (TARGET_CPU
, "m68k") == 0)
2687 else if (strcmp (TARGET_CPU
, "m68030") == 0)
2689 else if (strcmp (TARGET_CPU
, "m68040") == 0)
2695 /* If float or mmu were specified, just default cpu. */
2696 if (current_architecture
!= 0)
2697 current_architecture
|= cpu_type
;
2700 if ((cpu_type
& m68020up
) != 0)
2701 current_architecture
= (cpu_type
2710 current_architecture
= cpu_type
;
2714 memset((char *)(&the_ins
), '\0', sizeof(the_ins
)); /* JF for paranoia sake */
2718 for(n
=the_ins
.numargs
;n
;--n
)
2719 if(the_ins
.operands
[n
].error
) {
2720 er
=the_ins
.operands
[n
].error
;
2725 as_bad("%s -- statement `%s' ignored",er
,str
);
2729 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
2730 toP
=frag_more(2*the_ins
.numo
);
2731 fromP
= &the_ins
.opcode
[0];
2732 for(m
=the_ins
.numo
;m
;--m
) {
2733 md_number_to_chars(toP
,(long)(*fromP
),2);
2737 /* put out symbol-dependent info */
2738 for(m
=0;m
<the_ins
.nrel
;m
++) {
2739 switch(the_ins
.reloc
[m
].wid
) {
2756 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
2760 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2762 the_ins
.reloc
[m
].add
,
2763 the_ins
.reloc
[m
].sub
,
2764 the_ins
.reloc
[m
].off
,
2765 the_ins
.reloc
[m
].pcrel
,
2771 /* There's some frag hacking */
2772 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
2775 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
2776 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2780 for(m
=wid
/2;m
;--m
) {
2781 md_number_to_chars(toP
,(long)(*fromP
),2);
2786 for(m
=0;m
<the_ins
.nrel
;m
++) {
2787 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
2788 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
2791 wid
=the_ins
.reloc
[m
].wid
;
2794 the_ins
.reloc
[m
].wid
=0;
2795 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2798 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2800 the_ins
.reloc
[m
].add
,
2801 the_ins
.reloc
[m
].sub
,
2802 the_ins
.reloc
[m
].off
,
2803 the_ins
.reloc
[m
].pcrel
,
2806 /* know(the_ins.fragb[n].fadd); */
2807 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
2808 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
2810 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2813 toP
=frag_more(n
*sizeof(short));
2815 md_number_to_chars(toP
,(long)(*fromP
),2);
2821 for(m
=0;m
<the_ins
.nrel
;m
++) {
2824 wid
=the_ins
.reloc
[m
].wid
;
2827 the_ins
.reloc
[m
].wid
=0;
2828 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2831 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
2833 the_ins
.reloc
[m
].add
,
2834 the_ins
.reloc
[m
].sub
,
2835 the_ins
.reloc
[m
].off
,
2836 the_ins
.reloc
[m
].pcrel
,
2849 * md_begin -- set up hash tables with 68000 instructions.
2850 * similar to what the vax assembler does. ---phr
2852 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2853 a copy of it at runtime, adding in the information we want but isn't
2854 there. I think it'd be better to have an awk script hack the table
2855 at compile time. Or even just xstr the table and use it as-is. But
2856 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2859 register const struct m68k_opcode
*ins
;
2860 register struct m68k_incant
*hack
,
2862 register char *retval
= 0; /* empty string, or error msg text */
2863 register unsigned int i
;
2866 if ((op_hash
= hash_new()) == NULL
)
2867 as_fatal("Virtual memory exhausted");
2869 obstack_begin(&robyn
,4000);
2870 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
2871 hack
=slak
=(struct m68k_incant
*)obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2873 /* we *could* ignore insns that don't match our
2874 arch here but just leaving them out of the
2876 slak
->m_operands
=ins
->args
;
2877 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
2878 slak
->m_arch
= ins
->arch
;
2879 slak
->m_opcode
=ins
->opcode
;
2880 /* This is kludgey */
2881 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
2882 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
2883 slak
->m_next
=(struct m68k_incant
*) obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2890 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
2891 /* Didn't his mommy tell him about null pointers? */
2892 if(retval
&& *retval
)
2893 as_fatal("Internal Error: Can't hash %s: %s",ins
->name
,retval
);
2896 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
2897 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
2899 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
2900 notend_table
[i
] = 0;
2901 alt_notend_table
[i
] = 0;
2903 notend_table
[','] = 1;
2904 notend_table
['{'] = 1;
2905 notend_table
['}'] = 1;
2906 alt_notend_table
['a'] = 1;
2907 alt_notend_table
['A'] = 1;
2908 alt_notend_table
['d'] = 1;
2909 alt_notend_table
['D'] = 1;
2910 alt_notend_table
['#'] = 1;
2911 alt_notend_table
['f'] = 1;
2912 alt_notend_table
['F'] = 1;
2913 #ifdef REGISTER_PREFIX
2914 alt_notend_table
[REGISTER_PREFIX
] = 1;
2921 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2922 || (*s == ':' && strchr("aAdD#", s[1]))) \
2926 /* This funciton is called once, before the assembler exits. It is
2927 supposed to do any final cleanup for this part of the assembler.
2934 /* Equal to MAX_PRECISION in atof-ieee.c */
2935 #define MAX_LITTLENUMS 6
2937 /* Turn a string in input_line_pointer into a floating point constant of type
2938 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2939 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2942 md_atof(type
,litP
,sizeP
)
2948 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2949 LITTLENUM_TYPE
*wordP
;
2980 return "Bad call to MD_ATOF()";
2982 t
=atof_ieee(input_line_pointer
,type
,words
);
2984 input_line_pointer
=t
;
2986 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
2987 for(wordP
=words
;prec
--;) {
2988 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
2989 litP
+=sizeof(LITTLENUM_TYPE
);
2991 return ""; /* Someone should teach Dean about null pointers */
2994 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2995 for use in the a.out file, and stores them in the array pointed to by buf.
2996 This knows about the endian-ness of the target machine and does
2997 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2998 2 (short) and 4 (long) Floating numbers are put out as a series of
2999 LITTLENUMS (shorts, here at least)
3002 md_number_to_chars(buf
,val
,n
)
3022 as_fatal("failed sanity check.");
3027 md_apply_fix(fixP
, val
)
3031 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3033 switch(fixP
->fx_size
) {
3048 BAD_CASE (fixP
->fx_size
);
3053 /* *fragP has been relaxed to its final size, and now needs to have
3054 the bytes inside it modified to conform to the new size There is UGLY
3058 md_convert_frag(headers
, fragP
)
3059 object_headers
*headers
;
3060 register fragS
*fragP
;
3065 /* Address in object code of the displacement. */
3066 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
3068 #ifdef IBM_COMPILER_SUX
3069 /* This is wrong but it convinces the native rs6000 compiler to
3070 generate the code we want. */
3071 register char *buffer_address
= fragP
-> fr_literal
;
3072 buffer_address
+= fragP
-> fr_fix
;
3073 #else /* IBM_COMPILER_SUX */
3074 /* Address in gas core of the place to store the displacement. */
3075 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3076 #endif /* IBM_COMPILER_SUX */
3078 /* No longer true: know(fragP->fr_symbol); */
3080 /* The displacement of the address, from current location. */
3081 disp
= fragP
->fr_symbol
? S_GET_VALUE(fragP
->fr_symbol
) : 0;
3082 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3084 switch(fragP
->fr_subtype
) {
3085 case TAB(BCC68000
,BYTE
):
3086 case TAB(BRANCH
,BYTE
):
3087 know(issbyte(disp
));
3089 as_bad("short branch with zero offset: use :w");
3090 fragP
->fr_opcode
[1]=disp
;
3093 case TAB(DBCC
,SHORT
):
3094 know(issword(disp
));
3097 case TAB(BCC68000
,SHORT
):
3098 case TAB(BRANCH
,SHORT
):
3099 know(issword(disp
));
3100 fragP
->fr_opcode
[1]=0x00;
3103 case TAB(BRANCH
,LONG
):
3104 if (cpu_of_arch(current_architecture
) < m68020
) {
3105 if (fragP
->fr_opcode
[0]==0x61) {
3106 fragP
->fr_opcode
[0]= 0x4E;
3107 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3108 subseg_change(SEG_TEXT
, 0);
3121 } else if (fragP
->fr_opcode
[0]==0x60) {
3122 fragP
->fr_opcode
[0]= 0x4E;
3123 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3124 subseg_change(SEG_TEXT
, 0);
3125 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
3130 as_bad("Long branch offset not supported.");
3133 fragP
->fr_opcode
[1]=0xff;
3137 case TAB(BCC68000
,LONG
):
3138 /* only Bcc 68000 instructions can come here */
3139 /* change bcc into b!cc/jmp absl long */
3140 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3141 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
3143 /* JF: these used to be fr_opcode[2,3], but they may be in a
3144 different frag, in which case refering to them is a no-no.
3145 Only fr_opcode[0,1] are guaranteed to work. */
3146 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3147 *buffer_address
++ = 0xf9;
3148 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3149 subseg_change(SEG_TEXT
,0);
3150 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3156 case TAB(DBCC
,LONG
):
3157 /* only DBcc 68000 instructions can come here */
3158 /* change dbcc into dbcc/jmp absl long */
3159 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3160 *buffer_address
++ = 0x00; /* branch offset = 4 */
3161 *buffer_address
++ = 0x04;
3162 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3163 *buffer_address
++ = 0x06;
3164 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3165 *buffer_address
++ = 0xf9;
3167 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3168 subseg_change(SEG_TEXT
,0);
3169 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3175 case TAB(FBRANCH
,SHORT
):
3176 know((fragP
->fr_opcode
[1]&0x40)==0);
3179 case TAB(FBRANCH
,LONG
):
3180 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
3183 case TAB(PCREL
,SHORT
):
3186 case TAB(PCREL
,LONG
):
3187 /* The thing to do here is force it to ABSOLUTE LONG, since
3188 PCREL is really trying to shorten an ABSOLUTE address anyway */
3189 /* JF FOO This code has not been tested */
3190 subseg_change(SEG_TEXT
,0);
3191 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3192 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3193 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3194 fragP
->fr_opcode
[0],fragP
->fr_address
);
3195 fragP
->fr_opcode
[1]&= ~0x3F;
3196 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
3198 /* md_number_to_chars(buffer_address,
3199 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3203 case TAB(PCLEA
,SHORT
):
3204 subseg_change(SEG_TEXT
,0);
3205 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
3207 fragP
->fr_opcode
[1] &= ~0x3F;
3208 fragP
->fr_opcode
[1] |= 0x3A;
3211 case TAB(PCLEA
,LONG
):
3212 subseg_change(SEG_TEXT
,0);
3213 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
3215 *buffer_address
++ = 0x01;
3216 *buffer_address
++ = 0x70;
3218 /* buffer_address+=2; */
3222 } /* switch on subtype */
3225 md_number_to_chars(buffer_address
, (long) disp
, (int) ext
);
3226 fragP
->fr_fix
+= ext
;
3227 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3228 } /* if extending */
3231 } /* md_convert_frag() */
3233 /* Force truly undefined symbols to their maximum size, and generally set up
3234 the frag list to be relaxed
3236 int md_estimate_size_before_relax(fragP
, segment
)
3237 register fragS
*fragP
;
3241 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3243 old_fix
= fragP
->fr_fix
;
3245 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3246 switch (fragP
->fr_subtype
) {
3248 case TAB(BRANCH
,SZ_UNDEF
): {
3249 if((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3250 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3251 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
3253 } else if((fragP
->fr_symbol
== 0) || (cpu_of_arch(current_architecture
) < m68020
)) {
3254 /* On 68000, or for absolute value, switch to abs long */
3255 /* FIXME, we should check abs val, pick short or long */
3256 if(fragP
->fr_opcode
[0]==0x61) {
3257 fragP
->fr_opcode
[0]= 0x4E;
3258 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3259 subseg_change(SEG_TEXT
, 0);
3260 fix_new(fragP
, fragP
->fr_fix
, 4,
3261 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3264 } else if(fragP
->fr_opcode
[0]==0x60) {
3265 fragP
->fr_opcode
[0]= 0x4E;
3266 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3267 subseg_change(SEG_TEXT
, 0);
3268 fix_new(fragP
, fragP
->fr_fix
, 4,
3269 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3273 as_warn("Long branch offset to extern symbol not supported.");
3275 } else { /* Symbol is still undefined. Make it simple */
3276 fix_new(fragP
, (int)(fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3277 (symbolS
*)0, fragP
->fr_offset
+4, 1, NO_RELOC
);
3279 fragP
->fr_opcode
[1]=0xff;
3285 } /* case TAB(BRANCH,SZ_UNDEF) */
3287 case TAB(FBRANCH
,SZ_UNDEF
): {
3288 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3289 fragP
->fr_subtype
= TAB(FBRANCH
,SHORT
);
3292 fragP
->fr_subtype
= TAB(FBRANCH
,LONG
);
3296 } /* TAB(FBRANCH,SZ_UNDEF) */
3298 case TAB(PCREL
,SZ_UNDEF
): {
3299 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3300 fragP
->fr_subtype
= TAB(PCREL
,SHORT
);
3303 fragP
->fr_subtype
= TAB(PCREL
,LONG
);
3307 } /* TAB(PCREL,SZ_UNDEF) */
3309 case TAB(BCC68000
,SZ_UNDEF
): {
3310 if((fragP
->fr_symbol
!= NULL
)
3311 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3312 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
3315 /* only Bcc 68000 instructions can come here */
3316 /* change bcc into b!cc/jmp absl long */
3317 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3319 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3320 /* JF: these were fr_opcode[2,3] */
3321 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3322 buffer_address
[1] = 0xf8;
3323 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3324 subseg_change(SEG_TEXT
,0);
3325 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3326 fragP
->fr_offset
, 0, NO_RELOC
);
3329 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3330 /* JF: these were fr_opcode[2,3] */
3331 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3332 buffer_address
[1] = 0xf9;
3333 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3334 subseg_change(SEG_TEXT
,0);
3335 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3336 fragP
->fr_offset
, 0, NO_RELOC
);
3341 } /* case TAB(BCC68000,SZ_UNDEF) */
3343 case TAB(DBCC
,SZ_UNDEF
): {
3344 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3345 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3349 /* only DBcc 68000 instructions can come here */
3350 /* change dbcc into dbcc/jmp absl long */
3351 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3352 buffer_address
[0] = 0x00; /* branch offset = 4 */
3353 buffer_address
[1] = 0x04;
3354 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3357 /* JF: these were fr_opcode[5-7] */
3358 buffer_address
[3] = 0x04; /* plus 4 */
3359 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3360 buffer_address
[5] = 0xf8;
3361 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3362 subseg_change(SEG_TEXT
,0);
3363 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3366 fragP
->fr_offset
, 0, NO_RELOC
);
3369 /* JF: these were fr_opcode[5-7] */
3370 buffer_address
[3] = 0x06; /* Plus 6 */
3371 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3372 buffer_address
[5] = 0xf9;
3373 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3374 subseg_change(SEG_TEXT
,0);
3375 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3376 fragP
->fr_offset
, 0, NO_RELOC
);
3382 } /* case TAB(DBCC,SZ_UNDEF) */
3384 case TAB(PCLEA
,SZ_UNDEF
): {
3385 if ((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3386 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3389 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3393 } /* TAB(PCLEA,SZ_UNDEF) */
3398 } /* switch on subtype looking for SZ_UNDEF's. */
3400 /* now that SZ_UNDEF are taken care of, check others */
3401 switch (fragP
->fr_subtype
) {
3402 case TAB(BCC68000
,BYTE
):
3403 case TAB(BRANCH
,BYTE
):
3404 /* We can't do a short jump to the next instruction,
3405 so we force word mode. */
3406 if (fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3407 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3408 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3415 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3418 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3419 /* the bit-field entries in the relocation_info struct plays hell
3420 with the byte-order problems of cross-assembly. So as a hack,
3421 I added this mach. dependent ri twiddler. Ugly, but it gets
3423 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3424 are symbolnum, most sig. byte first. Last byte is broken up with
3425 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3426 nibble as nuthin. (on Sun 3 at least) */
3427 /* Translate the internal relocation information into target-specific
3431 md_ri_to_chars(the_bytes
, ri
)
3433 struct reloc_info_generic
*ri
;
3436 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3437 /* now the fun stuff */
3438 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3439 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3440 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3441 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3442 ((ri
->r_extern
<< 4) & 0x10));
3444 #endif /* comment */
3446 void tc_aout_fix_to_chars(where
, fixP
, segment_address_in_file
)
3449 relax_addressT segment_address_in_file
;
3452 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3453 * Out: GNU LD relocation length code: 0, 1, or 2.
3456 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
3459 know(fixP
->fx_addsy
!= NULL
);
3461 md_number_to_chars(where
,
3462 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3465 r_symbolnum
= (S_IS_DEFINED(fixP
->fx_addsy
)
3466 ? S_GET_TYPE(fixP
->fx_addsy
)
3467 : fixP
->fx_addsy
->sy_number
);
3469 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3470 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3471 where
[6] = r_symbolnum
& 0x0ff;
3472 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3473 (((!S_IS_DEFINED(fixP
->fx_addsy
)) << 4) & 0x10));
3476 } /* tc_aout_fix_to_chars() */
3478 #endif /* OBJ_AOUT or OBJ_BOUT */
3480 #ifndef WORKING_DOT_WORD
3481 const int md_short_jump_size
= 4;
3482 const int md_long_jump_size
= 6;
3485 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3494 offset
= to_addr
- (from_addr
+2);
3496 md_number_to_chars(ptr
,(long)0x6000,2);
3497 md_number_to_chars(ptr
+2,(long)offset
,2);
3501 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3510 if (cpu_of_arch(current_architecture
) < m68020
) {
3511 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3512 md_number_to_chars(ptr
,(long)0x4EF9,2);
3513 md_number_to_chars(ptr
+2,(long)offset
,4);
3514 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3517 offset
=to_addr
- (from_addr
+2);
3518 md_number_to_chars(ptr
,(long)0x60ff,2);
3519 md_number_to_chars(ptr
+2,(long)offset
,4);
3524 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3527 10: Absolute 1:8 only
3528 20: Absolute 0:7 only
3529 30: absolute 0:15 only
3530 40: Absolute 0:31 only
3531 50: absolute 0:127 only
3532 55: absolute -64:63 only
3533 60: absolute -128:127 only
3534 70: absolute 0:4095 only
3539 static int get_num(exp
,ok
)
3540 struct m68k_exp
*exp
;
3548 if(*exp
->e_beg
=='0') {
3549 if(exp
->e_beg
[1]=='x')
3550 sscanf(exp
->e_beg
+2,"%x",&l
);
3552 sscanf(exp
->e_beg
+1,"%O",&l
);
3555 return atol(exp
->e_beg
);
3561 /* Can't do anything */
3564 if(!exp
->e_beg
|| !exp
->e_end
) {
3565 seg(exp
)=SEG_ABSOLUTE
;
3568 offs(exp
)= (ok
==10) ? 1 : 0;
3569 as_warn("Null expression defaults to %ld",offs(exp
));
3574 if(/* ok!=80 && */exp
->e_end
[-1]==':' && (exp
->e_end
-exp
->e_beg
)>=2) {
3575 switch(exp
->e_end
[0]) {
3591 as_bad("Unknown size for expression \"%c\"",exp
->e_end
[0]);
3595 c_save
=exp
->e_end
[1];
3597 save_in
=input_line_pointer
;
3598 input_line_pointer
=exp
->e_beg
;
3599 switch(expression(&(exp
->e_exp
))) {
3601 seg(exp
)=SEG_ABSOLUTE
;
3604 offs(exp
)= (ok
==10) ? 1 : 0;
3605 as_warn("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
3609 /* Do the same thing the VAX asm does */
3610 seg(exp
)=SEG_ABSOLUTE
;
3615 as_warn("expression out of range: defaulting to 1");
3622 if(offs(exp
)<1 || offs(exp
)>8) {
3623 as_warn("expression out of range: defaulting to 1");
3628 if(offs(exp
)<0 || offs(exp
)>7)
3632 if(offs(exp
)<0 || offs(exp
)>15)
3636 if(offs(exp
)<0 || offs(exp
)>32)
3640 if(offs(exp
)<0 || offs(exp
)>127)
3644 if(offs(exp
)<-64 || offs(exp
)>63)
3648 if(offs(exp
)<-128 || offs(exp
)>127)
3652 if(offs(exp
)<0 || offs(exp
)>4095) {
3654 as_warn("expression out of range: defaulting to 0");
3666 case SEG_DIFFERENCE
:
3667 if(ok
>=10 && ok
<=70) {
3668 seg(exp
)=SEG_ABSOLUTE
;
3671 offs(exp
)= (ok
==10) ? 1 : 0;
3672 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3676 if(ok
==80 && offs(exp
)<0) { /* HACK! Turn it into a long */
3677 LITTLENUM_TYPE words
[6];
3679 gen_to_words(words
,2,8L);/* These numbers are magic! */
3680 seg(exp
)=SEG_ABSOLUTE
;
3683 offs(exp
)=words
[1]|(words
[0]<<16);
3685 seg(exp
)=SEG_ABSOLUTE
;
3688 offs(exp
)= (ok
==10) ? 1 : 0;
3689 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3693 as_fatal("failed sanity check.");
3695 if(input_line_pointer
!=exp
->e_end
+1)
3696 as_bad("Ignoring junk after expression");
3697 exp
->e_end
[1]=c_save
;
3698 input_line_pointer
=save_in
;
3700 switch(exp
->e_siz
) {
3702 if(!isbyte(offs(exp
)))
3703 as_warn("expression doesn't fit in BYTE");
3706 if(!isword(offs(exp
)))
3707 as_warn("expression doesn't fit in WORD");
3715 /* These are the back-ends for the various machine dependent pseudo-ops. */
3716 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
3718 static void s_data1() {
3719 subseg_new(SEG_DATA
,1);
3720 demand_empty_rest_of_line();
3723 static void s_data2() {
3724 subseg_new(SEG_DATA
,2);
3725 demand_empty_rest_of_line();
3730 /* We don't support putting frags in the BSS segment, we fake it
3731 by marking in_bss, then looking at s_skip for clues */
3733 subseg_new(SEG_BSS
, 0);
3734 demand_empty_rest_of_line();
3737 static void s_even() {
3739 register long temp_fill
;
3741 temp
= 1; /* JF should be 2? */
3742 temp_fill
= get_absolute_expression ();
3743 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
3744 frag_align (temp
, (int)temp_fill
);
3745 demand_empty_rest_of_line();
3748 static void s_proc() {
3749 demand_empty_rest_of_line();
3752 /* s_space is defined in read.c .skip is simply an alias to it. */
3756 * Invocation line includes a switch not recognized by the base assembler.
3757 * See if it's a processor-specific option. These are:
3759 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3760 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3761 * Select the architecture. Instructions or features not
3762 * supported by the selected architecture cause fatal
3763 * errors. More than one may be specified. The default is
3764 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3765 * for -m68000, and -m68882 is a synonym for -m68881.
3767 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
3768 * (e.g. m68020) also requests that float instructions be included. This
3769 * is the default setup, mostly to avoid hassling users. A better
3770 * rearrangement of this structure would be to add an option to DENY
3771 * floating point opcodes, for people who want to really know there's none
3772 * of that funny floaty stuff going on. FIXME-later.
3774 #ifndef MAYBE_FLOAT_TOO
3775 #define MAYBE_FLOAT_TOO m68881
3778 int md_parse_option(argP
,cntP
,vecP
)
3784 case 'l': /* -l means keep external to 2 bit offset
3785 rather than 16 bit one */
3788 case 'S': /* -S means that jbsr's always turn into jsr's. */
3793 /* intentional fall-through */
3799 } /* allow an optional "c" */
3801 if (!strcmp(*argP
, "68000")
3802 || !strcmp(*argP
, "68008")) {
3803 current_architecture
|= m68000
;
3804 } else if (!strcmp(*argP
, "68010")) {
3806 omagic
= 1<<16|OMAGIC
;
3808 current_architecture
|= m68010
;
3810 } else if (!strcmp(*argP
, "68020")) {
3811 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
3813 } else if (!strcmp(*argP
, "68030")) {
3814 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
3816 } else if (!strcmp(*argP
, "68040")) {
3817 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
3820 } else if (!strcmp(*argP
, "68881")) {
3821 current_architecture
|= m68881
;
3823 } else if (!strcmp(*argP
, "68882")) {
3824 current_architecture
|= m68882
;
3826 #endif /* NO_68881 */
3828 } else if (!strcmp(*argP
,"68851")) {
3829 current_architecture
|= m68851
;
3831 #endif /* NO_68851 */
3833 as_warn("Unknown architecture, \"%s\". option ignored", *argP
);
3834 } /* switch on architecture */
3836 while(**argP
) (*argP
)++;
3841 if (!strcmp(*argP
,"pic")) {
3843 break; /* -pic, Position Independent Code */
3857 /* TEST2: Test md_assemble() */
3858 /* Warning, this routine probably doesn't work anymore */
3862 struct m68k_it the_ins
;
3869 if(!gets(buf
) || !*buf
)
3871 if(buf
[0]=='|' || buf
[1]=='.')
3873 for(cp
=buf
;*cp
;cp
++)
3878 memset(&the_ins
, '\0', sizeof(the_ins
));
3879 m68k_ip(&the_ins
,buf
);
3881 printf("Error %s in %s\n",the_ins
.error
,buf
);
3883 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
3884 for(n
=0;n
<the_ins
.numo
;n
++)
3885 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
3887 print_the_insn(&the_ins
.opcode
[0],stdout
);
3888 (void)putchar('\n');
3890 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
3891 if(the_ins
.operands
[n
].error
) {
3892 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
3895 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
3896 if(the_ins
.operands
[n
].b_const
)
3897 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
3898 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
3899 if(the_ins
.operands
[n
].b_iadd
)
3900 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
3901 (void)putchar('\n');
3913 while(*str
&& *str
!=' ')
3915 if(str
[-1]==':' || str
[1]=='=')
3922 /* Possible states for relaxation:
3924 0 0 branch offset byte (bra, etc)
3928 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3932 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3951 extern fragS
*text_frag_root
;
3953 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
3954 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3955 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
3956 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
3968 fputs("Internal error:",stderr
);
3969 _doprnt(format
,&args
,stderr
);
3970 (void)putc('\n',stderr
);
3976 /* We have no need to default values of symbols. */
3980 md_undefined_symbol (name
)
3986 /* Parse an operand that is machine-specific.
3987 We just return without modifying the expression if we have nothing
3992 md_operand (expressionP
)
3993 expressionS
*expressionP
;
3997 /* Round up a section size to the appropriate boundary. */
3999 md_section_align (segment
, size
)
4003 return size
; /* Byte alignment is fine */
4006 /* Exactly what point is a PC-relative offset relative TO?
4007 On the 68k, they're relative to the address of the offset, plus
4008 its size. (??? Is this right? FIXME-SOON!) */
4010 md_pcrel_from (fixP
)
4013 return(fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
4023 /* end of tc-m68k.c */