VirtualBox

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

Last change on this file since 20374 was 20374, checked in by vboxsync, 15 years ago

*: s/RT_\(BEGIN|END\)_DECLS/RT_C_DECLS_\1/g

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 19.0 KB
Line 
1/* $Id: VMMInternal.h 20374 2009-06-08 00:43:21Z 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 wrapper.
91 *
92 * We need to be able to find the VM handle from the logger instance, so we wrap
93 * it in this structure.
94 */
95typedef struct VMMR0LOGGER
96{
97 /** Pointer to the VM handle. */
98 R0PTRTYPE(PVM) pVM;
99 /** Size of the allocated logger instance (Logger). */
100 uint32_t cbLogger;
101 /** Flag indicating whether we've create the logger Ring-0 instance yet. */
102 bool fCreated;
103 /** Flag indicating whether we've disabled flushing (world switch) or not. */
104 bool fFlushingDisabled;
105 /** Flag indicating whether we've registered the instance already. */
106 bool fRegistered;
107 bool a8Alignment;
108#if HC_ARCH_BITS == 32
109 uint32_t u32Alignment;
110#endif
111 /** The ring-0 logger instance. This extends beyond the size. */
112 RTLOGGER Logger;
113} VMMR0LOGGER;
114/** Pointer to a ring-0 logger instance wrapper. */
115typedef VMMR0LOGGER *PVMMR0LOGGER;
116
117
118/**
119 * Jump buffer for the setjmp/longjmp like constructs used to
120 * quickly 'call' back into Ring-3.
121 */
122typedef struct VMMR0JMPBUF
123{
124 /** Traditional jmp_buf stuff
125 * @{ */
126#if HC_ARCH_BITS == 32
127 uint32_t ebx;
128 uint32_t esi;
129 uint32_t edi;
130 uint32_t ebp;
131 uint32_t esp;
132 uint32_t eip;
133 uint32_t u32Padding;
134#endif
135#if HC_ARCH_BITS == 64
136 uint64_t rbx;
137# ifdef RT_OS_WINDOWS
138 uint64_t rsi;
139 uint64_t rdi;
140# endif
141 uint64_t rbp;
142 uint64_t r12;
143 uint64_t r13;
144 uint64_t r14;
145 uint64_t r15;
146 uint64_t rsp;
147 uint64_t rip;
148#endif
149 /** @} */
150
151 /** Flag that indicates that we've done a ring-3 call. */
152 bool fInRing3Call;
153 /** The number of bytes we've saved. */
154 uint32_t cbSavedStack;
155 /** Pointer to the buffer used to save the stack.
156 * This is assumed to be 8KB. */
157 RTR0PTR pvSavedStack;
158 /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
159 RTHCUINTREG SpCheck;
160 /** The esp we should resume execution with after the restore. */
161 RTHCUINTREG SpResume;
162 /** ESP/RSP at the time of the jump to ring 3. */
163 RTHCUINTREG SavedEsp;
164 /** EBP/RBP at the time of the jump to ring 3. */
165 RTHCUINTREG SavedEbp;
166} VMMR0JMPBUF;
167/** Pointer to a ring-0 jump buffer. */
168typedef VMMR0JMPBUF *PVMMR0JMPBUF;
169
170
171/**
172 * VMM Data (part of VM)
173 */
174typedef struct VMM
175{
176 /** Offset to the VM structure.
177 * See VMM2VM(). */
178 RTINT offVM;
179
180 /** @name World Switcher and Related
181 * @{
182 */
183 /** Size of the core code. */
184 RTUINT cbCoreCode;
185 /** Physical address of core code. */
186 RTHCPHYS HCPhysCoreCode;
187 /** Pointer to core code ring-3 mapping - contiguous memory.
188 * At present this only means the context switcher code. */
189 RTR3PTR pvCoreCodeR3;
190 /** Pointer to core code ring-0 mapping - contiguous memory.
191 * At present this only means the context switcher code. */
192 RTR0PTR pvCoreCodeR0;
193 /** Pointer to core code guest context mapping. */
194 RTRCPTR pvCoreCodeRC;
195 RTRCPTR pRCPadding0; /**< Alignment padding */
196#ifdef VBOX_WITH_NMI
197 /** The guest context address of the APIC (host) mapping. */
198 RTRCPTR GCPtrApicBase;
199 RTRCPTR pRCPadding1; /**< Alignment padding */
200#endif
201 /** The current switcher.
202 * This will be set before the VMM is fully initialized. */
203 VMMSWITCHER enmSwitcher;
204 /** Flag to disable the switcher permanently (VMX) (boolean) */
205 bool fSwitcherDisabled;
206 /** Array of offsets to the different switchers within the core code. */
207 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
208
209 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
210 RTRCPTR pfnCPUMRCResumeGuest;
211 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
212 RTRCPTR pfnCPUMRCResumeGuestV86;
213 /** Call Trampoline. See vmmGCCallTrampoline(). */
214 RTRCPTR pfnCallTrampolineRC;
215 /** Guest to host switcher entry point. */
216 RCPTRTYPE(PFNVMMSWITCHERRC) pfnGuestToHostRC;
217 /** Host to guest switcher entry point. */
218 R0PTRTYPE(PFNVMMSWITCHERHC) pfnHostToGuestR0;
219 /** @} */
220
221 /** @name Logging
222 * @{
223 */
224 /** Size of the allocated logger instance (pRCLoggerRC/pRCLoggerR3). */
225 uint32_t cbRCLogger;
226 /** Pointer to the RC logger instance - RC Ptr.
227 * This is NULL if logging is disabled. */
228 RCPTRTYPE(PRTLOGGERRC) pRCLoggerRC;
229 /** Pointer to the GC logger instance - R3 Ptr.
230 * This is NULL if logging is disabled. */
231 R3PTRTYPE(PRTLOGGERRC) pRCLoggerR3;
232 /** Pointer to the GC release logger instance - R3 Ptr. */
233 R3PTRTYPE(PRTLOGGERRC) pRCRelLoggerR3;
234 /** Pointer to the GC release logger instance - RC Ptr. */
235 RCPTRTYPE(PRTLOGGERRC) pRCRelLoggerRC;
236 /** Size of the allocated release logger instance (pRCRelLoggerRC/pRCRelLoggerR3).
237 * This may differ from cbRCLogger. */
238 uint32_t cbRCRelLogger;
239 /** @} */
240
241 /** The EMT yield timer. */
242 PTMTIMERR3 pYieldTimer;
243 /** The period to the next timeout when suspended or stopped.
244 * This is 0 when running. */
245 uint32_t cYieldResumeMillies;
246 /** The EMT yield timer interval (milliseconds). */
247 uint32_t cYieldEveryMillies;
248 /** The timestamp of the previous yield. (nano) */
249 uint64_t u64LastYield;
250
251 /** Critical section.
252 * Use for synchronizing all VCPUs
253 */
254 RTCRITSECT CritSectSync;
255
256 /** Buffer for storing the standard assertion message for a ring-0 assertion.
257 * Used for saving the assertion message text for the release log and guru
258 * meditation dump. */
259 char szRing0AssertMsg1[512];
260 /** Buffer for storing the custom message for a ring-0 assertion. */
261 char szRing0AssertMsg2[256];
262
263 /** Number of VMMR0_DO_RUN_GC calls. */
264 STAMCOUNTER StatRunRC;
265
266 /** Statistics for each of the RC/R0 return codes.
267 * @{ */
268 STAMCOUNTER StatRZRetNormal;
269 STAMCOUNTER StatRZRetInterrupt;
270 STAMCOUNTER StatRZRetInterruptHyper;
271 STAMCOUNTER StatRZRetGuestTrap;
272 STAMCOUNTER StatRZRetRingSwitch;
273 STAMCOUNTER StatRZRetRingSwitchInt;
274 STAMCOUNTER StatRZRetExceptionPrivilege;
275 STAMCOUNTER StatRZRetStaleSelector;
276 STAMCOUNTER StatRZRetIRETTrap;
277 STAMCOUNTER StatRZRetEmulate;
278 STAMCOUNTER StatRZRetIOBlockEmulate;
279 STAMCOUNTER StatRZRetPatchEmulate;
280 STAMCOUNTER StatRZRetIORead;
281 STAMCOUNTER StatRZRetIOWrite;
282 STAMCOUNTER StatRZRetMMIORead;
283 STAMCOUNTER StatRZRetMMIOWrite;
284 STAMCOUNTER StatRZRetMMIOPatchRead;
285 STAMCOUNTER StatRZRetMMIOPatchWrite;
286 STAMCOUNTER StatRZRetMMIOReadWrite;
287 STAMCOUNTER StatRZRetLDTFault;
288 STAMCOUNTER StatRZRetGDTFault;
289 STAMCOUNTER StatRZRetIDTFault;
290 STAMCOUNTER StatRZRetTSSFault;
291 STAMCOUNTER StatRZRetPDFault;
292 STAMCOUNTER StatRZRetCSAMTask;
293 STAMCOUNTER StatRZRetSyncCR3;
294 STAMCOUNTER StatRZRetMisc;
295 STAMCOUNTER StatRZRetPatchInt3;
296 STAMCOUNTER StatRZRetPatchPF;
297 STAMCOUNTER StatRZRetPatchGP;
298 STAMCOUNTER StatRZRetPatchIretIRQ;
299 STAMCOUNTER StatRZRetPageOverflow;
300 STAMCOUNTER StatRZRetRescheduleREM;
301 STAMCOUNTER StatRZRetToR3;
302 STAMCOUNTER StatRZRetTimerPending;
303 STAMCOUNTER StatRZRetInterruptPending;
304 STAMCOUNTER StatRZRetCallHost;
305 STAMCOUNTER StatRZRetPATMDuplicateFn;
306 STAMCOUNTER StatRZRetPGMChangeMode;
307 STAMCOUNTER StatRZRetEmulHlt;
308 STAMCOUNTER StatRZRetPendingRequest;
309 STAMCOUNTER StatRZCallPDMLock;
310 STAMCOUNTER StatRZCallLogFlush;
311 STAMCOUNTER StatRZCallPDMQueueFlush;
312 STAMCOUNTER StatRZCallPGMPoolGrow;
313 STAMCOUNTER StatRZCallPGMMapChunk;
314 STAMCOUNTER StatRZCallPGMAllocHandy;
315 STAMCOUNTER StatRZCallRemReplay;
316 STAMCOUNTER StatRZCallVMSetError;
317 STAMCOUNTER StatRZCallVMSetRuntimeError;
318 STAMCOUNTER StatRZCallPGMLock;
319 /** @} */
320} VMM;
321/** Pointer to VMM. */
322typedef VMM *PVMM;
323
324
325/**
326 * VMMCPU Data (part of VMCPU)
327 */
328typedef struct VMMCPU
329{
330 /** Offset to the VMCPU structure.
331 * See VMM2VMCPU(). */
332 RTINT offVMCPU;
333
334 /** The last RC/R0 return code. */
335 int32_t iLastGZRc;
336
337 /** VMM stack, pointer to the top of the stack in R3.
338 * Stack is allocated from the hypervisor heap and is page aligned
339 * and always writable in RC. */
340 R3PTRTYPE(uint8_t *) pbEMTStackR3;
341 /** Pointer to the bottom of the stack - needed for doing relocations. */
342 RCPTRTYPE(uint8_t *) pbEMTStackRC;
343 /** Pointer to the bottom of the stack - needed for doing relocations. */
344 RCPTRTYPE(uint8_t *) pbEMTStackBottomRC;
345
346#ifdef LOG_ENABLED
347 /** Pointer to the R0 logger instance - R3 Ptr.
348 * This is NULL if logging is disabled. */
349 R3PTRTYPE(PVMMR0LOGGER) pR0LoggerR3;
350 /** Pointer to the R0 logger instance - R0 Ptr.
351 * This is NULL if logging is disabled. */
352 R0PTRTYPE(PVMMR0LOGGER) pR0LoggerR0;
353#endif
354
355 /** @name CallHost
356 * @{ */
357 /** The pending operation. */
358 VMMCALLHOST enmCallHostOperation;
359 /** The result of the last operation. */
360 int32_t rcCallHost;
361#if HC_ARCH_BITS == 32
362 uint32_t padding;
363#endif
364 /** The argument to the operation. */
365 uint64_t u64CallHostArg;
366 /** The Ring-0 jmp buffer. */
367 VMMR0JMPBUF CallHostR0JmpBuf;
368 /** @} */
369
370} VMMCPU;
371/** Pointer to VMMCPU. */
372typedef VMMCPU *PVMMCPU;
373
374
375/**
376 * The VMMGCEntry() codes.
377 */
378typedef enum VMMGCOPERATION
379{
380 /** Do GC module init. */
381 VMMGC_DO_VMMGC_INIT = 1,
382
383 /** The first Trap testcase. */
384 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
385 /** Trap 0 testcases, uArg selects the variation. */
386 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
387 /** Trap 1 testcases, uArg selects the variation. */
388 VMMGC_DO_TESTCASE_TRAP_1,
389 /** Trap 2 testcases, uArg selects the variation. */
390 VMMGC_DO_TESTCASE_TRAP_2,
391 /** Trap 3 testcases, uArg selects the variation. */
392 VMMGC_DO_TESTCASE_TRAP_3,
393 /** Trap 4 testcases, uArg selects the variation. */
394 VMMGC_DO_TESTCASE_TRAP_4,
395 /** Trap 5 testcases, uArg selects the variation. */
396 VMMGC_DO_TESTCASE_TRAP_5,
397 /** Trap 6 testcases, uArg selects the variation. */
398 VMMGC_DO_TESTCASE_TRAP_6,
399 /** Trap 7 testcases, uArg selects the variation. */
400 VMMGC_DO_TESTCASE_TRAP_7,
401 /** Trap 8 testcases, uArg selects the variation. */
402 VMMGC_DO_TESTCASE_TRAP_8,
403 /** Trap 9 testcases, uArg selects the variation. */
404 VMMGC_DO_TESTCASE_TRAP_9,
405 /** Trap 0a testcases, uArg selects the variation. */
406 VMMGC_DO_TESTCASE_TRAP_0A,
407 /** Trap 0b testcases, uArg selects the variation. */
408 VMMGC_DO_TESTCASE_TRAP_0B,
409 /** Trap 0c testcases, uArg selects the variation. */
410 VMMGC_DO_TESTCASE_TRAP_0C,
411 /** Trap 0d testcases, uArg selects the variation. */
412 VMMGC_DO_TESTCASE_TRAP_0D,
413 /** Trap 0e testcases, uArg selects the variation. */
414 VMMGC_DO_TESTCASE_TRAP_0E,
415 /** The last trap testcase (exclusive). */
416 VMMGC_DO_TESTCASE_TRAP_LAST,
417 /** Testcase for checking interrupt forwarding. */
418 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
419 /** Switching testing and profiling stub. */
420 VMMGC_DO_TESTCASE_NOP,
421 /** Testcase for checking interrupt masking.. */
422 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
423 /** Switching testing and profiling stub. */
424 VMMGC_DO_TESTCASE_HWACCM_NOP,
425
426 /** The usual 32-bit hack. */
427 VMMGC_DO_32_BIT_HACK = 0x7fffffff
428} VMMGCOPERATION;
429
430
431RT_C_DECLS_BEGIN
432
433#ifdef IN_RING3
434int vmmR3SwitcherInit(PVM pVM);
435void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta);
436#endif /* IN_RING3 */
437
438#ifdef IN_RING0
439/**
440 * World switcher assembly routine.
441 * It will call VMMGCEntry().
442 *
443 * @returns return code from VMMGCEntry().
444 * @param pVM The VM in question.
445 * @param uArg See VMMGCEntry().
446 * @internal
447 */
448DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
449
450/**
451 * Callback function for vmmR0CallHostSetJmp.
452 *
453 * @returns VBox status code.
454 * @param pVM The VM handle.
455 */
456typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM, PVMCPU pVCpu);
457/** Pointer to FNVMMR0SETJMP(). */
458typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
459
460/**
461 * The setjmp variant used for calling Ring-3.
462 *
463 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
464 * in the middle of a ring-3 call. Another differences is the function pointer and
465 * argument. This has to do with resuming code and the stack frame of the caller.
466 *
467 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
468 * @param pJmpBuf The jmp_buf to set.
469 * @param pfn The function to be called when not resuming..
470 * @param pVM The argument of that function.
471 */
472DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM, PVMCPU pVCpu);
473
474/**
475 * Callback function for vmmR0CallHostSetJmpEx.
476 *
477 * @returns VBox status code.
478 * @param pvUser The user argument.
479 */
480typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
481/** Pointer to FNVMMR0SETJMP(). */
482typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
483
484/**
485 * Same as vmmR0CallHostSetJmp except for the function signature.
486 *
487 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
488 * @param pJmpBuf The jmp_buf to set.
489 * @param pfn The function to be called when not resuming..
490 * @param pvUser The argument of that function.
491 */
492DECLASM(int) vmmR0CallHostSetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
493
494
495/**
496 * Worker for VMMR0CallHost.
497 * This will save the stack and registers.
498 *
499 * @returns rc.
500 * @param pJmpBuf Pointer to the jump buffer.
501 * @param rc The return code.
502 */
503DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
504
505/**
506 * Internal R0 logger worker: Logger wrapper.
507 */
508VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
509
510/**
511 * Internal R0 logger worker: Flush logger.
512 *
513 * @param pLogger The logger instance to flush.
514 * @remark This function must be exported!
515 */
516VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
517
518#endif /* IN_RING0 */
519#ifdef IN_RC
520
521/**
522 * Internal GC logger worker: Logger wrapper.
523 */
524VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
525
526/**
527 * Internal GC release logger worker: Logger wrapper.
528 */
529VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
530
531/**
532 * Internal GC logger worker: Flush logger.
533 *
534 * @returns VINF_SUCCESS.
535 * @param pLogger The logger instance to flush.
536 * @remark This function must be exported!
537 */
538VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
539
540/** @name Trap testcases and related labels.
541 * @{ */
542DECLASM(void) vmmGCEnableWP(void);
543DECLASM(void) vmmGCDisableWP(void);
544DECLASM(int) vmmGCTestTrap3(void);
545DECLASM(int) vmmGCTestTrap8(void);
546DECLASM(int) vmmGCTestTrap0d(void);
547DECLASM(int) vmmGCTestTrap0e(void);
548DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
549DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
550/** @} */
551
552#endif /* IN_RC */
553
554RT_C_DECLS_END
555
556/** @} */
557
558#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