Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/opcodes/iq2000-ibld.c
Line
Count
Source (jump to first uncovered line)
1
/* DO NOT EDIT!  -*- buffer-read-only: t -*- vi:set ro:  */
2
/* Instruction building/extraction support for iq2000. -*- 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-2025 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 "iq2000-desc.h"
35
#include "iq2000-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
0
#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

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, cd->endian);
92
93
  /* Written this way to avoid undefined behaviour.  */
94
  mask = (1UL << (length - 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, cd->endian);
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
0
{
133
0
  static char errbuf[100];
134
0
  unsigned long mask;
135
136
  /* If LENGTH is zero, this operand doesn't contribute to the value.  */
137
0
  if (length == 0)
138
0
    return NULL;
139
140
  /* Written this way to avoid undefined behaviour.  */
141
0
  mask = (1UL << (length - 1) << 1) - 1;
142
143
0
  if (word_length > 8 * sizeof (CGEN_INSN_INT))
144
0
    abort ();
145
146
  /* For architectures with insns smaller than the base-insn-bitsize,
147
     word_length may be too big.  */
148
0
  if (cd->min_insn_bitsize < cd->base_insn_bitsize)
149
0
    {
150
0
      if (word_offset == 0
151
0
    && word_length > total_length)
152
0
  word_length = total_length;
153
0
    }
154
155
  /* Ensure VALUE will fit.  */
156
0
  if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
157
0
    {
158
0
      long minval = - (1UL << (length - 1));
159
0
      unsigned long maxval = mask;
160
161
0
      if ((value > 0 && (unsigned long) value > maxval)
162
0
    || value < minval)
163
0
  {
164
    /* xgettext:c-format */
165
0
    sprintf (errbuf,
166
0
       _("operand out of range (%ld not between %ld and %lu)"),
167
0
       value, minval, maxval);
168
0
    return errbuf;
169
0
  }
170
0
    }
171
0
  else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
172
0
    {
173
0
      unsigned long maxval = mask;
174
0
      unsigned long val = (unsigned long) value;
175
176
      /* For hosts with a word size > 32 check to see if value has been sign
177
   extended beyond 32 bits.  If so then ignore these higher sign bits
178
   as the user is attempting to store a 32-bit signed value into an
179
   unsigned 32-bit field which is allowed.  */
180
0
      if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
181
0
  val &= 0xFFFFFFFF;
182
183
0
      if (val > maxval)
184
0
  {
185
    /* xgettext:c-format */
186
0
    sprintf (errbuf,
187
0
       _("operand out of range (0x%lx not between 0 and 0x%lx)"),
188
0
       val, maxval);
189
0
    return errbuf;
190
0
  }
191
0
    }
192
0
  else
193
0
    {
194
0
      if (! cgen_signed_overflow_ok_p (cd))
195
0
  {
196
0
    long minval = - (1UL << (length - 1));
197
0
    long maxval =   (1UL << (length - 1)) - 1;
198
199
0
    if (value < minval || value > maxval)
200
0
      {
201
0
        sprintf
202
    /* xgettext:c-format */
203
0
    (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
204
0
     value, minval, maxval);
205
0
        return errbuf;
206
0
      }
207
0
  }
208
0
    }
209
210
0
#if CGEN_INT_INSN_P
211
212
0
  {
213
0
    int shift_within_word, shift_to_word, shift;
214
215
    /* How to shift the value to BIT0 of the word.  */
216
0
    shift_to_word = total_length - (word_offset + word_length);
217
218
    /* How to shift the value to the field within the word.  */
219
0
    if (CGEN_INSN_LSB0_P)
220
0
      shift_within_word = start + 1 - length;
221
0
    else
222
0
      shift_within_word = word_length - start - length;
223
224
    /* The total SHIFT, then mask in the value.  */
225
0
    shift = shift_to_word + shift_within_word;
226
0
    *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
227
0
  }
228
229
#else /* ! CGEN_INT_INSN_P */
230
231
  {
232
    unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
233
234
    insert_1 (cd, value, start, length, word_length, bufp);
235
  }
236
237
#endif /* ! CGEN_INT_INSN_P */
238
239
0
  return NULL;
240
0
}
241
242
/* Default insn builder (insert handler).
243
   The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
244
   that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
245
   recorded in host byte order, otherwise BUFFER is an array of bytes
246
   and the value is recorded in target byte order).
247
   The result is an error message or NULL if success.  */
248
249
static const char *
250
insert_insn_normal (CGEN_CPU_DESC cd,
251
        const CGEN_INSN * insn,
252
        CGEN_FIELDS * fields,
253
        CGEN_INSN_BYTES_PTR buffer,
254
        bfd_vma pc)
255
0
{
256
0
  const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
257
0
  unsigned long value;
258
0
  const CGEN_SYNTAX_CHAR_TYPE * syn;
259
260
0
  CGEN_INIT_INSERT (cd);
261
0
  value = CGEN_INSN_BASE_VALUE (insn);
262
263
  /* If we're recording insns as numbers (rather than a string of bytes),
264
     target byte order handling is deferred until later.  */
265
266
0
#if CGEN_INT_INSN_P
267
268
0
  put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
269
0
          CGEN_FIELDS_BITSIZE (fields), value);
270
271
#else
272
273
  cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
274
                                        (unsigned) CGEN_FIELDS_BITSIZE (fields)),
275
           value, cd->insn_endian);
276
277
#endif /* ! CGEN_INT_INSN_P */
278
279
  /* ??? It would be better to scan the format's fields.
280
     Still need to be able to insert a value based on the operand though;
281
     e.g. storing a branch displacement that got resolved later.
282
     Needs more thought first.  */
283
284
0
  for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
285
0
    {
286
0
      const char *errmsg;
287
288
0
      if (CGEN_SYNTAX_CHAR_P (* syn))
289
0
  continue;
290
291
0
      errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
292
0
               fields, buffer, pc);
293
0
      if (errmsg)
294
0
  return errmsg;
295
0
    }
296
297
0
  return NULL;
298
0
}
299
300
#if CGEN_INT_INSN_P
301
/* Cover function to store an insn value into an integral insn.  Must go here
302
   because it needs <prefix>-desc.h for CGEN_INT_INSN_P.  */
