1 | ; $Id: VMMRCA.asm 41338 2012-05-16 14:39:21Z 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 |
|
---|
27 |
|
---|
28 | ;*******************************************************************************
|
---|
29 | ;* Defined Constants And Macros *
|
---|
30 | ;*******************************************************************************
|
---|
31 | ;; save all registers before loading special values for the faulting.
|
---|
32 | %macro SaveAndLoadAll 0
|
---|
33 | pushad
|
---|
34 | push ds
|
---|
35 | push es
|
---|
36 | push fs
|
---|
37 | push gs
|
---|
38 | call NAME(vmmGCTestLoadRegs)
|
---|
39 | %endmacro
|
---|
40 |
|
---|
41 | ;; restore all registers after faulting.
|
---|
42 | %macro RestoreAll 0
|
---|
43 | pop gs
|
---|
44 | pop fs
|
---|
45 | pop es
|
---|
46 | pop ds
|
---|
47 | popad
|
---|
48 | %endmacro
|
---|
49 |
|
---|
50 |
|
---|
51 | ;*******************************************************************************
|
---|
52 | ;* External Symbols *
|
---|
53 | ;*******************************************************************************
|
---|
54 | extern IMPNAME(g_VM)
|
---|
55 | extern IMPNAME(g_Logger)
|
---|
56 | extern IMPNAME(g_RelLogger)
|
---|
57 | extern NAME(RTLogLogger)
|
---|
58 | extern NAME(vmmRCProbeFireHelper)
|
---|
59 |
|
---|
60 |
|
---|
61 | BEGINCODE
|
---|
62 |
|
---|
63 | ;/**
|
---|
64 | ; * Internal GC logger worker: Logger wrapper.
|
---|
65 | ; */
|
---|
66 | ;VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
|
---|
67 | EXPORTEDNAME vmmGCLoggerWrapper
|
---|
68 | %ifdef __YASM__
|
---|
69 | %ifdef ASM_FORMAT_ELF
|
---|
70 | push dword IMP(g_Logger) ; YASM BUG #67! YASMCHECK!
|
---|
71 | %else
|
---|
72 | push IMP(g_Logger)
|
---|
73 | %endif
|
---|
74 | %else
|
---|
75 | push IMP(g_Logger)
|
---|
76 | %endif
|
---|
77 | call NAME(RTLogLogger)
|
---|
78 | add esp, byte 4
|
---|
79 | ret
|
---|
80 | ENDPROC vmmGCLoggerWrapper
|
---|
81 |
|
---|
82 |
|
---|
83 | ;/**
|
---|
84 | ; * Internal GC logger worker: Logger (release) wrapper.
|
---|
85 | ; */
|
---|
86 | ;VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
|
---|
87 | EXPORTEDNAME vmmGCRelLoggerWrapper
|
---|
88 | %ifdef __YASM__
|
---|
89 | %ifdef ASM_FORMAT_ELF
|
---|
90 | push dword IMP(g_RelLogger) ; YASM BUG #67! YASMCHECK!
|
---|
91 | %else
|
---|
92 | push IMP(g_RelLogger)
|
---|
93 | %endif
|
---|
94 | %else
|
---|
95 | push IMP(g_RelLogger)
|
---|
96 | %endif
|
---|
97 | call NAME(RTLogLogger)
|
---|
98 | add esp, byte 4
|
---|
99 | ret
|
---|
100 | ENDPROC vmmGCRelLoggerWrapper
|
---|
101 |
|
---|
102 |
|
---|
103 | ;;
|
---|
104 | ; Enables write protection.
|
---|
105 | BEGINPROC vmmGCEnableWP
|
---|
106 | push eax
|
---|
107 | mov eax, cr0
|
---|
108 | or eax, X86_CR0_WRITE_PROTECT
|
---|
109 | mov cr0, eax
|
---|
110 | pop eax
|
---|
111 | ret
|
---|
112 | ENDPROC vmmGCEnableWP
|
---|
113 |
|
---|
114 |
|
---|
115 | ;;
|
---|
116 | ; Disables write protection.
|
---|
117 | BEGINPROC vmmGCDisableWP
|
---|
118 | push eax
|
---|
119 | mov eax, cr0
|
---|
120 | and eax, ~X86_CR0_WRITE_PROTECT
|
---|
121 | mov cr0, eax
|
---|
122 | pop eax
|
---|
123 | ret
|
---|
124 | ENDPROC vmmGCDisableWP
|
---|
125 |
|
---|
126 |
|
---|
127 | ;;
|
---|
128 | ; Load special register set expected upon faults.
|
---|
129 | ; All registers are changed.
|
---|
130 | BEGINPROC vmmGCTestLoadRegs
|
---|
131 | mov eax, ss
|
---|
132 | mov ds, eax
|
---|
133 | mov es, eax
|
---|
134 | mov fs, eax
|
---|
135 | mov gs, eax
|
---|
136 | mov edi, 001234567h
|
---|
137 | mov esi, 042000042h
|
---|
138 | mov ebp, 0ffeeddcch
|
---|
139 | mov ebx, 089abcdefh
|
---|
140 | mov ecx, 0ffffaaaah
|
---|
141 | mov edx, 077778888h
|
---|
142 | mov eax, 0f0f0f0f0h
|
---|
143 | ret
|
---|
144 | ENDPROC vmmGCTestLoadRegs
|
---|
145 |
|
---|
146 |
|
---|
147 | ;;
|
---|
148 | ; A Trap 3 testcase.
|
---|
149 | GLOBALNAME vmmGCTestTrap3
|
---|
150 | SaveAndLoadAll
|
---|
151 |
|
---|
152 | int 3
|
---|
153 | EXPORTEDNAME vmmGCTestTrap3_FaultEIP
|
---|
154 |
|
---|
155 | RestoreAll
|
---|
156 | mov eax, 0ffffffffh
|
---|
157 | ret
|
---|
158 | ENDPROC vmmGCTestTrap3
|
---|
159 |
|
---|
160 |
|
---|
161 | ;;
|
---|
162 | ; A Trap 8 testcase.
|
---|
163 | GLOBALNAME vmmGCTestTrap8
|
---|
164 | SaveAndLoadAll
|
---|
165 |
|
---|
166 | sub esp, byte 8
|
---|
167 | sidt [esp]
|
---|
168 | mov word [esp], 111 ; make any #PF double fault.
|
---|
169 | lidt [esp]
|
---|
170 | add esp, byte 8
|
---|
171 |
|
---|
172 | COM_S_CHAR '!'
|
---|
173 |
|
---|
174 | xor eax, eax
|
---|
175 | EXPORTEDNAME vmmGCTestTrap8_FaultEIP
|
---|
176 | mov eax, [eax]
|
---|
177 |
|
---|
178 |
|
---|
179 | COM_S_CHAR '2'
|
---|
180 |
|
---|
181 | RestoreAll
|
---|
182 | mov eax, 0ffffffffh
|
---|
183 | ret
|
---|
184 | ENDPROC vmmGCTestTrap8
|
---|
185 |
|
---|
186 |
|
---|
187 | ;;
|
---|
188 | ; A simple Trap 0d testcase.
|
---|
189 | GLOBALNAME vmmGCTestTrap0d
|
---|
190 | SaveAndLoadAll
|
---|
191 |
|
---|
192 | push ds
|
---|
193 | EXPORTEDNAME vmmGCTestTrap0d_FaultEIP
|
---|
194 | ltr [esp]
|
---|
195 | pop eax
|
---|
196 |
|
---|
197 | RestoreAll
|
---|
198 | mov eax, 0ffffffffh
|
---|
199 | ret
|
---|
200 | ENDPROC vmmGCTestTrap0d
|
---|
201 |
|
---|
202 |
|
---|
203 | ;;
|
---|
204 | ; A simple Trap 0e testcase.
|
---|
205 | GLOBALNAME vmmGCTestTrap0e
|
---|
206 | SaveAndLoadAll
|
---|
207 |
|
---|
208 | xor eax, eax
|
---|
209 | EXPORTEDNAME vmmGCTestTrap0e_FaultEIP
|
---|
210 | mov eax, [eax]
|
---|
211 |
|
---|
212 | RestoreAll
|
---|
213 | mov eax, 0ffffffffh
|
---|
214 | ret
|
---|
215 |
|
---|
216 | EXPORTEDNAME vmmGCTestTrap0e_ResumeEIP
|
---|
217 | RestoreAll
|
---|
218 | xor eax, eax
|
---|
219 | ret
|
---|
220 | ENDPROC vmmGCTestTrap0e
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 | ;;
|
---|
225 | ; The raw-mode context equivalent of SUPTracerFireProbe.
|
---|
226 | ;
|
---|
227 | ; See also SUPLibTracerA.asm.
|
---|
228 | ;
|
---|
229 | EXPORTEDNAME VMMRCProbeFire
|
---|
230 | push ebp
|
---|
231 | mov ebp, esp
|
---|
232 |
|
---|
233 | ;
|
---|
234 | ; Save edx and eflags so we can use them.
|
---|
235 | ;
|
---|
236 | pushf
|
---|
237 | push edx
|
---|
238 |
|
---|
239 | ;
|
---|
240 | ; Get the address of the tracer context record after first checking
|
---|
241 | ; that host calls hasn't been disabled.
|
---|
242 | ;
|
---|
243 | mov edx, IMP(g_VM)
|
---|
244 | add edx, [edx + VM.offVMCPU]
|
---|
245 | cmp dword [edx + VMCPU.vmm + VMMCPU.cCallRing3Disabled], 0
|
---|
246 | jnz .return
|
---|
247 | add edx, VMCPU.vmm + VMMCPU.TracerCtx
|
---|
248 |
|
---|
249 | ;
|
---|
250 | ; Save the X86 context.
|
---|
251 | ;
|
---|
252 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eax], eax
|
---|
253 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ecx], ecx
|
---|
254 | pop eax
|
---|
255 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edx], eax
|
---|
256 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebx], ebx
|
---|
257 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esi], esi
|
---|
258 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.edi], edi
|
---|
259 | pop eax
|
---|
260 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eflags], eax
|
---|
261 | mov eax, [ebp + 4]
|
---|
262 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.eip], eax
|
---|
263 | mov eax, [ebp]
|
---|
264 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.ebp], eax
|
---|
265 | lea eax, [ebp + 4*2]
|
---|
266 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.esp], eax
|
---|
267 |
|
---|
268 | mov ecx, [ebp + 4*2]
|
---|
269 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.uVtgProbeLoc], ecx
|
---|
270 |
|
---|
271 | mov eax, [ecx + 4] ; VTGPROBELOC::idProbe.
|
---|
272 | mov [edx + SUPDRVTRACERUSRCTX32.idProbe], eax
|
---|
273 | mov dword [edx + SUPDRVTRACERUSRCTX32.cBits], 32
|
---|
274 |
|
---|
275 | ; Copy the arguments off the stack.
|
---|
276 | %macro COPY_ONE_ARG 1
|
---|
277 | mov eax, [ebp + 12 + %1 * 4]
|
---|
278 | mov [edx + SUPDRVTRACERUSRCTX32.u.X86.aArgs + %1*4], eax
|
---|
279 | %endmacro
|
---|
280 | COPY_ONE_ARG 0
|
---|
281 | COPY_ONE_ARG 1
|
---|
282 | COPY_ONE_ARG 2
|
---|
283 | COPY_ONE_ARG 3
|
---|
284 | COPY_ONE_ARG 4
|
---|
285 | COPY_ONE_ARG 5
|
---|
286 | COPY_ONE_ARG 6
|
---|
287 | COPY_ONE_ARG 7
|
---|
288 | COPY_ONE_ARG 8
|
---|
289 | COPY_ONE_ARG 9
|
---|
290 | COPY_ONE_ARG 10
|
---|
291 | COPY_ONE_ARG 11
|
---|
292 | COPY_ONE_ARG 12
|
---|
293 | COPY_ONE_ARG 13
|
---|
294 | COPY_ONE_ARG 14
|
---|
295 | COPY_ONE_ARG 15
|
---|
296 | COPY_ONE_ARG 16
|
---|
297 | COPY_ONE_ARG 17
|
---|
298 | COPY_ONE_ARG 18
|
---|
299 | COPY_ONE_ARG 19
|
---|
300 |
|
---|
301 | ;
|
---|
302 | ; Call the helper (too lazy to do the VMM structure stuff).
|
---|
303 | ;
|
---|
304 | mov ecx, IMP(g_VM)
|
---|
305 | push ecx
|
---|
306 | call NAME(vmmRCProbeFireHelper)
|
---|
307 |
|
---|
308 | .return:
|
---|
309 | leave
|
---|
310 | ret
|
---|
311 | ENDPROC VMMRCProbeFire
|
---|
312 |
|
---|