VirtualBox

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

Last change on this file since 3776 was 3724, checked in by vboxsync, 17 years ago

removed the obsolete x86context.h (all constants are in VBox/x86.h).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.8 KB
Line 
1/* $Id: VMMInternal.h 3724 2007-07-19 18:57:24Z vboxsync $ */
2/** @file
3 * VMM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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_GC)
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 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 beyon 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 RTGCPTR pvGCCoreCode;
164#ifdef VBOX_WITH_NMI
165 /** The guest context address of the APIC (host) mapping. */
166 RTGCPTR GCPtrApicBase;
167 RTGCPTR 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 GCPTRTYPE(PFNVMMSWITCHERGC) pfnGCGuestToHost;
181 /** Call Trampoline. See vmmGCCallTrampoline(). */
182 RTGCPTR pfnGCCallTrampoline;
183
184 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
185 RTGCPTR pfnCPUMGCResumeGuest;
186 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
187 RTGCPTR pfnCPUMGCResumeGuestV86;
188 /** The last GC return code. */
189 RTINT iLastGCRc;
190#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
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 HCPTRTYPE(uint8_t *) pbHCStack;
198 /** Pointer to the bottom of the stack - needed for doing relocations. */
199 GCPTRTYPE(uint8_t *) pbGCStack;
200 /** Pointer to the bottom of the stack - needed for doing relocations. */
201 GCPTRTYPE(uint8_t *) pbGCStackBottom;
202
203 /** Pointer to the GC logger instance - GC Ptr.
204 * This is NULL if logging is disabled. */
205 GCPTRTYPE(PRTLOGGERGC) 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 HCPTRTYPE(PRTLOGGERGC) pLoggerHC;
211
212 /** Pointer to the R0 logger instance.
213 * This is NULL if logging is disabled. */
214 HCPTRTYPE(PVMMR0LOGGER) pR0Logger;
215
216#ifdef VBOX_WITH_GC_AND_R0_RELEASE_LOG
217 /** Pointer to the GC release logger instance - GC Ptr. */
218 GCPTRTYPE(PRTLOGGERGC) 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 HCPTRTYPE(PRTLOGGERGC) 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 PTMTIMERHC 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 /** Number of VMMR0_DO_RUN_GC calls. */
255 STAMCOUNTER StatRunGC;
256 /** Statistics for each of the GC return codes.
257 * @{ */
258 STAMCOUNTER StatGCRetNormal;
259 STAMCOUNTER StatGCRetInterrupt;
260 STAMCOUNTER StatGCRetInterruptHyper;
261 STAMCOUNTER StatGCRetGuestTrap;
262 STAMCOUNTER StatGCRetRingSwitch;
263 STAMCOUNTER StatGCRetRingSwitchInt;
264 STAMCOUNTER StatGCRetExceptionPrivilege;
265 STAMCOUNTER StatGCRetStaleSelector;
266 STAMCOUNTER StatGCRetIRETTrap;
267 STAMCOUNTER StatGCRetEmulate;
268 STAMCOUNTER StatGCRetPatchEmulate;
269 STAMCOUNTER StatGCRetIORead;
270 STAMCOUNTER StatGCRetIOWrite;
271 STAMCOUNTER StatGCRetMMIORead;
272 STAMCOUNTER StatGCRetMMIOWrite;
273 STAMCOUNTER StatGCRetMMIOPatchRead;
274 STAMCOUNTER StatGCRetMMIOPatchWrite;
275 STAMCOUNTER StatGCRetMMIOReadWrite;
276 STAMCOUNTER StatGCRetLDTFault;
277 STAMCOUNTER StatGCRetGDTFault;
278 STAMCOUNTER StatGCRetIDTFault;
279 STAMCOUNTER StatGCRetTSSFault;
280 STAMCOUNTER StatGCRetPDFault;
281 STAMCOUNTER StatGCRetCSAMTask;
282 STAMCOUNTER StatGCRetSyncCR3;
283 STAMCOUNTER StatGCRetMisc;
284 STAMCOUNTER StatGCRetPatchInt3;
285 STAMCOUNTER StatGCRetPatchPF;
286 STAMCOUNTER StatGCRetPatchGP;
287 STAMCOUNTER StatGCRetPatchIretIRQ;
288 STAMCOUNTER StatGCRetPageOverflow;
289 STAMCOUNTER StatGCRetRescheduleREM;
290 STAMCOUNTER StatGCRetToR3;
291 STAMCOUNTER StatGCRetTimerPending;
292 STAMCOUNTER StatGCRetInterruptPending;
293 STAMCOUNTER StatGCRetCallHost;
294 STAMCOUNTER StatGCRetPATMDuplicateFn;
295 STAMCOUNTER StatGCRetPGMChangeMode;
296 STAMCOUNTER StatGCRetEmulHlt;
297 STAMCOUNTER StatGCRetPendingRequest;
298 STAMCOUNTER StatGCRetPGMGrowRAM;
299 STAMCOUNTER StatGCRetPDMLock;
300 STAMCOUNTER StatGCRetLogFlush;
301 STAMCOUNTER StatGCRetPDMQueueFlush;
302 STAMCOUNTER StatGCRetPGMPoolGrow;
303 STAMCOUNTER StatGCRetRemReplay;
304 STAMCOUNTER StatGCRetVMSetError;
305 STAMCOUNTER StatGCRetVMSetRuntimeError;
306 STAMCOUNTER StatGCRetPGMLock;
307
308 /** @} */
309
310
311} VMM, *PVMM;
312
313
314/**
315 * The VMMGCEntry() codes.
316 */
317typedef enum VMMGCOPERATION
318{
319 /** Do GC module init. */
320 VMMGC_DO_VMMGC_INIT = 1,
321
322 /** The first Trap testcase. */
323 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
324 /** Trap 0 testcases, uArg selects the variation. */
325 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
326 /** Trap 1 testcases, uArg selects the variation. */
327 VMMGC_DO_TESTCASE_TRAP_1,
328 /** Trap 2 testcases, uArg selects the variation. */
329 VMMGC_DO_TESTCASE_TRAP_2,
330 /** Trap 3 testcases, uArg selects the variation. */
331 VMMGC_DO_TESTCASE_TRAP_3,
332 /** Trap 4 testcases, uArg selects the variation. */
333 VMMGC_DO_TESTCASE_TRAP_4,
334 /** Trap 5 testcases, uArg selects the variation. */
335 VMMGC_DO_TESTCASE_TRAP_5,
336 /** Trap 6 testcases, uArg selects the variation. */
337 VMMGC_DO_TESTCASE_TRAP_6,
338 /** Trap 7 testcases, uArg selects the variation. */
339 VMMGC_DO_TESTCASE_TRAP_7,
340 /** Trap 8 testcases, uArg selects the variation. */
341 VMMGC_DO_TESTCASE_TRAP_8,
342 /** Trap 9 testcases, uArg selects the variation. */
343 VMMGC_DO_TESTCASE_TRAP_9,
344 /** Trap 0a testcases, uArg selects the variation. */
345 VMMGC_DO_TESTCASE_TRAP_0A,
346 /** Trap 0b testcases, uArg selects the variation. */
347 VMMGC_DO_TESTCASE_TRAP_0B,
348 /** Trap 0c testcases, uArg selects the variation. */
349 VMMGC_DO_TESTCASE_TRAP_0C,
350 /** Trap 0d testcases, uArg selects the variation. */
351 VMMGC_DO_TESTCASE_TRAP_0D,
352 /** Trap 0e testcases, uArg selects the variation. */
353 VMMGC_DO_TESTCASE_TRAP_0E,
354 /** The last trap testcase (exclusive). */
355 VMMGC_DO_TESTCASE_TRAP_LAST,
356 /** Testcase for checking interrupt forwarding. */
357 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
358 /** Switching testing and profiling stub. */
359 VMMGC_DO_TESTCASE_NOP,
360 /** Testcase for checking interrupt masking.. */
361 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
362 /** Switching testing and profiling stub. */
363 VMMGC_DO_TESTCASE_HWACCM_NOP,
364
365 /** The usual 32-bit hack. */
366 VMMGC_DO_32_BIT_HACK = 0x7fffffff
367} VMMGCOPERATION;
368
369
370__BEGIN_DECLS
371
372
373#ifdef IN_RING0
374/**
375 * World switcher assembly routine.
376 * It will call VMMGCEntry().
377 *
378 * @returns return code from VMMGCEntry().
379 * @param pVM The VM in question.
380 * @param uArg See VMMGCEntry().
381 * @internal
382 */
383DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
384
385/**
386 * Callback function for vmmR0CallHostSetJmp.
387 *
388 * @returns VBox status code.
389 * @param pVM The VM handle.
390 */
391typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
392/** Pointer to FNVMMR0SETJMP(). */
393typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
394
395/**
396 * The setjmp variant used for calling Ring-3.
397 *
398 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
399 * in the middle of a ring-3 call. Another differences is the function pointer and
400 * argument. This has to do with resuming code and the stack frame of the caller.
401 *
402 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
403 * @param pJmpBuf The jmp_buf to set.
404 * @param pfn The function to be called when not resuming..
405 * @param pVM The argument of that function.
406 */
407DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
408
409/**
410 * Worker for VMMR0CallHost.
411 * This will save the stack and registers.
412 *
413 * @returns rc.
414 * @param pJmpBuf Pointer to the jump buffer.
415 * @param rc The return code.
416 */
417DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
418
419/**
420 * Internal R0 logger worker: Logger wrapper.
421 */
422VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
423
424/**
425 * Internal R0 logger worker: Flush logger.
426 *
427 * @param pLogger The logger instance to flush.
428 * @remark This function must be exported!
429 */
430VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
431
432#endif /* IN_RING0 */
433
434
435#ifdef IN_GC
436/**
437 * Internal GC logger worker: Logger wrapper.
438 */
439VMMGCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
440
441/**
442 * Internal GC release logger worker: Logger wrapper.
443 */
444VMMGCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
445
446/**
447 * Internal GC logger worker: Flush logger.
448 *
449 * @returns VINF_SUCCESS.
450 * @param pLogger The logger instance to flush.
451 * @remark This function must be exported!
452 */
453VMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERGC pLogger);
454
455/** @name Trap testcases and related labels.
456 * @{ */
457DECLASM(void) vmmGCEnableWP(void);
458DECLASM(void) vmmGCDisableWP(void);
459DECLASM(int) vmmGCTestTrap3(void);
460DECLASM(int) vmmGCTestTrap8(void);
461DECLASM(int) vmmGCTestTrap0d(void);
462DECLASM(int) vmmGCTestTrap0e(void);
463DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
464DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
465/** @} */
466
467#endif /* IN_GC */
468
469__END_DECLS
470
471/** @} */
472
473#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