]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
1) Initialize gBS, gST, gImageHandle in UefiBootServicesTableLib.c to NULL
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / DxeMain / DxeMain.c
index b590538feaefc04d03c758070b9b9ce72a28e39c..1e31a8899e753e33737722b7bb73f49a805af4e7 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 - 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
@@ -67,7 +67,7 @@ EFI_BOOT_SERVICES mBootServices = {
     sizeof (EFI_BOOT_SERVICES),                                                           // HeaderSize\r
     0,                                                                                    // CRC32\r
     0                                                                                     // Reserved\r
-  },                                                                                      \r
+  },\r
   (EFI_RAISE_TPL)                               CoreRaiseTpl,                             // RaiseTPL\r
   (EFI_RESTORE_TPL)                             CoreRestoreTpl,                           // RestoreTPL\r
   (EFI_ALLOCATE_PAGES)                          CoreAllocatePages,                        // AllocatePages\r
@@ -110,11 +110,8 @@ EFI_BOOT_SERVICES mBootServices = {
   (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)  CoreUninstallMultipleProtocolInterfaces,  // UninstallMultipleProtocolInterfaces\r
   (EFI_CALCULATE_CRC32)                         CoreEfiNotAvailableYetArg3,               // CalculateCrc32\r
   (EFI_COPY_MEM)                                CopyMem,                                  // CopyMem\r
-  (EFI_SET_MEM)                                 SetMem                                    // SetMem\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-  ,                                   \r
-  (EFI_CREATE_EVENT_EX)                          CoreCreateEventEx                         // CreateEventEx\r
-#endif\r
+  (EFI_SET_MEM)                                 SetMem,                                   // SetMem\r
+  (EFI_CREATE_EVENT_EX)                         CoreCreateEventEx                         // CreateEventEx\r
 };\r
 \r
 EFI_DXE_SERVICES mDxeServices = {\r
@@ -174,33 +171,20 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
     0,                                                            // CRC32\r
     0                                                             // Reserved\r
   },\r
-  (EFI_GET_TIME)                 CoreEfiNotAvailableYetArg2,      // GetTime\r
-  (EFI_SET_TIME)                 CoreEfiNotAvailableYetArg1,      // SetTime\r
-  (EFI_GET_WAKEUP_TIME)          CoreEfiNotAvailableYetArg3,      // GetWakeupTime\r
-  (EFI_SET_WAKEUP_TIME)          CoreEfiNotAvailableYetArg2,      // SetWakeupTime\r
-  (EFI_SET_VIRTUAL_ADDRESS_MAP)  CoreEfiNotAvailableYetArg4,      // SetVirtualAddressMap\r
-  (EFI_CONVERT_POINTER)          CoreEfiNotAvailableYetArg2,      // ConvertPointer\r
-  (EFI_GET_VARIABLE)             CoreEfiNotAvailableYetArg5,      // GetVariable\r
-  (EFI_GET_NEXT_VARIABLE_NAME)   CoreEfiNotAvailableYetArg3,      // GetNextVariableName\r
-  (EFI_SET_VARIABLE)             CoreEfiNotAvailableYetArg5,      // SetVariable\r
-  (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1,      // GetNextHighMonotonicCount\r
-  (EFI_RESET_SYSTEM)             CoreEfiNotAvailableYetArg4       // ResetSystem \r
-#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION <  0x00020000))\r
-  //\r
-  // This Tiano extension was removed when UEFI 2.0 support was added. \r
-  // It's now just a protocol.\r
-  //\r
-  ,\r
-  (EFI_REPORT_STATUS_CODE)       CoreEfiNotAvailableYetArg5       // ReportStatusCode\r
-#elif (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-  //\r
-  // New runtime services added by UEFI 2.0\r
-  //\r
-  ,\r
+  (EFI_GET_TIME)                    CoreEfiNotAvailableYetArg2,   // GetTime\r
+  (EFI_SET_TIME)                    CoreEfiNotAvailableYetArg1,   // SetTime\r
+  (EFI_GET_WAKEUP_TIME)             CoreEfiNotAvailableYetArg3,   // GetWakeupTime\r
+  (EFI_SET_WAKEUP_TIME)             CoreEfiNotAvailableYetArg2,   // SetWakeupTime\r
+  (EFI_SET_VIRTUAL_ADDRESS_MAP)     CoreEfiNotAvailableYetArg4,   // SetVirtualAddressMap\r
+  (EFI_CONVERT_POINTER)             CoreEfiNotAvailableYetArg2,   // ConvertPointer\r
+  (EFI_GET_VARIABLE)                CoreEfiNotAvailableYetArg5,   // GetVariable\r
+  (EFI_GET_NEXT_VARIABLE_NAME)      CoreEfiNotAvailableYetArg3,   // GetNextVariableName\r
+  (EFI_SET_VARIABLE)                CoreEfiNotAvailableYetArg5,   // SetVariable\r
+  (EFI_GET_NEXT_HIGH_MONO_COUNT)    CoreEfiNotAvailableYetArg1,   // GetNextHighMonotonicCount\r
+  (EFI_RESET_SYSTEM)                CoreEfiNotAvailableYetArg4,   // ResetSystem\r
   (EFI_UPDATE_CAPSULE)              CoreEfiNotAvailableYetArg3,   // UpdateCapsule\r
   (EFI_QUERY_CAPSULE_CAPABILITIES)  CoreEfiNotAvailableYetArg4,   // QueryCapsuleCapabilities\r
   (EFI_QUERY_VARIABLE_INFO)         CoreEfiNotAvailableYetArg4    // QueryVariableInfo\r
-#endif\r
 };\r
 \r
 EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
