nds32-dis.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /* NDS32-specific support for 32-bit ELF.
  2. Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. Contributed by Andes Technology Corporation.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include <stdio.h>
  19. #include "ansidecl.h"
  20. #include "disassemble.h"
  21. #include "bfd.h"
  22. #include "symcat.h"
  23. #include "libiberty.h"
  24. #include "opintl.h"
  25. #include <stdint.h>
  26. #include "hashtab.h"
  27. #include "nds32-asm.h"
  28. #include "opcode/nds32.h"
  29. /* Get fields macro define. */
  30. #define MASK_OP(insn, mask) ((insn) & (0x3f << 25 | (mask)))
  31. /* For mapping symbol. */
  32. enum map_type
  33. {
  34. MAP_DATA0,
  35. MAP_DATA1,
  36. MAP_DATA2,
  37. MAP_DATA3,
  38. MAP_DATA4,
  39. MAP_CODE,
  40. };
  41. struct nds32_private_data
  42. {
  43. /* Whether any mapping symbols are present in the provided symbol
  44. table. -1 if we do not know yet, otherwise 0 or 1. */
  45. int has_mapping_symbols;
  46. /* Track the last type (although this doesn't seem to be useful). */
  47. enum map_type last_mapping_type;
  48. /* Tracking symbol table information. */
  49. int last_symbol_index;
  50. bfd_vma last_addr;
  51. };
  52. /* Default text to print if an instruction isn't recognized. */
  53. #define UNKNOWN_INSN_MSG _("*unknown*")
  54. #define NDS32_PARSE_INSN16 0x01
  55. #define NDS32_PARSE_INSN32 0x02
  56. static uint32_t nds32_mask_opcode (uint32_t);
  57. static void nds32_special_opcode (uint32_t, struct nds32_opcode **);
  58. static int get_mapping_symbol_type (struct disassemble_info *, int,
  59. enum map_type *);
  60. static int is_mapping_symbol (struct disassemble_info *, int,
  61. enum map_type *);
  62. /* Hash function for disassemble. */
  63. static htab_t opcode_htab;
  64. /* Find the value map register name. */
  65. static const keyword_t *
  66. nds32_find_reg_keyword (const keyword_t *reg, int value)
  67. {
  68. if (!reg)
  69. return NULL;
  70. while (reg->name != NULL && reg->value != value)
  71. {
  72. reg++;
  73. }
  74. if (reg->name == NULL)
  75. return NULL;
  76. return reg;
  77. }
  78. static void
  79. nds32_parse_audio_ext (const field_t *pfd,
  80. disassemble_info *info, uint32_t insn)
  81. {
  82. fprintf_ftype func = info->fprintf_func;
  83. void *stream = info->stream;
  84. const keyword_t *psys_reg;
  85. int int_value, new_value;
  86. if (pfd->hw_res == HW_INT || pfd->hw_res == HW_UINT)
  87. {
  88. if (pfd->hw_res == HW_INT)
  89. int_value = (unsigned) N32_IMMS (insn >> pfd->bitpos,
  90. pfd->bitsize) << pfd->shift;
  91. else
  92. int_value = __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
  93. if (int_value < 10)
  94. func (stream, "#%d", int_value);
  95. else
  96. func (stream, "#0x%x", int_value);
  97. return;
  98. }
  99. int_value =
  100. __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
  101. new_value = int_value;
  102. psys_reg = (keyword_t*) nds32_keywords[pfd->hw_res];
  103. /* p = bit[4].bit[1:0], r = bit[4].bit[3:2]. */
  104. if (strcmp (pfd->name, "im5_i") == 0)
  105. {
  106. new_value = int_value & 0x03;
  107. new_value |= ((int_value & 0x10) >> 2);
  108. }
  109. else if (strcmp (pfd->name, "im5_m") == 0)
  110. {
  111. new_value = ((int_value & 0x1C) >> 2);
  112. }
  113. /* p = 0.bit[1:0], r = 0.bit[3:2]. */
  114. /* q = 1.bit[1:0], s = 1.bit[5:4]. */
  115. else if (strcmp (pfd->name, "im6_iq") == 0)
  116. {
  117. new_value |= 0x04;
  118. }
  119. else if (strcmp (pfd->name, "im6_ms") == 0)
  120. {
  121. new_value |= 0x04;
  122. }
  123. /* Rt CONCAT(c, t21, t0). */
  124. else if (strcmp (pfd->name, "a_rt21") == 0)
  125. {
  126. new_value = (insn & 0x00000020) >> 5;
  127. new_value |= (insn & 0x00000C00) >> 9;
  128. new_value |= (insn & 0x00008000) >> 12;
  129. }
  130. else if (strcmp (pfd->name, "a_rte") == 0)
  131. {
  132. new_value = (insn & 0x00000C00) >> 9;
  133. new_value |= (insn & 0x00008000) >> 12;
  134. }
  135. else if (strcmp (pfd->name, "a_rte1") == 0)
  136. {
  137. new_value = (insn & 0x00000C00) >> 9;
  138. new_value |= (insn & 0x00008000) >> 12;
  139. new_value |= 0x01;
  140. }
  141. else if (strcmp (pfd->name, "a_rte69") == 0)
  142. {
  143. new_value = int_value << 1;
  144. }
  145. else if (strcmp (pfd->name, "a_rte69_1") == 0)
  146. {
  147. new_value = int_value << 1;
  148. new_value |= 0x01;
  149. }
  150. psys_reg = nds32_find_reg_keyword (psys_reg, new_value);
  151. if (!psys_reg)
  152. func (stream, "???");
  153. else
  154. func (stream, "$%s", psys_reg->name);
  155. }
  156. /* Match instruction opcode with keyword table. */
  157. static field_t *
  158. match_field (char *name)
  159. {
  160. field_t *pfd;
  161. int k;
  162. for (k = 0; k < NDS32_CORE_COUNT; k++)
  163. {
  164. pfd = (field_t *) nds32_field_table[k];
  165. while (1)
  166. {
  167. if (pfd->name == NULL)
  168. break;
  169. if (strcmp (name, pfd->name) == 0)
  170. return pfd;
  171. pfd++;
  172. }
  173. }
  174. return NULL;
  175. }
  176. /* Dump instruction. If the opcode is unknown, return FALSE. */
  177. static void
  178. nds32_parse_opcode (struct nds32_opcode *opc, bfd_vma pc ATTRIBUTE_UNUSED,
  179. disassemble_info *info, uint32_t insn,
  180. uint32_t parse_mode)
  181. {
  182. int op = 0;
  183. fprintf_ftype func = info->fprintf_func;
  184. void *stream = info->stream;
  185. const char *pstr_src;
  186. char *pstr_tmp;
  187. char tmp_string[16];
  188. unsigned int push25gpr = 0, lsmwRb, lsmwRe, lsmwEnb4, checkbit, i;
  189. int int_value, ifthe1st = 1;
  190. const field_t *pfd;
  191. const keyword_t *psys_reg;
  192. if (opc == NULL)
  193. {
  194. func (stream, UNKNOWN_INSN_MSG);
  195. return;
  196. }
  197. pstr_src = opc->instruction;
  198. if (*pstr_src == 0)
  199. {
  200. func (stream, "%s", opc->opcode);
  201. return;
  202. }
  203. /* NDS32_PARSE_INSN16. */
  204. if (parse_mode & NDS32_PARSE_INSN16)
  205. {
  206. func (stream, "%s ", opc->opcode);
  207. }
  208. /* NDS32_PARSE_INSN32. */
  209. else
  210. {
  211. op = N32_OP6 (insn);
  212. if (op == N32_OP6_LSMW)
  213. func (stream, "%s.", opc->opcode);
  214. else if (strstr (opc->instruction, "tito"))
  215. func (stream, "%s", opc->opcode);
  216. else
  217. func (stream, "%s\t", opc->opcode);
  218. }
  219. while (*pstr_src)
  220. {
  221. switch (*pstr_src)
  222. {
  223. case '%':
  224. case '=':
  225. case '&':
  226. pstr_src++;
  227. /* Compare with nds32_operand_fields[].name. */
  228. pstr_tmp = &tmp_string[0];
  229. while (*pstr_src)
  230. {
  231. if ((*pstr_src == ',') || (*pstr_src == ' ')
  232. || (*pstr_src == '{') || (*pstr_src == '}')
  233. || (*pstr_src == '[') || (*pstr_src == ']')
  234. || (*pstr_src == '(') || (*pstr_src == ')')
  235. || (*pstr_src == '+') || (*pstr_src == '<'))
  236. break;
  237. *pstr_tmp++ = *pstr_src++;
  238. }
  239. *pstr_tmp = 0;
  240. if ((pfd = match_field (&tmp_string[0])) == NULL)
  241. return;
  242. /* For insn-16. */
  243. if (parse_mode & NDS32_PARSE_INSN16)
  244. {
  245. if (pfd->hw_res == HW_GPR)
  246. {
  247. int_value =
  248. __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
  249. /* push25/pop25. */
  250. if ((opc->value == 0xfc00) || (opc->value == 0xfc80))
  251. {
  252. if (int_value == 0)
  253. int_value = 6;
  254. else
  255. int_value = (6 + (0x01 << int_value));
  256. push25gpr = int_value;
  257. }
  258. else if (strcmp (pfd->name, "rt4") == 0)
  259. {
  260. int_value = nds32_r45map[int_value];
  261. }
  262. func (stream, "$%s", nds32_keyword_gpr[int_value].name);
  263. }
  264. else if ((pfd->hw_res == HW_INT) || (pfd->hw_res == HW_UINT))
  265. {
  266. if (pfd->hw_res == HW_INT)
  267. int_value
  268. = (unsigned) N32_IMMS (insn >> pfd->bitpos,
  269. pfd->bitsize) << pfd->shift;
  270. else
  271. int_value =
  272. __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
  273. /* movpi45. */
  274. if (opc->value == 0xfa00)
  275. {
  276. int_value += 16;
  277. func (stream, "#0x%x", int_value);
  278. }
  279. /* lwi45.fe. */
  280. else if (opc->value == 0xb200)
  281. {
  282. int_value = 0 - (128 - int_value);
  283. func (stream, "#%d", int_value);
  284. }
  285. /* beqz38/bnez38/beqs38/bnes38/j8/beqzs8/bnezs8. */
  286. else if ((opc->value == 0xc000) || (opc->value == 0xc800)
  287. || (opc->value == 0xd000) || (opc->value == 0xd800)
  288. || (opc->value == 0xd500) || (opc->value == 0xe800)
  289. || (opc->value == 0xe900))
  290. {
  291. info->print_address_func (int_value + pc, info);
  292. }
  293. /* push25/pop25. */
  294. else if ((opc->value == 0xfc00) || (opc->value == 0xfc80))
  295. {
  296. func (stream, "#%d ! {$r6", int_value);
  297. if (push25gpr != 6)
  298. func (stream, "~$%s", nds32_keyword_gpr[push25gpr].name);
  299. func (stream, ", $fp, $gp, $lp}");
  300. }
  301. else if (pfd->hw_res == HW_INT)
  302. {
  303. if (int_value < 10)
  304. func (stream, "#%d", int_value);
  305. else
  306. func (stream, "#0x%x", int_value);
  307. }
  308. else /* if (pfd->hw_res == HW_UINT). */
  309. {
  310. if (int_value < 10)
  311. func (stream, "#%u", int_value);
  312. else
  313. func (stream, "#0x%x", int_value);
  314. }
  315. }
  316. }
  317. /* for audio-ext. */
  318. else if (op == N32_OP6_AEXT)
  319. {
  320. nds32_parse_audio_ext (pfd, info, insn);
  321. }
  322. /* for insn-32. */
  323. else if (pfd->hw_res < HW_INT)
  324. {
  325. int_value =
  326. __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
  327. psys_reg = *(nds32_keyword_table[pfd->hw_res >> 8]
  328. + (pfd->hw_res & 0xff));
  329. psys_reg = nds32_find_reg_keyword (psys_reg, int_value);
  330. /* For HW_SR, dump the index when it can't
  331. map the register name. */
  332. if (!psys_reg && pfd->hw_res == HW_SR)
  333. func (stream, "%d", int_value);
  334. else if (!psys_reg)
  335. func (stream, "???");
  336. else
  337. {
  338. if (pfd->hw_res == HW_GPR || pfd->hw_res == HW_CPR
  339. || pfd->hw_res == HW_FDR || pfd->hw_res == HW_FSR
  340. || pfd->hw_res == HW_DXR || pfd->hw_res == HW_SR
  341. || pfd->hw_res == HW_USR)
  342. func (stream, "$%s", psys_reg->name);
  343. else if (pfd->hw_res == HW_DTITON
  344. || pfd->hw_res == HW_DTITOFF)
  345. func (stream, ".%s", psys_reg->name);
  346. else
  347. func (stream, "%s", psys_reg->name);
  348. }
  349. }
  350. else if ((pfd->hw_res == HW_INT) || (pfd->hw_res == HW_UINT))
  351. {
  352. if (pfd->hw_res == HW_INT)
  353. int_value = (unsigned) N32_IMMS (insn >> pfd->bitpos,
  354. pfd->bitsize) << pfd->shift;
  355. else
  356. int_value =
  357. __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
  358. if ((op == N32_OP6_BR1) || (op == N32_OP6_BR2))
  359. {
  360. info->print_address_func (int_value + pc, info);
  361. }
  362. else if ((op == N32_OP6_BR3) && (pfd->bitpos == 0))
  363. {
  364. info->print_address_func (int_value + pc, info);
  365. }
  366. else if (op == N32_OP6_JI)
  367. {
  368. /* FIXME: Handle relocation. */
  369. if (info->flags & INSN_HAS_RELOC)
  370. pc = 0;
  371. info->print_address_func (int_value + pc, info);
  372. }
  373. else if (op == N32_OP6_LSMW)
  374. {
  375. /* lmw.adm/smw.adm. */
  376. func (stream, "#0x%x ! {", int_value);
  377. lsmwEnb4 = int_value;
  378. lsmwRb = ((insn >> 20) & 0x1F);
  379. lsmwRe = ((insn >> 10) & 0x1F);
  380. /* If [Rb, Re] specifies at least one register,
  381. Rb(4,0) <= Re(4,0) and 0 <= Rb(4,0), Re(4,0) < 28.
  382. Disassembling does not consider this currently because of
  383. the convience comparing with bsp320. */
  384. if (lsmwRb != 31 || lsmwRe != 31)
  385. {
  386. func (stream, "$%s", nds32_keyword_gpr[lsmwRb].name);
  387. if (lsmwRb != lsmwRe)
  388. func (stream, "~$%s", nds32_keyword_gpr[lsmwRe].name);
  389. ifthe1st = 0;
  390. }
  391. if (lsmwEnb4 != 0)
  392. {
  393. /* $fp, $gp, $lp, $sp. */
  394. checkbit = 0x08;
  395. for (i = 0; i < 4; i++)
  396. {
  397. if (lsmwEnb4 & checkbit)
  398. {
  399. if (ifthe1st == 1)
  400. {
  401. ifthe1st = 0;
  402. func (stream, "$%s", nds32_keyword_gpr[28 + i].name);
  403. }
  404. else
  405. func (stream, ", $%s", nds32_keyword_gpr[28 + i].name);
  406. }
  407. checkbit >>= 1;
  408. }
  409. }
  410. func (stream, "}");
  411. }
  412. else if (pfd->hw_res == HW_INT)
  413. {
  414. if (int_value < 10)
  415. func (stream, "#%d", int_value);
  416. else
  417. func (stream, "#0x%x", int_value);
  418. }
  419. else /* if (pfd->hw_res == HW_UINT). */
  420. {
  421. if (int_value < 10)
  422. func (stream, "#%u", int_value);
  423. else
  424. func (stream, "#0x%x", int_value);
  425. }
  426. }
  427. break;
  428. case '{':
  429. case '}':
  430. pstr_src++;
  431. break;
  432. case ',':
  433. func (stream, ", ");
  434. pstr_src++;
  435. break;
  436. case '+':
  437. func (stream, " + ");
  438. pstr_src++;
  439. break;
  440. case '<':
  441. if (pstr_src[1] == '<')
  442. {
  443. func (stream, " << ");
  444. pstr_src += 2;
  445. }
  446. else
  447. {
  448. func (stream, " <");
  449. pstr_src++;
  450. }
  451. break;
  452. default:
  453. func (stream, "%c", *pstr_src++);
  454. break;
  455. }
  456. }
  457. }
  458. /* Filter instructions with some bits must be fixed. */
  459. static void
  460. nds32_filter_unknown_insn (uint32_t insn, struct nds32_opcode **opc)
  461. {
  462. if (!(*opc))
  463. return;
  464. switch ((*opc)->value)
  465. {
  466. case JREG (JR):
  467. case JREG (JRNEZ):
  468. /* jr jr.xtoff */
  469. if (__GF (insn, 6, 2) != 0 || __GF (insn, 15, 10) != 0)
  470. *opc = NULL;
  471. break;
  472. case MISC (STANDBY):
  473. if (__GF (insn, 7, 18) != 0)
  474. *opc = NULL;
  475. break;
  476. case SIMD (PBSAD):
  477. case SIMD (PBSADA):
  478. if (__GF (insn, 5, 5) != 0)
  479. *opc = NULL;
  480. break;
  481. case BR2 (SOP0):
  482. if (__GF (insn, 20, 5) != 0)
  483. *opc = NULL;
  484. break;
  485. case JREG (JRAL):
  486. if (__GF (insn, 5, 3) != 0 || __GF (insn, 15, 5) != 0)
  487. *opc = NULL;
  488. break;
  489. case ALU1 (NOR):
  490. case ALU1 (SLT):
  491. case ALU1 (SLTS):
  492. case ALU1 (SLLI):
  493. case ALU1 (SRLI):
  494. case ALU1 (SRAI):
  495. case ALU1 (ROTRI):
  496. case ALU1 (SLL):
  497. case ALU1 (SRL):
  498. case ALU1 (SRA):
  499. case ALU1 (ROTR):
  500. case ALU1 (SEB):
  501. case ALU1 (SEH):
  502. case ALU1 (ZEH):
  503. case ALU1 (WSBH):
  504. case ALU1 (SVA):
  505. case ALU1 (SVS):
  506. case ALU1 (CMOVZ):
  507. case ALU1 (CMOVN):
  508. if (__GF (insn, 5, 5) != 0)
  509. *opc = NULL;
  510. break;
  511. case MISC (IRET):
  512. case MISC (ISB):
  513. case MISC (DSB):
  514. if (__GF (insn, 5, 20) != 0)
  515. *opc = NULL;
  516. break;
  517. }
  518. }
  519. static void
  520. print_insn32 (bfd_vma pc, disassemble_info *info, uint32_t insn,
  521. uint32_t parse_mode)
  522. {
  523. /* Get the final correct opcode and parse. */
  524. struct nds32_opcode *opc;
  525. uint32_t opcode = nds32_mask_opcode (insn);
  526. opc = (struct nds32_opcode *) htab_find (opcode_htab, &opcode);
  527. nds32_special_opcode (insn, &opc);
  528. nds32_filter_unknown_insn (insn, &opc);
  529. nds32_parse_opcode (opc, pc, info, insn, parse_mode);
  530. }
  531. static void
  532. print_insn16 (bfd_vma pc, disassemble_info *info,
  533. uint32_t insn, uint32_t parse_mode)
  534. {
  535. struct nds32_opcode *opc;
  536. uint32_t opcode;
  537. /* Get highest 7 bit in default. */
  538. unsigned int mask = 0xfe00;
  539. /* Classify 16-bit instruction to 4 sets by bit 13 and 14. */
  540. switch (__GF (insn, 13, 2))
  541. {
  542. case 0x0:
  543. /* mov55 movi55 */
  544. if (__GF (insn, 11, 2) == 0)
  545. {
  546. mask = 0xfc00;
  547. /* ifret16 = mov55 $sp, $sp*/
  548. if (__GF (insn, 0, 11) == 0x3ff)
  549. mask = 0xffff;
  550. }
  551. else if (__GF (insn, 9, 4) == 0xb)
  552. mask = 0xfe07;
  553. break;
  554. case 0x1:
  555. /* lwi37 swi37 */
  556. if (__GF (insn, 11, 2) == 0x3)
  557. mask = 0xf880;
  558. break;
  559. case 0x2:
  560. mask = 0xf800;
  561. /* Exclude beqz38, bnez38, beqs38, and bnes38. */
  562. if (__GF (insn, 12, 1) == 0x1
  563. && __GF (insn, 8, 3) == 0x5)
  564. {
  565. if (__GF (insn, 11, 1) == 0x0)
  566. mask = 0xff00;
  567. else
  568. mask = 0xffe0;
  569. }
  570. break;
  571. case 0x3:
  572. switch (__GF (insn, 11, 2))
  573. {
  574. case 0x1:
  575. /* beqzs8 bnezs8 */
  576. if (__GF (insn, 9, 2) == 0x0)
  577. mask = 0xff00;
  578. /* addi10s */
  579. else if (__GF(insn, 10, 1) == 0x1)
  580. mask = 0xfc00;
  581. break;
  582. case 0x2:
  583. /* lwi37.sp swi37.sp */
  584. mask = 0xf880;
  585. break;
  586. case 0x3:
  587. if (__GF (insn, 8, 3) == 0x5)
  588. mask = 0xff00;
  589. else if (__GF (insn, 8, 3) == 0x4)
  590. mask = 0xff80;
  591. else if (__GF (insn, 9 , 2) == 0x3)
  592. mask = 0xfe07;
  593. break;
  594. }
  595. break;
  596. }
  597. opcode = insn & mask;
  598. opc = (struct nds32_opcode *) htab_find (opcode_htab, &opcode);
  599. nds32_special_opcode (insn, &opc);
  600. /* Get the final correct opcode and parse it. */
  601. nds32_parse_opcode (opc, pc, info, insn, parse_mode);
  602. }
  603. static hashval_t
  604. htab_hash_hash (const void *p)
  605. {
  606. return (*(unsigned int *) p) % 49;
  607. }
  608. static int
  609. htab_hash_eq (const void *p, const void *q)
  610. {
  611. uint32_t pinsn = ((struct nds32_opcode *) p)->value;
  612. uint32_t qinsn = *((uint32_t *) q);
  613. return (pinsn == qinsn);
  614. }
  615. /* Get the format of instruction. */
  616. static uint32_t
  617. nds32_mask_opcode (uint32_t insn)
  618. {
  619. uint32_t opcode = N32_OP6 (insn);
  620. switch (opcode)
  621. {
  622. case N32_OP6_LBI:
  623. case N32_OP6_LHI:
  624. case N32_OP6_LWI:
  625. case N32_OP6_LDI:
  626. case N32_OP6_LBI_BI:
  627. case N32_OP6_LHI_BI:
  628. case N32_OP6_LWI_BI:
  629. case N32_OP6_LDI_BI:
  630. case N32_OP6_SBI:
  631. case N32_OP6_SHI:
  632. case N32_OP6_SWI:
  633. case N32_OP6_SDI:
  634. case N32_OP6_SBI_BI:
  635. case N32_OP6_SHI_BI:
  636. case N32_OP6_SWI_BI:
  637. case N32_OP6_SDI_BI:
  638. case N32_OP6_LBSI:
  639. case N32_OP6_LHSI:
  640. case N32_OP6_LWSI:
  641. case N32_OP6_LBSI_BI:
  642. case N32_OP6_LHSI_BI:
  643. case N32_OP6_LWSI_BI:
  644. case N32_OP6_MOVI:
  645. case N32_OP6_SETHI:
  646. case N32_OP6_ADDI:
  647. case N32_OP6_SUBRI:
  648. case N32_OP6_ANDI:
  649. case N32_OP6_XORI:
  650. case N32_OP6_ORI:
  651. case N32_OP6_SLTI:
  652. case N32_OP6_SLTSI:
  653. case N32_OP6_CEXT:
  654. case N32_OP6_BITCI:
  655. return MASK_OP (insn, 0);
  656. case N32_OP6_ALU2:
  657. /* FFBI */
  658. if (__GF (insn, 0, 7) == (N32_ALU2_FFBI | N32_BIT (6)))
  659. return MASK_OP (insn, 0x7f);
  660. else if (__GF (insn, 0, 7) == (N32_ALU2_MFUSR | N32_BIT (6))
  661. || __GF (insn, 0, 7) == (N32_ALU2_MTUSR | N32_BIT (6)))
  662. /* RDOV CLROV */
  663. return MASK_OP (insn, 0xf81ff);
  664. else if (__GF (insn, 0, 10) == (N32_ALU2_ONEOP | N32_BIT (7)))
  665. {
  666. /* INSB */
  667. if (__GF (insn, 12, 3) == 4)
  668. return MASK_OP (insn, 0x73ff);
  669. return MASK_OP (insn, 0x7fff);
  670. }
  671. return MASK_OP (insn, 0x3ff);
  672. case N32_OP6_ALU1:
  673. case N32_OP6_SIMD:
  674. return MASK_OP (insn, 0x1f);
  675. case N32_OP6_MEM:
  676. return MASK_OP (insn, 0xff);
  677. case N32_OP6_JREG:
  678. return MASK_OP (insn, 0x7f);
  679. case N32_OP6_LSMW:
  680. return MASK_OP (insn, 0x23);
  681. case N32_OP6_SBGP:
  682. case N32_OP6_LBGP:
  683. return MASK_OP (insn, 0x1 << 19);
  684. case N32_OP6_HWGP:
  685. if (__GF (insn, 18, 2) == 0x3)
  686. return MASK_OP (insn, 0x7 << 17);
  687. return MASK_OP (insn, 0x3 << 18);
  688. case N32_OP6_DPREFI:
  689. return MASK_OP (insn, 0x1 << 24);
  690. case N32_OP6_LWC:
  691. case N32_OP6_SWC:
  692. case N32_OP6_LDC:
  693. case N32_OP6_SDC:
  694. return MASK_OP (insn, 0x1 << 12);
  695. case N32_OP6_JI:
  696. return MASK_OP (insn, 0x1 << 24);
  697. case N32_OP6_BR1:
  698. return MASK_OP (insn, 0x1 << 14);
  699. case N32_OP6_BR2:
  700. if (__GF (insn, 16, 4) == 0)
  701. return MASK_OP (insn, 0x1ff << 16);
  702. else
  703. return MASK_OP (insn, 0xf << 16);
  704. case N32_OP6_BR3:
  705. return MASK_OP (insn, 0x1 << 19);
  706. case N32_OP6_MISC:
  707. switch (__GF (insn, 0, 5))
  708. {
  709. case N32_MISC_MTSR:
  710. /* SETGIE and SETEND */
  711. if (__GF (insn, 5, 5) == 0x1 || __GF (insn, 5, 5) == 0x2)
  712. return MASK_OP (insn, 0x1fffff);
  713. return MASK_OP (insn, 0x1f);
  714. case N32_MISC_TLBOP:
  715. if (__GF (insn, 5, 5) == 5 || __GF (insn, 5, 5) == 7)
  716. /* PB FLUA */
  717. return MASK_OP (insn, 0x3ff);
  718. return MASK_OP (insn, 0x1f);
  719. default:
  720. return MASK_OP (insn, 0x1f);
  721. }
  722. case N32_OP6_COP:
  723. if (__GF (insn, 4, 2) == 0)
  724. {
  725. /* FPU */
  726. switch (__GF (insn, 0, 4))
  727. {
  728. case 0x0:
  729. case 0x8:
  730. /* FS1/F2OP FD1/F2OP */
  731. if (__GF (insn, 6, 4) == 0xf)
  732. return MASK_OP (insn, 0x7fff);
  733. /* FS1 FD1 */
  734. return MASK_OP (insn, 0x3ff);
  735. case 0x4:
  736. case 0xc:
  737. /* FS2 */
  738. return MASK_OP (insn, 0x3ff);
  739. case 0x1:
  740. case 0x9:
  741. /* XR */
  742. if (__GF (insn, 6, 4) == 0xc)
  743. return MASK_OP (insn, 0x7fff);
  744. /* MFCP MTCP */
  745. return MASK_OP (insn, 0x3ff);
  746. default:
  747. return MASK_OP (insn, 0xff);
  748. }
  749. }
  750. else if (__GF (insn, 0, 2) == 0)
  751. return MASK_OP (insn, 0xf);
  752. return MASK_OP (insn, 0xcf);
  753. case N32_OP6_AEXT:
  754. /* AUDIO */
  755. switch (__GF (insn, 23, 2))
  756. {
  757. case 0x0:
  758. if (__GF (insn, 5, 4) == 0)
  759. /* AMxxx AMAyyS AMyyS AMAWzS AMWzS */
  760. return MASK_OP (insn, (0x1f << 20) | 0x1ff);
  761. else if (__GF (insn, 5, 4) == 1)
  762. /* ALR ASR ALA ASA AUPI */
  763. return MASK_OP (insn, (0x1f << 20) | (0xf << 5));
  764. else if (__GF (insn, 20, 3) == 0 && __GF (insn, 6, 3) == 1)
  765. /* ALR2 */
  766. return MASK_OP (insn, (0x1f << 20) | (0x7 << 6));
  767. else if (__GF (insn, 20 ,3) == 2 && __GF (insn, 6, 3) == 1)
  768. /* AWEXT ASATS48 */
  769. return MASK_OP (insn, (0x1f << 20) | (0xf << 5));
  770. else if (__GF (insn, 20 ,3) == 3 && __GF (insn, 6, 3) == 1)
  771. /* AMTAR AMTAR2 AMFAR AMFAR2 */
  772. return MASK_OP (insn, (0x1f << 20) | (0x1f << 5));
  773. else if (__GF (insn, 7, 2) == 3)
  774. /* AMxxxSA */
  775. return MASK_OP (insn, (0x1f << 20) | (0x3 << 7));
  776. else if (__GF (insn, 6, 3) == 2)
  777. /* AMxxxL.S */
  778. return MASK_OP (insn, (0x1f << 20) | (0xf << 5));
  779. else
  780. /* AmxxxL.l AmxxxL2.S AMxxxL2.L */
  781. return MASK_OP (insn, (0x1f << 20) | (0x7 << 6));
  782. case 0x1:
  783. if (__GF (insn, 20, 3) == 0)
  784. /* AADDL ASUBL */
  785. return MASK_OP (insn, (0x1f << 20) | (0x1 << 5));
  786. else if (__GF (insn, 20, 3) == 1)
  787. /* AMTARI Ix AMTARI Mx */
  788. return MASK_OP (insn, (0x1f << 20));
  789. else if (__GF (insn, 6, 3) == 2)
  790. /* AMAWzSl.S AMWzSl.S */
  791. return MASK_OP (insn, (0x1f << 20) | (0xf << 5));
  792. else if (__GF (insn, 7, 2) == 3)
  793. /* AMAWzSSA AMWzSSA */
  794. return MASK_OP (insn, (0x1f << 20) | (0x3 << 7));
  795. else
  796. /* AMAWzSL.L AMAWzSL2.S AMAWzSL2.L
  797. AMWzSL.L AMWzSL.L AMWzSL2.S */
  798. return MASK_OP (insn, (0x1f << 20) | (0x7 << 6));
  799. case 0x2:
  800. if (__GF (insn, 6, 3) == 2)
  801. /* AMAyySl.S AMWyySl.S */
  802. return MASK_OP (insn, (0x1f << 20) | (0xf << 5));
  803. else if (__GF (insn, 7, 2) == 3)
  804. /* AMAWyySSA AMWyySSA */
  805. return MASK_OP (insn, (0x1f << 20) | (0x3 << 7));
  806. else
  807. /* AMAWyySL.L AMAWyySL2.S AMAWyySL2.L
  808. AMWyySL.L AMWyySL.L AMWyySL2.S */
  809. return MASK_OP (insn, (0x1f << 20) | (0x7 << 6));
  810. }
  811. return MASK_OP (insn, 0x1f << 20);
  812. default:
  813. return 1u << 31;
  814. }
  815. }
  816. /* Define cctl subtype. */
  817. static char *cctl_subtype [] =
  818. {
  819. /* 0x0 */
  820. "st0", "st0", "st0", "st2", "st2", "st3", "st3", "st4",
  821. "st1", "st1", "st1", "st0", "st0", NULL, NULL, "st5",
  822. /* 0x10 */
  823. "st0", NULL, NULL, "st2", "st2", "st3", "st3", NULL,
  824. "st1", NULL, NULL, "st0", "st0", NULL, NULL, NULL
  825. };
  826. /* Check the subset of opcode. */
  827. static void
  828. nds32_special_opcode (uint32_t insn, struct nds32_opcode **opc)
  829. {
  830. char *string = NULL;
  831. uint32_t op;
  832. if (!(*opc))
  833. return;
  834. /* Check if special case. */
  835. switch ((*opc)->value)
  836. {
  837. case OP6 (LWC):
  838. case OP6 (SWC):
  839. case OP6 (LDC):
  840. case OP6 (SDC):
  841. case FPU_RA_IMMBI (LWC):
  842. case FPU_RA_IMMBI (SWC):
  843. case FPU_RA_IMMBI (LDC):
  844. case FPU_RA_IMMBI (SDC):
  845. /* Check if cp0 => FPU. */
  846. if (__GF (insn, 13, 2) == 0)
  847. {
  848. while (!((*opc)->attr & ATTR (FPU)) && (*opc)->next)
  849. *opc = (*opc)->next;
  850. }
  851. break;
  852. case ALU1 (ADD):
  853. case ALU1 (SUB):
  854. case ALU1 (AND):
  855. case ALU1 (XOR):
  856. case ALU1 (OR):
  857. /* Check if (add/add_slli) (sub/sub_slli) (and/and_slli). */
  858. if (N32_SH5(insn) != 0)
  859. string = "sh";
  860. break;
  861. case ALU1 (SRLI):
  862. /* Check if nop. */
  863. if (__GF (insn, 10, 15) == 0)
  864. string = "nop";
  865. break;
  866. case MISC (CCTL):
  867. string = cctl_subtype [__GF (insn, 5, 5)];
  868. break;
  869. case JREG (JR):
  870. case JREG (JRAL):
  871. case JREG (JR) | JREG_RET:
  872. if (__GF (insn, 8, 2) != 0)
  873. string = "tit";
  874. break;
  875. case N32_OP6_COP:
  876. break;
  877. case 0x9200:
  878. /* nop16 */
  879. if (__GF (insn, 0, 9) == 0)
  880. string = "nop16";
  881. break;
  882. }
  883. if (string)
  884. {
  885. while (strstr ((*opc)->opcode, string) == NULL
  886. && strstr ((*opc)->instruction, string) == NULL && (*opc)->next)
  887. *opc = (*opc)->next;
  888. return;
  889. }
  890. /* Classify instruction is COP or FPU. */
  891. op = N32_OP6 (insn);
  892. if (op == N32_OP6_COP && __GF (insn, 4, 2) != 0)
  893. {
  894. while (((*opc)->attr & ATTR (FPU)) != 0 && (*opc)->next)
  895. *opc = (*opc)->next;
  896. }
  897. }
  898. int
  899. print_insn_nds32 (bfd_vma pc, disassemble_info *info)
  900. {
  901. int status;
  902. bfd_byte buf[4];
  903. bfd_byte buf_data[16];
  904. uint64_t given;
  905. uint64_t given1;
  906. uint32_t insn;
  907. int n;
  908. int last_symbol_index = -1;
  909. bfd_vma addr;
  910. int is_data = false;
  911. bool found = false;
  912. struct nds32_private_data *private_data;
  913. unsigned int size;
  914. enum map_type mapping_type = MAP_CODE;
  915. if (info->private_data == NULL)
  916. {
  917. /* Note: remain lifecycle throughout whole execution. */
  918. static struct nds32_private_data private;
  919. private.has_mapping_symbols = -1; /* unknown yet. */
  920. private.last_symbol_index = -1;
  921. private.last_addr = 0;
  922. info->private_data = &private;
  923. }
  924. private_data = info->private_data;
  925. if (info->symtab_size != 0)
  926. {
  927. int start;
  928. if (pc == 0)
  929. start = 0;
  930. else
  931. {
  932. start = info->symtab_pos;
  933. if (start < private_data->last_symbol_index)
  934. start = private_data->last_symbol_index;
  935. }
  936. if (0 > start)
  937. start = 0;
  938. if (private_data->has_mapping_symbols != 0
  939. && ((strncmp (".text", info->section->name, 5) == 0)))
  940. {
  941. for (n = start; n < info->symtab_size; n++)
  942. {
  943. addr = bfd_asymbol_value (info->symtab[n]);
  944. if (addr > pc)
  945. break;
  946. if (get_mapping_symbol_type (info, n, &mapping_type))
  947. {
  948. last_symbol_index = n;
  949. found = true;
  950. }
  951. }
  952. if (found)
  953. private_data->has_mapping_symbols = 1;
  954. else if (!found && private_data->has_mapping_symbols == -1)
  955. {
  956. /* Make sure there are no any mapping symbol. */
  957. for (n = 0; n < info->symtab_size; n++)
  958. {
  959. if (is_mapping_symbol (info, n, &mapping_type))
  960. {
  961. private_data->has_mapping_symbols = -1;
  962. break;
  963. }
  964. }
  965. if (private_data->has_mapping_symbols == -1)
  966. private_data->has_mapping_symbols = 0;
  967. }
  968. private_data->last_symbol_index = last_symbol_index;
  969. private_data->last_mapping_type = mapping_type;
  970. is_data = (private_data->last_mapping_type == MAP_DATA0
  971. || private_data->last_mapping_type == MAP_DATA1
  972. || private_data->last_mapping_type == MAP_DATA2
  973. || private_data->last_mapping_type == MAP_DATA3
  974. || private_data->last_mapping_type == MAP_DATA4);
  975. }
  976. }
  977. /* Wonder data or instruction. */
  978. if (is_data)
  979. {
  980. unsigned int i1;
  981. /* Fix corner case: there is no next mapping symbol,
  982. let mapping type decides size */
  983. size = 16;
  984. if (last_symbol_index + 1 >= info->symtab_size)
  985. {
  986. if (mapping_type == MAP_DATA0)
  987. size = 1;
  988. if (mapping_type == MAP_DATA1)
  989. size = 2;
  990. if (mapping_type == MAP_DATA2)
  991. size = 4;
  992. if (mapping_type == MAP_DATA3)
  993. size = 8;
  994. if (mapping_type == MAP_DATA4)
  995. size = 16;
  996. }
  997. for (n = last_symbol_index + 1; n < info->symtab_size; n++)
  998. {
  999. addr = bfd_asymbol_value (info->symtab[n]);
  1000. enum map_type fake_mapping_type;
  1001. if (get_mapping_symbol_type (info, n, &fake_mapping_type)
  1002. && (addr > pc
  1003. && ((info->section == NULL)
  1004. || (info->section == info->symtab[n]->section)))
  1005. && (addr - pc < size))
  1006. {
  1007. size = addr - pc;
  1008. break;
  1009. }
  1010. }
  1011. if (size == 3)
  1012. size = (pc & 1) ? 1 : 2;
  1013. /* Read bytes from BFD. */
  1014. info->read_memory_func (pc, buf_data, size, info);
  1015. given = 0;
  1016. given1 = 0;
  1017. /* Start assembling data. */
  1018. /* Little endian of data. */
  1019. if (info->endian == BFD_ENDIAN_LITTLE)
  1020. {
  1021. for (i1 = size - 1;; i1--)
  1022. {
  1023. if (i1 >= 8)
  1024. given1 = buf_data[i1] | (given1 << 8);
  1025. else
  1026. given = buf_data[i1] | (given << 8);
  1027. if (i1 == 0)
  1028. break;
  1029. }
  1030. }
  1031. else
  1032. {
  1033. /* Big endian of data. */
  1034. for (i1 = 0; i1 < size; i1++)
  1035. {
  1036. if (i1 <= 7)
  1037. given = buf_data[i1] | (given << 8);
  1038. else
  1039. given1 = buf_data[i1] | (given1 << 8);
  1040. }
  1041. }
  1042. info->bytes_per_line = 4;
  1043. if (size == 16)
  1044. info->fprintf_func (info->stream, ".qword\t0x%016" PRIx64 "%016" PRIx64,
  1045. given, given1);
  1046. else if (size == 8)
  1047. info->fprintf_func (info->stream, ".dword\t0x%016" PRIx64, given);
  1048. else if (size == 4)
  1049. info->fprintf_func (info->stream, ".word\t0x%08" PRIx64, given);
  1050. else if (size == 2)
  1051. {
  1052. /* short */
  1053. if (mapping_type == MAP_DATA0)
  1054. info->fprintf_func (info->stream, ".byte\t0x%02" PRIx64,
  1055. given & 0xFF);
  1056. else
  1057. info->fprintf_func (info->stream, ".short\t0x%04" PRIx64, given);
  1058. }
  1059. else
  1060. {
  1061. /* byte */
  1062. info->fprintf_func (info->stream, ".byte\t0x%02" PRIx64, given);
  1063. }
  1064. return size;
  1065. }
  1066. size = 4;
  1067. status = info->read_memory_func (pc, buf, 4, info);
  1068. if (status)
  1069. {
  1070. /* For the last 16-bit instruction. */
  1071. size = 2;
  1072. status = info->read_memory_func (pc, buf, 2, info);
  1073. if (status)
  1074. {
  1075. (*info->memory_error_func) (status, pc, info);
  1076. return -1;
  1077. }
  1078. buf[2] = 0;
  1079. buf[3] = 0;
  1080. }
  1081. insn = bfd_getb32 (buf);
  1082. /* 16-bit instruction. */
  1083. if (insn & 0x80000000)
  1084. {
  1085. print_insn16 (pc, info, (insn >> 16), NDS32_PARSE_INSN16);
  1086. return 2;
  1087. }
  1088. /* 32-bit instructions. */
  1089. if (size == 4)
  1090. print_insn32 (pc, info, insn, NDS32_PARSE_INSN32);
  1091. else
  1092. info->fprintf_func (info->stream,
  1093. _("insufficient data to decode instruction"));
  1094. return 4;
  1095. }
  1096. /* Ignore disassembling unnecessary name. */
  1097. static bool
  1098. nds32_symbol_is_valid (asymbol *sym,
  1099. struct disassemble_info *info ATTRIBUTE_UNUSED)
  1100. {
  1101. const char *name;
  1102. if (sym == NULL)
  1103. return false;
  1104. name = bfd_asymbol_name (sym);
  1105. /* Mapping symbol is invalid. */
  1106. if (name[0] == '$')
  1107. return false;
  1108. return true;
  1109. }
  1110. static void
  1111. nds32_add_opcode_hash_table (unsigned indx)
  1112. {
  1113. opcode_t *opc;
  1114. opc = nds32_opcode_table[indx];
  1115. if (opc == NULL)
  1116. return;
  1117. while (opc->opcode != NULL)
  1118. {
  1119. opcode_t **slot;
  1120. slot = (opcode_t **) htab_find_slot
  1121. (opcode_htab, &opc->value, INSERT);
  1122. if (*slot == NULL)
  1123. {
  1124. /* This is the new one. */
  1125. *slot = opc;
  1126. }
  1127. else
  1128. {
  1129. opcode_t *tmp;
  1130. /* Already exists. Append to the list. */
  1131. tmp = *slot;
  1132. while (tmp->next)
  1133. tmp = tmp->next;
  1134. tmp->next = opc;
  1135. opc->next = NULL;
  1136. }
  1137. opc++;
  1138. }
  1139. }
  1140. void
  1141. disassemble_init_nds32 (struct disassemble_info *info)
  1142. {
  1143. static unsigned init_done = 0;
  1144. unsigned k;
  1145. /* Set up symbol checking function. */
  1146. info->symbol_is_valid = nds32_symbol_is_valid;
  1147. /* Only need to initialize once:
  1148. High level will call this function for every object file.
  1149. For example, when disassemble all members of a library. */
  1150. if (init_done)
  1151. return;
  1152. /* Setup main core. */
  1153. nds32_keyword_table[NDS32_MAIN_CORE] = &nds32_keywords[0];
  1154. nds32_opcode_table[NDS32_MAIN_CORE] = &nds32_opcodes[0];
  1155. nds32_field_table[NDS32_MAIN_CORE] = &nds32_operand_fields[0];
  1156. /* Build opcode table. */
  1157. opcode_htab = htab_create_alloc (1024, htab_hash_hash, htab_hash_eq,
  1158. NULL, xcalloc, free);
  1159. for (k = 0; k < NDS32_CORE_COUNT; k++)
  1160. {
  1161. /* Add op-codes. */
  1162. nds32_add_opcode_hash_table (k);
  1163. }
  1164. init_done = 1;
  1165. }
  1166. static int
  1167. is_mapping_symbol (struct disassemble_info *info, int n,
  1168. enum map_type *map_type)
  1169. {
  1170. const char *name = NULL;
  1171. /* Get symbol name. */
  1172. name = bfd_asymbol_name (info->symtab[n]);
  1173. if (name[1] == 'c')
  1174. {
  1175. *map_type = MAP_CODE;
  1176. return true;
  1177. }
  1178. else if (name[1] == 'd' && name[2] == '0')
  1179. {
  1180. *map_type = MAP_DATA0;
  1181. return true;
  1182. }
  1183. else if (name[1] == 'd' && name[2] == '1')
  1184. {
  1185. *map_type = MAP_DATA1;
  1186. return true;
  1187. }
  1188. else if (name[1] == 'd' && name[2] == '2')
  1189. {
  1190. *map_type = MAP_DATA2;
  1191. return true;
  1192. }
  1193. else if (name[1] == 'd' && name[2] == '3')
  1194. {
  1195. *map_type = MAP_DATA3;
  1196. return true;
  1197. }
  1198. else if (name[1] == 'd' && name[2] == '4')
  1199. {
  1200. *map_type = MAP_DATA4;
  1201. return true;
  1202. }
  1203. return false;
  1204. }
  1205. static int
  1206. get_mapping_symbol_type (struct disassemble_info *info, int n,
  1207. enum map_type *map_type)
  1208. {
  1209. /* If the symbol is in a different section, ignore it. */
  1210. if (info->section != NULL
  1211. && info->section != info->symtab[n]->section)
  1212. return false;
  1213. return is_mapping_symbol (info, n, map_type);
  1214. }