1 | /* $Id: DisasmInternal.h 93115 2022-01-01 11:31:46Z 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_ParseModFence,
|
---|
67 | IDX_ParseYv,
|
---|
68 | IDX_ParseYb,
|
---|
69 | IDX_ParseXv,
|
---|
70 | IDX_ParseXb,
|
---|
71 | IDX_ParseEscFP,
|
---|
72 | IDX_ParseNopPause,
|
---|
73 | IDX_ParseImmByteSX,
|
---|
74 | IDX_ParseImmZ,
|
---|
75 | IDX_ParseThreeByteEsc4,
|
---|
76 | IDX_ParseThreeByteEsc5,
|
---|
77 | IDX_ParseImmAddrF,
|
---|
78 | IDX_ParseInvOpModRM,
|
---|
79 | IDX_ParseVex2b,
|
---|
80 | IDX_ParseVex3b,
|
---|
81 | IDX_ParseVexDest,
|
---|
82 | IDX_ParseMax
|
---|
83 | };
|
---|
84 | AssertCompile(IDX_ParseMax < 64 /* Packed DISOPCODE assumption. */);
|
---|
85 | /** @} */
|
---|
86 |
|
---|
87 |
|
---|
88 | /** @name Opcode maps.
|
---|
89 | * @{ */
|
---|
90 | extern const DISOPCODE g_InvalidOpcode[1];
|
---|
91 |
|
---|
92 | extern const DISOPCODE g_aOneByteMapX86[256];
|
---|
93 | extern const DISOPCODE g_aOneByteMapX64[256];
|
---|
94 | extern const DISOPCODE g_aTwoByteMapX86[256];
|
---|
95 |
|
---|
96 | /** Two byte opcode map with prefix 0x66 */
|
---|
97 | extern const DISOPCODE g_aTwoByteMapX86_PF66[256];
|
---|
98 |
|
---|
99 | /** Two byte opcode map with prefix 0xF2 */
|
---|
100 | extern const DISOPCODE g_aTwoByteMapX86_PFF2[256];
|
---|
101 |
|
---|
102 | /** Two byte opcode map with prefix 0xF3 */
|
---|
103 | extern const DISOPCODE g_aTwoByteMapX86_PFF3[256];
|
---|
104 |
|
---|
105 | /** Three byte opcode map (0xF 0x38) */
|
---|
106 | extern PCDISOPCODE const g_apThreeByteMapX86_0F38[16];
|
---|
107 |
|
---|
108 | /** Three byte opcode map with prefix 0x66 (0xF 0x38) */
|
---|
109 | extern PCDISOPCODE const g_apThreeByteMapX86_660F38[16];
|
---|
110 |
|
---|
111 | /** Three byte opcode map with prefix 0xF2 (0xF 0x38) */
|
---|
112 | extern PCDISOPCODE const g_apThreeByteMapX86_F20F38[16];
|
---|
113 |
|
---|
114 | /** Three byte opcode map with prefix 0xF3 (0xF 0x38) */
|
---|
115 | extern PCDISOPCODE const g_apThreeByteMapX86_F30F38[16];
|
---|
116 |
|
---|
117 | extern PCDISOPCODE const g_apThreeByteMapX86_0F3A[16];
|
---|
118 |
|
---|
119 | /** Three byte opcode map with prefix 0x66 (0xF 0x3A) */
|
---|
120 | extern PCDISOPCODE const g_apThreeByteMapX86_660F3A[16];
|
---|
121 |
|
---|
122 | /** Three byte opcode map with prefixes 0x66 0xF2 (0xF 0x38) */
|
---|
123 | extern PCDISOPCODE const g_apThreeByteMapX86_66F20F38[16];
|
---|
124 |
|
---|
125 | /** VEX opcodes table defined by [VEX.m-mmmm - 1].
|
---|
126 | * 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 00b */
|
---|
127 | extern PCDISOPCODE const g_aVexOpcodesMap[3];
|
---|
128 |
|
---|
129 | /** VEX opcodes table defined by [VEX.m-mmmm - 1].
|
---|
130 | * 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 01b (66h) */
|
---|
131 | extern PCDISOPCODE const g_aVexOpcodesMap_66H[3];
|
---|
132 |
|
---|
133 | /** 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 10b (F3h) */
|
---|
134 | extern PCDISOPCODE const g_aVexOpcodesMap_F3H[3];
|
---|
135 |
|
---|
136 | /** 0Fh, 0F38h, 0F3Ah correspondingly, VEX.pp = 11b (F2h) */
|
---|
137 | extern PCDISOPCODE const g_aVexOpcodesMap_F2H[3];
|
---|
138 | /** @} */
|
---|
139 |
|
---|
140 | /** @name Opcode extensions (Group tables)
|
---|
141 | * @{ */
|
---|
142 | extern const DISOPCODE g_aMapX86_Group1[8*4];
|
---|
143 | extern const DISOPCODE g_aMapX86_Group2[8*6];
|
---|
144 | extern const DISOPCODE g_aMapX86_Group3[8*2];
|
---|
145 | extern const DISOPCODE g_aMapX86_Group4[8];
|
---|
146 | extern const DISOPCODE g_aMapX86_Group5[8];
|
---|
147 | extern const DISOPCODE g_aMapX86_Group6[8];
|
---|
148 | extern const DISOPCODE g_aMapX86_Group7_mem[8];
|
---|
149 | extern const DISOPCODE g_aMapX86_Group7_mod11_rm000[8];
|
---|
150 | extern const DISOPCODE g_aMapX86_Group7_mod11_rm001[8];
|
---|
151 | extern const DISOPCODE g_aMapX86_Group8[8];
|
---|
152 | extern const DISOPCODE g_aMapX86_Group9[8];
|
---|
153 | extern const DISOPCODE g_aMapX86_Group10[8];
|
---|
154 | extern const DISOPCODE g_aMapX86_Group11[8*2];
|
---|
155 | extern const DISOPCODE g_aMapX86_Group12[8*2];
|
---|
156 | extern const DISOPCODE g_aMapX86_Group13[8*2];
|
---|
157 | extern const DISOPCODE g_aMapX86_Group14[8*2];
|
---|
158 | extern const DISOPCODE g_aMapX86_Group15_mem[8];
|
---|
159 | extern const DISOPCODE g_aMapX86_Group15_mod11_rm000[8];
|
---|
160 | extern const DISOPCODE g_aMapX86_Group16[8];
|
---|
161 | extern const DISOPCODE g_aMapX86_NopPause[2];
|
---|
162 | /** @} */
|
---|
163 |
|
---|
164 | /** 3DNow! map (0x0F 0x0F prefix) */
|
---|
165 | extern const DISOPCODE g_aTwoByteMapX86_3DNow[256];
|
---|
166 |
|
---|
167 | /** Floating point opcodes starting with escape byte 0xDF
|
---|
168 | * @{ */
|
---|
169 | extern const DISOPCODE g_aMapX86_EscF0_Low[8];
|
---|
170 | extern const DISOPCODE g_aMapX86_EscF0_High[16*4];
|
---|
171 | extern const DISOPCODE g_aMapX86_EscF1_Low[8];
|
---|
172 | extern const DISOPCODE g_aMapX86_EscF1_High[16*4];
|
---|
173 | extern const DISOPCODE g_aMapX86_EscF2_Low[8];
|
---|
174 | extern const DISOPCODE g_aMapX86_EscF2_High[16*4];
|
---|
175 | extern const DISOPCODE g_aMapX86_EscF3_Low[8];
|
---|
176 | extern const DISOPCODE g_aMapX86_EscF3_High[16*4];
|
---|
177 | extern const DISOPCODE g_aMapX86_EscF4_Low[8];
|
---|
178 | extern const DISOPCODE g_aMapX86_EscF4_High[16*4];
|
---|
179 | extern const DISOPCODE g_aMapX86_EscF5_Low[8];
|
---|
180 | extern const DISOPCODE g_aMapX86_EscF5_High[16*4];
|
---|
181 | extern const DISOPCODE g_aMapX86_EscF6_Low[8];
|
---|
182 | extern const DISOPCODE g_aMapX86_EscF6_High[16*4];
|
---|
183 | extern const DISOPCODE g_aMapX86_EscF7_Low[8];
|
---|
184 | extern const DISOPCODE g_aMapX86_EscF7_High[16*4];
|
---|
185 |
|
---|
186 | extern const PCDISOPCODE g_apMapX86_FP_Low[8];
|
---|
187 | extern const PCDISOPCODE g_apMapX86_FP_High[8];
|
---|
188 | /** @} */
|
---|
189 |
|
---|
190 | /** @def OP
|
---|
191 | * Wrapper which initializes an DISOPCODE.
|
---|
192 | * We must use this so that we can exclude unused fields in order
|
---|
193 | * to save precious bytes in the GC version.
|
---|
194 | *
|
---|
195 | * @internal
|
---|
196 | */
|
---|
197 | #if DISOPCODE_FORMAT == 0
|
---|
198 | # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
|
---|
199 | { pszOpcode, idxParse1, idxParse2, idxParse3, 0, opcode, param1, param2, param3, 0, 0, optype }
|
---|
200 | # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
|
---|
201 | { pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, 0, optype | DISOPTYPE_SSE }
|
---|
202 |
|
---|
203 | #elif DISOPCODE_FORMAT == 16
|
---|
204 | # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
|
---|
205 | { optype, opcode, idxParse1, idxParse2, param1, param2, idxParse3, param3, 0, 0 }
|
---|
206 | # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
|
---|
207 | { optype | DISOPTYPE_SSE, opcode, idxParse1, idxParse2, param1, param2, idxParse3, param3, param4, idxParse4 }
|
---|
208 |
|
---|
209 | #elif DISOPCODE_FORMAT == 15
|
---|
210 | # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
|
---|
211 | { opcode, idxParse1, idxParse2, idxParse3, param1, param2, param3, optype, 0, 0 }
|
---|
212 | # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
|
---|
213 | { opcode, idxParse1, idxParse2, idxParse3, param1, param2, param3, optype | DISOPTYPE_SSE, param4, idxParse4 }
|
---|
214 | #else
|
---|
215 | # error Unsupported DISOPCODE_FORMAT value
|
---|
216 | #endif
|
---|
217 |
|
---|
218 |
|
---|
219 | size_t disFormatBytes(PCDISSTATE pDis, char *pszDst, size_t cchDst, uint32_t fFlags);
|
---|
220 |
|
---|
221 | /** @} */
|
---|
222 | #endif /* !VBOX_INCLUDED_SRC_DisasmInternal_h */
|
---|
223 |
|
---|