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)
31 .macro AGENT_HANDLER_SIGNATURE
32 .byte 0x41, 0x47, 0x54, 0x48 # AGENT_HANDLER_SIGNATURE SIGNATURE_32('A','G','T','H')
37 ASM_PFX(ExceptionStubHeaderSize): .word ASM_PFX(Exception1Handle) - ASM_PFX(Exception0Handle)
42 AGENT_HANDLER_SIGNATURE
43 ASM_PFX(Exception0Handle):
47 jmp ASM_PFX(CommonEntry)
48 AGENT_HANDLER_SIGNATURE
49 ASM_PFX(Exception1Handle):
53 jmp ASM_PFX(CommonEntry)
54 AGENT_HANDLER_SIGNATURE
55 ASM_PFX(Exception2Handle):
59 jmp ASM_PFX(CommonEntry)
60 AGENT_HANDLER_SIGNATURE
61 ASM_PFX(Exception3Handle):
65 jmp ASM_PFX(CommonEntry)
66 AGENT_HANDLER_SIGNATURE
67 ASM_PFX(Exception4Handle):
71 jmp ASM_PFX(CommonEntry)
72 AGENT_HANDLER_SIGNATURE
73 ASM_PFX(Exception5Handle):
77 jmp ASM_PFX(CommonEntry)
78 AGENT_HANDLER_SIGNATURE
79 ASM_PFX(Exception6Handle):
83 jmp ASM_PFX(CommonEntry)
84 AGENT_HANDLER_SIGNATURE
85 ASM_PFX(Exception7Handle):
89 jmp ASM_PFX(CommonEntry)
90 AGENT_HANDLER_SIGNATURE
91 ASM_PFX(Exception8Handle):
95 jmp ASM_PFX(CommonEntry)
96 AGENT_HANDLER_SIGNATURE
97 ASM_PFX(Exception9Handle):
101 jmp ASM_PFX(CommonEntry)
102 AGENT_HANDLER_SIGNATURE
103 ASM_PFX(Exception10Handle):
107 jmp ASM_PFX(CommonEntry)
108 AGENT_HANDLER_SIGNATURE
109 ASM_PFX(Exception11Handle):
113 jmp ASM_PFX(CommonEntry)
114 AGENT_HANDLER_SIGNATURE
115 ASM_PFX(Exception12Handle):
119 jmp ASM_PFX(CommonEntry)
120 AGENT_HANDLER_SIGNATURE
121 ASM_PFX(Exception13Handle):
125 jmp ASM_PFX(CommonEntry)
126 AGENT_HANDLER_SIGNATURE
127 ASM_PFX(Exception14Handle):
131 jmp ASM_PFX(CommonEntry)
132 AGENT_HANDLER_SIGNATURE
133 ASM_PFX(Exception15Handle):
137 jmp ASM_PFX(CommonEntry)
138 AGENT_HANDLER_SIGNATURE
139 ASM_PFX(Exception16Handle):
143 jmp ASM_PFX(CommonEntry)
144 AGENT_HANDLER_SIGNATURE
145 ASM_PFX(Exception17Handle):
149 jmp ASM_PFX(CommonEntry)
150 AGENT_HANDLER_SIGNATURE
151 ASM_PFX(Exception18Handle):
155 jmp ASM_PFX(CommonEntry)
156 AGENT_HANDLER_SIGNATURE
157 ASM_PFX(Exception19Handle):
161 jmp ASM_PFX(CommonEntry)
162 AGENT_HANDLER_SIGNATURE
163 ASM_PFX(TimerInterruptHandle):
167 jmp ASM_PFX(CommonEntry)
170 ASM_PFX(CommonEntry):
172 #---------------------------------------;
173 # CommonInterruptEntry ;
174 #---------------------------------------;
175 # The follow algorithm is used for the common interrupt routine.
178 # +---------------------+ <-- 16-byte aligned ensured by processor
180 # +---------------------+
182 # +---------------------+
184 # +---------------------+
186 # +---------------------+
188 # +---------------------+
190 # +---------------------+
191 # + RCX / Vector Number +
192 # +---------------------+
194 # +---------------------+ <-- RBP, 16-byte aligned
197 # We need to determine if any extra data was pushed by the exception
198 cmpq $DEBUG_EXCEPT_DOUBLE_FAULT, %rcx
200 cmpq $DEBUG_EXCEPT_INVALID_TSS, %rcx
202 cmpq $DEBUG_EXCEPT_SEG_NOT_PRESENT, %rcx
204 cmpq $DEBUG_EXCEPT_STACK_FAULT, %rcx
206 cmpq $DEBUG_EXCEPT_GP_FAULT, %rcx
208 cmpq $DEBUG_EXCEPT_PAGE_FAULT, %rcx
210 cmpq $DEBUG_EXCEPT_ALIGNMENT_CHECK, %rcx
218 # All interrupt handlers are invoked through interrupt gates, so
219 # IF flag automatically cleared at the entry point
224 # Since here the stack pointer is 16-byte aligned, so
225 # EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64
229 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;
242 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
245 pushq 8(%rbp) # original rcx
247 pushq 48(%rbp) # original rsp
248 pushq (%rbp) # original rbp
252 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4;
266 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero
267 xorq %rax, %rax # set rax to 0
268 movzwq 56(%rbp), %rax
271 movzwq 32(%rbp), %rax
286 ## UINT64 Gdtr[2], Idtr[2];
302 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
305 ## clear Dr7 while executing debugger itself
311 ## insure all status bits in dr6 are clear...
324 ## FX_SAVE_STATE_X64 FxSaveState;
327 .byte 0x0f, 0xae, 0b00000111
329 ## save the exception data;
332 ## Clear Direction Flag
335 ## Prepare parameter and call
338 movq %rcx, %r15 # save vector in r15
340 # Per X64 calling convention, allocate maximum parameter stack space
341 # and make sure RSP is 16-byte aligned
344 call ASM_PFX(InterruptProcess)
347 ## skip the exception data;
350 ## FX_SAVE_STATE_X64 FxSaveState;
353 .byte 0x0f, 0xae, 0b00001110
356 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
365 ## skip restore of dr6. We cleared dr6 during the context save.
374 ## UINT64 Gdtr[2], Idtr[2];
375 ## Best not let anyone mess with these particular registers...
381 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss;
383 # mov gs, rax ; not for gs
385 # mov fs, rax ; not for fs
386 # (X64 will not use fs and gs, so we do not restore it)
394 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;
405 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
406 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;