68020db.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <mach.h>
  13. /*
  14. * 68020-specific debugger interface
  15. */
  16. static char *m68020excep(Map*, Rgetter);
  17. static int m68020foll(Map*, uint64_t, Rgetter, uint64_t*);
  18. static int m68020inst(Map*, uint64_t, char, char*, int);
  19. static int m68020das(Map*, uint64_t, char*, int);
  20. static int m68020instlen(Map*, uint64_t);
  21. Machdata m68020mach =
  22. {
  23. {0x48,0x48,0,0}, /* break point #0 instr. */
  24. 2, /* size of break point instr. */
  25. beswab, /* convert short to local byte order */
  26. beswal, /* convert long to local byte order */
  27. beswav, /* convert vlong to local byte order */
  28. cisctrace, /* C traceback */
  29. ciscframe, /* frame finder */
  30. m68020excep, /* print exception */
  31. 0, /* breakpoint fixup */
  32. beieeesftos,
  33. beieeedftos,
  34. m68020foll, /* follow-set calculation */
  35. m68020inst, /* print instruction */
  36. m68020das, /* dissembler */
  37. m68020instlen, /* instruction size */
  38. };
  39. /*
  40. * 68020 exception frames
  41. */
  42. #define BPTTRAP 4 /* breakpoint gives illegal inst */
  43. static char * excep[] = {
  44. [2] "bus error",
  45. [3] "address error",
  46. [4] "illegal instruction",
  47. [5] "zero divide",
  48. [6] "CHK",
  49. [7] "TRAP",
  50. [8] "privilege violation",
  51. [9] "Trace",
  52. [10] "line 1010",
  53. [11] "line 1011",
  54. [13] "coprocessor protocol violation",
  55. [24] "spurious",
  56. [25] "incon",
  57. [26] "tac",
  58. [27] "auto 3",
  59. [28] "clock",
  60. [29] "auto 5",
  61. [30] "parity",
  62. [31] "mouse",
  63. [32] "system call",
  64. [33] "system call 1",
  65. [48] "FPCP branch",
  66. [49] "FPCP inexact",
  67. [50] "FPCP zero div",
  68. [51] "FPCP underflow",
  69. [52] "FPCP operand err",
  70. [53] "FPCP overflow",
  71. [54] "FPCP signal NAN",
  72. };
  73. static int m68020vec;
  74. static
  75. struct ftype{
  76. int16_t fmt;
  77. int16_t len;
  78. char *name;
  79. } ftype[] = { /* section 6.5.7 page 6-24 */
  80. { 0, 4*2, "Short Format" },
  81. { 1, 4*2, "Throwaway" },
  82. { 2, 6*2, "Instruction Exception" },
  83. { 3, 6*2, "MC68040 Floating Point Exception" },
  84. { 8, 29*2, "MC68010 Bus Fault" },
  85. { 7, 30*2, "MC68040 Bus Fault" },
  86. { 9, 10*2, "Coprocessor mid-Instruction" },
  87. { 10, 16*2, "MC68020 Short Bus Fault" },
  88. { 11, 46*2, "MC68020 Long Bus Fault" },
  89. { 0, 0, 0 }
  90. };
  91. static int
  92. m68020ufix(Map *map)
  93. {
  94. struct ftype *ft;
  95. int i, size, vec;
  96. uint32_t efl[2];
  97. uint8_t *ef=(uint8_t*)efl;
  98. uint32_t l;
  99. uint64_t stktop;
  100. int16_t fvo;
  101. /* The kernel proc pointer on a 68020 is always
  102. * at #8xxxxxxx; on the 68040 NeXT, the address
  103. * is always #04xxxxxx. the sun3 port at sydney
  104. * uses 0xf8xxxxxx to 0xffxxxxxx.
  105. */
  106. m68020vec = 0;
  107. if (get4(map, mach->kbase, (&l)) < 0)
  108. return -1;
  109. if ((l&0xfc000000) == 0x04000000) /* if NeXT */
  110. size = 30*2;
  111. else
  112. size = 46*2; /* 68020 */
  113. USED(size);
  114. stktop = mach->kbase+mach->pgsize;
  115. for(i=3; i<100; i++){
  116. if (get1(map, stktop-i*4, (uint8_t*)&l, 4)< 0)
  117. return -1;
  118. if(machdata->swal(l) == 0xBADC0C0A){
  119. if (get1(map, stktop-(i-1)*4, (uint8_t *)&efl[0], 4) < 0)
  120. return -1;
  121. if (get1(map, stktop-(i-2)*4, (uint8_t *)&efl[1], 4) < 0)
  122. return -1;
  123. fvo = (ef[6]<<8)|ef[7];
  124. vec = fvo & 0xfff;
  125. vec >>= 2;
  126. if(vec >= 256)
  127. continue;
  128. for(ft=ftype; ft->name; ft++) {
  129. if(ft->fmt == ((fvo>>12) & 0xF)){
  130. m68020vec = vec;
  131. return 1;
  132. }
  133. }
  134. break;
  135. }
  136. }
  137. return -1;
  138. }
  139. static char *
  140. m68020excep(Map *map, Rgetter rget)
  141. {
  142. uint64_t pc;
  143. uint8_t buf[4];
  144. if (m68020ufix(map) < 0)
  145. return "bad exception frame";
  146. if(excep[m68020vec] == 0)
  147. return "bad exeception type";
  148. if(m68020vec == BPTTRAP) {
  149. pc = (*rget)(map, "PC");
  150. if (get1(map, pc, buf, machdata->bpsize) > 0)
  151. if(memcmp(buf, machdata->bpinst, machdata->bpsize) == 0)
  152. return "breakpoint";
  153. }
  154. return excep[m68020vec];
  155. }
  156. /* 68020 Disassembler and related functions */
  157. /*
  158. not supported: cpBcc, cpDBcc, cpGEN, cpScc, cpTRAPcc, cpRESTORE, cpSAVE
  159. opcode: 1 1 1 1 1 1
  160. 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  161. %y - register number x x x
  162. %f - trap vector x x x
  163. %e - destination eff addr x x x x x x
  164. %p - conditional predicate x x x x x x
  165. %s - size code x x
  166. %C - cache code x x
  167. %E - source eff addr. x x x x x x
  168. %d - direction bit x
  169. %c - condition code x x x x
  170. %x - register number x x x
  171. %b - shift count x x x
  172. %q - daffy 3-bit quick operand or shift count x x x
  173. %i - immediate operand <varies>
  174. %t - offset(PC) <varies>
  175. word 1: 1 1 1 1 1 1
  176. 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  177. %a - register number x x x
  178. %w - bit field width x x x x x
  179. %L - MMU function code (SFC/DFC/D%a/#[0-3]) x x x x x
  180. %P - conditional predicate x x x x x x
  181. %k - k factor x x x x x x x
  182. %m - register mask x x x x x x x x
  183. %N - control register id x x x x x x x x x x x x
  184. %j - (Dq != Dr) ? Dq:Dr : Dr x x x x x x
  185. %K - dynamic k register x x x
  186. %h - register number x x x
  187. %I - MMU function code mask x x x x
  188. %o - bit field offset x x x x x
  189. %u - register number x x x
  190. %D - float dest reg x x x
  191. %F - (fdr==fsr) ? "F%D" :"F%B,F%D" x x x x x x
  192. %S - float source type x x x
  193. %B - float source register x x x
  194. %Z - ATC level number x x x
  195. %H - MMU register x x x x
  196. %r - register type/number x x x x
  197. word 2: 1 1 1 1 1 1
  198. 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  199. %A - register number x x x
  200. %U - register number x x x
  201. %R - register type,number x x x x
  202. -----------------------------------------------------------------------------
  203. %a - register [word 1: 0-2]
  204. %c - condition code [opcode: 8-11]
  205. %d - direction [opcode: 8]
  206. %e - destination effective address [opcode: 0-5]
  207. %f - trap vector [opcode: 0-3]
  208. %h - register [word 1: 5-7]
  209. %i - immediate operand (1, 2, or 4 bytes)
  210. %j - Dq:Dr if Dq != Dr; else Dr => Dr [word 1: 0-2] Dq [word 1: 12-14]
  211. %k - k factor [word 1: 0-6]
  212. %m - register mask [word 1: 0-7]
  213. %o - bit field offset [word 1: 6-10]
  214. %p - conditional predicate [opcode: 0-5]
  215. %q - daffy 3-bit quick operand [opcode: 9-11]
  216. %r - register type, [word 1: 15], register [word 1: 12-14]
  217. %s - size [opcode: 6-7]
  218. %t - offset beyond pc (text address) (2 or 4 bytes)
  219. %u - register [word 1: 6-8]
  220. %w - bit field width [word 1: 0-4]
  221. %x - register [opcode: 9-11]
  222. %y - register [opcode: 0-2]
  223. %A - register [word 2: 0-2]
  224. %B - float source register [word 1: 10-12]
  225. %C - cache identifier [opcode: 6-7] (IC, DC, or BC)
  226. %D - float dest reg [word 1: 7-9]
  227. %E - dest effective address [opcode: 6-11]
  228. %F - float dest reg == float src reg => "F%D"; else "F%B,F%D"
  229. %H - MMU reg [word 1: 10-13] (see above & p 4-53/54)
  230. %I - MMU function code mask [word 1: 5-8]
  231. %K - dynamic k factor register [word 1: 4-6]
  232. %L - MMU function code [word 1: 0-4] (SFC, DFC, D%a, or #[0-3])
  233. %N - control register [word 1: 0-11]
  234. %P - conditional predicate [word 1: 0-5]
  235. %R - register type, [word 2: 15], register [word 2: 12-14]
  236. %S - float source type code [word 1: 10-12]
  237. %U - register [word 2: 6-8]
  238. %Z - ATC level number [word 1: 10-12]
  239. %1 - Special case: EA as second operand
  240. */
  241. /* Operand classes */
  242. enum {
  243. EAPI = 1, /* extended address: pre decrement only */
  244. EACA, /* extended address: control alterable */
  245. EACAD, /* extended address: control alterable or Dreg */
  246. EACAPI, /* extended address: control alterable or post-incr */
  247. EACAPD, /* extended address: control alterable or pre-decr */
  248. EAMA, /* extended address: memory alterable */
  249. EADA, /* extended address: data alterable */
  250. EAA, /* extended address: alterable */
  251. EAC, /* extended address: control addressing */
  252. EACPI, /* extended address: control addressing or post-incr */
  253. EACD, /* extended address: control addressing or Dreg */
  254. EAD, /* extended address: data addressing */
  255. EAM, /* extended address: memory addressing */
  256. EAM_B, /* EAM with byte immediate data */
  257. EADI, /* extended address: data addressing or immediate */
  258. EADI_L, /* EADI with long immediate data */
  259. EADI_W, /* EADI with word immediate data */
  260. EAALL, /* extended address: all modes */
  261. EAALL_L, /* EAALL with long immediate data */
  262. EAALL_W, /* EAALL with word immediate data */
  263. EAALL_B, /* EAALL with byte immediate date */
  264. /* special codes not directly used for validation */
  265. EAFLT, /* extended address: EADI for B, W, L, or S; else EAM */
  266. EADDA, /* destination extended address: EADA */
  267. BREAC, /* EAC operand for JMP or CALL */
  268. OP8, /* low 8 bits of op word */
  269. I8, /* low 8-bits of first extension word */
  270. I16, /* 16 bits in first extension word */
  271. I32, /* 32 bits in first and second extension words */
  272. IV, /* 8, 16 or 32 bit data in first & 2nd extension words */
  273. C16, /* CAS2 16 bit immediate with bits 9-11 & 3-5 zero */
  274. BR8, /* 8 bits in op word or 16 or 32 bits in extension words
  275. branch instruction format (p. 2-25) */
  276. BR16, /* 16-bit branch displacement */
  277. BR32, /* 32-bit branch displacement */
  278. STACK, /* return PC on stack - follow set only */
  279. };
  280. /* validation bit masks for various EA classes */
  281. enum {
  282. Dn = 0x0001, /* Data register */
  283. An = 0x0002, /* Address register */
  284. Ind = 0x0004, /* Address register indirect */
  285. Pinc = 0x0008, /* Address register indirect post-increment */
  286. Pdec = 0x0010, /* Address register indirect pre-decrement */
  287. Bdisp = 0x0020, /* Base/Displacement in all its forms */
  288. PCrel = 0x0040, /* PC relative addressing in all its forms */
  289. Imm = 0x0080, /* Immediate data */
  290. Abs = 0x0100, /* Absolute */
  291. };
  292. /* EA validation table indexed by operand class number */
  293. static int16_t validea[] =
  294. {
  295. 0, /* none */
  296. Pdec, /* EAPI */
  297. Abs|Bdisp|Ind, /* EACA */
  298. Abs|Bdisp|Ind|Dn, /* EACAD */
  299. Abs|Bdisp|Pinc|Ind, /* EACAPI */
  300. Abs|Bdisp|Pdec|Ind, /* EACAPD */
  301. Abs|Bdisp|Pdec|Pinc|Ind, /* EAMA */
  302. Abs|Bdisp|Pdec|Pinc|Ind|Dn, /* EADA */
  303. Abs|Bdisp|Pdec|Pinc|Ind|An|Dn, /* EAA */
  304. Abs|PCrel|Bdisp|Ind, /* EAC */
  305. Abs|PCrel|Bdisp|Pinc|Ind, /* EACPI */
  306. Abs|PCrel|Bdisp|Ind|Dn, /* EACD */
  307. Abs|PCrel|Bdisp|Pdec|Pinc|Ind|Dn, /* EAD */
  308. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind, /* EAM */
  309. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind, /* EAM_B */
  310. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|Dn, /* EADI */
  311. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|Dn, /* EADI_L */
  312. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|Dn, /* EADI_W */
  313. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|An|Dn, /* EAALL */
  314. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|An|Dn, /* EAALL_L */
  315. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|An|Dn, /* EAALL_W */
  316. Abs|Imm|PCrel|Bdisp|Pdec|Pinc|Ind|An|Dn, /* EAALL_B */
  317. };
  318. /* EA types */
  319. enum
  320. {
  321. Dreg, /* Dn */
  322. Areg, /* An */
  323. AInd, /* (An) */
  324. APdec, /* -(An) */
  325. APinc, /* (An)+ */
  326. ADisp, /* Displacement beyond (An) */
  327. BXD, /* Base, Index, Displacement */
  328. PDisp, /* Displacement beyond PC */
  329. PXD, /* PC, Index, Displacement */
  330. ABS, /* absolute */
  331. IMM, /* immediate */
  332. IREAL, /* single precision real immediate */
  333. IEXT, /* extended precision real immediate */
  334. IPACK, /* packed real immediate */
  335. IDBL, /* double precision real immediate */
  336. };
  337. typedef struct optable Optable;
  338. typedef struct operand Operand;
  339. typedef struct inst Inst;
  340. struct optable
  341. {
  342. uint16_t opcode;
  343. uint16_t mask0;
  344. uint16_t op2;
  345. uint16_t mask1;
  346. char opdata[2];
  347. char *format;
  348. };
  349. struct operand
  350. {
  351. int eatype;
  352. int16_t ext;
  353. union {
  354. int32_t immediate; /* sign-extended integer byte/word/long */
  355. struct { /* index mode displacements */
  356. int32_t disp;
  357. int32_t outer;
  358. };
  359. char floater[24]; /* floating point immediates */
  360. };
  361. };
  362. struct inst
  363. {
  364. int n; /* # bytes in instruction */
  365. uint64_t addr; /* addr of start of instruction */
  366. uint16_t raw[4+12]; /* longest instruction: 24 byte packed immediate */
  367. Operand and[2];
  368. char *end; /* end of print buffer */
  369. char *curr; /* current fill point in buffer */
  370. char *errmsg;
  371. };
  372. /* class 0: bit field, MOVEP & immediate instructions */
  373. static Optable t0[] = {
  374. { 0x003c, 0xffff, 0x0000, 0xff00, {I8}, "ORB %i,CCR" },
  375. { 0x007c, 0xffff, 0x0000, 0x0000, {I16}, "ORW %i,SR" },
  376. { 0x023c, 0xffff, 0x0000, 0xff00, {I8}, "ANDB %i,CCR" },
  377. { 0x027c, 0xffff, 0x0000, 0x0000, {I16}, "ANDW %i,SR" },
  378. { 0x0a3c, 0xffff, 0x0000, 0xff00, {I8}, "EORB %i,CCR" },
  379. { 0x0a7c, 0xffff, 0x0000, 0x0000, {I16}, "EORW %i,SR" },
  380. { 0x0cfc, 0xffff, 0x0000, 0x0000, {C16,C16}, "CAS2W R%a:R%A,R%u:R%U,(%r):(%R)"} ,
  381. { 0x0efc, 0xffff, 0x0000, 0x0000, {C16,C16}, "CAS2L R%a:R%A,R%u:R%U,(%r):(%R)"} ,
  382. { 0x06c0, 0xfff8, 0x0000, 0x0000, {0}, "RTM R%y" },
  383. { 0x06c8, 0xfff8, 0x0000, 0x0000, {0}, "RTM A%y" },
  384. { 0x0800, 0xfff8, 0x0000, 0x0000, {I16}, "BTSTL %i,R%y" },
  385. { 0x0840, 0xfff8, 0x0000, 0x0000, {I16}, "BCHGL %i,R%y" },
  386. { 0x0880, 0xfff8, 0x0000, 0x0000, {I16}, "BCLRL %i,R%y" },
  387. { 0x00c0, 0xffc0, 0x0000, 0x0fff, {EAC}, "CMP2B %e,%r" },
  388. { 0x00c0, 0xffc0, 0x0800, 0x0fff, {EAC}, "CHK2B %e,%r" },
  389. { 0x02c0, 0xffc0, 0x0000, 0x0fff, {EAC}, "CMP2W %e,%r" },
  390. { 0x02c0, 0xffc0, 0x0800, 0x0fff, {EAC}, "CHK2W %e,%r" },
  391. { 0x04c0, 0xffc0, 0x0000, 0x0fff, {EAC}, "CMP2L %e,%r" },
  392. { 0x04c0, 0xffc0, 0x0800, 0x0fff, {EAC}, "CHK2L %e,%r" },
  393. { 0x06c0, 0xffc0, 0x0000, 0x0000, {I16, BREAC}, "CALLM %i,%e" },
  394. { 0x0800, 0xffc0, 0x0000, 0x0000, {I16, EAD}, "BTSTB %i,%e" },
  395. { 0x0840, 0xffc0, 0x0000, 0x0000, {I16, EADA}, "BCHG %i,%e" },
  396. { 0x0880, 0xffc0, 0x0000, 0x0000, {I16, EADA}, "BCLR %i,%e" },
  397. { 0x08c0, 0xffc0, 0x0000, 0x0000, {I16, EADA}, "BSET %i,%e" },
  398. { 0x0ac0, 0xffc0, 0x0000, 0xfe38, {EAMA}, "CASB R%a,R%u,%e" },
  399. { 0x0cc0, 0xffc0, 0x0000, 0xfe38, {EAMA}, "CASW R%a,R%u,%e" },
  400. { 0x0ec0, 0xffc0, 0x0000, 0xfe38, {EAMA}, "CASL R%a,R%u,%e" },
  401. { 0x0000, 0xff00, 0x0000, 0x0000, {IV, EADA}, "OR%s %i,%e" },
  402. { 0x0200, 0xff00, 0x0000, 0x0000, {IV, EADA}, "AND%s %i,%e" },
  403. { 0x0400, 0xff00, 0x0000, 0x0000, {IV, EADA}, "SUB%s %i,%e" },
  404. { 0x0600, 0xff00, 0x0000, 0x0000, {IV, EADA}, "ADD%s %i,%e" },
  405. { 0x0a00, 0xff00, 0x0000, 0x0000, {IV, EADA}, "EOR%s %i,%e" },
  406. { 0x0c00, 0xff00, 0x0000, 0x0000, {IV, EAD}, "CMP%s %i,%e" },
  407. { 0x0e00, 0xff00, 0x0000, 0x0800, {EAMA}, "MOVES%s %e,%r" },
  408. { 0x0e00, 0xff00, 0x0800, 0x0800, {EAMA}, "MOVES%s %r,%e" },
  409. { 0x0108, 0xf1f8, 0x0000, 0x0000, {I16}, "MOVEPW (%i,A%y),R%x" },
  410. { 0x0148, 0xf1f8, 0x0000, 0x0000, {I16}, "MOVEPL (%i,A%y),R%x" },
  411. { 0x0188, 0xf1f8, 0x0000, 0x0000, {I16}, "MOVEPW R%x,(%i,A%y)" },
  412. { 0x01c8, 0xf1f8, 0x0000, 0x0000, {I16}, "MOVEPL R%x,(%i,A%y)" },
  413. { 0x0100, 0xf1f8, 0x0000, 0x0000, {0}, "BTSTL R%x,R%y" },
  414. { 0x0140, 0xf1f8, 0x0000, 0x0000, {0}, "BCHGL R%x,R%y" },
  415. { 0x0180, 0xf1f8, 0x0000, 0x0000, {0}, "BCLRL R%x,R%y" },
  416. { 0x01c0, 0xf1f8, 0x0000, 0x0000, {0}, "BSET R%x,R%y" },
  417. { 0x0100, 0xf1c0, 0x0000, 0x0000, {EAM_B}, "BTSTB R%x,%e" },
  418. { 0x0140, 0xf1c0, 0x0000, 0x0000, {EAMA}, "BCHG R%x,%e" },
  419. { 0x0180, 0xf1c0, 0x0000, 0x0000, {EAMA}, "BCLR R%x,%e" },
  420. { 0x01c0, 0xf1c0, 0x0000, 0x0000, {EAMA}, "BSET R%x,%e" },
  421. { 0,0,0,0,{0},0 },
  422. };
  423. /* class 1: move byte */
  424. static Optable t1[] = {
  425. { 0x1000, 0xf000, 0x0000, 0x0000, {EAALL_B,EADDA},"MOVB %e,%E" },
  426. { 0,0,0,0,{0},0 },
  427. };
  428. /* class 2: move long */
  429. static Optable t2[] = {
  430. { 0x2040, 0xf1c0, 0x0000, 0x0000, {EAALL_L}, "MOVL %e,A%x" },
  431. { 0x2000, 0xf000, 0x0000, 0x0000, {EAALL_L,EADDA},"MOVL %e,%E" },
  432. { 0,0,0,0,{0},0 },
  433. };
  434. /* class 3: move word */
  435. static Optable t3[] = {
  436. { 0x3040, 0xf1c0, 0x0000, 0x0000, {EAALL_W}, "MOVW %e,A%x" },
  437. { 0x3000, 0xf000, 0x0000, 0x0000, {EAALL_W,EADDA},"MOVW %e,%E" },
  438. { 0,0,0,0,{0},0 },
  439. };
  440. /* class 4: miscellaneous */
  441. static Optable t4[] = {
  442. { 0x4e75, 0xffff, 0x0000, 0x0000, {STACK}, "RTS" },
  443. { 0x4e77, 0xffff, 0x0000, 0x0000, {STACK}, "RTR" },
  444. { 0x4afc, 0xffff, 0x0000, 0x0000, {0}, "ILLEGAL" },
  445. { 0x4e71, 0xffff, 0x0000, 0x0000, {0}, "NOP" },
  446. { 0x4e74, 0xffff, 0x0000, 0x0000, {I16, STACK}, "RTD %i" },
  447. { 0x4e76, 0xffff, 0x0000, 0x0000, {0}, "TRAPV" },
  448. { 0x4e70, 0xffff, 0x0000, 0x0000, {0}, "RESET" },
  449. { 0x4e72, 0xffff, 0x0000, 0x0000, {I16}, "STOP %i" },
  450. { 0x4e73, 0xffff, 0x0000, 0x0000, {0}, "RTE" },
  451. { 0x4e7a, 0xffff, 0x0000, 0x0000, {I16}, "MOVEL %N,%r" },
  452. { 0x4e7b, 0xffff, 0x0000, 0x0000, {I16}, "MOVEL %r,%N" },
  453. { 0x4808, 0xfff8, 0x0000, 0x0000, {I32}, "LINKL A%y,%i" },
  454. { 0x4840, 0xfff8, 0x0000, 0x0000, {0}, "SWAPW R%y" },
  455. { 0x4848, 0xfff8, 0x0000, 0x0000, {0}, "BKPT #%y" },
  456. { 0x4880, 0xfff8, 0x0000, 0x0000, {0}, "EXTW R%y" },
  457. { 0x48C0, 0xfff8, 0x0000, 0x0000, {0}, "EXTL R%y" },
  458. { 0x49C0, 0xfff8, 0x0000, 0x0000, {0}, "EXTBL R%y" },
  459. { 0x4e50, 0xfff8, 0x0000, 0x0000, {I16}, "LINKW A%y,%i" },
  460. { 0x4e58, 0xfff8, 0x0000, 0x0000, {0}, "UNLK A%y" },
  461. { 0x4e60, 0xfff8, 0x0000, 0x0000, {0}, "MOVEL (A%y),USP" },
  462. { 0x4e68, 0xfff8, 0x0000, 0x0000, {0}, "MOVEL USP,(A%y)" },
  463. { 0x4e40, 0xfff0, 0x0000, 0x0000, {0}, "SYS %f" },
  464. { 0x40c0, 0xffc0, 0x0000, 0x0000, {EADA}, "MOVW SR,%e" },
  465. { 0x42c0, 0xffc0, 0x0000, 0x0000, {EADA}, "MOVW CCR,%e" },
  466. { 0x44c0, 0xffc0, 0x0000, 0x0000, {EADI_W}, "MOVW %e,CCR" },
  467. { 0x46c0, 0xffc0, 0x0000, 0x0000, {EADI_W}, "MOVW %e,SR" },
  468. { 0x4800, 0xffc0, 0x0000, 0x0000, {EADA}, "NBCDB %e" },
  469. { 0x4840, 0xffc0, 0x0000, 0x0000, {EAC}, "PEA %e" },
  470. { 0x4880, 0xffc0, 0x0000, 0x0000, {I16, EACAPD},"MOVEMW %i,%e" },
  471. { 0x48c0, 0xffc0, 0x0000, 0x0000, {I16, EACAPD},"MOVEML %i,%e" },
  472. { 0x4ac0, 0xffc0, 0x0000, 0x0000, {EADA}, "TAS %e" },
  473. { 0x4a00, 0xffc0, 0x0000, 0x0000, {EAD}, "TSTB %e" },
  474. { 0x4c00, 0xffc0, 0x0000, 0x8ff8, {EADI_L}, "MULUL %e,%r" },
  475. { 0x4c00, 0xffc0, 0x0400, 0x8ff8, {EADI_L}, "MULUL %e,R%a:%r" },
  476. { 0x4c00, 0xffc0, 0x0800, 0x8ff8, {EADI_L}, "MULSL %e,%r" },
  477. { 0x4c00, 0xffc0, 0x0c00, 0x8ff8, {EADI_L}, "MULSL %e,R%a:%r" },
  478. { 0x4c40, 0xffc0, 0x0000, 0x8ff8, {EADI_L}, "DIVUL %e,%j" },
  479. { 0x4c40, 0xffc0, 0x0400, 0x8ff8, {EADI_L}, "DIVUD %e,%r:R%a" },
  480. { 0x4c40, 0xffc0, 0x0800, 0x8ff8, {EADI_L}, "DIVSL %e,%j" },
  481. { 0x4c40, 0xffc0, 0x0c00, 0x8ff8, {EADI_L}, "DIVSD %e,%r:R%a" },
  482. { 0x4c80, 0xffc0, 0x0000, 0x0000, {I16, EACPI}, "MOVEMW %1,%i" },
  483. { 0x4cc0, 0xffc0, 0x0000, 0x0000, {I16, EACPI}, "MOVEML %1,%i" },
  484. { 0x4e80, 0xffc0, 0x0000, 0x0000, {BREAC}, "JSR %e" },
  485. { 0x4ec0, 0xffc0, 0x0000, 0x0000, {BREAC}, "JMP %e" },
  486. { 0x4000, 0xff00, 0x0000, 0x0000, {EADA}, "NEGX%s %e" },
  487. { 0x4200, 0xff00, 0x0000, 0x0000, {EADA}, "CLR%s %e" },
  488. { 0x4400, 0xff00, 0x0000, 0x0000, {EADA}, "NEG%s %e" },
  489. { 0x4600, 0xff00, 0x0000, 0x0000, {EADA}, "NOT%s %e" },
  490. { 0x4a00, 0xff00, 0x0000, 0x0000, {EAALL}, "TST%s %e" },
  491. { 0x4180, 0xf1c0, 0x0000, 0x0000, {EADI_W}, "CHKW %e,R%x" },
  492. { 0x41c0, 0xf1c0, 0x0000, 0x0000, {EAC}, "LEA %e,A%x" },
  493. { 0x4100, 0xf1c0, 0x0000, 0x0000, {EADI_L}, "CHKL %e,R%x" },
  494. { 0,0,0,0,{0},0 },
  495. };
  496. /* class 5: miscellaneous quick, branch & trap instructions */
  497. static Optable t5[] = {
  498. { 0x5000, 0xf1c0, 0x0000, 0x0000, {EADA}, "ADDB $Q#%q,%e" },
  499. { 0x5100, 0xf1c0, 0x0000, 0x0000, {EADA}, "SUBB $Q#%q,%e" },
  500. { 0x50c8, 0xf1f8, 0x0000, 0x0000, {BR16}, "DB%c R%y,%t" },
  501. { 0x51c8, 0xf1f8, 0x0000, 0x0000, {BR16}, "DB%c R%y,%t" },
  502. { 0x5000, 0xf1c0, 0x0000, 0x0000, {EAA}, "ADDB $Q#%q,%e" },
  503. { 0x5040, 0xf1c0, 0x0000, 0x0000, {EAA}, "ADDW $Q#%q,%e" },
  504. { 0x5080, 0xf1c0, 0x0000, 0x0000, {EAA}, "ADDL $Q#%q,%e" },
  505. { 0x5100, 0xf1c0, 0x0000, 0x0000, {EAA}, "SUBB $Q#%q,%e" },
  506. { 0x5140, 0xf1c0, 0x0000, 0x0000, {EAA}, "SUBW $Q#%q,%e" },
  507. { 0x5180, 0xf1c0, 0x0000, 0x0000, {EAA}, "SUBL $Q#%q,%e" },
  508. { 0x50fa, 0xf0ff, 0x0000, 0x0000, {I16}, "TRAP%cW %i" },
  509. { 0x50fb, 0xf0ff, 0x0000, 0x0000, {I32}, "TRAP%cL %i" },
  510. { 0x50fc, 0xf0ff, 0x0000, 0x0000, {0}, "TRAP%c" },
  511. { 0x50c0, 0xf0c0, 0x0000, 0x0000, {EADA}, "S%c %e" },
  512. { 0,0,0,0,{0},0 },
  513. };
  514. /* class 6: branch instructions */
  515. static Optable t6[] = {
  516. { 0x6000, 0xff00, 0x0000, 0x0000, {BR8}, "BRA %t" },
  517. { 0x6100, 0xff00, 0x0000, 0x0000, {BR8}, "BSR %t" },
  518. { 0x6000, 0xf000, 0x0000, 0x0000, {BR8}, "B%c %t" },
  519. { 0,0,0,0,{0},0 },
  520. };
  521. /* class 7: move quick */
  522. static Optable t7[] = {
  523. { 0x7000, 0xf100, 0x0000, 0x0000, {OP8}, "MOVL $Q%i,R%x" },
  524. { 0,0,0,0,{0},0 },
  525. };
  526. /* class 8: BCD operations, DIV, and OR instructions */
  527. static Optable t8[] = {
  528. { 0x8100, 0xf1f8, 0x0000, 0x0000, {0}, "SBCDB R%y,R%x" },
  529. { 0x8108, 0xf1f8, 0x0000, 0x0000, {0}, "SBCDB -(A%y),-(A%x)" },
  530. { 0x8140, 0xf1f8, 0x0000, 0x0000, {I16}, "PACK R%y,R%x,%i" },
  531. { 0x8148, 0xf1f8, 0x0000, 0x0000, {I16}, "PACK -(A%y),-(A%x),%i" },
  532. { 0x8180, 0xf1f8, 0x0000, 0x0000, {I16}, "UNPK R%y,R%x,%i" },
  533. { 0x8188, 0xf1f8, 0x0000, 0x0000, {I16}, "UNPK -(A%y),-(A%x),%i" },
  534. { 0x80c0, 0xf1c0, 0x0000, 0x0000, {EADI_W}, "DIVUW %e,R%x" },
  535. { 0x81c0, 0xf1c0, 0x0000, 0x0000, {EADI_W}, "DIVSW %e,R%x" },
  536. { 0x8000, 0xf100, 0x0000, 0x0000, {EADI}, "OR%s %e,R%x" },
  537. { 0x8100, 0xf100, 0x0000, 0x0000, {EAMA}, "OR%s R%x,%e" },
  538. { 0,0,0,0,{0},0 },
  539. };
  540. /* class 9: subtract instruction */
  541. static Optable t9[] = {
  542. { 0x90c0, 0xf1c0, 0x0000, 0x0000, {EAALL_W}, "SUBW %e,A%x" },
  543. { 0x91c0, 0xf1c0, 0x0000, 0x0000, {EAALL_L}, "SUBL %e,A%x" },
  544. { 0x9100, 0xf138, 0x0000, 0x0000, {0}, "SUBX%s R%y,R%x" },
  545. { 0x9108, 0xf138, 0x0000, 0x0000, {0}, "SUBX%s -(A%y),-(A%x)" },
  546. { 0x9000, 0xf100, 0x0000, 0x0000, {EAALL}, "SUB%s %e,R%x" },
  547. { 0x9100, 0xf100, 0x0000, 0x0000, {EAMA}, "SUB%s R%x,%e" },
  548. { 0,0,0,0,{0},0 },
  549. };
  550. /* class b: CMP & EOR */
  551. static Optable tb[] = {
  552. { 0xb000, 0xf1c0, 0x0000, 0x0000, {EADI}, "CMPB R%x,%e" },
  553. { 0xb040, 0xf1c0, 0x0000, 0x0000, {EAALL_W}, "CMPW R%x,%e" },
  554. { 0xb080, 0xf1c0, 0x0000, 0x0000, {EAALL_L}, "CMPL R%x,%e" },
  555. { 0xb0c0, 0xf1c0, 0x0000, 0x0000, {EAALL_W}, "CMPW A%x,%e" },
  556. { 0xb1c0, 0xf1c0, 0x0000, 0x0000, {EAALL_L}, "CMPL A%x,%e" },
  557. { 0xb108, 0xf138, 0x0000, 0x0000, {0}, "CMP%s (A%y)+,(A%x)+" },
  558. { 0xb100, 0xf100, 0x0000, 0x0000, {EADA}, "EOR%s %e,R%x" },
  559. { 0,0,0,0,{0},0 },
  560. };
  561. /* class c: AND, MUL, BCD & Exchange */
  562. static Optable tc[] = {
  563. { 0xc100, 0xf1f8, 0x0000, 0x0000, {0}, "ABCDB R%y,R%x" },
  564. { 0xc108, 0xf1f8, 0x0000, 0x0000, {0}, "ABCDB -(A%y),-(A%x)" },
  565. { 0xc140, 0xf1f8, 0x0000, 0x0000, {0}, "EXG R%x,R%y" },
  566. { 0xc148, 0xf1f8, 0x0000, 0x0000, {0}, "EXG A%x,A%y" },
  567. { 0xc188, 0xf1f8, 0x0000, 0x0000, {0}, "EXG R%x,A%y" },
  568. { 0xc0c0, 0xf1c0, 0x0000, 0x0000, {EADI_W}, "MULUW %e,R%x" },
  569. { 0xc1c0, 0xf1c0, 0x0000, 0x0000, {EADI_W}, "MULSW %e,R%x" },
  570. { 0xc000, 0xf100, 0x0000, 0x0000, {EADI}, "AND%s %e,R%x" },
  571. { 0xc100, 0xf100, 0x0000, 0x0000, {EAMA}, "AND%s R%x,%e" },
  572. { 0,0,0,0,{0},0 },
  573. };
  574. /* class d: addition */
  575. static Optable td[] = {
  576. { 0xd000, 0xf1c0, 0x0000, 0x0000, {EADI}, "ADDB %e,R%x" },
  577. { 0xd0c0, 0xf1c0, 0x0000, 0x0000, {EAALL_W}, "ADDW %e,A%x" },
  578. { 0xd1c0, 0xf1c0, 0x0000, 0x0000, {EAALL_L}, "ADDL %e,A%x" },
  579. { 0xd100, 0xf138, 0x0000, 0x0000, {0}, "ADDX%s R%y,R%x" },
  580. { 0xd108, 0xf138, 0x0000, 0x0000, {0}, "ADDX%s -(A%y),-(A%x)" },
  581. { 0xd000, 0xf100, 0x0000, 0x0000, {EAALL}, "ADD%s %e,R%x" },
  582. { 0xd100, 0xf100, 0x0000, 0x0000, {EAMA}, "ADD%s R%x,%e" },
  583. { 0,0,0,0,{0},0 },
  584. };
  585. /* class e: shift, rotate, bit field operations */
  586. static Optable te[] = {
  587. { 0xe8c0, 0xffc0, 0x0820, 0xfe38, {EACD}, "BFTST %e{R%u:R%a}" },
  588. { 0xe8c0, 0xffc0, 0x0800, 0xfe20, {EACD}, "BFTST %e{R%u:%w}" },
  589. { 0xe8c0, 0xffc0, 0x0020, 0xf838, {EACD}, "BFTST %e{%o:R%a}" },
  590. { 0xe8c0, 0xffc0, 0x0000, 0xf820, {EACD}, "BFTST %e{%o:%w}" },
  591. { 0xe9c0, 0xffc0, 0x0820, 0x8e38, {EACD}, "BFEXTU %e{R%u:R%a},%r" },
  592. { 0xe9c0, 0xffc0, 0x0800, 0x8e20, {EACD}, "BFEXTU %e{R%u:%w},%r" },
  593. { 0xe9c0, 0xffc0, 0x0020, 0x8838, {EACD}, "BFEXTU %e{%o:R%a},%r" },
  594. { 0xe9c0, 0xffc0, 0x0000, 0x8820, {EACD}, "BFEXTU %e{%o:%w},%r" },
  595. { 0xeac0, 0xffc0, 0x0820, 0xfe38, {EACAD}, "BFCHG %e{R%u:R%a}" },
  596. { 0xeac0, 0xffc0, 0x0800, 0xfe20, {EACAD}, "BFCHG %e{R%u:%w}" },
  597. { 0xeac0, 0xffc0, 0x0020, 0xf838, {EACAD}, "BFCHG %e{%o:R%a}" },
  598. { 0xeac0, 0xffc0, 0x0000, 0xf820, {EACAD}, "BFCHG %e{%o:%w}" },
  599. { 0xebc0, 0xffc0, 0x0820, 0x8e38, {EACD}, "BFEXTS %e{R%u:R%a},%r" },
  600. { 0xebc0, 0xffc0, 0x0800, 0x8e20, {EACD}, "BFEXTS %e{R%u:%w},%r" },
  601. { 0xebc0, 0xffc0, 0x0020, 0x8838, {EACD}, "BFEXTS %e{%o:R%a},%r" },
  602. { 0xebc0, 0xffc0, 0x0000, 0x8820, {EACD}, "BFEXTS %e{%o:%w},%r" },
  603. { 0xecc0, 0xffc0, 0x0820, 0xfe38, {EACAD}, "BFCLR %e{R%u:R%a}" },
  604. { 0xecc0, 0xffc0, 0x0800, 0xfe20, {EACAD}, "BFCLR %e{R%u:%w}" },
  605. { 0xecc0, 0xffc0, 0x0020, 0xf838, {EACAD}, "BFCLR %e{%o:R%a}" },
  606. { 0xecc0, 0xffc0, 0x0000, 0xf820, {EACAD}, "BFCLR %e{%o:%w}" },
  607. { 0xedc0, 0xffc0, 0x0820, 0x8e38, {EACAD}, "BFFFO %e{R%u:R%a},%r" },
  608. { 0xedc0, 0xffc0, 0x0800, 0x8e20, {EACAD}, "BFFFO %e{R%u:%w},%r" },
  609. { 0xedc0, 0xffc0, 0x0020, 0x8838, {EACAD}, "BFFFO %e{%o:R%a},%r" },
  610. { 0xedc0, 0xffc0, 0x0000, 0x8820, {EACAD}, "BFFFO %e{%o:%w},%r" },
  611. { 0xeec0, 0xffc0, 0x0820, 0xfe38, {EACAD}, "BFSET %e{R%u:R%a}" },
  612. { 0xeec0, 0xffc0, 0x0800, 0xfe20, {EACAD}, "BFSET %e{R%u:%w}" },
  613. { 0xeec0, 0xffc0, 0x0020, 0xf838, {EACAD}, "BFSET %e{%o:R%a}" },
  614. { 0xeec0, 0xffc0, 0x0000, 0xf820, {EACAD}, "BFSET %e{%o:%w}" },
  615. { 0xefc0, 0xffc0, 0x0820, 0x8e38, {EACAD}, "BFINS %r,%e{R%u:R%a}" },
  616. { 0xefc0, 0xffc0, 0x0800, 0x8e20, {EACAD}, "BFINS %r,%e{R%u:%w}" },
  617. { 0xefc0, 0xffc0, 0x0020, 0x8838, {EACAD}, "BFINS %r,%e{%o:R%a}" },
  618. { 0xefc0, 0xffc0, 0x0000, 0x8820, {EACAD}, "BFINS %r,%e{%o:%w}" },
  619. { 0xe0c0, 0xfec0, 0x0000, 0x0000, {EAMA}, "AS%dW %e" },
  620. { 0xe2c0, 0xfec0, 0x0000, 0x0000, {EAMA}, "LS%dW %e" },
  621. { 0xe4c0, 0xfec0, 0x0000, 0x0000, {EAMA}, "ROX%dW %e" },
  622. { 0xe6c0, 0xfec0, 0x0000, 0x0000, {EAMA}, "RO%dW %e" },
  623. { 0xe000, 0xf038, 0x0000, 0x0000, {0}, "AS%d%s #%q,R%y" },
  624. { 0xe008, 0xf038, 0x0000, 0x0000, {0}, "LS%d%s #%q,R%y" },
  625. { 0xe010, 0xf038, 0x0000, 0x0000, {0}, "ROX%d%s #%q,R%y" },
  626. { 0xe018, 0xf038, 0x0000, 0x0000, {0}, "RO%d%s #%q,R%y" },
  627. { 0xe020, 0xf038, 0x0000, 0x0000, {0}, "AS%d%s R%x,R%y" },
  628. { 0xe028, 0xf038, 0x0000, 0x0000, {0}, "LS%d%s R%x,R%y" },
  629. { 0xe030, 0xf038, 0x0000, 0x0000, {0}, "ROX%d%s R%x,R%y" },
  630. { 0xe038, 0xf038, 0x0000, 0x0000, {0}, "RO%d%s R%x,R%y" },
  631. { 0,0,0,0,{0},0 },
  632. };
  633. /* class f: coprocessor and mmu instructions */
  634. static Optable tf[] = {
  635. { 0xf280, 0xffff, 0x0000, 0xffff, {0}, "FNOP" },
  636. { 0xf200, 0xffff, 0x5c00, 0xfc00, {0}, "FMOVECRX %k,F%D" },
  637. { 0xf27a, 0xffff, 0x0000, 0xffc0, {I16}, "FTRAP%P %i" },
  638. { 0xf27b, 0xffff, 0x0000, 0xffc0, {I32}, "FTRAP%P %i" },
  639. { 0xf27c, 0xffff, 0x0000, 0xffc0, {0}, "FTRAP%P" },
  640. { 0xf248, 0xfff8, 0x0000, 0xffc0, {BR16}, "FDB%P R%y,%t" },
  641. { 0xf620, 0xfff8, 0x8000, 0x8fff, {0}, "MOVE16 (A%y)+,(%r)+" },
  642. { 0xf500, 0xfff8, 0x0000, 0x0000, {0}, "PFLUSHN (A%y)" },
  643. { 0xf508, 0xfff8, 0x0000, 0x0000, {0}, "PFLUSH (A%y)" },
  644. { 0xf510, 0xfff8, 0x0000, 0x0000, {0}, "PFLUSHAN" },
  645. { 0xf518, 0xfff8, 0x0000, 0x0000, {0}, "PFLUSHA" },
  646. { 0xf548, 0xfff8, 0x0000, 0x0000, {0}, "PTESTW (A%y)" },
  647. { 0xf568, 0xfff8, 0x0000, 0x0000, {0}, "PTESTR (A%y)" },
  648. { 0xf600, 0xfff8, 0x0000, 0x0000, {I32}, "MOVE16 (A%y)+,$%i" },
  649. { 0xf608, 0xfff8, 0x0000, 0x0000, {I32}, "MOVE16 $%i,(A%y)-" },
  650. { 0xf610, 0xfff8, 0x0000, 0x0000, {I32}, "MOVE16 (A%y),$%i" },
  651. { 0xf618, 0xfff8, 0x0000, 0x0000, {I32}, "MOVE16 $%i,(A%y)" },
  652. { 0xf000, 0xffc0, 0x0800, 0xffff, {EACA}, "PMOVE %e,TT0" },
  653. { 0xf000, 0xffc0, 0x0900, 0xffff, {EACA}, "PMOVEFD %e,TT0" },
  654. { 0xf000, 0xffc0, 0x0a00, 0xffff, {EACA}, "PMOVE TT0,%e" },
  655. { 0xf000, 0xffc0, 0x0b00, 0xffff, {EACA}, "PMOVEFD TT0,%e" },
  656. { 0xf000, 0xffc0, 0x0c00, 0xffff, {EACA}, "PMOVE %e,TT1" },
  657. { 0xf000, 0xffc0, 0x0d00, 0xffff, {EACA}, "PMOVEFD %e,TT1" },
  658. { 0xf000, 0xffc0, 0x0e00, 0xffff, {EACA}, "PMOVE TT1,%e" },
  659. { 0xf000, 0xffc0, 0x0f00, 0xffff, {EACA}, "PMOVEFD TT1,%e" },
  660. { 0xf000, 0xffc0, 0x2400, 0xffff, {0}, "PFLUSHA" },
  661. { 0xf000, 0xffc0, 0x2800, 0xffff, {EACA}, "PVALID VAL,%e" },
  662. { 0xf000, 0xffc0, 0x6000, 0xffff, {EACA}, "PMOVE %e,MMUSR" },
  663. { 0xf000, 0xffc0, 0x6200, 0xffff, {EACA}, "PMOVE MMUSR,%e" },
  664. { 0xf000, 0xffc0, 0x2800, 0xfff8, {EACA}, "PVALID A%a,%e" },
  665. { 0xf000, 0xffc0, 0x2000, 0xffe0, {EACA}, "PLOADW %L,%e" },
  666. { 0xf000, 0xffc0, 0x2200, 0xffe0, {EACA}, "PLOADR %L,%e" },
  667. { 0xf000, 0xffc0, 0x8000, 0xffe0, {EACA}, "PTESTW %L,%e,#0" },
  668. { 0xf000, 0xffc0, 0x8200, 0xffe0, {EACA}, "PTESTR %L,%e,#0" },
  669. { 0xf000, 0xffc0, 0x3000, 0xfe00, {0}, "PFLUSH %L,#%I" },
  670. { 0xf000, 0xffc0, 0x3800, 0xfe00, {EACA}, "PFLUSH %L,#%I,%e" },
  671. { 0xf000, 0xffc0, 0x8000, 0xe300, {EACA}, "PTESTW %L,%e,#%Z" },
  672. { 0xf000, 0xffc0, 0x8100, 0xe300, {EACA}, "PTESTW %L,%e,#%Z,A%h" },
  673. { 0xf000, 0xffc0, 0x8200, 0xe300, {EACA}, "PTESTR %L,%e,#%Z" },
  674. { 0xf000, 0xffc0, 0x8300, 0xe300, {EACA}, "PTESTR %L,%e,#%Z,A%h" },
  675. { 0xf000, 0xffc0, 0x4000, 0xc3ff, {EACA}, "PMOVE %e,%H" },
  676. { 0xf000, 0xffc0, 0x4100, 0xc3ff, {EACA}, "PMOVEFD %e,%H" },
  677. { 0xf000, 0xffc0, 0x4200, 0xc3ff, {EACA}, "PMOVE %H,%e" },
  678. /* floating point (coprocessor 1)*/
  679. { 0xf200, 0xffc0, 0x8400, 0xffff, {EAALL_L}, "FMOVEL %e,FPIAR" },
  680. { 0xf200, 0xffc0, 0x8800, 0xffff, {EADI_L}, "FMOVEL %e,FPSR" },
  681. { 0xf200, 0xffc0, 0x9000, 0xffff, {EADI_L}, "FMOVEL %e,FPCR" },
  682. { 0xf200, 0xffc0, 0xa400, 0xffff, {EAA}, "FMOVEL FPIAR,%e" },
  683. { 0xf200, 0xffc0, 0xa800, 0xffff, {EADA}, "FMOVEL FPSR,%e" },
  684. { 0xf200, 0xffc0, 0xb000, 0xffff, {EADA}, "FMOVEL FPCR,%e" },
  685. { 0xf240, 0xffc0, 0x0000, 0xffc0, {EADA}, "FS%P %e" },
  686. { 0xf200, 0xffc0, 0xd000, 0xff00, {EACPI}, "FMOVEMX %e,%m" },
  687. { 0xf200, 0xffc0, 0xd800, 0xff00, {EACPI}, "FMOVEMX %e,R%K" },
  688. { 0xf200, 0xffc0, 0xe000, 0xff00, {EAPI}, "FMOVEMX %m,-(A%y)" },
  689. { 0xf200, 0xffc0, 0xe800, 0xff00, {EAPI}, "FMOVEMX R%K,-(A%y)" },
  690. { 0xf200, 0xffc0, 0xf000, 0xff00, {EACAPD}, "FMOVEMX %m,%e" },
  691. { 0xf200, 0xffc0, 0xf800, 0xff00, {EACAPD}, "FMOVEMX R%K,%e" },
  692. { 0xf200, 0xffc0, 0x6800, 0xfc00, {EAMA}, "FMOVEX F%D,%e" },
  693. { 0xf200, 0xffc0, 0x6c00, 0xfc00, {EAMA}, "FMOVEP F%D,%e,{%k}" },
  694. { 0xf200, 0xffc0, 0x7400, 0xfc00, {EAMA}, "FMOVED F%D,%e" },
  695. { 0xf200, 0xffc0, 0x7c00, 0xfc00, {EAMA}, "FMOVEP F%D,%e,{R%K}" },
  696. { 0xf200, 0xffc0, 0x8000, 0xe3ff, {EAM}, "FMOVEML #%B,%e" },
  697. { 0xf200, 0xffc0, 0xa000, 0xe3ff, {EAMA}, "FMOVEML %e,#%B" },
  698. { 0xf200, 0xffc0, 0x0000, 0xe07f, {0}, "FMOVE F%B,F%D" },
  699. { 0xf200, 0xffc0, 0x0001, 0xe07f, {0}, "FINTX %F" },
  700. { 0xf200, 0xffc0, 0x0002, 0xe07f, {0}, "FSINHX %F" },
  701. { 0xf200, 0xffc0, 0x0003, 0xe07f, {0}, "FINTRZ %F" },
  702. { 0xf200, 0xffc0, 0x0004, 0xe07f, {0}, "FSQRTX %F" },
  703. { 0xf200, 0xffc0, 0x0006, 0xe07f, {0}, "FLOGNP1X %F" },
  704. { 0xf200, 0xffc0, 0x0009, 0xe07f, {0}, "FTANHX %F" },
  705. { 0xf200, 0xffc0, 0x000a, 0xe07f, {0}, "FATANX %F" },
  706. { 0xf200, 0xffc0, 0x000c, 0xe07f, {0}, "FASINX %F" },
  707. { 0xf200, 0xffc0, 0x000d, 0xe07f, {0}, "FATANHX %F" },
  708. { 0xf200, 0xffc0, 0x000e, 0xe07f, {0}, "FSINX %F" },
  709. { 0xf200, 0xffc0, 0x000f, 0xe07f, {0}, "FTANX %F" },
  710. { 0xf200, 0xffc0, 0x0010, 0xe07f, {0}, "FETOXX %F" },
  711. { 0xf200, 0xffc0, 0x0011, 0xe07f, {0}, "FTWOTOXX %F" },
  712. { 0xf200, 0xffc0, 0x0012, 0xe07f, {0}, "FTENTOXX %F" },
  713. { 0xf200, 0xffc0, 0x0014, 0xe07f, {0}, "FLOGNX %F" },
  714. { 0xf200, 0xffc0, 0x0015, 0xe07f, {0}, "FLOG10X %F" },
  715. { 0xf200, 0xffc0, 0x0016, 0xe07f, {0}, "FLOG2X %F" },
  716. { 0xf200, 0xffc0, 0x0018, 0xe07f, {0}, "FABSX %F" },
  717. { 0xf200, 0xffc0, 0x0019, 0xe07f, {0}, "FCOSHX %F" },
  718. { 0xf200, 0xffc0, 0x001a, 0xe07f, {0}, "FNEGX %F" },
  719. { 0xf200, 0xffc0, 0x001c, 0xe07f, {0}, "FACOSX %F" },
  720. { 0xf200, 0xffc0, 0x001d, 0xe07f, {0}, "FCOSX %F" },
  721. { 0xf200, 0xffc0, 0x001e, 0xe07f, {0}, "FGETEXPX %F" },
  722. { 0xf200, 0xffc0, 0x001f, 0xe07f, {0}, "FGETMANX %F" },
  723. { 0xf200, 0xffc0, 0x0020, 0xe07f, {0}, "FDIVX F%B,F%D" },
  724. { 0xf200, 0xffc0, 0x0021, 0xe07f, {0}, "FMODX F%B,F%D" },
  725. { 0xf200, 0xffc0, 0x0022, 0xe07f, {0}, "FADDX F%B,F%D" },
  726. { 0xf200, 0xffc0, 0x0023, 0xe07f, {0}, "FMULX F%B,F%D" },
  727. { 0xf200, 0xffc0, 0x0024, 0xe07f, {0}, "FSGLDIVX F%B,F%D" },
  728. { 0xf200, 0xffc0, 0x0025, 0xe07f, {0}, "FREMX F%B,F%D" },
  729. { 0xf200, 0xffc0, 0x0026, 0xe07f, {0}, "FSCALEX F%B,F%D" },
  730. { 0xf200, 0xffc0, 0x0027, 0xe07f, {0}, "FSGLMULX F%B,F%D" },
  731. { 0xf200, 0xffc0, 0x0028, 0xe07f, {0}, "FSUBX F%B,F%D" },
  732. { 0xf200, 0xffc0, 0x0038, 0xe07f, {0}, "FCMPX F%B,F%D" },
  733. { 0xf200, 0xffc0, 0x003a, 0xe07f, {0}, "FTSTX F%B" },
  734. { 0xf200, 0xffc0, 0x0040, 0xe07f, {0}, "FSMOVE F%B,F%D" },
  735. { 0xf200, 0xffc0, 0x0041, 0xe07f, {0}, "FSSQRTX %F"},
  736. { 0xf200, 0xffc0, 0x0044, 0xe07f, {0}, "FDMOVE F%B,F%D" },
  737. { 0xf200, 0xffc0, 0x0045, 0xe07f, {0}, "FDSQRTX %F" },
  738. { 0xf200, 0xffc0, 0x0058, 0xe07f, {0}, "FSABSX %F" },
  739. { 0xf200, 0xffc0, 0x005a, 0xe07f, {0}, "FSNEGX %F" },
  740. { 0xf200, 0xffc0, 0x005c, 0xe07f, {0}, "FDABSX %F" },
  741. { 0xf200, 0xffc0, 0x005e, 0xe07f, {0}, "FDNEGX %F" },
  742. { 0xf200, 0xffc0, 0x0060, 0xe07f, {0}, "FSDIVX F%B,F%D" },
  743. { 0xf200, 0xffc0, 0x0062, 0xe07f, {0}, "FSADDX F%B,F%D" },
  744. { 0xf200, 0xffc0, 0x0063, 0xe07f, {0}, "FSMULX F%B,F%D" },
  745. { 0xf200, 0xffc0, 0x0064, 0xe07f, {0}, "FDDIVX F%B,F%D" },
  746. { 0xf200, 0xffc0, 0x0066, 0xe07f, {0}, "FDADDX F%B,F%D" },
  747. { 0xf200, 0xffc0, 0x0067, 0xe07f, {0}, "FDMULX F%B,F%D" },
  748. { 0xf200, 0xffc0, 0x0068, 0xe07f, {0}, "FSSUBX F%B,F%D" },
  749. { 0xf200, 0xffc0, 0x006c, 0xe07f, {0}, "FDSUBX F%B,F%D" },
  750. { 0xf200, 0xffc0, 0x4000, 0xe07f, {EAFLT}, "FMOVE%S %e,F%D" },
  751. { 0xf200, 0xffc0, 0x4001, 0xe07f, {EAFLT}, "FINT%S %e,F%D" },
  752. { 0xf200, 0xffc0, 0x4002, 0xe07f, {EAFLT}, "FSINH%S %e,F%D" },
  753. { 0xf200, 0xffc0, 0x4003, 0xe07f, {EAFLT}, "FINTRZ%S %e,F%D" },
  754. { 0xf200, 0xffc0, 0x4004, 0xe07f, {EAFLT}, "FSQRT%S %e,F%D" },
  755. { 0xf200, 0xffc0, 0x4006, 0xe07f, {EAFLT}, "FLOGNP1%S %e,F%D" },
  756. { 0xf200, 0xffc0, 0x4009, 0xe07f, {EAFLT}, "FTANH%S %e,F%D" },
  757. { 0xf200, 0xffc0, 0x400a, 0xe07f, {EAFLT}, "FATAN%S %e,F%D" },
  758. { 0xf200, 0xffc0, 0x400c, 0xe07f, {EAFLT}, "FASIN%S %e,F%D" },
  759. { 0xf200, 0xffc0, 0x400d, 0xe07f, {EAFLT}, "FATANH%S %e,F%D" },
  760. { 0xf200, 0xffc0, 0x400e, 0xe07f, {EAFLT}, "FSIN%S %e,F%D" },
  761. { 0xf200, 0xffc0, 0x400f, 0xe07f, {EAFLT}, "FTAN%S %e,F%D" },
  762. { 0xf200, 0xffc0, 0x4010, 0xe07f, {EAFLT}, "FETOX%S %e,F%D" },
  763. { 0xf200, 0xffc0, 0x4011, 0xe07f, {EAFLT}, "FTWOTOX%S %e,F%D" },
  764. { 0xf200, 0xffc0, 0x4012, 0xe07f, {EAFLT}, "FTENTOX%S %e,F%D" },
  765. { 0xf200, 0xffc0, 0x4014, 0xe07f, {EAFLT}, "FLOGN%S %e,F%D" },
  766. { 0xf200, 0xffc0, 0x4015, 0xe07f, {EAFLT}, "FLOG10%S %e,F%D" },
  767. { 0xf200, 0xffc0, 0x4016, 0xe07f, {EAFLT}, "FLOG2%S %e,F%D" },
  768. { 0xf200, 0xffc0, 0x4018, 0xe07f, {EAFLT}, "FABS%S %e,F%D" },
  769. { 0xf200, 0xffc0, 0x4019, 0xe07f, {EAFLT}, "FCOSH%S %e,F%D" },
  770. { 0xf200, 0xffc0, 0x401a, 0xe07f, {EAFLT}, "FNEG%S %e,F%D" },
  771. { 0xf200, 0xffc0, 0x401c, 0xe07f, {EAFLT}, "FACOS%S %e,F%D" },
  772. { 0xf200, 0xffc0, 0x401d, 0xe07f, {EAFLT}, "FCOS%S %e,F%D" },
  773. { 0xf200, 0xffc0, 0x401e, 0xe07f, {EAFLT}, "FGETEXP%S %e,F%D" },
  774. { 0xf200, 0xffc0, 0x401f, 0xe07f, {EAFLT}, "FGETMAN%S %e,F%D" },
  775. { 0xf200, 0xffc0, 0x4020, 0xe07f, {EAFLT}, "FDIV%S %e,F%D" },
  776. { 0xf200, 0xffc0, 0x4021, 0xe07f, {EAFLT}, "FMOD%S %e,F%D" },
  777. { 0xf200, 0xffc0, 0x4022, 0xe07f, {EAFLT}, "FADD%S %e,F%D" },
  778. { 0xf200, 0xffc0, 0x4023, 0xe07f, {EAFLT}, "FMUL%S %e,F%D" },
  779. { 0xf200, 0xffc0, 0x4024, 0xe07f, {EAFLT}, "FSGLDIV%S %e,F%D" },
  780. { 0xf200, 0xffc0, 0x4025, 0xe07f, {EAFLT}, "FREM%S %e,F%D" },
  781. { 0xf200, 0xffc0, 0x4026, 0xe07f, {EAFLT}, "FSCALE%S %e,F%D" },
  782. { 0xf200, 0xffc0, 0x4027, 0xe07f, {EAFLT}, "FSGLMUL%S %e,F%D" },
  783. { 0xf200, 0xffc0, 0x4028, 0xe07f, {EAFLT}, "FSUB%S %e,F%D" },
  784. { 0xf200, 0xffc0, 0x4038, 0xe07f, {EAFLT}, "FCMP%S %e,F%D" },
  785. { 0xf200, 0xffc0, 0x403a, 0xe07f, {EAFLT}, "FTST%S %e" },
  786. { 0xf200, 0xffc0, 0x4040, 0xe07f, {EAFLT}, "FSMOVE%S %e,F%D" },
  787. { 0xf200, 0xffc0, 0x4041, 0xe07f, {EAFLT}, "FSSQRT%S %e,F%D" },
  788. { 0xf200, 0xffc0, 0x4044, 0xe07f, {EAFLT}, "FDMOVE%S %e,F%D" },
  789. { 0xf200, 0xffc0, 0x4045, 0xe07f, {EAFLT}, "FDSQRT%S %e,F%D" },
  790. { 0xf200, 0xffc0, 0x4058, 0xe07f, {EAFLT}, "FSABS%S %e,F%D" },
  791. { 0xf200, 0xffc0, 0x405a, 0xe07f, {EAFLT}, "FSNEG%S %e,F%D" },
  792. { 0xf200, 0xffc0, 0x405c, 0xe07f, {EAFLT}, "FDABS%S %e,F%D" },
  793. { 0xf200, 0xffc0, 0x405e, 0xe07f, {EAFLT}, "FDNEG%S %e,F%D" },
  794. { 0xf200, 0xffc0, 0x4060, 0xe07f, {EAFLT}, "FSDIV%S %e,F%D" },
  795. { 0xf200, 0xffc0, 0x4062, 0xe07f, {EAFLT}, "FSADD%S %e,F%D" },
  796. { 0xf200, 0xffc0, 0x4063, 0xe07f, {EAFLT}, "FSMUL%S %e,F%D" },
  797. { 0xf200, 0xffc0, 0x4064, 0xe07f, {EAFLT}, "FDDIV%S %e,F%D" },
  798. { 0xf200, 0xffc0, 0x4066, 0xe07f, {EAFLT}, "FDADD%S %e,F%D" },
  799. { 0xf200, 0xffc0, 0x4067, 0xe07f, {EAFLT}, "FDMUL%S %e,F%D" },
  800. { 0xf200, 0xffc0, 0x4068, 0xe07f, {EAFLT}, "FSSUB%S %e,F%D" },
  801. { 0xf200, 0xffc0, 0x406c, 0xe07f, {EAFLT}, "FDSUB%S %e,F%D" },
  802. { 0xf200, 0xffc0, 0x0030, 0xe078, {0}, "FSINCOSX F%B,F%a:F%D" },
  803. { 0xf200, 0xffc0, 0x4030, 0xe078, {EAFLT}, "FSINCOS%S %e,F%a:F%D" },
  804. { 0xf200, 0xffc0, 0x6000, 0xe000, {EADA}, "FMOVE%S F%D,%e" },
  805. { 0xf300, 0xffc0, 0x0000, 0x0000, {EACAPD}, "FSAVE %e" },
  806. { 0xf340, 0xffc0, 0x0000, 0x0000, {EACAPI}, "FRESTORE %e" },
  807. { 0xf280, 0xffc0, 0x0000, 0x0000, {BR16}, "FB%p %t" },
  808. { 0xf2c0, 0xffc0, 0x0000, 0x0000, {BR32}, "FB%p %t" },
  809. { 0xf408, 0xff38, 0x0000, 0x0000, {0}, "CINVL %C,(A%y)" },
  810. { 0xf410, 0xff38, 0x0000, 0x0000, {0}, "CINVP %C,(A%y)" },
  811. { 0xf418, 0xff38, 0x0000, 0x0000, {0}, "CINVA %C" },
  812. { 0xf428, 0xff38, 0x0000, 0x0000, {0}, "CPUSHL %C,(A%y)" },
  813. { 0xf430, 0xff38, 0x0000, 0x0000, {0}, "CPUSHP %C,(A%y)" },
  814. { 0xf438, 0xff38, 0x0000, 0x0000, {0}, "CPUSHA %C" },
  815. { 0,0,0,0,{0},0 },
  816. };
  817. static Optable *optables[] =
  818. {
  819. t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, 0, tb, tc, td, te, tf,
  820. };
  821. static Map *mymap;
  822. static int
  823. dumpinst(Inst *ip, char *buf, int n)
  824. {
  825. int i;
  826. if (n <= 0)
  827. return 0;
  828. *buf++ = '#';
  829. for (i = 0; i < ip->n && i*4+1 < n-4; i++, buf += 4)
  830. _hexify(buf, ip->raw[i], 3);
  831. *buf = 0;
  832. return i*4+1;
  833. }
  834. static int
  835. getword(Inst *ip, uint64_t offset)
  836. {
  837. if (ip->n < nelem(ip->raw)) {
  838. if (get2(mymap, offset, &ip->raw[ip->n++]) > 0)
  839. return 1;
  840. werrstr("can't read instruction: %r");
  841. } else
  842. werrstr("instruction too big: %r");
  843. return -1;
  844. }
  845. static int
  846. getshorts(Inst *ip, void *where, int n)
  847. {
  848. if (ip->n+n < nelem(ip->raw)) {
  849. if (get1(mymap, ip->addr+ip->n*2, (uint8_t*)&ip->raw[ip->n], n*2) < 0) {
  850. werrstr("can't read instruction: %r");
  851. return 0;
  852. }
  853. memmove(where, &ip->raw[ip->n], n*2);
  854. ip->n += n;
  855. return 1;
  856. }
  857. werrstr("instruction too big: %r");
  858. return 0;
  859. }
  860. static int
  861. i8(Inst *ip, int32_t *l)
  862. {
  863. if (getword(ip, ip->addr+ip->n*2) < 0)
  864. return -1;
  865. *l = ip->raw[ip->n-1]&0xff;
  866. if (*l&0x80)
  867. *l |= ~0xff;
  868. return 1;
  869. }
  870. static int
  871. i16(Inst *ip, int32_t *l)
  872. {
  873. if (getword(ip, ip->addr+ip->n*2) < 0)
  874. return -1;
  875. *l = ip->raw[ip->n-1];
  876. if (*l&0x8000)
  877. *l |= ~0xffff;
  878. return 1;
  879. }
  880. static int
  881. i32(Inst *ip, int32_t *l)
  882. {
  883. if (getword(ip, ip->addr+ip->n*2) < 0)
  884. return -1;
  885. if (getword(ip, ip->addr+ip->n*2) < 0)
  886. return -1;
  887. *l = (ip->raw[ip->n-2]<<16)|ip->raw[ip->n-1];
  888. return 1;
  889. }
  890. static int
  891. getimm(Inst *ip, Operand *ap, int mode)
  892. {
  893. ap->eatype = IMM;
  894. switch(mode)
  895. {
  896. case EAM_B: /* byte */
  897. case EAALL_B:
  898. return i8(ip, &ap->immediate);
  899. case EADI_W: /* word */
  900. case EAALL_W:
  901. return i16(ip, &ap->immediate);
  902. case EADI_L: /* long */
  903. case EAALL_L:
  904. return i32(ip, &ap->immediate);
  905. case EAFLT: /* floating point - size in bits 10-12 or word 1 */
  906. switch((ip->raw[1]>>10)&0x07)
  907. {
  908. case 0: /* long integer */
  909. return i32(ip, &ap->immediate);
  910. case 1: /* single precision real */
  911. ap->eatype = IREAL;
  912. return getshorts(ip, ap->floater, 2);
  913. case 2: /* extended precision real - not supported */
  914. ap->eatype = IEXT;
  915. return getshorts(ip, ap->floater, 6);
  916. case 3: /* packed decimal real - not supported */
  917. ap->eatype = IPACK;
  918. return getshorts(ip, ap->floater, 12);
  919. case 4: /* integer word */
  920. return i16(ip, &ap->immediate);
  921. case 5: /* double precision real */
  922. ap->eatype = IDBL;
  923. return getshorts(ip, ap->floater, 4);
  924. case 6: /* integer byte */
  925. return i8(ip, &ap->immediate);
  926. default:
  927. ip->errmsg = "bad immediate float data";
  928. return -1;
  929. }
  930. /* not reached */
  931. case IV: /* size encoded in bits 6&7 of opcode word */
  932. default:
  933. switch((ip->raw[0]>>6)&0x03)
  934. {
  935. case 0x00: /* integer byte */
  936. return i8(ip, &ap->immediate);
  937. case 0x01: /* integer word */
  938. return i16(ip, &ap->immediate);
  939. case 0x02: /* integer long */
  940. return i32(ip, &ap->immediate);
  941. default:
  942. ip->errmsg = "bad immediate size";
  943. return -1;
  944. }
  945. /* not reached */
  946. }
  947. }
  948. static int
  949. getdisp(Inst *ip, Operand *ap)
  950. {
  951. int16_t ext;
  952. if (getword(ip, ip->addr+ip->n*2) < 0)
  953. return -1;
  954. ext = ip->raw[ip->n-1];
  955. ap->ext = ext;
  956. if ((ext&0x100) == 0) { /* indexed with 7-bit displacement */
  957. ap->disp = ext&0x7f;
  958. if (ap->disp&0x40)
  959. ap->disp |= ~0x7f;
  960. return 1;
  961. }
  962. switch(ext&0x30) /* first (inner) displacement */
  963. {
  964. case 0x10:
  965. break;
  966. case 0x20:
  967. if (i16(ip, &ap->disp) < 0)
  968. return -1;
  969. break;
  970. case 0x30:
  971. if (i32(ip, &ap->disp) < 0)
  972. return -1;
  973. break;
  974. default:
  975. ip->errmsg = "bad EA displacement";
  976. return -1;
  977. }
  978. switch (ext&0x03) /* outer displacement */
  979. {
  980. case 0x02: /* 16 bit displacement */
  981. return i16(ip, &ap->outer);
  982. case 0x03: /* 32 bit displacement */
  983. return i32(ip, &ap->outer);
  984. default:
  985. break;
  986. }
  987. return 1;
  988. }
  989. static int
  990. ea(Inst *ip, int ea, Operand *ap, int mode)
  991. {
  992. int type, size;
  993. type = 0;
  994. ap->ext = 0;
  995. switch((ea>>3)&0x07)
  996. {
  997. case 0x00:
  998. ap->eatype = Dreg;
  999. type = Dn;
  1000. break;
  1001. case 0x01:
  1002. ap->eatype = Areg;
  1003. type = An;
  1004. break;
  1005. case 0x02:
  1006. ap->eatype = AInd;
  1007. type = Ind;
  1008. break;
  1009. case 0x03:
  1010. ap->eatype = APinc;
  1011. type = Pinc;
  1012. break;
  1013. case 0x04:
  1014. ap->eatype = APdec;
  1015. type = Pdec;
  1016. break;
  1017. case 0x05:
  1018. ap->eatype = ADisp;
  1019. type = Bdisp;
  1020. if (i16(ip, &ap->disp) < 0)
  1021. return -1;
  1022. break;
  1023. case 0x06:
  1024. ap->eatype = BXD;
  1025. type = Bdisp;
  1026. if (getdisp(ip, ap) < 0)
  1027. return -1;
  1028. break;
  1029. case 0x07:
  1030. switch(ea&0x07)
  1031. {
  1032. case 0x00:
  1033. type = Abs;
  1034. ap->eatype = ABS;
  1035. if (i16(ip, &ap->immediate) < 0)
  1036. return -1;
  1037. break;
  1038. case 0x01:
  1039. type = Abs;
  1040. ap->eatype = ABS;
  1041. if (i32(ip, &ap->immediate) < 0)
  1042. return -1;
  1043. break;
  1044. case 0x02:
  1045. type = PCrel;
  1046. ap->eatype = PDisp;
  1047. if (i16(ip, &ap->disp) < 0)
  1048. return -1;
  1049. break;
  1050. case 0x03:
  1051. type = PCrel;
  1052. ap->eatype = PXD;
  1053. if (getdisp(ip, ap) < 0)
  1054. return -1;
  1055. break;
  1056. case 0x04:
  1057. type = Imm;
  1058. if (getimm(ip, ap, mode) < 0)
  1059. return -1;
  1060. break;
  1061. default:
  1062. ip->errmsg = "bad EA mode";
  1063. return -1;
  1064. }
  1065. }
  1066. /* Allowable floating point EAs are restricted for packed,
  1067. * extended, and double precision operands
  1068. */
  1069. if (mode == EAFLT) {
  1070. size = (ip->raw[1]>>10)&0x07;
  1071. if (size == 2 || size == 3 || size == 5)
  1072. mode = EAM;
  1073. else
  1074. mode = EADI;
  1075. }
  1076. if (!(validea[mode]&type)) {
  1077. ip->errmsg = "invalid EA";
  1078. return -1;
  1079. }
  1080. return 1;
  1081. }
  1082. static int
  1083. decode(Inst *ip, Optable *op)
  1084. {
  1085. int i, t, mode;
  1086. Operand *ap;
  1087. int16_t opcode;
  1088. opcode = ip->raw[0];
  1089. for (i = 0; i < nelem(op->opdata) && op->opdata[i]; i++) {
  1090. ap = &ip->and[i];
  1091. mode = op->opdata[i];
  1092. switch(mode)
  1093. {
  1094. case EAPI: /* normal EA modes */
  1095. case EACA:
  1096. case EACAD:
  1097. case EACAPI:
  1098. case EACAPD:
  1099. case EAMA:
  1100. case EADA:
  1101. case EAA:
  1102. case EAC:
  1103. case EACPI:
  1104. case EACD:
  1105. case EAD:
  1106. case EAM:
  1107. case EAM_B:
  1108. case EADI:
  1109. case EADI_L:
  1110. case EADI_W:
  1111. case EAALL:
  1112. case EAALL_L:
  1113. case EAALL_W:
  1114. case EAALL_B:
  1115. case EAFLT:
  1116. if (ea(ip, opcode&0x3f, ap, mode) < 0)
  1117. return -1;
  1118. break;
  1119. case EADDA: /* stupid bit flop required */
  1120. t = ((opcode>>9)&0x07)|((opcode>>3)&0x38);
  1121. if (ea(ip, t, ap, EADA)< 0)
  1122. return -1;
  1123. break;
  1124. case BREAC: /* EAC JMP or CALL operand */
  1125. if (ea(ip, opcode&0x3f, ap, EAC) < 0)
  1126. return -1;
  1127. break;
  1128. case OP8: /* weird movq instruction */
  1129. ap->eatype = IMM;
  1130. ap->immediate = opcode&0xff;
  1131. if (opcode&0x80)
  1132. ap->immediate |= ~0xff;
  1133. break;
  1134. case I8: /* must be two-word opcode */
  1135. ap->eatype = IMM;
  1136. ap->immediate = ip->raw[1]&0xff;
  1137. if (ap->immediate&0x80)
  1138. ap->immediate |= ~0xff;
  1139. break;
  1140. case I16: /* 16 bit immediate */
  1141. case BR16:
  1142. ap->eatype = IMM;
  1143. if (i16(ip, &ap->immediate) < 0)
  1144. return -1;
  1145. break;
  1146. case C16: /* CAS2 16 bit immediate */
  1147. ap->eatype = IMM;
  1148. if (i16(ip, &ap->immediate) < 0)
  1149. return -1;
  1150. if (ap->immediate & 0x0e38) {
  1151. ip->errmsg = "bad CAS2W operand";
  1152. return 0;
  1153. }
  1154. break;
  1155. case I32: /* 32 bit immediate */
  1156. case BR32:
  1157. ap->eatype = IMM;
  1158. if (i32(ip, &ap->immediate) < 0)
  1159. return -1;
  1160. break;
  1161. case IV: /* immediate data depends on size field */
  1162. if (getimm(ip, ap, IV) < 0)
  1163. return -1;
  1164. break;
  1165. case BR8: /* branch displacement format */
  1166. ap->eatype = IMM;
  1167. ap->immediate = opcode&0xff;
  1168. if (ap->immediate == 0) {
  1169. if (i16(ip, &ap->immediate) < 0)
  1170. return -1;
  1171. } else if (ap->immediate == 0xff) {
  1172. if (i32(ip, &ap->immediate) < 0)
  1173. return -1;
  1174. } else if (ap->immediate & 0x80)
  1175. ap->immediate |= ~0xff;
  1176. break;
  1177. case STACK: /* Dummy operand type for Return instructions */
  1178. default:
  1179. break;
  1180. }
  1181. }
  1182. return 1;
  1183. }
  1184. static Optable *
  1185. instruction(Inst *ip)
  1186. {
  1187. uint16_t opcode, op2;
  1188. Optable *op;
  1189. int class;
  1190. ip->n = 0;
  1191. if (getword(ip, ip->addr) < 0)
  1192. return 0;
  1193. opcode = ip->raw[0];
  1194. if (get2(mymap, ip->addr+2, &op2) < 0)
  1195. op2 = 0;
  1196. class = (opcode>>12)&0x0f;
  1197. for (op = optables[class]; op && op->format; op++) {
  1198. if (op->opcode != (opcode&op->mask0))
  1199. continue;
  1200. if (op->op2 != (op2&op->mask1))
  1201. continue;
  1202. if (op->mask1)
  1203. ip->raw[ip->n++] = op2;
  1204. return op;
  1205. }
  1206. ip->errmsg = "Invalid opcode";
  1207. return 0;
  1208. }
  1209. #pragma varargck argpos bprint 2
  1210. static void
  1211. bprint(Inst *i, char *fmt, ...)
  1212. {
  1213. va_list arg;
  1214. va_start(arg, fmt);
  1215. i->curr = vseprint(i->curr, i->end, fmt, arg);
  1216. va_end(arg);
  1217. }
  1218. static char *regname[] =
  1219. {
  1220. "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "A0",
  1221. "A1", "A2", "A3", "A4", "A5", "A6", "A7", "PC", "SB"
  1222. };
  1223. static void
  1224. plocal(Inst *ip, Operand *ap)
  1225. {
  1226. int ret;
  1227. int32_t offset;
  1228. uint64_t moved;
  1229. Symbol s;
  1230. offset = ap->disp;
  1231. if (!findsym(ip->addr, CTEXT, &s))
  1232. goto none;
  1233. moved = pc2sp(ip->addr);
  1234. if (moved == -1)
  1235. goto none;
  1236. if (offset > moved) { /* above frame - must be argument */
  1237. offset -= moved;
  1238. ret = getauto(&s, offset-mach->szaddr, CPARAM, &s);
  1239. } else /* below frame - must be automatic */
  1240. ret = getauto(&s, moved-offset, CPARAM, &s);
  1241. if (ret)
  1242. bprint(ip, "%s+%lux", s.name, offset);
  1243. else
  1244. none: bprint(ip, "%lux", ap->disp);
  1245. }
  1246. /*
  1247. * this guy does all the work of printing the base and index component
  1248. * of an EA.
  1249. */
  1250. static int
  1251. pidx(Inst *ip, int ext, int reg, char *bfmt, char *ifmt, char *nobase)
  1252. {
  1253. char *s;
  1254. int printed;
  1255. char buf[512];
  1256. printed = 1;
  1257. if (ext&0x80) { /* Base suppressed */
  1258. if (reg == 16)
  1259. bprint(ip, bfmt, "(ZPC)");
  1260. else if (nobase)
  1261. bprint(ip, nobase);
  1262. else
  1263. printed = 0;
  1264. } else /* format base reg */
  1265. bprint(ip, bfmt, regname[reg]);
  1266. if (ext & 0x40) /* index suppressed */
  1267. return printed;
  1268. switch ((ext>>9)&0x03)
  1269. {
  1270. case 0x01:
  1271. s = "*2";
  1272. break;
  1273. case 0x02:
  1274. s = "*4";
  1275. break;
  1276. case 0x03:
  1277. s = "*8";
  1278. break;
  1279. default:
  1280. if (ext&0x80)
  1281. s = "*1";
  1282. else
  1283. s = "";
  1284. break;
  1285. }
  1286. sprint(buf, "%s.%c%s", regname[(ext>>12)&0x0f], (ext&0x800) ? 'L' : 'W', s);
  1287. if (!printed)
  1288. bprint(ip, ifmt, buf);
  1289. else
  1290. bprint(ip, "(%s)", buf);
  1291. return 1;
  1292. }
  1293. static void
  1294. prindex(Inst *ip, int reg, Operand *ap)
  1295. {
  1296. int16_t ext;
  1297. int left;
  1298. int disp;
  1299. left = ip->end-ip->curr;
  1300. if (left <= 0)
  1301. return;
  1302. ext = ap->ext;
  1303. disp = ap->disp;
  1304. /* look for static base register references */
  1305. if ((ext&0xa0) == 0x20 && reg == 14 && mach->sb && disp) {
  1306. reg = 17; /* "A6" -> "SB" */
  1307. disp += mach->sb;
  1308. }
  1309. if ((ext&0x100) == 0) { /* brief form */
  1310. if (reg == 15)
  1311. plocal(ip, ap);
  1312. else if (disp)
  1313. ip->curr += symoff(ip->curr, left, disp, CANY);
  1314. pidx(ip, ext&0xff00, reg, "(%s)", "(%s)", 0);
  1315. return;
  1316. }
  1317. switch(ext&0x3f) /* bd size, && i/is */
  1318. {
  1319. case 0x10:
  1320. if (!pidx(ip, ext, reg, "(%s)", "(%s)", 0))
  1321. bprint(ip, "#0");
  1322. break;
  1323. case 0x11:
  1324. if (pidx(ip, ext, reg, "((%s)", "((%s)", 0))
  1325. bprint(ip, ")");
  1326. else
  1327. bprint(ip, "#0");
  1328. break;
  1329. case 0x12:
  1330. case 0x13:
  1331. ip->curr += symoff(ip->curr, left, ap->outer, CANY);
  1332. if (pidx(ip, ext, reg, "((%s)", "((%s)", 0))
  1333. bprint(ip, ")");
  1334. break;
  1335. case 0x15:
  1336. if (!pidx(ip, ext, reg, "((%s))", "(%s)", 0))
  1337. bprint(ip, "#0");
  1338. break;
  1339. case 0x16:
  1340. case 0x17:
  1341. ip->curr += symoff(ip->curr, left, ap->outer, CANY);
  1342. pidx(ip, ext, reg, "((%s))", "(%s)", 0);
  1343. break;
  1344. case 0x20:
  1345. case 0x30:
  1346. if (reg == 15)
  1347. plocal(ip, ap);
  1348. else
  1349. ip->curr += symoff(ip->curr, left, disp, CANY);
  1350. pidx(ip, ext, reg, "(%s)", "(%s)", 0);
  1351. break;
  1352. case 0x21:
  1353. case 0x31:
  1354. *ip->curr++ = '(';
  1355. if (reg == 15)
  1356. plocal(ip, ap);
  1357. else
  1358. ip->curr += symoff(ip->curr, left-1, disp, CANY);
  1359. pidx(ip, ext, reg, "(%s)", "(%s)", 0);
  1360. bprint(ip, ")");
  1361. break;
  1362. case 0x22:
  1363. case 0x23:
  1364. case 0x32:
  1365. case 0x33:
  1366. ip->curr += symoff(ip->curr, left, ap->outer, CANY);
  1367. bprint(ip, "(");
  1368. if (reg == 15)
  1369. plocal(ip, ap);
  1370. else
  1371. ip->curr += symoff(ip->curr, ip->end-ip->curr, disp, CANY);
  1372. pidx(ip, ext, reg, "(%s)", "(%s)", 0);
  1373. bprint(ip, ")");
  1374. break;
  1375. case 0x25:
  1376. case 0x35:
  1377. *ip->curr++ = '(';
  1378. if (reg == 15)
  1379. plocal(ip, ap);
  1380. else
  1381. ip->curr += symoff(ip->curr, left-1, disp, CANY);
  1382. if (!pidx(ip, ext, reg, "(%s))", "(%s)", "())"))
  1383. bprint(ip, ")");
  1384. break;
  1385. case 0x26:
  1386. case 0x27:
  1387. case 0x36:
  1388. case 0x37:
  1389. ip->curr += symoff(ip->curr, left, ap->outer, CANY);
  1390. bprint(ip, "(");
  1391. if (reg == 15)
  1392. plocal(ip, ap);
  1393. else
  1394. ip->curr += symoff(ip->curr, ip->end-ip->curr, disp, CANY);
  1395. pidx(ip, ext, reg, "(%s))", "(%s)", "())");
  1396. break;
  1397. default:
  1398. bprint(ip, "??%x??", ext);
  1399. ip->errmsg = "bad EA";
  1400. break;
  1401. }
  1402. }
  1403. static void
  1404. pea(int reg, Inst *ip, Operand *ap)
  1405. {
  1406. int i, left;
  1407. left = ip->end-ip->curr;
  1408. if (left < 0)
  1409. return;
  1410. switch(ap->eatype)
  1411. {
  1412. case Dreg:
  1413. bprint(ip, "R%d", reg);
  1414. break;
  1415. case Areg:
  1416. bprint(ip, "A%d", reg);
  1417. break;
  1418. case AInd:
  1419. bprint(ip, "(A%d)", reg);
  1420. break;
  1421. case APinc:
  1422. bprint(ip, "(A%d)+", reg);
  1423. break;
  1424. case APdec:
  1425. bprint(ip, "-(A%d)", reg);
  1426. break;
  1427. case PDisp:
  1428. ip->curr += symoff(ip->curr, left, ip->addr+2+ap->disp, CANY);
  1429. break;
  1430. case PXD:
  1431. prindex(ip, 16, ap);
  1432. break;
  1433. case ADisp: /* references off the static base */
  1434. if (reg == 6 && mach->sb && ap->disp) {
  1435. ip->curr += symoff(ip->curr, left, ap->disp+mach->sb, CANY);
  1436. bprint(ip, "(SB)");
  1437. break;
  1438. }
  1439. /* reference autos and parameters off the stack */
  1440. if (reg == 7)
  1441. plocal(ip, ap);
  1442. else
  1443. ip->curr += symoff(ip->curr, left, ap->disp, CANY);
  1444. bprint(ip, "(A%d)", reg);
  1445. break;
  1446. case BXD:
  1447. prindex(ip, reg+8, ap);
  1448. break;
  1449. case ABS:
  1450. ip->curr += symoff(ip->curr, left, ap->immediate, CANY);
  1451. bprint(ip, "($0)");
  1452. break;
  1453. case IMM:
  1454. *ip->curr++ = '$';
  1455. ip->curr += symoff(ip->curr, left-1, ap->immediate, CANY);
  1456. break;
  1457. case IREAL:
  1458. *ip->curr++ = '$';
  1459. ip->curr += beieeesftos(ip->curr, left-1, (void*) ap->floater);
  1460. break;
  1461. case IDBL:
  1462. *ip->curr++ = '$';
  1463. ip->curr += beieeedftos(ip->curr, left-1, (void*) ap->floater);
  1464. break;
  1465. case IPACK:
  1466. bprint(ip, "$#");
  1467. for (i = 0; i < 24 && ip->curr < ip->end-1; i++) {
  1468. _hexify(ip->curr, ap->floater[i], 1);
  1469. ip->curr += 2;
  1470. }
  1471. break;
  1472. case IEXT:
  1473. bprint(ip, "$#");
  1474. ip->curr += beieee80ftos(ip->curr, left-2, (void*)ap->floater);
  1475. break;
  1476. default:
  1477. bprint(ip, "??%x??", ap->eatype);
  1478. ip->errmsg = "bad EA type";
  1479. break;
  1480. }
  1481. }
  1482. static char *cctab[] = { "F", "T", "HI", "LS", "CC", "CS", "NE", "EQ",
  1483. "VC", "VS", "PL", "MI", "GE", "LT", "GT", "LE" };
  1484. static char *fcond[] =
  1485. {
  1486. "F", "EQ", "OGT", "OGE", "OLT", "OLE", "OGL", "OR",
  1487. "UN", "UEQ", "UGT", "UGE", "ULT", "ULE", "NE", "T",
  1488. "SF", "SEQ", "GT", "GE", "LT", "LE", "GL", "GLE",
  1489. "NGLE", "NGL", "NLE", "NLT", "NGE", "NGT", "SNE", "ST"
  1490. };
  1491. static char *cachetab[] = { "NC", "DC", "IC", "BC" };
  1492. static char *mmutab[] = { "TC", "??", "SRP", "CRP" };
  1493. static char *crtab0[] =
  1494. {
  1495. "SFC", "DFC", "CACR", "TC", "ITT0", "ITT1", "DTT0", "DTT1",
  1496. };
  1497. static char *crtab1[] =
  1498. {
  1499. "USP", "VBR", "CAAR", "MSP", "ISP", "MMUSR", "URP", "SRP",
  1500. };
  1501. static char typetab[] = { 'L', 'S', 'X', 'P', 'W', 'D', 'B', '?', };
  1502. static char sztab[] = {'?', 'B', 'W', 'L', '?' };
  1503. static void
  1504. formatins(char *fmt, Inst *ip)
  1505. {
  1506. int16_t op, w1;
  1507. int r1, r2;
  1508. int currand;
  1509. op = ip->raw[0];
  1510. w1 = ip->raw[1];
  1511. currand = 0;
  1512. for (; *fmt && ip->curr < ip->end; fmt++) {
  1513. if (*fmt != '%')
  1514. *ip->curr++ = *fmt;
  1515. else switch(*++fmt)
  1516. {
  1517. case '%':
  1518. *ip->curr++ = '%';
  1519. break;
  1520. case 'a': /* register number; word 1:[0-2] */
  1521. *ip->curr++ = (w1&0x07)+'0';
  1522. break;
  1523. case 'c': /* condition code; opcode: [8-11] */
  1524. bprint(ip, cctab[(op>>8)&0x0f]);
  1525. break;
  1526. case 'd': /* shift direction; opcode: [8] */
  1527. if (op&0x100)
  1528. *ip->curr++ = 'L';
  1529. else
  1530. *ip->curr++ = 'R';
  1531. break;
  1532. case 'e': /* source effective address */
  1533. pea(op&0x07, ip, &ip->and[currand++]);
  1534. break;
  1535. case 'f': /* trap vector; op code: [0-3] */
  1536. bprint(ip, "%x", op&0x0f);
  1537. break;
  1538. case 'h': /* register number; word 1: [5-7] */
  1539. *ip->curr++ = (w1>>5)&0x07+'0';
  1540. break;
  1541. case 'i': /* immediate operand */
  1542. ip->curr += symoff(ip->curr, ip->end-ip->curr,
  1543. ip->and[currand++].immediate, CANY);
  1544. break;
  1545. case 'j': /* data registers; word 1: [0-2] & [12-14] */
  1546. r1 = w1&0x07;
  1547. r2 = (w1>>12)&0x07;
  1548. if (r1 == r2)
  1549. bprint(ip, "R%d", r1);
  1550. else
  1551. bprint(ip, "R%d:R%d", r2, r1);
  1552. break;
  1553. case 'k': /* k factor; word 1 [0-6] */
  1554. bprint(ip, "%x", w1&0x7f);
  1555. break;
  1556. case 'm': /* register mask; word 1 [0-7] */
  1557. bprint(ip, "%x", w1&0xff);
  1558. break;
  1559. case 'o': /* bit field offset; word1: [6-10] */
  1560. bprint(ip, "%d", (w1>>6)&0x3f);
  1561. break;
  1562. case 'p': /* conditional predicate; opcode: [0-5]
  1563. only bits 0-4 are defined */
  1564. bprint(ip, fcond[op&0x1f]);
  1565. break;
  1566. case 'q': /* 3-bit immediate value; opcode[9-11] */
  1567. r1 = (op>>9)&0x07;
  1568. if (r1 == 0)
  1569. *ip->curr++ = '8';
  1570. else
  1571. *ip->curr++ = r1+'0';
  1572. break;
  1573. case 'r': /* register type & number; word 1: [12-15] */
  1574. bprint(ip, regname[(w1>>12)&0x0f]);
  1575. break;
  1576. case 's': /* size; opcode [6-7] */
  1577. *ip->curr = sztab[((op>>6)&0x03)+1];
  1578. if (*ip->curr++ == '?')
  1579. ip->errmsg = "bad size code";
  1580. break;
  1581. case 't': /* text offset */
  1582. ip->curr += symoff(ip->curr, ip->end-ip->curr,
  1583. ip->and[currand++].immediate+ip->addr+2, CTEXT);
  1584. break;
  1585. case 'u': /* register number; word 1: [6-8] */
  1586. *ip->curr++ = ((w1>>6)&0x07)+'0';
  1587. break;
  1588. case 'w': /* bit field width; word 1: [0-4] */
  1589. bprint(ip, "%d", w1&0x0f);
  1590. break;
  1591. case 'x': /* register number; opcode: [9-11] */
  1592. *ip->curr++ = ((op>>9)&0x07)+'0';
  1593. break;
  1594. case 'y': /* register number; opcode: [0-2] */
  1595. *ip->curr++ = (op&0x07)+'0';
  1596. break;
  1597. case 'z': /* shift count; opcode: [9-11] */
  1598. *ip->curr++ = ((op>>9)&0x07)+'0';
  1599. break;
  1600. case 'A': /* register number; word 2: [0-2] */
  1601. *ip->curr++ = (ip->raw[2]&0x07)+'0';
  1602. break;
  1603. case 'B': /* float source reg; word 1: [10-12] */
  1604. *ip->curr++ = ((w1>>10)&0x07)+'0';
  1605. break;
  1606. case 'C': /* cache identifier; opcode: [6-7] */
  1607. bprint(ip, cachetab[(op>>6)&0x03]);
  1608. break;
  1609. case 'D': /* float dest reg; word 1: [7-9] */
  1610. *ip->curr++ = ((w1>>7)&0x07)+'0';
  1611. break;
  1612. case 'E': /* destination EA; opcode: [6-11] */
  1613. pea((op>>9)&0x07, ip, &ip->and[currand++]);
  1614. break;
  1615. case 'F': /* float dest register(s); word 1: [7-9] & [10-12] */
  1616. r1 = (w1>>7)&0x07;
  1617. r2 = (w1>>10)&0x07;
  1618. if (r1 == r2)
  1619. bprint(ip, "F%d", r1);
  1620. else
  1621. bprint(ip, "F%d,F%d", r2, r1);
  1622. break;
  1623. case 'H': /* MMU register; word 1 [10-13] */
  1624. bprint(ip, mmutab[(w1>>10)&0x03]);
  1625. if (ip->curr[-1] == '?')
  1626. ip->errmsg = "bad mmu register";
  1627. break;
  1628. case 'I': /* MMU function code mask; word 1: [5-8] */
  1629. bprint(ip, "%x", (w1>>4)&0x0f);
  1630. break;
  1631. case 'K': /* dynamic k-factor register; word 1: [5-8] */
  1632. bprint(ip, "%d", (w1>>4)&0x0f);
  1633. break;
  1634. case 'L': /* MMU function code; word 1: [0-6] */
  1635. if (w1&0x10)
  1636. bprint(ip, "%x", w1&0x0f);
  1637. else if (w1&0x08)
  1638. bprint(ip, "R%d",w1&0x07);
  1639. else if (w1&0x01)
  1640. bprint(ip, "DFC");
  1641. else
  1642. bprint(ip, "SFC");
  1643. break;
  1644. case 'N': /* control register; word 1: [0-11] */
  1645. r1 = w1&0xfff;
  1646. if (r1&0x800)
  1647. bprint(ip, crtab1[r1&0x07]);
  1648. else
  1649. bprint(ip, crtab0[r1&0x07]);
  1650. break;
  1651. case 'P': /* conditional predicate; word 1: [0-5] */
  1652. bprint(ip, fcond[w1&0x1f]);
  1653. break;
  1654. case 'R': /* register type & number; word 2 [12-15] */
  1655. bprint(ip, regname[(ip->raw[2]>>12)&0x0f]);
  1656. break;
  1657. case 'S': /* float source type code; word 1: [10-12] */
  1658. *ip->curr = typetab[(w1>>10)&0x07];
  1659. if (*ip->curr++ == '?')
  1660. ip->errmsg = "bad float type";
  1661. break;
  1662. case 'U': /* register number; word 2: [6-8] */
  1663. *ip->curr++ = ((ip->raw[2]>>6)&0x07)+'0';
  1664. break;
  1665. case 'Z': /* ATC level number; word 1: [10-12] */
  1666. bprint(ip, "%x", (w1>>10)&0x07);
  1667. break;
  1668. case '1': /* effective address in second operand*/
  1669. pea(op&0x07, ip, &ip->and[1]);
  1670. break;
  1671. default:
  1672. bprint(ip, "%%%c", *fmt);
  1673. break;
  1674. }
  1675. }
  1676. *ip->curr = 0; /* there's always room for 1 byte */
  1677. }
  1678. static int
  1679. dispsize(Inst *ip)
  1680. {
  1681. uint16_t ext;
  1682. static int dsize[] = {0, 0, 1, 2}; /* in words */
  1683. if (get2(mymap, ip->addr+ip->n*2, &ext) < 0)
  1684. return -1;
  1685. if ((ext&0x100) == 0)
  1686. return 1;
  1687. return dsize[(ext>>4)&0x03]+dsize[ext&0x03]+1;
  1688. }
  1689. static int
  1690. immsize(Inst *ip, int mode)
  1691. {
  1692. static int fsize[] = { 2, 2, 6, 12, 1, 4, 1, -1 };
  1693. static int isize[] = { 1, 1, 2, -1 };
  1694. switch(mode)
  1695. {
  1696. case EAM_B: /* byte */
  1697. case EAALL_B:
  1698. case EADI_W: /* word */
  1699. case EAALL_W:
  1700. return 1;
  1701. case EADI_L: /* long */
  1702. case EAALL_L:
  1703. return 2;
  1704. case EAFLT: /* floating point - size in bits 10-12 or word 1 */
  1705. return fsize[(ip->raw[1]>>10)&0x07];
  1706. case IV: /* size encoded in bits 6&7 of opcode word */
  1707. default:
  1708. return isize[(ip->raw[0]>>6)&0x03];
  1709. }
  1710. }
  1711. static int
  1712. easize(Inst *ip, int ea, int mode)
  1713. {
  1714. switch((ea>>3)&0x07)
  1715. {
  1716. case 0x00:
  1717. case 0x01:
  1718. case 0x02:
  1719. case 0x03:
  1720. case 0x04:
  1721. return 0;
  1722. case 0x05:
  1723. return 1;
  1724. case 0x06:
  1725. return dispsize(ip);
  1726. case 0x07:
  1727. switch(ea&0x07)
  1728. {
  1729. case 0x00:
  1730. case 0x02:
  1731. return 1;
  1732. case 0x01:
  1733. return 2;
  1734. case 0x03:
  1735. return dispsize(ip);
  1736. case 0x04:
  1737. return immsize(ip, mode);
  1738. default:
  1739. return -1;
  1740. }
  1741. }
  1742. return -1;
  1743. }
  1744. static int
  1745. instrsize(Inst *ip, Optable *op)
  1746. {
  1747. int i, t, mode;
  1748. int16_t opcode;
  1749. opcode = ip->raw[0];
  1750. for (i = 0; i < nelem(op->opdata) && op->opdata[i]; i++) {
  1751. mode = op->opdata[i];
  1752. switch(mode)
  1753. {
  1754. case EAPI: /* normal EA modes */
  1755. case EACA:
  1756. case EACAD:
  1757. case EACAPI:
  1758. case EACAPD:
  1759. case EAMA:
  1760. case EADA:
  1761. case EAA:
  1762. case EAC:
  1763. case EACPI:
  1764. case EACD:
  1765. case EAD:
  1766. case EAM:
  1767. case EAM_B:
  1768. case EADI:
  1769. case EADI_L:
  1770. case EADI_W:
  1771. case EAALL:
  1772. case EAALL_L:
  1773. case EAALL_W:
  1774. case EAALL_B:
  1775. case EAFLT:
  1776. t = easize(ip, opcode&0x3f, mode);
  1777. if (t < 0)
  1778. return -1;
  1779. ip->n += t;
  1780. break;
  1781. case EADDA: /* stupid bit flop required */
  1782. t = ((opcode>>9)&0x07)|((opcode>>3)&0x38);
  1783. t = easize(ip, t, mode);
  1784. if (t < 0)
  1785. return -1;
  1786. ip->n += t;
  1787. break;
  1788. case BREAC: /* EAC JMP or CALL operand */
  1789. /* easy displacements for follow set */
  1790. if ((opcode&0x038) == 0x28 || (opcode&0x3f) == 0x3a) {
  1791. if (i16(ip, &ip->and[i].immediate) < 0)
  1792. return -1;
  1793. } else {
  1794. t = easize(ip, opcode&0x3f, mode);
  1795. if (t < 0)
  1796. return -1;
  1797. ip->n += t;
  1798. }
  1799. break;
  1800. case I16: /* 16 bit immediate */
  1801. case C16: /* CAS2 16 bit immediate */
  1802. ip->n++;
  1803. break;
  1804. case BR16: /* 16 bit branch displacement */
  1805. if (i16(ip, &ip->and[i].immediate) < 0)
  1806. return -1;
  1807. break;
  1808. case BR32: /* 32 bit branch displacement */
  1809. if (i32(ip, &ip->and[i].immediate) < 0)
  1810. return -1;
  1811. break;
  1812. case I32: /* 32 bit immediate */
  1813. ip->n += 2;
  1814. break;
  1815. case IV: /* immediate data depends on size field */
  1816. t = (ip->raw[0]>>6)&0x03;
  1817. if (t < 2)
  1818. ip->n++;
  1819. else if (t == 2)
  1820. ip->n += 2;
  1821. else
  1822. return -1;
  1823. break;
  1824. case BR8: /* loony branch displacement format */
  1825. t = opcode&0xff;
  1826. if (t == 0) {
  1827. if (i16(ip, &ip->and[i].immediate) < 0)
  1828. return -1;
  1829. } else if (t == 0xff) {
  1830. if (i32(ip, &ip->and[i].immediate) < 0)
  1831. return -1;
  1832. } else {
  1833. ip->and[i].immediate = t;
  1834. if (t & 0x80)
  1835. ip->and[i].immediate |= ~0xff;
  1836. }
  1837. break;
  1838. case STACK: /* Dummy operand for Return instructions */
  1839. case OP8: /* weird movq instruction */
  1840. case I8: /* must be two-word opcode */
  1841. default:
  1842. break;
  1843. }
  1844. }
  1845. return 1;
  1846. }
  1847. static int
  1848. eaval(Inst *ip, Operand *ap, Rgetter rget)
  1849. {
  1850. int reg;
  1851. char buf[8];
  1852. reg = ip->raw[0]&0x07;
  1853. switch(ap->eatype)
  1854. {
  1855. case AInd:
  1856. sprint(buf, "A%d", reg);
  1857. return (*rget)(mymap, buf);
  1858. case PDisp:
  1859. return ip->addr+2+ap->disp;
  1860. case ADisp:
  1861. sprint(buf, "A%d", reg);
  1862. return ap->disp+(*rget)(mymap, buf);
  1863. case ABS:
  1864. return ap->immediate;
  1865. default:
  1866. return 0;
  1867. }
  1868. }
  1869. static int
  1870. m68020instlen(Map *map, uint64_t pc)
  1871. {
  1872. Inst i;
  1873. Optable *op;
  1874. mymap = map;
  1875. i.addr = pc;
  1876. i.errmsg = 0;
  1877. op = instruction(&i);
  1878. if (op && instrsize(&i, op) > 0)
  1879. return i.n*2;
  1880. return -1;
  1881. }
  1882. static int
  1883. m68020foll(Map *map, uint64_t pc, Rgetter rget, uint64_t *foll)
  1884. {
  1885. int j;
  1886. Inst i;
  1887. uint32_t l;
  1888. Optable *op;
  1889. mymap = map;
  1890. i.addr = pc;
  1891. i.errmsg = 0;
  1892. op = instruction(&i);
  1893. if (op == 0 || instrsize(&i, op) < 0)
  1894. return -1;
  1895. for (j = 0; j < nelem(op->opdata) && op->opdata[j]; j++) {
  1896. switch(op->opdata[j])
  1897. {
  1898. case BREAC: /* CALL, JMP, JSR */
  1899. foll[0] = pc+2+eaval(&i, &i.and[j], rget);
  1900. return 1;
  1901. case BR8: /* Bcc, BSR, & BRA */
  1902. case BR16: /* FBcc, FDBcc, DBcc */
  1903. case BR32: /* FBcc */
  1904. foll[0] = pc+i.n*2;
  1905. foll[1] = pc+2+i.and[j].immediate;
  1906. return 2;
  1907. case STACK: /* RTR, RTS, RTD */
  1908. if (get4(map, (*rget)(map, mach->sp), &l) < 0)
  1909. return -1;
  1910. *foll = l;
  1911. return 1;
  1912. default:
  1913. break;
  1914. }
  1915. }
  1916. foll[0] = pc+i.n*2;
  1917. return 1;
  1918. }
  1919. static int
  1920. m68020inst(Map *map, uint64_t pc, char modifier, char *buf, int n)
  1921. {
  1922. Inst i;
  1923. Optable *op;
  1924. USED(modifier);
  1925. mymap = map;
  1926. i.addr = pc;
  1927. i.curr = buf;
  1928. i.end = buf+n-1;
  1929. i.errmsg = 0;
  1930. op = instruction(&i);
  1931. if (!op)
  1932. return -1;
  1933. if (decode(&i, op) > 0)
  1934. formatins(op->format, &i);
  1935. if (i.errmsg) {
  1936. if (i.curr != buf)
  1937. bprint(&i, "\t\t;");
  1938. bprint(&i, "%s: ", i.errmsg);
  1939. dumpinst(&i, i.curr, i.end-i.curr);
  1940. }
  1941. return i.n*2;
  1942. }
  1943. static int
  1944. m68020das(Map *map, uint64_t pc, char *buf, int n)
  1945. {
  1946. Inst i;
  1947. Optable *op;
  1948. mymap = map;
  1949. i.addr = pc;
  1950. i.curr = buf;
  1951. i.end = buf+n-1;
  1952. i.errmsg = 0;
  1953. op = instruction(&i);
  1954. if (!op)
  1955. return -1;
  1956. decode(&i, op);
  1957. if (i.errmsg)
  1958. bprint(&i, "%s: ", i.errmsg);
  1959. dumpinst(&i, i.curr, i.end-i.curr);
  1960. return i.n*2;
  1961. }