bswap undefined behavior

This commit is contained in:
Stanislav Shwartsman 2010-03-19 10:00:48 +00:00
parent af27d82b66
commit e88e168081
5 changed files with 45 additions and 41 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: bit.cc,v 1.67 2010-02-26 11:44:50 sshwarts Exp $
// $Id: bit.cc,v 1.68 2010-03-19 10:00:48 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2009 The Bochs Project
@ -236,14 +236,16 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::SETNLE_EbR(bxInstruction_c *i)
BX_WRITE_8BIT_REGx(i->rm(), i->extend8bitL(), result_8);
}
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BSWAP_RX(bxInstruction_c *i)
{
BX_ERROR(("BSWAP with 16-bit opsize: undefined behavior !"));
BX_WRITE_16BIT_REG(i->opcodeReg(), 0);
}
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BSWAP_ERX(bxInstruction_c *i)
{
Bit32u val32, b0, b1, b2, b3;
if (i->os32L() == 0) {
BX_ERROR(("BSWAP with 16-bit opsize: undefined behavior !"));
}
val32 = BX_READ_32BIT_REG(i->opcodeReg());
b0 = val32 & 0xff; val32 >>= 8;
b1 = val32 & 0xff; val32 >>= 8;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.656 2010-03-18 15:19:16 sshwarts Exp $
// $Id: cpu.h,v 1.657 2010-03-19 10:00:48 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2009 The Bochs Project
@ -1518,6 +1518,7 @@ public: // for now...
BX_SMF void MOVSX_GdEbR(bxInstruction_c *) BX_CPP_AttrRegparmN(1);
BX_SMF void MOVSX_GdEwR(bxInstruction_c *) BX_CPP_AttrRegparmN(1);
BX_SMF void BSWAP_RX(bxInstruction_c *) BX_CPP_AttrRegparmN(1);
BX_SMF void BSWAP_ERX(bxInstruction_c *) BX_CPP_AttrRegparmN(1);
BX_SMF void ADD_GbEbR(bxInstruction_c *) BX_CPP_AttrRegparmN(1);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: fetchdecode.cc,v 1.258 2010-03-14 15:51:26 sshwarts Exp $
// $Id: fetchdecode.cc,v 1.259 2010-03-19 10:00:48 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2009 The Bochs Project
@ -673,14 +673,14 @@ static const BxOpcodeInfo_t BxOpcodeInfo32R[512*2] = {
/* 0F C5 /wr */ { BxPrefixSSE | BxImmediate_Ib, BX_IA_PEXTRW_GdPqIb, BxOpcodeGroupSSE_0fc5R },
/* 0F C6 /wr */ { BxPrefixSSE | BxImmediate_Ib, BX_IA_SHUFPS_VpsWpsIb, BxOpcodeGroupSSE_0fc6 },
/* 0F C7 /wr */ { 0, BX_IA_ERROR }, // CMPXCHG8B G9 group
/* 0F C8 /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F C9 /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CA /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CB /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CC /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CD /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CE /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CF /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F C8 /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F C9 /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CA /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CB /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CC /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CD /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CE /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CF /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F D0 /wr */ { BxPrefixSSE, BX_IA_ERROR, BxOpcodeGroupSSE_0fd0 },
/* 0F D1 /wr */ { BxPrefixSSE, BX_IA_PSRLW_PqQq, BxOpcodeGroupSSE_0fd1 },
/* 0F D2 /wr */ { BxPrefixSSE, BX_IA_PSRLD_PqQq, BxOpcodeGroupSSE_0fd2 },
@ -1782,14 +1782,14 @@ static const BxOpcodeInfo_t BxOpcodeInfo32M[512*2] = {
/* 0F C5 /wm */ { 0, BX_IA_ERROR }, // PEXTRW SSE group
/* 0F C6 /wm */ { BxPrefixSSE | BxImmediate_Ib, BX_IA_SHUFPS_VpsWpsIb, BxOpcodeGroupSSE_0fc6 },
/* 0F C7 /wm */ { BxGroup9, BX_IA_ERROR, BxOpcodeInfoG9M },
/* 0F C8 /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F C9 /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CA /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CB /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CC /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CD /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CE /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CF /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F C8 /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F C9 /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CA /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CB /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CC /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CD /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CE /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CF /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F D0 /wm */ { BxPrefixSSE, BX_IA_ERROR, BxOpcodeGroupSSE_0fd0 },
/* 0F D1 /wm */ { BxPrefixSSE, BX_IA_PSRLW_PqQq, BxOpcodeGroupSSE_0fd1 },
/* 0F D2 /wm */ { BxPrefixSSE, BX_IA_PSRLD_PqQq, BxOpcodeGroupSSE_0fd2 },

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: fetchdecode64.cc,v 1.255 2010-02-25 22:04:30 sshwarts Exp $
// $Id: fetchdecode64.cc,v 1.256 2010-03-19 10:00:48 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2009 The Bochs Project
@ -617,14 +617,14 @@ static const BxOpcodeInfo_t BxOpcodeInfo64R[512*3] = {
/* 0F C5 /wr */ { BxPrefixSSE | BxImmediate_Ib, BX_IA_PEXTRW_GdPqIb, BxOpcodeGroupSSE_0fc5R },
/* 0F C6 /wr */ { BxPrefixSSE | BxImmediate_Ib, BX_IA_SHUFPS_VpsWpsIb, BxOpcodeGroupSSE_0fc6 },
/* 0F C7 /wr */ { 0, BX_IA_ERROR }, // CMPXCHG8B G9 group
/* 0F C8 /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F C9 /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CA /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CB /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CC /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CD /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CE /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F CF /wr */ { 0, BX_IA_BSWAP_ERX },
/* 0F C8 /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F C9 /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CA /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CB /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CC /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CD /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CE /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F CF /wr */ { 0, BX_IA_BSWAP_RX },
/* 0F D0 /wr */ { BxPrefixSSE, BX_IA_ERROR, BxOpcodeGroupSSE_0fd0 },
/* 0F D1 /wr */ { BxPrefixSSE, BX_IA_PSRLW_PqQq, BxOpcodeGroupSSE_0fd1 },
/* 0F D2 /wr */ { BxPrefixSSE, BX_IA_PSRLD_PqQq, BxOpcodeGroupSSE_0fd2 },
@ -2180,14 +2180,14 @@ static const BxOpcodeInfo_t BxOpcodeInfo64M[512*3] = {
/* 0F C5 /wm */ { 0, BX_IA_ERROR }, // PEXTRW SSE group
/* 0F C6 /wm */ { BxPrefixSSE | BxImmediate_Ib, BX_IA_SHUFPS_VpsWpsIb, BxOpcodeGroupSSE_0fc6 },
/* 0F C7 /wm */ { BxGroup9, BX_IA_ERROR, BxOpcodeInfoG9M },
/* 0F C8 /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F C9 /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CA /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CB /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CC /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CD /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CE /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F CF /wm */ { 0, BX_IA_BSWAP_ERX },
/* 0F C8 /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F C9 /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CA /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CB /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CC /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CD /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CE /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F CF /wm */ { 0, BX_IA_BSWAP_RX },
/* 0F D0 /wm */ { BxPrefixSSE, BX_IA_ERROR, BxOpcodeGroupSSE_0fd0 },
/* 0F D1 /wm */ { BxPrefixSSE, BX_IA_PSRLW_PqQq, BxOpcodeGroupSSE_0fd1 },
/* 0F D2 /wm */ { BxPrefixSSE, BX_IA_PSRLD_PqQq, BxOpcodeGroupSSE_0fd2 },

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: ia_opcodes.h,v 1.40 2010-02-25 22:44:46 sshwarts Exp $
// $Id: ia_opcodes.h,v 1.41 2010-03-19 10:00:48 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2009 Stanislav Shwartsman
@ -739,6 +739,7 @@ bx_define_opcode(BX_IA_FPU_ESC, &BX_CPU_C::FPU_ESC, NULL, 0)
// 486 new instructions
bx_define_opcode(BX_IA_CPUID, &BX_CPU_C::CPUID, NULL, BX_CPU_486)
bx_define_opcode(BX_IA_BSWAP_RX, &BX_CPU_C::BSWAP_RX, NULL, BX_CPU_486)
bx_define_opcode(BX_IA_BSWAP_ERX, &BX_CPU_C::BSWAP_ERX, NULL, BX_CPU_486)
bx_define_opcode(BX_IA_INVD, &BX_CPU_C::INVD, NULL, BX_CPU_486)
bx_define_opcode(BX_IA_WBINVD, &BX_CPU_C::WBINVD, NULL, BX_CPU_486)