VirtualBox

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

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

bs3kit: Implemented switching to PAE16 and PAE32.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1; $Id: bs3-mode-SwitchToPAE32.asm 59244 2016-01-03 21:24:20Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPAE32
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
30;;
31; Switch to PAE paged protected mode from any other mode.
32;
33; @cproto BS3_DECL(void) Bs3SwitchToPAE32(void);
34;
35; @uses Nothing (except high 32-bit register parts), upper part of ESP is
36; cleared if caller is in 16-bit mode.
37;
38; @remarks Obviously returns to 32-bit mode, even if the caller was
39; in 16-bit or 64-bit mode. It doesn't not preserve the callers
40; ring, but instead changes to ring-0.
41;
42BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32
43%ifdef TMPL_PAE32
44 ret
45
46%else
47 ;
48 ; Switch to real mode.
49 ;
50 %if TMPL_BITS != 32
51 %if TMPL_BITS > 32
52 shl xPRE [xSP + xCB], 32 ; Adjust the return address from 64-bit to 32-bit.
53 add rsp, xCB - 4
54 %else
55 push word 0 ; Reserve space to expand the return address.
56 %endif
57 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
58 jmp .sixteen_bit_segment
59BS3_BEGIN_TEXT16
60 BS3_SET_BITS TMPL_BITS
61.sixteen_bit_segment:
62 %endif
63
64 ;
65 ; Switch to real mode.
66 ;
67 extern TMPL_NM(Bs3SwitchToRM)
68 call TMPL_NM(Bs3SwitchToRM)
69 BS3_SET_BITS 16
70
71 push eax
72 push ecx
73 pushfd
74
75 ;
76 ; Make sure both PAE and PSE are enabled (requires pentium pro).
77 ;
78 mov eax, cr4
79 mov ecx, eax
80 or eax, X86_CR4_PAE | X86_CR4_PSE
81 cmp eax, ecx
82 je .cr4_is_fine
83 mov cr4, eax
84.cr4_is_fine:
85
86 ;
87 ; Get the page directory (returned in eax).
88 ; Will lazy init page tables (in 16-bit prot mode).
89 ;
90 extern NAME(Bs3PagingGetRootForPAE32_rm)
91 call NAME(Bs3PagingGetRootForPAE32_rm)
92
93 cli
94 mov cr3, eax
95
96 ;
97 ; Load the GDT and enable PE32.
98 ;
99BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
100BS3_BEGIN_TEXT16
101 mov ax, BS3SYSTEM16
102 mov ds, ax
103 lgdt [Bs3Lgdt_Gdt]
104
105 mov eax, cr0
106 or eax, X86_CR0_PE | X86_CR0_PG
107 mov cr0, eax
108 jmp BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
109BS3_BEGIN_TEXT32
110.thirty_two_bit:
111
112 ;
113 ; Convert the (now) real mode stack pointer to 32-bit flat.
114 ;
115 xor eax, eax
116 mov ax, ss
117 shl eax, 4
118 and esp, 0ffffh
119 add esp, eax
120
121 mov ax, BS3_SEL_R0_SS32
122 mov ss, ax
123
124 ;
125 ; Call rountine for doing mode specific setups.
126 ;
127 extern NAME(Bs3EnteredMode_pae32)
128 call NAME(Bs3EnteredMode_pae32)
129
130 ;
131 ; Restore ecx, eax and flags (IF).
132 ;
133 %if TMPL_BITS < 32
134 movzx eax, word [esp + 12 + 2] ; Load return address.
135 add eax, BS3_ADDR_BS3TEXT16 ; Convert it to a flat address.
136 mov [esp + 12], eax ; Store it in the place right for 32-bit returns.
137 %endif
138 popfd
139 pop ecx
140 pop eax
141 ret
142
143 %if TMPL_BITS != 32
144TMPL_BEGIN_TEXT
145 %endif
146%endif
147BS3_PROC_END_MODE Bs3SwitchToPAE32
148
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