Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/opcodes/fr30-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 fr30. -*- 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 "fr30-desc.h"
35
#include "fr30-opc.h"
36
#include "cgen/basic-modes.h"
37
#include "opintl.h"
38
#include "safe-ctype.h"
39
40
#undef  min
41
0
#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
1.73k
#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
0
{
88
0
  unsigned long x, mask;
89
0
  int shift;
90
91
0
  x = cgen_get_insn_value (cd, bufp, word_length, cd->endian);
92
93
  /* Written this way to avoid undefined behaviour.  */
94
0
  mask = (1UL << (length - 1) << 1) - 1;
95
0
  if (CGEN_INSN_LSB0_P)
96
0
    shift = (start + 1) - length;
97
0
  else
98
0
    shift = (word_length - (start + length));
99
0
  x = (x & ~(mask << shift)) | ((value & mask) << shift);
100
101
0
  cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x, cd->endian);
102
0
}
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
#if CGEN_INT_INSN_P
211
212
  {
213
    int shift_within_word, shift_to_word, shift;
214
215
    /* How to shift the value to BIT0 of the word.  */
216
    shift_to_word = total_length - (word_offset + word_length);
217
218
    /* How to shift the value to the field within the word.  */
219
    if (CGEN_INSN_LSB0_P)
220
      shift_within_word = start + 1 - length;
221
    else
222
      shift_within_word = word_length - start - length;
223
224
    /* The total SHIFT, then mask in the value.  */
225
    shift = shift_to_word + shift_within_word;
226
    *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
227
  }
228
229
#else /* ! CGEN_INT_INSN_P */
230
231
0
  {
232
0
    unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
233
234
0
    insert_1 (cd, value, start, length, word_length, bufp);
235
0
  }
236
237
0
#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
#if CGEN_INT_INSN_P
267
268
  put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
269
          CGEN_FIELDS_BITSIZE (fields), value);
270
271
#else
272
273
0
  cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
274
0
                                        (unsigned) CGEN_FIELDS_BITSIZE (fields)),
275
0
           value, cd->insn_endian);
276
277
0
#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
{
311
  /* For architectures with insns smaller than the base-insn-bitsize,
312
     length may be too big.  */
313
  if (length > insn_length)
314
    *buf = value;
315
  else
316
    {
317
      int shift = insn_length - length;
318
      /* Written this way to avoid undefined behaviour.  */
319
      CGEN_INSN_INT mask = length == 0 ? 0 : (1UL << (length - 1) << 1) - 1;
320
321
      *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
322
    }
323
}
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
3.04k
{
343
  /* It's doubtful that the middle part has already been fetched so
344
     we don't optimize that case.  kiss.  */
345
3.04k
  unsigned int mask;
346
3.04k
  disassemble_info *info = (disassemble_info *) ex_info->dis_info;
347
348
  /* First do a quick check.  */
349
3.04k
  mask = (1 << bytes) - 1;
350
3.04k
  if (((ex_info->valid >> offset) & mask) == mask)
351
3.04k
    return 1;
352
353
  /* Search for the first byte we need to read.  */
354
0
  for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
355
0
    if (! (mask & ex_info->valid))
356
0
      break;
357
358
0
  if (bytes)
359
0
    {
360
0
      int status;
361
362
0
      pc += offset;
363
0
      status = (*info->read_memory_func)
364
0
  (pc, ex_info->insn_bytes + offset, bytes, info);
365
366
0
      if (status != 0)
367
0
  {
368
0
    (*info->memory_error_func) (status, pc, info);
369
0
    return 0;
370
0
  }
371
372
0
      ex_info->valid |= ((1 << bytes) - 1) << offset;
373
0
    }
374
375
0
  return 1;
376
0
}
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
3.04k
{
389
3.04k
  unsigned long x;
390
3.04k
  int shift;
391
392
3.04k
  x = cgen_get_insn_value (cd, bufp, word_length, cd->endian);
393
394
3.04k
  if (CGEN_INSN_LSB0_P)
395
0
    shift = (start + 1) - length;
396
3.04k
  else
397
3.04k
    shift = (word_length - (start + length));
398
3.04k
  return x >> shift;
399
3.04k
}
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
229k
{
444
229k
  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
229k
  if (length == 0)
449
0
    {
450
0
      *valuep = 0;
451
0
      return 1;
452
0
    }
453
454
229k
  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
229k
  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
229k
  if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
468
226k
    {
469
226k
      if (CGEN_INSN_LSB0_P)
470
0
  value = insn_value >> ((word_offset + start + 1) - length);
471
226k
      else
472
226k
  value = insn_value >> (total_length - ( word_offset + start + length));
473
226k
    }
474
475
3.04k
#if ! CGEN_INT_INSN_P
476
477
3.04k
  else
478
3.04k
    {
479
3.04k
      unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
480
481
3.04k
      if (word_length > 8 * sizeof (CGEN_INSN_INT))
482
0
  abort ();
483
484
3.04k
      if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
485
0
  {
486
0
    *valuep = 0;
487
0
    return 0;
488
0
  }
489
490
3.04k
      value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
491
3.04k
    }
492
493
229k
#endif /* ! CGEN_INT_INSN_P */
494
495
  /* Written this way to avoid undefined behaviour.  */
496
229k
  mask = (1UL << (length - 1) << 1) - 1;
497
498
229k
  value &= mask;
499
  /* sign extend? */
500
229k
  if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
501
229k
      && (value & (1UL << (length - 1))))
502
23.2k
    value |= ~mask;
