]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / SecPeiCpuException.c
index d4ae153c574205883882449919561346ed11a01a..497cd1649930d341da29022ce97a2dd0415ed0eb 100644 (file)
@@ -1,15 +1,16 @@
 /** @file\r
   CPU exception handler library implemenation for SEC/PEIM modules.\r
 \r
-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <PiPei.h>\r
+#include <Library/CcExitLib.h>\r
 #include "CpuExceptionCommon.h"\r
 \r
-CONST UINTN    mDoFarReturnFlag  = 0;\r
+CONST UINTN  mDoFarReturnFlag = 0;\r
 \r
 /**\r
   Common exception handler.\r
@@ -20,10 +21,53 @@ CONST UINTN    mDoFarReturnFlag  = 0;
 VOID\r
 EFIAPI\r
 CommonExceptionHandler (\r
-  IN EFI_EXCEPTION_TYPE   ExceptionType,\r
-  IN EFI_SYSTEM_CONTEXT   SystemContext\r
+  IN EFI_EXCEPTION_TYPE  ExceptionType,\r
+  IN EFI_SYSTEM_CONTEXT  SystemContext\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
+  switch (ExceptionType) {\r
+    case VC_EXCEPTION:\r
+      //\r
+      // #VC needs to be handled immediately upon enabling exception handling\r
+      // and therefore can't use the RegisterCpuInterruptHandler() interface\r
+      // (which isn't supported under Sec and Pei anyway).\r
+      //\r
+      // Handle the #VC:\r
+      //   On EFI_SUCCESS - Exception has been handled, return\r
+      //   On other       - ExceptionType contains (possibly new) exception\r
+      //                    value\r
+      //\r
+      Status = CcExitHandleVc (&ExceptionType, SystemContext);\r
+      if (!EFI_ERROR (Status)) {\r
+        return;\r
+      }\r
+\r
+      break;\r
+\r
+    case VE_EXCEPTION:\r
+      //\r
+      // #VE needs to be handled immediately upon enabling exception handling\r
+      // and therefore can't use the RegisterCpuInterruptHandler() interface\r
+      // (which isn't supported under Sec and Pei anyway).\r
+      //\r
+      // Handle the #VE:\r
+      //   On EFI_SUCCESS - Exception has been handled, return\r
+      //   On other       - ExceptionType contains (possibly new) exception\r
+      //                    value\r
+      //\r
+      Status = CcExitHandleVe (&ExceptionType, SystemContext);\r
+      if (!EFI_ERROR (Status)) {\r
+        return;\r
+      }\r
+\r
+      break;\r
+\r
+    default:\r
+      break;\r
+  }\r
+\r
   //\r
   // Initialize the serial port before dumping.\r
   //\r
@@ -60,26 +104,27 @@ CommonExceptionHandler (
 EFI_STATUS\r
 EFIAPI\r
 InitializeCpuExceptionHandlers (\r
-  IN EFI_VECTOR_HANDOFF_INFO       *VectorInfo OPTIONAL\r
+  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                       Status;\r
-  RESERVED_VECTORS_DATA            ReservedVectorData[CPU_EXCEPTION_NUM];\r
-  IA32_DESCRIPTOR                  IdtDescriptor;\r
-  UINTN                            IdtEntryCount;\r
-  UINT16                           CodeSegment;\r
-  EXCEPTION_HANDLER_TEMPLATE_MAP   TemplateMap;\r
-  IA32_IDT_GATE_DESCRIPTOR         *IdtTable;\r
-  UINTN                            Index;\r
-  UINTN                            InterruptHandler;\r
+  EFI_STATUS                      Status;\r
+  RESERVED_VECTORS_DATA           ReservedVectorData[CPU_EXCEPTION_NUM];\r
+  IA32_DESCRIPTOR                 IdtDescriptor;\r
+  UINTN                           IdtEntryCount;\r
+  UINT16                          CodeSegment;\r
+  EXCEPTION_HANDLER_TEMPLATE_MAP  TemplateMap;\r
+  IA32_IDT_GATE_DESCRIPTOR        *IdtTable;\r
+  UINTN                           Index;\r
+  UINTN                           InterruptHandler;\r
 \r
   if (VectorInfo != NULL) {\r
-    SetMem ((VOID *) ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);\r
+    SetMem ((VOID *)ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);\r
     Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);\r
     if (EFI_ERROR (Status)) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
+\r
   //\r
   // Read IDT descriptor and calculate IDT size\r
   //\r
@@ -91,6 +136,7 @@ InitializeCpuExceptionHandlers (
     //\r
     IdtEntryCount = CPU_EXCEPTION_NUM;\r
   }\r
+\r
   //\r
   // Use current CS as the segment selector of interrupt gate in IDT\r
   //\r
@@ -98,7 +144,7 @@ InitializeCpuExceptionHandlers (
 \r
   AsmGetTemplateAddressMap (&TemplateMap);\r
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;\r
-  for (Index = 0; Index < IdtEntryCount; Index ++) {\r
+  for (Index = 0; Index < IdtEntryCount; Index++) {\r
     IdtTable[Index].Bits.Selector = CodeSegment;\r
     //\r
     // Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK\r
@@ -109,38 +155,15 @@ InitializeCpuExceptionHandlers (
         continue;\r
       }\r
     }\r
+\r
     //\r
     // Update IDT entry\r
     //\r
     InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;\r
     ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);\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
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -150,8 +173,8 @@ InitializeCpuInterruptHandlers (
   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
+  NOTE: This function should be invoked after InitializeCpuExceptionHandlers() is invoked,\r
+  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
@@ -169,41 +192,33 @@ InitializeCpuInterruptHandlers (
 EFI_STATUS\r
 EFIAPI\r
 RegisterCpuInterruptHandler (\r
-  IN EFI_EXCEPTION_TYPE            InterruptType,\r
-  IN EFI_CPU_INTERRUPT_HANDLER     InterruptHandler\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
   )\r
 {\r
   return EFI_UNSUPPORTED;\r
 }\r
 \r
 /**\r
-  Initializes all CPU exceptions entries with optional extra initializations.\r
-\r
-  By default, this method should include all functionalities implemented by\r
-  InitializeCpuExceptionHandlers(), plus extra initialization works, if any.\r
-  This could be done by calling InitializeCpuExceptionHandlers() directly\r
-  in this method besides the extra works.\r
-\r
-  InitData is optional and its use and content are processor arch dependent.\r
-  The typical usage of it is to convey resources which have to be reserved\r
-  elsewhere and are necessary for the extra initializations of exception.\r
-\r
-  @param[in]  VectorInfo    Pointer to reserved vector list.\r
-  @param[in]  InitData      Pointer to data optional for extra initializations\r
-                            of exception.\r
-\r
-  @retval EFI_SUCCESS             The exceptions have been successfully\r
-                                  initialized.\r
-  @retval EFI_INVALID_PARAMETER   VectorInfo or InitData contains invalid\r
-                                  content.\r
-\r
+  Setup separate stacks for certain exception handlers.\r
+  If the input Buffer and BufferSize are both NULL, use global variable if possible.\r
+\r
+  @param[in]       Buffer        Point to buffer used to separate exception stack.\r
+  @param[in, out]  BufferSize    On input, it indicates the byte size of Buffer.\r
+                                 If the size is not enough, the return status will\r
+                                 be EFI_BUFFER_TOO_SMALL, and output BufferSize\r
+                                 will be the size it needs.\r
+\r
+  @retval EFI_SUCCESS             The stacks are assigned successfully.\r
+  @retval EFI_UNSUPPORTED         This function is not supported.\r
+  @retval EFI_BUFFER_TOO_SMALL    This BufferSize is too small.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-InitializeCpuExceptionHandlersEx (\r
-  IN EFI_VECTOR_HANDOFF_INFO            *VectorInfo OPTIONAL,\r
-  IN CPU_EXCEPTION_INIT_DATA            *InitData OPTIONAL\r
+InitializeSeparateExceptionStacks (\r
+  IN     VOID   *Buffer,\r
+  IN OUT UINTN  *BufferSize\r
   )\r
 {\r
-  return InitializeCpuExceptionHandlers (VectorInfo);\r
+  return EFI_UNSUPPORTED;\r
 }\r