303
304
static void
305
put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
306
        CGEN_INSN_BYTES_PTR buf,
307
        int length,
308
        int insn_length,
309
        CGEN_INSN_INT value)
310
0
{
311
  /* For architectures with insns smaller than the base-insn-bitsize,
312
     length may be too big.  */
313
0
  if (length > insn_length)
314
0
    *buf = value;
315
0
  else
316
0
    {
317
0
      int shift = insn_length - length;
318
      /* Written this way to avoid undefined behaviour.  */
319
0
      CGEN_INSN_INT mask = length == 0 ? 0 : (1UL << (length - 1) << 1) - 1;
320
321
0
      *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
322
0
    }
323
0
}
324
#endif
325

326
/* Operand extraction.  */
327
328
#if ! CGEN_INT_INSN_P
329
330
/* Subroutine of extract_normal.
331
   Ensure sufficient bytes are cached in EX_INFO.
332
   OFFSET is the offset in bytes from the start of the insn of the value.
333
   BYTES is the length of the needed value.
334
   Returns 1 for success, 0 for failure.  */
335
336
static CGEN_INLINE int
337
fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
338
      CGEN_EXTRACT_INFO *ex_info,
339
      int offset,
340
      int bytes,
341
      bfd_vma pc)
342
{
343
  /* It's doubtful that the middle part has already been fetched so
344
     we don't optimize that case.  kiss.  */
345
  unsigned int mask;
346
  disassemble_info *info = (disassemble_info *) ex_info->dis_info;
347
348
  /* First do a quick check.  */
349
  mask = (1 << bytes) - 1;
350
  if (((ex_info->valid >> offset) & mask) == mask)
351
    return 1;
352
353
  /* Search for the first byte we need to read.  */
354
  for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
355
    if (! (mask & ex_info->valid))
356
      break;
357
358
  if (bytes)
359
    {
360
      int status;
361
362
      pc += offset;
363
      status = (*info->read_memory_func)
364
  (pc, ex_info->insn_bytes + offset, bytes, info);
365
366
      if (status != 0)
367
  {
368
    (*info->memory_error_func) (status, pc, info);
369
    return 0;
370
  }
371
372
      ex_info->valid |= ((1 << bytes) - 1) << offset;
373
    }
374
375
  return 1;
376
}
377
378
/* Subroutine of extract_normal.  */
379
380
static CGEN_INLINE long
381
extract_1 (CGEN_CPU_DESC cd,
382
     CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
383
     int start,
384
     int length,
385
     int word_length,
386
     unsigned char *bufp,
387
     bfd_vma pc ATTRIBUTE_UNUSED)
388
{
389
  unsigned long x;
390
  int shift;
391
392
  x = cgen_get_insn_value (cd, bufp, word_length, cd->endian);
393
394
  if (CGEN_INSN_LSB0_P)
395
    shift = (start + 1) - length;
396
  else
397
    shift = (word_length - (start + length));
398
  return x >> shift;
399
}
400
401
#endif /* ! CGEN_INT_INSN_P */
402
403
/* Default extraction routine.
404
405
   INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
406
   or sometimes less for cases like the m32r where the base insn size is 32
407
   but some insns are 16 bits.
408
   ATTRS is a mask of the boolean attributes.  We only need `SIGNED',
409
   but for generality we take a bitmask of all of them.
410
   WORD_OFFSET is the offset in bits from the start of the insn of the value.
411
   WORD_LENGTH is the length of the word in bits in which the value resides.
412
   START is the starting bit number in the word, architecture origin.
413
   LENGTH is the length of VALUE in bits.
414
   TOTAL_LENGTH is the total length of the insn in bits.
415
416
   Returns 1 for success, 0 for failure.  */
417
418
/* ??? The return code isn't properly used.  wip.  */
419
420
/* ??? This doesn't handle bfd_vma's.  Create another function when
421
   necessary.  */
422
423
static int
424
extract_normal (CGEN_CPU_DESC cd,
425
#if ! CGEN_INT_INSN_P
426
    CGEN_EXTRACT_INFO *ex_info,
427
#else
428
    CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
429
#endif
430
    CGEN_INSN_INT insn_value,
431
    unsigned int attrs,
432
    unsigned int word_offset,
433
    unsigned int start,
434
    unsigned int length,
435
    unsigned int word_length,
436
    unsigned int total_length,
437
#if ! CGEN_INT_INSN_P
438
    bfd_vma pc,
439
#else
440
    bfd_vma pc ATTRIBUTE_UNUSED,
441
#endif
442
    long *valuep)
443
43.0k
{
444
43.0k
  long value, mask;
445
446
  /* If LENGTH is zero, this operand doesn't contribute to the value
447
     so give it a standard value of zero.  */
448
43.0k
  if (length == 0)
449
0
    {
450
0
      *valuep = 0;
451
0
      return 1;
452
0
    }
453
454
43.0k
  if (word_length > 8 * sizeof (CGEN_INSN_INT))
455
0
    abort ();
456
457
  /* For architectures with insns smaller than the insn-base-bitsize,
458
     word_length may be too big.  */
459
43.0k
  if (cd->min_insn_bitsize < cd->base_insn_bitsize)
460
0
    {
461
0
      if (word_offset + word_length > total_length)
462
0
  word_length = total_length - word_offset;
463
0
    }
464
465
  /* Does the value reside in INSN_VALUE, and at the right alignment?  */
466
467
43.0k
  if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
468
43.0k
    {
469
43.0k
      if (CGEN_INSN_LSB0_P)
470
43.0k
  value = insn_value >> ((word_offset + start + 1) - length);
471
0
      else
472
0
  value = insn_value >> (total_length - ( word_offset + start + length));
473
43.0k
    }
474
475
#if ! CGEN_INT_INSN_P
476
477
  else
478
    {
479
      unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
480
481
      if (word_length > 8 * sizeof (CGEN_INSN_INT))
482
  abort ();
483
484
      if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
485
  {
486
    *valuep = 0;
487
    return 0;
488
  }
489
490
      value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
491
    }
492
493
#endif /* ! CGEN_INT_INSN_P */
494
495
  /* Written this way to avoid undefined behaviour.  */
496
43.0k
  mask = (1UL << (length - 1) << 1) - 1;
497
498
43.0k
  value &= mask;
499
  /* sign extend? */
500
43.0k
  if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
501
43.0k
      && (value & (1UL << (length - 1))))
