1 /* tc-m68kmote.c All the m68020 specific stuff in one convenient, huge,
2 slow to compile, easy to find file.
3 Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 /* note that this file includes real declarations and thus can only be included by one source file per executable. */
29 #include "opcode/m68k.h"
31 /* This variable contains the value to write out at the beginning of
32 the a.out file. The 2<<16 means that this is a 68020 file instead
33 of an old-style 68000 file */
35 long omagic = 2<<16|OMAGIC; /* Magic byte for header file */
40 /* This array holds the chars that always start a comment. If the
41 pre-processor is disabled, these aren't very useful */
42 const char comment_chars[] = "|";
44 /* This array holds the chars that only start a comment at the beginning of
45 a line. If the line seems to have the form '# 123 filename'
46 .line and .file directives will appear in the pre-processed output */
47 /* Note that input_file.c hand checks for '#' at the beginning of the
48 first line of the input file. This is because the compiler outputs
49 #NO_APP at the beginning of its output. */
50 /* Also note that comments like this one will always work. */
52 const char line_comment_chars[] = "*";
54 const char line_comment_chars[] = "#";
57 /* Chars that can be used to separate mant from exp in floating point nums */
58 const char EXP_CHARS[] = "eE";
60 /* Chars that mean this number is a floating point constant */
64 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
66 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
67 changed in read.c . Ideally it shouldn't have to know about it at all,
68 but nothing is ideal around here.
71 int md_reloc_size = 8; /* Size of relocation record */
73 /* Its an arbitrary name: This means I don't approve of it */
74 /* See flames below */
75 static struct obstack robyn;
77 #define TAB(x,y) (((x)<<2)+(y))
78 #define TABTYPE(xy) ((xy) >> 2)
91 /* Operands we can parse: (And associated modes)
97 reg: address or data register
98 areg: address register
99 apc: address register, PC, ZPC or empty string
100 num: 16 or 32 bit num
102 sz: w or l if omitted, l assumed
103 scale: 1 2 4 or 8 if omitted, 1 assumed
105 7.4 IMMED #num --> NUM
106 0.? DREG dreg --> dreg
107 1.? AREG areg --> areg
108 2.? AINDR areg@ --> *(areg)
109 3.? AINC areg@+ --> *(areg++)
110 4.? ADEC areg@- --> *(--areg)
111 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
112 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
113 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
114 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
115 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
116 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
117 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
118 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
119 7.0 ABSL num:sz --> *(num)
120 num --> *(num) (sz L assumed)
121 *** MSCR otherreg --> Magic
123 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
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)
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 */
270 IC, /* instruction cache token */
271 DC, /* data cache token */
272 NC, /* no cache token */
273 BC, /* both caches token */
277 /* Internal form of an operand. */
279 char *error; /* Couldn't parse it */
280 enum operand_type mode; /* What mode this instruction is in. */
281 enum _register reg; /* Base register */
282 struct m68k_exp *con1;
283 int ireg; /* Index register */
284 int isiz; /* 0==unspec 1==byte(?) 2==short 3==long */
285 int imul; /* Multipy ireg by this (1,2,4,or 8) */
286 struct m68k_exp *con2;
289 /* internal form of a 68020 instruction */
292 char *args; /* list of opcode info */
295 int numo; /* Number of shorts in opcode */
298 struct m68k_op operands[6];
300 int nexp; /* number of exprs in use */
301 struct m68k_exp exprs[4];
303 int nfrag; /* Number of frags we have to produce */
305 int fragoff; /* Where in the current opcode[] the frag ends */
311 int nrel; /* Num of reloc strucs in use */
319 } reloc[5]; /* Five is enough??? */
322 #define cpu_of_arch(x) ((x) & m68000up)
323 #define float_of_arch(x) ((x) & mfloat)
324 #define mmu_of_arch(x) ((x) & mmmu)
326 static struct m68k_it the_ins; /* the instruction being assembled */
328 /* Macros for adding things to the m68k_it struct */
330 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
332 /* Like addword, but goes BEFORE general operands */
333 #define insop(w) {int z;\
334 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
335 the_ins.opcode[z]=the_ins.opcode[z-1];\
336 for(z=0;z<the_ins.nrel;z++)\
337 the_ins.reloc[z].n+=2;\
338 the_ins.opcode[opcode->m_codenum]=w;\
343 #define add_exp(beg,end) (\
344 the_ins.exprs[the_ins.nexp].e_beg=beg,\
345 the_ins.exprs[the_ins.nexp].e_end=end,\
346 &the_ins.exprs[the_ins.nexp++]\
350 /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
351 #define add_fix(width,exp,pc_rel) {\
352 the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
353 (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
354 the_ins.reloc[the_ins.nrel].add=adds((exp));\
355 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
356 the_ins.reloc[the_ins.nrel].off=offs((exp));\
357 the_ins.reloc[the_ins.nrel].wid=width;\
358 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
361 #define add_frag(add,off,type) {\
362 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
363 the_ins.fragb[the_ins.nfrag].fadd=add;\
364 the_ins.fragb[the_ins.nfrag].foff=off;\
365 the_ins.fragb[the_ins.nfrag++].fragty=type;\
368 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
370 #define seg(exp) ((exp)->e_exp.X_seg)
371 #define adds(exp) ((exp)->e_exp.X_add_symbol)
372 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
373 #define offs(exp) ((exp)->e_exp.X_add_number)
378 unsigned long m_opcode;
381 enum m68k_architecture m_arch;
382 struct m68k_incant *m_next;
385 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
386 #define gettwo(x) (((x)->m_opcode)&0xffff)
391 static char *crack_operand(char *str, struct m68k_op *opP);
392 static int get_num(struct m68k_exp *exp, int ok);
393 static int get_regs(int i, char *str, struct m68k_op *opP);
394 static int reverse_16_bits(int in);
395 static int reverse_8_bits(int in);
396 static int try_index(char **s, struct m68k_op *opP);
397 static void install_gen_operand(int mode, int val);
398 static void install_operand(int mode, int val);
399 static void s_bss(void);
400 static void s_data1(void);
401 static void s_data2(void);
402 static void s_even(void);
403 static void s_proc(void);
405 #else /* not __STDC__ */
407 static char *crack_operand();
408 static int get_num();
409 static int get_regs();
410 static int reverse_16_bits();
411 static int reverse_8_bits();
412 static int try_index();
413 static void install_gen_operand();
414 static void install_operand();
416 static void s_data1();
417 static void s_data2();
418 static void s_even();
419 static void s_proc();
421 #endif /* not __STDC__ */
423 static enum m68k_architecture current_architecture = 0;
425 /* BCC68000 is for patching in an extra jmp instruction for long offsets
426 on the 68000. The 68000 doesn't support long branches with branchs */
428 /* This table desribes how you change sizes for the various types of variable
429 size expressions. This version only supports two kinds. */
431 /* Note that calls to frag_var need to specify the maximum expansion needed */
432 /* This is currently 10 bytes for DBCC */
435 How far Forward this mode will reach:
436 How far Backward this mode will reach:
437 How many bytes this mode will add to the size of the frag
438 Which mode to go to if the offset won't fit in this one
442 { 1, 1, 0, 0 }, /* First entries aren't used */
443 { 1, 1, 0, 0 }, /* For no good reason except */
444 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
447 { (127), (-128), 0, TAB(BRANCH,SHORT)},
448 { (32767), (-32768), 2, TAB(BRANCH,LONG) },
452 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
453 { (32767), (-32768), 2, TAB(FBRANCH,LONG)},
457 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
458 { (32767), (-32768), 2, TAB(PCREL,LONG)},
462 { (127), (-128), 0, TAB(BCC68000,SHORT)},
463 { (32767), (-32768), 2, TAB(BCC68000,LONG) },
464 { 0, 0, 6, 0 }, /* jmp long space */
467 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
468 { (32767), (-32768), 2, TAB(DBCC,LONG) },
469 { 0, 0, 10, 0 }, /* bra/jmp long space */
472 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
473 { 32767, -32768, 2, TAB(PCLEA,LONG) },
479 /* These are the machine dependent pseudo-ops. These are included so
480 the assembler can work on the output from the SUN C compiler, which
484 /* This table describes all the machine specific pseudo-ops the assembler
485 has to support. The fields are:
486 pseudo-op name without dot
487 function to call to execute this pseudo-op
488 Integer arg to pass to the function
495 void s_align_bytes();
500 const pseudo_typeS md_pseudo_table[] = {
501 { "xdef", s_globl, 0 },
502 { "sect", s_sect, 0 },
504 { "dc.d", float_cons, 'd' },
505 { "dc.s", float_cons, 'f' },
509 { "comline", s_ds, 1 },
517 { "dcb.b", s_dcb, 1 },
518 { "dcb.w", s_dcb, 2 },
519 { "dcb.l", s_dcb, 4 },
520 { "xcom", s_comm, 0 },
521 { "align", s_align_bytes, 0 },
522 { "chip", s_chip, 0 },
527 const pseudo_typeS md_pseudo_table[] = {
528 { "data1", s_data1, 0 },
529 { "data2", s_data2, 0 },
531 { "even", s_even, 0 },
532 { "skip", s_space, 0 },
533 { "proc", s_proc, 0 },
542 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
543 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
545 #define issbyte(x) ((x)>=-128 && (x)<=127)
546 #define isubyte(x) ((x)>=0 && (x)<=255)
547 #define issword(x) ((x)>=-32768 && (x)<=32767)
548 #define isuword(x) ((x)>=0 && (x)<=65535)
550 #define isbyte(x) ((x)>=-128 && (x)<=255)
551 #define isword(x) ((x)>=-32768 && (x)<=65535)
552 #define islong(x) (1)
554 extern char *input_line_pointer;
561 /* JF these tables here are for speed at the expense of size */
562 /* You can replace them with the #if 0 versions if you really
563 need space and don't mind it running a bit slower */
565 static char mklower_table[256];
566 #define mklower(c) (mklower_table[(unsigned char)(c)])
567 static char notend_table[256];
568 static char alt_notend_table[256];
569 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
570 alt_notend_table[(unsigned char)(s[1])])))
573 #define mklower(c) (isupper(c) ? tolower(c) : c)
576 #define ISSPACE(x) ((x) == ' ' || (x) == '\t')
578 #define MULTIPLIER '*'
581 #define MULTIPLIER ':'
586 /* JF modified this to handle cases where the first part of a symbol name
587 looks like a register */
590 * m68k_reg_parse() := if it looks like a register, return it's token &
591 * advance the pointer.
594 enum _register m68k_reg_parse(ccp)
597 #ifndef MAX_REG_NAME_LEN
598 #define MAX_REG_NAME_LEN (6)
599 #endif /* MAX_REG_NAME_LEN */
600 register char c[MAX_REG_NAME_LEN];
605 c[0] = mklower(ccp[0][0]);
606 #ifdef REGISTER_PREFIX
607 if (c[0] != REGISTER_PREFIX) {
612 for (p = c, q = ccp[0]; p < c + MAX_REG_NAME_LEN; ++p, ++q)
625 if(c[1]>='0' && c[1]<='7') {
630 else if (c[1] == 'c') {
640 if (c[3] >= '0' && c[3] <= '7') {
642 ret = BAD + c[3] - '0';
646 if (c[3] >= '0' && c[3] <= '7') {
648 ret = BAC + c[3] - '0';
651 } else if (c[1] == 'c') {
659 if (c[1] == 'a' && c[2] == 'l') {
664 /* This supports both CCR and CC as the ccr reg. */
665 if(c[1]=='c' && c[2]=='r') {
668 } else if(c[1]=='c') {
671 } else if(c[1]=='a' && (c[2]=='a' || c[2]=='c') && c[3]=='r') {
673 ret = c[2]=='a' ? CAAR : CACR;
676 else if (c[1] == 'r' && c[2] == 'p') {
683 if (c[1] >= '0' && c[1] <= '7') {
685 ret = DATA + c[1] - '0';
686 } else if (c[1] == 'f' && c[2] == 'c') {
689 } else if (c[1] == 'c') {
692 } else if (c[1] == 't' && c[2] == 't') {
693 if ('0' <= c[3] && c[3] <= '1') {
695 ret = DTT0 + (c[3] - '0');
699 else if (c[1] == 'r' && c[2] == 'p') {
707 if(c[2]>='0' && c[2]<='7') {
709 ret = FPREG+c[2]-'0';
712 } else if(c[2]=='i') {
715 } else if(c[2]=='s') {
716 n= (c[3] == 'r' ? 4 : 3);
718 } else if(c[2]=='c') {
719 n= (c[3] == 'r' ? 4 : 3);
721 } else if (!isalpha(c[2]) && !isdigit(c[2])) {
730 if (c[1] == 's' && c[2] == 'p') {
733 } else if (c[1] == 'c') {
736 } else if (c[1] == 't' && c[2] == 't') {
737 if ('0' <= c[3] && c[3] <= '1') {
739 ret = ITT0 + (c[3] - '0');
744 if (c[1] == 's' && c[2] == 'p') {
747 } else if (c[1] == 'm' && c[2] == 'u' && c[3] == 's' && c[4] == 'r') {
761 if(c[2] == 's' && c[3]=='r') {
772 else if (c[1] == 's' && c[2] == 'r') {
780 if (c[1] == 'c' && c[2] == 'c') {
793 } else if (c[1] == 'p') {
796 } else if (c[1] == 'f' && c[2] == 'c') {
808 if (c[1] == 's' && c[2] == 'p') {
811 } else if (c[1] == 'r' && c[2] == 'p') {
818 if (c[1] == 'a' && c[2] == 'l') {
823 if(c[1]=='b' && c[2]=='r') {
829 if(c[1]=='p' && c[2]=='c') {
838 #ifdef REGISTER_PREFIX
841 if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
850 #define SKIP_WHITE() { str++; if(ISSPACE(*str)) str++;}
855 /* Parse an operand from the text *str into the operand struct *opP. */
859 register struct m68k_op *opP;
865 /* Skip leading blank */
869 opP->error="Missing operand";
872 /* *strend = last character of string */
873 for(strend=str;*strend;strend++)
877 /* Logic of the parsing switch(*str):
881 REG AREG or DREG or MSCR 3 or 2 or 13
882 REG- or REG/ REGLST 14
887 (EXPR,REG,INDX) AINDX 8
890 EXP2(REG,INDX) AINDX 8
893 REG means truth(m68k_reg_parse(&str))
894 INDX means truth(try_index(&str,opP))
896 EXP2 means not REG and not '(' and not '-('
900 /* "#<expression>" Immediate mode */
902 opP->con1=add_exp(str,strend);
907 i=m68k_reg_parse(&str);
910 /* "Rn" Register Direct mode */
912 if(i>=DATA+0 && i<=DATA+7)
914 else if(i>=ADDR+0 && i<=ADDR+7)
920 else if(*str=='/' || *str=='-') {
921 /* "Rm-Rn/Ro-Rp" Register list for MOVEM instruction */
923 return get_regs(i,str,opP);
926 opP->error="Junk after register name";
933 i=m68k_reg_parse(&str);
934 if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {
935 /* Can't indirect off non address regs */
936 opP->error="Invalid indirect register";
944 /* "(An)" Address Register Indirect mode */
950 /* "(An)+" Register Indirect w Postincrement */
955 opP->error="Junk after indirect";
960 i=try_index(&str,opP);
961 if(i==FAIL) return FAIL;
962 /* "(An,Rn)" Register Indirect with Index mode*/
967 opP->error="Bad indirect syntax";
972 /* "(EXPR,..." , a displacement */
976 if(stmp=index(str,',')) {
977 opP->con1=add_exp(str,stmp-1);
980 i=m68k_reg_parse(&str);
981 if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC) {
982 /* Can't indirect off non address regs */
983 opP->error="Invalid indirect register";
989 /* "(d,An)" Register Indirect w Displacement */
995 i=try_index(&str,opP);
996 if(i==FAIL) return FAIL;
997 /* "(d,An,Rn)" Register Indirect with Index */
1002 opP->error="Bad indirect syntax";
1007 opP->error="Invalid register";
1012 opP->error="Missing register for indirect";
1021 i=m68k_reg_parse(&str);
1022 if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {
1023 /* Can't indirect off non address regs */
1024 opP->error="Invalid indirect register";
1032 /* "-(An)" Register Indirect with Predecrement */
1036 opP->error="Junk after indirect";
1039 opP->error="Bad indirect syntax";
1042 opP->error="Invalid register";
1045 /* if '-' but not "-(', do nothing */
1048 /* whether *str=='-' or not */
1050 /* "EXP2" or "EXP2(REG..." */
1053 if(stmp=index(str,'(')) {
1054 opP->con1=add_exp(str,stmp-1);
1056 i=m68k_reg_parse(&str);
1057 if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC) {
1058 /* Can't indirect off non address regs */
1059 opP->error="Invalid indirect register";
1065 /* "d(An)" Register Indirect w Displacement */
1071 i=try_index(&str,opP);
1072 if(i==FAIL) return FAIL;
1073 /* "d(An,Rn)" Register Indirect with Index */
1078 opP->error="Bad indirect syntax";
1083 opP->error="Invalid register";
1088 /* "EXP2" Absolute */
1090 if(strend[-1]=='.') { /* mode ==foo.[wl] */
1101 opP->error="Size spec not .W or .L";
1109 opP->con1=add_exp(str,strend);
1114 /* end of m68k_ip_op () */
1117 * m68k_ip_op := '#' + <anything>
1118 * | <register> + range_sep + get_regs
1121 * range_sep := '/' | '-' ;
1123 * SKIP_WHITE := <empty> | ' ' ;
1130 register struct m68k_op *opP;
1134 char *parse_index();
1136 if (ISSPACE(*str)) {
1138 } /* Find the beginning of the string */
1141 opP->error="Missing operand";
1145 for(strend = str; *strend; strend++) ;;
1151 opP->con1=add_exp(str,strend);
1154 } /* Guess what: A constant. Shar and enjoy */
1156 i = m68k_reg_parse(&str);
1158 /* is a register, is exactly a register, and is followed by '@' */
1160 if((i==FAIL || *str!='\0') && *str!='@') {
1163 if(i!=FAIL && (*str=='/' || *str=='-')) {
1165 return(get_regs(i,str,opP));
1167 if ((stmp=strchr(str,'@')) != '\0') {
1168 opP->con1=add_exp(str,stmp-1);
1174 if ((current_architecture & m68020up) == 0) {
1176 } /* if target is not a '20 or better */
1179 if(*stmp++!='(' || *strend--!=')') {
1180 opP->error="Malformed operand";
1183 i=try_index(&stmp,opP);
1184 opP->con2=add_exp(stmp,strend);
1192 } /* if there's an '@' */
1194 opP->con1 = add_exp(str,strend);
1196 } /* not a register, not exactly a register, or no '@' */
1201 if(i>=DATA+0 && i<=DATA+7)
1203 else if(i>=ADDR+0 && i<=ADDR+7)
1210 if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) { /* Can't indirect off non address regs */
1211 opP->error="Invalid indirect register";
1231 opP->error="Junk after indirect";
1234 /* Some kind of indexing involved. Lets find out how bad it is */
1235 i=try_index(&str,opP);
1236 /* Didn't start with an index reg, maybe its offset or offset,reg */
1244 opP->error="Missing )";
1246 case ',': i=0; break;
1247 case '(': i++; break;
1248 case ')': --i; break;
1251 /* if(str[-3]==':') {
1268 opP->error="Specified size isn't :w or :l";
1271 opP->con1=add_exp(beg_str,str-4);
1272 opP->con1->e_siz=siz;
1274 opP->con1=add_exp(beg_str,str-2);
1275 /* Should be offset,reg */
1277 i=try_index(&str,opP);
1279 opP->error="Malformed index reg";
1284 /* We've now got offset) offset,reg) or reg) */
1287 /* Th-the-thats all folks */
1288 if (opP->reg == FAIL) opP->mode = AINDX; /* Other form of indirect */
1289 else if(opP->ireg == FAIL) opP->mode = AOFF;
1290 else opP->mode = AINDX;
1293 /* Next thing had better be another @ */
1294 if(*str!='@' || str[1]!='(') {
1295 opP->error = "junk after indirect";
1299 if ((current_architecture & m68020up) == 0) {
1301 } /* if target is not a '20 or better */
1305 if(opP->ireg != FAIL) {
1308 i = try_index(&str, opP);
1310 opP->error = "Two index registers! not allowed!";
1314 i = try_index(&str, opP);
1325 opP->error="Missing )";
1327 case ',': i=0; break;
1328 case '(': i++; break;
1329 case ')': --i; break;
1333 opP->con2=add_exp(beg_str,str-2);
1335 if (str[-1] == ',') {
1336 if (opP->ireg != FAIL) {
1337 opP->error = "Can't have two index regs";
1341 i = try_index(&str, opP);
1344 opP->error = "malformed index reg";
1349 } else if (opP->ireg != FAIL) {
1359 opP->error="Junk after indirect";
1363 } /* m68k_ip_op() */
1367 * try_index := data_or_address_register + ')' + SKIP_W
1368 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
1370 * multiplier := <empty>
1371 * | ':' + multiplier_number
1374 * multiplier_number := '1' | '2' | '4' | '8' ;
1376 * size_spec := 'l' | 'L' | 'w' | 'W' ;
1378 * SKIP_W := <empty> | ' ' ;
1382 static int try_index(s,opP)
1384 struct m68k_op *opP;
1388 #define SKIP_W() { ss++; if (ISSPACE(*ss)) ss++;}
1392 i=m68k_reg_parse(&ss);
1393 if(!(i>=DATA+0 && i<=ADDR+7)) { /* if i is not DATA or ADDR reg */
1408 opP->error="Missing : in index register";
1423 opP->error="Index register size spec not :w or :l";
1439 opP->error="index multiplier not 1, 2, 4 or 8";
1446 opP->error="Missing )";
1455 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1459 struct m68k_op thark;
1464 bzero(&thark,sizeof(thark));
1465 if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
1467 printf("op1 error %s in %s\n",thark.error,buf);
1468 printf("mode %d, reg %d, ",thark.mode,thark.reg);
1470 printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
1471 printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
1473 printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
1482 static struct hash_control* op_hash = NULL; /* handle of the OPCODE hash table
1483 NULL means any use before m68k_ip_begin()
1490 * This converts a string into a 68k instruction.
1491 * The string must be a bare single instruction in sun format
1492 * with RMS-style 68020 indirects
1495 * It provides some error messages: at most one fatal error message (which
1496 * stops the scan) and at most one warning message for each operand.
1497 * The 68k instruction is returned in exploded form, since we have no
1498 * knowledge of how you parse (or evaluate) your expressions.
1499 * We do however strip off and decode addressing modes and operation
1502 * This function's value is a string. If it is not "" then an internal
1503 * logic error was found: read this code to assign meaning to the string.
1504 * No argument string should generate such an error string:
1505 * it means a bug in our code, not in the user's text.
1507 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1511 /* JF this function no longer returns a useful value. Sorry */
1512 void m68k_ip (instring)
1516 register struct m68k_op *opP;
1517 register struct m68k_incant *opcode, prev_opcode;
1519 register int tmpreg = 0,
1528 char *crack_operand();
1530 LITTLENUM_TYPE words[6];
1531 LITTLENUM_TYPE *wordp;
1533 if (ISSPACE(*instring))
1534 instring++; /* skip leading whitespace */
1536 /* Scan up to end of operation-code, which MUST end in end-of-string
1537 or exactly 1 space. */
1538 for (p = instring; *p != '\0'; p++)
1543 if (p == instring) {
1544 the_ins.error = "No operator";
1545 the_ins.opcode[0] = NULL;
1546 /* the_ins.numo=1; */
1550 /* p now points to the end of the opcode name, probably whitespace.
1551 make sure the name is null terminated by clobbering the whitespace,
1552 look it up in the hash table, then fix it back. */
1556 /* Copy from input line to our private buffer, and drop any dots */
1559 char *dst = our_copy;
1560 char *src = instring;
1570 opcode = (struct m68k_incant *)hash_find (op_hash, our_copy);
1572 /* If no match, try again with a w suffix */
1577 opcode = (struct m68k_incant *)hash_find (op_hash, our_copy);
1585 opcode = (struct m68k_incant *)hash_find (op_hash, instring);
1589 if (opcode == NULL) {
1590 the_ins.error = "Unknown opcode";
1591 the_ins.opcode[0] = NULL;
1592 /* the_ins.numo=1; */
1596 /* found a legitimate opcode, start matching operands */
1597 while (ISSPACE(*p)) ++p;
1599 for(opP = &the_ins.operands[0]; *p; opP++) {
1601 p = crack_operand(p, opP);
1604 the_ins.error=opP->error;
1609 opsfound = opP - &the_ins.operands[0];
1611 /* This ugly hack is to support the floating pt opcodes in their standard form */
1612 /* Essentially, we fake a first enty of type COP#1 */
1613 if (opcode->m_operands[0]=='I') {
1616 for(n=opsfound;n>0;--n)
1617 the_ins.operands[n]=the_ins.operands[n-1];
1619 /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
1620 bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
1621 the_ins.operands[0].mode=MSCR;
1622 the_ins.operands[0].reg=COPNUM; /* COP #1 */
1626 /* We've got the operands. Find an opcode that'll accept them */
1627 for (losing = 0; ; ) {
1628 /* if we didn't get the right number of ops,
1629 or we have no common model with this pattern
1630 then reject this pattern. */
1632 if (opsfound != opcode->m_opnum
1633 || ((opcode->m_arch & current_architecture) == 0)) {
1638 for (s=opcode->m_operands, opP = &the_ins.operands[0]; *s && !losing; s += 2, opP++) {
1639 /* Warning: this switch is huge! */
1640 /* I've tried to organize the cases into this order:
1641 non-alpha first, then alpha by letter. lower-case goes directly
1642 before uppercase counterpart. */
1643 /* Code with multiple case ...: gets sorted by the lowest case ...
1644 it belongs to. I hope this makes sense. */
1647 if (opP->mode == MSCR || opP->mode == IMMED
1648 || opP->mode == DREG || opP->mode == AREG
1649 || opP->mode == AINC || opP->mode == ADEC
1650 || opP->mode == REGLST)
1655 if(opP->mode!=IMMED)
1660 t=get_num(opP->con1,80);
1661 if(s[1]=='b' && !isbyte(t))
1663 else if(s[1]=='w' && !isword(t))
1670 if(opP->mode!=IMMED)
1675 if(opP->mode==MSCR || opP->mode==AREG ||
1676 opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
1681 if(opP->mode==MSCR || opP->reg==PC ||
1682 opP->reg==ZPC || opP->mode==REGLST)
1688 if(opP->mode==MSCR || opP->mode==DREG ||
1689 opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
1690 opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
1695 if(opP->mode==MSCR || opP->mode==REGLST)
1710 if(opP->mode==MSCR || opP->mode==AREG ||
1711 opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
1716 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
1721 if(opP->mode==MSCR || opP->mode==AREG ||
1722 opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
1723 opP->reg==ZPC || opP->mode==REGLST)
1728 if(opP->mode==MSCR || opP->mode==AREG ||
1729 opP->mode==IMMED || opP->mode==REGLST)
1733 case '~': /* For now! (JF FOO is this right?) */
1734 if(opP->mode==MSCR || opP->mode==DREG ||
1735 opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
1744 if (opP->mode != AINDR) {
1746 } /* if not address register indirect */
1749 if(opP->mode!=ABSL || (flagseen['S'] && instring[0] == 'j'
1750 && instring[1] == 'b'
1751 && instring[2] == 's'
1752 && instring[3] == 'r'))
1757 if(opP->mode!=MSCR || opP->reg!=CCR)
1761 case 'd': /* FOO This mode is a KLUDGE!! */
1762 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
1763 opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
1773 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
1778 if(opP->mode!=MSCR || opP->reg<COPNUM ||
1784 if (opP->mode != MSCR
1787 || cpu_of_arch(current_architecture) < m68010 /* before 68010 had none */
1788 || (cpu_of_arch(current_architecture) < m68020
1792 && opP->reg != VBR) /* 68010's had only these */
1793 || (cpu_of_arch(current_architecture) < m68040
1801 && opP->reg != ISP) /* 680[23]0's have only these */
1802 || (cpu_of_arch(current_architecture) == m68040 /* 68040 has all but this */
1803 && opP->reg == CAAR)) {
1805 } /* doesn't cut it */
1809 if(opP->mode!=IMMED)
1815 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
1820 opP->reg=1<<(opP->reg-DATA);
1822 } else if(opP->mode!=REGLST) {
1824 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
1826 else if(s[1]=='3' && opP->reg&0x7000000)
1831 if(opP->mode!=IMMED)
1836 t=get_num(opP->con1,80);
1837 if(!issbyte(t) || isvar(opP->con1))
1843 if(opP->mode!=DREG && opP->mode!=IMMED)
1848 if(opP->mode!=IMMED)
1853 t=get_num(opP->con1,80);
1854 if(t<1 || t>8 || isvar(opP->con1))
1860 if(opP->mode!=DREG && opP->mode!=AREG)
1865 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
1870 if(opP->mode!=MSCR || opP->reg!=SR)
1875 if(opP->mode!=MSCR || opP->reg!=USP)
1879 /* JF these are out of order. We could put them
1880 in order if we were willing to put up with
1881 bunches of #ifdef m68851s in the code */
1883 /* Memory addressing mode used by pflushr */
1885 if(opP->mode==MSCR || opP->mode==DREG ||
1886 opP->mode==AREG || opP->mode==REGLST)
1891 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
1896 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
1897 opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
1902 if (opP->reg != VAL)
1907 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
1913 if (opP->mode != MSCR ||
1914 (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
1915 !(opP->reg >= BAC && opP->reg <= BAC+7)))
1920 if (opP->reg != PSR)
1925 if (opP->reg != PCSR)
1933 && opP->reg != BC) {
1935 } /* not a cache specifier. */
1939 if (opP->mode != ABSL) {
1941 } /* not absolute */
1945 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1946 *s, __LINE__, __FILE__);
1947 } /* switch on type of operand */
1950 } /* for each operand */
1951 } /* if immediately wrong */
1958 if (!opcode->m_next)
1960 if ((opcode->m_arch & current_architecture) == 0)
1962 the_ins.error = "Opcode not available on architecture specified";
1968 the_ins.error = "instruction/operands mismatch";
1972 } /* Fell off the end */
1973 opcode = opcode->m_next;
1977 /* now assemble it */
1979 the_ins.args=opcode->m_operands;
1980 the_ins.numargs=opcode->m_opnum;
1981 the_ins.numo=opcode->m_codenum;
1982 the_ins.opcode[0]=getone(opcode);
1983 the_ins.opcode[1]=gettwo(opcode);
1985 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++) {
1986 /* This switch is a doozy.
1987 Watch the first step; its a big one! */
2005 tmpreg=0x3c; /* 7.4 */
2006 if (strchr("bwl",s[1])) nextword=get_num(opP->con1,80);
2007 else nextword=nextword=get_num(opP->con1,0);
2008 if(isvar(opP->con1))
2009 add_fix(s[1],opP->con1,0);
2012 if(!isbyte(nextword))
2013 opP->error="operand out of range";
2018 if(!isword(nextword))
2019 opP->error="operand out of range";
2024 addword(nextword>>16);
2046 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
2047 *s, s[1], __LINE__, __FILE__);
2052 /* We gotta put out some float */
2053 if(seg(opP->con1)!=SEG_BIG) {
2054 int_to_gen(nextword);
2055 gen_to_words(words,baseo,(long int)outro);
2056 for(wordp=words;baseo--;wordp++)
2060 if(offs(opP->con1)>0) {
2061 as_warn("Bignum assumed to be binary bit-pattern");
2062 if(offs(opP->con1)>baseo) {
2063 as_warn("Bignum too big for %c format; truncated",s[1]);
2064 offs(opP->con1)=baseo;
2066 baseo-=offs(opP->con1);
2067 for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
2073 gen_to_words(words,baseo,(long)outro);
2074 for (wordp=words;baseo--;wordp++)
2078 tmpreg=opP->reg-DATA; /* 0.dreg */
2081 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
2084 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
2087 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
2090 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
2094 nextword=get_num(opP->con1,80);
2095 /* Force into index mode. Hope this works */
2097 /* We do the first bit for 32-bit displacements,
2098 and the second bit for 16 bit ones. It is
2099 possible that we should make the default be
2100 WORD instead of LONG, but I think that'd
2101 break GCC, so we put up with a little
2102 inefficiency for the sake of working output.
2105 if( !issword(nextword)
2106 || ( isvar(opP->con1)
2107 && ( ( opP->con1->e_siz==0
2108 && flagseen['l']==0)
2109 || opP->con1->e_siz==3))) {
2112 tmpreg=0x3B; /* 7.3 */
2114 tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
2115 if(isvar(opP->con1)) {
2117 add_frag(adds(opP->con1),
2119 TAB(PCLEA,SZ_UNDEF));
2123 add_fix('l',opP->con1,1);
2127 addword(nextword>>16);
2130 tmpreg=0x3A; /* 7.2 */
2132 tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
2134 if(isvar(opP->con1)) {
2136 add_fix('w',opP->con1,1);
2138 add_fix('w',opP->con1,0);
2147 know(current_architecture & m68020up);
2148 /* intentional fall-through */
2151 baseo=get_num(opP->con1,80);
2152 outro=get_num(opP->con2,80);
2153 /* Figure out the 'addressing mode' */
2154 /* Also turn on the BASE_DISABLE bit, if needed */
2155 if(opP->reg==PC || opP->reg==ZPC) {
2156 tmpreg=0x3b; /* 7.3 */
2159 } else if(opP->reg==FAIL) {
2161 tmpreg=0x30; /* 6.garbage */
2162 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
2164 siz1= (opP->con1) ? opP->con1->e_siz : 0;
2165 siz2= (opP->con2) ? opP->con2->e_siz : 0;
2167 /* Index register stuff */
2168 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
2169 nextword|=(opP->ireg-DATA)<<12;
2171 if(opP->isiz==0 || opP->isiz==3)
2175 case 2: nextword|=0x200; break;
2176 case 4: nextword|=0x400; break;
2177 case 8: nextword|=0x600; break;
2178 default: as_fatal("failed sanity check.");
2181 GET US OUT OF HERE! */
2183 /* Must be INDEX, with an index
2184 register. Address register
2185 cannot be ZERO-PC, and either
2186 :b was forced, or we know
2188 if( opP->mode==AINDX
2193 && !isvar(opP->con1)))) {
2194 nextword +=baseo&0xff;
2196 if(isvar(opP->con1))
2197 add_fix('B',opP->con1,0);
2201 nextword|=0x40; /* No index reg */
2203 /* It aint simple */
2205 /* If the guy specified a width, we assume that
2206 it is wide enough. Maybe it isn't. If so, we lose
2210 if(isvar(opP->con1) || !issword(baseo)) {
2221 as_warn("Byte dispacement won't work. Defaulting to :w");
2230 /* Figure out innner displacement stuff */
2231 if(opP->mode!=AINDX) {
2234 if(isvar(opP->con2) || !issword(outro)) {
2245 as_warn("Byte dispacement won't work. Defaulting to :w");
2253 if(opP->mode==APODX) nextword|=0x04;
2254 else if(opP->mode==AMIND) nextword|=0x40;
2258 if(isvar(opP->con1)) {
2259 if(opP->reg==PC || opP->reg==ZPC) {
2260 add_fix(siz1==3 ? 'l' : 'w',opP->con1,1);
2261 opP->con1->e_exp.X_add_number+=6;
2263 add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
2270 if(isvar(opP->con2)) {
2271 if(opP->reg==PC || opP->reg==ZPC) {
2272 add_fix(siz2==3 ? 'l' : 'w',opP->con2,1);
2273 opP->con1->e_exp.X_add_number+=6;
2275 add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
2285 nextword=get_num(opP->con1,80);
2286 switch(opP->con1->e_siz) {
2288 as_warn("Unknown size for absolute reference");
2290 if(!isvar(opP->con1) && issword(offs(opP->con1))) {
2291 tmpreg=0x38; /* 7.0 */
2295 /* Don't generate pc relative code
2296 on 68010 and 68000 */
2299 && seg(opP->con1) == SEG_TEXT
2300 && now_seg == SEG_TEXT
2301 && cpu_of_arch(current_architecture) < m68020
2303 && !strchr("~%&$?", s[0])) {
2304 tmpreg=0x3A; /* 7.2 */
2305 add_frag(adds(opP->con1),
2307 TAB(PCREL,SZ_UNDEF));
2310 case 3: /* Fall through into long */
2311 if(isvar(opP->con1))
2312 add_fix('l',opP->con1,0);
2314 tmpreg=0x39; /* 7.1 mode */
2315 addword(nextword>>16);
2320 if(isvar(opP->con1))
2321 add_fix('w',opP->con1,0);
2323 tmpreg=0x38; /* 7.0 mode */
2330 as_bad("unknown/incorrect operand");
2333 install_gen_operand(s[1],tmpreg);
2338 switch(s[1]) { /* JF: I hate floating point! */
2353 tmpreg=get_num(opP->con1,tmpreg);
2354 if(isvar(opP->con1))
2355 add_fix(s[1],opP->con1,0);
2357 case 'b': /* Danger: These do no check for
2358 certain types of overflow.
2361 opP->error="out of range";
2363 if(isvar(opP->con1))
2364 the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
2368 opP->error="out of range";
2370 if(isvar(opP->con1))
2371 the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
2374 insop(tmpreg); /* Because of the way insop works, we put these two out backwards */
2376 if(isvar(opP->con1))
2377 the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
2383 install_operand(s[1],tmpreg);
2386 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s[1], __LINE__, __FILE__);
2394 install_operand(s[1],opP->reg-ADDR);
2398 tmpreg=get_num(opP->con1,80);
2401 /* Needs no offsetting */
2402 add_fix('B',opP->con1,1);
2405 /* Offset the displacement to be relative to byte disp location */
2406 opP->con1->e_exp.X_add_number+=2;
2407 add_fix('w',opP->con1,1);
2412 if (cpu_of_arch(current_architecture) < m68020) /* 68000 or 010 */
2413 as_warn("Can't use long branches on 68000/68010");
2414 the_ins.opcode[the_ins.numo-1]|=0xff;
2415 /* Offset the displacement to be relative to byte disp location */
2416 opP->con1->e_exp.X_add_number+=4;
2417 add_fix('l',opP->con1,1);
2422 if(subs(opP->con1)) /* We can't relax it */
2425 /* This could either be a symbol, or an
2426 absolute address. No matter, the
2427 frag hacking will finger it out.
2428 Not quite: it can't switch from
2429 BRANCH to BCC68000 for the case
2430 where opnd is absolute (it needs
2431 to use the 68000 hack since no
2432 conditional abs jumps). */
2433 if (((cpu_of_arch(current_architecture) < m68020) || (0==adds(opP->con1)))
2434 && (the_ins.opcode[0] >= 0x6200)
2435 && (the_ins.opcode[0] <= 0x6f00)) {
2436 add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
2438 add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
2442 if(isvar(opP->con1)) {
2443 /* check for DBcc instruction */
2444 if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8) {
2445 /* size varies if patch */
2446 /* needed for long form */
2447 add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
2452 opP->con1->e_exp.X_add_number+=2;
2453 add_fix('w',opP->con1,1);
2457 case 'C': /* Fixed size LONG coproc branches */
2458 the_ins.opcode[the_ins.numo-1]|=0x40;
2459 /* Offset the displacement to be relative to byte disp location */
2460 /* Coproc branches don't have a byte disp option, but they are
2461 compatible with the ordinary branches, which do... */
2462 opP->con1->e_exp.X_add_number+=4;
2463 add_fix('l',opP->con1,1);
2467 case 'c': /* Var size Coprocesssor branches */
2468 if(subs(opP->con1)) {
2469 add_fix('l',opP->con1,1);
2470 add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
2471 } else if(adds(opP->con1)) {
2472 add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
2474 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2475 the_ins.opcode[the_ins.numo-1]|=0x40;
2476 add_fix('l',opP->con1,1);
2482 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
2483 s[1], __LINE__, __FILE__);
2487 case 'C': /* Ignore it */
2490 case 'd': /* JF this is a kludge */
2491 if(opP->mode==AOFF) {
2492 install_operand('s',opP->reg-ADDR);
2496 tmpP=opP->con1->e_end-2;
2498 opP->con1->e_end-=4; /* point to the , */
2499 baseo=m68k_reg_parse(&tmpP);
2500 if(baseo<ADDR+0 || baseo>ADDR+7) {
2501 as_bad("Unknown address reg, using A0");
2504 install_operand('s',baseo);
2506 tmpreg=get_num(opP->con1,80);
2507 if(!issword(tmpreg)) {
2508 as_warn("Expression out of range, using 0");
2515 install_operand(s[1],opP->reg-DATA);
2519 install_operand(s[1],opP->reg-FPREG);
2523 tmpreg=1+opP->reg-COPNUM;
2526 install_operand(s[1],tmpreg);
2529 case 'J': /* JF foo */
2531 case SFC: tmpreg=0x000; break;
2532 case DFC: tmpreg=0x001; break;
2533 case CACR: tmpreg=0x002; break;
2534 case TC: tmpreg=0x003; break;
2535 case ITT0: tmpreg=0x004; break;
2536 case ITT1: tmpreg=0x005; break;
2537 case DTT0: tmpreg=0x006; break;
2538 case DTT1: tmpreg=0x007; break;
2540 case USP: tmpreg=0x800; break;
2541 case VBR: tmpreg=0x801; break;
2542 case CAAR: tmpreg=0x802; break;
2543 case MSP: tmpreg=0x803; break;
2544 case ISP: tmpreg=0x804; break;
2545 case MMUSR: tmpreg=0x805; break;
2546 case URP: tmpreg=0x806; break;
2547 case SRP: tmpreg=0x807; break;
2549 as_fatal("failed sanity check.");
2551 install_operand(s[1],tmpreg);
2555 tmpreg=get_num(opP->con1,55);
2556 install_operand(s[1],tmpreg&0x7f);
2562 if(tmpreg&0x7FF0000)
2563 as_bad("Floating point register in register list");
2564 insop(reverse_16_bits(tmpreg));
2566 if(tmpreg&0x700FFFF)
2567 as_bad("Wrong register in floating-point reglist");
2568 install_operand(s[1],reverse_8_bits(tmpreg>>16));
2575 if(tmpreg&0x7FF0000)
2576 as_bad("Floating point register in register list");
2578 } else if(s[1]=='8') {
2579 if(tmpreg&0x0FFFFFF)
2580 as_bad("incorrect register in reglist");
2581 install_operand(s[1],tmpreg>>24);
2583 if(tmpreg&0x700FFFF)
2584 as_bad("wrong register in floating-point reglist");
2586 install_operand(s[1],tmpreg>>16);
2591 install_operand(s[1],get_num(opP->con1,60));
2595 tmpreg= (opP->mode==DREG)
2596 ? 0x20+opP->reg-DATA
2597 : (get_num(opP->con1,40)&0x1F);
2598 install_operand(s[1],tmpreg);
2602 tmpreg=get_num(opP->con1,10);
2605 install_operand(s[1],tmpreg);
2609 /* This depends on the fact that ADDR registers are
2610 eight more than their corresponding DATA regs, so
2611 the result will have the ADDR_REG bit set */
2612 install_operand(s[1],opP->reg-DATA);
2616 if(opP->reg==FPI) tmpreg=0x1;
2617 else if(opP->reg==FPS) tmpreg=0x2;
2618 else if(opP->reg==FPC) tmpreg=0x4;
2619 else as_fatal("failed sanity check.");
2620 install_operand(s[1],tmpreg);
2623 case 'S': /* Ignore it */
2627 install_operand(s[1],get_num(opP->con1,30));
2630 case 'U': /* Ignore it */
2635 case NC: tmpreg = 0; break;
2636 case DC: tmpreg = 1; break;
2637 case IC: tmpreg = 2; break;
2638 case BC: tmpreg = 3; break;
2640 as_fatal("failed sanity check");
2641 } /* switch on cache token */
2642 install_operand(s[1], tmpreg);
2645 /* JF: These are out of order, I fear. */
2655 as_fatal("failed sanity check.");
2657 install_operand(s[1],tmpreg);
2678 as_fatal("failed sanity check.");
2680 install_operand(s[1],tmpreg);
2684 if (opP->reg == VAL)
2686 as_fatal("failed sanity check.");
2701 as_fatal("failed sanity check.");
2703 install_operand(s[1],tmpreg);
2708 case BAD: case BAD+1: case BAD+2: case BAD+3:
2709 case BAD+4: case BAD+5: case BAD+6: case BAD+7:
2710 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2713 case BAC: case BAC+1: case BAC+2: case BAC+3:
2714 case BAC+4: case BAC+5: case BAC+6: case BAC+7:
2715 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2719 as_fatal("failed sanity check.");
2721 install_operand(s[1], tmpreg);
2724 know(opP->reg == PSR);
2727 know(opP->reg == PCSR);
2731 tmpreg=get_num(opP->con1,80);
2732 install_operand(s[1], tmpreg);
2735 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s[0], __LINE__, __FILE__);
2738 /* By the time whe get here (FINALLY) the_ins contains the complete
2739 instruction, ready to be emitted. . . */
2743 * get_regs := '/' + ?
2744 * | '-' + <register>
2745 * | '-' + <register> + ?
2750 * The idea here must be to scan in a set of registers but I don't
2751 * understand it. Looks awfully sloppy to me but I don't have any doc on
2758 static int get_regs(i,str,opP)
2760 struct m68k_op *opP;
2763 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2764 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2765 unsigned long cur_regs = 0;
2769 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2770 else if(x==FPS) cur_regs|=(1<<25);\
2771 else if(x==FPC) cur_regs|=(1<<26);\
2772 else cur_regs|=(1<<(x-1)); }
2779 } else if(*str=='-') {
2781 reg2=m68k_reg_parse(&str);
2782 if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
2783 opP->error="unknown register in register list";
2792 } else if(*str=='\0') {
2796 opP->error="unknow character in register list";
2799 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2802 reg1=m68k_reg_parse(&str);
2803 if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
2804 opP->error="unknown register in register list";
2812 static int reverse_16_bits(in)
2818 static int mask[16] = {
2819 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2820 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2827 } /* reverse_16_bits() */
2829 static int reverse_8_bits(in)
2835 static int mask[8] = {
2836 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2844 } /* reverse_8_bits() */
2846 static void install_operand(mode,val)
2852 the_ins.opcode[0]|=val & 0xFF; /* JF FF is for M kludge */
2855 the_ins.opcode[0]|=val<<9;
2858 the_ins.opcode[1]|=val<<12;
2861 the_ins.opcode[1]|=val<<6;
2864 the_ins.opcode[1]|=val;
2867 the_ins.opcode[2]|=val<<12;
2870 the_ins.opcode[2]|=val<<6;
2873 /* DANGER! This is a hack to force cas2l and cas2w cmds
2874 to be three words long! */
2876 the_ins.opcode[2]|=val;
2879 the_ins.opcode[1]|=val<<7;
2882 the_ins.opcode[1]|=val<<10;
2886 the_ins.opcode[1]|=val<<5;
2891 the_ins.opcode[1]|=(val<<10)|(val<<7);
2894 the_ins.opcode[1]|=(val<<12)|val;
2897 the_ins.opcode[0]|=val=0xff;
2900 the_ins.opcode[0]|=val<<9;
2903 the_ins.opcode[1]|=val;
2906 the_ins.opcode[1]|=val;
2907 the_ins.numo++; /* What a hack */
2910 the_ins.opcode[1]|=val<<4;
2917 the_ins.opcode[0] |= (val << 6);
2920 the_ins.opcode[1] = (val >> 16);
2921 the_ins.opcode[2] = val & 0xffff;
2925 as_fatal("failed sanity check.");
2927 } /* install_operand() */
2929 static void install_gen_operand(mode,val)
2935 the_ins.opcode[0]|=val;
2938 /* This is a kludge!!! */
2939 the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
2948 the_ins.opcode[0]|=val;
2950 /* more stuff goes here */
2952 as_fatal("failed sanity check.");
2954 } /* install_gen_operand() */
2957 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2958 * then deal with the bitfield hack.
2961 static char *crack_operand(str,opP)
2963 register struct m68k_op *opP;
2965 register int parens;
2967 register char *beg_str;
2973 for(parens=0;*str && (parens>0 || notend(str));str++) {
2974 if(*str=='(') parens++;
2975 else if(*str==')') {
2976 if(!parens) { /* ERROR */
2977 opP->error="Extra )";
2983 if(!*str && parens) { /* ERROR */
2984 opP->error="Missing )";
2989 if(m68k_ip_op(beg_str,opP)==FAIL) {
2996 c= *++str; /* JF bitfield hack */
3001 as_bad("Missing operand");
3006 /* See the comment up above where the #define notend(... is */
3011 if(*s==',') return 0;
3012 if(*s=='{' || *s=='}')
3014 if(*s!=':') return 1;
3015 /* This kludge here is for the division cmd, which is a kludge */
3016 if(index("aAdD#",s[1])) return 0;
3022 int done_pseudo(str)
3025 extern struct hash_control * po_hash;
3032 is_end_of_line[0] = 1;
3033 /* Skip over name of pseudo, change to lower case */
3034 while (isalpha(*ptr) || *ptr == '.')
3036 if (isupper(*ptr)) {
3037 *ptr = tolower(*ptr);
3046 pop = (pseudo_typeS *)hash_find(po_hash, str);
3049 if (pop != (pseudo_typeS *)NULL)
3051 input_line_pointer = null_ptr+1;
3053 /* Now we point to first non-blank char after pseudo op */
3054 (*pop->poc_handler)(pop->poc_val);
3055 input_line_pointer--;
3060 /* Just put back the char where the null was put and return as if nothing had happened */
3068 /* This is the guts of the machine-dependent assembler. STR points to a
3069 machine dependent instruction. This function is supposed to emit
3070 the frags/bytes it assembles to.
3081 int shorts_this_frag;
3083 /* if (done_pseudo(str)) return ;*/
3087 if (current_architecture == 0) {
3088 current_architecture = (m68020
3096 } /* default current_architecture */
3098 bzero((char *)(&the_ins),sizeof(the_ins)); /* JF for paranoia sake */
3103 for(n=the_ins.numargs;n;--n)
3104 if(the_ins.operands[n].error) {
3105 er=the_ins.operands[n].error;
3110 as_bad("\"%s\" -- Statement '%s' ignored",er,str);
3114 if(the_ins.nfrag==0) { /* No frag hacking involved; just put it out */
3115 toP=frag_more(2*the_ins.numo);
3116 fromP= &the_ins.opcode[0];
3117 for(m=the_ins.numo;m;--m) {
3118 md_number_to_chars(toP,(long)(*fromP),2);
3122 /* put out symbol-dependent info */
3123 for(m=0;m<the_ins.nrel;m++) {
3124 switch(the_ins.reloc[m].wid) {
3141 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins.reloc[m].wid);
3145 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
3147 the_ins.reloc[m].add,
3148 the_ins.reloc[m].sub,
3149 the_ins.reloc[m].off,
3150 the_ins.reloc[m].pcrel,
3156 /* There's some frag hacking */
3157 for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
3160 if(n==0) wid=2*the_ins.fragb[n].fragoff;
3161 else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
3165 for(m=wid/2;m;--m) {
3166 md_number_to_chars(toP,(long)(*fromP),2);
3171 for(m=0;m<the_ins.nrel;m++) {
3172 if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
3173 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
3176 wid=the_ins.reloc[m].wid;
3179 the_ins.reloc[m].wid=0;
3180 wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
3183 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
3185 the_ins.reloc[m].add,
3186 the_ins.reloc[m].sub,
3187 the_ins.reloc[m].off,
3188 the_ins.reloc[m].pcrel,
3191 /* know(the_ins.fragb[n].fadd); */
3192 (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
3193 the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
3195 n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
3198 toP=frag_more(n*sizeof(short));
3200 md_number_to_chars(toP,(long)(*fromP),2);
3206 for(m=0;m<the_ins.nrel;m++) {
3209 wid=the_ins.reloc[m].wid;
3212 the_ins.reloc[m].wid=0;
3213 wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
3216 (the_ins.reloc[m].n + toP-frag_now->fr_literal)- /* the_ins.numo */ shorts_this_frag*2,
3218 the_ins.reloc[m].add,
3219 the_ins.reloc[m].sub,
3220 the_ins.reloc[m].off,
3221 the_ins.reloc[m].pcrel,
3226 /* This function is called once, at assembler startup time. This should
3227 set up all the tables, etc that the MD part of the assembler needs
3233 * md_begin -- set up hash tables with 68000 instructions.
3234 * similar to what the vax assembler does. ---phr
3236 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
3237 a copy of it at runtime, adding in the information we want but isn't
3238 there. I think it'd be better to have an awk script hack the table
3239 at compile time. Or even just xstr the table and use it as-is. But
3240 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
3243 register const struct m68k_opcode *ins;
3244 register struct m68k_incant *hack,
3246 register char *retval = 0; /* empty string, or error msg text */
3247 register unsigned int i;
3250 if ((op_hash = hash_new()) == NULL)
3251 as_fatal("Virtual memory exhausted");
3253 obstack_begin(&robyn,4000);
3254 for (ins = m68k_opcodes; ins < endop; ins++) {
3255 hack=slak=(struct m68k_incant *)obstack_alloc(&robyn,sizeof(struct m68k_incant));
3257 /* we *could* ignore insns that don't match our
3258 arch here but just leaving them out of the
3260 slak->m_operands=ins->args;
3261 slak->m_opnum=strlen(slak->m_operands)/2;
3262 slak->m_arch = ins->arch;
3263 slak->m_opcode=ins->opcode;
3264 /* This is kludgey */
3265 slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
3266 if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
3267 slak->m_next=(struct m68k_incant *) obstack_alloc(&robyn,sizeof(struct m68k_incant));
3274 retval = hash_insert (op_hash, ins->name,(char *)hack);
3275 /* Didn't his mommy tell him about null pointers? */
3276 if(retval && *retval)
3277 as_fatal("Internal Error: Can't hash %s: %s",ins->name,retval);
3280 for (i = 0; i < sizeof(mklower_table) ; i++)
3281 mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
3283 for (i = 0 ; i < sizeof(notend_table) ; i++) {
3284 notend_table[i] = 0;
3285 alt_notend_table[i] = 0;
3287 notend_table[','] = 1;
3288 notend_table['{'] = 1;
3289 notend_table['}'] = 1;
3290 alt_notend_table['a'] = 1;
3291 alt_notend_table['A'] = 1;
3292 alt_notend_table['d'] = 1;
3293 alt_notend_table['D'] = 1;
3294 alt_notend_table['#'] = 1;
3295 alt_notend_table['f'] = 1;
3296 alt_notend_table['F'] = 1;
3298 #ifdef REGISTER_PREFIX
3299 alt_notend_table[REGISTER_PREFIX] = 1;
3306 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
3307 || (*s == ':' && strchr("aAdD#", s[1]))) \
3311 /* This funciton is called once, before the assembler exits. It is
3312 supposed to do any final cleanup for this part of the assembler.
3319 /* Equal to MAX_PRECISION in atof-ieee.c */
3320 #define MAX_LITTLENUMS 6
3322 /* Turn a string in str into a floating point constant of type
3323 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3324 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
3327 md_atof(type,litP,sizeP)
3333 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3334 LITTLENUM_TYPE *wordP;
3365 return "Bad call to MD_ATOF()";
3367 t=atof_ieee(input_line_pointer,type,words);
3369 input_line_pointer=t;
3371 *sizeP=prec * sizeof(LITTLENUM_TYPE);
3372 for(wordP=words;prec--;) {
3373 md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
3374 litP+=sizeof(LITTLENUM_TYPE);
3376 return ""; /* Someone should teach Dean about null pointers */
3379 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
3380 for use in the a.out file, and stores them in the array pointed to by buf.
3381 This knows about the endian-ness of the target machine and does
3382 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
3383 2 (short) and 4 (long) Floating numbers are put out as a series of
3384 LITTLENUMS (shorts, here at least)
3387 md_number_to_chars(buf,val,n)
3407 as_fatal("failed sanity check.");
3412 md_apply_fix(fixP, val)
3416 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3418 switch(fixP->fx_size) {
3433 BAD_CASE (fixP->fx_size);
3438 /* *fragP has been relaxed to its final size, and now needs to have
3439 the bytes inside it modified to conform to the new size There is UGLY
3443 md_convert_frag(headers, fragP)
3444 object_headers *headers;
3445 register fragS *fragP;
3450 /* Address in object code of the displacement. */
3451 register int object_address = fragP -> fr_fix + fragP -> fr_address;
3453 #ifdef IBM_COMPILER_SUX
3454 /* This is wrong but it convinces the native rs6000 compiler to
3455 generate the code we want. */
3456 register char *buffer_address = fragP -> fr_literal;
3457 buffer_address += fragP -> fr_fix;
3458 #else /* IBM_COMPILER_SUX */
3459 /* Address in gas core of the place to store the displacement. */
3460 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
3461 #endif /* IBM_COMPILER_SUX */
3463 /* No longer true: know(fragP->fr_symbol); */
3465 /* The displacement of the address, from current location. */
3466 disp = fragP->fr_symbol ? S_GET_VALUE(fragP->fr_symbol) : 0;
3467 disp = (disp + fragP->fr_offset) - object_address;
3469 switch(fragP->fr_subtype) {
3470 case TAB(BCC68000,BYTE):
3471 case TAB(BRANCH,BYTE):
3472 know(issbyte(disp));
3474 as_bad("short branch with zero offset: use :w");
3475 fragP->fr_opcode[1]=disp;
3478 case TAB(DBCC,SHORT):
3479 know(issword(disp));
3482 case TAB(BCC68000,SHORT):
3483 case TAB(BRANCH,SHORT):
3484 know(issword(disp));
3485 fragP->fr_opcode[1]=0x00;
3488 case TAB(BRANCH,LONG):
3489 if (cpu_of_arch(current_architecture) < m68020) {
3490 if (fragP->fr_opcode[0]==0x61) {
3491 fragP->fr_opcode[0]= 0x4E;
3492 fragP->fr_opcode[1]= 0xB9; /* JBSR with ABSL LONG offset */
3493 subseg_change(SEG_TEXT, 0);
3506 } else if (fragP->fr_opcode[0]==0x60) {
3507 fragP->fr_opcode[0]= 0x4E;
3508 fragP->fr_opcode[1]= 0xF9; /* JMP with ABSL LONG offset */
3509 subseg_change(SEG_TEXT, 0);
3510 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0,
3515 as_bad("Long branch offset not supported.");
3518 fragP->fr_opcode[1]=0xff;
3522 case TAB(BCC68000,LONG):
3523 /* only Bcc 68000 instructions can come here */
3524 /* change bcc into b!cc/jmp absl long */
3525 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
3526 fragP->fr_opcode[1] = 0x6; /* branch offset = 6 */
3528 /* JF: these used to be fr_opcode[2,3], but they may be in a
3529 different frag, in which case refering to them is a no-no.
3530 Only fr_opcode[0,1] are guaranteed to work. */
3531 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
3532 *buffer_address++ = 0xf9;
3533 fragP->fr_fix += 2; /* account for jmp instruction */
3534 subseg_change(SEG_TEXT,0);
3535 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3541 case TAB(DBCC,LONG):
3542 /* only DBcc 68000 instructions can come here */
3543 /* change dbcc into dbcc/jmp absl long */
3544 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3545 *buffer_address++ = 0x00; /* branch offset = 4 */
3546 *buffer_address++ = 0x04;
3547 *buffer_address++ = 0x60; /* put in bra pc+6 */
3548 *buffer_address++ = 0x06;
3549 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
3550 *buffer_address++ = 0xf9;
3552 fragP->fr_fix += 6; /* account for bra/jmp instructions */
3553 subseg_change(SEG_TEXT,0);
3554 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3560 case TAB(FBRANCH,SHORT):
3561 know((fragP->fr_opcode[1]&0x40)==0);
3564 case TAB(FBRANCH,LONG):
3565 fragP->fr_opcode[1]|=0x40; /* Turn on LONG bit */
3568 case TAB(PCREL,SHORT):
3571 case TAB(PCREL,LONG):
3572 /* The thing to do here is force it to ABSOLUTE LONG, since
3573 PCREL is really trying to shorten an ABSOLUTE address anyway */
3574 /* JF FOO This code has not been tested */
3575 subseg_change(SEG_TEXT,0);
3576 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
3577 if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
3578 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3579 fragP->fr_opcode[0],fragP->fr_address);
3580 fragP->fr_opcode[1]&= ~0x3F;
3581 fragP->fr_opcode[1]|=0x39; /* Mode 7.1 */
3583 /* md_number_to_chars(buffer_address,
3584 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3588 case TAB(PCLEA,SHORT):
3589 subseg_change(SEG_TEXT,0);
3590 fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset,1,
3592 fragP->fr_opcode[1] &= ~0x3F;
3593 fragP->fr_opcode[1] |= 0x3A;
3596 case TAB(PCLEA,LONG):
3597 subseg_change(SEG_TEXT,0);
3598 fix_new(fragP,(int)(fragP->fr_fix)+2,4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset+2,1,
3600 *buffer_address++ = 0x01;
3601 *buffer_address++ = 0x70;
3603 /* buffer_address+=2; */
3607 } /* switch on subtype */
3610 md_number_to_chars(buffer_address, (long) disp, (int) ext);
3611 fragP->fr_fix += ext;
3612 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3613 } /* if extending */
3616 } /* md_convert_frag() */
3618 /* Force truly undefined symbols to their maximum size, and generally set up
3619 the frag list to be relaxed
3621 int md_estimate_size_before_relax(fragP, segment)
3622 register fragS *fragP;
3626 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
3628 old_fix = fragP->fr_fix;
3630 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3631 switch(fragP->fr_subtype) {
3633 case TAB(BRANCH,SZ_UNDEF): {
3634 if((fragP->fr_symbol != NULL) /* Not absolute */
3635 && S_GET_SEGMENT(fragP->fr_symbol) == segment) {
3636 fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
3638 } else if((fragP->fr_symbol == 0) || (cpu_of_arch(current_architecture) < m68020)) {
3639 /* On 68000, or for absolute value, switch to abs long */
3640 /* FIXME, we should check abs val, pick short or long */
3641 if(fragP->fr_opcode[0]==0x61) {
3642 fragP->fr_opcode[0]= 0x4E;
3643 fragP->fr_opcode[1]= 0xB9; /* JBSR with ABSL LONG offset */
3644 subseg_change(SEG_TEXT, 0);
3645 fix_new(fragP, fragP->fr_fix, 4,
3646 fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
3649 } else if(fragP->fr_opcode[0]==0x60) {
3650 fragP->fr_opcode[0]= 0x4E;
3651 fragP->fr_opcode[1]= 0xF9; /* JMP with ABSL LONG offset */
3652 subseg_change(SEG_TEXT, 0);
3653 fix_new(fragP, fragP->fr_fix, 4,
3654 fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
3658 as_warn("Long branch offset to extern symbol not supported.");
3660 } else { /* Symbol is still undefined. Make it simple */
3661 fix_new(fragP, (int)(fragP->fr_fix), 4, fragP->fr_symbol,
3662 (symbolS *)0, fragP->fr_offset+4, 1, NO_RELOC);
3664 fragP->fr_opcode[1]=0xff;
3670 } /* case TAB(BRANCH,SZ_UNDEF) */
3672 case TAB(FBRANCH,SZ_UNDEF): {
3673 if(S_GET_SEGMENT(fragP->fr_symbol) == segment || flagseen['l']) {
3674 fragP->fr_subtype = TAB(FBRANCH,SHORT);
3677 fragP->fr_subtype = TAB(FBRANCH,LONG);
3681 } /* TAB(FBRANCH,SZ_UNDEF) */
3683 case TAB(PCREL,SZ_UNDEF): {
3684 if(S_GET_SEGMENT(fragP->fr_symbol) == segment || flagseen['l']) {
3685 fragP->fr_subtype = TAB(PCREL,SHORT);
3688 fragP->fr_subtype = TAB(PCREL,LONG);
3692 } /* TAB(PCREL,SZ_UNDEF) */
3694 case TAB(BCC68000,SZ_UNDEF): {
3695 if((fragP->fr_symbol != NULL)
3696 && S_GET_SEGMENT(fragP->fr_symbol) == segment) {
3697 fragP->fr_subtype=TAB(BCC68000,BYTE);
3700 /* only Bcc 68000 instructions can come here */
3701 /* change bcc into b!cc/jmp absl long */
3702 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
3704 fragP->fr_opcode[1] = 0x04; /* branch offset = 6 */
3705 /* JF: these were fr_opcode[2,3] */
3706 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
3707 buffer_address[1] = 0xf8;
3708 fragP->fr_fix += 2; /* account for jmp instruction */
3709 subseg_change(SEG_TEXT,0);
3710 fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0,
3711 fragP->fr_offset, 0, NO_RELOC);
3714 fragP->fr_opcode[1] = 0x06; /* branch offset = 6 */
3715 /* JF: these were fr_opcode[2,3] */
3716 buffer_address[2] = 0x4e; /* put in jmp long (0x4ef9) */
3717 buffer_address[3] = 0xf9;
3718 fragP->fr_fix += 2; /* account for jmp instruction */
3719 subseg_change(SEG_TEXT,0);
3720 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3721 fragP->fr_offset, 0, NO_RELOC);
3726 } /* case TAB(BCC68000,SZ_UNDEF) */
3728 case TAB(DBCC,SZ_UNDEF): {
3729 if (fragP->fr_symbol != NULL && S_GET_SEGMENT(fragP->fr_symbol) == segment) {
3730 fragP->fr_subtype=TAB(DBCC,SHORT);
3734 /* only DBcc 68000 instructions can come here */
3735 /* change dbcc into dbcc/jmp absl long */
3736 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3737 buffer_address[0] = 0x00; /* branch offset = 4 */
3738 buffer_address[1] = 0x04;
3739 buffer_address[2] = 0x60; /* put in bra pc + ... */
3742 /* JF: these were fr_opcode[5-7] */
3743 buffer_address[3] = 0x04; /* plus 4 */
3744 buffer_address[4] = 0x4e;/* Put in Jump Word */
3745 buffer_address[5] = 0xf8;
3746 fragP->fr_fix += 6; /* account for bra/jmp instruction */
3747 subseg_change(SEG_TEXT,0);
3748 fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0,
3749 fragP->fr_offset, 0, NO_RELOC);
3752 /* JF: these were fr_opcode[5-7] */
3753 buffer_address[3] = 0x06; /* Plus 6 */
3754 buffer_address[4] = 0x4e; /* put in jmp long (0x4ef9) */
3755 buffer_address[5] = 0xf9;
3756 fragP->fr_fix += 6; /* account for bra/jmp instruction */
3757 subseg_change(SEG_TEXT,0);
3758 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3759 fragP->fr_offset, 0, NO_RELOC);
3765 } /* case TAB(DBCC,SZ_UNDEF) */
3767 case TAB(PCLEA,SZ_UNDEF): {
3768 if ((S_GET_SEGMENT(fragP->fr_symbol))==segment || flagseen['l']) {
3769 fragP->fr_subtype=TAB(PCLEA,SHORT);
3772 fragP->fr_subtype=TAB(PCLEA,LONG);
3776 } /* TAB(PCLEA,SZ_UNDEF) */
3781 } /* switch on subtype looking for SZ_UNDEF's. */
3783 /* now that SZ_UNDEF are taken care of, check others */
3784 switch(fragP->fr_subtype) {
3785 case TAB(BCC68000,BYTE):
3786 case TAB(BRANCH,BYTE):
3787 /* We can't do a short jump to the next instruction,
3788 so we force word mode. */
3789 if (fragP->fr_symbol && S_GET_VALUE(fragP->fr_symbol)==0 &&
3790 fragP->fr_symbol->sy_frag==fragP->fr_next) {
3791 fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
3798 return fragP->fr_var + fragP->fr_fix - old_fix;
3801 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3802 /* the bit-field entries in the relocation_info struct plays hell
3803 with the byte-order problems of cross-assembly. So as a hack,
3804 I added this mach. dependent ri twiddler. Ugly, but it gets
3806 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3807 are symbolnum, most sig. byte first. Last byte is broken up with
3808 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3809 nibble as nuthin. (on Sun 3 at least) */
3810 /* Translate the internal relocation information into target-specific
3814 md_ri_to_chars(the_bytes, ri)
3816 struct reloc_info_generic *ri;
3819 md_number_to_chars(the_bytes, ri->r_address, 4);
3820 /* now the fun stuff */
3821 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
3822 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
3823 the_bytes[6] = ri->r_symbolnum & 0x0ff;
3824 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
3825 ((ri->r_extern << 4) & 0x10));
3827 #endif /* comment */
3829 void tc_aout_fix_to_chars(where, fixP, segment_address_in_file)
3832 relax_addressT segment_address_in_file;
3835 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3836 * Out: GNU LD relocation length code: 0, 1, or 2.
3839 static unsigned char nbytes_r_length [] = { 42, 0, 1, 42, 2 };
3845 md_number_to_chars(where,
3846 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
3849 /* now the fun stuff */
3850 if (S_GET_TYPE(fixP->fx_addsy) == N_UNDF) {
3852 r_symbolnum = fixP->fx_addsy->sy_number;
3855 r_symbolnum = S_GET_TYPE(fixP->fx_addsy);
3858 where[4] = (r_symbolnum >> 16) & 0x0ff;
3859 where[5] = (r_symbolnum >> 8) & 0x0ff;
3860 where[6] = r_symbolnum & 0x0ff;
3861 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
3862 ((r_extern << 4) & 0x10));
3865 } /* tc_aout_fix_to_chars() */
3867 #endif /* OBJ_AOUT or OBJ_BOUT */
3869 #ifndef WORKING_DOT_WORD
3870 const int md_short_jump_size = 4;
3871 const int md_long_jump_size = 6;
3874 md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
3883 offset = to_addr - (from_addr+2);
3885 md_number_to_chars(ptr ,(long)0x6000,2);
3886 md_number_to_chars(ptr+2,(long)offset,2);
3890 md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
3899 if (cpu_of_arch(current_architecture) < m68020) {
3900 offset=to_addr-S_GET_VALUE(to_symbol);
3901 md_number_to_chars(ptr ,(long)0x4EF9,2);
3902 md_number_to_chars(ptr+2,(long)offset,4);
3903 fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long)0,0,
3906 offset=to_addr - (from_addr+2);
3907 md_number_to_chars(ptr ,(long)0x60ff,2);
3908 md_number_to_chars(ptr+2,(long)offset,4);
3913 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3916 10: Absolute 1:8 only
3917 20: Absolute 0:7 only
3918 30: absolute 0:15 only
3919 40: Absolute 0:31 only
3920 50: absolute 0:127 only
3921 55: absolute -64:63 only
3922 60: absolute -128:127 only
3923 70: absolute 0:4095 only
3928 static int get_num(exp,ok)
3929 struct m68k_exp *exp;
3937 if(*exp->e_beg=='0') {
3938 if(exp->e_beg[1]=='x')
3939 sscanf(exp->e_beg+2,"%x",&l);
3941 sscanf(exp->e_beg+1,"%O",&l);
3944 return atol(exp->e_beg);
3950 /* Can't do anything */
3953 if(!exp->e_beg || !exp->e_end) {
3954 seg(exp)=SEG_ABSOLUTE;
3957 offs(exp)= (ok==10) ? 1 : 0;
3958 as_warn("Null expression defaults to %ld",offs(exp));
3963 if(/* ok!=80 && */exp->e_end[-1]==SIZER && (exp->e_end-exp->e_beg)>=2) {
3964 switch(exp->e_end[0]) {
3980 as_bad("Unknown size for expression \"%c\"",exp->e_end[0]);
3984 c_save=exp->e_end[1];
3986 save_in=input_line_pointer;
3987 input_line_pointer=exp->e_beg;
3988 switch(expression(&(exp->e_exp))) {
3990 seg(exp)=SEG_ABSOLUTE;
3993 offs(exp)= (ok==10) ? 1 : 0;
3994 as_warn("Unknown expression: '%s' defaulting to %d",exp->e_beg,offs(exp));
3998 /* Do the same thing the VAX asm does */
3999 seg(exp)=SEG_ABSOLUTE;
4004 as_warn("expression out of range: defaulting to 1");
4011 if(offs(exp)<1 || offs(exp)>8) {
4012 as_warn("expression out of range: defaulting to 1");
4017 if(offs(exp)<0 || offs(exp)>7)
4021 if(offs(exp)<0 || offs(exp)>15)
4025 if(offs(exp)<0 || offs(exp)>32)
4029 if(offs(exp)<0 || offs(exp)>127)
4033 if(offs(exp)<-64 || offs(exp)>63)
4037 if(offs(exp)<-128 || offs(exp)>127)
4041 if(offs(exp)<0 || offs(exp)>4095) {
4043 as_warn("expression out of range: defaulting to 0");
4055 case SEG_DIFFERENCE:
4056 if(ok>=10 && ok<=70) {
4057 seg(exp)=SEG_ABSOLUTE;
4060 offs(exp)= (ok==10) ? 1 : 0;
4061 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
4065 if(ok==80 && offs(exp)<0) { /* HACK! Turn it into a long */
4066 LITTLENUM_TYPE words[6];
4068 gen_to_words(words,2,8L);/* These numbers are magic! */
4069 seg(exp)=SEG_ABSOLUTE;
4072 offs(exp)=words[1]|(words[0]<<16);
4074 seg(exp)=SEG_ABSOLUTE;
4077 offs(exp)= (ok==10) ? 1 : 0;
4078 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
4082 as_fatal("failed sanity check.");
4084 if(input_line_pointer!=exp->e_end+1)
4085 as_bad("Ignoring junk after expression");
4086 exp->e_end[1]=c_save;
4087 input_line_pointer=save_in;
4089 switch(exp->e_siz) {
4091 if(!isbyte(offs(exp)))
4092 as_warn("expression doesn't fit in BYTE");
4095 if(!isword(offs(exp)))
4096 as_warn("expression doesn't fit in WORD");
4104 /* These are the back-ends for the various machine dependent pseudo-ops. */
4105 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
4107 static void s_data1() {
4108 subseg_new(SEG_DATA,1);
4109 demand_empty_rest_of_line();
4112 static void s_data2() {
4113 subseg_new(SEG_DATA,2);
4114 demand_empty_rest_of_line();
4117 static void s_bss() {
4118 /* We don't support putting frags in the BSS segment, but we
4119 can put them into initialized data for now... */
4120 subseg_new(SEG_DATA,255); /* FIXME-SOON */
4121 demand_empty_rest_of_line();
4124 static void s_even() {
4126 register long temp_fill;
4128 temp = 1; /* JF should be 2? */
4129 temp_fill = get_absolute_expression ();
4130 if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
4131 frag_align (temp, (int)temp_fill);
4132 demand_empty_rest_of_line();
4135 static void s_proc() {
4136 demand_empty_rest_of_line();
4139 /* s_space is defined in read.c .skip is simply an alias to it. */
4143 * Invocation line includes a switch not recognized by the base assembler.
4144 * See if it's a processor-specific option. These are:
4146 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4147 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4148 * Select the architecture. Instructions or features not
4149 * supported by the selected architecture cause fatal
4150 * errors. More than one may be specified. The default is
4151 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4152 * for -m68000, and -m68882 is a synonym for -m68881.
4154 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
4155 * (e.g. m68020) also requests that float instructions be included. This
4156 * is the default setup, mostly to avoid hassling users. A better
4157 * rearrangement of this structure would be to add an option to DENY
4158 * floating point opcodes, for people who want to really know there's none
4159 * of that funny floaty stuff going on. FIXME-later.
4161 #ifndef MAYBE_FLOAT_TOO
4162 #define MAYBE_FLOAT_TOO m68881
4165 int md_parse_option(argP,cntP,vecP)
4171 case 'l': /* -l means keep external to 2 bit offset
4172 rather than 16 bit one */
4175 case 'S': /* -S means that jbsr's always turn into jsr's. */
4180 /* intentional fall-through */
4186 } /* allow an optional "c" */
4188 if (!strcmp(*argP, "68000")
4189 || !strcmp(*argP, "68008")) {
4190 current_architecture |= m68000;
4191 } else if (!strcmp(*argP, "68010")) {
4193 omagic= 1<<16|OMAGIC;
4195 current_architecture |= m68010;
4197 } else if (!strcmp(*argP, "68020")) {
4198 current_architecture |= m68020 | MAYBE_FLOAT_TOO;
4200 } else if (!strcmp(*argP, "68030")) {
4201 current_architecture |= m68030 | MAYBE_FLOAT_TOO;
4203 } else if (!strcmp(*argP, "68040")) {
4204 current_architecture |= m68040 | MAYBE_FLOAT_TOO;
4207 } else if (!strcmp(*argP, "68881")) {
4208 current_architecture |= m68881;
4210 } else if (!strcmp(*argP, "68882")) {
4211 current_architecture |= m68882;
4213 #endif /* NO_68881 */
4215 } else if (!strcmp(*argP,"68851")) {
4216 current_architecture |= m68851;
4218 #endif /* NO_68851 */
4220 as_warn("Unknown architecture, \"%s\". option ignored", *argP);
4221 } /* switch on architecture */
4223 while(**argP) (*argP)++;
4228 if (!strcmp(*argP,"pic")) {
4230 break; /* -pic, Position Independent Code */
4244 /* TEST2: Test md_assemble() */
4245 /* Warning, this routine probably doesn't work anymore */
4249 struct m68k_it the_ins;
4256 if(!gets(buf) || !*buf)
4258 if(buf[0]=='|' || buf[1]=='.')
4260 for(cp=buf;*cp;cp++)
4265 bzero(&the_ins,sizeof(the_ins));
4266 m68k_ip(&the_ins,buf);
4268 printf("Error %s in %s\n",the_ins.error,buf);
4270 printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
4271 for(n=0;n<the_ins.numo;n++)
4272 printf(" 0x%x",the_ins.opcode[n]&0xffff);
4274 print_the_insn(&the_ins.opcode[0],stdout);
4275 (void)putchar('\n');
4277 for(n=0;n<strlen(the_ins.args)/2;n++) {
4278 if(the_ins.operands[n].error) {
4279 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
4282 printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
4283 if(the_ins.operands[n].b_const)
4284 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
4285 printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
4286 if(the_ins.operands[n].b_iadd)
4287 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
4288 (void)putchar('\n');
4298 while(ISSPACE(*str))
4300 while(*str && !ISSPACE(*str))
4302 if(str[-1]==':' || str[1]=='=')
4309 /* Possible states for relaxation:
4311 0 0 branch offset byte (bra, etc)
4315 1 0 indexed offsets byte a0@(32,d4:w:1) etc
4319 2 0 two-offset index word-word a0@(32,d4)@(45) etc
4355 extern fragS *text_frag_root;
4357 for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
4358 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
4359 fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
4360 printf("opcode 0x%x type %d subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
4372 fputs("Internal error:",stderr);
4373 _doprnt(format,&args,stderr);
4374 (void)putc('\n',stderr);
4380 /* We have no need to default values of symbols. */
4384 md_undefined_symbol (name)
4390 /* Parse an operand that is machine-specific.
4391 We just return without modifying the expression if we have nothing
4396 md_operand (expressionP)
4397 expressionS *expressionP;
4401 /* Round up a section size to the appropriate boundary. */
4403 md_section_align (segment, size)
4407 return size; /* Byte alignment is fine */
4410 /* Exactly what point is a PC-relative offset relative TO?
4411 On the 68k, they're relative to the address of the offset, plus
4412 its size. (??? Is this right? FIXME-SOON!) */
4414 md_pcrel_from (fixP)
4417 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
4423 unsigned int fill = get_absolute_expression() * size;
4424 char *p = frag_var (rs_fill, fill, fill, (relax_substateT)0, (symbolS *)0,
4427 demand_empty_rest_of_line();
4440 int repeat = get_absolute_expression();
4443 if (*input_line_pointer == ',')
4446 input_line_pointer++;
4448 fill = get_absolute_expression();
4449 p = frag_var(rs_fill,
4456 md_number_to_chars(p, fill, size);
4458 demand_empty_rest_of_line();
4465 unsigned int target = get_absolute_expression();
4466 #define MACHINE_MASK (m68000 | m68008 | m68010 | m68020 | m68040)
4471 current_architecture = (current_architecture & ~ MACHINE_MASK) | m68000;
4474 current_architecture = (current_architecture & ~ MACHINE_MASK) | m68010;
4477 current_architecture = (current_architecture & ~ MACHINE_MASK) | m68020;
4480 current_architecture = (current_architecture & ~ MACHINE_MASK) | m68030;
4483 current_architecture = (current_architecture & ~ MACHINE_MASK) | m68040;
4486 current_architecture |= m68881;
4489 current_architecture |= m68882;
4492 current_architecture |= m68851;
4496 as_bad("Unrecognised CHIP %d\n", target);
4499 demand_empty_rest_of_line();
4511 /* end of tc-m68kmote.c */