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