Add REP-prefix table
This commit is contained in:
8
decode.c
8
decode.c
@@ -38,6 +38,7 @@ typedef enum DecodeMode DecodeMode;
|
||||
#define ENTRY_TABLE72 4
|
||||
#define ENTRY_TABLE_PREFIX 5
|
||||
#define ENTRY_TABLE_VEX 6
|
||||
#define ENTRY_TABLE_PREFIX_REP 7
|
||||
#define ENTRY_MASK 7
|
||||
|
||||
#define ENTRY_UNPACK(table,kind,entry) do { \
|
||||
@@ -388,6 +389,13 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
|
||||
prefixes &= ~(PREFIX_OPSZ | PREFIX_REPNZ | PREFIX_REP);
|
||||
ENTRY_UNPACK(table, kind, table[index]);
|
||||
}
|
||||
else if (kind == ENTRY_TABLE_PREFIX_REP)
|
||||
{
|
||||
// Discard 66h mandatory prefix
|
||||
uint8_t index = mandatory_prefix != 1 ? mandatory_prefix : 0;
|
||||
prefixes &= ~(PREFIX_REPNZ | PREFIX_REP);
|
||||
ENTRY_UNPACK(table, kind, table[index]);
|
||||
}
|
||||
|
||||
// For VEX prefix, we have to distinguish between VEX.W and VEX.L which may
|
||||
// be part of the opcode.
|
||||
|
||||
12
instrs.txt
12
instrs.txt
@@ -422,8 +422,10 @@ F3.0fb8 RM GP GP - - POPCNT
|
||||
0fba/6 MI GP IMM8 - - BTR_IMM IMM_8 LOCK
|
||||
0fba/7 MI GP IMM8 - - BTC_IMM IMM_8 LOCK
|
||||
0fbb MR GP GP - - BTC LOCK
|
||||
0fbc RM GP GP - - BSF_TZCNT
|
||||
0fbd RM GP GP - - BSR_LZCNT
|
||||
RNP.0fbc RM GP GP - - BSF
|
||||
RF3.0fbc RM GP GP - - TZCNT
|
||||
RNP.0fbd RM GP GP - - BSR
|
||||
RF3.0fbd RM GP GP - - LZCNT
|
||||
0fbe RM GP GP8 - - MOVSX
|
||||
0fbf RM GP GP16 - - MOVSX
|
||||
0fc0 MR GP GP - - XADD SIZE_8 LOCK
|
||||
@@ -433,8 +435,10 @@ NP.0fc3 MR GP GP - - MOVNTI
|
||||
0fc8+ O GP - - - BSWAP
|
||||
0fff RM GP GP - - UD0
|
||||
#
|
||||
0f38f0 RM GP GP - - MOVBE_CRC32
|
||||
0f38f1 MR GP GP - - MOVBE_CRC32
|
||||
RNP.0f38f0 RM GP GP - - MOVBE MUSTMEM
|
||||
RF2.0f38f0 RM GP GP8 - - CRC32
|
||||
RNP.0f38f1 MR GP GP - - MOVBE MUSTMEM
|
||||
RF2.0f38f1 MR GP GP - - CRC32
|
||||
#
|
||||
# SSE
|
||||
NP.0f10 RM XMM XMM - - SSE_MOVUPS
|
||||
|
||||
@@ -139,6 +139,7 @@ class EntryKind(Enum):
|
||||
TABLE72 = 4
|
||||
TABLE_PREFIX = 5
|
||||
TABLE_VEX = 6
|
||||
TABLE_PREFIX_REP = 7
|
||||
|
||||
class TrieEntry(namedtuple("TrieEntry", "kind,items,payload")):
|
||||
__slots__ = ()
|
||||
@@ -148,6 +149,7 @@ class TrieEntry(namedtuple("TrieEntry", "kind,items,payload")):
|
||||
EntryKind.TABLE72: 72,
|
||||
EntryKind.TABLE_PREFIX: 8,
|
||||
EntryKind.TABLE_VEX: 4,
|
||||
EntryKind.TABLE_PREFIX_REP: 4,
|
||||
}
|
||||
@classmethod
|
||||
def table(cls, kind):
|
||||
@@ -170,7 +172,7 @@ class TrieEntry(namedtuple("TrieEntry", "kind,items,payload")):
|
||||
return TrieEntry(self.kind, tuple(mapped_items), self.payload)
|
||||
|
||||
import re
|
||||
opcode_regex = re.compile(r"^(?P<prefixes>(?P<vex>VEX\.)?(?P<legacy>NP|66|F2|F3)\.(?P<rexw>W[01]\.)?(?P<vexl>L[01]\.)?)?(?P<opcode>(?:[0-9a-f]{2})+)(?P<modrm>//?[0-7]|//[c-f][0-9a-f])?(?P<extended>\+)?$")
|
||||
opcode_regex = re.compile(r"^(?:(?P<prefixes>(?P<vex>VEX\.)?(?P<legacy>NP|66|F2|F3)\.(?P<rexw>W[01]\.)?(?P<vexl>L[01]\.)?)|R(?P<repprefix>NP|F2|F3).)?(?P<opcode>(?:[0-9a-f]{2})+)(?P<modrm>//?[0-7]|//[c-f][0-9a-f])?(?P<extended>\+)?$")
|
||||
|
||||
def parse_opcode(opcode_string):
|
||||
"""
|
||||
@@ -213,6 +215,9 @@ def parse_opcode(opcode_string):
|
||||
|
||||
entries = list(map(sum, product(rexw, vexl)))
|
||||
opcode.append((EntryKind.TABLE_VEX, entries))
|
||||
elif match.group("repprefix"):
|
||||
rep = {"NP": 0, "F3": 2, "F2": 3}[match.group("repprefix")]
|
||||
opcode.append((EntryKind.TABLE_PREFIX_REP, [rep]))
|
||||
|
||||
kinds, values = zip(*opcode)
|
||||
return [tuple(zip(kinds, prod)) for prod in product(*values)]
|
||||
|
||||
Reference in New Issue
Block a user