@@ -212,8 +196,8 @@ EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
   // prevent people from having pointer math bugs in their code.\r
   // now you have to use *DescriptorSize to make things work.\r
   //\r
-  sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),  \r
-  EFI_MEMORY_DESCRIPTOR_VERSION, \r
+  sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),\r
+  EFI_MEMORY_DESCRIPTOR_VERSION,\r
   0,\r
   NULL,\r
   NULL,\r
@@ -224,19 +208,19 @@ EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
 EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
 \r
 //\r
-// DXE Core Global Variables for the EFI System Table, Boot Services Table, \r
+// DXE Core Global Variables for the EFI System Table, Boot Services Table,\r
 // DXE Services Table, and Runtime Services Table\r
 //\r
-EFI_BOOT_SERVICES     *gBS = &mBootServices;\r
-EFI_DXE_SERVICES      *gDS = &mDxeServices;\r
-EFI_SYSTEM_TABLE      *gST = NULL;\r
+EFI_BOOT_SERVICES     *gDxeCoreBS = &mBootServices;\r
+EFI_DXE_SERVICES      *gDxeCoreDS = &mDxeServices;\r
+EFI_SYSTEM_TABLE      *gDxeCoreST = NULL;\r
 \r
 //\r
-// For debug initialize gRT to template. gRT must be allocated from RT memory\r
-//  but gRT is used for ASSERT () and DEBUG () type macros so lets give it\r
+// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory\r
+//  but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it\r
 //  a value that will not cause debug infrastructure to crash early on.\r
 //\r
-EFI_RUNTIME_SERVICES  *gRT = &mEfiRuntimeServicesTableTemplate;\r
+EFI_RUNTIME_SERVICES  *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
 EFI_HANDLE            gDxeCoreImageHandle = NULL;\r
 \r
 VOID  *mHobStart;\r
@@ -304,14 +288,14 @@ Returns:
   // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
   // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
   //\r
-  gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
-  ASSERT (gST != NULL);\r
+  gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
+  ASSERT (gDxeCoreST != NULL);\r
 \r
-  gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
-  ASSERT (gRT != NULL);\r
+  gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
+  ASSERT (gDxeCoreRT != NULL);\r
+\r
+  gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
 \r
-  gST->RuntimeServices = gRT;\r
-  \r
   //\r
   // Start the Image Services.\r
   //\r
@@ -321,7 +305,7 @@ Returns:
   //\r
   // Call constructor for all libraries\r
   //\r
-  ProcessLibraryConstructorList (gDxeCoreImageHandle, gST);\r
+  ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
   PERF_END   (0,PEI_TOK, NULL, 0) ;\r
   PERF_START (0,DXE_TOK, NULL, 0) ;\r
 \r
@@ -334,7 +318,7 @@ Returns:
   //\r
   // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
   //\r
-  Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS);\r
+  Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -350,16 +334,9 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Initialize the ReportStatusCode with PEI version, if availible\r
+  // Initialize the ReportStatusCode with PEI version, if available\r
   //\r
   CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode);\r
-#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
-  //\r
-  // This Tiano extension was removed when UEFI 2.0 support was added. \r
-  // It's now just a protocol.\r
-  //\r
-  gRT->ReportStatusCode = gStatusCode->ReportStatusCode;\r
-#endif\r
 \r
   //\r
   // Report Status Code here for DXE_ENTRY_POINT once it is available\r
@@ -386,22 +363,22 @@ Returns:
   Status = CoreInitializeEventServices ();\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-   \r
+\r
   //\r
   // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
   //\r
-  // These Protocols are not architectural. This implementation is sharing code between \r
-  // PEI and DXE in order to save FLASH space. These Protocols could also be implemented \r
-  // as part of the DXE Core. However, that would also require the DXE Core to be ported \r
-  // each time a different CPU is used, a different Decompression algorithm is used, or a \r
-  // different Image type is used. By placing these Protocols in PEI, the DXE Core remains \r
-  // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, \r
+  // These Protocols are not architectural. This implementation is sharing code between\r
+  // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
+  // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
+  // each time a different CPU is used, a different Decompression algorithm is used, or a\r
+  // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
+  // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
   // and from CPU to CPU.\r
   //\r
 \r
   //\r
   // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
-  //   \r
+  //\r
   Status = CoreInstallMultipleProtocolInterfaces (\r
               &mDecompressHandle,\r
               &gEfiDecompressProtocolGuid,           &gEfiDecompress,\r
@@ -423,16 +400,16 @@ Returns:
   //\r
   // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
   //\r
-  Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST);\r
+  Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = FwVolDriverInit (gDxeCoreImageHandle, gST);\r
+  Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Produce the Section Extraction Protocol \r
+  // Produce the Section Extraction Protocol\r
   //\r
