OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 #ifndef _DECODER_X86_64_H_ | |
8 #define _DECODER_X86_64_H_ | |
9 | |
10 #include <inttypes.h> | |
11 | |
12 #ifdef __cplusplus | |
13 extern "C" { | |
14 #endif | |
15 | |
16 enum operand_type { | |
17 OperandSize2bit, /* See VPERMIL2Px instruction for description. */ | |
18 OperandSize8bit, | |
19 OperandSize16bit, | |
20 OperandSize32bit, | |
21 OperandSize64bit, | |
22 OperandSize128bit, | |
23 OperandSize256bit, | |
24 OperandFloatSize16bit, /* OperandFloatSize16bit, OperandFloatSize32bit, */ | |
25 OperandFloatSize32bit, /* OperandFloatSize64bit, and OperandFloatSize80bit */ | |
26 OperandFloatSize64bit, /* are used for in-memory operands and XMM: */ | |
27 OperandFloatSize80bit, /* X87 registers always have type OperandST. */ | |
28 OperandX87Size16bit, /* OperandX87Size16bit, OperandX87Size32bit, and */ | |
29 OperandX87Size32bit, /* OperandX87Size64bit are signed integers in memory.*/ | |
30 OperandX87Size64bit, /* They are used for x87 instructions. */ | |
31 OperandX87BCD, /* 10-byte packed BCD value in memory. */ | |
32 OperandX87ENV, /* A 14-byte or 28-byte x87 environment. */ | |
33 OperandX87STATE, /* A 94-byte or 108-byte x87 state. */ | |
34 OperandX87MMXXMMSTATE, /* A 512-byte extended x87/MMX/XMM state. */ | |
35 OperandST, | |
36 OperandSelector, /* Operand is 6bytes/10bytes selector in memory. */ | |
37 OperandFarPtr, /* Operand is 6bytes/10bytes far pointer in memory. */ | |
38 OperandSegmentRegister, /* Operand is segment register: %{e,c,s,d,f,g}s. */ | |
39 OperandControlRegister, /* Operand is control register: %crX. */ | |
40 OperandDebugRegister, /* Operand is debug register: %drX. */ | |
41 OperandMMX, | |
42 OperandXMM, | |
43 OperandYMM | |
44 }; | |
45 | |
46 enum register_name { | |
47 REG_RAX, | |
48 REG_RCX, | |
49 REG_RDX, | |
50 REG_RBX, | |
51 REG_RSP, | |
52 REG_RBP, | |
53 REG_RSI, | |
54 REG_RDI, | |
55 REG_R8, | |
56 REG_R9, | |
57 REG_R10, | |
58 REG_R11, | |
59 REG_R12, | |
60 REG_R13, | |
61 REG_R14, | |
62 REG_R15, | |
63 REG_RM, /* Address in memory via rm field. */ | |
64 REG_RIP, /* RIP - used as base in x86-64 mode. */ | |
65 REG_RIZ, /* EIZ/RIZ - used as "always zero index" register. */ | |
66 REG_IMM, /* Fixed value in imm field. */ | |
67 REG_IMM2, /* Fixed value in second imm field. */ | |
68 REG_DS_RBX, /* Fox xlat: %ds(%rbx). */ | |
69 REG_ES_RDI, /* For string instructions: %es:(%rsi). */ | |
70 REG_DS_RSI, /* For string instructions: %ds:(%rdi). */ | |
71 REG_PORT_DX, /* 16-bit DX: for in/out instructions. */ | |
72 REG_NONE, /* For modrm: both index and base can be absent. */ | |
73 REG_ST, /* For x87 instructions: implicit %st. */ | |
74 JMP_TO /* Operand is jump target address: usually %rip+offset. */ | |
75 }; | |
76 | |
77 struct instruction { | |
78 const char *name; | |
79 unsigned char operands_count; | |
80 struct { | |
81 unsigned char rex; /* Mostly to distingush cases like %ah vs %spl. */ | |
82 _Bool data16:1; /* "Normal", non-rex prefixes. */ | |
83 _Bool lock:1; | |
84 _Bool repnz:1; | |
85 _Bool repz:1; | |
86 _Bool branch_not_taken:1; | |
87 _Bool branch_taken:1; | |
88 } prefix; | |
89 struct { | |
90 enum register_name name; | |
91 enum operand_type type; | |
92 } operands[5]; | |
93 struct { | |
94 enum register_name base; | |
95 enum register_name index; | |
96 int scale; | |
97 uint64_t offset; | |
98 } rm; | |
99 uint64_t imm[2]; | |
100 }; | |
101 | |
102 typedef void (*process_instruction_func) (const uint8_t *begin, | |
103 const uint8_t *end, | |
104 struct instruction *instruction, | |
105 void *userdata); | |
106 | |
107 typedef void (*process_error_func) (const uint8_t *ptr, void *userdata); | |
108 | |
109 int DecodeChunkAMD64(const uint8_t *data, size_t size, | |
110 process_instruction_func process_instruction, | |
111 process_error_func process_error, void *userdata); | |
112 | |
113 int DecodeChunkIA32(const uint8_t *data, size_t size, | |
114 process_instruction_func process_instruction, | |
115 process_error_func process_error, void *userdata); | |
116 | |
117 #ifdef __cplusplus | |
118 } | |
119 #endif | |
120 | |
121 #endif | |
OLD | NEW |