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