Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/fr30-dis.c
Line
Count
Source
1
/* DO NOT EDIT!  -*- buffer-read-only: t -*- vi:set ro:  */
2
/* Disassembler interface for targets using CGEN. -*- C -*-
3
   CGEN: Cpu tools GENerator
4
5
   THIS FILE IS MACHINE GENERATED WITH CGEN.
6
   - the resultant file is machine generated, cgen-dis.in isn't
7
8
   Copyright (C) 1996-2026 Free Software Foundation, Inc.
9
10
   This file is part of libopcodes.
11
12
   This library is free software; you can redistribute it and/or modify
13
   it under the terms of the GNU General Public License as published by
14
   the Free Software Foundation; either version 3, or (at your option)
15
   any later version.
16
17
   It is distributed in the hope that it will be useful, but WITHOUT
18
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
20
   License for more details.
21
22
   You should have received a copy of the GNU General Public License
23
   along with this program; if not, write to the Free Software Foundation, Inc.,
24
   51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
25
26
/* ??? Eventually more and more of this stuff can go to cpu-independent files.
27
   Keep that in mind.  */
28
29
#include "sysdep.h"
30
#include <stdio.h>
31
#include "ansidecl.h"
32
#include "disassemble.h"
33
#include "bfd.h"
34
#include "symcat.h"
35
#include "libiberty.h"
36
#include "fr30-desc.h"
37
#include "fr30-opc.h"
38
#include "opintl.h"
39
40
/* Default text to print if an instruction isn't recognized.  */
41
80.4k
#define UNKNOWN_INSN_MSG _("*unknown*")
42
43
static void print_normal
44
  (CGEN_CPU_DESC, void *, long, unsigned int, bfd_vma, int);
45
static void print_address
46
  (CGEN_CPU_DESC, void *, bfd_vma, unsigned int, bfd_vma, int) ATTRIBUTE_UNUSED;
47
static void print_keyword
48
  (CGEN_CPU_DESC, void *, CGEN_KEYWORD *, long, unsigned int) ATTRIBUTE_UNUSED;
49
static void print_insn_normal
50
  (CGEN_CPU_DESC, void *, const CGEN_INSN *, CGEN_FIELDS *, bfd_vma, int);
51
static int print_insn
52
  (CGEN_CPU_DESC, bfd_vma,  disassemble_info *, bfd_byte *, unsigned);
53
static int default_print_insn
54
  (CGEN_CPU_DESC, bfd_vma, disassemble_info *) ATTRIBUTE_UNUSED;
55
static int read_insn
56
  (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, int, CGEN_EXTRACT_INFO *,
57
   unsigned long *);
58

59
/* -- disassembler routines inserted here.  */
60
61
/* -- dis.c */
62
static void
63
print_register_list (void * dis_info,
64
         long value,
65
         long offset,
66
         int load_store) /* 0 == load, 1 == store.  */
67
6.02k
{
68
6.02k
  disassemble_info *info = dis_info;
69
6.02k
  int mask;
70
6.02k
  int reg_index = 0;
71
6.02k
  char * comma = "";
72
73
6.02k
  if (load_store)
74
3.15k
    mask = 0x80;
75
2.86k
  else
76
2.86k
    mask = 1;
77
78
6.02k
  if (value & mask)
79
2.86k
    {
80
2.86k
      (*info->fprintf_func) (info->stream, "r%li", reg_index + offset);
81
2.86k
      comma = ",";
82
2.86k
    }
83
84
48.1k
  for (reg_index = 1; reg_index <= 7; ++reg_index)
85
42.1k
    {
86
42.1k
      if (load_store)
87
22.1k
  mask >>= 1;
88
20.0k
      else
89
20.0k
  mask <<= 1;
90
91
42.1k
      if (value & mask)
92
16.8k
  {
93
16.8k
    (*info->fprintf_func) (info->stream, "%sr%li", comma, reg_index + offset);
94
16.8k
    comma = ",";
95
16.8k
  }
96
42.1k
    }
97
6.02k
}
98
99
static void
100
print_hi_register_list_ld (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
101
         void * dis_info,
102
         long value,
103
         unsigned int attrs ATTRIBUTE_UNUSED,
104
         bfd_vma pc ATTRIBUTE_UNUSED,
105
         int length ATTRIBUTE_UNUSED)