503
504
229k
  *valuep = value;
505
506
229k
  return 1;
507
229k
}
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
131k
{
526
131k
  const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
527
131k
  const CGEN_SYNTAX_CHAR_TYPE *syn;
528
529
131k
  CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
530
531
131k
  CGEN_INIT_EXTRACT (cd);
532
533
1.15M
  for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
534
1.02M
    {
535
1.02M
      int length;
536
537
1.02M
      if (CGEN_SYNTAX_CHAR_P (*syn))
538
707k
  continue;
539
540
313k
      length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
541
313k
          ex_info, insn_value, fields, pc);
542
313k
      if (length <= 0)
543
0
  return length;
544
313k
    }
545
546
  /* We recognized and successfully extracted this insn.  */
547
131k
  return CGEN_INSN_BITSIZE (insn);
548
131k
}
549

550
/* Machine generated code added here.  */
551
552
const char * fr30_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
fr30_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 FR30_OPERAND_CRI :
582
0
      errmsg = insert_normal (cd, fields->f_CRi, 0, 16, 12, 4, 16, total_length, buffer);
583
0
      break;
584
0
    case FR30_OPERAND_CRJ :
585
0
      errmsg = insert_normal (cd, fields->f_CRj, 0, 16, 8, 4, 16, total_length, buffer);
586
0
      break;
587
0
    case FR30_OPERAND_R13 :
588
0
      break;
589
0
    case FR30_OPERAND_R14 :
590
0
      break;
591
0
    case FR30_OPERAND_R15 :
592
0
      break;
593
0
    case FR30_OPERAND_RI :
594
0
      errmsg = insert_normal (cd, fields->f_Ri, 0, 0, 12, 4, 16, total_length, buffer);
595
0
      break;
596
0
    case FR30_OPERAND_RIC :
597
0
      errmsg = insert_normal (cd, fields->f_Ric, 0, 16, 12, 4, 16, total_length, buffer);
598
0
      break;
599
0
    case FR30_OPERAND_RJ :
600
0
      errmsg = insert_normal (cd, fields->f_Rj, 0, 0, 8, 4, 16, total_length, buffer);
601
0
      break;
602
0
    case FR30_OPERAND_RJC :
603
0
      errmsg = insert_normal (cd, fields->f_Rjc, 0, 16, 8, 4, 16, total_length, buffer);
604
0
      break;
605
0
    case FR30_OPERAND_RS1 :
606
0
      errmsg = insert_normal (cd, fields->f_Rs1, 0, 0, 8, 4, 16, total_length, buffer);
607
0
      break;
608
0
    case FR30_OPERAND_RS2 :
609
0
      errmsg = insert_normal (cd, fields->f_Rs2, 0, 0, 12, 4, 16, total_length, buffer);
610
0
      break;
611
0
    case FR30_OPERAND_CC :
612
0
      errmsg = insert_normal (cd, fields->f_cc, 0, 0, 4, 4, 16, total_length, buffer);
613
0
      break;
614
0
    case FR30_OPERAND_CCC :
615
0
      errmsg = insert_normal (cd, fields->f_ccc, 0, 16, 0, 8, 16, total_length, buffer);
616
0
      break;
617
0
    case FR30_OPERAND_DIR10 :
618
0
      {
619
0
        long value = fields->f_dir10;
620
0
        value = ((USI) (value) >> (2));
621
0
        errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
622
0
      }
623
0
      break;
624
0
    case FR30_OPERAND_DIR8 :
625
0
      errmsg = insert_normal (cd, fields->f_dir8, 0, 0, 8, 8, 16, total_length, buffer);
626
0
      break;
627
0
    case FR30_OPERAND_DIR9 :
628
0
      {
629
0
        long value = fields->f_dir9;
630
0
        value = ((USI) (value) >> (1));
631
0
        errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
632
0
      }
633
0
      break;
634
0
    case FR30_OPERAND_DISP10 :
635
0
      {
636
0
        long value = fields->f_disp10;
637
0
        value = ((SI) (value) >> (2));
638
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
639
0
      }
640
0
      break;
641
0
    case FR30_OPERAND_DISP8 :
642
0
      errmsg = insert_normal (cd, fields->f_disp8, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
643
0
      break;
644
0
    case FR30_OPERAND_DISP9 :
645
0
      {
646
0
        long value = fields->f_disp9;
647
0
        value = ((SI) (value) >> (1));
648
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
649
0
      }
650
0
      break;
651
0
    case FR30_OPERAND_I20 :
652
0
      {
653
0
{
654
0
  FLD (f_i20_4) = ((UINT) (FLD (f_i20)) >> (16));
655
0
  FLD (f_i20_16) = ((FLD (f_i20)) & (65535));
656
0
}
657
0
        errmsg = insert_normal (cd, fields->f_i20_4, 0, 0, 8, 4, 16, total_length, buffer);
658
0
        if (errmsg)
659
0
          break;
660
0
        errmsg = insert_normal (cd, fields->f_i20_16, 0, 16, 0, 16, 16, total_length, buffer);
661
0
        if (errmsg)
662
0
          break;
663
0
      }
664
0
      break;
665
0
    case FR30_OPERAND_I32 :
666
0
      errmsg = insert_normal (cd, fields->f_i32, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, buffer);
667
0
      break;
668
0
    case FR30_OPERAND_I8 :
669
0
      errmsg = insert_normal (cd, fields->f_i8, 0, 0, 4, 8, 16, total_length, buffer);
670
0
      break;
671
0
    case FR30_OPERAND_LABEL12 :
672
0
      {
673
0
        long value = fields->f_rel12;
674
0
        value = ((SI) (((value) - (((pc) + (2))))) >> (1));
675
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, buffer);
676
0
      }
