]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
UefiCpuPkg/CpuExceptionHandlerLib: Add DumpCpuContext() implementation
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / PeiCpuException.c
CommitLineData
a81abf16
JF
1/** @file\r
2 CPU exception handler library implementation for PEIM module.\r
3\r
1b2f7b3e 4Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
a81abf16
JF
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#include <Library/DebugLib.h>\r
18#include <Library/HobLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20\r
a81abf16
JF
21CONST UINTN mDoFarReturnFlag = 0;\r
22\r
23EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r
24\r
25/**\r
26 Get exception handler data pointer from GUIDed HOb.\r
27\r
28 @return pointer to exception handler data. \r
29**/\r
30EXCEPTION_HANDLER_DATA *\r
31GetExceptionHandlerData (\r
32 VOID\r
33 )\r
34{\r
35 EFI_HOB_GUID_TYPE *GuidHob;\r
36 VOID *DataInHob;\r
37 EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
38\r
39 ExceptionHandlerData = NULL;\r
40 GuidHob = GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid);\r
41 if (GuidHob != NULL) {\r
42 DataInHob = GET_GUID_HOB_DATA (GuidHob);\r
43 ExceptionHandlerData = (EXCEPTION_HANDLER_DATA *)(*(UINTN *)DataInHob);\r
44 }\r
45 ASSERT (ExceptionHandlerData != NULL);\r
46 return ExceptionHandlerData;\r
47}\r
48\r
49/**\r
50 Common exception handler.\r
51\r
52 @param ExceptionType Exception type.\r
53 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
54**/\r
55VOID\r
56EFIAPI\r
57CommonExceptionHandler (\r
58 IN EFI_EXCEPTION_TYPE ExceptionType, \r
59 IN EFI_SYSTEM_CONTEXT SystemContext\r
60 )\r
61{\r
62 EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
63\r
64 ExceptionHandlerData = GetExceptionHandlerData ();\r
65 CommonExceptionHandlerWorker (ExceptionType, SystemContext, ExceptionHandlerData);\r
66}\r
67\r
68/**\r
69 Initializes all CPU exceptions entries and provides the default exception handlers.\r
70 \r
71 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
72 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
73 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
74 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
75 Note: Before invoking this API, caller must allocate memory for IDT table and load \r
76 IDTR by AsmWriteIdtr().\r
77\r
78 @param[in] VectorInfo Pointer to reserved vector list.\r
79 \r
80 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r
81 with default exception handlers.\r
82 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
83 @retval EFI_UNSUPPORTED This function is not supported.\r
84\r
85**/\r
86EFI_STATUS\r
87EFIAPI\r
88InitializeCpuExceptionHandlers (\r
89 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
90 )\r
91{\r
92 EFI_STATUS Status;\r
93 EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
94 RESERVED_VECTORS_DATA *ReservedVectors;\r
95\r
96 ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);\r
97 ASSERT (ReservedVectors != NULL);\r
98\r
99 ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));\r
100 ASSERT (ExceptionHandlerData != NULL);\r
101 ExceptionHandlerData->ReservedVectors = ReservedVectors;\r
102 ExceptionHandlerData->ExternalInterruptHandler = NULL;\r
103 InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);\r
104\r
105 Status = InitializeCpuExceptionHandlersWorker (VectorInfo, ExceptionHandlerData);\r
106 if (EFI_ERROR (Status)) {\r
107 FreePool (ReservedVectors);\r
108 FreePool (ExceptionHandlerData);\r
109 return Status;\r
110 }\r
111\r
112 //\r
113 // Build location of CPU MP DATA buffer in HOB\r
114 //\r
115 BuildGuidDataHob (\r
116 &mCpuExceptrionHandlerLibHobGuid,\r
117 (VOID *)&ExceptionHandlerData,\r
118 sizeof(UINT64)\r
119 );\r
120\r
121 return EFI_SUCCESS;\r
122}\r
123\r
124/**\r
125 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
126 \r
127 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
128 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
129 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
130 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
131\r
132 @param[in] VectorInfo Pointer to reserved vector list.\r
133 \r
134 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized \r
135 with default interrupt/exception handlers.\r
136 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
137 @retval EFI_UNSUPPORTED This function is not supported.\r
138\r
139**/\r
140EFI_STATUS\r
141EFIAPI\r
142InitializeCpuInterruptHandlers (\r
143 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
144 )\r
145{\r
146 return EFI_UNSUPPORTED;\r
147}\r
148\r
149/**\r
150 Registers a function to be called from the processor interrupt handler.\r
151\r
152 This function registers and enables the handler specified by InterruptHandler for a processor \r
153 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r
154 handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r
155 The installed handler is called once for each processor interrupt or exception.\r
156 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
157 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
158\r
159 @param[in] InterruptType Defines which interrupt or exception to hook.\r
160 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
161 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
162 will be uninstalled.\r
163\r
164 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
165 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
166 previously installed.\r
167 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
168 previously installed.\r
169 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
170 or this function is not supported.\r
171**/\r
172EFI_STATUS\r
173EFIAPI\r
174RegisterCpuInterruptHandler (\r
175 IN EFI_EXCEPTION_TYPE InterruptType,\r
176 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
177 )\r
178{\r
179 return EFI_UNSUPPORTED;\r
180}