1 | ; $Id: bs3-mode-EnteredMode.asm 59287 2016-01-08 10:08:40Z 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 |
|
---|
29 |
|
---|
30 | ;;
|
---|
31 | ; @cproto BS3_DECL(void) Bs3EnteredMode(void);
|
---|
32 | ;
|
---|
33 | ; @uses Nothing.
|
---|
34 | ;
|
---|
35 | ; @remarks ASSUMES we're in ring-0 when not in some kind of real mode.
|
---|
36 | ;
|
---|
37 | BS3_PROC_BEGIN_MODE Bs3EnteredMode
|
---|
38 | push xBP
|
---|
39 | mov xBP, xSP
|
---|
40 | push xAX
|
---|
41 | %if TMPL_BITS == 64
|
---|
42 | push rcx
|
---|
43 | push rdx
|
---|
44 | push r8
|
---|
45 | push r9
|
---|
46 | %endif
|
---|
47 |
|
---|
48 | ;
|
---|
49 | ; Load stack selector (not always necessary) and sometimes CS too.
|
---|
50 | ;
|
---|
51 | %ifdef TMPL_RM
|
---|
52 | xor ax, ax
|
---|
53 | %elifdef TMPL_CMN_V86
|
---|
54 | extern v86_versions_of_Bs3EnteredMode_should_not_be_dragged_into_the_link
|
---|
55 | call v86_versions_of_Bs3EnteredMode_should_not_be_dragged_into_the_link
|
---|
56 | %elif TMPL_BITS == 16
|
---|
57 | jmp BS3_SEL_R0_CS16:.reloaded_cs
|
---|
58 | .reloaded_cs:
|
---|
59 | mov ax, BS3_SEL_R0_SS16
|
---|
60 | %elif TMPL_BITS == 32
|
---|
61 | mov ax, BS3_SEL_R0_SS32
|
---|
62 | %elif TMPL_BITS == 64
|
---|
63 | mov ax, BS3_SEL_R0_DS64
|
---|
64 | %else
|
---|
65 | %error "TMPL_BITS"
|
---|
66 | %endif
|
---|
67 | mov ss, ax
|
---|
68 |
|
---|
69 | ;
|
---|
70 | ; Load selector appropriate for accessing BS3SYSTEM16 data.
|
---|
71 | ;
|
---|
72 | %if TMPL_BITS == 16
|
---|
73 | mov ax, BS3_SEL_SYSTEM16
|
---|
74 | %else
|
---|
75 | mov ax, RT_CONCAT(BS3_SEL_R0_DS,TMPL_BITS)
|
---|
76 | %endif
|
---|
77 | mov ds, ax
|
---|
78 |
|
---|
79 | ;
|
---|
80 | ; Load the appropritate IDT or IVT.
|
---|
81 | ; Always 64-bit in long mode, otherwise according to TMPL_BITS.
|
---|
82 | ;
|
---|
83 | %ifdef TMPL_CMN_R86
|
---|
84 | BS3_EXTERN_SYSTEM16 Bs3Lidt_Ivt
|
---|
85 | TMPL_BEGIN_TEXT
|
---|
86 | lidt [Bs3Lidt_Ivt]
|
---|
87 | %elifdef TMPL_CMN_LM
|
---|
88 | BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt64
|
---|
89 | TMPL_BEGIN_TEXT
|
---|
90 | lidt [Bs3Lidt_Idt64 TMPL_WRT_SYSTEM16_OR_FLAT]
|
---|
91 | %else
|
---|
92 | BS3_EXTERN_SYSTEM16 RT_CONCAT(Bs3Lidt_Idt,TMPL_BITS)
|
---|
93 | TMPL_BEGIN_TEXT
|
---|
94 | lidt [RT_CONCAT(Bs3Lidt_Idt,TMPL_BITS) TMPL_WRT_SYSTEM16_OR_FLAT]
|
---|
95 | %endif
|
---|
96 |
|
---|
97 | %ifndef TMPL_CMN_R86
|
---|
98 | ;
|
---|
99 | ; Load the appropriate task selector.
|
---|
100 | ; Always 64-bit in long mode, otherwise according to TMPL_BITS.
|
---|
101 | ;
|
---|
102 | mov ax, X86DESCGENERIC_BIT_OFF_TYPE + 1 ; For clearing the busy bit in the TSS descriptor type.
|
---|
103 | %ifdef TMPL_CMN_LM
|
---|
104 | BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss64
|
---|
105 | TMPL_BEGIN_TEXT
|
---|
106 | btr [Bs3Gdte_Tss64 TMPL_WRT_SYSTEM16_OR_FLAT], ax
|
---|
107 | mov ax, BS3_SEL_TSS64
|
---|
108 |
|
---|
109 | %elif TMPL_BITS == 16
|
---|
110 | BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16
|
---|
111 | BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16DoubleFault
|
---|
112 | TMPL_BEGIN_TEXT
|
---|
113 | btr [Bs3Gdte_Tss16 TMPL_WRT_SYSTEM16_OR_FLAT], ax
|
---|
114 | btr [Bs3Gdte_Tss16DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ax
|
---|
115 | mov ax, BS3_SEL_TSS16
|
---|
116 |
|
---|
117 | %elif TMPL_BITS == 32
|
---|
118 | BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss32
|
---|
119 | BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss32DoubleFault
|
---|
120 | BS3_EXTERN_SYSTEM16 Bs3Tss32
|
---|
121 | BS3_EXTERN_SYSTEM16 Bs3Tss32DoubleFault
|
---|
122 | TMPL_BEGIN_TEXT
|
---|
123 | btr [Bs3Gdte_Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], ax
|
---|
124 | btr [Bs3Gdte_Tss32DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ax
|
---|
125 | mov eax, cr3
|
---|
126 | mov [X86TSS32.cr3 + Bs3Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], eax
|
---|
127 | mov [X86TSS32.cr3 + Bs3Tss32DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], eax
|
---|
128 | mov ax, BS3_SEL_TSS32
|
---|
129 | %else
|
---|
130 | %error "TMPL_BITS"
|
---|
131 | %endif
|
---|
132 | ltr ax
|
---|
133 | %endif ; !TMPL_CMN_R86
|
---|
134 |
|
---|
135 | %ifndef TMPL_CMN_R86
|
---|
136 | ;
|
---|
137 | ; Load the LDT.
|
---|
138 | ;
|
---|
139 | mov ax, BS3_SEL_LDT
|
---|
140 | lldt ax
|
---|
141 | %endif
|
---|
142 |
|
---|
143 | ;
|
---|
144 | ; Load ds and es.
|
---|
145 | ;
|
---|
146 | %ifdef TMPL_CMN_V86
|
---|
147 | mov ax, BS3_SEL_DATA16
|
---|
148 | %else
|
---|
149 | mov ax, RT_CONCAT(BS3_SEL_R0_DS,TMPL_BITS)
|
---|
150 | %endif
|
---|
151 | mov ds, ax
|
---|
152 | mov es, ax
|
---|
153 |
|
---|
154 | ;
|
---|
155 | ; Install system call handler.
|
---|
156 | ; Always 64-bit in long mode, otherwise according to TMPL_BITS.
|
---|
157 | ;
|
---|
158 | %ifdef TMPL_CMN_RM
|
---|
159 | mov word [ss: BS3_TRAP_SYSCALL*4], TMPL_NM(Bs3TrapSystemCallHandler) wrt BS3TEXT16
|
---|
160 | mov word [ss: BS3_TRAP_SYSCALL*4 + 2], BS3TEXT16
|
---|
161 | %elifdef TMPL_CMN_LM
|
---|
162 | BS3_EXTERN_CMN Bs3Trap64SetGate
|
---|
163 | extern Bs3TrapSystemCallHandler_lm64
|
---|
164 | TMPL_BEGIN_TEXT
|
---|
165 | push 0 ; bIst
|
---|
166 | %ifdef TMPL_64BIT
|
---|
167 | push Bs3TrapSystemCallHandler_lm64 wrt FLAT
|
---|
168 | %else
|
---|
169 | push dword 0 ; upper offset
|
---|
170 | push dword Bs3TrapSystemCallHandler_lm64 wrt FLAT
|
---|
171 | %endif
|
---|
172 | push BS3_SEL_R0_CS64
|
---|
173 | push 3 ; DPL
|
---|
174 | push AMD64_SEL_TYPE_SYS_INT_GATE
|
---|
175 | push BS3_TRAP_SYSCALL
|
---|
176 | BS3_CALL Bs3Trap64SetGate,6
|
---|
177 | add xSP, xCB * 5 + 8
|
---|
178 |
|
---|
179 | %elif TMPL_BITS == 16
|
---|
180 | BS3_EXTERN_CMN Bs3Trap16SetGate
|
---|
181 | extern TMPL_NM(Bs3TrapSystemCallHandler)
|
---|
182 | TMPL_BEGIN_TEXT
|
---|
183 | push 0 ; cParams
|
---|
184 | push TMPL_NM(Bs3TrapSystemCallHandler) wrt BS3TEXT16
|
---|
185 | push BS3_SEL_R0_CS16
|
---|
186 | push 3 ; DPL
|
---|
187 | push X86_SEL_TYPE_SYS_286_INT_GATE
|
---|
188 | push BS3_TRAP_SYSCALL
|
---|
189 | BS3_CALL Bs3Trap16SetGate,6
|
---|
190 | add xSP, xCB * 6
|
---|
191 |
|
---|
192 | %elif TMPL_BITS == 32
|
---|
193 | BS3_EXTERN_CMN Bs3Trap32SetGate
|
---|
194 | extern TMPL_NM(Bs3TrapSystemCallHandler)
|
---|
195 | TMPL_BEGIN_TEXT
|
---|
196 | push 0 ; cParams
|
---|
197 | push TMPL_NM(Bs3TrapSystemCallHandler) wrt FLAT
|
---|
198 | push BS3_SEL_R0_CS32
|
---|
199 | push 3 ; DPL
|
---|
200 | push X86_SEL_TYPE_SYS_386_INT_GATE
|
---|
201 | push BS3_TRAP_SYSCALL
|
---|
202 | BS3_CALL Bs3Trap32SetGate,6
|
---|
203 | add xSP, xCB * 6
|
---|
204 | %else
|
---|
205 | %error "TMPL_BITS"
|
---|
206 | %endif
|
---|
207 |
|
---|
208 | ;
|
---|
209 | ; Epilogue.
|
---|
210 | ;
|
---|
211 | %if TMPL_BITS == 64
|
---|
212 | pop r9
|
---|
213 | pop r8
|
---|
214 | pop rdx
|
---|
215 | pop rcx
|
---|
216 | %endif
|
---|
217 | pop xAX
|
---|
218 | leave
|
---|
219 | ret
|
---|
220 | BS3_PROC_END_MODE Bs3EnteredMode
|
---|
221 |
|
---|