]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI exceptions
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / PeiCpuException.c
index 5dd8423d2f5e8c5b0cd6c2fa986f60c676fd67d5..658f1087a258771018d4c6f0d5b21b3dd47be321 100644 (file)
@@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>\r
 #include <Library/HobLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
 \r
 CONST UINTN    mDoFarReturnFlag  = 0;\r
 \r
@@ -239,5 +240,29 @@ InitializeCpuExceptionHandlersEx (
   IN CPU_EXCEPTION_INIT_DATA            *InitData OPTIONAL\r
   )\r
 {\r
-  return InitializeCpuExceptionHandlers (VectorInfo);\r
+  EFI_STATUS                        Status;\r
+\r
+  //\r
+  // To avoid repeat initialization of default handlers, the caller should pass\r
+  // an extended init data with InitDefaultHandlers set to FALSE. There's no\r
+  // need to call this method to just initialize default handlers. Call non-ex\r
+  // version instead; or this method must be implemented as a simple wrapper of\r
+  // non-ex version of it, if this version has to be called.\r
+  //\r
+  if (InitData == NULL || InitData->Ia32.InitDefaultHandlers) {\r
+    Status = InitializeCpuExceptionHandlers (VectorInfo);\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Initializing stack switch is only necessary for Stack Guard functionality.\r
+    //\r
+    if (PcdGetBool (PcdCpuStackGuard) && InitData != NULL) {\r
+      Status = ArchSetupExcpetionStack (InitData);\r
+    }\r
+  }\r
+\r
+  return  Status;\r
 }\r