VirtualBox

source: vbox/trunk/include/VBox/cpum.h@ 1071

Last change on this file since 1071 was 1056, checked in by vboxsync, 18 years ago

CPUMR3SetCR4Feature

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.1 KB
Line 
1/** @file
2 * CPUM - CPU Monitor(/ Manager).
3 */
4
5/*
6 * Copyright (C) 2006 InnoTek Systemberatung GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#ifndef __VBox_cpum_h__
22#define __VBox_cpum_h__
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/x86.h>
27
28
29__BEGIN_DECLS
30
31/** @defgroup grp_cpum The CPU Monitor(/Manager) API
32 * @{
33 */
34
35/**
36 * Selector hidden registers.
37 */
38typedef struct CPUMSELREGHIDDEN
39{
40 /** Base register. */
41 uint32_t u32Base;
42 /** Limit (expanded). */
43 uint32_t u32Limit;
44 /** Flags.
45 * This is the high 32-bit word of the descriptor entry.
46 * Only the flags, dpl and type are used. */
47 X86DESCATTR Attr;
48} CPUMSELREGHID;
49/** Pointer to selector hidden registers. */
50typedef CPUMSELREGHID *PCPUMSELREGHID;
51/** Pointer to const selector hidden registers. */
52typedef const CPUMSELREGHID *PCCPUMSELREGHID;
53
54
55/**
56 * The sysenter register set.
57 */
58typedef struct CPUMSYSENTER
59{
60 /** Ring 0 cs.
61 * This value + 8 is the Ring 0 ss.
62 * This value + 16 is the Ring 3 cs.
63 * This value + 24 is the Ring 3 ss.
64 */
65 uint64_t cs;
66 /** Ring 0 eip. */
67 uint64_t eip;
68 /** Ring 0 esp. */
69 uint64_t esp;
70} CPUMSYSENTER;
71
72
73/**
74 * CPU context core.
75 */
76#pragma pack(1)
77typedef struct CPUMCTXCORE
78{
79 uint32_t edi;
80 uint32_t esi;
81 uint32_t ebp;
82 uint32_t eax;
83 uint32_t ebx;
84 uint32_t edx;
85 uint32_t ecx;
86
87 uint32_t esp;
88 RTSEL ss;
89 RTSEL ssPadding;
90
91 RTSEL gs;
92 RTSEL gsPadding;
93 RTSEL fs;
94 RTSEL fsPadding;
95 RTSEL es;
96 RTSEL esPadding;
97 RTSEL ds;
98 RTSEL dsPadding;
99 RTSEL cs;
100 RTSEL csPadding;
101
102 X86EFLAGS eflags;
103 uint32_t eip;
104
105 /** Hidden selector registers.
106 * @{ */
107 CPUMSELREGHID esHid;
108 CPUMSELREGHID csHid;
109 CPUMSELREGHID ssHid;
110 CPUMSELREGHID dsHid;
111 CPUMSELREGHID fsHid;
112 CPUMSELREGHID gsHid;
113 /** @} */
114
115} CPUMCTXCORE;
116/** Pointer to CPU context core. */
117typedef CPUMCTXCORE *PCPUMCTXCORE;
118/** Pointer to const CPU context core. */
119typedef const CPUMCTXCORE *PCCPUMCTXCORE;
120#pragma pack()
121
122/**
123 * CPU context.
124 */
125#pragma pack(1)
126typedef struct CPUMCTX
127{
128 /** FPU state. (16-byte alignment)
129 * @todo This doesn't have to be in X86FXSTATE on CPUs without fxsr - we need a type for the
130 * actual format or convert it (waste of time). */
131 X86FXSTATE fpu;
132
133 /** CPUMCTXCORE Part.
134 * @{ */
135 uint32_t edi;
136 uint32_t esi;
137 uint32_t ebp;
138 uint32_t eax;
139 uint32_t ebx;
140 uint32_t edx;
141 uint32_t ecx;
142
143 uint32_t esp;
144 RTSEL ss;
145 RTSEL ssPadding;
146
147 RTSEL gs;
148 RTSEL gsPadding;
149 RTSEL fs;
150 RTSEL fsPadding;
151 RTSEL es;
152 RTSEL esPadding;
153 RTSEL ds;
154 RTSEL dsPadding;
155 RTSEL cs;
156 RTSEL csPadding;
157
158 X86EFLAGS eflags;
159 uint32_t eip;
160
161 /** Hidden selector registers.
162 * @{ */
163 CPUMSELREGHID esHid;
164 CPUMSELREGHID csHid;
165 CPUMSELREGHID ssHid;
166 CPUMSELREGHID dsHid;
167 CPUMSELREGHID fsHid;
168 CPUMSELREGHID gsHid;
169 /** @} */
170
171 /** @} */
172
173 /** Control registers.
174 * @{ */
175 uint32_t cr0;
176 uint32_t cr2;
177 uint32_t cr3;
178 uint32_t cr4;
179 /** @} */
180
181 /** Debug registers.
182 * @{ */
183 uint32_t dr0;
184 uint32_t dr1;
185 uint32_t dr2;
186 uint32_t dr3;
187 uint32_t dr4; /**< @todo remove dr4 and dr5. */
188 uint32_t dr5;
189 uint32_t dr6;
190 uint32_t dr7;
191 /** @} */
192
193 /** Global Descriptor Table register. */
194 VBOXGDTR gdtr;
195 uint16_t gdtrPadding;
196 uint32_t gdtrPadding64;/** @todo fix this hack */
197 /** Interrupt Descriptor Table register. */
198 VBOXIDTR idtr;
199 uint16_t idtrPadding;
200 uint32_t idtrPadding64;/** @todo fix this hack */
201 /** The task register.
202 * Only the guest context uses all the members. */
203 RTSEL ldtr;
204 RTSEL ldtrPadding;
205 /** The task register.
206 * Only the guest context uses all the members. */
207 RTSEL tr;
208 RTSEL trPadding;
209
210 /** The sysenter msr registers.
211 * This member is not used by the hypervisor context. */
212 CPUMSYSENTER SysEnter;
213
214 /** Hidden selector registers.
215 * @{ */
216 CPUMSELREGHID ldtrHid;
217 CPUMSELREGHID trHid;
218 /** @} */
219
220 /* padding to get 32byte aligned size */
221 uint32_t padding[6];
222} CPUMCTX;
223#pragma pack()
224/** Pointer to CPUMCTX. */
225typedef CPUMCTX *PCPUMCTX;
226
227/**
228 * Gets the CPUMCTXCORE part of a CPUMCTX.
229 */
230#define CPUMCTX2CORE(pCtx) ((PCPUMCTXCORE)(void *)&(pCtx)->edi)
231
232/**
233 * The register set returned by a CPUID operation.
234 */
235typedef struct CPUMCPUID
236{
237 uint32_t eax;
238 uint32_t ebx;
239 uint32_t ecx;
240 uint32_t edx;
241} CPUMCPUID;
242/** Pointer to a CPUID leaf. */
243typedef CPUMCPUID *PCPUMCPUID;
244/** Pointer to a const CPUID leaf. */
245typedef const CPUMCPUID *PCCPUMCPUID;
246
247/**
248 * CPUID feature to set or clear.
249 */
250typedef enum CPUMCPUIDFEATURE
251{
252 CPUMCPUIDFEATURE_INVALID = 0,
253 /** The APIC feature bit. (Std+Ext) */
254 CPUMCPUIDFEATURE_APIC,
255 /** The sysenter/sysexit feature bit. (Std+Ext) */
256 CPUMCPUIDFEATURE_SEP
257} CPUMCPUIDFEATURE;
258
259
260/** @name Guest Register Getters.
261 * @{ */
262CPUMDECL(void) CPUMGetGuestGDTR(PVM pVM, PVBOXGDTR pGDTR);
263CPUMDECL(uint32_t) CPUMGetGuestIDTR(PVM pVM, uint16_t *pcbLimit);
264CPUMDECL(RTSEL) CPUMGetGuestTR(PVM pVM);
265CPUMDECL(RTSEL) CPUMGetGuestLDTR(PVM pVM);
266CPUMDECL(uint32_t) CPUMGetGuestCR0(PVM pVM);
267CPUMDECL(uint32_t) CPUMGetGuestCR2(PVM pVM);
268CPUMDECL(uint32_t) CPUMGetGuestCR3(PVM pVM);
269CPUMDECL(uint32_t) CPUMGetGuestCR4(PVM pVM);
270CPUMDECL(int) CPUMGetGuestCRx(PVM pVM, uint32_t iReg, uint32_t *pValue);
271CPUMDECL(uint32_t) CPUMGetGuestEFlags(PVM pVM);
272CPUMDECL(uint32_t) CPUMGetGuestEIP(PVM pVM);
273CPUMDECL(uint32_t) CPUMGetGuestEAX(PVM pVM);
274CPUMDECL(uint32_t) CPUMGetGuestEBX(PVM pVM);
275CPUMDECL(uint32_t) CPUMGetGuestECX(PVM pVM);
276CPUMDECL(uint32_t) CPUMGetGuestEDX(PVM pVM);
277CPUMDECL(uint32_t) CPUMGetGuestESI(PVM pVM);
278CPUMDECL(uint32_t) CPUMGetGuestEDI(PVM pVM);
279CPUMDECL(uint32_t) CPUMGetGuestESP(PVM pVM);
280CPUMDECL(uint32_t) CPUMGetGuestEBP(PVM pVM);
281CPUMDECL(RTSEL) CPUMGetGuestCS(PVM pVM);
282CPUMDECL(RTSEL) CPUMGetGuestDS(PVM pVM);
283CPUMDECL(RTSEL) CPUMGetGuestES(PVM pVM);
284CPUMDECL(RTSEL) CPUMGetGuestFS(PVM pVM);
285CPUMDECL(RTSEL) CPUMGetGuestGS(PVM pVM);
286CPUMDECL(RTSEL) CPUMGetGuestSS(PVM pVM);
287CPUMDECL(RTUINTREG) CPUMGetGuestDR0(PVM pVM);
288CPUMDECL(RTUINTREG) CPUMGetGuestDR1(PVM pVM);
289CPUMDECL(RTUINTREG) CPUMGetGuestDR2(PVM pVM);
290CPUMDECL(RTUINTREG) CPUMGetGuestDR3(PVM pVM);
291CPUMDECL(RTUINTREG) CPUMGetGuestDR6(PVM pVM);
292CPUMDECL(RTUINTREG) CPUMGetGuestDR7(PVM pVM);
293CPUMDECL(int) CPUMGetGuestDRx(PVM pVM, uint32_t iReg, uint32_t *pValue);
294CPUMDECL(void) CPUMGetGuestCpuId(PVM pVM, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx);
295CPUMDECL(GCPTRTYPE(PCCPUMCPUID)) CPUMGetGuestCpuIdStdGCPtr(PVM pVM);
296CPUMDECL(GCPTRTYPE(PCCPUMCPUID)) CPUMGetGuestCpuIdExtGCPtr(PVM pVM);
297CPUMDECL(GCPTRTYPE(PCCPUMCPUID)) CPUMGetGuestCpuIdDefGCPtr(PVM pVM);
298CPUMDECL(uint32_t) CPUMGetGuestCpuIdStdMax(PVM pVM);
299CPUMDECL(uint32_t) CPUMGetGuestCpuIdExtMax(PVM pVM);
300CPUMDECL(void) CPUMGetGuestCtx(PVM pVM, PCPUMCTX pCtx);
301CPUMDECL(CPUMSELREGHID *) CPUMGetGuestTRHid(PVM pVM);
302/** @} */
303
304/** @name Guest Register Setters.
305 * @{ */
306CPUMDECL(int) CPUMSetGuestGDTR(PVM pVM, uint32_t addr, uint16_t limit);
307CPUMDECL(int) CPUMSetGuestIDTR(PVM pVM, uint32_t addr, uint16_t limit);
308CPUMDECL(int) CPUMSetGuestTR(PVM pVM, uint16_t tr);
309CPUMDECL(int) CPUMSetGuestLDTR(PVM pVM, uint16_t ldtr);
310CPUMDECL(int) CPUMSetGuestCR0(PVM pVM, uint32_t cr0);
311CPUMDECL(int) CPUMSetGuestCR2(PVM pVM, uint32_t cr2);
312CPUMDECL(int) CPUMSetGuestCR3(PVM pVM, uint32_t cr3);
313CPUMDECL(int) CPUMSetGuestCR4(PVM pVM, uint32_t cr4);
314CPUMDECL(int) CPUMSetGuestCRx(PVM pVM, uint32_t iReg, uint32_t Value);
315CPUMDECL(int) CPUMSetGuestDR0(PVM pVM, RTGCUINTREG uDr0);
316CPUMDECL(int) CPUMSetGuestDR1(PVM pVM, RTGCUINTREG uDr1);
317CPUMDECL(int) CPUMSetGuestDR2(PVM pVM, RTGCUINTREG uDr2);
318CPUMDECL(int) CPUMSetGuestDR3(PVM pVM, RTGCUINTREG uDr3);
319CPUMDECL(int) CPUMSetGuestDR6(PVM pVM, RTGCUINTREG uDr6);
320CPUMDECL(int) CPUMSetGuestDR7(PVM pVM, RTGCUINTREG uDr7);
321CPUMDECL(int) CPUMSetGuestDRx(PVM pVM, uint32_t iReg, uint32_t Value);
322CPUMDECL(int) CPUMSetGuestEFlags(PVM pVM, uint32_t eflags);
323CPUMDECL(int) CPUMSetGuestEIP(PVM pVM, uint32_t eip);
324CPUMDECL(int) CPUMSetGuestEAX(PVM pVM, uint32_t eax);
325CPUMDECL(int) CPUMSetGuestEBX(PVM pVM, uint32_t ebx);
326CPUMDECL(int) CPUMSetGuestECX(PVM pVM, uint32_t ecx);
327CPUMDECL(int) CPUMSetGuestEDX(PVM pVM, uint32_t edx);
328CPUMDECL(int) CPUMSetGuestESI(PVM pVM, uint32_t esi);
329CPUMDECL(int) CPUMSetGuestEDI(PVM pVM, uint32_t edi);
330CPUMDECL(int) CPUMSetGuestESP(PVM pVM, uint32_t esp);
331CPUMDECL(int) CPUMSetGuestEBP(PVM pVM, uint32_t ebp);
332CPUMDECL(int) CPUMSetGuestCS(PVM pVM, uint16_t cs);
333CPUMDECL(int) CPUMSetGuestDS(PVM pVM, uint16_t ds);
334CPUMDECL(int) CPUMSetGuestES(PVM pVM, uint16_t es);
335CPUMDECL(int) CPUMSetGuestFS(PVM pVM, uint16_t fs);
336CPUMDECL(int) CPUMSetGuestGS(PVM pVM, uint16_t gs);
337CPUMDECL(int) CPUMSetGuestSS(PVM pVM, uint16_t ss);
338CPUMDECL(void) CPUMSetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature);
339CPUMDECL(void) CPUMClearGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature);
340CPUMDECL(void) CPUMSetGuestCtx(PVM pVM, const PCPUMCTX pCtx);
341/** @} */
342
343/** @name Misc Guest Predicate Functions.
344 * @{ */
345
346/**
347 * Tests if the guest is running in real mode or not.
348 *
349 * @returns true if in real mode, otherwise false.
350 * @param pVM The VM handle.
351 */
352DECLINLINE(bool) CPUMIsGuestInRealMode(PVM pVM)
353{
354 return !(CPUMGetGuestCR0(pVM) & X86_CR0_PE);
355}
356
357/**
358 * Tests if the guest is running in protected or not.
359 *
360 * @returns true if in protected mode, otherwise false.
361 * @param pVM The VM handle.
362 */
363DECLINLINE(bool) CPUMIsGuestInProtectedMode(PVM pVM)
364{
365 return !!(CPUMGetGuestCR0(pVM) & X86_CR0_PE);
366}
367
368/**
369 * Tests if the guest is running in paged protected or not.
370 *
371 * @returns true if in paged protected mode, otherwise false.
372 * @param pVM The VM handle.
373 */
374DECLINLINE(bool) CPUMIsGuestInPagedProtectedMode(PVM pVM)
375{
376 return (CPUMGetGuestCR0(pVM) & (X86_CR0_PE | X86_CR0_PG)) == (X86_CR0_PE | X86_CR0_PG);
377}
378
379/**
380 * Tests if the guest is running in paged protected or not.
381 *
382 * @returns true if in paged protected mode, otherwise false.
383 * @param pVM The VM handle.
384 */
385CPUMDECL(bool) CPUMIsGuestIn16BitCode(PVM pVM);
386
387/**
388 * Tests if the guest is running in paged protected or not.
389 *
390 * @returns true if in paged protected mode, otherwise false.
391 * @param pVM The VM handle.
392 */
393CPUMDECL(bool) CPUMIsGuestIn32BitCode(PVM pVM);
394
395/**
396 * Tests if the guest is running in paged protected or not.
397 *
398 * @returns true if in paged protected mode, otherwise false.
399 * @param pVM The VM handle.
400 */
401CPUMDECL(bool) CPUMIsGuestIn64BitCode(PVM pVM);
402
403/** @} */
404
405
406
407/** @name Hypervisor Register Getters.
408 * @{ */
409CPUMDECL(RTSEL) CPUMGetHyperCS(PVM pVM);
410CPUMDECL(RTSEL) CPUMGetHyperDS(PVM pVM);
411CPUMDECL(RTSEL) CPUMGetHyperES(PVM pVM);
412CPUMDECL(RTSEL) CPUMGetHyperFS(PVM pVM);
413CPUMDECL(RTSEL) CPUMGetHyperGS(PVM pVM);
414CPUMDECL(RTSEL) CPUMGetHyperSS(PVM pVM);
415#if 0 /* these are not correct. */
416CPUMDECL(uint32_t) CPUMGetHyperCR0(PVM pVM);
417CPUMDECL(uint32_t) CPUMGetHyperCR2(PVM pVM);
418CPUMDECL(uint32_t) CPUMGetHyperCR3(PVM pVM);
419CPUMDECL(uint32_t) CPUMGetHyperCR4(PVM pVM);
420#endif
421/** This register is only saved on fatal traps. */
422CPUMDECL(uint32_t) CPUMGetHyperEAX(PVM pVM);
423CPUMDECL(uint32_t) CPUMGetHyperEBX(PVM pVM);
424/** This register is only saved on fatal traps. */
425CPUMDECL(uint32_t) CPUMGetHyperECX(PVM pVM);
426/** This register is only saved on fatal traps. */
427CPUMDECL(uint32_t) CPUMGetHyperEDX(PVM pVM);
428CPUMDECL(uint32_t) CPUMGetHyperESI(PVM pVM);
429CPUMDECL(uint32_t) CPUMGetHyperEDI(PVM pVM);
430CPUMDECL(uint32_t) CPUMGetHyperEBP(PVM pVM);
431CPUMDECL(uint32_t) CPUMGetHyperESP(PVM pVM);
432CPUMDECL(uint32_t) CPUMGetHyperEFlags(PVM pVM);
433CPUMDECL(uint32_t) CPUMGetHyperEIP(PVM pVM);
434CPUMDECL(uint32_t) CPUMGetHyperIDTR(PVM pVM, uint16_t *pcbLimit);
435CPUMDECL(uint32_t) CPUMGetHyperGDTR(PVM pVM, uint16_t *pcbLimit);
436CPUMDECL(RTSEL) CPUMGetHyperLDTR(PVM pVM);
437CPUMDECL(RTGCUINTREG) CPUMGetHyperDR0(PVM pVM);
438CPUMDECL(RTGCUINTREG) CPUMGetHyperDR1(PVM pVM);
439CPUMDECL(RTGCUINTREG) CPUMGetHyperDR2(PVM pVM);
440CPUMDECL(RTGCUINTREG) CPUMGetHyperDR3(PVM pVM);
441CPUMDECL(RTGCUINTREG) CPUMGetHyperDR6(PVM pVM);
442CPUMDECL(RTGCUINTREG) CPUMGetHyperDR7(PVM pVM);
443CPUMDECL(void) CPUMGetHyperCtx(PVM pVM, PCPUMCTX pCtx);
444/** @} */
445
446/** @name Hypervisor Register Setters.
447 * @{ */
448CPUMDECL(void) CPUMSetHyperGDTR(PVM pVM, uint32_t addr, uint16_t limit);
449CPUMDECL(void) CPUMSetHyperLDTR(PVM pVM, RTSEL SelLDTR);
450CPUMDECL(void) CPUMSetHyperIDTR(PVM pVM, uint32_t addr, uint16_t limit);
451CPUMDECL(void) CPUMSetHyperCR3(PVM pVM, uint32_t cr3);
452CPUMDECL(void) CPUMSetHyperTR(PVM pVM, RTSEL SelTR);
453CPUMDECL(void) CPUMSetHyperCS(PVM pVM, RTSEL SelCS);
454CPUMDECL(void) CPUMSetHyperDS(PVM pVM, RTSEL SelDS);
455CPUMDECL(void) CPUMSetHyperES(PVM pVM, RTSEL SelDS);
456CPUMDECL(void) CPUMSetHyperFS(PVM pVM, RTSEL SelDS);
457CPUMDECL(void) CPUMSetHyperGS(PVM pVM, RTSEL SelDS);
458CPUMDECL(void) CPUMSetHyperSS(PVM pVM, RTSEL SelSS);
459CPUMDECL(void) CPUMSetHyperESP(PVM pVM, uint32_t u32ESP);
460CPUMDECL(int) CPUMSetHyperEFlags(PVM pVM, uint32_t Efl);
461CPUMDECL(void) CPUMSetHyperEIP(PVM pVM, uint32_t u32EIP);
462CPUMDECL(void) CPUMSetHyperDR0(PVM pVM, RTGCUINTREG uDr0);
463CPUMDECL(void) CPUMSetHyperDR1(PVM pVM, RTGCUINTREG uDr1);
464CPUMDECL(void) CPUMSetHyperDR2(PVM pVM, RTGCUINTREG uDr2);
465CPUMDECL(void) CPUMSetHyperDR3(PVM pVM, RTGCUINTREG uDr3);
466CPUMDECL(void) CPUMSetHyperDR6(PVM pVM, RTGCUINTREG uDr6);
467CPUMDECL(void) CPUMSetHyperDR7(PVM pVM, RTGCUINTREG uDr7);
468CPUMDECL(void) CPUMSetHyperCtx(PVM pVM, const PCPUMCTX pCtx);
469CPUMDECL(int) CPUMRecalcHyperDRx(PVM pVM);
470/** @} */
471
472CPUMDECL(void) CPUMPushHyper(PVM pVM, uint32_t u32);
473
474/**
475 * Sets or resets an alternative hypervisor context core.
476 *
477 * This is called when we get a hypervisor trap set switch the context
478 * core with the trap frame on the stack. It is called again to reset
479 * back to the default context core when resuming hypervisor execution.
480 *
481 * @param pVM The VM handle.
482 * @param pCtxCore Pointer to the alternative context core or NULL
483 * to go back to the default context core.
484 */
485CPUMDECL(void) CPUMHyperSetCtxCore(PVM pVM, PCPUMCTXCORE pCtxCore);
486
487
488/**
489 * Queries the pointer to the internal CPUMCTX structure
490 *
491 * @returns VBox status code.
492 * @param pVM Handle to the virtual machine.
493 * @param ppCtx Receives the CPUMCTX pointer when successful.
494 */
495CPUMDECL(int) CPUMQueryGuestCtxPtr(PVM pVM, PCPUMCTX *ppCtx);
496
497/**
498 * Queries the pointer to the internal CPUMCTX structure for the hypervisor.
499 *
500 * @returns VBox status code.
501 * @param pVM Handle to the virtual machine.
502 * @param ppCtx Receives the hyper CPUMCTX pointer when successful.
503 */
504CPUMDECL(int) CPUMQueryHyperCtxPtr(PVM pVM, PCPUMCTX *ppCtx);
505
506
507/**
508 * Gets the pointer to the internal CPUMCTXCORE structure.
509 * This is only for reading in order to save a few calls.
510 *
511 * @param pVM Handle to the virtual machine.
512 */
513CPUMDECL(PCCPUMCTXCORE) CPUMGetGuestCtxCore(PVM pVM);
514
515/**
516 * Gets the pointer to the internal CPUMCTXCORE structure for the hypervisor.
517 * This is only for reading in order to save a few calls.
518 *
519 * @param pVM Handle to the virtual machine.
520 */
521CPUMDECL(PCCPUMCTXCORE) CPUMGetHyperCtxCore(PVM pVM);
522
523/**
524 * Sets the guest context core registers.
525 *
526 * @param pVM Handle to the virtual machine.
527 * @param pCtxCore The new context core values.
528 */
529CPUMDECL(void) CPUMSetGuestCtxCore(PVM pVM, PCCPUMCTXCORE pCtxCore);
530
531
532/**
533 * Transforms the guest CPU state to raw-ring mode.
534 *
535 * This function will change the any of the cs and ss register with DPL=0 to DPL=1.
536 *
537 * @returns VBox status. (recompiler failure)
538 * @param pVM VM handle.
539 * @param pCtxCore The context core (for trap usage).
540 * @see @ref pg_raw
541 */
542CPUMDECL(int) CPUMRawEnter(PVM pVM, PCPUMCTXCORE pCtxCore);
543
544/**
545 * Transforms the guest CPU state from raw-ring mode to correct values.
546 *
547 * This function will change any selector registers with DPL=1 to DPL=0.
548 *
549 * @returns Adjusted rc.
550 * @param pVM VM handle.
551 * @param rc Raw mode return code
552 * @param pCtxCore The context core (for trap usage).
553 * @see @ref pg_raw
554 */
555CPUMDECL(int) CPUMRawLeave(PVM pVM, PCPUMCTXCORE pCtxCore, int rc);
556
557/**
558 * Gets the EFLAGS while we're in raw-mode.
559 *
560 * @returns The eflags.
561 * @param pVM The VM handle.
562 * @param pCtxCore The context core.
563 */
564CPUMDECL(uint32_t) CPUMRawGetEFlags(PVM pVM, PCPUMCTXCORE pCtxCore);
565
566/**
567 * Updates the EFLAGS while we're in raw-mode.
568 *
569 * @param pVM The VM handle.
570 * @param pCtxCore The context core.
571 * @param eflags The new EFLAGS value.
572 */
573CPUMDECL(void) CPUMRawSetEFlags(PVM pVM, PCPUMCTXCORE pCtxCore, uint32_t eflags);
574
575/**
576 * Lazily sync in the FPU/XMM state
577 *
578 * This function will change any selector registers with DPL=1 to DPL=0.
579 *
580 * @returns VBox status code.
581 * @param pVM VM handle.
582 */
583CPUMDECL(int) CPUMHandleLazyFPU(PVM pVM);
584
585
586/**
587 * Restore host FPU/XMM state
588 *
589 * @returns VBox status code.
590 * @param pVM VM handle.
591 */
592CPUMDECL(int) CPUMRestoreHostFPUState(PVM pVM);
593
594/** @name Changed flags
595 * These flags are used to keep track of which important register that
596 * have been changed since last they were reset. The only one allowed
597 * to clear them is REM!
598 * @{
599 */
600#define CPUM_CHANGED_FPU_REM BIT(0)
601#define CPUM_CHANGED_CR0 BIT(1)
602#define CPUM_CHANGED_CR4 BIT(2)
603#define CPUM_CHANGED_GLOBAL_TLB_FLUSH BIT(3)
604#define CPUM_CHANGED_CR3 BIT(4)
605#define CPUM_CHANGED_GDTR BIT(5)
606#define CPUM_CHANGED_IDTR BIT(6)
607#define CPUM_CHANGED_LDTR BIT(7)
608#define CPUM_CHANGED_TR BIT(8)
609#define CPUM_CHANGED_SYSENTER_MSR BIT(9)
610#define CPUM_CHANGED_HIDDEN_SEL_REGS BIT(10)
611/** @} */
612
613/**
614 * Gets and resets the changed flags (CPUM_CHANGED_*).
615 *
616 * @returns The changed flags.
617 * @param pVM VM handle.
618 */
619CPUMDECL(unsigned) CPUMGetAndClearChangedFlagsREM(PVM pVM);
620
621/**
622 * Sets the specified changed flags (CPUM_CHANGED_*).
623 *
624 * @param pVM The VM handle.
625 */
626CPUMDECL(void) CPUMSetChangedFlags(PVM pVM, uint32_t fChangedFlags);
627
628/**
629 * Checks if the CPU supports the FXSAVE and FXRSTOR instruction.
630 * @returns true if supported.
631 * @returns false if not supported.
632 * @param pVM The VM handle.
633 */
634CPUMDECL(bool) CPUMSupportsFXSR(PVM pVM);
635
636/**
637 * Checks if the host OS uses the SYSENTER / SYSEXIT instructions.
638 * @returns true if used.
639 * @returns false if not used.
640 * @param pVM The VM handle.
641 */
642CPUMDECL(bool) CPUMIsHostUsingSysEnter(PVM pVM);
643
644/**
645 * Checks if the host OS uses the SYSCALL / SYSRET instructions.
646 * @returns true if used.
647 * @returns false if not used.
648 * @param pVM The VM handle.
649 */
650CPUMDECL(bool) CPUMIsHostUsingSysCall(PVM pVM);
651
652/**
653 * Checks if we activated the FPU/XMM state of the guest OS
654 * @returns true if we did.
655 * @returns false if not.
656 * @param pVM The VM handle.
657 */
658CPUMDECL(bool) CPUMIsGuestFPUStateActive(PVM pVM);
659
660/**
661 * Deactivate the FPU/XMM state of the guest OS
662 * @param pVM The VM handle.
663 */
664CPUMDECL(void) CPUMDeactivateGuestFPUState(PVM pVM);
665
666
667/**
668 * Checks if the hidden selector registers are valid
669 * @returns true if they are.
670 * @returns false if not.
671 * @param pVM The VM handle.
672 */
673CPUMDECL(bool) CPUMAreHiddenSelRegsValid(PVM pVM);
674
675/**
676 * Checks if the hidden selector registers are valid
677 * @param pVM The VM handle.
678 * @param fValid Valid or not
679 */
680CPUMDECL(void) CPUMSetHiddenSelRegsValid(PVM pVM, bool fValid);
681
682
683#ifdef IN_RING3
684/** @defgroup grp_cpum_r3 The CPU Monitor(/Manager) API
685 * @ingroup grp_cpum
686 * @{
687 */
688
689/**
690 * Initializes the CPUM.
691 *
692 * @returns VBox status code.
693 * @param pVM The VM to operate on.
694 */
695CPUMR3DECL(int) CPUMR3Init(PVM pVM);
696
697/**
698 * Applies relocations to data and code managed by this
699 * component. This function will be called at init and
700 * whenever the VMM need to relocate it self inside the GC.
701 *
702 * The CPUM will update the addresses used by the switcher.
703 *
704 * @param pVM The VM.
705 */
706CPUMR3DECL(void) CPUMR3Relocate(PVM pVM);
707
708/**
709 * Terminates the CPUM.
710 *
711 * Termination means cleaning up and freeing all resources,
712 * the VM it self is at this point powered off or suspended.
713 *
714 * @returns VBox status code.
715 * @param pVM The VM to operate on.
716 */
717CPUMR3DECL(int) CPUMR3Term(PVM pVM);
718
719/**
720 * Resets the CPU.
721 *
722 * @param pVM The VM handle.
723 */
724CPUMR3DECL(void) CPUMR3Reset(PVM pVM);
725
726/**
727 * Queries the pointer to the internal CPUMCTX structure
728 *
729 * @returns VBox status code.
730 * @param pVM Handle to the virtual machine.
731 * @param ppCtx Receives the CPUMCTX GC pointer when successful.
732 */
733CPUMR3DECL(int) CPUMR3QueryGuestCtxGCPtr(PVM pVM, GCPTRTYPE(PCPUMCTX) *ppCtx);
734
735
736#ifdef DEBUG
737/**
738 * Debug helper - Saves guest context on raw mode entry (for fatal dump)
739 *
740 * @internal
741 */
742CPUMR3DECL(void) CPUMR3SaveEntryCtx(PVM pVM);
743#endif
744
745/**
746 * API for controlling a few of the CPU features found in CR4.
747 *
748 * Currently only X86_CR4_TSD is accepted as input.
749 *
750 * @returns VBox status code.
751 *
752 * @param pVM The VM handle.
753 * @param fOr The CR4 OR mask.
754 * @param fAnd The CR4 AND mask.
755 */
756CPUMR3DECL(int) CPUMR3SetCR4Feature(PVM pVM, RTHCUINTREG fOr, RTHCUINTREG fAnd);
757
758/** @} */
759#endif
760
761#ifdef IN_GC
762/** @defgroup grp_cpum_gc The CPU Monitor(/Manager) API
763 * @ingroup grp_cpum
764 * @{
765 */
766
767/**
768 * Calls a guest trap/interrupt handler directly
769 * Assumes a trap stack frame has already been setup on the guest's stack!
770 *
771 * @param pRegFrame Original trap/interrupt context
772 * @param selCS Code selector of handler
773 * @param pHandler GC virtual address of handler
774 * @param eflags Callee's EFLAGS
775 * @param selSS Stack selector for handler
776 * @param pEsp Stack address for handler
777 *
778 * This function does not return!
779 *
780 */
781CPUMGCDECL(void) CPUMGCCallGuestTrapHandler(PCPUMCTXCORE pRegFrame, uint32_t selCS, RTGCPTR pHandler, uint32_t eflags, uint32_t selSS, RTGCPTR pEsp);
782
783/** @} */
784#endif
785
786#ifdef IN_RING0
787/** @defgroup grp_cpum_r0 The CPU Monitor(/Manager) API
788 * @ingroup grp_cpum
789 * @{
790 */
791
792/**
793 * Does Ring-0 CPUM initialization.
794 *
795 * This is mainly to check that the Host CPU mode is compatible
796 * with VBox.
797 *
798 * @returns VBox status code.
799 * @param pVM The VM to operate on.
800 */
801CPUMR0DECL(int) CPUMR0Init(PVM pVM);
802
803/** @} */
804#endif
805
806/** @} */
807__END_DECLS
808
809
810#endif
811
812
813
814
815
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