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