---------------------------------------------------------------------- Patch name: patch.disasm Author: Kernel Panic (rzhevskiy@hetnet.nl) Date: March 5th, 2002 Detailed description: Changed some parts in the disassembler so that it shows relative jumps as all regular disassemblers do (that is, writes an absolute location), shows "mov [mem], al" as it should. The various hexadecimal values are now also displayed in capital letters. Apply patch to: bochs cvs on march 5th 2002 12:00GMT Instructions: To patch, go to main bochs directory. Type "patch -p1 < THIS_PATCH_FILE". ---------------------------------------------------------------------- --- debug/dbg_main.cc.old Tue Mar 5 11:36:07 2002 +++ debug/dbg_main.cc Tue Mar 5 11:36:56 2002 @@ -2067,7 +2067,7 @@ BX_CPU(which_cpu)->mem->dbg_fetch_mem(phy, 16, bx_disasm_ibuf); ilen = bx_disassemble.disasm(BX_CPU(which_cpu)->guard_found.is_32bit_code, - bx_disasm_ibuf, bx_disasm_tbuf); + BX_CPU(which_cpu)->guard_found.eip, bx_disasm_ibuf, bx_disasm_tbuf); // Note: it would be nice to display only the modified registers here, the easy // way out I have thought of would be to keep a prev_eax, prev_ebx, etc copies @@ -3253,7 +3253,7 @@ if (paddr_valid) { BX_MEM(0)->dbg_fetch_mem(paddr, 16, bx_disasm_ibuf); ilen = bx_disassemble.disasm(bx_debugger.disassemble_size==32, - bx_disasm_ibuf, bx_disasm_tbuf); + range.from, bx_disasm_ibuf, bx_disasm_tbuf); fprintf(stderr, "%08x: ", (unsigned) range.from); for (unsigned j=0; j> 6; index = (sib >> 3) & 0x07; base = sib & 0x07; - dis_sprintf("|SS%u|IND%u|BASE%u| ", (unsigned) ss, - (unsigned) index, (unsigned) base); +/* dis_sprintf("|SS%u|IND%u|BASE%u| ", (unsigned) ss, + (unsigned) index, (unsigned) base);*/ switch (mod) { case 0: @@ -1466,7 +1467,7 @@ dis_sprintf("%s", general_32bit_reg_name[base]); else { displ32 = fetch_dword(); - dis_sprintf("%08x", (unsigned) displ32); + dis_sprintf("%08X", (unsigned) displ32); } if (index != 4) @@ -1484,7 +1485,7 @@ if (index != 4) dis_sprintf(" + %s<<%u", index_name32[index], ss); - dis_sprintf(" + %02x]", (unsigned) displ8); + dis_sprintf(" + %02X]", (unsigned) displ8); break; case 2: if (seg_override) @@ -1535,7 +1536,7 @@ break; case 6: // DS:d16 displ16 = fetch_word(); - dis_sprintf("%s:%04x", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:%04X", mod_rm_seg_reg, (unsigned) displ16); break; case 7: // DS:[BX] dis_sprintf("%s:[BX]", mod_rm_seg_reg); @@ -1551,28 +1552,28 @@ mod_rm_seg_reg = sreg_mod01_rm16[rm]; switch (rm) { case 0: // DS:[BX+SI+d8] - dis_sprintf("%s:[BX+SI+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[BX+SI+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 1: // DS:[BX+DI+d8] - dis_sprintf("%s:[BX+DI+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[BX+DI+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 2: // SS:[BP+SI+d8] - dis_sprintf("%s:[BP+SI+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[BP+SI+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 3: // SS:[BP+DI+d8] - dis_sprintf("%s:[BP+DI+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[BP+DI+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 4: // DS:[SI+d8] - dis_sprintf("%s:[SI+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[SI+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 5: // DS:[DI+d8] - dis_sprintf("%s:[DI+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[DI+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 6: // SS:[BP+d8] - dis_sprintf("%s:[BP+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[BP+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; case 7: // DS:[BX+d8] - dis_sprintf("%s:[BX+%02x]", mod_rm_seg_reg, (unsigned) displ8); + dis_sprintf("%s:[BX+%02X]", mod_rm_seg_reg, (unsigned) displ8); break; } break; @@ -1585,28 +1586,28 @@ mod_rm_seg_reg = sreg_mod10_rm16[rm]; switch (rm) { case 0: // DS:[BX+SI+d16] - dis_sprintf("%s:[BX+SI+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[BX+SI+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 1: // DS:[BX+DI+d16] - dis_sprintf("%s:[BX+DI+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[BX+DI+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 2: // SS:[BP+SI+d16] - dis_sprintf("%s:[BP+SI+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[BP+SI+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 3: // SS:[BP+DI+d16] - dis_sprintf("%s:[BP+DI+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[BP+DI+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 4: // DS:[SI+d16] - dis_sprintf("%s:[SI+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[SI+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 5: // DS:[DI+d16] - dis_sprintf("%s:[DI+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[DI+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 6: // SS:[BP+d16] - dis_sprintf("%s:[BP+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[BP+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; case 7: // DS:[BX+d16] - dis_sprintf("%s:[BX+%04x]", mod_rm_seg_reg, (unsigned) displ16); + dis_sprintf("%s:[BX+%04X]", mod_rm_seg_reg, (unsigned) displ16); break; } break; --- disasm/dis_groups.cc.old Tue Mar 5 11:41:06 2002 +++ disasm/dis_groups.cc Tue Mar 5 11:41:18 2002 @@ -104,12 +104,41 @@ bx_disassemble_c::DXXb(void) {dis_sprintf("*** DXXb() unfinished ***");} void bx_disassemble_c::DXXv(void) {dis_sprintf("*** DXXv() unfinished ***");} + void -bx_disassemble_c::ALOb(void) {dis_sprintf("*** ALOb() unfinished ***");} +bx_disassemble_c::ALOb(void) +{ + char *seg; + + if (seg_override) + seg = seg_override; + else + seg = "DS"; + + if (db_32bit_addrsize) { + Bit32u imm32; + + imm32 = fetch_dword(); + dis_sprintf("AL, [%s:%08X]", seg, (unsigned) imm32); + } + else { + Bit16u imm16; + + imm16 = fetch_word(); + dis_sprintf("AL, [%s:%04X]", seg, (unsigned) imm16); + } +} void bx_disassemble_c::eAXOv(void) { + char *seg; + + if (seg_override) + seg = seg_override; + else + seg = "DS"; + if (db_32bit_opsize) { dis_sprintf("EAX, "); } @@ -121,30 +150,37 @@ Bit32u imm32; imm32 = fetch_dword(); - dis_sprintf("[%08x]", (unsigned) imm32); + dis_sprintf("[%s:%08X]", seg, (unsigned) imm32); } else { Bit16u imm16; imm16 = fetch_word(); - dis_sprintf("[%04x]", (unsigned) imm16); + dis_sprintf("[%s:%04X]", seg, (unsigned) imm16); } } void bx_disassemble_c::OveAX(void) { + char *seg; + + if (seg_override) + seg = seg_override; + else + seg = "DS"; + if (db_32bit_addrsize) { Bit32u imm32; imm32 = fetch_dword(); - dis_sprintf("[%08x], ", (unsigned) imm32); + dis_sprintf("[%s:%08X], ", seg, (unsigned) imm32); } else { Bit16u imm16; imm16 = fetch_word(); - dis_sprintf("[%04x], ", (unsigned) imm16); + dis_sprintf("[%s:%04X], ", seg, (unsigned) imm16); } if (db_32bit_opsize) { @@ -181,7 +217,30 @@ } void -bx_disassemble_c::ObAL(void) {dis_sprintf("*** ObAL() unfinished ***");} +bx_disassemble_c::ObAL(void) +{ + char *seg; + + if (seg_override) + seg = seg_override; + else + seg = "DS"; + +#if BX_CPU_LEVEL > 2 + if (db_32bit_opsize) + { + Bit32u imm32; + imm32 = fetch_dword(); + dis_sprintf("[%s:%08X], AL", seg, imm32); + } + else +#endif /* BX_CPU_LEVEL > 2 */ + { + Bit16u imm16; + imm16 = fetch_word(); + dis_sprintf("[%s:%04X], AL", seg, imm16); + } +} void bx_disassemble_c::YbAL(void) {dis_sprintf("*** YbAL() unfinished ***");} @@ -218,14 +277,14 @@ bx_disassemble_c::Av(void) { if (db_32bit_opsize) { - Bit32u imm32; + Bit32s imm32; imm32 = fetch_dword(); - dis_sprintf("%08x", (unsigned) imm32); + dis_sprintf("%08X", (unsigned) (imm32 + db_eip)); } else { - Bit16u imm16; + Bit16s imm16; imm16 = fetch_word(); - dis_sprintf("%04x", (unsigned) imm16); + dis_sprintf("%04X", (unsigned) ((imm16 + db_eip) & 0xFFFF)); } } @@ -262,7 +321,7 @@ Bit16u imm16; imm16 = fetch_word(); - dis_sprintf("#%04x", (unsigned) imm16); + dis_sprintf("%04X", (unsigned) imm16); } @@ -326,7 +385,7 @@ Bit32u imm32; imm32 = fetch_dword(); - dis_sprintf("+#%08x", (unsigned) imm32); + dis_sprintf("%08X", (unsigned) (imm32 + db_eip)); } else #endif @@ -334,7 +393,7 @@ Bit16u imm16; imm16 = fetch_word(); - dis_sprintf("+#%04x", (unsigned) imm16); + dis_sprintf("%04X", (unsigned) ((imm16 + db_eip) & 0xFFFF)); } } @@ -348,13 +407,13 @@ if (db_32bit_opsize) { decode_exgx(BX_GENERAL_32BIT_REG, BX_NO_REG_TYPE); imm8 = fetch_byte(); - dis_sprintf(", #%02x", (unsigned) imm8); + dis_sprintf(", %02X", (unsigned) imm8); } else { #endif /* BX_CPU_LEVEL > 2 */ decode_exgx(BX_GENERAL_16BIT_REG, BX_NO_REG_TYPE); imm8 = fetch_byte(); - dis_sprintf(", #%02x", (unsigned) imm8); + dis_sprintf(", %02X", (unsigned) imm8); #if BX_CPU_LEVEL > 2 } #endif /* BX_CPU_LEVEL > 2 */ @@ -368,13 +427,13 @@ Bit32u imm32; imm32 = fetch_dword(); - dis_sprintf("#%08x", (unsigned) imm32); + dis_sprintf("%08X", (unsigned) imm32); } else { Bit16u imm16; imm16 = fetch_word(); - dis_sprintf("#%04x", (unsigned) imm16); + dis_sprintf("%04X", (unsigned) imm16); } } @@ -385,7 +444,7 @@ Bit8u imm8; imm8 = fetch_byte(); - dis_sprintf("#%02x", imm8); + dis_sprintf("%02X", imm8); } @@ -395,7 +454,15 @@ Bit8u imm8; imm8 = fetch_byte(); - dis_sprintf("+#%02x", (unsigned) imm8); +#if BX_CPU_LEVEL > 2 + if (db_32bit_opsize) { + dis_sprintf("%08X", (unsigned) (imm8 + db_eip)); + } + else +#endif + { + dis_sprintf("%04X", (unsigned) ((imm8 + db_eip) & 0xFFFF)); + } } void @@ -405,7 +472,7 @@ decode_exgx(BX_GENERAL_8BIT_REG, BX_NO_REG_TYPE); imm8 = fetch_byte(); - dis_sprintf(", #%02x", (unsigned) imm8); + dis_sprintf(", %02X", (unsigned) imm8); } void @@ -419,13 +486,13 @@ decode_exgx(BX_GENERAL_32BIT_REG, BX_NO_REG_TYPE); imm32 = fetch_dword(); - dis_sprintf(", #%08x", (unsigned) imm32); + dis_sprintf(", %08X", (unsigned) imm32); } else { #endif /* BX_CPU_LEVEL > 2 */ decode_exgx(BX_GENERAL_16BIT_REG, BX_NO_REG_TYPE); imm16 = fetch_word(); - dis_sprintf(", #%04x", (unsigned) imm16); + dis_sprintf(", %04X", (unsigned) imm16); #if BX_CPU_LEVEL > 2 } #endif /* BX_CPU_LEVEL > 2 */ @@ -480,7 +547,7 @@ imm32 = fetch_dword(); cs_selector = fetch_word(); - dis_sprintf("%04x:%08x", (unsigned) cs_selector, (unsigned) imm32); + dis_sprintf("%04X:%08X", (unsigned) cs_selector, (unsigned) imm32); } else #endif /* BX_CPU_LEVEL > 2 */ @@ -490,7 +557,7 @@ imm16 = fetch_word(); cs_selector = fetch_word(); - dis_sprintf("%04x:%04x", (unsigned) cs_selector, (unsigned) imm16); + dis_sprintf("%04X:%04X", (unsigned) cs_selector, (unsigned) imm16); } } --- cpu/debugstuff.cc.old Tue Oct 9 17:15:14 2001 +++ cpu/debugstuff.cc Tue Mar 5 12:03:47 2002 @@ -141,7 +141,7 @@ if (valid) { BX_CPU_THIS_PTR mem->dbg_fetch_mem(phy_addr, 16, instr_buf); isize = bx_disassemble.disasm(BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b, - instr_buf, char_buf); + BX_CPU_THIS_PTR eip, instr_buf, char_buf); for (unsigned j=0; j> %02x", (unsigned) instr_buf[j])); BX_INFO((">> : %s", char_buf)); --- disasm/disasm.h Wed Oct 3 09:10:37 2001 +++ ../../bochs/disasm/disasm.h Tue Mar 5 11:50:45 2002 @@ -40,13 +40,14 @@ class bx_disassemble_c : public logfunctions { public: bx_disassemble_c(void); - unsigned disasm(Boolean is_32, Bit8u *instr, char *disbuf); + unsigned disasm(Boolean is_32, Bit32u ip, Bit8u *instr, char *disbuf); private: Boolean db_32bit_opsize; Boolean db_32bit_addrsize; Boolean db_rep_prefix; Boolean db_repne_prefix; + Bit32u db_eip; Bit8u *instruction_begin; // keep track of where instruction starts Bit8u *instruction; // for fetching of next byte of instruction @@ -74,6 +75,7 @@ char *index_name32[8]; BX_CPP_INLINE Bit8u fetch_byte(void) { + db_eip++; return(*instruction++); }; BX_CPP_INLINE Bit8u peek_byte(void) { @@ -87,6 +89,7 @@ b0 = * (Bit8u *) instruction++; b1 = * (Bit8u *) instruction++; ret16 = (b1<<8) | b0; + db_eip += 2; return(ret16); }; @@ -99,6 +102,7 @@ b2 = * (Bit8u *) instruction++; b3 = * (Bit8u *) instruction++; ret32 = (b3<<24) | (b2<<16) | (b1<<8) | b0; + db_eip += 4; return(ret32); };