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

  1. /* tc-i860.c -- Assemble for the I860
  2.    Copyright (C) 1989, 1992, 1993 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
  18.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. #include "as.h"
  21.  
  22. #include "opcode/i860.h"
  23.  
  24. void md_begin ();
  25. void md_number_to_chars ();
  26. void md_assemble ();
  27. char *md_atof ();
  28. void md_convert_frag ();
  29. void md_create_short_jump ();
  30. void md_create_long_jump ();
  31. int md_estimate_size_before_relax ();
  32. void md_number_to_imm ();
  33. void md_number_to_disp ();
  34. void md_number_to_field ();
  35. void md_ri_to_chars ();
  36. static void i860_ip ();
  37. /* void emit_machine_reloc(); */
  38.  
  39. const int md_reloc_size = sizeof (struct relocation_info);
  40.  
  41. /* void (*md_emit_relocations)() = emit_machine_reloc; */
  42.  
  43. /* handle of the OPCODE hash table */
  44. static struct hash_control *op_hash = NULL;
  45.  
  46. static void s_dual (), s_enddual ();
  47. static void s_atmp ();
  48.  
  49. const pseudo_typeS
  50.   md_pseudo_table[] =
  51. {
  52.   {"dual", s_dual, 4},
  53.   {"enddual", s_enddual, 4},
  54.   {"atmp", s_atmp, 4},
  55.   {NULL, 0, 0},
  56. };
  57.  
  58. int md_short_jump_size = 4;
  59. int md_long_jump_size = 4;
  60.  
  61. /* This array holds the chars that always start a comment.  If the
  62.    pre-processor is disabled, these aren't very useful */
  63. const char comment_chars[] = "!/";    /* JF removed '|' from comment_chars */
  64.  
  65. /* This array holds the chars that only start a comment at the beginning of
  66.    a line.  If the line seems to have the form '# 123 filename'
  67.    .line and .file directives will appear in the pre-processed output */
  68. /* Note that input_file.c hand checks for '#' at the beginning of the
  69.    first line of the input file.  This is because the compiler outputs
  70.    #NO_APP at the beginning of its output. */
  71. /* Also note that comments like this one will always work. */
  72. const char line_comment_chars[] = "#/";
  73.  
  74. const char line_separator_chars[] = "";
  75.  
  76. /* Chars that can be used to separate mant from exp in floating point nums */
  77. const char EXP_CHARS[] = "eE";
  78.  
  79. /* Chars that mean this number is a floating point constant */
  80. /* As in 0f12.456 */
  81. /* or    0d1.2345e12 */
  82. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  83.  
  84. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  85.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  86.    but nothing is ideal around here.
  87.    */
  88. int size_reloc_info = sizeof (struct relocation_info);
  89.  
  90. static unsigned char octal[256];
  91. #define isoctal(c)  octal[c]
  92. static unsigned char toHex[256];
  93.  
  94. struct i860_it
  95.   {
  96.     char *error;
  97.     unsigned long opcode;
  98.     struct nlist *nlistp;
  99.     expressionS exp;
  100.     int pcrel;
  101.     enum expand_type expand;
  102.     enum highlow_type highlow;
  103.     enum reloc_type reloc;
  104.   } the_insn;
  105.  
  106. #if __STDC__ == 1
  107.  
  108. static void print_insn (struct i860_it *insn);
  109. static int getExpression (char *str);
  110.  
  111. #else /* not __STDC__ */
  112.  
  113. static void print_insn ();
  114. static int getExpression ();
  115.  
  116. #endif /* not __STDC__ */
  117.  
  118. static char *expr_end;
  119. static char last_expand;    /* error if expansion after branch */
  120.  
  121. enum dual
  122. {
  123.   DUAL_OFF = 0, DUAL_ON, DUAL_DDOT, DUAL_ONDDOT,
  124. };
  125. static enum dual dual_mode = DUAL_OFF;    /* dual-instruction mode */
  126.  
  127. static void
  128. s_dual ()            /* floating point instructions have dual set */
  129. {
  130.   dual_mode = DUAL_ON;
  131. }
  132.  
  133. static void
  134. s_enddual ()            /* floating point instructions have dual set */
  135. {
  136.   dual_mode = DUAL_OFF;
  137. }
  138.  
  139. static int atmp = 31;        /* temporary register for pseudo's */
  140.  
  141. static void
  142. s_atmp ()
  143. {
  144.   register int temp;
  145.   if (strncmp (input_line_pointer, "sp", 2) == 0)
  146.     {
  147.       input_line_pointer += 2;
  148.       atmp = 2;
  149.     }
  150.   else if (strncmp (input_line_pointer, "fp", 2) == 0)
  151.     {
  152.       input_line_pointer += 2;
  153.       atmp = 3;
  154.     }
  155.   else if (strncmp (input_line_pointer, "r", 1) == 0)
  156.     {
  157.       input_line_pointer += 1;
  158.       temp = get_absolute_expression ();
  159.       if (temp >= 0 && temp <= 31)
  160.     atmp = temp;
  161.       else
  162.     as_bad ("Unknown temporary pseudo register");
  163.     }
  164.   else
  165.     {
  166.       as_bad ("Unknown temporary pseudo register");
  167.     }
  168.   demand_empty_rest_of_line ();
  169. }
  170.  
  171. /* This function is called once, at assembler startup time.  It should
  172.    set up all the tables, etc. that the MD part of the assembler will need.  */
  173. void
  174. md_begin ()
  175. {
  176.   register char *retval = NULL;
  177.   int lose = 0;
  178.   register unsigned int i = 0;
  179.  
  180.   op_hash = hash_new ();
  181.  
  182.   while (i < NUMOPCODES)
  183.     {
  184.       const char *name = i860_opcodes[i].name;
  185.       retval = hash_insert (op_hash, name, &i860_opcodes[i]);
  186.       if (retval != NULL)
  187.     {
  188.       fprintf (stderr, "internal error: can't hash `%s': %s\n",
  189.            i860_opcodes[i].name, retval);
  190.       lose = 1;
  191.     }
  192.       do
  193.     {
  194.       if (i860_opcodes[i].match & i860_opcodes[i].lose)
  195.         {
  196.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  197.                i860_opcodes[i].name, i860_opcodes[i].args);
  198.           lose = 1;
  199.         }
  200.       ++i;
  201.     }
  202.       while (i < NUMOPCODES
  203.          && !strcmp (i860_opcodes[i].name, name));
  204.     }
  205.  
  206.   if (lose)
  207.     as_fatal ("Broken assembler.  No assembly attempted.");
  208.  
  209.   for (i = '0'; i < '8'; ++i)
  210.     octal[i] = 1;
  211.   for (i = '0'; i <= '9'; ++i)
  212.     toHex[i] = i - '0';
  213.   for (i = 'a'; i <= 'f'; ++i)
  214.     toHex[i] = i + 10 - 'a';
  215.   for (i = 'A'; i <= 'F'; ++i)
  216.     toHex[i] = i + 10 - 'A';
  217. }
  218.  
  219. void
  220. md_assemble (str)
  221.      char *str;
  222. {
  223.   char *toP;
  224.   int rsd;
  225.   int no_opcodes = 1;
  226.   int i;
  227.   struct i860_it pseudo[3];
  228.  
  229.   assert (str);
  230.   i860_ip (str);
  231.  
  232.   /* check for expandable flag to produce pseudo-instructions */
  233.   if (the_insn.expand != 0 && the_insn.highlow == NO_SPEC)
  234.     {
  235.       for (i = 0; i < 3; i++)
  236.     pseudo[i] = the_insn;
  237.  
  238.       switch (the_insn.expand)
  239.     {
  240.  
  241.     case E_DELAY:
  242.       no_opcodes = 1;
  243.       break;
  244.  
  245.     case E_MOV:
  246.       if (the_insn.exp.X_add_symbol == NULL &&
  247.           the_insn.exp.X_op_symbol == NULL &&
  248.           (the_insn.exp.X_add_number < (1 << 15) &&
  249.            the_insn.exp.X_add_number >= -(1 << 15)))
  250.         break;
  251.       /* or l%const,r0,ireg_dest */
  252.       pseudo[0].opcode = (the_insn.opcode & 0x001f0000) | 0xe4000000;
  253.       pseudo[0].highlow = PAIR;
  254.       /* orh h%const,ireg_dest,ireg_dest */
  255.       pseudo[1].opcode = (the_insn.opcode & 0x03ffffff) | 0xec000000 |
  256.         ((the_insn.opcode & 0x001f0000) << 5);
  257.       pseudo[1].highlow = HIGH;
  258.       no_opcodes = 2;
  259.       break;
  260.  
  261.     case E_ADDR:
  262.       if (the_insn.exp.X_add_symbol == NULL &&
  263.           the_insn.exp.X_op_symbol == NULL)
  264.         break;
  265.       /* orh ha%addr_expr,r0,r31 */
  266.       pseudo[0].opcode = 0xec000000 | (atmp << 16);
  267.       pseudo[0].highlow = HIGHADJ;
  268.       pseudo[0].reloc = LOW0;    /* must overwrite */
  269.       /* l%addr_expr(r31),ireg_dest */
  270.       pseudo[1].opcode = (the_insn.opcode & ~0x003e0000) | (atmp << 21);
  271.       pseudo[1].highlow = PAIR;
  272.       no_opcodes = 2;
  273.       break;
  274.  
  275.     case E_U32:        /* 2nd version emulates Intel as, not doc. */
  276.       if (the_insn.exp.X_add_symbol == NULL &&
  277.           the_insn.exp.X_op_symbol == NULL &&
  278.           (the_insn.exp.X_add_number < (1 << 16) &&
  279.            the_insn.exp.X_add_number >= 0))
  280.         break;
  281.       /* $(opcode)h h%const,ireg_src2,ireg_dest
  282.                pseudo[0].opcode = (the_insn.opcode & 0xf3ffffff) | 0x0c000000; */
  283.       /* $(opcode)h h%const,ireg_src2,r31 */
  284.       pseudo[0].opcode = (the_insn.opcode & 0xf3e0ffff) | 0x0c000000 |
  285.         (atmp << 16);
  286.       pseudo[0].highlow = HIGH;
  287.       /* $(opcode) l%const,ireg_dest,ireg_dest
  288.                pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000 |
  289.                ((the_insn.opcode & 0x001f0000) << 5); */
  290.       /* $(opcode) l%const,r31,ireg_dest */
  291.       pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000 |
  292.         (atmp << 21);
  293.       pseudo[1].highlow = PAIR;
  294.       no_opcodes = 2;
  295.       break;
  296.  
  297.     case E_AND:        /* 2nd version emulates Intel as, not doc. */
  298.       if (the_insn.exp.X_add_symbol == NULL &&
  299.           the_insn.exp.X_op_symbol == NULL &&
  300.           (the_insn.exp.X_add_number < (1 << 16) &&
  301.            the_insn.exp.X_add_number >= 0))
  302.         break;
  303.       /* andnot h%const,ireg_src2,ireg_dest
  304.                pseudo[0].opcode = (the_insn.opcode & 0x03ffffff) | 0xd4000000; */
  305.       /* andnot h%const,ireg_src2,r31 */
  306.       pseudo[0].opcode = (the_insn.opcode & 0x03e0ffff) | 0xd4000000 |
  307.         (atmp << 16);
  308.       pseudo[0].highlow = HIGH;
  309.       pseudo[0].exp.X_add_number = -1 - the_insn.exp.X_add_number;
  310.       /* andnot l%const,ireg_dest,ireg_dest
  311.                pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000 |
  312.                ((the_insn.opcode & 0x001f0000) << 5); */
  313.       /* andnot l%const,r31,ireg_dest */
  314.       pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000 |
  315.         (atmp << 21);
  316.       pseudo[1].highlow = PAIR;
  317.       pseudo[1].exp.X_add_number = -1 - the_insn.exp.X_add_number;
  318.       no_opcodes = 2;
  319.       break;
  320.  
  321.     case E_S32:
  322.       if (the_insn.exp.X_add_symbol == NULL &&
  323.           the_insn.exp.X_op_symbol == NULL &&
  324.           (the_insn.exp.X_add_number < (1 << 15) &&
  325.            the_insn.exp.X_add_number >= -(1 << 15)))
  326.         break;
  327.       /* orh h%const,r0,r31 */
  328.       pseudo[0].opcode = 0xec000000 | (atmp << 16);
  329.       pseudo[0].highlow = HIGH;
  330.       /* or l%const,r31,r31 */
  331.       pseudo[1].opcode = 0xe4000000 | (atmp << 21) | (atmp << 16);
  332.       pseudo[1].highlow = PAIR;
  333.       /* r31,ireg_src2,ireg_dest */
  334.       pseudo[2].opcode = (the_insn.opcode & ~0x0400ffff) | (atmp << 11);
  335.       pseudo[2].reloc = NO_RELOC;
  336.       no_opcodes = 3;
  337.       break;
  338.  
  339.     default:
  340.       as_fatal ("failed sanity check.");
  341.     }
  342.  
  343.       the_insn = pseudo[0];
  344.       /* check for expanded opcode after branch or in dual */
  345.       if (no_opcodes > 1 && last_expand == 1)
  346.     as_warn ("Expanded opcode after delayed branch: `%s'", str);
  347.       if (no_opcodes > 1 && dual_mode != DUAL_OFF)
  348.     as_warn ("Expanded opcode in dual mode: `%s'", str);
  349.     }
  350.  
  351.   i = 0;
  352.   do
  353.     {                /* always produce at least one opcode */
  354.       toP = frag_more (4);
  355.       /* put out the opcode */
  356.       md_number_to_chars (toP, the_insn.opcode, 4);
  357.  
  358.       /* check for expanded opcode after branch or in dual */
  359.       last_expand = the_insn.pcrel;
  360.  
  361.       /* put out the symbol-dependent stuff */
  362.       if (the_insn.reloc != NO_RELOC)
  363.     {
  364.       fix_new (frag_now,    /* which frag */
  365.            (toP - frag_now->fr_literal),    /* where */
  366.            4,        /* size */
  367.            &the_insn.exp,
  368.            the_insn.pcrel,
  369.       /* merge bit fields into one argument */
  370.       (int) (((the_insn.highlow & 0x3) << 4) | (the_insn.reloc & 0xf)));
  371.     }
  372.       the_insn = pseudo[++i];
  373.     }
  374.   while (--no_opcodes > 0);
  375.  
  376. }
  377.  
  378. static void
  379. i860_ip (str)
  380.      char *str;
  381. {
  382.   char *s;
  383.   const char *args;
  384.   char c;
  385.   unsigned long i;
  386.   struct i860_opcode *insn;
  387.   char *argsStart;
  388.   unsigned long opcode;
  389.   unsigned int mask;
  390.   int match = 0;
  391.   int comma = 0;
  392.  
  393.  
  394.   for (s = str; islower (*s) || *s == '.' || *s == '3'; ++s)
  395.     ;
  396.   switch (*s)
  397.     {
  398.  
  399.     case '\0':
  400.       break;
  401.  
  402.     case ',':
  403.       comma = 1;
  404.  
  405.       /*FALLTHROUGH*/
  406.  
  407.     case ' ':
  408.       *s++ = '\0';
  409.       break;
  410.  
  411.     default:
  412.       as_fatal ("Unknown opcode: `%s'", str);
  413.     }
  414.  
  415.   if (strncmp (str, "d.", 2) == 0)
  416.     {                /* check for d. opcode prefix */
  417.       if (dual_mode == DUAL_ON)
  418.     dual_mode = DUAL_ONDDOT;
  419.       else
  420.     dual_mode = DUAL_DDOT;
  421.       str += 2;
  422.     }
  423.  
  424.   if ((insn = (struct i860_opcode *) hash_find (op_hash, str)) == NULL)
  425.     {
  426.       if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
  427.     str -= 2;
  428.       as_bad ("Unknown opcode: `%s'", str);
  429.       return;
  430.     }
  431.   if (comma)
  432.     {
  433.       *--s = ',';
  434.     }
  435.   argsStart = s;
  436.   for (;;)
  437.     {
  438.       opcode = insn->match;
  439.       memset (&the_insn, '\0', sizeof (the_insn));
  440.       the_insn.reloc = NO_RELOC;
  441.  
  442.       /*
  443.          * Build the opcode, checking as we go to make
  444.          * sure that the operands match
  445.          */
  446.       for (args = insn->args;; ++args)
  447.     {
  448.       switch (*args)
  449.         {
  450.  
  451.         case '\0':        /* end of args */
  452.           if (*s == '\0')
  453.         {
  454.           match = 1;
  455.         }
  456.           break;
  457.  
  458.         case '+':
  459.         case '(':        /* these must match exactly */
  460.         case ')':
  461.         case ',':
  462.         case ' ':
  463.           if (*s++ == *args)
  464.         continue;
  465.           break;
  466.  
  467.         case '#':        /* must be at least one digit */
  468.           if (isdigit (*s++))
  469.         {
  470.           while (isdigit (*s))
  471.             {
  472.               ++s;
  473.             }
  474.           continue;
  475.         }
  476.           break;
  477.  
  478.         case '1':        /* next operand must be a register */
  479.         case '2':
  480.         case 'd':
  481.           switch (*s)
  482.         {
  483.  
  484.         case 'f':    /* frame pointer */
  485.           s++;
  486.           if (*s++ == 'p')
  487.             {
  488.               mask = 0x3;
  489.               break;
  490.             }
  491.           goto error;
  492.  
  493.         case 's':    /* stack pointer */
  494.           s++;
  495.           if (*s++ == 'p')
  496.             {
  497.               mask = 0x2;
  498.               break;
  499.             }
  500.           goto error;
  501.  
  502.         case 'r':    /* any register */
  503.           s++;
  504.           if (!isdigit (c = *s++))
  505.             {
  506.               goto error;
  507.             }
  508.           if (isdigit (*s))
  509.             {
  510.               if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
  511.             {
  512.               goto error;
  513.             }
  514.             }
  515.           else
  516.             {
  517.               c -= '0';
  518.             }
  519.           mask = c;
  520.           break;
  521.  
  522.         default:    /* not this opcode */
  523.           goto error;
  524.         }
  525.           /*
  526.                  * Got the register, now figure out where
  527.                  * it goes in the opcode.
  528.                  */
  529.           switch (*args)
  530.         {
  531.  
  532.         case '1':
  533.           opcode |= mask << 11;
  534.           continue;
  535.  
  536.         case '2':
  537.           opcode |= mask << 21;
  538.           continue;
  539.  
  540.         case 'd':
  541.           opcode |= mask << 16;
  542.           continue;
  543.  
  544.         }
  545.           break;
  546.  
  547.         case 'e':        /* next operand is a floating point register */
  548.         case 'f':
  549.         case 'g':
  550.           if (*s++ == 'f' && isdigit (*s))
  551.         {
  552.           mask = *s++;
  553.           if (isdigit (*s))
  554.             {
  555.               mask = 10 * (mask - '0') + (*s++ - '0');
  556.               if (mask >= 32)
  557.             {
  558.               break;
  559.             }
  560.             }
  561.           else
  562.             {
  563.               mask -= '0';
  564.             }
  565.           switch (*args)
  566.             {
  567.  
  568.             case 'e':
  569.               opcode |= mask << 11;
  570.               continue;
  571.  
  572.             case 'f':
  573.               opcode |= mask << 21;
  574.               continue;
  575.  
  576.             case 'g':
  577.               opcode |= mask << 16;
  578.               if (dual_mode != DUAL_OFF)
  579.             opcode |= (1 << 9);    /* dual mode instruction */
  580.               if (dual_mode == DUAL_DDOT)
  581.             dual_mode = DUAL_OFF;
  582.               if (dual_mode == DUAL_ONDDOT)
  583.             dual_mode = DUAL_ON;
  584.               if ((opcode & (1 << 10)) && (mask == ((opcode >> 11) & 0x1f)))
  585.             as_warn ("Fsr1 equals fdest with Pipelining");
  586.               continue;
  587.             }
  588.         }
  589.           break;
  590.  
  591.         case 'c':        /* next operand must be a control register */
  592.           if (strncmp (s, "fir", 3) == 0)
  593.         {
  594.           opcode |= 0x0 << 21;
  595.           s += 3;
  596.           continue;
  597.         }
  598.           if (strncmp (s, "psr", 3) == 0)
  599.         {
  600.           opcode |= 0x1 << 21;
  601.           s += 3;
  602.           continue;
  603.         }
  604.           if (strncmp (s, "dirbase", 7) == 0)
  605.         {
  606.           opcode |= 0x2 << 21;
  607.           s += 7;
  608.           continue;
  609.         }
  610.           if (strncmp (s, "db", 2) == 0)
  611.         {
  612.           opcode |= 0x3 << 21;
  613.           s += 2;
  614.           continue;
  615.         }
  616.           if (strncmp (s, "fsr", 3) == 0)
  617.         {
  618.           opcode |= 0x4 << 21;
  619.           s += 3;
  620.           continue;
  621.         }
  622.           if (strncmp (s, "epsr", 4) == 0)
  623.         {
  624.           opcode |= 0x5 << 21;
  625.           s += 4;
  626.           continue;
  627.         }
  628.           break;
  629.  
  630.         case '5':        /* 5 bit immediate in src1 */
  631.           memset (&the_insn, '\0', sizeof (the_insn));
  632.           if (!getExpression (s))
  633.         {
  634.           s = expr_end;
  635.           if (the_insn.exp.X_add_number & ~0x1f)
  636.             as_bad ("5-bit immediate too large");
  637.           opcode |= (the_insn.exp.X_add_number & 0x1f) << 11;
  638.           memset (&the_insn, '\0', sizeof (the_insn));
  639.           the_insn.reloc = NO_RELOC;
  640.           continue;
  641.         }
  642.           break;
  643.  
  644.         case 'l':        /* 26 bit immediate, relative branch */
  645.           the_insn.reloc = BRADDR;
  646.           the_insn.pcrel = 1;
  647.           goto immediate;
  648.  
  649.         case 's':        /* 16 bit immediate, split relative branch */
  650.           /* upper 5 bits of offset in dest field */
  651.           the_insn.pcrel = 1;
  652.           the_insn.reloc = SPLIT0;
  653.           goto immediate;
  654.  
  655.         case 'S':        /* 16 bit immediate, split (st), aligned */
  656.           if (opcode & (1 << 28))
  657.         if (opcode & 0x1)
  658.           the_insn.reloc = SPLIT2;
  659.         else
  660.           the_insn.reloc = SPLIT1;
  661.           else
  662.         the_insn.reloc = SPLIT0;
  663.           goto immediate;
  664.  
  665.         case 'I':        /* 16 bit immediate, aligned */
  666.           if (opcode & (1 << 28))
  667.         if (opcode & 0x1)
  668.           the_insn.reloc = LOW2;
  669.         else
  670.           the_insn.reloc = LOW1;
  671.           else
  672.         the_insn.reloc = LOW0;
  673.           goto immediate;
  674.  
  675.         case 'i':        /* 16 bit immediate */
  676.           the_insn.reloc = LOW0;
  677.  
  678.           /*FALLTHROUGH*/
  679.  
  680.         immediate:
  681.           if (*s == ' ')
  682.         s++;
  683.           if (strncmp (s, "ha%", 3) == 0)
  684.         {
  685.           the_insn.highlow = HIGHADJ;
  686.           s += 3;
  687.         }
  688.           else if (strncmp (s, "h%", 2) == 0)
  689.         {
  690.           the_insn.highlow = HIGH;
  691.           s += 2;
  692.         }
  693.           else if (strncmp (s, "l%", 2) == 0)
  694.         {
  695.           the_insn.highlow = PAIR;
  696.           s += 2;
  697.         }
  698.           the_insn.expand = insn->expand;
  699.  
  700.           /* Note that if the getExpression() fails, we will still have
  701.                    created U entries in the symbol table for the 'symbols'
  702.                    in the input string.  Try not to create U symbols for
  703.                    registers, etc. */
  704.  
  705.           if (!getExpression (s))
  706.         {
  707.           s = expr_end;
  708.           continue;
  709.         }
  710.           break;
  711.  
  712.         default:
  713.           as_fatal ("failed sanity check.");
  714.         }
  715.       break;
  716.     }
  717.     error:
  718.       if (match == 0)
  719.     {
  720.       /* Args don't match.  */
  721.       if (&insn[1] - i860_opcodes < NUMOPCODES
  722.           && !strcmp (insn->name, insn[1].name))
  723.         {
  724.           ++insn;
  725.           s = argsStart;
  726.           continue;
  727.         }
  728.       else
  729.         {
  730.           as_bad ("Illegal operands");
  731.           return;
  732.         }
  733.     }
  734.       break;
  735.     }
  736.  
  737.   the_insn.opcode = opcode;
  738. }
  739.  
  740. static int
  741. getExpression (str)
  742.      char *str;
  743. {
  744.   char *save_in;
  745.   segT seg;
  746.  
  747.   save_in = input_line_pointer;
  748.   input_line_pointer = str;
  749.   seg = expression (&the_insn.exp);
  750.   if (seg != absolute_section
  751.       && seg != undefined_section
  752.       && ! SEG_NORMAL (seg))
  753.     {
  754.       the_insn.error = "bad segment";
  755.       expr_end = input_line_pointer;
  756.       input_line_pointer = save_in;
  757.       return 1;
  758.     }
  759.   expr_end = input_line_pointer;
  760.   input_line_pointer = save_in;
  761.   return 0;
  762. }
  763.  
  764.  
  765. /*
  766.   This is identical to the md_atof in m68k.c.  I think this is right,
  767.   but I'm not sure.
  768.  
  769.   Turn a string in input_line_pointer into a floating point constant of type
  770.   type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  771.   emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  772.   */
  773.  
  774. /* Equal to MAX_PRECISION in atof-ieee.c */
  775. #define MAX_LITTLENUMS 6
  776.  
  777. char *
  778. md_atof (type, litP, sizeP)
  779.      char type;
  780.      char *litP;
  781.      int *sizeP;
  782. {
  783.   int prec;
  784.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  785.   LITTLENUM_TYPE *wordP;
  786.   char *t;
  787.   char *atof_ieee ();
  788.  
  789.   switch (type)
  790.     {
  791.  
  792.     case 'f':
  793.     case 'F':
  794.     case 's':
  795.     case 'S':
  796.       prec = 2;
  797.       break;
  798.  
  799.     case 'd':
  800.     case 'D':
  801.     case 'r':
  802.     case 'R':
  803.       prec = 4;
  804.       break;
  805.  
  806.     case 'x':
  807.     case 'X':
  808.       prec = 6;
  809.       break;
  810.  
  811.     case 'p':
  812.     case 'P':
  813.       prec = 6;
  814.       break;
  815.  
  816.     default:
  817.       *sizeP = 0;
  818.       return "Bad call to MD_ATOF()";
  819.     }
  820.   t = atof_ieee (input_line_pointer, type, words);
  821.   if (t)
  822.     input_line_pointer = t;
  823.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  824.   for (wordP = words; prec--;)
  825.     {
  826.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  827.       litP += sizeof (LITTLENUM_TYPE);
  828.     }
  829.   return 0;
  830. }
  831.  
  832. /*
  833.  * Write out big-endian.
  834.  */
  835. void
  836. md_number_to_chars (buf, val, n)
  837.      char *buf;
  838.      valueT val;
  839.      int n;
  840. {
  841.   number_to_chars_bigendian (buf, val, n);
  842. }
  843.  
  844. void
  845. md_number_to_imm (buf, val, n, fixP)
  846.      char *buf;
  847.      long val;
  848.      int n;
  849.      fixS *fixP;
  850. {
  851.   enum reloc_type reloc = fixP->fx_r_type & 0xf;
  852.   enum highlow_type highlow = (fixP->fx_r_type >> 4) & 0x3;
  853.  
  854.   assert (buf);
  855.   assert (n == 4);        /* always on i860 */
  856.  
  857.   switch (highlow)
  858.     {
  859.  
  860.     case HIGHADJ:        /* adjusts the high-order 16-bits */
  861.       if (val & (1 << 15))
  862.     val += (1 << 16);
  863.  
  864.       /*FALLTHROUGH*/
  865.  
  866.     case HIGH:            /* selects the high-order 16-bits */
  867.       val >>= 16;
  868.       break;
  869.  
  870.     case PAIR:            /* selects the low-order 16-bits */
  871.       val = val & 0xffff;
  872.       break;
  873.  
  874.     default:
  875.       break;
  876.     }
  877.  
  878.   switch (reloc)
  879.     {
  880.  
  881.     case BRADDR:        /* br,call,bc,bc.t,bnc,bnc.t w/26-bit immediate */
  882.       if (fixP->fx_pcrel != 1)
  883.     as_bad ("26-bit branch w/o pc relative set: 0x%08x", val);
  884.       val >>= 2;        /* align pcrel offset, see manual */
  885.  
  886.       if (val >= (1 << 25) || val < -(1 << 25))    /* check for overflow */
  887.     as_bad ("26-bit branch offset overflow: 0x%08x", val);
  888.       buf[0] = (buf[0] & 0xfc) | ((val >> 24) & 0x3);
  889.       buf[1] = val >> 16;
  890.       buf[2] = val >> 8;
  891.       buf[3] = val;
  892.       break;
  893.  
  894.     case SPLIT2:        /* 16 bit immediate, 4-byte aligned */
  895.       if (val & 0x3)
  896.     as_bad ("16-bit immediate 4-byte alignment error: 0x%08x", val);
  897.       val &= ~0x3;        /* 4-byte align value */
  898.       /*FALLTHROUGH*/
  899.     case SPLIT1:        /* 16 bit immediate, 2-byte aligned */
  900.       if (val & 0x1)
  901.     as_bad ("16-bit immediate 2-byte alignment error: 0x%08x", val);
  902.       val &= ~0x1;        /* 2-byte align value */
  903.       /*FALLTHROUGH*/
  904.     case SPLIT0:        /* st,bla,bte,btne w/16-bit immediate */
  905.       if (fixP->fx_pcrel == 1)
  906.     val >>= 2;        /* align pcrel offset, see manual */
  907.       /* check for bounds */
  908.       if (highlow != PAIR && (val >= (1 << 16) || val < -(1 << 15)))
  909.     as_bad ("16-bit branch offset overflow: 0x%08x", val);
  910.       buf[1] = (buf[1] & ~0x1f) | ((val >> 11) & 0x1f);
  911.       buf[2] = (buf[2] & ~0x7) | ((val >> 8) & 0x7);
  912.       buf[3] |= val;        /* perserve bottom opcode bits */
  913.       break;
  914.  
  915.     case LOW4:            /* fld,pfld,pst,flush 16-byte aligned */
  916.       if (val & 0xf)
  917.     as_bad ("16-bit immediate 16-byte alignment error: 0x%08x", val);
  918.       val &= ~0xf;        /* 16-byte align value */
  919.       /*FALLTHROUGH*/
  920.     case LOW3:            /* fld,pfld,pst,flush 8-byte aligned */
  921.       if (val & 0x7)
  922.     as_bad ("16-bit immediate 8-byte alignment error: 0x%08x", val);
  923.       val &= ~0x7;        /* 8-byte align value */
  924.       /*FALLTHROUGH*/
  925.     case LOW2:            /* 16 bit immediate, 4-byte aligned */
  926.       if (val & 0x3)
  927.     as_bad ("16-bit immediate 4-byte alignment error: 0x%08x", val);
  928.       val &= ~0x3;        /* 4-byte align value */
  929.       /*FALLTHROUGH*/
  930.     case LOW1:            /* 16 bit immediate, 2-byte aligned */
  931.       if (val & 0x1)
  932.     as_bad ("16-bit immediate 2-byte alignment error: 0x%08x", val);
  933.       val &= ~0x1;        /* 2-byte align value */
  934.       /*FALLTHROUGH*/
  935.     case LOW0:            /* 16 bit immediate, byte aligned */
  936.       /* check for bounds */
  937.       if (highlow != PAIR && (val >= (1 << 16) || val < -(1 << 15)))
  938.     as_bad ("16-bit immediate overflow: 0x%08x", val);
  939.       buf[2] = val >> 8;
  940.       buf[3] |= val;        /* perserve bottom opcode bits */
  941.       break;
  942.  
  943.     case NO_RELOC:
  944.     default:
  945.       as_bad ("bad relocation type: 0x%02x", reloc);
  946.       break;
  947.     }
  948. }
  949.  
  950. /* should never be called for i860 */
  951. void
  952. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  953.      char *ptr;
  954.      addressT from_addr, to_addr;
  955.      fragS *frag;
  956.      symbolS *to_symbol;
  957. {
  958.   as_fatal ("i860_create_short_jmp\n");
  959. }
  960.  
  961. /* should never be called for i860 */
  962. void
  963. md_number_to_disp (buf, val, n)
  964.      char *buf;
  965.      long val;
  966. {
  967.   as_fatal ("md_number_to_disp\n");
  968. }
  969.  
  970. /* should never be called for i860 */
  971. void
  972. md_number_to_field (buf, val, fix)
  973.      char *buf;
  974.      long val;
  975.      void *fix;
  976. {
  977.   as_fatal ("i860_number_to_field\n");
  978. }
  979.  
  980. /* the bit-field entries in the relocation_info struct plays hell
  981.    with the byte-order problems of cross-assembly.  So as a hack,
  982.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  983.    you there. -KWK */
  984. /* on i860: first 4 bytes are normal unsigned long address, next three
  985.    bytes are index, most sig. byte first.  Byte 7 is broken up with
  986.    bit 7 as pcrel, bit 6 as extern, and the lower six bits as
  987.    relocation type (highlow 5-4).  Next 4 bytes are long addend. */
  988. /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
  989. void
  990. md_ri_to_chars (ri_p, ri)
  991.      struct relocation_info *ri_p, ri;
  992. {
  993. #if 0
  994.   unsigned char the_bytes[sizeof (*ri_p)];
  995.  
  996.   /* this is easy */
  997.   md_number_to_chars (the_bytes, ri.r_address, sizeof (ri.r_address));
  998.   /* now the fun stuff */
  999.   the_bytes[4] = (ri.r_index >> 16) & 0x0ff;
  1000.   the_bytes[5] = (ri.r_index >> 8) & 0x0ff;
  1001.   the_bytes[6] = ri.r_index & 0x0ff;
  1002.   the_bytes[7] = ((ri.r_extern << 7) & 0x80) | (0 & 0x60) | (ri.r_type & 0x1F);
  1003.   /* Also easy */
  1004.   md_number_to_chars (&the_bytes[8], ri.r_addend, sizeof (ri.r_addend));
  1005.   /* now put it back where you found it, Junior... */
  1006.   memcpy ((char *) ri_p, the_bytes, sizeof (*ri_p));
  1007. #endif
  1008. }
  1009.  
  1010. /* should never be called for i860 */
  1011. void
  1012. md_convert_frag (headers, seg, fragP)
  1013.      object_headers *headers;
  1014.      segT seg;
  1015.      register fragS *fragP;
  1016. {
  1017.   as_fatal ("i860_convert_frag\n");
  1018. }
  1019.  
  1020. /* should never be called for i860 */
  1021. void
  1022. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1023.      char *ptr;
  1024.      addressT from_addr, to_addr;
  1025.      fragS *frag;
  1026.      symbolS *to_symbol;
  1027. {
  1028.   as_fatal ("i860_create_long_jump\n");
  1029. }
  1030.  
  1031. /* should never be called for i860 */
  1032. int
  1033. md_estimate_size_before_relax (fragP, segtype)
  1034.      register fragS *fragP;
  1035.      segT segtype;
  1036. {
  1037.   as_fatal ("i860_estimate_size_before_relax\n");
  1038. }
  1039.  
  1040. /* for debugging only, must match enum reloc_type */
  1041. static char *Reloc[] =
  1042. {
  1043.   "NO_RELOC",
  1044.   "BRADDR",
  1045.   "LOW0",
  1046.   "LOW1",
  1047.   "LOW2",
  1048.   "LOW3",
  1049.   "LOW4",
  1050.   "SPLIT0",
  1051.   "SPLIT1",
  1052.   "SPLIT2",
  1053.   "RELOC_32",
  1054. };
  1055. static char *Highlow[] =
  1056. {
  1057.   "NO_SPEC",
  1058.   "PAIR",
  1059.   "HIGH",
  1060.   "HIGHADJ",
  1061. };
  1062. static void
  1063. print_insn (insn)
  1064.      struct i860_it *insn;
  1065. {
  1066.   if (insn->error)
  1067.     {
  1068.       fprintf (stderr, "ERROR: %s\n");
  1069.     }
  1070.   fprintf (stderr, "opcode=0x%08x\t", insn->opcode);
  1071.   fprintf (stderr, "expand=0x%08x\t", insn->expand);
  1072.   fprintf (stderr, "reloc = %s\t", Reloc[insn->reloc]);
  1073.   fprintf (stderr, "highlow = %s\n", Highlow[insn->highlow]);
  1074.   fprintf (stderr, "exp =  {\n");
  1075.   fprintf (stderr, "\t\tX_add_symbol = %s\n",
  1076.        insn->exp.X_add_symbol ?
  1077.        (S_GET_NAME (insn->exp.X_add_symbol) ?
  1078.         S_GET_NAME (insn->exp.X_add_symbol) : "???") : "0");
  1079.   fprintf (stderr, "\t\tX_op_symbol = %s\n",
  1080.        insn->exp.X_op_symbol ?
  1081.        (S_GET_NAME (insn->exp.X_op_symbol) ?
  1082.         S_GET_NAME (insn->exp.X_op_symbol) : "???") : "0");
  1083.   fprintf (stderr, "\t\tX_add_number = %d\n",
  1084.        insn->exp.X_add_number);
  1085.   fprintf (stderr, "}\n");
  1086. }
  1087.  
  1088. CONST char *md_shortopts = "";
  1089. struct option md_longopts[] = {
  1090.   {NULL, no_argument, NULL, 0}
  1091. };
  1092. size_t md_longopts_size = sizeof(md_longopts);
  1093.  
  1094. int
  1095. md_parse_option (c, arg)
  1096.      int c;
  1097.      char *arg;
  1098. {
  1099.   return 0;
  1100. }
  1101.  
  1102. void
  1103. md_show_usage (stream)
  1104.      FILE *stream;
  1105. {
  1106. }
  1107.  
  1108. #ifdef comment
  1109. /*
  1110.  * I860 relocations are completely different, so it needs
  1111.  * this machine dependent routine to emit them.
  1112.  */
  1113. void
  1114. emit_machine_reloc (fixP, segment_address_in_file)
  1115.      register fixS *fixP;
  1116.      relax_addressT segment_address_in_file;
  1117. {
  1118.   struct reloc_info_i860 ri;
  1119.   register symbolS *symbolP;
  1120.   extern char *next_object_file_charP;
  1121.   long add_number;
  1122.  
  1123.   memset ((char *) &ri, '\0', sizeof (ri));
  1124.   for (; fixP; fixP = fixP->fx_next)
  1125.     {
  1126.  
  1127.       if (fixP->fx_r_type & ~0x3f)
  1128.     {
  1129.       as_fatal ("fixP->fx_r_type = %d\n", fixP->fx_r_type);
  1130.     }
  1131.       ri.r_pcrel = fixP->fx_pcrel;
  1132.       ri.r_type = fixP->fx_r_type;
  1133.  
  1134.       if ((symbolP = fixP->fx_addsy) != NULL)
  1135.     {
  1136.       ri.r_address = fixP->fx_frag->fr_address +
  1137.         fixP->fx_where - segment_address_in_file;
  1138.       if (!S_IS_DEFINED (symbolP))
  1139.         {
  1140.           ri.r_extern = 1;
  1141.           ri.r_symbolnum = symbolP->sy_number;
  1142.         }
  1143.       else
  1144.         {
  1145.           ri.r_extern = 0;
  1146.           ri.r_symbolnum = S_GET_TYPE (symbolP);
  1147.         }
  1148.       if (symbolP && symbolP->sy_frag)
  1149.         {
  1150.           ri.r_addend = symbolP->sy_frag->fr_address;
  1151.         }
  1152.       ri.r_type = fixP->fx_r_type;
  1153.       if (fixP->fx_pcrel)
  1154.         {
  1155.           /* preserve actual offset vs. pc + 4 */
  1156.           ri.r_addend -= (ri.r_address + 4);
  1157.         }
  1158.       else
  1159.         {
  1160.           ri.r_addend = fixP->fx_addnumber;
  1161.         }
  1162.  
  1163.       md_ri_to_chars ((char *) &ri, ri);
  1164.       append (&next_object_file_charP, (char *) &ri, sizeof (ri));
  1165.     }
  1166.     }
  1167. }
  1168.  
  1169. #endif /* comment */
  1170.  
  1171. #ifdef OBJ_AOUT
  1172.  
  1173. /* on i860: first 4 bytes are normal unsigned long address, next three
  1174.    bytes are index, most sig. byte first.  Byte 7 is broken up with
  1175.    bit 7 as pcrel, bit 6 as extern, and the lower six bits as
  1176.    relocation type (highlow 5-4).  Next 4 bytes are long addend. */
  1177.  
  1178. void
  1179. tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
  1180.      char *where;
  1181.      fixS *fixP;
  1182.      relax_addressT segment_address_in_file;
  1183. {
  1184.   long r_index;
  1185.   long r_extern;
  1186.   long r_addend = 0;
  1187.   long r_address;
  1188.  
  1189.   know (fixP->fx_addsy);
  1190.   know (!(fixP->fx_r_type & ~0x3f));
  1191.  
  1192.   if (!S_IS_DEFINED (fixP->fx_addsy))
  1193.     {
  1194.       r_extern = 1;
  1195.       r_index = fixP->fx_addsy->sy_number;
  1196.     }
  1197.   else
  1198.     {
  1199.       r_extern = 0;
  1200.       r_index = S_GET_TYPE (fixP->fx_addsy);
  1201.     }
  1202.  
  1203.   md_number_to_chars (where,
  1204.               r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
  1205.               4);
  1206.  
  1207.   where[4] = (r_index >> 16) & 0x0ff;
  1208.   where[5] = (r_index >> 8) & 0x0ff;
  1209.   where[6] = r_index & 0x0ff;
  1210.   where[7] = (((fixP->fx_pcrel << 7) & 0x80)
  1211.           | ((r_extern << 6) & 0x40)
  1212.           | (fixP->fx_r_type & 0x3F));
  1213.  
  1214.   if (fixP->fx_addsy->sy_frag)
  1215.     {
  1216.       r_addend = fixP->fx_addsy->sy_frag->fr_address;
  1217.     }
  1218.  
  1219.   if (fixP->fx_pcrel)
  1220.     {
  1221.       /* preserve actual offset vs. pc + 4 */
  1222.       r_addend -= (r_address + 4);
  1223.     }
  1224.   else
  1225.     {
  1226.       r_addend = fixP->fx_addnumber;
  1227.     }
  1228.  
  1229.   md_number_to_chars (&where[8], r_addend, 4);
  1230. }
  1231.  
  1232. #endif /* OBJ_AOUT */
  1233.  
  1234. /* We have no need to default values of symbols.  */
  1235.  
  1236. /* ARGSUSED */
  1237. symbolS *
  1238. md_undefined_symbol (name)
  1239.      char *name;
  1240. {
  1241.   return 0;
  1242. }
  1243.  
  1244. /* Round up a section size to the appropriate boundary.  */
  1245. valueT
  1246. md_section_align (segment, size)
  1247.      segT segment;
  1248.      valueT size;
  1249. {
  1250.   return size;            /* Byte alignment is fine */
  1251. }
  1252.  
  1253. /* Exactly what point is a PC-relative offset relative TO?
  1254.    On the i860, they're relative to the address of the offset, plus
  1255.    its size. (??? Is this right?  FIXME-SOON!) */
  1256. long
  1257. md_pcrel_from (fixP)
  1258.      fixS *fixP;
  1259. {
  1260.   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
  1261. }
  1262.  
  1263. void
  1264. md_apply_fix (fixP, val)
  1265.      fixS *fixP;
  1266.      long val;
  1267. {
  1268.   char *place = fixP->fx_where + fixP->fx_frag->fr_literal;
  1269.  
  1270.   /* looks to me like i860 never has bit fixes. Let's see. xoxorich. */
  1271.   know (fixP->fx_bit_fixP == NULL);
  1272.   if (!fixP->fx_bit_fixP)
  1273.     {
  1274.       fixP->fx_addnumber = val;
  1275.       md_number_to_imm (place, val, fixP->fx_size, fixP);
  1276.     }
  1277.   else
  1278.     {
  1279.       md_number_to_field (place, val, fixP->fx_bit_fixP);
  1280.     }
  1281. }
  1282.  
  1283. /*
  1284.  * Local Variables:
  1285.  * fill-column: 131
  1286.  * comment-column: 0
  1287.  * End:
  1288.  */
  1289.  
  1290. /* end of tc-i860.c */
  1291.