1 | ; $Id: VMMRCA.asm 49893 2013-12-13 00:40:20Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; VMMGC - Raw-mode Context Virtual Machine Monitor assembly routines.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2012 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 | ;*******************************************************************************
|
---|
19 | ;* Header Files *
|
---|
20 | ;*******************************************************************************
|
---|
21 | %include "VBox/asmdefs.mac"
|
---|
22 | %include "iprt/x86.mac"
|
---|
23 | %include "VBox/sup.mac"
|
---|
24 | %include "VBox/vmm/vm.mac"
|
---|
25 | %include "VMMInternal.mac"
|
---|
26 | %include "VMMRC.mac"
|
---|
27 |
|
---|
28 |
|
---|
29 | ;*******************************************************************************
|
---|
30 | ;* Defined Constants And Macros *
|
---|
31 | ;*******************************************************************************
|
---|
32 | ;; save all registers before loading special values for the faulting.
|
---|
33 | %macro SaveAndLoadAll 0
|
---|
34 | pushad
|
---|
35 | push ds
|
---|
36 | push es
|
---|
37 | push fs
|
---|
38 | push gs
|
---|
39 | call NAME(vmmGCTestLoadRegs)
|
---|
40 | %endmacro
|
---|
41 |
|
---|
42 | ;; restore all registers after faulting.
|
---|
43 | %macro RestoreAll 0
|
---|
44 | pop gs
|
---|
45 | pop fs
|
---|
46 | pop es
|
---|
47 | pop ds
|
---|
48 | popad
|
---|
49 | %endmacro
|
---|
50 |
|
---|
51 |
|
---|
52 | ;*******************************************************************************
|
---|
53 | ;* External Symbols *
|
---|
54 | ;*******************************************************************************
|
---|
55 | extern IMPNAME(g_VM)
|
---|
56 | extern IMPNAME(g_Logger)
|
---|
57 | extern IMPNAME(g_RelLogger)
|
---|
58 | extern NAME(RTLogLogger)
|
---|
59 | extern NAME(vmmRCProbeFireHelper)
|
---|
60 | extern NAME(TRPMRCTrapHyperHandlerSetEIP)
|
---|
61 |
|
---|
62 |
|
---|
63 | BEGINCODE
|
---|
64 |
|
---|
65 | ;/**
|
---|
66 | ; * Internal GC logger worker: Logger wrapper.
|
---|
67 | ; */
|
---|
68 | ;VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
|
---|
69 | EXPORTEDNAME vmmGCLoggerWrapper
|
---|
70 | %ifdef __YASM__
|
---|
71 | %ifdef ASM_FORMAT_ELF
|
---|
72 | push dword IMP(g_Logger) ; YASM BUG #67! YASMCHECK!
|
---|
73 | %else
|
---|
74 | push IMP(g_Logger)
|
---|
75 | %endif
|
---|
76 | %else
|
---|
77 | push IMP(g_Logger)
|
---|
78 | %endif
|
---|
79 | call NAME(RTLogLogger)
|
---|
80 | add esp, byte 4
|
---|
81 | ret
|
---|
82 | ENDPROC vmmGCLoggerWrapper
|
---|
83 |
|
---|
84 |
|
---|
85 | ;/**
|
---|
86 | ; * Internal GC logger worker: Logger (release) wrapper.
|
---|
87 | ; */
|
---|
88 | ;VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
|
---|
89 | EXPORTEDNAME vmmGCRelLoggerWrapper
|
---|
90 | %ifdef __YASM__
|
---|
91 | %ifdef ASM_FORMAT_ELF
|
---|
92 | push dword IMP(g_RelLogger) ; YASM BUG #67! YASMCHECK!
|
---|
93 | %else
|
---|
94 | push IMP(g_RelLogger)
|
---|
95 | %endif
|
---|
96 | %else
|
---|
97 | push IMP(g_RelLogger)
|
---|
98 | %endif
|
---|
99 | call NAME(RTLogLogger)
|
---|
100 | add esp, byte 4
|
---|
101 | ret
|
---|
102 | ENDPROC vmmGCRelLoggerWrapper
|
---|
103 |
|
---|
104 |
|
---|
105 | ;;
|
---|
106 | ; Enables write protection.
|
---|
107 | BEGINPROC vmmGCEnableWP
|
---|
108 | push eax
|
---|
109 | mov eax, cr0
|
---|
110 | or eax, X86_CR0_WRITE_PROTECT
|
---|
111 | mov cr0, eax
|
---|
112 | pop eax
|
---|
113 | ret
|
---|
114 | ENDPROC vmmGCEnableWP
|
---|
115 |
|
---|
116 |
|
---|
117 | ;;
|
---|
118 | ; Disables write protection.
|
---|
119 | BEGINPROC vmmGCDisableWP
|
---|
120 | push eax
|
---|
121 | mov eax, cr0
|
---|
122 | and eax, ~X86_CR0_WRITE_PROTECT
|
---|
123 | mov cr0, eax
|
---|
124 | pop eax
|
---|
125 | ret
|
---|
126 | ENDPROC vmmGCDisableWP
|
---|
127 |
|
---|
128 |
|
---|
129 | ;;
|
---|
130 | ; Load special register set expected upon faults.
|
---|
131 | ; All registers are changed.
|
---|
132 | BEGINPROC vmmGCTestLoadRegs
|
---|
133 | mov eax, ss
|
---|
134 | mov ds, eax
|
---|
135 | mov es, eax
|
---|
136 | mov fs, eax
|
---|
137 | mov gs, eax
|
---|
138 | mov edi, 001234567h
|
---|
139 | mov esi, 042000042h
|
---|
140 | mov ebp, 0ffeeddcch
|
---|
141 | mov ebx, 089abcdefh
|
---|
142 | mov ecx, 0ffffaaaah
|
---|
143 | mov edx, 077778888h
|
---|
144 | mov eax, 0f0f0f0f0h
|
---|
145 | ret
|
---|
146 | ENDPROC vmmGCTestLoadRegs
|
---|
147 |
|
---|
148 |
|
---|
149 | ;;
|
---|
150 | ; A Trap 3 testcase.
|
---|
151 | GLOBALNAME vmmGCTestTrap3
|
---|
152 | SaveAndLoadAll
|
---|
153 |
|
---|
154 | int 3
|
---|
155 | EXPORTEDNAME vmmGCTestTrap3_FaultEIP
|
---|
156 |
|
---|
157 | RestoreAll
|
---|
158 | mov eax, 0ffffffffh
|
---|
159 | ret
|
---|
160 | ENDPROC vmmGCTestTrap3
|
---|
161 |
|
---|
162 |
|
---|
163 | ;;
|
---|
164 | ; A Trap 8 testcase.
|
---|
165 | GLOBALNAME vmmGCTestTrap8
|
---|
166 | SaveAndLoadAll
|
---|
167 |
|
---|
168 | sub esp, byte 8
|
---|
169 | sidt [esp]
|
---|
170 | mov word [esp], 111 ; make any #PF double fault.
|
---|
171 | lidt [esp]
|
---|
172 | add esp, byte 8
|
---|
173 |
|
---|
174 | COM_S_CHAR '!'
|
---|
175 |
|
---|
176 | xor eax, eax
|
---|
177 | EXPORTEDNAME vmmGCTestTrap8_FaultEIP
|
---|
178 | mov eax, [eax]
|
---|
179 |
|
---|
180 |
|
---|
181 | COM_S_CHAR '2'
|
---|
182 |
|
---|
183 | RestoreAll
|
---|
184 | mov eax, 0ffffffffh
|
---|
185 | ret
|
---|
186 | ENDPROC vmmGCTestTrap8
|
---|
187 |
|
---|
188 |
|
---|
189 | ;;
|
---|
190 | ; A simple Trap 0d testcase.
|
---|
191 | GLOBALNAME vmmGCTestTrap0d
|
---|
192 | SaveAndLoadAll
|
---|
193 |
|
---|
194 | push ds
|
---|
195 | EXPORTEDNAME vmmGCTestTrap0d_FaultEIP
|
---|
196 | ltr [esp]
|
---|
197 | pop eax
|
---|
198 |
|
---|
199 | RestoreAll
|
---|
200 | mov eax, 0ffffffffh
|
---|
201 | ret
|
---|
202 | ENDPROC vmmGCTestTrap0d
|
---|
203 |
|
---|
204 |
|
---|
205 | ;;
|
---|
206 | ; A simple Trap 0e testcase.
|
---|
207 | GLOBALNAME vmmGCTestTrap0e
|
---|
208 | SaveAndLoadAll
|
---|
209 |
|
---|
210 | xor eax, eax
|
---|
211 | EXPORTEDNAME vmmGCTestTrap0e_FaultEIP
|
---|
212 | mov eax, [eax]
|
---|
213 |
|
---|
214 | RestoreAll
|
---|
215 | mov eax, 0ffffffffh
|
---|
216 | ret
|
---|
217 |
|
---|
218 | EXPORTEDNAME vmmGCTestTrap0e_ResumeEIP
|
---|
219 | RestoreAll
|
---|
220 | xor eax, eax
|
---|
221 | ret
|
---|
222 | ENDPROC vmmGCTestTrap0e
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 | ;;
|
---|
227 | ; Safely reads an MSR.
|
---|
228 | ; @returns boolean
|
---|
229 | ; @param uMsr The MSR to red.
|
---|
230 | ; @param pu64Value Where to return the value on success.
|
---|
231 | ;
|
---|
232 | GLOBALNAME vmmRCSafeMsrRead
|
---|
233 | push ebp
|
---|
234 | mov ebp, esp
|
---|
235 | pushf
|
---|
236 | cli
|
---|
237 | push esi
|
---|
238 | push edi
|
---|
239 | push ebx
|
---|
240 | push ebp
|
---|
241 |
|
---|
242 | mov ecx, [ebp + 8] ; The MSR to read.
|
---|
243 | mov eax, 0deadbeefh
|
---|
244 | mov edx, 0deadbeefh
|
---|
245 |
|
---|
246 | TRPM_GP_HANDLER NAME(TRPMRCTrapHyperHandlerSetEIP), .trapped
|
---|
247 | rdmsr
|
---|
248 |
|
---|
249 | mov ecx, [ebp + 0ch] ; Where to store the result.
|
---|
250 | mov [ecx], eax
|
---|
251 | mov [ecx + 4], edx
|
---|
252 |
|
---|
253 | mov eax, 1
|
---|
254 | .return:
|
---|
255 | pop ebp
|
---|
256 | pop ebx
|
---|
257 | pop edi
|
---|
258 | pop esi
|
---|
259 | popf
|
---|
260 | leave
|
---|
261 | ret
|
---|
262 |
|
---|
263 | .trapped:
|
---|
264 | mov eax, 0
|
---|
265 | jmp .return
|
---|
266 | ENDPROC vmmRCSafeMsrRead
|
---|
267 |
|
---|
268 |
|
---|
269 | ;;
|
---|
270 | ; Safely writes an MSR.
|
---|
271 | ; @returns boolean
|
---|
272 | ; @param uMsr The MSR to red.
|
---|
273 | ; @param u64Value The value to write.
|
---|
274 | ;
|
---|
275 | GLOBALNAME vmmRCSafeMsrWrite
|
---|
276 | push ebp
|
---|
277 | mov ebp, esp
|
---|
278 | pushf
|
---|
279 | cli
|
---|
280 | push esi
|
---|
281 | push edi
|
---|
282 | push ebx
|
---|
283 | push ebp
|
---|
284 |
|
---|
285 | mov ecx, [ebp + 8] ; The MSR to write to.
|
---|
286 | mov eax, [ebp + 12] ; The value to write.
|
---|
287 | mov edx, [ebp + 16]
|
---|
288 |
|
---|
289 | TRPM_GP_HANDLER NAME(TRPMRCTrapHyperHandlerSetEIP), .trapped
|
---|
290 | wrmsr
|
---|
291 |
|
---|
292 | mov eax, 1
|
---|
293 | .return:
|
---|
294 | pop ebp
|
---|
295 | pop ebx
|
---|
296 | pop edi
|
---|
297 | pop esi
|
---|
298 | popf
|
---|
299 | leave
|
---|
300 | ret
|
---|
301 |
|
---|
302 | .trapped:
|
---|
303 | mov eax, 0
|
---|
304 | jmp .return
|
---|
305 | ENDPROC vmmRCSafeMsrWrite
|
---|
306 |
|
---|
307 |
|
---|
308 |
|
---|
309 | ;;
|
---|
310 | ; The raw-mode context equivalent of SUPTracerFireProbe.
|
---|
311 | ;
|
---|
312 | ; See also SUPLibTracerA.asm.
|
---|
313 | ;
|
---|
314 | EXPORTEDNAME VMMRCProbeFire
|
---|
315 | push ebp
|
---|
316 | mov ebp, esp
|
---|
317 |
|
---|
318 | ;
|
---|
319 | ; Save edx and eflags so we can use them.
|
---|
320 | ;
|
---|
321 | pushf
|
---|
322 | push edx
|
---|
323 |
|
---|
324 | ;
|
---|
325 | ; Get the address of the tracer context record after first checking
|
---|
326 | ; that host calls hasn't been disabled.
|
---|
327 | ;
|
---|
328 | mov edx, IMP(g_VM)
|
---|
329 | add edx, [edx + VM.offVMCPU]
|
---|
330 | cmp dword [edx + VMCPU.vmm + VMMCPU.cCallRing3Disabled], 0
|
---|
331 | jnz .return
|
---|
332 | add edx, VMCPU.vmm + VMMCPU.TracerCtx
|
---|
333 |
|
---|
334 | ;
|
---|
335 | ; Save the X86 context.
|
---|
336 | ;
|
---|
337 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eax], eax
|
---|
338 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ecx], ecx
|
---|
339 | pop eax
|
---|
340 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edx], eax
|
---|
341 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebx], ebx
|
---|
342 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esi], esi
|
---|
343 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edi], edi
|
---|
344 | pop eax
|
---|
345 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eflags], eax
|
---|
346 | mov eax, [ebp + 4]
|
---|
347 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eip], eax
|
---|
348 | mov eax, [ebp]
|
---|
349 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebp], eax
|
---|
350 | lea eax, [ebp + 4*2]
|
---|
351 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esp], eax
|
---|
352 |
|
---|
353 | mov ecx, [ebp + 4*2]
|
---|
354 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.uVtgProbeLoc], ecx
|
---|
355 |
|
---|
356 | mov eax, [ecx + 4] ; VTGPROBELOC::idProbe.
|
---|
357 | mov [edx + SUPDRVTRACERUSRCTX32.idProbe], eax
|
---|
358 | mov dword [edx + SUPDRVTRACERUSRCTX32.cBits], 32
|
---|
359 |
|
---|
360 | ; Copy the arguments off the stack.
|
---|
361 | %macro COPY_ONE_ARG 1
|
---|
362 | mov eax, [ebp + 12 + %1 * 4]
|
---|
363 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.aArgs + %1*4], eax
|
---|
364 | %endmacro
|
---|
365 | COPY_ONE_ARG 0
|
---|
366 | COPY_ONE_ARG 1
|
---|
367 | COPY_ONE_ARG 2
|
---|
368 | COPY_ONE_ARG 3
|
---|
369 | COPY_ONE_ARG 4
|
---|
370 | COPY_ONE_ARG 5
|
---|
371 | COPY_ONE_ARG 6
|
---|
372 | COPY_ONE_ARG 7
|
---|
373 | COPY_ONE_ARG 8
|
---|
374 | COPY_ONE_ARG 9
|
---|
375 | COPY_ONE_ARG 10
|
---|
376 | COPY_ONE_ARG 11
|
---|
377 | COPY_ONE_ARG 12
|
---|
378 | COPY_ONE_ARG 13
|
---|
379 | COPY_ONE_ARG 14
|
---|
380 | COPY_ONE_ARG 15
|
---|
381 | COPY_ONE_ARG 16
|
---|
382 | COPY_ONE_ARG 17
|
---|
383 | COPY_ONE_ARG 18
|
---|
384 | COPY_ONE_ARG 19
|
---|
385 |
|
---|
386 | ;
|
---|
387 | ; Call the helper (too lazy to do the VMM structure stuff).
|
---|
388 | ;
|
---|
389 | mov ecx, IMP(g_VM)
|
---|
390 | push ecx
|
---|
391 | call NAME(vmmRCProbeFireHelper)
|
---|
392 |
|
---|
393 | .return:
|
---|
394 | leave
|
---|
395 | ret
|
---|
396 | ENDPROC VMMRCProbeFire
|
---|
397 |
|
---|