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-z8k.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  30KB  |  1,613 lines

  1. /* tc-z8k.c -- Assemble code for the Zilog Z800n
  2.    Copyright (C) 1992 Free Software Foundation.
  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
  18.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. /*
  21.   Written By Steve Chamberlain
  22.   sac@cygnus.com
  23.   */
  24. #define DEFINE_TABLE
  25. #include <stdio.h>
  26.  
  27. #include "opcodes/z8k-opc.h"
  28.  
  29. #include "as.h"
  30. #include "bfd.h"
  31. #include <ctype.h>
  32.  
  33. const char comment_chars[] =
  34. {'!', 0};
  35. const char line_separator_chars[] =
  36. {';', 0};
  37. const char line_comment_chars[] =
  38. {'#', 0};
  39.  
  40. extern int machine;
  41. extern int coff_flags;
  42. int segmented_mode;
  43. const int md_reloc_size;
  44.  
  45. /* This table describes all the machine specific pseudo-ops the assembler
  46.    has to support.  The fields are:
  47.    pseudo-op name without dot
  48.    function to call to execute this pseudo-op
  49.    Integer arg to pass to the function
  50.    */
  51.  
  52. void cons ();
  53.  
  54. void
  55. s_segm ()
  56. {
  57.   segmented_mode = 1;
  58.   machine = bfd_mach_z8001;
  59.   coff_flags = F_Z8001;
  60. }
  61.  
  62. void
  63. s_unseg ()
  64. {
  65.   segmented_mode = 0;
  66.   machine = bfd_mach_z8002;
  67.   coff_flags = F_Z8002;
  68. }
  69.  
  70. static
  71. void
  72. even ()
  73. {
  74.   frag_align (1, 0);
  75.   record_alignment (now_seg, 1);
  76. }
  77.  
  78. void obj_coff_section ();
  79.  
  80. int
  81. tohex (c)
  82.      int c;
  83. {
  84.   if (isdigit (c))
  85.     return c - '0';
  86.   if (islower (c))
  87.     return c - 'a' + 10;
  88.   return c - 'A' + 10;
  89. }
  90.  
  91. void
  92. sval ()
  93. {
  94.  
  95.   SKIP_WHITESPACE ();
  96.   if (*input_line_pointer == '\'')
  97.     {
  98.       int c;
  99.       input_line_pointer++;
  100.       c = *input_line_pointer++;
  101.       while (c != '\'')
  102.     {
  103.       if (c == '%')
  104.         {
  105.           c = (tohex (input_line_pointer[0]) << 4)
  106.         | tohex (input_line_pointer[1]);
  107.           input_line_pointer += 2;
  108.         }
  109.       FRAG_APPEND_1_CHAR (c);
  110.       c = *input_line_pointer++;
  111.     }
  112.       demand_empty_rest_of_line ();
  113.     }
  114.  
  115. }
  116. const pseudo_typeS md_pseudo_table[] =
  117. {
  118.   {"int", cons, 2},
  119.   {"data.b", cons, 1},
  120.   {"data.w", cons, 2},
  121.   {"data.l", cons, 4},
  122.   {"form", listing_psize, 0},
  123.   {"heading", listing_title, 0},
  124.   {"import", s_ignore, 0},
  125.   {"page", listing_eject, 0},
  126.   {"program", s_ignore, 0},
  127.   {"z8001", s_segm, 0},
  128.   {"z8002", s_unseg, 0},
  129.  
  130.  
  131.   {"segm", s_segm, 0},
  132.   {"unsegm", s_unseg, 0},
  133.   {"unseg", s_unseg, 0},
  134.   {"name", s_app_file, 0},
  135.   {"global", s_globl, 0},
  136.   {"wval", cons, 2},
  137.   {"lval", cons, 4},
  138.   {"bval", cons, 1},
  139.   {"sval", sval, 0},
  140.   {"rsect", obj_coff_section, 0},
  141.   {"sect", obj_coff_section, 0},
  142.   {"block", s_space, 0},
  143.   {"even", even, 0},
  144.   {0, 0, 0}
  145. };
  146.  
  147. const char EXP_CHARS[] = "eE";
  148.  
  149. /* Chars that mean this number is a floating point constant */
  150. /* As in 0f12.456 */
  151. /* or    0d1.2345e12 */
  152. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  153.  
  154. static struct hash_control *opcode_hash_control;    /* Opcode mnemonics */
  155.  
  156. void
  157. md_begin ()
  158. {
  159.   opcode_entry_type *opcode;
  160.   char *prev_name = "";
  161.   int idx = 0;
  162.  
  163.   opcode_hash_control = hash_new ();
  164.  
  165.   for (opcode = z8k_table; opcode->name; opcode++)
  166.     {
  167.       /* Only enter unique codes into the table */
  168.       char *src = opcode->name;
  169.  
  170.       if (strcmp (opcode->name, prev_name))
  171.     {
  172.       hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
  173.       idx++;
  174.     }
  175.       opcode->idx = idx;
  176.       prev_name = opcode->name;
  177.     }
  178.  
  179.   /* default to z8002 */
  180.   s_unseg ();
  181.  
  182.   /* insert the pseudo ops too */
  183.   for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
  184.     {
  185.       opcode_entry_type *fake_opcode;
  186.       fake_opcode = (opcode_entry_type *) malloc (sizeof (opcode_entry_type));
  187.       fake_opcode->name = md_pseudo_table[idx].poc_name,
  188.     fake_opcode->func = (void *) (md_pseudo_table + idx);
  189.       fake_opcode->opcode = 250;
  190.       hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode);
  191.     }
  192.  
  193.   linkrelax = 1;
  194. }
  195.  
  196. struct z8k_exp
  197. {
  198.   char *e_beg;
  199.   char *e_end;
  200.   expressionS e_exp;
  201. };
  202. typedef struct z8k_op
  203. {
  204.   char regsize;            /* 'b','w','r','q' */
  205.   unsigned int reg;        /* 0..15 */
  206.  
  207.   int mode;
  208.  
  209.   unsigned int x_reg;        /* any other register associated with the mode */
  210.   expressionS exp;        /* any expression */
  211. }
  212.  
  213. op_type;
  214.  
  215. static expressionS *da_operand;
  216. static expressionS *imm_operand;
  217.  
  218. int reg[16];
  219. int the_cc;
  220. int the_ctrl;
  221. int the_flags;
  222. int the_interrupt;
  223.  
  224. char *
  225. DEFUN (whatreg, (reg, src),
  226.        int *reg AND
  227.        char *src)
  228. {
  229.   if (isdigit (src[1]))
  230.     {
  231.       *reg = (src[0] - '0') * 10 + src[1] - '0';
  232.       return src + 2;
  233.     }
  234.   else
  235.     {
  236.       *reg = (src[0] - '0');
  237.       return src + 1;
  238.     }
  239. }
  240.  
  241. /*
  242.   parse operands
  243.  
  244.   rh0-rh7, rl0-rl7
  245.   r0-r15
  246.   rr0-rr14
  247.   rq0--rq12
  248.   WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
  249.   r0l,r0h,..r7l,r7h
  250.   @WREG
  251.   @WREG+
  252.   @-WREG
  253.   #const
  254.  
  255.   */
  256.  
  257. /* try and parse a reg name, returns number of chars consumed */
  258. char *
  259. DEFUN (parse_reg, (src, mode, reg),
  260.        char *src AND
  261.        int *mode AND
  262.        unsigned int *reg)
  263. {
  264.   char *res = 0;
  265.   char regno;
  266.  
  267.   if (src[0] == 's' && src[1] == 'p')
  268.     {
  269.       if (segmented_mode)
  270.         {
  271.           *mode = CLASS_REG_LONG;
  272.           *reg = 14;
  273.         }
  274.       else
  275.         {
  276.           *mode = CLASS_REG_WORD;
  277.           *reg = 15;
  278.         }
  279.       return src + 2;
  280.     }
  281.   if (src[0] == 'r')
  282.     {
  283.       if (src[1] == 'r')
  284.         {
  285.           *mode = CLASS_REG_LONG;
  286.           res = whatreg (reg, src + 2);
  287.       regno = *reg;
  288.       if (regno > 14)
  289.               as_warn ("register rr%d, out of range.",regno);
  290.         }
  291.       else if (src[1] == 'h')
  292.         {
  293.           *mode = CLASS_REG_BYTE;
  294.           res = whatreg (reg, src + 2);
  295.       regno = *reg;
  296.       if (regno > 7)
  297.               as_warn ("register rh%d, out of range.",regno);
  298.         }
  299.       else if (src[1] == 'l')
  300.         {
  301.           *mode = CLASS_REG_BYTE;
  302.           res = whatreg (reg, src + 2);
  303.       regno = *reg;
  304.       if (regno > 7)
  305.               as_warn ("register rl%d, out of range.",regno);
  306.           *reg += 8;
  307.         }
  308.       else if (src[1] == 'q')
  309.         {
  310.           *mode = CLASS_REG_QUAD;
  311.           res = whatreg (reg, src + 2);
  312.       regno = *reg;
  313.       if (regno > 12)
  314.               as_warn ("register rq%d, out of range.",regno);
  315.         }
  316.       else
  317.         {
  318.           *mode = CLASS_REG_WORD;
  319.           res = whatreg (reg, src + 1);
  320.       regno = *reg;
  321.       if (regno > 15)
  322.               as_warn ("register r%d, out of range.",regno);
  323.         }
  324.     }
  325.   return res;
  326.  
  327. }
  328.  
  329. char *
  330. DEFUN (parse_exp, (s, op),
  331.        char *s AND
  332.        expressionS * op)
  333. {
  334.   char *save = input_line_pointer;
  335.   char *new;
  336.  
  337.   input_line_pointer = s;
  338.   expression (op);
  339.   if (op->X_op == O_absent)
  340.     as_bad ("missing operand");
  341.   new = input_line_pointer;
  342.   input_line_pointer = save;
  343.   return new;
  344. }
  345.  
  346. /* The many forms of operand:
  347.  
  348.    <rb>
  349.    <r>
  350.    <rr>
  351.    <rq>
  352.    @r
  353.    #exp
  354.    exp
  355.    exp(r)
  356.    r(#exp)
  357.    r(r)
  358.  
  359.  
  360.  
  361.    */
  362.  
  363. static
  364. char *
  365. DEFUN (checkfor, (ptr, what),
  366.        char *ptr AND
  367.        char what)
  368. {
  369.   if (*ptr == what)
  370.     ptr++;
  371.   else
  372.     {
  373.       as_bad ("expected %c", what);
  374.     }
  375.   return ptr;
  376. }
  377.  
  378. /* Make sure the mode supplied is the size of a word */
  379. static void
  380. DEFUN (regword, (mode, string),
  381.        int mode AND
  382.        char *string)
  383. {
  384.   int ok;
  385.  
  386.   ok = CLASS_REG_WORD;
  387.   if (ok != mode)
  388.     {
  389.       as_bad ("register is wrong size for a word %s", string);
  390.     }
  391. }
  392.  
  393. /* Make sure the mode supplied is the size of an address */
  394. static void
  395. DEFUN (regaddr, (mode, string),
  396.        int mode AND
  397.        char *string)
  398. {
  399.   int ok;
  400.  
  401.   ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
  402.   if (ok != mode)
  403.     {
  404.       as_bad ("register is wrong size for address %s", string);
  405.     }
  406. }
  407.  
  408. struct ctrl_names
  409. {
  410.    int value;
  411.    char *name;
  412. };
  413.  
  414. struct ctrl_names ctrl_table[] =
  415. {
  416.    0x2, "fcw",
  417.    0X3, "refresh",
  418.    0x4, "psapseg",
  419.    0x5, "psapoff",
  420.    0x5, "psap",
  421.    0x6, "nspseg",
  422.    0x7, "nspoff",
  423.    0x7, "nsp",
  424.    0, 0
  425. };
  426.    
  427. static void
  428. DEFUN (get_ctrl_operand, (ptr, mode, dst),
  429.        char **ptr AND
  430.        struct z8k_op *mode AND
  431.        unsigned int dst)
  432. {
  433.   char *src = *ptr;
  434.   int r;
  435.   int i;
  436.  
  437.   while (*src == ' ')
  438.     src++;
  439.  
  440.   mode->mode = CLASS_CTRL;
  441.   for (i = 0; ctrl_table[i].name; i++)
  442.     {
  443.       int j;
  444.  
  445.       for (j = 0; ctrl_table[i].name[j]; j++)
  446.         {
  447.           if (ctrl_table[i].name[j] != src[j])
  448.             goto fail;
  449.         }
  450.       the_ctrl = ctrl_table[i].value;
  451.       *ptr = src + j;
  452.       return;
  453.     fail:;
  454.     }
  455.   the_ctrl = 0;
  456.   return;
  457. }
  458.  
  459. struct flag_names
  460. {
  461.   int value;
  462.   char *name;
  463.  
  464. };
  465.  
  466. struct flag_names flag_table[] =
  467. {
  468.   0x1, "p",
  469.   0x1, "v",
  470.   0x2, "s",
  471.   0x4, "z",
  472.   0x8, "c",
  473.   0x0, "+",
  474.   0, 0
  475. };
  476.  
  477. static void
  478. DEFUN (get_flags_operand, (ptr, mode, dst),
  479.        char **ptr AND
  480.        struct z8k_op *mode AND
  481.        unsigned int dst)
  482. {
  483.   char *src = *ptr;
  484.   int r;
  485.   int i;
  486.   int j;
  487.  
  488.   while (*src == ' ')
  489.     src++;
  490.  
  491.   mode->mode = CLASS_FLAGS;
  492.   the_flags = 0;
  493.   for (j = 0; j <= 9; j++)
  494.     {
  495.      if (!src[j])
  496.     goto done;
  497.      for (i = 0; flag_table[i].name; i++)
  498.         {
  499.           if (flag_table[i].name[0] == src[j])
  500.         {
  501.             the_flags = the_flags | flag_table[i].value;
  502.         goto match;
  503.         }
  504.         }
  505.       goto done;
  506.     match:
  507.      ;
  508.     }
  509.   done:
  510.   *ptr = src + j;
  511.   return;
  512. }
  513.  
  514.  
  515. struct interrupt_names
  516. {
  517.   int value;
  518.   char *name;
  519.  
  520. };
  521.  
  522. struct interrupt_names intr_table[] =
  523. {
  524.   0x1, "nvi",
  525.   0x2, "vi",
  526.   0x3, "both",
  527.   0x3, "all",
  528.   0, 0
  529. };
  530.  
  531. static void
  532. DEFUN (get_interrupt_operand, (ptr, mode, dst),
  533.        char **ptr AND
  534.        struct z8k_op *mode AND
  535.        unsigned int dst)
  536. {
  537.   char *src = *ptr;
  538.   int r;
  539.   int i;
  540.  
  541.   while (*src == ' ')
  542.     src++;
  543.  
  544.   mode->mode = CLASS_IMM;
  545.   for (i = 0; intr_table[i].name; i++)
  546.     {
  547.       int j;
  548.  
  549.       for (j = 0; intr_table[i].name[j]; j++)
  550.         {
  551.           if (intr_table[i].name[j] != src[j])
  552.             goto fail;
  553.         }
  554.       the_interrupt = intr_table[i].value;
  555.       *ptr = src + j;
  556.       return;
  557.     fail:;
  558.     }
  559.   the_interrupt = 0x0;
  560.   return;
  561. }
  562.  
  563. struct cc_names
  564. {
  565.   int value;
  566.   char *name;
  567.  
  568. };
  569.  
  570. struct cc_names table[] =
  571. {
  572.   0x0, "f",
  573.   0x1, "lt",
  574.   0x2, "le",
  575.   0x3, "ule",
  576.   0x4, "ov",
  577.   0x4, "pe",
  578.   0x5, "mi",
  579.   0x6, "eq",
  580.   0x6, "z",
  581.   0x7, "c",
  582.   0x7, "ult",
  583.   0x8, "t",
  584.   0x9, "ge",
  585.   0xa, "gt",
  586.   0xb, "ugt",
  587.   0xc, "nov",
  588.   0xc, "po",
  589.   0xd, "pl",
  590.   0xe, "ne",
  591.   0xe, "nz",
  592.   0xf, "nc",
  593.   0xf, "uge",
  594.   0, 0
  595. };
  596.  
  597. static void
  598. DEFUN (get_cc_operand, (ptr, mode, dst),
  599.        char **ptr AND
  600.        struct z8k_op *mode AND
  601.        unsigned int dst)
  602. {
  603.   char *src = *ptr;
  604.   int r;
  605.   int i;
  606.  
  607.   while (*src == ' ')
  608.     src++;
  609.  
  610.   mode->mode = CLASS_CC;
  611.   for (i = 0; table[i].name; i++)
  612.     {
  613.       int j;
  614.  
  615.       for (j = 0; table[i].name[j]; j++)
  616.     {
  617.       if (table[i].name[j] != src[j])
  618.         goto fail;
  619.     }
  620.       the_cc = table[i].value;
  621.       *ptr = src + j;
  622.       return;
  623.     fail:;
  624.     }
  625.   the_cc = 0x8;
  626. }
  627.  
  628. static void
  629. get_operand (ptr, mode, dst)
  630.      char **ptr;
  631.      struct z8k_op *mode;
  632.      unsigned int dst;
  633. {
  634.   char *src = *ptr;
  635.   char *end;
  636.   unsigned int num;
  637.   unsigned int len;
  638.   unsigned int size;
  639.  
  640.   mode->mode = 0;
  641.  
  642.   while (*src == ' ')
  643.     src++;
  644.   if (*src == '#')
  645.     {
  646.       mode->mode = CLASS_IMM;
  647.       imm_operand = &(mode->exp);
  648.       src = parse_exp (src + 1, &(mode->exp));
  649.     }
  650.   else if (*src == '@')
  651.     {
  652.       int d;
  653.  
  654.       mode->mode = CLASS_IR;
  655.       src = parse_reg (src + 1, &d, &mode->reg);
  656.     }
  657.   else
  658.     {
  659.       int regn;
  660.  
  661.       end = parse_reg (src, &mode->mode, ®n);
  662.  
  663.       if (end)
  664.     {
  665.       int nw, nr;
  666.  
  667.       src = end;
  668.       if (*src == '(')
  669.         {
  670.           src++;
  671.           end = parse_reg (src, &nw, &nr);
  672.           if (end)
  673.         {
  674.           /* Got Ra(Rb) */
  675.           src = end;
  676.  
  677.           if (*src != ')')
  678.             {
  679.               as_bad ("Missing ) in ra(rb)");
  680.             }
  681.           else
  682.             {
  683.               src++;
  684.             }
  685.  
  686.           regaddr (mode->mode, "ra(rb) ra");
  687. /*          regword (mode->mode, "ra(rb) rb");*/
  688.           mode->mode = CLASS_BX;
  689.           mode->reg = regn;
  690.           mode->x_reg = nr;
  691.           reg[ARG_RX] = nr;
  692.         }
  693.           else
  694.         {
  695.           /* Got Ra(disp) */
  696.           if (*src == '#')
  697.             src++;
  698.           src = parse_exp (src, &(mode->exp));
  699.           src = checkfor (src, ')');
  700.           mode->mode = CLASS_BA;
  701.           mode->reg = regn;
  702.           mode->x_reg = 0;
  703.           imm_operand = &(mode->exp);
  704.         }
  705.         }
  706.       else
  707.         {
  708.           mode->reg = regn;
  709.           mode->x_reg = 0;
  710.         }
  711.     }
  712.       else
  713.     {
  714.       /* No initial reg */
  715.       src = parse_exp (src, &(mode->exp));
  716.       if (*src == '(')
  717.         {
  718.           src++;
  719.           end = parse_reg (src, &(mode->mode), ®n);
  720.           regword (mode->mode, "addr(Ra) ra");
  721.           mode->mode = CLASS_X;
  722.           mode->reg = regn;
  723.           mode->x_reg = 0;
  724.           da_operand = &(mode->exp);
  725.           src = checkfor (end, ')');
  726.         }
  727.       else
  728.         {
  729.           /* Just an address */
  730.           mode->mode = CLASS_DA;
  731.           mode->reg = 0;
  732.           mode->x_reg = 0;
  733.           da_operand = &(mode->exp);
  734.         }
  735.     }
  736.     }
  737.   *ptr = src;
  738. }
  739.  
  740. static
  741. char *
  742. get_operands (opcode, op_end, operand)
  743.      opcode_entry_type *opcode;
  744.      char *op_end;
  745.      op_type *operand;
  746. {
  747.   char *ptr = op_end;
  748. char *savptr;
  749.   switch (opcode->noperands)
  750.     {
  751.     case 0:
  752.       operand[0].mode = 0;
  753.       operand[1].mode = 0;
  754.       break;
  755.  
  756.     case 1:
  757.       ptr++;
  758.       if (opcode->arg_info[0] == CLASS_CC)
  759.         {
  760.           get_cc_operand (&ptr, operand + 0, 0);
  761.         }
  762.       else if (opcode->arg_info[0] == CLASS_FLAGS)
  763.         {
  764.           get_flags_operand (&ptr, operand + 0, 0);
  765.         }
  766.       else if (opcode->arg_info[0] == (CLASS_IMM +(ARG_IMM2)))
  767.         {
  768.           get_interrupt_operand (&ptr, operand + 0, 0);
  769.         }
  770.       else
  771.         {
  772.           get_operand (&ptr, operand + 0, 0);
  773.         }
  774.       operand[1].mode = 0;
  775.       break;
  776.  
  777.     case 2:
  778.       ptr++;
  779.       savptr = ptr;
  780.       if (opcode->arg_info[0] == CLASS_CC)
  781.         {
  782.           get_cc_operand (&ptr, operand + 0, 0);
  783.         }
  784.       else if (opcode->arg_info[0] == CLASS_CTRL)
  785.              {
  786.                get_ctrl_operand (&ptr, operand + 0, 0);
  787.                if (the_ctrl == 0)
  788.                  {
  789.                    ptr = savptr;
  790.                    get_operand (&ptr, operand + 0, 0);
  791.                    if (ptr == 0)
  792.                      return;
  793.                    if (*ptr == ',')
  794.                      ptr++;
  795.                    get_ctrl_operand (&ptr, operand + 1, 1);
  796.                    return ptr;
  797.                  }
  798.              }
  799.       else
  800.         {
  801.           get_operand (&ptr, operand + 0, 0);
  802.         }
  803.       if (ptr == 0)
  804.         return;
  805.       if (*ptr == ',')
  806.         ptr++;
  807.       get_operand (&ptr, operand + 1, 1);
  808.       break;
  809.  
  810.     case 3:
  811.       ptr++;
  812.       get_operand (&ptr, operand + 0, 0);
  813.       if (*ptr == ',')
  814.     ptr++;
  815.       get_operand (&ptr, operand + 1, 1);
  816.       if (*ptr == ',')
  817.     ptr++;
  818.       get_operand (&ptr, operand + 2, 2);
  819.       break;
  820.  
  821.     case 4:
  822.       ptr++;
  823.       get_operand (&ptr, operand + 0, 0);
  824.       if (*ptr == ',')
  825.     ptr++;
  826.       get_operand (&ptr, operand + 1, 1);
  827.       if (*ptr == ',')
  828.     ptr++;
  829.       get_operand (&ptr, operand + 2, 2);
  830.       if (*ptr == ',')
  831.     ptr++;
  832.       get_cc_operand (&ptr, operand + 3, 3);
  833.       break;
  834.     default:
  835.       abort ();
  836.     }
  837.  
  838.   return ptr;
  839. }
  840.  
  841. /* Passed a pointer to a list of opcodes which use different
  842.    addressing modes, return the opcode which matches the opcodes
  843.    provided
  844.    */
  845.  
  846. static
  847. opcode_entry_type *
  848. DEFUN (get_specific, (opcode, operands),
  849.        opcode_entry_type * opcode AND
  850.        op_type * operands)
  851.  
  852. {
  853.   opcode_entry_type *this_try = opcode;
  854.   int found = 0;
  855.   unsigned int noperands = opcode->noperands;
  856.  
  857.   unsigned int dispreg;
  858.   unsigned int this_index = opcode->idx;
  859.  
  860.   while (this_index == opcode->idx && !found)
  861.     {
  862.       unsigned int i;
  863.  
  864.       this_try = opcode++;
  865.       for (i = 0; i < noperands; i++)
  866.     {
  867.       int mode = operands[i].mode;
  868.  
  869.       if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
  870.         {
  871.           /* it could be an pc rel operand, if this is a da mode and
  872.        we like disps, then insert it */
  873.  
  874.           if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
  875.         {
  876.           /* This is the case */
  877.           operands[i].mode = CLASS_DISP;
  878.         }
  879.           else if (mode == CLASS_BA && this_try->arg_info[i])
  880.         {
  881.           /* Can't think of a way to turn what we've been given into
  882.          something that's ok */
  883.           goto fail;
  884.         }
  885.           else if (this_try->arg_info[i] & CLASS_PR)
  886.         {
  887.           if (mode == CLASS_REG_LONG && segmented_mode)
  888.             {
  889.               /* ok */
  890.             }
  891.           else if (mode == CLASS_REG_WORD && !segmented_mode)
  892.             {
  893.               /* ok */
  894.             }
  895.           else
  896.             goto fail;
  897.         }
  898.           else
  899.         goto fail;
  900.         }
  901.       switch (mode & CLASS_MASK)
  902.         {
  903.         default:
  904.           break;
  905.         case CLASS_X:
  906.         case CLASS_IR:
  907.         case CLASS_BA:
  908.         case CLASS_BX:
  909.         case CLASS_DISP:
  910.         case CLASS_REG:
  911.         case CLASS_REG_WORD:
  912.         case CLASS_REG_BYTE:
  913.         case CLASS_REG_QUAD:
  914.         case CLASS_REG_LONG:
  915.         case CLASS_REGN0:
  916.           reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
  917.           break;
  918.         }
  919.     }
  920.  
  921.       found = 1;
  922.     fail:;
  923.     }
  924.   if (found)
  925.     return this_try;
  926.   else
  927.     return 0;
  928. }
  929.  
  930. static void
  931. DEFUN (check_operand, (operand, width, string),
  932.        struct z8k_op *operand AND
  933.        unsigned int width AND
  934.        char *string)
  935. {
  936.   if (operand->exp.X_add_symbol == 0
  937.       && operand->exp.X_op_symbol == 0)
  938.     {
  939.  
  940.       /* No symbol involved, let's look at offset, it's dangerous if any of
  941.        the high bits are not 0 or ff's, find out by oring or anding with
  942.        the width and seeing if the answer is 0 or all fs*/
  943.       if ((operand->exp.X_add_number & ~width) != 0 &&
  944.       (operand->exp.X_add_number | width) != (~0))
  945.     {
  946.       as_warn ("operand %s0x%x out of range.", string, operand->exp.X_add_number);
  947.     }
  948.     }
  949.  
  950. }
  951.  
  952. static char buffer[20];
  953.  
  954. static void
  955. DEFUN (newfix, (ptr, type, operand),
  956.        int ptr AND
  957.        int type AND
  958.        expressionS * operand)
  959. {
  960.   if (operand->X_add_symbol
  961.       || operand->X_op_symbol
  962.       || operand->X_add_number)
  963.     {
  964.       fix_new_exp (frag_now,
  965.            ptr,
  966.            1,
  967.            operand,
  968.            0,
  969.            type);
  970.     }
  971. }
  972.  
  973. static char *
  974. DEFUN (apply_fix, (ptr, type, operand, size),
  975.        char *ptr AND
  976.        int type AND
  977.        expressionS * operand AND
  978.        int size)
  979. {
  980.   int n = operand->X_add_number;
  981.  
  982.   operand->X_add_number = n;
  983.   newfix ((ptr - buffer) / 2, type, operand);
  984. #if 1
  985.   switch (size)
  986.     {
  987.     case 8:            /* 8 nibbles == 32 bits */
  988.       *ptr++ = n >> 28;
  989.       *ptr++ = n >> 24;
  990.       *ptr++ = n >> 20;
  991.       *ptr++ = n >> 16;
  992.     case 4:            /* 4 niblles == 16 bits */
  993.       *ptr++ = n >> 12;
  994.       *ptr++ = n >> 8;
  995.     case 2:
  996.       *ptr++ = n >> 4;
  997.     case 1:
  998.       *ptr++ = n >> 0;
  999.       break;
  1000.     }
  1001. #endif
  1002.   return ptr;
  1003.  
  1004. }
  1005.  
  1006. /* Now we know what sort of opcodes it is, lets build the bytes -
  1007.  */
  1008. #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
  1009. static void
  1010. build_bytes (this_try, operand)
  1011.      opcode_entry_type * this_try;
  1012.      struct z8k_op *operand;
  1013. {
  1014.   unsigned int i;
  1015.  
  1016.   int length;
  1017.   char *output;
  1018.   char *output_ptr = buffer;
  1019.   char part;
  1020.   int c;
  1021.   char high;
  1022.   int nib;
  1023.   int nibble;
  1024.   unsigned int *class_ptr;
  1025.  
  1026.   frag_wane (frag_now);
  1027.   frag_new (0);
  1028.  
  1029.   memset (buffer, 20, 0);
  1030.   class_ptr = this_try->byte_info;
  1031. top:;
  1032.  
  1033.   for (nibble = 0; c = *class_ptr++; nibble++)
  1034.     {
  1035.  
  1036.       switch (c & CLASS_MASK)
  1037.     {
  1038.     default:
  1039.  
  1040.       abort ();
  1041.     case CLASS_ADDRESS:
  1042.       /* Direct address, we don't cope with the SS mode right now */
  1043.       if (segmented_mode)
  1044.         {
  1045.           da_operand->X_add_number |= 0x80000000;
  1046.           output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8);
  1047.         }
  1048.       else
  1049.         {
  1050.           output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
  1051.         }
  1052.       da_operand = 0;
  1053.       break;
  1054.     case CLASS_DISP8:
  1055.       /* pc rel 8 bit */
  1056.       output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
  1057.       da_operand = 0;
  1058.       break;
  1059.  
  1060.     case CLASS_0DISP7:
  1061.       /* pc rel 7 bit */
  1062.       *output_ptr = 0;
  1063.       output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
  1064.       da_operand = 0;
  1065.       break;
  1066.  
  1067.     case CLASS_1DISP7:
  1068.       /* pc rel 7 bit */
  1069.       *output_ptr = 0x80;
  1070.       output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
  1071.           output_ptr[-2] =  0x8;
  1072.       da_operand = 0;
  1073.       break;
  1074.  
  1075.     case CLASS_BIT_1OR2:
  1076.       *output_ptr = c & 0xf;
  1077.       if (imm_operand)
  1078.         {
  1079.           if (imm_operand->X_add_number == 2)
  1080.         {
  1081.           *output_ptr |= 2;
  1082.         }
  1083.           else if (imm_operand->X_add_number != 1)
  1084.         {
  1085.           as_bad ("immediate must be 1 or 2");
  1086.         }
  1087.         }
  1088.       else
  1089.         {
  1090.           as_bad ("immediate 1 or 2 expected");
  1091.         }
  1092.       output_ptr++;
  1093.       break;
  1094.     case CLASS_CC:
  1095.       *output_ptr++ = the_cc;
  1096.       break;
  1097.         case CLASS_0CCC:
  1098.           *output_ptr++ = the_ctrl;
  1099.           break;
  1100.         case CLASS_1CCC:
  1101.           *output_ptr++ = the_ctrl | 0x8;
  1102.           break;
  1103.         case CLASS_00II:
  1104.           *output_ptr++ = (~the_interrupt & 0x3);
  1105.           break;
  1106.         case CLASS_01II:
  1107.           *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
  1108.           break;
  1109.         case CLASS_FLAGS:
  1110.           *output_ptr++ = the_flags;
  1111.           break;
  1112.     case CLASS_BIT:
  1113.       *output_ptr++ = c & 0xf;
  1114.       break;
  1115.     case CLASS_REGN0:
  1116.       if (reg[c & 0xf] == 0)
  1117.         {
  1118.           as_bad ("can't use R0 here");
  1119.         }
  1120.     case CLASS_REG:
  1121.     case CLASS_REG_BYTE:
  1122.     case CLASS_REG_WORD:
  1123.     case CLASS_REG_LONG:
  1124.     case CLASS_REG_QUAD:
  1125.       /* Insert bit mattern of
  1126.      right reg */
  1127.       *output_ptr++ = reg[c & 0xf];
  1128.       break;
  1129.     case CLASS_DISP:
  1130.       output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
  1131.       da_operand = 0;
  1132.       break;
  1133.  
  1134.     case CLASS_IMM:
  1135.       {
  1136.         nib = 0;
  1137.         switch (c & ARG_MASK)
  1138.           {
  1139.           case ARG_IMM4:
  1140.         output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
  1141.         break;
  1142.           case ARG_IMM4M1:
  1143.         imm_operand->X_add_number--;
  1144.         output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
  1145.         break;
  1146.           case ARG_IMMNMINUS1:
  1147.         imm_operand->X_add_number--;
  1148.         output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
  1149.         break;
  1150.           case ARG_NIM8:
  1151.         imm_operand->X_add_number = -imm_operand->X_add_number;
  1152.           case ARG_IMM8:
  1153.         output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2);
  1154.         break;
  1155.           case ARG_IMM16:
  1156.         output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4);
  1157.         break;
  1158.  
  1159.           case ARG_IMM32:
  1160.         output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8);
  1161.         break;
  1162.  
  1163.           default:
  1164.         abort ();
  1165.           }
  1166.       }
  1167.     }
  1168.     }
  1169.  
  1170.   /* Copy from the nibble buffer into the frag */
  1171.  
  1172.   {
  1173.     int length = (output_ptr - buffer) / 2;
  1174.     char *src = buffer;
  1175.     char *fragp = frag_more (length);
  1176.  
  1177.     while (src < output_ptr)
  1178.       {
  1179.     *fragp = (src[0] << 4) | src[1];
  1180.     src += 2;
  1181.     fragp++;
  1182.       }
  1183.  
  1184.   }
  1185.  
  1186. }
  1187.  
  1188. /* This is the guts of the machine-dependent assembler.  STR points to a
  1189.    machine dependent instruction.  This funciton is supposed to emit
  1190.    the frags/bytes it assembles to.
  1191.    */
  1192.  
  1193. void
  1194. DEFUN (md_assemble, (str),
  1195.        char *str)
  1196. {
  1197.   char *op_start;
  1198.   char *op_end;
  1199.   unsigned int i;
  1200.   struct z8k_op operand[3];
  1201.   opcode_entry_type *opcode;
  1202.   opcode_entry_type *prev_opcode;
  1203.  
  1204.   char *dot = 0;
  1205.   char c;
  1206.  
  1207.   /* Drop leading whitespace */
  1208.   while (*str == ' ')
  1209.     str++;
  1210.  
  1211.   /* find the op code end */
  1212.   for (op_start = op_end = str;
  1213.        *op_end != 0 && *op_end != ' ';
  1214.        op_end++)
  1215.     {
  1216.     }
  1217.  
  1218.   ;
  1219.  
  1220.   if (op_end == op_start)
  1221.     {
  1222.       as_bad ("can't find opcode ");
  1223.     }
  1224.   c = *op_end;
  1225.  
  1226.   *op_end = 0;
  1227.  
  1228.   opcode = (opcode_entry_type *) hash_find (opcode_hash_control,
  1229.                         op_start);
  1230.  
  1231.  
  1232.   if (opcode == NULL)
  1233.     {
  1234.       as_bad ("unknown opcode");
  1235.       return;
  1236.     }
  1237.  
  1238.   if (opcode->opcode == 250)
  1239.     {
  1240.       /* was really a pseudo op */
  1241.  
  1242.       pseudo_typeS *p;
  1243.       char oc;
  1244.  
  1245.       char *old = input_line_pointer;
  1246.       *op_end = c;
  1247.  
  1248.  
  1249.       input_line_pointer = op_end;
  1250.  
  1251.       oc = *old;
  1252.       *old = '\n';
  1253.       while (*input_line_pointer == ' ')
  1254.     input_line_pointer++;
  1255.       p = (pseudo_typeS *) (opcode->func);
  1256.  
  1257.       (p->poc_handler) (p->poc_val);
  1258.       input_line_pointer = old;
  1259.       *old = oc;
  1260.     }
  1261.   else
  1262.     {
  1263.       input_line_pointer = get_operands (opcode, op_end,
  1264.                      operand);
  1265.       prev_opcode = opcode;
  1266.  
  1267.       opcode = get_specific (opcode, operand);
  1268.  
  1269.       if (opcode == 0)
  1270.     {
  1271.       /* Couldn't find an opcode which matched the operands */
  1272.       char *where = frag_more (2);
  1273.  
  1274.       where[0] = 0x0;
  1275.       where[1] = 0x0;
  1276.  
  1277.       as_bad ("Can't find opcode to match operands");
  1278.       return;
  1279.     }
  1280.  
  1281.       build_bytes (opcode, operand);
  1282.     }
  1283. }
  1284.  
  1285. void
  1286. DEFUN (tc_crawl_symbol_chain, (headers),
  1287.        object_headers * headers)
  1288. {
  1289.   printf ("call to tc_crawl_symbol_chain \n");
  1290. }
  1291.  
  1292. symbolS *
  1293. DEFUN (md_undefined_symbol, (name),
  1294.        char *name)
  1295. {
  1296.   return 0;
  1297. }
  1298.  
  1299. void
  1300. DEFUN (tc_headers_hook, (headers),
  1301.        object_headers * headers)
  1302. {
  1303.   printf ("call to tc_headers_hook \n");
  1304. }
  1305.  
  1306. /* Various routines to kill one day */
  1307. /* Equal to MAX_PRECISION in atof-ieee.c */
  1308. #define MAX_LITTLENUMS 6
  1309.  
  1310. /* Turn a string in input_line_pointer into a floating point constant of type
  1311.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  1312.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  1313.    */
  1314. char *
  1315. md_atof (type, litP, sizeP)
  1316.      char type;
  1317.      char *litP;
  1318.      int *sizeP;
  1319. {
  1320.   int prec;
  1321.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1322.   LITTLENUM_TYPE *wordP;
  1323.   char *t;
  1324.   char *atof_ieee ();
  1325.  
  1326.   switch (type)
  1327.     {
  1328.     case 'f':
  1329.     case 'F':
  1330.     case 's':
  1331.     case 'S':
  1332.       prec = 2;
  1333.       break;
  1334.  
  1335.     case 'd':
  1336.     case 'D':
  1337.     case 'r':
  1338.     case 'R':
  1339.       prec = 4;
  1340.       break;
  1341.  
  1342.     case 'x':
  1343.     case 'X':
  1344.       prec = 6;
  1345.       break;
  1346.  
  1347.     case 'p':
  1348.     case 'P':
  1349.       prec = 6;
  1350.       break;
  1351.  
  1352.     default:
  1353.       *sizeP = 0;
  1354.       return "Bad call to MD_ATOF()";
  1355.     }
  1356.   t = atof_ieee (input_line_pointer, type, words);
  1357.   if (t)
  1358.     input_line_pointer = t;
  1359.  
  1360.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  1361.   for (wordP = words; prec--;)
  1362.     {
  1363.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  1364.       litP += sizeof (LITTLENUM_TYPE);
  1365.     }
  1366.   return 0;
  1367. }
  1368.  
  1369. CONST char *md_shortopts = "z:";
  1370. struct option md_longopts[] = {
  1371.   {NULL, no_argument, NULL, 0}
  1372. };
  1373. size_t md_longopts_size = sizeof(md_longopts);
  1374.  
  1375. int
  1376. md_parse_option (c, arg)
  1377.      int c;
  1378.      char *arg;
  1379. {
  1380.   switch (c)
  1381.     {
  1382.     case 'z':
  1383.       if (!strcmp (arg, "8001"))
  1384.     s_segm ();
  1385.       else if (!strcmp (arg, "8002"))
  1386.     s_unseg ();
  1387.       else
  1388.     {
  1389.       as_bad ("invalid architecture -z%s", arg);
  1390.       return 0;
  1391.     }
  1392.       break;
  1393.  
  1394.     default:
  1395.       return 0;
  1396.     }
  1397.  
  1398.   return 1;
  1399. }
  1400.  
  1401. void
  1402. md_show_usage (stream)
  1403.      FILE *stream;
  1404. {
  1405.   fprintf(stream, "\
  1406. Z8K options:\n\
  1407. -z8001            generate segmented code\n\
  1408. -z8002            generate unsegmented code\n");
  1409. }
  1410.  
  1411. int md_short_jump_size;
  1412.  
  1413. void
  1414. tc_aout_fix_to_chars ()
  1415. {
  1416.   printf ("call to tc_aout_fix_to_chars \n");
  1417.   abort ();
  1418. }
  1419.  
  1420. void
  1421. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1422.      char *ptr;
  1423.      addressT from_addr;
  1424.      addressT to_addr;
  1425.      fragS *frag;
  1426.      symbolS *to_symbol;
  1427. {
  1428.   as_fatal ("failed sanity check.");
  1429. }
  1430.  
  1431. void
  1432. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1433.      char *ptr;
  1434.      addressT from_addr, to_addr;
  1435.      fragS *frag;
  1436.      symbolS *to_symbol;
  1437. {
  1438.   as_fatal ("failed sanity check.");
  1439. }
  1440.  
  1441. void
  1442. md_convert_frag (headers, seg, fragP)
  1443.      object_headers *headers;
  1444.      segT seg;
  1445.      fragS *fragP;
  1446. {
  1447.   printf ("call to md_convert_frag \n");
  1448.   abort ();
  1449. }
  1450.  
  1451. valueT
  1452. DEFUN (md_section_align, (seg, size),
  1453.        segT seg AND
  1454.        valueT size)
  1455. {
  1456.   return ((size + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
  1457.  
  1458. }
  1459.  
  1460. void
  1461. md_apply_fix (fixP, val)
  1462.      fixS *fixP;
  1463.      long val;
  1464. {
  1465.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  1466.  
  1467.   switch (fixP->fx_r_type)
  1468.     {
  1469.     case R_IMM4L:
  1470.       buf[0] = (buf[0] & 0xf0) | ((buf[0] + val) & 0xf);
  1471.       break;
  1472.  
  1473.     case R_JR:
  1474.  
  1475.       *buf++ = val;
  1476.       /*    if (val != 0) abort();*/
  1477.       break;
  1478.  
  1479.     case R_DISP7:
  1480.  
  1481.       *buf++ += val;
  1482.       /*    if (val != 0) abort();*/
  1483.       break;
  1484.  
  1485.     case R_IMM8:
  1486.       buf[0] += val;
  1487.       break;
  1488.     case R_IMM16:
  1489.       *buf++ = (val >> 8);
  1490.       *buf++ = val;
  1491.       break;
  1492.     case R_IMM32:
  1493.       *buf++ = (val >> 24);
  1494.       *buf++ = (val >> 16);
  1495.       *buf++ = (val >> 8);
  1496.       *buf++ = val;
  1497.       break;
  1498. #if 0
  1499.     case R_DA | R_SEG:
  1500.       *buf++ = (val >> 16);
  1501.       *buf++ = 0x00;
  1502.       *buf++ = (val >> 8);
  1503.       *buf++ = val;
  1504.       break;
  1505. #endif
  1506.  
  1507.     case 0:
  1508.       md_number_to_chars (buf, val, fixP->fx_size);
  1509.       break;
  1510.  
  1511.     default:
  1512.       abort ();
  1513.  
  1514.     }
  1515. }
  1516.  
  1517. int md_long_jump_size;
  1518. int
  1519. md_estimate_size_before_relax (fragP, segment_type)
  1520.      register fragS *fragP;
  1521.      register segT segment_type;
  1522. {
  1523.   printf ("call tomd_estimate_size_before_relax \n");
  1524.   abort ();
  1525. }
  1526.  
  1527. /* Put number into target byte order */
  1528.  
  1529. void
  1530. DEFUN (md_number_to_chars, (ptr, use, nbytes),
  1531.        char *ptr AND
  1532.        valueT use AND
  1533.        int nbytes)
  1534. {
  1535.   number_to_chars_bigendian (ptr, use, nbytes);
  1536. }
  1537. long
  1538. md_pcrel_from (fixP)
  1539.      fixS *fixP;
  1540. {
  1541.   abort ();
  1542. }
  1543.  
  1544. void
  1545. tc_coff_symbol_emit_hook (s)
  1546.      struct symbol *s;
  1547. {
  1548. }
  1549.  
  1550. void
  1551. tc_reloc_mangle (fix_ptr, intr, base)
  1552.      fixS *fix_ptr;
  1553.      struct internal_reloc *intr;
  1554.      bfd_vma base;
  1555.  
  1556. {
  1557.   symbolS *symbol_ptr;
  1558.  
  1559.   if (fix_ptr->fx_addsy &&
  1560.       fix_ptr->fx_subsy) 
  1561.     {
  1562.       symbolS *add = fix_ptr->fx_addsy;
  1563.       symbolS *sub = fix_ptr->fx_subsy;
  1564.       if (S_GET_SEGMENT(add) != S_GET_SEGMENT(sub))
  1565.     {
  1566.       as_bad("Can't subtract symbols in different sections %s %s",
  1567.          S_GET_NAME(add), S_GET_NAME(sub));
  1568.     }
  1569.       else {
  1570.     int diff = S_GET_VALUE(add) - S_GET_VALUE(sub);
  1571.     fix_ptr->fx_addsy = 0;
  1572.     fix_ptr->fx_subsy = 0;
  1573.     fix_ptr->fx_offset += diff;
  1574.       }
  1575.     }
  1576.   symbol_ptr = fix_ptr->fx_addsy;
  1577.  
  1578.   /* If this relocation is attached to a symbol then it's ok
  1579.      to output it */
  1580.   if (fix_ptr->fx_r_type == 0)
  1581.     {
  1582.       /* cons likes to create reloc32's whatever the size of the reloc.. */
  1583.       switch (fix_ptr->fx_size)
  1584.     {
  1585.     case 2:
  1586.       intr->r_type = R_IMM16;
  1587.       break;
  1588.     case 1:
  1589.       intr->r_type = R_IMM8;
  1590.       break;
  1591.     case 4:
  1592.       intr->r_type = R_IMM32;
  1593.       break;
  1594.     default:
  1595.       abort ();
  1596.     }
  1597.  
  1598.     }
  1599.   else
  1600.     {
  1601.       intr->r_type = fix_ptr->fx_r_type;
  1602.     }
  1603.  
  1604.   intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
  1605.   intr->r_offset = fix_ptr->fx_offset;
  1606.  
  1607.   if (symbol_ptr)
  1608.     intr->r_symndx = symbol_ptr->sy_number;
  1609.   else
  1610.     intr->r_symndx = -1;
  1611. }
  1612.  
  1613.