]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2Pkg/FspSecCore/SecMain.c
IntelFsp2Pkg: FSP should not override IDT
[mirror_edk2.git] / IntelFsp2Pkg / FspSecCore / SecMain.c
index fa556bf05821a2b2bdb9b6ef0fcc9cd177cd5256..ddbfc4fcdf0b5a14abf47a3546f9977785ec0410 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2018, 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
@@ -19,6 +19,11 @@ EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi = {
 };\r
 \r
 EFI_PEI_PPI_DESCRIPTOR            mPeiSecPlatformInformationPpi[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gFspInApiModePpiGuid,\r
+    NULL\r
+  },\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
     &gEfiTemporaryRamSupportPpiGuid,\r
@@ -39,7 +44,7 @@ UINT64  mIdtEntryTemplate = 0xffff8e000008ffe4ULL;
 \r
 \r
   @param[in] SizeOfRam          Size of the temporary memory available for use.\r
-  @param[in] TempRamBase        Base address of tempory ram\r
+  @param[in] TempRamBase        Base address of temporary ram\r
   @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.\r
   @param[in] PeiCore            PeiCore entry point.\r
   @param[in] BootLoaderStack    BootLoader stack.\r
@@ -65,6 +70,7 @@ SecStartup (
   UINT32                      Index;\r
   FSP_GLOBAL_DATA             PeiFspData;\r
   UINT64                      ExceptionHandler;\r
+  UINTN                       IdtSize;\r
 \r
   //\r
   // Process all libraries constructor function linked to SecCore.\r
@@ -93,13 +99,26 @@ SecStartup (
   // |                   |\r
   // |-------------------|---->  TempRamBase\r
   IdtTableInStack.PeiService  = NULL;\r
-  ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate);\r
-  for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {\r
-    CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64));\r
+  AsmReadIdtr (&IdtDescriptor);\r
+  if ((IdtDescriptor.Base == 0) && (IdtDescriptor.Limit == 0xFFFF)) {\r
+    ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate);\r
+    for (Index = 0; Index < FixedPcdGet8(PcdFspMaxInterruptSupported); Index ++) {\r
+      CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64));\r
+    }\r
+    IdtSize = sizeof (IdtTableInStack.IdtTable);\r
+  } else {\r
+    if (IdtDescriptor.Limit + 1 > sizeof (IdtTableInStack.IdtTable)) {\r
+      //\r
+      // ERROR: IDT table size from boot loader is larger than FSP can support, DeadLoop here!\r
+      //\r
+      CpuDeadLoop();\r
+    } else {\r
+      IdtSize = IdtDescriptor.Limit + 1;\r
+    }\r
+    CopyMem ((VOID *) (UINTN) &IdtTableInStack.IdtTable, (VOID *) IdtDescriptor.Base, IdtSize);\r
   }\r
-\r
   IdtDescriptor.Base  = (UINTN) &IdtTableInStack.IdtTable;\r
-  IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1);\r
+  IdtDescriptor.Limit = (UINT16)(IdtSize - 1);\r
 \r
   AsmWriteIdtr (&IdtDescriptor);\r
 \r
@@ -133,7 +152,7 @@ SecStartup (
 \r
   //\r
   // Call PeiCore Entry\r
-  //  \r
+  //\r
   PeiCore (&SecCoreData, mPeiSecPlatformInformationPpi);\r
 \r
   //\r
@@ -177,7 +196,7 @@ SecTemporaryRamSupport (
 \r
   HeapSize   = CopySize * PcdGet8 (PcdFspHeapSizePercentage) / 100 ;\r
   StackSize  = CopySize - HeapSize;\r
-    \r
+\r
   OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
   NewHeap = (VOID*)((UINTN)PermanentMemoryBase + StackSize);\r
 \r
@@ -215,8 +234,8 @@ SecTemporaryRamSupport (
 \r
   //\r
   // SecSwitchStack function must be invoked after the memory migration\r
-  // immediatly, also we need fixup the stack change caused by new call into\r
-  // permenent memory.\r
+  // immediately, also we need fixup the stack change caused by new call into\r
+  // permanent memory.\r
   //\r
   SecSwitchStack (\r
     (UINT32) (UINTN) OldStack,\r