Permalink
Browse files

Tests/Unused vars/Comments/Move segment selector code

  • Loading branch information...
1 parent 7ee179f commit cb584c7fa71b424a1442ec294560282bddc1dc25 @Nukem9 Nukem9 committed Jan 22, 2016
Showing with 77 additions and 59 deletions.
  1. +3 −1 XEDParse.vcxproj
  2. +6 −0 XEDParse.vcxproj.filters
  3. +3 −0 XEDParseTest/Tests.h
  4. +2 −53 src/Operand.cpp
  5. +53 −0 src/OperandSegSel.cpp
  6. +3 −0 src/OperandSegSel.h
  7. +1 −0 src/Parser.h
  8. +6 −5 src/Validator.cpp
View
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@@ -31,6 +31,7 @@
<ClCompile Include="src\MnemonicTable.cpp" />
<ClCompile Include="src\Operand.cpp" />
<ClCompile Include="src\OperandMem.cpp" />
+ <ClCompile Include="src\OperandSegSel.cpp" />
<ClCompile Include="src\OpSize.cpp" />
<ClCompile Include="src\Parser.cpp" />
<ClCompile Include="src\ParseTest.cpp" />
@@ -45,6 +46,7 @@
<ClInclude Include="src\MnemonicTable.h" />
<ClInclude Include="src\Operand.h" />
<ClInclude Include="src\OperandMem.h" />
+ <ClInclude Include="src\OperandSegSel.h" />
<ClInclude Include="src\OpSize.h" />
<ClInclude Include="src\Parser.h" />
<ClInclude Include="src\ParseTest.h" />
@@ -48,6 +48,9 @@
<ClCompile Include="src\XEDParse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\OperandSegSel.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\BranchInst.h">
@@ -290,5 +293,8 @@
<ClInclude Include="xed2\include\xed-version.h">
<Filter>Header Files\XED2</Filter>
</ClInclude>
+ <ClInclude Include="src\OperandSegSel.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
@@ -55,6 +55,7 @@ static XED_TestEntry XED_AllTests[] =
{ ENTRY(false, 0x00405C23, 6, "\x69\xC0\xFF\x01\x00\x00", "IMUL EAX, EAX, 0x1FF") },
{ ENTRY(false, 0x00405C23, 6, "\x69\xC0\xFF\x00\x00\x00", "IMUL EAX, EAX, 0xFF") },
{ ENTRY(false, 0x00405C23, 6, "\x69\xC0\xFE\x00\x00\x00", "IMUL EAX, EAX, 0xFE") },
+ { ENTRY(false, 0x00405C23, 3, "\x6B\xC0\x1E", "IMUL EAX, EAX, 0x1E") },
{ ENTRY(false, 0x00405C23, 5, "\xB8\x78\x56\x34\x12", "MOV EAX, 0x12345678") },
{ ENTRY(false, 0x00405C23, 5, "\xB8\xFE\xFF\xFF\xFF", "MOV EAX, 0xFFFFFFFE") },
{ ENTRY(false, 0x00405C23, 3, "\xDF\x3C\x24", "FISTP QWORD PTR [ESP]") },
@@ -76,7 +77,9 @@ static XED_TestEntry XED_AllTests[] =
{ ENTRY(true, 0x7FFCA9FF1977, 3, "\x48\x63\xD0", "MOVSXD RDX, EAX") },
{ ENTRY(true, 0x7FFCA9FF1977, 5, "\x45\x0F\xBE\x24\x2F", "MOVSX R12D, BYTE PTR [R15+RBP*1]") },
{ ENTRY(true, 0x7FFCA9FF1977, 7, "\x4D\x69\xED\x10\x01\x00\x00", "IMUL R13, R13, 0x110") },
+ { ENTRY(true, 0x7FFCA9FF1977, 4, "\x4D\x6B\xED\x11", "IMUL R13, R13, 0x11") },
{ ENTRY(true, 0x7FFCA9FF1977, 11, "\x48\xC7\x05\xAF\x55\x0F\x00\xFF\x00\x00\x00", "MOV QWORD PTR [RIP+0xF55AF], 0xFF") },
+ { ENTRY(true, 0x000000000000, 11, "\x48\xC7\x05\xAF\x55\x0F\x00\xFF\x00\x00\x00", "MOV QWORD PTR [F55BA], 0xFF") },
{ ENTRY(true, 0x7FFCA9FF1977, 11, "\x48\xC7\x05\xAF\x55\x0F\x00\xFE\xFF\xFF\xFF", "MOV QWORD PTR [RIP+0xF55AF], 0xFFFFFFFFFFFFFFFE") },
{ ENTRY(true, 0x7FFCA9FF1977, 4, "\x48\x0F\xC7\x08", "CMPXCHG16B [RAX]") },
{ ENTRY(true, 0x7FFCA9FF1977, 3, "\x0F\xC7\x08", "CMPXCHG8B [RAX]") },
View
@@ -26,61 +26,10 @@ OPSIZE PromoteImmediateWidth(bool Signed, ULONGLONG Value, OPSIZE Width)
return Width;
}
-bool HandleSegSelectorOperand(XEDPARSE* Parse, const char* Value, InstOperand* Operand)
-{
- char selector[64];
- char offset[64];
-
- // Copy the prefix into a buffer
- strcpy(selector, Value);
- *strchr(selector, ':') = '\0';
-
- // Copy the offset
- strcpy(offset, strrchr(Value, ':') + 1);
-
- // The segment selector is always a number from 0 to 0xFFFF
- if(strlen(selector) > 0)
- {
- ULONGLONG selVal = 0;
-
- if(!valfromstring(selector, &selVal) || abs((LONGLONG)selVal) > USHRT_MAX)
- {
- strcpy(Parse->error, "Invalid segment selector value");
- return false;
- }
-
- Operand->Sel.Selector = selVal & 0xFFFF;
- }
- else
- {
- strcpy(Parse->error, "Invalid segment selector");
- return false;
- }
-
- // Determine offset
- if(strlen(offset) <= 0)
- {
- strcpy(Parse->error, "Invalid offset");
- return false;
- }
-
- // Ex: 033:X86SwitchTo64BitMode
- ULONGLONG offsetVal = 0;
-
- if(!valfromstring(offset, &offsetVal) && !(Parse->cbUnknown && Parse->cbUnknown(offset, &offsetVal)))
- {
- sprintf(Parse->error, "Unable to parse offset '%s'", offset);
- return false;
- }
-
- Operand->Sel.Offset = offsetVal & 0xFFFFFFFF;
- return true;
-}
-
bool AnalyzeOperand(XEDPARSE* Parse, const char* Value, InstOperand* Operand)
{
- REG registerVal = RegFromString(Value);
- ULONGLONG immVal = 0;
+ REG registerVal = RegFromString(Value);
+ ULONGLONG immVal = 0;
if(registerVal != REG_INVALID)
{
View
@@ -0,0 +1,53 @@
+#include "Translator.h"
+#include <stdio.h>
+
+bool HandleSegSelectorOperand(XEDPARSE* Parse, const char* Value, InstOperand* Operand)
+{
+ char selector[64];
+ char offset[64];
+
+ // Copy the prefix into a buffer
+ strcpy(selector, Value);
+ *strchr(selector, ':') = '\0';
+
+ // Copy the offset
+ strcpy(offset, strrchr(Value, ':') + 1);
+
+ // The segment selector is always a number from 0 to 0xFFFF
+ if(strlen(selector) > 0)
+ {
+ ULONGLONG selVal = 0;
+
+ if(!valfromstring(selector, &selVal) || abs((LONGLONG)selVal) > USHRT_MAX)
+ {
+ strcpy(Parse->error, "Invalid segment selector value");
+ return false;
+ }
+
+ Operand->Sel.Selector = selVal & 0xFFFF;
+ }
+ else
+ {
+ strcpy(Parse->error, "Invalid segment selector");
+ return false;
+ }
+
+ // Determine offset
+ if(strlen(offset) <= 0)
+ {
+ strcpy(Parse->error, "Invalid offset");
+ return false;
+ }
+
+ // Ex: 033:X86SwitchTo64BitMode
+ ULONGLONG offsetVal = 0;
+
+ if(!valfromstring(offset, &offsetVal) && !(Parse->cbUnknown && Parse->cbUnknown(offset, &offsetVal)))
+ {
+ sprintf(Parse->error, "Unable to parse offset '%s'", offset);
+ return false;
+ }
+
+ Operand->Sel.Offset = offsetVal & 0xFFFFFFFF;
+ return true;
+}
View
@@ -0,0 +1,3 @@
+#pragma once
+
+bool HandleSegSelectorOperand(XEDPARSE* Parse, const char* Value, InstOperand* Operand);
View
@@ -6,6 +6,7 @@
#include "Register.h"
#include "Operand.h"
#include "OperandMem.h"
+#include "OperandSegSel.h"
#include "Prefix.h"
struct Inst
View
@@ -380,8 +380,6 @@ void ValidateFpuOperands(XEDPARSE* Parse, Inst* Instruction)
for(int i = 0; i < type->InstructionCount; i++)
{
const xed_inst_t* inst = type->Instructions[i];
- const xed_operand_t* op = xed_inst_operand(inst, 0);
- xed_operand_enum_t name = xed_operand_name(op);
// FPU extensions only
if(xed_iform_to_extension(inst->_iform_enum) != XED_EXTENSION_X87)
@@ -421,7 +419,7 @@ bool ValidateInstOperands(XEDPARSE* Parse, Inst* Instruction)
// return false;
//
- // Xed requires an implicit "ST0" register for some X87 instructions
+ // Special case: Implicit "ST0" register required for some X87 instructions
//
ValidateFpuOperands(Parse, Instruction);
@@ -439,13 +437,13 @@ bool ValidateInstOperands(XEDPARSE* Parse, Inst* Instruction)
return ResizeSingleOperand(Parse, Instruction->Class, &Instruction->Operands[0]);
//
- // Special case for LEA (Segments can't be used)
+ // Special case: LEA (Segments can't be used)
//
if(Instruction->Class == XED_ICLASS_LEA)
Instruction->Operands[1].Segment = REG_INVALID;
//
- // Special case for XCHG (Swap memory operand)
+ // Special case: XCHG (Swap memory operand)
//
if(Instruction->Class == XED_ICLASS_XCHG)
{
@@ -570,6 +568,9 @@ void LookupTableInit()
type->IClass = iclass;
type->MinimumOperands = min(xed_inst_noperands(inst), type->MinimumOperands);
+ if(type->InstructionCount >= 32)
+ __debugbreak();
+
type->Instructions[type->InstructionCount++] = inst;
}

0 comments on commit cb584c7

Please sign in to comment.