502
1.15k
    value |= ~mask;
503
504
43.0k
  *valuep = value;
505
506
43.0k
  return 1;
507
43.0k
}
508
509
/* Default insn extractor.
510
511
   INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
512
   The extracted fields are stored in FIELDS.
513
   EX_INFO is used to handle reading variable length insns.
514
   Return the length of the insn in bits, or 0 if no match,
515
   or -1 if an error occurs fetching data (memory_error_func will have
516
   been called).  */
517
518
static int
519
extract_insn_normal (CGEN_CPU_DESC cd,
520
         const CGEN_INSN *insn,
521
         CGEN_EXTRACT_INFO *ex_info,
522
         CGEN_INSN_INT insn_value,
523
         CGEN_FIELDS *fields,
524
         bfd_vma pc)
525
16.8k
{
526
16.8k
  const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
527
16.8k
  const CGEN_SYNTAX_CHAR_TYPE *syn;
528
529
16.8k
  CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
530
531
16.8k
  CGEN_INIT_EXTRACT (cd);
532
533
122k
  for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
534
105k
    {
535
105k
      int length;
536
537
105k
      if (CGEN_SYNTAX_CHAR_P (*syn))
538
62.8k
  continue;
539
540
43.0k
      length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
541
43.0k
          ex_info, insn_value, fields, pc);
542
43.0k
      if (length <= 0)
543
0
  return length;
544
43.0k
    }
545
546
  /* We recognized and successfully extracted this insn.  */
547
16.8k
  return CGEN_INSN_BITSIZE (insn);
548
16.8k
}
549

550
/* Machine generated code added here.  */
551
552
const char * iq2000_cgen_insert_operand
553
  (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
554
555
/* Main entry point for operand insertion.
556
557
   This function is basically just a big switch statement.  Earlier versions
558
   used tables to look up the function to use, but
559
   - if the table contains both assembler and disassembler functions then
560
     the disassembler contains much of the assembler and vice-versa,
561
   - there's a lot of inlining possibilities as things grow,
562
   - using a switch statement avoids the function call overhead.
563
564
   This function could be moved into `parse_insn_normal', but keeping it
565
   separate makes clear the interface between `parse_insn_normal' and each of
566
   the handlers.  It's also needed by GAS to insert operands that couldn't be
567
   resolved during parsing.  */
568
569
const char *
570
iq2000_cgen_insert_operand (CGEN_CPU_DESC cd,
571
           int opindex,
572
           CGEN_FIELDS * fields,
573
           CGEN_INSN_BYTES_PTR buffer,
574
           bfd_vma pc ATTRIBUTE_UNUSED)
575
0
{
576
0
  const char * errmsg = NULL;
577
0
  unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
578
579
0
  switch (opindex)
580
0
    {
581
0
    case IQ2000_OPERAND__INDEX :
582
0
      errmsg = insert_normal (cd, fields->f_index, 0, 0, 8, 9, 32, total_length, buffer);
583
0
      break;
584
0
    case IQ2000_OPERAND_BASE :
585
0
      errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
586
0
      break;
587
0
    case IQ2000_OPERAND_BASEOFF :
588
0
      errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
589
0
      break;
590
0
    case IQ2000_OPERAND_BITNUM :
591
0
      errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
592
0
      break;
593
0
    case IQ2000_OPERAND_BYTECOUNT :
594
0
      errmsg = insert_normal (cd, fields->f_bytecount, 0, 0, 7, 8, 32, total_length, buffer);
595
0
      break;
596
0
    case IQ2000_OPERAND_CAM_Y :
597
0
      errmsg = insert_normal (cd, fields->f_cam_y, 0, 0, 2, 3, 32, total_length, buffer);
598
0
      break;
599
0
    case IQ2000_OPERAND_CAM_Z :
600
0
      errmsg = insert_normal (cd, fields->f_cam_z, 0, 0, 5, 3, 32, total_length, buffer);
601
0
      break;
602
0
    case IQ2000_OPERAND_CM_3FUNC :
603
0
      errmsg = insert_normal (cd, fields->f_cm_3func, 0, 0, 5, 3, 32, total_length, buffer);
604
0
      break;
605
0
    case IQ2000_OPERAND_CM_3Z :
606
0
      errmsg = insert_normal (cd, fields->f_cm_3z, 0, 0, 1, 2, 32, total_length, buffer);
607
0
      break;
608
0
    case IQ2000_OPERAND_CM_4FUNC :
609
0
      errmsg = insert_normal (cd, fields->f_cm_4func, 0, 0, 5, 4, 32, total_length, buffer);
610
0
      break;
611
0
    case IQ2000_OPERAND_CM_4Z :
612
0
      errmsg = insert_normal (cd, fields->f_cm_4z, 0, 0, 2, 3, 32, total_length, buffer);
613
0
      break;
614
0
    case IQ2000_OPERAND_COUNT :
615
0
      errmsg = insert_normal (cd, fields->f_count, 0, 0, 15, 7, 32, total_length, buffer);
616
0
      break;
617
0
    case IQ2000_OPERAND_EXECODE :
618
0
      errmsg = insert_normal (cd, fields->f_excode, 0, 0, 25, 20, 32, total_length, buffer);
619
0
      break;
620
0
    case IQ2000_OPERAND_HI16 :
621
0
      errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
622
0
      break;
623
0
    case IQ2000_OPERAND_IMM :
624
0
      errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
625
0
      break;
626
0
    case IQ2000_OPERAND_JMPTARG :
627
0
      {
628
0
        long value = fields->f_jtarg;
629
0
        value = ((USI) (((value) & (262143))) >> (2));
630
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 16, 32, total_length, buffer);
631
0
      }
632
0
      break;
633
0
    case IQ2000_OPERAND_JMPTARGQ10 :
634
0
      {
635
0
        long value = fields->f_jtargq10;
636
0
        value = ((USI) (((value) & (8388607))) >> (2));
637
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, buffer);
638
0
      }
639
0
      break;
640
0
    case IQ2000_OPERAND_LO16 :
641
0
      errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
642
0
      break;
643
0
    case IQ2000_OPERAND_MASK :
644
0
      errmsg = insert_normal (cd, fields->f_mask, 0, 0, 9, 4, 32, total_length, buffer);
645
0
      break;
646
0
    case IQ2000_OPERAND_MASKL :
647
0
      errmsg = insert_normal (cd, fields->f_maskl, 0, 0, 4, 5, 32, total_length, buffer);
648
0
      break;
649
0
    case IQ2000_OPERAND_MASKQ10 :
650
0
      errmsg = insert_normal (cd, fields->f_maskq10, 0, 0, 10, 5, 32, total_length, buffer);
651
0
      break;
652
0
    case IQ2000_OPERAND_MASKR :
653
0
      errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
654
0
      break;
655
0
    case IQ2000_OPERAND_MLO16 :
656
0
      errmsg = insert_normal (cd, fields->f_imm, 0, 0, 15, 16, 32, total_length, buffer);
657
0
      break;
658
0
    case IQ2000_OPERAND_OFFSET :
659
0
      {
660
0
        long value = fields->f_offset;
661
0
        value = ((SI) (((value) - (pc))) >> (2));
662
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 16, 32, total_length, buffer);
663
0
      }
