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.
16 #------------------------------------------------------------------------------
22 #EXTRN ASM_PFX(mErrorCodeFlag):DWORD # Error code flags for exceptions
26 # point to the external interrupt vector table
28 ExternalVectorTablePtr:
31 ASM_GLOBAL ASM_PFX(InitializeExternalVectorTablePtr)
32 ASM_PFX(InitializeExternalVectorTablePtr):
34 movl %eax, ExternalVectorTablePtr
37 #------------------------------------------------------------------------------
42 #------------------------------------------------------------------------------
43 ASM_GLOBAL ASM_PFX(SetCodeSelector)
44 ASM_PFX(SetCodeSelector):
47 leal setCodeSelectorLongJump, %eax
50 .byte 0xFF, 0x2C, 0x24 # jmp *(%esp) note:(FWORD jmp)
51 setCodeSelectorLongJump:
55 #------------------------------------------------------------------------------
60 #------------------------------------------------------------------------------
61 ASM_GLOBAL ASM_PFX(SetDataSelectors)
62 ASM_PFX(SetDataSelectors):
71 #---------------------------------------;
72 # CommonInterruptEntry ;
73 #---------------------------------------;
74 # The follow algorithm is used for the common interrupt routine.
76 ASM_GLOBAL ASM_PFX(CommonInterruptEntry)
77 ASM_PFX(CommonInterruptEntry):
80 # All interrupt handlers are invoked through interrupt gates, so
81 # IF flag automatically cleared at the entry point
85 # Calculate vector number
87 # Get the return address of call, actually, it is the
88 # address of vector number.
93 cmpl $32, %ecx # Intel reserved vector for exceptions?
95 bt %ecx, ASM_PFX(mErrorCodeFlag)
102 # +---------------------+
104 # +---------------------+
106 # +---------------------+
108 # +---------------------+
110 # +---------------------+ <-- ESP
113 # ECX - Vector Number
117 # Put Vector Number on stack
122 # Put 0 (dummy) error code on stack, and restore ECX
124 xorl %ecx, %ecx # ECX = 0
127 jmp ErrorCodeAndVectorOnStack
133 # +---------------------+
135 # +---------------------+
137 # +---------------------+
139 # +---------------------+
141 # +---------------------+
143 # +---------------------+ <-- ESP
146 # ECX - Vector Number
150 # Put Vector Number on stack and restore ECX
154 ErrorCodeAndVectorOnStack:
160 # +---------------------+
162 # +---------------------+
164 # +---------------------+
166 # +---------------------+
168 # +---------------------+
170 # +---------------------+
172 # +---------------------+ <-- EBP
176 # Align stack to make sure that EFI_FX_SAVE_STATE_IA32 of EFI_SYSTEM_CONTEXT_IA32
179 andl $0x0fffffff0, %esp
182 #; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
193 #; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
196 movzwl 16(%ebp), %eax
211 #; UINT32 Gdtr[2], Idtr[2];
237 #; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
251 #; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
265 #; FX_SAVE_STATE_IA32 FxSaveState;
268 .byte 0x0f, 0x0ae, 0x07 #fxsave [edi]
270 #; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear
273 #; UINT32 ExceptionData;
276 #; call into exception handler
277 movl ExternalVectorTablePtr, %eax # get the interrupt vectors base
278 orl %eax, %eax # NULL?
279 jz nullExternalExceptionHandler
282 movl (%eax,%ecx,4), %eax
283 orl %eax, %eax # NULL?
284 jz nullExternalExceptionHandler
286 #; Prepare parameter and call
293 # Call External Exception Handler
298 nullExternalExceptionHandler:
301 #; UINT32 ExceptionData;
304 #; FX_SAVE_STATE_IA32 FxSaveState;
306 .byte 0x0f, 0x0ae, 0x0e # fxrstor [esi]
309 #; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
310 #; Skip restoration of DRx registers to support in-circuit emualators
311 #; or debuggers set breakpoint in interrupt/exception context
314 #; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
317 addl $4, %esp # not for Cr1
329 #; UINT32 Gdtr[2], Idtr[2];
330 #; Best not let anyone mess with these particular registers...
336 #; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
337 #; NOTE - modified segment registers could hang the debugger... We
338 #; could attempt to insulate ourselves against this possibility,
339 #; but that poses risks as well.
348 #; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
351 addl $4, %esp # not for ebp
352 addl $4, %esp # not for esp