~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/VMM/EMInternal.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: EMInternal.h $ */
2
 
/** @file
3
 
 * EM - Internal header file.
4
 
 */
5
 
 
6
 
/*
7
 
 * Copyright (C) 2006-2007 Oracle Corporation
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
 
 
18
 
#ifndef ___EMInternal_h
19
 
#define ___EMInternal_h
20
 
 
21
 
#include <VBox/cdefs.h>
22
 
#include <VBox/types.h>
23
 
#include <VBox/em.h>
24
 
#include <VBox/stam.h>
25
 
#include <VBox/patm.h>
26
 
#include <VBox/dis.h>
27
 
#include <VBox/pdmcritsect.h>
28
 
#include <iprt/avl.h>
29
 
#include <setjmp.h>
30
 
 
31
 
RT_C_DECLS_BEGIN
32
 
 
33
 
 
34
 
/** @defgroup grp_em_int       Internal
35
 
 * @ingroup grp_em
36
 
 * @internal
37
 
 * @{
38
 
 */
39
 
 
40
 
/** The saved state version. */
41
 
#define EM_SAVED_STATE_VERSION                          4
42
 
#define EM_SAVED_STATE_VERSION_PRE_MWAIT                3
43
 
#define EM_SAVED_STATE_VERSION_PRE_SMP                  2
44
 
 
45
 
 
46
 
/**
47
 
 * MWait state flags.
48
 
 */
49
 
/* MWait activated. */
50
 
#define EMMWAIT_FLAG_ACTIVE             RT_BIT(0)
51
 
/* MWait will continue when an interrupt is pending even when IF=0. */
52
 
#define EMMWAIT_FLAG_BREAKIRQIF0        RT_BIT(1)
53
 
/* Monitor instruction was executed previously. */
54
 
#define EMMWAIT_FLAG_MONITOR_ACTIVE     RT_BIT(2)
55
 
 
56
 
 
57
 
/**
58
 
 * Cli node structure
59
 
 */
60
 
typedef struct CLISTAT
61
 
{
62
 
    /** The key is the cli address. */
63
 
    AVLGCPTRNODECORE        Core;
64
 
#if HC_ARCH_BITS == 32 && !defined(RT_OS_WINDOWS)
65
 
    /** Padding. */
66
 
    uint32_t                u32Padding;
67
 
#endif
68
 
    /** Occurrences. */
69
 
    STAMCOUNTER             Counter;
70
 
} CLISTAT, *PCLISTAT;
71
 
#ifdef IN_RING3
72
 
AssertCompileMemberAlignment(CLISTAT, Counter, 8);
73
 
#endif
74
 
 
75
 
 
76
 
/**
77
 
 * Excessive EM statistics.
78
 
 */
79
 
typedef struct EMSTATS
80
 
