Coverage Report

Created: 2023-08-28 06:31

/src/binutils-gdb/opcodes/disassemble.c
Line
Count
Source (jump to first uncovered line)
1
/* Select disassembly routine for specified architecture.
2
   Copyright (C) 1994-2023 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
6
   This library is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include "disassemble.h"
23
#include "safe-ctype.h"
24
#include "opintl.h"
25
26
#ifdef ARCH_all
27
#ifdef BFD64
28
#define ARCH_aarch64
29
#define ARCH_alpha
30
#define ARCH_bpf
31
#define ARCH_ia64
32
#define ARCH_loongarch
33
#define ARCH_mips
34
#define ARCH_mmix
35
#define ARCH_nfp
36
#define ARCH_riscv
37
#define ARCH_score
38
#define ARCH_tilegx
39
#endif
40
#define ARCH_arc
41
#define ARCH_arm
42
#define ARCH_avr
43
#define ARCH_bfin
44
#define ARCH_cr16
45
#define ARCH_cris
46
#define ARCH_crx
47
#define ARCH_csky
48
#define ARCH_d10v
49
#define ARCH_d30v
50
#define ARCH_dlx
51
#define ARCH_epiphany
52
#define ARCH_fr30
53
#define ARCH_frv
54
#define ARCH_ft32
55
#define ARCH_h8300
56
#define ARCH_hppa
57
#define ARCH_i386
58
#define ARCH_ip2k
59
#define ARCH_iq2000
60
#define ARCH_kvx
61
#define ARCH_lm32
62
#define ARCH_m32c
63
#define ARCH_m32r
64
#define ARCH_m68hc11
65
#define ARCH_m68hc12
66
#define ARCH_m68k
67
#define ARCH_mcore
68
#define ARCH_mep
69
#define ARCH_metag
70
#define ARCH_microblaze
71
#define ARCH_mn10200
72
#define ARCH_mn10300
73
#define ARCH_moxie
74
#define ARCH_mt
75
#define ARCH_msp430
76
#define ARCH_nds32
77
#define ARCH_nios2
78
#define ARCH_ns32k
79
#define ARCH_or1k
80
#define ARCH_pdp11
81
#define ARCH_pj
82
#define ARCH_powerpc
83
#define ARCH_pru
84
#define ARCH_rs6000
85
#define ARCH_rl78
86
#define ARCH_rx
87
#define ARCH_s12z
88
#define ARCH_s390
89
#define ARCH_sh
90
#define ARCH_sparc
91
#define ARCH_spu
92
#define ARCH_tic30
93
#define ARCH_tic4x
94
#define ARCH_tic54x
95
#define ARCH_tic6x
96
#define ARCH_tilepro
97
#define ARCH_v850
98
#define ARCH_vax
99
#define ARCH_visium
100
#define ARCH_wasm32
101
#define ARCH_xstormy16
102
#define ARCH_xgate
103
#define ARCH_xtensa
104
#define ARCH_z80
105
#define ARCH_z8k
106
#endif
107
108
#ifdef ARCH_m32c
109
#include "m32c-desc.h"
110
#endif
111
112
disassembler_ftype
113
disassembler (enum bfd_architecture a,
114
        bool big ATTRIBUTE_UNUSED,
115
        unsigned long mach ATTRIBUTE_UNUSED,
116
        bfd *abfd ATTRIBUTE_UNUSED)
117
83.1k
{
118
83.1k
  disassembler_ftype disassemble;
119
120
83.1k
  switch (a)
121
83.1k
    {
122
      /* If you add a case to this table, also add it to the
123
   ARCH_all definition right above this function.  */
124
0
#ifdef ARCH_aarch64
125
8.81k
    case bfd_arch_aarch64:
126
8.81k
      disassemble = print_insn_aarch64;
127
8.81k
      break;
128
0
#endif
129
0
#ifdef ARCH_alpha
130
247
    case bfd_arch_alpha:
131
247
      disassemble = print_insn_alpha;
