VirtualBox

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

最後變更 在這個檔案從60311是 60291,由 vboxsync 提交於 9 年 前

bs3kit: A bunch of changes to be able to test the effects of a GDT page being read-only or not-present.

  • Extended the GDT so we get a whole page to play paging tricks with.
  • Added syscall for restoring a context from ring-0 so we can safely get out of bogus test context that aren't in ring-0 (non-standard CS value causing trouble here). Implemented the string print syscall since the restore syscall forced me to sort out pointers.
  • Changed most string printers to do more than one char at a time (usually a line) to save context switches (screen priting is done via INT 10h in real mode).
  • Test the CS access bit handling during INT XXh.
  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.9 KB
 
1; $Id: bs3-mode-SwitchToRM.asm 60291 2016-04-01 20:51:29Z 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.alldomusa.eu.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 GPRs and EFLAGS are unchanged (except high 32-bit register (AMD64) parts).
43; CS is loaded with BS3TEXT16.
44; SS:[RE]SP is converted to real mode address.
45; DS and ES are loaded with BS3DATA16_GROUP.
46; FS and GS are loaded with zero if present.
47;
48; @remarks Obviously returns to 16-bit mode, even if the caller was
49; in 32-bit or 64-bit mode.
50;
51; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
52;
53BS3_PROC_BEGIN_MODE Bs3SwitchToRM
54%ifdef TMPL_RM
55 push ax
56 mov ax, BS3_SEL_DATA16
57 mov ds, ax
58 mov es, ax
59 pop ax
60 ret
61
62%elif BS3_MODE_IS_V86(TMPL_MODE)
63 ;
64 ; V8086 - Switch to 16-bit ring-0 and call worker for that mode.
65 ;
66 extern BS3_CMN_NM(Bs3SwitchToRing0)
67 call BS3_CMN_NM(Bs3SwitchToRing0)
68 extern %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToRM)
69 jmp %[BS3_MODE_R0_NM_ %+ TMPL_MODE](Bs3SwitchToRM)
70
71%else
72 ;
73 ; Protected mode.
74 ; 80286 requirements for PE16 clutters the code a little.
75 ;
76 %if TMPL_MODE == BS3_MODE_PE16
77 cmp byte [BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_80286
78 ja .do_386_prologue
79 push ax
80 push bx
81 pushf
82 push word 1
83 jmp .done_prologue
84 %endif
85.do_386_prologue:
86 push sAX
87 push sBX
88 sPUSHF
89 %if TMPL_MODE == BS3_MODE_PE16
90 push word 0
91 %elif BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
92 push sDX
93 push sCX
94 %endif
95.done_prologue:
96
97 ;
98 ; Get to 16-bit ring-0 and disable interrupts.
99 ;
100 extern BS3_CMN_NM(Bs3SwitchToRing0)
101 call BS3_CMN_NM(Bs3SwitchToRing0)
102
103 cli
104
105 %if TMPL_MODE == BS3_MODE_PE16
106 ;
107 ; On 80286 we must reset the CPU to get back to real mode.
108 ;
109 pop ax
110 push ax
111 test ax, ax
112 jz .is_386_or_better
113.implement_this_later:
114 int3
115 jmp .implement_this_later
116
117 jmp .reload_cs
118
119 %elif TMPL_BITS != 16
120 ;
121 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
122 ;
123 jmp .sixteen_bit_segment wrt FLAT
124BS3_BEGIN_TEXT16
125 BS3_SET_BITS TMPL_BITS
126.sixteen_bit_segment:
127
128 extern BS3_CMN_NM(Bs3SwitchTo16Bit)
129 call BS3_CMN_NM(Bs3SwitchTo16Bit)
130 BS3_SET_BITS 16
131 %endif
132 ;
133 ; Before exiting to real mode we must load sensible selectors into the
134 ; segment registers so the hidden parts (which doesn't get reloaded in
135 ; real mode) are real mode compatible.
136 ;
137.is_386_or_better:
138;; @todo Testcase: Experiment leaving weird stuff in the hidden segment registers.
139 mov ax, BS3_SEL_R0_DS16
140 mov ds, ax
141 mov es, ax
142 mov fs, ax
143 mov gs, ax
144
145 ;
146 ; Exit to real mode.
147 ;
148 mov eax, cr0
149 and eax, X86_CR0_NO_PE_NO_PG
150 mov cr0, eax
151 jmp BS3TEXT16:.reload_cs
152.reload_cs:
153
154 ;
155 ; Convert the stack (now 16-bit prot) to real mode.
156 ;
157 mov ax, BS3_SEL_SYSTEM16
158 mov ds, ax
159 mov bx, ss
160 and bx, X86_SEL_MASK ; ASSUMES GDT stack selector
161 mov al, [bx + 4 + Bs3Gdt]
162 mov ah, [bx + 7 + Bs3Gdt]
163 add sp, [bx + 2 + Bs3Gdt] ; ASSUMES not expand down segment.
164 adc ax, 0
165%ifdef BS3_STRICT
166 test ax, 0fff0h
167 jz .stack_conv_ok
168 int3
169.stack_conv_ok:
170%endif
171 shl ax, 12
172 mov ss, ax
173 %if TMPL_BITS != 16
174 and esp, 0ffffh
175 %endif
176
177 %if BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
178 ;
179 ; Clear the long mode enable bit.
180 ;
181 mov ecx, MSR_K6_EFER
182 rdmsr
183 and eax, ~MSR_K6_EFER_LME
184 wrmsr
185 %endif
186
187 ;
188 ; Call routine for doing mode specific setups.
189 ;
190 extern NAME(Bs3EnteredMode_rm)
191 call NAME(Bs3EnteredMode_rm)
192
193 %if TMPL_MODE == BS3_MODE_PE16
194 pop ax
195 test ax, ax
196 jz .do_386_epilogue
197 popf
198 pop bx
199 pop ax
200 pop bp
201 %endif
202.do_386_epilogue:
203 %if BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
204 pop ecx
205 TMPL_ONLY_64BIT_STMT pop eax
206 pop edx
207 TMPL_ONLY_64BIT_STMT pop eax
208 %endif
209 popfd
210 TMPL_ONLY_64BIT_STMT pop eax
211 pop ebx
212 TMPL_ONLY_64BIT_STMT pop eax
213 pop eax
214 TMPL_ONLY_64BIT_STMT add sp, 4
215 retn (TMPL_BITS - 16) / 8
216
217 %if TMPL_BITS != 16
218TMPL_BEGIN_TEXT
219 %endif
220%endif
221BS3_PROC_END_MODE Bs3SwitchToRM
222
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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