VirtualBox

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

Last change on this file since 61533 was 60686, checked in by vboxsync, 9 years ago

bs3kit: Enabled full gdt base address loading (and testing).

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