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 void s_align_bytes();
413 static void s_data1();
414 static void s_data2();
415 static void s_even();
416 static void s_proc();
418 #endif /* not __STDC__ */
420 static enum m68k_architecture current_architecture
= 0;
422 /* BCC68000 is for patching in an extra jmp instruction for long offsets
423 on the 68000. The 68000 doesn't support long branches with branchs */
425 /* This table desribes how you change sizes for the various types of variable
426 size expressions. This version only supports two kinds. */
428 /* Note that calls to frag_var need to specify the maximum expansion needed */
429 /* This is currently 10 bytes for DBCC */
432 How far Forward this mode will reach:
433 How far Backward this mode will reach:
434 How many bytes this mode will add to the size of the frag
435 Which mode to go to if the offset won't fit in this one
439 { 1, 1, 0, 0 }, /* First entries aren't used */
440 { 1, 1, 0, 0 }, /* For no good reason except */
441 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
444 { (127), (-128), 0, TAB(BRANCH
,SHORT
)},
445 { (32767), (-32768), 2, TAB(BRANCH
,LONG
) },
449 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
450 { (32767), (-32768), 2, TAB(FBRANCH
,LONG
)},
454 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
455 { (32767), (-32768), 2, TAB(PCREL
,LONG
)},
459 { (127), (-128), 0, TAB(BCC68000
,SHORT
)},
460 { (32767), (-32768), 2, TAB(BCC68000
,LONG
) },
461 { 0, 0, 6, 0 }, /* jmp long space */
464 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
465 { (32767), (-32768), 2, TAB(DBCC
,LONG
) },
466 { 0, 0, 10, 0 }, /* bra/jmp long space */
469 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
470 { 32767, -32768, 2, TAB(PCLEA
,LONG
) },
476 /* These are the machine dependent pseudo-ops. These are included so
477 the assembler can work on the output from the SUN C compiler, which
481 /* This table describes all the machine specific pseudo-ops the assembler
482 has to support. The fields are:
483 pseudo-op name without dot
484 function to call to execute this pseudo-op
485 Integer arg to pass to the function
487 const pseudo_typeS md_pseudo_table
[] = {
488 { "data1", s_data1
, 0 },
489 { "data2", s_data2
, 0 },
491 { "even", s_even
, 0 },
492 { "skip", s_space
, 0 },
493 { "proc", s_proc
, 0 },
495 { "align", s_align_bytes
, 0 },
501 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
502 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
504 #define issbyte(x) ((x)>=-128 && (x)<=127)
505 #define isubyte(x) ((x)>=0 && (x)<=255)
506 #define issword(x) ((x)>=-32768 && (x)<=32767)
507 #define isuword(x) ((x)>=0 && (x)<=65535)
509 #define isbyte(x) ((x)>=-128 && (x)<=255)
510 #define isword(x) ((x)>=-32768 && (x)<=65535)
511 #define islong(x) (1)
513 extern char *input_line_pointer
;
520 /* JF these tables here are for speed at the expense of size */
521 /* You can replace them with the #if 0 versions if you really
522 need space and don't mind it running a bit slower */
524 static char mklower_table
[256];
525 #define mklower(c) (mklower_table[(unsigned char)(c)])
526 static char notend_table
[256];
527 static char alt_notend_table
[256];
528 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
529 alt_notend_table[(unsigned char)(s[1])])))
532 #define mklower(c) (isupper(c) ? tolower(c) : c)
536 /* JF modified this to handle cases where the first part of a symbol name
537 looks like a register */
540 * m68k_reg_parse() := if it looks like a register, return it's token &
541 * advance the pointer.
544 enum _register
m68k_reg_parse(ccp
)
549 if (isalpha(*start
) && is_name_beginner(*start
))
555 while (is_part_of_name(c
= *p
++))
558 symbolP
= symbol_find(start
);
561 if (symbolP
&& S_GET_SEGMENT(symbolP
) == SEG_REGISTER
)
564 return S_GET_VALUE(symbolP
);
572 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
575 * m68k_ip_op := '#' + <anything>
576 * | <register> + range_sep + get_regs
579 * range_sep := '/' | '-' ;
581 * SKIP_WHITE := <empty> | ' ' ;
588 register struct m68k_op
*opP
;
596 } /* Find the beginning of the string */
599 opP
->error
="Missing operand";
603 for(strend
= str
; *strend
; strend
++) ;;
609 opP
->con1
=add_exp(str
,strend
);
612 } /* Guess what: A constant. Shar and enjoy */
614 i
= m68k_reg_parse(&str
);
616 /* is a register, is exactly a register, and is followed by '@' */
618 if((i
==FAIL
|| *str
!='\0') && *str
!='@') {
621 if(i
!=FAIL
&& (*str
=='/' || *str
=='-')) {
623 return(get_regs(i
,str
,opP
));
625 if ((stmp
=strchr(str
,'@')) != '\0') {
626 opP
->con1
=add_exp(str
,stmp
-1);
632 if ((current_architecture
& m68020up
) == 0) {
634 } /* if target is not a '20 or better */
637 if(*stmp
++!='(' || *strend
--!=')') {
638 opP
->error
="Malformed operand";
641 i
=try_index(&stmp
,opP
);
642 opP
->con2
=add_exp(stmp
,strend
);
650 } /* if there's an '@' */
652 opP
->con1
= add_exp(str
,strend
);
654 } /* not a register, not exactly a register, or no '@' */
659 if(i
>=DATA
+0 && i
<=DATA
+7)
661 else if(i
>=ADDR
+0 && i
<=ADDR
+7)
668 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
) { /* Can't indirect off non address regs */
669 opP
->error
="Invalid indirect register";
689 opP
->error
="Junk after indirect";
692 /* Some kind of indexing involved. Lets find out how bad it is */
693 i
=try_index(&str
,opP
);
694 /* Didn't start with an index reg, maybe its offset or offset,reg */
702 opP
->error
="Missing )";
704 case ',': i
=0; break;
705 case '(': i
++; break;
706 case ')': --i
; break;
709 /* if(str[-3]==':') {
726 opP->error="Specified size isn't :w or :l";
729 opP->con1=add_exp(beg_str,str-4);
730 opP->con1->e_siz=siz;
732 opP
->con1
=add_exp(beg_str
,str
-2);
733 /* Should be offset,reg */
735 i
=try_index(&str
,opP
);
737 opP
->error
="Malformed index reg";
742 /* We've now got offset) offset,reg) or reg) */
745 /* Th-the-thats all folks */
746 if (opP
->reg
== FAIL
) opP
->mode
= AINDX
; /* Other form of indirect */
747 else if(opP
->ireg
== FAIL
) opP
->mode
= AOFF
;
748 else opP
->mode
= AINDX
;
751 /* Next thing had better be another @ */
763 if ((current_architecture
& m68020up
) == 0) {
765 } /* if target is not a '20 or better */
768 if(opP
->ireg
!= FAIL
) {
771 i
= try_index(&str
, opP
);
773 opP
->error
= "Two index registers! not allowed!";
777 i
= try_index(&str
, opP
);
789 opP
->error
="Missing )";
792 case ',': i
=0; break;
793 case '(': i
++; break;
794 case ')': --i
; break;
798 opP
->con2
=add_exp(beg_str
,str
-2);
800 if (str
[-1] == ',') {
801 if (opP
->ireg
!= FAIL
) {
802 opP
->error
= "Can't have two index regs";
806 i
= try_index(&str
, opP
);
809 opP
->error
= "malformed index reg";
814 } else if (opP
->ireg
!= FAIL
) {
824 opP
->error
="Junk after indirect";
832 * try_index := data_or_address_register + ')' + SKIP_W
833 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
835 * multiplier := <empty>
836 * | ':' + multiplier_number
839 * multiplier_number := '1' | '2' | '4' | '8' ;
841 * size_spec := 'l' | 'L' | 'w' | 'W' ;
843 * SKIP_W := <empty> | ' ' ;
847 static int try_index(s
,opP
)
853 #define SKIP_W() { ss++; if (*ss==' ') ss++;}
857 i
=m68k_reg_parse(&ss
);
858 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
872 opP
->error
="Missing : in index register";
887 opP
->error
="Index register size spec not :w or :l";
899 if (cpu_of_arch(current_architecture
) < m68020
) {
900 opP
->error
="no index scaling in pre-68020's";
907 opP
->error
="index multiplier not 1, 2, 4 or 8";
914 opP
->error
="Missing )";
923 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
927 struct m68k_op thark
;
932 memset(&thark
, '\0', sizeof(thark
));
933 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
935 printf("op1 error %s in %s\n",thark
.error
,buf
);
936 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
938 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
939 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
941 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
950 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
951 NULL means any use before m68k_ip_begin()
958 * This converts a string into a 68k instruction.
959 * The string must be a bare single instruction in sun format
960 * with RMS-style 68020 indirects
963 * It provides some error messages: at most one fatal error message (which
964 * stops the scan) and at most one warning message for each operand.
965 * The 68k instruction is returned in exploded form, since we have no
966 * knowledge of how you parse (or evaluate) your expressions.
967 * We do however strip off and decode addressing modes and operation
970 * This function's value is a string. If it is not "" then an internal
971 * logic error was found: read this code to assign meaning to the string.
972 * No argument string should generate such an error string:
973 * it means a bug in our code, not in the user's text.
975 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
979 /* JF this function no longer returns a useful value. Sorry */
980 void m68k_ip (instring
)
984 register struct m68k_op
*opP
;
985 register struct m68k_incant
*opcode
;
987 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
992 char *crack_operand();
993 LITTLENUM_TYPE words
[6];
994 LITTLENUM_TYPE
*wordp
;
996 if (*instring
== ' ')
997 instring
++; /* skip leading whitespace */
999 /* Scan up to end of operation-code, which MUST end in end-of-string
1000 or exactly 1 space. */
1001 for (p
= instring
; *p
!= '\0'; p
++)
1006 if (p
== instring
) {
1007 the_ins
.error
= "No operator";
1008 the_ins
.opcode
[0] = NULL
;
1009 /* the_ins.numo=1; */
1013 /* p now points to the end of the opcode name, probably whitespace.
1014 make sure the name is null terminated by clobbering the whitespace,
1015 look it up in the hash table, then fix it back. */
1018 opcode
= (struct m68k_incant
*)hash_find (op_hash
, instring
);
1021 if (opcode
== NULL
) {
1022 the_ins
.error
= "Unknown operator";
1023 the_ins
.opcode
[0] = NULL
;
1024 /* the_ins.numo=1; */
1028 /* found a legitimate opcode, start matching operands */
1029 while (*p
== ' ') ++p
;
1031 for(opP
= &the_ins
.operands
[0]; *p
; opP
++) {
1033 p
= crack_operand(p
, opP
);
1036 the_ins
.error
=opP
->error
;
1041 opsfound
= opP
- &the_ins
.operands
[0];
1043 /* This ugly hack is to support the floating pt opcodes in their standard form */
1044 /* Essentially, we fake a first enty of type COP#1 */
1045 if (opcode
->m_operands
[0]=='I') {
1048 for(n
=opsfound
;n
>0;--n
)
1049 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1051 /* memcpy((char *)(&the_ins.operands[1]), (char *)(&the_ins.operands[0]), opsfound*sizeof(the_ins.operands[0])); */
1052 memset((char *)(&the_ins
.operands
[0]), '\0', sizeof(the_ins
.operands
[0]));
1053 the_ins
.operands
[0].mode
=MSCR
;
1054 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1058 /* We've got the operands. Find an opcode that'll accept them */
1059 for (losing
= 0; ; ) {
1060 /* if we didn't get the right number of ops,
1061 or we have no common model with this pattern
1062 then reject this pattern. */
1064 if (opsfound
!= opcode
->m_opnum
1065 || ((opcode
->m_arch
& current_architecture
) == 0)) {
1070 for (s
=opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++) {
1071 /* Warning: this switch is huge! */
1072 /* I've tried to organize the cases into this order:
1073 non-alpha first, then alpha by letter. lower-case goes directly
1074 before uppercase counterpart. */
1075 /* Code with multiple case ...: gets sorted by the lowest case ...
1076 it belongs to. I hope this makes sense. */
1079 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1080 || opP
->mode
== DREG
|| opP
->mode
== AREG
1081 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1082 || opP
->mode
== REGLST
)
1087 if(opP
->mode
!=IMMED
)
1092 t
=get_num(opP
->con1
,80);
1093 if(s
[1]=='b' && !isbyte(t
))
1095 else if(s
[1]=='w' && !isword(t
))
1102 if(opP
->mode
!=IMMED
)
1107 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1108 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1113 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1114 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1120 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1121 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1122 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1127 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1142 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1143 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1148 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1153 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1154 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1155 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1160 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1161 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1165 case '~': /* For now! (JF FOO is this right?) */
1166 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1167 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1176 if (opP
->mode
!= AINDR
) {
1178 } /* if not address register indirect */
1181 if(opP
->mode
!=ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1182 && instring
[1] == 'b'
1183 && instring
[2] == 's'
1184 && instring
[3] == 'r'))
1189 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1193 case 'd': /* FOO This mode is a KLUDGE!! */
1194 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1195 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1205 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1210 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1216 if (opP
->mode
!= MSCR
1219 || cpu_of_arch(current_architecture
) < m68010
/* before 68010 had none */
1220 || (cpu_of_arch(current_architecture
) < m68020
1224 && opP
->reg
!= VBR
) /* 68010's had only these */
1225 || (cpu_of_arch(current_architecture
) < m68040
1233 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1234 || (cpu_of_arch(current_architecture
) == m68040
/* 68040 has all but this */
1235 && opP
->reg
== CAAR
)) {
1237 } /* doesn't cut it */
1241 if(opP
->mode
!=IMMED
)
1247 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1252 opP
->reg
=1<<(opP
->reg
-DATA
);
1254 } else if(opP
->mode
!=REGLST
) {
1256 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1258 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1263 if(opP
->mode
!=IMMED
)
1268 t
=get_num(opP
->con1
,80);
1269 if(!issbyte(t
) || isvar(opP
->con1
))
1275 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1280 if(opP
->mode
!=IMMED
)
1285 t
=get_num(opP
->con1
,80);
1286 if(t
<1 || t
>8 || isvar(opP
->con1
))
1292 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1297 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1302 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1307 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1311 /* JF these are out of order. We could put them
1312 in order if we were willing to put up with
1313 bunches of #ifdef m68851s in the code */
1315 /* Memory addressing mode used by pflushr */
1317 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1318 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1323 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1328 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TC
&& opP
->reg
!= CAL
&&
1329 opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1334 if (opP
->reg
!= VAL
)
1339 if (opP
->mode
!= MSCR
|| (opP
->reg
!= DRP
&& opP
->reg
!= SRP
&&
1345 if (opP
->mode
!= MSCR
||
1346 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1347 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1352 if (opP
->reg
!= PSR
)
1357 if (opP
->reg
!= PCSR
)
1365 && opP
->reg
!= BC
) {
1367 } /* not a cache specifier. */
1371 if (opP
->mode
!= ABSL
) {
1373 } /* not absolute */
1377 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1378 *s
, __LINE__
, __FILE__
);
1379 } /* switch on type of operand */
1382 } /* for each operand */
1383 } /* if immediately wrong */
1389 opcode
= opcode
->m_next
;
1392 the_ins
.error
= "instruction/operands mismatch or invalid\n instruction for this architecture";
1394 } /* Fell off the end */
1399 /* now assemble it */
1401 the_ins
.args
=opcode
->m_operands
;
1402 the_ins
.numargs
=opcode
->m_opnum
;
1403 the_ins
.numo
=opcode
->m_codenum
;
1404 the_ins
.opcode
[0]=getone(opcode
);
1405 the_ins
.opcode
[1]=gettwo(opcode
);
1407 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++) {
1408 /* This switch is a doozy.
1409 Watch the first step; its a big one! */
1427 tmpreg
=0x3c; /* 7.4 */
1428 if (strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1429 else nextword
=nextword
=get_num(opP
->con1
,0);
1430 if(isvar(opP
->con1
))
1431 add_fix(s
[1],opP
->con1
,0);
1434 if(!isbyte(nextword
))
1435 opP
->error
="operand out of range";
1440 if(!isword(nextword
))
1441 opP
->error
="operand out of range";
1446 addword(nextword
>>16);
1468 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1469 *s
, s
[1], __LINE__
, __FILE__
);
1474 /* We gotta put out some float */
1475 if(seg(opP
->con1
)!=SEG_BIG
) {
1476 int_to_gen(nextword
);
1477 gen_to_words(words
,baseo
,(long int)outro
);
1478 for(wordp
=words
;baseo
--;wordp
++)
1482 if(offs(opP
->con1
)>0) {
1483 as_warn("Bignum assumed to be binary bit-pattern");
1484 if(offs(opP
->con1
)>baseo
) {
1485 as_warn("Bignum too big for %c format; truncated",s
[1]);
1486 offs(opP
->con1
)=baseo
;
1488 baseo
-=offs(opP
->con1
);
1489 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1495 gen_to_words(words
,baseo
,(long)outro
);
1496 for (wordp
=words
;baseo
--;wordp
++)
1500 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1503 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1506 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1509 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1512 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1516 nextword
=get_num(opP
->con1
,80);
1517 /* Force into index mode. Hope this works */
1519 /* We do the first bit for 32-bit displacements,
1520 and the second bit for 16 bit ones. It is
1521 possible that we should make the default be
1522 WORD instead of LONG, but I think that'd
1523 break GCC, so we put up with a little
1524 inefficiency for the sake of working output.
1527 if( !issword(nextword
)
1528 || ( isvar(opP
->con1
)
1529 && ( ( opP
->con1
->e_siz
==0
1530 && flagseen
['l']==0)
1531 || opP
->con1
->e_siz
==3))) {
1534 tmpreg
=0x3B; /* 7.3 */
1536 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1537 if(isvar(opP
->con1
)) {
1539 add_frag(adds(opP
->con1
),
1541 TAB(PCLEA
,SZ_UNDEF
));
1545 add_fix('l',opP
->con1
,1);
1549 addword(nextword
>>16);
1552 tmpreg
=0x3A; /* 7.2 */
1554 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
1556 if(isvar(opP
->con1
)) {
1558 add_fix('w',opP
->con1
,1);
1560 add_fix('w',opP
->con1
,0);
1569 know(current_architecture
& m68020up
);
1570 /* intentional fall-through */
1573 baseo
=get_num(opP
->con1
,80);
1574 outro
=get_num(opP
->con2
,80);
1575 /* Figure out the 'addressing mode' */
1576 /* Also turn on the BASE_DISABLE bit, if needed */
1577 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1578 tmpreg
=0x3b; /* 7.3 */
1581 } else if(opP
->reg
==FAIL
) {
1583 tmpreg
=0x30; /* 6.garbage */
1584 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
1586 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
1587 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
1589 /* Index register stuff */
1590 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
1591 nextword
|=(opP
->ireg
-DATA
)<<12;
1593 if(opP
->isiz
==0 || opP
->isiz
==3)
1597 case 2: nextword
|=0x200; break;
1598 case 4: nextword
|=0x400; break;
1599 case 8: nextword
|=0x600; break;
1600 default: as_fatal("failed sanity check.");
1603 GET US OUT OF HERE! */
1605 /* Must be INDEX, with an index
1606 register. Address register
1607 cannot be ZERO-PC, and either
1608 :b was forced, or we know
1610 if( opP
->mode
==AINDX
1615 && !isvar(opP
->con1
)))) {
1616 nextword
+=baseo
&0xff;
1618 if(isvar(opP
->con1
))
1619 add_fix('B',opP
->con1
,0);
1623 nextword
|=0x40; /* No index reg */
1625 /* It aint simple */
1627 /* If the guy specified a width, we assume that
1628 it is wide enough. Maybe it isn't. If so, we lose
1632 if(isvar(opP
->con1
) || !issword(baseo
)) {
1643 as_warn("Byte dispacement won't work. Defaulting to :w");
1652 /* Figure out innner displacement stuff */
1653 if(opP
->mode
!=AINDX
) {
1656 if(isvar(opP
->con2
) || !issword(outro
)) {
1667 as_warn("Byte dispacement won't work. Defaulting to :w");
1675 if(opP
->mode
==APODX
) nextword
|=0x04;
1676 else if(opP
->mode
==AMIND
) nextword
|=0x40;
1680 if(isvar(opP
->con1
)) {
1681 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1682 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
1683 opP
->con1
->e_exp
.X_add_number
+=6;
1685 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
1692 if(isvar(opP
->con2
)) {
1693 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
1694 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
1695 opP
->con1
->e_exp
.X_add_number
+=6;
1697 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
1707 nextword
=get_num(opP
->con1
,80);
1708 switch(opP
->con1
->e_siz
) {
1710 as_warn("Unknown size for absolute reference");
1712 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
1713 tmpreg
=0x38; /* 7.0 */
1717 /* Don't generate pc relative code
1718 on 68010 and 68000 */
1721 && seg(opP
->con1
) == SEG_TEXT
1722 && now_seg
== SEG_TEXT
1723 && cpu_of_arch(current_architecture
) >= m68020
1725 && !strchr("~%&$?", s
[0])) {
1726 tmpreg
=0x3A; /* 7.2 */
1727 add_frag(adds(opP
->con1
),
1729 TAB(PCREL
,SZ_UNDEF
));
1732 case 3: /* Fall through into long */
1733 if(isvar(opP
->con1
))
1734 add_fix('l',opP
->con1
,0);
1736 tmpreg
=0x39; /* 7.1 mode */
1737 addword(nextword
>>16);
1742 if(isvar(opP
->con1
))
1743 add_fix('w',opP
->con1
,0);
1745 tmpreg
=0x38; /* 7.0 mode */
1752 as_bad("unknown/incorrect operand");
1755 install_gen_operand(s
[1],tmpreg
);
1760 switch(s
[1]) { /* JF: I hate floating point! */
1775 tmpreg
=get_num(opP
->con1
,tmpreg
);
1776 if(isvar(opP
->con1
))
1777 add_fix(s
[1],opP
->con1
,0);
1779 case 'b': /* Danger: These do no check for
1780 certain types of overflow.
1783 opP
->error
="out of range";
1785 if(isvar(opP
->con1
))
1786 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1790 opP
->error
="out of range";
1792 if(isvar(opP
->con1
))
1793 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1796 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
1798 if(isvar(opP
->con1
))
1799 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
1805 install_operand(s
[1],tmpreg
);
1808 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
1816 install_operand(s
[1],opP
->reg
-ADDR
);
1820 tmpreg
=get_num(opP
->con1
,80);
1823 /* Needs no offsetting */
1824 add_fix('B',opP
->con1
,1);
1827 /* Offset the displacement to be relative to byte disp location */
1828 opP
->con1
->e_exp
.X_add_number
+=2;
1829 add_fix('w',opP
->con1
,1);
1834 if (cpu_of_arch(current_architecture
) < m68020
) /* 68000 or 010 */
1835 as_warn("Can't use long branches on 68000/68010");
1836 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
1837 /* Offset the displacement to be relative to byte disp location */
1838 opP
->con1
->e_exp
.X_add_number
+=4;
1839 add_fix('l',opP
->con1
,1);
1844 if(subs(opP
->con1
)) /* We can't relax it */
1847 /* This could either be a symbol, or an
1848 absolute address. No matter, the
1849 frag hacking will finger it out.
1850 Not quite: it can't switch from
1851 BRANCH to BCC68000 for the case
1852 where opnd is absolute (it needs
1853 to use the 68000 hack since no
1854 conditional abs jumps). */
1855 if (((cpu_of_arch(current_architecture
) < m68020
) || (0==adds(opP
->con1
)))
1856 && (the_ins
.opcode
[0] >= 0x6200)
1857 && (the_ins
.opcode
[0] <= 0x6f00)) {
1858 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
1860 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BRANCH
,SZ_UNDEF
));
1864 if(isvar(opP
->con1
)) {
1865 /* check for DBcc instruction */
1866 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
1867 /* size varies if patch */
1868 /* needed for long form */
1869 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
1874 opP
->con1
->e_exp
.X_add_number
+=2;
1875 add_fix('w',opP
->con1
,1);
1879 case 'C': /* Fixed size LONG coproc branches */
1880 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1881 /* Offset the displacement to be relative to byte disp location */
1882 /* Coproc branches don't have a byte disp option, but they are
1883 compatible with the ordinary branches, which do... */
1884 opP
->con1
->e_exp
.X_add_number
+=4;
1885 add_fix('l',opP
->con1
,1);
1889 case 'c': /* Var size Coprocesssor branches */
1890 if(subs(opP
->con1
)) {
1891 add_fix('l',opP
->con1
,1);
1892 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
1893 } else if(adds(opP
->con1
)) {
1894 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
1896 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
1897 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
1898 add_fix('l',opP
->con1
,1);
1904 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
1905 s
[1], __LINE__
, __FILE__
);
1909 case 'C': /* Ignore it */
1912 case 'd': /* JF this is a kludge */
1913 if(opP
->mode
==AOFF
) {
1914 install_operand('s',opP
->reg
-ADDR
);
1918 tmpP
=opP
->con1
->e_end
-2;
1920 opP
->con1
->e_end
-=4; /* point to the , */
1921 baseo
=m68k_reg_parse(&tmpP
);
1922 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
1923 as_bad("Unknown address reg, using A0");
1926 install_operand('s',baseo
);
1928 tmpreg
=get_num(opP
->con1
,80);
1929 if(!issword(tmpreg
)) {
1930 as_warn("Expression out of range, using 0");
1937 install_operand(s
[1],opP
->reg
-DATA
);
1941 install_operand(s
[1],opP
->reg
-FPREG
);
1945 tmpreg
=1+opP
->reg
-COPNUM
;
1948 install_operand(s
[1],tmpreg
);
1951 case 'J': /* JF foo */
1953 case SFC
: tmpreg
=0x000; break;
1954 case DFC
: tmpreg
=0x001; break;
1955 case CACR
: tmpreg
=0x002; break;
1956 case TC
: tmpreg
=0x003; break;
1957 case ITT0
: tmpreg
=0x004; break;
1958 case ITT1
: tmpreg
=0x005; break;
1959 case DTT0
: tmpreg
=0x006; break;
1960 case DTT1
: tmpreg
=0x007; break;
1962 case USP
: tmpreg
=0x800; break;
1963 case VBR
: tmpreg
=0x801; break;
1964 case CAAR
: tmpreg
=0x802; break;
1965 case MSP
: tmpreg
=0x803; break;
1966 case ISP
: tmpreg
=0x804; break;
1967 case MMUSR
: tmpreg
=0x805; break;
1968 case URP
: tmpreg
=0x806; break;
1969 case SRP
: tmpreg
=0x807; break;
1971 as_fatal("failed sanity check.");
1973 install_operand(s
[1],tmpreg
);
1977 tmpreg
=get_num(opP
->con1
,55);
1978 install_operand(s
[1],tmpreg
&0x7f);
1984 if(tmpreg
&0x7FF0000)
1985 as_bad("Floating point register in register list");
1986 insop(reverse_16_bits(tmpreg
));
1988 if(tmpreg
&0x700FFFF)
1989 as_bad("Wrong register in floating-point reglist");
1990 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
1997 if(tmpreg
&0x7FF0000)
1998 as_bad("Floating point register in register list");
2000 } else if(s
[1]=='8') {
2001 if(tmpreg
&0x0FFFFFF)
2002 as_bad("incorrect register in reglist");
2003 install_operand(s
[1],tmpreg
>>24);
2005 if(tmpreg
&0x700FFFF)
2006 as_bad("wrong register in floating-point reglist");
2008 install_operand(s
[1],tmpreg
>>16);
2013 install_operand(s
[1],get_num(opP
->con1
,60));
2017 tmpreg
= (opP
->mode
==DREG
)
2018 ? 0x20+opP
->reg
-DATA
2019 : (get_num(opP
->con1
,40)&0x1F);
2020 install_operand(s
[1],tmpreg
);
2024 tmpreg
=get_num(opP
->con1
,10);
2027 install_operand(s
[1],tmpreg
);
2031 /* This depends on the fact that ADDR registers are
2032 eight more than their corresponding DATA regs, so
2033 the result will have the ADDR_REG bit set */
2034 install_operand(s
[1],opP
->reg
-DATA
);
2038 if(opP
->reg
==FPI
) tmpreg
=0x1;
2039 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2040 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2041 else as_fatal("failed sanity check.");
2042 install_operand(s
[1],tmpreg
);
2045 case 'S': /* Ignore it */
2049 install_operand(s
[1],get_num(opP
->con1
,30));
2052 case 'U': /* Ignore it */
2057 case NC
: tmpreg
= 0; break;
2058 case DC
: tmpreg
= 1; break;
2059 case IC
: tmpreg
= 2; break;
2060 case BC
: tmpreg
= 3; break;
2062 as_fatal("failed sanity check");
2063 } /* switch on cache token */
2064 install_operand(s
[1], tmpreg
);
2067 /* JF: These are out of order, I fear. */
2077 as_fatal("failed sanity check.");
2079 install_operand(s
[1],tmpreg
);
2100 as_fatal("failed sanity check.");
2102 install_operand(s
[1],tmpreg
);
2106 if (opP
->reg
== VAL
)
2108 as_fatal("failed sanity check.");
2123 as_fatal("failed sanity check.");
2125 install_operand(s
[1],tmpreg
);
2130 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2131 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2132 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2135 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2136 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2137 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2141 as_fatal("failed sanity check.");
2143 install_operand(s
[1], tmpreg
);
2146 know(opP
->reg
== PSR
);
2149 know(opP
->reg
== PCSR
);
2153 tmpreg
=get_num(opP
->con1
,80);
2154 install_operand(s
[1], tmpreg
);
2157 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s
[0], __LINE__
, __FILE__
);
2160 /* By the time whe get here (FINALLY) the_ins contains the complete
2161 instruction, ready to be emitted. . . */
2165 * get_regs := '/' + ?
2166 * | '-' + <register>
2167 * | '-' + <register> + ?
2172 * The idea here must be to scan in a set of registers but I don't
2173 * understand it. Looks awfully sloppy to me but I don't have any doc on
2180 static int get_regs(i
,str
,opP
)
2182 struct m68k_op
*opP
;
2185 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2186 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2187 unsigned long cur_regs
= 0;
2191 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2192 else if(x==FPS) cur_regs|=(1<<25);\
2193 else if(x==FPC) cur_regs|=(1<<26);\
2194 else cur_regs|=(1<<(x-1)); }
2201 } else if(*str
=='-') {
2203 reg2
=m68k_reg_parse(&str
);
2204 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2205 opP
->error
="unknown register in register list";
2214 } else if(*str
=='\0') {
2218 opP
->error
="unknow character in register list";
2221 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2224 reg1
=m68k_reg_parse(&str
);
2225 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2226 opP
->error
="unknown register in register list";
2234 static int reverse_16_bits(in
)
2240 static int mask
[16] = {
2241 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2242 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2249 } /* reverse_16_bits() */
2251 static int reverse_8_bits(in
)
2257 static int mask
[8] = {
2258 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2266 } /* reverse_8_bits() */
2268 static void install_operand(mode
,val
)
2274 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2277 the_ins
.opcode
[0]|=val
<<9;
2280 the_ins
.opcode
[1]|=val
<<12;
2283 the_ins
.opcode
[1]|=val
<<6;
2286 the_ins
.opcode
[1]|=val
;
2289 the_ins
.opcode
[2]|=val
<<12;
2292 the_ins
.opcode
[2]|=val
<<6;
2295 /* DANGER! This is a hack to force cas2l and cas2w cmds
2296 to be three words long! */
2298 the_ins
.opcode
[2]|=val
;
2301 the_ins
.opcode
[1]|=val
<<7;
2304 the_ins
.opcode
[1]|=val
<<10;
2308 the_ins
.opcode
[1]|=val
<<5;
2313 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2316 the_ins
.opcode
[1]|=(val
<<12)|val
;
2319 the_ins
.opcode
[0]|=val
=0xff;
2322 the_ins
.opcode
[0]|=val
<<9;
2325 the_ins
.opcode
[1]|=val
;
2328 the_ins
.opcode
[1]|=val
;
2329 the_ins
.numo
++; /* What a hack */
2332 the_ins
.opcode
[1]|=val
<<4;
2339 the_ins
.opcode
[0] |= (val
<< 6);
2342 the_ins
.opcode
[1] = (val
>> 16);
2343 the_ins
.opcode
[2] = val
& 0xffff;
2347 as_fatal("failed sanity check.");
2349 } /* install_operand() */
2351 static void install_gen_operand(mode
,val
)
2357 the_ins
.opcode
[0]|=val
;
2360 /* This is a kludge!!! */
2361 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2370 the_ins
.opcode
[0]|=val
;
2372 /* more stuff goes here */
2374 as_fatal("failed sanity check.");
2376 } /* install_gen_operand() */
2379 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2380 * then deal with the bitfield hack.
2383 static char *crack_operand(str
,opP
)
2385 register struct m68k_op
*opP
;
2387 register int parens
;
2389 register char *beg_str
;
2395 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2396 if(*str
=='(') parens
++;
2397 else if(*str
==')') {
2398 if(!parens
) { /* ERROR */
2399 opP
->error
="Extra )";
2405 if(!*str
&& parens
) { /* ERROR */
2406 opP
->error
="Missing )";
2411 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2417 c
= *++str
; /* JF bitfield hack */
2421 as_bad("Missing operand");
2426 /* See the comment up above where the #define notend(... is */
2431 if(*s
==',') return 0;
2432 if(*s
=='{' || *s
=='}')
2434 if(*s
!=':') return 1;
2435 /* This kludge here is for the division cmd, which is a kludge */
2436 if(index("aAdD#",s
[1])) return 0;
2441 /* This is the guts of the machine-dependent assembler. STR points to a
2442 machine dependent instruction. This function is supposed to emit
2443 the frags/bytes it assembles to.
2447 insert_reg(regname
, regnum
)
2453 symbol_table_insert(symbol_new(regname
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2455 for (i
= 0; regname
[i
]; i
++)
2456 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2459 symbol_table_insert(symbol_new(buf
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2576 for (i
= 0; init_table
[i
].name
; i
++)
2578 insert_reg(init_table
[i
].name
, init_table
[i
].number
);
2592 int shorts_this_frag
;
2595 if (current_architecture
== 0)
2596 current_architecture
= (m68020
2604 /* If only float and mmu were specified, default cpu. */
2605 else if (cpu_of_arch (current_architecture
) == 0)
2606 current_architecture
|= m68020
;
2608 memset((char *)(&the_ins
), '\0', sizeof(the_ins
)); /* JF for paranoia sake */
2612 for(n
=the_ins
.numargs
;n
;--n
)
2613 if(the_ins
.operands
[n
].error
) {
2614 er
=the_ins
.operands
[n
].error
;
2619 as_bad("%s -- statement `%s' ignored",er
,str
);
2623 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
2624 toP
=frag_more(2*the_ins
.numo
);
2625 fromP
= &the_ins
.opcode
[0];
2626 for(m
=the_ins
.numo
;m
;--m
) {
2627 md_number_to_chars(toP
,(long)(*fromP
),2);
2631 /* put out symbol-dependent info */
2632 for(m
=0;m
<the_ins
.nrel
;m
++) {
2633 switch(the_ins
.reloc
[m
].wid
) {
2650 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
2654 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2656 the_ins
.reloc
[m
].add
,
2657 the_ins
.reloc
[m
].sub
,
2658 the_ins
.reloc
[m
].off
,
2659 the_ins
.reloc
[m
].pcrel
,
2665 /* There's some frag hacking */
2666 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
2669 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
2670 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2674 for(m
=wid
/2;m
;--m
) {
2675 md_number_to_chars(toP
,(long)(*fromP
),2);
2680 for(m
=0;m
<the_ins
.nrel
;m
++) {
2681 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
2682 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
2685 wid
=the_ins
.reloc
[m
].wid
;
2688 the_ins
.reloc
[m
].wid
=0;
2689 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2692 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
2694 the_ins
.reloc
[m
].add
,
2695 the_ins
.reloc
[m
].sub
,
2696 the_ins
.reloc
[m
].off
,
2697 the_ins
.reloc
[m
].pcrel
,
2700 /* know(the_ins.fragb[n].fadd); */
2701 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
2702 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
2704 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
2707 toP
=frag_more(n
*sizeof(short));
2709 md_number_to_chars(toP
,(long)(*fromP
),2);
2715 for(m
=0;m
<the_ins
.nrel
;m
++) {
2718 wid
=the_ins
.reloc
[m
].wid
;
2721 the_ins
.reloc
[m
].wid
=0;
2722 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
2725 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
2727 the_ins
.reloc
[m
].add
,
2728 the_ins
.reloc
[m
].sub
,
2729 the_ins
.reloc
[m
].off
,
2730 the_ins
.reloc
[m
].pcrel
,
2743 * md_begin -- set up hash tables with 68000 instructions.
2744 * similar to what the vax assembler does. ---phr
2746 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2747 a copy of it at runtime, adding in the information we want but isn't
2748 there. I think it'd be better to have an awk script hack the table
2749 at compile time. Or even just xstr the table and use it as-is. But
2750 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2753 register const struct m68k_opcode
*ins
;
2754 register struct m68k_incant
*hack
,
2756 register char *retval
= 0; /* empty string, or error msg text */
2757 register unsigned int i
;
2760 if ((op_hash
= hash_new()) == NULL
)
2761 as_fatal("Virtual memory exhausted");
2763 obstack_begin(&robyn
,4000);
2764 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
2765 hack
=slak
=(struct m68k_incant
*)obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2767 /* we *could* ignore insns that don't match our
2768 arch here but just leaving them out of the
2770 slak
->m_operands
=ins
->args
;
2771 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
2772 slak
->m_arch
= ins
->arch
;
2773 slak
->m_opcode
=ins
->opcode
;
2774 /* This is kludgey */
2775 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
2776 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
2777 slak
->m_next
=(struct m68k_incant
*) obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
2784 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
2785 /* Didn't his mommy tell him about null pointers? */
2786 if(retval
&& *retval
)
2787 as_fatal("Internal Error: Can't hash %s: %s",ins
->name
,retval
);
2790 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
2791 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
2793 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
2794 notend_table
[i
] = 0;
2795 alt_notend_table
[i
] = 0;
2797 notend_table
[','] = 1;
2798 notend_table
['{'] = 1;
2799 notend_table
['}'] = 1;
2800 alt_notend_table
['a'] = 1;
2801 alt_notend_table
['A'] = 1;
2802 alt_notend_table
['d'] = 1;
2803 alt_notend_table
['D'] = 1;
2804 alt_notend_table
['#'] = 1;
2805 alt_notend_table
['f'] = 1;
2806 alt_notend_table
['F'] = 1;
2807 #ifdef REGISTER_PREFIX
2808 alt_notend_table
[REGISTER_PREFIX
] = 1;
2815 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2816 || (*s == ':' && strchr("aAdD#", s[1]))) \
2820 /* This funciton is called once, before the assembler exits. It is
2821 supposed to do any final cleanup for this part of the assembler.
2828 /* Equal to MAX_PRECISION in atof-ieee.c */
2829 #define MAX_LITTLENUMS 6
2831 /* Turn a string in input_line_pointer into a floating point constant of type
2832 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2833 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2836 md_atof(type
,litP
,sizeP
)
2842 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2843 LITTLENUM_TYPE
*wordP
;
2874 return "Bad call to MD_ATOF()";
2876 t
=atof_ieee(input_line_pointer
,type
,words
);
2878 input_line_pointer
=t
;
2880 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
2881 for(wordP
=words
;prec
--;) {
2882 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
2883 litP
+=sizeof(LITTLENUM_TYPE
);
2885 return ""; /* Someone should teach Dean about null pointers */
2888 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2889 for use in the a.out file, and stores them in the array pointed to by buf.
2890 This knows about the endian-ness of the target machine and does
2891 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2892 2 (short) and 4 (long) Floating numbers are put out as a series of
2893 LITTLENUMS (shorts, here at least)
2896 md_number_to_chars(buf
,val
,n
)
2916 as_fatal("failed sanity check.");
2921 md_apply_fix(fixP
, val
)
2925 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2927 switch(fixP
->fx_size
) {
2942 BAD_CASE (fixP
->fx_size
);
2947 /* *fragP has been relaxed to its final size, and now needs to have
2948 the bytes inside it modified to conform to the new size There is UGLY
2952 md_convert_frag(headers
, fragP
)
2953 object_headers
*headers
;
2954 register fragS
*fragP
;
2959 /* Address in object code of the displacement. */
2960 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
2962 #ifdef IBM_COMPILER_SUX
2963 /* This is wrong but it convinces the native rs6000 compiler to
2964 generate the code we want. */
2965 register char *buffer_address
= fragP
-> fr_literal
;
2966 buffer_address
+= fragP
-> fr_fix
;
2967 #else /* IBM_COMPILER_SUX */
2968 /* Address in gas core of the place to store the displacement. */
2969 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2970 #endif /* IBM_COMPILER_SUX */
2972 /* No longer true: know(fragP->fr_symbol); */
2974 /* The displacement of the address, from current location. */
2975 disp
= fragP
->fr_symbol
? S_GET_VALUE(fragP
->fr_symbol
) : 0;
2976 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
2978 switch(fragP
->fr_subtype
) {
2979 case TAB(BCC68000
,BYTE
):
2980 case TAB(BRANCH
,BYTE
):
2981 know(issbyte(disp
));
2983 as_bad("short branch with zero offset: use :w");
2984 fragP
->fr_opcode
[1]=disp
;
2987 case TAB(DBCC
,SHORT
):
2988 know(issword(disp
));
2991 case TAB(BCC68000
,SHORT
):
2992 case TAB(BRANCH
,SHORT
):
2993 know(issword(disp
));
2994 fragP
->fr_opcode
[1]=0x00;
2997 case TAB(BRANCH
,LONG
):
2998 if (cpu_of_arch(current_architecture
) < m68020
) {
2999 if (fragP
->fr_opcode
[0]==0x61) {
3000 fragP
->fr_opcode
[0]= 0x4E;
3001 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3002 subseg_change(SEG_TEXT
, 0);
3015 } else if (fragP
->fr_opcode
[0]==0x60) {
3016 fragP
->fr_opcode
[0]= 0x4E;
3017 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3018 subseg_change(SEG_TEXT
, 0);
3019 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
3024 as_bad("Long branch offset not supported.");
3027 fragP
->fr_opcode
[1]=0xff;
3031 case TAB(BCC68000
,LONG
):
3032 /* only Bcc 68000 instructions can come here */
3033 /* change bcc into b!cc/jmp absl long */
3034 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3035 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
3037 /* JF: these used to be fr_opcode[2,3], but they may be in a
3038 different frag, in which case refering to them is a no-no.
3039 Only fr_opcode[0,1] are guaranteed to work. */
3040 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3041 *buffer_address
++ = 0xf9;
3042 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3043 subseg_change(SEG_TEXT
,0);
3044 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3050 case TAB(DBCC
,LONG
):
3051 /* only DBcc 68000 instructions can come here */
3052 /* change dbcc into dbcc/jmp absl long */
3053 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3054 *buffer_address
++ = 0x00; /* branch offset = 4 */
3055 *buffer_address
++ = 0x04;
3056 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3057 *buffer_address
++ = 0x06;
3058 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3059 *buffer_address
++ = 0xf9;
3061 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3062 subseg_change(SEG_TEXT
,0);
3063 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3069 case TAB(FBRANCH
,SHORT
):
3070 know((fragP
->fr_opcode
[1]&0x40)==0);
3073 case TAB(FBRANCH
,LONG
):
3074 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
3077 case TAB(PCREL
,SHORT
):
3080 case TAB(PCREL
,LONG
):
3081 /* The thing to do here is force it to ABSOLUTE LONG, since
3082 PCREL is really trying to shorten an ABSOLUTE address anyway */
3083 /* JF FOO This code has not been tested */
3084 subseg_change(SEG_TEXT
,0);
3085 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3086 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3087 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3088 fragP
->fr_opcode
[0],fragP
->fr_address
);
3089 fragP
->fr_opcode
[1]&= ~0x3F;
3090 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
3092 /* md_number_to_chars(buffer_address,
3093 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3097 case TAB(PCLEA
,SHORT
):
3098 subseg_change(SEG_TEXT
,0);
3099 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
3101 fragP
->fr_opcode
[1] &= ~0x3F;
3102 fragP
->fr_opcode
[1] |= 0x3A;
3105 case TAB(PCLEA
,LONG
):
3106 subseg_change(SEG_TEXT
,0);
3107 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
3109 *buffer_address
++ = 0x01;
3110 *buffer_address
++ = 0x70;
3112 /* buffer_address+=2; */
3116 } /* switch on subtype */
3119 md_number_to_chars(buffer_address
, (long) disp
, (int) ext
);
3120 fragP
->fr_fix
+= ext
;
3121 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3122 } /* if extending */
3125 } /* md_convert_frag() */
3127 /* Force truly undefined symbols to their maximum size, and generally set up
3128 the frag list to be relaxed
3130 int md_estimate_size_before_relax(fragP
, segment
)
3131 register fragS
*fragP
;
3135 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3137 old_fix
= fragP
->fr_fix
;
3139 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3140 switch (fragP
->fr_subtype
) {
3142 case TAB(BRANCH
,SZ_UNDEF
): {
3143 if((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3144 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3145 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
3147 } else if((fragP
->fr_symbol
== 0) || (cpu_of_arch(current_architecture
) < m68020
)) {
3148 /* On 68000, or for absolute value, switch to abs long */
3149 /* FIXME, we should check abs val, pick short or long */
3150 if(fragP
->fr_opcode
[0]==0x61) {
3151 fragP
->fr_opcode
[0]= 0x4E;
3152 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3153 subseg_change(SEG_TEXT
, 0);
3154 fix_new(fragP
, fragP
->fr_fix
, 4,
3155 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3158 } else if(fragP
->fr_opcode
[0]==0x60) {
3159 fragP
->fr_opcode
[0]= 0x4E;
3160 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3161 subseg_change(SEG_TEXT
, 0);
3162 fix_new(fragP
, fragP
->fr_fix
, 4,
3163 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3167 as_warn("Long branch offset to extern symbol not supported.");
3169 } else { /* Symbol is still undefined. Make it simple */
3170 fix_new(fragP
, (int)(fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3171 (symbolS
*)0, fragP
->fr_offset
+4, 1, NO_RELOC
);
3173 fragP
->fr_opcode
[1]=0xff;
3179 } /* case TAB(BRANCH,SZ_UNDEF) */
3181 case TAB(FBRANCH
,SZ_UNDEF
): {
3182 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3183 fragP
->fr_subtype
= TAB(FBRANCH
,SHORT
);
3186 fragP
->fr_subtype
= TAB(FBRANCH
,LONG
);
3190 } /* TAB(FBRANCH,SZ_UNDEF) */
3192 case TAB(PCREL
,SZ_UNDEF
): {
3193 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3194 fragP
->fr_subtype
= TAB(PCREL
,SHORT
);
3197 fragP
->fr_subtype
= TAB(PCREL
,LONG
);
3201 } /* TAB(PCREL,SZ_UNDEF) */
3203 case TAB(BCC68000
,SZ_UNDEF
): {
3204 if((fragP
->fr_symbol
!= NULL
)
3205 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3206 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
3209 /* only Bcc 68000 instructions can come here */
3210 /* change bcc into b!cc/jmp absl long */
3211 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3213 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3214 /* JF: these were fr_opcode[2,3] */
3215 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3216 buffer_address
[1] = 0xf8;
3217 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3218 subseg_change(SEG_TEXT
,0);
3219 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3220 fragP
->fr_offset
, 0, NO_RELOC
);
3223 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3224 /* JF: these were fr_opcode[2,3] */
3225 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3226 buffer_address
[1] = 0xf9;
3227 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3228 subseg_change(SEG_TEXT
,0);
3229 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3230 fragP
->fr_offset
, 0, NO_RELOC
);
3235 } /* case TAB(BCC68000,SZ_UNDEF) */
3237 case TAB(DBCC
,SZ_UNDEF
): {
3238 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3239 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3243 /* only DBcc 68000 instructions can come here */
3244 /* change dbcc into dbcc/jmp absl long */
3245 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3246 buffer_address
[0] = 0x00; /* branch offset = 4 */
3247 buffer_address
[1] = 0x04;
3248 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3251 /* JF: these were fr_opcode[5-7] */
3252 buffer_address
[3] = 0x04; /* plus 4 */
3253 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3254 buffer_address
[5] = 0xf8;
3255 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3256 subseg_change(SEG_TEXT
,0);
3257 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3260 fragP
->fr_offset
, 0, NO_RELOC
);
3263 /* JF: these were fr_opcode[5-7] */
3264 buffer_address
[3] = 0x06; /* Plus 6 */
3265 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3266 buffer_address
[5] = 0xf9;
3267 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3268 subseg_change(SEG_TEXT
,0);
3269 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3270 fragP
->fr_offset
, 0, NO_RELOC
);
3276 } /* case TAB(DBCC,SZ_UNDEF) */
3278 case TAB(PCLEA
,SZ_UNDEF
): {
3279 if ((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3280 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3283 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3287 } /* TAB(PCLEA,SZ_UNDEF) */
3292 } /* switch on subtype looking for SZ_UNDEF's. */
3294 /* now that SZ_UNDEF are taken care of, check others */
3295 switch (fragP
->fr_subtype
) {
3296 case TAB(BCC68000
,BYTE
):
3297 case TAB(BRANCH
,BYTE
):
3298 /* We can't do a short jump to the next instruction,
3299 so we force word mode. */
3300 if (fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3301 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3302 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3309 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3312 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3313 /* the bit-field entries in the relocation_info struct plays hell
3314 with the byte-order problems of cross-assembly. So as a hack,
3315 I added this mach. dependent ri twiddler. Ugly, but it gets
3317 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3318 are symbolnum, most sig. byte first. Last byte is broken up with
3319 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3320 nibble as nuthin. (on Sun 3 at least) */
3321 /* Translate the internal relocation information into target-specific
3325 md_ri_to_chars(the_bytes
, ri
)
3327 struct reloc_info_generic
*ri
;
3330 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3331 /* now the fun stuff */
3332 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3333 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3334 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3335 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3336 ((ri
->r_extern
<< 4) & 0x10));
3338 #endif /* comment */
3340 void tc_aout_fix_to_chars(where
, fixP
, segment_address_in_file
)
3343 relax_addressT segment_address_in_file
;
3346 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3347 * Out: GNU LD relocation length code: 0, 1, or 2.
3350 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
3353 know(fixP
->fx_addsy
!= NULL
);
3355 md_number_to_chars(where
,
3356 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3359 r_symbolnum
= (S_IS_DEFINED(fixP
->fx_addsy
)
3360 ? S_GET_TYPE(fixP
->fx_addsy
)
3361 : fixP
->fx_addsy
->sy_number
);
3363 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3364 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3365 where
[6] = r_symbolnum
& 0x0ff;
3366 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3367 (((!S_IS_DEFINED(fixP
->fx_addsy
)) << 4) & 0x10));
3370 } /* tc_aout_fix_to_chars() */
3372 #endif /* OBJ_AOUT or OBJ_BOUT */
3374 #ifndef WORKING_DOT_WORD
3375 const int md_short_jump_size
= 4;
3376 const int md_long_jump_size
= 6;
3379 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3388 offset
= to_addr
- (from_addr
+2);
3390 md_number_to_chars(ptr
,(long)0x6000,2);
3391 md_number_to_chars(ptr
+2,(long)offset
,2);
3395 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3404 if (cpu_of_arch(current_architecture
) < m68020
) {
3405 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3406 md_number_to_chars(ptr
,(long)0x4EF9,2);
3407 md_number_to_chars(ptr
+2,(long)offset
,4);
3408 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3411 offset
=to_addr
- (from_addr
+2);
3412 md_number_to_chars(ptr
,(long)0x60ff,2);
3413 md_number_to_chars(ptr
+2,(long)offset
,4);
3418 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3421 10: Absolute 1:8 only
3422 20: Absolute 0:7 only
3423 30: absolute 0:15 only
3424 40: Absolute 0:31 only
3425 50: absolute 0:127 only
3426 55: absolute -64:63 only
3427 60: absolute -128:127 only
3428 70: absolute 0:4095 only
3433 static int get_num(exp
,ok
)
3434 struct m68k_exp
*exp
;
3442 if(*exp
->e_beg
=='0') {
3443 if(exp
->e_beg
[1]=='x')
3444 sscanf(exp
->e_beg
+2,"%x",&l
);
3446 sscanf(exp
->e_beg
+1,"%O",&l
);
3449 return atol(exp
->e_beg
);
3455 /* Can't do anything */
3458 if(!exp
->e_beg
|| !exp
->e_end
) {
3459 seg(exp
)=SEG_ABSOLUTE
;
3462 offs(exp
)= (ok
==10) ? 1 : 0;
3463 as_warn("Null expression defaults to %ld",offs(exp
));
3468 if(/* ok!=80 && */exp
->e_end
[-1]==':' && (exp
->e_end
-exp
->e_beg
)>=2) {
3469 switch(exp
->e_end
[0]) {
3485 as_bad("Unknown size for expression \"%c\"",exp
->e_end
[0]);
3489 c_save
=exp
->e_end
[1];
3491 save_in
=input_line_pointer
;
3492 input_line_pointer
=exp
->e_beg
;
3493 switch(expression(&(exp
->e_exp
))) {
3495 seg(exp
)=SEG_ABSOLUTE
;
3498 offs(exp
)= (ok
==10) ? 1 : 0;
3499 as_warn("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
3503 /* Do the same thing the VAX asm does */
3504 seg(exp
)=SEG_ABSOLUTE
;
3509 as_warn("expression out of range: defaulting to 1");
3516 if(offs(exp
)<1 || offs(exp
)>8) {
3517 as_warn("expression out of range: defaulting to 1");
3522 if(offs(exp
)<0 || offs(exp
)>7)
3526 if(offs(exp
)<0 || offs(exp
)>15)
3530 if(offs(exp
)<0 || offs(exp
)>32)
3534 if(offs(exp
)<0 || offs(exp
)>127)
3538 if(offs(exp
)<-64 || offs(exp
)>63)
3542 if(offs(exp
)<-128 || offs(exp
)>127)
3546 if(offs(exp
)<0 || offs(exp
)>4095) {
3548 as_warn("expression out of range: defaulting to 0");
3560 case SEG_DIFFERENCE
:
3561 if(ok
>=10 && ok
<=70) {
3562 seg(exp
)=SEG_ABSOLUTE
;
3565 offs(exp
)= (ok
==10) ? 1 : 0;
3566 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3570 if(ok
==80 && offs(exp
)<0) { /* HACK! Turn it into a long */
3571 LITTLENUM_TYPE words
[6];
3573 gen_to_words(words
,2,8L);/* These numbers are magic! */
3574 seg(exp
)=SEG_ABSOLUTE
;
3577 offs(exp
)=words
[1]|(words
[0]<<16);
3579 seg(exp
)=SEG_ABSOLUTE
;
3582 offs(exp
)= (ok
==10) ? 1 : 0;
3583 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
3587 as_fatal("failed sanity check.");
3589 if(input_line_pointer
!=exp
->e_end
+1)
3590 as_bad("Ignoring junk after expression");
3591 exp
->e_end
[1]=c_save
;
3592 input_line_pointer
=save_in
;
3594 switch(exp
->e_siz
) {
3596 if(!isbyte(offs(exp
)))
3597 as_warn("expression doesn't fit in BYTE");
3600 if(!isword(offs(exp
)))
3601 as_warn("expression doesn't fit in WORD");
3609 /* These are the back-ends for the various machine dependent pseudo-ops. */
3610 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
3612 static void s_data1() {
3613 subseg_new(SEG_DATA
,1);
3614 demand_empty_rest_of_line();
3617 static void s_data2() {
3618 subseg_new(SEG_DATA
,2);
3619 demand_empty_rest_of_line();
3624 /* We don't support putting frags in the BSS segment, we fake it
3625 by marking in_bss, then looking at s_skip for clues */
3627 subseg_new(SEG_BSS
, 0);
3628 demand_empty_rest_of_line();
3631 static void s_even() {
3633 register long temp_fill
;
3635 temp
= 1; /* JF should be 2? */
3636 temp_fill
= get_absolute_expression ();
3637 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
3638 frag_align (temp
, (int)temp_fill
);
3639 demand_empty_rest_of_line();
3642 static void s_proc() {
3643 demand_empty_rest_of_line();
3646 /* s_space is defined in read.c .skip is simply an alias to it. */
3650 * Invocation line includes a switch not recognized by the base assembler.
3651 * See if it's a processor-specific option. These are:
3653 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3654 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3655 * Select the architecture. Instructions or features not
3656 * supported by the selected architecture cause fatal
3657 * errors. More than one may be specified. The default is
3658 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3659 * for -m68000, and -m68882 is a synonym for -m68881.
3661 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
3662 * (e.g. m68020) also requests that float instructions be included. This
3663 * is the default setup, mostly to avoid hassling users. A better
3664 * rearrangement of this structure would be to add an option to DENY
3665 * floating point opcodes, for people who want to really know there's none
3666 * of that funny floaty stuff going on. FIXME-later.
3668 #ifndef MAYBE_FLOAT_TOO
3669 #define MAYBE_FLOAT_TOO m68881
3672 int md_parse_option(argP
,cntP
,vecP
)
3678 case 'l': /* -l means keep external to 2 bit offset
3679 rather than 16 bit one */
3682 case 'S': /* -S means that jbsr's always turn into jsr's. */
3687 /* intentional fall-through */
3693 } /* allow an optional "c" */
3695 if (!strcmp(*argP
, "68000")
3696 || !strcmp(*argP
, "68008")) {
3697 current_architecture
|= m68000
;
3698 } else if (!strcmp(*argP
, "68010")) {
3700 omagic
= 1<<16|OMAGIC
;
3702 current_architecture
|= m68010
;
3704 } else if (!strcmp(*argP
, "68020")) {
3705 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
3707 } else if (!strcmp(*argP
, "68030")) {
3708 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
3710 } else if (!strcmp(*argP
, "68040")) {
3711 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
3714 } else if (!strcmp(*argP
, "68881")) {
3715 current_architecture
|= m68881
;
3717 } else if (!strcmp(*argP
, "68882")) {
3718 current_architecture
|= m68882
;
3720 #endif /* NO_68881 */
3722 } else if (!strcmp(*argP
,"68851")) {
3723 current_architecture
|= m68851
;
3725 #endif /* NO_68851 */
3727 as_warn("Unknown architecture, \"%s\". option ignored", *argP
);
3728 } /* switch on architecture */
3730 while(**argP
) (*argP
)++;
3735 if (!strcmp(*argP
,"pic")) {
3737 break; /* -pic, Position Independent Code */
3751 /* TEST2: Test md_assemble() */
3752 /* Warning, this routine probably doesn't work anymore */
3756 struct m68k_it the_ins
;
3763 if(!gets(buf
) || !*buf
)
3765 if(buf
[0]=='|' || buf
[1]=='.')
3767 for(cp
=buf
;*cp
;cp
++)
3772 memset(&the_ins
, '\0', sizeof(the_ins
));
3773 m68k_ip(&the_ins
,buf
);
3775 printf("Error %s in %s\n",the_ins
.error
,buf
);
3777 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
3778 for(n
=0;n
<the_ins
.numo
;n
++)
3779 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
3781 print_the_insn(&the_ins
.opcode
[0],stdout
);
3782 (void)putchar('\n');
3784 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
3785 if(the_ins
.operands
[n
].error
) {
3786 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
3789 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
3790 if(the_ins
.operands
[n
].b_const
)
3791 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
3792 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
3793 if(the_ins
.operands
[n
].b_iadd
)
3794 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
3795 (void)putchar('\n');
3807 while(*str
&& *str
!=' ')
3809 if(str
[-1]==':' || str
[1]=='=')
3816 /* Possible states for relaxation:
3818 0 0 branch offset byte (bra, etc)
3822 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3826 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3845 extern fragS
*text_frag_root
;
3847 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
3848 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3849 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
3850 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
3862 fputs("Internal error:",stderr
);
3863 _doprnt(format
,&args
,stderr
);
3864 (void)putc('\n',stderr
);
3870 /* We have no need to default values of symbols. */
3874 md_undefined_symbol (name
)
3880 /* Parse an operand that is machine-specific.
3881 We just return without modifying the expression if we have nothing
3886 md_operand (expressionP
)
3887 expressionS
*expressionP
;
3891 /* Round up a section size to the appropriate boundary. */
3893 md_section_align (segment
, size
)
3897 return size
; /* Byte alignment is fine */
3900 /* Exactly what point is a PC-relative offset relative TO?
3901 On the 68k, they're relative to the address of the offset, plus
3902 its size. (??? Is this right? FIXME-SOON!) */
3904 md_pcrel_from (fixP
)
3907 return(fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
3917 /* end of tc-m68k.c */