VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-ExtCtxSave.asm@ 106560

Last change on this file since 106560 was 106061, checked in by vboxsync, 4 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1; $Id: bs3-cmn-ExtCtxSave.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; BS3Kit - Bs3ExtCtxSave.
4;
5
6;
7; Copyright (C) 2007-2024 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%include "bs3kit-template-header.mac"
38
39extern BS3_CMN_NM(Bs3RegSetXcr0)
40
41;;
42; Saves the extended CPU context (FPU, SSE, AVX, ++).
43;
44; @param pExtCtx
45;
46BS3_PROC_BEGIN_CMN Bs3ExtCtxSave, BS3_PBC_NEAR
47 push xBP
48 mov xBP, xSP
49 push sAX
50 push sCX
51 push sDX
52 push xBX
53BONLY16 push es
54
55%if ARCH_BITS == 16
56 les bx, [xBP + xCB + cbCurRetAddr]
57 mov al, [es:bx + BS3EXTCTX.enmMethod]
58 cmp al, BS3EXTCTXMETHOD_XSAVE
59 je .do_16_xsave
60 cmp al, BS3EXTCTXMETHOD_FXSAVE
61 je .do_16_fxsave
62 cmp al, BS3EXTCTXMETHOD_ANCIENT
63 je .do_16_ancient
64 int3
65
66.do_16_ancient:
67 fnsave [es:bx + BS3EXTCTX.Ctx]
68 jmp .return
69
70.do_16_fxsave:
71 fxsave [es:bx + BS3EXTCTX.Ctx]
72 jmp .return
73
74.do_16_xsave:
75 ; xgetbv can be used in any ring!
76 xor ecx, ecx
77 xgetbv
78 mov [es:bx + BS3EXTCTX.fXcr0Saved], eax
79 mov [es:bx + BS3EXTCTX.fXcr0Saved + 4], edx
80
81 push dword [es:bx + BS3EXTCTX.fXcr0Nominal + 4]
82 push dword [es:bx + BS3EXTCTX.fXcr0Nominal]
83 call BS3_CMN_NM(Bs3RegSetXcr0)
84
85 mov eax, [es:bx + BS3EXTCTX.fXcr0Nominal]
86 mov edx, [es:bx + BS3EXTCTX.fXcr0Nominal + 4]
87 xsave [es:bx + BS3EXTCTX.Ctx]
88
89 push dword [es:bx + BS3EXTCTX.fXcr0Saved + 4]
90 push dword [es:bx + BS3EXTCTX.fXcr0Saved]
91 call BS3_CMN_NM(Bs3RegSetXcr0)
92
93 add xSP, 4 * 2 * 2 ; clean up both calls
94 ;jmp .return
95
96%else
97BONLY32 mov ebx, [xBP + xCB + cbCurRetAddr]
98BONLY64 mov rbx, rcx
99
100 mov al, [xBX + BS3EXTCTX.enmMethod]
101 cmp al, BS3EXTCTXMETHOD_XSAVE
102 je .do_xsave
103 cmp al, BS3EXTCTXMETHOD_FXSAVE
104 je .do_fxsave
105 cmp al, BS3EXTCTXMETHOD_ANCIENT
106 je .do_ancient
107 int3
108
109.do_ancient:
110 fnsave [xBX + BS3EXTCTX.Ctx]
111 jmp .return
112
113.do_fxsave:
114BONLY32 fxsave [xBX + BS3EXTCTX.Ctx]
115BONLY64 fxsave64 [xBX + BS3EXTCTX.Ctx]
116 jmp .return
117
118.do_xsave:
119 xor ecx, ecx
120 xgetbv
121 mov [xBX + BS3EXTCTX.fXcr0Saved], eax
122 mov [xBX + BS3EXTCTX.fXcr0Saved + 4], edx
123
124 %if ARCH_BITS == 32
125 push dword [xBX + BS3EXTCTX.fXcr0Nominal + 4]
126 push dword [xBX + BS3EXTCTX.fXcr0Nominal]
127 call BS3_CMN_NM(Bs3RegSetXcr0)
128
129 mov eax, [xBX + BS3EXTCTX.fXcr0Nominal]
130 mov edx, [xBX + BS3EXTCTX.fXcr0Nominal + 4]
131 xsave [xBX + BS3EXTCTX.Ctx]
132
133 push dword [xBX + BS3EXTCTX.fXcr0Saved + 4]
134 push dword [xBX + BS3EXTCTX.fXcr0Saved]
135 call BS3_CMN_NM(Bs3RegSetXcr0)
136
137 add xSP, 4 * 2 * 2 ; clean up both calls
138 %else
139 mov rcx, [xBX + BS3EXTCTX.fXcr0Nominal]
140 push rcx ; only to reserve necessary stack space for the Bs3RegSetXcr0 param dump.
141 call BS3_CMN_NM(Bs3RegSetXcr0)
142
143 mov eax, [xBX + BS3EXTCTX.fXcr0Nominal]
144 mov edx, [xBX + BS3EXTCTX.fXcr0Nominal + 4]
145 xsave64 [xBX + BS3EXTCTX.Ctx]
146
147 mov rcx, [xBX + BS3EXTCTX.fXcr0Saved]
148 call BS3_CMN_NM(Bs3RegSetXcr0)
149
150 add xSP, 8h ; clean up
151 %endif
152 ;jmp .return
153
154%endif
155
156.return:
157BONLY16 pop es
158 pop xBX
159 pop sDX
160 pop sCX
161 pop sAX
162 mov xSP, xBP
163 pop xBP
164 ret
165BS3_PROC_END_CMN Bs3ExtCtxSave
166
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