{
81
 
    /** GC: Profiling of EMInterpretInstruction(). */
82
 
    STAMPROFILE             StatRZEmulate;
83
 
    /** HC: Profiling of EMInterpretInstruction(). */
84
 
    STAMPROFILE             StatR3Emulate;
85
 
 
86
 
    /** @name Interpreter Instruction statistics.
87
 
     * @{
88
 
     */
89
 
    STAMCOUNTER             StatRZInterpretSucceeded;
90
 
    STAMCOUNTER             StatR3InterpretSucceeded;
91
 
 
92
 
    STAMCOUNTER             StatRZAnd;
93
 
    STAMCOUNTER             StatR3And;
94
 
    STAMCOUNTER             StatRZCpuId;
95
 
    STAMCOUNTER             StatR3CpuId;
96
 
    STAMCOUNTER             StatRZDec;
97
 
    STAMCOUNTER             StatR3Dec;
98
 
    STAMCOUNTER             StatRZHlt;
99
 
    STAMCOUNTER             StatR3Hlt;
100
 
    STAMCOUNTER             StatRZInc;
101
 
    STAMCOUNTER             StatR3Inc;
102
 
    STAMCOUNTER             StatRZInvlPg;
103
 
    STAMCOUNTER             StatR3InvlPg;
104
 
    STAMCOUNTER             StatRZIret;
105
 
    STAMCOUNTER             StatR3Iret;
106
 
    STAMCOUNTER             StatRZLLdt;
107
 
    STAMCOUNTER             StatR3LLdt;
108
 
    STAMCOUNTER             StatRZLIdt;
109
 
    STAMCOUNTER             StatR3LIdt;
110
 
    STAMCOUNTER             StatRZLGdt;
111
 
    STAMCOUNTER             StatR3LGdt;
112
 
    STAMCOUNTER             StatRZMov;
113
 
    STAMCOUNTER             StatR3Mov;
114
 
    STAMCOUNTER             StatRZMovCRx;
115
 
    STAMCOUNTER             StatR3MovCRx;
116
 
    STAMCOUNTER             StatRZMovDRx;
117
 
    STAMCOUNTER             StatR3MovDRx;
118
 
    STAMCOUNTER             StatRZOr;
119
 
    STAMCOUNTER             StatR3Or;
120
 
    STAMCOUNTER             StatRZPop;
121
 
    STAMCOUNTER             StatR3Pop;
122
 
    STAMCOUNTER             StatRZSti;
123
 
    STAMCOUNTER             StatR3Sti;
124
 
    STAMCOUNTER             StatRZXchg;
125
 
    STAMCOUNTER             StatR3Xchg;
126
 
    STAMCOUNTER             StatRZXor;
127
 
    STAMCOUNTER             StatR3Xor;
128
 
    STAMCOUNTER             StatRZMonitor;
129
 
    STAMCOUNTER             StatR3Monitor;
130
 
    STAMCOUNTER             StatRZMWait;
131
 
    STAMCOUNTER             StatR3MWait;
132
 
    STAMCOUNTER             StatRZAdd;
133
 
    STAMCOUNTER             StatR3Add;
134
 
    STAMCOUNTER             StatRZSub;
135
 
    STAMCOUNTER             StatR3Sub;
136
 
    STAMCOUNTER             StatRZAdc;
137
 
    STAMCOUNTER             StatR3Adc;
138
 
    STAMCOUNTER             StatRZRdtsc;
139
 
    STAMCOUNTER             StatR3Rdtsc;
140
 
    STAMCOUNTER             StatRZRdpmc;
141
 
    STAMCOUNTER             StatR3Rdpmc;
142
 
    STAMCOUNTER             StatRZBtr;
143
 
    STAMCOUNTER             StatR3Btr;
144
 
    STAMCOUNTER             StatRZBts;
145
 
    STAMCOUNTER             StatR3Bts;
146
 
    STAMCOUNTER             StatRZBtc;
147
 
    STAMCOUNTER             StatR3Btc;
148
 
    STAMCOUNTER             StatRZCmpXchg;
149
 
    STAMCOUNTER             StatR3CmpXchg;
150
 
    STAMCOUNTER             StatRZCmpXchg8b;
151
 
    STAMCOUNTER             StatR3CmpXchg8b;
152
 
    STAMCOUNTER             StatRZXAdd;
153
 
    STAMCOUNTER             StatR3XAdd;
154
 
    STAMCOUNTER             StatRZClts;
155
 
    STAMCOUNTER             StatR3Clts;
156
 
    STAMCOUNTER             StatRZStosWD;
157
 
    STAMCOUNTER             StatR3StosWD;
158
 
    STAMCOUNTER             StatR3Rdmsr;
159
 
    STAMCOUNTER             StatR3Wrmsr;
160
 
    STAMCOUNTER             StatRZRdmsr;
161
 
    STAMCOUNTER             StatRZWrmsr;
162
 
    STAMCOUNTER             StatRZWbInvd;
163
 
    STAMCOUNTER             StatR3WbInvd;
164
 
    STAMCOUNTER             StatRZLmsw;
165
 
    STAMCOUNTER             StatR3Lmsw;
166
 
    STAMCOUNTER             StatRZSmsw;
167
 
    STAMCOUNTER             StatR3Smsw;
168
 
 
169
 
    STAMCOUNTER             StatRZInterpretFailed;
170
 
    STAMCOUNTER             StatR3InterpretFailed;
171
 
 
172
 
    STAMCOUNTER             StatRZFailedAnd;
173
 
    STAMCOUNTER             StatR3FailedAnd;
174
 
    STAMCOUNTER             StatRZFailedCpuId;
175
 
    STAMCOUNTER             StatR3FailedCpuId;
176
 
    STAMCOUNTER             StatRZFailedDec;
177
 
    STAMCOUNTER             StatR3FailedDec;
178
 
    STAMCOUNTER             StatRZFailedHlt;
179
 
    STAMCOUNTER             StatR3FailedHlt;
180
 
    STAMCOUNTER             StatRZFailedInc;
181
 
    STAMCOUNTER             StatR3FailedInc;
182
 
    STAMCOUNTER             StatRZFailedInvlPg;
183
 
    STAMCOUNTER             StatR3FailedInvlPg;
184
 
    STAMCOUNTER             StatRZFailedIret;
185
 
    STAMCOUNTER             StatR3FailedIret;
186
 
    STAMCOUNTER             StatRZFailedLLdt;
187
 
    STAMCOUNTER             StatR3FailedLLdt;
188
 
    STAMCOUNTER             StatRZFailedLGdt;
189
 
    STAMCOUNTER             StatR3FailedLGdt;
190
 
    STAMCOUNTER             StatRZFailedLIdt;
191
 
    STAMCOUNTER             StatR3FailedLIdt;
192
 
    STAMCOUNTER             StatRZFailedMisc;
193
 
    STAMCOUNTER             StatR3FailedMisc;
194
 
    STAMCOUNTER             StatRZFailedMov;
195
 
    STAMCOUNTER             StatR3FailedMov;
196
 
    STAMCOUNTER             StatRZFailedMovCRx;
197
 
    STAMCOUNTER             StatR3FailedMovCRx;
198
 
    STAMCOUNTER             StatRZFailedMovDRx;
199
 
    STAMCOUNTER             StatR3FailedMovDRx;
200
 
    STAMCOUNTER             StatRZFailedOr;
201
 
    STAMCOUNTER             StatR3FailedOr;
202
 
    STAMCOUNTER             StatRZFailedPop;
203
 
    STAMCOUNTER             StatR3FailedPop;
204
 
    STAMCOUNTER             StatRZFailedSti;
205
 
    STAMCOUNTER             StatR3FailedSti;
206
 
    STAMCOUNTER             StatRZFailedXchg;
207
 
    STAMCOUNTER             StatR3FailedXchg;
208
 
    STAMCOUNTER             StatRZFailedXor;
209
 
    STAMCOUNTER             StatR3FailedXor;
210
 
    STAMCOUNTER             StatRZFailedMonitor;
211
 
    STAMCOUNTER             StatR3FailedMonitor;
212
 
    STAMCOUNTER             StatRZFailedMWait;
213
 
    STAMCOUNTER             StatR3FailedMWait;
214
 
    STAMCOUNTER             StatR3FailedRdmsr;
215
 
    STAMCOUNTER             StatR3FailedWrmsr;
216
 
    STAMCOUNTER             StatRZFailedRdmsr;
217
 
    STAMCOUNTER             StatRZFailedWrmsr;
218
 
    STAMCOUNTER             StatRZFailedLmsw;
219
 
    STAMCOUNTER             StatR3FailedLmsw;
220
 
    STAMCOUNTER             StatRZFailedSmsw;
221
 
    STAMCOUNTER             StatR3FailedSmsw;
222
 
 
223
 
    STAMCOUNTER             StatRZFailedAdd;
224
 
    STAMCOUNTER             StatR3FailedAdd;
225
 
    STAMCOUNTER             StatRZFailedAdc;
226
 
    STAMCOUNTER             StatR3FailedAdc;
227
 
    STAMCOUNTER             StatRZFailedBtr;
228
 
    STAMCOUNTER             StatR3FailedBtr;
229
 
    STAMCOUNTER             StatRZFailedBts;
230
 
    STAMCOUNTER             StatR3FailedBts;
231
 
    STAMCOUNTER             StatRZFailedBtc;
232
 
    STAMCOUNTER             StatR3FailedBtc;
233
 
    STAMCOUNTER             StatRZFailedCli;
234
 
    STAMCOUNTER             StatR3FailedCli;
235
 
    STAMCOUNTER             StatRZFailedCmpXchg;
236
 
    STAMCOUNTER             StatR3FailedCmpXchg;
237
 
    STAMCOUNTER             StatRZFailedCmpXchg8b;
238
 
    STAMCOUNTER             StatR3FailedCmpXchg8b;
239
 
    STAMCOUNTER             StatRZFailedXAdd;
240
 
    STAMCOUNTER             StatR3FailedXAdd;
241
 
    STAMCOUNTER             StatR3FailedMovNTPS;
242
 
    STAMCOUNTER             StatRZFailedMovNTPS;
243
 
    STAMCOUNTER             StatRZFailedStosWD;
244
 
    STAMCOUNTER             StatR3FailedStosWD;
245
 
    STAMCOUNTER             StatRZFailedSub;
246
 
    STAMCOUNTER             StatR3FailedSub;
247
 
    STAMCOUNTER             StatRZFailedWbInvd;
248
 
    STAMCOUNTER             StatR3FailedWbInvd;
249
 
    STAMCOUNTER             StatRZFailedRdtsc;
250
 
    STAMCOUNTER             StatR3FailedRdtsc;
251
 
    STAMCOUNTER             StatRZFailedRdpmc;
252
 
    STAMCOUNTER             StatR3FailedRdpmc;
253
 
    STAMCOUNTER             StatRZFailedClts;
254
 
    STAMCOUNTER             StatR3FailedClts;
255
 
 
256
 
    STAMCOUNTER             StatRZFailedUserMode;
257
 
    STAMCOUNTER             StatR3FailedUserMode;
258
 
    STAMCOUNTER             StatRZFailedPrefix;
259
 
    STAMCOUNTER             StatR3FailedPrefix;
260
 
    /** @} */
261
 
 
262
 
    /** @name Privileged Instructions Ending Up In HC.
263
 
     * @{ */
264
 
    STAMCOUNTER             StatCli;
265
 
    STAMCOUNTER             StatSti;
266
 
    STAMCOUNTER             StatIn;
267
 
    STAMCOUNTER             StatIoRestarted;
268
 
    STAMCOUNTER             StatOut;
269
 
    STAMCOUNTER             StatInvlpg;
270
 
    STAMCOUNTER             StatHlt;
271
 
    STAMCOUNTER             StatMovReadCR[USE_REG_CR4 + 1];
272
 
    STAMCOUNTER             StatMovWriteCR[USE_REG_CR4 + 1];
273
 
    STAMCOUNTER             StatMovDRx;
274
 
    STAMCOUNTER             StatIret;
275
 
    STAMCOUNTER             StatMovLgdt;
276
 
    STAMCOUNTER             StatMovLldt;
277
 
    STAMCOUNTER             StatMovLidt;
278
 
    STAMCOUNTER             StatMisc;
279
 
    STAMCOUNTER             StatSysEnter;
280
 
    STAMCOUNTER             StatSysExit;
281
 
    STAMCOUNTER             StatSysCall;
282
 
    STAMCOUNTER             StatSysRet;
283
 
    /** @} */
284
 
 
285
 
} EMSTATS;
286
 
