1 #------------------------------------------------------------------------------
3 # Copyright (c) 2006 - 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"
24 ASM_GLOBAL ASM_PFX(InterruptProcess)
26 ASM_GLOBAL ASM_PFX(Exception0Handle)
27 ASM_GLOBAL ASM_PFX(ExceptionStubHeaderSize)
28 ASM_GLOBAL ASM_PFX(TimerInterruptHandle)
29 ASM_GLOBAL ASM_PFX(CommonEntry)
33 ASM_PFX(ExceptionStubHeaderSize): .word ASM_PFX(Exception1Handle) - ASM_PFX(Exception0Handle)
38 .byte 0x41, 0x47, 0x54, 0x48 # AGENT_HANDLER_SIGNATURE SIGNATURE_32('A','G','T','H')
39 ASM_PFX(Exception0Handle):
43 jmp ASM_PFX(CommonEntry)
44 ASM_PFX(Exception1Handle):
48 jmp ASM_PFX(CommonEntry)
49 ASM_PFX(Exception2Handle):
53 jmp ASM_PFX(CommonEntry)
54 ASM_PFX(Exception3Handle):
58 jmp ASM_PFX(CommonEntry)
59 ASM_PFX(Exception4Handle):
63 jmp ASM_PFX(CommonEntry)
64 ASM_PFX(Exception5Handle):
68 jmp ASM_PFX(CommonEntry)
69 ASM_PFX(Exception6Handle):
73 jmp ASM_PFX(CommonEntry)
74 ASM_PFX(Exception7Handle):
78 jmp ASM_PFX(CommonEntry)
79 ASM_PFX(Exception8Handle):
83 jmp ASM_PFX(CommonEntry)
84 ASM_PFX(Exception9Handle):
88 jmp ASM_PFX(CommonEntry)
89 ASM_PFX(Exception10Handle):
93 jmp ASM_PFX(CommonEntry)
94 ASM_PFX(Exception11Handle):
98 jmp ASM_PFX(CommonEntry)
99 ASM_PFX(Exception12Handle):
103 jmp ASM_PFX(CommonEntry)
104 ASM_PFX(Exception13Handle):
108 jmp ASM_PFX(CommonEntry)
109 ASM_PFX(Exception14Handle):
113 jmp ASM_PFX(CommonEntry)
114 ASM_PFX(Exception15Handle):
118 jmp ASM_PFX(CommonEntry)
119 ASM_PFX(Exception16Handle):
123 jmp ASM_PFX(CommonEntry)
124 ASM_PFX(Exception17Handle):
128 jmp ASM_PFX(CommonEntry)
129 ASM_PFX(Exception18Handle):
133 jmp ASM_PFX(CommonEntry)
134 ASM_PFX(Exception19Handle):
138 jmp ASM_PFX(CommonEntry)
140 ASM_PFX(TimerInterruptHandle):
144 jmp ASM_PFX(CommonEntry)
147 ASM_PFX(CommonEntry):
149 #---------------------------------------;
150 # CommonInterruptEntry ;
151 #---------------------------------------;
152 # The follow algorithm is used for the common interrupt routine.
155 # +---------------------+ <-- 16-byte aligned ensured by processor
157 # +---------------------+
159 # +---------------------+
161 # +---------------------+
163 # +---------------------+
165 # +---------------------+
167 # +---------------------+
168 # + RCX / Vector Number +
169 # +---------------------+
171 # +---------------------+ <-- RBP, 16-byte aligned
174 # We need to determine if any extra data was pushed by the exception
175 cmpq $DEBUG_EXCEPT_DOUBLE_FAULT, %rcx
177 cmpq $DEBUG_EXCEPT_INVALID_TSS, %rcx
179 cmpq $DEBUG_EXCEPT_SEG_NOT_PRESENT, %rcx
181 cmpq $DEBUG_EXCEPT_STACK_FAULT, %rcx
183 cmpq $DEBUG_EXCEPT_GP_FAULT, %rcx
185 cmpq $DEBUG_EXCEPT_PAGE_FAULT, %rcx
187 cmpq $DEBUG_EXCEPT_ALIGNMENT_CHECK, %rcx
195 # All interrupt handlers are invoked through interrupt gates, so
196 # IF flag automatically cleared at the entry point
201 # Since here the stack pointer is 16-byte aligned, so
202 # EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64
206 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;
219 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
222 pushq 8(%rbp) # original rcx
224 pushq 48(%rbp) # original rsp
225 pushq (%rbp) # original rbp
229 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4;
243 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero
244 xorq %rax, %rax # set rax to 0
245 movzwq 56(%rbp), %rax
248 movzwq 32(%rbp), %rax
263 ## UINT64 Gdtr[2], Idtr[2];
279 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
282 ## clear Dr7 while executing debugger itself
288 ## insure all status bits in dr6 are clear...
301 ## FX_SAVE_STATE_X64 FxSaveState;
304 .byte 0x0f, 0xae, 0b00000111
306 ## save the exception data;
309 ## Clear Direction Flag
312 ## Prepare parameter and call
315 movq %rcx, %r15 # save vector in r15
317 # Per X64 calling convention, allocate maximum parameter stack space
318 # and make sure RSP is 16-byte aligned
321 call ASM_PFX(InterruptProcess)
324 ## skip the exception data;
327 ## FX_SAVE_STATE_X64 FxSaveState;
330 .byte 0x0f, 0xae, 0b00001110
333 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
342 ## skip restore of dr6. We cleared dr6 during the context save.
351 ## UINT64 Gdtr[2], Idtr[2];
352 ## Best not let anyone mess with these particular registers...
358 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss;
360 # mov gs, rax ; not for gs
362 # mov fs, rax ; not for fs
363 # (X64 will not use fs and gs, so we do not restore it)
371 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;
382 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
383 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;