677
0
      break;
678
0
    case FR30_OPERAND_LABEL9 :
679
0
      {
680
0
        long value = fields->f_rel9;
681
0
        value = ((SI) (((value) - (((pc) + (2))))) >> (1));
682
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, buffer);
683
0
      }
684
0
      break;
685
0
    case FR30_OPERAND_M4 :
686
0
      {
687
0
        long value = fields->f_m4;
688
0
        value = ((value) & (15));
689
0
        errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
690
0
      }
691
0
      break;
692
0
    case FR30_OPERAND_PS :
693
0
      break;
694
0
    case FR30_OPERAND_REGLIST_HI_LD :
695
0
      errmsg = insert_normal (cd, fields->f_reglist_hi_ld, 0, 0, 8, 8, 16, total_length, buffer);
696
0
      break;
697
0
    case FR30_OPERAND_REGLIST_HI_ST :
698
0
      errmsg = insert_normal (cd, fields->f_reglist_hi_st, 0, 0, 8, 8, 16, total_length, buffer);
699
0
      break;
700
0
    case FR30_OPERAND_REGLIST_LOW_LD :
701
0
      errmsg = insert_normal (cd, fields->f_reglist_low_ld, 0, 0, 8, 8, 16, total_length, buffer);
702
0
      break;
703
0
    case FR30_OPERAND_REGLIST_LOW_ST :
704
0
      errmsg = insert_normal (cd, fields->f_reglist_low_st, 0, 0, 8, 8, 16, total_length, buffer);
705
0
      break;
706
0
    case FR30_OPERAND_S10 :
707
0
      {
708
0
        long value = fields->f_s10;
709
0
        value = ((SI) (value) >> (2));
710
0
        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, buffer);
711
0
      }
712
0
      break;
713
0
    case FR30_OPERAND_U10 :
714
0
      {
715
0
        long value = fields->f_u10;
716
0
        value = ((USI) (value) >> (2));
717
0
        errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
718
0
      }
719
0
      break;
720
0
    case FR30_OPERAND_U4 :
721
0
      errmsg = insert_normal (cd, fields->f_u4, 0, 0, 8, 4, 16, total_length, buffer);
722
0
      break;
723
0
    case FR30_OPERAND_U4C :
724
0
      errmsg = insert_normal (cd, fields->f_u4c, 0, 0, 12, 4, 16, total_length, buffer);
725
0
      break;
726
0
    case FR30_OPERAND_U8 :
727
0
      errmsg = insert_normal (cd, fields->f_u8, 0, 0, 8, 8, 16, total_length, buffer);
728
0
      break;
729
0
    case FR30_OPERAND_UDISP6 :
730
0
      {
731
0
        long value = fields->f_udisp6;
732
0
        value = ((USI) (value) >> (2));
733
0
        errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
734
0
      }
735
0
      break;
736
737
0
    default :
738
      /* xgettext:c-format */
739
0
      opcodes_error_handler
740
0
  (_("internal error: unrecognized field %d while building insn"),
741
0
   opindex);
742
0
      abort ();
743
0
  }
744
745
0
  return errmsg;
746
0
}
747
748
int fr30_cgen_extract_operand
749
  (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
750
751
/* Main entry point for operand extraction.
752
   The result is <= 0 for error, >0 for success.
753
   ??? Actual values aren't well defined right now.
754
755
   This function is basically just a big switch statement.  Earlier versions
756
   used tables to look up the function to use, but
757
   - if the table contains both assembler and disassembler functions then
758
     the disassembler contains much of the assembler and vice-versa,
759
   - there's a lot of inlining possibilities as things grow,
760
   - using a switch statement avoids the function call overhead.
761
762
   This function could be moved into `print_insn_normal', but keeping it
763
   separate makes clear the interface between `print_insn_normal' and each of
764
   the handlers.  */
765
766
int
767
fr30_cgen_extract_operand (CGEN_CPU_DESC cd,
768
           int opindex,
769
           CGEN_EXTRACT_INFO *ex_info,
770
           CGEN_INSN_INT insn_value,
771
           CGEN_FIELDS * fields,
772
           bfd_vma pc)
773
313k
{
774
  /* Assume success (for those operands that are nops).  */
775
313k
  int length = 1;
776
313k
  unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
777
778
313k
  switch (opindex)
779
313k
    {
780
161
    case FR30_OPERAND_CRI :
781
161
      length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_CRi);
782
161
      break;
783
224
    case FR30_OPERAND_CRJ :
784
224
      length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_CRj);
785
224
      break;
786
47.8k
    case FR30_OPERAND_R13 :
787
47.8k
      break;
788
32.9k
    case FR30_OPERAND_R14 :
789
32.9k
      break;
790
3.55k
    case FR30_OPERAND_R15 :
791
3.55k
      break;
792
98.0k
    case FR30_OPERAND_RI :
793
98.0k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Ri);
794
98.0k
      break;
795
104
    case FR30_OPERAND_RIC :
796
104
      length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_Ric);
797
104
      break;
798
50.7k
    case FR30_OPERAND_RJ :
799
50.7k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rj);
800
50.7k
      break;
801
41
    case FR30_OPERAND_RJC :
802
41
      length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_Rjc);
803
41
      break;
