VirtualBox

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

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

string.h & stdio.h + header cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.0 KB
Line 
1/* $Id: VMMInternal.h 23 2007-01-15 14:08:28Z 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 uint32_t ebx;
105 uint32_t esi;
106 uint32_t edi;
107 uint32_t ebp;
108 uint32_t esp;
109 uint32_t eip;
110 /** @} */
111
112 /** Flag that indicates that we've done a ring-3 call. */
113 bool fInRing3Call;
114 /** Pointer to the buffer used to save the stack.
115 * This is assumed to be 8KB. */
116 void *pvSavedStack;
117 /** The number of bytes we've saved. */
118 uint32_t cbSavedStack;
119 /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
120 uint32_t espCheck;
121 /** The esp we should resume execution with after the restore. */
122 uint32_t espResume;
123} VMMR0JMPBUF, *PVMMR0JMPBUF;
124
125
126/**
127 * VMM Data (part of VMM)
128 */
129typedef struct VMM
130{
131 /** Offset to the VM structure.
132 * See VMM2VM(). */
133 RTINT offVM;
134
135 /** Size of the core code. */
136 RTUINT cbCoreCode;
137 /** Physical address of core code. */
138 RTHCPHYS HCPhysCoreCode;
139/** @todo pvHCCoreCodeR3 -> pvCoreCodeR3, pvHCCoreCodeR0 -> pvCoreCodeR0 */
140 /** Pointer to core code ring-3 mapping - contiguous memory.
141 * At present this only means the context switcher code. */
142 RTHCPTR pvHCCoreCodeR3;
143 /** Pointer to core code ring-0 mapping - contiguous memory.
144 * At present this only means the context switcher code. */
145 RTHCPTR pvHCCoreCodeR0;
146 /** Pointer to core code guest context mapping. */
147 RTGCPTR pvGCCoreCode;
148#ifdef VBOX_WITH_NMI
149 /** The guest context address of the APIC (host) mapping. */
150 RTGCPTR GCPtrApicBase;
151 RTGCPTR pGCPadding0; /**< Alignment padding */
152#endif
153 /** The current switcher.
154 * This will be set before the VMM is fully initialized. */
155 VMMSWITCHER enmSwitcher;
156 /** Array of offsets to the different switchers within the core code. */
157 RTUINT aoffSwitchers[VMMSWITCHER_MAX];
158 /** Flag to disable the switcher permanently (VMX) (boolean) */
159 bool fSwitcherDisabled;
160
161 /** Host to guest switcher entry point. */
162 R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0HostToGuest;
163 /** Guest to host switcher entry point. */
164 GCPTRTYPE(PFNVMMSWITCHERGC) pfnGCGuestToHost;
165 /** Call Trampoline. See vmmGCCallTrampoline(). */
166 RTGCPTR pfnGCCallTrampoline;
167
168 /** Resume Guest Execution. See CPUMGCResumeGuest(). */
169 RTGCPTR pfnCPUMGCResumeGuest;
170 /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
171 RTGCPTR pfnCPUMGCResumeGuestV86;
172 /** The last GC return code. */
173 RTINT iLastGCRc;
174#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
175 uint32_t u32Padding0; /**< Alignment padding. */
176#endif
177
178 /** VMM stack, pointer to the top of the stack in HC.
179 * Stack is allocated from the hypervisor heap and is page aligned
180 * and always writable in GC. */
181 HCPTRTYPE(uint8_t *) pbHCStack;
182 /** Pointer to the bottom of the stack - needed for doing relocations. */
183 GCPTRTYPE(uint8_t *) pbGCStack;
184 /** Pointer to the bottom of the stack - needed for doing relocations. */
185 GCPTRTYPE(uint8_t *) pbGCStackBottom;
186
187 /** Pointer to the GC logger instance - GC Ptr.
188 * This is NULL if logging is disabled. */
189 GCPTRTYPE(PRTLOGGERGC) pLoggerGC;
190 /** Size of the allocated logger instance (pLoggerGC/pLoggerHC). */
191 RTUINT cbLoggerGC;
192 /** Pointer to the GC logger instance - HC Ptr.
193 * This is NULL if logging is disabled. */
194 HCPTRTYPE(PRTLOGGERGC) pLoggerHC;
195
196 /** Pointer to the R0 logger instance.
197 * This is NULL if logging is disabled. */
198 HCPTRTYPE(PVMMR0LOGGER) pR0Logger;
199
200#ifdef VBOX_WITH_GC_AND_R0_RELEASE_LOG
201 /** Pointer to the GC release logger instance - GC Ptr. */
202 GCPTRTYPE(PRTLOGGERGC) pRelLoggerGC;
203 /** Size of the allocated release logger instance (pRelLoggerGC/pRelLoggerHC).
204 * This may differ from cbLoggerGC. */
205 RTUINT cbRelLoggerGC;
206 /** Pointer to the GC release logger instance - HC Ptr. */
207 HCPTRTYPE(PRTLOGGERGC) pRelLoggerHC;
208#endif /* VBOX_WITH_GC_AND_R0_RELEASE_LOG */
209
210 /** Global VM critical section. */
211 RTCRITSECT CritSectVMLock;
212
213 /** The EMT yield timer. */
214 PTMTIMERHC pYieldTimer;
215 /** The period to the next timeout when suspended or stopped.
216 * This is 0 when running. */
217 uint32_t cYieldResumeMillies;
218 /** The EMT yield timer interval (milliseconds). */
219 uint32_t cYieldEveryMillies;
220
221 /** @name CallHost
222 * @{ */
223 /** The pending operation. */
224 VMMCALLHOST enmCallHostOperation;
225 /** The result of the last operation. */
226 int32_t rcCallHost;
227 /** The argument to the operation. */
228 uint64_t u64CallHostArg;
229 /** The Ring-0 jmp buffer. */
230 VMMR0JMPBUF CallHostR0JmpBuf;
231 /** @} */
232
233 /* on VC these members are qword aligned! */
234 //uint32_t u32Padding[1];
235 /** Number of VMMR0_DO_RUN_GC calls. */
236 STAMCOUNTER StatRunGC;
237 /** Statistics for each of the GC return codes.
238 * @{ */
239 STAMCOUNTER StatGCRetNormal;
240 STAMCOUNTER StatGCRetInterrupt;
241 STAMCOUNTER StatGCRetInterruptHyper;
242 STAMCOUNTER StatGCRetGuestTrap;
243 STAMCOUNTER StatGCRetRingSwitch;
244 STAMCOUNTER StatGCRetRingSwitchInt;
245 STAMCOUNTER StatGCRetExceptionPrivilege;
246 STAMCOUNTER StatGCRetStaleSelector;
247 STAMCOUNTER StatGCRetIRETTrap;
248 STAMCOUNTER StatGCRetEmulate;
249 STAMCOUNTER StatGCRetPatchEmulate;
250 STAMCOUNTER StatGCRetIORead;
251 STAMCOUNTER StatGCRetIOWrite;
252 STAMCOUNTER StatGCRetIOReadWrite;
253 STAMCOUNTER StatGCRetMMIORead;
254 STAMCOUNTER StatGCRetMMIOWrite;
255 STAMCOUNTER StatGCRetMMIOPatchRead;
256 STAMCOUNTER StatGCRetMMIOPatchWrite;
257 STAMCOUNTER StatGCRetMMIOReadWrite;
258 STAMCOUNTER StatGCRetLDTFault;
259 STAMCOUNTER StatGCRetGDTFault;
260 STAMCOUNTER StatGCRetIDTFault;
261 STAMCOUNTER StatGCRetTSSFault;
262 STAMCOUNTER StatGCRetPDFault;
263 STAMCOUNTER StatGCRetCSAMTask;
264 STAMCOUNTER StatGCRetSyncCR3;
265 STAMCOUNTER StatGCRetMisc;
266 STAMCOUNTER StatGCRetPatchInt3;
267 STAMCOUNTER StatGCRetPatchPF;
268 STAMCOUNTER StatGCRetPatchGP;
269 STAMCOUNTER StatGCRetPageOverflow;
270 STAMCOUNTER StatGCRetRescheduleREM;
271 STAMCOUNTER StatGCRetToR3;
272 STAMCOUNTER StatGCRetTimerPending;
273 STAMCOUNTER StatGCRetInterruptPending;
274 STAMCOUNTER StatGCRetCallHost;
275 STAMCOUNTER StatGCRetPATMDuplicateFn;
276 STAMCOUNTER StatGCRetPGMChangeMode;
277 STAMCOUNTER StatGCRetEmulHlt;
278 STAMCOUNTER StatGCRetPendingRequest;
279 STAMCOUNTER StatGCRetPGMGrowRAM;
280 STAMCOUNTER StatGCRetPDMLock;
281 STAMCOUNTER StatGCRetLogFlush;
282 STAMCOUNTER StatGCRetPDMQueueFlush;
283 STAMCOUNTER StatGCRetPGMPoolGrow;
284 STAMCOUNTER StatGCRetRemReplay;
285 STAMCOUNTER StatGCRetVMSetError;
286 STAMCOUNTER StatGCRetPGMLock;
287
288 /** @} */
289
290
291} VMM, *PVMM;
292
293
294/**
295 * The VMMGCEntry() codes.
296 */
297typedef enum VMMGCOPERATION
298{
299 /** Do GC module init. */
300 VMMGC_DO_VMMGC_INIT = 1,
301
302 /** The first Trap testcase. */
303 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
304 /** Trap 0 testcases, uArg selects the variation. */
305 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
306 /** Trap 1 testcases, uArg selects the variation. */
307 VMMGC_DO_TESTCASE_TRAP_1,
308 /** Trap 2 testcases, uArg selects the variation. */
309 VMMGC_DO_TESTCASE_TRAP_2,
310 /** Trap 3 testcases, uArg selects the variation. */
311 VMMGC_DO_TESTCASE_TRAP_3,
312 /** Trap 4 testcases, uArg selects the variation. */
313 VMMGC_DO_TESTCASE_TRAP_4,
314 /** Trap 5 testcases, uArg selects the variation. */
315 VMMGC_DO_TESTCASE_TRAP_5,
316 /** Trap 6 testcases, uArg selects the variation. */
317 VMMGC_DO_TESTCASE_TRAP_6,
318 /** Trap 7 testcases, uArg selects the variation. */
319 VMMGC_DO_TESTCASE_TRAP_7,
320 /** Trap 8 testcases, uArg selects the variation. */
321 VMMGC_DO_TESTCASE_TRAP_8,
322 /** Trap 9 testcases, uArg selects the variation. */
323 VMMGC_DO_TESTCASE_TRAP_9,
324 /** Trap 0a testcases, uArg selects the variation. */
325 VMMGC_DO_TESTCASE_TRAP_0A,
326 /** Trap 0b testcases, uArg selects the variation. */
327 VMMGC_DO_TESTCASE_TRAP_0B,
328 /** Trap 0c testcases, uArg selects the variation. */
329 VMMGC_DO_TESTCASE_TRAP_0C,
330 /** Trap 0d testcases, uArg selects the variation. */
331 VMMGC_DO_TESTCASE_TRAP_0D,
332 /** Trap 0e testcases, uArg selects the variation. */
333 VMMGC_DO_TESTCASE_TRAP_0E,
334 /** The last trap testcase (exclusive). */
335 VMMGC_DO_TESTCASE_TRAP_LAST,
336 /** Testcase for checking interrupt forwarding. */
337 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
338 /** Switching testing and profiling stub. */
339 VMMGC_DO_TESTCASE_NOP,
340
341 /** The usual 32-bit hack. */
342 VMMGC_DO_32_BIT_HACK = 0x7fffffff
343} VMMGCOPERATION;
344
345
346__BEGIN_DECLS
347
348
349#ifdef IN_RING0
350/**
351 * World switcher assembly routine.
352 * It will call VMMGCEntry().
353 *
354 * @returns return code from VMMGCEntry().
355 * @param pVM The VM in question.
356 * @param uArg See VMMGCEntry().
357 * @internal
358 */
359DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
360
361/**
362 * Callback function for vmmR0CallHostSetJmp.
363 *
364 * @returns VBox status code.
365 * @param pVM The VM handle.
366 */
367typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
368/** Pointer to FNVMMR0SETJMP(). */
369typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
370
371/**
372 * The setjmp variant used for calling Ring-3.
373 *
374 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
375 * in the middle of a ring-3 call. Another differences is the function pointer and
376 * argument. This has to do with resuming code and the stack frame of the caller.
377 *
378 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
379 * @param pJmpBuf The jmp_buf to set.
380 * @param pfn The function to be called when not resuming..
381 * @param pVM The argument of that function.
382 */
383DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
384
385/**
386 * Worker for VMMR0CallHost.
387 * This will save the stack and registers.
388 *
389 * @returns rc.
390 * @param pJmpBuf Pointer to the jump buffer.
391 * @param rc The return code.
392 */
393DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
394
395/**
396 * Internal R0 logger worker: Logger wrapper.
397 */
398VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
399
400/**
401 * Internal R0 logger worker: Flush logger.
402 *
403 * @param pLogger The logger instance to flush.
404 * @remark This function must be exported!
405 */
406VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
407
408#endif /* IN_RING0 */
409
410
411#ifdef IN_GC
412/**
413 * Internal GC logger worker: Logger wrapper.
414 */
415VMMGCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
416
417/**
418 * Internal GC release logger worker: Logger wrapper.
419 */
420VMMGCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
421
422/**
423 * Internal GC logger worker: Flush logger.
424 *
425 * @returns VINF_SUCCESS.
426 * @param pLogger The logger instance to flush.
427 * @remark This function must be exported!
428 */
429VMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERGC pLogger);
430
431/** @name Trap testcases
432 * @{ */
433DECLASM(void) vmmGCEnableWP(void);
434DECLASM(void) vmmGCDisableWP(void);
435DECLASM(int) vmmGCTestTrap3(void);
436DECLASM(int) vmmGCTestTrap8(void);
437DECLASM(int) vmmGCTestTrap0d(void);
438DECLASM(int) vmmGCTestTrap0e(void);
439/** @} */
440
441#endif /* IN_GC */
442
443__END_DECLS
444
445/** @} */
446
447#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