disassemble.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /* Select disassembly routine for specified architecture.
  2. Copyright (C) 1994-2015 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 "dis-asm.h"
  18. #ifdef ARCH_all
  19. #define ARCH_aarch64
  20. #define ARCH_alpha
  21. #define ARCH_arc
  22. #define ARCH_arm
  23. #define ARCH_avr
  24. #define ARCH_bfin
  25. #define ARCH_cr16
  26. #define ARCH_cris
  27. #define ARCH_crx
  28. #define ARCH_d10v
  29. #define ARCH_d30v
  30. #define ARCH_dlx
  31. #define ARCH_epiphany
  32. #define ARCH_fr30
  33. #define ARCH_frv
  34. #define ARCH_ft32
  35. #define ARCH_h8300
  36. #define ARCH_h8500
  37. #define ARCH_hppa
  38. #define ARCH_i370
  39. #define ARCH_i386
  40. #define ARCH_i860
  41. #define ARCH_i960
  42. #define ARCH_ia64
  43. #define ARCH_ip2k
  44. #define ARCH_iq2000
  45. #define ARCH_lm32
  46. #define ARCH_m32c
  47. #define ARCH_m32r
  48. #define ARCH_m68hc11
  49. #define ARCH_m68hc12
  50. #define ARCH_m68k
  51. #define ARCH_m88k
  52. #define ARCH_mcore
  53. #define ARCH_mep
  54. #define ARCH_metag
  55. #define ARCH_microblaze
  56. #define ARCH_mips
  57. #define ARCH_mmix
  58. #define ARCH_mn10200
  59. #define ARCH_mn10300
  60. #define ARCH_moxie
  61. #define ARCH_mt
  62. #define ARCH_msp430
  63. #define ARCH_nds32
  64. #define ARCH_nios2
  65. #define ARCH_ns32k
  66. #define ARCH_or1k
  67. #define ARCH_pdp11
  68. #define ARCH_pj
  69. #define ARCH_powerpc
  70. #define ARCH_rs6000
  71. #define ARCH_rl78
  72. #define ARCH_rx
  73. #define ARCH_s390
  74. #define ARCH_score
  75. #define ARCH_sh
  76. #define ARCH_sparc
  77. #define ARCH_spu
  78. #define ARCH_tic30
  79. #define ARCH_tic4x
  80. #define ARCH_tic54x
  81. #define ARCH_tic6x
  82. #define ARCH_tic80
  83. #define ARCH_tilegx
  84. #define ARCH_tilepro
  85. #define ARCH_v850
  86. #define ARCH_vax
  87. #define ARCH_visium
  88. #define ARCH_w65
  89. #define ARCH_xstormy16
  90. #define ARCH_xc16x
  91. #define ARCH_xgate
  92. #define ARCH_xtensa
  93. #define ARCH_z80
  94. #define ARCH_z8k
  95. #define INCLUDE_SHMEDIA
  96. #endif
  97. #ifdef ARCH_m32c
  98. #include "m32c-desc.h"
  99. #endif
  100. disassembler_ftype
  101. disassembler (abfd)
  102. bfd *abfd;
  103. {
  104. enum bfd_architecture a = bfd_get_arch (abfd);
  105. disassembler_ftype disassemble;
  106. switch (a)
  107. {
  108. /* If you add a case to this table, also add it to the
  109. ARCH_all definition right above this function. */
  110. #ifdef ARCH_aarch64
  111. case bfd_arch_aarch64:
  112. disassemble = print_insn_aarch64;
  113. break;
  114. #endif
  115. #ifdef ARCH_alpha
  116. case bfd_arch_alpha:
  117. disassemble = print_insn_alpha;
  118. break;
  119. #endif
  120. #ifdef ARCH_arc
  121. case bfd_arch_arc:
  122. disassemble = arc_get_disassembler (abfd);
  123. break;
  124. #endif
  125. #ifdef ARCH_arm
  126. case bfd_arch_arm:
  127. if (bfd_big_endian (abfd))
  128. disassemble = print_insn_big_arm;
  129. else
  130. disassemble = print_insn_little_arm;
  131. break;
  132. #endif
  133. #ifdef ARCH_avr
  134. case bfd_arch_avr:
  135. disassemble = print_insn_avr;
  136. break;
  137. #endif
  138. #ifdef ARCH_bfin
  139. case bfd_arch_bfin:
  140. disassemble = print_insn_bfin;
  141. break;
  142. #endif
  143. #ifdef ARCH_cr16
  144. case bfd_arch_cr16:
  145. disassemble = print_insn_cr16;
  146. break;
  147. #endif
  148. #ifdef ARCH_cris
  149. case bfd_arch_cris:
  150. disassemble = cris_get_disassembler (abfd);
  151. break;
  152. #endif
  153. #ifdef ARCH_crx
  154. case bfd_arch_crx:
  155. disassemble = print_insn_crx;
  156. break;
  157. #endif
  158. #ifdef ARCH_d10v
  159. case bfd_arch_d10v:
  160. disassemble = print_insn_d10v;
  161. break;
  162. #endif
  163. #ifdef ARCH_d30v
  164. case bfd_arch_d30v:
  165. disassemble = print_insn_d30v;
  166. break;
  167. #endif
  168. #ifdef ARCH_dlx
  169. case bfd_arch_dlx:
  170. /* As far as I know we only handle big-endian DLX objects. */
  171. disassemble = print_insn_dlx;
  172. break;
  173. #endif
  174. #ifdef ARCH_h8300
  175. case bfd_arch_h8300:
  176. if (bfd_get_mach (abfd) == bfd_mach_h8300h
  177. || bfd_get_mach (abfd) == bfd_mach_h8300hn)
  178. disassemble = print_insn_h8300h;
  179. else if (bfd_get_mach (abfd) == bfd_mach_h8300s
  180. || bfd_get_mach (abfd) == bfd_mach_h8300sn
  181. || bfd_get_mach (abfd) == bfd_mach_h8300sx
  182. || bfd_get_mach (abfd) == bfd_mach_h8300sxn)
  183. disassemble = print_insn_h8300s;
  184. else
  185. disassemble = print_insn_h8300;
  186. break;
  187. #endif
  188. #ifdef ARCH_h8500
  189. case bfd_arch_h8500:
  190. disassemble = print_insn_h8500;
  191. break;
  192. #endif
  193. #ifdef ARCH_hppa
  194. case bfd_arch_hppa:
  195. disassemble = print_insn_hppa;
  196. break;
  197. #endif
  198. #ifdef ARCH_i370
  199. case bfd_arch_i370:
  200. disassemble = print_insn_i370;
  201. break;
  202. #endif
  203. #ifdef ARCH_i386
  204. case bfd_arch_i386:
  205. case bfd_arch_iamcu:
  206. case bfd_arch_l1om:
  207. case bfd_arch_k1om:
  208. disassemble = print_insn_i386;
  209. break;
  210. #endif
  211. #ifdef ARCH_i860
  212. case bfd_arch_i860:
  213. disassemble = print_insn_i860;
  214. break;
  215. #endif
  216. #ifdef ARCH_i960
  217. case bfd_arch_i960:
  218. disassemble = print_insn_i960;
  219. break;
  220. #endif
  221. #ifdef ARCH_ia64
  222. case bfd_arch_ia64:
  223. disassemble = print_insn_ia64;
  224. break;
  225. #endif
  226. #ifdef ARCH_ip2k
  227. case bfd_arch_ip2k:
  228. disassemble = print_insn_ip2k;
  229. break;
  230. #endif
  231. #ifdef ARCH_epiphany
  232. case bfd_arch_epiphany:
  233. disassemble = print_insn_epiphany;
  234. break;
  235. #endif
  236. #ifdef ARCH_fr30
  237. case bfd_arch_fr30:
  238. disassemble = print_insn_fr30;
  239. break;
  240. #endif
  241. #ifdef ARCH_lm32
  242. case bfd_arch_lm32:
  243. disassemble = print_insn_lm32;
  244. break;
  245. #endif
  246. #ifdef ARCH_m32r
  247. case bfd_arch_m32r:
  248. disassemble = print_insn_m32r;
  249. break;
  250. #endif
  251. #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
  252. || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
  253. case bfd_arch_m68hc11:
  254. disassemble = print_insn_m68hc11;
  255. break;
  256. case bfd_arch_m68hc12:
  257. disassemble = print_insn_m68hc12;
  258. break;
  259. case bfd_arch_m9s12x:
  260. disassemble = print_insn_m9s12x;
  261. break;
  262. case bfd_arch_m9s12xg:
  263. disassemble = print_insn_m9s12xg;
  264. break;
  265. #endif
  266. #ifdef ARCH_m68k
  267. case bfd_arch_m68k:
  268. disassemble = print_insn_m68k;
  269. break;
  270. #endif
  271. #ifdef ARCH_m88k
  272. case bfd_arch_m88k:
  273. disassemble = print_insn_m88k;
  274. break;
  275. #endif
  276. #ifdef ARCH_mt
  277. case bfd_arch_mt:
  278. disassemble = print_insn_mt;
  279. break;
  280. #endif
  281. #ifdef ARCH_microblaze
  282. case bfd_arch_microblaze:
  283. disassemble = print_insn_microblaze;
  284. break;
  285. #endif
  286. #ifdef ARCH_msp430
  287. case bfd_arch_msp430:
  288. disassemble = print_insn_msp430;
  289. break;
  290. #endif
  291. #ifdef ARCH_nds32
  292. case bfd_arch_nds32:
  293. disassemble = print_insn_nds32;
  294. break;
  295. #endif
  296. #ifdef ARCH_ns32k
  297. case bfd_arch_ns32k:
  298. disassemble = print_insn_ns32k;
  299. break;
  300. #endif
  301. #ifdef ARCH_mcore
  302. case bfd_arch_mcore:
  303. disassemble = print_insn_mcore;
  304. break;
  305. #endif
  306. #ifdef ARCH_mep
  307. case bfd_arch_mep:
  308. disassemble = print_insn_mep;
  309. break;
  310. #endif
  311. #ifdef ARCH_metag
  312. case bfd_arch_metag:
  313. disassemble = print_insn_metag;
  314. break;
  315. #endif
  316. #ifdef ARCH_mips
  317. case bfd_arch_mips:
  318. if (bfd_big_endian (abfd))
  319. disassemble = print_insn_big_mips;
  320. else
  321. disassemble = print_insn_little_mips;
  322. break;
  323. #endif
  324. #ifdef ARCH_mmix
  325. case bfd_arch_mmix:
  326. disassemble = print_insn_mmix;
  327. break;
  328. #endif
  329. #ifdef ARCH_mn10200
  330. case bfd_arch_mn10200:
  331. disassemble = print_insn_mn10200;
  332. break;
  333. #endif
  334. #ifdef ARCH_mn10300
  335. case bfd_arch_mn10300:
  336. disassemble = print_insn_mn10300;
  337. break;
  338. #endif
  339. #ifdef ARCH_nios2
  340. case bfd_arch_nios2:
  341. if (bfd_big_endian (abfd))
  342. disassemble = print_insn_big_nios2;
  343. else
  344. disassemble = print_insn_little_nios2;
  345. break;
  346. #endif
  347. #ifdef ARCH_or1k
  348. case bfd_arch_or1k:
  349. disassemble = print_insn_or1k;
  350. break;
  351. #endif
  352. #ifdef ARCH_pdp11
  353. case bfd_arch_pdp11:
  354. disassemble = print_insn_pdp11;
  355. break;
  356. #endif
  357. #ifdef ARCH_pj
  358. case bfd_arch_pj:
  359. disassemble = print_insn_pj;
  360. break;
  361. #endif
  362. #ifdef ARCH_powerpc
  363. case bfd_arch_powerpc:
  364. if (bfd_big_endian (abfd))
  365. disassemble = print_insn_big_powerpc;
  366. else
  367. disassemble = print_insn_little_powerpc;
  368. break;
  369. #endif
  370. #ifdef ARCH_rs6000
  371. case bfd_arch_rs6000:
  372. if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
  373. disassemble = print_insn_big_powerpc;
  374. else
  375. disassemble = print_insn_rs6000;
  376. break;
  377. #endif
  378. #ifdef ARCH_rl78
  379. case bfd_arch_rl78:
  380. disassemble = rl78_get_disassembler (abfd);
  381. break;
  382. #endif
  383. #ifdef ARCH_rx
  384. case bfd_arch_rx:
  385. disassemble = print_insn_rx;
  386. break;
  387. #endif
  388. #ifdef ARCH_s390
  389. case bfd_arch_s390:
  390. disassemble = print_insn_s390;
  391. break;
  392. #endif
  393. #ifdef ARCH_score
  394. case bfd_arch_score:
  395. if (bfd_big_endian (abfd))
  396. disassemble = print_insn_big_score;
  397. else
  398. disassemble = print_insn_little_score;
  399. break;
  400. #endif
  401. #ifdef ARCH_sh
  402. case bfd_arch_sh:
  403. disassemble = print_insn_sh;
  404. break;
  405. #endif
  406. #ifdef ARCH_sparc
  407. case bfd_arch_sparc:
  408. disassemble = print_insn_sparc;
  409. break;
  410. #endif
  411. #ifdef ARCH_spu
  412. case bfd_arch_spu:
  413. disassemble = print_insn_spu;
  414. break;
  415. #endif
  416. #ifdef ARCH_tic30
  417. case bfd_arch_tic30:
  418. disassemble = print_insn_tic30;
  419. break;
  420. #endif
  421. #ifdef ARCH_tic4x
  422. case bfd_arch_tic4x:
  423. disassemble = print_insn_tic4x;
  424. break;
  425. #endif
  426. #ifdef ARCH_tic54x
  427. case bfd_arch_tic54x:
  428. disassemble = print_insn_tic54x;
  429. break;
  430. #endif
  431. #ifdef ARCH_tic6x
  432. case bfd_arch_tic6x:
  433. disassemble = print_insn_tic6x;
  434. break;
  435. #endif
  436. #ifdef ARCH_tic80
  437. case bfd_arch_tic80:
  438. disassemble = print_insn_tic80;
  439. break;
  440. #endif
  441. #ifdef ARCH_ft32
  442. case bfd_arch_ft32:
  443. disassemble = print_insn_ft32;
  444. break;
  445. #endif
  446. #ifdef ARCH_v850
  447. case bfd_arch_v850:
  448. case bfd_arch_v850_rh850:
  449. disassemble = print_insn_v850;
  450. break;
  451. #endif
  452. #ifdef ARCH_w65
  453. case bfd_arch_w65:
  454. disassemble = print_insn_w65;
  455. break;
  456. #endif
  457. #ifdef ARCH_xgate
  458. case bfd_arch_xgate:
  459. disassemble = print_insn_xgate;
  460. break;
  461. #endif
  462. #ifdef ARCH_xstormy16
  463. case bfd_arch_xstormy16:
  464. disassemble = print_insn_xstormy16;
  465. break;
  466. #endif
  467. #ifdef ARCH_xc16x
  468. case bfd_arch_xc16x:
  469. disassemble = print_insn_xc16x;
  470. break;
  471. #endif
  472. #ifdef ARCH_xtensa
  473. case bfd_arch_xtensa:
  474. disassemble = print_insn_xtensa;
  475. break;
  476. #endif
  477. #ifdef ARCH_z80
  478. case bfd_arch_z80:
  479. disassemble = print_insn_z80;
  480. break;
  481. #endif
  482. #ifdef ARCH_z8k
  483. case bfd_arch_z8k:
  484. if (bfd_get_mach(abfd) == bfd_mach_z8001)
  485. disassemble = print_insn_z8001;
  486. else
  487. disassemble = print_insn_z8002;
  488. break;
  489. #endif
  490. #ifdef ARCH_vax
  491. case bfd_arch_vax:
  492. disassemble = print_insn_vax;
  493. break;
  494. #endif
  495. #ifdef ARCH_visium
  496. case bfd_arch_visium:
  497. disassemble = print_insn_visium;
  498. break;
  499. #endif
  500. #ifdef ARCH_frv
  501. case bfd_arch_frv:
  502. disassemble = print_insn_frv;
  503. break;
  504. #endif
  505. #ifdef ARCH_moxie
  506. case bfd_arch_moxie:
  507. disassemble = print_insn_moxie;
  508. break;
  509. #endif
  510. #ifdef ARCH_iq2000
  511. case bfd_arch_iq2000:
  512. disassemble = print_insn_iq2000;
  513. break;
  514. #endif
  515. #ifdef ARCH_m32c
  516. case bfd_arch_m32c:
  517. disassemble = print_insn_m32c;
  518. break;
  519. #endif
  520. #ifdef ARCH_tilegx
  521. case bfd_arch_tilegx:
  522. disassemble = print_insn_tilegx;
  523. break;
  524. #endif
  525. #ifdef ARCH_tilepro
  526. case bfd_arch_tilepro:
  527. disassemble = print_insn_tilepro;
  528. break;
  529. #endif
  530. default:
  531. return 0;
  532. }
  533. return disassemble;
  534. }
  535. void
  536. disassembler_usage (stream)
  537. FILE * stream ATTRIBUTE_UNUSED;
  538. {
  539. #ifdef ARCH_aarch64
  540. print_aarch64_disassembler_options (stream);
  541. #endif
  542. #ifdef ARCH_arm
  543. print_arm_disassembler_options (stream);
  544. #endif
  545. #ifdef ARCH_mips
  546. print_mips_disassembler_options (stream);
  547. #endif
  548. #ifdef ARCH_powerpc
  549. print_ppc_disassembler_options (stream);
  550. #endif
  551. #ifdef ARCH_i386
  552. print_i386_disassembler_options (stream);
  553. #endif
  554. #ifdef ARCH_s390
  555. print_s390_disassembler_options (stream);
  556. #endif
  557. return;
  558. }
  559. void
  560. disassemble_init_for_target (struct disassemble_info * info)
  561. {
  562. if (info == NULL)
  563. return;
  564. switch (info->arch)
  565. {
  566. #ifdef ARCH_aarch64
  567. case bfd_arch_aarch64:
  568. info->symbol_is_valid = aarch64_symbol_is_valid;
  569. info->disassembler_needs_relocs = TRUE;
  570. break;
  571. #endif
  572. #ifdef ARCH_arm
  573. case bfd_arch_arm:
  574. info->symbol_is_valid = arm_symbol_is_valid;
  575. info->disassembler_needs_relocs = TRUE;
  576. break;
  577. #endif
  578. #ifdef ARCH_ia64
  579. case bfd_arch_ia64:
  580. info->skip_zeroes = 16;
  581. break;
  582. #endif
  583. #ifdef ARCH_tic4x
  584. case bfd_arch_tic4x:
  585. info->skip_zeroes = 32;
  586. break;
  587. #endif
  588. #ifdef ARCH_mep
  589. case bfd_arch_mep:
  590. info->skip_zeroes = 256;
  591. info->skip_zeroes_at_end = 0;
  592. break;
  593. #endif
  594. #ifdef ARCH_metag
  595. case bfd_arch_metag:
  596. info->disassembler_needs_relocs = TRUE;
  597. break;
  598. #endif
  599. #ifdef ARCH_m32c
  600. case bfd_arch_m32c:
  601. /* This processor in fact is little endian. The value set here
  602. reflects the way opcodes are written in the cgen description. */
  603. info->endian = BFD_ENDIAN_BIG;
  604. if (! info->insn_sets)
  605. {
  606. info->insn_sets = cgen_bitset_create (ISA_MAX);
  607. if (info->mach == bfd_mach_m16c)
  608. cgen_bitset_set (info->insn_sets, ISA_M16C);
  609. else
  610. cgen_bitset_set (info->insn_sets, ISA_M32C);
  611. }
  612. break;
  613. #endif
  614. #ifdef ARCH_powerpc
  615. case bfd_arch_powerpc:
  616. #endif
  617. #ifdef ARCH_rs6000
  618. case bfd_arch_rs6000:
  619. #endif
  620. #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
  621. disassemble_init_powerpc (info);
  622. break;
  623. #endif
  624. default:
  625. break;
  626. }
  627. }