106
1.66k
{
107
1.66k
  print_register_list (dis_info, value, 8, 0 /* Load.  */);
108
1.66k
}
109
110
static void
111
print_low_register_list_ld (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
112
          void * dis_info,
113
          long value,
114
          unsigned int attrs ATTRIBUTE_UNUSED,
115
          bfd_vma pc ATTRIBUTE_UNUSED,
116
          int length ATTRIBUTE_UNUSED)
117
1.19k
{
118
1.19k
  print_register_list (dis_info, value, 0, 0 /* Load.  */);
119
1.19k
}
120
121
static void
122
print_hi_register_list_st (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
123
         void * dis_info,
124
         long value,
125
         unsigned int attrs ATTRIBUTE_UNUSED,
126
         bfd_vma pc ATTRIBUTE_UNUSED,
127
         int length ATTRIBUTE_UNUSED)
128
1.42k
{
129
1.42k
  print_register_list (dis_info, value, 8, 1 /* Store.  */);
130
1.42k
}
131
132
static void
133
print_low_register_list_st (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
134
          void * dis_info,
135
          long value,
136
          unsigned int attrs ATTRIBUTE_UNUSED,
137
          bfd_vma pc ATTRIBUTE_UNUSED,
138
          int length ATTRIBUTE_UNUSED)
139
1.73k
{
140
1.73k
  print_register_list (dis_info, value, 0, 1 /* Store.  */);
141
1.73k
}
142
143
static void
144
print_m4 (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
145
    void * dis_info,
146
    long value,
147
    unsigned int attrs ATTRIBUTE_UNUSED,
148
    bfd_vma pc ATTRIBUTE_UNUSED,
149
    int length ATTRIBUTE_UNUSED)
150
2.44k
{
151
2.44k
  disassemble_info *info = (disassemble_info *) dis_info;
152
153
2.44k
  (*info->fprintf_func) (info->stream, "%ld", value);
154
2.44k
}
155
/* -- */
156
157
void fr30_cgen_print_operand
158
  (CGEN_CPU_DESC, int, void *, CGEN_FIELDS *, void const *, bfd_vma, int);
159
160
/* Main entry point for printing operands.
161
   XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
162
   of dis-asm.h on cgen.h.
163
164
   This function is basically just a big switch statement.  Earlier versions
165
   used tables to look up the function to use, but
166
   - if the table contains both assembler and disassembler functions then
167
     the disassembler contains much of the assembler and vice-versa,
168
   - there's a lot of inlining possibilities as things grow,
169
   - using a switch statement avoids the function call overhead.
170
171
   This function could be moved into `print_insn_normal', but keeping it
172
   separate makes clear the interface between `print_insn_normal' and each of
173
   the handlers.  */
174
175
void
176
fr30_cgen_print_operand (CGEN_CPU_DESC cd,
177
         int opindex,
178
         void * xinfo,
179
         CGEN_FIELDS *fields,
180
         void const *attrs ATTRIBUTE_UNUSED,
181
         bfd_vma pc,
182
         int length)
