1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2010 - 2015, 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.
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.
18 ; Debug interrupt handle functions.
20 ;------------------------------------------------------------------------------
22 #include "DebugException.h"
31 InterruptProcess PROTO C
33 public Exception0Handle, TimerInterruptHandle, ExceptionStubHeaderSize
35 AGENT_HANDLER_SIGNATURE MACRO
36 db 41h, 47h, 54h, 48h ; SIGNATURE_32('A','G','T','H')
41 ExceptionStubHeaderSize DD Exception1Handle - Exception0Handle
42 CommonEntryAddr DD CommonEntry
46 AGENT_HANDLER_SIGNATURE
51 jmp dword ptr [CommonEntryAddr]
52 AGENT_HANDLER_SIGNATURE
57 jmp dword ptr [CommonEntryAddr]
58 AGENT_HANDLER_SIGNATURE
63 jmp dword ptr [CommonEntryAddr]
64 AGENT_HANDLER_SIGNATURE
69 jmp dword ptr [CommonEntryAddr]
70 AGENT_HANDLER_SIGNATURE
75 jmp dword ptr [CommonEntryAddr]
76 AGENT_HANDLER_SIGNATURE
81 jmp dword ptr [CommonEntryAddr]
82 AGENT_HANDLER_SIGNATURE
87 jmp dword ptr [CommonEntryAddr]
88 AGENT_HANDLER_SIGNATURE
93 jmp dword ptr [CommonEntryAddr]
94 AGENT_HANDLER_SIGNATURE
99 jmp dword ptr [CommonEntryAddr]
100 AGENT_HANDLER_SIGNATURE
105 jmp dword ptr [CommonEntryAddr]
106 AGENT_HANDLER_SIGNATURE
111 jmp dword ptr [CommonEntryAddr]
112 AGENT_HANDLER_SIGNATURE
117 jmp dword ptr [CommonEntryAddr]
118 AGENT_HANDLER_SIGNATURE
123 jmp dword ptr [CommonEntryAddr]
124 AGENT_HANDLER_SIGNATURE
129 jmp dword ptr [CommonEntryAddr]
130 AGENT_HANDLER_SIGNATURE
135 jmp dword ptr [CommonEntryAddr]
136 AGENT_HANDLER_SIGNATURE
141 jmp dword ptr [CommonEntryAddr]
142 AGENT_HANDLER_SIGNATURE
147 jmp dword ptr [CommonEntryAddr]
148 AGENT_HANDLER_SIGNATURE
153 jmp dword ptr [CommonEntryAddr]
154 AGENT_HANDLER_SIGNATURE
159 jmp dword ptr [CommonEntryAddr]
160 AGENT_HANDLER_SIGNATURE
165 jmp dword ptr [CommonEntryAddr]
166 AGENT_HANDLER_SIGNATURE
167 TimerInterruptHandle:
171 jmp dword ptr [CommonEntryAddr]
175 ; +---------------------+
177 ; +---------------------+
179 ; +---------------------+
181 ; +---------------------+
183 ; +---------------------+
184 ; + EAX / Vector Number +
185 ; +---------------------+
187 ; +---------------------+ <-- EBP
189 cmp eax, DEBUG_EXCEPT_DOUBLE_FAULT
191 cmp eax, DEBUG_EXCEPT_INVALID_TSS
193 cmp eax, DEBUG_EXCEPT_SEG_NOT_PRESENT
195 cmp eax, DEBUG_EXCEPT_STACK_FAULT
197 cmp eax, DEBUG_EXCEPT_GP_FAULT
199 cmp eax, DEBUG_EXCEPT_PAGE_FAULT
201 cmp eax, DEBUG_EXCEPT_ALIGNMENT_CHECK
205 mov dword ptr [esp + 4], 0
210 mov ebp, esp ; save esp in ebp
212 ; Make stack 16-byte alignment to make sure save fxrstor later
217 ; store UINT32 Edi, Esi, Ebp, Ebx, Edx, Ecx, Eax;
218 push dword ptr [ebp + 4] ; original eax
222 mov ebx, eax ; save vector in ebx
225 push eax ; original ESP
226 push dword ptr [ebp] ; EBP
230 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
231 ;; insure FXSAVE/FXRSTOR is enabled in CR4...
232 ;; ... while we're at it, make sure DE is also enabled...
234 push ebx ; temporarily save value of ebx on stack
235 cpuid ; use CPUID to determine if FXSAVE/FXRESTOR and
237 pop ebx ; retore value of ebx that was overwritten by CPUID
239 push eax ; push cr4 firstly
240 test edx, BIT24 ; Test for FXSAVE/FXRESTOR support
242 or eax, BIT9 ; Set CR4.OSFXSR
244 test edx, BIT2 ; Test for Debugging Extensions support
246 or eax, BIT3 ; Set CR4.DE
253 push 0 ; cr0 will not saved???
272 mov ecx, [ebp + 4 * 3] ; EIP
275 ;; UINT32 Gdtr[2], Idtr[2];
289 mov ecx, [ebp + 4 * 5]
292 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
296 ;; clear Dr7 while executing debugger itself
304 ;; insure all status bits in dr6 are clear...
317 ;; Clear Direction Flag
320 ;; FX_SAVE_STATE_IA32 FxSaveState;
325 mov ecx, 128 ;= 512 / 4
329 test edx, BIT24 ; Test for FXSAVE/FXRESTOR support.
330 ; edx still contains result from CPUID above
332 db 0fh, 0aeh, 00000111y ;fxsave [edi]
335 ;; save the exception data
336 push dword ptr [ebp + 8]
338 ; call the C interrupt process function
341 call InterruptProcess
344 ; skip the exception data
347 ;; FX_SAVE_STATE_IA32 FxSaveState;
350 cpuid ; use CPUID to determine if FXSAVE/FXRESTOR are supported
351 test edx, BIT24 ; Test for FXSAVE/FXRESTOR support
353 db 0fh, 0aeh, 00001110y ; fxrstor [esi]
357 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
366 ;; skip restore of dr6. We cleared dr6 during the context save.
372 pop dword ptr [ebp + 4 * 5] ; set EFLAGS in stack
375 ;; UINT32 Gdtr[2], Idtr[2];
376 ;; Best not let anyone mess with these particular registers...
380 pop dword ptr [ebp + 4 * 3] ; set EIP in stack
382 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
383 ;; NOTE - modified segment registers could hang the debugger... We
384 ;; could attempt to insulate ourselves against this possibility,
385 ;; but that poses risks as well.
391 pop dword ptr [ebp + 4 * 4] ; set CS in stack
394 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
397 add esp, 4 ; skip for Cr1
405 ;; restore general register
408 pop dword ptr [ebp] ; save updated ebp
409 pop dword ptr [ebp + 4] ; save updated esp
416 pop ebp ; restore ebp maybe updated
417 pop esp ; restore esp maybe updated
418 sub esp, 4 * 3 ; restore interupt pushced stack