VirtualBox

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

Last change on this file since 13702 was 13701, checked in by vboxsync, 16 years ago

VMM: some statistics cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.9 KB
Line 
1/* $Id: VMMInternal.h 13701 2008-10-30 23:31:19Z 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_RC)
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_RC_RELEASE_LOGGING
43 * Enables RC release logging. */
44#define VBOX_WITH_RC_RELEASE_LOGGING
45
46/** @def VBOX_WITH_R0_LOGGING
47 * Enables Ring-0 logging (non-release).
48 *
49 * Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup),
50 * so you have to sign up here by adding your defined(DEBUG_<userid>) to the
51 * #if, or by adding VBOX_WITH_R0_LOGGING to your LocalConfig.kmk.
52 *
53 * You might also wish to enable the AssertMsg1/2 overrides in VMMR0.cpp when
54 * enabling this.
55 */
56#if defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(DOXYGEN_RUNNING)
57# define VBOX_WITH_R0_LOGGING
58#endif
59
60
61/**
62 * Converts a VMM pointer into a VM pointer.
63 * @returns Pointer to the VM structure the VMM is part of.
64 * @param pVMM Pointer to VMM instance data.
65 */
66#define VMM2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
67
68
69/**
70 * Switcher function, HC to RC.
71 *
72 * @param pVM The VM handle.
73 * @returns Return code indicating the action to take.
74 */
75typedef DECLASMTYPE(int) FNVMMSWITCHERHC(PVM pVM);
76/** Pointer to switcher function. */
77typedef FNVMMSWITCHERHC *PFNVMMSWITCHERHC;
78
79/**
80 * Switcher function, RC to HC.
81 *
82 * @param rc VBox status code.
83 */
84typedef DECLASMTYPE(void) FNVMMSWITCHERRC(int rc);
85/** Pointer to switcher function. */
86typedef FNVMMSWITCHERRC *PFNVMMSWITCHERRC;
87
88
89/**
90 * The ring-0 logger instance.
91 * We need to be able to find the VM handle from the logger instance.
92 */
93typedef struct VMMR0LOGGER
94{
95 /** Pointer to the VM handle. */
96 R0PTRTYPE(PVM) pVM;
97 /** Size of the allocated logger instance (Logger). */
98 uint32_t cbLogger;
99 /** Flag indicating whether we've create the logger Ring-0 instance yet. */
100 bool fCreated;
101#if HC_ARCH_BITS == 32
102 uint32_t u32Alignment;
103#endif
104 /** The ring-0 logger instance. This extends beyond the size.*/
105 RTLOGGER Logger;
106} VMMR0LOGGER, *PVMMR0LOGGER;
107
108
109/**
110 * Jump buffer for the setjmp/longjmp like constructs used to
111 * quickly 'call' back into Ring-3.
112 */
113typedef struct VMMR0JMPBUF
114{
115 /** Tranditional jmp_buf stuff
116 * @{ */
117#if HC_ARCH_BITS == 32
118 uint32_t ebx;
119 uint32_t esi;
120 uint32_t edi;
121 uint32_t ebp;
122 uint32_t esp;
123 uint32_t eip;
124 uint32_t u32Padding;
125#endif
126#if HC_ARCH_BITS == 64
127 uint64_t rbx;
128# ifdef RT_OS_WINDOWS
129 uint64_t rsi;
130 uint64_t rdi;
131# endif
132 uint64_t rbp;
133 uint64_t r12;
134 uint64_t r13;
135 uint64_t r14;
136 uint64_t r15;
137 uint64_t rsp;
138 uint64_t rip;
139#endif
140 /** @} */
141
142 /** Flag that indicates that we've done a ring-3 call. */
143 bool fInRing3Call;
144 /** The number of bytes we've saved. */
145 uint32_t cbSavedStack;
146 /** Pointer to the buffer used to save the stack.
147 * This is assumed to be 8KB. */
148 RTR0PTR pvSavedStack;
149 /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
150 RTHCUINTREG SpCheck;
151 /** The esp we should resume execution with after the restore. */
152 RTHCUINTREG SpResume;
153} VMMR0JMPBUF;
154/** Pointer to a ring-0 jump buffer. */
155typedef VMMR0JMPBUF *PVMMR0JMPBUF;
156
157
158/**
159 * VMM Data (part of VMM)
160 */
161typedef struct VMM
162{
163 /** Offset to the VM structure.
164 * See VMM2VM(). */
165 RTINT offVM;
166
167 /** Size of the core code. */
168 RTUINT cbCoreCode;
169 /** Physical address of core code. */
170 RTHCPHYS HCPhysCoreCode;
171/** @todo pvHCCoreCodeR3 -> pvCoreCodeR3, pvHCCoreCodeR0 -> pvCoreCodeR0 */
172 /** Pointer to core code ring-3 mapping - contiguous memory.
173 * At present this only means the context switcher code. */
174 RTR3PTR pvHCCoreCodeR3;
175 /** Pointer to core code ring-0 mapping - contiguous memory.
176 * At present this only means the context switcher code. */
177 RTR0PTR pvHCCoreCodeR0;
178 /** Pointer to core code guest context mapping. */
179 RTGCPTR32 pvGCCoreCode;
180#ifdef VBOX_WITH_NMI
181 /** The guest context address of the APIC (host) mapping. */
182 RTGCPTR32 GCPtrApicBase;
183 RTGCPTR32 pGCPadding0; /**< Alignment padding */
184#endif
185 /** The current switcher.
186 * This will be set before the VMM is fully initialized. */
187 VMMSWITCHER enmSwitcher;
188 /** Array of offsets to the different switchers within the core code. */
189 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
190 /** Flag to disable the switcher permanently (VMX) (boolean) */
191 bool fSwitcherDisabled;
192
193 /** Host to guest switcher entry point. */
194 R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0HostToGuest;
195 /** Guest to host switcher entry point. */
196 RCPTRTYPE(PFNVMMSWITCHERRC) pfnGCGuestToHost;
197 /** Call Trampoline. See vmmGCCallTrampoline(). */
198 RTGCPTR32 pfnGCCallTrampoline;
199
200 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
201 RTGCPTR32 pfnCPUMGCResumeGuest;
202 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
203 RTGCPTR32 pfnCPUMGCResumeGuestV86;
204 /** The last GC return code. */
205 RTINT iLastGCRc;
206#if HC_ARCH_BITS == 64
207 uint32_t u32Padding0; /**< Alignment padding. */
208#endif
209
210 /** VMM stack, pointer to the top of the stack in R3.
211 * Stack is allocated from the hypervisor heap and is page aligned
212 * and always writable in RC. */
213 R3PTRTYPE(uint8_t *) pbEMTStackR3;
214 /** Pointer to the bottom of the stack - needed for doing relocations. */
215 RCPTRTYPE(uint8_t *) pbEMTStackRC;
216 /** Pointer to the bottom of the stack - needed for doing relocations. */
217 RCPTRTYPE(uint8_t *) pbEMTStackBottomRC;
218
219 /** Pointer to the GC logger instance - GC Ptr.
220 * This is NULL if logging is disabled. */
221 RCPTRTYPE(PRTLOGGERRC) pLoggerGC;
222 /** Size of the allocated logger instance (pLoggerGC/pLoggerHC). */
223 RTUINT cbLoggerGC;
224 /** Pointer to the GC logger instance - HC Ptr.
225 * This is NULL if logging is disabled. */
226 R3PTRTYPE(PRTLOGGERRC) pLoggerHC;
227
228 /** Pointer to the R0 logger instance.
229 * This is NULL if logging is disabled. */
230 R3R0PTRTYPE(PVMMR0LOGGER) pR0Logger;
231
232#ifdef VBOX_WITH_RC_RELEASE_LOGGING
233 /** Pointer to the GC release logger instance - GC Ptr. */
234 RCPTRTYPE(PRTLOGGERRC) pRelLoggerGC;
235 /** Size of the allocated release logger instance (pRelLoggerGC/pRelLoggerHC).
236 * This may differ from cbLoggerGC. */
237 RTUINT cbRelLoggerGC;
238 /** Pointer to the GC release logger instance - HC Ptr. */
239 R3PTRTYPE(PRTLOGGERRC) pRelLoggerHC;
240#endif /* VBOX_WITH_RC_RELEASE_LOGGING */
241
242 /** Global VM critical section. */
243 RTCRITSECT CritSectVMLock;
244
245 /** The EMT yield timer. */
246 PTMTIMERR3 pYieldTimer;
247 /** The period to the next timeout when suspended or stopped.
248 * This is 0 when running. */
249 uint32_t cYieldResumeMillies;
250 /** The EMT yield timer interval (milliseconds). */
251 uint32_t cYieldEveryMillies;
252#if HC_ARCH_BITS == 32
253 uint32_t u32Padding0; /**< Alignment padding. */
254#endif
255 /** The timestamp of the previous yield. (nano) */
256 uint64_t u64LastYield;
257
258 /** @name CallHost
259 * @todo SMP: per vCPU
260 * @{ */
261 /** The pending operation. */
262 VMMCALLHOST enmCallHostOperation;
263 /** The result of the last operation. */
264 int32_t rcCallHost;
265 /** The argument to the operation. */
266 uint64_t u64CallHostArg;
267 /** The Ring-0 jmp buffer. */
268 VMMR0JMPBUF CallHostR0JmpBuf;
269 /** @} */
270
271 /** Buffer for storing the standard assertion message for a ring-0 assertion.
272 * Used for saving the assertion message text for the release log and guru
273 * meditation dump. */
274 char szRing0AssertMsg1[256];
275 /** Buffer for storing the custom message for a ring-0 assertion. */
276 char szRing0AssertMsg2[256];
277
278 /** Number of VMMR0_DO_RUN_GC calls. */
279 STAMCOUNTER StatRunRC;
280
281 /** Statistics for each of the RC/R0 return codes.
282 * @{ */
283 STAMCOUNTER StatRZRetNormal;
284 STAMCOUNTER StatRZRetInterrupt;
285 STAMCOUNTER StatRZRetInterruptHyper;
286 STAMCOUNTER StatRZRetGuestTrap;
287 STAMCOUNTER StatRZRetRingSwitch;
288 STAMCOUNTER StatRZRetRingSwitchInt;
289 STAMCOUNTER StatRZRetExceptionPrivilege;
290 STAMCOUNTER StatRZRetStaleSelector;
291 STAMCOUNTER StatRZRetIRETTrap;
292 STAMCOUNTER StatRZRetEmulate;
293 STAMCOUNTER StatRZRetPatchEmulate;
294 STAMCOUNTER StatRZRetIORead;
295 STAMCOUNTER StatRZRetIOWrite;
296 STAMCOUNTER StatRZRetMMIORead;
297 STAMCOUNTER StatRZRetMMIOWrite;
298 STAMCOUNTER StatRZRetMMIOPatchRead;
299 STAMCOUNTER StatRZRetMMIOPatchWrite;
300 STAMCOUNTER StatRZRetMMIOReadWrite;
301 STAMCOUNTER StatRZRetLDTFault;
302 STAMCOUNTER StatRZRetGDTFault;
303 STAMCOUNTER StatRZRetIDTFault;
304 STAMCOUNTER StatRZRetTSSFault;
305 STAMCOUNTER StatRZRetPDFault;
306 STAMCOUNTER StatRZRetCSAMTask;
307 STAMCOUNTER StatRZRetSyncCR3;
308 STAMCOUNTER StatRZRetMisc;
309 STAMCOUNTER StatRZRetPatchInt3;
310 STAMCOUNTER StatRZRetPatchPF;
311 STAMCOUNTER StatRZRetPatchGP;
312 STAMCOUNTER StatRZRetPatchIretIRQ;
313 STAMCOUNTER StatRZRetPageOverflow;
314 STAMCOUNTER StatRZRetRescheduleREM;
315 STAMCOUNTER StatRZRetToR3;
316 STAMCOUNTER StatRZRetTimerPending;
317 STAMCOUNTER StatRZRetInterruptPending;
318 STAMCOUNTER StatRZRetCallHost;
319 STAMCOUNTER StatRZRetPATMDuplicateFn;
320 STAMCOUNTER StatRZRetPGMChangeMode;
321 STAMCOUNTER StatRZRetEmulHlt;
322 STAMCOUNTER StatRZRetPendingRequest;
323#ifndef VBOX_WITH_NEW_PHYS_CODE
324 STAMCOUNTER StatRZCallPGMGrowRAM;
325#endif
326 STAMCOUNTER StatRZCallPDMLock;
327 STAMCOUNTER StatRZCallLogFlush;
328 STAMCOUNTER StatRZCallPDMQueueFlush;
329 STAMCOUNTER StatRZCallPGMPoolGrow;
330 STAMCOUNTER StatRZCallPGMMapChunk;
331 STAMCOUNTER StatRZCallPGMAllocHandy;
332 STAMCOUNTER StatRZCallRemReplay;
333 STAMCOUNTER StatRZCallVMSetError;
334 STAMCOUNTER StatRZCallVMSetRuntimeError;
335 STAMCOUNTER StatRZCallPGMLock;
336 /** @} */
337} VMM;
338/** Pointer to VMM. */
339typedef VMM *PVMM;
340
341
342/**
343 * The VMMGCEntry() codes.
344 */
345typedef enum VMMGCOPERATION
346{
347 /** Do GC module init. */
348 VMMGC_DO_VMMGC_INIT = 1,
349
350 /** The first Trap testcase. */
351 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
352 /** Trap 0 testcases, uArg selects the variation. */
353 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
354 /** Trap 1 testcases, uArg selects the variation. */
355 VMMGC_DO_TESTCASE_TRAP_1,
356 /** Trap 2 testcases, uArg selects the variation. */
357 VMMGC_DO_TESTCASE_TRAP_2,
358 /** Trap 3 testcases, uArg selects the variation. */
359 VMMGC_DO_TESTCASE_TRAP_3,
360 /** Trap 4 testcases, uArg selects the variation. */
361 VMMGC_DO_TESTCASE_TRAP_4,
362 /** Trap 5 testcases, uArg selects the variation. */
363 VMMGC_DO_TESTCASE_TRAP_5,
364 /** Trap 6 testcases, uArg selects the variation. */
365 VMMGC_DO_TESTCASE_TRAP_6,
366 /** Trap 7 testcases, uArg selects the variation. */
367 VMMGC_DO_TESTCASE_TRAP_7,
368 /** Trap 8 testcases, uArg selects the variation. */
369 VMMGC_DO_TESTCASE_TRAP_8,
370 /** Trap 9 testcases, uArg selects the variation. */
371 VMMGC_DO_TESTCASE_TRAP_9,
372 /** Trap 0a testcases, uArg selects the variation. */
373 VMMGC_DO_TESTCASE_TRAP_0A,
374 /** Trap 0b testcases, uArg selects the variation. */
375 VMMGC_DO_TESTCASE_TRAP_0B,
376 /** Trap 0c testcases, uArg selects the variation. */
377 VMMGC_DO_TESTCASE_TRAP_0C,
378 /** Trap 0d testcases, uArg selects the variation. */
379 VMMGC_DO_TESTCASE_TRAP_0D,
380 /** Trap 0e testcases, uArg selects the variation. */
381 VMMGC_DO_TESTCASE_TRAP_0E,
382 /** The last trap testcase (exclusive). */
383 VMMGC_DO_TESTCASE_TRAP_LAST,
384 /** Testcase for checking interrupt forwarding. */
385 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
386 /** Switching testing and profiling stub. */
387 VMMGC_DO_TESTCASE_NOP,
388 /** Testcase for checking interrupt masking.. */
389 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
390 /** Switching testing and profiling stub. */
391 VMMGC_DO_TESTCASE_HWACCM_NOP,
392
393 /** The usual 32-bit hack. */
394 VMMGC_DO_32_BIT_HACK = 0x7fffffff
395} VMMGCOPERATION;
396
397
398__BEGIN_DECLS
399
400
401#ifdef IN_RING0
402/**
403 * World switcher assembly routine.
404 * It will call VMMGCEntry().
405 *
406 * @returns return code from VMMGCEntry().
407 * @param pVM The VM in question.
408 * @param uArg See VMMGCEntry().
409 * @internal
410 */
411DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
412
413/**
414 * Callback function for vmmR0CallHostSetJmp.
415 *
416 * @returns VBox status code.
417 * @param pVM The VM handle.
418 */
419typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
420/** Pointer to FNVMMR0SETJMP(). */
421typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
422
423/**
424 * The setjmp variant used for calling Ring-3.
425 *
426 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
427 * in the middle of a ring-3 call. Another differences is the function pointer and
428 * argument. This has to do with resuming code and the stack frame of the caller.
429 *
430 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
431 * @param pJmpBuf The jmp_buf to set.
432 * @param pfn The function to be called when not resuming..
433 * @param pVM The argument of that function.
434 */
435DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
436
437/**
438 * Callback function for vmmR0CallHostSetJmpEx.
439 *
440 * @returns VBox status code.
441 * @param pvUser The user argument.
442 */
443typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
444/** Pointer to FNVMMR0SETJMP(). */
445typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
446
447/**
448 * Same as vmmR0CallHostSetJmp except for the function signature.
449 *
450 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
451 * @param pJmpBuf The jmp_buf to set.
452 * @param pfn The function to be called when not resuming..
453 * @param pvUser The argument of that function.
454 */
455DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
456
457
458/**
459 * Worker for VMMR0CallHost.
460 * This will save the stack and registers.
461 *
462 * @returns rc.
463 * @param pJmpBuf Pointer to the jump buffer.
464 * @param rc The return code.
465 */
466DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
467
468/**
469 * Internal R0 logger worker: Logger wrapper.
470 */
471VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
472
473/**
474 * Internal R0 logger worker: Flush logger.
475 *
476 * @param pLogger The logger instance to flush.
477 * @remark This function must be exported!
478 */
479VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
480
481#endif /* IN_RING0 */
482#ifdef IN_GC
483
484/**
485 * Internal GC logger worker: Logger wrapper.
486 */
487VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
488
489/**
490 * Internal GC release logger worker: Logger wrapper.
491 */
492VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
493
494/**
495 * Internal GC logger worker: Flush logger.
496 *
497 * @returns VINF_SUCCESS.
498 * @param pLogger The logger instance to flush.
499 * @remark This function must be exported!
500 */
501VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
502
503/** @name Trap testcases and related labels.
504 * @{ */
505DECLASM(void) vmmGCEnableWP(void);
506DECLASM(void) vmmGCDisableWP(void);
507DECLASM(int) vmmGCTestTrap3(void);
508DECLASM(int) vmmGCTestTrap8(void);
509DECLASM(int) vmmGCTestTrap0d(void);
510DECLASM(int) vmmGCTestTrap0e(void);
511DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
512DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
513/** @} */
514
515#endif /* IN_GC */
516
517__END_DECLS
518
519/** @} */
520
521#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