~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/VMM/VMMGC/CPUMGCA.asm

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
; $Id: CPUMGCA.asm $
2
 
;; @file
3
 
; CPUM - Guest Context Assembly Routines.
4
 
;
5
 
 
6
 
; Copyright (C) 2006-2007 Oracle Corporation
7
 
;
8
 
; This file is part of VirtualBox Open Source Edition (OSE), as
9
 
; available from http://www.virtualbox.org. This file is free software;
10
 
; you can redistribute it and/or modify it under the terms of the GNU
11
 
; General Public License (GPL) as published by the Free Software
12
 
; Foundation, in version 2 as it comes in the "COPYING" file of the
13
 
; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14
 
; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15
 
;
16
 
 
17
 
;*******************************************************************************
18
 
;* Header Files                                                                *
19
 
;*******************************************************************************
20
 
%include "VMMGC.mac"
21
 
%include "VBox/vm.mac"
22
 
%include "VBox/err.mac"
23
 
%include "VBox/stam.mac"
24
 
%include "CPUMInternal.mac"
25
 
%include "VBox/x86.mac"
26
 
%include "VBox/cpum.mac"
27
 
 
28
 
 
29
 
;*******************************************************************************
30
 
;* External Symbols                                                            *
31
 
;*******************************************************************************
32
 
extern IMPNAME(g_CPUM)                 ; VMM GC Builtin import
33
 
extern IMPNAME(g_VM)                   ; VMM GC Builtin import
34
 
extern NAME(cpumGCHandleNPAndGP)       ; CPUMGC.cpp
35
 
 
36
 
;
37
 
; Enables write protection of Hypervisor memory pages.
38
 
; !note! Must be commented out for Trap8 debug handler.
39
 
;
40
 
%define ENABLE_WRITE_PROTECTION 1
41
 
 
42
 
BEGINCODE
43
 
 
44
 
 
45
 
;;
46
 
; Restores GC context before doing iret.
47
 
;
48
 
; @param    [esp + 4]   Pointer to interrupt stack frame, i.e. pointer
49
 
;                       to the a struct with this layout:
50
 
;                           00h eip
51
 
;                           04h cs
52
 
;                           08h eflags
53
 
;                           0ch esp
54
 
;                           10h ss
55
 
;                           14h es (V86 only)
56
 
;                           18h ds (V86 only)
57
 
;                           1Ch fs (V86 only)
58
 
;                           20h gs (V86 only)
59
 
;
60
 
; @uses     everything but cs, ss, esp, and eflags.
61
 
;
62
 
; @remark   Assumes we're restoring in Ring-0 a context which is not Ring-0.
63
 
;           Further assumes flat stack and valid ds.
64
 
 
65
 
BEGINPROC CPUMGCRestoreInt
66
 
    ;
67
 
    ; Update iret frame.
68
 
    ;
69
 
    mov     eax, [esp + 4]              ; get argument
70
 
    mov     edx, IMP(g_CPUM)
71
 
    ; Convert to CPUMCPU pointer
72
 
    add     edx, [edx + CPUM.offCPUMCPU0]
73
 
 
74
 
    mov     ecx, [edx + CPUMCPU.Guest.eip]
75
 
    mov     [eax +  0h], ecx
76
 
    mov     ecx, [edx + CPUMCPU.Guest.cs]
77
 
    mov     [eax +  4h], ecx
78
 
    mov     ecx, [edx + CPUMCPU.Guest.eflags]
79
 
    mov     [eax +  8h], ecx
80
 
    mov     ecx, [edx + CPUMCPU.Guest.esp]
81
 
    mov     [eax + 0ch], ecx
82
 
    mov     ecx, [edx + CPUMCPU.Guest.ss]
83
 
    mov     [eax + 10h], ecx
84
 
 
85
 
    test    dword [edx + CPUMCPU.Guest.eflags], X86_EFL_VM
86
 
    jnz short CPUMGCRestoreInt_V86
87
 
 
88
 
    ;
89
 
    ; Load registers.
90
 
    ;
91
 
    ; todo: potential trouble loading invalid es,fs,gs,ds because
92
 
    ;       of a VMM imposed exception?
93
 
    mov     es,  [edx + CPUMCPU.Guest.es]
94
 
    mov     fs,  [edx + CPUMCPU.Guest.fs]
95
 
    mov     gs,  [edx + CPUMCPU.Guest.gs]
96
 
    mov     esi, [edx + CPUMCPU.Guest.esi]
97
 
    mov     edi, [edx + CPUMCPU.Guest.edi]
98
 
    mov     ebp, [edx + CPUMCPU.Guest.ebp]
99
 
    mov     ebx, [edx + CPUMCPU.Guest.ebx]
