]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Merge Temporary Ram support patch.
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Feb 2008 18:24:43 +0000 (18:24 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Feb 2008 18:24:43 +0000 (18:24 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4782 6f19259b-4bc3-4df7-8a09-765794883524

19 files changed:
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
MdeModulePkg/Core/Pei/Memory/MemoryServices.c
MdeModulePkg/Core/Pei/PeiMain.h
MdeModulePkg/Core/Pei/PeiMain.inf
MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
MdeModulePkg/Core/Pei/Ppi/Ppi.c
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc
MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c
MdePkg/Library/PeiServicesTablePointerLibKr7/PeiServicesTablePointer.c
MdePkg/MdePkg.dec
Nt32Pkg/Include/Library/EdkGenericBdsLib.h
Nt32Pkg/Nt32Pkg.dec
Nt32Pkg/Nt32Pkg.dsc
Nt32Pkg/Nt32Pkg.fdf
Nt32Pkg/Sec/SecMain.c
Nt32Pkg/Sec/SecMain.h
Nt32Pkg/Sec/SecMain.inf
Nt32Pkg/Sec/Stack.asm [new file with mode: 0644]

index 73a6245b7e9001d8cc88e4092147afeccc35b5f9..cf9ea5d173fe1a78ddb813cc405f3a2d3f014fcd 100644 (file)
@@ -28,13 +28,6 @@ typedef struct {
   EFI_HANDLE            Handle;\r
 } PEIM_FILE_HANDLE_EXTENDED_DATA;\r
 \r
-STATIC\r
-VOID\r
-InvokePeiCore (\r
-  VOID          *Context1,\r
-  VOID          *Context2\r
-  );\r
-\r
 VOID\r
 DiscoverPeimsAndOrderWithApriori (\r
   IN  PEI_CORE_INSTANCE    *Private,\r
@@ -55,7 +48,7 @@ Returns:
 \r
   NONE\r
 \r
---*/  \r
+--*/\r
 {\r
   EFI_STATUS                          Status;\r
   EFI_PEI_FV_HANDLE                   FileHandle;\r
@@ -90,20 +83,20 @@ Returns:
   //\r
   for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
     Status = PeiFindFileEx (\r
-                VolumeHandle, \r
-                NULL, \r
-                PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r
+                VolumeHandle,\r
+                NULL,\r
+                PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,\r
                 &FileHandle,\r
                 &AprioriFileHandle\r
                 );\r
     if (Status != EFI_SUCCESS) {\r
       break;\r
     }\r
-    \r
+\r
     Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r
   }\r
 \r
-  Private->AprioriCount = 0; \r
+  Private->AprioriCount = 0;\r
   if (AprioriFileHandle != NULL) {\r
     //\r
     // Read the Apriori file\r
@@ -114,21 +107,21 @@ Returns:
       // Calculate the number of PEIMs in the A Priori list\r
       //\r
       Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF;\r
-      Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER);   \r
+      Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER);\r
       Private->AprioriCount /= sizeof (EFI_GUID);\r
-        \r
+\r
       SetMem (FileGuid, sizeof (FileGuid), 0);\r
       for (Index = 0; Index < PeimCount; Index++) {\r
         //\r
         // Make an array of file name guids that matches the FileHandle array so we can convert\r
         // quickly from file name to file handle\r
         //\r
-        CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID));    \r
+        CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID));\r
       }\r
 \r
       //\r
       // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r
-      // Add avalible PEIMs in Apriori file into TempFileHandles array at first. \r
+      // Add avalible PEIMs in Apriori file into TempFileHandles array at first.\r
       //\r
       Index2 = 0;\r
       for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r
@@ -139,7 +132,7 @@ Returns:
           }\r
         }\r
         if (Guid == NULL) {\r
-          break;  \r
+          break;\r
         }\r
         PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r
         TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r
@@ -154,7 +147,7 @@ Returns:
       // Update valid Aprioricount\r
       //\r
       Private->AprioriCount = Index;\r
-      \r
+\r
       //\r
       // Add in any PEIMs not in the Apriori file\r
       //\r
@@ -171,11 +164,11 @@ Returns:
       //Index the end of array contains re-range Pei moudle.\r
       //\r
       TempFileHandles[Index] = NULL;\r
-      \r
+\r
       //\r
       // Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r
-      // We need to update it to start with files in the A Priori list and \r
-      // then the remaining files in PEIM order. \r
+      // We need to update it to start with files in the A Priori list and\r
+      // then the remaining files in PEIM order.\r
       //\r
       CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r
     }\r
@@ -186,7 +179,46 @@ Returns:
   //\r
   Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r
   CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
-  \r
+\r
+}\r
+\r
+VOID*\r
+ShadowPeiCore(\r
+  EFI_PEI_SERVICES     **PeiServices,\r
+  PEI_CORE_INSTANCE    *PrivateInMem\r
+  )\r
+{\r
+  EFI_PEI_FILE_HANDLE  PeiCoreFileHandle;\r
+  EFI_PHYSICAL_ADDRESS EntryPoint;\r
+  EFI_STATUS           Status;\r
+  UINT32               AuthenticationState;\r
+\r
+  PeiCoreFileHandle = NULL;\r
+\r
+  //\r
+  // Find the PEI Core in the BFV\r
+  //\r
+  Status = PeiFindFileEx (\r
+             (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,\r
+             NULL,\r
+             EFI_FV_FILETYPE_PEI_CORE,\r
+             &PeiCoreFileHandle,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Shadow PEI Core into memory so it will run faster\r
+  //\r
+  Status = PeiLoadImage (\r
+              PeiServices,\r
+              *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+              &EntryPoint,\r
+              &AuthenticationState\r
+              );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r
 }\r
 \r
 VOID\r
@@ -220,9 +252,8 @@ Returns:
   UINT32                              Index1;\r
   UINT32                              Index2;\r
   EFI_PEI_SERVICES                    **PeiServices;\r
-  VOID                                *PrivateInMem;\r
-  EFI_PEI_FV_HANDLE                   VolumeHandle; \r
-  EFI_PEI_FILE_HANDLE                 PeiCoreFileHandle;\r
+  EFI_PEI_FV_HANDLE                   VolumeHandle;\r
+  //EFI_PHYSICAL_ADDRESS                PeiCoreFileHandle;\r
   EFI_PEI_FILE_HANDLE                 PeimFileHandle;\r
   UINTN                               FvCount;\r
   UINTN                               PeimCount;\r
@@ -234,10 +265,19 @@ Returns:
   UINTN                               SaveCurrentPeimCount;\r
   UINTN                               SaveCurrentFvCount;\r
   EFI_PEI_FILE_HANDLE                 SaveCurrentFileHandle;\r
-  VOID                                *TopOfStack;\r
-  PEI_CORE_PARAMETERS                 PeiCoreParameters;\r
   PEIM_FILE_HANDLE_EXTENDED_DATA      ExtendedData;\r
+  EFI_PHYSICAL_ADDRESS                NewPermenentMemoryBase;\r
+  TEMPORARY_RAM_SUPPORT_PPI           *TemporaryRamSupportPpi;\r
+  EFI_HOB_HANDOFF_INFO_TABLE          *OldHandOffTable;\r
+  EFI_HOB_HANDOFF_INFO_TABLE          *NewHandOffTable;\r
+  INTN                                Offset;\r
+  PEI_CORE_INSTANCE                   *PrivateInMem;\r
+  UINT64                              NewPeiStackSize;\r
+  UINT64                              OldPeiStackSize;\r
+  UINT64                              StackGap;\r
   EFI_FV_FILE_INFO                    FvFileInfo;\r
+  UINTN                               OldCheckingTop;\r
+  UINTN                               OldCheckingBottom;\r
 \r
 \r
   PeiServices = &Private->PS;\r
@@ -257,11 +297,11 @@ Returns:
     for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r
       for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
         if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
-          PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];  \r
+          PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r
           Status = PeiLoadImage (\r
-                    &Private->PS, \r
-                    PeimFileHandle,  \r
-                    &EntryPoint, \r
+                    &Private->PS,\r
+                    PeimFileHandle,\r
+                    &EntryPoint,\r
                     &AuthenticationState\r
                     );\r
           if (Status == EFI_SUCCESS) {\r
@@ -270,18 +310,18 @@ Returns:
             //\r
             Private->Fv[Index1].PeimState[Index2]++;\r
             Private->CurrentFileHandle   = PeimFileHandle;\r
-            Private->CurrentPeimFvCount  = Index1;        \r
-            Private->CurrentPeimCount    = Index2;        \r
+            Private->CurrentPeimFvCount  = Index1;\r
+            Private->CurrentPeimCount    = Index2;\r
             //\r
             // Call the PEIM entry point\r
             //\r
             PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
-            \r
+\r
             PERF_START (0, "PEIM", NULL, 0);\r
             PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->PS);\r
             PERF_END (0, "PEIM", NULL, 0);\r
-          } \r
-          \r
+          }\r
+\r
           //\r
           // Process the Notify list and dispatch any notifies for\r
           // newly installed PPIs.\r
@@ -290,9 +330,9 @@ Returns:
         }\r
       }\r
     }\r
