VirtualBox

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

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

VMM: some adjustments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 18.5 KB
Line 
1/* $Id: VMMInternal.h 13796 2008-11-04 18:37:33Z 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/**
355 * VMMCPU Data (part of VMCPU)
356 */
357typedef struct VMMCPU
358{
359 /** Offset to the VMCPU structure.
360 * See VMM2VMCPU(). */
361 RTINT offVMCPU;
362} VMMCPU;
363/** Pointer to VMMCPU. */
364typedef VMMCPU *PVMMCPU;
365
366
367/**
368 * The VMMGCEntry() codes.
369 */
370typedef enum VMMGCOPERATION
371{
372 /** Do GC module init. */
373 VMMGC_DO_VMMGC_INIT = 1,
374
375 /** The first Trap testcase. */
376 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
377 /** Trap 0 testcases, uArg selects the variation. */
378 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
379 /** Trap 1 testcases, uArg selects the variation. */
380 VMMGC_DO_TESTCASE_TRAP_1,
381 /** Trap 2 testcases, uArg selects the variation. */
382 VMMGC_DO_TESTCASE_TRAP_2,
383 /** Trap 3 testcases, uArg selects the variation. */
384 VMMGC_DO_TESTCASE_TRAP_3,
385 /** Trap 4 testcases, uArg selects the variation. */
386 VMMGC_DO_TESTCASE_TRAP_4,
387 /** Trap 5 testcases, uArg selects the variation. */
388 VMMGC_DO_TESTCASE_TRAP_5,
389 /** Trap 6 testcases, uArg selects the variation. */
390 VMMGC_DO_TESTCASE_TRAP_6,
391 /** Trap 7 testcases, uArg selects the variation. */
392 VMMGC_DO_TESTCASE_TRAP_7,
393 /** Trap 8 testcases, uArg selects the variation. */
394 VMMGC_DO_TESTCASE_TRAP_8,
395 /** Trap 9 testcases, uArg selects the variation. */
396 VMMGC_DO_TESTCASE_TRAP_9,
397 /** Trap 0a testcases, uArg selects the variation. */
398 VMMGC_DO_TESTCASE_TRAP_0A,
399 /** Trap 0b testcases, uArg selects the variation. */
400 VMMGC_DO_TESTCASE_TRAP_0B,
401 /** Trap 0c testcases, uArg selects the variation. */
402 VMMGC_DO_TESTCASE_TRAP_0C,
403 /** Trap 0d testcases, uArg selects the variation. */
404 VMMGC_DO_TESTCASE_TRAP_0D,
405 /** Trap 0e testcases, uArg selects the variation. */
406 VMMGC_DO_TESTCASE_TRAP_0E,
407 /** The last trap testcase (exclusive). */
408 VMMGC_DO_TESTCASE_TRAP_LAST,
409 /** Testcase for checking interrupt forwarding. */
410 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
411 /** Switching testing and profiling stub. */
412 VMMGC_DO_TESTCASE_NOP,
413 /** Testcase for checking interrupt masking.. */
414 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
415 /** Switching testing and profiling stub. */
416 VMMGC_DO_TESTCASE_HWACCM_NOP,
417
418 /** The usual 32-bit hack. */
419 VMMGC_DO_32_BIT_HACK = 0x7fffffff
420} VMMGCOPERATION;
421
422
423__BEGIN_DECLS
424
425
426#ifdef IN_RING0
427/**
428 * World switcher assembly routine.
429 * It will call VMMGCEntry().
430 *
431 * @returns return code from VMMGCEntry().
432 * @param pVM The VM in question.
433 * @param uArg See VMMGCEntry().
434 * @internal
435 */
436DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
437
438/**
439 * Callback function for vmmR0CallHostSetJmp.
440 *
441 * @returns VBox status code.
442 * @param pVM The VM handle.
443 */
444typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
445/** Pointer to FNVMMR0SETJMP(). */
446typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
447
448/**
449 * The setjmp variant used for calling Ring-3.
450 *
451 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
452 * in the middle of a ring-3 call. Another differences is the function pointer and
453 * argument. This has to do with resuming code and the stack frame of the caller.
454 *
455 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
456 * @param pJmpBuf The jmp_buf to set.
457 * @param pfn The function to be called when not resuming..
458 * @param pVM The argument of that function.
459 */
460DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
461
462/**
463 * Callback function for vmmR0CallHostSetJmpEx.
464 *
465 * @returns VBox status code.
466 * @param pvUser The user argument.
467 */
468typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
469/** Pointer to FNVMMR0SETJMP(). */
470typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
471
472/**
473 * Same as vmmR0CallHostSetJmp except for the function signature.
474 *
475 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
476 * @param pJmpBuf The jmp_buf to set.
477 * @param pfn The function to be called when not resuming..
478 * @param pvUser The argument of that function.
479 */
480DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
481
482
483/**
484 * Worker for VMMR0CallHost.
485 * This will save the stack and registers.
486 *
487 * @returns rc.
488 * @param pJmpBuf Pointer to the jump buffer.
489 * @param rc The return code.
490 */
491DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
492
493/**
494 * Internal R0 logger worker: Logger wrapper.
495 */
496VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
497
498/**
499 * Internal R0 logger worker: Flush logger.
500 *
501 * @param pLogger The logger instance to flush.
502 * @remark This function must be exported!
503 */
504VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
505
506#endif /* IN_RING0 */
507#ifdef IN_GC
508
509/**
510 * Internal GC logger worker: Logger wrapper.
511 */
512VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
513
514/**
515 * Internal GC release logger worker: Logger wrapper.
516 */
517VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
518
519/**
520 * Internal GC logger worker: Flush logger.
521 *
522 * @returns VINF_SUCCESS.
523 * @param pLogger The logger instance to flush.
524 * @remark This function must be exported!
525 */
526VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
527
528/** @name Trap testcases and related labels.
529 * @{ */
530DECLASM(void) vmmGCEnableWP(void);
531DECLASM(void) vmmGCDisableWP(void);
532DECLASM(int) vmmGCTestTrap3(void);
533DECLASM(int) vmmGCTestTrap8(void);
534DECLASM(int) vmmGCTestTrap0d(void);
535DECLASM(int) vmmGCTestTrap0e(void);
536DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
537DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
538/** @} */
539
540#endif /* IN_GC */
541
542__END_DECLS
543
544/** @} */
545
546#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