804
626
    case FR30_OPERAND_RS1 :
805
626
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rs1);
806
626
      break;
807
976
    case FR30_OPERAND_RS2 :
808
976
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Rs2);
809
976
      break;
810
0
    case FR30_OPERAND_CC :
811
0
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 16, total_length, pc, & fields->f_cc);
812
0
      break;
813
265
    case FR30_OPERAND_CCC :
814
265
      length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 8, 16, total_length, pc, & fields->f_ccc);
815
265
      break;
816
3.13k
    case FR30_OPERAND_DIR10 :
817
3.13k
      {
818
3.13k
        long value;
819
3.13k
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
820
3.13k
        value = ((value) << (2));
821
3.13k
        fields->f_dir10 = value;
822
3.13k
      }
823
3.13k
      break;
824
1.51k
    case FR30_OPERAND_DIR8 :
825
1.51k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_dir8);
826
1.51k
      break;
827
2.34k
    case FR30_OPERAND_DIR9 :
828
2.34k
      {
829
2.34k
        long value;
830
2.34k
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
831
2.34k
        value = ((value) << (1));
832
2.34k
        fields->f_dir9 = value;
833
2.34k
      }
834
2.34k
      break;
835
10.4k
    case FR30_OPERAND_DISP10 :
836
10.4k
      {
837
10.4k
        long value;
838
10.4k
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
839
10.4k
        value = ((value) * (4));
840
10.4k
        fields->f_disp10 = value;
841
10.4k
      }
842
10.4k
      break;
843
12.5k
    case FR30_OPERAND_DISP8 :
844
12.5k
      length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & fields->f_disp8);
845
12.5k
      break;
846
9.92k
    case FR30_OPERAND_DISP9 :
847
9.92k
      {
848
9.92k
        long value;
849
9.92k
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
850
9.92k
        value = ((value) * (2));
851
9.92k
        fields->f_disp9 = value;
852
9.92k
      }
853
9.92k
      break;
854
579
    case FR30_OPERAND_I20 :
855
579
      {
856
579
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_i20_4);
857
579
        if (length <= 0) break;
858
579
        length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 16, 16, total_length, pc, & fields->f_i20_16);
859
579
        if (length <= 0) break;
860
579
{
861
579
  FLD (f_i20) = ((((FLD (f_i20_4)) << (16))) | (FLD (f_i20_16)));
862
579
}
863
579
      }
864
0
      break;
865
122
    case FR30_OPERAND_I32 :
866
122
      length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, pc, & fields->f_i32);
867
122
      break;
868
4.09k
    case FR30_OPERAND_I8 :
869
4.09k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 8, 16, total_length, pc, & fields->f_i8);
870
4.09k
      break;
871
3.11k
    case FR30_OPERAND_LABEL12 :
872
3.11k
      {
873
3.11k
        long value;
874
3.11k
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, pc, & value);
875
3.11k
        value = ((((value) * (2))) + (((pc) + (2))));
876
3.11k
        fields->f_rel12 = value;
877
3.11k
      }
878
3.11k
      break;
879
15.2k
    case FR30_OPERAND_LABEL9 :
880
15.2k
      {
881
15.2k
        long value;
882
15.2k
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, pc, & value);
883
15.2k
        value = ((((value) * (2))) + (((pc) + (2))));
884
15.2k
        fields->f_rel9 = value;
885
15.2k
      }
886
15.2k
      break;
887
729
    case FR30_OPERAND_M4 :
888
729
      {
889
729
        long value;
890
729
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
891
729
        value = ((value) | (-16));
892
729
        fields->f_m4 = value;
893
729
      }
894
729
      break;
895
705
    case FR30_OPERAND_PS :
896
705
      break;
897
1.15k
    case FR30_OPERAND_REGLIST_HI_LD :
898
1.15k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_ld);
899
1.15k
      break;
900
1.04k
    case FR30_OPERAND_REGLIST_HI_ST :
901
1.04k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_st);
902
1.04k
      break;
903
786
    case FR30_OPERAND_REGLIST_LOW_LD :
904
786
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_ld);
905
786
      break;
906
1.33k
    case FR30_OPERAND_REGLIST_LOW_ST :
907
1.33k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_st);
908
1.33k
      break;
909
249
    case FR30_OPERAND_S10 :
910
249
      {
911
249
        long value;
912
249
        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, pc, & value);
913
249
        value = ((value) * (4));
914
249
        fields->f_s10 = value;
915
249
      }
916
249
      break;
917
780
    case FR30_OPERAND_U10 :
918
780
      {
919
780
        long value;
920
780
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
921
780
        value = ((value) << (2));
922
780
        fields->f_u10 = value;
923
780
      }
924
780
      break;
925
5.60k
    case FR30_OPERAND_U4 :
926
5.60k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_u4);
927
5.60k
      break;
928
265
    case FR30_OPERAND_U4C :
929
265
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_u4c);
930
265
      break;
931
1.26k
    case FR30_OPERAND_U8 :
932
1.26k
      length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_u8);
933
1.26k
      break;
934
1.33k
    case FR30_OPERAND_UDISP6 :
935
1.33k
      {
936
1.33k
        long value;
937
1.33k
        length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
938
1.33k
        value = ((value) << (2));
939
1.33k
        fields->f_udisp6 = value;
940
1.33k
      }
941
1.33k
      break;
942
943
0
    default :
944
      /* xgettext:c-format */
945
0
      opcodes_error_handler
946
0
  (_("internal error: unrecognized field %d while decoding insn"),
947
0
   opindex);