-    Private->CurrentFileHandle  = SaveCurrentFileHandle;   \r
-    Private->CurrentPeimFvCount = SaveCurrentFvCount;    \r
-    Private->CurrentPeimCount   = SaveCurrentPeimCount;    \r
+    Private->CurrentFileHandle  = SaveCurrentFileHandle;\r
+    Private->CurrentPeimFvCount = SaveCurrentFvCount;\r
+    Private->CurrentPeimCount   = SaveCurrentPeimCount;\r
   }\r
 \r
   //\r
@@ -314,7 +354,7 @@ Returns:
       if (Private->CurrentPeimCount == 0) {\r
         //\r
         // When going through each FV, at first, search Apriori file to\r
-        // reorder all PEIMs to ensure the PEIMs in Apriori file to get \r
+        // reorder all PEIMs to ensure the PEIMs in Apriori file to get\r
         // dispatch at first.\r
         //\r
         DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r
@@ -323,8 +363,8 @@ Returns:
       //\r
       // Start to dispatch all modules within the current Fv.\r
       //\r
-      for (PeimCount = Private->CurrentPeimCount; \r
-           (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL); \r
+      for (PeimCount = Private->CurrentPeimCount;\r
+           (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
            PeimCount++) {\r
         Private->CurrentPeimCount  = PeimCount;\r
         PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
@@ -345,16 +385,17 @@ Returns:
               // For PEIM driver, Load its entry point\r
               //\r
               Status = PeiLoadImage (\r
-                         PeiServices, \r
-                         PeimFileHandle,  \r
-                         &EntryPoint, \r
+                         PeiServices,\r
+                         PeimFileHandle,\r
+                         &EntryPoint,\r
                          &AuthenticationState\r
                          );\r
             }\r
 \r
             if ((Status == EFI_SUCCESS)) {\r
               //\r
-              // The PEIM has its dependencies satisfied, and is processed.\r
+              // The PEIM has its dependencies satisfied, and its entry point\r
+              // has been found, so invoke it.\r
               //\r
               PERF_START (0, "PEIM", NULL, 0);\r
 \r
@@ -373,7 +414,7 @@ Returns:
                 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
                 //\r
                 Private->Fv[FvCount].PeimState[PeimCount]++;\r
-                \r
+\r
                 if (FvFileInfo.FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
                   //\r
                   // Call the PEIM entry point for PEIM driver\r
@@ -393,102 +434,203 @@ Returns:
                 );\r
               PERF_END (0, "PEIM", NULL, 0);\r
 \r
-            } else {\r
+            }\r
+\r
+            if (Private->SwitchStackSignal) {\r
+\r
               //\r
-              // If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be ready,\r
-              // we flag that more Peims need to be dispatched.\r
+              // Reserve the size of new stack at bottom of physical memory\r
               //\r
-              PeimNeedingDispatch = TRUE;\r
-            }\r
+              OldPeiStackSize = Private->StackSize;\r
+              NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
+              if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {\r
+                Private->StackSize = NewPeiStackSize;\r
+              } else {\r
+                Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize);\r
+              }\r
 \r
-            //\r
-            // Process the Notify list and dispatch any notifies for\r
-            // newly installed PPIs.\r
-            //\r
-            ProcessNotifyList (Private);\r
+              //\r
+              // In theory, the size of new stack in permenent memory should large than\r
+              // size of old stack in temporary memory.\r
+              // But if new stack is smaller than the size of old stack, we also reserve\r
+              // the size of old stack at bottom of permenent memory.\r
+              //\r
+              StackGap = 0;\r
+              if (Private->StackSize > OldPeiStackSize) {\r
+                StackGap = Private->StackSize - OldPeiStackSize;\r
+              }\r
 \r
-            //\r
-            // If permanent memory was discovered and installed by this\r
-            // PEIM, shadow PEI Core and switch the stacks to the new memory.  \r
-            //\r
-            if (Private->SwitchStackSignal) {\r
+              //\r
+              // Update HandOffHob for new installed permenent memory\r
+              //\r
+              OldHandOffTable   = Private->HobList.HandoffInformationTable;\r
+              OldCheckingBottom = (UINTN)OldHandOffTable;\r
+              OldCheckingTop    = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);\r
 \r
               //\r
-              // Make sure we don't retry the same PEIM that added memory\r
+              // The whole temporary memory will be migrated to physical memory.\r
+              // CAUTION: The new base is computed accounding to gap of new stack.\r
               //\r
-              Private->CurrentPeimCount++;\r
+              NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;\r
+              Offset                 = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->TemporaryRamBase;\r
+              NewHandOffTable        = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + Offset);\r
+              PrivateInMem           = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + Offset);\r
 \r
               //\r
-              // Migrate IDT from CAR into real memory, so after stack switches to\r
-              // the new memory, the caller can get memory version PeiServiceTable. \r
+              // TemporaryRamSupportPpi is produced by platform's SEC\r
               //\r
-              MigrateIdtTable (PeiServices);\r
+              Status = PeiLocatePpi (\r
+                         (CONST EFI_PEI_SERVICES **) PeiServices,\r
+                         &gEfiTemporaryRamSupportPpiGuid,\r
+                         0,\r
+                         NULL,\r
+                         (VOID**)&TemporaryRamSupportPpi\r
+                         );\r
+\r
 \r
+              if (!EFI_ERROR (Status)) {\r
+                TemporaryRamSupportPpi->TemporaryRamMigration (\r
+                                          (CONST EFI_PEI_SERVICES **) PeiServices,\r
+                                          (EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase,\r
+                                          (EFI_PHYSICAL_ADDRESS)(UINTN) NewPermenentMemoryBase,\r
+                                          SecCoreData->TemporaryRamSize\r
+                                          );\r
+\r
+              } else {\r
+                CopyMem (\r
+                  (VOID*)(UINTN) NewPermenentMemoryBase,\r
+                  SecCoreData->TemporaryRamBase,\r
+                  SecCoreData->TemporaryRamSize\r
+                  );\r
+              }\r
+\r
+\r
+              //\r
               //\r
-              // Since we are at dispatch level, only the Core's private data \r
-              // is preserved, nobody else should have any data on the stack. \r
-              // So we need to copy PEI core instance data to memory.\r
+              // Fixup the PeiCore's private data\r
               //\r
-              PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);\r
-              ASSERT (PrivateInMem != NULL);\r
+              PrivateInMem->PS          = &PrivateInMem->ServiceTableShadow;\r
+              PrivateInMem->CpuIo       = &PrivateInMem->ServiceTableShadow.CpuIo;\r
+              PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + Offset);\r
+              PrivateInMem->StackBase   = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);\r
+\r
+              PeiServices = &PrivateInMem->PS;\r
+\r
+              //\r
+              // Fixup for PeiService's address\r
+              //\r
+              SetPeiServicesTablePointer(PeiServices);\r
+\r
+              //\r
+              // Update HandOffHob for new installed permenent memory\r
+              //\r
+              NewHandOffTable->EfiEndOfHobList =\r
+                (EFI_PHYSICAL_ADDRESS)(VOID*)((UINTN) NewHandOffTable->EfiEndOfHobList + Offset);\r
+              NewHandOffTable->EfiMemoryTop        = PrivateInMem->PhysicalMemoryBegin +\r
+                                                     PrivateInMem->PhysicalMemoryLength;\r
+              NewHandOffTable->EfiMemoryBottom     = PrivateInMem->PhysicalMemoryBegin;\r
+              NewHandOffTable->EfiFreeMemoryTop    = PrivateInMem->FreePhysicalMemoryTop;\r
+              NewHandOffTable->EfiFreeMemoryBottom = NewHandOffTable->EfiEndOfHobList +\r
+                                                     sizeof (EFI_HOB_GENERIC_HEADER);\r
+\r
+              //\r
+              // We need convert the PPI desciptor's pointer\r
+              //\r
+              ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices, \r
+                                  OldCheckingBottom, \r
+                                  OldCheckingTop, \r
+                                  NewHandOffTable);\r
+\r
+              DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",\r
+                                  (UINTN)PrivateInMem->StackBase,\r
+                                  PrivateInMem->StackSize));\r
+              BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize);\r
+\r
+              //\r
+              // After the whole temporary memory is migrated, then we can allocate page in\r
+              // permenent memory.\r
+              //\r
+              PrivateInMem->PeiMemoryInstalled     = TRUE;\r
+\r
+              //\r
+              // Make sure we don't retry the same PEIM that added memory\r
+              //\r
+              PrivateInMem->CurrentPeimCount++;\r
 \r
               //\r
               // Shadow PEI Core. When permanent memory is avaiable, shadow\r
               // PEI Core and PEIMs to get high performance.\r
               //\r
-              PeiCoreFileHandle = NULL;\r
+              //PeiCoreFileHandle = 0;\r
               //\r
               // Find the PEI Core in the BFV\r
               //\r
