VirtualBox

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

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

64-bit.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.4 KB
Line 
1/* $Id: VMMInternal.h 140 2007-01-18 15:28:16Z 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#endif
112#if HC_ARCH_BITS == 64
113 uint64_t rbx;
114# ifdef __WIN__
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 void *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 RTHCPTR pvHCCoreCodeR3;
159 /** Pointer to core code ring-0 mapping - contiguous memory.
160 * At present this only means the context switcher code. */
161 RTHCPTR 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
237 /** @name CallHost
238 * @{ */
239 /** The pending operation. */
240 VMMCALLHOST enmCallHostOperation;
241 /** The result of the last operation. */
242 int32_t rcCallHost;
243 /** The argument to the operation. */
244 uint64_t u64CallHostArg;
245 /** The Ring-0 jmp buffer. */
246 VMMR0JMPBUF CallHostR0JmpBuf;
247 /** @} */
248
249 /* on VC these members are qword aligned! */
250 //uint32_t u32Padding[1];
251 /** Number of VMMR0_DO_RUN_GC calls. */
252 STAMCOUNTER StatRunGC;
253 /** Statistics for each of the GC return codes.
254 * @{ */
255 STAMCOUNTER StatGCRetNormal;
256 STAMCOUNTER StatGCRetInterrupt;
257 STAMCOUNTER StatGCRetInterruptHyper;
258 STAMCOUNTER StatGCRetGuestTrap;
259 STAMCOUNTER StatGCRetRingSwitch;
260 STAMCOUNTER StatGCRetRingSwitchInt;
261 STAMCOUNTER StatGCRetExceptionPrivilege;
262 STAMCOUNTER StatGCRetStaleSelector;
263 STAMCOUNTER StatGCRetIRETTrap;
264 STAMCOUNTER StatGCRetEmulate;
265 STAMCOUNTER StatGCRetPatchEmulate;
266 STAMCOUNTER StatGCRetIORead;
267 STAMCOUNTER StatGCRetIOWrite;
268 STAMCOUNTER StatGCRetIOReadWrite;
269 STAMCOUNTER StatGCRetMMIORead;
270 STAMCOUNTER StatGCRetMMIOWrite;
271 STAMCOUNTER StatGCRetMMIOPatchRead;
272 STAMCOUNTER StatGCRetMMIOPatchWrite;
273 STAMCOUNTER StatGCRetMMIOReadWrite;
274 STAMCOUNTER StatGCRetLDTFault;
275 STAMCOUNTER StatGCRetGDTFault;
276 STAMCOUNTER StatGCRetIDTFault;
277 STAMCOUNTER StatGCRetTSSFault;
278 STAMCOUNTER StatGCRetPDFault;
279 STAMCOUNTER StatGCRetCSAMTask;
280 STAMCOUNTER StatGCRetSyncCR3;
281 STAMCOUNTER StatGCRetMisc;
282 STAMCOUNTER StatGCRetPatchInt3;
283 STAMCOUNTER StatGCRetPatchPF;
284 STAMCOUNTER StatGCRetPatchGP;
285 STAMCOUNTER StatGCRetPageOverflow;
286 STAMCOUNTER StatGCRetRescheduleREM;
287 STAMCOUNTER StatGCRetToR3;
288 STAMCOUNTER StatGCRetTimerPending;
289 STAMCOUNTER StatGCRetInterruptPending;
290 STAMCOUNTER StatGCRetCallHost;
291 STAMCOUNTER StatGCRetPATMDuplicateFn;
292 STAMCOUNTER StatGCRetPGMChangeMode;
293 STAMCOUNTER StatGCRetEmulHlt;
294 STAMCOUNTER StatGCRetPendingRequest;
295 STAMCOUNTER StatGCRetPGMGrowRAM;
296 STAMCOUNTER StatGCRetPDMLock;
297 STAMCOUNTER StatGCRetLogFlush;
298 STAMCOUNTER StatGCRetPDMQueueFlush;
299 STAMCOUNTER StatGCRetPGMPoolGrow;
300 STAMCOUNTER StatGCRetRemReplay;
301 STAMCOUNTER StatGCRetVMSetError;
302 STAMCOUNTER StatGCRetPGMLock;
303
304 /** @} */
305
306
307} VMM, *PVMM;
308
309
310/**
311 * The VMMGCEntry() codes.
312 */
313typedef enum VMMGCOPERATION
314{
315 /** Do GC module init. */
316 VMMGC_DO_VMMGC_INIT = 1,
317
318 /** The first Trap testcase. */
319 VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
320 /** Trap 0 testcases, uArg selects the variation. */
321 VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
322 /** Trap 1 testcases, uArg selects the variation. */
323 VMMGC_DO_TESTCASE_TRAP_1,
324 /** Trap 2 testcases, uArg selects the variation. */
325 VMMGC_DO_TESTCASE_TRAP_2,
326 /** Trap 3 testcases, uArg selects the variation. */
327 VMMGC_DO_TESTCASE_TRAP_3,
328 /** Trap 4 testcases, uArg selects the variation. */
329 VMMGC_DO_TESTCASE_TRAP_4,
330 /** Trap 5 testcases, uArg selects the variation. */
331 VMMGC_DO_TESTCASE_TRAP_5,
332 /** Trap 6 testcases, uArg selects the variation. */
333 VMMGC_DO_TESTCASE_TRAP_6,
334 /** Trap 7 testcases, uArg selects the variation. */
335 VMMGC_DO_TESTCASE_TRAP_7,
336 /** Trap 8 testcases, uArg selects the variation. */
337 VMMGC_DO_TESTCASE_TRAP_8,
338 /** Trap 9 testcases, uArg selects the variation. */
339 VMMGC_DO_TESTCASE_TRAP_9,
340 /** Trap 0a testcases, uArg selects the variation. */
341 VMMGC_DO_TESTCASE_TRAP_0A,
342 /** Trap 0b testcases, uArg selects the variation. */
343 VMMGC_DO_TESTCASE_TRAP_0B,
344 /** Trap 0c testcases, uArg selects the variation. */
345 VMMGC_DO_TESTCASE_TRAP_0C,
346 /** Trap 0d testcases, uArg selects the variation. */
347 VMMGC_DO_TESTCASE_TRAP_0D,
348 /** Trap 0e testcases, uArg selects the variation. */
349 VMMGC_DO_TESTCASE_TRAP_0E,
350 /** The last trap testcase (exclusive). */
351 VMMGC_DO_TESTCASE_TRAP_LAST,
352 /** Testcase for checking interrupt forwarding. */
353 VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
354 /** Switching testing and profiling stub. */
355 VMMGC_DO_TESTCASE_NOP,
356
357 /** The usual 32-bit hack. */
358 VMMGC_DO_32_BIT_HACK = 0x7fffffff
359} VMMGCOPERATION;
360
361
362__BEGIN_DECLS
363
364
365#ifdef IN_RING0
366/**
367 * World switcher assembly routine.
368 * It will call VMMGCEntry().
369 *
370 * @returns return code from VMMGCEntry().
371 * @param pVM The VM in question.
372 * @param uArg See VMMGCEntry().
373 * @internal
374 */
375DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
376
377/**
378 * Callback function for vmmR0CallHostSetJmp.
379 *
380 * @returns VBox status code.
381 * @param pVM The VM handle.
382 */
383typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
384/** Pointer to FNVMMR0SETJMP(). */
385typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
386
387/**
388 * The setjmp variant used for calling Ring-3.
389 *
390 * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
391 * in the middle of a ring-3 call. Another differences is the function pointer and
392 * argument. This has to do with resuming code and the stack frame of the caller.
393 *
394 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
395 * @param pJmpBuf The jmp_buf to set.
396 * @param pfn The function to be called when not resuming..
397 * @param pVM The argument of that function.
398 */
399DECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
400
401/**
402 * Worker for VMMR0CallHost.
403 * This will save the stack and registers.
404 *
405 * @returns rc.
406 * @param pJmpBuf Pointer to the jump buffer.
407 * @param rc The return code.
408 */
409DECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
410
411/**
412 * Internal R0 logger worker: Logger wrapper.
413 */
414VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
415
416/**
417 * Internal R0 logger worker: Flush logger.
418 *
419 * @param pLogger The logger instance to flush.
420 * @remark This function must be exported!
421 */
422VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
423
424#endif /* IN_RING0 */
425
426
427#ifdef IN_GC
428/**
429 * Internal GC logger worker: Logger wrapper.
430 */
431VMMGCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
432
433/**
434 * Internal GC release logger worker: Logger wrapper.
435 */
436VMMGCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
437
438/**
439 * Internal GC logger worker: Flush logger.
440 *
441 * @returns VINF_SUCCESS.
442 * @param pLogger The logger instance to flush.
443 * @remark This function must be exported!
444 */
445VMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERGC pLogger);
446
447/** @name Trap testcases
448 * @{ */
449DECLASM(void) vmmGCEnableWP(void);
450DECLASM(void) vmmGCDisableWP(void);
451DECLASM(int) vmmGCTestTrap3(void);
452DECLASM(int) vmmGCTestTrap8(void);
453DECLASM(int) vmmGCTestTrap0d(void);
454DECLASM(int) vmmGCTestTrap0e(void);
455/** @} */
456
457#endif /* IN_GC */
458
459__END_DECLS
460
461/** @} */
462
463#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