100
 
    mov     ecx, [edx + CPUMCPU.Guest.ecx]
101
 
    mov     eax, [edx + CPUMCPU.Guest.eax]
102
 
    push    dword [edx + CPUMCPU.Guest.ds]
103
 
    mov     edx, [edx + CPUMCPU.Guest.edx]
104
 
    pop     ds
105
 
 
106
 
    ret
107
 
 
108
 
CPUMGCRestoreInt_V86:
109
 
    ; iret restores ds, es, fs & gs
110
 
    mov     ecx, [edx + CPUMCPU.Guest.es]
111
 
    mov     [eax + 14h], ecx
112
 
    mov     ecx, [edx + CPUMCPU.Guest.ds]
113
 
    mov     [eax + 18h], ecx
114
 
    mov     ecx, [edx + CPUMCPU.Guest.fs]
115
 
    mov     [eax + 1Ch], ecx
116
 
    mov     ecx, [edx + CPUMCPU.Guest.gs]
117
 
    mov     [eax + 20h], ecx
118
 
    mov     esi, [edx + CPUMCPU.Guest.esi]
119
 
    mov     edi, [edx + CPUMCPU.Guest.edi]
120
 
    mov     ebp, [edx + CPUMCPU.Guest.ebp]
121
 
    mov     ebx, [edx + CPUMCPU.Guest.ebx]
122
 
    mov     ecx, [edx + CPUMCPU.Guest.ecx]
123
 
    mov     eax, [edx + CPUMCPU.Guest.eax]
124
 
    mov     edx, [edx + CPUMCPU.Guest.edx]
125
 
    ret
126
 
 
127
 
ENDPROC CPUMGCRestoreInt
128
 
 
129
 
 
130
 
;;
131
 
; Calls a guest trap/interrupt handler directly
132
 
; Assumes a trap stack frame has already been setup on the guest's stack!
133
 
;
134
 
; @param   pRegFrame   [esp + 4]  Original trap/interrupt context
135
 
; @param   selCS       [esp + 8]  Code selector of handler
136
 
; @param   pHandler    [esp + 12] GC virtual address of handler
137
 
; @param   eflags      [esp + 16] Callee's EFLAGS
138
 
; @param   selSS       [esp + 20] Stack selector for handler
139
 
; @param   pEsp        [esp + 24] Stack address for handler
140
 
;
141
 
; @remark This call never returns!
142
 
;
143
 
; VMMRCDECL(void) CPUMGCCallGuestTrapHandler(PCPUMCTXCORE pRegFrame, uint32_t selCS, RTGCPTR pHandler, uint32_t eflags, uint32_t selSS, RTGCPTR pEsp);
144
 
align 16
145
 
BEGINPROC_EXPORTED CPUMGCCallGuestTrapHandler
146
 
    mov     ebp, esp
147
 
 
148
 
    ; construct iret stack frame
149
 
    push    dword [ebp + 20]                ; SS
150
 
    push    dword [ebp + 24]                ; ESP
151
 
    push    dword [ebp + 16]                ; EFLAGS
152
 
    push    dword [ebp + 8]                 ; CS
153
 
    push    dword [ebp + 12]                ; EIP
154
 
 
155
 
    ;
156
 
    ; enable WP
157
 
    ;
158
 
%ifdef ENABLE_WRITE_PROTECTION
159
 
    mov     eax, cr0
160
 
    or      eax, X86_CR0_WRITE_PROTECT
161
 
    mov     cr0, eax
162
 
%endif
163
 
 
164
 
    ; restore CPU context (all except cs, eip, ss, esp & eflags; which are restored or overwritten by iret)
165
 
    mov     ebp, [ebp + 4]                  ; pRegFrame
166
 
    mov     ebx, [ebp + CPUMCTXCORE.ebx]
167
 
    mov     ecx, [ebp + CPUMCTXCORE.ecx]
168
 
    mov     edx, [ebp + CPUMCTXCORE.edx]
169
 
    mov     esi, [ebp + CPUMCTXCORE.esi]
170
 
    mov     edi, [ebp + CPUMCTXCORE.edi]
171
 
 
172
 
    ;; @todo  load segment registers *before* enabling WP.
173
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_GS | CPUM_HANDLER_CTXCORE_IN_EBP
174
 
    mov     gs, [ebp + CPUMCTXCORE.gs]
175
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_FS | CPUM_HANDLER_CTXCORE_IN_EBP
176
 
    mov     fs, [ebp + CPUMCTXCORE.fs]
177
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_ES | CPUM_HANDLER_CTXCORE_IN_EBP
178
 
    mov     es, [ebp + CPUMCTXCORE.es]
