2 CPU exception handler library implementation for PEIM module.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 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.
16 #include "CpuExceptionCommon.h"
17 #include <Library/DebugLib.h>
18 #include <Library/HobLib.h>
19 #include <Library/MemoryAllocationLib.h>
22 // Image Alignment size for PEI phase
24 CONST UINTN mImageAlignSize
= 4;
25 CONST UINTN mDoFarReturnFlag
= 0;
27 EFI_GUID mCpuExceptrionHandlerLibHobGuid
= CPU_EXCEPTION_HANDLER_LIB_HOB_GUID
;
30 Get exception handler data pointer from GUIDed HOb.
32 @return pointer to exception handler data.
34 EXCEPTION_HANDLER_DATA
*
35 GetExceptionHandlerData (
39 EFI_HOB_GUID_TYPE
*GuidHob
;
41 EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
;
43 ExceptionHandlerData
= NULL
;
44 GuidHob
= GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid
);
45 if (GuidHob
!= NULL
) {
46 DataInHob
= GET_GUID_HOB_DATA (GuidHob
);
47 ExceptionHandlerData
= (EXCEPTION_HANDLER_DATA
*)(*(UINTN
*)DataInHob
);
49 ASSERT (ExceptionHandlerData
!= NULL
);
50 return ExceptionHandlerData
;
54 Common exception handler.
56 @param ExceptionType Exception type.
57 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
61 CommonExceptionHandler (
62 IN EFI_EXCEPTION_TYPE ExceptionType
,
63 IN EFI_SYSTEM_CONTEXT SystemContext
66 EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
;
68 ExceptionHandlerData
= GetExceptionHandlerData ();
69 CommonExceptionHandlerWorker (ExceptionType
, SystemContext
, ExceptionHandlerData
);
73 Initializes all CPU exceptions entries and provides the default exception handlers.
75 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
76 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
77 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
78 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
79 Note: Before invoking this API, caller must allocate memory for IDT table and load
80 IDTR by AsmWriteIdtr().
82 @param[in] VectorInfo Pointer to reserved vector list.
84 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
85 with default exception handlers.
86 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
87 @retval EFI_UNSUPPORTED This function is not supported.
92 InitializeCpuExceptionHandlers (
93 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
97 EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
;
98 RESERVED_VECTORS_DATA
*ReservedVectors
;
100 ReservedVectors
= AllocatePool (sizeof (RESERVED_VECTORS_DATA
) * CPU_EXCEPTION_NUM
);
101 ASSERT (ReservedVectors
!= NULL
);
103 ExceptionHandlerData
= AllocatePool (sizeof (EXCEPTION_HANDLER_DATA
));
104 ASSERT (ExceptionHandlerData
!= NULL
);
105 ExceptionHandlerData
->ReservedVectors
= ReservedVectors
;
106 ExceptionHandlerData
->ExternalInterruptHandler
= NULL
;
107 InitializeSpinLock (&ExceptionHandlerData
->DisplayMessageSpinLock
);
109 Status
= InitializeCpuExceptionHandlersWorker (VectorInfo
, ExceptionHandlerData
);
110 if (EFI_ERROR (Status
)) {
111 FreePool (ReservedVectors
);
112 FreePool (ExceptionHandlerData
);
117 // Build location of CPU MP DATA buffer in HOB
120 &mCpuExceptrionHandlerLibHobGuid
,
121 (VOID
*)&ExceptionHandlerData
,
129 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
131 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
132 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
133 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
134 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
136 @param[in] VectorInfo Pointer to reserved vector list.
138 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized
139 with default interrupt/exception handlers.
140 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
141 @retval EFI_UNSUPPORTED This function is not supported.
146 InitializeCpuInterruptHandlers (
147 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
150 return EFI_UNSUPPORTED
;
154 Registers a function to be called from the processor interrupt handler.
156 This function registers and enables the handler specified by InterruptHandler for a processor
157 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
158 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
159 The installed handler is called once for each processor interrupt or exception.
160 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
161 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
163 @param[in] InterruptType Defines which interrupt or exception to hook.
164 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
165 when a processor interrupt occurs. If this parameter is NULL, then the handler
168 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
169 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
170 previously installed.
171 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
172 previously installed.
173 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
174 or this function is not supported.
178 RegisterCpuInterruptHandler (
179 IN EFI_EXCEPTION_TYPE InterruptType
,
180 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
183 return EFI_UNSUPPORTED
;