-              Status = PeiFindFileEx (\r
-                        (EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader, \r
-                        NULL, \r
-                        EFI_FV_FILETYPE_PEI_CORE, \r
-                        &PeiCoreFileHandle,\r
-                        NULL\r
-                        );\r
-              ASSERT_EFI_ERROR (Status);\r
-  \r
+              //Status = PeiFindFileEx (\r
+              //          (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,\r
+              //          NULL,\r
+               //         EFI_FV_FILETYPE_PEI_CORE,\r
+              //          (EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle,\r
+              //          NULL\r
+              //          );\r
+              //ASSERT_EFI_ERROR (Status);\r
+\r
               //\r
               // Shadow PEI Core into memory so it will run faster\r
               //\r
-              Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);\r
-              ASSERT_EFI_ERROR (Status);\r
-  \r
+              //Status = PeiLoadImage (\r
+              //           PeiServices,\r
+              //           *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+              //           &EntryPoint,\r
+               //          &AuthenticationState\r
+               //          );\r
+              //ASSERT_EFI_ERROR (Status);\r
+\r
+              //PrivateInMem->ShadowedPeiCore = (VOID*) ((UINTN) EntryPoint +\r
+              //                                         (UINTN) PeiCore    -\r
+              //                                         (UINTN) _ModuleEntryPoint);\r
+              PrivateInMem->ShadowedPeiCore = ShadowPeiCore (\r
+                                                PeiServices,\r
+                                                PrivateInMem\r
+                                                );\r
               //\r
-              // Switch to memory based stack and reenter PEI Core that has been\r
-              //  shadowed to memory.\r
+              // Process the Notify list and dispatch any notifies for\r
+              // newly installed PPIs.\r
               //\r
+              ProcessNotifyList (PrivateInMem);\r
+\r
               //\r
-              // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r
+              // Entry PEI Phase 2\r
               //\r
-              TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);\r
-              TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
-              \r
-              PeiCoreParameters.SecCoreData = SecCoreData;\r
-              PeiCoreParameters.PpiList     = NULL;\r
-              PeiCoreParameters.Data        = PrivateInMem;\r
-              ASSERT (PeiCoreParameters.Data != 0);\r
+              PeiCore (SecCoreData, NULL, PrivateInMem);\r
 \r
-              PeiSwitchStacks (\r
-                InvokePeiCore,\r
-                (VOID*) ((UINTN) EntryPoint + ((UINTN) PeiCore - (UINTN) _ModuleEntryPoint)),\r
-                (VOID*) &PeiCoreParameters,  \r
-                TopOfStack,\r
-                (VOID*)(UINTN)Private->StackBase\r
-                );\r
+              //((PEI_CORE_ENTRY_POINT) (UINTN) PrivateInMem->ShadowedPeiCore) (\r
+              //                                        SecCoreData,\r
+              //                                        NULL,\r
+              //                                        PrivateInMem\r
+              //                                        );\r
+\r
+              //\r
+              // Code should not come here\r
+              //\r
+              ASSERT_EFI_ERROR(FALSE);\r
             }\r
 \r
+            //\r
+            // Process the Notify list and dispatch any notifies for\r
+            // newly installed PPIs.\r
+            //\r
+            ProcessNotifyList (Private);\r
+\r
             if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) &&   \\r
                 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
               //\r
-              // If memory is availble we shadow images by default for performance reasons. \r
-              // We call the entry point a 2nd time so the module knows it's shadowed. \r
+              // If memory is availble we shadow images by default for performance reasons.\r
+              // We call the entry point a 2nd time so the module knows it's shadowed.\r
               //\r
               //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
               PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
               //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
-              \r
+\r
               //\r
               // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
               //\r
@@ -518,16 +660,16 @@ Returns:
     }\r
 \r
     //\r
-    // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go \r
+    // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go\r
     // through all the FV.\r
     //\r
     Private->CurrentPeimFvCount = 0;\r
 \r
     //\r
-    // PeimNeedingDispatch being TRUE means we found a PEIM that did not get \r
+    // PeimNeedingDispatch being TRUE means we found a PEIM that did not get\r
     //  dispatched. So we need to make another pass\r
     //\r
-    // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this \r
+    // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this\r
     //  pass. If we did not dispatch a PEIM there is no point in trying again\r
     //  as it will fail the next time too (nothing has changed).\r
     //\r
@@ -602,13 +744,13 @@ Returns:
     //\r
     return TRUE;\r
   }\r
-  \r
+\r
   //\r
-  // Depex section not in the encapsulated section. \r
+  // Depex section not in the encapsulated section.\r
   //\r
   Status = PeiServicesFfsFindSectionData (\r
               EFI_SECTION_PEI_DEPEX,\r
-              FileHandle, \r
+              FileHandle,\r
               (VOID **)&DepexData\r
               );\r
 \r
@@ -630,12 +772,12 @@ Returns:
   discovery permanent memory.\r
 \r
        @param FileHandle       File handle of a PEIM.\r
-  \r
+\r
   @retval EFI_NOT_FOUND                                The file handle doesn't point to PEIM itself.\r
   @retval EFI_ALREADY_STARTED          Indicate that the PEIM has been registered itself.\r
   @retval EFI_SUCCESS                                          Successfully to register itself.\r
 \r