664
0
      break;
665
0
    case IQ2000_OPERAND_RD :
666
0
      errmsg = insert_normal (cd, fields->f_rd, 0, 0, 15, 5, 32, total_length, buffer);
667
0
      break;
668
0
    case IQ2000_OPERAND_RD_RS :
669
0
      {
670
0
{
671
0
  FLD (f_rd) = FLD (f_rd_rs);
672
0
  FLD (f_rs) = FLD (f_rd_rs);
673
0
}
674
0
        errmsg = insert_normal (cd, fields->f_rd, 0, 0, 15, 5, 32, total_length, buffer);
675
0
        if (errmsg)
676
0
          break;
677
0
        errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
678
0
        if (errmsg)
679
0
          break;
680
0
      }
681
0
      break;
682
0
    case IQ2000_OPERAND_RD_RT :
683
0
      {
684
0
{
685
0
  FLD (f_rd) = FLD (f_rd_rt);
686
0
  FLD (f_rt) = FLD (f_rd_rt);
687
0
}
688
0
        errmsg = insert_normal (cd, fields->f_rd, 0, 0, 15, 5, 32, total_length, buffer);
689
0
        if (errmsg)
690
0
          break;
691
0
        errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
692
0
        if (errmsg)
693
0
          break;
694
0
      }
695
0
      break;
696
0
    case IQ2000_OPERAND_RS :
697
0
      errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
698
0
      break;
699
0
    case IQ2000_OPERAND_RT :
700
0
      errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
701
0
      break;
702
0
    case IQ2000_OPERAND_RT_RS :
703
0
      {
704
0
{
705
0
  FLD (f_rt) = FLD (f_rt_rs);
706
0
  FLD (f_rs) = FLD (f_rt_rs);
707
0
}
708
0
        errmsg = insert_normal (cd, fields->f_rt, 0, 0, 20, 5, 32, total_length, buffer);
709
0
        if (errmsg)
710
0
          break;
711
0
        errmsg = insert_normal (cd, fields->f_rs, 0, 0, 25, 5, 32, total_length, buffer);
712
0
        if (errmsg)
713
0
          break;
714
0
      }
715
0
      break;
716
0
    case IQ2000_OPERAND_SHAMT :
717
0
      errmsg = insert_normal (cd, fields->f_shamt, 0, 0, 10, 5, 32, total_length, buffer);
718
0
      break;
719
720
0
    default :
721
      /* xgettext:c-format */
722
0
      opcodes_error_handler
723
0
  (_("internal error: unrecognized field %d while building insn"),
724
0
   opindex);
725
0
      abort ();
726
0
  }
727
728
0
  return errmsg;
729
0
}
730
731
int iq2000_cgen_extract_operand
732
  (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
733
734
/* Main entry point for operand extraction.
735
   The result is <= 0 for error, >0 for success.
736
   ??? Actual values aren't well defined right now.
737
738
   This function is basically just a big switch statement.  Earlier versions
739
   used tables to look up the function to use, but
740
   - if the table contains both assembler and disassembler functions then
741
     the disassembler contains much of the assembler and vice-versa,
742
   - there's a lot of inlining possibilities as things grow,
743
   - using a switch statement avoids the function call overhead.
744
745
   This function could be moved into `print_insn_normal', but keeping it
746
   separate makes clear the interface between `print_insn_normal' and each of
747
   the handlers.  */
748
749
int
750
iq2000_cgen_extract_operand (CGEN_CPU_DESC cd,
751
           int opindex,
752
           CGEN_EXTRACT_INFO *ex_info,
753
           CGEN_INSN_INT insn_value,
754
           CGEN_FIELDS * fields,
755
           bfd_vma pc)
756
43.0k
{
757
  /* Assume success (for those operands that are nops).  */
758
43.0k
  int length = 1;
759
43.0k
  unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
760
761
43.0k
  switch (opindex)
762
43.0k
    {
763
133
    case IQ2000_OPERAND__INDEX :
764
133
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 9, 32, total_length, pc, & fields->f_index);
765
133
      break;
766
2.08k
    case IQ2000_OPERAND_BASE :
767
2.08k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
768
2.08k
      break;
769
0
    case IQ2000_OPERAND_BASEOFF :
770
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
771
0
      break;
772
824
    case IQ2000_OPERAND_BITNUM :
773
824
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
774
824
      break;
775
0
    case IQ2000_OPERAND_BYTECOUNT :
776
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 32, total_length, pc, & fields->f_bytecount);
777
0
      break;
778
0
    case IQ2000_OPERAND_CAM_Y :
779
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 2, 3, 32, total_length, pc, & fields->f_cam_y);
780
0
      break;
781
0
    case IQ2000_OPERAND_CAM_Z :
782
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 3, 32, total_length, pc, & fields->f_cam_z);
783
0
      break;
784
0
    case IQ2000_OPERAND_CM_3FUNC :
785
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 3, 32, total_length, pc, & fields->f_cm_3func);
786
0
      break;
