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"
25 externdef InterruptProcess:near
29 public Exception0Handle, TimerInterruptHandle, ExceptionStubHeaderSize
31 AGENT_HANDLER_SIGNATURE MACRO
32 db 41h, 47h, 54h, 48h ; SIGNATURE_32('A','G','T','H')
35 ExceptionStubHeaderSize dd Exception1Handle - Exception0Handle ;
36 CommonEntryAddr dq CommonEntry ;
40 AGENT_HANDLER_SIGNATURE
45 jmp qword ptr [CommonEntryAddr]
46 AGENT_HANDLER_SIGNATURE
51 jmp qword ptr [CommonEntryAddr]
52 AGENT_HANDLER_SIGNATURE
57 jmp qword ptr [CommonEntryAddr]
58 AGENT_HANDLER_SIGNATURE
63 jmp qword ptr [CommonEntryAddr]
64 AGENT_HANDLER_SIGNATURE
69 jmp qword ptr [CommonEntryAddr]
70 AGENT_HANDLER_SIGNATURE
75 jmp qword ptr [CommonEntryAddr]
76 AGENT_HANDLER_SIGNATURE
81 jmp qword ptr [CommonEntryAddr]
82 AGENT_HANDLER_SIGNATURE
87 jmp qword ptr [CommonEntryAddr]
88 AGENT_HANDLER_SIGNATURE
93 jmp qword ptr [CommonEntryAddr]
94 AGENT_HANDLER_SIGNATURE
99 jmp qword ptr [CommonEntryAddr]
100 AGENT_HANDLER_SIGNATURE
105 jmp qword ptr [CommonEntryAddr]
106 AGENT_HANDLER_SIGNATURE
111 jmp qword ptr [CommonEntryAddr]
112 AGENT_HANDLER_SIGNATURE
117 jmp qword ptr [CommonEntryAddr]
118 AGENT_HANDLER_SIGNATURE
123 jmp qword ptr [CommonEntryAddr]
124 AGENT_HANDLER_SIGNATURE
129 jmp qword ptr [CommonEntryAddr]
130 AGENT_HANDLER_SIGNATURE
135 jmp qword ptr [CommonEntryAddr]
136 AGENT_HANDLER_SIGNATURE
141 jmp qword ptr [CommonEntryAddr]
142 AGENT_HANDLER_SIGNATURE
147 jmp qword ptr [CommonEntryAddr]
148 AGENT_HANDLER_SIGNATURE
153 jmp qword ptr [CommonEntryAddr]
154 AGENT_HANDLER_SIGNATURE
159 jmp qword ptr [CommonEntryAddr]
160 AGENT_HANDLER_SIGNATURE
161 TimerInterruptHandle:
165 jmp qword ptr [CommonEntryAddr]
168 ; We need to determine if any extra data was pushed by the exception
169 cmp rcx, DEBUG_EXCEPT_DOUBLE_FAULT
171 cmp rcx, DEBUG_EXCEPT_INVALID_TSS
173 cmp rcx, DEBUG_EXCEPT_SEG_NOT_PRESENT
175 cmp rcx, DEBUG_EXCEPT_STACK_FAULT
177 cmp rcx, DEBUG_EXCEPT_GP_FAULT
179 cmp rcx, DEBUG_EXCEPT_PAGE_FAULT
181 cmp rcx, DEBUG_EXCEPT_ALIGNMENT_CHECK
185 mov qword ptr [rsp + 8], 0
191 ; store UINT64 r8, r9, r10, r11, r12, r13, r14, r15;
204 ; store UINT64 Rdi, Rsi, Rbp, Rsp, Rdx, Rcx, Rbx, Rax;
207 push qword ptr [rbp + 8] ; original rcx
209 push qword ptr [rbp + 6 * 8] ; original rsp
210 push qword ptr [rbp] ; original rbp
214 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
215 ;; insure FXSAVE/FXRSTOR is enabled in CR4...
216 ;; ... while we're at it, make sure DE is also enabled...
244 mov rax, [rbp + 8 * 3] ; EIP
247 ;; UINT64 Gdtr[2], Idtr[2];
261 mov rax, [rbp + 8 * 5]
264 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
268 ;; clear Dr7 while executing debugger itself
276 ;; insure all status bits in dr6 are clear...
291 db 0fh, 0aeh, 00000111y ;fxsave [rdi]
293 ;; save the exception data
294 push qword ptr [rbp + 16]
296 ;; Clear Direction Flag
299 ; call the C interrupt process function
300 mov rdx, rsp ; Structure
301 mov r15, rcx ; save vector in r15
304 ; Per X64 calling convention, allocate maximum parameter stack space
305 ; and make sure RSP is 16-byte aligned
308 call InterruptProcess
311 ;; skip the exception data
315 db 0fh, 0aeh, 00001110y ; fxrstor [rsi]
318 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
327 ;; skip restore of dr6. We cleared dr6 during the context save.
333 pop qword ptr [rbp + 8 * 5]
336 ;; UINT64 Gdtr[2], Idtr[2];
337 ;; Best not let anyone mess with these particular registers...
341 pop qword ptr [rbp + 8 * 3] ; set EIP in stack
343 ;; UINT64 Gs, Fs, Es, Ds, Cs, Ss;
344 ;; NOTE - modified segment registers could hang the debugger... We
345 ;; could attempt to insulate ourselves against this possibility,
346 ;; but that poses risks as well.
354 pop qword ptr [rbp + 8 * 4] ; Set CS in stack
358 ;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4;
361 add rsp, 8 ; skip for Cr1
369 ;; restore general register
372 add rsp, 8 ; skip rbp
373 add rsp, 8 ; skip rsp
382 ; store UINT64 r8, r9, r10, r11, r12, r13, r14, r15;
394 add rsp, 16 ; skip rcx and error code