-**/ \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiRegisterForShadow (\r
@@ -658,52 +800,13 @@ PeiRegisterForShadow (
     //\r
     return EFI_ALREADY_STARTED;\r
   }\r
-  \r
+\r
   Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
-/**\r
-  This routine invoke the PeiCore's entry in new stack environment.\r
-\r
-       @param Context1         The first context parameter is entry of PeiCore\r
-  @param Context2      The second context parameter is parameter structure point for PeiCore\r
-\r
-**/ \r
-STATIC\r
-VOID\r
-InvokePeiCore (\r
-  VOID          *Context1,\r
-  VOID          *Context2\r
-  )\r
-{\r
-  PEI_CORE_ENTRY_POINT  PeiCoreEntryPoint;\r
-  PEI_CORE_PARAMETERS       *PeiCoreParameters;\r
-\r
-  //\r
-  // Running on new stack in SEC Core\r
-  //\r
-\r
-  PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r
-  PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r
-\r
-  //\r
-  // Call PEI Core using new stack\r
-  //\r
-  PeiCoreEntryPoint (\r
-    PeiCoreParameters->SecCoreData,\r
-    PeiCoreParameters->PpiList,\r
-    PeiCoreParameters->Data\r
-    );\r
-\r
-  //\r
-  // Never returns\r
-  //\r
-  ASSERT (FALSE);\r
-  CpuDeadLoop ();\r
-}\r
 \r
 /**\r
   Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r
@@ -712,7 +815,7 @@ InvokePeiCore (
        @param FileHandle               File handle of a Fv type file.\r
   @param AuthenticationState  Pointer to attestation authentication state of image.\r
 \r
-  \r
+\r
   @retval EFI_NOT_FOUND                                FV image can't be found.\r
   @retval EFI_SUCCESS                                          Successfully to process it.\r
 \r
@@ -730,12 +833,12 @@ ProcessFvFile (
   UINT32                FvAlignment;\r
   VOID                  *FvBuffer;\r
   EFI_PEI_HOB_POINTERS  HobFv2;\r
-  \r
+\r
   FvBuffer             = NULL;\r
   *AuthenticationState = 0;\r
 \r
   //\r
-  // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already \r
+  // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
   // been extracted.\r
   //\r
   HobFv2.Raw = GetHobList ();\r
@@ -748,7 +851,7 @@ ProcessFvFile (
     }\r
     HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r
   }\r
-  \r
+\r
   //\r
   // Find FvImage in FvFile\r
   //\r
@@ -758,7 +861,7 @@ ProcessFvFile (
              FvFileHandle,\r
              (VOID **)&FvImageHandle\r
              );\r
-  \r
+\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -774,7 +877,7 @@ ProcessFvFile (
   if (FvAlignment < 8) {\r
     FvAlignment = 8;\r
   }\r
-  // \r
+  //\r
   // Check FvImage\r
   //\r
   if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r
@@ -788,7 +891,7 @@ ProcessFvFile (
     //\r
     PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r
   }\r
-  \r
+\r
   //\r
   // Install FvPpi and Build FvHob\r
   //\r
@@ -817,6 +920,6 @@ ProcessFvFile (
     &FvImageInfo.FvName,\r
     &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)\r
     );\r
-    \r
+\r
   return EFI_SUCCESS;\r
 }\r
index 05e65ce75e00aa8389cdb8e46bad02c9e4b51f25..457804fef2b5197a661dbcdca63d3e10d6d52efc 100644 (file)
@@ -21,6 +21,12 @@ Abstract:
 \r
 #include <PeiMain.h>\r
 \r
+static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiMemoryDiscoveredPpiGuid,\r
+  NULL\r
+};\r
+\r
 VOID\r
 InitializeMemoryServices (\r
   IN PEI_CORE_INSTANCE           *PrivateData,\r
@@ -49,15 +55,18 @@ Returns:
 \r
 --*/\r
 {\r
-  PrivateData->SwitchStackSignal = FALSE;\r
+  \r
+  PrivateData->SwitchStackSignal      = FALSE;\r
 \r
   if (OldCoreData == NULL) {\r
 \r
     PrivateData->PeiMemoryInstalled = FALSE;\r
 \r
-    PrivateData->BottomOfCarHeap = SecCoreData->PeiTemporaryRamBase; \r
-    PrivateData->TopOfCarHeap = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize);\r
\r
+    PrivateData->BottomOfCarHeap        = SecCoreData->PeiTemporaryRamBase; \r
+    PrivateData->TopOfCarHeap           = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize);\r
+    PrivateData->SizeOfTemporaryMemory  = SecCoreData->TemporaryRamSize;\r
+    PrivateData->StackSize              = (UINT64) SecCoreData->StackSize;\r
+    \r
     DEBUG_CODE_BEGIN ();\r
       PrivateData->SizeOfCacheAsRam = SecCoreData->PeiTemporaryRamSize + SecCoreData->StackSize;\r
       PrivateData->MaxTopOfCarHeap  = (VOID *) ((UINTN) PrivateData->BottomOfCarHeap + (UINTN) PrivateData->SizeOfCacheAsRam);\r
@@ -85,9 +94,9 @@ Returns:
 EFI_STATUS\r
 EFIAPI\r
 PeiInstallPeiMemory (\r
-  IN CONST EFI_PEI_SERVICES      **PeiServices,\r
-  IN EFI_PHYSICAL_ADDRESS  MemoryBegin,\r
-  IN UINT64                MemoryLength\r
+  IN CONST EFI_PEI_SERVICES  **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS    MemoryBegin,\r
+  IN UINT64                  MemoryLength\r
   )\r
 /*++\r
 \r
@@ -109,72 +118,15 @@ Returns:
 --*/\r
 {\r
   PEI_CORE_INSTANCE                     *PrivateData;\r
-  EFI_HOB_HANDOFF_INFO_TABLE            *OldHandOffHob;\r
-  EFI_HOB_HANDOFF_INFO_TABLE            *NewHandOffHob;\r
-  UINT64                                PeiStackSize;\r
-  UINT64                                EfiFreeMemorySize;\r
-  EFI_PHYSICAL_ADDRESS                  PhysicalAddressOfOldHob;\r
-\r
-  if (MemoryLength > (MAX_ADDRESS - MemoryBegin + 1))\r
-    return EFI_INVALID_PARAMETER;\r
-    \r
-   \r
+\r
   DEBUG ((EFI_D_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));\r
-  \r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
 \r
-  PrivateData->SwitchStackSignal = TRUE;\r
-  PrivateData->PeiMemoryInstalled = TRUE;\r
-  \r
-  //\r
-  // Ensure the stack base is in page alignment \r
-  //\r
-  PrivateData->StackBase = ((UINTN)MemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
-  PeiStackSize = (RShiftU64 (MemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
-  \r
-  if (PEI_STACK_SIZE > PeiStackSize) {\r
-    PrivateData->StackSize = PeiStackSize;\r
-  } else {\r
-    PrivateData->StackSize = PEI_STACK_SIZE;\r
-  }\r
-\r
-  OldHandOffHob = PrivateData->HobList.HandoffInformationTable;\r
-\r
-  PrivateData->HobList.Raw = (VOID *)((UINTN)(PrivateData->StackBase + PrivateData->StackSize));\r
-  NewHandOffHob = PrivateData->HobList.HandoffInformationTable;\r
-  PhysicalAddressOfOldHob = (EFI_PHYSICAL_ADDRESS) (UINTN) OldHandOffHob;\r
-\r
-  EfiFreeMemorySize = OldHandOffHob->EfiFreeMemoryBottom - PhysicalAddressOfOldHob;\r
-  \r
-  DEBUG ((EFI_D_INFO, "HOBLIST address before memory init = 0x%p\n",  OldHandOffHob));\r
-  DEBUG ((EFI_D_INFO, "HOBLIST address after memory init = 0x%p\n", NewHandOffHob));\r
-\r
-  CopyMem (\r
-    NewHandOffHob,\r
-    OldHandOffHob,\r
-    (UINTN)EfiFreeMemorySize\r
-    );\r
-\r
-  NewHandOffHob->EfiMemoryTop     = MemoryBegin + MemoryLength;\r
-  NewHandOffHob->EfiFreeMemoryTop = NewHandOffHob->EfiMemoryTop;\r
-  NewHandOffHob->EfiMemoryBottom  = MemoryBegin;\r
-  \r
-  NewHandOffHob->EfiFreeMemoryBottom = (UINTN)NewHandOffHob + EfiFreeMemorySize;                                     \r
-                                       \r
-  NewHandOffHob->EfiEndOfHobList     = (UINTN)NewHandOffHob +\r
-                                       (OldHandOffHob->EfiEndOfHobList -\r
-                                        PhysicalAddressOfOldHob);\r
-  \r
-  //\r
-  // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
-  //  the 63-bit of address is set to 1.\r
-  //\r
-  SWITCH_TO_CACHE_MODE (PrivateData);\r
-  \r
-  ConvertPpiPointers (PeiServices, OldHandOffHob, NewHandOffHob);\r
-\r
-  BuildStackHob (PrivateData->StackBase, PrivateData->StackSize);\r
-  \r
+  PrivateData->PhysicalMemoryBegin   = MemoryBegin;\r
+  PrivateData->PhysicalMemoryLength  = MemoryLength;\r
+  PrivateData->FreePhysicalMemoryTop = MemoryBegin + MemoryLength;\r
+   \r
+  PrivateData->SwitchStackSignal      = TRUE;\r
 \r
   return EFI_SUCCESS;   \r
 }\r
@@ -214,56 +166,70 @@ Returns:
   PEI_CORE_INSTANCE                       *PrivateData;\r
   EFI_PEI_HOB_POINTERS                    Hob;\r
   EFI_PHYSICAL_ADDRESS                    Offset;\r
+  EFI_PHYSICAL_ADDRESS                    *FreeMemoryTop;\r
+  EFI_PHYSICAL_ADDRESS                    *FreeMemoryBottom;\r
 \r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
-\r
+  Hob.Raw     = PrivateData->HobList.Raw;\r
+  \r
   //\r
   // Check if Hob already available\r
   //\r
   if (!PrivateData->PeiMemoryInstalled) {\r
-    return EFI_NOT_AVAILABLE_YET;\r
+    //\r
+    // When PeiInstallMemory is called but CAR has *not* been moved to temporary memory,\r
+    // the AllocatePage will dependent the field of PEI_CORE_INSTANCE structure.\r
+    //\r
+    if (!PrivateData->SwitchStackSignal) {\r
+      return EFI_NOT_AVAILABLE_YET;\r
+    } else {\r
+      FreeMemoryTop     = &(PrivateData->FreePhysicalMemoryTop);\r
+      FreeMemoryBottom  = &(PrivateData->PhysicalMemoryBegin);\r
+    }\r
+  } else {\r
+    FreeMemoryTop     = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);\r
+    FreeMemoryBottom  = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
   }\r
 \r
-  Hob.Raw = PrivateData->HobList.Raw;\r
+  \r
 \r
   //\r
   // Check to see if on 4k boundary\r
   //\r
-  Offset = Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF;\r
-\r
+  Offset = *(FreeMemoryTop) & 0xFFF;\r
+  \r
   //\r
   // If not aligned, make the allocation aligned.\r
   //\r
   if (Offset != 0) {\r
-    Hob.HandoffInformationTable->EfiFreeMemoryTop -= Offset;\r
+    *(FreeMemoryTop) -= Offset;\r
   }\r
-\r
-  ASSERT (Hob.HandoffInformationTable->EfiFreeMemoryTop >= Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
+  \r
   //\r
   // Verify that there is sufficient memory to satisfy the allocation\r
   //\r
-  if (Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < \r
-      Hob.HandoffInformationTable->EfiFreeMemoryBottom) {\r
+  if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < \r
+      *(FreeMemoryBottom)) {\r
     DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages));\r
     DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \\r
-    EFI_SIZE_TO_PAGES ((UINTN) (Hob.HandoffInformationTable->EfiFreeMemoryTop - Hob.HandoffInformationTable->EfiFreeMemoryBottom))));\r
+    EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom)))));\r
     return  EFI_OUT_OF_RESOURCES;\r
   } else {\r
     //\r
     // Update the PHIT to reflect the memory usage\r
     //\r
-    Hob.HandoffInformationTable->EfiFreeMemoryTop -= Pages * EFI_PAGE_SIZE;\r
+    *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE;\r
 \r
     //\r
     // Update the value for the caller\r
     //\r
-    *Memory = Hob.HandoffInformationTable->EfiFreeMemoryTop;\r
+    *Memory = *(FreeMemoryTop);\r
 \r
     //\r
     // Create a memory allocation HOB.\r
     //\r
     BuildMemoryAllocationHob (\r
-      Hob.HandoffInformationTable->EfiFreeMemoryTop,\r
+      *(FreeMemoryTop),\r
       Pages * EFI_PAGE_SIZE,\r
       MemoryType\r
       );\r
index ef2d592a5e51bcd6b92f1e41d23028672146cbb3..319bf87711f3a20a6325ced26b6017041c4706e4 100644 (file)
@@ -35,6 +35,7 @@ Revision History
 #include <Ppi/GuidedSectionExtraction.h>\r
 #include <Ppi/LoadFile.h>\r
 #include <Ppi/Security2.h>\r
+#include <Ppi/TemporaryRamSupport.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PeiCoreEntryPoint.h>\r
 #include <Library/BaseLib.h>\r
@@ -66,9 +67,7 @@ typedef union {
   VOID                        *Raw;\r
 } PEI_PPI_LIST_POINTERS;\r
 \r
-#define PEI_STACK_SIZE 0x20000\r
-\r
-#define MAX_PPI_DESCRIPTORS 128\r
+#define MAX_PPI_DESCRIPTORS 64\r
 \r
 typedef struct {\r
   INTN                    PpiListEnd;\r
@@ -135,9 +134,14 @@ typedef struct{
   VOID                               *CpuIo;\r
   EFI_PEI_SECURITY2_PPI              *PrivateSecurityPpi;\r
   EFI_PEI_SERVICES                   ServiceTableShadow;\r
+  UINTN                              SizeOfTemporaryMemory;\r
   UINTN                              SizeOfCacheAsRam;\r
   VOID                               *MaxTopOfCarHeap;\r
   EFI_PEI_PPI_DESCRIPTOR             *XipLoadFile;\r
+  EFI_PHYSICAL_ADDRESS               PhysicalMemoryBegin;\r
+  UINT64                             PhysicalMemoryLength;\r
+  EFI_PHYSICAL_ADDRESS               FreePhysicalMemoryTop;\r
+  VOID*                              ShadowedPeiCore;\r
   CACHE_SECTION_DATA                 CacheSection;\r
 } PEI_CORE_INSTANCE;\r
 \r
@@ -307,6 +311,35 @@ Returns:
 ;\r
 \r
 \r
+EFI_STATUS\r
+FindNextPeim (\r
+  IN EFI_PEI_SERVICES            **PeiServices,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **PeimFileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching file in the\r
+    FFS volume. The search starts from FileHeader inside\r
+    the Firmware Volume defined by FwVolHeader.\r
+\r
+Arguments:\r
+    PeiServices - Pointer to the PEI Core Services Table.\r
+\r
+    FwVolHeader - Pointer to the FV header of the volume to search.\r
+                     This parameter must point to a valid FFS volume.\r
+\r
+    PeimFileHeader  - Pointer to the current file from which to begin searching.\r
+                  This pointer will be updated upon return to reflect the file found.\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+;\r
+\r
 BOOLEAN\r
 Dispatched (\r
   IN UINT8  CurrentPeim,\r
@@ -439,8 +472,9 @@ Returns:
 \r
 VOID\r
 ConvertPpiPointers (\r
-  IN CONST EFI_PEI_SERVICES              **PeiServices,\r
-  IN EFI_HOB_HANDOFF_INFO_TABLE    *OldHandOffHob,\r
+  IN CONST EFI_PEI_SERVICES                     **PeiServices,\r
+  IN UINTN                         OldCheckingBottom,\r
+  IN UINTN                         OldCheckingTop,\r
   IN EFI_HOB_HANDOFF_INFO_TABLE    *NewHandOffHob\r
   )\r
 /*++\r
@@ -451,9 +485,10 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  PeiServices   - The PEI core services table.\r
-  OldHandOffHob - The old handoff HOB list.\r
-  NewHandOffHob - The new handoff HOB list.\r
+  PeiServices       - The PEI core services table.\r
+  OldCheckingBottom - The old checking bottom.\r
+  OldCheckingTop    - The old checking top.\r
+  NewHandOffHob     - The new handoff HOB list.\r
 \r
 Returns:\r
 \r
index 1d2c8fc5df6fd7715777a7e36035212126226a55..08d6da475ac2d406c80e3994693937f87360a742 100644 (file)
   gEfiPeiFirmwareVolumeInfoPpiGuid\r
   gEfiPeiLoadFilePpiGuid\r
   gEfiPeiSecurity2PpiGuid\r
+  gEfiTemporaryRamSupportPpiGuid\r
 \r
 [FixedPcd.common]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeimDispatch\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeiCoreEntry\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize\r
+\r
 \r
 [FeaturePcd.common]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst\r
+\r
+[BuildOptions.common]\r
+  MSFT:*_*_*_CC_FLAGS = /Fa$* /FAsc /FR$(@R).SBR\r
index 4e2d9b10aa19749ff8dfd9fd3e042d6c80cc643d..a6feaeb91fb8ee64a4ebb4865c26c3f7c7f2a631 100644 (file)
@@ -122,6 +122,7 @@ Returns:
   PEI_CORE_INSTANCE                                     *OldCoreData;\r
   EFI_PEI_CPU_IO_PPI                                    *CpuIo;\r
   EFI_PEI_PCI_CFG2_PPI                                  *PciCfg;\r
+  PEI_CORE_ENTRY_POINT                                  ShadowedPeiCore;\r
 \r
   mTick = 0;\r
   OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
@@ -133,6 +134,16 @@ Returns:
   }\r
 \r
   if (OldCoreData != NULL) {\r
+    ShadowedPeiCore = (PEI_CORE_ENTRY_POINT) (UINTN) OldCoreData->ShadowedPeiCore;\r
+    if (ShadowedPeiCore != NULL) {\r
+      OldCoreData->ShadowedPeiCore = NULL;\r
+      ShadowedPeiCore (\r
+        SecCoreData,\r
+        PpiList,\r
+        OldCoreData\r
+        );\r
+    }\r
+\r
     CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
     \r
     CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
@@ -181,8 +192,8 @@ Returns:
       UINTN  StackValue;\r
 \r
       StackValue = INIT_CAR_VALUE;\r
-      for (StackPointer = (UINTN *) OldCoreData->TopOfCarHeap;\r
-           ((UINTN) StackPointer < ((UINTN) OldCoreData->MaxTopOfCarHeap))\r
+      for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
+           ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
            && StackValue == INIT_CAR_VALUE;\r
            StackPointer++) {\r
         StackValue = *StackPointer;\r
@@ -190,7 +201,7 @@ Returns:
       \r
       DEBUG ((EFI_D_INFO, "Total Cache as RAM:    %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
       DEBUG ((EFI_D_INFO, "  CAR stack ever used: %d bytes.\n",\r
-        ((UINTN) OldCoreData->MaxTopOfCarHeap - (UINTN) StackPointer)\r
+        ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
         ));\r
       DEBUG ((EFI_D_INFO, "  CAR heap used:       %d bytes.\n",\r
         ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
index 2ee45c44f7c1e5f387565ee9f82e85f171150ac6..bb358a25d32449e6718e00874daf3aa9861b960b 100644 (file)
@@ -1,13 +1,13 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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
-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
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+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
 \r
 Module Name:\r
 \r
@@ -50,14 +50,15 @@ Returns:
     PrivateData->PpiData.DispatchListEnd = MAX_PPI_DESCRIPTORS-1;\r
     PrivateData->PpiData.LastDispatchedNotify = MAX_PPI_DESCRIPTORS-1;\r
   }\r
\r
-  return;   \r
+\r
+  return;\r
 }\r
 \r
 VOID\r
 ConvertPpiPointers (\r
   IN CONST EFI_PEI_SERVICES                     **PeiServices,\r
-  IN EFI_HOB_HANDOFF_INFO_TABLE    *OldHandOffHob,\r
+  IN UINTN                         OldCheckingBottom,\r
+  IN UINTN                         OldCheckingTop,\r
   IN EFI_HOB_HANDOFF_INFO_TABLE    *NewHandOffHob\r
   )\r
 /*++\r
@@ -68,12 +69,13 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  PeiServices   - The PEI core services table.\r
-  OldHandOffHob - The old handoff HOB list.\r
-  NewHandOffHob - The new handoff HOB list.\r
+  PeiServices       - The PEI core services table.\r
+  OldCheckingBottom - The old checking bottom.\r
+  OldCheckingTop    - The old checking top.\r
+  NewHandOffHob     - The new handoff HOB list.\r
 \r
 Returns:\r
-            \r
+\r
 --*/\r
 {\r
   PEI_CORE_INSTANCE     *PrivateData;\r
@@ -83,15 +85,15 @@ Returns:
 \r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
 \r
-  Fixup = (UINTN)NewHandOffHob - (UINTN)OldHandOffHob;\r
-  \r
+  Fixup = (UINTN)NewHandOffHob - OldCheckingBottom;\r
+\r
   for (Index = 0; Index < MAX_PPI_DESCRIPTORS; Index++) {\r
     if (Index < PrivateData->PpiData.PpiListEnd ||\r
         Index > PrivateData->PpiData.NotifyListEnd) {\r
       PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];\r
-      \r
-      if (((UINTN)PpiPointer->Raw < (UINTN)OldHandOffHob->EfiFreeMemoryBottom) && \r
-          ((UINTN)PpiPointer->Raw >= (UINTN)OldHandOffHob)) {\r
+\r
+      if (((UINTN)PpiPointer->Raw < OldCheckingTop) &&\r
+          ((UINTN)PpiPointer->Raw >= OldCheckingBottom)) {\r
         //\r
         // Convert the pointer to the PEIM descriptor from the old HOB heap\r
         // to the relocated HOB heap.\r
@@ -102,9 +104,9 @@ Returns:
         // Only when the PEIM descriptor is in the old HOB should it be necessary\r
         // to try to convert the pointers in the PEIM descriptor\r
         //\r
-        \r
-        if (((UINTN)PpiPointer->Ppi->Guid < (UINTN)OldHandOffHob->EfiFreeMemoryBottom) && \r
-            ((UINTN)PpiPointer->Ppi->Guid >= (UINTN)OldHandOffHob)) {\r
+\r
+        if (((UINTN)PpiPointer->Ppi->Guid < OldCheckingTop) &&\r
+            ((UINTN)PpiPointer->Ppi->Guid >= OldCheckingBottom)) {\r
           //\r
           // Convert the pointer to the GUID in the PPI or NOTIFY descriptor\r
           // from the old HOB heap to the relocated HOB heap.\r
@@ -117,13 +119,13 @@ Returns:
         // the notification function in the NOTIFY descriptor needs not be converted.\r
         //\r
         if (Index < PrivateData->PpiData.PpiListEnd &&\r
-            (UINTN)PpiPointer->Ppi->Ppi < (UINTN)OldHandOffHob->EfiFreeMemoryBottom &&\r
-            (UINTN)PpiPointer->Ppi->Ppi >= (UINTN)OldHandOffHob) {\r
+            (UINTN)PpiPointer->Ppi->Ppi < OldCheckingTop &&\r
+            (UINTN)PpiPointer->Ppi->Ppi >= OldCheckingBottom) {\r
             //\r
             // Convert the pointer to the PPI interface structure in the PPI descriptor\r
             // from the old HOB heap to the relocated HOB heap.\r
             //\r
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi+ Fixup);   \r
+            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi+ Fixup);\r
         }\r
       }\r
     }\r
@@ -177,7 +179,7 @@ Returns:
   // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last\r
   // EFI_PEI_PPI_DESCRIPTOR in the list.\r
   //\r
-    \r
+\r
   for (;;) {\r
     //\r
     // Since PpiData is used for NotifyList and InstallList, max resource\r
@@ -187,7 +189,7 @@ Returns:
       return  EFI_OUT_OF_RESOURCES;\r
     }\r
     //\r
-    // Check if it is a valid PPI. \r
+    // Check if it is a valid PPI.\r
     // If not, rollback list to exclude all in this list.\r
     // Try to indicate which item failed.\r
     //\r
@@ -197,14 +199,14 @@ Returns:
       return  EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid)); \r
-    PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR*) PpiList;    \r
+    DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid));\r
+    PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR*) PpiList;\r
     PrivateData->PpiData.PpiListEnd++;\r
