--- /dev/null
+/** @file\r
+ CPU exception handler library implementation for PEIM module.\r
+\r
+Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include "CpuExceptionCommon.h"\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+//\r
+// Image Alignment size for PEI phase\r
+//\r
+CONST UINTN mImageAlignSize = 4;\r
+CONST UINTN mDoFarReturnFlag = 0;\r
+\r
+EFI_GUID mCpuExceptrionHandlerLibHobGuid = CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;\r
+\r
+/**\r
+ Get exception handler data pointer from GUIDed HOb.\r
+\r
+ @return pointer to exception handler data. \r
+**/\r
+EXCEPTION_HANDLER_DATA *\r
+GetExceptionHandlerData (\r
+ VOID\r
+ )\r
+{\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+ VOID *DataInHob;\r
+ EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
+\r
+ ExceptionHandlerData = NULL;\r
+ GuidHob = GetFirstGuidHob (&mCpuExceptrionHandlerLibHobGuid);\r
+ if (GuidHob != NULL) {\r
+ DataInHob = GET_GUID_HOB_DATA (GuidHob);\r
+ ExceptionHandlerData = (EXCEPTION_HANDLER_DATA *)(*(UINTN *)DataInHob);\r
+ }\r
+ ASSERT (ExceptionHandlerData != NULL);\r
+ return ExceptionHandlerData;\r
+}\r
+\r
+/**\r
+ Common exception handler.\r
+\r
+ @param ExceptionType Exception type.\r
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
+**/\r
+VOID\r
+EFIAPI\r
+CommonExceptionHandler (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType, \r
+ IN EFI_SYSTEM_CONTEXT SystemContext\r
+ )\r
+{\r
+ EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
+\r
+ ExceptionHandlerData = GetExceptionHandlerData ();\r
+ CommonExceptionHandlerWorker (ExceptionType, SystemContext, ExceptionHandlerData);\r
+}\r
+\r
+/**\r
+ Initializes all CPU exceptions entries and provides the default exception handlers.\r
+ \r
+ Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
+ persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
+ If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
+ If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
+ Note: Before invoking this API, caller must allocate memory for IDT table and load \r
+ IDTR by AsmWriteIdtr().\r
+\r
+ @param[in] VectorInfo Pointer to reserved vector list.\r
+ \r
+ @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r
+ with default exception handlers.\r
+ @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
+ @retval EFI_UNSUPPORTED This function is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpuExceptionHandlers (\r
+ IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EXCEPTION_HANDLER_DATA *ExceptionHandlerData;\r
+ RESERVED_VECTORS_DATA *ReservedVectors;\r
+\r
+ ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);\r
+ ASSERT (ReservedVectors != NULL);\r
+\r
+ ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));\r
+ ASSERT (ExceptionHandlerData != NULL);\r
+ ExceptionHandlerData->ReservedVectors = ReservedVectors;\r
+ ExceptionHandlerData->ExternalInterruptHandler = NULL;\r
+ InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);\r
+\r
+ Status = InitializeCpuExceptionHandlersWorker (VectorInfo, ExceptionHandlerData);\r
+ if (EFI_ERROR (Status)) {\r
+ FreePool (ReservedVectors);\r
+ FreePool (ExceptionHandlerData);\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Build location of CPU MP DATA buffer in HOB\r
+ //\r
+ BuildGuidDataHob (\r
+ &mCpuExceptrionHandlerLibHobGuid,\r
+ (VOID *)&ExceptionHandlerData,\r
+ sizeof(UINT64)\r
+ );\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
+ \r
+ Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
+ persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
+ If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
+ If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
+\r
+ @param[in] VectorInfo Pointer to reserved vector list.\r
+ \r
+ @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized \r
+ with default interrupt/exception handlers.\r
+ @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
+ @retval EFI_UNSUPPORTED This function is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpuInterruptHandlers (\r
+ IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Registers a function to be called from the processor interrupt handler.\r
+\r
+ This function registers and enables the handler specified by InterruptHandler for a processor \r
+ interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r
+ handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r
+ The installed handler is called once for each processor interrupt or exception.\r
+ NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
+ InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
+\r
+ @param[in] InterruptType Defines which interrupt or exception to hook.\r
+ @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
+ when a processor interrupt occurs. If this parameter is NULL, then the handler\r
+ will be uninstalled.\r
+\r
+ @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
+ @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
+ previously installed.\r
+ @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
+ previously installed.\r
+ @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
+ or this function is not supported.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterCpuInterruptHandler (\r
+ IN EFI_EXCEPTION_TYPE InterruptType,\r
+ IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}
\ No newline at end of file
--- /dev/null
+## @file\r
+# CPU Exception Handler library instance for PEI module.\r
+#\r
+# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# \r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# \r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = PeiCpuExceptionHandlerLib\r
+ MODULE_UNI_FILE = PeiCpuExceptionHandlerLib.uni\r
+ FILE_GUID = 980DDA67-44A6-4897-99E6-275290B71F9E\r
+ MODULE_TYPE = PEIM\r
+ VERSION_STRING = 1.1\r
+ LIBRARY_CLASS = CpuExceptionHandlerLib|PEI_CORE PEIM\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64\r
+#\r
+\r
+[Sources.Ia32]\r
+ Ia32/ExceptionHandlerAsm.asm\r
+ Ia32/ExceptionHandlerAsm.S |GCC\r
+ Ia32/ArchExceptionHandler.c\r
+ Ia32/ArchInterruptDefs.h\r
+\r
+[Sources.X64]\r
+ X64/ExceptionHandlerAsm.asm\r
+ X64/ExceptionHandlerAsm.S |GCC\r
+ X64/ArchExceptionHandler.c\r
+ X64/ArchInterruptDefs.h\r
+\r
+[Sources.common]\r
+ CpuExceptionCommon.h\r
+ CpuExceptionCommon.c\r
+ PeiCpuException.c\r
+ PeiDxeSmmCpuException.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ SerialPortLib\r
+ PrintLib\r
+ LocalApicLib\r
+ PeCoffGetEntryPointLib\r
+ HobLib\r
+ MemoryAllocationLib\r
+ SynchronizationLib\r