132
247
      break;
133
0
#endif
134
0
#ifdef ARCH_arc
135
2.92k
    case bfd_arch_arc:
136
2.92k
      disassemble = arc_get_disassembler (abfd);
137
2.92k
      break;
138
0
#endif
139
0
#ifdef ARCH_arm
140
19.0k
    case bfd_arch_arm:
141
19.0k
      if (big)
142
9.40k
  disassemble = print_insn_big_arm;
143
9.60k
      else
144
9.60k
  disassemble = print_insn_little_arm;
145
19.0k
      break;
146
0
#endif
147
0
#ifdef ARCH_avr
148
139
    case bfd_arch_avr:
149
139
      disassemble = print_insn_avr;
150
139
      break;
151
0
#endif
152
0
#ifdef ARCH_bfin
153
1.18k
    case bfd_arch_bfin:
154
1.18k
      disassemble = print_insn_bfin;
155
1.18k
      break;
156
0
#endif
157
0
#ifdef ARCH_cr16
158
159
    case bfd_arch_cr16:
159
159
      disassemble = print_insn_cr16;
160
159
      break;
161
0
#endif
162
0
#ifdef ARCH_cris
163
278
    case bfd_arch_cris:
164
278
      disassemble = cris_get_disassembler (abfd);
165
278
      break;
166
0
#endif
167
0
#ifdef ARCH_crx
168
151
    case bfd_arch_crx:
169
151
      disassemble = print_insn_crx;
170
151
      break;
171
0
#endif
172
0
#ifdef ARCH_csky
173
1.06k
    case bfd_arch_csky:
174
1.06k
      disassemble = csky_get_disassembler (abfd);
175
1.06k
      break;
176
0
#endif
177
178
0
#ifdef ARCH_d10v
179
163
    case bfd_arch_d10v:
180
163
      disassemble = print_insn_d10v;
181
163
      break;
182
0
#endif
183
0
#ifdef ARCH_d30v
184
281
    case bfd_arch_d30v:
185
281
      disassemble = print_insn_d30v;
186
281
      break;
187
0
#endif
188
0
#ifdef ARCH_dlx
189
68
    case bfd_arch_dlx:
190
      /* As far as I know we only handle big-endian DLX objects.  */
191
68
      disassemble = print_insn_dlx;
192
68
      break;
193
0
#endif
194
0
#ifdef ARCH_h8300
195
429
    case bfd_arch_h8300:
196
429
      if (mach == bfd_mach_h8300h || mach == bfd_mach_h8300hn)
197
34
  disassemble = print_insn_h8300h;
198
395
      else if (mach == bfd_mach_h8300s
199
395
         || mach == bfd_mach_h8300sn
200
395
         || mach == bfd_mach_h8300sx
201
395
         || mach == bfd_mach_h8300sxn)
202
31
  disassemble = print_insn_h8300s;
203
364
      else
204
364
  disassemble = print_insn_h8300;
205
429
      break;
206
0
#endif
207
0
#ifdef ARCH_hppa
208
520
    case bfd_arch_hppa:
209
520
      disassemble = print_insn_hppa;
210
520
      break;
211
0
#endif
212
0
#ifdef ARCH_i386
213
12.8k
    case bfd_arch_i386:
214
12.9k
    case bfd_arch_iamcu:
215
12.9k
      disassemble = print_insn_i386;
216
12.9k
      break;
217
0
#endif
218
0
#ifdef ARCH_ia64
219
398
    case bfd_arch_ia64:
220
398
      disassemble = print_insn_ia64;
221
398
      break;
222
0
#endif
223
0
#ifdef ARCH_ip2k
224
106
    case bfd_arch_ip2k:
225
106
      disassemble = print_insn_ip2k;
226
106
      break;
227
0
#endif
228
0
#ifdef ARCH_bpf
229
43
    case bfd_arch_bpf:
230
43
      disassemble = print_insn_bpf;
231
43
      break;
