1 #------------------------------------------------------------------------------
3 # Copyright (c) 2006 - 2012, 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 ASM_PFX(Exception0Handle):
42 jmp ASM_PFX(CommonEntry)
43 ASM_PFX(Exception1Handle):
47 jmp ASM_PFX(CommonEntry)
48 ASM_PFX(Exception2Handle):
52 jmp ASM_PFX(CommonEntry)
53 ASM_PFX(Exception3Handle):
57 jmp ASM_PFX(CommonEntry)
58 ASM_PFX(Exception4Handle):
62 jmp ASM_PFX(CommonEntry)
63 ASM_PFX(Exception5Handle):
67 jmp ASM_PFX(CommonEntry)
68 ASM_PFX(Exception6Handle):
72 jmp ASM_PFX(CommonEntry)
73 ASM_PFX(Exception7Handle):
77 jmp ASM_PFX(CommonEntry)
78 ASM_PFX(Exception8Handle):
82 jmp ASM_PFX(CommonEntry)
83 ASM_PFX(Exception9Handle):
87 jmp ASM_PFX(CommonEntry)
88 ASM_PFX(Exception10Handle):
92 jmp ASM_PFX(CommonEntry)
93 ASM_PFX(Exception11Handle):
97 jmp ASM_PFX(CommonEntry)
98 ASM_PFX(Exception12Handle):
102 jmp ASM_PFX(CommonEntry)
103 ASM_PFX(Exception13Handle):
107 jmp ASM_PFX(CommonEntry)
108 ASM_PFX(Exception14Handle):
112 jmp ASM_PFX(CommonEntry)
113 ASM_PFX(Exception15Handle):
117 jmp ASM_PFX(CommonEntry)
118 ASM_PFX(Exception16Handle):
122 jmp ASM_PFX(CommonEntry)
123 ASM_PFX(Exception17Handle):
127 jmp ASM_PFX(CommonEntry)
128 ASM_PFX(Exception18Handle):
132 jmp ASM_PFX(CommonEntry)
133 ASM_PFX(Exception19Handle):
137 jmp ASM_PFX(CommonEntry)
139 ASM_PFX(TimerInterruptHandle):
143 jmp ASM_PFX(CommonEntry)
146 ASM_PFX(CommonEntry):
148 #---------------------------------------;
149 # CommonInterruptEntry ;
150 #---------------------------------------;
151 # The follow algorithm is used for the common interrupt routine.
154 # +---------------------+ <-- 16-byte aligned ensured by processor
156 # +---------------------+
158 # +---------------------+
160 # +---------------------+
162 # +---------------------+
164 # +---------------------+
166 # +---------------------+
167 # + RCX / Vector Number +
168 # +---------------------+
170 # +---------------------+ <-- RBP, 16-byte aligned
173 # We need to determine if any extra data was pushed by the exception
174 cmpq $DEBUG_EXCEPT_DOUBLE_FAULT, %rcx
176 cmpq $DEBUG_EXCEPT_INVALID_TSS, %rcx
178 cmpq $DEBUG_EXCEPT_SEG_NOT_PRESENT, %rcx
180 cmpq $DEBUG_EXCEPT_STACK_FAULT, %rcx
182 cmpq $DEBUG_EXCEPT_GP_FAULT, %rcx
184 cmpq $DEBUG_EXCEPT_PAGE_FAULT, %rcx
186 cmpq $DEBUG_EXCEPT_ALIGNMENT_CHECK, %rcx
194 # All interrupt handlers are invoked through interrupt gates, so
195 # IF flag automatically cleared at the entry point
200 # Since here the stack pointer is 16-byte aligned, so
201 # EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64
205 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;
218 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
221 pushq 8(%rbp) # original rcx
223 pushq 48(%rbp) # original rsp
224 pushq (%rbp) # original rbp
228 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4;
242 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero
243 xorq %rax, %rax # set rax to 0
244 movzwq 56(%rbp), %rax
247 movzwq 32(%rbp), %rax
262 ## UINT64 Gdtr[2], Idtr[2];
278 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
281 ## clear Dr7 while executing debugger itself
283 #debug movq %rax, %dr7
287 ## insure all status bits in dr6 are clear...
300 ## FX_SAVE_STATE_X64 FxSaveState;
303 .byte 0x0f, 0xae, 0b00000111
305 ## save the exception data;
308 ## Clear Direction Flag
311 ## Prepare parameter and call
314 movq %rcx, %r15 # save vector in r15
316 # Per X64 calling convention, allocate maximum parameter stack space
317 # and make sure RSP is 16-byte aligned
320 call ASM_PFX(InterruptProcess)
323 ## skip the exception data;
326 ## FX_SAVE_STATE_X64 FxSaveState;
329 .byte 0x0f, 0xae, 0b00001110
332 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
341 ## skip restore of dr6. We cleared dr6 during the context save.
350 ## UINT64 Gdtr[2], Idtr[2];
351 ## Best not let anyone mess with these particular registers...
357 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss;
359 # mov gs, rax ; not for gs
361 # mov fs, rax ; not for fs
362 # (X64 will not use fs and gs, so we do not restore it)
370 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;
381 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
382 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;