1 | ; $Id: bs3-mode-SwitchToLM16.asm 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SwitchToLM16
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2023 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 | ;;
|
---|
41 | ; Switch to 16-bit long mode from any other mode.
|
---|
42 | ;
|
---|
43 | ; @cproto BS3_DECL(void) Bs3SwitchToLM16(void);
|
---|
44 | ;
|
---|
45 | ; @uses Nothing (except possibly high 32-bit and/or upper 64-bit register parts).
|
---|
46 | ;
|
---|
47 | ; @remarks Obviously returns to 16-bit mode, even if the caller was in 32-bit
|
---|
48 | ; or 64-bit mode. It doesn't not preserve the callers ring, but
|
---|
49 | ; instead changes to ring-0.
|
---|
50 | ;
|
---|
51 | ; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
|
---|
52 | ;
|
---|
53 | %if TMPL_BITS == 16
|
---|
54 | BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToLM16_Safe), function , 0
|
---|
55 | %endif
|
---|
56 | BS3_PROC_BEGIN_MODE Bs3SwitchToLM16, BS3_PBC_NEAR
|
---|
57 | %ifdef TMPL_LM16
|
---|
58 | extern BS3_CMN_NM(Bs3SwitchToRing0)
|
---|
59 | call BS3_CMN_NM(Bs3SwitchToRing0)
|
---|
60 | push ax
|
---|
61 | mov ax, BS3_SEL_R0_DS16
|
---|
62 | mov ds, ax
|
---|
63 | mov es, ax
|
---|
64 | pop ax
|
---|
65 | ret
|
---|
66 |
|
---|
67 | %elifdef TMPL_CMN_LM
|
---|
68 | ;
|
---|
69 | ; Already in long mode, just switch to 16-bit.
|
---|
70 | ;
|
---|
71 | extern BS3_CMN_NM(Bs3SwitchTo16Bit)
|
---|
72 | jmp BS3_CMN_NM(Bs3SwitchTo16Bit)
|
---|
73 |
|
---|
74 | %else
|
---|
75 | ;
|
---|
76 | ; Switch to LM32 and then switch to 64-bits (IDT & TSS are the same for
|
---|
77 | ; LM16, LM32 and LM64, unlike the rest).
|
---|
78 | ;
|
---|
79 | ; (The long mode switching code is going via 32-bit protected mode, so
|
---|
80 | ; Bs3SwitchToLM32 contains the actual code for switching to avoid
|
---|
81 | ; unnecessary 32-bit -> 64-bit -> 32-bit trips.)
|
---|
82 | ;
|
---|
83 | extern TMPL_NM(Bs3SwitchToLM32)
|
---|
84 | call TMPL_NM(Bs3SwitchToLM32)
|
---|
85 | BS3_SET_BITS 32
|
---|
86 |
|
---|
87 | extern _Bs3SwitchTo16Bit_c32
|
---|
88 | %if TMPL_BITS == 16
|
---|
89 | sub esp, 2
|
---|
90 | shr dword [esp], 16
|
---|
91 | %elif TMPL_BITS == 64
|
---|
92 | pop dword [esp + 4]
|
---|
93 | %endif
|
---|
94 | jmp _Bs3SwitchTo16Bit_c32
|
---|
95 | %endif
|
---|
96 | BS3_PROC_END_MODE Bs3SwitchToLM16
|
---|
97 |
|
---|
98 |
|
---|
99 | %if TMPL_BITS == 16
|
---|
100 | ;;
|
---|
101 | ; Custom far stub.
|
---|
102 | BS3_BEGIN_TEXT16_FARSTUBS
|
---|
103 | BS3_PROC_BEGIN_MODE Bs3SwitchToLM16, BS3_PBC_FAR
|
---|
104 | inc bp
|
---|
105 | push bp
|
---|
106 | mov bp, sp
|
---|
107 |
|
---|
108 | ; Call the real thing.
|
---|
109 | call TMPL_NM(Bs3SwitchToLM16)
|
---|
110 |
|
---|
111 | %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
|
---|
112 | ; Jmp to common code for the tedious conversion.
|
---|
113 | BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
|
---|
114 | jmp Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
|
---|
115 | %else
|
---|
116 | pop bp
|
---|
117 | dec bp
|
---|
118 | retf
|
---|
119 | %endif
|
---|
120 | BS3_PROC_END_MODE Bs3SwitchToLM16
|
---|
121 |
|
---|
122 | %else
|
---|
123 | ;;
|
---|
124 | ; Safe far return to non-BS3TEXT16 code.
|
---|
125 | BS3_EXTERN_CMN Bs3SwitchHlpConvFlatRetToRetfProtMode
|
---|
126 | BS3_BEGIN_TEXT16
|
---|
127 | BS3_SET_BITS TMPL_BITS
|
---|
128 | BS3_PROC_BEGIN_MODE Bs3SwitchToLM16_Safe, BS3_PBC_NEAR
|
---|
129 | call Bs3SwitchHlpConvFlatRetToRetfProtMode ; Special internal function. Uses nothing, but modifies the stack.
|
---|
130 | call TMPL_NM(Bs3SwitchToLM16)
|
---|
131 | BS3_SET_BITS 16
|
---|
132 | retf
|
---|
133 | BS3_PROC_END_MODE Bs3SwitchToLM16_Safe
|
---|
134 |
|
---|
135 | %endif
|
---|
136 |
|
---|