/** Pointer to the excessive EM statistics. */
287
 
typedef EMSTATS *PEMSTATS;
288
 
 
289
 
 
290
 
/**
291
 
 * Converts a EM pointer into a VM pointer.
292
 
 * @returns Pointer to the VM structure the EM is part of.
293
 
 * @param   pEM   Pointer to EM instance data.
294
 
 */
295
 
#define EM2VM(pEM)  ( (PVM)((char*)pEM - pEM->offVM) )
296
 
 
297
 
/**
298
 
 * EM VM Instance data.
299
 
 * Changes to this must checked against the padding of the cfgm union in VM!
300
 
 */
301
 
typedef struct EM
302
 
{
303
 
    /** Offset to the VM structure.
304
 
     * See EM2VM(). */
305
 
    RTUINT                  offVM;
306
 
 
307
 
    /** Id of the VCPU that last executed code in the recompiler. */
308
 
    VMCPUID                 idLastRemCpu;
309
 
 
310
 
    /** REM critical section.
311
 
     * This protects recompiler usage
312
 
     */
313
 
    PDMCRITSECT             CritSectREM;
314
 
} EM;
315
 
/** Pointer to EM VM instance data. */
316
 
typedef EM *PEM;
317
 
 
318
 
 
319
 
/**
320
 
 * EM VMCPU Instance data.
321
 
 */
