]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / PeiCpuException.c
index 5dd8423d2f5e8c5b0cd6c2fa986f60c676fd67d5..d256643435e55ab6e25dba69a63bc78c6db1af9b 100644 (file)
@@ -2,13 +2,7 @@
   CPU exception handler library implementation for PEIM module.\r
 \r
 Copyright (c) 2016 - 2018, 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
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -17,6 +11,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
@@ -45,7 +40,7 @@ GetExceptionHandlerData (
 \r
   AsmReadIdtr (&IdtDescriptor);\r
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;\r
-  \r
+\r
   Exception0StubHeader = (EXCEPTION0_STUB_HEADER *)ArchGetIdtHandler (&IdtTable[0]);\r
   return Exception0StubHeader->ExceptionHandlerData;\r
 }\r
@@ -57,7 +52,7 @@ GetExceptionHandlerData (
   exception handler data. The new allocated memory layout follows structure EXCEPTION0_STUB_HEADER.\r
   The code assumes that all processors uses the same exception handler for #0 exception.\r
 \r
-  @param  pointer to exception handler data.\r
+  @param ExceptionHandlerData  pointer to exception handler data.\r
 **/\r
 VOID\r
 SetExceptionHandlerData (\r
@@ -73,7 +68,7 @@ SetExceptionHandlerData (
   //\r
   AsmReadIdtr (&IdtDescriptor);\r
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;\r
-  \r
+\r
   Exception0StubHeader = AllocatePool (sizeof (*Exception0StubHeader));\r
   ASSERT (Exception0StubHeader != NULL);\r
   CopyMem (\r
@@ -239,5 +234,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 = ArchSetupExceptionStack (InitData);\r
+    }\r
+  }\r
+\r
+  return  Status;\r
 }\r