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