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