mep.opc 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. /* MeP opcode support. -*- C -*-
  2. Copyright 2011 Free Software Foundation, Inc.
  3. Contributed by Red Hat Inc;
  4. This file is part of the GNU Binutils.
  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,
  16. MA 02110-1301, USA. */
  17. /* -- opc.h */
  18. #undef CGEN_DIS_HASH_SIZE
  19. #define CGEN_DIS_HASH_SIZE 1
  20. #undef CGEN_DIS_HASH
  21. #define CGEN_DIS_HASH(buffer, insn) 0
  22. #define CGEN_VERBOSE_ASSEMBLER_ERRORS
  23. typedef struct
  24. {
  25. char * name;
  26. int config_enum;
  27. unsigned cpu_flag;
  28. int big_endian;
  29. int vliw_bits;
  30. CGEN_ATTR_VALUE_BITSET_TYPE cop16_isa;
  31. CGEN_ATTR_VALUE_BITSET_TYPE cop32_isa;
  32. CGEN_ATTR_VALUE_BITSET_TYPE cop48_isa;
  33. CGEN_ATTR_VALUE_BITSET_TYPE cop64_isa;
  34. CGEN_ATTR_VALUE_BITSET_TYPE cop_isa;
  35. CGEN_ATTR_VALUE_BITSET_TYPE core_isa;
  36. unsigned int option_mask;
  37. } mep_config_map_struct;
  38. extern mep_config_map_struct mep_config_map[];
  39. extern int mep_config_index;
  40. extern void init_mep_all_core_isas_mask (void);
  41. extern void init_mep_all_cop_isas_mask (void);
  42. extern CGEN_ATTR_VALUE_BITSET_TYPE mep_cop_isa (void);
  43. #define MEP_CONFIG (mep_config_map[mep_config_index].config_enum)
  44. #define MEP_CPU (mep_config_map[mep_config_index].cpu_flag)
  45. #define MEP_OMASK (mep_config_map[mep_config_index].option_mask)
  46. #define MEP_VLIW (mep_config_map[mep_config_index].vliw_bits > 0)
  47. #define MEP_VLIW32 (mep_config_map[mep_config_index].vliw_bits == 32)
  48. #define MEP_VLIW64 (mep_config_map[mep_config_index].vliw_bits == 64)
  49. #define MEP_COP16_ISA (mep_config_map[mep_config_index].cop16_isa)
  50. #define MEP_COP32_ISA (mep_config_map[mep_config_index].cop32_isa)
  51. #define MEP_COP48_ISA (mep_config_map[mep_config_index].cop48_isa)
  52. #define MEP_COP64_ISA (mep_config_map[mep_config_index].cop64_isa)
  53. #define MEP_COP_ISA (mep_config_map[mep_config_index].cop_isa)
  54. #define MEP_CORE_ISA (mep_config_map[mep_config_index].core_isa)
  55. /* begin-cop-ip-supported-defines */
  56. #define MEP_IVC2_SUPPORTED 1
  57. /* end-cop-ip-supported-defines */
  58. extern int mep_insn_supported_by_isa (const CGEN_INSN *, CGEN_ATTR_VALUE_BITSET_TYPE *);
  59. /* A mask for all ISAs executed by the core. */
  60. #define MEP_ALL_CORE_ISAS_MASK mep_all_core_isas_mask
  61. extern CGEN_ATTR_VALUE_BITSET_TYPE mep_all_core_isas_mask;
  62. #define MEP_INSN_CORE_P(insn) ( \
  63. init_mep_all_core_isas_mask (), \
  64. mep_insn_supported_by_isa (insn, & MEP_ALL_CORE_ISAS_MASK) \
  65. )
  66. /* A mask for all ISAs executed by a VLIW coprocessor. */
  67. #define MEP_ALL_COP_ISAS_MASK mep_all_cop_isas_mask
  68. extern CGEN_ATTR_VALUE_BITSET_TYPE mep_all_cop_isas_mask;
  69. #define MEP_INSN_COP_P(insn) ( \
  70. init_mep_all_cop_isas_mask (), \
  71. mep_insn_supported_by_isa (insn, & MEP_ALL_COP_ISAS_MASK) \
  72. )
  73. extern int mep_cgen_insn_supported (CGEN_CPU_DESC, const CGEN_INSN *);
  74. extern int mep_cgen_insn_supported_asm (CGEN_CPU_DESC, const CGEN_INSN *);
  75. /* -- asm.c */
  76. #include "elf/mep.h"
  77. #define CGEN_VALIDATE_INSN_SUPPORTED
  78. #define mep_cgen_insn_supported mep_cgen_insn_supported_asm
  79. const char * parse_csrn (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
  80. const char * parse_tpreg (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
  81. const char * parse_spreg (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
  82. const char * parse_mep_align (CGEN_CPU_DESC, const char **, enum cgen_operand_type, long *);
  83. const char * parse_mep_alignu (CGEN_CPU_DESC, const char **, enum cgen_operand_type, unsigned long *);
  84. static const char * parse_signed16 (CGEN_CPU_DESC, const char **, int, long *);
  85. static const char * parse_signed16_range (CGEN_CPU_DESC, const char **, int, long *) ATTRIBUTE_UNUSED;
  86. static const char * parse_unsigned16 (CGEN_CPU_DESC, const char **, int, unsigned long *);
  87. static const char * parse_unsigned16_range (CGEN_CPU_DESC, const char **, int, unsigned long *) ATTRIBUTE_UNUSED;
  88. static const char * parse_lo16 (CGEN_CPU_DESC, const char **, int, long *, long);
  89. static const char * parse_unsigned7 (CGEN_CPU_DESC, const char **, enum cgen_operand_type, unsigned long *);
  90. static const char * parse_zero (CGEN_CPU_DESC, const char **, int, long *);
  91. const char *
  92. parse_csrn (CGEN_CPU_DESC cd, const char **strp,
  93. CGEN_KEYWORD *keyword_table, long *field)
  94. {
  95. const char *err;
  96. unsigned long value;
  97. err = cgen_parse_keyword (cd, strp, keyword_table, field);
  98. if (!err)
  99. return NULL;
  100. err = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CSRN_IDX, & value);
  101. if (err)
  102. return err;
  103. *field = value;
  104. return NULL;
  105. }
  106. /* begin-cop-ip-parse-handlers */
  107. static const char *
  108. parse_ivc2_cr (CGEN_CPU_DESC,
  109. const char **,
  110. CGEN_KEYWORD *,
  111. long *) ATTRIBUTE_UNUSED;
  112. static const char *
  113. parse_ivc2_cr (CGEN_CPU_DESC cd,
  114. const char **strp,
  115. CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
  116. long *field)
  117. {
  118. return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr_ivc2, field);
  119. }
  120. static const char *
  121. parse_ivc2_ccr (CGEN_CPU_DESC,
  122. const char **,
  123. CGEN_KEYWORD *,
  124. long *) ATTRIBUTE_UNUSED;
  125. static const char *
  126. parse_ivc2_ccr (CGEN_CPU_DESC cd,
  127. const char **strp,
  128. CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
  129. long *field)
  130. {
  131. return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, field);
  132. }
  133. /* end-cop-ip-parse-handlers */
  134. const char *
  135. parse_tpreg (CGEN_CPU_DESC cd, const char ** strp,
  136. CGEN_KEYWORD *keyword_table, long *field)
  137. {
  138. const char *err;
  139. err = cgen_parse_keyword (cd, strp, keyword_table, field);
  140. if (err)
  141. return err;
  142. if (*field != 13)
  143. return _("Only $tp or $13 allowed for this opcode");
  144. return NULL;
  145. }
  146. const char *
  147. parse_spreg (CGEN_CPU_DESC cd, const char ** strp,
  148. CGEN_KEYWORD *keyword_table, long *field)
  149. {
  150. const char *err;
  151. err = cgen_parse_keyword (cd, strp, keyword_table, field);
  152. if (err)
  153. return err;
  154. if (*field != 15)
  155. return _("Only $sp or $15 allowed for this opcode");
  156. return NULL;
  157. }
  158. const char *
  159. parse_mep_align (CGEN_CPU_DESC cd, const char ** strp,
  160. enum cgen_operand_type type, long *field)
  161. {
  162. long lsbs = 0;
  163. const char *err;
  164. switch (type)
  165. {
  166. case MEP_OPERAND_PCREL8A2:
  167. case MEP_OPERAND_PCREL12A2:
  168. case MEP_OPERAND_PCREL17A2:
  169. case MEP_OPERAND_PCREL24A2:
  170. err = cgen_parse_signed_integer (cd, strp, type, field);
  171. break;
  172. case MEP_OPERAND_PCABS24A2:
  173. case MEP_OPERAND_UDISP7:
  174. case MEP_OPERAND_UDISP7A2:
  175. case MEP_OPERAND_UDISP7A4:
  176. case MEP_OPERAND_UIMM7A4:
  177. case MEP_OPERAND_ADDR24A4:
  178. err = cgen_parse_unsigned_integer (cd, strp, type, (unsigned long *) field);
  179. break;
  180. default:
  181. abort();
  182. }
  183. if (err)
  184. return err;
  185. switch (type)
  186. {
  187. case MEP_OPERAND_UDISP7:
  188. lsbs = 0;
  189. break;
  190. case MEP_OPERAND_PCREL8A2:
  191. case MEP_OPERAND_PCREL12A2:
  192. case MEP_OPERAND_PCREL17A2:
  193. case MEP_OPERAND_PCREL24A2:
  194. case MEP_OPERAND_PCABS24A2:
  195. case MEP_OPERAND_UDISP7A2:
  196. lsbs = *field & 1;
  197. break;
  198. case MEP_OPERAND_UDISP7A4:
  199. case MEP_OPERAND_UIMM7A4:
  200. case MEP_OPERAND_ADDR24A4:
  201. lsbs = *field & 3;
  202. break;
  203. lsbs = *field & 7;
  204. break;
  205. default:
  206. /* Safe assumption? */
  207. abort ();
  208. }
  209. if (lsbs)
  210. return "Value is not aligned enough";
  211. return NULL;
  212. }
  213. const char *
  214. parse_mep_alignu (CGEN_CPU_DESC cd, const char ** strp,
  215. enum cgen_operand_type type, unsigned long *field)
  216. {
  217. return parse_mep_align (cd, strp, type, (long *) field);
  218. }
  219. /* Handle %lo(), %tpoff(), %sdaoff(), %hi(), and other signed
  220. constants in a signed context. */
  221. static const char *
  222. parse_signed16 (CGEN_CPU_DESC cd,
  223. const char **strp,
  224. int opindex,
  225. long *valuep)
  226. {
  227. return parse_lo16 (cd, strp, opindex, valuep, 1);
  228. }
  229. static const char *
  230. parse_lo16 (CGEN_CPU_DESC cd,
  231. const char **strp,
  232. int opindex,
  233. long *valuep,
  234. long signedp)
  235. {
  236. const char *errmsg;
  237. enum cgen_parse_operand_result result_type;
  238. bfd_vma value;
  239. if (strncasecmp (*strp, "%lo(", 4) == 0)
  240. {
  241. *strp += 4;
  242. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
  243. & result_type, & value);
  244. if (**strp != ')')
  245. return _("missing `)'");
  246. ++*strp;
  247. if (errmsg == NULL
  248. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  249. value &= 0xffff;
  250. if (signedp)
  251. *valuep = (long)(short) value;
  252. else
  253. *valuep = value;
  254. return errmsg;
  255. }
  256. if (strncasecmp (*strp, "%hi(", 4) == 0)
  257. {
  258. *strp += 4;
  259. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
  260. & result_type, & value);
  261. if (**strp != ')')
  262. return _("missing `)'");
  263. ++*strp;
  264. if (errmsg == NULL
  265. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  266. value = (value + 0x8000) >> 16;
  267. *valuep = value;
  268. return errmsg;
  269. }
  270. if (strncasecmp (*strp, "%uhi(", 5) == 0)
  271. {
  272. *strp += 5;
  273. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
  274. & result_type, & value);
  275. if (**strp != ')')
  276. return _("missing `)'");
  277. ++*strp;
  278. if (errmsg == NULL
  279. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  280. value = value >> 16;
  281. *valuep = value;
  282. return errmsg;
  283. }
  284. if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
  285. {
  286. *strp += 8;
  287. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
  288. NULL, & value);
  289. if (**strp != ')')
  290. return _("missing `)'");
  291. ++*strp;
  292. *valuep = value;
  293. return errmsg;
  294. }
  295. if (strncasecmp (*strp, "%tpoff(", 7) == 0)
  296. {
  297. *strp += 7;
  298. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
  299. NULL, & value);
  300. if (**strp != ')')
  301. return _("missing `)'");
  302. ++*strp;
  303. *valuep = value;
  304. return errmsg;
  305. }
  306. if (**strp == '%')
  307. return _("invalid %function() here");
  308. return cgen_parse_signed_integer (cd, strp, opindex, valuep);
  309. }
  310. static const char *
  311. parse_unsigned16 (CGEN_CPU_DESC cd,
  312. const char **strp,
  313. int opindex,
  314. unsigned long *valuep)
  315. {
  316. return parse_lo16 (cd, strp, opindex, (long *) valuep, 0);
  317. }
  318. static const char *
  319. parse_signed16_range (CGEN_CPU_DESC cd,
  320. const char **strp,
  321. int opindex,
  322. signed long *valuep)
  323. {
  324. const char *errmsg = 0;
  325. signed long value;
  326. errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
  327. if (errmsg)
  328. return errmsg;
  329. if (value < -32768 || value > 32767)
  330. return _("Immediate is out of range -32768 to 32767");
  331. *valuep = value;
  332. return 0;
  333. }
  334. static const char *
  335. parse_unsigned16_range (CGEN_CPU_DESC cd,
  336. const char **strp,
  337. int opindex,
  338. unsigned long *valuep)
  339. {
  340. const char *errmsg = 0;
  341. unsigned long value;
  342. errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
  343. if (errmsg)
  344. return errmsg;
  345. if (value > 65535)
  346. return _("Immediate is out of range 0 to 65535");
  347. *valuep = value;
  348. return 0;
  349. }
  350. /* A special case of parse_signed16 which accepts only the value zero. */
  351. static const char *
  352. parse_zero (CGEN_CPU_DESC cd, const char **strp, int opindex, long *valuep)
  353. {
  354. const char *errmsg;
  355. enum cgen_parse_operand_result result_type;
  356. bfd_vma value;
  357. /*fprintf(stderr, "dj: signed parse opindex `%s'\n", *strp);*/
  358. /* Prevent ($ry) from being attempted as an expression on 'sw $rx,($ry)'.
  359. It will fail and cause ry to be listed as an undefined symbol in the
  360. listing. */
  361. if (strncmp (*strp, "($", 2) == 0)
  362. return "not zero"; /* any string will do -- will never be seen. */
  363. if (strncasecmp (*strp, "%lo(", 4) == 0)
  364. {
  365. *strp += 4;
  366. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
  367. &result_type, &value);
  368. if (**strp != ')')
  369. return "missing `)'";
  370. ++*strp;
  371. if (errmsg == NULL
  372. && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
  373. return "not zero"; /* any string will do -- will never be seen. */
  374. *valuep = value;
  375. return errmsg;
  376. }
  377. if (strncasecmp (*strp, "%hi(", 4) == 0)
  378. {
  379. *strp += 4;
  380. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
  381. &result_type, &value);
  382. if (**strp != ')')
  383. return "missing `)'";
  384. ++*strp;
  385. if (errmsg == NULL
  386. && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
  387. return "not zero"; /* any string will do -- will never be seen. */
  388. *valuep = value;
  389. return errmsg;
  390. }
  391. if (strncasecmp (*strp, "%uhi(", 5) == 0)
  392. {
  393. *strp += 5;
  394. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
  395. &result_type, &value);
  396. if (**strp != ')')
  397. return "missing `)'";
  398. ++*strp;
  399. if (errmsg == NULL
  400. && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
  401. return "not zero"; /* any string will do -- will never be seen. */
  402. *valuep = value;
  403. return errmsg;
  404. }
  405. if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
  406. {
  407. *strp += 8;
  408. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
  409. &result_type, &value);
  410. if (**strp != ')')
  411. return "missing `)'";
  412. ++*strp;
  413. if (errmsg == NULL
  414. && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
  415. return "not zero"; /* any string will do -- will never be seen. */
  416. *valuep = value;
  417. return errmsg;
  418. }
  419. if (strncasecmp (*strp, "%tpoff(", 7) == 0)
  420. {
  421. *strp += 7;
  422. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
  423. &result_type, &value);
  424. if (**strp != ')')
  425. return "missing `)'";
  426. ++*strp;
  427. if (errmsg == NULL
  428. && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
  429. return "not zero"; /* any string will do -- will never be seen. */
  430. *valuep = value;
  431. return errmsg;
  432. }
  433. if (**strp == '%')
  434. return "invalid %function() here";
  435. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_NONE,
  436. &result_type, &value);
  437. if (errmsg == NULL
  438. && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
  439. return "not zero"; /* any string will do -- will never be seen. */
  440. return errmsg;
  441. }
  442. static const char *
  443. parse_unsigned7 (CGEN_CPU_DESC cd, const char **strp,
  444. enum cgen_operand_type opindex, unsigned long *valuep)
  445. {
  446. const char *errmsg;
  447. bfd_vma value;
  448. /* fprintf(stderr, "dj: unsigned7 parse `%s'\n", *strp); */
  449. if (strncasecmp (*strp, "%tpoff(", 7) == 0)
  450. {
  451. int reloc;
  452. *strp += 7;
  453. switch (opindex)
  454. {
  455. case MEP_OPERAND_UDISP7:
  456. reloc = BFD_RELOC_MEP_TPREL7;
  457. break;
  458. case MEP_OPERAND_UDISP7A2:
  459. reloc = BFD_RELOC_MEP_TPREL7A2;
  460. break;
  461. case MEP_OPERAND_UDISP7A4:
  462. reloc = BFD_RELOC_MEP_TPREL7A4;
  463. break;
  464. default:
  465. /* Safe assumption? */
  466. abort ();
  467. }
  468. errmsg = cgen_parse_address (cd, strp, opindex, reloc,
  469. NULL, &value);
  470. if (**strp != ')')
  471. return "missing `)'";
  472. ++*strp;
  473. *valuep = value;
  474. return errmsg;
  475. }
  476. if (**strp == '%')
  477. return _("invalid %function() here");
  478. return parse_mep_alignu (cd, strp, opindex, valuep);
  479. }
  480. static ATTRIBUTE_UNUSED const char *
  481. parse_cdisp10 (CGEN_CPU_DESC cd,
  482. const char **strp,
  483. int opindex,
  484. long *valuep)
  485. {
  486. const char *errmsg = 0;
  487. signed long value;
  488. long have_zero = 0;
  489. int wide = 0;
  490. int alignment;
  491. switch (opindex)
  492. {
  493. case MEP_OPERAND_CDISP10A4:
  494. alignment = 2;
  495. break;
  496. case MEP_OPERAND_CDISP10A2:
  497. alignment = 1;
  498. break;
  499. case MEP_OPERAND_CDISP10:
  500. default:
  501. alignment = 0;
  502. break;
  503. }
  504. if ((MEP_CPU & EF_MEP_CPU_MASK) == EF_MEP_CPU_C5)
  505. wide = 1;
  506. if (strncmp (*strp, "0x0", 3) == 0
  507. || (**strp == '0' && *(*strp + 1) != 'x'))
  508. have_zero = 1;
  509. errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
  510. if (errmsg)
  511. return errmsg;
  512. if (wide)
  513. {
  514. if (value < -512 || value > 511)
  515. return _("Immediate is out of range -512 to 511");
  516. }
  517. else
  518. {
  519. if (value < -128 || value > 127)
  520. return _("Immediate is out of range -128 to 127");
  521. }
  522. if (value & ((1<<alignment)-1))
  523. return _("Value is not aligned enough");
  524. /* If this field may require a relocation then use larger dsp16. */
  525. if (! have_zero && value == 0)
  526. return (wide ? _("Immediate is out of range -512 to 511")
  527. : _("Immediate is out of range -128 to 127"));
  528. *valuep = value;
  529. return 0;
  530. }
  531. /* BEGIN LIGHTWEIGHT MACRO PROCESSOR. */
  532. #define MAXARGS 9
  533. typedef struct
  534. {
  535. char *name;
  536. char *expansion;
  537. } macro;
  538. typedef struct
  539. {
  540. const char *start;
  541. int len;
  542. } arg;
  543. macro macros[] =
  544. {
  545. { "sizeof", "(`1.end + (- `1))"},
  546. { "startof", "(`1 | 0)" },
  547. { "align4", "(`1&(~3))"},
  548. /*{ "hi", "(((`1+0x8000)>>16) & 0xffff)" }, */
  549. /*{ "lo", "(`1 & 0xffff)" }, */
  550. /*{ "sdaoff", "((`1-__sdabase) & 0x7f)"}, */
  551. /*{ "tpoff", "((`1-__tpbase) & 0x7f)"}, */
  552. { 0,0 }
  553. };
  554. static char * expand_string (const char *, int);
  555. static const char *
  556. mep_cgen_expand_macros_and_parse_operand
  557. (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
  558. static char *
  559. str_append (char *dest, const char *input, int len)
  560. {
  561. char *new_dest;
  562. int oldlen;
  563. if (len == 0)
  564. return dest;
  565. /* printf("str_append: <<%s>>, <<%s>>, %d\n", dest, input, len); */
  566. oldlen = (dest ? strlen(dest) : 0);
  567. new_dest = realloc (dest, oldlen + len + 1);
  568. memset (new_dest + oldlen, 0, len + 1);
  569. return strncat (new_dest, input, len);
  570. }
  571. static macro *
  572. lookup_macro (const char *name)
  573. {
  574. macro *m;
  575. for (m = macros; m->name; ++m)
  576. if (strncmp (m->name, name, strlen(m->name)) == 0)
  577. return m;
  578. return 0;
  579. }
  580. static char *
  581. expand_macro (arg *args, int narg, macro *mac)
  582. {
  583. char *result = 0, *rescanned_result = 0;
  584. char *e = mac->expansion;
  585. char *mark = e;
  586. int mac_arg = 0;
  587. /* printf("expanding macro %s with %d args\n", mac->name, narg + 1); */
  588. while (*e)
  589. {
  590. if (*e == '`' &&
  591. (*e+1) &&
  592. ((*(e + 1) - '1') <= MAXARGS) &&
  593. ((*(e + 1) - '1') <= narg))
  594. {
  595. result = str_append (result, mark, e - mark);
  596. mac_arg = (*(e + 1) - '1');
  597. /* printf("replacing `%d with %s\n", mac_arg+1, args[mac_arg].start); */
  598. result = str_append (result, args[mac_arg].start, args[mac_arg].len);
  599. ++e;
  600. mark = e+1;
  601. }
  602. ++e;
  603. }
  604. if (mark != e)
  605. result = str_append (result, mark, e - mark);
  606. if (result)
  607. {
  608. rescanned_result = expand_string (result, 0);
  609. free (result);
  610. return rescanned_result;
  611. }
  612. else
  613. return result;
  614. }
  615. #define IN_TEXT 0
  616. #define IN_ARGS 1
  617. static char *
  618. expand_string (const char *in, int first_only)
  619. {
  620. int num_expansions = 0;
  621. int depth = 0;
  622. int narg = -1;
  623. arg args[MAXARGS];
  624. int state = IN_TEXT;
  625. const char *mark = in;
  626. macro *pmacro = NULL;
  627. char *expansion = 0;
  628. char *result = 0;
  629. while (*in)
  630. {
  631. switch (state)
  632. {
  633. case IN_TEXT:
  634. if (*in == '%' && *(in + 1) && (!first_only || num_expansions == 0))
  635. {
  636. pmacro = lookup_macro (in + 1);
  637. if (pmacro)
  638. {
  639. /* printf("entering state %d at '%s'...\n", state, in); */
  640. result = str_append (result, mark, in - mark);
  641. mark = in;
  642. in += 1 + strlen (pmacro->name);
  643. while (*in == ' ') ++in;
  644. if (*in != '(')
  645. {
  646. state = IN_TEXT;
  647. pmacro = NULL;
  648. }
  649. else
  650. {
  651. state = IN_ARGS;
  652. narg = 0;
  653. args[narg].start = in + 1;
  654. args[narg].len = 0;
  655. mark = in + 1;
  656. }
  657. }
  658. }
  659. break;
  660. case IN_ARGS:
  661. if (depth == 0)
  662. {
  663. switch (*in)
  664. {
  665. case ',':
  666. narg++;
  667. args[narg].start = (in + 1);
  668. args[narg].len = 0;
  669. break;
  670. case ')':
  671. state = IN_TEXT;
  672. /* printf("entering state %d at '%s'...\n", state, in); */
  673. if (pmacro)
  674. {
  675. expansion = 0;
  676. expansion = expand_macro (args, narg, pmacro);
  677. num_expansions++;
  678. if (expansion)
  679. {
  680. result = str_append (result, expansion, strlen (expansion));
  681. free (expansion);
  682. }
  683. }
  684. else
  685. {
  686. result = str_append (result, mark, in - mark);
  687. }
  688. pmacro = NULL;
  689. mark = in + 1;
  690. break;
  691. case '(':
  692. depth++;
  693. default:
  694. args[narg].len++;
  695. break;
  696. }
  697. }
  698. else
  699. {
  700. if (*in == ')')
  701. depth--;
  702. if (narg > -1)
  703. args[narg].len++;
  704. }
  705. }
  706. ++in;
  707. }
  708. if (mark != in)
  709. result = str_append (result, mark, in - mark);
  710. return result;
  711. }
  712. #undef IN_ARGS
  713. #undef IN_TEXT
  714. #undef MAXARGS
  715. /* END LIGHTWEIGHT MACRO PROCESSOR. */
  716. const char * mep_cgen_parse_operand
  717. (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
  718. const char *
  719. mep_cgen_expand_macros_and_parse_operand (CGEN_CPU_DESC cd, int opindex,
  720. const char ** strp_in, CGEN_FIELDS * fields)
  721. {
  722. const char * errmsg = NULL;
  723. char *str = 0, *hold = 0;
  724. const char **strp = 0;
  725. /* Set up a new pointer to macro-expanded string. */
  726. str = expand_string (*strp_in, 1);
  727. /* fprintf (stderr, " expanded <<%s>> to <<%s>>\n", *strp_in, str); */
  728. hold = str;
  729. strp = (const char **)(&str);
  730. errmsg = mep_cgen_parse_operand (cd, opindex, strp, fields);
  731. /* Now work out the advance. */
  732. if (strlen (str) == 0)
  733. *strp_in += strlen (*strp_in);
  734. else
  735. {
  736. if (strstr (*strp_in, str))
  737. /* A macro-expansion was pulled off the front. */
  738. *strp_in = strstr (*strp_in, str);
  739. else
  740. /* A non-macro-expansion was pulled off the front. */
  741. *strp_in += (str - hold);
  742. }
  743. if (hold)
  744. free (hold);
  745. return errmsg;
  746. }
  747. #define CGEN_ASM_INIT_HOOK (cd->parse_operand = mep_cgen_expand_macros_and_parse_operand);
  748. /* -- dis.c */
  749. #include "elf/mep.h"
  750. #include "elf-bfd.h"
  751. #define CGEN_VALIDATE_INSN_SUPPORTED
  752. static void print_tpreg (CGEN_CPU_DESC, PTR, CGEN_KEYWORD *, long, unsigned int);
  753. static void print_spreg (CGEN_CPU_DESC, PTR, CGEN_KEYWORD *, long, unsigned int);
  754. static void
  755. print_tpreg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, PTR dis_info,
  756. CGEN_KEYWORD *table ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED,
  757. unsigned int flags ATTRIBUTE_UNUSED)
  758. {
  759. disassemble_info *info = (disassemble_info *) dis_info;
  760. (*info->fprintf_func) (info->stream, "$tp");
  761. }
  762. static void
  763. print_spreg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, PTR dis_info,
  764. CGEN_KEYWORD *table ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED,
  765. unsigned int flags ATTRIBUTE_UNUSED)
  766. {
  767. disassemble_info *info = (disassemble_info *) dis_info;
  768. (*info->fprintf_func) (info->stream, "$sp");
  769. }
  770. /* begin-cop-ip-print-handlers */
  771. static void
  772. print_ivc2_cr (CGEN_CPU_DESC,
  773. void *,
  774. CGEN_KEYWORD *,
  775. long,
  776. unsigned int) ATTRIBUTE_UNUSED;
  777. static void
  778. print_ivc2_cr (CGEN_CPU_DESC cd,
  779. void *dis_info,
  780. CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
  781. long value,
  782. unsigned int attrs)
  783. {
  784. print_keyword (cd, dis_info, & mep_cgen_opval_h_cr_ivc2, value, attrs);
  785. }
  786. static void
  787. print_ivc2_ccr (CGEN_CPU_DESC,
  788. void *,
  789. CGEN_KEYWORD *,
  790. long,
  791. unsigned int) ATTRIBUTE_UNUSED;
  792. static void
  793. print_ivc2_ccr (CGEN_CPU_DESC cd,
  794. void *dis_info,
  795. CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
  796. long value,
  797. unsigned int attrs)
  798. {
  799. print_keyword (cd, dis_info, & mep_cgen_opval_h_ccr_ivc2, value, attrs);
  800. }
  801. /* end-cop-ip-print-handlers */
  802. /************************************************************\
  803. *********************** Experimental *************************
  804. \************************************************************/
  805. #undef CGEN_PRINT_INSN
  806. #define CGEN_PRINT_INSN mep_print_insn
  807. static int
  808. mep_print_vliw_insns (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info,
  809. bfd_byte *buf, int corelength, int copro1length,
  810. int copro2length ATTRIBUTE_UNUSED)
  811. {
  812. int i;
  813. int status = 0;
  814. /* char insnbuf[CGEN_MAX_INSN_SIZE]; */
  815. bfd_byte insnbuf[64];
  816. /* If corelength > 0 then there is a core insn present. It
  817. will be at the beginning of the buffer. After printing
  818. the core insn, we need to print the + on the next line. */
  819. if (corelength > 0)
  820. {
  821. int my_status = 0;
  822. for (i = 0; i < corelength; i++ )
  823. insnbuf[i] = buf[i];
  824. cd->isas = & MEP_CORE_ISA;
  825. my_status = print_insn (cd, pc, info, insnbuf, corelength);
  826. if (my_status != corelength)
  827. {
  828. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  829. my_status = corelength;
  830. }
  831. status += my_status;
  832. /* Print the + to indicate that the following copro insn is */
  833. /* part of a vliw group. */
  834. if (copro1length > 0)
  835. (*info->fprintf_func) (info->stream, " + ");
  836. }
  837. /* Now all that is left to be processed is the coprocessor insns
  838. In vliw mode, there will always be one. Its positioning will
  839. be from byte corelength to byte corelength+copro1length -1.
  840. No need to check for existence. Also, the first vliw insn,
  841. will, as spec'd, always be at least as long as the core insn
  842. so we don't need to flush the buffer. */
  843. if (copro1length > 0)
  844. {
  845. int my_status = 0;
  846. for (i = corelength; i < corelength + copro1length; i++ )
  847. insnbuf[i - corelength] = buf[i];
  848. switch (copro1length)
  849. {
  850. case 0:
  851. break;
  852. case 2:
  853. cd->isas = & MEP_COP16_ISA;
  854. break;
  855. case 4:
  856. cd->isas = & MEP_COP32_ISA;
  857. break;
  858. case 6:
  859. cd->isas = & MEP_COP48_ISA;
  860. break;
  861. case 8:
  862. cd->isas = & MEP_COP64_ISA;
  863. break;
  864. default:
  865. /* Shouldn't be anything but 16,32,48,64. */
  866. break;
  867. }
  868. my_status = print_insn (cd, pc, info, insnbuf, copro1length);
  869. if (my_status != copro1length)
  870. {
  871. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  872. my_status = copro1length;
  873. }
  874. status += my_status;
  875. }
  876. #if 0
  877. /* Now we need to process the second copro insn if it exists. We
  878. have no guarantee that the second copro insn will be longer
  879. than the first, so we have to flush the buffer if we are have
  880. a second copro insn to process. If present, this insn will
  881. be in the position from byte corelength+copro1length to byte
  882. corelength+copro1length+copro2length-1 (which better equal 8
  883. or else we're in big trouble. */
  884. if (copro2length > 0)
  885. {
  886. int my_status = 0;
  887. for (i = 0; i < 64 ; i++)
  888. insnbuf[i] = 0;
  889. for (i = corelength + copro1length; i < 64; i++)
  890. insnbuf[i - (corelength + copro1length)] = buf[i];
  891. switch (copro2length)
  892. {
  893. case 2:
  894. cd->isas = 1 << ISA_EXT_COP1_16;
  895. break;
  896. case 4:
  897. cd->isas = 1 << ISA_EXT_COP1_32;
  898. break;
  899. case 6:
  900. cd->isas = 1 << ISA_EXT_COP1_48;
  901. break;
  902. case 8:
  903. cd->isas = 1 << ISA_EXT_COP1_64;
  904. break;
  905. default:
  906. /* Shouldn't be anything but 16,32,48,64. */
  907. break;
  908. }
  909. my_status = print_insn (cd, pc, info, insnbuf, copro2length);
  910. if (my_status != copro2length)
  911. {
  912. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  913. my_status = copro2length;
  914. }
  915. status += my_status;
  916. }
  917. #endif
  918. /* Status should now be the number of bytes that were printed
  919. which should be 4 for VLIW32 mode and 64 for VLIW64 mode. */
  920. if ((!MEP_VLIW64 && (status != 4)) || (MEP_VLIW64 && (status != 8)))
  921. return -1;
  922. else
  923. return status;
  924. }
  925. /* The two functions mep_examine_vliw[32,64]_insns are used find out
  926. which vliw combinaion (16 bit core with 48 bit copro, 32 bit core
  927. with 32 bit copro, etc.) is present. Later on, when internally
  928. parallel coprocessors are handled, only these functions should
  929. need to be changed.
  930. At this time only the following combinations are supported:
  931. VLIW32 Mode:
  932. 16 bit core insn (core) and 16 bit coprocessor insn (cop1)
  933. 32 bit core insn (core)
  934. 32 bit coprocessor insn (cop1)
  935. Note: As of this time, I do not believe we have enough information
  936. to distinguish a 32 bit core insn from a 32 bit cop insn. Also,
  937. no 16 bit coprocessor insns have been specified.
  938. VLIW64 Mode:
  939. 16 bit core insn (core) and 48 bit coprocessor insn (cop1)
  940. 32 bit core insn (core) and 32 bit coprocessor insn (cop1)
  941. 64 bit coprocessor insn (cop1)
  942. The framework for an internally parallel coprocessor is also
  943. present (2nd coprocessor insn is cop2), but at this time it
  944. is not used. This only appears to be valid in VLIW64 mode. */
  945. static int
  946. mep_examine_vliw32_insns (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  947. {
  948. int status;
  949. int buflength;
  950. int corebuflength;
  951. int cop1buflength;
  952. int cop2buflength;
  953. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  954. char indicator16[1];
  955. char indicatorcop32[2];
  956. /* At this time we're not supporting internally parallel coprocessors,
  957. so cop2buflength will always be 0. */
  958. cop2buflength = 0;
  959. /* Read in 32 bits. */
  960. buflength = 4; /* VLIW insn spans 4 bytes. */
  961. status = (*info->read_memory_func) (pc, buf, buflength, info);
  962. if (status != 0)
  963. {
  964. (*info->memory_error_func) (status, pc, info);
  965. return -1;
  966. }
  967. /* Put the big endian representation of the bytes to be examined
  968. in the temporary buffers for examination. */
  969. if (info->endian == BFD_ENDIAN_BIG)
  970. {
  971. indicator16[0] = buf[0];
  972. indicatorcop32[0] = buf[0];
  973. indicatorcop32[1] = buf[1];
  974. }
  975. else
  976. {
  977. indicator16[0] = buf[1];
  978. indicatorcop32[0] = buf[1];
  979. indicatorcop32[1] = buf[0];
  980. }
  981. /* If the two high order bits are 00, 01 or 10, we have a 16 bit
  982. core insn and a 48 bit copro insn. */
  983. if ((indicator16[0] & 0x80) && (indicator16[0] & 0x40))
  984. {
  985. if ((indicatorcop32[0] & 0xf0) == 0xf0 && (indicatorcop32[1] & 0x07) == 0x07)
  986. {
  987. /* We have a 32 bit copro insn. */
  988. corebuflength = 0;
  989. /* All 4 4ytes are one copro insn. */
  990. cop1buflength = 4;
  991. }
  992. else
  993. {
  994. /* We have a 32 bit core. */
  995. corebuflength = 4;
  996. cop1buflength = 0;
  997. }
  998. }
  999. else
  1000. {
  1001. /* We have a 16 bit core insn and a 16 bit copro insn. */
  1002. corebuflength = 2;
  1003. cop1buflength = 2;
  1004. }
  1005. /* Now we have the distrubution set. Print them out. */
  1006. status = mep_print_vliw_insns (cd, pc, info, buf, corebuflength,
  1007. cop1buflength, cop2buflength);
  1008. return status;
  1009. }
  1010. static int
  1011. mep_examine_vliw64_insns (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  1012. {
  1013. int status;
  1014. int buflength;
  1015. int corebuflength;
  1016. int cop1buflength;
  1017. int cop2buflength;
  1018. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  1019. char indicator16[1];
  1020. char indicator64[4];
  1021. /* At this time we're not supporting internally parallel
  1022. coprocessors, so cop2buflength will always be 0. */
  1023. cop2buflength = 0;
  1024. /* Read in 64 bits. */
  1025. buflength = 8; /* VLIW insn spans 8 bytes. */
  1026. status = (*info->read_memory_func) (pc, buf, buflength, info);
  1027. if (status != 0)
  1028. {
  1029. (*info->memory_error_func) (status, pc, info);
  1030. return -1;
  1031. }
  1032. /* We have all 64 bits in the buffer now. We have to figure out
  1033. what combination of instruction sizes are present. The two
  1034. high order bits will indicate whether or not we have a 16 bit
  1035. core insn or not. If not, then we have to look at the 7,8th
  1036. bytes to tell whether we have 64 bit copro insn or a 32 bit
  1037. core insn with a 32 bit copro insn. Endianness will make a
  1038. difference here. */
  1039. /* Put the big endian representation of the bytes to be examined
  1040. in the temporary buffers for examination. */
  1041. /* indicator16[0] = buf[0]; */
  1042. if (info->endian == BFD_ENDIAN_BIG)
  1043. {
  1044. indicator16[0] = buf[0];
  1045. indicator64[0] = buf[0];
  1046. indicator64[1] = buf[1];
  1047. indicator64[2] = buf[2];
  1048. indicator64[3] = buf[3];
  1049. }
  1050. else
  1051. {
  1052. indicator16[0] = buf[1];
  1053. indicator64[0] = buf[1];
  1054. indicator64[1] = buf[0];
  1055. indicator64[2] = buf[3];
  1056. indicator64[3] = buf[2];
  1057. }
  1058. /* If the two high order bits are 00, 01 or 10, we have a 16 bit
  1059. core insn and a 48 bit copro insn. */
  1060. if ((indicator16[0] & 0x80) && (indicator16[0] & 0x40))
  1061. {
  1062. if ((indicator64[0] & 0xf0) == 0xf0 && (indicator64[1] & 0x07) == 0x07
  1063. && ((indicator64[2] & 0xfe) != 0xf0 || (indicator64[3] & 0xf4) != 0))
  1064. {
  1065. /* We have a 64 bit copro insn. */
  1066. corebuflength = 0;
  1067. /* All 8 bytes are one copro insn. */
  1068. cop1buflength = 8;
  1069. }
  1070. else
  1071. {
  1072. /* We have a 32 bit core insn and a 32 bit copro insn. */
  1073. corebuflength = 4;
  1074. cop1buflength = 4;
  1075. }
  1076. }
  1077. else
  1078. {
  1079. /* We have a 16 bit core insn and a 48 bit copro insn. */
  1080. corebuflength = 2;
  1081. cop1buflength = 6;
  1082. }
  1083. /* Now we have the distrubution set. Print them out. */
  1084. status = mep_print_vliw_insns (cd, pc, info, buf, corebuflength,
  1085. cop1buflength, cop2buflength);
  1086. return status;
  1087. }
  1088. #ifdef MEP_IVC2_SUPPORTED
  1089. static int
  1090. print_slot_insn (CGEN_CPU_DESC cd,
  1091. bfd_vma pc,
  1092. disassemble_info *info,
  1093. SLOTS_ATTR slot,
  1094. bfd_byte *buf)
  1095. {
  1096. const CGEN_INSN_LIST *insn_list;
  1097. CGEN_INSN_INT insn_value;
  1098. CGEN_EXTRACT_INFO ex_info;
  1099. insn_value = cgen_get_insn_value (cd, buf, 32);
  1100. /* Fill in ex_info fields like read_insn would. Don't actually call
  1101. read_insn, since the incoming buffer is already read (and possibly
  1102. modified a la m32r). */
  1103. ex_info.valid = (1 << 8) - 1;
  1104. ex_info.dis_info = info;
  1105. ex_info.insn_bytes = buf;
  1106. /* The instructions are stored in hash lists.
  1107. Pick the first one and keep trying until we find the right one. */
  1108. insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
  1109. while (insn_list != NULL)
  1110. {
  1111. const CGEN_INSN *insn = insn_list->insn;
  1112. CGEN_FIELDS fields;
  1113. int length;
  1114. if ((CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_CONFIG)
  1115. && CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_CONFIG) != MEP_CONFIG)
  1116. || ! (CGEN_ATTR_CGEN_INSN_SLOTS_VALUE (CGEN_INSN_ATTRS (insn)) & (1 << slot)))
  1117. {
  1118. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  1119. continue;
  1120. }
  1121. if ((insn_value & CGEN_INSN_BASE_MASK (insn))
  1122. == CGEN_INSN_BASE_VALUE (insn))
  1123. {
  1124. /* Printing is handled in two passes. The first pass parses the
  1125. machine insn and extracts the fields. The second pass prints
  1126. them. */
  1127. length = CGEN_EXTRACT_FN (cd, insn)
  1128. (cd, insn, &ex_info, insn_value, &fields, pc);
  1129. /* Length < 0 -> error. */
  1130. if (length < 0)
  1131. return length;
  1132. if (length > 0)
  1133. {
  1134. CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
  1135. /* Length is in bits, result is in bytes. */
  1136. return length / 8;
  1137. }
  1138. }
  1139. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  1140. }
  1141. if (slot == SLOTS_P0S)
  1142. (*info->fprintf_func) (info->stream, "*unknown-p0s*");
  1143. else if (slot == SLOTS_P0)
  1144. (*info->fprintf_func) (info->stream, "*unknown-p0*");
  1145. else if (slot == SLOTS_P1)
  1146. (*info->fprintf_func) (info->stream, "*unknown-p1*");
  1147. else if (slot == SLOTS_C3)
  1148. (*info->fprintf_func) (info->stream, "*unknown-c3*");
  1149. return 0;
  1150. }
  1151. static int
  1152. mep_examine_ivc2_insns (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, bfd_vma pc ATTRIBUTE_UNUSED, disassemble_info *info ATTRIBUTE_UNUSED)
  1153. {
  1154. int status;
  1155. int buflength;
  1156. bfd_byte buf[8];
  1157. bfd_byte insn[8];
  1158. int e;
  1159. /* Read in 64 bits. */
  1160. buflength = 8; /* VLIW insn spans 8 bytes. */
  1161. status = (*info->read_memory_func) (pc, buf, buflength, info);
  1162. if (status != 0)
  1163. {
  1164. (*info->memory_error_func) (status, pc, info);
  1165. return -1;
  1166. }
  1167. if (info->endian == BFD_ENDIAN_LITTLE)
  1168. e = 1;
  1169. else
  1170. e = 0;
  1171. if (((unsigned char)buf[0^e] & 0xf0) < 0xc0)
  1172. {
  1173. /* <--00--><--11--><--22--><--33--><--44--><--55--><--66--><--77--> */
  1174. /* V1 [-----core-----][--------p0s-------][------------p1------------] */
  1175. print_insn (cd, pc, info, buf, 2);
  1176. insn[0^e] = 0;
  1177. insn[1^e] = buf[2^e];
  1178. insn[2^e] = buf[3^e];
  1179. insn[3^e] = buf[4^e] & 0xf0;
  1180. (*info->fprintf_func) (info->stream, " + ");
  1181. print_slot_insn (cd, pc, info, SLOTS_P0S, insn);
  1182. insn[0^e] = buf[4^e] << 4 | buf[5^e] >> 4;
  1183. insn[1^e] = buf[5^e] << 4 | buf[6^e] >> 4;
  1184. insn[2^e] = buf[6^e] << 4 | buf[7^e] >> 4;
  1185. insn[3^e] = buf[7^e] << 4;
  1186. (*info->fprintf_func) (info->stream, " + ");
  1187. print_slot_insn (cd, pc, info, SLOTS_P1, insn);
  1188. }
  1189. else if ((buf[0^e] & 0xf0) == 0xf0 && (buf[1^e] & 0x0f) == 0x07)
  1190. {
  1191. /* <--00--><--11--><--22--><--33--><--44--><--55--><--66--><--77--> */
  1192. /* V3 1111[--p0--]0111[--------p0--------][------------p1------------] */
  1193. /* 00000000111111112222222233333333 */
  1194. insn[0^e] = buf[0^e] << 4 | buf[1^e] >> 4;
  1195. insn[1^e] = buf[2^e];
  1196. insn[2^e] = buf[3^e];
  1197. insn[3^e] = buf[4^e] & 0xf0;
  1198. print_slot_insn (cd, pc, info, SLOTS_P0, insn);
  1199. insn[0^e] = buf[4^e] << 4 | buf[5^e] >> 4;
  1200. insn[1^e] = buf[5^e] << 4 | buf[6^e] >> 4;
  1201. insn[2^e] = buf[6^e] << 4 | buf[7^e] >> 4;
  1202. insn[3^e] = buf[7^e] << 4;
  1203. (*info->fprintf_func) (info->stream, " + ");
  1204. print_slot_insn (cd, pc, info, SLOTS_P1, insn);
  1205. }
  1206. else
  1207. {
  1208. /* <--00--><--11--><--22--><--33--><--44--><--55--><--66--><--77--> */
  1209. /* V2 [-------------core-------------]xxxx[------------p1------------] */
  1210. print_insn (cd, pc, info, buf, 4);
  1211. insn[0^e] = buf[4^e] << 4 | buf[5^e] >> 4;
  1212. insn[1^e] = buf[5^e] << 4 | buf[6^e] >> 4;
  1213. insn[2^e] = buf[6^e] << 4 | buf[7^e] >> 4;
  1214. insn[3^e] = buf[7^e] << 4;
  1215. (*info->fprintf_func) (info->stream, " + ");
  1216. print_slot_insn (cd, pc, info, SLOTS_P1, insn);
  1217. }
  1218. return 8;
  1219. }
  1220. #endif /* MEP_IVC2_SUPPORTED */
  1221. /* This is a hack. SID calls this to update the disassembler as the
  1222. CPU changes modes. */
  1223. static int mep_ivc2_disassemble_p = 0;
  1224. static int mep_ivc2_vliw_disassemble_p = 0;
  1225. void
  1226. mep_print_insn_set_ivc2_mode (int ivc2_p, int vliw_p, int cfg_idx);
  1227. void
  1228. mep_print_insn_set_ivc2_mode (int ivc2_p, int vliw_p, int cfg_idx)
  1229. {
  1230. mep_ivc2_disassemble_p = ivc2_p;
  1231. mep_ivc2_vliw_disassemble_p = vliw_p;
  1232. mep_config_index = cfg_idx;
  1233. }
  1234. static int
  1235. mep_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  1236. {
  1237. int status;
  1238. int cop_type;
  1239. int ivc2 = 0;
  1240. static CGEN_ATTR_VALUE_BITSET_TYPE *ivc2_core_isa = NULL;
  1241. if (ivc2_core_isa == NULL)
  1242. {
  1243. /* IVC2 has some core-only coprocessor instructions. We
  1244. use COP32 to flag those, and COP64 for the VLIW ones,
  1245. since they have the same names. */
  1246. ivc2_core_isa = cgen_bitset_create (MAX_ISAS);
  1247. }
  1248. /* Extract and adapt to configuration number, if available. */
  1249. if (info->section && info->section->owner)
  1250. {
  1251. bfd *abfd = info->section->owner;
  1252. mep_config_index = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_INDEX_MASK;
  1253. /* This instantly redefines MEP_CONFIG, MEP_OMASK, .... MEP_VLIW64 */
  1254. cop_type = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_COP_MASK;
  1255. if (cop_type == EF_MEP_COP_IVC2)
  1256. ivc2 = 1;
  1257. }
  1258. /* Picking the right ISA bitmask for the current context is tricky. */
  1259. if (info->section)
  1260. {
  1261. if (info->section->flags & SEC_MEP_VLIW)
  1262. {
  1263. #ifdef MEP_IVC2_SUPPORTED
  1264. if (ivc2)
  1265. {
  1266. /* ivc2 has its own way of selecting its functions. */
  1267. cd->isas = & MEP_CORE_ISA;
  1268. status = mep_examine_ivc2_insns (cd, pc, info);
  1269. }
  1270. else
  1271. #endif
  1272. /* Are we in 32 or 64 bit vliw mode? */
  1273. if (MEP_VLIW64)
  1274. status = mep_examine_vliw64_insns (cd, pc, info);
  1275. else
  1276. status = mep_examine_vliw32_insns (cd, pc, info);
  1277. /* Both the above branches set their own isa bitmasks. */
  1278. }
  1279. else
  1280. {
  1281. if (ivc2)
  1282. {
  1283. cgen_bitset_clear (ivc2_core_isa);
  1284. cgen_bitset_union (ivc2_core_isa, &MEP_CORE_ISA, ivc2_core_isa);
  1285. cgen_bitset_union (ivc2_core_isa, &MEP_COP32_ISA, ivc2_core_isa);
  1286. cd->isas = ivc2_core_isa;
  1287. }
  1288. else
  1289. cd->isas = & MEP_CORE_ISA;
  1290. status = default_print_insn (cd, pc, info);
  1291. }
  1292. }
  1293. else /* sid or gdb */
  1294. {
  1295. #ifdef MEP_IVC2_SUPPORTED
  1296. if (mep_ivc2_disassemble_p)
  1297. {
  1298. if (mep_ivc2_vliw_disassemble_p)
  1299. {
  1300. cd->isas = & MEP_CORE_ISA;
  1301. status = mep_examine_ivc2_insns (cd, pc, info);
  1302. return status;
  1303. }
  1304. else
  1305. {
  1306. if (ivc2)
  1307. cd->isas = ivc2_core_isa;
  1308. }
  1309. }
  1310. #endif
  1311. status = default_print_insn (cd, pc, info);
  1312. }
  1313. return status;
  1314. }
  1315. /* -- opc.c */
  1316. #include "elf/mep.h"
  1317. /* A mask for all ISAs executed by the core. */
  1318. CGEN_ATTR_VALUE_BITSET_TYPE mep_all_core_isas_mask = {0, 0};
  1319. void
  1320. init_mep_all_core_isas_mask (void)
  1321. {
  1322. if (mep_all_core_isas_mask.length != 0)
  1323. return;
  1324. cgen_bitset_init (& mep_all_core_isas_mask, ISA_MAX);
  1325. cgen_bitset_set (& mep_all_core_isas_mask, ISA_MEP);
  1326. /* begin-all-core-isas */
  1327. cgen_bitset_add (& mep_all_core_isas_mask, ISA_EXT_CORE1);
  1328. /* end-all-core-isas */
  1329. }
  1330. CGEN_ATTR_VALUE_BITSET_TYPE mep_all_cop_isas_mask = {0, 0};
  1331. void
  1332. init_mep_all_cop_isas_mask (void)
  1333. {
  1334. if (mep_all_cop_isas_mask.length != 0)
  1335. return;
  1336. cgen_bitset_init (& mep_all_cop_isas_mask, ISA_MAX);
  1337. /* begin-all-cop-isas */
  1338. cgen_bitset_add (& mep_all_cop_isas_mask, ISA_EXT_COP1_16);
  1339. cgen_bitset_add (& mep_all_cop_isas_mask, ISA_EXT_COP1_32);
  1340. cgen_bitset_add (& mep_all_cop_isas_mask, ISA_EXT_COP1_48);
  1341. cgen_bitset_add (& mep_all_cop_isas_mask, ISA_EXT_COP1_64);
  1342. /* end-all-cop-isas */
  1343. }
  1344. int
  1345. mep_insn_supported_by_isa (const CGEN_INSN *insn, CGEN_ATTR_VALUE_BITSET_TYPE *isa_mask)
  1346. {
  1347. CGEN_BITSET insn_isas = CGEN_INSN_BITSET_ATTR_VALUE (insn, CGEN_INSN_ISA);
  1348. return cgen_bitset_intersect_p (& insn_isas, isa_mask);
  1349. }
  1350. #define OPTION_MASK \
  1351. ( (1 << CGEN_INSN_OPTIONAL_BIT_INSN) \
  1352. | (1 << CGEN_INSN_OPTIONAL_MUL_INSN) \
  1353. | (1 << CGEN_INSN_OPTIONAL_DIV_INSN) \
  1354. | (1 << CGEN_INSN_OPTIONAL_DEBUG_INSN) \
  1355. | (1 << CGEN_INSN_OPTIONAL_LDZ_INSN) \
  1356. | (1 << CGEN_INSN_OPTIONAL_ABS_INSN) \
  1357. | (1 << CGEN_INSN_OPTIONAL_AVE_INSN) \
  1358. | (1 << CGEN_INSN_OPTIONAL_MINMAX_INSN) \
  1359. | (1 << CGEN_INSN_OPTIONAL_CLIP_INSN) \
  1360. | (1 << CGEN_INSN_OPTIONAL_SAT_INSN) \
  1361. | (1 << CGEN_INSN_OPTIONAL_UCI_INSN) \
  1362. | (1 << CGEN_INSN_OPTIONAL_DSP_INSN) \
  1363. | (1 << CGEN_INSN_OPTIONAL_CP_INSN) \
  1364. | (1 << CGEN_INSN_OPTIONAL_CP64_INSN) )
  1365. mep_config_map_struct mep_config_map[] =
  1366. {
  1367. /* config-map-start */
  1368. /* Default entry: first module, with all options enabled. */
  1369. { "", 0, EF_MEP_COP_IVC2 | EF_MEP_CPU_C5,0, 64, { 1, "\x20" }, { 1, "\x10" }, { 1, "\x8" }, { 1, "\x4" }, { 1, "\x3c" }, { 1, "\xc0" }, OPTION_MASK | (1 << CGEN_INSN_OPTIONAL_DSP_INSN) | (1 << CGEN_INSN_OPTIONAL_UCI_INSN) },
  1370. { "default", CONFIG_DEFAULT, EF_MEP_COP_IVC2 | EF_MEP_CPU_C5, 0, 64, { 1, "\x20" }, { 1, "\x10" }, { 1, "\x8" }, { 1, "\x4" }, { 1, "\x3c" }, { 1, "\xc0" },
  1371. 0
  1372. | (1 << CGEN_INSN_OPTIONAL_CP_INSN)
  1373. | (1 << CGEN_INSN_OPTIONAL_CP64_INSN)
  1374. | (1 << CGEN_INSN_OPTIONAL_MUL_INSN)
  1375. | (1 << CGEN_INSN_OPTIONAL_DIV_INSN)
  1376. | (1 << CGEN_INSN_OPTIONAL_BIT_INSN)
  1377. | (1 << CGEN_INSN_OPTIONAL_LDZ_INSN)
  1378. | (1 << CGEN_INSN_OPTIONAL_ABS_INSN)
  1379. | (1 << CGEN_INSN_OPTIONAL_AVE_INSN)
  1380. | (1 << CGEN_INSN_OPTIONAL_MINMAX_INSN)
  1381. | (1 << CGEN_INSN_OPTIONAL_CLIP_INSN)
  1382. | (1 << CGEN_INSN_OPTIONAL_SAT_INSN) },
  1383. /* config-map-end */
  1384. { 0, 0, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, 0 }
  1385. };
  1386. int mep_config_index = 0;
  1387. static int
  1388. check_configured_mach (int machs)
  1389. {
  1390. /* All base insns are supported. */
  1391. int mach = 1 << MACH_BASE;
  1392. switch (MEP_CPU & EF_MEP_CPU_MASK)
  1393. {
  1394. case EF_MEP_CPU_C2:
  1395. case EF_MEP_CPU_C3:
  1396. mach |= (1 << MACH_MEP);
  1397. break;
  1398. case EF_MEP_CPU_H1:
  1399. mach |= (1 << MACH_H1);
  1400. break;
  1401. case EF_MEP_CPU_C5:
  1402. mach |= (1 << MACH_MEP);
  1403. mach |= (1 << MACH_C5);
  1404. break;
  1405. default:
  1406. break;
  1407. }
  1408. return machs & mach;
  1409. }
  1410. int
  1411. mep_cgen_insn_supported (CGEN_CPU_DESC cd, const CGEN_INSN *insn)
  1412. {
  1413. int iconfig = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_CONFIG);
  1414. int machs = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_MACH);
  1415. CGEN_BITSET isas = CGEN_INSN_BITSET_ATTR_VALUE (insn, CGEN_INSN_ISA);
  1416. int ok1;
  1417. int ok2;
  1418. int ok3;
  1419. /* If the insn has an option bit set that we don't want,
  1420. reject it. */
  1421. if (CGEN_INSN_ATTRS (insn)->bool_ & OPTION_MASK & ~MEP_OMASK)
  1422. return 0;
  1423. /* If attributes are absent, assume no restriction. */
  1424. if (machs == 0)
  1425. machs = ~0;
  1426. ok1 = ((machs & cd->machs) && cgen_bitset_intersect_p (& isas, cd->isas));
  1427. /* If the insn is config-specific, make sure it matches. */
  1428. ok2 = (iconfig == 0 || iconfig == MEP_CONFIG);
  1429. /* Make sure the insn is supported by the configured mach */
  1430. ok3 = check_configured_mach (machs);
  1431. return (ok1 && ok2 && ok3);
  1432. }
  1433. int
  1434. mep_cgen_insn_supported_asm (CGEN_CPU_DESC cd, const CGEN_INSN *insn)
  1435. {
  1436. #ifdef MEP_IVC2_SUPPORTED
  1437. /* If we're assembling VLIW packets, ignore the 12-bit BSR as we
  1438. can't relax that. The 24-bit BSR is matched instead. */
  1439. if (insn->base->num == MEP_INSN_BSR12
  1440. && cgen_bitset_contains (cd->isas, ISA_EXT_COP1_64))
  1441. return 0;
  1442. #endif
  1443. return mep_cgen_insn_supported (cd, insn);
  1444. }