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