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
#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
\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
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
//\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
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