VirtualBox

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

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

Some initial VM data restructuring.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 18.5 KB
Line 
1/* $Id: VMMInternal.h 13742 2008-11-03 12:19:40Z 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 VM)
160 */
161typedef struct VMM
162{
163 /** Offset to the VM structure.
164 * See VMM2VM(). */
165 RTINT offVM;
166
167 /** @name World Switcher and Related
168 * @{
169 */
170 /** Size of the core code. */
171 RTUINT cbCoreCode;
172 /** Physical address of core code. */
173 RTHCPHYS HCPhysCoreCode;
174 /** Pointer to core code ring-3 mapping - contiguous memory.
175 * At present this only means the context switcher code. */
176 RTR3PTR pvCoreCodeR3;
177 /** Pointer to core code ring-0 mapping - contiguous memory.
178 * At present this only means the context switcher code. */
179 RTR0PTR pvCoreCodeR0;
180 /** Pointer to core code guest context mapping. */
181 RTRCPTR pvCoreCodeRC;
182#ifdef VBOX_WITH_NMI
183 /** The guest context address of the APIC (host) mapping. */
184 RTRCPTR GCPtrApicBase;
185 RTRCPTR pGCPadding0; /**< Alignment padding */
186#endif
187 /** The current switcher.
188 * This will be set before the VMM is fully initialized. */
189 VMMSWITCHER enmSwitcher;
190 /** Array of offsets to the different switchers within the core code. */
191 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
192 /** Flag to disable the switcher permanently (VMX) (boolean) */
193 bool fSwitcherDisabled;
194
195 /** Host to guest switcher entry point. */
196 R0PTRTYPE(PFNVMMSWITCHERHC) pfnHostToGuestR0;
197 /** Guest to host switcher entry point. */
198 RCPTRTYPE(PFNVMMSWITCHERRC) pfnGuestToHostRC;
199 /** Call Trampoline. See vmmGCCallTrampoline(). */
200 RTRCPTR pfnCallTrampolineRC;
201
202 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
203 RTRCPTR pfnCPUMRCResumeGuest;
204 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
205 RTRCPTR pfnCPUMRCResumeGuestV86;
206 /** The last RC/R0 return code. */
207 RTINT iLastGZRc;
208#if HC_ARCH_BITS == 64
209 uint32_t u32Padding0; /**< Alignment padding. */
210#endif
211 /** @} */
212
213 /** VMM stack, pointer to the top of the stack in R3.
214 * Stack is allocated from the hypervisor heap and is page aligned
215 * and always writable in RC. */
216 R3PTRTYPE(uint8_t *) pbEMTStackR3;
217 /** Pointer to the bottom of the stack - needed for doing relocations. */
218 RCPTRTYPE(uint8_t *) pbEMTStackRC;
219 /** Pointer to the bottom of the stack - needed for doing relocations. */
220 RCPTRTYPE(uint8_t *) pbEMTStackBottomRC;
221
222 /** @name Logging
223 * @{
224 */
225 /** Size of the allocated logger instance (pRCLoggerRC/pRCLoggerR3). */
226 uint32_t cbRCLogger;
227 /** Pointer to the RC logger instance - RC Ptr.
228 * This is NULL if logging is disabled. */
229 RCPTRTYPE(PRTLOGGERRC) pRCLoggerRC;
230 /** Pointer to the GC logger instance - R3 Ptr.
231 * This is NULL if logging is disabled. */
232 R3PTRTYPE(PRTLOGGERRC) pRCLoggerR3;
233#ifdef VBOX_WITH_RC_RELEASE_LOGGING
234 /** Size of the allocated release logger instance (pRCRelLoggerRC/pRCRelLoggerR3).
235 * This may differ from cbRCLogger. */
236 uint32_t cbRCRelLogger;
237 /** Pointer to the GC release logger instance - RC Ptr. */
238 RCPTRTYPE(PRTLOGGERRC) pRCRelLoggerRC;
239 /** Pointer to the GC release logger instance - R3 Ptr. */
240 R3PTRTYPE(PRTLOGGERRC) pRCRelLoggerR3;
241#endif /* VBOX_WITH_RC_RELEASE_LOGGING */
242 /** Pointer to the R0 logger instance - R3 Ptr.
243 * This is NULL if logging is disabled. */
244 R3PTRTYPE(PVMMR0LOGGER) pR0LoggerR3;
245 /** Pointer to the R0 logger instance - R0 Ptr.
246 * This is NULL if logging is disabled. */
247 R0PTRTYPE(PVMMR0LOGGER) pR0LoggerR0;
248#if HC_ARCH_BITS == 32
249 uint32_t u32Padding1; /**< Alignment padding. */
250#endif
251 /** @} */
252
253
254 /** Global VM critical section. */
255 RTCRITSECT CritSectVMLock;
256
257 /** The EMT yield timer. */
258 PTMTIMERR3 pYieldTimer;
259 /** The period to the next timeout when suspended or stopped.
260 * This is 0 when running. */
261 uint32_t cYieldResumeMillies;
262 /** The EMT yield timer interval (milliseconds). */
263 uint32_t cYieldEveryMillies;
264#if HC_ARCH_BITS == 32
265 uint32_t u32Padding0; /**< Alignment padding. */
266#endif
267 /** The timestamp of the previous yield. (nano) */
268 uint64_t u64LastYield;
269
270 /** @name CallHost
271 * @todo SMP: per vCPU
272 * @{ */
273 /** The pending operation. */
274 VMMCALLHOST enmCallHostOperation;
275 /** The result of the last operation. */
276 int32_t rcCallHost;
277 /** The argument to the operation. */
278 uint64_t u64CallHostArg;
279 /** The Ring-0 jmp buffer. */
280 VMMR0JMPBUF CallHostR0JmpBuf;
281 /** @} */
282
283 /** Buffer for storing the standard assertion message for a ring-0 assertion.
284 * Used for saving the assertion message text for the release log and guru
285 * meditation dump. */
286 char szRing0AssertMsg1[256];
287 /** Buffer for storing the custom message for a ring-0 assertion. */
288 char szRing0AssertMsg2[256];
289
290 /** Number of VMMR0_DO_RUN_GC calls. */
291 STAMCOUNTER StatRunRC;
292
293 /** Statistics for each of the RC/R0 return codes.
294 * @{ */
295 STAMCOUNTER StatRZRetNormal;
296 STAMCOUNTER StatRZRetInterrupt;
297 STAMCOUNTER StatRZRetInterruptHyper;
298 STAMCOUNTER StatRZRetGuestTrap;
299 STAMCOUNTER StatRZRetRingSwitch;
300 STAMCOUNTER StatRZRetRingSwitchInt;
301 STAMCOUNTER StatRZRetExceptionPrivilege;
302 STAMCOUNTER StatRZRetStaleSelector;
303 STAMCOUNTER StatRZRetIRETTrap;
304 STAMCOUNTER StatRZRetEmulate;
305 STAMCOUNTER StatRZRetPatchEmulate;
306 STAMCOUNTER StatRZRetIORead;
307 STAMCOUNTER StatRZRetIOWrite;
308 STAMCOUNTER StatRZRetMMIORead;
309 STAMCOUNTER StatRZRetMMIOWrite;
310 STAMCOUNTER StatRZRetMMIOPatchRead;
311 STAMCOUNTER StatRZRetMMIOPatchWrite;
312 STAMCOUNTER StatRZRetMMIOReadWrite;
313 STAMCOUNTER StatRZRetLDTFault;
314 STAMCOUNTER StatRZRetGDTFault;
315 STAMCOUNTER StatRZRetIDTFault;
316 STAMCOUNTER StatRZRetTSSFault;
317 STAMCOUNTER StatRZRetPDFault;
318 STAMCOUNTER StatRZRetCSAMTask;
319 STAMCOUNTER StatRZRetSyncCR3;
320 STAMCOUNTER StatRZRetMisc;
321 STAMCOUNTER StatRZRetPatchInt3;
322 STAMCOUNTER StatRZRetPatchPF;
323 STAMCOUNTER StatRZRetPatchGP;
324 STAMCOUNTER StatRZRetPatchIretIRQ;
325 STAMCOUNTER StatRZRetPageOverflow;
326 STAMCOUNTER StatRZRetRescheduleREM;
327 STAMCOUNTER StatRZRetToR3;
328 STAMCOUNTER StatRZRetTimerPending;
329 STAMCOUNTER StatRZRetInterruptPending;
330 STAMCOUNTER StatRZRetCallHost;
331 STAMCOUNTER StatRZRetPATMDuplicateFn;
332 STAMCOUNTER StatRZRetPGMChangeMode;
333 STAMCOUNTER StatRZRetEmulHlt;
334 STAMCOUNTER StatRZRetPendingRequest;
335#ifndef VBOX_WITH_NEW_PHYS_CODE
336 STAMCOUNTER StatRZCallPGMGrowRAM;
337#endif
338 STAMCOUNTER StatRZCallPDMLock;
339 STAMCOUNTER StatRZCallLogFlush;
340 STAMCOUNTER StatRZCallPDMQueueFlush;
341 STAMCOUNTER StatRZCallPGMPoolGrow;
342 STAMCOUNTER StatRZCallPGMMapChunk;
343 STAMCOUNTER StatRZCallPGMAllocHandy;
344 STAMCOUNTER StatRZCallRemReplay;
345 STAMCOUNTER StatRZCallVMSetError;
346 STAMCOUNTER StatRZCallVMSetRuntimeError;
347 STAMCOUNTER StatRZCallPGMLock;
348 /** @} */
349} VMM;
350/** Pointer to VMM. */
351typedef VMM *PVMM;
352
353/**
354 * VMMCPU Data (part of VMCPU)
355 */
356typedef struct VMMCPU
357{
358 /** Offset to the VMCPU structure.
359 * See VMM2VMCPU(). */
360 RTINT offVMCPU;
361} VMMCPU;
362/** Pointer to VMMCPU. */
363typedef VMMCPU *PVMMCPU;
364
365
366/**
367 * The VMMGCEntry() codes.
368 */
369typedef enum VMMGCOPERATION
370{
371 /** Do GC module init. */
372 VMMGC_DO_VMMGC_INIT = 1,
373
374 /** The first Trap testcase. */
375 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
376 /** Trap 0 testcases, uArg selects the variation. */
377 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
378 /** Trap 1 testcases, uArg selects the variation. */
379 VMMGC_DO_TESTCASE_TRAP_1,
380 /** Trap 2 testcases, uArg selects the variation. */
381 VMMGC_DO_TESTCASE_TRAP_2,
382 /** Trap 3 testcases, uArg selects the variation. */
383 VMMGC_DO_TESTCASE_TRAP_3,
384 /** Trap 4 testcases, uArg selects the variation. */
385 VMMGC_DO_TESTCASE_TRAP_4,
386 /** Trap 5 testcases, uArg selects the variation. */
387 VMMGC_DO_TESTCASE_TRAP_5,
388 /** Trap 6 testcases, uArg selects the variation. */
389 VMMGC_DO_TESTCASE_TRAP_6,
390 /** Trap 7 testcases, uArg selects the variation. */
391 VMMGC_DO_TESTCASE_TRAP_7,
392 /** Trap 8 testcases, uArg selects the variation. */
393 VMMGC_DO_TESTCASE_TRAP_8,
394 /** Trap 9 testcases, uArg selects the variation. */
395 VMMGC_DO_TESTCASE_TRAP_9,
396 /** Trap 0a testcases, uArg selects the variation. */
397 VMMGC_DO_TESTCASE_TRAP_0A,
398 /** Trap 0b testcases, uArg selects the variation. */
399 VMMGC_DO_TESTCASE_TRAP_0B,
400 /** Trap 0c testcases, uArg selects the variation. */
401 VMMGC_DO_TESTCASE_TRAP_0C,
402 /** Trap 0d testcases, uArg selects the variation. */
403 VMMGC_DO_TESTCASE_TRAP_0D,
404 /** Trap 0e testcases, uArg selects the variation. */
405 VMMGC_DO_TESTCASE_TRAP_0E,
406 /** The last trap testcase (exclusive). */
407 VMMGC_DO_TESTCASE_TRAP_LAST,
408 /** Testcase for checking interrupt forwarding. */
409 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
410 /** Switching testing and profiling stub. */
411 VMMGC_DO_TESTCASE_NOP,
412 /** Testcase for checking interrupt masking.. */
413 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
414 /** Switching testing and profiling stub. */
415 VMMGC_DO_TESTCASE_HWACCM_NOP,
416
417 /** The usual 32-bit hack. */
418 VMMGC_DO_32_BIT_HACK = 0x7fffffff
419} VMMGCOPERATION;
420
421
422__BEGIN_DECLS
423
424
425#ifdef IN_RING0
426/**
427 * World switcher assembly routine.
428 * It will call VMMGCEntry().
429 *
430 * @returns return code from VMMGCEntry().
431 * @param pVM The VM in question.
432 * @param uArg See VMMGCEntry().
433 * @internal
434 */
435DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
436
437/**
438 * Callback function for vmmR0CallHostSetJmp.
439 *
440 * @returns VBox status code.
441 * @param pVM The VM handle.
442 */
443typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
444/** Pointer to FNVMMR0SETJMP(). */
445typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
446
447/**
448 * The setjmp variant used for calling Ring-3.
449 *
450 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
451 * in the middle of a ring-3 call. Another differences is the function pointer and
452 * argument. This has to do with resuming code and the stack frame of the caller.
453 *
454 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
455 * @param pJmpBuf The jmp_buf to set.
456 * @param pfn The function to be called when not resuming..
457 * @param pVM The argument of that function.
458 */
459DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
460
461/**
462 * Callback function for vmmR0CallHostSetJmpEx.
463 *
464 * @returns VBox status code.
465 * @param pvUser The user argument.
466 */
467typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
468/** Pointer to FNVMMR0SETJMP(). */
469typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
470
471/**
472 * Same as vmmR0CallHostSetJmp except for the function signature.
473 *
474 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
475 * @param pJmpBuf The jmp_buf to set.
476 * @param pfn The function to be called when not resuming..
477 * @param pvUser The argument of that function.
478 */
479DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
480
481
482/**
483 * Worker for VMMR0CallHost.
484 * This will save the stack and registers.
485 *
486 * @returns rc.
487 * @param pJmpBuf Pointer to the jump buffer.
488 * @param rc The return code.
489 */
490DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
491
492/**
493 * Internal R0 logger worker: Logger wrapper.
494 */
495VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
496
497/**
498 * Internal R0 logger worker: Flush logger.
499 *
500 * @param pLogger The logger instance to flush.
501 * @remark This function must be exported!
502 */
503VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
504
505#endif /* IN_RING0 */
506#ifdef IN_GC
507
508/**
509 * Internal GC logger worker: Logger wrapper.
510 */
511VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
512
513/**
514 * Internal GC release logger worker: Logger wrapper.
515 */
516VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
517
518/**
519 * Internal GC logger worker: Flush logger.
520 *
521 * @returns VINF_SUCCESS.
522 * @param pLogger The logger instance to flush.
523 * @remark This function must be exported!
524 */
525VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
526
527/** @name Trap testcases and related labels.
528 * @{ */
529DECLASM(void) vmmGCEnableWP(void);
530DECLASM(void) vmmGCDisableWP(void);
531DECLASM(int) vmmGCTestTrap3(void);
532DECLASM(int) vmmGCTestTrap8(void);
533DECLASM(int) vmmGCTestTrap0d(void);
534DECLASM(int) vmmGCTestTrap0e(void);
535DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
536DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
537/** @} */
538
539#endif /* IN_GC */
540
541__END_DECLS
542
543/** @} */
544
545#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette