home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / 486DIS_C / TABLE.C < prev    next >
Text File  |  1992-05-26  |  13KB  |  299 lines

  1. /* Percent tokens in strings:
  2.    First char after '%':
  3.     A - direct address
  4.     C - reg of r/m picks control register
  5.     D - reg of r/m picks debug register
  6.     E - r/m picks operand
  7.     F - flags register
  8.     G - reg of r/m picks general register
  9.     I - immediate data
  10.     J - relative IP offset
  11. +       K - call/jmp distance
  12.     M - r/m picks memory
  13.     O - no r/m, offset only
  14.     R - mod of r/m picks register only
  15.     S - reg of r/m picks segment register
  16.     T - reg of r/m picks test register
  17.     X - DS:ESI
  18.     Y - ES:EDI
  19.     2 - prefix of two-byte opcode
  20. +       e - put in 'e' if use32 (second char is part of reg name)
  21. +           put in 'w' for use16 or 'd' for use32 (second char is 'w')
  22. +       j - put in 'e' in jcxz if prefix==0x66
  23.     f - floating point (second char is esc value)
  24.     g - do r/m group 'n', n==0..7
  25.     p - prefix
  26.     s - size override (second char is a,o)
  27. +       d - put d if double arg, nothing otherwise (pushfd, popfd &c)
  28. +       w - put w if word, d if double arg, nothing otherwise (lodsw/lodsd)
  29. +       P - simple prefix
  30.  
  31.    Second char after '%':
  32.     a - two words in memory (BOUND)
  33.     b - byte
  34.     c - byte or word
  35.     d - dword
  36. +       f - far call/jmp
  37. +       n - near call/jmp
  38.         p - 32 or 48 bit pointer
  39. +       q - byte/word thingy
  40.     s - six byte pseudo-descriptor
  41.     v - word or dword
  42.         w - word
  43. +       x - sign extended byte
  44.     F - use floating regs in mod/rm
  45.     1-8 - group number, esc value, etc
  46. */
  47.  
  48. /* watch out for aad && aam with odd operands */
  49.  
  50.  
  51. char *opmap1[256] = {
  52. /* 0 */
  53.   "add %Eb,%Gb",      "add %Ev,%Gv",     "add %Gb,%Eb",    "add %Gv,%Ev",
  54.   "add al,%Ib",       "add %eax,%Iv",    "push es",        "pop es",
  55.   "or %Eb,%Gb",       "or %Ev,%Gv",      "or %Gb,%Eb",     "or %Gv,%Ev",
  56.   "or al,%Ib",        "or %eax,%Iv",     "push cs",        "%2 ",
  57. /* 1 */
  58.   "adc %Eb,%Gb",      "adc %Ev,%Gv",     "adc %Gb,%Eb",    "adc %Gv,%Ev",
  59.   "adc al,%Ib",       "adc %eax,%Iv",    "push ss",        "pop ss",
  60.   "sbb %Eb,%Gb",      "sbb %Ev,%Gv",     "sbb %Gb,%Eb",    "sbb %Gv,%Ev",
  61.   "sbb al,%Ib",       "sbb %eax,%Iv",    "push ds",        "pop ds",
  62. /* 2 */
  63.   "and %Eb,%Gb",      "and %Ev,%Gv",     "and %Gb,%Eb",    "and %Gv,%Ev",
  64.   "and al,%Ib",       "and %eax,%Iv",    "%pe",            "daa",
  65.   "sub %Eb,%Gb",      "sub %Ev,%Gv",     "sub %Gb,%Eb",    "sub %Gv,%Ev",
  66.   "sub al,%Ib",       "sub %eax,%Iv",    "%pc",            "das",
  67. /* 3 */
  68.   "xor %Eb,%Gb",      "xor %Ev,%Gv",     "xor %Gb,%Eb",    "xor %Gv,%Ev",
  69.   "xor al,%Ib",       "xor %eax,%Iv",    "%ps",            "aaa",
  70.   "cmp %Eb,%Gb",      "cmp %Ev,%Gv",     "cmp %Gb,%Eb",    "cmp %Gv,%Ev",
  71.   "cmp al,%Ib",       "cmp %eax,%Iv",    "%pd",            "aas",
  72. /* 4 */
  73.   "inc %eax",         "inc %ecx",        "inc %edx",       "inc %ebx",
  74.   "inc %esp",         "inc %ebp",        "inc %esi",       "inc %edi",
  75.   "dec %eax",         "dec %ecx",        "dec %edx",       "dec %ebx",
  76.   "dec %esp",         "dec %ebp",        "dec %esi",       "dec %edi",
  77. /* 5 */
  78.   "push %eax",        "push %ecx",       "push %edx",      "push %ebx",
  79.   "push %esp",        "push %ebp",       "push %esi",      "push %edi",
  80.   "pop %eax",         "pop %ecx",        "pop %edx",       "pop %ebx",
  81.   "pop %esp",         "pop %ebp",        "pop %esi",       "pop %edi",
  82. /* 6 */
  83.   "pusha%d ",         "popa%d ",         "bound %Gv,%Ma",  "arpl %Ew,%Rw",
  84.   "%pf",              "%pg",             "%so",            "%sa",
  85.   "push %Iv",         "imul %Gv,%Ev,%Iv","push %Ix",       "imul %Gv,%Ev,%Ib",
  86.   "insb",             "ins%ew",          "outsb",          "outs%ew",
  87. /* 7 */
  88.   "jo %Jb",           "jno %Jb",         "jc %Jb",         "jnc %Jb",
  89.   "je %Jb",           "jne %Jb",         "jbe %Jb",        "ja %Jb",
  90.   "js %Jb",           "jns %Jb",         "jpe %Jb",        "jpo %Jb",
  91.   "jl %Jb",           "jge %Jb",         "jle %Jb",        "jg %Jb",
  92. /* 8 */
  93. /*  "%g0 %Eb,%Ib",      "%g0 %Ev,%Iv",     "%g0 %Ev,%Ib",    "%g0 %Ev,%Ib", */
  94.   "%g0 %Eb,%Ib",      "%g0 %Ev,%Iv",     "%g0 %Ev,%Ix",    "%g0 %Ev,%Ix",
  95.   "test %Eb,%Gb",     "test %Ev,%Gv",    "xchg %Eb,%Gb",   "xchg %Ev,%Gv",
  96.   "mov %Eb,%Gb",      "mov %Ev,%Gv",     "mov %Gb,%Eb",    "mov %Gv,%Ev",
  97.   "mov %Ew,%Sw",      "lea %Gv,%M ",     "mov %Sw,%Ew",    "pop %Ev",
  98. /* 9 */
  99.   "nop",              "xchg %ecx,%eax",  "xchg %edx,%eax", "xchg %ebx,%eax",
  100.   "xchg %esp,%eax",   "xchg %ebp,%eax",  "xchg %esi,%eax", "xchg %edi,%eax",
  101.   "cbw",              "cwd",             "call %Ap",       "fwait",
  102.   "pushf%d ",         "popf%d ",         "sahf",           "lahf",
  103. /* a */
  104.   "mov al,%Oc",       "mov %eax,%Ov",    "mov %Oc,al",     "mov %Ov,%eax",
  105.   "%P movsb",         "%P movs%w",       "%P cmpsb",       "%P cmps%w ",
  106.   "test al,%Ib",      "test %eax,%Iv",   "%P stosb",       "%P stos%w ",
  107.   "%P lodsb",         "%P lods%w ",      "%P scasb",       "%P scas%w ",
  108. /* b */
  109.   "mov al,%Ib",       "mov cl,%Ib",      "mov dl,%Ib",     "mov bl,%Ib",
  110.   "mov ah,%Ib",       "mov ch,%Ib",      "mov dh,%Ib",     "mov bh,%Ib",
  111.   "mov %eax,%Iv",     "mov %ecx,%Iv",    "mov %edx,%Iv",   "mov %ebx,%Iv",
  112.   "mov %esp,%Iv",     "mov %ebp,%Iv",    "mov %esi,%Iv",   "mov %edi,%Iv",
  113. /* c */
  114.   "%g1 %Eb,%Ib",      "%g1 %Ev,%Ib",     "ret %Iw",        "ret",
  115.   "les %Gv,%Mp",      "lds %Gv,%Mp",     "mov %Eb,%Ib",    "mov %Ev,%Iv",
  116.   "enter %Iw,%Ib",    "leave",           "retf %Iw",       "retf",
  117.   "int 03",           "int %Ib",         "into",           "iret",
  118. /* d */
  119.   "%g1 %Eb,1",        "%g1 %Ev,1",       "%g1 %Eb,cl",     "%g1 %Ev,cl",
  120.   "aam ; %Ib",        "aad ; %Ib",       "setalc",         "xlat",
  121. #if 0
  122.   "esc 0,%Ib",        "esc 1,%Ib",       "esc 2,%Ib",      "esc 3,%Ib",
  123.   "esc 4,%Ib",        "esc 5,%Ib",       "esc 6,%Ib",      "esc 7,%Ib",
  124. #else
  125.   "%f0",              "%f1",             "%f2",            "%f3",
  126.   "%f4",              "%f5",             "%f6",            "%f7",
  127. #endif
  128. /* e */
  129.   "loopne %Jb",       "loope %Jb",       "loop %Jb",       "j%j cxz %Jb",
  130.   "in al,%Ib",        "in %eax,%Ib",     "out %Ib,al",     "out %Ib,%eax",
  131.   "call %Jv",         "jmp %Jv",         "jmp %Ap",        "jmp %Ks%Jb",
  132.   "in al,dx",         "in %eax,dx",      "out dx,al",      "out dx,%eax",
  133. /* f */
  134.   "lock %p ",         0,                 "repne %p ",      "repe %p ",
  135.   "hlt",              "cmc",             "%g2",            "%g2",
  136.   "clc",              "stc",             "cli",            "sti",
  137.   "cld",              "std",             "%g3",            "%g4"
  138. };
  139.  
  140.  
  141. char *second[] = {
  142. /* 0 */
  143.   "%g5",              "%g6",             "lar %Gv,%Ew",    "lsl %Gv,%Ew",
  144.   0,                  "loadall",         "clts",           "loadall",
  145.   "invd",             "wbinvd",          0,                0,
  146.   0,                  0,                 0,                0,
  147. /* 1 */
  148.   "mov %Eb,%Gb",      "mov %Ev,%Gv",     "mov %Gb,%Eb",    "mov %Gv,%Ev",
  149.   0,                  0,                 0,                0,
  150.   0,                  0,                 0,                0,
  151.   0,                  0,                 0,                0,
  152. /* 2 */
  153.   "mov %Rd,%Cd",      "mov %Rd,%Dd",     "mov %Cd,%Rd",    "mov %Dd,%Rd",
  154.   "mov %Rd,%Td",      0,                 "mov %Td,%Rd",    0,
  155.   0,                  0,                 0,                0,
  156.   0,                  0,                 0,                0,
  157. /* 3 */
  158.   0, 0, 0, 0, 0, 0, 0, 0,
  159.   0, 0, 0, 0, 0, 0, 0, 0,
  160. /* 4 */
  161.   0, 0, 0, 0, 0, 0, 0, 0,
  162.   0, 0, 0, 0, 0, 0, 0, 0,
  163. /* 5 */
  164.   0, 0, 0, 0, 0, 0, 0, 0,
  165.   0, 0, 0, 0, 0, 0, 0, 0,
  166. /* 6 */
  167.   0, 0, 0, 0, 0, 0, 0, 0,
  168.   0, 0, 0, 0, 0, 0, 0, 0,
  169. /* 7 */
  170.   0, 0, 0, 0, 0, 0, 0, 0,
  171.   0, 0, 0, 0, 0, 0, 0, 0,
  172. /* 8 */
  173.   "jo %Jv",           "jno %Jv",         "jb %Jv",         "jnb %Jv",
  174.   "jz %Jv",           "jnz %Jv",         "jbe %Jv",        "ja %Jv",
  175.   "js %Jv",           "jns %Jv",         "jp %Jv",         "jnp %Jv",
  176.   "jl %Jv",           "jge %Jv",         "jle %Jv",        "jg %Jv",
  177. /* 9 */
  178.   "seto %Eb",         "setno %Eb",       "setc %Eb",       "setnc %Eb",
  179.   "setz %Eb",         "setnz %Eb",       "setbe %Eb",      "setnbe %Eb",
  180.   "sets %Eb",         "setns %Eb",       "setp %Eb",       "setnp %Eb",
  181.   "setl %Eb",         "setge %Eb",       "setle %Eb",      "setg %Eb",
  182. /* a */
  183.   "push fs",          "pop fs",          0,                "bt %Ev,%Gv",
  184.   "shld %Ev,%Gv,%Ib", "shld %Ev,%Gv,cl", 0,                0,
  185.   "push gs",          "pop gs",          0,                "bts %Ev,%Gv",
  186.   "shrd %Ev,%Gv,%Ib", "shrd %Ev,%Gv,cl", 0,                "imul %Gv,%Ev",
  187. /* b */
  188.   "cmpxchg %Eb,%Gb",  "cmpxchg %Ev,%Gv", "lss %Mp",        "btr %Ev,%Gv",
  189.   "lfs %Mp",          "lgs %Mp",         "movzx %Gv,%Eb",  "movzx %Gv,%Ew",
  190.   0,                  0,                 "%g7 %Ev,%Ib",    "btc %Ev,%Gv",
  191.   "bsf %Gv,%Ev",      "bsr %Gv,%Ev",     "movsx %Gv,%Eb",  "movsx %Gv,%Ew",
  192. /* c */
  193.   "xadd %Eb,%Gb",     "xadd %Ev,%Gv",    0,                0,
  194.   0,                  0,                 0,                0,
  195.   "bswap eax",        "bswap ecx",       "bswap edx",      "bswap ebx",
  196.   "bswap esp",        "bswap ebp",       "bswap esi",      "bswap edi",
  197. /* d */
  198.   0, 0, 0, 0, 0, 0, 0, 0,
  199.   0, 0, 0, 0, 0, 0, 0, 0,
  200. /* e */
  201.   0, 0, 0, 0, 0, 0, 0, 0,
  202.   0, 0, 0, 0, 0, 0, 0, 0,
  203. /* f */
  204.   0, 0, 0, 0, 0, 0, 0, 0,
  205.   0, 0, 0, 0, 0, 0, 0, 0,
  206. };
  207.  
  208.  
  209. char *groups[][8] = {   /* group 0 is group 3 for %Ev set */
  210. /* 0 */
  211.   { "add",            "or",              "adc",            "sbb",
  212.     "and",            "sub",             "xor",            "cmp"           },
  213. /* 1 */
  214.   { "rol",            "ror",             "rcl",            "rcr",
  215.     "shl",            "shr",             "shl",            "sar"           },
  216. /* 2 */  /* v   v*/
  217.   { "test %Eq,%Iq",   "test %Eq,%Iq",    "not %Ev",        "neg %Ev",
  218.     "mul %Ec",        "imul %Ec",        "div %Ec",        "idiv %Ec" },
  219. /* 3 */
  220.   { "inc %Eb",        "dec %Eb",         0,                0,
  221.     0,                0,                 0,                0               },
  222. /* 4 */
  223.   { "inc %Ev",        "dec %Ev",         "call %Kn%Ev",  "call %Kf%Ep",
  224.     "jmp %Kn%Ev",     "jmp %Kf%Ep",      "push %Ev",       0               },
  225. /* 5 */
  226.   { "sldt %Ew",       "str %Ew",         "lldt %Ew",       "ltr %Ew",
  227.     "verr %Ew",       "verw %Ew",        0,                0               },
  228. /* 6 */
  229.   { "sgdt %Ms",       "sidt %Ms",        "lgdt %Ms",       "lidt %Ms",
  230.     "smsw %Ew",       0,                 "lmsw %Ew",       0               },
  231. /* 7 */
  232.   { 0,                0,                 0,                0,
  233.     "bt",             "bts",             "btr",            "btc"           }
  234. };
  235.  
  236. /* zero here means invalid.  If first entry starts with '*', use st(i) */
  237. /* no assumed %EFs here.  Indexed by RM(modrm())                       */
  238. char *f0[]     = { 0, 0, 0, 0, 0, 0, 0, 0};
  239. char *fop_9[]  = { "*fxch st,%GF" };
  240. char *fop_10[] = { "fnop", 0, 0, 0, 0, 0, 0, 0 };
  241. char *fop_12[] = { "fchs", "fabs", 0, 0, "ftst", "fxam", 0, 0 };
  242. char *fop_13[] = { "fld1", "fldl2t", "fldl2e", "fldpi",
  243.                    "fldlg2", "fldln2", "fldz", 0 };
  244. char *fop_14[] = { "f2xm1", "fyl2x", "fptan", "fpatan",
  245.                    "fxtract", "fprem1", "fdecstp", "fincstp" };
  246. char *fop_15[] = { "fprem", "fyl2xp1", "fsqrt", "fsincos",
  247.                    "frndint", "fscale", "fsin", "fcos" };
  248. char *fop_21[] = { 0, "fucompp", 0, 0, 0, 0, 0, 0 };
  249. char *fop_28[] = { 0, 0, "fclex", "finit", 0, 0, 0, 0 };
  250. char *fop_32[] = { "*fadd %GF,st" };
  251. char *fop_33[] = { "*fmul %GF,st" };
  252. char *fop_36[] = { "*fsubr %GF,st" };
  253. char *fop_37[] = { "*fsub %GF,st" };
  254. char *fop_38[] = { "*fdivr %GF,st" };
  255. char *fop_39[] = { "*fdiv %GF,st" };
  256. char *fop_40[] = { "*ffree %GF" };
  257. char *fop_42[] = { "*fst %GF" };
  258. char *fop_43[] = { "*fstp %GF" };
  259. char *fop_44[] = { "*fucom %GF" };
  260. char *fop_45[] = { "*fucomp %GF" };
  261. char *fop_48[] = { "*faddp %GF,st" };
  262. char *fop_49[] = { "*fmulp %GF,st" };
  263. char *fop_51[] = { 0, "fcompp", 0, 0, 0, 0, 0, 0 };
  264. char *fop_52[] = { "*fsubrp %GF,st" };
  265. char *fop_53[] = { "*fsubp %GF,st" };
  266. char *fop_54[] = { "*fdivrp %GF,st" };
  267. char *fop_55[] = { "*fdivp %GF,st" };
  268. char *fop_60[] = { "fstsw ax", 0, 0, 0, 0, 0, 0, 0 };
  269.  
  270. char **fspecial[] = { /* 0=use st(i), 1=undefined 0 in fop_* means undefined */
  271.   0, 0, 0, 0, 0, 0, 0, 0,
  272.   0, fop_9, fop_10, 0, fop_12, fop_13, fop_14, fop_15,
  273.   f0, f0, f0, f0, f0, fop_21, f0, f0,
  274.   f0, f0, f0, f0, fop_28, f0, f0, f0,
  275.   fop_32, fop_33, f0, f0, fop_36, fop_37, fop_38, fop_39,
  276.   fop_40, f0, fop_42, fop_43, fop_44, fop_45, f0, f0,
  277.   fop_48, fop_49, f0, fop_51, fop_52, fop_53, fop_54, fop_55,
  278.   f0, f0, f0, f0, fop_60, f0, f0, f0,
  279. };
  280.  
  281. char *floatops[] = { /* assumed " %EF" at end of each.  mod != 3 only */
  282. /*00*/ "fadd", "fmul", "fcom", "fcomp",
  283.        "fsub", "fsubr", "fdiv", "fdivr",
  284. /*08*/ "fld", 0, "fst", "fstp",
  285.        "fldenv", "fldcw", "fstenv", "fstcw",
  286. /*16*/ "fiadd", "fimul", "ficomw", "ficompw",
  287.        "fisub", "fisubr", "fidiv", "fidivr",
  288. /*24*/ "fild", 0, "fist", "fistp",
  289.        "frstor", "fldt", 0, "fstpt",
  290. /*32*/ "faddq", "fmulq", "fcomq", "fcompq",
  291.        "fsubq", "fsubrq", "fdivq", "fdivrq",
  292. /*40*/ "fldq", 0, "fstq", "fstpq",
  293.        0, 0, "fsave", "fstsw",
  294. /*48*/ "fiaddw", "fimulw", "ficomw", "ficompw",
  295.        "fisubw", "fisubrw", "fidivw", "fidivr",
  296. /*56*/ "fildw", 0, "fistw", "fistpw",
  297.        "fbldt", "fildq", "fbstpt", "fistpq"
  298. };
  299.