1 | /* $Id: DisasmInternal.h 95319 2022-06-21 09:53:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox disassembler - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_DisasmInternal_h
|
---|
19 | #define VBOX_INCLUDED_SRC_DisasmInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/types.h>
|
---|
25 | #include <VBox/dis.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | /** @defgroup grp_dis_int Internals.
|
---|
29 | * @ingroup grp_dis
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @name Index into g_apfnCalcSize and g_apfnFullDisasm.
|
---|
34 | * @{ */
|
---|
35 | enum IDX_Parse
|
---|
36 | {
|
---|
37 | IDX_ParseNop = 0,
|
---|
38 | IDX_ParseModRM,
|
---|
39 | IDX_UseModRM,
|
---|
40 | IDX_ParseImmByte,
|
---|
41 | IDX_ParseImmBRel,
|
---|
42 | IDX_ParseImmUshort,
|
---|
43 | IDX_ParseImmV,
|
---|
44 | IDX_ParseImmVRel,
|
---|
45 | IDX_ParseImmAddr,
|
---|
46 | IDX_ParseFixedReg,
|
---|
47 | IDX_ParseImmUlong,
|
---|
48 | IDX_ParseImmQword,
|
---|
49 | IDX_ParseTwoByteEsc,
|
---|
50 | IDX_ParseGrp1,
|
---|
51 | IDX_ParseShiftGrp2,
|
---|
52 | IDX_ParseGrp3,
|
---|
53 | IDX_ParseGrp4,
|
---|
54 | IDX_ParseGrp5,
|
---|
55 | IDX_Parse3DNow,
|
---|
56 | IDX_ParseGrp6,
|
---|
57 | IDX_ParseGrp7,
|
---|
58 | IDX_ParseGrp8,
|
---|
59 | IDX_ParseGrp9,
|
---|
60 | IDX_ParseGrp10,
|
---|
61 | IDX_ParseGrp12,
|
---|
62 | IDX_ParseGrp13,
|
---|
63 | IDX_ParseGrp14,
|
---|
64 | IDX_ParseGrp15,
|
---|
65 | IDX_ParseGrp16,
|
---|
66 | IDX_ParseGrp17,
|
---|
67 | IDX_ParseModFence,
|
---|
68 | IDX_ParseYv,
|
---|
69 | IDX_ParseYb,
|
---|
70 | IDX_ParseXv,
|
---|
71 | IDX_ParseXb,
|
---|
72 | IDX_ParseEscFP,
|
---|
73 | IDX_ParseNopPause,
|
---|
74 | IDX_ParseImmByteSX,
|
---|
75 | IDX_ParseImmZ,
|
---|
76 | IDX_ParseThreeByteEsc4,
|
---|
77 | IDX_ParseThreeByteEsc5,
|
---|
78 | IDX_ParseImmAddrF,
|
---|
79 | IDX_ParseInvOpModRM,
|
---|
80 | IDX_ParseVex2b,
|
---|
81 | IDX_ParseVex3b,
|
---|
82 | IDX_ParseVexDest,
|
---|
83 | IDX_ParseMax
|
---|
84 | };
|
---|
85 | AssertCompile(IDX_ParseMax < 64 /* Packed DISOPCODE assumption. */);
|
---|
86 | /** @} */
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Opcode map descriptor.
|
---|
90 | *
|
---|
91 | * This is used a number of places to save storage space where there are lots of
|
---|
92 | * invalid instructions and the beginning or end of the map.
|
---|
93 | */
|
---|
94 | typedef struct DISOPMAPDESC
|
---|
95 | {
|
---|
96 | /** Pointer to the opcodes described by this structure. */
|
---|
97 | PCDISOPCODE papOpcodes;
|
---|
98 | #if ARCH_BITS <= 32
|
---|
99 | uint16_t
|
---|
100 | #else
|
---|
101 | uint32_t
|
---|
102 | #endif
|
---|
103 | /** The map index corresponding to the first papOpcodes entry. */
|
---|
104 | idxFirst,
|
---|
105 | /** Number of opcodes in the map. */
|
---|
106 | cOpcodes;
|
---|
107 | } DISOPMAPDESC;
|
---|
108 | /** Pointer to a const opcode map descriptor. */
|
---|
109 | typedef DISOPMAPDESC const *PCDISOPMAPDESC;
|
---|
110 |
|
---|
111 | /** @name Opcode maps.
|
---|
112 | * @{ */
|
---|
113 | extern const DISOPCODE g_InvalidOpcode[1];
|
---|
114 |
|
---|
115 | extern const DISOPCODE g_aOneByteMapX86[256];
|
---|
116 | extern const DISOPCODE g_aOneByteMapX64[256];
|
---|
117 | extern const DISOPCODE g_aTwoByteMapX86[256];
|
---|
118 |
|
---|
119 | /** Two byte opcode map with prefix 0x66 */
|
---|
120 | extern const DISOPCODE g_aTwoByteMapX86_PF66[256];
|
---|
121 |
|
---|
122 | /** Two byte opcode map with prefix 0xF2 */
|
---|
123 | extern const DISOPCODE g_aTwoByteMapX86_PFF2[256];
|
---|
124 |
|
---|
125 | /** Two byte opcode map with prefix 0xF3 */
|
---|
126 | extern const DISOPCODE g_aTwoByteMapX86_PFF3[256];
|
---|
127 |
|
---|
128 | /** Three byte opcode map (0xF 0x38) */
|
---|
129 | extern PCDISOPCODE const g_apThreeByteMapX86_0F38[16];
|
---|
130 |
|
---|
131 | /** Three byte opcode map with prefix 0x66 (0xF 0x38) */
|
---|
132 | extern PCDISOPCODE const g_apThreeByteMapX86_660F38[16];
|
---|
133 |
|
---|
134 | /** Three byte opcode map with prefix 0xF2 (0xF 0x38) */
|
---|
135 | extern PCDISOPCODE const g_apThreeByteMapX86_F20F38[16];
|
---|
136 |
|
---|
137 | /** Three byte opcode map with prefix 0xF3 (0xF 0x38) */
|
---|
138 | extern PCDISOPCODE const g_apThreeByteMapX86_F30F38[16];
|
---|
139 |
|
---|
140 | extern PCDISOPCODE const g_apThreeByteMapX86_0F3A[16];
|
---|
141 |
|
---|
142 | /** Three byte opcode map with prefix 0x66 (0xF 0x3A) */
|
---|
143 | extern PCDISOPCODE const g_apThreeByteMapX86_660F3A[16];
|
---|
144 |
|
---|
145 | /** Three byte opcode map with prefixes 0x66 0xF2 (0xF 0x38) */
|
---|
146 | extern PCDISOPCODE const g_apThreeByteMapX86_66F20F38[16];
|
---|
147 |
|
---|
148 | /** VEX opcodes table defined by [VEX.m-mmmm - 1].
|
---|
149 | * 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 00b */
|
---|
150 | extern PCDISOPMAPDESC const g_apVexOpcodesMapRanges_None[3];
|
---|
151 |
|
---|
152 | /** VEX opcodes table defined by [VEX.m-mmmm - 1].
|
---|
153 | * 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 01b (66h) */
|
---|
154 | extern PCDISOPMAPDESC const g_apVexOpcodesMapRanges_66H[3];
|
---|
155 |
|
---|
156 | /** 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 10b (F3h) */
|
---|
157 | extern PCDISOPMAPDESC const g_apVexOpcodesMapRanges_F3H[3];
|
---|
158 |
|
---|
159 | /** 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 11b (F2h) */
|
---|
160 | extern PCDISOPMAPDESC const g_apVexOpcodesMapRanges_F2H[3];
|
---|
161 |
|
---|
162 | /** Two dimmentional map descriptor array: first index is by VEX.pp (prefix),
|
---|
163 | * second by the VEX.mmmm (map).
|
---|
164 | * The latter has to be bounced checked as we only have the first 4 maps. */
|
---|
165 | extern PCDISOPMAPDESC const g_aapVexOpcodesMapRanges[4][4];
|
---|
166 | /** @} */
|
---|
167 |
|
---|
168 | /** @name Opcode extensions (Group tables)
|
---|
169 | * @{ */
|
---|
170 | extern const DISOPCODE g_aMapX86_Group1[8*4];
|
---|
171 | extern const DISOPCODE g_aMapX86_Group2[8*6];
|
---|
172 | extern const DISOPCODE g_aMapX86_Group3[8*2];
|
---|
173 | extern const DISOPCODE g_aMapX86_Group4[8];
|
---|
174 | extern const DISOPCODE g_aMapX86_Group5[8];
|
---|
175 | extern const DISOPCODE g_aMapX86_Group6[8];
|
---|
176 | extern const DISOPCODE g_aMapX86_Group7_mem[8];
|
---|
177 | extern const DISOPCODE g_aMapX86_Group7_mod11_rm000[8];
|
---|
178 | extern const DISOPCODE g_aMapX86_Group7_mod11_rm001[8];
|
---|
179 | extern const DISOPCODE g_aMapX86_Group8[8];
|
---|
180 | extern const DISOPCODE g_aMapX86_Group9[8];
|
---|
181 | extern const DISOPCODE g_aMapX86_Group10[8];
|
---|
182 | extern const DISOPCODE g_aMapX86_Group11[8*2];
|
---|
183 | extern const DISOPCODE g_aMapX86_Group12[8*2];
|
---|
184 | extern const DISOPCODE g_aMapX86_Group13[8*2];
|
---|
185 | extern const DISOPCODE g_aMapX86_Group14[8*2];
|
---|
186 | extern const DISOPCODE g_aMapX86_Group15_mem[8];
|
---|
187 | extern const DISOPCODE g_aMapX86_Group15_mod11_rm000[8];
|
---|
188 | extern const DISOPCODE g_aMapX86_Group16[8];
|
---|
189 | extern const DISOPCODE g_aMapX86_Group17[8*2];
|
---|
190 | extern const DISOPCODE g_aMapX86_NopPause[2];
|
---|
191 | /** @} */
|
---|
192 |
|
---|
193 | /** 3DNow! map (0x0F 0x0F prefix) */
|
---|
194 | extern const DISOPCODE g_aTwoByteMapX86_3DNow[256];
|
---|
195 |
|
---|
196 | /** Floating point opcodes starting with escape byte 0xDF
|
---|
197 | * @{ */
|
---|
198 | extern const DISOPCODE g_aMapX86_EscF0_Low[8];
|
---|
199 | extern const DISOPCODE g_aMapX86_EscF0_High[16*4];
|
---|
200 | extern const DISOPCODE g_aMapX86_EscF1_Low[8];
|
---|
201 | extern const DISOPCODE g_aMapX86_EscF1_High[16*4];
|
---|
202 | extern const DISOPCODE g_aMapX86_EscF2_Low[8];
|
---|
203 | extern const DISOPCODE g_aMapX86_EscF2_High[16*4];
|
---|
204 | extern const DISOPCODE g_aMapX86_EscF3_Low[8];
|
---|
205 | extern const DISOPCODE g_aMapX86_EscF3_High[16*4];
|
---|
206 | extern const DISOPCODE g_aMapX86_EscF4_Low[8];
|
---|
207 | extern const DISOPCODE g_aMapX86_EscF4_High[16*4];
|
---|
208 | extern const DISOPCODE g_aMapX86_EscF5_Low[8];
|
---|
209 | extern const DISOPCODE g_aMapX86_EscF5_High[16*4];
|
---|
210 | extern const DISOPCODE g_aMapX86_EscF6_Low[8];
|
---|
211 | extern const DISOPCODE g_aMapX86_EscF6_High[16*4];
|
---|
212 | extern const DISOPCODE g_aMapX86_EscF7_Low[8];
|
---|
213 | extern const DISOPCODE g_aMapX86_EscF7_High[16*4];
|
---|
214 |
|
---|
215 | extern const PCDISOPCODE g_apMapX86_FP_Low[8];
|
---|
216 | extern const PCDISOPCODE g_apMapX86_FP_High[8];
|
---|
217 | /** @} */
|
---|
218 |
|
---|
219 | /** @def OP
|
---|
220 | * Wrapper which initializes an DISOPCODE.
|
---|
221 | * We must use this so that we can exclude unused fields in order
|
---|
222 | * to save precious bytes in the GC version.
|
---|
223 | *
|
---|
224 | * @internal
|
---|
225 | */
|
---|
226 | #if DISOPCODE_FORMAT == 0
|
---|
227 | # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
|
---|
228 | { pszOpcode, idxParse1, idxParse2, idxParse3, 0, opcode, param1, param2, param3, 0, 0, optype }
|
---|
229 | # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
|
---|
230 | { pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, 0, optype | DISOPTYPE_SSE }
|
---|
231 |
|
---|
232 | #elif DISOPCODE_FORMAT == 16
|
---|
233 | # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
|
---|
234 | { optype, opcode, idxParse1, idxParse2, param1, param2, idxParse3, param3, 0, 0 }
|
---|
235 | # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
|
---|
236 | { optype | DISOPTYPE_SSE, opcode, idxParse1, idxParse2, param1, param2, idxParse3, param3, param4, idxParse4 }
|
---|
237 |
|
---|
238 | #elif DISOPCODE_FORMAT == 15
|
---|
239 | # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
|
---|
240 | { opcode, idxParse1, idxParse2, idxParse3, param1, param2, param3, optype, 0, 0 }
|
---|
241 | # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
|
---|
242 | { opcode, idxParse1, idxParse2, idxParse3, param1, param2, param3, optype | DISOPTYPE_SSE, param4, idxParse4 }
|
---|
243 | #else
|
---|
244 | # error Unsupported DISOPCODE_FORMAT value
|
---|
245 | #endif
|
---|
246 |
|
---|
247 |
|
---|
248 | size_t disFormatBytes(PCDISSTATE pDis, char *pszDst, size_t cchDst, uint32_t fFlags);
|
---|
249 |
|
---|
250 | /** @} */
|
---|
251 | #endif /* !VBOX_INCLUDED_SRC_DisasmInternal_h */
|
---|
252 |
|
---|