2 CPU exception handler library implementation for PEIM module.
4 Copyright (c) 2016 - 2017, 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>
21 CONST UINTN mDoFarReturnFlag
= 0;
23 EFI_GUID mCpuExceptrionHandlerLibHobGuid
= CPU_EXCEPTION_HANDLER_LIB_HOB_GUID
;
26 Get exception handler data pointer from GUIDed HOb.
28 @return pointer to exception handler data.
30 EXCEPTION_HANDLER_DATA
*
31 GetExceptionHandlerData (
35 EFI_HOB_GUID_TYPE
*GuidHob
;
37 EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
;
39 ExceptionHandlerData
= NULL
;
40 GuidHob
= GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid
);
41 if (GuidHob
!= NULL
) {
42 DataInHob
= GET_GUID_HOB_DATA (GuidHob
);
43 ExceptionHandlerData
= (EXCEPTION_HANDLER_DATA
*)(*(UINTN
*)DataInHob
);
45 ASSERT (ExceptionHandlerData
!= NULL
);
46 return ExceptionHandlerData
;
50 Common exception handler.
52 @param ExceptionType Exception type.
53 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
57 CommonExceptionHandler (
58 IN EFI_EXCEPTION_TYPE ExceptionType
,
59 IN EFI_SYSTEM_CONTEXT SystemContext
62 EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
;
64 ExceptionHandlerData
= GetExceptionHandlerData ();
65 CommonExceptionHandlerWorker (ExceptionType
, SystemContext
, ExceptionHandlerData
);
69 Initializes all CPU exceptions entries and provides the default exception handlers.
71 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
72 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
73 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
74 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
75 Note: Before invoking this API, caller must allocate memory for IDT table and load
76 IDTR by AsmWriteIdtr().
78 @param[in] VectorInfo Pointer to reserved vector list.
80 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
81 with default exception handlers.
82 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
83 @retval EFI_UNSUPPORTED This function is not supported.
88 InitializeCpuExceptionHandlers (
89 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
93 EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
;
94 RESERVED_VECTORS_DATA
*ReservedVectors
;
96 ReservedVectors
= AllocatePool (sizeof (RESERVED_VECTORS_DATA
) * CPU_EXCEPTION_NUM
);
97 ASSERT (ReservedVectors
!= NULL
);
99 ExceptionHandlerData
= AllocatePool (sizeof (EXCEPTION_HANDLER_DATA
));
100 ASSERT (ExceptionHandlerData
!= NULL
);
101 ExceptionHandlerData
->ReservedVectors
= ReservedVectors
;
102 ExceptionHandlerData
->ExternalInterruptHandler
= NULL
;
103 InitializeSpinLock (&ExceptionHandlerData
->DisplayMessageSpinLock
);
105 Status
= InitializeCpuExceptionHandlersWorker (VectorInfo
, ExceptionHandlerData
);
106 if (EFI_ERROR (Status
)) {
107 FreePool (ReservedVectors
);
108 FreePool (ExceptionHandlerData
);
113 // Build location of CPU MP DATA buffer in HOB
116 &mCpuExceptrionHandlerLibHobGuid
,
117 (VOID
*)&ExceptionHandlerData
,
125 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
127 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
128 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
129 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
130 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
132 @param[in] VectorInfo Pointer to reserved vector list.
134 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized
135 with default interrupt/exception handlers.
136 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
137 @retval EFI_UNSUPPORTED This function is not supported.
142 InitializeCpuInterruptHandlers (
143 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
146 return EFI_UNSUPPORTED
;
150 Registers a function to be called from the processor interrupt handler.
152 This function registers and enables the handler specified by InterruptHandler for a processor
153 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
154 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
155 The installed handler is called once for each processor interrupt or exception.
156 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
157 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
159 @param[in] InterruptType Defines which interrupt or exception to hook.
160 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
161 when a processor interrupt occurs. If this parameter is NULL, then the handler
164 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
165 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
166 previously installed.
167 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
168 previously installed.
169 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
170 or this function is not supported.
174 RegisterCpuInterruptHandler (
175 IN EFI_EXCEPTION_TYPE InterruptType
,
176 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
179 return EFI_UNSUPPORTED
;