232
0
#endif
233
0
#ifdef ARCH_epiphany
234
113
    case bfd_arch_epiphany:
235
113
      disassemble = print_insn_epiphany;
236
113
      break;
237
0
#endif
238
0
#ifdef ARCH_fr30
239
207
    case bfd_arch_fr30:
240
207
      disassemble = print_insn_fr30;
241
207
      break;
242
0
#endif
243
0
#ifdef ARCH_kvx
244
161
    case bfd_arch_kvx:
245
161
      disassemble = print_insn_kvx;
246
161
      break;
247
0
#endif
248
0
#ifdef ARCH_lm32
249
141
    case bfd_arch_lm32:
250
141
      disassemble = print_insn_lm32;
251
141
      break;
252
0
#endif
253
0
#ifdef ARCH_m32r
254
239
    case bfd_arch_m32r:
255
239
      disassemble = print_insn_m32r;
256
239
      break;
257
0
#endif
258
0
#if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
259
0
    || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
260
52
    case bfd_arch_m68hc11:
261
52
      disassemble = print_insn_m68hc11;
262
52
      break;
263
162
    case bfd_arch_m68hc12:
264
162
      disassemble = print_insn_m68hc12;
265
162
      break;
266
124
    case bfd_arch_m9s12x:
267
124
      disassemble = print_insn_m9s12x;
268
124
      break;
269
50
    case bfd_arch_m9s12xg:
270
50
      disassemble = print_insn_m9s12xg;
271
50
      break;
272
0
#endif
273
0
#if defined(ARCH_s12z)
274
350
    case bfd_arch_s12z:
275
350
      disassemble = print_insn_s12z;
276
350
      break;
277
0
#endif
278
0
#ifdef ARCH_m68k
279
809
    case bfd_arch_m68k:
280
809
      disassemble = print_insn_m68k;
281
809
      break;
282
0
#endif
283
0
#ifdef ARCH_mt
284
185
    case bfd_arch_mt:
285
185
      disassemble = print_insn_mt;
286
185
      break;
287
0
#endif
288
0
#ifdef ARCH_microblaze
289
131
    case bfd_arch_microblaze:
290
131
      disassemble = print_insn_microblaze;
291
131
      break;
292
0
#endif
293
0
#ifdef ARCH_msp430
294
331
    case bfd_arch_msp430:
295
331
      disassemble = print_insn_msp430;
296
331
      break;
297
0
#endif
298
0
#ifdef ARCH_nds32
299
802
    case bfd_arch_nds32:
300
802
      disassemble = print_insn_nds32;
301
802
      break;
302
0
#endif
303
0
#ifdef ARCH_nfp
304
254
    case bfd_arch_nfp:
305
254
      disassemble = print_insn_nfp;
306
254
      break;
307
0
#endif
308
0
#ifdef ARCH_ns32k
309
810
    case bfd_arch_ns32k:
310
810
      disassemble = print_insn_ns32k;
311
810
      break;
312
0
#endif
313
0
#ifdef ARCH_mcore
314
288
    case bfd_arch_mcore:
315
288
      disassemble = print_insn_mcore;
316
288
      break;
317
0
#endif
318
0
#ifdef ARCH_mep
319
237
    case bfd_arch_mep:
320
237
      disassemble = print_insn_mep;
321
237
      break;
322
0
#endif
323
0
#ifdef ARCH_metag
324
1.50k
    case bfd_arch_metag:
325
1.50k
      disassemble = print_insn_metag;
326
1.50k
      break;
327
0
#endif
328
0
#ifdef ARCH_mips
329
7.65k
    case bfd_arch_mips:
330
7.65k
      if (big)
331
3.42k
  disassemble = print_insn_big_mips;
332
4.23k
      else
333
4.23k
  disassemble = print_insn_little_mips;
334
7.65k
      break;
335
0
#endif
336
0
#ifdef ARCH_mmix
337
120
    case bfd_arch_mmix:
338
120
      disassemble = print_insn_mmix;
339
120
      break;
