VirtualBox

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

Last change on this file since 56295 was 56286, checked in by vboxsync, 9 years ago

Cleaned up all grep hits for 'VMMGC'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1; $Id: VMMRCA.asm 56286 2015-06-09 11:06:39Z vboxsync $
2;; @file
3; VMMRC - Raw-mode Context Virtual Machine Monitor assembly routines.
4;
5
6;
7; Copyright (C) 2006-2015 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 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
246TRPM_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
266ENDPROC 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;
275GLOBALNAME 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
289TRPM_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
305ENDPROC vmmRCSafeMsrWrite
306
307
308
309;;
310; The raw-mode context equivalent of SUPTracerFireProbe.
311;
312; See also SUPLibTracerA.asm.
313;
314EXPORTEDNAME 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
396ENDPROC VMMRCProbeFire
397
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