home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gas-1.38.1-src.lha / src / amiga / gas-1.38 / m68k.c < prev    next >
C/C++ Source or Header  |  1993-09-09  |  88KB  |  3,773 lines

  1. /* m68k.c  All the m68020 specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.    Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of GAS, the GNU Assembler.
  6.  
  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 1, or (at your option)
  10. any later version.
  11.  
  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.
  16.  
  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.  */
  20.  
  21.  
  22.  
  23.  
  24. #if 0
  25. #define DP(a) printf a
  26. #else
  27. #define DP(a)
  28. #endif
  29.  
  30.  
  31.  
  32. #include <ctype.h>
  33.  
  34. #include "m68k-opcode.h"
  35. #include "as.h"
  36. #include "obstack.h"
  37. #include "frags.h"
  38. #include "struc-symbol.h"
  39. #include "flonum.h"
  40. #include "expr.h"
  41. #include "hash.h"
  42. #include "md.h"
  43. #include "m68k.h"
  44.  
  45. extern char *index();
  46.  
  47. /* This variable contains the value to write out at the beginning of
  48.    the a.out file.  The MID_SUN020 means that this is a 68020 file instead
  49.    of an old-style 68000 file */
  50.  
  51. short mid    = MID_SUN020;
  52. short omagic = OMAGIC;    /* Magic byte for header file */
  53.  
  54. /* This array holds the chars that always start a comment.  If the
  55.    pre-processor is disabled, these aren't very useful */
  56. const char comment_chars[] = "|";
  57.  
  58. /* This array holds the chars that only start a comment at the beginning of
  59.    a line.  If the line seems to have the form '# 123 filename'
  60.    .line and .file directives will appear in the pre-processed output */
  61. /* Note that input_file.c hand checks for '#' at the beginning of the
  62.    first line of the input file.  This is because the compiler outputs
  63.    #NO_APP at the beginning of its output. */
  64. /* Also note that '/*' will always start a comment */
  65. const char line_comment_chars[] = "#";
  66.  
  67. /* Chars that can be used to separate mant from exp in floating point nums */
  68. const char EXP_CHARS[] = "eE";
  69.  
  70. /* Chars that mean this number is a floating point constant */
  71. /* As in 0f12.456 */
  72. /* or    0d1.2345e12 */
  73.  
  74. const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  75.  
  76. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  77.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  78.    but nothing is ideal around here.
  79.  */
  80.  
  81. void fix_new();
  82. void install_operand();
  83. void install_gen_operand();
  84.  
  85. /* Its an arbitrary name:  This means I don't approve of it */
  86. /* See flames below */
  87. struct obstack robyn;
  88.  
  89. #define TAB(x,y)    (((x)<<2)+(y))
  90. #define TABTYPE(xy)     ((xy) >> 2)
  91. #define BYTE        0
  92. #define SHORT        1
  93. #define LONG        2
  94. #define SZ_UNDEF    3
  95.  
  96. #define BRANCH        1
  97. #define FBRANCH        2
  98. #define PCREL        3
  99. #define BCC68000        4
  100. #define DBCC            5
  101. #define PCLEA        6
  102. #define ABSREL        7
  103. #define IMMREL        8
  104.  
  105. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  106.    on the 68000.  The 68000 doesn't support long branches with branchs */
  107.  
  108. /* ABSREL (nice name;-)) is used in small-code/-data mode, it might be 
  109.  * implemented base-relative (a4), pc-relative, or base-rel with an extra
  110.  * add instruction to add the base-register
  111.  *
  112.  * IMMREL is the analogous mode for immediate addressing of variables. This
  113.  * one can lead into situations, where a replacement is not possible:
  114.  * addl #foo,a0
  115.  * can't be made pc-relative, if foo is in the text segment */
  116.  
  117.  
  118. /* This table desribes how you change sizes for the various types of variable
  119.    size expressions.  This version only supports two kinds. */
  120.  
  121. /* Note that calls to frag_var need to specify the maximum expansion needed */
  122. /* This is currently 10 bytes for DBCC */
  123.  
  124. /* The fields are:
  125.     How far Forward this mode will reach:
  126.     How far Backward this mode will reach:
  127.     How many bytes this mode will add to the size of the frag
  128.     Which mode to go to if the offset won't fit in this one
  129.  */
  130. const relax_typeS
  131. md_relax_table[] = {
  132. { 1,        1,        0,    0 },    /* First entries aren't used */
  133. { 1,        1,        0,    0 },    /* For no good reason except */
  134. { 1,        1,        0,    0 },    /* that the VAX doesn't either */
  135. { 1,        1,        0,    0 },
  136.  
  137. { (127),    (-128),        0,    TAB(BRANCH,SHORT)},
  138. { (32767),    (-32768),    2,    TAB(BRANCH,LONG) },
  139. { 0,        0,        4,    0 },
  140. { 1,        1,        0,    0 },
  141.  
  142. { 1,        1,        0,    0 },    /* FBRANCH doesn't come BYTE */
  143. { (32767),    (-32768),    2,    TAB(FBRANCH,LONG)},
  144. { 0,        0,        4,    0 },
  145. { 1,        1,        0,    0 },
  146.  
  147. { 1,        1,        0,    0 },    /* PCREL doesn't come BYTE */
  148. { (32767),    (-32768),    2,    TAB(PCREL,LONG)},
  149. { 0,        0,        4,    0 },
  150. { 1,        1,        0,    0 },
  151.  
  152. { (127),    (-128),        0,    TAB(BCC68000,SHORT)},
  153. { (32767),    (-32768),    2,    TAB(BCC68000,LONG) },
  154. { 0,        0,        6,    0 },    /* jmp long space */
  155. { 1,        1,        0,    0 },
  156.  
  157. { 1,        1,        0,    0 },    /* DBCC doesn't come BYTE */
  158. { (32767),    (-32768),    2,    TAB(DBCC,LONG) },
  159. { 0,        0,        10,    0 },    /* bra/jmp long space */
  160. { 1,        1,        0,    0 },
  161.  
  162. { 1,        1,        0,    0 },    /* PCLEA doesn't come BYTE */
  163. { 32767,    -32768,        2,    TAB(PCLEA,LONG) },
  164. { 0,        0,        6,    0 },
  165. { 1,        1,        0,    0 },
  166.  
  167. { 127,        -128,        0,    0 },
  168. { 32767,    -32768,        2,    TAB(ABSREL,LONG) },
  169. { 0,        0,        6,    0 },
  170. { 1,        1,        0,    0 },
  171.  
  172. { 127,        -128,        0,    0 },
  173. { 32767,    -32768,        2,    TAB(IMMREL,LONG) },
  174. { 0,        0,        6,    0 },
  175. { 1,        1,        0,    0 },
  176.  
  177. };
  178.  
  179. void    s_data1(),    s_data2(),    s_even(),    s_space();
  180. void    s_proc(),    float_cons();
  181.  
  182. /* These are the machine dependent pseudo-ops.  These are included so
  183.    the assembler can work on the output from the SUN C compiler, which
  184.    generates these.
  185.  */
  186.  
  187. /* This table describes all the machine specific pseudo-ops the assembler
  188.    has to support.  The fields are:
  189.        pseudo-op name without dot
  190.       function to call to execute this pseudo-op
  191.       Integer arg to pass to the function
  192.  */
  193. const pseudo_typeS md_pseudo_table[] = {
  194.     { "data1",    s_data1,    0    },
  195.     { "data2",    s_data2,    0    },
  196.     { "even",    s_even,        0    },
  197.     { "skip",    s_space,    0    },
  198.     { "proc",    s_proc,        0    },
  199.     { 0,        0,        0    }
  200. };
  201.  
  202.  
  203. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  204. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  205.  
  206. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  207. #define isubyte(x)    ((x)>=0 && (x)<=255)
  208. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  209. #define isuword(x)    ((x)>=0 && (x)<=65535)
  210.  
  211. #define isbyte(x)    ((x)>=-128 && (x)<=255)
  212. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  213. #define islong(x)    (1)
  214.  
  215. extern char *input_line_pointer;
  216.  
  217. /* Operands we can parse:  (And associated modes)
  218.  
  219. numb:    8 bit num
  220. numw:    16 bit num
  221. numl:    32 bit num
  222. dreg:    data reg 0-7
  223. reg:    address or data register
  224. areg:    address register
  225. apc:    address register, PC, ZPC or empty string
  226. num:    16 or 32 bit num
  227. num2:    like num
  228. sz:    w or l        if omitted, l assumed
  229. scale:    1 2 4 or 8    if omitted, 1 assumed
  230.  
  231. 7.4 IMMED #num                --> NUM
  232. 0.? DREG  dreg                --> dreg
  233. 1.? AREG  areg                --> areg
  234. 2.? AINDR areg@                --> *(areg)
  235. 3.? AINC  areg@+            --> *(areg++)
  236. 4.? ADEC  areg@-            --> *(--areg)
  237. 5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  238. 6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  239. 6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  240. 6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  241. 6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  242. 6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  243. 6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  244. 6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  245. 7.0 ABSL  num:sz            --> *(num)
  246.           num                --> *(num) (sz L assumed)
  247. *** MSCR  otherreg            --> Magic
  248. With -l option
  249. 5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  250.  
  251. examples:
  252.     #foo    #0x35    #12
  253.     d2
  254.     a4
  255.     a3@
  256.     a5@+
  257.     a6@-
  258.     a2@(12)    pc@(14)
  259.     a1@(5,d2:w:1)    @(45,d6:l:4)
  260.     pc@(a2)        @(d4)
  261.     etc . . .
  262.  
  263.  
  264. #name@(numw)    -->turn into PC rel mode
  265. apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  266.  
  267. */
  268.  
  269. #define IMMED    1
  270. #define DREG    2
  271. #define AREG    3
  272. #define AINDR    4
  273. #define ADEC    5
  274. #define AINC    6
  275. #define AOFF    7
  276. #define AINDX    8
  277. #define APODX    9
  278. #define AMIND    10
  279. #define APRDX    11
  280. #define ABSL    12
  281. #define MSCR    13
  282. #define REGLST    14
  283.  
  284. #define FAIL    0
  285. #define OK    1
  286.  
  287. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  288.    8-15==addr reg for operands that take both types */
  289. #define DATA    1        /*   1- 8 == data registers 0-7 */
  290. #define ADDR    (DATA+8)    /*   9-16 == address regs 0-7 */
  291. #define FPREG    (ADDR+8)    /*  17-24 Eight FP registers */
  292. #define COPNUM    (FPREG+8)    /*  25-32 Co-processor #1-#8 */
  293.  
  294. #define PC    (COPNUM+8)    /*  33 Program counter */
  295. #define ZPC    (PC+1)        /*  34 Hack for Program space, but 0 addressing */
  296. #define SR    (ZPC+1)        /*  35 Status Reg */
  297. #define CCR    (SR+1)        /*  36 Condition code Reg */
  298.  
  299. /* These have to be in order for the movec instruction to work. */
  300. #define USP    (CCR+1)        /*  37 User Stack Pointer */
  301. #define ISP    (USP+1)        /*  38 Interrupt stack pointer */
  302. #define SFC    (ISP+1)        /*  39 */
  303. #define DFC    (SFC+1)        /*  40 */
  304. #define CACR    (DFC+1)        /*  41 */
  305. #define VBR    (CACR+1)    /*  42 */
  306. #define CAAR    (VBR+1)        /*  43 */
  307. #define MSP    (CAAR+1)    /*  44 */
  308.  
  309. #define FPI    (MSP+1)        /* 45 */
  310. #define FPS    (FPI+1)        /* 46 */
  311. #define FPC    (FPS+1)        /* 47 */
  312. /*
  313.  * these defines should be in m68k.c but
  314.  * i put them here to keep all the m68851 stuff
  315.  * together -rab
  316.  * JF--Make sure these #s don't clash with the ones in m68k.c
  317.  * That would be BAD.
  318.  */
  319. #define TC    (FPC+1)        /* 48 */
  320. #define DRP    (TC+1)        /* 49 */
  321. #define SRP    (DRP+1)        /* 50 */
  322. #define CRP    (SRP+1)        /* 51 */
  323. #define CAL    (CRP+1)        /* 52 */
  324. #define VAL    (CAL+1)        /* 53 */
  325. #define SCC    (VAL+1)        /* 54 */
  326. #define AC    (SCC+1)        /* 55 */
  327. #define BAD    (AC+1)        /* 56,57,58,59, 60,61,62,63 */
  328. #define BAC    (BAD+8)        /* 64,65,66,67, 68,69,70,71 */
  329. #define PSR    (BAC+8)        /* 72 */
  330. #define PCSR    (PSR+1)        /* 73 */
  331.  
  332.  
  333. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  334. /* I think. . .  */
  335.  
  336. #define    SP    ADDR+7
  337.  
  338. /* JF these tables here are for speed at the expense of size */
  339. /* You can replace them with the #if 0 versions if you really
  340.    need space and don't mind it running a bit slower */
  341.  
  342. static char mklower_table[256];
  343. #define mklower(c) (mklower_table[(unsigned char)(c)])
  344. static char notend_table[256];
  345. static char alt_notend_table[256];
  346. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  347.  alt_notend_table[(unsigned char)(s[1])])))
  348.  
  349. #if 0
  350. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  351. #endif
  352.  
  353.  
  354. struct m68k_exp {
  355.     char    *e_beg;
  356.     char    *e_end;
  357.     expressionS e_exp;
  358.     short    e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  359.     short    e_baserel;    /* if the expression is base relative */
  360. };
  361.  
  362. /* Internal form of an operand.  */
  363. struct m68k_op {
  364.     char    *error;        /* Couldn't parse it */
  365.     int    mode;        /* What mode this instruction is in.  */
  366.     unsigned long int    reg;        /* Base register */
  367.     struct m68k_exp *con1;
  368.     int    ireg;        /* Index register */
  369.     int    isiz;        /* 0==unspec  1==byte(?)  2==short  3==long  */
  370.     int    imul;        /* Multipy ireg by this (1,2,4,or 8) */
  371.     struct    m68k_exp *con2;
  372. };
  373.  
  374. /* internal form of a 68020 instruction */
  375. struct m68_it {
  376.     char    *error;
  377.     char    *args;        /* list of opcode info */
  378.     int    numargs;
  379.  
  380.     int    numo;        /* Number of shorts in opcode */
  381.     short    opcode[11];
  382.  
  383.     struct m68k_op operands[6];
  384.  
  385.     int    nexp;        /* number of exprs in use */
  386.     struct m68k_exp exprs[4];
  387.  
  388.     int    nfrag;        /* Number of frags we have to produce */
  389.     struct {
  390.         int fragoff;    /* Where in the current opcode[] the frag ends */
  391.         symbolS *fadd;
  392.         long int foff;
  393.         int fragty;
  394.     } fragb[4];
  395.  
  396.     int    nrel;        /* Num of reloc strucs in use */
  397.     struct    {
  398.         int    n;
  399.         symbolS    *add,
  400.             *sub;
  401.         long int off;
  402.         char    wid;
  403.         char    pcrel;
  404.         char    baserel;
  405.     } reloc[5];        /* Five is enough??? */
  406. };
  407.  
  408. struct m68_it the_ins;        /* the instruction being assembled */
  409.  
  410.  
  411. /* Macros for adding things to the m68_it struct */
  412.  
  413. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  414.  
  415. /* Like addword, but goes BEFORE general operands */
  416. #define insop(w)    {int z;\
  417.  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  418.    the_ins.opcode[z]=the_ins.opcode[z-1];\
  419.  for(z=0;z<the_ins.nrel;z++)\
  420.    the_ins.reloc[z].n+=2;\
  421.  the_ins.opcode[opcode->m_codenum]=w;\
  422.  the_ins.numo++;\
  423. }
  424.  
  425.  
  426. #define add_exp(beg,end) (\
  427.     the_ins.exprs[the_ins.nexp].e_beg=beg,\
  428.     the_ins.exprs[the_ins.nexp].e_end=end,\
  429.     &the_ins.exprs[the_ins.nexp++]\
  430. )
  431.  
  432.  
  433. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  434. #define add_fix(width,exp,pc_rel,base_rel) {\
  435.     the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  436.         (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  437.     the_ins.reloc[the_ins.nrel].add=adds((exp));\
  438.     the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  439.     the_ins.reloc[the_ins.nrel].off=offs((exp));\
  440.     the_ins.reloc[the_ins.nrel].wid=width;\
  441.     the_ins.reloc[the_ins.nrel].pcrel=pc_rel;\
  442.     the_ins.reloc[the_ins.nrel++].baserel=base_rel;\
  443.     DP(("add_fix, bsr = %d\n",base_rel));\
  444. }
  445.  
  446. #define add_frag(add,off,type)  {\
  447.     the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  448.     the_ins.fragb[the_ins.nfrag].fadd=add;\
  449.     the_ins.fragb[the_ins.nfrag].foff=off;\
  450.     the_ins.fragb[the_ins.nfrag++].fragty=type;\
  451. }
  452.  
  453. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  454.  
  455. #define seg(exp)    ((exp)->e_exp.X_seg)
  456. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  457. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  458. #define offs(exp)    ((exp)->e_exp.X_add_number)
  459.  
  460.  
  461. struct m68_incant {
  462.     char *m_operands;
  463.     unsigned long m_opcode;
  464.     short m_opnum;
  465.     short m_codenum;
  466.     struct m68_incant *m_next;
  467. };
  468.  
  469. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  470. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  471.  
  472.  
  473. /* JF modified this to handle cases where the first part of a symbol name
  474.    looks like a register */
  475.  
  476. int
  477. m68k_reg_parse(ccp)
  478. register char **ccp;
  479. {
  480.     register char c1,
  481.         c2,
  482.         c3,
  483.         c4;
  484.     register int n = 0,
  485.         ret = FAIL;
  486.  
  487.     c1=mklower(ccp[0][0]);
  488. #ifdef REGISTER_PREFIX
  489.     if(c1!=REGISTER_PREFIX)
  490.         return FAIL;
  491.     c1=mklower(ccp[0][1]);
  492.     c2=mklower(ccp[0][2]);
  493.     c3=mklower(ccp[0][3]);
  494.     c4=mklower(ccp[0][4]);
  495. #else
  496.     c2=mklower(ccp[0][1]);
  497.     c3=mklower(ccp[0][2]);
  498.     c4=mklower(ccp[0][3]);
  499. #endif
  500.     switch(c1) {
  501.     case 'a':
  502.         if(c2>='0' && c2<='7') {
  503.             n=2;
  504.             ret=ADDR+c2-'0';
  505.         }
  506. #ifdef m68851
  507.         else if (c2 == 'c') {
  508.             n = 2;
  509.             ret = AC;
  510.         }
  511. #endif
  512.         break;
  513. #ifdef m68851
  514.     case 'b':
  515.         if (c2 == 'a') {
  516.             if (c3 == 'd') {
  517.                 if (c4 >= '0' && c4 <= '7') {
  518.                     n = 4;
  519.                     ret = BAD + c4 - '0';
  520.                 }
  521.             }
  522.             if (c3 == 'c') {
  523.                 if (c4 >= '0' && c4 <= '7') {
  524.                     n = 4;
  525.                     ret = BAC + c4 - '0';
  526.                 }
  527.             }
  528.         }
  529.         break;
  530. #endif
  531.     case 'c':
  532. #ifdef m68851
  533.         if (c2 == 'a' && c3 == 'l') {
  534.             n = 3;
  535.             ret = CAL;
  536.         } else
  537. #endif
  538.             /* This supports both CCR and CC as the ccr reg. */
  539.         if(c2=='c' && c3=='r') {
  540.             n=3;
  541.             ret = CCR;
  542.         } else if(c2=='c') {
  543.             n=2;
  544.             ret = CCR;
  545.         } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  546.             n=4;
  547.             ret = c3=='a' ? CAAR : CACR;
  548.         }
  549. #ifdef m68851
  550.         else if (c2 == 'r' && c3 == 'p') {
  551.             n = 3;
  552.             ret = (CRP);
  553.         }
  554. #endif
  555.         break;
  556.     case 'd':
  557.         if(c2>='0' && c2<='7') {
  558.             n=2;
  559.             ret = DATA+c2-'0';
  560.         } else if(c2=='f' && c3=='c') {
  561.             n=3;
  562.             ret = DFC;
  563.         }
  564. #ifdef m68851
  565.         else if (c2 == 'r' && c3 == 'p') {
  566.             n = 3;
  567.             ret = (DRP);
  568.         }
  569. #endif
  570.         break;
  571.     case 'f':
  572.         if(c2=='p') {
  573.             if(c3>='0' && c3<='7') {
  574.                 n=3;
  575.                 ret = FPREG+c3-'0';
  576.                 if(c4==':')
  577.                     ccp[0][3]=',';
  578.             } else if(c3=='i') {
  579.                 n=3;
  580.                 ret = FPI;
  581.             } else if(c3=='s') {
  582.                 n= (c4 == 'r' ? 4 : 3);
  583.                 ret = FPS;
  584.             } else if(c3=='c') {
  585.                 n= (c4 == 'r' ? 4 : 3);
  586.                 ret = FPC;
  587.             }
  588.         }
  589.         break;
  590.     case 'i':
  591.         if(c2=='s' && c3=='p') {
  592.             n=3;
  593.             ret = ISP;
  594.         }
  595.         break;
  596.     case 'm':
  597.         if(c2=='s' && c3=='p') {
  598.             n=3;
  599.             ret = MSP;
  600.         }
  601.         break;
  602.     case 'p':
  603.         if(c2=='c') {
  604. #ifdef m68851
  605.             if(c3 == 's' && c4=='r') {
  606.                 n=4;
  607.                 ret = (PCSR);
  608.             } else
  609. #endif
  610.             {
  611.                 n=2;
  612.                 ret = PC;
  613.             }
  614.         }
  615. #ifdef m68851
  616.         else if (c2 == 's' && c3 == 'r') {
  617.             n = 3;
  618.             ret = (PSR);
  619.         }
  620. #endif
  621.         break;
  622.     case 's':
  623. #ifdef m68851
  624.         if (c2 == 'c' && c3 == 'c') {
  625.             n = 3;
  626.             ret = (SCC);
  627.         } else if (c2 == 'r' && c3 == 'p') {
  628.             n = 3;
  629.             ret = (SRP);
  630.         } else
  631. #endif
  632.         if(c2=='r') {
  633.             n=2;
  634.             ret = SR;
  635.         } else if(c2=='p') {
  636.             n=2;
  637.             ret = ADDR+7;
  638.         } else if(c2=='f' && c3=='c') {
  639.             n=3;
  640.             ret = SFC;
  641.         }
  642.         break;
  643. #ifdef m68851
  644.     case 't':
  645.         if(c2 == 'c') {
  646.             n=2;
  647.             ret=TC;
  648.         }
  649.         break;
  650. #endif
  651.     case 'u':
  652.         if(c2=='s' && c3=='p') {
  653.             n=3;
  654.             ret = USP;
  655.         }
  656.         break;
  657.     case 'v':
  658. #ifdef m68851
  659.         if (c2 == 'a' && c3 == 'l') {
  660.             n = 3;
  661.             ret = (VAL);
  662.         } else
  663. #endif
  664.         if(c2=='b' && c3=='r') {
  665.             n=3;
  666.             ret = VBR;
  667.         }
  668.         break;
  669.     case 'z':
  670.         if(c2=='p' && c3=='c') {
  671.             n=3;
  672.             ret = ZPC;
  673.         }
  674.         break;
  675.     default:
  676.         break;
  677.     }
  678.     if(n) {
  679. #ifdef REGISTER_PREFIX
  680.         n++;
  681. #endif
  682.         if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  683.             ret=FAIL;
  684.         else
  685.             ccp[0]+=n;
  686.     } else
  687.         ret = FAIL;
  688.     return ret;
  689. }
  690.  
  691. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  692.  
  693. int
  694. m68k_ip_op(str,opP)
  695. char *str;
  696. register struct m68k_op *opP;
  697. {
  698.     char    *strend;
  699.     long    i;
  700.     char    *parse_index();
  701.  
  702.     if(*str==' ')
  703.         str++;
  704.         /* Find the end of the string */
  705.     if(!*str) {
  706.         /* Out of gas */
  707.         opP->error="Missing operand";
  708.         return FAIL;
  709.     }
  710.     for(strend=str;*strend;strend++)
  711.         ;
  712.     --strend;
  713.  
  714.         /* Guess what:  A constant.  Shar and enjoy */
  715.     if(*str=='#') {
  716.         str++;
  717.         opP->con1=add_exp(str,strend);
  718.         opP->mode=IMMED;
  719.         return OK;
  720.     }
  721.     i=m68k_reg_parse(&str);
  722.     if((i==FAIL || *str!='\0') && *str!='@') {
  723.         char *stmp;
  724.  
  725.         if(i!=FAIL && (*str=='/' || *str=='-')) {
  726.             opP->mode=REGLST;
  727.             return get_regs(i,str,opP);
  728.         }
  729.         if(stmp=index(str,'@')) {
  730.             opP->con1=add_exp(str,stmp-1);
  731.             if(stmp==strend) {
  732.                 opP->mode=AINDX;
  733.                 return OK;
  734.             }
  735.             stmp++;
  736.             if(*stmp++!='(' || *strend--!=')') {
  737.                 opP->error="Malformed operand";
  738.                 return FAIL;
  739.             }
  740.             i=try_index(&stmp,opP);
  741.             opP->con2=add_exp(stmp,strend);
  742.             if(i==FAIL) opP->mode=AMIND;
  743.             else opP->mode=APODX;
  744.             return OK;
  745.         }
  746.         opP->mode=ABSL;
  747.         opP->con1=add_exp(str,strend);
  748.         return OK;
  749.     }
  750.     opP->reg=i;
  751.     if(*str=='\0') {
  752.         if(i>=DATA+0 && i<=DATA+7)
  753.             opP->mode=DREG;
  754.         else if(i>=ADDR+0 && i<=ADDR+7)
  755.             opP->mode=AREG;
  756.         else
  757.             opP->mode=MSCR;
  758.         return OK;
  759.     }
  760.     if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {    /* Can't indirect off non address regs */
  761.         opP->error="Invalid indirect register";
  762.         return FAIL;
  763.     }
  764.     if(*str!='@')
  765.         abort();
  766.     str++;
  767.     switch(*str) {
  768.     case '\0':
  769.         opP->mode=AINDR;
  770.         return OK;
  771.     case '-':
  772.         opP->mode=ADEC;
  773.         return OK;
  774.     case '+':
  775.         opP->mode=AINC;
  776.         return OK;
  777.     case '(':
  778.         str++;
  779.         break;
  780.     default:
  781.         opP->error="Junk after indirect";
  782.         return FAIL;
  783.     }
  784.         /* Some kind of indexing involved.  Lets find out how bad it is */
  785.     i=try_index(&str,opP);
  786.         /* Didn't start with an index reg, maybe its offset or offset,reg */
  787.     if(i==FAIL) {
  788.         char *beg_str;
  789.  
  790.         beg_str=str;
  791.         for(i=1;i;) {
  792.             switch(*str++) {
  793.             case '\0':
  794.                 opP->error="Missing )";
  795.                 return FAIL;
  796.             case ',': i=0; break;
  797.             case '(': i++; break;
  798.             case ')': --i; break;
  799.             }
  800.         }
  801.         /* if(str[-3]==':') {
  802.             int siz;
  803.  
  804.             switch(str[-2]) {
  805.             case 'b':
  806.             case 'B':
  807.                 siz=1;
  808.                 break;
  809.             case 'w':
  810.             case 'W':
  811.                 siz=2;
  812.                 break;
  813.             case 'l':
  814.             case 'L':
  815.                 siz=3;
  816.                 break;
  817.             default:
  818.                 opP->error="Specified size isn't :w or :l";
  819.                 return FAIL;
  820.             }
  821.             opP->con1=add_exp(beg_str,str-4);
  822.             opP->con1->e_siz=siz;
  823.         } else */
  824.             opP->con1=add_exp(beg_str,str-2);
  825.             /* Should be offset,reg */
  826.         if(str[-1]==',') {
  827.             i=try_index(&str,opP);
  828.             if(i==FAIL) {
  829.                 opP->error="Malformed index reg";
  830.                 return FAIL;
  831.             }
  832.         }
  833.     }
  834.         /* We've now got offset)   offset,reg)   or    reg) */
  835.  
  836.     if(*str=='\0') {
  837.         /* Th-the-thats all folks */
  838.         if(opP->reg==FAIL) opP->mode=AINDX;    /* Other form of indirect */
  839.         else if(opP->ireg==FAIL) opP->mode=AOFF;
  840.         else opP->mode=AINDX;
  841.         return OK;
  842.     }
  843.         /* Next thing had better be another @ */
  844.     if(*str!='@' || str[1]!='(') {
  845.         opP->error="junk after indirect";
  846.         return FAIL;
  847.     }
  848.     str+=2;
  849.     if(opP->ireg!=FAIL) {
  850.         opP->mode=APRDX;
  851.         i=try_index(&str,opP);
  852.         if(i!=FAIL) {
  853.             opP->error="Two index registers!  not allowed!";
  854.             return FAIL;
  855.         }
  856.     } else
  857.         i=try_index(&str,opP);
  858.     if(i==FAIL) {
  859.         char *beg_str;
  860.  
  861.         beg_str=str;
  862.         for(i=1;i;) {
  863.             switch(*str++) {
  864.             case '\0':
  865.                 opP->error="Missing )";
  866.                 return FAIL;
  867.             case ',': i=0; break;
  868.             case '(': i++; break;
  869.             case ')': --i; break;
  870.             }
  871.         }
  872.         opP->con2=add_exp(beg_str,str-2);
  873.         if(str[-1]==',') {
  874.             if(opP->ireg!=FAIL) {
  875.                 opP->error="Can't have two index regs";
  876.                 return FAIL;
  877.             }
  878.             i=try_index(&str,opP);
  879.             if(i==FAIL) {
  880.                 opP->error="malformed index reg";
  881.                 return FAIL;
  882.             }
  883.             opP->mode=APODX;
  884.         } else if(opP->ireg!=FAIL)
  885.             opP->mode=APRDX;
  886.         else
  887.             opP->mode=AMIND;
  888.     } else
  889.         opP->mode=APODX;
  890.     if(*str!='\0') {
  891.         opP->error="Junk after indirect";
  892.         return FAIL;
  893.     }
  894.     return OK;
  895. }
  896.  
  897. int
  898. try_index(s,opP)
  899. char **s;
  900. struct m68k_op *opP;
  901. {
  902.     register int    i;
  903.     char    *ss;
  904. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  905.  
  906.     ss= *s;
  907.     /* SKIP_W(); */
  908.     i=m68k_reg_parse(&ss);
  909.     if(!(i>=DATA+0 && i<=ADDR+7)) {    /* if i is not DATA or ADDR reg */
  910.         *s=ss;
  911.         return FAIL;
  912.     }
  913.     opP->ireg=i;
  914.     /* SKIP_W(); */
  915.     if(*ss==')') {
  916.         opP->isiz=0;
  917.         opP->imul=1;
  918.         SKIP_W();
  919.         *s=ss;
  920.         return OK;
  921.     }
  922.     /* to make life a bit easier for Motorola freaks, allow . as well as
  923.      * : as size introducer */
  924.     if(*ss!=':' && *ss != '.') {
  925.         opP->error="Missing : in index register";
  926.         *s=ss;
  927.         return FAIL;
  928.     }
  929.     SKIP_W();
  930.     switch(*ss) {
  931.     case 'w':
  932.     case 'W':
  933.         opP->isiz=2;
  934.         break;
  935.     case 'l':
  936.     case 'L':
  937.         opP->isiz=3;
  938.         break;
  939.     default:
  940.         opP->error="Index register size spec not :w or :l";
  941.         *s=ss;
  942.         return FAIL;
  943.     }
  944.     SKIP_W();
  945.     if(*ss==':') {
  946.         SKIP_W();
  947.         switch(*ss) {
  948.         case '1':
  949.         case '2':
  950.         case '4':
  951.         case '8':
  952.             opP->imul= *ss-'0';
  953.             break;
  954.         default:
  955.             opP->error="index multiplier not 1, 2, 4 or 8";
  956.             *s=ss;
  957.             return FAIL;
  958.         }
  959.         SKIP_W();
  960.     } else opP->imul=1;
  961.     if(*ss!=')') {
  962.         opP->error="Missing )";
  963.         *s=ss;
  964.         return FAIL;
  965.     }
  966.     SKIP_W();
  967.     *s=ss;
  968.     return OK;
  969. }
  970.  
  971. #ifdef TEST1    /* TEST1 tests m68k_ip_op(), which parses operands */
  972. main()
  973. {
  974.     char buf[128];
  975.     struct m68k_op thark;
  976.  
  977.     for(;;) {
  978.         if(!gets(buf))
  979.             break;
  980.         bzero(&thark,sizeof(thark));
  981.         if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  982.         if(thark.error)
  983.             printf("op1 error %s in %s\n",thark.error,buf);
  984.         printf("mode %d, reg %d, ",thark.mode,thark.reg);
  985.         if(thark.b_const)
  986.             printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  987.         printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  988.         if(thark.b_iadd)
  989.             printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  990.         printf("\n");
  991.     }
  992.     exit(0);
  993. }
  994.  
  995. #endif
  996.  
  997.  
  998. static struct hash_control*   op_hash = NULL;    /* handle of the OPCODE hash table
  999.                    NULL means any use before m68_ip_begin()
  1000.                    will crash */
  1001.  
  1002.  
  1003. /*
  1004.  *        m 6 8 _ i p ( )
  1005.  *
  1006.  * This converts a string into a 68k instruction.
  1007.  * The string must be a bare single instruction in sun format
  1008.  * with RMS-style 68020 indirects
  1009.  *  (example:  )
  1010.  *
  1011.  * It provides some error messages: at most one fatal error message (which
  1012.  * stops the scan) and at most one warning message for each operand.
  1013.  * The 68k instruction is returned in exploded form, since we have no
  1014.  * knowledge of how you parse (or evaluate) your expressions.
  1015.  * We do however strip off and decode addressing modes and operation
  1016.  * mnemonic.
  1017.  *
  1018.  * This function's value is a string. If it is not "" then an internal
  1019.  * logic error was found: read this code to assign meaning to the string.
  1020.  * No argument string should generate such an error string:
  1021.  * it means a bug in our code, not in the user's text.
  1022.  *
  1023.  * You MUST have called m68_ip_begin() once and m68_ip_end() never before using
  1024.  * this function.
  1025.  */
  1026.  
  1027. /* JF this function no longer returns a useful value.  Sorry */
  1028. void
  1029. m68_ip (instring)
  1030. char    *instring;
  1031. {
  1032.     register char *p;
  1033.     register struct m68k_op *opP;
  1034.     register struct m68_incant *opcode;
  1035.     register char *s;
  1036.     register int tmpreg,
  1037.         baseo,
  1038.         outro,
  1039.         nextword;
  1040.     int    siz1,
  1041.         siz2;
  1042.     char    c;
  1043.     int    losing;
  1044.     int    opsfound;
  1045.     char    *crack_operand();
  1046.     LITTLENUM_TYPE words[6];
  1047.     LITTLENUM_TYPE *wordp;
  1048.  
  1049.     if (*instring == ' ')
  1050.         instring++;            /* skip leading whitespace */
  1051.  
  1052.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1053.      or exactly 1 space. */
  1054.     for (p = instring; *p != '\0'; p++)
  1055.         if (*p == ' ')
  1056.             break;
  1057.  
  1058.  
  1059.     if (p == instring) {
  1060.         the_ins.error = "No operator";
  1061.         the_ins.opcode[0] = NULL;
  1062.         /* the_ins.numo=1; */
  1063.         return;
  1064.     }
  1065.  
  1066.   /* p now points to the end of the opcode name, probably whitespace.
  1067.      make sure the name is null terminated by clobbering the whitespace,
  1068.      look it up in the hash table, then fix it back. */   
  1069.     c = *p;
  1070.     *p = '\0';
  1071.     opcode = (struct m68_incant *)hash_find (op_hash, instring);
  1072.     *p = c;
  1073.  
  1074.     if (opcode == NULL) {
  1075.         the_ins.error = "Unknown operator";
  1076.         the_ins.opcode[0] = NULL;
  1077.         /* the_ins.numo=1; */
  1078.         return;
  1079.     }
  1080.  
  1081.   /* found a legitimate opcode, start matching operands */
  1082.     for(opP= &the_ins.operands[0];*p;opP++) {
  1083.         p = crack_operand (p, opP);
  1084.         if(opP->error) {
  1085.             the_ins.error=opP->error;
  1086.             return;
  1087.         }
  1088.     }
  1089.  
  1090.     opsfound=opP- &the_ins.operands[0];
  1091.     /* This ugly hack is to support the floating pt opcodes in their standard form */
  1092.     /* Essentially, we fake a first enty of type COP#1 */
  1093.     if(opcode->m_operands[0]=='I') {
  1094.         int    n;
  1095.  
  1096.         for(n=opsfound;n>0;--n)
  1097.             the_ins.operands[n]=the_ins.operands[n-1];
  1098.  
  1099.         /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  1100.         bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  1101.         the_ins.operands[0].mode=MSCR;
  1102.         the_ins.operands[0].reg=COPNUM;        /* COP #1 */
  1103.         opsfound++;
  1104.     }
  1105.         /* We've got the operands.  Find an opcode that'll
  1106.            accept them */
  1107.     for(losing=0;;) {
  1108.         if(opsfound!=opcode->m_opnum)
  1109.             losing++;
  1110.         else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  1111.                 /* Warning: this switch is huge! */
  1112.                 /* I've tried to organize the cases into  this order:
  1113.                    non-alpha first, then alpha by letter.  lower-case goes directly
  1114.                    before uppercase counterpart. */
  1115.                 /* Code with multiple case ...: gets sorted by the lowest case ...
  1116.                    it belongs to.  I hope this makes sense. */
  1117.             switch(*s) {
  1118.             case '!':
  1119.                 if(opP->mode==MSCR || opP->mode==IMMED ||
  1120.  opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1121.                     losing++;
  1122.                 break;
  1123.  
  1124.             case '#':
  1125.                 if(opP->mode!=IMMED)
  1126.                     losing++;
  1127.                 else {
  1128.                     long t;
  1129.  
  1130.                     t=get_num(opP->con1,80);
  1131.                     if(s[1]=='b' && !isbyte(t))
  1132.                         losing++;
  1133.                     else if(s[1]=='w' && !isword(t))
  1134.                         losing++;
  1135.                 }
  1136.                 break;
  1137.  
  1138.             case '^':
  1139.             case 'T':
  1140.                 if(opP->mode!=IMMED)
  1141.                     losing++;
  1142.                 break;
  1143.  
  1144.             case '$':
  1145.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1146.  opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1147.                     losing++;
  1148.                 break;
  1149.  
  1150.             case '%':
  1151.                 if(opP->mode==MSCR || opP->reg==PC ||
  1152.  opP->reg==ZPC || opP->mode==REGLST)
  1153.                     losing++;
  1154.                 break;
  1155.  
  1156.  
  1157.             case '&':
  1158.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1159.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  1160.  opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1161.                     losing++;
  1162.                 break;
  1163.  
  1164.             case '*':
  1165.                 if(opP->mode==MSCR || opP->mode==REGLST)
  1166.                     losing++;
  1167.                 break;
  1168.  
  1169.             case '+':
  1170.                 if(opP->mode!=AINC)
  1171.                     losing++;
  1172.                 break;
  1173.  
  1174.             case '-':
  1175.                 if(opP->mode!=ADEC)
  1176.                     losing++;
  1177.                 break;
  1178.  
  1179.             case '/':
  1180.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1181.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  1182.                     losing++;
  1183.                 break;
  1184.  
  1185.             case ';':
  1186.                 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  1187.                     losing++;
  1188.                 break;
  1189.  
  1190.             case '?':
  1191.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1192.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1193.  opP->reg==ZPC || opP->mode==REGLST)
  1194.                     losing++;
  1195.                 break;
  1196.  
  1197.             case '@':
  1198.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1199.  opP->mode==IMMED || opP->mode==REGLST)
  1200.                     losing++;
  1201.                 break;
  1202.  
  1203.             case '~':        /* For now! (JF FOO is this right?) */
  1204.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1205.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1206.                     losing++;
  1207.                 break;
  1208.  
  1209.             case 'A':
  1210.                 if(opP->mode!=AREG)
  1211.                     losing++;
  1212.                 break;
  1213.  
  1214.             case 'B':    /* FOO */
  1215.                 if(opP->mode!=ABSL)
  1216.                     losing++;
  1217.                 break;
  1218.  
  1219.             case 'C':
  1220.                 if(opP->mode!=MSCR || opP->reg!=CCR)
  1221.                     losing++;
  1222.                 break;
  1223.  
  1224.             case 'd':    /* FOO This mode is a KLUDGE!! */
  1225.                 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1226.  opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1227.                     losing++;
  1228.                 break;
  1229.  
  1230.             case 'D':
  1231.                 if(opP->mode!=DREG)
  1232.                     losing++;
  1233.                 break;
  1234.  
  1235.             case 'F':
  1236.                 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1237.                     losing++;
  1238.                 break;
  1239.  
  1240.             case 'I':
  1241.                 if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1242.  opP->reg>=COPNUM+7)
  1243.                     losing++;
  1244.                 break;
  1245.  
  1246.             case 'J':
  1247.                 if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1248.                     losing++;
  1249.                 break;
  1250.  
  1251.             case 'k':
  1252.                 if(opP->mode!=IMMED)
  1253.                     losing++;
  1254.                 break;
  1255.  
  1256.             case 'l':
  1257.             case 'L':
  1258.                 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1259.                     if(s[1]=='8')
  1260.                         losing++;
  1261.                     else {
  1262.                         opP->mode=REGLST;
  1263.                         opP->reg=1<<(opP->reg-DATA);
  1264.                     }
  1265.                 } else if(opP->mode!=REGLST) {
  1266.                     losing++;
  1267.                 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1268.                     losing++;
  1269.                 else if(s[1]=='3' && opP->reg&0x7000000)
  1270.                     losing++;
  1271.                 break;
  1272.  
  1273.             case 'M':
  1274.                 if(opP->mode!=IMMED)
  1275.                     losing++;
  1276.                 else {
  1277.                     long t;
  1278.  
  1279.                     t=get_num(opP->con1,80);
  1280.                     if(!issbyte(t) || isvar(opP->con1))
  1281.                         losing++;
  1282.                 }
  1283.                 break;
  1284.  
  1285.             case 'O':
  1286.                 if(opP->mode!=DREG && opP->mode!=IMMED)
  1287.                     losing++;
  1288.                 break;
  1289.  
  1290.             case 'Q':
  1291.                 if(opP->mode!=IMMED)
  1292.                     losing++;
  1293.                 else {
  1294.                     long t;
  1295.  
  1296.                     t=get_num(opP->con1,80);
  1297.                     if(t<1 || t>8 || isvar(opP->con1))
  1298.                         losing++;
  1299.                 }
  1300.                 break;
  1301.  
  1302.             case 'R':
  1303.                 if(opP->mode!=DREG && opP->mode!=AREG)
  1304.                     losing++;
  1305.                 break;
  1306.  
  1307.             case 's':
  1308.                 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1309.                     losing++;
  1310.                 break;
  1311.  
  1312.             case 'S':
  1313.                 if(opP->mode!=MSCR || opP->reg!=SR)
  1314.                     losing++;
  1315.                 break;
  1316.  
  1317.             case 'U':
  1318.                 if(opP->mode!=MSCR || opP->reg!=USP)
  1319.                     losing++;
  1320.                 break;
  1321.  
  1322.             /* JF these are out of order.  We could put them
  1323.                in order if we were willing to put up with
  1324.                bunches of #ifdef m68851s in the code */
  1325. #ifdef m68851
  1326.             /* Memory addressing mode used by pflushr */
  1327.             case '|':
  1328.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1329.  opP->mode==AREG || opP->mode==REGLST)
  1330.                     losing++;
  1331.                 break;
  1332.  
  1333.             case 'f':
  1334.                 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1335.                     losing++;
  1336.                 break;
  1337.  
  1338.             case 'P':
  1339.                 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1340.                     opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1341.                     losing++;
  1342.                 break;
  1343.  
  1344.             case 'V':
  1345.                 if (opP->reg != VAL)
  1346.                     losing++;
  1347.                 break;
  1348.  
  1349.             case 'W':
  1350.                 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1351.                     opP->reg != CRP))
  1352.                     losing++;
  1353.                 break;
  1354.  
  1355.             case 'X':
  1356.                 if (opP->mode != MSCR ||
  1357.                     (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1358.                      !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1359.                     losing++;
  1360.                 break;
  1361.  
  1362.             case 'Y':
  1363.                 if (opP->reg != PSR)
  1364.                     losing++;
  1365.                 break;
  1366.  
  1367.             case 'Z':
  1368.                 if (opP->reg != PCSR)
  1369.                     losing++;
  1370.                 break;
  1371. #endif
  1372.             default:
  1373.                 as_fatal("Internal error:  Operand mode %c unknown",*s);
  1374.             }
  1375.         }
  1376.         if(!losing)
  1377.             break;
  1378.         opcode=opcode->m_next;
  1379.         if(!opcode) {        /* Fell off the end */
  1380.             the_ins.error="instruction/operands mismatch";
  1381.             return;
  1382.         }
  1383.         losing=0;
  1384.     }
  1385.     the_ins.args=opcode->m_operands;
  1386.     the_ins.numargs=opcode->m_opnum;
  1387.     the_ins.numo=opcode->m_codenum;
  1388.     the_ins.opcode[0]=getone(opcode);
  1389.     the_ins.opcode[1]=gettwo(opcode);
  1390.  
  1391.     for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1392.             /* This switch is a doozy.
  1393.                What the first step; its a big one! */
  1394.         switch(s[0]) {
  1395.  
  1396.         case '*':
  1397.         case '~':
  1398.         case '%':
  1399.         case ';':
  1400.         case '@':
  1401.         case '!':
  1402.         case '&':
  1403.         case '$':
  1404.         case '?':
  1405.         case '/':
  1406. #ifdef m68851
  1407.         case '|':
  1408. #endif
  1409.             switch(opP->mode) {
  1410.             case IMMED:
  1411.                 tmpreg=0x3c;    /* 7.4 */
  1412.                 if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1413.                 else nextword=nextword=get_num(opP->con1,0);
  1414.                 if(isvar(opP->con1))
  1415.                   {
  1416.                     if (flagseen['p'] || flagseen['b'])
  1417.                       {
  1418. DP(("adding IMMREL frag\n"));
  1419.                         add_frag (adds(opP->con1),
  1420.                                 offs(opP->con1),
  1421.                                 TAB(IMMREL, SZ_UNDEF));
  1422.                           break;
  1423.                       }
  1424.                      else
  1425.                     add_fix(s[1],opP->con1,0,0);
  1426.                   }
  1427.                 switch(s[1]) {
  1428.                 case 'b':
  1429.                     if(!isbyte(nextword))
  1430.                         opP->error="operand out of range";
  1431.                     addword(nextword);
  1432.                     baseo=0;
  1433.                     break;
  1434.                 case 'w':
  1435.                     if(!isword(nextword))
  1436.                         opP->error="operand out of range";
  1437.                     addword(nextword);
  1438.                     baseo=0;
  1439.                     break;
  1440.                 case 'l':
  1441.                     addword(nextword>>16);
  1442.                     addword(nextword);
  1443.                     baseo=0;
  1444.                     break;
  1445.  
  1446.                 case 'f':
  1447.                     baseo=2;
  1448.                     outro=8;
  1449.                     break;
  1450.                 case 'F':
  1451.                     baseo=4;
  1452.                     outro=11;
  1453.                     break;
  1454.                 case 'x':
  1455.                     baseo=6;
  1456.                     outro=15;
  1457.                     break;
  1458.                 case 'p':
  1459.                     baseo=6;
  1460.                     outro= -1;
  1461.                     break;
  1462.                 default:
  1463.                     as_fatal("Internal error:  Can't decode %c%c",*s,s[1]);
  1464.                 }
  1465.                 if(!baseo)
  1466.                     break;
  1467.  
  1468.                 /* We gotta put out some float */
  1469.                 if(seg(opP->con1)!=SEG_BIG) {
  1470.                     int_to_gen(nextword);
  1471.                     gen_to_words(words,baseo,(long int)outro);
  1472.                     for(wordp=words;baseo--;wordp++)
  1473.                         addword(*wordp);
  1474.                     break;
  1475.                 }        /* Its BIG */
  1476.                 if(offs(opP->con1)>0) {
  1477.                     as_warn("Bignum assumed to be binary bit-pattern");
  1478.                     if(offs(opP->con1)>baseo) {
  1479.                         as_warn("Bignum too big for %c format; truncated",s[1]);
  1480.                         offs(opP->con1)=baseo;
  1481.                     }
  1482.                     baseo-=offs(opP->con1);
  1483.                     for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1484.                         addword(*wordp);
  1485.                     while(baseo--)
  1486.                         addword(0);
  1487.                     break;
  1488.                 }
  1489.                 gen_to_words(words,baseo,(long int)outro);
  1490.                 for(wordp=words;baseo--;wordp++)
  1491.                     addword(*wordp);
  1492.                 break;
  1493.             case DREG:
  1494.                 tmpreg=opP->reg-DATA; /* 0.dreg */
  1495.                 break;
  1496.             case AREG:
  1497.                 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1498.                 break;
  1499.             case AINDR:
  1500.                 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1501.                 break;
  1502.             case ADEC:
  1503.                 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1504.                 break;
  1505.             case AINC:
  1506.                 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1507.                 break;
  1508.             case AOFF:
  1509.  
  1510.                 nextword=get_num(opP->con1,80);
  1511.                 /* Force into index mode.  Hope this works */
  1512.  
  1513.                 /* We do the first bit for 32-bit displacements,
  1514.                    and the second bit for 16 bit ones.  It is
  1515.                    possible that we should make the default be
  1516.                    WORD instead of LONG, but I think that'd
  1517.                    break GCC, so we put up with a little
  1518.                    inefficiency for the sake of working output.
  1519.                  */
  1520.  
  1521.                 if(   !issword(nextword)
  1522.                    || (   isvar(opP->con1)
  1523.                        && (  (   opP->con1->e_siz==0
  1524.                           && flagseen['l']==0)
  1525.                        || opP->con1->e_siz==3))) {
  1526.  
  1527.                     if(opP->reg==PC)
  1528.                         tmpreg=0x3B;    /* 7.3 */
  1529.                     else
  1530.                         tmpreg=0x30+opP->reg-ADDR;    /* 6.areg */
  1531.                     if(isvar(opP->con1)) {
  1532.                         if(opP->reg==PC) {
  1533.                                add_frag(adds(opP->con1),
  1534.                              offs(opP->con1),
  1535.                              TAB(PCLEA,SZ_UNDEF));
  1536.                             break;
  1537.                         } else {
  1538.                             addword(0x0170);
  1539.                             add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1540.                         }
  1541.                     } else
  1542.                         addword(0x0170);
  1543.                     addword(nextword>>16);
  1544.                 } else {
  1545.                     if(opP->reg==PC)
  1546.                         tmpreg=0x3A; /* 7.2 */
  1547.                     else
  1548.                         tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1549.  
  1550.                     if(isvar(opP->con1)) {
  1551.                         if(opP->reg==PC) {
  1552.                             add_fix('w',opP->con1,1,opP->con1->e_baserel);
  1553.                         } else
  1554.                             add_fix('w',opP->con1,0,opP->con1->e_baserel);
  1555.                         }
  1556.                 }
  1557.                 addword(nextword);
  1558.                 break;
  1559.             case AINDX:
  1560.             case APODX:
  1561.             case AMIND:
  1562.             case APRDX:
  1563.                 nextword=0;
  1564.                 baseo=get_num(opP->con1,80);
  1565.                 outro=get_num(opP->con2,80);
  1566.                     /* Figure out the 'addressing mode' */
  1567.                     /* Also turn on the BASE_DISABLE bit, if needed */
  1568.                 if(opP->reg==PC || opP->reg==ZPC) {
  1569.                     tmpreg=0x3b; /* 7.3 */
  1570.                     if(opP->reg==ZPC)
  1571.                         nextword|=0x80;
  1572.                 } else if(opP->reg==FAIL) {
  1573.                     nextword|=0x80;
  1574.                     tmpreg=0x30;    /* 6.garbage */
  1575.                 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1576.  
  1577.                 siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1578.                 siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1579.  
  1580.                     /* Index register stuff */
  1581.                 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1582.                     nextword|=(opP->ireg-DATA)<<12;
  1583.  
  1584.                     if(opP->isiz==0 || opP->isiz==3)
  1585.                         nextword|=0x800;
  1586.                     switch(opP->imul) {
  1587.                     case 1: break;
  1588.                     case 2: nextword|=0x200; break;
  1589.                     case 4: nextword|=0x400; break;
  1590.                     case 8: nextword|=0x600; break;
  1591.                     default: abort();
  1592.                     }
  1593.                         /* IF its simple,
  1594.                            GET US OUT OF HERE! */
  1595.  
  1596.                         /* Must be INDEX, with an index
  1597.                            register.  Address register
  1598.                            cannot be ZERO-PC, and either
  1599.                            :b was forced, or we know
  1600.                            it will fit */
  1601.                     if(   opP->mode==AINDX
  1602.                        && opP->reg!=FAIL
  1603.                        && opP->reg!=ZPC
  1604.                        && (   siz1==1
  1605.                            || (   issbyte(baseo)
  1606.                            && !isvar(opP->con1)))) {
  1607.                         nextword +=baseo&0xff;
  1608.                         addword(nextword);
  1609.                         if(isvar(opP->con1))
  1610.                             add_fix('B',opP->con1,0,0);
  1611.                         break;
  1612.                     }
  1613.                 } else
  1614.                     nextword|=0x40;    /* No index reg */
  1615.  
  1616.                     /* It aint simple */
  1617.                 nextword|=0x100;
  1618.                     /* If the guy specified a width, we assume that
  1619.                        it is wide enough.  Maybe it isn't.  Ifso, we lose
  1620.                      */
  1621.                 switch(siz1) {
  1622.                 case 0:
  1623.                     if(isvar(opP->con1) || !issword(baseo)) {
  1624.                         siz1=3;
  1625.                         nextword|=0x30;
  1626.                     } else if(baseo==0)
  1627.                         nextword|=0x10;
  1628.                     else {    
  1629.                         nextword|=0x20;
  1630.                         siz1=2;
  1631.                     }
  1632.                     break;
  1633.                 case 1:
  1634.                     as_warn("Byte dispacement won't work.  Defaulting to :w");
  1635.                 case 2:
  1636.                     nextword|=0x20;
  1637.                     break;
  1638.                 case 3:
  1639.                     nextword|=0x30;
  1640.                     break;
  1641.                 }
  1642.  
  1643.                     /* Figure out innner displacement stuff */
  1644.                 if(opP->mode!=AINDX) {
  1645.                     switch(siz2) {
  1646.                     case 0:
  1647.                         if(isvar(opP->con2) || !issword(outro)) {
  1648.                             siz2=3;
  1649.                             nextword|=0x3;
  1650.                         } else if(outro==0)
  1651.                             nextword|=0x1;
  1652.                         else {    
  1653.                             nextword|=0x2;
  1654.                             siz2=2;
  1655.                         }
  1656.                         break;
  1657.                     case 1:
  1658.                         as_warn("Byte dispacement won't work.  Defaulting to :w");
  1659.                     case 2:
  1660.                         nextword|=0x2;
  1661.                         break;
  1662.                     case 3:
  1663.                         nextword|=0x3;
  1664.                         break;
  1665.                     }
  1666.                     if(opP->mode==APODX) nextword|=0x04;
  1667.                     else if(opP->mode==AMIND) nextword|=0x40;
  1668.                 }
  1669.                 addword(nextword);
  1670.  
  1671.                 if(isvar(opP->con1)) {
  1672.                     if(opP->reg==PC || opP->reg==ZPC) {
  1673.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,1,opP->con1->e_baserel);
  1674.                         opP->con1->e_exp.X_add_number+=6;
  1675.                     } else
  1676.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,0,opP->con1->e_baserel);
  1677.                 }
  1678.                 if(siz1==3)
  1679.                     addword(baseo>>16);
  1680.                 if(siz1)
  1681.                     addword(baseo);
  1682.  
  1683.                 if(isvar(opP->con2)) {
  1684.                     if(opP->reg==PC || opP->reg==ZPC) {
  1685.                         add_fix(siz2==3 ? 'l' : 'w',opP->con2,1,opP->con2->e_baserel);
  1686.                         opP->con1->e_exp.X_add_number+=6;
  1687.                     } else
  1688.                         add_fix(siz2==3 ? 'l' : 'w',opP->con2,0,opP->con2->e_baserel);
  1689.                 }
  1690.                 if(siz2==3)
  1691.                     addword(outro>>16);
  1692.                 if(siz2)
  1693.                     addword(outro);
  1694.  
  1695.                 break;
  1696.  
  1697.             case ABSL:
  1698.                 nextword=get_num(opP->con1,80);
  1699. DP(("case ABSL: opP->con1->e_siz = %d\n",opP->con1->e_siz));
  1700.                 switch(opP->con1->e_siz) {
  1701.                 default:
  1702.                     as_warn("Unknown size for absolute reference");
  1703.                 case 0:
  1704.                     if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1705. DP(("tmpreg=7.0\n"));
  1706.                         tmpreg=0x38; /* 7.0 */
  1707.                         addword(nextword);
  1708.                         break;
  1709.                     }
  1710.                     /* Don't generate pc relative code
  1711.                        on 68010 and 68000 */
  1712.                     if(isvar(opP->con1) &&
  1713.                        !subs(opP->con1) &&
  1714.                        seg(opP->con1)==SEG_TEXT &&
  1715.                        now_seg==SEG_TEXT &&
  1716.                        (flagseen['m']==0 ||
  1717.                         flagseen['p']==1) &&
  1718.                         !index("~%&$?", s[0])) {
  1719. DP(("tmpreg=7.2\n"));
  1720.                         tmpreg=0x3A; /* 7.2 */
  1721.                         add_frag(adds(opP->con1),
  1722.                              offs(opP->con1),
  1723.                              TAB(PCREL,SZ_UNDEF));
  1724.                         break;
  1725.                     }
  1726.                 case 3:        /* Fall through into long */
  1727.                     if (flagseen['p'] || flagseen['b'])
  1728.                       {
  1729. DP(("adding ABSREL frag\n"));
  1730.                         tmpreg=0x3A; /* 7.2 */
  1731.                         /* opP->con1->e_exp.X_add_number+=2; */
  1732.                         add_frag (adds(opP->con1),
  1733.                                   offs(opP->con1),
  1734.                                   TAB(ABSREL, SZ_UNDEF));
  1735.                         break;
  1736.                       }
  1737.  
  1738.  
  1739. #if 0
  1740.                     if (flagseen['b'] && now_seg==SEG_TEXT)
  1741.                       {
  1742. DP(("tmpreg=5.4\n"));
  1743.                         add_fix('w', opP->con1, 0, 1);
  1744.                         tmpreg = 0x2c; /* 5.4 mode */
  1745.                         addword (nextword);
  1746.                         break;
  1747.                       }
  1748. #endif
  1749.  
  1750.                     if(isvar(opP->con1))
  1751.                         add_fix('l',opP->con1,0,opP->con1->e_baserel);
  1752.  
  1753.                     tmpreg=0x39;    /* 7.1 mode */
  1754. DP(("tmpreg=7.1\n"));
  1755.                     addword(nextword>>16);
  1756.                     addword(nextword);
  1757.                     break;
  1758.  
  1759.                 case 2:        /* Word */
  1760.                     if(isvar(opP->con1))
  1761.                         add_fix('w',opP->con1,0,opP->con1->e_baserel);
  1762. DP(("tmpreg=7.0#2\n"));
  1763.  
  1764.                     tmpreg=0x38;    /* 7.0 mode */
  1765.                     addword(nextword);
  1766.                     break;
  1767.                 }
  1768.                 break;
  1769.             case MSCR:
  1770.             default:
  1771.                 as_bad("unknown/incorrect operand");
  1772.                 /* abort(); */
  1773.             }
  1774.             install_gen_operand(s[1],tmpreg);
  1775.             break;
  1776.  
  1777.         case '#':
  1778.         case '^':
  1779.             switch(s[1]) {    /* JF: I hate floating point! */
  1780.             case 'j':
  1781.                 tmpreg=70;
  1782.                 break;
  1783.             case '8':
  1784.                 tmpreg=20;
  1785.                 break;
  1786.             case 'C':
  1787.                 tmpreg=50;
  1788.                 break;
  1789.             case '3':
  1790.             default:
  1791.                 tmpreg=80;
  1792.                 break;
  1793.             }
  1794.             tmpreg=get_num(opP->con1,tmpreg);
  1795.             if(isvar(opP->con1))
  1796.                 add_fix(s[1],opP->con1,0,opP->con1->e_baserel);
  1797.             switch(s[1]) {
  1798.             case 'b':    /* Danger:  These do no check for
  1799.                        certain types of overflow.
  1800.                        user beware! */
  1801.                 if(!isbyte(tmpreg))
  1802.                     opP->error="out of range";
  1803.                 insop(tmpreg);
  1804.                 if(isvar(opP->con1))
  1805.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1806.                 break;
  1807.             case 'w':
  1808.                 if(!isword(tmpreg))
  1809.                     opP->error="out of range";
  1810.                 insop(tmpreg);
  1811.                 if(isvar(opP->con1))
  1812.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1813.                 break;
  1814.             case 'l':
  1815.                 insop(tmpreg);        /* Because of the way insop works, we put these two out backwards */
  1816.                 insop(tmpreg>>16);
  1817.                 if(isvar(opP->con1))
  1818.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1819.                 break;
  1820.             case '3':
  1821.                 tmpreg&=0xFF;
  1822.             case '8':
  1823.             case 'C':
  1824.                 install_operand(s[1],tmpreg);
  1825.                 break;
  1826.             default:
  1827.                 as_fatal("Internal error:  Unknown mode #%c",s[1]);
  1828.             }
  1829.             break;
  1830.  
  1831.         case '+':
  1832.         case '-':
  1833.         case 'A':
  1834.             install_operand(s[1],opP->reg-ADDR);
  1835.             break;
  1836.  
  1837.         case 'B':
  1838.             tmpreg=get_num(opP->con1,80);
  1839.             switch(s[1]) {
  1840.             case 'g':
  1841.                 if(opP->con1->e_siz) {    /* Deal with fixed size stuff by hand */
  1842.                     switch(opP->con1->e_siz) {
  1843.                     case 1:
  1844.                         add_fix('b',opP->con1,1,opP->con1->e_baserel);
  1845.                         break;
  1846.                     case 2:
  1847.                         add_fix('w',opP->con1,1,opP->con1->e_baserel);
  1848.                         addword(0);
  1849.                         break;
  1850.                     case 3:
  1851.                         add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1852.                         addword(0);
  1853.                         addword(0);
  1854.                         break;
  1855.                     default:
  1856.                         as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1857.                     }
  1858.                 } else if(subs(opP->con1)) {
  1859.                         /* We can't relax it */
  1860.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1861.                     add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1862.                     addword(0);
  1863.                     addword(0);
  1864.                 } else if(adds(opP->con1)) {
  1865.                     if (flagseen['m'] && 
  1866.                         (the_ins.opcode[0] >= 0x6200) &&
  1867.                         (the_ins.opcode[0] <= 0x6f00)) {
  1868.                       add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1869.                     } else {
  1870.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1871.                     }
  1872.                 } else {
  1873.                     /* JF:  This is the WRONG thing to do
  1874.                     add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1875.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1876.                     offs(opP->con1)+=4;
  1877.                     add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1878.                     addword(0);
  1879.                     addword(0);
  1880.                 }
  1881.                 break;
  1882.             case 'w':
  1883.                 if(isvar(opP->con1)) {
  1884.                     /* check for DBcc instruction */
  1885.                     if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8) {
  1886.                         /* size varies if patch */
  1887.                         /* needed for long form */
  1888.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1889.                         break;
  1890.                     }
  1891.  
  1892.                         /* Don't ask! */
  1893.                     opP->con1->e_exp.X_add_number+=2;
  1894.                     add_fix('w',opP->con1,1,opP->con1->e_baserel);
  1895.                 }
  1896.                 addword(0);
  1897.                 break;
  1898.             case 'c':
  1899.                 if(opP->con1->e_siz) {
  1900.                     switch(opP->con1->e_siz) {
  1901.                     case 2:
  1902.                         add_fix('w',opP->con1,1,opP->con1->e_baserel)
  1903.                         addword(0);
  1904.                         break;
  1905.                     case 3:
  1906.                         the_ins.opcode[the_ins.numo-1]|=0x40;
  1907.                         add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1908.                         addword(0);
  1909.                         addword(0);
  1910.                         break;
  1911.                     default:
  1912.                         as_bad("Bad size for offset, must be word or long");
  1913.                         break;
  1914.                     }
  1915.                 } else if(subs(opP->con1)) {
  1916.                     add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1917.                     add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  1918.                 } else if(adds(opP->con1)) {
  1919.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  1920.                 } else {
  1921.                     /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  1922.                     the_ins.opcode[the_ins.numo-1]|=0x40;
  1923.                     add_fix('l',opP->con1,1,opP->con1->e_baserel);
  1924.                     addword(0);
  1925.                     addword(4);
  1926.                 }
  1927.                 break;
  1928.             default:
  1929.                 as_fatal("Internal error:  operand type B%c unknown",s[1]);
  1930.             }
  1931.             break;
  1932.  
  1933.         case 'C':        /* Ignore it */
  1934.             break;
  1935.  
  1936.         case 'd':        /* JF this is a kludge */
  1937.             if(opP->mode==AOFF) {
  1938.                 install_operand('s',opP->reg-ADDR);
  1939.             } else {
  1940.                 char *tmpP;
  1941.  
  1942.                 tmpP=opP->con1->e_end-2;
  1943.                 opP->con1->e_beg++;
  1944.                 opP->con1->e_end-=4;    /* point to the , */
  1945.                 baseo=m68k_reg_parse(&tmpP);
  1946.                 if(baseo<ADDR+0 || baseo>ADDR+7) {
  1947.                     as_bad("Unknown address reg, using A0");
  1948.                     baseo=0;
  1949.                 } else baseo-=ADDR;
  1950.                 install_operand('s',baseo);
  1951.             }
  1952.             tmpreg=get_num(opP->con1,80);
  1953.             if(!issword(tmpreg)) {
  1954.                 as_warn("Expression out of range, using 0");
  1955.                 tmpreg=0;
  1956.             }
  1957.             addword(tmpreg);
  1958.             break;
  1959.  
  1960.         case 'D':
  1961.             install_operand(s[1],opP->reg-DATA);
  1962.             break;
  1963.  
  1964.         case 'F':
  1965.             install_operand(s[1],opP->reg-FPREG);
  1966.             break;
  1967.  
  1968.         case 'I':
  1969.             tmpreg=1+opP->reg-COPNUM;
  1970.             if(tmpreg==8)
  1971.                 tmpreg=0;
  1972.             install_operand(s[1],tmpreg);
  1973.             break;
  1974.  
  1975.         case 'J':        /* JF foo */
  1976.             switch(opP->reg) {
  1977.             case SFC:
  1978.                 tmpreg=0;
  1979.                 break;
  1980.             case DFC:
  1981.                 tmpreg=0x001;
  1982.                 break;
  1983.             case CACR:
  1984.                 tmpreg=0x002;
  1985.                 break;
  1986.             case USP:
  1987.                 tmpreg=0x800;
  1988.                 break;
  1989.             case VBR:
  1990.                 tmpreg=0x801;
  1991.                 break;
  1992.             case CAAR:
  1993.                 tmpreg=0x802;
  1994.                 break;
  1995.             case MSP:
  1996.                 tmpreg=0x803;
  1997.                 break;
  1998.             case ISP:
  1999.                 tmpreg=0x804;
  2000.                 break;
  2001.             default:
  2002.                 abort();
  2003.             }
  2004.             install_operand(s[1],tmpreg);
  2005.             break;
  2006.  
  2007.         case 'k':
  2008.             tmpreg=get_num(opP->con1,55);
  2009.             install_operand(s[1],tmpreg&0x7f);
  2010.             break;
  2011.  
  2012.         case 'l':
  2013.             tmpreg=opP->reg;
  2014.             if(s[1]=='w') {
  2015.                 if(tmpreg&0x7FF0000)
  2016.                     as_bad("Floating point register in register list");
  2017.                 insop(reverse_16_bits(tmpreg));
  2018.             } else {
  2019.                 if(tmpreg&0x700FFFF)
  2020.                     as_bad("Wrong register in floating-point reglist");
  2021.                 install_operand(s[1],reverse_8_bits(tmpreg>>16));
  2022.             }
  2023.             break;
  2024.  
  2025.         case 'L':
  2026.             tmpreg=opP->reg;
  2027.             if(s[1]=='w') {
  2028.                 if(tmpreg&0x7FF0000)
  2029.                     as_bad("Floating point register in register list");
  2030.                 insop(tmpreg);
  2031.             } else if(s[1]=='8') {
  2032.                 if(tmpreg&0x0FFFFFF)
  2033.                     as_bad("incorrect register in reglist");
  2034.                 install_operand(s[1],tmpreg>>24);
  2035.             } else {
  2036.                 if(tmpreg&0x700FFFF)
  2037.                     as_bad("wrong register in floating-point reglist");
  2038.                 else
  2039.                     install_operand(s[1],tmpreg>>16);
  2040.             }
  2041.             break;
  2042.  
  2043.         case 'M':
  2044.             install_operand(s[1],get_num(opP->con1,60));
  2045.             break;
  2046.  
  2047.         case 'O':
  2048.             tmpreg= (opP->mode==DREG)
  2049.                 ? 0x20+opP->reg-DATA
  2050.                 : (get_num(opP->con1,40)&0x1F);
  2051.             install_operand(s[1],tmpreg);
  2052.             break;
  2053.  
  2054.         case 'Q':
  2055.             tmpreg=get_num(opP->con1,10);
  2056.             if(tmpreg==8)
  2057.                 tmpreg=0;
  2058.             install_operand(s[1],tmpreg);
  2059.             break;
  2060.  
  2061.         case 'R':
  2062.             /* This depends on the fact that ADDR registers are
  2063.                eight more than their corresponding DATA regs, so
  2064.                the result will have the ADDR_REG bit set */
  2065.             install_operand(s[1],opP->reg-DATA);
  2066.             break;
  2067.  
  2068.         case 's':
  2069.             if(opP->reg==FPI) tmpreg=0x1;
  2070.             else if(opP->reg==FPS) tmpreg=0x2;
  2071.             else if(opP->reg==FPC) tmpreg=0x4;
  2072.             else abort();
  2073.             install_operand(s[1],tmpreg);
  2074.             break;
  2075.  
  2076.         case 'S':    /* Ignore it */
  2077.             break;
  2078.  
  2079.         case 'T':
  2080.             install_operand(s[1],get_num(opP->con1,30));
  2081.             break;
  2082.  
  2083.         case 'U':    /* Ignore it */
  2084.             break;
  2085.  
  2086. #ifdef m68851
  2087.             /* JF: These are out of order, I fear. */
  2088.         case 'f':
  2089.             switch (opP->reg) {
  2090.             case SFC:
  2091.                 tmpreg=0;
  2092.                 break;
  2093.             case DFC:
  2094.                 tmpreg=1;
  2095.                 break;
  2096.             default:
  2097.                 abort();
  2098.             }
  2099.             install_operand(s[1],tmpreg);
  2100.             break;
  2101.  
  2102.         case 'P':
  2103.             switch(opP->reg) {
  2104.             case TC:
  2105.                 tmpreg=0;
  2106.                 break;
  2107.             case CAL:
  2108.                 tmpreg=4;
  2109.                 break;
  2110.             case VAL:
  2111.                 tmpreg=5;
  2112.                 break;
  2113.             case SCC:
  2114.                 tmpreg=6;
  2115.                 break;
  2116.             case AC:
  2117.                 tmpreg=7;
  2118.                 break;
  2119.             default:
  2120.                 abort();
  2121.             }
  2122.             install_operand(s[1],tmpreg);
  2123.             break;
  2124.  
  2125.         case 'V':
  2126.             if (opP->reg == VAL)
  2127.                 break;
  2128.             abort();
  2129.  
  2130.         case 'W':
  2131.             switch(opP->reg) {
  2132.  
  2133.             case DRP:
  2134.                 tmpreg=1;
  2135.                 break;
  2136.             case SRP:
  2137.                 tmpreg=2;
  2138.                 break;
  2139.             case CRP:
  2140.                 tmpreg=3;
  2141.                 break;
  2142.             default:
  2143.                 abort();
  2144.             }
  2145.             install_operand(s[1],tmpreg);
  2146.             break;
  2147.  
  2148.         case 'X':
  2149.             switch (opP->reg) {
  2150.             case BAD: case BAD+1: case BAD+2: case BAD+3:
  2151.             case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  2152.                 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2153.                 break;
  2154.  
  2155.             case BAC: case BAC+1: case BAC+2: case BAC+3:
  2156.             case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  2157.                 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2158.                 break;
  2159.  
  2160.             default:
  2161.                 abort();
  2162.             }
  2163.             install_operand(s[1], tmpreg);
  2164.             break;
  2165.         case 'Y':
  2166.             if (opP->reg == PSR)
  2167.                 break;
  2168.             abort();
  2169.  
  2170.         case 'Z':
  2171.             if (opP->reg == PCSR)
  2172.                 break;
  2173.             abort();
  2174. #endif /* m68851 */
  2175.         default:
  2176.             as_fatal("Internal error:  Operand type %c unknown",s[0]);
  2177.         }
  2178.     }
  2179.     /* By the time whe get here (FINALLY) the_ins contains the complete
  2180.        instruction, ready to be emitted. . . */
  2181. }
  2182.  
  2183. int
  2184. get_regs(i,str,opP)
  2185. struct m68k_op *opP;
  2186. char *str;
  2187. {
  2188.     /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  2189.     /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  2190.     unsigned long int cur_regs = 0;
  2191.     int    reg1,
  2192.         reg2;
  2193.  
  2194. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  2195.              else if(x==FPS) cur_regs|=(1<<25);\
  2196.              else if(x==FPC) cur_regs|=(1<<26);\
  2197.              else cur_regs|=(1<<(x-1));  }
  2198.  
  2199.     reg1=i;
  2200.     for(;;) {
  2201.         if(*str=='/') {
  2202.             ADD_REG(reg1);
  2203.             str++;
  2204.         } else if(*str=='-') {
  2205.             str++;
  2206.             reg2=m68k_reg_parse(&str);
  2207.             if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  2208.                 opP->error="unknown register in register list";
  2209.                 return FAIL;
  2210.             }
  2211.             while(reg1<=reg2) {
  2212.                 ADD_REG(reg1);
  2213.                 reg1++;
  2214.             }
  2215.             if(*str=='\0')
  2216.                 break;
  2217.         } else if(*str=='\0') {
  2218.             ADD_REG(reg1);
  2219.             break;
  2220.         } else {
  2221.             opP->error="unknow character in register list";
  2222.             return FAIL;
  2223.         }
  2224. /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  2225.         if (*str=='/')
  2226.           str ++;
  2227.         reg1=m68k_reg_parse(&str);
  2228.         if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  2229.             opP->error="unknown register in register list";
  2230.             return FAIL;
  2231.         }
  2232.     }
  2233.     opP->reg=cur_regs;
  2234.     return OK;
  2235. }
  2236.  
  2237. int
  2238. reverse_16_bits(in)
  2239. int in;
  2240. {
  2241.     int out=0;
  2242.     int n;
  2243.  
  2244.     static int mask[16] = {
  2245. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2246. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  2247.     };
  2248.     for(n=0;n<16;n++) {
  2249.         if(in&mask[n])
  2250.             out|=mask[15-n];
  2251.     }
  2252.     return out;
  2253. }
  2254.  
  2255. int
  2256. reverse_8_bits(in)
  2257. int in;
  2258. {
  2259.     int out=0;
  2260.     int n;
  2261.  
  2262.     static int mask[8] = {
  2263. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2264.     };
  2265.  
  2266.     for(n=0;n<8;n++) {
  2267.         if(in&mask[n])
  2268.             out|=mask[7-n];
  2269.     }
  2270.     return out;
  2271. }
  2272.  
  2273. void
  2274. install_operand(mode,val)
  2275. int mode;
  2276. int val;
  2277. {
  2278.     switch(mode) {
  2279.     case 's':
  2280.         the_ins.opcode[0]|=val & 0xFF;    /* JF FF is for M kludge */
  2281.         break;
  2282.     case 'd':
  2283.         the_ins.opcode[0]|=val<<9;
  2284.         break;
  2285.     case '1':
  2286.         the_ins.opcode[1]|=val<<12;
  2287.         break;
  2288.     case '2':
  2289.         the_ins.opcode[1]|=val<<6;
  2290.         break;
  2291.     case '3':
  2292.         the_ins.opcode[1]|=val;
  2293.         break;
  2294.     case '4':
  2295.         the_ins.opcode[2]|=val<<12;
  2296.         break;
  2297.     case '5':
  2298.         the_ins.opcode[2]|=val<<6;
  2299.         break;
  2300.     case '6':
  2301.             /* DANGER!  This is a hack to force cas2l and cas2w cmds
  2302.                to be three words long! */
  2303.         the_ins.numo++;
  2304.         the_ins.opcode[2]|=val;
  2305.         break;
  2306.     case '7':
  2307.         the_ins.opcode[1]|=val<<7;
  2308.         break;
  2309.     case '8':
  2310.         the_ins.opcode[1]|=val<<10;
  2311.         break;
  2312. #ifdef m68851
  2313.     case '9':
  2314.         the_ins.opcode[1]|=val<<5;
  2315.         break;
  2316. #endif
  2317.  
  2318.     case 't':
  2319.         the_ins.opcode[1]|=(val<<10)|(val<<7);
  2320.         break;
  2321.     case 'D':
  2322.         the_ins.opcode[1]|=(val<<12)|val;
  2323.         break;
  2324.     case 'g':
  2325.         the_ins.opcode[0]|=val=0xff;
  2326.         break;
  2327.     case 'i':
  2328.         the_ins.opcode[0]|=val<<9;
  2329.         break;
  2330.     case 'C':
  2331.         the_ins.opcode[1]|=val;
  2332.         break;
  2333.     case 'j':
  2334.         the_ins.opcode[1]|=val;
  2335.         the_ins.numo++;        /* What a hack */
  2336.         break;
  2337.     case 'k':
  2338.         the_ins.opcode[1]|=val<<4;
  2339.         break;
  2340.     case 'b':
  2341.     case 'w':
  2342.     case 'l':
  2343.         break;
  2344.     case 'c':
  2345.     default:
  2346.         abort();
  2347.     }
  2348. }
  2349.  
  2350. void
  2351. install_gen_operand(mode,val)
  2352. int mode;
  2353. int val;
  2354. {
  2355.     switch(mode) {
  2356.     case 's':
  2357.         the_ins.opcode[0]|=val;
  2358.         break;
  2359.     case 'd':
  2360.             /* This is a kludge!!! */
  2361.         the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2362.         break;
  2363.     case 'b':
  2364.     case 'w':
  2365.     case 'l':
  2366.     case 'f':
  2367.     case 'F':
  2368.     case 'x':
  2369.     case 'p':
  2370.         the_ins.opcode[0]|=val;
  2371.         break;
  2372.         /* more stuff goes here */
  2373.     default:
  2374.         abort();
  2375.     }
  2376. }
  2377.  
  2378. char *
  2379. crack_operand(str,opP)
  2380. register char *str;
  2381. register struct m68k_op *opP;
  2382. {
  2383.     register int parens;
  2384.     register int c;
  2385.     register char *beg_str;
  2386.  
  2387.     if(!str) {
  2388.         return str;
  2389.     }
  2390.     beg_str=str;
  2391.     for(parens=0;*str && (parens>0 || notend(str));str++) {
  2392.         if(*str=='(') parens++;
  2393.         else if(*str==')') {
  2394.             if(!parens) {        /* ERROR */
  2395.                 opP->error="Extra )";
  2396.                 return str;
  2397.             }
  2398.             --parens;
  2399.         }
  2400.     }
  2401.     if(!*str && parens) {        /* ERROR */
  2402.         opP->error="Missing )";
  2403.         return str;
  2404.     }
  2405.     c= *str;
  2406.     *str='\0';
  2407.     if(m68k_ip_op(beg_str,opP)==FAIL) {
  2408.         *str=c;
  2409.         return str;
  2410.     }
  2411.     *str=c;
  2412.     if(c=='}')
  2413.         c= *++str;        /* JF bitfield hack */
  2414.     if(c) {
  2415.         c= *++str;
  2416.         if(!c)
  2417.             as_bad("Missing operand");
  2418.     }
  2419.     return str;
  2420. }
  2421.  
  2422. /* See the comment up above where the #define notend(... is */
  2423. #if 0
  2424. notend(s)
  2425. char *s;
  2426. {
  2427.     if(*s==',') return 0;
  2428.     if(*s=='{' || *s=='}')
  2429.         return 0;
  2430.     if(*s!=':') return 1;
  2431.         /* This kludge here is for the division cmd, which is a kludge */
  2432.     if(index("aAdD#",s[1])) return 0;
  2433.     return 1;
  2434. }
  2435. #endif
  2436.  
  2437. /* This is the guts of the machine-dependent assembler.  STR points to a
  2438.    machine dependent instruction.  This funciton is supposed to emit
  2439.    the frags/bytes it assembles to.
  2440.  */
  2441. void
  2442. md_assemble(str)
  2443. char *str;
  2444. {
  2445.     char *er;
  2446.     short    *fromP;
  2447.     char    *toP;
  2448.     int    m,n;
  2449.     char    *to_beg_P;
  2450.     int    shorts_this_frag;
  2451.  
  2452.     bzero((char *)(&the_ins),sizeof(the_ins));    /* JF for paranoia sake */
  2453.     m68_ip(str);
  2454.     er=the_ins.error;
  2455.     if(!er) {
  2456.         for(n=the_ins.numargs;n;--n)
  2457.             if(the_ins.operands[n].error) {
  2458.                 er=the_ins.operands[n].error;
  2459.                 break;
  2460.             }
  2461.     }
  2462.     if(er) {
  2463.         as_bad("\"%s\" -- Statement '%s' ignored",er,str);
  2464.         return;
  2465.     }
  2466.  
  2467.     if(the_ins.nfrag==0) {    /* No frag hacking involved; just put it out */
  2468.         toP=frag_more(2*the_ins.numo);
  2469.         fromP= &the_ins.opcode[0];
  2470.         for(m=the_ins.numo;m;--m) {
  2471.             md_number_to_chars(toP,(long)(*fromP),2);
  2472.             toP+=2;
  2473.             fromP++;
  2474.         }
  2475.             /* put out symbol-dependent info */
  2476.         for(m=0;m<the_ins.nrel;m++) {
  2477.             switch(the_ins.reloc[m].wid) {
  2478.             case 'B':
  2479.                 n=1;
  2480.                 break;
  2481.             case 'b':
  2482.                 n=1;
  2483.                 break;
  2484.             case '3':
  2485.                 n=2;
  2486.                 break;
  2487.             case 'w':
  2488.                 n=2;
  2489.                 break;
  2490.             case 'l':
  2491.                 n=4;
  2492.                 break;
  2493.             default:
  2494.                 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins.reloc[m].wid);
  2495.             }
  2496.  
  2497.             fix_new(frag_now,
  2498.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2499.                 n,
  2500.                 the_ins.reloc[m].add,
  2501.                 the_ins.reloc[m].sub,
  2502.                 the_ins.reloc[m].off,
  2503.                 the_ins.reloc[m].pcrel,
  2504.                 the_ins.reloc[m].baserel);
  2505.         }
  2506.         return;
  2507.     }
  2508.  
  2509.         /* There's some frag hacking */
  2510.     for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2511.         int wid;
  2512.  
  2513.         if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2514.         else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2515.         toP=frag_more(wid);
  2516.         to_beg_P=toP;
  2517.         shorts_this_frag=0;
  2518.         for(m=wid/2;m;--m) {
  2519.             md_number_to_chars(toP,(long)(*fromP),2);
  2520.             toP+=2;
  2521.             fromP++;
  2522.             shorts_this_frag++;
  2523.         }
  2524.         for(m=0;m<the_ins.nrel;m++) {
  2525.             if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2526.                 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2527.                 break;
  2528.             }
  2529.             wid=the_ins.reloc[m].wid;
  2530.             if(wid==0)
  2531.                 continue;
  2532.             the_ins.reloc[m].wid=0;
  2533.             wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2534.  
  2535.             fix_new(frag_now,
  2536.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2537.                 wid,
  2538.                 the_ins.reloc[m].add,
  2539.                 the_ins.reloc[m].sub,
  2540.                 the_ins.reloc[m].off,
  2541.                 the_ins.reloc[m].pcrel,
  2542.                 the_ins.reloc[m].baserel);
  2543.         }
  2544.         know(the_ins.fragb[n].fadd);
  2545.         (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2546.  the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2547.     }
  2548.     n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2549.     shorts_this_frag=0;
  2550.     if(n) {
  2551.         toP=frag_more(n*sizeof(short));
  2552.         while(n--) {
  2553.             md_number_to_chars(toP,(long)(*fromP),2);
  2554.             toP+=2;
  2555.             fromP++;
  2556.             shorts_this_frag++;
  2557.         }
  2558.     }
  2559.     for(m=0;m<the_ins.nrel;m++) {
  2560.         int wid;
  2561.  
  2562.         wid=the_ins.reloc[m].wid;
  2563.         if(wid==0)
  2564.             continue;
  2565.         the_ins.reloc[m].wid=0;
  2566.         wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2567.  
  2568.         fix_new(frag_now,
  2569.             (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2570.             wid,
  2571.             the_ins.reloc[m].add,
  2572.             the_ins.reloc[m].sub,
  2573.             the_ins.reloc[m].off,
  2574.             the_ins.reloc[m].pcrel,
  2575.             the_ins.reloc[m].baserel);
  2576.     }
  2577. }
  2578.  
  2579. /* This function is called once, at assembler startup time.  This should
  2580.    set up all the tables, etc that the MD part of the assembler needs
  2581.  */
  2582. void
  2583. md_begin()
  2584. {
  2585. /*
  2586.  * md_begin -- set up hash tables with 68000 instructions.
  2587.  * similar to what the vax assembler does.  ---phr
  2588.  */
  2589.     /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2590.        a copy of it at runtime, adding in the information we want but isn't
  2591.        there.  I think it'd be better to have an awk script hack the table
  2592.        at compile time.  Or even just xstr the table and use it as-is.  But
  2593.        my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  2594.        names.  */
  2595.  
  2596.     register struct m68k_opcode *ins;
  2597.     register struct m68_incant *hack,
  2598.         *slak;
  2599.     register char *retval = 0;        /* empty string, or error msg text */
  2600.     register int i;
  2601.     register char c;
  2602.  
  2603.     if ((op_hash = hash_new()) == NULL)
  2604.         as_fatal("Virtual memory exhausted");
  2605.  
  2606.     obstack_begin(&robyn,4000);
  2607.     for (ins = m68k_opcodes; ins < endop; ins++) {
  2608.         hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2609.         do {
  2610.             slak->m_operands=ins->args;
  2611.             slak->m_opnum=strlen(slak->m_operands)/2;
  2612.             slak->m_opcode=ins->opcode;
  2613.                 /* This is kludgey */
  2614.             slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2615.             if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2616.                 slak->m_next=(struct m68_incant *)
  2617. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2618.                 ins++;
  2619.             } else
  2620.                 slak->m_next=0;
  2621.             slak=slak->m_next;
  2622.         } while(slak);
  2623.  
  2624.         retval = hash_insert (op_hash, ins->name,(char *)hack);
  2625.             /* Didn't his mommy tell him about null pointers? */
  2626.         if(retval && *retval)
  2627.             as_fatal("Internal Error:  Can't hash %s: %s",ins->name,retval);
  2628.     }
  2629.  
  2630.     for (i = 0; i < sizeof(mklower_table) ; i++)
  2631.         mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2632.  
  2633.     for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2634.         notend_table[i] = 0;
  2635.         alt_notend_table[i] = 0;
  2636.     }
  2637.     notend_table[','] = 1;
  2638.     notend_table['{'] = 1;
  2639.     notend_table['}'] = 1;
  2640.     alt_notend_table['a'] = 1;
  2641.     alt_notend_table['A'] = 1;
  2642.     alt_notend_table['d'] = 1;
  2643.     alt_notend_table['D'] = 1;
  2644.     alt_notend_table['#'] = 1;
  2645.     alt_notend_table['f'] = 1;
  2646.     alt_notend_table['F'] = 1;
  2647. #ifdef REGISTER_PREFIX
  2648.     alt_notend_table[REGISTER_PREFIX] = 1;
  2649. #endif
  2650. }
  2651.  
  2652. #if 0
  2653. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2654.                    || (*s == ':' && index("aAdD#", s[1]))) \
  2655.                ? 0 : 1)
  2656. #endif
  2657.  
  2658. /* This funciton is called once, before the assembler exits.  It is
  2659.    supposed to do any final cleanup for this part of the assembler.
  2660.  */
  2661. void
  2662. md_end()
  2663. {
  2664. }
  2665.  
  2666. /* Equal to MAX_PRECISION in atof-ieee.c */
  2667. #define MAX_LITTLENUMS 6
  2668.  
  2669. /* Turn a string in input_line_pointer into a floating point constant of type
  2670.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2671.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2672.  */
  2673. char *
  2674. md_atof(type,litP,sizeP)
  2675. char type;
  2676. char *litP;
  2677. int *sizeP;
  2678. {
  2679.     int    prec;
  2680.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2681.     LITTLENUM_TYPE *wordP;
  2682.     char    *t;
  2683.     char    *atof_ieee();
  2684.  
  2685.     switch(type) {
  2686.     case 'f':
  2687.     case 'F':
  2688.     case 's':
  2689.     case 'S':
  2690.         prec = 2;
  2691.         break;
  2692.  
  2693.     case 'd':
  2694.     case 'D':
  2695.     case 'r':
  2696.     case 'R':
  2697.         prec = 4;
  2698.         break;
  2699.  
  2700.     case 'x':
  2701.     case 'X':
  2702.         prec = 6;
  2703.         break;
  2704.  
  2705.     case 'p':
  2706.     case 'P':
  2707.         prec = 6;
  2708.         break;
  2709.  
  2710.     default:
  2711.         *sizeP=0;
  2712.         return "Bad call to MD_ATOF()";
  2713.     }
  2714.     t=atof_ieee(input_line_pointer,type,words);
  2715.     if(t)
  2716.         input_line_pointer=t;
  2717.  
  2718.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2719.     for(wordP=words;prec--;) {
  2720.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2721.         litP+=sizeof(LITTLENUM_TYPE);
  2722.     }
  2723.     return "";    /* Someone should teach Dean about null pointers */
  2724. }
  2725.  
  2726. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2727.    for use in the a.out file, and stores them in the array pointed to by buf.
  2728.    This knows about the endian-ness of the target machine and does
  2729.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2730.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2731.    LITTLENUMS (shorts, here at least)
  2732.  */
  2733. void
  2734. md_number_to_chars(buf,val,n)
  2735. char    *buf;
  2736. long    val;
  2737. int n;
  2738. {
  2739.     switch(n) {
  2740.     case 1:
  2741.         *buf++=val;
  2742.         break;
  2743.     case 2:
  2744.         *buf++=(val>>8);
  2745.         *buf++=val;
  2746.         break;
  2747.     case 4:
  2748.         *buf++=(val>>24);
  2749.         *buf++=(val>>16);
  2750.         *buf++=(val>>8);
  2751.         *buf++=val;
  2752.         break;
  2753.     default:
  2754.         abort();
  2755.     }
  2756. }
  2757.  
  2758. void
  2759. md_number_to_imm(buf,val,n)
  2760. char *buf;
  2761. long val;
  2762. int n;
  2763. {
  2764.     switch(n) {
  2765.     case 1:
  2766.         *buf++=val;
  2767.         break;
  2768.     case 2:
  2769.         *buf++=(val>>8);
  2770.         *buf++=val;
  2771.         break;
  2772.     case 4:
  2773.         *buf++=(val>>24);
  2774.         *buf++=(val>>16);
  2775.         *buf++=(val>>8);
  2776.         *buf++=val;
  2777.         break;
  2778.     default:
  2779.         abort();
  2780.     }
  2781. }
  2782.  
  2783. void
  2784. md_number_to_disp(buf,val,n)
  2785. char    *buf;
  2786. long    val;
  2787. int n;
  2788. {
  2789.     abort();
  2790. }
  2791.  
  2792. void
  2793. md_number_to_field(buf,val,fix)
  2794. char *buf;
  2795. long val;
  2796. void *fix;
  2797. {
  2798.     abort();
  2799. }
  2800.  
  2801.  
  2802. /* *fragP has been relaxed to its final size, and now needs to have
  2803.    the bytes inside it modified to conform to the new size  There is UGLY
  2804.    MAGIC here. ..
  2805.  */
  2806. void
  2807. md_convert_frag(fragP)
  2808. register fragS *fragP;
  2809. {
  2810.   long disp;
  2811.   long ext;
  2812.  
  2813.   /* Address in gas core of the place to store the displacement.  */
  2814.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2815.   /* Address in object code of the displacement.  */
  2816.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2817.  
  2818.   know(fragP->fr_symbol);
  2819.  
  2820.   /* The displacement of the address, from current location.  */
  2821.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2822.  
  2823. DP(("md_convert_frag: fragP->fr_subtype = $%x\n", fragP->fr_subtype));
  2824.  
  2825.   switch(fragP->fr_subtype) {
  2826.   case TAB(BCC68000,BYTE):
  2827.   case TAB(BRANCH,BYTE):
  2828.     know(issbyte(disp));
  2829.     if(disp==0)
  2830.       as_bad("short branch with zero offset: use :w");
  2831.     fragP->fr_opcode[1]=disp;
  2832.     ext=0;
  2833.     break;
  2834.   case TAB(DBCC,SHORT):
  2835.     know(issword(disp));
  2836.     ext=2;
  2837.     break;
  2838.   case TAB(BCC68000,SHORT):
  2839.   case TAB(BRANCH,SHORT):
  2840.     know(issword(disp));
  2841.     fragP->fr_opcode[1]=0x00;
  2842.     ext=2;
  2843.     break;
  2844.   case TAB(BRANCH,LONG):
  2845.     if(flagseen['m']) {
  2846.       if (flagseen['p']) {
  2847.         as_bad("Long branch in small code model, not supported.");
  2848.       } else {
  2849.         if(fragP->fr_opcode[0]==0x61) { /* BSR */
  2850.         fragP->fr_opcode[0]= 0x4E;
  2851.         fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2852.         subseg_change(SEG_TEXT, 0);
  2853.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0, 0);
  2854.         fragP->fr_fix+=4;
  2855.         ext=0;
  2856.         } else if(fragP->fr_opcode[0]==0x60) {
  2857.           fragP->fr_opcode[0]= 0x4E;
  2858.           fragP->fr_opcode[1]= 0xF9;      /* JMP  with ABSL LONG offset */
  2859.           subseg_change(SEG_TEXT, 0);
  2860.           fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0,0);
  2861.           fragP->fr_fix+=4;
  2862.           ext=0;
  2863.         }else {
  2864.           as_bad("Long branch offset not supported.");
  2865.         }
  2866.       }
  2867.     } else {
  2868.       fragP->fr_opcode[1]=0xff;
  2869.       ext=4;
  2870.     }
  2871.     break;
  2872.   case TAB(BCC68000,LONG):
  2873.     /* only Bcc 68000 instructions can come here */
  2874.         /* change bcc into b!cc/jmp absl long */
  2875.     fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2876.         fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2877.  
  2878.     /* JF: these used to be fr_opcode[2,3], but they may be in a
  2879.        different frag, in which case refering to them is a no-no.
  2880.        Only fr_opcode[0,1] are guaranteed to work. */
  2881.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2882.         *buffer_address++ = 0xf9;  
  2883.         fragP->fr_fix += 2;         /* account for jmp instruction */
  2884.         subseg_change(SEG_TEXT,0);
  2885.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2886.                      fragP->fr_offset,0,0);
  2887.         fragP->fr_fix += 4;
  2888.         ext=0;
  2889.     break;
  2890.   case TAB(DBCC,LONG):
  2891.         /* only DBcc 68000 instructions can come here */
  2892.         /* change dbcc into dbcc/jmp absl long */
  2893.     /* JF: these used to be fr_opcode[2-7], but that's wrong */
  2894.         *buffer_address++ = 0x00;  /* branch offset = 4 */
  2895.         *buffer_address++ = 0x04;  
  2896.         *buffer_address++ = 0x60;  /* put in bra pc+6 */ 
  2897.         *buffer_address++ = 0x06;  
  2898.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2899.         *buffer_address++ = 0xf9;  
  2900.  
  2901.         fragP->fr_fix += 6;         /* account for bra/jmp instructions */
  2902.         subseg_change(SEG_TEXT,0);
  2903.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2904.                      fragP->fr_offset,0,0);
  2905.         fragP->fr_fix += 4;
  2906.         ext=0;
  2907.     break;
  2908.   case TAB(FBRANCH,SHORT):
  2909.     know((fragP->fr_opcode[1]&0x40)==0);
  2910.     ext=2;
  2911.     break;
  2912.   case TAB(FBRANCH,LONG):
  2913.     fragP->fr_opcode[1]|=0x40;    /* Turn on LONG bit */
  2914.     ext=4;
  2915.     break;
  2916.   case TAB(PCREL,SHORT):
  2917. DP(("TAB(PCREL,SHORT)\n"));
  2918.     ext=2;
  2919.     break;
  2920.   case TAB(PCREL,LONG):
  2921. DP(("TAB(PCREL,LONG)\n"));
  2922.     /* The thing to do here is force it to ABSOLUTE LONG, since
  2923.        PCREL is really trying to shorten an ABSOLUTE address anyway */
  2924.     /* JF FOO This code has not been tested */
  2925.     
  2926.     if (flagseen['p'])
  2927.       as_bad ("Trying to force a pcrel thing into absolute mode while in small code mode");
  2928.     
  2929.     subseg_change(SEG_TEXT,0);
  2930.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0,0);
  2931.     if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  2932.       as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  2933.             fragP->fr_opcode[0],fragP->fr_address);
  2934.     fragP->fr_opcode[1]&= ~0x3F;
  2935.     fragP->fr_opcode[1]|=0x39;    /* Mode 7.1 */
  2936.     fragP->fr_fix+=4;
  2937.     /* md_number_to_chars(buffer_address,
  2938.                (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  2939.                4); */
  2940.     ext=0;
  2941.     break;
  2942.   case TAB(PCLEA,SHORT):
  2943. DP(("TAB(PCLEA,SHORT)\n"));
  2944.     subseg_change(SEG_TEXT,0);
  2945.     fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset, 1, 0);
  2946.     fragP->fr_opcode[1] &= ~0x3F;
  2947.     fragP->fr_opcode[1] |= 0x3A;
  2948.     ext=2;
  2949.     break;
  2950.   case TAB(PCLEA,LONG):
  2951. DP(("TAB(PCLEA,LONG)\n"));
  2952.     subseg_change(SEG_TEXT,0);
  2953.     fix_new(fragP,(int)(fragP->fr_fix)+2,4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset+2,1,0);
  2954.     *buffer_address++ = 0x01;
  2955.     *buffer_address++ = 0x70;
  2956.     fragP->fr_fix+=2;
  2957.     /* buffer_address+=2; */
  2958.     ext=4;
  2959.     break;
  2960.  
  2961.  
  2962.   case TAB(ABSREL,BYTE):
  2963. DP(("TAB(ABSREL,BYTE)\n"));
  2964.     as_bad ("ABSREL_BYTE: how the ** does this look ?? \n");
  2965.     break;
  2966.   case TAB(ABSREL,SHORT):
  2967. DP(("TAB(ABSREL,SHORT)\n"));
  2968.     subseg_change (SEG_TEXT, 0);
  2969.     ext = 2;
  2970.     fragP->fr_opcode[1] &= ~0x3f;
  2971.     if ((fragP->fr_symbol->sy_type & N_TYPE) == N_TEXT)
  2972.       {
  2973.         /* so this is really a pc-relative address */
  2974.         fragP->fr_opcode[1] |=  0x3a;
  2975.         fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0, fragP->fr_offset+2, 1, 0);
  2976.     break;
  2977.       }
  2978.     /* in that case we have to generate base-relative code
  2979.      * (note: if we're in N_UNDF, this could as well be pc-relative, but the linker
  2980.      *        will have to do the final patch in that case) */
  2981.     fragP->fr_opcode[1] |=  0x2c;  /* (a4) */
  2982.     fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset, 0, 1);
  2983.     break;
  2984.   case TAB(ABSREL,LONG):
  2985. DP(("TAB(ABSREL,LONG)\n"));
  2986.     as_bad ("ABSREL_LONG: sorry, not supported.\n");
  2987.     break;
  2988.  
  2989.   case TAB(IMMREL,BYTE):
  2990. DP(("TAB(IMMREL,BYTE)\n"));
  2991.     as_bad ("IMMREL_BYTE: how the ** does this look ?? \n");
  2992.     break;
  2993.   case TAB(IMMREL,SHORT):
  2994. DP(("TAB(IMMREL,SHORT)\n"));
  2995.     subseg_change (SEG_TEXT, 0);
  2996.     ext = 0; 
  2997.     if ((fragP->fr_symbol->sy_type & N_TYPE) == N_TEXT)
  2998.       {
  2999.     /* we can only fix operations on data registers, not on <ea> */
  3000.     if ((fragP->fr_opcode[1] & 0x38) != 0)
  3001.       {
  3002.         /* use the normal reloc32, sigh... */
  3003.         fix_new (fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,(symbolS *)0, fragP->fr_offset, 0, 0);
  3004.         fragP->fr_fix += 4;
  3005.         break;
  3006.       }
  3007.  
  3008.         /* so this is really a pc-relative address
  3009.          * What we have to do now is a VERY UGLY AND BIG KLUDGE. Basically do the
  3010.          * following thing:
  3011.          *   turn
  3012.          *     addl #foo,d0      (foo is N_TEXT)
  3013.          *   into
  3014.          *     pea  foo(pc)
  3015.          *     addl (sp)+,d0
  3016.          */
  3017.         *buffer_address++ = fragP->fr_opcode[0]; /* save the original command */
  3018.     *buffer_address++ = fragP->fr_opcode[1];
  3019.         fragP->fr_opcode[0] = 0x48;     /* PEA */
  3020.         fragP->fr_opcode[1] = 0x7a;
  3021.         fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0, fragP->fr_offset+2, 1, 0);
  3022.     
  3023.         *buffer_address++ = 0x9f;    /* sp@+ */
  3024.     fragP->fr_fix += 4;    /* two byte fix, two byte code extension */
  3025.     break;
  3026.       }
  3027.     /* in that case we have to generate base-relative code
  3028.      * (note: if we're in N_UNDF, this could as well be pc-relative, but the linker
  3029.      *        will have to do the final patch in that case) */
  3030.  
  3031.     /* analogous (more or less;-)) to above, the following conversion is done
  3032.      *   turn
  3033.      *     addl #bar,d0        (bar is N_DATA)
  3034.      *   into
  3035.      *       addl #<bar>,d0    where <bar> is a baserel-reloc
  3036.      *     addl a4,d0
  3037.      */
  3038.  
  3039.     fix_new(fragP,(int)(fragP->fr_fix), 4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset, 0, 1);
  3040.     *buffer_address++ = 0xd0;
  3041.     *buffer_address++ = 0x8c;
  3042.     break;
  3043.   
  3044.   }
  3045.   if(ext) {
  3046.     md_number_to_chars(buffer_address,(long)disp,(int)ext);
  3047.     fragP->fr_fix+=ext;
  3048.   }
  3049. }
  3050.  
  3051. /* Force truly undefined symbols to their maximum size, and generally set up
  3052.    the frag list to be relaxed
  3053.  */
  3054. int
  3055. md_estimate_size_before_relax(fragP,segtype)
  3056. register fragS *fragP;
  3057. int segtype;
  3058. {
  3059.     int    old_fix;
  3060.     register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  3061.  
  3062.     old_fix=fragP->fr_fix;
  3063.  
  3064. DP(("md_estimate_size_before_relax, fragP->fr_subtype = $%x\n",fragP->fr_subtype));
  3065.     /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  3066.     switch(fragP->fr_subtype) {
  3067.     case TAB(BRANCH,SZ_UNDEF):
  3068.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3069.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  3070.             break;
  3071.         } else if(flagseen['m']) {
  3072.             if(fragP->fr_opcode[0]==0x61) { /* BSR */
  3073.                 if (flagseen['p']) {
  3074.                     /* leave the BSR, no need to change
  3075.                      * it into a JSR (PC,..) */
  3076.                     subseg_change(SEG_TEXT, 0);
  3077.                     fix_new(fragP, fragP->fr_fix, 2, 
  3078.                         fragP->fr_symbol, 0, fragP->fr_offset, 1, 0);
  3079.                     fragP->fr_fix+=2;
  3080.                 } else if(flagseen['l']) {
  3081. #if 0
  3082.                     fragP->fr_opcode[0]= 0x4E;
  3083.                     fragP->fr_opcode[1]= 0xB8;    /* JBSR with ABSL WORD offset */
  3084.                     subseg_change(SEG_TEXT, 0);
  3085.                     fix_new(fragP, fragP->fr_fix, 2, 
  3086.                         fragP->fr_symbol, 0, fragP->fr_offset, 0, 0);
  3087.                     fragP->fr_fix+=2;
  3088. #else
  3089.                     subseg_change(SEG_TEXT, 0);
  3090.             fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,
  3091.  (symbolS *)0,fragP->fr_offset + 2,1, 0);
  3092.             fragP->fr_fix+=2;
  3093.             fragP->fr_opcode[1]=0x00;
  3094. #endif
  3095.                 } else {
  3096.                     fragP->fr_opcode[0]= 0x4E;
  3097.                     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  3098.                     subseg_change(SEG_TEXT, 0);
  3099.                     fix_new(fragP, fragP->fr_fix, 4, 
  3100.                         fragP->fr_symbol, 0, fragP->fr_offset, 0, 0);
  3101.                     fragP->fr_fix+=4;
  3102.                 }
  3103.                 frag_wane(fragP);
  3104.             } else if(fragP->fr_opcode[0]==0x60) {    /* BRA */
  3105.                 if(flagseen['p']) {
  3106.                     subseg_change(SEG_TEXT, 0);
  3107.                     fix_new(fragP, fragP->fr_fix, 2, 
  3108.                         fragP->fr_symbol, 0, fragP->fr_offset, 1, 0);
  3109.                     fragP->fr_fix+=2;
  3110.                 } else if(flagseen['l']) {
  3111.                     fragP->fr_opcode[0]= 0x4E;
  3112.                     fragP->fr_opcode[1]= 0xF8;    /* JMP    with ABSL WORD offset */
  3113.                     subseg_change(SEG_TEXT, 0);
  3114.                     fix_new(fragP, fragP->fr_fix, 2, 
  3115.                         fragP->fr_symbol, 0, fragP->fr_offset, 0, 0);
  3116.                     fragP->fr_fix+=2;
  3117.                 } else {
  3118.                     fragP->fr_opcode[0]= 0x4E;
  3119.                     fragP->fr_opcode[1]= 0xF9;    /* JMP    with ABSL LONG offset */
  3120.                     subseg_change(SEG_TEXT, 0);
  3121.                     fix_new(fragP, fragP->fr_fix, 4, 
  3122.                         fragP->fr_symbol, 0, fragP->fr_offset, 0, 0);
  3123.                     fragP->fr_fix+=4;
  3124.                 }
  3125.                 frag_wane(fragP);
  3126.             } else {
  3127.                 as_warn("Long branch offset to extern symbol not supported.");
  3128.             }
  3129.         } else if(flagseen['l']) {    /* Symbol is still undefined.  Make it simple */
  3130.             fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,
  3131.  (symbolS *)0,fragP->fr_offset + 2,1, 0);
  3132.             fragP->fr_fix+=2;
  3133.             fragP->fr_opcode[1]=0x00;
  3134.             frag_wane(fragP);
  3135.         } else {
  3136. DP(("TAB(BRANCH,SZ_UNDEF)\n"));
  3137.             fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  3138.  (symbolS *)0,fragP->fr_offset + 4,1,0);
  3139.             fragP->fr_fix+=4;
  3140.             fragP->fr_opcode[1]=0xff;
  3141.             frag_wane(fragP);
  3142.             break;
  3143.         }
  3144.         break;
  3145.  
  3146.     case TAB(FBRANCH,SZ_UNDEF):
  3147.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  3148.             fragP->fr_subtype=TAB(FBRANCH,SHORT);
  3149.             fragP->fr_var+=2;
  3150.         } else {
  3151.             fragP->fr_subtype=TAB(FBRANCH,LONG);
  3152.             fragP->fr_var+=4;
  3153.         }
  3154.         break;
  3155.  
  3156.     case TAB(PCREL,SZ_UNDEF):
  3157. DP(("TAB(PCREL,SZ_UNDEF)\n"));
  3158.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l'] || flagseen['p']) {
  3159.             fragP->fr_subtype=TAB(PCREL,SHORT);
  3160.             fragP->fr_var+=2;
  3161.         } else {
  3162.             fragP->fr_subtype=TAB(PCREL,LONG);
  3163.             fragP->fr_var+=4;
  3164.         }
  3165.         break;
  3166.  
  3167.     case TAB(BCC68000,SZ_UNDEF):
  3168.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3169.             fragP->fr_subtype=TAB(BCC68000,BYTE);
  3170.             break;
  3171.         }
  3172.         /* only Bcc 68000 instructions can come here */
  3173.         /* change bcc into b!cc/jmp absl long */
  3174.         fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  3175.         if(flagseen['l']) {
  3176.             fragP->fr_opcode[1] = 0x04;   /* branch offset = 6 */
  3177.             /* JF: these were fr_opcode[2,3] */
  3178.             buffer_address[0] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3179.             buffer_address[1] = 0xf8;
  3180.             fragP->fr_fix += 2;         /* account for jmp instruction */
  3181.             subseg_change(SEG_TEXT,0);
  3182.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3183.                              fragP->fr_offset,0,0);
  3184.             fragP->fr_fix += 2;
  3185.         } else {
  3186.             fragP->fr_opcode[1] = 0x06;   /* branch offset = 6 */
  3187.             /* JF: these were fr_opcode[2,3] */
  3188.             buffer_address[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3189.             buffer_address[3] = 0xf9;
  3190.             fragP->fr_fix += 2;         /* account for jmp instruction */
  3191.             subseg_change(SEG_TEXT,0);
  3192.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3193.                              fragP->fr_offset,0,0);
  3194.             fragP->fr_fix += 4;
  3195.         }
  3196.         frag_wane(fragP);
  3197.         break;
  3198.  
  3199.     case TAB(DBCC,SZ_UNDEF):
  3200.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3201.             fragP->fr_subtype=TAB(DBCC,SHORT);
  3202.             fragP->fr_var+=2;
  3203.             break;
  3204.         }
  3205.         /* only DBcc 68000 instructions can come here */
  3206.         /* change dbcc into dbcc/jmp absl long */
  3207.         /* JF: these used to be fr_opcode[2-4], which is wrong. */
  3208.         buffer_address[0] = 0x00;  /* branch offset = 4 */
  3209.         buffer_address[1] = 0x04;  
  3210.         buffer_address[2] = 0x60;  /* put in bra pc + ... */ 
  3211.         if(flagseen['l']) {
  3212.             /* JF: these were fr_opcode[5-7] */
  3213.             buffer_address[3] = 0x04; /* plus 4 */
  3214.             buffer_address[4] = 0x4e;/* Put in Jump Word */
  3215.             buffer_address[5] = 0xf8;
  3216.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3217.             subseg_change(SEG_TEXT,0);
  3218.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3219.                              fragP->fr_offset,0,0);
  3220.             fragP->fr_fix+=2;
  3221.         } else {
  3222.             /* JF: these were fr_opcode[5-7] */
  3223.             buffer_address[3] = 0x06;  /* Plus 6 */
  3224.             buffer_address[4] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3225.             buffer_address[5] = 0xf9;  
  3226.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3227.             subseg_change(SEG_TEXT,0);
  3228.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3229.                              fragP->fr_offset,0,0);
  3230.             fragP->fr_fix += 4;
  3231.         }
  3232.         frag_wane(fragP);
  3233.         break;
  3234.  
  3235.     case TAB(PCLEA,SZ_UNDEF):
  3236. DP(("TAB(PCLEA,SZ_UNDEF)\n"));
  3237.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l'] || flagseen['p']) {
  3238.             fragP->fr_subtype=TAB(PCLEA,SHORT);
  3239.             fragP->fr_var+=2;
  3240.         } else {
  3241.             fragP->fr_subtype=TAB(PCLEA,LONG);
  3242.             fragP->fr_var+=6;
  3243.         }
  3244.         break;
  3245.  
  3246.     case TAB(ABSREL,SZ_UNDEF):
  3247. DP(("TAB(ABSREL,SZ_UNDEF)\n"));
  3248.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l'] || flagseen['p']) {
  3249.             fragP->fr_subtype=TAB(ABSREL,SHORT);
  3250.             fragP->fr_var+=2;
  3251.         } else {
  3252.             fragP->fr_subtype=TAB(ABSREL,LONG);
  3253.             fragP->fr_var+=6;
  3254.         }
  3255.         break;
  3256.  
  3257.     default:
  3258.         break;
  3259.     }
  3260.  
  3261.     /* now that SZ_UNDEF are taken care of, check others */
  3262.     switch(fragP->fr_subtype) {
  3263.     case TAB(BCC68000,BYTE):
  3264.     case TAB(BRANCH,BYTE):
  3265.             /* We can't do a short jump to the next instruction,
  3266.                so we force word mode.  */
  3267.         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  3268.  fragP->fr_symbol->sy_frag==fragP->fr_next) {
  3269.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  3270.             fragP->fr_var+=2;
  3271.         }
  3272.         break;
  3273.     default:
  3274.         break;
  3275.     }
  3276.     return fragP->fr_var + fragP->fr_fix - old_fix;
  3277. }
  3278.  
  3279. /* the bit-field entries in the relocation_info struct plays hell 
  3280.    with the byte-order problems of cross-assembly.  So as a hack,
  3281.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  3282.    you there. -KWK */
  3283. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  3284. are symbolnum, most sig. byte first.  Last byte is broken up with
  3285. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  3286. nibble as nuthin. (on Sun 3 at least) */
  3287. void
  3288. md_ri_to_chars(ri_p, ri)
  3289.      struct relocation_info *ri_p, ri;
  3290. {
  3291.   unsigned char the_bytes[8];
  3292.  
  3293. DP(("md_ri_to_chars: baserel = %d\n", ri.r_baserel));
  3294.  
  3295.   /* this is easy */
  3296.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  3297.   /* now the fun stuff */
  3298.   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  3299.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  3300.   the_bytes[6] = ri.r_symbolnum & 0x0ff;
  3301.   the_bytes[7] = (((ri.r_pcrel << 7)  & 0x80) | ((ri.r_length << 5) & 0x60) | 
  3302.     ((ri.r_extern << 4)  & 0x10) | ((ri.r_baserel << 3) & 0x08)); 
  3303.   /* now put it back where you found it */
  3304.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  3305. }
  3306.  
  3307. #ifndef WORKING_DOT_WORD
  3308. int md_short_jump_size = 4;
  3309. int md_long_jump_size = 6;
  3310.  
  3311. void
  3312. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3313. char    *ptr;
  3314. long    from_addr,
  3315.     to_addr;
  3316. fragS    *frag;
  3317. symbolS    *to_symbol;
  3318. {
  3319.     long offset;
  3320.  
  3321.     offset = to_addr - (from_addr+2);
  3322.  
  3323.     md_number_to_chars(ptr  ,(long)0x6000,2);
  3324.     md_number_to_chars(ptr+2,(long)offset,2);
  3325. }
  3326.  
  3327. void
  3328. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3329. char    *ptr;
  3330. long    from_addr,
  3331.     to_addr;
  3332. fragS    *frag;
  3333. symbolS    *to_symbol;
  3334. {
  3335.     long offset;
  3336.  
  3337.     if(flagseen['m']) {
  3338.         offset=to_addr-to_symbol->sy_value;
  3339.         md_number_to_chars(ptr  ,(long)0x4EF9,2);
  3340.         md_number_to_chars(ptr+2,(long)offset,4);
  3341.         fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0,0);
  3342.     } else {
  3343.         offset=to_addr - (from_addr+2);
  3344.         md_number_to_chars(ptr  ,(long)0x60ff,2);
  3345.         md_number_to_chars(ptr+2,(long)offset,4);
  3346.     }
  3347. }
  3348.  
  3349. #endif
  3350. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  3351.  
  3352.     0:  Everything is OK
  3353.     10:  Absolute 1:8    only
  3354.     20:  Absolute 0:7    only
  3355.     30:  absolute 0:15    only
  3356.     40:  Absolute 0:31    only
  3357.     50:  absolute 0:127    only
  3358.     55:  absolute -64:63    only
  3359.     60:  absolute -128:127    only
  3360.     70:  absolute 0:4095    only
  3361.     80:  No bignums
  3362.  
  3363. */
  3364. int
  3365. get_num(exp,ok)
  3366. struct m68k_exp *exp;
  3367. int ok;
  3368. {
  3369. #ifdef TEST2
  3370.     long    l = 0;
  3371.  
  3372.     if(!exp->e_beg)
  3373.         return 0;
  3374.     if(*exp->e_beg=='0') {
  3375.         if(exp->e_beg[1]=='x')
  3376.             sscanf(exp->e_beg+2,"%x",&l);
  3377.         else
  3378.             sscanf(exp->e_beg+1,"%O",&l);
  3379.         return l;
  3380.     }
  3381.     return atol(exp->e_beg);
  3382. #else
  3383.     char    *save_in;
  3384.     char    c_save;
  3385.  
  3386.     if(!exp) {
  3387.         /* Can't do anything */
  3388.         return 0;
  3389.     }
  3390.     if(!exp->e_beg || !exp->e_end) {
  3391.         seg(exp)=SEG_ABSOLUTE;
  3392.         adds(exp)=0;
  3393.         subs(exp)=0;
  3394.         offs(exp)= (ok==10) ? 1 : 0;
  3395.         as_warn("Null expression defaults to %ld",offs(exp));
  3396.         return 0;
  3397.     }
  3398.  
  3399.     exp->e_siz=0;
  3400.     exp->e_baserel = 0;
  3401.     if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>=2) {
  3402.         switch(exp->e_end[0]) {
  3403.         case 'B':
  3404.             exp->e_baserel = 1;
  3405.         case 's':
  3406.         case 'S':
  3407.         case 'b':
  3408.             exp->e_siz=1;
  3409.             break;
  3410.         case 'W':
  3411.             exp->e_baserel = 1;
  3412.         case 'w':
  3413.             exp->e_siz=2;
  3414.             break;
  3415.         case 'L':
  3416.             exp->e_baserel = 1;
  3417.         case 'l':
  3418.             exp->e_siz=3;
  3419.             break;
  3420.         default:
  3421.             as_bad("Unknown size for expression \"%c\"",exp->e_end[0]);
  3422.         }
  3423.         exp->e_end-=2;
  3424.     }
  3425.     c_save=exp->e_end[1];
  3426.     exp->e_end[1]='\0';
  3427.     save_in=input_line_pointer;
  3428.     input_line_pointer=exp->e_beg;
  3429.     switch(expression(&(exp->e_exp))) {
  3430.     case SEG_PASS1:
  3431.         seg(exp)=SEG_ABSOLUTE;
  3432.         adds(exp)=0;
  3433.         subs(exp)=0;
  3434.         offs(exp)= (ok==10) ? 1 : 0;
  3435.         as_warn("Unknown expression: '%s' defaulting to %d",exp->e_beg,offs(exp));
  3436.         break;
  3437.  
  3438.     case SEG_NONE:
  3439.         /* Do the same thing the VAX asm does */
  3440.         seg(exp)=SEG_ABSOLUTE;
  3441.         adds(exp)=0;
  3442.         subs(exp)=0;
  3443.         offs(exp)=0;
  3444.         if(ok==10) {
  3445.             as_warn("expression out of range: defaulting to 1");
  3446.             offs(exp)=1;
  3447.         }
  3448.         break;
  3449.     case SEG_ABSOLUTE:
  3450.         switch(ok) {
  3451.         case 10:
  3452.             if(offs(exp)<1 || offs(exp)>8) {
  3453.                 as_warn("expression out of range: defaulting to 1");
  3454.                 offs(exp)=1;
  3455.             }
  3456.             break;
  3457.         case 20:
  3458.             if(offs(exp)<0 || offs(exp)>7)
  3459.                 goto outrange;
  3460.             break;
  3461.         case 30:
  3462.             if(offs(exp)<0 || offs(exp)>15)
  3463.                 goto outrange;
  3464.             break;
  3465.         case 40:
  3466.             if(offs(exp)<0 || offs(exp)>32)
  3467.                 goto outrange;
  3468.             break;
  3469.         case 50:
  3470.             if(offs(exp)<0 || offs(exp)>127)
  3471.                 goto outrange;
  3472.             break;
  3473.         case 55:
  3474.             if(offs(exp)<-64 || offs(exp)>63)
  3475.                 goto outrange;
  3476.             break;
  3477.         case 60:
  3478.             if(offs(exp)<-128 || offs(exp)>127)
  3479.                 goto outrange;
  3480.             break;
  3481.         case 70:
  3482.             if(offs(exp)<0 || offs(exp)>4095) {
  3483.             outrange:
  3484.                 as_warn("expression out of range: defaulting to 0");
  3485.                 offs(exp)=0;
  3486.             }
  3487.             break;
  3488.         default:
  3489.             break;
  3490.         }
  3491.         break;
  3492.     case SEG_TEXT:
  3493.     case SEG_DATA:
  3494.     case SEG_BSS:
  3495.     case SEG_UNKNOWN:
  3496.     case SEG_DIFFERENCE:
  3497.         if(ok>=10 && ok<=70) {
  3498.             seg(exp)=SEG_ABSOLUTE;
  3499.             adds(exp)=0;
  3500.             subs(exp)=0;
  3501.             offs(exp)= (ok==10) ? 1 : 0;
  3502.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3503.         }
  3504.         break;
  3505.     case SEG_BIG:
  3506.         if(ok==80 && offs(exp)<0) {    /* HACK! Turn it into a long */
  3507.             LITTLENUM_TYPE words[6];
  3508.  
  3509.             gen_to_words(words,2,8L);/* These numbers are magic! */
  3510.             seg(exp)=SEG_ABSOLUTE;
  3511.             adds(exp)=0;
  3512.             subs(exp)=0;
  3513.             offs(exp)=words[1]|(words[0]<<16);
  3514.         } else if(ok!=0) {
  3515.             seg(exp)=SEG_ABSOLUTE;
  3516.             adds(exp)=0;
  3517.             subs(exp)=0;
  3518.             offs(exp)= (ok==10) ? 1 : 0;
  3519.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3520.         }
  3521.         break;
  3522.     default:
  3523.         abort();
  3524.     }
  3525.     if(input_line_pointer!=exp->e_end+1)
  3526.         as_bad("Ignoring junk after expression");
  3527.     exp->e_end[1]=c_save;
  3528.     input_line_pointer=save_in;
  3529.     if(exp->e_siz) {
  3530.         switch(exp->e_siz) {
  3531.         case 1:
  3532.             if(!isbyte(offs(exp)))
  3533.                 as_warn("expression doesn't fit in BYTE");
  3534.             break;
  3535.         case 2:
  3536.             if(!isword(offs(exp)))
  3537.                 as_warn("expression doesn't fit in WORD");
  3538.             break;
  3539.         }
  3540.     }
  3541.     return offs(exp);
  3542. #endif
  3543. }
  3544.  
  3545. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  3546. void demand_empty_rest_of_line();    /* Hate those extra verbose names */
  3547.  
  3548. void
  3549. s_data1()
  3550. {
  3551.     subseg_new(SEG_DATA,1);
  3552.     demand_empty_rest_of_line();
  3553. }
  3554.  
  3555. void
  3556. s_data2()
  3557. {
  3558.     subseg_new(SEG_DATA,2);
  3559.     demand_empty_rest_of_line();
  3560. }
  3561.  
  3562. void
  3563. s_even()
  3564. {
  3565.     register int temp;
  3566.     register long int temp_fill;
  3567.  
  3568.     temp = 1;        /* JF should be 2? */
  3569.     temp_fill = get_absolute_expression ();
  3570.     if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  3571.         frag_align (temp, (int)temp_fill);
  3572.     demand_empty_rest_of_line();
  3573. }
  3574.  
  3575. void
  3576. s_proc()
  3577. {
  3578.     demand_empty_rest_of_line();
  3579. }
  3580.  
  3581. /* s_space is defined in read.c .skip is simply an alias to it. */
  3582.  
  3583. int
  3584. md_parse_option(argP,cntP,vecP)
  3585. char **argP;
  3586. int *cntP;
  3587. char ***vecP;
  3588. {
  3589.     switch(**argP) {
  3590.     /* additions for pc- and base-relative conversions, MW */
  3591.     case 's':
  3592.         (*argP)++;
  3593.         while (**argP)
  3594.           {
  3595.             if (**argP == 'c')
  3596.               /* small-code, generate pc-relative code */
  3597.               flagseen['p'] = 1;
  3598.             else if (**argP == 'd')
  3599.               flagseen['b'] = 1;
  3600.             else
  3601.               as_warn ("Unknown -s option ignored.");
  3602.             (*argP)++;
  3603.           }
  3604.         break;
  3605.  
  3606.     case 'l':    /* -l means keep external to 2 bit offset
  3607.                rather than 16 bit one */
  3608.         break;
  3609.  
  3610.     case 'm':
  3611.         /* Gas almost ignores this option! */
  3612.         (*argP)++;
  3613.         if(**argP=='c')
  3614.             (*argP)++;
  3615.         if(!strcmp(*argP,"68000")) {
  3616.             flagseen['m']=2;
  3617.             mid = MID_SUN010;    /* rather than SUN020 */
  3618.         } else if(!strcmp(*argP,"68010")) {
  3619.             mid = MID_SUN010;
  3620.             flagseen['m']=1;
  3621.         } else if(!strcmp(*argP,"68020"))
  3622.             flagseen['m']=0;
  3623.         else
  3624.             as_warn("Unknown -m option ignored");
  3625.         while(**argP)
  3626.             (*argP)++;
  3627.         break;
  3628.  
  3629.     default:
  3630.         return 0;
  3631.     }
  3632.     return 1;
  3633. }
  3634.  
  3635.  
  3636. #ifdef TEST2
  3637.  
  3638. /* TEST2:  Test md_assemble() */
  3639. /* Warning, this routine probably doesn't work anymore */
  3640.  
  3641. main()
  3642. {
  3643.     struct m68_it the_ins;
  3644.     char buf[120];
  3645.     char *cp;
  3646.     int    n;
  3647.  
  3648.     m68_ip_begin();
  3649.     for(;;) {
  3650.         if(!gets(buf) || !*buf)
  3651.             break;
  3652.         if(buf[0]=='|' || buf[1]=='.')
  3653.             continue;
  3654.         for(cp=buf;*cp;cp++)
  3655.             if(*cp=='\t')
  3656.                 *cp=' ';
  3657.         if(is_label(buf))
  3658.             continue;
  3659.         bzero(&the_ins,sizeof(the_ins));
  3660.         m68_ip(&the_ins,buf);
  3661.         if(the_ins.error) {
  3662.             printf("Error %s in %s\n",the_ins.error,buf);
  3663.         } else {
  3664.             printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  3665.             for(n=0;n<the_ins.numo;n++)
  3666.                 printf(" 0x%x",the_ins.opcode[n]&0xffff);
  3667.             printf("    ");
  3668.             print_the_insn(&the_ins.opcode[0],stdout);
  3669.             (void)putchar('\n');
  3670.         }
  3671.         for(n=0;n<strlen(the_ins.args)/2;n++) {
  3672.             if(the_ins.operands[n].error) {
  3673.                 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  3674.                 continue;
  3675.             }
  3676.             printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  3677.             if(the_ins.operands[n].b_const)
  3678.                 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  3679.             printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  3680.             if(the_ins.operands[n].b_iadd)
  3681.                 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  3682.             (void)putchar('\n');
  3683.         }
  3684.     }
  3685.     m68_ip_end();
  3686.     return 0;
  3687. }
  3688.  
  3689. is_label(str)
  3690. char *str;
  3691. {
  3692.     while(*str==' ')
  3693.         str++;
  3694.     while(*str && *str!=' ')
  3695.         str++;
  3696.     if(str[-1]==':' || str[1]=='=')
  3697.         return 1;
  3698.     return 0;
  3699. }
  3700.  
  3701. #endif
  3702.  
  3703. /* Possible states for relaxation:
  3704.  
  3705. 0 0    branch offset    byte    (bra, etc)
  3706. 0 1            word
  3707. 0 2            long
  3708.  
  3709. 1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  3710. 1 1            word
  3711. 1 2            long
  3712.  
  3713. 2 0    two-offset index word-word a0@(32,d4)@(45) etc
  3714. 2 1            word-long
  3715. 2 2            long-word
  3716. 2 3            long-long
  3717.  
  3718. */
  3719.  
  3720.  
  3721.  
  3722. #ifdef DONTDEF
  3723. abort()
  3724. {
  3725.     printf("ABORT!\n");
  3726.     exit(12);
  3727. }
  3728.  
  3729. char *index(s,c)
  3730. char *s;
  3731. {
  3732.     while(*s!=c) {
  3733.         if(!*s) return 0;
  3734.         s++;
  3735.     }
  3736.     return s;
  3737. }
  3738.  
  3739. bzero(s,n)
  3740. char *s;
  3741. {
  3742.     while(n--)
  3743.         *s++=0;
  3744. }
  3745.  
  3746. print_frags()
  3747. {
  3748.     fragS *fragP;
  3749.     extern fragS *text_frag_root;
  3750.  
  3751.     for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3752.         printf("addr %lu  next 0x%x  fix %ld  var %ld  symbol 0x%x  offset %ld\n",
  3753.  fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3754.         printf("opcode 0x%x  type %d  subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3755.     }
  3756.     fflush(stdout);
  3757.     return 0;
  3758. }
  3759. #endif
  3760.  
  3761. #ifdef DONTDEF
  3762. /*VARARGS1*/
  3763. panic(format,args)
  3764. char *format;
  3765. {
  3766.     fputs("Internal error:",stderr);
  3767.     _doprnt(format,&args,stderr);
  3768.     (void)putc('\n',stderr);
  3769.     as_where();
  3770.     abort();
  3771. }
  3772. #endif
  3773.