2db.c 60 KB

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