1 | ; $Id: bs3-mode-SwitchToPPV86.asm 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SwitchToPPV86
|
---|
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 | ;;
|
---|
41 | ; Switch to 16-bit v8086 paged protected mode with 32-bit sys+tss from any other mode.
|
---|
42 | ;
|
---|
43 | ; @cproto BS3_DECL(void) Bs3SwitchToPPV86(void);
|
---|
44 | ;
|
---|
45 | ; @uses Nothing (except high 32-bit register parts).
|
---|
46 | ;
|
---|
47 | ; @remarks Obviously returns to 16-bit v8086 mode, even if the caller was
|
---|
48 | ; in 32-bit or 64-bit mode.
|
---|
49 | ;
|
---|
50 | ; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
|
---|
51 | ;
|
---|
52 | %if TMPL_BITS == 16
|
---|
53 | BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToPPV86_Safe), function , 0
|
---|
54 | %endif
|
---|
55 | BS3_PROC_BEGIN_MODE Bs3SwitchToPPV86, BS3_PBC_NEAR
|
---|
56 | %if TMPL_MODE == BS3_MODE_PPV86
|
---|
57 | ret
|
---|
58 |
|
---|
59 | %else
|
---|
60 | ;
|
---|
61 | ; Switch to 32-bit PP32 and from there to V8086.
|
---|
62 | ;
|
---|
63 | extern TMPL_NM(Bs3SwitchToPP32)
|
---|
64 | call TMPL_NM(Bs3SwitchToPP32)
|
---|
65 | BS3_SET_BITS 32
|
---|
66 |
|
---|
67 | ;
|
---|
68 | ; Switch to v8086 mode after adjusting the return address.
|
---|
69 | ;
|
---|
70 | %if TMPL_BITS == 16
|
---|
71 | push word [esp]
|
---|
72 | mov word [esp + 2], 0
|
---|
73 | %elif TMPL_BITS == 64
|
---|
74 | pop dword [esp + 4]
|
---|
75 | %endif
|
---|
76 | extern _Bs3SwitchTo16BitV86_c32
|
---|
77 | jmp _Bs3SwitchTo16BitV86_c32
|
---|
78 | %endif
|
---|
79 | BS3_PROC_END_MODE Bs3SwitchToPPV86
|
---|
80 |
|
---|
81 |
|
---|
82 | %if TMPL_BITS == 16
|
---|
83 | ;;
|
---|
84 | ; Custom far stub.
|
---|
85 | BS3_BEGIN_TEXT16_FARSTUBS
|
---|
86 | BS3_PROC_BEGIN_MODE Bs3SwitchToPPV86, BS3_PBC_FAR
|
---|
87 | inc bp
|
---|
88 | push bp
|
---|
89 | mov bp, sp
|
---|
90 |
|
---|
91 | ; Call the real thing.
|
---|
92 | call TMPL_NM(Bs3SwitchToPPV86)
|
---|
93 |
|
---|
94 | %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
|
---|
95 | ; Jmp to common code for the tedious conversion.
|
---|
96 | BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
|
---|
97 | jmp Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
|
---|
98 | %else
|
---|
99 | pop bp
|
---|
100 | dec bp
|
---|
101 | retf
|
---|
102 | %endif
|
---|
103 | BS3_PROC_END_MODE Bs3SwitchToPPV86
|
---|
104 |
|
---|
105 | %else
|
---|
106 | ;;
|
---|
107 | ; Safe far return to non-BS3TEXT16 code.
|
---|
108 | BS3_EXTERN_CMN Bs3SwitchHlpConvFlatRetToRetfProtMode
|
---|
109 | BS3_BEGIN_TEXT16
|
---|
110 | BS3_SET_BITS TMPL_BITS
|
---|
111 | BS3_PROC_BEGIN_MODE Bs3SwitchToPPV86_Safe, BS3_PBC_NEAR
|
---|
112 | call Bs3SwitchHlpConvFlatRetToRetfProtMode ; Special internal function. Uses nothing, but modifies the stack.
|
---|
113 | call TMPL_NM(Bs3SwitchToPPV86)
|
---|
114 | BS3_SET_BITS 16
|
---|
115 | retf
|
---|
116 | BS3_PROC_END_MODE Bs3SwitchToPPV86_Safe
|
---|
117 | %endif
|
---|
118 |
|
---|