xstormy16-dis.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 "xstormy16-desc.h"
  29. #include "xstormy16-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 xstormy16_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. xstormy16_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 XSTORMY16_OPERAND_RB :
  76. print_keyword (cd, info, & xstormy16_cgen_opval_gr_Rb_names, fields->f_Rb, 0);
  77. break;
  78. case XSTORMY16_OPERAND_RBJ :
  79. print_keyword (cd, info, & xstormy16_cgen_opval_gr_Rb_names, fields->f_Rbj, 0);
  80. break;
  81. case XSTORMY16_OPERAND_RD :
  82. print_keyword (cd, info, & xstormy16_cgen_opval_gr_names, fields->f_Rd, 0);
  83. break;
  84. case XSTORMY16_OPERAND_RDM :
  85. print_keyword (cd, info, & xstormy16_cgen_opval_gr_names, fields->f_Rdm, 0);
  86. break;
  87. case XSTORMY16_OPERAND_RM :
  88. print_keyword (cd, info, & xstormy16_cgen_opval_gr_names, fields->f_Rm, 0);
  89. break;
  90. case XSTORMY16_OPERAND_RS :
  91. print_keyword (cd, info, & xstormy16_cgen_opval_gr_names, fields->f_Rs, 0);
  92. break;
  93. case XSTORMY16_OPERAND_ABS24 :
  94. print_normal (cd, info, fields->f_abs24, 0|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  95. break;
  96. case XSTORMY16_OPERAND_BCOND2 :
  97. print_keyword (cd, info, & xstormy16_cgen_opval_h_branchcond, fields->f_op2, 0);
  98. break;
  99. case XSTORMY16_OPERAND_BCOND5 :
  100. print_keyword (cd, info, & xstormy16_cgen_opval_h_branchcond, fields->f_op5, 0);
  101. break;
  102. case XSTORMY16_OPERAND_HMEM8 :
  103. print_normal (cd, info, fields->f_hmem8, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
  104. break;
  105. case XSTORMY16_OPERAND_IMM12 :
  106. print_normal (cd, info, fields->f_imm12, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  107. break;
  108. case XSTORMY16_OPERAND_IMM16 :
  109. print_normal (cd, info, fields->f_imm16, 0|(1<<CGEN_OPERAND_SIGN_OPT), pc, length);
  110. break;
  111. case XSTORMY16_OPERAND_IMM2 :
  112. print_normal (cd, info, fields->f_imm2, 0, pc, length);
  113. break;
  114. case XSTORMY16_OPERAND_IMM3 :
  115. print_normal (cd, info, fields->f_imm3, 0, pc, length);
  116. break;
  117. case XSTORMY16_OPERAND_IMM3B :
  118. print_normal (cd, info, fields->f_imm3b, 0, pc, length);
  119. break;
  120. case XSTORMY16_OPERAND_IMM4 :
  121. print_normal (cd, info, fields->f_imm4, 0, pc, length);
  122. break;
  123. case XSTORMY16_OPERAND_IMM8 :
  124. print_normal (cd, info, fields->f_imm8, 0, pc, length);
  125. break;
  126. case XSTORMY16_OPERAND_IMM8SMALL :
  127. print_normal (cd, info, fields->f_imm8, 0, pc, length);
  128. break;
  129. case XSTORMY16_OPERAND_LMEM8 :
  130. print_normal (cd, info, fields->f_lmem8, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
  131. break;
  132. case XSTORMY16_OPERAND_REL12 :
  133. print_normal (cd, info, fields->f_rel12, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  134. break;
  135. case XSTORMY16_OPERAND_REL12A :
  136. print_normal (cd, info, fields->f_rel12a, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  137. break;
  138. case XSTORMY16_OPERAND_REL8_2 :
  139. print_normal (cd, info, fields->f_rel8_2, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  140. break;
  141. case XSTORMY16_OPERAND_REL8_4 :
  142. print_normal (cd, info, fields->f_rel8_4, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  143. break;
  144. case XSTORMY16_OPERAND_WS2 :
  145. print_keyword (cd, info, & xstormy16_cgen_opval_h_wordsize, fields->f_op2m, 0);
  146. break;
  147. default :
  148. /* xgettext:c-format */
  149. opcodes_error_handler
  150. (_("internal error: unrecognized field %d while printing insn"),
  151. opindex);
  152. abort ();
  153. }
  154. }
  155. cgen_print_fn * const xstormy16_cgen_print_handlers[] =
  156. {
  157. print_insn_normal,
  158. };
  159. void
  160. xstormy16_cgen_init_dis (CGEN_CPU_DESC cd)
  161. {
  162. xstormy16_cgen_init_opcode_table (cd);
  163. xstormy16_cgen_init_ibld_table (cd);
  164. cd->print_handlers = & xstormy16_cgen_print_handlers[0];
  165. cd->print_operand = xstormy16_cgen_print_operand;
  166. }
  167. /* Default print handler. */
  168. static void
  169. print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  170. void *dis_info,
  171. long value,
  172. unsigned int attrs,
  173. bfd_vma pc ATTRIBUTE_UNUSED,
  174. int length ATTRIBUTE_UNUSED)
  175. {
  176. disassemble_info *info = (disassemble_info *) dis_info;
  177. /* Print the operand as directed by the attributes. */
  178. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  179. ; /* nothing to do */
  180. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  181. (*info->fprintf_func) (info->stream, "%ld", value);
  182. else
  183. (*info->fprintf_func) (info->stream, "0x%lx", value);
  184. }
  185. /* Default address handler. */
  186. static void
  187. print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  188. void *dis_info,
  189. bfd_vma value,
  190. unsigned int attrs,
  191. bfd_vma pc ATTRIBUTE_UNUSED,
  192. int length ATTRIBUTE_UNUSED)
  193. {
  194. disassemble_info *info = (disassemble_info *) dis_info;
  195. /* Print the operand as directed by the attributes. */
  196. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  197. ; /* Nothing to do. */
  198. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
  199. (*info->print_address_func) (value, info);
  200. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
  201. (*info->print_address_func) (value, info);
  202. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  203. (*info->fprintf_func) (info->stream, "%ld", (long) value);
  204. else
  205. (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
  206. }
  207. /* Keyword print handler. */
  208. static void
  209. print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  210. void *dis_info,
  211. CGEN_KEYWORD *keyword_table,
  212. long value,
  213. unsigned int attrs ATTRIBUTE_UNUSED)
  214. {
  215. disassemble_info *info = (disassemble_info *) dis_info;
  216. const CGEN_KEYWORD_ENTRY *ke;
  217. ke = cgen_keyword_lookup_value (keyword_table, value);
  218. if (ke != NULL)
  219. (*info->fprintf_func) (info->stream, "%s", ke->name);
  220. else
  221. (*info->fprintf_func) (info->stream, "???");
  222. }
  223. /* Default insn printer.
  224. DIS_INFO is defined as `void *' so the disassembler needn't know anything
  225. about disassemble_info. */
  226. static void
  227. print_insn_normal (CGEN_CPU_DESC cd,
  228. void *dis_info,
  229. const CGEN_INSN *insn,
  230. CGEN_FIELDS *fields,
  231. bfd_vma pc,
  232. int length)
  233. {
  234. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  235. disassemble_info *info = (disassemble_info *) dis_info;
  236. const CGEN_SYNTAX_CHAR_TYPE *syn;
  237. CGEN_INIT_PRINT (cd);
  238. for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
  239. {
  240. if (CGEN_SYNTAX_MNEMONIC_P (*syn))
  241. {
  242. (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
  243. continue;
  244. }
  245. if (CGEN_SYNTAX_CHAR_P (*syn))
  246. {
  247. (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
  248. continue;
  249. }
  250. /* We have an operand. */
  251. xstormy16_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
  252. fields, CGEN_INSN_ATTRS (insn), pc, length);
  253. }
  254. }
  255. /* Subroutine of print_insn. Reads an insn into the given buffers and updates
  256. the extract info.
  257. Returns 0 if all is well, non-zero otherwise. */
  258. static int
  259. read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  260. bfd_vma pc,
  261. disassemble_info *info,
  262. bfd_byte *buf,
  263. int buflen,
  264. CGEN_EXTRACT_INFO *ex_info,
  265. unsigned long *insn_value)
  266. {
  267. int status = (*info->read_memory_func) (pc, buf, buflen, info);
  268. if (status != 0)
  269. {
  270. (*info->memory_error_func) (status, pc, info);
  271. return -1;
  272. }
  273. ex_info->dis_info = info;
  274. ex_info->valid = (1 << buflen) - 1;
  275. ex_info->insn_bytes = buf;
  276. *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
  277. return 0;
  278. }
  279. /* Utility to print an insn.
  280. BUF is the base part of the insn, target byte order, BUFLEN bytes long.
  281. The result is the size of the insn in bytes or zero for an unknown insn
  282. or -1 if an error occurs fetching data (memory_error_func will have
  283. been called). */
  284. static int
  285. print_insn (CGEN_CPU_DESC cd,
  286. bfd_vma pc,
  287. disassemble_info *info,
  288. bfd_byte *buf,
  289. unsigned int buflen)
  290. {
  291. CGEN_INSN_INT insn_value;
  292. const CGEN_INSN_LIST *insn_list;
  293. CGEN_EXTRACT_INFO ex_info;
  294. int basesize;
  295. /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
  296. basesize = cd->base_insn_bitsize < buflen * 8 ?
  297. cd->base_insn_bitsize : buflen * 8;
  298. insn_value = cgen_get_insn_value (cd, buf, basesize, cd->insn_endian);
  299. /* Fill in ex_info fields like read_insn would. Don't actually call
  300. read_insn, since the incoming buffer is already read (and possibly
  301. modified a la m32r). */
  302. ex_info.valid = (1 << buflen) - 1;
  303. ex_info.dis_info = info;
  304. ex_info.insn_bytes = buf;
  305. /* The instructions are stored in hash lists.
  306. Pick the first one and keep trying until we find the right one. */
  307. insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
  308. while (insn_list != NULL)
  309. {
  310. const CGEN_INSN *insn = insn_list->insn;
  311. CGEN_FIELDS fields;
  312. int length;
  313. unsigned long insn_value_cropped;
  314. #ifdef CGEN_VALIDATE_INSN_SUPPORTED
  315. /* Not needed as insn shouldn't be in hash lists if not supported. */
  316. /* Supported by this cpu? */
  317. if (! xstormy16_cgen_insn_supported (cd, insn))
  318. {
  319. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  320. continue;
  321. }
  322. #endif
  323. /* Basic bit mask must be correct. */
  324. /* ??? May wish to allow target to defer this check until the extract
  325. handler. */
  326. /* Base size may exceed this instruction's size. Extract the
  327. relevant part from the buffer. */
  328. if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
  329. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  330. insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
  331. info->endian == BFD_ENDIAN_BIG);
  332. else
  333. insn_value_cropped = insn_value;
  334. if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
  335. == CGEN_INSN_BASE_VALUE (insn))
  336. {
  337. /* Printing is handled in two passes. The first pass parses the
  338. machine insn and extracts the fields. The second pass prints
  339. them. */
  340. /* Make sure the entire insn is loaded into insn_value, if it
  341. can fit. */
  342. if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
  343. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  344. {
  345. unsigned long full_insn_value;
  346. int rc = read_insn (cd, pc, info, buf,
  347. CGEN_INSN_BITSIZE (insn) / 8,
  348. & ex_info, & full_insn_value);
  349. if (rc != 0)
  350. return rc;
  351. length = CGEN_EXTRACT_FN (cd, insn)
  352. (cd, insn, &ex_info, full_insn_value, &fields, pc);
  353. }
  354. else
  355. length = CGEN_EXTRACT_FN (cd, insn)
  356. (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
  357. /* Length < 0 -> error. */
  358. if (length < 0)
  359. return length;
  360. if (length > 0)
  361. {
  362. CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
  363. /* Length is in bits, result is in bytes. */
  364. return length / 8;
  365. }
  366. }
  367. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  368. }
  369. return 0;
  370. }
  371. /* Default value for CGEN_PRINT_INSN.
  372. The result is the size of the insn in bytes or zero for an unknown insn
  373. or -1 if an error occured fetching bytes. */
  374. #ifndef CGEN_PRINT_INSN
  375. #define CGEN_PRINT_INSN default_print_insn
  376. #endif
  377. static int
  378. default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  379. {
  380. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  381. int buflen;
  382. int status;
  383. /* Attempt to read the base part of the insn. */
  384. buflen = cd->base_insn_bitsize / 8;
  385. status = (*info->read_memory_func) (pc, buf, buflen, info);
  386. /* Try again with the minimum part, if min < base. */
  387. if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
  388. {
  389. buflen = cd->min_insn_bitsize / 8;
  390. status = (*info->read_memory_func) (pc, buf, buflen, info);
  391. }
  392. if (status != 0)
  393. {
  394. (*info->memory_error_func) (status, pc, info);
  395. return -1;
  396. }
  397. return print_insn (cd, pc, info, buf, buflen);
  398. }
  399. /* Main entry point.
  400. Print one instruction from PC on INFO->STREAM.
  401. Return the size of the instruction (in bytes). */
  402. typedef struct cpu_desc_list
  403. {
  404. struct cpu_desc_list *next;
  405. CGEN_BITSET *isa;
  406. int mach;
  407. int endian;
  408. int insn_endian;
  409. CGEN_CPU_DESC cd;
  410. } cpu_desc_list;
  411. int
  412. print_insn_xstormy16 (bfd_vma pc, disassemble_info *info)
  413. {
  414. static cpu_desc_list *cd_list = 0;
  415. cpu_desc_list *cl = 0;
  416. static CGEN_CPU_DESC cd = 0;
  417. static CGEN_BITSET *prev_isa;
  418. static int prev_mach;
  419. static int prev_endian;
  420. static int prev_insn_endian;
  421. int length;
  422. CGEN_BITSET *isa;
  423. int mach;
  424. int endian = (info->endian == BFD_ENDIAN_BIG
  425. ? CGEN_ENDIAN_BIG
  426. : CGEN_ENDIAN_LITTLE);
  427. int insn_endian = (info->endian_code == BFD_ENDIAN_BIG
  428. ? CGEN_ENDIAN_BIG
  429. : CGEN_ENDIAN_LITTLE);
  430. enum bfd_architecture arch;
  431. /* ??? gdb will set mach but leave the architecture as "unknown" */
  432. #ifndef CGEN_BFD_ARCH
  433. #define CGEN_BFD_ARCH bfd_arch_xstormy16
  434. #endif
  435. arch = info->arch;
  436. if (arch == bfd_arch_unknown)
  437. arch = CGEN_BFD_ARCH;
  438. /* There's no standard way to compute the machine or isa number
  439. so we leave it to the target. */
  440. #ifdef CGEN_COMPUTE_MACH
  441. mach = CGEN_COMPUTE_MACH (info);
  442. #else
  443. mach = info->mach;
  444. #endif
  445. #ifdef CGEN_COMPUTE_ISA
  446. {
  447. static CGEN_BITSET *permanent_isa;
  448. if (!permanent_isa)
  449. permanent_isa = cgen_bitset_create (MAX_ISAS);
  450. isa = permanent_isa;
  451. cgen_bitset_clear (isa);
  452. cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
  453. }
  454. #else
  455. isa = info->private_data;
  456. #endif
  457. /* If we've switched cpu's, try to find a handle we've used before */
  458. if (cd
  459. && (cgen_bitset_compare (isa, prev_isa) != 0
  460. || mach != prev_mach
  461. || endian != prev_endian))
  462. {
  463. cd = 0;
  464. for (cl = cd_list; cl; cl = cl->next)
  465. {
  466. if (cgen_bitset_compare (cl->isa, isa) == 0 &&
  467. cl->mach == mach &&
  468. cl->endian == endian)
  469. {
  470. cd = cl->cd;
  471. prev_isa = cd->isas;
  472. break;
  473. }
  474. }
  475. }
  476. /* If we haven't initialized yet, initialize the opcode table. */
  477. if (! cd)
  478. {
  479. const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
  480. const char *mach_name;
  481. if (!arch_type)
  482. abort ();
  483. mach_name = arch_type->printable_name;
  484. prev_isa = cgen_bitset_copy (isa);
  485. prev_mach = mach;
  486. prev_endian = endian;
  487. prev_insn_endian = insn_endian;
  488. cd = xstormy16_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
  489. CGEN_CPU_OPEN_BFDMACH, mach_name,
  490. CGEN_CPU_OPEN_ENDIAN, prev_endian,
  491. CGEN_CPU_OPEN_INSN_ENDIAN, prev_insn_endian,
  492. CGEN_CPU_OPEN_END);
  493. if (!cd)
  494. abort ();
  495. /* Save this away for future reference. */
  496. cl = xmalloc (sizeof (struct cpu_desc_list));
  497. cl->cd = cd;
  498. cl->isa = prev_isa;
  499. cl->mach = mach;
  500. cl->endian = endian;
  501. cl->next = cd_list;
  502. cd_list = cl;
  503. xstormy16_cgen_init_dis (cd);
  504. }
  505. /* We try to have as much common code as possible.
  506. But at this point some targets need to take over. */
  507. /* ??? Some targets may need a hook elsewhere. Try to avoid this,
  508. but if not possible try to move this hook elsewhere rather than
  509. have two hooks. */
  510. length = CGEN_PRINT_INSN (cd, pc, info);
  511. if (length > 0)
  512. return length;
  513. if (length < 0)
  514. return -1;
  515. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  516. return cd->default_insn_bitsize / 8;
  517. }