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
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 eax ; push cr4 firstly
241 push 0 ; cr0 will not saved???
260 mov ecx, [ebp + 4 * 3] ; EIP
263 ;; UINT32 Gdtr[2], Idtr[2];
277 mov ecx, [ebp + 4 * 5]
280 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
284 ;; clear Dr7 while executing debugger itself
292 ;; insure all status bits in dr6 are clear...
305 ;; FX_SAVE_STATE_IA32 FxSaveState;
308 db 0fh, 0aeh, 00000111y ;fxsave [edi]
310 ;; save the exception data
311 push dword ptr [ebp + 8]
313 ;; Clear Direction Flag
316 ; call the C interrupt process function
319 call InterruptProcess
322 ; skip the exception data
325 ;; FX_SAVE_STATE_IA32 FxSaveState;
327 db 0fh, 0aeh, 00001110y ; fxrstor [esi]
330 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
339 ;; skip restore of dr6. We cleared dr6 during the context save.
345 pop dword ptr [ebp + 4 * 5] ; set EFLAGS in stack
348 ;; UINT32 Gdtr[2], Idtr[2];
349 ;; Best not let anyone mess with these particular registers...
353 pop dword ptr [ebp + 4 * 3] ; set EIP in stack
355 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
356 ;; NOTE - modified segment registers could hang the debugger... We
357 ;; could attempt to insulate ourselves against this possibility,
358 ;; but that poses risks as well.
364 pop dword ptr [ebp + 4 * 4] ; set CS in stack
367 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
370 add esp, 4 ; skip for Cr1
378 ;; restore general register
381 pop dword ptr [ebp] ; save updated ebp
382 pop dword ptr [ebp + 4] ; save updated esp
389 pop ebp ; restore ebp maybe updated
390 pop esp ; restore esp maybe updated
391 sub esp, 4 * 3 ; restore interupt pushced stack