948
0
      abort ();
949
313k
    }
950
951
313k
  return length;
952
313k
}
953
954
cgen_insert_fn * const fr30_cgen_insert_handlers[] =
955
{
956
  insert_insn_normal,
957
};
958
959
cgen_extract_fn * const fr30_cgen_extract_handlers[] =
960
{
961
  extract_insn_normal,
962
};
963
964
int fr30_cgen_get_int_operand     (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
965
bfd_vma fr30_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
966
967
/* Getting values from cgen_fields is handled by a collection of functions.
968
   They are distinguished by the type of the VALUE argument they return.
969
   TODO: floating point, inlining support, remove cases where result type
970
   not appropriate.  */
971
972
int
973
fr30_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
974
           int opindex,
975
           const CGEN_FIELDS * fields)
976
0
{
977
0
  int value;
978
979
0
  switch (opindex)
980
0
    {
981
0
    case FR30_OPERAND_CRI :
982
0
      value = fields->f_CRi;
983
0
      break;
984
0
    case FR30_OPERAND_CRJ :
985
0
      value = fields->f_CRj;
986
0
      break;
987
0
    case FR30_OPERAND_R13 :
988
0
      value = 0;
989
0
      break;
990
0
    case FR30_OPERAND_R14 :
991
0
      value = 0;
992
0
      break;
993
0
    case FR30_OPERAND_R15 :
994
0
      value = 0;
995
0
      break;
996
0
    case FR30_OPERAND_RI :
997
0
      value = fields->f_Ri;
998
0
      break;
999
0
    case FR30_OPERAND_RIC :
1000
0
      value = fields->f_Ric;
1001
0
      break;
1002
0
    case FR30_OPERAND_RJ :
1003
0
      value = fields->f_Rj;
1004
0
      break;
1005
0
    case FR30_OPERAND_RJC :
1006
0
      value = fields->f_Rjc;
1007
0
      break;
1008
0
    case FR30_OPERAND_RS1 :
1009
0
      value = fields->f_Rs1;
1010
0
      break;
1011
0
    case FR30_OPERAND_RS2 :
1012
0
      value = fields->f_Rs2;
1013
0
      break;
1014
0
    case FR30_OPERAND_CC :
1015
0
      value = fields->f_cc;
1016
0
      break;
1017
0
    case FR30_OPERAND_CCC :
1018
0
      value = fields->f_ccc;
1019
0
      break;
1020
0
    case FR30_OPERAND_DIR10 :
1021
0
      value = fields->f_dir10;
1022
0
      break;
1023
0
    case FR30_OPERAND_DIR8 :
1024
0
      value = fields->f_dir8;
1025
0
      break;
1026
0
    case FR30_OPERAND_DIR9 :
1027
0
      value = fields->f_dir9;
1028
0
      break;
1029
0
    case FR30_OPERAND_DISP10 :
1030
0
      value = fields->f_disp10;
1031
0
      break;
1032
0
    case FR30_OPERAND_DISP8 :
1033
0
      value = fields->f_disp8;
1034
0
      break;
1035
0
    case FR30_OPERAND_DISP9 :
1036
0
      value = fields->f_disp9;
1037
0
      break;
1038
0
    case FR30_OPERAND_I20 :
1039
0
      value = fields->f_i20;
1040
0
      break;
1041
0
    case FR30_OPERAND_I32 :
1042
0
      value = fields->f_i32;
1043
0
      break;
1044
0
    case FR30_OPERAND_I8 :
1045
0
      value = fields->f_i8;
1046
0
      break;
1047
0
    case FR30_OPERAND_LABEL12 :
1048
0
      value = fields->f_rel12;
1049
0
      break;
1050
0
    case FR30_OPERAND_LABEL9 :
1051
0
      value = fields->f_rel9;
1052
0
      break;
1053
0
    case FR30_OPERAND_M4 :
1054
0
      value = fields->f_m4;
1055
0
      break;
1056
0
    case FR30_OPERAND_PS :
1057
0
      value = 0;
1058
0
      break;
1059
0
    case FR30_OPERAND_REGLIST_HI_LD :
1060
0
      value = fields->f_reglist_hi_ld;
1061
0
      break;
1062
0
    case FR30_OPERAND_REGLIST_HI_ST :
1063
0
      value = fields->f_reglist_hi_st;
1064
0
      break;
1065
0
    case FR30_OPERAND_REGLIST_LOW_LD :
1066
0
      value = fields->f_reglist_low_ld;
1067
0
      break;
1068
0
    case FR30_OPERAND_REGLIST_LOW_ST :
1069
0
      value = fields->f_reglist_low_st;
1070
0
      break;
1071
0
    case FR30_OPERAND_S10 :
1072
0
      value = fields->f_s10;
1073
0
      break;
1074
0
    case FR30_OPERAND_U10 :
1075
0
      value = fields->f_u10;
1076
0
      break;
1077
0
    case FR30_OPERAND_U4 :
1078
0
      value = fields->f_u4;
1079
0
      break;
1080
0
    case FR30_OPERAND_U4C :
1081
0
      value = fields->f_u4c;
1082
0
      break;
1083
0
    case FR30_OPERAND_U8 :
1084
0
      value = fields->f_u8;
1085
0
      break;
1086
0
    case FR30_OPERAND_UDISP6 :
1087
0
      value = fields->f_udisp6;
1088
0
      break;
1089
1090
0
    default :
1091
      /* xgettext:c-format */
1092
0
      opcodes_error_handler
1093
0
  (_("internal error: unrecognized field %d while getting int operand"),
1094
0
   opindex);
1095
0
      abort ();
1096
0
  }
1097
1098
0
  return value;
1099
0
}
1100
1101
bfd_vma
1102
fr30_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1103
           int opindex,
