VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMRC/VMMRCA.asm@ 49409

Last change on this file since 49409 was 49362, checked in by vboxsync, 11 years ago

VMMRCA.asm/vmmRcSafeMsr*: See if making sure interrupts are disabled while reading/writing MSRs helps with the solaris host reboots.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1; $Id: VMMRCA.asm 49362 2013-11-01 12:45:13Z 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;*******************************************************************************
55extern IMPNAME(g_VM)
56extern IMPNAME(g_Logger)
57extern IMPNAME(g_RelLogger)
58extern NAME(RTLogLogger)
59extern NAME(vmmRCProbeFireHelper)
60extern NAME(TRPMRCTrapHyperHandlerSetEIP)
61
62
63BEGINCODE
64
65;/**
66; * Internal GC logger worker: Logger wrapper.
67; */
68;VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
69EXPORTEDNAME 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
82ENDPROC vmmGCLoggerWrapper
83
84
85;/**
86; * Internal GC logger worker: Logger (release) wrapper.
87; */
88;VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
89EXPORTEDNAME 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
102ENDPROC vmmGCRelLoggerWrapper
103
104
105;;
106; Enables write protection.
107BEGINPROC vmmGCEnableWP
108 push eax
109 mov eax, cr0
110 or eax, X86_CR0_WRITE_PROTECT
111 mov cr0, eax
112 pop eax
113 ret
114ENDPROC vmmGCEnableWP
115
116
117;;
118; Disables write protection.
119BEGINPROC vmmGCDisableWP
120 push eax
121 mov eax, cr0
122 and eax, ~X86_CR0_WRITE_PROTECT
123 mov cr0, eax
124 pop eax
125 ret
126ENDPROC vmmGCDisableWP
127
128
129;;
130; Load special register set expected upon faults.
131; All registers are changed.
132BEGINPROC 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
146ENDPROC vmmGCTestLoadRegs
147
148
149;;
150; A Trap 3 testcase.
151GLOBALNAME vmmGCTestTrap3
152 SaveAndLoadAll
153
154 int 3
155EXPORTEDNAME vmmGCTestTrap3_FaultEIP
156
157 RestoreAll
158 mov eax, 0ffffffffh
159 ret
160ENDPROC vmmGCTestTrap3
161
162
163;;
164; A Trap 8 testcase.
165GLOBALNAME 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
177EXPORTEDNAME vmmGCTestTrap8_FaultEIP
178 mov eax, [eax]
179
180
181 COM_S_CHAR '2'
182
183 RestoreAll
184 mov eax, 0ffffffffh
185 ret
186ENDPROC vmmGCTestTrap8
187
188
189;;
190; A simple Trap 0d testcase.
191GLOBALNAME vmmGCTestTrap0d
192 SaveAndLoadAll
193
194 push ds
195EXPORTEDNAME vmmGCTestTrap0d_FaultEIP
196 ltr [esp]
197 pop eax
198
199 RestoreAll
200 mov eax, 0ffffffffh
201 ret
202ENDPROC vmmGCTestTrap0d
203
204
205;;
206; A simple Trap 0e testcase.
207GLOBALNAME vmmGCTestTrap0e
208 SaveAndLoadAll
209
210 xor eax, eax
211EXPORTEDNAME vmmGCTestTrap0e_FaultEIP
212 mov eax, [eax]
213
214 RestoreAll
215 mov eax, 0ffffffffh
216 ret
217
218EXPORTEDNAME vmmGCTestTrap0e_ResumeEIP
219 RestoreAll
220 xor eax, eax
221 ret
222ENDPROC 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;
232GLOBALNAME vmmRCSafeMsrRead
233 push ebp
234 mov ebp, esp
235 pushf
236 cli
237
238 mov ecx, [ebp + 8] ; The MSR to read.
239 mov eax, 0deadbeefh
240 mov edx, 0deadbeefh
241
242TRPM_GP_HANDLER NAME(TRPMRCTrapHyperHandlerSetEIP), .trapped
243 rdmsr
244
245 mov ecx, [ebp + 0ch] ; Where to store the result.
246 mov [ecx], eax
247 mov [ecx + 4], edx
248
249 popf
250 mov eax, 1
251 leave
252 ret
253
254.trapped:
255 popf
256 mov eax, 0
257 leave
258 ret
259ENDPROC vmmRCSafeMsrRead
260
261
262;;
263; Safely writes an MSR.
264; @returns boolean
265; @param uMsr The MSR to red.
266; @param u64Value The value to write.
267;
268GLOBALNAME vmmRCSafeMsrWrite
269 push ebp
270 mov ebp, esp
271 pushf
272 cli
273
274 mov ecx, [ebp + 8] ; The MSR to write to.
275 mov eax, [ebp + 12] ; The value to write.
276 mov edx, [ebp + 16]
277
278TRPM_GP_HANDLER NAME(TRPMRCTrapHyperHandlerSetEIP), .trapped
279 wrmsr
280
281 popf
282 mov eax, 1
283 leave
284 ret
285
286.trapped:
287 popf
288 mov eax, 0
289 leave
290 ret
291ENDPROC vmmRCSafeMsrWrite
292
293
294
295;;
296; The raw-mode context equivalent of SUPTracerFireProbe.
297;
298; See also SUPLibTracerA.asm.
299;
300EXPORTEDNAME VMMRCProbeFire
301 push ebp
302 mov ebp, esp
303
304 ;
305 ; Save edx and eflags so we can use them.
306 ;
307 pushf
308 push edx
309
310 ;
311 ; Get the address of the tracer context record after first checking
312 ; that host calls hasn't been disabled.
313 ;
314 mov edx, IMP(g_VM)
315 add edx, [edx + VM.offVMCPU]
316 cmp dword [edx + VMCPU.vmm + VMMCPU.cCallRing3Disabled], 0
317 jnz .return
318 add edx, VMCPU.vmm + VMMCPU.TracerCtx
319
320 ;
321 ; Save the X86 context.
322 ;
323 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eax], eax
324 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ecx], ecx
325 pop eax
326 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edx], eax
327 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebx], ebx
328 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esi], esi
329 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edi], edi
330 pop eax
331 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eflags], eax
332 mov eax, [ebp + 4]
333 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eip], eax
334 mov eax, [ebp]
335 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebp], eax
336 lea eax, [ebp + 4*2]
337 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esp], eax
338
339 mov ecx, [ebp + 4*2]
340 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.uVtgProbeLoc], ecx
341
342 mov eax, [ecx + 4] ; VTGPROBELOC::idProbe.
343 mov [edx + SUPDRVTRACERUSRCTX32.idProbe], eax
344 mov dword [edx + SUPDRVTRACERUSRCTX32.cBits], 32
345
346 ; Copy the arguments off the stack.
347%macro COPY_ONE_ARG 1
348 mov eax, [ebp + 12 + %1 * 4]
349 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.aArgs + %1*4], eax
350%endmacro
351 COPY_ONE_ARG 0
352 COPY_ONE_ARG 1
353 COPY_ONE_ARG 2
354 COPY_ONE_ARG 3
355 COPY_ONE_ARG 4
356 COPY_ONE_ARG 5
357 COPY_ONE_ARG 6
358 COPY_ONE_ARG 7
359 COPY_ONE_ARG 8
360 COPY_ONE_ARG 9
361 COPY_ONE_ARG 10
362 COPY_ONE_ARG 11
363 COPY_ONE_ARG 12
364 COPY_ONE_ARG 13
365 COPY_ONE_ARG 14
366 COPY_ONE_ARG 15
367 COPY_ONE_ARG 16
368 COPY_ONE_ARG 17
369 COPY_ONE_ARG 18
370 COPY_ONE_ARG 19
371
372 ;
373 ; Call the helper (too lazy to do the VMM structure stuff).
374 ;
375 mov ecx, IMP(g_VM)
376 push ecx
377 call NAME(vmmRCProbeFireHelper)
378
379.return:
380 leave
381 ret
382ENDPROC VMMRCProbeFire
383
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