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"
32 /* This variable contains the value to write out at the beginning of
33 the a.out file. The 2<<16 means that this is a 68020 file instead
34 of an old-style 68000 file */
36 long omagic
= 2 << 16 | OMAGIC
; /* Magic byte for header file */
41 /* This array holds the chars that always start a comment. If the
42 pre-processor is disabled, these aren't very useful */
43 const char comment_chars
[] = "|";
45 /* This array holds the chars that only start a comment at the beginning of
46 a line. If the line seems to have the form '# 123 filename'
47 .line and .file directives will appear in the pre-processed output */
48 /* Note that input_file.c hand checks for '#' at the beginning of the
49 first line of the input file. This is because the compiler outputs
50 #NO_APP at the beginning of its output. */
51 /* Also note that comments like this one will always work. */
52 const char line_comment_chars
[] = "#";
54 const char line_separator_chars
[] = "";
56 /* Chars that can be used to separate mant from exp in floating point nums */
57 const char EXP_CHARS
[] = "eE";
59 /* Chars that mean this number is a floating point constant */
63 const char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
65 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
66 changed in read.c . Ideally it shouldn't have to know about it at all,
67 but nothing is ideal around here.
70 int md_reloc_size
= 8; /* Size of relocation record */
72 /* Its an arbitrary name: This means I don't approve of it */
73 /* See flames below */
74 static struct obstack robyn
;
76 #define TAB(x,y) (((x)<<2)+(y))
77 #define TABTYPE(xy) ((xy) >> 2)
90 /* Operands we can parse: (And associated modes)
96 reg: address or data register
97 areg: address register
98 apc: address register, PC, ZPC or empty string
101 sz: w or l if omitted, l assumed
102 scale: 1 2 4 or 8 if omitted, 1 assumed
104 7.4 IMMED #num --> NUM
105 0.? DREG dreg --> dreg
106 1.? AREG areg --> areg
107 2.? AINDR areg@ --> *(areg)
108 3.? AINC areg@+ --> *(areg++)
109 4.? ADEC areg@- --> *(--areg)
110 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
111 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
112 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
113 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
114 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
115 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
116 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
117 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
118 7.0 ABSL num:sz --> *(num)
119 num --> *(num) (sz L assumed)
120 *** MSCR otherreg --> Magic
122 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
123 ?.? DINDR dreg@ --> (dreg) -- cas2 only
133 a1@(5,d2:w:1) @(45,d6:l:4)
138 #name@(numw) -->turn into PC rel mode
139 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
168 short e_siz
; /* 0== default 1==short/byte 2==word 3==long */
171 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
172 8-15==addr reg for operands that take both types */
176 DATA
= 1, /* 1- 8 == data registers 0-7 */
196 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
201 FPREG
, /* Eight FP registers */
210 COPNUM
= (FPREG
+ 8), /* Co-processor #1-#8 */
219 PC
, /* Program counter */
220 ZPC
, /* Hack for Program space, but 0 addressing */
222 CCR
, /* Condition code Reg */
224 /* These have to be in order for the movec instruction to work. */
225 USP
, /* User Stack Pointer */
226 ISP
, /* Interrupt stack pointer */
241 /* end of movec ordering constraints */
247 DRP
, /* 68851 or 68030 MMU regs */
271 PSR
, /* aka MMUSR on 68030 (but not MMUSR on 68040)
272 and ACUSR on 68ec030 */
275 IC
, /* instruction cache token */
276 DC
, /* data cache token */
277 NC
, /* no cache token */
278 BC
, /* both caches token */
280 TT0
, /* 68030 access control unit regs */
284 /* Internal form of an operand. */
287 char *error
; /* Couldn't parse it */
288 enum operand_type mode
; /* What mode this instruction is in. */
289 enum _register reg
; /* Base register */
290 struct m68k_exp
*con1
;
291 int ireg
; /* Index register */
292 int isiz
; /* 0==unspec 1==byte(?) 2==short 3==long */
293 int imul
; /* Multipy ireg by this (1,2,4,or 8) */
294 struct m68k_exp
*con2
;
297 /* internal form of a 68020 instruction */
301 char *args
; /* list of opcode info */
304 int numo
; /* Number of shorts in opcode */
307 struct m68k_op operands
[6];
309 int nexp
; /* number of exprs in use */
310 struct m68k_exp exprs
[4];
312 int nfrag
; /* Number of frags we have to produce */
315 int fragoff
; /* Where in the current opcode[] the frag ends */
322 int nrel
; /* Num of reloc strucs in use */
331 reloc
[5]; /* Five is enough??? */
334 #define cpu_of_arch(x) ((x) & m68000up)
335 #define float_of_arch(x) ((x) & mfloat)
336 #define mmu_of_arch(x) ((x) & mmmu)
338 static struct m68k_it the_ins
; /* the instruction being assembled */
340 /* Macros for adding things to the m68k_it struct */
342 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
344 /* Like addword, but goes BEFORE general operands */
345 #define insop(w) {int z;\
346 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
347 the_ins.opcode[z]=the_ins.opcode[z-1];\
348 for(z=0;z<the_ins.nrel;z++)\
349 the_ins.reloc[z].n+=2;\
350 the_ins.opcode[opcode->m_codenum]=w;\
355 #define add_exp(beg,end) (\
356 the_ins.exprs[the_ins.nexp].e_beg=beg,\
357 the_ins.exprs[the_ins.nexp].e_end=end,\
358 &the_ins.exprs[the_ins.nexp++]\
362 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
364 #define add_fix(width,exp,pc_rel) \
366 the_ins.reloc[the_ins.nrel].n= (((width)=='B') \
367 ? (the_ins.numo*2-1) \
369 ? ((the_ins.numo-1)*2) \
370 : (the_ins.numo*2)));\
371 the_ins.reloc[the_ins.nrel].add=adds((exp));\
372 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
373 the_ins.reloc[the_ins.nrel].off=offs((exp));\
374 the_ins.reloc[the_ins.nrel].wid=width;\
375 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
378 #define add_frag(add,off,type) \
380 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
381 the_ins.fragb[the_ins.nfrag].fadd=add;\
382 the_ins.fragb[the_ins.nfrag].foff=off;\
383 the_ins.fragb[the_ins.nfrag++].fragty=type;\
386 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
388 #define seg(exp) ((exp)->e_exp.X_seg)
389 #define adds(exp) ((exp)->e_exp.X_add_symbol)
390 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
391 #define offs(exp) ((exp)->e_exp.X_add_number)
397 unsigned long m_opcode
;
401 struct m68k_incant
*m_next
;
406 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
407 #define gettwo(x) (((x)->m_opcode)&0xffff)
412 static char *crack_operand (char *str
, struct m68k_op
*opP
);
413 static int get_num (struct m68k_exp
*exp
, int ok
);
414 static int get_regs (int i
, char *str
, struct m68k_op
*opP
);
415 static int reverse_16_bits (int in
);
416 static int reverse_8_bits (int in
);
417 static int try_index (char **s
, struct m68k_op
*opP
);
418 static void install_gen_operand (int mode
, int val
);
419 static void install_operand (int mode
, int val
);
420 static void s_bss (void);
421 static void s_data1 (void);
422 static void s_data2 (void);
423 static void s_even (void);
424 static void s_proc (void);
426 #else /* not __STDC__ */
428 static char *crack_operand ();
429 static int get_num ();
430 static int get_regs ();
431 static int reverse_16_bits ();
432 static int reverse_8_bits ();
433 static int try_index ();
434 static void install_gen_operand ();
435 static void install_operand ();
436 static void s_bss ();
437 void s_align_bytes ();
438 static void s_data1 ();
439 static void s_data2 ();
440 static void s_even ();
441 static void s_proc ();
443 #endif /* not __STDC__ */
445 static int current_architecture
= 0;
447 /* BCC68000 is for patching in an extra jmp instruction for long offsets
448 on the 68000. The 68000 doesn't support long branches with branchs */
450 /* This table desribes how you change sizes for the various types of variable
451 size expressions. This version only supports two kinds. */
453 /* Note that calls to frag_var need to specify the maximum expansion needed */
454 /* This is currently 10 bytes for DBCC */
457 How far Forward this mode will reach:
458 How far Backward this mode will reach:
459 How many bytes this mode will add to the size of the frag
460 Which mode to go to if the offset won't fit in this one
465 {1, 1, 0, 0}, /* First entries aren't used */
466 {1, 1, 0, 0}, /* For no good reason except */
467 {1, 1, 0, 0}, /* that the VAX doesn't either */
470 {(127), (-128), 0, TAB (ABRANCH
, SHORT
)},
471 {(32767), (-32768), 2, TAB (ABRANCH
, LONG
)},
475 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
476 {(32767), (-32768), 2, TAB (FBRANCH
, LONG
)},
480 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
481 {(32767), (-32768), 2, TAB (PCREL
, LONG
)},
485 {(127), (-128), 0, TAB (BCC68000
, SHORT
)},
486 {(32767), (-32768), 2, TAB (BCC68000
, LONG
)},
487 {0, 0, 6, 0}, /* jmp long space */
490 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
491 {(32767), (-32768), 2, TAB (DBCC
, LONG
)},
492 {0, 0, 10, 0}, /* bra/jmp long space */
495 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
496 {32767, -32768, 2, TAB (PCLEA
, LONG
)},
502 /* These are the machine dependent pseudo-ops. These are included so
503 the assembler can work on the output from the SUN C compiler, which
507 /* This table describes all the machine specific pseudo-ops the assembler
508 has to support. The fields are:
509 pseudo-op name without dot
510 function to call to execute this pseudo-op
511 Integer arg to pass to the function
513 const pseudo_typeS md_pseudo_table
[] =
515 {"data1", s_data1
, 0},
516 {"data2", s_data2
, 0},
519 {"skip", s_space
, 0},
522 {"align", s_align_bytes
, 0},
528 /* The mote pseudo ops are put into the opcode table, since they
529 don't start with a . they look like opcodes to gas.
531 extern void obj_coff_section ();
533 const pseudo_typeS mote_pseudo_table
[] =
541 {"ds.l", s_space
, 4},
543 {"ds.w", s_space
, 2},
544 {"ds.b", s_space
, 1},
546 {"xdef", s_globl
, 0},
547 {"align", s_align_ptwo
, 0},
549 {"sect", obj_coff_section
, 0},
550 {"section", obj_coff_section
, 0},
555 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
556 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
558 #define issbyte(x) ((x)>=-128 && (x)<=127)
559 #define isubyte(x) ((x)>=0 && (x)<=255)
560 #define issword(x) ((x)>=-32768 && (x)<=32767)
561 #define isuword(x) ((x)>=0 && (x)<=65535)
563 #define isbyte(x) ((x)>=-128 && (x)<=255)
564 #define isword(x) ((x)>=-32768 && (x)<=65535)
565 #define islong(x) (1)
567 extern char *input_line_pointer
;
575 /* JF these tables here are for speed at the expense of size */
576 /* You can replace them with the #if 0 versions if you really
577 need space and don't mind it running a bit slower */
579 static char mklower_table
[256];
580 #define mklower(c) (mklower_table[(unsigned char)(c)])
581 static char notend_table
[256];
582 static char alt_notend_table
[256];
583 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
584 alt_notend_table[(unsigned char)(s[1])])))
587 #define mklower(c) (isupper(c) ? tolower(c) : c)
591 /* JF modified this to handle cases where the first part of a symbol name
592 looks like a register */
595 * m68k_reg_parse() := if it looks like a register, return it's token &
596 * advance the pointer.
608 #ifdef REGISTER_PREFIX
609 if (*start
!= REGISTER_PREFIX
)
614 if (*p
== OPTIONAL_REGISTER_PREFIX
)
617 if (!isalpha (*p
) || !is_name_beginner (*p
))
621 while (isalpha (c
) || isdigit (c
) || c
== '_')
627 symbolP
= symbol_find (start
);
630 if (symbolP
&& S_GET_SEGMENT (symbolP
) == SEG_REGISTER
)
633 return S_GET_VALUE (symbolP
);
639 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
640 #define SKIP_W() { ss++; if(*ss==' ') ss++;}
642 /* Parse an index specification using Motorola syntax. */
645 try_moto_index (s
, opP
)
656 i
= m68k_reg_parse (&ss
);
657 if (!(i
>= DATA
+ 0 && i
<= ADDR
+ 7))
658 { /* if i is not DATA or ADDR reg */
659 opP
->error
= "Invalid index register";
675 opP
->error
= "Missing . in index register";
680 if (mklower (*ss
) == 'w')
682 else if (mklower (*ss
) == 'l')
686 opP
->error
= "Size spec not .W or .L";
691 if (*ss
== '.' || *ss
== '*')
700 opP
->imul
= *ss
- '0';
703 opP
->error
= "index multiplier not 1, 2, 4 or 8";
713 opP
->error
= "Missing )";
724 * try_index := data_or_address_register + ')' + SKIP_W
725 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
727 * multiplier := <empty>
728 * | ':' + multiplier_number
731 * multiplier_number := '1' | '2' | '4' | '8' ;
733 * size_spec := 'l' | 'L' | 'w' | 'W' ;
735 * SKIP_W := <empty> | ' ' ;
749 i
= m68k_reg_parse (&ss
);
750 if (!(i
>= DATA
+ 0 && i
<= ADDR
+ 7))
751 { /* if i is not DATA or ADDR reg */
767 opP
->error
= "Missing : in index register";
783 opP
->error
= "Index register size spec not :w or :l";
797 if (cpu_of_arch (current_architecture
) < m68020
)
799 opP
->error
= "no index scaling in pre-68020's";
803 opP
->imul
= *ss
- '0';
806 opP
->error
= "index multiplier not 1, 2, 4 or 8";
816 opP
->error
= "Missing )";
825 /* Ian Taylor expanded this function to accept both MIT and Motorola
826 syntax. I removed the old comment, since it was wrong. The syntax
827 this accepted even before my changes was complex and undocumented.
828 I mainly added a large case when the operand string does not
829 contain an '@', since the Motorola syntax does not use the '@'
833 m68k_ip_op (str
, opP
)
835 register struct m68k_op
*opP
;
839 char *parse_index ();
845 } /* Find the beginning of the string */
849 opP
->error
= "Missing operand";
853 for (strend
= str
; *strend
; strend
++)
860 opP
->con1
= add_exp (str
, strend
);
863 } /* Guess what: A constant. Shar and enjoy */
865 i
= m68k_reg_parse (&str
);
869 if (*str
== '/' || *str
== '-')
871 /* "Rm-Rn/Ro-Rp" Register list for MOVEM instruction */
873 return get_regs (i
, str
, opP
);
878 /* "Rn" Register Direct mode */
879 if (i
>= DATA
+ 0 && i
<= DATA
+ 7)
881 else if (i
>= ADDR
+ 0 && i
<= ADDR
+ 7)
893 if ((stmp
= strchr (str
, '@')) != 0)
895 opP
->con1
= add_exp (str
, stmp
- 1);
902 if ((current_architecture
& m68020up
) == 0)
905 } /* if target is not a '20 or better */
908 if (*stmp
++ != '(' || *strend
-- != ')')
910 opP
->error
= "Malformed operand";
913 i
= try_index (&stmp
, opP
);
914 opP
->con2
= add_exp (stmp
, strend
);
925 } /* if there's an '@' */
927 #ifndef MIT_SYNTAX_ONLY
928 /* The operand has no '@'. Try to parse it using
930 /* Logic of the parsing switch(*str):
934 REG AREG or DREG or MSCR 3 or 2 or 13
935 REG- or REG/ REGLST 14
940 (EXPR,REG,INDX) AINDX 8
943 EXP2(REG,INDX) AINDX 8
946 REG means truth(m68k_reg_parse(&str))
947 INDX means truth(try_moto_index(&str,opP))
949 EXP2 means not REG and not '(' and not '-('
955 i
= m68k_reg_parse (&str
);
956 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7)
957 && (i
< DATA
+ 0 || i
> DATA
+ 7
958 || *str
!= ')' || str
[1] != '0')
959 && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
)
961 /* Can't indirect off non address regs */
962 opP
->error
= "Invalid indirect register";
973 /* "(An)" Address Register Indirect mode
974 or "(Dn)" for cas2. */
975 if (i
>= DATA
+ 0 && i
<= DATA
+ 7)
985 /* "(An)+" Register Indirect w Postincrement */
990 opP
->error
= "Junk after indirect";
996 i
= try_moto_index (&str
, opP
);
999 /* "(An,Rn)" Register Indirect with Index mode*/
1005 opP
->error
= "Bad indirect syntax";
1011 /* "(EXPR,..." , a displacement */
1015 if (stmp
= index (str
, ','))
1017 opP
->con1
= add_exp (str
, stmp
- 1);
1020 i
= m68k_reg_parse (&str
);
1021 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
)
1023 /* Can't indirect off non address regs */
1024 opP
->error
= "Invalid indirect register";
1032 /* "(d,An)" Register Indirect w Displacement */
1039 i
= try_moto_index (&str
, opP
);
1042 /* "(d,An,Rn)" Register Indirect with Index */
1048 opP
->error
= "Bad indirect syntax";
1054 opP
->error
= "Invalid register";
1061 opP
->con1
= add_exp (str
- 1, strend
);
1072 i
= m68k_reg_parse (&str
);
1073 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
)
1075 /* Can't indirect off non address regs */
1076 opP
->error
= "Invalid indirect register";
1087 /* "-(An)" Register Indirect with Predecrement */
1091 opP
->error
= "Junk after indirect";
1094 opP
->error
= "Bad indirect syntax";
1098 opP
->con1
= add_exp (str
- 2, strend
);
1101 /* if '-' but not "-(', do nothing */
1104 /* whether *str=='-' or not */
1106 /* "EXP2" or "EXP2(REG..." */
1109 if (stmp
= index (str
, '('))
1113 opP
->con1
= add_exp (str
, stmp
- 1);
1115 i
= m68k_reg_parse (&str
);
1116 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
1117 && i
!= ZPC
&& i
!= FAIL
)
1119 /* Can't indirect off non address regs */
1120 opP
->error
= "Invalid indirect register";
1128 /* "d(An)" Register Indirect w Displacement */
1135 i
= try_moto_index (&str
, opP
);
1138 /* "d(An,Rn)" Register Indirect with Index */
1144 opP
->error
= "Bad indirect syntax";
1151 opP
->con1
= add_exp (ostr
, strend
);
1157 /* "EXP2" Absolute */
1160 if (strend
[-1] == '.' || strend
[-1] == ':')
1162 /* mode ==foo.[wl] */
1177 opP
->con1
= add_exp (str
, strend
);
1182 #else /* defined (MIT_SYNTAX_ONLY) */
1184 opP
->con1
= add_exp (str
, strend
);
1186 #endif /* defined (MIT_SYNTAX_ONLY) */
1191 /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
1192 if ((i
< ADDR
+ 0 || i
> ADDR
+ 7) && i
!= PC
&& i
!= ZPC
&& i
!= FAIL
1193 && (str
[1] != '\0' || i
< DATA
+ 0 || i
> DATA
+ 7))
1195 opP
->error
= "Invalid indirect register";
1204 if (i
< DATA
+ 0 || i
> DATA
+ 7)
1219 opP
->error
= "Junk after indirect";
1222 /* Some kind of indexing involved. Lets find out how bad it is */
1223 i
= try_index (&str
, opP
);
1224 /* Didn't start with an index reg, maybe its offset or offset,reg */
1235 opP
->error
= "Missing )";
1248 /* if(str[-3]==':') {
1265 opP->error="Specified size isn't :w or :l";
1268 opP->con1=add_exp(beg_str,str-4);
1269 opP->con1->e_siz=siz;
1271 opP
->con1
= add_exp (beg_str
, str
- 2);
1272 /* Should be offset,reg */
1275 i
= try_index (&str
, opP
);
1278 opP
->error
= "Malformed index reg";
1283 /* We've now got offset) offset,reg) or reg) */
1287 /* Th-the-thats all folks */
1288 if (opP
->reg
== FAIL
)
1289 opP
->mode
= AINDX
; /* Other form of indirect */
1290 else if (opP
->ireg
== FAIL
)
1296 /* Next thing had better be another @ */
1311 if ((current_architecture
& m68020up
) == 0)
1314 } /* if target is not a '20 or better */
1317 if (opP
->ireg
!= FAIL
)
1321 i
= try_index (&str
, opP
);
1324 opP
->error
= "Two index registers! not allowed!";
1330 i
= try_index (&str
, opP
);
1345 opP
->error
= "Missing )";
1360 opP
->con2
= add_exp (beg_str
, str
- 2);
1364 if (opP
->ireg
!= FAIL
)
1366 opP
->error
= "Can't have two index regs";
1370 i
= try_index (&str
, opP
);
1374 opP
->error
= "malformed index reg";
1380 else if (opP
->ireg
!= FAIL
)
1396 opP
->error
= "Junk after indirect";
1400 } /* m68k_ip_op() */
1406 tc_coff_fix2rtype (fixP
)
1409 return (fixP
->fx_pcrel
?
1410 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
1411 fixP
->fx_size
== 2 ? R_PCRWORD
:
1413 (fixP
->fx_size
== 1 ? R_RELBYTE
:
1414 fixP
->fx_size
== 2 ? R_RELWORD
:
1422 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1426 struct m68k_op thark
;
1432 memset (&thark
, '\0', sizeof (thark
));
1433 if (!m68k_ip_op (buf
, &thark
))
1436 printf ("op1 error %s in %s\n", thark
.error
, buf
);
1437 printf ("mode %d, reg %d, ", thark
.mode
, thark
.reg
);
1439 printf ("Constant: '%.*s',", 1 + thark
.e_const
- thark
.b_const
, thark
.b_const
);
1440 printf ("ireg %d, isiz %d, imul %d ", thark
.ireg
, thark
.isiz
, thark
.imul
);
1442 printf ("Iadd: '%.*s'", 1 + thark
.e_iadd
- thark
.b_iadd
, thark
.b_iadd
);
1451 static struct hash_control
*op_hash
= NULL
; /* handle of the OPCODE hash table
1452 NULL means any use before m68k_ip_begin()
1459 * This converts a string into a 68k instruction.
1460 * The string must be a bare single instruction in sun format
1461 * with RMS-style 68020 indirects
1464 * It provides some error messages: at most one fatal error message (which
1465 * stops the scan) and at most one warning message for each operand.
1466 * The 68k instruction is returned in exploded form, since we have no
1467 * knowledge of how you parse (or evaluate) your expressions.
1468 * We do however strip off and decode addressing modes and operation
1471 * This function's value is a string. If it is not "" then an internal
1472 * logic error was found: read this code to assign meaning to the string.
1473 * No argument string should generate such an error string:
1474 * it means a bug in our code, not in the user's text.
1476 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1480 /* JF this function no longer returns a useful value. Sorry */
1486 register struct m68k_op
*opP
;
1487 register struct m68k_incant
*opcode
;
1489 register int tmpreg
= 0, baseo
= 0, outro
= 0, nextword
;
1490 char *pdot
, *pdotmove
;
1495 char *crack_operand ();
1496 LITTLENUM_TYPE words
[6];
1497 LITTLENUM_TYPE
*wordp
;
1498 unsigned long ok_arch
= 0;
1500 if (*instring
== ' ')
1501 instring
++; /* skip leading whitespace */
1503 /* Scan up to end of operation-code, which MUST end in end-of-string
1504 or exactly 1 space. */
1506 for (p
= instring
; *p
!= '\0'; p
++)
1516 the_ins
.error
= "No operator";
1517 the_ins
.opcode
[0] = NULL
;
1518 /* the_ins.numo=1; */
1522 /* p now points to the end of the opcode name, probably whitespace.
1523 make sure the name is null terminated by clobbering the whitespace,
1524 look it up in the hash table, then fix it back.
1525 Remove a dot, first, since the opcode tables have none. */
1528 for (pdotmove
= pdot
; pdotmove
< p
; pdotmove
++)
1529 *pdotmove
= pdotmove
[1];
1535 opcode
= (struct m68k_incant
*) hash_find (op_hash
, instring
);
1540 for (pdotmove
= p
; pdotmove
> pdot
; pdotmove
--)
1541 *pdotmove
= pdotmove
[-1];
1548 the_ins
.error
= "Unknown operator";
1549 the_ins
.opcode
[0] = NULL
;
1550 /* the_ins.numo=1; */
1554 /* found a legitimate opcode, start matching operands */
1559 if (opcode
->m_operands
== 0)
1561 char *old
= input_line_pointer
;
1563 input_line_pointer
= p
;
1564 /* Ahh - it's a motorola style psuedo op */
1565 mote_pseudo_table
[opcode
->m_opnum
].poc_handler
1566 (mote_pseudo_table
[opcode
->m_opnum
].poc_val
);
1567 input_line_pointer
= old
;
1573 for (opP
= &the_ins
.operands
[0]; *p
; opP
++)
1576 p
= crack_operand (p
, opP
);
1580 the_ins
.error
= opP
->error
;
1585 opsfound
= opP
- &the_ins
.operands
[0];
1587 /* This ugly hack is to support the floating pt opcodes in their standard form */
1588 /* Essentially, we fake a first enty of type COP#1 */
1589 if (opcode
->m_operands
[0] == 'I')
1593 for (n
= opsfound
; n
> 0; --n
)
1594 the_ins
.operands
[n
] = the_ins
.operands
[n
- 1];
1596 memset ((char *) (&the_ins
.operands
[0]), '\0', sizeof (the_ins
.operands
[0]));
1597 the_ins
.operands
[0].mode
= MSCR
;
1598 the_ins
.operands
[0].reg
= COPNUM
; /* COP #1 */
1602 /* We've got the operands. Find an opcode that'll accept them */
1605 /* if we didn't get the right number of ops,
1606 or we have no common model with this pattern
1607 then reject this pattern. */
1609 if (opsfound
!= opcode
->m_opnum
1610 || ((opcode
->m_arch
& current_architecture
) == 0))
1613 ok_arch
|= opcode
->m_arch
;
1617 for (s
= opcode
->m_operands
, opP
= &the_ins
.operands
[0]; *s
&& !losing
; s
+= 2, opP
++)
1619 /* Warning: this switch is huge! */
1620 /* I've tried to organize the cases into this order:
1621 non-alpha first, then alpha by letter. lower-case goes directly
1622 before uppercase counterpart. */
1623 /* Code with multiple case ...: gets sorted by the lowest case ...
1624 it belongs to. I hope this makes sense. */
1628 if (opP
->mode
== MSCR
|| opP
->mode
== IMMED
1629 || opP
->mode
== DREG
|| opP
->mode
== AREG
1630 || opP
->mode
== AINC
|| opP
->mode
== ADEC
1631 || opP
->mode
== REGLST
)
1650 if (opP
->mode
!= IMMED
)
1656 t
= get_num (opP
->con1
, 80);
1657 if (s
[1] == 'b' && !isbyte (t
))
1659 else if (s
[1] == 'w' && !isword (t
))
1666 if (opP
->mode
!= IMMED
)
1671 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1672 opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1677 if (opP
->mode
== MSCR
|| opP
->reg
== PC
||
1678 opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1684 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1685 opP
->mode
== AREG
|| opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
||
1686 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== REGLST
)
1691 if (opP
->mode
== MSCR
|| opP
->mode
== REGLST
)
1696 if (opP
->mode
!= AINC
)
1701 if (opP
->mode
!= ADEC
)
1706 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1707 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== IMMED
|| opP
->mode
== REGLST
)
1712 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
|| opP
->mode
== REGLST
)
1717 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1718 opP
->mode
== AINC
|| opP
->mode
== ADEC
|| opP
->mode
== IMMED
|| opP
->reg
== PC
||
1719 opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1724 if (opP
->mode
== MSCR
|| opP
->mode
== AREG
||
1725 opP
->mode
== IMMED
|| opP
->mode
== REGLST
)
1729 case '~': /* For now! (JF FOO is this right?) */
1730 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1731 opP
->mode
== AREG
|| opP
->mode
== IMMED
|| opP
->reg
== PC
|| opP
->reg
== ZPC
|| opP
->mode
== REGLST
)
1736 if (opP
->mode
!= MSCR
|| (opP
->reg
!= TT0
&& opP
->reg
!= TT1
))
1741 if (opP
->mode
!= AREG
)
1745 if (opP
->mode
!= AINDR
)
1748 } /* if not address register indirect */
1751 if (opP
->mode
!= ABSL
|| (flagseen
['S'] && instring
[0] == 'j'
1752 && instring
[1] == 'b'
1753 && instring
[2] == 's'
1754 && instring
[3] == 'r'))
1759 if (opP
->mode
!= MSCR
|| opP
->reg
!= CCR
)
1763 case 'd': /* FOO This mode is a KLUDGE!! */
1764 if (opP
->mode
!= AOFF
&& (opP
->mode
!= ABSL
||
1765 opP
->con1
->e_beg
[0] != '(' || opP
->con1
->e_end
[0] != ')'))
1770 if (opP
->mode
!= DREG
)
1775 if (opP
->mode
!= MSCR
|| opP
->reg
< (FPREG
+ 0) || opP
->reg
> (FPREG
+ 7))
1780 if (opP
->mode
!= MSCR
|| opP
->reg
< COPNUM
||
1781 opP
->reg
>= COPNUM
+ 7)
1786 if (opP
->mode
!= MSCR
1789 || cpu_of_arch (current_architecture
) < m68010
/* before 68010 had none */
1790 || (cpu_of_arch (current_architecture
) < m68020
1794 && opP
->reg
!= VBR
) /* 68010's had only these */
1795 || (cpu_of_arch (current_architecture
) < m68040
1803 && opP
->reg
!= ISP
) /* 680[23]0's have only these */
1804 || (cpu_of_arch (current_architecture
) == m68040
/* 68040 has all but this */
1805 && opP
->reg
== CAAR
))
1808 } /* doesn't cut it */
1812 if (opP
->mode
!= IMMED
)
1818 if (opP
->mode
== DREG
|| opP
->mode
== AREG
|| opP
->mode
== FPREG
)
1825 opP
->reg
= 1 << (opP
->reg
- DATA
);
1828 else if (opP
->mode
!= REGLST
)
1832 else if (s
[1] == '8' && opP
->reg
& 0x0FFffFF)
1834 else if (s
[1] == '3' && opP
->reg
& 0x7000000)
1839 if (opP
->mode
!= IMMED
)
1845 t
= get_num (opP
->con1
, 80);
1846 if (!issbyte (t
) || isvar (opP
->con1
))
1852 if (opP
->mode
!= DREG
&& opP
->mode
!= IMMED
)
1857 if (opP
->mode
!= IMMED
)
1863 t
= get_num (opP
->con1
, 80);
1864 if (t
< 1 || t
> 8 || isvar (opP
->con1
))
1870 if (opP
->mode
!= DREG
&& opP
->mode
!= AREG
)
1875 if (opP
->mode
!= AINDR
&& opP
->mode
!= DINDR
)
1880 if (opP
->mode
!= MSCR
|| !(opP
->reg
== FPI
|| opP
->reg
== FPS
|| opP
->reg
== FPC
))
1885 if (opP
->mode
!= MSCR
|| opP
->reg
!= SR
)
1890 if (opP
->mode
!= IMMED
)
1894 long t
= get_num (opP
->con1
, 80);
1895 if (t
< 0 || t
> 7 || isvar (opP
->con1
))
1901 if (opP
->mode
!= MSCR
|| opP
->reg
!= USP
)
1905 /* JF these are out of order. We could put them
1906 in order if we were willing to put up with
1907 bunches of #ifdef m68851s in the code.
1909 Don't forget that you need these operands
1910 to use 68030 MMU instructions. */
1912 /* Memory addressing mode used by pflushr */
1914 if (opP
->mode
== MSCR
|| opP
->mode
== DREG
||
1915 opP
->mode
== AREG
|| opP
->mode
== REGLST
)
1920 if (opP
->mode
!= MSCR
|| (opP
->reg
!= SFC
&& opP
->reg
!= DFC
))
1925 if (opP
->mode
!= MSCR
1926 || (opP
->reg
!= TC
&& opP
->reg
!= CAL
1927 && opP
->reg
!= VAL
&& opP
->reg
!= SCC
&& opP
->reg
!= AC
))
1932 if (opP
->reg
!= VAL
)
1937 if (opP
->mode
!= MSCR
1938 || (opP
->reg
!= DRP
&& opP
->reg
!= SRP
1939 && opP
->reg
!= CRP
))
1944 if (opP
->mode
!= MSCR
||
1945 (!(opP
->reg
>= BAD
&& opP
->reg
<= BAD
+ 7) &&
1946 !(opP
->reg
>= BAC
&& opP
->reg
<= BAC
+ 7)))
1951 if (opP
->reg
!= PSR
)
1956 if (opP
->reg
!= PCSR
)
1967 } /* not a cache specifier. */
1971 if (opP
->mode
!= ABSL
)
1974 } /* not absolute */
1978 as_fatal ("Internal error: Operand mode %c unknown in line %d of file \"%s\"",
1979 *s
, __LINE__
, __FILE__
);
1980 } /* switch on type of operand */
1984 } /* for each operand */
1985 } /* if immediately wrong */
1992 opcode
= opcode
->m_next
;
1997 && !(ok_arch
& current_architecture
))
2001 strcpy (buf
, "invalid instruction for this architecture; needs ");
2002 cp
= buf
+ strlen (buf
);
2006 strcpy (cp
, "fpu (68040 or 68881/68882)");
2009 strcpy (cp
, "mmu (68030 or 68851)");
2012 strcpy (cp
, "68020 or higher");
2015 strcpy (cp
, "68000 or higher");
2018 strcpy (cp
, "68010 or higher");
2022 int got_one
= 0, idx
;
2039 for (idx
= 0; idx
< sizeof (archs
) / sizeof (archs
[0]); idx
++)
2041 if (archs
[idx
].arch
& ok_arch
)
2045 strcpy (cp
, " or ");
2049 strcpy (cp
, archs
[idx
].name
);
2061 the_ins
.error
= "operands mismatch";
2063 } /* Fell off the end */
2068 /* now assemble it */
2070 the_ins
.args
= opcode
->m_operands
;
2071 the_ins
.numargs
= opcode
->m_opnum
;
2072 the_ins
.numo
= opcode
->m_codenum
;
2073 the_ins
.opcode
[0] = getone (opcode
);
2074 the_ins
.opcode
[1] = gettwo (opcode
);
2076 for (s
= the_ins
.args
, opP
= &the_ins
.operands
[0]; *s
; s
+= 2, opP
++)
2078 /* This switch is a doozy.
2079 Watch the first step; its a big one! */
2100 tmpreg
= 0x3c; /* 7.4 */
2101 if (strchr ("bwl", s
[1]))
2102 nextword
= get_num (opP
->con1
, 80);
2104 nextword
= nextword
= get_num (opP
->con1
, 0);
2105 if (isvar (opP
->con1
))
2106 add_fix (s
[1], opP
->con1
, 0);
2110 if (!isbyte (nextword
))
2111 opP
->error
= "operand out of range";
2116 if (!isword (nextword
))
2117 opP
->error
= "operand out of range";
2122 addword (nextword
>> 16);
2144 as_fatal ("Internal error: Can't decode %c%c in line %s of file \"%s\"",
2145 *s
, s
[1], __LINE__
, __FILE__
);
2150 /* We gotta put out some float */
2152 if (seg (opP
->con1
) != SEG_BIG
)
2154 int_to_gen (nextword
);
2155 gen_to_words (words
, baseo
, (long int) outro
);
2156 for (wordp
= words
; baseo
--; wordp
++)
2161 if (seg (opP
->con1
) != SEG_BIG
)
2166 if (offs (opP
->con1
) > 0)
2168 if (offs (opP
->con1
) > baseo
)
2170 as_warn ("Bignum too big for %c format; truncated", s
[1]);
2171 offs (opP
->con1
) = baseo
;
2173 baseo
-= offs (opP
->con1
);
2174 for (wordp
= generic_bignum
+ offs (opP
->con1
) - 1; offs (opP
->con1
)--; --wordp
)
2180 gen_to_words (words
, baseo
, (long) outro
);
2181 for (wordp
= words
; baseo
--; wordp
++)
2185 tmpreg
= opP
->reg
- DATA
; /* 0.dreg */
2188 tmpreg
= 0x08 + opP
->reg
- ADDR
; /* 1.areg */
2191 tmpreg
= 0x10 + opP
->reg
- ADDR
; /* 2.areg */
2194 tmpreg
= 0x20 + opP
->reg
- ADDR
; /* 4.areg */
2197 tmpreg
= 0x18 + opP
->reg
- ADDR
; /* 3.areg */
2201 nextword
= get_num (opP
->con1
, 80);
2202 /* Force into index mode. Hope this works */
2204 /* We do the first bit for 32-bit displacements, and the
2205 second bit for 16 bit ones. It is possible that we
2206 should make the default be WORD instead of LONG, but
2207 I think that'd break GCC, so we put up with a little
2208 inefficiency for the sake of working output. */
2210 if (!issword (nextword
)
2211 || (isvar (opP
->con1
)
2212 && ((opP
->con1
->e_siz
== 0
2213 && flagseen
['l'] == 0)
2214 || opP
->con1
->e_siz
== 3)))
2218 tmpreg
= 0x3B; /* 7.3 */
2220 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2221 if (isvar (opP
->con1
))
2225 add_frag (adds (opP
->con1
),
2226 offs (opP
->con1
) + 2,
2227 TAB (PCLEA
, SZ_UNDEF
));
2233 add_fix ('l', opP
->con1
, 0);
2238 addword (nextword
>> 16);
2243 tmpreg
= 0x3A; /* 7.2 */
2245 tmpreg
= 0x28 + opP
->reg
- ADDR
; /* 5.areg */
2247 if (isvar (opP
->con1
))
2251 add_fix ('w', opP
->con1
, 1);
2254 add_fix ('w', opP
->con1
, 0);
2263 know (current_architecture
& m68020up
);
2264 /* intentional fall-through */
2267 baseo
= get_num (opP
->con1
, 80);
2268 outro
= get_num (opP
->con2
, 80);
2269 /* Figure out the 'addressing mode' */
2270 /* Also turn on the BASE_DISABLE bit, if needed */
2271 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2273 tmpreg
= 0x3b;/* 7.3 */
2274 if (opP
->reg
== ZPC
)
2277 else if (opP
->reg
== FAIL
)
2280 tmpreg
= 0x30;/* 6.garbage */
2283 tmpreg
= 0x30 + opP
->reg
- ADDR
; /* 6.areg */
2285 siz1
= (opP
->con1
) ? opP
->con1
->e_siz
: 0;
2286 siz2
= (opP
->con2
) ? opP
->con2
->e_siz
: 0;
2288 /* Index register stuff */
2289 if (opP
->ireg
>= DATA
+ 0 && opP
->ireg
<= ADDR
+ 7)
2291 nextword
|= (opP
->ireg
- DATA
) << 12;
2293 if (opP
->isiz
== 0 || opP
->isiz
== 3)
2309 as_fatal ("failed sanity check.");
2312 GET US OUT OF HERE! */
2314 /* Must be INDEX, with an index
2315 register. Address register
2316 cannot be ZERO-PC, and either
2317 :b was forced, or we know
2319 if (opP
->mode
== AINDX
2324 && !isvar (opP
->con1
))))
2326 nextword
+= baseo
& 0xff;
2328 if (isvar (opP
->con1
))
2329 add_fix ('B', opP
->con1
, 0);
2334 nextword
|= 0x40; /* No index reg */
2336 /* It aint simple */
2338 /* If the guy specified a width, we assume that
2339 it is wide enough. Maybe it isn't. If so, we lose
2344 if (isvar (opP
->con1
) || !issword (baseo
))
2349 else if (baseo
== 0)
2358 as_warn ("Byte dispacement won't work. Defaulting to :w");
2367 /* Figure out innner displacement stuff */
2368 if (opP
->mode
!= AINDX
)
2373 if (isvar (opP
->con2
) || !issword (outro
))
2378 else if (outro
== 0)
2387 as_warn ("Byte dispacement won't work. Defaulting to :w");
2395 if (opP
->mode
== APODX
)
2397 else if (opP
->mode
== AMIND
)
2402 if (isvar (opP
->con1
))
2404 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2406 add_fix (siz1
== 3 ? 'l' : 'w', opP
->con1
, 1);
2407 opP
->con1
->e_exp
.X_add_number
+= 6;
2410 add_fix (siz1
== 3 ? 'l' : 'w', opP
->con1
, 0);
2413 addword (baseo
>> 16);
2417 if (isvar (opP
->con2
))
2419 if (opP
->reg
== PC
|| opP
->reg
== ZPC
)
2421 add_fix (siz2
== 3 ? 'l' : 'w', opP
->con2
, 1);
2422 opP
->con1
->e_exp
.X_add_number
+= 6;
2425 add_fix (siz2
== 3 ? 'l' : 'w', opP
->con2
, 0);
2428 addword (outro
>> 16);
2435 nextword
= get_num (opP
->con1
, 80);
2436 switch (opP
->con1
->e_siz
)
2439 as_warn ("Unknown size for absolute reference");
2441 if (!isvar (opP
->con1
) && issword (offs (opP
->con1
)))
2443 tmpreg
= 0x38; /* 7.0 */
2447 /* Don't generate pc relative code
2448 on 68010 and 68000 */
2449 if (isvar (opP
->con1
)
2450 && !subs (opP
->con1
)
2451 && seg (opP
->con1
) == SEG_TEXT
2452 && now_seg
== SEG_TEXT
2453 && cpu_of_arch (current_architecture
) >= m68020
2455 && !strchr ("~%&$?", s
[0]))
2457 tmpreg
= 0x3A; /* 7.2 */
2458 add_frag (adds (opP
->con1
),
2460 TAB (PCREL
, SZ_UNDEF
));
2463 case 3: /* Fall through into long */
2464 if (isvar (opP
->con1
))
2465 add_fix ('l', opP
->con1
, 0);
2467 tmpreg
= 0x39;/* 7.1 mode */
2468 addword (nextword
>> 16);
2473 if (isvar (opP
->con1
))
2474 add_fix ('w', opP
->con1
, 0);
2476 tmpreg
= 0x38;/* 7.0 mode */
2482 as_bad ("invalid indirect register");
2486 as_bad ("unknown/incorrect operand");
2489 install_gen_operand (s
[1], tmpreg
);
2495 { /* JF: I hate floating point! */
2510 tmpreg
= get_num (opP
->con1
, tmpreg
);
2511 if (isvar (opP
->con1
))
2512 add_fix (s
[1], opP
->con1
, 0);
2515 case 'b': /* Danger: These do no check for
2516 certain types of overflow.
2518 if (!isbyte (tmpreg
))
2519 opP
->error
= "out of range";
2521 if (isvar (opP
->con1
))
2522 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2525 if (!isword (tmpreg
))
2526 opP
->error
= "out of range";
2528 if (isvar (opP
->con1
))
2529 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2532 insop (tmpreg
); /* Because of the way insop works, we put these two out backwards */
2533 insop (tmpreg
>> 16);
2534 if (isvar (opP
->con1
))
2535 the_ins
.reloc
[the_ins
.nrel
- 1].n
= (opcode
->m_codenum
) * 2;
2541 install_operand (s
[1], tmpreg
);
2544 as_fatal ("Internal error: Unknown mode #%c in line %s of file \"%s\"", s
[1], __LINE__
, __FILE__
);
2552 install_operand (s
[1], opP
->reg
- ADDR
);
2556 tmpreg
= get_num (opP
->con1
, 80);
2560 /* Needs no offsetting */
2561 add_fix ('B', opP
->con1
, 1);
2564 /* Offset the displacement to be relative to byte disp location */
2565 opP
->con1
->e_exp
.X_add_number
+= 2;
2566 add_fix ('w', opP
->con1
, 1);
2571 if (cpu_of_arch (current_architecture
) < m68020
) /* 68000 or 010 */
2572 as_warn ("Can't use long branches on 68000/68010");
2573 the_ins
.opcode
[the_ins
.numo
- 1] |= 0xff;
2574 /* Offset the displacement to be relative to byte disp location */
2575 opP
->con1
->e_exp
.X_add_number
+= 4;
2576 add_fix ('l', opP
->con1
, 1);
2581 if (subs (opP
->con1
)) /* We can't relax it */
2584 /* This could either be a symbol, or an
2585 absolute address. No matter, the
2586 frag hacking will finger it out.
2587 Not quite: it can't switch from
2588 BRANCH to BCC68000 for the case
2589 where opnd is absolute (it needs
2590 to use the 68000 hack since no
2591 conditional abs jumps). */
2592 if (((cpu_of_arch (current_architecture
) < m68020
) || (0 == adds (opP
->con1
)))
2593 && (the_ins
.opcode
[0] >= 0x6200)
2594 && (the_ins
.opcode
[0] <= 0x6f00))
2596 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (BCC68000
, SZ_UNDEF
));
2600 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (ABRANCH
, SZ_UNDEF
));
2604 if (isvar (opP
->con1
))
2606 /* check for DBcc instruction */
2607 if ((the_ins
.opcode
[0] & 0xf0f8) == 0x50c8)
2609 /* size varies if patch */
2610 /* needed for long form */
2611 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (DBCC
, SZ_UNDEF
));
2616 opP
->con1
->e_exp
.X_add_number
+= 2;
2617 add_fix ('w', opP
->con1
, 1);
2621 case 'C': /* Fixed size LONG coproc branches */
2622 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2623 /* Offset the displacement to be relative to byte disp location */
2624 /* Coproc branches don't have a byte disp option, but they are
2625 compatible with the ordinary branches, which do... */
2626 opP
->con1
->e_exp
.X_add_number
+= 4;
2627 add_fix ('l', opP
->con1
, 1);
2631 case 'c': /* Var size Coprocesssor branches */
2632 if (subs (opP
->con1
))
2634 add_fix ('l', opP
->con1
, 1);
2635 add_frag ((symbolS
*) 0, (long) 0, TAB (FBRANCH
, LONG
));
2637 else if (adds (opP
->con1
))
2639 add_frag (adds (opP
->con1
), offs (opP
->con1
), TAB (FBRANCH
, SZ_UNDEF
));
2643 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2644 the_ins
.opcode
[the_ins
.numo
- 1] |= 0x40;
2645 add_fix ('l', opP
->con1
, 1);
2651 as_fatal ("Internal error: operand type B%c unknown in line %s of file \"%s\"",
2652 s
[1], __LINE__
, __FILE__
);
2656 case 'C': /* Ignore it */
2659 case 'd': /* JF this is a kludge */
2660 if (opP
->mode
== AOFF
)
2662 install_operand ('s', opP
->reg
- ADDR
);
2668 tmpP
= opP
->con1
->e_end
- 2;
2670 opP
->con1
->e_end
-= 4; /* point to the , */
2671 baseo
= m68k_reg_parse (&tmpP
);
2672 if (baseo
< ADDR
+ 0 || baseo
> ADDR
+ 7)
2674 as_bad ("Unknown address reg, using A0");
2679 install_operand ('s', baseo
);
2681 tmpreg
= get_num (opP
->con1
, 80);
2682 if (!issword (tmpreg
))
2684 as_warn ("Expression out of range, using 0");
2691 install_operand (s
[1], opP
->reg
- DATA
);
2695 install_operand (s
[1], opP
->reg
- FPREG
);
2699 tmpreg
= 1 + opP
->reg
- COPNUM
;
2702 install_operand (s
[1], tmpreg
);
2705 case 'J': /* JF foo */
2758 as_fatal ("failed sanity check.");
2760 install_operand (s
[1], tmpreg
);
2764 tmpreg
= get_num (opP
->con1
, 55);
2765 install_operand (s
[1], tmpreg
& 0x7f);
2772 if (tmpreg
& 0x7FF0000)
2773 as_bad ("Floating point register in register list");
2774 insop (reverse_16_bits (tmpreg
));
2778 if (tmpreg
& 0x700FFFF)
2779 as_bad ("Wrong register in floating-point reglist");
2780 install_operand (s
[1], reverse_8_bits (tmpreg
>> 16));
2788 if (tmpreg
& 0x7FF0000)
2789 as_bad ("Floating point register in register list");
2792 else if (s
[1] == '8')
2794 if (tmpreg
& 0x0FFFFFF)
2795 as_bad ("incorrect register in reglist");
2796 install_operand (s
[1], tmpreg
>> 24);
2800 if (tmpreg
& 0x700FFFF)
2801 as_bad ("wrong register in floating-point reglist");
2803 install_operand (s
[1], tmpreg
>> 16);
2808 install_operand (s
[1], get_num (opP
->con1
, 60));
2812 tmpreg
= (opP
->mode
== DREG
)
2813 ? 0x20 + opP
->reg
- DATA
2814 : (get_num (opP
->con1
, 40) & 0x1F);
2815 install_operand (s
[1], tmpreg
);
2819 tmpreg
= get_num (opP
->con1
, 10);
2822 install_operand (s
[1], tmpreg
);
2827 /* This depends on the fact that ADDR registers are
2828 eight more than their corresponding DATA regs, so
2829 the result will have the ADDR_REG bit set */
2830 install_operand (s
[1], opP
->reg
- DATA
);
2834 if (opP
->reg
== FPI
)
2836 else if (opP
->reg
== FPS
)
2838 else if (opP
->reg
== FPC
)
2841 as_fatal ("failed sanity check.");
2842 install_operand (s
[1], tmpreg
);
2845 case 'S': /* Ignore it */
2849 install_operand (s
[1], get_num (opP
->con1
, 30));
2852 case 'U': /* Ignore it */
2871 as_fatal ("failed sanity check");
2872 } /* switch on cache token */
2873 install_operand (s
[1], tmpreg
);
2876 /* JF: These are out of order, I fear. */
2887 as_fatal ("failed sanity check.");
2889 install_operand (s
[1], tmpreg
);
2911 as_fatal ("failed sanity check.");
2913 install_operand (s
[1], tmpreg
);
2917 if (opP
->reg
== VAL
)
2919 as_fatal ("failed sanity check.");
2935 as_fatal ("failed sanity check.");
2937 install_operand (s
[1], tmpreg
);
2951 tmpreg
= (4 << 10) | ((opP
->reg
- BAD
) << 2);
2962 tmpreg
= (5 << 10) | ((opP
->reg
- BAC
) << 2);
2966 as_fatal ("failed sanity check.");
2968 install_operand (s
[1], tmpreg
);
2971 know (opP
->reg
== PSR
);
2974 know (opP
->reg
== PCSR
);
2987 as_fatal ("failed sanity check");
2989 install_operand (s
[1], tmpreg
);
2992 tmpreg
= get_num (opP
->con1
, 20);
2993 install_operand (s
[1], tmpreg
);
2995 case '_': /* used only for move16 absolute 32-bit address */
2996 tmpreg
= get_num (opP
->con1
, 80);
2997 addword (tmpreg
>> 16);
2998 addword (tmpreg
& 0xFFFF);
3001 as_fatal ("Internal error: Operand type %c unknown in line %d of file \"%s\"",
3002 s
[0], __LINE__
, __FILE__
);
3006 /* By the time whe get here (FINALLY) the_ins contains the complete
3007 instruction, ready to be emitted. . . */
3011 * get_regs := '/' + ?
3012 * | '-' + <register>
3013 * | '-' + <register> + ?
3018 * The idea here must be to scan in a set of registers but I don't
3019 * understand it. Looks awfully sloppy to me but I don't have any doc on
3027 get_regs (i
, str
, opP
)
3029 struct m68k_op
*opP
;
3032 /* 26, 25, 24, 23-16, 15-8, 0-7 */
3033 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
3034 unsigned long cur_regs
= 0;
3037 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
3038 else if(x==FPS) cur_regs|=(1<<25);\
3039 else if(x==FPC) cur_regs|=(1<<26);\
3040 else cur_regs|=(1<<(x-1)); }
3050 else if (*str
== '-')
3053 reg2
= m68k_reg_parse (&str
);
3054 if (reg2
< DATA
|| reg2
>= FPREG
+ 8 || reg1
== FPI
|| reg1
== FPS
|| reg1
== FPC
)
3056 opP
->error
= "unknown register in register list";
3059 while (reg1
<= reg2
)
3067 else if (*str
== '\0')
3074 opP
->error
= "unknow character in register list";
3077 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
3080 reg1
= m68k_reg_parse (&str
);
3081 if ((reg1
< DATA
|| reg1
>= FPREG
+ 8) && !(reg1
== FPI
|| reg1
== FPS
|| reg1
== FPC
))
3083 opP
->error
= "unknown register in register list";
3087 opP
->reg
= cur_regs
;
3092 reverse_16_bits (in
)
3098 static int mask
[16] =
3100 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3101 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3103 for (n
= 0; n
< 16; n
++)
3106 out
|= mask
[15 - n
];
3109 } /* reverse_16_bits() */
3118 static int mask
[8] =
3120 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3123 for (n
= 0; n
< 8; n
++)
3129 } /* reverse_8_bits() */
3132 install_operand (mode
, val
)
3139 the_ins
.opcode
[0] |= val
& 0xFF; /* JF FF is for M kludge */
3142 the_ins
.opcode
[0] |= val
<< 9;
3145 the_ins
.opcode
[1] |= val
<< 12;
3148 the_ins
.opcode
[1] |= val
<< 6;
3151 the_ins
.opcode
[1] |= val
;
3154 the_ins
.opcode
[2] |= val
<< 12;
3157 the_ins
.opcode
[2] |= val
<< 6;
3160 /* DANGER! This is a hack to force cas2l and cas2w cmds
3161 to be three words long! */
3163 the_ins
.opcode
[2] |= val
;
3166 the_ins
.opcode
[1] |= val
<< 7;
3169 the_ins
.opcode
[1] |= val
<< 10;
3173 the_ins
.opcode
[1] |= val
<< 5;
3178 the_ins
.opcode
[1] |= (val
<< 10) | (val
<< 7);
3181 the_ins
.opcode
[1] |= (val
<< 12) | val
;
3184 the_ins
.opcode
[0] |= val
= 0xff;
3187 the_ins
.opcode
[0] |= val
<< 9;
3190 the_ins
.opcode
[1] |= val
;
3193 the_ins
.opcode
[1] |= val
;
3194 the_ins
.numo
++; /* What a hack */
3197 the_ins
.opcode
[1] |= val
<< 4;
3204 the_ins
.opcode
[0] |= (val
<< 6);
3207 the_ins
.opcode
[1] = (val
>> 16);
3208 the_ins
.opcode
[2] = val
& 0xffff;
3212 as_fatal ("failed sanity check.");
3214 } /* install_operand() */
3217 install_gen_operand (mode
, val
)
3224 the_ins
.opcode
[0] |= val
;
3227 /* This is a kludge!!! */
3228 the_ins
.opcode
[0] |= (val
& 0x07) << 9 | (val
& 0x38) << 3;
3237 the_ins
.opcode
[0] |= val
;
3239 /* more stuff goes here */
3241 as_fatal ("failed sanity check.");
3243 } /* install_gen_operand() */
3246 * verify that we have some number of paren pairs, do m68k_ip_op(), and
3247 * then deal with the bitfield hack.
3251 crack_operand (str
, opP
)
3253 register struct m68k_op
*opP
;
3255 register int parens
;
3257 register char *beg_str
;
3264 for (parens
= 0; *str
&& (parens
> 0 || notend (str
)); str
++)
3268 else if (*str
== ')')
3272 opP
->error
= "Extra )";
3278 if (!*str
&& parens
)
3280 opP
->error
= "Missing )";
3285 if (m68k_ip_op (beg_str
, opP
) == FAIL
)
3292 c
= *++str
; /* JF bitfield hack */
3297 as_bad ("Missing operand");
3302 /* See the comment up above where the #define notend(... is */
3309 if (*s
== '{' || *s
== '}')
3313 /* This kludge here is for the division cmd, which is a kludge */
3314 if (index ("aAdD#", s
[1]))
3321 /* This is the guts of the machine-dependent assembler. STR points to a
3322 machine dependent instruction. This function is supposed to emit
3323 the frags/bytes it assembles to.
3327 insert_reg (regname
, regnum
)
3334 #ifdef REGISTER_PREFIX
3335 buf
[0] = REGISTER_PREFIX
;
3336 strcpy (buf
+ 1, regname
);
3340 symbol_table_insert (symbol_new (regname
, SEG_REGISTER
, regnum
, &zero_address_frag
));
3342 for (i
= 0; regname
[i
]; i
++)
3343 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
3346 symbol_table_insert (symbol_new (buf
, SEG_REGISTER
, regnum
, &zero_address_frag
));
3457 /* 68ec030 versions of same */
3460 /* 68ec030 access control unit, identical to 030 MMU status reg */
3472 for (i
= 0; init_table
[i
].name
; i
++)
3473 insert_reg (init_table
[i
].name
, init_table
[i
].number
);
3476 static int no_68851
, no_68881
;
3487 int shorts_this_frag
;
3488 static int done_first_time
;
3490 if (!done_first_time
)
3492 done_first_time
= 1;
3494 if (cpu_of_arch (current_architecture
) == 0)
3501 if (strcmp (TARGET_CPU
, "m68000") == 0)
3503 else if (strcmp (TARGET_CPU
, "m68010") == 0)
3505 else if (strcmp (TARGET_CPU
, "m68020") == 0
3506 || strcmp (TARGET_CPU
, "m68k") == 0)
3508 else if (strcmp (TARGET_CPU
, "m68030") == 0)
3510 else if (strcmp (TARGET_CPU
, "m68040") == 0)
3512 else if (strcmp (TARGET_CPU
, "cpu32") == 0)
3518 current_architecture
|= cpu_type
;
3520 #if 0 /* Could be doing emulation. */
3521 if (current_architecture
& m68881
)
3523 if (current_architecture
& m68000
)
3524 as_bad ("incompatible processors 68000 and 68881/2 specified");
3525 if (current_architecture
& m68010
)
3526 as_bad ("incompatible processors 68010 and 68881/2 specified");
3527 if (current_architecture
& m68040
)
3528 as_bad ("incompatible processors 68040 and 68881/2 specified");
3531 /* What other incompatibilities could we check for? */
3533 /* Toss in some default assumptions about coprocessors. */
3535 && (cpu_of_arch (current_architecture
)
3536 /* Can CPU32 have a 68881 coprocessor?? */
3537 & (m68020
| m68030
| cpu32
)))
3539 current_architecture
|= m68881
;
3542 && (cpu_of_arch (current_architecture
) & m68020up
) != 0)
3544 current_architecture
|= m68851
;
3546 if (no_68881
&& (current_architecture
& m68881
))
3547 as_bad ("options for 68881 and no-68881 both given");
3548 if (no_68851
&& (current_architecture
& m68851
))
3549 as_bad ("options for 68851 and no-68851 both given");
3550 done_first_time
= 1;
3553 memset ((char *) (&the_ins
), '\0', sizeof (the_ins
)); /* JF for paranoia sake */
3558 for (n
= the_ins
.numargs
; n
; --n
)
3559 if (the_ins
.operands
[n
].error
)
3561 er
= the_ins
.operands
[n
].error
;
3567 as_bad ("%s -- statement `%s' ignored", er
, str
);
3571 if (the_ins
.nfrag
== 0)
3572 { /* No frag hacking involved; just put it out */
3573 toP
= frag_more (2 * the_ins
.numo
);
3574 fromP
= &the_ins
.opcode
[0];
3575 for (m
= the_ins
.numo
; m
; --m
)
3577 md_number_to_chars (toP
, (long) (*fromP
), 2);
3581 /* put out symbol-dependent info */
3582 for (m
= 0; m
< the_ins
.nrel
; m
++)
3584 switch (the_ins
.reloc
[m
].wid
)
3602 as_fatal ("Don't know how to figure width of %c in md_assemble()", the_ins
.reloc
[m
].wid
);
3606 (toP
- frag_now
->fr_literal
) - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
,
3608 the_ins
.reloc
[m
].add
,
3609 the_ins
.reloc
[m
].sub
,
3610 the_ins
.reloc
[m
].off
,
3611 the_ins
.reloc
[m
].pcrel
,
3617 /* There's some frag hacking */
3618 for (n
= 0, fromP
= &the_ins
.opcode
[0]; n
< the_ins
.nfrag
; n
++)
3623 wid
= 2 * the_ins
.fragb
[n
].fragoff
;
3625 wid
= 2 * (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3626 toP
= frag_more (wid
);
3628 shorts_this_frag
= 0;
3629 for (m
= wid
/ 2; m
; --m
)
3631 md_number_to_chars (toP
, (long) (*fromP
), 2);
3636 for (m
= 0; m
< the_ins
.nrel
; m
++)
3638 if ((the_ins
.reloc
[m
].n
) >= 2 * shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */ )
3640 the_ins
.reloc
[m
].n
-= 2 * shorts_this_frag
/* 2*the_ins.fragb[n].fragoff */ ;
3643 wid
= the_ins
.reloc
[m
].wid
;
3646 the_ins
.reloc
[m
].wid
= 0;
3647 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3650 (toP
- frag_now
->fr_literal
) - the_ins
.numo
* 2 + the_ins
.reloc
[m
].n
,
3652 the_ins
.reloc
[m
].add
,
3653 the_ins
.reloc
[m
].sub
,
3654 the_ins
.reloc
[m
].off
,
3655 the_ins
.reloc
[m
].pcrel
,
3658 /* know(the_ins.fragb[n].fadd); */
3659 (void) frag_var (rs_machine_dependent
, 10, 0, (relax_substateT
) (the_ins
.fragb
[n
].fragty
),
3660 the_ins
.fragb
[n
].fadd
, the_ins
.fragb
[n
].foff
, to_beg_P
);
3662 n
= (the_ins
.numo
- the_ins
.fragb
[n
- 1].fragoff
);
3663 shorts_this_frag
= 0;
3666 toP
= frag_more (n
* sizeof (short));
3669 md_number_to_chars (toP
, (long) (*fromP
), 2);
3675 for (m
= 0; m
< the_ins
.nrel
; m
++)
3679 wid
= the_ins
.reloc
[m
].wid
;
3682 the_ins
.reloc
[m
].wid
= 0;
3683 wid
= (wid
== 'b') ? 1 : (wid
== 'w') ? 2 : (wid
== 'l') ? 4 : 4000;
3686 (the_ins
.reloc
[m
].n
+ toP
- frag_now
->fr_literal
) - /* the_ins.numo */ shorts_this_frag
* 2,
3688 the_ins
.reloc
[m
].add
,
3689 the_ins
.reloc
[m
].sub
,
3690 the_ins
.reloc
[m
].off
,
3691 the_ins
.reloc
[m
].pcrel
,
3702 * md_begin -- set up hash tables with 68000 instructions.
3703 * similar to what the vax assembler does. ---phr
3705 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3706 a copy of it at runtime, adding in the information we want but isn't
3707 there. I think it'd be better to have an awk script hack the table
3708 at compile time. Or even just xstr the table and use it as-is. But
3709 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3712 register const struct m68k_opcode
*ins
;
3713 register struct m68k_incant
*hack
, *slak
;
3714 register char *retval
= 0; /* empty string, or error msg text */
3715 register unsigned int i
;
3718 if ((op_hash
= hash_new ()) == NULL
)
3719 as_fatal ("Virtual memory exhausted");
3721 obstack_begin (&robyn
, 4000);
3722 for (ins
= m68k_opcodes
; ins
< endop
; ins
++)
3724 hack
= slak
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3727 /* we *could* ignore insns that don't match our
3728 arch here but just leaving them out of the
3730 slak
->m_operands
= ins
->args
;
3731 slak
->m_opnum
= strlen (slak
->m_operands
) / 2;
3732 slak
->m_arch
= ins
->arch
;
3733 slak
->m_opcode
= ins
->opcode
;
3734 /* This is kludgey */
3735 slak
->m_codenum
= ((ins
->match
) & 0xffffL
) ? 2 : 1;
3736 if ((ins
+ 1) != endop
&& !strcmp (ins
->name
, (ins
+ 1)->name
))
3738 slak
->m_next
= (struct m68k_incant
*) obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3743 slak
= slak
->m_next
;
3747 retval
= hash_insert (op_hash
, ins
->name
, (char *) hack
);
3748 /* Didn't his mommy tell him about null pointers? */
3749 if (retval
&& *retval
)
3750 as_bad ("Internal Error: Can't hash %s: %s", ins
->name
, retval
);
3753 for (i
= 0; i
< sizeof (mklower_table
); i
++)
3754 mklower_table
[i
] = (isupper (c
= (char) i
)) ? tolower (c
) : c
;
3756 for (i
= 0; i
< sizeof (notend_table
); i
++)
3758 notend_table
[i
] = 0;
3759 alt_notend_table
[i
] = 0;
3761 notend_table
[','] = 1;
3762 notend_table
['{'] = 1;
3763 notend_table
['}'] = 1;
3764 alt_notend_table
['a'] = 1;
3765 alt_notend_table
['A'] = 1;
3766 alt_notend_table
['d'] = 1;
3767 alt_notend_table
['D'] = 1;
3768 alt_notend_table
['#'] = 1;
3769 alt_notend_table
['f'] = 1;
3770 alt_notend_table
['F'] = 1;
3771 #ifdef REGISTER_PREFIX
3772 alt_notend_table
[REGISTER_PREFIX
] = 1;
3774 #ifdef OPTIONAL_REGISTER_PREFIX
3775 alt_notend_table
[OPTIONAL_REGISTER_PREFIX
] = 1;
3778 #ifndef MIT_SYNTAX_ONLY
3779 /* Insert pseudo ops, these have to go into the opcode table since
3780 gas expects pseudo ops to start with a dot */
3783 while (mote_pseudo_table
[n
].poc_name
)
3785 hack
= (struct m68k_incant
*)
3786 obstack_alloc (&robyn
, sizeof (struct m68k_incant
));
3787 hash_insert (op_hash
,
3788 mote_pseudo_table
[n
].poc_name
, (char *) hack
);
3789 hack
->m_operands
= 0;
3800 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
3801 || (*s == ':' && strchr("aAdD#", s[1]))) \
3805 /* This funciton is called once, before the assembler exits. It is
3806 supposed to do any final cleanup for this part of the assembler.
3813 /* Equal to MAX_PRECISION in atof-ieee.c */
3814 #define MAX_LITTLENUMS 6
3816 /* Turn a string in input_line_pointer into a floating point constant of type
3817 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3818 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
3821 md_atof (type
, litP
, sizeP
)
3827 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3828 LITTLENUM_TYPE
*wordP
;
3860 return "Bad call to MD_ATOF()";
3862 t
= atof_ieee (input_line_pointer
, type
, words
);
3864 input_line_pointer
= t
;
3866 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3867 for (wordP
= words
; prec
--;)
3869 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3870 litP
+= sizeof (LITTLENUM_TYPE
);
3872 return ""; /* Someone should teach Dean about null pointers */
3875 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
3876 for use in the a.out file, and stores them in the array pointed to by buf.
3877 This knows about the endian-ness of the target machine and does
3878 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
3879 2 (short) and 4 (long) Floating numbers are put out as a series of
3880 LITTLENUMS (shorts, here at least)
3883 md_number_to_chars (buf
, val
, n
)
3894 *buf
++ = (val
>> 8);
3898 *buf
++ = (val
>> 24);
3899 *buf
++ = (val
>> 16);
3900 *buf
++ = (val
>> 8);
3904 as_fatal ("failed sanity check.");
3909 md_apply_fix (fixP
, val
)
3913 #ifdef IBM_COMPILER_SUX
3914 /* This is unnecessary but it convinces the native rs6000
3915 compiler to generate the code we want. */
3916 char *buf
= fixP
->fx_frag
->fr_literal
;
3917 buf
+= fixP
->fx_where
;
3918 #else /* IBM_COMPILER_SUX */
3919 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3920 #endif /* IBM_COMPILER_SUX */
3922 switch (fixP
->fx_size
)
3928 *buf
++ = (val
>> 8);
3932 *buf
++ = (val
>> 24);
3933 *buf
++ = (val
>> 16);
3934 *buf
++ = (val
>> 8);
3938 BAD_CASE (fixP
->fx_size
);
3943 /* *fragP has been relaxed to its final size, and now needs to have
3944 the bytes inside it modified to conform to the new size There is UGLY
3948 md_convert_frag (headers
, fragP
)
3949 object_headers
*headers
;
3950 register fragS
*fragP
;
3955 /* Address in object code of the displacement. */
3956 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
3958 #ifdef IBM_COMPILER_SUX
3959 /* This is wrong but it convinces the native rs6000 compiler to
3960 generate the code we want. */
3961 register char *buffer_address
= fragP
->fr_literal
;
3962 buffer_address
+= fragP
->fr_fix
;
3963 #else /* IBM_COMPILER_SUX */
3964 /* Address in gas core of the place to store the displacement. */
3965 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
3966 #endif /* IBM_COMPILER_SUX */
3968 /* No longer true: know(fragP->fr_symbol); */
3970 /* The displacement of the address, from current location. */
3971 disp
= fragP
->fr_symbol
? S_GET_VALUE (fragP
->fr_symbol
) : 0;
3972 disp
= (disp
+ fragP
->fr_offset
) - object_address
;
3974 switch (fragP
->fr_subtype
)
3976 case TAB (BCC68000
, BYTE
):
3977 case TAB (ABRANCH
, BYTE
):
3978 know (issbyte (disp
));
3980 as_bad ("short branch with zero offset: use :w");
3981 fragP
->fr_opcode
[1] = disp
;
3984 case TAB (DBCC
, SHORT
):
3985 know (issword (disp
));
3988 case TAB (BCC68000
, SHORT
):
3989 case TAB (ABRANCH
, SHORT
):
3990 know (issword (disp
));
3991 fragP
->fr_opcode
[1] = 0x00;
3994 case TAB (ABRANCH
, LONG
):
3995 if (cpu_of_arch (current_architecture
) < m68020
)
3997 if (fragP
->fr_opcode
[0] == 0x61)
3999 fragP
->fr_opcode
[0] = 0x4E;
4000 fragP
->fr_opcode
[1] = 0xB9; /* JBSR with ABSL LONG offset */
4001 subseg_change (SEG_TEXT
, 0);
4015 else if (fragP
->fr_opcode
[0] == 0x60)
4017 fragP
->fr_opcode
[0] = 0x4E;
4018 fragP
->fr_opcode
[1] = 0xF9; /* JMP with ABSL LONG offset */
4019 subseg_change (SEG_TEXT
, 0);
4020 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0,
4027 as_bad ("Long branch offset not supported.");
4032 fragP
->fr_opcode
[1] = 0xff;
4036 case TAB (BCC68000
, LONG
):
4037 /* only Bcc 68000 instructions can come here */
4038 /* change bcc into b!cc/jmp absl long */
4039 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4040 fragP
->fr_opcode
[1] = 0x6;/* branch offset = 6 */
4042 /* JF: these used to be fr_opcode[2,3], but they may be in a
4043 different frag, in which case refering to them is a no-no.
4044 Only fr_opcode[0,1] are guaranteed to work. */
4045 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4046 *buffer_address
++ = 0xf9;
4047 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4048 subseg_change (SEG_TEXT
, 0);
4049 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
4050 fragP
->fr_offset
, 0,
4055 case TAB (DBCC
, LONG
):
4056 /* only DBcc 68000 instructions can come here */
4057 /* change dbcc into dbcc/jmp absl long */
4058 /* JF: these used to be fr_opcode[2-7], but that's wrong */
4059 *buffer_address
++ = 0x00; /* branch offset = 4 */
4060 *buffer_address
++ = 0x04;
4061 *buffer_address
++ = 0x60; /* put in bra pc+6 */
4062 *buffer_address
++ = 0x06;
4063 *buffer_address
++ = 0x4e; /* put in jmp long (0x4ef9) */
4064 *buffer_address
++ = 0xf9;
4066 fragP
->fr_fix
+= 6; /* account for bra/jmp instructions */
4067 subseg_change (SEG_TEXT
, 0);
4068 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
4069 fragP
->fr_offset
, 0,
4074 case TAB (FBRANCH
, SHORT
):
4075 know ((fragP
->fr_opcode
[1] & 0x40) == 0);
4078 case TAB (FBRANCH
, LONG
):
4079 fragP
->fr_opcode
[1] |= 0x40; /* Turn on LONG bit */
4082 case TAB (PCREL
, SHORT
):
4085 case TAB (PCREL
, LONG
):
4086 /* The thing to do here is force it to ABSOLUTE LONG, since
4087 PCREL is really trying to shorten an ABSOLUTE address anyway */
4088 /* JF FOO This code has not been tested */
4089 subseg_change (SEG_TEXT
, 0);
4090 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
4091 if ((fragP
->fr_opcode
[1] & 0x3F) != 0x3A)
4092 as_bad ("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
4093 fragP
->fr_opcode
[0], fragP
->fr_address
);
4094 fragP
->fr_opcode
[1] &= ~0x3F;
4095 fragP
->fr_opcode
[1] |= 0x39; /* Mode 7.1 */
4097 /* md_number_to_chars(buffer_address,
4098 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
4102 case TAB (PCLEA
, SHORT
):
4103 subseg_change (SEG_TEXT
, 0);
4104 fix_new (fragP
, (int) (fragP
->fr_fix
), 2, fragP
->fr_symbol
, (symbolS
*) 0, fragP
->fr_offset
, 1,
4106 fragP
->fr_opcode
[1] &= ~0x3F;
4107 fragP
->fr_opcode
[1] |= 0x3A;
4110 case TAB (PCLEA
, LONG
):
4111 subseg_change (SEG_TEXT
, 0);
4112 fix_new (fragP
, (int) (fragP
->fr_fix
) + 2, 4, fragP
->fr_symbol
, (symbolS
*) 0, fragP
->fr_offset
+ 2, 1,
4114 *buffer_address
++ = 0x01;
4115 *buffer_address
++ = 0x70;
4117 /* buffer_address+=2; */
4121 } /* switch on subtype */
4125 md_number_to_chars (buffer_address
, (long) disp
, (int) ext
);
4126 fragP
->fr_fix
+= ext
;
4127 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
4128 } /* if extending */
4131 } /* md_convert_frag() */
4133 /* Force truly undefined symbols to their maximum size, and generally set up
4134 the frag list to be relaxed
4137 md_estimate_size_before_relax (fragP
, segment
)
4138 register fragS
*fragP
;
4142 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
4144 old_fix
= fragP
->fr_fix
;
4146 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
4147 switch (fragP
->fr_subtype
)
4150 case TAB (ABRANCH
, SZ_UNDEF
):
4152 if ((fragP
->fr_symbol
!= NULL
) /* Not absolute */
4153 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4155 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), BYTE
);
4158 else if ((fragP
->fr_symbol
== 0) || (cpu_of_arch (current_architecture
) < m68020
))
4160 /* On 68000, or for absolute value, switch to abs long */
4161 /* FIXME, we should check abs val, pick short or long */
4162 if (fragP
->fr_opcode
[0] == 0x61)
4164 fragP
->fr_opcode
[0] = 0x4E;
4165 fragP
->fr_opcode
[1] = 0xB9; /* JBSR with ABSL LONG offset */
4166 subseg_change (SEG_TEXT
, 0);
4167 fix_new (fragP
, fragP
->fr_fix
, 4,
4168 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
4172 else if (fragP
->fr_opcode
[0] == 0x60)
4174 fragP
->fr_opcode
[0] = 0x4E;
4175 fragP
->fr_opcode
[1] = 0xF9; /* JMP with ABSL LONG offset */
4176 subseg_change (SEG_TEXT
, 0);
4177 fix_new (fragP
, fragP
->fr_fix
, 4,
4178 fragP
->fr_symbol
, 0, fragP
->fr_offset
, 0, NO_RELOC
);
4184 as_warn ("Long branch offset to extern symbol not supported.");
4188 { /* Symbol is still undefined. Make it simple */
4189 fix_new (fragP
, (int) (fragP
->fr_fix
), 4, fragP
->fr_symbol
,
4190 (symbolS
*) 0, fragP
->fr_offset
+ 4, 1, NO_RELOC
);
4192 fragP
->fr_opcode
[1] = 0xff;
4198 } /* case TAB(ABRANCH,SZ_UNDEF) */
4200 case TAB (FBRANCH
, SZ_UNDEF
):
4202 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flagseen
['l'])
4204 fragP
->fr_subtype
= TAB (FBRANCH
, SHORT
);
4209 fragP
->fr_subtype
= TAB (FBRANCH
, LONG
);
4213 } /* TAB(FBRANCH,SZ_UNDEF) */
4215 case TAB (PCREL
, SZ_UNDEF
):
4217 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
|| flagseen
['l'])
4219 fragP
->fr_subtype
= TAB (PCREL
, SHORT
);
4224 fragP
->fr_subtype
= TAB (PCREL
, LONG
);
4228 } /* TAB(PCREL,SZ_UNDEF) */
4230 case TAB (BCC68000
, SZ_UNDEF
):
4232 if ((fragP
->fr_symbol
!= NULL
)
4233 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4235 fragP
->fr_subtype
= TAB (BCC68000
, BYTE
);
4238 /* only Bcc 68000 instructions can come here */
4239 /* change bcc into b!cc/jmp absl long */
4240 fragP
->fr_opcode
[0] ^= 0x01; /* invert bcc */
4243 fragP
->fr_opcode
[1] = 0x04; /* branch offset = 6 */
4244 /* JF: these were fr_opcode[2,3] */
4245 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4246 buffer_address
[1] = 0xf8;
4247 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4248 subseg_change (SEG_TEXT
, 0);
4249 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
4250 fragP
->fr_offset
, 0, NO_RELOC
);
4255 fragP
->fr_opcode
[1] = 0x06; /* branch offset = 6 */
4256 /* JF: these were fr_opcode[2,3] */
4257 buffer_address
[0] = 0x4e; /* put in jmp long (0x4ef9) */
4258 buffer_address
[1] = 0xf9;
4259 fragP
->fr_fix
+= 2; /* account for jmp instruction */
4260 subseg_change (SEG_TEXT
, 0);
4261 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
4262 fragP
->fr_offset
, 0, NO_RELOC
);
4267 } /* case TAB(BCC68000,SZ_UNDEF) */
4269 case TAB (DBCC
, SZ_UNDEF
):
4271 if (fragP
->fr_symbol
!= NULL
&& S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
4273 fragP
->fr_subtype
= TAB (DBCC
, SHORT
);
4277 /* only DBcc 68000 instructions can come here */
4278 /* change dbcc into dbcc/jmp absl long */
4279 /* JF: these used to be fr_opcode[2-4], which is wrong. */
4280 buffer_address
[0] = 0x00; /* branch offset = 4 */
4281 buffer_address
[1] = 0x04;
4282 buffer_address
[2] = 0x60; /* put in bra pc + ... */
4286 /* JF: these were fr_opcode[5-7] */
4287 buffer_address
[3] = 0x04; /* plus 4 */
4288 buffer_address
[4] = 0x4e; /* Put in Jump Word */
4289 buffer_address
[5] = 0xf8;
4290 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4291 subseg_change (SEG_TEXT
, 0);
4292 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, 0,
4295 fragP
->fr_offset
, 0, NO_RELOC
);
4300 /* JF: these were fr_opcode[5-7] */
4301 buffer_address
[3] = 0x06; /* Plus 6 */
4302 buffer_address
[4] = 0x4e; /* put in jmp long (0x4ef9) */
4303 buffer_address
[5] = 0xf9;
4304 fragP
->fr_fix
+= 6; /* account for bra/jmp instruction */
4305 subseg_change (SEG_TEXT
, 0);
4306 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
, 0,
4307 fragP
->fr_offset
, 0, NO_RELOC
);
4313 } /* case TAB(DBCC,SZ_UNDEF) */
4315 case TAB (PCLEA
, SZ_UNDEF
):
4317 if ((S_GET_SEGMENT (fragP
->fr_symbol
)) == segment
|| flagseen
['l'])
4319 fragP
->fr_subtype
= TAB (PCLEA
, SHORT
);
4324 fragP
->fr_subtype
= TAB (PCLEA
, LONG
);
4328 } /* TAB(PCLEA,SZ_UNDEF) */
4333 } /* switch on subtype looking for SZ_UNDEF's. */
4335 /* now that SZ_UNDEF are taken care of, check others */
4336 switch (fragP
->fr_subtype
)
4338 case TAB (BCC68000
, BYTE
):
4339 case TAB (ABRANCH
, BYTE
):
4340 /* We can't do a short jump to the next instruction,
4341 so we force word mode. */
4342 if (fragP
->fr_symbol
&& S_GET_VALUE (fragP
->fr_symbol
) == 0 &&
4343 fragP
->fr_symbol
->sy_frag
== fragP
->fr_next
)
4345 fragP
->fr_subtype
= TAB (TABTYPE (fragP
->fr_subtype
), SHORT
);
4352 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
4355 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4356 /* the bit-field entries in the relocation_info struct plays hell
4357 with the byte-order problems of cross-assembly. So as a hack,
4358 I added this mach. dependent ri twiddler. Ugly, but it gets
4360 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
4361 are symbolnum, most sig. byte first. Last byte is broken up with
4362 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
4363 nibble as nuthin. (on Sun 3 at least) */
4364 /* Translate the internal relocation information into target-specific
4368 md_ri_to_chars (the_bytes
, ri
)
4370 struct reloc_info_generic
*ri
;
4373 md_number_to_chars (the_bytes
, ri
->r_address
, 4);
4374 /* now the fun stuff */
4375 the_bytes
[4] = (ri
->r_symbolnum
>> 16) & 0x0ff;
4376 the_bytes
[5] = (ri
->r_symbolnum
>> 8) & 0x0ff;
4377 the_bytes
[6] = ri
->r_symbolnum
& 0x0ff;
4378 the_bytes
[7] = (((ri
->r_pcrel
<< 7) & 0x80) | ((ri
->r_length
<< 5) & 0x60) |
4379 ((ri
->r_extern
<< 4) & 0x10));
4382 #endif /* comment */
4385 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
4388 relax_addressT segment_address_in_file
;
4391 * In: length of relocation (or of address) in chars: 1, 2 or 4.
4392 * Out: GNU LD relocation length code: 0, 1, or 2.
4395 static CONST
unsigned char nbytes_r_length
[] =
4399 know (fixP
->fx_addsy
!= NULL
);
4401 md_number_to_chars (where
,
4402 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
4405 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
4406 ? S_GET_TYPE (fixP
->fx_addsy
)
4407 : fixP
->fx_addsy
->sy_number
);
4409 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
4410 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
4411 where
[6] = r_symbolnum
& 0x0ff;
4412 where
[7] = (((fixP
->fx_pcrel
<< 7) & 0x80) | ((nbytes_r_length
[fixP
->fx_size
] << 5) & 0x60) |
4413 (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 4) & 0x10));
4416 } /* tc_aout_fix_to_chars() */
4418 #endif /* OBJ_AOUT or OBJ_BOUT */
4420 #ifndef WORKING_DOT_WORD
4421 const int md_short_jump_size
= 4;
4422 const int md_long_jump_size
= 6;
4425 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4427 long from_addr
, to_addr
;
4433 offset
= to_addr
- (from_addr
+ 2);
4435 md_number_to_chars (ptr
, (long) 0x6000, 2);
4436 md_number_to_chars (ptr
+ 2, (long) offset
, 2);
4440 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
4442 long from_addr
, to_addr
;
4448 if (cpu_of_arch (current_architecture
) < m68020
)
4450 offset
= to_addr
- S_GET_VALUE (to_symbol
);
4451 md_number_to_chars (ptr
, (long) 0x4EF9, 2);
4452 md_number_to_chars (ptr
+ 2, (long) offset
, 4);
4453 fix_new (frag
, (ptr
+ 2) - frag
->fr_literal
, 4, to_symbol
, (symbolS
*) 0, (long) 0, 0,
4458 offset
= to_addr
- (from_addr
+ 2);
4459 md_number_to_chars (ptr
, (long) 0x60ff, 2);
4460 md_number_to_chars (ptr
+ 2, (long) offset
, 4);
4465 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
4468 10: Absolute 1:8 only
4469 20: Absolute 0:7 only
4470 30: absolute 0:15 only
4471 40: Absolute 0:31 only
4472 50: absolute 0:127 only
4473 55: absolute -64:63 only
4474 60: absolute -128:127 only
4475 70: absolute 0:4095 only
4482 struct m68k_exp
*exp
;
4490 if (*exp
->e_beg
== '0')
4492 if (exp
->e_beg
[1] == 'x')
4493 sscanf (exp
->e_beg
+ 2, "%x", &l
);
4495 sscanf (exp
->e_beg
+ 1, "%O", &l
);
4498 return atol (exp
->e_beg
);
4505 /* Can't do anything */
4508 if (!exp
->e_beg
|| !exp
->e_end
)
4510 seg (exp
) = SEG_ABSOLUTE
;
4513 offs (exp
) = (ok
== 10) ? 1 : 0;
4514 as_warn ("Null expression defaults to %ld", offs (exp
));
4519 if ( /* ok!=80 && */ (exp
->e_end
[-1] == ':' || exp
->e_end
[-1] == '.')
4520 && (exp
->e_end
- exp
->e_beg
) >= 2)
4522 switch (exp
->e_end
[0])
4542 if (exp
->e_end
[-1] == ':')
4543 as_bad ("Unknown size for expression \"%c\"", exp
->e_end
[0]);
4547 c_save
= exp
->e_end
[1];
4548 exp
->e_end
[1] = '\0';
4549 save_in
= input_line_pointer
;
4550 input_line_pointer
= exp
->e_beg
;
4551 switch (expression (&(exp
->e_exp
)))
4554 seg (exp
) = SEG_ABSOLUTE
;
4557 offs (exp
) = (ok
== 10) ? 1 : 0;
4558 as_warn ("Unknown expression: '%s' defaulting to %d", exp
->e_beg
, offs (exp
));
4562 /* Do the same thing the VAX asm does */
4563 seg (exp
) = SEG_ABSOLUTE
;
4569 as_warn ("expression out of range: defaulting to 1");
4577 if (offs (exp
) < 1 || offs (exp
) > 8)
4579 as_warn ("expression out of range: defaulting to 1");
4584 if (offs (exp
) < 0 || offs (exp
) > 7)
4588 if (offs (exp
) < 0 || offs (exp
) > 15)
4592 if (offs (exp
) < 0 || offs (exp
) > 32)
4596 if (offs (exp
) < 0 || offs (exp
) > 127)
4600 if (offs (exp
) < -64 || offs (exp
) > 63)
4604 if (offs (exp
) < -128 || offs (exp
) > 127)
4608 if (offs (exp
) < 0 || offs (exp
) > 4095)
4611 as_warn ("expression out of range: defaulting to 0");
4620 if (offs (exp
) < 0 /* flonum */
4621 && (ok
== 80 /* no bignums */
4622 || (ok
> 10 /* small-int ranges including 0 ok */
4623 /* If we have a flonum zero, a zero integer should
4624 do as well (e.g., in moveq). */
4625 && generic_floating_point_number
.exponent
== 0
4626 && generic_floating_point_number
.low
[0] == 0)))
4628 /* HACK! Turn it into a long */
4629 LITTLENUM_TYPE words
[6];
4631 gen_to_words (words
, 2, 8L); /* These numbers are magic! */
4632 seg (exp
) = SEG_ABSOLUTE
;
4635 offs (exp
) = words
[1] | (words
[0] << 16);
4639 seg (exp
) = SEG_ABSOLUTE
;
4642 offs (exp
) = (ok
== 10) ? 1 : 0;
4643 as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp
->e_beg
, offs (exp
));
4651 case SEG_DIFFERENCE
:
4652 if (ok
>= 10 && ok
<= 70)
4654 seg (exp
) = SEG_ABSOLUTE
;
4657 offs (exp
) = (ok
== 10) ? 1 : 0;
4658 as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp
->e_beg
, offs (exp
));
4664 if (input_line_pointer
!= exp
->e_end
+ 1)
4665 as_bad ("Ignoring junk after expression");
4666 exp
->e_end
[1] = c_save
;
4667 input_line_pointer
= save_in
;
4673 if (!isbyte (offs (exp
)))
4674 as_warn ("expression doesn't fit in BYTE");
4677 if (!isword (offs (exp
)))
4678 as_warn ("expression doesn't fit in WORD");
4686 /* These are the back-ends for the various machine dependent pseudo-ops. */
4687 void demand_empty_rest_of_line (); /* Hate those extra verbose names */
4692 subseg_new (SEG_DATA
, 1);
4693 demand_empty_rest_of_line ();
4699 subseg_new (SEG_DATA
, 2);
4700 demand_empty_rest_of_line ();
4706 /* We don't support putting frags in the BSS segment, we fake it
4707 by marking in_bss, then looking at s_skip for clues */
4709 subseg_new (SEG_BSS
, 0);
4710 demand_empty_rest_of_line ();
4717 register long temp_fill
;
4719 temp
= 1; /* JF should be 2? */
4720 temp_fill
= get_absolute_expression ();
4721 if (!need_pass_2
) /* Never make frag if expect extra pass. */
4722 frag_align (temp
, (int) temp_fill
);
4723 demand_empty_rest_of_line ();
4729 demand_empty_rest_of_line ();
4732 /* s_space is defined in read.c .skip is simply an alias to it. */
4736 * Invocation line includes a switch not recognized by the base assembler.
4737 * See if it's a processor-specific option. These are:
4739 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4740 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4741 * Select the architecture. Instructions or features not
4742 * supported by the selected architecture cause fatal
4743 * errors. More than one may be specified. The default is
4744 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4745 * for -m68000, and -m68882 is a synonym for -m68881.
4746 * -[A]m[c]no-68851, -[A]m[c]no-68881
4747 * Don't accept 688?1 instructions. (The "c" is kind of silly,
4748 * so don't use or document it, but that's the way the parsing
4751 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
4752 * (e.g. m68020) also requests that float instructions be included. This
4753 * is the default setup, mostly to avoid hassling users. A better
4754 * rearrangement of this structure would be to add an option to DENY
4755 * floating point opcodes, for people who want to really know there's none
4756 * of that funny floaty stuff going on. FIXME-later.
4758 #ifndef MAYBE_FLOAT_TOO
4759 #define MAYBE_FLOAT_TOO /* m68881 */ 0 /* this is handled later */
4763 md_parse_option (argP
, cntP
, vecP
)
4770 case 'l': /* -l means keep external to 2 bit offset
4771 rather than 16 bit one */
4774 case 'S': /* -S means that jbsr's always turn into jsr's. */
4779 /* intentional fall-through */
4786 } /* allow an optional "c" */
4788 if (!strcmp (*argP
, "68000")
4789 || !strcmp (*argP
, "68008"))
4791 current_architecture
|= m68000
;
4793 else if (!strcmp (*argP
, "68010"))
4796 omagic
= 1 << 16 | OMAGIC
;
4798 current_architecture
|= m68010
;
4800 else if (!strcmp (*argP
, "68020"))
4802 current_architecture
|= m68020
| MAYBE_FLOAT_TOO
;
4804 else if (!strcmp (*argP
, "68030"))
4806 current_architecture
|= m68030
| MAYBE_FLOAT_TOO
;
4808 else if (!strcmp (*argP
, "68040"))
4810 current_architecture
|= m68040
| MAYBE_FLOAT_TOO
;
4813 else if (!strcmp (*argP
, "68881"))
4815 current_architecture
|= m68881
;
4817 else if (!strcmp (*argP
, "68882"))
4819 current_architecture
|= m68882
;
4820 #endif /* NO_68881 */
4821 /* Even if we aren't configured to support the processor,
4822 it should still be possible to assert that the user
4823 doesn't have it... */
4825 else if (!strcmp (*argP
, "no-68881")
4826 || !strcmp (*argP
, "no-68882"))
4831 else if (!strcmp (*argP
, "68851"))
4833 current_architecture
|= m68851
;
4834 #endif /* NO_68851 */
4836 else if (!strcmp (*argP
, "no-68851"))
4840 else if (!strcmp (*argP
, "pu32"))
4842 current_architecture
|= cpu32
;
4846 as_warn ("Unknown architecture, \"%s\". option ignored", *argP
);
4847 } /* switch on architecture */
4855 if (!strcmp (*argP
, "pic"))
4858 break; /* -pic, Position Independent Code */
4874 /* TEST2: Test md_assemble() */
4875 /* Warning, this routine probably doesn't work anymore */
4879 struct m68k_it the_ins
;
4887 if (!gets (buf
) || !*buf
)
4889 if (buf
[0] == '|' || buf
[1] == '.')
4891 for (cp
= buf
; *cp
; cp
++)
4896 memset (&the_ins
, '\0', sizeof (the_ins
));
4897 m68k_ip (&the_ins
, buf
);
4900 printf ("Error %s in %s\n", the_ins
.error
, buf
);
4904 printf ("Opcode(%d.%s): ", the_ins
.numo
, the_ins
.args
);
4905 for (n
= 0; n
< the_ins
.numo
; n
++)
4906 printf (" 0x%x", the_ins
.opcode
[n
] & 0xffff);
4908 print_the_insn (&the_ins
.opcode
[0], stdout
);
4909 (void) putchar ('\n');
4911 for (n
= 0; n
< strlen (the_ins
.args
) / 2; n
++)
4913 if (the_ins
.operands
[n
].error
)
4915 printf ("op%d Error %s in %s\n", n
, the_ins
.operands
[n
].error
, buf
);
4918 printf ("mode %d, reg %d, ", the_ins
.operands
[n
].mode
, the_ins
.operands
[n
].reg
);
4919 if (the_ins
.operands
[n
].b_const
)
4920 printf ("Constant: '%.*s', ", 1 + the_ins
.operands
[n
].e_const
- the_ins
.operands
[n
].b_const
, the_ins
.operands
[n
].b_const
);
4921 printf ("ireg %d, isiz %d, imul %d, ", the_ins
.operands
[n
].ireg
, the_ins
.operands
[n
].isiz
, the_ins
.operands
[n
].imul
);
4922 if (the_ins
.operands
[n
].b_iadd
)
4923 printf ("Iadd: '%.*s',", 1 + the_ins
.operands
[n
].e_iadd
- the_ins
.operands
[n
].b_iadd
, the_ins
.operands
[n
].b_iadd
);
4924 (void) putchar ('\n');
4936 while (*str
&& *str
!= ' ')
4938 if (str
[-1] == ':' || str
[1] == '=')
4945 /* Possible states for relaxation:
4947 0 0 branch offset byte (bra, etc)
4951 1 0 indexed offsets byte a0@(32,d4:w:1) etc
4955 2 0 two-offset index word-word a0@(32,d4)@(45) etc
4962 /* We have no need to default values of symbols. */
4966 md_undefined_symbol (name
)
4972 /* Parse an operand that is machine-specific.
4973 We just return without modifying the expression if we have nothing
4978 md_operand (expressionP
)
4979 expressionS
*expressionP
;
4983 /* Round up a section size to the appropriate boundary. */
4985 md_section_align (segment
, size
)
4989 return size
; /* Byte alignment is fine */
4992 /* Exactly what point is a PC-relative offset relative TO?
4993 On the 68k, they're relative to the address of the offset, plus
4994 its size. (??? Is this right? FIXME-SOON!) */
4996 md_pcrel_from (fixP
)
4999 return (fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
5003 tc_coff_symbol_emit_hook ()
5008 tc_coff_sizemachdep (frag
)
5011 switch (frag
->fr_subtype
& 0x3)
5025 /* end of tc-m68k.c */