1104
           const CGEN_FIELDS * fields)
1105
0
{
1106
0
  bfd_vma value;
1107
1108
0
  switch (opindex)
1109
0
    {
1110
0
    case FR30_OPERAND_CRI :
1111
0
      value = fields->f_CRi;
1112
0
      break;
1113
0
    case FR30_OPERAND_CRJ :
1114
0
      value = fields->f_CRj;
1115
0
      break;
1116
0
    case FR30_OPERAND_R13 :
1117
0
      value = 0;
1118
0
      break;
1119
0
    case FR30_OPERAND_R14 :
1120
0
      value = 0;
1121
0
      break;
1122
0
    case FR30_OPERAND_R15 :
1123
0
      value = 0;
1124
0
      break;
1125
0
    case FR30_OPERAND_RI :
1126
0
      value = fields->f_Ri;
1127
0
      break;
1128
0
    case FR30_OPERAND_RIC :
1129
0
      value = fields->f_Ric;
1130
0
      break;
1131
0
    case FR30_OPERAND_RJ :
1132
0
      value = fields->f_Rj;
1133
0
      break;
1134
0
    case FR30_OPERAND_RJC :
1135
0
      value = fields->f_Rjc;
1136
0
      break;
1137
0
    case FR30_OPERAND_RS1 :
1138
0
      value = fields->f_Rs1;
1139
0
      break;
1140
0
    case FR30_OPERAND_RS2 :
1141
0
      value = fields->f_Rs2;
1142
0
      break;
1143
0
    case FR30_OPERAND_CC :
1144
0
      value = fields->f_cc;
1145
0
      break;
1146
0
    case FR30_OPERAND_CCC :
1147
0
      value = fields->f_ccc;
1148
0
      break;
1149
0
    case FR30_OPERAND_DIR10 :
1150
0
      value = fields->f_dir10;
1151
0
      break;
1152
0
    case FR30_OPERAND_DIR8 :
1153
0
      value = fields->f_dir8;
1154
0
      break;
1155
0
    case FR30_OPERAND_DIR9 :
1156
0
      value = fields->f_dir9;
1157
0
      break;
1158
0
    case FR30_OPERAND_DISP10 :
1159
0
      value = fields->f_disp10;
1160
0
      break;
1161
0
    case FR30_OPERAND_DISP8 :
1162
0
      value = fields->f_disp8;
1163
0
      break;
1164
0
    case FR30_OPERAND_DISP9 :
1165
0
      value = fields->f_disp9;
1166
0
      break;
1167
0
    case FR30_OPERAND_I20 :
1168
0
      value = fields->f_i20;
1169
0
      break;
1170
0
    case FR30_OPERAND_I32 :
1171
0
      value = fields->f_i32;
1172
0
      break;
1173
0
    case FR30_OPERAND_I8 :
1174
0
      value = fields->f_i8;
1175
0
      break;
1176
0
    case FR30_OPERAND_LABEL12 :
1177
0
      value = fields->f_rel12;
1178
0
      break;
1179
0
    case FR30_OPERAND_LABEL9 :
1180
0
      value = fields->f_rel9;
1181
0
      break;
1182
0
    case FR30_OPERAND_M4 :
1183
0
      value = fields->f_m4;
1184
0
      break;
1185
0
    case FR30_OPERAND_PS :
1186
0
      value = 0;
1187
0
      break;
1188
0
    case FR30_OPERAND_REGLIST_HI_LD :
1189
0
      value = fields->f_reglist_hi_ld;
1190
0
      break;
1191
0
    case FR30_OPERAND_REGLIST_HI_ST :
1192
0
      value = fields->f_reglist_hi_st;
1193
0
      break;
1194
0
    case FR30_OPERAND_REGLIST_LOW_LD :
1195
0
      value = fields->f_reglist_low_ld;
1196
0
      break;
1197
0
    case FR30_OPERAND_REGLIST_LOW_ST :
1198
0
      value = fields->f_reglist_low_st;
1199
0
      break;
1200
0
    case FR30_OPERAND_S10 :
1201
0
      value = fields->f_s10;
1202
0
      break;
1203
0
    case FR30_OPERAND_U10 :
1204
0
      value = fields->f_u10;
1205
0
      break;
1206
0
    case FR30_OPERAND_U4 :
1207
0
      value = fields->f_u4;
1208
0
      break;
1209
0
    case FR30_OPERAND_U4C :
1210
0
      value = fields->f_u4c;
1211
0
      break;
1212
0
    case FR30_OPERAND_U8 :
1213
0
      value = fields->f_u8;
1214
0
      break;
1215
0
    case FR30_OPERAND_UDISP6 :
1216
0
      value = fields->f_udisp6;
1217
0
      break;
1218
1219
0
    default :
1220
      /* xgettext:c-format */
1221
0
      opcodes_error_handler
1222
0
  (_("internal error: unrecognized field %d while getting vma operand"),
1223
0
   opindex);
1224
0
      abort ();
1225
0
  }
1226
1227
0
  return value;
1228
0
}
1229
1230
void fr30_cgen_set_int_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
1231
void fr30_cgen_set_vma_operand  (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
1232
1233
/* Stuffing values in cgen_fields is handled by a collection of functions.
1234
   They are distinguished by the type of the VALUE argument they accept.
1235
   TODO: floating point, inlining support, remove cases where argument type
1236
   not appropriate.  */
1237
1238
void
1239
fr30_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1240
           int opindex,
1241
           CGEN_FIELDS * fields,
1242
           int value)
