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. */
29 /* note that this file includes real declarations and thus can only be included by one source file per executable. */
30 #include "opcode/m68k.h"
33 /* This variable contains the value to write out at the beginning of
34 the a.out file. The 2<<16 means that this is a 68020 file instead
35 of an old-style 68000 file */
37 long omagic
= 2<<16|OMAGIC
; /* Magic byte for header file */
42 /* This array holds the chars that always start a comment. If the
43 pre-processor is disabled, these aren't very useful */
44 const char comment_chars
[] = "|";
46 /* This array holds the chars that only start a comment at the beginning of
47 a line. If the line seems to have the form '# 123 filename'
48 .line and .file directives will appear in the pre-processed output */
49 /* Note that input_file.c hand checks for '#' at the beginning of the
50 first line of the input file. This is because the compiler outputs
51 #NO_APP at the beginning of its output. */
52 /* Also note that comments like this one will always work. */
53 const char line_comment_chars
[] = "#";
55 /* Chars that can be used to separate mant from exp in floating point nums */
56 const char EXP_CHARS
[] = "eE";
58 /* Chars that mean this number is a floating point constant */
62 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
64 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
65 changed in read.c . Ideally it shouldn't have to know about it at all,
66 but nothing is ideal around here.
69 int md_reloc_size
= 8; /* Size of relocation record */
71 /* Its an arbitrary name: This means I don't approve of it */
72 /* See flames below */
73 static struct obstack robyn
;
75 #define TAB(x,y) (((x)<<2)+(y))
76 #define TABTYPE(xy) ((xy) >> 2)
89 /* Operands we can parse: (And associated modes)
95 reg: address or data register
96 areg: address register
97 apc: address register, PC, ZPC or empty string
100 sz: w or l if omitted, l assumed
101 scale: 1 2 4 or 8 if omitted, 1 assumed
103 7.4 IMMED #num --> NUM
104 0.? DREG dreg --> dreg
105 1.? AREG areg --> areg
106 2.? AINDR areg@ --> *(areg)
107 3.? AINC areg@+ --> *(areg++)
108 4.? ADEC areg@- --> *(--areg)
109 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
110 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
111 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
112 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
113 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
114 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
115 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
116 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
117 7.0 ABSL num:sz --> *(num)
118 num --> *(num) (sz L assumed)
119 *** MSCR otherreg --> Magic
121 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
122 ?.? DINDR dreg@ --> (dreg) -- cas2 only
132 a1@(5,d2:w:1) @(45,d6:l:4)
137 #name@(numw) -->turn into PC rel mode
138 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
165 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
168 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
169 8-15==addr reg for operands that take both types */
172 DATA
= 1, /* 1- 8 == data registers 0-7 */
192 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
197 FPREG
, /* Eight FP registers */
206 COPNUM
= (FPREG
+8), /* Co-processor #1-#8 */
215 PC
, /* Program counter */
216 ZPC
, /* Hack for Program space, but 0 addressing */
218 CCR
, /* Condition code Reg */
220 /* These have to be in order for the movec instruction to work. */
221 USP
, /* User Stack Pointer */
222 ISP
, /* Interrupt stack pointer */
237 /* end of movec ordering constraints */
243 DRP
, /* 68851 or 68030 MMU regs */
267 PSR
, /* aka MMUSR on 68030 (but not MMUSR on 68040)
268 and ACUSR on 68ec030 */
271 IC
, /* instruction cache token */
272 DC
, /* data cache token */
273 NC
, /* no cache token */
274 BC
, /* both caches token */
276 TT0
, /* 68030 access control unit regs */
280 /* Internal form of an operand. */
282 char *error
; /* Couldn't parse it */
283 enum operand_type mode
; /* What mode this instruction is in. */
284 enum _register reg
; /* Base register */
285 struct m68k_exp
*con1
;
286 int ireg
; /* Index register */
287 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
288 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
289 struct m68k_exp
*con2
;
292 /* internal form of a 68020 instruction */
295 char *args
; /* list of opcode info */
298 int numo
; /* Number of shorts in opcode */
301 struct m68k_op operands
[6];
303 int nexp
; /* number of exprs in use */
304 struct m68k_exp exprs
[4];
306 int nfrag
; /* Number of frags we have to produce */
308 int fragoff
; /* Where in the current opcode[] the frag ends */
314 int nrel
; /* Num of reloc strucs in use */
322 } reloc
[5]; /* Five is enough??? */
325 #define cpu_of_arch(x) ((x) & m68000up)
326 #define float_of_arch(x) ((x) & mfloat)
327 #define mmu_of_arch(x) ((x) & mmmu)
329 static struct m68k_it the_ins
; /* the instruction being assembled */
331 /* Macros for adding things to the m68k_it struct */
333 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
335 /* Like addword, but goes BEFORE general operands */
336 #define insop(w) {int z;\
337 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
338 the_ins.opcode[z]=the_ins.opcode[z-1];\
339 for(z=0;z<the_ins.nrel;z++)\
340 the_ins.reloc[z].n+=2;\
341 the_ins.opcode[opcode->m_codenum]=w;\
346 #define add_exp(beg,end) (\
347 the_ins.exprs[the_ins.nexp].e_beg=beg,\
348 the_ins.exprs[the_ins.nexp].e_end=end,\
349 &the_ins.exprs[the_ins.nexp++]\
353 /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
354 #define add_fix(width,exp,pc_rel) {\
355 the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
356 (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
357 the_ins.reloc[the_ins.nrel].add=adds((exp));\
358 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
359 the_ins.reloc[the_ins.nrel].off=offs((exp));\
360 the_ins.reloc[the_ins.nrel].wid=width;\
361 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
364 #define add_frag(add,off,type) {\
365 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
366 the_ins.fragb[the_ins.nfrag].fadd=add;\
367 the_ins.fragb[the_ins.nfrag].foff=off;\
368 the_ins.fragb[the_ins.nfrag++].fragty=type;\
371 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
373 #define seg(exp) ((exp)->e_exp.X_seg)
374 #define adds(exp) ((exp)->e_exp.X_add_symbol)
375 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
376 #define offs(exp) ((exp)->e_exp.X_add_number)
381 unsigned long m_opcode
;
384 enum m68k_architecture m_arch
;
385 struct m68k_incant
*m_next
;
390 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
391 #define gettwo(x) (((x)->m_opcode)&0xffff)
396 static char *crack_operand(char *str
, struct m68k_op
*opP
);
397 static int get_num(struct m68k_exp
*exp
, int ok
);
398 static int get_regs(int i
, char *str
, struct m68k_op
*opP
);
399 static int reverse_16_bits(int in
);
400 static int reverse_8_bits(int in
);
401 static int try_index(char **s
, struct m68k_op
*opP
);
402 static void install_gen_operand(int mode
, int val
);
403 static void install_operand(int mode
, int val
);
404 static void s_bss(void);
405 static void s_data1(void);
406 static void s_data2(void);
407 static void s_even(void);
408 static void s_proc(void);
410 #else /* not __STDC__ */
412 static char *crack_operand();
413 static int get_num();
414 static int get_regs();
415 static int reverse_16_bits();
416 static int reverse_8_bits();
417 static int try_index();
418 static void install_gen_operand();
419 static void install_operand();
421 void s_align_bytes();
422 static void s_data1();
423 static void s_data2();
424 static void s_even();
425 static void s_proc();
427 #endif /* not __STDC__ */
429 static enum m68k_architecture current_architecture
= 0;
431 /* BCC68000 is for patching in an extra jmp instruction for long offsets
432 on the 68000. The 68000 doesn't support long branches with branchs */
434 /* This table desribes how you change sizes for the various types of variable
435 size expressions. This version only supports two kinds. */
437 /* Note that calls to frag_var need to specify the maximum expansion needed */
438 /* This is currently 10 bytes for DBCC */
441 How far Forward this mode will reach:
442 How far Backward this mode will reach:
443 How many bytes this mode will add to the size of the frag
444 Which mode to go to if the offset won't fit in this one
448 { 1, 1, 0, 0 }, /* First entries aren't used */
449 { 1, 1, 0, 0 }, /* For no good reason except */
450 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
453 { (127), (-128), 0, TAB(ABRANCH
,SHORT
)},
454 { (32767), (-32768), 2, TAB(ABRANCH
,LONG
) },
458 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
459 { (32767), (-32768), 2, TAB(FBRANCH
,LONG
)},
463 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
464 { (32767), (-32768), 2, TAB(PCREL
,LONG
)},
468 { (127), (-128), 0, TAB(BCC68000
,SHORT
)},
469 { (32767), (-32768), 2, TAB(BCC68000
,LONG
) },
470 { 0, 0, 6, 0 }, /* jmp long space */
473 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
474 { (32767), (-32768), 2, TAB(DBCC
,LONG
) },
475 { 0, 0, 10, 0 }, /* bra/jmp long space */
478 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
479 { 32767, -32768, 2, TAB(PCLEA
,LONG
) },
485 /* These are the machine dependent pseudo-ops. These are included so
486 the assembler can work on the output from the SUN C compiler, which
490 /* This table describes all the machine specific pseudo-ops the assembler
491 has to support. The fields are:
492 pseudo-op name without dot
493 function to call to execute this pseudo-op
494 Integer arg to pass to the function
496 const pseudo_typeS md_pseudo_table
[] = {
497 { "data1", s_data1
, 0 },
498 { "data2", s_data2
, 0 },
500 { "even", s_even
, 0 },
501 { "skip", s_space
, 0 },
502 { "proc", s_proc
, 0 },
504 { "align", s_align_bytes
, 0 },
510 /* The mote pseudo ops are put into the opcode table, since they
511 don't start with a . they look like opcodes to gas.
513 extern void obj_coff_section();
515 const pseudo_typeS mote_pseudo_table
[] =
523 { "ds.l", s_space
,4},
525 { "ds.w", s_space
,2},
526 { "ds.b", s_space
,1},
528 { "xdef", s_globl
, 0},
529 { "align", s_align_ptwo
, 0},
531 { "sect", obj_coff_section
,0},
532 { "section", obj_coff_section
,0},
537 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
538 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
540 #define issbyte(x) ((x)>=-128 && (x)<=127)
541 #define isubyte(x) ((x)>=0 && (x)<=255)
542 #define issword(x) ((x)>=-32768 && (x)<=32767)
543 #define isuword(x) ((x)>=0 && (x)<=65535)
545 #define isbyte(x) ((x)>=-128 && (x)<=255)
546 #define isword(x) ((x)>=-32768 && (x)<=65535)
547 #define islong(x) (1)
549 extern char *input_line_pointer
;
556 /* JF these tables here are for speed at the expense of size */
557 /* You can replace them with the #if 0 versions if you really
558 need space and don't mind it running a bit slower */
560 static char mklower_table
[256];
561 #define mklower(c) (mklower_table[(unsigned char)(c)])
562 static char notend_table
[256];
563 static char alt_notend_table
[256];
564 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
565 alt_notend_table[(unsigned char)(s[1])])))
568 #define mklower(c) (isupper(c) ? tolower(c) : c)
572 /* JF modified this to handle cases where the first part of a symbol name
573 looks like a register */
576 * m68k_reg_parse() := if it looks like a register, return it's token &
577 * advance the pointer.
580 enum _register
m68k_reg_parse(ccp
)
585 if (isalpha(*start
) && is_name_beginner(*start
))
592 while (isalpha(c
) || isdigit(c
))
599 symbolP
= symbol_find(start
);
602 if (symbolP
&& S_GET_SEGMENT(symbolP
) == SEG_REGISTER
)
605 return S_GET_VALUE(symbolP
);
613 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
614 #define SKIP_W() { ss++; if(*ss==' ') ss++;}
616 /* Parse an index specification using Motorola syntax. */
619 try_moto_index(s
,opP
)
629 i
=m68k_reg_parse(&ss
);
630 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
631 opP
->error
="Invalid index register";
645 opP
->error
="Missing . in index register";
650 if(mklower(*ss
)=='w') opP
->isiz
=2;
651 else if(mklower(*ss
)=='l') opP
->isiz
=3;
653 opP
->error
="Size spec not .W or .L";
658 if(*ss
=='.' || *ss
=='*') {
668 opP
->error
="index multiplier not 1, 2, 4 or 8";
675 opP
->error
="Missing )";
686 * try_index := data_or_address_register + ')' + SKIP_W
687 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
689 * multiplier := <empty>
690 * | ':' + multiplier_number
693 * multiplier_number := '1' | '2' | '4' | '8' ;
695 * size_spec := 'l' | 'L' | 'w' | 'W' ;
697 * SKIP_W := <empty> | ' ' ;
701 static int try_index(s
,opP
)
710 i
=m68k_reg_parse(&ss
);
711 if(!(i
>=DATA
+0 && i
<=ADDR
+7)) { /* if i is not DATA or ADDR reg */
725 opP
->error
="Missing : in index register";
740 opP
->error
="Index register size spec not :w or :l";
752 if (cpu_of_arch(current_architecture
) < m68020
) {
753 opP
->error
="no index scaling in pre-68020's";
760 opP
->error
="index multiplier not 1, 2, 4 or 8";
767 opP
->error
="Missing )";
776 /* Ian Taylor expanded this function to accept both MIT and Motorola
777 syntax. I removed the old comment, since it was wrong. The syntax
778 this accepted even before my changes was complex and undocumented.
779 I mainly added a large case when the operand string does not
780 contain an '@', since the Motorola syntax does not use the '@'
786 register struct m68k_op
*opP
;
795 } /* Find the beginning of the string */
798 opP
->error
="Missing operand";
802 for(strend
= str
; *strend
; strend
++)
808 opP
->con1
=add_exp(str
,strend
);
811 } /* Guess what: A constant. Shar and enjoy */
813 i
= m68k_reg_parse(&str
);
816 if(*str
=='/' || *str
=='-') {
817 /* "Rm-Rn/Ro-Rp" Register list for MOVEM instruction */
819 return get_regs(i
,str
,opP
);
823 /* "Rn" Register Direct mode */
824 if(i
>=DATA
+0 && i
<=DATA
+7)
826 else if(i
>=ADDR
+0 && i
<=ADDR
+7)
837 if ((stmp
=strchr(str
,'@')) != 0) {
838 opP
->con1
=add_exp(str
,stmp
-1);
844 if ((current_architecture
& m68020up
) == 0) {
846 } /* if target is not a '20 or better */
849 if(*stmp
++!='(' || *strend
--!=')') {
850 opP
->error
="Malformed operand";
853 i
=try_index(&stmp
,opP
);
854 opP
->con2
=add_exp(stmp
,strend
);
862 } /* if there's an '@' */
864 #ifndef MIT_SYNTAX_ONLY
865 /* The operand has no '@'. Try to parse it using
867 /* Logic of the parsing switch(*str):
871 REG AREG or DREG or MSCR 3 or 2 or 13
872 REG- or REG/ REGLST 14
877 (EXPR,REG,INDX) AINDX 8
880 EXP2(REG,INDX) AINDX 8
883 REG means truth(m68k_reg_parse(&str))
884 INDX means truth(try_moto_index(&str,opP))
886 EXP2 means not REG and not '(' and not '-('
891 i
=m68k_reg_parse(&str
);
892 if((i
<ADDR
+0 || i
>ADDR
+7)
893 && (i
<DATA
+0 || i
>DATA
+7
894 || *str
!= ')' || str
[1] != '0')
895 && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
) {
896 /* Can't indirect off non address regs */
897 opP
->error
="Invalid indirect register";
905 /* "(An)" Address Register Indirect mode
906 or "(Dn)" for cas2. */
907 if (i
>=DATA
+0 && i
<=DATA
+7)
915 /* "(An)+" Register Indirect w Postincrement */
920 opP
->error
="Junk after indirect";
925 i
=try_moto_index(&str
,opP
);
926 if(i
==FAIL
) return FAIL
;
927 /* "(An,Rn)" Register Indirect with Index mode*/
932 opP
->error
="Bad indirect syntax";
937 /* "(EXPR,..." , a displacement */
941 if(stmp
=index(str
,',')) {
942 opP
->con1
=add_exp(str
,stmp
-1);
945 i
=m68k_reg_parse(&str
);
946 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
) {
947 /* Can't indirect off non address regs */
948 opP
->error
="Invalid indirect register";
954 /* "(d,An)" Register Indirect w Displacement */
960 i
=try_moto_index(&str
,opP
);
961 if(i
==FAIL
) return FAIL
;
962 /* "(d,An,Rn)" Register Indirect with Index */
967 opP
->error
="Bad indirect syntax";
972 opP
->error
="Invalid register";
978 opP
->con1
= add_exp(str
-1,strend
);
987 i
=m68k_reg_parse(&str
);
988 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
) {
989 /* Can't indirect off non address regs */
990 opP
->error
="Invalid indirect register";
998 /* "-(An)" Register Indirect with Predecrement */
1002 opP
->error
="Junk after indirect";
1005 opP
->error
="Bad indirect syntax";
1009 opP
->con1
= add_exp(str
-2,strend
);
1012 /* if '-' but not "-(', do nothing */
1015 /* whether *str=='-' or not */
1017 /* "EXP2" or "EXP2(REG..." */
1020 if(stmp
=index(str
,'(')) {
1023 opP
->con1
=add_exp(str
,stmp
-1);
1025 i
=m68k_reg_parse(&str
);
1026 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
1027 && i
!=ZPC
&& i
!=FAIL
) {
1028 /* Can't indirect off non address regs */
1029 opP
->error
="Invalid indirect register";
1035 /* "d(An)" Register Indirect w Displacement */
1041 i
=try_moto_index(&str
,opP
);
1042 if(i
==FAIL
) return FAIL
;
1043 /* "d(An,Rn)" Register Indirect with Index */
1048 opP
->error
="Bad indirect syntax";
1054 opP
->con1
= add_exp(ostr
,strend
);
1059 /* "EXP2" Absolute */
1062 if(strend
[-1]=='.' || strend
[-1]==':') {
1063 /* mode ==foo.[wl] */
1077 opP
->con1
=add_exp(str
,strend
);
1082 #else /* defined (MIT_SYNTAX_ONLY) */
1084 opP
->con1
=add_exp(str
,strend
);
1086 #endif /* defined (MIT_SYNTAX_ONLY) */
1091 /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
1092 if((i
<ADDR
+0 || i
>ADDR
+7) && i
!=PC
&& i
!=ZPC
&& i
!=FAIL
1093 && (str
[1] != '\0' || i
<DATA
+0 || i
>DATA
+7)) {
1094 opP
->error
="Invalid indirect register";
1102 if (i
<DATA
+0 || i
>DATA
+7)
1117 opP
->error
="Junk after indirect";
1120 /* Some kind of indexing involved. Lets find out how bad it is */
1121 i
=try_index(&str
,opP
);
1122 /* Didn't start with an index reg, maybe its offset or offset,reg */
1130 opP
->error
="Missing )";
1132 case ',': i
=0; break;
1133 case '(': i
++; break;
1134 case ')': --i
; break;
1137 /* if(str[-3]==':') {
1154 opP->error="Specified size isn't :w or :l";
1157 opP->con1=add_exp(beg_str,str-4);
1158 opP->con1->e_siz=siz;
1160 opP
->con1
=add_exp(beg_str
,str
-2);
1161 /* Should be offset,reg */
1163 i
=try_index(&str
,opP
);
1165 opP
->error
="Malformed index reg";
1170 /* We've now got offset) offset,reg) or reg) */
1173 /* Th-the-thats all folks */
1174 if (opP
->reg
== FAIL
) opP
->mode
= AINDX
; /* Other form of indirect */
1175 else if(opP
->ireg
== FAIL
) opP
->mode
= AOFF
;
1176 else opP
->mode
= AINDX
;
1179 /* Next thing had better be another @ */
1181 if (str
[1] == '(') {
1191 if ((current_architecture
& m68020up
) == 0) {
1193 } /* if target is not a '20 or better */
1196 if(opP
->ireg
!= FAIL
) {
1199 i
= try_index(&str
, opP
);
1201 opP
->error
= "Two index registers! not allowed!";
1205 i
= try_index(&str
, opP
);
1217 opP
->error
="Missing )";
1220 case ',': i
=0; break;
1221 case '(': i
++; break;
1222 case ')': --i
; break;
1226 opP
->con2
=add_exp(beg_str
,str
-2);
1228 if (str
[-1] == ',') {
1229 if (opP
->ireg
!= FAIL
) {
1230 opP
->error
= "Can't have two index regs";
1234 i
= try_index(&str
, opP
);
1237 opP
->error
= "malformed index reg";
1242 } else if (opP
->ireg
!= FAIL
) {
1252 opP
->error
="Junk after indirect";
1256 } /* m68k_ip_op() */
1261 short tc_coff_fix2rtype(fixP
)
1264 return (fixP
->fx_pcrel
?
1265 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
1266 fixP
->fx_size
== 2 ? R_PCRWORD
:
1268 (fixP
->fx_size
== 1 ? R_RELBYTE
:
1269 fixP
->fx_size
== 2 ? R_RELWORD
:
1277 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1281 struct m68k_op thark
;
1286 memset(&thark
, '\0', sizeof(thark
));
1287 if(!m68k_ip_op(buf
,&thark
)) printf("FAIL:");
1289 printf("op1 error %s in %s\n",thark
.error
,buf
);
1290 printf("mode %d, reg %d, ",thark
.mode
,thark
.reg
);
1292 printf("Constant: '%.*s',",1+thark
.e_const
-thark
.b_const
,thark
.b_const
);
1293 printf("ireg %d, isiz %d, imul %d ",thark
.ireg
,thark
.isiz
,thark
.imul
);
1295 printf("Iadd: '%.*s'",1+thark
.e_iadd
-thark
.b_iadd
,thark
.b_iadd
);
1304 static struct hash_control
* op_hash
= NULL
; /* handle of the OPCODE hash table
1305 NULL means any use before m68k_ip_begin()
1312 * This converts a string into a 68k instruction.
1313 * The string must be a bare single instruction in sun format
1314 * with RMS-style 68020 indirects
1317 * It provides some error messages: at most one fatal error message (which
1318 * stops the scan) and at most one warning message for each operand.
1319 * The 68k instruction is returned in exploded form, since we have no
1320 * knowledge of how you parse (or evaluate) your expressions.
1321 * We do however strip off and decode addressing modes and operation
1324 * This function's value is a string. If it is not "" then an internal
1325 * logic error was found: read this code to assign meaning to the string.
1326 * No argument string should generate such an error string:
1327 * it means a bug in our code, not in the user's text.
1329 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1333 /* JF this function no longer returns a useful value. Sorry */
1334 void m68k_ip (instring
)
1338 register struct m68k_op
*opP
;
1339 register struct m68k_incant
*opcode
;
1341 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1342 char *pdot
, *pdotmove
;
1347 char *crack_operand();
1348 LITTLENUM_TYPE words
[6];
1349 LITTLENUM_TYPE
*wordp
;
1350 unsigned long ok_arch
= 0;
1352 if (*instring
== ' ')
1353 instring
++; /* skip leading whitespace */
1355 /* Scan up to end of operation-code, which MUST end in end-of-string
1356 or exactly 1 space. */
1358 for (p
= instring
; *p
!= '\0'; p
++) {
1365 if (p
== instring
) {
1366 the_ins
.error
= "No operator";
1367 the_ins
.opcode
[0] = NULL
;
1368 /* the_ins.numo=1; */
1372 /* p now points to the end of the opcode name, probably whitespace.
1373 make sure the name is null terminated by clobbering the whitespace,
1374 look it up in the hash table, then fix it back.
1375 Remove a dot, first, since the opcode tables have none. */
1377 for (pdotmove
=pdot
; pdotmove
<p
; pdotmove
++)
1378 *pdotmove
=pdotmove
[1];
1384 opcode
= (struct m68k_incant
*)hash_find (op_hash
, instring
);
1388 for (pdotmove
=p
; pdotmove
>pdot
; pdotmove
--)
1389 *pdotmove
=pdotmove
[-1];
1394 if (opcode
== NULL
) {
1395 the_ins
.error
= "Unknown operator";
1396 the_ins
.opcode
[0] = NULL
;
1397 /* the_ins.numo=1; */
1401 /* found a legitimate opcode, start matching operands */
1402 while (*p
== ' ') ++p
;
1405 if (opcode
->m_operands
== 0) {
1406 char *old
= input_line_pointer
;
1408 input_line_pointer
= p
;
1409 /* Ahh - it's a motorola style psuedo op */
1410 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1411 ( mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1412 input_line_pointer
= old
;
1418 for(opP
= &the_ins
.operands
[0]; *p
; opP
++) {
1420 p
= crack_operand(p
, opP
);
1423 the_ins
.error
=opP
->error
;
1428 opsfound
= opP
- &the_ins
.operands
[0];
1430 /* This ugly hack is to support the floating pt opcodes in their standard form */
1431 /* Essentially, we fake a first enty of type COP#1 */
1432 if (opcode
->m_operands
[0]=='I') {
1435 for(n
=opsfound
;n
>0;--n
)
1436 the_ins
.operands
[n
]=the_ins
.operands
[n
-1];
1438 memset((char *)(&the_ins
.operands
[0]), '\0', sizeof(the_ins
.operands
[0]));
1439 the_ins
.operands
[0].mode
=MSCR
;
1440 the_ins
.operands
[0].reg
=COPNUM
; /* COP #1 */
1444 /* We've got the operands. Find an opcode that'll accept them */
1445 for (losing
= 0; ; ) {
1446 /* if we didn't get the right number of ops,
1447 or we have no common model with this pattern
1448 then reject this pattern. */
1450 if (opsfound
!= opcode
->m_opnum
1451 || ((opcode
->m_arch
& current_architecture
) == 0))
1454 ok_arch
|= opcode
->m_arch
;
1457 for (s
=opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++) {
1458 /* Warning: this switch is huge! */
1459 /* I've tried to organize the cases into this order:
1460 non-alpha first, then alpha by letter. lower-case goes directly
1461 before uppercase counterpart. */
1462 /* Code with multiple case ...: gets sorted by the lowest case ...
1463 it belongs to. I hope this makes sense. */
1466 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1467 || opP
->mode
== DREG
|| opP
->mode
== AREG
1468 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1469 || opP
->mode
== REGLST
)
1474 if(opP
->mode
!=IMMED
)
1479 t
=get_num(opP
->con1
,80);
1480 if(s
[1]=='b' && !isbyte(t
))
1482 else if(s
[1]=='w' && !isword(t
))
1489 if(opP
->mode
!=IMMED
)
1494 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1495 opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1500 if(opP
->mode
==MSCR
|| opP
->reg
==PC
||
1501 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1507 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1508 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
||
1509 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==REGLST
)
1514 if(opP
->mode
==MSCR
|| opP
->mode
==REGLST
)
1529 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1530 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1535 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1540 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1541 opP
->mode
==AINC
|| opP
->mode
==ADEC
|| opP
->mode
==IMMED
|| opP
->reg
==PC
||
1542 opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1547 if(opP
->mode
==MSCR
|| opP
->mode
==AREG
||
1548 opP
->mode
==IMMED
|| opP
->mode
==REGLST
)
1552 case '~': /* For now! (JF FOO is this right?) */
1553 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1554 opP
->mode
==AREG
|| opP
->mode
==IMMED
|| opP
->reg
==PC
|| opP
->reg
==ZPC
|| opP
->mode
==REGLST
)
1559 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1568 if (opP
->mode
!= AINDR
) {
1570 } /* if not address register indirect */
1573 if(opP
->mode
!=ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1574 && instring
[1] == 'b'
1575 && instring
[2] == 's'
1576 && instring
[3] == 'r'))
1581 if(opP
->mode
!=MSCR
|| opP
->reg
!=CCR
)
1585 case 'd': /* FOO This mode is a KLUDGE!! */
1586 if(opP
->mode
!=AOFF
&& (opP
->mode
!=ABSL
||
1587 opP
->con1
->e_beg
[0]!='(' || opP
->con1
->e_end
[0]!=')'))
1597 if(opP
->mode
!=MSCR
|| opP
->reg
<(FPREG
+0) || opP
->reg
>(FPREG
+7))
1602 if(opP
->mode
!=MSCR
|| opP
->reg
<COPNUM
||
1608 if (opP
->mode
!= MSCR
1611 || cpu_of_arch(current_architecture
) < m68010
/* before 68010 had none */
1612 || (cpu_of_arch(current_architecture
) < m68020
1616 && opP
->reg
!= VBR
) /* 68010's had only these */
1617 || (cpu_of_arch(current_architecture
) < m68040
1625 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1626 || (cpu_of_arch(current_architecture
) == m68040
/* 68040 has all but this */
1627 && opP
->reg
== CAAR
)) {
1629 } /* doesn't cut it */
1633 if(opP
->mode
!=IMMED
)
1639 if(opP
->mode
==DREG
|| opP
->mode
==AREG
|| opP
->mode
==FPREG
) {
1644 opP
->reg
=1<<(opP
->reg
-DATA
);
1646 } else if(opP
->mode
!=REGLST
) {
1648 } else if(s
[1]=='8' && opP
->reg
&0x0FFffFF)
1650 else if(s
[1]=='3' && opP
->reg
&0x7000000)
1655 if(opP
->mode
!=IMMED
)
1660 t
=get_num(opP
->con1
,80);
1661 if(!issbyte(t
) || isvar(opP
->con1
))
1667 if(opP
->mode
!=DREG
&& opP
->mode
!=IMMED
)
1672 if(opP
->mode
!=IMMED
)
1677 t
=get_num(opP
->con1
,80);
1678 if(t
<1 || t
>8 || isvar(opP
->con1
))
1684 if(opP
->mode
!=DREG
&& opP
->mode
!=AREG
)
1689 if (opP
->mode
!=AINDR
&& opP
->mode
!=DINDR
)
1694 if(opP
->mode
!=MSCR
|| !(opP
->reg
==FPI
|| opP
->reg
==FPS
|| opP
->reg
==FPC
))
1699 if(opP
->mode
!=MSCR
|| opP
->reg
!=SR
)
1704 if (opP
->mode
!= IMMED
)
1708 long t
= get_num (opP
->con1
, 80);
1709 if (t
< 0 || t
> 7 || isvar (opP
->con1
))
1715 if(opP
->mode
!=MSCR
|| opP
->reg
!=USP
)
1719 /* JF these are out of order. We could put them
1720 in order if we were willing to put up with
1721 bunches of #ifdef m68851s in the code.
1723 Don't forget that you need these operands
1724 to use 68030 MMU instructions. */
1726 /* Memory addressing mode used by pflushr */
1728 if(opP
->mode
==MSCR
|| opP
->mode
==DREG
||
1729 opP
->mode
==AREG
|| opP
->mode
==REGLST
)
1734 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1739 if (opP
->mode
!= MSCR
1740 || (opP
->reg
!= TC
&& opP
->reg
!= CAL
1741 && opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1746 if (opP
->reg
!= VAL
)
1751 if (opP
->mode
!= MSCR
1752 || (opP
->reg
!= DRP
&& opP
->reg
!= SRP
1753 && opP
->reg
!= CRP
))
1758 if (opP
->mode
!= MSCR
||
1759 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+7) &&
1760 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+7)))
1765 if (opP
->reg
!= PSR
)
1770 if (opP
->reg
!= PCSR
)
1778 && opP
->reg
!= BC
) {
1780 } /* not a cache specifier. */
1784 if (opP
->mode
!= ABSL
) {
1786 } /* not absolute */
1790 as_fatal("Internal error: Operand mode %c unknown in line %d of file \"%s\"",
1791 *s
, __LINE__
, __FILE__
);
1792 } /* switch on type of operand */
1796 } /* for each operand */
1797 } /* if immediately wrong */
1803 opcode
= opcode
->m_next
;
1807 && !(ok_arch
& current_architecture
))
1811 strcpy (buf
, "invalid instruction for this architecture; needs ");
1812 cp
= buf
+ strlen (buf
);
1816 strcpy (cp
, "fpu (68040 or 68881/68882)");
1819 strcpy (cp
, "mmu (68030 or 68851)");
1822 strcpy (cp
, "68020 or higher");
1825 strcpy (cp
, "68000 or higher");
1828 strcpy (cp
, "68010 or higher");
1832 int got_one
= 0, idx
;
1833 const static struct {
1834 enum m68k_architecture arch
;
1845 for (idx
= 0; idx
< sizeof (archs
)/sizeof (archs
[0]); idx
++)
1847 if (archs
[idx
].arch
& ok_arch
)
1851 strcpy (cp
, " or ");
1855 strcpy (cp
, archs
[idx
].name
);
1867 the_ins
.error
= "operands mismatch";
1869 } /* Fell off the end */
1874 /* now assemble it */
1876 the_ins
.args
=opcode
->m_operands
;
1877 the_ins
.numargs
=opcode
->m_opnum
;
1878 the_ins
.numo
=opcode
->m_codenum
;
1879 the_ins
.opcode
[0]=getone(opcode
);
1880 the_ins
.opcode
[1]=gettwo(opcode
);
1882 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++) {
1883 /* This switch is a doozy.
1884 Watch the first step; its a big one! */
1902 tmpreg
=0x3c; /* 7.4 */
1903 if (strchr("bwl",s
[1])) nextword
=get_num(opP
->con1
,80);
1904 else nextword
=nextword
=get_num(opP
->con1
,0);
1905 if(isvar(opP
->con1
))
1906 add_fix(s
[1],opP
->con1
,0);
1909 if(!isbyte(nextword
))
1910 opP
->error
="operand out of range";
1915 if(!isword(nextword
))
1916 opP
->error
="operand out of range";
1921 addword(nextword
>>16);
1943 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1944 *s
, s
[1], __LINE__
, __FILE__
);
1949 /* We gotta put out some float */
1950 if(seg(opP
->con1
)!=SEG_BIG
) {
1951 int_to_gen(nextword
);
1952 gen_to_words(words
,baseo
,(long int)outro
);
1953 for(wordp
=words
;baseo
--;wordp
++)
1957 if(offs(opP
->con1
)>0) {
1958 as_warn("Bignum assumed to be binary bit-pattern");
1959 if(offs(opP
->con1
)>baseo
) {
1960 as_warn("Bignum too big for %c format; truncated",s
[1]);
1961 offs(opP
->con1
)=baseo
;
1963 baseo
-=offs(opP
->con1
);
1964 for(wordp
=generic_bignum
+offs(opP
->con1
)-1;offs(opP
->con1
)--;--wordp
)
1970 gen_to_words(words
,baseo
,(long)outro
);
1971 for (wordp
=words
;baseo
--;wordp
++)
1975 tmpreg
=opP
->reg
-DATA
; /* 0.dreg */
1978 tmpreg
=0x08+opP
->reg
-ADDR
; /* 1.areg */
1981 tmpreg
=0x10+opP
->reg
-ADDR
; /* 2.areg */
1984 tmpreg
=0x20+opP
->reg
-ADDR
; /* 4.areg */
1987 tmpreg
=0x18+opP
->reg
-ADDR
; /* 3.areg */
1991 nextword
=get_num(opP
->con1
,80);
1992 /* Force into index mode. Hope this works */
1994 /* We do the first bit for 32-bit displacements,
1995 and the second bit for 16 bit ones. It is
1996 possible that we should make the default be
1997 WORD instead of LONG, but I think that'd
1998 break GCC, so we put up with a little
1999 inefficiency for the sake of working output.
2002 if( !issword(nextword
)
2003 || ( isvar(opP
->con1
)
2004 && ( ( opP
->con1
->e_siz
==0
2005 && flagseen
['l']==0)
2006 || opP
->con1
->e_siz
==3))) {
2009 tmpreg
=0x3B; /* 7.3 */
2011 tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
2012 if(isvar(opP
->con1
)) {
2014 add_frag(adds(opP
->con1
),
2016 TAB(PCLEA
,SZ_UNDEF
));
2020 add_fix('l',opP
->con1
,0);
2024 addword(nextword
>>16);
2027 tmpreg
=0x3A; /* 7.2 */
2029 tmpreg
=0x28+opP
->reg
-ADDR
; /* 5.areg */
2031 if(isvar(opP
->con1
)) {
2033 add_fix('w',opP
->con1
,1);
2035 add_fix('w',opP
->con1
,0);
2044 know(current_architecture
& m68020up
);
2045 /* intentional fall-through */
2048 baseo
=get_num(opP
->con1
,80);
2049 outro
=get_num(opP
->con2
,80);
2050 /* Figure out the 'addressing mode' */
2051 /* Also turn on the BASE_DISABLE bit, if needed */
2052 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
2053 tmpreg
=0x3b; /* 7.3 */
2056 } else if(opP
->reg
==FAIL
) {
2058 tmpreg
=0x30; /* 6.garbage */
2059 } else tmpreg
=0x30+opP
->reg
-ADDR
; /* 6.areg */
2061 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
2062 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
2064 /* Index register stuff */
2065 if(opP
->ireg
>=DATA
+0 && opP
->ireg
<=ADDR
+7) {
2066 nextword
|=(opP
->ireg
-DATA
)<<12;
2068 if(opP
->isiz
==0 || opP
->isiz
==3)
2072 case 2: nextword
|=0x200; break;
2073 case 4: nextword
|=0x400; break;
2074 case 8: nextword
|=0x600; break;
2075 default: as_fatal("failed sanity check.");
2078 GET US OUT OF HERE! */
2080 /* Must be INDEX, with an index
2081 register. Address register
2082 cannot be ZERO-PC, and either
2083 :b was forced, or we know
2085 if( opP
->mode
==AINDX
2090 && !isvar(opP
->con1
)))) {
2091 nextword
+=baseo
&0xff;
2093 if(isvar(opP
->con1
))
2094 add_fix('B',opP
->con1
,0);
2098 nextword
|=0x40; /* No index reg */
2100 /* It aint simple */
2102 /* If the guy specified a width, we assume that
2103 it is wide enough. Maybe it isn't. If so, we lose
2107 if(isvar(opP
->con1
) || !issword(baseo
)) {
2118 as_warn("Byte dispacement won't work. Defaulting to :w");
2127 /* Figure out innner displacement stuff */
2128 if(opP
->mode
!=AINDX
) {
2131 if(isvar(opP
->con2
) || !issword(outro
)) {
2142 as_warn("Byte dispacement won't work. Defaulting to :w");
2150 if(opP
->mode
==APODX
) nextword
|=0x04;
2151 else if(opP
->mode
==AMIND
) nextword
|=0x40;
2155 if(isvar(opP
->con1
)) {
2156 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
2157 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,1);
2158 opP
->con1
->e_exp
.X_add_number
+=6;
2160 add_fix(siz1
==3 ? 'l' : 'w',opP
->con1
,0);
2167 if(isvar(opP
->con2
)) {
2168 if(opP
->reg
==PC
|| opP
->reg
==ZPC
) {
2169 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,1);
2170 opP
->con1
->e_exp
.X_add_number
+=6;
2172 add_fix(siz2
==3 ? 'l' : 'w',opP
->con2
,0);
2182 nextword
=get_num(opP
->con1
,80);
2183 switch(opP
->con1
->e_siz
) {
2185 as_warn("Unknown size for absolute reference");
2187 if(!isvar(opP
->con1
) && issword(offs(opP
->con1
))) {
2188 tmpreg
=0x38; /* 7.0 */
2192 /* Don't generate pc relative code
2193 on 68010 and 68000 */
2196 && seg(opP
->con1
) == SEG_TEXT
2197 && now_seg
== SEG_TEXT
2198 && cpu_of_arch(current_architecture
) >= m68020
2200 && !strchr("~%&$?", s
[0])) {
2201 tmpreg
=0x3A; /* 7.2 */
2202 add_frag(adds(opP
->con1
),
2204 TAB(PCREL
,SZ_UNDEF
));
2207 case 3: /* Fall through into long */
2208 if(isvar(opP
->con1
))
2209 add_fix('l',opP
->con1
,0);
2211 tmpreg
=0x39; /* 7.1 mode */
2212 addword(nextword
>>16);
2217 if(isvar(opP
->con1
))
2218 add_fix('w',opP
->con1
,0);
2220 tmpreg
=0x38; /* 7.0 mode */
2226 as_bad("invalid indirect register");
2230 as_bad("unknown/incorrect operand");
2233 install_gen_operand(s
[1],tmpreg
);
2238 switch(s
[1]) { /* JF: I hate floating point! */
2253 tmpreg
=get_num(opP
->con1
,tmpreg
);
2254 if(isvar(opP
->con1
))
2255 add_fix(s
[1],opP
->con1
,0);
2257 case 'b': /* Danger: These do no check for
2258 certain types of overflow.
2261 opP
->error
="out of range";
2263 if(isvar(opP
->con1
))
2264 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
2268 opP
->error
="out of range";
2270 if(isvar(opP
->con1
))
2271 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
2274 insop(tmpreg
); /* Because of the way insop works, we put these two out backwards */
2276 if(isvar(opP
->con1
))
2277 the_ins
.reloc
[the_ins
.nrel
-1].n
=(opcode
->m_codenum
)*2;
2283 install_operand(s
[1],tmpreg
);
2286 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
2294 install_operand(s
[1],opP
->reg
-ADDR
);
2298 tmpreg
=get_num(opP
->con1
,80);
2301 /* Needs no offsetting */
2302 add_fix('B',opP
->con1
,1);
2305 /* Offset the displacement to be relative to byte disp location */
2306 opP
->con1
->e_exp
.X_add_number
+=2;
2307 add_fix('w',opP
->con1
,1);
2312 if (cpu_of_arch(current_architecture
) < m68020
) /* 68000 or 010 */
2313 as_warn("Can't use long branches on 68000/68010");
2314 the_ins
.opcode
[the_ins
.numo
-1]|=0xff;
2315 /* Offset the displacement to be relative to byte disp location */
2316 opP
->con1
->e_exp
.X_add_number
+=4;
2317 add_fix('l',opP
->con1
,1);
2322 if(subs(opP
->con1
)) /* We can't relax it */
2325 /* This could either be a symbol, or an
2326 absolute address. No matter, the
2327 frag hacking will finger it out.
2328 Not quite: it can't switch from
2329 BRANCH to BCC68000 for the case
2330 where opnd is absolute (it needs
2331 to use the 68000 hack since no
2332 conditional abs jumps). */
2333 if (((cpu_of_arch(current_architecture
) < m68020
) || (0==adds(opP
->con1
)))
2334 && (the_ins
.opcode
[0] >= 0x6200)
2335 && (the_ins
.opcode
[0] <= 0x6f00)) {
2336 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(BCC68000
,SZ_UNDEF
));
2338 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(ABRANCH
,SZ_UNDEF
));
2342 if(isvar(opP
->con1
)) {
2343 /* check for DBcc instruction */
2344 if ((the_ins
.opcode
[0] & 0xf0f8) ==0x50c8) {
2345 /* size varies if patch */
2346 /* needed for long form */
2347 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(DBCC
,SZ_UNDEF
));
2352 opP
->con1
->e_exp
.X_add_number
+=2;
2353 add_fix('w',opP
->con1
,1);
2357 case 'C': /* Fixed size LONG coproc branches */
2358 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
2359 /* Offset the displacement to be relative to byte disp location */
2360 /* Coproc branches don't have a byte disp option, but they are
2361 compatible with the ordinary branches, which do... */
2362 opP
->con1
->e_exp
.X_add_number
+=4;
2363 add_fix('l',opP
->con1
,1);
2367 case 'c': /* Var size Coprocesssor branches */
2368 if(subs(opP
->con1
)) {
2369 add_fix('l',opP
->con1
,1);
2370 add_frag((symbolS
*)0,(long)0,TAB(FBRANCH
,LONG
));
2371 } else if(adds(opP
->con1
)) {
2372 add_frag(adds(opP
->con1
),offs(opP
->con1
),TAB(FBRANCH
,SZ_UNDEF
));
2374 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2375 the_ins
.opcode
[the_ins
.numo
-1]|=0x40;
2376 add_fix('l',opP
->con1
,1);
2382 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
2383 s
[1], __LINE__
, __FILE__
);
2387 case 'C': /* Ignore it */
2390 case 'd': /* JF this is a kludge */
2391 if(opP
->mode
==AOFF
) {
2392 install_operand('s',opP
->reg
-ADDR
);
2396 tmpP
=opP
->con1
->e_end
-2;
2398 opP
->con1
->e_end
-=4; /* point to the , */
2399 baseo
=m68k_reg_parse(&tmpP
);
2400 if(baseo
<ADDR
+0 || baseo
>ADDR
+7) {
2401 as_bad("Unknown address reg, using A0");
2404 install_operand('s',baseo
);
2406 tmpreg
=get_num(opP
->con1
,80);
2407 if(!issword(tmpreg
)) {
2408 as_warn("Expression out of range, using 0");
2415 install_operand(s
[1],opP
->reg
-DATA
);
2419 install_operand(s
[1],opP
->reg
-FPREG
);
2423 tmpreg
=1+opP
->reg
-COPNUM
;
2426 install_operand(s
[1],tmpreg
);
2429 case 'J': /* JF foo */
2431 case SFC
: tmpreg
=0x000; break;
2432 case DFC
: tmpreg
=0x001; break;
2433 case CACR
: tmpreg
=0x002; break;
2434 case TC
: tmpreg
=0x003; break;
2435 case ITT0
: tmpreg
=0x004; break;
2436 case ITT1
: tmpreg
=0x005; break;
2437 case DTT0
: tmpreg
=0x006; break;
2438 case DTT1
: tmpreg
=0x007; break;
2440 case USP
: tmpreg
=0x800; break;
2441 case VBR
: tmpreg
=0x801; break;
2442 case CAAR
: tmpreg
=0x802; break;
2443 case MSP
: tmpreg
=0x803; break;
2444 case ISP
: tmpreg
=0x804; break;
2445 case MMUSR
: tmpreg
=0x805; break;
2446 case URP
: tmpreg
=0x806; break;
2447 case SRP
: tmpreg
=0x807; break;
2449 as_fatal("failed sanity check.");
2451 install_operand(s
[1],tmpreg
);
2455 tmpreg
=get_num(opP
->con1
,55);
2456 install_operand(s
[1],tmpreg
&0x7f);
2462 if(tmpreg
&0x7FF0000)
2463 as_bad("Floating point register in register list");
2464 insop(reverse_16_bits(tmpreg
));
2466 if(tmpreg
&0x700FFFF)
2467 as_bad("Wrong register in floating-point reglist");
2468 install_operand(s
[1],reverse_8_bits(tmpreg
>>16));
2475 if(tmpreg
&0x7FF0000)
2476 as_bad("Floating point register in register list");
2478 } else if(s
[1]=='8') {
2479 if(tmpreg
&0x0FFFFFF)
2480 as_bad("incorrect register in reglist");
2481 install_operand(s
[1],tmpreg
>>24);
2483 if(tmpreg
&0x700FFFF)
2484 as_bad("wrong register in floating-point reglist");
2486 install_operand(s
[1],tmpreg
>>16);
2491 install_operand(s
[1],get_num(opP
->con1
,60));
2495 tmpreg
= (opP
->mode
==DREG
)
2496 ? 0x20+opP
->reg
-DATA
2497 : (get_num(opP
->con1
,40)&0x1F);
2498 install_operand(s
[1],tmpreg
);
2502 tmpreg
=get_num(opP
->con1
,10);
2505 install_operand(s
[1],tmpreg
);
2510 /* This depends on the fact that ADDR registers are
2511 eight more than their corresponding DATA regs, so
2512 the result will have the ADDR_REG bit set */
2513 install_operand(s
[1],opP
->reg
-DATA
);
2517 if(opP
->reg
==FPI
) tmpreg
=0x1;
2518 else if(opP
->reg
==FPS
) tmpreg
=0x2;
2519 else if(opP
->reg
==FPC
) tmpreg
=0x4;
2520 else as_fatal("failed sanity check.");
2521 install_operand(s
[1],tmpreg
);
2524 case 'S': /* Ignore it */
2528 install_operand(s
[1],get_num(opP
->con1
,30));
2531 case 'U': /* Ignore it */
2536 case NC
: tmpreg
= 0; break;
2537 case DC
: tmpreg
= 1; break;
2538 case IC
: tmpreg
= 2; break;
2539 case BC
: tmpreg
= 3; break;
2541 as_fatal("failed sanity check");
2542 } /* switch on cache token */
2543 install_operand(s
[1], tmpreg
);
2546 /* JF: These are out of order, I fear. */
2556 as_fatal("failed sanity check.");
2558 install_operand(s
[1],tmpreg
);
2579 as_fatal("failed sanity check.");
2581 install_operand(s
[1],tmpreg
);
2585 if (opP
->reg
== VAL
)
2587 as_fatal("failed sanity check.");
2602 as_fatal("failed sanity check.");
2604 install_operand(s
[1],tmpreg
);
2609 case BAD
: case BAD
+1: case BAD
+2: case BAD
+3:
2610 case BAD
+4: case BAD
+5: case BAD
+6: case BAD
+7:
2611 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2614 case BAC
: case BAC
+1: case BAC
+2: case BAC
+3:
2615 case BAC
+4: case BAC
+5: case BAC
+6: case BAC
+7:
2616 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2620 as_fatal("failed sanity check.");
2622 install_operand(s
[1], tmpreg
);
2625 know(opP
->reg
== PSR
);
2628 know(opP
->reg
== PCSR
);
2641 as_fatal ("failed sanity check");
2643 install_operand (s
[1], tmpreg
);
2646 tmpreg
= get_num (opP
->con1
, 20);
2647 install_operand (s
[1], tmpreg
);
2649 case '_': /* used only for move16 absolute 32-bit address */
2650 tmpreg
=get_num(opP
->con1
,80);
2651 addword (tmpreg
>> 16);
2652 addword (tmpreg
& 0xFFFF);
2655 as_fatal("Internal error: Operand type %c unknown in line %d of file \"%s\"",
2656 s
[0], __LINE__
, __FILE__
);
2660 /* By the time whe get here (FINALLY) the_ins contains the complete
2661 instruction, ready to be emitted. . . */
2665 * get_regs := '/' + ?
2666 * | '-' + <register>
2667 * | '-' + <register> + ?
2672 * The idea here must be to scan in a set of registers but I don't
2673 * understand it. Looks awfully sloppy to me but I don't have any doc on
2680 static int get_regs(i
,str
,opP
)
2682 struct m68k_op
*opP
;
2685 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2686 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2687 unsigned long cur_regs
= 0;
2691 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2692 else if(x==FPS) cur_regs|=(1<<25);\
2693 else if(x==FPC) cur_regs|=(1<<26);\
2694 else cur_regs|=(1<<(x-1)); }
2701 } else if(*str
=='-') {
2703 reg2
=m68k_reg_parse(&str
);
2704 if(reg2
<DATA
|| reg2
>=FPREG
+8 || reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
) {
2705 opP
->error
="unknown register in register list";
2714 } else if(*str
=='\0') {
2718 opP
->error
="unknow character in register list";
2721 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2724 reg1
=m68k_reg_parse(&str
);
2725 if((reg1
<DATA
|| reg1
>=FPREG
+8) && !(reg1
==FPI
|| reg1
==FPS
|| reg1
==FPC
)) {
2726 opP
->error
="unknown register in register list";
2734 static int reverse_16_bits(in
)
2740 static int mask
[16] = {
2741 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2742 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2749 } /* reverse_16_bits() */
2751 static int reverse_8_bits(in
)
2757 static int mask
[8] = {
2758 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2766 } /* reverse_8_bits() */
2768 static void install_operand(mode
,val
)
2774 the_ins
.opcode
[0]|=val
& 0xFF; /* JF FF is for M kludge */
2777 the_ins
.opcode
[0]|=val
<<9;
2780 the_ins
.opcode
[1]|=val
<<12;
2783 the_ins
.opcode
[1]|=val
<<6;
2786 the_ins
.opcode
[1]|=val
;
2789 the_ins
.opcode
[2]|=val
<<12;
2792 the_ins
.opcode
[2]|=val
<<6;
2795 /* DANGER! This is a hack to force cas2l and cas2w cmds
2796 to be three words long! */
2798 the_ins
.opcode
[2]|=val
;
2801 the_ins
.opcode
[1]|=val
<<7;
2804 the_ins
.opcode
[1]|=val
<<10;
2808 the_ins
.opcode
[1]|=val
<<5;
2813 the_ins
.opcode
[1]|=(val
<<10)|(val
<<7);
2816 the_ins
.opcode
[1]|=(val
<<12)|val
;
2819 the_ins
.opcode
[0]|=val
=0xff;
2822 the_ins
.opcode
[0]|=val
<<9;
2825 the_ins
.opcode
[1]|=val
;
2828 the_ins
.opcode
[1]|=val
;
2829 the_ins
.numo
++; /* What a hack */
2832 the_ins
.opcode
[1]|=val
<<4;
2839 the_ins
.opcode
[0] |= (val
<< 6);
2842 the_ins
.opcode
[1] = (val
>> 16);
2843 the_ins
.opcode
[2] = val
& 0xffff;
2847 as_fatal("failed sanity check.");
2849 } /* install_operand() */
2851 static void install_gen_operand(mode
,val
)
2857 the_ins
.opcode
[0]|=val
;
2860 /* This is a kludge!!! */
2861 the_ins
.opcode
[0]|=(val
&0x07)<<9|(val
&0x38)<<3;
2870 the_ins
.opcode
[0]|=val
;
2872 /* more stuff goes here */
2874 as_fatal("failed sanity check.");
2876 } /* install_gen_operand() */
2879 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2880 * then deal with the bitfield hack.
2883 static char *crack_operand(str
,opP
)
2885 register struct m68k_op
*opP
;
2887 register int parens
;
2889 register char *beg_str
;
2895 for(parens
=0;*str
&& (parens
>0 || notend(str
));str
++) {
2896 if(*str
=='(') parens
++;
2897 else if(*str
==')') {
2898 if(!parens
) { /* ERROR */
2899 opP
->error
="Extra )";
2905 if(!*str
&& parens
) { /* ERROR */
2906 opP
->error
="Missing )";
2911 if(m68k_ip_op(beg_str
,opP
)==FAIL
) {
2917 c
= *++str
; /* JF bitfield hack */
2921 as_bad("Missing operand");
2926 /* See the comment up above where the #define notend(... is */
2931 if(*s
==',') return 0;
2932 if(*s
=='{' || *s
=='}')
2934 if(*s
!=':') return 1;
2935 /* This kludge here is for the division cmd, which is a kludge */
2936 if(index("aAdD#",s
[1])) return 0;
2941 /* This is the guts of the machine-dependent assembler. STR points to a
2942 machine dependent instruction. This function is supposed to emit
2943 the frags/bytes it assembles to.
2947 insert_reg(regname
, regnum
)
2953 symbol_table_insert(symbol_new(regname
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2955 for (i
= 0; regname
[i
]; i
++)
2956 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
2959 symbol_table_insert(symbol_new(buf
, SEG_REGISTER
, regnum
, &zero_address_frag
));
2962 static const struct {
3066 /* 68ec030 versions of same */
3069 /* 68ec030 access control unit, identical to 030 MMU status reg */
3081 for (i
= 0; init_table
[i
].name
; i
++)
3082 insert_reg(init_table
[i
].name
, init_table
[i
].number
);
3095 int shorts_this_frag
;
3096 static int done_first_time
;
3098 if (!done_first_time
)
3100 done_first_time
= 1;
3102 if (cpu_of_arch (current_architecture
) == 0)
3104 enum m68k_architecture cpu_type
;
3109 if (strcmp (TARGET_CPU
, "m68000") == 0)
3111 else if (strcmp (TARGET_CPU
, "m68010") == 0)
3113 else if (strcmp (TARGET_CPU
, "m68020") == 0
3114 || strcmp (TARGET_CPU
, "m68k") == 0)
3116 else if (strcmp (TARGET_CPU
, "m68030") == 0)
3118 else if (strcmp (TARGET_CPU
, "m68040") == 0)
3124 /* If float or mmu were specified, just default cpu. */
3125 if (current_architecture
!= 0)
3126 current_architecture
|= cpu_type
;
3129 if ((cpu_type
& m68020up
) != 0)
3130 current_architecture
= (cpu_type
3139 current_architecture
= cpu_type
;
3142 if (cpu_of_arch (current_architecture
) == m68000
3143 && (current_architecture
& m68881
) != 0)
3145 as_bad ("incompatible processors 68000 and 68881 specified");
3147 done_first_time
= 1;
3150 memset((char *)(&the_ins
), '\0', sizeof(the_ins
)); /* JF for paranoia sake */
3154 for(n
=the_ins
.numargs
;n
;--n
)
3155 if(the_ins
.operands
[n
].error
) {
3156 er
=the_ins
.operands
[n
].error
;
3161 as_bad("%s -- statement `%s' ignored",er
,str
);
3165 if(the_ins
.nfrag
==0) { /* No frag hacking involved; just put it out */
3166 toP
=frag_more(2*the_ins
.numo
);
3167 fromP
= &the_ins
.opcode
[0];
3168 for(m
=the_ins
.numo
;m
;--m
) {
3169 md_number_to_chars(toP
,(long)(*fromP
),2);
3173 /* put out symbol-dependent info */
3174 for(m
=0;m
<the_ins
.nrel
;m
++) {
3175 switch(the_ins
.reloc
[m
].wid
) {
3192 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins
.reloc
[m
].wid
);
3196 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
3198 the_ins
.reloc
[m
].add
,
3199 the_ins
.reloc
[m
].sub
,
3200 the_ins
.reloc
[m
].off
,
3201 the_ins
.reloc
[m
].pcrel
,
3207 /* There's some frag hacking */
3208 for(n
=0,fromP
= &the_ins
.opcode
[0];n
<the_ins
.nfrag
;n
++) {
3211 if(n
==0) wid
=2*the_ins
.fragb
[n
].fragoff
;
3212 else wid
=2*(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
3216 for(m
=wid
/2;m
;--m
) {
3217 md_number_to_chars(toP
,(long)(*fromP
),2);
3222 for(m
=0;m
<the_ins
.nrel
;m
++) {
3223 if((the_ins
.reloc
[m
].n
)>= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */) {
3224 the_ins
.reloc
[m
].n
-= 2*shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */;
3227 wid
=the_ins
.reloc
[m
].wid
;
3230 the_ins
.reloc
[m
].wid
=0;
3231 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
3234 (toP
-frag_now
->fr_literal
)-the_ins
.numo
*2+the_ins
.reloc
[m
].n
,
3236 the_ins
.reloc
[m
].add
,
3237 the_ins
.reloc
[m
].sub
,
3238 the_ins
.reloc
[m
].off
,
3239 the_ins
.reloc
[m
].pcrel
,
3242 /* know(the_ins.fragb[n].fadd); */
3243 (void)frag_var(rs_machine_dependent
,10,0,(relax_substateT
)(the_ins
.fragb
[n
].fragty
),
3244 the_ins
.fragb
[n
].fadd
,the_ins
.fragb
[n
].foff
,to_beg_P
);
3246 n
=(the_ins
.numo
-the_ins
.fragb
[n
-1].fragoff
);
3249 toP
=frag_more(n
*sizeof(short));
3251 md_number_to_chars(toP
,(long)(*fromP
),2);
3257 for(m
=0;m
<the_ins
.nrel
;m
++) {
3260 wid
=the_ins
.reloc
[m
].wid
;
3263 the_ins
.reloc
[m
].wid
=0;
3264 wid
= (wid
=='b') ? 1 : (wid
=='w') ? 2 : (wid
=='l') ? 4 : 4000;
3267 (the_ins
.reloc
[m
].n
+ toP
-frag_now
->fr_literal
)-/* the_ins.numo */ shorts_this_frag
*2,
3269 the_ins
.reloc
[m
].add
,
3270 the_ins
.reloc
[m
].sub
,
3271 the_ins
.reloc
[m
].off
,
3272 the_ins
.reloc
[m
].pcrel
,
3283 * md_begin -- set up hash tables with 68000 instructions.
3284 * similar to what the vax assembler does. ---phr
3286 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3287 a copy of it at runtime, adding in the information we want but isn't
3288 there. I think it'd be better to have an awk script hack the table
3289 at compile time. Or even just xstr the table and use it as-is. But
3290 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3293 register const struct m68k_opcode
*ins
;
3294 register struct m68k_incant
*hack
,
3296 register char *retval
= 0; /* empty string, or error msg text */
3297 register unsigned int i
;
3300 if ((op_hash
= hash_new()) == NULL
)
3301 as_fatal("Virtual memory exhausted");
3303 obstack_begin(&robyn
,4000);
3304 for (ins
= m68k_opcodes
; ins
< endop
; ins
++) {
3305 hack
=slak
=(struct m68k_incant
*)obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
3307 /* we *could* ignore insns that don't match our
3308 arch here but just leaving them out of the
3310 slak
->m_operands
=ins
->args
;
3311 slak
->m_opnum
=strlen(slak
->m_operands
)/2;
3312 slak
->m_arch
= ins
->arch
;
3313 slak
->m_opcode
=ins
->opcode
;
3314 /* This is kludgey */
3315 slak
->m_codenum
=((ins
->match
)&0xffffL
) ? 2 : 1;
3316 if((ins
+1)!=endop
&& !strcmp(ins
->name
,(ins
+1)->name
)) {
3317 slak
->m_next
=(struct m68k_incant
*) obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
3324 retval
= hash_insert (op_hash
, ins
->name
,(char *)hack
);
3325 /* Didn't his mommy tell him about null pointers? */
3326 if(retval
&& *retval
)
3327 as_bad("Internal Error: Can't hash %s: %s",ins
->name
,retval
);
3330 for (i
= 0; i
< sizeof(mklower_table
) ; i
++)
3331 mklower_table
[i
] = (isupper(c
= (char) i
)) ? tolower(c
) : c
;
3333 for (i
= 0 ; i
< sizeof(notend_table
) ; i
++) {
3334 notend_table
[i
] = 0;
3335 alt_notend_table
[i
] = 0;
3337 notend_table
[','] = 1;
3338 notend_table
['{'] = 1;
3339 notend_table
['}'] = 1;
3340 alt_notend_table
['a'] = 1;
3341 alt_notend_table
['A'] = 1;
3342 alt_notend_table
['d'] = 1;
3343 alt_notend_table
['D'] = 1;
3344 alt_notend_table
['#'] = 1;
3345 alt_notend_table
['f'] = 1;
3346 alt_notend_table
['F'] = 1;
3347 #ifdef REGISTER_PREFIX
3348 alt_notend_table
[REGISTER_PREFIX
] = 1;
3351 #ifndef MIT_SYNTAX_ONLY
3352 /* Insert pseudo ops, these have to go into the opcode table since
3353 gas expects pseudo ops to start with a dot */
3356 while (mote_pseudo_table
[n
].poc_name
)
3358 hack
=(struct m68k_incant
*)
3359 obstack_alloc(&robyn
,sizeof(struct m68k_incant
));
3360 hash_insert(op_hash
,
3361 mote_pseudo_table
[n
].poc_name
, (char *)hack
);
3362 hack
->m_operands
= 0;
3373 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
3374 || (*s == ':' && strchr("aAdD#", s[1]))) \
3378 /* This funciton is called once, before the assembler exits. It is
3379 supposed to do any final cleanup for this part of the assembler.
3386 /* Equal to MAX_PRECISION in atof-ieee.c */
3387 #define MAX_LITTLENUMS 6
3389 /* Turn a string in input_line_pointer into a floating point constant of type
3390 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3391 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
3394 md_atof(type
,litP
,sizeP
)
3400 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3401 LITTLENUM_TYPE
*wordP
;
3432 return "Bad call to MD_ATOF()";
3434 t
=atof_ieee(input_line_pointer
,type
,words
);
3436 input_line_pointer
=t
;
3438 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
3439 for(wordP
=words
;prec
--;) {
3440 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
3441 litP
+=sizeof(LITTLENUM_TYPE
);
3443 return ""; /* Someone should teach Dean about null pointers */
3446 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
3447 for use in the a.out file, and stores them in the array pointed to by buf.
3448 This knows about the endian-ness of the target machine and does
3449 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
3450 2 (short) and 4 (long) Floating numbers are put out as a series of
3451 LITTLENUMS (shorts, here at least)
3454 md_number_to_chars(buf
,val
,n
)
3474 as_fatal("failed sanity check.");
3479 md_apply_fix(fixP
, val
)
3483 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3485 switch(fixP
->fx_size
) {
3500 BAD_CASE (fixP
->fx_size
);
3505 /* *fragP has been relaxed to its final size, and now needs to have
3506 the bytes inside it modified to conform to the new size There is UGLY
3510 md_convert_frag(headers
, fragP
)
3511 object_headers
*headers
;
3512 register fragS
*fragP
;
3517 /* Address in object code of the displacement. */
3518 register int object_address
= fragP
-> fr_fix
+ fragP
-> fr_address
;
3520 #ifdef IBM_COMPILER_SUX
3521 /* This is wrong but it convinces the native rs6000 compiler to
3522 generate the code we want. */
3523 register char *buffer_address
= fragP
-> fr_literal
;
3524 buffer_address
+= fragP
-> fr_fix
;
3525 #else /* IBM_COMPILER_SUX */
3526 /* Address in gas core of the place to store the displacement. */
3527 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3528 #endif /* IBM_COMPILER_SUX */
3530 /* No longer true: know(fragP->fr_symbol); */
3532 /* The displacement of the address, from current location. */
3533 disp
= fragP
->fr_symbol
? S_GET_VALUE(fragP
->fr_symbol
) : 0;
3534 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3536 switch(fragP
->fr_subtype
) {
3537 case TAB(BCC68000
,BYTE
):
3538 case TAB(ABRANCH
,BYTE
):
3539 know(issbyte(disp
));
3541 as_bad("short branch with zero offset: use :w");
3542 fragP
->fr_opcode
[1]=disp
;
3545 case TAB(DBCC
,SHORT
):
3546 know(issword(disp
));
3549 case TAB(BCC68000
,SHORT
):
3550 case TAB(ABRANCH
,SHORT
):
3551 know(issword(disp
));
3552 fragP
->fr_opcode
[1]=0x00;
3555 case TAB(ABRANCH
,LONG
):
3556 if (cpu_of_arch(current_architecture
) < m68020
) {
3557 if (fragP
->fr_opcode
[0]==0x61) {
3558 fragP
->fr_opcode
[0]= 0x4E;
3559 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3560 subseg_change(SEG_TEXT
, 0);
3573 } else if (fragP
->fr_opcode
[0]==0x60) {
3574 fragP
->fr_opcode
[0]= 0x4E;
3575 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3576 subseg_change(SEG_TEXT
, 0);
3577 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
,0,
3582 as_bad("Long branch offset not supported.");
3585 fragP
->fr_opcode
[1]=0xff;
3589 case TAB(BCC68000
,LONG
):
3590 /* only Bcc 68000 instructions can come here */
3591 /* change bcc into b!cc/jmp absl long */
3592 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3593 fragP
->fr_opcode
[1] = 0x6; /* branch offset = 6 */
3595 /* JF: these used to be fr_opcode[2,3], but they may be in a
3596 different frag, in which case refering to them is a no-no.
3597 Only fr_opcode[0,1] are guaranteed to work. */
3598 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3599 *buffer_address
++ = 0xf9;
3600 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3601 subseg_change(SEG_TEXT
,0);
3602 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3608 case TAB(DBCC
,LONG
):
3609 /* only DBcc 68000 instructions can come here */
3610 /* change dbcc into dbcc/jmp absl long */
3611 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3612 *buffer_address
++ = 0x00; /* branch offset = 4 */
3613 *buffer_address
++ = 0x04;
3614 *buffer_address
++ = 0x60; /* put in bra pc+6 */
3615 *buffer_address
++ = 0x06;
3616 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
3617 *buffer_address
++ = 0xf9;
3619 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
3620 subseg_change(SEG_TEXT
,0);
3621 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3627 case TAB(FBRANCH
,SHORT
):
3628 know((fragP
->fr_opcode
[1]&0x40)==0);
3631 case TAB(FBRANCH
,LONG
):
3632 fragP
->fr_opcode
[1]|=0x40; /* Turn on LONG bit */
3635 case TAB(PCREL
,SHORT
):
3638 case TAB(PCREL
,LONG
):
3639 /* The thing to do here is force it to ABSOLUTE LONG, since
3640 PCREL is really trying to shorten an ABSOLUTE address anyway */
3641 /* JF FOO This code has not been tested */
3642 subseg_change(SEG_TEXT
,0);
3643 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3644 if((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
3645 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3646 fragP
->fr_opcode
[0],fragP
->fr_address
);
3647 fragP
->fr_opcode
[1]&= ~0x3F;
3648 fragP
->fr_opcode
[1]|=0x39; /* Mode 7.1 */
3650 /* md_number_to_chars(buffer_address,
3651 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3655 case TAB(PCLEA
,SHORT
):
3656 subseg_change(SEG_TEXT
,0);
3657 fix_new(fragP
,(int)(fragP
->fr_fix
),2,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
,1,
3659 fragP
->fr_opcode
[1] &= ~0x3F;
3660 fragP
->fr_opcode
[1] |= 0x3A;
3663 case TAB(PCLEA
,LONG
):
3664 subseg_change(SEG_TEXT
,0);
3665 fix_new(fragP
,(int)(fragP
->fr_fix
)+2,4,fragP
->fr_symbol
,(symbolS
*)0,fragP
->fr_offset
+2,1,
3667 *buffer_address
++ = 0x01;
3668 *buffer_address
++ = 0x70;
3670 /* buffer_address+=2; */
3674 } /* switch on subtype */
3677 md_number_to_chars(buffer_address
, (long) disp
, (int) ext
);
3678 fragP
->fr_fix
+= ext
;
3679 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3680 } /* if extending */
3683 } /* md_convert_frag() */
3685 /* Force truly undefined symbols to their maximum size, and generally set up
3686 the frag list to be relaxed
3688 int md_estimate_size_before_relax(fragP
, segment
)
3689 register fragS
*fragP
;
3693 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3695 old_fix
= fragP
->fr_fix
;
3697 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3698 switch (fragP
->fr_subtype
) {
3700 case TAB(ABRANCH
,SZ_UNDEF
): {
3701 if((fragP
->fr_symbol
!= NULL
) /* Not absolute */
3702 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3703 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),BYTE
);
3705 } else if((fragP
->fr_symbol
== 0) || (cpu_of_arch(current_architecture
) < m68020
)) {
3706 /* On 68000, or for absolute value, switch to abs long */
3707 /* FIXME, we should check abs val, pick short or long */
3708 if(fragP
->fr_opcode
[0]==0x61) {
3709 fragP
->fr_opcode
[0]= 0x4E;
3710 fragP
->fr_opcode
[1]= 0xB9; /* JBSR with ABSL LONG offset */
3711 subseg_change(SEG_TEXT
, 0);
3712 fix_new(fragP
, fragP
->fr_fix
, 4,
3713 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3716 } else if(fragP
->fr_opcode
[0]==0x60) {
3717 fragP
->fr_opcode
[0]= 0x4E;
3718 fragP
->fr_opcode
[1]= 0xF9; /* JMP with ABSL LONG offset */
3719 subseg_change(SEG_TEXT
, 0);
3720 fix_new(fragP
, fragP
->fr_fix
, 4,
3721 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
3725 as_warn("Long branch offset to extern symbol not supported.");
3727 } else { /* Symbol is still undefined. Make it simple */
3728 fix_new(fragP
, (int)(fragP
->fr_fix
), 4, fragP
->fr_symbol
,
3729 (symbolS
*)0, fragP
->fr_offset
+4, 1, NO_RELOC
);
3731 fragP
->fr_opcode
[1]=0xff;
3737 } /* case TAB(ABRANCH,SZ_UNDEF) */
3739 case TAB(FBRANCH
,SZ_UNDEF
): {
3740 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3741 fragP
->fr_subtype
= TAB(FBRANCH
,SHORT
);
3744 fragP
->fr_subtype
= TAB(FBRANCH
,LONG
);
3748 } /* TAB(FBRANCH,SZ_UNDEF) */
3750 case TAB(PCREL
,SZ_UNDEF
): {
3751 if(S_GET_SEGMENT(fragP
->fr_symbol
) == segment
|| flagseen
['l']) {
3752 fragP
->fr_subtype
= TAB(PCREL
,SHORT
);
3755 fragP
->fr_subtype
= TAB(PCREL
,LONG
);
3759 } /* TAB(PCREL,SZ_UNDEF) */
3761 case TAB(BCC68000
,SZ_UNDEF
): {
3762 if((fragP
->fr_symbol
!= NULL
)
3763 && S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3764 fragP
->fr_subtype
=TAB(BCC68000
,BYTE
);
3767 /* only Bcc 68000 instructions can come here */
3768 /* change bcc into b!cc/jmp absl long */
3769 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
3771 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
3772 /* JF: these were fr_opcode[2,3] */
3773 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3774 buffer_address
[1] = 0xf8;
3775 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3776 subseg_change(SEG_TEXT
,0);
3777 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3778 fragP
->fr_offset
, 0, NO_RELOC
);
3781 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
3782 /* JF: these were fr_opcode[2,3] */
3783 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
3784 buffer_address
[1] = 0xf9;
3785 fragP
->fr_fix
+= 2; /* account for jmp instruction */
3786 subseg_change(SEG_TEXT
,0);
3787 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3788 fragP
->fr_offset
, 0, NO_RELOC
);
3793 } /* case TAB(BCC68000,SZ_UNDEF) */
3795 case TAB(DBCC
,SZ_UNDEF
): {
3796 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT(fragP
->fr_symbol
) == segment
) {
3797 fragP
->fr_subtype
=TAB(DBCC
,SHORT
);
3801 /* only DBcc 68000 instructions can come here */
3802 /* change dbcc into dbcc/jmp absl long */
3803 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3804 buffer_address
[0] = 0x00; /* branch offset = 4 */
3805 buffer_address
[1] = 0x04;
3806 buffer_address
[2] = 0x60; /* put in bra pc + ... */
3809 /* JF: these were fr_opcode[5-7] */
3810 buffer_address
[3] = 0x04; /* plus 4 */
3811 buffer_address
[4] = 0x4e;/* Put in Jump Word */
3812 buffer_address
[5] = 0xf8;
3813 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3814 subseg_change(SEG_TEXT
,0);
3815 fix_new(fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
3818 fragP
->fr_offset
, 0, NO_RELOC
);
3821 /* JF: these were fr_opcode[5-7] */
3822 buffer_address
[3] = 0x06; /* Plus 6 */
3823 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
3824 buffer_address
[5] = 0xf9;
3825 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
3826 subseg_change(SEG_TEXT
,0);
3827 fix_new(fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
3828 fragP
->fr_offset
, 0, NO_RELOC
);
3834 } /* case TAB(DBCC,SZ_UNDEF) */
3836 case TAB(PCLEA
,SZ_UNDEF
): {
3837 if ((S_GET_SEGMENT(fragP
->fr_symbol
))==segment
|| flagseen
['l']) {
3838 fragP
->fr_subtype
=TAB(PCLEA
,SHORT
);
3841 fragP
->fr_subtype
=TAB(PCLEA
,LONG
);
3845 } /* TAB(PCLEA,SZ_UNDEF) */
3850 } /* switch on subtype looking for SZ_UNDEF's. */
3852 /* now that SZ_UNDEF are taken care of, check others */
3853 switch (fragP
->fr_subtype
) {
3854 case TAB(BCC68000
,BYTE
):
3855 case TAB(ABRANCH
,BYTE
):
3856 /* We can't do a short jump to the next instruction,
3857 so we force word mode. */
3858 if (fragP
->fr_symbol
&& S_GET_VALUE(fragP
->fr_symbol
)==0 &&
3859 fragP
->fr_symbol
->sy_frag
==fragP
->fr_next
) {
3860 fragP
->fr_subtype
=TAB(TABTYPE(fragP
->fr_subtype
),SHORT
);
3867 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
3870 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3871 /* the bit-field entries in the relocation_info struct plays hell
3872 with the byte-order problems of cross-assembly. So as a hack,
3873 I added this mach. dependent ri twiddler. Ugly, but it gets
3875 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3876 are symbolnum, most sig. byte first. Last byte is broken up with
3877 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3878 nibble as nuthin. (on Sun 3 at least) */
3879 /* Translate the internal relocation information into target-specific
3883 md_ri_to_chars(the_bytes
, ri
)
3885 struct reloc_info_generic
*ri
;
3888 md_number_to_chars(the_bytes
, ri
->r_address
, 4);
3889 /* now the fun stuff */
3890 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
3891 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
3892 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
3893 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
3894 ((ri
->r_extern
<< 4) & 0x10));
3896 #endif /* comment */
3898 void tc_aout_fix_to_chars(where
, fixP
, segment_address_in_file
)
3901 relax_addressT segment_address_in_file
;
3904 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3905 * Out: GNU LD relocation length code: 0, 1, or 2.
3908 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
3911 know(fixP
->fx_addsy
!= NULL
);
3913 md_number_to_chars(where
,
3914 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
3917 r_symbolnum
= (S_IS_DEFINED(fixP
->fx_addsy
)
3918 ? S_GET_TYPE(fixP
->fx_addsy
)
3919 : fixP
->fx_addsy
->sy_number
);
3921 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
3922 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
3923 where
[6] = r_symbolnum
& 0x0ff;
3924 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
3925 (((!S_IS_DEFINED(fixP
->fx_addsy
)) << 4) & 0x10));
3928 } /* tc_aout_fix_to_chars() */
3930 #endif /* OBJ_AOUT or OBJ_BOUT */
3932 #ifndef WORKING_DOT_WORD
3933 const int md_short_jump_size
= 4;
3934 const int md_long_jump_size
= 6;
3937 md_create_short_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3946 offset
= to_addr
- (from_addr
+2);
3948 md_number_to_chars(ptr
,(long)0x6000,2);
3949 md_number_to_chars(ptr
+2,(long)offset
,2);
3953 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
3962 if (cpu_of_arch(current_architecture
) < m68020
) {
3963 offset
=to_addr
-S_GET_VALUE(to_symbol
);
3964 md_number_to_chars(ptr
,(long)0x4EF9,2);
3965 md_number_to_chars(ptr
+2,(long)offset
,4);
3966 fix_new(frag
,(ptr
+2)-frag
->fr_literal
,4,to_symbol
,(symbolS
*)0,(long)0,0,
3969 offset
=to_addr
- (from_addr
+2);
3970 md_number_to_chars(ptr
,(long)0x60ff,2);
3971 md_number_to_chars(ptr
+2,(long)offset
,4);
3976 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3979 10: Absolute 1:8 only
3980 20: Absolute 0:7 only
3981 30: absolute 0:15 only
3982 40: Absolute 0:31 only
3983 50: absolute 0:127 only
3984 55: absolute -64:63 only
3985 60: absolute -128:127 only
3986 70: absolute 0:4095 only
3991 static int get_num(exp
,ok
)
3992 struct m68k_exp
*exp
;
4000 if(*exp
->e_beg
=='0') {
4001 if(exp
->e_beg
[1]=='x')
4002 sscanf(exp
->e_beg
+2,"%x",&l
);
4004 sscanf(exp
->e_beg
+1,"%O",&l
);
4007 return atol(exp
->e_beg
);
4013 /* Can't do anything */
4016 if(!exp
->e_beg
|| !exp
->e_end
) {
4017 seg(exp
)=SEG_ABSOLUTE
;
4020 offs(exp
)= (ok
==10) ? 1 : 0;
4021 as_warn("Null expression defaults to %ld",offs(exp
));
4026 if(/* ok!=80 && */ (exp
->e_end
[-1]==':' || exp
->e_end
[-1]=='.')
4027 && (exp
->e_end
-exp
->e_beg
)>=2) {
4028 switch(exp
->e_end
[0]) {
4047 if (exp
->e_end
[-1] == ':')
4048 as_bad("Unknown size for expression \"%c\"",exp
->e_end
[0]);
4052 c_save
=exp
->e_end
[1];
4054 save_in
=input_line_pointer
;
4055 input_line_pointer
=exp
->e_beg
;
4056 switch(expression(&(exp
->e_exp
))) {
4058 seg(exp
)=SEG_ABSOLUTE
;
4061 offs(exp
)= (ok
==10) ? 1 : 0;
4062 as_warn("Unknown expression: '%s' defaulting to %d",exp
->e_beg
,offs(exp
));
4066 /* Do the same thing the VAX asm does */
4067 seg(exp
)=SEG_ABSOLUTE
;
4072 as_warn("expression out of range: defaulting to 1");
4079 if(offs(exp
)<1 || offs(exp
)>8) {
4080 as_warn("expression out of range: defaulting to 1");
4085 if(offs(exp
)<0 || offs(exp
)>7)
4089 if(offs(exp
)<0 || offs(exp
)>15)
4093 if(offs(exp
)<0 || offs(exp
)>32)
4097 if(offs(exp
)<0 || offs(exp
)>127)
4101 if(offs(exp
)<-64 || offs(exp
)>63)
4105 if(offs(exp
)<-128 || offs(exp
)>127)
4109 if(offs(exp
)<0 || offs(exp
)>4095) {
4111 as_warn("expression out of range: defaulting to 0");
4123 case SEG_DIFFERENCE
:
4124 if(ok
>=10 && ok
<=70) {
4125 seg(exp
)=SEG_ABSOLUTE
;
4128 offs(exp
)= (ok
==10) ? 1 : 0;
4129 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
4133 if (offs (exp
) < 0 /* flonum */
4134 && (ok
== 80 /* no bignums */
4135 || (ok
> 10 /* small-int ranges including 0 ok */
4136 /* If we have a flonum zero, a zero integer should
4137 do as well (e.g., in moveq). */
4138 && generic_floating_point_number
.exponent
== 0
4139 && generic_floating_point_number
.low
[0] == 0)))
4141 /* HACK! Turn it into a long */
4142 LITTLENUM_TYPE words
[6];
4144 gen_to_words(words
,2,8L);/* These numbers are magic! */
4145 seg(exp
)=SEG_ABSOLUTE
;
4148 offs(exp
)=words
[1]|(words
[0]<<16);
4151 seg(exp
)=SEG_ABSOLUTE
;
4154 offs(exp
)= (ok
==10) ? 1 : 0;
4155 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp
->e_beg
,offs(exp
));
4159 as_fatal("failed sanity check.");
4161 if(input_line_pointer
!=exp
->e_end
+1)
4162 as_bad("Ignoring junk after expression");
4163 exp
->e_end
[1]=c_save
;
4164 input_line_pointer
=save_in
;
4166 switch(exp
->e_siz
) {
4168 if(!isbyte(offs(exp
)))
4169 as_warn("expression doesn't fit in BYTE");
4172 if(!isword(offs(exp
)))
4173 as_warn("expression doesn't fit in WORD");
4181 /* These are the back-ends for the various machine dependent pseudo-ops. */
4182 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
4184 static void s_data1() {
4185 subseg_new(SEG_DATA
,1);
4186 demand_empty_rest_of_line();
4189 static void s_data2() {
4190 subseg_new(SEG_DATA
,2);
4191 demand_empty_rest_of_line();
4196 /* We don't support putting frags in the BSS segment, we fake it
4197 by marking in_bss, then looking at s_skip for clues */
4199 subseg_new(SEG_BSS
, 0);
4200 demand_empty_rest_of_line();
4203 static void s_even() {
4205 register long temp_fill
;
4207 temp
= 1; /* JF should be 2? */
4208 temp_fill
= get_absolute_expression ();
4209 if ( ! need_pass_2
) /* Never make frag if expect extra pass. */
4210 frag_align (temp
, (int)temp_fill
);
4211 demand_empty_rest_of_line();
4214 static void s_proc() {
4215 demand_empty_rest_of_line();
4218 /* s_space is defined in read.c .skip is simply an alias to it. */
4222 * Invocation line includes a switch not recognized by the base assembler.
4223 * See if it's a processor-specific option. These are:
4225 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4226 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4227 * Select the architecture. Instructions or features not
4228 * supported by the selected architecture cause fatal
4229 * errors. More than one may be specified. The default is
4230 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4231 * for -m68000, and -m68882 is a synonym for -m68881.
4233 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
4234 * (e.g. m68020) also requests that float instructions be included. This
4235 * is the default setup, mostly to avoid hassling users. A better
4236 * rearrangement of this structure would be to add an option to DENY
4237 * floating point opcodes, for people who want to really know there's none
4238 * of that funny floaty stuff going on. FIXME-later.
4240 #ifndef MAYBE_FLOAT_TOO
4241 #define MAYBE_FLOAT_TOO m68881
4244 int md_parse_option(argP
,cntP
,vecP
)
4250 case 'l': /* -l means keep external to 2 bit offset
4251 rather than 16 bit one */
4254 case 'S': /* -S means that jbsr's always turn into jsr's. */
4259 /* intentional fall-through */
4265 } /* allow an optional "c" */
4267 if (!strcmp(*argP
, "68000")
4268 || !strcmp(*argP
, "68008")) {
4269 current_architecture
|= m68000
;
4270 } else if (!strcmp(*argP
, "68010")) {
4272 omagic
= 1<<16|OMAGIC
;
4274 current_architecture
|= m68010
;
4276 } else if (!strcmp(*argP
, "68020")) {
4277 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
4279 } else if (!strcmp(*argP
, "68030")) {
4280 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
4282 } else if (!strcmp(*argP
, "68040")) {
4283 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
4286 } else if (!strcmp(*argP
, "68881")) {
4287 current_architecture
|= m68881
;
4289 } else if (!strcmp(*argP
, "68882")) {
4290 current_architecture
|= m68882
;
4292 #endif /* NO_68881 */
4294 } else if (!strcmp(*argP
,"68851")) {
4295 current_architecture
|= m68851
;
4297 #endif /* NO_68851 */
4299 as_warn("Unknown architecture, \"%s\". option ignored", *argP
);
4300 } /* switch on architecture */
4302 while(**argP
) (*argP
)++;
4307 if (!strcmp(*argP
,"pic")) {
4309 break; /* -pic, Position Independent Code */
4323 /* TEST2: Test md_assemble() */
4324 /* Warning, this routine probably doesn't work anymore */
4328 struct m68k_it the_ins
;
4335 if(!gets(buf
) || !*buf
)
4337 if(buf
[0]=='|' || buf
[1]=='.')
4339 for(cp
=buf
;*cp
;cp
++)
4344 memset(&the_ins
, '\0', sizeof(the_ins
));
4345 m68k_ip(&the_ins
,buf
);
4347 printf("Error %s in %s\n",the_ins
.error
,buf
);
4349 printf("Opcode(%d.%s): ",the_ins
.numo
,the_ins
.args
);
4350 for(n
=0;n
<the_ins
.numo
;n
++)
4351 printf(" 0x%x",the_ins
.opcode
[n
]&0xffff);
4353 print_the_insn(&the_ins
.opcode
[0],stdout
);
4354 (void)putchar('\n');
4356 for(n
=0;n
<strlen(the_ins
.args
)/2;n
++) {
4357 if(the_ins
.operands
[n
].error
) {
4358 printf("op%d Error %s in %s\n",n
,the_ins
.operands
[n
].error
,buf
);
4361 printf("mode %d, reg %d, ",the_ins
.operands
[n
].mode
,the_ins
.operands
[n
].reg
);
4362 if(the_ins
.operands
[n
].b_const
)
4363 printf("Constant: '%.*s', ",1+the_ins
.operands
[n
].e_const
-the_ins
.operands
[n
].b_const
,the_ins
.operands
[n
].b_const
);
4364 printf("ireg %d, isiz %d, imul %d, ",the_ins
.operands
[n
].ireg
,the_ins
.operands
[n
].isiz
,the_ins
.operands
[n
].imul
);
4365 if(the_ins
.operands
[n
].b_iadd
)
4366 printf("Iadd: '%.*s',",1+the_ins
.operands
[n
].e_iadd
-the_ins
.operands
[n
].b_iadd
,the_ins
.operands
[n
].b_iadd
);
4367 (void)putchar('\n');
4379 while(*str
&& *str
!=' ')
4381 if(str
[-1]==':' || str
[1]=='=')
4388 /* Possible states for relaxation:
4390 0 0 branch offset byte (bra, etc)
4394 1 0 indexed offsets byte a0@(32,d4:w:1) etc
4398 2 0 two-offset index word-word a0@(32,d4)@(45) etc
4417 extern fragS
*text_frag_root
;
4419 for(fragP
=text_frag_root
;fragP
;fragP
=fragP
->fr_next
) {
4420 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
4421 fragP
->fr_address
,fragP
->fr_next
,fragP
->fr_fix
,fragP
->fr_var
,fragP
->fr_symbol
,fragP
->fr_offset
);
4422 printf("opcode 0x%x type %d subtype %d\n\n",fragP
->fr_opcode
,fragP
->fr_type
,fragP
->fr_subtype
);
4434 fputs("Internal error:",stderr
);
4435 _doprnt(format
,&args
,stderr
);
4436 (void)putc('\n',stderr
);
4442 /* We have no need to default values of symbols. */
4446 md_undefined_symbol (name
)
4452 /* Parse an operand that is machine-specific.
4453 We just return without modifying the expression if we have nothing
4458 md_operand (expressionP
)
4459 expressionS
*expressionP
;
4463 /* Round up a section size to the appropriate boundary. */
4465 md_section_align (segment
, size
)
4469 return size
; /* Byte alignment is fine */
4472 /* Exactly what point is a PC-relative offset relative TO?
4473 On the 68k, they're relative to the address of the offset, plus
4474 its size. (??? Is this right? FIXME-SOON!) */
4476 md_pcrel_from (fixP
)
4479 return(fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
4483 tc_coff_symbol_emit_hook ()
4488 tc_coff_sizemachdep(frag
)
4491 switch (frag
->fr_subtype
& 0x3)
4493 case BYTE
: return 1;
4494 case SHORT
: return 2;
4495 case LONG
: return 4;
4507 /* end of tc-m68k.c */