From 292153b30e8256a625a28ba8ab53bdd1207b2260 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Mon, 22 Oct 2007 17:41:41 +0000 Subject: [PATCH] Fixed BranchImm cases in 64-bit mode --- bochs/cpu/cpu.h | 14 +++++----- bochs/cpu/ctrl_xfer16.cc | 6 ++--- bochs/cpu/ctrl_xfer32.cc | 8 +++--- bochs/cpu/ctrl_xfer64.cc | 6 ++--- bochs/cpu/fetchdecode.cc | 15 ++++++++--- bochs/cpu/fetchdecode64.cc | 52 +++++++++++++++++++------------------- 6 files changed, 55 insertions(+), 46 deletions(-) diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index 2a035b73a..f67e5bc38 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.h,v 1.340 2007-10-21 22:07:32 sshwarts Exp $ +// $Id: cpu.h,v 1.341 2007-10-22 17:41:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -1558,8 +1558,8 @@ public: // for now... BX_SMF void OUT_IbAL(bxInstruction_c *); BX_SMF void OUT_IbAX(bxInstruction_c *); BX_SMF void OUT_IbEAX(bxInstruction_c *); - BX_SMF void CALL_Aw(bxInstruction_c *); - BX_SMF void CALL_Ad(bxInstruction_c *); + BX_SMF void CALL_Jw(bxInstruction_c *); + BX_SMF void CALL_Jd(bxInstruction_c *); BX_SMF void JMP_Jd(bxInstruction_c *); BX_SMF void JMP_Jw(bxInstruction_c *); BX_SMF void JMP_Ap(bxInstruction_c *); @@ -2514,7 +2514,7 @@ public: // for now... BX_SMF void IRET64(bxInstruction_c *); - BX_SMF void CALL_Aq(bxInstruction_c *); + BX_SMF void CALL_Jq(bxInstruction_c *); BX_SMF void JMP_Jq(bxInstruction_c *); BX_SMF void JCC_Jq(bxInstruction_c *); @@ -3482,10 +3482,10 @@ IMPLEMENT_EFLAG_ACCESSOR (TF, 8) #define BxImmediate_IwIb 0x0006 // enter_IwIb #define BxImmediate_O 0x0007 // MOV_ALOd, mov_OdAL, mov_eAXOv, mov_OveAX #define BxImmediate_BrOff8 0x0008 // Relative branch offset byte -#define BxImmediate_BrOff16 0x0009 // Relative branch offset word -#define BxImmediate_BrOff32 BxImmediate_Iv +#define BxImmediate_BrOff16 0x0009 // Relative branch offset word, not encodable in 64-bit mode +#define BxImmediate_BrOff32 0x000A // Relative branch offset dword #if BX_SUPPORT_X86_64 -#define BxImmediate_Iq 0x000A // 64 bit override +#define BxImmediate_Iq 0x000B // 64 bit override #endif // Lookup for opcode and attributes in another opcode tables diff --git a/bochs/cpu/ctrl_xfer16.cc b/bochs/cpu/ctrl_xfer16.cc index af2e29f9b..8333510fb 100644 --- a/bochs/cpu/ctrl_xfer16.cc +++ b/bochs/cpu/ctrl_xfer16.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: ctrl_xfer16.cc,v 1.38 2007-10-18 21:27:56 sshwarts Exp $ +// $Id: ctrl_xfer16.cc,v 1.39 2007-10-22 17:41:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -144,7 +144,7 @@ done: BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value, EIP); } -void BX_CPU_C::CALL_Aw(bxInstruction_c *i) +void BX_CPU_C::CALL_Jw(bxInstruction_c *i) { Bit32u new_EIP; @@ -157,7 +157,7 @@ void BX_CPU_C::CALL_Aw(bxInstruction_c *i) if (new_EIP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled) { - BX_ERROR(("CALL_Aw: new_IP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].limit")); + BX_ERROR(("CALL_Jw: new_IP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].limit")); exception(BX_GP_EXCEPTION, 0, 0); } diff --git a/bochs/cpu/ctrl_xfer32.cc b/bochs/cpu/ctrl_xfer32.cc index b2318aead..13455f138 100644 --- a/bochs/cpu/ctrl_xfer32.cc +++ b/bochs/cpu/ctrl_xfer32.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: ctrl_xfer32.cc,v 1.50 2007-10-18 21:27:56 sshwarts Exp $ +// $Id: ctrl_xfer32.cc,v 1.51 2007-10-22 17:41:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -125,7 +125,7 @@ done: BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value, EIP); } -void BX_CPU_C::CALL_Ad(bxInstruction_c *i) +void BX_CPU_C::CALL_Jd(bxInstruction_c *i) { #if BX_DEBUGGER BX_CPU_THIS_PTR show_flag |= Flag_call; @@ -133,8 +133,8 @@ void BX_CPU_C::CALL_Ad(bxInstruction_c *i) Bit32u new_EIP = EIP + i->Id(); - if ( new_EIP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled ) { - BX_ERROR(("CALL_Ad: offset outside of CS limits")); + if (new_EIP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled) { + BX_ERROR(("CALL_Jd: offset outside of CS limits")); exception(BX_GP_EXCEPTION, 0, 0); } diff --git a/bochs/cpu/ctrl_xfer64.cc b/bochs/cpu/ctrl_xfer64.cc index 886184846..bf815d507 100644 --- a/bochs/cpu/ctrl_xfer64.cc +++ b/bochs/cpu/ctrl_xfer64.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: ctrl_xfer64.cc,v 1.49 2007-10-18 21:27:56 sshwarts Exp $ +// $Id: ctrl_xfer64.cc,v 1.50 2007-10-22 17:41:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -113,7 +113,7 @@ void BX_CPU_C::RETfar64(bxInstruction_c *i) BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value, RIP); } -void BX_CPU_C::CALL_Aq(bxInstruction_c *i) +void BX_CPU_C::CALL_Jq(bxInstruction_c *i) { Bit64u new_RIP = RIP + (Bit32s) i->Id(); @@ -122,7 +122,7 @@ void BX_CPU_C::CALL_Aq(bxInstruction_c *i) #endif if (! IsCanonical(new_RIP)) { - BX_ERROR(("CALL_Aq: canonical RIP violation")); + BX_ERROR(("CALL_Jq: canonical RIP violation")); exception(BX_GP_EXCEPTION, 0, 0); } diff --git a/bochs/cpu/fetchdecode.cc b/bochs/cpu/fetchdecode.cc index 34dc1b353..a1518c541 100644 --- a/bochs/cpu/fetchdecode.cc +++ b/bochs/cpu/fetchdecode.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: fetchdecode.cc,v 1.112 2007-10-20 10:56:43 sshwarts Exp $ +// $Id: fetchdecode.cc,v 1.113 2007-10-22 17:41:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -655,7 +655,7 @@ static const BxOpcodeInfo_t BxOpcodeInfo[512*2] = { /* E5 */ { BxImmediate_Ib, &BX_CPU_C::IN_AXIb }, /* E6 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAL }, /* E7 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAX }, - /* E8 */ { BxImmediate_BrOff16, &BX_CPU_C::CALL_Aw }, + /* E8 */ { BxImmediate_BrOff16, &BX_CPU_C::CALL_Jw }, /* E9 */ { BxImmediate_BrOff16, &BX_CPU_C::JMP_Jw }, /* EA */ { BxImmediate_IvIw, &BX_CPU_C::JMP_Ap }, /* EB */ { BxImmediate_BrOff8, &BX_CPU_C::JMP_Jw }, @@ -1213,7 +1213,7 @@ static const BxOpcodeInfo_t BxOpcodeInfo[512*2] = { /* E5 */ { BxImmediate_Ib, &BX_CPU_C::IN_EAXIb }, /* E6 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAL }, /* E7 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbEAX }, - /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Ad }, + /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Jd }, /* E9 */ { BxImmediate_BrOff32, &BX_CPU_C::JMP_Jd }, /* EA */ { BxImmediate_IvIw, &BX_CPU_C::JMP_Ap }, /* EB */ { BxImmediate_BrOff8, &BX_CPU_C::JMP_Jd }, @@ -2002,6 +2002,15 @@ modrm_done: return(0); } break; + case BxImmediate_BrOff32: + if ((ilen+3) < remain) { + instruction->modRMForm.Id = (Bit32s) FetchDWORD(iptr); + ilen += 4; + } + else { + return(0); + } + break; default: BX_INFO(("b1 was %x", b1)); BX_PANIC(("fetchdecode: imm_mode = %u", imm_mode)); diff --git a/bochs/cpu/fetchdecode64.cc b/bochs/cpu/fetchdecode64.cc index d5cc3fcc7..1075be62a 100644 --- a/bochs/cpu/fetchdecode64.cc +++ b/bochs/cpu/fetchdecode64.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: fetchdecode64.cc,v 1.117 2007-10-20 10:56:44 sshwarts Exp $ +// $Id: fetchdecode64.cc,v 1.118 2007-10-22 17:41:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -788,8 +788,8 @@ static const BxOpcodeInfo_t BxOpcodeInfo64[512*3] = { /* E5 */ { BxImmediate_Ib, &BX_CPU_C::IN_AXIb }, /* E6 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAL }, /* E7 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAX }, - /* E8 */ { BxImmediate_BrOff16, &BX_CPU_C::CALL_Aw }, - /* E9 */ { BxImmediate_BrOff16, &BX_CPU_C::JMP_Jq }, + /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Jq }, + /* E9 */ { BxImmediate_BrOff32, &BX_CPU_C::JMP_Jq }, /* EA */ { 0, &BX_CPU_C::BxError }, /* EB */ { BxImmediate_BrOff8, &BX_CPU_C::JMP_Jq }, /* EC */ { 0, &BX_CPU_C::IN_ALDX }, @@ -954,22 +954,22 @@ static const BxOpcodeInfo_t BxOpcodeInfo64[512*3] = { /* 0F 7D */ { BxAnother | BxPrefixSSE, NULL, BxOpcodeGroupSSE_0f7d }, /* 0F 7E */ { BxAnother | BxPrefixSSE, NULL, BxOpcodeGroupSSE_0f7e }, /* 0F 7F */ { BxAnother | BxPrefixSSE, NULL, BxOpcodeGroupSSE_0f7f }, - /* 0F 80 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 81 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 82 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 83 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 84 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 85 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 86 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 87 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 88 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 89 */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 8A */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 8B */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 8C */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 8D */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 8E */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, - /* 0F 8F */ { BxImmediate_BrOff16, &BX_CPU_C::JCC_Jq }, + /* 0F 80 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 81 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 82 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 83 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 84 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 85 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 86 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 87 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 88 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 89 */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 8A */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 8B */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 8C */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 8D */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 8E */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, + /* 0F 8F */ { BxImmediate_BrOff32, &BX_CPU_C::JCC_Jq }, /* 0F 90 */ { BxAnother, &BX_CPU_C::SETO_Eb }, /* 0F 91 */ { BxAnother, &BX_CPU_C::SETNO_Eb }, /* 0F 92 */ { BxAnother, &BX_CPU_C::SETB_Eb }, @@ -1317,7 +1317,7 @@ static const BxOpcodeInfo_t BxOpcodeInfo64[512*3] = { /* E5 */ { BxImmediate_Ib, &BX_CPU_C::IN_EAXIb }, /* E6 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAL }, /* E7 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbEAX }, - /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Aq }, + /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Jq }, /* E9 */ { BxImmediate_BrOff32, &BX_CPU_C::JMP_Jq }, /* EA */ { 0, &BX_CPU_C::BxError }, /* EB */ { BxImmediate_BrOff8, &BX_CPU_C::JMP_Jq }, @@ -1846,7 +1846,7 @@ static const BxOpcodeInfo_t BxOpcodeInfo64[512*3] = { /* E5 */ { BxImmediate_Ib, &BX_CPU_C::IN_EAXIb }, /* E6 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbAL }, /* E7 */ { BxImmediate_Ib, &BX_CPU_C::OUT_IbEAX }, - /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Aq }, + /* E8 */ { BxImmediate_BrOff32, &BX_CPU_C::CALL_Jq }, /* E9 */ { BxImmediate_BrOff32, &BX_CPU_C::JMP_Jq }, /* EA */ { 0, &BX_CPU_C::BxError }, /* EB */ { BxImmediate_BrOff8, &BX_CPU_C::JMP_Jq }, @@ -2604,7 +2604,7 @@ modrm_done: return(0); } break; - case BxImmediate_Iv: // same as BxImmediate_BrOff32 + case BxImmediate_Iv: if (instruction->os32L()) { if ((ilen+3) < remain) { instruction->modRMForm.Id = FetchDWORD(iptr); @@ -2674,10 +2674,10 @@ modrm_done: return(0); } break; - case BxImmediate_BrOff16: - if ((ilen+1) < remain) { - instruction->modRMForm.Id = (Bit16s) FetchWORD(iptr); - ilen += 2; + case BxImmediate_BrOff32: + if ((ilen+3) < remain) { + instruction->modRMForm.Id = (Bit32s) FetchDWORD(iptr); + ilen += 4; } else { return(0);