787
0
    case IQ2000_OPERAND_CM_3Z :
788
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 1, 2, 32, total_length, pc, & fields->f_cm_3z);
789
0
      break;
790
0
    case IQ2000_OPERAND_CM_4FUNC :
791
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 4, 32, total_length, pc, & fields->f_cm_4func);
792
0
      break;
793
0
    case IQ2000_OPERAND_CM_4Z :
794
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 2, 3, 32, total_length, pc, & fields->f_cm_4z);
795
0
      break;
796
133
    case IQ2000_OPERAND_COUNT :
797
133
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 7, 32, total_length, pc, & fields->f_count);
798
133
      break;
799
0
    case IQ2000_OPERAND_EXECODE :
800
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 20, 32, total_length, pc, & fields->f_excode);
801
0
      break;
802
2.04k
    case IQ2000_OPERAND_HI16 :
803
2.04k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
804
2.04k
      break;
805
1.06k
    case IQ2000_OPERAND_IMM :
806
1.06k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
807
1.06k
      break;
808
72
    case IQ2000_OPERAND_JMPTARG :
809
72
      {
810
72
        long value;
811
72
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 16, 32, total_length, pc, & value);
812
72
        value = ((((pc) & (0xf0000000))) | (((value) << (2))));
813
72
        fields->f_jtarg = value;
814
72
      }
815
72
      break;
816
0
    case IQ2000_OPERAND_JMPTARGQ10 :
817
0
      {
818
0
        long value;
819
0
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, pc, & value);
820
0
        value = ((((pc) & (0xf0000000))) | (((value) << (2))));
821
0
        fields->f_jtargq10 = value;
822
0
      }
823
0
      break;
824
4.30k
    case IQ2000_OPERAND_LO16 :
825
4.30k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
826
4.30k
      break;
827
81
    case IQ2000_OPERAND_MASK :
828
81
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 4, 32, total_length, pc, & fields->f_mask);
829
81
      break;
830
123
    case IQ2000_OPERAND_MASKL :
831
123
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 5, 32, total_length, pc, & fields->f_maskl);
832
123
      break;
833
0
    case IQ2000_OPERAND_MASKQ10 :
834
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 5, 32, total_length, pc, & fields->f_maskq10);
835
0
      break;
836
123
    case IQ2000_OPERAND_MASKR :
837
123
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
838
123
      break;
839
0
    case IQ2000_OPERAND_MLO16 :
840
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm);
841
0
      break;
842
4.85k
    case IQ2000_OPERAND_OFFSET :
843
4.85k
      {
844
4.85k
        long value;
845
4.85k
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 16, 32, total_length, pc, & value);
846
4.85k
        value = ((((value) * (4))) + (((pc) + (4))));
847
4.85k
        fields->f_offset = value;
848
4.85k
      }
849
4.85k
      break;
850
1.84k
    case IQ2000_OPERAND_RD :
851
1.84k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_rd);
852
1.84k
      break;
853
0
    case IQ2000_OPERAND_RD_RS :
854
0
      {
855
0
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_rd);
856
0
        if (length <= 0) break;
857
0
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
858
0
        if (length <= 0) break;
859
0
{
860
0
  FLD (f_rd_rs) = FLD (f_rs);
861
0
}
862
0
      }
863
0
      break;
864
0
    case IQ2000_OPERAND_RD_RT :
865
0
      {
866
0
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_rd);
867
0
        if (length <= 0) break;
868
0
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
869
0
        if (length <= 0) break;
870
0
{
871
0
  FLD (f_rd_rt) = FLD (f_rt);
872
0
}
873
0
      }
874
0
      break;
875
10.9k
    case IQ2000_OPERAND_RS :
876
10.9k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
877
10.9k
      break;
878
12.9k
    case IQ2000_OPERAND_RT :
879
12.9k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
880
12.9k
      break;
881
0
    case IQ2000_OPERAND_RT_RS :
882
0
      {
883
0
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_rt);
884
0
        if (length <= 0) break;
885
0
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_rs);
886
0
        if (length <= 0) break;
887
0
{
888
0
  FLD (f_rd_rs) = FLD (f_rs);
889
0
}
890
0
      }
891
0
      break;
892
1.43k
    case IQ2000_OPERAND_SHAMT :
893
1.43k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 5, 32, total_length, pc, & fields->f_shamt);
894
1.43k
      break;
895
896
0
    default :
897
      /* xgettext:c-format */
898
0
      opcodes_error_handler
899
0
  (_("internal error: unrecognized field %d while decoding insn"),
900
0
   opindex);
901
0
      abort ();
902
43.0k
    }
903
904
43.0k
  return length;
905
43.0k
}
906
907
cgen_insert_fn * const iq2000_cgen_insert_handlers[] =
908
{
909
  insert_insn_normal,
910
};
911
912
cgen_extract_fn * const iq2000_cgen_extract_handlers[] =
913
{
914
  extract_insn_normal,
915
};
916
917
int iq2000_cgen_get_int_operand     (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
918
bfd_vma iq2000_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
919
920
/* Getting values from cgen_fields is handled by a collection of functions.
921
   They are distinguished by the type of the VALUE argument they return.
922
   TODO: floating point, inlining support, remove cases where result type
923
   not appropriate.  */
924
925
int
926
iq2000_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
927
           int opindex,
928
           const CGEN_FIELDS * fields)
