VirtualBox

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

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

bs3kit: Updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1; $Id: bs3-mode-SwitchToRM.asm 59863 2016-02-26 20:59:52Z 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
30TMPL_BEGIN_TEXT
31
32
33;;
34; Switch to real mode from any other mode.
35;
36; @cproto BS3_DECL(void) Bs3SwitchToRM(void);
37;
38; @uses Nothing (except high 32-bit register parts).
39;
40; @remarks Obviously returns to 16-bit mode, even if the caller was
41; in 32-bit or 64-bit mode.
42;
43; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
44;
45BS3_PROC_BEGIN_MODE Bs3SwitchToRM
46%ifdef TMPL_RM
47 ret
48
49%else
50 push sAX
51 push sBX
52 sPUSHF
53
54 ;
55 ; Get to 16-bit ring-0 and disable interrupts.
56 ;
57 extern BS3_CMN_NM(Bs3SwitchToRing0)
58 call BS3_CMN_NM(Bs3SwitchToRing0)
59
60 cli
61
62 %if TMPL_BITS != 16
63 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
64 jmp .sixteen_bit_segment wrt FLAT
65BS3_BEGIN_TEXT16
66 BS3_SET_BITS TMPL_BITS
67.sixteen_bit_segment:
68
69 extern BS3_CMN_NM(Bs3SwitchTo16Bit)
70 call BS3_CMN_NM(Bs3SwitchTo16Bit)
71 BS3_SET_BITS 16
72 %endif
73
74 ;
75 ; Exit to real mode.
76 ;
77 mov eax, cr0
78 and eax, X86_CR0_NO_PE_NO_PG
79 mov cr0, eax
80 jmp BS3TEXT16:.reload_cs
81.reload_cs:
82
83 ;
84 ; Convert the stack (now 16-bit prot) to real mode.
85 ;
86 mov ax, BS3_SEL_SYSTEM16
87 mov ds, ax
88 mov bx, ss
89 and bx, X86_SEL_MASK ; ASSUMES GDT stack selector
90 mov al, [bx + 4 + Bs3Gdt]
91 mov ah, [bx + 7 + Bs3Gdt]
92 add sp, [bx + 2 + Bs3Gdt] ; ASSUMES not expand down segment.
93 adc ax, 0
94%ifdef BS3_STRICT
95 test ax, 0fff0h
96 jz .stack_conv_ok
97 int3
98.stack_conv_ok:
99%endif
100 shl ax, 12
101 mov ss, ax
102 %if TMPL_BITS != 16
103 and esp, 0ffffh
104 %endif
105
106 ;
107 ; Call routine for doing mode specific setups.
108 ;
109 extern NAME(Bs3EnteredMode_rm)
110 call NAME(Bs3EnteredMode_rm)
111
112 %if TMPL_BITS == 64
113 pop eax
114 popfd
115 pop ebx
116 pop ebx
117 pop eax
118 pop eax
119 %else
120 popfd
121 pop ebx
122 pop eax
123 %endif
124 retn BS3_IF_16_32_64BIT(0, 2, 6)
125
126 %if TMPL_BITS != 16
127TMPL_BEGIN_TEXT
128 %endif
129%endif
130BS3_PROC_END_MODE Bs3SwitchToRM
131
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