1 | ; $Id: bs3-cmn-ExtCtxRestoreEx.asm 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3ExtCtxRestoreEx.
|
---|
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 |
|
---|
39 |
|
---|
40 | %if ARCH_BITS != 64
|
---|
41 | BS3_EXTERN_DATA16 g_bBs3CurrentMode
|
---|
42 |
|
---|
43 | BS3_BEGIN_TEXT64
|
---|
44 | extern _Bs3ExtCtxRestore_c64
|
---|
45 | %if ARCH_BITS == 16
|
---|
46 | extern BS3_CMN_NM(Bs3SelProtFar16DataToFlat)
|
---|
47 | extern _Bs3SwitchTo16Bit_c64
|
---|
48 | %else
|
---|
49 | extern _Bs3SwitchTo32Bit_c64
|
---|
50 | %endif
|
---|
51 |
|
---|
52 | TMPL_BEGIN_TEXT
|
---|
53 | extern BS3_CMN_NM(Bs3SwitchTo64Bit)
|
---|
54 | %if ARCH_BITS == 16
|
---|
55 | extern BS3_CMN_NM(Bs3SelProtFar16DataToFlat)
|
---|
56 | %endif
|
---|
57 | %endif
|
---|
58 |
|
---|
59 | extern BS3_CMN_NM(Bs3ExtCtxRestore)
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | ;;
|
---|
64 | ; Restores the extended CPU context (FPU, SSE, AVX, ++), full 64-bit
|
---|
65 | ; when in long mode.
|
---|
66 | ;
|
---|
67 | ; @param pExtCtx
|
---|
68 | ;
|
---|
69 | BS3_PROC_BEGIN_CMN Bs3ExtCtxRestoreEx, BS3_PBC_NEAR
|
---|
70 | %if ARCH_BITS == 64
|
---|
71 | jmp BS3_CMN_NM(Bs3ExtCtxRestore)
|
---|
72 | %else
|
---|
73 | push xBP
|
---|
74 | mov xBP, xSP
|
---|
75 | push sAX
|
---|
76 |
|
---|
77 | ;
|
---|
78 | ; Check if we're in long mode.
|
---|
79 | ;
|
---|
80 | mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
|
---|
81 | and al, BS3_MODE_SYS_MASK
|
---|
82 | cmp al, BS3_MODE_SYS_LM
|
---|
83 | je .in_long_mode
|
---|
84 |
|
---|
85 | ;
|
---|
86 | ; Not in long mode, so do normal restore.
|
---|
87 | ;
|
---|
88 | pop sAX
|
---|
89 | leave
|
---|
90 | jmp BS3_CMN_NM(Bs3ExtCtxRestore)
|
---|
91 |
|
---|
92 | ;
|
---|
93 | ; Switch to 64-bit to do the restoring so we can restore 64-bit only state.
|
---|
94 | ;
|
---|
95 | .in_long_mode:
|
---|
96 | push sCX
|
---|
97 | BONLY16 push sDX
|
---|
98 |
|
---|
99 | ; Load ecx with the flat pExtCtx address.
|
---|
100 | mov ecx, [xBP + xCB + cbCurRetAddr]
|
---|
101 |
|
---|
102 | %if ARCH_BITS == 16
|
---|
103 | push ecx
|
---|
104 | call BS3_CMN_NM(Bs3SelProtFar16DataToFlat)
|
---|
105 | mov ecx, edx
|
---|
106 | shl ecx, 16
|
---|
107 | mov cx, ax
|
---|
108 | %endif
|
---|
109 |
|
---|
110 | ; Switch to 64-bit mode.
|
---|
111 | call BS3_CMN_NM(Bs3SwitchTo64Bit)
|
---|
112 | BITS 64
|
---|
113 |
|
---|
114 | ; Do the restore.
|
---|
115 | sub rsp, 20h
|
---|
116 | call _Bs3ExtCtxRestore_c64
|
---|
117 | add rsp, 20h
|
---|
118 |
|
---|
119 | ; Switch back to the original mode.
|
---|
120 | %if ARCH_BITS == 16
|
---|
121 | call _Bs3SwitchTo16Bit_c64
|
---|
122 | %else
|
---|
123 | call _Bs3SwitchTo32Bit_c64
|
---|
124 | %endif
|
---|
125 | BITS ARCH_BITS
|
---|
126 |
|
---|
127 | ; Restore context and return.
|
---|
128 | BONLY16 pop sDX
|
---|
129 | pop sCX
|
---|
130 |
|
---|
131 | pop sAX
|
---|
132 | leave
|
---|
133 | ret
|
---|
134 | %endif
|
---|
135 | BS3_PROC_END_CMN Bs3ExtCtxRestoreEx
|
---|
136 |
|
---|