Fixed BranchImm cases in 64-bit mode

This commit is contained in:
Stanislav Shwartsman 2007-10-22 17:41:41 +00:00
parent 68ef783632
commit 292153b30e
6 changed files with 55 additions and 46 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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));

View File

@ -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);