1 #------------------------------------------------------------------------------
3 #* Copyright (c) 2006 - 2010, 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
155 # Fall through to join main routine code
156 # at ErrorCodeAndVectorOnStack
158 CommonInterruptEntry_al_0000:
159 jmp CommonInterruptEntry_al_0000
161 ErrorCodeAndVectorOnStack:
167 # +---------------------+
169 # +---------------------+
171 # +---------------------+
173 # +---------------------+
175 # +---------------------+
177 # +---------------------+
179 # +---------------------+ <-- EBP
183 # Align stack to make sure that EFI_FX_SAVE_STATE_IA32 of EFI_SYSTEM_CONTEXT_IA32
186 andl $0x0fffffff0, %esp
189 #; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
200 #; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
203 movzwl 16(%ebp), %eax
218 #; UINT32 Gdtr[2], Idtr[2];
244 #; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
258 #; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
272 #; FX_SAVE_STATE_IA32 FxSaveState;
275 .byte 0x0f, 0x0ae, 0x07 #fxsave [edi]
277 #; UINT32 ExceptionData;
280 #; call into exception handler
281 movl ExternalVectorTablePtr, %eax # get the interrupt vectors base
282 orl %eax, %eax # NULL?
283 jz nullExternalExceptionHandler
286 movl (%eax,%ecx,4), %eax
287 orl %eax, %eax # NULL?
288 jz nullExternalExceptionHandler
290 #; Prepare parameter and call
297 # Call External Exception Handler
302 nullExternalExceptionHandler:
305 #; UINT32 ExceptionData;
308 #; FX_SAVE_STATE_IA32 FxSaveState;
310 .byte 0x0f, 0x0ae, 0x0e # fxrstor [esi]
313 #; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
314 #; Skip restoration of DRx registers to support in-circuit emualators
315 #; or debuggers set breakpoint in interrupt/exception context
318 #; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
321 addl $4, %esp # not for Cr1
333 #; UINT32 Gdtr[2], Idtr[2];
334 #; Best not let anyone mess with these particular registers...
340 #; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
341 #; NOTE - modified segment registers could hang the debugger... We
342 #; could attempt to insulate ourselves against this possibility,
343 #; but that poses risks as well.
352 #; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
355 addl $4, %esp # not for ebp
356 addl $4, %esp # not for esp