1 ;------------------------------------------------------------------------------
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.
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
37 ExceptionStubHeaderSize DW Exception1Handle - Exception0Handle
38 CommonEntryAddr DD CommonEntry
42 db 41h, 47h, 54h, 48h ; AGENT_HANDLER_SIGNATURE SIGNATURE_32('A','G','T','H')
47 jmp dword ptr [CommonEntryAddr]
52 jmp dword ptr [CommonEntryAddr]
57 jmp dword ptr [CommonEntryAddr]
62 jmp dword ptr [CommonEntryAddr]
67 jmp dword ptr [CommonEntryAddr]
72 jmp dword ptr [CommonEntryAddr]
77 jmp dword ptr [CommonEntryAddr]
82 jmp dword ptr [CommonEntryAddr]
87 jmp dword ptr [CommonEntryAddr]
92 jmp dword ptr [CommonEntryAddr]
97 jmp dword ptr [CommonEntryAddr]
102 jmp dword ptr [CommonEntryAddr]
107 jmp dword ptr [CommonEntryAddr]
112 jmp dword ptr [CommonEntryAddr]
117 jmp dword ptr [CommonEntryAddr]
122 jmp dword ptr [CommonEntryAddr]
127 jmp dword ptr [CommonEntryAddr]
132 jmp dword ptr [CommonEntryAddr]
137 jmp dword ptr [CommonEntryAddr]
142 jmp dword ptr [CommonEntryAddr]
144 TimerInterruptHandle:
148 jmp dword ptr [CommonEntryAddr]
152 ; +---------------------+
154 ; +---------------------+
156 ; +---------------------+
158 ; +---------------------+
160 ; +---------------------+
161 ; + EAX / Vector Number +
162 ; +---------------------+
164 ; +---------------------+ <-- EBP
166 cmp eax, DEBUG_EXCEPT_DOUBLE_FAULT
168 cmp eax, DEBUG_EXCEPT_INVALID_TSS
170 cmp eax, DEBUG_EXCEPT_SEG_NOT_PRESENT
172 cmp eax, DEBUG_EXCEPT_STACK_FAULT
174 cmp eax, DEBUG_EXCEPT_GP_FAULT
176 cmp eax, DEBUG_EXCEPT_PAGE_FAULT
178 cmp eax, DEBUG_EXCEPT_ALIGNMENT_CHECK
182 mov dword ptr [esp + 4], 0
187 mov ebp, esp ; save esp in ebp
189 ; Make stack 16-byte alignment to make sure save fxrstor later
194 ; store UINT32 Edi, Esi, Ebp, Ebx, Edx, Ecx, Eax;
195 push dword ptr [ebp + 4] ; original eax
199 mov ebx, eax ; save vector in ebx
202 push eax ; original ESP
203 push dword ptr [ebp] ; EBP
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...
211 push eax ; push cr4 firstly
218 push 0 ; cr0 will not saved???
237 mov ecx, [ebp + 4 * 3] ; EIP
240 ;; UINT32 Gdtr[2], Idtr[2];
254 mov ecx, [ebp + 4 * 5]
257 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
261 ;; clear Dr7 while executing debugger itself
269 ;; insure all status bits in dr6 are clear...
282 ;; FX_SAVE_STATE_IA32 FxSaveState;
285 db 0fh, 0aeh, 00000111y ;fxsave [edi]
287 ;; save the exception data
288 push dword ptr [ebp + 8]
290 ;; Clear Direction Flag
293 ; call the C interrupt process function
296 call InterruptProcess
299 ; skip the exception data
302 ;; FX_SAVE_STATE_IA32 FxSaveState;
304 db 0fh, 0aeh, 00001110y ; fxrstor [esi]
307 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
316 ;; skip restore of dr6. We cleared dr6 during the context save.
322 pop dword ptr [ebp + 4 * 5] ; set EFLAGS in stack
325 ;; UINT32 Gdtr[2], Idtr[2];
326 ;; Best not let anyone mess with these particular registers...
330 pop dword ptr [ebp + 4 * 3] ; set EIP in stack
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.
341 pop dword ptr [ebp + 4 * 4] ; set CS in stack
344 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
347 add esp, 4 ; skip for Cr1
355 ;; restore general register
358 pop dword ptr [ebp] ; save updated ebp
359 pop dword ptr [ebp + 4] ; save updated esp
366 pop ebp ; restore ebp maybe updated
367 pop esp ; restore esp maybe updated
368 sub esp, 4 * 3 ; restore interupt pushced stack