VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMInternal.h@ 12623

Last change on this file since 12623 was 12479, checked in by vboxsync, 16 years ago

Also print ring 0 release assertion messages to the release log. Now we get meaningless
VINF_EM_DBG_HYPER_ASSERTION guru meditations.

Bumped the minor version of the support driver, because of new exports.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.7 KB
Line 
1/* $Id: VMMInternal.h 12479 2008-09-16 09:14:29Z vboxsync $ */
2/** @file
3 * VMM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___VMMInternal_h
23#define ___VMMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/stam.h>
27#include <VBox/log.h>
28#include <iprt/critsect.h>
29
30
31#if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_GC)
32# error "Not in VMM! This is an internal header!"
33#endif
34
35
36/** @defgroup grp_vmm_int Internals
37 * @ingroup grp_vmm
38 * @internal
39 * @{
40 */
41
42/** @def VBOX_WITH_GC_AND_R0_RELEASE_LOG
43 * Enabled GC and R0 release logging (the latter is not implemented yet). */
44#define VBOX_WITH_GC_AND_R0_RELEASE_LOG
45
46
47/**
48 * Converts a VMM pointer into a VM pointer.
49 * @returns Pointer to the VM structure the VMM is part of.
50 * @param pVMM Pointer to VMM instance data.
51 */
52#define VMM2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
53
54
55/**
56 * Switcher function, HC to GC.
57 *
58 * @param pVM The VM handle.
59 * @returns Return code indicating the action to take.
60 */
61typedef DECLASMTYPE(int) FNVMMSWITCHERHC(PVM pVM);
62/** Pointer to switcher function. */
63typedef FNVMMSWITCHERHC *PFNVMMSWITCHERHC;
64
65/**
66 * Switcher function, GC to HC.
67 *
68 * @param rc VBox status code.
69 */
70typedef DECLASMTYPE(void) FNVMMSWITCHERGC(int rc);
71/** Pointer to switcher function. */
72typedef FNVMMSWITCHERGC *PFNVMMSWITCHERGC;
73
74
75/**
76 * The ring-0 logger instance.
77 * We need to be able to find the VM handle from the logger instance.
78 */
79typedef struct VMMR0LOGGER
80{
81 /** Pointer to the VM handle. */
82 R0PTRTYPE(PVM) pVM;
83 /** Size of the allocated logger instance (Logger). */
84 uint32_t cbLogger;
85 /** Flag indicating whether we've create the logger Ring-0 instance yet. */
86 bool fCreated;
87#if HC_ARCH_BITS == 32
88 uint32_t u32Alignment;
89#endif
90 /** The ring-0 logger instance. This extends beyond the size.*/
91 RTLOGGER Logger;
92} VMMR0LOGGER, *PVMMR0LOGGER;
93
94
95/**
96 * Jump buffer for the setjmp/longjmp like constructs used to
97 * quickly 'call' back into Ring-3.
98 */
99typedef struct VMMR0JMPBUF
100{
101 /** Tranditional jmp_buf stuff
102 * @{ */
103#if HC_ARCH_BITS == 32
104 uint32_t ebx;
105 uint32_t esi;
106 uint32_t edi;
107 uint32_t ebp;
108 uint32_t esp;
109 uint32_t eip;
110 uint32_t u32Padding;
111#endif
112#if HC_ARCH_BITS == 64
113 uint64_t rbx;
114# ifdef RT_OS_WINDOWS
115 uint64_t rsi;
116 uint64_t rdi;
117# endif
118 uint64_t rbp;
119 uint64_t r12;
120 uint64_t r13;
121 uint64_t r14;
122 uint64_t r15;
123 uint64_t rsp;
124 uint64_t rip;
125#endif
126 /** @} */
127
128 /** Flag that indicates that we've done a ring-3 call. */
129 bool fInRing3Call;
130 /** The number of bytes we've saved. */
131 uint32_t cbSavedStack;
132 /** Pointer to the buffer used to save the stack.
133 * This is assumed to be 8KB. */
134 RTR0PTR pvSavedStack;
135 /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
136 RTHCUINTREG SpCheck;
137 /** The esp we should resume execution with after the restore. */
138 RTHCUINTREG SpResume;
139} VMMR0JMPBUF, *PVMMR0JMPBUF;
140
141
142/**
143 * VMM Data (part of VMM)
144 */
145typedef struct VMM
146{
147 /** Offset to the VM structure.
148 * See VMM2VM(). */
149 RTINT offVM;
150
151 /** Size of the core code. */
152 RTUINT cbCoreCode;
153 /** Physical address of core code. */
154 RTHCPHYS HCPhysCoreCode;
155/** @todo pvHCCoreCodeR3 -> pvCoreCodeR3, pvHCCoreCodeR0 -> pvCoreCodeR0 */
156 /** Pointer to core code ring-3 mapping - contiguous memory.
157 * At present this only means the context switcher code. */
158 RTR3PTR pvHCCoreCodeR3;
159 /** Pointer to core code ring-0 mapping - contiguous memory.
160 * At present this only means the context switcher code. */
161 RTR0PTR pvHCCoreCodeR0;
162 /** Pointer to core code guest context mapping. */
163 RTGCPTR32 pvGCCoreCode;
164#ifdef VBOX_WITH_NMI
165 /** The guest context address of the APIC (host) mapping. */
166 RTGCPTR32 GCPtrApicBase;
167 RTGCPTR32 pGCPadding0; /**< Alignment padding */
168#endif
169 /** The current switcher.
170 * This will be set before the VMM is fully initialized. */
171 VMMSWITCHER enmSwitcher;
172 /** Array of offsets to the different switchers within the core code. */
173 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
174 /** Flag to disable the switcher permanently (VMX) (boolean) */
175 bool fSwitcherDisabled;
176
177 /** Host to guest switcher entry point. */
178 R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0HostToGuest;
179 /** Guest to host switcher entry point. */
180 RCPTRTYPE(PFNVMMSWITCHERGC) pfnGCGuestToHost;
181 /** Call Trampoline. See vmmGCCallTrampoline(). */
182 RTGCPTR32 pfnGCCallTrampoline;
183
184 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
185 RTGCPTR32 pfnCPUMGCResumeGuest;
186 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
187 RTGCPTR32 pfnCPUMGCResumeGuestV86;
188 /** The last GC return code. */
189 RTINT iLastGCRc;
190#if HC_ARCH_BITS == 64
191 uint32_t u32Padding0; /**< Alignment padding. */
192#endif
193
194 /** VMM stack, pointer to the top of the stack in HC.
195 * Stack is allocated from the hypervisor heap and is page aligned
196 * and always writable in GC. */
197 R3PTRTYPE(uint8_t *) pbHCStack;
198 /** Pointer to the bottom of the stack - needed for doing relocations. */
199 RCPTRTYPE(uint8_t *) pbGCStack;
200 /** Pointer to the bottom of the stack - needed for doing relocations. */
201 RCPTRTYPE(uint8_t *) pbGCStackBottom;
202
203 /** Pointer to the GC logger instance - GC Ptr.
204 * This is NULL if logging is disabled. */
205 RCPTRTYPE(PRTLOGGERRC) pLoggerGC;
206 /** Size of the allocated logger instance (pLoggerGC/pLoggerHC). */
207 RTUINT cbLoggerGC;
208 /** Pointer to the GC logger instance - HC Ptr.
209 * This is NULL if logging is disabled. */
210 R3PTRTYPE(PRTLOGGERRC) pLoggerHC;
211
212 /** Pointer to the R0 logger instance.
213 * This is NULL if logging is disabled. */
214 R3R0PTRTYPE(PVMMR0LOGGER) pR0Logger;
215
216#ifdef VBOX_WITH_GC_AND_R0_RELEASE_LOG
217 /** Pointer to the GC release logger instance - GC Ptr. */
218 RCPTRTYPE(PRTLOGGERRC) pRelLoggerGC;
219 /** Size of the allocated release logger instance (pRelLoggerGC/pRelLoggerHC).
220 * This may differ from cbLoggerGC. */
221 RTUINT cbRelLoggerGC;
222 /** Pointer to the GC release logger instance - HC Ptr. */
223 R3PTRTYPE(PRTLOGGERRC) pRelLoggerHC;
224#endif /* VBOX_WITH_GC_AND_R0_RELEASE_LOG */
225
226 /** Global VM critical section. */
227 RTCRITSECT CritSectVMLock;
228
229 /** The EMT yield timer. */
230 PTMTIMERR3 pYieldTimer;
231 /** The period to the next timeout when suspended or stopped.
232 * This is 0 when running. */
233 uint32_t cYieldResumeMillies;
234 /** The EMT yield timer interval (milliseconds). */
235 uint32_t cYieldEveryMillies;
236#if HC_ARCH_BITS == 32
237 uint32_t u32Padding0; /**< Alignment padding. */
238#endif
239 /** The timestamp of the previous yield. (nano) */
240 uint64_t u64LastYield;
241
242 /** @name CallHost
243 * @{ */
244 /** The pending operation. */
245 VMMCALLHOST enmCallHostOperation;
246 /** The result of the last operation. */
247 int32_t rcCallHost;
248 /** The argument to the operation. */
249 uint64_t u64CallHostArg;
250 /** The Ring-0 jmp buffer. */
251 VMMR0JMPBUF CallHostR0JmpBuf;
252 /** Buffer for storing ring 0 assertion output, so we can reroute it to the release log. */
253 char szRing0AssertMsg1[256];
254 char szRing0AssertMsg2[256];
255 /** @} */
256
257 /** Number of VMMR0_DO_RUN_GC calls. */
258 STAMCOUNTER StatRunGC;
259 /** Statistics for each of the GC return codes.
260 * @{ */
261 STAMCOUNTER StatGCRetNormal;
262 STAMCOUNTER StatGCRetInterrupt;
263 STAMCOUNTER StatGCRetInterruptHyper;
264 STAMCOUNTER StatGCRetGuestTrap;
265 STAMCOUNTER StatGCRetRingSwitch;
266 STAMCOUNTER StatGCRetRingSwitchInt;
267 STAMCOUNTER StatGCRetExceptionPrivilege;
268 STAMCOUNTER StatGCRetStaleSelector;
269 STAMCOUNTER StatGCRetIRETTrap;
270 STAMCOUNTER StatGCRetEmulate;
271 STAMCOUNTER StatGCRetPatchEmulate;
272 STAMCOUNTER StatGCRetIORead;
273 STAMCOUNTER StatGCRetIOWrite;
274 STAMCOUNTER StatGCRetMMIORead;
275 STAMCOUNTER StatGCRetMMIOWrite;
276 STAMCOUNTER StatGCRetMMIOPatchRead;
277 STAMCOUNTER StatGCRetMMIOPatchWrite;
278 STAMCOUNTER StatGCRetMMIOReadWrite;
279 STAMCOUNTER StatGCRetLDTFault;
280 STAMCOUNTER StatGCRetGDTFault;
281 STAMCOUNTER StatGCRetIDTFault;
282 STAMCOUNTER StatGCRetTSSFault;
283 STAMCOUNTER StatGCRetPDFault;
284 STAMCOUNTER StatGCRetCSAMTask;
285 STAMCOUNTER StatGCRetSyncCR3;
286 STAMCOUNTER StatGCRetMisc;
287 STAMCOUNTER StatGCRetPatchInt3;
288 STAMCOUNTER StatGCRetPatchPF;
289 STAMCOUNTER StatGCRetPatchGP;
290 STAMCOUNTER StatGCRetPatchIretIRQ;
291 STAMCOUNTER StatGCRetPageOverflow;
292 STAMCOUNTER StatGCRetRescheduleREM;
293 STAMCOUNTER StatGCRetToR3;
294 STAMCOUNTER StatGCRetTimerPending;
295 STAMCOUNTER StatGCRetInterruptPending;
296 STAMCOUNTER StatGCRetCallHost;
297 STAMCOUNTER StatGCRetPATMDuplicateFn;
298 STAMCOUNTER StatGCRetPGMChangeMode;
299 STAMCOUNTER StatGCRetEmulHlt;
300 STAMCOUNTER StatGCRetPendingRequest;
301 STAMCOUNTER StatGCRetPGMGrowRAM;
302 STAMCOUNTER StatGCRetPDMLock;
303 STAMCOUNTER StatGCRetHyperAssertion;
304 STAMCOUNTER StatGCRetLogFlush;
305 STAMCOUNTER StatGCRetPDMQueueFlush;
306 STAMCOUNTER StatGCRetPGMPoolGrow;
307 STAMCOUNTER StatGCRetRemReplay;
308 STAMCOUNTER StatGCRetVMSetError;
309 STAMCOUNTER StatGCRetVMSetRuntimeError;
310 STAMCOUNTER StatGCRetPGMLock;
311
312 /** @} */
313
314
315} VMM, *PVMM;
316
317
318/**
319 * The VMMGCEntry() codes.
320 */
321typedef enum VMMGCOPERATION
322{
323 /** Do GC module init. */
324 VMMGC_DO_VMMGC_INIT = 1,
325
326 /** The first Trap testcase. */
327 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
328 /** Trap 0 testcases, uArg selects the variation. */
329 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
330 /** Trap 1 testcases, uArg selects the variation. */
331 VMMGC_DO_TESTCASE_TRAP_1,
332 /** Trap 2 testcases, uArg selects the variation. */
333 VMMGC_DO_TESTCASE_TRAP_2,
334 /** Trap 3 testcases, uArg selects the variation. */
335 VMMGC_DO_TESTCASE_TRAP_3,
336 /** Trap 4 testcases, uArg selects the variation. */
337 VMMGC_DO_TESTCASE_TRAP_4,
338 /** Trap 5 testcases, uArg selects the variation. */
339 VMMGC_DO_TESTCASE_TRAP_5,
340 /** Trap 6 testcases, uArg selects the variation. */
341 VMMGC_DO_TESTCASE_TRAP_6,
342 /** Trap 7 testcases, uArg selects the variation. */
343 VMMGC_DO_TESTCASE_TRAP_7,
344 /** Trap 8 testcases, uArg selects the variation. */
345 VMMGC_DO_TESTCASE_TRAP_8,
346 /** Trap 9 testcases, uArg selects the variation. */
347 VMMGC_DO_TESTCASE_TRAP_9,
348 /** Trap 0a testcases, uArg selects the variation. */
349 VMMGC_DO_TESTCASE_TRAP_0A,
350 /** Trap 0b testcases, uArg selects the variation. */
351 VMMGC_DO_TESTCASE_TRAP_0B,
352 /** Trap 0c testcases, uArg selects the variation. */
353 VMMGC_DO_TESTCASE_TRAP_0C,
354 /** Trap 0d testcases, uArg selects the variation. */
355 VMMGC_DO_TESTCASE_TRAP_0D,
356 /** Trap 0e testcases, uArg selects the variation. */
357 VMMGC_DO_TESTCASE_TRAP_0E,
358 /** The last trap testcase (exclusive). */
359 VMMGC_DO_TESTCASE_TRAP_LAST,
360 /** Testcase for checking interrupt forwarding. */
361 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
362 /** Switching testing and profiling stub. */
363 VMMGC_DO_TESTCASE_NOP,
364 /** Testcase for checking interrupt masking.. */
365 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
366 /** Switching testing and profiling stub. */
367 VMMGC_DO_TESTCASE_HWACCM_NOP,
368
369 /** The usual 32-bit hack. */
370 VMMGC_DO_32_BIT_HACK = 0x7fffffff
371} VMMGCOPERATION;
372
373
374__BEGIN_DECLS
375
376
377#ifdef IN_RING0
378/**
379 * World switcher assembly routine.
380 * It will call VMMGCEntry().
381 *
382 * @returns return code from VMMGCEntry().
383 * @param pVM The VM in question.
384 * @param uArg See VMMGCEntry().
385 * @internal
386 */
387DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
388
389/**
390 * Callback function for vmmR0CallHostSetJmp.
391 *
392 * @returns VBox status code.
393 * @param pVM The VM handle.
394 */
395typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
396/** Pointer to FNVMMR0SETJMP(). */
397typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
398
399/**
400 * The setjmp variant used for calling Ring-3.
401 *
402 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
403 * in the middle of a ring-3 call. Another differences is the function pointer and
404 * argument. This has to do with resuming code and the stack frame of the caller.
405 *
406 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
407 * @param pJmpBuf The jmp_buf to set.
408 * @param pfn The function to be called when not resuming..
409 * @param pVM The argument of that function.
410 */
411DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
412
413/**
414 * Callback function for vmmR0CallHostSetJmpEx.
415 *
416 * @returns VBox status code.
417 * @param pvUser The user argument.
418 */
419typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
420/** Pointer to FNVMMR0SETJMP(). */
421typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
422
423/**
424 * Same as vmmR0CallHostSetJmp except for the function signature.
425 *
426 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
427 * @param pJmpBuf The jmp_buf to set.
428 * @param pfn The function to be called when not resuming..
429 * @param pvUser The argument of that function.
430 */
431DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
432
433
434/**
435 * Worker for VMMR0CallHost.
436 * This will save the stack and registers.
437 *
438 * @returns rc.
439 * @param pJmpBuf Pointer to the jump buffer.
440 * @param rc The return code.
441 */
442DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
443
444/**
445 * Internal R0 logger worker: Logger wrapper.
446 */
447VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
448
449/**
450 * Internal R0 logger worker: Flush logger.
451 *
452 * @param pLogger The logger instance to flush.
453 * @remark This function must be exported!
454 */
455VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
456
457#endif /* IN_RING0 */
458
459
460#ifdef IN_GC
461/**
462 * Internal GC logger worker: Logger wrapper.
463 */
464VMMGCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
465
466/**
467 * Internal GC release logger worker: Logger wrapper.
468 */
469VMMGCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
470
471/**
472 * Internal GC logger worker: Flush logger.
473 *
474 * @returns VINF_SUCCESS.
475 * @param pLogger The logger instance to flush.
476 * @remark This function must be exported!
477 */
478VMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
479
480/** @name Trap testcases and related labels.
481 * @{ */
482DECLASM(void) vmmGCEnableWP(void);
483DECLASM(void) vmmGCDisableWP(void);
484DECLASM(int) vmmGCTestTrap3(void);
485DECLASM(int) vmmGCTestTrap8(void);
486DECLASM(int) vmmGCTestTrap0d(void);
487DECLASM(int) vmmGCTestTrap0e(void);
488DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
489DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
490/** @} */
491
492#endif /* IN_GC */
493
494__END_DECLS
495
496/** @} */
497
498#endif
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