340
0
#endif
341
0
#ifdef ARCH_mn10200
342
143
    case bfd_arch_mn10200:
343
143
      disassemble = print_insn_mn10200;
344
143
      break;
345
0
#endif
346
0
#ifdef ARCH_mn10300
347
256
    case bfd_arch_mn10300:
348
256
      disassemble = print_insn_mn10300;
349
256
      break;
350
0
#endif
351
0
#ifdef ARCH_nios2
352
169
    case bfd_arch_nios2:
353
169
      if (big)
354
84
  disassemble = print_insn_big_nios2;
355
85
      else
356
85
  disassemble = print_insn_little_nios2;
357
169
      break;
358
0
#endif
359
0
#ifdef ARCH_or1k
360
131
    case bfd_arch_or1k:
361
131
      disassemble = print_insn_or1k;
362
131
      break;
363
0
#endif
364
0
#ifdef ARCH_pdp11
365
499
    case bfd_arch_pdp11:
366
499
      disassemble = print_insn_pdp11;
367
499
      break;
368
0
#endif
369
0
#ifdef ARCH_pj
370
0
    case bfd_arch_pj:
371
0
      disassemble = print_insn_pj;
372
0
      break;
373
0
#endif
374
0
#ifdef ARCH_powerpc
375
689
    case bfd_arch_powerpc:
376
689
#endif
377
689
#ifdef ARCH_rs6000
378
1.01k
    case bfd_arch_rs6000:
379
1.01k
#endif
380
1.01k
#if defined ARCH_powerpc || defined ARCH_rs6000
381
1.01k
      if (big)
382
599
  disassemble = print_insn_big_powerpc;
383
415
      else
384
415
  disassemble = print_insn_little_powerpc;
385
1.01k
      break;
386
0
#endif
387
0
#ifdef ARCH_pru
388
69
    case bfd_arch_pru:
389
69
      disassemble = print_insn_pru;
390
69
      break;
391
0
#endif
392
0
#ifdef ARCH_riscv
393
676
    case bfd_arch_riscv:
394
676
      disassemble = riscv_get_disassembler (abfd);
395
676
      break;
396
0
#endif
397
0
#ifdef ARCH_rl78
398
1.43k
    case bfd_arch_rl78:
399
1.43k
      disassemble = rl78_get_disassembler (abfd);
400
1.43k
      break;
401
0
#endif
402
0
#ifdef ARCH_rx
403
5.67k
    case bfd_arch_rx:
404
5.67k
      disassemble = print_insn_rx;
405
5.67k
      break;
406
0
#endif
407
0
#ifdef ARCH_s390
408
161
    case bfd_arch_s390:
409
161
      disassemble = print_insn_s390;
410
161
      break;
411
0
#endif
412
0
#ifdef ARCH_score
413
440
    case bfd_arch_score:
414
440
      if (big)
415
197
  disassemble = print_insn_big_score;
416
243
      else
417
243
  disassemble = print_insn_little_score;
418
440
     break;
419
0
#endif
420
0
#ifdef ARCH_sh
421
962
    case bfd_arch_sh:
422
962
      disassemble = print_insn_sh;
423
962
      break;
424
0
#endif
425
0
#ifdef ARCH_sparc
426
347
    case bfd_arch_sparc:
427
347
      disassemble = print_insn_sparc;
428
347
      break;
429
0
#endif
430
0
#ifdef ARCH_spu
431
225
    case bfd_arch_spu:
432
225
      disassemble = print_insn_spu;
433
225
      break;
434
0
#endif
435
0
#ifdef ARCH_tic30
436
439
    case bfd_arch_tic30:
437
439
      disassemble = print_insn_tic30;
438
439
      break;
439
0
#endif
440
0
#ifdef ARCH_tic4x
441
237
    case bfd_arch_tic4x:
442
237
      disassemble = print_insn_tic4x;
443
237
      break;
444
0
#endif
445
0
#ifdef ARCH_tic54x
446
453
    case bfd_arch_tic54x:
