1 | /* $Id: EMHandleRCTmpl.h 92519 2021-11-20 00:09:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * EM - emR3[Raw|Hm|Nem]HandleRC template.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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 VMM_INCLUDED_SRC_include_EMHandleRCTmpl_h
|
---|
19 | #define VMM_INCLUDED_SRC_include_EMHandleRCTmpl_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #if defined(EMHANDLERC_WITH_PATM) + defined(EMHANDLERC_WITH_HM) + defined(EMHANDLERC_WITH_NEM) != 1
|
---|
25 | # error "Exactly one of these must be defined: EMHANDLERC_WITH_PATM, EMHANDLERC_WITH_HM, EMHANDLERC_WITH_NEM"
|
---|
26 | #endif
|
---|
27 |
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Process a subset of the raw-mode, HM and NEM return codes.
|
---|
31 | *
|
---|
32 | * Since we have to share this with raw-mode single stepping, this inline
|
---|
33 | * function has been created to avoid code duplication.
|
---|
34 | *
|
---|
35 | * @returns VINF_SUCCESS if it's ok to continue raw mode.
|
---|
36 | * @returns VBox status code to return to the EM main loop.
|
---|
37 | *
|
---|
38 | * @param pVM The cross context VM structure.
|
---|
39 | * @param pVCpu The cross context virtual CPU structure.
|
---|
40 | * @param rc The return code.
|
---|
41 | */
|
---|
42 | #if defined(EMHANDLERC_WITH_HM) || defined(DOXYGEN_RUNNING)
|
---|
43 | int emR3HmHandleRC(PVM pVM, PVMCPU pVCpu, int rc)
|
---|
44 | #elif defined(EMHANDLERC_WITH_NEM)
|
---|
45 | int emR3NemHandleRC(PVM pVM, PVMCPU pVCpu, int rc)
|
---|
46 | #endif
|
---|
47 | {
|
---|
48 | switch (rc)
|
---|
49 | {
|
---|
50 | /*
|
---|
51 | * Common & simple ones.
|
---|
52 | */
|
---|
53 | case VINF_SUCCESS:
|
---|
54 | break;
|
---|
55 | case VINF_EM_RESCHEDULE_RAW:
|
---|
56 | case VINF_EM_RESCHEDULE_HM:
|
---|
57 | case VINF_EM_RAW_INTERRUPT:
|
---|
58 | case VINF_EM_RAW_TO_R3:
|
---|
59 | case VINF_EM_RAW_TIMER_PENDING:
|
---|
60 | case VINF_EM_PENDING_REQUEST:
|
---|
61 | rc = VINF_SUCCESS;
|
---|
62 | break;
|
---|
63 |
|
---|
64 | #ifndef EMHANDLERC_WITH_NEM
|
---|
65 | /*
|
---|
66 | * Conflict or out of page tables.
|
---|
67 | *
|
---|
68 | * VM_FF_PGM_SYNC_CR3 is set by the hypervisor and all we need to
|
---|
69 | * do here is to execute the pending forced actions.
|
---|
70 | */
|
---|
71 | case VINF_PGM_SYNC_CR3:
|
---|
72 | AssertMsg(VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL),
|
---|
73 | ("VINF_PGM_SYNC_CR3 and no VMCPU_FF_PGM_SYNC_CR3*!\n"));
|
---|
74 | rc = VINF_SUCCESS;
|
---|
75 | break;
|
---|
76 |
|
---|
77 | /*
|
---|
78 | * PGM pool flush pending (guest SMP only).
|
---|
79 | */
|
---|
80 | /** @todo jumping back and forth between ring 0 and 3 can burn a lot of cycles
|
---|
81 | * if the EMT thread that's supposed to handle the flush is currently not active
|
---|
82 | * (e.g. waiting to be scheduled) -> fix this properly!
|
---|
83 | *
|
---|
84 | * bird: Since the clearing is global and done via a rendezvous any CPU can do
|
---|
85 | * it. They would have to choose who to call VMMR3EmtRendezvous and send
|
---|
86 | * the rest to VMMR3EmtRendezvousFF ... Hmm ... that's not going to work
|
---|
87 | * all that well since the latter will race the setup done by the
|
---|
88 | * first. Guess that means we need some new magic in that area for
|
---|
89 | * handling this case. :/
|
---|
90 | */
|
---|
91 | case VINF_PGM_POOL_FLUSH_PENDING:
|
---|
92 | rc = VINF_SUCCESS;
|
---|
93 | break;
|
---|
94 | #endif /* !EMHANDLERC_WITH_NEM */
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * I/O Port access - emulate the instruction.
|
---|
98 | */
|
---|
99 | case VINF_IOM_R3_IOPORT_READ:
|
---|
100 | case VINF_IOM_R3_IOPORT_WRITE:
|
---|
101 | case VINF_EM_RESUME_R3_HISTORY_EXEC: /* Resume EMHistoryExec after VMCPU_FF_IOM. */
|
---|
102 | rc = emR3ExecuteIOInstruction(pVM, pVCpu);
|
---|
103 | break;
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * Execute pending I/O Port access.
|
---|
107 | */
|
---|
108 | case VINF_EM_PENDING_R3_IOPORT_WRITE:
|
---|
109 | rc = VBOXSTRICTRC_TODO(emR3ExecutePendingIoPortWrite(pVM, pVCpu));
|
---|
110 | break;
|
---|
111 | case VINF_EM_PENDING_R3_IOPORT_READ:
|
---|
112 | rc = VBOXSTRICTRC_TODO(emR3ExecutePendingIoPortRead(pVM, pVCpu));
|
---|
113 | break;
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Memory mapped I/O access - emulate the instruction.
|
---|
117 | */
|
---|
118 | case VINF_IOM_R3_MMIO_READ:
|
---|
119 | case VINF_IOM_R3_MMIO_WRITE:
|
---|
120 | case VINF_IOM_R3_MMIO_READ_WRITE:
|
---|
121 | rc = emR3ExecuteInstruction(pVM, pVCpu, "MMIO");
|
---|
122 | break;
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * Machine specific register access - emulate the instruction.
|
---|
126 | */
|
---|
127 | case VINF_CPUM_R3_MSR_READ:
|
---|
128 | case VINF_CPUM_R3_MSR_WRITE:
|
---|
129 | rc = emR3ExecuteInstruction(pVM, pVCpu, "MSR");
|
---|
130 | break;
|
---|
131 |
|
---|
132 | /*
|
---|
133 | * GIM hypercall.
|
---|
134 | */
|
---|
135 | case VINF_GIM_R3_HYPERCALL:
|
---|
136 | rc = emR3ExecuteInstruction(pVM, pVCpu, "Hypercall");
|
---|
137 | break;
|
---|
138 |
|
---|
139 | #ifdef EMHANDLERC_WITH_HM
|
---|
140 | case VINF_EM_HM_PATCH_TPR_INSTR:
|
---|
141 | rc = HMR3PatchTprInstr(pVM, pVCpu);
|
---|
142 | break;
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | case VINF_EM_RAW_GUEST_TRAP:
|
---|
146 | case VINF_EM_RAW_EMULATE_INSTR:
|
---|
147 | Assert(!TRPMHasTrap(pVCpu)); /* We're directly executing instructions below without respecting any pending traps! */
|
---|
148 | rc = emR3ExecuteInstruction(pVM, pVCpu, "EMUL: ");
|
---|
149 | break;
|
---|
150 |
|
---|
151 | case VINF_EM_RAW_INJECT_TRPM_EVENT:
|
---|
152 | CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_XCPT_MASK);
|
---|
153 | rc = VBOXSTRICTRC_VAL(IEMInjectTrpmEvent(pVCpu));
|
---|
154 | /* The following condition should be removed when IEM_IMPLEMENTS_TASKSWITCH becomes true. */
|
---|
155 | if (rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED)
|
---|
156 | rc = emR3ExecuteInstruction(pVM, pVCpu, "EVENT: ");
|
---|
157 | break;
|
---|
158 |
|
---|
159 | case VINF_EM_EMULATE_SPLIT_LOCK:
|
---|
160 | rc = VBOXSTRICTRC_TODO(emR3ExecuteSplitLockInstruction(pVM, pVCpu));
|
---|
161 | break;
|
---|
162 |
|
---|
163 |
|
---|
164 | /*
|
---|
165 | * Up a level.
|
---|
166 | */
|
---|
167 | case VINF_EM_TERMINATE:
|
---|
168 | case VINF_EM_OFF:
|
---|
169 | case VINF_EM_RESET:
|
---|
170 | case VINF_EM_SUSPEND:
|
---|
171 | case VINF_EM_HALT:
|
---|
172 | case VINF_EM_RESUME:
|
---|
173 | case VINF_EM_NO_MEMORY:
|
---|
174 | case VINF_EM_RESCHEDULE:
|
---|
175 | case VINF_EM_RESCHEDULE_REM:
|
---|
176 | case VINF_EM_WAIT_SIPI:
|
---|
177 | break;
|
---|
178 |
|
---|
179 | /*
|
---|
180 | * Up a level and invoke the debugger.
|
---|
181 | */
|
---|
182 | case VINF_EM_DBG_STEPPED:
|
---|
183 | case VINF_EM_DBG_BREAKPOINT:
|
---|
184 | case VINF_EM_DBG_STEP:
|
---|
185 | case VINF_EM_DBG_HYPER_BREAKPOINT:
|
---|
186 | case VINF_EM_DBG_HYPER_STEPPED:
|
---|
187 | case VINF_EM_DBG_HYPER_ASSERTION:
|
---|
188 | case VINF_EM_DBG_STOP:
|
---|
189 | case VINF_EM_DBG_EVENT:
|
---|
190 | break;
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * Up a level, dump and debug.
|
---|
194 | */
|
---|
195 | case VERR_TRPM_DONT_PANIC:
|
---|
196 | case VERR_TRPM_PANIC:
|
---|
197 | case VERR_VMM_RING0_ASSERTION:
|
---|
198 | case VINF_EM_TRIPLE_FAULT:
|
---|
199 | case VERR_VMM_HYPER_CR3_MISMATCH:
|
---|
200 | case VERR_VMM_RING3_CALL_DISABLED:
|
---|
201 | case VERR_IEM_INSTR_NOT_IMPLEMENTED:
|
---|
202 | case VERR_IEM_ASPECT_NOT_IMPLEMENTED:
|
---|
203 | case VERR_EM_GUEST_CPU_HANG:
|
---|
204 | break;
|
---|
205 |
|
---|
206 | #ifdef EMHANDLERC_WITH_HM
|
---|
207 | /*
|
---|
208 | * Up a level, after Hm have done some release logging.
|
---|
209 | */
|
---|
210 | case VERR_VMX_INVALID_VMCS_FIELD:
|
---|
211 | case VERR_VMX_INVALID_VMCS_PTR:
|
---|
212 | case VERR_VMX_INVALID_VMXON_PTR:
|
---|
213 | case VERR_VMX_UNEXPECTED_INTERRUPTION_EXIT_TYPE:
|
---|
214 | case VERR_VMX_UNEXPECTED_EXCEPTION:
|
---|
215 | case VERR_VMX_UNEXPECTED_EXIT:
|
---|
216 | case VERR_VMX_INVALID_GUEST_STATE:
|
---|
217 | case VERR_VMX_UNABLE_TO_START_VM:
|
---|
218 | case VERR_SVM_UNKNOWN_EXIT:
|
---|
219 | case VERR_SVM_UNEXPECTED_EXIT:
|
---|
220 | case VERR_SVM_UNEXPECTED_PATCH_TYPE:
|
---|
221 | case VERR_SVM_UNEXPECTED_XCPT_EXIT:
|
---|
222 | HMR3CheckError(pVM, rc);
|
---|
223 | break;
|
---|
224 |
|
---|
225 | /* Up a level; fatal */
|
---|
226 | case VERR_VMX_IN_VMX_ROOT_MODE:
|
---|
227 | case VERR_SVM_IN_USE:
|
---|
228 | case VERR_SVM_UNABLE_TO_START_VM:
|
---|
229 | break;
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | #ifdef EMHANDLERC_WITH_NEM
|
---|
233 | /* Fatal stuff, up a level. */
|
---|
234 | case VERR_NEM_IPE_0:
|
---|
235 | case VERR_NEM_IPE_1:
|
---|
236 | case VERR_NEM_IPE_2:
|
---|
237 | case VERR_NEM_IPE_3:
|
---|
238 | case VERR_NEM_IPE_4:
|
---|
239 | case VERR_NEM_IPE_5:
|
---|
240 | case VERR_NEM_IPE_6:
|
---|
241 | case VERR_NEM_IPE_7:
|
---|
242 | case VERR_NEM_IPE_8:
|
---|
243 | case VERR_NEM_IPE_9:
|
---|
244 | break;
|
---|
245 | #endif
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * These two should be handled via the force flag already, but just in
|
---|
249 | * case they end up here deal with it.
|
---|
250 | */
|
---|
251 | case VINF_IOM_R3_IOPORT_COMMIT_WRITE:
|
---|
252 | case VINF_IOM_R3_MMIO_COMMIT_WRITE:
|
---|
253 | AssertFailed();
|
---|
254 | rc = VBOXSTRICTRC_TODO(IOMR3ProcessForceFlag(pVM, pVCpu, rc));
|
---|
255 | break;
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * Anything which is not known to us means an internal error
|
---|
259 | * and the termination of the VM!
|
---|
260 | */
|
---|
261 | default:
|
---|
262 | AssertMsgFailed(("Unknown GC return code: %Rra\n", rc));
|
---|
263 | break;
|
---|
264 | }
|
---|
265 | return rc;
|
---|
266 | }
|
---|
267 |
|
---|
268 | #endif /* !VMM_INCLUDED_SRC_include_EMHandleRCTmpl_h */
|
---|
269 |
|
---|