VirtualBox

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

Last change on this file since 60600 was 60557, checked in by vboxsync, 9 years ago

bs3kit: move real mode version of Bs3TestDoModes out of the default 16-bit code segment.

  • 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-SwitchToPP16.asm 60557 2016-04-19 03:01:35Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPP16
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_PP16
30extern NAME(Bs3EnteredMode_pp16)
31 %ifdef TMPL_PP32
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) Bs3SwitchToPP16(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(Bs3SwitchToPP16_Safe), function , 0
51%endif
52BS3_PROC_BEGIN_MODE Bs3SwitchToPP16, BS3_PBC_NEAR
53%ifdef TMPL_PP16
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](Bs3SwitchToPP16)
70 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPP16)
71
72%else
73
74 ;
75 ; Switch to 16-bit text segment and prepare for returning in 16-bit mode.
76 ;
77 %if TMPL_BITS != 16
78 shl xPRE [xSP + xCB], TMPL_BITS - 16 ; Adjust the return address.
79 add xSP, xCB - 2
80
81 ; Must be in 16-bit segment when calling Bs3SwitchToRM and Bs3SwitchTo16Bit.
82 jmp .sixteen_bit_segment
83BS3_BEGIN_TEXT16
84 BS3_SET_BITS TMPL_BITS
85.sixteen_bit_segment:
86 %endif
87
88 %ifdef TMPL_PP32
89 ;
90 ; No need to go to real-mode here, we use the same CR3 and stuff.
91 ; Just switch to 32-bit mode and call the Bs3EnteredMode routine to
92 ; load the right descriptor tables.
93 ;
94 call Bs3SwitchTo16Bit
95 BS3_SET_BITS 16
96 call NAME(Bs3EnteredMode_pp16)
97 ret
98 %else
99
100 ;
101 ; Switch to real mode.
102 ;
103 extern TMPL_NM(Bs3SwitchToRM)
104 call TMPL_NM(Bs3SwitchToRM)
105 BS3_SET_BITS 16
106
107 push eax
108 push ecx
109 pushfd
110%ifdef BS3_STRICT
111 mov ax, ds
112 cmp ax, BS3_ADDR_BS3DATA16 >> 4
113 je .real_mode_ds_ok
114 hlt
115.real_mode_ds_ok:
116%endif
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(Bs3PagingGetRootForPP16_rm)
123 call NAME(Bs3PagingGetRootForPP16_rm)
124
125 cli
126 mov cr3, eax
127
128 ;
129 ; Make sure PAE is really off and that PSE is enabled when supported.
130 ;
131BS3_EXTERN_DATA16 g_uBs3CpuDetected
132BS3_BEGIN_TEXT16
133 test byte [1 + BS3_DATA16_WRT(g_uBs3CpuDetected)], (BS3CPU_F_CPUID >> 8)
134 jz .cr4_is_fine
135 mov eax, cr4
136 mov ecx, eax
137 and eax, ~(X86_CR4_PAE | X86_CR4_PSE)
138 test byte [1 + BS3_DATA16_WRT(g_uBs3CpuDetected)], (BS3CPU_F_PSE >> 8)
139 jz .no_pse
140 or eax, X86_CR4_PSE
141.no_pse:
142 cmp eax, ecx
143 je .cr4_is_fine
144 mov cr4, eax
145.cr4_is_fine:
146
147 ;
148 ; Load the GDT and enable PP16.
149 ;
150BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
151BS3_BEGIN_TEXT16
152 mov ax, BS3SYSTEM16
153 mov ds, ax
154 lgdt [Bs3Lgdt_Gdt]
155
156 mov eax, cr0
157 or eax, X86_CR0_PE | X86_CR0_PG
158 mov cr0, eax
159 jmp BS3_SEL_R0_CS16:.reload_cs_and_stuff
160.reload_cs_and_stuff:
161
162 ;
163 ; Convert the (now) real mode stack to 16-bit.
164 ;
165 mov ax, .stack_fix_return
166 extern NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
167 jmp NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
168.stack_fix_return:
169
170 ;
171 ; Call rountine for doing mode specific setups.
172 ;
173 call NAME(Bs3EnteredMode_pp16)
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 Bs3SwitchToPP16
186
187
188%if TMPL_BITS == 16
189;;
190; Custom far stub.
191BS3_BEGIN_TEXT16_FARSTUBS
192BS3_PROC_BEGIN_MODE Bs3SwitchToPP16, BS3_PBC_FAR
193 inc bp
194 push bp
195 mov bp, sp
196
197 ; Call the real thing.
198 call TMPL_NM(Bs3SwitchToPP16)
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 Bs3SwitchToPP16
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 Bs3SwitchToPP16_Safe, BS3_PBC_NEAR
218 call Bs3SwitchHlpConvFlatRetToRetfProtMode ; Special internal function. Uses nothing, but modifies the stack.
219 call TMPL_NM(Bs3SwitchToPP16)
220 BS3_SET_BITS 16
221 retf
222BS3_PROC_END_MODE Bs3SwitchToPP16_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