sh-dis.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /* Disassemble SH instructions.
  2. Copyright (C) 1993-2015 Free Software Foundation, Inc.
  3. This file is part of the GNU opcodes library.
  4. This library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. It is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this file; see the file COPYING. If not, write to the
  14. Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include <stdio.h>
  18. #define STATIC_TABLE
  19. #define DEFINE_TABLE
  20. #include "sh-opc.h"
  21. #include "dis-asm.h"
  22. #ifdef ARCH_all
  23. #define INCLUDE_SHMEDIA
  24. #endif
  25. static void
  26. print_movxy (const sh_opcode_info *op,
  27. int rn,
  28. int rm,
  29. fprintf_ftype fprintf_fn,
  30. void *stream)
  31. {
  32. int n;
  33. fprintf_fn (stream, "%s\t", op->name);
  34. for (n = 0; n < 2; n++)
  35. {
  36. switch (op->arg[n])
  37. {
  38. case A_IND_N:
  39. case AX_IND_N:
  40. case AXY_IND_N:
  41. case AY_IND_N:
  42. case AYX_IND_N:
  43. fprintf_fn (stream, "@r%d", rn);
  44. break;
  45. case A_INC_N:
  46. case AX_INC_N:
  47. case AXY_INC_N:
  48. case AY_INC_N:
  49. case AYX_INC_N:
  50. fprintf_fn (stream, "@r%d+", rn);
  51. break;
  52. case AX_PMOD_N:
  53. case AXY_PMOD_N:
  54. fprintf_fn (stream, "@r%d+r8", rn);
  55. break;
  56. case AY_PMOD_N:
  57. case AYX_PMOD_N:
  58. fprintf_fn (stream, "@r%d+r9", rn);
  59. break;
  60. case DSP_REG_A_M:
  61. fprintf_fn (stream, "a%c", '0' + rm);
  62. break;
  63. case DSP_REG_X:
  64. fprintf_fn (stream, "x%c", '0' + rm);
  65. break;
  66. case DSP_REG_Y:
  67. fprintf_fn (stream, "y%c", '0' + rm);
  68. break;
  69. case DSP_REG_AX:
  70. fprintf_fn (stream, "%c%c",
  71. (rm & 1) ? 'x' : 'a',
  72. (rm & 2) ? '1' : '0');
  73. break;
  74. case DSP_REG_XY:
  75. fprintf_fn (stream, "%c%c",
  76. (rm & 1) ? 'y' : 'x',
  77. (rm & 2) ? '1' : '0');
  78. break;
  79. case DSP_REG_AY:
  80. fprintf_fn (stream, "%c%c",
  81. (rm & 2) ? 'y' : 'a',
  82. (rm & 1) ? '1' : '0');
  83. break;
  84. case DSP_REG_YX:
  85. fprintf_fn (stream, "%c%c",
  86. (rm & 2) ? 'x' : 'y',
  87. (rm & 1) ? '1' : '0');
  88. break;
  89. default:
  90. abort ();
  91. }
  92. if (n == 0)
  93. fprintf_fn (stream, ",");
  94. }
  95. }
  96. /* Print a double data transfer insn. INSN is just the lower three
  97. nibbles of the insn, i.e. field a and the bit that indicates if
  98. a parallel processing insn follows.
  99. Return nonzero if a field b of a parallel processing insns follows. */
  100. static void
  101. print_insn_ddt (int insn, struct disassemble_info *info)
  102. {
  103. fprintf_ftype fprintf_fn = info->fprintf_func;
  104. void *stream = info->stream;
  105. /* If this is just a nop, make sure to emit something. */
  106. if (insn == 0x000)
  107. fprintf_fn (stream, "nopx\tnopy");
  108. /* If a parallel processing insn was printed before,
  109. and we got a non-nop, emit a tab. */
  110. if ((insn & 0x800) && (insn & 0x3ff))
  111. fprintf_fn (stream, "\t");
  112. /* Check if either the x or y part is invalid. */
  113. if (((insn & 0xc) == 0 && (insn & 0x2a0))
  114. || ((insn & 3) == 0 && (insn & 0x150)))
  115. if (info->mach != bfd_mach_sh_dsp
  116. && info->mach != bfd_mach_sh3_dsp)
  117. {
  118. static const sh_opcode_info *first_movx, *first_movy;
  119. const sh_opcode_info *op;
  120. int is_movy;
  121. if (! first_movx)
  122. {
  123. for (first_movx = sh_table; first_movx->nibbles[1] != MOVX_NOPY;)
  124. first_movx++;
  125. for (first_movy = first_movx; first_movy->nibbles[1] != MOVY_NOPX;)
  126. first_movy++;
  127. }
  128. is_movy = ((insn & 3) != 0);
  129. if (is_movy)
  130. op = first_movy;
  131. else
  132. op = first_movx;
  133. while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
  134. || op->nibbles[3] != (unsigned) (insn & 0xf))
  135. op++;
  136. print_movxy (op,
  137. (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
  138. + 2 * is_movy
  139. + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)),
  140. (insn >> 6) & 3,
  141. fprintf_fn, stream);
  142. }
  143. else
  144. fprintf_fn (stream, ".word 0x%x", insn);
  145. else
  146. {
  147. static const sh_opcode_info *first_movx, *first_movy;
  148. const sh_opcode_info *opx, *opy;
  149. unsigned int insn_x, insn_y;
  150. if (! first_movx)
  151. {
  152. for (first_movx = sh_table; first_movx->nibbles[1] != MOVX;)
  153. first_movx++;
  154. for (first_movy = first_movx; first_movy->nibbles[1] != MOVY;)
  155. first_movy++;
  156. }
  157. insn_x = (insn >> 2) & 0xb;
  158. if (insn_x)
  159. {
  160. for (opx = first_movx; opx->nibbles[2] != insn_x;)
  161. opx++;
  162. print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1,
  163. fprintf_fn, stream);
  164. }
  165. insn_y = (insn & 3) | ((insn >> 1) & 8);
  166. if (insn_y)
  167. {
  168. if (insn_x)
  169. fprintf_fn (stream, "\t");
  170. for (opy = first_movy; opy->nibbles[2] != insn_y;)
  171. opy++;
  172. print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
  173. fprintf_fn, stream);
  174. }
  175. }
  176. }
  177. static void
  178. print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
  179. {
  180. switch (rm)
  181. {
  182. case A_A1_NUM:
  183. fprintf_fn (stream, "a1");
  184. break;
  185. case A_A0_NUM:
  186. fprintf_fn (stream, "a0");
  187. break;
  188. case A_X0_NUM:
  189. fprintf_fn (stream, "x0");
  190. break;
  191. case A_X1_NUM:
  192. fprintf_fn (stream, "x1");
  193. break;
  194. case A_Y0_NUM:
  195. fprintf_fn (stream, "y0");
  196. break;
  197. case A_Y1_NUM:
  198. fprintf_fn (stream, "y1");
  199. break;
  200. case A_M0_NUM:
  201. fprintf_fn (stream, "m0");
  202. break;
  203. case A_A1G_NUM:
  204. fprintf_fn (stream, "a1g");
  205. break;
  206. case A_M1_NUM:
  207. fprintf_fn (stream, "m1");
  208. break;
  209. case A_A0G_NUM:
  210. fprintf_fn (stream, "a0g");
  211. break;
  212. default:
  213. fprintf_fn (stream, "0x%x", rm);
  214. break;
  215. }
  216. }
  217. static void
  218. print_insn_ppi (int field_b, struct disassemble_info *info)
  219. {
  220. static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
  221. static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
  222. fprintf_ftype fprintf_fn = info->fprintf_func;
  223. void *stream = info->stream;
  224. unsigned int nib1, nib2, nib3;
  225. unsigned int altnib1, nib4;
  226. char *dc = NULL;
  227. const sh_opcode_info *op;
  228. if ((field_b & 0xe800) == 0)
  229. {
  230. fprintf_fn (stream, "psh%c\t#%d,",
  231. field_b & 0x1000 ? 'a' : 'l',
  232. (field_b >> 4) & 127);
  233. print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
  234. return;
  235. }
  236. if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
  237. {
  238. static char *du_tab[] = { "x0", "y0", "a0", "a1" };
  239. static char *se_tab[] = { "x0", "x1", "y0", "a1" };
  240. static char *sf_tab[] = { "y0", "y1", "x0", "a1" };
  241. static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
  242. if (field_b & 0x2000)
  243. fprintf_fn (stream, "p%s %s,%s,%s\t",
  244. (field_b & 0x1000) ? "add" : "sub",
  245. sx_tab[(field_b >> 6) & 3],
  246. sy_tab[(field_b >> 4) & 3],
  247. du_tab[(field_b >> 0) & 3]);
  248. else if ((field_b & 0xf0) == 0x10
  249. && info->mach != bfd_mach_sh_dsp
  250. && info->mach != bfd_mach_sh3_dsp)
  251. fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
  252. else if ((field_b & 0xf3) != 0)
  253. fprintf_fn (stream, ".word 0x%x\t", field_b);
  254. fprintf_fn (stream, "pmuls%c%s,%s,%s",
  255. field_b & 0x2000 ? ' ' : '\t',
  256. se_tab[(field_b >> 10) & 3],
  257. sf_tab[(field_b >> 8) & 3],
  258. sg_tab[(field_b >> 2) & 3]);
  259. return;
  260. }
  261. nib1 = PPIC;
  262. nib2 = field_b >> 12 & 0xf;
  263. nib3 = field_b >> 8 & 0xf;
  264. nib4 = field_b >> 4 & 0xf;
  265. switch (nib3 & 0x3)
  266. {
  267. case 0:
  268. dc = "";
  269. nib1 = PPI3;
  270. break;
  271. case 1:
  272. dc = "";
  273. break;
  274. case 2:
  275. dc = "dct ";
  276. nib3 -= 1;
  277. break;
  278. case 3:
  279. dc = "dcf ";
  280. nib3 -= 2;
  281. break;
  282. }
  283. if (nib1 == PPI3)
  284. altnib1 = PPI3NC;
  285. else
  286. altnib1 = nib1;
  287. for (op = sh_table; op->name; op++)
  288. {
  289. if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
  290. && op->nibbles[2] == nib2
  291. && op->nibbles[3] == nib3)
  292. {
  293. int n;
  294. switch (op->nibbles[4])
  295. {
  296. case HEX_0:
  297. break;
  298. case HEX_XX00:
  299. if ((nib4 & 3) != 0)
  300. continue;
  301. break;
  302. case HEX_1:
  303. if ((nib4 & 3) != 1)
  304. continue;
  305. break;
  306. case HEX_00YY:
  307. if ((nib4 & 0xc) != 0)
  308. continue;
  309. break;
  310. case HEX_4:
  311. if ((nib4 & 0xc) != 4)
  312. continue;
  313. break;
  314. default:
  315. abort ();
  316. }
  317. fprintf_fn (stream, "%s%s\t", dc, op->name);
  318. for (n = 0; n < 3 && op->arg[n] != A_END; n++)
  319. {
  320. if (n && op->arg[1] != A_END)
  321. fprintf_fn (stream, ",");
  322. switch (op->arg[n])
  323. {
  324. case DSP_REG_N:
  325. print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
  326. break;
  327. case DSP_REG_X:
  328. fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
  329. break;
  330. case DSP_REG_Y:
  331. fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
  332. break;
  333. case A_MACH:
  334. fprintf_fn (stream, "mach");
  335. break;
  336. case A_MACL:
  337. fprintf_fn (stream, "macl");
  338. break;
  339. default:
  340. abort ();
  341. }
  342. }
  343. return;
  344. }
  345. }
  346. /* Not found. */
  347. fprintf_fn (stream, ".word 0x%x", field_b);
  348. }
  349. /* FIXME mvs: movx insns print as ".word 0x%03x", insn & 0xfff
  350. (ie. the upper nibble is missing). */
  351. int
  352. print_insn_sh (bfd_vma memaddr, struct disassemble_info *info)
  353. {
  354. fprintf_ftype fprintf_fn = info->fprintf_func;
  355. void *stream = info->stream;
  356. unsigned char insn[4];
  357. unsigned char nibs[8];
  358. int status;
  359. bfd_vma relmask = ~(bfd_vma) 0;
  360. const sh_opcode_info *op;
  361. unsigned int target_arch;
  362. int allow_op32;
  363. switch (info->mach)
  364. {
  365. case bfd_mach_sh:
  366. target_arch = arch_sh1;
  367. /* SH coff object files lack information about the machine type, so
  368. we end up with bfd_mach_sh unless it was set explicitly (which
  369. could have happended if this is a call from gdb or the simulator.) */
  370. if (info->symbols
  371. && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour)
  372. target_arch = arch_sh4;
  373. break;
  374. case bfd_mach_sh5:
  375. #ifdef INCLUDE_SHMEDIA
  376. status = print_insn_sh64 (memaddr, info);
  377. if (status != -2)
  378. return status;
  379. #endif
  380. /* When we get here for sh64, it's because we want to disassemble
  381. SHcompact, i.e. arch_sh4. */
  382. target_arch = arch_sh4;
  383. break;
  384. default:
  385. target_arch = sh_get_arch_from_bfd_mach (info->mach);
  386. }
  387. status = info->read_memory_func (memaddr, insn, 2, info);
  388. if (status != 0)
  389. {
  390. info->memory_error_func (status, memaddr, info);
  391. return -1;
  392. }
  393. if (info->endian == BFD_ENDIAN_LITTLE)
  394. {
  395. nibs[0] = (insn[1] >> 4) & 0xf;
  396. nibs[1] = insn[1] & 0xf;
  397. nibs[2] = (insn[0] >> 4) & 0xf;
  398. nibs[3] = insn[0] & 0xf;
  399. }
  400. else
  401. {
  402. nibs[0] = (insn[0] >> 4) & 0xf;
  403. nibs[1] = insn[0] & 0xf;
  404. nibs[2] = (insn[1] >> 4) & 0xf;
  405. nibs[3] = insn[1] & 0xf;
  406. }
  407. status = info->read_memory_func (memaddr + 2, insn + 2, 2, info);
  408. if (status != 0)
  409. allow_op32 = 0;
  410. else
  411. {
  412. allow_op32 = 1;
  413. if (info->endian == BFD_ENDIAN_LITTLE)
  414. {
  415. nibs[4] = (insn[3] >> 4) & 0xf;
  416. nibs[5] = insn[3] & 0xf;
  417. nibs[6] = (insn[2] >> 4) & 0xf;
  418. nibs[7] = insn[2] & 0xf;
  419. }
  420. else
  421. {
  422. nibs[4] = (insn[2] >> 4) & 0xf;
  423. nibs[5] = insn[2] & 0xf;
  424. nibs[6] = (insn[3] >> 4) & 0xf;
  425. nibs[7] = insn[3] & 0xf;
  426. }
  427. }
  428. if (nibs[0] == 0xf && (nibs[1] & 4) == 0
  429. && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up))
  430. {
  431. if (nibs[1] & 8)
  432. {
  433. int field_b;
  434. status = info->read_memory_func (memaddr + 2, insn, 2, info);
  435. if (status != 0)
  436. {
  437. info->memory_error_func (status, memaddr + 2, info);
  438. return -1;
  439. }
  440. if (info->endian == BFD_ENDIAN_LITTLE)
  441. field_b = insn[1] << 8 | insn[0];
  442. else
  443. field_b = insn[0] << 8 | insn[1];
  444. print_insn_ppi (field_b, info);
  445. print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
  446. return 4;
  447. }
  448. print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
  449. return 2;
  450. }
  451. for (op = sh_table; op->name; op++)
  452. {
  453. int n;
  454. int imm = 0;
  455. int rn = 0;
  456. int rm = 0;
  457. int rb = 0;
  458. int disp_pc;
  459. bfd_vma disp_pc_addr = 0;
  460. int disp = 0;
  461. int has_disp = 0;
  462. int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4;
  463. if (!allow_op32
  464. && SH_MERGE_ARCH_SET (op->arch, arch_op32))
  465. goto fail;
  466. if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch))
  467. goto fail;
  468. for (n = 0; n < max_n; n++)
  469. {
  470. int i = op->nibbles[n];
  471. if (i < 16)
  472. {
  473. if (nibs[n] == i)
  474. continue;
  475. goto fail;
  476. }
  477. switch (i)
  478. {
  479. case BRANCH_8:
  480. imm = (nibs[2] << 4) | (nibs[3]);
  481. if (imm & 0x80)
  482. imm |= ~0xff;
  483. imm = ((char) imm) * 2 + 4;
  484. goto ok;
  485. case BRANCH_12:
  486. imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
  487. if (imm & 0x800)
  488. imm |= ~0xfff;
  489. imm = imm * 2 + 4;
  490. goto ok;
  491. case IMM0_3c:
  492. if (nibs[3] & 0x8)
  493. goto fail;
  494. imm = nibs[3] & 0x7;
  495. break;
  496. case IMM0_3s:
  497. if (!(nibs[3] & 0x8))
  498. goto fail;
  499. imm = nibs[3] & 0x7;
  500. break;
  501. case IMM0_3Uc:
  502. if (nibs[2] & 0x8)
  503. goto fail;
  504. imm = nibs[2] & 0x7;
  505. break;
  506. case IMM0_3Us:
  507. if (!(nibs[2] & 0x8))
  508. goto fail;
  509. imm = nibs[2] & 0x7;
  510. break;
  511. case DISP0_12:
  512. case DISP1_12:
  513. disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7];
  514. has_disp = 1;
  515. goto ok;
  516. case DISP0_12BY2:
  517. case DISP1_12BY2:
  518. disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1;
  519. relmask = ~(bfd_vma) 1;
  520. has_disp = 1;
  521. goto ok;
  522. case DISP0_12BY4:
  523. case DISP1_12BY4:
  524. disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2;
  525. relmask = ~(bfd_vma) 3;
  526. has_disp = 1;
  527. goto ok;
  528. case DISP0_12BY8:
  529. case DISP1_12BY8:
  530. disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3;
  531. relmask = ~(bfd_vma) 7;
  532. has_disp = 1;
  533. goto ok;
  534. case IMM0_20_4:
  535. break;
  536. case IMM0_20:
  537. imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
  538. | (nibs[6] << 4) | nibs[7]);
  539. if (imm & 0x80000)
  540. imm -= 0x100000;
  541. goto ok;
  542. case IMM0_20BY8:
  543. imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
  544. | (nibs[6] << 4) | nibs[7]);
  545. imm <<= 8;
  546. if (imm & 0x8000000)
  547. imm -= 0x10000000;
  548. goto ok;
  549. case IMM0_4:
  550. case IMM1_4:
  551. imm = nibs[3];
  552. goto ok;
  553. case IMM0_4BY2:
  554. case IMM1_4BY2:
  555. imm = nibs[3] << 1;
  556. goto ok;
  557. case IMM0_4BY4:
  558. case IMM1_4BY4:
  559. imm = nibs[3] << 2;
  560. goto ok;
  561. case IMM0_8:
  562. case IMM1_8:
  563. imm = (nibs[2] << 4) | nibs[3];
  564. disp = imm;
  565. has_disp = 1;
  566. if (imm & 0x80)
  567. imm -= 0x100;
  568. goto ok;
  569. case PCRELIMM_8BY2:
  570. imm = ((nibs[2] << 4) | nibs[3]) << 1;
  571. relmask = ~(bfd_vma) 1;
  572. goto ok;
  573. case PCRELIMM_8BY4:
  574. imm = ((nibs[2] << 4) | nibs[3]) << 2;
  575. relmask = ~(bfd_vma) 3;
  576. goto ok;
  577. case IMM0_8BY2:
  578. case IMM1_8BY2:
  579. imm = ((nibs[2] << 4) | nibs[3]) << 1;
  580. goto ok;
  581. case IMM0_8BY4:
  582. case IMM1_8BY4:
  583. imm = ((nibs[2] << 4) | nibs[3]) << 2;
  584. goto ok;
  585. case REG_N_D:
  586. if ((nibs[n] & 1) != 0)
  587. goto fail;
  588. /* Fall through. */
  589. case REG_N:
  590. rn = nibs[n];
  591. break;
  592. case REG_M:
  593. rm = nibs[n];
  594. break;
  595. case REG_N_B01:
  596. if ((nibs[n] & 0x3) != 1 /* binary 01 */)
  597. goto fail;
  598. rn = (nibs[n] & 0xc) >> 2;
  599. break;
  600. case REG_NM:
  601. rn = (nibs[n] & 0xc) >> 2;
  602. rm = (nibs[n] & 0x3);
  603. break;
  604. case REG_B:
  605. rb = nibs[n] & 0x07;
  606. break;
  607. case SDT_REG_N:
  608. /* sh-dsp: single data transfer. */
  609. rn = nibs[n];
  610. if ((rn & 0xc) != 4)
  611. goto fail;
  612. rn = rn & 0x3;
  613. rn |= (!(rn & 2)) << 2;
  614. break;
  615. case PPI:
  616. case REPEAT:
  617. goto fail;
  618. default:
  619. abort ();
  620. }
  621. }
  622. ok:
  623. /* sh2a has D_REG but not X_REG. We don't know the pattern
  624. doesn't match unless we check the output args to see if they
  625. make sense. */
  626. if (target_arch == arch_sh2a
  627. && ((op->arg[0] == DX_REG_M && (rm & 1) != 0)
  628. || (op->arg[1] == DX_REG_N && (rn & 1) != 0)))
  629. goto fail;
  630. fprintf_fn (stream, "%s\t", op->name);
  631. disp_pc = 0;
  632. for (n = 0; n < 3 && op->arg[n] != A_END; n++)
  633. {
  634. if (n && op->arg[1] != A_END)
  635. fprintf_fn (stream, ",");
  636. switch (op->arg[n])
  637. {
  638. case A_IMM:
  639. fprintf_fn (stream, "#%d", imm);
  640. break;
  641. case A_R0:
  642. fprintf_fn (stream, "r0");
  643. break;
  644. case A_REG_N:
  645. fprintf_fn (stream, "r%d", rn);
  646. break;
  647. case A_INC_N:
  648. case AS_INC_N:
  649. fprintf_fn (stream, "@r%d+", rn);
  650. break;
  651. case A_DEC_N:
  652. case AS_DEC_N:
  653. fprintf_fn (stream, "@-r%d", rn);
  654. break;
  655. case A_IND_N:
  656. case AS_IND_N:
  657. fprintf_fn (stream, "@r%d", rn);
  658. break;
  659. case A_DISP_REG_N:
  660. fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn);
  661. break;
  662. case AS_PMOD_N:
  663. fprintf_fn (stream, "@r%d+r8", rn);
  664. break;
  665. case A_REG_M:
  666. fprintf_fn (stream, "r%d", rm);
  667. break;
  668. case A_INC_M:
  669. fprintf_fn (stream, "@r%d+", rm);
  670. break;
  671. case A_DEC_M:
  672. fprintf_fn (stream, "@-r%d", rm);
  673. break;
  674. case A_IND_M:
  675. fprintf_fn (stream, "@r%d", rm);
  676. break;
  677. case A_DISP_REG_M:
  678. fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm);
  679. break;
  680. case A_REG_B:
  681. fprintf_fn (stream, "r%d_bank", rb);
  682. break;
  683. case A_DISP_PC:
  684. disp_pc = 1;
  685. disp_pc_addr = imm + 4 + (memaddr & relmask);
  686. (*info->print_address_func) (disp_pc_addr, info);
  687. break;
  688. case A_IND_R0_REG_N:
  689. fprintf_fn (stream, "@(r0,r%d)", rn);
  690. break;
  691. case A_IND_R0_REG_M:
  692. fprintf_fn (stream, "@(r0,r%d)", rm);
  693. break;
  694. case A_DISP_GBR:
  695. fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm);
  696. break;
  697. case A_TBR:
  698. fprintf_fn (stream, "tbr");
  699. break;
  700. case A_DISP2_TBR:
  701. fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm);
  702. break;
  703. case A_INC_R15:
  704. fprintf_fn (stream, "@r15+");
  705. break;
  706. case A_DEC_R15:
  707. fprintf_fn (stream, "@-r15");
  708. break;
  709. case A_R0_GBR:
  710. fprintf_fn (stream, "@(r0,gbr)");
  711. break;
  712. case A_BDISP12:
  713. case A_BDISP8:
  714. (*info->print_address_func) (imm + memaddr, info);
  715. break;
  716. case A_SR:
  717. fprintf_fn (stream, "sr");
  718. break;
  719. case A_GBR:
  720. fprintf_fn (stream, "gbr");
  721. break;
  722. case A_VBR:
  723. fprintf_fn (stream, "vbr");
  724. break;
  725. case A_DSR:
  726. fprintf_fn (stream, "dsr");
  727. break;
  728. case A_MOD:
  729. fprintf_fn (stream, "mod");
  730. break;
  731. case A_RE:
  732. fprintf_fn (stream, "re");
  733. break;
  734. case A_RS:
  735. fprintf_fn (stream, "rs");
  736. break;
  737. case A_A0:
  738. fprintf_fn (stream, "a0");
  739. break;
  740. case A_X0:
  741. fprintf_fn (stream, "x0");
  742. break;
  743. case A_X1:
  744. fprintf_fn (stream, "x1");
  745. break;
  746. case A_Y0:
  747. fprintf_fn (stream, "y0");
  748. break;
  749. case A_Y1:
  750. fprintf_fn (stream, "y1");
  751. break;
  752. case DSP_REG_M:
  753. print_dsp_reg (rm, fprintf_fn, stream);
  754. break;
  755. case A_SSR:
  756. fprintf_fn (stream, "ssr");
  757. break;
  758. case A_SPC:
  759. fprintf_fn (stream, "spc");
  760. break;
  761. case A_MACH:
  762. fprintf_fn (stream, "mach");
  763. break;
  764. case A_MACL:
  765. fprintf_fn (stream, "macl");
  766. break;
  767. case A_PR:
  768. fprintf_fn (stream, "pr");
  769. break;
  770. case A_SGR:
  771. fprintf_fn (stream, "sgr");
  772. break;
  773. case A_DBR:
  774. fprintf_fn (stream, "dbr");
  775. break;
  776. case F_REG_N:
  777. fprintf_fn (stream, "fr%d", rn);
  778. break;
  779. case F_REG_M:
  780. fprintf_fn (stream, "fr%d", rm);
  781. break;
  782. case DX_REG_N:
  783. if (rn & 1)
  784. {
  785. fprintf_fn (stream, "xd%d", rn & ~1);
  786. break;
  787. }
  788. case D_REG_N:
  789. fprintf_fn (stream, "dr%d", rn);
  790. break;
  791. case DX_REG_M:
  792. if (rm & 1)
  793. {
  794. fprintf_fn (stream, "xd%d", rm & ~1);
  795. break;
  796. }
  797. case D_REG_M:
  798. fprintf_fn (stream, "dr%d", rm);
  799. break;
  800. case FPSCR_M:
  801. case FPSCR_N:
  802. fprintf_fn (stream, "fpscr");
  803. break;
  804. case FPUL_M:
  805. case FPUL_N:
  806. fprintf_fn (stream, "fpul");
  807. break;
  808. case F_FR0:
  809. fprintf_fn (stream, "fr0");
  810. break;
  811. case V_REG_N:
  812. fprintf_fn (stream, "fv%d", rn * 4);
  813. break;
  814. case V_REG_M:
  815. fprintf_fn (stream, "fv%d", rm * 4);
  816. break;
  817. case XMTRX_M4:
  818. fprintf_fn (stream, "xmtrx");
  819. break;
  820. default:
  821. abort ();
  822. }
  823. }
  824. #if 0
  825. /* This code prints instructions in delay slots on the same line
  826. as the instruction which needs the delay slots. This can be
  827. confusing, since other disassembler don't work this way, and
  828. it means that the instructions are not all in a line. So I
  829. disabled it. Ian. */
  830. if (!(info->flags & 1)
  831. && (op->name[0] == 'j'
  832. || (op->name[0] == 'b'
  833. && (op->name[1] == 'r'
  834. || op->name[1] == 's'))
  835. || (op->name[0] == 'r' && op->name[1] == 't')
  836. || (op->name[0] == 'b' && op->name[2] == '.')))
  837. {
  838. info->flags |= 1;
  839. fprintf_fn (stream, "\t(slot ");
  840. print_insn_sh (memaddr + 2, info);
  841. info->flags &= ~1;
  842. fprintf_fn (stream, ")");
  843. return 4;
  844. }
  845. #endif
  846. if (disp_pc && strcmp (op->name, "mova") != 0)
  847. {
  848. int size;
  849. bfd_byte bytes[4];
  850. if (relmask == ~(bfd_vma) 1)
  851. size = 2;
  852. else
  853. size = 4;
  854. /* Not reading an instruction - disable stop_vma. */
  855. info->stop_vma = 0;
  856. status = info->read_memory_func (disp_pc_addr, bytes, size, info);
  857. if (status == 0)
  858. {
  859. unsigned int val;
  860. if (size == 2)
  861. {
  862. if (info->endian == BFD_ENDIAN_LITTLE)
  863. val = bfd_getl16 (bytes);
  864. else
  865. val = bfd_getb16 (bytes);
  866. }
  867. else
  868. {
  869. if (info->endian == BFD_ENDIAN_LITTLE)
  870. val = bfd_getl32 (bytes);
  871. else
  872. val = bfd_getb32 (bytes);
  873. }
  874. if ((*info->symbol_at_address_func) (val, info))
  875. {
  876. fprintf_fn (stream, "\t! ");
  877. (*info->print_address_func) (val, info);
  878. }
  879. else
  880. fprintf_fn (stream, "\t! %x", val);
  881. }
  882. }
  883. return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2;
  884. fail:
  885. ;
  886. }
  887. fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
  888. return 2;
  889. }