iq2000-dis.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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 "iq2000-desc.h"
  29. #include "iq2000-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. void iq2000_cgen_print_operand
  50. (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, void const *, bfd_vma, int);
  51. /* Main entry point for printing operands.
  52. XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
  53. of dis-asm.h on cgen.h.
  54. This function is basically just a big switch statement. Earlier versions
  55. used tables to look up the function to use, but
  56. - if the table contains both assembler and disassembler functions then
  57. the disassembler contains much of the assembler and vice-versa,
  58. - there's a lot of inlining possibilities as things grow,
  59. - using a switch statement avoids the function call overhead.
  60. This function could be moved into `print_insn_normal', but keeping it
  61. separate makes clear the interface between `print_insn_normal' and each of
  62. the handlers. */
  63. void
  64. iq2000_cgen_print_operand (CGEN_CPU_DESC cd,
  65. int opindex,
  66. void * xinfo,
  67. CGEN_FIELDS *fields,
  68. void const *attrs ATTRIBUTE_UNUSED,
  69. bfd_vma pc,
  70. int length)
  71. {
  72. disassemble_info *info = (disassemble_info *) xinfo;
  73. switch (opindex)
  74. {
  75. case IQ2000_OPERAND__INDEX :
  76. print_normal (cd, info, fields->f_index, 0, pc, length);
  77. break;
  78. case IQ2000_OPERAND_BASE :
  79. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rs, 0);
  80. break;
  81. case IQ2000_OPERAND_BASEOFF :
  82. print_address (cd, info, fields->f_imm, 0, pc, length);
  83. break;
  84. case IQ2000_OPERAND_BITNUM :
  85. print_normal (cd, info, fields->f_rt, 0, pc, length);
  86. break;
  87. case IQ2000_OPERAND_BYTECOUNT :
  88. print_normal (cd, info, fields->f_bytecount, 0, pc, length);
  89. break;
  90. case IQ2000_OPERAND_CAM_Y :
  91. print_normal (cd, info, fields->f_cam_y, 0, pc, length);
  92. break;
  93. case IQ2000_OPERAND_CAM_Z :
  94. print_normal (cd, info, fields->f_cam_z, 0, pc, length);
  95. break;
  96. case IQ2000_OPERAND_CM_3FUNC :
  97. print_normal (cd, info, fields->f_cm_3func, 0, pc, length);
  98. break;
  99. case IQ2000_OPERAND_CM_3Z :
  100. print_normal (cd, info, fields->f_cm_3z, 0, pc, length);
  101. break;
  102. case IQ2000_OPERAND_CM_4FUNC :
  103. print_normal (cd, info, fields->f_cm_4func, 0, pc, length);
  104. break;
  105. case IQ2000_OPERAND_CM_4Z :
  106. print_normal (cd, info, fields->f_cm_4z, 0, pc, length);
  107. break;
  108. case IQ2000_OPERAND_COUNT :
  109. print_normal (cd, info, fields->f_count, 0, pc, length);
  110. break;
  111. case IQ2000_OPERAND_EXECODE :
  112. print_normal (cd, info, fields->f_excode, 0, pc, length);
  113. break;
  114. case IQ2000_OPERAND_HI16 :
  115. print_normal (cd, info, fields->f_imm, 0, pc, length);
  116. break;
  117. case IQ2000_OPERAND_IMM :
  118. print_normal (cd, info, fields->f_imm, 0, pc, length);
  119. break;
  120. case IQ2000_OPERAND_JMPTARG :
  121. print_address (cd, info, fields->f_jtarg, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
  122. break;
  123. case IQ2000_OPERAND_JMPTARGQ10 :
  124. print_address (cd, info, fields->f_jtargq10, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
  125. break;
  126. case IQ2000_OPERAND_LO16 :
  127. print_normal (cd, info, fields->f_imm, 0, pc, length);
  128. break;
  129. case IQ2000_OPERAND_MASK :
  130. print_normal (cd, info, fields->f_mask, 0, pc, length);
  131. break;
  132. case IQ2000_OPERAND_MASKL :
  133. print_normal (cd, info, fields->f_maskl, 0, pc, length);
  134. break;
  135. case IQ2000_OPERAND_MASKQ10 :
  136. print_normal (cd, info, fields->f_maskq10, 0, pc, length);
  137. break;
  138. case IQ2000_OPERAND_MASKR :
  139. print_normal (cd, info, fields->f_rs, 0, pc, length);
  140. break;
  141. case IQ2000_OPERAND_MLO16 :
  142. print_normal (cd, info, fields->f_imm, 0, pc, length);
  143. break;
  144. case IQ2000_OPERAND_OFFSET :
  145. print_address (cd, info, fields->f_offset, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  146. break;
  147. case IQ2000_OPERAND_RD :
  148. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rd, 0);
  149. break;
  150. case IQ2000_OPERAND_RD_RS :
  151. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rd_rs, 0|(1<<CGEN_OPERAND_VIRTUAL));
  152. break;
  153. case IQ2000_OPERAND_RD_RT :
  154. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rd_rt, 0|(1<<CGEN_OPERAND_VIRTUAL));
  155. break;
  156. case IQ2000_OPERAND_RS :
  157. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rs, 0);
  158. break;
  159. case IQ2000_OPERAND_RT :
  160. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rt, 0);
  161. break;
  162. case IQ2000_OPERAND_RT_RS :
  163. print_keyword (cd, info, & iq2000_cgen_opval_gr_names, fields->f_rt_rs, 0|(1<<CGEN_OPERAND_VIRTUAL));
  164. break;
  165. case IQ2000_OPERAND_SHAMT :
  166. print_normal (cd, info, fields->f_shamt, 0, pc, length);
  167. break;
  168. default :
  169. /* xgettext:c-format */
  170. opcodes_error_handler
  171. (_("internal error: unrecognized field %d while printing insn"),
  172. opindex);
  173. abort ();
  174. }
  175. }
  176. cgen_print_fn * const iq2000_cgen_print_handlers[] =
  177. {
  178. print_insn_normal,
  179. };
  180. void
  181. iq2000_cgen_init_dis (CGEN_CPU_DESC cd)
  182. {
  183. iq2000_cgen_init_opcode_table (cd);
  184. iq2000_cgen_init_ibld_table (cd);
  185. cd->print_handlers = & iq2000_cgen_print_handlers[0];
  186. cd->print_operand = iq2000_cgen_print_operand;
  187. }
  188. /* Default print handler. */
  189. static void
  190. print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  191. void *dis_info,
  192. long value,
  193. unsigned int attrs,
  194. bfd_vma pc ATTRIBUTE_UNUSED,
  195. int length ATTRIBUTE_UNUSED)
  196. {
  197. disassemble_info *info = (disassemble_info *) dis_info;
  198. /* Print the operand as directed by the attributes. */
  199. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  200. ; /* nothing to do */
  201. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  202. (*info->fprintf_func) (info->stream, "%ld", value);
  203. else
  204. (*info->fprintf_func) (info->stream, "0x%lx", value);
  205. }
  206. /* Default address handler. */
  207. static void
  208. print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  209. void *dis_info,
  210. bfd_vma value,
  211. unsigned int attrs,
  212. bfd_vma pc ATTRIBUTE_UNUSED,
  213. int length ATTRIBUTE_UNUSED)
  214. {
  215. disassemble_info *info = (disassemble_info *) dis_info;
  216. /* Print the operand as directed by the attributes. */
  217. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  218. ; /* Nothing to do. */
  219. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
  220. (*info->print_address_func) (value, info);
  221. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
  222. (*info->print_address_func) (value, info);
  223. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  224. (*info->fprintf_func) (info->stream, "%ld", (long) value);
  225. else
  226. (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
  227. }
  228. /* Keyword print handler. */
  229. static void
  230. print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  231. void *dis_info,
  232. CGEN_KEYWORD *keyword_table,
  233. long value,
  234. unsigned int attrs ATTRIBUTE_UNUSED)
  235. {
  236. disassemble_info *info = (disassemble_info *) dis_info;
  237. const CGEN_KEYWORD_ENTRY *ke;
  238. ke = cgen_keyword_lookup_value (keyword_table, value);
  239. if (ke != NULL)
  240. (*info->fprintf_func) (info->stream, "%s", ke->name);
  241. else
  242. (*info->fprintf_func) (info->stream, "???");
  243. }
  244. /* Default insn printer.
  245. DIS_INFO is defined as `void *' so the disassembler needn't know anything
  246. about disassemble_info. */
  247. static void
  248. print_insn_normal (CGEN_CPU_DESC cd,
  249. void *dis_info,
  250. const CGEN_INSN *insn,
  251. CGEN_FIELDS *fields,
  252. bfd_vma pc,
  253. int length)
  254. {
  255. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  256. disassemble_info *info = (disassemble_info *) dis_info;
  257. const CGEN_SYNTAX_CHAR_TYPE *syn;
  258. CGEN_INIT_PRINT (cd);
  259. for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
  260. {
  261. if (CGEN_SYNTAX_MNEMONIC_P (*syn))
  262. {
  263. (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
  264. continue;
  265. }
  266. if (CGEN_SYNTAX_CHAR_P (*syn))
  267. {
  268. (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
  269. continue;
  270. }
  271. /* We have an operand. */
  272. iq2000_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
  273. fields, CGEN_INSN_ATTRS (insn), pc, length);
  274. }
  275. }
  276. /* Subroutine of print_insn. Reads an insn into the given buffers and updates
  277. the extract info.
  278. Returns 0 if all is well, non-zero otherwise. */
  279. static int
  280. read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  281. bfd_vma pc,
  282. disassemble_info *info,
  283. bfd_byte *buf,
  284. int buflen,
  285. CGEN_EXTRACT_INFO *ex_info,
  286. unsigned long *insn_value)
  287. {
  288. int status = (*info->read_memory_func) (pc, buf, buflen, info);
  289. if (status != 0)
  290. {
  291. (*info->memory_error_func) (status, pc, info);
  292. return -1;
  293. }
  294. ex_info->dis_info = info;
  295. ex_info->valid = (1 << buflen) - 1;
  296. ex_info->insn_bytes = buf;
  297. *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
  298. return 0;
  299. }
  300. /* Utility to print an insn.
  301. BUF is the base part of the insn, target byte order, BUFLEN bytes long.
  302. The result is the size of the insn in bytes or zero for an unknown insn
  303. or -1 if an error occurs fetching data (memory_error_func will have
  304. been called). */
  305. static int
  306. print_insn (CGEN_CPU_DESC cd,
  307. bfd_vma pc,
  308. disassemble_info *info,
  309. bfd_byte *buf,
  310. unsigned int buflen)
  311. {
  312. CGEN_INSN_INT insn_value;
  313. const CGEN_INSN_LIST *insn_list;
  314. CGEN_EXTRACT_INFO ex_info;
  315. int basesize;
  316. /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
  317. basesize = cd->base_insn_bitsize < buflen * 8 ?
  318. cd->base_insn_bitsize : buflen * 8;
  319. insn_value = cgen_get_insn_value (cd, buf, basesize, cd->insn_endian);
  320. /* Fill in ex_info fields like read_insn would. Don't actually call
  321. read_insn, since the incoming buffer is already read (and possibly
  322. modified a la m32r). */
  323. ex_info.valid = (1 << buflen) - 1;
  324. ex_info.dis_info = info;
  325. ex_info.insn_bytes = buf;
  326. /* The instructions are stored in hash lists.
  327. Pick the first one and keep trying until we find the right one. */
  328. insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
  329. while (insn_list != NULL)
  330. {
  331. const CGEN_INSN *insn = insn_list->insn;
  332. CGEN_FIELDS fields;
  333. int length;
  334. unsigned long insn_value_cropped;
  335. #ifdef CGEN_VALIDATE_INSN_SUPPORTED
  336. /* Not needed as insn shouldn't be in hash lists if not supported. */
  337. /* Supported by this cpu? */
  338. if (! iq2000_cgen_insn_supported (cd, insn))
  339. {
  340. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  341. continue;
  342. }
  343. #endif
  344. /* Basic bit mask must be correct. */
  345. /* ??? May wish to allow target to defer this check until the extract
  346. handler. */
  347. /* Base size may exceed this instruction's size. Extract the
  348. relevant part from the buffer. */
  349. if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
  350. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  351. insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
  352. info->endian == BFD_ENDIAN_BIG);
  353. else
  354. insn_value_cropped = insn_value;
  355. if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
  356. == CGEN_INSN_BASE_VALUE (insn))
  357. {
  358. /* Printing is handled in two passes. The first pass parses the
  359. machine insn and extracts the fields. The second pass prints
  360. them. */
  361. /* Make sure the entire insn is loaded into insn_value, if it
  362. can fit. */
  363. if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
  364. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  365. {
  366. unsigned long full_insn_value;
  367. int rc = read_insn (cd, pc, info, buf,
  368. CGEN_INSN_BITSIZE (insn) / 8,
  369. & ex_info, & full_insn_value);
  370. if (rc != 0)
  371. return rc;
  372. length = CGEN_EXTRACT_FN (cd, insn)
  373. (cd, insn, &ex_info, full_insn_value, &fields, pc);
  374. }
  375. else
  376. length = CGEN_EXTRACT_FN (cd, insn)
  377. (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
  378. /* Length < 0 -> error. */
  379. if (length < 0)
  380. return length;
  381. if (length > 0)
  382. {
  383. CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
  384. /* Length is in bits, result is in bytes. */
  385. return length / 8;
  386. }
  387. }
  388. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  389. }
  390. return 0;
  391. }
  392. /* Default value for CGEN_PRINT_INSN.
  393. The result is the size of the insn in bytes or zero for an unknown insn
  394. or -1 if an error occured fetching bytes. */
  395. #ifndef CGEN_PRINT_INSN
  396. #define CGEN_PRINT_INSN default_print_insn
  397. #endif
  398. static int
  399. default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  400. {
  401. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  402. int buflen;
  403. int status;
  404. /* Attempt to read the base part of the insn. */
  405. buflen = cd->base_insn_bitsize / 8;
  406. status = (*info->read_memory_func) (pc, buf, buflen, info);
  407. /* Try again with the minimum part, if min < base. */
  408. if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
  409. {
  410. buflen = cd->min_insn_bitsize / 8;
  411. status = (*info->read_memory_func) (pc, buf, buflen, info);
  412. }
  413. if (status != 0)
  414. {
  415. (*info->memory_error_func) (status, pc, info);
  416. return -1;
  417. }
  418. return print_insn (cd, pc, info, buf, buflen);
  419. }
  420. /* Main entry point.
  421. Print one instruction from PC on INFO->STREAM.
  422. Return the size of the instruction (in bytes). */
  423. typedef struct cpu_desc_list
  424. {
  425. struct cpu_desc_list *next;
  426. CGEN_BITSET *isa;
  427. int mach;
  428. int endian;
  429. int insn_endian;
  430. CGEN_CPU_DESC cd;
  431. } cpu_desc_list;
  432. int
  433. print_insn_iq2000 (bfd_vma pc, disassemble_info *info)
  434. {
  435. static cpu_desc_list *cd_list = 0;
  436. cpu_desc_list *cl = 0;
  437. static CGEN_CPU_DESC cd = 0;
  438. static CGEN_BITSET *prev_isa;
  439. static int prev_mach;
  440. static int prev_endian;
  441. static int prev_insn_endian;
  442. int length;
  443. CGEN_BITSET *isa;
  444. int mach;
  445. int endian = (info->endian == BFD_ENDIAN_BIG
  446. ? CGEN_ENDIAN_BIG
  447. : CGEN_ENDIAN_LITTLE);
  448. int insn_endian = (info->endian_code == BFD_ENDIAN_BIG
  449. ? CGEN_ENDIAN_BIG
  450. : CGEN_ENDIAN_LITTLE);
  451. enum bfd_architecture arch;
  452. /* ??? gdb will set mach but leave the architecture as "unknown" */
  453. #ifndef CGEN_BFD_ARCH
  454. #define CGEN_BFD_ARCH bfd_arch_iq2000
  455. #endif
  456. arch = info->arch;
  457. if (arch == bfd_arch_unknown)
  458. arch = CGEN_BFD_ARCH;
  459. /* There's no standard way to compute the machine or isa number
  460. so we leave it to the target. */
  461. #ifdef CGEN_COMPUTE_MACH
  462. mach = CGEN_COMPUTE_MACH (info);
  463. #else
  464. mach = info->mach;
  465. #endif
  466. #ifdef CGEN_COMPUTE_ISA
  467. {
  468. static CGEN_BITSET *permanent_isa;
  469. if (!permanent_isa)
  470. permanent_isa = cgen_bitset_create (MAX_ISAS);
  471. isa = permanent_isa;
  472. cgen_bitset_clear (isa);
  473. cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
  474. }
  475. #else
  476. isa = info->private_data;
  477. #endif
  478. /* If we've switched cpu's, try to find a handle we've used before */
  479. if (cd
  480. && (cgen_bitset_compare (isa, prev_isa) != 0
  481. || mach != prev_mach
  482. || endian != prev_endian))
  483. {
  484. cd = 0;
  485. for (cl = cd_list; cl; cl = cl->next)
  486. {
  487. if (cgen_bitset_compare (cl->isa, isa) == 0 &&
  488. cl->mach == mach &&
  489. cl->endian == endian)
  490. {
  491. cd = cl->cd;
  492. prev_isa = cd->isas;
  493. break;
  494. }
  495. }
  496. }
  497. /* If we haven't initialized yet, initialize the opcode table. */
  498. if (! cd)
  499. {
  500. const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
  501. const char *mach_name;
  502. if (!arch_type)
  503. abort ();
  504. mach_name = arch_type->printable_name;
  505. prev_isa = cgen_bitset_copy (isa);
  506. prev_mach = mach;
  507. prev_endian = endian;
  508. prev_insn_endian = insn_endian;
  509. cd = iq2000_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
  510. CGEN_CPU_OPEN_BFDMACH, mach_name,
  511. CGEN_CPU_OPEN_ENDIAN, prev_endian,
  512. CGEN_CPU_OPEN_INSN_ENDIAN, prev_insn_endian,
  513. CGEN_CPU_OPEN_END);
  514. if (!cd)
  515. abort ();
  516. /* Save this away for future reference. */
  517. cl = xmalloc (sizeof (struct cpu_desc_list));
  518. cl->cd = cd;
  519. cl->isa = prev_isa;
  520. cl->mach = mach;
  521. cl->endian = endian;
  522. cl->next = cd_list;
  523. cd_list = cl;
  524. iq2000_cgen_init_dis (cd);
  525. }
  526. /* We try to have as much common code as possible.
  527. But at this point some targets need to take over. */
  528. /* ??? Some targets may need a hook elsewhere. Try to avoid this,
  529. but if not possible try to move this hook elsewhere rather than
  530. have two hooks. */
  531. length = CGEN_PRINT_INSN (cd, pc, info);
  532. if (length > 0)
  533. return length;
  534. if (length < 0)
  535. return -1;
  536. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  537. return cd->default_insn_bitsize / 8;
  538. }