1 | ; $Id: bs3-c32-Trap32ResumeFrame.asm 59286 2016-01-08 00:23:32Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Trap, 32-bit resume.
|
---|
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 | %ifndef TMPL_32BIT
|
---|
30 | %error "32-bit only template, at the moment"
|
---|
31 | %endif
|
---|
32 |
|
---|
33 |
|
---|
34 | ;;
|
---|
35 | ; @cproto BS3_DECL(void) Bs3Trap32ResumeFrame(BS3TRAPFRAME BS3_FAR *pTrapFrame, uint16_t fFlags)
|
---|
36 | BS3_PROC_BEGIN_CMN Bs3Trap32ResumeFrame
|
---|
37 | push xBP
|
---|
38 | mov xBP, xSP
|
---|
39 |
|
---|
40 | mov ebx, [xBP + 8] ; pTrapFrame
|
---|
41 |
|
---|
42 | ;
|
---|
43 | ; Restore control registers if they've changed.
|
---|
44 | ;
|
---|
45 | test word [xBP + 12], BS3TRAPRESUME_F_SKIP_CRX
|
---|
46 | jnz .skip_control_regs
|
---|
47 |
|
---|
48 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4]
|
---|
49 | mov edx, cr4
|
---|
50 | cmp eax, edx
|
---|
51 | je .skip_cr4
|
---|
52 | mov cr4, eax
|
---|
53 | .skip_cr4:
|
---|
54 |
|
---|
55 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3]
|
---|
56 | mov edx, cr3
|
---|
57 | cmp eax, edx
|
---|
58 | je .skip_cr3
|
---|
59 | mov cr3, eax
|
---|
60 | .skip_cr3:
|
---|
61 |
|
---|
62 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2]
|
---|
63 | mov edx, cr2
|
---|
64 | cmp eax, edx
|
---|
65 | je .skip_cr2
|
---|
66 | mov cr2, eax
|
---|
67 | .skip_cr2:
|
---|
68 |
|
---|
69 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0]
|
---|
70 | mov edx, cr0
|
---|
71 | cmp eax, edx
|
---|
72 | je .skip_cr0
|
---|
73 | mov cr0, eax
|
---|
74 | .skip_cr0:
|
---|
75 |
|
---|
76 | ; LDTR
|
---|
77 | sldt ax
|
---|
78 | cmp ax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr]
|
---|
79 | je .skip_ldtr
|
---|
80 | lldt [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr]
|
---|
81 | .skip_ldtr:
|
---|
82 |
|
---|
83 | ; TR - complicated because we need to clear the busy bit. ASSUMES GDT.
|
---|
84 | str ax
|
---|
85 | cmp ax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.tr]
|
---|
86 | je .skip_tr
|
---|
87 |
|
---|
88 | movzx eax, word [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.tr]
|
---|
89 | or eax, eax ; check for null.
|
---|
90 | jz .load_tr
|
---|
91 |
|
---|
92 | sub esp, 10h
|
---|
93 | mov dword [esp + 8], 0 ; paranoia^2
|
---|
94 | sgdt [esp + 6]
|
---|
95 | add eax, [esp + 8] ; the limit.
|
---|
96 | add esp, 10h
|
---|
97 |
|
---|
98 | add eax, X86DESCGENERIC_BIT_OFF_TYPE / 8
|
---|
99 | and byte [eax], ~(X86_SEL_TYPE_SYS_TSS_BUSY_MASK << (X86DESCGENERIC_BIT_OFF_TYPE % 8))
|
---|
100 | .load_tr:
|
---|
101 | ltr [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.tr]
|
---|
102 | .skip_tr:
|
---|
103 |
|
---|
104 | .skip_control_regs:
|
---|
105 |
|
---|
106 | ;
|
---|
107 | ; Branch into iret frame specific code.
|
---|
108 | ;
|
---|
109 | test dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], X86_EFL_VM
|
---|
110 | jnz .iret_v8086
|
---|
111 | mov ax, ss
|
---|
112 | mov dx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss]
|
---|
113 | and ax, 3
|
---|
114 | and dx, 3
|
---|
115 | cmp ax, dx
|
---|
116 | cli
|
---|
117 | jne .iret_other_cpl
|
---|
118 |
|
---|
119 | ;
|
---|
120 | ; IRET to same CPL. ASSUMES that we can stash an IRET frame and EBP at ESP.
|
---|
121 | ;
|
---|
122 | mov ebp, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp]
|
---|
123 | sub ebp, 16 ; IRET + EBP
|
---|
124 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags]
|
---|
125 | mov [ebp + 12], eax
|
---|
126 | movzx eax, word [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cs]
|
---|
127 | mov [ebp + 8], eax
|
---|
128 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rip]
|
---|
129 | mov [ebp + 4], eax
|
---|
130 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp]
|
---|
131 | mov [ebp], eax
|
---|
132 |
|
---|
133 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax]
|
---|
134 | mov ecx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx]
|
---|
135 | mov edx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx]
|
---|
136 | mov esi, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi]
|
---|
137 | mov edi, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi]
|
---|
138 |
|
---|
139 | mov gs, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.gs]
|
---|
140 | mov fs, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.fs]
|
---|
141 | mov es, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.es]
|
---|
142 | mov ss, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss]
|
---|
143 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ds]
|
---|
144 | mov ebx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx]
|
---|
145 | pop ds
|
---|
146 | leave
|
---|
147 | iretd
|
---|
148 |
|
---|
149 | ;
|
---|
150 | ; IRET to other CPL.
|
---|
151 | ;
|
---|
152 | .iret_other_cpl:
|
---|
153 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss]
|
---|
154 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp]
|
---|
155 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags]
|
---|
156 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cs]
|
---|
157 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rip]
|
---|
158 |
|
---|
159 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax]
|
---|
160 | mov ecx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx]
|
---|
161 | mov edx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx]
|
---|
162 | mov esi, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi]
|
---|
163 | mov edi, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi]
|
---|
164 |
|
---|
165 | mov gs, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.gs]
|
---|
166 | mov fs, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.fs]
|
---|
167 | mov es, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.es]
|
---|
168 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp]
|
---|
169 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ds]
|
---|
170 | mov ebx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx]
|
---|
171 | pop ds
|
---|
172 | pop ebp
|
---|
173 | iretd
|
---|
174 |
|
---|
175 | ;
|
---|
176 | ; IRET to virtual 8086 mode.
|
---|
177 | ;
|
---|
178 | .iret_v8086:
|
---|
179 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.gs]
|
---|
180 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.fs]
|
---|
181 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ds]
|
---|
182 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.es]
|
---|
183 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss]
|
---|
184 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp]
|
---|
185 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags]
|
---|
186 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.cs]
|
---|
187 | push dword [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rip]
|
---|
188 |
|
---|
189 | mov eax, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax]
|
---|
190 | mov ecx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx]
|
---|
191 | mov edx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx]
|
---|
192 | mov esi, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi]
|
---|
193 | mov edi, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi]
|
---|
194 | mov ebp, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp]
|
---|
195 | mov ebx, [ebx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx]
|
---|
196 | iretd
|
---|
197 |
|
---|
198 | BS3_PROC_END_CMN Bs3Trap32ResumeFrame
|
---|
199 |
|
---|