VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32.asm@ 97613

Last change on this file since 97613 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1; $Id: bs3-mode-SwitchToPE32.asm 96407 2022-08-22 17:43:14Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPE32
4;
5
6;
7; Copyright (C) 2007-2022 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 32-bit unpaged protected mode from any other mode.
42;
43; @cproto BS3_DECL(void) Bs3SwitchToPE32(void);
44;
45; @uses Nothing (except high 32-bit register parts), upper part of ESP is
46; cleared if caller is in 16-bit mode.
47;
48; @remarks Obviously returns to 32-bit mode, even if the caller was
49; in 16-bit or 64-bit mode.
50;
51; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
52;
53BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToPE32_Safe), function, 0
54BS3_PROC_BEGIN_MODE Bs3SwitchToPE32, BS3_PBC_NEAR
55%ifdef TMPL_PE32
56 ret
57
58%elif BS3_MODE_IS_V86(TMPL_MODE)
59 ;
60 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
61 ;
62 extern BS3_CMN_NM(Bs3SwitchToRing0)
63 call BS3_CMN_NM(Bs3SwitchToRing0)
64 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPE32)
65 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPE32)
66
67%else
68 ;
69 ; Switch to real mode.
70 ;
71 %if TMPL_BITS != 32
72 %if TMPL_BITS > 32
73 shl xPRE [xSP], 32 ; Adjust the return address from 64-bit to 32-bit.
74 add rsp, xCB - 4
75 %else
76 push word 0 ; Reserve space to expand the return address.
77 %endif
78 %endif
79 %if TMPL_BITS != 16
80 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
81 jmp .sixteen_bit_segment
82BS3_BEGIN_TEXT16
83 BS3_SET_BITS TMPL_BITS
84BS3_GLOBAL_LOCAL_LABEL .sixteen_bit_segment
85 %endif
86 ;
87 ; Switch to real mode.
88 ;
89 extern TMPL_NM(Bs3SwitchToRM)
90 call TMPL_NM(Bs3SwitchToRM)
91 BS3_SET_BITS 16
92
93 push eax
94 pushfd
95 cli
96
97 ;
98 ; Load the GDT and enable PE32.
99 ;
100BS3_EXTERN_SYSTEM16 Bs3LgdtDef_Gdt
101BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
102BS3_BEGIN_TEXT16
103 mov ax, BS3SYSTEM16
104 mov ds, ax
105 lgdt [Bs3LgdtDef_Gdt] ; Will only load 24-bit base!
106
107 mov eax, cr0
108 or eax, X86_CR0_PE
109 mov cr0, eax
110 jmp BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
111BS3_BEGIN_TEXT32
112BS3_GLOBAL_LOCAL_LABEL .thirty_two_bit
113
114 ;
115 ; Convert the (now) real mode stack pointer to 32-bit flat.
116 ;
117 xor eax, eax
118 mov ax, ss
119 shl eax, 4
120 and esp, 0ffffh
121 add esp, eax
122
123 mov ax, BS3_SEL_R0_SS32
124 mov ss, ax
125
126 ;
127 ; Call rountine for doing mode specific setups.
128 ;
129 extern NAME(Bs3EnteredMode_pe32)
130 call NAME(Bs3EnteredMode_pe32)
131
132 ; Load full 32-bit GDT base address.
133 lgdt [Bs3Lgdt_Gdt wrt FLAT]
134
135 ;
136 ; Restore eax and flags (IF).
137 ;
138 %if TMPL_BITS < 32
139 and esp, 0ffffh ; Make sure the high word is zero.
140 movzx eax, word [esp + 8 + 2] ; Load return address.
141 add eax, BS3_ADDR_BS3TEXT16 ; Convert it to a flat address.
142 mov [esp + 8], eax ; Store it in the place right for 32-bit returns.
143 %endif
144 popfd
145 pop eax
146 ret
147
148 %if TMPL_BITS != 32
149TMPL_BEGIN_TEXT
150 %endif
151%endif
152BS3_PROC_END_MODE Bs3SwitchToPE32
153
154
155%if TMPL_BITS == 16
156;;
157; Custom far stub.
158BS3_BEGIN_TEXT16_FARSTUBS
159BS3_PROC_BEGIN_MODE Bs3SwitchToPE32, BS3_PBC_FAR
160 inc bp
161 push bp
162 mov bp, sp
163
164 ; Call the real thing.
165 call TMPL_NM(Bs3SwitchToPE32)
166 BS3_SET_BITS 32
167
168 ; Jmp to common code for the tedious conversion.
169 %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
170 extern _Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn_c32
171 jmp _Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn_c32
172 %else
173 extern _Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn_c32
174 jmp _Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn_c32
175 %endif
176 BS3_SET_BITS 16
177BS3_PROC_END_MODE Bs3SwitchToPE32
178%endif
179
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