VirtualBox

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

Last change on this file since 104792 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1; $Id: bs3-mode-SwitchToPAE16.asm 98103 2023-01-17 14:15:46Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPAE16
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;*********************************************************************************************************************************
38;* Header Files *
39;*********************************************************************************************************************************
40%include "bs3kit-template-header.mac"
41
42
43;*********************************************************************************************************************************
44;* External Symbols *
45;*********************************************************************************************************************************
46%ifndef TMPL_PAE16
47BS3_BEGIN_TEXT16
48extern NAME(Bs3EnteredMode_pae16)
49 %ifdef TMPL_PAE32
50 BS3_EXTERN_CMN Bs3SwitchTo16Bit
51 %endif
52TMPL_BEGIN_TEXT
53%endif
54
55
56;;
57; Switch to 16-bit paged protected mode from any other mode.
58;
59; @cproto BS3_DECL(void) Bs3SwitchToPAE16(void);
60;
61; @uses Nothing (except high 32-bit register parts).
62;
63; @remarks Obviously returns to 16-bit mode, even if the caller was
64; in 32-bit or 64-bit mode.
65;
66; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
67;
68%if TMPL_BITS == 16
69BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToPAE16_Safe), function , 0
70%endif
71BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16, BS3_PBC_NEAR
72%ifdef TMPL_PAE16
73 extern BS3_CMN_NM(Bs3SwitchToRing0)
74 call BS3_CMN_NM(Bs3SwitchToRing0)
75 push ax
76 mov ax, BS3_SEL_R0_DS16
77 mov ds, ax
78 mov es, ax
79 pop ax
80 ret
81
82%elif BS3_MODE_IS_V86(TMPL_MODE)
83 ;
84 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
85 ;
86 extern BS3_CMN_NM(Bs3SwitchToRing0)
87 call BS3_CMN_NM(Bs3SwitchToRing0)
88 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPAE16)
89 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPAE16)
90
91%else
92 ;
93 ; Switch to 16-bit text segment and prepare for returning in 16-bit mode.
94 ;
95 %if TMPL_BITS != 16
96 shl xPRE [xSP], TMPL_BITS - 16 ; Adjust the return address.
97 add xSP, xCB - 2
98
99 ; Must be in 16-bit segment when calling Bs3SwitchToRM and Bs3SwitchTo16Bit.
100 jmp .sixteen_bit_segment
101BS3_BEGIN_TEXT16
102 BS3_SET_BITS TMPL_BITS
103BS3_GLOBAL_LOCAL_LABEL .sixteen_bit_segment
104 %endif
105
106 %ifdef TMPL_PAE32
107 ;
108 ; No need to go to real-mode here, we use the same CR3 and stuff.
109 ; Just switch to 32-bit mode and call the Bs3EnteredMode routine to
110 ; load the right descriptor tables.
111 ;
112 call Bs3SwitchTo16Bit
113 BS3_SET_BITS 16
114 call NAME(Bs3EnteredMode_pae16)
115 ret
116 %else
117
118 ;
119 ; Switch to real mode.
120 ;
121 extern TMPL_NM(Bs3SwitchToRM)
122 call TMPL_NM(Bs3SwitchToRM)
123 BS3_SET_BITS 16
124
125 push eax
126 push ecx
127 pushfd
128
129 ;
130 ; Get the page directory (returned in eax).
131 ; Will lazy init page tables (in 16-bit prot mode).
132 ;
133 extern NAME(Bs3PagingGetRootForPAE16_rm)
134 call NAME(Bs3PagingGetRootForPAE16_rm)
135
136 cli
137 mov cr3, eax
138
139 ;
140 ; Make sure PAE, PSE, and VME are enabled (former two require pentium pro, latter 486).
141 ;
142 mov eax, cr4
143 mov ecx, eax
144 or eax, X86_CR4_PAE | X86_CR4_PSE | X86_CR4_VME
145 cmp eax, ecx
146 je .cr4_is_fine
147 mov cr4, eax
148.cr4_is_fine:
149
150 ;
151 ; Load the GDT and enable PP16.
152 ;
153BS3_EXTERN_SYSTEM16 Bs3LgdtDef_Gdt
154BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
155BS3_BEGIN_TEXT16
156 mov ax, BS3SYSTEM16
157 mov ds, ax
158 lgdt [Bs3LgdtDef_Gdt] ; Will only load 24-bit base!
159
160 mov eax, cr0
161 or eax, X86_CR0_PE | X86_CR0_PG
162 mov cr0, eax
163 jmp BS3_SEL_R0_CS16:.reload_cs_and_stuff
164.reload_cs_and_stuff:
165
166 ;
167 ; Convert the (now) real mode stack to 16-bit.
168 ;
169 mov ax, .stack_fix_return
170 extern NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
171 jmp NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
172.stack_fix_return:
173
174 ;
175 ; Call rountine for doing mode specific setups.
176 ;
177 call NAME(Bs3EnteredMode_pae16)
178
179 ;
180 ; Load full 32-bit GDT base address from 32-bit segment.
181 ;
182 push ds
183 mov ax, BS3_SEL_SYSTEM16
184 mov ds, ax
185 jmp dword BS3_SEL_R0_CS32:.load_full_gdt_base wrt FLAT
186.load_full_gdt_base:
187 BS3_SET_BITS 32
188 lgdt [Bs3Lgdt_Gdt wrt BS3SYSTEM16]
189 jmp BS3_SEL_R0_CS16:.back_to_16bit
190.back_to_16bit:
191 BS3_SET_BITS 16
192 pop ds
193
194 popfd
195 pop ecx
196 pop eax
197 ret
198
199 %endif ; !TMPL_PP32
200 %if TMPL_BITS != 16
201TMPL_BEGIN_TEXT
202 %endif
203%endif
204BS3_PROC_END_MODE Bs3SwitchToPAE16
205
206
207%if TMPL_BITS == 16
208;;
209; Custom far stub.
210BS3_BEGIN_TEXT16_FARSTUBS
211BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16, BS3_PBC_FAR
212 inc bp
213 push bp
214 mov bp, sp
215
216 ; Call the real thing.
217 call TMPL_NM(Bs3SwitchToPAE16)
218
219 %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
220 ; Jmp to common code for the tedious conversion.
221 BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
222 jmp Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
223 %else
224 pop bp
225 dec bp
226 retf
227 %endif
228BS3_PROC_END_MODE Bs3SwitchToPAE16
229
230%else
231;;
232; Safe far return to non-BS3TEXT16 code.
233BS3_EXTERN_CMN Bs3SwitchHlpConvFlatRetToRetfProtMode
234BS3_BEGIN_TEXT16
235BS3_SET_BITS TMPL_BITS
236BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_Safe, BS3_PBC_NEAR
237 call Bs3SwitchHlpConvFlatRetToRetfProtMode ; Special internal function. Uses nothing, but modifies the stack.
238 call TMPL_NM(Bs3SwitchToPAE16)
239 BS3_SET_BITS 16
240 retf
241BS3_PROC_END_MODE Bs3SwitchToPAE16_Safe
242%endif
243
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