-  Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST);\r
+  Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -455,7 +432,7 @@ Returns:
   DEBUG_CODE_BEGIN ();\r
     CoreDisplayMissingArchProtocols ();\r
   DEBUG_CODE_END ();\r
-  \r
+\r
   //\r
   // Assert if the Architectural Protocols are not present.\r
   //\r
@@ -477,7 +454,7 @@ Returns:
   // Transfer control to the BDS Architectural Protocol\r
   //\r
   gBds->Entry (gBds);\r
-  \r
+\r
   //\r
   // BDS should never return\r
   //\r
@@ -561,7 +538,7 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
 \r
 Returns:\r
@@ -595,9 +572,9 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
-  \r
+\r
   Arg3        - Undefined\r
 \r
 Returns:\r
@@ -632,11 +609,11 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
-  \r
+\r
   Arg3        - Undefined\r
-  \r
+\r
   Arg4        - Undefined\r
 \r
 Returns:\r
@@ -672,13 +649,13 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
-  \r
+\r
   Arg3        - Undefined\r
-  \r
+\r
   Arg4        - Undefined\r
-  \r
+\r
   Arg5        - Undefined\r
 \r
 Returns:\r
@@ -729,7 +706,7 @@ Returns:
   if (GuidHob == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   Buffer = GET_GUID_HOB_DATA (GuidHob);\r
   ASSERT (Buffer != NULL);\r
 \r
@@ -763,14 +740,14 @@ Returns:
   UINT32 Crc;\r
 \r
   Hdr->CRC32 = 0;\r
-  \r
+\r
   //\r
-  // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
+  // If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
   //  Crc will come back as zero if we set it to zero here\r
   //\r
   Crc = 0;\r
-  gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
-  Hdr->CRC32 = Crc; \r
+  gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
+  Hdr->CRC32 = Crc;\r
 }\r
 \r
 \r
@@ -835,30 +812,30 @@ Returns:
   //\r
   // Clear the non-runtime values of the EFI System Table\r
   //\r
-  gST->BootServices        = NULL;\r
-  gST->ConIn               = NULL;\r
-  gST->ConsoleInHandle     = NULL;\r
-  gST->ConOut              = NULL;\r
-  gST->ConsoleOutHandle    = NULL;\r
-  gST->StdErr              = NULL;\r
-  gST->StandardErrorHandle = NULL;\r
+  gDxeCoreST->BootServices        = NULL;\r
+  gDxeCoreST->ConIn               = NULL;\r
+  gDxeCoreST->ConsoleInHandle     = NULL;\r
+  gDxeCoreST->ConOut              = NULL;\r
+  gDxeCoreST->ConsoleOutHandle    = NULL;\r
+  gDxeCoreST->StdErr              = NULL;\r
+  gDxeCoreST->StandardErrorHandle = NULL;\r
 \r
   //\r
   // Recompute the 32-bit CRC of the EFI System Table\r
   //\r
-  CalculateEfiHdrCrc (&gST->Hdr);\r
+  CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
 \r
   //\r
   // Zero out the Boot Service Table\r
   //\r
-  SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);\r
-  gBS = NULL;\r
-  \r
+  SetMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES), 0);\r
+  gDxeCoreBS = NULL;\r
+\r
   //\r
   // Update the AtRuntime field in Runtiem AP.\r
   //\r
   gRuntime->AtRuntime = TRUE;\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -871,6 +848,11 @@ DxeMainUefiDecompressGetInfo (
   OUT  UINT32                           *ScratchSize\r
   )\r
 {\r
+  if (Source == NULL \r
+        || DestinationSize == NULL \r
+        || ScratchSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
   return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
@@ -889,7 +871,13 @@ DxeMainUefiDecompress (
   EFI_STATUS  Status;\r
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
-\r
+  \r
+  if (Source == NULL \r
+        || Destination== NULL \r
+        || Scratch == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -911,6 +899,12 @@ DxeMainTianoDecompressGetInfo (
   OUT  UINT32                           *ScratchSize\r
   )\r
 {\r
+  if (Source == NULL \r
+        || DestinationSize == NULL \r
+        || ScratchSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   return TianoDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
@@ -929,7 +923,13 @@ DxeMainTianoDecompress (
   EFI_STATUS  Status;\r
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
-\r
+  \r
+  if (Source == NULL \r
+        || Destination== NULL \r
+        || Scratch == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   Status = TianoDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -951,6 +951,12 @@ DxeMainCustomDecompressGetInfo (
   OUT  UINT32                            *ScratchSize\r
   )\r
 {\r
+  if (Source == NULL \r
+        || DestinationSize == NULL \r
+        || ScratchSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   return CustomDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
@@ -970,6 +976,12 @@ DxeMainCustomDecompress (
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
 \r
+  if (Source == NULL \r
+        || Destination== NULL \r
+        || Scratch == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Status = CustomDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r