447
453
      disassemble = print_insn_tic54x;
448
453
      break;
449
0
#endif
450
0
#ifdef ARCH_tic6x
451
320
    case bfd_arch_tic6x:
452
320
      disassemble = print_insn_tic6x;
453
320
      break;
454
0
#endif
455
0
#ifdef ARCH_ft32
456
108
    case bfd_arch_ft32:
457
108
      disassemble = print_insn_ft32;
458
108
      break;
459
0
#endif
460
0
#ifdef ARCH_v850
461
258
    case bfd_arch_v850:
462
274
    case bfd_arch_v850_rh850:
463
274
      disassemble = print_insn_v850;
464
274
      break;
465
0
#endif
466
0
#ifdef ARCH_wasm32
467
196
    case bfd_arch_wasm32:
468
196
      disassemble = print_insn_wasm32;
469
196
      break;
470
0
#endif
471
0
#ifdef ARCH_xgate
472
118
    case bfd_arch_xgate:
473
118
      disassemble = print_insn_xgate;
474
118
      break;
475
0
#endif
476
0
#ifdef ARCH_xstormy16
477
93
    case bfd_arch_xstormy16:
478
93
      disassemble = print_insn_xstormy16;
479
93
      break;
480
0
#endif
481
0
#ifdef ARCH_xtensa
482
1.96k
    case bfd_arch_xtensa:
483
1.96k
      disassemble = print_insn_xtensa;
484
1.96k
      break;
485
0
#endif
486
0
#ifdef ARCH_z80
487
295
    case bfd_arch_z80:
488
295
      disassemble = print_insn_z80;
489
295
      break;
490
0
#endif
491
0
#ifdef ARCH_z8k
492
366
    case bfd_arch_z8k:
493
366
      if (mach == bfd_mach_z8001)
494
250
  disassemble = print_insn_z8001;
495
116
      else
496
116
  disassemble = print_insn_z8002;
497
366
      break;
498
0
#endif
499
0
#ifdef ARCH_vax
500
394
    case bfd_arch_vax:
501
394
      disassemble = print_insn_vax;
502
394
      break;
503
0
#endif
504
0
#ifdef ARCH_visium
505
301
     case bfd_arch_visium:
506
301
       disassemble = print_insn_visium;
507
301
       break;
508
0
#endif
509
0
#ifdef ARCH_frv
510
199
    case bfd_arch_frv:
511
199
      disassemble = print_insn_frv;
512
199
      break;
513
0
#endif
514
0
#ifdef ARCH_moxie
515
89
    case bfd_arch_moxie:
516
89
      disassemble = print_insn_moxie;
517
89
      break;
518
0
#endif
519
0
#ifdef ARCH_iq2000
520
89
    case bfd_arch_iq2000:
521
89
      disassemble = print_insn_iq2000;
522
89
      break;
523
0
#endif
524
0
#ifdef ARCH_m32c
525
333
    case bfd_arch_m32c:
526
333
      disassemble = print_insn_m32c;
527
333
      break;
528
0
#endif
529
0
#ifdef ARCH_tilegx
530
250
    case bfd_arch_tilegx:
531
250
      disassemble = print_insn_tilegx;
532
250
      break;
533
0
#endif
534
0
#ifdef ARCH_tilepro
535
105
    case bfd_arch_tilepro:
536
105
      disassemble = print_insn_tilepro;
537
105
      break;
538
0
#endif
539
0
#ifdef ARCH_loongarch
540
217
    case bfd_arch_loongarch:
541
217
      disassemble = print_insn_loongarch;
542
217
      break;
543
0
#endif
544
459
    default:
545
459
      return 0;
546
83.1k
    }
547
82.6k
  return disassemble;
