home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Source / GNU / cctools / as / m68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-20  |  87.8 KB  |  3,899 lines

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