VirtualBox

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

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

VMM + VBox/cdefs.h: consolidated all the XYZ*DECLS of the VMM into VMM*DECL. Removed dead DECL and IN_XYZ* macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.9 KB
Line 
1/* $Id: VMMInternal.h 12989 2008-10-06 02:15:39Z 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_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 /** @} */
253
254 /** Buffer for storing the standard assertion message for a ring-0 assertion.
255 * Used for saving the assertion message text for the release log and guru
256 * meditation dump. */
257 char szRing0AssertMsg1[256];
258 /** Buffer for storing the custom message for a ring-0 assertion. */
259 char szRing0AssertMsg2[256];
260
261 /** Number of VMMR0_DO_RUN_GC calls. */
262 STAMCOUNTER StatRunGC;
263 /** Statistics for each of the GC return codes.
264 * @{ */
265 STAMCOUNTER StatGCRetNormal;
266 STAMCOUNTER StatGCRetInterrupt;
267 STAMCOUNTER StatGCRetInterruptHyper;
268 STAMCOUNTER StatGCRetGuestTrap;
269 STAMCOUNTER StatGCRetRingSwitch;
270 STAMCOUNTER StatGCRetRingSwitchInt;
271 STAMCOUNTER StatGCRetExceptionPrivilege;
272 STAMCOUNTER StatGCRetStaleSelector;
273 STAMCOUNTER StatGCRetIRETTrap;
274 STAMCOUNTER StatGCRetEmulate;
275 STAMCOUNTER StatGCRetPatchEmulate;
276 STAMCOUNTER StatGCRetIORead;
277 STAMCOUNTER StatGCRetIOWrite;
278 STAMCOUNTER StatGCRetMMIORead;
279 STAMCOUNTER StatGCRetMMIOWrite;
280 STAMCOUNTER StatGCRetMMIOPatchRead;
281 STAMCOUNTER StatGCRetMMIOPatchWrite;
282 STAMCOUNTER StatGCRetMMIOReadWrite;
283 STAMCOUNTER StatGCRetLDTFault;
284 STAMCOUNTER StatGCRetGDTFault;
285 STAMCOUNTER StatGCRetIDTFault;
286 STAMCOUNTER StatGCRetTSSFault;
287 STAMCOUNTER StatGCRetPDFault;
288 STAMCOUNTER StatGCRetCSAMTask;
289 STAMCOUNTER StatGCRetSyncCR3;
290 STAMCOUNTER StatGCRetMisc;
291 STAMCOUNTER StatGCRetPatchInt3;
292 STAMCOUNTER StatGCRetPatchPF;
293 STAMCOUNTER StatGCRetPatchGP;
294 STAMCOUNTER StatGCRetPatchIretIRQ;
295 STAMCOUNTER StatGCRetPageOverflow;
296 STAMCOUNTER StatGCRetRescheduleREM;
297 STAMCOUNTER StatGCRetToR3;
298 STAMCOUNTER StatGCRetTimerPending;
299 STAMCOUNTER StatGCRetInterruptPending;
300 STAMCOUNTER StatGCRetCallHost;
301 STAMCOUNTER StatGCRetPATMDuplicateFn;
302 STAMCOUNTER StatGCRetPGMChangeMode;
303 STAMCOUNTER StatGCRetEmulHlt;
304 STAMCOUNTER StatGCRetPendingRequest;
305 STAMCOUNTER StatGCRetPGMGrowRAM;
306 STAMCOUNTER StatGCRetPDMLock;
307 STAMCOUNTER StatGCRetHyperAssertion;
308 STAMCOUNTER StatGCRetLogFlush;
309 STAMCOUNTER StatGCRetPDMQueueFlush;
310 STAMCOUNTER StatGCRetPGMPoolGrow;
311 STAMCOUNTER StatGCRetRemReplay;
312 STAMCOUNTER StatGCRetVMSetError;
313 STAMCOUNTER StatGCRetVMSetRuntimeError;
314 STAMCOUNTER StatGCRetPGMLock;
315
316 /** @} */
317
318
319} VMM, *PVMM;
320
321
322/**
323 * The VMMGCEntry() codes.
324 */
325typedef enum VMMGCOPERATION
326{
327 /** Do GC module init. */
328 VMMGC_DO_VMMGC_INIT = 1,
329
330 /** The first Trap testcase. */
331 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
332 /** Trap 0 testcases, uArg selects the variation. */
333 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
334 /** Trap 1 testcases, uArg selects the variation. */
335 VMMGC_DO_TESTCASE_TRAP_1,
336 /** Trap 2 testcases, uArg selects the variation. */
337 VMMGC_DO_TESTCASE_TRAP_2,
338 /** Trap 3 testcases, uArg selects the variation. */
339 VMMGC_DO_TESTCASE_TRAP_3,
340 /** Trap 4 testcases, uArg selects the variation. */
341 VMMGC_DO_TESTCASE_TRAP_4,
342 /** Trap 5 testcases, uArg selects the variation. */
343 VMMGC_DO_TESTCASE_TRAP_5,
344 /** Trap 6 testcases, uArg selects the variation. */
345 VMMGC_DO_TESTCASE_TRAP_6,
346 /** Trap 7 testcases, uArg selects the variation. */
347 VMMGC_DO_TESTCASE_TRAP_7,
348 /** Trap 8 testcases, uArg selects the variation. */
349 VMMGC_DO_TESTCASE_TRAP_8,
350 /** Trap 9 testcases, uArg selects the variation. */
351 VMMGC_DO_TESTCASE_TRAP_9,
352 /** Trap 0a testcases, uArg selects the variation. */
353 VMMGC_DO_TESTCASE_TRAP_0A,
354 /** Trap 0b testcases, uArg selects the variation. */
355 VMMGC_DO_TESTCASE_TRAP_0B,
356 /** Trap 0c testcases, uArg selects the variation. */
357 VMMGC_DO_TESTCASE_TRAP_0C,
358 /** Trap 0d testcases, uArg selects the variation. */
359 VMMGC_DO_TESTCASE_TRAP_0D,
360 /** Trap 0e testcases, uArg selects the variation. */
361 VMMGC_DO_TESTCASE_TRAP_0E,
362 /** The last trap testcase (exclusive). */
363 VMMGC_DO_TESTCASE_TRAP_LAST,
364 /** Testcase for checking interrupt forwarding. */
365 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
366 /** Switching testing and profiling stub. */
367 VMMGC_DO_TESTCASE_NOP,
368 /** Testcase for checking interrupt masking.. */
369 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
370 /** Switching testing and profiling stub. */
371 VMMGC_DO_TESTCASE_HWACCM_NOP,
372
373 /** The usual 32-bit hack. */
374 VMMGC_DO_32_BIT_HACK = 0x7fffffff
375} VMMGCOPERATION;
376
377
378__BEGIN_DECLS
379
380
381#ifdef IN_RING0
382/**
383 * World switcher assembly routine.
384 * It will call VMMGCEntry().
385 *
386 * @returns return code from VMMGCEntry().
387 * @param pVM The VM in question.
388 * @param uArg See VMMGCEntry().
389 * @internal
390 */
391DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
392
393/**
394 * Callback function for vmmR0CallHostSetJmp.
395 *
396 * @returns VBox status code.
397 * @param pVM The VM handle.
398 */
399typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
400/** Pointer to FNVMMR0SETJMP(). */
401typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
402
403/**
404 * The setjmp variant used for calling Ring-3.
405 *
406 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
407 * in the middle of a ring-3 call. Another differences is the function pointer and
408 * argument. This has to do with resuming code and the stack frame of the caller.
409 *
410 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
411 * @param pJmpBuf The jmp_buf to set.
412 * @param pfn The function to be called when not resuming..
413 * @param pVM The argument of that function.
414 */
415DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
416
417/**
418 * Callback function for vmmR0CallHostSetJmpEx.
419 *
420 * @returns VBox status code.
421 * @param pvUser The user argument.
422 */
423typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
424/** Pointer to FNVMMR0SETJMP(). */
425typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
426
427/**
428 * Same as vmmR0CallHostSetJmp except for the function signature.
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 pvUser The argument of that function.
434 */
435DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
436
437
438/**
439 * Worker for VMMR0CallHost.
440 * This will save the stack and registers.
441 *
442 * @returns rc.
443 * @param pJmpBuf Pointer to the jump buffer.
444 * @param rc The return code.
445 */
446DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
447
448/**
449 * Internal R0 logger worker: Logger wrapper.
450 */
451VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
452
453/**
454 * Internal R0 logger worker: Flush logger.
455 *
456 * @param pLogger The logger instance to flush.
457 * @remark This function must be exported!
458 */
459VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
460
461#endif /* IN_RING0 */
462
463
464#ifdef IN_GC
465/**
466 * Internal GC logger worker: Logger wrapper.
467 */
468VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
469
470/**
471 * Internal GC release logger worker: Logger wrapper.
472 */
473VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
474
475/**
476 * Internal GC logger worker: Flush logger.
477 *
478 * @returns VINF_SUCCESS.
479 * @param pLogger The logger instance to flush.
480 * @remark This function must be exported!
481 */
482VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
483
484/** @name Trap testcases and related labels.
485 * @{ */
486DECLASM(void) vmmGCEnableWP(void);
487DECLASM(void) vmmGCDisableWP(void);
488DECLASM(int) vmmGCTestTrap3(void);
489DECLASM(int) vmmGCTestTrap8(void);
490DECLASM(int) vmmGCTestTrap0d(void);
491DECLASM(int) vmmGCTestTrap0e(void);
492DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
493DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
494/** @} */
495
496#endif /* IN_GC */
497
498__END_DECLS
499
500/** @} */
501
502#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