diff --git a/decode.c b/decode.c index 85c4a53..8116d6b 100644 --- a/decode.c +++ b/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. diff --git a/instrs.txt b/instrs.txt index 5419b24..4ac3df4 100644 --- a/instrs.txt +++ b/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 diff --git a/parseinstrs.py b/parseinstrs.py index 0643633..ab4fef4 100644 --- a/parseinstrs.py +++ b/parseinstrs.py @@ -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(?PVEX\.)?(?PNP|66|F2|F3)\.(?PW[01]\.)?(?PL[01]\.)?)?(?P(?:[0-9a-f]{2})+)(?P//?[0-7]|//[c-f][0-9a-f])?(?P\+)?$") +opcode_regex = re.compile(r"^(?:(?P(?PVEX\.)?(?PNP|66|F2|F3)\.(?PW[01]\.)?(?PL[01]\.)?)|R(?PNP|F2|F3).)?(?P(?:[0-9a-f]{2})+)(?P//?[0-7]|//[c-f][0-9a-f])?(?P\+)?$") 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)]