929
0
{
930
0
  int value;
931
932
0
  switch (opindex)
933
0
    {
934
0
    case IQ2000_OPERAND__INDEX :
935
0
      value = fields->f_index;
936
0
      break;
937
0
    case IQ2000_OPERAND_BASE :
938
0
      value = fields->f_rs;
939
0
      break;
940
0
    case IQ2000_OPERAND_BASEOFF :
941
0
      value = fields->f_imm;
942
0
      break;
943
0
    case IQ2000_OPERAND_BITNUM :
944
0
      value = fields->f_rt;
945
0
      break;
946
0
    case IQ2000_OPERAND_BYTECOUNT :
947
0
      value = fields->f_bytecount;
948
0
      break;
949
0
    case IQ2000_OPERAND_CAM_Y :
950
0
      value = fields->f_cam_y;
951
0
      break;
952
0
    case IQ2000_OPERAND_CAM_Z :
953
0
      value = fields->f_cam_z;
954
0
      break;
955
0
    case IQ2000_OPERAND_CM_3FUNC :
956
0
      value = fields->f_cm_3func;
957
0
      break;
958
0
    case IQ2000_OPERAND_CM_3Z :
959
0
      value = fields->f_cm_3z;
960
0
      break;
961
0
    case IQ2000_OPERAND_CM_4FUNC :
962
0
      value = fields->f_cm_4func;
963
0
      break;
964
0
    case IQ2000_OPERAND_CM_4Z :
965
0
      value = fields->f_cm_4z;
966
0
      break;
967
0
    case IQ2000_OPERAND_COUNT :
968
0
      value = fields->f_count;
969
0
      break;
970
0
    case IQ2000_OPERAND_EXECODE :
971
0
      value = fields->f_excode;
972
0
      break;
973
0
    case IQ2000_OPERAND_HI16 :
974
0
      value = fields->f_imm;
975
0
      break;
976
0
    case IQ2000_OPERAND_IMM :
977
0
      value = fields->f_imm;
978
0
      break;
979
0
    case IQ2000_OPERAND_JMPTARG :
980
0
      value = fields->f_jtarg;
981
0
      break;
982
0
    case IQ2000_OPERAND_JMPTARGQ10 :
983
0
      value = fields->f_jtargq10;
984
0
      break;
985
0
    case IQ2000_OPERAND_LO16 :
986
0
      value = fields->f_imm;
987
0
      break;
988
0
    case IQ2000_OPERAND_MASK :
989
0
      value = fields->f_mask;
990
0
      break;
991
0
    case IQ2000_OPERAND_MASKL :
992
0
      value = fields->f_maskl;
993
0
      break;
994
0
    case IQ2000_OPERAND_MASKQ10 :
995
0
      value = fields->f_maskq10;
996
0
      break;
997
0
    case IQ2000_OPERAND_MASKR :
998
0
      value = fields->f_rs;
999
0
      break;
1000
0
    case IQ2000_OPERAND_MLO16 :
1001
0
      value = fields->f_imm;
1002
0
      break;
1003
0
    case IQ2000_OPERAND_OFFSET :
1004
0
      value = fields->f_offset;
1005
0
      break;
1006
0
    case IQ2000_OPERAND_RD :
1007
0
      value = fields->f_rd;
1008
0
      break;
1009
0
    case IQ2000_OPERAND_RD_RS :
1010
0
      value = fields->f_rd_rs;
1011
0
      break;
1012
0
    case IQ2000_OPERAND_RD_RT :
1013
0
      value = fields->f_rd_rt;
1014
0
      break;
1015
0
    case IQ2000_OPERAND_RS :
1016
0
      value = fields->f_rs;
1017
0
      break;
1018
0
    case IQ2000_OPERAND_RT :
1019
0
      value = fields->f_rt;
1020
0
      break;
1021
0
    case IQ2000_OPERAND_RT_RS :
1022
0
      value = fields->f_rt_rs;
1023
0
      break;
1024
0
    case IQ2000_OPERAND_SHAMT :
1025
0
      value = fields->f_shamt;
1026
0
      break;
1027
1028
0
    default :
1029
      /* xgettext:c-format */
1030
0
      opcodes_error_handler
1031
0
  (_("internal error: unrecognized field %d while getting int operand"),
1032
0
   opindex);
1033
0
      abort ();
1034
0
  }
1035
1036
0
  return value;
1037
0
}
1038
1039
bfd_vma
1040
iq2000_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1041
           int opindex,
1042
           const CGEN_FIELDS * fields)
1043
0
{
1044
0
  bfd_vma value;
1045
1046
0
  switch (opindex)
1047
0
    {
1048
0
    case IQ2000_OPERAND__INDEX :
1049
0
      value = fields->f_index;
1050
0
      break;
1051
0
    case IQ2000_OPERAND_BASE :
1052
0
      value = fields->f_rs;
1053
0
      break;
1054
0
    case IQ2000_OPERAND_BASEOFF :
1055
0
      value = fields->f_imm;
1056
0
      break;
1057
0
    case IQ2000_OPERAND_BITNUM :
1058
0
      value = fields->f_rt;
1059
0
      break;
1060
0
    case IQ2000_OPERAND_BYTECOUNT :
1061
0
      value = fields->f_bytecount;
1062
0
      break;
1063
0
    case IQ2000_OPERAND_CAM_Y :
1064
0
      value = fields->f_cam_y;
1065
0
      break;
1066
0
    case IQ2000_OPERAND_CAM_Z :
1067
0
      value = fields->f_cam_z;
1068
0
      break;
1069
0
    case IQ2000_OPERAND_CM_3FUNC :
1070
0
      value = fields->f_cm_3func;
1071
0
      break;
1072
0
    case IQ2000_OPERAND_CM_3Z :
1073
0
      value = fields->f_cm_3z;
1074
0
      break;
1075
0
    case IQ2000_OPERAND_CM_4FUNC :
1076
0
      value = fields->f_cm_4func;
1077
0
      break;
1078
0
    case IQ2000_OPERAND_CM_4Z :
1079
0
      value = fields->f_cm_4z;
1080
0
      break;
1081
0
    case IQ2000_OPERAND_COUNT :
1082
0
      value = fields->f_count;
1083
0
      break;
1084
0
    case IQ2000_OPERAND_EXECODE :
1085
0
      value = fields->f_excode;
1086
0
      break;
1087
0
    case IQ2000_OPERAND_HI16 :
1088
0
      value = fields->f_imm;
1089
0
      break;
1090
0
    case IQ2000_OPERAND_IMM :
1091
0
      value = fields->f_imm;
1092
0
      break;
1093
0
    case IQ2000_OPERAND_JMPTARG :
1094
0
      value = fields->f_jtarg;
1095
0
      break;
1096
0
    case IQ2000_OPERAND_JMPTARGQ10 :
1097
0
      value = fields->f_jtargq10;
1098
0
      break;
1099
0
    case IQ2000_OPERAND_LO16 :
1100
0
      value = fields->f_imm;
1101
0
      break;
1102
0
    case IQ2000_OPERAND_MASK :
1103
0
      value = fields->f_mask;
1104
0
      break;
1105
0
    case IQ2000_OPERAND_MASKL :
1106
0
      value = fields->f_maskl;
1107
0
      break;
1108
0
    case IQ2000_OPERAND_MASKQ10 :
1109
0
      value = fields->f_maskq10;
1110
0
      break;
1111
0
    case IQ2000_OPERAND_MASKR :
1112
0
      value = fields->f_rs;
1113
0
      break;
1114
0
    case IQ2000_OPERAND_MLO16 :
1115
0
      value = fields->f_imm;
1116
0
      break;
1117
0
    case IQ2000_OPERAND_OFFSET :
1118
0
      value = fields->f_offset;
1119
0
      break;
1120
0
    case IQ2000_OPERAND_RD :
1121
0
      value = fields->f_rd;
1122
0
      break;
1123
0
    case IQ2000_OPERAND_RD_RS :
1124
0
      value = fields->f_rd_rs;
1125
0
      break;
1126
0
    case IQ2000_OPERAND_RD_RT :
1127
0
      value = fields->f_rd_rt;
1128
0
      break;
1129
0
    case IQ2000_OPERAND_RS :
1130
0
      value = fields->f_rs;
1131
0
      break;
1132
0
    case IQ2000_OPERAND_RT :
1133
0
      value = fields->f_rt;
1134
0
      break;
1135
0
    case IQ2000_OPERAND_RT_RS :
1136
0
      value = fields->f_rt_rs;
1137
0
      break;
1138
0
    case IQ2000_OPERAND_SHAMT :
1139
0
      value = fields->f_shamt;
1140
0
      break;
1141
1142
0
    default :
1143
      /* xgettext:c-format */
1144
0
      opcodes_error_handler
1145
0
  (_("internal error: unrecognized field %d while getting vma operand"),
1146
0
   opindex);
1147
0
      abort ();
1148
0
  }
1149
1150
0
  return value;
1151
0
}
1152
1153
void iq2000_cgen_set_int_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
1154
void iq2000_cgen_set_vma_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
1155
1156
/* Stuffing values in cgen_fields is handled by a collection of functions.
1157
   They are distinguished by the type of the VALUE argument they accept.
1158
   TODO: floating point, inlining support, remove cases where argument type
1159
   not appropriate.  */
