VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/CPUMDbg-armv8.cpp

Last change on this file was 100118, checked in by vboxsync, 11 months ago

VMM/CPUM: Include VBAR_EL1 register, bugref:10387 bugref:10390

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.2 KB
Line 
1/* $Id: CPUMDbg-armv8.cpp 100118 2023-06-08 12:41:57Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor / Manager, Debugger & Debugging APIs.
4 */
5
6/*
7 * Copyright (C) 2010-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
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DBGF
33#include <VBox/vmm/cpum.h>
34#include <VBox/vmm/dbgf.h>
35#include <VBox/vmm/apic.h>
36#include "CPUMInternal-armv8.h"
37#include <VBox/vmm/vm.h>
38#include <VBox/param.h>
39#include <VBox/err.h>
40#include <VBox/log.h>
41#include <iprt/thread.h>
42#include <iprt/string.h>
43#include <iprt/uint128.h>
44
45
46/**
47 * @interface_method_impl{DBGFREGDESC,pfnGet}
48 */
49static DECLCALLBACK(int) cpumR3RegGet_Generic(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
50{
51 PVMCPU pVCpu = (PVMCPU)pvUser;
52 void const *pv = (uint8_t const *)&pVCpu->cpum + pDesc->offRegister;
53
54 VMCPU_ASSERT_EMT(pVCpu);
55
56 switch (pDesc->enmType)
57 {
58 case DBGFREGVALTYPE_U8: pValue->u8 = *(uint8_t const *)pv; return VINF_SUCCESS;
59 case DBGFREGVALTYPE_U16: pValue->u16 = *(uint16_t const *)pv; return VINF_SUCCESS;
60 case DBGFREGVALTYPE_U32: pValue->u32 = *(uint32_t const *)pv; return VINF_SUCCESS;
61 case DBGFREGVALTYPE_U64: pValue->u64 = *(uint64_t const *)pv; return VINF_SUCCESS;
62 case DBGFREGVALTYPE_U128: pValue->u128 = *(PCRTUINT128U )pv; return VINF_SUCCESS;
63 case DBGFREGVALTYPE_U256: pValue->u256 = *(PCRTUINT256U )pv; return VINF_SUCCESS;
64 case DBGFREGVALTYPE_U512: pValue->u512 = *(PCRTUINT512U )pv; return VINF_SUCCESS;
65 default:
66 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
67 }
68}
69
70
71/**
72 * @interface_method_impl{DBGFREGDESC,pfnSet}
73 */
74static DECLCALLBACK(int) cpumR3RegSet_Generic(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
75{
76 PVMCPU pVCpu = (PVMCPU)pvUser;
77 void *pv = (uint8_t *)&pVCpu->cpum + pDesc->offRegister;
78
79 VMCPU_ASSERT_EMT(pVCpu);
80
81 switch (pDesc->enmType)
82 {
83 case DBGFREGVALTYPE_U8:
84 *(uint8_t *)pv &= ~pfMask->u8;
85 *(uint8_t *)pv |= pValue->u8 & pfMask->u8;
86 return VINF_SUCCESS;
87
88 case DBGFREGVALTYPE_U16:
89 *(uint16_t *)pv &= ~pfMask->u16;
90 *(uint16_t *)pv |= pValue->u16 & pfMask->u16;
91 return VINF_SUCCESS;
92
93 case DBGFREGVALTYPE_U32:
94 *(uint32_t *)pv &= ~pfMask->u32;
95 *(uint32_t *)pv |= pValue->u32 & pfMask->u32;
96 return VINF_SUCCESS;
97
98 case DBGFREGVALTYPE_U64:
99 *(uint64_t *)pv &= ~pfMask->u64;
100 *(uint64_t *)pv |= pValue->u64 & pfMask->u64;
101 return VINF_SUCCESS;
102
103 case DBGFREGVALTYPE_U128:
104 {
105 RTUINT128U Val;
106 RTUInt128AssignAnd((PRTUINT128U)pv, RTUInt128AssignBitwiseNot(RTUInt128Assign(&Val, &pfMask->u128)));
107 RTUInt128AssignOr((PRTUINT128U)pv, RTUInt128AssignAnd(RTUInt128Assign(&Val, &pValue->u128), &pfMask->u128));
108 return VINF_SUCCESS;
109 }
110
111 default:
112 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
113 }
114}
115
116
117/*
118 * Set up aliases.
119 */
120#define CPUMREGALIAS_STD(Name, psz32) \
121 static DBGFREGALIAS const g_aCpumRegAliases_##Name[] = \
122 { \
123 { psz32, DBGFREGVALTYPE_U32 }, \
124 { NULL, DBGFREGVALTYPE_INVALID } \
125 }
126CPUMREGALIAS_STD(x0, "w0");
127CPUMREGALIAS_STD(x1, "w1");
128CPUMREGALIAS_STD(x2, "w2");
129CPUMREGALIAS_STD(x3, "w3");
130CPUMREGALIAS_STD(x4, "w4");
131CPUMREGALIAS_STD(x5, "w5");
132CPUMREGALIAS_STD(x6, "w6");
133CPUMREGALIAS_STD(x7, "w7");
134CPUMREGALIAS_STD(x8, "w8");
135CPUMREGALIAS_STD(x9, "w9");
136CPUMREGALIAS_STD(x10, "w10");
137CPUMREGALIAS_STD(x11, "w11");
138CPUMREGALIAS_STD(x12, "w12");
139CPUMREGALIAS_STD(x13, "w13");
140CPUMREGALIAS_STD(x14, "w14");
141CPUMREGALIAS_STD(x15, "w15");
142CPUMREGALIAS_STD(x16, "w16");
143CPUMREGALIAS_STD(x17, "w17");
144CPUMREGALIAS_STD(x18, "w18");
145CPUMREGALIAS_STD(x19, "w19");
146CPUMREGALIAS_STD(x20, "w20");
147CPUMREGALIAS_STD(x21, "w21");
148CPUMREGALIAS_STD(x22, "w22");
149CPUMREGALIAS_STD(x23, "w23");
150CPUMREGALIAS_STD(x24, "w24");
151CPUMREGALIAS_STD(x25, "w25");
152CPUMREGALIAS_STD(x26, "w26");
153CPUMREGALIAS_STD(x27, "w27");
154CPUMREGALIAS_STD(x28, "w28");
155CPUMREGALIAS_STD(x29, "w29");
156CPUMREGALIAS_STD(x30, "w30");
157#undef CPUMREGALIAS_STD
158
159static DBGFREGALIAS const g_aCpumRegAliases_pstate[] =
160{
161 { "spsr_el2", DBGFREGVALTYPE_U64 },
162 { NULL, DBGFREGVALTYPE_INVALID }
163};
164
165
166/*
167 * Sub fields.
168 */
169/** Sub-fields for the SPSR_EL2/PSTATE register. */
170static DBGFREGSUBFIELD const g_aCpumRegFields_pstate[] =
171{
172 DBGFREGSUBFIELD_RW("sp", 0, 1, 0),
173 DBGFREGSUBFIELD_RW("el", 2, 2, 0),
174 DBGFREGSUBFIELD_RW("m4", 4, 1, 0),
175 DBGFREGSUBFIELD_RW("f", 6, 1, 0),
176 DBGFREGSUBFIELD_RW("i", 7, 1, 0),
177 DBGFREGSUBFIELD_RW("a", 8, 1, 0),
178 DBGFREGSUBFIELD_RW("d", 9, 1, 0),
179 DBGFREGSUBFIELD_RW("btype", 10, 2, 0),
180 DBGFREGSUBFIELD_RW("ssbs", 12, 1, 0),
181 DBGFREGSUBFIELD_RW("allint", 13, 1, 0),
182 DBGFREGSUBFIELD_RW("il", 20, 1, 0),
183 DBGFREGSUBFIELD_RW("ss", 21, 1, 0),
184 DBGFREGSUBFIELD_RW("pan", 22, 1, 0),
185 DBGFREGSUBFIELD_RW("uao", 23, 1, 0),
186 DBGFREGSUBFIELD_RW("dit", 24, 1, 0),
187 DBGFREGSUBFIELD_RW("tco", 25, 1, 0),
188 DBGFREGSUBFIELD_RW("v", 28, 1, 0),
189 DBGFREGSUBFIELD_RW("c", 29, 1, 0),
190 DBGFREGSUBFIELD_RW("z", 30, 1, 0),
191 DBGFREGSUBFIELD_RW("n", 31, 1, 0),
192 DBGFREGSUBFIELD_TERMINATOR()
193};
194
195/** Sub-fields for the v<n> registers. */
196static DBGFREGSUBFIELD const g_aCpumRegFields_vN[] =
197{
198 DBGFREGSUBFIELD_RW("r0", 0, 32, 0),
199 DBGFREGSUBFIELD_RW("r0.man", 0+ 0, 23, 0),
200 DBGFREGSUBFIELD_RW("r0.exp", 0+23, 8, 0),
201 DBGFREGSUBFIELD_RW("r0.sig", 0+31, 1, 0),
202 DBGFREGSUBFIELD_RW("r1", 32, 32, 0),
203 DBGFREGSUBFIELD_RW("r1.man", 32+ 0, 23, 0),
204 DBGFREGSUBFIELD_RW("r1.exp", 32+23, 8, 0),
205 DBGFREGSUBFIELD_RW("r1.sig", 32+31, 1, 0),
206 DBGFREGSUBFIELD_RW("r2", 64, 32, 0),
207 DBGFREGSUBFIELD_RW("r2.man", 64+ 0, 23, 0),
208 DBGFREGSUBFIELD_RW("r2.exp", 64+23, 8, 0),
209 DBGFREGSUBFIELD_RW("r2.sig", 64+31, 1, 0),
210 DBGFREGSUBFIELD_RW("r3", 96, 32, 0),
211 DBGFREGSUBFIELD_RW("r3.man", 96+ 0, 23, 0),
212 DBGFREGSUBFIELD_RW("r3.exp", 96+23, 8, 0),
213 DBGFREGSUBFIELD_RW("r3.sig", 96+31, 1, 0),
214 DBGFREGSUBFIELD_TERMINATOR()
215};
216
217/** @name Macros for producing register descriptor table entries.
218 * @{ */
219#define CPU_REG_EX_AS(a_szName, a_RegSuff, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
220 { a_szName, DBGFREG_ARMV8_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
221
222#define CPU_GREG_REG(n) \
223 CPU_REG_RW_AS("x" #n, GREG_X##n, U64, aGRegs[n], cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_x##n, NULL)
224
225#define CPU_VREG_REG(n) \
226 CPU_REG_RW_AS("v" #n, VREG_V##n, U128, aVRegs[n], cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, g_aCpumRegFields_vN)
227
228/** @} */
229
230
231/**
232 * The guest register descriptors.
233 */
234static DBGFREGDESC const g_aCpumRegGstDescs[] =
235{
236#define CPU_REG_RW_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
237 { a_szName, DBGFREG_ARMV8_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, (uint32_t)RT_UOFFSETOF(CPUMCPU, Guest.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
238#define CPU_REG_RO_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
239 { a_szName, DBGFREG_ARMV8_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, (uint32_t)RT_UOFFSETOF(CPUMCPU, Guest.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
240
241 CPU_GREG_REG(0),
242 CPU_GREG_REG(1),
243 CPU_GREG_REG(2),
244 CPU_GREG_REG(3),
245 CPU_GREG_REG(4),
246 CPU_GREG_REG(5),
247 CPU_GREG_REG(6),
248 CPU_GREG_REG(7),
249 CPU_GREG_REG(8),
250 CPU_GREG_REG(9),
251 CPU_GREG_REG(10),
252 CPU_GREG_REG(11),
253 CPU_GREG_REG(12),
254 CPU_GREG_REG(13),
255 CPU_GREG_REG(14),
256 CPU_GREG_REG(15),
257 CPU_GREG_REG(16),
258 CPU_GREG_REG(17),
259 CPU_GREG_REG(18),
260 CPU_GREG_REG(19),
261 CPU_GREG_REG(20),
262 CPU_GREG_REG(21),
263 CPU_GREG_REG(22),
264 CPU_GREG_REG(23),
265 CPU_GREG_REG(24),
266 CPU_GREG_REG(25),
267 CPU_GREG_REG(26),
268 CPU_GREG_REG(27),
269 CPU_GREG_REG(28),
270 CPU_GREG_REG(29),
271 CPU_GREG_REG(30),
272 CPU_REG_RW_AS("pstate", PSTATE, U64, fPState, cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_pstate, g_aCpumRegFields_pstate ),
273 CPU_REG_RW_AS("pc", PC, U64, Pc, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
274 CPU_REG_RW_AS("sp_el0", SP_EL0, U64, aSpReg[0], cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
275 CPU_REG_RW_AS("sp_el1", SP_EL1, U64, aSpReg[1], cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
276 CPU_REG_RW_AS("spsr_el1", SPSR_EL1, U64, Spsr, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
277 CPU_REG_RW_AS("sctlr_el1", SCTLR_EL1, U64, Sctlr, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
278 CPU_REG_RW_AS("tcr_el1", TCR_EL1, U64, Tcr, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
279 CPU_REG_RW_AS("ttbr0_el1", TTBR0_EL1, U64, Ttbr0, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
280 CPU_REG_RW_AS("ttbr1_el1", TTBR1_EL1, U64, Ttbr1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
281 CPU_REG_RW_AS("elr_el1", ELR_EL1, U64, Elr, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
282 CPU_REG_RW_AS("vbar_el1", VBAR_EL1, U64, VBar, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
283 CPU_REG_RW_AS("fpcr", FPCR, U64, fpcr, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
284 CPU_REG_RW_AS("fpsr", FPSR, U64, fpsr, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
285 CPU_VREG_REG(0),
286 CPU_VREG_REG(1),
287 CPU_VREG_REG(2),
288 CPU_VREG_REG(3),
289 CPU_VREG_REG(4),
290 CPU_VREG_REG(5),
291 CPU_VREG_REG(6),
292 CPU_VREG_REG(7),
293 CPU_VREG_REG(8),
294 CPU_VREG_REG(9),
295 CPU_VREG_REG(10),
296 CPU_VREG_REG(11),
297 CPU_VREG_REG(12),
298 CPU_VREG_REG(13),
299 CPU_VREG_REG(14),
300 CPU_VREG_REG(15),
301 CPU_VREG_REG(16),
302 CPU_VREG_REG(17),
303 CPU_VREG_REG(18),
304 CPU_VREG_REG(19),
305 CPU_VREG_REG(20),
306 CPU_VREG_REG(21),
307 CPU_VREG_REG(22),
308 CPU_VREG_REG(23),
309 CPU_VREG_REG(24),
310 CPU_VREG_REG(25),
311 CPU_VREG_REG(26),
312 CPU_VREG_REG(27),
313 CPU_VREG_REG(28),
314 CPU_VREG_REG(29),
315 CPU_VREG_REG(30),
316 CPU_VREG_REG(31),
317 DBGFREGDESC_TERMINATOR()
318
319#undef CPU_REG_RW_AS
320#undef CPU_REG_RO_AS
321};
322
323
324/**
325 * Initializes the debugger related sides of the CPUM component.
326 *
327 * Called by CPUMR3Init.
328 *
329 * @returns VBox status code.
330 * @param pVM The cross context VM structure.
331 */
332DECLHIDDEN(int) cpumR3DbgInit(PVM pVM)
333{
334 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
335 {
336 int rc = DBGFR3RegRegisterCpu(pVM, pVM->apCpusR3[idCpu], g_aCpumRegGstDescs, true /*fGuestRegs*/);
337 AssertLogRelRCReturn(rc, rc);
338 }
339
340 return VINF_SUCCESS;
341}
342
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use