1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2010, 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
46 jmp dword ptr [CommonEntryAddr]
51 jmp dword ptr [CommonEntryAddr]
56 jmp dword ptr [CommonEntryAddr]
61 jmp dword ptr [CommonEntryAddr]
66 jmp dword ptr [CommonEntryAddr]
71 jmp dword ptr [CommonEntryAddr]
76 jmp dword ptr [CommonEntryAddr]
81 jmp dword ptr [CommonEntryAddr]
86 jmp dword ptr [CommonEntryAddr]
91 jmp dword ptr [CommonEntryAddr]
96 jmp dword ptr [CommonEntryAddr]
101 jmp dword ptr [CommonEntryAddr]
106 jmp dword ptr [CommonEntryAddr]
111 jmp dword ptr [CommonEntryAddr]
116 jmp dword ptr [CommonEntryAddr]
121 jmp dword ptr [CommonEntryAddr]
126 jmp dword ptr [CommonEntryAddr]
131 jmp dword ptr [CommonEntryAddr]
136 jmp dword ptr [CommonEntryAddr]
141 jmp dword ptr [CommonEntryAddr]
143 TimerInterruptHandle:
147 jmp dword ptr [CommonEntryAddr]
151 ; +---------------------+
153 ; +---------------------+
155 ; +---------------------+
157 ; +---------------------+
159 ; +---------------------+
160 ; + EAX / Vector Number +
161 ; +---------------------+
163 ; +---------------------+ <-- EBP
165 cmp eax, DEBUG_EXCEPT_DOUBLE_FAULT
167 cmp eax, DEBUG_EXCEPT_INVALID_TSS
169 cmp eax, DEBUG_EXCEPT_SEG_NOT_PRESENT
171 cmp eax, DEBUG_EXCEPT_STACK_FAULT
173 cmp eax, DEBUG_EXCEPT_GP_FAULT
175 cmp eax, DEBUG_EXCEPT_PAGE_FAULT
177 cmp eax, DEBUG_EXCEPT_ALIGNMENT_CHECK
181 mov dword ptr [esp + 4], 0
186 mov ebp, esp ; save esp in ebp
188 ; Make stack 16-byte alignment to make sure save fxrstor later
193 ; store UINT32 Edi, Esi, Ebp, Ebx, Edx, Ecx, Eax;
194 push dword ptr [ebp + 4] ; original eax
198 mov ebx, eax ; save vector in ebx
201 push eax ; original ESP
202 push dword ptr [ebp] ; EBP
206 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
207 ;; insure FXSAVE/FXRSTOR is enabled in CR4...
208 ;; ... while we're at it, make sure DE is also enabled...
210 push eax ; push cr4 firstly
217 push 0 ; cr0 will not saved???
236 mov ecx, [ebp + 4 * 3] ; EIP
239 ;; UINT32 Gdtr[2], Idtr[2];
253 mov ecx, [ebp + 4 * 5]
256 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
260 ;; clear Dr7 while executing debugger itself
268 ;; insure all status bits in dr6 are clear...
281 ;; FX_SAVE_STATE_IA32 FxSaveState;
284 db 0fh, 0aeh, 00000111y ;fxsave [edi]
286 ;; Clear Direction Flag
289 ; call the C interrupt process function
292 call InterruptProcess
295 ;; FX_SAVE_STATE_IA32 FxSaveState;
297 db 0fh, 0aeh, 00001110y ; fxrstor [esi]
300 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
309 ;; skip restore of dr6. We cleared dr6 during the context save.
315 pop dword ptr [ebp + 4 * 5] ; set EFLAGS in stack
318 ;; UINT32 Gdtr[2], Idtr[2];
319 ;; Best not let anyone mess with these particular registers...
323 pop dword ptr [ebp + 4 * 3] ; set EIP in stack
325 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
326 ;; NOTE - modified segment registers could hang the debugger... We
327 ;; could attempt to insulate ourselves against this possibility,
328 ;; but that poses risks as well.
334 pop dword ptr [ebp + 4 * 4] ; set CS in stack
337 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
340 add esp, 4 ; skip for Cr1
348 ;; restore general register
351 pop dword ptr [ebp] ; save updated ebp
352 pop dword ptr [ebp + 4] ; save updated esp
359 pop ebp ; restore ebp maybe updated
360 pop esp ; restore esp maybe updated
361 sub esp, 4 * 3 ; restore interupt pushced stack