VirtualBox

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

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

bs3kit: More IDT handling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1; $Id: bs3-mode-EnteredMode.asm 59260 2016-01-06 03:05:21Z 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;
37BS3_PROC_BEGIN_MODE Bs3EnteredMode
38 push xBP
39 mov xBP, xSP
40 push xAX
41
42 ;
43 ; Load selectors, IDTs and stuff as appropriate.
44 ;
45%ifdef TMPL_CMN_R86
46BS3_BEGIN_DATA16
47TMPL_BEGIN_TEXT
48extern TMPL_NM(Bs3TrapSystemCallHandler)
49 xor ax, ax
50 mov ss, ax
51 mov ax, BS3DATA16
52 mov ds, ax
53 mov es, ax
54
55 mov word [ss: BS3_TRAP_SYSCALL*4], TMPL_NM(Bs3TrapSystemCallHandler) wrt BS3TEXT16
56 mov word [ss: BS3_TRAP_SYSCALL*4 + 2], BS3TEXT16
57
58%elif TMPL_BITS == 16
59BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt16
60BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16
61BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16DoubleFault
62TMPL_BEGIN_TEXT
63 jmp BS3_SEL_R0_CS16:.reloaded_cs
64.reloaded_cs:
65
66 mov ax, BS3_SEL_R0_SS16
67 mov ss, ax
68
69 mov ax, BS3_SEL_SYSTEM16
70 mov ds, ax
71 lidt [Bs3Lidt_Idt16]
72
73 mov ax, X86DESCGENERIC_BIT_OFF_TYPE + 1
74 btr [Bs3Gdte_Tss16DoubleFault], ax ; mark it not busy
75 btr [Bs3Gdte_Tss16], ax ; mark it not busy
76 mov ax, BS3_SEL_TSS16
77 ltr ax
78
79 mov ax, BS3_SEL_LDT
80 lldt ax
81
82 mov ax, BS3_SEL_R0_DS16
83 mov ds, ax
84 mov es, ax
85
86 %ifndef TMPL_CMN_LM
87; BS3_EXTERN_CMN Bs3Trap32SetGate
88; extern TMPL_NM(Bs3TrapSystemCallHandler)
89; push 0 ; cParams
90; push TMPL_NM(Bs3TrapSystemCallHandler) wrt BS3TEXT16
91; push BS3_SEL_R0_CS16
92; push 3 ; DPL
93; push X86_SEL_TYPE_SYS_286_INT_GATE
94; push BS3_TRAP_SYSCALL
95; BS3_CALL Bs3Trap16SetGate,6
96; add sp, xCB * 6
97 %endif
98
99%elif TMPL_BITS == 32
100BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt32
101BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss32
102BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss32DoubleFault
103TMPL_BEGIN_TEXT
104 mov ax, BS3_SEL_R0_SS32
105 mov ss, ax
106
107 mov ax, BS3_SEL_SYSTEM16
108 mov ds, ax
109 lidt [Bs3Lidt_Idt32]
110
111 mov ax, X86DESCGENERIC_BIT_OFF_TYPE + 1
112 btr [Bs3Gdte_Tss32DoubleFault], ax ; mark it not busy
113 btr [Bs3Gdte_Tss32], ax ; mark it not busy
114 mov ax, BS3_SEL_TSS32
115 ltr ax
116
117 mov ax, BS3_SEL_LDT
118 lldt ax
119
120 mov ax, BS3_SEL_R0_DS32
121 mov ds, ax
122 mov es, ax
123
124 %ifndef TMPL_CMN_LM
125 BS3_EXTERN_CMN Bs3Trap32SetGate
126 extern TMPL_NM(Bs3TrapSystemCallHandler)
127 push 0 ; cParams
128 push TMPL_NM(Bs3TrapSystemCallHandler) wrt FLAT
129 push BS3_SEL_R0_CS32
130 push 3 ; DPL
131 push X86_SEL_TYPE_SYS_386_INT_GATE
132 push BS3_TRAP_SYSCALL
133 BS3_CALL Bs3Trap32SetGate,6
134 add esp, xCB * 6
135 %endif
136
137%elif TMPL_BITS == 64
138BS3_EXTERN_SYSTEM16 Bs3Lidt_Idt64
139BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss64
140TMPL_BEGIN_TEXT
141 mov ax, BS3_SEL_R0_DS64
142 mov ss, ax
143
144 mov ax, BS3_SEL_SYSTEM16
145 mov ds, ax
146 lidt [Bs3Lidt_Idt64]
147
148 mov eax, X86DESCGENERIC_BIT_OFF_TYPE + 1
149 btr [Bs3Gdte_Tss64], eax ; mark it not busy
150 mov ax, BS3_SEL_TSS64
151 ltr ax
152
153 mov ax, BS3_SEL_LDT
154 lldt ax
155
156 mov ax, BS3_SEL_R0_DS64
157 mov ds, ax
158 mov es, ax
159
160%else
161 %error "TMPL_BITS"
162%endif
163
164 %ifdef TMPL_CMN_LM
165 ;
166 ; In long mode we always use a 64-bit TSS and a IDT with all 64-bit gates.
167 ;
168 %if TMPL_BITS == 64
169 push rcx
170 push rdx
171 push r8
172 push r9
173 %endif
174
175 BS3_EXTERN_CMN Bs3Trap64SetGate
176 extern Bs3TrapSystemCallHandler_lm64
177 push 0 ; bIst
178 %ifdef TMPL_64BIT
179 push Bs3TrapSystemCallHandler_lm64 wrt FLAT
180 %else
181 push dword 0 ; upper offset
182 push dword Bs3TrapSystemCallHandler_lm64 wrt FLAT
183 %endif
184 push BS3_SEL_R0_CS64
185 push 3 ; DPL
186 push AMD64_SEL_TYPE_SYS_INT_GATE
187 push BS3_TRAP_SYSCALL
188 BS3_CALL Bs3Trap64SetGate,6
189 add xSP, xCB * 5 + 8
190
191 %if TMPL_BITS == 64
192 pop r9
193 pop r8
194 pop rdx
195 pop rcx
196 %endif
197 %endif
198
199 pop xAX
200 leave
201 ret
202BS3_PROC_END_MODE Bs3EnteredMode
203
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