-    \r
+\r
     //\r
     // Continue until the end of the PPI List.\r
     //\r
-    if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==  \r
+    if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==\r
         EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {\r
       break;\r
     }\r
@@ -220,7 +222,7 @@ Returns:
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     LastCallbackInstall,\r
     PrivateData->PpiData.PpiListEnd,\r
-    PrivateData->PpiData.DispatchListEnd,                 \r
+    PrivateData->PpiData.DispatchListEnd,\r
     PrivateData->PpiData.NotifyListEnd\r
     );\r
 \r
@@ -286,7 +288,7 @@ Returns:
 \r
   //\r
   // Remove the old PPI from the database, add the new one.\r
-  // \r
+  //\r
   DEBUG((EFI_D_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));\r
   PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) NewPpi;\r
 \r
@@ -298,7 +300,7 @@ Returns:
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     Index,\r
     Index+1,\r
-    PrivateData->PpiData.DispatchListEnd,                 \r
+    PrivateData->PpiData.DispatchListEnd,\r
     PrivateData->PpiData.NotifyListEnd\r
     );\r
 \r
@@ -333,7 +335,7 @@ Arguments:
 \r
 Returns:\r
 \r
-  Status -  EFI_SUCCESS   if the PPI is in the database           \r
+  Status -  EFI_SUCCESS   if the PPI is in the database\r
             EFI_NOT_FOUND if the PPI is not in the database\r
 --*/\r
 {\r
@@ -342,7 +344,7 @@ Returns:
   EFI_GUID            *CheckGuid;\r
   EFI_PEI_PPI_DESCRIPTOR  *TempPtr;\r
 \r
-  \r
+\r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
 \r
   //\r
@@ -440,7 +442,7 @@ Returns:
     if (Index == PrivateData->PpiData.PpiListEnd - 1) {\r
       return  EFI_OUT_OF_RESOURCES;\r
     }\r
-    \r
+\r
     //\r
     // If some of the PPI data is invalid restore original Notify PPI database value\r
     //\r
@@ -449,13 +451,13 @@ Returns:
         DEBUG((EFI_D_ERROR, "ERROR -> InstallNotify: %g %x\n", NotifyList->Guid, NotifyList->Notify));\r
       return  EFI_INVALID_PARAMETER;\r
     }\r
