1 | ; $Id: bs3-cmn-ExtCtxRestore.asm 95371 2022-06-24 23:11:42Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3ExtCtxRestore.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2022 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 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 | %include "bs3kit-template-header.mac"
|
---|
28 |
|
---|
29 | extern BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
30 |
|
---|
31 |
|
---|
32 | ;;
|
---|
33 | ; Restores the extended CPU context (FPU, SSE, AVX, ++).
|
---|
34 | ;
|
---|
35 | ; @param pExtCtx
|
---|
36 | ;
|
---|
37 | BS3_PROC_BEGIN_CMN Bs3ExtCtxRestore, BS3_PBC_NEAR
|
---|
38 | push xBP
|
---|
39 | mov xBP, xSP
|
---|
40 | push sAX
|
---|
41 | push sCX
|
---|
42 | push sDX
|
---|
43 | push xBX
|
---|
44 | BONLY16 push es
|
---|
45 |
|
---|
46 | %if ARCH_BITS == 16
|
---|
47 | les bx, [xBP + xCB + cbCurRetAddr]
|
---|
48 | mov al, [es:bx + BS3EXTCTX.enmMethod]
|
---|
49 | cmp al, BS3EXTCTXMETHOD_XSAVE
|
---|
50 | je .do_16_xsave
|
---|
51 | cmp al, BS3EXTCTXMETHOD_FXSAVE
|
---|
52 | je .do_16_fxsave
|
---|
53 | cmp al, BS3EXTCTXMETHOD_ANCIENT
|
---|
54 | je .do_16_ancient
|
---|
55 | int3
|
---|
56 |
|
---|
57 | .do_16_ancient:
|
---|
58 | frstor [es:bx + BS3EXTCTX.Ctx]
|
---|
59 | jmp .return
|
---|
60 |
|
---|
61 | .do_16_fxsave:
|
---|
62 | fxrstor [es:bx + BS3EXTCTX.Ctx]
|
---|
63 | jmp .return
|
---|
64 |
|
---|
65 | .do_16_xsave:
|
---|
66 | push dword [es:bx + BS3EXTCTX.fXcr0Nominal + 4]
|
---|
67 | push dword [es:bx + BS3EXTCTX.fXcr0Nominal]
|
---|
68 | call BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
69 |
|
---|
70 | mov eax, [es:bx + BS3EXTCTX.fXcr0Nominal]
|
---|
71 | mov edx, [es:bx + BS3EXTCTX.fXcr0Nominal + 4]
|
---|
72 | xrstor [es:bx + BS3EXTCTX.Ctx]
|
---|
73 |
|
---|
74 | push dword [es:bx + BS3EXTCTX.fXcr0Saved + 4]
|
---|
75 | push dword [es:bx + BS3EXTCTX.fXcr0Saved]
|
---|
76 | call BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
77 |
|
---|
78 | add xSP, 4 * 2 * 2 ; clean up both calls
|
---|
79 | ;jmp .return
|
---|
80 |
|
---|
81 | %else
|
---|
82 | BONLY32 mov ebx, [xBP + xCB + cbCurRetAddr]
|
---|
83 | BONLY64 mov rbx, rcx
|
---|
84 |
|
---|
85 | mov al, [xBX + BS3EXTCTX.enmMethod]
|
---|
86 | cmp al, BS3EXTCTXMETHOD_XSAVE
|
---|
87 | je .do_xsave
|
---|
88 | cmp al, BS3EXTCTXMETHOD_FXSAVE
|
---|
89 | je .do_fxsave
|
---|
90 | cmp al, BS3EXTCTXMETHOD_ANCIENT
|
---|
91 | je .do_ancient
|
---|
92 | int3
|
---|
93 |
|
---|
94 | .do_ancient:
|
---|
95 | frstor [xBX + BS3EXTCTX.Ctx]
|
---|
96 | jmp .return
|
---|
97 |
|
---|
98 | .do_fxsave:
|
---|
99 | BONLY32 fxrstor [xBX + BS3EXTCTX.Ctx]
|
---|
100 | BONLY64 fxrstor64 [xBX + BS3EXTCTX.Ctx]
|
---|
101 | jmp .return
|
---|
102 |
|
---|
103 | .do_xsave:
|
---|
104 | %if ARCH_BITS == 32
|
---|
105 | push dword [xBX + BS3EXTCTX.fXcr0Nominal + 4]
|
---|
106 | push dword [xBX + BS3EXTCTX.fXcr0Nominal]
|
---|
107 | call BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
108 |
|
---|
109 | mov eax, [xBX + BS3EXTCTX.fXcr0Nominal]
|
---|
110 | mov edx, [xBX + BS3EXTCTX.fXcr0Nominal + 4]
|
---|
111 | xrstor [xBX + BS3EXTCTX.Ctx]
|
---|
112 |
|
---|
113 | push dword [xBX + BS3EXTCTX.fXcr0Saved + 4]
|
---|
114 | push dword [xBX + BS3EXTCTX.fXcr0Saved]
|
---|
115 | call BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
116 |
|
---|
117 | add xSP, 4 * 2 * 2 ; clean up both calls
|
---|
118 | %else
|
---|
119 | mov rcx, [xBX + BS3EXTCTX.fXcr0Nominal]
|
---|
120 | push rcx ; just for reserving parameter dumping space needed by Bs3RegSetXcr0
|
---|
121 | call BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
122 |
|
---|
123 | mov eax, [xBX + BS3EXTCTX.fXcr0Nominal]
|
---|
124 | mov edx, [xBX + BS3EXTCTX.fXcr0Nominal + 4]
|
---|
125 | xrstor64 [xBX + BS3EXTCTX.Ctx]
|
---|
126 |
|
---|
127 | mov rcx, [xBX + BS3EXTCTX.fXcr0Saved]
|
---|
128 | call BS3_CMN_NM(Bs3RegSetXcr0)
|
---|
129 |
|
---|
130 | add xSP, 8 ; clean up parameter space
|
---|
131 | ;jmp .return
|
---|
132 | %endif
|
---|
133 | %endif
|
---|
134 |
|
---|
135 | .return:
|
---|
136 | BONLY16 pop es
|
---|
137 | pop xBX
|
---|
138 | pop sDX
|
---|
139 | pop sCX
|
---|
140 | pop sAX
|
---|
141 | mov xSP, xBP
|
---|
142 | pop xBP
|
---|
143 | ret
|
---|
144 | BS3_PROC_END_CMN Bs3ExtCtxRestore
|
---|
145 |
|
---|