VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16.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: 4.6 KB
Line 
1; $Id: bs3-mode-SwitchToPE16.asm 60557 2016-04-19 03:01:35Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPE16
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 16-bit unpaged protected mode from any other mode.
32;
33; @cproto BS3_DECL(void) Bs3SwitchToPE16(void);
34;
35; @uses Nothing (except high 32-bit register parts).
36;
37; @remarks Obviously returns to 16-bit mode, even if the caller was
38; in 32-bit or 64-bit mode.
39;
40; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
41;
42%if TMPL_BITS == 16
43BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToPE16_Safe), function , 0
44%endif
45BS3_PROC_BEGIN_MODE Bs3SwitchToPE16, BS3_PBC_NEAR
46%ifdef TMPL_PE16
47 extern BS3_CMN_NM(Bs3SwitchToRing0)
48 call BS3_CMN_NM(Bs3SwitchToRing0)
49 push ax
50 mov ax, BS3_SEL_R0_DS16
51 mov ds, ax
52 mov es, ax
53 pop ax
54 ret
55
56%elif BS3_MODE_IS_V86(TMPL_MODE)
57 ;
58 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
59 ;
60 extern BS3_CMN_NM(Bs3SwitchToRing0)
61 call BS3_CMN_NM(Bs3SwitchToRing0)
62 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPE16)
63 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPE16)
64
65%else
66 ;
67 ; Switch to 16-bit mode and prepare for returning in 16-bit mode.
68 ;
69 %if TMPL_BITS != 16
70 shl xPRE [xSP + xCB], TMPL_BITS - 16 ; Adjust the return address.
71 add xSP, xCB - 2
72
73 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
74 jmp .sixteen_bit_segment
75BS3_BEGIN_TEXT16
76 BS3_SET_BITS TMPL_BITS
77.sixteen_bit_segment:
78 %endif
79
80 ;
81 ; Switch to real mode.
82 ;
83 extern TMPL_NM(Bs3SwitchToRM)
84 call TMPL_NM(Bs3SwitchToRM)
85 BS3_SET_BITS 16
86
87 push ax
88 push cx
89 pushf
90 cli
91
92 ;
93 ; Load the GDT and enable PE16.
94 ;
95BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
96BS3_BEGIN_TEXT16
97 mov ax, BS3SYSTEM16
98 mov ds, ax
99 lgdt [Bs3Lgdt_Gdt]
100
101 smsw ax
102 or ax, X86_CR0_PE
103 lmsw ax
104
105 ;
106 ; Convert from real mode stack to protected mode stack.
107 ;
108 mov ax, .p16_stack
109 extern NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
110 jmp NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
111.p16_stack:
112
113 ;
114 ; Call routine for doing mode specific setups.
115 ;
116 extern NAME(Bs3EnteredMode_pe16)
117 call NAME(Bs3EnteredMode_pe16)
118
119 popf
120 pop cx
121 pop ax
122 ret
123
124 %if TMPL_BITS != 16
125TMPL_BEGIN_TEXT
126 %endif
127%endif
128BS3_PROC_END_MODE Bs3SwitchToPE16
129
130
131%if TMPL_BITS == 16
132;;
133; Custom far stub.
134BS3_BEGIN_TEXT16_FARSTUBS
135BS3_PROC_BEGIN_MODE Bs3SwitchToPE16, BS3_PBC_FAR
136 inc bp
137 push bp
138 mov bp, sp
139
140 ; Call the real thing.
141 call TMPL_NM(Bs3SwitchToPE16)
142
143 %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
144 ; Jmp to common code for the tedious conversion.
145 BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
146 jmp Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
147 %else
148 pop bp
149 dec bp
150 retf
151 %endif
152BS3_PROC_END_MODE Bs3SwitchToPE16
153
154%else
155;;
156; Safe far return to non-BS3TEXT16 code.
157BS3_EXTERN_CMN Bs3SwitchHlpConvFlatRetToRetfProtMode
158BS3_BEGIN_TEXT16
159BS3_SET_BITS TMPL_BITS
160BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_Safe, BS3_PBC_NEAR
161 call Bs3SwitchHlpConvFlatRetToRetfProtMode ; Special internal function. Uses nothing, but modifies the stack.
162 call TMPL_NM(Bs3SwitchToPE16)
163 BS3_SET_BITS 16
164 retf
165BS3_PROC_END_MODE Bs3SwitchToPE16_Safe
166%endif
167
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