-     \r
+\r
     if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) != 0) {\r
-      NotifyDispatchCount ++; \r
-    }        \r
-    \r
-    PrivateData->PpiData.PpiListPtrs[Index].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;      \r
-   \r
+      NotifyDispatchCount ++;\r
+    }\r
+\r
+    PrivateData->PpiData.PpiListPtrs[Index].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;\r
+\r
     PrivateData->PpiData.NotifyListEnd--;\r
     DEBUG((EFI_D_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));\r
     if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==\r
@@ -468,26 +470,26 @@ Returns:
     NotifyList++;\r
     Index--;\r
   }\r
\r
+\r
   //\r
-  // If there is Dispatch Notify PPI installed put them on the bottom \r
+  // If there is Dispatch Notify PPI installed put them on the bottom\r
   //\r
   if (NotifyDispatchCount > 0) {\r
-    for (NotifyIndex = LastCallbackNotify; NotifyIndex > PrivateData->PpiData.NotifyListEnd; NotifyIndex--) {             \r
+    for (NotifyIndex = LastCallbackNotify; NotifyIndex > PrivateData->PpiData.NotifyListEnd; NotifyIndex--) {\r
       if ((PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) != 0) {\r
         NotifyPtr = PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify;\r
-        \r
+\r
         for (Index = NotifyIndex; Index < PrivateData->PpiData.DispatchListEnd; Index++){\r
           PrivateData->PpiData.PpiListPtrs[Index].Notify = PrivateData->PpiData.PpiListPtrs[Index + 1].Notify;\r
         }\r
         PrivateData->PpiData.PpiListPtrs[Index].Notify = NotifyPtr;\r
-        PrivateData->PpiData.DispatchListEnd--;                \r
+        PrivateData->PpiData.DispatchListEnd--;\r
       }\r
     }\r
-    \r
-    LastCallbackNotify -= NotifyDispatchCount;        \r
+\r
+    LastCallbackNotify -= NotifyDispatchCount;\r
   }\r
-  \r
+\r
   //\r
   // Dispatch any callback level notifies for all previously installed PPIs.\r
   //\r
@@ -499,8 +501,8 @@ Returns:
     LastCallbackNotify,\r
     PrivateData->PpiData.NotifyListEnd\r
     );\r
-  \r
-  \r
+\r
+\r
   return  EFI_SUCCESS;\r
 }\r
 \r
@@ -525,13 +527,13 @@ Returns:
 \r
 {\r
   INTN                    TempValue;\r
\r
+\r
   while (TRUE) {\r
     //\r
     // Check if the PEIM that was just dispatched resulted in any\r
     // Notifies getting installed.  If so, go process any dispatch\r
     // level Notifies that match the previouly installed PPIs.\r
-    // Use "while" instead of "if" since DispatchNotify can modify \r
+    // Use "while" instead of "if" since DispatchNotify can modify\r
     // DispatchListEnd (with NotifyPpi) so we have to iterate until the same.\r
     //\r
     while (PrivateData->PpiData.LastDispatchedNotify != PrivateData->PpiData.DispatchListEnd) {\r
@@ -546,13 +548,13 @@ Returns:
         );\r
       PrivateData->PpiData.LastDispatchedNotify = TempValue;\r
     }\r
-    \r
-    \r
+\r
+\r
     //\r
     // Check if the PEIM that was just dispatched resulted in any\r
     // PPIs getting installed.  If so, go process any dispatch\r
     // level Notifies that match the installed PPIs.\r
-    // Use "while" instead of "if" since DispatchNotify can modify \r
+    // Use "while" instead of "if" since DispatchNotify can modify\r
     // PpiListEnd (with InstallPpi) so we have to iterate until the same.\r
     //\r
     while (PrivateData->PpiData.LastDispatchedInstall != PrivateData->PpiData.PpiListEnd) {\r
@@ -567,11 +569,11 @@ Returns:
         );\r
       PrivateData->PpiData.LastDispatchedInstall = TempValue;\r
     }\r
-    \r
+\r
     if (PrivateData->PpiData.LastDispatchedNotify == PrivateData->PpiData.DispatchListEnd) {\r
       break;\r
     }\r