179
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_DS | CPUM_HANDLER_CTXCORE_IN_EBP
180
 
    mov     ds, [ebp + CPUMCTXCORE.ds]
181
 
 
182
 
    mov     eax, [ebp + CPUMCTXCORE.eax]
183
 
    mov     ebp, [ebp + CPUMCTXCORE.ebp]
184
 
 
185
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
186
 
    iret
187
 
ENDPROC CPUMGCCallGuestTrapHandler
188
 
 
189
 
 
190
 
;;
191
 
; Performs an iret to V86 code
192
 
; Assumes a trap stack frame has already been setup on the guest's stack!
193
 
;
194
 
; @param   pRegFrame   Original trap/interrupt context
195
 
;
196
 
; This function does not return!
197
 
;
198
 
;VMMRCDECL(void) CPUMGCCallV86Code(PCPUMCTXCORE pRegFrame);
199
 
align 16
200
 
BEGINPROC CPUMGCCallV86Code
201
 
    mov     ebp, [esp + 4]                  ; pRegFrame
202
 
 
203
 
    ; construct iret stack frame
204
 
    push    dword [ebp + CPUMCTXCORE.gs]
205
 
    push    dword [ebp + CPUMCTXCORE.fs]
206
 
    push    dword [ebp + CPUMCTXCORE.ds]
207
 
    push    dword [ebp + CPUMCTXCORE.es]
208
 
    push    dword [ebp + CPUMCTXCORE.ss]
209
 
    push    dword [ebp + CPUMCTXCORE.esp]
210
 
    push    dword [ebp + CPUMCTXCORE.eflags]
211
 
    push    dword [ebp + CPUMCTXCORE.cs]
212
 
    push    dword [ebp + CPUMCTXCORE.eip]
213
 
 
214
 
    ;
215
 
    ; enable WP
216
 
    ;
217
 
%ifdef ENABLE_WRITE_PROTECTION
218
 
    mov     eax, cr0
219
 
    or      eax, X86_CR0_WRITE_PROTECT
220
 
    mov     cr0, eax
221
 
%endif
222
 
 
223
 
    ; restore CPU context (all except cs, eip, ss, esp, eflags, ds, es, fs & gs; which are restored or overwritten by iret)
224
 
    mov     eax, [ebp + CPUMCTXCORE.eax]
225
 
    mov     ebx, [ebp + CPUMCTXCORE.ebx]
226
 
    mov     ecx, [ebp + CPUMCTXCORE.ecx]
227
 
    mov     edx, [ebp + CPUMCTXCORE.edx]
228
 
    mov     esi, [ebp + CPUMCTXCORE.esi]
229
 
    mov     edi, [ebp + CPUMCTXCORE.edi]
230
 
    mov     ebp, [ebp + CPUMCTXCORE.ebp]
231
 
 
232
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
233
 
    iret
234
 
ENDPROC CPUMGCCallV86Code
235
 
 
236
 
 
237
 
;;
238
 
; This is a main entry point for resuming (or starting) guest
239
 
; code execution.
240
 
;
241
 
; We get here directly from VMMSwitcher.asm (jmp at the end
242
 
; of VMMSwitcher_HostToGuest).
243
 
;
244
 
; This call never returns!
245
 
;
246
 
; @param    edx     Pointer to CPUM structure.
247
 
;
248
 
align 16
249
 
BEGINPROC_EXPORTED CPUMGCResumeGuest
250
 
    ; Convert to CPUMCPU pointer
251
 
    add     edx, [edx + CPUM.offCPUMCPU0]
252
 
    ;
253
 
    ; Setup iretd
254
 
    ;
255
 
    push    dword [edx + CPUMCPU.Guest.ss]
256
 
    push    dword [edx + CPUMCPU.Guest.esp]
257
 
    push    dword [edx + CPUMCPU.Guest.eflags]
258
 
    push    dword [edx + CPUMCPU.Guest.cs]
259
 
    push    dword [edx + CPUMCPU.Guest.eip]
260
 
 
261
 
    ;
262
 
    ; Restore registers.
263
 
    ;
264
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_ES
265
 
    mov     es,  [edx + CPUMCPU.Guest.es]
266
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_FS
267
 
    mov     fs,  [edx + CPUMCPU.Guest.fs]
268
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_GS
269
 
    mov     gs,  [edx + CPUMCPU.Guest.gs]
270
 
 
271
 
%ifdef VBOX_WITH_STATISTICS
272
 
    ;
273
 
    ; Statistics.
274
 
    ;
275
 
    push    edx
276
 
    mov     edx, IMP(g_VM)
277
 
    lea     edx, [edx + VM.StatTotalQemuToGC]
278
 
    STAM_PROFILE_ADV_STOP edx
279
 
 
280
 
    mov     edx, IMP(g_VM)
