2 ;------------------------------------------------------------------------------
4 ;* Copyright (c) 2006 - 2011, 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 ;; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear
278 ;; UINT32 ExceptionData;
279 push dword ptr [ebp + 2 * 4]
281 ;; call into exception handler
282 mov eax, ExternalVectorTablePtr ; get the interrupt vectors base
284 jz nullExternalExceptionHandler
287 mov eax, [eax + ecx * 4]
289 jz nullExternalExceptionHandler
291 ;; Prepare parameter and call
294 mov edx, dword ptr [ebp + 1 * 4]
298 ; Call External Exception Handler
303 nullExternalExceptionHandler:
306 ;; UINT32 ExceptionData;
309 ;; FX_SAVE_STATE_IA32 FxSaveState;
311 db 0fh, 0aeh, 0eh ; fxrstor [esi]
314 ;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
315 ;; Skip restoration of DRx registers to support in-circuit emualators
316 ;; or debuggers set breakpoint in interrupt/exception context
319 ;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
322 add esp, 4 ; not for Cr1
331 pop dword ptr [ebp + 5 * 4]
334 ;; UINT32 Gdtr[2], Idtr[2];
335 ;; Best not let anyone mess with these particular registers...
339 pop dword ptr [ebp + 3 * 4]
341 ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
342 ;; NOTE - modified segment registers could hang the debugger... We
343 ;; could attempt to insulate ourselves against this possibility,
344 ;; but that poses risks as well.
350 pop dword ptr [ebp + 4 * 4]
353 ;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
356 add esp, 4 ; not for ebp
357 add esp, 4 ; not for esp
368 CommonInterruptEntry ENDP