322
 
typedef struct EMCPU
323
 
{
324
 
    /** Offset to the VM structure.
325
 
     * See EMCPU2VM(). */
326
 
    RTUINT                  offVMCPU;
327
 
 
328
 
    /** Execution Manager State. */
329
 
    EMSTATE volatile        enmState;
330
 
 
331
 
    /** Previous Execution Manager State. */
332
 
    EMSTATE                 enmPrevState;
333
 
 
334
 
    /** Force raw-mode execution.
335
 
     * This is used to prevent REM from trying to execute patch code.
336
 
     * The flag is cleared upon entering emR3RawExecute() and updated in certain return paths. */
337
 
    bool                    fForceRAW;
338
 
 
339
 
    uint8_t                 u8Padding[3];
340
 
 
341
 
    /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
342
 
    RTGCUINTPTR             GCPtrInhibitInterrupts;
343
 
 
344
 
    /** Pointer to the PATM status structure. (R3 Ptr) */
345
 
    R3PTRTYPE(PPATMGCSTATE) pPatmGCState;
346
 
 
347
 
    /** Pointer to the guest CPUM state. (R3 Ptr) */
348
 
    R3PTRTYPE(PCPUMCTX)     pCtx;
349
 
 
350
 
#if GC_ARCH_BITS == 64
351
 
    RTGCPTR                 aPadding1;
352
 
#endif
353
 
 
354
 
    /* MWait halt state. */
355
 
    struct
356
 
    {
357
 
        uint32_t            fWait;          /* type of mwait; see EMMWAIT_FLAG_* */
358
 
        uint32_t            a32Padding[1];
359
 
        RTGCPTR             uMWaitEAX;      /* mwait hints */
360
 
        RTGCPTR             uMWaitECX;      /* mwait extensions */
361
 
        RTGCPTR             uMonitorEAX;    /* monitored address. */
362
 
        RTGCPTR             uMonitorECX;    /* monitor extension. */
363
 
        RTGCPTR             uMonitorEDX;    /* monitor hint. */
364
 
    } mwait;
365
 
 
366
 
    union
367
 
    {
368
 
        /** Padding used in the other rings.
369
 
         * This must be larger than jmp_buf on any supported platform. */
370
 
        char                achPaddingFatalLongJump[HC_ARCH_BITS == 32 ? 176 : 256];
371
 
#ifdef IN_RING3
372
 
        /** Long buffer jump for fatal VM errors.
373
 
         * It will jump to before the outer EM loop is entered. */
374
 
        jmp_buf             FatalLongJump;
375
 
#endif
376
 
    } u;
377
 
 
378
 
    /** For saving stack space, the disassembler state is allocated here instead of
379
 
     * on the stack.
380
 
     * @note The DISCPUSTATE structure is not R3/R0/RZ clean!  */
381
 
    union
382
 
    {
383
 
        /** The disassembler scratch space. */
384
 
        DISCPUSTATE         DisState;
385
 
        /** Padding. */
386
 
        uint8_t             abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
387
 
    };
388
 
 
389
 
    /** @name Execution profiling.
390
 
     * @{ */
391
 
    STAMPROFILE             StatForcedActions;
392
 
    STAMPROFILE             StatHalted;
393
 
    STAMPROFILEADV          StatHwAccEntry;
394
 
    STAMPROFILE             StatHwAccExec;
395
 
    STAMPROFILE             StatREMEmu;
396
 
    STAMPROFILE             StatREMExec;
397
 
    STAMPROFILE             StatREMSync;
398
 
    STAMPROFILEADV          StatREMTotal;
399
 
    STAMPROFILE             StatRAWExec;
400
 
    STAMPROFILEADV          StatRAWEntry;
401
 
    STAMPROFILEADV          StatRAWTail;
402
 
    STAMPROFILEADV          StatRAWTotal;
403
 
    STAMPROFILEADV          StatTotal;
404
 
    /** @} */
405
 
 
406
 
    /** R3: Profiling of emR3RawExecuteIOInstruction. */
407
 
    STAMPROFILE             StatIOEmu;
408
 
    /** R3: Profiling of emR3RawPrivileged. */
409
 
    STAMPROFILE             StatPrivEmu;
410
 
    /** R3: Number of time emR3HwAccExecute is called. */
411
 
    STAMCOUNTER             StatHwAccExecuteEntry;
412
 
 
413
 
    /** More statistics (R3). */
414
 
    R3PTRTYPE(PEMSTATS)     pStatsR3;
415
 
    /** More statistics (R0). */
416
 
    R0PTRTYPE(PEMSTATS)     pStatsR0;
417
 
    /** More statistics (RC). */
418
 
    RCPTRTYPE(PEMSTATS)     pStatsRC;
419
 
#if HC_ARCH_BITS == 64
420
 
    RTRCPTR                 padding0;
421
 
#endif
422
 
 
423
 
    /** Tree for keeping track of cli occurances (debug only). */
424
 
    R3PTRTYPE(PAVLGCPTRNODECORE) pCliStatTree;
425
 
    STAMCOUNTER             StatTotalClis;
426
 
#if 0
427
 
    /** 64-bit Visual C++ rounds the struct size up to 16 byte. */
428
 
    uint64_t                padding1;
429
 
#endif
430
 
} EMCPU;
431
 
/** Pointer to EM VM instance data. */
432
 
typedef EMCPU *PEMCPU;
433
 
 
434
 
/** @} */
435
 
 
436
 
 
437
 
int     emR3HwAccExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
438
 
int     emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
439
 
int     emR3RawHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
440
 
int     emR3HwaccmHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
441
 
EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
442
 
int     emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
443
 
int     emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
444
 
int     emR3RawUpdateForceFlag(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
445
 
int     emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
446
 
int     emR3RawStep(PVM pVM, PVMCPU pVCpu);
447
 
int     emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
448
 
 
449
 
RT_C_DECLS_END
450
 
 
451
 
#endif
452