281
 
    lea     edx, [edx + VM.StatTotalInGC]
282
 
    STAM_PROFILE_ADV_START edx
283
 
    pop     edx
284
 
%endif
285
 
 
286
 
    ;
287
 
    ; enable WP
288
 
    ;
289
 
%ifdef ENABLE_WRITE_PROTECTION
290
 
    mov     eax, cr0
291
 
    or      eax, X86_CR0_WRITE_PROTECT
292
 
    mov     cr0, eax
293
 
%endif
294
 
 
295
 
    ;
296
 
    ; Continue restore.
297
 
    ;
298
 
    mov     esi, [edx + CPUMCPU.Guest.esi]
299
 
    mov     edi, [edx + CPUMCPU.Guest.edi]
300
 
    mov     ebp, [edx + CPUMCPU.Guest.ebp]
301
 
    mov     ebx, [edx + CPUMCPU.Guest.ebx]
302
 
    mov     ecx, [edx + CPUMCPU.Guest.ecx]
303
 
    mov     eax, [edx + CPUMCPU.Guest.eax]
304
 
    push    dword [edx + CPUMCPU.Guest.ds]
305
 
    mov     edx, [edx + CPUMCPU.Guest.edx]
306
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_DS
307
 
    pop     ds
308
 
 
309
 
    ; restart execution.
310
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
311
 
    iretd
312
 
ENDPROC     CPUMGCResumeGuest
313
 
 
314
 
 
315
 
;;
316
 
; This is a main entry point for resuming (or starting) guest
317
 
; code execution for raw V86 mode
318
 
;
319
 
; We get here directly from VMMSwitcher.asm (jmp at the end
320
 
; of VMMSwitcher_HostToGuest).
321
 
;
322
 
; This call never returns!
323
 
;
324
 
; @param    edx     Pointer to CPUM structure.
325
 
;
326
 
align 16
327
 
BEGINPROC_EXPORTED CPUMGCResumeGuestV86
328
 
    ; Convert to CPUMCPU pointer
329
 
    add     edx, [edx + CPUM.offCPUMCPU0]
330
 
    ;
331
 
    ; Setup iretd
332
 
    ;
333
 
    push    dword [edx + CPUMCPU.Guest.gs]
334
 
    push    dword [edx + CPUMCPU.Guest.fs]
335
 
    push    dword [edx + CPUMCPU.Guest.ds]
336
 
    push    dword [edx + CPUMCPU.Guest.es]
337
 
 
338
 
    push    dword [edx + CPUMCPU.Guest.ss]
339
 
    push    dword [edx + CPUMCPU.Guest.esp]
340
 
 
341
 
    push    dword [edx + CPUMCPU.Guest.eflags]
342
 
    push    dword [edx + CPUMCPU.Guest.cs]
343
 
    push    dword [edx + CPUMCPU.Guest.eip]
344
 
 
345
 
    ;
346
 
    ; Restore registers.
347
 
    ;
348
 
 
349
 
%ifdef VBOX_WITH_STATISTICS
350
 
    ;
351
 
    ; Statistics.
352
 
    ;
353
 
    push    edx
354
 
    mov     edx, IMP(g_VM)
355
 
    lea     edx, [edx + VM.StatTotalQemuToGC]
356
 
    STAM_PROFILE_ADV_STOP edx
357
 
 
358
 
    mov     edx, IMP(g_VM)
359
 
    lea     edx, [edx + VM.StatTotalInGC]
360
 
    STAM_PROFILE_ADV_START edx
361
 
    pop     edx
362
 
%endif
363
 
 
364
 
    ;
365
 
    ; enable WP
366
 
    ;
367
 
%ifdef ENABLE_WRITE_PROTECTION
368
 
    mov     eax, cr0
369
 
    or      eax, X86_CR0_WRITE_PROTECT
370
 
    mov     cr0, eax
371
 
%endif
372
 
 
373
 
    ;
374
 
    ; Continue restore.
375
 
    ;
376
 
    mov     esi, [edx + CPUMCPU.Guest.esi]
377
 
    mov     edi, [edx + CPUMCPU.Guest.edi]
378
 
    mov     ebp, [edx + CPUMCPU.Guest.ebp]
379
 
    mov     ecx, [edx + CPUMCPU.Guest.ecx]
380
 
    mov     ebx, [edx + CPUMCPU.Guest.ebx]
381
 
    mov     eax, [edx + CPUMCPU.Guest.eax]
382
 
    mov     edx, [edx + CPUMCPU.Guest.edx]
383
 
 
384
 
    ; restart execution.
385
 
    TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
386
 
    iretd
387
 
ENDPROC     CPUMGCResumeGuestV86
388