source: Daodan/src/beaengine/BeaEngine.h@ 1191

Last change on this file since 1191 was 984, checked in by alloc, 11 years ago

Daodan: TV code

File size: 7.0 KB
Line 
1#ifndef _BEA_ENGINE_
2#define _BEA_ENGINE_
3#if defined(__cplusplus) && defined(__BORLANDC__)
4namespace BeaEngine {
5#endif
6
7#include <beaengine/macros.h>
8#include <beaengine/export.h>
9#include <beaengine/basic_types.h>
10
11#if !defined(BEA_ENGINE_STATIC)
12 #if defined(BUILD_BEA_ENGINE_DLL)
13 #define BEA_API bea__api_export__
14 #else
15 #define BEA_API bea__api_import__
16 #endif
17#else
18 #define BEA_API
19#endif
20
21
22#define INSTRUCT_LENGTH 64
23
24#pragma pack(1)
25typedef struct {
26 UInt8 W_;
27 UInt8 R_;
28 UInt8 X_;
29 UInt8 B_;
30 UInt8 state;
31} REX_Struct ;
32#pragma pack()
33
34#pragma pack(1)
35typedef struct {
36 int Number;
37 int NbUndefined;
38 UInt8 LockPrefix;
39 UInt8 OperandSize;
40 UInt8 AddressSize;
41 UInt8 RepnePrefix;
42 UInt8 RepPrefix;
43 UInt8 FSPrefix;
44 UInt8 SSPrefix;
45 UInt8 GSPrefix;
46 UInt8 ESPrefix;
47 UInt8 CSPrefix;
48 UInt8 DSPrefix;
49 UInt8 BranchTaken;
50 UInt8 BranchNotTaken;
51 REX_Struct REX;
52 char alignment[2];
53} PREFIXINFO ;
54#pragma pack()
55
56#pragma pack(1)
57typedef struct {
58 UInt8 OF_;
59 UInt8 SF_;
60 UInt8 ZF_;
61 UInt8 AF_;
62 UInt8 PF_;
63 UInt8 CF_;
64 UInt8 TF_;
65 UInt8 IF_;
66 UInt8 DF_;
67 UInt8 NT_;
68 UInt8 RF_;
69 UInt8 alignment;
70} EFLStruct ;
71#pragma pack()
72
73#pragma pack(4)
74typedef struct {
75 Int32 BaseRegister;
76 Int32 IndexRegister;
77 Int32 Scale;
78 Int64 Displacement;
79} MEMORYTYPE ;
80#pragma pack()
81
82
83#pragma pack(1)
84typedef struct {
85 Int32 Category;
86 Int32 Opcode;
87 char Mnemonic[16];
88 Int32 BranchType;
89 EFLStruct Flags;
90 UInt64 AddrValue;
91 Int64 Immediat;
92 UInt32 ImplicitModifiedRegs;
93} INSTRTYPE;
94#pragma pack()
95
96#pragma pack(1)
97typedef struct {
98 char ArgMnemonic[64];
99 Int32 ArgType;
100 Int32 ArgSize;
101 Int32 ArgPosition;
102 UInt32 AccessMode;
103 MEMORYTYPE Memory;
104 UInt32 SegmentReg;
105} ARGTYPE;
106#pragma pack()
107
108/* reserved structure used for thread-safety */
109/* unusable by customer */
110#pragma pack(1)
111typedef struct {
112 UIntPtr EIP_;
113 UInt64 EIP_VA;
114 UIntPtr EIP_REAL;
115 Int32 OriginalOperandSize;
116 Int32 OperandSize;
117 Int32 MemDecoration;
118 Int32 AddressSize;
119 Int32 MOD_;
120 Int32 RM_;
121 Int32 INDEX_;
122 Int32 SCALE_;
123 Int32 BASE_;
124 Int32 MMX_;
125 Int32 SSE_;
126 Int32 CR_;
127 Int32 DR_;
128 Int32 SEG_;
129 Int32 REGOPCODE;
130 UInt32 DECALAGE_EIP;
131 Int32 FORMATNUMBER;
132 Int32 SYNTAX_;
133 UInt64 EndOfBlock;
134 Int32 RelativeAddress;
135 UInt32 Architecture;
136 Int32 ImmediatSize;
137 Int32 NB_PREFIX;
138 Int32 PrefRepe;
139 Int32 PrefRepne;
140 UInt32 SEGMENTREGS;
141 UInt32 SEGMENTFS;
142 Int32 third_arg;
143 Int32 TAB_;
144 Int32 ERROR_OPCODE;
145 REX_Struct REX;
146 Int32 OutOfBlock;
147} InternalDatas;
148#pragma pack()
149
150/* ************** main structure ************ */
151#pragma pack(1)
152typedef struct _Disasm {
153 UIntPtr EIP;
154 UInt64 VirtualAddr;
155 UInt32 SecurityBlock;
156 char CompleteInstr[INSTRUCT_LENGTH];
157 UInt32 Archi;
158 UInt64 Options;
159 INSTRTYPE Instruction;
160 ARGTYPE Argument1;
161 ARGTYPE Argument2;
162 ARGTYPE Argument3;
163 PREFIXINFO Prefix;
164 InternalDatas Reserved_;
165} DISASM, *PDISASM, *LPDISASM;
166#pragma pack()
167
168#define ESReg 1
169#define DSReg 2
170#define FSReg 3
171#define GSReg 4
172#define CSReg 5
173#define SSReg 6
174
175#define InvalidPrefix 4
176#define SuperfluousPrefix 2
177#define NotUsedPrefix 0
178#define MandatoryPrefix 8
179#define InUsePrefix 1
180
181#define LowPosition 0
182#define HighPosition 1
183
184enum INSTRUCTION_TYPE
185{
186 GENERAL_PURPOSE_INSTRUCTION = 0x10000,
187 FPU_INSTRUCTION = 0x20000,
188 MMX_INSTRUCTION = 0x40000,
189 SSE_INSTRUCTION = 0x80000,
190 SSE2_INSTRUCTION = 0x100000,
191 SSE3_INSTRUCTION = 0x200000,
192 SSSE3_INSTRUCTION = 0x400000,
193 SSE41_INSTRUCTION = 0x800000,
194 SSE42_INSTRUCTION = 0x1000000,
195 SYSTEM_INSTRUCTION = 0x2000000,
196 VM_INSTRUCTION = 0x4000000,
197 UNDOCUMENTED_INSTRUCTION = 0x8000000,
198 AMD_INSTRUCTION = 0x10000000,
199 ILLEGAL_INSTRUCTION = 0x20000000,
200 AES_INSTRUCTION = 0x40000000,
201 CLMUL_INSTRUCTION = (int)0x80000000,
202
203
204 DATA_TRANSFER = 0x1,
205 ARITHMETIC_INSTRUCTION,
206 LOGICAL_INSTRUCTION,
207 SHIFT_ROTATE,
208 BIT_UInt8,
209 CONTROL_TRANSFER,
210 STRING_INSTRUCTION,
211 InOutINSTRUCTION,
212 ENTER_LEAVE_INSTRUCTION,
213 FLAG_CONTROL_INSTRUCTION,
214 SEGMENT_REGISTER,
215 MISCELLANEOUS_INSTRUCTION,
216 COMPARISON_INSTRUCTION,
217 LOGARITHMIC_INSTRUCTION,
218 TRIGONOMETRIC_INSTRUCTION,
219 UNSUPPORTED_INSTRUCTION,
220 LOAD_CONSTANTS,
221 FPUCONTROL,
222 STATE_MANAGEMENT,
223 CONVERSION_INSTRUCTION,
224 SHUFFLE_UNPACK,
225 PACKED_SINGLE_PRECISION,
226 SIMD128bits,
227 SIMD64bits,
228 CACHEABILITY_CONTROL,
229 FP_INTEGER_CONVERSION,
230 SPECIALIZED_128bits,
231 SIMD_FP_PACKED,
232 SIMD_FP_HORIZONTAL ,
233 AGENT_SYNCHRONISATION,
234 PACKED_ALIGN_RIGHT ,
235 PACKED_SIGN,
236 PACKED_BLENDING_INSTRUCTION,
237 PACKED_TEST,
238 PACKED_MINMAX,
239 HORIZONTAL_SEARCH,
240 PACKED_EQUALITY,
241 STREAMING_LOAD,
242 INSERTION_EXTRACTION,
243 DOT_PRODUCT,
244 SAD_INSTRUCTION,
245 ACCELERATOR_INSTRUCTION, /* crc32, popcnt (sse4.2) */
246 ROUND_INSTRUCTION
247
248};
249
250enum EFLAGS_STATES
251{
252 TE_ = 1,
253 MO_ = 2,
254 RE_ = 4,
255 SE_ = 8,
256 UN_ = 0x10,
257 PR_ = 0x20
258};
259
260enum BRANCH_TYPE
261{
262 JO = 1,
263 JC = 2,
264 JE = 3,
265 JA = 4,
266 JS = 5,
267 JP = 6,
268 JL = 7,
269 JG = 8,
270 JB = 2, // JC == JB
271 JECXZ = 10,
272 JmpType = 11,
273 CallType = 12,
274 RetType = 13,
275 JNO = -1,
276 JNC = -2,
277 JNE = -3,
278 JNA = -4,
279 JNS = -5,
280 JNP = -6,
281 JNL = -7,
282 JNG = -8,
283 JNB = -2 // JNC == JNB
284};
285
286enum ARGUMENTS_TYPE
287{
288 NO_ARGUMENT = 0x10000000,
289 REGISTER_TYPE = 0x20000000,
290 MEMORY_TYPE = 0x40000000,
291 CONSTANT_TYPE = (int)0x80000000,
292
293 MMX_REG = 0x10000,
294 GENERAL_REG = 0x20000,
295 FPU_REG = 0x40000,
296 SSE_REG = 0x80000,
297 CR_REG = 0x100000,
298 DR_REG = 0x200000,
299 SPECIAL_REG = 0x400000,
300 MEMORY_MANAGEMENT_REG = 0x800000,
301 SEGMENT_REG = 0x1000000,
302
303 RELATIVE_ = 0x4000000,
304 ABSOLUTE_ = 0x8000000,
305
306 READ = 0x1,
307 WRITE = 0x2,
308
309 REG0 = 0x1,
310 REG1 = 0x2,
311 REG2 = 0x4,
312 REG3 = 0x8,
313 REG4 = 0x10,
314 REG5 = 0x20,
315 REG6 = 0x40,
316 REG7 = 0x80,
317 REG8 = 0x100,
318 REG9 = 0x200,
319 REG10 = 0x400,
320 REG11 = 0x800,
321 REG12 = 0x1000,
322 REG13 = 0x2000,
323 REG14 = 0x4000,
324 REG15 = 0x8000
325};
326
327enum SPECIAL_INFO
328{
329 UNKNOWN_OPCODE = -1,
330 OUT_OF_BLOCK = 0,
331
332 /* === mask = 0xff */
333 NoTabulation = 0x00000000,
334 Tabulation = 0x00000001,
335
336 /* === mask = 0xff00 */
337 MasmSyntax = 0x00000000,
338 GoAsmSyntax = 0x00000100,
339 NasmSyntax = 0x00000200,
340 ATSyntax = 0x00000400,
341
342 /* === mask = 0xff0000 */
343 PrefixedNumeral = 0x00010000,
344 SuffixedNumeral = 0x00000000,
345
346 /* === mask = 0xff000000 */
347 ShowSegmentRegs = 0x01000000
348};
349
350
351#ifdef __cplusplus
352extern "C"
353#endif
354
355BEA_API int __bea_callspec__ Disasm (LPDISASM pDisAsm);
356BEA_API const__ char* __bea_callspec__ BeaEngineVersion (void);
357BEA_API const__ char* __bea_callspec__ BeaEngineRevision (void);
358#if defined(__cplusplus) && defined(__BORLANDC__)
359};
360using namespace BeaEngine;
361#endif
362#endif
Note: See TracBrowser for help on using the repository browser.