VirtualBox

source: vbox/trunk/src/VBox/VMM/EMHandleRCTmpl.h@ 28800

Last change on this file since 28800 was 28800, checked in by vboxsync, 14 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* $Id: EMHandleRCTmpl.h 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * EM - emR3[Raw|Hwaccm]HandleRC template.
4 */
5
6/*
7 * Copyright (C) 2006-2009 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 ___EMHandleRCTmpl_h
19#define ___EMHandleRCTmpl_h
20
21/**
22 * Process a subset of the raw-mode return code.
23 *
24 * Since we have to share this with raw-mode single stepping, this inline
25 * function has been created to avoid code duplication.
26 *
27 * @returns VINF_SUCCESS if it's ok to continue raw mode.
28 * @returns VBox status code to return to the EM main loop.
29 *
30 * @param pVM The VM handle
31 * @param pVCpu The VMCPU handle
32 * @param rc The return code.
33 * @param pCtx The guest cpu context.
34 */
35#ifdef EMHANDLERC_WITH_PATM
36int emR3RawHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc)
37#elif defined(EMHANDLERC_WITH_HWACCM)
38int emR3HwaccmHandleRC(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc)
39#endif
40{
41 switch (rc)
42 {
43 /*
44 * Common & simple ones.
45 */
46 case VINF_SUCCESS:
47 break;
48 case VINF_EM_RESCHEDULE_RAW:
49 case VINF_EM_RESCHEDULE_HWACC:
50 case VINF_EM_RAW_INTERRUPT:
51 case VINF_EM_RAW_TO_R3:
52 case VINF_EM_RAW_TIMER_PENDING:
53 case VINF_EM_PENDING_REQUEST:
54 rc = VINF_SUCCESS;
55 break;
56
57#ifdef EMHANDLERC_WITH_PATM
58 /*
59 * Privileged instruction.
60 */
61 case VINF_EM_RAW_EXCEPTION_PRIVILEGED:
62 case VINF_PATM_PATCH_TRAP_GP:
63 rc = emR3RawPrivileged(pVM, pVCpu);
64 break;
65
66 case VINF_EM_RAW_GUEST_TRAP:
67 /*
68 * Got a trap which needs dispatching.
69 */
70 if (PATMR3IsInsidePatchJump(pVM, pCtx->eip, NULL))
71 {
72 AssertReleaseMsgFailed(("FATAL ERROR: executing random instruction inside generated patch jump %08X\n", CPUMGetGuestEIP(pVCpu)));
73 rc = VERR_EM_RAW_PATCH_CONFLICT;
74 break;
75 }
76 rc = emR3RawGuestTrap(pVM, pVCpu);
77 break;
78
79 /*
80 * Trap in patch code.
81 */
82 case VINF_PATM_PATCH_TRAP_PF:
83 case VINF_PATM_PATCH_INT3:
84 rc = emR3PatchTrap(pVM, pVCpu, pCtx, rc);
85 break;
86
87 case VINF_PATM_DUPLICATE_FUNCTION:
88 Assert(PATMIsPatchGCAddr(pVM, pCtx->eip));
89 rc = PATMR3DuplicateFunctionRequest(pVM, pCtx);
90 AssertRC(rc);
91 rc = VINF_SUCCESS;
92 break;
93
94 case VINF_PATM_CHECK_PATCH_PAGE:
95 rc = PATMR3HandleMonitoredPage(pVM);
96 AssertRC(rc);
97 rc = VINF_SUCCESS;
98 break;
99
100 /*
101 * Patch manager.
102 */
103 case VERR_EM_RAW_PATCH_CONFLICT:
104 AssertReleaseMsgFailed(("%Rrc handling is not yet implemented\n", rc));
105 break;
106#endif /* EMHANDLERC_WITH_PATM */
107
108#ifdef VBOX_WITH_VMI
109 /*
110 * PARAV function.
111 */
112 case VINF_EM_RESCHEDULE_PARAV:
113 rc = PARAVCallFunction(pVM);
114 break;
115#endif
116
117#ifdef EMHANDLERC_WITH_PATM
118 /*
119 * Memory mapped I/O access - attempt to patch the instruction
120 */
121 case VINF_PATM_HC_MMIO_PATCH_READ:
122 rc = PATMR3InstallPatch(pVM, SELMToFlat(pVM, DIS_SELREG_CS, CPUMCTX2CORE(pCtx), pCtx->eip),
123 PATMFL_MMIO_ACCESS | ((SELMGetCpuModeFromSelector(pVM, pCtx->eflags, pCtx->cs, &pCtx->csHid) == CPUMODE_32BIT) ? PATMFL_CODE32 : 0));
124 if (RT_FAILURE(rc))
125 rc = emR3ExecuteInstruction(pVM, pVCpu, "MMIO");
126 break;
127
128 case VINF_PATM_HC_MMIO_PATCH_WRITE:
129 AssertFailed(); /* not yet implemented. */
130 rc = emR3ExecuteInstruction(pVM, pVCpu, "MMIO");
131 break;
132#endif /* EMHANDLERC_WITH_PATM */
133
134 /*
135 * Conflict or out of page tables.
136 *
137 * VM_FF_PGM_SYNC_CR3 is set by the hypervisor and all we need to
138 * do here is to execute the pending forced actions.
139 */
140 case VINF_PGM_SYNC_CR3:
141 AssertMsg(VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL),
142 ("VINF_PGM_SYNC_CR3 and no VMCPU_FF_PGM_SYNC_CR3*!\n"));
143 rc = VINF_SUCCESS;
144 break;
145
146 /*
147 * PGM pool flush pending (guest SMP only).
148 */
149 /** @todo jumping back and forth between ring 0 and 3 can burn a lot of cycles
150 * if the EMT thread that's supposed to handle the flush is currently not active
151 * (e.g. waiting to be scheduled) -> fix this properly!
152 *
153 * bird: Since the clearing is global and done via a rendezvous any CPU can do
154 * it. They would have to choose who to call VMMR3EmtRendezvous and send
155 * the rest to VMMR3EmtRendezvousFF ... Hmm ... that's not going to work
156 * all that well since the the latter will race the setup done by the
157 * first. Guess that means we need some new magic in that area for
158 * handling this case. :/
159 */
160 case VINF_PGM_POOL_FLUSH_PENDING:
161 rc = VINF_SUCCESS;
162 break;
163
164 /*
165 * Paging mode change.
166 */
167 case VINF_PGM_CHANGE_MODE:
168 rc = PGMChangeMode(pVCpu, pCtx->cr0, pCtx->cr4, pCtx->msrEFER);
169 if (rc == VINF_SUCCESS)
170 rc = VINF_EM_RESCHEDULE;
171 AssertMsg(RT_FAILURE(rc) || (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST), ("%Rrc\n", rc));
172 break;
173
174#ifdef EMHANDLERC_WITH_PATM
175 /*
176 * CSAM wants to perform a task in ring-3. It has set an FF action flag.
177 */
178 case VINF_CSAM_PENDING_ACTION:
179 rc = VINF_SUCCESS;
180 break;
181
182 /*
183 * Invoked Interrupt gate - must directly (!) go to the recompiler.
184 */
185 case VINF_EM_RAW_INTERRUPT_PENDING:
186 case VINF_EM_RAW_RING_SWITCH_INT:
187 Assert(TRPMHasTrap(pVCpu));
188 Assert(!PATMIsPatchGCAddr(pVM, pCtx->eip));
189
190 if (TRPMHasTrap(pVCpu))
191 {
192 /* If the guest gate is marked unpatched, then we will check again if we can patch it. */
193 uint8_t u8Interrupt = TRPMGetTrapNo(pVCpu);
194 if (TRPMR3GetGuestTrapHandler(pVM, u8Interrupt) == TRPM_INVALID_HANDLER)
195 {
196 CSAMR3CheckGates(pVM, u8Interrupt, 1);
197 Log(("emR3RawHandleRC: recheck gate %x -> valid=%d\n", u8Interrupt, TRPMR3GetGuestTrapHandler(pVM, u8Interrupt) != TRPM_INVALID_HANDLER));
198 /* Note: If it was successful, then we could go back to raw mode, but let's keep things simple for now. */
199 }
200 }
201 rc = VINF_EM_RESCHEDULE_REM;
202 break;
203
204 /*
205 * Other ring switch types.
206 */
207 case VINF_EM_RAW_RING_SWITCH:
208 rc = emR3RawRingSwitch(pVM, pVCpu);
209 break;
210#endif /* EMHANDLERC_WITH_PATM */
211
212 /*
213 * I/O Port access - emulate the instruction.
214 */
215 case VINF_IOM_HC_IOPORT_READ:
216 case VINF_IOM_HC_IOPORT_WRITE:
217 rc = emR3ExecuteIOInstruction(pVM, pVCpu);
218 break;
219
220 /*
221 * Memory mapped I/O access - emulate the instruction.
222 */
223 case VINF_IOM_HC_MMIO_READ:
224 case VINF_IOM_HC_MMIO_WRITE:
225 case VINF_IOM_HC_MMIO_READ_WRITE:
226 rc = emR3ExecuteInstruction(pVM, pVCpu, "MMIO");
227 break;
228
229#ifdef EMHANDLERC_WITH_HWACCM
230 /*
231 * (MM)IO intensive code block detected; fall back to the recompiler for better performance
232 */
233 case VINF_EM_RAW_EMULATE_IO_BLOCK:
234 rc = HWACCMR3EmulateIoBlock(pVM, pCtx);
235 break;
236
237 case VINF_EM_HWACCM_PATCH_TPR_INSTR:
238 rc = HWACCMR3PatchTprInstr(pVM, pVCpu, pCtx);
239 break;
240#endif
241
242#ifdef EMHANDLERC_WITH_PATM
243 /*
244 * Execute instruction.
245 */
246 case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
247 rc = emR3ExecuteInstruction(pVM, pVCpu, "LDT FAULT: ");
248 break;
249 case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
250 rc = emR3ExecuteInstruction(pVM, pVCpu, "GDT FAULT: ");
251 break;
252 case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
253 rc = emR3ExecuteInstruction(pVM, pVCpu, "IDT FAULT: ");
254 break;
255 case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
256 rc = emR3ExecuteInstruction(pVM, pVCpu, "TSS FAULT: ");
257 break;
258 case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
259 rc = emR3ExecuteInstruction(pVM, pVCpu, "PD FAULT: ");
260 break;
261 case VINF_EM_RAW_EMULATE_INSTR_HLT:
262 /** @todo skip instruction and go directly to the halt state. (see REM for implementation details) */
263 rc = emR3RawPrivileged(pVM, pVCpu);
264 break;
265#endif
266
267#ifdef EMHANDLERC_WITH_PATM
268 case VINF_PATM_PENDING_IRQ_AFTER_IRET:
269 rc = emR3ExecuteInstruction(pVM, pVCpu, "EMUL: ", VINF_PATM_PENDING_IRQ_AFTER_IRET);
270 break;
271
272 case VINF_PATCH_EMULATE_INSTR:
273#else
274 case VINF_EM_RAW_GUEST_TRAP:
275#endif
276 case VINF_EM_RAW_EMULATE_INSTR:
277 rc = emR3ExecuteInstruction(pVM, pVCpu, "EMUL: ");
278 break;
279
280#ifdef EMHANDLERC_WITH_PATM
281 /*
282 * Stale selector and iret traps => REM.
283 */
284 case VINF_EM_RAW_STALE_SELECTOR:
285 case VINF_EM_RAW_IRET_TRAP:
286 /* We will not go to the recompiler if EIP points to patch code. */
287 if (PATMIsPatchGCAddr(pVM, pCtx->eip))
288 {
289 pCtx->eip = PATMR3PatchToGCPtr(pVM, (RTGCPTR)pCtx->eip, 0);
290 }
291 LogFlow(("emR3RawHandleRC: %Rrc -> %Rrc\n", rc, VINF_EM_RESCHEDULE_REM));
292 rc = VINF_EM_RESCHEDULE_REM;
293 break;
294#endif
295
296 /*
297 * Up a level.
298 */
299 case VINF_EM_TERMINATE:
300 case VINF_EM_OFF:
301 case VINF_EM_RESET:
302 case VINF_EM_SUSPEND:
303 case VINF_EM_HALT:
304 case VINF_EM_RESUME:
305 case VINF_EM_NO_MEMORY:
306 case VINF_EM_RESCHEDULE:
307 case VINF_EM_RESCHEDULE_REM:
308 case VINF_EM_WAIT_SIPI:
309 break;
310
311 /*
312 * Up a level and invoke the debugger.
313 */
314 case VINF_EM_DBG_STEPPED:
315 case VINF_EM_DBG_BREAKPOINT:
316 case VINF_EM_DBG_STEP:
317 case VINF_EM_DBG_HYPER_BREAKPOINT:
318 case VINF_EM_DBG_HYPER_STEPPED:
319 case VINF_EM_DBG_HYPER_ASSERTION:
320 case VINF_EM_DBG_STOP:
321 break;
322
323 /*
324 * Up a level, dump and debug.
325 */
326 case VERR_TRPM_DONT_PANIC:
327 case VERR_TRPM_PANIC:
328 case VERR_VMM_RING0_ASSERTION:
329 case VERR_VMM_HYPER_CR3_MISMATCH:
330 case VERR_VMM_RING3_CALL_DISABLED:
331 break;
332
333#ifdef EMHANDLERC_WITH_HWACCM
334 /*
335 * Up a level, after HwAccM have done some release logging.
336 */
337 case VERR_VMX_INVALID_VMCS_FIELD:
338 case VERR_VMX_INVALID_VMCS_PTR:
339 case VERR_VMX_INVALID_VMXON_PTR:
340 case VERR_VMX_UNEXPECTED_INTERRUPTION_EXIT_CODE:
341 case VERR_VMX_UNEXPECTED_EXCEPTION:
342 case VERR_VMX_UNEXPECTED_EXIT_CODE:
343 case VERR_VMX_INVALID_GUEST_STATE:
344 case VERR_VMX_UNABLE_TO_START_VM:
345 case VERR_VMX_UNABLE_TO_RESUME_VM:
346 HWACCMR3CheckError(pVM, rc);
347 break;
348
349 /* Up a level; fatal */
350 case VERR_VMX_IN_VMX_ROOT_MODE:
351 case VERR_SVM_IN_USE:
352 break;
353#endif
354
355 /*
356 * Anything which is not known to us means an internal error
357 * and the termination of the VM!
358 */
359 default:
360 AssertMsgFailed(("Unknown GC return code: %Rra\n", rc));
361 break;
362 }
363 return rc;
364}
365
366#endif
367
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use