tic6x-dis.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  1. /* TI C6X disassembler.
  2. Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. Contributed by Joseph Myers <joseph@codesourcery.com>
  4. Bernd Schmidt <bernds@codesourcery.com>
  5. This file is part of libopcodes.
  6. This library is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. It is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  13. License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. MA 02110-1301, USA. */
  18. #include "sysdep.h"
  19. #include "disassemble.h"
  20. #include "opcode/tic6x.h"
  21. #include "libiberty.h"
  22. /* Define the instruction format table. */
  23. const tic6x_insn_format tic6x_insn_format_table[tic6x_insn_format_max] =
  24. {
  25. #define FMT(name, num_bits, cst_bits, mask, fields) \
  26. { num_bits, cst_bits, mask, fields },
  27. #include "opcode/tic6x-insn-formats.h"
  28. #undef FMT
  29. };
  30. /* Define the control register table. */
  31. const tic6x_ctrl tic6x_ctrl_table[tic6x_ctrl_max] =
  32. {
  33. #define CTRL(name, isa, rw, crlo, crhi_mask) \
  34. { \
  35. STRINGX(name), \
  36. CONCAT2(TIC6X_INSN_,isa), \
  37. CONCAT2(tic6x_rw_,rw), \
  38. crlo, \
  39. crhi_mask \
  40. },
  41. #include "opcode/tic6x-control-registers.h"
  42. #undef CTRL
  43. };
  44. /* Define the opcode table. */
  45. const tic6x_opcode tic6x_opcode_table[tic6x_opcode_max] =
  46. {
  47. #define INSNU(name, func_unit, format, type, isa, flags, fixed, ops, var) \
  48. { \
  49. STRINGX(name), \
  50. CONCAT2(tic6x_func_unit_,func_unit), \
  51. CONCAT3(tic6x_insn_format,_,format), \
  52. CONCAT2(tic6x_pipeline_,type), \
  53. CONCAT2(TIC6X_INSN_,isa), \
  54. flags, \
  55. fixed, \
  56. ops, \
  57. var \
  58. },
  59. #define INSNUE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
  60. { \
  61. STRINGX(name), \
  62. CONCAT2(tic6x_func_unit_,func_unit), \
  63. CONCAT3(tic6x_insn_format,_,format), \
  64. CONCAT2(tic6x_pipeline_,type), \
  65. CONCAT2(TIC6X_INSN_,isa), \
  66. flags, \
  67. fixed, \
  68. ops, \
  69. var \
  70. },
  71. #define INSN(name, func_unit, format, type, isa, flags, fixed, ops, var) \
  72. { \
  73. STRINGX(name), \
  74. CONCAT2(tic6x_func_unit_,func_unit), \
  75. CONCAT4(tic6x_insn_format_,func_unit,_,format), \
  76. CONCAT2(tic6x_pipeline_,type), \
  77. CONCAT2(TIC6X_INSN_,isa), \
  78. flags, \
  79. fixed, \
  80. ops, \
  81. var \
  82. },
  83. #define INSNE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
  84. { \
  85. STRINGX(name), \
  86. CONCAT2(tic6x_func_unit_,func_unit), \
  87. CONCAT4(tic6x_insn_format_,func_unit,_,format), \
  88. CONCAT2(tic6x_pipeline_,type), \
  89. CONCAT2(TIC6X_INSN_,isa), \
  90. flags, \
  91. fixed, \
  92. ops, \
  93. var \
  94. },
  95. #include "opcode/tic6x-opcode-table.h"
  96. #undef INSN
  97. #undef INSNE
  98. #undef INSNU
  99. #undef INSNUE
  100. };
  101. /* If instruction format FMT has a field FIELD, return a pointer to
  102. the description of that field; otherwise return NULL. */
  103. const tic6x_insn_field *
  104. tic6x_field_from_fmt (const tic6x_insn_format *fmt, tic6x_insn_field_id field)
  105. {
  106. unsigned int f;
  107. for (f = 0; f < fmt->num_fields; f++)
  108. if (fmt->fields[f].field_id == field)
  109. return &fmt->fields[f];
  110. return NULL;
  111. }
  112. /* Extract the field width. */
  113. static unsigned int
  114. tic6x_field_width (const tic6x_insn_field *field)
  115. {
  116. unsigned int i;
  117. unsigned int width = 0;
  118. if (!field->num_bitfields)
  119. return field->bitfields[0].width;
  120. for (i = 0 ; i < field->num_bitfields ; i++)
  121. width += field->bitfields[i].width;
  122. return width;
  123. }
  124. /* Extract the bits corresponding to FIELD from OPCODE. */
  125. static unsigned int
  126. tic6x_field_bits (unsigned int opcode, const tic6x_insn_field *field)
  127. {
  128. unsigned int i;
  129. unsigned int val = 0;
  130. if (!field->num_bitfields)
  131. return (opcode >> field->bitfields[0].low_pos) & ((1u << field->bitfields[0].width) - 1);
  132. for (i = 0 ; i < field->num_bitfields ; i++)
  133. val |= ((opcode >> field->bitfields[i].low_pos) & ((1u << field->bitfields[i].width) - 1))
  134. << field->bitfields[i].pos;
  135. return val;
  136. }
  137. /* Extract a 32-bit value read from the instruction stream. */
  138. static unsigned int
  139. tic6x_extract_32 (unsigned char *p, struct disassemble_info *info)
  140. {
  141. if (info->endian == BFD_ENDIAN_LITTLE)
  142. return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned) p[3] << 24);
  143. else
  144. return p[3] | (p[2] << 8) | (p[1] << 16) | ((unsigned) p[0] << 24);
  145. }
  146. /* Extract a 16-bit value read from the instruction stream. */
  147. static unsigned int
  148. tic6x_extract_16 (unsigned char *p, tic6x_fetch_packet_header *header,
  149. struct disassemble_info *info)
  150. {
  151. unsigned int op16;
  152. if (info->endian == BFD_ENDIAN_LITTLE)
  153. op16 = (p[0]) | (p[1] << 8);
  154. else
  155. op16 = (p[1]) | (p[0] << 8);
  156. op16 |= (header->sat << TIC6X_COMPACT_SAT_POS);
  157. op16 |= (header->br << TIC6X_COMPACT_BR_POS);
  158. op16 |= (header->dsz << TIC6X_COMPACT_DSZ_POS);
  159. return op16;
  160. }
  161. /* FP points to a fetch packet. Return whether it is header-based; if
  162. it is, fill in HEADER. */
  163. static bool
  164. tic6x_check_fetch_packet_header (unsigned char *fp,
  165. tic6x_fetch_packet_header *header,
  166. struct disassemble_info *info)
  167. {
  168. int i;
  169. header->header = tic6x_extract_32 (fp + 28, info);
  170. if ((header->header & 0xf0000000) != 0xe0000000)
  171. {
  172. header->prot = 0;
  173. header->rs = 0;
  174. header->dsz = 0;
  175. header->br = 0;
  176. header->sat = 0;
  177. for (i = 0; i < 7; i++)
  178. header->word_compact[i] = false;
  179. for (i = 0; i < 14; i++)
  180. header->p_bits[i] = false;
  181. return false;
  182. }
  183. for (i = 0; i < 7; i++)
  184. header->word_compact[i]
  185. = (header->header & (1u << (21 + i))) != 0;
  186. header->prot = (header->header & (1u << 20)) != 0;
  187. header->rs = (header->header & (1u << 19)) != 0;
  188. header->dsz = (header->header >> 16) & 0x7;
  189. header->br = (header->header & (1u << 15)) != 0;
  190. header->sat = (header->header & (1u << 14)) != 0;
  191. for (i = 0; i < 14; i++)
  192. header->p_bits[i] = (header->header & (1u << i)) != 0;
  193. return true;
  194. }
  195. /* Disassemble the instruction at ADDR and print it using
  196. INFO->FPRINTF_FUNC and INFO->STREAM, returning the number of bytes
  197. consumed. */
  198. int
  199. print_insn_tic6x (bfd_vma addr, struct disassemble_info *info)
  200. {
  201. int status;
  202. bfd_vma fp_addr;
  203. bfd_vma fp_offset;
  204. unsigned char fp[32];
  205. unsigned int opcode;
  206. tic6x_opcode_id opcode_id;
  207. bool fetch_packet_header_based;
  208. tic6x_fetch_packet_header header;
  209. unsigned int num_bits;
  210. bool bad_offset = false;
  211. fp_offset = addr & 0x1f;
  212. fp_addr = addr - fp_offset;
  213. /* Read in a block of instructions. Since there might be a
  214. symbol in the middle of this block, disable stop_vma. */
  215. info->stop_vma = 0;
  216. status = info->read_memory_func (fp_addr, fp, 32, info);
  217. if (status)
  218. {
  219. info->memory_error_func (status, addr, info);
  220. return -1;
  221. }
  222. fetch_packet_header_based
  223. = tic6x_check_fetch_packet_header (fp, &header, info);
  224. if (fetch_packet_header_based)
  225. {
  226. if (fp_offset & 0x1)
  227. bad_offset = true;
  228. if ((fp_offset & 0x3) && (fp_offset >= 28
  229. || !header.word_compact[fp_offset >> 2]))
  230. bad_offset = true;
  231. if (fp_offset == 28)
  232. {
  233. info->bytes_per_chunk = 4;
  234. info->fprintf_func (info->stream, "<fetch packet header 0x%.8x>",
  235. header.header);
  236. return 4;
  237. }
  238. num_bits = (header.word_compact[fp_offset >> 2] ? 16 : 32);
  239. }
  240. else
  241. {
  242. num_bits = 32;
  243. if (fp_offset & 0x3)
  244. bad_offset = true;
  245. }
  246. if (bad_offset)
  247. {
  248. info->bytes_per_chunk = 1;
  249. info->fprintf_func (info->stream, ".byte 0x%.2x", fp[fp_offset]);
  250. return 1;
  251. }
  252. if (num_bits == 16)
  253. {
  254. /* The least-significant part of a 32-bit word comes logically
  255. before the most-significant part. For big-endian, follow the
  256. TI assembler in showing instructions in logical order by
  257. pretending that the two halves of the word are in opposite
  258. locations to where they actually are. */
  259. if (info->endian == BFD_ENDIAN_LITTLE)
  260. opcode = tic6x_extract_16 (fp + fp_offset, &header, info);
  261. else
  262. opcode = tic6x_extract_16 (fp + (fp_offset ^ 2), &header, info);
  263. }
  264. else
  265. opcode = tic6x_extract_32 (fp + fp_offset, info);
  266. for (opcode_id = 0; opcode_id < tic6x_opcode_max; opcode_id++)
  267. {
  268. const tic6x_opcode *const opc = &tic6x_opcode_table[opcode_id];
  269. const tic6x_insn_format *const fmt
  270. = &tic6x_insn_format_table[opc->format];
  271. const tic6x_insn_field *creg_field;
  272. bool p_bit;
  273. const char *parallel;
  274. const char *cond = "";
  275. const char *func_unit;
  276. char func_unit_buf[8];
  277. unsigned int func_unit_side = 0;
  278. unsigned int func_unit_data_side = 0;
  279. unsigned int func_unit_cross = 0;
  280. unsigned int t_val = 0;
  281. /* The maximum length of the text of a non-PC-relative operand
  282. is 24 bytes (SPMASK masking all eight functional units, with
  283. separating commas and trailing NUL). */
  284. char operands[TIC6X_MAX_OPERANDS][24] = { { 0 } };
  285. bfd_vma operands_addresses[TIC6X_MAX_OPERANDS] = { 0 };
  286. bool operands_text[TIC6X_MAX_OPERANDS] = { false };
  287. bool operands_pcrel[TIC6X_MAX_OPERANDS] = { false };
  288. unsigned int fix;
  289. unsigned int num_operands;
  290. unsigned int op_num;
  291. bool fixed_ok;
  292. bool operands_ok;
  293. bool have_t = false;
  294. if (opc->flags & TIC6X_FLAG_MACRO)
  295. continue;
  296. if (fmt->num_bits != num_bits)
  297. continue;
  298. if ((opcode & fmt->mask) != fmt->cst_bits)
  299. continue;
  300. /* If the format has a creg field, it is only a candidate for a
  301. match if the creg and z fields have values indicating a valid
  302. condition; reserved values indicate either an instruction
  303. format without a creg field, or an invalid instruction. */
  304. creg_field = tic6x_field_from_fmt (fmt, tic6x_field_creg);
  305. if (creg_field)
  306. {
  307. const tic6x_insn_field *z_field;
  308. unsigned int creg_value, z_value;
  309. static const char *const conds[8][2] =
  310. {
  311. { "", NULL },
  312. { "[b0] ", "[!b0] " },
  313. { "[b1] ", "[!b1] " },
  314. { "[b2] ", "[!b2] " },
  315. { "[a1] ", "[!a1] " },
  316. { "[a2] ", "[!a2] " },
  317. { "[a0] ", "[!a0] " },
  318. { NULL, NULL }
  319. };
  320. /* A creg field is not meaningful without a z field, so if
  321. the z field is not present this is an error in the format
  322. table. */
  323. z_field = tic6x_field_from_fmt (fmt, tic6x_field_z);
  324. if (!z_field)
  325. {
  326. printf ("*** opcode %x: missing z field", opcode);
  327. abort ();
  328. }
  329. creg_value = tic6x_field_bits (opcode, creg_field);
  330. z_value = tic6x_field_bits (opcode, z_field);
  331. cond = conds[creg_value][z_value];
  332. if (cond == NULL)
  333. continue;
  334. }
  335. if (opc->flags & TIC6X_FLAG_INSN16_SPRED)
  336. {
  337. const tic6x_insn_field *cc_field;
  338. unsigned int s_value = 0;
  339. unsigned int z_value = 0;
  340. bool cond_known = false;
  341. static const char *const conds[2][2] =
  342. {
  343. { "[a0] ", "[!a0] " },
  344. { "[b0] ", "[!b0] " }
  345. };
  346. cc_field = tic6x_field_from_fmt (fmt, tic6x_field_cc);
  347. if (cc_field)
  348. {
  349. unsigned int cc_value;
  350. cc_value = tic6x_field_bits (opcode, cc_field);
  351. s_value = (cc_value & 0x2) >> 1;
  352. z_value = (cc_value & 0x1);
  353. cond_known = true;
  354. }
  355. else
  356. {
  357. const tic6x_insn_field *z_field;
  358. const tic6x_insn_field *s_field;
  359. s_field = tic6x_field_from_fmt (fmt, tic6x_field_s);
  360. if (!s_field)
  361. {
  362. printf ("opcode %x: missing compact insn predicate register field (s field)\n",
  363. opcode);
  364. abort ();
  365. }
  366. s_value = tic6x_field_bits (opcode, s_field);
  367. z_field = tic6x_field_from_fmt (fmt, tic6x_field_z);
  368. if (!z_field)
  369. {
  370. printf ("opcode %x: missing compact insn predicate z_value (z field)\n", opcode);
  371. abort ();
  372. }
  373. z_value = tic6x_field_bits (opcode, z_field);
  374. cond_known = true;
  375. }
  376. if (!cond_known)
  377. {
  378. printf ("opcode %x: unspecified ompact insn predicate\n", opcode);
  379. abort ();
  380. }
  381. cond = conds[s_value][z_value];
  382. }
  383. /* All fixed fields must have matching values; all fields with
  384. restricted ranges must have values within those ranges. */
  385. fixed_ok = true;
  386. for (fix = 0; fix < opc->num_fixed_fields; fix++)
  387. {
  388. unsigned int field_bits;
  389. const tic6x_insn_field *const field
  390. = tic6x_field_from_fmt (fmt, opc->fixed_fields[fix].field_id);
  391. if (!field)
  392. {
  393. printf ("opcode %x: missing field #%d for FIX #%d\n",
  394. opcode, opc->fixed_fields[fix].field_id, fix);
  395. abort ();
  396. }
  397. field_bits = tic6x_field_bits (opcode, field);
  398. if (field_bits < opc->fixed_fields[fix].min_val
  399. || field_bits > opc->fixed_fields[fix].max_val)
  400. {
  401. fixed_ok = false;
  402. break;
  403. }
  404. }
  405. if (!fixed_ok)
  406. continue;
  407. /* The instruction matches. */
  408. /* The p-bit indicates whether this instruction is in parallel
  409. with the *next* instruction, whereas the parallel bars
  410. indicate the instruction is in parallel with the *previous*
  411. instruction. Thus, we must find the p-bit for the previous
  412. instruction. */
  413. if (num_bits == 16 && (fp_offset & 0x2) == 2)
  414. {
  415. /* This is the logically second (most significant; second in
  416. fp_offset terms because fp_offset relates to logical not
  417. physical addresses) instruction of a compact pair; find
  418. the p-bit for the first (least significant). */
  419. p_bit = header.p_bits[(fp_offset >> 2) << 1];
  420. }
  421. else if (fp_offset >= 4)
  422. {
  423. /* Find the last instruction of the previous word in this
  424. fetch packet. For compact instructions, this is the most
  425. significant 16 bits. */
  426. if (fetch_packet_header_based
  427. && header.word_compact[(fp_offset >> 2) - 1])
  428. p_bit = header.p_bits[(fp_offset >> 1) - 1];
  429. else
  430. {
  431. unsigned int prev_opcode
  432. = tic6x_extract_32 (fp + (fp_offset & 0x1c) - 4, info);
  433. p_bit = (prev_opcode & 0x1) != 0;
  434. }
  435. }
  436. else
  437. {
  438. /* Find the last instruction of the previous fetch
  439. packet. */
  440. unsigned char fp_prev[32];
  441. status = info->read_memory_func (fp_addr - 32, fp_prev, 32, info);
  442. if (status)
  443. /* No previous instruction to be parallel with. */
  444. p_bit = false;
  445. else
  446. {
  447. bool prev_header_based;
  448. tic6x_fetch_packet_header prev_header;
  449. prev_header_based
  450. = tic6x_check_fetch_packet_header (fp_prev, &prev_header, info);
  451. if (prev_header_based)
  452. {
  453. if (prev_header.word_compact[6])
  454. p_bit = prev_header.p_bits[13];
  455. else
  456. {
  457. unsigned int prev_opcode = tic6x_extract_32 (fp_prev + 24,
  458. info);
  459. p_bit = (prev_opcode & 0x1) != 0;
  460. }
  461. }
  462. else
  463. {
  464. unsigned int prev_opcode = tic6x_extract_32 (fp_prev + 28,
  465. info);
  466. p_bit = (prev_opcode & 0x1) != 0;
  467. }
  468. }
  469. }
  470. parallel = p_bit ? "|| " : "";
  471. if (opc->func_unit == tic6x_func_unit_nfu)
  472. func_unit = "";
  473. else
  474. {
  475. unsigned int fld_num;
  476. char func_unit_char;
  477. const char *data_str;
  478. bool have_areg = false;
  479. bool have_cross = false;
  480. func_unit_side = (opc->flags & TIC6X_FLAG_SIDE_B_ONLY) ? 2 : 0;
  481. func_unit_cross = 0;
  482. func_unit_data_side = (opc->flags & TIC6X_FLAG_SIDE_T2_ONLY) ? 2 : 0;
  483. for (fld_num = 0; fld_num < opc->num_variable_fields; fld_num++)
  484. {
  485. const tic6x_coding_field *const enc = &opc->variable_fields[fld_num];
  486. const tic6x_insn_field *field;
  487. unsigned int fld_val;
  488. field = tic6x_field_from_fmt (fmt, enc->field_id);
  489. if (!field)
  490. {
  491. printf ("opcode %x: could not retrieve field (field_id:%d)\n",
  492. opcode, fld_num);
  493. abort ();
  494. }
  495. fld_val = tic6x_field_bits (opcode, field);
  496. switch (enc->coding_method)
  497. {
  498. case tic6x_coding_fu:
  499. /* The side must be specified exactly once. */
  500. if (func_unit_side)
  501. {
  502. printf ("opcode %x: field #%d use tic6x_coding_fu, but func_unit_side is already set!\n",
  503. opcode, fld_num);
  504. abort ();
  505. }
  506. func_unit_side = (fld_val ? 2 : 1);
  507. break;
  508. case tic6x_coding_data_fu:
  509. /* The data side must be specified exactly once. */
  510. if (func_unit_data_side)
  511. {
  512. printf ("opcode %x: field #%d use tic6x_coding_fu, but func_unit_side is already set!\n",
  513. opcode, fld_num);
  514. abort ();
  515. }
  516. func_unit_data_side = (fld_val ? 2 : 1);
  517. break;
  518. case tic6x_coding_xpath:
  519. /* Cross path use must be specified exactly
  520. once. */
  521. if (have_cross)
  522. {
  523. printf ("opcode %x: field #%d use tic6x_coding_xpath, have_cross is already set!\n",
  524. opcode, fld_num);
  525. abort ();
  526. }
  527. have_cross = true;
  528. func_unit_cross = fld_val;
  529. break;
  530. case tic6x_coding_rside:
  531. /* If the format has a t field, use it for src/dst register side. */
  532. have_t = true;
  533. t_val = fld_val;
  534. func_unit_data_side = (t_val ? 2 : 1);
  535. break;
  536. case tic6x_coding_areg:
  537. have_areg = true;
  538. break;
  539. default:
  540. /* Don't relate to functional units. */
  541. break;
  542. }
  543. }
  544. /* The side of the functional unit used must now have been
  545. determined either from the flags or from an instruction
  546. field. */
  547. if (func_unit_side != 1 && func_unit_side != 2)
  548. {
  549. printf ("opcode %x: func_unit_side is not encoded!\n", opcode);
  550. abort ();
  551. }
  552. /* Cross paths are not applicable when sides are specified
  553. for both address and data paths. */
  554. if (func_unit_data_side && have_cross)
  555. {
  556. printf ("opcode %x: xpath not applicable when side are specified both for address and data!\n",
  557. opcode);
  558. abort ();
  559. }
  560. /* Separate address and data paths are only applicable for
  561. the D unit. */
  562. if (func_unit_data_side && opc->func_unit != tic6x_func_unit_d)
  563. {
  564. printf ("opcode %x: separate address and data paths only applicable for D unit!\n",
  565. opcode);
  566. abort ();
  567. }
  568. /* If an address register is being used but in ADDA rather
  569. than a load or store, it uses a cross path for side-A
  570. instructions, and the cross path use is not specified by
  571. an instruction field. */
  572. if (have_areg && !func_unit_data_side)
  573. {
  574. if (have_cross)
  575. {
  576. printf ("opcode %x: illegal cross path specifier in adda opcode!\n", opcode);
  577. abort ();
  578. }
  579. func_unit_cross = func_unit_side == 1;
  580. }
  581. switch (opc->func_unit)
  582. {
  583. case tic6x_func_unit_d:
  584. func_unit_char = 'D';
  585. break;
  586. case tic6x_func_unit_l:
  587. func_unit_char = 'L';
  588. break;
  589. case tic6x_func_unit_m:
  590. func_unit_char = 'M';
  591. break;
  592. case tic6x_func_unit_s:
  593. func_unit_char = 'S';
  594. break;
  595. default:
  596. printf ("opcode %x: illegal func_unit specifier %d\n", opcode, opc->func_unit);
  597. abort ();
  598. }
  599. switch (func_unit_data_side)
  600. {
  601. case 0:
  602. data_str = "";
  603. break;
  604. case 1:
  605. data_str = "T1";
  606. break;
  607. case 2:
  608. data_str = "T2";
  609. break;
  610. default:
  611. printf ("opcode %x: illegal data func_unit specifier %d\n",
  612. opcode, func_unit_data_side);
  613. abort ();
  614. }
  615. if (opc->flags & TIC6X_FLAG_INSN16_BSIDE && func_unit_side == 1)
  616. func_unit_cross = 1;
  617. snprintf (func_unit_buf, sizeof func_unit_buf, " .%c%u%s%s",
  618. func_unit_char, func_unit_side,
  619. (func_unit_cross ? "X" : ""), data_str);
  620. func_unit = func_unit_buf;
  621. }
  622. /* For each operand there must be one or more fields set based
  623. on that operand, that can together be used to derive the
  624. operand value. */
  625. operands_ok = true;
  626. num_operands = opc->num_operands;
  627. for (op_num = 0; op_num < num_operands; op_num++)
  628. {
  629. unsigned int fld_num;
  630. unsigned int mem_base_reg = 0;
  631. bool mem_base_reg_known = false;
  632. bool mem_base_reg_known_long = false;
  633. unsigned int mem_offset = 0;
  634. bool mem_offset_known = false;
  635. bool mem_offset_known_long = false;
  636. unsigned int mem_mode = 0;
  637. bool mem_mode_known = false;
  638. unsigned int mem_scaled = 0;
  639. bool mem_scaled_known = false;
  640. unsigned int crlo = 0;
  641. bool crlo_known = false;
  642. unsigned int crhi = 0;
  643. bool crhi_known = false;
  644. bool spmask_skip_operand = false;
  645. unsigned int fcyc_bits = 0;
  646. bool prev_sploop_found = false;
  647. switch (opc->operand_info[op_num].form)
  648. {
  649. case tic6x_operand_b15reg:
  650. /* Fully determined by the functional unit. */
  651. operands_text[op_num] = true;
  652. snprintf (operands[op_num], 24, "b15");
  653. continue;
  654. case tic6x_operand_zreg:
  655. /* Fully determined by the functional unit. */
  656. operands_text[op_num] = true;
  657. snprintf (operands[op_num], 24, "%c0",
  658. (func_unit_side == 2 ? 'b' : 'a'));
  659. continue;
  660. case tic6x_operand_retreg:
  661. /* Fully determined by the functional unit. */
  662. operands_text[op_num] = true;
  663. snprintf (operands[op_num], 24, "%c3",
  664. (func_unit_side == 2 ? 'b' : 'a'));
  665. continue;
  666. case tic6x_operand_irp:
  667. operands_text[op_num] = true;
  668. snprintf (operands[op_num], 24, "irp");
  669. continue;
  670. case tic6x_operand_nrp:
  671. operands_text[op_num] = true;
  672. snprintf (operands[op_num], 24, "nrp");
  673. continue;
  674. case tic6x_operand_ilc:
  675. operands_text[op_num] = true;
  676. snprintf (operands[op_num], 24, "ilc");
  677. continue;
  678. case tic6x_operand_hw_const_minus_1:
  679. operands_text[op_num] = true;
  680. snprintf (operands[op_num], 24, "-1");
  681. continue;
  682. case tic6x_operand_hw_const_0:
  683. operands_text[op_num] = true;
  684. snprintf (operands[op_num], 24, "0");
  685. continue;
  686. case tic6x_operand_hw_const_1:
  687. operands_text[op_num] = true;
  688. snprintf (operands[op_num], 24, "1");
  689. continue;
  690. case tic6x_operand_hw_const_5:
  691. operands_text[op_num] = true;
  692. snprintf (operands[op_num], 24, "5");
  693. continue;
  694. case tic6x_operand_hw_const_16:
  695. operands_text[op_num] = true;
  696. snprintf (operands[op_num], 24, "16");
  697. continue;
  698. case tic6x_operand_hw_const_24:
  699. operands_text[op_num] = true;
  700. snprintf (operands[op_num], 24, "24");
  701. continue;
  702. case tic6x_operand_hw_const_31:
  703. operands_text[op_num] = true;
  704. snprintf (operands[op_num], 24, "31");
  705. continue;
  706. default:
  707. break;
  708. }
  709. for (fld_num = 0; fld_num < opc->num_variable_fields; fld_num++)
  710. {
  711. const tic6x_coding_field *const enc
  712. = &opc->variable_fields[fld_num];
  713. const tic6x_insn_field *field;
  714. unsigned int fld_val;
  715. unsigned int reg_base = 0;
  716. signed int signed_fld_val;
  717. char reg_side = '?';
  718. if (enc->operand_num != op_num)
  719. continue;
  720. field = tic6x_field_from_fmt (fmt, enc->field_id);
  721. if (!field)
  722. {
  723. printf ("opcode %x: missing field (field_id:%d) in format\n", opcode, enc->field_id);
  724. abort ();
  725. }
  726. fld_val = tic6x_field_bits (opcode, field);
  727. switch (enc->coding_method)
  728. {
  729. case tic6x_coding_cst_s3i:
  730. (fld_val == 0x00) && (fld_val = 0x10);
  731. (fld_val == 0x07) && (fld_val = 0x08);
  732. /* Fall through. */
  733. case tic6x_coding_ucst:
  734. case tic6x_coding_ulcst_dpr_byte:
  735. case tic6x_coding_ulcst_dpr_half:
  736. case tic6x_coding_ulcst_dpr_word:
  737. case tic6x_coding_lcst_low16:
  738. switch (opc->operand_info[op_num].form)
  739. {
  740. case tic6x_operand_asm_const:
  741. case tic6x_operand_link_const:
  742. operands_text[op_num] = true;
  743. snprintf (operands[op_num], 24, "%u", fld_val);
  744. break;
  745. case tic6x_operand_mem_long:
  746. mem_offset = fld_val;
  747. mem_offset_known_long = true;
  748. break;
  749. default:
  750. printf ("opcode %x: illegal operand form for operand#%d\n", opcode, op_num);
  751. abort ();
  752. }
  753. break;
  754. case tic6x_coding_lcst_high16:
  755. operands_text[op_num] = true;
  756. snprintf (operands[op_num], 24, "%u", fld_val << 16);
  757. break;
  758. case tic6x_coding_scst_l3i:
  759. operands_text[op_num] = true;
  760. if (fld_val == 0)
  761. {
  762. signed_fld_val = 8;
  763. }
  764. else
  765. {
  766. signed_fld_val = (signed int) fld_val;
  767. signed_fld_val ^= (1 << (tic6x_field_width (field) - 1));
  768. signed_fld_val -= (1 << (tic6x_field_width (field) - 1));
  769. }
  770. snprintf (operands[op_num], 24, "%d", signed_fld_val);
  771. break;
  772. case tic6x_coding_scst:
  773. operands_text[op_num] = true;
  774. signed_fld_val = (signed int) fld_val;
  775. signed_fld_val ^= (1 << (tic6x_field_width (field) - 1));
  776. signed_fld_val -= (1 << (tic6x_field_width (field) - 1));
  777. snprintf (operands[op_num], 24, "%d", signed_fld_val);
  778. break;
  779. case tic6x_coding_ucst_minus_one:
  780. operands_text[op_num] = true;
  781. snprintf (operands[op_num], 24, "%u", fld_val + 1);
  782. break;
  783. case tic6x_coding_pcrel:
  784. case tic6x_coding_pcrel_half:
  785. signed_fld_val = (signed int) fld_val;
  786. signed_fld_val ^= (1 << (tic6x_field_width (field) - 1));
  787. signed_fld_val -= (1 << (tic6x_field_width (field) - 1));
  788. if (fetch_packet_header_based
  789. && enc->coding_method == tic6x_coding_pcrel_half)
  790. signed_fld_val *= 2;
  791. else
  792. signed_fld_val *= 4;
  793. operands_pcrel[op_num] = true;
  794. operands_addresses[op_num] = fp_addr + signed_fld_val;
  795. break;
  796. case tic6x_coding_regpair_msb:
  797. if (opc->operand_info[op_num].form != tic6x_operand_regpair)
  798. abort ();
  799. operands_text[op_num] = true;
  800. snprintf (operands[op_num], 24, "%c%u:%c%u",
  801. (func_unit_side == 2 ? 'b' : 'a'), (fld_val | 0x1),
  802. (func_unit_side == 2 ? 'b' : 'a'), (fld_val | 0x1) - 1);
  803. break;
  804. case tic6x_coding_pcrel_half_unsigned:
  805. operands_pcrel[op_num] = true;
  806. operands_addresses[op_num] = fp_addr + 2 * fld_val;
  807. break;
  808. case tic6x_coding_reg_shift:
  809. fld_val <<= 1;
  810. /* Fall through. */
  811. case tic6x_coding_reg:
  812. if (num_bits == 16 && header.rs && !(opc->flags & TIC6X_FLAG_INSN16_NORS))
  813. {
  814. reg_base = 16;
  815. }
  816. switch (opc->operand_info[op_num].form)
  817. {
  818. case tic6x_operand_treg:
  819. if (!have_t)
  820. {
  821. printf ("opcode %x: operand treg but missing t field\n", opcode);
  822. abort ();
  823. }
  824. operands_text[op_num] = true;
  825. reg_side = t_val ? 'b' : 'a';
  826. snprintf (operands[op_num], 24, "%c%u", reg_side, reg_base + fld_val);
  827. break;
  828. case tic6x_operand_reg:
  829. operands_text[op_num] = true;
  830. reg_side = (func_unit_side == 2) ? 'b' : 'a';
  831. snprintf (operands[op_num], 24, "%c%u", reg_side, reg_base + fld_val);
  832. break;
  833. case tic6x_operand_reg_nors:
  834. operands_text[op_num] = true;
  835. reg_side = (func_unit_side == 2) ? 'b' : 'a';
  836. snprintf (operands[op_num], 24, "%c%u", reg_side, fld_val);
  837. break;
  838. case tic6x_operand_reg_bside:
  839. operands_text[op_num] = true;
  840. snprintf (operands[op_num], 24, "b%u", reg_base + fld_val);
  841. break;
  842. case tic6x_operand_reg_bside_nors:
  843. operands_text[op_num] = true;
  844. snprintf (operands[op_num], 24, "b%u", fld_val);
  845. break;
  846. case tic6x_operand_xreg:
  847. operands_text[op_num] = true;
  848. reg_side = ((func_unit_side == 2) ^ func_unit_cross) ? 'b' : 'a';
  849. snprintf (operands[op_num], 24, "%c%u", reg_side, reg_base + fld_val);
  850. break;
  851. case tic6x_operand_dreg:
  852. operands_text[op_num] = true;
  853. reg_side = (func_unit_data_side == 2) ? 'b' : 'a';
  854. snprintf (operands[op_num], 24, "%c%u", reg_side, reg_base + fld_val);
  855. break;
  856. case tic6x_operand_regpair:
  857. operands_text[op_num] = true;
  858. if (fld_val & 1)
  859. operands_ok = false;
  860. reg_side = (func_unit_side == 2) ? 'b' : 'a';
  861. snprintf (operands[op_num], 24, "%c%u:%c%u",
  862. reg_side, reg_base + fld_val + 1,
  863. reg_side, reg_base + fld_val);
  864. break;
  865. case tic6x_operand_xregpair:
  866. operands_text[op_num] = true;
  867. if (fld_val & 1)
  868. operands_ok = false;
  869. reg_side = ((func_unit_side == 2) ^ func_unit_cross) ? 'b' : 'a';
  870. snprintf (operands[op_num], 24, "%c%u:%c%u",
  871. reg_side, reg_base + fld_val + 1,
  872. reg_side, reg_base + fld_val);
  873. break;
  874. case tic6x_operand_tregpair:
  875. if (!have_t)
  876. {
  877. printf ("opcode %x: operand tregpair but missing t field\n", opcode);
  878. abort ();
  879. }
  880. operands_text[op_num] = true;
  881. if (fld_val & 1)
  882. operands_ok = false;
  883. reg_side = t_val ? 'b' : 'a';
  884. snprintf (operands[op_num], 24, "%c%u:%c%u",
  885. reg_side, reg_base + fld_val + 1,
  886. reg_side, reg_base + fld_val);
  887. break;
  888. case tic6x_operand_dregpair:
  889. operands_text[op_num] = true;
  890. if (fld_val & 1)
  891. operands_ok = false;
  892. reg_side = (func_unit_data_side) == 2 ? 'b' : 'a';
  893. snprintf (operands[op_num], 24, "%c%u:%c%u",
  894. reg_side, reg_base + fld_val + 1,
  895. reg_side, reg_base + fld_val);
  896. break;
  897. case tic6x_operand_mem_deref:
  898. operands_text[op_num] = true;
  899. reg_side = func_unit_side == 2 ? 'b' : 'a';
  900. snprintf (operands[op_num], 24, "*%c%u", reg_side, reg_base + fld_val);
  901. break;
  902. case tic6x_operand_mem_short:
  903. case tic6x_operand_mem_ndw:
  904. mem_base_reg = fld_val;
  905. mem_base_reg_known = true;
  906. break;
  907. default:
  908. printf ("opcode %x: unexpected operand form %d for operand #%d",
  909. opcode, opc->operand_info[op_num].form, op_num);
  910. abort ();
  911. }
  912. break;
  913. case tic6x_coding_reg_ptr:
  914. switch (opc->operand_info[op_num].form)
  915. {
  916. case tic6x_operand_mem_short:
  917. case tic6x_operand_mem_ndw:
  918. if (fld_val > 0x3u)
  919. {
  920. printf("opcode %x: illegal field value for ptr register of operand #%d (%d)",
  921. opcode, op_num, fld_val);
  922. abort ();
  923. }
  924. mem_base_reg = 0x4 | fld_val;
  925. mem_base_reg_known = true;
  926. break;
  927. default:
  928. printf ("opcode %x: unexpected operand form %d for operand #%d",
  929. opcode, opc->operand_info[op_num].form, op_num);
  930. abort ();
  931. }
  932. break;
  933. case tic6x_coding_areg:
  934. switch (opc->operand_info[op_num].form)
  935. {
  936. case tic6x_operand_areg:
  937. operands_text[op_num] = true;
  938. snprintf (operands[op_num], 24, "b%u",
  939. fld_val ? 15u : 14u);
  940. break;
  941. case tic6x_operand_mem_long:
  942. mem_base_reg = fld_val ? 15u : 14u;
  943. mem_base_reg_known_long = true;
  944. break;
  945. default:
  946. printf ("opcode %x: bad operand form\n", opcode);
  947. abort ();
  948. }
  949. break;
  950. case tic6x_coding_mem_offset_minus_one_noscale:
  951. case tic6x_coding_mem_offset_minus_one:
  952. fld_val += 1;
  953. /* Fall through. */
  954. case tic6x_coding_mem_offset_noscale:
  955. case tic6x_coding_mem_offset:
  956. mem_offset = fld_val;
  957. mem_offset_known = true;
  958. if (num_bits == 16)
  959. {
  960. mem_mode_known = true;
  961. mem_mode = TIC6X_INSN16_MEM_MODE_VAL (opc->flags);
  962. mem_scaled_known = true;
  963. mem_scaled = true;
  964. if (opc->flags & TIC6X_FLAG_INSN16_B15PTR)
  965. {
  966. mem_base_reg_known = true;
  967. mem_base_reg = 15;
  968. }
  969. if ( enc->coding_method == tic6x_coding_mem_offset_noscale
  970. || enc->coding_method == tic6x_coding_mem_offset_noscale )
  971. mem_scaled = false;
  972. }
  973. break;
  974. case tic6x_coding_mem_mode:
  975. mem_mode = fld_val;
  976. mem_mode_known = true;
  977. break;
  978. case tic6x_coding_scaled:
  979. mem_scaled = fld_val;
  980. mem_scaled_known = true;
  981. break;
  982. case tic6x_coding_crlo:
  983. crlo = fld_val;
  984. crlo_known = true;
  985. break;
  986. case tic6x_coding_crhi:
  987. crhi = fld_val;
  988. crhi_known = true;
  989. break;
  990. case tic6x_coding_fstg:
  991. case tic6x_coding_fcyc:
  992. if (!prev_sploop_found)
  993. {
  994. bfd_vma search_fp_addr = fp_addr;
  995. bfd_vma search_fp_offset = fp_offset;
  996. bool search_fp_header_based
  997. = fetch_packet_header_based;
  998. tic6x_fetch_packet_header search_fp_header = header;
  999. unsigned char search_fp[32];
  1000. unsigned int search_num_bits;
  1001. unsigned int search_opcode;
  1002. unsigned int sploop_ii = 0;
  1003. int i;
  1004. memcpy (search_fp, fp, 32);
  1005. /* To interpret these bits in an SPKERNEL
  1006. instruction, we must find the previous
  1007. SPLOOP-family instruction. It may come up to
  1008. 48 execute packets earlier. */
  1009. for (i = 0; i < 48 * 8; i++)
  1010. {
  1011. /* Find the previous instruction. */
  1012. if (search_fp_offset & 2)
  1013. search_fp_offset -= 2;
  1014. else if (search_fp_offset >= 4)
  1015. {
  1016. if (search_fp_header_based
  1017. && (search_fp_header.word_compact
  1018. [(search_fp_offset >> 2) - 1]))
  1019. search_fp_offset -= 2;
  1020. else
  1021. search_fp_offset -= 4;
  1022. }
  1023. else
  1024. {
  1025. search_fp_addr -= 32;
  1026. status = info->read_memory_func (search_fp_addr,
  1027. search_fp,
  1028. 32, info);
  1029. if (status)
  1030. /* No previous SPLOOP instruction. */
  1031. break;
  1032. search_fp_header_based
  1033. = (tic6x_check_fetch_packet_header
  1034. (search_fp, &search_fp_header, info));
  1035. if (search_fp_header_based)
  1036. search_fp_offset
  1037. = search_fp_header.word_compact[6] ? 26 : 24;
  1038. else
  1039. search_fp_offset = 28;
  1040. }
  1041. /* Extract the previous instruction. */
  1042. if (search_fp_header_based)
  1043. search_num_bits
  1044. = (search_fp_header.word_compact[search_fp_offset
  1045. >> 2]
  1046. ? 16
  1047. : 32);
  1048. else
  1049. search_num_bits = 32;
  1050. if (search_num_bits == 16)
  1051. {
  1052. if (info->endian == BFD_ENDIAN_LITTLE)
  1053. search_opcode
  1054. = (tic6x_extract_16
  1055. (search_fp + search_fp_offset, &header, info));
  1056. else
  1057. search_opcode
  1058. = (tic6x_extract_16
  1059. (search_fp + (search_fp_offset ^ 2), &header,
  1060. info));
  1061. }
  1062. else
  1063. search_opcode
  1064. = tic6x_extract_32 (search_fp + search_fp_offset,
  1065. info);
  1066. /* Check whether it is an SPLOOP-family
  1067. instruction. */
  1068. if (search_num_bits == 32
  1069. && ((search_opcode & 0x003ffffe) == 0x00038000
  1070. || (search_opcode & 0x003ffffe) == 0x0003a000
  1071. || ((search_opcode & 0x003ffffe)
  1072. == 0x0003e000)))
  1073. {
  1074. prev_sploop_found = true;
  1075. sploop_ii = ((search_opcode >> 23) & 0x1f) + 1;
  1076. }
  1077. else if (search_num_bits == 16
  1078. && (search_opcode & 0x3c7e) == 0x0c66)
  1079. {
  1080. prev_sploop_found = true;
  1081. sploop_ii
  1082. = (((search_opcode >> 7) & 0x7)
  1083. | ((search_opcode >> 11) & 0x8)) + 1;
  1084. }
  1085. if (prev_sploop_found)
  1086. {
  1087. if (sploop_ii <= 0)
  1088. {
  1089. printf ("opcode %x: sloop index not found (%d)\n", opcode, sploop_ii);
  1090. abort ();
  1091. }
  1092. else if (sploop_ii <= 1)
  1093. fcyc_bits = 0;
  1094. else if (sploop_ii <= 2)
  1095. fcyc_bits = 1;
  1096. else if (sploop_ii <= 4)
  1097. fcyc_bits = 2;
  1098. else if (sploop_ii <= 8)
  1099. fcyc_bits = 3;
  1100. else if (sploop_ii <= 14)
  1101. fcyc_bits = 4;
  1102. else
  1103. prev_sploop_found = false;
  1104. }
  1105. if (prev_sploop_found)
  1106. break;
  1107. }
  1108. }
  1109. if (!prev_sploop_found)
  1110. {
  1111. operands_ok = false;
  1112. operands_text[op_num] = true;
  1113. break;
  1114. }
  1115. if (fcyc_bits > tic6x_field_width(field))
  1116. {
  1117. printf ("opcode %x: illegal fcyc value (%d)\n", opcode, fcyc_bits);
  1118. abort ();
  1119. }
  1120. if (enc->coding_method == tic6x_coding_fstg)
  1121. {
  1122. int i, t;
  1123. for (t = 0, i = fcyc_bits; i < 6; i++)
  1124. t = (t << 1) | ((fld_val >> i) & 1);
  1125. operands_text[op_num] = true;
  1126. snprintf (operands[op_num], 24, "%u", t);
  1127. }
  1128. else
  1129. {
  1130. operands_text[op_num] = true;
  1131. snprintf (operands[op_num], 24, "%u",
  1132. fld_val & ((1 << fcyc_bits) - 1));
  1133. }
  1134. break;
  1135. case tic6x_coding_spmask:
  1136. if (fld_val == 0)
  1137. spmask_skip_operand = true;
  1138. else
  1139. {
  1140. char *p;
  1141. unsigned int i;
  1142. operands_text[op_num] = true;
  1143. p = operands[op_num];
  1144. for (i = 0; i < 8; i++)
  1145. if (fld_val & (1 << i))
  1146. {
  1147. *p++ = "LSDM"[i/2];
  1148. *p++ = '1' + (i & 1);
  1149. *p++ = ',';
  1150. }
  1151. p[-1] = 0;
  1152. }
  1153. break;
  1154. case tic6x_coding_fu:
  1155. case tic6x_coding_data_fu:
  1156. case tic6x_coding_xpath:
  1157. case tic6x_coding_rside:
  1158. /* Don't relate to operands, so operand number is
  1159. meaningless. */
  1160. break;
  1161. default:
  1162. printf ("opcode %x: illegal field encoding (%d)\n", opcode, enc->coding_method);
  1163. abort ();
  1164. }
  1165. if (mem_base_reg_known_long && mem_offset_known_long)
  1166. {
  1167. if (operands_text[op_num] || operands_pcrel[op_num])
  1168. {
  1169. printf ("opcode %x: long access but operands already known ?\n", opcode);
  1170. abort ();
  1171. }
  1172. operands_text[op_num] = true;
  1173. snprintf (operands[op_num], 24, "*+b%u(%u)", mem_base_reg,
  1174. mem_offset * opc->operand_info[op_num].size);
  1175. }
  1176. if (mem_base_reg_known && mem_offset_known && mem_mode_known
  1177. && (mem_scaled_known
  1178. || (opc->operand_info[op_num].form
  1179. != tic6x_operand_mem_ndw)))
  1180. {
  1181. char side;
  1182. char base[4];
  1183. bool offset_is_reg;
  1184. bool offset_scaled;
  1185. char offset[4];
  1186. char offsetp[6];
  1187. if (operands_text[op_num] || operands_pcrel[op_num])
  1188. {
  1189. printf ("opcode %x: mem access operands already known ?\n", opcode);
  1190. abort ();
  1191. }
  1192. side = func_unit_side == 2 ? 'b' : 'a';
  1193. snprintf (base, 4, "%c%u", side, mem_base_reg);
  1194. offset_is_reg = (mem_mode & 4) != 0;
  1195. if (offset_is_reg)
  1196. {
  1197. if (num_bits == 16 && header.rs && !(opc->flags & TIC6X_FLAG_INSN16_NORS))
  1198. {
  1199. reg_base = 16;
  1200. }
  1201. snprintf (offset, 4, "%c%u", side, reg_base + mem_offset);
  1202. if (opc->operand_info[op_num].form
  1203. == tic6x_operand_mem_ndw)
  1204. offset_scaled = mem_scaled != 0;
  1205. else
  1206. offset_scaled = true;
  1207. }
  1208. else
  1209. {
  1210. if (opc->operand_info[op_num].form
  1211. == tic6x_operand_mem_ndw)
  1212. {
  1213. offset_scaled = mem_scaled != 0;
  1214. snprintf (offset, 4, "%u", mem_offset);
  1215. }
  1216. else
  1217. {
  1218. offset_scaled = false;
  1219. snprintf (offset, 4, "%u",
  1220. (mem_offset
  1221. * opc->operand_info[op_num].size));
  1222. }
  1223. }
  1224. if (offset_scaled)
  1225. snprintf (offsetp, 6, "[%s]", offset);
  1226. else
  1227. snprintf (offsetp, 6, "(%s)", offset);
  1228. operands_text[op_num] = true;
  1229. switch (mem_mode & ~4u)
  1230. {
  1231. case 0:
  1232. snprintf (operands[op_num], 24, "*-%s%s", base, offsetp);
  1233. break;
  1234. case 1:
  1235. snprintf (operands[op_num], 24, "*+%s%s", base, offsetp);
  1236. break;
  1237. case 2:
  1238. case 3:
  1239. operands_ok = false;
  1240. break;
  1241. case 8:
  1242. snprintf (operands[op_num], 24, "*--%s%s", base,
  1243. offsetp);
  1244. break;
  1245. case 9:
  1246. snprintf (operands[op_num], 24, "*++%s%s", base,
  1247. offsetp);
  1248. break;
  1249. case 10:
  1250. snprintf (operands[op_num], 24, "*%s--%s", base,
  1251. offsetp);
  1252. break;
  1253. case 11:
  1254. snprintf (operands[op_num], 24, "*%s++%s", base,
  1255. offsetp);
  1256. break;
  1257. default:
  1258. printf ("*** unknown mem_mode : %d \n", mem_mode);
  1259. abort ();
  1260. }
  1261. }
  1262. if (crlo_known && crhi_known)
  1263. {
  1264. tic6x_rw rw;
  1265. tic6x_ctrl_id crid;
  1266. if (operands_text[op_num] || operands_pcrel[op_num])
  1267. {
  1268. printf ("*** abort crlo crli\n");
  1269. abort ();
  1270. }
  1271. rw = opc->operand_info[op_num].rw;
  1272. if (rw != tic6x_rw_read
  1273. && rw != tic6x_rw_write)
  1274. {
  1275. printf ("*** abort rw : %d\n", rw);
  1276. abort ();
  1277. }
  1278. for (crid = 0; crid < tic6x_ctrl_max; crid++)
  1279. {
  1280. if (crlo == tic6x_ctrl_table[crid].crlo
  1281. && (crhi & tic6x_ctrl_table[crid].crhi_mask) == 0
  1282. && (rw == tic6x_rw_read
  1283. ? (tic6x_ctrl_table[crid].rw == tic6x_rw_read
  1284. || (tic6x_ctrl_table[crid].rw
  1285. == tic6x_rw_read_write))
  1286. : (tic6x_ctrl_table[crid].rw == tic6x_rw_write
  1287. || (tic6x_ctrl_table[crid].rw
  1288. == tic6x_rw_read_write))))
  1289. break;
  1290. }
  1291. if (crid == tic6x_ctrl_max)
  1292. {
  1293. operands_text[op_num] = true;
  1294. operands_ok = false;
  1295. }
  1296. else
  1297. {
  1298. operands_text[op_num] = true;
  1299. snprintf (operands[op_num], 24, "%s",
  1300. tic6x_ctrl_table[crid].name);
  1301. }
  1302. }
  1303. if (operands_text[op_num] || operands_pcrel[op_num]
  1304. || spmask_skip_operand)
  1305. break;
  1306. }
  1307. /* end for fld_num */
  1308. if (spmask_skip_operand)
  1309. {
  1310. /* SPMASK operands are only valid as the single operand
  1311. in the opcode table. */
  1312. if (num_operands != 1)
  1313. {
  1314. printf ("opcode: %x, num_operands != 1 : %d\n", opcode, num_operands);
  1315. abort ();
  1316. }
  1317. num_operands = 0;
  1318. break;
  1319. }
  1320. /* The operand must by now have been decoded. */
  1321. if (!operands_text[op_num] && !operands_pcrel[op_num])
  1322. {
  1323. printf ("opcode: %x, operand #%d not decoded\n", opcode, op_num);
  1324. abort ();
  1325. }
  1326. }
  1327. /* end for op_num */
  1328. if (!operands_ok)
  1329. continue;
  1330. info->bytes_per_chunk = num_bits / 8;
  1331. info->fprintf_func (info->stream, "%s", parallel);
  1332. info->fprintf_func (info->stream, "%s%s%s", cond, opc->name,
  1333. func_unit);
  1334. for (op_num = 0; op_num < num_operands; op_num++)
  1335. {
  1336. info->fprintf_func (info->stream, "%c", (op_num == 0 ? ' ' : ','));
  1337. if (operands_pcrel[op_num])
  1338. info->print_address_func (operands_addresses[op_num], info);
  1339. else
  1340. info->fprintf_func (info->stream, "%s", operands[op_num]);
  1341. }
  1342. if (fetch_packet_header_based && header.prot)
  1343. info->fprintf_func (info->stream, " || nop 5");
  1344. return num_bits / 8;
  1345. }
  1346. info->bytes_per_chunk = num_bits / 8;
  1347. info->fprintf_func (info->stream, "<undefined instruction 0x%.*x>",
  1348. (int) num_bits / 4, opcode);
  1349. return num_bits / 8;
  1350. }