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