tic30-dis.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /* Disassembly routines for TMS320C30 architecture
  2. Copyright (C) 1998-2015 Free Software Foundation, Inc.
  3. Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
  4. This file is part of the GNU opcodes library.
  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 file; see the file COPYING. If not, write to the
  15. Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include <errno.h>
  19. #include <math.h>
  20. #include "dis-asm.h"
  21. #include "opcode/tic30.h"
  22. #define NORMAL_INSN 1
  23. #define PARALLEL_INSN 2
  24. /* Gets the type of instruction based on the top 2 or 3 bits of the
  25. instruction word. */
  26. #define GET_TYPE(insn) (insn & 0x80000000 ? insn & 0xC0000000 : insn & 0xE0000000)
  27. /* Instruction types. */
  28. #define TWO_OPERAND_1 0x00000000
  29. #define TWO_OPERAND_2 0x40000000
  30. #define THREE_OPERAND 0x20000000
  31. #define PAR_STORE 0xC0000000
  32. #define MUL_ADDS 0x80000000
  33. #define BRANCHES 0x60000000
  34. /* Specific instruction id bits. */
  35. #define NORMAL_IDEN 0x1F800000
  36. #define PAR_STORE_IDEN 0x3E000000
  37. #define MUL_ADD_IDEN 0x2C000000
  38. #define BR_IMM_IDEN 0x1F000000
  39. #define BR_COND_IDEN 0x1C3F0000
  40. /* Addressing modes. */
  41. #define AM_REGISTER 0x00000000
  42. #define AM_DIRECT 0x00200000
  43. #define AM_INDIRECT 0x00400000
  44. #define AM_IMM 0x00600000
  45. #define P_FIELD 0x03000000
  46. #define REG_AR0 0x08
  47. #define LDP_INSN 0x08700000
  48. /* TMS320C30 program counter for current instruction. */
  49. static unsigned int _pc;
  50. struct instruction
  51. {
  52. int type;
  53. insn_template *tm;
  54. partemplate *ptm;
  55. };
  56. static int
  57. get_tic30_instruction (unsigned long insn_word, struct instruction *insn)
  58. {
  59. switch (GET_TYPE (insn_word))
  60. {
  61. case TWO_OPERAND_1:
  62. case TWO_OPERAND_2:
  63. case THREE_OPERAND:
  64. insn->type = NORMAL_INSN;
  65. {
  66. insn_template *current_optab = (insn_template *) tic30_optab;
  67. for (; current_optab < tic30_optab_end; current_optab++)
  68. {
  69. if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
  70. {
  71. if (current_optab->operands == 0)
  72. {
  73. if (current_optab->base_opcode == insn_word)
  74. {
  75. insn->tm = current_optab;
  76. break;
  77. }
  78. }
  79. else if ((current_optab->base_opcode & NORMAL_IDEN) == (insn_word & NORMAL_IDEN))
  80. {
  81. insn->tm = current_optab;
  82. break;
  83. }
  84. }
  85. }
  86. }
  87. break;
  88. case PAR_STORE:
  89. insn->type = PARALLEL_INSN;
  90. {
  91. partemplate *current_optab = (partemplate *) tic30_paroptab;
  92. for (; current_optab < tic30_paroptab_end; current_optab++)
  93. {
  94. if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
  95. {
  96. if ((current_optab->base_opcode & PAR_STORE_IDEN)
  97. == (insn_word & PAR_STORE_IDEN))
  98. {
  99. insn->ptm = current_optab;
  100. break;
  101. }
  102. }
  103. }
  104. }
  105. break;
  106. case MUL_ADDS:
  107. insn->type = PARALLEL_INSN;
  108. {
  109. partemplate *current_optab = (partemplate *) tic30_paroptab;
  110. for (; current_optab < tic30_paroptab_end; current_optab++)
  111. {
  112. if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
  113. {
  114. if ((current_optab->base_opcode & MUL_ADD_IDEN)
  115. == (insn_word & MUL_ADD_IDEN))
  116. {
  117. insn->ptm = current_optab;
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. break;
  124. case BRANCHES:
  125. insn->type = NORMAL_INSN;
  126. {
  127. insn_template *current_optab = (insn_template *) tic30_optab;
  128. for (; current_optab < tic30_optab_end; current_optab++)
  129. {
  130. if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
  131. {
  132. if (current_optab->operand_types[0] & Imm24)
  133. {
  134. if ((current_optab->base_opcode & BR_IMM_IDEN)
  135. == (insn_word & BR_IMM_IDEN))
  136. {
  137. insn->tm = current_optab;
  138. break;
  139. }
  140. }
  141. else if (current_optab->operands > 0)
  142. {
  143. if ((current_optab->base_opcode & BR_COND_IDEN)
  144. == (insn_word & BR_COND_IDEN))
  145. {
  146. insn->tm = current_optab;
  147. break;
  148. }
  149. }
  150. else
  151. {
  152. if ((current_optab->base_opcode & (BR_COND_IDEN | 0x00800000))
  153. == (insn_word & (BR_COND_IDEN | 0x00800000)))
  154. {
  155. insn->tm = current_optab;
  156. break;
  157. }
  158. }
  159. }
  160. }
  161. }
  162. break;
  163. default:
  164. return 0;
  165. }
  166. return 1;
  167. }
  168. static int
  169. get_register_operand (unsigned char fragment, char *buffer)
  170. {
  171. const reg *current_reg = tic30_regtab;
  172. if (buffer == NULL)
  173. return 0;
  174. for (; current_reg < tic30_regtab_end; current_reg++)
  175. {
  176. if ((fragment & 0x1F) == current_reg->opcode)
  177. {
  178. strcpy (buffer, current_reg->name);
  179. return 1;
  180. }
  181. }
  182. return 0;
  183. }
  184. static int
  185. get_indirect_operand (unsigned short fragment,
  186. int size,
  187. char *buffer)
  188. {
  189. unsigned char mod;
  190. unsigned arnum;
  191. unsigned char disp;
  192. if (buffer == NULL)
  193. return 0;
  194. /* Determine which bits identify the sections of the indirect
  195. operand based on the size in bytes. */
  196. switch (size)
  197. {
  198. case 1:
  199. mod = (fragment & 0x00F8) >> 3;
  200. arnum = (fragment & 0x0007);
  201. disp = 0;
  202. break;
  203. case 2:
  204. mod = (fragment & 0xF800) >> 11;
  205. arnum = (fragment & 0x0700) >> 8;
  206. disp = (fragment & 0x00FF);
  207. break;
  208. default:
  209. return 0;
  210. }
  211. {
  212. const ind_addr_type *current_ind = tic30_indaddr_tab;
  213. for (; current_ind < tic30_indaddrtab_end; current_ind++)
  214. {
  215. if (current_ind->modfield == mod)
  216. {
  217. if (current_ind->displacement == IMPLIED_DISP && size == 2)
  218. continue;
  219. else
  220. {
  221. size_t i, len;
  222. int bufcnt;
  223. len = strlen (current_ind->syntax);
  224. for (i = 0, bufcnt = 0; i < len; i++, bufcnt++)
  225. {
  226. buffer[bufcnt] = current_ind->syntax[i];
  227. if (buffer[bufcnt - 1] == 'a' && buffer[bufcnt] == 'r')
  228. buffer[++bufcnt] = arnum + '0';
  229. if (buffer[bufcnt] == '('
  230. && current_ind->displacement == DISP_REQUIRED)
  231. {
  232. sprintf (&buffer[bufcnt + 1], "%u", disp);
  233. bufcnt += strlen (&buffer[bufcnt + 1]);
  234. }
  235. }
  236. buffer[bufcnt + 1] = '\0';
  237. break;
  238. }
  239. }
  240. }
  241. }
  242. return 1;
  243. }
  244. static int
  245. cnvt_tmsfloat_ieee (unsigned long tmsfloat, int size, float *ieeefloat)
  246. {
  247. unsigned long exponent, sign, mant;
  248. union
  249. {
  250. unsigned long l;
  251. float f;
  252. } val;
  253. if (size == 2)
  254. {
  255. if ((tmsfloat & 0x0000F000) == 0x00008000)
  256. tmsfloat = 0x80000000;
  257. else
  258. {
  259. tmsfloat <<= 16;
  260. tmsfloat = (long) tmsfloat >> 4;
  261. }
  262. }
  263. exponent = tmsfloat & 0xFF000000;
  264. if (exponent == 0x80000000)
  265. {
  266. *ieeefloat = 0.0;
  267. return 1;
  268. }
  269. exponent += 0x7F000000;
  270. sign = (tmsfloat & 0x00800000) << 8;
  271. mant = tmsfloat & 0x007FFFFF;
  272. if (exponent == 0xFF000000)
  273. {
  274. if (mant == 0)
  275. *ieeefloat = ERANGE;
  276. #ifdef HUGE_VALF
  277. if (sign == 0)
  278. *ieeefloat = HUGE_VALF;
  279. else
  280. *ieeefloat = -HUGE_VALF;
  281. #else
  282. if (sign == 0)
  283. *ieeefloat = 1.0 / 0.0;
  284. else
  285. *ieeefloat = -1.0 / 0.0;
  286. #endif
  287. return 1;
  288. }
  289. exponent >>= 1;
  290. if (sign)
  291. {
  292. mant = (~mant) & 0x007FFFFF;
  293. mant += 1;
  294. exponent += mant & 0x00800000;
  295. exponent &= 0x7F800000;
  296. mant &= 0x007FFFFF;
  297. }
  298. if (tmsfloat == 0x80000000)
  299. sign = mant = exponent = 0;
  300. tmsfloat = sign | exponent | mant;
  301. val.l = tmsfloat;
  302. *ieeefloat = val.f;
  303. return 1;
  304. }
  305. static int
  306. print_two_operand (disassemble_info *info,
  307. unsigned long insn_word,
  308. struct instruction *insn)
  309. {
  310. char name[12];
  311. char operand[2][13] =
  312. {
  313. {0},
  314. {0}
  315. };
  316. float f_number;
  317. if (insn->tm == NULL)
  318. return 0;
  319. strcpy (name, insn->tm->name);
  320. if (insn->tm->opcode_modifier == AddressMode)
  321. {
  322. int src_op, dest_op;
  323. /* Determine whether instruction is a store or a normal instruction. */
  324. if ((insn->tm->operand_types[1] & (Direct | Indirect))
  325. == (Direct | Indirect))
  326. {
  327. src_op = 1;
  328. dest_op = 0;
  329. }
  330. else
  331. {
  332. src_op = 0;
  333. dest_op = 1;
  334. }
  335. /* Get the destination register. */
  336. if (insn->tm->operands == 2)
  337. get_register_operand ((insn_word & 0x001F0000) >> 16, operand[dest_op]);
  338. /* Get the source operand based on addressing mode. */
  339. switch (insn_word & AddressMode)
  340. {
  341. case AM_REGISTER:
  342. /* Check for the NOP instruction before getting the operand. */
  343. if ((insn->tm->operand_types[0] & NotReq) == 0)
  344. get_register_operand ((insn_word & 0x0000001F), operand[src_op]);
  345. break;
  346. case AM_DIRECT:
  347. sprintf (operand[src_op], "@0x%lX", (insn_word & 0x0000FFFF));
  348. break;
  349. case AM_INDIRECT:
  350. get_indirect_operand ((insn_word & 0x0000FFFF), 2, operand[src_op]);
  351. break;
  352. case AM_IMM:
  353. /* Get the value of the immediate operand based on variable type. */
  354. switch (insn->tm->imm_arg_type)
  355. {
  356. case Imm_Float:
  357. cnvt_tmsfloat_ieee ((insn_word & 0x0000FFFF), 2, &f_number);
  358. sprintf (operand[src_op], "%2.2f", f_number);
  359. break;
  360. case Imm_SInt:
  361. sprintf (operand[src_op], "%d", (short) (insn_word & 0x0000FFFF));
  362. break;
  363. case Imm_UInt:
  364. sprintf (operand[src_op], "%lu", (insn_word & 0x0000FFFF));
  365. break;
  366. default:
  367. return 0;
  368. }
  369. /* Handle special case for LDP instruction. */
  370. if ((insn_word & 0xFFFFFF00) == LDP_INSN)
  371. {
  372. strcpy (name, "ldp");
  373. sprintf (operand[0], "0x%06lX", (insn_word & 0x000000FF) << 16);
  374. operand[1][0] = '\0';
  375. }
  376. }
  377. }
  378. /* Handle case for stack and rotate instructions. */
  379. else if (insn->tm->operands == 1)
  380. {
  381. if (insn->tm->opcode_modifier == StackOp)
  382. get_register_operand ((insn_word & 0x001F0000) >> 16, operand[0]);
  383. }
  384. /* Output instruction to stream. */
  385. info->fprintf_func (info->stream, " %s %s%c%s", name,
  386. operand[0][0] ? operand[0] : "",
  387. operand[1][0] ? ',' : ' ',
  388. operand[1][0] ? operand[1] : "");
  389. return 1;
  390. }
  391. static int
  392. print_three_operand (disassemble_info *info,
  393. unsigned long insn_word,
  394. struct instruction *insn)
  395. {
  396. char operand[3][13] =
  397. {
  398. {0},
  399. {0},
  400. {0}
  401. };
  402. if (insn->tm == NULL)
  403. return 0;
  404. switch (insn_word & AddressMode)
  405. {
  406. case AM_REGISTER:
  407. get_register_operand ((insn_word & 0x000000FF), operand[0]);
  408. get_register_operand ((insn_word & 0x0000FF00) >> 8, operand[1]);
  409. break;
  410. case AM_DIRECT:
  411. get_register_operand ((insn_word & 0x000000FF), operand[0]);
  412. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1]);
  413. break;
  414. case AM_INDIRECT:
  415. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0]);
  416. get_register_operand ((insn_word & 0x0000FF00) >> 8, operand[1]);
  417. break;
  418. case AM_IMM:
  419. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0]);
  420. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1]);
  421. break;
  422. default:
  423. return 0;
  424. }
  425. if (insn->tm->operands == 3)
  426. get_register_operand ((insn_word & 0x001F0000) >> 16, operand[2]);
  427. info->fprintf_func (info->stream, " %s %s,%s%c%s", insn->tm->name,
  428. operand[0], operand[1],
  429. operand[2][0] ? ',' : ' ',
  430. operand[2][0] ? operand[2] : "");
  431. return 1;
  432. }
  433. static int
  434. print_par_insn (disassemble_info *info,
  435. unsigned long insn_word,
  436. struct instruction *insn)
  437. {
  438. size_t i, len;
  439. char *name1, *name2;
  440. char operand[2][3][13] =
  441. {
  442. {
  443. {0},
  444. {0},
  445. {0}
  446. },
  447. {
  448. {0},
  449. {0},
  450. {0}
  451. }
  452. };
  453. if (insn->ptm == NULL)
  454. return 0;
  455. /* Parse out the names of each of the parallel instructions from the
  456. q_insn1_insn2 format. */
  457. name1 = (char *) strdup (insn->ptm->name + 2);
  458. name2 = "";
  459. len = strlen (name1);
  460. for (i = 0; i < len; i++)
  461. {
  462. if (name1[i] == '_')
  463. {
  464. name2 = &name1[i + 1];
  465. name1[i] = '\0';
  466. break;
  467. }
  468. }
  469. /* Get the operands of the instruction based on the operand order. */
  470. switch (insn->ptm->oporder)
  471. {
  472. case OO_4op1:
  473. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
  474. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
  475. get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
  476. get_register_operand ((insn_word >> 22) & 0x07, operand[0][1]);
  477. break;
  478. case OO_4op2:
  479. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
  480. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][0]);
  481. get_register_operand ((insn_word >> 19) & 0x07, operand[1][1]);
  482. get_register_operand ((insn_word >> 22) & 0x07, operand[0][1]);
  483. break;
  484. case OO_4op3:
  485. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
  486. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
  487. get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
  488. get_register_operand ((insn_word >> 22) & 0x07, operand[0][0]);
  489. break;
  490. case OO_5op1:
  491. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
  492. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
  493. get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
  494. get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
  495. get_register_operand ((insn_word >> 22) & 0x07, operand[0][2]);
  496. break;
  497. case OO_5op2:
  498. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
  499. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
  500. get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
  501. get_register_operand ((insn_word >> 19) & 0x07, operand[0][0]);
  502. get_register_operand ((insn_word >> 22) & 0x07, operand[0][2]);
  503. break;
  504. case OO_PField:
  505. if (insn_word & 0x00800000)
  506. get_register_operand (0x01, operand[0][2]);
  507. else
  508. get_register_operand (0x00, operand[0][2]);
  509. if (insn_word & 0x00400000)
  510. get_register_operand (0x03, operand[1][2]);
  511. else
  512. get_register_operand (0x02, operand[1][2]);
  513. switch (insn_word & P_FIELD)
  514. {
  515. case 0x00000000:
  516. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
  517. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
  518. get_register_operand ((insn_word >> 16) & 0x07, operand[1][1]);
  519. get_register_operand ((insn_word >> 19) & 0x07, operand[1][0]);
  520. break;
  521. case 0x01000000:
  522. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][0]);
  523. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
  524. get_register_operand ((insn_word >> 16) & 0x07, operand[1][1]);
  525. get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
  526. break;
  527. case 0x02000000:
  528. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][1]);
  529. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][0]);
  530. get_register_operand ((insn_word >> 16) & 0x07, operand[0][1]);
  531. get_register_operand ((insn_word >> 19) & 0x07, operand[0][0]);
  532. break;
  533. case 0x03000000:
  534. get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][1]);
  535. get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
  536. get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
  537. get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
  538. break;
  539. }
  540. break;
  541. default:
  542. return 0;
  543. }
  544. info->fprintf_func (info->stream, " %s %s,%s%c%s", name1,
  545. operand[0][0], operand[0][1],
  546. operand[0][2][0] ? ',' : ' ',
  547. operand[0][2][0] ? operand[0][2] : "");
  548. info->fprintf_func (info->stream, "\n\t\t\t|| %s %s,%s%c%s", name2,
  549. operand[1][0], operand[1][1],
  550. operand[1][2][0] ? ',' : ' ',
  551. operand[1][2][0] ? operand[1][2] : "");
  552. free (name1);
  553. return 1;
  554. }
  555. static int
  556. print_branch (disassemble_info *info,
  557. unsigned long insn_word,
  558. struct instruction *insn)
  559. {
  560. char operand[2][13] =
  561. {
  562. {0},
  563. {0}
  564. };
  565. unsigned long address;
  566. int print_label = 0;
  567. if (insn->tm == NULL)
  568. return 0;
  569. /* Get the operands for 24-bit immediate jumps. */
  570. if (insn->tm->operand_types[0] & Imm24)
  571. {
  572. address = insn_word & 0x00FFFFFF;
  573. sprintf (operand[0], "0x%lX", address);
  574. print_label = 1;
  575. }
  576. /* Get the operand for the trap instruction. */
  577. else if (insn->tm->operand_types[0] & IVector)
  578. {
  579. address = insn_word & 0x0000001F;
  580. sprintf (operand[0], "0x%lX", address);
  581. }
  582. else
  583. {
  584. address = insn_word & 0x0000FFFF;
  585. /* Get the operands for the DB instructions. */
  586. if (insn->tm->operands == 2)
  587. {
  588. get_register_operand (((insn_word & 0x01C00000) >> 22) + REG_AR0, operand[0]);
  589. if (insn_word & PCRel)
  590. {
  591. sprintf (operand[1], "%d", (short) address);
  592. print_label = 1;
  593. }
  594. else
  595. get_register_operand (insn_word & 0x0000001F, operand[1]);
  596. }
  597. /* Get the operands for the standard branches. */
  598. else if (insn->tm->operands == 1)
  599. {
  600. if (insn_word & PCRel)
  601. {
  602. address = (short) address;
  603. sprintf (operand[0], "%ld", address);
  604. print_label = 1;
  605. }
  606. else
  607. get_register_operand (insn_word & 0x0000001F, operand[0]);
  608. }
  609. }
  610. info->fprintf_func (info->stream, " %s %s%c%s", insn->tm->name,
  611. operand[0][0] ? operand[0] : "",
  612. operand[1][0] ? ',' : ' ',
  613. operand[1][0] ? operand[1] : "");
  614. /* Print destination of branch in relation to current symbol. */
  615. if (print_label && info->symbols)
  616. {
  617. asymbol *sym = *info->symbols;
  618. if ((insn->tm->opcode_modifier == PCRel) && (insn_word & PCRel))
  619. {
  620. address = (_pc + 1 + (short) address) - ((sym->section->vma + sym->value) / 4);
  621. /* Check for delayed instruction, if so adjust destination. */
  622. if (insn_word & 0x00200000)
  623. address += 2;
  624. }
  625. else
  626. {
  627. address -= ((sym->section->vma + sym->value) / 4);
  628. }
  629. if (address == 0)
  630. info->fprintf_func (info->stream, " <%s>", sym->name);
  631. else
  632. info->fprintf_func (info->stream, " <%s %c %lu>", sym->name,
  633. ((short) address < 0) ? '-' : '+',
  634. address);
  635. }
  636. return 1;
  637. }
  638. int
  639. print_insn_tic30 (bfd_vma pc, disassemble_info *info)
  640. {
  641. unsigned long insn_word;
  642. struct instruction insn = { 0, NULL, NULL };
  643. bfd_vma bufaddr = pc - info->buffer_vma;
  644. /* Obtain the current instruction word from the buffer. */
  645. insn_word = (*(info->buffer + bufaddr) << 24) | (*(info->buffer + bufaddr + 1) << 16) |
  646. (*(info->buffer + bufaddr + 2) << 8) | *(info->buffer + bufaddr + 3);
  647. _pc = pc / 4;
  648. /* Get the instruction refered to by the current instruction word
  649. and print it out based on its type. */
  650. if (!get_tic30_instruction (insn_word, &insn))
  651. return -1;
  652. switch (GET_TYPE (insn_word))
  653. {
  654. case TWO_OPERAND_1:
  655. case TWO_OPERAND_2:
  656. if (!print_two_operand (info, insn_word, &insn))
  657. return -1;
  658. break;
  659. case THREE_OPERAND:
  660. if (!print_three_operand (info, insn_word, &insn))
  661. return -1;
  662. break;
  663. case PAR_STORE:
  664. case MUL_ADDS:
  665. if (!print_par_insn (info, insn_word, &insn))
  666. return -1;
  667. break;
  668. case BRANCHES:
  669. if (!print_branch (info, insn_word, &insn))
  670. return -1;
  671. break;
  672. }
  673. return 4;
  674. }