Home | History | Annotate | Download | only in opcodes
      1 /* Instruction building/extraction support for xstormy16. -*- C -*-
      2 
      3    THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
      4    - the resultant file is machine generated, cgen-ibld.in isn't
      5 
      6    Copyright (C) 1996-2014 Free Software Foundation, Inc.
      7 
      8    This file is part of libopcodes.
      9 
     10    This library is free software; you can redistribute it and/or modify
     11    it under the terms of the GNU General Public License as published by
     12    the Free Software Foundation; either version 3, or (at your option)
     13    any later version.
     14 
     15    It is distributed in the hope that it will be useful, but WITHOUT
     16    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     17    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     18    License for more details.
     19 
     20    You should have received a copy of the GNU General Public License
     21    along with this program; if not, write to the Free Software Foundation, Inc.,
     22    51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
     23 
     24 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
     25    Keep that in mind.  */
     26 
     27 #include "sysdep.h"
     28 #include <stdio.h>
     29 #include "ansidecl.h"
     30 #include "dis-asm.h"
     31 #include "bfd.h"
     32 #include "symcat.h"
     33 #include "xstormy16-desc.h"
     34 #include "xstormy16-opc.h"
     35 #include "cgen/basic-modes.h"
     36 #include "opintl.h"
     37 #include "safe-ctype.h"
     38 
     39 #undef  min
     40 #define min(a,b) ((a) < (b) ? (a) : (b))
     41 #undef  max
     42 #define max(a,b) ((a) > (b) ? (a) : (b))
     43 
     44 /* Used by the ifield rtx function.  */
     45 #define FLD(f) (fields->f)
     46 
     47 static const char * insert_normal
     48   (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
     49    unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
     50 static const char * insert_insn_normal
     51   (CGEN_CPU_DESC, const CGEN_INSN *,
     52    CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
     53 static int extract_normal
     54   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
     55    unsigned int, unsigned int, unsigned int, unsigned int,
     56    unsigned int, unsigned int, bfd_vma, long *);
     57 static int extract_insn_normal
     58   (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
     59    CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
     60 #if CGEN_INT_INSN_P
     61 static void put_insn_int_value
     62   (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
     63 #endif
     64 #if ! CGEN_INT_INSN_P
     65 static CGEN_INLINE void insert_1
     66   (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
     67 static CGEN_INLINE int fill_cache
     68   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *,  int, int, bfd_vma);
     69 static CGEN_INLINE long extract_1
     70   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
     71 #endif
     72 
     73 /* Operand insertion.  */
     75 
     76 #if ! CGEN_INT_INSN_P
     77 
     78 /* Subroutine of insert_normal.  */
     79 
     80 static CGEN_INLINE void
     81 insert_1 (CGEN_CPU_DESC cd,
     82 	  unsigned long value,
     83 	  int start,
     84 	  int length,
     85 	  int word_length,
     86 	  unsigned char *bufp)
     87 {
     88   unsigned long x,mask;
     89   int shift;
     90 
     91   x = cgen_get_insn_value (cd, bufp, word_length);
     92 
     93   /* Written this way to avoid undefined behaviour.  */
     94   mask = (((1L << (length - 1)) - 1) << 1) | 1;
     95   if (CGEN_INSN_LSB0_P)
     96     shift = (start + 1) - length;
     97   else
     98     shift = (word_length - (start + length));
     99   x = (x & ~(mask << shift)) | ((value & mask) << shift);
    100 
    101   cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
    102 }
    103 
    104 #endif /* ! CGEN_INT_INSN_P */
    105 
    106 /* Default insertion routine.
    107 
    108    ATTRS is a mask of the boolean attributes.
    109    WORD_OFFSET is the offset in bits from the start of the insn of the value.
    110    WORD_LENGTH is the length of the word in bits in which the value resides.
    111    START is the starting bit number in the word, architecture origin.
    112    LENGTH is the length of VALUE in bits.
    113    TOTAL_LENGTH is the total length of the insn in bits.
    114 
    115    The result is an error message or NULL if success.  */
    116 
    117 /* ??? This duplicates functionality with bfd's howto table and
    118    bfd_install_relocation.  */
    119 /* ??? This doesn't handle bfd_vma's.  Create another function when
    120    necessary.  */
    121 
    122 static const char *
    123 insert_normal (CGEN_CPU_DESC cd,
    124 	       long value,
    125 	       unsigned int attrs,
    126 	       unsigned int word_offset,
    127 	       unsigned int start,
    128 	       unsigned int length,
    129 	       unsigned int word_length,
    130 	       unsigned int total_length,
    131 	       CGEN_INSN_BYTES_PTR buffer)
    132 {
    133   static char errbuf[100];
    134   /* Written this way to avoid undefined behaviour.  */
    135   unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
    136 
    137   /* If LENGTH is zero, this operand doesn't contribute to the value.  */
    138   if (length == 0)
    139     return NULL;
    140 
    141   if (word_length > 8 * sizeof (CGEN_INSN_INT))
    142     abort ();
    143 
    144   /* For architectures with insns smaller than the base-insn-bitsize,
    145      word_length may be too big.  */
    146   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
    147     {
    148       if (word_offset == 0
    149 	  && word_length > total_length)
    150 	word_length = total_length;
    151     }
    152 
    153   /* Ensure VALUE will fit.  */
    154   if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
    155     {
    156       long minval = - (1L << (length - 1));
    157       unsigned long maxval = mask;
    158 
    159       if ((value > 0 && (unsigned long) value > maxval)
    160 	  || value < minval)
    161 	{
    162 	  /* xgettext:c-format */
    163 	  sprintf (errbuf,
    164 		   _("operand out of range (%ld not between %ld and %lu)"),
    165 		   value, minval, maxval);
    166 	  return errbuf;
    167 	}
    168     }
    169   else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
    170     {
    171       unsigned long maxval = mask;
    172       unsigned long val = (unsigned long) value;
    173 
    174       /* For hosts with a word size > 32 check to see if value has been sign
    175 	 extended beyond 32 bits.  If so then ignore these higher sign bits
    176 	 as the user is attempting to store a 32-bit signed value into an
    177 	 unsigned 32-bit field which is allowed.  */
    178       if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
    179 	val &= 0xFFFFFFFF;
    180 
    181       if (val > maxval)
    182 	{
    183 	  /* xgettext:c-format */
    184 	  sprintf (errbuf,
    185 		   _("operand out of range (0x%lx not between 0 and 0x%lx)"),
    186 		   val, maxval);
    187 	  return errbuf;
    188 	}
    189     }
    190   else
    191     {
    192       if (! cgen_signed_overflow_ok_p (cd))
    193 	{
    194 	  long minval = - (1L << (length - 1));
    195 	  long maxval =   (1L << (length - 1)) - 1;
    196 
    197 	  if (value < minval || value > maxval)
    198 	    {
    199 	      sprintf
    200 		/* xgettext:c-format */
    201 		(errbuf, _("operand out of range (%ld not between %ld and %ld)"),
    202 		 value, minval, maxval);
    203 	      return errbuf;
    204 	    }
    205 	}
    206     }
    207 
    208 #if CGEN_INT_INSN_P
    209 
    210   {
    211     int shift;
    212 
    213     if (CGEN_INSN_LSB0_P)
    214       shift = (word_offset + start + 1) - length;
    215     else
    216       shift = total_length - (word_offset + start + length);
    217     *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
    218   }
    219 
    220 #else /* ! CGEN_INT_INSN_P */
    221 
    222   {
    223     unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
    224 
    225     insert_1 (cd, value, start, length, word_length, bufp);
    226   }
    227 
    228 #endif /* ! CGEN_INT_INSN_P */
    229 
    230   return NULL;
    231 }
    232 
    233 /* Default insn builder (insert handler).
    234    The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
    235    that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
    236    recorded in host byte order, otherwise BUFFER is an array of bytes
    237    and the value is recorded in target byte order).
    238    The result is an error message or NULL if success.  */
    239 
    240 static const char *
    241 insert_insn_normal (CGEN_CPU_DESC cd,
    242 		    const CGEN_INSN * insn,
    243 		    CGEN_FIELDS * fields,
    244 		    CGEN_INSN_BYTES_PTR buffer,
    245 		    bfd_vma pc)
    246 {
    247   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
    248   unsigned long value;
    249   const CGEN_SYNTAX_CHAR_TYPE * syn;
    250 
    251   CGEN_INIT_INSERT (cd);
    252   value = CGEN_INSN_BASE_VALUE (insn);
    253 
    254   /* If we're recording insns as numbers (rather than a string of bytes),
    255      target byte order handling is deferred until later.  */
    256 
    257 #if CGEN_INT_INSN_P
    258 
    259   put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
    260 		      CGEN_FIELDS_BITSIZE (fields), value);
    261 
    262 #else
    263 
    264   cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
    265 					(unsigned) CGEN_FIELDS_BITSIZE (fields)),
    266 		       value);
    267 
    268 #endif /* ! CGEN_INT_INSN_P */
    269 
    270   /* ??? It would be better to scan the format's fields.
    271      Still need to be able to insert a value based on the operand though;
    272      e.g. storing a branch displacement that got resolved later.
    273      Needs more thought first.  */
    274 
    275   for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
    276     {
    277       const char *errmsg;
    278 
    279       if (CGEN_SYNTAX_CHAR_P (* syn))
    280 	continue;
    281 
    282       errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
    283 				       fields, buffer, pc);
    284       if (errmsg)
    285 	return errmsg;
    286     }
    287 
    288   return NULL;
    289 }
    290 
    291 #if CGEN_INT_INSN_P
    292 /* Cover function to store an insn value into an integral insn.  Must go here
    293    because it needs <prefix>-desc.h for CGEN_INT_INSN_P.  */
    294 
    295 static void
    296 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    297 		    CGEN_INSN_BYTES_PTR buf,
    298 		    int length,
    299 		    int insn_length,
    300 		    CGEN_INSN_INT value)
    301 {
    302   /* For architectures with insns smaller than the base-insn-bitsize,
    303      length may be too big.  */
    304   if (length > insn_length)
    305     *buf = value;
    306   else
    307     {
    308       int shift = insn_length - length;
    309       /* Written this way to avoid undefined behaviour.  */
    310       CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
    311 
    312       *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
    313     }
    314 }
    315 #endif
    316 
    317 /* Operand extraction.  */
    319 
    320 #if ! CGEN_INT_INSN_P
    321 
    322 /* Subroutine of extract_normal.
    323    Ensure sufficient bytes are cached in EX_INFO.
    324    OFFSET is the offset in bytes from the start of the insn of the value.
    325    BYTES is the length of the needed value.
    326    Returns 1 for success, 0 for failure.  */
    327 
    328 static CGEN_INLINE int
    329 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    330 	    CGEN_EXTRACT_INFO *ex_info,
    331 	    int offset,
    332 	    int bytes,
    333 	    bfd_vma pc)
    334 {
    335   /* It's doubtful that the middle part has already been fetched so
    336      we don't optimize that case.  kiss.  */
    337   unsigned int mask;
    338   disassemble_info *info = (disassemble_info *) ex_info->dis_info;
    339 
    340   /* First do a quick check.  */
    341   mask = (1 << bytes) - 1;
    342   if (((ex_info->valid >> offset) & mask) == mask)
    343     return 1;
    344 
    345   /* Search for the first byte we need to read.  */
    346   for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
    347     if (! (mask & ex_info->valid))
    348       break;
    349 
    350   if (bytes)
    351     {
    352       int status;
    353 
    354       pc += offset;
    355       status = (*info->read_memory_func)
    356 	(pc, ex_info->insn_bytes + offset, bytes, info);
    357 
    358       if (status != 0)
    359 	{
    360 	  (*info->memory_error_func) (status, pc, info);
    361 	  return 0;
    362 	}
    363 
    364       ex_info->valid |= ((1 << bytes) - 1) << offset;
    365     }
    366 
    367   return 1;
    368 }
    369 
    370 /* Subroutine of extract_normal.  */
    371 
    372 static CGEN_INLINE long
    373 extract_1 (CGEN_CPU_DESC cd,
    374 	   CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
    375 	   int start,
    376 	   int length,
    377 	   int word_length,
    378 	   unsigned char *bufp,
    379 	   bfd_vma pc ATTRIBUTE_UNUSED)
    380 {
    381   unsigned long x;
    382   int shift;
    383 
    384   x = cgen_get_insn_value (cd, bufp, word_length);
    385 
    386   if (CGEN_INSN_LSB0_P)
    387     shift = (start + 1) - length;
    388   else
    389     shift = (word_length - (start + length));
    390   return x >> shift;
    391 }
    392 
    393 #endif /* ! CGEN_INT_INSN_P */
    394 
    395 /* Default extraction routine.
    396 
    397    INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
    398    or sometimes less for cases like the m32r where the base insn size is 32
    399    but some insns are 16 bits.
    400    ATTRS is a mask of the boolean attributes.  We only need `SIGNED',
    401    but for generality we take a bitmask of all of them.
    402    WORD_OFFSET is the offset in bits from the start of the insn of the value.
    403    WORD_LENGTH is the length of the word in bits in which the value resides.
    404    START is the starting bit number in the word, architecture origin.
    405    LENGTH is the length of VALUE in bits.
    406    TOTAL_LENGTH is the total length of the insn in bits.
    407 
    408    Returns 1 for success, 0 for failure.  */
    409 
    410 /* ??? The return code isn't properly used.  wip.  */
    411 
    412 /* ??? This doesn't handle bfd_vma's.  Create another function when
    413    necessary.  */
    414 
    415 static int
    416 extract_normal (CGEN_CPU_DESC cd,
    417 #if ! CGEN_INT_INSN_P
    418 		CGEN_EXTRACT_INFO *ex_info,
    419 #else
    420 		CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
    421 #endif
    422 		CGEN_INSN_INT insn_value,
    423 		unsigned int attrs,
    424 		unsigned int word_offset,
    425 		unsigned int start,
    426 		unsigned int length,
    427 		unsigned int word_length,
    428 		unsigned int total_length,
    429 #if ! CGEN_INT_INSN_P
    430 		bfd_vma pc,
    431 #else
    432 		bfd_vma pc ATTRIBUTE_UNUSED,
    433 #endif
    434 		long *valuep)
    435 {
    436   long value, mask;
    437 
    438   /* If LENGTH is zero, this operand doesn't contribute to the value
    439      so give it a standard value of zero.  */
    440   if (length == 0)
    441     {
    442       *valuep = 0;
    443       return 1;
    444     }
    445 
    446   if (word_length > 8 * sizeof (CGEN_INSN_INT))
    447     abort ();
    448 
    449   /* For architectures with insns smaller than the insn-base-bitsize,
    450      word_length may be too big.  */
    451   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
    452     {
    453       if (word_offset + word_length > total_length)
    454 	word_length = total_length - word_offset;
    455     }
    456 
    457   /* Does the value reside in INSN_VALUE, and at the right alignment?  */
    458 
    459   if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
    460     {
    461       if (CGEN_INSN_LSB0_P)
    462 	value = insn_value >> ((word_offset + start + 1) - length);
    463       else
    464 	value = insn_value >> (total_length - ( word_offset + start + length));
    465     }
    466 
    467 #if ! CGEN_INT_INSN_P
    468 
    469   else
    470     {
    471       unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
    472 
    473       if (word_length > 8 * sizeof (CGEN_INSN_INT))
    474 	abort ();
    475 
    476       if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
    477 	return 0;
    478 
    479       value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
    480     }
    481 
    482 #endif /* ! CGEN_INT_INSN_P */
    483 
    484   /* Written this way to avoid undefined behaviour.  */
    485   mask = (((1L << (length - 1)) - 1) << 1) | 1;
    486 
    487   value &= mask;
    488   /* sign extend? */
    489   if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
    490       && (value & (1L << (length - 1))))
    491     value |= ~mask;
    492 
    493   *valuep = value;
    494 
    495   return 1;
    496 }
    497 
    498 /* Default insn extractor.
    499 
    500    INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
    501    The extracted fields are stored in FIELDS.
    502    EX_INFO is used to handle reading variable length insns.
    503    Return the length of the insn in bits, or 0 if no match,
    504    or -1 if an error occurs fetching data (memory_error_func will have
    505    been called).  */
    506 
    507 static int
    508 extract_insn_normal (CGEN_CPU_DESC cd,
    509 		     const CGEN_INSN *insn,
    510 		     CGEN_EXTRACT_INFO *ex_info,
    511 		     CGEN_INSN_INT insn_value,
    512 		     CGEN_FIELDS *fields,
    513 		     bfd_vma pc)
    514 {
    515   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
    516   const CGEN_SYNTAX_CHAR_TYPE *syn;
    517 
    518   CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
    519 
    520   CGEN_INIT_EXTRACT (cd);
    521 
    522   for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
    523     {
    524       int length;
    525 
    526       if (CGEN_SYNTAX_CHAR_P (*syn))
    527 	continue;
    528 
    529       length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
    530 					ex_info, insn_value, fields, pc);
    531       if (length <= 0)
    532 	return length;
    533     }
    534 
    535   /* We recognized and successfully extracted this insn.  */
    536   return CGEN_INSN_BITSIZE (insn);
    537 }
    538 
    539 /* Machine generated code added here.  */
    541 
    542 const char * xstormy16_cgen_insert_operand
    543   (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
    544 
    545 /* Main entry point for operand insertion.
    546 
    547    This function is basically just a big switch statement.  Earlier versions
    548    used tables to look up the function to use, but
    549    - if the table contains both assembler and disassembler functions then
    550      the disassembler contains much of the assembler and vice-versa,
    551    - there's a lot of inlining possibilities as things grow,
    552    - using a switch statement avoids the function call overhead.
    553 
    554    This function could be moved into `parse_insn_normal', but keeping it
    555    separate makes clear the interface between `parse_insn_normal' and each of
    556    the handlers.  It's also needed by GAS to insert operands that couldn't be
    557    resolved during parsing.  */
    558 
    559 const char *
    560 xstormy16_cgen_insert_operand (CGEN_CPU_DESC cd,
    561 			     int opindex,
    562 			     CGEN_FIELDS * fields,
    563 			     CGEN_INSN_BYTES_PTR buffer,
    564 			     bfd_vma pc ATTRIBUTE_UNUSED)
    565 {
    566   const char * errmsg = NULL;
    567   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
    568 
    569   switch (opindex)
    570     {
    571     case XSTORMY16_OPERAND_RB :
    572       errmsg = insert_normal (cd, fields->f_Rb, 0, 0, 17, 3, 32, total_length, buffer);
    573       break;
    574     case XSTORMY16_OPERAND_RBJ :
    575       errmsg = insert_normal (cd, fields->f_Rbj, 0, 0, 11, 1, 32, total_length, buffer);
    576       break;
    577     case XSTORMY16_OPERAND_RD :
    578       errmsg = insert_normal (cd, fields->f_Rd, 0, 0, 12, 4, 32, total_length, buffer);
    579       break;
    580     case XSTORMY16_OPERAND_RDM :
    581       errmsg = insert_normal (cd, fields->f_Rdm, 0, 0, 13, 3, 32, total_length, buffer);
    582       break;
    583     case XSTORMY16_OPERAND_RM :
    584       errmsg = insert_normal (cd, fields->f_Rm, 0, 0, 4, 3, 32, total_length, buffer);
    585       break;
    586     case XSTORMY16_OPERAND_RS :
    587       errmsg = insert_normal (cd, fields->f_Rs, 0, 0, 8, 4, 32, total_length, buffer);
    588       break;
    589     case XSTORMY16_OPERAND_ABS24 :
    590       {
    591 {
    592   FLD (f_abs24_1) = ((FLD (f_abs24)) & (255));
    593   FLD (f_abs24_2) = ((UINT) (FLD (f_abs24)) >> (8));
    594 }
    595         errmsg = insert_normal (cd, fields->f_abs24_1, 0, 0, 8, 8, 32, total_length, buffer);
    596         if (errmsg)
    597           break;
    598         errmsg = insert_normal (cd, fields->f_abs24_2, 0, 0, 16, 16, 32, total_length, buffer);
    599         if (errmsg)
    600           break;
    601       }
    602       break;
    603     case XSTORMY16_OPERAND_BCOND2 :
    604       errmsg = insert_normal (cd, fields->f_op2, 0, 0, 4, 4, 32, total_length, buffer);
    605       break;
    606     case XSTORMY16_OPERAND_BCOND5 :
    607       errmsg = insert_normal (cd, fields->f_op5, 0, 0, 16, 4, 32, total_length, buffer);
    608       break;
    609     case XSTORMY16_OPERAND_HMEM8 :
    610       {
    611         long value = fields->f_hmem8;
    612         value = ((value) - (32512));
    613         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, buffer);
    614       }
    615       break;
    616     case XSTORMY16_OPERAND_IMM12 :
    617       errmsg = insert_normal (cd, fields->f_imm12, 0|(1<<CGEN_IFLD_SIGNED), 0, 20, 12, 32, total_length, buffer);
    618       break;
    619     case XSTORMY16_OPERAND_IMM16 :
    620       errmsg = insert_normal (cd, fields->f_imm16, 0|(1<<CGEN_IFLD_SIGN_OPT), 0, 16, 16, 32, total_length, buffer);
    621       break;
    622     case XSTORMY16_OPERAND_IMM2 :
    623       errmsg = insert_normal (cd, fields->f_imm2, 0, 0, 10, 2, 32, total_length, buffer);
    624       break;
    625     case XSTORMY16_OPERAND_IMM3 :
    626       errmsg = insert_normal (cd, fields->f_imm3, 0, 0, 4, 3, 32, total_length, buffer);
    627       break;
    628     case XSTORMY16_OPERAND_IMM3B :
    629       errmsg = insert_normal (cd, fields->f_imm3b, 0, 0, 17, 3, 32, total_length, buffer);
    630       break;
    631     case XSTORMY16_OPERAND_IMM4 :
    632       errmsg = insert_normal (cd, fields->f_imm4, 0, 0, 8, 4, 32, total_length, buffer);
    633       break;
    634     case XSTORMY16_OPERAND_IMM8 :
    635       errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 8, 8, 32, total_length, buffer);
    636       break;
    637     case XSTORMY16_OPERAND_IMM8SMALL :
    638       errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 8, 8, 32, total_length, buffer);
    639       break;
    640     case XSTORMY16_OPERAND_LMEM8 :
    641       errmsg = insert_normal (cd, fields->f_lmem8, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, buffer);
    642       break;
    643     case XSTORMY16_OPERAND_REL12 :
    644       {
    645         long value = fields->f_rel12;
    646         value = ((value) - (((pc) + (4))));
    647         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 20, 12, 32, total_length, buffer);
    648       }
    649       break;
    650     case XSTORMY16_OPERAND_REL12A :
    651       {
    652         long value = fields->f_rel12a;
    653         value = ((SI) (((value) - (((pc) + (2))))) >> (1));
    654         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 4, 11, 32, total_length, buffer);
    655       }
    656       break;
    657     case XSTORMY16_OPERAND_REL8_2 :
    658       {
    659         long value = fields->f_rel8_2;
    660         value = ((value) - (((pc) + (2))));
    661         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 32, total_length, buffer);
    662       }
    663       break;
    664     case XSTORMY16_OPERAND_REL8_4 :
    665       {
    666         long value = fields->f_rel8_4;
    667         value = ((value) - (((pc) + (4))));
    668         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 32, total_length, buffer);
    669       }
    670       break;
    671     case XSTORMY16_OPERAND_WS2 :
    672       errmsg = insert_normal (cd, fields->f_op2m, 0, 0, 7, 1, 32, total_length, buffer);
    673       break;
    674 
    675     default :
    676       /* xgettext:c-format */
    677       fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
    678 	       opindex);
    679       abort ();
    680   }
    681 
    682   return errmsg;
    683 }
    684 
    685 int xstormy16_cgen_extract_operand
    686   (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
    687 
    688 /* Main entry point for operand extraction.
    689    The result is <= 0 for error, >0 for success.
    690    ??? Actual values aren't well defined right now.
    691 
    692    This function is basically just a big switch statement.  Earlier versions
    693    used tables to look up the function to use, but
    694    - if the table contains both assembler and disassembler functions then
    695      the disassembler contains much of the assembler and vice-versa,
    696    - there's a lot of inlining possibilities as things grow,
    697    - using a switch statement avoids the function call overhead.
    698 
    699    This function could be moved into `print_insn_normal', but keeping it
    700    separate makes clear the interface between `print_insn_normal' and each of
    701    the handlers.  */
    702 
    703 int
    704 xstormy16_cgen_extract_operand (CGEN_CPU_DESC cd,
    705 			     int opindex,
    706 			     CGEN_EXTRACT_INFO *ex_info,
    707 			     CGEN_INSN_INT insn_value,
    708 			     CGEN_FIELDS * fields,
    709 			     bfd_vma pc)
    710 {
    711   /* Assume success (for those operands that are nops).  */
    712   int length = 1;
    713   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
    714 
    715   switch (opindex)
    716     {
    717     case XSTORMY16_OPERAND_RB :
    718       length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 3, 32, total_length, pc, & fields->f_Rb);
    719       break;
    720     case XSTORMY16_OPERAND_RBJ :
    721       length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_Rbj);
    722       break;
    723     case XSTORMY16_OPERAND_RD :
    724       length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 32, total_length, pc, & fields->f_Rd);
    725       break;
    726     case XSTORMY16_OPERAND_RDM :
    727       length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 3, 32, total_length, pc, & fields->f_Rdm);
    728       break;
    729     case XSTORMY16_OPERAND_RM :
    730       length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 3, 32, total_length, pc, & fields->f_Rm);
    731       break;
    732     case XSTORMY16_OPERAND_RS :
    733       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 32, total_length, pc, & fields->f_Rs);
    734       break;
    735     case XSTORMY16_OPERAND_ABS24 :
    736       {
    737         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 32, total_length, pc, & fields->f_abs24_1);
    738         if (length <= 0) break;
    739         length = extract_normal (cd, ex_info, insn_value, 0, 0, 16, 16, 32, total_length, pc, & fields->f_abs24_2);
    740         if (length <= 0) break;
    741   FLD (f_abs24) = ((((FLD (f_abs24_2)) << (8))) | (FLD (f_abs24_1)));
    742       }
    743       break;
    744     case XSTORMY16_OPERAND_BCOND2 :
    745       length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 32, total_length, pc, & fields->f_op2);
    746       break;
    747     case XSTORMY16_OPERAND_BCOND5 :
    748       length = extract_normal (cd, ex_info, insn_value, 0, 0, 16, 4, 32, total_length, pc, & fields->f_op5);
    749       break;
    750     case XSTORMY16_OPERAND_HMEM8 :
    751       {
    752         long value;
    753         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, pc, & value);
    754         value = ((value) + (32512));
    755         fields->f_hmem8 = value;
    756       }
    757       break;
    758     case XSTORMY16_OPERAND_IMM12 :
    759       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 20, 12, 32, total_length, pc, & fields->f_imm12);
    760       break;
    761     case XSTORMY16_OPERAND_IMM16 :
    762       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 0, 16, 16, 32, total_length, pc, & fields->f_imm16);
    763       break;
    764     case XSTORMY16_OPERAND_IMM2 :
    765       length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 2, 32, total_length, pc, & fields->f_imm2);
    766       break;
    767     case XSTORMY16_OPERAND_IMM3 :
    768       length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 3, 32, total_length, pc, & fields->f_imm3);
    769       break;
    770     case XSTORMY16_OPERAND_IMM3B :
    771       length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 3, 32, total_length, pc, & fields->f_imm3b);
    772       break;
    773     case XSTORMY16_OPERAND_IMM4 :
    774       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 32, total_length, pc, & fields->f_imm4);
    775       break;
    776     case XSTORMY16_OPERAND_IMM8 :
    777       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 32, total_length, pc, & fields->f_imm8);
    778       break;
    779     case XSTORMY16_OPERAND_IMM8SMALL :
    780       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 32, total_length, pc, & fields->f_imm8);
    781       break;
    782     case XSTORMY16_OPERAND_LMEM8 :
    783       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, pc, & fields->f_lmem8);
    784       break;
    785     case XSTORMY16_OPERAND_REL12 :
    786       {
    787         long value;
    788         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 20, 12, 32, total_length, pc, & value);
    789         value = ((value) + (((pc) + (4))));
    790         fields->f_rel12 = value;
    791       }
    792       break;
    793     case XSTORMY16_OPERAND_REL12A :
    794       {
    795         long value;
    796         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 4, 11, 32, total_length, pc, & value);
    797         value = ((((value) << (1))) + (((pc) + (2))));
    798         fields->f_rel12a = value;
    799       }
    800       break;
    801     case XSTORMY16_OPERAND_REL8_2 :
    802       {
    803         long value;
    804         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 32, total_length, pc, & value);
    805         value = ((value) + (((pc) + (2))));
    806         fields->f_rel8_2 = value;
    807       }
    808       break;
    809     case XSTORMY16_OPERAND_REL8_4 :
    810       {
    811         long value;
    812         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 32, total_length, pc, & value);
    813         value = ((value) + (((pc) + (4))));
    814         fields->f_rel8_4 = value;
    815       }
    816       break;
    817     case XSTORMY16_OPERAND_WS2 :
    818       length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 1, 32, total_length, pc, & fields->f_op2m);
    819       break;
    820 
    821     default :
    822       /* xgettext:c-format */
    823       fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
    824 	       opindex);
    825       abort ();
    826     }
    827 
    828   return length;
    829 }
    830 
    831 cgen_insert_fn * const xstormy16_cgen_insert_handlers[] =
    832 {
    833   insert_insn_normal,
    834 };
    835 
    836 cgen_extract_fn * const xstormy16_cgen_extract_handlers[] =
    837 {
    838   extract_insn_normal,
    839 };
    840 
    841 int xstormy16_cgen_get_int_operand     (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
    842 bfd_vma xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
    843 
    844 /* Getting values from cgen_fields is handled by a collection of functions.
    845    They are distinguished by the type of the VALUE argument they return.
    846    TODO: floating point, inlining support, remove cases where result type
    847    not appropriate.  */
    848 
    849 int
    850 xstormy16_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    851 			     int opindex,
    852 			     const CGEN_FIELDS * fields)
    853 {
    854   int value;
    855 
    856   switch (opindex)
    857     {
    858     case XSTORMY16_OPERAND_RB :
    859       value = fields->f_Rb;
    860       break;
    861     case XSTORMY16_OPERAND_RBJ :
    862       value = fields->f_Rbj;
    863       break;
    864     case XSTORMY16_OPERAND_RD :
    865       value = fields->f_Rd;
    866       break;
    867     case XSTORMY16_OPERAND_RDM :
    868       value = fields->f_Rdm;
    869       break;
    870     case XSTORMY16_OPERAND_RM :
    871       value = fields->f_Rm;
    872       break;
    873     case XSTORMY16_OPERAND_RS :
    874       value = fields->f_Rs;
    875       break;
    876     case XSTORMY16_OPERAND_ABS24 :
    877       value = fields->f_abs24;
    878       break;
    879     case XSTORMY16_OPERAND_BCOND2 :
    880       value = fields->f_op2;
    881       break;
    882     case XSTORMY16_OPERAND_BCOND5 :
    883       value = fields->f_op5;
    884       break;
    885     case XSTORMY16_OPERAND_HMEM8 :
    886       value = fields->f_hmem8;
    887       break;
    888     case XSTORMY16_OPERAND_IMM12 :
    889       value = fields->f_imm12;
    890       break;
    891     case XSTORMY16_OPERAND_IMM16 :
    892       value = fields->f_imm16;
    893       break;
    894     case XSTORMY16_OPERAND_IMM2 :
    895       value = fields->f_imm2;
    896       break;
    897     case XSTORMY16_OPERAND_IMM3 :
    898       value = fields->f_imm3;
    899       break;
    900     case XSTORMY16_OPERAND_IMM3B :
    901       value = fields->f_imm3b;
    902       break;
    903     case XSTORMY16_OPERAND_IMM4 :
    904       value = fields->f_imm4;
    905       break;
    906     case XSTORMY16_OPERAND_IMM8 :
    907       value = fields->f_imm8;
    908       break;
    909     case XSTORMY16_OPERAND_IMM8SMALL :
    910       value = fields->f_imm8;
    911       break;
    912     case XSTORMY16_OPERAND_LMEM8 :
    913       value = fields->f_lmem8;
    914       break;
    915     case XSTORMY16_OPERAND_REL12 :
    916       value = fields->f_rel12;
    917       break;
    918     case XSTORMY16_OPERAND_REL12A :
    919       value = fields->f_rel12a;
    920       break;
    921     case XSTORMY16_OPERAND_REL8_2 :
    922       value = fields->f_rel8_2;
    923       break;
    924     case XSTORMY16_OPERAND_REL8_4 :
    925       value = fields->f_rel8_4;
    926       break;
    927     case XSTORMY16_OPERAND_WS2 :
    928       value = fields->f_op2m;
    929       break;
    930 
    931     default :
    932       /* xgettext:c-format */
    933       fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
    934 		       opindex);
    935       abort ();
    936   }
    937 
    938   return value;
    939 }
    940 
    941 bfd_vma
    942 xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
    943 			     int opindex,
    944 			     const CGEN_FIELDS * fields)
    945 {
    946   bfd_vma value;
    947 
    948   switch (opindex)
    949     {
    950     case XSTORMY16_OPERAND_RB :
    951       value = fields->f_Rb;
    952       break;
    953     case XSTORMY16_OPERAND_RBJ :
    954       value = fields->f_Rbj;
    955       break;
    956     case XSTORMY16_OPERAND_RD :
    957       value = fields->f_Rd;
    958       break;
    959     case XSTORMY16_OPERAND_RDM :
    960       value = fields->f_Rdm;
    961       break;
    962     case XSTORMY16_OPERAND_RM :
    963       value = fields->f_Rm;
    964       break;
    965     case XSTORMY16_OPERAND_RS :
    966       value = fields->f_Rs;
    967       break;
    968     case XSTORMY16_OPERAND_ABS24 :
    969       value = fields->f_abs24;
    970       break;
    971     case XSTORMY16_OPERAND_BCOND2 :
    972       value = fields->f_op2;
    973       break;
    974     case XSTORMY16_OPERAND_BCOND5 :
    975       value = fields->f_op5;
    976       break;
    977     case XSTORMY16_OPERAND_HMEM8 :
    978       value = fields->f_hmem8;
    979       break;
    980     case XSTORMY16_OPERAND_IMM12 :
    981       value = fields->f_imm12;
    982       break;
    983     case XSTORMY16_OPERAND_IMM16 :
    984       value = fields->f_imm16;
    985       break;
    986     case XSTORMY16_OPERAND_IMM2 :
    987       value = fields->f_imm2;
    988       break;
    989     case XSTORMY16_OPERAND_IMM3 :
    990       value = fields->f_imm3;
    991       break;
    992     case XSTORMY16_OPERAND_IMM3B :
    993       value = fields->f_imm3b;
    994       break;
    995     case XSTORMY16_OPERAND_IMM4 :
    996       value = fields->f_imm4;
    997       break;
    998     case XSTORMY16_OPERAND_IMM8 :
    999       value = fields->f_imm8;
   1000       break;
   1001     case XSTORMY16_OPERAND_IMM8SMALL :
   1002       value = fields->f_imm8;
   1003       break;
   1004     case XSTORMY16_OPERAND_LMEM8 :
   1005       value = fields->f_lmem8;
   1006       break;
   1007     case XSTORMY16_OPERAND_REL12 :
   1008       value = fields->f_rel12;
   1009       break;
   1010     case XSTORMY16_OPERAND_REL12A :
   1011       value = fields->f_rel12a;
   1012       break;
   1013     case XSTORMY16_OPERAND_REL8_2 :
   1014       value = fields->f_rel8_2;
   1015       break;
   1016     case XSTORMY16_OPERAND_REL8_4 :
   1017       value = fields->f_rel8_4;
   1018       break;
   1019     case XSTORMY16_OPERAND_WS2 :
   1020       value = fields->f_op2m;
   1021       break;
   1022 
   1023     default :
   1024       /* xgettext:c-format */
   1025       fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
   1026 		       opindex);
   1027       abort ();
   1028   }
   1029 
   1030   return value;
   1031 }
   1032 
   1033 void xstormy16_cgen_set_int_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
   1034 void xstormy16_cgen_set_vma_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
   1035 
   1036 /* Stuffing values in cgen_fields is handled by a collection of functions.
   1037    They are distinguished by the type of the VALUE argument they accept.
   1038    TODO: floating point, inlining support, remove cases where argument type
   1039    not appropriate.  */
   1040 
   1041 void
   1042 xstormy16_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
   1043 			     int opindex,
   1044 			     CGEN_FIELDS * fields,
   1045 			     int value)
   1046 {
   1047   switch (opindex)
   1048     {
   1049     case XSTORMY16_OPERAND_RB :
   1050       fields->f_Rb = value;
   1051       break;
   1052     case XSTORMY16_OPERAND_RBJ :
   1053       fields->f_Rbj = value;
   1054       break;
   1055     case XSTORMY16_OPERAND_RD :
   1056       fields->f_Rd = value;
   1057       break;
   1058     case XSTORMY16_OPERAND_RDM :
   1059       fields->f_Rdm = value;
   1060       break;
   1061     case XSTORMY16_OPERAND_RM :
   1062       fields->f_Rm = value;
   1063       break;
   1064     case XSTORMY16_OPERAND_RS :
   1065       fields->f_Rs = value;
   1066       break;
   1067     case XSTORMY16_OPERAND_ABS24 :
   1068       fields->f_abs24 = value;
   1069       break;
   1070     case XSTORMY16_OPERAND_BCOND2 :
   1071       fields->f_op2 = value;
   1072       break;
   1073     case XSTORMY16_OPERAND_BCOND5 :
   1074       fields->f_op5 = value;
   1075       break;
   1076     case XSTORMY16_OPERAND_HMEM8 :
   1077       fields->f_hmem8 = value;
   1078       break;
   1079     case XSTORMY16_OPERAND_IMM12 :
   1080       fields->f_imm12 = value;
   1081       break;
   1082     case XSTORMY16_OPERAND_IMM16 :
   1083       fields->f_imm16 = value;
   1084       break;
   1085     case XSTORMY16_OPERAND_IMM2 :
   1086       fields->f_imm2 = value;
   1087       break;
   1088     case XSTORMY16_OPERAND_IMM3 :
   1089       fields->f_imm3 = value;
   1090       break;
   1091     case XSTORMY16_OPERAND_IMM3B :
   1092       fields->f_imm3b = value;
   1093       break;
   1094     case XSTORMY16_OPERAND_IMM4 :
   1095       fields->f_imm4 = value;
   1096       break;
   1097     case XSTORMY16_OPERAND_IMM8 :
   1098       fields->f_imm8 = value;
   1099       break;
   1100     case XSTORMY16_OPERAND_IMM8SMALL :
   1101       fields->f_imm8 = value;
   1102       break;
   1103     case XSTORMY16_OPERAND_LMEM8 :
   1104       fields->f_lmem8 = value;
   1105       break;
   1106     case XSTORMY16_OPERAND_REL12 :
   1107       fields->f_rel12 = value;
   1108       break;
   1109     case XSTORMY16_OPERAND_REL12A :
   1110       fields->f_rel12a = value;
   1111       break;
   1112     case XSTORMY16_OPERAND_REL8_2 :
   1113       fields->f_rel8_2 = value;
   1114       break;
   1115     case XSTORMY16_OPERAND_REL8_4 :
   1116       fields->f_rel8_4 = value;
   1117       break;
   1118     case XSTORMY16_OPERAND_WS2 :
   1119       fields->f_op2m = value;
   1120       break;
   1121 
   1122     default :
   1123       /* xgettext:c-format */
   1124       fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
   1125 		       opindex);
   1126       abort ();
   1127   }
   1128 }
   1129 
   1130 void
   1131 xstormy16_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
   1132 			     int opindex,
   1133 			     CGEN_FIELDS * fields,
   1134 			     bfd_vma value)
   1135 {
   1136   switch (opindex)
   1137     {
   1138     case XSTORMY16_OPERAND_RB :
   1139       fields->f_Rb = value;
   1140       break;
   1141     case XSTORMY16_OPERAND_RBJ :
   1142       fields->f_Rbj = value;
   1143       break;
   1144     case XSTORMY16_OPERAND_RD :
   1145       fields->f_Rd = value;
   1146       break;
   1147     case XSTORMY16_OPERAND_RDM :
   1148       fields->f_Rdm = value;
   1149       break;
   1150     case XSTORMY16_OPERAND_RM :
   1151       fields->f_Rm = value;
   1152       break;
   1153     case XSTORMY16_OPERAND_RS :
   1154       fields->f_Rs = value;
   1155       break;
   1156     case XSTORMY16_OPERAND_ABS24 :
   1157       fields->f_abs24 = value;
   1158       break;
   1159     case XSTORMY16_OPERAND_BCOND2 :
   1160       fields->f_op2 = value;
   1161       break;
   1162     case XSTORMY16_OPERAND_BCOND5 :
   1163       fields->f_op5 = value;
   1164       break;
   1165     case XSTORMY16_OPERAND_HMEM8 :
   1166       fields->f_hmem8 = value;
   1167       break;
   1168     case XSTORMY16_OPERAND_IMM12 :
   1169       fields->f_imm12 = value;
   1170       break;
   1171     case XSTORMY16_OPERAND_IMM16 :
   1172       fields->f_imm16 = value;
   1173       break;
   1174     case XSTORMY16_OPERAND_IMM2 :
   1175       fields->f_imm2 = value;
   1176       break;
   1177     case XSTORMY16_OPERAND_IMM3 :
   1178       fields->f_imm3 = value;
   1179       break;
   1180     case XSTORMY16_OPERAND_IMM3B :
   1181       fields->f_imm3b = value;
   1182       break;
   1183     case XSTORMY16_OPERAND_IMM4 :
   1184       fields->f_imm4 = value;
   1185       break;
   1186     case XSTORMY16_OPERAND_IMM8 :
   1187       fields->f_imm8 = value;
   1188       break;
   1189     case XSTORMY16_OPERAND_IMM8SMALL :
   1190       fields->f_imm8 = value;
   1191       break;
   1192     case XSTORMY16_OPERAND_LMEM8 :
   1193       fields->f_lmem8 = value;
   1194       break;
   1195     case XSTORMY16_OPERAND_REL12 :
   1196       fields->f_rel12 = value;
   1197       break;
   1198     case XSTORMY16_OPERAND_REL12A :
   1199       fields->f_rel12a = value;
   1200       break;
   1201     case XSTORMY16_OPERAND_REL8_2 :
   1202       fields->f_rel8_2 = value;
   1203       break;
   1204     case XSTORMY16_OPERAND_REL8_4 :
   1205       fields->f_rel8_4 = value;
   1206       break;
   1207     case XSTORMY16_OPERAND_WS2 :
   1208       fields->f_op2m = value;
   1209       break;
   1210 
   1211     default :
   1212       /* xgettext:c-format */
   1213       fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
   1214 		       opindex);
   1215       abort ();
   1216   }
   1217 }
   1218 
   1219 /* Function to call before using the instruction builder tables.  */
   1220 
   1221 void
   1222 xstormy16_cgen_init_ibld_table (CGEN_CPU_DESC cd)
   1223 {
   1224   cd->insert_handlers = & xstormy16_cgen_insert_handlers[0];
   1225   cd->extract_handlers = & xstormy16_cgen_extract_handlers[0];
   1226 
   1227   cd->insert_operand = xstormy16_cgen_insert_operand;
   1228   cd->extract_operand = xstormy16_cgen_extract_operand;
   1229 
   1230   cd->get_int_operand = xstormy16_cgen_get_int_operand;
   1231   cd->set_int_operand = xstormy16_cgen_set_int_operand;
   1232   cd->get_vma_operand = xstormy16_cgen_get_vma_operand;
   1233   cd->set_vma_operand = xstormy16_cgen_set_vma_operand;
   1234 }
   1235