VirtualBox

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

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

bs3kit: Working 16 and 64 bit PrintChr system call, fixed/documented 64-bit calls.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1; $Id: bs3-mode-SwitchToPP32.asm 59287 2016-01-08 10:08:40Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPP32
4;
5
6;
7; Copyright (C) 2007-2015 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 32-bit paged protected mode from any other mode.
32;
33; @cproto BS3_DECL(void) Bs3SwitchToPE32(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;
42; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
43;
44BS3_PROC_BEGIN_MODE Bs3SwitchToPP32
45%ifdef TMPL_PP32
46 ret
47
48%else
49 ;
50 ; Switch to real mode.
51 ;
52 %if TMPL_BITS != 32
53 %if TMPL_BITS > 32
54 shl xPRE [xSP + xCB], 32 ; Adjust the return address from 64-bit to 32-bit.
55 add rsp, xCB - 4
56 %else
57 push word 0 ; Reserve space to expand the return address.
58 %endif
59 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
60 jmp .sixteen_bit_segment
61BS3_BEGIN_TEXT16
62 BS3_SET_BITS TMPL_BITS
63.sixteen_bit_segment:
64 %endif
65
66 ;
67 ; Switch to real mode.
68 ;
69 extern TMPL_NM(Bs3SwitchToRM)
70 call TMPL_NM(Bs3SwitchToRM)
71 BS3_SET_BITS 16
72
73 push eax
74 push ecx
75 pushfd
76
77 ;
78 ; Make sure PAE is really off and that PSE is on.
79 ;
80 mov eax, cr4
81 mov ecx, eax
82 and eax, ~X86_CR4_PAE
83 or eax, X86_CR4_PSE
84 cmp eax, ecx
85 je .cr4_is_fine
86 mov cr4, eax
87.cr4_is_fine:
88
89 ;
90 ; Get the page directory (returned in eax).
91 ; Will lazy init page tables (in 16-bit prot mode).
92 ;
93 extern NAME(Bs3PagingGetRootForPP32_rm)
94 call NAME(Bs3PagingGetRootForPP32_rm)
95
96 cli
97 mov cr3, eax
98
99 ;
100 ; Load the GDT and enable PE32.
101 ;
102BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
103BS3_BEGIN_TEXT16
104 mov ax, BS3SYSTEM16
105 mov ds, ax
106 lgdt [Bs3Lgdt_Gdt]
107
108 mov eax, cr0
109 or eax, X86_CR0_PE | X86_CR0_PG
110 mov cr0, eax
111 jmp BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
112BS3_BEGIN_TEXT32
113.thirty_two_bit:
114
115 ;
116 ; Convert the (now) real mode stack pointer to 32-bit flat.
117 ;
118 xor eax, eax
119 mov ax, ss
120 shl eax, 4
121 and esp, 0ffffh
122 add esp, eax
123
124 mov ax, BS3_SEL_R0_SS32
125 mov ss, ax
126
127 ;
128 ; Call rountine for doing mode specific setups.
129 ;
130 extern NAME(Bs3EnteredMode_pp32)
131 call NAME(Bs3EnteredMode_pp32)
132
133 ;
134 ; Restore ecx, eax and flags (IF).
135 ;
136 %if TMPL_BITS < 32
137 movzx eax, word [esp + 12 + 2] ; Load return address.
138 add eax, BS3_ADDR_BS3TEXT16 ; Convert it to a flat address.
139 mov [esp + 12], eax ; Store it in the place right for 32-bit returns.
140 %endif
141 popfd
142 pop ecx
143 pop eax
144 ret
145
146 %if TMPL_BITS != 32
147TMPL_BEGIN_TEXT
148 %endif
149%endif
150BS3_PROC_END_MODE Bs3SwitchToPP32
151
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