1 | ; $Id: CPUMInternal.mac 14785 2008-11-28 15:11:20Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; CPUM - Internal header file (asm).
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | ; Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | ; Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | ; additional information or have any questions.
|
---|
20 | ;
|
---|
21 |
|
---|
22 | %include "VBox/asmdefs.mac"
|
---|
23 |
|
---|
24 | %define CPUM_USED_FPU RT_BIT(0)
|
---|
25 | %define CPUM_USED_FPU_SINCE_REM RT_BIT(1)
|
---|
26 | %define CPUM_USE_SYSENTER RT_BIT(2)
|
---|
27 | %define CPUM_USE_SYSCALL RT_BIT(3)
|
---|
28 | %define CPUM_USE_DEBUG_REGS_HOST RT_BIT(4)
|
---|
29 | %define CPUM_USE_DEBUG_REGS RT_BIT(5)
|
---|
30 |
|
---|
31 | %define CPUM_HANDLER_DS 1
|
---|
32 | %define CPUM_HANDLER_ES 2
|
---|
33 | %define CPUM_HANDLER_FS 3
|
---|
34 | %define CPUM_HANDLER_GS 4
|
---|
35 | %define CPUM_HANDLER_IRET 5
|
---|
36 | %define CPUM_HANDLER_TYPEMASK 0ffh
|
---|
37 | %define CPUM_HANDLER_CTXCORE_IN_EBP RT_BIT(31)
|
---|
38 |
|
---|
39 | %define VMMGCRET_USED_FPU 040000000h
|
---|
40 |
|
---|
41 | %define FPUSTATE_SIZE 512
|
---|
42 |
|
---|
43 | ;; if anyone figures how to do %if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL) in
|
---|
44 | ; nasm please tell / fix this hack.
|
---|
45 | %ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
|
---|
46 | %define fVBOX_WITH_HYBIRD_32BIT_KERNEL 1
|
---|
47 | %else
|
---|
48 | %define fVBOX_WITH_HYBIRD_32BIT_KERNEL 0
|
---|
49 | %endif
|
---|
50 |
|
---|
51 | struc CPUM
|
---|
52 | ;
|
---|
53 | ; Hypervisor Context.
|
---|
54 | ;
|
---|
55 | alignb 64 ; the padding
|
---|
56 | .Hyper.fpu resb FPUSTATE_SIZE
|
---|
57 |
|
---|
58 | .Hyper.edi resq 1
|
---|
59 | .Hyper.esi resq 1
|
---|
60 | .Hyper.ebp resq 1
|
---|
61 | .Hyper.eax resq 1
|
---|
62 | .Hyper.ebx resq 1
|
---|
63 | .Hyper.edx resq 1
|
---|
64 | .Hyper.ecx resq 1
|
---|
65 | .Hyper.esp resq 1
|
---|
66 | .Hyper.lss_esp resd 1
|
---|
67 | .Hyper.ss resw 1
|
---|
68 | .Hyper.ssPadding resw 1
|
---|
69 | .Hyper.gs resw 1
|
---|
70 | .Hyper.gsPadding resw 1
|
---|
71 | .Hyper.fs resw 1
|
---|
72 | .Hyper.fsPadding resw 1
|
---|
73 | .Hyper.es resw 1
|
---|
74 | .Hyper.esPadding resw 1
|
---|
75 | .Hyper.ds resw 1
|
---|
76 | .Hyper.dsPadding resw 1
|
---|
77 | .Hyper.cs resw 1
|
---|
78 | .Hyper.csPadding resw 3
|
---|
79 | .Hyper.eflags resq 1
|
---|
80 | .Hyper.eip resq 1
|
---|
81 | .Hyper.r8 resq 1
|
---|
82 | .Hyper.r9 resq 1
|
---|
83 | .Hyper.r10 resq 1
|
---|
84 | .Hyper.r11 resq 1
|
---|
85 | .Hyper.r12 resq 1
|
---|
86 | .Hyper.r13 resq 1
|
---|
87 | .Hyper.r14 resq 1
|
---|
88 | .Hyper.r15 resq 1
|
---|
89 |
|
---|
90 | .Hyper.esHid.u64Base resq 1
|
---|
91 | .Hyper.esHid.u32Limit resd 1
|
---|
92 | .Hyper.esHid.Attr resd 1
|
---|
93 |
|
---|
94 | .Hyper.csHid.u64Base resq 1
|
---|
95 | .Hyper.csHid.u32Limit resd 1
|
---|
96 | .Hyper.csHid.Attr resd 1
|
---|
97 |
|
---|
98 | .Hyper.ssHid.u64Base resq 1
|
---|
99 | .Hyper.ssHid.u32Limit resd 1
|
---|
100 | .Hyper.ssHid.Attr resd 1
|
---|
101 |
|
---|
102 | .Hyper.dsHid.u64Base resq 1
|
---|
103 | .Hyper.dsHid.u32Limit resd 1
|
---|
104 | .Hyper.dsHid.Attr resd 1
|
---|
105 |
|
---|
106 | .Hyper.fsHid.u64Base resq 1
|
---|
107 | .Hyper.fsHid.u32Limit resd 1
|
---|
108 | .Hyper.fsHid.Attr resd 1
|
---|
109 |
|
---|
110 | .Hyper.gsHid.u64Base resq 1
|
---|
111 | .Hyper.gsHid.u32Limit resd 1
|
---|
112 | .Hyper.gsHid.Attr resd 1
|
---|
113 |
|
---|
114 | .Hyper.cr0 resq 1
|
---|
115 | .Hyper.cr2 resq 1
|
---|
116 | .Hyper.cr3 resq 1
|
---|
117 | .Hyper.cr4 resq 1
|
---|
118 |
|
---|
119 | .Hyper.dr resq 8
|
---|
120 |
|
---|
121 | .Hyper.gdtr resb 10 ; GDT limit + linear address
|
---|
122 | .Hyper.gdtrPadding resw 1
|
---|
123 | .Hyper.idtr resb 10 ; IDT limit + linear address
|
---|
124 | .Hyper.idtrPadding resw 1
|
---|
125 | .Hyper.ldtr resw 1
|
---|
126 | .Hyper.ldtrPadding resw 1
|
---|
127 | .Hyper.tr resw 1
|
---|
128 | .Hyper.trPadding resw 1
|
---|
129 |
|
---|
130 | .Hyper.SysEnter.cs resb 8
|
---|
131 | .Hyper.SysEnter.eip resb 8
|
---|
132 | .Hyper.SysEnter.esp resb 8
|
---|
133 |
|
---|
134 | .Hyper.msrEFER resb 8
|
---|
135 | .Hyper.msrSTAR resb 8
|
---|
136 | .Hyper.msrPAT resb 8
|
---|
137 | .Hyper.msrLSTAR resb 8
|
---|
138 | .Hyper.msrCSTAR resb 8
|
---|
139 | .Hyper.msrSFMASK resb 8
|
---|
140 | .Hyper.msrKERNELGSBASE resb 8
|
---|
141 |
|
---|
142 | .Hyper.ldtrHid.u64Base resq 1
|
---|
143 | .Hyper.ldtrHid.u32Limit resd 1
|
---|
144 | .Hyper.ldtrHid.Attr resd 1
|
---|
145 |
|
---|
146 | .Hyper.trHid.u64Base resq 1
|
---|
147 | .Hyper.trHid.u32Limit resd 1
|
---|
148 | .Hyper.trHid.Attr resd 1
|
---|
149 |
|
---|
150 | ;
|
---|
151 | ; Other stuff.
|
---|
152 | ;
|
---|
153 | alignb 64
|
---|
154 | ; hypervisor core context.
|
---|
155 | .pHyperCoreR3 RTR3PTR_RES 1
|
---|
156 | .pHyperCoreR0 RTR0PTR_RES 1
|
---|
157 | .pHyperCoreRC RTRCPTR_RES 1
|
---|
158 | ;...
|
---|
159 | .ulOffCPUMCPU resd 1
|
---|
160 | .fValidHiddenSelRegs resd 1
|
---|
161 |
|
---|
162 | ; CPUID eax=1
|
---|
163 | .CPUFeatures.edx resd 1
|
---|
164 | .CPUFeatures.ecx resd 1
|
---|
165 |
|
---|
166 | ; CPUID eax=0x80000001
|
---|
167 | .CPUFeaturesExt.edx resd 1
|
---|
168 | .CPUFeaturesExt.ecx resd 1
|
---|
169 |
|
---|
170 | .enmCPUVendor resd 1
|
---|
171 |
|
---|
172 | ; CR4 masks
|
---|
173 | .CR4.AndMask resd 1
|
---|
174 | .CR4.OrMask resd 1
|
---|
175 | ; entered rawmode?
|
---|
176 | .fRawEntered resb 1
|
---|
177 | %if RTHCPTR_CB == 8
|
---|
178 | .abPadding resb 7
|
---|
179 | %else
|
---|
180 | .abPadding resb 3
|
---|
181 | %endif
|
---|
182 |
|
---|
183 | ; CPUID leafs
|
---|
184 | .aGuestCpuIdStd resb 16*6
|
---|
185 | .aGuestCpuIdExt resb 16*10
|
---|
186 | .aGuestCpuIdCentaur resb 16*4
|
---|
187 | .GuestCpuIdDef resb 16
|
---|
188 |
|
---|
189 | alignb 64
|
---|
190 | ; CPUMCTX debug stuff...
|
---|
191 | .GuestEntry resb 1024
|
---|
192 | endstruc
|
---|
193 |
|
---|
194 | struc CPUMCPU
|
---|
195 | ;
|
---|
196 | ; Host context state
|
---|
197 | ;
|
---|
198 | .Host.fpu resb FPUSTATE_SIZE
|
---|
199 |
|
---|
200 | %if HC_ARCH_BITS == 64 || fVBOX_WITH_HYBIRD_32BIT_KERNEL
|
---|
201 | ;.Host.rax resq 1 - scratch
|
---|
202 | .Host.rbx resq 1
|
---|
203 | ;.Host.rcx resq 1 - scratch
|
---|
204 | ;.Host.rdx resq 1 - scratch
|
---|
205 | .Host.rdi resq 1
|
---|
206 | .Host.rsi resq 1
|
---|
207 | .Host.rbp resq 1
|
---|
208 | .Host.rsp resq 1
|
---|
209 | ;.Host.r8 resq 1 - scratch
|
---|
210 | ;.Host.r9 resq 1 - scratch
|
---|
211 | .Host.r10 resq 1
|
---|
212 | .Host.r11 resq 1
|
---|
213 | .Host.r12 resq 1
|
---|
214 | .Host.r13 resq 1
|
---|
215 | .Host.r14 resq 1
|
---|
216 | .Host.r15 resq 1
|
---|
217 | ;.Host.rip resd 1 - scratch
|
---|
218 | .Host.rflags resq 1
|
---|
219 | %endif
|
---|
220 | %if HC_ARCH_BITS == 32
|
---|
221 | ;.Host.eax resd 1 - scratch
|
---|
222 | .Host.ebx resd 1
|
---|
223 | ;.Host.edx resd 1 - scratch
|
---|
224 | ;.Host.ecx resd 1 - scratch
|
---|
225 | .Host.edi resd 1
|
---|
226 | .Host.esi resd 1
|
---|
227 | .Host.ebp resd 1
|
---|
228 | .Host.eflags resd 1
|
---|
229 | ;.Host.eip resd 1 - scratch
|
---|
230 | ; lss pair!
|
---|
231 | .Host.esp resd 1
|
---|
232 | %endif
|
---|
233 | .Host.ss resw 1
|
---|
234 | .Host.ssPadding resw 1
|
---|
235 | .Host.gs resw 1
|
---|
236 | .Host.gsPadding resw 1
|
---|
237 | .Host.fs resw 1
|
---|
238 | .Host.fsPadding resw 1
|
---|
239 | .Host.es resw 1
|
---|
240 | .Host.esPadding resw 1
|
---|
241 | .Host.ds resw 1
|
---|
242 | .Host.dsPadding resw 1
|
---|
243 | .Host.cs resw 1
|
---|
244 | .Host.csPadding resw 1
|
---|
245 |
|
---|
246 | %if HC_ARCH_BITS == 32 && fVBOX_WITH_HYBIRD_32BIT_KERNEL == 0
|
---|
247 | .Host.cr0 resd 1
|
---|
248 | ;.Host.cr2 resd 1 - scratch
|
---|
249 | .Host.cr3 resd 1
|
---|
250 | .Host.cr4 resd 1
|
---|
251 |
|
---|
252 | .Host.dr0 resd 1
|
---|
253 | .Host.dr1 resd 1
|
---|
254 | .Host.dr2 resd 1
|
---|
255 | .Host.dr3 resd 1
|
---|
256 | .Host.dr6 resd 1
|
---|
257 | .Host.dr7 resd 1
|
---|
258 |
|
---|
259 | .Host.gdtr resb 6 ; GDT limit + linear address
|
---|
260 | .Host.gdtrPadding resw 1
|
---|
261 | .Host.idtr resb 6 ; IDT limit + linear address
|
---|
262 | .Host.idtrPadding resw 1
|
---|
263 | .Host.ldtr resw 1
|
---|
264 | .Host.ldtrPadding resw 1
|
---|
265 | .Host.tr resw 1
|
---|
266 | .Host.trPadding resw 1
|
---|
267 |
|
---|
268 | .Host.SysEnterPadding resd 1
|
---|
269 | .Host.SysEnter.cs resq 1
|
---|
270 | .Host.SysEnter.eip resq 1
|
---|
271 | .Host.SysEnter.esp resq 1
|
---|
272 |
|
---|
273 | %else ; 64-bit
|
---|
274 |
|
---|
275 | .Host.cr0 resq 1
|
---|
276 | ;.Host.cr2 resq 1 - scratch
|
---|
277 | .Host.cr3 resq 1
|
---|
278 | .Host.cr4 resq 1
|
---|
279 | .Host.cr8 resq 1
|
---|
280 |
|
---|
281 | .Host.dr0 resq 1
|
---|
282 | .Host.dr1 resq 1
|
---|
283 | .Host.dr2 resq 1
|
---|
284 | .Host.dr3 resq 1
|
---|
285 | .Host.dr6 resq 1
|
---|
286 | .Host.dr7 resq 1
|
---|
287 |
|
---|
288 | .Host.gdtr resb 10 ; GDT limit + linear address
|
---|
289 | .Host.gdtrPadding resw 1
|
---|
290 | .Host.idtr resb 10 ; IDT limit + linear address
|
---|
291 | .Host.idtrPadding resw 1
|
---|
292 | .Host.ldtr resw 1
|
---|
293 | .Host.ldtrPadding resw 1
|
---|
294 | .Host.tr resw 1
|
---|
295 | .Host.trPadding resw 1
|
---|
296 |
|
---|
297 | .Host.SysEnter.cs resq 1
|
---|
298 | .Host.SysEnter.eip resq 1
|
---|
299 | .Host.SysEnter.esp resq 1
|
---|
300 | .Host.FSbase resq 1
|
---|
301 | .Host.GSbase resq 1
|
---|
302 | .Host.efer resq 1
|
---|
303 | %endif ; 64-bit
|
---|
304 |
|
---|
305 | ;
|
---|
306 | ; Guest context state
|
---|
307 | ; (Identical to the .Hyper chunk above.)
|
---|
308 | ;
|
---|
309 | alignb 64
|
---|
310 | .Guest.fpu resb FPUSTATE_SIZE
|
---|
311 |
|
---|
312 | .Guest.edi resq 1
|
---|
313 | .Guest.esi resq 1
|
---|
314 | .Guest.ebp resq 1
|
---|
315 | .Guest.eax resq 1
|
---|
316 | .Guest.ebx resq 1
|
---|
317 | .Guest.edx resq 1
|
---|
318 | .Guest.ecx resq 1
|
---|
319 | .Guest.esp resq 1
|
---|
320 | .Guest.lss_esp resd 1
|
---|
321 | .Guest.ss resw 1
|
---|
322 | .Guest.ssPadding resw 1
|
---|
323 | .Guest.gs resw 1
|
---|
324 | .Guest.gsPadding resw 1
|
---|
325 | .Guest.fs resw 1
|
---|
326 | .Guest.fsPadding resw 1
|
---|
327 | .Guest.es resw 1
|
---|
328 | .Guest.esPadding resw 1
|
---|
329 | .Guest.ds resw 1
|
---|
330 | .Guest.dsPadding resw 1
|
---|
331 | .Guest.cs resw 1
|
---|
332 | .Guest.csPadding resw 3
|
---|
333 | .Guest.eflags resq 1
|
---|
334 | .Guest.eip resq 1
|
---|
335 | .Guest.r8 resq 1
|
---|
336 | .Guest.r9 resq 1
|
---|
337 | .Guest.r10 resq 1
|
---|
338 | .Guest.r11 resq 1
|
---|
339 | .Guest.r12 resq 1
|
---|
340 | .Guest.r13 resq 1
|
---|
341 | .Guest.r14 resq 1
|
---|
342 | .Guest.r15 resq 1
|
---|
343 |
|
---|
344 | .Guest.esHid.u64Base resq 1
|
---|
345 | .Guest.esHid.u32Limit resd 1
|
---|
346 | .Guest.esHid.Attr resd 1
|
---|
347 |
|
---|
348 | .Guest.csHid.u64Base resq 1
|
---|
349 | .Guest.csHid.u32Limit resd 1
|
---|
350 | .Guest.csHid.Attr resd 1
|
---|
351 |
|
---|
352 | .Guest.ssHid.u64Base resq 1
|
---|
353 | .Guest.ssHid.u32Limit resd 1
|
---|
354 | .Guest.ssHid.Attr resd 1
|
---|
355 |
|
---|
356 | .Guest.dsHid.u64Base resq 1
|
---|
357 | .Guest.dsHid.u32Limit resd 1
|
---|
358 | .Guest.dsHid.Attr resd 1
|
---|
359 |
|
---|
360 | .Guest.fsHid.u64Base resq 1
|
---|
361 | .Guest.fsHid.u32Limit resd 1
|
---|
362 | .Guest.fsHid.Attr resd 1
|
---|
363 |
|
---|
364 | .Guest.gsHid.u64Base resq 1
|
---|
365 | .Guest.gsHid.u32Limit resd 1
|
---|
366 | .Guest.gsHid.Attr resd 1
|
---|
367 |
|
---|
368 | .Guest.cr0 resq 1
|
---|
369 | .Guest.cr2 resq 1
|
---|
370 | .Guest.cr3 resq 1
|
---|
371 | .Guest.cr4 resq 1
|
---|
372 |
|
---|
373 | .Guest.dr resq 8
|
---|
374 |
|
---|
375 | .Guest.gdtr resb 10 ; GDT limit + linear address
|
---|
376 | .Guest.gdtrPadding resw 1
|
---|
377 | .Guest.idtr resb 10 ; IDT limit + linear address
|
---|
378 | .Guest.idtrPadding resw 1
|
---|
379 | .Guest.ldtr resw 1
|
---|
380 | .Guest.ldtrPadding resw 1
|
---|
381 | .Guest.tr resw 1
|
---|
382 | .Guest.trPadding resw 1
|
---|
383 |
|
---|
384 | .Guest.SysEnter.cs resb 8
|
---|
385 | .Guest.SysEnter.eip resb 8
|
---|
386 | .Guest.SysEnter.esp resb 8
|
---|
387 |
|
---|
388 | .Guest.msrEFER resb 8
|
---|
389 | .Guest.msrSTAR resb 8
|
---|
390 | .Guest.msrPAT resb 8
|
---|
391 | .Guest.msrLSTAR resb 8
|
---|
392 | .Guest.msrCSTAR resb 8
|
---|
393 | .Guest.msrSFMASK resb 8
|
---|
394 | .Guest.msrKERNELGSBASE resb 8
|
---|
395 |
|
---|
396 | .Guest.ldtrHid.u64Base resq 1
|
---|
397 | .Guest.ldtrHid.u32Limit resd 1
|
---|
398 | .Guest.ldtrHid.Attr resd 1
|
---|
399 |
|
---|
400 | .Guest.trHid.u64Base resq 1
|
---|
401 | .Guest.trHid.u32Limit resd 1
|
---|
402 | .Guest.trHid.Attr resd 1
|
---|
403 |
|
---|
404 | .GuestMsr.au64 resq 64
|
---|
405 |
|
---|
406 | .fUseFlags resd 1
|
---|
407 | .fChanged resd 1
|
---|
408 | .ulOffCPUM resd 1
|
---|
409 | .u32RetCode resd 1
|
---|
410 | endstruc
|
---|
411 |
|
---|
412 |
|
---|
413 | ;;
|
---|
414 | ; Converts the CPUM pointer to CPUMCPU (for the first VMCPU)
|
---|
415 | ; @param %1 register name
|
---|
416 | %macro CPUMCPU_FROM_CPUM 1
|
---|
417 | add %1, [%1 + CPUM.ulOffCPUMCPU]
|
---|
418 | %endmacro
|
---|
419 |
|
---|
420 | ;;
|
---|
421 | ; Converts the CPUMCPU pointer to CPUM (for the first VMCPU)
|
---|
422 | ; @param %1 register name
|
---|
423 | %macro CPUM_FROM_CPUMCPU 1
|
---|
424 | sub %1, [%1 + CPUMCPU.ulOffCPUM]
|
---|
425 | %endmacro
|
---|