2 ;------------------------------------------------------------------------------
4 ;* Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 ;* This program and the accompanying materials
6 ;* are licensed and made available under the terms and conditions of the BSD License
7 ;* which accompanies this distribution. The full text of the license may be found at
8 ;* http://opensource.org/licenses/bsd-license.php
10 ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 ;------------------------------------------------------------------------------
23 EXTRN mErrorCodeFlag:DWORD ; Error code flags for exceptions
26 ; point to the external interrupt vector table
28 ExternalVectorTablePtr DWORD 0
30 InitializeExternalVectorTablePtr PROC PUBLIC
32 mov ExternalVectorTablePtr, eax
34 InitializeExternalVectorTablePtr ENDP
36 ;------------------------------------------------------------------------------
41 ;------------------------------------------------------------------------------
42 SetCodeSelector PROC PUBLIC
45 lea eax, setCodeSelectorLongJump
49 setCodeSelectorLongJump:
54 ;------------------------------------------------------------------------------
59 ;------------------------------------------------------------------------------
60 SetDataSelectors PROC PUBLIC
70 ;---------------------------------------;
71 ; CommonInterruptEntry ;
72 ;---------------------------------------;
73 ; The follow algorithm is used for the common interrupt routine.
75 CommonInterruptEntry PROC PUBLIC
78 ; All interrupt handlers are invoked through interrupt gates, so
79 ; IF flag automatically cleared at the entry point
83 ; Calculate vector number
85 ; Get the return address of call, actually, it is the
86 ; address of vector number.
91 cmp ecx, 32 ; Intel reserved vector for exceptions?
93 bt mErrorCodeFlag, ecx
100 ; +---------------------+
102 ; +---------------------+
104 ; +---------------------+
106 ; +---------------------+
108 ; +---------------------+ <-- ESP
111 ; ECX - Vector Number
115 ; Put Vector Number on stack
120 ; Put 0 (dummy) error code on stack, and restore ECX
122 xor ecx, ecx ; ECX = 0
125 jmp ErrorCodeAndVectorOnStack
131 ; +---------------------+
133 ; +---------------------+
135 ; +---------------------+
137 ; +---------------------+
139 ; +---------------------+
141 ; +---------------------+ <-- ESP
144 ; ECX - Vector Number
148 ; Put Vector Number on stack and restore ECX
153 ; Fall through to join main routine code
154 ; at ErrorCodeAndVectorOnStack
159 ErrorCodeAndVectorOnStack:
165 ; +---------------------+
167 ; +---------------------+
169 ; +---------------------+
171 ; +---------------------+
173 ; +---------------------+
175 ; +---------------------+
177 ; +---------------------+ <-- EBP
181 ; Align stack to make sure that EFI_FX_SAVE_STATE_IA32 of EFI_SYSTEM_CONTEXT_IA32
187 ;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
192 lea ecx, [ebp + 6 * 4]
194 push dword ptr [ebp] ; EBP
198 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
201 movzx eax, word ptr [ebp + 4 * 4]
213 mov eax, [ebp + 3 * 4]
216 ;; UINT32 Gdtr[2], Idtr[2];
239 mov eax, [ebp + 5 * 4]
242 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
256 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
270 ;; FX_SAVE_STATE_IA32 FxSaveState;
273 db 0fh, 0aeh, 07h ;fxsave [edi]
275 ;; UINT32 ExceptionData;
276 push dword ptr [ebp + 2 * 4]
278 ;; call into exception handler
279 mov eax, ExternalVectorTablePtr ; get the interrupt vectors base
281 jz nullExternalExceptionHandler
284 mov eax, [eax + ecx * 4]
286 jz nullExternalExceptionHandler
288 ;; Prepare parameter and call
291 mov edx, dword ptr [ebp + 1 * 4]
295 ; Call External Exception Handler
300 nullExternalExceptionHandler:
303 ;; UINT32 ExceptionData;
306 ;; FX_SAVE_STATE_IA32 FxSaveState;
308 db 0fh, 0aeh, 0eh ; fxrstor [esi]
311 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
312 ;; Skip restoration of DRx registers to support in-circuit emualators
313 ;; or debuggers set breakpoint in interrupt/exception context
316 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
319 add esp, 4 ; not for Cr1
328 pop dword ptr [ebp + 5 * 4]
331 ;; UINT32 Gdtr[2], Idtr[2];
332 ;; Best not let anyone mess with these particular registers...
336 pop dword ptr [ebp + 3 * 4]
338 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
339 ;; NOTE - modified segment registers could hang the debugger... We
340 ;; could attempt to insulate ourselves against this possibility,
341 ;; but that poses risks as well.
347 pop dword ptr [ebp + 4 * 4]
350 ;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
353 add esp, 4 ; not for ebp
354 add esp, 4 ; not for esp
365 CommonInterruptEntry ENDP