TianoCore EDK2 master
Loading...
Searching...
No Matches
SecPeiCpuException.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10#include <Library/CcExitLib.h>
11#include "CpuExceptionCommon.h"
12
13CONST UINTN mDoFarReturnFlag = 0;
14
21VOID
22EFIAPI
24 IN EFI_EXCEPTION_TYPE ExceptionType,
25 IN EFI_SYSTEM_CONTEXT SystemContext
26 )
27{
28 EFI_STATUS Status;
29
30 switch (ExceptionType) {
31 case VC_EXCEPTION:
32 //
33 // #VC needs to be handled immediately upon enabling exception handling
34 // and therefore can't use the RegisterCpuInterruptHandler() interface
35 // (which isn't supported under Sec and Pei anyway).
36 //
37 // Handle the #VC:
38 // On EFI_SUCCESS - Exception has been handled, return
39 // On other - ExceptionType contains (possibly new) exception
40 // value
41 //
42 Status = CcExitHandleVc (&ExceptionType, SystemContext);
43 if (!EFI_ERROR (Status)) {
44 return;
45 }
46
47 break;
48
49 case VE_EXCEPTION:
50 //
51 // #VE needs to be handled immediately upon enabling exception handling
52 // and therefore can't use the RegisterCpuInterruptHandler() interface
53 // (which isn't supported under Sec and Pei anyway).
54 //
55 // Handle the #VE:
56 // On EFI_SUCCESS - Exception has been handled, return
57 // On other - ExceptionType contains (possibly new) exception
58 // value
59 //
60 Status = CcExitHandleVe (&ExceptionType, SystemContext);
61 if (!EFI_ERROR (Status)) {
62 return;
63 }
64
65 break;
66
67 default:
68 break;
69 }
70
71 //
72 // Initialize the serial port before dumping.
73 //
75 //
76 // Display ExceptionType, CPU information and Image information
77 //
78 DumpImageAndCpuContent (ExceptionType, SystemContext);
79
80 //
81 // Enter a dead loop.
82 //
83 CpuDeadLoop ();
84}
85
105EFIAPI
107 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
108 )
109{
110 EFI_STATUS Status;
111 RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];
112 IA32_DESCRIPTOR IdtDescriptor;
113 UINTN IdtEntryCount;
114 UINT16 CodeSegment;
116 IA32_IDT_GATE_DESCRIPTOR *IdtTable;
117 UINTN Index;
118 UINTN InterruptHandler;
119
120 if (VectorInfo != NULL) {
121 SetMem ((VOID *)ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
122 Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);
123 if (EFI_ERROR (Status)) {
124 return EFI_INVALID_PARAMETER;
125 }
126 }
127
128 //
129 // Read IDT descriptor and calculate IDT size
130 //
131 AsmReadIdtr (&IdtDescriptor);
132 IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);
133 if (IdtEntryCount > CPU_EXCEPTION_NUM) {
134 //
135 // CPU exception library only setup CPU_EXCEPTION_NUM exception handler at most
136 //
137 IdtEntryCount = CPU_EXCEPTION_NUM;
138 }
139
140 //
141 // Use current CS as the segment selector of interrupt gate in IDT
142 //
143 CodeSegment = AsmReadCs ();
144
145 AsmGetTemplateAddressMap (&TemplateMap);
146 IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
147 for (Index = 0; Index < IdtEntryCount; Index++) {
148 IdtTable[Index].Bits.Selector = CodeSegment;
149 //
150 // Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK
151 // supported in this instance
152 //
153 if (VectorInfo != NULL) {
154 if (ReservedVectorData[Index].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {
155 continue;
156 }
157 }
158
159 //
160 // Update IDT entry
161 //
162 InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;
163 ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
164 }
165
166 return EFI_SUCCESS;
167}
168
193EFIAPI
195 IN EFI_EXCEPTION_TYPE InterruptType,
196 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
197 )
198{
199 return EFI_UNSUPPORTED;
200}
201
217EFIAPI
219 IN VOID *Buffer,
220 IN OUT UINTN *BufferSize
221 )
222{
223 return EFI_UNSUPPORTED;
224}
UINT64 UINTN
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
Definition: SerialPortLib.c:25
VOID EFIAPI CpuDeadLoop(VOID)
Definition: CpuDeadLoop.c:25
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
EFI_STATUS EFIAPI CcExitHandleVe(IN OUT EFI_EXCEPTION_TYPE *ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
VOID(EFIAPI * EFI_CPU_INTERRUPT_HANDLER)(IN CONST EFI_EXCEPTION_TYPE InterruptType, IN CONST EFI_SYSTEM_CONTEXT SystemContext)
Definition: Cpu.h:52
EFI_STATUS ReadAndVerifyVectorInfo(IN EFI_VECTOR_HANDOFF_INFO *VectorInfo, OUT RESERVED_VECTORS_DATA *ReservedVector, IN UINTN VectorCount)
VOID DumpImageAndCpuContent(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
VOID EFIAPI AsmGetTemplateAddressMap(OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap)
VOID ArchUpdateIdtEntry(OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry, IN UINTN InterruptHandler)
UINT16 EFIAPI AsmReadCs(VOID)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
EFI_STATUS EFIAPI CcExitHandleVc(IN OUT EFI_EXCEPTION_TYPE *ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_STATUS EFIAPI InitializeSeparateExceptionStacks(IN VOID *Buffer, IN OUT UINTN *BufferSize)
EFI_STATUS EFIAPI InitializeCpuExceptionHandlers(IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL)
EFI_STATUS EFIAPI RegisterCpuInterruptHandler(IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler)
VOID EFIAPI CommonExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define EFI_VECTOR_HANDOFF_DO_NOT_HOOK
VOID EFIAPI AsmReadIdtr(OUT IA32_DESCRIPTOR *Idtr)
Definition: X86ReadIdtr.c:24