548
83.1k
}
549
550
void
551
disassembler_usage (FILE *stream ATTRIBUTE_UNUSED)
552
0
{
553
0
#ifdef ARCH_aarch64
554
0
  print_aarch64_disassembler_options (stream);
555
0
#endif
556
0
#ifdef ARCH_arc
557
0
  print_arc_disassembler_options (stream);
558
0
#endif
559
0
#ifdef ARCH_arm
560
0
  print_arm_disassembler_options (stream);
561
0
#endif
562
0
#ifdef ARCH_mips
563
0
  print_mips_disassembler_options (stream);
564
0
#endif
565
0
#ifdef ARCH_nfp
566
0
  print_nfp_disassembler_options (stream);
567
0
#endif
568
0
#ifdef ARCH_powerpc
569
0
  print_ppc_disassembler_options (stream);
570
0
#endif
571
0
#ifdef ARCH_riscv
572
0
  print_riscv_disassembler_options (stream);
573
0
#endif
574
0
#ifdef ARCH_i386
575
0
  print_i386_disassembler_options (stream);
576
0
#endif
577
0
#ifdef ARCH_kvx
578
0
  print_kvx_disassembler_options (stream);
579
0
#endif
580
0
#ifdef ARCH_s390
581
0
  print_s390_disassembler_options (stream);
582
0
#endif
583
0
#ifdef ARCH_wasm32
584
0
  print_wasm32_disassembler_options (stream);
585
0
#endif
586
0
#ifdef ARCH_loongarch
587
0
  print_loongarch_disassembler_options (stream);
588
0
#endif
589
0
#ifdef ARCH_bpf
590
0
  print_bpf_disassembler_options (stream);
591
0
#endif
592
0
  return;
593
0
}
594
595
void
596
disassemble_init_for_target (struct disassemble_info * info)
597
82.6k
{
598
82.6k
  if (info == NULL)
599
0
    return;
600
601
82.6k
  switch (info->arch)
602
82.6k
    {
603
0
#ifdef ARCH_aarch64
604
8.81k
    case bfd_arch_aarch64:
605
8.81k
      info->symbol_is_valid = aarch64_symbol_is_valid;
606
8.81k
      info->disassembler_needs_relocs = true;
607
8.81k
      info->created_styled_output = true;
608
8.81k
      break;
609
0
#endif
610
0
#ifdef ARCH_arc
611
2.92k
    case bfd_arch_arc:
612
2.92k
      info->created_styled_output = true;
613
2.92k
      break;
614
0
#endif
615
0
#ifdef ARCH_arm
616
19.0k
    case bfd_arch_arm:
617
19.0k
      info->symbol_is_valid = arm_symbol_is_valid;
618
19.0k
      info->disassembler_needs_relocs = true;
619
19.0k
      info->created_styled_output = true;
620
19.0k
      break;
621
0
#endif
622
0
#ifdef ARCH_avr
623
139
    case bfd_arch_avr:
624
139
      info->created_styled_output = true;
625
139
      break;
626
0
#endif
627
0
#ifdef ARCH_csky
628
1.06k
    case bfd_arch_csky:
629
1.06k
      info->symbol_is_valid = csky_symbol_is_valid;
630
1.06k
      info->disassembler_needs_relocs = true;
631
1.06k
      break;
632
0
#endif
633
0
#ifdef ARCH_i386
634
12.8k
    case bfd_arch_i386:
635
12.9k
    case bfd_arch_iamcu:
636
12.9k
      info->created_styled_output = true;
637
12.9k
      break;
638
0
#endif
639
0
#ifdef ARCH_ia64
640
398
    case bfd_arch_ia64:
641
398
      info->skip_zeroes = 16;
642
398
      break;
643
0
#endif
644
0
#ifdef ARCH_loongarch
645
217
    case bfd_arch_loongarch:
646
217
      info->created_styled_output = true;
647
217
      break;
648
0
#endif
649
0
#ifdef ARCH_tic4x
650
237
    case bfd_arch_tic4x:
651
237
      info->skip_zeroes = 32;
652
237
      break;
653
0
#endif
654
0
#ifdef ARCH_m68k
655
809
    case bfd_arch_m68k:
656
809
      info->created_styled_output = true;
657
809
      break;
658
0
#endif
659
0
#ifdef ARCH_mep
660
237
    case bfd_arch_mep:
661
237
      info->skip_zeroes = 256;
662
237
      info->skip_zeroes_at_end = 0;
663
237
      break;
664
0
#endif
665
0
#ifdef ARCH_metag
666
1.50k
    case bfd_arch_metag:
667
1.50k
      info->disassembler_needs_relocs = true;
668
1.50k
      break;
669
0
#endif
670
0
#ifdef ARCH_mips
671
7.65k
    case bfd_arch_mips:
672
7.65k
      info->created_styled_output = true;
673
7.65k
      break;
674
0
#endif
675
0
#ifdef ARCH_m32c
676
333
    case bfd_arch_m32c:
677
      /* This processor in fact is little endian.  The value set here
678
   reflects the way opcodes are written in the cgen description.  */
679
333
      info->endian = BFD_ENDIAN_BIG;
680
333
      if (!info->private_data)
681
333
  {
682
333
    info->private_data = cgen_bitset_create (ISA_MAX);
683
333
    if (info->mach == bfd_mach_m16c)
684
93
      cgen_bitset_set (info->private_data, ISA_M16C);
685
240
    else
686
240
      cgen_bitset_set (info->private_data, ISA_M32C);
687
333
  }
688
333
      break;
689
0
#endif
690
0
#ifdef ARCH_bpf
691
43
    case bfd_arch_bpf:
692
43
      info->created_styled_output = true;
693
43
      break;
694
0
#endif
695
0
#ifdef ARCH_pru
696
69
    case bfd_arch_pru:
697
69
      info->disassembler_needs_relocs = true;
698
69
      break;
699
0
#endif
700
0
#ifdef ARCH_powerpc
701
689
    case bfd_arch_powerpc:
702
689
#endif
703
689
#ifdef ARCH_rs6000
704
1.01k
    case bfd_arch_rs6000:
705
1.01k
#endif
706
1.01k
#if defined (ARCH_powerpc) || defined (ARCH_rs6000)
707
1.01k
      disassemble_init_powerpc (info);
708
1.01k
      info->created_styled_output = true;
709
1.01k
      break;
710
0
#endif
711
0
#ifdef ARCH_riscv
712
676
    case bfd_arch_riscv:
713
676
      info->symbol_is_valid = riscv_symbol_is_valid;
714
676
      info->created_styled_output = true;
715
676
      break;
716
0
#endif
717
0
#ifdef ARCH_wasm32
718
196
    case bfd_arch_wasm32:
719
196
      disassemble_init_wasm32 (info);
720
196
      break;
721
0
#endif
722
0
#ifdef ARCH_s390
723
161
    case bfd_arch_s390:
724
161
      disassemble_init_s390 (info);
725
161
      info->created_styled_output = true;
726
161
      break;
727
0
#endif
728
0
#ifdef ARCH_nds32
729
802
    case bfd_arch_nds32:
730
802
      disassemble_init_nds32 (info);
731
802
      break;
732
0
 #endif
733
23.4k
    default:
734
23.4k
      break;
735
82.6k
    }
736
82.6k
}
737
738
void
739
disassemble_free_target (struct disassemble_info *info)
740
82.6k
{
741
82.6k
  if (info == NULL)
742
0
    return;
743
744
82.6k
  switch (info->arch)
745
82.6k
    {
746
77.0k
    default:
747
77.0k
      return;
748
749
77.0k
#ifdef ARCH_m32c
750
77.0k
    case bfd_arch_m32c:
751
333
#endif
752
333
#if defined ARCH_m32c
753
333
      if (info->private_data)
754
333
  {
755
333
    CGEN_BITSET *mask = info->private_data;
756
333
    free (mask->bits);
757
333
  }
758
333
      break;
759
0
#endif
760
761
0
#ifdef ARCH_arc
762
2.92k
    case bfd_arch_arc:
763
2.92k
      break;
764
0
#endif
765
0
#ifdef ARCH_cris
766
278
    case bfd_arch_cris:
767
278
      break;
768
0
#endif
769
0
#ifdef ARCH_mmix
770
120
    case bfd_arch_mmix:
771
120
      break;
772
0
#endif
773
0
#ifdef ARCH_nfp
774
254
    case bfd_arch_nfp:
775
254
      break;
776
0
#endif
777
0
#ifdef ARCH_powerpc
778
689
    case bfd_arch_powerpc:
779
689
      break;
780
0
#endif
781
0
#ifdef ARCH_riscv
782
676
    case bfd_arch_riscv:
783
676
      disassemble_free_riscv (info);
784
676
      break;
785
0
#endif
786
0
#ifdef ARCH_rs6000
787
325
    case bfd_arch_rs6000:
788
325
      break;
789
82.6k
#endif
790
82.6k
    }
791
792
5.59k
  free (info->private_data);
793
5.59k
}
794
795
/* Remove whitespace and consecutive commas from OPTIONS.  */
796
797
char *
798
remove_whitespace_and_extra_commas (char *options)
799
0
{
800
0
  char *str;
801
0
  size_t i, len;
802
803
0
  if (options == NULL)
804
0
    return NULL;
805
806
  /* Strip off all trailing whitespace and commas.  */
807
0
  for (len = strlen (options); len > 0; len--)
808
0
    {
809
0
      if (!ISSPACE (options[len - 1]) && options[len - 1] != ',')
810
0
  break;
811
0
      options[len - 1] = '\0';
812
0
    }
813
814
  /* Convert all remaining whitespace to commas.  */
815
0
  for (i = 0; options[i] != '\0'; i++)
816
0
    if (ISSPACE (options[i]))
817
0
      options[i] = ',';
818
819
  /* Remove consecutive commas.  */
820
0
  for (str = options; *str != '\0'; str++)
821
0
    if (*str == ',' && (*(str + 1) == ',' || str == options))
822
0
      {
823
0
  char *next = str + 1;
824
0
  while (*next == ',')
825
0
    next++;
826
0
  len = strlen (next);
827
0
  if (str != options)
828
0
    str++;
829
0
  memmove (str, next, len);
830
0
  next[len - (size_t)(next - str)] = '\0';
831
0
      }
832
0
  return (strlen (options) != 0) ? options : NULL;
833
0
}
834
835
/* Like STRCMP, but treat ',' the same as '\0' so that we match
836
   strings like "foobar" against "foobar,xxyyzz,...".  */
