home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / gas / config / tc-m68k.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  161KB  |  6,784 lines

  1. /* tc-m68k.c -- Assemble for the m68k family
  2.    Copyright (C) 1987, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to the Free
  18.    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  19.    02111-1307, USA.  */
  20.  
  21. #include <ctype.h>
  22. #include "as.h"
  23. #include "obstack.h"
  24. #include "subsegs.h"
  25.  
  26. #include "opcode/m68k.h"
  27. #include "m68k-parse.h"
  28.  
  29. /* This string holds the chars that always start a comment.  If the
  30.    pre-processor is disabled, these aren't very useful.  The macro
  31.    tc_comment_chars points to this.  We use this, rather than the
  32.    usual comment_chars, so that the --bitwise-or option will work.  */
  33. #if (defined (OBJ_ELF) && ! defined (TE_PSOS) && ! defined (TE_LINUX)) || defined (TE_DELTA)
  34. const char *m68k_comment_chars = "|#";
  35. #else
  36. const char *m68k_comment_chars = "|";
  37. #endif
  38.  
  39. /* This array holds the chars that only start a comment at the beginning of
  40.    a line.  If the line seems to have the form '# 123 filename'
  41.    .line and .file directives will appear in the pre-processed output */
  42. /* Note that input_file.c hand checks for '#' at the beginning of the
  43.    first line of the input file.  This is because the compiler outputs
  44.    #NO_APP at the beginning of its output. */
  45. /* Also note that comments like this one will always work. */
  46. const char line_comment_chars[] = "#";
  47.  
  48. const char line_separator_chars[] = "";
  49.  
  50. /* Chars that can be used to separate mant from exp in floating point nums */
  51. CONST char EXP_CHARS[] = "eE";
  52.  
  53. /* Chars that mean this number is a floating point constant, as
  54.    in "0f12.456" or "0d1.2345e12".  */
  55.  
  56. CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  57.  
  58. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  59.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  60.    but nothing is ideal around here.  */
  61.  
  62. const int md_reloc_size = 8;    /* Size of relocation record */
  63.  
  64. /* Are we trying to generate PIC code?  If so, absolute references
  65.    ought to be made into linkage table references or pc-relative
  66.    references.  Not implemented.  For ELF there are other means 
  67.    to denote pic relocations.  */
  68. int flag_want_pic;
  69.  
  70. static int flag_short_refs;    /* -l option */
  71. static int flag_long_jumps;    /* -S option */
  72. static int flag_small_code;    /* -sc option */
  73.  
  74. #ifdef REGISTER_PREFIX_OPTIONAL
  75. int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
  76. #else
  77. int flag_reg_prefix_optional;
  78. #endif
  79.  
  80. /* Whether --register-prefix-optional was used on the command line.  */
  81. static int reg_prefix_optional_seen;
  82.  
  83. /* The floating point coprocessor to use by default.  */
  84. static enum m68k_register m68k_float_copnum = COP1;
  85.  
  86. /* If this is non-zero, then references to number(%pc) will be taken
  87.    to refer to number, rather than to %pc + number.  */
  88. static int m68k_abspcadd;
  89.  
  90. /* If this is non-zero, then the quick forms of the move, add, and sub
  91.    instructions are used when possible.  */
  92. static int m68k_quick = 1;
  93.  
  94. /* If this is non-zero, then if the size is not specified for a base
  95.    or outer displacement, the assembler assumes that the size should
  96.    be 32 bits.  */
  97. static int m68k_rel32 = 1;
  98.  
  99. /* Its an arbitrary name:  This means I don't approve of it */
  100. /* See flames below */
  101. static struct obstack robyn;
  102.  
  103. #define TAB(x,y)    (((x)<<2)+(y))
  104. #define TABTYPE(xy)     ((xy) >> 2)
  105. #define BYTE        0
  106. #define SHORT        1
  107. #define LONG        2
  108. #define SZ_UNDEF    3
  109. #undef BRANCH
  110. /* Case `g' except when BCC68000 is applicable.  */
  111. #define ABRANCH        1
  112. /* Coprocessor branches.  */
  113. #define FBRANCH        2
  114. /* Mode 7.2 -- program counter indirect with (16-bit) displacement,
  115.    supported on all cpus.  Widens to 32-bit absolute.  */
  116. #define PCREL        3
  117. /* For inserting an extra jmp instruction with long offset on 68000,
  118.    for expanding conditional branches.  (Not bsr or bra.)  Since the
  119.    68000 doesn't support 32-bit displacements for conditional
  120.    branches, we fake it by reversing the condition and branching
  121.    around a jmp with an absolute long operand.  */
  122. #define BCC68000        4
  123. /* For the DBcc "instructions".  If the displacement requires 32 bits,
  124.    the branch-around-a-jump game is played here too.  */
  125. #define DBCC            5
  126. /* Not currently used?  */
  127. #define PCLEA        6
  128. /* Mode AINDX (apc-relative) using PC, with variable target, might fit
  129.    in 16 or 8 bits.  */
  130. #define PCINDEX        7
  131. /* AmigaOS relocations */
  132. #define ABSREL        8
  133. #define IMMREL        9
  134.  
  135. struct m68k_incant
  136.   {
  137.     const char *m_operands;
  138.     unsigned long m_opcode;
  139.     short m_opnum;
  140.     short m_codenum;
  141.     int m_arch;
  142.     struct m68k_incant *m_next;
  143.   };
  144.  
  145. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  146. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  147.  
  148. static const enum m68k_register m68000_control_regs[] = { 0 };
  149. static const enum m68k_register m68010_control_regs[] = {
  150.   SFC, DFC, USP, VBR,
  151.   0
  152. };
  153. static const enum m68k_register m68020_control_regs[] = {
  154.   SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
  155.   0
  156. };
  157. static const enum m68k_register m68040_control_regs[] = {
  158.   SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
  159.   USP, VBR, MSP, ISP, MMUSR, URP, SRP,
  160.   0
  161. };
  162. static const enum m68k_register m68060_control_regs[] = {
  163.   SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
  164.   USP, VBR, URP, SRP, PCR,
  165.   0
  166. };
  167. static const enum m68k_register mcf5200_control_regs[] = {
  168.   CACR, TC, ITT0, ITT1, DTT0, DTT1, VBR, ROMBAR, 
  169.   RAMBAR0, RAMBAR1, MBAR,
  170.   0
  171. };
  172. #define cpu32_control_regs m68010_control_regs
  173.  
  174. static const enum m68k_register *control_regs;
  175.  
  176. /* internal form of a 68020 instruction */
  177. struct m68k_it
  178. {
  179.   const char *error;
  180.   const char *args;        /* list of opcode info */
  181.   int numargs;
  182.  
  183.   int numo;            /* Number of shorts in opcode */
  184.   short opcode[11];
  185.  
  186.   struct m68k_op operands[6];
  187.  
  188.   int nexp;            /* number of exprs in use */
  189.   struct m68k_exp exprs[4];
  190.  
  191.   int nfrag;            /* Number of frags we have to produce */
  192.   struct
  193.     {
  194.       int fragoff;        /* Where in the current opcode the frag ends */
  195.       symbolS *fadd;
  196.       long foff;
  197.       int fragty;
  198.     }
  199.   fragb[4];
  200.  
  201.   int nrel;            /* Num of reloc strucs in use */
  202.   struct
  203.     {
  204.       int n;
  205.       expressionS exp;
  206.       char wid;
  207.       char pcrel;
  208.       /* In a pc relative address the difference between the address
  209.      of the offset and the address that the offset is relative
  210.      to.  This depends on the addressing mode.  Basically this
  211.      is the value to put in the offset field to address the
  212.      first byte of the offset, without regarding the special
  213.      significance of some values (in the branch instruction, for
  214.      example).  */
  215.       int pcrel_fix;
  216. #ifdef OBJ_ELF
  217.       /* Whether this expression needs special pic relocation, and if
  218.      so, which.  */
  219.       enum pic_relocation pic_reloc;
  220. #endif
  221.       char baserel;
  222.     }
  223.   reloc[5];            /* Five is enough??? */
  224. };
  225.  
  226. #define cpu_of_arch(x)        ((x) & (m68000up|mcf5200))
  227. #define float_of_arch(x)    ((x) & mfloat)
  228. #define mmu_of_arch(x)        ((x) & mmmu)
  229.  
  230. static struct m68k_it the_ins;    /* the instruction being assembled */
  231.  
  232. #define op(ex)        ((ex)->exp.X_op)
  233. #define adds(ex)    ((ex)->exp.X_add_symbol)
  234. #define subs(ex)    ((ex)->exp.X_op_symbol)
  235. #define offs(ex)    ((ex)->exp.X_add_number)
  236.  
  237. /* Macros for adding things to the m68k_it struct */
  238.  
  239. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  240.  
  241. /* Like addword, but goes BEFORE general operands */
  242. static void
  243. insop (w, opcode)
  244.      int w;
  245.      struct m68k_incant *opcode;
  246. {
  247.   int z;
  248.   for(z=the_ins.numo;z>opcode->m_codenum;--z)
  249.     the_ins.opcode[z]=the_ins.opcode[z-1];
  250.   for(z=0;z<the_ins.nrel;z++)
  251.     the_ins.reloc[z].n+=2;
  252.   for (z = 0; z < the_ins.nfrag; z++)
  253.     the_ins.fragb[z].fragoff++;
  254.   the_ins.opcode[opcode->m_codenum]=w;
  255.   the_ins.numo++;
  256. }
  257.  
  258. /* The numo+1 kludge is so we can hit the low order byte of the prev word.
  259.    Blecch.  */
  260. static void
  261. add_fix (width, exp, pc_rel, pc_fix, base_rel)
  262.      char width;
  263.      struct m68k_exp *exp;
  264.      int pc_rel;
  265.      int pc_fix;
  266.      int base_rel;
  267. {
  268.   the_ins.reloc[the_ins.nrel].n = (((width)=='B')
  269.                    ? (the_ins.numo*2-1)
  270.                    : (((width)=='b')
  271.                       ? (the_ins.numo*2+1)
  272.                       : (the_ins.numo*2)));
  273.   the_ins.reloc[the_ins.nrel].exp = exp->exp;
  274.   the_ins.reloc[the_ins.nrel].wid = width;
  275.   the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
  276. #ifdef OBJ_ELF
  277.   the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
  278. #endif
  279.   the_ins.reloc[the_ins.nrel].pcrel = pc_rel;
  280.   the_ins.reloc[the_ins.nrel++].baserel = base_rel;
  281. }
  282.  
  283. /* Cause an extra frag to be generated here, inserting up to 10 bytes
  284.    (that value is chosen in the frag_var call in md_assemble).  TYPE
  285.    is the subtype of the frag to be generated; its primary type is
  286.    rs_machine_dependent.
  287.  
  288.    The TYPE parameter is also used by md_convert_frag_1 and
  289.    md_estimate_size_before_relax.  The appropriate type of fixup will
  290.    be emitted by md_convert_frag_1.
  291.  
  292.    ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET.  */
  293. static void
  294. add_frag(add,off,type)
  295.      symbolS *add;
  296.      long off;
  297.      int type;
  298. {
  299.   the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;
  300.   the_ins.fragb[the_ins.nfrag].fadd=add;
  301.   the_ins.fragb[the_ins.nfrag].foff=off;
  302.   the_ins.fragb[the_ins.nfrag++].fragty=type;
  303. }
  304.  
  305. #define isvar(ex) \
  306.   (op (ex) != O_constant && op (ex) != O_big)
  307.  
  308. static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
  309. static int get_num PARAMS ((struct m68k_exp *exp, int ok));
  310. static int reverse_16_bits PARAMS ((int in));
  311. static int reverse_8_bits PARAMS ((int in));
  312. static void install_gen_operand PARAMS ((int mode, int val));
  313. static void install_operand PARAMS ((int mode, int val));
  314. static void s_bss PARAMS ((int));
  315. static void s_data1 PARAMS ((int));
  316. static void s_data2 PARAMS ((int));
  317. static void s_even PARAMS ((int));
  318. static void s_proc PARAMS ((int));
  319. static void mri_chip PARAMS ((void));
  320. static void s_chip PARAMS ((int));
  321. static void s_fopt PARAMS ((int));
  322. static void s_opt PARAMS ((int));
  323. static void s_reg PARAMS ((int));
  324. static void s_restore PARAMS ((int));
  325. static void s_save PARAMS ((int));
  326. static void s_mri_if PARAMS ((int));
  327. static void s_mri_else PARAMS ((int));
  328. static void s_mri_endi PARAMS ((int));
  329. static void s_mri_break PARAMS ((int));
  330. static void s_mri_next PARAMS ((int));
  331. static void s_mri_for PARAMS ((int));
  332. static void s_mri_endf PARAMS ((int));
  333. static void s_mri_repeat PARAMS ((int));
  334. static void s_mri_until PARAMS ((int));
  335. static void s_mri_while PARAMS ((int));
  336. static void s_mri_endw PARAMS ((int));
  337.  
  338. static int current_architecture;
  339.  
  340. struct m68k_cpu {
  341.   unsigned long arch;
  342.   const char *name;
  343.   int alias;
  344. };
  345.  
  346. static const struct m68k_cpu archs[] = {
  347.   { m68000, "68000", 0 },
  348.   { m68010, "68010", 0 },
  349.   { m68020, "68020", 0 },
  350.   { m68030, "68030", 0 },
  351.   { m68040, "68040", 0 },
  352.   { m68060, "68060", 0 },
  353.   { cpu32,  "cpu32", 0 },
  354.   { m68881, "68881", 0 },
  355.   { m68851, "68851", 0 },
  356.   { mcf5200, "5200", 0 },
  357.   /* Aliases (effectively, so far as gas is concerned) for the above
  358.      cpus.  */
  359.   { m68020, "68k", 1 },
  360.   { m68000, "68302", 1 },
  361.   { m68000, "68008", 1 },
  362.   { m68000, "68ec000", 1 },
  363.   { m68000, "68hc000", 1 },
  364.   { m68000, "68hc001", 1 },
  365.   { m68020, "68ec020", 1 },
  366.   { m68030, "68ec030", 1 },
  367.   { m68040, "68ec040", 1 },
  368.   { m68060, "68ec060", 1 },
  369.   { cpu32,  "68330", 1 },
  370.   { cpu32,  "68331", 1 },
  371.   { cpu32,  "68332", 1 },
  372.   { cpu32,  "68333", 1 },
  373.   { cpu32,  "68340", 1 },
  374.   { cpu32,  "68360", 1 },
  375.   { m68881, "68882", 1 },
  376. };
  377.  
  378. static const int n_archs = sizeof (archs) / sizeof (archs[0]);
  379.  
  380. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  381.    on the 68000.  The 68000 doesn't support long branches with branchs */
  382.  
  383. /* ABSREL (nice name;-)) is used in small-code, it might be 
  384.  * implemented base-relative (a4), pc-relative, or base-rel with an extra
  385.  * add instruction to add the base-register
  386.  *
  387.  * IMMREL is the analogous mode for immediate addressing of variables. This
  388.  * one can lead into situations, where a replacement is not possible:
  389.  * addl #foo,a0
  390.  * can't be made pc-relative, if foo is in the text segment */
  391.  
  392. /* This table desribes how you change sizes for the various types of variable
  393.    size expressions.  This version only supports two kinds. */
  394.  
  395. /* Note that calls to frag_var need to specify the maximum expansion
  396.    needed; this is currently 10 bytes for DBCC.  */
  397.  
  398. /* The fields are:
  399.    How far Forward this mode will reach:
  400.    How far Backward this mode will reach:
  401.    How many bytes this mode will add to the size of the frag
  402.    Which mode to go to if the offset won't fit in this one
  403.    */
  404. relax_typeS md_relax_table[] =
  405. {
  406.   {1, 1, 0, 0},            /* First entries aren't used */
  407.   {1, 1, 0, 0},            /* For no good reason except */
  408.   {1, 1, 0, 0},            /* that the VAX doesn't either */
  409.   {1, 1, 0, 0},
  410.  
  411.   {(127), (-128), 0, TAB (ABRANCH, SHORT)},
  412.   {(32767), (-32768), 2, TAB (ABRANCH, LONG)},
  413.   {0, 0, 4, 0},
  414.   {1, 1, 0, 0},
  415.  
  416.   {1, 1, 0, 0},            /* FBRANCH doesn't come BYTE */
  417.   {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
  418.   {0, 0, 4, 0},
  419.   {1, 1, 0, 0},
  420.  
  421.   {1, 1, 0, 0},            /* PCREL doesn't come BYTE */
  422.   {(32767), (-32768), 2, TAB (PCREL, LONG)},
  423.   {0, 0, 4, 0},
  424.   {1, 1, 0, 0},
  425.  
  426.   {(127), (-128), 0, TAB (BCC68000, SHORT)},
  427.   {(32767), (-32768), 2, TAB (BCC68000, LONG)},
  428.   {0, 0, 6, 0},            /* jmp long space */
  429.   {1, 1, 0, 0},
  430.  
  431.   {1, 1, 0, 0},            /* DBCC doesn't come BYTE */
  432.   {(32767), (-32768), 2, TAB (DBCC, LONG)},
  433.   {0, 0, 10, 0},        /* bra/jmp long space */
  434.   {1, 1, 0, 0},
  435.  
  436.   {1, 1, 0, 0},            /* PCLEA doesn't come BYTE */
  437.   {32767, -32768, 2, TAB (PCLEA, LONG)},
  438.   {0, 0, 6, 0},
  439.   {1, 1, 0, 0},
  440.  
  441.   /* For, e.g., jmp pcrel indexed.  */
  442.   {125, -130, 0, TAB (PCINDEX, SHORT)},
  443.   {32765, -32770, 2, TAB (PCINDEX, LONG)},
  444.   {0, 0, 4, 0},
  445.   {1, 1, 0, 0},
  446.  
  447.   {127, -128, 0, 0},
  448.   {32767, -32768, 2, TAB(ABSREL,LONG)},
  449.   {0, 0, 6, 0},
  450.   {1, 1, 0, 0},
  451.  
  452.   {127, -128, 0, 0},
  453.   {32767, -32768, 2, TAB(IMMREL,LONG)},
  454.   {0, 0, 6, 0},
  455.   {1, 1, 0, 0},
  456.  
  457. };
  458.  
  459. /* These are the machine dependent pseudo-ops.  These are included so
  460.    the assembler can work on the output from the SUN C compiler, which
  461.    generates these.
  462.    */
  463.  
  464. /* This table describes all the machine specific pseudo-ops the assembler
  465.    has to support.  The fields are:
  466.    pseudo-op name without dot
  467.    function to call to execute this pseudo-op
  468.    Integer arg to pass to the function
  469.    */
  470. const pseudo_typeS md_pseudo_table[] =
  471. {
  472.   {"data1", s_data1, 0},
  473.   {"data2", s_data2, 0},
  474.   {"bss", s_bss, 0},
  475.   {"even", s_even, 0},
  476.   {"skip", s_space, 0},
  477.   {"proc", s_proc, 0},
  478. #ifndef __amigaos__
  479. #if defined (TE_SUN3) || defined (OBJ_ELF)
  480.   {"align", s_align_bytes, 0},
  481. #endif
  482. #ifdef OBJ_ELF
  483.   {"swbeg", s_ignore, 0},
  484. #endif
  485. #endif
  486.   {"extend", float_cons, 'x'},
  487.   {"ldouble", float_cons, 'x'},
  488.  
  489.   /* The following pseudo-ops are supported for MRI compatibility.  */
  490.   {"chip", s_chip, 0},
  491.   {"comline", s_space, 1},
  492.   {"fopt", s_fopt, 0},
  493.   {"mask2", s_ignore, 0},
  494.   {"opt", s_opt, 0},
  495.   {"reg", s_reg, 0},
  496.   {"restore", s_restore, 0},
  497.   {"save", s_save, 0},
  498.  
  499.   {"if", s_mri_if, 0},
  500.   {"if.b", s_mri_if, 'b'},
  501.   {"if.w", s_mri_if, 'w'},
  502.   {"if.l", s_mri_if, 'l'},
  503.   {"else", s_mri_else, 0},
  504.   {"else.s", s_mri_else, 's'},
  505.   {"else.l", s_mri_else, 'l'},
  506.   {"endi", s_mri_endi, 0},
  507.   {"break", s_mri_break, 0},
  508.   {"break.s", s_mri_break, 's'},
  509.   {"break.l", s_mri_break, 'l'},
  510.   {"next", s_mri_next, 0},
  511.   {"next.s", s_mri_next, 's'},
  512.   {"next.l", s_mri_next, 'l'},
  513.   {"for", s_mri_for, 0},
  514.   {"for.b", s_mri_for, 'b'},
  515.   {"for.w", s_mri_for, 'w'},
  516.   {"for.l", s_mri_for, 'l'},
  517.   {"endf", s_mri_endf, 0},
  518.   {"repeat", s_mri_repeat, 0},
  519.   {"until", s_mri_until, 0},
  520.   {"until.b", s_mri_until, 'b'},
  521.   {"until.w", s_mri_until, 'w'},
  522.   {"until.l", s_mri_until, 'l'},
  523.   {"while", s_mri_while, 0},
  524.   {"while.b", s_mri_while, 'b'},
  525.   {"while.w", s_mri_while, 'w'},
  526.   {"while.l", s_mri_while, 'l'},
  527.   {"endw", s_mri_endw, 0},
  528.  
  529.   {0, 0, 0}
  530. };
  531.  
  532.  
  533. /* The mote pseudo ops are put into the opcode table, since they
  534.    don't start with a . they look like opcodes to gas.
  535.    */
  536. extern void obj_coff_section ();
  537.  
  538. CONST pseudo_typeS mote_pseudo_table[] =
  539. {
  540.  
  541.   {"dcl", cons, 4},
  542.   {"dc", cons, 2},
  543.   {"dcw", cons, 2},
  544.   {"dcb", cons, 1},
  545.  
  546.   {"dsl", s_space, 4},
  547.   {"ds", s_space, 2},
  548.   {"dsw", s_space, 2},
  549.   {"dsb", s_space, 1},
  550.  
  551.   {"xdef", s_globl, 0},
  552. #ifdef OBJ_ELF
  553.   {"align", s_align_bytes, 0},
  554. #else
  555.   {"align", s_align_ptwo, 0},
  556. #endif
  557. #ifdef M68KCOFF
  558.   {"sect", obj_coff_section, 0},
  559.   {"section", obj_coff_section, 0},
  560. #endif
  561.   {0, 0, 0}
  562. };
  563.  
  564. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  565. #define isubyte(x)    ((x)>=0 && (x)<=255)
  566. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  567. #define isuword(x)    ((x)>=0 && (x)<=65535)
  568.  
  569. #define isbyte(x)    ((x)>= -255 && (x)<=255)
  570. #define isword(x)    ((x)>=-65536 && (x)<=65535)
  571. #define islong(x)    (1)
  572.  
  573. extern char *input_line_pointer;
  574.  
  575. static char mklower_table[256];
  576. #define mklower(c) (mklower_table[(unsigned char)(c)])
  577. static char notend_table[256];
  578. static char alt_notend_table[256];
  579. #define notend(s)                        \
  580.   (! (notend_table[(unsigned char) *s]                \
  581.       || (*s == ':'                        \
  582.       && alt_notend_table[(unsigned char) s[1]])))
  583.  
  584. #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
  585.  
  586. #ifdef NO_PCREL_RELOCS
  587.  
  588. int
  589. make_pcrel_absolute(fixP, add_number)
  590.     fixS *fixP;
  591.     long *add_number;
  592. {
  593.   register unsigned char *opcode = fixP->fx_frag->fr_opcode;
  594.  
  595.   /* rewrite the PC relative instructions to absolute address ones.
  596.    * these are rumoured to be faster, and the apollo linker refuses
  597.    * to deal with the PC relative relocations.
  598.    */
  599.   if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
  600.     {
  601.       opcode[0] = 0x4e;
  602.       opcode[1] = 0xf9;
  603.     }
  604.   else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
  605.     {
  606.       opcode[0] = 0x4e;
  607.       opcode[1] = 0xb9;
  608.     }
  609.   else
  610.     as_fatal ("Unknown PC relative instruction");
  611.   *add_number -= 4;
  612.   return 0;
  613. }
  614.  
  615. #endif /* NO_PCREL_RELOCS */
  616.  
  617. short
  618. tc_coff_fix2rtype (fixP)
  619.      fixS *fixP;
  620. {
  621.   if (fixP->fx_tcbit && fixP->fx_size == 4)
  622.     return R_RELLONG_NEG;
  623. #ifdef NO_PCREL_RELOCS
  624.   know (fixP->fx_pcrel == 0);
  625.   return (fixP->fx_size == 1 ? R_RELBYTE
  626.       : fixP->fx_size == 2 ? R_DIR16
  627.       : R_DIR32);
  628. #else
  629.   return (fixP->fx_pcrel ?
  630.       (fixP->fx_size == 1 ? R_PCRBYTE :
  631.        fixP->fx_size == 2 ? R_PCRWORD :
  632.        R_PCRLONG) :
  633.       (fixP->fx_size == 1 ? R_RELBYTE :
  634.        fixP->fx_size == 2 ? R_RELWORD :
  635.        R_RELLONG));
  636. #endif
  637. }
  638.  
  639. #endif
  640.  
  641. #ifdef OBJ_ELF
  642.  
  643. /* Compute the relocation code for a fixup of SIZE bytes, using pc
  644.    relative relocation if PCREL is non-zero.  PIC says whether a special
  645.    pic relocation was requested.  */
  646.  
  647. static bfd_reloc_code_real_type get_reloc_code
  648.   PARAMS ((int, int, enum pic_relocation));
  649.  
  650. static bfd_reloc_code_real_type
  651. get_reloc_code (size, pcrel, pic)
  652.      int size;
  653.      int pcrel;
  654.      enum pic_relocation pic;
  655. {
  656.   switch (pic)
  657.     {
  658.     case pic_got_pcrel:
  659.       switch (size)
  660.     {
  661.     case 1:
  662.       return BFD_RELOC_8_GOT_PCREL;
  663.     case 2:
  664.       return BFD_RELOC_16_GOT_PCREL;
  665.     case 4:
  666.       return BFD_RELOC_32_GOT_PCREL;
  667.     }
  668.       break;
  669.  
  670.     case pic_got_off:
  671.       switch (size)
  672.     {
  673.     case 1:
  674.       return BFD_RELOC_8_GOTOFF;
  675.     case 2:
  676.       return BFD_RELOC_16_GOTOFF;
  677.     case 4:
  678.       return BFD_RELOC_32_GOTOFF;
  679.     }
  680.       break;
  681.  
  682.     case pic_plt_pcrel:
  683.       switch (size)
  684.     {
  685.     case 1:
  686.       return BFD_RELOC_8_PLT_PCREL;
  687.     case 2:
  688.       return BFD_RELOC_16_PLT_PCREL;
  689.     case 4:
  690.       return BFD_RELOC_32_PLT_PCREL;
  691.     }
  692.       break;
  693.  
  694.     case pic_plt_off:
  695.       switch (size)
  696.     {
  697.     case 1:
  698.       return BFD_RELOC_8_PLTOFF;
  699.     case 2:
  700.       return BFD_RELOC_16_PLTOFF;
  701.     case 4:
  702.       return BFD_RELOC_32_PLTOFF;
  703.     }
  704.       break;
  705.  
  706.     case pic_none:
  707.       if (pcrel)
  708.     {
  709.       switch (size)
  710.         {
  711.         case 1:
  712.           return BFD_RELOC_8_PCREL;
  713.         case 2:
  714.           return BFD_RELOC_16_PCREL;
  715.         case 4:
  716.           return BFD_RELOC_32_PCREL;
  717.         }
  718.     }
  719.       else
  720.     {
  721.       switch (size)
  722.         {
  723.         case 1:
  724.           return BFD_RELOC_8;
  725.         case 2:
  726.           return BFD_RELOC_16;
  727.         case 4:
  728.           return BFD_RELOC_32;
  729.         }
  730.     }
  731.     }
  732.  
  733.   as_bad ("Can not do %d byte %s%srelocation", size,
  734.       pcrel ? "pc-relative " : "",
  735.       pic == pic_none ? "" : "pic ");
  736.   return BFD_RELOC_NONE;
  737. }
  738.  
  739. /* Here we decide which fixups can be adjusted to make them relative
  740.    to the beginning of the section instead of the symbol.  Basically
  741.    we need to make sure that the dynamic relocations are done
  742.    correctly, so in some cases we force the original symbol to be
  743.    used.  */
  744. int
  745. tc_m68k_fix_adjustable (fixP)
  746.      fixS *fixP;
  747. {
  748.   /* Prevent all adjustments to global symbols. */
  749.   if (S_IS_EXTERNAL (fixP->fx_addsy))
  750.     return 0;
  751.  
  752.   /* adjust_reloc_syms doesn't know about the GOT */
  753.   switch (fixP->fx_r_type)
  754.     {
  755.     case BFD_RELOC_8_GOT_PCREL:
  756.     case BFD_RELOC_16_GOT_PCREL:
  757.     case BFD_RELOC_32_GOT_PCREL:
  758.     case BFD_RELOC_8_GOTOFF:
  759.     case BFD_RELOC_16_GOTOFF:
  760.     case BFD_RELOC_32_GOTOFF:
  761.     case BFD_RELOC_8_PLT_PCREL:
  762.     case BFD_RELOC_16_PLT_PCREL:
  763.     case BFD_RELOC_32_PLT_PCREL:
  764.     case BFD_RELOC_8_PLTOFF:
  765.     case BFD_RELOC_16_PLTOFF:
  766.     case BFD_RELOC_32_PLTOFF:
  767.       return 0;
  768.  
  769.     default:
  770.       return 1;
  771.     }
  772. }
  773.  
  774. #else /* !OBJ_ELF */
  775.  
  776. #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
  777.  
  778. #endif /* OBJ_ELF */
  779.  
  780. #ifdef BFD_ASSEMBLER
  781.  
  782. arelent *
  783. tc_gen_reloc (section, fixp)
  784.      asection *section;
  785.      fixS *fixp;
  786. {
  787.   arelent *reloc;
  788.   bfd_reloc_code_real_type code;
  789.  
  790.   if (fixp->fx_tcbit)
  791.     abort ();
  792.  
  793.   if (fixp->fx_r_type != BFD_RELOC_NONE)
  794.     {
  795.       code = fixp->fx_r_type;
  796.  
  797.       /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
  798.          that fixup_segment converted a non-PC relative reloc into a
  799.          PC relative reloc.  In such a case, we need to convert the
  800.          reloc code.  */
  801.       if (fixp->fx_pcrel)
  802.     {
  803.       switch (code)
  804.         {
  805.         case BFD_RELOC_8:
  806.           code = BFD_RELOC_8_PCREL;
  807.           break;
  808.         case BFD_RELOC_16:
  809.           code = BFD_RELOC_16_PCREL;
  810.           break;
  811.         case BFD_RELOC_32:
  812.           code = BFD_RELOC_32_PCREL;
  813.           break;
  814.         case BFD_RELOC_8_PCREL:
  815.         case BFD_RELOC_16_PCREL:
  816.         case BFD_RELOC_32_PCREL:
  817.         case BFD_RELOC_8_GOT_PCREL:
  818.         case BFD_RELOC_16_GOT_PCREL:
  819.         case BFD_RELOC_32_GOT_PCREL:
  820.         case BFD_RELOC_8_GOTOFF:
  821.         case BFD_RELOC_16_GOTOFF:
  822.         case BFD_RELOC_32_GOTOFF:
  823.         case BFD_RELOC_8_PLT_PCREL:
  824.         case BFD_RELOC_16_PLT_PCREL:
  825.         case BFD_RELOC_32_PLT_PCREL:
  826.         case BFD_RELOC_8_PLTOFF:
  827.         case BFD_RELOC_16_PLTOFF:
  828.         case BFD_RELOC_32_PLTOFF:
  829.           break;
  830.         default:
  831.           as_bad_where (fixp->fx_file, fixp->fx_line,
  832.                 "Cannot make %s relocation PC relative",
  833.                 bfd_get_reloc_code_name (code));
  834.         }
  835.     }
  836.     }
  837.   else
  838.     {
  839. #define F(SZ,PCREL)        (((SZ) << 1) + (PCREL))
  840.       switch (F (fixp->fx_size, fixp->fx_pcrel))
  841.     {
  842. #define MAP(SZ,PCREL,TYPE)    case F(SZ,PCREL): code = (TYPE); break
  843.       MAP (1, 0, BFD_RELOC_8);
  844.       MAP (2, 0, BFD_RELOC_16);
  845.       MAP (4, 0, BFD_RELOC_32);
  846.       MAP (1, 1, BFD_RELOC_8_PCREL);
  847.       MAP (2, 1, BFD_RELOC_16_PCREL);
  848.       MAP (4, 1, BFD_RELOC_32_PCREL);
  849.     default:
  850.       abort ();
  851.     }
  852.     }
  853. #undef F
  854. #undef MAP
  855.  
  856.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  857.   assert (reloc != 0);
  858.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  859.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  860. #ifndef OBJ_ELF
  861.   if (fixp->fx_pcrel)
  862.     reloc->addend = fixp->fx_addnumber;
  863.   else
  864.     reloc->addend = 0;
  865. #else
  866.   if (!fixp->fx_pcrel)
  867.     reloc->addend = fixp->fx_addnumber;
  868.   else
  869.     reloc->addend = (section->vma
  870.              + (fixp->fx_pcrel_adjust == 64
  871.             ? -1 : fixp->fx_pcrel_adjust)
  872.              + fixp->fx_addnumber
  873.              + md_pcrel_from (fixp));
  874. #endif
  875.  
  876.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  877.   assert (reloc->howto != 0);
  878.  
  879.   return reloc;
  880. }
  881.  
  882. #endif /* BFD_ASSEMBLER */
  883.  
  884. /* Handle of the OPCODE hash table.  NULL means any use before
  885.    m68k_ip_begin() will crash.  */
  886. static struct hash_control *op_hash;
  887.  
  888. /* Assemble an m68k instruction.  */
  889.  
  890. void
  891. m68k_ip (instring)
  892.      char *instring;
  893. {
  894.   register char *p;
  895.   register struct m68k_op *opP;
  896.   register struct m68k_incant *opcode;
  897.   register const char *s;
  898.   register int tmpreg = 0, baseo = 0, outro = 0, nextword;
  899.   char *pdot, *pdotmove;
  900.   enum m68k_size siz1, siz2;
  901.   char c;
  902.   int losing;
  903.   int opsfound;
  904.   char *crack_operand ();
  905.   LITTLENUM_TYPE words[6];
  906.   LITTLENUM_TYPE *wordp;
  907.   unsigned long ok_arch = 0;
  908.  
  909.   if (*instring == ' ')
  910.     instring++;            /* skip leading whitespace */
  911.  
  912.   /* Scan up to end of operation-code, which MUST end in end-of-string
  913.      or exactly 1 space. */
  914.   pdot = 0;
  915.   for (p = instring; *p != '\0'; p++)
  916.     {
  917.       if (*p == ' ')
  918.     break;
  919.       if (*p == '.')
  920.     pdot = p;
  921.     }
  922.  
  923.   if (p == instring)
  924.     {
  925.       the_ins.error = "No operator";
  926.       return;
  927.     }
  928.  
  929.   /* p now points to the end of the opcode name, probably whitespace.
  930.      Make sure the name is null terminated by clobbering the
  931.      whitespace, look it up in the hash table, then fix it back.
  932.      Remove a dot, first, since the opcode tables have none.  */
  933.   if (pdot != NULL)
  934.     {
  935.       for (pdotmove = pdot; pdotmove < p; pdotmove++)
  936.     *pdotmove = pdotmove[1];
  937.       p--;
  938.     }
  939.  
  940.   c = *p;
  941.   *p = '\0';
  942.   opcode = (struct m68k_incant *) hash_find (op_hash, instring);
  943.   *p = c;
  944.  
  945.   if (pdot != NULL)
  946.     {
  947.       for (pdotmove = p; pdotmove > pdot; pdotmove--)
  948.     *pdotmove = pdotmove[-1];
  949.       *pdot = '.';
  950.       ++p;
  951.     }
  952.  
  953.   if (opcode == NULL)
  954.     {
  955.       the_ins.error = "Unknown operator";
  956.       return;
  957.     }
  958.  
  959.   /* found a legitimate opcode, start matching operands */
  960.   while (*p == ' ')
  961.     ++p;
  962.  
  963.   if (opcode->m_operands == 0)
  964.     {
  965.       char *old = input_line_pointer;
  966.       *old = '\n';
  967.       input_line_pointer = p;
  968.       /* Ahh - it's a motorola style psuedo op */
  969.       mote_pseudo_table[opcode->m_opnum].poc_handler
  970.     (mote_pseudo_table[opcode->m_opnum].poc_val);
  971.       input_line_pointer = old;
  972.       *old = 0;
  973.  
  974.       return;
  975.     }
  976.  
  977.   if (flag_mri && opcode->m_opnum == 0)
  978.     {
  979.       /* In MRI mode, random garbage is allowed after an instruction
  980.          which accepts no operands.  */
  981.       the_ins.args = opcode->m_operands;
  982.       the_ins.numargs = opcode->m_opnum;
  983.       the_ins.numo = opcode->m_codenum;
  984.       the_ins.opcode[0] = getone (opcode);
  985.       the_ins.opcode[1] = gettwo (opcode);
  986.       return;
  987.     }
  988.  
  989.   for (opP = &the_ins.operands[0]; *p; opP++)
  990.     {
  991.       p = crack_operand (p, opP);
  992.  
  993.       if (opP->error)
  994.     {
  995.       the_ins.error = opP->error;
  996.       return;
  997.     }
  998.     }
  999.  
  1000.   opsfound = opP - &the_ins.operands[0];
  1001.  
  1002.   /* This ugly hack is to support the floating pt opcodes in their
  1003.      standard form.  Essentially, we fake a first enty of type COP#1 */
  1004.   if (opcode->m_operands[0] == 'I')
  1005.     {
  1006.       int n;
  1007.  
  1008.       for (n = opsfound; n > 0; --n)
  1009.     the_ins.operands[n] = the_ins.operands[n - 1];
  1010.  
  1011.       memset ((char *) (&the_ins.operands[0]), '\0',
  1012.           sizeof (the_ins.operands[0]));
  1013.       the_ins.operands[0].mode = CONTROL;
  1014.       the_ins.operands[0].reg = m68k_float_copnum;
  1015.       opsfound++;
  1016.     }
  1017.  
  1018.   /* We've got the operands.  Find an opcode that'll accept them */
  1019.   for (losing = 0;;)
  1020.     {
  1021.       /* If we didn't get the right number of ops, or we have no
  1022.      common model with this pattern then reject this pattern. */
  1023.  
  1024.       if (opsfound != opcode->m_opnum
  1025.       || ((opcode->m_arch & current_architecture) == 0))
  1026.     {
  1027.       ++losing;
  1028.       ok_arch |= opcode->m_arch;
  1029.     }
  1030.       else
  1031.     {
  1032.       for (s = opcode->m_operands, opP = &the_ins.operands[0];
  1033.            *s && !losing;
  1034.            s += 2, opP++)
  1035.         {
  1036.           /* Warning: this switch is huge! */
  1037.           /* I've tried to organize the cases into this order:
  1038.          non-alpha first, then alpha by letter.  Lower-case
  1039.          goes directly before uppercase counterpart.  */
  1040.           /* Code with multiple case ...: gets sorted by the lowest
  1041.          case ... it belongs to.  I hope this makes sense.  */
  1042.           switch (*s)
  1043.         {
  1044.         case '!':
  1045.           switch (opP->mode)
  1046.             {
  1047.             case IMMED:
  1048.             case DREG:
  1049.             case AREG:
  1050.             case FPREG:
  1051.             case CONTROL:
  1052.             case AINC:
  1053.             case ADEC:
  1054.             case REGLST:
  1055.               losing++;
  1056.               break;
  1057.             default:
  1058.               break;
  1059.             }
  1060.           break;
  1061.  
  1062.         case '`':
  1063.           switch (opP->mode)
  1064.             {
  1065.             case IMMED:
  1066.             case DREG:
  1067.             case AREG:
  1068.             case FPREG:
  1069.             case CONTROL:
  1070.             case AINC:
  1071.             case REGLST:
  1072.             case AINDR:
  1073.               losing++;
  1074.               break;
  1075.             default:
  1076.               break;
  1077.             }
  1078.           break;
  1079.  
  1080.         case '#':
  1081.           if (opP->mode != IMMED)
  1082.             losing++;
  1083.           else if (s[1] == 'b'
  1084.                && ! isvar (&opP->disp)
  1085.                && (opP->disp.exp.X_op != O_constant
  1086.                    || ! isbyte (opP->disp.exp.X_add_number)))
  1087.             losing++;
  1088.           else if (s[1] == 'w'
  1089.                && ! isvar (&opP->disp)
  1090.                && (opP->disp.exp.X_op != O_constant
  1091.                    || ! isword (opP->disp.exp.X_add_number)))
  1092.             losing++;
  1093.           else if (s[1] == 'W'
  1094.                && ! isvar (&opP->disp)
  1095.                && (opP->disp.exp.X_op != O_constant
  1096.                    || ! issword (opP->disp.exp.X_add_number)))
  1097.             losing++;
  1098.           break;
  1099.  
  1100.         case '^':
  1101.         case 'T':
  1102.           if (opP->mode != IMMED)
  1103.             losing++;
  1104.           break;
  1105.  
  1106.         case '$':
  1107.           if (opP->mode == AREG
  1108.               || opP->mode == CONTROL
  1109.               || opP->mode == FPREG
  1110.               || opP->mode == IMMED
  1111.               || opP->mode == REGLST
  1112.               || (opP->mode != ABSL
  1113.               && (opP->reg == PC
  1114.                   || opP->reg == ZPC)))
  1115.             losing++;
  1116.           break;
  1117.  
  1118.         case '%':
  1119.           if (opP->mode == CONTROL
  1120.               || opP->mode == FPREG
  1121.               || opP->mode == REGLST
  1122.               || opP->mode == IMMED
  1123.               || (opP->mode != ABSL
  1124.               && (opP->reg == PC
  1125.                   || opP->reg == ZPC)))
  1126.             losing++;
  1127.           break;
  1128.  
  1129.         case '&':
  1130.           switch (opP->mode)
  1131.             {
  1132.             case DREG:
  1133.             case AREG:
  1134.             case FPREG:
  1135.             case CONTROL:
  1136.             case IMMED:
  1137.             case AINC:
  1138.             case ADEC:
  1139.             case REGLST:
  1140.               losing++;
  1141.               break;
  1142.             case ABSL:
  1143.               break;
  1144.             default:
  1145.               if (opP->reg == PC
  1146.               || opP->reg == ZPC)
  1147.             losing++;
  1148.               break;
  1149.             }
  1150.           break;
  1151.  
  1152.         case '*':
  1153.           if (opP->mode == CONTROL
  1154.               || opP->mode == FPREG
  1155.               || opP->mode == REGLST)
  1156.             losing++;
  1157.           break;
  1158.  
  1159.         case '+':
  1160.           if (opP->mode != AINC)
  1161.             losing++;
  1162.           break;
  1163.  
  1164.         case '-':
  1165.           if (opP->mode != ADEC)
  1166.             losing++;
  1167.           break;
  1168.  
  1169.         case '/':
  1170.           switch (opP->mode)
  1171.             {
  1172.             case AREG:
  1173.             case CONTROL:
  1174.             case FPREG:
  1175.             case AINC:
  1176.             case ADEC:
  1177.             case IMMED:
  1178.             case REGLST:
  1179.               losing++;
  1180.               break;
  1181.             default:
  1182.               break;
  1183.             }
  1184.           break;
  1185.  
  1186.         case ';':
  1187.           switch (opP->mode)
  1188.             {
  1189.             case AREG:
  1190.             case CONTROL:
  1191.             case FPREG:
  1192.             case REGLST:
  1193.               losing++;
  1194.               break;
  1195.             default:
  1196.               break;
  1197.             }
  1198.           break;
  1199.  
  1200.         case '?':
  1201.           switch (opP->mode)
  1202.             {
  1203.             case AREG:
  1204.             case CONTROL:
  1205.             case FPREG:
  1206.             case AINC:
  1207.             case ADEC:
  1208.             case IMMED:
  1209.             case REGLST:
  1210.               losing++;
  1211.               break;
  1212.             case ABSL:
  1213.               break;
  1214.             default:
  1215.               if (opP->reg == PC || opP->reg == ZPC)
  1216.             losing++;
  1217.               break;
  1218.             }
  1219.           break;
  1220.  
  1221.         case '@':
  1222.           switch (opP->mode)
  1223.             {
  1224.             case AREG:
  1225.             case CONTROL:
  1226.             case FPREG:
  1227.             case IMMED:
  1228.             case REGLST:
  1229.               losing++;
  1230.               break;
  1231.             default:
  1232.               break;
  1233.             }
  1234.           break;
  1235.  
  1236.         case '~':    /* For now! (JF FOO is this right?) */
  1237.           switch (opP->mode)
  1238.             {
  1239.             case DREG:
  1240.             case AREG:
  1241.             case CONTROL:
  1242.             case FPREG:
  1243.             case IMMED:
  1244.             case REGLST:
  1245.               losing++;
  1246.               break;
  1247.             case ABSL:
  1248.               break;
  1249.             default:
  1250.               if (opP->reg == PC
  1251.               || opP->reg == ZPC)
  1252.             losing++;
  1253.               break;
  1254.             }
  1255.           break;
  1256.  
  1257.         case '3':
  1258.           if (opP->mode != CONTROL
  1259.               || (opP->reg != TT0 && opP->reg != TT1))
  1260.             losing++;
  1261.           break;
  1262.  
  1263.         case 'A':
  1264.           if (opP->mode != AREG)
  1265.             losing++;
  1266.           break;
  1267.  
  1268.         case 'a':
  1269.           if (opP->mode != AINDR)
  1270.             ++losing;
  1271.           break;
  1272.  
  1273.         case 'B':    /* FOO */
  1274.           if (opP->mode != ABSL
  1275.               || (flag_long_jumps
  1276.               && strncmp (instring, "jbsr", 4) == 0))
  1277.             losing++;
  1278.           break;
  1279.  
  1280.         case 'C':
  1281.           if (opP->mode != CONTROL || opP->reg != CCR)
  1282.             losing++;
  1283.           break;
  1284.  
  1285.         case 'd':
  1286.           if (opP->mode != DISP
  1287.               || opP->reg < ADDR0
  1288.               || opP->reg > ADDR7)
  1289.             losing++;
  1290.           break;
  1291.  
  1292.         case 'D':
  1293.           if (opP->mode != DREG)
  1294.             losing++;
  1295.           break;
  1296.  
  1297.         case 'F':
  1298.           if (opP->mode != FPREG)
  1299.             losing++;
  1300.           break;
  1301.  
  1302.         case 'I':
  1303.           if (opP->mode != CONTROL
  1304.               || opP->reg < COP0
  1305.               || opP->reg > COP7)
  1306.             losing++;
  1307.           break;
  1308.  
  1309.         case 'J':
  1310.           if (opP->mode != CONTROL
  1311.               || opP->reg < USP
  1312.               || opP->reg > last_movec_reg)
  1313.             losing++;
  1314.           else
  1315.             {
  1316.               const enum m68k_register *rp;
  1317.               for (rp = control_regs; *rp; rp++)
  1318.             if (*rp == opP->reg)
  1319.               break;
  1320.               if (*rp == 0)
  1321.             losing++;
  1322.             }
  1323.           break;
  1324.  
  1325.         case 'k':
  1326.           if (opP->mode != IMMED)
  1327.             losing++;
  1328.           break;
  1329.  
  1330.         case 'l':
  1331.         case 'L':
  1332.           if (opP->mode == DREG
  1333.               || opP->mode == AREG
  1334.               || opP->mode == FPREG)
  1335.             {
  1336.               if (s[1] == '8')
  1337.             losing++;
  1338.               else
  1339.             {
  1340.               switch (opP->mode)
  1341.                 {
  1342.                 case DREG:
  1343.                   opP->mask = 1 << (opP->reg - DATA0);
  1344.                   break;
  1345.                 case AREG:
  1346.                   opP->mask = 1 << (opP->reg - ADDR0 + 8);
  1347.                   break;
  1348.                 case FPREG:
  1349.                   opP->mask = 1 << (opP->reg - FP0 + 16);
  1350.                   break;
  1351.                 default:
  1352.                   abort ();
  1353.                 }
  1354.               opP->mode = REGLST;
  1355.             }
  1356.             }
  1357.           else if (opP->mode == CONTROL)
  1358.             {
  1359.               if (s[1] != '8')
  1360.             losing++;
  1361.               else
  1362.             {
  1363.               switch (opP->reg)
  1364.                 {
  1365.                 case FPI:
  1366.                   opP->mask = 1 << 24;
  1367.                   break;
  1368.                 case FPS:
  1369.                   opP->mask = 1 << 25;
  1370.                   break;
  1371.                 case FPC:
  1372.                   opP->mask = 1 << 26;
  1373.                   break;
  1374.                 default:
  1375.                   losing++;
  1376.                   break;
  1377.                 }
  1378.               opP->mode = REGLST;
  1379.             }
  1380.             }
  1381.           else if (opP->mode == ABSL
  1382.                && opP->disp.size == SIZE_UNSPEC
  1383.                && opP->disp.exp.X_op == O_constant)
  1384.             {
  1385.               /* This is what the MRI REG pseudo-op generates.  */
  1386.               opP->mode = REGLST;
  1387.               opP->mask = opP->disp.exp.X_add_number;
  1388.             }
  1389.           else if (opP->mode != REGLST)
  1390.             losing++;
  1391.           else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
  1392.             losing++;
  1393.           else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
  1394.             losing++;
  1395.           break;
  1396.  
  1397.         case 'M':
  1398.           if (opP->mode != IMMED)
  1399.             losing++;
  1400.           else if (opP->disp.exp.X_op != O_constant
  1401.                || ! issbyte (opP->disp.exp.X_add_number))
  1402.             losing++;
  1403.           else if (! m68k_quick
  1404.                && instring[3] != 'q'
  1405.                && instring[4] != 'q')
  1406.             losing++;
  1407.           break;
  1408.  
  1409.         case 'O':
  1410.           if (opP->mode != DREG
  1411.               && opP->mode != IMMED
  1412.               && opP->mode != ABSL)
  1413.             losing++;
  1414.           break;
  1415.  
  1416.         case 'Q':
  1417.           if (opP->mode != IMMED)
  1418.             losing++;
  1419.           else if (opP->disp.exp.X_op != O_constant
  1420.                || opP->disp.exp.X_add_number < 1
  1421.                || opP->disp.exp.X_add_number > 8)
  1422.             losing++;
  1423.           else if (! m68k_quick
  1424.                && (strncmp (instring, "add", 3) == 0
  1425.                    || strncmp (instring, "sub", 3) == 0)
  1426.                && instring[3] != 'q')
  1427.             losing++;
  1428.           break;
  1429.  
  1430.         case 'R':
  1431.           if (opP->mode != DREG && opP->mode != AREG)
  1432.             losing++;
  1433.           break;
  1434.  
  1435.         case 'r':
  1436.           if (opP->mode != AINDR
  1437.               && (opP->mode != BASE
  1438.               || (opP->reg != 0
  1439.                   && opP->reg != ZADDR0)
  1440.               || opP->disp.exp.X_op != O_absent
  1441.               || ((opP->index.reg < DATA0
  1442.                    || opP->index.reg > DATA7)
  1443.                   && (opP->index.reg < ADDR0
  1444.                   || opP->index.reg > ADDR7))
  1445.               || opP->index.size != SIZE_UNSPEC
  1446.               || opP->index.scale != 1))
  1447.             losing++;
  1448.           break;
  1449.  
  1450.         case 's':
  1451.           if (opP->mode != CONTROL
  1452.               || ! (opP->reg == FPI
  1453.                 || opP->reg == FPS
  1454.                 || opP->reg == FPC))
  1455.             losing++;
  1456.           break;
  1457.  
  1458.         case 'S':
  1459.           if (opP->mode != CONTROL || opP->reg != SR)
  1460.             losing++;
  1461.           break;
  1462.  
  1463.         case 't':
  1464.           if (opP->mode != IMMED)
  1465.             losing++;
  1466.           else if (opP->disp.exp.X_op != O_constant
  1467.                || opP->disp.exp.X_add_number < 0
  1468.                || opP->disp.exp.X_add_number > 7)
  1469.             losing++;
  1470.           break;
  1471.  
  1472.         case 'U':
  1473.           if (opP->mode != CONTROL || opP->reg != USP)
  1474.             losing++;
  1475.           break;
  1476.  
  1477.           /* JF these are out of order.  We could put them
  1478.              in order if we were willing to put up with
  1479.              bunches of #ifdef m68851s in the code.
  1480.  
  1481.              Don't forget that you need these operands
  1482.              to use 68030 MMU instructions.  */
  1483. #ifndef NO_68851
  1484.           /* Memory addressing mode used by pflushr */
  1485.         case '|':
  1486.           if (opP->mode == CONTROL
  1487.               || opP->mode == FPREG
  1488.               || opP->mode == DREG
  1489.               || opP->mode == AREG
  1490.               || opP->mode == REGLST)
  1491.             losing++;
  1492.           /* We should accept immediate operands, but they
  1493.                      supposedly have to be quad word, and we don't
  1494.                      handle that.  I would like to see what a Motorola
  1495.                      assembler does before doing something here.  */
  1496.           if (opP->mode == IMMED)
  1497.             losing++;
  1498.           break;
  1499.  
  1500.         case 'f':
  1501.           if (opP->mode != CONTROL
  1502.               || (opP->reg != SFC && opP->reg != DFC))
  1503.             losing++;
  1504.           break;
  1505.  
  1506.         case '0':
  1507.           if (opP->mode != CONTROL || opP->reg != TC)
  1508.             losing++;
  1509.           break;
  1510.  
  1511.         case '1':
  1512.           if (opP->mode != CONTROL || opP->reg != AC)
  1513.             losing++;
  1514.           break;
  1515.  
  1516.         case '2':
  1517.           if (opP->mode != CONTROL
  1518.               || (opP->reg != CAL
  1519.               && opP->reg != VAL
  1520.               && opP->reg != SCC))
  1521.             losing++;
  1522.           break;
  1523.  
  1524.         case 'V':
  1525.           if (opP->mode != CONTROL
  1526.               || opP->reg != VAL)
  1527.             losing++;
  1528.           break;
  1529.  
  1530.         case 'W':
  1531.           if (opP->mode != CONTROL
  1532.               || (opP->reg != DRP
  1533.               && opP->reg != SRP
  1534.               && opP->reg != CRP))
  1535.             losing++;
  1536.           break;
  1537.  
  1538.         case 'X':
  1539.           if (opP->mode != CONTROL
  1540.               || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
  1541.               && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
  1542.             losing++;
  1543.           break;
  1544.  
  1545.         case 'Y':
  1546.           if (opP->mode != CONTROL || opP->reg != PSR)
  1547.             losing++;
  1548.           break;
  1549.  
  1550.         case 'Z':
  1551.           if (opP->mode != CONTROL || opP->reg != PCSR)
  1552.             losing++;
  1553.           break;
  1554. #endif
  1555.         case 'c':
  1556.           if (opP->mode != CONTROL
  1557.               || (opP->reg != NC
  1558.               && opP->reg != IC
  1559.               && opP->reg != DC
  1560.               && opP->reg != BC))
  1561.             {
  1562.               losing++;
  1563.             }        /* not a cache specifier. */
  1564.           break;
  1565.  
  1566.         case '_':
  1567.           if (opP->mode != ABSL)
  1568.             ++losing;
  1569.           break;
  1570.  
  1571.         default:
  1572.           abort ();
  1573.         }        /* switch on type of operand */
  1574.  
  1575.           if (losing)
  1576.         break;
  1577.         }            /* for each operand */
  1578.     }            /* if immediately wrong */
  1579.  
  1580.       if (!losing)
  1581.     {
  1582.       break;
  1583.     }            /* got it. */
  1584.  
  1585.       opcode = opcode->m_next;
  1586.  
  1587.       if (!opcode)
  1588.     {
  1589.       if (ok_arch
  1590.           && !(ok_arch & current_architecture))
  1591.         {
  1592.           char buf[200], *cp;
  1593.           int len;
  1594.           strcpy (buf,
  1595.               "invalid instruction for this architecture; needs ");
  1596.           cp = buf + strlen (buf);
  1597.           switch (ok_arch)
  1598.         {
  1599.         case mfloat:
  1600.           strcpy (cp, "fpu (68040, 68060 or 68881/68882)");
  1601.           break;
  1602.         case mmmu:
  1603.           strcpy (cp, "mmu (68030 or 68851)");
  1604.           break;
  1605.         case m68020up:
  1606.           strcpy (cp, "68020 or higher");
  1607.           break;
  1608.         case m68000up:
  1609.           strcpy (cp, "68000 or higher");
  1610.           break;
  1611.         case m68010up:
  1612.           strcpy (cp, "68010 or higher");
  1613.           break;
  1614.         default:
  1615.           {
  1616.             int got_one = 0, idx;
  1617.             for (idx = 0; idx < sizeof (archs) / sizeof (archs[0]);
  1618.              idx++)
  1619.               {
  1620.             if ((archs[idx].arch & ok_arch)
  1621.                 && ! archs[idx].alias)
  1622.               {
  1623.                 if (got_one)
  1624.                   {
  1625.                 strcpy (cp, " or ");
  1626.                 cp += strlen (cp);
  1627.                   }
  1628.                 got_one = 1;
  1629.                 strcpy (cp, archs[idx].name);
  1630.                 cp += strlen (cp);
  1631.               }
  1632.               }
  1633.           }
  1634.         }
  1635.           len = cp - buf + 1;
  1636.           cp = malloc (len);
  1637.           strcpy (cp, buf);
  1638.           the_ins.error = cp;
  1639.         }
  1640.       else
  1641.         the_ins.error = "operands mismatch";
  1642.       return;
  1643.     }            /* Fell off the end */
  1644.  
  1645.       losing = 0;
  1646.     }
  1647.  
  1648.   /* now assemble it */
  1649.  
  1650.   the_ins.args = opcode->m_operands;
  1651.   the_ins.numargs = opcode->m_opnum;
  1652.   the_ins.numo = opcode->m_codenum;
  1653.   the_ins.opcode[0] = getone (opcode);
  1654.   the_ins.opcode[1] = gettwo (opcode);
  1655.  
  1656.   for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
  1657.     {
  1658.       /* This switch is a doozy.
  1659.        Watch the first step; its a big one! */
  1660.       switch (s[0])
  1661.     {
  1662.  
  1663.     case '*':
  1664.     case '~':
  1665.     case '%':
  1666.     case ';':
  1667.     case '@':
  1668.     case '!':
  1669.     case '&':
  1670.     case '$':
  1671.     case '?':
  1672.     case '/':
  1673.     case '`':
  1674. #ifndef NO_68851
  1675.     case '|':
  1676. #endif
  1677.       switch (opP->mode)
  1678.         {
  1679.         case IMMED:
  1680.           tmpreg = 0x3c;    /* 7.4 */
  1681.           if (strchr ("bwl", s[1]))
  1682.         nextword = get_num (&opP->disp, 80);
  1683.           else
  1684.         nextword = get_num (&opP->disp, 0);
  1685.           if (isvar (&opP->disp))
  1686.             {
  1687. /* This doesn't work when the symbol is N_UNDF! So we ignore this for the moment.
  1688.  
  1689.               if (flag_small_code)
  1690.                 {
  1691.                   add_frag (adds(&opP->disp),
  1692.                           offs(&opP->disp),
  1693.                           TAB(IMMREL, SZ_UNDEF));
  1694.                     break;
  1695.                 }
  1696.               else
  1697. */
  1698.             add_fix(s[1], &opP->disp, 0, 0, opP->disp.baserel);
  1699.             }
  1700.           switch (s[1])
  1701.         {
  1702.         case 'b':
  1703.           if (!isbyte (nextword))
  1704.             opP->error = "operand out of range";
  1705.           addword (nextword);
  1706.           baseo = 0;
  1707.           break;
  1708.         case 'w':
  1709.           if (!isword (nextword))
  1710.             opP->error = "operand out of range";
  1711.           addword (nextword);
  1712.           baseo = 0;
  1713.           break;
  1714.         case 'W':
  1715.           if (!issword (nextword))
  1716.             opP->error = "operand out of range";
  1717.           addword (nextword);
  1718.           baseo = 0;
  1719.           break;
  1720.         case 'l':
  1721.           addword (nextword >> 16);
  1722.           addword (nextword);
  1723.           baseo = 0;
  1724.           break;
  1725.  
  1726.         case 'f':
  1727.           baseo = 2;
  1728.           outro = 8;
  1729.           break;
  1730.         case 'F':
  1731.           baseo = 4;
  1732.           outro = 11;
  1733.           break;
  1734.         case 'x':
  1735.           baseo = 6;
  1736.           outro = 15;
  1737.           break;
  1738.         case 'p':
  1739.           baseo = 6;
  1740.           outro = -1;
  1741.           break;
  1742.         default:
  1743.           abort ();
  1744.         }
  1745.           if (!baseo)
  1746.         break;
  1747.  
  1748.           /* We gotta put out some float */
  1749.           if (op (&opP->disp) != O_big)
  1750.         {
  1751.           valueT val;
  1752.           int gencnt;
  1753.  
  1754.           /* Can other cases happen here?  */
  1755.           if (op (&opP->disp) != O_constant)
  1756.             abort ();
  1757.  
  1758.           val = (valueT) offs (&opP->disp);
  1759.           gencnt = 0;
  1760.           do
  1761.             {
  1762.               generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
  1763.               val >>= LITTLENUM_NUMBER_OF_BITS;
  1764.               ++gencnt;
  1765.             }
  1766.           while (val != 0);
  1767.           offs (&opP->disp) = gencnt;
  1768.         }
  1769.           if (offs (&opP->disp) > 0)
  1770.         {
  1771.           if (offs (&opP->disp) > baseo)
  1772.             {
  1773.               as_warn ("Bignum too big for %c format; truncated",
  1774.                    s[1]);
  1775.               offs (&opP->disp) = baseo;
  1776.             }
  1777.           baseo -= offs (&opP->disp);
  1778.           while (baseo--)
  1779.             addword (0);
  1780.           for (wordp = generic_bignum + offs (&opP->disp) - 1;
  1781.                offs (&opP->disp)--;
  1782.                --wordp)
  1783.             addword (*wordp);
  1784.           break;
  1785.         }
  1786.           gen_to_words (words, baseo, (long) outro);
  1787.           for (wordp = words; baseo--; wordp++)
  1788.         addword (*wordp);
  1789.           break;
  1790.         case DREG:
  1791.           tmpreg = opP->reg - DATA;    /* 0.dreg */
  1792.           break;
  1793.         case AREG:
  1794.           tmpreg = 0x08 + opP->reg - ADDR;    /* 1.areg */
  1795.           break;
  1796.         case AINDR:
  1797.           tmpreg = 0x10 + opP->reg - ADDR;    /* 2.areg */
  1798.           break;
  1799.         case ADEC:
  1800.           tmpreg = 0x20 + opP->reg - ADDR;    /* 4.areg */
  1801.           break;
  1802.         case AINC:
  1803.           tmpreg = 0x18 + opP->reg - ADDR;    /* 3.areg */
  1804.           break;
  1805.         case DISP:
  1806.  
  1807.           nextword = get_num (&opP->disp, 80);
  1808.  
  1809.           if (opP->reg == PC
  1810.           && ! isvar (&opP->disp)
  1811.           && m68k_abspcadd)
  1812.         {
  1813.           opP->disp.exp.X_op = O_symbol;
  1814. #ifndef BFD_ASSEMBLER
  1815.           opP->disp.exp.X_add_symbol = &abs_symbol;
  1816. #else
  1817.           opP->disp.exp.X_add_symbol =
  1818.             section_symbol (absolute_section);
  1819. #endif
  1820.         }
  1821.  
  1822.           /* Force into index mode.  Hope this works */
  1823.  
  1824.           /* We do the first bit for 32-bit displacements, and the
  1825.          second bit for 16 bit ones.  It is possible that we
  1826.          should make the default be WORD instead of LONG, but
  1827.          I think that'd break GCC, so we put up with a little
  1828.          inefficiency for the sake of working output.  */
  1829.  
  1830.           if (!issword (nextword)
  1831.           || (isvar (&opP->disp)
  1832.               && ((opP->disp.size == SIZE_UNSPEC
  1833.                && flag_short_refs == 0
  1834.                && cpu_of_arch (current_architecture) >= m68020)
  1835.               || opP->disp.size == SIZE_LONG)))
  1836.         {
  1837.           if (cpu_of_arch (current_architecture) < m68020)
  1838.             opP->error =
  1839.               "displacement too large for this architecture; needs 68020 or higher";
  1840.           if (opP->reg == PC)
  1841.             tmpreg = 0x3B;    /* 7.3 */
  1842.           else
  1843.             tmpreg = 0x30 + opP->reg - ADDR;    /* 6.areg */
  1844.           if (isvar (&opP->disp))
  1845.             {
  1846.               if (opP->reg == PC)
  1847.             {
  1848.               if (opP->disp.size == SIZE_LONG
  1849. #ifdef OBJ_ELF
  1850.                   /* If the displacement needs pic
  1851.                  relocation it cannot be relaxed.  */
  1852.                   || opP->disp.pic_reloc != pic_none
  1853. #endif
  1854.                   )
  1855.                 {
  1856.                   addword (0x0170);
  1857.                   add_fix ('l', &opP->disp, 1, 2, opP->disp.baserel);
  1858.                 }
  1859.               else
  1860.                 {
  1861.                   add_frag (adds (&opP->disp),
  1862.                     offs (&opP->disp),
  1863.                     TAB (PCLEA, SZ_UNDEF));
  1864.                   break;
  1865.                 }
  1866.             }
  1867.               else
  1868.             {
  1869.               addword (0x0170);
  1870.               add_fix ('l', &opP->disp, 0, 0, opP->disp.baserel);
  1871.             }
  1872.             }
  1873.           else
  1874.             addword (0x0170);
  1875.           addword (nextword >> 16);
  1876.         }
  1877.           else
  1878.         {
  1879.           if (opP->reg == PC)
  1880.             tmpreg = 0x3A;    /* 7.2 */
  1881.           else
  1882.             tmpreg = 0x28 + opP->reg - ADDR;    /* 5.areg */
  1883.  
  1884.           if (isvar (&opP->disp))
  1885.             {
  1886.               if (opP->reg == PC)
  1887.             {
  1888.               add_fix ('w', &opP->disp, 1, 0, opP->disp.baserel);
  1889.             }
  1890.               else
  1891.             add_fix ('w', &opP->disp, 0, 0, opP->disp.baserel);
  1892.             }
  1893.         }
  1894.           addword (nextword);
  1895.           break;
  1896.  
  1897.         case POST:
  1898.         case PRE:
  1899.         case BASE:
  1900.           nextword = 0;
  1901.           baseo = get_num (&opP->disp, 80);
  1902.           if (opP->mode == POST || opP->mode == PRE)
  1903.         outro = get_num (&opP->odisp, 80);
  1904.           /* Figure out the `addressing mode'.
  1905.          Also turn on the BASE_DISABLE bit, if needed.  */
  1906.           if (opP->reg == PC || opP->reg == ZPC)
  1907.         {
  1908.           tmpreg = 0x3b;    /* 7.3 */
  1909.           if (opP->reg == ZPC)
  1910.             nextword |= 0x80;
  1911.         }
  1912.           else if (opP->reg == 0)
  1913.         {
  1914.           nextword |= 0x80;
  1915.           tmpreg = 0x30;    /* 6.garbage */
  1916.         }
  1917.           else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
  1918.         {
  1919.           nextword |= 0x80;
  1920.           tmpreg = 0x30 + opP->reg - ZADDR0;
  1921.         }
  1922.           else
  1923.         tmpreg = 0x30 + opP->reg - ADDR;    /* 6.areg */
  1924.  
  1925.           siz1 = opP->disp.size;
  1926.           if (opP->mode == POST || opP->mode == PRE)
  1927.         siz2 = opP->odisp.size;
  1928.           else
  1929.         siz2 = SIZE_UNSPEC;
  1930.  
  1931.           /* Index register stuff */
  1932.           if (opP->index.reg != 0
  1933.           && opP->index.reg >= DATA
  1934.           && opP->index.reg <= ADDR7)
  1935.         {
  1936.           nextword |= (opP->index.reg - DATA) << 12;
  1937.  
  1938.           if (opP->index.size == SIZE_UNSPEC
  1939.               || opP->index.size == SIZE_LONG)
  1940.             nextword |= 0x800;
  1941.  
  1942.           if (cpu_of_arch (current_architecture) < m68020)
  1943.             {
  1944.               if (opP->index.scale != 1)
  1945.             {
  1946.               opP->error =
  1947.                 "scale factor invalid on this architecture; needs cpu32 or 68020 or higher";
  1948.             }
  1949.             }
  1950.  
  1951.           switch (opP->index.scale)
  1952.             {
  1953.             case 1:
  1954.               break;
  1955.             case 2:
  1956.               nextword |= 0x200;
  1957.               break;
  1958.             case 4:
  1959.               nextword |= 0x400;
  1960.               break;
  1961.             case 8:
  1962.               nextword |= 0x600;
  1963.               break;
  1964.             default:
  1965.               abort ();
  1966.             }
  1967.           /* IF its simple,
  1968.              GET US OUT OF HERE! */
  1969.  
  1970.           /* Must be INDEX, with an index register.  Address
  1971.              register cannot be ZERO-PC, and either :b was
  1972.              forced, or we know it will fit.  For a 68000 or
  1973.              68010, force this mode anyways, because the
  1974.              larger modes aren't supported.  */
  1975.           if (opP->mode == BASE
  1976.               && ((opP->reg >= ADDR0
  1977.                && opP->reg <= ADDR7)
  1978.               || opP->reg == PC))
  1979.             {
  1980.               if (siz1 == SIZE_BYTE
  1981.               || cpu_of_arch (current_architecture) < m68020
  1982.               || (siz1 == SIZE_UNSPEC
  1983.                   && ! isvar (&opP->disp)
  1984.                   && issbyte (baseo)))
  1985.             {
  1986.                nextword += baseo & 0xff;
  1987.                addword (nextword);
  1988.                if (isvar (&opP->disp))
  1989.                 {
  1990.                   /* Do a byte relocation.  If it doesn't
  1991.                  fit (possible on m68000) let the
  1992.                  fixup processing complain later.  */
  1993.                   if (opP->reg == PC)
  1994.                 add_fix ('B', &opP->disp, 1, 1, 0);    /* FIXME? -fnf */
  1995.                   else
  1996.                 add_fix ('B', &opP->disp, 0, 0, 0);    /* FIXME? -fnf */
  1997.                 }
  1998.               else if (siz1 != SIZE_BYTE)
  1999.                 {
  2000.                   if (siz1 != SIZE_UNSPEC)
  2001.                 as_warn ("Forcing byte displacement");
  2002.                   if (! issbyte (baseo))
  2003.                 opP->error = "byte displacement out of range";
  2004.                 }
  2005.  
  2006.               break;
  2007.             }
  2008.               else if (siz1 == SIZE_UNSPEC
  2009.                    && opP->reg == PC
  2010.                    && isvar (&opP->disp)
  2011.                    && subs (&opP->disp) == NULL
  2012. #ifdef OBJ_ELF
  2013.                    /* If the displacement needs pic
  2014.                   relocation it cannot be relaxed.  */
  2015.                    && opP->disp.pic_reloc == pic_none
  2016. #endif
  2017.                    )
  2018.             {
  2019.                nextword += baseo & 0xff;
  2020.                addword (nextword);
  2021.                add_frag (adds (&opP->disp), offs (&opP->disp),
  2022.                      TAB (PCINDEX, SZ_UNDEF));
  2023.  
  2024.               break;
  2025.              }
  2026.             }
  2027.         }
  2028.           else
  2029.         {
  2030.           nextword |= 0x40;    /* No index reg */
  2031.           if (opP->index.reg >= ZDATA0
  2032.               && opP->index.reg <= ZDATA7)
  2033.             nextword |= (opP->index.reg - ZDATA0) << 12;
  2034.           else if (opP->index.reg >= ZADDR0
  2035.                || opP->index.reg <= ZADDR7)
  2036.             nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
  2037.         }
  2038.  
  2039.           /* It isn't simple.  */
  2040.  
  2041.           if (cpu_of_arch (current_architecture) < m68020)
  2042.         opP->error =
  2043.           "invalid operand mode for this architecture; needs 68020 or higher";
  2044.  
  2045.           nextword |= 0x100;
  2046.           /* If the guy specified a width, we assume that it is
  2047.          wide enough.  Maybe it isn't.  If so, we lose.  */
  2048.           switch (siz1)
  2049.         {
  2050.         case SIZE_UNSPEC:
  2051.           if (isvar (&opP->disp)
  2052.               ? m68k_rel32
  2053.               : ! issword (baseo))
  2054.             {
  2055.               siz1 = SIZE_LONG;
  2056.               nextword |= 0x30;
  2057.             }
  2058.           else if (! isvar (&opP->disp) && baseo == 0)
  2059.             nextword |= 0x10;
  2060.           else
  2061.             {
  2062.               nextword |= 0x20;
  2063.               siz1 = SIZE_WORD;
  2064.             }
  2065.           break;
  2066.         case SIZE_BYTE:
  2067.           as_warn (":b not permitted; defaulting to :w");
  2068.           /* Fall through.  */
  2069.         case SIZE_WORD:
  2070.           nextword |= 0x20;
  2071.           break;
  2072.         case SIZE_LONG:
  2073.           nextword |= 0x30;
  2074.           break;
  2075.         }
  2076.  
  2077.           /* Figure out innner displacement stuff */
  2078.           if (opP->mode == POST || opP->mode == PRE)
  2079.         {
  2080.           if (cpu_of_arch (current_architecture) & cpu32)
  2081.             opP->error = "invalid operand mode for this architecture; needs 68020 or higher";
  2082.           switch (siz2)
  2083.             {
  2084.             case SIZE_UNSPEC:
  2085.               if (isvar (&opP->odisp)
  2086.               ? m68k_rel32
  2087.               : ! issword (outro))
  2088.             {
  2089.               siz2 = SIZE_LONG;
  2090.               nextword |= 0x3;
  2091.             }
  2092.               else if (! isvar (&opP->odisp) && outro == 0)
  2093.             nextword |= 0x1;
  2094.               else
  2095.             {
  2096.               nextword |= 0x2;
  2097.               siz2 = SIZE_WORD;
  2098.             }
  2099.               break;
  2100.             case 1:
  2101.               as_warn (":b not permitted; defaulting to :w");
  2102.               /* Fall through.  */
  2103.             case 2:
  2104.               nextword |= 0x2;
  2105.               break;
  2106.             case 3:
  2107.               nextword |= 0x3;
  2108.               break;
  2109.             }
  2110.           if (opP->mode == POST
  2111.               && (nextword & 0x40) == 0)
  2112.             nextword |= 0x04;
  2113.         }
  2114.           addword (nextword);
  2115.  
  2116.           if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
  2117.         {
  2118.           if (opP->reg == PC || opP->reg == ZPC)
  2119.             add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2, opP->disp.baserel);
  2120.           else
  2121.             add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0, opP->disp.baserel);
  2122.         }
  2123.           if (siz1 == SIZE_LONG)
  2124.         addword (baseo >> 16);
  2125.           if (siz1 != SIZE_UNSPEC)
  2126.         addword (baseo);
  2127.  
  2128.           if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
  2129.         add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0, opP->disp.baserel);
  2130.           if (siz2 == SIZE_LONG)
  2131.         addword (outro >> 16);
  2132.           if (siz2 != SIZE_UNSPEC)
  2133.         addword (outro);
  2134.  
  2135.           break;
  2136.  
  2137.         case ABSL:
  2138.           nextword = get_num (&opP->disp, 80);
  2139.           switch (opP->disp.size)
  2140.         {
  2141.         default:
  2142.           abort ();
  2143.         case SIZE_UNSPEC:
  2144.           if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
  2145.             {
  2146.               tmpreg = 0x38;    /* 7.0 */
  2147.               addword (nextword);
  2148.               break;
  2149.             }
  2150.           /* Don't generate pc relative code on 68010 and
  2151.              68000.  */
  2152.           if (isvar (&opP->disp)
  2153.               && !subs (&opP->disp)
  2154.               && adds (&opP->disp)
  2155. #ifdef OBJ_ELF
  2156.               /* If the displacement needs pic relocation it
  2157.              cannot be relaxed.  */
  2158.               && opP->disp.pic_reloc == pic_none
  2159. #endif
  2160.               && S_GET_SEGMENT (adds (&opP->disp)) == now_seg
  2161.               && (cpu_of_arch (current_architecture) >= m68020 || flag_small_code)
  2162.               && !flag_long_jumps
  2163.               && !strchr ("~%&$?", s[0]))
  2164.             {
  2165.               tmpreg = 0x3A;    /* 7.2 */
  2166.               add_frag (adds (&opP->disp),
  2167.                 offs (&opP->disp),
  2168.                 TAB (PCREL, SZ_UNDEF));
  2169.               break;
  2170.             }
  2171.           /* Fall through into long */
  2172.         case SIZE_LONG:
  2173. #if 0
  2174.         /* This doesn't work when the symbol is N_UNDF! We ignore this for now. */
  2175.  
  2176.           if (flag_small_code)
  2177.             {
  2178.               tmpreg=0x3A; /* 7.2 */
  2179.               add_frag (adds(&opP->disp),
  2180.                     offs(&opP->disp),
  2181.                 TAB(ABSREL, SZ_UNDEF));
  2182.               break;
  2183.             }
  2184. #endif
  2185.           if (isvar (&opP->disp))
  2186.             add_fix ('l', &opP->disp, 0, 0, opP->disp.baserel);
  2187.  
  2188.           tmpreg = 0x39;/* 7.1 mode */
  2189.           addword (nextword >> 16);
  2190.           addword (nextword);
  2191.           break;
  2192.  
  2193.         case SIZE_WORD:    /* Word */
  2194.           if (isvar (&opP->disp))
  2195.             add_fix ('w', &opP->disp, 0, 0, opP->disp.baserel);
  2196.  
  2197.           tmpreg = 0x38;/* 7.0 mode */
  2198.           addword (nextword);
  2199.           break;
  2200.         }
  2201.           break;
  2202.         case CONTROL:
  2203.         case FPREG:
  2204.         default:
  2205.           as_bad ("unknown/incorrect operand");
  2206.           /* abort(); */
  2207.         }
  2208.       install_gen_operand (s[1], tmpreg);
  2209.       break;
  2210.  
  2211.     case '#':
  2212.     case '^':
  2213.       switch (s[1])
  2214.         {            /* JF: I hate floating point! */
  2215.         case 'j':
  2216.           tmpreg = 70;
  2217.           break;
  2218.         case '8':
  2219.           tmpreg = 20;
  2220.           break;
  2221.         case 'C':
  2222.           tmpreg = 50;
  2223.           break;
  2224.         case '3':
  2225.         default:
  2226.           tmpreg = 80;
  2227.           break;
  2228.         }
  2229.       tmpreg = get_num (&opP->disp, tmpreg);
  2230.       if (isvar (&opP->disp))
  2231.         add_fix (s[1], &opP->disp, 0, 0, opP->disp.baserel);
  2232.       switch (s[1])
  2233.         {
  2234.         case 'b':        /* Danger:  These do no check for
  2235.                    certain types of overflow.
  2236.                    user beware! */
  2237.           if (!isbyte (tmpreg))
  2238.         opP->error = "out of range";
  2239.           insop (tmpreg, opcode);
  2240.           if (isvar (&opP->disp))
  2241.         the_ins.reloc[the_ins.nrel - 1].n =
  2242.           (opcode->m_codenum) * 2 + 1;
  2243.           break;
  2244.         case 'w':
  2245.           if (!isword (tmpreg))
  2246.         opP->error = "out of range";
  2247.           insop (tmpreg, opcode);
  2248.           if (isvar (&opP->disp))
  2249.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2250.           break;
  2251.         case 'W':
  2252.           if (!issword (tmpreg))
  2253.         opP->error = "out of range";
  2254.           insop (tmpreg, opcode);
  2255.           if (isvar (&opP->disp))
  2256.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2257.           break;
  2258.         case 'l':
  2259.           /* Because of the way insop works, we put these two out
  2260.          backwards.  */
  2261.           insop (tmpreg, opcode);
  2262.           insop (tmpreg >> 16, opcode);
  2263.           if (isvar (&opP->disp))
  2264.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2265.           break;
  2266.         case '3':
  2267.           tmpreg &= 0xFF;
  2268.         case '8':
  2269.         case 'C':
  2270.           install_operand (s[1], tmpreg);
  2271.           break;
  2272.         default:
  2273.           abort ();
  2274.         }
  2275.       break;
  2276.  
  2277.     case '+':
  2278.     case '-':
  2279.     case 'A':
  2280.     case 'a':
  2281.       install_operand (s[1], opP->reg - ADDR);
  2282.       break;
  2283.  
  2284.     case 'B':
  2285.       tmpreg = get_num (&opP->disp, 80);
  2286.       switch (s[1])
  2287.         {
  2288.         case 'B':
  2289.           /* The pc_fix argument winds up in fx_pcrel_adjust,
  2290.                  which is a char, and may therefore be unsigned.  We
  2291.                  want to pass -1, but we pass 64 instead, and convert
  2292.                  back in md_pcrel_from.  */
  2293.           add_fix ('B', &opP->disp, 1, 64, opP->disp.baserel);
  2294.           break;
  2295.         case 'W':
  2296.           add_fix ('w', &opP->disp, 1, 0, opP->disp.baserel);
  2297.           addword (0);
  2298.           break;
  2299.         case 'L':
  2300.         long_branch:
  2301.           if (cpu_of_arch (current_architecture) < m68020)
  2302.         as_warn ("Can't use long branches on 68000/68010");
  2303.           the_ins.opcode[the_ins.numo - 1] |= 0xff;
  2304.           add_fix ('l', &opP->disp, 1, 0, opP->disp.baserel);
  2305.           addword (0);
  2306.           addword (0);
  2307.           break;
  2308.         case 'g':
  2309.           if (subs (&opP->disp))    /* We can't relax it */
  2310.         goto long_branch;
  2311.  
  2312. #ifdef OBJ_ELF
  2313.           /* If the displacement needs pic relocation it cannot be
  2314.          relaxed.  */
  2315.           if (opP->disp.pic_reloc != pic_none)
  2316.         goto long_branch;
  2317. #endif
  2318.  
  2319.           /* This could either be a symbol, or an absolute
  2320.          address.  No matter, the frag hacking will finger it
  2321.          out.  Not quite: it can't switch from BRANCH to
  2322.          BCC68000 for the case where opnd is absolute (it
  2323.          needs to use the 68000 hack since no conditional abs
  2324.          jumps).  */
  2325.           if (((cpu_of_arch (current_architecture) < m68020)
  2326.            || (0 == adds (&opP->disp)))
  2327.           && (the_ins.opcode[0] >= 0x6200)
  2328.           && (the_ins.opcode[0] <= 0x6f00))
  2329.         add_frag (adds (&opP->disp), offs (&opP->disp),
  2330.               TAB (BCC68000, SZ_UNDEF));
  2331.           else
  2332.         add_frag (adds (&opP->disp), offs (&opP->disp),
  2333.               TAB (ABRANCH, SZ_UNDEF));
  2334.           break;
  2335.         case 'w':
  2336.           if (isvar (&opP->disp))
  2337.         {
  2338. #if 1
  2339.           /* check for DBcc instruction */
  2340.           if ((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
  2341.             {
  2342.               /* size varies if patch */
  2343.               /* needed for long form */
  2344.               add_frag (adds (&opP->disp), offs (&opP->disp),
  2345.                 TAB (DBCC, SZ_UNDEF));
  2346.               break;
  2347.             }
  2348. #endif
  2349.           add_fix ('w', &opP->disp, 1, 0, opP->disp.baserel);
  2350.         }
  2351.           addword (0);
  2352.           break;
  2353.         case 'C':        /* Fixed size LONG coproc branches */
  2354.           add_fix ('l', &opP->disp, 1, 0, opP->disp.baserel);
  2355.           addword (0);
  2356.           addword (0);
  2357.           break;
  2358.         case 'c':        /* Var size Coprocesssor branches */
  2359.           if (subs (&opP->disp))
  2360.         {
  2361.           add_fix ('l', &opP->disp, 1, 0, opP->disp.baserel);
  2362.           add_frag ((symbolS *) 0, (long) 0, TAB (FBRANCH, LONG));
  2363.         }
  2364.           else if (adds (&opP->disp))
  2365.         add_frag (adds (&opP->disp), offs (&opP->disp),
  2366.               TAB (FBRANCH, SZ_UNDEF));
  2367.           else
  2368.         {
  2369.           /* add_frag((symbolS *) 0, offs(&opP->disp),
  2370.              TAB(FBRANCH,SHORT)); */
  2371.           the_ins.opcode[the_ins.numo - 1] |= 0x40;
  2372.           add_fix ('l', &opP->disp, 1, 0, opP->disp.baserel);
  2373.           addword (0);
  2374.           addword (0);
  2375.         }
  2376.           break;
  2377.         default:
  2378.           abort ();
  2379.         }
  2380.       break;
  2381.  
  2382.     case 'C':        /* Ignore it */
  2383.       break;
  2384.  
  2385.     case 'd':        /* JF this is a kludge */
  2386.       install_operand ('s', opP->reg - ADDR);
  2387.       tmpreg = get_num (&opP->disp, 80);
  2388.       if (!issword (tmpreg))
  2389.         {
  2390.           as_warn ("Expression out of range, using 0");
  2391.           tmpreg = 0;
  2392.         }
  2393.       addword (tmpreg);
  2394.       break;
  2395.  
  2396.     case 'D':
  2397.       install_operand (s[1], opP->reg - DATA);
  2398.       break;
  2399.  
  2400.     case 'F':
  2401.       install_operand (s[1], opP->reg - FP0);
  2402.       break;
  2403.  
  2404.     case 'I':
  2405.       tmpreg = opP->reg - COP0;
  2406.       install_operand (s[1], tmpreg);
  2407.       break;
  2408.  
  2409.     case 'J':        /* JF foo */
  2410.       switch (opP->reg)
  2411.         {
  2412.         case SFC:
  2413.           tmpreg = 0x000;
  2414.           break;
  2415.         case DFC:
  2416.           tmpreg = 0x001;
  2417.           break;
  2418.         case CACR:
  2419.           tmpreg = 0x002;
  2420.           break;
  2421.         case TC:
  2422.           tmpreg = 0x003;
  2423.           break;
  2424.         case ITT0:
  2425.           tmpreg = 0x004;
  2426.           break;
  2427.         case ITT1:
  2428.           tmpreg = 0x005;
  2429.           break;
  2430.         case DTT0:
  2431.           tmpreg = 0x006;
  2432.           break;
  2433.         case DTT1:
  2434.           tmpreg = 0x007;
  2435.           break;
  2436.         case BUSCR:
  2437.           tmpreg = 0x008;
  2438.           break;
  2439.  
  2440.         case USP:
  2441.           tmpreg = 0x800;
  2442.           break;
  2443.         case VBR:
  2444.           tmpreg = 0x801;
  2445.           break;
  2446.         case CAAR:
  2447.           tmpreg = 0x802;
  2448.           break;
  2449.         case MSP:
  2450.           tmpreg = 0x803;
  2451.           break;
  2452.         case ISP:
  2453.           tmpreg = 0x804;
  2454.           break;
  2455.         case MMUSR:
  2456.           tmpreg = 0x805;
  2457.           break;
  2458.         case URP:
  2459.           tmpreg = 0x806;
  2460.           break;
  2461.         case SRP:
  2462.           tmpreg = 0x807;
  2463.           break;
  2464.         case PCR:
  2465.           tmpreg = 0x808;
  2466.           break;
  2467.             case ROMBAR:
  2468.           tmpreg = 0xC00;
  2469.           break;
  2470.         case RAMBAR0:
  2471.           tmpreg = 0xC04;
  2472.           break;
  2473.         case RAMBAR1:
  2474.           tmpreg = 0xC05;
  2475.           break;
  2476.         case MBAR:
  2477.           tmpreg = 0xC0F;
  2478.           break;
  2479.         default:
  2480.           abort ();
  2481.         }
  2482.       install_operand (s[1], tmpreg);
  2483.       break;
  2484.  
  2485.     case 'k':
  2486.       tmpreg = get_num (&opP->disp, 55);
  2487.       install_operand (s[1], tmpreg & 0x7f);
  2488.       break;
  2489.  
  2490.     case 'l':
  2491.       tmpreg = opP->mask;
  2492.       if (s[1] == 'w')
  2493.         {
  2494.           if (tmpreg & 0x7FF0000)
  2495.         as_bad ("Floating point register in register list");
  2496.           insop (reverse_16_bits (tmpreg), opcode);
  2497.         }
  2498.       else
  2499.         {
  2500.           if (tmpreg & 0x700FFFF)
  2501.         as_bad ("Wrong register in floating-point reglist");
  2502.           install_operand (s[1], reverse_8_bits (tmpreg >> 16));
  2503.         }
  2504.       break;
  2505.  
  2506.     case 'L':
  2507.       tmpreg = opP->mask;
  2508.       if (s[1] == 'w')
  2509.         {
  2510.           if (tmpreg & 0x7FF0000)
  2511.         as_bad ("Floating point register in register list");
  2512.           insop (tmpreg, opcode);
  2513.         }
  2514.       else if (s[1] == '8')
  2515.         {
  2516.           if (tmpreg & 0x0FFFFFF)
  2517.         as_bad ("incorrect register in reglist");
  2518.           install_operand (s[1], tmpreg >> 24);
  2519.         }
  2520.       else
  2521.         {
  2522.           if (tmpreg & 0x700FFFF)
  2523.         as_bad ("wrong register in floating-point reglist");
  2524.           else
  2525.         install_operand (s[1], tmpreg >> 16);
  2526.         }
  2527.       break;
  2528.  
  2529.     case 'M':
  2530.       install_operand (s[1], get_num (&opP->disp, 60));
  2531.       break;
  2532.  
  2533.     case 'O':
  2534.       tmpreg = ((opP->mode == DREG)
  2535.             ? 0x20 + opP->reg - DATA
  2536.             : (get_num (&opP->disp, 40) & 0x1F));
  2537.       install_operand (s[1], tmpreg);
  2538.       break;
  2539.  
  2540.     case 'Q':
  2541.       tmpreg = get_num (&opP->disp, 10);
  2542.       if (tmpreg == 8)
  2543.         tmpreg = 0;
  2544.       install_operand (s[1], tmpreg);
  2545.       break;
  2546.  
  2547.     case 'R':
  2548.       /* This depends on the fact that ADDR registers are eight
  2549.          more than their corresponding DATA regs, so the result
  2550.          will have the ADDR_REG bit set */
  2551.       install_operand (s[1], opP->reg - DATA);
  2552.       break;
  2553.  
  2554.     case 'r':
  2555.       if (opP->mode == AINDR)
  2556.         install_operand (s[1], opP->reg - DATA);
  2557.       else
  2558.         install_operand (s[1], opP->index.reg - DATA);
  2559.       break;
  2560.  
  2561.     case 's':
  2562.       if (opP->reg == FPI)
  2563.         tmpreg = 0x1;
  2564.       else if (opP->reg == FPS)
  2565.         tmpreg = 0x2;
  2566.       else if (opP->reg == FPC)
  2567.         tmpreg = 0x4;
  2568.       else
  2569.         abort ();
  2570.       install_operand (s[1], tmpreg);
  2571.       break;
  2572.  
  2573.     case 'S':        /* Ignore it */
  2574.       break;
  2575.  
  2576.     case 'T':
  2577.       install_operand (s[1], get_num (&opP->disp, 30));
  2578.       break;
  2579.  
  2580.     case 'U':        /* Ignore it */
  2581.       break;
  2582.  
  2583.     case 'c':
  2584.       switch (opP->reg)
  2585.         {
  2586.         case NC:
  2587.           tmpreg = 0;
  2588.           break;
  2589.         case DC:
  2590.           tmpreg = 1;
  2591.           break;
  2592.         case IC:
  2593.           tmpreg = 2;
  2594.           break;
  2595.         case BC:
  2596.           tmpreg = 3;
  2597.           break;
  2598.         default:
  2599.           as_fatal ("failed sanity check");
  2600.         }            /* switch on cache token */
  2601.       install_operand (s[1], tmpreg);
  2602.       break;
  2603. #ifndef NO_68851
  2604.       /* JF: These are out of order, I fear. */
  2605.     case 'f':
  2606.       switch (opP->reg)
  2607.         {
  2608.         case SFC:
  2609.           tmpreg = 0;
  2610.           break;
  2611.         case DFC:
  2612.           tmpreg = 1;
  2613.           break;
  2614.         default:
  2615.           abort ();
  2616.         }
  2617.       install_operand (s[1], tmpreg);
  2618.       break;
  2619.  
  2620.     case '0':
  2621.     case '1':
  2622.     case '2':
  2623.       switch (opP->reg)
  2624.         {
  2625.         case TC:
  2626.           tmpreg = 0;
  2627.           break;
  2628.         case CAL:
  2629.           tmpreg = 4;
  2630.           break;
  2631.         case VAL:
  2632.           tmpreg = 5;
  2633.           break;
  2634.         case SCC:
  2635.           tmpreg = 6;
  2636.           break;
  2637.         case AC:
  2638.           tmpreg = 7;
  2639.           break;
  2640.         default:
  2641.           abort ();
  2642.         }
  2643.       install_operand (s[1], tmpreg);
  2644.       break;
  2645.  
  2646.     case 'V':
  2647.       if (opP->reg == VAL)
  2648.         break;
  2649.       abort ();
  2650.  
  2651.     case 'W':
  2652.       switch (opP->reg)
  2653.         {
  2654.         case DRP:
  2655.           tmpreg = 1;
  2656.           break;
  2657.         case SRP:
  2658.           tmpreg = 2;
  2659.           break;
  2660.         case CRP:
  2661.           tmpreg = 3;
  2662.           break;
  2663.         default:
  2664.           abort ();
  2665.         }
  2666.       install_operand (s[1], tmpreg);
  2667.       break;
  2668.  
  2669.     case 'X':
  2670.       switch (opP->reg)
  2671.         {
  2672.         case BAD:
  2673.         case BAD + 1:
  2674.         case BAD + 2:
  2675.         case BAD + 3:
  2676.         case BAD + 4:
  2677.         case BAD + 5:
  2678.         case BAD + 6:
  2679.         case BAD + 7:
  2680.           tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2681.           break;
  2682.  
  2683.         case BAC:
  2684.         case BAC + 1:
  2685.         case BAC + 2:
  2686.         case BAC + 3:
  2687.         case BAC + 4:
  2688.         case BAC + 5:
  2689.         case BAC + 6:
  2690.         case BAC + 7:
  2691.           tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2692.           break;
  2693.  
  2694.         default:
  2695.           abort ();
  2696.         }
  2697.       install_operand (s[1], tmpreg);
  2698.       break;
  2699.     case 'Y':
  2700.       know (opP->reg == PSR);
  2701.       break;
  2702.     case 'Z':
  2703.       know (opP->reg == PCSR);
  2704.       break;
  2705. #endif /* m68851 */
  2706.     case '3':
  2707.       switch (opP->reg)
  2708.         {
  2709.         case TT0:
  2710.           tmpreg = 2;
  2711.           break;
  2712.         case TT1:
  2713.           tmpreg = 3;
  2714.           break;
  2715.         default:
  2716.           abort ();
  2717.         }
  2718.       install_operand (s[1], tmpreg);
  2719.       break;
  2720.     case 't':
  2721.       tmpreg = get_num (&opP->disp, 20);
  2722.       install_operand (s[1], tmpreg);
  2723.       break;
  2724.     case '_':    /* used only for move16 absolute 32-bit address */
  2725.       tmpreg = get_num (&opP->disp, 80);
  2726.       addword (tmpreg >> 16);
  2727.       addword (tmpreg & 0xFFFF);
  2728.       break;
  2729.     default:
  2730.       abort ();
  2731.     }
  2732.     }
  2733.  
  2734.   /* By the time whe get here (FINALLY) the_ins contains the complete
  2735.      instruction, ready to be emitted. . . */
  2736. }
  2737.  
  2738. static int
  2739. reverse_16_bits (in)
  2740.      int in;
  2741. {
  2742.   int out = 0;
  2743.   int n;
  2744.  
  2745.   static int mask[16] =
  2746.   {
  2747.     0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  2748.     0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
  2749.   };
  2750.   for (n = 0; n < 16; n++)
  2751.     {
  2752.       if (in & mask[n])
  2753.     out |= mask[15 - n];
  2754.     }
  2755.   return out;
  2756. }                /* reverse_16_bits() */
  2757.  
  2758. static int
  2759. reverse_8_bits (in)
  2760.      int in;
  2761. {
  2762.   int out = 0;
  2763.   int n;
  2764.  
  2765.   static int mask[8] =
  2766.   {
  2767.     0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  2768.   };
  2769.  
  2770.   for (n = 0; n < 8; n++)
  2771.     {
  2772.       if (in & mask[n])
  2773.     out |= mask[7 - n];
  2774.     }
  2775.   return out;
  2776. }                /* reverse_8_bits() */
  2777.  
  2778. /* Cause an extra frag to be generated here, inserting up to 10 bytes
  2779.    (that value is chosen in the frag_var call in md_assemble).  TYPE
  2780.    is the subtype of the frag to be generated; its primary type is
  2781.    rs_machine_dependent.
  2782.  
  2783.    The TYPE parameter is also used by md_convert_frag_1 and
  2784.    md_estimate_size_before_relax.  The appropriate type of fixup will
  2785.    be emitted by md_convert_frag_1.
  2786.  
  2787.    ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET.  */
  2788. static void
  2789. install_operand (mode, val)
  2790.      int mode;
  2791.      int val;
  2792. {
  2793.   switch (mode)
  2794.     {
  2795.     case 's':
  2796.       the_ins.opcode[0] |= val & 0xFF;    /* JF FF is for M kludge */
  2797.       break;
  2798.     case 'd':
  2799.       the_ins.opcode[0] |= val << 9;
  2800.       break;
  2801.     case '1':
  2802.       the_ins.opcode[1] |= val << 12;
  2803.       break;
  2804.     case '2':
  2805.       the_ins.opcode[1] |= val << 6;
  2806.       break;
  2807.     case '3':
  2808.       the_ins.opcode[1] |= val;
  2809.       break;
  2810.     case '4':
  2811.       the_ins.opcode[2] |= val << 12;
  2812.       break;
  2813.     case '5':
  2814.       the_ins.opcode[2] |= val << 6;
  2815.       break;
  2816.     case '6':
  2817.       /* DANGER!  This is a hack to force cas2l and cas2w cmds to be
  2818.      three words long! */
  2819.       the_ins.numo++;
  2820.       the_ins.opcode[2] |= val;
  2821.       break;
  2822.     case '7':
  2823.       the_ins.opcode[1] |= val << 7;
  2824.       break;
  2825.     case '8':
  2826.       the_ins.opcode[1] |= val << 10;
  2827.       break;
  2828. #ifndef NO_68851
  2829.     case '9':
  2830.       the_ins.opcode[1] |= val << 5;
  2831.       break;
  2832. #endif
  2833.  
  2834.     case 't':
  2835.       the_ins.opcode[1] |= (val << 10) | (val << 7);
  2836.       break;
  2837.     case 'D':
  2838.       the_ins.opcode[1] |= (val << 12) | val;
  2839.       break;
  2840.     case 'g':
  2841.       the_ins.opcode[0] |= val = 0xff;
  2842.       break;
  2843.     case 'i':
  2844.       the_ins.opcode[0] |= val << 9;
  2845.       break;
  2846.     case 'C':
  2847.       the_ins.opcode[1] |= val;
  2848.       break;
  2849.     case 'j':
  2850.       the_ins.opcode[1] |= val;
  2851.       the_ins.numo++;        /* What a hack */
  2852.       break;
  2853.     case 'k':
  2854.       the_ins.opcode[1] |= val << 4;
  2855.       break;
  2856.     case 'b':
  2857.     case 'w':
  2858.     case 'W':
  2859.     case 'l':
  2860.       break;
  2861.     case 'e':
  2862.       the_ins.opcode[0] |= (val << 6);
  2863.       break;
  2864.     case 'L':
  2865.       the_ins.opcode[1] = (val >> 16);
  2866.       the_ins.opcode[2] = val & 0xffff;
  2867.       break;
  2868.     case 'c':
  2869.     default:
  2870.       as_fatal ("failed sanity check.");
  2871.     }
  2872. }                /* install_operand() */
  2873.  
  2874. static void
  2875. install_gen_operand (mode, val)
  2876.      int mode;
  2877.      int val;
  2878. {
  2879.   switch (mode)
  2880.     {
  2881.     case 's':
  2882.       the_ins.opcode[0] |= val;
  2883.       break;
  2884.     case 'd':
  2885.       /* This is a kludge!!! */
  2886.       the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
  2887.       break;
  2888.     case 'b':
  2889.     case 'w':
  2890.     case 'l':
  2891.     case 'f':
  2892.     case 'F':
  2893.     case 'x':
  2894.     case 'p':
  2895.       the_ins.opcode[0] |= val;
  2896.       break;
  2897.       /* more stuff goes here */
  2898.     default:
  2899.       as_fatal ("failed sanity check.");
  2900.     }
  2901. }                /* install_gen_operand() */
  2902.  
  2903. /*
  2904.  * verify that we have some number of paren pairs, do m68k_ip_op(), and
  2905.  * then deal with the bitfield hack.
  2906.  */
  2907.  
  2908. static char *
  2909. crack_operand (str, opP)
  2910.      register char *str;
  2911.      register struct m68k_op *opP;
  2912. {
  2913.   register int parens;
  2914.   register int c;
  2915.   register char *beg_str;
  2916.   int inquote = 0;
  2917.  
  2918.   if (!str)
  2919.     {
  2920.       return str;
  2921.     }
  2922.   beg_str = str;
  2923.   for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
  2924.     {
  2925.       if (! inquote)
  2926.     {
  2927.       if (*str == '(')
  2928.         parens++;
  2929.       else if (*str == ')')
  2930.         {
  2931.           if (!parens)
  2932.         {            /* ERROR */
  2933.           opP->error = "Extra )";
  2934.           return str;
  2935.         }
  2936.           --parens;
  2937.         }
  2938.     }
  2939.       if (flag_mri && *str == '\'')
  2940.     inquote = ! inquote;
  2941.     }
  2942.   if (!*str && parens)
  2943.     {                /* ERROR */
  2944.       opP->error = "Missing )";
  2945.       return str;
  2946.     }
  2947.   c = *str;
  2948.   *str = '\0';
  2949.   if (m68k_ip_op (beg_str, opP) != 0)
  2950.     {
  2951.       *str = c;
  2952.       return str;
  2953.     }
  2954.   *str = c;
  2955.   if (c == '}')
  2956.     c = *++str;            /* JF bitfield hack */
  2957.   if (c)
  2958.     {
  2959.       c = *++str;
  2960.       if (!c)
  2961.     as_bad ("Missing operand");
  2962.     }
  2963.   return str;
  2964. }
  2965.  
  2966. /* This is the guts of the machine-dependent assembler.  STR points to a
  2967.    machine dependent instruction.  This function is supposed to emit
  2968.    the frags/bytes it assembles to.
  2969.    */
  2970.  
  2971. void
  2972. insert_reg (regname, regnum)
  2973.      char *regname;
  2974.      int regnum;
  2975. {
  2976.   char buf[100];
  2977.   int i;
  2978.  
  2979. #ifdef REGISTER_PREFIX
  2980.   if (!flag_reg_prefix_optional)
  2981.     {
  2982.       buf[0] = REGISTER_PREFIX;
  2983.       strcpy (buf + 1, regname);
  2984.       regname = buf;
  2985.     }
  2986. #endif
  2987.  
  2988.   symbol_table_insert (symbol_new (regname, reg_section, regnum,
  2989.                    &zero_address_frag));
  2990.  
  2991.   for (i = 0; regname[i]; i++)
  2992.     buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
  2993.   buf[i] = '\0';
  2994.  
  2995.   symbol_table_insert (symbol_new (buf, reg_section, regnum,
  2996.                    &zero_address_frag));
  2997. }
  2998.  
  2999. struct init_entry
  3000.   {
  3001.     const char *name;
  3002.     int number;
  3003.   };
  3004.  
  3005. static const struct init_entry init_table[] =
  3006. {
  3007.   { "d0", DATA0 },
  3008.   { "d1", DATA1 },
  3009.   { "d2", DATA2 },
  3010.   { "d3", DATA3 },
  3011.   { "d4", DATA4 },
  3012.   { "d5", DATA5 },
  3013.   { "d6", DATA6 },
  3014.   { "d7", DATA7 },
  3015.   { "a0", ADDR0 },
  3016.   { "a1", ADDR1 },
  3017.   { "a2", ADDR2 },
  3018.   { "a3", ADDR3 },
  3019.   { "a4", ADDR4 },
  3020.   { "a5", ADDR5 },
  3021.   { "fp", ADDR5 },
  3022.   { "a6", ADDR6 },
  3023.   { "a7", ADDR7 },
  3024.   { "sp", ADDR7 },
  3025.   { "ssp", ADDR7 },
  3026.   { "fp0", FP0 },
  3027.   { "fp1", FP1 },
  3028.   { "fp2", FP2 },
  3029.   { "fp3", FP3 },
  3030.   { "fp4", FP4 },
  3031.   { "fp5", FP5 },
  3032.   { "fp6", FP6 },
  3033.   { "fp7", FP7 },
  3034.   { "fpi", FPI },
  3035.   { "fpiar", FPI },
  3036.   { "fpc", FPI },
  3037.   { "fps", FPS },
  3038.   { "fpsr", FPS },
  3039.   { "fpc", FPC },
  3040.   { "fpcr", FPC },
  3041.   { "control", FPC },
  3042.   { "status", FPS },
  3043.   { "iaddr", FPI },
  3044.  
  3045.   { "cop0", COP0 },
  3046.   { "cop1", COP1 },
  3047.   { "cop2", COP2 },
  3048.   { "cop3", COP3 },
  3049.   { "cop4", COP4 },
  3050.   { "cop5", COP5 },
  3051.   { "cop6", COP6 },
  3052.   { "cop7", COP7 },
  3053.   { "pc", PC },
  3054.   { "zpc", ZPC },
  3055.   { "sr", SR },
  3056.  
  3057.   { "ccr", CCR },
  3058.   { "cc", CCR },
  3059.  
  3060.   /* control registers */
  3061.   { "sfc", SFC },        /* Source Function Code */
  3062.   { "sfcr", SFC },
  3063.   { "dfc", DFC },        /* Destination Function Code */
  3064.   { "dfcr", DFC },
  3065.   { "cacr", CACR },        /* Cache Control Register */
  3066.   { "caar", CAAR },        /* Cache Address Register */
  3067.  
  3068.   { "usp", USP },        /* User Stack Pointer */
  3069.   { "vbr", VBR },        /* Vector Base Register */
  3070.   { "msp", MSP },        /* Master Stack Pointer */
  3071.   { "isp", ISP },        /* Interrupt Stack Pointer */
  3072.  
  3073.   { "itt0", ITT0 },        /* Instruction Transparent Translation Reg 0 */
  3074.   { "itt1", ITT1 },        /* Instruction Transparent Translation Reg 1 */
  3075.   { "dtt0", DTT0 },        /* Data Transparent Translation Register 0 */
  3076.   { "dtt1", DTT1 },        /* Data Transparent Translation Register 1 */
  3077.  
  3078.   /* 68ec040 versions of same */
  3079.   { "iacr0", ITT0 },        /* Instruction Access Control Register 0 */
  3080.   { "iacr1", ITT1 },        /* Instruction Access Control Register 0 */
  3081.   { "dacr0", DTT0 },        /* Data Access Control Register 0 */
  3082.   { "dacr1", DTT1 },        /* Data Access Control Register 0 */
  3083.  
  3084.   /* mcf5200 versions of same */
  3085.   { "acr2", ITT0 },        /* Access Control Unit 2 */
  3086.   { "acr3", ITT1 },        /* Access Control Unit 3 */
  3087.   { "acr0", DTT0 },        /* Access Control Unit 0 */
  3088.   { "acr1", DTT1 },        /* Access Control Unit 1 */
  3089.  
  3090.   { "tc", TC },            /* MMU Translation Control Register */
  3091.   { "tcr", TC },
  3092.  
  3093.   { "mmusr", MMUSR },        /* MMU Status Register */
  3094.   { "srp", SRP },        /* User Root Pointer */
  3095.   { "urp", URP },        /* Supervisor Root Pointer */
  3096.  
  3097.   { "buscr", BUSCR },
  3098.   { "pcr", PCR },
  3099.  
  3100.   { "rombar", ROMBAR },        /* ROM Base Address Register */
  3101.   { "rambar0", RAMBAR0 },    /* ROM Base Address Register */
  3102.   { "rambar1", RAMBAR1 },    /* ROM Base Address Register */
  3103.   { "mbar", MBAR },        /* Module Base Address Register */
  3104.   /* end of control registers */
  3105.  
  3106.   { "ac", AC },
  3107.   { "bc", BC },
  3108.   { "cal", CAL },
  3109.   { "crp", CRP },
  3110.   { "drp", DRP },
  3111.   { "pcsr", PCSR },
  3112.   { "psr", PSR },
  3113.   { "scc", SCC },
  3114.   { "val", VAL },
  3115.   { "bad0", BAD0 },
  3116.   { "bad1", BAD1 },
  3117.   { "bad2", BAD2 },
  3118.   { "bad3", BAD3 },
  3119.   { "bad4", BAD4 },
  3120.   { "bad5", BAD5 },
  3121.   { "bad6", BAD6 },
  3122.   { "bad7", BAD7 },
  3123.   { "bac0", BAC0 },
  3124.   { "bac1", BAC1 },
  3125.   { "bac2", BAC2 },
  3126.   { "bac3", BAC3 },
  3127.   { "bac4", BAC4 },
  3128.   { "bac5", BAC5 },
  3129.   { "bac6", BAC6 },
  3130.   { "bac7", BAC7 },
  3131.  
  3132.   { "ic", IC },
  3133.   { "dc", DC },
  3134.   { "nc", NC },
  3135.  
  3136.   { "tt0", TT0 },
  3137.   { "tt1", TT1 },
  3138.   /* 68ec030 versions of same */
  3139.   { "ac0", TT0 },
  3140.   { "ac1", TT1 },
  3141.   /* 68ec030 access control unit, identical to 030 MMU status reg */
  3142.   { "acusr", PSR },
  3143.  
  3144.   /* Suppressed data and address registers.  */
  3145.   { "zd0", ZDATA0 },
  3146.   { "zd1", ZDATA1 },
  3147.   { "zd2", ZDATA2 },
  3148.   { "zd3", ZDATA3 },
  3149.   { "zd4", ZDATA4 },
  3150.   { "zd5", ZDATA5 },
  3151.   { "zd6", ZDATA6 },
  3152.   { "zd7", ZDATA7 },
  3153.   { "za0", ZADDR0 },
  3154.   { "za1", ZADDR1 },
  3155.   { "za2", ZADDR2 },
  3156.   { "za3", ZADDR3 },
  3157.   { "za4", ZADDR4 },
  3158.   { "za5", ZADDR5 },
  3159.   { "za6", ZADDR6 },
  3160.   { "za7", ZADDR7 },
  3161.  
  3162.   { 0, 0 }
  3163. };
  3164.  
  3165. void
  3166. init_regtable ()
  3167. {
  3168.   int i;
  3169.   for (i = 0; init_table[i].name; i++)
  3170.     insert_reg (init_table[i].name, init_table[i].number);
  3171. }
  3172.  
  3173. static int no_68851, no_68881;
  3174.  
  3175. #ifdef OBJ_AOUT
  3176. /* a.out machine type.  Default to 68020.  */
  3177. int m68k_aout_machtype = 2;
  3178. #endif
  3179.  
  3180. void
  3181. md_assemble (str)
  3182.      char *str;
  3183. {
  3184.   const char *er;
  3185.   short *fromP;
  3186.   char *toP = NULL;
  3187.   int m, n = 0;
  3188.   char *to_beg_P;
  3189.   int shorts_this_frag;
  3190.   fixS *fixP;
  3191.  
  3192.   /* In MRI mode, the instruction and operands are separated by a
  3193.      space.  Anything following the operands is a comment.  The label
  3194.      has already been removed.  */
  3195.   if (flag_mri)
  3196.     {
  3197.       char *s;
  3198.       int fields = 0;
  3199.       int infield = 0;
  3200.       int inquote = 0;
  3201.  
  3202.       for (s = str; *s != '\0'; s++)
  3203.     {
  3204.       if ((*s == ' ' || *s == '\t') && ! inquote)
  3205.         {
  3206.           if (infield)
  3207.         {
  3208.           ++fields;
  3209.           if (fields >= 2)
  3210.             {
  3211.               *s = '\0';
  3212.               break;
  3213.             }
  3214.           infield = 0;
  3215.         }
  3216.         }
  3217.       else
  3218.         {
  3219.           if (! infield)
  3220.         infield = 1;
  3221.           if (*s == '\'')
  3222.         inquote = ! inquote;
  3223.         }
  3224.     }
  3225.     }
  3226.  
  3227.   memset ((char *) (&the_ins), '\0', sizeof (the_ins));
  3228.   m68k_ip (str);
  3229.   er = the_ins.error;
  3230.   if (!er)
  3231.     {
  3232.       for (n = 0; n < the_ins.numargs; n++)
  3233.     if (the_ins.operands[n].error)
  3234.       {
  3235.         er = the_ins.operands[n].error;
  3236.         break;
  3237.       }
  3238.     }
  3239.   if (er)
  3240.     {
  3241.       as_bad ("%s -- statement `%s' ignored", er, str);
  3242.       return;
  3243.     }
  3244.  
  3245.   if (the_ins.nfrag == 0)
  3246.     {
  3247.       /* No frag hacking involved; just put it out */
  3248.       toP = frag_more (2 * the_ins.numo);
  3249.       fromP = &the_ins.opcode[0];
  3250.       for (m = the_ins.numo; m; --m)
  3251.     {
  3252.       md_number_to_chars (toP, (long) (*fromP), 2);
  3253.       toP += 2;
  3254.       fromP++;
  3255.     }
  3256.       /* put out symbol-dependent info */
  3257.       for (m = 0; m < the_ins.nrel; m++)
  3258.     {
  3259.       switch (the_ins.reloc[m].wid)
  3260.         {
  3261.         case 'B':
  3262.           n = 1;
  3263.           break;
  3264.         case 'b':
  3265.           n = 1;
  3266.           break;
  3267.         case '3':
  3268.           n = 2;
  3269.           break;
  3270.         case 'w':
  3271.           n = 2;
  3272.           break;
  3273.         case 'l':
  3274.           n = 4;
  3275.           break;
  3276.         default:
  3277.           as_fatal ("Don't know how to figure width of %c in md_assemble()",
  3278.             the_ins.reloc[m].wid);
  3279.         }
  3280.  
  3281.       fixP = fix_new_exp (frag_now,
  3282.                   ((toP - frag_now->fr_literal)
  3283.                    - the_ins.numo * 2 + the_ins.reloc[m].n),
  3284.                   n,
  3285.                   &the_ins.reloc[m].exp,
  3286.                   the_ins.reloc[m].pcrel,
  3287.                   get_reloc_code (n, the_ins.reloc[m].pcrel,
  3288.                           the_ins.reloc[m].pic_reloc),
  3289.                   the_ins.reloc[m].baserel);
  3290.       fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
  3291.     }
  3292.       return;
  3293.     }
  3294.  
  3295.   /* There's some frag hacking */
  3296.   for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
  3297.     {
  3298.       int wid;
  3299.  
  3300.       if (n == 0)
  3301.     wid = 2 * the_ins.fragb[n].fragoff;
  3302.       else
  3303.     wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  3304.       toP = frag_more (wid);
  3305.       to_beg_P = toP;
  3306.       shorts_this_frag = 0;
  3307.       for (m = wid / 2; m; --m)
  3308.     {
  3309.       md_number_to_chars (toP, (long) (*fromP), 2);
  3310.       toP += 2;
  3311.       fromP++;
  3312.       shorts_this_frag++;
  3313.     }
  3314.       for (m = 0; m < the_ins.nrel; m++)
  3315.     {
  3316.       if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
  3317.         {
  3318.           the_ins.reloc[m].n -= 2 * shorts_this_frag;
  3319.           break;
  3320.         }
  3321.       wid = the_ins.reloc[m].wid;
  3322.       if (wid == 0)
  3323.         continue;
  3324.       the_ins.reloc[m].wid = 0;
  3325.       wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  3326.  
  3327.       fixP = fix_new_exp (frag_now,
  3328.                   ((toP - frag_now->fr_literal)
  3329.                    - the_ins.numo * 2 + the_ins.reloc[m].n),
  3330.                   wid,
  3331.                   &the_ins.reloc[m].exp,
  3332.                   the_ins.reloc[m].pcrel,
  3333.                   get_reloc_code (wid, the_ins.reloc[m].pcrel,
  3334.                           the_ins.reloc[m].pic_reloc),
  3335.                   the_ins.reloc[m].baserel);
  3336.       fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
  3337.     }
  3338.       (void) frag_var (rs_machine_dependent, 10, 0,
  3339.                (relax_substateT) (the_ins.fragb[n].fragty),
  3340.                the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
  3341.     }
  3342.   n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  3343.   shorts_this_frag = 0;
  3344.   if (n)
  3345.     {
  3346.       toP = frag_more (n * sizeof (short));
  3347.       while (n--)
  3348.     {
  3349.       md_number_to_chars (toP, (long) (*fromP), 2);
  3350.       toP += 2;
  3351.       fromP++;
  3352.       shorts_this_frag++;
  3353.     }
  3354.     }
  3355.   for (m = 0; m < the_ins.nrel; m++)
  3356.     {
  3357.       int wid;
  3358.  
  3359.       wid = the_ins.reloc[m].wid;
  3360.       if (wid == 0)
  3361.     continue;
  3362.       the_ins.reloc[m].wid = 0;
  3363.       wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  3364.  
  3365.       fixP = fix_new_exp (frag_now,
  3366.               ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
  3367.                - shorts_this_frag * 2),
  3368.               wid,
  3369.               &the_ins.reloc[m].exp,
  3370.               the_ins.reloc[m].pcrel,
  3371.               get_reloc_code (wid, the_ins.reloc[m].pcrel,
  3372.                       the_ins.reloc[m].pic_reloc),
  3373.               the_ins.reloc[m].baserel);
  3374.       fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
  3375.     }
  3376. }
  3377.  
  3378. void
  3379. md_begin ()
  3380. {
  3381.   /*
  3382.    * md_begin -- set up hash tables with 68000 instructions.
  3383.    * similar to what the vax assembler does.  ---phr
  3384.    */
  3385.   /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  3386.      a copy of it at runtime, adding in the information we want but isn't
  3387.      there.  I think it'd be better to have an awk script hack the table
  3388.      at compile time.  Or even just xstr the table and use it as-is.  But
  3389.      my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  3390.      names.  */
  3391.  
  3392.   register const struct m68k_opcode *ins;
  3393.   register struct m68k_incant *hack, *slak;
  3394.   register const char *retval = 0;    /* empty string, or error msg text */
  3395.   register unsigned int i;
  3396.   register char c;
  3397.  
  3398.   if (flag_mri)
  3399.     {
  3400.       flag_reg_prefix_optional = 1;
  3401.       m68k_abspcadd = 1;
  3402.       m68k_rel32 = 0;
  3403.     }
  3404.  
  3405.   op_hash = hash_new ();
  3406.  
  3407.   obstack_begin (&robyn, 4000);
  3408.   for (i = 0; i < m68k_numopcodes; i++)
  3409.     {
  3410.       hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3411.       do
  3412.     {
  3413.       ins = &m68k_opcodes[i];
  3414.       /* We *could* ignore insns that don't match our arch here
  3415.          but just leaving them out of the hash. */
  3416.       slak->m_operands = ins->args;
  3417.       slak->m_opnum = strlen (slak->m_operands) / 2;
  3418.       slak->m_arch = ins->arch;
  3419.       slak->m_opcode = ins->opcode;
  3420.       /* This is kludgey */
  3421.       slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
  3422.       if (i + 1 != m68k_numopcodes
  3423.           && !strcmp (ins->name, m68k_opcodes[i + 1].name))
  3424.         {
  3425.           slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3426.           i++;
  3427.         }
  3428.       else
  3429.         slak->m_next = 0;
  3430.       slak = slak->m_next;
  3431.     }
  3432.       while (slak);
  3433.  
  3434.       retval = hash_insert (op_hash, ins->name, (char *) hack);
  3435.       if (retval)
  3436.     as_fatal ("Internal Error:  Can't hash %s: %s", ins->name, retval);
  3437.     }
  3438.  
  3439.   for (i = 0; i < m68k_numaliases; i++)
  3440.     {
  3441.       const char *name = m68k_opcode_aliases[i].primary;
  3442.       const char *alias = m68k_opcode_aliases[i].alias;
  3443.       PTR val = hash_find (op_hash, name);
  3444.       if (!val)
  3445.     as_fatal ("Internal Error: Can't find %s in hash table", name);
  3446.       retval = hash_insert (op_hash, alias, val);
  3447.       if (retval)
  3448.     as_fatal ("Internal Error: Can't hash %s: %s", alias, retval);
  3449.     }
  3450.  
  3451.   /* In MRI mode, all unsized branches are variable sized.  Normally,
  3452.      they are word sized.  */
  3453.   if (flag_mri)
  3454.     {
  3455.       static struct m68k_opcode_alias mri_aliases[] =
  3456.     {
  3457.       { "bhi",    "jhi", },
  3458.       { "bls",    "jls", },
  3459.       { "bcc",    "jcc", },
  3460.       { "bcs",    "jcs", },
  3461.       { "bne",    "jne", },
  3462.       { "beq",    "jeq", },
  3463.       { "bvc",    "jvc", },
  3464.       { "bvs",    "jvs", },
  3465.       { "bpl",    "jpl", },
  3466.       { "bmi",    "jmi", },
  3467.       { "bge",    "jge", },
  3468.       { "blt",    "jlt", },
  3469.       { "bgt",    "jgt", },
  3470.       { "ble",    "jle", },
  3471.       { "bra",    "jra", },
  3472.       { "bsr",    "jbsr", },
  3473.     };
  3474.  
  3475.       for (i = 0; i < sizeof mri_aliases / sizeof mri_aliases[0]; i++)
  3476.     {
  3477.       const char *name = mri_aliases[i].primary;
  3478.       const char *alias = mri_aliases[i].alias;
  3479.       PTR val = hash_find (op_hash, name);
  3480.       if (!val)
  3481.         as_fatal ("Internal Error: Can't find %s in hash table", name);
  3482.       retval = hash_jam (op_hash, alias, val);
  3483.       if (retval)
  3484.         as_fatal ("Internal Error: Can't hash %s: %s", alias, retval);
  3485.     }
  3486.     }
  3487.  
  3488.   for (i = 0; i < sizeof (mklower_table); i++)
  3489.     mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
  3490.  
  3491.   for (i = 0; i < sizeof (notend_table); i++)
  3492.     {
  3493.       notend_table[i] = 0;
  3494.       alt_notend_table[i] = 0;
  3495.     }
  3496.   notend_table[','] = 1;
  3497.   notend_table['{'] = 1;
  3498.   notend_table['}'] = 1;
  3499.   alt_notend_table['a'] = 1;
  3500.   alt_notend_table['A'] = 1;
  3501.   alt_notend_table['d'] = 1;
  3502.   alt_notend_table['D'] = 1;
  3503.   alt_notend_table['#'] = 1;
  3504.   alt_notend_table['&'] = 1;
  3505.   alt_notend_table['f'] = 1;
  3506.   alt_notend_table['F'] = 1;
  3507. #ifdef REGISTER_PREFIX
  3508.   alt_notend_table[REGISTER_PREFIX] = 1;
  3509. #endif
  3510.  
  3511.   /* We need to put '(' in alt_notend_table to handle
  3512.        cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
  3513.      */
  3514.   alt_notend_table['('] = 1;
  3515.  
  3516.   /* We need to put '@' in alt_notend_table to handle
  3517.        cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
  3518.      */
  3519.   alt_notend_table['@'] = 1;
  3520.  
  3521.   /* We need to put digits in alt_notend_table to handle
  3522.        bfextu %d0{24:1},%d0
  3523.      */
  3524.   alt_notend_table['0'] = 1;
  3525.   alt_notend_table['1'] = 1;
  3526.   alt_notend_table['2'] = 1;
  3527.   alt_notend_table['3'] = 1;
  3528.   alt_notend_table['4'] = 1;
  3529.   alt_notend_table['5'] = 1;
  3530.   alt_notend_table['6'] = 1;
  3531.   alt_notend_table['7'] = 1;
  3532.   alt_notend_table['8'] = 1;
  3533.   alt_notend_table['9'] = 1;
  3534.  
  3535. #ifndef MIT_SYNTAX_ONLY
  3536.   /* Insert pseudo ops, these have to go into the opcode table since
  3537.      gas expects pseudo ops to start with a dot */
  3538.   {
  3539.     int n = 0;
  3540.     while (mote_pseudo_table[n].poc_name)
  3541.       {
  3542.     hack = (struct m68k_incant *)
  3543.       obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3544.     hash_insert (op_hash,
  3545.              mote_pseudo_table[n].poc_name, (char *) hack);
  3546.     hack->m_operands = 0;
  3547.     hack->m_opnum = n;
  3548.     n++;
  3549.       }
  3550.   }
  3551. #endif
  3552.  
  3553.   init_regtable ();
  3554.  
  3555. #ifdef OBJ_ELF
  3556.   record_alignment (text_section, 2);
  3557.   record_alignment (data_section, 2);
  3558.   record_alignment (bss_section, 2);
  3559. #endif
  3560. }
  3561.  
  3562. void
  3563. m68k_init_after_args ()
  3564. {
  3565.   if (cpu_of_arch (current_architecture) == 0)
  3566.     {
  3567.       int i;
  3568.       const char *default_cpu = TARGET_CPU;
  3569.  
  3570.       if (*default_cpu == 'm')
  3571.     default_cpu++;
  3572.       for (i = 0; i < n_archs; i++)
  3573.     if (strcasecmp (default_cpu, archs[i].name) == 0)
  3574.       break;
  3575.       if (i == n_archs)
  3576.     {
  3577.       as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU);
  3578.       current_architecture |= m68020;
  3579.     }
  3580.       else
  3581.     current_architecture |= archs[i].arch;
  3582.     }
  3583.   /* Permit m68881 specification with all cpus; those that can't work
  3584.      with a coprocessor could be doing emulation.  */
  3585.   if (current_architecture & m68851)
  3586.     {
  3587.       if (current_architecture & m68040)
  3588.     {
  3589.       as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
  3590.     }
  3591.     }
  3592.   /* What other incompatibilities could we check for?  */
  3593.  
  3594.   /* Toss in some default assumptions about coprocessors.  */
  3595.   if (!no_68881
  3596.       && (cpu_of_arch (current_architecture)
  3597.       /* Can CPU32 have a 68881 coprocessor??  */
  3598.       & (m68020 | m68030 | cpu32)))
  3599.     {
  3600.       current_architecture |= m68881;
  3601.     }
  3602.   if (!no_68851
  3603.       && (cpu_of_arch (current_architecture) & m68020up) != 0
  3604.       && (cpu_of_arch (current_architecture) & m68040up) == 0)
  3605.     {
  3606.       current_architecture |= m68851;
  3607.     }
  3608.   if (no_68881 && (current_architecture & m68881))
  3609.     as_bad ("options for 68881 and no-68881 both given");
  3610.   if (no_68851 && (current_architecture & m68851))
  3611.     as_bad ("options for 68851 and no-68851 both given");
  3612.  
  3613. #ifdef OBJ_AOUT
  3614.   /* Work out the magic number.  This isn't very general.  */
  3615.   if (current_architecture & m68000)
  3616.     m68k_aout_machtype = 0;
  3617.   else if (current_architecture & m68010)
  3618.     m68k_aout_machtype = 1;
  3619.   else if (current_architecture & m68020)
  3620.     m68k_aout_machtype = 2;
  3621.   else
  3622.     m68k_aout_machtype = 2;
  3623. #endif
  3624.  
  3625.   /* Note which set of "movec" control registers is available.  */
  3626.   switch (cpu_of_arch (current_architecture))
  3627.     {
  3628.     case m68000:
  3629.       control_regs = m68000_control_regs;
  3630.       break;
  3631.     case m68010:
  3632.       control_regs = m68010_control_regs;
  3633.       break;
  3634.     case m68020:
  3635.     case m68030:
  3636.       control_regs = m68020_control_regs;
  3637.       break;
  3638.     case m68040:
  3639.       control_regs = m68040_control_regs;
  3640.       break;
  3641.     case m68060:
  3642.       control_regs = m68060_control_regs;
  3643.       break;
  3644.     case cpu32:
  3645.       control_regs = cpu32_control_regs;
  3646.       break;
  3647.     case mcf5200:
  3648.       control_regs = mcf5200_control_regs;
  3649.       break;
  3650.     default:
  3651.       abort ();
  3652.     }
  3653.  
  3654.   if (cpu_of_arch (current_architecture) < m68020)
  3655.     md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
  3656. }
  3657.  
  3658. /* This is called if we go in or out of MRI mode because of the .mri
  3659.    pseudo-op.  */
  3660.  
  3661. void
  3662. m68k_mri_mode_change (on)
  3663.      int on;
  3664. {
  3665.   if (on)
  3666.     {
  3667.       if (! flag_reg_prefix_optional)
  3668.     {
  3669.       flag_reg_prefix_optional = 1;
  3670. #ifdef REGISTER_PREFIX
  3671.       init_regtable ();
  3672. #endif
  3673.     }
  3674.       m68k_abspcadd = 1;
  3675.       m68k_rel32 = 0;
  3676.     }
  3677.   else
  3678.     {
  3679.       if (! reg_prefix_optional_seen)
  3680.     {
  3681. #ifdef REGISTER_PREFIX_OPTIONAL
  3682.       flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
  3683. #else
  3684.       flag_reg_prefix_optional = 0;
  3685. #endif
  3686. #ifdef REGISTER_PREFIX
  3687.       init_regtable ();
  3688. #endif
  3689.     }
  3690.       m68k_abspcadd = 0;
  3691.       m68k_rel32 = 1;
  3692.     }
  3693. }
  3694.  
  3695. /* Equal to MAX_PRECISION in atof-ieee.c */
  3696. #define MAX_LITTLENUMS 6
  3697.  
  3698. /* Turn a string in input_line_pointer into a floating point constant
  3699.    of type type, and store the appropriate bytes in *litP.  The number
  3700.    of LITTLENUMS emitted is stored in *sizeP .  An error message is
  3701.    returned, or NULL on OK.  */
  3702.  
  3703. char *
  3704. md_atof (type, litP, sizeP)
  3705.      char type;
  3706.      char *litP;
  3707.      int *sizeP;
  3708. {
  3709.   int prec;
  3710.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  3711.   LITTLENUM_TYPE *wordP;
  3712.   char *t;
  3713.   char *atof_ieee ();
  3714.  
  3715.   switch (type)
  3716.     {
  3717.     case 'f':
  3718.     case 'F':
  3719.     case 's':
  3720.     case 'S':
  3721.       prec = 2;
  3722.       break;
  3723.  
  3724.     case 'd':
  3725.     case 'D':
  3726.     case 'r':
  3727.     case 'R':
  3728.       prec = 4;
  3729.       break;
  3730.  
  3731.     case 'x':
  3732.     case 'X':
  3733.       prec = 6;
  3734.       break;
  3735.  
  3736.     case 'p':
  3737.     case 'P':
  3738.       prec = 6;
  3739.       break;
  3740.  
  3741.     default:
  3742.       *sizeP = 0;
  3743.       return "Bad call to MD_ATOF()";
  3744.     }
  3745.   t = atof_ieee (input_line_pointer, type, words);
  3746.   if (t)
  3747.     input_line_pointer = t;
  3748.  
  3749.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  3750.   for (wordP = words; prec--;)
  3751.     {
  3752.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  3753.       litP += sizeof (LITTLENUM_TYPE);
  3754.     }
  3755.   return 0;
  3756. }
  3757.  
  3758. void
  3759. md_number_to_chars (buf, val, n)
  3760.      char *buf;
  3761.      valueT val;
  3762.      int n;
  3763. {
  3764.   number_to_chars_bigendian (buf, val, n);
  3765. }
  3766.  
  3767. static void
  3768. md_apply_fix_2 (fixP, val)
  3769.      fixS *fixP;
  3770.      offsetT val;
  3771. {
  3772.   addressT upper_limit;
  3773.   offsetT lower_limit;
  3774.  
  3775.   /* This is unnecessary but it convinces the native rs6000 compiler
  3776.      to generate the code we want.  */
  3777.   char *buf = fixP->fx_frag->fr_literal;
  3778.   buf += fixP->fx_where;
  3779.   /* end ibm compiler workaround */
  3780.  
  3781.   if (val & 0x80000000)
  3782.     val |= ~(addressT)0x7fffffff;
  3783.   else
  3784.     val &= 0x7fffffff;
  3785.  
  3786. #ifdef OBJ_ELF
  3787.   if (fixP->fx_addsy)
  3788.     {
  3789.       memset (buf, 0, fixP->fx_size);
  3790.       fixP->fx_addnumber = val;    /* Remember value for emit_reloc */
  3791.       return;
  3792.     }
  3793. #endif
  3794.  
  3795.   switch (fixP->fx_size)
  3796.     {
  3797.       /* The cast to offsetT below are necessary to make code correct for
  3798.      machines where ints are smaller than offsetT */
  3799.     case 1:
  3800.       *buf++ = val;
  3801.       upper_limit = 0x7f;
  3802.       lower_limit = - (offsetT) 0x80;
  3803.       break;
  3804.     case 2:
  3805.       *buf++ = (val >> 8);
  3806.       *buf++ = val;
  3807.       upper_limit = 0x7fff;
  3808.       lower_limit = - (offsetT) 0x8000;
  3809.       break;
  3810.     case 4:
  3811.       *buf++ = (val >> 24);
  3812.       *buf++ = (val >> 16);
  3813.       *buf++ = (val >> 8);
  3814.       *buf++ = val;
  3815.       upper_limit = 0x7fffffff;
  3816.       lower_limit = - (offsetT) 0x7fffffff - 1;    /* avoid constant overflow */
  3817.       break;
  3818.     default:
  3819.       BAD_CASE (fixP->fx_size);
  3820.     }
  3821.  
  3822.   /* Fix up a negative reloc.  */
  3823.   if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
  3824.     {
  3825.       fixP->fx_addsy = fixP->fx_subsy;
  3826.       fixP->fx_subsy = NULL;
  3827.       fixP->fx_tcbit = 1;
  3828.     }
  3829.  
  3830.   /* For non-pc-relative values, it's conceivable we might get something
  3831.      like "0xff" for a byte field.  So extend the upper part of the range
  3832.      to accept such numbers.  We arbitrarily disallow "-0xff" or "0xff+0xff",
  3833.      so that we can do any range checking at all.  */
  3834.   if (!fixP->fx_pcrel)
  3835.     upper_limit = upper_limit * 2 + 1;
  3836.  
  3837.   if ((addressT) val > upper_limit
  3838.       && (val > 0 || val < lower_limit))
  3839.     as_bad_where (fixP->fx_file, fixP->fx_line, "value out of range");
  3840.  
  3841.   /* A one byte PC-relative reloc means a short branch.  We can't use
  3842.      a short branch with a value of 0 or -1, because those indicate
  3843.      different opcodes (branches with longer offsets).  */
  3844.   if (fixP->fx_pcrel
  3845.       && fixP->fx_size == 1
  3846.       && (fixP->fx_addsy == NULL
  3847.       || S_IS_DEFINED (fixP->fx_addsy))
  3848.       && (val == 0 || val == -1))
  3849.     as_bad_where (fixP->fx_file, fixP->fx_line, "invalid byte branch offset");
  3850. }
  3851.  
  3852. #ifdef BFD_ASSEMBLER
  3853. int
  3854. md_apply_fix (fixP, valp)
  3855.      fixS *fixP;
  3856.      valueT *valp;
  3857. {
  3858.   md_apply_fix_2 (fixP, (addressT) *valp);
  3859.   return 1;
  3860. }
  3861. #else
  3862. void md_apply_fix (fixP, val)
  3863.      fixS *fixP;
  3864.      long val;
  3865. {
  3866.   md_apply_fix_2 (fixP, (addressT) val);
  3867. }
  3868. #endif
  3869.  
  3870. /* *fragP has been relaxed to its final size, and now needs to have
  3871.    the bytes inside it modified to conform to the new size  There is UGLY
  3872.    MAGIC here. ..
  3873.    */
  3874. void
  3875. md_convert_frag_1 (fragP)
  3876.      register fragS *fragP;
  3877. {
  3878.   long disp;
  3879.   long ext = 0;
  3880.   fixS *fixP;
  3881.  
  3882.   /* Address in object code of the displacement.  */
  3883.   register int object_address = fragP->fr_fix + fragP->fr_address;
  3884.  
  3885.   /* Address in gas core of the place to store the displacement.  */
  3886.   /* This convinces the native rs6000 compiler to generate the code we
  3887.      want. */
  3888.   register char *buffer_address = fragP->fr_literal;
  3889.   buffer_address += fragP->fr_fix;
  3890.   /* end ibm compiler workaround */
  3891.  
  3892.   /* The displacement of the address, from current location.  */
  3893.   disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
  3894.   disp = (disp + fragP->fr_offset) - object_address;
  3895.  
  3896. #ifdef BFD_ASSEMBLER
  3897.   disp += fragP->fr_symbol->sy_frag->fr_address;
  3898. #endif
  3899.  
  3900.   switch (fragP->fr_subtype)
  3901.     {
  3902.     case TAB (BCC68000, BYTE):
  3903.     case TAB (ABRANCH, BYTE):
  3904.       know (issbyte (disp));
  3905.       if (disp == 0)
  3906.     as_bad ("short branch with zero offset: use :w");
  3907.       fragP->fr_opcode[1] = disp;
  3908.       ext = 0;
  3909.       break;
  3910.     case TAB (DBCC, SHORT):
  3911.       know (issword (disp));
  3912.       ext = 2;
  3913.       break;
  3914.     case TAB (BCC68000, SHORT):
  3915.     case TAB (ABRANCH, SHORT):
  3916.       know (issword (disp));
  3917.       fragP->fr_opcode[1] = 0x00;
  3918.       ext = 2;
  3919.       break;
  3920.     case TAB (ABRANCH, LONG):
  3921.       if (cpu_of_arch (current_architecture) < m68020)
  3922.     {
  3923.           if (flag_small_code)
  3924.             {
  3925.               as_bad("Long branch in small code model, not supported.");
  3926.             }
  3927.           else if (fragP->fr_opcode[0] == 0x61)
  3928.         /* BSR */
  3929.         {
  3930.           fragP->fr_opcode[0] = 0x4E;
  3931.           fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
  3932.  
  3933.           fix_new (fragP,
  3934.                fragP->fr_fix,
  3935.                4,
  3936.                fragP->fr_symbol,
  3937.                fragP->fr_offset,
  3938.                0,
  3939.                NO_RELOC, 0);
  3940.  
  3941.           fragP->fr_fix += 4;
  3942.           ext = 0;
  3943.         }
  3944.       /* BRA */
  3945.       else if (fragP->fr_opcode[0] == 0x60)
  3946.         {
  3947.           fragP->fr_opcode[0] = 0x4E;
  3948.           fragP->fr_opcode[1] = (char) 0xF9; /* JMP  with ABSL LONG offset */
  3949.           fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  3950.                fragP->fr_offset, 0, NO_RELOC, 0);
  3951.           fragP->fr_fix += 4;
  3952.           ext = 0;
  3953.         }
  3954.       else
  3955.         {
  3956.           as_bad ("Long branch offset not supported.");
  3957.         }
  3958.     }
  3959.       else
  3960.     {
  3961.       fragP->fr_opcode[1] = (char) 0xff;
  3962.       ext = 4;
  3963.     }
  3964.       break;
  3965.     case TAB (BCC68000, LONG):
  3966.       /* only Bcc 68000 instructions can come here */
  3967.       /* change bcc into b!cc/jmp absl long */
  3968.       fragP->fr_opcode[0] ^= 0x01;    /* invert bcc */
  3969.       fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
  3970.  
  3971.       /* JF: these used to be fr_opcode[2,3], but they may be in a
  3972.        different frag, in which case refering to them is a no-no.
  3973.        Only fr_opcode[0,1] are guaranteed to work. */
  3974.       *buffer_address++ = 0x4e;    /* put in jmp long (0x4ef9) */
  3975.       *buffer_address++ = (char) 0xf9;
  3976.       fragP->fr_fix += 2;    /* account for jmp instruction */
  3977.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  3978.            fragP->fr_offset, 0, NO_RELOC, 0);
  3979.       fragP->fr_fix += 4;
  3980.       ext = 0;
  3981.       break;
  3982.     case TAB (DBCC, LONG):
  3983.       /* only DBcc 68000 instructions can come here */
  3984.       /* change dbcc into dbcc/jmp absl long */
  3985.       /* JF: these used to be fr_opcode[2-7], but that's wrong */
  3986.       *buffer_address++ = 0x00;    /* branch offset = 4 */
  3987.       *buffer_address++ = 0x04;
  3988.       *buffer_address++ = 0x60;    /* put in bra pc+6 */
  3989.       *buffer_address++ = 0x06;
  3990.       *buffer_address++ = 0x4e;    /* put in jmp long (0x4ef9) */
  3991.       *buffer_address++ = (char) 0xf9;
  3992.  
  3993.       fragP->fr_fix += 6;    /* account for bra/jmp instructions */
  3994.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  3995.            fragP->fr_offset, 0, NO_RELOC, 0);
  3996.       fragP->fr_fix += 4;
  3997.       ext = 0;
  3998.       break;
  3999.     case TAB (FBRANCH, SHORT):
  4000.       know ((fragP->fr_opcode[1] & 0x40) == 0);
  4001.       ext = 2;
  4002.       break;
  4003.     case TAB (FBRANCH, LONG):
  4004.       fragP->fr_opcode[1] |= 0x40;    /* Turn on LONG bit */
  4005.       ext = 4;
  4006.       break;
  4007.     case TAB (PCREL, SHORT):
  4008.       ext = 2;
  4009.       break;
  4010.     case TAB (PCREL, LONG):
  4011.       /* The thing to do here is force it to ABSOLUTE LONG, since
  4012.     PCREL is really trying to shorten an ABSOLUTE address anyway */
  4013.       /* JF FOO This code has not been tested */
  4014.       if (flag_small_code)
  4015.         as_bad ("Trying to force a pcrel thing into absolute mode while in small code mode");
  4016.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
  4017.            0, NO_RELOC, 0);
  4018.       if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  4019.     as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
  4020.         (unsigned) fragP->fr_opcode[0],
  4021.         (unsigned long) fragP->fr_address);
  4022.       fragP->fr_opcode[1] &= ~0x3F;
  4023.       fragP->fr_opcode[1] |= 0x39;    /* Mode 7.1 */
  4024.       fragP->fr_fix += 4;
  4025.       ext = 0;
  4026.       break;
  4027.     case TAB (PCLEA, SHORT):
  4028.       fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
  4029.            fragP->fr_offset, 1, NO_RELOC, 0);
  4030.       fragP->fr_opcode[1] &= ~0x3F;
  4031.       fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
  4032.       ext = 2;
  4033.       break;
  4034.     case TAB (PCLEA, LONG):
  4035.       fixP = fix_new (fragP, (int) (fragP->fr_fix) + 2, 4, fragP->fr_symbol,
  4036.               fragP->fr_offset, 1, NO_RELOC, 0);
  4037.       fixP->fx_pcrel_adjust = 2;
  4038.       /* Already set to mode 7.3; this indicates: PC indirect with
  4039.      suppressed index, 32-bit displacement.  */
  4040.       *buffer_address++ = 0x01;
  4041.       *buffer_address++ = 0x70;
  4042.       fragP->fr_fix += 2;
  4043.       ext = 4;
  4044.       break;
  4045.  
  4046.     case TAB (PCINDEX, BYTE):
  4047.       disp += 2;
  4048.       if (!issbyte (disp))
  4049.     {
  4050.       as_bad ("displacement doesn't fit in one byte");
  4051.       disp = 0;
  4052.     }
  4053.       assert (fragP->fr_fix >= 2);
  4054.       buffer_address[-2] &= ~1;
  4055.       buffer_address[-1] = disp;
  4056.       ext = 0;
  4057.       break;
  4058.     case TAB (PCINDEX, SHORT):
  4059.       disp += 2;
  4060.       assert (issword (disp));
  4061.       assert (fragP->fr_fix >= 2);
  4062.       buffer_address[-2] |= 0x1;
  4063.       buffer_address[-1] = 0x20;
  4064.       fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
  4065.               fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
  4066.               NO_RELOC, 0);
  4067.       fixP->fx_pcrel_adjust = 2;
  4068.       ext = 2;
  4069.       break;
  4070.     case TAB (PCINDEX, LONG):
  4071.       disp += 2;
  4072.       fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
  4073.               fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
  4074.               NO_RELOC, 0);
  4075.       fixP->fx_pcrel_adjust = 2;
  4076.       assert (fragP->fr_fix >= 2);
  4077.       buffer_address[-2] |= 0x1;
  4078.       buffer_address[-1] = 0x30;
  4079.       ext = 4;
  4080.       break;
  4081.     case TAB(ABSREL,BYTE):
  4082.       as_bad ("ABSREL_BYTE: how the ** does this look ?? \n");
  4083.       break;
  4084.     case TAB(ABSREL,SHORT):
  4085.       subseg_change (text_section, 0);
  4086.       ext = 2;
  4087.       fragP->fr_opcode[1] &= ~0x3f;
  4088.       if ((S_GET_TYPE (fragP->fr_symbol)) == N_TEXT)
  4089.         {
  4090.           /* so this is really a pc-relative address */
  4091.           fragP->fr_opcode[1] |=  0x3a;
  4092.           fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol, fragP->fr_offset+2, 1, NO_RELOC, 0);
  4093.       break;
  4094.         }
  4095.       /* in that case we have to generate base-relative code
  4096.        * (note: if we're in N_UNDF, this could as well be pc-relative, but the linker
  4097.        *        will have to do the final patch in that case) */
  4098.       fragP->fr_opcode[1] |=  0x2c;  /* (a4) */
  4099.       fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,fragP->fr_offset, 0, NO_RELOC, 1);
  4100.       break;
  4101.     case TAB(ABSREL,LONG):
  4102.       as_bad ("ABSREL_LONG: sorry, not supported.\n");
  4103.       break;
  4104.   
  4105.     case TAB(IMMREL,BYTE):
  4106.       as_bad ("IMMREL_BYTE: how the ** does this look ?? \n");
  4107.       break;
  4108.     case TAB(IMMREL,SHORT):
  4109.       subseg_change (text_section, 0);
  4110.       ext = 0; 
  4111.       if ((S_GET_TYPE (fragP->fr_symbol)) == N_TEXT)
  4112.         {
  4113.       /* we can only fix operations on data registers, not on <ea> */
  4114.      if ((fragP->fr_opcode[1] & 0x38) != 0)
  4115.          {
  4116.           /* use the normal reloc32, sigh... */
  4117.           fix_new (fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC, 0);
  4118.           fragP->fr_fix += 4;
  4119.           break;
  4120.         }
  4121.   
  4122.           /* so this is really a pc-relative address
  4123.            * What we have to do now is a VERY UGLY AND BIG KLUDGE. Basically do the
  4124.            * following thing:
  4125.            *   turn
  4126.            *     addl #foo,d0      (foo is N_TEXT)
  4127.            *   into
  4128.            *     pea  foo(pc)
  4129.            *     addl (sp)+,d0
  4130.            */
  4131.           *buffer_address++ = fragP->fr_opcode[0]; /* save the original command */
  4132.       *buffer_address++ = fragP->fr_opcode[1];
  4133.           fragP->fr_opcode[0] = 0x48;     /* PEA */
  4134.           fragP->fr_opcode[1] = 0x7a;
  4135.           fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol, fragP->fr_offset+2, 1, NO_RELOC, 0);
  4136.       
  4137.           *buffer_address++ = 0x9f;    /* sp@+ */
  4138.       fragP->fr_fix += 4;    /* two byte fix, two byte code extension */
  4139.       break;
  4140.         }
  4141.       /* in that case we have to generate base-relative code
  4142.        * (note: if we're in N_UNDF, this could as well be pc-relative, but the linker
  4143.        *        will have to do the final patch in that case) */
  4144.   
  4145.       /* analogous (more or less;-)) to above, the following conversion is done
  4146.        *   turn
  4147.        *     addl #bar,d0        (bar is N_DATA)
  4148.        *   into
  4149.        *       addl #<bar>,d0    where <bar> is a baserel-reloc
  4150.        *     addl a4,d0
  4151.        */
  4152.    
  4153.       fix_new(fragP,(int)(fragP->fr_fix), 4,fragP->fr_symbol,fragP->fr_offset, 0, NO_RELOC, 1);
  4154.       *buffer_address++ = 0xd0;
  4155.       *buffer_address++ = 0x8c;
  4156.       break;
  4157.     }
  4158.  
  4159.   if (ext)
  4160.     {
  4161.       md_number_to_chars (buffer_address, (long) disp, (int) ext);
  4162.       fragP->fr_fix += ext;
  4163.     }
  4164. }
  4165.  
  4166. #ifndef BFD_ASSEMBLER
  4167.  
  4168. void
  4169. md_convert_frag (headers, sec, fragP)
  4170.      object_headers *headers;
  4171.      segT sec;
  4172.      fragS *fragP;
  4173. {
  4174.   md_convert_frag_1 (fragP);
  4175. }
  4176.  
  4177. #else
  4178.  
  4179. void
  4180. md_convert_frag (abfd, sec, fragP)
  4181.      bfd *abfd;
  4182.      segT sec;
  4183.      fragS *fragP;
  4184. {
  4185.   md_convert_frag_1 (fragP);
  4186. }
  4187. #endif
  4188.  
  4189. /* Force truly undefined symbols to their maximum size, and generally set up
  4190.    the frag list to be relaxed
  4191.    */
  4192. int
  4193. md_estimate_size_before_relax (fragP, segment)
  4194.      register fragS *fragP;
  4195.      segT segment;
  4196. {
  4197.   int old_fix;
  4198.   register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
  4199.  
  4200.   old_fix = fragP->fr_fix;
  4201.  
  4202.   /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  4203.   switch (fragP->fr_subtype)
  4204.     {
  4205.  
  4206.     case TAB (ABRANCH, SZ_UNDEF):
  4207.       {
  4208.     if ((fragP->fr_symbol != NULL)    /* Not absolute */
  4209.         && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4210.       {
  4211.         fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
  4212.         break;
  4213.       }
  4214.     else if ((fragP->fr_symbol == 0) || (cpu_of_arch (current_architecture) < m68020))
  4215.       {
  4216.         /* On 68000, or for absolute value, switch to abs long */
  4217.         /* FIXME, we should check abs val, pick short or long */
  4218.             if (fragP->fr_opcode[0] == 0x61)
  4219.           {
  4220.         if (flag_small_code)
  4221.           {
  4222.             /* leave the BSR, no need to change
  4223.              * it into a JSR (PC,..) */
  4224.             subseg_change(text_section, 0);
  4225.             fix_new(fragP, fragP->fr_fix, 2, 
  4226.                 fragP->fr_symbol, fragP->fr_offset, 1, NO_RELOC, 0);
  4227.             fragP->fr_fix+=2;
  4228.             fragP->fr_opcode[1]=0x00;
  4229.               }
  4230.             else if (flag_short_refs)
  4231.               {
  4232.             subseg_change(text_section, 0);
  4233.             fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,
  4234.                 fragP->fr_offset + 2, 0, NO_RELOC, 0);
  4235.             fragP->fr_fix+=2;
  4236.             fragP->fr_opcode[1]=0x00;
  4237.           }
  4238.         else
  4239.           {
  4240.             fragP->fr_opcode[0] = 0x4E;
  4241.             fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
  4242.             subseg_change (text_section, 0);
  4243.             fix_new (fragP, fragP->fr_fix, 4,
  4244.                  fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC, 0);
  4245.             fragP->fr_fix += 4;
  4246.           }
  4247.         frag_wane (fragP);
  4248.           }
  4249.         else if (fragP->fr_opcode[0] == 0x60)
  4250.           {
  4251.         if (flag_small_code)
  4252.             {
  4253.             subseg_change(text_section, 0);
  4254.             fix_new(fragP, fragP->fr_fix, 2, 
  4255.                 fragP->fr_symbol, fragP->fr_offset, 1, NO_RELOC, 0);
  4256.               fragP->fr_fix+=2;
  4257.           }
  4258.                 else if (flag_short_refs)
  4259.                   {
  4260.             fragP->fr_opcode[0]= 0x4E;
  4261.             fragP->fr_opcode[1]= 0xF8;    /* JMP    with ABSL WORD offset */
  4262.             subseg_change(text_section, 0);
  4263.             fix_new(fragP, fragP->fr_fix, 2, 
  4264.                 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC, 0);
  4265.             fragP->fr_fix+=2;
  4266.           }
  4267.         else
  4268.           {
  4269.             fragP->fr_opcode[0] = 0x4E;
  4270.             fragP->fr_opcode[1] = (char) 0xF9; /* JMP  with ABSL LONG offset */
  4271.             subseg_change (text_section, 0);
  4272.             fix_new (fragP, fragP->fr_fix, 4,
  4273.                  fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC, 0);
  4274.             fragP->fr_fix += 4;
  4275.           }
  4276.         frag_wane (fragP);
  4277.           }
  4278.         else
  4279.           {
  4280.         as_warn ("Long branch offset to extern symbol not supported.");
  4281.           }
  4282.       }
  4283.     else
  4284.       {            /* Symbol is still undefined.  Make it simple */
  4285.         fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
  4286.              fragP->fr_offset, 1, NO_RELOC, 0);
  4287.         fragP->fr_fix += 4;
  4288.         fragP->fr_opcode[1] = (char) 0xff;
  4289.         frag_wane (fragP);
  4290.         break;
  4291.       }
  4292.  
  4293.     break;
  4294.       }                /* case TAB(ABRANCH,SZ_UNDEF) */
  4295.  
  4296.     case TAB (FBRANCH, SZ_UNDEF):
  4297.       {
  4298.     if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flag_short_refs)
  4299.       {
  4300.         fragP->fr_subtype = TAB (FBRANCH, SHORT);
  4301.         fragP->fr_var += 2;
  4302.       }
  4303.     else
  4304.       {
  4305.         fix_new (fragP, (int) fragP->fr_fix, 4, fragP->fr_symbol,
  4306.              fragP->fr_offset, 1, NO_RELOC, 0);
  4307.         fragP->fr_fix += 4;
  4308.         fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
  4309.         frag_wane (fragP);
  4310.       }
  4311.     break;
  4312.       }                /* TAB(FBRANCH,SZ_UNDEF) */
  4313.  
  4314.     case TAB (PCREL, SZ_UNDEF):
  4315.       {
  4316.     if (S_GET_SEGMENT (fragP->fr_symbol) == segment
  4317.         || flag_short_refs
  4318.         || cpu_of_arch (current_architecture) < m68020)
  4319.       {
  4320.         fragP->fr_subtype = TAB (PCREL, SHORT);
  4321.         fragP->fr_var += 2;
  4322.       }
  4323.     else
  4324.       {
  4325.         fragP->fr_subtype = TAB (PCREL, LONG);
  4326.         fragP->fr_var += 4;
  4327.       }
  4328.     break;
  4329.       }                /* TAB(PCREL,SZ_UNDEF) */
  4330.  
  4331.     case TAB (BCC68000, SZ_UNDEF):
  4332.       {
  4333.     if ((fragP->fr_symbol != NULL)
  4334.         && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4335.       {
  4336.         fragP->fr_subtype = TAB (BCC68000, BYTE);
  4337.         break;
  4338.       }
  4339.     /* only Bcc 68000 instructions can come here */
  4340.     /* change bcc into b!cc/jmp absl long */
  4341.     fragP->fr_opcode[0] ^= 0x01;    /* invert bcc */
  4342.     if (flag_short_refs)
  4343.       {
  4344.         fragP->fr_opcode[1] = 0x04;    /* branch offset = 6 */
  4345.         /* JF: these were fr_opcode[2,3] */
  4346.         buffer_address[0] = 0x4e;    /* put in jmp long (0x4ef9) */
  4347.         buffer_address[1] = (char) 0xf8;
  4348.         fragP->fr_fix += 2;    /* account for jmp instruction */
  4349.         fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4350.              fragP->fr_offset, 0, NO_RELOC, 0);
  4351.         fragP->fr_fix += 2;
  4352.       }
  4353.     else
  4354.       {
  4355.         fragP->fr_opcode[1] = 0x06;    /* branch offset = 6 */
  4356.         /* JF: these were fr_opcode[2,3] */
  4357.         buffer_address[0] = 0x4e;    /* put in jmp long (0x4ef9) */
  4358.         buffer_address[1] = (char) 0xf9;
  4359.         fragP->fr_fix += 2;    /* account for jmp instruction */
  4360.         fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4361.              fragP->fr_offset, 0, NO_RELOC, 0);
  4362.         fragP->fr_fix += 4;
  4363.       }
  4364.     frag_wane (fragP);
  4365.     break;
  4366.       }                /* case TAB(BCC68000,SZ_UNDEF) */
  4367.  
  4368.     case TAB (DBCC, SZ_UNDEF):
  4369.       {
  4370.     if (fragP->fr_symbol != NULL && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4371.       {
  4372.         fragP->fr_subtype = TAB (DBCC, SHORT);
  4373.         fragP->fr_var += 2;
  4374.         break;
  4375.       }
  4376.     /* only DBcc 68000 instructions can come here */
  4377.     /* change dbcc into dbcc/jmp absl long */
  4378.     /* JF: these used to be fr_opcode[2-4], which is wrong. */
  4379.     buffer_address[0] = 0x00;    /* branch offset = 4 */
  4380.     buffer_address[1] = 0x04;
  4381.     buffer_address[2] = 0x60;    /* put in bra pc + ... */
  4382.  
  4383.     if (flag_short_refs)
  4384.       {
  4385.         /* JF: these were fr_opcode[5-7] */
  4386.         buffer_address[3] = 0x04;    /* plus 4 */
  4387.         buffer_address[4] = 0x4e;    /* Put in Jump Word */
  4388.         buffer_address[5] = (char) 0xf8;
  4389.         fragP->fr_fix += 6;    /* account for bra/jmp instruction */
  4390.         fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4391.              fragP->fr_offset, 0, NO_RELOC, 0);
  4392.         fragP->fr_fix += 2;
  4393.       }
  4394.     else
  4395.       {
  4396.         /* JF: these were fr_opcode[5-7] */
  4397.         buffer_address[3] = 0x06;    /* Plus 6 */
  4398.         buffer_address[4] = 0x4e;    /* put in jmp long (0x4ef9) */
  4399.         buffer_address[5] = (char) 0xf9;
  4400.         fragP->fr_fix += 6;    /* account for bra/jmp instruction */
  4401.         fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4402.              fragP->fr_offset, 0, NO_RELOC, 0);
  4403.         fragP->fr_fix += 4;
  4404.       }
  4405.  
  4406.     frag_wane (fragP);
  4407.     break;
  4408.       }                /* case TAB(DBCC,SZ_UNDEF) */
  4409.  
  4410.     case TAB (PCLEA, SZ_UNDEF):
  4411.       {
  4412.     if ((S_GET_SEGMENT (fragP->fr_symbol)) == segment
  4413.         || flag_short_refs
  4414.         || cpu_of_arch (current_architecture) < m68020)
  4415.       {
  4416.         fragP->fr_subtype = TAB (PCLEA, SHORT);
  4417.         fragP->fr_var += 2;
  4418.       }
  4419.     else
  4420.       {
  4421.         fragP->fr_subtype = TAB (PCLEA, LONG);
  4422.         fragP->fr_var += 6;
  4423.       }
  4424.     break;
  4425.       }                /* TAB(PCLEA,SZ_UNDEF) */
  4426.  
  4427.     case TAB (PCINDEX, SZ_UNDEF):
  4428.       if (S_GET_SEGMENT (fragP->fr_symbol) == segment
  4429.       || cpu_of_arch (current_architecture) < m68020)
  4430.     {
  4431.       fragP->fr_subtype = TAB (PCINDEX, BYTE);
  4432.     }
  4433.       else
  4434.     {
  4435.       fragP->fr_subtype = TAB (PCINDEX, LONG);
  4436.       fragP->fr_var += 4;
  4437.     }
  4438.       break;
  4439.  
  4440.     case TAB(ABSREL,SZ_UNDEF):
  4441.     if ((S_GET_SEGMENT (fragP->fr_symbol)) == segment || flag_short_refs || flag_small_code) {
  4442.         fragP->fr_subtype = TAB(ABSREL, SHORT);
  4443.         fragP->fr_var += 2;
  4444.     } else {
  4445.         fragP->fr_subtype = TAB(ABSREL, LONG);
  4446.         fragP->fr_var += 6;
  4447.     }
  4448.       break;
  4449.  
  4450.     default:
  4451.       break;
  4452.     }
  4453.  
  4454.   /* now that SZ_UNDEF are taken care of, check others */
  4455.   switch (fragP->fr_subtype)
  4456.     {
  4457.     case TAB (BCC68000, BYTE):
  4458.     case TAB (ABRANCH, BYTE):
  4459.       /* We can't do a short jump to the next instruction, so in that
  4460.      case we force word mode.  At this point S_GET_VALUE should
  4461.      return the offset of the symbol within its frag.  If the
  4462.      symbol is at the start of a frag, and it is the next frag
  4463.      with any data in it (usually this is just the next frag, but
  4464.      assembler listings may introduce empty frags), we must use
  4465.      word mode.  */
  4466.       if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0)
  4467.     {
  4468.       fragS *l;
  4469.  
  4470.       for (l = fragP->fr_next;
  4471.            l != fragP->fr_symbol->sy_frag;
  4472.            l = l->fr_next)
  4473.         if (l->fr_fix + l->fr_var != 0)
  4474.           break;
  4475.       if (l == fragP->fr_symbol->sy_frag)
  4476.         {
  4477.           fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4478.           fragP->fr_var += 2;
  4479.         }
  4480.     }
  4481.       break;
  4482.     default:
  4483.       break;
  4484.     }
  4485.   return fragP->fr_var + fragP->fr_fix - old_fix;
  4486. }
  4487.  
  4488. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  4489. /* the bit-field entries in the relocation_info struct plays hell
  4490.    with the byte-order problems of cross-assembly.  So as a hack,
  4491.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  4492.    you there. -KWK */
  4493. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  4494.    are symbolnum, most sig. byte first.  Last byte is broken up with
  4495.    bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  4496.    nibble as nuthin. (on Sun 3 at least) */
  4497. /* Translate the internal relocation information into target-specific
  4498.    format. */
  4499. #ifdef comment
  4500. void
  4501. md_ri_to_chars (the_bytes, ri)
  4502.      char *the_bytes;
  4503.      struct reloc_info_generic *ri;
  4504. {
  4505.   /* this is easy */
  4506.   md_number_to_chars (the_bytes, ri->r_address, 4);
  4507.   /* now the fun stuff */
  4508.   the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
  4509.   the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
  4510.   the_bytes[6] = ri->r_symbolnum & 0x0ff;
  4511.   the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
  4512.           ((ri->r_extern << 4) & 0x10) | ((ri->r_baserel << 3) & 0x08));
  4513. }
  4514.  
  4515. #endif /* comment */
  4516.  
  4517. #ifndef BFD_ASSEMBLER
  4518. void
  4519. tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
  4520.      char *where;
  4521.      fixS *fixP;
  4522.      relax_addressT segment_address_in_file;
  4523. {
  4524.   /*
  4525.    * In: length of relocation (or of address) in chars: 1, 2 or 4.
  4526.    * Out: GNU LD relocation length code: 0, 1, or 2.
  4527.    */
  4528.  
  4529.   static CONST unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
  4530.   long r_symbolnum;
  4531.  
  4532.   know (fixP->fx_addsy != NULL);
  4533.  
  4534.   md_number_to_chars (where,
  4535.        fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
  4536.               4);
  4537.  
  4538.   r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
  4539.          ? S_GET_TYPE (fixP->fx_addsy)
  4540.          : fixP->fx_addsy->sy_number);
  4541.  
  4542.   where[4] = (r_symbolnum >> 16) & 0x0ff;
  4543.   where[5] = (r_symbolnum >> 8) & 0x0ff;
  4544.   where[6] = r_symbolnum & 0x0ff;
  4545.   where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
  4546.           (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10) | ((fixP->tc_fix_data << 3) & 0x08));
  4547. }
  4548. #endif
  4549.  
  4550. #endif /* OBJ_AOUT or OBJ_BOUT */
  4551.  
  4552. #ifndef WORKING_DOT_WORD
  4553. CONST int md_short_jump_size = 4;
  4554. CONST int md_long_jump_size = 6;
  4555.  
  4556. void
  4557. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  4558.      char *ptr;
  4559.      addressT from_addr, to_addr;
  4560.      fragS *frag;
  4561.      symbolS *to_symbol;
  4562. {
  4563.   valueT offset;
  4564.  
  4565.   offset = to_addr - (from_addr + 2);
  4566.  
  4567.   md_number_to_chars (ptr, (valueT) 0x6000, 2);
  4568.   md_number_to_chars (ptr + 2, (valueT) offset, 2);
  4569. }
  4570.  
  4571. void
  4572. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  4573.      char *ptr;
  4574.      addressT from_addr, to_addr;
  4575.      fragS *frag;
  4576.      symbolS *to_symbol;
  4577. {
  4578.   valueT offset;
  4579.  
  4580.   if (cpu_of_arch (current_architecture) < m68020)
  4581.     {
  4582.       offset = to_addr - S_GET_VALUE (to_symbol);
  4583.       md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
  4584.       md_number_to_chars (ptr + 2, (valueT) offset, 4);
  4585.       fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
  4586.            0, NO_RELOC, 0);
  4587.     }
  4588.   else
  4589.     {
  4590.       offset = to_addr - (from_addr + 2);
  4591.       md_number_to_chars (ptr, (valueT) 0x60ff, 2);
  4592.       md_number_to_chars (ptr + 2, (valueT) offset, 4);
  4593.     }
  4594. }
  4595.  
  4596. #endif
  4597.  
  4598. /* Different values of OK tell what its OK to return.  Things that
  4599.    aren't OK are an error (what a shock, no?)
  4600.  
  4601.    0:  Everything is OK
  4602.    10:  Absolute 1:8    only
  4603.    20:  Absolute 0:7    only
  4604.    30:  absolute 0:15    only
  4605.    40:  Absolute 0:31    only
  4606.    50:  absolute 0:127    only
  4607.    55:  absolute -64:63    only
  4608.    60:  absolute -128:127    only
  4609.    70:  absolute 0:4095    only
  4610.    80:  No bignums
  4611.  
  4612.    */
  4613.  
  4614. static int
  4615. get_num (exp, ok)
  4616.      struct m68k_exp *exp;
  4617.      int ok;
  4618. {
  4619.   if (exp->exp.X_op == O_absent)
  4620.     {
  4621.       /* Do the same thing the VAX asm does */
  4622.       op (exp) = O_constant;
  4623.       adds (exp) = 0;
  4624.       subs (exp) = 0;
  4625.       offs (exp) = 0;
  4626.       if (ok == 10)
  4627.     {
  4628.       as_warn ("expression out of range: defaulting to 1");
  4629.       offs (exp) = 1;
  4630.     }
  4631.     }
  4632.   else if (exp->exp.X_op == O_constant)
  4633.     {
  4634.       switch (ok)
  4635.     {
  4636.     case 10:
  4637.       if (offs (exp) < 1 || offs (exp) > 8)
  4638.         {
  4639.           as_warn ("expression out of range: defaulting to 1");
  4640.           offs (exp) = 1;
  4641.         }
  4642.       break;
  4643.     case 20:
  4644.       if (offs (exp) < 0 || offs (exp) > 7)
  4645.         goto outrange;
  4646.       break;
  4647.     case 30:
  4648.       if (offs (exp) < 0 || offs (exp) > 15)
  4649.         goto outrange;
  4650.       break;
  4651.     case 40:
  4652.       if (offs (exp) < 0 || offs (exp) > 32)
  4653.         goto outrange;
  4654.       break;
  4655.     case 50:
  4656.       if (offs (exp) < 0 || offs (exp) > 127)
  4657.         goto outrange;
  4658.       break;
  4659.     case 55:
  4660.       if (offs (exp) < -64 || offs (exp) > 63)
  4661.         goto outrange;
  4662.       break;
  4663.     case 60:
  4664.       if (offs (exp) < -128 || offs (exp) > 127)
  4665.         goto outrange;
  4666.       break;
  4667.     case 70:
  4668.       if (offs (exp) < 0 || offs (exp) > 4095)
  4669.         {
  4670.         outrange:
  4671.           as_warn ("expression out of range: defaulting to 0");
  4672.           offs (exp) = 0;
  4673.         }
  4674.       break;
  4675.     default:
  4676.       break;
  4677.     }
  4678.     }
  4679.   else if (exp->exp.X_op == O_big)
  4680.     {
  4681.       if (offs (exp) <= 0    /* flonum */
  4682.       && (ok == 80        /* no bignums */
  4683.           || (ok > 10    /* small-int ranges including 0 ok */
  4684.           /* If we have a flonum zero, a zero integer should
  4685.              do as well (e.g., in moveq).  */
  4686.           && generic_floating_point_number.exponent == 0
  4687.           && generic_floating_point_number.low[0] == 0)))
  4688.     {
  4689.       /* HACK! Turn it into a long */
  4690.       LITTLENUM_TYPE words[6];
  4691.  
  4692.       gen_to_words (words, 2, 8L);    /* These numbers are magic! */
  4693.       op (exp) = O_constant;
  4694.       adds (exp) = 0;
  4695.       subs (exp) = 0;
  4696.       offs (exp) = words[1] | (words[0] << 16);
  4697.     }
  4698.       else if (ok != 0)
  4699.     {
  4700.       op (exp) = O_constant;
  4701.       adds (exp) = 0;
  4702.       subs (exp) = 0;
  4703.       offs (exp) = (ok == 10) ? 1 : 0;
  4704.       as_warn ("Can't deal with expression; defaulting to %ld",
  4705.            offs (exp));
  4706.     }
  4707.     }
  4708.   else
  4709.     {
  4710.       if (ok >= 10 && ok <= 70)
  4711.     {
  4712.       op (exp) = O_constant;
  4713.       adds (exp) = 0;
  4714.       subs (exp) = 0;
  4715.       offs (exp) = (ok == 10) ? 1 : 0;
  4716.       as_warn ("Can't deal with expression; defaulting to %ld",
  4717.            offs (exp));
  4718.     }
  4719.     }
  4720.  
  4721.   if (exp->size != SIZE_UNSPEC)
  4722.     {
  4723.       switch (exp->size)
  4724.     {
  4725.     case SIZE_UNSPEC:
  4726.     case SIZE_LONG:
  4727.       break;
  4728.     case SIZE_BYTE:
  4729.       if (!isbyte (offs (exp)))
  4730.         as_warn ("expression doesn't fit in BYTE");
  4731.       break;
  4732.     case SIZE_WORD:
  4733.       if (!isword (offs (exp)))
  4734.         as_warn ("expression doesn't fit in WORD");
  4735.       break;
  4736.     }
  4737.     }
  4738.  
  4739.   return offs (exp);
  4740. }
  4741.  
  4742. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  4743. void demand_empty_rest_of_line ();    /* Hate those extra verbose names */
  4744.  
  4745. static void
  4746. s_data1 (ignore)
  4747.      int ignore;
  4748. {
  4749.   subseg_set (data_section, 1);
  4750.   demand_empty_rest_of_line ();
  4751. }
  4752.  
  4753. static void
  4754. s_data2 (ignore)
  4755.      int ignore;
  4756. {
  4757.   subseg_set (data_section, 2);
  4758.   demand_empty_rest_of_line ();
  4759. }
  4760.  
  4761. static void
  4762. s_bss (ignore)
  4763.      int ignore;
  4764. {
  4765.   /* We don't support putting frags in the BSS segment, we fake it
  4766.      by marking in_bss, then looking at s_skip for clues.  */
  4767.  
  4768.   subseg_set (bss_section, 0);
  4769.   demand_empty_rest_of_line ();
  4770. }
  4771.  
  4772. static void
  4773. s_even (ignore)
  4774.      int ignore;
  4775. {
  4776.   register int temp;
  4777.   register long temp_fill;
  4778.  
  4779.   temp = 1;            /* JF should be 2? */
  4780.   temp_fill = get_absolute_expression ();
  4781.   if (!need_pass_2)        /* Never make frag if expect extra pass. */
  4782.     frag_align (temp, (int) temp_fill);
  4783.   demand_empty_rest_of_line ();
  4784. }
  4785.  
  4786. static void
  4787. s_proc (ignore)
  4788.      int ignore;
  4789. {
  4790.   demand_empty_rest_of_line ();
  4791. }
  4792.  
  4793. /* Pseudo-ops handled for MRI compatibility.  */
  4794.  
  4795. /* Handle an MRI style chip specification.  */
  4796.  
  4797. static void
  4798. mri_chip ()
  4799. {
  4800.   char *s;
  4801.   char c;
  4802.   int i;
  4803.  
  4804.   s = input_line_pointer;
  4805.   c = get_symbol_end ();
  4806.   for (i = 0; i < n_archs; i++)
  4807.     if (strcasecmp (s, archs[i].name) == 0)
  4808.       break;
  4809.   if (i >= n_archs)
  4810.     {
  4811.       as_bad ("%s: unrecognized processor name", s);
  4812.       *input_line_pointer = c;
  4813.       ignore_rest_of_line ();
  4814.       return;
  4815.     }
  4816.   *input_line_pointer = c;
  4817.  
  4818.   if (*input_line_pointer == '/')
  4819.     current_architecture = 0;
  4820.   else
  4821.     current_architecture &= m68881 | m68851;
  4822.   current_architecture |= archs[i].arch;
  4823.  
  4824.   while (*input_line_pointer == '/')
  4825.     {
  4826.       ++input_line_pointer;
  4827.       s = input_line_pointer;
  4828.       c = get_symbol_end ();
  4829.       if (strcmp (s, "68881") == 0)
  4830.     current_architecture |= m68881;
  4831.       else if (strcmp (s, "68851") == 0)
  4832.     current_architecture |= m68851;
  4833.       *input_line_pointer = c;
  4834.     }
  4835. }
  4836.  
  4837. /* The MRI CHIP pseudo-op.  */
  4838.  
  4839. static void
  4840. s_chip (ignore)
  4841.      int ignore;
  4842. {
  4843.   char *stop = NULL;
  4844.   char stopc;
  4845.  
  4846.   if (flag_mri)
  4847.     stop = mri_comment_field (&stopc);
  4848.   mri_chip ();
  4849.   if (flag_mri)
  4850.     mri_comment_end (stop, stopc);
  4851.   demand_empty_rest_of_line ();
  4852. }
  4853.  
  4854. /* The MRI FOPT pseudo-op.  */
  4855.  
  4856. static void
  4857. s_fopt (ignore)
  4858.      int ignore;
  4859. {
  4860.   SKIP_WHITESPACE ();
  4861.  
  4862.   if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
  4863.     {
  4864.       int temp;
  4865.  
  4866.       input_line_pointer += 3;
  4867.       temp = get_absolute_expression ();
  4868.       if (temp < 0 || temp > 7)
  4869.     as_bad ("bad coprocessor id");
  4870.       else
  4871.     m68k_float_copnum = COP0 + temp;
  4872.     }
  4873.   else
  4874.     {
  4875.       as_bad ("unrecognized fopt option");
  4876.       ignore_rest_of_line ();
  4877.       return;
  4878.     }
  4879.  
  4880.   demand_empty_rest_of_line ();
  4881. }
  4882.  
  4883. /* The structure used to handle the MRI OPT pseudo-op.  */
  4884.  
  4885. struct opt_action
  4886. {
  4887.   /* The name of the option.  */
  4888.   const char *name;
  4889.  
  4890.   /* If this is not NULL, just call this function.  The first argument
  4891.      is the ARG field of this structure, the second argument is
  4892.      whether the option was negated.  */
  4893.   void (*pfn) PARAMS ((int arg, int on));
  4894.  
  4895.   /* If this is not NULL, and the PFN field is NULL, set the variable
  4896.      this points to.  Set it to the ARG field if the option was not
  4897.      negated, and the NOTARG field otherwise.  */
  4898.   int *pvar;
  4899.  
  4900.   /* The value to pass to PFN or to assign to *PVAR.  */
  4901.   int arg;
  4902.  
  4903.   /* The value to assign to *PVAR if the option is negated.  If PFN is
  4904.      NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
  4905.      the option may not be negated.  */
  4906.   int notarg;
  4907. };
  4908.  
  4909. /* The table used to handle the MRI OPT pseudo-op.  */
  4910.  
  4911. static void skip_to_comma PARAMS ((int, int));
  4912. static void opt_nest PARAMS ((int, int));
  4913. static void opt_chip PARAMS ((int, int));
  4914. static void opt_list PARAMS ((int, int));
  4915. static void opt_list_symbols PARAMS ((int, int));
  4916.  
  4917. static const struct opt_action opt_table[] =
  4918. {
  4919.   { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
  4920.  
  4921.   /* We do relaxing, so there is little use for these options.  */
  4922.   { "b", 0, 0, 0, 0 },
  4923.   { "brs", 0, 0, 0, 0 },
  4924.   { "brb", 0, 0, 0, 0 },
  4925.   { "brl", 0, 0, 0, 0 },
  4926.   { "brw", 0, 0, 0, 0 },
  4927.  
  4928.   { "c", 0, 0, 0, 0 },
  4929.   { "cex", 0, 0, 0, 0 },
  4930.   { "case", 0, &symbols_case_sensitive, 1, 0 },
  4931.   { "cl", 0, 0, 0, 0 },
  4932.   { "cre", 0, 0, 0, 0 },
  4933.   { "d", 0, &flag_keep_locals, 1, 0 },
  4934.   { "e", 0, 0, 0, 0 },
  4935.   { "f", 0, &flag_short_refs, 1, 0 },
  4936.   { "frs", 0, &flag_short_refs, 1, 0 },
  4937.   { "frl", 0, &flag_short_refs, 0, 1 },
  4938.   { "g", 0, 0, 0, 0 },
  4939.   { "i", 0, 0, 0, 0 },
  4940.   { "m", 0, 0, 0, 0 },
  4941.   { "mex", 0, 0, 0, 0 },
  4942.   { "mc", 0, 0, 0, 0 },
  4943.   { "md", 0, 0, 0, 0 },
  4944.   { "nest", opt_nest, 0, 0, 0 },
  4945.   { "next", skip_to_comma, 0, 0, 0 },
  4946.   { "o", 0, 0, 0, 0 },
  4947.   { "old", 0, 0, 0, 0 },
  4948.   { "op", skip_to_comma, 0, 0, 0 },
  4949.   { "pco", 0, 0, 0, 0 },
  4950.   { "p", opt_chip, 0, 0, 0 },
  4951.   { "pcr", 0, 0, 0, 0 },
  4952.   { "pcs", 0, 0, 0, 0 },
  4953.   { "r", 0, 0, 0, 0 },
  4954.   { "quick", 0, &m68k_quick, 1, 0 },
  4955.   { "rel32", 0, &m68k_rel32, 1, 0 },
  4956.   { "s", opt_list, 0, 0, 0 },
  4957.   { "t", opt_list_symbols, 0, 0, 0 },
  4958.   { "w", 0, &flag_no_warnings, 0, 1 },
  4959.   { "x", 0, 0, 0, 0 }
  4960. };
  4961.  
  4962. #define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
  4963.  
  4964. /* The MRI OPT pseudo-op.  */
  4965.  
  4966. static void
  4967. s_opt (ignore)
  4968.      int ignore;
  4969. {
  4970.   do
  4971.     {
  4972.       int t;
  4973.       char *s;
  4974.       char c;
  4975.       int i;
  4976.       const struct opt_action *o;
  4977.  
  4978.       SKIP_WHITESPACE ();
  4979.  
  4980.       t = 1;
  4981.       if (*input_line_pointer == '-')
  4982.     {
  4983.       ++input_line_pointer;
  4984.       t = 0;
  4985.     }
  4986.       else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
  4987.     {
  4988.       input_line_pointer += 2;
  4989.       t = 0;
  4990.     }
  4991.  
  4992.       s = input_line_pointer;
  4993.       c = get_symbol_end ();
  4994.  
  4995.       for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
  4996.     {
  4997.       if (strcasecmp (s, o->name) == 0)
  4998.         {
  4999.           if (o->pfn)
  5000.         {
  5001.           /* Restore input_line_pointer now in case the option
  5002.              takes arguments.  */
  5003.           *input_line_pointer = c;
  5004.           (*o->pfn) (o->arg, t);
  5005.         }
  5006.           else if (o->pvar != NULL)
  5007.         {
  5008.           if (! t && o->arg == o->notarg)
  5009.             as_bad ("option `%s' may not be negated", s);
  5010.           *input_line_pointer = c;
  5011.           *o->pvar = t ? o->arg : o->notarg;
  5012.         }
  5013.           else
  5014.         *input_line_pointer = c;
  5015.           break;
  5016.         }
  5017.     }
  5018.       if (i >= OPTCOUNT)
  5019.     {
  5020.       as_bad ("option `%s' not recognized", s);
  5021.       *input_line_pointer = c;
  5022.     }
  5023.     }
  5024.   while (*input_line_pointer++ == ',');
  5025.  
  5026.   /* Move back to terminating character.  */
  5027.   --input_line_pointer;
  5028.   demand_empty_rest_of_line ();
  5029. }
  5030.  
  5031. /* Skip ahead to a comma.  This is used for OPT options which we do
  5032.    not suppor tand which take arguments.  */
  5033.  
  5034. static void
  5035. skip_to_comma (arg, on)
  5036.      int arg;
  5037.      int on;
  5038. {
  5039.   while (*input_line_pointer != ','
  5040.      && ! is_end_of_line[(unsigned char) *input_line_pointer])
  5041.     ++input_line_pointer;
  5042. }
  5043.  
  5044. /* Handle the OPT NEST=depth option.  */
  5045.  
  5046. static void
  5047. opt_nest (arg, on)
  5048.      int arg;
  5049.      int on;
  5050. {
  5051.   if (*input_line_pointer != '=')
  5052.     {
  5053.       as_bad ("bad format of OPT NEST=depth");
  5054.       return;
  5055.     }
  5056.  
  5057.   ++input_line_pointer;
  5058.   max_macro_nest = get_absolute_expression ();
  5059. }
  5060.  
  5061. /* Handle the OPT P=chip option.  */
  5062.  
  5063. static void
  5064. opt_chip (arg, on)
  5065.      int arg;
  5066.      int on;
  5067. {
  5068.   if (*input_line_pointer != '=')
  5069.     {
  5070.       /* This is just OPT P, which we do not support.  */
  5071.       return;
  5072.     }
  5073.  
  5074.   ++input_line_pointer;
  5075.   mri_chip ();
  5076. }
  5077.  
  5078. /* Handle the OPT S option.  */
  5079.  
  5080. static void
  5081. opt_list (arg, on)
  5082.      int arg;
  5083.      int on;
  5084. {
  5085.   listing_list (on);
  5086. }
  5087.  
  5088. /* Handle the OPT T option.  */
  5089.  
  5090. static void
  5091. opt_list_symbols (arg, on)
  5092.      int arg;
  5093.      int on;
  5094. {
  5095.   if (on)
  5096.     listing |= LISTING_SYMBOLS;
  5097.   else
  5098.     listing &=~ LISTING_SYMBOLS;
  5099. }
  5100.  
  5101. /* Handle the MRI REG pseudo-op.  */
  5102.  
  5103. static void
  5104. s_reg (ignore)
  5105.      int ignore;
  5106. {
  5107.   char *s;
  5108.   int c;
  5109.   struct m68k_op rop;
  5110.   unsigned long mask;
  5111.   char *stop = NULL;
  5112.   char stopc;
  5113.  
  5114.   if (line_label == NULL)
  5115.     {
  5116.       as_bad ("missing label");
  5117.       ignore_rest_of_line ();
  5118.       return;
  5119.     }
  5120.  
  5121.   if (flag_mri)
  5122.     stop = mri_comment_field (&stopc);
  5123.  
  5124.   SKIP_WHITESPACE ();
  5125.  
  5126.   s = input_line_pointer;
  5127.   while (isalnum ((unsigned char) *input_line_pointer)
  5128. #ifdef REGISTER_PREFIX
  5129.      || *input_line_pointer == REGISTER_PREFIX
  5130. #endif
  5131.      || *input_line_pointer == '/'
  5132.      || *input_line_pointer == '-')
  5133.     ++input_line_pointer;
  5134.   c = *input_line_pointer;
  5135.   *input_line_pointer = '\0';
  5136.  
  5137.   if (m68k_ip_op (s, &rop) != 0)
  5138.     {
  5139.       if (rop.error == NULL)
  5140.     as_bad ("bad register list");
  5141.       else
  5142.     as_bad ("bad register list: %s", rop.error);
  5143.       *input_line_pointer = c;
  5144.       ignore_rest_of_line ();
  5145.       return;
  5146.     }
  5147.  
  5148.   *input_line_pointer = c;
  5149.  
  5150.   if (rop.mode == REGLST)
  5151.     mask = rop.mask;
  5152.   else if (rop.mode == DREG)
  5153.     mask = 1 << (rop.reg - DATA0);
  5154.   else if (rop.mode == AREG)
  5155.     mask = 1 << (rop.reg - ADDR0 + 8);
  5156.   else if (rop.mode == FPREG)
  5157.     mask = 1 << (rop.reg - FP0 + 16);
  5158.   else if (rop.mode == CONTROL
  5159.        && rop.reg == FPI)
  5160.     mask = 1 << 24;
  5161.   else if (rop.mode == CONTROL
  5162.        && rop.reg == FPS)
  5163.     mask = 1 << 25;
  5164.   else if (rop.mode == CONTROL
  5165.        && rop.reg == FPC)
  5166.     mask = 1 << 26;
  5167.   else
  5168.     {
  5169.       as_bad ("bad register list");
  5170.       ignore_rest_of_line ();
  5171.       return;
  5172.     }
  5173.  
  5174.   S_SET_SEGMENT (line_label, absolute_section);
  5175.   S_SET_VALUE (line_label, mask);
  5176.   line_label->sy_frag = &zero_address_frag;
  5177.  
  5178.   if (flag_mri)
  5179.     mri_comment_end (stop, stopc);
  5180.  
  5181.   demand_empty_rest_of_line ();
  5182. }
  5183.  
  5184. /* This structure is used for the MRI SAVE and RESTORE pseudo-ops.  */
  5185.  
  5186. struct save_opts
  5187. {
  5188.   struct save_opts *next;
  5189.   int abspcadd;
  5190.   int symbols_case_sensitive;
  5191.   int keep_locals;
  5192.   int short_refs;
  5193.   int architecture;
  5194.   int quick;
  5195.   int rel32;
  5196.   int listing;
  5197.   int no_warnings;
  5198.   /* FIXME: We don't save OPT S.  */
  5199. };
  5200.  
  5201. /* This variable holds the stack of saved options.  */
  5202.  
  5203. static struct save_opts *save_stack;
  5204.  
  5205. /* The MRI SAVE pseudo-op.  */
  5206.  
  5207. static void
  5208. s_save (ignore)
  5209.      int ignore;
  5210. {
  5211.   struct save_opts *s;
  5212.  
  5213.   s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
  5214.   s->abspcadd = m68k_abspcadd;
  5215.   s->symbols_case_sensitive = symbols_case_sensitive;
  5216.   s->keep_locals = flag_keep_locals;
  5217.   s->short_refs = flag_short_refs;
  5218.   s->architecture = current_architecture;
  5219.   s->quick = m68k_quick;
  5220.   s->rel32 = m68k_rel32;
  5221.   s->listing = listing;
  5222.   s->no_warnings = flag_no_warnings;
  5223.  
  5224.   s->next = save_stack;
  5225.   save_stack = s;
  5226.  
  5227.   demand_empty_rest_of_line ();
  5228. }
  5229.  
  5230. /* The MRI RESTORE pseudo-op.  */
  5231.  
  5232. static void
  5233. s_restore (ignore)
  5234.      int ignore;
  5235. {
  5236.   struct save_opts *s;
  5237.  
  5238.   if (save_stack == NULL)
  5239.     {
  5240.       as_bad ("restore without save");
  5241.       ignore_rest_of_line ();
  5242.       return;
  5243.     }
  5244.  
  5245.   s = save_stack;
  5246.   save_stack = s->next;
  5247.  
  5248.   m68k_abspcadd = s->abspcadd;
  5249.   symbols_case_sensitive = s->symbols_case_sensitive;
  5250.   flag_keep_locals = s->keep_locals;
  5251.   flag_short_refs = s->short_refs;
  5252.   current_architecture = s->architecture;
  5253.   m68k_quick = s->quick;
  5254.   m68k_rel32 = s->rel32;
  5255.   listing = s->listing;
  5256.   flag_no_warnings = s->no_warnings;
  5257.  
  5258.   free (s);
  5259.  
  5260.   demand_empty_rest_of_line ();
  5261. }
  5262.  
  5263. /* Types of MRI structured control directives.  */
  5264.  
  5265. enum mri_control_type
  5266. {
  5267.   mri_for,
  5268.   mri_if,
  5269.   mri_repeat,
  5270.   mri_while
  5271. };
  5272.  
  5273. /* This structure is used to stack the MRI structured control
  5274.    directives.  */
  5275.  
  5276. struct mri_control_info
  5277. {
  5278.   /* The directive within which this one is enclosed.  */
  5279.   struct mri_control_info *outer;
  5280.  
  5281.   /* The type of directive.  */
  5282.   enum mri_control_type type;
  5283.  
  5284.   /* Whether an ELSE has been in an IF.  */
  5285.   int else_seen;
  5286.  
  5287.   /* The add or sub statement at the end of a FOR.  */
  5288.   char *incr;
  5289.  
  5290.   /* The label of the top of a FOR or REPEAT loop.  */
  5291.   char *top;
  5292.  
  5293.   /* The label to jump to for the next iteration, or the else
  5294.      expression of a conditional.  */
  5295.   char *next;
  5296.  
  5297.   /* The label to jump to to break out of the loop, or the label past
  5298.      the end of a conditional.  */
  5299.   char *bottom;
  5300. };
  5301.  
  5302. /* The stack of MRI structured control directives.  */
  5303.  
  5304. static struct mri_control_info *mri_control_stack;
  5305.  
  5306. /* The current MRI structured control directive index number, used to
  5307.    generate label names.  */
  5308.  
  5309. static int mri_control_index;
  5310.  
  5311. /* Some function prototypes.  */
  5312.  
  5313. static char *mri_control_label PARAMS ((void));
  5314. static struct mri_control_info *push_mri_control
  5315.   PARAMS ((enum mri_control_type));
  5316. static void pop_mri_control PARAMS ((void));
  5317. static int parse_mri_condition PARAMS ((int *));
  5318. static int parse_mri_control_operand
  5319.   PARAMS ((int *, char **, char **, char **, char **));
  5320. static int swap_mri_condition PARAMS ((int));
  5321. static int reverse_mri_condition PARAMS ((int));
  5322. static void build_mri_control_operand
  5323.   PARAMS ((int, int, char *, char *, char *, char *, const char *,
  5324.        const char *, int));
  5325. static void parse_mri_control_expression
  5326.   PARAMS ((char *, int, const char *, const char *, int));
  5327.  
  5328. /* Generate a new MRI label structured control directive label name.  */
  5329.  
  5330. static char *
  5331. mri_control_label ()
  5332. {
  5333.   char *n;
  5334.  
  5335.   n = (char *) xmalloc (20);
  5336.   sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
  5337.   ++mri_control_index;
  5338.   return n;
  5339. }
  5340.  
  5341. /* Create a new MRI structured control directive.  */
  5342.  
  5343. static struct mri_control_info *
  5344. push_mri_control (type)
  5345.      enum mri_control_type type;
  5346. {
  5347.   struct mri_control_info *n;
  5348.  
  5349.   n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
  5350.  
  5351.   n->type = type;
  5352.   n->else_seen = 0;
  5353.   if (type == mri_if || type == mri_while)
  5354.     n->top = NULL;
  5355.   else
  5356.     n->top = mri_control_label ();
  5357.   n->next = mri_control_label ();
  5358.   n->bottom = mri_control_label ();
  5359.  
  5360.   n->outer = mri_control_stack;
  5361.   mri_control_stack = n;
  5362.  
  5363.   return n;
  5364. }
  5365.  
  5366. /* Pop off the stack of MRI structured control directives.  */
  5367.  
  5368. static void
  5369. pop_mri_control ()
  5370. {
  5371.   struct mri_control_info *n;
  5372.  
  5373.   n = mri_control_stack;
  5374.   mri_control_stack = n->outer;
  5375.   if (n->top != NULL)
  5376.     free (n->top);
  5377.   free (n->next);
  5378.   free (n->bottom);
  5379.   free (n);
  5380. }
  5381.  
  5382. /* Recognize a condition code in an MRI structured control expression.  */
  5383.  
  5384. static int
  5385. parse_mri_condition (pcc)
  5386.      int *pcc;
  5387. {
  5388.   char c1, c2;
  5389.  
  5390.   know (*input_line_pointer == '<');
  5391.  
  5392.   ++input_line_pointer;
  5393.   c1 = *input_line_pointer++;
  5394.   c2 = *input_line_pointer++;
  5395.  
  5396.   if (*input_line_pointer != '>')
  5397.     {
  5398.       as_bad ("syntax error in structured control directive");
  5399.       return 0;
  5400.     }
  5401.  
  5402.   ++input_line_pointer;
  5403.   SKIP_WHITESPACE ();
  5404.  
  5405.   if (isupper (c1))
  5406.     c1 = tolower (c1);
  5407.   if (isupper (c2))
  5408.     c2 = tolower (c2);
  5409.  
  5410.   *pcc = (c1 << 8) | c2;
  5411.  
  5412.   return 1;
  5413. }
  5414.  
  5415. /* Parse a single operand in an MRI structured control expression.  */
  5416.  
  5417. static int
  5418. parse_mri_control_operand (pcc, leftstart, leftstop, rightstart, rightstop)
  5419.      int *pcc;
  5420.      char **leftstart;
  5421.      char **leftstop;
  5422.      char **rightstart;
  5423.      char **rightstop;
  5424. {
  5425.   char *s;
  5426.  
  5427.   SKIP_WHITESPACE ();
  5428.  
  5429.   *pcc = -1;
  5430.   *leftstart = NULL;
  5431.   *leftstop = NULL;
  5432.   *rightstart = NULL;
  5433.   *rightstop = NULL;
  5434.  
  5435.   if (*input_line_pointer == '<')
  5436.     {
  5437.       /* It's just a condition code.  */
  5438.       return parse_mri_condition (pcc);
  5439.     }
  5440.  
  5441.   /* Look ahead for the condition code.  */
  5442.   for (s = input_line_pointer; *s != '\0'; ++s)
  5443.     {
  5444.       if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
  5445.     break;
  5446.     }
  5447.   if (*s == '\0')
  5448.     {
  5449.       as_bad ("missing condition code in structured control directive");
  5450.       return 0;
  5451.     }
  5452.  
  5453.   *leftstart = input_line_pointer;
  5454.   *leftstop = s;
  5455.   if (*leftstop > *leftstart
  5456.       && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
  5457.     --*leftstop;
  5458.  
  5459.   input_line_pointer = s;
  5460.   if (! parse_mri_condition (pcc))
  5461.     return 0;
  5462.  
  5463.   /* Look ahead for AND or OR or end of line.  */
  5464.   for (s = input_line_pointer; *s != '\0'; ++s)
  5465.     {
  5466.       if ((strncasecmp (s, "AND", 3) == 0
  5467.        && (s[3] == '.' || ! is_part_of_name (s[3])))
  5468.       || (strncasecmp (s, "OR", 2) == 0
  5469.           && (s[2] == '.' || ! is_part_of_name (s[2]))))
  5470.     break;
  5471.     }
  5472.  
  5473.   *rightstart = input_line_pointer;
  5474.   *rightstop = s;
  5475.   if (*rightstop > *rightstart
  5476.       && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
  5477.     --*rightstop;
  5478.  
  5479.   input_line_pointer = s;
  5480.  
  5481.   return 1;
  5482. }
  5483.  
  5484. #define MCC(b1, b2) (((b1) << 8) | (b2))
  5485.  
  5486. /* Swap the sense of a condition.  This changes the condition so that
  5487.    it generates the same result when the operands are swapped.  */
  5488.  
  5489. static int
  5490. swap_mri_condition (cc)
  5491.      int cc;
  5492. {
  5493.   switch (cc)
  5494.     {
  5495.     case MCC ('h', 'i'): return MCC ('c', 's');
  5496.     case MCC ('l', 's'): return MCC ('c', 'c');
  5497.     case MCC ('c', 'c'): return MCC ('l', 's');
  5498.     case MCC ('c', 's'): return MCC ('h', 'i');
  5499.     case MCC ('p', 'l'): return MCC ('m', 'i');
  5500.     case MCC ('m', 'i'): return MCC ('p', 'l');
  5501.     case MCC ('g', 'e'): return MCC ('l', 'e');
  5502.     case MCC ('l', 't'): return MCC ('g', 't');
  5503.     case MCC ('g', 't'): return MCC ('l', 't');
  5504.     case MCC ('l', 'e'): return MCC ('g', 'e');
  5505.     }
  5506.   return cc;
  5507. }
  5508.  
  5509. /* Reverse the sense of a condition.  */
  5510.  
  5511. static int
  5512. reverse_mri_condition (cc)
  5513.      int cc;
  5514. {
  5515.   switch (cc)
  5516.     {
  5517.     case MCC ('h', 'i'): return MCC ('l', 's');
  5518.     case MCC ('l', 's'): return MCC ('h', 'i');
  5519.     case MCC ('c', 'c'): return MCC ('c', 's');
  5520.     case MCC ('c', 's'): return MCC ('c', 'c');
  5521.     case MCC ('n', 'e'): return MCC ('e', 'q');
  5522.     case MCC ('e', 'q'): return MCC ('n', 'e');
  5523.     case MCC ('v', 'c'): return MCC ('v', 's');
  5524.     case MCC ('v', 's'): return MCC ('v', 'c');
  5525.     case MCC ('p', 'l'): return MCC ('m', 'i');
  5526.     case MCC ('m', 'i'): return MCC ('p', 'l');
  5527.     case MCC ('g', 'e'): return MCC ('l', 't');
  5528.     case MCC ('l', 't'): return MCC ('g', 'e');
  5529.     case MCC ('g', 't'): return MCC ('l', 'e');
  5530.     case MCC ('l', 'e'): return MCC ('g', 't');
  5531.     }
  5532.   return cc;
  5533. }
  5534.  
  5535. /* Build an MRI structured control expression.  This generates test
  5536.    and branch instructions.  It goes to TRUELAB if the condition is
  5537.    true, and to FALSELAB if the condition is false.  Exactly one of
  5538.    TRUELAB and FALSELAB will be NULL, meaning to fall through.  QUAL
  5539.    is the size qualifier for the expression.  EXTENT is the size to
  5540.    use for the branch.  */
  5541.  
  5542. static void
  5543. build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5544.                rightstop, truelab, falselab, extent)
  5545.      int qual;
  5546.      int cc;
  5547.      char *leftstart;
  5548.      char *leftstop;
  5549.      char *rightstart;
  5550.      char *rightstop;
  5551.      const char *truelab;
  5552.      const char *falselab;
  5553.      int extent;
  5554. {
  5555.   char *buf;
  5556.   char *s;
  5557.  
  5558.   if (leftstart != NULL)
  5559.     {
  5560.       struct m68k_op leftop, rightop;
  5561.       char c;
  5562.  
  5563.       /* Swap the compare operands, if necessary, to produce a legal
  5564.      m68k compare instruction.  Comparing a register operand with
  5565.      a non-register operand requires the register to be on the
  5566.      right (cmp, cmpa).  Comparing an immediate value with
  5567.      anything requires the immediate value to be on the left
  5568.      (cmpi).  */
  5569.  
  5570.       c = *leftstop;
  5571.       *leftstop = '\0';
  5572.       (void) m68k_ip_op (leftstart, &leftop);
  5573.       *leftstop = c;
  5574.  
  5575.       c = *rightstop;
  5576.       *rightstop = '\0';
  5577.       (void) m68k_ip_op (rightstart, &rightop);
  5578.       *rightstop = c;
  5579.  
  5580.       if (rightop.mode == IMMED
  5581.       || ((leftop.mode == DREG || leftop.mode == AREG)
  5582.           && (rightop.mode != DREG && rightop.mode != AREG)))
  5583.     {
  5584.       char *temp;
  5585.  
  5586.       cc = swap_mri_condition (cc);
  5587.       temp = leftstart;
  5588.       leftstart = rightstart;
  5589.       rightstart = temp;
  5590.       temp = leftstop;
  5591.       leftstop = rightstop;
  5592.       rightstop = temp;
  5593.     }
  5594.     }
  5595.  
  5596.   if (truelab == NULL)
  5597.     {
  5598.       cc = reverse_mri_condition (cc);
  5599.       truelab = falselab;
  5600.     }
  5601.       
  5602.   if (leftstart != NULL)
  5603.     {
  5604.       buf = (char *) xmalloc (20
  5605.                   + (leftstop - leftstart)
  5606.                   + (rightstop - rightstart));
  5607.       s = buf;
  5608.       *s++ = 'c';
  5609.       *s++ = 'm';
  5610.       *s++ = 'p';
  5611.       if (qual != '\0')
  5612.     *s++ = qual;
  5613.       *s++ = ' ';
  5614.       memcpy (s, leftstart, leftstop - leftstart);
  5615.       s += leftstop - leftstart;
  5616.       *s++ = ',';
  5617.       memcpy (s, rightstart, rightstop - rightstart);
  5618.       s += rightstop - rightstart;
  5619.       *s = '\0';
  5620.       md_assemble (buf);
  5621.       free (buf);
  5622.     }
  5623.       
  5624.   buf = (char *) xmalloc (20 + strlen (truelab));
  5625.   s = buf;
  5626.   *s++ = 'b';
  5627.   *s++ = cc >> 8;
  5628.   *s++ = cc & 0xff;
  5629.   if (extent != '\0')
  5630.     *s++ = extent;
  5631.   *s++ = ' ';
  5632.   strcpy (s, truelab);
  5633.   md_assemble (buf);
  5634.   free (buf);
  5635. }
  5636.  
  5637. /* Parse an MRI structured control expression.  This generates test
  5638.    and branch instructions.  STOP is where the expression ends.  It
  5639.    goes to TRUELAB if the condition is true, and to FALSELAB if the
  5640.    condition is false.  Exactly one of TRUELAB and FALSELAB will be
  5641.    NULL, meaning to fall through.  QUAL is the size qualifier for the
  5642.    expression.  EXTENT is the size to use for the branch.  */
  5643.  
  5644. static void
  5645. parse_mri_control_expression (stop, qual, truelab, falselab, extent)
  5646.      char *stop;
  5647.      int qual;
  5648.      const char *truelab;
  5649.      const char *falselab;
  5650.      int extent;
  5651. {
  5652.   int c;
  5653.   int cc;
  5654.   char *leftstart;
  5655.   char *leftstop;
  5656.   char *rightstart;
  5657.   char *rightstop;
  5658.  
  5659.   c = *stop;
  5660.   *stop = '\0';
  5661.  
  5662.   if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
  5663.                    &rightstart, &rightstop))
  5664.     {
  5665.       *stop = c;
  5666.       return;
  5667.     }
  5668.  
  5669.   if (strncasecmp (input_line_pointer, "AND", 3) == 0)
  5670.     {
  5671.       const char *flab;
  5672.  
  5673.       if (falselab != NULL)
  5674.     flab = falselab;
  5675.       else
  5676.     flab = mri_control_label ();
  5677.  
  5678.       build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5679.                  rightstop, (const char *) NULL, flab, extent);
  5680.  
  5681.       input_line_pointer += 3;
  5682.       if (*input_line_pointer != '.'
  5683.       || input_line_pointer[1] == '\0')
  5684.     qual = '\0';
  5685.       else
  5686.     {
  5687.       qual = input_line_pointer[1];
  5688.       input_line_pointer += 2;
  5689.     }
  5690.  
  5691.       if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
  5692.                        &rightstart, &rightstop))
  5693.     {
  5694.       *stop = c;
  5695.       return;
  5696.     }
  5697.  
  5698.       build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5699.                  rightstop, truelab, falselab, extent);
  5700.  
  5701.       if (falselab == NULL)
  5702.     colon (flab);
  5703.     }
  5704.   else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
  5705.     {
  5706.       const char *tlab;
  5707.  
  5708.       if (truelab != NULL)
  5709.     tlab = truelab;
  5710.       else
  5711.     tlab = mri_control_label ();
  5712.  
  5713.       build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5714.                  rightstop, tlab, (const char *) NULL, extent);
  5715.  
  5716.       input_line_pointer += 2;
  5717.       if (*input_line_pointer != '.'
  5718.       || input_line_pointer[1] == '\0')
  5719.     qual = '\0';
  5720.       else
  5721.     {
  5722.       qual = input_line_pointer[1];
  5723.       input_line_pointer += 2;
  5724.     }
  5725.  
  5726.       if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
  5727.                        &rightstart, &rightstop))
  5728.     {
  5729.       *stop = c;
  5730.       return;
  5731.     }
  5732.  
  5733.       build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5734.                  rightstop, truelab, falselab, extent);
  5735.  
  5736.       if (truelab == NULL)
  5737.     colon (tlab);
  5738.     }
  5739.   else
  5740.     {
  5741.       build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5742.                  rightstop, truelab, falselab, extent);
  5743.     }
  5744.  
  5745.   *stop = c;
  5746.   if (input_line_pointer != stop)
  5747.     as_bad ("syntax error in structured control directive");
  5748. }
  5749.  
  5750. /* Handle the MRI IF pseudo-op.  This may be a structured control
  5751.    directive, or it may be a regular assembler conditional, depending
  5752.    on its operands.  */
  5753.  
  5754. static void
  5755. s_mri_if (qual)
  5756.      int qual;
  5757. {
  5758.   char *s;
  5759.   int c;
  5760.   struct mri_control_info *n;
  5761.  
  5762.   /* A structured control directive must end with THEN with an
  5763.      optional qualifier.  */
  5764.   s = input_line_pointer;
  5765.   while (! is_end_of_line[(unsigned char) *s]
  5766.      && (! flag_mri || *s != '*'))
  5767.     ++s;
  5768.   --s;
  5769.   while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
  5770.     --s;
  5771.  
  5772.   if (s - input_line_pointer > 1
  5773.       && s[-1] == '.')
  5774.     s -= 2;
  5775.  
  5776.   if (s - input_line_pointer < 3
  5777.       || strncasecmp (s - 3, "THEN", 4) != 0)
  5778.     {
  5779.       if (qual != '\0')
  5780.     {
  5781.       as_bad ("missing then");
  5782.       ignore_rest_of_line ();
  5783.       return;
  5784.     }
  5785.  
  5786.       /* It's a conditional.  */
  5787.       s_if (O_ne);
  5788.       return;
  5789.     }
  5790.  
  5791.   /* Since this might be a conditional if, this pseudo-op will be
  5792.      called even if we are supported to be ignoring input.  Double
  5793.      check now.  Clobber *input_line_pointer so that ignore_input
  5794.      thinks that this is not a special pseudo-op.  */
  5795.   c = *input_line_pointer;
  5796.   *input_line_pointer = 0;
  5797.   if (ignore_input ())
  5798.     {
  5799.       *input_line_pointer = c;
  5800.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5801.     ++input_line_pointer;
  5802.       demand_empty_rest_of_line ();
  5803.       return;
  5804.     }
  5805.   *input_line_pointer = c;
  5806.  
  5807.   n = push_mri_control (mri_if);
  5808.  
  5809.   parse_mri_control_expression (s - 3, qual, (const char *) NULL,
  5810.                 n->next, s[1] == '.' ? s[2] : '\0');
  5811.  
  5812.   if (s[1] == '.')
  5813.     input_line_pointer = s + 3;
  5814.   else
  5815.     input_line_pointer = s + 1;
  5816.  
  5817.   if (flag_mri)
  5818.     {
  5819.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5820.     ++input_line_pointer;
  5821.     }
  5822.  
  5823.   demand_empty_rest_of_line ();
  5824. }
  5825.  
  5826. /* Handle the MRI else pseudo-op.  If we are currently doing an MRI
  5827.    structured IF, associate the ELSE with the IF.  Otherwise, assume
  5828.    it is a conditional else.  */
  5829.  
  5830. static void
  5831. s_mri_else (qual)
  5832.      int qual;
  5833. {
  5834.   int c;
  5835.   char *buf;
  5836.   char q[2];
  5837.  
  5838.   if (qual == '\0'
  5839.       && (mri_control_stack == NULL
  5840.       || mri_control_stack->type != mri_if
  5841.       || mri_control_stack->else_seen))
  5842.     {
  5843.       s_else (0);
  5844.       return;
  5845.     }
  5846.  
  5847.   c = *input_line_pointer;
  5848.   *input_line_pointer = 0;
  5849.   if (ignore_input ())
  5850.     {
  5851.       *input_line_pointer = c;
  5852.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5853.     ++input_line_pointer;
  5854.       demand_empty_rest_of_line ();
  5855.       return;
  5856.     }
  5857.   *input_line_pointer = c;
  5858.  
  5859.   if (mri_control_stack == NULL
  5860.       || mri_control_stack->type != mri_if
  5861.       || mri_control_stack->else_seen)
  5862.     {
  5863.       as_bad ("else without matching if");
  5864.       ignore_rest_of_line ();
  5865.       return;
  5866.     }
  5867.  
  5868.   mri_control_stack->else_seen = 1;
  5869.  
  5870.   buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
  5871.   q[0] = qual;
  5872.   q[1] = '\0';
  5873.   sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
  5874.   md_assemble (buf);
  5875.   free (buf);
  5876.  
  5877.   colon (mri_control_stack->next);
  5878.  
  5879.   if (flag_mri)
  5880.     {
  5881.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5882.     ++input_line_pointer;
  5883.     }
  5884.  
  5885.   demand_empty_rest_of_line ();
  5886. }
  5887.  
  5888. /* Handle the MRI ENDI pseudo-op.  */
  5889.  
  5890. static void
  5891. s_mri_endi (ignore)
  5892.      int ignore;
  5893. {
  5894.   if (mri_control_stack == NULL
  5895.       || mri_control_stack->type != mri_if)
  5896.     {
  5897.       as_bad ("endi without matching if");
  5898.       ignore_rest_of_line ();
  5899.       return;
  5900.     }
  5901.  
  5902.   /* ignore_input will not return true for ENDI, so we don't need to
  5903.      worry about checking it again here.  */
  5904.  
  5905.   if (! mri_control_stack->else_seen)
  5906.     colon (mri_control_stack->next);
  5907.   colon (mri_control_stack->bottom);
  5908.  
  5909.   pop_mri_control ();
  5910.  
  5911.   if (flag_mri)
  5912.     {
  5913.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5914.     ++input_line_pointer;
  5915.     }
  5916.  
  5917.   demand_empty_rest_of_line ();
  5918. }
  5919.  
  5920. /* Handle the MRI BREAK pseudo-op.  */
  5921.  
  5922. static void
  5923. s_mri_break (extent)
  5924.      int extent;
  5925. {
  5926.   struct mri_control_info *n;
  5927.   char *buf;
  5928.   char ex[2];
  5929.  
  5930.   n = mri_control_stack;
  5931.   while (n != NULL
  5932.      && n->type != mri_for
  5933.      && n->type != mri_repeat
  5934.      && n->type != mri_while)
  5935.     n = n->outer;
  5936.   if (n == NULL)
  5937.     {
  5938.       as_bad ("break outside of structured loop");
  5939.       ignore_rest_of_line ();
  5940.       return;
  5941.     }
  5942.  
  5943.   buf = (char *) xmalloc (20 + strlen (n->bottom));
  5944.   ex[0] = extent;
  5945.   ex[1] = '\0';
  5946.   sprintf (buf, "bra%s %s", ex, n->bottom);
  5947.   md_assemble (buf);
  5948.   free (buf);
  5949.  
  5950.   if (flag_mri)
  5951.     {
  5952.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5953.     ++input_line_pointer;
  5954.     }
  5955.  
  5956.   demand_empty_rest_of_line ();
  5957. }
  5958.  
  5959. /* Handle the MRI NEXT pseudo-op.  */
  5960.  
  5961. static void
  5962. s_mri_next (extent)
  5963.      int extent;
  5964. {
  5965.   struct mri_control_info *n;
  5966.   char *buf;
  5967.   char ex[2];
  5968.  
  5969.   n = mri_control_stack;
  5970.   while (n != NULL
  5971.      && n->type != mri_for
  5972.      && n->type != mri_repeat
  5973.      && n->type != mri_while)
  5974.     n = n->outer;
  5975.   if (n == NULL)
  5976.     {
  5977.       as_bad ("next outside of structured loop");
  5978.       ignore_rest_of_line ();
  5979.       return;
  5980.     }
  5981.  
  5982.   buf = (char *) xmalloc (20 + strlen (n->next));
  5983.   ex[0] = extent;
  5984.   ex[1] = '\0';
  5985.   sprintf (buf, "bra%s %s", ex, n->next);
  5986.   md_assemble (buf);
  5987.   free (buf);
  5988.  
  5989.   if (flag_mri)
  5990.     {
  5991.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  5992.     ++input_line_pointer;
  5993.     }
  5994.  
  5995.   demand_empty_rest_of_line ();
  5996. }
  5997.  
  5998. /* Handle the MRI FOR pseudo-op.  */
  5999.  
  6000. static void
  6001. s_mri_for (qual)
  6002.      int qual;
  6003. {
  6004.   const char *varstart, *varstop;
  6005.   const char *initstart, *initstop;
  6006.   const char *endstart, *endstop;
  6007.   const char *bystart, *bystop;
  6008.   int up;
  6009.   int by;
  6010.   int extent;
  6011.   struct mri_control_info *n;
  6012.   char *buf;
  6013.   char *s;
  6014.   char ex[2];
  6015.  
  6016.   /* The syntax is
  6017.        FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
  6018.      */
  6019.  
  6020.   SKIP_WHITESPACE ();
  6021.   varstart = input_line_pointer;
  6022.  
  6023.   /* Look for the '='.  */
  6024.   while (! is_end_of_line[(unsigned char) *input_line_pointer]
  6025.      && *input_line_pointer != '=')
  6026.     ++input_line_pointer;
  6027.   if (*input_line_pointer != '=')
  6028.     {
  6029.       as_bad ("missing =");
  6030.       ignore_rest_of_line ();
  6031.       return;
  6032.     }
  6033.  
  6034.   varstop = input_line_pointer;
  6035.   if (varstop > varstart
  6036.       && (varstop[-1] == ' ' || varstop[-1] == '\t'))
  6037.     --varstop;
  6038.  
  6039.   ++input_line_pointer;
  6040.  
  6041.   initstart = input_line_pointer;
  6042.  
  6043.   /* Look for TO or DOWNTO.  */
  6044.   up = 1;
  6045.   initstop = NULL;
  6046.   while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6047.     {
  6048.       if (strncasecmp (input_line_pointer, "TO", 2) == 0
  6049.       && ! is_part_of_name (input_line_pointer[2]))
  6050.     {
  6051.       initstop = input_line_pointer;
  6052.       input_line_pointer += 2;
  6053.       break;
  6054.     }
  6055.       if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
  6056.       && ! is_part_of_name (input_line_pointer[6]))
  6057.     {
  6058.       initstop = input_line_pointer;
  6059.       up = 0;
  6060.       input_line_pointer += 6;
  6061.       break;
  6062.     }
  6063.       ++input_line_pointer;
  6064.     }
  6065.   if (initstop == NULL)
  6066.     {
  6067.       as_bad ("missing to or downto");
  6068.       ignore_rest_of_line ();
  6069.       return;
  6070.     }
  6071.   if (initstop > initstart
  6072.       && (initstop[-1] == ' ' || initstop[-1] == '\t'))
  6073.     --initstop;
  6074.  
  6075.   SKIP_WHITESPACE ();
  6076.   endstart = input_line_pointer;
  6077.  
  6078.   /* Look for BY or DO.  */
  6079.   by = 0;
  6080.   endstop = NULL;
  6081.   while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6082.     {
  6083.       if (strncasecmp (input_line_pointer, "BY", 2) == 0
  6084.       && ! is_part_of_name (input_line_pointer[2]))
  6085.     {
  6086.       endstop = input_line_pointer;
  6087.       by = 1;
  6088.       input_line_pointer += 2;
  6089.       break;
  6090.     }
  6091.       if (strncasecmp (input_line_pointer, "DO", 2) == 0
  6092.       && (input_line_pointer[2] == '.'
  6093.           || ! is_part_of_name (input_line_pointer[2])))
  6094.     {
  6095.       endstop = input_line_pointer;
  6096.       input_line_pointer += 2;
  6097.       break;
  6098.     }
  6099.       ++input_line_pointer;
  6100.     }
  6101.   if (endstop == NULL)
  6102.     {
  6103.       as_bad ("missing do");
  6104.       ignore_rest_of_line ();
  6105.       return;
  6106.     }
  6107.   if (endstop > endstart
  6108.       && (endstop[-1] == ' ' || endstop[-1] == '\t'))
  6109.     --endstop;
  6110.  
  6111.   if (! by)
  6112.     {
  6113.       bystart = "#1";
  6114.       bystop = bystart + 2;
  6115.     }
  6116.   else
  6117.     {
  6118.       SKIP_WHITESPACE ();
  6119.       bystart = input_line_pointer;
  6120.  
  6121.       /* Look for DO.  */
  6122.       bystop = NULL;
  6123.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6124.     {
  6125.       if (strncasecmp (input_line_pointer, "DO", 2) == 0
  6126.           && (input_line_pointer[2] == '.'
  6127.           || ! is_part_of_name (input_line_pointer[2])))
  6128.         {
  6129.           bystop = input_line_pointer;
  6130.           input_line_pointer += 2;
  6131.           break;
  6132.         }
  6133.       ++input_line_pointer;
  6134.     }
  6135.       if (bystop == NULL)
  6136.     {
  6137.       as_bad ("missing do");
  6138.       ignore_rest_of_line ();
  6139.       return;
  6140.     }
  6141.       if (bystop > bystart
  6142.       && (bystop[-1] == ' ' || bystop[-1] == '\t'))
  6143.     --bystop;
  6144.     }
  6145.  
  6146.   if (*input_line_pointer != '.')
  6147.     extent = '\0';
  6148.   else
  6149.     {
  6150.       extent = input_line_pointer[1];
  6151.       input_line_pointer += 2;
  6152.     }
  6153.  
  6154.   /* We have fully parsed the FOR operands.  Now build the loop.  */
  6155.  
  6156.   n = push_mri_control (mri_for);
  6157.  
  6158.   buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
  6159.  
  6160.   /* move init,var */
  6161.   s = buf;
  6162.   *s++ = 'm';
  6163.   *s++ = 'o';
  6164.   *s++ = 'v';
  6165.   *s++ = 'e';
  6166.   if (qual != '\0')
  6167.     *s++ = qual;
  6168.   *s++ = ' ';
  6169.   memcpy (s, initstart, initstop - initstart);
  6170.   s += initstop - initstart;
  6171.   *s++ = ',';
  6172.   memcpy (s, varstart, varstop - varstart);
  6173.   s += varstop - varstart;
  6174.   *s = '\0';
  6175.   md_assemble (buf);
  6176.  
  6177.   colon (n->top);
  6178.  
  6179.   /* cmp end,var */
  6180.   s = buf;
  6181.   *s++ = 'c';
  6182.   *s++ = 'm';
  6183.   *s++ = 'p';
  6184.   if (qual != '\0')
  6185.     *s++ = qual;
  6186.   *s++ = ' ';
  6187.   memcpy (s, endstart, endstop - endstart);
  6188.   s += endstop - endstart;
  6189.   *s++ = ',';
  6190.   memcpy (s, varstart, varstop - varstart);
  6191.   s += varstop - varstart;
  6192.   *s = '\0';
  6193.   md_assemble (buf);
  6194.  
  6195.   /* bcc bottom */
  6196.   ex[0] = extent;
  6197.   ex[1] = '\0';
  6198.   if (up)
  6199.     sprintf (buf, "blt%s %s", ex, n->bottom);
  6200.   else
  6201.     sprintf (buf, "bgt%s %s", ex, n->bottom);
  6202.   md_assemble (buf);
  6203.  
  6204.   /* Put together the add or sub instruction used by ENDF.  */
  6205.   s = buf;
  6206.   if (up)
  6207.     strcpy (s, "add");
  6208.   else
  6209.     strcpy (s, "sub");
  6210.   s += 3;
  6211.   if (qual != '\0')
  6212.     *s++ = qual;
  6213.   *s++ = ' ';
  6214.   memcpy (s, bystart, bystop - bystart);
  6215.   s += bystop - bystart;
  6216.   *s++ = ',';
  6217.   memcpy (s, varstart, varstop - varstart);
  6218.   s += varstop - varstart;
  6219.   *s = '\0';
  6220.   n->incr = buf;
  6221.  
  6222.   if (flag_mri)
  6223.     {
  6224.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6225.     ++input_line_pointer;
  6226.     }
  6227.  
  6228.   demand_empty_rest_of_line ();
  6229. }
  6230.  
  6231. /* Handle the MRI ENDF pseudo-op.  */
  6232.  
  6233. static void
  6234. s_mri_endf (ignore)
  6235.      int ignore;
  6236. {
  6237.   if (mri_control_stack == NULL
  6238.       || mri_control_stack->type != mri_for)
  6239.     {
  6240.       as_bad ("endf without for");
  6241.       ignore_rest_of_line ();
  6242.       return;
  6243.     }
  6244.  
  6245.   colon (mri_control_stack->next);
  6246.  
  6247.   md_assemble (mri_control_stack->incr);
  6248.  
  6249.   sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
  6250.   md_assemble (mri_control_stack->incr);
  6251.  
  6252.   free (mri_control_stack->incr);
  6253.  
  6254.   colon (mri_control_stack->bottom);
  6255.  
  6256.   pop_mri_control ();
  6257.  
  6258.   if (flag_mri)
  6259.     {
  6260.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6261.     ++input_line_pointer;
  6262.     }
  6263.  
  6264.   demand_empty_rest_of_line ();
  6265. }
  6266.  
  6267. /* Handle the MRI REPEAT pseudo-op.  */
  6268.  
  6269. static void
  6270. s_mri_repeat (ignore)
  6271.      int ignore;
  6272. {
  6273.   struct mri_control_info *n;
  6274.  
  6275.   n = push_mri_control (mri_repeat);
  6276.   colon (n->top);
  6277.   if (flag_mri)
  6278.     {
  6279.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6280.     ++input_line_pointer;
  6281.     }
  6282.   demand_empty_rest_of_line ();
  6283. }
  6284.  
  6285. /* Handle the MRI UNTIL pseudo-op.  */
  6286.  
  6287. static void
  6288. s_mri_until (qual)
  6289.      int qual;
  6290. {
  6291.   char *s;
  6292.  
  6293.   if (mri_control_stack == NULL
  6294.       || mri_control_stack->type != mri_repeat)
  6295.     {
  6296.       as_bad ("until without repeat");
  6297.       ignore_rest_of_line ();
  6298.       return;
  6299.     }
  6300.  
  6301.   colon (mri_control_stack->next);
  6302.  
  6303.   for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
  6304.     ;
  6305.  
  6306.   parse_mri_control_expression (s, qual, (const char *) NULL,
  6307.                 mri_control_stack->top, '\0');
  6308.  
  6309.   colon (mri_control_stack->bottom);
  6310.  
  6311.   input_line_pointer = s;
  6312.  
  6313.   pop_mri_control ();
  6314.  
  6315.   if (flag_mri)
  6316.     {
  6317.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6318.     ++input_line_pointer;
  6319.     }
  6320.  
  6321.   demand_empty_rest_of_line ();
  6322. }
  6323.  
  6324. /* Handle the MRI WHILE pseudo-op.  */
  6325.  
  6326. static void
  6327. s_mri_while (qual)
  6328.      int qual;
  6329. {
  6330.   char *s;
  6331.  
  6332.   struct mri_control_info *n;
  6333.  
  6334.   s = input_line_pointer;
  6335.   while (! is_end_of_line[(unsigned char) *s]
  6336.      && (! flag_mri || *s != '*'))
  6337.     s++;
  6338.   --s;
  6339.   while (*s == ' ' || *s == '\t')
  6340.     --s;
  6341.   if (s - input_line_pointer > 1
  6342.       && s[-1] == '.')
  6343.     s -= 2;
  6344.   if (s - input_line_pointer < 2
  6345.       || strncasecmp (s - 1, "DO", 2) != 0)
  6346.     {
  6347.       as_bad ("missing do");
  6348.       ignore_rest_of_line ();
  6349.       return;
  6350.     }
  6351.  
  6352.   n = push_mri_control (mri_while);
  6353.  
  6354.   colon (n->next);
  6355.  
  6356.   parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
  6357.                 s[1] == '.' ? s[2] : '\0');
  6358.  
  6359.   input_line_pointer = s + 1;
  6360.   if (*input_line_pointer == '.')
  6361.     input_line_pointer += 2;
  6362.  
  6363.   if (flag_mri)
  6364.     {
  6365.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6366.     ++input_line_pointer;
  6367.     }
  6368.  
  6369.   demand_empty_rest_of_line ();
  6370. }
  6371.  
  6372. /* Handle the MRI ENDW pseudo-op.  */
  6373.  
  6374. static void
  6375. s_mri_endw (ignore)
  6376.      int ignore;
  6377. {
  6378.   char *buf;
  6379.  
  6380.   if (mri_control_stack == NULL
  6381.       || mri_control_stack->type != mri_while)
  6382.     {
  6383.       as_bad ("endw without while");
  6384.       ignore_rest_of_line ();
  6385.       return;
  6386.     }
  6387.  
  6388.   buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
  6389.   sprintf (buf, "bra %s", mri_control_stack->next);
  6390.   md_assemble (buf);
  6391.   free (buf);
  6392.  
  6393.   colon (mri_control_stack->bottom);
  6394.  
  6395.   pop_mri_control ();
  6396.  
  6397.   if (flag_mri)
  6398.     {
  6399.       while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6400.     ++input_line_pointer;
  6401.     }
  6402.  
  6403.   demand_empty_rest_of_line ();
  6404. }
  6405.  
  6406. /*
  6407.  * md_parse_option
  6408.  *    Invocation line includes a switch not recognized by the base assembler.
  6409.  *    See if it's a processor-specific option.  These are:
  6410.  *
  6411.  *    -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
  6412.  *    -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
  6413.  *        Select the architecture.  Instructions or features not
  6414.  *        supported by the selected architecture cause fatal
  6415.  *        errors.  More than one may be specified.  The default is
  6416.  *        -m68020 -m68851 -m68881.  Note that -m68008 is a synonym
  6417.  *        for -m68000, and -m68882 is a synonym for -m68881.
  6418.  *    -[A]m[c]no-68851, -[A]m[c]no-68881
  6419.  *        Don't accept 688?1 instructions.  (The "c" is kind of silly,
  6420.  *        so don't use or document it, but that's the way the parsing
  6421.  *        works).
  6422.  *
  6423.  *    -pic    Indicates PIC.
  6424.  *    -k    Indicates PIC.  (Sun 3 only.)
  6425.  *
  6426.  *    --bitwise-or
  6427.  *        Permit `|' to be used in expressions.
  6428.  *
  6429.  */
  6430.  
  6431. #ifdef OBJ_ELF
  6432. CONST char *md_shortopts = "lSA:m:kQ:V";
  6433. #else
  6434. CONST char *md_shortopts = "SA:m:s:k";
  6435. #endif
  6436.  
  6437. struct option md_longopts[] = {
  6438. #define OPTION_PIC (OPTION_MD_BASE)
  6439.   {"pic", no_argument, NULL, OPTION_PIC},
  6440. #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
  6441.   {"register-prefix-optional", no_argument, NULL,
  6442.      OPTION_REGISTER_PREFIX_OPTIONAL},
  6443. #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
  6444.   {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
  6445.   {NULL, no_argument, NULL, 0}
  6446. };
  6447. size_t md_longopts_size = sizeof(md_longopts);
  6448.  
  6449. int
  6450. md_parse_option (c, arg)
  6451.      int c;
  6452.      char *arg;
  6453. {
  6454.   switch (c)
  6455.     {
  6456. #if 0
  6457.     /* FIXME:  #if 0 is the wrong way to disable this code since it disables it
  6458.        for all targets and we only need it disabled for the Amiga.  However we can't
  6459.        test for __amigaos__ not being defined, since we may be building a cross 
  6460.        environment for the Amiga, in which case __amigaos__ won't be defined.
  6461.        Do NOT use -l on the Amiga, it fails to work properly. Most importantly,
  6462.        it can generate "JMP absolute word" instructions where the absolute address
  6463.        is a sign-extended word. Obviously, this works only in the first and last
  6464.        32K of memory. 
  6465.  
  6466.        Use -smallcode instead.
  6467.     */
  6468.     case 'l':            /* -l means keep external to 2 bit offset
  6469.                    rather than 16 bit one */
  6470.       flag_short_refs = 1;
  6471.       break;
  6472. #endif
  6473.  
  6474.     case 'S':            /* -S means that jbsr's always turn into
  6475.                    jsr's.  */
  6476.       flag_long_jumps = 1;
  6477.       break;
  6478.  
  6479.     case 's':
  6480.       if (!strcmp(arg, "c") || !strcmp(arg, "mallcode"))
  6481.         flag_small_code = 1;
  6482.       else
  6483.         return 0;
  6484.       break;
  6485.       
  6486.     case 'A':
  6487.       if (*arg == 'm')
  6488.      arg++;
  6489.       /* intentional fall-through */
  6490.     case 'm':
  6491.  
  6492.       if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
  6493.     {
  6494.       int i;
  6495.       unsigned long arch;
  6496.       const char *oarg = arg;
  6497.  
  6498.       arg += 3;
  6499.       if (*arg == 'm')
  6500.         {
  6501.           arg++;
  6502.           if (arg[0] == 'c' && arg[1] == '6')
  6503.         arg++;
  6504.         }
  6505.       for (i = 0; i < n_archs; i++)
  6506.         if (!strcmp (arg, archs[i].name))
  6507.           break;
  6508.       if (i == n_archs)
  6509.         {
  6510.         unknown:
  6511.           as_bad ("unrecognized option `%s'", oarg);
  6512.           return 0;
  6513.         }
  6514.       arch = archs[i].arch;
  6515.       if (arch == m68881)
  6516.         no_68881 = 1;
  6517.       else if (arch == m68851)
  6518.         no_68851 = 1;
  6519.       else
  6520.         goto unknown;
  6521.     }
  6522.       else
  6523.     {
  6524.       int i;
  6525.  
  6526.       if (arg[0] == 'c' && arg[1] == '6')
  6527.         arg++;
  6528.  
  6529.       for (i = 0; i < n_archs; i++)
  6530.         if (!strcmp (arg, archs[i].name))
  6531.           {
  6532.         unsigned long arch = archs[i].arch;
  6533.         if (cpu_of_arch (arch))
  6534.           /* It's a cpu spec.  */
  6535.           {
  6536.             current_architecture &= ~m68000up;
  6537.             current_architecture |= arch;
  6538.           }
  6539.         else if (arch == m68881)
  6540.           {
  6541.             current_architecture |= m68881;
  6542.             no_68881 = 0;
  6543.           }
  6544.         else if (arch == m68851)
  6545.           {
  6546.             current_architecture |= m68851;
  6547.             no_68851 = 0;
  6548.           }
  6549.         else
  6550.           /* ??? */
  6551.           abort ();
  6552.         break;
  6553.           }
  6554.       if (i == n_archs)
  6555.         {
  6556.           as_bad ("unrecognized architecture specification `%s'", arg);
  6557.           return 0;
  6558.         }
  6559.     }
  6560.       break;
  6561.  
  6562.     case OPTION_PIC:
  6563.     case 'k':
  6564.       flag_want_pic = 1;
  6565.       break;            /* -pic, Position Independent Code */
  6566.  
  6567.     case OPTION_REGISTER_PREFIX_OPTIONAL:
  6568.       flag_reg_prefix_optional = 1;
  6569.       reg_prefix_optional_seen = 1;
  6570.       break;
  6571.  
  6572.       /* -V: SVR4 argument to print version ID.  */
  6573.     case 'V':
  6574.       print_version_id ();
  6575.       break;
  6576.  
  6577.       /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
  6578.      should be emitted or not.  FIXME: Not implemented.  */
  6579.     case 'Q':
  6580.       break;
  6581.  
  6582.     case OPTION_BITWISE_OR:
  6583.       {
  6584.     char *n, *t;
  6585.     const char *s;
  6586.  
  6587.     n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
  6588.     t = n;
  6589.     for (s = m68k_comment_chars; *s != '\0'; s++)
  6590.       if (*s != '|')
  6591.         *t++ = *s;
  6592.     *t = '\0';
  6593.     m68k_comment_chars = n;
  6594.       }
  6595.       break;
  6596.  
  6597.     default:
  6598.       return 0;
  6599.     }
  6600.  
  6601.   return 1;
  6602. }
  6603.  
  6604. void
  6605. md_show_usage (stream)
  6606.      FILE *stream;
  6607. {
  6608.   fprintf(stream, "\
  6609. 680X0 options:\n\
  6610. -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
  6611.  | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
  6612.  | -mcpu32 | -mcf5200\n\
  6613.             specify variant of 680X0 architecture [default 68020]\n\
  6614. -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
  6615.             target has/lacks floating-point coprocessor\n\
  6616.             [default yes for 68020, 68030, and cpu32]\n");
  6617.   fprintf(stream, "\
  6618. -m68851 | -mno-68851\n\
  6619.             target has/lacks memory-management unit coprocessor\n\
  6620.             [default yes for 68020 and up]\n\
  6621. -pic, -k        generate position independent code\n\
  6622. -S            turn jbsr into jsr\n\
  6623. -smallcode, -sc        small code model\n\
  6624. --register-prefix-optional\n\
  6625.             recognize register names without prefix character\n\
  6626. --bitwise-or        do not treat `|' as a comment character\n");
  6627. }
  6628.  
  6629. #ifdef TEST2
  6630.  
  6631. /* TEST2:  Test md_assemble() */
  6632. /* Warning, this routine probably doesn't work anymore */
  6633.  
  6634. main ()
  6635. {
  6636.   struct m68k_it the_ins;
  6637.   char buf[120];
  6638.   char *cp;
  6639.   int n;
  6640.  
  6641.   m68k_ip_begin ();
  6642.   for (;;)
  6643.     {
  6644.       if (!gets (buf) || !*buf)
  6645.     break;
  6646.       if (buf[0] == '|' || buf[1] == '.')
  6647.     continue;
  6648.       for (cp = buf; *cp; cp++)
  6649.     if (*cp == '\t')
  6650.       *cp = ' ';
  6651.       if (is_label (buf))
  6652.     continue;
  6653.       memset (&the_ins, '\0', sizeof (the_ins));
  6654.       m68k_ip (&the_ins, buf);
  6655.       if (the_ins.error)
  6656.     {
  6657.       printf ("Error %s in %s\n", the_ins.error, buf);
  6658.     }
  6659.       else
  6660.     {
  6661.       printf ("Opcode(%d.%s): ", the_ins.numo, the_ins.args);
  6662.       for (n = 0; n < the_ins.numo; n++)
  6663.         printf (" 0x%x", the_ins.opcode[n] & 0xffff);
  6664.       printf ("    ");
  6665.       print_the_insn (&the_ins.opcode[0], stdout);
  6666.       (void) putchar ('\n');
  6667.     }
  6668.       for (n = 0; n < strlen (the_ins.args) / 2; n++)
  6669.     {
  6670.       if (the_ins.operands[n].error)
  6671.         {
  6672.           printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
  6673.           continue;
  6674.         }
  6675.       printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
  6676.       if (the_ins.operands[n].b_const)
  6677.         printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
  6678.       printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
  6679.       if (the_ins.operands[n].b_iadd)
  6680.         printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
  6681.       (void) putchar ('\n');
  6682.     }
  6683.     }
  6684.   m68k_ip_end ();
  6685.   return 0;
  6686. }
  6687.  
  6688. is_label (str)
  6689.      char *str;
  6690. {
  6691.   while (*str == ' ')
  6692.     str++;
  6693.   while (*str && *str != ' ')
  6694.     str++;
  6695.   if (str[-1] == ':' || str[1] == '=')
  6696.     return 1;
  6697.   return 0;
  6698. }
  6699.  
  6700. #endif
  6701.  
  6702. /* Possible states for relaxation:
  6703.  
  6704.    0 0    branch offset    byte    (bra, etc)
  6705.    0 1            word
  6706.    0 2            long
  6707.  
  6708.    1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  6709.    1 1            word
  6710.    1 2            long
  6711.  
  6712.    2 0    two-offset index word-word a0@(32,d4)@(45) etc
  6713.    2 1            word-long
  6714.    2 2            long-word
  6715.    2 3            long-long
  6716.  
  6717.    */
  6718.  
  6719. /* We have no need to default values of symbols.  */
  6720.  
  6721. /* ARGSUSED */
  6722. symbolS *
  6723. md_undefined_symbol (name)
  6724.      char *name;
  6725. {
  6726.   return 0;
  6727. }
  6728.  
  6729. /* Round up a section size to the appropriate boundary.  */
  6730. valueT
  6731. md_section_align (segment, size)
  6732.      segT segment;
  6733.      valueT size;
  6734. {
  6735.   return size;            /* Byte alignment is fine */
  6736. }
  6737.  
  6738. /* Exactly what point is a PC-relative offset relative TO?
  6739.    On the 68k, it is relative to the address of the first extension
  6740.    word.  The difference between the addresses of the offset and the
  6741.    first extension word is stored in fx_pcrel_adjust. */
  6742. long
  6743. md_pcrel_from (fixP)
  6744.      fixS *fixP;
  6745. {
  6746.   int adjust;
  6747.  
  6748.   /* Because fx_pcrel_adjust is a char, and may be unsigned, we store
  6749.      -1 as 64.  */
  6750.   adjust = fixP->fx_pcrel_adjust;
  6751.   if (adjust == 64)
  6752.     adjust = -1;
  6753.   return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
  6754. }
  6755.  
  6756. #ifndef BFD_ASSEMBLER
  6757. /*ARGSUSED*/
  6758. void
  6759. tc_coff_symbol_emit_hook (ignore)
  6760.      symbolS *ignore;
  6761. {
  6762. }
  6763.  
  6764. int
  6765. tc_coff_sizemachdep (frag)
  6766.      fragS *frag;
  6767. {
  6768.   switch (frag->fr_subtype & 0x3)
  6769.     {
  6770.     case BYTE:
  6771.       return 1;
  6772.     case SHORT:
  6773.       return 2;
  6774.     case LONG:
  6775.       return 4;
  6776.     default:
  6777.       abort ();
  6778.       return 0;
  6779.     }
  6780. }
  6781. #endif
  6782.  
  6783. /* end of tc-m68k.c */
  6784.