1243
0
{
1244
0
  switch (opindex)
1245
0
    {
1246
0
    case FR30_OPERAND_CRI :
1247
0
      fields->f_CRi = value;
1248
0
      break;
1249
0
    case FR30_OPERAND_CRJ :
1250
0
      fields->f_CRj = value;
1251
0
      break;
1252
0
    case FR30_OPERAND_R13 :
1253
0
      break;
1254
0
    case FR30_OPERAND_R14 :
1255
0
      break;
1256
0
    case FR30_OPERAND_R15 :
1257
0
      break;
1258
0
    case FR30_OPERAND_RI :
1259
0
      fields->f_Ri = value;
1260
0
      break;
1261
0
    case FR30_OPERAND_RIC :
1262
0
      fields->f_Ric = value;
1263
0
      break;
1264
0
    case FR30_OPERAND_RJ :
1265
0
      fields->f_Rj = value;
1266
0
      break;
1267
0
    case FR30_OPERAND_RJC :
1268
0
      fields->f_Rjc = value;
1269
0
      break;
1270
0
    case FR30_OPERAND_RS1 :
1271
0
      fields->f_Rs1 = value;
1272
0
      break;
1273
0
    case FR30_OPERAND_RS2 :
1274
0
      fields->f_Rs2 = value;
1275
0
      break;
1276
0
    case FR30_OPERAND_CC :
1277
0
      fields->f_cc = value;
1278
0
      break;
1279
0
    case FR30_OPERAND_CCC :
1280
0
      fields->f_ccc = value;
1281
0
      break;
1282
0
    case FR30_OPERAND_DIR10 :
1283
0
      fields->f_dir10 = value;
1284
0
      break;
1285
0
    case FR30_OPERAND_DIR8 :
1286
0
      fields->f_dir8 = value;
1287
0
      break;
1288
0
    case FR30_OPERAND_DIR9 :
1289
0
      fields->f_dir9 = value;
1290
0
      break;
1291
0
    case FR30_OPERAND_DISP10 :
1292
0
      fields->f_disp10 = value;
1293
0
      break;
1294
0
    case FR30_OPERAND_DISP8 :
1295
0
      fields->f_disp8 = value;
1296
0
      break;
1297
0
    case FR30_OPERAND_DISP9 :
1298
0
      fields->f_disp9 = value;
1299
0
      break;
1300
0
    case FR30_OPERAND_I20 :
1301
0
      fields->f_i20 = value;
1302
0
      break;
1303
0
    case FR30_OPERAND_I32 :
1304
0
      fields->f_i32 = value;
1305
0
      break;
1306
0
    case FR30_OPERAND_I8 :
1307
0
      fields->f_i8 = value;
1308
0
      break;
1309
0
    case FR30_OPERAND_LABEL12 :
1310
0
      fields->f_rel12 = value;
1311
0
      break;
1312
0
    case FR30_OPERAND_LABEL9 :
1313
0
      fields->f_rel9 = value;
1314
0
      break;
1315
0
    case FR30_OPERAND_M4 :
1316
0
      fields->f_m4 = value;
1317
0
      break;
1318
0
    case FR30_OPERAND_PS :
1319
0
      break;
1320
0
    case FR30_OPERAND_REGLIST_HI_LD :
1321
0
      fields->f_reglist_hi_ld = value;
1322
0
      break;
1323
0
    case FR30_OPERAND_REGLIST_HI_ST :
1324
0
      fields->f_reglist_hi_st = value;
1325
0
      break;
1326
0
    case FR30_OPERAND_REGLIST_LOW_LD :
1327
0
      fields->f_reglist_low_ld = value;
1328
0
      break;
1329
0
    case FR30_OPERAND_REGLIST_LOW_ST :
1330
0
      fields->f_reglist_low_st = value;
1331
0
      break;
1332
0
    case FR30_OPERAND_S10 :
1333
0
      fields->f_s10 = value;
1334
0
      break;
1335
0
    case FR30_OPERAND_U10 :
1336
0
      fields->f_u10 = value;
1337
0
      break;
1338
0
    case FR30_OPERAND_U4 :
1339
0
      fields->f_u4 = value;
1340
0
      break;
1341
0
    case FR30_OPERAND_U4C :
1342
0
      fields->f_u4c = value;
1343
0
      break;
1344
0
    case FR30_OPERAND_U8 :
1345
0
      fields->f_u8 = value;
1346
0
      break;
1347
0
    case FR30_OPERAND_UDISP6 :
1348
0
      fields->f_udisp6 = value;
1349
0
      break;
1350
1351
0
    default :
1352
      /* xgettext:c-format */
1353
0
      opcodes_error_handler
1354
0
  (_("internal error: unrecognized field %d while setting int operand"),
1355
0
   opindex);
1356
0
      abort ();
1357
0
  }
1358
0
}
1359
1360
void
1361
fr30_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1362
           int opindex,
1363
           CGEN_FIELDS * fields,
1364
           bfd_vma value)
