disassemble.c 18 KB

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