1 #------------------------------------------------------------------------------
3 # Copyright (c) 2010 - 2015, 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)
25 ASM_GLOBAL ASM_PFX(Exception0Handle)
26 ASM_GLOBAL ASM_PFX(ExceptionStubHeaderSize)
27 ASM_GLOBAL ASM_PFX(TimerInterruptHandle)
28 ASM_GLOBAL ASM_PFX(CommonEntry)
30 .macro AGENT_HANDLER_SIGNATURE
31 .byte 0x41, 0x47, 0x54, 0x48 # AGENT_HANDLER_SIGNATURE SIGNATURE_32('A','G','T','H')
36 ASM_PFX(ExceptionStubHeaderSize): .long ASM_PFX(Exception1Handle) - ASM_PFX(Exception0Handle)
40 AGENT_HANDLER_SIGNATURE
41 ASM_PFX(Exception0Handle):
45 jmp ASM_PFX(CommonEntry)
46 AGENT_HANDLER_SIGNATURE
47 ASM_PFX(Exception1Handle):
51 jmp ASM_PFX(CommonEntry)
52 AGENT_HANDLER_SIGNATURE
53 ASM_PFX(Exception2Handle):
57 jmp ASM_PFX(CommonEntry)
58 AGENT_HANDLER_SIGNATURE
59 ASM_PFX(Exception3Handle):
63 jmp ASM_PFX(CommonEntry)
64 AGENT_HANDLER_SIGNATURE
65 ASM_PFX(Exception4Handle):
69 jmp ASM_PFX(CommonEntry)
70 AGENT_HANDLER_SIGNATURE
71 ASM_PFX(Exception5Handle):
75 jmp ASM_PFX(CommonEntry)
76 AGENT_HANDLER_SIGNATURE
77 ASM_PFX(Exception6Handle):
81 jmp ASM_PFX(CommonEntry)
82 AGENT_HANDLER_SIGNATURE
83 ASM_PFX(Exception7Handle):
87 jmp ASM_PFX(CommonEntry)
88 AGENT_HANDLER_SIGNATURE
89 ASM_PFX(Exception8Handle):
93 jmp ASM_PFX(CommonEntry)
94 AGENT_HANDLER_SIGNATURE
95 ASM_PFX(Exception9Handle):
99 jmp ASM_PFX(CommonEntry)
100 AGENT_HANDLER_SIGNATURE
101 ASM_PFX(Exception10Handle):
105 jmp ASM_PFX(CommonEntry)
106 AGENT_HANDLER_SIGNATURE
107 ASM_PFX(Exception11Handle):
111 jmp ASM_PFX(CommonEntry)
112 AGENT_HANDLER_SIGNATURE
113 ASM_PFX(Exception12Handle):
117 jmp ASM_PFX(CommonEntry)
118 AGENT_HANDLER_SIGNATURE
119 ASM_PFX(Exception13Handle):
123 jmp ASM_PFX(CommonEntry)
124 AGENT_HANDLER_SIGNATURE
125 ASM_PFX(Exception14Handle):
129 jmp ASM_PFX(CommonEntry)
130 AGENT_HANDLER_SIGNATURE
131 ASM_PFX(Exception15Handle):
135 jmp ASM_PFX(CommonEntry)
136 AGENT_HANDLER_SIGNATURE
137 ASM_PFX(Exception16Handle):
141 jmp ASM_PFX(CommonEntry)
142 AGENT_HANDLER_SIGNATURE
143 ASM_PFX(Exception17Handle):
147 jmp ASM_PFX(CommonEntry)
148 AGENT_HANDLER_SIGNATURE
149 ASM_PFX(Exception18Handle):
153 jmp ASM_PFX(CommonEntry)
154 AGENT_HANDLER_SIGNATURE
155 ASM_PFX(Exception19Handle):
159 jmp ASM_PFX(CommonEntry)
160 AGENT_HANDLER_SIGNATURE
161 ASM_PFX(TimerInterruptHandle):
165 jmp ASM_PFX(CommonEntry)
168 ASM_PFX(CommonEntry):
170 #---------------------------------------;
172 #----------------------------------------------------------------------------;
173 # The follow algorithm is used for the common interrupt routine.
174 # Entry from each interrupt with a push eax and eax=interrupt number
176 # +---------------------+
178 # +---------------------+
180 # +---------------------+
182 # +---------------------+
184 # +---------------------+
185 # + EAX / Vector Number +
186 # +---------------------+
188 # +---------------------+ <-- EBP
191 # We need to determine if any extra data was pushed by the exception
192 cmpl $DEBUG_EXCEPT_DOUBLE_FAULT, %eax
194 cmpl $DEBUG_EXCEPT_INVALID_TSS, %eax
196 cmpl $DEBUG_EXCEPT_SEG_NOT_PRESENT, %eax
198 cmpl $DEBUG_EXCEPT_STACK_FAULT, %eax
200 cmpl $DEBUG_EXCEPT_GP_FAULT, %eax
202 cmpl $DEBUG_EXCEPT_PAGE_FAULT, %eax
204 cmpl $DEBUG_EXCEPT_ALIGNMENT_CHECK, %eax
216 # Align stack to make sure that EFI_FX_SAVE_STATE_IA32 of EFI_SYSTEM_CONTEXT_IA32
219 andl $0xfffffff0,%esp
222 ## UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
227 mov %eax, %ebx # save vector in ebx
229 pushl %ecx # save original ESP
234 ## UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
235 ## insure FXSAVE/FXRSTOR is enabled in CR4...
236 ## ... while we're at it, make sure DE is also enabled...
238 pushl %ebx # temporarily save value of ebx on stack
239 cpuid # use CPUID to determine if FXSAVE/FXRESTOR
240 # and DE are supported
241 popl %ebx # retore value of ebx that was overwritten
244 pushl %eax # push cr4 firstly
245 testl $BIT24, %edx # Test for FXSAVE/FXRESTOR support
247 orl $BIT9, %eax # Set CR4.OSFXSR
249 testl $BIT2, %edx # Test for Debugging Extensions support
251 orl $BIT3, %eax # Set CR4.DE
263 ## UINT32 Gs, Fs, Es, Ds, Cs, Ss;
266 movzwl 16(%ebp), %eax
280 ## UINT32 Gdtr[2], Idtr[2];
296 ## UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
299 ## clear Dr7 while executing debugger itself
305 ## insure all status bits in dr6 are clear...
318 ## FX_SAVE_STATE_IA32 FxSaveState;
321 testl $BIT24, %edx # Test for FXSAVE/FXRESTOR support.
322 # edx still contains result from CPUID above
324 .byte 0x0f, 0xae, 0x07 # fxsave [edi]
327 ## save the exception data
330 ## Clear Direction Flag
333 ## Prepare parameter and call C function
336 call ASM_PFX(InterruptProcess)
339 ## skip the exception data
342 ## FX_SAVE_STATE_IA32 FxSaveState;
345 cpuid # use CPUID to determine if FXSAVE/FXRESTOR
347 testl $BIT24, %edx # Test for FXSAVE/FXRESTOR support
349 .byte 0x0f, 0xae, 0x0e # fxrstor [esi]
353 ## UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
362 ## skip restore of dr6. We cleared dr6 during the context save.
371 ## UINT32 Gdtr[2], Idtr[2];
372 ## Best not let anyone mess with these particular registers...
378 ## UINT32 Gs, Fs, Es, Ds, Cs, Ss;
379 ## NOTE - modified segment registers could hang the debugger... We
380 ## could attempt to insulate ourselves against this possibility,
381 ## but that poses risks as well.
390 ## UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
393 addl $4,%esp # not for Cr1
401 ## UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
404 addl $4,%esp # not for ebp
405 addl $4,%esp # not for esp
413 addl $8,%esp # skip eax