1365
0
{
1366
0
  switch (opindex)
1367
0
    {
1368
0
    case FR30_OPERAND_CRI :
1369
0
      fields->f_CRi = value;
1370
0
      break;
1371
0
    case FR30_OPERAND_CRJ :
1372
0
      fields->f_CRj = value;
1373
0
      break;
1374
0
    case FR30_OPERAND_R13 :
1375
0
      break;
1376
0
    case FR30_OPERAND_R14 :
1377
0
      break;
1378
0
    case FR30_OPERAND_R15 :
1379
0
      break;
1380
0
    case FR30_OPERAND_RI :
1381
0
      fields->f_Ri = value;
1382
0
      break;
1383
0
    case FR30_OPERAND_RIC :
1384
0
      fields->f_Ric = value;
1385
0
      break;
1386
0
    case FR30_OPERAND_RJ :
1387
0
      fields->f_Rj = value;
1388
0
      break;
1389
0
    case FR30_OPERAND_RJC :
1390
0
      fields->f_Rjc = value;
1391
0
      break;
1392
0
    case FR30_OPERAND_RS1 :
1393
0
      fields->f_Rs1 = value;
1394
0
      break;
1395
0
    case FR30_OPERAND_RS2 :
1396
0
      fields->f_Rs2 = value;
1397
0
      break;
1398
0
    case FR30_OPERAND_CC :
1399
0
      fields->f_cc = value;
1400
0
      break;
1401
0
    case FR30_OPERAND_CCC :
1402
0
      fields->f_ccc = value;
1403
0
      break;
1404
0
    case FR30_OPERAND_DIR10 :
1405
0
      fields->f_dir10 = value;
1406
0
      break;
1407
0
    case FR30_OPERAND_DIR8 :
1408
0
      fields->f_dir8 = value;
1409
0
      break;
1410
0
    case FR30_OPERAND_DIR9 :
1411
0
      fields->f_dir9 = value;
1412
0
      break;
1413
0
    case FR30_OPERAND_DISP10 :
1414
0
      fields->f_disp10 = value;
1415
0
      break;
1416
0
    case FR30_OPERAND_DISP8 :
1417
0
      fields->f_disp8 = value;
1418
0
      break;
1419
0
    case FR30_OPERAND_DISP9 :
1420
0
      fields->f_disp9 = value;
1421
0
      break;
1422
0
    case FR30_OPERAND_I20 :
1423
0
      fields->f_i20 = value;
1424
0
      break;
1425
0
    case FR30_OPERAND_I32 :
1426
0
      fields->f_i32 = value;
1427
0
      break;
1428
0
    case FR30_OPERAND_I8 :
1429
0
      fields->f_i8 = value;
1430
0
      break;
1431
0
    case FR30_OPERAND_LABEL12 :
1432
0
      fields->f_rel12 = value;
1433
0
      break;
1434
0
    case FR30_OPERAND_LABEL9 :
1435
0
      fields->f_rel9 = value;
1436
0
      break;
1437
0
    case FR30_OPERAND_M4 :
1438
0
      fields->f_m4 = value;
1439
0
      break;
1440
0
    case FR30_OPERAND_PS :
1441
0
      break;
1442
0
    case FR30_OPERAND_REGLIST_HI_LD :
1443
0
      fields->f_reglist_hi_ld = value;
1444
0
      break;
1445
0
    case FR30_OPERAND_REGLIST_HI_ST :
1446
0
      fields->f_reglist_hi_st = value;
1447
0
      break;
1448
0
    case FR30_OPERAND_REGLIST_LOW_LD :
1449
0
      fields->f_reglist_low_ld = value;
1450
0
      break;
1451
0
    case FR30_OPERAND_REGLIST_LOW_ST :
1452
0
      fields->f_reglist_low_st = value;
1453
0
      break;
1454
0
    case FR30_OPERAND_S10 :
1455
0
      fields->f_s10 = value;
1456
0
      break;
1457
0
    case FR30_OPERAND_U10 :
1458
0
      fields->f_u10 = value;
1459
0
      break;
1460
0
    case FR30_OPERAND_U4 :
1461
0
      fields->f_u4 = value;
1462
0
      break;
1463
0
    case FR30_OPERAND_U4C :
1464
0
      fields->f_u4c = value;
1465
0
      break;
1466
0
    case FR30_OPERAND_U8 :
1467
0
      fields->f_u8 = value;
1468
0
      break;
1469
0
    case FR30_OPERAND_UDISP6 :
1470
0
      fields->f_udisp6 = value;
1471
0
      break;
1472
1473
0
    default :
1474
      /* xgettext:c-format */
1475
0
      opcodes_error_handler
1476
0
  (_("internal error: unrecognized field %d while setting vma operand"),
1477
0
   opindex);
1478
0
      abort ();
1479
0
  }
1480
0
}
1481
1482
/* Function to call before using the instruction builder tables.  */
1483
1484
void
1485
fr30_cgen_init_ibld_table (CGEN_CPU_DESC cd)
1486
3
{
1487
3
  cd->insert_handlers = & fr30_cgen_insert_handlers[0];
1488
3
  cd->extract_handlers = & fr30_cgen_extract_handlers[0];
1489
1490
3
  cd->insert_operand = fr30_cgen_insert_operand;
1491
3
  cd->extract_operand = fr30_cgen_extract_operand;
1492
1493
3
  cd->get_int_operand = fr30_cgen_get_int_operand;
1494
3
  cd->set_int_operand = fr30_cgen_set_int_operand;
1495
3
  cd->get_vma_operand = fr30_cgen_get_vma_operand;
1496
3
  cd->set_vma_operand = fr30_cgen_set_vma_operand;
1497
3
}