2 IA32 CPU Exception Handler functons.
4 Copyright (c) 2012 - 2017, 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[in] ExceptionType Exception type.
54 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
55 @param[in] ExceptionHandlerData Pointer to exception handler data.
58 ArchSaveExceptionContext (
59 IN UINTN ExceptionType
,
60 IN EFI_SYSTEM_CONTEXT SystemContext
,
61 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
65 RESERVED_VECTORS_DATA
*ReservedVectors
;
67 ReservedVectors
= ExceptionHandlerData
->ReservedVectors
;
69 // Save Exception context in global variable
71 ReservedVectors
[ExceptionType
].OldFlags
= SystemContext
.SystemContextIa32
->Eflags
;
72 ReservedVectors
[ExceptionType
].OldCs
= SystemContext
.SystemContextIa32
->Cs
;
73 ReservedVectors
[ExceptionType
].OldIp
= SystemContext
.SystemContextIa32
->Eip
;
74 ReservedVectors
[ExceptionType
].ExceptionData
= SystemContext
.SystemContextIa32
->ExceptionData
;
76 // Clear IF flag to avoid old IDT handler enable interrupt by IRET
78 Eflags
.UintN
= SystemContext
.SystemContextIa32
->Eflags
;
80 SystemContext
.SystemContextIa32
->Eflags
= Eflags
.UintN
;
82 // Modify the EIP in stack, then old IDT handler will return to the stub code
84 SystemContext
.SystemContextIa32
->Eip
= (UINTN
) ReservedVectors
[ExceptionType
].HookAfterStubHeaderCode
;
88 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
90 @param[in] ExceptionType Exception type.
91 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
92 @param[in] ExceptionHandlerData Pointer to exception handler data.
95 ArchRestoreExceptionContext (
96 IN UINTN ExceptionType
,
97 IN EFI_SYSTEM_CONTEXT SystemContext
,
98 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
101 RESERVED_VECTORS_DATA
*ReservedVectors
;
103 ReservedVectors
= ExceptionHandlerData
->ReservedVectors
;
104 SystemContext
.SystemContextIa32
->Eflags
= ReservedVectors
[ExceptionType
].OldFlags
;
105 SystemContext
.SystemContextIa32
->Cs
= ReservedVectors
[ExceptionType
].OldCs
;
106 SystemContext
.SystemContextIa32
->Eip
= ReservedVectors
[ExceptionType
].OldIp
;
107 SystemContext
.SystemContextIa32
->ExceptionData
= ReservedVectors
[ExceptionType
].ExceptionData
;
111 Display processor context.
113 @param[in] ExceptionType Exception type.
114 @param[in] SystemContext Processor context to be display.
119 IN EFI_EXCEPTION_TYPE ExceptionType
,
120 IN EFI_SYSTEM_CONTEXT SystemContext
123 InternalPrintMessage (
124 "!!!! IA32 Exception Type - %02x(%a) CPU Apic ID - %08x !!!!\n",
126 GetExceptionNameStr (ExceptionType
),
129 if ((mErrorCodeFlag
& (1 << ExceptionType
)) != 0) {
130 InternalPrintMessage (
131 "ExceptionData - %08x",
132 SystemContext
.SystemContextIa32
->ExceptionData
134 if (ExceptionType
== EXCEPT_IA32_PAGE_FAULT
) {
135 InternalPrintMessage (
136 " I:%x R:%x U:%x W:%x P:%x PK:%x S:%x",
137 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_ID
) != 0,
138 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_RSVD
) != 0,
139 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_US
) != 0,
140 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_WR
) != 0,
141 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_P
) != 0,
142 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_PK
) != 0,
143 (SystemContext
.SystemContextIa32
->ExceptionData
& IA32_PF_EC_SGX
) != 0
146 InternalPrintMessage ("\n");
148 InternalPrintMessage (
149 "EIP - %08x, CS - %08x, EFLAGS - %08x\n",
150 SystemContext
.SystemContextIa32
->Eip
,
151 SystemContext
.SystemContextIa32
->Cs
,
152 SystemContext
.SystemContextIa32
->Eflags
154 InternalPrintMessage (
155 "EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",
156 SystemContext
.SystemContextIa32
->Eax
,
157 SystemContext
.SystemContextIa32
->Ecx
,
158 SystemContext
.SystemContextIa32
->Edx
,
159 SystemContext
.SystemContextIa32
->Ebx
161 InternalPrintMessage (
162 "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x\n",
163 SystemContext
.SystemContextIa32
->Esp
,
164 SystemContext
.SystemContextIa32
->Ebp
,
165 SystemContext
.SystemContextIa32
->Esi
,
166 SystemContext
.SystemContextIa32
->Edi
168 InternalPrintMessage (
169 "DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x\n",
170 SystemContext
.SystemContextIa32
->Ds
,
171 SystemContext
.SystemContextIa32
->Es
,
172 SystemContext
.SystemContextIa32
->Fs
,
173 SystemContext
.SystemContextIa32
->Gs
,
174 SystemContext
.SystemContextIa32
->Ss
176 InternalPrintMessage (
177 "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x\n",
178 SystemContext
.SystemContextIa32
->Cr0
,
179 SystemContext
.SystemContextIa32
->Cr2
,
180 SystemContext
.SystemContextIa32
->Cr3
,
181 SystemContext
.SystemContextIa32
->Cr4
183 InternalPrintMessage (
184 "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x\n",
185 SystemContext
.SystemContextIa32
->Dr0
,
186 SystemContext
.SystemContextIa32
->Dr1
,
187 SystemContext
.SystemContextIa32
->Dr2
,
188 SystemContext
.SystemContextIa32
->Dr3
190 InternalPrintMessage (
191 "DR6 - %08x, DR7 - %08x\n",
192 SystemContext
.SystemContextIa32
->Dr6
,
193 SystemContext
.SystemContextIa32
->Dr7
195 InternalPrintMessage (
196 "GDTR - %08x %08x, IDTR - %08x %08x\n",
197 SystemContext
.SystemContextIa32
->Gdtr
[0],
198 SystemContext
.SystemContextIa32
->Gdtr
[1],
199 SystemContext
.SystemContextIa32
->Idtr
[0],
200 SystemContext
.SystemContextIa32
->Idtr
[1]
202 InternalPrintMessage (
203 "LDTR - %08x, TR - %08x\n",
204 SystemContext
.SystemContextIa32
->Ldtr
,
205 SystemContext
.SystemContextIa32
->Tr
207 InternalPrintMessage (
208 "FXSAVE_STATE - %08x\n",
209 &SystemContext
.SystemContextIa32
->FxSaveState
214 Display CPU information.
216 @param ExceptionType Exception type.
217 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
220 DumpImageAndCpuContent (
221 IN EFI_EXCEPTION_TYPE ExceptionType
,
222 IN EFI_SYSTEM_CONTEXT SystemContext
225 DumpCpuContext (ExceptionType
, SystemContext
);
227 // Dump module image base and module entry point by EIP
229 DumpModuleImageInfo (SystemContext
.SystemContextIa32
->Eip
);