VirtualBox

source: vbox/trunk/src/VBox/Disassembler/DisasmInternal-armv8.h@ 99425

Last change on this file since 99425 was 99334, checked in by vboxsync, 21 months ago

Diassembler: Updates to the ARMv8 disassembler, bugref:10394

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/* $Id: DisasmInternal-armv8.h 99334 2023-04-07 10:10:07Z vboxsync $ */
2/** @file
3 * VBox disassembler - Internal header.
4 */
5
6/*
7 * Copyright (C) 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_armv8_h
29#define VBOX_INCLUDED_SRC_DisasmInternal_armv8_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_apfnFullDisasm.
49 * @{ */
50typedef enum DISPARMPARSEIDX
51{
52 kDisParmParseNop = 0,
53 kDisParmParseImm,
54 kDisParmParseImmRel,
55 kDisParmParseImmAdr,
56 kDisParmParseReg,
57 kDisParmParseImmsImmrN,
58 kDisParmParseHw,
59 kDisParmParseCond,
60 kDisParmParsePState,
61 kDisParmParseMax
62} DISPARMPARSEIDX;
63/** @} */
64
65
66/**
67 * Opcode structure.
68 */
69typedef struct DISARMV8OPCODE
70{
71 /** The mask defining the static bits of the opcode. */
72 uint32_t fMask;
73 /** The value of masked bits of the isntruction. */
74 uint32_t fValue;
75 /** The generic opcode structure. */
76 DISOPCODE Opc;
77} DISARMV8OPCODE;
78/** Pointer to a const opcode. */
79typedef const DISARMV8OPCODE *PCDISARMV8OPCODE;
80
81
82typedef struct DISARMV8INSNPARAM
83{
84 /** The parser to use for the parameter. */
85 DISPARMPARSEIDX idxParse;
86 /** Bit index at which the field starts. */
87 uint8_t idxBitStart;
88 /** Size of the bit field. */
89 uint8_t cBits;
90} DISARMV8INSNPARAM;
91typedef DISARMV8INSNPARAM *PDISARMV8INSNPARAM;
92typedef const DISARMV8INSNPARAM *PCDISARMV8INSNPARAM;
93
94#define DIS_ARMV8_INSN_PARAM_NONE { kDisParmParseNop, 0, 0 }
95#define DIS_ARMV8_INSN_PARAM_CREATE(a_idxParse, a_idxBitStart, a_cBits) \
96 { a_idxParse, a_idxBitStart, a_cBits }
97
98
99/**
100 * Opcode decode index.
101 */
102typedef enum DISARMV8OPCDECODE
103{
104 kDisArmV8OpcDecodeNop = 0,
105 kDisArmV8OpcDecodeLookup,
106 kDisArmV8OpcDecodeMax
107} DISARMV8OPCDECODE;
108
109
110/**
111 * Decoder stage type.
112 */
113typedef enum kDisArmV8DecodeType
114{
115 kDisArmV8DecodeType_Invalid = 0,
116 kDisArmV8DecodeType_Map,
117 kDisArmV8DecodeType_Table,
118 kDisArmV8DecodeType_InsnClass,
119 kDisArmV8DecodeType_32Bit_Hack = 0x7fffffff
120} kDisArmV8DecodeType;
121
122
123/**
124 * Decode header.
125 */
126typedef struct DISARMV8DECODEHDR
127{
128 /** Next stage decoding type. */
129 kDisArmV8DecodeType enmDecodeType;
130 /** Number of entries in the next decoder stage or
131 * opcodes in the instruction class. */
132 uint32_t cDecode;
133} DISARMV8DECODEHDR;
134/** Pointer to a decode header. */
135typedef DISARMV8DECODEHDR *PDISARMV8DECODEHDR;
136/** Pointer to a const decode header. */
137typedef const DISARMV8DECODEHDR *PCDISARMV8DECODEHDR;
138typedef const PCDISARMV8DECODEHDR *PPCDISARMV8DECODEHDR;
139
140
141/**
142 * Instruction class descriptor.
143 */
144typedef struct DISARMV8INSNCLASS
145{
146 /** Decoder header. */
147 DISARMV8DECODEHDR Hdr;
148 /** Pointer to the arry of opcodes. */
149 PCDISARMV8OPCODE paOpcodes;
150 /** Some flags for this instruction class. */
151 uint32_t fClass;
152 /** Opcode decoder function. */
153 DISARMV8OPCDECODE enmOpcDecode;
154 /** The mask of the bits relevant for decoding. */
155 uint32_t fMask;
156 /** Number of bits to shift to get an index. */
157 uint32_t cShift;
158 /** The parameters. */
159 DISARMV8INSNPARAM aParms[4];
160} DISARMV8INSNCLASS;
161/** Pointer to a constant instruction class descriptor. */
162typedef const DISARMV8INSNCLASS *PCDISARMV8INSNCLASS;
163
164/** The instruction class distinguishes between a 32-bit and 64-bit variant using the sf bit (bit 31). */
165#define DISARMV8INSNCLASS_F_SF RT_BIT_32(0)
166/** The N bit in an N:ImmR:ImmS bit vector must be 1 for 64-bit instruction variants. */
167#define DISARMV8INSNCLASS_F_N_FORCED_1_ON_64BIT RT_BIT_32(1)
168/** The instruction class is using the 64-bit register encoding only. */
169#define DISARMV8INSNCLASS_F_FORCED_64BIT RT_BIT_32(2)
170
171
172#define DIS_ARMV8_DECODE_INSN_CLASS_DEFINE_BEGIN(a_Name) \
173 static const DISARMV8OPCODE a_Name ## Opcodes[] = {
174#define DIS_ARMV8_DECODE_INSN_CLASS_DEFINE_PARAMS(a_Name, a_fClass, a_enmOpcDecode, a_fMask, a_cShift) \
175 }; \
176 static const DISARMV8INSNCLASS a_Name = { { kDisArmV8DecodeType_InsnClass, RT_ELEMENTS(a_Name ## Opcodes) }, &a_Name ## Opcodes[0],\
177 a_fClass, a_enmOpcDecode, a_fMask, a_cShift, {
178#define DIS_ARMV8_DECODE_INSN_CLASS_DEFINE_END } }
179
180/**
181 * Decoder lookup table entry.
182 */
183typedef struct DISARMV8DECODETBLENTRY
184{
185 /** The mask to apply to the instruction. */
186 uint32_t fMask;
187 /** The value the masked instruction must match for the entry to match. */
188 uint32_t fValue;
189 /** The next stage followed when there is a match. */
190 PCDISARMV8DECODEHDR pHdrNext;
191} DISARMV8DECODETBLENTRY;
192typedef struct DISARMV8DECODETBLENTRY *PDISARMV8DECODETBLENTRY;
193typedef const DISARMV8DECODETBLENTRY *PCDISARMV8DECODETBLENTRY;
194
195
196#define DIS_ARMV8_DECODE_TBL_ENTRY_INIT(a_fMask, a_fValue, a_pNext) \
197 { a_fMask, a_fValue, &a_pNext.Hdr }
198
199
200/**
201 * Decoder lookup table using masks and values.
202 */
203typedef struct DISARMV8DECODETBL
204{
205 /** The header for the decoder lookup table. */
206 DISARMV8DECODEHDR Hdr;
207 /** Pointer to the individual entries. */
208 PCDISARMV8DECODETBLENTRY paEntries;
209} DISARMV8DECODETBL;
210/** Pointer to a const decode table. */
211typedef const struct DISARMV8DECODETBL *PCDISARMV8DECODETBL;
212
213
214#define DIS_ARMV8_DECODE_TBL_DEFINE_BEGIN(a_Name) \
215 static const DISARMV8DECODETBLENTRY a_Name ## TblEnt[] = {
216
217#define DIS_ARMV8_DECODE_TBL_DEFINE_END(a_Name) \
218 }; \
219 static const DISARMV8DECODETBL a_Name = { { kDisArmV8DecodeType_Table, RT_ELEMENTS(a_Name ## TblEnt) }, &a_Name ## TblEnt[0] }
220
221
222/**
223 * Decoder map when direct indexing is possible.
224 */
225typedef struct DISARMV8DECODEMAP
226{
227 /** The header for the decoder map. */
228 DISARMV8DECODEHDR Hdr;
229 /** The bitmask used to decide where to go next. */
230 uint32_t fMask;
231 /** Amount to shift to get at the index. */
232 uint32_t cShift;
233 /** Pointer to the array of pointers to the next stage to index into. */
234 PPCDISARMV8DECODEHDR papNext;
235} DISARMV8DECODEMAP;
236/** Pointer to a const decode map. */
237typedef const struct DISARMV8DECODEMAP *PCDISARMV8DECODEMAP;
238
239#define DIS_ARMV8_DECODE_MAP_DEFINE_BEGIN(a_Name) \
240 static const PCDISARMV8DECODEHDR a_Name ## MapHdrs[] = {
241
242#define DIS_ARMV8_DECODE_MAP_DEFINE_END(a_Name, a_fMask, a_cShift) \
243 }; \
244 static const DISARMV8DECODEMAP a_Name = { { kDisArmV8DecodeType_Map, RT_ELEMENTS(a_Name ## MapHdrs) }, a_fMask, a_cShift, &a_Name ## MapHdrs[0] }
245
246#define DIS_ARMV8_DECODE_MAP_DEFINE_END_NON_STATIC(a_Name, a_fMask, a_cShift) \
247 }; \
248 DECL_HIDDEN_CONST(DISARMV8DECODEMAP) a_Name = { { kDisArmV8DecodeType_Map, RT_ELEMENTS(a_Name ## MapHdrs) }, a_fMask, a_cShift, &a_Name ## MapHdrs[0] }
249
250#define DIS_ARMV8_DECODE_MAP_INVALID_ENTRY NULL
251#define DIS_ARMV8_DECODE_MAP_ENTRY(a_Next) &a_Next.Hdr
252
253
254/** @name Decoder maps.
255 * @{ */
256extern DECL_HIDDEN_DATA(DISOPCODE) g_ArmV8A64InvalidOpcode[1];
257
258extern DECL_HIDDEN_DATA(DISARMV8DECODEMAP) g_ArmV8A64DecodeL0;
259/** @} */
260
261
262/** @} */
263#endif /* !VBOX_INCLUDED_SRC_DisasmInternal_armv8_h */
264
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette