1 | ; $Id: bs3-mode-SwitchToPE16.asm 59950 2016-03-08 07:50:19Z 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 | BS3_PROC_BEGIN_MODE Bs3SwitchToPE16
|
---|
43 | %ifdef TMPL_PE16
|
---|
44 | ret
|
---|
45 |
|
---|
46 | %elif BS3_MODE_IS_V86(TMPL_MODE)
|
---|
47 | ;
|
---|
48 | ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
|
---|
49 | ;
|
---|
50 | extern BS3_CMN_NM(Bs3SwitchToRing0)
|
---|
51 | call BS3_CMN_NM(Bs3SwitchToRing0)
|
---|
52 | extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPE16)
|
---|
53 | jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToPE16)
|
---|
54 |
|
---|
55 | %else
|
---|
56 | ;
|
---|
57 | ; Switch to 16-bit mode and prepare for returning in 16-bit mode.
|
---|
58 | ;
|
---|
59 | %if TMPL_BITS != 16
|
---|
60 | shl xPRE [xSP + xCB], TMPL_BITS - 16 ; Adjust the return address.
|
---|
61 | add xSP, xCB - 2
|
---|
62 |
|
---|
63 | ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
|
---|
64 | jmp .sixteen_bit_segment
|
---|
65 | BS3_BEGIN_TEXT16
|
---|
66 | BS3_SET_BITS TMPL_BITS
|
---|
67 | .sixteen_bit_segment:
|
---|
68 | %endif
|
---|
69 |
|
---|
70 | ;
|
---|
71 | ; Switch to real mode.
|
---|
72 | ;
|
---|
73 | extern TMPL_NM(Bs3SwitchToRM)
|
---|
74 | call TMPL_NM(Bs3SwitchToRM)
|
---|
75 | BS3_SET_BITS 16
|
---|
76 |
|
---|
77 | push ax
|
---|
78 | push cx
|
---|
79 | pushf
|
---|
80 | cli
|
---|
81 |
|
---|
82 | ;
|
---|
83 | ; Load the GDT and enable PE16.
|
---|
84 | ;
|
---|
85 | BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
|
---|
86 | BS3_BEGIN_TEXT16
|
---|
87 | mov ax, BS3SYSTEM16
|
---|
88 | mov ds, ax
|
---|
89 | lgdt [Bs3Lgdt_Gdt]
|
---|
90 |
|
---|
91 | smsw ax
|
---|
92 | or ax, X86_CR0_PE
|
---|
93 | lmsw ax
|
---|
94 |
|
---|
95 | ;
|
---|
96 | ; Convert from real mode stack to protected mode stack.
|
---|
97 | ;
|
---|
98 | mov ax, .p16_stack
|
---|
99 | extern NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
|
---|
100 | jmp NAME(Bs3ConvertRMStackToP16UsingCxReturnToAx_c16)
|
---|
101 | .p16_stack:
|
---|
102 |
|
---|
103 | ;
|
---|
104 | ; Call routine for doing mode specific setups.
|
---|
105 | ;
|
---|
106 | extern NAME(Bs3EnteredMode_pe16)
|
---|
107 | call NAME(Bs3EnteredMode_pe16)
|
---|
108 |
|
---|
109 | popf
|
---|
110 | pop cx
|
---|
111 | pop ax
|
---|
112 | ret
|
---|
113 |
|
---|
114 | %if TMPL_BITS != 16
|
---|
115 | TMPL_BEGIN_TEXT
|
---|
116 | %endif
|
---|
117 | %endif
|
---|
118 | BS3_PROC_END_MODE Bs3SwitchToPE16
|
---|
119 |
|
---|