837
838
int
839
disassembler_options_cmp (const char *s1, const char *s2)
840
129k
{
841
129k
  unsigned char c1, c2;
842
843
129k
  do
844
177k
    {
845
177k
      c1 = (unsigned char) *s1++;
846
177k
      if (c1 == ',')
847
23.8k
  c1 = '\0';
848
177k
      c2 = (unsigned char) *s2++;
849
177k
      if (c2 == ',')
850
1.44k
  c2 = '\0';
851
177k
      if (c1 == '\0')
852
28.3k
  return c1 - c2;
853
177k
    }
854
149k
  while (c1 == c2);
855
856
101k
  return c1 - c2;
857
129k
}
858
859
void
860
opcodes_assert (const char *file, int line)
861
0
{
862
0
  opcodes_error_handler (_("assertion fail %s:%d"), file, line);
863
0
  opcodes_error_handler (_("Please report this bug"));
864
0
  abort ();
865
0
}
866
867
/* Set the stream, and the styled and unstyled printf functions within
868
   INFO.  */
869
870
void
871
disassemble_set_printf (struct disassemble_info *info, void *stream,
872
      fprintf_ftype unstyled_printf,
873
      fprintf_styled_ftype styled_printf)
874
184M
{
875
184M
  info->stream = stream;
876
184M
  info->fprintf_func = unstyled_printf;
877
184M
  info->fprintf_styled_func = styled_printf;
878
184M
}