FFFF minix/commands/mdb/mdbdis86.c at R3.1.0 · Jendoliver/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1564 lines (1413 loc) · 27.2 KB

mdbdis86.c

File metadata and controls

1564 lines (1413 loc) · 27.2 KB
{
u8_t got;
if ((got = get8()) > MAX_SIGNED_CHAR)
got -= (MAX_UNSIGNED_CHAR + 1);
return got;
}
PRIVATE void getmodregrm()
{
opcode_pt modregrm;
modregrm = get8();
mod = modregrm & MOD_MASK;
reg = (modregrm & REG_MASK) >> REG_SHIFT;
rm = (modregrm & RM_MASK) >> RM_SHIFT;
}
PRIVATE void i_00_to_3f(opc)
opcode_pt opc;
{
opcode_pt sub;
if (opc == 15)
pagef();
else if ((sub = opc & 7) >= 6)
{
outustr((sstr_00_to_3f - 6)[((opc >> 2) & 0x0E) + sub]);
if (!(opc & 1))
data_seg = opc;
}
else
{
oututstr(str_00_to_3f[(opc >> 3) & 7]);
if (sub == 4)
{
outustr(genreg[0]);
outcomma();
Ib();
}
else if (sub == 5)
{
outax();
outcomma();
Iv();
}
else
outad(sub);
}
}
PRIVATE void i_40_to_5f(opc)
opcode_pt opc;
{
outustr(str_40_to_5f[(opc >> 3) & 3]);
outustr(genreg[hosize + (opc & 7)]);
}
PRIVATE void i_60_to_6f(opc)
opcode_pt opc;
{
/* most for 386, some for 286 */
outustr((str_60_to_6f - 0x60)[opc]);
switch (opc)
{
case 0x60:
case 0x61:
if (hosize == 16)
outwsize();
break;
case 0x62:
GvMa();
break;
case 0x63:
EwRw();
break;
case 0x64:
case 0x65:
data_seg = opc;
break;
case 0x66:
hosize = (16 + 8) - hdefsize;
break;
case 0x67:
hasize = (16 + 8) - hdefsize;
break;
case 0x68:
outword();
Iv();
break;
case 0x6A:
outword();
outimmed(SIGNBIT | WORDBIT);
break;
case 0x69:
GvEv();
outcomma();
Iv();
break;
case 0x6B:
GvEv();
outcomma();
outimmed(SIGNBIT | WORDBIT);
break;
case 0x6D:
case 0x6F:
outwsize();
break;
}
}
PRIVATE void i_70_to_7f(opc)
opcode_pt opc;
{
outustr("j");
oututstr((str_flags - 0x70)[opc]);
Jb();
}
PRIVATE void i_80(opc)
opcode_pt opc;
{
if (opc >= 4)
{
outustr(opc >= 6 ? "xchg\t" : "test\t");
outad(opc);
}
else
{
getmodregrm();
oututstr(str_00_to_3f[reg]);
outbwptr(opc);
outea(opc);
outcomma();
outimmed(opc);
#ifdef SIGNED_LOGICALS
if (opc & SIGNBIT && (reg == 1 || reg == 4 || reg == 6))
/* and, or and xor with signe extension are not documented in some
* 8086 and 80286 manuals, but make sense and work
*/
outfishy();
#endif
}
}
PRIVATE void i_88(opc)
opcode_pt opc;
{
if (opc < 4)
{
outustr(movtab);
outad(opc);
}
else if (opc == 5)
{
oututstr("lea");
GvM();
}
else if (opc == 7)
{
oututstr("pop");
getmodregrm();
outwptr();
Ev();
if (reg != 0)
outfishy();
}
else
{
getmodregrm();
outustr(movtab);
if (!(opc & TOREGBIT))
{
Ev();
outcomma();
}
outustr(segreg[reg]);
if (opc & TOREGBIT)
{
outcomma();
Ev();
}
}
}
PRIVATE void i_90(opc)
opcode_pt opc;
{
if (opc == 0)
outustr("nop");
else
{
outustr("xchg\t");
outax();
outcomma();
outustr(genreg[hosize + opc]);
}
}
PRIVATE void i_98(opc)
opcode_pt opc;
{
outustr((str_98 - 8)[opc + hosize]);
if (opc == 2)
outsegpc();
}
PRIVATE void i_a0(opc)
opcode_pt opc;
{
outustr(str_a0[opc]);
if (opc < 4)
{
mod = MEM0_MOD; /* fake */
reg = 0; /* fake ax */
if (hasize == 16)
rm = 5; /* fake [d16] */
else
rm = 6; /* fake [d32] */
outad1(opc ^ TOREGBIT);
}
else if (opc & 1)
outwsize();
}
PRIVATE void i_a8(opc)
opcode_pt opc;
{
outustr(str_a8[opc]);
if (opc < 2)
{
outalorx(opc);
outcomma();
outimmed(opc);
}
else if (opc & 1)
outwsize();
}
PRIVATE void i_b0(opc)
opcode_pt opc;
{
outustr(movtab);
outustr(genreg[opc]);
outcomma();
Ib();
}
PRIVATE void i_b8(opc)
opcode_pt opc;
{
outustr(movtab);
outustr(genreg[hosize + opc]);
outcomma();
Iv();
}
PRIVATE void i_c0(opc)
opcode_pt opc;
{
outustr(str_c0[opc]);
if (opc >= 6)
{
getmodregrm();
outbwptr(opc);
outea(opc);
outcomma();
outimmed(opc & WORDBIT);
if (reg != 0)
/* not completely decoded (like DEBUG) */
outfishy();
}
else if (opc >= 4)
GvMp();
else if (opc == 2)
Iv();
else if (opc < 2)
shift(opc);
}
PRIVATE void i_c8(opc)
opcode_pt opc;
{
outustr(str_c8[opc]);
if (opc == 0)
{
Iw();
outcomma();
Ib();
}
if (opc == 2)
Iv();
else if (opc == 5)
Ib();
else if (opc == 7 && hosize == 16)
outwsize();
}
PRIVATE void i_d0(opc)
opcode_pt opc;
{
opcode_pt aabyte;
if (opc < 4)
shift(opc | 0xD0);
else
{
outustr((str_d0 - 4)[opc]);
if (opc < 6 && (aabyte = get8()) != 0x0A)
{
outtab();
outh8(aabyte);
outfishy();
}
}
}
PRIVATE void i_d8(opc)
opcode_pt opc;
{
opcode_pt esc;
char *str;
getmodregrm();
esc = (opc << 3) | reg;
if ((str = (mod == REG_MOD ? str1_d8 : str_d8)[esc]) == NULL)
{
escape:
oututstr("esc");
outh8(esc);
outcomma();
outea(0);
return;
}
if (*str == 0)
{
str = sstr_d8[str[1] + rm];
if (str == NULL)
goto escape;
outustr(str);
return;
}
outustr(str);
outtab();
if (mod == REG_MOD)
{
if (opc == 0 && reg != 2 && reg != 3)
outustr("st,");
outf1();
if (opc == 4 || opc == 6)
outustr(",st");
return;
}
switch(size_d8[esc])
{
case 4:
outustr("d");
case 2:
outwptr();
break;
case 8:
outustr("q");
outwptr();
break;
case 10:
outustr("t");
outbptr();
break;
}
outea(opc);
}
PRIVATE void i_e0(opc)
opcode_pt opc;
{
outustr(str_e0[opc]);
if (opc < 4)
Jb();
else if (opc < 6)
{
outalorx(opc);
outcomma();
Ib();
}
else
{
Ib();
outcomma();
outalorx(opc);
}
}
PRIVATE void i_e8(opc)
opcode_pt opc;
{
outustr(str_e8[opc]);
if (opc < 2)
Jv();
else if (opc == 2)
outsegpc();
else if (opc == 3)
Jb();
else
{
if (opc & TOREGBIT)
{
outustr(genreg[10]);
outcomma();
outalorx(opc);
}
else
{
outalorx(opc);
outcomma();
outustr(genreg[10]);
}
}
}
PRIVATE void i_f0(opc)
opcode_pt opc;
{
if (opc < 6)
outustr(str_f0[opc]);
else
{
getmodregrm();
outustr(sstr_f0[reg]);
outbwptr(opc);
outea(opc);
if (reg == 0)
{
outcomma();
outimmed(opc & WORDBIT);
}
}
}
PRIVATE void i_f8(opc)
opcode_pt opc;
{
if (opc < 6)
outustr(str_f8[opc]);
else
{
getmodregrm();
if (opc == 6 && reg >= 2)
outustr("fishy\t");
else
outustr(sstr_f8[reg]);
outbwptr(opc);
outea(opc);
}
}
PRIVATE void outad(opc)
opcode_pt opc;
{
getmodregrm();
outad1(opc);
}
PRIVATE void outad1(opc)
opcode_pt opc;
{
if (!(opc & TOREGBIT))
{
outea(opc);
outcomma();
}
if (opc & WORDBIT)
Gv1();
else
outustr(genreg[reg]);
if (opc & TOREGBIT)
{
outcomma();
outea(opc);
}
}
PRIVATE void outalorx(opc)
opcode_pt opc;
{
if (opc & WORDBIT)
outax();
else
outustr(genreg[0]);
}
PRIVATE void outax()
{
outustr(genreg[hosize]);
}
PRIVATE void outbptr()
{
outustr("byte ptr ");
}
PRIVATE void outbwptr(opc)
opcode_pt opc;
{
if (mod != REG_MOD)
{
if (opc & WORDBIT)
outwptr();
else
outbptr();
}
}
PRIVATE void outea(wordflags)
opcode_pt wordflags;
{
reg_pt base;
reg_pt index;
opcode_pt ss;
opcode_pt ssindexbase;
if (mod == REG_MOD)
outustr(genreg[hosize * (wordflags & WORDBIT) + rm]);
else
{
outbyte(LINDIRECT);
if (hasize == 16)
{
if (rm == 4)
{
base = (ssindexbase = get8()) & BASE_MASK;
if (mod == MEM0_MOD && base == 5)
outgetaddr();
else
outustr((genreg + 16)[base]);
ss = (ssindexbase & SS_MASK) >> SS_SHIFT;
if ((index = (ssindexbase & INDEX_MASK) >> INDEX_SHIFT) != 4)
{
outbyte('+');
outustr((genreg + 16)[index]);
outstr("\0\0\0*2\0*4\0*8\0" + (3 * ss));
}
}
else if (mod == MEM0_MOD && rm == 5)
outgetaddr();
else
outustr((genreg + 16)[rm]);
}
else if (mod == MEM0_MOD && rm == 6)
outgetaddr();
else
outustr(indreg[rm]);
if (mod == MEM1_MOD)
/* fake sign extension to get +- */
outimmed(SIGNBIT | WORDBIT);
else if (mod == MEM2_MOD)
{
outbyte('+');
#if (_WORD_SIZE == 4)
out32offset();
#else
outgetaddr();
#endif
}
outbyte(RINDIRECT);
if (hasize == 16 && rm == 4 && index == 4 && ss != 0)
outfishy();
}
}
PRIVATE void outf1()
{
outustr("st(");
outbyte((int) (rm + '0'));
outbyte(')');
}
#if (_WORD_SIZE == 4)
PRIVATE void out32offset()
{
off_t off;
if (hasize == 16)
off = get32();
else
outfishy();
outh32(off);
}
#endif
PRIVATE void outfishy()
{
outustr("\t???");
}
PRIVATE void outgetaddr()
{
off_t off;
if (hasize == 16)
off = get32();
else
off = get16();
if ( finds_data(off,data_seg) )
*offptr++ = off;
else if (hasize == 16)
outh32(off);
else
outh16((u16_t) off);
}
PRIVATE void outimmed(signwordflag)
opcode_pt signwordflag;
{
su8_pt byte;
if (signwordflag & WORDBIT)
{
if (signwordflag & SIGNBIT)
{
if ((byte = get8s()) < 0)
{
0