1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
12 ; Debug interrupt handle functions.
14 ;------------------------------------------------------------------------------
16 #include "DebugException.h"
20 extern ASM_PFX(InterruptProcess)
21 global ASM_PFX(Exception0Handle)
22 global ASM_PFX(TimerInterruptHandle)
23 global ASM_PFX(ExceptionStubHeaderSize)
25 %macro AGENT_HANDLER_SIGNATURE 0
26 db 0x41, 0x47, 0x54, 0x48 ; SIGNATURE_32('A','G','T','H')
29 ASM_PFX(ExceptionStubHeaderSize): dd Exception1Handle - ASM_PFX(Exception0Handle) ;
30 CommonEntryAddr: dq CommonEntry ;
35 AGENT_HANDLER_SIGNATURE
36 ASM_PFX(Exception0Handle):
40 jmp qword [CommonEntryAddr]
41 AGENT_HANDLER_SIGNATURE
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
156 ASM_PFX(TimerInterruptHandle):
160 jmp qword [CommonEntryAddr]
163 ; We need to determine if any extra data was pushed by the exception
164 cmp rcx, DEBUG_EXCEPT_DOUBLE_FAULT
166 cmp rcx, DEBUG_EXCEPT_INVALID_TSS
168 cmp rcx, DEBUG_EXCEPT_SEG_NOT_PRESENT
170 cmp rcx, DEBUG_EXCEPT_STACK_FAULT
172 cmp rcx, DEBUG_EXCEPT_GP_FAULT
174 cmp rcx, DEBUG_EXCEPT_PAGE_FAULT
176 cmp rcx, DEBUG_EXCEPT_ALIGNMENT_CHECK
180 mov qword [rsp + 8], 0
186 ; store UINT64 r8, r9, r10, r11, r12, r13, r14, r15;
199 ; store UINT64 Rdi, Rsi, Rbp, Rsp, Rdx, Rcx, Rbx, Rax;
202 push qword [rbp + 8] ; original rcx
204 push qword [rbp + 6 * 8] ; original rsp
205 push qword [rbp] ; original rbp
209 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
210 ;; insure FXSAVE/FXRSTOR is enabled in CR4...
211 ;; ... while we're at it, make sure DE is also enabled...
239 mov rax, [rbp + 8 * 3] ; EIP
242 ;; UINT64 Gdtr[2], Idtr[2];
256 mov rax, [rbp + 8 * 5]
259 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
263 ;; clear Dr7 while executing debugger itself
271 ;; insure all status bits in dr6 are clear...
284 ;; Clear Direction Flag
292 mov rcx, dword 64 ;= 512 / 8
298 ;; save the exception data
299 push qword [rbp + 16]
301 ; call the C interrupt process function
302 mov rdx, rsp ; Structure
303 mov r15, rcx ; save vector in r15
306 ; Per X64 calling convention, allocate maximum parameter stack space
307 ; and make sure RSP is 16-byte aligned
310 call ASM_PFX(InterruptProcess)
313 ;; skip the exception data
320 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
329 ;; skip restore of dr6. We cleared dr6 during the context save.
335 pop qword [rbp + 8 * 5]
338 ;; UINT64 Gdtr[2], Idtr[2];
339 ;; Best not let anyone mess with these particular registers...
343 pop qword [rbp + 8 * 3] ; set EIP in stack
345 ;; UINT64 Gs, Fs, Es, Ds, Cs, Ss;
346 ;; NOTE - modified segment registers could hang the debugger... We
347 ;; could attempt to insulate ourselves against this possibility,
348 ;; but that poses risks as well.
356 pop qword [rbp + 8 * 4] ; Set CS in stack
360 ;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4;
363 add rsp, 8 ; skip for Cr1
371 ;; restore general register
374 add rsp, 8 ; skip rbp
375 add rsp, 8 ; skip rsp
384 ; store UINT64 r8, r9, r10, r11, r12, r13, r14, r15;
396 add rsp, 16 ; skip rcx and error code