1160
1161
void
1162
iq2000_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1163
           int opindex,
1164
           CGEN_FIELDS * fields,
1165
           int value)
1166
0
{
1167
0
  switch (opindex)
1168
0
    {
1169
0
    case IQ2000_OPERAND__INDEX :
1170
0
      fields->f_index = value;
1171
0
      break;
1172
0
    case IQ2000_OPERAND_BASE :
1173
0
      fields->f_rs = value;
1174
0
      break;
1175
0
    case IQ2000_OPERAND_BASEOFF :
1176
0
      fields->f_imm = value;
1177
0
      break;
1178
0
    case IQ2000_OPERAND_BITNUM :
1179
0
      fields->f_rt = value;
1180
0
      break;
1181
0
    case IQ2000_OPERAND_BYTECOUNT :
1182
0
      fields->f_bytecount = value;
1183
0
      break;
1184
0
    case IQ2000_OPERAND_CAM_Y :
1185
0
      fields->f_cam_y = value;
1186
0
      break;
1187
0
    case IQ2000_OPERAND_CAM_Z :
1188
0
      fields->f_cam_z = value;
1189
0
      break;
1190
0
    case IQ2000_OPERAND_CM_3FUNC :
1191
0
      fields->f_cm_3func = value;
1192
0
      break;
1193
0
    case IQ2000_OPERAND_CM_3Z :
1194
0
      fields->f_cm_3z = value;
1195
0
      break;
1196
0
    case IQ2000_OPERAND_CM_4FUNC :
1197
0
      fields->f_cm_4func = value;
1198
0
      break;
1199
0
    case IQ2000_OPERAND_CM_4Z :
1200
0
      fields->f_cm_4z = value;
1201
0
      break;
1202
0
    case IQ2000_OPERAND_COUNT :
1203
0
      fields->f_count = value;
1204
0
      break;
1205
0
    case IQ2000_OPERAND_EXECODE :
1206
0
      fields->f_excode = value;
1207
0
      break;
1208
0
    case IQ2000_OPERAND_HI16 :
1209
0
      fields->f_imm = value;
1210
0
      break;
1211
0
    case IQ2000_OPERAND_IMM :
1212
0
      fields->f_imm = value;
1213
0
      break;
1214
0
    case IQ2000_OPERAND_JMPTARG :
1215
0
      fields->f_jtarg = value;
1216
0
      break;
1217
0
    case IQ2000_OPERAND_JMPTARGQ10 :
1218
0
      fields->f_jtargq10 = value;
1219
0
      break;
1220
0
    case IQ2000_OPERAND_LO16 :
1221
0
      fields->f_imm = value;
1222
0
      break;
1223
0
    case IQ2000_OPERAND_MASK :
1224
0
      fields->f_mask = value;
1225
0
      break;
1226
0
    case IQ2000_OPERAND_MASKL :
1227
0
      fields->f_maskl = value;
1228
0
      break;
1229
0
    case IQ2000_OPERAND_MASKQ10 :
1230
0
      fields->f_maskq10 = value;
1231
0
      break;
1232
0
    case IQ2000_OPERAND_MASKR :
1233
0
      fields->f_rs = value;
1234
0
      break;
1235
0
    case IQ2000_OPERAND_MLO16 :
1236
0
      fields->f_imm = value;
1237
0
      break;
1238
0
    case IQ2000_OPERAND_OFFSET :
1239
0
      fields->f_offset = value;
1240
0
      break;
1241
0
    case IQ2000_OPERAND_RD :
1242
0
      fields->f_rd = value;
1243
0
      break;
1244
0
    case IQ2000_OPERAND_RD_RS :
1245
0
      fields->f_rd_rs = value;
1246
0
      break;
1247
0
    case IQ2000_OPERAND_RD_RT :
1248
0
      fields->f_rd_rt = value;
1249
0
      break;
1250
0
    case IQ2000_OPERAND_RS :
1251
0
      fields->f_rs = value;
1252
0
      break;
1253
0
    case IQ2000_OPERAND_RT :
1254
0
      fields->f_rt = value;
1255
0
      break;
1256
0
    case IQ2000_OPERAND_RT_RS :
1257
0
      fields->f_rt_rs = value;
1258
0
      break;
1259
0
    case IQ2000_OPERAND_SHAMT :
1260
0
      fields->f_shamt = value;
1261
0
      break;
1262
1263
0
    default :
1264
      /* xgettext:c-format */
1265
0
      opcodes_error_handler
1266
0
  (_("internal error: unrecognized field %d while setting int operand"),
1267
0
   opindex);
1268
0
      abort ();
1269
0
  }
1270
0
}
1271
1272
void
1273
iq2000_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1274
           int opindex,
