mep-dis.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
  2. /* Disassembler interface for targets using CGEN. -*- C -*-
  3. CGEN: Cpu tools GENerator
  4. THIS FILE IS MACHINE GENERATED WITH CGEN.
  5. - the resultant file is machine generated, cgen-dis.in isn't
  6. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  7. This file is part of libopcodes.
  8. This library is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3, or (at your option)
  11. any later version.
  12. It is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  15. License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software Foundation, Inc.,
  18. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  19. /* ??? Eventually more and more of this stuff can go to cpu-independent files.
  20. Keep that in mind. */
  21. #include "sysdep.h"
  22. #include <stdio.h>
  23. #include "ansidecl.h"
  24. #include "disassemble.h"
  25. #include "bfd.h"
  26. #include "symcat.h"
  27. #include "libiberty.h"
  28. #include "mep-desc.h"
  29. #include "mep-opc.h"
  30. #include "opintl.h"
  31. /* Default text to print if an instruction isn't recognized. */
  32. #define UNKNOWN_INSN_MSG _("*unknown*")
  33. static void print_normal
  34. (CGEN_CPU_DESC, void *, long, unsigned int, bfd_vma, int);
  35. static void print_address
  36. (CGEN_CPU_DESC, void *, bfd_vma, unsigned int, bfd_vma, int) ATTRIBUTE_UNUSED;
  37. static void print_keyword
  38. (CGEN_CPU_DESC, void *, CGEN_KEYWORD *, long, unsigned int) ATTRIBUTE_UNUSED;
  39. static void print_insn_normal
  40. (CGEN_CPU_DESC, void *, const CGEN_INSN *, CGEN_FIELDS *, bfd_vma, int);
  41. static int print_insn
  42. (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, unsigned);
  43. static int default_print_insn
  44. (CGEN_CPU_DESC, bfd_vma, disassemble_info *) ATTRIBUTE_UNUSED;
  45. static int read_insn
  46. (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, int, CGEN_EXTRACT_INFO *,
  47. unsigned long *);
  48. /* -- disassembler routines inserted here. */
  49. /* -- dis.c */
  50. #include "elf/mep.h"
  51. #include "elf-bfd.h"
  52. #define CGEN_VALIDATE_INSN_SUPPORTED
  53. static void print_tpreg (CGEN_CPU_DESC, PTR, CGEN_KEYWORD *, long, unsigned int);
  54. static void print_spreg (CGEN_CPU_DESC, PTR, CGEN_KEYWORD *, long, unsigned int);
  55. static void
  56. print_tpreg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, PTR dis_info,
  57. CGEN_KEYWORD *table ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED,
  58. unsigned int flags ATTRIBUTE_UNUSED)
  59. {
  60. disassemble_info *info = (disassemble_info *) dis_info;
  61. (*info->fprintf_func) (info->stream, "$tp");
  62. }
  63. static void
  64. print_spreg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, PTR dis_info,
  65. CGEN_KEYWORD *table ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED,
  66. unsigned int flags ATTRIBUTE_UNUSED)
  67. {
  68. disassemble_info *info = (disassemble_info *) dis_info;
  69. (*info->fprintf_func) (info->stream, "$sp");
  70. }
  71. /* begin-cop-ip-print-handlers */
  72. static void
  73. print_ivc2_cr (CGEN_CPU_DESC,
  74. void *,
  75. CGEN_KEYWORD *,
  76. long,
  77. unsigned int) ATTRIBUTE_UNUSED;
  78. static void
  79. print_ivc2_cr (CGEN_CPU_DESC cd,
  80. void *dis_info,
  81. CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
  82. long value,
  83. unsigned int attrs)
  84. {
  85. print_keyword (cd, dis_info, & mep_cgen_opval_h_cr_ivc2, value, attrs);
  86. }
  87. static void
  88. print_ivc2_ccr (CGEN_CPU_DESC,
  89. void *,
  90. CGEN_KEYWORD *,
  91. long,
  92. unsigned int) ATTRIBUTE_UNUSED;
  93. static void
  94. print_ivc2_ccr (CGEN_CPU_DESC cd,
  95. void *dis_info,
  96. CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
  97. long value,
  98. unsigned int attrs)
  99. {
  100. print_keyword (cd, dis_info, & mep_cgen_opval_h_ccr_ivc2, value, attrs);
  101. }
  102. /* end-cop-ip-print-handlers */
  103. /************************************************************\
  104. *********************** Experimental *************************
  105. \************************************************************/
  106. #undef CGEN_PRINT_INSN
  107. #define CGEN_PRINT_INSN mep_print_insn
  108. static int
  109. mep_print_vliw_insns (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info,
  110. bfd_byte *buf, int corelength, int copro1length,
  111. int copro2length ATTRIBUTE_UNUSED)
  112. {
  113. int i;
  114. int status = 0;
  115. /* char insnbuf[CGEN_MAX_INSN_SIZE]; */
  116. bfd_byte insnbuf[64];
  117. /* If corelength > 0 then there is a core insn present. It
  118. will be at the beginning of the buffer. After printing
  119. the core insn, we need to print the + on the next line. */
  120. if (corelength > 0)
  121. {
  122. int my_status = 0;
  123. for (i = 0; i < corelength; i++ )
  124. insnbuf[i] = buf[i];
  125. cd->isas = & MEP_CORE_ISA;
  126. my_status = print_insn (cd, pc, info, insnbuf, corelength);
  127. if (my_status != corelength)
  128. {
  129. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  130. my_status = corelength;
  131. }
  132. status += my_status;
  133. /* Print the + to indicate that the following copro insn is */
  134. /* part of a vliw group. */
  135. if (copro1length > 0)
  136. (*info->fprintf_func) (info->stream, " + ");
  137. }
  138. /* Now all that is left to be processed is the coprocessor insns
  139. In vliw mode, there will always be one. Its positioning will
  140. be from byte corelength to byte corelength+copro1length -1.
  141. No need to check for existence. Also, the first vliw insn,
  142. will, as spec'd, always be at least as long as the core insn
  143. so we don't need to flush the buffer. */
  144. if (copro1length > 0)
  145. {
  146. int my_status = 0;
  147. for (i = corelength; i < corelength + copro1length; i++ )
  148. insnbuf[i - corelength] = buf[i];
  149. switch (copro1length)
  150. {
  151. case 0:
  152. break;
  153. case 2:
  154. cd->isas = & MEP_COP16_ISA;
  155. break;
  156. case 4:
  157. cd->isas = & MEP_COP32_ISA;
  158. break;
  159. case 6:
  160. cd->isas = & MEP_COP48_ISA;
  161. break;
  162. case 8:
  163. cd->isas = & MEP_COP64_ISA;
  164. break;
  165. default:
  166. /* Shouldn't be anything but 16,32,48,64. */
  167. break;
  168. }
  169. my_status = print_insn (cd, pc, info, insnbuf, copro1length);
  170. if (my_status != copro1length)
  171. {
  172. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  173. my_status = copro1length;
  174. }
  175. status += my_status;
  176. }
  177. #if 0
  178. /* Now we need to process the second copro insn if it exists. We
  179. have no guarantee that the second copro insn will be longer
  180. than the first, so we have to flush the buffer if we are have
  181. a second copro insn to process. If present, this insn will
  182. be in the position from byte corelength+copro1length to byte
  183. corelength+copro1length+copro2length-1 (which better equal 8
  184. or else we're in big trouble. */
  185. if (copro2length > 0)
  186. {
  187. int my_status = 0;
  188. for (i = 0; i < 64 ; i++)
  189. insnbuf[i] = 0;
  190. for (i = corelength + copro1length; i < 64; i++)
  191. insnbuf[i - (corelength + copro1length)] = buf[i];
  192. switch (copro2length)
  193. {
  194. case 2:
  195. cd->isas = 1 << ISA_EXT_COP1_16;
  196. break;
  197. case 4:
  198. cd->isas = 1 << ISA_EXT_COP1_32;
  199. break;
  200. case 6:
  201. cd->isas = 1 << ISA_EXT_COP1_48;
  202. break;
  203. case 8:
  204. cd->isas = 1 << ISA_EXT_COP1_64;
  205. break;
  206. default:
  207. /* Shouldn't be anything but 16,32,48,64. */
  208. break;
  209. }
  210. my_status = print_insn (cd, pc, info, insnbuf, copro2length);
  211. if (my_status != copro2length)
  212. {
  213. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  214. my_status = copro2length;
  215. }
  216. status += my_status;
  217. }
  218. #endif
  219. /* Status should now be the number of bytes that were printed
  220. which should be 4 for VLIW32 mode and 64 for VLIW64 mode. */
  221. if ((!MEP_VLIW64 && (status != 4)) || (MEP_VLIW64 && (status != 8)))
  222. return -1;
  223. else
  224. return status;
  225. }
  226. /* The two functions mep_examine_vliw[32,64]_insns are used find out
  227. which vliw combinaion (16 bit core with 48 bit copro, 32 bit core
  228. with 32 bit copro, etc.) is present. Later on, when internally
  229. parallel coprocessors are handled, only these functions should
  230. need to be changed.
  231. At this time only the following combinations are supported:
  232. VLIW32 Mode:
  233. 16 bit core insn (core) and 16 bit coprocessor insn (cop1)
  234. 32 bit core insn (core)
  235. 32 bit coprocessor insn (cop1)
  236. Note: As of this time, I do not believe we have enough information
  237. to distinguish a 32 bit core insn from a 32 bit cop insn. Also,
  238. no 16 bit coprocessor insns have been specified.
  239. VLIW64 Mode:
  240. 16 bit core insn (core) and 48 bit coprocessor insn (cop1)
  241. 32 bit core insn (core) and 32 bit coprocessor insn (cop1)
  242. 64 bit coprocessor insn (cop1)
  243. The framework for an internally parallel coprocessor is also
  244. present (2nd coprocessor insn is cop2), but at this time it
  245. is not used. This only appears to be valid in VLIW64 mode. */
  246. static int
  247. mep_examine_vliw32_insns (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  248. {
  249. int status;
  250. int buflength;
  251. int corebuflength;
  252. int cop1buflength;
  253. int cop2buflength;
  254. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  255. char indicator16[1];
  256. char indicatorcop32[2];
  257. /* At this time we're not supporting internally parallel coprocessors,
  258. so cop2buflength will always be 0. */
  259. cop2buflength = 0;
  260. /* Read in 32 bits. */
  261. buflength = 4; /* VLIW insn spans 4 bytes. */
  262. status = (*info->read_memory_func) (pc, buf, buflength, info);
  263. if (status != 0)
  264. {
  265. (*info->memory_error_func) (status, pc, info);
  266. return -1;
  267. }
  268. /* Put the big endian representation of the bytes to be examined
  269. in the temporary buffers for examination. */
  270. if (info->endian == BFD_ENDIAN_BIG)
  271. {
  272. indicator16[0] = buf[0];
  273. indicatorcop32[0] = buf[0];
  274. indicatorcop32[1] = buf[1];
  275. }
  276. else
  277. {
  278. indicator16[0] = buf[1];
  279. indicatorcop32[0] = buf[1];
  280. indicatorcop32[1] = buf[0];
  281. }
  282. /* If the two high order bits are 00, 01 or 10, we have a 16 bit
  283. core insn and a 48 bit copro insn. */
  284. if ((indicator16[0] & 0x80) && (indicator16[0] & 0x40))
  285. {
  286. if ((indicatorcop32[0] & 0xf0) == 0xf0 && (indicatorcop32[1] & 0x07) == 0x07)
  287. {
  288. /* We have a 32 bit copro insn. */
  289. corebuflength = 0;
  290. /* All 4 4ytes are one copro insn. */
  291. cop1buflength = 4;
  292. }
  293. else
  294. {
  295. /* We have a 32 bit core. */
  296. corebuflength = 4;
  297. cop1buflength = 0;
  298. }
  299. }
  300. else
  301. {
  302. /* We have a 16 bit core insn and a 16 bit copro insn. */
  303. corebuflength = 2;
  304. cop1buflength = 2;
  305. }
  306. /* Now we have the distrubution set. Print them out. */
  307. status = mep_print_vliw_insns (cd, pc, info, buf, corebuflength,
  308. cop1buflength, cop2buflength);
  309. return status;
  310. }
  311. static int
  312. mep_examine_vliw64_insns (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  313. {
  314. int status;
  315. int buflength;
  316. int corebuflength;
  317. int cop1buflength;
  318. int cop2buflength;
  319. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  320. char indicator16[1];
  321. char indicator64[4];
  322. /* At this time we're not supporting internally parallel
  323. coprocessors, so cop2buflength will always be 0. */
  324. cop2buflength = 0;
  325. /* Read in 64 bits. */
  326. buflength = 8; /* VLIW insn spans 8 bytes. */
  327. status = (*info->read_memory_func) (pc, buf, buflength, info);
  328. if (status != 0)
  329. {
  330. (*info->memory_error_func) (status, pc, info);
  331. return -1;
  332. }
  333. /* We have all 64 bits in the buffer now. We have to figure out
  334. what combination of instruction sizes are present. The two
  335. high order bits will indicate whether or not we have a 16 bit
  336. core insn or not. If not, then we have to look at the 7,8th
  337. bytes to tell whether we have 64 bit copro insn or a 32 bit
  338. core insn with a 32 bit copro insn. Endianness will make a
  339. difference here. */
  340. /* Put the big endian representation of the bytes to be examined
  341. in the temporary buffers for examination. */
  342. /* indicator16[0] = buf[0]; */
  343. if (info->endian == BFD_ENDIAN_BIG)
  344. {
  345. indicator16[0] = buf[0];
  346. indicator64[0] = buf[0];
  347. indicator64[1] = buf[1];
  348. indicator64[2] = buf[2];
  349. indicator64[3] = buf[3];
  350. }
  351. else
  352. {
  353. indicator16[0] = buf[1];
  354. indicator64[0] = buf[1];
  355. indicator64[1] = buf[0];
  356. indicator64[2] = buf[3];
  357. indicator64[3] = buf[2];
  358. }
  359. /* If the two high order bits are 00, 01 or 10, we have a 16 bit
  360. core insn and a 48 bit copro insn. */
  361. if ((indicator16[0] & 0x80) && (indicator16[0] & 0x40))
  362. {
  363. if ((indicator64[0] & 0xf0) == 0xf0 && (indicator64[1] & 0x07) == 0x07
  364. && ((indicator64[2] & 0xfe) != 0xf0 || (indicator64[3] & 0xf4) != 0))
  365. {
  366. /* We have a 64 bit copro insn. */
  367. corebuflength = 0;
  368. /* All 8 bytes are one copro insn. */
  369. cop1buflength = 8;
  370. }
  371. else
  372. {
  373. /* We have a 32 bit core insn and a 32 bit copro insn. */
  374. corebuflength = 4;
  375. cop1buflength = 4;
  376. }
  377. }
  378. else
  379. {
  380. /* We have a 16 bit core insn and a 48 bit copro insn. */
  381. corebuflength = 2;
  382. cop1buflength = 6;
  383. }
  384. /* Now we have the distrubution set. Print them out. */
  385. status = mep_print_vliw_insns (cd, pc, info, buf, corebuflength,
  386. cop1buflength, cop2buflength);
  387. return status;
  388. }
  389. #ifdef MEP_IVC2_SUPPORTED
  390. static int
  391. print_slot_insn (CGEN_CPU_DESC cd,
  392. bfd_vma pc,
  393. disassemble_info *info,
  394. SLOTS_ATTR slot,
  395. bfd_byte *buf)
  396. {
  397. const CGEN_INSN_LIST *insn_list;
  398. CGEN_INSN_INT insn_value;
  399. CGEN_EXTRACT_INFO ex_info;
  400. insn_value = cgen_get_insn_value (cd, buf, 32, cd->insn_endian);
  401. /* Fill in ex_info fields like read_insn would. Don't actually call
  402. read_insn, since the incoming buffer is already read (and possibly
  403. modified a la m32r). */
  404. ex_info.valid = (1 << 8) - 1;
  405. ex_info.dis_info = info;
  406. ex_info.insn_bytes = buf;
  407. /* The instructions are stored in hash lists.
  408. Pick the first one and keep trying until we find the right one. */
  409. insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
  410. while (insn_list != NULL)
  411. {
  412. const CGEN_INSN *insn = insn_list->insn;
  413. CGEN_FIELDS fields;
  414. int length;
  415. if ((CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_CONFIG)
  416. && CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_CONFIG) != MEP_CONFIG)
  417. || ! (CGEN_ATTR_CGEN_INSN_SLOTS_VALUE (CGEN_INSN_ATTRS (insn)) & (1 << slot)))
  418. {
  419. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  420. continue;
  421. }
  422. if ((insn_value & CGEN_INSN_BASE_MASK (insn))
  423. == CGEN_INSN_BASE_VALUE (insn))
  424. {
  425. /* Printing is handled in two passes. The first pass parses the
  426. machine insn and extracts the fields. The second pass prints
  427. them. */
  428. length = CGEN_EXTRACT_FN (cd, insn)
  429. (cd, insn, &ex_info, insn_value, &fields, pc);
  430. /* Length < 0 -> error. */
  431. if (length < 0)
  432. return length;
  433. if (length > 0)
  434. {
  435. CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
  436. /* Length is in bits, result is in bytes. */
  437. return length / 8;
  438. }
  439. }
  440. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  441. }
  442. if (slot == SLOTS_P0S)
  443. (*info->fprintf_func) (info->stream, "*unknown-p0s*");
  444. else if (slot == SLOTS_P0)
  445. (*info->fprintf_func) (info->stream, "*unknown-p0*");
  446. else if (slot == SLOTS_P1)
  447. (*info->fprintf_func) (info->stream, "*unknown-p1*");
  448. else if (slot == SLOTS_C3)
  449. (*info->fprintf_func) (info->stream, "*unknown-c3*");
  450. return 0;
  451. }
  452. static int
  453. mep_examine_ivc2_insns (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, bfd_vma pc ATTRIBUTE_UNUSED, disassemble_info *info ATTRIBUTE_UNUSED)
  454. {
  455. int status;
  456. int buflength;
  457. bfd_byte buf[8];
  458. bfd_byte insn[8];
  459. int e;
  460. /* Read in 64 bits. */
  461. buflength = 8; /* VLIW insn spans 8 bytes. */
  462. status = (*info->read_memory_func) (pc, buf, buflength, info);
  463. if (status != 0)
  464. {
  465. (*info->memory_error_func) (status, pc, info);
  466. return -1;
  467. }
  468. if (info->endian == BFD_ENDIAN_LITTLE)
  469. e = 1;
  470. else
  471. e = 0;
  472. if (((unsigned char)buf[0^e] & 0xf0) < 0xc0)
  473. {
  474. /* <--00--><--11--><--22--><--33--><--44--><--55--><--66--><--77--> */
  475. /* V1 [-----core-----][--------p0s-------][------------p1------------] */
  476. print_insn (cd, pc, info, buf, 2);
  477. insn[0^e] = 0;
  478. insn[1^e] = buf[2^e];
  479. insn[2^e] = buf[3^e];
  480. insn[3^e] = buf[4^e] & 0xf0;
  481. (*info->fprintf_func) (info->stream, " + ");
  482. print_slot_insn (cd, pc, info, SLOTS_P0S, insn);
  483. insn[0^e] = buf[4^e] << 4 | buf[5^e] >> 4;
  484. insn[1^e] = buf[5^e] << 4 | buf[6^e] >> 4;
  485. insn[2^e] = buf[6^e] << 4 | buf[7^e] >> 4;
  486. insn[3^e] = buf[7^e] << 4;
  487. (*info->fprintf_func) (info->stream, " + ");
  488. print_slot_insn (cd, pc, info, SLOTS_P1, insn);
  489. }
  490. else if ((buf[0^e] & 0xf0) == 0xf0 && (buf[1^e] & 0x0f) == 0x07)
  491. {
  492. /* <--00--><--11--><--22--><--33--><--44--><--55--><--66--><--77--> */
  493. /* V3 1111[--p0--]0111[--------p0--------][------------p1------------] */
  494. /* 00000000111111112222222233333333 */
  495. insn[0^e] = buf[0^e] << 4 | buf[1^e] >> 4;
  496. insn[1^e] = buf[2^e];
  497. insn[2^e] = buf[3^e];
  498. insn[3^e] = buf[4^e] & 0xf0;
  499. print_slot_insn (cd, pc, info, SLOTS_P0, insn);
  500. insn[0^e] = buf[4^e] << 4 | buf[5^e] >> 4;
  501. insn[1^e] = buf[5^e] << 4 | buf[6^e] >> 4;
  502. insn[2^e] = buf[6^e] << 4 | buf[7^e] >> 4;
  503. insn[3^e] = buf[7^e] << 4;
  504. (*info->fprintf_func) (info->stream, " + ");
  505. print_slot_insn (cd, pc, info, SLOTS_P1, insn);
  506. }
  507. else
  508. {
  509. /* <--00--><--11--><--22--><--33--><--44--><--55--><--66--><--77--> */
  510. /* V2 [-------------core-------------]xxxx[------------p1------------] */
  511. print_insn (cd, pc, info, buf, 4);
  512. insn[0^e] = buf[4^e] << 4 | buf[5^e] >> 4;
  513. insn[1^e] = buf[5^e] << 4 | buf[6^e] >> 4;
  514. insn[2^e] = buf[6^e] << 4 | buf[7^e] >> 4;
  515. insn[3^e] = buf[7^e] << 4;
  516. (*info->fprintf_func) (info->stream, " + ");
  517. print_slot_insn (cd, pc, info, SLOTS_P1, insn);
  518. }
  519. return 8;
  520. }
  521. #endif /* MEP_IVC2_SUPPORTED */
  522. /* This is a hack. SID calls this to update the disassembler as the
  523. CPU changes modes. */
  524. static int mep_ivc2_disassemble_p = 0;
  525. static int mep_ivc2_vliw_disassemble_p = 0;
  526. void
  527. mep_print_insn_set_ivc2_mode (int ivc2_p, int vliw_p, int cfg_idx);
  528. void
  529. mep_print_insn_set_ivc2_mode (int ivc2_p, int vliw_p, int cfg_idx)
  530. {
  531. mep_ivc2_disassemble_p = ivc2_p;
  532. mep_ivc2_vliw_disassemble_p = vliw_p;
  533. mep_config_index = cfg_idx;
  534. }
  535. static int
  536. mep_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  537. {
  538. int status;
  539. int cop_type;
  540. int ivc2 = 0;
  541. static CGEN_ATTR_VALUE_BITSET_TYPE *ivc2_core_isa = NULL;
  542. if (ivc2_core_isa == NULL)
  543. {
  544. /* IVC2 has some core-only coprocessor instructions. We
  545. use COP32 to flag those, and COP64 for the VLIW ones,
  546. since they have the same names. */
  547. ivc2_core_isa = cgen_bitset_create (MAX_ISAS);
  548. }
  549. /* Extract and adapt to configuration number, if available. */
  550. if (info->section && info->section->owner)
  551. {
  552. bfd *abfd = info->section->owner;
  553. mep_config_index = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_INDEX_MASK;
  554. /* This instantly redefines MEP_CONFIG, MEP_OMASK, .... MEP_VLIW64 */
  555. cop_type = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_COP_MASK;
  556. if (cop_type == EF_MEP_COP_IVC2)
  557. ivc2 = 1;
  558. }
  559. /* Picking the right ISA bitmask for the current context is tricky. */
  560. if (info->section)
  561. {
  562. if (info->section->flags & SEC_MEP_VLIW)
  563. {
  564. #ifdef MEP_IVC2_SUPPORTED
  565. if (ivc2)
  566. {
  567. /* ivc2 has its own way of selecting its functions. */
  568. cd->isas = & MEP_CORE_ISA;
  569. status = mep_examine_ivc2_insns (cd, pc, info);
  570. }
  571. else
  572. #endif
  573. /* Are we in 32 or 64 bit vliw mode? */
  574. if (MEP_VLIW64)
  575. status = mep_examine_vliw64_insns (cd, pc, info);
  576. else
  577. status = mep_examine_vliw32_insns (cd, pc, info);
  578. /* Both the above branches set their own isa bitmasks. */
  579. }
  580. else
  581. {
  582. if (ivc2)
  583. {
  584. cgen_bitset_clear (ivc2_core_isa);
  585. cgen_bitset_union (ivc2_core_isa, &MEP_CORE_ISA, ivc2_core_isa);
  586. cgen_bitset_union (ivc2_core_isa, &MEP_COP32_ISA, ivc2_core_isa);
  587. cd->isas = ivc2_core_isa;
  588. }
  589. else
  590. cd->isas = & MEP_CORE_ISA;
  591. status = default_print_insn (cd, pc, info);
  592. }
  593. }
  594. else /* sid or gdb */
  595. {
  596. #ifdef MEP_IVC2_SUPPORTED
  597. if (mep_ivc2_disassemble_p)
  598. {
  599. if (mep_ivc2_vliw_disassemble_p)
  600. {
  601. cd->isas = & MEP_CORE_ISA;
  602. status = mep_examine_ivc2_insns (cd, pc, info);
  603. return status;
  604. }
  605. else
  606. {
  607. if (ivc2)
  608. cd->isas = ivc2_core_isa;
  609. }
  610. }
  611. #endif
  612. status = default_print_insn (cd, pc, info);
  613. }
  614. return status;
  615. }
  616. /* -- opc.c */
  617. void mep_cgen_print_operand
  618. (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, void const *, bfd_vma, int);
  619. /* Main entry point for printing operands.
  620. XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
  621. of dis-asm.h on cgen.h.
  622. This function is basically just a big switch statement. Earlier versions
  623. used tables to look up the function to use, but
  624. - if the table contains both assembler and disassembler functions then
  625. the disassembler contains much of the assembler and vice-versa,
  626. - there's a lot of inlining possibilities as things grow,
  627. - using a switch statement avoids the function call overhead.
  628. This function could be moved into `print_insn_normal', but keeping it
  629. separate makes clear the interface between `print_insn_normal' and each of
  630. the handlers. */
  631. void
  632. mep_cgen_print_operand (CGEN_CPU_DESC cd,
  633. int opindex,
  634. void * xinfo,
  635. CGEN_FIELDS *fields,
  636. void const *attrs ATTRIBUTE_UNUSED,
  637. bfd_vma pc,
  638. int length)
  639. {
  640. disassemble_info *info = (disassemble_info *) xinfo;
  641. switch (opindex)
  642. {
  643. case MEP_OPERAND_ADDR24A4 :
  644. print_normal (cd, info, fields->f_24u8a4n, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  645. break;
  646. case MEP_OPERAND_C5RMUIMM20 :
  647. print_normal (cd, info, fields->f_c5_rmuimm20, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  648. break;
  649. case MEP_OPERAND_C5RNMUIMM24 :
  650. print_normal (cd, info, fields->f_c5_rnmuimm24, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  651. break;
  652. case MEP_OPERAND_CALLNUM :
  653. print_normal (cd, info, fields->f_callnum, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  654. break;
  655. case MEP_OPERAND_CCCC :
  656. print_normal (cd, info, fields->f_rm, 0, pc, length);
  657. break;
  658. case MEP_OPERAND_CCRN :
  659. print_keyword (cd, info, & mep_cgen_opval_h_ccr, fields->f_ccrn, 0|(1<<CGEN_OPERAND_VIRTUAL));
  660. break;
  661. case MEP_OPERAND_CDISP10 :
  662. print_normal (cd, info, fields->f_cdisp10, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  663. break;
  664. case MEP_OPERAND_CDISP10A2 :
  665. print_normal (cd, info, fields->f_cdisp10, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  666. break;
  667. case MEP_OPERAND_CDISP10A4 :
  668. print_normal (cd, info, fields->f_cdisp10, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  669. break;
  670. case MEP_OPERAND_CDISP10A8 :
  671. print_normal (cd, info, fields->f_cdisp10, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  672. break;
  673. case MEP_OPERAND_CDISP12 :
  674. print_normal (cd, info, fields->f_12s20, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  675. break;
  676. case MEP_OPERAND_CIMM4 :
  677. print_normal (cd, info, fields->f_rn, 0, pc, length);
  678. break;
  679. case MEP_OPERAND_CIMM5 :
  680. print_normal (cd, info, fields->f_5u24, 0, pc, length);
  681. break;
  682. case MEP_OPERAND_CODE16 :
  683. print_normal (cd, info, fields->f_16u16, 0, pc, length);
  684. break;
  685. case MEP_OPERAND_CODE24 :
  686. print_normal (cd, info, fields->f_24u4n, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  687. break;
  688. case MEP_OPERAND_CP_FLAG :
  689. print_keyword (cd, info, & mep_cgen_opval_h_ccr, 0, 0);
  690. break;
  691. case MEP_OPERAND_CRN :
  692. print_keyword (cd, info, & mep_cgen_opval_h_cr, fields->f_crn, 0);
  693. break;
  694. case MEP_OPERAND_CRN64 :
  695. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_crn, 0);
  696. break;
  697. case MEP_OPERAND_CRNX :
  698. print_keyword (cd, info, & mep_cgen_opval_h_cr, fields->f_crnx, 0|(1<<CGEN_OPERAND_VIRTUAL));
  699. break;
  700. case MEP_OPERAND_CRNX64 :
  701. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_crnx, 0|(1<<CGEN_OPERAND_VIRTUAL));
  702. break;
  703. case MEP_OPERAND_CROC :
  704. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_5u7, 0);
  705. break;
  706. case MEP_OPERAND_CROP :
  707. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_5u23, 0);
  708. break;
  709. case MEP_OPERAND_CRPC :
  710. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_5u26, 0);
  711. break;
  712. case MEP_OPERAND_CRPP :
  713. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_5u18, 0);
  714. break;
  715. case MEP_OPERAND_CRQC :
  716. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_5u21, 0);
  717. break;
  718. case MEP_OPERAND_CRQP :
  719. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_5u13, 0);
  720. break;
  721. case MEP_OPERAND_CSRN :
  722. print_keyword (cd, info, & mep_cgen_opval_h_csr, fields->f_csrn, 0|(1<<CGEN_OPERAND_VIRTUAL));
  723. break;
  724. case MEP_OPERAND_CSRN_IDX :
  725. print_normal (cd, info, fields->f_csrn, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  726. break;
  727. case MEP_OPERAND_DBG :
  728. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  729. break;
  730. case MEP_OPERAND_DEPC :
  731. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  732. break;
  733. case MEP_OPERAND_EPC :
  734. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  735. break;
  736. case MEP_OPERAND_EXC :
  737. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  738. break;
  739. case MEP_OPERAND_HI :
  740. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  741. break;
  742. case MEP_OPERAND_IMM16P0 :
  743. print_normal (cd, info, fields->f_ivc2_imm16p0, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  744. break;
  745. case MEP_OPERAND_IMM3P12 :
  746. print_normal (cd, info, fields->f_ivc2_3u12, 0, pc, length);
  747. break;
  748. case MEP_OPERAND_IMM3P25 :
  749. print_normal (cd, info, fields->f_ivc2_3u25, 0, pc, length);
  750. break;
  751. case MEP_OPERAND_IMM3P4 :
  752. print_normal (cd, info, fields->f_ivc2_3u4, 0, pc, length);
  753. break;
  754. case MEP_OPERAND_IMM3P5 :
  755. print_normal (cd, info, fields->f_ivc2_3u5, 0, pc, length);
  756. break;
  757. case MEP_OPERAND_IMM3P9 :
  758. print_normal (cd, info, fields->f_ivc2_3u9, 0, pc, length);
  759. break;
  760. case MEP_OPERAND_IMM4P10 :
  761. print_normal (cd, info, fields->f_ivc2_4u10, 0, pc, length);
  762. break;
  763. case MEP_OPERAND_IMM4P4 :
  764. print_normal (cd, info, fields->f_ivc2_4u4, 0, pc, length);
  765. break;
  766. case MEP_OPERAND_IMM4P8 :
  767. print_normal (cd, info, fields->f_ivc2_4u8, 0, pc, length);
  768. break;
  769. case MEP_OPERAND_IMM5P23 :
  770. print_normal (cd, info, fields->f_ivc2_5u23, 0, pc, length);
  771. break;
  772. case MEP_OPERAND_IMM5P3 :
  773. print_normal (cd, info, fields->f_ivc2_5u3, 0, pc, length);
  774. break;
  775. case MEP_OPERAND_IMM5P7 :
  776. print_normal (cd, info, fields->f_ivc2_5u7, 0, pc, length);
  777. break;
  778. case MEP_OPERAND_IMM5P8 :
  779. print_normal (cd, info, fields->f_ivc2_5u8, 0, pc, length);
  780. break;
  781. case MEP_OPERAND_IMM6P2 :
  782. print_normal (cd, info, fields->f_ivc2_6u2, 0, pc, length);
  783. break;
  784. case MEP_OPERAND_IMM6P6 :
  785. print_normal (cd, info, fields->f_ivc2_6u6, 0, pc, length);
  786. break;
  787. case MEP_OPERAND_IMM8P0 :
  788. print_normal (cd, info, fields->f_ivc2_8u0, 0, pc, length);
  789. break;
  790. case MEP_OPERAND_IMM8P20 :
  791. print_normal (cd, info, fields->f_ivc2_8u20, 0, pc, length);
  792. break;
  793. case MEP_OPERAND_IMM8P4 :
  794. print_normal (cd, info, fields->f_ivc2_8u4, 0, pc, length);
  795. break;
  796. case MEP_OPERAND_IVC_X_0_2 :
  797. print_normal (cd, info, fields->f_ivc2_2u0, 0, pc, length);
  798. break;
  799. case MEP_OPERAND_IVC_X_0_3 :
  800. print_normal (cd, info, fields->f_ivc2_3u0, 0, pc, length);
  801. break;
  802. case MEP_OPERAND_IVC_X_0_4 :
  803. print_normal (cd, info, fields->f_ivc2_4u0, 0, pc, length);
  804. break;
  805. case MEP_OPERAND_IVC_X_0_5 :
  806. print_normal (cd, info, fields->f_ivc2_5u0, 0, pc, length);
  807. break;
  808. case MEP_OPERAND_IVC_X_6_1 :
  809. print_normal (cd, info, fields->f_ivc2_1u6, 0, pc, length);
  810. break;
  811. case MEP_OPERAND_IVC_X_6_2 :
  812. print_normal (cd, info, fields->f_ivc2_2u6, 0, pc, length);
  813. break;
  814. case MEP_OPERAND_IVC_X_6_3 :
  815. print_normal (cd, info, fields->f_ivc2_3u6, 0, pc, length);
  816. break;
  817. case MEP_OPERAND_IVC2_ACC0_0 :
  818. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  819. break;
  820. case MEP_OPERAND_IVC2_ACC0_1 :
  821. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  822. break;
  823. case MEP_OPERAND_IVC2_ACC0_2 :
  824. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  825. break;
  826. case MEP_OPERAND_IVC2_ACC0_3 :
  827. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  828. break;
  829. case MEP_OPERAND_IVC2_ACC0_4 :
  830. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  831. break;
  832. case MEP_OPERAND_IVC2_ACC0_5 :
  833. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  834. break;
  835. case MEP_OPERAND_IVC2_ACC0_6 :
  836. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  837. break;
  838. case MEP_OPERAND_IVC2_ACC0_7 :
  839. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  840. break;
  841. case MEP_OPERAND_IVC2_ACC1_0 :
  842. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  843. break;
  844. case MEP_OPERAND_IVC2_ACC1_1 :
  845. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  846. break;
  847. case MEP_OPERAND_IVC2_ACC1_2 :
  848. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  849. break;
  850. case MEP_OPERAND_IVC2_ACC1_3 :
  851. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  852. break;
  853. case MEP_OPERAND_IVC2_ACC1_4 :
  854. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  855. break;
  856. case MEP_OPERAND_IVC2_ACC1_5 :
  857. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  858. break;
  859. case MEP_OPERAND_IVC2_ACC1_6 :
  860. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  861. break;
  862. case MEP_OPERAND_IVC2_ACC1_7 :
  863. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  864. break;
  865. case MEP_OPERAND_IVC2_CC :
  866. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  867. break;
  868. case MEP_OPERAND_IVC2_COFA0 :
  869. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  870. break;
  871. case MEP_OPERAND_IVC2_COFA1 :
  872. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  873. break;
  874. case MEP_OPERAND_IVC2_COFR0 :
  875. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  876. break;
  877. case MEP_OPERAND_IVC2_COFR1 :
  878. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  879. break;
  880. case MEP_OPERAND_IVC2_CSAR0 :
  881. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  882. break;
  883. case MEP_OPERAND_IVC2_CSAR1 :
  884. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, 0, 0);
  885. break;
  886. case MEP_OPERAND_IVC2C3CCRN :
  887. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, fields->f_ivc2_ccrn_c3, 0|(1<<CGEN_OPERAND_VIRTUAL));
  888. break;
  889. case MEP_OPERAND_IVC2CCRN :
  890. print_keyword (cd, info, & mep_cgen_opval_h_ccr_ivc2, fields->f_ivc2_ccrn, 0|(1<<CGEN_OPERAND_VIRTUAL));
  891. break;
  892. case MEP_OPERAND_IVC2CRN :
  893. print_keyword (cd, info, & mep_cgen_opval_h_cr64, fields->f_ivc2_crnx, 0|(1<<CGEN_OPERAND_VIRTUAL));
  894. break;
  895. case MEP_OPERAND_IVC2RM :
  896. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_ivc2_crm, 0);
  897. break;
  898. case MEP_OPERAND_LO :
  899. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  900. break;
  901. case MEP_OPERAND_LP :
  902. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  903. break;
  904. case MEP_OPERAND_MB0 :
  905. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  906. break;
  907. case MEP_OPERAND_MB1 :
  908. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  909. break;
  910. case MEP_OPERAND_ME0 :
  911. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  912. break;
  913. case MEP_OPERAND_ME1 :
  914. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  915. break;
  916. case MEP_OPERAND_NPC :
  917. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  918. break;
  919. case MEP_OPERAND_OPT :
  920. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  921. break;
  922. case MEP_OPERAND_PCABS24A2 :
  923. print_address (cd, info, fields->f_24u5a2n, 0|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  924. break;
  925. case MEP_OPERAND_PCREL12A2 :
  926. print_address (cd, info, fields->f_12s4a2, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  927. break;
  928. case MEP_OPERAND_PCREL17A2 :
  929. print_address (cd, info, fields->f_17s16a2, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  930. break;
  931. case MEP_OPERAND_PCREL24A2 :
  932. print_address (cd, info, fields->f_24s5a2n, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  933. break;
  934. case MEP_OPERAND_PCREL8A2 :
  935. print_address (cd, info, fields->f_8s8a2, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
  936. break;
  937. case MEP_OPERAND_PSW :
  938. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  939. break;
  940. case MEP_OPERAND_R0 :
  941. print_keyword (cd, info, & mep_cgen_opval_h_gpr, 0, 0);
  942. break;
  943. case MEP_OPERAND_R1 :
  944. print_keyword (cd, info, & mep_cgen_opval_h_gpr, 0, 0);
  945. break;
  946. case MEP_OPERAND_RL :
  947. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rl, 0);
  948. break;
  949. case MEP_OPERAND_RL5 :
  950. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rl5, 0);
  951. break;
  952. case MEP_OPERAND_RM :
  953. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rm, 0);
  954. break;
  955. case MEP_OPERAND_RMA :
  956. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rm, 0);
  957. break;
  958. case MEP_OPERAND_RN :
  959. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  960. break;
  961. case MEP_OPERAND_RN3 :
  962. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  963. break;
  964. case MEP_OPERAND_RN3C :
  965. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  966. break;
  967. case MEP_OPERAND_RN3L :
  968. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  969. break;
  970. case MEP_OPERAND_RN3S :
  971. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  972. break;
  973. case MEP_OPERAND_RN3UC :
  974. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  975. break;
  976. case MEP_OPERAND_RN3UL :
  977. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  978. break;
  979. case MEP_OPERAND_RN3US :
  980. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn3, 0);
  981. break;
  982. case MEP_OPERAND_RNC :
  983. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  984. break;
  985. case MEP_OPERAND_RNL :
  986. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  987. break;
  988. case MEP_OPERAND_RNS :
  989. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  990. break;
  991. case MEP_OPERAND_RNUC :
  992. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  993. break;
  994. case MEP_OPERAND_RNUL :
  995. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  996. break;
  997. case MEP_OPERAND_RNUS :
  998. print_keyword (cd, info, & mep_cgen_opval_h_gpr, fields->f_rn, 0);
  999. break;
  1000. case MEP_OPERAND_SAR :
  1001. print_keyword (cd, info, & mep_cgen_opval_h_csr, 0, 0);
  1002. break;
  1003. case MEP_OPERAND_SDISP16 :
  1004. print_normal (cd, info, fields->f_16s16, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1005. break;
  1006. case MEP_OPERAND_SIMM16 :
  1007. print_normal (cd, info, fields->f_16s16, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1008. break;
  1009. case MEP_OPERAND_SIMM16P0 :
  1010. print_normal (cd, info, fields->f_ivc2_simm16p0, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  1011. break;
  1012. case MEP_OPERAND_SIMM6 :
  1013. print_normal (cd, info, fields->f_6s8, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1014. break;
  1015. case MEP_OPERAND_SIMM8 :
  1016. print_normal (cd, info, fields->f_8s8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELOC_IMPLIES_OVERFLOW), pc, length);
  1017. break;
  1018. case MEP_OPERAND_SIMM8P0 :
  1019. print_normal (cd, info, fields->f_ivc2_8s0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1020. break;
  1021. case MEP_OPERAND_SIMM8P20 :
  1022. print_normal (cd, info, fields->f_ivc2_8s20, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1023. break;
  1024. case MEP_OPERAND_SIMM8P4 :
  1025. print_normal (cd, info, fields->f_ivc2_8s4, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1026. break;
  1027. case MEP_OPERAND_SP :
  1028. print_keyword (cd, info, & mep_cgen_opval_h_gpr, 0, 0);
  1029. break;
  1030. case MEP_OPERAND_SPR :
  1031. print_spreg (cd, info, & mep_cgen_opval_h_gpr, 0, 0);
  1032. break;
  1033. case MEP_OPERAND_TP :
  1034. print_keyword (cd, info, & mep_cgen_opval_h_gpr, 0, 0);
  1035. break;
  1036. case MEP_OPERAND_TPR :
  1037. print_tpreg (cd, info, & mep_cgen_opval_h_gpr, 0, 0);
  1038. break;
  1039. case MEP_OPERAND_UDISP2 :
  1040. print_normal (cd, info, fields->f_2u6, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1041. break;
  1042. case MEP_OPERAND_UDISP7 :
  1043. print_normal (cd, info, fields->f_7u9, 0, pc, length);
  1044. break;
  1045. case MEP_OPERAND_UDISP7A2 :
  1046. print_normal (cd, info, fields->f_7u9a2, 0, pc, length);
  1047. break;
  1048. case MEP_OPERAND_UDISP7A4 :
  1049. print_normal (cd, info, fields->f_7u9a4, 0, pc, length);
  1050. break;
  1051. case MEP_OPERAND_UIMM16 :
  1052. print_normal (cd, info, fields->f_16u16, 0, pc, length);
  1053. break;
  1054. case MEP_OPERAND_UIMM2 :
  1055. print_normal (cd, info, fields->f_2u10, 0, pc, length);
  1056. break;
  1057. case MEP_OPERAND_UIMM24 :
  1058. print_normal (cd, info, fields->f_24u8n, 0|(1<<CGEN_OPERAND_VIRTUAL), pc, length);
  1059. break;
  1060. case MEP_OPERAND_UIMM3 :
  1061. print_normal (cd, info, fields->f_3u5, 0, pc, length);
  1062. break;
  1063. case MEP_OPERAND_UIMM4 :
  1064. print_normal (cd, info, fields->f_4u8, 0, pc, length);
  1065. break;
  1066. case MEP_OPERAND_UIMM5 :
  1067. print_normal (cd, info, fields->f_5u8, 0, pc, length);
  1068. break;
  1069. case MEP_OPERAND_UIMM7A4 :
  1070. print_normal (cd, info, fields->f_7u9a4, 0, pc, length);
  1071. break;
  1072. case MEP_OPERAND_ZERO :
  1073. print_normal (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
  1074. break;
  1075. default :
  1076. /* xgettext:c-format */
  1077. opcodes_error_handler
  1078. (_("internal error: unrecognized field %d while printing insn"),
  1079. opindex);
  1080. abort ();
  1081. }
  1082. }
  1083. cgen_print_fn * const mep_cgen_print_handlers[] =
  1084. {
  1085. print_insn_normal,
  1086. };
  1087. void
  1088. mep_cgen_init_dis (CGEN_CPU_DESC cd)
  1089. {
  1090. mep_cgen_init_opcode_table (cd);
  1091. mep_cgen_init_ibld_table (cd);
  1092. cd->print_handlers = & mep_cgen_print_handlers[0];
  1093. cd->print_operand = mep_cgen_print_operand;
  1094. }
  1095. /* Default print handler. */
  1096. static void
  1097. print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1098. void *dis_info,
  1099. long value,
  1100. unsigned int attrs,
  1101. bfd_vma pc ATTRIBUTE_UNUSED,
  1102. int length ATTRIBUTE_UNUSED)
  1103. {
  1104. disassemble_info *info = (disassemble_info *) dis_info;
  1105. /* Print the operand as directed by the attributes. */
  1106. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  1107. ; /* nothing to do */
  1108. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  1109. (*info->fprintf_func) (info->stream, "%ld", value);
  1110. else
  1111. (*info->fprintf_func) (info->stream, "0x%lx", value);
  1112. }
  1113. /* Default address handler. */
  1114. static void
  1115. print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1116. void *dis_info,
  1117. bfd_vma value,
  1118. unsigned int attrs,
  1119. bfd_vma pc ATTRIBUTE_UNUSED,
  1120. int length ATTRIBUTE_UNUSED)
  1121. {
  1122. disassemble_info *info = (disassemble_info *) dis_info;
  1123. /* Print the operand as directed by the attributes. */
  1124. if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
  1125. ; /* Nothing to do. */
  1126. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
  1127. (*info->print_address_func) (value, info);
  1128. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
  1129. (*info->print_address_func) (value, info);
  1130. else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
  1131. (*info->fprintf_func) (info->stream, "%ld", (long) value);
  1132. else
  1133. (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
  1134. }
  1135. /* Keyword print handler. */
  1136. static void
  1137. print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1138. void *dis_info,
  1139. CGEN_KEYWORD *keyword_table,
  1140. long value,
  1141. unsigned int attrs ATTRIBUTE_UNUSED)
  1142. {
  1143. disassemble_info *info = (disassemble_info *) dis_info;
  1144. const CGEN_KEYWORD_ENTRY *ke;
  1145. ke = cgen_keyword_lookup_value (keyword_table, value);
  1146. if (ke != NULL)
  1147. (*info->fprintf_func) (info->stream, "%s", ke->name);
  1148. else
  1149. (*info->fprintf_func) (info->stream, "???");
  1150. }
  1151. /* Default insn printer.
  1152. DIS_INFO is defined as `void *' so the disassembler needn't know anything
  1153. about disassemble_info. */
  1154. static void
  1155. print_insn_normal (CGEN_CPU_DESC cd,
  1156. void *dis_info,
  1157. const CGEN_INSN *insn,
  1158. CGEN_FIELDS *fields,
  1159. bfd_vma pc,
  1160. int length)
  1161. {
  1162. const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
  1163. disassemble_info *info = (disassemble_info *) dis_info;
  1164. const CGEN_SYNTAX_CHAR_TYPE *syn;
  1165. CGEN_INIT_PRINT (cd);
  1166. for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
  1167. {
  1168. if (CGEN_SYNTAX_MNEMONIC_P (*syn))
  1169. {
  1170. (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
  1171. continue;
  1172. }
  1173. if (CGEN_SYNTAX_CHAR_P (*syn))
  1174. {
  1175. (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
  1176. continue;
  1177. }
  1178. /* We have an operand. */
  1179. mep_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
  1180. fields, CGEN_INSN_ATTRS (insn), pc, length);
  1181. }
  1182. }
  1183. /* Subroutine of print_insn. Reads an insn into the given buffers and updates
  1184. the extract info.
  1185. Returns 0 if all is well, non-zero otherwise. */
  1186. static int
  1187. read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  1188. bfd_vma pc,
  1189. disassemble_info *info,
  1190. bfd_byte *buf,
  1191. int buflen,
  1192. CGEN_EXTRACT_INFO *ex_info,
  1193. unsigned long *insn_value)
  1194. {
  1195. int status = (*info->read_memory_func) (pc, buf, buflen, info);
  1196. if (status != 0)
  1197. {
  1198. (*info->memory_error_func) (status, pc, info);
  1199. return -1;
  1200. }
  1201. ex_info->dis_info = info;
  1202. ex_info->valid = (1 << buflen) - 1;
  1203. ex_info->insn_bytes = buf;
  1204. *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
  1205. return 0;
  1206. }
  1207. /* Utility to print an insn.
  1208. BUF is the base part of the insn, target byte order, BUFLEN bytes long.
  1209. The result is the size of the insn in bytes or zero for an unknown insn
  1210. or -1 if an error occurs fetching data (memory_error_func will have
  1211. been called). */
  1212. static int
  1213. print_insn (CGEN_CPU_DESC cd,
  1214. bfd_vma pc,
  1215. disassemble_info *info,
  1216. bfd_byte *buf,
  1217. unsigned int buflen)
  1218. {
  1219. CGEN_INSN_INT insn_value;
  1220. const CGEN_INSN_LIST *insn_list;
  1221. CGEN_EXTRACT_INFO ex_info;
  1222. int basesize;
  1223. /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
  1224. basesize = cd->base_insn_bitsize < buflen * 8 ?
  1225. cd->base_insn_bitsize : buflen * 8;
  1226. insn_value = cgen_get_insn_value (cd, buf, basesize, cd->insn_endian);
  1227. /* Fill in ex_info fields like read_insn would. Don't actually call
  1228. read_insn, since the incoming buffer is already read (and possibly
  1229. modified a la m32r). */
  1230. ex_info.valid = (1 << buflen) - 1;
  1231. ex_info.dis_info = info;
  1232. ex_info.insn_bytes = buf;
  1233. /* The instructions are stored in hash lists.
  1234. Pick the first one and keep trying until we find the right one. */
  1235. insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
  1236. while (insn_list != NULL)
  1237. {
  1238. const CGEN_INSN *insn = insn_list->insn;
  1239. CGEN_FIELDS fields;
  1240. int length;
  1241. unsigned long insn_value_cropped;
  1242. #ifdef CGEN_VALIDATE_INSN_SUPPORTED
  1243. /* Not needed as insn shouldn't be in hash lists if not supported. */
  1244. /* Supported by this cpu? */
  1245. if (! mep_cgen_insn_supported (cd, insn))
  1246. {
  1247. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  1248. continue;
  1249. }
  1250. #endif
  1251. /* Basic bit mask must be correct. */
  1252. /* ??? May wish to allow target to defer this check until the extract
  1253. handler. */
  1254. /* Base size may exceed this instruction's size. Extract the
  1255. relevant part from the buffer. */
  1256. if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
  1257. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  1258. insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
  1259. info->endian == BFD_ENDIAN_BIG);
  1260. else
  1261. insn_value_cropped = insn_value;
  1262. if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
  1263. == CGEN_INSN_BASE_VALUE (insn))
  1264. {
  1265. /* Printing is handled in two passes. The first pass parses the
  1266. machine insn and extracts the fields. The second pass prints
  1267. them. */
  1268. /* Make sure the entire insn is loaded into insn_value, if it
  1269. can fit. */
  1270. if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
  1271. (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
  1272. {
  1273. unsigned long full_insn_value;
  1274. int rc = read_insn (cd, pc, info, buf,
  1275. CGEN_INSN_BITSIZE (insn) / 8,
  1276. & ex_info, & full_insn_value);
  1277. if (rc != 0)
  1278. return rc;
  1279. length = CGEN_EXTRACT_FN (cd, insn)
  1280. (cd, insn, &ex_info, full_insn_value, &fields, pc);
  1281. }
  1282. else
  1283. length = CGEN_EXTRACT_FN (cd, insn)
  1284. (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
  1285. /* Length < 0 -> error. */
  1286. if (length < 0)
  1287. return length;
  1288. if (length > 0)
  1289. {
  1290. CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
  1291. /* Length is in bits, result is in bytes. */
  1292. return length / 8;
  1293. }
  1294. }
  1295. insn_list = CGEN_DIS_NEXT_INSN (insn_list);
  1296. }
  1297. return 0;
  1298. }
  1299. /* Default value for CGEN_PRINT_INSN.
  1300. The result is the size of the insn in bytes or zero for an unknown insn
  1301. or -1 if an error occured fetching bytes. */
  1302. #ifndef CGEN_PRINT_INSN
  1303. #define CGEN_PRINT_INSN default_print_insn
  1304. #endif
  1305. static int
  1306. default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
  1307. {
  1308. bfd_byte buf[CGEN_MAX_INSN_SIZE];
  1309. int buflen;
  1310. int status;
  1311. /* Attempt to read the base part of the insn. */
  1312. buflen = cd->base_insn_bitsize / 8;
  1313. status = (*info->read_memory_func) (pc, buf, buflen, info);
  1314. /* Try again with the minimum part, if min < base. */
  1315. if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
  1316. {
  1317. buflen = cd->min_insn_bitsize / 8;
  1318. status = (*info->read_memory_func) (pc, buf, buflen, info);
  1319. }
  1320. if (status != 0)
  1321. {
  1322. (*info->memory_error_func) (status, pc, info);
  1323. return -1;
  1324. }
  1325. return print_insn (cd, pc, info, buf, buflen);
  1326. }
  1327. /* Main entry point.
  1328. Print one instruction from PC on INFO->STREAM.
  1329. Return the size of the instruction (in bytes). */
  1330. typedef struct cpu_desc_list
  1331. {
  1332. struct cpu_desc_list *next;
  1333. CGEN_BITSET *isa;
  1334. int mach;
  1335. int endian;
  1336. int insn_endian;
  1337. CGEN_CPU_DESC cd;
  1338. } cpu_desc_list;
  1339. int
  1340. print_insn_mep (bfd_vma pc, disassemble_info *info)
  1341. {
  1342. static cpu_desc_list *cd_list = 0;
  1343. cpu_desc_list *cl = 0;
  1344. static CGEN_CPU_DESC cd = 0;
  1345. static CGEN_BITSET *prev_isa;
  1346. static int prev_mach;
  1347. static int prev_endian;
  1348. static int prev_insn_endian;
  1349. int length;
  1350. CGEN_BITSET *isa;
  1351. int mach;
  1352. int endian = (info->endian == BFD_ENDIAN_BIG
  1353. ? CGEN_ENDIAN_BIG
  1354. : CGEN_ENDIAN_LITTLE);
  1355. int insn_endian = (info->endian_code == BFD_ENDIAN_BIG
  1356. ? CGEN_ENDIAN_BIG
  1357. : CGEN_ENDIAN_LITTLE);
  1358. enum bfd_architecture arch;
  1359. /* ??? gdb will set mach but leave the architecture as "unknown" */
  1360. #ifndef CGEN_BFD_ARCH
  1361. #define CGEN_BFD_ARCH bfd_arch_mep
  1362. #endif
  1363. arch = info->arch;
  1364. if (arch == bfd_arch_unknown)
  1365. arch = CGEN_BFD_ARCH;
  1366. /* There's no standard way to compute the machine or isa number
  1367. so we leave it to the target. */
  1368. #ifdef CGEN_COMPUTE_MACH
  1369. mach = CGEN_COMPUTE_MACH (info);
  1370. #else
  1371. mach = info->mach;
  1372. #endif
  1373. #ifdef CGEN_COMPUTE_ISA
  1374. {
  1375. static CGEN_BITSET *permanent_isa;
  1376. if (!permanent_isa)
  1377. permanent_isa = cgen_bitset_create (MAX_ISAS);
  1378. isa = permanent_isa;
  1379. cgen_bitset_clear (isa);
  1380. cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
  1381. }
  1382. #else
  1383. isa = info->private_data;
  1384. #endif
  1385. /* If we've switched cpu's, try to find a handle we've used before */
  1386. if (cd
  1387. && (cgen_bitset_compare (isa, prev_isa) != 0
  1388. || mach != prev_mach
  1389. || endian != prev_endian))
  1390. {
  1391. cd = 0;
  1392. for (cl = cd_list; cl; cl = cl->next)
  1393. {
  1394. if (cgen_bitset_compare (cl->isa, isa) == 0 &&
  1395. cl->mach == mach &&
  1396. cl->endian == endian)
  1397. {
  1398. cd = cl->cd;
  1399. prev_isa = cd->isas;
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. /* If we haven't initialized yet, initialize the opcode table. */
  1405. if (! cd)
  1406. {
  1407. const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
  1408. const char *mach_name;
  1409. if (!arch_type)
  1410. abort ();
  1411. mach_name = arch_type->printable_name;
  1412. prev_isa = cgen_bitset_copy (isa);
  1413. prev_mach = mach;
  1414. prev_endian = endian;
  1415. prev_insn_endian = insn_endian;
  1416. cd = mep_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
  1417. CGEN_CPU_OPEN_BFDMACH, mach_name,
  1418. CGEN_CPU_OPEN_ENDIAN, prev_endian,
  1419. CGEN_CPU_OPEN_INSN_ENDIAN, prev_insn_endian,
  1420. CGEN_CPU_OPEN_END);
  1421. if (!cd)
  1422. abort ();
  1423. /* Save this away for future reference. */
  1424. cl = xmalloc (sizeof (struct cpu_desc_list));
  1425. cl->cd = cd;
  1426. cl->isa = prev_isa;
  1427. cl->mach = mach;
  1428. cl->endian = endian;
  1429. cl->next = cd_list;
  1430. cd_list = cl;
  1431. mep_cgen_init_dis (cd);
  1432. }
  1433. /* We try to have as much common code as possible.
  1434. But at this point some targets need to take over. */
  1435. /* ??? Some targets may need a hook elsewhere. Try to avoid this,
  1436. but if not possible try to move this hook elsewhere rather than
  1437. have two hooks. */
  1438. length = CGEN_PRINT_INSN (cd, pc, info);
  1439. if (length > 0)
  1440. return length;
  1441. if (length < 0)
  1442. return -1;
  1443. (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
  1444. return cd->default_insn_bitsize / 8;
  1445. }