Convert generic probe interface to C++ (and perform some cleanups)
[external/binutils.git] / opcodes / mt-ibld.c
1 /* DO NOT EDIT!  -*- buffer-read-only: t -*- vi:set ro:  */
2 /* Instruction building/extraction support for mt. -*- C -*-
3
4    THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
5    - the resultant file is machine generated, cgen-ibld.in isn't
6
7    Copyright (C) 1996-2017 Free Software Foundation, Inc.
8
9    This file is part of libopcodes.
10
11    This library is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 3, or (at your option)
14    any later version.
15
16    It is distributed in the hope that it will be useful, but WITHOUT
17    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
19    License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software Foundation, Inc.,
23    51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
24
25 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
26    Keep that in mind.  */
27
28 #include "sysdep.h"
29 #include <stdio.h>
30 #include "ansidecl.h"
31 #include "dis-asm.h"
32 #include "bfd.h"
33 #include "symcat.h"
34 #include "mt-desc.h"
35 #include "mt-opc.h"
36 #include "cgen/basic-modes.h"
37 #include "opintl.h"
38 #include "safe-ctype.h"
39
40 #undef  min
41 #define min(a,b) ((a) < (b) ? (a) : (b))
42 #undef  max
43 #define max(a,b) ((a) > (b) ? (a) : (b))
44
45 /* Used by the ifield rtx function.  */
46 #define FLD(f) (fields->f)
47
48 static const char * insert_normal
49   (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
50    unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
51 static const char * insert_insn_normal
52   (CGEN_CPU_DESC, const CGEN_INSN *,
53    CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
54 static int extract_normal
55   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
56    unsigned int, unsigned int, unsigned int, unsigned int,
57    unsigned int, unsigned int, bfd_vma, long *);
58 static int extract_insn_normal
59   (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
60    CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
61 #if CGEN_INT_INSN_P
62 static void put_insn_int_value
63   (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
64 #endif
65 #if ! CGEN_INT_INSN_P
66 static CGEN_INLINE void insert_1
67   (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
68 static CGEN_INLINE int fill_cache
69   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *,  int, int, bfd_vma);
70 static CGEN_INLINE long extract_1
71   (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
72 #endif
73 \f
74 /* Operand insertion.  */
75
76 #if ! CGEN_INT_INSN_P
77
78 /* Subroutine of insert_normal.  */
79
80 static CGEN_INLINE void
81 insert_1 (CGEN_CPU_DESC cd,
82           unsigned long value,
83           int start,
84           int length,
85           int word_length,
86           unsigned char *bufp)
87 {
88   unsigned long x,mask;
89   int shift;
90
91   x = cgen_get_insn_value (cd, bufp, word_length);
92
93   /* Written this way to avoid undefined behaviour.  */
94   mask = (((1L << (length - 1)) - 1) << 1) | 1;
95   if (CGEN_INSN_LSB0_P)
96     shift = (start + 1) - length;
97   else
98     shift = (word_length - (start + length));
99   x = (x & ~(mask << shift)) | ((value & mask) << shift);
100
101   cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
102 }
103
104 #endif /* ! CGEN_INT_INSN_P */
105
106 /* Default insertion routine.
107
108    ATTRS is a mask of the boolean attributes.
109    WORD_OFFSET is the offset in bits from the start of the insn of the value.
110    WORD_LENGTH is the length of the word in bits in which the value resides.
111    START is the starting bit number in the word, architecture origin.
112    LENGTH is the length of VALUE in bits.
113    TOTAL_LENGTH is the total length of the insn in bits.
114
115    The result is an error message or NULL if success.  */
116
117 /* ??? This duplicates functionality with bfd's howto table and
118    bfd_install_relocation.  */
119 /* ??? This doesn't handle bfd_vma's.  Create another function when
120    necessary.  */
121
122 static const char *
123 insert_normal (CGEN_CPU_DESC cd,
124                long value,
125                unsigned int attrs,
126                unsigned int word_offset,
127                unsigned int start,
128                unsigned int length,
129                unsigned int word_length,
130                unsigned int total_length,
131                CGEN_INSN_BYTES_PTR buffer)
132 {
133   static char errbuf[100];
134   /* Written this way to avoid undefined behaviour.  */
135   unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
136
137   /* If LENGTH is zero, this operand doesn't contribute to the value.  */
138   if (length == 0)
139     return NULL;
140
141   if (word_length > 8 * sizeof (CGEN_INSN_INT))
142     abort ();
143
144   /* For architectures with insns smaller than the base-insn-bitsize,
145      word_length may be too big.  */
146   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
147     {
148       if (word_offset == 0
149           && word_length > total_length)
150         word_length = total_length;
151     }
152
153   /* Ensure VALUE will fit.  */
154   if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
155     {
156       long minval = - (1L << (length - 1));
157       unsigned long maxval = mask;
158
159       if ((value > 0 && (unsigned long) value > maxval)
160           || value < minval)
161         {
162           /* xgettext:c-format */
163           sprintf (errbuf,
164                    _("operand out of range (%ld not between %ld and %lu)"),
165                    value, minval, maxval);
166           return errbuf;
167         }
168     }
169   else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
170     {
171       unsigned long maxval = mask;
172       unsigned long val = (unsigned long) value;
173
174       /* For hosts with a word size > 32 check to see if value has been sign
175          extended beyond 32 bits.  If so then ignore these higher sign bits
176          as the user is attempting to store a 32-bit signed value into an
177          unsigned 32-bit field which is allowed.  */
178       if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
179         val &= 0xFFFFFFFF;
180
181       if (val > maxval)
182         {
183           /* xgettext:c-format */
184           sprintf (errbuf,
185                    _("operand out of range (0x%lx not between 0 and 0x%lx)"),
186                    val, maxval);
187           return errbuf;
188         }
189     }
190   else
191     {
192       if (! cgen_signed_overflow_ok_p (cd))
193         {
194           long minval = - (1L << (length - 1));
195           long maxval =   (1L << (length - 1)) - 1;
196
197           if (value < minval || value > maxval)
198             {
199               sprintf
200                 /* xgettext:c-format */
201                 (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
202                  value, minval, maxval);
203               return errbuf;
204             }
205         }
206     }
207
208 #if CGEN_INT_INSN_P
209
210   {
211     int shift_within_word, shift_to_word, shift;
212
213     /* How to shift the value to BIT0 of the word.  */
214     shift_to_word = total_length - (word_offset + word_length);
215
216     /* How to shift the value to the field within the word.  */
217     if (CGEN_INSN_LSB0_P)
218       shift_within_word = start + 1 - length;
219     else
220       shift_within_word = word_length - start - length;
221
222     /* The total SHIFT, then mask in the value.  */
223     shift = shift_to_word + shift_within_word;
224     *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
225   }
226
227 #else /* ! CGEN_INT_INSN_P */
228
229   {
230     unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
231
232     insert_1 (cd, value, start, length, word_length, bufp);
233   }
234
235 #endif /* ! CGEN_INT_INSN_P */
236
237   return NULL;
238 }
239
240 /* Default insn builder (insert handler).
241    The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
242    that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
243    recorded in host byte order, otherwise BUFFER is an array of bytes
244    and the value is recorded in target byte order).
245    The result is an error message or NULL if success.  */
246
247 static const char *
248 insert_insn_normal (CGEN_CPU_DESC cd,
249                     const CGEN_INSN * insn,
250                     CGEN_FIELDS * fields,
251                     CGEN_INSN_BYTES_PTR buffer,
252                     bfd_vma pc)
253 {
254   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
255   unsigned long value;
256   const CGEN_SYNTAX_CHAR_TYPE * syn;
257
258   CGEN_INIT_INSERT (cd);
259   value = CGEN_INSN_BASE_VALUE (insn);
260
261   /* If we're recording insns as numbers (rather than a string of bytes),
262      target byte order handling is deferred until later.  */
263
264 #if CGEN_INT_INSN_P
265
266   put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
267                       CGEN_FIELDS_BITSIZE (fields), value);
268
269 #else
270
271   cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
272                                         (unsigned) CGEN_FIELDS_BITSIZE (fields)),
273                        value);
274
275 #endif /* ! CGEN_INT_INSN_P */
276
277   /* ??? It would be better to scan the format's fields.
278      Still need to be able to insert a value based on the operand though;
279      e.g. storing a branch displacement that got resolved later.
280      Needs more thought first.  */
281
282   for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
283     {
284       const char *errmsg;
285
286       if (CGEN_SYNTAX_CHAR_P (* syn))
287         continue;
288
289       errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
290                                        fields, buffer, pc);
291       if (errmsg)
292         return errmsg;
293     }
294
295   return NULL;
296 }
297
298 #if CGEN_INT_INSN_P
299 /* Cover function to store an insn value into an integral insn.  Must go here
300    because it needs <prefix>-desc.h for CGEN_INT_INSN_P.  */
301
302 static void
303 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
304                     CGEN_INSN_BYTES_PTR buf,
305                     int length,
306                     int insn_length,
307                     CGEN_INSN_INT value)
308 {
309   /* For architectures with insns smaller than the base-insn-bitsize,
310      length may be too big.  */
311   if (length > insn_length)
312     *buf = value;
313   else
314     {
315       int shift = insn_length - length;
316       /* Written this way to avoid undefined behaviour.  */
317       CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
318
319       *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
320     }
321 }
322 #endif
323 \f
324 /* Operand extraction.  */
325
326 #if ! CGEN_INT_INSN_P
327
328 /* Subroutine of extract_normal.
329    Ensure sufficient bytes are cached in EX_INFO.
330    OFFSET is the offset in bytes from the start of the insn of the value.
331    BYTES is the length of the needed value.
332    Returns 1 for success, 0 for failure.  */
333
334 static CGEN_INLINE int
335 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
336             CGEN_EXTRACT_INFO *ex_info,
337             int offset,
338             int bytes,
339             bfd_vma pc)
340 {
341   /* It's doubtful that the middle part has already been fetched so
342      we don't optimize that case.  kiss.  */
343   unsigned int mask;
344   disassemble_info *info = (disassemble_info *) ex_info->dis_info;
345
346   /* First do a quick check.  */
347   mask = (1 << bytes) - 1;
348   if (((ex_info->valid >> offset) & mask) == mask)
349     return 1;
350
351   /* Search for the first byte we need to read.  */
352   for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
353     if (! (mask & ex_info->valid))
354       break;
355
356   if (bytes)
357     {
358       int status;
359
360       pc += offset;
361       status = (*info->read_memory_func)
362         (pc, ex_info->insn_bytes + offset, bytes, info);
363
364       if (status != 0)
365         {
366           (*info->memory_error_func) (status, pc, info);
367           return 0;
368         }
369
370       ex_info->valid |= ((1 << bytes) - 1) << offset;
371     }
372
373   return 1;
374 }
375
376 /* Subroutine of extract_normal.  */
377
378 static CGEN_INLINE long
379 extract_1 (CGEN_CPU_DESC cd,
380            CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
381            int start,
382            int length,
383            int word_length,
384            unsigned char *bufp,
385            bfd_vma pc ATTRIBUTE_UNUSED)
386 {
387   unsigned long x;
388   int shift;
389
390   x = cgen_get_insn_value (cd, bufp, word_length);
391
392   if (CGEN_INSN_LSB0_P)
393     shift = (start + 1) - length;
394   else
395     shift = (word_length - (start + length));
396   return x >> shift;
397 }
398
399 #endif /* ! CGEN_INT_INSN_P */
400
401 /* Default extraction routine.
402
403    INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
404    or sometimes less for cases like the m32r where the base insn size is 32
405    but some insns are 16 bits.
406    ATTRS is a mask of the boolean attributes.  We only need `SIGNED',
407    but for generality we take a bitmask of all of them.
408    WORD_OFFSET is the offset in bits from the start of the insn of the value.
409    WORD_LENGTH is the length of the word in bits in which the value resides.
410    START is the starting bit number in the word, architecture origin.
411    LENGTH is the length of VALUE in bits.
412    TOTAL_LENGTH is the total length of the insn in bits.
413
414    Returns 1 for success, 0 for failure.  */
415
416 /* ??? The return code isn't properly used.  wip.  */
417
418 /* ??? This doesn't handle bfd_vma's.  Create another function when
419    necessary.  */
420
421 static int
422 extract_normal (CGEN_CPU_DESC cd,
423 #if ! CGEN_INT_INSN_P
424                 CGEN_EXTRACT_INFO *ex_info,
425 #else
426                 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
427 #endif
428                 CGEN_INSN_INT insn_value,
429                 unsigned int attrs,
430                 unsigned int word_offset,
431                 unsigned int start,
432                 unsigned int length,
433                 unsigned int word_length,
434                 unsigned int total_length,
435 #if ! CGEN_INT_INSN_P
436                 bfd_vma pc,
437 #else
438                 bfd_vma pc ATTRIBUTE_UNUSED,
439 #endif
440                 long *valuep)
441 {
442   long value, mask;
443
444   /* If LENGTH is zero, this operand doesn't contribute to the value
445      so give it a standard value of zero.  */
446   if (length == 0)
447     {
448       *valuep = 0;
449       return 1;
450     }
451
452   if (word_length > 8 * sizeof (CGEN_INSN_INT))
453     abort ();
454
455   /* For architectures with insns smaller than the insn-base-bitsize,
456      word_length may be too big.  */
457   if (cd->min_insn_bitsize < cd->base_insn_bitsize)
458     {
459       if (word_offset + word_length > total_length)
460         word_length = total_length - word_offset;
461     }
462
463   /* Does the value reside in INSN_VALUE, and at the right alignment?  */
464
465   if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
466     {
467       if (CGEN_INSN_LSB0_P)
468         value = insn_value >> ((word_offset + start + 1) - length);
469       else
470         value = insn_value >> (total_length - ( word_offset + start + length));
471     }
472
473 #if ! CGEN_INT_INSN_P
474
475   else
476     {
477       unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
478
479       if (word_length > 8 * sizeof (CGEN_INSN_INT))
480         abort ();
481
482       if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
483         return 0;
484
485       value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
486     }
487
488 #endif /* ! CGEN_INT_INSN_P */
489
490   /* Written this way to avoid undefined behaviour.  */
491   mask = (((1L << (length - 1)) - 1) << 1) | 1;
492
493   value &= mask;
494   /* sign extend? */
495   if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
496       && (value & (1L << (length - 1))))
497     value |= ~mask;
498
499   *valuep = value;
500
501   return 1;
502 }
503
504 /* Default insn extractor.
505
506    INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
507    The extracted fields are stored in FIELDS.
508    EX_INFO is used to handle reading variable length insns.
509    Return the length of the insn in bits, or 0 if no match,
510    or -1 if an error occurs fetching data (memory_error_func will have
511    been called).  */
512
513 static int
514 extract_insn_normal (CGEN_CPU_DESC cd,
515                      const CGEN_INSN *insn,
516                      CGEN_EXTRACT_INFO *ex_info,
517                      CGEN_INSN_INT insn_value,
518                      CGEN_FIELDS *fields,
519                      bfd_vma pc)
520 {
521   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
522   const CGEN_SYNTAX_CHAR_TYPE *syn;
523
524   CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
525
526   CGEN_INIT_EXTRACT (cd);
527
528   for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
529     {
530       int length;
531
532       if (CGEN_SYNTAX_CHAR_P (*syn))
533         continue;
534
535       length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
536                                         ex_info, insn_value, fields, pc);
537       if (length <= 0)
538         return length;
539     }
540
541   /* We recognized and successfully extracted this insn.  */
542   return CGEN_INSN_BITSIZE (insn);
543 }
544 \f
545 /* Machine generated code added here.  */
546
547 const char * mt_cgen_insert_operand
548   (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
549
550 /* Main entry point for operand insertion.
551
552    This function is basically just a big switch statement.  Earlier versions
553    used tables to look up the function to use, but
554    - if the table contains both assembler and disassembler functions then
555      the disassembler contains much of the assembler and vice-versa,
556    - there's a lot of inlining possibilities as things grow,
557    - using a switch statement avoids the function call overhead.
558
559    This function could be moved into `parse_insn_normal', but keeping it
560    separate makes clear the interface between `parse_insn_normal' and each of
561    the handlers.  It's also needed by GAS to insert operands that couldn't be
562    resolved during parsing.  */
563
564 const char *
565 mt_cgen_insert_operand (CGEN_CPU_DESC cd,
566                              int opindex,
567                              CGEN_FIELDS * fields,
568                              CGEN_INSN_BYTES_PTR buffer,
569                              bfd_vma pc ATTRIBUTE_UNUSED)
570 {
571   const char * errmsg = NULL;
572   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
573
574   switch (opindex)
575     {
576     case MT_OPERAND_A23 :
577       errmsg = insert_normal (cd, fields->f_a23, 0, 0, 23, 1, 32, total_length, buffer);
578       break;
579     case MT_OPERAND_BALL :
580       errmsg = insert_normal (cd, fields->f_ball, 0, 0, 19, 1, 32, total_length, buffer);
581       break;
582     case MT_OPERAND_BALL2 :
583       errmsg = insert_normal (cd, fields->f_ball2, 0, 0, 15, 1, 32, total_length, buffer);
584       break;
585     case MT_OPERAND_BANKADDR :
586       errmsg = insert_normal (cd, fields->f_bankaddr, 0, 0, 25, 13, 32, total_length, buffer);
587       break;
588     case MT_OPERAND_BRC :
589       errmsg = insert_normal (cd, fields->f_brc, 0, 0, 18, 3, 32, total_length, buffer);
590       break;
591     case MT_OPERAND_BRC2 :
592       errmsg = insert_normal (cd, fields->f_brc2, 0, 0, 14, 3, 32, total_length, buffer);
593       break;
594     case MT_OPERAND_CB1INCR :
595       errmsg = insert_normal (cd, fields->f_cb1incr, 0|(1<<CGEN_IFLD_SIGNED), 0, 19, 6, 32, total_length, buffer);
596       break;
597     case MT_OPERAND_CB1SEL :
598       errmsg = insert_normal (cd, fields->f_cb1sel, 0, 0, 25, 3, 32, total_length, buffer);
599       break;
600     case MT_OPERAND_CB2INCR :
601       errmsg = insert_normal (cd, fields->f_cb2incr, 0|(1<<CGEN_IFLD_SIGNED), 0, 13, 6, 32, total_length, buffer);
602       break;
603     case MT_OPERAND_CB2SEL :
604       errmsg = insert_normal (cd, fields->f_cb2sel, 0, 0, 22, 3, 32, total_length, buffer);
605       break;
606     case MT_OPERAND_CBRB :
607       errmsg = insert_normal (cd, fields->f_cbrb, 0, 0, 10, 1, 32, total_length, buffer);
608       break;
609     case MT_OPERAND_CBS :
610       errmsg = insert_normal (cd, fields->f_cbs, 0, 0, 19, 2, 32, total_length, buffer);
611       break;
612     case MT_OPERAND_CBX :
613       errmsg = insert_normal (cd, fields->f_cbx, 0, 0, 14, 3, 32, total_length, buffer);
614       break;
615     case MT_OPERAND_CCB :
616       errmsg = insert_normal (cd, fields->f_ccb, 0, 0, 11, 1, 32, total_length, buffer);
617       break;
618     case MT_OPERAND_CDB :
619       errmsg = insert_normal (cd, fields->f_cdb, 0, 0, 10, 1, 32, total_length, buffer);
620       break;
621     case MT_OPERAND_CELL :
622       errmsg = insert_normal (cd, fields->f_cell, 0, 0, 9, 3, 32, total_length, buffer);
623       break;
624     case MT_OPERAND_COLNUM :
625       errmsg = insert_normal (cd, fields->f_colnum, 0, 0, 18, 3, 32, total_length, buffer);
626       break;
627     case MT_OPERAND_CONTNUM :
628       errmsg = insert_normal (cd, fields->f_contnum, 0, 0, 8, 9, 32, total_length, buffer);
629       break;
630     case MT_OPERAND_CR :
631       errmsg = insert_normal (cd, fields->f_cr, 0, 0, 22, 3, 32, total_length, buffer);
632       break;
633     case MT_OPERAND_CTXDISP :
634       errmsg = insert_normal (cd, fields->f_ctxdisp, 0, 0, 5, 6, 32, total_length, buffer);
635       break;
636     case MT_OPERAND_DUP :
637       errmsg = insert_normal (cd, fields->f_dup, 0, 0, 6, 1, 32, total_length, buffer);
638       break;
639     case MT_OPERAND_FBDISP :
640       errmsg = insert_normal (cd, fields->f_fbdisp, 0, 0, 15, 6, 32, total_length, buffer);
641       break;
642     case MT_OPERAND_FBINCR :
643       errmsg = insert_normal (cd, fields->f_fbincr, 0, 0, 23, 4, 32, total_length, buffer);
644       break;
645     case MT_OPERAND_FRDR :
646       errmsg = insert_normal (cd, fields->f_dr, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, buffer);
647       break;
648     case MT_OPERAND_FRDRRR :
649       errmsg = insert_normal (cd, fields->f_drrr, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 4, 32, total_length, buffer);
650       break;
651     case MT_OPERAND_FRSR1 :
652       errmsg = insert_normal (cd, fields->f_sr1, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 23, 4, 32, total_length, buffer);
653       break;
654     case MT_OPERAND_FRSR2 :
655       errmsg = insert_normal (cd, fields->f_sr2, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, buffer);
656       break;
657     case MT_OPERAND_ID :
658       errmsg = insert_normal (cd, fields->f_id, 0, 0, 14, 1, 32, total_length, buffer);
659       break;
660     case MT_OPERAND_IMM16 :
661       {
662         long value = fields->f_imm16s;
663         value = ((value) + (0));
664         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, buffer);
665       }
666       break;
667     case MT_OPERAND_IMM16L :
668       errmsg = insert_normal (cd, fields->f_imm16l, 0, 0, 23, 16, 32, total_length, buffer);
669       break;
670     case MT_OPERAND_IMM16O :
671       {
672         long value = fields->f_imm16s;
673         value = ((value) + (0));
674         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, buffer);
675       }
676       break;
677     case MT_OPERAND_IMM16Z :
678       errmsg = insert_normal (cd, fields->f_imm16u, 0, 0, 15, 16, 32, total_length, buffer);
679       break;
680     case MT_OPERAND_INCAMT :
681       errmsg = insert_normal (cd, fields->f_incamt, 0, 0, 19, 8, 32, total_length, buffer);
682       break;
683     case MT_OPERAND_INCR :
684       errmsg = insert_normal (cd, fields->f_incr, 0, 0, 17, 6, 32, total_length, buffer);
685       break;
686     case MT_OPERAND_LENGTH :
687       errmsg = insert_normal (cd, fields->f_length, 0, 0, 15, 3, 32, total_length, buffer);
688       break;
689     case MT_OPERAND_LOOPSIZE :
690       {
691         long value = fields->f_loopo;
692         value = ((USI) (value) >> (2));
693         errmsg = insert_normal (cd, value, 0, 0, 7, 8, 32, total_length, buffer);
694       }
695       break;
696     case MT_OPERAND_MASK :
697       errmsg = insert_normal (cd, fields->f_mask, 0, 0, 25, 16, 32, total_length, buffer);
698       break;
699     case MT_OPERAND_MASK1 :
700       errmsg = insert_normal (cd, fields->f_mask1, 0, 0, 22, 3, 32, total_length, buffer);
701       break;
702     case MT_OPERAND_MODE :
703       errmsg = insert_normal (cd, fields->f_mode, 0, 0, 25, 2, 32, total_length, buffer);
704       break;
705     case MT_OPERAND_PERM :
706       errmsg = insert_normal (cd, fields->f_perm, 0, 0, 25, 2, 32, total_length, buffer);
707       break;
708     case MT_OPERAND_RBBC :
709       errmsg = insert_normal (cd, fields->f_rbbc, 0, 0, 25, 2, 32, total_length, buffer);
710       break;
711     case MT_OPERAND_RC :
712       errmsg = insert_normal (cd, fields->f_rc, 0, 0, 15, 1, 32, total_length, buffer);
713       break;
714     case MT_OPERAND_RC1 :
715       errmsg = insert_normal (cd, fields->f_rc1, 0, 0, 11, 1, 32, total_length, buffer);
716       break;
717     case MT_OPERAND_RC2 :
718       errmsg = insert_normal (cd, fields->f_rc2, 0, 0, 6, 1, 32, total_length, buffer);
719       break;
720     case MT_OPERAND_RC3 :
721       errmsg = insert_normal (cd, fields->f_rc3, 0, 0, 7, 1, 32, total_length, buffer);
722       break;
723     case MT_OPERAND_RCNUM :
724       errmsg = insert_normal (cd, fields->f_rcnum, 0, 0, 14, 3, 32, total_length, buffer);
725       break;
726     case MT_OPERAND_RDA :
727       errmsg = insert_normal (cd, fields->f_rda, 0, 0, 25, 1, 32, total_length, buffer);
728       break;
729     case MT_OPERAND_ROWNUM :
730       errmsg = insert_normal (cd, fields->f_rownum, 0, 0, 14, 3, 32, total_length, buffer);
731       break;
732     case MT_OPERAND_ROWNUM1 :
733       errmsg = insert_normal (cd, fields->f_rownum1, 0, 0, 12, 3, 32, total_length, buffer);
734       break;
735     case MT_OPERAND_ROWNUM2 :
736       errmsg = insert_normal (cd, fields->f_rownum2, 0, 0, 9, 3, 32, total_length, buffer);
737       break;
738     case MT_OPERAND_SIZE :
739       errmsg = insert_normal (cd, fields->f_size, 0, 0, 13, 14, 32, total_length, buffer);
740       break;
741     case MT_OPERAND_TYPE :
742       errmsg = insert_normal (cd, fields->f_type, 0, 0, 21, 2, 32, total_length, buffer);
743       break;
744     case MT_OPERAND_WR :
745       errmsg = insert_normal (cd, fields->f_wr, 0, 0, 24, 1, 32, total_length, buffer);
746       break;
747     case MT_OPERAND_XMODE :
748       errmsg = insert_normal (cd, fields->f_xmode, 0, 0, 23, 1, 32, total_length, buffer);
749       break;
750
751     default :
752       /* xgettext:c-format */
753       fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
754                opindex);
755       abort ();
756   }
757
758   return errmsg;
759 }
760
761 int mt_cgen_extract_operand
762   (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
763
764 /* Main entry point for operand extraction.
765    The result is <= 0 for error, >0 for success.
766    ??? Actual values aren't well defined right now.
767
768    This function is basically just a big switch statement.  Earlier versions
769    used tables to look up the function to use, but
770    - if the table contains both assembler and disassembler functions then
771      the disassembler contains much of the assembler and vice-versa,
772    - there's a lot of inlining possibilities as things grow,
773    - using a switch statement avoids the function call overhead.
774
775    This function could be moved into `print_insn_normal', but keeping it
776    separate makes clear the interface between `print_insn_normal' and each of
777    the handlers.  */
778
779 int
780 mt_cgen_extract_operand (CGEN_CPU_DESC cd,
781                              int opindex,
782                              CGEN_EXTRACT_INFO *ex_info,
783                              CGEN_INSN_INT insn_value,
784                              CGEN_FIELDS * fields,
785                              bfd_vma pc)
786 {
787   /* Assume success (for those operands that are nops).  */
788   int length = 1;
789   unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
790
791   switch (opindex)
792     {
793     case MT_OPERAND_A23 :
794       length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 1, 32, total_length, pc, & fields->f_a23);
795       break;
796     case MT_OPERAND_BALL :
797       length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 1, 32, total_length, pc, & fields->f_ball);
798       break;
799     case MT_OPERAND_BALL2 :
800       length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 1, 32, total_length, pc, & fields->f_ball2);
801       break;
802     case MT_OPERAND_BANKADDR :
803       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 13, 32, total_length, pc, & fields->f_bankaddr);
804       break;
805     case MT_OPERAND_BRC :
806       length = extract_normal (cd, ex_info, insn_value, 0, 0, 18, 3, 32, total_length, pc, & fields->f_brc);
807       break;
808     case MT_OPERAND_BRC2 :
809       length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_brc2);
810       break;
811     case MT_OPERAND_CB1INCR :
812       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 19, 6, 32, total_length, pc, & fields->f_cb1incr);
813       break;
814     case MT_OPERAND_CB1SEL :
815       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 3, 32, total_length, pc, & fields->f_cb1sel);
816       break;
817     case MT_OPERAND_CB2INCR :
818       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 13, 6, 32, total_length, pc, & fields->f_cb2incr);
819       break;
820     case MT_OPERAND_CB2SEL :
821       length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_cb2sel);
822       break;
823     case MT_OPERAND_CBRB :
824       length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_cbrb);
825       break;
826     case MT_OPERAND_CBS :
827       length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 2, 32, total_length, pc, & fields->f_cbs);
828       break;
829     case MT_OPERAND_CBX :
830       length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_cbx);
831       break;
832     case MT_OPERAND_CCB :
833       length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_ccb);
834       break;
835     case MT_OPERAND_CDB :
836       length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_cdb);
837       break;
838     case MT_OPERAND_CELL :
839       length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 3, 32, total_length, pc, & fields->f_cell);
840       break;
841     case MT_OPERAND_COLNUM :
842       length = extract_normal (cd, ex_info, insn_value, 0, 0, 18, 3, 32, total_length, pc, & fields->f_colnum);
843       break;
844     case MT_OPERAND_CONTNUM :
845       length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 9, 32, total_length, pc, & fields->f_contnum);
846       break;
847     case MT_OPERAND_CR :
848       length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_cr);
849       break;
850     case MT_OPERAND_CTXDISP :
851       length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 6, 32, total_length, pc, & fields->f_ctxdisp);
852       break;
853     case MT_OPERAND_DUP :
854       length = extract_normal (cd, ex_info, insn_value, 0, 0, 6, 1, 32, total_length, pc, & fields->f_dup);
855       break;
856     case MT_OPERAND_FBDISP :
857       length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 6, 32, total_length, pc, & fields->f_fbdisp);
858       break;
859     case MT_OPERAND_FBINCR :
860       length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 4, 32, total_length, pc, & fields->f_fbincr);
861       break;
862     case MT_OPERAND_FRDR :
863       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, pc, & fields->f_dr);
864       break;
865     case MT_OPERAND_FRDRRR :
866       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 4, 32, total_length, pc, & fields->f_drrr);
867       break;
868     case MT_OPERAND_FRSR1 :
869       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 23, 4, 32, total_length, pc, & fields->f_sr1);
870       break;
871     case MT_OPERAND_FRSR2 :
872       length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, pc, & fields->f_sr2);
873       break;
874     case MT_OPERAND_ID :
875       length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 1, 32, total_length, pc, & fields->f_id);
876       break;
877     case MT_OPERAND_IMM16 :
878       {
879         long value;
880         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, pc, & value);
881         value = ((value) + (0));
882         fields->f_imm16s = value;
883       }
884       break;
885     case MT_OPERAND_IMM16L :
886       length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 16, 32, total_length, pc, & fields->f_imm16l);
887       break;
888     case MT_OPERAND_IMM16O :
889       {
890         long value;
891         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, pc, & value);
892         value = ((value) + (0));
893         fields->f_imm16s = value;
894       }
895       break;
896     case MT_OPERAND_IMM16Z :
897       length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm16u);
898       break;
899     case MT_OPERAND_INCAMT :
900       length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 8, 32, total_length, pc, & fields->f_incamt);
901       break;
902     case MT_OPERAND_INCR :
903       length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 6, 32, total_length, pc, & fields->f_incr);
904       break;
905     case MT_OPERAND_LENGTH :
906       length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 3, 32, total_length, pc, & fields->f_length);
907       break;
908     case MT_OPERAND_LOOPSIZE :
909       {
910         long value;
911         length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 32, total_length, pc, & value);
912         value = ((((value) << (2))) + (8));
913         fields->f_loopo = value;
914       }
915       break;
916     case MT_OPERAND_MASK :
917       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 16, 32, total_length, pc, & fields->f_mask);
918       break;
919     case MT_OPERAND_MASK1 :
920       length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_mask1);
921       break;
922     case MT_OPERAND_MODE :
923       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_mode);
924       break;
925     case MT_OPERAND_PERM :
926       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_perm);
927       break;
928     case MT_OPERAND_RBBC :
929       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_rbbc);
930       break;
931     case MT_OPERAND_RC :
932       length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 1, 32, total_length, pc, & fields->f_rc);
933       break;
934     case MT_OPERAND_RC1 :
935       length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_rc1);
936       break;
937     case MT_OPERAND_RC2 :
938       length = extract_normal (cd, ex_info, insn_value, 0, 0, 6, 1, 32, total_length, pc, & fields->f_rc2);
939       break;
940     case MT_OPERAND_RC3 :
941       length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 1, 32, total_length, pc, & fields->f_rc3);
942       break;
943     case MT_OPERAND_RCNUM :
944       length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_rcnum);
945       break;
946     case MT_OPERAND_RDA :
947       length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 1, 32, total_length, pc, & fields->f_rda);
948       break;
949     case MT_OPERAND_ROWNUM :
950       length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_rownum);
951       break;
952     case MT_OPERAND_ROWNUM1 :
953       length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 3, 32, total_length, pc, & fields->f_rownum1);
954       break;
955     case MT_OPERAND_ROWNUM2 :
956       length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 3, 32, total_length, pc, & fields->f_rownum2);
957       break;
958     case MT_OPERAND_SIZE :
959       length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 14, 32, total_length, pc, & fields->f_size);
960       break;
961     case MT_OPERAND_TYPE :
962       length = extract_normal (cd, ex_info, insn_value, 0, 0, 21, 2, 32, total_length, pc, & fields->f_type);
963       break;
964     case MT_OPERAND_WR :
965       length = extract_normal (cd, ex_info, insn_value, 0, 0, 24, 1, 32, total_length, pc, & fields->f_wr);
966       break;
967     case MT_OPERAND_XMODE :
968       length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 1, 32, total_length, pc, & fields->f_xmode);
969       break;
970
971     default :
972       /* xgettext:c-format */
973       fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
974                opindex);
975       abort ();
976     }
977
978   return length;
979 }
980
981 cgen_insert_fn * const mt_cgen_insert_handlers[] =
982 {
983   insert_insn_normal,
984 };
985
986 cgen_extract_fn * const mt_cgen_extract_handlers[] =
987 {
988   extract_insn_normal,
989 };
990
991 int mt_cgen_get_int_operand     (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
992 bfd_vma mt_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
993
994 /* Getting values from cgen_fields is handled by a collection of functions.
995    They are distinguished by the type of the VALUE argument they return.
996    TODO: floating point, inlining support, remove cases where result type
997    not appropriate.  */
998
999 int
1000 mt_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1001                              int opindex,
1002                              const CGEN_FIELDS * fields)
1003 {
1004   int value;
1005
1006   switch (opindex)
1007     {
1008     case MT_OPERAND_A23 :
1009       value = fields->f_a23;
1010       break;
1011     case MT_OPERAND_BALL :
1012       value = fields->f_ball;
1013       break;
1014     case MT_OPERAND_BALL2 :
1015       value = fields->f_ball2;
1016       break;
1017     case MT_OPERAND_BANKADDR :
1018       value = fields->f_bankaddr;
1019       break;
1020     case MT_OPERAND_BRC :
1021       value = fields->f_brc;
1022       break;
1023     case MT_OPERAND_BRC2 :
1024       value = fields->f_brc2;
1025       break;
1026     case MT_OPERAND_CB1INCR :
1027       value = fields->f_cb1incr;
1028       break;
1029     case MT_OPERAND_CB1SEL :
1030       value = fields->f_cb1sel;
1031       break;
1032     case MT_OPERAND_CB2INCR :
1033       value = fields->f_cb2incr;
1034       break;
1035     case MT_OPERAND_CB2SEL :
1036       value = fields->f_cb2sel;
1037       break;
1038     case MT_OPERAND_CBRB :
1039       value = fields->f_cbrb;
1040       break;
1041     case MT_OPERAND_CBS :
1042       value = fields->f_cbs;
1043       break;
1044     case MT_OPERAND_CBX :
1045       value = fields->f_cbx;
1046       break;
1047     case MT_OPERAND_CCB :
1048       value = fields->f_ccb;
1049       break;
1050     case MT_OPERAND_CDB :
1051       value = fields->f_cdb;
1052       break;
1053     case MT_OPERAND_CELL :
1054       value = fields->f_cell;
1055       break;
1056     case MT_OPERAND_COLNUM :
1057       value = fields->f_colnum;
1058       break;
1059     case MT_OPERAND_CONTNUM :
1060       value = fields->f_contnum;
1061       break;
1062     case MT_OPERAND_CR :
1063       value = fields->f_cr;
1064       break;
1065     case MT_OPERAND_CTXDISP :
1066       value = fields->f_ctxdisp;
1067       break;
1068     case MT_OPERAND_DUP :
1069       value = fields->f_dup;
1070       break;
1071     case MT_OPERAND_FBDISP :
1072       value = fields->f_fbdisp;
1073       break;
1074     case MT_OPERAND_FBINCR :
1075       value = fields->f_fbincr;
1076       break;
1077     case MT_OPERAND_FRDR :
1078       value = fields->f_dr;
1079       break;
1080     case MT_OPERAND_FRDRRR :
1081       value = fields->f_drrr;
1082       break;
1083     case MT_OPERAND_FRSR1 :
1084       value = fields->f_sr1;
1085       break;
1086     case MT_OPERAND_FRSR2 :
1087       value = fields->f_sr2;
1088       break;
1089     case MT_OPERAND_ID :
1090       value = fields->f_id;
1091       break;
1092     case MT_OPERAND_IMM16 :
1093       value = fields->f_imm16s;
1094       break;
1095     case MT_OPERAND_IMM16L :
1096       value = fields->f_imm16l;
1097       break;
1098     case MT_OPERAND_IMM16O :
1099       value = fields->f_imm16s;
1100       break;
1101     case MT_OPERAND_IMM16Z :
1102       value = fields->f_imm16u;
1103       break;
1104     case MT_OPERAND_INCAMT :
1105       value = fields->f_incamt;
1106       break;
1107     case MT_OPERAND_INCR :
1108       value = fields->f_incr;
1109       break;
1110     case MT_OPERAND_LENGTH :
1111       value = fields->f_length;
1112       break;
1113     case MT_OPERAND_LOOPSIZE :
1114       value = fields->f_loopo;
1115       break;
1116     case MT_OPERAND_MASK :
1117       value = fields->f_mask;
1118       break;
1119     case MT_OPERAND_MASK1 :
1120       value = fields->f_mask1;
1121       break;
1122     case MT_OPERAND_MODE :
1123       value = fields->f_mode;
1124       break;
1125     case MT_OPERAND_PERM :
1126       value = fields->f_perm;
1127       break;
1128     case MT_OPERAND_RBBC :
1129       value = fields->f_rbbc;
1130       break;
1131     case MT_OPERAND_RC :
1132       value = fields->f_rc;
1133       break;
1134     case MT_OPERAND_RC1 :
1135       value = fields->f_rc1;
1136       break;
1137     case MT_OPERAND_RC2 :
1138       value = fields->f_rc2;
1139       break;
1140     case MT_OPERAND_RC3 :
1141       value = fields->f_rc3;
1142       break;
1143     case MT_OPERAND_RCNUM :
1144       value = fields->f_rcnum;
1145       break;
1146     case MT_OPERAND_RDA :
1147       value = fields->f_rda;
1148       break;
1149     case MT_OPERAND_ROWNUM :
1150       value = fields->f_rownum;
1151       break;
1152     case MT_OPERAND_ROWNUM1 :
1153       value = fields->f_rownum1;
1154       break;
1155     case MT_OPERAND_ROWNUM2 :
1156       value = fields->f_rownum2;
1157       break;
1158     case MT_OPERAND_SIZE :
1159       value = fields->f_size;
1160       break;
1161     case MT_OPERAND_TYPE :
1162       value = fields->f_type;
1163       break;
1164     case MT_OPERAND_WR :
1165       value = fields->f_wr;
1166       break;
1167     case MT_OPERAND_XMODE :
1168       value = fields->f_xmode;
1169       break;
1170
1171     default :
1172       /* xgettext:c-format */
1173       fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
1174                        opindex);
1175       abort ();
1176   }
1177
1178   return value;
1179 }
1180
1181 bfd_vma
1182 mt_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1183                              int opindex,
1184                              const CGEN_FIELDS * fields)
1185 {
1186   bfd_vma value;
1187
1188   switch (opindex)
1189     {
1190     case MT_OPERAND_A23 :
1191       value = fields->f_a23;
1192       break;
1193     case MT_OPERAND_BALL :
1194       value = fields->f_ball;
1195       break;
1196     case MT_OPERAND_BALL2 :
1197       value = fields->f_ball2;
1198       break;
1199     case MT_OPERAND_BANKADDR :
1200       value = fields->f_bankaddr;
1201       break;
1202     case MT_OPERAND_BRC :
1203       value = fields->f_brc;
1204       break;
1205     case MT_OPERAND_BRC2 :
1206       value = fields->f_brc2;
1207       break;
1208     case MT_OPERAND_CB1INCR :
1209       value = fields->f_cb1incr;
1210       break;
1211     case MT_OPERAND_CB1SEL :
1212       value = fields->f_cb1sel;
1213       break;
1214     case MT_OPERAND_CB2INCR :
1215       value = fields->f_cb2incr;
1216       break;
1217     case MT_OPERAND_CB2SEL :
1218       value = fields->f_cb2sel;
1219       break;
1220     case MT_OPERAND_CBRB :
1221       value = fields->f_cbrb;
1222       break;
1223     case MT_OPERAND_CBS :
1224       value = fields->f_cbs;
1225       break;
1226     case MT_OPERAND_CBX :
1227       value = fields->f_cbx;
1228       break;
1229     case MT_OPERAND_CCB :
1230       value = fields->f_ccb;
1231       break;
1232     case MT_OPERAND_CDB :
1233       value = fields->f_cdb;
1234       break;
1235     case MT_OPERAND_CELL :
1236       value = fields->f_cell;
1237       break;
1238     case MT_OPERAND_COLNUM :
1239       value = fields->f_colnum;
1240       break;
1241     case MT_OPERAND_CONTNUM :
1242       value = fields->f_contnum;
1243       break;
1244     case MT_OPERAND_CR :
1245       value = fields->f_cr;
1246       break;
1247     case MT_OPERAND_CTXDISP :
1248       value = fields->f_ctxdisp;
1249       break;
1250     case MT_OPERAND_DUP :
1251       value = fields->f_dup;
1252       break;
1253     case MT_OPERAND_FBDISP :
1254       value = fields->f_fbdisp;
1255       break;
1256     case MT_OPERAND_FBINCR :
1257       value = fields->f_fbincr;
1258       break;
1259     case MT_OPERAND_FRDR :
1260       value = fields->f_dr;
1261       break;
1262     case MT_OPERAND_FRDRRR :
1263       value = fields->f_drrr;
1264       break;
1265     case MT_OPERAND_FRSR1 :
1266       value = fields->f_sr1;
1267       break;
1268     case MT_OPERAND_FRSR2 :
1269       value = fields->f_sr2;
1270       break;
1271     case MT_OPERAND_ID :
1272       value = fields->f_id;
1273       break;
1274     case MT_OPERAND_IMM16 :
1275       value = fields->f_imm16s;
1276       break;
1277     case MT_OPERAND_IMM16L :
1278       value = fields->f_imm16l;
1279       break;
1280     case MT_OPERAND_IMM16O :
1281       value = fields->f_imm16s;
1282       break;
1283     case MT_OPERAND_IMM16Z :
1284       value = fields->f_imm16u;
1285       break;
1286     case MT_OPERAND_INCAMT :
1287       value = fields->f_incamt;
1288       break;
1289     case MT_OPERAND_INCR :
1290       value = fields->f_incr;
1291       break;
1292     case MT_OPERAND_LENGTH :
1293       value = fields->f_length;
1294       break;
1295     case MT_OPERAND_LOOPSIZE :
1296       value = fields->f_loopo;
1297       break;
1298     case MT_OPERAND_MASK :
1299       value = fields->f_mask;
1300       break;
1301     case MT_OPERAND_MASK1 :
1302       value = fields->f_mask1;
1303       break;
1304     case MT_OPERAND_MODE :
1305       value = fields->f_mode;
1306       break;
1307     case MT_OPERAND_PERM :
1308       value = fields->f_perm;
1309       break;
1310     case MT_OPERAND_RBBC :
1311       value = fields->f_rbbc;
1312       break;
1313     case MT_OPERAND_RC :
1314       value = fields->f_rc;
1315       break;
1316     case MT_OPERAND_RC1 :
1317       value = fields->f_rc1;
1318       break;
1319     case MT_OPERAND_RC2 :
1320       value = fields->f_rc2;
1321       break;
1322     case MT_OPERAND_RC3 :
1323       value = fields->f_rc3;
1324       break;
1325     case MT_OPERAND_RCNUM :
1326       value = fields->f_rcnum;
1327       break;
1328     case MT_OPERAND_RDA :
1329       value = fields->f_rda;
1330       break;
1331     case MT_OPERAND_ROWNUM :
1332       value = fields->f_rownum;
1333       break;
1334     case MT_OPERAND_ROWNUM1 :
1335       value = fields->f_rownum1;
1336       break;
1337     case MT_OPERAND_ROWNUM2 :
1338       value = fields->f_rownum2;
1339       break;
1340     case MT_OPERAND_SIZE :
1341       value = fields->f_size;
1342       break;
1343     case MT_OPERAND_TYPE :
1344       value = fields->f_type;
1345       break;
1346     case MT_OPERAND_WR :
1347       value = fields->f_wr;
1348       break;
1349     case MT_OPERAND_XMODE :
1350       value = fields->f_xmode;
1351       break;
1352
1353     default :
1354       /* xgettext:c-format */
1355       fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
1356                        opindex);
1357       abort ();
1358   }
1359
1360   return value;
1361 }
1362
1363 void mt_cgen_set_int_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
1364 void mt_cgen_set_vma_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
1365
1366 /* Stuffing values in cgen_fields is handled by a collection of functions.
1367    They are distinguished by the type of the VALUE argument they accept.
1368    TODO: floating point, inlining support, remove cases where argument type
1369    not appropriate.  */
1370
1371 void
1372 mt_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1373                              int opindex,
1374                              CGEN_FIELDS * fields,
1375                              int value)
1376 {
1377   switch (opindex)
1378     {
1379     case MT_OPERAND_A23 :
1380       fields->f_a23 = value;
1381       break;
1382     case MT_OPERAND_BALL :
1383       fields->f_ball = value;
1384       break;
1385     case MT_OPERAND_BALL2 :
1386       fields->f_ball2 = value;
1387       break;
1388     case MT_OPERAND_BANKADDR :
1389       fields->f_bankaddr = value;
1390       break;
1391     case MT_OPERAND_BRC :
1392       fields->f_brc = value;
1393       break;
1394     case MT_OPERAND_BRC2 :
1395       fields->f_brc2 = value;
1396       break;
1397     case MT_OPERAND_CB1INCR :
1398       fields->f_cb1incr = value;
1399       break;
1400     case MT_OPERAND_CB1SEL :
1401       fields->f_cb1sel = value;
1402       break;
1403     case MT_OPERAND_CB2INCR :
1404       fields->f_cb2incr = value;
1405       break;
1406     case MT_OPERAND_CB2SEL :
1407       fields->f_cb2sel = value;
1408       break;
1409     case MT_OPERAND_CBRB :
1410       fields->f_cbrb = value;
1411       break;
1412     case MT_OPERAND_CBS :
1413       fields->f_cbs = value;
1414       break;
1415     case MT_OPERAND_CBX :
1416       fields->f_cbx = value;
1417       break;
1418     case MT_OPERAND_CCB :
1419       fields->f_ccb = value;
1420       break;
1421     case MT_OPERAND_CDB :
1422       fields->f_cdb = value;
1423       break;
1424     case MT_OPERAND_CELL :
1425       fields->f_cell = value;
1426       break;
1427     case MT_OPERAND_COLNUM :
1428       fields->f_colnum = value;
1429       break;
1430     case MT_OPERAND_CONTNUM :
1431       fields->f_contnum = value;
1432       break;
1433     case MT_OPERAND_CR :
1434       fields->f_cr = value;
1435       break;
1436     case MT_OPERAND_CTXDISP :
1437       fields->f_ctxdisp = value;
1438       break;
1439     case MT_OPERAND_DUP :
1440       fields->f_dup = value;
1441       break;
1442     case MT_OPERAND_FBDISP :
1443       fields->f_fbdisp = value;
1444       break;
1445     case MT_OPERAND_FBINCR :
1446       fields->f_fbincr = value;
1447       break;
1448     case MT_OPERAND_FRDR :
1449       fields->f_dr = value;
1450       break;
1451     case MT_OPERAND_FRDRRR :
1452       fields->f_drrr = value;
1453       break;
1454     case MT_OPERAND_FRSR1 :
1455       fields->f_sr1 = value;
1456       break;
1457     case MT_OPERAND_FRSR2 :
1458       fields->f_sr2 = value;
1459       break;
1460     case MT_OPERAND_ID :
1461       fields->f_id = value;
1462       break;
1463     case MT_OPERAND_IMM16 :
1464       fields->f_imm16s = value;
1465       break;
1466     case MT_OPERAND_IMM16L :
1467       fields->f_imm16l = value;
1468       break;
1469     case MT_OPERAND_IMM16O :
1470       fields->f_imm16s = value;
1471       break;
1472     case MT_OPERAND_IMM16Z :
1473       fields->f_imm16u = value;
1474       break;
1475     case MT_OPERAND_INCAMT :
1476       fields->f_incamt = value;
1477       break;
1478     case MT_OPERAND_INCR :
1479       fields->f_incr = value;
1480       break;
1481     case MT_OPERAND_LENGTH :
1482       fields->f_length = value;
1483       break;
1484     case MT_OPERAND_LOOPSIZE :
1485       fields->f_loopo = value;
1486       break;
1487     case MT_OPERAND_MASK :
1488       fields->f_mask = value;
1489       break;
1490     case MT_OPERAND_MASK1 :
1491       fields->f_mask1 = value;
1492       break;
1493     case MT_OPERAND_MODE :
1494       fields->f_mode = value;
1495       break;
1496     case MT_OPERAND_PERM :
1497       fields->f_perm = value;
1498       break;
1499     case MT_OPERAND_RBBC :
1500       fields->f_rbbc = value;
1501       break;
1502     case MT_OPERAND_RC :
1503       fields->f_rc = value;
1504       break;
1505     case MT_OPERAND_RC1 :
1506       fields->f_rc1 = value;
1507       break;
1508     case MT_OPERAND_RC2 :
1509       fields->f_rc2 = value;
1510       break;
1511     case MT_OPERAND_RC3 :
1512       fields->f_rc3 = value;
1513       break;
1514     case MT_OPERAND_RCNUM :
1515       fields->f_rcnum = value;
1516       break;
1517     case MT_OPERAND_RDA :
1518       fields->f_rda = value;
1519       break;
1520     case MT_OPERAND_ROWNUM :
1521       fields->f_rownum = value;
1522       break;
1523     case MT_OPERAND_ROWNUM1 :
1524       fields->f_rownum1 = value;
1525       break;
1526     case MT_OPERAND_ROWNUM2 :
1527       fields->f_rownum2 = value;
1528       break;
1529     case MT_OPERAND_SIZE :
1530       fields->f_size = value;
1531       break;
1532     case MT_OPERAND_TYPE :
1533       fields->f_type = value;
1534       break;
1535     case MT_OPERAND_WR :
1536       fields->f_wr = value;
1537       break;
1538     case MT_OPERAND_XMODE :
1539       fields->f_xmode = value;
1540       break;
1541
1542     default :
1543       /* xgettext:c-format */
1544       fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
1545                        opindex);
1546       abort ();
1547   }
1548 }
1549
1550 void
1551 mt_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1552                              int opindex,
1553                              CGEN_FIELDS * fields,
1554                              bfd_vma value)
1555 {
1556   switch (opindex)
1557     {
1558     case MT_OPERAND_A23 :
1559       fields->f_a23 = value;
1560       break;
1561     case MT_OPERAND_BALL :
1562       fields->f_ball = value;
1563       break;
1564     case MT_OPERAND_BALL2 :
1565       fields->f_ball2 = value;
1566       break;
1567     case MT_OPERAND_BANKADDR :
1568       fields->f_bankaddr = value;
1569       break;
1570     case MT_OPERAND_BRC :
1571       fields->f_brc = value;
1572       break;
1573     case MT_OPERAND_BRC2 :
1574       fields->f_brc2 = value;
1575       break;
1576     case MT_OPERAND_CB1INCR :
1577       fields->f_cb1incr = value;
1578       break;
1579     case MT_OPERAND_CB1SEL :
1580       fields->f_cb1sel = value;
1581       break;
1582     case MT_OPERAND_CB2INCR :
1583       fields->f_cb2incr = value;
1584       break;
1585     case MT_OPERAND_CB2SEL :
1586       fields->f_cb2sel = value;
1587       break;
1588     case MT_OPERAND_CBRB :
1589       fields->f_cbrb = value;
1590       break;
1591     case MT_OPERAND_CBS :
1592       fields->f_cbs = value;
1593       break;
1594     case MT_OPERAND_CBX :
1595       fields->f_cbx = value;
1596       break;
1597     case MT_OPERAND_CCB :
1598       fields->f_ccb = value;
1599       break;
1600     case MT_OPERAND_CDB :
1601       fields->f_cdb = value;
1602       break;
1603     case MT_OPERAND_CELL :
1604       fields->f_cell = value;
1605       break;
1606     case MT_OPERAND_COLNUM :
1607       fields->f_colnum = value;
1608       break;
1609     case MT_OPERAND_CONTNUM :
1610       fields->f_contnum = value;
1611       break;
1612     case MT_OPERAND_CR :
1613       fields->f_cr = value;
1614       break;
1615     case MT_OPERAND_CTXDISP :
1616       fields->f_ctxdisp = value;
1617       break;
1618     case MT_OPERAND_DUP :
1619       fields->f_dup = value;
1620       break;
1621     case MT_OPERAND_FBDISP :
1622       fields->f_fbdisp = value;
1623       break;
1624     case MT_OPERAND_FBINCR :
1625       fields->f_fbincr = value;
1626       break;
1627     case MT_OPERAND_FRDR :
1628       fields->f_dr = value;
1629       break;
1630     case MT_OPERAND_FRDRRR :
1631       fields->f_drrr = value;
1632       break;
1633     case MT_OPERAND_FRSR1 :
1634       fields->f_sr1 = value;
1635       break;
1636     case MT_OPERAND_FRSR2 :
1637       fields->f_sr2 = value;
1638       break;
1639     case MT_OPERAND_ID :
1640       fields->f_id = value;
1641       break;
1642     case MT_OPERAND_IMM16 :
1643       fields->f_imm16s = value;
1644       break;
1645     case MT_OPERAND_IMM16L :
1646       fields->f_imm16l = value;
1647       break;
1648     case MT_OPERAND_IMM16O :
1649       fields->f_imm16s = value;
1650       break;
1651     case MT_OPERAND_IMM16Z :
1652       fields->f_imm16u = value;
1653       break;
1654     case MT_OPERAND_INCAMT :
1655       fields->f_incamt = value;
1656       break;
1657     case MT_OPERAND_INCR :
1658       fields->f_incr = value;
1659       break;
1660     case MT_OPERAND_LENGTH :
1661       fields->f_length = value;
1662       break;
1663     case MT_OPERAND_LOOPSIZE :
1664       fields->f_loopo = value;
1665       break;
1666     case MT_OPERAND_MASK :
1667       fields->f_mask = value;
1668       break;
1669     case MT_OPERAND_MASK1 :
1670       fields->f_mask1 = value;
1671       break;
1672     case MT_OPERAND_MODE :
1673       fields->f_mode = value;
1674       break;
1675     case MT_OPERAND_PERM :
1676       fields->f_perm = value;
1677       break;
1678     case MT_OPERAND_RBBC :
1679       fields->f_rbbc = value;
1680       break;
1681     case MT_OPERAND_RC :
1682       fields->f_rc = value;
1683       break;
1684     case MT_OPERAND_RC1 :
1685       fields->f_rc1 = value;
1686       break;
1687     case MT_OPERAND_RC2 :
1688       fields->f_rc2 = value;
1689       break;
1690     case MT_OPERAND_RC3 :
1691       fields->f_rc3 = value;
1692       break;
1693     case MT_OPERAND_RCNUM :
1694       fields->f_rcnum = value;
1695       break;
1696     case MT_OPERAND_RDA :
1697       fields->f_rda = value;
1698       break;
1699     case MT_OPERAND_ROWNUM :
1700       fields->f_rownum = value;
1701       break;
1702     case MT_OPERAND_ROWNUM1 :
1703       fields->f_rownum1 = value;
1704       break;
1705     case MT_OPERAND_ROWNUM2 :
1706       fields->f_rownum2 = value;
1707       break;
1708     case MT_OPERAND_SIZE :
1709       fields->f_size = value;
1710       break;
1711     case MT_OPERAND_TYPE :
1712       fields->f_type = value;
1713       break;
1714     case MT_OPERAND_WR :
1715       fields->f_wr = value;
1716       break;
1717     case MT_OPERAND_XMODE :
1718       fields->f_xmode = value;
1719       break;
1720
1721     default :
1722       /* xgettext:c-format */
1723       fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
1724                        opindex);
1725       abort ();
1726   }
1727 }
1728
1729 /* Function to call before using the instruction builder tables.  */
1730
1731 void
1732 mt_cgen_init_ibld_table (CGEN_CPU_DESC cd)
1733 {
1734   cd->insert_handlers = & mt_cgen_insert_handlers[0];
1735   cd->extract_handlers = & mt_cgen_extract_handlers[0];
1736
1737   cd->insert_operand = mt_cgen_insert_operand;
1738   cd->extract_operand = mt_cgen_extract_operand;
1739
1740   cd->get_int_operand = mt_cgen_get_int_operand;
1741   cd->set_int_operand = mt_cgen_set_int_operand;
1742   cd->get_vma_operand = mt_cgen_get_vma_operand;
1743   cd->set_vma_operand = mt_cgen_set_vma_operand;
1744 }