1275
           CGEN_FIELDS * fields,
1276
           bfd_vma value)
1277
0
{
1278
0
  switch (opindex)
1279
0
    {
1280
0
    case IQ2000_OPERAND__INDEX :
1281
0
      fields->f_index = value;
1282
0
      break;
1283
0
    case IQ2000_OPERAND_BASE :
1284
0
      fields->f_rs = value;
1285
0
      break;
1286
0
    case IQ2000_OPERAND_BASEOFF :
1287
0
      fields->f_imm = value;
1288
0
      break;
1289
0
    case IQ2000_OPERAND_BITNUM :
1290
0
      fields->f_rt = value;
1291
0
      break;
1292
0
    case IQ2000_OPERAND_BYTECOUNT :
1293
0
      fields->f_bytecount = value;
1294
0
      break;
1295
0
    case IQ2000_OPERAND_CAM_Y :
1296
0
      fields->f_cam_y = value;
1297
0
      break;
1298
0
    case IQ2000_OPERAND_CAM_Z :
1299
0
      fields->f_cam_z = value;
1300
0
      break;
1301
0
    case IQ2000_OPERAND_CM_3FUNC :
1302
0
      fields->f_cm_3func = value;
1303
0
      break;
1304
0
    case IQ2000_OPERAND_CM_3Z :
1305
0
      fields->f_cm_3z = value;
1306
0
      break;
1307
0
    case IQ2000_OPERAND_CM_4FUNC :
1308
0
      fields->f_cm_4func = value;
1309
0
      break;
1310
0
    case IQ2000_OPERAND_CM_4Z :
1311
0
      fields->f_cm_4z = value;
1312
0
      break;
1313
0
    case IQ2000_OPERAND_COUNT :
1314
0
      fields->f_count = value;
1315
0
      break;
1316
0
    case IQ2000_OPERAND_EXECODE :
1317
0
      fields->f_excode = value;
1318
0
      break;
1319
0
    case IQ2000_OPERAND_HI16 :
1320
0
      fields->f_imm = value;
1321
0
      break;
1322
0
    case IQ2000_OPERAND_IMM :
1323
0
      fields->f_imm = value;
1324
0
      break;
1325
0
    case IQ2000_OPERAND_JMPTARG :
1326
0
      fields->f_jtarg = value;
1327
0
      break;
1328
0
    case IQ2000_OPERAND_JMPTARGQ10 :
1329
0
      fields->f_jtargq10 = value;
1330
0
      break;
1331
0
    case IQ2000_OPERAND_LO16 :
1332
0
      fields->f_imm = value;
1333
0
      break;
1334
0
    case IQ2000_OPERAND_MASK :
1335
0
      fields->f_mask = value;
1336
0
      break;
1337
0
    case IQ2000_OPERAND_MASKL :
1338
0
      fields->f_maskl = value;
1339
0
      break;
1340
0
    case IQ2000_OPERAND_MASKQ10 :
1341
0
      fields->f_maskq10 = value;
1342
0
      break;
1343
0
    case IQ2000_OPERAND_MASKR :
1344
0
      fields->f_rs = value;
1345
0
      break;
1346
0
    case IQ2000_OPERAND_MLO16 :
1347
0
      fields->f_imm = value;
1348
0
      break;
1349
0
    case IQ2000_OPERAND_OFFSET :
1350
0
      fields->f_offset = value;
1351
0
      break;
1352
0
    case IQ2000_OPERAND_RD :
1353
0
      fields->f_rd = value;
1354
0
      break;
1355
0
    case IQ2000_OPERAND_RD_RS :
1356
0
      fields->f_rd_rs = value;
1357
0
      break;
1358
0
    case IQ2000_OPERAND_RD_RT :
1359
0
      fields->f_rd_rt = value;
1360
0
      break;
1361
0
    case IQ2000_OPERAND_RS :
1362
0
      fields->f_rs = value;
1363
0
      break;
1364
0
    case IQ2000_OPERAND_RT :
1365
0
      fields->f_rt = value;
1366
0
      break;
1367
0
    case IQ2000_OPERAND_RT_RS :
1368
0
      fields->f_rt_rs = value;
1369
0
      break;
1370
0
    case IQ2000_OPERAND_SHAMT :
1371
0
      fields->f_shamt = value;
1372
0
      break;
1373
1374
0
    default :
1375
      /* xgettext:c-format */
1376
0
      opcodes_error_handler
1377
0
  (_("internal error: unrecognized field %d while setting vma operand"),
1378
0
   opindex);
1379
0
      abort ();
1380
0
  }
1381
0
}
1382
1383
/* Function to call before using the instruction builder tables.  */
1384
1385
void
1386
iq2000_cgen_init_ibld_table (CGEN_CPU_DESC cd)
1387
4
{
1388
4
  cd->insert_handlers = & iq2000_cgen_insert_handlers[0];
1389
4
  cd->extract_handlers = & iq2000_cgen_extract_handlers[0];
1390
1391
4
  cd->insert_operand = iq2000_cgen_insert_operand;
1392
4
  cd->extract_operand = iq2000_cgen_extract_operand;
1393
1394
4
  cd->get_int_operand = iq2000_cgen_get_int_operand;
1395
4
  cd->set_int_operand = iq2000_cgen_set_int_operand;
1396
4
  cd->get_vma_operand = iq2000_cgen_get_vma_operand;
1397
4
  cd->set_vma_operand = iq2000_cgen_set_vma_operand;
1398
4
}