]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.asm
This revision can only work with Intel(c) UDK Debugger Tool version 1.2 or greater...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / Ia32 / AsmFuncs.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php.
8 ;
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 ;
12 ; Module Name:
13 ;
14 ; AsmFuncs.asm
15 ;
16 ; Abstract:
17 ;
18 ; Debug interrupt handle functions.
19 ;
20 ;------------------------------------------------------------------------------
21
22 #include "DebugException.h"
23
24 .686p
25 .xmm
26 .model flat,c
27
28 ;
29 ; InterruptProcess()
30 ;
31 InterruptProcess PROTO C
32
33 public Exception0Handle, TimerInterruptHandle, ExceptionStubHeaderSize
34
35 .data
36
37 ExceptionStubHeaderSize DW Exception1Handle - Exception0Handle
38 CommonEntryAddr DD CommonEntry
39
40 .code
41
42 Exception0Handle:
43 cli
44 push eax
45 mov eax, 0
46 jmp dword ptr [CommonEntryAddr]
47 Exception1Handle:
48 cli
49 push eax
50 mov eax, 1
51 jmp dword ptr [CommonEntryAddr]
52 Exception2Handle:
53 cli
54 push eax
55 mov eax, 2
56 jmp dword ptr [CommonEntryAddr]
57 Exception3Handle:
58 cli
59 push eax
60 mov eax, 3
61 jmp dword ptr [CommonEntryAddr]
62 Exception4Handle:
63 cli
64 push eax
65 mov eax, 4
66 jmp dword ptr [CommonEntryAddr]
67 Exception5Handle:
68 cli
69 push eax
70 mov eax, 5
71 jmp dword ptr [CommonEntryAddr]
72 Exception6Handle:
73 cli
74 push eax
75 mov eax, 6
76 jmp dword ptr [CommonEntryAddr]
77 Exception7Handle:
78 cli
79 push eax
80 mov eax, 7
81 jmp dword ptr [CommonEntryAddr]
82 Exception8Handle:
83 cli
84 push eax
85 mov eax, 8
86 jmp dword ptr [CommonEntryAddr]
87 Exception9Handle:
88 cli
89 push eax
90 mov eax, 9
91 jmp dword ptr [CommonEntryAddr]
92 Exception10Handle:
93 cli
94 push eax
95 mov eax, 10
96 jmp dword ptr [CommonEntryAddr]
97 Exception11Handle:
98 cli
99 push eax
100 mov eax, 11
101 jmp dword ptr [CommonEntryAddr]
102 Exception12Handle:
103 cli
104 push eax
105 mov eax, 12
106 jmp dword ptr [CommonEntryAddr]
107 Exception13Handle:
108 cli
109 push eax
110 mov eax, 13
111 jmp dword ptr [CommonEntryAddr]
112 Exception14Handle:
113 cli
114 push eax
115 mov eax, 14
116 jmp dword ptr [CommonEntryAddr]
117 Exception15Handle:
118 cli
119 push eax
120 mov eax, 15
121 jmp dword ptr [CommonEntryAddr]
122 Exception16Handle:
123 cli
124 push eax
125 mov eax, 16
126 jmp dword ptr [CommonEntryAddr]
127 Exception17Handle:
128 cli
129 push eax
130 mov eax, 17
131 jmp dword ptr [CommonEntryAddr]
132 Exception18Handle:
133 cli
134 push eax
135 mov eax, 18
136 jmp dword ptr [CommonEntryAddr]
137 Exception19Handle:
138 cli
139 push eax
140 mov eax, 19
141 jmp dword ptr [CommonEntryAddr]
142
143 TimerInterruptHandle:
144 cli
145 push eax
146 mov eax, 32
147 jmp dword ptr [CommonEntryAddr]
148
149 CommonEntry:
150 ;
151 ; +---------------------+
152 ; + EFlags +
153 ; +---------------------+
154 ; + CS +
155 ; +---------------------+
156 ; + EIP +
157 ; +---------------------+
158 ; + Error Code +
159 ; +---------------------+
160 ; + EAX / Vector Number +
161 ; +---------------------+
162 ; + EBP +
163 ; +---------------------+ <-- EBP
164 ;
165 cmp eax, DEBUG_EXCEPT_DOUBLE_FAULT
166 je NoExtrPush
167 cmp eax, DEBUG_EXCEPT_INVALID_TSS
168 je NoExtrPush
169 cmp eax, DEBUG_EXCEPT_SEG_NOT_PRESENT
170 je NoExtrPush
171 cmp eax, DEBUG_EXCEPT_STACK_FAULT
172 je NoExtrPush
173 cmp eax, DEBUG_EXCEPT_GP_FAULT
174 je NoExtrPush
175 cmp eax, DEBUG_EXCEPT_PAGE_FAULT
176 je NoExtrPush
177 cmp eax, DEBUG_EXCEPT_ALIGNMENT_CHECK
178 je NoExtrPush
179
180 push [esp]
181 mov dword ptr [esp + 4], 0
182
183 NoExtrPush:
184
185 push ebp
186 mov ebp, esp ; save esp in ebp
187 ;
188 ; Make stack 16-byte alignment to make sure save fxrstor later
189 ;
190 and esp, 0fffffff0h
191 sub esp, 12
192
193 ; store UINT32 Edi, Esi, Ebp, Ebx, Edx, Ecx, Eax;
194 push dword ptr [ebp + 4] ; original eax
195 push ebx
196 push ecx
197 push edx
198 mov ebx, eax ; save vector in ebx
199 mov eax, ebp
200 add eax, 4 * 6
201 push eax ; original ESP
202 push dword ptr [ebp] ; EBP
203 push esi
204 push edi
205
206 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
207 ;; insure FXSAVE/FXRSTOR is enabled in CR4...
208 ;; ... while we're at it, make sure DE is also enabled...
209 mov eax, cr4
210 push eax ; push cr4 firstly
211 or eax, 208h
212 mov cr4, eax
213 mov eax, cr3
214 push eax
215 mov eax, cr2
216 push eax
217 push 0 ; cr0 will not saved???
218 mov eax, cr0
219 push eax
220
221 xor ecx, ecx
222 mov ecx, Ss
223 push ecx
224 mov ecx, Cs
225 push ecx
226 mov ecx, Ds
227 push ecx
228 mov ecx, Es
229 push ecx
230 mov ecx, Fs
231 push ecx
232 mov ecx, Gs
233 push ecx
234
235 ;; EIP
236 mov ecx, [ebp + 4 * 3] ; EIP
237 push ecx
238
239 ;; UINT32 Gdtr[2], Idtr[2];
240 sub esp, 8
241 sidt fword ptr [esp]
242 sub esp, 8
243 sgdt fword ptr [esp]
244
245 ;; UINT32 Ldtr, Tr;
246 xor eax, eax
247 str ax
248 push eax
249 sldt ax
250 push eax
251
252 ;; EFlags
253 mov ecx, [ebp + 4 * 5]
254 push ecx
255
256 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
257 mov eax, dr7
258 push eax
259
260 ;; clear Dr7 while executing debugger itself
261 xor eax, eax
262 ;; mov dr7, eax
263
264 ;; Dr6
265 mov eax, dr6
266 push eax
267
268 ;; insure all status bits in dr6 are clear...
269 xor eax, eax
270 mov dr6, eax
271
272 mov eax, dr3
273 push eax
274 mov eax, dr2
275 push eax
276 mov eax, dr1
277 push eax
278 mov eax, dr0
279 push eax
280
281 ;; FX_SAVE_STATE_IA32 FxSaveState;
282 sub esp, 512
283 mov edi, esp
284 db 0fh, 0aeh, 00000111y ;fxsave [edi]
285
286 ;; save the exception data
287 push dword ptr [ebp + 8]
288
289 ;; Clear Direction Flag
290 cld
291
292 ; call the C interrupt process function
293 push esp ; Structure
294 push ebx ; vector
295 call InterruptProcess
296 add esp, 8
297
298 ; skip the exception data
299 add esp, 4
300
301 ;; FX_SAVE_STATE_IA32 FxSaveState;
302 mov esi, esp
303 db 0fh, 0aeh, 00001110y ; fxrstor [esi]
304 add esp, 512
305
306 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
307 pop eax
308 mov dr0, eax
309 pop eax
310 mov dr1, eax
311 pop eax
312 mov dr2, eax
313 pop eax
314 mov dr3, eax
315 ;; skip restore of dr6. We cleared dr6 during the context save.
316 add esp, 4
317 pop eax
318 mov dr7, eax
319
320 ;; set EFlags
321 pop dword ptr [ebp + 4 * 5] ; set EFLAGS in stack
322
323 ;; UINT32 Ldtr, Tr;
324 ;; UINT32 Gdtr[2], Idtr[2];
325 ;; Best not let anyone mess with these particular registers...
326 add esp, 24
327
328 ;; UINT32 Eip;
329 pop dword ptr [ebp + 4 * 3] ; set EIP in stack
330
331 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
332 ;; NOTE - modified segment registers could hang the debugger... We
333 ;; could attempt to insulate ourselves against this possibility,
334 ;; but that poses risks as well.
335 ;;
336 pop gs
337 pop fs
338 pop es
339 pop ds
340 pop dword ptr [ebp + 4 * 4] ; set CS in stack
341 pop ss
342
343 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
344 pop eax
345 mov cr0, eax
346 add esp, 4 ; skip for Cr1
347 pop eax
348 mov cr2, eax
349 pop eax
350 mov cr3, eax
351 pop eax
352 mov cr4, eax
353
354 ;; restore general register
355 pop edi
356 pop esi
357 pop dword ptr [ebp] ; save updated ebp
358 pop dword ptr [ebp + 4] ; save updated esp
359 pop edx
360 pop ecx
361 pop ebx
362 pop eax
363
364 mov esp, ebp
365 pop ebp ; restore ebp maybe updated
366 pop esp ; restore esp maybe updated
367 sub esp, 4 * 3 ; restore interupt pushced stack
368
369 iretd
370
371 END