2 IA32 CPU Exception Hanlder functons.
4 Copyright (c) 2012 - 2013, 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.
15 #include "CpuExceptionCommon.h"
18 Return address map of exception handler template so that C code can generate
21 @param IdtEntry Pointer to IDT entry to be updated.
22 @param InterruptHandler IDT handler value.
27 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
,
28 IN UINTN InterruptHandler
31 IdtEntry
->Bits
.OffsetLow
= (UINT16
)(UINTN
)InterruptHandler
;
32 IdtEntry
->Bits
.OffsetHigh
= (UINT16
)((UINTN
)InterruptHandler
>> 16);
33 IdtEntry
->Bits
.GateType
= IA32_IDT_GATE_TYPE_INTERRUPT_32
;
37 Read IDT handler value from IDT entry.
39 @param IdtEntry Pointer to IDT entry to be read.
44 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
47 return (UINTN
)IdtEntry
->Bits
.OffsetLow
+ (((UINTN
)IdtEntry
->Bits
.OffsetHigh
) << 16);
51 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
53 @param ExceptionType Exception type.
54 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
58 ArchSaveExceptionContext (
59 IN UINTN ExceptionType
,
60 IN EFI_SYSTEM_CONTEXT SystemContext
65 // Save Exception context in global variable
67 mReservedVectors
[ExceptionType
].OldFlags
= SystemContext
.SystemContextIa32
->Eflags
;
68 mReservedVectors
[ExceptionType
].OldCs
= SystemContext
.SystemContextIa32
->Cs
;
69 mReservedVectors
[ExceptionType
].OldIp
= SystemContext
.SystemContextIa32
->Eip
;
70 mReservedVectors
[ExceptionType
].ExceptionData
= SystemContext
.SystemContextIa32
->ExceptionData
;
72 // Clear IF flag to avoid old IDT handler enable interrupt by IRET
74 Eflags
.UintN
= SystemContext
.SystemContextIa32
->Eflags
;
76 SystemContext
.SystemContextIa32
->Eflags
= Eflags
.UintN
;
78 // Modify the EIP in stack, then old IDT handler will return to the stub code
80 SystemContext
.SystemContextIa32
->Eip
= (UINTN
) mReservedVectors
[ExceptionType
].HookAfterStubHeaderCode
;
84 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
86 @param ExceptionType Exception type.
87 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
90 ArchRestoreExceptionContext (
91 IN UINTN ExceptionType
,
92 IN EFI_SYSTEM_CONTEXT SystemContext
95 SystemContext
.SystemContextIa32
->Eflags
= mReservedVectors
[ExceptionType
].OldFlags
;
96 SystemContext
.SystemContextIa32
->Cs
= mReservedVectors
[ExceptionType
].OldCs
;
97 SystemContext
.SystemContextIa32
->Eip
= mReservedVectors
[ExceptionType
].OldIp
;
98 SystemContext
.SystemContextIa32
->ExceptionData
= mReservedVectors
[ExceptionType
].ExceptionData
;
102 Display CPU information.
104 @param ExceptionType Exception type.
105 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
109 IN EFI_EXCEPTION_TYPE ExceptionType
,
110 IN EFI_SYSTEM_CONTEXT SystemContext
116 InternalPrintMessage (
117 "!!!! IA32 Exception Type - %08x CPU Apic ID - %08x !!!!\n",
121 InternalPrintMessage (
122 "EIP - %08x, CS - %08x, EFLAGS - %08x\n",
123 SystemContext
.SystemContextIa32
->Eip
,
124 SystemContext
.SystemContextIa32
->Cs
,
125 SystemContext
.SystemContextIa32
->Eflags
127 if ((mErrorCodeFlag
& (1 << ExceptionType
)) != 0) {
128 InternalPrintMessage (
129 "ExceptionData - %08x\n",
130 SystemContext
.SystemContextIa32
->ExceptionData
133 InternalPrintMessage (
134 "EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",
135 SystemContext
.SystemContextIa32
->Eax
,
136 SystemContext
.SystemContextIa32
->Ecx
,
137 SystemContext
.SystemContextIa32
->Edx
,
138 SystemContext
.SystemContextIa32
->Ebx
140 InternalPrintMessage (
141 "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x\n",
142 SystemContext
.SystemContextIa32
->Esp
,
143 SystemContext
.SystemContextIa32
->Ebp
,
144 SystemContext
.SystemContextIa32
->Esi
,
145 SystemContext
.SystemContextIa32
->Edi
147 InternalPrintMessage (
148 "DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x\n",
149 SystemContext
.SystemContextIa32
->Ds
,
150 SystemContext
.SystemContextIa32
->Es
,
151 SystemContext
.SystemContextIa32
->Fs
,
152 SystemContext
.SystemContextIa32
->Gs
,
153 SystemContext
.SystemContextIa32
->Ss
155 InternalPrintMessage (
156 "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x\n",
157 SystemContext
.SystemContextIa32
->Cr0
,
158 SystemContext
.SystemContextIa32
->Cr2
,
159 SystemContext
.SystemContextIa32
->Cr3
,
160 SystemContext
.SystemContextIa32
->Cr4
162 InternalPrintMessage (
163 "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x\n",
164 SystemContext
.SystemContextIa32
->Dr0
,
165 SystemContext
.SystemContextIa32
->Dr1
,
166 SystemContext
.SystemContextIa32
->Dr2
,
167 SystemContext
.SystemContextIa32
->Dr3
169 InternalPrintMessage (
170 "DR6 - %08x, DR7 - %08x\n",
171 SystemContext
.SystemContextIa32
->Dr6
,
172 SystemContext
.SystemContextIa32
->Dr7
174 InternalPrintMessage (
175 "GDTR - %08x %08x, IDTR - %08x %08x\n",
176 SystemContext
.SystemContextIa32
->Gdtr
[0],
177 SystemContext
.SystemContextIa32
->Gdtr
[1],
178 SystemContext
.SystemContextIa32
->Idtr
[0],
179 SystemContext
.SystemContextIa32
->Idtr
[1]
181 InternalPrintMessage (
182 "LDTR - %08x, TR - %08x\n",
183 SystemContext
.SystemContextIa32
->Ldtr
,
184 SystemContext
.SystemContextIa32
->Tr
186 InternalPrintMessage (
187 "FXSAVE_STATE - %08x\n",
188 &SystemContext
.SystemContextIa32
->FxSaveState
192 // Find module image base and module entry point by RIP
194 ImageBase
= FindModuleImageBase (SystemContext
.SystemContextIa32
->Eip
, &EntryPoint
);
195 if (ImageBase
!= 0) {
196 InternalPrintMessage (
197 " (ImageBase=%08x, EntryPoint=%08x) !!!!\n",