1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2016, 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"
26 extern ASM_PFX(InterruptProcess)
27 global ASM_PFX(Exception0Handle)
28 global ASM_PFX(TimerInterruptHandle)
29 global ASM_PFX(ExceptionStubHeaderSize)
31 %macro AGENT_HANDLER_SIGNATURE 0
32 db 0x41, 0x47, 0x54, 0x48 ; SIGNATURE_32('A','G','T','H')
35 ASM_PFX(ExceptionStubHeaderSize): dd Exception1Handle - ASM_PFX(Exception0Handle) ;
36 CommonEntryAddr: dq CommonEntry ;
41 AGENT_HANDLER_SIGNATURE
42 ASM_PFX(Exception0Handle):
46 jmp qword [CommonEntryAddr]
47 AGENT_HANDLER_SIGNATURE
52 jmp qword [CommonEntryAddr]
53 AGENT_HANDLER_SIGNATURE
58 jmp qword [CommonEntryAddr]
59 AGENT_HANDLER_SIGNATURE
64 jmp qword [CommonEntryAddr]
65 AGENT_HANDLER_SIGNATURE
70 jmp qword [CommonEntryAddr]
71 AGENT_HANDLER_SIGNATURE
76 jmp qword [CommonEntryAddr]
77 AGENT_HANDLER_SIGNATURE
82 jmp qword [CommonEntryAddr]
83 AGENT_HANDLER_SIGNATURE
88 jmp qword [CommonEntryAddr]
89 AGENT_HANDLER_SIGNATURE
94 jmp qword [CommonEntryAddr]
95 AGENT_HANDLER_SIGNATURE
100 jmp qword [CommonEntryAddr]
101 AGENT_HANDLER_SIGNATURE
106 jmp qword [CommonEntryAddr]
107 AGENT_HANDLER_SIGNATURE
112 jmp qword [CommonEntryAddr]
113 AGENT_HANDLER_SIGNATURE
118 jmp qword [CommonEntryAddr]
119 AGENT_HANDLER_SIGNATURE
124 jmp qword [CommonEntryAddr]
125 AGENT_HANDLER_SIGNATURE
130 jmp qword [CommonEntryAddr]
131 AGENT_HANDLER_SIGNATURE
136 jmp qword [CommonEntryAddr]
137 AGENT_HANDLER_SIGNATURE
142 jmp qword [CommonEntryAddr]
143 AGENT_HANDLER_SIGNATURE
148 jmp qword [CommonEntryAddr]
149 AGENT_HANDLER_SIGNATURE
154 jmp qword [CommonEntryAddr]
155 AGENT_HANDLER_SIGNATURE
160 jmp qword [CommonEntryAddr]
161 AGENT_HANDLER_SIGNATURE
162 ASM_PFX(TimerInterruptHandle):
166 jmp qword [CommonEntryAddr]
169 ; We need to determine if any extra data was pushed by the exception
170 cmp rcx, DEBUG_EXCEPT_DOUBLE_FAULT
172 cmp rcx, DEBUG_EXCEPT_INVALID_TSS
174 cmp rcx, DEBUG_EXCEPT_SEG_NOT_PRESENT
176 cmp rcx, DEBUG_EXCEPT_STACK_FAULT
178 cmp rcx, DEBUG_EXCEPT_GP_FAULT
180 cmp rcx, DEBUG_EXCEPT_PAGE_FAULT
182 cmp rcx, DEBUG_EXCEPT_ALIGNMENT_CHECK
186 mov qword [rsp + 8], 0
192 ; store UINT64 r8, r9, r10, r11, r12, r13, r14, r15;
205 ; store UINT64 Rdi, Rsi, Rbp, Rsp, Rdx, Rcx, Rbx, Rax;
208 push qword [rbp + 8] ; original rcx
210 push qword [rbp + 6 * 8] ; original rsp
211 push qword [rbp] ; original rbp
215 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
216 ;; insure FXSAVE/FXRSTOR is enabled in CR4...
217 ;; ... while we're at it, make sure DE is also enabled...
245 mov rax, [rbp + 8 * 3] ; EIP
248 ;; UINT64 Gdtr[2], Idtr[2];
262 mov rax, [rbp + 8 * 5]
265 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
269 ;; clear Dr7 while executing debugger itself
277 ;; insure all status bits in dr6 are clear...
290 ;; Clear Direction Flag
298 mov rcx, dword 64 ;= 512 / 8
302 db 0xf, 0xae, 00000111y ;fxsave [rdi]
304 ;; save the exception data
305 push qword [rbp + 16]
307 ; call the C interrupt process function
308 mov rdx, rsp ; Structure
309 mov r15, rcx ; save vector in r15
312 ; Per X64 calling convention, allocate maximum parameter stack space
313 ; and make sure RSP is 16-byte aligned
316 call ASM_PFX(InterruptProcess)
319 ;; skip the exception data
323 db 0xf, 0xae, 00001110y ; fxrstor [rsi]
326 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
335 ;; skip restore of dr6. We cleared dr6 during the context save.
341 pop qword [rbp + 8 * 5]
344 ;; UINT64 Gdtr[2], Idtr[2];
345 ;; Best not let anyone mess with these particular registers...
349 pop qword [rbp + 8 * 3] ; set EIP in stack
351 ;; UINT64 Gs, Fs, Es, Ds, Cs, Ss;
352 ;; NOTE - modified segment registers could hang the debugger... We
353 ;; could attempt to insulate ourselves against this possibility,
354 ;; but that poses risks as well.
362 pop qword [rbp + 8 * 4] ; Set CS in stack
366 ;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4;
369 add rsp, 8 ; skip for Cr1
377 ;; restore general register
380 add rsp, 8 ; skip rbp
381 add rsp, 8 ; skip rsp
390 ; store UINT64 r8, r9, r10, r11, r12, r13, r14, r15;
402 add rsp, 16 ; skip rcx and error code