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