sh-dis.c 22 KB

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