VirtualBox

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

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

tstVMM: Extended it with a 'msr' mode for dump the MSRs of the host CPU brute-force style.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1; $Id: VMMRCA.asm 49141 2013-10-16 14:07:14Z 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 pushad
236
237 mov ecx, [ebp + 8] ; the MSR to read.
238 mov eax, 0deadbeefh
239 mov edx, 0deadbeefh
240
241TRPM_GP_HANDLER NAME(TRPMRCTrapHyperHandlerSetEIP), .trapped
242 rdmsr
243
244 mov ecx, [ebp + 0ch] ; Where to store the result.
245 mov [ecx], eax
246 mov [ecx], edx
247
248 popad
249 mov eax, 1
250 leave
251 ret
252
253.trapped:
254 popad
255 mov eax, 0
256 leave
257 ret
258ENDPROC vmmRCSafeMsrRead
259
260
261
262;;
263; The raw-mode context equivalent of SUPTracerFireProbe.
264;
265; See also SUPLibTracerA.asm.
266;
267EXPORTEDNAME VMMRCProbeFire
268 push ebp
269 mov ebp, esp
270
271 ;
272 ; Save edx and eflags so we can use them.
273 ;
274 pushf
275 push edx
276
277 ;
278 ; Get the address of the tracer context record after first checking
279 ; that host calls hasn't been disabled.
280 ;
281 mov edx, IMP(g_VM)
282 add edx, [edx + VM.offVMCPU]
283 cmp dword [edx + VMCPU.vmm + VMMCPU.cCallRing3Disabled], 0
284 jnz .return
285 add edx, VMCPU.vmm + VMMCPU.TracerCtx
286
287 ;
288 ; Save the X86 context.
289 ;
290 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eax], eax
291 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ecx], ecx
292 pop eax
293 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edx], eax
294 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebx], ebx
295 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esi], esi
296 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edi], edi
297 pop eax
298 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eflags], eax
299 mov eax, [ebp + 4]
300 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eip], eax
301 mov eax, [ebp]
302 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebp], eax
303 lea eax, [ebp + 4*2]
304 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esp], eax
305
306 mov ecx, [ebp + 4*2]
307 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.uVtgProbeLoc], ecx
308
309 mov eax, [ecx + 4] ; VTGPROBELOC::idProbe.
310 mov [edx + SUPDRVTRACERUSRCTX32.idProbe], eax
311 mov dword [edx + SUPDRVTRACERUSRCTX32.cBits], 32
312
313 ; Copy the arguments off the stack.
314%macro COPY_ONE_ARG 1
315 mov eax, [ebp + 12 + %1 * 4]
316 mov [edx + SUPDRVTRACERUSRCTX32.u.X86.aArgs + %1*4], eax
317%endmacro
318 COPY_ONE_ARG 0
319 COPY_ONE_ARG 1
320 COPY_ONE_ARG 2
321 COPY_ONE_ARG 3
322 COPY_ONE_ARG 4
323 COPY_ONE_ARG 5
324 COPY_ONE_ARG 6
325 COPY_ONE_ARG 7
326 COPY_ONE_ARG 8
327 COPY_ONE_ARG 9
328 COPY_ONE_ARG 10
329 COPY_ONE_ARG 11
330 COPY_ONE_ARG 12
331 COPY_ONE_ARG 13
332 COPY_ONE_ARG 14
333 COPY_ONE_ARG 15
334 COPY_ONE_ARG 16
335 COPY_ONE_ARG 17
336 COPY_ONE_ARG 18
337 COPY_ONE_ARG 19
338
339 ;
340 ; Call the helper (too lazy to do the VMM structure stuff).
341 ;
342 mov ecx, IMP(g_VM)
343 push ecx
344 call NAME(vmmRCProbeFireHelper)
345
346.return:
347 leave
348 ret
349ENDPROC VMMRCProbeFire
350
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