VirtualBox

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

Last change on this file since 100763 was 100046, checked in by vboxsync, 19 months ago

Disassembler: Some updates to the ARMv8 disassembler lying around, bugref:10394

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