frv-dis.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. THIS FILE IS MACHINE GENERATED WITH CGEN.
  5. - the resultant file is machine generated, cgen-dis.in isn't
  6. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  7. This file is part of libopcodes.
  8. This library is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3, or (at your option)
  11. any later version.
  12. It is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  15. License for more details.
  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 Foundation, Inc.,
  18. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  19. /* ??? Eventually more and more of this stuff can go to cpu-independent files.
  20. Keep that in mind. */
  21. #include "sysdep.h"
  22. #include <stdio.h>
  23. #include "ansidecl.h"
  24. #include "disassemble.h"
  25. #include "bfd.h"
  26. #include "symcat.h"
  27. #include "libiberty.h"
  28. #include "frv-desc.h"
  29. #include "frv-opc.h"
  30. #include "opintl.h"
  31. /* Default text to print if an instruction isn't recognized. */
  32. #define UNKNOWN_INSN_MSG _("*unknown*")
  33. static void print_normal
  34. (CGEN_CPU_DESC, void *, long, unsigned int, bfd_vma, int);
  35. static void print_address
  36. (CGEN_CPU_DESC, void *, bfd_vma, unsigned int, bfd_vma, int) ATTRIBUTE_UNUSED;
  37. static void print_keyword
  38. (CGEN_CPU_DESC, void *, CGEN_KEYWORD *, long, unsigned int) ATTRIBUTE_UNUSED;
  39. static void print_insn_normal
  40. (CGEN_CPU_DESC, void *, const CGEN_INSN *, CGEN_FIELDS *, bfd_vma, int);
  41. static int print_insn
  42. (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, unsigned);
  43. static int default_print_insn
  44. (CGEN_CPU_DESC, bfd_vma, disassemble_info *) ATTRIBUTE_UNUSED;
  45. static int read_insn
  46. (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, int, CGEN_EXTRACT_INFO *,
  47. unsigned long *);
  48. /* -- disassembler routines inserted here. */
  49. /* -- dis.c */
  50. static void
  51. print_at (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  52. void * dis_info,
  53. long reloc_ann ATTRIBUTE_UNUSED,
  54. long value ATTRIBUTE_UNUSED,
  55. bfd_vma pc ATTRIBUTE_UNUSED,
  56. int length ATTRIBUTE_UNUSED)
  57. {
  58. disassemble_info *info = (disassemble_info *) dis_info;
  59. (*info->fprintf_func) (info->stream, "@");
  60. }
  61. static void
  62. print_spr (CGEN_CPU_DESC cd,
  63. void * dis_info,
  64. CGEN_KEYWORD *names,
  65. long regno,
  66. unsigned int attrs)
  67. {
  68. /* Use the register index format for any unnamed registers. */
  69. if (cgen_keyword_lookup_value (names, regno) == NULL)
  70. {
  71. disassemble_info *info = (disassemble_info *) dis_info;
  72. (*info->fprintf_func) (info->stream, "spr[%ld]", regno);
  73. }
  74. else
  75. print_keyword (cd, dis_info, names, regno, attrs);
  76. }
  77. static void
  78. print_hi (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  79. void * dis_info,
  80. long value,
  81. unsigned int attrs ATTRIBUTE_UNUSED,
  82. bfd_vma pc ATTRIBUTE_UNUSED,
  83. int length ATTRIBUTE_UNUSED)
  84. {
  85. disassemble_info *info = (disassemble_info *) dis_info;
  86. (*info->fprintf_func) (info->stream, value ? "0x%lx" : "hi(0x%lx)", value);
  87. }
  88. static void
  89. print_lo (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  90. void * dis_info,
  91. long value,
  92. unsigned int attrs ATTRIBUTE_UNUSED,
  93. bfd_vma pc ATTRIBUTE_UNUSED,
  94. int length ATTRIBUTE_UNUSED)
  95. {
  96. disassemble_info *info = (disassemble_info *) dis_info;
  97. if (value)
  98. (*info->fprintf_func) (info->stream, "0x%lx", value);
  99. else
  100. (*info->fprintf_func) (info->stream, "lo(0x%lx)", value);
  101. }
  102. /* -- */
  103. void frv_cgen_print_operand
  104. (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, void const *, bfd_vma, int);
  105. /* Main entry point for printing operands.
  106. XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
  107. of dis-asm.h on cgen.h.
  108. This function is basically just a big switch statement. Earlier versions
  109. used tables to look up the function to use, but
  110. - if the table contains both assembler and disassembler functions then
  111. the disassembler contains much of the assembler and vice-versa,
  112. - there's a lot of inlining possibilities as things grow,
  113. - using a switch statement avoids the function call overhead.
  114. This function could be moved into `print_insn_normal', but keeping it
  115. separate makes clear the interface between `print_insn_normal' and each of
  116. the handlers. */
  117. void
  118. frv_cgen_print_operand (CGEN_CPU_DESC cd,
  119. int opindex,
  120. void * xinfo,
  121. CGEN_FIELDS *fields,
  122. void const *attrs ATTRIBUTE_UNUSED,
  123. bfd_vma pc,
  124. int length)
  125. {
  126. disassemble_info *info = (disassemble_info *) xinfo;
  127. switch (opindex)
  128. {
  129. case FRV_OPERAND_A0 :
  130. print_normal (cd, info, fields->f_A, 0, pc, length);
  131. break;
  132. case FRV_OPERAND_A1 :
  133. print_normal (cd, info, fields->f_A, 0, pc, length);
  134. break;
  135. case FRV_OPERAND_ACC40SI :
  136. print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Si, 0);
  137. break;
  138. case FRV_OPERAND_ACC40SK :
  139. print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Sk, 0);
  140. break;
  141. case FRV_OPERAND_ACC40UI :
  142. print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Ui, 0);
  143. break;
  144. case FRV_OPERAND_ACC40UK :
  145. print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Uk, 0);
  146. break;
  147. case FRV_OPERAND_ACCGI :
  148. print_keyword (cd, info, & frv_cgen_opval_accg_names, fields->f_ACCGi, 0);
  149. break;
  150. case FRV_OPERAND_ACCGK :
  151. print_keyword (cd, info, & frv_cgen_opval_accg_names, fields->f_ACCGk, 0);
  152. break;
  153. case FRV_OPERAND_CCI :
  154. print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CCi, 0);
  155. break;
  156. case FRV_OPERAND_CPRDOUBLEK :
  157. print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRk, 0);
  158. break;
  159. case FRV_OPERAND_CPRI :
  160. print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRi, 0);
  161. break;
  162. case FRV_OPERAND_CPRJ :
  163. print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRj, 0);
  164. break;
  165. case FRV_OPERAND_CPRK :
  166. print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRk, 0);
  167. break;
  168. case FRV_OPERAND_CRI :
  169. print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRi, 0);
  170. break;
  171. case FRV_OPERAND_CRJ :
  172. print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRj, 0);
  173. break;
  174. case FRV_OPERAND_CRJ_FLOAT :
  175. print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRj_float, 0);
  176. break;
  177. case FRV_OPERAND_CRJ_INT :
  178. print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRj_int, 0);
  179. break;
  180. case FRV_OPERAND_CRK :
  181. print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRk, 0);
  182. break;
  183. case FRV_OPERAND_FCCI_1 :
  184. print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCi_1, 0);
  185. break;
  186. case FRV_OPERAND_FCCI_2 :
  187. print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCi_2, 0);
  188. break;
  189. case FRV_OPERAND_FCCI_3 :
  190. print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCi_3, 0);
  191. break;
  192. case FRV_OPERAND_FCCK :
  193. print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCk, 0);
  194. break;
  195. case FRV_OPERAND_FRDOUBLEI :
  196. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0);
  197. break;
  198. case FRV_OPERAND_FRDOUBLEJ :
  199. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0);
  200. break;
  201. case FRV_OPERAND_FRDOUBLEK :
  202. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0);
  203. break;
  204. case FRV_OPERAND_FRI :
  205. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0);
  206. break;
  207. case FRV_OPERAND_FRINTI :
  208. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0);
  209. break;
  210. case FRV_OPERAND_FRINTIEVEN :
  211. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0);
  212. break;
  213. case FRV_OPERAND_FRINTJ :
  214. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0);
  215. break;
  216. case FRV_OPERAND_FRINTJEVEN :
  217. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0);
  218. break;
  219. case FRV_OPERAND_FRINTK :
  220. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0);
  221. break;
  222. case FRV_OPERAND_FRINTKEVEN :
  223. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0);
  224. break;
  225. case FRV_OPERAND_FRJ :
  226. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0);
  227. break;
  228. case FRV_OPERAND_FRK :
  229. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0);
  230. break;
  231. case FRV_OPERAND_FRKHI :
  232. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0);
  233. break;
  234. case FRV_OPERAND_FRKLO :
  235. print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0);
  236. break;
  237. case FRV_OPERAND_GRDOUBLEK :
  238. print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0);
  239. break;
  240. case FRV_OPERAND_GRI :
  241. print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRi, 0);
  242. break;
  243. case FRV_OPERAND_GRJ :
  244. print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRj, 0);
  245. break;
  246. case FRV_OPERAND_GRK :
  247. print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0);
  248. break;
  249. case FRV_OPERAND_GRKHI :
  250. print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0);
  251. break;
  252. case FRV_OPERAND_GRKLO :
  253. print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0);
  254. break;
  255. case FRV_OPERAND_ICCI_1 :
  256. print_keyword (cd, info, & frv_cgen_opval_iccr_names, fields->f_ICCi_1, 0);
  257. break;
  258. case FRV_OPERAND_ICCI_2 :
  259. print_keyword (cd, info, & frv_cgen_opval_iccr_names, fields->f_ICCi_2, 0);
  260. break;
  261. case FRV_OPERAND_ICCI_3 :
  262. print_keyword (cd, info, & frv_cgen_opval_iccr_names, fields->f_ICCi_3, 0);
  263. break;
  264. case FRV_OPERAND_LI :
  265. print_normal (cd, info, fields->f_LI, 0, pc, length);
  266. break;
  267. case FRV_OPERAND_LRAD :
  268. print_normal (cd, info, fields->f_LRAD, 0, pc, length);
  269. break;
  270. case FRV_OPERAND_LRAE :
  271. print_normal (cd, info, fields->f_LRAE, 0, pc, length);
  272. break;
  273. case FRV_OPERAND_LRAS :
  274. print_normal (cd, info, fields->f_LRAS, 0, pc, length);
  275. break;
  276. case FRV_OPERAND_TLBPRL :
  277. print_normal (cd, info, fields->f_TLBPRL, 0, pc, length);
  278. break;
  279. case FRV_OPERAND_TLBPROPX :
  280. print_normal (cd, info, fields->f_TLBPRopx, 0, pc, length);
  281. break;
  282. case FRV_OPERAND_AE :
  283. print_normal (cd, info, fields->f_ae, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  284. break;
  285. case FRV_OPERAND_CALLANN :
  286. print_at (cd, info, fields->f_reloc_ann, 0, pc, length);
  287. break;
  288. case FRV_OPERAND_CCOND :
  289. print_normal (cd, info, fields->f_ccond, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  290. break;
  291. case FRV_OPERAND_COND :
  292. print_normal (cd, info, fields->f_cond, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  293. break;
  294. case FRV_OPERAND_D12 :
  295. print_normal (cd, info, fields->f_d12, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  296. break;
  297. case FRV_OPERAND_DEBUG :
  298. print_normal (cd, info, fields->f_debug, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  299. break;
  300. case FRV_OPERAND_EIR :
  301. print_normal (cd, info, fields->f_eir, 0, pc, length);
  302. break;
  303. case FRV_OPERAND_HINT :
  304. print_normal (cd, info, fields->f_hint, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  305. break;
  306. case FRV_OPERAND_HINT_NOT_TAKEN :
  307. print_keyword (cd, info, & frv_cgen_opval_h_hint_not_taken, fields->f_hint, 0);
  308. break;
  309. case FRV_OPERAND_HINT_TAKEN :
  310. print_keyword (cd, info, & frv_cgen_opval_h_hint_taken, fields->f_hint, 0);
  311. break;
  312. case FRV_OPERAND_LABEL16 :
  313. print_address (cd, info, fields->f_label16, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  314. break;
  315. case FRV_OPERAND_LABEL24 :
  316. print_address (cd, info, fields->f_label24, 0|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  317. break;
  318. case FRV_OPERAND_LDANN :
  319. print_at (cd, info, fields->f_reloc_ann, 0, pc, length);
  320. break;
  321. case FRV_OPERAND_LDDANN :
  322. print_at (cd, info, fields->f_reloc_ann, 0, pc, length);
  323. break;
  324. case FRV_OPERAND_LOCK :
  325. print_normal (cd, info, fields->f_lock, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  326. break;
  327. case FRV_OPERAND_PACK :
  328. print_keyword (cd, info, & frv_cgen_opval_h_pack, fields->f_pack, 0);
  329. break;
  330. case FRV_OPERAND_S10 :
  331. print_normal (cd, info, fields->f_s10, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  332. break;
  333. case FRV_OPERAND_S12 :
  334. print_normal (cd, info, fields->f_d12, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  335. break;
  336. case FRV_OPERAND_S16 :
  337. print_normal (cd, info, fields->f_s16, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  338. break;
  339. case FRV_OPERAND_S5 :
  340. print_normal (cd, info, fields->f_s5, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  341. break;
  342. case FRV_OPERAND_S6 :
  343. print_normal (cd, info, fields->f_s6, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  344. break;
  345. case FRV_OPERAND_S6_1 :
  346. print_normal (cd, info, fields->f_s6_1, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  347. break;
  348. case FRV_OPERAND_SLO16 :
  349. print_lo (cd, info, fields->f_s16, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  350. break;
  351. case FRV_OPERAND_SPR :
  352. print_spr (cd, info, & frv_cgen_opval_spr_names, fields->f_spr, 0|(1<<CGEN_OPERAND_VIRTUAL));
  353. break;
  354. case FRV_OPERAND_U12 :
  355. print_normal (cd, info, fields->f_u12, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  356. break;
  357. case FRV_OPERAND_U16 :
  358. print_normal (cd, info, fields->f_u16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  359. break;
  360. case FRV_OPERAND_U6 :
  361. print_normal (cd, info, fields->f_u6, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
  362. break;
  363. case FRV_OPERAND_UHI16 :
  364. print_hi (cd, info, fields->f_u16, 0, pc, length);
  365. break;
  366. case FRV_OPERAND_ULO16 :
  367. print_lo (cd, info, fields->f_u16, 0, pc, length);
  368. break;
  369. default :
  370. /* xgettext:c-format */
  371. opcodes_error_handler
  372. (_("internal error: unrecognized field %d while printing insn"),
  373. opindex);
  374. abort ();
  375. }
  376. }
  377. cgen_print_fn * const frv_cgen_print_handlers[] =
  378. {
  379. print_insn_normal,
  380. };
  381. void
  382. frv_cgen_init_dis (CGEN_CPU_DESC cd)
  383. {
  384. frv_cgen_init_opcode_table (cd);
  385. frv_cgen_init_ibld_table (cd);
  386. cd->print_handlers = & frv_cgen_print_handlers[0];
  387. cd->print_operand = frv_cgen_print_operand;
  388. }
  389. /* Default print handler. */
  390. static void
  391. print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  392. void *dis_info,
  393. long value,
  394. unsigned int attrs,
  395. bfd_vma pc ATTRIBUTE_UNUSED,
  396. int length ATTRIBUTE_UNUSED)
  397. {
  398. disassemble_info *info = (disassemble_info *) dis_info;
  399. /* Print the operand as directed by the attributes. */
  400. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  401. ; /* nothing to do */
  402. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  403. (*info->fprintf_func) (info->stream, "%ld", value);
  404. else
  405. (*info->fprintf_func) (info->stream, "0x%lx", value);
  406. }
  407. /* Default address handler. */
  408. static void
  409. print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  410. void *dis_info,
  411. bfd_vma value,
  412. unsigned int attrs,
  413. bfd_vma pc ATTRIBUTE_UNUSED,
  414. int length ATTRIBUTE_UNUSED)
  415. {
  416. disassemble_info *info = (disassemble_info *) dis_info;
  417. /* Print the operand as directed by the attributes. */
  418. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  419. ; /* Nothing to do. */
  420. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
  421. (*info->print_address_func) (value, info);
  422. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
  423. (*info->print_address_func) (value, info);
  424. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  425. (*info->fprintf_func) (info->stream, "%ld", (long) value);
  426. else
  427. (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
  428. }
  429. /* Keyword print handler. */
  430. static void
  431. print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  432. void *dis_info,
  433. CGEN_KEYWORD *keyword_table,
  434. long value,
  435. unsigned int attrs ATTRIBUTE_UNUSED)
  436. {
  437. disassemble_info *info = (disassemble_info *) dis_info;
  438. const CGEN_KEYWORD_ENTRY *ke;
  439. ke = cgen_keyword_lookup_value (keyword_table, value);
  440. if (ke != NULL)
  441. (*info->fprintf_func) (info->stream, "%s", ke->name);
  442. else
  443. (*info->fprintf_func) (info->stream, "???");
  444. }
  445. /* Default insn printer.
  446. DIS_INFO is defined as `void *' so the disassembler needn't know anything
  447. about disassemble_info. */
  448. static void
  449. print_insn_normal (CGEN_CPU_DESC cd,
  450. void *dis_info,
  451. const CGEN_INSN *insn,
  452. CGEN_FIELDS *fields,
  453. bfd_vma pc,
  454. int length)
  455. {
  456. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  457. disassemble_info *info = (disassemble_info *) dis_info;
  458. const CGEN_SYNTAX_CHAR_TYPE *syn;
  459. CGEN_INIT_PRINT (cd);
  460. for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
  461. {
  462. if (CGEN_SYNTAX_MNEMONIC_P (*syn))
  463. {
  464. (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
  465. continue;
  466. }
  467. if (CGEN_SYNTAX_CHAR_P (*syn))
  468. {
  469. (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
  470. continue;
  471. }
  472. /* We have an operand. */
  473. frv_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
  474. fields, CGEN_INSN_ATTRS (insn), pc, length);
  475. }
  476. }
  477. /* Subroutine of print_insn. Reads an insn into the given buffers and updates
  478. the extract info.
  479. Returns 0 if all is well, non-zero otherwise. */
  480. static int
  481. read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  482. bfd_vma pc,
  483. disassemble_info *info,
  484. bfd_byte *buf,
  485. int buflen,
  486. CGEN_EXTRACT_INFO *ex_info,
  487. unsigned long *insn_value)
  488. {
  489. int status = (*info->read_memory_func) (pc, buf, buflen, info);
  490. if (status != 0)
  491. {
  492. (*info->memory_error_func) (status, pc, info);
  493. return -1;
  494. }
  495. ex_info->dis_info = info;
  496. ex_info->valid = (1 << buflen) - 1;
  497. ex_info->insn_bytes = buf;
  498. *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
  499. return 0;
  500. }
  501. /* Utility to print an insn.
  502. BUF is the base part of the insn, target byte order, BUFLEN bytes long.
  503. The result is the size of the insn in bytes or zero for an unknown insn
  504. or -1 if an error occurs fetching data (memory_error_func will have
  505. been called). */
  506. static int
  507. print_insn (CGEN_CPU_DESC cd,
  508. bfd_vma pc,
  509. disassemble_info *info,
  510. bfd_byte *buf,
  511. unsigned int buflen)
  512. {
  513. CGEN_INSN_INT insn_value;
  514. const CGEN_INSN_LIST *insn_list;
  515. CGEN_EXTRACT_INFO ex_info;
  516. int basesize;
  517. /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
  518. basesize = cd->base_insn_bitsize < buflen * 8 ?
  519. cd->base_insn_bitsize : buflen * 8;
  520. insn_value = cgen_get_insn_value (cd, buf, basesize, cd->insn_endian);
  521. /* Fill in ex_info fields like read_insn would. Don't actually call
  522. read_insn, since the incoming buffer is already read (and possibly
  523. modified a la m32r). */
  524. ex_info.valid = (1 << buflen) - 1;
  525. ex_info.dis_info = info;
  526. ex_info.insn_bytes = buf;
  527. /* The instructions are stored in hash lists.
  528. Pick the first one and keep trying until we find the right one. */
  529. insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
  530. while (insn_list != NULL)
  531. {
  532. const CGEN_INSN *insn = insn_list->insn;
  533. CGEN_FIELDS fields;
  534. int length;
  535. unsigned long insn_value_cropped;
  536. #ifdef CGEN_VALIDATE_INSN_SUPPORTED
  537. /* Not needed as insn shouldn't be in hash lists if not supported. */
  538. /* Supported by this cpu? */
  539. if (! frv_cgen_insn_supported (cd, insn))
  540. {
  541. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  542. continue;
  543. }
  544. #endif
  545. /* Basic bit mask must be correct. */
  546. /* ??? May wish to allow target to defer this check until the extract
  547. handler. */
  548. /* Base size may exceed this instruction's size. Extract the
  549. relevant part from the buffer. */
  550. if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
  551. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  552. insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
  553. info->endian == BFD_ENDIAN_BIG);
  554. else
  555. insn_value_cropped = insn_value;
  556. if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
  557. == CGEN_INSN_BASE_VALUE (insn))
  558. {
  559. /* Printing is handled in two passes. The first pass parses the
  560. machine insn and extracts the fields. The second pass prints
  561. them. */
  562. /* Make sure the entire insn is loaded into insn_value, if it
  563. can fit. */
  564. if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
  565. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  566. {
  567. unsigned long full_insn_value;
  568. int rc = read_insn (cd, pc, info, buf,
  569. CGEN_INSN_BITSIZE (insn) / 8,
  570. & ex_info, & full_insn_value);
  571. if (rc != 0)
  572. return rc;
  573. length = CGEN_EXTRACT_FN (cd, insn)
  574. (cd, insn, &ex_info, full_insn_value, &fields, pc);
  575. }
  576. else
  577. length = CGEN_EXTRACT_FN (cd, insn)
  578. (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
  579. /* Length < 0 -> error. */
  580. if (length < 0)
  581. return length;
  582. if (length > 0)
  583. {
  584. CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
  585. /* Length is in bits, result is in bytes. */
  586. return length / 8;
  587. }
  588. }
  589. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  590. }
  591. return 0;
  592. }
  593. /* Default value for CGEN_PRINT_INSN.
  594. The result is the size of the insn in bytes or zero for an unknown insn
  595. or -1 if an error occured fetching bytes. */
  596. #ifndef CGEN_PRINT_INSN
  597. #define CGEN_PRINT_INSN default_print_insn
  598. #endif
  599. static int
  600. default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  601. {
  602. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  603. int buflen;
  604. int status;
  605. /* Attempt to read the base part of the insn. */
  606. buflen = cd->base_insn_bitsize / 8;
  607. status = (*info->read_memory_func) (pc, buf, buflen, info);
  608. /* Try again with the minimum part, if min < base. */
  609. if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
  610. {
  611. buflen = cd->min_insn_bitsize / 8;
  612. status = (*info->read_memory_func) (pc, buf, buflen, info);
  613. }
  614. if (status != 0)
  615. {
  616. (*info->memory_error_func) (status, pc, info);
  617. return -1;
  618. }
  619. return print_insn (cd, pc, info, buf, buflen);
  620. }
  621. /* Main entry point.
  622. Print one instruction from PC on INFO->STREAM.
  623. Return the size of the instruction (in bytes). */
  624. typedef struct cpu_desc_list
  625. {
  626. struct cpu_desc_list *next;
  627. CGEN_BITSET *isa;
  628. int mach;
  629. int endian;
  630. int insn_endian;
  631. CGEN_CPU_DESC cd;
  632. } cpu_desc_list;
  633. int
  634. print_insn_frv (bfd_vma pc, disassemble_info *info)
  635. {
  636. static cpu_desc_list *cd_list = 0;
  637. cpu_desc_list *cl = 0;
  638. static CGEN_CPU_DESC cd = 0;
  639. static CGEN_BITSET *prev_isa;
  640. static int prev_mach;
  641. static int prev_endian;
  642. static int prev_insn_endian;
  643. int length;
  644. CGEN_BITSET *isa;
  645. int mach;
  646. int endian = (info->endian == BFD_ENDIAN_BIG
  647. ? CGEN_ENDIAN_BIG
  648. : CGEN_ENDIAN_LITTLE);
  649. int insn_endian = (info->endian_code == BFD_ENDIAN_BIG
  650. ? CGEN_ENDIAN_BIG
  651. : CGEN_ENDIAN_LITTLE);
  652. enum bfd_architecture arch;
  653. /* ??? gdb will set mach but leave the architecture as "unknown" */
  654. #ifndef CGEN_BFD_ARCH
  655. #define CGEN_BFD_ARCH bfd_arch_frv
  656. #endif
  657. arch = info->arch;
  658. if (arch == bfd_arch_unknown)
  659. arch = CGEN_BFD_ARCH;
  660. /* There's no standard way to compute the machine or isa number
  661. so we leave it to the target. */
  662. #ifdef CGEN_COMPUTE_MACH
  663. mach = CGEN_COMPUTE_MACH (info);
  664. #else
  665. mach = info->mach;
  666. #endif
  667. #ifdef CGEN_COMPUTE_ISA
  668. {
  669. static CGEN_BITSET *permanent_isa;
  670. if (!permanent_isa)
  671. permanent_isa = cgen_bitset_create (MAX_ISAS);
  672. isa = permanent_isa;
  673. cgen_bitset_clear (isa);
  674. cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
  675. }
  676. #else
  677. isa = info->private_data;
  678. #endif
  679. /* If we've switched cpu's, try to find a handle we've used before */
  680. if (cd
  681. && (cgen_bitset_compare (isa, prev_isa) != 0
  682. || mach != prev_mach
  683. || endian != prev_endian))
  684. {
  685. cd = 0;
  686. for (cl = cd_list; cl; cl = cl->next)
  687. {
  688. if (cgen_bitset_compare (cl->isa, isa) == 0 &&
  689. cl->mach == mach &&
  690. cl->endian == endian)
  691. {
  692. cd = cl->cd;
  693. prev_isa = cd->isas;
  694. break;
  695. }
  696. }
  697. }
  698. /* If we haven't initialized yet, initialize the opcode table. */
  699. if (! cd)
  700. {
  701. const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
  702. const char *mach_name;
  703. if (!arch_type)
  704. abort ();
  705. mach_name = arch_type->printable_name;
  706. prev_isa = cgen_bitset_copy (isa);
  707. prev_mach = mach;
  708. prev_endian = endian;
  709. prev_insn_endian = insn_endian;
  710. cd = frv_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
  711. CGEN_CPU_OPEN_BFDMACH, mach_name,
  712. CGEN_CPU_OPEN_ENDIAN, prev_endian,
  713. CGEN_CPU_OPEN_INSN_ENDIAN, prev_insn_endian,
  714. CGEN_CPU_OPEN_END);
  715. if (!cd)
  716. abort ();
  717. /* Save this away for future reference. */
  718. cl = xmalloc (sizeof (struct cpu_desc_list));
  719. cl->cd = cd;
  720. cl->isa = prev_isa;
  721. cl->mach = mach;
  722. cl->endian = endian;
  723. cl->next = cd_list;
  724. cd_list = cl;
  725. frv_cgen_init_dis (cd);
  726. }
  727. /* We try to have as much common code as possible.
  728. But at this point some targets need to take over. */
  729. /* ??? Some targets may need a hook elsewhere. Try to avoid this,
  730. but if not possible try to move this hook elsewhere rather than
  731. have two hooks. */
  732. length = CGEN_PRINT_INSN (cd, pc, info);
  733. if (length > 0)
  734. return length;
  735. if (length < 0)
  736. return -1;
  737. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  738. return cd->default_insn_bitsize / 8;
  739. }