VirtualBox

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

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

VMM: cleanup in progress.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.3 KB
Line 
1/* $Id: VMMInternal.h 13697 2008-10-30 22:13:25Z 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.
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, GC to HC.
81 *
82 * @param rc VBox status code.
83 */
84typedef DECLASMTYPE(void) FNVMMSWITCHERGC(int rc);
85/** Pointer to switcher function. */
86typedef FNVMMSWITCHERGC *PFNVMMSWITCHERGC;
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, *PVMMR0JMPBUF;
154
155
156/**
157 * VMM Data (part of VMM)
158 */
159typedef struct VMM
160{
161 /** Offset to the VM structure.
162 * See VMM2VM(). */
163 RTINT offVM;
164
165 /** Size of the core code. */
166 RTUINT cbCoreCode;
167 /** Physical address of core code. */
168 RTHCPHYS HCPhysCoreCode;
169/** @todo pvHCCoreCodeR3 -> pvCoreCodeR3, pvHCCoreCodeR0 -> pvCoreCodeR0 */
170 /** Pointer to core code ring-3 mapping - contiguous memory.
171 * At present this only means the context switcher code. */
172 RTR3PTR pvHCCoreCodeR3;
173 /** Pointer to core code ring-0 mapping - contiguous memory.
174 * At present this only means the context switcher code. */
175 RTR0PTR pvHCCoreCodeR0;
176 /** Pointer to core code guest context mapping. */
177 RTGCPTR32 pvGCCoreCode;
178#ifdef VBOX_WITH_NMI
179 /** The guest context address of the APIC (host) mapping. */
180 RTGCPTR32 GCPtrApicBase;
181 RTGCPTR32 pGCPadding0; /**< Alignment padding */
182#endif
183 /** The current switcher.
184 * This will be set before the VMM is fully initialized. */
185 VMMSWITCHER enmSwitcher;
186 /** Array of offsets to the different switchers within the core code. */
187 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
188 /** Flag to disable the switcher permanently (VMX) (boolean) */
189 bool fSwitcherDisabled;
190
191 /** Host to guest switcher entry point. */
192 R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0HostToGuest;
193 /** Guest to host switcher entry point. */
194 RCPTRTYPE(PFNVMMSWITCHERGC) pfnGCGuestToHost;
195 /** Call Trampoline. See vmmGCCallTrampoline(). */
196 RTGCPTR32 pfnGCCallTrampoline;
197
198 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
199 RTGCPTR32 pfnCPUMGCResumeGuest;
200 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
201 RTGCPTR32 pfnCPUMGCResumeGuestV86;
202 /** The last GC return code. */
203 RTINT iLastGCRc;
204#if HC_ARCH_BITS == 64
205 uint32_t u32Padding0; /**< Alignment padding. */
206#endif
207
208 /** VMM stack, pointer to the top of the stack in HC.
209 * Stack is allocated from the hypervisor heap and is page aligned
210 * and always writable in GC. */
211 R3PTRTYPE(uint8_t *) pbHCStack;
212 /** Pointer to the bottom of the stack - needed for doing relocations. */
213 RCPTRTYPE(uint8_t *) pbGCStack;
214 /** Pointer to the bottom of the stack - needed for doing relocations. */
215 RCPTRTYPE(uint8_t *) pbGCStackBottom;
216
217 /** Pointer to the GC logger instance - GC Ptr.
218 * This is NULL if logging is disabled. */
219 RCPTRTYPE(PRTLOGGERRC) pLoggerGC;
220 /** Size of the allocated logger instance (pLoggerGC/pLoggerHC). */
221 RTUINT cbLoggerGC;
222 /** Pointer to the GC logger instance - HC Ptr.
223 * This is NULL if logging is disabled. */
224 R3PTRTYPE(PRTLOGGERRC) pLoggerHC;
225
226 /** Pointer to the R0 logger instance.
227 * This is NULL if logging is disabled. */
228 R3R0PTRTYPE(PVMMR0LOGGER) pR0Logger;
229
230#ifdef VBOX_WITH_RC_RELEASE_LOGGING
231 /** Pointer to the GC release logger instance - GC Ptr. */
232 RCPTRTYPE(PRTLOGGERRC) pRelLoggerGC;
233 /** Size of the allocated release logger instance (pRelLoggerGC/pRelLoggerHC).
234 * This may differ from cbLoggerGC. */
235 RTUINT cbRelLoggerGC;
236 /** Pointer to the GC release logger instance - HC Ptr. */
237 R3PTRTYPE(PRTLOGGERRC) pRelLoggerHC;
238#endif /* VBOX_WITH_RC_RELEASE_LOGGING */
239
240 /** Global VM critical section. */
241 RTCRITSECT CritSectVMLock;
242
243 /** The EMT yield timer. */
244 PTMTIMERR3 pYieldTimer;
245 /** The period to the next timeout when suspended or stopped.
246 * This is 0 when running. */
247 uint32_t cYieldResumeMillies;
248 /** The EMT yield timer interval (milliseconds). */
249 uint32_t cYieldEveryMillies;
250#if HC_ARCH_BITS == 32
251 uint32_t u32Padding0; /**< Alignment padding. */
252#endif
253 /** The timestamp of the previous yield. (nano) */
254 uint64_t u64LastYield;
255
256 /** @name CallHost
257 * @{ */
258 /** The pending operation. */
259 VMMCALLHOST enmCallHostOperation;
260 /** The result of the last operation. */
261 int32_t rcCallHost;
262 /** The argument to the operation. */
263 uint64_t u64CallHostArg;
264 /** The Ring-0 jmp buffer. */
265 VMMR0JMPBUF CallHostR0JmpBuf;
266 /** @} */
267
268 /** Buffer for storing the standard assertion message for a ring-0 assertion.
269 * Used for saving the assertion message text for the release log and guru
270 * meditation dump. */
271 char szRing0AssertMsg1[256];
272 /** Buffer for storing the custom message for a ring-0 assertion. */
273 char szRing0AssertMsg2[256];
274
275 /** Number of VMMR0_DO_RUN_GC calls. */
276 STAMCOUNTER StatRunGC;
277
278 /** Statistics for each of the GC return codes.
279 * @{ */
280 STAMCOUNTER StatGCRetNormal;
281 STAMCOUNTER StatGCRetInterrupt;
282 STAMCOUNTER StatGCRetInterruptHyper;
283 STAMCOUNTER StatGCRetGuestTrap;
284 STAMCOUNTER StatGCRetRingSwitch;
285 STAMCOUNTER StatGCRetRingSwitchInt;
286 STAMCOUNTER StatGCRetExceptionPrivilege;
287 STAMCOUNTER StatGCRetStaleSelector;
288 STAMCOUNTER StatGCRetIRETTrap;
289 STAMCOUNTER StatGCRetEmulate;
290 STAMCOUNTER StatGCRetPatchEmulate;
291 STAMCOUNTER StatGCRetIORead;
292 STAMCOUNTER StatGCRetIOWrite;
293 STAMCOUNTER StatGCRetMMIORead;
294 STAMCOUNTER StatGCRetMMIOWrite;
295 STAMCOUNTER StatGCRetMMIOPatchRead;
296 STAMCOUNTER StatGCRetMMIOPatchWrite;
297 STAMCOUNTER StatGCRetMMIOReadWrite;
298 STAMCOUNTER StatGCRetLDTFault;
299 STAMCOUNTER StatGCRetGDTFault;
300 STAMCOUNTER StatGCRetIDTFault;
301 STAMCOUNTER StatGCRetTSSFault;
302 STAMCOUNTER StatGCRetPDFault;
303 STAMCOUNTER StatGCRetCSAMTask;
304 STAMCOUNTER StatGCRetSyncCR3;
305 STAMCOUNTER StatGCRetMisc;
306 STAMCOUNTER StatGCRetPatchInt3;
307 STAMCOUNTER StatGCRetPatchPF;
308 STAMCOUNTER StatGCRetPatchGP;
309 STAMCOUNTER StatGCRetPatchIretIRQ;
310 STAMCOUNTER StatGCRetPageOverflow;
311 STAMCOUNTER StatGCRetRescheduleREM;
312 STAMCOUNTER StatGCRetToR3;
313 STAMCOUNTER StatGCRetTimerPending;
314 STAMCOUNTER StatGCRetInterruptPending;
315 STAMCOUNTER StatGCRetCallHost;
316 STAMCOUNTER StatGCRetPATMDuplicateFn;
317 STAMCOUNTER StatGCRetPGMChangeMode;
318 STAMCOUNTER StatGCRetEmulHlt;
319 STAMCOUNTER StatGCRetPendingRequest;
320 STAMCOUNTER StatGCRetPGMGrowRAM;
321 STAMCOUNTER StatGCRetPDMLock;
322 STAMCOUNTER StatGCRetHyperAssertion;
323 STAMCOUNTER StatGCRetLogFlush;
324 STAMCOUNTER StatGCRetPDMQueueFlush;
325 STAMCOUNTER StatGCRetPGMPoolGrow;
326 STAMCOUNTER StatGCRetRemReplay;
327 STAMCOUNTER StatGCRetVMSetError;
328 STAMCOUNTER StatGCRetVMSetRuntimeError;
329 STAMCOUNTER StatGCRetPGMLock;
330 /** @} */
331
332
333} VMM, *PVMM;
334
335
336/**
337 * The VMMGCEntry() codes.
338 */
339typedef enum VMMGCOPERATION
340{
341 /** Do GC module init. */
342 VMMGC_DO_VMMGC_INIT = 1,
343
344 /** The first Trap testcase. */
345 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
346 /** Trap 0 testcases, uArg selects the variation. */
347 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
348 /** Trap 1 testcases, uArg selects the variation. */
349 VMMGC_DO_TESTCASE_TRAP_1,
350 /** Trap 2 testcases, uArg selects the variation. */
351 VMMGC_DO_TESTCASE_TRAP_2,
352 /** Trap 3 testcases, uArg selects the variation. */
353 VMMGC_DO_TESTCASE_TRAP_3,
354 /** Trap 4 testcases, uArg selects the variation. */
355 VMMGC_DO_TESTCASE_TRAP_4,
356 /** Trap 5 testcases, uArg selects the variation. */
357 VMMGC_DO_TESTCASE_TRAP_5,
358 /** Trap 6 testcases, uArg selects the variation. */
359 VMMGC_DO_TESTCASE_TRAP_6,
360 /** Trap 7 testcases, uArg selects the variation. */
361 VMMGC_DO_TESTCASE_TRAP_7,
362 /** Trap 8 testcases, uArg selects the variation. */
363 VMMGC_DO_TESTCASE_TRAP_8,
364 /** Trap 9 testcases, uArg selects the variation. */
365 VMMGC_DO_TESTCASE_TRAP_9,
366 /** Trap 0a testcases, uArg selects the variation. */
367 VMMGC_DO_TESTCASE_TRAP_0A,
368 /** Trap 0b testcases, uArg selects the variation. */
369 VMMGC_DO_TESTCASE_TRAP_0B,
370 /** Trap 0c testcases, uArg selects the variation. */
371 VMMGC_DO_TESTCASE_TRAP_0C,
372 /** Trap 0d testcases, uArg selects the variation. */
373 VMMGC_DO_TESTCASE_TRAP_0D,
374 /** Trap 0e testcases, uArg selects the variation. */
375 VMMGC_DO_TESTCASE_TRAP_0E,
376 /** The last trap testcase (exclusive). */
377 VMMGC_DO_TESTCASE_TRAP_LAST,
378 /** Testcase for checking interrupt forwarding. */
379 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
380 /** Switching testing and profiling stub. */
381 VMMGC_DO_TESTCASE_NOP,
382 /** Testcase for checking interrupt masking.. */
383 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
384 /** Switching testing and profiling stub. */
385 VMMGC_DO_TESTCASE_HWACCM_NOP,
386
387 /** The usual 32-bit hack. */
388 VMMGC_DO_32_BIT_HACK = 0x7fffffff
389} VMMGCOPERATION;
390
391
392__BEGIN_DECLS
393
394
395#ifdef IN_RING0
396/**
397 * World switcher assembly routine.
398 * It will call VMMGCEntry().
399 *
400 * @returns return code from VMMGCEntry().
401 * @param pVM The VM in question.
402 * @param uArg See VMMGCEntry().
403 * @internal
404 */
405DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
406
407/**
408 * Callback function for vmmR0CallHostSetJmp.
409 *
410 * @returns VBox status code.
411 * @param pVM The VM handle.
412 */
413typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
414/** Pointer to FNVMMR0SETJMP(). */
415typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
416
417/**
418 * The setjmp variant used for calling Ring-3.
419 *
420 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
421 * in the middle of a ring-3 call. Another differences is the function pointer and
422 * argument. This has to do with resuming code and the stack frame of the caller.
423 *
424 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
425 * @param pJmpBuf The jmp_buf to set.
426 * @param pfn The function to be called when not resuming..
427 * @param pVM The argument of that function.
428 */
429DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
430
431/**
432 * Callback function for vmmR0CallHostSetJmpEx.
433 *
434 * @returns VBox status code.
435 * @param pvUser The user argument.
436 */
437typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
438/** Pointer to FNVMMR0SETJMP(). */
439typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
440
441/**
442 * Same as vmmR0CallHostSetJmp except for the function signature.
443 *
444 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
445 * @param pJmpBuf The jmp_buf to set.
446 * @param pfn The function to be called when not resuming..
447 * @param pvUser The argument of that function.
448 */
449DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
450
451
452/**
453 * Worker for VMMR0CallHost.
454 * This will save the stack and registers.
455 *
456 * @returns rc.
457 * @param pJmpBuf Pointer to the jump buffer.
458 * @param rc The return code.
459 */
460DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
461
462/**
463 * Internal R0 logger worker: Logger wrapper.
464 */
465VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
466
467/**
468 * Internal R0 logger worker: Flush logger.
469 *
470 * @param pLogger The logger instance to flush.
471 * @remark This function must be exported!
472 */
473VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
474
475#endif /* IN_RING0 */
476
477
478#ifdef IN_GC
479/**
480 * Internal GC logger worker: Logger wrapper.
481 */
482VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
483
484/**
485 * Internal GC release logger worker: Logger wrapper.
486 */
487VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
488
489/**
490 * Internal GC logger worker: Flush logger.
491 *
492 * @returns VINF_SUCCESS.
493 * @param pLogger The logger instance to flush.
494 * @remark This function must be exported!
495 */
496VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
497
498/** @name Trap testcases and related labels.
499 * @{ */
500DECLASM(void) vmmGCEnableWP(void);
501DECLASM(void) vmmGCDisableWP(void);
502DECLASM(int) vmmGCTestTrap3(void);
503DECLASM(int) vmmGCTestTrap8(void);
504DECLASM(int) vmmGCTestTrap0d(void);
505DECLASM(int) vmmGCTestTrap0e(void);
506DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
507DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
508/** @} */
509
510#endif /* IN_GC */
511
512__END_DECLS
513
514/** @} */
515
516#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