-  } \r
+  }\r
   return;\r
 }\r
 \r
@@ -629,8 +631,8 @@ Returns:  None
           (((INT32 *)SearchGuid)[1] == ((INT32 *)CheckGuid)[1]) &&\r
           (((INT32 *)SearchGuid)[2] == ((INT32 *)CheckGuid)[2]) &&\r
           (((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3])) {\r
-        DEBUG ((EFI_D_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %x\n", \r
-          SearchGuid, \r
+        DEBUG ((EFI_D_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %x\n",\r
+          SearchGuid,\r
           NotifyDescriptor->Notify\r
           ));\r
         NotifyDescriptor->Notify (\r
index dbe872062fc189544bb0deb82ce62a5da51dd312..22ce7d5ecad60f5ee807a546d92dfc76f3b134ee 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries|40|UINT8|0x0001002f\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6|UINT32|0x00010030\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32|UINT32|0x00010031\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000|UINT32|0x00010032\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|0x30000001\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|0x30000002\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400|UINT32|0x30000003\r
index 59a6a56dd1171908f6fc3b6b5f138018747f175a..20211ff57250e4bf6ccaff1bc660e9abb2dc6c2d 100644 (file)
 \r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000\r
 \r
 \r
 [PcdsFixedAtBuild.IPF]\r
index 21669d717ea175b210f371bb35a51437153132de..21c2009143db3cc0b6fdd55572998a98580db748 100644 (file)
@@ -69,7 +69,7 @@ GetPeiServicesTablePointer (
 EFI_STATUS\r
 EFIAPI\r
 PeiServicesTablePointerLibConstructor (\r
-  IN EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN EFI_PEI_FILE_HANDLE  *FfsHeader,\r
   IN EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
@@ -77,17 +77,4 @@ PeiServicesTablePointerLibConstructor (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  After memory initialization in PEI phase, the IDT table in temporary memory should \r
-  be migrated to memory, and the address of PeiServicesPointer also need to be updated  \r
-  immediately preceding the new IDT table.\r
-  \r
-  @param    PeiServices   The address of PeiServices pointer.\r
-**/\r
-VOID\r
-MigrateIdtTable (\r
-  IN EFI_PEI_SERVICES  **PeiServices\r
-  )\r
-{\r
-}\r
 \r
index 961aea9010ae0e8cea92a7660c75e8243b5028ff..3680fbc78aaeaf6da50131e08865970ab5779c45 100644 (file)
@@ -74,20 +74,9 @@ SetPeiServicesTablePointer (
   EFI_PEI_SERVICES ** PeiServicesTablePointer\r
   )\r
 {\r
+  AsmWriteKr7 ((UINT64)(UINTN)PeiServicesTablePointer);\r
 }\r
   \r
-/**\r
-  After memory initialization in PEI phase, the IDT table in temporary memory should \r
-  be migrated to memory, and the address of PeiServicesPointer also need to be updated  \r
-  immediately preceding the new IDT table.\r
-  \r
-  @param    PeiServices   The address of PeiServices pointer.\r
-**/\r
-VOID\r
-MigrateIdtTable (\r
-  IN EFI_PEI_SERVICES  **PeiServices\r
-  )\r
-{\r
-}\r
+\r
 \r
 \r
index 0811cd66fb1a13bb8471c6aafa034d158145175c..28aac1dcf6a43fb7d97c0f19a844745bcc52b7c5 100644 (file)
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeDriverEnd|0x3040003|UINT32|0x30001014              # EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END\r
 \r
 [PcdsFixedAtBuild.IPF]\r
-  gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000|UINT64|0x0000000f\r
+  gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000|UINT64|0x0000000f  # comments\r
 \r
 [PcdsPatchableInModule.common]\r
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000|UINT64|0x0000000a\r
index bc2066fc46b891665ed4a9d7e349ae2aa1559101..bfdcbe3111ade6b3115ddbe95ee8e8f499976b73 100644 (file)
@@ -1,4 +1,7 @@
-/*++\r
+/*! \addtogroup Library EdkGenericBdsLib */\r
+/*@{ */\r
+/**@file \r
+  BDS library definition, include the file and data structure\r
 \r
 Copyright (c) 2006 - 2007, Intel Corporation\r
 All rights reserved. This program and the accompanying materials                          \r
@@ -9,15 +12,7 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
-Module Name:\r
-\r
-  BdsLib.h\r
-\r
-Abstract:\r
-\r
-  BDS library definition, include the file and data structure\r
-\r
---*/\r
+**/\r
 \r
 #ifndef _BDS_LIB_H_\r
 #define _BDS_LIB_H_\r
@@ -110,6 +105,11 @@ BdsLibBootNext (
   VOID\r
   );\r
 \r
+/*!\r
+ \fn BdsLibBootViaBootOption\r
+ \param BDS_COMMON_OPTION\r
+ \param EFI_DEVICE_PATH_PROTOCOL\r
+*/\r
 EFI_STATUS\r
 BdsLibBootViaBootOption (\r
   IN  BDS_COMMON_OPTION             * Option,\r
@@ -394,3 +394,4 @@ BdsLibGetHiiHandles (
   );\r
 \r
 #endif // _BDS_LIB_H_\r
+/*@} */
\ No newline at end of file
index f54d7ea733b121f969907cae12bc06ba6ad457a2..2d87f2d4f54298312ece1b802cc44e9ea08d9df0 100644 (file)
@@ -15,6 +15,7 @@
 #\r
 #**/\r
 \r
+\r
 ################################################################################\r
 #\r
 # Defines Section - statements that will be processed to create a Makefile.\r
@@ -22,6 +23,7 @@
 ################################################################################\r
 \r
 [Defines]\r
+\r
   DEC_SPECIFICATION              = 0x00010005\r
   PACKAGE_NAME                   = Nt32Pkg\r
   PACKAGE_GUID                   = 0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3\r
index e34191bcc9aa99a4907443bc6426cfdbcaec2888..2287ae725f7c69646de2b06b64b8b8bb901e7638 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE\r
 \r
 [PcdsFixedAtBuild.IA32]\r
+  #gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeRuntimeMemorySize|128\r
   gEfiNt32PkgTokenSpaceGuid.PcdWinNtMemorySizeForSecMain|L"64!64"|VOID*|12\r
index b931f803b8553a852f8475f3d6d03d8cd3fe7b34..edd69ad17343bf7b7c355d35c65c0a48871bdf50 100644 (file)
@@ -162,9 +162,9 @@ INF  IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf
 INF  Nt32Pkg/BootModePei/BootModePei.inf\r
 INF  Nt32Pkg/WinNtFlashMapPei/WinNtFlashMapPei.inf\r
 INF  MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf\r
-INF  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
 INF  Nt32Pkg/WinNtAutoScanPei/WinNtAutoScanPei.inf\r
 INF  Nt32Pkg/WinNtFirmwareVolumePei/WinNtFirmwareVolumePei.inf\r
+INF  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
 INF  Nt32Pkg/WinNtThunkPPIToProtocolPei/WinNtThunkPPIToProtocolPei.inf\r
 INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
 \r
index 4054d61bd04ea1307652aa74c9414580b2657be5..ccfc6bb3f8e0c679ca68ea8edeff434d1f74c9f1 100644 (file)
@@ -58,6 +58,7 @@ EFI_PEI_PROGRESS_CODE_PPI                 mSecStatusCodePpi     = { SecPeiReport
 \r
 NT_FWH_PPI                                mSecFwhInformationPpi = { SecWinNtFdAddress };\r
 \r
+TEMPORARY_RAM_SUPPORT_PPI                 mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};\r
 \r
 EFI_PEI_PPI_DESCRIPTOR  gPrivateDispatchTable[] = {\r
   {\r
@@ -85,6 +86,11 @@ EFI_PEI_PPI_DESCRIPTOR  gPrivateDispatchTable[] = {
     &gEfiPeiStatusCodePpiGuid,\r
     &mSecStatusCodePpi\r
   },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gEfiTemporaryRamSupportPpiGuid,\r
+    &mSecTemporaryRamSupportPpi\r
+  },\r
   {\r
     EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
     &gNtFwhPpiGuid,\r
@@ -116,7 +122,12 @@ UINTN                   mPdbNameModHandleArraySize = 0;
 PDB_NAME_TO_MOD_HANDLE  *mPdbNameModHandleArray = NULL;\r
 \r
 \r
-\r
+VOID\r
+EFIAPI\r
+SecSwitchStack (\r
+  UINT32   TemporaryMemoryBase,\r
+  UINT32   PermenentMemoryBase\r
+  );\r
 \r
 INTN\r
 EFIAPI\r
@@ -566,18 +577,31 @@ Returns:
   EFI_PHYSICAL_ADDRESS        PeiCoreEntryPoint;\r
   EFI_PHYSICAL_ADDRESS        PeiImageAddress;\r
   EFI_SEC_PEI_HAND_OFF        *SecCoreData;\r
+  UINTN                       PeiStackSize;\r
 \r
   //\r
   // Compute Top Of Memory for Stack and PEI Core Allocations\r
   //\r
-  TopOfMemory = LargestRegion + LargestRegionSize;\r
+  TopOfMemory  = LargestRegion + LargestRegionSize;\r
+  PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
 \r
   //\r
-  // Allocate 128KB for the Stack\r
+  // |-----------| <---- TemporaryRamBase + TemporaryRamSize\r
+  // |   Heap    |\r
+  // |           |\r
+  // |-----------| <---- StackBase / PeiTemporaryMemoryBase\r
+  // |           |\r
+  // |  Stack    |\r
+  // |-----------| <---- TemporaryRamBase\r
+  // \r
+  TopOfStack  = (VOID *)(LargestRegion + PeiStackSize);\r
+  TopOfMemory = LargestRegion + PeiStackSize;\r
+\r
   //\r
-  TopOfStack  = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);\r
+  // Reservet space for storing PeiCore's parament in stack.\r
+  // \r
+  TopOfStack  = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);\r
   TopOfStack  = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
-  TopOfMemory = TopOfMemory - STACK_SIZE;\r
 \r
   //\r
   // Patch value in dispatch table values\r
@@ -591,12 +615,12 @@ Returns:
   SecCoreData->DataSize               = sizeof(EFI_SEC_PEI_HAND_OFF);\r
   SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;\r
   SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdWinNtFirmwareFdSize);\r
-  SecCoreData->TemporaryRamBase       = (VOID*)(UINTN)TopOfMemory\r
+  SecCoreData->TemporaryRamBase       = (VOID*)(UINTN)LargestRegion\r
   SecCoreData->TemporaryRamSize       = STACK_SIZE;\r
-  SecCoreData->PeiTemporaryRamBase    = SecCoreData->TemporaryRamBase;\r
-  SecCoreData->PeiTemporaryRamSize    = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
-  SecCoreData->StackBase              = (VOID*)((UINTN)SecCoreData->TemporaryRamBase + (UINTN)SecCoreData->TemporaryRamSize);\r
-  SecCoreData->StackSize              = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
+  SecCoreData->StackBase              = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);\r
+  SecCoreData->StackSize              = PeiStackSize;\r
+  SecCoreData->PeiTemporaryRamBase    = SecCoreData->StackBase;\r
+  SecCoreData->PeiTemporaryRamSize    = STACK_SIZE - PeiStackSize;\r
 \r
   //\r
   // Load the PEI Core from a Firmware Volume\r
@@ -1209,3 +1233,44 @@ _ModuleEntryPoint (
 {\r
 }\r
 \r
+EFI_STATUS\r
+EFIAPI\r
+SecTemporaryRamSupport (\r
+  IN CONST EFI_PEI_SERVICES   **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,\r
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,\r
+  IN UINTN                    CopySize\r
+  )\r
+{\r
+  //\r
+  // Migrate the whole temporary memory to permenent memory.\r
+  // \r
+  CopyMem (\r
+    (VOID*)(UINTN)PermanentMemoryBase, \r
+    (VOID*)(UINTN)TemporaryMemoryBase, \r
+    CopySize\r
+    );\r
+\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
+  // \r
+  SecSwitchStack (\r
+    (UINT32) TemporaryMemoryBase,\r
+    (UINT32) PermanentMemoryBase\r
+    );\r
+\r
+  //\r
+  // We need *not* fix the return address because currently, \r
+  // The PeiCore is excuted in flash.\r
+  //\r
+\r
+  //\r
+  // Simulate to invalid CAR, terminate CAR\r
+  // \r
+  //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
index 7102d5f5fa2defdb65095634858ce5506cd30260..1f54fd0dd22fc7d2b23816e2a1c7f3bc8ffbbdb0 100644 (file)
@@ -31,6 +31,7 @@ Abstract:
 #include <Ppi/NtThunk.h>\r
 #include <Ppi/StatusCode.h>\r
 #include <Ppi/NtFwh.h>\r
+#include <Ppi/TemporaryRamSupport.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PrintLib.h>\r
@@ -576,6 +577,14 @@ SecNt32PeCoffUnloadimage (
   IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
   );\r
 \r
+EFI_STATUS\r
+EFIAPI\r
+SecTemporaryRamSupport (\r
+  IN CONST EFI_PEI_SERVICES   **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,\r
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,\r
+  IN UINTN                    CopySize\r
+  );\r
 \r
 typedef struct {\r
   EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;\r
index 20e4726465f3d7edad9773d5afa7132548ff6218..95cd30e2ea833b7175d869491ab0f1d799c67900 100644 (file)
@@ -33,6 +33,7 @@
   WinNtThunk.c\r
   FwVol.c\r
   SecMain.c\r
+  Stack.asm\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
@@ -58,6 +59,7 @@
   gNtFwhPpiGuid                                 # PPI ALWAYS_PRODUCED\r
   gPeiNtAutoScanPpiGuid                         # PPI ALWAYS_PRODUCED\r
   gPeiNtThunkPpiGuid                            # PPI ALWAYS_PRODUCED\r
+  gEfiTemporaryRamSupportPpiGuid\r
 \r
 \r
 [FixedPcd.common]\r
@@ -69,4 +71,6 @@
 [BuildOptions.common]\r
   MSFT:*_*_IA32_DLINK_FLAGS = /out:"$(BIN_DIR)\SecMain.exe" /base:0x10000000 /pdb:"$(BIN_DIR)\SecMain.pdb" /LIBPATH:"$(VCINSTALLDIR)\Lib" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib\r
   MSFT:*_*_IA32_CC_FLAGS = /nologo /W4 /WX /Gy /c /D UNICODE /Od /FI$(DEST_DIR_DEBUG)/AutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE\r
-\r
+  MSFT:*_*_IA32_PP_FLAGS = /nologo /E /TC /FI$(DEST_DIR_DEBUG)/AutoGen.h\r
+  MSFT:*_*_IA32_ASM_FLAGS = /nologo /W3 /WX /c /coff /Cx /Zd /W0 /Zi\r
+  MSFT:*_*_IA32_ASMLINK_FLAGS       = /link /nologo /tiny\r
diff --git a/Nt32Pkg/Sec/Stack.asm b/Nt32Pkg/Sec/Stack.asm
new file mode 100644 (file)
index 0000000..ca6b7fa
--- /dev/null
@@ -0,0 +1,94 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+; 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
+;\r
+; Module Name:\r
+;\r
+;   Stack.asm\r
+;\r
+; Abstract:\r
+;\r
+;   Switch the stack from temporary memory to permenent memory.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    .586p\r
+    .model  flat,C\r
+    .code\r
+    \r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; SecSwitchStack (\r
+;   UINT32   TemporaryMemoryBase,\r
+;   UINT32   PermenentMemoryBase\r
+;   );\r
+;------------------------------------------------------------------------------    \r
+SecSwitchStack   PROC\r
+    ;\r
+    ; Save three register: eax, ebx, ecx\r
+    ;\r
+    push  eax\r
+    push  ebx\r
+    push  ecx\r
+    push  edx\r
+    \r
+    ;\r
+    ; !!CAUTION!! this function address's is pushed into stack after\r
+    ; migration of whole temporary memory, so need save it to permenent\r
+    ; memory at first!\r
+    ;\r
+    \r
+    mov   ebx, [esp + 20]          ; Save the first parameter\r
+    mov   ecx, [esp + 24]          ; Save the second parameter\r
+    \r
+    ;\r
+    ; Save this function's return address into permenent memory at first.\r
+    ; Then, Fixup the esp point to permenent memory\r
+    ;\r
+    mov   eax, esp\r
+    sub   eax, ebx\r
+    add   eax, ecx\r
+    mov   edx, dword ptr [esp]         ; copy pushed register's value to permenent memory\r
+    mov   dword ptr [eax], edx    \r
+    mov   edx, dword ptr [esp + 4]\r
+    mov   dword ptr [eax + 4], edx    \r
+    mov   edx, dword ptr [esp + 8]\r
+    mov   dword ptr [eax + 8], edx    \r
+    mov   edx, dword ptr [esp + 12]\r
+    mov   dword ptr [eax + 12], edx    \r
+    mov   edx, dword ptr [esp + 16]    ; Update this function's return address into permenent memory\r
+    mov   dword ptr [eax + 16], edx    \r
+    mov   esp, eax                     ; From now, esp is pointed to permenent memory\r
+        \r
+    ;\r
+    ; Fixup the ebp point to permenent memory\r
+    ;\r
+    mov   eax, ebp\r
+    sub   eax, ebx\r
+    add   eax, ecx\r
+    mov   ebp, eax                ; From now, ebp is pointed to permenent memory\r
+    \r
+    ;\r
+    ; Fixup callee's ebp point for PeiDispatch\r
+    ;\r
+    mov   eax, dword ptr [ebp]\r
+    sub   eax, ebx\r
+    add   eax, ecx\r
+    mov   dword ptr [ebp], eax    ; From now, Temporary's PPI caller's stack is in permenent memory\r
+    \r
+    pop   edx\r
+    pop   ecx\r
+    pop   ebx\r
+    pop   eax\r
+    ret\r
+SecSwitchStack   ENDP\r
+\r
+    END\r