Home | History | Annotate | Line # | Download | only in config
tc-tic30.c revision 1.3
      1  1.1  christos /* tc-c30.c -- Assembly code for the Texas Instruments TMS320C30
      2  1.3  christos    Copyright (C) 1998-2015 Free Software Foundation, Inc.
      3  1.1  christos    Contributed by Steven Haworth (steve (at) pm.cse.rmit.edu.au)
      4  1.1  christos 
      5  1.1  christos    This file is part of GAS, the GNU Assembler.
      6  1.1  christos 
      7  1.1  christos    GAS is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3, or (at your option)
     10  1.1  christos    any later version.
     11  1.1  christos 
     12  1.1  christos    GAS is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with GAS; see the file COPYING.  If not, write to the Free
     19  1.1  christos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     20  1.1  christos    02110-1301, USA.  */
     21  1.1  christos 
     22  1.1  christos /* Texas Instruments TMS320C30 machine specific gas.
     23  1.1  christos    Written by Steven Haworth (steve (at) pm.cse.rmit.edu.au).
     24  1.1  christos    Bugs & suggestions are completely welcome.  This is free software.
     25  1.1  christos    Please help us make it better.  */
     26  1.1  christos 
     27  1.1  christos #include "as.h"
     28  1.1  christos #include "safe-ctype.h"
     29  1.1  christos #include "opcode/tic30.h"
     30  1.1  christos 
     31  1.1  christos /* Put here all non-digit non-letter characters that may occur in an
     32  1.1  christos    operand.  */
     33  1.1  christos static char operand_special_chars[] = "%$-+(,)*._~/<>&^!:[@]";
     34  1.1  christos static char *ordinal_names[] =
     35  1.1  christos {
     36  1.1  christos   N_("first"), N_("second"), N_("third"), N_("fourth"), N_("fifth")
     37  1.1  christos };
     38  1.1  christos 
     39  1.1  christos const char comment_chars[]        = ";";
     40  1.1  christos const char line_comment_chars[]   = "*";
     41  1.1  christos const char line_separator_chars[] = "";
     42  1.1  christos 
     43  1.1  christos const char *md_shortopts = "";
     44  1.1  christos struct option md_longopts[] =
     45  1.1  christos {
     46  1.1  christos   {NULL, no_argument, NULL, 0}
     47  1.1  christos };
     48  1.1  christos 
     49  1.1  christos size_t md_longopts_size = sizeof (md_longopts);
     50  1.1  christos 
     51  1.1  christos /* Chars that mean this number is a floating point constant.
     52  1.1  christos    As in 0f12.456
     53  1.1  christos    or    0d1.2345e12.  */
     54  1.1  christos const char FLT_CHARS[] = "fFdDxX";
     55  1.1  christos 
     56  1.1  christos /* Chars that can be used to separate mant from exp in floating point
     57  1.1  christos    nums.  */
     58  1.1  christos const char EXP_CHARS[] = "eE";
     59  1.1  christos 
     60  1.1  christos /* Tables for lexical analysis.  */
     61  1.1  christos static char opcode_chars[256];
     62  1.1  christos static char register_chars[256];
     63  1.1  christos static char operand_chars[256];
     64  1.1  christos static char space_chars[256];
     65  1.1  christos static char identifier_chars[256];
     66  1.1  christos static char digit_chars[256];
     67  1.1  christos 
     68  1.1  christos /* Lexical macros.  */
     69  1.1  christos #define is_opcode_char(x)     (opcode_chars     [(unsigned char) x])
     70  1.1  christos #define is_operand_char(x)    (operand_chars    [(unsigned char) x])
     71  1.1  christos #define is_register_char(x)   (register_chars   [(unsigned char) x])
     72  1.1  christos #define is_space_char(x)      (space_chars      [(unsigned char) x])
     73  1.1  christos #define is_identifier_char(x) (identifier_chars [(unsigned char) x])
     74  1.1  christos #define is_digit_char(x)      (digit_chars      [(unsigned char) x])
     75  1.1  christos 
     76  1.1  christos const pseudo_typeS md_pseudo_table[] =
     77  1.1  christos {
     78  1.1  christos   {0, 0, 0}
     79  1.1  christos };
     80  1.1  christos 
     81  1.1  christos static int ATTRIBUTE_PRINTF_1
     82  1.1  christos debug (const char *string, ...)
     83  1.1  christos {
     84  1.1  christos   if (flag_debug)
     85  1.1  christos     {
     86  1.1  christos       char str[100];
     87  1.3  christos       va_list argptr;
     88  1.1  christos 
     89  1.3  christos       va_start (argptr, string);
     90  1.1  christos       vsprintf (str, string, argptr);
     91  1.3  christos       va_end (argptr);
     92  1.1  christos       if (str[0] == '\0')
     93  1.1  christos 	return (0);
     94  1.1  christos       fputs (str, USE_STDOUT ? stdout : stderr);
     95  1.1  christos       return strlen (str);
     96  1.1  christos     }
     97  1.1  christos   else
     98  1.1  christos     return 0;
     99  1.1  christos }
    100  1.1  christos 
    101  1.1  christos /* Hash table for opcode lookup.  */
    102  1.1  christos static struct hash_control *op_hash;
    103  1.1  christos /* Hash table for parallel opcode lookup.  */
    104  1.1  christos static struct hash_control *parop_hash;
    105  1.1  christos /* Hash table for register lookup.  */
    106  1.1  christos static struct hash_control *reg_hash;
    107  1.1  christos /* Hash table for indirect addressing lookup.  */
    108  1.1  christos static struct hash_control *ind_hash;
    109  1.1  christos 
    110  1.1  christos void
    111  1.1  christos md_begin (void)
    112  1.1  christos {
    113  1.1  christos   const char *hash_err;
    114  1.1  christos 
    115  1.1  christos   debug ("In md_begin()\n");
    116  1.1  christos   op_hash = hash_new ();
    117  1.1  christos 
    118  1.1  christos   {
    119  1.1  christos     const insn_template *current_optab = tic30_optab;
    120  1.1  christos 
    121  1.1  christos     for (; current_optab < tic30_optab_end; current_optab++)
    122  1.1  christos       {
    123  1.1  christos 	hash_err = hash_insert (op_hash, current_optab->name,
    124  1.1  christos 				(char *) current_optab);
    125  1.1  christos 	if (hash_err)
    126  1.1  christos 	  as_fatal ("Internal Error: Can't Hash %s: %s",
    127  1.1  christos 		    current_optab->name, hash_err);
    128  1.1  christos       }
    129  1.1  christos   }
    130  1.1  christos 
    131  1.1  christos   parop_hash = hash_new ();
    132  1.1  christos 
    133  1.1  christos   {
    134  1.1  christos     const partemplate *current_parop = tic30_paroptab;
    135  1.1  christos 
    136  1.1  christos     for (; current_parop < tic30_paroptab_end; current_parop++)
    137  1.1  christos       {
    138  1.1  christos 	hash_err = hash_insert (parop_hash, current_parop->name,
    139  1.1  christos 				(char *) current_parop);
    140  1.1  christos 	if (hash_err)
    141  1.1  christos 	  as_fatal ("Internal Error: Can't Hash %s: %s",
    142  1.1  christos 		    current_parop->name, hash_err);
    143  1.1  christos       }
    144  1.1  christos   }
    145  1.1  christos 
    146  1.1  christos   reg_hash = hash_new ();
    147  1.1  christos 
    148  1.1  christos   {
    149  1.1  christos     const reg *current_reg = tic30_regtab;
    150  1.1  christos 
    151  1.1  christos     for (; current_reg < tic30_regtab_end; current_reg++)
    152  1.1  christos       {
    153  1.1  christos 	hash_err = hash_insert (reg_hash, current_reg->name,
    154  1.1  christos 				(char *) current_reg);
    155  1.1  christos 	if (hash_err)
    156  1.1  christos 	  as_fatal ("Internal Error: Can't Hash %s: %s",
    157  1.1  christos 		    current_reg->name, hash_err);
    158  1.1  christos       }
    159  1.1  christos   }
    160  1.1  christos 
    161  1.1  christos   ind_hash = hash_new ();
    162  1.1  christos 
    163  1.1  christos   {
    164  1.1  christos     const ind_addr_type *current_ind = tic30_indaddr_tab;
    165  1.1  christos 
    166  1.1  christos     for (; current_ind < tic30_indaddrtab_end; current_ind++)
    167  1.1  christos       {
    168  1.1  christos 	hash_err = hash_insert (ind_hash, current_ind->syntax,
    169  1.1  christos 				(char *) current_ind);
    170  1.1  christos 	if (hash_err)
    171  1.1  christos 	  as_fatal ("Internal Error: Can't Hash %s: %s",
    172  1.1  christos 		    current_ind->syntax, hash_err);
    173  1.1  christos       }
    174  1.1  christos   }
    175  1.1  christos 
    176  1.1  christos   /* Fill in lexical tables:  opcode_chars, operand_chars, space_chars.  */
    177  1.1  christos   {
    178  1.1  christos     int c;
    179  1.1  christos     char *p;
    180  1.1  christos 
    181  1.1  christos     for (c = 0; c < 256; c++)
    182  1.1  christos       {
    183  1.1  christos 	if (ISLOWER (c) || ISDIGIT (c))
    184  1.1  christos 	  {
    185  1.1  christos 	    opcode_chars[c] = c;
    186  1.1  christos 	    register_chars[c] = c;
    187  1.1  christos 	  }
    188  1.1  christos 	else if (ISUPPER (c))
    189  1.1  christos 	  {
    190  1.1  christos 	    opcode_chars[c] = TOLOWER (c);
    191  1.1  christos 	    register_chars[c] = opcode_chars[c];
    192  1.1  christos 	  }
    193  1.1  christos 	else if (c == ')' || c == '(')
    194  1.1  christos 	  register_chars[c] = c;
    195  1.1  christos 
    196  1.1  christos 	if (ISUPPER (c) || ISLOWER (c) || ISDIGIT (c))
    197  1.1  christos 	  operand_chars[c] = c;
    198  1.1  christos 
    199  1.1  christos 	if (ISDIGIT (c) || c == '-')
    200  1.1  christos 	  digit_chars[c] = c;
    201  1.1  christos 
    202  1.1  christos 	if (ISALPHA (c) || c == '_' || c == '.' || ISDIGIT (c))
    203  1.1  christos 	  identifier_chars[c] = c;
    204  1.1  christos 
    205  1.1  christos 	if (c == ' ' || c == '\t')
    206  1.1  christos 	  space_chars[c] = c;
    207  1.1  christos 
    208  1.1  christos 	if (c == '_')
    209  1.1  christos 	  opcode_chars[c] = c;
    210  1.1  christos       }
    211  1.1  christos     for (p = operand_special_chars; *p != '\0'; p++)
    212  1.1  christos       operand_chars[(unsigned char) *p] = *p;
    213  1.1  christos   }
    214  1.1  christos }
    215  1.1  christos 
    216  1.1  christos /* Address Mode OR values.  */
    217  1.1  christos #define AM_Register  0x00000000
    218  1.1  christos #define AM_Direct    0x00200000
    219  1.1  christos #define AM_Indirect  0x00400000
    220  1.1  christos #define AM_Immediate 0x00600000
    221  1.1  christos #define AM_NotReq    0xFFFFFFFF
    222  1.1  christos 
    223  1.1  christos /* PC Relative OR values.  */
    224  1.1  christos #define PC_Register 0x00000000
    225  1.1  christos #define PC_Relative 0x02000000
    226  1.1  christos 
    227  1.1  christos typedef struct
    228  1.1  christos {
    229  1.1  christos   unsigned op_type;
    230  1.1  christos   struct
    231  1.1  christos   {
    232  1.1  christos     int resolved;
    233  1.1  christos     unsigned address;
    234  1.1  christos     char *label;
    235  1.1  christos     expressionS direct_expr;
    236  1.1  christos   } direct;
    237  1.1  christos   struct
    238  1.1  christos   {
    239  1.1  christos     unsigned mod;
    240  1.1  christos     int ARnum;
    241  1.1  christos     unsigned char disp;
    242  1.1  christos   } indirect;
    243  1.1  christos   struct
    244  1.1  christos   {
    245  1.1  christos     unsigned opcode;
    246  1.1  christos   } reg;
    247  1.1  christos   struct
    248  1.1  christos   {
    249  1.1  christos     int resolved;
    250  1.1  christos     int decimal_found;
    251  1.1  christos     float f_number;
    252  1.1  christos     int s_number;
    253  1.1  christos     unsigned int u_number;
    254  1.1  christos     char *label;
    255  1.1  christos     expressionS imm_expr;
    256  1.1  christos   } immediate;
    257  1.1  christos } operand;
    258  1.1  christos 
    259  1.1  christos insn_template *opcode;
    260  1.1  christos 
    261  1.1  christos struct tic30_insn
    262  1.1  christos {
    263  1.1  christos   insn_template *tm;		/* Template of current instruction.  */
    264  1.1  christos   unsigned opcode;		/* Final opcode.  */
    265  1.1  christos   unsigned int operands;	/* Number of given operands.  */
    266  1.1  christos   /* Type of operand given in instruction.  */
    267  1.1  christos   operand *operand_type[MAX_OPERANDS];
    268  1.1  christos   unsigned addressing_mode;	/* Final addressing mode of instruction.  */
    269  1.1  christos };
    270  1.1  christos 
    271  1.1  christos struct tic30_insn insn;
    272  1.1  christos static int found_parallel_insn;
    273  1.1  christos 
    274  1.1  christos static char output_invalid_buf[sizeof (unsigned char) * 2 + 6];
    275  1.1  christos 
    276  1.1  christos static char *
    277  1.1  christos output_invalid (char c)
    278  1.1  christos {
    279  1.1  christos   if (ISPRINT (c))
    280  1.1  christos     snprintf (output_invalid_buf, sizeof (output_invalid_buf),
    281  1.1  christos 	      "'%c'", c);
    282  1.1  christos   else
    283  1.3  christos     snprintf (output_invalid_buf, sizeof (output_invalid_buf),
    284  1.1  christos 	      "(0x%x)", (unsigned char) c);
    285  1.1  christos   return output_invalid_buf;
    286  1.1  christos }
    287  1.1  christos 
    288  1.1  christos /* next_line points to the next line after the current instruction
    289  1.1  christos    (current_line).  Search for the parallel bars, and if found, merge two
    290  1.1  christos    lines into internal syntax for a parallel instruction:
    291  1.1  christos      q_[INSN1]_[INSN2] [OPERANDS1] | [OPERANDS2]
    292  1.1  christos    By this stage, all comments are scrubbed, and only the bare lines are
    293  1.1  christos    given.  */
    294  1.1  christos 
    295  1.1  christos #define NONE           0
    296  1.1  christos #define START_OPCODE   1
    297  1.1  christos #define END_OPCODE     2
    298  1.1  christos #define START_OPERANDS 3
    299  1.1  christos #define END_OPERANDS   4
    300  1.1  christos 
    301  1.1  christos static char *
    302  1.1  christos tic30_find_parallel_insn (char *current_line, char *next_line)
    303  1.1  christos {
    304  1.1  christos   int found_parallel = 0;
    305  1.1  christos   char first_opcode[256];
    306  1.1  christos   char second_opcode[256];
    307  1.1  christos   char first_operands[256];
    308  1.1  christos   char second_operands[256];
    309  1.1  christos   char *parallel_insn;
    310  1.1  christos 
    311  1.1  christos   debug ("In tic30_find_parallel_insn()\n");
    312  1.1  christos   while (!is_end_of_line[(unsigned char) *next_line])
    313  1.1  christos     {
    314  1.1  christos       if (*next_line == PARALLEL_SEPARATOR
    315  1.1  christos 	  && *(next_line + 1) == PARALLEL_SEPARATOR)
    316  1.1  christos 	{
    317  1.1  christos 	  found_parallel = 1;
    318  1.1  christos 	  next_line++;
    319  1.1  christos 	  break;
    320  1.1  christos 	}
    321  1.1  christos       next_line++;
    322  1.1  christos     }
    323  1.1  christos   if (!found_parallel)
    324  1.1  christos     return NULL;
    325  1.1  christos   debug ("Found a parallel instruction\n");
    326  1.1  christos 
    327  1.1  christos   {
    328  1.1  christos     int i;
    329  1.1  christos     char *op, *operands, *line;
    330  1.1  christos 
    331  1.1  christos     for (i = 0; i < 2; i++)
    332  1.1  christos       {
    333  1.1  christos 	if (i == 0)
    334  1.1  christos 	  {
    335  1.1  christos 	    op = &first_opcode[0];
    336  1.1  christos 	    operands = &first_operands[0];
    337  1.1  christos 	    line = current_line;
    338  1.1  christos 	  }
    339  1.1  christos 	else
    340  1.1  christos 	  {
    341  1.1  christos 	    op = &second_opcode[0];
    342  1.1  christos 	    operands = &second_operands[0];
    343  1.1  christos 	    line = next_line;
    344  1.1  christos 	  }
    345  1.1  christos 
    346  1.1  christos 	{
    347  1.1  christos 	  int search_status = NONE;
    348  1.1  christos 	  int char_ptr = 0;
    349  1.1  christos 	  char c;
    350  1.1  christos 
    351  1.1  christos 	  while (!is_end_of_line[(unsigned char) (c = *line)])
    352  1.1  christos 	    {
    353  1.1  christos 	      if (is_opcode_char (c) && search_status == NONE)
    354  1.1  christos 		{
    355  1.1  christos 		  op[char_ptr++] = TOLOWER (c);
    356  1.1  christos 		  search_status = START_OPCODE;
    357  1.1  christos 		}
    358  1.1  christos 	      else if (is_opcode_char (c) && search_status == START_OPCODE)
    359  1.1  christos 		op[char_ptr++] = TOLOWER (c);
    360  1.1  christos 	      else if (!is_opcode_char (c) && search_status == START_OPCODE)
    361  1.1  christos 		{
    362  1.1  christos 		  op[char_ptr] = '\0';
    363  1.1  christos 		  char_ptr = 0;
    364  1.1  christos 		  search_status = END_OPCODE;
    365  1.1  christos 		}
    366  1.1  christos 	      else if (is_operand_char (c) && search_status == START_OPERANDS)
    367  1.1  christos 		operands[char_ptr++] = c;
    368  1.1  christos 
    369  1.1  christos 	      if (is_operand_char (c) && search_status == END_OPCODE)
    370  1.1  christos 		{
    371  1.1  christos 		  operands[char_ptr++] = c;
    372  1.1  christos 		  search_status = START_OPERANDS;
    373  1.1  christos 		}
    374  1.1  christos 
    375  1.1  christos 	      line++;
    376  1.1  christos 	    }
    377  1.1  christos 	  if (search_status != START_OPERANDS)
    378  1.1  christos 	    return NULL;
    379  1.1  christos 	  operands[char_ptr] = '\0';
    380  1.1  christos 	}
    381  1.1  christos       }
    382  1.1  christos   }
    383  1.1  christos   parallel_insn = malloc (strlen (first_opcode) + strlen (first_operands)
    384  1.1  christos 			  + strlen (second_opcode) + strlen (second_operands) + 8);
    385  1.1  christos   sprintf (parallel_insn, "q_%s_%s %s | %s",
    386  1.1  christos 	   first_opcode, second_opcode,
    387  1.1  christos 	   first_operands, second_operands);
    388  1.1  christos   debug ("parallel insn = %s\n", parallel_insn);
    389  1.1  christos   return parallel_insn;
    390  1.1  christos }
    391  1.1  christos 
    392  1.1  christos #undef NONE
    393  1.1  christos #undef START_OPCODE
    394  1.1  christos #undef END_OPCODE
    395  1.1  christos #undef START_OPERANDS
    396  1.1  christos #undef END_OPERANDS
    397  1.1  christos 
    398  1.1  christos static operand *
    399  1.1  christos tic30_operand (char *token)
    400  1.1  christos {
    401  1.1  christos   unsigned int count;
    402  1.1  christos   char ind_buffer[strlen (token)];
    403  1.1  christos   operand *current_op;
    404  1.1  christos 
    405  1.1  christos   debug ("In tic30_operand with %s\n", token);
    406  1.1  christos   current_op = malloc (sizeof (* current_op));
    407  1.1  christos   memset (current_op, '\0', sizeof (operand));
    408  1.1  christos 
    409  1.1  christos   if (*token == DIRECT_REFERENCE)
    410  1.1  christos     {
    411  1.1  christos       char *token_posn = token + 1;
    412  1.1  christos       int direct_label = 0;
    413  1.1  christos 
    414  1.1  christos       debug ("Found direct reference\n");
    415  1.1  christos       while (*token_posn)
    416  1.1  christos 	{
    417  1.1  christos 	  if (!is_digit_char (*token_posn))
    418  1.1  christos 	    direct_label = 1;
    419  1.1  christos 	  token_posn++;
    420  1.1  christos 	}
    421  1.1  christos 
    422  1.1  christos       if (direct_label)
    423  1.1  christos 	{
    424  1.1  christos 	  char *save_input_line_pointer;
    425  1.1  christos 	  segT retval;
    426  1.1  christos 
    427  1.1  christos 	  debug ("Direct reference is a label\n");
    428  1.1  christos 	  current_op->direct.label = token + 1;
    429  1.1  christos 	  save_input_line_pointer = input_line_pointer;
    430  1.1  christos 	  input_line_pointer = token + 1;
    431  1.1  christos 	  debug ("Current input_line_pointer: %s\n", input_line_pointer);
    432  1.1  christos 	  retval = expression (&current_op->direct.direct_expr);
    433  1.1  christos 
    434  1.1  christos 	  debug ("Expression type: %d\n",
    435  1.1  christos 		 current_op->direct.direct_expr.X_op);
    436  1.1  christos 	  debug ("Expression addnum: %ld\n",
    437  1.1  christos 		 (long) current_op->direct.direct_expr.X_add_number);
    438  1.1  christos 	  debug ("Segment: %p\n", retval);
    439  1.1  christos 
    440  1.1  christos 	  input_line_pointer = save_input_line_pointer;
    441  1.1  christos 
    442  1.1  christos 	  if (current_op->direct.direct_expr.X_op == O_constant)
    443  1.1  christos 	    {
    444  1.1  christos 	      current_op->direct.address =
    445  1.1  christos 		current_op->direct.direct_expr.X_add_number;
    446  1.1  christos 	      current_op->direct.resolved = 1;
    447  1.1  christos 	    }
    448  1.1  christos 	}
    449  1.1  christos       else
    450  1.1  christos 	{
    451  1.1  christos 	  debug ("Direct reference is a number\n");
    452  1.1  christos 	  current_op->direct.address = atoi (token + 1);
    453  1.1  christos 	  current_op->direct.resolved = 1;
    454  1.1  christos 	}
    455  1.1  christos       current_op->op_type = Direct;
    456  1.1  christos     }
    457  1.1  christos   else if (*token == INDIRECT_REFERENCE)
    458  1.1  christos     {
    459  1.1  christos       /* Indirect reference operand.  */
    460  1.1  christos       int found_ar = 0;
    461  1.1  christos       int found_disp = 0;
    462  1.1  christos       int ar_number = -1;
    463  1.1  christos       int disp_number = 0;
    464  1.1  christos       int buffer_posn = 1;
    465  1.1  christos       ind_addr_type *ind_addr_op;
    466  1.1  christos 
    467  1.1  christos       debug ("Found indirect reference\n");
    468  1.1  christos       ind_buffer[0] = *token;
    469  1.1  christos 
    470  1.1  christos       for (count = 1; count < strlen (token); count++)
    471  1.1  christos 	{
    472  1.1  christos 	  /* Strip operand.  */
    473  1.1  christos 	  ind_buffer[buffer_posn] = TOLOWER (*(token + count));
    474  1.1  christos 
    475  1.1  christos 	  if ((*(token + count - 1) == 'a' || *(token + count - 1) == 'A')
    476  1.1  christos 	      && (*(token + count) == 'r' || *(token + count) == 'R'))
    477  1.1  christos 	    {
    478  1.1  christos 	      /* AR reference is found, so get its number and remove
    479  1.1  christos 		 it from the buffer so it can pass through hash_find().  */
    480  1.1  christos 	      if (found_ar)
    481  1.1  christos 		{
    482  1.1  christos 		  as_bad (_("More than one AR register found in indirect reference"));
    483  1.1  christos 		  return NULL;
    484  1.1  christos 		}
    485  1.1  christos 	      if (*(token + count + 1) < '0' || *(token + count + 1) > '7')
    486  1.1  christos 		{
    487  1.1  christos 		  as_bad (_("Illegal AR register in indirect reference"));
    488  1.1  christos 		  return NULL;
    489  1.1  christos 		}
    490  1.1  christos 	      ar_number = *(token + count + 1) - '0';
    491  1.1  christos 	      found_ar = 1;
    492  1.1  christos 	      count++;
    493  1.1  christos 	    }
    494  1.1  christos 
    495  1.1  christos 	  if (*(token + count) == '(')
    496  1.1  christos 	    {
    497  1.1  christos 	      /* Parenthesis found, so check if a displacement value is
    498  1.1  christos 		 inside.  If so, get the value and remove it from the
    499  1.1  christos 		 buffer.  */
    500  1.1  christos 	      if (is_digit_char (*(token + count + 1)))
    501  1.1  christos 		{
    502  1.1  christos 		  char disp[10];
    503  1.1  christos 		  int disp_posn = 0;
    504  1.1  christos 
    505  1.1  christos 		  if (found_disp)
    506  1.1  christos 		    {
    507  1.1  christos 		      as_bad (_("More than one displacement found in indirect reference"));
    508  1.1  christos 		      return NULL;
    509  1.1  christos 		    }
    510  1.1  christos 		  count++;
    511  1.1  christos 		  while (*(token + count) != ')')
    512  1.1  christos 		    {
    513  1.1  christos 		      if (!is_digit_char (*(token + count)))
    514  1.1  christos 			{
    515  1.1  christos 			  as_bad (_("Invalid displacement in indirect reference"));
    516  1.1  christos 			  return NULL;
    517  1.1  christos 			}
    518  1.1  christos 		      disp[disp_posn++] = *(token + (count++));
    519  1.1  christos 		    }
    520  1.1  christos 		  disp[disp_posn] = '\0';
    521  1.1  christos 		  disp_number = atoi (disp);
    522  1.1  christos 		  count--;
    523  1.1  christos 		  found_disp = 1;
    524  1.1  christos 		}
    525  1.1  christos 	    }
    526  1.1  christos 	  buffer_posn++;
    527  1.1  christos 	}
    528  1.1  christos 
    529  1.1  christos       ind_buffer[buffer_posn] = '\0';
    530  1.1  christos       if (!found_ar)
    531  1.1  christos 	{
    532  1.1  christos 	  as_bad (_("AR register not found in indirect reference"));
    533  1.1  christos 	  return NULL;
    534  1.1  christos 	}
    535  1.1  christos 
    536  1.1  christos       ind_addr_op = (ind_addr_type *) hash_find (ind_hash, ind_buffer);
    537  1.1  christos       if (ind_addr_op)
    538  1.1  christos 	{
    539  1.1  christos 	  debug ("Found indirect reference: %s\n", ind_addr_op->syntax);
    540  1.1  christos 	  if (ind_addr_op->displacement == IMPLIED_DISP)
    541  1.1  christos 	    {
    542  1.1  christos 	      found_disp = 1;
    543  1.1  christos 	      disp_number = 1;
    544  1.1  christos 	    }
    545  1.1  christos 	  else if ((ind_addr_op->displacement == DISP_REQUIRED) && !found_disp)
    546  1.1  christos 	    {
    547  1.1  christos 	      /* Maybe an implied displacement of 1 again.  */
    548  1.1  christos 	      as_bad (_("required displacement wasn't given in indirect reference"));
    549  1.1  christos 	      return 0;
    550  1.1  christos 	    }
    551  1.1  christos 	}
    552  1.1  christos       else
    553  1.1  christos 	{
    554  1.1  christos 	  as_bad (_("illegal indirect reference"));
    555  1.1  christos 	  return NULL;
    556  1.1  christos 	}
    557  1.1  christos 
    558  1.1  christos       if (found_disp && (disp_number < 0 || disp_number > 255))
    559  1.1  christos 	{
    560  1.1  christos 	  as_bad (_("displacement must be an unsigned 8-bit number"));
    561  1.1  christos 	  return NULL;
    562  1.1  christos 	}
    563  1.1  christos 
    564  1.1  christos       current_op->indirect.mod = ind_addr_op->modfield;
    565  1.1  christos       current_op->indirect.disp = disp_number;
    566  1.1  christos       current_op->indirect.ARnum = ar_number;
    567  1.1  christos       current_op->op_type = Indirect;
    568  1.1  christos     }
    569  1.1  christos   else
    570  1.1  christos     {
    571  1.1  christos       reg *regop = (reg *) hash_find (reg_hash, token);
    572  1.1  christos 
    573  1.1  christos       if (regop)
    574  1.1  christos 	{
    575  1.1  christos 	  debug ("Found register operand: %s\n", regop->name);
    576  1.1  christos 	  if (regop->regtype == REG_ARn)
    577  1.1  christos 	    current_op->op_type = ARn;
    578  1.1  christos 	  else if (regop->regtype == REG_Rn)
    579  1.1  christos 	    current_op->op_type = Rn;
    580  1.1  christos 	  else if (regop->regtype == REG_DP)
    581  1.1  christos 	    current_op->op_type = DPReg;
    582  1.1  christos 	  else
    583  1.1  christos 	    current_op->op_type = OtherReg;
    584  1.1  christos 	  current_op->reg.opcode = regop->opcode;
    585  1.1  christos 	}
    586  1.1  christos       else
    587  1.1  christos 	{
    588  1.1  christos 	  if (!is_digit_char (*token)
    589  1.1  christos 	      || *(token + 1) == 'x'
    590  1.1  christos 	      || strchr (token, 'h'))
    591  1.1  christos 	    {
    592  1.1  christos 	      char *save_input_line_pointer;
    593  1.1  christos 	      segT retval;
    594  1.1  christos 
    595  1.1  christos 	      debug ("Probably a label: %s\n", token);
    596  1.1  christos 	      current_op->immediate.label = malloc (strlen (token) + 1);
    597  1.1  christos 	      strcpy (current_op->immediate.label, token);
    598  1.1  christos 	      current_op->immediate.label[strlen (token)] = '\0';
    599  1.1  christos 	      save_input_line_pointer = input_line_pointer;
    600  1.1  christos 	      input_line_pointer = token;
    601  1.1  christos 
    602  1.1  christos 	      debug ("Current input_line_pointer: %s\n", input_line_pointer);
    603  1.1  christos 	      retval = expression (&current_op->immediate.imm_expr);
    604  1.1  christos 	      debug ("Expression type: %d\n",
    605  1.1  christos 		     current_op->immediate.imm_expr.X_op);
    606  1.1  christos 	      debug ("Expression addnum: %ld\n",
    607  1.1  christos 		     (long) current_op->immediate.imm_expr.X_add_number);
    608  1.1  christos 	      debug ("Segment: %p\n", retval);
    609  1.1  christos 	      input_line_pointer = save_input_line_pointer;
    610  1.1  christos 
    611  1.1  christos 	      if (current_op->immediate.imm_expr.X_op == O_constant)
    612  1.1  christos 		{
    613  1.1  christos 		  current_op->immediate.s_number
    614  1.1  christos 		    = current_op->immediate.imm_expr.X_add_number;
    615  1.1  christos 		  current_op->immediate.u_number
    616  1.1  christos 		    = (unsigned int) current_op->immediate.imm_expr.X_add_number;
    617  1.1  christos 		  current_op->immediate.resolved = 1;
    618  1.1  christos 		}
    619  1.1  christos 	    }
    620  1.1  christos 	  else
    621  1.1  christos 	    {
    622  1.1  christos 	      debug ("Found a number or displacement\n");
    623  1.1  christos 	      for (count = 0; count < strlen (token); count++)
    624  1.1  christos 		if (*(token + count) == '.')
    625  1.1  christos 		  current_op->immediate.decimal_found = 1;
    626  1.1  christos 	      current_op->immediate.label = malloc (strlen (token) + 1);
    627  1.1  christos 	      strcpy (current_op->immediate.label, token);
    628  1.1  christos 	      current_op->immediate.label[strlen (token)] = '\0';
    629  1.1  christos 	      current_op->immediate.f_number = (float) atof (token);
    630  1.1  christos 	      current_op->immediate.s_number = (int) atoi (token);
    631  1.1  christos 	      current_op->immediate.u_number = (unsigned int) atoi (token);
    632  1.1  christos 	      current_op->immediate.resolved = 1;
    633  1.1  christos 	    }
    634  1.1  christos 	  current_op->op_type = Disp | Abs24 | Imm16 | Imm24;
    635  1.1  christos 	  if (current_op->immediate.u_number <= 31)
    636  1.1  christos 	    current_op->op_type |= IVector;
    637  1.1  christos 	}
    638  1.1  christos     }
    639  1.1  christos   return current_op;
    640  1.1  christos }
    641  1.1  christos 
    642  1.1  christos struct tic30_par_insn
    643  1.1  christos {
    644  1.1  christos   partemplate *tm;		/* Template of current parallel instruction.  */
    645  1.1  christos   unsigned operands[2];		/* Number of given operands for each insn.  */
    646  1.1  christos   /* Type of operand given in instruction.  */
    647  1.1  christos   operand *operand_type[2][MAX_OPERANDS];
    648  1.1  christos   int swap_operands;		/* Whether to swap operands around.  */
    649  1.1  christos   unsigned p_field;		/* Value of p field in multiply add/sub instructions.  */
    650  1.1  christos   unsigned opcode;		/* Final opcode.  */
    651  1.1  christos };
    652  1.1  christos 
    653  1.1  christos struct tic30_par_insn p_insn;
    654  1.1  christos 
    655  1.1  christos static int
    656  1.1  christos tic30_parallel_insn (char *token)
    657  1.1  christos {
    658  1.1  christos   static partemplate *p_opcode;
    659  1.1  christos   char *current_posn = token;
    660  1.1  christos   char *token_start;
    661  1.1  christos   char save_char;
    662  1.1  christos 
    663  1.1  christos   debug ("In tic30_parallel_insn with %s\n", token);
    664  1.1  christos   memset (&p_insn, '\0', sizeof (p_insn));
    665  1.1  christos 
    666  1.1  christos   while (is_opcode_char (*current_posn))
    667  1.1  christos     current_posn++;
    668  1.1  christos   {
    669  1.1  christos     /* Find instruction.  */
    670  1.1  christos     save_char = *current_posn;
    671  1.1  christos     *current_posn = '\0';
    672  1.1  christos     p_opcode = (partemplate *) hash_find (parop_hash, token);
    673  1.1  christos     if (p_opcode)
    674  1.1  christos       {
    675  1.1  christos 	debug ("Found instruction %s\n", p_opcode->name);
    676  1.1  christos 	p_insn.tm = p_opcode;
    677  1.1  christos       }
    678  1.1  christos     else
    679  1.1  christos       {
    680  1.1  christos 	char first_opcode[6] = {0};
    681  1.1  christos 	char second_opcode[6] = {0};
    682  1.1  christos 	unsigned int i;
    683  1.1  christos 	int current_opcode = -1;
    684  1.1  christos 	int char_ptr = 0;
    685  1.1  christos 
    686  1.1  christos 	for (i = 0; i < strlen (token); i++)
    687  1.1  christos 	  {
    688  1.1  christos 	    char ch = *(token + i);
    689  1.1  christos 
    690  1.1  christos 	    if (ch == '_' && current_opcode == -1)
    691  1.1  christos 	      {
    692  1.1  christos 		current_opcode = 0;
    693  1.1  christos 		continue;
    694  1.1  christos 	      }
    695  1.1  christos 
    696  1.1  christos 	    if (ch == '_' && current_opcode == 0)
    697  1.1  christos 	      {
    698  1.1  christos 		current_opcode = 1;
    699  1.1  christos 		char_ptr = 0;
    700  1.1  christos 		continue;
    701  1.1  christos 	      }
    702  1.1  christos 
    703  1.1  christos 	    switch (current_opcode)
    704  1.1  christos 	      {
    705  1.1  christos 	      case 0:
    706  1.1  christos 		first_opcode[char_ptr++] = ch;
    707  1.1  christos 		break;
    708  1.1  christos 	      case 1:
    709  1.1  christos 		second_opcode[char_ptr++] = ch;
    710  1.1  christos 		break;
    711  1.1  christos 	      }
    712  1.1  christos 	  }
    713  1.1  christos 
    714  1.1  christos 	debug ("first_opcode = %s\n", first_opcode);
    715  1.1  christos 	debug ("second_opcode = %s\n", second_opcode);
    716  1.1  christos 	sprintf (token, "q_%s_%s", second_opcode, first_opcode);
    717  1.1  christos 	p_opcode = (partemplate *) hash_find (parop_hash, token);
    718  1.1  christos 
    719  1.1  christos 	if (p_opcode)
    720  1.1  christos 	  {
    721  1.1  christos 	    debug ("Found instruction %s\n", p_opcode->name);
    722  1.1  christos 	    p_insn.tm = p_opcode;
    723  1.1  christos 	    p_insn.swap_operands = 1;
    724  1.1  christos 	  }
    725  1.1  christos 	else
    726  1.1  christos 	  return 0;
    727  1.1  christos       }
    728  1.1  christos     *current_posn = save_char;
    729  1.1  christos   }
    730  1.1  christos 
    731  1.1  christos   {
    732  1.1  christos     /* Find operands.  */
    733  1.1  christos     int paren_not_balanced;
    734  1.1  christos     int expecting_operand = 0;
    735  1.1  christos     int found_separator = 0;
    736  1.1  christos 
    737  1.1  christos     do
    738  1.1  christos       {
    739  1.1  christos 	/* Skip optional white space before operand.  */
    740  1.1  christos 	while (!is_operand_char (*current_posn)
    741  1.1  christos 	       && *current_posn != END_OF_INSN)
    742  1.1  christos 	  {
    743  1.1  christos 	    if (!is_space_char (*current_posn)
    744  1.1  christos 		&& *current_posn != PARALLEL_SEPARATOR)
    745  1.1  christos 	      {
    746  1.1  christos 		as_bad (_("Invalid character %s before %s operand"),
    747  1.1  christos 			output_invalid (*current_posn),
    748  1.1  christos 			ordinal_names[insn.operands]);
    749  1.1  christos 		return 1;
    750  1.1  christos 	      }
    751  1.1  christos 	    if (*current_posn == PARALLEL_SEPARATOR)
    752  1.1  christos 	      found_separator = 1;
    753  1.1  christos 	    current_posn++;
    754  1.1  christos 	  }
    755  1.1  christos 
    756  1.1  christos 	token_start = current_posn;
    757  1.1  christos 	paren_not_balanced = 0;
    758  1.1  christos 
    759  1.1  christos 	while (paren_not_balanced || *current_posn != ',')
    760  1.1  christos 	  {
    761  1.1  christos 	    if (*current_posn == END_OF_INSN)
    762  1.1  christos 	      {
    763  1.1  christos 		if (paren_not_balanced)
    764  1.1  christos 		  {
    765  1.1  christos 		    as_bad (_("Unbalanced parenthesis in %s operand."),
    766  1.1  christos 			    ordinal_names[insn.operands]);
    767  1.1  christos 		    return 1;
    768  1.1  christos 		  }
    769  1.1  christos 		else
    770  1.1  christos 		  break;
    771  1.1  christos 	      }
    772  1.1  christos 	    else if (*current_posn == PARALLEL_SEPARATOR)
    773  1.1  christos 	      {
    774  1.1  christos 		while (is_space_char (*(current_posn - 1)))
    775  1.1  christos 		  current_posn--;
    776  1.1  christos 		break;
    777  1.1  christos 	      }
    778  1.1  christos 	    else if (!is_operand_char (*current_posn)
    779  1.1  christos 		     && !is_space_char (*current_posn))
    780  1.1  christos 	      {
    781  1.1  christos 		as_bad (_("Invalid character %s in %s operand"),
    782  1.1  christos 			output_invalid (*current_posn),
    783  1.1  christos 			ordinal_names[insn.operands]);
    784  1.1  christos 		return 1;
    785  1.1  christos 	      }
    786  1.1  christos 
    787  1.1  christos 	    if (*current_posn == '(')
    788  1.1  christos 	      ++paren_not_balanced;
    789  1.1  christos 	    if (*current_posn == ')')
    790  1.1  christos 	      --paren_not_balanced;
    791  1.1  christos 	    current_posn++;
    792  1.1  christos 	  }
    793  1.1  christos 
    794  1.1  christos 	if (current_posn != token_start)
    795  1.1  christos 	  {
    796  1.1  christos 	    /* Yes, we've read in another operand.  */
    797  1.1  christos 	    p_insn.operands[found_separator]++;
    798  1.1  christos 	    if (p_insn.operands[found_separator] > MAX_OPERANDS)
    799  1.1  christos 	      {
    800  1.1  christos 		as_bad (_("Spurious operands; (%d operands/instruction max)"),
    801  1.1  christos 			MAX_OPERANDS);
    802  1.1  christos 		return 1;
    803  1.1  christos 	      }
    804  1.1  christos 
    805  1.1  christos 	    /* Now parse operand adding info to 'insn' as we go along.  */
    806  1.1  christos 	    save_char = *current_posn;
    807  1.1  christos 	    *current_posn = '\0';
    808  1.1  christos 	    p_insn.operand_type[found_separator][p_insn.operands[found_separator] - 1] =
    809  1.1  christos 	      tic30_operand (token_start);
    810  1.1  christos 	    *current_posn = save_char;
    811  1.1  christos 	    if (!p_insn.operand_type[found_separator][p_insn.operands[found_separator] - 1])
    812  1.1  christos 	      return 1;
    813  1.1  christos 	  }
    814  1.1  christos 	else
    815  1.1  christos 	  {
    816  1.1  christos 	    if (expecting_operand)
    817  1.1  christos 	      {
    818  1.1  christos 		as_bad (_("Expecting operand after ','; got nothing"));
    819  1.1  christos 		return 1;
    820  1.1  christos 	      }
    821  1.1  christos 	    if (*current_posn == ',')
    822  1.1  christos 	      {
    823  1.1  christos 		as_bad (_("Expecting operand before ','; got nothing"));
    824  1.1  christos 		return 1;
    825  1.1  christos 	      }
    826  1.1  christos 	  }
    827  1.1  christos 
    828  1.1  christos 	/* Now *current_posn must be either ',' or END_OF_INSN.  */
    829  1.1  christos 	if (*current_posn == ',')
    830  1.1  christos 	  {
    831  1.1  christos 	    if (*++current_posn == END_OF_INSN)
    832  1.1  christos 	      {
    833  1.1  christos 		/* Just skip it, if it's \n complain.  */
    834  1.1  christos 		as_bad (_("Expecting operand after ','; got nothing"));
    835  1.1  christos 		return 1;
    836  1.1  christos 	      }
    837  1.1  christos 	    expecting_operand = 1;
    838  1.1  christos 	  }
    839  1.1  christos       }
    840  1.1  christos     while (*current_posn != END_OF_INSN);
    841  1.1  christos   }
    842  1.1  christos 
    843  1.1  christos   if (p_insn.swap_operands)
    844  1.1  christos     {
    845  1.1  christos       int temp_num, i;
    846  1.1  christos       operand *temp_op;
    847  1.1  christos 
    848  1.1  christos       temp_num = p_insn.operands[0];
    849  1.1  christos       p_insn.operands[0] = p_insn.operands[1];
    850  1.1  christos       p_insn.operands[1] = temp_num;
    851  1.1  christos       for (i = 0; i < MAX_OPERANDS; i++)
    852  1.1  christos 	{
    853  1.1  christos 	  temp_op = p_insn.operand_type[0][i];
    854  1.1  christos 	  p_insn.operand_type[0][i] = p_insn.operand_type[1][i];
    855  1.1  christos 	  p_insn.operand_type[1][i] = temp_op;
    856  1.1  christos 	}
    857  1.1  christos     }
    858  1.1  christos 
    859  1.1  christos   if (p_insn.operands[0] != p_insn.tm->operands_1)
    860  1.1  christos     {
    861  1.1  christos       as_bad (_("incorrect number of operands given in the first instruction"));
    862  1.1  christos       return 1;
    863  1.1  christos     }
    864  1.1  christos 
    865  1.1  christos   if (p_insn.operands[1] != p_insn.tm->operands_2)
    866  1.1  christos     {
    867  1.1  christos       as_bad (_("incorrect number of operands given in the second instruction"));
    868  1.1  christos       return 1;
    869  1.1  christos     }
    870  1.1  christos 
    871  1.1  christos   debug ("Number of operands in first insn: %d\n", p_insn.operands[0]);
    872  1.1  christos   debug ("Number of operands in second insn: %d\n", p_insn.operands[1]);
    873  1.1  christos 
    874  1.1  christos   {
    875  1.1  christos     /* Now check if operands are correct.  */
    876  1.1  christos     int count;
    877  1.1  christos     int num_rn = 0;
    878  1.1  christos     int num_ind = 0;
    879  1.1  christos 
    880  1.1  christos     for (count = 0; count < 2; count++)
    881  1.1  christos       {
    882  1.1  christos 	unsigned int i;
    883  1.1  christos 	for (i = 0; i < p_insn.operands[count]; i++)
    884  1.1  christos 	  {
    885  1.1  christos 	    if ((p_insn.operand_type[count][i]->op_type &
    886  1.1  christos 		 p_insn.tm->operand_types[count][i]) == 0)
    887  1.1  christos 	      {
    888  1.1  christos 		as_bad (_("%s instruction, operand %d doesn't match"),
    889  1.1  christos 			ordinal_names[count], i + 1);
    890  1.1  christos 		return 1;
    891  1.1  christos 	      }
    892  1.1  christos 
    893  1.1  christos 	    /* Get number of R register and indirect reference contained
    894  1.1  christos 	       within the first two operands of each instruction.  This is
    895  1.1  christos 	       required for the multiply parallel instructions which require
    896  1.1  christos 	       two R registers and two indirect references, but not in any
    897  1.1  christos 	       particular place.  */
    898  1.1  christos 	    if ((p_insn.operand_type[count][i]->op_type & Rn) && i < 2)
    899  1.1  christos 	      num_rn++;
    900  1.1  christos 	    else if ((p_insn.operand_type[count][i]->op_type & Indirect)
    901  1.1  christos 		     && i < 2)
    902  1.1  christos 	      num_ind++;
    903  1.1  christos 	  }
    904  1.1  christos       }
    905  1.1  christos 
    906  1.1  christos     if ((p_insn.tm->operand_types[0][0] & (Indirect | Rn))
    907  1.1  christos 	== (Indirect | Rn))
    908  1.1  christos       {
    909  1.1  christos 	/* Check for the multiply instructions.  */
    910  1.1  christos 	if (num_rn != 2)
    911  1.1  christos 	  {
    912  1.1  christos 	    as_bad (_("incorrect format for multiply parallel instruction"));
    913  1.1  christos 	    return 1;
    914  1.1  christos 	  }
    915  1.1  christos 
    916  1.1  christos 	if (num_ind != 2)
    917  1.1  christos 	  {
    918  1.1  christos 	    /* Shouldn't get here.  */
    919  1.1  christos 	    as_bad (_("incorrect format for multiply parallel instruction"));
    920  1.1  christos 	    return 1;
    921  1.1  christos 	  }
    922  1.1  christos 
    923  1.1  christos 	if ((p_insn.operand_type[0][2]->reg.opcode != 0x00)
    924  1.1  christos 	    && (p_insn.operand_type[0][2]->reg.opcode != 0x01))
    925  1.1  christos 	  {
    926  1.1  christos 	    as_bad (_("destination for multiply can only be R0 or R1"));
    927  1.1  christos 	    return 1;
    928  1.1  christos 	  }
    929  1.1  christos 
    930  1.1  christos 	if ((p_insn.operand_type[1][2]->reg.opcode != 0x02)
    931  1.1  christos 	    && (p_insn.operand_type[1][2]->reg.opcode != 0x03))
    932  1.1  christos 	  {
    933  1.1  christos 	    as_bad (_("destination for add/subtract can only be R2 or R3"));
    934  1.1  christos 	    return 1;
    935  1.1  christos 	  }
    936  1.1  christos 
    937  1.1  christos 	/* Now determine the P field for the instruction.  */
    938  1.1  christos 	if (p_insn.operand_type[0][0]->op_type & Indirect)
    939  1.1  christos 	  {
    940  1.1  christos 	    if (p_insn.operand_type[0][1]->op_type & Indirect)
    941  1.1  christos 	      p_insn.p_field = 0x00000000;	/* Ind * Ind, Rn  +/- Rn.  */
    942  1.1  christos 	    else if (p_insn.operand_type[1][0]->op_type & Indirect)
    943  1.1  christos 	      p_insn.p_field = 0x01000000;	/* Ind * Rn,  Ind +/- Rn.  */
    944  1.1  christos 	    else
    945  1.1  christos 	      p_insn.p_field = 0x03000000;	/* Ind * Rn,  Rn  +/- Ind.  */
    946  1.1  christos 	  }
    947  1.1  christos 	else
    948  1.1  christos 	  {
    949  1.1  christos 	    if (p_insn.operand_type[0][1]->op_type & Rn)
    950  1.1  christos 	      p_insn.p_field = 0x02000000;	/* Rn  * Rn,  Ind +/- Ind.  */
    951  1.1  christos 	    else if (p_insn.operand_type[1][0]->op_type & Indirect)
    952  1.1  christos 	      {
    953  1.1  christos 		operand *temp;
    954  1.1  christos 		p_insn.p_field = 0x01000000;	/* Rn  * Ind, Ind +/- Rn.  */
    955  1.1  christos 		/* Need to swap the two multiply operands around so that
    956  1.1  christos 		   everything is in its place for the opcode makeup.
    957  1.1  christos 		   ie so Ind * Rn, Ind +/- Rn.  */
    958  1.1  christos 		temp = p_insn.operand_type[0][0];
    959  1.1  christos 		p_insn.operand_type[0][0] = p_insn.operand_type[0][1];
    960  1.1  christos 		p_insn.operand_type[0][1] = temp;
    961  1.1  christos 	      }
    962  1.1  christos 	    else
    963  1.1  christos 	      {
    964  1.1  christos 		operand *temp;
    965  1.1  christos 		p_insn.p_field = 0x03000000;	/* Rn  * Ind, Rn  +/- Ind.  */
    966  1.1  christos 		temp = p_insn.operand_type[0][0];
    967  1.1  christos 		p_insn.operand_type[0][0] = p_insn.operand_type[0][1];
    968  1.1  christos 		p_insn.operand_type[0][1] = temp;
    969  1.1  christos 	      }
    970  1.1  christos 	  }
    971  1.1  christos       }
    972  1.1  christos   }
    973  1.1  christos 
    974  1.1  christos   debug ("P field: %08X\n", p_insn.p_field);
    975  1.1  christos 
    976  1.1  christos   /* Finalise opcode.  This is easier for parallel instructions as they have
    977  1.1  christos      to be fully resolved, there are no memory addresses allowed, except
    978  1.1  christos      through indirect addressing, so there are no labels to resolve.  */
    979  1.1  christos   p_insn.opcode = p_insn.tm->base_opcode;
    980  1.1  christos 
    981  1.1  christos   switch (p_insn.tm->oporder)
    982  1.1  christos     {
    983  1.1  christos     case OO_4op1:
    984  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum);
    985  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 3);
    986  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
    987  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
    988  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
    989  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 22);
    990  1.1  christos       break;
    991  1.1  christos 
    992  1.1  christos     case OO_4op2:
    993  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum);
    994  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 3);
    995  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.ARnum << 8);
    996  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.mod << 11);
    997  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->reg.opcode << 19);
    998  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 22);
    999  1.1  christos       if (p_insn.operand_type[1][1]->reg.opcode == p_insn.operand_type[0][1]->reg.opcode)
   1000  1.1  christos 	as_warn (_("loading the same register in parallel operation"));
   1001  1.1  christos       break;
   1002  1.1  christos 
   1003  1.1  christos     case OO_4op3:
   1004  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.ARnum);
   1005  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.mod << 3);
   1006  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
   1007  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
   1008  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
   1009  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->reg.opcode << 22);
   1010  1.1  christos       break;
   1011  1.1  christos 
   1012  1.1  christos     case OO_5op1:
   1013  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum);
   1014  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 3);
   1015  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
   1016  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
   1017  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
   1018  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 19);
   1019  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][2]->reg.opcode << 22);
   1020  1.1  christos       break;
   1021  1.1  christos 
   1022  1.1  christos     case OO_5op2:
   1023  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.ARnum);
   1024  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.mod << 3);
   1025  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum << 8);
   1026  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 11);
   1027  1.1  christos       p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
   1028  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][0]->reg.opcode << 19);
   1029  1.1  christos       p_insn.opcode |= (p_insn.operand_type[0][2]->reg.opcode << 22);
   1030  1.1  christos       break;
   1031  1.1  christos 
   1032  1.1  christos     case OO_PField:
   1033  1.1  christos       p_insn.opcode |= p_insn.p_field;
   1034  1.1  christos       if (p_insn.operand_type[0][2]->reg.opcode == 0x01)
   1035  1.1  christos 	p_insn.opcode |= 0x00800000;
   1036  1.1  christos       if (p_insn.operand_type[1][2]->reg.opcode == 0x03)
   1037  1.1  christos 	p_insn.opcode |= 0x00400000;
   1038  1.1  christos 
   1039  1.1  christos       switch (p_insn.p_field)
   1040  1.1  christos 	{
   1041  1.1  christos 	case 0x00000000:
   1042  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.ARnum);
   1043  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][1]->indirect.mod << 3);
   1044  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum << 8);
   1045  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 11);
   1046  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][1]->reg.opcode << 16);
   1047  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 19);
   1048  1.1  christos 	  break;
   1049  1.1  christos 	case 0x01000000:
   1050  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.ARnum);
   1051  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.mod << 3);
   1052  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum << 8);
   1053  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 11);
   1054  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][1]->reg.opcode << 16);
   1055  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 19);
   1056  1.1  christos 	  break;
   1057  1.1  christos 	case 0x02000000:
   1058  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum);
   1059  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 3);
   1060  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.ARnum << 8);
   1061  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][0]->indirect.mod << 11);
   1062  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 16);
   1063  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->reg.opcode << 19);
   1064  1.1  christos 	  break;
   1065  1.1  christos 	case 0x03000000:
   1066  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.ARnum);
   1067  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][1]->indirect.mod << 3);
   1068  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.ARnum << 8);
   1069  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][0]->indirect.mod << 11);
   1070  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[1][0]->reg.opcode << 16);
   1071  1.1  christos 	  p_insn.opcode |= (p_insn.operand_type[0][1]->reg.opcode << 19);
   1072  1.1  christos 	  break;
   1073  1.1  christos 	}
   1074  1.1  christos       break;
   1075  1.1  christos     }
   1076  1.1  christos 
   1077  1.1  christos   {
   1078  1.1  christos     char *p;
   1079  1.1  christos 
   1080  1.1  christos     p = frag_more (INSN_SIZE);
   1081  1.1  christos     md_number_to_chars (p, (valueT) p_insn.opcode, INSN_SIZE);
   1082  1.1  christos   }
   1083  1.1  christos 
   1084  1.1  christos   {
   1085  1.1  christos     unsigned int i, j;
   1086  1.1  christos 
   1087  1.1  christos     for (i = 0; i < 2; i++)
   1088  1.1  christos       for (j = 0; j < p_insn.operands[i]; j++)
   1089  1.1  christos 	free (p_insn.operand_type[i][j]);
   1090  1.1  christos   }
   1091  1.1  christos 
   1092  1.1  christos   debug ("Final opcode: %08X\n", p_insn.opcode);
   1093  1.1  christos   debug ("\n");
   1094  1.1  christos 
   1095  1.1  christos   return 1;
   1096  1.1  christos }
   1097  1.1  christos 
   1098  1.1  christos /* In order to get gas to ignore any | chars at the start of a line,
   1099  1.1  christos    this function returns true if a | is found in a line.  */
   1100  1.1  christos 
   1101  1.1  christos int
   1102  1.1  christos tic30_unrecognized_line (int c)
   1103  1.1  christos {
   1104  1.1  christos   debug ("In tc_unrecognized_line\n");
   1105  1.1  christos   return (c == PARALLEL_SEPARATOR);
   1106  1.1  christos }
   1107  1.1  christos 
   1108  1.1  christos int
   1109  1.1  christos md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
   1110  1.1  christos 			       segT segment ATTRIBUTE_UNUSED)
   1111  1.1  christos {
   1112  1.1  christos   debug ("In md_estimate_size_before_relax()\n");
   1113  1.1  christos   return 0;
   1114  1.1  christos }
   1115  1.1  christos 
   1116  1.1  christos void
   1117  1.1  christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   1118  1.1  christos 		 segT sec ATTRIBUTE_UNUSED,
   1119  1.3  christos 		 fragS *fragP ATTRIBUTE_UNUSED)
   1120  1.1  christos {
   1121  1.1  christos   debug ("In md_convert_frag()\n");
   1122  1.1  christos }
   1123  1.1  christos 
   1124  1.1  christos void
   1125  1.1  christos md_apply_fix (fixS *fixP,
   1126  1.1  christos 	       valueT *valP,
   1127  1.1  christos 	       segT seg ATTRIBUTE_UNUSED)
   1128  1.1  christos {
   1129  1.1  christos   valueT value = *valP;
   1130  1.1  christos 
   1131  1.1  christos   debug ("In md_apply_fix() with value = %ld\n", (long) value);
   1132  1.1  christos   debug ("Values in fixP\n");
   1133  1.1  christos   debug ("fx_size = %d\n", fixP->fx_size);
   1134  1.1  christos   debug ("fx_pcrel = %d\n", fixP->fx_pcrel);
   1135  1.1  christos   debug ("fx_where = %ld\n", fixP->fx_where);
   1136  1.1  christos   debug ("fx_offset = %d\n", (int) fixP->fx_offset);
   1137  1.1  christos   {
   1138  1.1  christos     char *buf = fixP->fx_frag->fr_literal + fixP->fx_where;
   1139  1.1  christos 
   1140  1.1  christos     value /= INSN_SIZE;
   1141  1.1  christos     if (fixP->fx_size == 1)
   1142  1.1  christos       /* Special fix for LDP instruction.  */
   1143  1.1  christos       value = (value & 0x00FF0000) >> 16;
   1144  1.1  christos 
   1145  1.1  christos     debug ("new value = %ld\n", (long) value);
   1146  1.1  christos     md_number_to_chars (buf, value, fixP->fx_size);
   1147  1.1  christos   }
   1148  1.1  christos 
   1149  1.1  christos   if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
   1150  1.1  christos     fixP->fx_done = 1;
   1151  1.1  christos }
   1152  1.1  christos 
   1153  1.1  christos int
   1154  1.1  christos md_parse_option (int c ATTRIBUTE_UNUSED,
   1155  1.1  christos 		 char *arg ATTRIBUTE_UNUSED)
   1156  1.1  christos {
   1157  1.1  christos   debug ("In md_parse_option()\n");
   1158  1.1  christos   return 0;
   1159  1.1  christos }
   1160  1.1  christos 
   1161  1.1  christos void
   1162  1.1  christos md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
   1163  1.1  christos {
   1164  1.1  christos   debug ("In md_show_usage()\n");
   1165  1.1  christos }
   1166  1.1  christos 
   1167  1.1  christos symbolS *
   1168  1.1  christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
   1169  1.1  christos {
   1170  1.1  christos   debug ("In md_undefined_symbol()\n");
   1171  1.1  christos   return (symbolS *) 0;
   1172  1.1  christos }
   1173  1.1  christos 
   1174  1.1  christos valueT
   1175  1.1  christos md_section_align (segT segment, valueT size)
   1176  1.1  christos {
   1177  1.1  christos   debug ("In md_section_align() segment = %p and size = %lu\n",
   1178  1.1  christos 	 segment, (unsigned long) size);
   1179  1.1  christos   size = (size + 3) / 4;
   1180  1.1  christos   size *= 4;
   1181  1.1  christos   debug ("New size value = %lu\n", (unsigned long) size);
   1182  1.1  christos   return size;
   1183  1.1  christos }
   1184  1.1  christos 
   1185  1.1  christos long
   1186  1.1  christos md_pcrel_from (fixS *fixP)
   1187  1.1  christos {
   1188  1.1  christos   int offset;
   1189  1.1  christos 
   1190  1.1  christos   debug ("In md_pcrel_from()\n");
   1191  1.1  christos   debug ("fx_where = %ld\n", fixP->fx_where);
   1192  1.1  christos   debug ("fx_size = %d\n", fixP->fx_size);
   1193  1.1  christos   /* Find the opcode that represents the current instruction in the
   1194  1.1  christos      fr_literal storage area, and check bit 21.  Bit 21 contains whether the
   1195  1.1  christos      current instruction is a delayed one or not, and then set the offset
   1196  1.1  christos      value appropriately.  */
   1197  1.1  christos   if (fixP->fx_frag->fr_literal[fixP->fx_where - fixP->fx_size + 1] & 0x20)
   1198  1.1  christos     offset = 3;
   1199  1.1  christos   else
   1200  1.1  christos     offset = 1;
   1201  1.1  christos   debug ("offset = %d\n", offset);
   1202  1.1  christos   /* PC Relative instructions have a format:
   1203  1.1  christos      displacement = Label - (PC + offset)
   1204  1.1  christos      This function returns PC + offset where:
   1205  1.1  christos      fx_where - fx_size = PC
   1206  1.1  christos      INSN_SIZE * offset = offset number of instructions.  */
   1207  1.1  christos   return fixP->fx_where - fixP->fx_size + (INSN_SIZE * offset);
   1208  1.1  christos }
   1209  1.1  christos 
   1210  1.1  christos char *
   1211  1.1  christos md_atof (int what_statement_type,
   1212  1.1  christos 	 char *literalP,
   1213  1.1  christos 	 int *sizeP)
   1214  1.1  christos {
   1215  1.1  christos   int prec;
   1216  1.1  christos   char *token;
   1217  1.1  christos   char keepval;
   1218  1.1  christos   unsigned long value;
   1219  1.1  christos   float float_value;
   1220  1.1  christos 
   1221  1.1  christos   debug ("In md_atof()\n");
   1222  1.1  christos   debug ("precision = %c\n", what_statement_type);
   1223  1.1  christos   debug ("literal = %s\n", literalP);
   1224  1.1  christos   debug ("line = ");
   1225  1.1  christos   token = input_line_pointer;
   1226  1.1  christos   while (!is_end_of_line[(unsigned char) *input_line_pointer]
   1227  1.1  christos 	 && (*input_line_pointer != ','))
   1228  1.1  christos     {
   1229  1.1  christos       debug ("%c", *input_line_pointer);
   1230  1.1  christos       input_line_pointer++;
   1231  1.1  christos     }
   1232  1.1  christos 
   1233  1.1  christos   keepval = *input_line_pointer;
   1234  1.1  christos   *input_line_pointer = '\0';
   1235  1.1  christos   debug ("\n");
   1236  1.1  christos   float_value = (float) atof (token);
   1237  1.1  christos   *input_line_pointer = keepval;
   1238  1.1  christos   debug ("float_value = %f\n", float_value);
   1239  1.1  christos 
   1240  1.1  christos   switch (what_statement_type)
   1241  1.1  christos     {
   1242  1.1  christos     case 'f':
   1243  1.1  christos     case 'F':
   1244  1.1  christos     case 's':
   1245  1.1  christos     case 'S':
   1246  1.1  christos       prec = 2;
   1247  1.1  christos       break;
   1248  1.1  christos 
   1249  1.1  christos     case 'd':
   1250  1.1  christos     case 'D':
   1251  1.1  christos     case 'r':
   1252  1.1  christos     case 'R':
   1253  1.1  christos       prec = 4;
   1254  1.1  christos       break;
   1255  1.1  christos 
   1256  1.1  christos     default:
   1257  1.1  christos       *sizeP = 0;
   1258  1.1  christos       return _("Unrecognized or unsupported floating point constant");
   1259  1.1  christos     }
   1260  1.1  christos 
   1261  1.1  christos   if (float_value == 0.0)
   1262  1.1  christos     value = (prec == 2) ? 0x00008000L : 0x80000000L;
   1263  1.1  christos   else
   1264  1.1  christos     {
   1265  1.1  christos       unsigned long exp, sign, mant, tmsfloat;
   1266  1.1  christos       union
   1267  1.1  christos       {
   1268  1.1  christos 	float f;
   1269  1.1  christos 	long  l;
   1270  1.1  christos       }
   1271  1.1  christos       converter;
   1272  1.1  christos 
   1273  1.1  christos       converter.f = float_value;
   1274  1.1  christos       tmsfloat = converter.l;
   1275  1.1  christos       sign = tmsfloat & 0x80000000;
   1276  1.1  christos       mant = tmsfloat & 0x007FFFFF;
   1277  1.1  christos       exp = tmsfloat & 0x7F800000;
   1278  1.1  christos       exp <<= 1;
   1279  1.1  christos       if (exp == 0xFF000000)
   1280  1.1  christos 	{
   1281  1.1  christos 	  if (mant == 0)
   1282  1.1  christos 	    value = 0x7F7FFFFF;
   1283  1.1  christos 	  else if (sign == 0)
   1284  1.1  christos 	    value = 0x7F7FFFFF;
   1285  1.1  christos 	  else
   1286  1.1  christos 	    value = 0x7F800000;
   1287  1.1  christos 	}
   1288  1.1  christos       else
   1289  1.1  christos 	{
   1290  1.1  christos 	  exp -= 0x7F000000;
   1291  1.1  christos 	  if (sign)
   1292  1.1  christos 	    {
   1293  1.1  christos 	      mant = mant & 0x007FFFFF;
   1294  1.1  christos 	      mant = -mant;
   1295  1.1  christos 	      mant = mant & 0x00FFFFFF;
   1296  1.1  christos 	      if (mant == 0)
   1297  1.1  christos 		{
   1298  1.1  christos 		  mant |= 0x00800000;
   1299  1.1  christos 		  exp = (long) exp - 0x01000000;
   1300  1.1  christos 		}
   1301  1.1  christos 	    }
   1302  1.1  christos 	  tmsfloat = exp | mant;
   1303  1.1  christos 	  value = tmsfloat;
   1304  1.1  christos 	}
   1305  1.1  christos       if (prec == 2)
   1306  1.1  christos 	{
   1307  1.1  christos 	  long expon, mantis;
   1308  1.1  christos 
   1309  1.1  christos 	  if (tmsfloat == 0x80000000)
   1310  1.1  christos 	    value = 0x8000;
   1311  1.1  christos 	  else
   1312  1.1  christos 	    {
   1313  1.1  christos 	      value = 0;
   1314  1.1  christos 	      expon = (tmsfloat & 0xFF000000);
   1315  1.1  christos 	      expon >>= 24;
   1316  1.1  christos 	      mantis = tmsfloat & 0x007FFFFF;
   1317  1.1  christos 	      if (tmsfloat & 0x00800000)
   1318  1.1  christos 		{
   1319  1.1  christos 		  mantis |= 0xFF000000;
   1320  1.1  christos 		  mantis += 0x00000800;
   1321  1.1  christos 		  mantis >>= 12;
   1322  1.1  christos 		  mantis |= 0x00000800;
   1323  1.1  christos 		  mantis &= 0x0FFF;
   1324  1.1  christos 		  if (expon > 7)
   1325  1.1  christos 		    value = 0x7800;
   1326  1.1  christos 		}
   1327  1.1  christos 	      else
   1328  1.1  christos 		{
   1329  1.1  christos 		  mantis |= 0x00800000;
   1330  1.1  christos 		  mantis += 0x00000800;
   1331  1.1  christos 		  expon += (mantis >> 24);
   1332  1.1  christos 		  mantis >>= 12;
   1333  1.1  christos 		  mantis &= 0x07FF;
   1334  1.1  christos 		  if (expon > 7)
   1335  1.1  christos 		    value = 0x77FF;
   1336  1.1  christos 		}
   1337  1.1  christos 	      if (expon < -8)
   1338  1.1  christos 		value = 0x8000;
   1339  1.1  christos 	      if (value == 0)
   1340  1.1  christos 		{
   1341  1.1  christos 		  mantis = (expon << 12) | mantis;
   1342  1.1  christos 		  value = mantis & 0xFFFF;
   1343  1.1  christos 		}
   1344  1.1  christos 	    }
   1345  1.1  christos 	}
   1346  1.1  christos     }
   1347  1.1  christos   md_number_to_chars (literalP, value, prec);
   1348  1.1  christos   *sizeP = prec;
   1349  1.1  christos   return NULL;
   1350  1.1  christos }
   1351  1.1  christos 
   1352  1.1  christos void
   1353  1.1  christos md_number_to_chars (char *buf, valueT val, int n)
   1354  1.1  christos {
   1355  1.1  christos   debug ("In md_number_to_chars()\n");
   1356  1.1  christos   number_to_chars_bigendian (buf, val, n);
   1357  1.1  christos }
   1358  1.1  christos 
   1359  1.1  christos #define F(SZ,PCREL)		(((SZ) << 1) + (PCREL))
   1360  1.1  christos #define MAP(SZ,PCREL,TYPE)	case F(SZ,PCREL): code = (TYPE); break
   1361  1.1  christos 
   1362  1.1  christos arelent *
   1363  1.1  christos tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
   1364  1.1  christos {
   1365  1.1  christos   arelent *rel;
   1366  1.1  christos   bfd_reloc_code_real_type code = 0;
   1367  1.1  christos 
   1368  1.1  christos   debug ("In tc_gen_reloc()\n");
   1369  1.1  christos   debug ("fixP.size = %d\n", fixP->fx_size);
   1370  1.1  christos   debug ("fixP.pcrel = %d\n", fixP->fx_pcrel);
   1371  1.1  christos   debug ("addsy.name = %s\n", S_GET_NAME (fixP->fx_addsy));
   1372  1.1  christos 
   1373  1.1  christos   switch (F (fixP->fx_size, fixP->fx_pcrel))
   1374  1.1  christos     {
   1375  1.1  christos       MAP (1, 0, BFD_RELOC_TIC30_LDP);
   1376  1.1  christos       MAP (2, 0, BFD_RELOC_16);
   1377  1.1  christos       MAP (3, 0, BFD_RELOC_24);
   1378  1.1  christos       MAP (2, 1, BFD_RELOC_16_PCREL);
   1379  1.1  christos       MAP (4, 0, BFD_RELOC_32);
   1380  1.1  christos     default:
   1381  1.1  christos       as_bad (_("Can not do %d byte %srelocation"), fixP->fx_size,
   1382  1.1  christos 	      fixP->fx_pcrel ? _("pc-relative ") : "");
   1383  1.1  christos     }
   1384  1.1  christos #undef MAP
   1385  1.1  christos #undef F
   1386  1.1  christos 
   1387  1.1  christos   rel = xmalloc (sizeof (* rel));
   1388  1.1  christos   gas_assert (rel != 0);
   1389  1.1  christos   rel->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
   1390  1.1  christos   *rel->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   1391  1.1  christos   rel->address = fixP->fx_frag->fr_address + fixP->fx_where;
   1392  1.1  christos   rel->addend = 0;
   1393  1.1  christos   rel->howto = bfd_reloc_type_lookup (stdoutput, code);
   1394  1.1  christos   if (!rel->howto)
   1395  1.1  christos     {
   1396  1.1  christos       const char *name;
   1397  1.1  christos 
   1398  1.1  christos       name = S_GET_NAME (fixP->fx_addsy);
   1399  1.1  christos       if (name == NULL)
   1400  1.1  christos 	name = "<unknown>";
   1401  1.1  christos       as_fatal ("Cannot generate relocation type for symbol %s, code %s",
   1402  1.1  christos 		name, bfd_get_reloc_code_name (code));
   1403  1.1  christos     }
   1404  1.1  christos   return rel;
   1405  1.1  christos }
   1406  1.1  christos 
   1407  1.1  christos void
   1408  1.1  christos md_operand (expressionS *expressionP ATTRIBUTE_UNUSED)
   1409  1.1  christos {
   1410  1.1  christos   debug ("In md_operand()\n");
   1411  1.1  christos }
   1412  1.1  christos 
   1413  1.1  christos void
   1414  1.1  christos md_assemble (char *line)
   1415  1.1  christos {
   1416  1.1  christos   insn_template *op;
   1417  1.1  christos   char *current_posn;
   1418  1.1  christos   char *token_start;
   1419  1.1  christos   char save_char;
   1420  1.1  christos   unsigned int count;
   1421  1.1  christos 
   1422  1.1  christos   debug ("In md_assemble() with argument %s\n", line);
   1423  1.1  christos   memset (&insn, '\0', sizeof (insn));
   1424  1.1  christos   if (found_parallel_insn)
   1425  1.1  christos     {
   1426  1.1  christos       debug ("Line is second part of parallel instruction\n\n");
   1427  1.1  christos       found_parallel_insn = 0;
   1428  1.1  christos       return;
   1429  1.1  christos     }
   1430  1.1  christos   if ((current_posn =
   1431  1.1  christos        tic30_find_parallel_insn (line, input_line_pointer + 1)) == NULL)
   1432  1.1  christos     current_posn = line;
   1433  1.1  christos   else
   1434  1.1  christos     found_parallel_insn = 1;
   1435  1.1  christos 
   1436  1.1  christos   while (is_space_char (*current_posn))
   1437  1.1  christos     current_posn++;
   1438  1.1  christos 
   1439  1.1  christos   token_start = current_posn;
   1440  1.1  christos 
   1441  1.1  christos   if (!is_opcode_char (*current_posn))
   1442  1.1  christos     {
   1443  1.1  christos       as_bad (_("Invalid character %s in opcode"),
   1444  1.1  christos 	      output_invalid (*current_posn));
   1445  1.1  christos       return;
   1446  1.1  christos     }
   1447  1.1  christos   /* Check if instruction is a parallel instruction
   1448  1.1  christos      by seeing if the first character is a q.  */
   1449  1.1  christos   if (*token_start == 'q')
   1450  1.1  christos     {
   1451  1.1  christos       if (tic30_parallel_insn (token_start))
   1452  1.1  christos 	{
   1453  1.1  christos 	  if (found_parallel_insn)
   1454  1.1  christos 	    free (token_start);
   1455  1.1  christos 	  return;
   1456  1.1  christos 	}
   1457  1.1  christos     }
   1458  1.1  christos   while (is_opcode_char (*current_posn))
   1459  1.1  christos     current_posn++;
   1460  1.1  christos   {
   1461  1.1  christos     /* Find instruction.  */
   1462  1.1  christos     save_char = *current_posn;
   1463  1.1  christos     *current_posn = '\0';
   1464  1.1  christos     op = (insn_template *) hash_find (op_hash, token_start);
   1465  1.1  christos     if (op)
   1466  1.1  christos       {
   1467  1.1  christos 	debug ("Found instruction %s\n", op->name);
   1468  1.1  christos 	insn.tm = op;
   1469  1.1  christos       }
   1470  1.1  christos     else
   1471  1.1  christos       {
   1472  1.1  christos 	debug ("Didn't find insn\n");
   1473  1.1  christos 	as_bad (_("Unknown TMS320C30 instruction: %s"), token_start);
   1474  1.1  christos 	return;
   1475  1.1  christos       }
   1476  1.1  christos     *current_posn = save_char;
   1477  1.1  christos   }
   1478  1.1  christos 
   1479  1.1  christos   if (*current_posn != END_OF_INSN)
   1480  1.1  christos     {
   1481  1.1  christos       /* Find operands.  */
   1482  1.1  christos       int paren_not_balanced;
   1483  1.1  christos       int expecting_operand = 0;
   1484  1.1  christos       int this_operand;
   1485  1.1  christos       do
   1486  1.1  christos 	{
   1487  1.1  christos 	  /* Skip optional white space before operand.  */
   1488  1.1  christos 	  while (!is_operand_char (*current_posn)
   1489  1.1  christos 		 && *current_posn != END_OF_INSN)
   1490  1.1  christos 	    {
   1491  1.1  christos 	      if (!is_space_char (*current_posn))
   1492  1.1  christos 		{
   1493  1.1  christos 		  as_bad (_("Invalid character %s before %s operand"),
   1494  1.1  christos 			  output_invalid (*current_posn),
   1495  1.1  christos 			  ordinal_names[insn.operands]);
   1496  1.1  christos 		  return;
   1497  1.1  christos 		}
   1498  1.1  christos 	      current_posn++;
   1499  1.1  christos 	    }
   1500  1.1  christos 	  token_start = current_posn;
   1501  1.1  christos 	  paren_not_balanced = 0;
   1502  1.1  christos 	  while (paren_not_balanced || *current_posn != ',')
   1503  1.1  christos 	    {
   1504  1.1  christos 	      if (*current_posn == END_OF_INSN)
   1505  1.1  christos 		{
   1506  1.1  christos 		  if (paren_not_balanced)
   1507  1.1  christos 		    {
   1508  1.1  christos 		      as_bad (_("Unbalanced parenthesis in %s operand."),
   1509  1.1  christos 			      ordinal_names[insn.operands]);
   1510  1.1  christos 		      return;
   1511  1.1  christos 		    }
   1512  1.1  christos 		  else
   1513  1.1  christos 		    break;
   1514  1.1  christos 		}
   1515  1.1  christos 	      else if (!is_operand_char (*current_posn)
   1516  1.1  christos 		       && !is_space_char (*current_posn))
   1517  1.1  christos 		{
   1518  1.1  christos 		  as_bad (_("Invalid character %s in %s operand"),
   1519  1.1  christos 			  output_invalid (*current_posn),
   1520  1.1  christos 			  ordinal_names[insn.operands]);
   1521  1.1  christos 		  return;
   1522  1.1  christos 		}
   1523  1.1  christos 	      if (*current_posn == '(')
   1524  1.1  christos 		++paren_not_balanced;
   1525  1.1  christos 	      if (*current_posn == ')')
   1526  1.1  christos 		--paren_not_balanced;
   1527  1.1  christos 	      current_posn++;
   1528  1.1  christos 	    }
   1529  1.1  christos 	  if (current_posn != token_start)
   1530  1.1  christos 	    {
   1531  1.1  christos 	      /* Yes, we've read in another operand.  */
   1532  1.1  christos 	      this_operand = insn.operands++;
   1533  1.1  christos 	      if (insn.operands > MAX_OPERANDS)
   1534  1.1  christos 		{
   1535  1.1  christos 		  as_bad (_("Spurious operands; (%d operands/instruction max)"),
   1536  1.1  christos 			  MAX_OPERANDS);
   1537  1.1  christos 		  return;
   1538  1.1  christos 		}
   1539  1.1  christos 
   1540  1.1  christos 	      /* Now parse operand adding info to 'insn' as we go along.  */
   1541  1.1  christos 	      save_char = *current_posn;
   1542  1.1  christos 	      *current_posn = '\0';
   1543  1.1  christos 	      insn.operand_type[this_operand] = tic30_operand (token_start);
   1544  1.1  christos 	      *current_posn = save_char;
   1545  1.1  christos 	      if (insn.operand_type[this_operand] == NULL)
   1546  1.1  christos 		return;
   1547  1.1  christos 	    }
   1548  1.1  christos 	  else
   1549  1.1  christos 	    {
   1550  1.1  christos 	      if (expecting_operand)
   1551  1.1  christos 		{
   1552  1.1  christos 		  as_bad (_("Expecting operand after ','; got nothing"));
   1553  1.1  christos 		  return;
   1554  1.1  christos 		}
   1555  1.1  christos 	      if (*current_posn == ',')
   1556  1.1  christos 		{
   1557  1.1  christos 		  as_bad (_("Expecting operand before ','; got nothing"));
   1558  1.1  christos 		  return;
   1559  1.1  christos 		}
   1560  1.1  christos 	    }
   1561  1.1  christos 
   1562  1.1  christos 	  /* Now *current_posn must be either ',' or END_OF_INSN.  */
   1563  1.1  christos 	  if (*current_posn == ',')
   1564  1.1  christos 	    {
   1565  1.1  christos 	      if (*++current_posn == END_OF_INSN)
   1566  1.1  christos 		{
   1567  1.1  christos 		  /* Just skip it, if it's \n complain.  */
   1568  1.1  christos 		  as_bad (_("Expecting operand after ','; got nothing"));
   1569  1.1  christos 		  return;
   1570  1.1  christos 		}
   1571  1.1  christos 	      expecting_operand = 1;
   1572  1.1  christos 	    }
   1573  1.1  christos 	}
   1574  1.1  christos       while (*current_posn != END_OF_INSN);
   1575  1.1  christos     }
   1576  1.1  christos 
   1577  1.1  christos   debug ("Number of operands found: %d\n", insn.operands);
   1578  1.1  christos 
   1579  1.1  christos   /* Check that number of operands is correct.  */
   1580  1.1  christos   if (insn.operands != insn.tm->operands)
   1581  1.1  christos     {
   1582  1.1  christos       unsigned int i;
   1583  1.1  christos       unsigned int numops = insn.tm->operands;
   1584  1.1  christos 
   1585  1.1  christos       /* If operands are not the same, then see if any of the operands are
   1586  1.1  christos 	 not required.  Then recheck with number of given operands.  If they
   1587  1.1  christos 	 are still not the same, then give an error, otherwise carry on.  */
   1588  1.1  christos       for (i = 0; i < insn.tm->operands; i++)
   1589  1.1  christos 	if (insn.tm->operand_types[i] & NotReq)
   1590  1.1  christos 	  numops--;
   1591  1.1  christos       if (insn.operands != numops)
   1592  1.1  christos 	{
   1593  1.1  christos 	  as_bad (_("Incorrect number of operands given"));
   1594  1.1  christos 	  return;
   1595  1.1  christos 	}
   1596  1.1  christos     }
   1597  1.1  christos   insn.addressing_mode = AM_NotReq;
   1598  1.1  christos   for (count = 0; count < insn.operands; count++)
   1599  1.1  christos     {
   1600  1.1  christos       if (insn.operand_type[count]->op_type & insn.tm->operand_types[count])
   1601  1.1  christos 	{
   1602  1.1  christos 	  debug ("Operand %d matches\n", count + 1);
   1603  1.1  christos 	  /* If instruction has two operands and has an AddressMode
   1604  1.1  christos 	     modifier then set addressing mode type for instruction.  */
   1605  1.1  christos 	  if (insn.tm->opcode_modifier == AddressMode)
   1606  1.1  christos 	    {
   1607  1.1  christos 	      int addr_insn = 0;
   1608  1.1  christos 	      /* Store instruction uses the second
   1609  1.1  christos 		 operand for the address mode.  */
   1610  1.1  christos 	      if ((insn.tm->operand_types[1] & (Indirect | Direct))
   1611  1.1  christos 		  == (Indirect | Direct))
   1612  1.1  christos 		addr_insn = 1;
   1613  1.1  christos 
   1614  1.1  christos 	      if (insn.operand_type[addr_insn]->op_type & (AllReg))
   1615  1.1  christos 		insn.addressing_mode = AM_Register;
   1616  1.1  christos 	      else if (insn.operand_type[addr_insn]->op_type & Direct)
   1617  1.1  christos 		insn.addressing_mode = AM_Direct;
   1618  1.1  christos 	      else if (insn.operand_type[addr_insn]->op_type & Indirect)
   1619  1.1  christos 		insn.addressing_mode = AM_Indirect;
   1620  1.1  christos 	      else
   1621  1.1  christos 		insn.addressing_mode = AM_Immediate;
   1622  1.1  christos 	    }
   1623  1.1  christos 	}
   1624  1.1  christos       else
   1625  1.1  christos 	{
   1626  1.1  christos 	  as_bad (_("The %s operand doesn't match"), ordinal_names[count]);
   1627  1.1  christos 	  return;
   1628  1.1  christos 	}
   1629  1.1  christos     }
   1630  1.1  christos 
   1631  1.1  christos   /* Now set the addressing mode for 3 operand instructions.  */
   1632  1.1  christos   if ((insn.tm->operand_types[0] & op3T1)
   1633  1.1  christos       && (insn.tm->operand_types[1] & op3T2))
   1634  1.1  christos     {
   1635  1.1  christos       /* Set the addressing mode to the values used for 2 operand
   1636  1.1  christos 	 instructions in the  G addressing field of the opcode.  */
   1637  1.1  christos       char *p;
   1638  1.1  christos       switch (insn.operand_type[0]->op_type)
   1639  1.1  christos 	{
   1640  1.1  christos 	case Rn:
   1641  1.1  christos 	case ARn:
   1642  1.1  christos 	case DPReg:
   1643  1.1  christos 	case OtherReg:
   1644  1.1  christos 	  if (insn.operand_type[1]->op_type & (AllReg))
   1645  1.1  christos 	    insn.addressing_mode = AM_Register;
   1646  1.1  christos 	  else if (insn.operand_type[1]->op_type & Indirect)
   1647  1.1  christos 	    insn.addressing_mode = AM_Direct;
   1648  1.1  christos 	  else
   1649  1.1  christos 	    {
   1650  1.1  christos 	      /* Shouldn't make it to this stage.  */
   1651  1.1  christos 	      as_bad (_("Incompatible first and second operands in instruction"));
   1652  1.1  christos 	      return;
   1653  1.1  christos 	    }
   1654  1.1  christos 	  break;
   1655  1.1  christos 	case Indirect:
   1656  1.1  christos 	  if (insn.operand_type[1]->op_type & (AllReg))
   1657  1.1  christos 	    insn.addressing_mode = AM_Indirect;
   1658  1.1  christos 	  else if (insn.operand_type[1]->op_type & Indirect)
   1659  1.1  christos 	    insn.addressing_mode = AM_Immediate;
   1660  1.1  christos 	  else
   1661  1.1  christos 	    {
   1662  1.1  christos 	      /* Shouldn't make it to this stage.  */
   1663  1.1  christos 	      as_bad (_("Incompatible first and second operands in instruction"));
   1664  1.1  christos 	      return;
   1665  1.1  christos 	    }
   1666  1.1  christos 	  break;
   1667  1.1  christos 	}
   1668  1.1  christos       /* Now make up the opcode for the 3 operand instructions.  As in
   1669  1.1  christos 	 parallel instructions, there will be no unresolved values, so they
   1670  1.1  christos 	 can be fully formed and added to the frag table.  */
   1671  1.1  christos       insn.opcode = insn.tm->base_opcode;
   1672  1.1  christos       if (insn.operand_type[0]->op_type & Indirect)
   1673  1.1  christos 	{
   1674  1.1  christos 	  insn.opcode |= (insn.operand_type[0]->indirect.ARnum);
   1675  1.1  christos 	  insn.opcode |= (insn.operand_type[0]->indirect.mod << 3);
   1676  1.1  christos 	}
   1677  1.1  christos       else
   1678  1.1  christos 	insn.opcode |= (insn.operand_type[0]->reg.opcode);
   1679  1.1  christos 
   1680  1.1  christos       if (insn.operand_type[1]->op_type & Indirect)
   1681  1.1  christos 	{
   1682  1.1  christos 	  insn.opcode |= (insn.operand_type[1]->indirect.ARnum << 8);
   1683  1.1  christos 	  insn.opcode |= (insn.operand_type[1]->indirect.mod << 11);
   1684  1.1  christos 	}
   1685  1.1  christos       else
   1686  1.1  christos 	insn.opcode |= (insn.operand_type[1]->reg.opcode << 8);
   1687  1.1  christos 
   1688  1.1  christos       if (insn.operands == 3)
   1689  1.1  christos 	insn.opcode |= (insn.operand_type[2]->reg.opcode << 16);
   1690  1.1  christos 
   1691  1.1  christos       insn.opcode |= insn.addressing_mode;
   1692  1.1  christos       p = frag_more (INSN_SIZE);
   1693  1.1  christos       md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1694  1.1  christos     }
   1695  1.1  christos   else
   1696  1.1  christos     {
   1697  1.1  christos       /* Not a three operand instruction.  */
   1698  1.1  christos       char *p;
   1699  1.1  christos       int am_insn = -1;
   1700  1.1  christos       insn.opcode = insn.tm->base_opcode;
   1701  1.1  christos       /* Create frag for instruction - all instructions are 4 bytes long.  */
   1702  1.1  christos       p = frag_more (INSN_SIZE);
   1703  1.1  christos       if ((insn.operands > 0) && (insn.tm->opcode_modifier == AddressMode))
   1704  1.1  christos 	{
   1705  1.1  christos 	  insn.opcode |= insn.addressing_mode;
   1706  1.1  christos 	  if (insn.addressing_mode == AM_Indirect)
   1707  1.1  christos 	    {
   1708  1.1  christos 	      /* Determine which operand gives the addressing mode.  */
   1709  1.1  christos 	      if (insn.operand_type[0]->op_type & Indirect)
   1710  1.1  christos 		am_insn = 0;
   1711  1.1  christos 	      if ((insn.operands > 1)
   1712  1.1  christos 		  && (insn.operand_type[1]->op_type & Indirect))
   1713  1.1  christos 		am_insn = 1;
   1714  1.1  christos 	      insn.opcode |= (insn.operand_type[am_insn]->indirect.disp);
   1715  1.1  christos 	      insn.opcode |= (insn.operand_type[am_insn]->indirect.ARnum << 8);
   1716  1.1  christos 	      insn.opcode |= (insn.operand_type[am_insn]->indirect.mod << 11);
   1717  1.1  christos 	      if (insn.operands > 1)
   1718  1.1  christos 		insn.opcode |= (insn.operand_type[!am_insn]->reg.opcode << 16);
   1719  1.1  christos 	      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1720  1.1  christos 	    }
   1721  1.1  christos 	  else if (insn.addressing_mode == AM_Register)
   1722  1.1  christos 	    {
   1723  1.1  christos 	      insn.opcode |= (insn.operand_type[0]->reg.opcode);
   1724  1.1  christos 	      if (insn.operands > 1)
   1725  1.1  christos 		insn.opcode |= (insn.operand_type[1]->reg.opcode << 16);
   1726  1.1  christos 	      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1727  1.1  christos 	    }
   1728  1.1  christos 	  else if (insn.addressing_mode == AM_Direct)
   1729  1.1  christos 	    {
   1730  1.1  christos 	      if (insn.operand_type[0]->op_type & Direct)
   1731  1.1  christos 		am_insn = 0;
   1732  1.1  christos 	      if ((insn.operands > 1)
   1733  1.1  christos 		  && (insn.operand_type[1]->op_type & Direct))
   1734  1.1  christos 		am_insn = 1;
   1735  1.1  christos 	      if (insn.operands > 1)
   1736  1.1  christos 		insn.opcode |=
   1737  1.1  christos 		  (insn.operand_type[! am_insn]->reg.opcode << 16);
   1738  1.1  christos 	      if (insn.operand_type[am_insn]->direct.resolved == 1)
   1739  1.1  christos 		{
   1740  1.1  christos 		  /* Resolved values can be placed straight
   1741  1.1  christos 		     into instruction word, and output.  */
   1742  1.1  christos 		  insn.opcode |=
   1743  1.1  christos 		    (insn.operand_type[am_insn]->direct.address & 0x0000FFFF);
   1744  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1745  1.1  christos 		}
   1746  1.1  christos 	      else
   1747  1.1  christos 		{
   1748  1.1  christos 		  /* Unresolved direct addressing mode instruction.  */
   1749  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1750  1.1  christos 		  fix_new_exp (frag_now, p + 2 - (frag_now->fr_literal), 2,
   1751  1.1  christos 			       & insn.operand_type[am_insn]->direct.direct_expr,
   1752  1.1  christos 			       0, 0);
   1753  1.1  christos 		}
   1754  1.1  christos 	    }
   1755  1.1  christos 	  else if (insn.addressing_mode == AM_Immediate)
   1756  1.1  christos 	    {
   1757  1.1  christos 	      if (insn.operand_type[0]->immediate.resolved == 1)
   1758  1.1  christos 		{
   1759  1.1  christos 		  char *keeploc;
   1760  1.1  christos 		  int size;
   1761  1.1  christos 
   1762  1.1  christos 		  if (insn.operands > 1)
   1763  1.1  christos 		    insn.opcode |= (insn.operand_type[1]->reg.opcode << 16);
   1764  1.1  christos 
   1765  1.1  christos 		  switch (insn.tm->imm_arg_type)
   1766  1.1  christos 		    {
   1767  1.1  christos 		    case Imm_Float:
   1768  1.1  christos 		      debug ("Floating point first operand\n");
   1769  1.1  christos 		      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1770  1.1  christos 
   1771  1.1  christos 		      keeploc = input_line_pointer;
   1772  1.1  christos 		      input_line_pointer =
   1773  1.1  christos 			insn.operand_type[0]->immediate.label;
   1774  1.1  christos 
   1775  1.1  christos 		      if (md_atof ('f', p + 2, & size) != 0)
   1776  1.1  christos 			{
   1777  1.1  christos 			  as_bad (_("invalid short form floating point immediate operand"));
   1778  1.1  christos 			  return;
   1779  1.1  christos 			}
   1780  1.1  christos 
   1781  1.1  christos 		      input_line_pointer = keeploc;
   1782  1.1  christos 		      break;
   1783  1.1  christos 
   1784  1.1  christos 		    case Imm_UInt:
   1785  1.1  christos 		      debug ("Unsigned int first operand\n");
   1786  1.1  christos 		      if (insn.operand_type[0]->immediate.decimal_found)
   1787  1.1  christos 			as_warn (_("rounding down first operand float to unsigned int"));
   1788  1.1  christos 		      if (insn.operand_type[0]->immediate.u_number > 0xFFFF)
   1789  1.1  christos 			as_warn (_("only lower 16-bits of first operand are used"));
   1790  1.1  christos 		      insn.opcode |=
   1791  1.1  christos 			(insn.operand_type[0]->immediate.u_number & 0x0000FFFFL);
   1792  1.1  christos 		      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1793  1.1  christos 		      break;
   1794  1.1  christos 
   1795  1.1  christos 		    case Imm_SInt:
   1796  1.1  christos 		      debug ("Int first operand\n");
   1797  1.1  christos 
   1798  1.1  christos 		      if (insn.operand_type[0]->immediate.decimal_found)
   1799  1.1  christos 			as_warn (_("rounding down first operand float to signed int"));
   1800  1.1  christos 
   1801  1.1  christos 		      if (insn.operand_type[0]->immediate.s_number < -32768 ||
   1802  1.1  christos 			  insn.operand_type[0]->immediate.s_number > 32767)
   1803  1.1  christos 			{
   1804  1.1  christos 			  as_bad (_("first operand is too large for 16-bit signed int"));
   1805  1.1  christos 			  return;
   1806  1.1  christos 			}
   1807  1.1  christos 		      insn.opcode |=
   1808  1.1  christos 			(insn.operand_type[0]->immediate.s_number & 0x0000FFFFL);
   1809  1.1  christos 		      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1810  1.1  christos 		      break;
   1811  1.1  christos 		    }
   1812  1.1  christos 		}
   1813  1.1  christos 	      else
   1814  1.1  christos 		{
   1815  1.1  christos 		  /* Unresolved immediate label.  */
   1816  1.1  christos 		  if (insn.operands > 1)
   1817  1.1  christos 		    insn.opcode |= (insn.operand_type[1]->reg.opcode << 16);
   1818  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1819  1.1  christos 		  fix_new_exp (frag_now, p + 2 - (frag_now->fr_literal), 2,
   1820  1.1  christos 			       & insn.operand_type[0]->immediate.imm_expr,
   1821  1.1  christos 			       0, 0);
   1822  1.1  christos 		}
   1823  1.1  christos 	    }
   1824  1.1  christos 	}
   1825  1.1  christos       else if (insn.tm->opcode_modifier == PCRel)
   1826  1.1  christos 	{
   1827  1.1  christos 	  /* Conditional Branch and Call instructions.  */
   1828  1.1  christos 	  if ((insn.tm->operand_types[0] & (AllReg | Disp))
   1829  1.1  christos 	      == (AllReg | Disp))
   1830  1.1  christos 	    {
   1831  1.1  christos 	      if (insn.operand_type[0]->op_type & (AllReg))
   1832  1.1  christos 		{
   1833  1.1  christos 		  insn.opcode |= (insn.operand_type[0]->reg.opcode);
   1834  1.1  christos 		  insn.opcode |= PC_Register;
   1835  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1836  1.1  christos 		}
   1837  1.1  christos 	      else
   1838  1.1  christos 		{
   1839  1.1  christos 		  insn.opcode |= PC_Relative;
   1840  1.1  christos 		  if (insn.operand_type[0]->immediate.resolved == 1)
   1841  1.1  christos 		    {
   1842  1.1  christos 		      insn.opcode |=
   1843  1.1  christos 			(insn.operand_type[0]->immediate.s_number & 0x0000FFFF);
   1844  1.1  christos 		      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1845  1.1  christos 		    }
   1846  1.1  christos 		  else
   1847  1.1  christos 		    {
   1848  1.1  christos 		      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1849  1.1  christos 		      fix_new_exp (frag_now, p + 2 - (frag_now->fr_literal),
   1850  1.1  christos 				   2, & insn.operand_type[0]->immediate.imm_expr,
   1851  1.1  christos 				   1, 0);
   1852  1.1  christos 		    }
   1853  1.1  christos 		}
   1854  1.1  christos 	    }
   1855  1.1  christos 	  else if ((insn.tm->operand_types[0] & ARn) == ARn)
   1856  1.1  christos 	    {
   1857  1.1  christos 	      /* Decrement and Branch instructions.  */
   1858  1.1  christos 	      insn.opcode |= ((insn.operand_type[0]->reg.opcode - 0x08) << 22);
   1859  1.1  christos 	      if (insn.operand_type[1]->op_type & (AllReg))
   1860  1.1  christos 		{
   1861  1.1  christos 		  insn.opcode |= (insn.operand_type[1]->reg.opcode);
   1862  1.1  christos 		  insn.opcode |= PC_Register;
   1863  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1864  1.1  christos 		}
   1865  1.1  christos 	      else if (insn.operand_type[1]->immediate.resolved == 1)
   1866  1.1  christos 		{
   1867  1.1  christos 		  if (insn.operand_type[0]->immediate.decimal_found)
   1868  1.1  christos 		    {
   1869  1.1  christos 		      as_bad (_("first operand is floating point"));
   1870  1.1  christos 		      return;
   1871  1.1  christos 		    }
   1872  1.1  christos 		  if (insn.operand_type[0]->immediate.s_number < -32768 ||
   1873  1.1  christos 		      insn.operand_type[0]->immediate.s_number > 32767)
   1874  1.1  christos 		    {
   1875  1.1  christos 		      as_bad (_("first operand is too large for 16-bit signed int"));
   1876  1.1  christos 		      return;
   1877  1.1  christos 		    }
   1878  1.1  christos 		  insn.opcode |= (insn.operand_type[1]->immediate.s_number);
   1879  1.1  christos 		  insn.opcode |= PC_Relative;
   1880  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1881  1.1  christos 		}
   1882  1.1  christos 	      else
   1883  1.1  christos 		{
   1884  1.1  christos 		  insn.opcode |= PC_Relative;
   1885  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1886  1.1  christos 		  fix_new_exp (frag_now, p + 2 - frag_now->fr_literal, 2,
   1887  1.1  christos 			       & insn.operand_type[1]->immediate.imm_expr,
   1888  1.1  christos 			       1, 0);
   1889  1.1  christos 		}
   1890  1.1  christos 	    }
   1891  1.1  christos 	}
   1892  1.1  christos       else if (insn.tm->operand_types[0] == IVector)
   1893  1.1  christos 	{
   1894  1.1  christos 	  /* Trap instructions.  */
   1895  1.1  christos 	  if (insn.operand_type[0]->op_type & IVector)
   1896  1.1  christos 	    insn.opcode |= (insn.operand_type[0]->immediate.u_number);
   1897  1.1  christos 	  else
   1898  1.1  christos 	    {
   1899  1.1  christos 	      /* Shouldn't get here.  */
   1900  1.1  christos 	      as_bad (_("interrupt vector for trap instruction out of range"));
   1901  1.1  christos 	      return;
   1902  1.1  christos 	    }
   1903  1.1  christos 	  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1904  1.1  christos 	}
   1905  1.1  christos       else if (insn.tm->opcode_modifier == StackOp
   1906  1.1  christos 	       || insn.tm->opcode_modifier == Rotate)
   1907  1.1  christos 	{
   1908  1.1  christos 	  /* Push, Pop and Rotate instructions.  */
   1909  1.1  christos 	  insn.opcode |= (insn.operand_type[0]->reg.opcode << 16);
   1910  1.1  christos 	  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1911  1.1  christos 	}
   1912  1.1  christos       else if ((insn.tm->operand_types[0] & (Abs24 | Direct))
   1913  1.1  christos 	       == (Abs24 | Direct))
   1914  1.1  christos 	{
   1915  1.1  christos 	  /* LDP Instruction needs to be tested
   1916  1.1  christos 	     for before the next section.  */
   1917  1.1  christos 	  if (insn.operand_type[0]->op_type & Direct)
   1918  1.1  christos 	    {
   1919  1.1  christos 	      if (insn.operand_type[0]->direct.resolved == 1)
   1920  1.1  christos 		{
   1921  1.1  christos 		  /* Direct addressing uses lower 8 bits of direct address.  */
   1922  1.1  christos 		  insn.opcode |=
   1923  1.1  christos 		    (insn.operand_type[0]->direct.address & 0x00FF0000) >> 16;
   1924  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1925  1.1  christos 		}
   1926  1.1  christos 	      else
   1927  1.1  christos 		{
   1928  1.1  christos 		  fixS *fix;
   1929  1.1  christos 
   1930  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1931  1.1  christos 		  fix = fix_new_exp (frag_now, p + 3 - (frag_now->fr_literal),
   1932  1.1  christos 				     1, &insn.operand_type[0]->direct.direct_expr, 0, 0);
   1933  1.1  christos 		  /* Ensure that the assembler doesn't complain
   1934  1.1  christos 		     about fitting a 24-bit address into 8 bits.  */
   1935  1.1  christos 		  fix->fx_no_overflow = 1;
   1936  1.1  christos 		}
   1937  1.1  christos 	    }
   1938  1.1  christos 	  else
   1939  1.1  christos 	    {
   1940  1.1  christos 	      if (insn.operand_type[0]->immediate.resolved == 1)
   1941  1.1  christos 		{
   1942  1.1  christos 		  /* Immediate addressing uses upper 8 bits of address.  */
   1943  1.1  christos 		  if (insn.operand_type[0]->immediate.u_number > 0x00FFFFFF)
   1944  1.1  christos 		    {
   1945  1.1  christos 		      as_bad (_("LDP instruction needs a 24-bit operand"));
   1946  1.1  christos 		      return;
   1947  1.1  christos 		    }
   1948  1.1  christos 		  insn.opcode |=
   1949  1.1  christos 		    ((insn.operand_type[0]->immediate.u_number & 0x00FF0000) >> 16);
   1950  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1951  1.1  christos 		}
   1952  1.1  christos 	      else
   1953  1.1  christos 		{
   1954  1.1  christos 		  fixS *fix;
   1955  1.1  christos 		  md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1956  1.1  christos 		  fix = fix_new_exp (frag_now, p + 3 - (frag_now->fr_literal),
   1957  1.1  christos 				     1, &insn.operand_type[0]->immediate.imm_expr,
   1958  1.1  christos 				     0, 0);
   1959  1.1  christos 		  fix->fx_no_overflow = 1;
   1960  1.1  christos 		}
   1961  1.1  christos 	    }
   1962  1.1  christos 	}
   1963  1.1  christos       else if (insn.tm->operand_types[0] & (Imm24))
   1964  1.1  christos 	{
   1965  1.1  christos 	  /* Unconditional Branch and Call instructions.  */
   1966  1.1  christos 	  if (insn.operand_type[0]->immediate.resolved == 1)
   1967  1.1  christos 	    {
   1968  1.1  christos 	      if (insn.operand_type[0]->immediate.u_number > 0x00FFFFFF)
   1969  1.1  christos 		as_warn (_("first operand is too large for a 24-bit displacement"));
   1970  1.1  christos 	      insn.opcode |=
   1971  1.1  christos 		(insn.operand_type[0]->immediate.u_number & 0x00FFFFFF);
   1972  1.1  christos 	      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1973  1.1  christos 	    }
   1974  1.1  christos 	  else
   1975  1.1  christos 	    {
   1976  1.1  christos 	      md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1977  1.1  christos 	      fix_new_exp (frag_now, p + 1 - (frag_now->fr_literal), 3,
   1978  1.1  christos 			   & insn.operand_type[0]->immediate.imm_expr, 0, 0);
   1979  1.1  christos 	    }
   1980  1.1  christos 	}
   1981  1.1  christos       else if (insn.tm->operand_types[0] & NotReq)
   1982  1.1  christos 	/* Check for NOP instruction without arguments.  */
   1983  1.1  christos 	md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1984  1.1  christos 
   1985  1.1  christos       else if (insn.tm->operands == 0)
   1986  1.1  christos 	/* Check for instructions without operands.  */
   1987  1.1  christos 	md_number_to_chars (p, (valueT) insn.opcode, INSN_SIZE);
   1988  1.1  christos     }
   1989  1.1  christos   debug ("Addressing mode: %08X\n", insn.addressing_mode);
   1990  1.1  christos   {
   1991  1.1  christos     unsigned int i;
   1992  1.1  christos 
   1993  1.1  christos     for (i = 0; i < insn.operands; i++)
   1994  1.1  christos       {
   1995  1.1  christos 	if (insn.operand_type[i]->immediate.label)
   1996  1.1  christos 	  free (insn.operand_type[i]->immediate.label);
   1997  1.1  christos 	free (insn.operand_type[i]);
   1998  1.1  christos       }
   1999  1.1  christos   }
   2000  1.1  christos   debug ("Final opcode: %08X\n", insn.opcode);
   2001  1.1  christos   debug ("\n");
   2002  1.1  christos }
   2003