VirtualBox

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

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

bs3kit: Updates and fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1; $Id: bs3-mode-EnteredMode.asm 59941 2016-03-07 15:13:51Z vboxsync $
2;; @file
3; BS3Kit - Bs3EnteredMode
4;
5
6;
7; Copyright (C) 2007-2016 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_DATA16 g_bBs3CurrentMode
30TMPL_BEGIN_TEXT
31
32;;
33; @cproto BS3_DECL(void) Bs3EnteredMode(void);
34;
35; @uses Nothing.
36;
37; @remarks ASSUMES we're in ring-0 when not in some kind of real mode.
38;
39BS3_PROC_BEGIN_MODE Bs3EnteredMode
40 push xBP
41 mov xBP, xSP
42 push xAX
43%if BS3_MODE_IS_64BIT_CODE(TMPL_MODE)
44 push rcx
45 push rdx
46 push r8
47 push r9
48%endif
49
50 ;
51 ; Load stack selector (not always necessary) and sometimes CS too.
52 ;
53%if BS3_MODE_IS_RM_SYS(TMPL_MODE)
54 xor ax, ax
55%elif BS3_MODE_IS_V86(TMPL_MODE)
56 extern v86_versions_of_Bs3EnteredMode_should_not_be_dragged_into_the_link
57 call v86_versions_of_Bs3EnteredMode_should_not_be_dragged_into_the_link
58%elif BS3_MODE_IS_16BIT_CODE(TMPL_MODE)
59 jmp BS3_SEL_R0_CS16:.reloaded_cs
60.reloaded_cs:
61 mov ax, BS3_SEL_R0_SS16
62%elif BS3_MODE_IS_32BIT_CODE(TMPL_MODE)
63 mov ax, BS3_SEL_R0_SS32
64%elif BS3_MODE_IS_64BIT_CODE(TMPL_MODE)
65 mov ax, BS3_SEL_R0_DS64
66%else
67 %error "TMPL_MODE"
68%endif
69 mov ss, ax
70
71 ;
72 ; Load selector appropriate for accessing BS3SYSTEM16 data.
73 ;
74%if BS3_MODE_IS_16BIT_CODE(TMPL_MODE)
75 mov ax, BS3_SEL_SYSTEM16
76%else
77 mov ax, RT_CONCAT(BS3_SEL_R0_DS,TMPL_BITS)
78%endif
79 mov ds, ax
80
81 ;
82 ; Load the appropritate IDT or IVT.
83 ; Always 64-bit in long mode, otherwise according to TMPL_BITS.
84 ;
85%if BS3_MODE_IS_RM_SYS(TMPL_MODE)
86 BS3_EXTERN_SYSTEM16 Bs3Lidt_Ivt
87 TMPL_BEGIN_TEXT
88 lidt [Bs3Lidt_Ivt]
89
90%elif BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
91 BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt16
92 TMPL_BEGIN_TEXT
93 lidt [Bs3Lidt_Idt16 TMPL_WRT_SYSTEM16_OR_FLAT]
94
95%elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
96 BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt32
97 TMPL_BEGIN_TEXT
98 lidt [Bs3Lidt_Idt32 TMPL_WRT_SYSTEM16_OR_FLAT]
99
100%elif BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
101 BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt64
102 TMPL_BEGIN_TEXT
103 lidt [Bs3Lidt_Idt64 TMPL_WRT_SYSTEM16_OR_FLAT]
104%else
105 %error "TMPL_MODE"
106%endif
107
108%if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
109 ;
110 ; Load the appropriate task selector.
111 ; Always 64-bit in long mode, otherwise according to TMPL_BITS.
112 ;
113 mov ax, X86DESCGENERIC_BIT_OFF_TYPE + 1 ; For clearing the busy bit in the TSS descriptor type.
114 %if BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
115 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss64
116 TMPL_BEGIN_TEXT
117 btr [Bs3Gdte_Tss64 TMPL_WRT_SYSTEM16_OR_FLAT], ax
118 mov ax, BS3_SEL_TSS64
119
120 %elif BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
121 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16
122 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16DoubleFault
123 TMPL_BEGIN_TEXT
124 btr [Bs3Gdte_Tss16 TMPL_WRT_SYSTEM16_OR_FLAT], ax
125 btr [Bs3Gdte_Tss16DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ax
126 mov ax, BS3_SEL_TSS16
127
128 %elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
129 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss32
130 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss32DoubleFault
131 BS3_EXTERN_SYSTEM16 Bs3Tss32
132 BS3_EXTERN_SYSTEM16 Bs3Tss32DoubleFault
133 TMPL_BEGIN_TEXT
134 btr [Bs3Gdte_Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], ax
135 btr [Bs3Gdte_Tss32DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ax
136 mov eax, cr3
137 mov [X86TSS32.cr3 + Bs3Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], eax
138 mov [X86TSS32.cr3 + Bs3Tss32DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], eax
139 mov ax, BS3_SEL_TSS32
140 %else
141 %error "TMPL_BITS"
142 %endif
143 ltr ax
144%endif ; !TMPL_CMN_R86
145
146%if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
147 ;
148 ; Load the LDT.
149 ;
150 mov ax, BS3_SEL_LDT
151 lldt ax
152%endif
153
154 ;
155 ; Load ds and es.
156 ;
157%ifdef TMPL_CMN_V86
158 mov ax, BS3_SEL_DATA16
159%else
160 mov ax, RT_CONCAT(BS3_SEL_R0_DS,TMPL_BITS)
161%endif
162 mov ds, ax
163 mov es, ax
164
165%if TMPL_BITS == 16
166 ; For restoring after Bs3Trap* calls below.
167 push ax
168 push ax
169%endif
170
171 ;
172 ; Set global indicating CPU mode.
173 ;
174 mov byte [BS3_WRT_RIP(g_bBs3CurrentMode)], TMPL_MODE
175
176 ;
177 ; Install system call handler.
178 ; Always 64-bit in long mode, otherwise according to TMPL_BITS.
179 ;
180%if BS3_MODE_IS_RM_SYS(TMPL_MODE)
181 extern _Bs3TrapSystemCallHandler_rm
182 mov word [ss: BS3_TRAP_SYSCALL*4], _Bs3TrapSystemCallHandler_rm wrt BS3TEXT16
183 mov word [ss: BS3_TRAP_SYSCALL*4 + 2], BS3TEXT16
184
185%elif BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
186 BS3_EXTERN_CMN Bs3Trap16SetGate
187 extern TMPL_NM(Bs3TrapSystemCallHandler)
188 BS3_BEGIN_TEXT16
189 TMPL_BEGIN_TEXT
190 push 0 ; cParams
191 push TMPL_NM(Bs3TrapSystemCallHandler) wrt BS3TEXT16
192 push BS3_SEL_R0_CS16
193 push 3 ; DPL
194 push X86_SEL_TYPE_SYS_286_INT_GATE
195 push BS3_TRAP_SYSCALL
196 BS3_CALL Bs3Trap16SetGate,6
197 add xSP, xCB * 6
198
199%elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
200 BS3_EXTERN_CMN Bs3Trap32SetGate
201 extern TMPL_NM(Bs3TrapSystemCallHandler)
202 TMPL_BEGIN_TEXT
203 push 0 ; cParams
204 push dword TMPL_NM(Bs3TrapSystemCallHandler) wrt FLAT
205 push BS3_SEL_R0_CS32
206 push 3 ; DPL
207 push X86_SEL_TYPE_SYS_386_INT_GATE
208 push BS3_TRAP_SYSCALL
209 BS3_CALL Bs3Trap32SetGate,6
210 add xSP, xCB * 6
211
212%elif BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
213 BS3_EXTERN_CMN Bs3Trap64SetGate
214 extern Bs3TrapSystemCallHandler_lm64
215 TMPL_BEGIN_TEXT
216 push 0 ; bIst
217 %if BS3_MODE_IS_64BIT_CODE(TMPL_MODE)
218 push Bs3TrapSystemCallHandler_lm64 wrt FLAT
219 %else
220 push dword 0 ; upper offset
221 push dword Bs3TrapSystemCallHandler_lm64 wrt FLAT
222 %endif
223 push BS3_SEL_R0_CS64
224 push 3 ; DPL
225 push AMD64_SEL_TYPE_SYS_INT_GATE
226 push BS3_TRAP_SYSCALL
227 BS3_CALL Bs3Trap64SetGate,6
228 add xSP, xCB * 5 + 8
229%else
230 %error "TMPL_BITS"
231%endif
232
233%if TMPL_BITS == 16
234 ; Restoring ds and es after the above calls.
235 pop es
236 pop ds
237%endif
238
239 ;
240 ; Epilogue.
241 ;
242%if TMPL_BITS == 64
243 pop r9
244 pop r8
245 pop rdx
246 pop rcx
247%endif
248 pop xAX
249 leave
250 ret
251.dbg_str:
252 db 'CurrentMode=%#x', 0ah, 0
253BS3_PROC_END_MODE Bs3EnteredMode
254
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