VirtualBox

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

Last change on this file since 84794 was 82968, checked in by vboxsync, 5 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.0 KB
Line 
1; $Id: bs3-mode-SwitchToPAE16.asm 82968 2020-02-04 10:35:17Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPAE16
4;
5
6;
7; Copyright (C) 2007-2020 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; The contents of this file may alternatively be used under the terms
18; of the Common Development and Distribution License Version 1.0
19; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20; VirtualBox OSE distribution, in which case the provisions of the
21; CDDL are applicable instead of those of the GPL.
22;
23; You may elect to license modified versions of this file under the
24; terms and conditions of either the GPL or the CDDL or both.
25;
26
27;*********************************************************************************************************************************
28;* Header Files *
29;*********************************************************************************************************************************
30%include "bs3kit-template-header.mac"
31
32
33;*********************************************************************************************************************************
34;* External Symbols *
35;*********************************************************************************************************************************
36%ifndef TMPL_PAE16
37BS3_BEGIN_TEXT16
38extern NAME(Bs3EnteredMode_pae16)
39 %ifdef TMPL_PAE32
40 BS3_EXTERN_CMN Bs3SwitchTo16Bit
41 %endif
42TMPL_BEGIN_TEXT
43%endif
44
45
46;;
47; Switch to 16-bit paged protected mode from any other mode.
48;
49; @cproto BS3_DECL(void) Bs3SwitchToPAE16(void);
50;
51; @uses Nothing (except high 32-bit register parts).
52;
53; @remarks Obviously returns to 16-bit mode, even if the caller was
54; in 32-bit or 64-bit mode.
55;
56; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
57;
58%if TMPL_BITS == 16
59BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToPAE16_Safe), function , 0
60%endif
61BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16, BS3_PBC_NEAR
62%ifdef TMPL_PAE16
63 extern BS3_CMN_NM(Bs3SwitchToRing0)
64 call BS3_CMN_NM(Bs3SwitchToRing0)
65 push ax
66 mov ax, BS3_SEL_R0_DS16
67 mov ds, ax
68 mov es, ax
69 pop ax
70 ret
71
72%elif BS3_MODE_IS_V86(TMPL_MODE)
73 ;
74 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
75 ;
76 extern BS3_CMN_NM(Bs3SwitchToRing0)
77 call BS3_CMN_NM(Bs3SwitchToRing0)
78 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPAE16)
79 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPAE16)
80
81%else
82 ;
83 ; Switch to 16-bit text segment and prepare for returning in 16-bit mode.
84 ;
85 %if TMPL_BITS != 16
86 shl xPRE [xSP], TMPL_BITS - 16 ; Adjust the return address.
87 add xSP, xCB - 2
88
89 ; Must be in 16-bit segment when calling Bs3SwitchToRM and Bs3SwitchTo16Bit.
90 jmp .sixteen_bit_segment
91BS3_BEGIN_TEXT16
92 BS3_SET_BITS TMPL_BITS
93BS3_GLOBAL_LOCAL_LABEL .sixteen_bit_segment
94 %endif
95
96 %ifdef TMPL_PAE32
97 ;
98 ; No need to go to real-mode here, we use the same CR3 and stuff.
99 ; Just switch to 32-bit mode and call the Bs3EnteredMode routine to
100 ; load the right descriptor tables.
101 ;
102 call Bs3SwitchTo16Bit
103 BS3_SET_BITS 16
104 call NAME(Bs3EnteredMode_pae16)
105 ret
106 %else
107
108 ;
109 ; Switch to real mode.
110 ;
111 extern TMPL_NM(Bs3SwitchToRM)
112 call TMPL_NM(Bs3SwitchToRM)
113 BS3_SET_BITS 16
114
115 push eax
116 push ecx
117 pushfd
118
119 ;
120 ; Get the page directory (returned in eax).
121 ; Will lazy init page tables (in 16-bit prot mode).
122 ;
123 extern NAME(Bs3PagingGetRootForPAE16_rm)
124 call NAME(Bs3PagingGetRootForPAE16_rm)
125
126 cli
127 mov cr3, eax
128
129 ;
130 ; Make sure PAE, PSE, and VME are enabled (former two require pentium pro, latter 486).
131 ;
132 mov eax, cr4
133 mov ecx, eax
134 or eax, X86_CR4_PAE | X86_CR4_PSE | X86_CR4_VME
135 cmp eax, ecx
136 je .cr4_is_fine
137 mov cr4, eax
138.cr4_is_fine:
139
140 ;
141 ; Load the GDT and enable PP16.
142 ;
143BS3_EXTERN_SYSTEM16 Bs3LgdtDef_Gdt
144BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
145BS3_BEGIN_TEXT16
146 mov ax, BS3SYSTEM16
147 mov ds, ax
148 lgdt [Bs3LgdtDef_Gdt] ; Will only load 24-bit base!
149
150 mov eax, cr0
151 or eax, X86_CR0_PE | X86_CR0_PG
152 mov cr0, eax
153 jmp BS3_SEL_R0_CS16:.reload_cs_and_stuff
154.reload_cs_and_stuff:
155
156 ;
157 ; Convert the (now) real mode stack to 16-bit.
158 ;
159 mov ax, .stack_fix_return
160 extern NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
161 jmp NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
162.stack_fix_return:
163
164 ;
165 ; Call rountine for doing mode specific setups.
166 ;
167 call NAME(Bs3EnteredMode_pae16)
168
169 ;
170 ; Load full 32-bit GDT base address from 32-bit segment.
171 ;
172 push ds
173 mov ax, BS3_SEL_SYSTEM16
174 mov ds, ax
175 jmp dword BS3_SEL_R0_CS32:.load_full_gdt_base wrt FLAT
176.load_full_gdt_base:
177 BS3_SET_BITS 32
178 lgdt [Bs3Lgdt_Gdt wrt BS3SYSTEM16]
179 jmp BS3_SEL_R0_CS16:.back_to_16bit
180.back_to_16bit:
181 BS3_SET_BITS 16
182 pop ds
183
184 popfd
185 pop ecx
186 pop eax
187 ret
188
189 %endif ; !TMPL_PP32
190 %if TMPL_BITS != 16
191TMPL_BEGIN_TEXT
192 %endif
193%endif
194BS3_PROC_END_MODE Bs3SwitchToPAE16
195
196
197%if TMPL_BITS == 16
198;;
199; Custom far stub.
200BS3_BEGIN_TEXT16_FARSTUBS
201BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16, BS3_PBC_FAR
202 inc bp
203 push bp
204 mov bp, sp
205
206 ; Call the real thing.
207 call TMPL_NM(Bs3SwitchToPAE16)
208
209 %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
210 ; Jmp to common code for the tedious conversion.
211 BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
212 jmp Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
213 %else
214 pop bp
215 dec bp
216 retf
217 %endif
218BS3_PROC_END_MODE Bs3SwitchToPAE16
219
220%else
221;;
222; Safe far return to non-BS3TEXT16 code.
223BS3_EXTERN_CMN Bs3SwitchHlpConvFlatRetToRetfProtMode
224BS3_BEGIN_TEXT16
225BS3_SET_BITS TMPL_BITS
226BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_Safe, BS3_PBC_NEAR
227 call Bs3SwitchHlpConvFlatRetToRetfProtMode ; Special internal function. Uses nothing, but modifies the stack.
228 call TMPL_NM(Bs3SwitchToPAE16)
229 BS3_SET_BITS 16
230 retf
231BS3_PROC_END_MODE Bs3SwitchToPAE16_Safe
232%endif
233
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