VirtualBox

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

Last change on this file since 2283 was 2283, checked in by vboxsync, 18 years ago

Working TMCLOCK_VIRTUAL_SYNC.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.9 KB
Line 
1/* $Id: VMMInternal.h 2283 2007-04-20 22:27:52Z vboxsync $ */
2/** @file
3 * VMM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 <x86context.h>
27#include <VBox/stam.h>
28#include <VBox/log.h>
29#include <iprt/critsect.h>
30
31
32#if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_GC)
33# error "Not in VMM! This is an internal header!"
34#endif
35
36
37/** @defgroup grp_vmm_int Internals
38 * @ingroup grp_vmm
39 * @internal
40 * @{
41 */
42
43/** @def VBOX_WITH_GC_AND_R0_RELEASE_LOG
44 * Enabled GC and R0 release logging (the latter is not implemented yet). */
45#define VBOX_WITH_GC_AND_R0_RELEASE_LOG
46
47
48/**
49 * Converts a VMM pointer into a VM pointer.
50 * @returns Pointer to the VM structure the VMM is part of.
51 * @param pVMM Pointer to VMM instance data.
52 */
53#define VMM2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
54
55
56/**
57 * Switcher function, HC to GC.
58 *
59 * @param pVM The VM handle.
60 * @returns Return code indicating the action to take.
61 */
62typedef DECLASMTYPE(int) FNVMMSWITCHERHC(PVM pVM);
63/** Pointer to switcher function. */
64typedef FNVMMSWITCHERHC *PFNVMMSWITCHERHC;
65
66/**
67 * Switcher function, GC to HC.
68 *
69 * @param rc VBox status code.
70 */
71typedef DECLASMTYPE(void) FNVMMSWITCHERGC(int rc);
72/** Pointer to switcher function. */
73typedef FNVMMSWITCHERGC *PFNVMMSWITCHERGC;
74
75
76/**
77 * The ring-0 logger instance.
78 * We need to be able to find the VM handle from the logger instance.
79 */
80typedef struct VMMR0LOGGER
81{
82 /** Pointer to the VM handle. */
83 PVM pVM;
84 /** Size of the allocated logger instance (Logger). */
85 uint32_t cbLogger;
86 /** Flag indicating whether we've create the logger Ring-0 instance yet. */
87 bool fCreated;
88#if HC_ARCH_BITS == 32
89 uint32_t u32Alignment;
90#endif
91 /** The ring-0 logger instance. This extends beyon the size.*/
92 RTLOGGER Logger;
93} VMMR0LOGGER, *PVMMR0LOGGER;
94
95
96/**
97 * Jump buffer for the setjmp/longjmp like constructs used to
98 * quickly 'call' back into Ring-3.
99 */
100typedef struct VMMR0JMPBUF
101{
102 /** Tranditional jmp_buf stuff
103 * @{ */
104#if HC_ARCH_BITS == 32
105 uint32_t ebx;
106 uint32_t esi;
107 uint32_t edi;
108 uint32_t ebp;
109 uint32_t esp;
110 uint32_t eip;
111 uint32_t u32Padding;
112#endif
113#if HC_ARCH_BITS == 64
114 uint64_t rbx;
115# ifdef __WIN__
116 uint64_t rsi;
117 uint64_t rdi;
118# endif
119 uint64_t rbp;
120 uint64_t r12;
121 uint64_t r13;
122 uint64_t r14;
123 uint64_t r15;
124 uint64_t rsp;
125 uint64_t rip;
126#endif
127 /** @} */
128
129 /** Flag that indicates that we've done a ring-3 call. */
130 bool fInRing3Call;
131 /** The number of bytes we've saved. */
132 uint32_t cbSavedStack;
133 /** Pointer to the buffer used to save the stack.
134 * This is assumed to be 8KB. */
135 RTR0PTR pvSavedStack;
136 /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
137 RTHCUINTREG SpCheck;
138 /** The esp we should resume execution with after the restore. */
139 RTHCUINTREG SpResume;
140} VMMR0JMPBUF, *PVMMR0JMPBUF;
141
142
143/**
144 * VMM Data (part of VMM)
145 */
146typedef struct VMM
147{
148 /** Offset to the VM structure.
149 * See VMM2VM(). */
150 RTINT offVM;
151
152 /** Size of the core code. */
153 RTUINT cbCoreCode;
154 /** Physical address of core code. */
155 RTHCPHYS HCPhysCoreCode;
156/** @todo pvHCCoreCodeR3 -> pvCoreCodeR3, pvHCCoreCodeR0 -> pvCoreCodeR0 */
157 /** Pointer to core code ring-3 mapping - contiguous memory.
158 * At present this only means the context switcher code. */
159 RTR3PTR pvHCCoreCodeR3;
160 /** Pointer to core code ring-0 mapping - contiguous memory.
161 * At present this only means the context switcher code. */
162 RTR0PTR pvHCCoreCodeR0;
163 /** Pointer to core code guest context mapping. */
164 RTGCPTR pvGCCoreCode;
165#ifdef VBOX_WITH_NMI
166 /** The guest context address of the APIC (host) mapping. */
167 RTGCPTR GCPtrApicBase;
168 RTGCPTR pGCPadding0; /**< Alignment padding */
169#endif
170 /** The current switcher.
171 * This will be set before the VMM is fully initialized. */
172 VMMSWITCHER enmSwitcher;
173 /** Array of offsets to the different switchers within the core code. */
174 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
175 /** Flag to disable the switcher permanently (VMX) (boolean) */
176 bool fSwitcherDisabled;
177
178 /** Host to guest switcher entry point. */
179 R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0HostToGuest;
180 /** Guest to host switcher entry point. */
181 GCPTRTYPE(PFNVMMSWITCHERGC) pfnGCGuestToHost;
182 /** Call Trampoline. See vmmGCCallTrampoline(). */
183 RTGCPTR pfnGCCallTrampoline;
184
185 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
186 RTGCPTR pfnCPUMGCResumeGuest;
187 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
188 RTGCPTR pfnCPUMGCResumeGuestV86;
189 /** The last GC return code. */
190 RTINT iLastGCRc;
191#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
192 uint32_t u32Padding0; /**< Alignment padding. */
193#endif
194
195 /** VMM stack, pointer to the top of the stack in HC.
196 * Stack is allocated from the hypervisor heap and is page aligned
197 * and always writable in GC. */
198 HCPTRTYPE(uint8_t *) pbHCStack;
199 /** Pointer to the bottom of the stack - needed for doing relocations. */
200 GCPTRTYPE(uint8_t *) pbGCStack;
201 /** Pointer to the bottom of the stack - needed for doing relocations. */
202 GCPTRTYPE(uint8_t *) pbGCStackBottom;
203
204 /** Pointer to the GC logger instance - GC Ptr.
205 * This is NULL if logging is disabled. */
206 GCPTRTYPE(PRTLOGGERGC) pLoggerGC;
207 /** Size of the allocated logger instance (pLoggerGC/pLoggerHC). */
208 RTUINT cbLoggerGC;
209 /** Pointer to the GC logger instance - HC Ptr.
210 * This is NULL if logging is disabled. */
211 HCPTRTYPE(PRTLOGGERGC) pLoggerHC;
212
213 /** Pointer to the R0 logger instance.
214 * This is NULL if logging is disabled. */
215 HCPTRTYPE(PVMMR0LOGGER) pR0Logger;
216
217#ifdef VBOX_WITH_GC_AND_R0_RELEASE_LOG
218 /** Pointer to the GC release logger instance - GC Ptr. */
219 GCPTRTYPE(PRTLOGGERGC) pRelLoggerGC;
220 /** Size of the allocated release logger instance (pRelLoggerGC/pRelLoggerHC).
221 * This may differ from cbLoggerGC. */
222 RTUINT cbRelLoggerGC;
223 /** Pointer to the GC release logger instance - HC Ptr. */
224 HCPTRTYPE(PRTLOGGERGC) pRelLoggerHC;
225#endif /* VBOX_WITH_GC_AND_R0_RELEASE_LOG */
226
227 /** Global VM critical section. */
228 RTCRITSECT CritSectVMLock;
229
230 /** The EMT yield timer. */
231 PTMTIMERHC pYieldTimer;
232 /** The period to the next timeout when suspended or stopped.
233 * This is 0 when running. */
234 uint32_t cYieldResumeMillies;
235 /** The EMT yield timer interval (milliseconds). */
236 uint32_t cYieldEveryMillies;
237#if HC_ARCH_BITS == 32
238 uint32_t u32Padding0; /**< Alignment padding. */
239#endif
240 /** The timestamp of the previous yield. (nano) */
241 uint64_t u64LastYield;
242
243 /** @name CallHost
244 * @{ */
245 /** The pending operation. */
246 VMMCALLHOST enmCallHostOperation;
247 /** The result of the last operation. */
248 int32_t rcCallHost;
249 /** The argument to the operation. */
250 uint64_t u64CallHostArg;
251 /** The Ring-0 jmp buffer. */
252 VMMR0JMPBUF CallHostR0JmpBuf;
253 /** @} */
254
255 /** Number of VMMR0_DO_RUN_GC calls. */
256 STAMCOUNTER StatRunGC;
257 /** Statistics for each of the GC return codes.
258 * @{ */
259 STAMCOUNTER StatGCRetNormal;
260 STAMCOUNTER StatGCRetInterrupt;
261 STAMCOUNTER StatGCRetInterruptHyper;
262 STAMCOUNTER StatGCRetGuestTrap;
263 STAMCOUNTER StatGCRetRingSwitch;
264 STAMCOUNTER StatGCRetRingSwitchInt;
265 STAMCOUNTER StatGCRetExceptionPrivilege;
266 STAMCOUNTER StatGCRetStaleSelector;
267 STAMCOUNTER StatGCRetIRETTrap;
268 STAMCOUNTER StatGCRetEmulate;
269 STAMCOUNTER StatGCRetPatchEmulate;
270 STAMCOUNTER StatGCRetIORead;
271 STAMCOUNTER StatGCRetIOWrite;
272 STAMCOUNTER StatGCRetIOReadWrite;
273 STAMCOUNTER StatGCRetMMIORead;
274 STAMCOUNTER StatGCRetMMIOWrite;
275 STAMCOUNTER StatGCRetMMIOPatchRead;
276 STAMCOUNTER StatGCRetMMIOPatchWrite;
277 STAMCOUNTER StatGCRetMMIOReadWrite;
278 STAMCOUNTER StatGCRetLDTFault;
279 STAMCOUNTER StatGCRetGDTFault;
280 STAMCOUNTER StatGCRetIDTFault;
281 STAMCOUNTER StatGCRetTSSFault;
282 STAMCOUNTER StatGCRetPDFault;
283 STAMCOUNTER StatGCRetCSAMTask;
284 STAMCOUNTER StatGCRetSyncCR3;
285 STAMCOUNTER StatGCRetMisc;
286 STAMCOUNTER StatGCRetPatchInt3;
287 STAMCOUNTER StatGCRetPatchPF;
288 STAMCOUNTER StatGCRetPatchGP;
289 STAMCOUNTER StatGCRetPatchIretIRQ;
290 STAMCOUNTER StatGCRetPageOverflow;
291 STAMCOUNTER StatGCRetRescheduleREM;
292 STAMCOUNTER StatGCRetToR3;
293 STAMCOUNTER StatGCRetTimerPending;
294 STAMCOUNTER StatGCRetInterruptPending;
295 STAMCOUNTER StatGCRetCallHost;
296 STAMCOUNTER StatGCRetPATMDuplicateFn;
297 STAMCOUNTER StatGCRetPGMChangeMode;
298 STAMCOUNTER StatGCRetEmulHlt;
299 STAMCOUNTER StatGCRetPendingRequest;
300 STAMCOUNTER StatGCRetPGMGrowRAM;
301 STAMCOUNTER StatGCRetPDMLock;
302 STAMCOUNTER StatGCRetLogFlush;
303 STAMCOUNTER StatGCRetPDMQueueFlush;
304 STAMCOUNTER StatGCRetPGMPoolGrow;
305 STAMCOUNTER StatGCRetRemReplay;
306 STAMCOUNTER StatGCRetVMSetError;
307 STAMCOUNTER StatGCRetVMSetRuntimeError;
308 STAMCOUNTER StatGCRetPGMLock;
309
310 /** @} */
311
312
313} VMM, *PVMM;
314
315
316/**
317 * The VMMGCEntry() codes.
318 */
319typedef enum VMMGCOPERATION
320{
321 /** Do GC module init. */
322 VMMGC_DO_VMMGC_INIT = 1,
323
324 /** The first Trap testcase. */
325 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
326 /** Trap 0 testcases, uArg selects the variation. */
327 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
328 /** Trap 1 testcases, uArg selects the variation. */
329 VMMGC_DO_TESTCASE_TRAP_1,
330 /** Trap 2 testcases, uArg selects the variation. */
331 VMMGC_DO_TESTCASE_TRAP_2,
332 /** Trap 3 testcases, uArg selects the variation. */
333 VMMGC_DO_TESTCASE_TRAP_3,
334 /** Trap 4 testcases, uArg selects the variation. */
335 VMMGC_DO_TESTCASE_TRAP_4,
336 /** Trap 5 testcases, uArg selects the variation. */
337 VMMGC_DO_TESTCASE_TRAP_5,
338 /** Trap 6 testcases, uArg selects the variation. */
339 VMMGC_DO_TESTCASE_TRAP_6,
340 /** Trap 7 testcases, uArg selects the variation. */
341 VMMGC_DO_TESTCASE_TRAP_7,
342 /** Trap 8 testcases, uArg selects the variation. */
343 VMMGC_DO_TESTCASE_TRAP_8,
344 /** Trap 9 testcases, uArg selects the variation. */
345 VMMGC_DO_TESTCASE_TRAP_9,
346 /** Trap 0a testcases, uArg selects the variation. */
347 VMMGC_DO_TESTCASE_TRAP_0A,
348 /** Trap 0b testcases, uArg selects the variation. */
349 VMMGC_DO_TESTCASE_TRAP_0B,
350 /** Trap 0c testcases, uArg selects the variation. */
351 VMMGC_DO_TESTCASE_TRAP_0C,
352 /** Trap 0d testcases, uArg selects the variation. */
353 VMMGC_DO_TESTCASE_TRAP_0D,
354 /** Trap 0e testcases, uArg selects the variation. */
355 VMMGC_DO_TESTCASE_TRAP_0E,
356 /** The last trap testcase (exclusive). */
357 VMMGC_DO_TESTCASE_TRAP_LAST,
358 /** Testcase for checking interrupt forwarding. */
359 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
360 /** Switching testing and profiling stub. */
361 VMMGC_DO_TESTCASE_NOP,
362 /** Testcase for checking interrupt masking.. */
363 VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
364 /** Switching testing and profiling stub. */
365 VMMGC_DO_TESTCASE_HWACCM_NOP,
366
367 /** The usual 32-bit hack. */
368 VMMGC_DO_32_BIT_HACK = 0x7fffffff
369} VMMGCOPERATION;
370
371
372__BEGIN_DECLS
373
374
375#ifdef IN_RING0
376/**
377 * World switcher assembly routine.
378 * It will call VMMGCEntry().
379 *
380 * @returns return code from VMMGCEntry().
381 * @param pVM The VM in question.
382 * @param uArg See VMMGCEntry().
383 * @internal
384 */
385DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
386
387/**
388 * Callback function for vmmR0CallHostSetJmp.
389 *
390 * @returns VBox status code.
391 * @param pVM The VM handle.
392 */
393typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
394/** Pointer to FNVMMR0SETJMP(). */
395typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
396
397/**
398 * The setjmp variant used for calling Ring-3.
399 *
400 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
401 * in the middle of a ring-3 call. Another differences is the function pointer and
402 * argument. This has to do with resuming code and the stack frame of the caller.
403 *
404 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
405 * @param pJmpBuf The jmp_buf to set.
406 * @param pfn The function to be called when not resuming..
407 * @param pVM The argument of that function.
408 */
409DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
410
411/**
412 * Worker for VMMR0CallHost.
413 * This will save the stack and registers.
414 *
415 * @returns rc.
416 * @param pJmpBuf Pointer to the jump buffer.
417 * @param rc The return code.
418 */
419DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
420
421/**
422 * Internal R0 logger worker: Logger wrapper.
423 */
424VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
425
426/**
427 * Internal R0 logger worker: Flush logger.
428 *
429 * @param pLogger The logger instance to flush.
430 * @remark This function must be exported!
431 */
432VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
433
434#endif /* IN_RING0 */
435
436
437#ifdef IN_GC
438/**
439 * Internal GC logger worker: Logger wrapper.
440 */
441VMMGCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
442
443/**
444 * Internal GC release logger worker: Logger wrapper.
445 */
446VMMGCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
447
448/**
449 * Internal GC logger worker: Flush logger.
450 *
451 * @returns VINF_SUCCESS.
452 * @param pLogger The logger instance to flush.
453 * @remark This function must be exported!
454 */
455VMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERGC pLogger);
456
457/** @name Trap testcases and related labels.
458 * @{ */
459DECLASM(void) vmmGCEnableWP(void);
460DECLASM(void) vmmGCDisableWP(void);
461DECLASM(int) vmmGCTestTrap3(void);
462DECLASM(int) vmmGCTestTrap8(void);
463DECLASM(int) vmmGCTestTrap0d(void);
464DECLASM(int) vmmGCTestTrap0e(void);
465DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
466DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
467/** @} */
468
469#endif /* IN_GC */
470
471__END_DECLS
472
473/** @} */
474
475#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