]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
UefiCpuPkg/CpuExceptionHandler: Init serial port before context dump
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / SecPeiCpuException.c
CommitLineData
8f07f895 1/** @file\r
e41aad15 2 CPU exception handler library implemenation for SEC/PEIM modules.\r
8f07f895 3\r
7230212a 4Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>\r
8f07f895 5This program and the accompanying materials are licensed and made available under\r
6the terms and conditions of the BSD License that accompanies this distribution.\r
7The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php.\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include "CpuExceptionCommon.h"\r
17\r
e41aad15 18CONST UINTN mDoFarReturnFlag = 0;\r
8f07f895 19\r
20/**\r
21 Common exception handler.\r
22\r
23 @param ExceptionType Exception type.\r
24 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
25**/\r
26VOID\r
27EFIAPI\r
28CommonExceptionHandler (\r
dd563742 29 IN EFI_EXCEPTION_TYPE ExceptionType,\r
8f07f895 30 IN EFI_SYSTEM_CONTEXT SystemContext\r
31 )\r
32{\r
7230212a
RN
33 //\r
34 // Initialize the serial port before dumping.\r
35 //\r
36 SerialPortInitialize ();\r
8f07f895 37 //\r
38 // Display ExceptionType, CPU information and Image information\r
dd563742 39 //\r
1b2f7b3e 40 DumpImageAndCpuContent (ExceptionType, SystemContext);\r
dd563742 41\r
8f07f895 42 //\r
43 // Enter a dead loop.\r
44 //\r
45 CpuDeadLoop ();\r
46}\r
47\r
48/**\r
e41aad15 49 Initializes all CPU exceptions entries and provides the default exception handlers.\r
dd563742 50\r
e41aad15
JF
51 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
52 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
dd563742 53 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r
e41aad15 54 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
dd563742 55 Note: Before invoking this API, caller must allocate memory for IDT table and load\r
a9c7ab95 56 IDTR by AsmWriteIdtr().\r
e41aad15
JF
57\r
58 @param[in] VectorInfo Pointer to reserved vector list.\r
dd563742
JF
59\r
60 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized\r
e41aad15
JF
61 with default exception handlers.\r
62 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
63 @retval EFI_UNSUPPORTED This function is not supported.\r
64\r
8f07f895 65**/\r
e41aad15
JF
66EFI_STATUS\r
67EFIAPI\r
68InitializeCpuExceptionHandlers (\r
69 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
70 )\r
71{\r
dd563742 72 EFI_STATUS Status;\r
e41aad15
JF
73 RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];\r
74 IA32_DESCRIPTOR IdtDescriptor;\r
75 UINTN IdtEntryCount;\r
76 UINT16 CodeSegment;\r
77 EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;\r
78 IA32_IDT_GATE_DESCRIPTOR *IdtTable;\r
79 UINTN Index;\r
80 UINTN InterruptHandler;\r
81\r
82 if (VectorInfo != NULL) {\r
83 SetMem ((VOID *) ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);\r
84 Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);\r
85 if (EFI_ERROR (Status)) {\r
86 return EFI_INVALID_PARAMETER;\r
87 }\r
88 }\r
89 //\r
90 // Read IDT descriptor and calculate IDT size\r
91 //\r
92 AsmReadIdtr (&IdtDescriptor);\r
93 IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);\r
94 if (IdtEntryCount > CPU_EXCEPTION_NUM) {\r
95 //\r
96 // CPU exeption library only setup CPU_EXCEPTION_NUM exception handler at most\r
97 //\r
98 IdtEntryCount = CPU_EXCEPTION_NUM;\r
99 }\r
100 //\r
101 // Use current CS as the segment selector of interrupt gate in IDT\r
102 //\r
103 CodeSegment = AsmReadCs ();\r
104\r
105 AsmGetTemplateAddressMap (&TemplateMap);\r
106 IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;\r
107 for (Index = 0; Index < IdtEntryCount; Index ++) {\r
108 IdtTable[Index].Bits.Selector = CodeSegment;\r
109 //\r
110 // Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK\r
111 // supported in this instance\r
112 //\r
113 if (VectorInfo != NULL) {\r
114 if (ReservedVectorData[Index].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {\r
115 continue;\r
116 }\r
117 }\r
118 //\r
119 // Update IDT entry\r
120 //\r
121 InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;\r
122 ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);\r
123 }\r
124 return EFI_SUCCESS;\r
125}\r
126\r
127/**\r
128 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
dd563742 129\r
e41aad15
JF
130 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
131 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
dd563742 132 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r
e41aad15
JF
133 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
134\r
135 @param[in] VectorInfo Pointer to reserved vector list.\r
dd563742
JF
136\r
137 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized\r
e41aad15
JF
138 with default interrupt/exception handlers.\r
139 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
140 @retval EFI_UNSUPPORTED This function is not supported.\r
141\r
142**/\r
143EFI_STATUS\r
8f07f895 144EFIAPI\r
e41aad15
JF
145InitializeCpuInterruptHandlers (\r
146 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
8f07f895 147 )\r
148{\r
e41aad15 149 return EFI_UNSUPPORTED;\r
8f07f895 150}\r
e41aad15
JF
151\r
152/**\r
153 Registers a function to be called from the processor interrupt handler.\r
154\r
dd563742
JF
155 This function registers and enables the handler specified by InterruptHandler for a processor\r
156 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r
157 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r
e41aad15
JF
158 The installed handler is called once for each processor interrupt or exception.\r
159 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
160 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
161\r
162 @param[in] InterruptType Defines which interrupt or exception to hook.\r
163 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
164 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
165 will be uninstalled.\r
166\r
167 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
168 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
169 previously installed.\r
170 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
171 previously installed.\r
172 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
173 or this function is not supported.\r
3f25e6ea 174**/\r
e41aad15
JF
175EFI_STATUS\r
176EFIAPI\r
177RegisterCpuInterruptHandler (\r
178 IN EFI_EXCEPTION_TYPE InterruptType,\r
179 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
180 )\r
181{\r
182 return EFI_UNSUPPORTED;\r
0ff5aa9c
JW
183}\r
184\r
185/**\r
186 Initializes all CPU exceptions entries with optional extra initializations.\r
187\r
188 By default, this method should include all functionalities implemented by\r
189 InitializeCpuExceptionHandlers(), plus extra initialization works, if any.\r
190 This could be done by calling InitializeCpuExceptionHandlers() directly\r
191 in this method besides the extra works.\r
192\r
193 InitData is optional and its use and content are processor arch dependent.\r
194 The typical usage of it is to convey resources which have to be reserved\r
195 elsewhere and are necessary for the extra initializations of exception.\r
196\r
197 @param[in] VectorInfo Pointer to reserved vector list.\r
198 @param[in] InitData Pointer to data optional for extra initializations\r
199 of exception.\r
200\r
201 @retval EFI_SUCCESS The exceptions have been successfully\r
202 initialized.\r
203 @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid\r
204 content.\r
205\r
206**/\r
207EFI_STATUS\r
208EFIAPI\r
209InitializeCpuExceptionHandlersEx (\r
210 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r
211 IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL\r
212 )\r
213{\r
214 return InitializeCpuExceptionHandlers (VectorInfo);\r
215}\r