mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-23 20:29:30 +00:00
Whitespace.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177909 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c76067b774
commit
8173c5e7c8
@ -61,7 +61,7 @@ static int modRMRequired(OpcodeType type,
|
|||||||
InstructionContext insnContext,
|
InstructionContext insnContext,
|
||||||
uint8_t opcode) {
|
uint8_t opcode) {
|
||||||
const struct ContextDecision* decision = 0;
|
const struct ContextDecision* decision = 0;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ONEBYTE:
|
case ONEBYTE:
|
||||||
decision = &ONEBYTE_SYM;
|
decision = &ONEBYTE_SYM;
|
||||||
@ -102,7 +102,7 @@ static InstrUID decode(OpcodeType type,
|
|||||||
uint8_t opcode,
|
uint8_t opcode,
|
||||||
uint8_t modRM) {
|
uint8_t modRM) {
|
||||||
const struct ModRMDecision* dec = 0;
|
const struct ModRMDecision* dec = 0;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ONEBYTE:
|
case ONEBYTE:
|
||||||
dec = &ONEBYTE_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
|
dec = &ONEBYTE_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
|
||||||
@ -123,7 +123,7 @@ static InstrUID decode(OpcodeType type,
|
|||||||
dec = &THREEBYTEA7_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
|
dec = &THREEBYTEA7_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (dec->modrm_type) {
|
switch (dec->modrm_type) {
|
||||||
default:
|
default:
|
||||||
debug("Corrupt table! Unknown modrm_type");
|
debug("Corrupt table! Unknown modrm_type");
|
||||||
@ -171,10 +171,10 @@ static const struct InstructionSpecifier *specifierForUID(InstrUID uid) {
|
|||||||
*/
|
*/
|
||||||
static int consumeByte(struct InternalInstruction* insn, uint8_t* byte) {
|
static int consumeByte(struct InternalInstruction* insn, uint8_t* byte) {
|
||||||
int ret = insn->reader(insn->readerArg, byte, insn->readerCursor);
|
int ret = insn->reader(insn->readerArg, byte, insn->readerCursor);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
++(insn->readerCursor);
|
++(insn->readerCursor);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,19 +238,19 @@ CONSUME_FUNC(consumeUInt64, uint64_t)
|
|||||||
*/
|
*/
|
||||||
static void dbgprintf(struct InternalInstruction* insn,
|
static void dbgprintf(struct InternalInstruction* insn,
|
||||||
const char* format,
|
const char* format,
|
||||||
...) {
|
...) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
if (!insn->dlog)
|
if (!insn->dlog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
(void)vsnprintf(buffer, sizeof(buffer), format, ap);
|
(void)vsnprintf(buffer, sizeof(buffer), format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
insn->dlog(insn->dlogArg, buffer);
|
insn->dlog(insn->dlogArg, buffer);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,15 +305,15 @@ static int readPrefixes(struct InternalInstruction* insn) {
|
|||||||
BOOL prefixGroups[4] = { FALSE };
|
BOOL prefixGroups[4] = { FALSE };
|
||||||
uint64_t prefixLocation;
|
uint64_t prefixLocation;
|
||||||
uint8_t byte = 0;
|
uint8_t byte = 0;
|
||||||
|
|
||||||
BOOL hasAdSize = FALSE;
|
BOOL hasAdSize = FALSE;
|
||||||
BOOL hasOpSize = FALSE;
|
BOOL hasOpSize = FALSE;
|
||||||
|
|
||||||
dbgprintf(insn, "readPrefixes()");
|
dbgprintf(insn, "readPrefixes()");
|
||||||
|
|
||||||
while (isPrefix) {
|
while (isPrefix) {
|
||||||
prefixLocation = insn->readerCursor;
|
prefixLocation = insn->readerCursor;
|
||||||
|
|
||||||
if (consumeByte(insn, &byte))
|
if (consumeByte(insn, &byte))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -400,21 +400,21 @@ static int readPrefixes(struct InternalInstruction* insn) {
|
|||||||
isPrefix = FALSE;
|
isPrefix = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPrefix)
|
if (isPrefix)
|
||||||
dbgprintf(insn, "Found prefix 0x%hhx", byte);
|
dbgprintf(insn, "Found prefix 0x%hhx", byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
insn->vexSize = 0;
|
insn->vexSize = 0;
|
||||||
|
|
||||||
if (byte == 0xc4) {
|
if (byte == 0xc4) {
|
||||||
uint8_t byte1;
|
uint8_t byte1;
|
||||||
|
|
||||||
if (lookAtByte(insn, &byte1)) {
|
if (lookAtByte(insn, &byte1)) {
|
||||||
dbgprintf(insn, "Couldn't read second byte of VEX");
|
dbgprintf(insn, "Couldn't read second byte of VEX");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) {
|
if (insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) {
|
||||||
insn->vexSize = 3;
|
insn->vexSize = 3;
|
||||||
insn->necessaryPrefixLocation = insn->readerCursor - 1;
|
insn->necessaryPrefixLocation = insn->readerCursor - 1;
|
||||||
@ -423,67 +423,67 @@ static int readPrefixes(struct InternalInstruction* insn) {
|
|||||||
unconsumeByte(insn);
|
unconsumeByte(insn);
|
||||||
insn->necessaryPrefixLocation = insn->readerCursor - 1;
|
insn->necessaryPrefixLocation = insn->readerCursor - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insn->vexSize == 3) {
|
if (insn->vexSize == 3) {
|
||||||
insn->vexPrefix[0] = byte;
|
insn->vexPrefix[0] = byte;
|
||||||
consumeByte(insn, &insn->vexPrefix[1]);
|
consumeByte(insn, &insn->vexPrefix[1]);
|
||||||
consumeByte(insn, &insn->vexPrefix[2]);
|
consumeByte(insn, &insn->vexPrefix[2]);
|
||||||
|
|
||||||
/* We simulate the REX prefix for simplicity's sake */
|
/* We simulate the REX prefix for simplicity's sake */
|
||||||
|
|
||||||
if (insn->mode == MODE_64BIT) {
|
if (insn->mode == MODE_64BIT) {
|
||||||
insn->rexPrefix = 0x40
|
insn->rexPrefix = 0x40
|
||||||
| (wFromVEX3of3(insn->vexPrefix[2]) << 3)
|
| (wFromVEX3of3(insn->vexPrefix[2]) << 3)
|
||||||
| (rFromVEX2of3(insn->vexPrefix[1]) << 2)
|
| (rFromVEX2of3(insn->vexPrefix[1]) << 2)
|
||||||
| (xFromVEX2of3(insn->vexPrefix[1]) << 1)
|
| (xFromVEX2of3(insn->vexPrefix[1]) << 1)
|
||||||
| (bFromVEX2of3(insn->vexPrefix[1]) << 0);
|
| (bFromVEX2of3(insn->vexPrefix[1]) << 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ppFromVEX3of3(insn->vexPrefix[2]))
|
switch (ppFromVEX3of3(insn->vexPrefix[2]))
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case VEX_PREFIX_66:
|
case VEX_PREFIX_66:
|
||||||
hasOpSize = TRUE;
|
hasOpSize = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx 0x%hhx", insn->vexPrefix[0], insn->vexPrefix[1], insn->vexPrefix[2]);
|
dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx 0x%hhx", insn->vexPrefix[0], insn->vexPrefix[1], insn->vexPrefix[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (byte == 0xc5) {
|
else if (byte == 0xc5) {
|
||||||
uint8_t byte1;
|
uint8_t byte1;
|
||||||
|
|
||||||
if (lookAtByte(insn, &byte1)) {
|
if (lookAtByte(insn, &byte1)) {
|
||||||
dbgprintf(insn, "Couldn't read second byte of VEX");
|
dbgprintf(insn, "Couldn't read second byte of VEX");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) {
|
if (insn->mode == MODE_64BIT || (byte1 & 0xc0) == 0xc0) {
|
||||||
insn->vexSize = 2;
|
insn->vexSize = 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unconsumeByte(insn);
|
unconsumeByte(insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insn->vexSize == 2) {
|
if (insn->vexSize == 2) {
|
||||||
insn->vexPrefix[0] = byte;
|
insn->vexPrefix[0] = byte;
|
||||||
consumeByte(insn, &insn->vexPrefix[1]);
|
consumeByte(insn, &insn->vexPrefix[1]);
|
||||||
|
|
||||||
if (insn->mode == MODE_64BIT) {
|
if (insn->mode == MODE_64BIT) {
|
||||||
insn->rexPrefix = 0x40
|
insn->rexPrefix = 0x40
|
||||||
| (rFromVEX2of2(insn->vexPrefix[1]) << 2);
|
| (rFromVEX2of2(insn->vexPrefix[1]) << 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ppFromVEX2of2(insn->vexPrefix[1]))
|
switch (ppFromVEX2of2(insn->vexPrefix[1]))
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case VEX_PREFIX_66:
|
case VEX_PREFIX_66:
|
||||||
hasOpSize = TRUE;
|
hasOpSize = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx", insn->vexPrefix[0], insn->vexPrefix[1]);
|
dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx", insn->vexPrefix[0], insn->vexPrefix[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,17 +491,17 @@ static int readPrefixes(struct InternalInstruction* insn) {
|
|||||||
if (insn->mode == MODE_64BIT) {
|
if (insn->mode == MODE_64BIT) {
|
||||||
if ((byte & 0xf0) == 0x40) {
|
if ((byte & 0xf0) == 0x40) {
|
||||||
uint8_t opcodeByte;
|
uint8_t opcodeByte;
|
||||||
|
|
||||||
if (lookAtByte(insn, &opcodeByte) || ((opcodeByte & 0xf0) == 0x40)) {
|
if (lookAtByte(insn, &opcodeByte) || ((opcodeByte & 0xf0) == 0x40)) {
|
||||||
dbgprintf(insn, "Redundant REX prefix");
|
dbgprintf(insn, "Redundant REX prefix");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
insn->rexPrefix = byte;
|
insn->rexPrefix = byte;
|
||||||
insn->necessaryPrefixLocation = insn->readerCursor - 2;
|
insn->necessaryPrefixLocation = insn->readerCursor - 2;
|
||||||
|
|
||||||
dbgprintf(insn, "Found REX prefix 0x%hhx", byte);
|
dbgprintf(insn, "Found REX prefix 0x%hhx", byte);
|
||||||
} else {
|
} else {
|
||||||
unconsumeByte(insn);
|
unconsumeByte(insn);
|
||||||
insn->necessaryPrefixLocation = insn->readerCursor - 1;
|
insn->necessaryPrefixLocation = insn->readerCursor - 1;
|
||||||
}
|
}
|
||||||
@ -539,7 +539,7 @@ static int readPrefixes(struct InternalInstruction* insn) {
|
|||||||
insn->immediateSize = (hasOpSize ? 2 : 4);
|
insn->immediateSize = (hasOpSize ? 2 : 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,22 +550,22 @@ static int readPrefixes(struct InternalInstruction* insn) {
|
|||||||
* @param insn - The instruction whose opcode is to be read.
|
* @param insn - The instruction whose opcode is to be read.
|
||||||
* @return - 0 if the opcode could be read successfully; nonzero otherwise.
|
* @return - 0 if the opcode could be read successfully; nonzero otherwise.
|
||||||
*/
|
*/
|
||||||
static int readOpcode(struct InternalInstruction* insn) {
|
static int readOpcode(struct InternalInstruction* insn) {
|
||||||
/* Determine the length of the primary opcode */
|
/* Determine the length of the primary opcode */
|
||||||
|
|
||||||
uint8_t current;
|
uint8_t current;
|
||||||
|
|
||||||
dbgprintf(insn, "readOpcode()");
|
dbgprintf(insn, "readOpcode()");
|
||||||
|
|
||||||
insn->opcodeType = ONEBYTE;
|
insn->opcodeType = ONEBYTE;
|
||||||
|
|
||||||
if (insn->vexSize == 3)
|
if (insn->vexSize == 3)
|
||||||
{
|
{
|
||||||
switch (mmmmmFromVEX2of3(insn->vexPrefix[1]))
|
switch (mmmmmFromVEX2of3(insn->vexPrefix[1]))
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)", mmmmmFromVEX2of3(insn->vexPrefix[1]));
|
dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)", mmmmmFromVEX2of3(insn->vexPrefix[1]));
|
||||||
return -1;
|
return -1;
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case VEX_LOB_0F:
|
case VEX_LOB_0F:
|
||||||
@ -577,7 +577,7 @@ static int readOpcode(struct InternalInstruction* insn) {
|
|||||||
insn->threeByteEscape = 0x38;
|
insn->threeByteEscape = 0x38;
|
||||||
insn->opcodeType = THREEBYTE_38;
|
insn->opcodeType = THREEBYTE_38;
|
||||||
return consumeByte(insn, &insn->opcode);
|
return consumeByte(insn, &insn->opcode);
|
||||||
case VEX_LOB_0F3A:
|
case VEX_LOB_0F3A:
|
||||||
insn->twoByteEscape = 0x0f;
|
insn->twoByteEscape = 0x0f;
|
||||||
insn->threeByteEscape = 0x3a;
|
insn->threeByteEscape = 0x3a;
|
||||||
insn->opcodeType = THREEBYTE_3A;
|
insn->opcodeType = THREEBYTE_3A;
|
||||||
@ -590,68 +590,68 @@ static int readOpcode(struct InternalInstruction* insn) {
|
|||||||
insn->opcodeType = TWOBYTE;
|
insn->opcodeType = TWOBYTE;
|
||||||
return consumeByte(insn, &insn->opcode);
|
return consumeByte(insn, &insn->opcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consumeByte(insn, ¤t))
|
if (consumeByte(insn, ¤t))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (current == 0x0f) {
|
if (current == 0x0f) {
|
||||||
dbgprintf(insn, "Found a two-byte escape prefix (0x%hhx)", current);
|
dbgprintf(insn, "Found a two-byte escape prefix (0x%hhx)", current);
|
||||||
|
|
||||||
insn->twoByteEscape = current;
|
insn->twoByteEscape = current;
|
||||||
|
|
||||||
if (consumeByte(insn, ¤t))
|
if (consumeByte(insn, ¤t))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (current == 0x38) {
|
if (current == 0x38) {
|
||||||
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
||||||
|
|
||||||
insn->threeByteEscape = current;
|
insn->threeByteEscape = current;
|
||||||
|
|
||||||
if (consumeByte(insn, ¤t))
|
if (consumeByte(insn, ¤t))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
insn->opcodeType = THREEBYTE_38;
|
insn->opcodeType = THREEBYTE_38;
|
||||||
} else if (current == 0x3a) {
|
} else if (current == 0x3a) {
|
||||||
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
||||||
|
|
||||||
insn->threeByteEscape = current;
|
insn->threeByteEscape = current;
|
||||||
|
|
||||||
if (consumeByte(insn, ¤t))
|
if (consumeByte(insn, ¤t))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
insn->opcodeType = THREEBYTE_3A;
|
insn->opcodeType = THREEBYTE_3A;
|
||||||
} else if (current == 0xa6) {
|
} else if (current == 0xa6) {
|
||||||
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
||||||
|
|
||||||
insn->threeByteEscape = current;
|
insn->threeByteEscape = current;
|
||||||
|
|
||||||
if (consumeByte(insn, ¤t))
|
if (consumeByte(insn, ¤t))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
insn->opcodeType = THREEBYTE_A6;
|
insn->opcodeType = THREEBYTE_A6;
|
||||||
} else if (current == 0xa7) {
|
} else if (current == 0xa7) {
|
||||||
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
|
||||||
|
|
||||||
insn->threeByteEscape = current;
|
insn->threeByteEscape = current;
|
||||||
|
|
||||||
if (consumeByte(insn, ¤t))
|
if (consumeByte(insn, ¤t))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
insn->opcodeType = THREEBYTE_A7;
|
insn->opcodeType = THREEBYTE_A7;
|
||||||
} else {
|
} else {
|
||||||
dbgprintf(insn, "Didn't find a three-byte escape prefix");
|
dbgprintf(insn, "Didn't find a three-byte escape prefix");
|
||||||
|
|
||||||
insn->opcodeType = TWOBYTE;
|
insn->opcodeType = TWOBYTE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point we have consumed the full opcode.
|
* At this point we have consumed the full opcode.
|
||||||
* Anything we consume from here on must be unconsumed.
|
* Anything we consume from here on must be unconsumed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
insn->opcode = current;
|
insn->opcode = current;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,19 +673,19 @@ static int getIDWithAttrMask(uint16_t* instructionID,
|
|||||||
struct InternalInstruction* insn,
|
struct InternalInstruction* insn,
|
||||||
uint8_t attrMask) {
|
uint8_t attrMask) {
|
||||||
BOOL hasModRMExtension;
|
BOOL hasModRMExtension;
|
||||||
|
|
||||||
uint8_t instructionClass;
|
uint8_t instructionClass;
|
||||||
|
|
||||||
instructionClass = contextForAttrs(attrMask);
|
instructionClass = contextForAttrs(attrMask);
|
||||||
|
|
||||||
hasModRMExtension = modRMRequired(insn->opcodeType,
|
hasModRMExtension = modRMRequired(insn->opcodeType,
|
||||||
instructionClass,
|
instructionClass,
|
||||||
insn->opcode);
|
insn->opcode);
|
||||||
|
|
||||||
if (hasModRMExtension) {
|
if (hasModRMExtension) {
|
||||||
if (readModRM(insn))
|
if (readModRM(insn))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*instructionID = decode(insn->opcodeType,
|
*instructionID = decode(insn->opcodeType,
|
||||||
instructionClass,
|
instructionClass,
|
||||||
insn->opcode,
|
insn->opcode,
|
||||||
@ -696,7 +696,7 @@ static int getIDWithAttrMask(uint16_t* instructionID,
|
|||||||
insn->opcode,
|
insn->opcode,
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,7 +709,7 @@ static int getIDWithAttrMask(uint16_t* instructionID,
|
|||||||
*/
|
*/
|
||||||
static BOOL is16BitEquivalent(const char* orig, const char* equiv) {
|
static BOOL is16BitEquivalent(const char* orig, const char* equiv) {
|
||||||
off_t i;
|
off_t i;
|
||||||
|
|
||||||
for (i = 0;; i++) {
|
for (i = 0;; i++) {
|
||||||
if (orig[i] == '\0' && equiv[i] == '\0')
|
if (orig[i] == '\0' && equiv[i] == '\0')
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -728,8 +728,8 @@ static BOOL is16BitEquivalent(const char* orig, const char* equiv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* getID - Determines the ID of an instruction, consuming the ModR/M byte as
|
* getID - Determines the ID of an instruction, consuming the ModR/M byte as
|
||||||
* appropriate for extended and escape opcodes. Determines the attributes and
|
* appropriate for extended and escape opcodes. Determines the attributes and
|
||||||
* context for the instruction before doing so.
|
* context for the instruction before doing so.
|
||||||
*
|
*
|
||||||
* @param insn - The instruction whose ID is to be determined.
|
* @param insn - The instruction whose ID is to be determined.
|
||||||
@ -739,21 +739,21 @@ static BOOL is16BitEquivalent(const char* orig, const char* equiv) {
|
|||||||
static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
||||||
uint8_t attrMask;
|
uint8_t attrMask;
|
||||||
uint16_t instructionID;
|
uint16_t instructionID;
|
||||||
|
|
||||||
dbgprintf(insn, "getID()");
|
dbgprintf(insn, "getID()");
|
||||||
|
|
||||||
attrMask = ATTR_NONE;
|
attrMask = ATTR_NONE;
|
||||||
|
|
||||||
if (insn->mode == MODE_64BIT)
|
if (insn->mode == MODE_64BIT)
|
||||||
attrMask |= ATTR_64BIT;
|
attrMask |= ATTR_64BIT;
|
||||||
|
|
||||||
if (insn->vexSize) {
|
if (insn->vexSize) {
|
||||||
attrMask |= ATTR_VEX;
|
attrMask |= ATTR_VEX;
|
||||||
|
|
||||||
if (insn->vexSize == 3) {
|
if (insn->vexSize == 3) {
|
||||||
switch (ppFromVEX3of3(insn->vexPrefix[2])) {
|
switch (ppFromVEX3of3(insn->vexPrefix[2])) {
|
||||||
case VEX_PREFIX_66:
|
case VEX_PREFIX_66:
|
||||||
attrMask |= ATTR_OPSIZE;
|
attrMask |= ATTR_OPSIZE;
|
||||||
break;
|
break;
|
||||||
case VEX_PREFIX_F3:
|
case VEX_PREFIX_F3:
|
||||||
attrMask |= ATTR_XS;
|
attrMask |= ATTR_XS;
|
||||||
@ -762,14 +762,14 @@ static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
|||||||
attrMask |= ATTR_XD;
|
attrMask |= ATTR_XD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lFromVEX3of3(insn->vexPrefix[2]))
|
if (lFromVEX3of3(insn->vexPrefix[2]))
|
||||||
attrMask |= ATTR_VEXL;
|
attrMask |= ATTR_VEXL;
|
||||||
}
|
}
|
||||||
else if (insn->vexSize == 2) {
|
else if (insn->vexSize == 2) {
|
||||||
switch (ppFromVEX2of2(insn->vexPrefix[1])) {
|
switch (ppFromVEX2of2(insn->vexPrefix[1])) {
|
||||||
case VEX_PREFIX_66:
|
case VEX_PREFIX_66:
|
||||||
attrMask |= ATTR_OPSIZE;
|
attrMask |= ATTR_OPSIZE;
|
||||||
break;
|
break;
|
||||||
case VEX_PREFIX_F3:
|
case VEX_PREFIX_F3:
|
||||||
attrMask |= ATTR_XS;
|
attrMask |= ATTR_XS;
|
||||||
@ -778,7 +778,7 @@ static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
|||||||
attrMask |= ATTR_XD;
|
attrMask |= ATTR_XD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lFromVEX2of2(insn->vexPrefix[1]))
|
if (lFromVEX2of2(insn->vexPrefix[1]))
|
||||||
attrMask |= ATTR_VEXL;
|
attrMask |= ATTR_VEXL;
|
||||||
}
|
}
|
||||||
@ -849,26 +849,26 @@ static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
|||||||
* conservative, but in the specific case where OpSize is present but not
|
* conservative, but in the specific case where OpSize is present but not
|
||||||
* in the right place we check if there's a 16-bit operation.
|
* in the right place we check if there's a 16-bit operation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const struct InstructionSpecifier *spec;
|
const struct InstructionSpecifier *spec;
|
||||||
uint16_t instructionIDWithOpsize;
|
uint16_t instructionIDWithOpsize;
|
||||||
const char *specName, *specWithOpSizeName;
|
const char *specName, *specWithOpSizeName;
|
||||||
|
|
||||||
spec = specifierForUID(instructionID);
|
spec = specifierForUID(instructionID);
|
||||||
|
|
||||||
if (getIDWithAttrMask(&instructionIDWithOpsize,
|
if (getIDWithAttrMask(&instructionIDWithOpsize,
|
||||||
insn,
|
insn,
|
||||||
attrMask | ATTR_OPSIZE)) {
|
attrMask | ATTR_OPSIZE)) {
|
||||||
/*
|
/*
|
||||||
* ModRM required with OpSize but not present; give up and return version
|
* ModRM required with OpSize but not present; give up and return version
|
||||||
* without OpSize set
|
* without OpSize set
|
||||||
*/
|
*/
|
||||||
|
|
||||||
insn->instructionID = instructionID;
|
insn->instructionID = instructionID;
|
||||||
insn->spec = spec;
|
insn->spec = spec;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
specName = x86DisassemblerGetInstrName(instructionID, miiArg);
|
specName = x86DisassemblerGetInstrName(instructionID, miiArg);
|
||||||
specWithOpSizeName =
|
specWithOpSizeName =
|
||||||
x86DisassemblerGetInstrName(instructionIDWithOpsize, miiArg);
|
x86DisassemblerGetInstrName(instructionIDWithOpsize, miiArg);
|
||||||
@ -895,10 +895,10 @@ static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
|||||||
const struct InstructionSpecifier *specWithNewOpcode;
|
const struct InstructionSpecifier *specWithNewOpcode;
|
||||||
|
|
||||||
spec = specifierForUID(instructionID);
|
spec = specifierForUID(instructionID);
|
||||||
|
|
||||||
/* Borrow opcode from one of the other XCHGar opcodes */
|
/* Borrow opcode from one of the other XCHGar opcodes */
|
||||||
insn->opcode = 0x91;
|
insn->opcode = 0x91;
|
||||||
|
|
||||||
if (getIDWithAttrMask(&instructionIDWithNewOpcode,
|
if (getIDWithAttrMask(&instructionIDWithNewOpcode,
|
||||||
insn,
|
insn,
|
||||||
attrMask)) {
|
attrMask)) {
|
||||||
@ -919,10 +919,10 @@ static int getID(struct InternalInstruction* insn, const void *miiArg) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
insn->instructionID = instructionID;
|
insn->instructionID = instructionID;
|
||||||
insn->spec = specifierForUID(insn->instructionID);
|
insn->spec = specifierForUID(insn->instructionID);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -937,14 +937,14 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
SIBIndex sibIndexBase = 0;
|
SIBIndex sibIndexBase = 0;
|
||||||
SIBBase sibBaseBase = 0;
|
SIBBase sibBaseBase = 0;
|
||||||
uint8_t index, base;
|
uint8_t index, base;
|
||||||
|
|
||||||
dbgprintf(insn, "readSIB()");
|
dbgprintf(insn, "readSIB()");
|
||||||
|
|
||||||
if (insn->consumedSIB)
|
if (insn->consumedSIB)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
insn->consumedSIB = TRUE;
|
insn->consumedSIB = TRUE;
|
||||||
|
|
||||||
switch (insn->addressSize) {
|
switch (insn->addressSize) {
|
||||||
case 2:
|
case 2:
|
||||||
dbgprintf(insn, "SIB-based addressing doesn't work in 16-bit mode");
|
dbgprintf(insn, "SIB-based addressing doesn't work in 16-bit mode");
|
||||||
@ -962,9 +962,9 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
|
|
||||||
if (consumeByte(insn, &insn->sib))
|
if (consumeByte(insn, &insn->sib))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
index = indexFromSIB(insn->sib) | (xFromREX(insn->rexPrefix) << 3);
|
index = indexFromSIB(insn->sib) | (xFromREX(insn->rexPrefix) << 3);
|
||||||
|
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0x4:
|
case 0x4:
|
||||||
insn->sibIndex = SIB_INDEX_NONE;
|
insn->sibIndex = SIB_INDEX_NONE;
|
||||||
@ -976,7 +976,7 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
insn->sibIndex = SIB_INDEX_NONE;
|
insn->sibIndex = SIB_INDEX_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (scaleFromSIB(insn->sib)) {
|
switch (scaleFromSIB(insn->sib)) {
|
||||||
case 0:
|
case 0:
|
||||||
insn->sibScale = 1;
|
insn->sibScale = 1;
|
||||||
@ -991,9 +991,9 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
insn->sibScale = 8;
|
insn->sibScale = 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
base = baseFromSIB(insn->sib) | (bFromREX(insn->rexPrefix) << 3);
|
base = baseFromSIB(insn->sib) | (bFromREX(insn->rexPrefix) << 3);
|
||||||
|
|
||||||
switch (base) {
|
switch (base) {
|
||||||
case 0x5:
|
case 0x5:
|
||||||
switch (modFromModRM(insn->modRM)) {
|
switch (modFromModRM(insn->modRM)) {
|
||||||
@ -1003,12 +1003,12 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
break;
|
break;
|
||||||
case 0x1:
|
case 0x1:
|
||||||
insn->eaDisplacement = EA_DISP_8;
|
insn->eaDisplacement = EA_DISP_8;
|
||||||
insn->sibBase = (insn->addressSize == 4 ?
|
insn->sibBase = (insn->addressSize == 4 ?
|
||||||
SIB_BASE_EBP : SIB_BASE_RBP);
|
SIB_BASE_EBP : SIB_BASE_RBP);
|
||||||
break;
|
break;
|
||||||
case 0x2:
|
case 0x2:
|
||||||
insn->eaDisplacement = EA_DISP_32;
|
insn->eaDisplacement = EA_DISP_32;
|
||||||
insn->sibBase = (insn->addressSize == 4 ?
|
insn->sibBase = (insn->addressSize == 4 ?
|
||||||
SIB_BASE_EBP : SIB_BASE_RBP);
|
SIB_BASE_EBP : SIB_BASE_RBP);
|
||||||
break;
|
break;
|
||||||
case 0x3:
|
case 0x3:
|
||||||
@ -1020,7 +1020,7 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
insn->sibBase = (SIBBase)(sibBaseBase + base);
|
insn->sibBase = (SIBBase)(sibBaseBase + base);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,22 +1028,22 @@ static int readSIB(struct InternalInstruction* insn) {
|
|||||||
* readDisplacement - Consumes the displacement of an instruction.
|
* readDisplacement - Consumes the displacement of an instruction.
|
||||||
*
|
*
|
||||||
* @param insn - The instruction whose displacement is to be read.
|
* @param insn - The instruction whose displacement is to be read.
|
||||||
* @return - 0 if the displacement byte was successfully read; nonzero
|
* @return - 0 if the displacement byte was successfully read; nonzero
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
static int readDisplacement(struct InternalInstruction* insn) {
|
static int readDisplacement(struct InternalInstruction* insn) {
|
||||||
int8_t d8;
|
int8_t d8;
|
||||||
int16_t d16;
|
int16_t d16;
|
||||||
int32_t d32;
|
int32_t d32;
|
||||||
|
|
||||||
dbgprintf(insn, "readDisplacement()");
|
dbgprintf(insn, "readDisplacement()");
|
||||||
|
|
||||||
if (insn->consumedDisplacement)
|
if (insn->consumedDisplacement)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
insn->consumedDisplacement = TRUE;
|
insn->consumedDisplacement = TRUE;
|
||||||
insn->displacementOffset = insn->readerCursor - insn->startLocation;
|
insn->displacementOffset = insn->readerCursor - insn->startLocation;
|
||||||
|
|
||||||
switch (insn->eaDisplacement) {
|
switch (insn->eaDisplacement) {
|
||||||
case EA_DISP_NONE:
|
case EA_DISP_NONE:
|
||||||
insn->consumedDisplacement = FALSE;
|
insn->consumedDisplacement = FALSE;
|
||||||
@ -1064,7 +1064,7 @@ static int readDisplacement(struct InternalInstruction* insn) {
|
|||||||
insn->displacement = d32;
|
insn->displacement = d32;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
insn->consumedDisplacement = TRUE;
|
insn->consumedDisplacement = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1076,22 +1076,22 @@ static int readDisplacement(struct InternalInstruction* insn) {
|
|||||||
* @param insn - The instruction whose addressing information is to be read.
|
* @param insn - The instruction whose addressing information is to be read.
|
||||||
* @return - 0 if the information was successfully read; nonzero otherwise.
|
* @return - 0 if the information was successfully read; nonzero otherwise.
|
||||||
*/
|
*/
|
||||||
static int readModRM(struct InternalInstruction* insn) {
|
static int readModRM(struct InternalInstruction* insn) {
|
||||||
uint8_t mod, rm, reg;
|
uint8_t mod, rm, reg;
|
||||||
|
|
||||||
dbgprintf(insn, "readModRM()");
|
dbgprintf(insn, "readModRM()");
|
||||||
|
|
||||||
if (insn->consumedModRM)
|
if (insn->consumedModRM)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (consumeByte(insn, &insn->modRM))
|
if (consumeByte(insn, &insn->modRM))
|
||||||
return -1;
|
return -1;
|
||||||
insn->consumedModRM = TRUE;
|
insn->consumedModRM = TRUE;
|
||||||
|
|
||||||
mod = modFromModRM(insn->modRM);
|
mod = modFromModRM(insn->modRM);
|
||||||
rm = rmFromModRM(insn->modRM);
|
rm = rmFromModRM(insn->modRM);
|
||||||
reg = regFromModRM(insn->modRM);
|
reg = regFromModRM(insn->modRM);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This goes by insn->registerSize to pick the correct register, which messes
|
* This goes by insn->registerSize to pick the correct register, which messes
|
||||||
* up if we're using (say) XMM or 8-bit register operands. That gets fixed in
|
* up if we're using (say) XMM or 8-bit register operands. That gets fixed in
|
||||||
@ -1111,16 +1111,16 @@ static int readModRM(struct InternalInstruction* insn) {
|
|||||||
insn->eaRegBase = EA_REG_RAX;
|
insn->eaRegBase = EA_REG_RAX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
reg |= rFromREX(insn->rexPrefix) << 3;
|
reg |= rFromREX(insn->rexPrefix) << 3;
|
||||||
rm |= bFromREX(insn->rexPrefix) << 3;
|
rm |= bFromREX(insn->rexPrefix) << 3;
|
||||||
|
|
||||||
insn->reg = (Reg)(insn->regBase + reg);
|
insn->reg = (Reg)(insn->regBase + reg);
|
||||||
|
|
||||||
switch (insn->addressSize) {
|
switch (insn->addressSize) {
|
||||||
case 2:
|
case 2:
|
||||||
insn->eaBaseBase = EA_BASE_BX_SI;
|
insn->eaBaseBase = EA_BASE_BX_SI;
|
||||||
|
|
||||||
switch (mod) {
|
switch (mod) {
|
||||||
case 0x0:
|
case 0x0:
|
||||||
if (rm == 0x6) {
|
if (rm == 0x6) {
|
||||||
@ -1155,14 +1155,14 @@ static int readModRM(struct InternalInstruction* insn) {
|
|||||||
case 4:
|
case 4:
|
||||||
case 8:
|
case 8:
|
||||||
insn->eaBaseBase = (insn->addressSize == 4 ? EA_BASE_EAX : EA_BASE_RAX);
|
insn->eaBaseBase = (insn->addressSize == 4 ? EA_BASE_EAX : EA_BASE_RAX);
|
||||||
|
|
||||||
switch (mod) {
|
switch (mod) {
|
||||||
case 0x0:
|
case 0x0:
|
||||||
insn->eaDisplacement = EA_DISP_NONE; /* readSIB may override this */
|
insn->eaDisplacement = EA_DISP_NONE; /* readSIB may override this */
|
||||||
switch (rm) {
|
switch (rm) {
|
||||||
case 0x4:
|
case 0x4:
|
||||||
case 0xc: /* in case REXW.b is set */
|
case 0xc: /* in case REXW.b is set */
|
||||||
insn->eaBase = (insn->addressSize == 4 ?
|
insn->eaBase = (insn->addressSize == 4 ?
|
||||||
EA_BASE_sib : EA_BASE_sib64);
|
EA_BASE_sib : EA_BASE_sib64);
|
||||||
readSIB(insn);
|
readSIB(insn);
|
||||||
if (readDisplacement(insn))
|
if (readDisplacement(insn))
|
||||||
@ -1204,7 +1204,7 @@ static int readModRM(struct InternalInstruction* insn) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} /* switch (insn->addressSize) */
|
} /* switch (insn->addressSize) */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1287,12 +1287,12 @@ GENERIC_FIXUP_FUNC(fixupRMValue, insn->eaRegBase, EA_REG)
|
|||||||
* @return - 0 if fixup was successful; -1 if the register returned was
|
* @return - 0 if fixup was successful; -1 if the register returned was
|
||||||
* invalid for its class.
|
* invalid for its class.
|
||||||
*/
|
*/
|
||||||
static int fixupReg(struct InternalInstruction *insn,
|
static int fixupReg(struct InternalInstruction *insn,
|
||||||
const struct OperandSpecifier *op) {
|
const struct OperandSpecifier *op) {
|
||||||
uint8_t valid;
|
uint8_t valid;
|
||||||
|
|
||||||
dbgprintf(insn, "fixupReg()");
|
dbgprintf(insn, "fixupReg()");
|
||||||
|
|
||||||
switch ((OperandEncoding)op->encoding) {
|
switch ((OperandEncoding)op->encoding) {
|
||||||
default:
|
default:
|
||||||
debug("Expected a REG or R/M encoding in fixupReg");
|
debug("Expected a REG or R/M encoding in fixupReg");
|
||||||
@ -1324,12 +1324,12 @@ static int fixupReg(struct InternalInstruction *insn,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* readOpcodeModifier - Reads an operand from the opcode field of an
|
* readOpcodeModifier - Reads an operand from the opcode field of an
|
||||||
* instruction. Handles AddRegFrm instructions.
|
* instruction. Handles AddRegFrm instructions.
|
||||||
*
|
*
|
||||||
* @param insn - The instruction whose opcode field is to be read.
|
* @param insn - The instruction whose opcode field is to be read.
|
||||||
@ -1339,12 +1339,12 @@ static int fixupReg(struct InternalInstruction *insn,
|
|||||||
*/
|
*/
|
||||||
static int readOpcodeModifier(struct InternalInstruction* insn) {
|
static int readOpcodeModifier(struct InternalInstruction* insn) {
|
||||||
dbgprintf(insn, "readOpcodeModifier()");
|
dbgprintf(insn, "readOpcodeModifier()");
|
||||||
|
|
||||||
if (insn->consumedOpcodeModifier)
|
if (insn->consumedOpcodeModifier)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
insn->consumedOpcodeModifier = TRUE;
|
insn->consumedOpcodeModifier = TRUE;
|
||||||
|
|
||||||
switch (insn->spec->modifierType) {
|
switch (insn->spec->modifierType) {
|
||||||
default:
|
default:
|
||||||
debug("Unknown modifier type.");
|
debug("Unknown modifier type.");
|
||||||
@ -1358,11 +1358,11 @@ static int readOpcodeModifier(struct InternalInstruction* insn) {
|
|||||||
case MODIFIER_MODRM:
|
case MODIFIER_MODRM:
|
||||||
insn->opcodeModifier = insn->modRM - insn->spec->modifierBase;
|
insn->opcodeModifier = insn->modRM - insn->spec->modifierBase;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* readOpcodeRegister - Reads an operand from the opcode field of an
|
* readOpcodeRegister - Reads an operand from the opcode field of an
|
||||||
* instruction and interprets it appropriately given the operand width.
|
* instruction and interprets it appropriately given the operand width.
|
||||||
* Handles AddRegFrm instructions.
|
* Handles AddRegFrm instructions.
|
||||||
*
|
*
|
||||||
@ -1377,39 +1377,39 @@ static int readOpcodeRegister(struct InternalInstruction* insn, uint8_t size) {
|
|||||||
|
|
||||||
if (readOpcodeModifier(insn))
|
if (readOpcodeModifier(insn))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
size = insn->registerSize;
|
size = insn->registerSize;
|
||||||
|
|
||||||
switch (size) {
|
switch (size) {
|
||||||
case 1:
|
case 1:
|
||||||
insn->opcodeRegister = (Reg)(MODRM_REG_AL + ((bFromREX(insn->rexPrefix) << 3)
|
insn->opcodeRegister = (Reg)(MODRM_REG_AL + ((bFromREX(insn->rexPrefix) << 3)
|
||||||
| insn->opcodeModifier));
|
| insn->opcodeModifier));
|
||||||
if (insn->rexPrefix &&
|
if (insn->rexPrefix &&
|
||||||
insn->opcodeRegister >= MODRM_REG_AL + 0x4 &&
|
insn->opcodeRegister >= MODRM_REG_AL + 0x4 &&
|
||||||
insn->opcodeRegister < MODRM_REG_AL + 0x8) {
|
insn->opcodeRegister < MODRM_REG_AL + 0x8) {
|
||||||
insn->opcodeRegister = (Reg)(MODRM_REG_SPL
|
insn->opcodeRegister = (Reg)(MODRM_REG_SPL
|
||||||
+ (insn->opcodeRegister - MODRM_REG_AL - 4));
|
+ (insn->opcodeRegister - MODRM_REG_AL - 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
insn->opcodeRegister = (Reg)(MODRM_REG_AX
|
insn->opcodeRegister = (Reg)(MODRM_REG_AX
|
||||||
+ ((bFromREX(insn->rexPrefix) << 3)
|
+ ((bFromREX(insn->rexPrefix) << 3)
|
||||||
| insn->opcodeModifier));
|
| insn->opcodeModifier));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
insn->opcodeRegister = (Reg)(MODRM_REG_EAX
|
insn->opcodeRegister = (Reg)(MODRM_REG_EAX
|
||||||
+ ((bFromREX(insn->rexPrefix) << 3)
|
+ ((bFromREX(insn->rexPrefix) << 3)
|
||||||
| insn->opcodeModifier));
|
| insn->opcodeModifier));
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
insn->opcodeRegister = (Reg)(MODRM_REG_RAX
|
insn->opcodeRegister = (Reg)(MODRM_REG_RAX
|
||||||
+ ((bFromREX(insn->rexPrefix) << 3)
|
+ ((bFromREX(insn->rexPrefix) << 3)
|
||||||
| insn->opcodeModifier));
|
| insn->opcodeModifier));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1427,20 +1427,20 @@ static int readImmediate(struct InternalInstruction* insn, uint8_t size) {
|
|||||||
uint16_t imm16;
|
uint16_t imm16;
|
||||||
uint32_t imm32;
|
uint32_t imm32;
|
||||||
uint64_t imm64;
|
uint64_t imm64;
|
||||||
|
|
||||||
dbgprintf(insn, "readImmediate()");
|
dbgprintf(insn, "readImmediate()");
|
||||||
|
|
||||||
if (insn->numImmediatesConsumed == 2) {
|
if (insn->numImmediatesConsumed == 2) {
|
||||||
debug("Already consumed two immediates");
|
debug("Already consumed two immediates");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
size = insn->immediateSize;
|
size = insn->immediateSize;
|
||||||
else
|
else
|
||||||
insn->immediateSize = size;
|
insn->immediateSize = size;
|
||||||
insn->immediateOffset = insn->readerCursor - insn->startLocation;
|
insn->immediateOffset = insn->readerCursor - insn->startLocation;
|
||||||
|
|
||||||
switch (size) {
|
switch (size) {
|
||||||
case 1:
|
case 1:
|
||||||
if (consumeByte(insn, &imm8))
|
if (consumeByte(insn, &imm8))
|
||||||
@ -1463,9 +1463,9 @@ static int readImmediate(struct InternalInstruction* insn, uint8_t size) {
|
|||||||
insn->immediates[insn->numImmediatesConsumed] = imm64;
|
insn->immediates[insn->numImmediatesConsumed] = imm64;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
insn->numImmediatesConsumed++;
|
insn->numImmediatesConsumed++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1478,7 +1478,7 @@ static int readImmediate(struct InternalInstruction* insn, uint8_t size) {
|
|||||||
*/
|
*/
|
||||||
static int readVVVV(struct InternalInstruction* insn) {
|
static int readVVVV(struct InternalInstruction* insn) {
|
||||||
dbgprintf(insn, "readVVVV()");
|
dbgprintf(insn, "readVVVV()");
|
||||||
|
|
||||||
if (insn->vexSize == 3)
|
if (insn->vexSize == 3)
|
||||||
insn->vvvv = vvvvFromVEX3of3(insn->vexPrefix[2]);
|
insn->vvvv = vvvvFromVEX3of3(insn->vexPrefix[2]);
|
||||||
else if (insn->vexSize == 2)
|
else if (insn->vexSize == 2)
|
||||||
@ -1503,14 +1503,14 @@ static int readOperands(struct InternalInstruction* insn) {
|
|||||||
int index;
|
int index;
|
||||||
int hasVVVV, needVVVV;
|
int hasVVVV, needVVVV;
|
||||||
int sawRegImm = 0;
|
int sawRegImm = 0;
|
||||||
|
|
||||||
dbgprintf(insn, "readOperands()");
|
dbgprintf(insn, "readOperands()");
|
||||||
|
|
||||||
/* If non-zero vvvv specified, need to make sure one of the operands
|
/* If non-zero vvvv specified, need to make sure one of the operands
|
||||||
uses it. */
|
uses it. */
|
||||||
hasVVVV = !readVVVV(insn);
|
hasVVVV = !readVVVV(insn);
|
||||||
needVVVV = hasVVVV && (insn->vvvv != 0);
|
needVVVV = hasVVVV && (insn->vvvv != 0);
|
||||||
|
|
||||||
for (index = 0; index < X86_MAX_OPERANDS; ++index) {
|
for (index = 0; index < X86_MAX_OPERANDS; ++index) {
|
||||||
switch (x86OperandSets[insn->spec->operands][index].encoding) {
|
switch (x86OperandSets[insn->spec->operands][index].encoding) {
|
||||||
case ENCODING_NONE:
|
case ENCODING_NONE:
|
||||||
@ -1612,7 +1612,7 @@ static int readOperands(struct InternalInstruction* insn) {
|
|||||||
|
|
||||||
/* If we didn't find ENCODING_VVVV operand, but non-zero vvvv present, fail */
|
/* If we didn't find ENCODING_VVVV operand, but non-zero vvvv present, fail */
|
||||||
if (needVVVV) return -1;
|
if (needVVVV) return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1620,7 +1620,7 @@ static int readOperands(struct InternalInstruction* insn) {
|
|||||||
* decodeInstruction - Reads and interprets a full instruction provided by the
|
* decodeInstruction - Reads and interprets a full instruction provided by the
|
||||||
* user.
|
* user.
|
||||||
*
|
*
|
||||||
* @param insn - A pointer to the instruction to be populated. Must be
|
* @param insn - A pointer to the instruction to be populated. Must be
|
||||||
* pre-allocated.
|
* pre-allocated.
|
||||||
* @param reader - The function to be used to read the instruction's bytes.
|
* @param reader - The function to be used to read the instruction's bytes.
|
||||||
* @param readerArg - A generic argument to be passed to the reader to store
|
* @param readerArg - A generic argument to be passed to the reader to store
|
||||||
@ -1645,7 +1645,7 @@ int decodeInstruction(struct InternalInstruction* insn,
|
|||||||
uint64_t startLoc,
|
uint64_t startLoc,
|
||||||
DisassemblerMode mode) {
|
DisassemblerMode mode) {
|
||||||
memset(insn, 0, sizeof(struct InternalInstruction));
|
memset(insn, 0, sizeof(struct InternalInstruction));
|
||||||
|
|
||||||
insn->reader = reader;
|
insn->reader = reader;
|
||||||
insn->readerArg = readerArg;
|
insn->readerArg = readerArg;
|
||||||
insn->dlog = logger;
|
insn->dlog = logger;
|
||||||
@ -1654,7 +1654,7 @@ int decodeInstruction(struct InternalInstruction* insn,
|
|||||||
insn->readerCursor = startLoc;
|
insn->readerCursor = startLoc;
|
||||||
insn->mode = mode;
|
insn->mode = mode;
|
||||||
insn->numImmediatesConsumed = 0;
|
insn->numImmediatesConsumed = 0;
|
||||||
|
|
||||||
if (readPrefixes(insn) ||
|
if (readPrefixes(insn) ||
|
||||||
readOpcode(insn) ||
|
readOpcode(insn) ||
|
||||||
getID(insn, miiArg) ||
|
getID(insn, miiArg) ||
|
||||||
@ -1663,14 +1663,14 @@ int decodeInstruction(struct InternalInstruction* insn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
insn->operands = &x86OperandSets[insn->spec->operands][0];
|
insn->operands = &x86OperandSets[insn->spec->operands][0];
|
||||||
|
|
||||||
insn->length = insn->readerCursor - insn->startLocation;
|
insn->length = insn->readerCursor - insn->startLocation;
|
||||||
|
|
||||||
dbgprintf(insn, "Read from 0x%llx to 0x%llx: length %zu",
|
dbgprintf(insn, "Read from 0x%llx to 0x%llx: length %zu",
|
||||||
startLoc, insn->readerCursor, insn->length);
|
startLoc, insn->readerCursor, insn->length);
|
||||||
|
|
||||||
if (insn->length > 15)
|
if (insn->length > 15)
|
||||||
dbgprintf(insn, "Instruction exceeds 15-byte limit");
|
dbgprintf(insn, "Instruction exceeds 15-byte limit");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user