arc-dis.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. /* Instruction printing code for the ARC.
  2. Copyright (C) 1994-2017 Free Software Foundation, Inc.
  3. Contributed by Claudiu Zissulescu (claziss@synopsys.com)
  4. This file is part of libopcodes.
  5. This library is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. It is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include <stdio.h>
  19. #include <assert.h>
  20. #include "dis-asm.h"
  21. #include "opcode/arc.h"
  22. #include "elf/arc.h"
  23. #include "arc-dis.h"
  24. #include "arc-ext.h"
  25. #include "elf-bfd.h"
  26. #include "libiberty.h"
  27. #include "opintl.h"
  28. /* Structure used to iterate over, and extract the values for, operands of
  29. an opcode. */
  30. struct arc_operand_iterator
  31. {
  32. /* The complete instruction value to extract operands from. */
  33. unsigned long long insn;
  34. /* The LIMM if this is being tracked separately. This field is only
  35. valid if we find the LIMM operand in the operand list. */
  36. unsigned limm;
  37. /* The opcode this iterator is operating on. */
  38. const struct arc_opcode *opcode;
  39. /* The index into the opcodes operand index list. */
  40. const unsigned char *opidx;
  41. };
  42. /* A private data used by ARC decoder. */
  43. struct arc_disassemble_info
  44. {
  45. /* The current disassembled arc opcode. */
  46. const struct arc_opcode *opcode;
  47. /* Instruction length w/o limm field. */
  48. unsigned insn_len;
  49. /* TRUE if we have limm. */
  50. bfd_boolean limm_p;
  51. /* LIMM value, if exists. */
  52. unsigned limm;
  53. /* Condition code, if exists. */
  54. unsigned condition_code;
  55. /* Writeback mode. */
  56. unsigned writeback_mode;
  57. /* Number of operands. */
  58. unsigned operands_count;
  59. struct arc_insn_operand operands[MAX_INSN_ARGS];
  60. };
  61. /* Globals variables. */
  62. static const char * const regnames[64] =
  63. {
  64. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  65. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  66. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  67. "r24", "r25", "gp", "fp", "sp", "ilink", "r30", "blink",
  68. "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
  69. "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
  70. "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
  71. "r56", "r57", "ACCL", "ACCH", "lp_count", "rezerved", "LIMM", "pcl"
  72. };
  73. static const char * const addrtypenames[ARC_NUM_ADDRTYPES] =
  74. {
  75. "bd", "jid", "lbd", "mbd", "sd", "sm", "xa", "xd",
  76. "cd", "cbd", "cjid", "clbd", "cm", "csd", "cxa", "cxd"
  77. };
  78. static int addrtypenames_max = ARC_NUM_ADDRTYPES - 1;
  79. static const char * const addrtypeunknown = "unknown";
  80. /* This structure keeps track which instruction class(es)
  81. should be ignored durring disassembling. */
  82. typedef struct skipclass
  83. {
  84. insn_class_t insn_class;
  85. insn_subclass_t subclass;
  86. struct skipclass *nxt;
  87. } skipclass_t, *linkclass;
  88. /* Intial classes of instructions to be consider first when
  89. disassembling. */
  90. static linkclass decodelist = NULL;
  91. /* ISA mask value enforced via disassembler info options. ARC_OPCODE_NONE
  92. value means that no CPU is enforced. */
  93. static unsigned enforced_isa_mask = ARC_OPCODE_NONE;
  94. /* Macros section. */
  95. #ifdef DEBUG
  96. # define pr_debug(fmt, args...) fprintf (stderr, fmt, ##args)
  97. #else
  98. # define pr_debug(fmt, args...)
  99. #endif
  100. #define ARRANGE_ENDIAN(info, buf) \
  101. (info->endian == BFD_ENDIAN_LITTLE ? bfd_getm32 (bfd_getl32 (buf)) \
  102. : bfd_getb32 (buf))
  103. #define BITS(word,s,e) (((word) << (sizeof (word) * 8 - 1 - e)) >> \
  104. (s + (sizeof (word) * 8 - 1 - e)))
  105. #define OPCODE_32BIT_INSN(word) (BITS ((word), 27, 31))
  106. /* Functions implementation. */
  107. /* Initialize private data. */
  108. static bfd_boolean
  109. init_arc_disasm_info (struct disassemble_info *info)
  110. {
  111. struct arc_disassemble_info *arc_infop
  112. = calloc (sizeof (*arc_infop), 1);
  113. if (arc_infop == NULL)
  114. return FALSE;
  115. info->private_data = arc_infop;
  116. return TRUE;
  117. }
  118. /* Add a new element to the decode list. */
  119. static void
  120. add_to_decodelist (insn_class_t insn_class,
  121. insn_subclass_t subclass)
  122. {
  123. linkclass t = (linkclass) xmalloc (sizeof (skipclass_t));
  124. t->insn_class = insn_class;
  125. t->subclass = subclass;
  126. t->nxt = decodelist;
  127. decodelist = t;
  128. }
  129. /* Return TRUE if we need to skip the opcode from being
  130. disassembled. */
  131. static bfd_boolean
  132. skip_this_opcode (const struct arc_opcode *opcode)
  133. {
  134. linkclass t = decodelist;
  135. /* Check opcode for major 0x06, return if it is not in. */
  136. if (arc_opcode_len (opcode) == 4
  137. && OPCODE_32BIT_INSN (opcode->opcode) != 0x06)
  138. return FALSE;
  139. /* or not a known truble class. */
  140. switch (opcode->insn_class)
  141. {
  142. case FLOAT:
  143. case DSP:
  144. break;
  145. default:
  146. return FALSE;
  147. }
  148. while (t != NULL)
  149. {
  150. if ((t->insn_class == opcode->insn_class)
  151. && (t->subclass == opcode->subclass))
  152. return FALSE;
  153. t = t->nxt;
  154. }
  155. return TRUE;
  156. }
  157. static bfd_vma
  158. bfd_getm32 (unsigned int data)
  159. {
  160. bfd_vma value = 0;
  161. value = ((data & 0xff00) | (data & 0xff)) << 16;
  162. value |= ((data & 0xff0000) | (data & 0xff000000)) >> 16;
  163. return value;
  164. }
  165. static bfd_boolean
  166. special_flag_p (const char *opname,
  167. const char *flgname)
  168. {
  169. const struct arc_flag_special *flg_spec;
  170. unsigned i, j, flgidx;
  171. for (i = 0; i < arc_num_flag_special; i++)
  172. {
  173. flg_spec = &arc_flag_special_cases[i];
  174. if (strcmp (opname, flg_spec->name))
  175. continue;
  176. /* Found potential special case instruction. */
  177. for (j=0;; ++j)
  178. {
  179. flgidx = flg_spec->flags[j];
  180. if (flgidx == 0)
  181. break; /* End of the array. */
  182. if (strcmp (flgname, arc_flag_operands[flgidx].name) == 0)
  183. return TRUE;
  184. }
  185. }
  186. return FALSE;
  187. }
  188. /* Find opcode from ARC_TABLE given the instruction described by INSN and
  189. INSNLEN. The ISA_MASK restricts the possible matches in ARC_TABLE. */
  190. static const struct arc_opcode *
  191. find_format_from_table (struct disassemble_info *info,
  192. const struct arc_opcode *arc_table,
  193. unsigned long long insn,
  194. unsigned int insn_len,
  195. unsigned isa_mask,
  196. bfd_boolean *has_limm,
  197. bfd_boolean overlaps)
  198. {
  199. unsigned int i = 0;
  200. const struct arc_opcode *opcode = NULL;
  201. const struct arc_opcode *t_op = NULL;
  202. const unsigned char *opidx;
  203. const unsigned char *flgidx;
  204. bfd_boolean warn_p = FALSE;
  205. do
  206. {
  207. bfd_boolean invalid = FALSE;
  208. opcode = &arc_table[i++];
  209. if (!(opcode->cpu & isa_mask))
  210. continue;
  211. if (arc_opcode_len (opcode) != (int) insn_len)
  212. continue;
  213. if ((insn & opcode->mask) != opcode->opcode)
  214. continue;
  215. *has_limm = FALSE;
  216. /* Possible candidate, check the operands. */
  217. for (opidx = opcode->operands; *opidx; opidx++)
  218. {
  219. int value, limmind;
  220. const struct arc_operand *operand = &arc_operands[*opidx];
  221. if (operand->flags & ARC_OPERAND_FAKE)
  222. continue;
  223. if (operand->extract)
  224. value = (*operand->extract) (insn, &invalid);
  225. else
  226. value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
  227. /* Check for LIMM indicator. If it is there, then make sure
  228. we pick the right format. */
  229. limmind = (isa_mask & ARC_OPCODE_ARCV2) ? 0x1E : 0x3E;
  230. if (operand->flags & ARC_OPERAND_IR
  231. && !(operand->flags & ARC_OPERAND_LIMM))
  232. {
  233. if ((value == 0x3E && insn_len == 4)
  234. || (value == limmind && insn_len == 2))
  235. {
  236. invalid = TRUE;
  237. break;
  238. }
  239. }
  240. if (operand->flags & ARC_OPERAND_LIMM
  241. && !(operand->flags & ARC_OPERAND_DUPLICATE))
  242. *has_limm = TRUE;
  243. }
  244. /* Check the flags. */
  245. for (flgidx = opcode->flags; *flgidx; flgidx++)
  246. {
  247. /* Get a valid flag class. */
  248. const struct arc_flag_class *cl_flags = &arc_flag_classes[*flgidx];
  249. const unsigned *flgopridx;
  250. int foundA = 0, foundB = 0;
  251. unsigned int value;
  252. /* Check first the extensions. */
  253. if (cl_flags->flag_class & F_CLASS_EXTEND)
  254. {
  255. value = (insn & 0x1F);
  256. if (arcExtMap_condCodeName (value))
  257. continue;
  258. }
  259. /* Check for the implicit flags. */
  260. if (cl_flags->flag_class & F_CLASS_IMPLICIT)
  261. continue;
  262. for (flgopridx = cl_flags->flags; *flgopridx; ++flgopridx)
  263. {
  264. const struct arc_flag_operand *flg_operand =
  265. &arc_flag_operands[*flgopridx];
  266. value = (insn >> flg_operand->shift)
  267. & ((1 << flg_operand->bits) - 1);
  268. if (value == flg_operand->code)
  269. foundA = 1;
  270. if (value)
  271. foundB = 1;
  272. }
  273. if (!foundA && foundB)
  274. {
  275. invalid = TRUE;
  276. break;
  277. }
  278. }
  279. if (invalid)
  280. continue;
  281. if (insn_len == 4
  282. && overlaps)
  283. {
  284. warn_p = TRUE;
  285. t_op = opcode;
  286. if (skip_this_opcode (opcode))
  287. continue;
  288. }
  289. /* The instruction is valid. */
  290. return opcode;
  291. }
  292. while (opcode->mask);
  293. if (warn_p)
  294. {
  295. info->fprintf_func (info->stream,
  296. _("\nWarning: disassembly may be wrong due to "
  297. "guessed opcode class choice.\n"
  298. "Use -M<class[,class]> to select the correct "
  299. "opcode class(es).\n\t\t\t\t"));
  300. return t_op;
  301. }
  302. return NULL;
  303. }
  304. /* Find opcode for INSN, trying various different sources. The instruction
  305. length in INSN_LEN will be updated if the instruction requires a LIMM
  306. extension.
  307. A pointer to the opcode is placed into OPCODE_RESULT, and ITER is
  308. initialised, ready to iterate over the operands of the found opcode. If
  309. the found opcode requires a LIMM then the LIMM value will be loaded into a
  310. field of ITER.
  311. This function returns TRUE in almost all cases, FALSE is reserved to
  312. indicate an error (failing to find an opcode is not an error) a returned
  313. result of FALSE would indicate that the disassembler can't continue.
  314. If no matching opcode is found then the returned result will be TRUE, the
  315. value placed into OPCODE_RESULT will be NULL, ITER will be undefined, and
  316. INSN_LEN will be unchanged.
  317. If a matching opcode is found, then the returned result will be TRUE, the
  318. opcode pointer is placed into OPCODE_RESULT, INSN_LEN will be increased by
  319. 4 if the instruction requires a LIMM, and the LIMM value will have been
  320. loaded into a field of ITER. Finally, ITER will have been initialised so
  321. that calls to OPERAND_ITERATOR_NEXT will iterate over the opcode's
  322. operands. */
  323. static bfd_boolean
  324. find_format (bfd_vma memaddr,
  325. unsigned long long insn,
  326. unsigned int * insn_len,
  327. unsigned isa_mask,
  328. struct disassemble_info * info,
  329. const struct arc_opcode ** opcode_result,
  330. struct arc_operand_iterator * iter)
  331. {
  332. const struct arc_opcode *opcode = NULL;
  333. bfd_boolean needs_limm;
  334. const extInstruction_t *einsn, *i;
  335. unsigned limm = 0;
  336. struct arc_disassemble_info *arc_infop = info->private_data;
  337. /* First, try the extension instructions. */
  338. if (*insn_len == 4)
  339. {
  340. einsn = arcExtMap_insn (OPCODE_32BIT_INSN (insn), insn);
  341. for (i = einsn; (i != NULL) && (opcode == NULL); i = i->next)
  342. {
  343. const char *errmsg = NULL;
  344. opcode = arcExtMap_genOpcode (i, isa_mask, &errmsg);
  345. if (opcode == NULL)
  346. {
  347. (*info->fprintf_func) (info->stream, "\
  348. An error occured while generating the extension instruction operations");
  349. *opcode_result = NULL;
  350. return FALSE;
  351. }
  352. opcode = find_format_from_table (info, opcode, insn, *insn_len,
  353. isa_mask, &needs_limm, FALSE);
  354. }
  355. }
  356. /* Then, try finding the first match in the opcode table. */
  357. if (opcode == NULL)
  358. opcode = find_format_from_table (info, arc_opcodes, insn, *insn_len,
  359. isa_mask, &needs_limm, TRUE);
  360. if (needs_limm && opcode != NULL)
  361. {
  362. bfd_byte buffer[4];
  363. int status;
  364. status = (*info->read_memory_func) (memaddr + *insn_len, buffer,
  365. 4, info);
  366. if (status != 0)
  367. {
  368. opcode = NULL;
  369. }
  370. else
  371. {
  372. limm = ARRANGE_ENDIAN (info, buffer);
  373. *insn_len += 4;
  374. }
  375. }
  376. if (opcode != NULL)
  377. {
  378. iter->insn = insn;
  379. iter->limm = limm;
  380. iter->opcode = opcode;
  381. iter->opidx = opcode->operands;
  382. }
  383. *opcode_result = opcode;
  384. /* Update private data. */
  385. arc_infop->opcode = opcode;
  386. arc_infop->limm = (needs_limm) ? limm : 0;
  387. arc_infop->limm_p = needs_limm;
  388. return TRUE;
  389. }
  390. static void
  391. print_flags (const struct arc_opcode *opcode,
  392. unsigned long long *insn,
  393. struct disassemble_info *info)
  394. {
  395. const unsigned char *flgidx;
  396. unsigned int value;
  397. struct arc_disassemble_info *arc_infop = info->private_data;
  398. /* Now extract and print the flags. */
  399. for (flgidx = opcode->flags; *flgidx; flgidx++)
  400. {
  401. /* Get a valid flag class. */
  402. const struct arc_flag_class *cl_flags = &arc_flag_classes[*flgidx];
  403. const unsigned *flgopridx;
  404. /* Check first the extensions. */
  405. if (cl_flags->flag_class & F_CLASS_EXTEND)
  406. {
  407. const char *name;
  408. value = (insn[0] & 0x1F);
  409. name = arcExtMap_condCodeName (value);
  410. if (name)
  411. {
  412. (*info->fprintf_func) (info->stream, ".%s", name);
  413. continue;
  414. }
  415. }
  416. for (flgopridx = cl_flags->flags; *flgopridx; ++flgopridx)
  417. {
  418. const struct arc_flag_operand *flg_operand =
  419. &arc_flag_operands[*flgopridx];
  420. /* Implicit flags are only used for the insn decoder. */
  421. if (cl_flags->flag_class & F_CLASS_IMPLICIT)
  422. {
  423. if (cl_flags->flag_class & F_CLASS_COND)
  424. arc_infop->condition_code = flg_operand->code;
  425. else if (cl_flags->flag_class & F_CLASS_WB)
  426. arc_infop->writeback_mode = flg_operand->code;
  427. else if (cl_flags->flag_class & F_CLASS_ZZ)
  428. info->data_size = flg_operand->code;
  429. continue;
  430. }
  431. if (!flg_operand->favail)
  432. continue;
  433. value = (insn[0] >> flg_operand->shift)
  434. & ((1 << flg_operand->bits) - 1);
  435. if (value == flg_operand->code)
  436. {
  437. /* FIXME!: print correctly nt/t flag. */
  438. if (!special_flag_p (opcode->name, flg_operand->name))
  439. (*info->fprintf_func) (info->stream, ".");
  440. else if (info->insn_type == dis_dref)
  441. {
  442. switch (flg_operand->name[0])
  443. {
  444. case 'b':
  445. info->data_size = 1;
  446. break;
  447. case 'h':
  448. case 'w':
  449. info->data_size = 2;
  450. break;
  451. default:
  452. info->data_size = 4;
  453. break;
  454. }
  455. }
  456. if (flg_operand->name[0] == 'd'
  457. && flg_operand->name[1] == 0)
  458. info->branch_delay_insns = 1;
  459. /* Check if it is a conditional flag. */
  460. if (cl_flags->flag_class & F_CLASS_COND)
  461. {
  462. if (info->insn_type == dis_jsr)
  463. info->insn_type = dis_condjsr;
  464. else if (info->insn_type == dis_branch)
  465. info->insn_type = dis_condbranch;
  466. arc_infop->condition_code = flg_operand->code;
  467. }
  468. /* Check for the write back modes. */
  469. if (cl_flags->flag_class & F_CLASS_WB)
  470. arc_infop->writeback_mode = flg_operand->code;
  471. (*info->fprintf_func) (info->stream, "%s", flg_operand->name);
  472. }
  473. }
  474. }
  475. }
  476. static const char *
  477. get_auxreg (const struct arc_opcode *opcode,
  478. int value,
  479. unsigned isa_mask)
  480. {
  481. const char *name;
  482. unsigned int i;
  483. const struct arc_aux_reg *auxr = &arc_aux_regs[0];
  484. if (opcode->insn_class != AUXREG)
  485. return NULL;
  486. name = arcExtMap_auxRegName (value);
  487. if (name)
  488. return name;
  489. for (i = 0; i < arc_num_aux_regs; i++, auxr++)
  490. {
  491. if (!(auxr->cpu & isa_mask))
  492. continue;
  493. if (auxr->subclass != NONE)
  494. return NULL;
  495. if (auxr->address == value)
  496. return auxr->name;
  497. }
  498. return NULL;
  499. }
  500. /* Convert a value representing an address type to a string used to refer to
  501. the address type in assembly code. */
  502. static const char *
  503. get_addrtype (int value)
  504. {
  505. if (value < 0 || value > addrtypenames_max)
  506. return addrtypeunknown;
  507. return addrtypenames[value];
  508. }
  509. /* Calculate the instruction length for an instruction starting with MSB
  510. and LSB, the most and least significant byte. The ISA_MASK is used to
  511. filter the instructions considered to only those that are part of the
  512. current architecture.
  513. The instruction lengths are calculated from the ARC_OPCODE table, and
  514. cached for later use. */
  515. static unsigned int
  516. arc_insn_length (bfd_byte msb, bfd_byte lsb, struct disassemble_info *info)
  517. {
  518. bfd_byte major_opcode = msb >> 3;
  519. switch (info->mach)
  520. {
  521. case bfd_mach_arc_arc700:
  522. /* The nps400 extension set requires this special casing of the
  523. instruction length calculation. Right now this is not causing any
  524. problems as none of the known extensions overlap in opcode space,
  525. but, if they ever do then we might need to start carrying
  526. information around in the elf about which extensions are in use. */
  527. if (major_opcode == 0xb)
  528. {
  529. bfd_byte minor_opcode = lsb & 0x1f;
  530. if (minor_opcode < 4)
  531. return 6;
  532. else if (minor_opcode == 0x10 || minor_opcode == 0x11)
  533. return 8;
  534. }
  535. if (major_opcode == 0xa)
  536. {
  537. return 8;
  538. }
  539. /* Fall through. */
  540. case bfd_mach_arc_arc600:
  541. return (major_opcode > 0xb) ? 2 : 4;
  542. break;
  543. case bfd_mach_arc_arcv2:
  544. return (major_opcode > 0x7) ? 2 : 4;
  545. break;
  546. default:
  547. abort ();
  548. }
  549. }
  550. /* Extract and return the value of OPERAND from the instruction whose value
  551. is held in the array INSN. */
  552. static int
  553. extract_operand_value (const struct arc_operand *operand,
  554. unsigned long long insn,
  555. unsigned limm)
  556. {
  557. int value;
  558. /* Read the limm operand, if required. */
  559. if (operand->flags & ARC_OPERAND_LIMM)
  560. /* The second part of the instruction value will have been loaded as
  561. part of the find_format call made earlier. */
  562. value = limm;
  563. else
  564. {
  565. if (operand->extract)
  566. value = (*operand->extract) (insn, (int *) NULL);
  567. else
  568. {
  569. if (operand->flags & ARC_OPERAND_ALIGNED32)
  570. {
  571. value = (insn >> operand->shift)
  572. & ((1 << (operand->bits - 2)) - 1);
  573. value = value << 2;
  574. }
  575. else
  576. {
  577. value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
  578. }
  579. if (operand->flags & ARC_OPERAND_SIGNED)
  580. {
  581. int signbit = 1 << (operand->bits - 1);
  582. value = (value ^ signbit) - signbit;
  583. }
  584. }
  585. }
  586. return value;
  587. }
  588. /* Find the next operand, and the operands value from ITER. Return TRUE if
  589. there is another operand, otherwise return FALSE. If there is an
  590. operand returned then the operand is placed into OPERAND, and the value
  591. into VALUE. If there is no operand returned then OPERAND and VALUE are
  592. unchanged. */
  593. static bfd_boolean
  594. operand_iterator_next (struct arc_operand_iterator *iter,
  595. const struct arc_operand **operand,
  596. int *value)
  597. {
  598. if (*iter->opidx == 0)
  599. {
  600. *operand = NULL;
  601. return FALSE;
  602. }
  603. *operand = &arc_operands[*iter->opidx];
  604. *value = extract_operand_value (*operand, iter->insn, iter->limm);
  605. iter->opidx++;
  606. return TRUE;
  607. }
  608. /* Helper for parsing the options. */
  609. static void
  610. parse_option (const char *option)
  611. {
  612. if (disassembler_options_cmp (option, "dsp") == 0)
  613. add_to_decodelist (DSP, NONE);
  614. else if (disassembler_options_cmp (option, "spfp") == 0)
  615. add_to_decodelist (FLOAT, SPX);
  616. else if (disassembler_options_cmp (option, "dpfp") == 0)
  617. add_to_decodelist (FLOAT, DPX);
  618. else if (disassembler_options_cmp (option, "quarkse_em") == 0)
  619. {
  620. add_to_decodelist (FLOAT, DPX);
  621. add_to_decodelist (FLOAT, SPX);
  622. add_to_decodelist (FLOAT, QUARKSE1);
  623. add_to_decodelist (FLOAT, QUARKSE2);
  624. }
  625. else if (disassembler_options_cmp (option, "fpuda") == 0)
  626. add_to_decodelist (FLOAT, DPA);
  627. else if (disassembler_options_cmp (option, "fpus") == 0)
  628. {
  629. add_to_decodelist (FLOAT, SP);
  630. add_to_decodelist (FLOAT, CVT);
  631. }
  632. else if (disassembler_options_cmp (option, "fpud") == 0)
  633. {
  634. add_to_decodelist (FLOAT, DP);
  635. add_to_decodelist (FLOAT, CVT);
  636. }
  637. else
  638. fprintf (stderr, _("Unrecognised disassembler option: %s\n"), option);
  639. }
  640. #define ARC_CPU_TYPE_A6xx(NAME,EXTRA) \
  641. { #NAME, ARC_OPCODE_ARC600, "ARC600" }
  642. #define ARC_CPU_TYPE_A7xx(NAME,EXTRA) \
  643. { #NAME, ARC_OPCODE_ARC700, "ARC700" }
  644. #define ARC_CPU_TYPE_AV2EM(NAME,EXTRA) \
  645. { #NAME, ARC_OPCODE_ARCv2EM, "ARC EM" }
  646. #define ARC_CPU_TYPE_AV2HS(NAME,EXTRA) \
  647. { #NAME, ARC_OPCODE_ARCv2HS, "ARC HS" }
  648. #define ARC_CPU_TYPE_NONE \
  649. { 0, 0, 0 }
  650. /* A table of CPU names and opcode sets. */
  651. static const struct cpu_type
  652. {
  653. const char *name;
  654. unsigned flags;
  655. const char *isa;
  656. }
  657. cpu_types[] =
  658. {
  659. #include "elf/arc-cpu.def"
  660. };
  661. /* Helper for parsing the CPU options. Accept any of the ARC architectures
  662. values. OPTION should be a value passed to cpu=. */
  663. static unsigned
  664. parse_cpu_option (const char *option)
  665. {
  666. int i;
  667. for (i = 0; cpu_types[i].name; ++i)
  668. {
  669. if (!disassembler_options_cmp (cpu_types[i].name, option))
  670. {
  671. return cpu_types[i].flags;
  672. }
  673. }
  674. fprintf (stderr, _("Unrecognised disassembler CPU option: %s\n"), option);
  675. return ARC_OPCODE_NONE;
  676. }
  677. /* Go over the options list and parse it. */
  678. static void
  679. parse_disassembler_options (const char *options)
  680. {
  681. const char *option;
  682. if (options == NULL)
  683. return;
  684. /* Disassembler might be reused for difference CPU's, and cpu option set for
  685. the first one shouldn't be applied to second (which might not have
  686. explicit cpu in its options. Therefore it is required to reset enforced
  687. CPU when new options are being parsed. */
  688. enforced_isa_mask = ARC_OPCODE_NONE;
  689. FOR_EACH_DISASSEMBLER_OPTION (option, options)
  690. {
  691. /* A CPU option? Cannot use STRING_COMMA_LEN because strncmp is also a
  692. preprocessor macro. */
  693. if (strncmp (option, "cpu=", 4) == 0)
  694. /* Strip leading `cpu=`. */
  695. enforced_isa_mask = parse_cpu_option (option + 4);
  696. else
  697. parse_option (option);
  698. }
  699. }
  700. /* Return the instruction type for an instruction described by OPCODE. */
  701. static enum dis_insn_type
  702. arc_opcode_to_insn_type (const struct arc_opcode *opcode)
  703. {
  704. enum dis_insn_type insn_type;
  705. switch (opcode->insn_class)
  706. {
  707. case BRANCH:
  708. case BBIT0:
  709. case BBIT1:
  710. case BI:
  711. case BIH:
  712. case BRCC:
  713. case EI:
  714. case JLI:
  715. case JUMP:
  716. case LOOP:
  717. if (!strncmp (opcode->name, "bl", 2)
  718. || !strncmp (opcode->name, "jl", 2))
  719. {
  720. if (opcode->subclass == COND)
  721. insn_type = dis_condjsr;
  722. else
  723. insn_type = dis_jsr;
  724. }
  725. else
  726. {
  727. if (opcode->subclass == COND)
  728. insn_type = dis_condbranch;
  729. else
  730. insn_type = dis_branch;
  731. }
  732. break;
  733. case LOAD:
  734. case STORE:
  735. case MEMORY:
  736. case ENTER:
  737. case PUSH:
  738. case POP:
  739. insn_type = dis_dref;
  740. break;
  741. case LEAVE:
  742. insn_type = dis_branch;
  743. break;
  744. default:
  745. insn_type = dis_nonbranch;
  746. break;
  747. }
  748. return insn_type;
  749. }
  750. /* Disassemble ARC instructions. */
  751. static int
  752. print_insn_arc (bfd_vma memaddr,
  753. struct disassemble_info *info)
  754. {
  755. bfd_byte buffer[8];
  756. unsigned int highbyte, lowbyte;
  757. int status;
  758. unsigned int insn_len;
  759. unsigned long long insn = 0;
  760. unsigned isa_mask = ARC_OPCODE_NONE;
  761. const struct arc_opcode *opcode;
  762. bfd_boolean need_comma;
  763. bfd_boolean open_braket;
  764. int size;
  765. const struct arc_operand *operand;
  766. int value;
  767. struct arc_operand_iterator iter;
  768. struct arc_disassemble_info *arc_infop;
  769. if (info->disassembler_options)
  770. {
  771. parse_disassembler_options (info->disassembler_options);
  772. /* Avoid repeated parsing of the options. */
  773. info->disassembler_options = NULL;
  774. }
  775. if (info->private_data == NULL && !init_arc_disasm_info (info))
  776. return -1;
  777. memset (&iter, 0, sizeof (iter));
  778. highbyte = ((info->endian == BFD_ENDIAN_LITTLE) ? 1 : 0);
  779. lowbyte = ((info->endian == BFD_ENDIAN_LITTLE) ? 0 : 1);
  780. /* Figure out CPU type, unless it was enforced via disassembler options. */
  781. if (enforced_isa_mask == ARC_OPCODE_NONE)
  782. {
  783. Elf_Internal_Ehdr *header = NULL;
  784. if (info->section && info->section->owner)
  785. header = elf_elfheader (info->section->owner);
  786. switch (info->mach)
  787. {
  788. case bfd_mach_arc_arc700:
  789. isa_mask = ARC_OPCODE_ARC700;
  790. break;
  791. case bfd_mach_arc_arc600:
  792. isa_mask = ARC_OPCODE_ARC600;
  793. break;
  794. case bfd_mach_arc_arcv2:
  795. default:
  796. isa_mask = ARC_OPCODE_ARCv2EM;
  797. /* TODO: Perhaps remove definition of header since it is only used at
  798. this location. */
  799. if (header != NULL
  800. && (header->e_flags & EF_ARC_MACH_MSK) == EF_ARC_CPU_ARCV2HS)
  801. isa_mask = ARC_OPCODE_ARCv2HS;
  802. break;
  803. }
  804. }
  805. else
  806. isa_mask = enforced_isa_mask;
  807. if (isa_mask == ARC_OPCODE_ARCv2HS)
  808. {
  809. /* FPU instructions are not extensions for HS. */
  810. add_to_decodelist (FLOAT, SP);
  811. add_to_decodelist (FLOAT, DP);
  812. add_to_decodelist (FLOAT, CVT);
  813. }
  814. /* This variable may be set by the instruction decoder. It suggests
  815. the number of bytes objdump should display on a single line. If
  816. the instruction decoder sets this, it should always set it to
  817. the same value in order to get reasonable looking output. */
  818. info->bytes_per_line = 8;
  819. /* In the next lines, we set two info variables control the way
  820. objdump displays the raw data. For example, if bytes_per_line is
  821. 8 and bytes_per_chunk is 4, the output will look like this:
  822. 00: 00000000 00000000
  823. with the chunks displayed according to "display_endian". */
  824. if (info->section
  825. && !(info->section->flags & SEC_CODE))
  826. {
  827. /* This is not a CODE section. */
  828. switch (info->section->size)
  829. {
  830. case 1:
  831. case 2:
  832. case 4:
  833. size = info->section->size;
  834. break;
  835. default:
  836. size = (info->section->size & 0x01) ? 1 : 4;
  837. break;
  838. }
  839. info->bytes_per_chunk = 1;
  840. info->display_endian = info->endian;
  841. }
  842. else
  843. {
  844. size = 2;
  845. info->bytes_per_chunk = 2;
  846. info->display_endian = info->endian;
  847. }
  848. /* Read the insn into a host word. */
  849. status = (*info->read_memory_func) (memaddr, buffer, size, info);
  850. if (status != 0)
  851. {
  852. (*info->memory_error_func) (status, memaddr, info);
  853. return -1;
  854. }
  855. if (info->section
  856. && !(info->section->flags & SEC_CODE))
  857. {
  858. /* Data section. */
  859. unsigned long data;
  860. data = bfd_get_bits (buffer, size * 8,
  861. info->display_endian == BFD_ENDIAN_BIG);
  862. switch (size)
  863. {
  864. case 1:
  865. (*info->fprintf_func) (info->stream, ".byte\t0x%02lx", data);
  866. break;
  867. case 2:
  868. (*info->fprintf_func) (info->stream, ".short\t0x%04lx", data);
  869. break;
  870. case 4:
  871. (*info->fprintf_func) (info->stream, ".word\t0x%08lx", data);
  872. break;
  873. default:
  874. abort ();
  875. }
  876. return size;
  877. }
  878. insn_len = arc_insn_length (buffer[highbyte], buffer[lowbyte], info);
  879. pr_debug ("instruction length = %d bytes\n", insn_len);
  880. arc_infop = info->private_data;
  881. arc_infop->insn_len = insn_len;
  882. switch (insn_len)
  883. {
  884. case 2:
  885. insn = (buffer[highbyte] << 8) | buffer[lowbyte];
  886. break;
  887. case 4:
  888. {
  889. /* This is a long instruction: Read the remaning 2 bytes. */
  890. status = (*info->read_memory_func) (memaddr + 2, &buffer[2], 2, info);
  891. if (status != 0)
  892. {
  893. (*info->memory_error_func) (status, memaddr + 2, info);
  894. return -1;
  895. }
  896. insn = (unsigned long long) ARRANGE_ENDIAN (info, buffer);
  897. }
  898. break;
  899. case 6:
  900. {
  901. status = (*info->read_memory_func) (memaddr + 2, &buffer[2], 4, info);
  902. if (status != 0)
  903. {
  904. (*info->memory_error_func) (status, memaddr + 2, info);
  905. return -1;
  906. }
  907. insn = (unsigned long long) ARRANGE_ENDIAN (info, &buffer[2]);
  908. insn |= ((unsigned long long) buffer[highbyte] << 40)
  909. | ((unsigned long long) buffer[lowbyte] << 32);
  910. }
  911. break;
  912. case 8:
  913. {
  914. status = (*info->read_memory_func) (memaddr + 2, &buffer[2], 6, info);
  915. if (status != 0)
  916. {
  917. (*info->memory_error_func) (status, memaddr + 2, info);
  918. return -1;
  919. }
  920. insn =
  921. ((((unsigned long long) ARRANGE_ENDIAN (info, buffer)) << 32)
  922. | ((unsigned long long) ARRANGE_ENDIAN (info, &buffer[4])));
  923. }
  924. break;
  925. default:
  926. /* There is no instruction whose length is not 2, 4, 6, or 8. */
  927. abort ();
  928. }
  929. pr_debug ("instruction value = %llx\n", insn);
  930. /* Set some defaults for the insn info. */
  931. info->insn_info_valid = 1;
  932. info->branch_delay_insns = 0;
  933. info->data_size = 4;
  934. info->insn_type = dis_nonbranch;
  935. info->target = 0;
  936. info->target2 = 0;
  937. /* FIXME to be moved in dissasemble_init_for_target. */
  938. info->disassembler_needs_relocs = TRUE;
  939. /* Find the first match in the opcode table. */
  940. if (!find_format (memaddr, insn, &insn_len, isa_mask, info, &opcode, &iter))
  941. return -1;
  942. if (!opcode)
  943. {
  944. switch (insn_len)
  945. {
  946. case 2:
  947. (*info->fprintf_func) (info->stream, ".long %#04llx",
  948. insn & 0xffff);
  949. break;
  950. case 4:
  951. (*info->fprintf_func) (info->stream, ".long %#08llx",
  952. insn & 0xffffffff);
  953. break;
  954. case 6:
  955. (*info->fprintf_func) (info->stream, ".long %#08llx",
  956. insn & 0xffffffff);
  957. (*info->fprintf_func) (info->stream, ".long %#04llx",
  958. (insn >> 32) & 0xffff);
  959. break;
  960. case 8:
  961. (*info->fprintf_func) (info->stream, ".long %#08llx",
  962. insn & 0xffffffff);
  963. (*info->fprintf_func) (info->stream, ".long %#08llx",
  964. insn >> 32);
  965. break;
  966. default:
  967. abort ();
  968. }
  969. info->insn_type = dis_noninsn;
  970. return insn_len;
  971. }
  972. /* Print the mnemonic. */
  973. (*info->fprintf_func) (info->stream, "%s", opcode->name);
  974. /* Preselect the insn class. */
  975. info->insn_type = arc_opcode_to_insn_type (opcode);
  976. pr_debug ("%s: 0x%08llx\n", opcode->name, opcode->opcode);
  977. print_flags (opcode, &insn, info);
  978. if (opcode->operands[0] != 0)
  979. (*info->fprintf_func) (info->stream, "\t");
  980. need_comma = FALSE;
  981. open_braket = FALSE;
  982. arc_infop->operands_count = 0;
  983. /* Now extract and print the operands. */
  984. operand = NULL;
  985. while (operand_iterator_next (&iter, &operand, &value))
  986. {
  987. if (open_braket && (operand->flags & ARC_OPERAND_BRAKET))
  988. {
  989. (*info->fprintf_func) (info->stream, "]");
  990. open_braket = FALSE;
  991. continue;
  992. }
  993. /* Only take input from real operands. */
  994. if (ARC_OPERAND_IS_FAKE (operand))
  995. continue;
  996. if ((operand->flags & ARC_OPERAND_IGNORE)
  997. && (operand->flags & ARC_OPERAND_IR)
  998. && value == -1)
  999. continue;
  1000. if (operand->flags & ARC_OPERAND_COLON)
  1001. {
  1002. (*info->fprintf_func) (info->stream, ":");
  1003. continue;
  1004. }
  1005. if (need_comma)
  1006. (*info->fprintf_func) (info->stream, ",");
  1007. if (!open_braket && (operand->flags & ARC_OPERAND_BRAKET))
  1008. {
  1009. (*info->fprintf_func) (info->stream, "[");
  1010. open_braket = TRUE;
  1011. need_comma = FALSE;
  1012. continue;
  1013. }
  1014. need_comma = TRUE;
  1015. /* Print the operand as directed by the flags. */
  1016. if (operand->flags & ARC_OPERAND_IR)
  1017. {
  1018. const char *rname;
  1019. assert (value >=0 && value < 64);
  1020. rname = arcExtMap_coreRegName (value);
  1021. if (!rname)
  1022. rname = regnames[value];
  1023. (*info->fprintf_func) (info->stream, "%s", rname);
  1024. if (operand->flags & ARC_OPERAND_TRUNCATE)
  1025. {
  1026. rname = arcExtMap_coreRegName (value + 1);
  1027. if (!rname)
  1028. rname = regnames[value + 1];
  1029. (*info->fprintf_func) (info->stream, "%s", rname);
  1030. }
  1031. }
  1032. else if (operand->flags & ARC_OPERAND_LIMM)
  1033. {
  1034. const char *rname = get_auxreg (opcode, value, isa_mask);
  1035. if (rname && open_braket)
  1036. (*info->fprintf_func) (info->stream, "%s", rname);
  1037. else
  1038. {
  1039. (*info->fprintf_func) (info->stream, "%#x", value);
  1040. if (info->insn_type == dis_branch
  1041. || info->insn_type == dis_jsr)
  1042. info->target = (bfd_vma) value;
  1043. }
  1044. }
  1045. else if (operand->flags & ARC_OPERAND_PCREL)
  1046. {
  1047. /* PCL relative. */
  1048. if (info->flags & INSN_HAS_RELOC)
  1049. memaddr = 0;
  1050. (*info->print_address_func) ((memaddr & ~3) + value, info);
  1051. info->target = (bfd_vma) (memaddr & ~3) + value;
  1052. }
  1053. else if (operand->flags & ARC_OPERAND_SIGNED)
  1054. {
  1055. const char *rname = get_auxreg (opcode, value, isa_mask);
  1056. if (rname && open_braket)
  1057. (*info->fprintf_func) (info->stream, "%s", rname);
  1058. else
  1059. (*info->fprintf_func) (info->stream, "%d", value);
  1060. }
  1061. else if (operand->flags & ARC_OPERAND_ADDRTYPE)
  1062. {
  1063. const char *addrtype = get_addrtype (value);
  1064. (*info->fprintf_func) (info->stream, "%s", addrtype);
  1065. /* A colon follow an address type. */
  1066. need_comma = FALSE;
  1067. }
  1068. else
  1069. {
  1070. if (operand->flags & ARC_OPERAND_TRUNCATE
  1071. && !(operand->flags & ARC_OPERAND_ALIGNED32)
  1072. && !(operand->flags & ARC_OPERAND_ALIGNED16)
  1073. && value >= 0 && value <= 14)
  1074. {
  1075. switch (value)
  1076. {
  1077. case 0:
  1078. need_comma = FALSE;
  1079. break;
  1080. case 1:
  1081. (*info->fprintf_func) (info->stream, "r13");
  1082. break;
  1083. default:
  1084. (*info->fprintf_func) (info->stream, "r13-%s",
  1085. regnames[13 + value - 1]);
  1086. break;
  1087. }
  1088. }
  1089. else
  1090. {
  1091. const char *rname = get_auxreg (opcode, value, isa_mask);
  1092. if (rname && open_braket)
  1093. (*info->fprintf_func) (info->stream, "%s", rname);
  1094. else
  1095. (*info->fprintf_func) (info->stream, "%#x", value);
  1096. }
  1097. }
  1098. if (operand->flags & ARC_OPERAND_LIMM)
  1099. {
  1100. arc_infop->operands[arc_infop->operands_count].kind
  1101. = ARC_OPERAND_KIND_LIMM;
  1102. /* It is not important to have exactly the LIMM indicator
  1103. here. */
  1104. arc_infop->operands[arc_infop->operands_count].value = 63;
  1105. }
  1106. else
  1107. {
  1108. arc_infop->operands[arc_infop->operands_count].value = value;
  1109. arc_infop->operands[arc_infop->operands_count].kind
  1110. = (operand->flags & ARC_OPERAND_IR
  1111. ? ARC_OPERAND_KIND_REG
  1112. : ARC_OPERAND_KIND_SHIMM);
  1113. }
  1114. arc_infop->operands_count ++;
  1115. }
  1116. return insn_len;
  1117. }
  1118. disassembler_ftype
  1119. arc_get_disassembler (bfd *abfd)
  1120. {
  1121. /* BFD my be absent, if opcodes is invoked from the debugger that
  1122. has connected to remote target and doesn't have an ELF file. */
  1123. if (abfd != NULL)
  1124. {
  1125. /* Read the extension insns and registers, if any. */
  1126. build_ARC_extmap (abfd);
  1127. #ifdef DEBUG
  1128. dump_ARC_extmap ();
  1129. #endif
  1130. }
  1131. return print_insn_arc;
  1132. }
  1133. void
  1134. print_arc_disassembler_options (FILE *stream)
  1135. {
  1136. int i;
  1137. fprintf (stream, _("\n\
  1138. The following ARC specific disassembler options are supported for use \n\
  1139. with -M switch (multiple options should be separated by commas):\n"));
  1140. /* cpu=... options. */
  1141. for (i = 0; cpu_types[i].name; ++i)
  1142. {
  1143. /* As of now all value CPU values are less than 16 characters. */
  1144. fprintf (stream, " cpu=%-16s\tEnforce %s ISA.\n",
  1145. cpu_types[i].name, cpu_types[i].isa);
  1146. }
  1147. fprintf (stream, _("\
  1148. dsp Recognize DSP instructions.\n"));
  1149. fprintf (stream, _("\
  1150. spfp Recognize FPX SP instructions.\n"));
  1151. fprintf (stream, _("\
  1152. dpfp Recognize FPX DP instructions.\n"));
  1153. fprintf (stream, _("\
  1154. quarkse_em Recognize FPU QuarkSE-EM instructions.\n"));
  1155. fprintf (stream, _("\
  1156. fpuda Recognize double assist FPU instructions.\n"));
  1157. fprintf (stream, _("\
  1158. fpus Recognize single precision FPU instructions.\n"));
  1159. fprintf (stream, _("\
  1160. fpud Recognize double precision FPU instructions.\n"));
  1161. }
  1162. void arc_insn_decode (bfd_vma addr,
  1163. struct disassemble_info *info,
  1164. disassembler_ftype disasm_func,
  1165. struct arc_instruction *insn)
  1166. {
  1167. const struct arc_opcode *opcode;
  1168. struct arc_disassemble_info *arc_infop;
  1169. /* Ensure that insn would be in the reset state. */
  1170. memset (insn, 0, sizeof (struct arc_instruction));
  1171. /* There was an error when disassembling, for example memory read error. */
  1172. if (disasm_func (addr, info) < 0)
  1173. {
  1174. insn->valid = FALSE;
  1175. return;
  1176. }
  1177. assert (info->private_data != NULL);
  1178. arc_infop = info->private_data;
  1179. insn->length = arc_infop->insn_len;;
  1180. insn->address = addr;
  1181. /* Quick exit if memory at this address is not an instruction. */
  1182. if (info->insn_type == dis_noninsn)
  1183. {
  1184. insn->valid = FALSE;
  1185. return;
  1186. }
  1187. insn->valid = TRUE;
  1188. opcode = (const struct arc_opcode *) arc_infop->opcode;
  1189. insn->insn_class = opcode->insn_class;
  1190. insn->limm_value = arc_infop->limm;
  1191. insn->limm_p = arc_infop->limm_p;
  1192. insn->is_control_flow = (info->insn_type == dis_branch
  1193. || info->insn_type == dis_condbranch
  1194. || info->insn_type == dis_jsr
  1195. || info->insn_type == dis_condjsr);
  1196. insn->has_delay_slot = info->branch_delay_insns;
  1197. insn->writeback_mode
  1198. = (enum arc_ldst_writeback_mode) arc_infop->writeback_mode;
  1199. insn->data_size_mode = info->data_size;
  1200. insn->condition_code = arc_infop->condition_code;
  1201. memcpy (insn->operands, arc_infop->operands,
  1202. sizeof (struct arc_insn_operand) * MAX_INSN_ARGS);
  1203. insn->operands_count = arc_infop->operands_count;
  1204. }
  1205. /* Local variables:
  1206. eval: (c-set-style "gnu")
  1207. indent-tabs-mode: t
  1208. End: */