You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1318 lines
34 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2006 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program 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 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "arm_disassembler.h"
  24. #include "log.h"
  25. #include <string.h>
  26. /* textual represenation of the condition field */
  27. /* ALways (default) is ommitted (empty string) */
  28. char *arm_condition_strings[] =
  29. {
  30. "EQ", "NE", "CS", "CC", "MI", "PL", "VS", "VC", "HI", "LS", "GE", "LT", "GT", "LE", "", "NV"
  31. };
  32. /* make up for C's missing ROR */
  33. u32 ror(u32 value, int places)
  34. {
  35. return (value >> places) | (value << (32 - places));
  36. }
  37. int evaluate_pld(u32 opcode, u32 address, arm_instruction_t *instruction)
  38. {
  39. /* PLD */
  40. if ((opcode & 0x0d70f0000) == 0x0550f000)
  41. {
  42. instruction->type = ARM_PLD;
  43. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tPLD ...TODO...", address, opcode);
  44. return ERROR_OK;
  45. }
  46. else
  47. {
  48. instruction->type = ARM_UNDEFINED_INSTRUCTION;
  49. return ERROR_OK;
  50. }
  51. ERROR("should never reach this point");
  52. return -1;
  53. }
  54. int evaluate_swi(u32 opcode, u32 address, arm_instruction_t *instruction)
  55. {
  56. instruction->type = ARM_SWI;
  57. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tSWI 0x%6.6x", address, opcode, (opcode & 0xffffff));
  58. return ERROR_OK;
  59. }
  60. int evaluate_blx_imm(u32 opcode, u32 address, arm_instruction_t *instruction)
  61. {
  62. int offset;
  63. u32 immediate;
  64. u32 target_address;
  65. instruction->type = ARM_BLX;
  66. immediate = opcode & 0x00ffffff;
  67. /* sign extend 24-bit immediate */
  68. if (immediate & 0x00800000)
  69. offset = 0xff000000 | immediate;
  70. else
  71. offset = immediate;
  72. /* shift two bits left */
  73. offset <<= 2;
  74. /* odd/event halfword */
  75. if (opcode & 0x01000000)
  76. offset |= 0x2;
  77. target_address = address + 8 + offset;
  78. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tBLX 0x%8.8x", address, opcode, target_address);
  79. instruction->info.b_bl_bx_blx.reg_operand = -1;
  80. instruction->info.b_bl_bx_blx.target_address = target_address;
  81. return ERROR_OK;
  82. }
  83. int evaluate_b_bl(u32 opcode, u32 address, arm_instruction_t *instruction)
  84. {
  85. u8 L;
  86. u32 immediate;
  87. int offset;
  88. u32 target_address;
  89. immediate = opcode & 0x00ffffff;
  90. L = (opcode & 0x01000000) >> 24;
  91. /* sign extend 24-bit immediate */
  92. if (immediate & 0x00800000)
  93. offset = 0xff000000 | immediate;
  94. else
  95. offset = immediate;
  96. /* shift two bits left */
  97. offset <<= 2;
  98. target_address = address + 8 + offset;
  99. if (L)
  100. instruction->type = ARM_BL;
  101. else
  102. instruction->type = ARM_B;
  103. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tB%s%s 0x%8.8x", address, opcode,
  104. (L) ? "L" : "", COND(opcode), target_address);
  105. instruction->info.b_bl_bx_blx.reg_operand = -1;
  106. instruction->info.b_bl_bx_blx.target_address = target_address;
  107. return ERROR_OK;
  108. }
  109. /* Coprocessor load/store and double register transfers */
  110. /* both normal and extended instruction space (condition field b1111) */
  111. int evaluate_ldc_stc_mcrr_mrrc(u32 opcode, u32 address, arm_instruction_t *instruction)
  112. {
  113. u8 cp_num = (opcode & 0xf00) >> 8;
  114. /* MCRR or MRRC */
  115. if (((opcode & 0x0ff00000) == 0x0c400000) || ((opcode & 0x0ff00000) == 0x0c400000))
  116. {
  117. u8 cp_opcode, Rd, Rn, CRm;
  118. char *mnemonic;
  119. cp_opcode = (opcode & 0xf0) >> 4;
  120. Rd = (opcode & 0xf000) >> 12;
  121. Rn = (opcode & 0xf0000) >> 16;
  122. CRm = (opcode & 0xf);
  123. /* MCRR */
  124. if ((opcode & 0x0ff00000) == 0x0c400000)
  125. {
  126. instruction->type = ARM_MCRR;
  127. mnemonic = "MCRR";
  128. }
  129. /* MRRC */
  130. if ((opcode & 0x0ff00000) == 0x0c500000)
  131. {
  132. instruction->type = ARM_MRRC;
  133. mnemonic = "MRRC";
  134. }
  135. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s p%i, %x, r%i, r%i, c%i",
  136. address, opcode, mnemonic, COND(opcode), cp_num, cp_opcode, Rd, Rn, CRm);
  137. }
  138. else /* LDC or STC */
  139. {
  140. u8 CRd, Rn, offset;
  141. u8 U, N;
  142. char *mnemonic;
  143. char addressing_mode[32];
  144. CRd = (opcode & 0xf000) >> 12;
  145. Rn = (opcode & 0xf0000) >> 16;
  146. offset = (opcode & 0xff);
  147. /* load/store */
  148. if (opcode & 0x00100000)
  149. {
  150. instruction->type = ARM_LDC;
  151. mnemonic = "LDC";
  152. }
  153. else
  154. {
  155. instruction->type = ARM_STC;
  156. mnemonic = "STC";
  157. }
  158. U = (opcode & 0x00800000) >> 23;
  159. N = (opcode & 0x00400000) >> 22;
  160. /* addressing modes */
  161. if ((opcode & 0x01200000) == 0x01000000) /* immediate offset */
  162. snprintf(addressing_mode, 32, "[r%i, #%s0x%2.2x*4]", Rn, (U) ? "" : "-", offset);
  163. else if ((opcode & 0x01200000) == 0x01200000) /* immediate pre-indexed */
  164. snprintf(addressing_mode, 32, "[r%i, #%s0x%2.2x*4]!", Rn, (U) ? "" : "-", offset);
  165. else if ((opcode & 0x01200000) == 0x00200000) /* immediate post-indexed */
  166. snprintf(addressing_mode, 32, "[r%i], #%s0x%2.2x*4", Rn, (U) ? "" : "-", offset);
  167. else if ((opcode & 0x01200000) == 0x00000000) /* unindexed */
  168. snprintf(addressing_mode, 32, "[r%i], #0x%2.2x", Rn, offset);
  169. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s p%i, c%i, %s",
  170. address, opcode, mnemonic, ((opcode & 0xf0000000) == 0xf0000000) ? COND(opcode) : "2",
  171. (N) ? "L" : "",
  172. cp_num, CRd, addressing_mode);
  173. }
  174. return ERROR_OK;
  175. }
  176. /* Coprocessor data processing instructions */
  177. /* Coprocessor register transfer instructions */
  178. /* both normal and extended instruction space (condition field b1111) */
  179. int evaluate_cdp_mcr_mrc(u32 opcode, u32 address, arm_instruction_t *instruction)
  180. {
  181. char* cond;
  182. char* mnemonic;
  183. u8 cp_num, opcode_1, CRd_Rd, CRn, CRm, opcode_2;
  184. cond = ((opcode & 0xf0000000) == 0xf0000000) ? "2" : COND(opcode);
  185. cp_num = (opcode & 0xf00) >> 8;
  186. CRd_Rd = (opcode & 0xf000) >> 12;
  187. CRn = (opcode & 0xf0000) >> 16;
  188. CRm = (opcode & 0xf);
  189. opcode_2 = (opcode & 0xe0) >> 5;
  190. /* CDP or MRC/MCR */
  191. if (opcode & 0x00000010) /* bit 4 set -> MRC/MCR */
  192. {
  193. if (opcode & 0x00100000) /* bit 20 set -> MRC */
  194. {
  195. instruction->type = ARM_MRC;
  196. mnemonic = "MRC";
  197. }
  198. else /* bit 20 not set -> MCR */
  199. {
  200. instruction->type = ARM_MCR;
  201. mnemonic = "MCR";
  202. }
  203. opcode_1 = (opcode & 0x00e00000) >> 21;
  204. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s p%i, 0x%2.2x, r%i, c%i, c%i, 0x%2.2x",
  205. address, opcode, mnemonic, cond,
  206. cp_num, opcode_1, CRd_Rd, CRn, CRm, opcode_2);
  207. }
  208. else /* bit 4 not set -> CDP */
  209. {
  210. instruction->type = ARM_CDP;
  211. mnemonic = "CDP";
  212. opcode_1 = (opcode & 0x00f00000) >> 20;
  213. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s p%i, 0x%2.2x, c%i, c%i, c%i, 0x%2.2x",
  214. address, opcode, mnemonic, cond,
  215. cp_num, opcode_1, CRd_Rd, CRn, CRm, opcode_2);
  216. }
  217. return ERROR_OK;
  218. }
  219. /* Load/store instructions */
  220. int evaluate_load_store(u32 opcode, u32 address, arm_instruction_t *instruction)
  221. {
  222. u8 I, P, U, B, W, L;
  223. u8 Rn, Rd;
  224. char *operation; /* "LDR" or "STR" */
  225. char *suffix; /* "", "B", "T", "BT" */
  226. char offset[32];
  227. /* examine flags */
  228. I = (opcode & 0x02000000) >> 25;
  229. P = (opcode & 0x01000000) >> 24;
  230. U = (opcode & 0x00800000) >> 23;
  231. B = (opcode & 0x00400000) >> 22;
  232. W = (opcode & 0x00200000) >> 21;
  233. L = (opcode & 0x00100000) >> 20;
  234. /* target register */
  235. Rd = (opcode & 0xf000) >> 12;
  236. /* base register */
  237. Rn = (opcode & 0xf0000) >> 16;
  238. instruction->info.load_store.Rd = Rd;
  239. instruction->info.load_store.Rn = Rn;
  240. instruction->info.load_store.U = U;
  241. /* determine operation */
  242. if (L)
  243. operation = "LDR";
  244. else
  245. operation = "STR";
  246. /* determine instruction type and suffix */
  247. if (B)
  248. {
  249. if ((P == 0) && (W == 1))
  250. {
  251. if (L)
  252. instruction->type = ARM_LDRBT;
  253. else
  254. instruction->type = ARM_STRBT;
  255. suffix = "BT";
  256. }
  257. else
  258. {
  259. if (L)
  260. instruction->type = ARM_LDRB;
  261. else
  262. instruction->type = ARM_STRB;
  263. suffix = "B";
  264. }
  265. }
  266. else
  267. {
  268. if ((P == 0) && (W == 1))
  269. {
  270. if (L)
  271. instruction->type = ARM_LDRT;
  272. else
  273. instruction->type = ARM_STRT;
  274. suffix = "T";
  275. }
  276. else
  277. {
  278. if (L)
  279. instruction->type = ARM_LDR;
  280. else
  281. instruction->type = ARM_STR;
  282. suffix = "";
  283. }
  284. }
  285. if (!I) /* #+-<offset_12> */
  286. {
  287. u32 offset_12 = (opcode & 0xfff);
  288. snprintf(offset, 32, "#%s0x%x", (U) ? "" : "-", offset_12);
  289. instruction->info.load_store.offset_mode = 0;
  290. instruction->info.load_store.offset.offset = offset_12;
  291. }
  292. else /* either +-<Rm> or +-<Rm>, <shift>, #<shift_imm> */
  293. {
  294. u8 shift_imm, shift;
  295. u8 Rm;
  296. shift_imm = (opcode & 0xf80) >> 7;
  297. shift = (opcode & 0x60) >> 5;
  298. Rm = (opcode & 0xf);
  299. /* LSR encodes a shift by 32 bit as 0x0 */
  300. if ((shift == 0x1) && (shift_imm == 0x0))
  301. shift_imm = 0x20;
  302. /* ASR encodes a shift by 32 bit as 0x0 */
  303. if ((shift == 0x2) && (shift_imm == 0x0))
  304. shift_imm = 0x20;
  305. /* ROR by 32 bit is actually a RRX */
  306. if ((shift == 0x3) && (shift_imm == 0x0))
  307. shift = 0x4;
  308. instruction->info.load_store.offset_mode = 1;
  309. instruction->info.load_store.offset.reg.Rm = Rm;
  310. instruction->info.load_store.offset.reg.shift = shift;
  311. instruction->info.load_store.offset.reg.shift_imm = shift_imm;
  312. if ((shift_imm == 0x0) && (shift == 0x0)) /* +-<Rm> */
  313. {
  314. snprintf(offset, 32, "%sr%i", (U) ? "" : "-", Rm);
  315. }
  316. else /* +-<Rm>, <Shift>, #<shift_imm> */
  317. {
  318. switch (shift)
  319. {
  320. case 0x0: /* LSL */
  321. snprintf(offset, 32, "%sr%i, LSL #0x%x", (U) ? "" : "-", Rm, shift_imm);
  322. break;
  323. case 0x1: /* LSR */
  324. snprintf(offset, 32, "%sr%i, LSR #0x%x", (U) ? "" : "-", Rm, shift_imm);
  325. break;
  326. case 0x2: /* ASR */
  327. snprintf(offset, 32, "%sr%i, ASR #0x%x", (U) ? "" : "-", Rm, shift_imm);
  328. break;
  329. case 0x3: /* ROR */
  330. snprintf(offset, 32, "%sr%i, ROR #0x%x", (U) ? "" : "-", Rm, shift_imm);
  331. break;
  332. case 0x4: /* RRX */
  333. snprintf(offset, 32, "%sr%i, RRX", (U) ? "" : "-", Rm);
  334. break;
  335. }
  336. }
  337. }
  338. if (P == 1)
  339. {
  340. if (W == 0) /* offset */
  341. {
  342. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, [r%i, %s]",
  343. address, opcode, operation, COND(opcode), suffix,
  344. Rd, Rn, offset);
  345. instruction->info.load_store.index_mode = 0;
  346. }
  347. else /* pre-indexed */
  348. {
  349. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, [r%i, %s]!",
  350. address, opcode, operation, COND(opcode), suffix,
  351. Rd, Rn, offset);
  352. instruction->info.load_store.index_mode = 1;
  353. }
  354. }
  355. else /* post-indexed */
  356. {
  357. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, [r%i], %s",
  358. address, opcode, operation, COND(opcode), suffix,
  359. Rd, Rn, offset);
  360. instruction->info.load_store.index_mode = 2;
  361. }
  362. return ERROR_OK;
  363. }
  364. /* Miscellaneous load/store instructions */
  365. int evaluate_misc_load_store(u32 opcode, u32 address, arm_instruction_t *instruction)
  366. {
  367. u8 P, U, I, W, L, S, H;
  368. u8 Rn, Rd;
  369. char *operation; /* "LDR" or "STR" */
  370. char *suffix; /* "H", "SB", "SH", "D" */
  371. char offset[32];
  372. /* examine flags */
  373. P = (opcode & 0x01000000) >> 24;
  374. U = (opcode & 0x00800000) >> 23;
  375. I = (opcode & 0x00400000) >> 22;
  376. W = (opcode & 0x00200000) >> 21;
  377. L = (opcode & 0x00100000) >> 20;
  378. S = (opcode & 0x00000040) >> 6;
  379. H = (opcode & 0x00000020) >> 5;
  380. /* target register */
  381. Rd = (opcode & 0xf000) >> 12;
  382. /* base register */
  383. Rn = (opcode & 0xf0000) >> 16;
  384. instruction->info.load_store.Rd = Rd;
  385. instruction->info.load_store.Rn = Rn;
  386. instruction->info.load_store.U = U;
  387. /* determine instruction type and suffix */
  388. if (S) /* signed */
  389. {
  390. if (L) /* load */
  391. {
  392. if (H)
  393. {
  394. operation = "LDR";
  395. instruction->type = ARM_LDRSH;
  396. suffix = "SH";
  397. }
  398. else
  399. {
  400. operation = "LDR";
  401. instruction->type = ARM_LDRSB;
  402. suffix = "SB";
  403. }
  404. }
  405. else /* there are no signed stores, so this is used to encode double-register load/stores */
  406. {
  407. suffix = "D";
  408. if (H)
  409. {
  410. operation = "STR";
  411. instruction->type = ARM_STRD;
  412. }
  413. else
  414. {
  415. operation = "LDR";
  416. instruction->type = ARM_LDRD;
  417. }
  418. }
  419. }
  420. else /* unsigned */
  421. {
  422. suffix = "H";
  423. if (L) /* load */
  424. {
  425. operation = "LDR";
  426. instruction->type = ARM_LDRH;
  427. }
  428. else /* store */
  429. {
  430. operation = "STR";
  431. instruction->type = ARM_STRH;
  432. }
  433. }
  434. if (I) /* Immediate offset/index (#+-<offset_8>)*/
  435. {
  436. u32 offset_8 = ((opcode & 0xf00) >> 4) | (opcode & 0xf);
  437. snprintf(offset, 32, "#%s0x%x", (U) ? "" : "-", offset_8);
  438. instruction->info.load_store.offset_mode = 0;
  439. instruction->info.load_store.offset.offset = offset_8;
  440. }
  441. else /* Register offset/index (+-<Rm>) */
  442. {
  443. u8 Rm;
  444. Rm = (opcode & 0xf);
  445. snprintf(offset, 32, "%sr%i", (U) ? "" : "-", Rm);
  446. instruction->info.load_store.offset_mode = 1;
  447. instruction->info.load_store.offset.reg.Rm = Rm;
  448. instruction->info.load_store.offset.reg.shift = 0x0;
  449. instruction->info.load_store.offset.reg.shift_imm = 0x0;
  450. }
  451. if (P == 1)
  452. {
  453. if (W == 0) /* offset */
  454. {
  455. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, [r%i, %s]",
  456. address, opcode, operation, COND(opcode), suffix,
  457. Rd, Rn, offset);
  458. instruction->info.load_store.index_mode = 0;
  459. }
  460. else /* pre-indexed */
  461. {
  462. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, [r%i, %s]!",
  463. address, opcode, operation, COND(opcode), suffix,
  464. Rd, Rn, offset);
  465. instruction->info.load_store.index_mode = 1;
  466. }
  467. }
  468. else /* post-indexed */
  469. {
  470. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, [r%i], %s",
  471. address, opcode, operation, COND(opcode), suffix,
  472. Rd, Rn, offset);
  473. instruction->info.load_store.index_mode = 2;
  474. }
  475. return ERROR_OK;
  476. }
  477. /* Load/store multiples instructions */
  478. int evaluate_ldm_stm(u32 opcode, u32 address, arm_instruction_t *instruction)
  479. {
  480. u8 P, U, S, W, L, Rn;
  481. u32 register_list;
  482. char *addressing_mode;
  483. char *mnemonic;
  484. char reg_list[69];
  485. char *reg_list_p;
  486. int i;
  487. int first_reg = 1;
  488. P = (opcode & 0x01000000) >> 24;
  489. U = (opcode & 0x00800000) >> 23;
  490. S = (opcode & 0x00400000) >> 22;
  491. W = (opcode & 0x00200000) >> 21;
  492. L = (opcode & 0x00100000) >> 20;
  493. register_list = (opcode & 0xffff);
  494. Rn = (opcode & 0xf0000) >> 16;
  495. instruction->info.load_store_multiple.Rn = Rn;
  496. instruction->info.load_store_multiple.register_list = register_list;
  497. instruction->info.load_store_multiple.S = S;
  498. instruction->info.load_store_multiple.W = W;
  499. if (L)
  500. {
  501. instruction->type = ARM_LDM;
  502. mnemonic = "LDM";
  503. }
  504. else
  505. {
  506. instruction->type = ARM_STM;
  507. mnemonic = "STM";
  508. }
  509. if (P)
  510. {
  511. if (U)
  512. {
  513. instruction->info.load_store_multiple.addressing_mode = 1;
  514. addressing_mode = "IB";
  515. }
  516. else
  517. {
  518. instruction->info.load_store_multiple.addressing_mode = 3;
  519. addressing_mode = "DB";
  520. }
  521. }
  522. else
  523. {
  524. if (U)
  525. {
  526. instruction->info.load_store_multiple.addressing_mode = 0;
  527. addressing_mode = "IA";
  528. }
  529. else
  530. {
  531. instruction->info.load_store_multiple.addressing_mode = 2;
  532. addressing_mode = "DA";
  533. }
  534. }
  535. reg_list_p = reg_list;
  536. for (i = 0; i <= 15; i++)
  537. {
  538. if ((register_list >> i) & 1)
  539. {
  540. if (first_reg)
  541. {
  542. first_reg = 0;
  543. reg_list_p += snprintf(reg_list_p, (reg_list + 69 - reg_list_p), "r%i", i);
  544. }
  545. else
  546. {
  547. reg_list_p += snprintf(reg_list_p, (reg_list + 69 - reg_list_p), ", r%i", i);
  548. }
  549. }
  550. }
  551. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i%s, {%s}%s",
  552. address, opcode, mnemonic, COND(opcode), addressing_mode,
  553. Rn, (W) ? "!" : "", reg_list, (S) ? "^" : "");
  554. return ERROR_OK;
  555. }
  556. /* Multiplies, extra load/stores */
  557. int evaluate_mul_and_extra_ld_st(u32 opcode, u32 address, arm_instruction_t *instruction)
  558. {
  559. /* Multiply (accumulate) (long) and Swap/swap byte */
  560. if ((opcode & 0x000000f0) == 0x00000090)
  561. {
  562. /* Multiply (accumulate) */
  563. if ((opcode & 0x0f800000) == 0x00000000)
  564. {
  565. u8 Rm, Rs, Rn, Rd, S;
  566. Rm = opcode & 0xf;
  567. Rs = (opcode & 0xf00) >> 8;
  568. Rn = (opcode & 0xf000) >> 12;
  569. Rd = (opcode & 0xf0000) >> 16;
  570. S = (opcode & 0x00100000) >> 20;
  571. /* examine A bit (accumulate) */
  572. if (opcode & 0x00200000)
  573. {
  574. instruction->type = ARM_MLA;
  575. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tMLA%s%s r%i, r%i, r%i, r%i",
  576. address, opcode, COND(opcode), (S) ? "S" : "", Rd, Rm, Rs, Rn);
  577. }
  578. else
  579. {
  580. instruction->type = ARM_MUL;
  581. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tMUL%s%s r%i, r%i, r%i",
  582. address, opcode, COND(opcode), (S) ? "S" : "", Rd, Rm, Rs);
  583. }
  584. return ERROR_OK;
  585. }
  586. /* Multiply (accumulate) long */
  587. if ((opcode & 0x0f800000) == 0x00800000)
  588. {
  589. char* mnemonic = NULL;
  590. u8 Rm, Rs, RdHi, RdLow, S;
  591. Rm = opcode & 0xf;
  592. Rs = (opcode & 0xf00) >> 8;
  593. RdHi = (opcode & 0xf000) >> 12;
  594. RdLow = (opcode & 0xf0000) >> 16;
  595. S = (opcode & 0x00100000) >> 20;
  596. switch ((opcode & 0x00600000) >> 21)
  597. {
  598. case 0x0:
  599. instruction->type = ARM_UMULL;
  600. mnemonic = "UMULL";
  601. break;
  602. case 0x1:
  603. instruction->type = ARM_UMLAL;
  604. mnemonic = "UMLAL";
  605. break;
  606. case 0x2:
  607. instruction->type = ARM_SMULL;
  608. mnemonic = "SMULL";
  609. break;
  610. case 0x3:
  611. instruction->type = ARM_SMLAL;
  612. mnemonic = "SMLAL";
  613. break;
  614. }
  615. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, r%i, r%i, r%i",
  616. address, opcode, mnemonic, COND(opcode), (S) ? "S" : "",
  617. RdLow, RdHi, Rm, Rs);
  618. return ERROR_OK;
  619. }
  620. /* Swap/swap byte */
  621. if ((opcode & 0x0f800000) == 0x01000000)
  622. {
  623. u8 Rm, Rd, Rn;
  624. Rm = opcode & 0xf;
  625. Rd = (opcode & 0xf000) >> 12;
  626. Rn = (opcode & 0xf0000) >> 16;
  627. /* examine B flag */
  628. instruction->type = (opcode & 0x00400000) ? ARM_SWPB : ARM_SWP;
  629. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s r%i, r%i, [r%i]",
  630. address, opcode, (opcode & 0x00400000) ? "SWPB" : "SWP", COND(opcode), Rd, Rm, Rn);
  631. return ERROR_OK;
  632. }
  633. }
  634. return evaluate_misc_load_store(opcode, address, instruction);
  635. }
  636. int evaluate_mrs_msr(u32 opcode, u32 address, arm_instruction_t *instruction)
  637. {
  638. int R = (opcode & 0x00400000) >> 22;
  639. char *PSR = (R) ? "SPSR" : "CPSR";
  640. /* Move register to status register (MSR) */
  641. if (opcode & 0x00200000)
  642. {
  643. instruction->type = ARM_MSR;
  644. /* immediate variant */
  645. if (opcode & 0x02000000)
  646. {
  647. u8 immediate = (opcode & 0xff);
  648. u8 rotate = (opcode & 0xf00);
  649. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tMSR%s %s_%s%s%s%s, 0x%8.8x",
  650. address, opcode, COND(opcode), PSR,
  651. (opcode & 0x10000) ? "c" : "",
  652. (opcode & 0x20000) ? "x" : "",
  653. (opcode & 0x40000) ? "s" : "",
  654. (opcode & 0x80000) ? "f" : "",
  655. ror(immediate, (rotate * 2))
  656. );
  657. }
  658. else /* register variant */
  659. {
  660. u8 Rm = opcode & 0xf;
  661. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tMSR%s %s_%s%s%s%s, r%i",
  662. address, opcode, COND(opcode), PSR,
  663. (opcode & 0x10000) ? "c" : "",
  664. (opcode & 0x20000) ? "x" : "",
  665. (opcode & 0x40000) ? "s" : "",
  666. (opcode & 0x80000) ? "f" : "",
  667. Rm
  668. );
  669. }
  670. }
  671. else /* Move status register to register (MRS) */
  672. {
  673. u8 Rd;
  674. instruction->type = ARM_MRS;
  675. Rd = (opcode & 0x0000f000) >> 12;
  676. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tMRS%s r%i, %s",
  677. address, opcode, COND(opcode), Rd, PSR);
  678. }
  679. return ERROR_OK;
  680. }
  681. /* Miscellaneous instructions */
  682. int evaluate_misc_instr(u32 opcode, u32 address, arm_instruction_t *instruction)
  683. {
  684. /* MRS/MSR */
  685. if ((opcode & 0x000000f0) == 0x00000000)
  686. {
  687. evaluate_mrs_msr(opcode, address, instruction);
  688. }
  689. /* BX */
  690. if ((opcode & 0x006000f0) == 0x00200010)
  691. {
  692. u8 Rm;
  693. instruction->type = ARM_BX;
  694. Rm = opcode & 0xf;
  695. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tBX%s r%i",
  696. address, opcode, COND(opcode), Rm);
  697. instruction->info.b_bl_bx_blx.reg_operand = Rm;
  698. instruction->info.b_bl_bx_blx.target_address = -1;
  699. }
  700. /* CLZ */
  701. if ((opcode & 0x0060000f0) == 0x00300010)
  702. {
  703. u8 Rm, Rd;
  704. instruction->type = ARM_CLZ;
  705. Rm = opcode & 0xf;
  706. Rd = (opcode & 0xf000) >> 12;
  707. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tCLZ%s r%i, r%i",
  708. address, opcode, COND(opcode), Rd, Rm);
  709. }
  710. /* BLX */
  711. if ((opcode & 0x0060000f0) == 0x00200030)
  712. {
  713. u8 Rm;
  714. instruction->type = ARM_BLX;
  715. Rm = opcode & 0xf;
  716. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tBLX%s r%i",
  717. address, opcode, COND(opcode), Rm);
  718. instruction->info.b_bl_bx_blx.reg_operand = Rm;
  719. instruction->info.b_bl_bx_blx.target_address = -1;
  720. }
  721. /* Enhanced DSP add/subtracts */
  722. if ((opcode & 0x0000000f0) == 0x00000050)
  723. {
  724. u8 Rm, Rd, Rn;
  725. char *mnemonic = NULL;
  726. Rm = opcode & 0xf;
  727. Rd = (opcode & 0xf000) >> 12;
  728. Rn = (opcode & 0xf0000) >> 16;
  729. switch ((opcode & 0x00600000) >> 21)
  730. {
  731. case 0x0:
  732. instruction->type = ARM_QADD;
  733. mnemonic = "QADD";
  734. break;
  735. case 0x1:
  736. instruction->type = ARM_QSUB;
  737. mnemonic = "QSUB";
  738. break;
  739. case 0x2:
  740. instruction->type = ARM_QDADD;
  741. mnemonic = "QDADD";
  742. break;
  743. case 0x3:
  744. instruction->type = ARM_QDSUB;
  745. mnemonic = "QDSUB";
  746. break;
  747. }
  748. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s r%i, r%i, r%i",
  749. address, opcode, mnemonic, COND(opcode), Rd, Rm, Rn);
  750. }
  751. /* Software breakpoints */
  752. if ((opcode & 0x0000000f0) == 0x00000070)
  753. {
  754. u32 immediate;
  755. instruction->type = ARM_BKPT;
  756. immediate = ((opcode & 0x000fff00) >> 4) | (opcode & 0xf);
  757. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tBKPT 0x%4.4x",
  758. address, opcode, immediate);
  759. }
  760. /* Enhanced DSP multiplies */
  761. if ((opcode & 0x000000090) == 0x00000080)
  762. {
  763. int x = (opcode & 0x20) >> 5;
  764. int y = (opcode & 0x40) >> 6;
  765. /* SMLA<x><y> */
  766. if ((opcode & 0x00600000) == 0x00000000)
  767. {
  768. u8 Rd, Rm, Rs, Rn;
  769. instruction->type = ARM_SMLAxy;
  770. Rd = (opcode & 0xf0000) >> 16;
  771. Rm = (opcode & 0xf);
  772. Rs = (opcode & 0xf00) >> 8;
  773. Rn = (opcode & 0xf000) >> 12;
  774. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tSMLA%s%s%s r%i, r%i, r%i, r%i",
  775. address, opcode, (x) ? "T" : "B", (y) ? "T" : "B", COND(opcode),
  776. Rd, Rm, Rs, Rn);
  777. }
  778. /* SMLAL<x><y> */
  779. if ((opcode & 0x00600000) == 0x00400000)
  780. {
  781. u8 RdLow, RdHi, Rm, Rs;
  782. instruction->type = ARM_SMLAxy;
  783. RdHi = (opcode & 0xf0000) >> 16;
  784. RdLow = (opcode & 0xf000) >> 12;
  785. Rm = (opcode & 0xf);
  786. Rs = (opcode & 0xf00) >> 8;
  787. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tSMLA%s%s%s r%i, r%i, r%i, r%i",
  788. address, opcode, (x) ? "T" : "B", (y) ? "T" : "B", COND(opcode),
  789. RdLow, RdHi, Rm, Rs);
  790. }
  791. /* SMLAW<y> */
  792. if (((opcode & 0x00600000) == 0x00100000) && (x == 0))
  793. {
  794. u8 Rd, Rm, Rs, Rn;
  795. instruction->type = ARM_SMLAWy;
  796. Rd = (opcode & 0xf0000) >> 16;
  797. Rm = (opcode & 0xf);
  798. Rs = (opcode & 0xf00) >> 8;
  799. Rn = (opcode & 0xf000) >> 12;
  800. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tSMLAW%s%s r%i, r%i, r%i, r%i",
  801. address, opcode, (y) ? "T" : "B", COND(opcode),
  802. Rd, Rm, Rs, Rn);
  803. }
  804. /* SMUL<x><y> */
  805. if ((opcode & 0x00600000) == 0x00300000)
  806. {
  807. u8 Rd, Rm, Rs;
  808. instruction->type = ARM_SMULxy;
  809. Rd = (opcode & 0xf0000) >> 16;
  810. Rm = (opcode & 0xf);
  811. Rs = (opcode & 0xf00) >> 8;
  812. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tSMULW%s%s%s r%i, r%i, r%i",
  813. address, opcode, (x) ? "T" : "B", (y) ? "T" : "B", COND(opcode),
  814. Rd, Rm, Rs);
  815. }
  816. /* SMULW<y> */
  817. if (((opcode & 0x00600000) == 0x00100000) && (x == 1))
  818. {
  819. u8 Rd, Rm, Rs;
  820. instruction->type = ARM_SMULWy;
  821. Rd = (opcode & 0xf0000) >> 16;
  822. Rm = (opcode & 0xf);
  823. Rs = (opcode & 0xf00) >> 8;
  824. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tSMULW%s%s r%i, r%i, r%i",
  825. address, opcode, (y) ? "T" : "B", COND(opcode),
  826. Rd, Rm, Rs);
  827. }
  828. }
  829. return ERROR_OK;
  830. }
  831. int evaluate_data_proc(u32 opcode, u32 address, arm_instruction_t *instruction)
  832. {
  833. u8 I, op, S, Rn, Rd;
  834. char *mnemonic = NULL;
  835. char shifter_operand[32];
  836. I = (opcode & 0x02000000) >> 25;
  837. op = (opcode & 0x01e00000) >> 21;
  838. S = (opcode & 0x00100000) >> 20;
  839. Rd = (opcode & 0xf000) >> 12;
  840. Rn = (opcode & 0xf0000) >> 16;
  841. instruction->info.data_proc.Rd = Rd;
  842. instruction->info.data_proc.Rn = Rn;
  843. instruction->info.data_proc.S = S;
  844. switch (op)
  845. {
  846. case 0x0:
  847. instruction->type = ARM_AND;
  848. mnemonic = "AND";
  849. break;
  850. case 0x1:
  851. instruction->type = ARM_EOR;
  852. mnemonic = "EOR";
  853. break;
  854. case 0x2:
  855. instruction->type = ARM_SUB;
  856. mnemonic = "SUB";
  857. break;
  858. case 0x3:
  859. instruction->type = ARM_RSB;
  860. mnemonic = "RSB";
  861. break;
  862. case 0x4:
  863. instruction->type = ARM_ADD;
  864. mnemonic = "ADD";
  865. break;
  866. case 0x5:
  867. instruction->type = ARM_ADC;
  868. mnemonic = "ADC";
  869. break;
  870. case 0x6:
  871. instruction->type = ARM_SBC;
  872. mnemonic = "SBC";
  873. break;
  874. case 0x7:
  875. instruction->type = ARM_RSC;
  876. mnemonic = "RSC";
  877. break;
  878. case 0x8:
  879. instruction->type = ARM_TST;
  880. mnemonic = "TST";
  881. break;
  882. case 0x9:
  883. instruction->type = ARM_TEQ;
  884. mnemonic = "TEQ";
  885. break;
  886. case 0xa:
  887. instruction->type = ARM_CMP;
  888. mnemonic = "CMP";
  889. break;
  890. case 0xb:
  891. instruction->type = ARM_CMN;
  892. mnemonic = "CMN";
  893. break;
  894. case 0xc:
  895. instruction->type = ARM_ORR;
  896. mnemonic = "ORR";
  897. break;
  898. case 0xd:
  899. instruction->type = ARM_MOV;
  900. mnemonic = "MOV";
  901. break;
  902. case 0xe:
  903. instruction->type = ARM_BIC;
  904. mnemonic = "BIC";
  905. break;
  906. case 0xf:
  907. instruction->type = ARM_MVN;
  908. mnemonic = "MVN";
  909. break;
  910. }
  911. if (I) /* immediate shifter operand (#<immediate>)*/
  912. {
  913. u8 immed_8 = opcode & 0xff;
  914. u8 rotate_imm = (opcode & 0xf00) >> 8;
  915. u32 immediate;
  916. immediate = ror(immed_8, rotate_imm * 2);
  917. snprintf(shifter_operand, 32, "#0x%x", immediate);
  918. instruction->info.data_proc.variant = 0;
  919. instruction->info.data_proc.shifter_operand.immediate.immediate = immediate;
  920. }
  921. else /* register-based shifter operand */
  922. {
  923. u8 shift, Rm;
  924. shift = (opcode & 0x60) >> 5;
  925. Rm = (opcode & 0xf);
  926. if ((opcode & 0x10) != 0x10) /* Immediate shifts ("<Rm>" or "<Rm>, <shift> #<shift_immediate>") */
  927. {
  928. u8 shift_imm;
  929. shift_imm = (opcode & 0xf80) >> 7;
  930. instruction->info.data_proc.variant = 1;
  931. instruction->info.data_proc.shifter_operand.immediate_shift.Rm = Rm;
  932. instruction->info.data_proc.shifter_operand.immediate_shift.shift_imm = shift_imm;
  933. instruction->info.data_proc.shifter_operand.immediate_shift.shift = shift;
  934. /* LSR encodes a shift by 32 bit as 0x0 */
  935. if ((shift == 0x1) && (shift_imm == 0x0))
  936. shift_imm = 0x20;
  937. /* ASR encodes a shift by 32 bit as 0x0 */
  938. if ((shift == 0x2) && (shift_imm == 0x0))
  939. shift_imm = 0x20;
  940. /* ROR by 32 bit is actually a RRX */
  941. if ((shift == 0x3) && (shift_imm == 0x0))
  942. shift = 0x4;
  943. if ((shift_imm == 0x0) && (shift == 0x0))
  944. {
  945. snprintf(shifter_operand, 32, "r%i", Rm);
  946. }
  947. else
  948. {
  949. if (shift == 0x0) /* LSL */
  950. {
  951. snprintf(shifter_operand, 32, "r%i, LSL #0x%x", Rm, shift_imm);
  952. }
  953. else if (shift == 0x1) /* LSR */
  954. {
  955. snprintf(shifter_operand, 32, "r%i, LSR #0x%x", Rm, shift_imm);
  956. }
  957. else if (shift == 0x2) /* ASR */
  958. {
  959. snprintf(shifter_operand, 32, "r%i, ASR #0x%x", Rm, shift_imm);
  960. }
  961. else if (shift == 0x3) /* ROR */
  962. {
  963. snprintf(shifter_operand, 32, "r%i, ROR #0x%x", Rm, shift_imm);
  964. }
  965. else if (shift == 0x4) /* RRX */
  966. {
  967. snprintf(shifter_operand, 32, "r%i, RRX", Rm);
  968. }
  969. }
  970. }
  971. else /* Register shifts ("<Rm>, <shift> <Rs>") */
  972. {
  973. u8 Rs = (opcode & 0xf00) >> 8;
  974. instruction->info.data_proc.variant = 2;
  975. instruction->info.data_proc.shifter_operand.register_shift.Rm = Rm;
  976. instruction->info.data_proc.shifter_operand.register_shift.Rs = Rs;
  977. instruction->info.data_proc.shifter_operand.register_shift.shift = shift;
  978. if (shift == 0x0) /* LSL */
  979. {
  980. snprintf(shifter_operand, 32, "r%i, LSL r%i", Rm, Rs);
  981. }
  982. else if (shift == 0x1) /* LSR */
  983. {
  984. snprintf(shifter_operand, 32, "r%i, LSR r%i", Rm, Rs);
  985. }
  986. else if (shift == 0x2) /* ASR */
  987. {
  988. snprintf(shifter_operand, 32, "r%i, ASR r%i", Rm, Rs);
  989. }
  990. else if (shift == 0x3) /* ROR */
  991. {
  992. snprintf(shifter_operand, 32, "r%i, ROR r%i", Rm, Rs);
  993. }
  994. }
  995. }
  996. if ((op < 0x8) || (op == 0xc) || (op == 0xe)) /* <opcode3>{<cond>}{S} <Rd>, <Rn>, <shifter_operand> */
  997. {
  998. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, r%i, %s",
  999. address, opcode, mnemonic, COND(opcode),
  1000. (S) ? "S" : "", Rd, Rn, shifter_operand);
  1001. }
  1002. else if ((op == 0xd) || (op == 0xf)) /* <opcode1>{<cond>}{S} <Rd>, <shifter_operand> */
  1003. {
  1004. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s%s r%i, %s",
  1005. address, opcode, mnemonic, COND(opcode),
  1006. (S) ? "S" : "", Rd, shifter_operand);
  1007. }
  1008. else /* <opcode2>{<cond>} <Rn>, <shifter_operand> */
  1009. {
  1010. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\t%s%s r%i, %s",
  1011. address, opcode, mnemonic, COND(opcode),
  1012. Rn, shifter_operand);
  1013. }
  1014. return ERROR_OK;
  1015. }
  1016. int arm_evaluate_opcode(u32 opcode, u32 address, arm_instruction_t *instruction)
  1017. {
  1018. /* clear fields, to avoid confusion */
  1019. memset(instruction, 0, sizeof(arm_instruction_t));
  1020. instruction->opcode = opcode;
  1021. /* catch opcodes with condition field [31:28] = b1111 */
  1022. if ((opcode & 0xf0000000) == 0xf0000000)
  1023. {
  1024. /* Undefined instruction (or ARMv5E cache preload PLD) */
  1025. if ((opcode & 0x08000000) == 0x00000000)
  1026. return evaluate_pld(opcode, address, instruction);
  1027. /* Undefined instruction */
  1028. if ((opcode & 0x0e000000) == 0x08000000)
  1029. {
  1030. instruction->type = ARM_UNDEFINED_INSTRUCTION;
  1031. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tUNDEFINED INSTRUCTION", address, opcode);
  1032. return ERROR_OK;
  1033. }
  1034. /* Branch and branch with link and change to Thumb */
  1035. if ((opcode & 0x0e000000) == 0x0a000000)
  1036. return evaluate_blx_imm(opcode, address, instruction);
  1037. /* Extended coprocessor opcode space (ARMv5 and higher )*/
  1038. /* Coprocessor load/store and double register transfers */
  1039. if ((opcode & 0x0e000000) == 0x0c000000)
  1040. return evaluate_ldc_stc_mcrr_mrrc(opcode, address, instruction);
  1041. /* Coprocessor data processing */
  1042. if ((opcode & 0x0f000100) == 0x0c000000)
  1043. return evaluate_cdp_mcr_mrc(opcode, address, instruction);
  1044. /* Coprocessor register transfers */
  1045. if ((opcode & 0x0f000010) == 0x0c000010)
  1046. return evaluate_cdp_mcr_mrc(opcode, address, instruction);
  1047. /* Undefined instruction */
  1048. if ((opcode & 0x0f000000) == 0x0f000000)
  1049. {
  1050. instruction->type = ARM_UNDEFINED_INSTRUCTION;
  1051. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tUNDEFINED INSTRUCTION", address, opcode);
  1052. return ERROR_OK;
  1053. }
  1054. }
  1055. /* catch opcodes with [27:25] = b000 */
  1056. if ((opcode & 0x0e000000) == 0x00000000)
  1057. {
  1058. /* Multiplies, extra load/stores */
  1059. if ((opcode & 0x00000090) == 0x00000090)
  1060. return evaluate_mul_and_extra_ld_st(opcode, address, instruction);
  1061. /* Miscellaneous instructions */
  1062. if ((opcode & 0x0f900000) == 0x01000000)
  1063. return evaluate_misc_instr(opcode, address, instruction);
  1064. return evaluate_data_proc(opcode, address, instruction);
  1065. }
  1066. /* catch opcodes with [27:25] = b001 */
  1067. if ((opcode & 0x0e000000) == 0x02000000)
  1068. {
  1069. /* Undefined instruction */
  1070. if ((opcode & 0x0fb00000) == 0x03000000)
  1071. {
  1072. instruction->type = ARM_UNDEFINED_INSTRUCTION;
  1073. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tUNDEFINED INSTRUCTION", address, opcode);
  1074. return ERROR_OK;
  1075. }
  1076. /* Move immediate to status register */
  1077. if ((opcode & 0x0fb00000) == 0x03200000)
  1078. return evaluate_mrs_msr(opcode, address, instruction);
  1079. return evaluate_data_proc(opcode, address, instruction);
  1080. }
  1081. /* catch opcodes with [27:25] = b010 */
  1082. if ((opcode & 0x0e000000) == 0x04000000)
  1083. {
  1084. /* Load/store immediate offset */
  1085. return evaluate_load_store(opcode, address, instruction);
  1086. }
  1087. /* catch opcodes with [27:25] = b011 */
  1088. if ((opcode & 0x0e000000) == 0x06000000)
  1089. {
  1090. /* Undefined instruction */
  1091. if ((opcode & 0x00000010) == 0x00000010)
  1092. {
  1093. instruction->type = ARM_UNDEFINED_INSTRUCTION;
  1094. snprintf(instruction->text, 128, "0x%8.8x\t0x%8.8x\tUNDEFINED INSTRUCTION", address, opcode);
  1095. return ERROR_OK;
  1096. }
  1097. /* Load/store register offset */
  1098. return evaluate_load_store(opcode, address, instruction);
  1099. }
  1100. /* catch opcodes with [27:25] = b100 */
  1101. if ((opcode & 0x0e000000) == 0x08000000)
  1102. {
  1103. /* Load/store multiple */
  1104. return evaluate_ldm_stm(opcode, address, instruction);
  1105. }
  1106. /* catch opcodes with [27:25] = b101 */
  1107. if ((opcode & 0x0e000000) == 0x0a000000)
  1108. {
  1109. /* Branch and branch with link */
  1110. return evaluate_b_bl(opcode, address, instruction);
  1111. }
  1112. /* catch opcodes with [27:25] = b110 */
  1113. if ((opcode & 0x0e000000) == 0x0a000000)
  1114. {
  1115. /* Coprocessor load/store and double register transfers */
  1116. return evaluate_ldc_stc_mcrr_mrrc(opcode, address, instruction);
  1117. }
  1118. /* catch opcodes with [27:25] = b111 */
  1119. if ((opcode & 0x0e000000) == 0x0e000000)
  1120. {
  1121. /* Software interrupt */
  1122. if ((opcode & 0x0f000000) == 0x0f000000)
  1123. return evaluate_swi(opcode, address, instruction);
  1124. /* Coprocessor data processing */
  1125. if ((opcode & 0x0f000010) == 0x0e000000)
  1126. return evaluate_cdp_mcr_mrc(opcode, address, instruction);
  1127. /* Coprocessor register transfers */
  1128. if ((opcode & 0x0f000010) == 0x0e000010)
  1129. return evaluate_cdp_mcr_mrc(opcode, address, instruction);
  1130. }
  1131. ERROR("should never reach this point");
  1132. return -1;
  1133. }