1*3d8817e4Smiod /* Instruction building/extraction support for fr30. -*- 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 "fr30-desc.h"
35*3d8817e4Smiod #include "fr30-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 * fr30_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 *
fr30_cgen_insert_operand(CGEN_CPU_DESC cd,int opindex,CGEN_FIELDS * fields,CGEN_INSN_BYTES_PTR buffer,bfd_vma pc ATTRIBUTE_UNUSED)557*3d8817e4Smiod fr30_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 FR30_OPERAND_CRI :
569*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_CRi, 0, 16, 12, 4, 16, total_length, buffer);
570*3d8817e4Smiod       break;
571*3d8817e4Smiod     case FR30_OPERAND_CRJ :
572*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_CRj, 0, 16, 8, 4, 16, total_length, buffer);
573*3d8817e4Smiod       break;
574*3d8817e4Smiod     case FR30_OPERAND_R13 :
575*3d8817e4Smiod       break;
576*3d8817e4Smiod     case FR30_OPERAND_R14 :
577*3d8817e4Smiod       break;
578*3d8817e4Smiod     case FR30_OPERAND_R15 :
579*3d8817e4Smiod       break;
580*3d8817e4Smiod     case FR30_OPERAND_RI :
581*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_Ri, 0, 0, 12, 4, 16, total_length, buffer);
582*3d8817e4Smiod       break;
583*3d8817e4Smiod     case FR30_OPERAND_RIC :
584*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_Ric, 0, 16, 12, 4, 16, total_length, buffer);
585*3d8817e4Smiod       break;
586*3d8817e4Smiod     case FR30_OPERAND_RJ :
587*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_Rj, 0, 0, 8, 4, 16, total_length, buffer);
588*3d8817e4Smiod       break;
589*3d8817e4Smiod     case FR30_OPERAND_RJC :
590*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_Rjc, 0, 16, 8, 4, 16, total_length, buffer);
591*3d8817e4Smiod       break;
592*3d8817e4Smiod     case FR30_OPERAND_RS1 :
593*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_Rs1, 0, 0, 8, 4, 16, total_length, buffer);
594*3d8817e4Smiod       break;
595*3d8817e4Smiod     case FR30_OPERAND_RS2 :
596*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_Rs2, 0, 0, 12, 4, 16, total_length, buffer);
597*3d8817e4Smiod       break;
598*3d8817e4Smiod     case FR30_OPERAND_CC :
599*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_cc, 0, 0, 4, 4, 16, total_length, buffer);
600*3d8817e4Smiod       break;
601*3d8817e4Smiod     case FR30_OPERAND_CCC :
602*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_ccc, 0, 16, 0, 8, 16, total_length, buffer);
603*3d8817e4Smiod       break;
604*3d8817e4Smiod     case FR30_OPERAND_DIR10 :
605*3d8817e4Smiod       {
606*3d8817e4Smiod         long value = fields->f_dir10;
607*3d8817e4Smiod         value = ((unsigned int) (value) >> (2));
608*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
609*3d8817e4Smiod       }
610*3d8817e4Smiod       break;
611*3d8817e4Smiod     case FR30_OPERAND_DIR8 :
612*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_dir8, 0, 0, 8, 8, 16, total_length, buffer);
613*3d8817e4Smiod       break;
614*3d8817e4Smiod     case FR30_OPERAND_DIR9 :
615*3d8817e4Smiod       {
616*3d8817e4Smiod         long value = fields->f_dir9;
617*3d8817e4Smiod         value = ((unsigned int) (value) >> (1));
618*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
619*3d8817e4Smiod       }
620*3d8817e4Smiod       break;
621*3d8817e4Smiod     case FR30_OPERAND_DISP10 :
622*3d8817e4Smiod       {
623*3d8817e4Smiod         long value = fields->f_disp10;
624*3d8817e4Smiod         value = ((int) (value) >> (2));
625*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
626*3d8817e4Smiod       }
627*3d8817e4Smiod       break;
628*3d8817e4Smiod     case FR30_OPERAND_DISP8 :
629*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_disp8, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
630*3d8817e4Smiod       break;
631*3d8817e4Smiod     case FR30_OPERAND_DISP9 :
632*3d8817e4Smiod       {
633*3d8817e4Smiod         long value = fields->f_disp9;
634*3d8817e4Smiod         value = ((int) (value) >> (1));
635*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
636*3d8817e4Smiod       }
637*3d8817e4Smiod       break;
638*3d8817e4Smiod     case FR30_OPERAND_I20 :
639*3d8817e4Smiod       {
640*3d8817e4Smiod {
641*3d8817e4Smiod   FLD (f_i20_4) = ((unsigned int) (FLD (f_i20)) >> (16));
642*3d8817e4Smiod   FLD (f_i20_16) = ((FLD (f_i20)) & (65535));
643*3d8817e4Smiod }
644*3d8817e4Smiod         errmsg = insert_normal (cd, fields->f_i20_4, 0, 0, 8, 4, 16, total_length, buffer);
645*3d8817e4Smiod         if (errmsg)
646*3d8817e4Smiod           break;
647*3d8817e4Smiod         errmsg = insert_normal (cd, fields->f_i20_16, 0, 16, 0, 16, 16, total_length, buffer);
648*3d8817e4Smiod         if (errmsg)
649*3d8817e4Smiod           break;
650*3d8817e4Smiod       }
651*3d8817e4Smiod       break;
652*3d8817e4Smiod     case FR30_OPERAND_I32 :
653*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_i32, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, buffer);
654*3d8817e4Smiod       break;
655*3d8817e4Smiod     case FR30_OPERAND_I8 :
656*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_i8, 0, 0, 4, 8, 16, total_length, buffer);
657*3d8817e4Smiod       break;
658*3d8817e4Smiod     case FR30_OPERAND_LABEL12 :
659*3d8817e4Smiod       {
660*3d8817e4Smiod         long value = fields->f_rel12;
661*3d8817e4Smiod         value = ((int) (((value) - (((pc) + (2))))) >> (1));
662*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, buffer);
663*3d8817e4Smiod       }
664*3d8817e4Smiod       break;
665*3d8817e4Smiod     case FR30_OPERAND_LABEL9 :
666*3d8817e4Smiod       {
667*3d8817e4Smiod         long value = fields->f_rel9;
668*3d8817e4Smiod         value = ((int) (((value) - (((pc) + (2))))) >> (1));
669*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, buffer);
670*3d8817e4Smiod       }
671*3d8817e4Smiod       break;
672*3d8817e4Smiod     case FR30_OPERAND_M4 :
673*3d8817e4Smiod       {
674*3d8817e4Smiod         long value = fields->f_m4;
675*3d8817e4Smiod         value = ((value) & (15));
676*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
677*3d8817e4Smiod       }
678*3d8817e4Smiod       break;
679*3d8817e4Smiod     case FR30_OPERAND_PS :
680*3d8817e4Smiod       break;
681*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_LD :
682*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_reglist_hi_ld, 0, 0, 8, 8, 16, total_length, buffer);
683*3d8817e4Smiod       break;
684*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_ST :
685*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_reglist_hi_st, 0, 0, 8, 8, 16, total_length, buffer);
686*3d8817e4Smiod       break;
687*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_LD :
688*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_reglist_low_ld, 0, 0, 8, 8, 16, total_length, buffer);
689*3d8817e4Smiod       break;
690*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_ST :
691*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_reglist_low_st, 0, 0, 8, 8, 16, total_length, buffer);
692*3d8817e4Smiod       break;
693*3d8817e4Smiod     case FR30_OPERAND_S10 :
694*3d8817e4Smiod       {
695*3d8817e4Smiod         long value = fields->f_s10;
696*3d8817e4Smiod         value = ((int) (value) >> (2));
697*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, buffer);
698*3d8817e4Smiod       }
699*3d8817e4Smiod       break;
700*3d8817e4Smiod     case FR30_OPERAND_U10 :
701*3d8817e4Smiod       {
702*3d8817e4Smiod         long value = fields->f_u10;
703*3d8817e4Smiod         value = ((unsigned int) (value) >> (2));
704*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
705*3d8817e4Smiod       }
706*3d8817e4Smiod       break;
707*3d8817e4Smiod     case FR30_OPERAND_U4 :
708*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_u4, 0, 0, 8, 4, 16, total_length, buffer);
709*3d8817e4Smiod       break;
710*3d8817e4Smiod     case FR30_OPERAND_U4C :
711*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_u4c, 0, 0, 12, 4, 16, total_length, buffer);
712*3d8817e4Smiod       break;
713*3d8817e4Smiod     case FR30_OPERAND_U8 :
714*3d8817e4Smiod       errmsg = insert_normal (cd, fields->f_u8, 0, 0, 8, 8, 16, total_length, buffer);
715*3d8817e4Smiod       break;
716*3d8817e4Smiod     case FR30_OPERAND_UDISP6 :
717*3d8817e4Smiod       {
718*3d8817e4Smiod         long value = fields->f_udisp6;
719*3d8817e4Smiod         value = ((unsigned int) (value) >> (2));
720*3d8817e4Smiod         errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
721*3d8817e4Smiod       }
722*3d8817e4Smiod       break;
723*3d8817e4Smiod 
724*3d8817e4Smiod     default :
725*3d8817e4Smiod       /* xgettext:c-format */
726*3d8817e4Smiod       fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
727*3d8817e4Smiod 	       opindex);
728*3d8817e4Smiod       abort ();
729*3d8817e4Smiod   }
730*3d8817e4Smiod 
731*3d8817e4Smiod   return errmsg;
732*3d8817e4Smiod }
733*3d8817e4Smiod 
734*3d8817e4Smiod int fr30_cgen_extract_operand
735*3d8817e4Smiod   (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
736*3d8817e4Smiod 
737*3d8817e4Smiod /* Main entry point for operand extraction.
738*3d8817e4Smiod    The result is <= 0 for error, >0 for success.
739*3d8817e4Smiod    ??? Actual values aren't well defined right now.
740*3d8817e4Smiod 
741*3d8817e4Smiod    This function is basically just a big switch statement.  Earlier versions
742*3d8817e4Smiod    used tables to look up the function to use, but
743*3d8817e4Smiod    - if the table contains both assembler and disassembler functions then
744*3d8817e4Smiod      the disassembler contains much of the assembler and vice-versa,
745*3d8817e4Smiod    - there's a lot of inlining possibilities as things grow,
746*3d8817e4Smiod    - using a switch statement avoids the function call overhead.
747*3d8817e4Smiod 
748*3d8817e4Smiod    This function could be moved into `print_insn_normal', but keeping it
749*3d8817e4Smiod    separate makes clear the interface between `print_insn_normal' and each of
750*3d8817e4Smiod    the handlers.  */
751*3d8817e4Smiod 
752*3d8817e4Smiod int
fr30_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)753*3d8817e4Smiod fr30_cgen_extract_operand (CGEN_CPU_DESC cd,
754*3d8817e4Smiod 			     int opindex,
755*3d8817e4Smiod 			     CGEN_EXTRACT_INFO *ex_info,
756*3d8817e4Smiod 			     CGEN_INSN_INT insn_value,
757*3d8817e4Smiod 			     CGEN_FIELDS * fields,
758*3d8817e4Smiod 			     bfd_vma pc)
759*3d8817e4Smiod {
760*3d8817e4Smiod   /* Assume success (for those operands that are nops).  */
761*3d8817e4Smiod   int length = 1;
762*3d8817e4Smiod   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
763*3d8817e4Smiod 
764*3d8817e4Smiod   switch (opindex)
765*3d8817e4Smiod     {
766*3d8817e4Smiod     case FR30_OPERAND_CRI :
767*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_CRi);
768*3d8817e4Smiod       break;
769*3d8817e4Smiod     case FR30_OPERAND_CRJ :
770*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_CRj);
771*3d8817e4Smiod       break;
772*3d8817e4Smiod     case FR30_OPERAND_R13 :
773*3d8817e4Smiod       break;
774*3d8817e4Smiod     case FR30_OPERAND_R14 :
775*3d8817e4Smiod       break;
776*3d8817e4Smiod     case FR30_OPERAND_R15 :
777*3d8817e4Smiod       break;
778*3d8817e4Smiod     case FR30_OPERAND_RI :
779*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Ri);
780*3d8817e4Smiod       break;
781*3d8817e4Smiod     case FR30_OPERAND_RIC :
782*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_Ric);
783*3d8817e4Smiod       break;
784*3d8817e4Smiod     case FR30_OPERAND_RJ :
785*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rj);
786*3d8817e4Smiod       break;
787*3d8817e4Smiod     case FR30_OPERAND_RJC :
788*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_Rjc);
789*3d8817e4Smiod       break;
790*3d8817e4Smiod     case FR30_OPERAND_RS1 :
791*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rs1);
792*3d8817e4Smiod       break;
793*3d8817e4Smiod     case FR30_OPERAND_RS2 :
794*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Rs2);
795*3d8817e4Smiod       break;
796*3d8817e4Smiod     case FR30_OPERAND_CC :
797*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 16, total_length, pc, & fields->f_cc);
798*3d8817e4Smiod       break;
799*3d8817e4Smiod     case FR30_OPERAND_CCC :
800*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 8, 16, total_length, pc, & fields->f_ccc);
801*3d8817e4Smiod       break;
802*3d8817e4Smiod     case FR30_OPERAND_DIR10 :
803*3d8817e4Smiod       {
804*3d8817e4Smiod         long value;
805*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
806*3d8817e4Smiod         value = ((value) << (2));
807*3d8817e4Smiod         fields->f_dir10 = value;
808*3d8817e4Smiod       }
809*3d8817e4Smiod       break;
810*3d8817e4Smiod     case FR30_OPERAND_DIR8 :
811*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_dir8);
812*3d8817e4Smiod       break;
813*3d8817e4Smiod     case FR30_OPERAND_DIR9 :
814*3d8817e4Smiod       {
815*3d8817e4Smiod         long value;
816*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
817*3d8817e4Smiod         value = ((value) << (1));
818*3d8817e4Smiod         fields->f_dir9 = value;
819*3d8817e4Smiod       }
820*3d8817e4Smiod       break;
821*3d8817e4Smiod     case FR30_OPERAND_DISP10 :
822*3d8817e4Smiod       {
823*3d8817e4Smiod         long value;
824*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
825*3d8817e4Smiod         value = ((value) << (2));
826*3d8817e4Smiod         fields->f_disp10 = value;
827*3d8817e4Smiod       }
828*3d8817e4Smiod       break;
829*3d8817e4Smiod     case FR30_OPERAND_DISP8 :
830*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & fields->f_disp8);
831*3d8817e4Smiod       break;
832*3d8817e4Smiod     case FR30_OPERAND_DISP9 :
833*3d8817e4Smiod       {
834*3d8817e4Smiod         long value;
835*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
836*3d8817e4Smiod         value = ((value) << (1));
837*3d8817e4Smiod         fields->f_disp9 = value;
838*3d8817e4Smiod       }
839*3d8817e4Smiod       break;
840*3d8817e4Smiod     case FR30_OPERAND_I20 :
841*3d8817e4Smiod       {
842*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_i20_4);
843*3d8817e4Smiod         if (length <= 0) break;
844*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 16, 16, total_length, pc, & fields->f_i20_16);
845*3d8817e4Smiod         if (length <= 0) break;
846*3d8817e4Smiod {
847*3d8817e4Smiod   FLD (f_i20) = ((((FLD (f_i20_4)) << (16))) | (FLD (f_i20_16)));
848*3d8817e4Smiod }
849*3d8817e4Smiod       }
850*3d8817e4Smiod       break;
851*3d8817e4Smiod     case FR30_OPERAND_I32 :
852*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, pc, & fields->f_i32);
853*3d8817e4Smiod       break;
854*3d8817e4Smiod     case FR30_OPERAND_I8 :
855*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 8, 16, total_length, pc, & fields->f_i8);
856*3d8817e4Smiod       break;
857*3d8817e4Smiod     case FR30_OPERAND_LABEL12 :
858*3d8817e4Smiod       {
859*3d8817e4Smiod         long value;
860*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, pc, & value);
861*3d8817e4Smiod         value = ((((value) << (1))) + (((pc) + (2))));
862*3d8817e4Smiod         fields->f_rel12 = value;
863*3d8817e4Smiod       }
864*3d8817e4Smiod       break;
865*3d8817e4Smiod     case FR30_OPERAND_LABEL9 :
866*3d8817e4Smiod       {
867*3d8817e4Smiod         long value;
868*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, pc, & value);
869*3d8817e4Smiod         value = ((((value) << (1))) + (((pc) + (2))));
870*3d8817e4Smiod         fields->f_rel9 = value;
871*3d8817e4Smiod       }
872*3d8817e4Smiod       break;
873*3d8817e4Smiod     case FR30_OPERAND_M4 :
874*3d8817e4Smiod       {
875*3d8817e4Smiod         long value;
876*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
877*3d8817e4Smiod         value = ((value) | (((-1) << (4))));
878*3d8817e4Smiod         fields->f_m4 = value;
879*3d8817e4Smiod       }
880*3d8817e4Smiod       break;
881*3d8817e4Smiod     case FR30_OPERAND_PS :
882*3d8817e4Smiod       break;
883*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_LD :
884*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_ld);
885*3d8817e4Smiod       break;
886*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_ST :
887*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_st);
888*3d8817e4Smiod       break;
889*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_LD :
890*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_ld);
891*3d8817e4Smiod       break;
892*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_ST :
893*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_st);
894*3d8817e4Smiod       break;
895*3d8817e4Smiod     case FR30_OPERAND_S10 :
896*3d8817e4Smiod       {
897*3d8817e4Smiod         long value;
898*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, pc, & value);
899*3d8817e4Smiod         value = ((value) << (2));
900*3d8817e4Smiod         fields->f_s10 = value;
901*3d8817e4Smiod       }
902*3d8817e4Smiod       break;
903*3d8817e4Smiod     case FR30_OPERAND_U10 :
904*3d8817e4Smiod       {
905*3d8817e4Smiod         long value;
906*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
907*3d8817e4Smiod         value = ((value) << (2));
908*3d8817e4Smiod         fields->f_u10 = value;
909*3d8817e4Smiod       }
910*3d8817e4Smiod       break;
911*3d8817e4Smiod     case FR30_OPERAND_U4 :
912*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_u4);
913*3d8817e4Smiod       break;
914*3d8817e4Smiod     case FR30_OPERAND_U4C :
915*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_u4c);
916*3d8817e4Smiod       break;
917*3d8817e4Smiod     case FR30_OPERAND_U8 :
918*3d8817e4Smiod       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_u8);
919*3d8817e4Smiod       break;
920*3d8817e4Smiod     case FR30_OPERAND_UDISP6 :
921*3d8817e4Smiod       {
922*3d8817e4Smiod         long value;
923*3d8817e4Smiod         length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
924*3d8817e4Smiod         value = ((value) << (2));
925*3d8817e4Smiod         fields->f_udisp6 = value;
926*3d8817e4Smiod       }
927*3d8817e4Smiod       break;
928*3d8817e4Smiod 
929*3d8817e4Smiod     default :
930*3d8817e4Smiod       /* xgettext:c-format */
931*3d8817e4Smiod       fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
932*3d8817e4Smiod 	       opindex);
933*3d8817e4Smiod       abort ();
934*3d8817e4Smiod     }
935*3d8817e4Smiod 
936*3d8817e4Smiod   return length;
937*3d8817e4Smiod }
938*3d8817e4Smiod 
939*3d8817e4Smiod cgen_insert_fn * const fr30_cgen_insert_handlers[] =
940*3d8817e4Smiod {
941*3d8817e4Smiod   insert_insn_normal,
942*3d8817e4Smiod };
943*3d8817e4Smiod 
944*3d8817e4Smiod cgen_extract_fn * const fr30_cgen_extract_handlers[] =
945*3d8817e4Smiod {
946*3d8817e4Smiod   extract_insn_normal,
947*3d8817e4Smiod };
948*3d8817e4Smiod 
949*3d8817e4Smiod int fr30_cgen_get_int_operand     (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
950*3d8817e4Smiod bfd_vma fr30_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
951*3d8817e4Smiod 
952*3d8817e4Smiod /* Getting values from cgen_fields is handled by a collection of functions.
953*3d8817e4Smiod    They are distinguished by the type of the VALUE argument they return.
954*3d8817e4Smiod    TODO: floating point, inlining support, remove cases where result type
955*3d8817e4Smiod    not appropriate.  */
956*3d8817e4Smiod 
957*3d8817e4Smiod int
fr30_cgen_get_int_operand(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,int opindex,const CGEN_FIELDS * fields)958*3d8817e4Smiod fr30_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
959*3d8817e4Smiod 			     int opindex,
960*3d8817e4Smiod 			     const CGEN_FIELDS * fields)
961*3d8817e4Smiod {
962*3d8817e4Smiod   int value;
963*3d8817e4Smiod 
964*3d8817e4Smiod   switch (opindex)
965*3d8817e4Smiod     {
966*3d8817e4Smiod     case FR30_OPERAND_CRI :
967*3d8817e4Smiod       value = fields->f_CRi;
968*3d8817e4Smiod       break;
969*3d8817e4Smiod     case FR30_OPERAND_CRJ :
970*3d8817e4Smiod       value = fields->f_CRj;
971*3d8817e4Smiod       break;
972*3d8817e4Smiod     case FR30_OPERAND_R13 :
973*3d8817e4Smiod       value = 0;
974*3d8817e4Smiod       break;
975*3d8817e4Smiod     case FR30_OPERAND_R14 :
976*3d8817e4Smiod       value = 0;
977*3d8817e4Smiod       break;
978*3d8817e4Smiod     case FR30_OPERAND_R15 :
979*3d8817e4Smiod       value = 0;
980*3d8817e4Smiod       break;
981*3d8817e4Smiod     case FR30_OPERAND_RI :
982*3d8817e4Smiod       value = fields->f_Ri;
983*3d8817e4Smiod       break;
984*3d8817e4Smiod     case FR30_OPERAND_RIC :
985*3d8817e4Smiod       value = fields->f_Ric;
986*3d8817e4Smiod       break;
987*3d8817e4Smiod     case FR30_OPERAND_RJ :
988*3d8817e4Smiod       value = fields->f_Rj;
989*3d8817e4Smiod       break;
990*3d8817e4Smiod     case FR30_OPERAND_RJC :
991*3d8817e4Smiod       value = fields->f_Rjc;
992*3d8817e4Smiod       break;
993*3d8817e4Smiod     case FR30_OPERAND_RS1 :
994*3d8817e4Smiod       value = fields->f_Rs1;
995*3d8817e4Smiod       break;
996*3d8817e4Smiod     case FR30_OPERAND_RS2 :
997*3d8817e4Smiod       value = fields->f_Rs2;
998*3d8817e4Smiod       break;
999*3d8817e4Smiod     case FR30_OPERAND_CC :
1000*3d8817e4Smiod       value = fields->f_cc;
1001*3d8817e4Smiod       break;
1002*3d8817e4Smiod     case FR30_OPERAND_CCC :
1003*3d8817e4Smiod       value = fields->f_ccc;
1004*3d8817e4Smiod       break;
1005*3d8817e4Smiod     case FR30_OPERAND_DIR10 :
1006*3d8817e4Smiod       value = fields->f_dir10;
1007*3d8817e4Smiod       break;
1008*3d8817e4Smiod     case FR30_OPERAND_DIR8 :
1009*3d8817e4Smiod       value = fields->f_dir8;
1010*3d8817e4Smiod       break;
1011*3d8817e4Smiod     case FR30_OPERAND_DIR9 :
1012*3d8817e4Smiod       value = fields->f_dir9;
1013*3d8817e4Smiod       break;
1014*3d8817e4Smiod     case FR30_OPERAND_DISP10 :
1015*3d8817e4Smiod       value = fields->f_disp10;
1016*3d8817e4Smiod       break;
1017*3d8817e4Smiod     case FR30_OPERAND_DISP8 :
1018*3d8817e4Smiod       value = fields->f_disp8;
1019*3d8817e4Smiod       break;
1020*3d8817e4Smiod     case FR30_OPERAND_DISP9 :
1021*3d8817e4Smiod       value = fields->f_disp9;
1022*3d8817e4Smiod       break;
1023*3d8817e4Smiod     case FR30_OPERAND_I20 :
1024*3d8817e4Smiod       value = fields->f_i20;
1025*3d8817e4Smiod       break;
1026*3d8817e4Smiod     case FR30_OPERAND_I32 :
1027*3d8817e4Smiod       value = fields->f_i32;
1028*3d8817e4Smiod       break;
1029*3d8817e4Smiod     case FR30_OPERAND_I8 :
1030*3d8817e4Smiod       value = fields->f_i8;
1031*3d8817e4Smiod       break;
1032*3d8817e4Smiod     case FR30_OPERAND_LABEL12 :
1033*3d8817e4Smiod       value = fields->f_rel12;
1034*3d8817e4Smiod       break;
1035*3d8817e4Smiod     case FR30_OPERAND_LABEL9 :
1036*3d8817e4Smiod       value = fields->f_rel9;
1037*3d8817e4Smiod       break;
1038*3d8817e4Smiod     case FR30_OPERAND_M4 :
1039*3d8817e4Smiod       value = fields->f_m4;
1040*3d8817e4Smiod       break;
1041*3d8817e4Smiod     case FR30_OPERAND_PS :
1042*3d8817e4Smiod       value = 0;
1043*3d8817e4Smiod       break;
1044*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_LD :
1045*3d8817e4Smiod       value = fields->f_reglist_hi_ld;
1046*3d8817e4Smiod       break;
1047*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_ST :
1048*3d8817e4Smiod       value = fields->f_reglist_hi_st;
1049*3d8817e4Smiod       break;
1050*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_LD :
1051*3d8817e4Smiod       value = fields->f_reglist_low_ld;
1052*3d8817e4Smiod       break;
1053*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_ST :
1054*3d8817e4Smiod       value = fields->f_reglist_low_st;
1055*3d8817e4Smiod       break;
1056*3d8817e4Smiod     case FR30_OPERAND_S10 :
1057*3d8817e4Smiod       value = fields->f_s10;
1058*3d8817e4Smiod       break;
1059*3d8817e4Smiod     case FR30_OPERAND_U10 :
1060*3d8817e4Smiod       value = fields->f_u10;
1061*3d8817e4Smiod       break;
1062*3d8817e4Smiod     case FR30_OPERAND_U4 :
1063*3d8817e4Smiod       value = fields->f_u4;
1064*3d8817e4Smiod       break;
1065*3d8817e4Smiod     case FR30_OPERAND_U4C :
1066*3d8817e4Smiod       value = fields->f_u4c;
1067*3d8817e4Smiod       break;
1068*3d8817e4Smiod     case FR30_OPERAND_U8 :
1069*3d8817e4Smiod       value = fields->f_u8;
1070*3d8817e4Smiod       break;
1071*3d8817e4Smiod     case FR30_OPERAND_UDISP6 :
1072*3d8817e4Smiod       value = fields->f_udisp6;
1073*3d8817e4Smiod       break;
1074*3d8817e4Smiod 
1075*3d8817e4Smiod     default :
1076*3d8817e4Smiod       /* xgettext:c-format */
1077*3d8817e4Smiod       fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
1078*3d8817e4Smiod 		       opindex);
1079*3d8817e4Smiod       abort ();
1080*3d8817e4Smiod   }
1081*3d8817e4Smiod 
1082*3d8817e4Smiod   return value;
1083*3d8817e4Smiod }
1084*3d8817e4Smiod 
1085*3d8817e4Smiod bfd_vma
fr30_cgen_get_vma_operand(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,int opindex,const CGEN_FIELDS * fields)1086*3d8817e4Smiod fr30_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1087*3d8817e4Smiod 			     int opindex,
1088*3d8817e4Smiod 			     const CGEN_FIELDS * fields)
1089*3d8817e4Smiod {
1090*3d8817e4Smiod   bfd_vma value;
1091*3d8817e4Smiod 
1092*3d8817e4Smiod   switch (opindex)
1093*3d8817e4Smiod     {
1094*3d8817e4Smiod     case FR30_OPERAND_CRI :
1095*3d8817e4Smiod       value = fields->f_CRi;
1096*3d8817e4Smiod       break;
1097*3d8817e4Smiod     case FR30_OPERAND_CRJ :
1098*3d8817e4Smiod       value = fields->f_CRj;
1099*3d8817e4Smiod       break;
1100*3d8817e4Smiod     case FR30_OPERAND_R13 :
1101*3d8817e4Smiod       value = 0;
1102*3d8817e4Smiod       break;
1103*3d8817e4Smiod     case FR30_OPERAND_R14 :
1104*3d8817e4Smiod       value = 0;
1105*3d8817e4Smiod       break;
1106*3d8817e4Smiod     case FR30_OPERAND_R15 :
1107*3d8817e4Smiod       value = 0;
1108*3d8817e4Smiod       break;
1109*3d8817e4Smiod     case FR30_OPERAND_RI :
1110*3d8817e4Smiod       value = fields->f_Ri;
1111*3d8817e4Smiod       break;
1112*3d8817e4Smiod     case FR30_OPERAND_RIC :
1113*3d8817e4Smiod       value = fields->f_Ric;
1114*3d8817e4Smiod       break;
1115*3d8817e4Smiod     case FR30_OPERAND_RJ :
1116*3d8817e4Smiod       value = fields->f_Rj;
1117*3d8817e4Smiod       break;
1118*3d8817e4Smiod     case FR30_OPERAND_RJC :
1119*3d8817e4Smiod       value = fields->f_Rjc;
1120*3d8817e4Smiod       break;
1121*3d8817e4Smiod     case FR30_OPERAND_RS1 :
1122*3d8817e4Smiod       value = fields->f_Rs1;
1123*3d8817e4Smiod       break;
1124*3d8817e4Smiod     case FR30_OPERAND_RS2 :
1125*3d8817e4Smiod       value = fields->f_Rs2;
1126*3d8817e4Smiod       break;
1127*3d8817e4Smiod     case FR30_OPERAND_CC :
1128*3d8817e4Smiod       value = fields->f_cc;
1129*3d8817e4Smiod       break;
1130*3d8817e4Smiod     case FR30_OPERAND_CCC :
1131*3d8817e4Smiod       value = fields->f_ccc;
1132*3d8817e4Smiod       break;
1133*3d8817e4Smiod     case FR30_OPERAND_DIR10 :
1134*3d8817e4Smiod       value = fields->f_dir10;
1135*3d8817e4Smiod       break;
1136*3d8817e4Smiod     case FR30_OPERAND_DIR8 :
1137*3d8817e4Smiod       value = fields->f_dir8;
1138*3d8817e4Smiod       break;
1139*3d8817e4Smiod     case FR30_OPERAND_DIR9 :
1140*3d8817e4Smiod       value = fields->f_dir9;
1141*3d8817e4Smiod       break;
1142*3d8817e4Smiod     case FR30_OPERAND_DISP10 :
1143*3d8817e4Smiod       value = fields->f_disp10;
1144*3d8817e4Smiod       break;
1145*3d8817e4Smiod     case FR30_OPERAND_DISP8 :
1146*3d8817e4Smiod       value = fields->f_disp8;
1147*3d8817e4Smiod       break;
1148*3d8817e4Smiod     case FR30_OPERAND_DISP9 :
1149*3d8817e4Smiod       value = fields->f_disp9;
1150*3d8817e4Smiod       break;
1151*3d8817e4Smiod     case FR30_OPERAND_I20 :
1152*3d8817e4Smiod       value = fields->f_i20;
1153*3d8817e4Smiod       break;
1154*3d8817e4Smiod     case FR30_OPERAND_I32 :
1155*3d8817e4Smiod       value = fields->f_i32;
1156*3d8817e4Smiod       break;
1157*3d8817e4Smiod     case FR30_OPERAND_I8 :
1158*3d8817e4Smiod       value = fields->f_i8;
1159*3d8817e4Smiod       break;
1160*3d8817e4Smiod     case FR30_OPERAND_LABEL12 :
1161*3d8817e4Smiod       value = fields->f_rel12;
1162*3d8817e4Smiod       break;
1163*3d8817e4Smiod     case FR30_OPERAND_LABEL9 :
1164*3d8817e4Smiod       value = fields->f_rel9;
1165*3d8817e4Smiod       break;
1166*3d8817e4Smiod     case FR30_OPERAND_M4 :
1167*3d8817e4Smiod       value = fields->f_m4;
1168*3d8817e4Smiod       break;
1169*3d8817e4Smiod     case FR30_OPERAND_PS :
1170*3d8817e4Smiod       value = 0;
1171*3d8817e4Smiod       break;
1172*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_LD :
1173*3d8817e4Smiod       value = fields->f_reglist_hi_ld;
1174*3d8817e4Smiod       break;
1175*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_ST :
1176*3d8817e4Smiod       value = fields->f_reglist_hi_st;
1177*3d8817e4Smiod       break;
1178*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_LD :
1179*3d8817e4Smiod       value = fields->f_reglist_low_ld;
1180*3d8817e4Smiod       break;
1181*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_ST :
1182*3d8817e4Smiod       value = fields->f_reglist_low_st;
1183*3d8817e4Smiod       break;
1184*3d8817e4Smiod     case FR30_OPERAND_S10 :
1185*3d8817e4Smiod       value = fields->f_s10;
1186*3d8817e4Smiod       break;
1187*3d8817e4Smiod     case FR30_OPERAND_U10 :
1188*3d8817e4Smiod       value = fields->f_u10;
1189*3d8817e4Smiod       break;
1190*3d8817e4Smiod     case FR30_OPERAND_U4 :
1191*3d8817e4Smiod       value = fields->f_u4;
1192*3d8817e4Smiod       break;
1193*3d8817e4Smiod     case FR30_OPERAND_U4C :
1194*3d8817e4Smiod       value = fields->f_u4c;
1195*3d8817e4Smiod       break;
1196*3d8817e4Smiod     case FR30_OPERAND_U8 :
1197*3d8817e4Smiod       value = fields->f_u8;
1198*3d8817e4Smiod       break;
1199*3d8817e4Smiod     case FR30_OPERAND_UDISP6 :
1200*3d8817e4Smiod       value = fields->f_udisp6;
1201*3d8817e4Smiod       break;
1202*3d8817e4Smiod 
1203*3d8817e4Smiod     default :
1204*3d8817e4Smiod       /* xgettext:c-format */
1205*3d8817e4Smiod       fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
1206*3d8817e4Smiod 		       opindex);
1207*3d8817e4Smiod       abort ();
1208*3d8817e4Smiod   }
1209*3d8817e4Smiod 
1210*3d8817e4Smiod   return value;
1211*3d8817e4Smiod }
1212*3d8817e4Smiod 
1213*3d8817e4Smiod void fr30_cgen_set_int_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
1214*3d8817e4Smiod void fr30_cgen_set_vma_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
1215*3d8817e4Smiod 
1216*3d8817e4Smiod /* Stuffing values in cgen_fields is handled by a collection of functions.
1217*3d8817e4Smiod    They are distinguished by the type of the VALUE argument they accept.
1218*3d8817e4Smiod    TODO: floating point, inlining support, remove cases where argument type
1219*3d8817e4Smiod    not appropriate.  */
1220*3d8817e4Smiod 
1221*3d8817e4Smiod void
fr30_cgen_set_int_operand(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,int opindex,CGEN_FIELDS * fields,int value)1222*3d8817e4Smiod fr30_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1223*3d8817e4Smiod 			     int opindex,
1224*3d8817e4Smiod 			     CGEN_FIELDS * fields,
1225*3d8817e4Smiod 			     int value)
1226*3d8817e4Smiod {
1227*3d8817e4Smiod   switch (opindex)
1228*3d8817e4Smiod     {
1229*3d8817e4Smiod     case FR30_OPERAND_CRI :
1230*3d8817e4Smiod       fields->f_CRi = value;
1231*3d8817e4Smiod       break;
1232*3d8817e4Smiod     case FR30_OPERAND_CRJ :
1233*3d8817e4Smiod       fields->f_CRj = value;
1234*3d8817e4Smiod       break;
1235*3d8817e4Smiod     case FR30_OPERAND_R13 :
1236*3d8817e4Smiod       break;
1237*3d8817e4Smiod     case FR30_OPERAND_R14 :
1238*3d8817e4Smiod       break;
1239*3d8817e4Smiod     case FR30_OPERAND_R15 :
1240*3d8817e4Smiod       break;
1241*3d8817e4Smiod     case FR30_OPERAND_RI :
1242*3d8817e4Smiod       fields->f_Ri = value;
1243*3d8817e4Smiod       break;
1244*3d8817e4Smiod     case FR30_OPERAND_RIC :
1245*3d8817e4Smiod       fields->f_Ric = value;
1246*3d8817e4Smiod       break;
1247*3d8817e4Smiod     case FR30_OPERAND_RJ :
1248*3d8817e4Smiod       fields->f_Rj = value;
1249*3d8817e4Smiod       break;
1250*3d8817e4Smiod     case FR30_OPERAND_RJC :
1251*3d8817e4Smiod       fields->f_Rjc = value;
1252*3d8817e4Smiod       break;
1253*3d8817e4Smiod     case FR30_OPERAND_RS1 :
1254*3d8817e4Smiod       fields->f_Rs1 = value;
1255*3d8817e4Smiod       break;
1256*3d8817e4Smiod     case FR30_OPERAND_RS2 :
1257*3d8817e4Smiod       fields->f_Rs2 = value;
1258*3d8817e4Smiod       break;
1259*3d8817e4Smiod     case FR30_OPERAND_CC :
1260*3d8817e4Smiod       fields->f_cc = value;
1261*3d8817e4Smiod       break;
1262*3d8817e4Smiod     case FR30_OPERAND_CCC :
1263*3d8817e4Smiod       fields->f_ccc = value;
1264*3d8817e4Smiod       break;
1265*3d8817e4Smiod     case FR30_OPERAND_DIR10 :
1266*3d8817e4Smiod       fields->f_dir10 = value;
1267*3d8817e4Smiod       break;
1268*3d8817e4Smiod     case FR30_OPERAND_DIR8 :
1269*3d8817e4Smiod       fields->f_dir8 = value;
1270*3d8817e4Smiod       break;
1271*3d8817e4Smiod     case FR30_OPERAND_DIR9 :
1272*3d8817e4Smiod       fields->f_dir9 = value;
1273*3d8817e4Smiod       break;
1274*3d8817e4Smiod     case FR30_OPERAND_DISP10 :
1275*3d8817e4Smiod       fields->f_disp10 = value;
1276*3d8817e4Smiod       break;
1277*3d8817e4Smiod     case FR30_OPERAND_DISP8 :
1278*3d8817e4Smiod       fields->f_disp8 = value;
1279*3d8817e4Smiod       break;
1280*3d8817e4Smiod     case FR30_OPERAND_DISP9 :
1281*3d8817e4Smiod       fields->f_disp9 = value;
1282*3d8817e4Smiod       break;
1283*3d8817e4Smiod     case FR30_OPERAND_I20 :
1284*3d8817e4Smiod       fields->f_i20 = value;
1285*3d8817e4Smiod       break;
1286*3d8817e4Smiod     case FR30_OPERAND_I32 :
1287*3d8817e4Smiod       fields->f_i32 = value;
1288*3d8817e4Smiod       break;
1289*3d8817e4Smiod     case FR30_OPERAND_I8 :
1290*3d8817e4Smiod       fields->f_i8 = value;
1291*3d8817e4Smiod       break;
1292*3d8817e4Smiod     case FR30_OPERAND_LABEL12 :
1293*3d8817e4Smiod       fields->f_rel12 = value;
1294*3d8817e4Smiod       break;
1295*3d8817e4Smiod     case FR30_OPERAND_LABEL9 :
1296*3d8817e4Smiod       fields->f_rel9 = value;
1297*3d8817e4Smiod       break;
1298*3d8817e4Smiod     case FR30_OPERAND_M4 :
1299*3d8817e4Smiod       fields->f_m4 = value;
1300*3d8817e4Smiod       break;
1301*3d8817e4Smiod     case FR30_OPERAND_PS :
1302*3d8817e4Smiod       break;
1303*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_LD :
1304*3d8817e4Smiod       fields->f_reglist_hi_ld = value;
1305*3d8817e4Smiod       break;
1306*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_ST :
1307*3d8817e4Smiod       fields->f_reglist_hi_st = value;
1308*3d8817e4Smiod       break;
1309*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_LD :
1310*3d8817e4Smiod       fields->f_reglist_low_ld = value;
1311*3d8817e4Smiod       break;
1312*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_ST :
1313*3d8817e4Smiod       fields->f_reglist_low_st = value;
1314*3d8817e4Smiod       break;
1315*3d8817e4Smiod     case FR30_OPERAND_S10 :
1316*3d8817e4Smiod       fields->f_s10 = value;
1317*3d8817e4Smiod       break;
1318*3d8817e4Smiod     case FR30_OPERAND_U10 :
1319*3d8817e4Smiod       fields->f_u10 = value;
1320*3d8817e4Smiod       break;
1321*3d8817e4Smiod     case FR30_OPERAND_U4 :
1322*3d8817e4Smiod       fields->f_u4 = value;
1323*3d8817e4Smiod       break;
1324*3d8817e4Smiod     case FR30_OPERAND_U4C :
1325*3d8817e4Smiod       fields->f_u4c = value;
1326*3d8817e4Smiod       break;
1327*3d8817e4Smiod     case FR30_OPERAND_U8 :
1328*3d8817e4Smiod       fields->f_u8 = value;
1329*3d8817e4Smiod       break;
1330*3d8817e4Smiod     case FR30_OPERAND_UDISP6 :
1331*3d8817e4Smiod       fields->f_udisp6 = value;
1332*3d8817e4Smiod       break;
1333*3d8817e4Smiod 
1334*3d8817e4Smiod     default :
1335*3d8817e4Smiod       /* xgettext:c-format */
1336*3d8817e4Smiod       fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
1337*3d8817e4Smiod 		       opindex);
1338*3d8817e4Smiod       abort ();
1339*3d8817e4Smiod   }
1340*3d8817e4Smiod }
1341*3d8817e4Smiod 
1342*3d8817e4Smiod void
fr30_cgen_set_vma_operand(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,int opindex,CGEN_FIELDS * fields,bfd_vma value)1343*3d8817e4Smiod fr30_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1344*3d8817e4Smiod 			     int opindex,
1345*3d8817e4Smiod 			     CGEN_FIELDS * fields,
1346*3d8817e4Smiod 			     bfd_vma value)
1347*3d8817e4Smiod {
1348*3d8817e4Smiod   switch (opindex)
1349*3d8817e4Smiod     {
1350*3d8817e4Smiod     case FR30_OPERAND_CRI :
1351*3d8817e4Smiod       fields->f_CRi = value;
1352*3d8817e4Smiod       break;
1353*3d8817e4Smiod     case FR30_OPERAND_CRJ :
1354*3d8817e4Smiod       fields->f_CRj = value;
1355*3d8817e4Smiod       break;
1356*3d8817e4Smiod     case FR30_OPERAND_R13 :
1357*3d8817e4Smiod       break;
1358*3d8817e4Smiod     case FR30_OPERAND_R14 :
1359*3d8817e4Smiod       break;
1360*3d8817e4Smiod     case FR30_OPERAND_R15 :
1361*3d8817e4Smiod       break;
1362*3d8817e4Smiod     case FR30_OPERAND_RI :
1363*3d8817e4Smiod       fields->f_Ri = value;
1364*3d8817e4Smiod       break;
1365*3d8817e4Smiod     case FR30_OPERAND_RIC :
1366*3d8817e4Smiod       fields->f_Ric = value;
1367*3d8817e4Smiod       break;
1368*3d8817e4Smiod     case FR30_OPERAND_RJ :
1369*3d8817e4Smiod       fields->f_Rj = value;
1370*3d8817e4Smiod       break;
1371*3d8817e4Smiod     case FR30_OPERAND_RJC :
1372*3d8817e4Smiod       fields->f_Rjc = value;
1373*3d8817e4Smiod       break;
1374*3d8817e4Smiod     case FR30_OPERAND_RS1 :
1375*3d8817e4Smiod       fields->f_Rs1 = value;
1376*3d8817e4Smiod       break;
1377*3d8817e4Smiod     case FR30_OPERAND_RS2 :
1378*3d8817e4Smiod       fields->f_Rs2 = value;
1379*3d8817e4Smiod       break;
1380*3d8817e4Smiod     case FR30_OPERAND_CC :
1381*3d8817e4Smiod       fields->f_cc = value;
1382*3d8817e4Smiod       break;
1383*3d8817e4Smiod     case FR30_OPERAND_CCC :
1384*3d8817e4Smiod       fields->f_ccc = value;
1385*3d8817e4Smiod       break;
1386*3d8817e4Smiod     case FR30_OPERAND_DIR10 :
1387*3d8817e4Smiod       fields->f_dir10 = value;
1388*3d8817e4Smiod       break;
1389*3d8817e4Smiod     case FR30_OPERAND_DIR8 :
1390*3d8817e4Smiod       fields->f_dir8 = value;
1391*3d8817e4Smiod       break;
1392*3d8817e4Smiod     case FR30_OPERAND_DIR9 :
1393*3d8817e4Smiod       fields->f_dir9 = value;
1394*3d8817e4Smiod       break;
1395*3d8817e4Smiod     case FR30_OPERAND_DISP10 :
1396*3d8817e4Smiod       fields->f_disp10 = value;
1397*3d8817e4Smiod       break;
1398*3d8817e4Smiod     case FR30_OPERAND_DISP8 :
1399*3d8817e4Smiod       fields->f_disp8 = value;
1400*3d8817e4Smiod       break;
1401*3d8817e4Smiod     case FR30_OPERAND_DISP9 :
1402*3d8817e4Smiod       fields->f_disp9 = value;
1403*3d8817e4Smiod       break;
1404*3d8817e4Smiod     case FR30_OPERAND_I20 :
1405*3d8817e4Smiod       fields->f_i20 = value;
1406*3d8817e4Smiod       break;
1407*3d8817e4Smiod     case FR30_OPERAND_I32 :
1408*3d8817e4Smiod       fields->f_i32 = value;
1409*3d8817e4Smiod       break;
1410*3d8817e4Smiod     case FR30_OPERAND_I8 :
1411*3d8817e4Smiod       fields->f_i8 = value;
1412*3d8817e4Smiod       break;
1413*3d8817e4Smiod     case FR30_OPERAND_LABEL12 :
1414*3d8817e4Smiod       fields->f_rel12 = value;
1415*3d8817e4Smiod       break;
1416*3d8817e4Smiod     case FR30_OPERAND_LABEL9 :
1417*3d8817e4Smiod       fields->f_rel9 = value;
1418*3d8817e4Smiod       break;
1419*3d8817e4Smiod     case FR30_OPERAND_M4 :
1420*3d8817e4Smiod       fields->f_m4 = value;
1421*3d8817e4Smiod       break;
1422*3d8817e4Smiod     case FR30_OPERAND_PS :
1423*3d8817e4Smiod       break;
1424*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_LD :
1425*3d8817e4Smiod       fields->f_reglist_hi_ld = value;
1426*3d8817e4Smiod       break;
1427*3d8817e4Smiod     case FR30_OPERAND_REGLIST_HI_ST :
1428*3d8817e4Smiod       fields->f_reglist_hi_st = value;
1429*3d8817e4Smiod       break;
1430*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_LD :
1431*3d8817e4Smiod       fields->f_reglist_low_ld = value;
1432*3d8817e4Smiod       break;
1433*3d8817e4Smiod     case FR30_OPERAND_REGLIST_LOW_ST :
1434*3d8817e4Smiod       fields->f_reglist_low_st = value;
1435*3d8817e4Smiod       break;
1436*3d8817e4Smiod     case FR30_OPERAND_S10 :
1437*3d8817e4Smiod       fields->f_s10 = value;
1438*3d8817e4Smiod       break;
1439*3d8817e4Smiod     case FR30_OPERAND_U10 :
1440*3d8817e4Smiod       fields->f_u10 = value;
1441*3d8817e4Smiod       break;
1442*3d8817e4Smiod     case FR30_OPERAND_U4 :
1443*3d8817e4Smiod       fields->f_u4 = value;
1444*3d8817e4Smiod       break;
1445*3d8817e4Smiod     case FR30_OPERAND_U4C :
1446*3d8817e4Smiod       fields->f_u4c = value;
1447*3d8817e4Smiod       break;
1448*3d8817e4Smiod     case FR30_OPERAND_U8 :
1449*3d8817e4Smiod       fields->f_u8 = value;
1450*3d8817e4Smiod       break;
1451*3d8817e4Smiod     case FR30_OPERAND_UDISP6 :
1452*3d8817e4Smiod       fields->f_udisp6 = value;
1453*3d8817e4Smiod       break;
1454*3d8817e4Smiod 
1455*3d8817e4Smiod     default :
1456*3d8817e4Smiod       /* xgettext:c-format */
1457*3d8817e4Smiod       fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
1458*3d8817e4Smiod 		       opindex);
1459*3d8817e4Smiod       abort ();
1460*3d8817e4Smiod   }
1461*3d8817e4Smiod }
1462*3d8817e4Smiod 
1463*3d8817e4Smiod /* Function to call before using the instruction builder tables.  */
1464*3d8817e4Smiod 
1465*3d8817e4Smiod void
fr30_cgen_init_ibld_table(CGEN_CPU_DESC cd)1466*3d8817e4Smiod fr30_cgen_init_ibld_table (CGEN_CPU_DESC cd)
1467*3d8817e4Smiod {
1468*3d8817e4Smiod   cd->insert_handlers = & fr30_cgen_insert_handlers[0];
1469*3d8817e4Smiod   cd->extract_handlers = & fr30_cgen_extract_handlers[0];
1470*3d8817e4Smiod 
1471*3d8817e4Smiod   cd->insert_operand = fr30_cgen_insert_operand;
1472*3d8817e4Smiod   cd->extract_operand = fr30_cgen_extract_operand;
1473*3d8817e4Smiod 
1474*3d8817e4Smiod   cd->get_int_operand = fr30_cgen_get_int_operand;
1475*3d8817e4Smiod   cd->set_int_operand = fr30_cgen_set_int_operand;
1476*3d8817e4Smiod   cd->get_vma_operand = fr30_cgen_get_vma_operand;
1477*3d8817e4Smiod   cd->set_vma_operand = fr30_cgen_set_vma_operand;
1478*3d8817e4Smiod }
1479