183
719k
{
184
719k
  disassemble_info *info = (disassemble_info *) xinfo;
185
186
719k
  switch (opindex)
187
719k
    {
188
462
    case FR30_OPERAND_CRI :
189
462
      print_keyword (cd, info, & fr30_cgen_opval_cr_names, fields->f_CRi, 0);
190
462
      break;
191
550
    case FR30_OPERAND_CRJ :
192
550
      print_keyword (cd, info, & fr30_cgen_opval_cr_names, fields->f_CRj, 0);
193
550
      break;
194
85.2k
    case FR30_OPERAND_R13 :
195
85.2k
      print_keyword (cd, info, & fr30_cgen_opval_h_r13, 0, 0);
196
85.2k
      break;
197
92.5k
    case FR30_OPERAND_R14 :
198
92.5k
      print_keyword (cd, info, & fr30_cgen_opval_h_r14, 0, 0);
199
92.5k
      break;
200
6.31k
    case FR30_OPERAND_R15 :
201
6.31k
      print_keyword (cd, info, & fr30_cgen_opval_h_r15, 0, 0);
202
6.31k
      break;
203
228k
    case FR30_OPERAND_RI :
204
228k
      print_keyword (cd, info, & fr30_cgen_opval_gr_names, fields->f_Ri, 0);
205
228k
      break;
206
169
    case FR30_OPERAND_RIC :
207
169
      print_keyword (cd, info, & fr30_cgen_opval_gr_names, fields->f_Ric, 0);
208
169
      break;
209
97.9k
    case FR30_OPERAND_RJ :
210
97.9k
      print_keyword (cd, info, & fr30_cgen_opval_gr_names, fields->f_Rj, 0);
211
97.9k
      break;
212
81
    case FR30_OPERAND_RJC :
213
81
      print_keyword (cd, info, & fr30_cgen_opval_gr_names, fields->f_Rjc, 0);
214
81
      break;
215
1.76k
    case FR30_OPERAND_RS1 :
216
1.76k
      print_keyword (cd, info, & fr30_cgen_opval_dr_names, fields->f_Rs1, 0);
217
1.76k
      break;
218
947
    case FR30_OPERAND_RS2 :
219
947
      print_keyword (cd, info, & fr30_cgen_opval_dr_names, fields->f_Rs2, 0);
220
947
      break;
221
0
    case FR30_OPERAND_CC :
222
0
      print_normal (cd, info, fields->f_cc, 0, pc, length);
223
0
      break;
224
631
    case FR30_OPERAND_CCC :
225
631
      print_normal (cd, info, fields->f_ccc, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
226
631
      break;
227
6.14k
    case FR30_OPERAND_DIR10 :
228
6.14k
      print_normal (cd, info, fields->f_dir10, 0, pc, length);
229
6.14k
      break;
230
4.02k
    case FR30_OPERAND_DIR8 :
231
4.02k
      print_normal (cd, info, fields->f_dir8, 0, pc, length);
232
4.02k
      break;
233
5.51k
    case FR30_OPERAND_DIR9 :
234
5.51k
      print_normal (cd, info, fields->f_dir9, 0, pc, length);
235
5.51k
      break;
236
32.4k
    case FR30_OPERAND_DISP10 :
237
32.4k
      print_normal (cd, info, fields->f_disp10, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
238
32.4k
      break;
239
30.6k
    case FR30_OPERAND_DISP8 :
240
30.6k
      print_normal (cd, info, fields->f_disp8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
241
30.6k
      break;
242
29.5k
    case FR30_OPERAND_DISP9 :
243
29.5k
      print_normal (cd, info, fields->f_disp9, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
244
29.5k
      break;
245
1.21k
    case FR30_OPERAND_I20 :
246
1.21k
      print_normal (cd, info, fields->f_i20, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
247
1.21k
      break;
248
90
    case FR30_OPERAND_I32 :
249
90
      print_normal (cd, info, fields->f_i32, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGN_OPT), pc, length);
250
90
      break;
251
11.7k
    case FR30_OPERAND_I8 :
252
11.7k
      print_normal (cd, info, fields->f_i8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
253
11.7k
      break;
254
11.8k
    case FR30_OPERAND_LABEL12 :
255
11.8k
      print_address (cd, info, fields->f_rel12, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
256
11.8k
      break;
257
37.5k
    case FR30_OPERAND_LABEL9 :
258
37.5k
      print_address (cd, info, fields->f_rel9, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
259
37.5k
      break;
260
2.44k
    case FR30_OPERAND_M4 :
261
2.44k
      print_m4 (cd, info, fields->f_m4, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
262
2.44k
      break;
263
345
    case FR30_OPERAND_PS :
264
345
      print_keyword (cd, info, & fr30_cgen_opval_h_ps, 0, 0);
265
345
      break;
266
1.66k
    case FR30_OPERAND_REGLIST_HI_LD :
267
1.66k
      print_hi_register_list_ld (cd, info, fields->f_reglist_hi_ld, 0, pc, length);
268
1.66k
      break;
269
1.42k
    case FR30_OPERAND_REGLIST_HI_ST :
270
1.42k
      print_hi_register_list_st (cd, info, fields->f_reglist_hi_st, 0, pc, length);
271
1.42k
      break;
272
1.19k
    case FR30_OPERAND_REGLIST_LOW_LD :
273
1.19k
      print_low_register_list_ld (cd, info, fields->f_reglist_low_ld, 0, pc, length);
274
1.19k
      break;
275
1.73k
    case FR30_OPERAND_REGLIST_LOW_ST :
276
1.73k
      print_low_register_list_st (cd, info, fields->f_reglist_low_st, 0, pc, length);
277
1.73k
      break;
278
1.31k
    case FR30_OPERAND_S10 :
279
1.31k
      print_normal (cd, info, fields->f_s10, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
280
1.31k
      break;
281
1.60k
    case FR30_OPERAND_U10 :
282
1.60k
      print_normal (cd, info, fields->f_u10, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
283
1.60k
      break;
284
15.3k
    case FR30_OPERAND_U4 :
285
15.3k
      print_normal (cd, info, fields->f_u4, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
286
15.3k
      break;
287
631
    case FR30_OPERAND_U4C :
288
631
      print_normal (cd, info, fields->f_u4c, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
289
631
      break;
290
3.46k
    case FR30_OPERAND_U8 :
291
3.46k
      print_normal (cd, info, fields->f_u8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
292
3.46k
      break;
293
2.97k
    case FR30_OPERAND_UDISP6 :
294
2.97k
      print_normal (cd, info, fields->f_udisp6, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
295
2.97k
      break;
296
297
0
    default :
298
      /* xgettext:c-format */
299
0
      opcodes_error_handler
300
0
  (_("internal error: unrecognized field %d while printing insn"),
301
0
   opindex);
302
0
      abort ();
303
719k
  }
304
719k
}
305
306
cgen_print_fn * const fr30_cgen_print_handlers[] =
307
{
308
  print_insn_normal,
309
};
310
311
312
void
313
fr30_cgen_init_dis (CGEN_CPU_DESC cd)
314
3
{
315
3
  fr30_cgen_init_opcode_table (cd);
316
3
  fr30_cgen_init_ibld_table (cd);
317
3
  cd->print_handlers = & fr30_cgen_print_handlers[0];
318
3
  cd->print_operand = fr30_cgen_print_operand;
319
3
}
320
321

322
/* Default print handler.  */
323
324
static void
325
print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
326
        void *dis_info,
327
        long value,
328
        unsigned int attrs,
329
        bfd_vma pc ATTRIBUTE_UNUSED,
330
        int length ATTRIBUTE_UNUSED)
331
147k
{
332
147k
  disassemble_info *info = (disassemble_info *) dis_info;
333
334
  /* Print the operand as directed by the attributes.  */
335
147k
  if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
336
0
    ; /* nothing to do */
337
147k
  else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
338
93.9k
    (*info->fprintf_func) (info->stream, "%ld", value);
339
53.4k
  else
340
53.4k
    (*info->fprintf_func) (info->stream, "0x%lx", value);
341
147k
}
342
343
/* Default address handler.  */
344
345
static void
346
print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
347
         void *dis_info,
348
         bfd_vma value,
349
         unsigned int attrs,
350
         bfd_vma pc ATTRIBUTE_UNUSED,
351
         int length ATTRIBUTE_UNUSED)
352
49.3k
{
353
49.3k
  disassemble_info *info = (disassemble_info *) dis_info;
354
355
  /* Print the operand as directed by the attributes.  */
356
49.3k
  if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
357
0
    ; /* Nothing to do.  */
358
49.3k
  else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
359
49.3k
    (*info->print_address_func) (value, info);
360
0
  else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
361
0
    (*info->print_address_func) (value, info);
362
0
  else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
363
0
    (*info->fprintf_func) (info->stream, "%ld", (long) value);
364
0
  else
365
0
    (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
366
49.3k
}
367
368
/* Keyword print handler.  */
369
370
static void
371
print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
372
         void *dis_info,
373
         CGEN_KEYWORD *keyword_table,
374
         long value,
375
         unsigned int attrs ATTRIBUTE_UNUSED)
376
514k
{
377
514k
  disassemble_info *info = (disassemble_info *) dis_info;
378
514k
  const CGEN_KEYWORD_ENTRY *ke;
379
380
514k
  ke = cgen_keyword_lookup_value (keyword_table, value);
381
514k
  if (ke != NULL)
382
512k
    (*info->fprintf_func) (info->stream, "%s", ke->name);
383
1.47k
  else
384
1.47k
    (*info->fprintf_func) (info->stream, "???");
385
514k
}
386

387
/* Default insn printer.
388
389
   DIS_INFO is defined as `void *' so the disassembler needn't know anything
390
   about disassemble_info.  */
391
392
static void
393
print_insn_normal (CGEN_CPU_DESC cd,
394
       void *dis_info,
395
       const CGEN_INSN *insn,
396
       CGEN_FIELDS *fields,
397
       bfd_vma pc,
398
       int length)
399
307k
{
400
307k
  const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
401
307k
  disassemble_info *info = (disassemble_info *) dis_info;
402
307k
  const CGEN_SYNTAX_CHAR_TYPE *syn;
403
404
307k
  CGEN_INIT_PRINT (cd);
405
406
2.62M
  for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
407
2.31M
    {
408
2.31M
      if (CGEN_SYNTAX_MNEMONIC_P (*syn))
409
307k
  {
410
307k
    (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
411
307k
    continue;
412
307k
  }
413
2.00M
      if (CGEN_SYNTAX_CHAR_P (*syn))
414
1.28M
  {
415
1.28M
    (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
416
1.28M
    continue;
417
1.28M
  }
418
419
      /* We have an operand.  */
420
719k
      fr30_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
421
719k
         fields, CGEN_INSN_ATTRS (insn), pc, length);
422
719k
    }
423
307k
}
424

425
/* Subroutine of print_insn. Reads an insn into the given buffers and updates
426
   the extract info.
427
   Returns 0 if all is well, non-zero otherwise.  */
428
429
static int
430
read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
431
     bfd_vma pc,
432
     disassemble_info *info,
433
     bfd_byte *buf,
434
     int buflen,
435
     CGEN_EXTRACT_INFO *ex_info,
436
     unsigned long *insn_value)
437
1.93k
{
438
1.93k
  int status = (*info->read_memory_func) (pc, buf, buflen, info);
439
440
1.93k
  if (status != 0)
441
2
    {
442
2
      (*info->memory_error_func) (status, pc, info);
443
2
      return -1;
444
2
    }
445
446
1.93k
  ex_info->dis_info = info;
447
1.93k
  ex_info->valid = (1 << buflen) - 1;
448
1.93k
  ex_info->insn_bytes = buf;
449
450
1.93k
  *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
451
1.93k
  return 0;
452
1.93k
}
453
454
/* Utility to print an insn.
455
   BUF is the base part of the insn, target byte order, BUFLEN bytes long.
456
   The result is the size of the insn in bytes or zero for an unknown insn
457
   or -1 if an error occurs fetching data (memory_error_func will have
458
   been called).  */
459
460
static int
461
print_insn (CGEN_CPU_DESC cd,
462
      bfd_vma pc,
463
      disassemble_info *info,
464
      bfd_byte *buf,
465
      unsigned int buflen)
466
387k
{
467
387k
  CGEN_INSN_INT insn_value;
468
387k
  const CGEN_INSN_LIST *insn_list;
469
387k
  CGEN_EXTRACT_INFO ex_info;
470
387k
  int basesize;
471
472
  /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
473
387k
  basesize = cd->base_insn_bitsize < buflen * 8 ?
474
387k
                                     cd->base_insn_bitsize : buflen * 8;
475
387k
  insn_value = cgen_get_insn_value (cd, buf, basesize, cd->insn_endian);
476
477
478
  /* Fill in ex_info fields like read_insn would.  Don't actually call
479
     read_insn, since the incoming buffer is already read (and possibly
480
     modified a la m32r).  */
481
387k
  ex_info.valid = (1 << buflen) - 1;
482
387k
  ex_info.dis_info = info;
483
387k
  ex_info.insn_bytes = buf;
484
485
  /* The instructions are stored in hash lists.
486
     Pick the first one and keep trying until we find the right one.  */
487
488
387k
  insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
489
5.46M
  while (insn_list != NULL)
490
5.38M
    {
491
5.38M
      const CGEN_INSN *insn = insn_list->insn;
492
5.38M
      CGEN_FIELDS fields;
493
5.38M
      int length;
494
5.38M
      unsigned long insn_value_cropped;
495
496
#ifdef CGEN_VALIDATE_INSN_SUPPORTED
497
      /* Not needed as insn shouldn't be in hash lists if not supported.  */
498
      /* Supported by this cpu?  */
499
      if (! fr30_cgen_insn_supported (cd, insn))
500
        {
501
          insn_list = CGEN_DIS_NEXT_INSN (insn_list);
502
    continue;
503
        }
504
#endif
505
506
      /* Basic bit mask must be correct.  */
507
      /* ??? May wish to allow target to defer this check until the extract
508
   handler.  */
509
510
      /* Base size may exceed this instruction's size.  Extract the
511
         relevant part from the buffer. */
512
5.38M
      if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
513
0
    (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
514
0
  insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
515
0
             info->endian == BFD_ENDIAN_BIG);
516
5.38M
      else
517
5.38M
  insn_value_cropped = insn_value;
518
519
5.38M
      if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
520
5.38M
    == CGEN_INSN_BASE_VALUE (insn))
521
307k
  {
522
    /* Printing is handled in two passes.  The first pass parses the
523
       machine insn and extracts the fields.  The second pass prints
524
       them.  */
525
526
    /* Make sure the entire insn is loaded into insn_value, if it
527
       can fit.  */
528
307k
    if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
529
1.93k
        (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
530
1.93k
      {
531
1.93k
        unsigned long full_insn_value;
532
1.93k
        int rc = read_insn (cd, pc, info, buf,
533
1.93k
          CGEN_INSN_BITSIZE (insn) / 8,
534
1.93k
          & ex_info, & full_insn_value);
535
1.93k
        if (rc != 0)
536
2
    return rc;
537
1.93k
        length = CGEN_EXTRACT_FN (cd, insn)
538
1.93k
    (cd, insn, &ex_info, full_insn_value, &fields, pc);
539
1.93k
      }
540
305k
    else
541
305k
      length = CGEN_EXTRACT_FN (cd, insn)
542
305k
        (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
543
544
    /* Length < 0 -> error.  */
545
307k
    if (length < 0)
546
0
      return length;
547
307k
    if (length > 0)
548
307k
      {
549
307k
        CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
550
        /* Length is in bits, result is in bytes.  */
551
307k
        return length / 8;
552
307k
      }
553
307k
  }
554
555
5.07M
      insn_list = CGEN_DIS_NEXT_INSN (insn_list);
556
5.07M
    }
557
558
80.4k
  return 0;
559
387k
}
560
561
/* Default value for CGEN_PRINT_INSN.
562
   The result is the size of the insn in bytes or zero for an unknown insn
563
   or -1 if an error occured fetching bytes.  */
564
565
#ifndef CGEN_PRINT_INSN
566
387k
#define CGEN_PRINT_INSN default_print_insn
567
#endif
568
569
static int
570
default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
571
387k
{
572
387k
  bfd_byte buf[CGEN_MAX_INSN_SIZE];
573
387k
  int buflen;
574
387k
  int status;
575
576
  /* Attempt to read the base part of the insn.  */
577
387k
  buflen = cd->base_insn_bitsize / 8;
578
387k
  status = (*info->read_memory_func) (pc, buf, buflen, info);
579
580
  /* Try again with the minimum part, if min < base.  */
581
387k
  if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
582
0
    {
583
0
      buflen = cd->min_insn_bitsize / 8;
584
0
      status = (*info->read_memory_func) (pc, buf, buflen, info);
585
0
    }
586
587
387k
  if (status != 0)
588
81
    {
589
81
      (*info->memory_error_func) (status, pc, info);
590
81
      return -1;
591
81
    }
592
593
387k
  return print_insn (cd, pc, info, buf, buflen);
594
387k
}
595
596
/* Main entry point.
597
   Print one instruction from PC on INFO->STREAM.
598
   Return the size of the instruction (in bytes).  */
599
600
typedef struct cpu_desc_list
601
{
602
  struct cpu_desc_list *next;
603
  CGEN_BITSET *isa;
604
  int mach;
605
  int endian;
606
  int insn_endian;
607
  CGEN_CPU_DESC cd;
608
} cpu_desc_list;
609
610
int
611
print_insn_fr30 (bfd_vma pc, disassemble_info *info)
612
387k
{
613
387k
  static cpu_desc_list *cd_list = 0;
614
387k
  cpu_desc_list *cl = 0;
615
387k
  static CGEN_CPU_DESC cd = 0;
616
387k
  static CGEN_BITSET *prev_isa;
617
387k
  static int prev_mach;
618
387k
  static int prev_endian;
619
387k
  static int prev_insn_endian;
620
387k
  int length;
621
387k
  CGEN_BITSET *isa;
622
387k
  int mach;
623
387k
  int endian = (info->endian == BFD_ENDIAN_BIG
624
387k
    ? CGEN_ENDIAN_BIG
625
387k
    : CGEN_ENDIAN_LITTLE);
626
387k
  int insn_endian = (info->endian_code == BFD_ENDIAN_BIG
627
387k
                     ? CGEN_ENDIAN_BIG
628
387k
                     : CGEN_ENDIAN_LITTLE);
629
387k
  enum bfd_architecture arch;
630
631
  /* ??? gdb will set mach but leave the architecture as "unknown" */
632
387k
#ifndef CGEN_BFD_ARCH
633
387k
#define CGEN_BFD_ARCH bfd_arch_fr30
634
387k
#endif
635
387k
  arch = info->arch;
636
387k
  if (arch == bfd_arch_unknown)
637
0
    arch = CGEN_BFD_ARCH;
638
639
  /* There's no standard way to compute the machine or isa number
640
     so we leave it to the target.  */
641
#ifdef CGEN_COMPUTE_MACH
642
  mach = CGEN_COMPUTE_MACH (info);
643
#else
644
387k
  mach = info->mach;
645
387k
#endif
646
647
#ifdef CGEN_COMPUTE_ISA
648
  {
649
    static CGEN_BITSET *permanent_isa;
650
651
    if (!permanent_isa)
652
      permanent_isa = cgen_bitset_create (MAX_ISAS);
653
    isa = permanent_isa;
654
    cgen_bitset_clear (isa);
655
    cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
656
  }
657
#else
658
387k
  isa = info->private_data;
659
387k
#endif
660
661
  /* If we've switched cpu's, try to find a handle we've used before */
662
387k
  if (cd
663
387k
      && (cgen_bitset_compare (isa, prev_isa) != 0
664
387k
    || mach != prev_mach
665
265k
    || endian != prev_endian))
666
122k
    {
667
122k
      cd = 0;
668
244k
      for (cl = cd_list; cl; cl = cl->next)
669
244k
  {
670
244k
    if (cgen_bitset_compare (cl->isa, isa) == 0 &&
671
244k
        cl->mach == mach &&
672
122k
        cl->endian == endian)
673
122k
      {
674
122k
        cd = cl->cd;
675
122k
        prev_isa = cd->isas;
676
122k
        break;
677
122k
      }
678
244k
  }
679
122k
    }
680
681
  /* If we haven't initialized yet, initialize the opcode table.  */
682
387k
  if (! cd)
683
3
    {
684
3
      const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
685
3
      const char *mach_name;
686
687
3
      if (!arch_type)
688
0
  abort ();
689
3
      mach_name = arch_type->printable_name;
690
691
3
      prev_isa = cgen_bitset_copy (isa);
692
3
      prev_mach = mach;
693
3
      prev_endian = endian;
694
3
      prev_insn_endian = insn_endian;
695
3
      cd = fr30_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
696
3
         CGEN_CPU_OPEN_BFDMACH, mach_name,
697
3
         CGEN_CPU_OPEN_ENDIAN, prev_endian,
698
3
                                 CGEN_CPU_OPEN_INSN_ENDIAN, prev_insn_endian,
699
3
         CGEN_CPU_OPEN_END);
700
3
      if (!cd)
701
0
  abort ();
702
703
      /* Save this away for future reference.  */
704
3
      cl = xmalloc (sizeof (struct cpu_desc_list));
705
3
      cl->cd = cd;
706
3
      cl->isa = prev_isa;
707
3
      cl->mach = mach;
708
3
      cl->endian = endian;
709
3
      cl->next = cd_list;
710
3
      cd_list = cl;
711
712
3
      fr30_cgen_init_dis (cd);
713
3
    }
714
715
  /* We try to have as much common code as possible.
716
     But at this point some targets need to take over.  */
717
  /* ??? Some targets may need a hook elsewhere.  Try to avoid this,
718
     but if not possible try to move this hook elsewhere rather than
719
     have two hooks.  */
720
387k
  length = CGEN_PRINT_INSN (cd, pc, info);
721
387k
  if (length > 0)
722
307k
    return length;
723
80.5k
  if (length < 0)
724
83
    return -1;
725
726
80.4k
  (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
727
80.4k
  return cd->default_insn_bitsize / 8;
728
80.5k
}