nanojpeg: helper for Udis86 -> Fail* register ID translation
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1793 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -48,48 +48,6 @@ public:
|
||||
* @returns \c true if a new instruction could be retrieved, \c false if the object has expired
|
||||
*/
|
||||
inline bool fetchNextInstruction() { return (ud_disassemble(&ud_obj) > 0); }
|
||||
/**
|
||||
* Returns the FailBochs equivalent to a UDIS86 GPR identifier.
|
||||
* Attention: this only returns either 32-bit or 64-bit registers, no general IDs
|
||||
* @param udisReg the udis86 GPR ID
|
||||
* @returns the FailBochs GPR ID, usable with the BochsRegisterManager class
|
||||
*/
|
||||
static inline fail::GPRegisterId udisGPRToFailBochsGPR(ud_type_t udisReg)
|
||||
{
|
||||
#define REG_CASE(REG) case UD_R_##REG: return fail::RID_##REG
|
||||
switch (udisReg) {
|
||||
#if BX_SUPPORT_X86_64 // 64 bit register id's:
|
||||
REG_CASE(RAX);
|
||||
REG_CASE(RCX);
|
||||
REG_CASE(RDX);
|
||||
REG_CASE(RBX);
|
||||
REG_CASE(RSP);
|
||||
REG_CASE(RBP);
|
||||
REG_CASE(RSI);
|
||||
REG_CASE(RDI);
|
||||
REG_CASE(R8);
|
||||
REG_CASE(R9);
|
||||
REG_CASE(R10);
|
||||
REG_CASE(R11);
|
||||
REG_CASE(R12);
|
||||
REG_CASE(R13);
|
||||
REG_CASE(R14);
|
||||
REG_CASE(R15);
|
||||
#else
|
||||
REG_CASE(EAX);
|
||||
REG_CASE(ECX);
|
||||
REG_CASE(EDX);
|
||||
REG_CASE(EBX);
|
||||
REG_CASE(ESP);
|
||||
REG_CASE(EBP);
|
||||
REG_CASE(ESI);
|
||||
REG_CASE(EDI);
|
||||
#endif
|
||||
default:
|
||||
return fail::RID_LAST_GP_ID;
|
||||
}
|
||||
#undef REG_CASE
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __UDIS86_HPP__
|
||||
|
||||
@ -209,6 +209,55 @@ Udis86Helper::typeToString(ud_type type)
|
||||
}
|
||||
#undef CASE
|
||||
|
||||
fail::GPRegisterId
|
||||
Udis86Helper::udisGPRToFailBochsGPR(ud_type_t udisReg, uint64_t& bitmask)
|
||||
{
|
||||
#define REG_CASE(UDREG, FAILREG, BITMASK) case UD_R_##UDREG: bitmask = BITMASK; return fail::RID_##FAILREG;
|
||||
switch (udisReg) {
|
||||
#if BX_SUPPORT_X86_64 // 64 bit register id's:
|
||||
// TODO
|
||||
#else
|
||||
// 8 bit GPRs
|
||||
REG_CASE(AL, EAX, 0xff)
|
||||
REG_CASE(BL, EBX, 0xff)
|
||||
REG_CASE(CL, ECX, 0xff)
|
||||
REG_CASE(DL, EDX, 0xff)
|
||||
REG_CASE(SPL, ESP, 0xff)
|
||||
REG_CASE(BPL, EBP, 0xff)
|
||||
REG_CASE(SIL, ESI, 0xff)
|
||||
REG_CASE(DIL, EDI, 0xff)
|
||||
// (R8B-R15B)
|
||||
REG_CASE(AH, EAX, 0xff00)
|
||||
REG_CASE(BH, EBX, 0xff00)
|
||||
REG_CASE(CH, ECX, 0xff00)
|
||||
REG_CASE(DH, EDX, 0xff00)
|
||||
// 16 bit GPRs
|
||||
REG_CASE(AX, EAX, 0xffff)
|
||||
REG_CASE(BX, EBX, 0xffff)
|
||||
REG_CASE(CX, ECX, 0xffff)
|
||||
REG_CASE(DX, EDX, 0xffff)
|
||||
REG_CASE(SP, ESP, 0xffff)
|
||||
REG_CASE(BP, EBP, 0xffff)
|
||||
REG_CASE(SI, ESI, 0xffff)
|
||||
REG_CASE(DI, EDI, 0xffff)
|
||||
// (R8W-R15W)
|
||||
// 32 bit GPRs
|
||||
REG_CASE(EAX, EAX, 0xffffffff)
|
||||
REG_CASE(EBX, EBX, 0xffffffff)
|
||||
REG_CASE(ECX, ECX, 0xffffffff)
|
||||
REG_CASE(EDX, EDX, 0xffffffff)
|
||||
REG_CASE(ESP, ESP, 0xffffffff)
|
||||
REG_CASE(EBP, EBP, 0xffffffff)
|
||||
REG_CASE(ESI, ESI, 0xffffffff)
|
||||
REG_CASE(EDI, EDI, 0xffffffff)
|
||||
// missing: segment, control, debug, mmx, x86, xmm registers, EIP
|
||||
#endif
|
||||
default:
|
||||
return fail::RID_LAST_GP_ID;
|
||||
}
|
||||
#undef REG_CASE
|
||||
}
|
||||
|
||||
void Udis86Helper::initOpcodeModMap()
|
||||
{
|
||||
// The mentioned operands only include general-purpose registers.
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include <utility>
|
||||
#include <map>
|
||||
|
||||
#include "sal/bochs/BochsRegisterIDs.hpp"
|
||||
|
||||
class Udis86Helper {
|
||||
public:
|
||||
// types
|
||||
@ -48,6 +50,13 @@ public:
|
||||
void inOutRegisters(UDRegisterSet& in, UDRegisterSet& out);
|
||||
char operandTypeToChar(unsigned op);
|
||||
unsigned operandCount();
|
||||
/**
|
||||
* Returns the FailBochs equivalent to a UDIS86 GPR identifier.
|
||||
* Attention: this only returns either 32-bit or 64-bit registers, no general IDs
|
||||
* @param udisReg the udis86 GPR ID
|
||||
* @returns the FailBochs GPR ID, usable with the BochsRegisterManager class
|
||||
*/
|
||||
static fail::GPRegisterId udisGPRToFailBochsGPR(ud_type_t udisReg, uint64_t& bitmask);
|
||||
static char const * mnemonicToString(unsigned mnemonic);
|
||||
static char const * typeToString(ud_type type);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user