v850-dis.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /* Disassemble V850 instructions.
  2. Copyright (C) 1996-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 program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "opcode/v850.h"
  20. #include "disassemble.h"
  21. #include "opintl.h"
  22. #include "libiberty.h"
  23. static const int v850_cacheop_codes[] =
  24. {
  25. 0x00, 0x20, 0x40, 0x60, 0x61, 0x04, 0x06,
  26. 0x07, 0x24, 0x26, 0x27, 0x44, 0x64, 0x65, -1
  27. };
  28. static const int v850_prefop_codes[] =
  29. { 0x00, 0x04, -1};
  30. static void
  31. print_value (int flags,
  32. bfd_vma memaddr,
  33. struct disassemble_info *info,
  34. long value)
  35. {
  36. if (flags & V850_PCREL)
  37. {
  38. bfd_vma addr = value + memaddr;
  39. if (flags & V850_INVERSE_PCREL)
  40. addr = memaddr - value;
  41. info->print_address_func (addr, info);
  42. }
  43. else if (flags & V850_OPERAND_DISP)
  44. {
  45. if (flags & V850_OPERAND_SIGNED)
  46. {
  47. info->fprintf_func (info->stream, "%ld", value);
  48. }
  49. else
  50. {
  51. info->fprintf_func (info->stream, "%lu", value);
  52. }
  53. }
  54. else if ((flags & V850E_IMMEDIATE32)
  55. || (flags & V850E_IMMEDIATE16HI))
  56. {
  57. info->fprintf_func (info->stream, "0x%lx", value);
  58. }
  59. else
  60. {
  61. if (flags & V850_OPERAND_SIGNED)
  62. {
  63. info->fprintf_func (info->stream, "%ld", value);
  64. }
  65. else
  66. {
  67. info->fprintf_func (info->stream, "%lu", value);
  68. }
  69. }
  70. }
  71. static long
  72. get_operand_value (const struct v850_operand *operand,
  73. unsigned long insn,
  74. int bytes_read,
  75. bfd_vma memaddr,
  76. struct disassemble_info * info,
  77. bool noerror,
  78. int *invalid)
  79. {
  80. unsigned long value;
  81. bfd_byte buffer[4];
  82. if ((operand->flags & V850E_IMMEDIATE16)
  83. || (operand->flags & V850E_IMMEDIATE16HI))
  84. {
  85. int status = info->read_memory_func (memaddr + bytes_read, buffer, 2, info);
  86. if (status == 0)
  87. {
  88. value = bfd_getl16 (buffer);
  89. if (operand->flags & V850E_IMMEDIATE16HI)
  90. value <<= 16;
  91. else if (value & 0x8000)
  92. value |= (-1UL << 16);
  93. return value;
  94. }
  95. if (!noerror)
  96. info->memory_error_func (status, memaddr + bytes_read, info);
  97. return 0;
  98. }
  99. if (operand->flags & V850E_IMMEDIATE23)
  100. {
  101. int status = info->read_memory_func (memaddr + 2, buffer, 4, info);
  102. if (status == 0)
  103. {
  104. value = bfd_getl32 (buffer);
  105. value = (operand->extract) (value, invalid);
  106. return value;
  107. }
  108. if (!noerror)
  109. info->memory_error_func (status, memaddr + bytes_read, info);
  110. return 0;
  111. }
  112. if (operand->flags & V850E_IMMEDIATE32)
  113. {
  114. int status = info->read_memory_func (memaddr + bytes_read, buffer, 4, info);
  115. if (status == 0)
  116. {
  117. bytes_read += 4;
  118. value = bfd_getl32 (buffer);
  119. return value;
  120. }
  121. if (!noerror)
  122. info->memory_error_func (status, memaddr + bytes_read, info);
  123. return 0;
  124. }
  125. if (operand->extract)
  126. value = (operand->extract) (insn, invalid);
  127. else
  128. {
  129. if (operand->bits == -1)
  130. value = (insn & operand->shift);
  131. else
  132. value = (insn >> operand->shift) & ((1ul << operand->bits) - 1);
  133. if (operand->flags & V850_OPERAND_SIGNED)
  134. {
  135. unsigned long sign = 1ul << (operand->bits - 1);
  136. value = (value ^ sign) - sign;
  137. }
  138. }
  139. return value;
  140. }
  141. static const char *
  142. get_v850_sreg_name (unsigned int reg)
  143. {
  144. static const char *const v850_sreg_names[] =
  145. {
  146. "eipc/vip/mpm", "eipsw/mpc", "fepc/tid", "fepsw/ppa", "ecr/vmecr", "psw/vmtid",
  147. "sr6/fpsr/vmadr/dcc", "sr7/fpepc/dc0",
  148. "sr8/fpst/vpecr/dcv1", "sr9/fpcc/vptid", "sr10/fpcfg/vpadr/spal", "sr11/spau",
  149. "sr12/vdecr/ipa0l", "eiic/vdtid/ipa0u", "feic/ipa1l", "dbic/ipa1u",
  150. "ctpc/ipa2l", "ctpsw/ipa2u", "dbpc/ipa3l", "dbpsw/ipa3u", "ctbp/dpa0l",
  151. "dir/dpa0u", "bpc/dpa0u", "asid/dpa1l",
  152. "bpav/dpa1u", "bpam/dpa2l", "bpdv/dpa2u", "bpdm/dpa3l", "eiwr/dpa3u",
  153. "fewr", "dbwr", "bsel"
  154. };
  155. if (reg < ARRAY_SIZE (v850_sreg_names))
  156. return v850_sreg_names[reg];
  157. return _("<invalid s-reg number>");
  158. }
  159. static const char *
  160. get_v850_reg_name (unsigned int reg)
  161. {
  162. static const char *const v850_reg_names[] =
  163. {
  164. "r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7",
  165. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  166. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  167. "r24", "r25", "r26", "r27", "r28", "r29", "ep", "lp"
  168. };
  169. if (reg < ARRAY_SIZE (v850_reg_names))
  170. return v850_reg_names[reg];
  171. return _("<invalid reg number>");
  172. }
  173. static const char *
  174. get_v850_vreg_name (unsigned int reg)
  175. {
  176. static const char *const v850_vreg_names[] =
  177. {
  178. "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7", "vr8", "vr9",
  179. "vr10", "vr11", "vr12", "vr13", "vr14", "vr15", "vr16", "vr17", "vr18",
  180. "vr19", "vr20", "vr21", "vr22", "vr23", "vr24", "vr25", "vr26", "vr27",
  181. "vr28", "vr29", "vr30", "vr31"
  182. };
  183. if (reg < ARRAY_SIZE (v850_vreg_names))
  184. return v850_vreg_names[reg];
  185. return _("<invalid v-reg number>");
  186. }
  187. static const char *
  188. get_v850_cc_name (unsigned int reg)
  189. {
  190. static const char *const v850_cc_names[] =
  191. {
  192. "v", "c/l", "z", "nh", "s/n", "t", "lt", "le",
  193. "nv", "nc/nl", "nz", "h", "ns/p", "sa", "ge", "gt"
  194. };
  195. if (reg < ARRAY_SIZE (v850_cc_names))
  196. return v850_cc_names[reg];
  197. return _("<invalid CC-reg number>");
  198. }
  199. static const char *
  200. get_v850_float_cc_name (unsigned int reg)
  201. {
  202. static const char *const v850_float_cc_names[] =
  203. {
  204. "f/t", "un/or", "eq/neq", "ueq/ogl", "olt/uge", "ult/oge", "ole/ugt", "ule/ogt",
  205. "sf/st", "ngle/gle", "seq/sne", "ngl/gl", "lt/nlt", "nge/ge", "le/nle", "ngt/gt"
  206. };
  207. if (reg < ARRAY_SIZE (v850_float_cc_names))
  208. return v850_float_cc_names[reg];
  209. return _("<invalid float-CC-reg number>");
  210. }
  211. static const char *
  212. get_v850_cacheop_name (unsigned int reg)
  213. {
  214. static const char *const v850_cacheop_names[] =
  215. {
  216. "chbii", "cibii", "cfali", "cisti", "cildi", "chbid", "chbiwbd",
  217. "chbwbd", "cibid", "cibiwbd", "cibwbd", "cfald", "cistd", "cildd"
  218. };
  219. if (reg < ARRAY_SIZE (v850_cacheop_names))
  220. return v850_cacheop_names[reg];
  221. return _("<invalid cacheop number>");
  222. }
  223. static const char *
  224. get_v850_prefop_name (unsigned int reg)
  225. {
  226. static const char *const v850_prefop_names[] =
  227. { "prefi", "prefd" };
  228. if (reg < ARRAY_SIZE (v850_prefop_names))
  229. return v850_prefop_names[reg];
  230. return _("<invalid prefop number>");
  231. }
  232. static int
  233. disassemble (bfd_vma memaddr,
  234. struct disassemble_info *info,
  235. int bytes_read,
  236. unsigned long insn)
  237. {
  238. struct v850_opcode *op = (struct v850_opcode *) v850_opcodes;
  239. const struct v850_operand *operand;
  240. int match = 0;
  241. int target_processor;
  242. switch (info->mach)
  243. {
  244. case 0:
  245. default:
  246. target_processor = PROCESSOR_V850;
  247. break;
  248. case bfd_mach_v850e:
  249. target_processor = PROCESSOR_V850E;
  250. break;
  251. case bfd_mach_v850e1:
  252. target_processor = PROCESSOR_V850E;
  253. break;
  254. case bfd_mach_v850e2:
  255. target_processor = PROCESSOR_V850E2;
  256. break;
  257. case bfd_mach_v850e2v3:
  258. target_processor = PROCESSOR_V850E2V3;
  259. break;
  260. case bfd_mach_v850e3v5:
  261. target_processor = PROCESSOR_V850E3V5;
  262. break;
  263. }
  264. /* If this is a two byte insn, then mask off the high bits. */
  265. if (bytes_read == 2)
  266. insn &= 0xffff;
  267. /* Find the opcode. */
  268. while (op->name)
  269. {
  270. if ((op->mask & insn) == op->opcode
  271. && (op->processors & target_processor)
  272. && !(op->processors & PROCESSOR_OPTION_ALIAS))
  273. {
  274. /* Code check start. */
  275. const unsigned char *opindex_ptr;
  276. unsigned int opnum;
  277. unsigned int memop;
  278. for (opindex_ptr = op->operands, opnum = 1;
  279. *opindex_ptr != 0;
  280. opindex_ptr++, opnum++)
  281. {
  282. int invalid = 0;
  283. long value;
  284. operand = &v850_operands[*opindex_ptr];
  285. value = get_operand_value (operand, insn, bytes_read, memaddr,
  286. info, 1, &invalid);
  287. if (invalid)
  288. goto next_opcode;
  289. if ((operand->flags & V850_NOT_R0) && value == 0 && (op->memop) <=2)
  290. goto next_opcode;
  291. if ((operand->flags & V850_NOT_SA) && value == 0xd)
  292. goto next_opcode;
  293. if ((operand->flags & V850_NOT_IMM0) && value == 0)
  294. goto next_opcode;
  295. }
  296. /* Code check end. */
  297. match = 1;
  298. (*info->fprintf_func) (info->stream, "%s\t", op->name);
  299. #if 0
  300. fprintf (stderr, "match: insn: %lx, mask: %lx, opcode: %lx, name: %s\n",
  301. insn, op->mask, op->opcode, op->name );
  302. #endif
  303. memop = op->memop;
  304. /* Now print the operands.
  305. MEMOP is the operand number at which a memory
  306. address specification starts, or zero if this
  307. instruction has no memory addresses.
  308. A memory address is always two arguments.
  309. This information allows us to determine when to
  310. insert commas into the output stream as well as
  311. when to insert disp[reg] expressions onto the
  312. output stream. */
  313. for (opindex_ptr = op->operands, opnum = 1;
  314. *opindex_ptr != 0;
  315. opindex_ptr++, opnum++)
  316. {
  317. bool square = false;
  318. long value;
  319. int flag;
  320. char *prefix;
  321. operand = &v850_operands[*opindex_ptr];
  322. value = get_operand_value (operand, insn, bytes_read, memaddr,
  323. info, 0, 0);
  324. /* The first operand is always output without any
  325. special handling.
  326. For the following arguments:
  327. If memop && opnum == memop + 1, then we need '[' since
  328. we're about to output the register used in a memory
  329. reference.
  330. If memop && opnum == memop + 2, then we need ']' since
  331. we just finished the register in a memory reference. We
  332. also need a ',' before this operand.
  333. Else we just need a comma.
  334. We may need to output a trailing ']' if the last operand
  335. in an instruction is the register for a memory address.
  336. The exception (and there's always an exception) are the
  337. "jmp" insn which needs square brackets around it's only
  338. register argument, and the clr1/not1/set1/tst1 insns
  339. which [...] around their second register argument. */
  340. prefix = "";
  341. if (operand->flags & V850_OPERAND_BANG)
  342. {
  343. prefix = "!";
  344. }
  345. else if (operand->flags & V850_OPERAND_PERCENT)
  346. {
  347. prefix = "%";
  348. }
  349. if (opnum == 1 && opnum == memop)
  350. {
  351. info->fprintf_func (info->stream, "%s[", prefix);
  352. square = true;
  353. }
  354. else if ( (strcmp ("stc.w", op->name) == 0
  355. || strcmp ("cache", op->name) == 0
  356. || strcmp ("pref", op->name) == 0)
  357. && opnum == 2 && opnum == memop)
  358. {
  359. info->fprintf_func (info->stream, ", [");
  360. square = true;
  361. }
  362. else if ( (strcmp (op->name, "pushsp") == 0
  363. || strcmp (op->name, "popsp") == 0
  364. || strcmp (op->name, "dbpush" ) == 0)
  365. && opnum == 2)
  366. {
  367. info->fprintf_func (info->stream, "-");
  368. }
  369. else if (opnum > 1
  370. && (v850_operands[*(opindex_ptr - 1)].flags
  371. & V850_OPERAND_DISP) != 0
  372. && opnum == memop)
  373. {
  374. info->fprintf_func (info->stream, "%s[", prefix);
  375. square = true;
  376. }
  377. else if (opnum == 2
  378. && ( op->opcode == 0x00e407e0 /* clr1 */
  379. || op->opcode == 0x00e207e0 /* not1 */
  380. || op->opcode == 0x00e007e0 /* set1 */
  381. || op->opcode == 0x00e607e0 /* tst1 */
  382. ))
  383. {
  384. info->fprintf_func (info->stream, ", %s[", prefix);
  385. square = true;
  386. }
  387. else if (opnum > 1)
  388. info->fprintf_func (info->stream, ", %s", prefix);
  389. /* Extract the flags, ignoring ones which do not
  390. effect disassembly output. */
  391. flag = operand->flags & (V850_OPERAND_REG
  392. | V850_REG_EVEN
  393. | V850_OPERAND_EP
  394. | V850_OPERAND_SRG
  395. | V850E_OPERAND_REG_LIST
  396. | V850_OPERAND_CC
  397. | V850_OPERAND_VREG
  398. | V850_OPERAND_CACHEOP
  399. | V850_OPERAND_PREFOP
  400. | V850_OPERAND_FLOAT_CC);
  401. switch (flag)
  402. {
  403. case V850_OPERAND_REG:
  404. info->fprintf_func (info->stream, "%s", get_v850_reg_name (value));
  405. break;
  406. case (V850_OPERAND_REG|V850_REG_EVEN):
  407. info->fprintf_func (info->stream, "%s", get_v850_reg_name (value * 2));
  408. break;
  409. case V850_OPERAND_EP:
  410. info->fprintf_func (info->stream, "ep");
  411. break;
  412. case V850_OPERAND_SRG:
  413. info->fprintf_func (info->stream, "%s", get_v850_sreg_name (value));
  414. break;
  415. case V850E_OPERAND_REG_LIST:
  416. {
  417. static int list12_regs[32] = { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  418. 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
  419. int *regs;
  420. int i;
  421. unsigned int mask = 0;
  422. int pc = 0;
  423. switch (operand->shift)
  424. {
  425. case 0xffe00001: regs = list12_regs; break;
  426. default:
  427. /* xgettext:c-format */
  428. opcodes_error_handler (_("unknown operand shift: %x"),
  429. operand->shift);
  430. abort ();
  431. }
  432. for (i = 0; i < 32; i++)
  433. {
  434. if (value & (1u << i))
  435. {
  436. switch (regs[ i ])
  437. {
  438. default:
  439. mask |= (1u << regs[ i ]);
  440. break;
  441. case 0:
  442. /* xgettext:c-format */
  443. opcodes_error_handler (_("unknown reg: %d"), i);
  444. abort ();
  445. break;
  446. case -1:
  447. pc = 1;
  448. break;
  449. }
  450. }
  451. }
  452. info->fprintf_func (info->stream, "{");
  453. if (mask || pc)
  454. {
  455. if (mask)
  456. {
  457. unsigned int bit;
  458. int shown_one = 0;
  459. for (bit = 0; bit < 32; bit++)
  460. if (mask & (1u << bit))
  461. {
  462. unsigned int first = bit;
  463. unsigned int last;
  464. if (shown_one)
  465. info->fprintf_func (info->stream, ", ");
  466. else
  467. shown_one = 1;
  468. info->fprintf_func (info->stream, "%s", get_v850_reg_name (first));
  469. for (bit++; bit < 32; bit++)
  470. if ((mask & (1u << bit)) == 0)
  471. break;
  472. last = bit;
  473. if (last > first + 1)
  474. {
  475. info->fprintf_func (info->stream, " - %s", get_v850_reg_name (last - 1));
  476. }
  477. }
  478. }
  479. if (pc)
  480. info->fprintf_func (info->stream, "%sPC", mask ? ", " : "");
  481. }
  482. info->fprintf_func (info->stream, "}");
  483. }
  484. break;
  485. case V850_OPERAND_CC:
  486. info->fprintf_func (info->stream, "%s", get_v850_cc_name (value));
  487. break;
  488. case V850_OPERAND_FLOAT_CC:
  489. info->fprintf_func (info->stream, "%s", get_v850_float_cc_name (value));
  490. break;
  491. case V850_OPERAND_CACHEOP:
  492. {
  493. int idx;
  494. for (idx = 0; v850_cacheop_codes[idx] != -1; idx++)
  495. {
  496. if (value == v850_cacheop_codes[idx])
  497. {
  498. info->fprintf_func (info->stream, "%s",
  499. get_v850_cacheop_name (idx));
  500. goto MATCH_CACHEOP_CODE;
  501. }
  502. }
  503. info->fprintf_func (info->stream, "%d", (int) value);
  504. }
  505. MATCH_CACHEOP_CODE:
  506. break;
  507. case V850_OPERAND_PREFOP:
  508. {
  509. int idx;
  510. for (idx = 0; v850_prefop_codes[idx] != -1; idx++)
  511. {
  512. if (value == v850_prefop_codes[idx])
  513. {
  514. info->fprintf_func (info->stream, "%s",
  515. get_v850_prefop_name (idx));
  516. goto MATCH_PREFOP_CODE;
  517. }
  518. }
  519. info->fprintf_func (info->stream, "%d", (int) value);
  520. }
  521. MATCH_PREFOP_CODE:
  522. break;
  523. case V850_OPERAND_VREG:
  524. info->fprintf_func (info->stream, "%s", get_v850_vreg_name (value));
  525. break;
  526. default:
  527. print_value (operand->flags, memaddr, info, value);
  528. break;
  529. }
  530. if (square)
  531. (*info->fprintf_func) (info->stream, "]");
  532. }
  533. /* All done. */
  534. break;
  535. }
  536. next_opcode:
  537. op++;
  538. }
  539. return match;
  540. }
  541. int
  542. print_insn_v850 (bfd_vma memaddr, struct disassemble_info * info)
  543. {
  544. int status, status2, match;
  545. bfd_byte buffer[8];
  546. int length = 0, code_length = 0;
  547. unsigned long insn = 0, insn2 = 0;
  548. int target_processor;
  549. switch (info->mach)
  550. {
  551. case 0:
  552. default:
  553. target_processor = PROCESSOR_V850;
  554. break;
  555. case bfd_mach_v850e:
  556. target_processor = PROCESSOR_V850E;
  557. break;
  558. case bfd_mach_v850e1:
  559. target_processor = PROCESSOR_V850E;
  560. break;
  561. case bfd_mach_v850e2:
  562. target_processor = PROCESSOR_V850E2;
  563. break;
  564. case bfd_mach_v850e2v3:
  565. target_processor = PROCESSOR_V850E2V3;
  566. break;
  567. case bfd_mach_v850e3v5:
  568. target_processor = PROCESSOR_V850E3V5;
  569. break;
  570. }
  571. status = info->read_memory_func (memaddr, buffer, 2, info);
  572. if (status)
  573. {
  574. info->memory_error_func (status, memaddr, info);
  575. return -1;
  576. }
  577. insn = bfd_getl16 (buffer);
  578. status2 = info->read_memory_func (memaddr+2, buffer, 2 , info);
  579. if (!status2)
  580. {
  581. insn2 = bfd_getl16 (buffer);
  582. /* fprintf (stderr, "insn2 0x%08lx\n", insn2); */
  583. }
  584. /* Special case. */
  585. if (length == 0
  586. && ((target_processor & PROCESSOR_V850E2_UP) != 0))
  587. {
  588. if ((insn & 0xffff) == 0x02e0 /* jr 32bit */
  589. && !status2 && (insn2 & 0x1) == 0)
  590. {
  591. length = 2;
  592. code_length = 6;
  593. }
  594. else if ((insn & 0xffe0) == 0x02e0 /* jarl 32bit */
  595. && !status2 && (insn2 & 0x1) == 0)
  596. {
  597. length = 2;
  598. code_length = 6;
  599. }
  600. else if ((insn & 0xffe0) == 0x06e0 /* jmp 32bit */
  601. && !status2 && (insn2 & 0x1) == 0)
  602. {
  603. length = 2;
  604. code_length = 6;
  605. }
  606. }
  607. if (length == 0
  608. && ((target_processor & PROCESSOR_V850E3V5_UP) != 0))
  609. {
  610. if ( ((insn & 0xffe0) == 0x07a0 /* ld.dw 23bit (v850e3v5) */
  611. && !status2 && (insn2 & 0x000f) == 0x0009)
  612. || ((insn & 0xffe0) == 0x07a0 /* st.dw 23bit (v850e3v5) */
  613. && !status2 && (insn2 & 0x000f) == 0x000f))
  614. {
  615. length = 4;
  616. code_length = 6;
  617. }
  618. }
  619. if (length == 0
  620. && ((target_processor & PROCESSOR_V850E2V3_UP) != 0))
  621. {
  622. if (((insn & 0xffe0) == 0x0780 /* ld.b 23bit */
  623. && !status2 && (insn2 & 0x000f) == 0x0005)
  624. || ((insn & 0xffe0) == 0x07a0 /* ld.bu 23bit */
  625. && !status2 && (insn2 & 0x000f) == 0x0005)
  626. || ((insn & 0xffe0) == 0x0780 /* ld.h 23bit */
  627. && !status2 && (insn2 & 0x000f) == 0x0007)
  628. || ((insn & 0xffe0) == 0x07a0 /* ld.hu 23bit */
  629. && !status2 && (insn2 & 0x000f) == 0x0007)
  630. || ((insn & 0xffe0) == 0x0780 /* ld.w 23bit */
  631. && !status2 && (insn2 & 0x000f) == 0x0009))
  632. {
  633. length = 4;
  634. code_length = 6;
  635. }
  636. else if (((insn & 0xffe0) == 0x0780 /* st.b 23bit */
  637. && !status2 && (insn2 & 0x000f) == 0x000d)
  638. || ((insn & 0xffe0) == 0x07a0 /* st.h 23bit */
  639. && !status2 && (insn2 & 0x000f) == 0x000d)
  640. || ((insn & 0xffe0) == 0x0780 /* st.w 23bit */
  641. && !status2 && (insn2 & 0x000f) == 0x000f))
  642. {
  643. length = 4;
  644. code_length = 6;
  645. }
  646. }
  647. if (length == 0
  648. && target_processor != PROCESSOR_V850)
  649. {
  650. if ((insn & 0xffe0) == 0x0620) /* 32 bit MOV */
  651. {
  652. length = 2;
  653. code_length = 6;
  654. }
  655. else if ((insn & 0xffc0) == 0x0780 /* prepare {list}, imm5, imm16<<16 */
  656. && !status2 && (insn2 & 0x001f) == 0x0013)
  657. {
  658. length = 4;
  659. code_length = 6;
  660. }
  661. else if ((insn & 0xffc0) == 0x0780 /* prepare {list}, imm5, imm16 */
  662. && !status2 && (insn2 & 0x001f) == 0x000b)
  663. {
  664. length = 4;
  665. code_length = 6;
  666. }
  667. else if ((insn & 0xffc0) == 0x0780 /* prepare {list}, imm5, imm32 */
  668. && !status2 && (insn2 & 0x001f) == 0x001b)
  669. {
  670. length = 4;
  671. code_length = 8;
  672. }
  673. }
  674. if (length == 4
  675. || (length == 0
  676. && (insn & 0x0600) == 0x0600))
  677. {
  678. /* This is a 4 byte insn. */
  679. status = info->read_memory_func (memaddr, buffer, 4, info);
  680. if (!status)
  681. {
  682. insn = bfd_getl32 (buffer);
  683. if (!length)
  684. length = code_length = 4;
  685. }
  686. }
  687. if (code_length > length)
  688. {
  689. status = info->read_memory_func (memaddr + length, buffer, code_length - length, info);
  690. if (status)
  691. length = 0;
  692. }
  693. if (length == 0 && !status)
  694. length = code_length = 2;
  695. if (length == 2)
  696. insn &= 0xffff;
  697. /* when the last 2 bytes of section is 0xffff, length will be 0 and cause infinitive loop */
  698. if (length == 0)
  699. return -1;
  700. match = disassemble (memaddr, info, length, insn);
  701. if (!match)
  702. {
  703. int l = 0;
  704. status = info->read_memory_func (memaddr, buffer, code_length, info);
  705. while (l < code_length)
  706. {
  707. if (code_length - l == 2)
  708. {
  709. insn = bfd_getl16 (buffer + l) & 0xffff;
  710. info->fprintf_func (info->stream, ".short\t0x%04lx", insn);
  711. l += 2;
  712. }
  713. else
  714. {
  715. insn = bfd_getl32 (buffer + l);
  716. info->fprintf_func (info->stream, ".long\t0x%08lx", insn);
  717. l += 4;
  718. }
  719. }
  720. }
  721. return code_length;
  722. }