VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32.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: 6.1 KB
Line 
1; $Id: bs3-mode-SwitchToPP32.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPP32
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 32-bit paged 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. It doesn't not preserve the callers
50; ring, but instead changes to ring-0.
51;
52; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
53;
54BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToPP32_Safe), function, 0
55BS3_PROC_BEGIN_MODE Bs3SwitchToPP32, BS3_PBC_NEAR
56%ifdef TMPL_PP32
57 ret
58
59%elif BS3_MODE_IS_V86(TMPL_MODE)
60 ;
61 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
62 ;
63 extern BS3_CMN_NM(Bs3SwitchToRing0)
64 call BS3_CMN_NM(Bs3SwitchToRing0)
65 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPP32)
66 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPP32)
67
68%else
69 ;
70 ; Switch to real mode.
71 ;
72 %if TMPL_BITS != 32
73 %if TMPL_BITS > 32
74 shl xPRE [xSP], 32 ; Adjust the return address from 64-bit to 32-bit.
75 add rsp, xCB - 4
76 %else
77 push word 0 ; Reserve space to expand the return address.
78 %endif
79 %endif
80 %if TMPL_BITS != 16
81 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
82 jmp .sixteen_bit_segment
83BS3_BEGIN_TEXT16
84 BS3_SET_BITS TMPL_BITS
85BS3_GLOBAL_LOCAL_LABEL .sixteen_bit_segment
86 %endif
87
88 ;
89 ; Switch to real mode.
90 ;
91 extern TMPL_NM(Bs3SwitchToRM)
92 call TMPL_NM(Bs3SwitchToRM)
93 BS3_SET_BITS 16
94
95 push eax
96 push ecx
97 pushfd
98
99 ;
100 ; Make sure PAE is really off and that PSE is on when supported.
101 ;
102BS3_EXTERN_DATA16 g_uBs3CpuDetected
103BS3_BEGIN_TEXT16
104 test byte [1 + BS3_DATA16_WRT(g_uBs3CpuDetected)], (BS3CPU_F_CPUID >> 8)
105 jz .cr4_is_fine
106 mov eax, cr4
107 mov ecx, eax
108 and eax, ~(X86_CR4_PAE | X86_CR4_PSE)
109 test byte [1 + BS3_DATA16_WRT(g_uBs3CpuDetected)], (BS3CPU_F_PSE >> 8)
110 jz .no_pse
111 or eax, X86_CR4_PSE
112.no_pse:
113 cmp eax, ecx
114 je .cr4_is_fine
115 mov cr4, eax
116.cr4_is_fine:
117
118 ;
119 ; Get the page directory (returned in eax).
120 ; Will lazy init page tables (in 16-bit prot mode).
121 ;
122 extern NAME(Bs3PagingGetRootForPP32_rm)
123 call NAME(Bs3PagingGetRootForPP32_rm)
124
125 cli
126 mov cr3, eax
127
128 ;
129 ; Load the GDT and enable PE32.
130 ;
131BS3_EXTERN_SYSTEM16 Bs3LgdtDef_Gdt
132BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
133BS3_BEGIN_TEXT16
134 mov ax, BS3SYSTEM16
135 mov ds, ax
136 lgdt [Bs3LgdtDef_Gdt] ; Will only load 24-bit base!
137
138 mov eax, cr0
139 or eax, X86_CR0_PE | X86_CR0_PG
140 mov cr0, eax
141 jmp BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
142BS3_BEGIN_TEXT32
143BS3_GLOBAL_LOCAL_LABEL .thirty_two_bit
144 ;
145 ; Convert the (now) real mode stack pointer to 32-bit flat.
146 ;
147 xor eax, eax
148 mov ax, ss
149 shl eax, 4
150 and esp, 0ffffh
151 add esp, eax
152
153 mov ax, BS3_SEL_R0_SS32
154 mov ss, ax
155
156 ;
157 ; Call rountine for doing mode specific setups.
158 ;
159 extern NAME(Bs3EnteredMode_pp32)
160 call NAME(Bs3EnteredMode_pp32)
161
162 ; Load full 32-bit GDT base address.
163 lgdt [Bs3Lgdt_Gdt wrt FLAT]
164
165 ;
166 ; Restore ecx, eax and flags (IF).
167 ;
168 %if TMPL_BITS < 32
169 movzx eax, word [esp + 12 + 2] ; Load return address.
170 add eax, BS3_ADDR_BS3TEXT16 ; Convert it to a flat address.
171 mov [esp + 12], eax ; Store it in the place right for 32-bit returns.
172 %endif
173 popfd
174 pop ecx
175 pop eax
176 ret
177
178 %if TMPL_BITS != 32
179TMPL_BEGIN_TEXT
180 %endif
181%endif
182BS3_PROC_END_MODE Bs3SwitchToPP32
183
184
185%if TMPL_BITS == 16
186;;
187; Custom far stub.
188BS3_BEGIN_TEXT16_FARSTUBS
189BS3_PROC_BEGIN_MODE Bs3SwitchToPP32, BS3_PBC_FAR
190 inc bp
191 push bp
192 mov bp, sp
193
194 ; Call the real thing.
195 call TMPL_NM(Bs3SwitchToPP32)
196 BS3_SET_BITS 32
197
198 ; Jmp to common code for the tedious conversion.
199 %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
200 extern _Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn_c32
201 jmp _Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn_c32
202 %else
203 extern _Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn_c32
204 jmp _Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn_c32
205 %endif
206 BS3_SET_BITS 16
207BS3_PROC_END_MODE Bs3SwitchToPP32
208%endif
209
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