1 /* m68k.c All the m68020 specific stuff in one convenient, huge,
2 slow to compile, easy to find file.
3 Copyright (C) 1987, 1991 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. */
27 /* note that this file includes real declarations and thus can only be included by one source file per executable. */
28 #include "opcode/m68k.h"
30 /* This variable contains the value to write out at the beginning of
31 the a.out file. The 2<<16 means that this is a 68020 file instead
32 of an old-style 68000 file */
34 long omagic = 2<<16|OMAGIC; /* Magic byte for header file */
39 /* This array holds the chars that always start a comment. If the
40 pre-processor is disabled, these aren't very useful */
41 const char comment_chars[] = "|";
43 /* This array holds the chars that only start a comment at the beginning of
44 a line. If the line seems to have the form '# 123 filename'
45 .line and .file directives will appear in the pre-processed output */
46 /* Note that input_file.c hand checks for '#' at the beginning of the
47 first line of the input file. This is because the compiler outputs
48 #NO_APP at the beginning of its output. */
49 /* Also note that comments like this one will always work. */
50 const char line_comment_chars[] = "#";
52 /* Chars that can be used to separate mant from exp in floating point nums */
53 const char EXP_CHARS[] = "eE";
55 /* Chars that mean this number is a floating point constant */
59 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
61 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
62 changed in read.c . Ideally it shouldn't have to know about it at all,
63 but nothing is ideal around here.
66 int md_reloc_size = 8; /* Size of relocation record */
68 /* Its an arbitrary name: This means I don't approve of it */
69 /* See flames below */
70 static struct obstack robyn;
72 #define TAB(x,y) (((x)<<2)+(y))
73 #define TABTYPE(xy) ((xy) >> 2)
86 /* Operands we can parse: (And associated modes)
92 reg: address or data register
93 areg: address register
94 apc: address register, PC, ZPC or empty string
97 sz: w or l if omitted, l assumed
98 scale: 1 2 4 or 8 if omitted, 1 assumed
100 7.4 IMMED #num --> NUM
101 0.? DREG dreg --> dreg
102 1.? AREG areg --> areg
103 2.? AINDR areg@ --> *(areg)
104 3.? AINC areg@+ --> *(areg++)
105 4.? ADEC areg@- --> *(--areg)
106 5.? AOFF apc@(numw) --> *(apc+numw) -- empty string and ZPC not allowed here
107 6.? AINDX apc@(num,reg:sz:scale) --> *(apc+num+reg*scale)
108 6.? AINDX apc@(reg:sz:scale) --> same, with num=0
109 6.? APODX apc@(num)@(num2,reg:sz:scale) --> *(*(apc+num)+num2+reg*scale)
110 6.? APODX apc@(num)@(reg:sz:scale) --> same, with num2=0
111 6.? AMIND apc@(num)@(num2) --> *(*(apc+num)+num2) (previous mode without an index reg)
112 6.? APRDX apc@(num,reg:sz:scale)@(num2) --> *(*(apc+num+reg*scale)+num2)
113 6.? APRDX apc@(reg:sz:scale)@(num2) --> same, with num=0
114 7.0 ABSL num:sz --> *(num)
115 num --> *(num) (sz L assumed)
116 *** MSCR otherreg --> Magic
118 5.? AOFF apc@(num) --> *(apc+num) -- empty string and ZPC not allowed here still
128 a1@(5,d2:w:1) @(45,d6:l:4)
133 #name@(numw) -->turn into PC rel mode
134 apc@(num8,reg:sz:scale) --> *(apc+num8+reg*scale)
160 short e_siz; /* 0== default 1==short/byte 2==word 3==long */
163 /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
164 8-15==addr reg for operands that take both types */
167 DATA = 1, /* 1- 8 == data registers 0-7 */
187 /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
192 FPREG, /* Eight FP registers */
201 COPNUM = (FPREG+8), /* Co-processor #1-#8 */
210 PC, /* Program counter */
211 ZPC, /* Hack for Program space, but 0 addressing */
213 CCR, /* Condition code Reg */
215 /* These have to be in order for the movec instruction to work. */
216 USP, /* User Stack Pointer */
217 ISP, /* Interrupt stack pointer */
232 /* end of movec ordering constraints */
265 IC, /* instruction cache token */
266 DC, /* data cache token */
267 NC, /* no cache token */
268 BC, /* both caches token */
272 /* Internal form of an operand. */
274 char *error; /* Couldn't parse it */
275 enum operand_type mode; /* What mode this instruction is in. */
276 enum _register reg; /* Base register */
277 struct m68k_exp *con1;
278 int ireg; /* Index register */
279 int isiz; /* 0==unspec 1==byte(?) 2==short 3==long */
280 int imul; /* Multipy ireg by this (1,2,4,or 8) */
281 struct m68k_exp *con2;
284 /* internal form of a 68020 instruction */
287 char *args; /* list of opcode info */
290 int numo; /* Number of shorts in opcode */
293 struct m68k_op operands[6];
295 int nexp; /* number of exprs in use */
296 struct m68k_exp exprs[4];
298 int nfrag; /* Number of frags we have to produce */
300 int fragoff; /* Where in the current opcode[] the frag ends */
306 int nrel; /* Num of reloc strucs in use */
314 } reloc[5]; /* Five is enough??? */
317 #define cpu_of_arch(x) ((x) & m68000up)
318 #define float_of_arch(x) ((x) & mfloat)
319 #define mmu_of_arch(x) ((x) & mmmu)
321 static struct m68k_it the_ins; /* the instruction being assembled */
323 /* Macros for adding things to the m68k_it struct */
325 #define addword(w) the_ins.opcode[the_ins.numo++]=(w)
327 /* Like addword, but goes BEFORE general operands */
328 #define insop(w) {int z;\
329 for(z=the_ins.numo;z>opcode->m_codenum;--z)\
330 the_ins.opcode[z]=the_ins.opcode[z-1];\
331 for(z=0;z<the_ins.nrel;z++)\
332 the_ins.reloc[z].n+=2;\
333 the_ins.opcode[opcode->m_codenum]=w;\
338 #define add_exp(beg,end) (\
339 the_ins.exprs[the_ins.nexp].e_beg=beg,\
340 the_ins.exprs[the_ins.nexp].e_end=end,\
341 &the_ins.exprs[the_ins.nexp++]\
345 /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
346 #define add_fix(width,exp,pc_rel) {\
347 the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
348 (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
349 the_ins.reloc[the_ins.nrel].add=adds((exp));\
350 the_ins.reloc[the_ins.nrel].sub=subs((exp));\
351 the_ins.reloc[the_ins.nrel].off=offs((exp));\
352 the_ins.reloc[the_ins.nrel].wid=width;\
353 the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
356 #define add_frag(add,off,type) {\
357 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
358 the_ins.fragb[the_ins.nfrag].fadd=add;\
359 the_ins.fragb[the_ins.nfrag].foff=off;\
360 the_ins.fragb[the_ins.nfrag++].fragty=type;\
363 #define isvar(exp) ((exp) && (adds(exp) || subs(exp)))
365 #define seg(exp) ((exp)->e_exp.X_seg)
366 #define adds(exp) ((exp)->e_exp.X_add_symbol)
367 #define subs(exp) ((exp)->e_exp.X_subtract_symbol)
368 #define offs(exp) ((exp)->e_exp.X_add_number)
373 unsigned long m_opcode;
376 enum m68k_architecture m_arch;
377 struct m68k_incant *m_next;
380 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
381 #define gettwo(x) (((x)->m_opcode)&0xffff)
386 static char *crack_operand(char *str, struct m68k_op *opP);
387 static int get_num(struct m68k_exp *exp, int ok);
388 static int get_regs(int i, char *str, struct m68k_op *opP);
389 static int reverse_16_bits(int in);
390 static int reverse_8_bits(int in);
391 static int try_index(char **s, struct m68k_op *opP);
392 static void install_gen_operand(int mode, int val);
393 static void install_operand(int mode, int val);
394 static void s_bss(void);
395 static void s_data1(void);
396 static void s_data2(void);
397 static void s_even(void);
398 static void s_proc(void);
402 static char *crack_operand();
403 static int get_num();
404 static int get_regs();
405 static int reverse_16_bits();
406 static int reverse_8_bits();
407 static int try_index();
408 static void install_gen_operand();
409 static void install_operand();
411 static void s_data1();
412 static void s_data2();
413 static void s_even();
414 static void s_proc();
416 #endif /* __STDC__ */
418 static enum m68k_architecture current_architecture = 0;
420 /* BCC68000 is for patching in an extra jmp instruction for long offsets
421 on the 68000. The 68000 doesn't support long branches with branchs */
423 /* This table desribes how you change sizes for the various types of variable
424 size expressions. This version only supports two kinds. */
426 /* Note that calls to frag_var need to specify the maximum expansion needed */
427 /* This is currently 10 bytes for DBCC */
430 How far Forward this mode will reach:
431 How far Backward this mode will reach:
432 How many bytes this mode will add to the size of the frag
433 Which mode to go to if the offset won't fit in this one
437 { 1, 1, 0, 0 }, /* First entries aren't used */
438 { 1, 1, 0, 0 }, /* For no good reason except */
439 { 1, 1, 0, 0 }, /* that the VAX doesn't either */
442 { (127), (-128), 0, TAB(BRANCH,SHORT)},
443 { (32767), (-32768), 2, TAB(BRANCH,LONG) },
447 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE */
448 { (32767), (-32768), 2, TAB(FBRANCH,LONG)},
452 { 1, 1, 0, 0 }, /* PCREL doesn't come BYTE */
453 { (32767), (-32768), 2, TAB(PCREL,LONG)},
457 { (127), (-128), 0, TAB(BCC68000,SHORT)},
458 { (32767), (-32768), 2, TAB(BCC68000,LONG) },
459 { 0, 0, 6, 0 }, /* jmp long space */
462 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE */
463 { (32767), (-32768), 2, TAB(DBCC,LONG) },
464 { 0, 0, 10, 0 }, /* bra/jmp long space */
467 { 1, 1, 0, 0 }, /* PCLEA doesn't come BYTE */
468 { 32767, -32768, 2, TAB(PCLEA,LONG) },
474 /* These are the machine dependent pseudo-ops. These are included so
475 the assembler can work on the output from the SUN C compiler, which
479 /* This table describes all the machine specific pseudo-ops the assembler
480 has to support. The fields are:
481 pseudo-op name without dot
482 function to call to execute this pseudo-op
483 Integer arg to pass to the function
485 const pseudo_typeS md_pseudo_table[] = {
486 { "data1", s_data1, 0 },
487 { "data2", s_data2, 0 },
489 { "even", s_even, 0 },
490 { "skip", s_space, 0 },
491 { "proc", s_proc, 0 },
496 /* #define isbyte(x) ((x)>=-128 && (x)<=127) */
497 /* #define isword(x) ((x)>=-32768 && (x)<=32767) */
499 #define issbyte(x) ((x)>=-128 && (x)<=127)
500 #define isubyte(x) ((x)>=0 && (x)<=255)
501 #define issword(x) ((x)>=-32768 && (x)<=32767)
502 #define isuword(x) ((x)>=0 && (x)<=65535)
504 #define isbyte(x) ((x)>=-128 && (x)<=255)
505 #define isword(x) ((x)>=-32768 && (x)<=65535)
506 #define islong(x) (1)
508 extern char *input_line_pointer;
515 /* JF these tables here are for speed at the expense of size */
516 /* You can replace them with the #if 0 versions if you really
517 need space and don't mind it running a bit slower */
519 static char mklower_table[256];
520 #define mklower(c) (mklower_table[(unsigned char)(c)])
521 static char notend_table[256];
522 static char alt_notend_table[256];
523 #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
524 alt_notend_table[(unsigned char)(s[1])])))
527 #define mklower(c) (isupper(c) ? tolower(c) : c)
531 /* JF modified this to handle cases where the first part of a symbol name
532 looks like a register */
535 * m68k_reg_parse() := if it looks like a register, return it's token &
536 * advance the pointer.
539 enum _register m68k_reg_parse(ccp)
542 #ifndef MAX_REG_NAME_LEN
543 #define MAX_REG_NAME_LEN (6)
544 #endif /* MAX_REG_NAME_LEN */
545 register char c[MAX_REG_NAME_LEN];
550 c[0] = mklower(ccp[0][0]);
551 #ifdef REGISTER_PREFIX
552 if (c[0] != REGISTER_PREFIX) {
557 for (p = c, q = ccp[0]; p < c + MAX_REG_NAME_LEN; ++p, ++q)
570 if(c[1]>='0' && c[1]<='7') {
575 else if (c[1] == 'c') {
585 if (c[3] >= '0' && c[3] <= '7') {
587 ret = BAD + c[3] - '0';
591 if (c[3] >= '0' && c[3] <= '7') {
593 ret = BAC + c[3] - '0';
596 } else if (c[1] == 'c') {
604 if (c[1] == 'a' && c[2] == 'l') {
609 /* This supports both CCR and CC as the ccr reg. */
610 if(c[1]=='c' && c[2]=='r') {
613 } else if(c[1]=='c') {
616 } else if(c[1]=='a' && (c[2]=='a' || c[2]=='c') && c[3]=='r') {
618 ret = c[2]=='a' ? CAAR : CACR;
621 else if (c[1] == 'r' && c[2] == 'p') {
628 if (c[1] >= '0' && c[1] <= '7') {
630 ret = DATA + c[1] - '0';
631 } else if (c[1] == 'f' && c[2] == 'c') {
634 } else if (c[1] == 'c') {
637 } else if (c[1] == 't' && c[2] == 't') {
638 if ('0' <= c[3] && c[3] <= '1') {
640 ret = DTT0 + (c[3] - '0');
644 else if (c[1] == 'r' && c[2] == 'p') {
652 if(c[2]>='0' && c[2]<='7') {
654 ret = FPREG+c[2]-'0';
657 } else if(c[2]=='i') {
660 } else if(c[2]=='s') {
661 n= (c[3] == 'r' ? 4 : 3);
663 } else if(c[2]=='c') {
664 n= (c[3] == 'r' ? 4 : 3);
670 if (c[1] == 's' && c[2] == 'p') {
673 } else if (c[1] == 'c') {
676 } else if (c[1] == 't' && c[2] == 't') {
677 if ('0' <= c[3] && c[3] <= '1') {
679 ret = ITT0 + (c[3] - '0');
684 if (c[1] == 's' && c[2] == 'p') {
687 } else if (c[1] == 'm' && c[2] == 'u' && c[3] == 's' && c[4] == 'r') {
701 if(c[2] == 's' && c[3]=='r') {
712 else if (c[1] == 's' && c[2] == 'r') {
720 if (c[1] == 'c' && c[2] == 'c') {
733 } else if (c[1] == 'p') {
736 } else if (c[1] == 'f' && c[2] == 'c') {
748 if (c[1] == 's' && c[2] == 'p') {
751 } else if (c[1] == 'r' && c[2] == 'p') {
758 if (c[1] == 'a' && c[2] == 'l') {
763 if(c[1]=='b' && c[2]=='r') {
769 if(c[1]=='p' && c[2]=='c') {
778 #ifdef REGISTER_PREFIX
781 if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
790 #define SKIP_WHITE() { str++; if(*str==' ') str++;}
793 * m68k_ip_op := '#' + <anything>
794 * | <register> + range_sep + get_regs
797 * range_sep := '/' | '-' ;
799 * SKIP_WHITE := <empty> | ' ' ;
806 register struct m68k_op *opP;
814 } /* Find the beginning of the string */
817 opP->error="Missing operand";
821 for(strend = str; *strend; strend++) ;;
827 opP->con1=add_exp(str,strend);
830 } /* Guess what: A constant. Shar and enjoy */
832 i = m68k_reg_parse(&str);
834 /* is a register, is exactly a register, and is followed by '@' */
836 if((i==FAIL || *str!='\0') && *str!='@') {
839 if(i!=FAIL && (*str=='/' || *str=='-')) {
841 return(get_regs(i,str,opP));
843 if ((stmp=strchr(str,'@')) != '\0') {
844 opP->con1=add_exp(str,stmp-1);
850 if ((current_architecture & m68020up) == 0) {
852 } /* if target is not a '20 or better */
855 if(*stmp++!='(' || *strend--!=')') {
856 opP->error="Malformed operand";
859 i=try_index(&stmp,opP);
860 opP->con2=add_exp(stmp,strend);
868 } /* if there's an '@' */
870 opP->con1 = add_exp(str,strend);
872 } /* not a register, not exactly a register, or no '@' */
877 if(i>=DATA+0 && i<=DATA+7)
879 else if(i>=ADDR+0 && i<=ADDR+7)
886 if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) { /* Can't indirect off non address regs */
887 opP->error="Invalid indirect register";
907 opP->error="Junk after indirect";
910 /* Some kind of indexing involved. Lets find out how bad it is */
911 i=try_index(&str,opP);
912 /* Didn't start with an index reg, maybe its offset or offset,reg */
920 opP->error="Missing )";
922 case ',': i=0; break;
923 case '(': i++; break;
924 case ')': --i; break;
927 /* if(str[-3]==':') {
944 opP->error="Specified size isn't :w or :l";
947 opP->con1=add_exp(beg_str,str-4);
948 opP->con1->e_siz=siz;
950 opP->con1=add_exp(beg_str,str-2);
951 /* Should be offset,reg */
953 i=try_index(&str,opP);
955 opP->error="Malformed index reg";
960 /* We've now got offset) offset,reg) or reg) */
963 /* Th-the-thats all folks */
964 if (opP->reg == FAIL) opP->mode = AINDX; /* Other form of indirect */
965 else if(opP->ireg == FAIL) opP->mode = AOFF;
966 else opP->mode = AINDX;
969 /* Next thing had better be another @ */
970 if(*str!='@' || str[1]!='(') {
971 opP->error = "junk after indirect";
975 if ((current_architecture & m68020up) == 0) {
977 } /* if target is not a '20 or better */
981 if(opP->ireg != FAIL) {
984 i = try_index(&str, opP);
986 opP->error = "Two index registers! not allowed!";
990 i = try_index(&str, opP);
1001 opP->error="Missing )";
1003 case ',': i=0; break;
1004 case '(': i++; break;
1005 case ')': --i; break;
1009 opP->con2=add_exp(beg_str,str-2);
1011 if (str[-1] == ',') {
1012 if (opP->ireg != FAIL) {
1013 opP->error = "Can't have two index regs";
1017 i = try_index(&str, opP);
1020 opP->error = "malformed index reg";
1025 } else if (opP->ireg != FAIL) {
1035 opP->error="Junk after indirect";
1039 } /* m68k_ip_op() */
1043 * try_index := data_or_address_register + ')' + SKIP_W
1044 * | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
1046 * multiplier := <empty>
1047 * | ':' + multiplier_number
1050 * multiplier_number := '1' | '2' | '4' | '8' ;
1052 * size_spec := 'l' | 'L' | 'w' | 'W' ;
1054 * SKIP_W := <empty> | ' ' ;
1058 static int try_index(s,opP)
1060 struct m68k_op *opP;
1064 #define SKIP_W() { ss++; if (*ss==' ') ss++;}
1068 i=m68k_reg_parse(&ss);
1069 if(!(i>=DATA+0 && i<=ADDR+7)) { /* if i is not DATA or ADDR reg */
1083 opP->error="Missing : in index register";
1098 opP->error="Index register size spec not :w or :l";
1113 opP->error="index multiplier not 1, 2, 4 or 8";
1120 opP->error="Missing )";
1129 #ifdef TEST1 /* TEST1 tests m68k_ip_op(), which parses operands */
1133 struct m68k_op thark;
1138 bzero(&thark,sizeof(thark));
1139 if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
1141 printf("op1 error %s in %s\n",thark.error,buf);
1142 printf("mode %d, reg %d, ",thark.mode,thark.reg);
1144 printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
1145 printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
1147 printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
1156 static struct hash_control* op_hash = NULL; /* handle of the OPCODE hash table
1157 NULL means any use before m68k_ip_begin()
1164 * This converts a string into a 68k instruction.
1165 * The string must be a bare single instruction in sun format
1166 * with RMS-style 68020 indirects
1169 * It provides some error messages: at most one fatal error message (which
1170 * stops the scan) and at most one warning message for each operand.
1171 * The 68k instruction is returned in exploded form, since we have no
1172 * knowledge of how you parse (or evaluate) your expressions.
1173 * We do however strip off and decode addressing modes and operation
1176 * This function's value is a string. If it is not "" then an internal
1177 * logic error was found: read this code to assign meaning to the string.
1178 * No argument string should generate such an error string:
1179 * it means a bug in our code, not in the user's text.
1181 * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
1185 /* JF this function no longer returns a useful value. Sorry */
1186 void m68k_ip (instring)
1190 register struct m68k_op *opP;
1191 register struct m68k_incant *opcode;
1193 register int tmpreg = 0,
1202 char *crack_operand();
1203 LITTLENUM_TYPE words[6];
1204 LITTLENUM_TYPE *wordp;
1206 if (*instring == ' ')
1207 instring++; /* skip leading whitespace */
1209 /* Scan up to end of operation-code, which MUST end in end-of-string
1210 or exactly 1 space. */
1211 for (p = instring; *p != '\0'; p++)
1216 if (p == instring) {
1217 the_ins.error = "No operator";
1218 the_ins.opcode[0] = NULL;
1219 /* the_ins.numo=1; */
1223 /* p now points to the end of the opcode name, probably whitespace.
1224 make sure the name is null terminated by clobbering the whitespace,
1225 look it up in the hash table, then fix it back. */
1228 opcode = (struct m68k_incant *)hash_find (op_hash, instring);
1231 if (opcode == NULL) {
1232 the_ins.error = "Unknown operator";
1233 the_ins.opcode[0] = NULL;
1234 /* the_ins.numo=1; */
1238 /* found a legitimate opcode, start matching operands */
1239 while (*p == ' ') ++p;
1241 for(opP = &the_ins.operands[0]; *p; opP++) {
1243 p = crack_operand(p, opP);
1246 the_ins.error=opP->error;
1251 opsfound = opP - &the_ins.operands[0];
1253 /* This ugly hack is to support the floating pt opcodes in their standard form */
1254 /* Essentially, we fake a first enty of type COP#1 */
1255 if (opcode->m_operands[0]=='I') {
1258 for(n=opsfound;n>0;--n)
1259 the_ins.operands[n]=the_ins.operands[n-1];
1261 /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
1262 bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
1263 the_ins.operands[0].mode=MSCR;
1264 the_ins.operands[0].reg=COPNUM; /* COP #1 */
1268 /* We've got the operands. Find an opcode that'll accept them */
1269 for (losing = 0; ; ) {
1270 /* if we didn't get the right number of ops,
1271 or we have no common model with this pattern
1272 then reject this pattern. */
1274 if (opsfound != opcode->m_opnum
1275 || ((opcode->m_arch & current_architecture) == 0)) {
1280 for (s=opcode->m_operands, opP = &the_ins.operands[0]; *s && !losing; s += 2, opP++) {
1281 /* Warning: this switch is huge! */
1282 /* I've tried to organize the cases into this order:
1283 non-alpha first, then alpha by letter. lower-case goes directly
1284 before uppercase counterpart. */
1285 /* Code with multiple case ...: gets sorted by the lowest case ...
1286 it belongs to. I hope this makes sense. */
1289 if (opP->mode == MSCR || opP->mode == IMMED
1290 || opP->mode == DREG || opP->mode == AREG
1291 || opP->mode == AINC || opP->mode == ADEC
1292 || opP->mode == REGLST)
1297 if(opP->mode!=IMMED)
1302 t=get_num(opP->con1,80);
1303 if(s[1]=='b' && !isbyte(t))
1305 else if(s[1]=='w' && !isword(t))
1312 if(opP->mode!=IMMED)
1317 if(opP->mode==MSCR || opP->mode==AREG ||
1318 opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
1323 if(opP->mode==MSCR || opP->reg==PC ||
1324 opP->reg==ZPC || opP->mode==REGLST)
1330 if(opP->mode==MSCR || opP->mode==DREG ||
1331 opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
1332 opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
1337 if(opP->mode==MSCR || opP->mode==REGLST)
1352 if(opP->mode==MSCR || opP->mode==AREG ||
1353 opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
1358 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
1363 if(opP->mode==MSCR || opP->mode==AREG ||
1364 opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
1365 opP->reg==ZPC || opP->mode==REGLST)
1370 if(opP->mode==MSCR || opP->mode==AREG ||
1371 opP->mode==IMMED || opP->mode==REGLST)
1375 case '~': /* For now! (JF FOO is this right?) */
1376 if(opP->mode==MSCR || opP->mode==DREG ||
1377 opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
1386 if (opP->mode != AINDR) {
1388 } /* if not address register indirect */
1391 if(opP->mode!=ABSL || (flagseen['S'] && instring[0] == 'j'
1392 && instring[1] == 'b'
1393 && instring[2] == 's'
1394 && instring[3] == 'r'))
1399 if(opP->mode!=MSCR || opP->reg!=CCR)
1403 case 'd': /* FOO This mode is a KLUDGE!! */
1404 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
1405 opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
1415 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
1420 if(opP->mode!=MSCR || opP->reg<COPNUM ||
1426 if (opP->mode != MSCR
1429 || cpu_of_arch(current_architecture) < m68010 /* before 68010 had none */
1430 || (cpu_of_arch(current_architecture) < m68020
1434 && opP->reg != VBR) /* 68010's had only these */
1435 || (cpu_of_arch(current_architecture) < m68040
1443 && opP->reg != ISP) /* 680[23]0's have only these */
1444 || (cpu_of_arch(current_architecture) == m68040 /* 68040 has all but this */
1445 && opP->reg == CAAR)) {
1447 } /* doesn't cut it */
1451 if(opP->mode!=IMMED)
1457 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
1462 opP->reg=1<<(opP->reg-DATA);
1464 } else if(opP->mode!=REGLST) {
1466 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
1468 else if(s[1]=='3' && opP->reg&0x7000000)
1473 if(opP->mode!=IMMED)
1478 t=get_num(opP->con1,80);
1479 if(!issbyte(t) || isvar(opP->con1))
1485 if(opP->mode!=DREG && opP->mode!=IMMED)
1490 if(opP->mode!=IMMED)
1495 t=get_num(opP->con1,80);
1496 if(t<1 || t>8 || isvar(opP->con1))
1502 if(opP->mode!=DREG && opP->mode!=AREG)
1507 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
1512 if(opP->mode!=MSCR || opP->reg!=SR)
1517 if(opP->mode!=MSCR || opP->reg!=USP)
1521 /* JF these are out of order. We could put them
1522 in order if we were willing to put up with
1523 bunches of #ifdef m68851s in the code */
1525 /* Memory addressing mode used by pflushr */
1527 if(opP->mode==MSCR || opP->mode==DREG ||
1528 opP->mode==AREG || opP->mode==REGLST)
1533 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
1538 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
1539 opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
1544 if (opP->reg != VAL)
1549 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
1555 if (opP->mode != MSCR ||
1556 (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
1557 !(opP->reg >= BAC && opP->reg <= BAC+7)))
1562 if (opP->reg != PSR)
1567 if (opP->reg != PCSR)
1575 && opP->reg != BC) {
1577 } /* not a cache specifier. */
1581 if (opP->mode != ABSL) {
1583 } /* not absolute */
1587 as_fatal("Internal error: Operand mode %c unknown in line %s of file \"%s\"",
1588 *s, __LINE__, __FILE__);
1589 } /* switch on type of operand */
1592 } /* for each operand */
1593 } /* if immediately wrong */
1599 opcode = opcode->m_next;
1602 the_ins.error = "instruction/operands mismatch";
1604 } /* Fell off the end */
1609 /* now assemble it */
1611 the_ins.args=opcode->m_operands;
1612 the_ins.numargs=opcode->m_opnum;
1613 the_ins.numo=opcode->m_codenum;
1614 the_ins.opcode[0]=getone(opcode);
1615 the_ins.opcode[1]=gettwo(opcode);
1617 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++) {
1618 /* This switch is a doozy.
1619 Watch the first step; its a big one! */
1637 tmpreg=0x3c; /* 7.4 */
1638 if (strchr("bwl",s[1])) nextword=get_num(opP->con1,80);
1639 else nextword=nextword=get_num(opP->con1,0);
1640 if(isvar(opP->con1))
1641 add_fix(s[1],opP->con1,0);
1644 if(!isbyte(nextword))
1645 opP->error="operand out of range";
1650 if(!isword(nextword))
1651 opP->error="operand out of range";
1656 addword(nextword>>16);
1678 as_fatal("Internal error: Can't decode %c%c in line %s of file \"%s\"",
1679 *s, s[1], __LINE__, __FILE__);
1684 /* We gotta put out some float */
1685 if(seg(opP->con1)!=SEG_BIG) {
1686 int_to_gen(nextword);
1687 gen_to_words(words,baseo,(long int)outro);
1688 for(wordp=words;baseo--;wordp++)
1692 if(offs(opP->con1)>0) {
1693 as_warn("Bignum assumed to be binary bit-pattern");
1694 if(offs(opP->con1)>baseo) {
1695 as_warn("Bignum too big for %c format; truncated",s[1]);
1696 offs(opP->con1)=baseo;
1698 baseo-=offs(opP->con1);
1699 for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
1705 gen_to_words(words,baseo,(long)outro);
1706 for (wordp=words;baseo--;wordp++)
1710 tmpreg=opP->reg-DATA; /* 0.dreg */
1713 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
1716 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
1719 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
1722 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
1726 nextword=get_num(opP->con1,80);
1727 /* Force into index mode. Hope this works */
1729 /* We do the first bit for 32-bit displacements,
1730 and the second bit for 16 bit ones. It is
1731 possible that we should make the default be
1732 WORD instead of LONG, but I think that'd
1733 break GCC, so we put up with a little
1734 inefficiency for the sake of working output.
1737 if( !issword(nextword)
1738 || ( isvar(opP->con1)
1739 && ( ( opP->con1->e_siz==0
1740 && flagseen['l']==0)
1741 || opP->con1->e_siz==3))) {
1744 tmpreg=0x3B; /* 7.3 */
1746 tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
1747 if(isvar(opP->con1)) {
1749 add_frag(adds(opP->con1),
1751 TAB(PCLEA,SZ_UNDEF));
1755 add_fix('l',opP->con1,1);
1759 addword(nextword>>16);
1762 tmpreg=0x3A; /* 7.2 */
1764 tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
1766 if(isvar(opP->con1)) {
1768 add_fix('w',opP->con1,1);
1770 add_fix('w',opP->con1,0);
1779 know(current_architecture & m68020up);
1780 /* intentional fall-through */
1783 baseo=get_num(opP->con1,80);
1784 outro=get_num(opP->con2,80);
1785 /* Figure out the 'addressing mode' */
1786 /* Also turn on the BASE_DISABLE bit, if needed */
1787 if(opP->reg==PC || opP->reg==ZPC) {
1788 tmpreg=0x3b; /* 7.3 */
1791 } else if(opP->reg==FAIL) {
1793 tmpreg=0x30; /* 6.garbage */
1794 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
1796 siz1= (opP->con1) ? opP->con1->e_siz : 0;
1797 siz2= (opP->con2) ? opP->con2->e_siz : 0;
1799 /* Index register stuff */
1800 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
1801 nextword|=(opP->ireg-DATA)<<12;
1803 if(opP->isiz==0 || opP->isiz==3)
1807 case 2: nextword|=0x200; break;
1808 case 4: nextword|=0x400; break;
1809 case 8: nextword|=0x600; break;
1810 default: as_fatal("failed sanity check.");
1813 GET US OUT OF HERE! */
1815 /* Must be INDEX, with an index
1816 register. Address register
1817 cannot be ZERO-PC, and either
1818 :b was forced, or we know
1820 if( opP->mode==AINDX
1825 && !isvar(opP->con1)))) {
1826 nextword +=baseo&0xff;
1828 if(isvar(opP->con1))
1829 add_fix('B',opP->con1,0);
1833 nextword|=0x40; /* No index reg */
1835 /* It aint simple */
1837 /* If the guy specified a width, we assume that
1838 it is wide enough. Maybe it isn't. If so, we lose
1842 if(isvar(opP->con1) || !issword(baseo)) {
1853 as_warn("Byte dispacement won't work. Defaulting to :w");
1862 /* Figure out innner displacement stuff */
1863 if(opP->mode!=AINDX) {
1866 if(isvar(opP->con2) || !issword(outro)) {
1877 as_warn("Byte dispacement won't work. Defaulting to :w");
1885 if(opP->mode==APODX) nextword|=0x04;
1886 else if(opP->mode==AMIND) nextword|=0x40;
1890 if(isvar(opP->con1)) {
1891 if(opP->reg==PC || opP->reg==ZPC) {
1892 add_fix(siz1==3 ? 'l' : 'w',opP->con1,1);
1893 opP->con1->e_exp.X_add_number+=6;
1895 add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
1902 if(isvar(opP->con2)) {
1903 if(opP->reg==PC || opP->reg==ZPC) {
1904 add_fix(siz2==3 ? 'l' : 'w',opP->con2,1);
1905 opP->con1->e_exp.X_add_number+=6;
1907 add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
1917 nextword=get_num(opP->con1,80);
1918 switch(opP->con1->e_siz) {
1920 as_warn("Unknown size for absolute reference");
1922 if(!isvar(opP->con1) && issword(offs(opP->con1))) {
1923 tmpreg=0x38; /* 7.0 */
1927 /* Don't generate pc relative code
1928 on 68010 and 68000 */
1931 && seg(opP->con1) == SEG_TEXT
1932 && now_seg == SEG_TEXT
1933 && cpu_of_arch(current_architecture) < m68020
1935 && !strchr("~%&$?", s[0])) {
1936 tmpreg=0x3A; /* 7.2 */
1937 add_frag(adds(opP->con1),
1939 TAB(PCREL,SZ_UNDEF));
1942 case 3: /* Fall through into long */
1943 if(isvar(opP->con1))
1944 add_fix('l',opP->con1,0);
1946 tmpreg=0x39; /* 7.1 mode */
1947 addword(nextword>>16);
1952 if(isvar(opP->con1))
1953 add_fix('w',opP->con1,0);
1955 tmpreg=0x38; /* 7.0 mode */
1962 as_bad("unknown/incorrect operand");
1965 install_gen_operand(s[1],tmpreg);
1970 switch(s[1]) { /* JF: I hate floating point! */
1985 tmpreg=get_num(opP->con1,tmpreg);
1986 if(isvar(opP->con1))
1987 add_fix(s[1],opP->con1,0);
1989 case 'b': /* Danger: These do no check for
1990 certain types of overflow.
1993 opP->error="out of range";
1995 if(isvar(opP->con1))
1996 the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
2000 opP->error="out of range";
2002 if(isvar(opP->con1))
2003 the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
2006 insop(tmpreg); /* Because of the way insop works, we put these two out backwards */
2008 if(isvar(opP->con1))
2009 the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
2015 install_operand(s[1],tmpreg);
2018 as_fatal("Internal error: Unknown mode #%c in line %s of file \"%s\"", s[1], __LINE__, __FILE__);
2026 install_operand(s[1],opP->reg-ADDR);
2030 tmpreg=get_num(opP->con1,80);
2033 /* Needs no offsetting */
2034 add_fix('B',opP->con1,1);
2037 /* Offset the displacement to be relative to byte disp location */
2038 opP->con1->e_exp.X_add_number+=2;
2039 add_fix('w',opP->con1,1);
2044 if (cpu_of_arch(current_architecture) < m68020) /* 68000 or 010 */
2045 as_warn("Can't use long branches on 68000/68010");
2046 the_ins.opcode[the_ins.numo-1]|=0xff;
2047 /* Offset the displacement to be relative to byte disp location */
2048 opP->con1->e_exp.X_add_number+=4;
2049 add_fix('l',opP->con1,1);
2054 if(subs(opP->con1)) /* We can't relax it */
2057 /* This could either be a symbol, or an
2058 absolute address. No matter, the
2059 frag hacking will finger it out.
2060 Not quite: it can't switch from
2061 BRANCH to BCC68000 for the case
2062 where opnd is absolute (it needs
2063 to use the 68000 hack since no
2064 conditional abs jumps). */
2065 if (((cpu_of_arch(current_architecture) < m68020) || (0==adds(opP->con1)))
2066 && (the_ins.opcode[0] >= 0x6200)
2067 && (the_ins.opcode[0] <= 0x6f00)) {
2068 add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
2070 add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
2074 if(isvar(opP->con1)) {
2075 /* check for DBcc instruction */
2076 if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8) {
2077 /* size varies if patch */
2078 /* needed for long form */
2079 add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
2084 opP->con1->e_exp.X_add_number+=2;
2085 add_fix('w',opP->con1,1);
2089 case 'C': /* Fixed size LONG coproc branches */
2090 the_ins.opcode[the_ins.numo-1]|=0x40;
2091 /* Offset the displacement to be relative to byte disp location */
2092 /* Coproc branches don't have a byte disp option, but they are
2093 compatible with the ordinary branches, which do... */
2094 opP->con1->e_exp.X_add_number+=4;
2095 add_fix('l',opP->con1,1);
2099 case 'c': /* Var size Coprocesssor branches */
2100 if(subs(opP->con1)) {
2101 add_fix('l',opP->con1,1);
2102 add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
2103 } else if(adds(opP->con1)) {
2104 add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
2106 /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
2107 the_ins.opcode[the_ins.numo-1]|=0x40;
2108 add_fix('l',opP->con1,1);
2114 as_fatal("Internal error: operand type B%c unknown in line %s of file \"%s\"",
2115 s[1], __LINE__, __FILE__);
2119 case 'C': /* Ignore it */
2122 case 'd': /* JF this is a kludge */
2123 if(opP->mode==AOFF) {
2124 install_operand('s',opP->reg-ADDR);
2128 tmpP=opP->con1->e_end-2;
2130 opP->con1->e_end-=4; /* point to the , */
2131 baseo=m68k_reg_parse(&tmpP);
2132 if(baseo<ADDR+0 || baseo>ADDR+7) {
2133 as_bad("Unknown address reg, using A0");
2136 install_operand('s',baseo);
2138 tmpreg=get_num(opP->con1,80);
2139 if(!issword(tmpreg)) {
2140 as_warn("Expression out of range, using 0");
2147 install_operand(s[1],opP->reg-DATA);
2151 install_operand(s[1],opP->reg-FPREG);
2155 tmpreg=1+opP->reg-COPNUM;
2158 install_operand(s[1],tmpreg);
2161 case 'J': /* JF foo */
2163 case SFC: tmpreg=0x000; break;
2164 case DFC: tmpreg=0x001; break;
2165 case CACR: tmpreg=0x002; break;
2166 case TC: tmpreg=0x003; break;
2167 case ITT0: tmpreg=0x004; break;
2168 case ITT1: tmpreg=0x005; break;
2169 case DTT0: tmpreg=0x006; break;
2170 case DTT1: tmpreg=0x007; break;
2172 case USP: tmpreg=0x800; break;
2173 case VBR: tmpreg=0x801; break;
2174 case CAAR: tmpreg=0x802; break;
2175 case MSP: tmpreg=0x803; break;
2176 case ISP: tmpreg=0x804; break;
2177 case MMUSR: tmpreg=0x805; break;
2178 case URP: tmpreg=0x806; break;
2179 case SRP: tmpreg=0x807; break;
2181 as_fatal("failed sanity check.");
2183 install_operand(s[1],tmpreg);
2187 tmpreg=get_num(opP->con1,55);
2188 install_operand(s[1],tmpreg&0x7f);
2194 if(tmpreg&0x7FF0000)
2195 as_bad("Floating point register in register list");
2196 insop(reverse_16_bits(tmpreg));
2198 if(tmpreg&0x700FFFF)
2199 as_bad("Wrong register in floating-point reglist");
2200 install_operand(s[1],reverse_8_bits(tmpreg>>16));
2207 if(tmpreg&0x7FF0000)
2208 as_bad("Floating point register in register list");
2210 } else if(s[1]=='8') {
2211 if(tmpreg&0x0FFFFFF)
2212 as_bad("incorrect register in reglist");
2213 install_operand(s[1],tmpreg>>24);
2215 if(tmpreg&0x700FFFF)
2216 as_bad("wrong register in floating-point reglist");
2218 install_operand(s[1],tmpreg>>16);
2223 install_operand(s[1],get_num(opP->con1,60));
2227 tmpreg= (opP->mode==DREG)
2228 ? 0x20+opP->reg-DATA
2229 : (get_num(opP->con1,40)&0x1F);
2230 install_operand(s[1],tmpreg);
2234 tmpreg=get_num(opP->con1,10);
2237 install_operand(s[1],tmpreg);
2241 /* This depends on the fact that ADDR registers are
2242 eight more than their corresponding DATA regs, so
2243 the result will have the ADDR_REG bit set */
2244 install_operand(s[1],opP->reg-DATA);
2248 if(opP->reg==FPI) tmpreg=0x1;
2249 else if(opP->reg==FPS) tmpreg=0x2;
2250 else if(opP->reg==FPC) tmpreg=0x4;
2251 else as_fatal("failed sanity check.");
2252 install_operand(s[1],tmpreg);
2255 case 'S': /* Ignore it */
2259 install_operand(s[1],get_num(opP->con1,30));
2262 case 'U': /* Ignore it */
2267 case NC: tmpreg = 0; break;
2268 case DC: tmpreg = 1; break;
2269 case IC: tmpreg = 2; break;
2270 case BC: tmpreg = 3; break;
2272 as_fatal("failed sanity check");
2273 } /* switch on cache token */
2274 install_operand(s[1], tmpreg);
2277 /* JF: These are out of order, I fear. */
2287 as_fatal("failed sanity check.");
2289 install_operand(s[1],tmpreg);
2310 as_fatal("failed sanity check.");
2312 install_operand(s[1],tmpreg);
2316 if (opP->reg == VAL)
2318 as_fatal("failed sanity check.");
2333 as_fatal("failed sanity check.");
2335 install_operand(s[1],tmpreg);
2340 case BAD: case BAD+1: case BAD+2: case BAD+3:
2341 case BAD+4: case BAD+5: case BAD+6: case BAD+7:
2342 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2345 case BAC: case BAC+1: case BAC+2: case BAC+3:
2346 case BAC+4: case BAC+5: case BAC+6: case BAC+7:
2347 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2351 as_fatal("failed sanity check.");
2353 install_operand(s[1], tmpreg);
2356 know(opP->reg == PSR);
2359 know(opP->reg == PCSR);
2363 tmpreg=get_num(opP->con1,80);
2364 install_operand(s[1], tmpreg);
2367 as_fatal("Internal error: Operand type %c unknown in line %s of file \"%s\"", s[0], __LINE__, __FILE__);
2370 /* By the time whe get here (FINALLY) the_ins contains the complete
2371 instruction, ready to be emitted. . . */
2375 * get_regs := '/' + ?
2376 * | '-' + <register>
2377 * | '-' + <register> + ?
2382 * The idea here must be to scan in a set of registers but I don't
2383 * understand it. Looks awfully sloppy to me but I don't have any doc on
2390 static int get_regs(i,str,opP)
2392 struct m68k_op *opP;
2395 /* 26, 25, 24, 23-16, 15-8, 0-7 */
2396 /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
2397 unsigned long cur_regs = 0;
2401 #define ADD_REG(x) { if(x==FPI) cur_regs|=(1<<24);\
2402 else if(x==FPS) cur_regs|=(1<<25);\
2403 else if(x==FPC) cur_regs|=(1<<26);\
2404 else cur_regs|=(1<<(x-1)); }
2411 } else if(*str=='-') {
2413 reg2=m68k_reg_parse(&str);
2414 if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
2415 opP->error="unknown register in register list";
2424 } else if(*str=='\0') {
2428 opP->error="unknow character in register list";
2431 /* DJA -- Bug Fix. Did't handle d1-d2/a1 until the following instruction was added */
2434 reg1=m68k_reg_parse(&str);
2435 if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
2436 opP->error="unknown register in register list";
2444 static int reverse_16_bits(in)
2450 static int mask[16] = {
2451 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2452 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
2459 } /* reverse_16_bits() */
2461 static int reverse_8_bits(in)
2467 static int mask[8] = {
2468 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
2476 } /* reverse_8_bits() */
2478 static void install_operand(mode,val)
2484 the_ins.opcode[0]|=val & 0xFF; /* JF FF is for M kludge */
2487 the_ins.opcode[0]|=val<<9;
2490 the_ins.opcode[1]|=val<<12;
2493 the_ins.opcode[1]|=val<<6;
2496 the_ins.opcode[1]|=val;
2499 the_ins.opcode[2]|=val<<12;
2502 the_ins.opcode[2]|=val<<6;
2505 /* DANGER! This is a hack to force cas2l and cas2w cmds
2506 to be three words long! */
2508 the_ins.opcode[2]|=val;
2511 the_ins.opcode[1]|=val<<7;
2514 the_ins.opcode[1]|=val<<10;
2518 the_ins.opcode[1]|=val<<5;
2523 the_ins.opcode[1]|=(val<<10)|(val<<7);
2526 the_ins.opcode[1]|=(val<<12)|val;
2529 the_ins.opcode[0]|=val=0xff;
2532 the_ins.opcode[0]|=val<<9;
2535 the_ins.opcode[1]|=val;
2538 the_ins.opcode[1]|=val;
2539 the_ins.numo++; /* What a hack */
2542 the_ins.opcode[1]|=val<<4;
2549 the_ins.opcode[0] |= (val << 6);
2552 the_ins.opcode[1] = (val >> 16);
2553 the_ins.opcode[2] = val & 0xffff;
2557 as_fatal("failed sanity check.");
2559 } /* install_operand() */
2561 static void install_gen_operand(mode,val)
2567 the_ins.opcode[0]|=val;
2570 /* This is a kludge!!! */
2571 the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
2580 the_ins.opcode[0]|=val;
2582 /* more stuff goes here */
2584 as_fatal("failed sanity check.");
2586 } /* install_gen_operand() */
2589 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2590 * then deal with the bitfield hack.
2593 static char *crack_operand(str,opP)
2595 register struct m68k_op *opP;
2597 register int parens;
2599 register char *beg_str;
2605 for(parens=0;*str && (parens>0 || notend(str));str++) {
2606 if(*str=='(') parens++;
2607 else if(*str==')') {
2608 if(!parens) { /* ERROR */
2609 opP->error="Extra )";
2615 if(!*str && parens) { /* ERROR */
2616 opP->error="Missing )";
2621 if(m68k_ip_op(beg_str,opP)==FAIL) {
2627 c= *++str; /* JF bitfield hack */
2631 as_bad("Missing operand");
2636 /* See the comment up above where the #define notend(... is */
2641 if(*s==',') return 0;
2642 if(*s=='{' || *s=='}')
2644 if(*s!=':') return 1;
2645 /* This kludge here is for the division cmd, which is a kludge */
2646 if(index("aAdD#",s[1])) return 0;
2651 /* This is the guts of the machine-dependent assembler. STR points to a
2652 machine dependent instruction. This function is supposed to emit
2653 the frags/bytes it assembles to.
2664 int shorts_this_frag;
2667 if (current_architecture == 0) {
2668 current_architecture = (m68020
2676 } /* default current_architecture */
2678 bzero((char *)(&the_ins),sizeof(the_ins)); /* JF for paranoia sake */
2682 for(n=the_ins.numargs;n;--n)
2683 if(the_ins.operands[n].error) {
2684 er=the_ins.operands[n].error;
2689 as_bad("\"%s\" -- Statement '%s' ignored",er,str);
2693 if(the_ins.nfrag==0) { /* No frag hacking involved; just put it out */
2694 toP=frag_more(2*the_ins.numo);
2695 fromP= &the_ins.opcode[0];
2696 for(m=the_ins.numo;m;--m) {
2697 md_number_to_chars(toP,(long)(*fromP),2);
2701 /* put out symbol-dependent info */
2702 for(m=0;m<the_ins.nrel;m++) {
2703 switch(the_ins.reloc[m].wid) {
2720 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins.reloc[m].wid);
2724 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
2726 the_ins.reloc[m].add,
2727 the_ins.reloc[m].sub,
2728 the_ins.reloc[m].off,
2729 the_ins.reloc[m].pcrel,
2735 /* There's some frag hacking */
2736 for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
2739 if(n==0) wid=2*the_ins.fragb[n].fragoff;
2740 else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
2744 for(m=wid/2;m;--m) {
2745 md_number_to_chars(toP,(long)(*fromP),2);
2750 for(m=0;m<the_ins.nrel;m++) {
2751 if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
2752 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
2755 wid=the_ins.reloc[m].wid;
2758 the_ins.reloc[m].wid=0;
2759 wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
2762 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
2764 the_ins.reloc[m].add,
2765 the_ins.reloc[m].sub,
2766 the_ins.reloc[m].off,
2767 the_ins.reloc[m].pcrel,
2770 /* know(the_ins.fragb[n].fadd); */
2771 (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
2772 the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
2774 n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
2777 toP=frag_more(n*sizeof(short));
2779 md_number_to_chars(toP,(long)(*fromP),2);
2785 for(m=0;m<the_ins.nrel;m++) {
2788 wid=the_ins.reloc[m].wid;
2791 the_ins.reloc[m].wid=0;
2792 wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
2795 (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
2797 the_ins.reloc[m].add,
2798 the_ins.reloc[m].sub,
2799 the_ins.reloc[m].off,
2800 the_ins.reloc[m].pcrel,
2805 /* This function is called once, at assembler startup time. This should
2806 set up all the tables, etc that the MD part of the assembler needs
2812 * md_begin -- set up hash tables with 68000 instructions.
2813 * similar to what the vax assembler does. ---phr
2815 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
2816 a copy of it at runtime, adding in the information we want but isn't
2817 there. I think it'd be better to have an awk script hack the table
2818 at compile time. Or even just xstr the table and use it as-is. But
2819 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2822 register const struct m68k_opcode *ins;
2823 register struct m68k_incant *hack,
2825 register char *retval = 0; /* empty string, or error msg text */
2826 register unsigned int i;
2829 if ((op_hash = hash_new()) == NULL)
2830 as_fatal("Virtual memory exhausted");
2832 obstack_begin(&robyn,4000);
2833 for (ins = m68k_opcodes; ins < endop; ins++) {
2834 hack=slak=(struct m68k_incant *)obstack_alloc(&robyn,sizeof(struct m68k_incant));
2836 /* we *could* ignore insns that don't match our
2837 arch here but just leaving them out of the
2839 slak->m_operands=ins->args;
2840 slak->m_opnum=strlen(slak->m_operands)/2;
2841 slak->m_arch = ins->arch;
2842 slak->m_opcode=ins->opcode;
2843 /* This is kludgey */
2844 slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
2845 if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
2846 slak->m_next=(struct m68k_incant *) obstack_alloc(&robyn,sizeof(struct m68k_incant));
2853 retval = hash_insert (op_hash, ins->name,(char *)hack);
2854 /* Didn't his mommy tell him about null pointers? */
2855 if(retval && *retval)
2856 as_fatal("Internal Error: Can't hash %s: %s",ins->name,retval);
2859 for (i = 0; i < sizeof(mklower_table) ; i++)
2860 mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
2862 for (i = 0 ; i < sizeof(notend_table) ; i++) {
2863 notend_table[i] = 0;
2864 alt_notend_table[i] = 0;
2866 notend_table[','] = 1;
2867 notend_table['{'] = 1;
2868 notend_table['}'] = 1;
2869 alt_notend_table['a'] = 1;
2870 alt_notend_table['A'] = 1;
2871 alt_notend_table['d'] = 1;
2872 alt_notend_table['D'] = 1;
2873 alt_notend_table['#'] = 1;
2874 alt_notend_table['f'] = 1;
2875 alt_notend_table['F'] = 1;
2876 #ifdef REGISTER_PREFIX
2877 alt_notend_table[REGISTER_PREFIX] = 1;
2882 #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
2883 || (*s == ':' && strchr("aAdD#", s[1]))) \
2887 /* This funciton is called once, before the assembler exits. It is
2888 supposed to do any final cleanup for this part of the assembler.
2895 /* Equal to MAX_PRECISION in atof-ieee.c */
2896 #define MAX_LITTLENUMS 6
2898 /* Turn a string in input_line_pointer into a floating point constant of type
2899 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2900 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2903 md_atof(type,litP,sizeP)
2909 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2910 LITTLENUM_TYPE *wordP;
2941 return "Bad call to MD_ATOF()";
2943 t=atof_ieee(input_line_pointer,type,words);
2945 input_line_pointer=t;
2947 *sizeP=prec * sizeof(LITTLENUM_TYPE);
2948 for(wordP=words;prec--;) {
2949 md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
2950 litP+=sizeof(LITTLENUM_TYPE);
2952 return ""; /* Someone should teach Dean about null pointers */
2955 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
2956 for use in the a.out file, and stores them in the array pointed to by buf.
2957 This knows about the endian-ness of the target machine and does
2958 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
2959 2 (short) and 4 (long) Floating numbers are put out as a series of
2960 LITTLENUMS (shorts, here at least)
2963 md_number_to_chars(buf,val,n)
2983 as_fatal("failed sanity check.");
2988 md_apply_fix(fixP, val)
2992 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2994 switch(fixP->fx_size) {
3009 BAD_CASE (fixP->fx_size);
3014 /* *fragP has been relaxed to its final size, and now needs to have
3015 the bytes inside it modified to conform to the new size There is UGLY
3019 md_convert_frag(headers, fragP)
3020 object_headers *headers;
3021 register fragS *fragP;
3026 /* Address in object code of the displacement. */
3027 register int object_address = fragP -> fr_fix + fragP -> fr_address;
3029 #ifdef IBM_COMPILER_SUX
3030 /* This is wrong but it convinces the native rs6000 compiler to
3031 generate the code we want. */
3032 register char *buffer_address = fragP -> fr_literal;
3033 buffer_address += fragP -> fr_fix;
3034 #else /* IBM_COMPILER_SUX */
3035 /* Address in gas core of the place to store the displacement. */
3036 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
3037 #endif /* IBM_COMPILER_SUX */
3039 /* No longer true: know(fragP->fr_symbol); */
3041 /* The displacement of the address, from current location. */
3042 disp = fragP->fr_symbol ? S_GET_VALUE(fragP->fr_symbol) : 0;
3043 disp = (disp + fragP->fr_offset) - object_address;
3045 switch(fragP->fr_subtype) {
3046 case TAB(BCC68000,BYTE):
3047 case TAB(BRANCH,BYTE):
3048 know(issbyte(disp));
3050 as_bad("short branch with zero offset: use :w");
3051 fragP->fr_opcode[1]=disp;
3054 case TAB(DBCC,SHORT):
3055 know(issword(disp));
3058 case TAB(BCC68000,SHORT):
3059 case TAB(BRANCH,SHORT):
3060 know(issword(disp));
3061 fragP->fr_opcode[1]=0x00;
3064 case TAB(BRANCH,LONG):
3065 if (cpu_of_arch(current_architecture) < m68020) {
3066 if (fragP->fr_opcode[0]==0x61) {
3067 fragP->fr_opcode[0]= 0x4E;
3068 fragP->fr_opcode[1]= 0xB9; /* JBSR with ABSL LONG offset */
3069 subseg_change(SEG_TEXT, 0);
3082 } else if (fragP->fr_opcode[0]==0x60) {
3083 fragP->fr_opcode[0]= 0x4E;
3084 fragP->fr_opcode[1]= 0xF9; /* JMP with ABSL LONG offset */
3085 subseg_change(SEG_TEXT, 0);
3086 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0,
3091 as_bad("Long branch offset not supported.");
3094 fragP->fr_opcode[1]=0xff;
3098 case TAB(BCC68000,LONG):
3099 /* only Bcc 68000 instructions can come here */
3100 /* change bcc into b!cc/jmp absl long */
3101 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
3102 fragP->fr_opcode[1] = 0x6; /* branch offset = 6 */
3104 /* JF: these used to be fr_opcode[2,3], but they may be in a
3105 different frag, in which case refering to them is a no-no.
3106 Only fr_opcode[0,1] are guaranteed to work. */
3107 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
3108 *buffer_address++ = 0xf9;
3109 fragP->fr_fix += 2; /* account for jmp instruction */
3110 subseg_change(SEG_TEXT,0);
3111 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3117 case TAB(DBCC,LONG):
3118 /* only DBcc 68000 instructions can come here */
3119 /* change dbcc into dbcc/jmp absl long */
3120 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3121 *buffer_address++ = 0x00; /* branch offset = 4 */
3122 *buffer_address++ = 0x04;
3123 *buffer_address++ = 0x60; /* put in bra pc+6 */
3124 *buffer_address++ = 0x06;
3125 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
3126 *buffer_address++ = 0xf9;
3128 fragP->fr_fix += 6; /* account for bra/jmp instructions */
3129 subseg_change(SEG_TEXT,0);
3130 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3136 case TAB(FBRANCH,SHORT):
3137 know((fragP->fr_opcode[1]&0x40)==0);
3140 case TAB(FBRANCH,LONG):
3141 fragP->fr_opcode[1]|=0x40; /* Turn on LONG bit */
3144 case TAB(PCREL,SHORT):
3147 case TAB(PCREL,LONG):
3148 /* The thing to do here is force it to ABSOLUTE LONG, since
3149 PCREL is really trying to shorten an ABSOLUTE address anyway */
3150 /* JF FOO This code has not been tested */
3151 subseg_change(SEG_TEXT,0);
3152 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
3153 if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
3154 as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
3155 fragP->fr_opcode[0],fragP->fr_address);
3156 fragP->fr_opcode[1]&= ~0x3F;
3157 fragP->fr_opcode[1]|=0x39; /* Mode 7.1 */
3159 /* md_number_to_chars(buffer_address,
3160 (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
3164 case TAB(PCLEA,SHORT):
3165 subseg_change(SEG_TEXT,0);
3166 fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset,1,
3168 fragP->fr_opcode[1] &= ~0x3F;
3169 fragP->fr_opcode[1] |= 0x3A;
3172 case TAB(PCLEA,LONG):
3173 subseg_change(SEG_TEXT,0);
3174 fix_new(fragP,(int)(fragP->fr_fix)+2,4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset+2,1,
3176 *buffer_address++ = 0x01;
3177 *buffer_address++ = 0x70;
3179 /* buffer_address+=2; */
3183 } /* switch on subtype */
3186 md_number_to_chars(buffer_address, (long) disp, (int) ext);
3187 fragP->fr_fix += ext;
3188 /* H_SET_TEXT_SIZE(headers, H_GET_TEXT_SIZE(headers) + ext); */
3189 } /* if extending */
3192 } /* md_convert_frag() */
3194 /* Force truly undefined symbols to their maximum size, and generally set up
3195 the frag list to be relaxed
3197 int md_estimate_size_before_relax(fragP, segment)
3198 register fragS *fragP;
3202 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
3204 old_fix = fragP->fr_fix;
3206 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3207 switch(fragP->fr_subtype) {
3209 case TAB(BRANCH,SZ_UNDEF): {
3210 if((fragP->fr_symbol != NULL) /* Not absolute */
3211 && S_GET_SEGMENT(fragP->fr_symbol) == segment) {
3212 fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
3214 } else if((fragP->fr_symbol == 0) || (cpu_of_arch(current_architecture) < m68020)) {
3215 /* On 68000, or for absolute value, switch to abs long */
3216 /* FIXME, we should check abs val, pick short or long */
3217 if(fragP->fr_opcode[0]==0x61) {
3218 fragP->fr_opcode[0]= 0x4E;
3219 fragP->fr_opcode[1]= 0xB9; /* JBSR with ABSL LONG offset */
3220 subseg_change(SEG_TEXT, 0);
3221 fix_new(fragP, fragP->fr_fix, 4,
3222 fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
3225 } else if(fragP->fr_opcode[0]==0x60) {
3226 fragP->fr_opcode[0]= 0x4E;
3227 fragP->fr_opcode[1]= 0xF9; /* JMP with ABSL LONG offset */
3228 subseg_change(SEG_TEXT, 0);
3229 fix_new(fragP, fragP->fr_fix, 4,
3230 fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
3234 as_warn("Long branch offset to extern symbol not supported.");
3236 } else { /* Symbol is still undefined. Make it simple */
3237 fix_new(fragP, (int)(fragP->fr_fix), 4, fragP->fr_symbol,
3238 (symbolS *)0, fragP->fr_offset+4, 1, NO_RELOC);
3240 fragP->fr_opcode[1]=0xff;
3246 } /* case TAB(BRANCH,SZ_UNDEF) */
3248 case TAB(FBRANCH,SZ_UNDEF): {
3249 if(S_GET_SEGMENT(fragP->fr_symbol) == segment || flagseen['l']) {
3250 fragP->fr_subtype = TAB(FBRANCH,SHORT);
3253 fragP->fr_subtype = TAB(FBRANCH,LONG);
3257 } /* TAB(FBRANCH,SZ_UNDEF) */
3259 case TAB(PCREL,SZ_UNDEF): {
3260 if(S_GET_SEGMENT(fragP->fr_symbol) == segment || flagseen['l']) {
3261 fragP->fr_subtype = TAB(PCREL,SHORT);
3264 fragP->fr_subtype = TAB(PCREL,LONG);
3268 } /* TAB(PCREL,SZ_UNDEF) */
3270 case TAB(BCC68000,SZ_UNDEF): {
3271 if((fragP->fr_symbol != NULL)
3272 && S_GET_SEGMENT(fragP->fr_symbol) == segment) {
3273 fragP->fr_subtype=TAB(BCC68000,BYTE);
3276 /* only Bcc 68000 instructions can come here */
3277 /* change bcc into b!cc/jmp absl long */
3278 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
3280 fragP->fr_opcode[1] = 0x04; /* branch offset = 6 */
3281 /* JF: these were fr_opcode[2,3] */
3282 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
3283 buffer_address[1] = 0xf8;
3284 fragP->fr_fix += 2; /* account for jmp instruction */
3285 subseg_change(SEG_TEXT,0);
3286 fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0,
3287 fragP->fr_offset, 0, NO_RELOC);
3290 fragP->fr_opcode[1] = 0x06; /* branch offset = 6 */
3291 /* JF: these were fr_opcode[2,3] */
3292 buffer_address[2] = 0x4e; /* put in jmp long (0x4ef9) */
3293 buffer_address[3] = 0xf9;
3294 fragP->fr_fix += 2; /* account for jmp instruction */
3295 subseg_change(SEG_TEXT,0);
3296 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3297 fragP->fr_offset, 0, NO_RELOC);
3302 } /* case TAB(BCC68000,SZ_UNDEF) */
3304 case TAB(DBCC,SZ_UNDEF): {
3305 if (fragP->fr_symbol != NULL && S_GET_SEGMENT(fragP->fr_symbol) == segment) {
3306 fragP->fr_subtype=TAB(DBCC,SHORT);
3310 /* only DBcc 68000 instructions can come here */
3311 /* change dbcc into dbcc/jmp absl long */
3312 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3313 buffer_address[0] = 0x00; /* branch offset = 4 */
3314 buffer_address[1] = 0x04;
3315 buffer_address[2] = 0x60; /* put in bra pc + ... */
3318 /* JF: these were fr_opcode[5-7] */
3319 buffer_address[3] = 0x04; /* plus 4 */
3320 buffer_address[4] = 0x4e;/* Put in Jump Word */
3321 buffer_address[5] = 0xf8;
3322 fragP->fr_fix += 6; /* account for bra/jmp instruction */
3323 subseg_change(SEG_TEXT,0);
3324 fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0,
3325 fragP->fr_offset, 0, NO_RELOC);
3328 /* JF: these were fr_opcode[5-7] */
3329 buffer_address[3] = 0x06; /* Plus 6 */
3330 buffer_address[4] = 0x4e; /* put in jmp long (0x4ef9) */
3331 buffer_address[5] = 0xf9;
3332 fragP->fr_fix += 6; /* account for bra/jmp instruction */
3333 subseg_change(SEG_TEXT,0);
3334 fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
3335 fragP->fr_offset, 0, NO_RELOC);
3341 } /* case TAB(DBCC,SZ_UNDEF) */
3343 case TAB(PCLEA,SZ_UNDEF): {
3344 if ((S_GET_SEGMENT(fragP->fr_symbol))==segment || flagseen['l']) {
3345 fragP->fr_subtype=TAB(PCLEA,SHORT);
3348 fragP->fr_subtype=TAB(PCLEA,LONG);
3352 } /* TAB(PCLEA,SZ_UNDEF) */
3357 } /* switch on subtype looking for SZ_UNDEF's. */
3359 /* now that SZ_UNDEF are taken care of, check others */
3360 switch(fragP->fr_subtype) {
3361 case TAB(BCC68000,BYTE):
3362 case TAB(BRANCH,BYTE):
3363 /* We can't do a short jump to the next instruction,
3364 so we force word mode. */
3365 if (fragP->fr_symbol && S_GET_VALUE(fragP->fr_symbol)==0 &&
3366 fragP->fr_symbol->sy_frag==fragP->fr_next) {
3367 fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
3374 return fragP->fr_var + fragP->fr_fix - old_fix;
3377 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
3378 /* the bit-field entries in the relocation_info struct plays hell
3379 with the byte-order problems of cross-assembly. So as a hack,
3380 I added this mach. dependent ri twiddler. Ugly, but it gets
3382 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
3383 are symbolnum, most sig. byte first. Last byte is broken up with
3384 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3385 nibble as nuthin. (on Sun 3 at least) */
3386 /* Translate the internal relocation information into target-specific
3390 md_ri_to_chars(the_bytes, ri)
3392 struct reloc_info_generic *ri;
3395 md_number_to_chars(the_bytes, ri->r_address, 4);
3396 /* now the fun stuff */
3397 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
3398 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
3399 the_bytes[6] = ri->r_symbolnum & 0x0ff;
3400 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
3401 ((ri->r_extern << 4) & 0x10));
3403 #endif /* comment */
3405 void tc_aout_fix_to_chars(where, fixP, segment_address_in_file)
3408 relax_addressT segment_address_in_file;
3411 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3412 * Out: GNU LD relocation length code: 0, 1, or 2.
3415 static unsigned char nbytes_r_length [] = { 42, 0, 1, 42, 2 };
3421 md_number_to_chars(where,
3422 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
3425 /* now the fun stuff */
3426 if (S_GET_TYPE(fixP->fx_addsy) == N_UNDF) {
3428 r_symbolnum = fixP->fx_addsy->sy_number;
3431 r_symbolnum = S_GET_TYPE(fixP->fx_addsy);
3434 where[4] = (r_symbolnum >> 16) & 0x0ff;
3435 where[5] = (r_symbolnum >> 8) & 0x0ff;
3436 where[6] = r_symbolnum & 0x0ff;
3437 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
3438 ((r_extern << 4) & 0x10));
3441 } /* tc_aout_fix_to_chars() */
3443 #endif /* OBJ_AOUT or OBJ_BOUT */
3445 #ifndef WORKING_DOT_WORD
3446 const int md_short_jump_size = 4;
3447 const int md_long_jump_size = 6;
3450 md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
3459 offset = to_addr - (from_addr+2);
3461 md_number_to_chars(ptr ,(long)0x6000,2);
3462 md_number_to_chars(ptr+2,(long)offset,2);
3466 md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
3475 if (cpu_of_arch(current_architecture) < m68020) {
3476 offset=to_addr-S_GET_VALUE(to_symbol);
3477 md_number_to_chars(ptr ,(long)0x4EF9,2);
3478 md_number_to_chars(ptr+2,(long)offset,4);
3479 fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long)0,0,
3482 offset=to_addr - (from_addr+2);
3483 md_number_to_chars(ptr ,(long)0x60ff,2);
3484 md_number_to_chars(ptr+2,(long)offset,4);
3489 /* Different values of OK tell what its OK to return. Things that aren't OK are an error (what a shock, no?)
3492 10: Absolute 1:8 only
3493 20: Absolute 0:7 only
3494 30: absolute 0:15 only
3495 40: Absolute 0:31 only
3496 50: absolute 0:127 only
3497 55: absolute -64:63 only
3498 60: absolute -128:127 only
3499 70: absolute 0:4095 only
3504 static int get_num(exp,ok)
3505 struct m68k_exp *exp;
3513 if(*exp->e_beg=='0') {
3514 if(exp->e_beg[1]=='x')
3515 sscanf(exp->e_beg+2,"%x",&l);
3517 sscanf(exp->e_beg+1,"%O",&l);
3520 return atol(exp->e_beg);
3526 /* Can't do anything */
3529 if(!exp->e_beg || !exp->e_end) {
3530 seg(exp)=SEG_ABSOLUTE;
3533 offs(exp)= (ok==10) ? 1 : 0;
3534 as_warn("Null expression defaults to %ld",offs(exp));
3539 if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>=2) {
3540 switch(exp->e_end[0]) {
3556 as_bad("Unknown size for expression \"%c\"",exp->e_end[0]);
3560 c_save=exp->e_end[1];
3562 save_in=input_line_pointer;
3563 input_line_pointer=exp->e_beg;
3564 switch(expression(&(exp->e_exp))) {
3566 seg(exp)=SEG_ABSOLUTE;
3569 offs(exp)= (ok==10) ? 1 : 0;
3570 as_warn("Unknown expression: '%s' defaulting to %d",exp->e_beg,offs(exp));
3574 /* Do the same thing the VAX asm does */
3575 seg(exp)=SEG_ABSOLUTE;
3580 as_warn("expression out of range: defaulting to 1");
3587 if(offs(exp)<1 || offs(exp)>8) {
3588 as_warn("expression out of range: defaulting to 1");
3593 if(offs(exp)<0 || offs(exp)>7)
3597 if(offs(exp)<0 || offs(exp)>15)
3601 if(offs(exp)<0 || offs(exp)>32)
3605 if(offs(exp)<0 || offs(exp)>127)
3609 if(offs(exp)<-64 || offs(exp)>63)
3613 if(offs(exp)<-128 || offs(exp)>127)
3617 if(offs(exp)<0 || offs(exp)>4095) {
3619 as_warn("expression out of range: defaulting to 0");
3631 case SEG_DIFFERENCE:
3632 if(ok>=10 && ok<=70) {
3633 seg(exp)=SEG_ABSOLUTE;
3636 offs(exp)= (ok==10) ? 1 : 0;
3637 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
3641 if(ok==80 && offs(exp)<0) { /* HACK! Turn it into a long */
3642 LITTLENUM_TYPE words[6];
3644 gen_to_words(words,2,8L);/* These numbers are magic! */
3645 seg(exp)=SEG_ABSOLUTE;
3648 offs(exp)=words[1]|(words[0]<<16);
3650 seg(exp)=SEG_ABSOLUTE;
3653 offs(exp)= (ok==10) ? 1 : 0;
3654 as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
3658 as_fatal("failed sanity check.");
3660 if(input_line_pointer!=exp->e_end+1)
3661 as_bad("Ignoring junk after expression");
3662 exp->e_end[1]=c_save;
3663 input_line_pointer=save_in;
3665 switch(exp->e_siz) {
3667 if(!isbyte(offs(exp)))
3668 as_warn("expression doesn't fit in BYTE");
3671 if(!isword(offs(exp)))
3672 as_warn("expression doesn't fit in WORD");
3680 /* These are the back-ends for the various machine dependent pseudo-ops. */
3681 void demand_empty_rest_of_line(); /* Hate those extra verbose names */
3683 static void s_data1() {
3684 subseg_new(SEG_DATA,1);
3685 demand_empty_rest_of_line();
3688 static void s_data2() {
3689 subseg_new(SEG_DATA,2);
3690 demand_empty_rest_of_line();
3693 static void s_bss() {
3694 /* We don't support putting frags in the BSS segment, but we
3695 can put them into initialized data for now... */
3696 subseg_new(SEG_DATA,255); /* FIXME-SOON */
3697 demand_empty_rest_of_line();
3700 static void s_even() {
3702 register long temp_fill;
3704 temp = 1; /* JF should be 2? */
3705 temp_fill = get_absolute_expression ();
3706 if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
3707 frag_align (temp, (int)temp_fill);
3708 demand_empty_rest_of_line();
3711 static void s_proc() {
3712 demand_empty_rest_of_line();
3715 /* s_space is defined in read.c .skip is simply an alias to it. */
3719 * Invocation line includes a switch not recognized by the base assembler.
3720 * See if it's a processor-specific option. These are:
3722 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
3723 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
3724 * Select the architecture. Instructions or features not
3725 * supported by the selected architecture cause fatal
3726 * errors. More than one may be specified. The default is
3727 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
3728 * for -m68000, and -m68882 is a synonym for -m68881.
3730 * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
3731 * (e.g. m68020) also requests that float instructions be included. This
3732 * is the default setup, mostly to avoid hassling users. A better
3733 * rearrangement of this structure would be to add an option to DENY
3734 * floating point opcodes, for people who want to really know there's none
3735 * of that funny floaty stuff going on. FIXME-later.
3737 #ifndef MAYBE_FLOAT_TOO
3738 #define MAYBE_FLOAT_TOO m68881
3741 int md_parse_option(argP,cntP,vecP)
3747 case 'l': /* -l means keep external to 2 bit offset
3748 rather than 16 bit one */
3751 case 'S': /* -S means that jbsr's always turn into jsr's. */
3756 /* intentional fall-through */
3762 } /* allow an optional "c" */
3764 if (!strcmp(*argP, "68000")
3765 || !strcmp(*argP, "68008")) {
3766 current_architecture |= m68000;
3767 } else if (!strcmp(*argP, "68010")) {
3769 omagic= 1<<16|OMAGIC;
3771 current_architecture |= m68010;
3773 } else if (!strcmp(*argP, "68020")) {
3774 current_architecture |= m68020 | MAYBE_FLOAT_TOO;
3776 } else if (!strcmp(*argP, "68030")) {
3777 current_architecture |= m68030 | MAYBE_FLOAT_TOO;
3779 } else if (!strcmp(*argP, "68040")) {
3780 current_architecture |= m68040 | MAYBE_FLOAT_TOO;
3783 } else if (!strcmp(*argP, "68881")) {
3784 current_architecture |= m68881;
3786 } else if (!strcmp(*argP, "68882")) {
3787 current_architecture |= m68882;
3789 #endif /* NO_68881 */
3791 } else if (!strcmp(*argP,"68851")) {
3792 current_architecture |= m68851;
3794 #endif /* NO_68851 */
3796 as_warn("Unknown architecture, \"%s\". option ignored", *argP);
3797 } /* switch on architecture */
3799 while(**argP) (*argP)++;
3804 if (!strcmp(*argP,"pic")) {
3806 break; /* -pic, Position Independent Code */
3820 /* TEST2: Test md_assemble() */
3821 /* Warning, this routine probably doesn't work anymore */
3825 struct m68k_it the_ins;
3832 if(!gets(buf) || !*buf)
3834 if(buf[0]=='|' || buf[1]=='.')
3836 for(cp=buf;*cp;cp++)
3841 bzero(&the_ins,sizeof(the_ins));
3842 m68k_ip(&the_ins,buf);
3844 printf("Error %s in %s\n",the_ins.error,buf);
3846 printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
3847 for(n=0;n<the_ins.numo;n++)
3848 printf(" 0x%x",the_ins.opcode[n]&0xffff);
3850 print_the_insn(&the_ins.opcode[0],stdout);
3851 (void)putchar('\n');
3853 for(n=0;n<strlen(the_ins.args)/2;n++) {
3854 if(the_ins.operands[n].error) {
3855 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
3858 printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
3859 if(the_ins.operands[n].b_const)
3860 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
3861 printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
3862 if(the_ins.operands[n].b_iadd)
3863 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
3864 (void)putchar('\n');
3876 while(*str && *str!=' ')
3878 if(str[-1]==':' || str[1]=='=')
3885 /* Possible states for relaxation:
3887 0 0 branch offset byte (bra, etc)
3891 1 0 indexed offsets byte a0@(32,d4:w:1) etc
3895 2 0 two-offset index word-word a0@(32,d4)@(45) etc
3931 extern fragS *text_frag_root;
3933 for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
3934 printf("addr %lu next 0x%x fix %ld var %ld symbol 0x%x offset %ld\n",
3935 fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
3936 printf("opcode 0x%x type %d subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
3948 fputs("Internal error:",stderr);
3949 _doprnt(format,&args,stderr);
3950 (void)putc('\n',stderr);
3956 /* We have no need to default values of symbols. */
3960 md_undefined_symbol (name)
3966 /* Parse an operand that is machine-specific.
3967 We just return without modifying the expression if we have nothing
3972 md_operand (expressionP)
3973 expressionS *expressionP;
3977 /* Round up a section size to the appropriate boundary. */
3979 md_section_align (segment, size)
3983 return size; /* Byte alignment is fine */
3986 /* Exactly what point is a PC-relative offset relative TO?
3987 On the 68k, they're relative to the address of the offset, plus
3988 its size. (??? Is this right? FIXME-SOON!) */
3990 md_pcrel_from (fixP)
3993 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
4003 /* end of tc-m68k.c */