VirtualBox

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

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

bs3kit: v8086 code reduction.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1; $Id: bs3-mode-SwitchToRM.asm 59950 2016-03-08 07:50:19Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToRM
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
29BS3_EXTERN_SYSTEM16 Bs3Gdt
30%if TMPL_MODE == BS3_MODE_PE16
31BS3_EXTERN_DATA16 g_uBs3CpuDetected
32%endif
33
34TMPL_BEGIN_TEXT
35
36
37;;
38; Switch to real mode from any other mode.
39;
40; @cproto BS3_DECL(void) Bs3SwitchToRM(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;
49BS3_PROC_BEGIN_MODE Bs3SwitchToRM
50%ifdef TMPL_RM
51 ret
52
53%elif BS3_MODE_IS_V86(TMPL_MODE)
54 ;
55 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
56 ;
57 extern BS3_CMN_NM(Bs3SwitchToRing0)
58 call BS3_CMN_NM(Bs3SwitchToRing0)
59 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToRM)
60 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToRM)
61
62%else
63 ;
64 ; Protected mode.
65 ;
66 push sAX
67 push sBX
68 sPUSHF
69
70 ;
71 ; Get to 16-bit ring-0 and disable interrupts.
72 ;
73 extern BS3_CMN_NM(Bs3SwitchToRing0)
74 call BS3_CMN_NM(Bs3SwitchToRing0)
75
76 cli
77
78 %if TMPL_MODE == BS3_MODE_PE16
79 ;
80 ; On 80286 we must reset the CPU to get back to real mode.
81 ;
82 mov ax, BS3_SEL_DATA16
83 mov ds, ax
84 cmp byte [BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_80286
85 jne .is_386_or_better
86.implement_this_later:
87 int3
88 jmp .implement_this_later
89
90 jmp .reload_cs
91
92 %elif TMPL_BITS != 16
93 ;
94 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
95 ;
96 jmp .sixteen_bit_segment wrt FLAT
97BS3_BEGIN_TEXT16
98 BS3_SET_BITS TMPL_BITS
99.sixteen_bit_segment:
100
101 extern BS3_CMN_NM(Bs3SwitchTo16Bit)
102 call BS3_CMN_NM(Bs3SwitchTo16Bit)
103 BS3_SET_BITS 16
104 %endif
105
106 ;
107 ; Exit to real mode.
108 ;
109.is_386_or_better:
110 mov eax, cr0
111 and eax, X86_CR0_NO_PE_NO_PG
112 mov cr0, eax
113 jmp BS3TEXT16:.reload_cs
114.reload_cs:
115
116 ;
117 ; Convert the stack (now 16-bit prot) to real mode.
118 ;
119 mov ax, BS3_SEL_SYSTEM16
120 mov ds, ax
121 mov bx, ss
122 and bx, X86_SEL_MASK ; ASSUMES GDT stack selector
123 mov al, [bx + 4 + Bs3Gdt]
124 mov ah, [bx + 7 + Bs3Gdt]
125 add sp, [bx + 2 + Bs3Gdt] ; ASSUMES not expand down segment.
126 adc ax, 0
127%ifdef BS3_STRICT
128 test ax, 0fff0h
129 jz .stack_conv_ok
130 int3
131.stack_conv_ok:
132%endif
133 shl ax, 12
134 mov ss, ax
135 %if TMPL_BITS != 16
136 and esp, 0ffffh
137 %endif
138
139 ;
140 ; Call routine for doing mode specific setups.
141 ;
142 extern NAME(Bs3EnteredMode_rm)
143 call NAME(Bs3EnteredMode_rm)
144
145 %if TMPL_BITS == 64
146 pop eax
147 popfd
148 pop ebx
149 pop ebx
150 pop eax
151 pop eax
152 %else
153 popfd
154 pop ebx
155 pop eax
156 %endif
157 retn BS3_IF_16_32_64BIT(0, 2, 6)
158
159 %if TMPL_BITS != 16
160TMPL_BEGIN_TEXT
161 %endif
162%endif
163BS3_PROC_END_MODE Bs3SwitchToRM
164
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette