]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
Merge branch 'master' of https://github.com/tianocore/edk2
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.c
index 496638a17ed1bca43b955199b6662c8901ad069d..551560b1fce1e92466e271065c83855f39d14565 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMM Core Main Entry Point\r
 \r
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available \r
   under the terms and conditions of the BSD License which accompanies this \r
   distribution.  The full text of the license may be found at        \r
@@ -87,6 +87,8 @@ SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[] = {
 UINTN                           mFullSmramRangeCount;\r
 EFI_SMRAM_DESCRIPTOR            *mFullSmramRanges;\r
 \r
+EFI_LOADED_IMAGE_PROTOCOL       *mSmmCoreLoadedImage;\r
+\r
 /**\r
   Place holder function until all the SMM System Table Service are available.\r
 \r
@@ -432,9 +434,13 @@ SmmEntryPoint (
   PERF_START (NULL, "SMM", NULL, 0) ;\r
 \r
   //\r
-  // Update SMST using the context\r
+  // Update SMST with contents of the SmmEntryContext structure\r
   //\r
-  CopyMem (&gSmmCoreSmst.SmmStartupThisAp, SmmEntryContext, sizeof (EFI_SMM_ENTRY_CONTEXT));\r
+  gSmmCoreSmst.SmmStartupThisAp      = SmmEntryContext->SmmStartupThisAp;\r
+  gSmmCoreSmst.CurrentlyExecutingCpu = SmmEntryContext->CurrentlyExecutingCpu;\r
+  gSmmCoreSmst.NumberOfCpus          = SmmEntryContext->NumberOfCpus;\r
+  gSmmCoreSmst.CpuSaveStateSize      = SmmEntryContext->CpuSaveStateSize;\r
+  gSmmCoreSmst.CpuSaveState          = SmmEntryContext->CpuSaveState;\r
 \r
   //\r
   // Call platform hook before Smm Dispatch\r
@@ -516,6 +522,51 @@ SmmEntryPoint (
   PERF_END (NULL, "SMM", NULL, 0) ;\r
 }\r
 \r
+/**\r
+  Install LoadedImage protocol for SMM Core.\r
+**/\r
+VOID\r
+SmmCoreInstallLoadedImage (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_HANDLE                 Handle;\r
+\r
+  //\r
+  // Allocate a Loaded Image Protocol in EfiBootServicesData\r
+  //\r
+  Status = gBS->AllocatePool (EfiBootServicesData, sizeof(EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ZeroMem (mSmmCoreLoadedImage, sizeof (EFI_LOADED_IMAGE_PROTOCOL));\r
+  //\r
+  // Fill in the remaining fields of the Loaded Image Protocol instance.\r
+  // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.\r
+  //\r
+  mSmmCoreLoadedImage->Revision      = EFI_LOADED_IMAGE_PROTOCOL_REVISION;\r
+  mSmmCoreLoadedImage->ParentHandle  = gSmmCorePrivate->SmmIplImageHandle;\r
+  mSmmCoreLoadedImage->SystemTable   = gST;\r
+\r
+  mSmmCoreLoadedImage->ImageBase     = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;\r
+  mSmmCoreLoadedImage->ImageSize     = gSmmCorePrivate->PiSmmCoreImageSize;\r
+  mSmmCoreLoadedImage->ImageCodeType = EfiRuntimeServicesCode;\r
+  mSmmCoreLoadedImage->ImageDataType = EfiRuntimeServicesData;\r
+\r
+  //\r
+  // Create a new image handle in the UEFI handle database for the SMM Driver\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiLoadedImageProtocolGuid, mSmmCoreLoadedImage,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return ;\r
+}\r
+\r
 /**\r
   The Entry Point for SMM Core\r
 \r
@@ -581,6 +632,9 @@ SmmMain (
   }\r
 \r
   RegisterSmramProfileHandler ();\r
+  SmramProfileInstallProtocol ();\r
+\r
+  SmmCoreInstallLoadedImage ();\r
 \r
   return EFI_SUCCESS;\r
 }\r