1 // Copyright (C) 2003 Dolphin Project.
2 
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6 
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License 2.0 for more details.
11 
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14 
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
17 
18 #pragma once
19 
20 #include "Common.h"
21 
22 struct LSInstructionInfo
23 {
24 	int operandSize; //8, 16, 32, 64
25 	int instructionSize;
26 	int regOperandReg;
27 	int otherReg;
28 	int scaledReg;
29 	bool zeroExtend;
30 	bool signExtend;
31 	bool hasImmediate;
32 	bool isMemoryWrite;
33 	u64 immediate;
34 	s32 displacement;
35 };
36 
37 struct ModRM
38 {
39 	int mod, reg, rm;
ModRMModRM40 	ModRM(u8 modRM, u8 rex)
41 	{
42 		mod = modRM >> 6;
43 		reg = ((modRM >> 3) & 7) | ((rex & 4)?8:0);
44 		rm = modRM & 7;
45 	}
46 };
47 
48 enum {
49 	MOVZX_BYTE      = 0xB6, //movzx on byte
50 	MOVZX_SHORT     = 0xB7, //movzx on short
51 	MOVSX_BYTE      = 0xBE, //movsx on byte
52 	MOVSX_SHORT     = 0xBF, //movsx on short
53 	MOVE_8BIT	    = 0xC6, //move 8-bit immediate
54 	MOVE_16_32BIT   = 0xC7, //move 16 or 32-bit immediate
55 	MOVE_REG_TO_MEM = 0x89, //move reg to memory
56 	MOVE_MEM_TO_REG = 0x8B, //move memory to reg
57 };
58 
59 enum AccessType {
60 	OP_ACCESS_READ = 0,
61 	OP_ACCESS_WRITE = 1
62 };
63 
64 bool X86AnalyzeMOV(const unsigned char *codePtr, LSInstructionInfo &info);
65