X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkModulePkg%2FCore%2FDxe%2FDxeMain%2FDxeMain.c;h=1e31a8899e753e33737722b7bb73f49a805af4e7;hp=24568ea334456141f08d306c05ce489712aa1139;hb=abb234751e4fbe58afc5e7c7e203db2a93aac0f8;hpb=a537f1483c1312f9a937b7ec854396170006ff8d diff --git a/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c b/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c index 24568ea334..1e31a8899e 100644 --- a/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -1,13 +1,13 @@ /*++ -Copyright (c) 2006, Intel Corporation -All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2007, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: @@ -21,127 +21,6 @@ Abstract: #include -VOID -EFIAPI -DxeMain ( - IN VOID *HobStart - ); - -EFI_STATUS -EFIAPI -CoreEfiNotAvailableYetArg0 ( - VOID - ); - -EFI_STATUS -EFIAPI -CoreEfiNotAvailableYetArg1 ( - UINTN Arg1 - ); - -EFI_STATUS -EFIAPI -CoreEfiNotAvailableYetArg2 ( - UINTN Arg1, - UINTN Arg2 - ); - -EFI_STATUS -EFIAPI -CoreEfiNotAvailableYetArg3 ( - UINTN Arg1, - UINTN Arg2, - UINTN Arg3 - ); - -EFI_STATUS -EFIAPI -CoreEfiNotAvailableYetArg4 ( - UINTN Arg1, - UINTN Arg2, - UINTN Arg3, - UINTN Arg4 - ); - -EFI_STATUS -EFIAPI -CoreEfiNotAvailableYetArg5 ( - UINTN Arg1, - UINTN Arg2, - UINTN Arg3, - UINTN Arg4, - UINTN Arg5 - ); - -EFI_STATUS -CoreGetPeiProtocol ( - IN EFI_GUID *ProtocolGuid, - IN VOID **Interface - ); - -EFI_STATUS -DxeMainUefiDecompressGetInfo ( - IN EFI_DECOMPRESS_PROTOCOL *This, - IN VOID *Source, - IN UINT32 SourceSize, - OUT UINT32 *DestinationSize, - OUT UINT32 *ScratchSize - ); - -EFI_STATUS -EFIAPI -DxeMainUefiDecompress ( - IN EFI_DECOMPRESS_PROTOCOL *This, - IN VOID *Source, - IN UINT32 SourceSize, - IN OUT VOID *Destination, - IN UINT32 DestinationSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ); - -EFI_STATUS -DxeMainTianoDecompressGetInfo ( - IN EFI_TIANO_DECOMPRESS_PROTOCOL *This, - IN VOID *Source, - IN UINT32 SourceSize, - OUT UINT32 *DestinationSize, - OUT UINT32 *ScratchSize - ); - -EFI_STATUS -EFIAPI -DxeMainTianoDecompress ( - IN EFI_TIANO_DECOMPRESS_PROTOCOL *This, - IN VOID *Source, - IN UINT32 SourceSize, - IN OUT VOID *Destination, - IN UINT32 DestinationSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ); - -EFI_STATUS -DxeMainCustomDecompressGetInfo ( - IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This, - IN VOID *Source, - IN UINT32 SourceSize, - OUT UINT32 *DestinationSize, - OUT UINT32 *ScratchSize - ); - -EFI_STATUS -EFIAPI -DxeMainCustomDecompress ( - IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL *This, - IN VOID *Source, - IN UINT32 SourceSize, - IN OUT VOID *Destination, - IN UINT32 DestinationSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ); - // // DXE Core Global Variables for Protocols from PEI // @@ -157,7 +36,7 @@ EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL; EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL; EFI_BDS_ARCH_PROTOCOL *gBds = NULL; EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL; -EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = NULL; + // // BugBug: I'n not runtime, but is the PPI? @@ -188,7 +67,7 @@ EFI_BOOT_SERVICES mBootServices = { sizeof (EFI_BOOT_SERVICES), // HeaderSize 0, // CRC32 0 // Reserved - }, + }, (EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL (EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL (EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages @@ -231,11 +110,8 @@ EFI_BOOT_SERVICES mBootServices = { (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces (EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32 (EFI_COPY_MEM) CopyMem, // CopyMem - (EFI_SET_MEM) SetMem // SetMem -#if (EFI_SPECIFICATION_VERSION >= 0x00020000) - , - (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx -#endif + (EFI_SET_MEM) SetMem, // SetMem + (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx }; EFI_DXE_SERVICES mDxeServices = { @@ -295,49 +171,56 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = { 0, // CRC32 0 // Reserved }, - (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime - (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime - (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime - (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime - (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap - (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer - (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable - (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName - (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable - (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount - (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4 // ResetSystem -#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000)) - // - // This Tiano extension was removed when UEFI 2.0 support was added. - // It's now just a protocol. - // - , - (EFI_REPORT_STATUS_CODE) CoreEfiNotAvailableYetArg5 // ReportStatusCode -#elif (EFI_SPECIFICATION_VERSION >= 0x00020000) - // - // New runtime services added by UEFI 2.0 - // - , + (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime + (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime + (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime + (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime + (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap + (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer + (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable + (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName + (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable + (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount + (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo -#endif }; +EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = { + INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead), + INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead), + + // + // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will + // prevent people from having pointer math bugs in their code. + // now you have to use *DescriptorSize to make things work. + // + sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)), + EFI_MEMORY_DESCRIPTOR_VERSION, + 0, + NULL, + NULL, + FALSE, + FALSE +}; + +EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate; + // -// DXE Core Global Variables for the EFI System Table, Boot Services Table, +// DXE Core Global Variables for the EFI System Table, Boot Services Table, // DXE Services Table, and Runtime Services Table // -EFI_BOOT_SERVICES *gBS = &mBootServices; -EFI_DXE_SERVICES *gDS = &mDxeServices; -EFI_SYSTEM_TABLE *gST = NULL; +EFI_BOOT_SERVICES *gDxeCoreBS = &mBootServices; +EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices; +EFI_SYSTEM_TABLE *gDxeCoreST = NULL; // -// For debug initialize gRT to template. gRT must be allocated from RT memory -// but gRT is used for ASSERT () and DEBUG () type macros so lets give it +// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory +// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it // a value that will not cause debug infrastructure to crash early on. // -EFI_RUNTIME_SERVICES *gRT = &mEfiRuntimeServicesTableTemplate; +EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate; EFI_HANDLE gDxeCoreImageHandle = NULL; VOID *mHobStart; @@ -394,12 +277,6 @@ Returns: EFI_PHYSICAL_ADDRESS MemoryBaseAddress; UINT64 MemoryLength; -#ifdef EFI_DXE_PERFORMANCE - UINT64 Tick; - - GetTimerValue (&Tick); -#endif - mHobStart = HobStart; // @@ -411,14 +288,14 @@ Returns: // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table // - gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate); - ASSERT (gST != NULL); + gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate); + ASSERT (gDxeCoreST != NULL); - gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate); - ASSERT (gRT != NULL); + gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate); + ASSERT (gDxeCoreRT != NULL); + + gDxeCoreST->RuntimeServices = gDxeCoreRT; - gST->RuntimeServices = gRT; - // // Start the Image Services. // @@ -428,7 +305,9 @@ Returns: // // Call constructor for all libraries // - ProcessLibraryConstructorList (gDxeCoreImageHandle, gST); + ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST); + PERF_END (0,PEI_TOK, NULL, 0) ; + PERF_START (0,DXE_TOK, NULL, 0) ; // // Initialize the Global Coherency Domain Services @@ -439,7 +318,7 @@ Returns: // // Install the DXE Services Table into the EFI System Tables's Configuration Table // - Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS); + Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS); ASSERT_EFI_ERROR (Status); // @@ -455,16 +334,9 @@ Returns: ASSERT_EFI_ERROR (Status); // - // Initialize the ReportStatusCode with PEI version, if availible + // Initialize the ReportStatusCode with PEI version, if available // CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode); -#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000)) - // - // This Tiano extension was removed when UEFI 2.0 support was added. - // It's now just a protocol. - // - gRT->ReportStatusCode = gStatusCode->ReportStatusCode; -#endif // // Report Status Code here for DXE_ENTRY_POINT once it is available @@ -491,22 +363,22 @@ Returns: Status = CoreInitializeEventServices (); ASSERT_EFI_ERROR (Status); - + // // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs // - // These Protocols are not architectural. This implementation is sharing code between - // PEI and DXE in order to save FLASH space. These Protocols could also be implemented - // as part of the DXE Core. However, that would also require the DXE Core to be ported - // each time a different CPU is used, a different Decompression algorithm is used, or a - // different Image type is used. By placing these Protocols in PEI, the DXE Core remains - // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, + // These Protocols are not architectural. This implementation is sharing code between + // PEI and DXE in order to save FLASH space. These Protocols could also be implemented + // as part of the DXE Core. However, that would also require the DXE Core to be ported + // each time a different CPU is used, a different Decompression algorithm is used, or a + // different Image type is used. By placing these Protocols in PEI, the DXE Core remains + // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, // and from CPU to CPU. // // // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components - // + // Status = CoreInstallMultipleProtocolInterfaces ( &mDecompressHandle, &gEfiDecompressProtocolGuid, &gEfiDecompress, @@ -528,16 +400,16 @@ Returns: // // Produce Firmware Volume Protocols, one for each FV in the HOB list. // - Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST); + Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST); ASSERT_EFI_ERROR (Status); - Status = FwVolDriverInit (gDxeCoreImageHandle, gST); + Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST); ASSERT_EFI_ERROR (Status); // - // Produce the Section Extraction Protocol + // Produce the Section Extraction Protocol // - Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST); + Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST); ASSERT_EFI_ERROR (Status); // @@ -557,10 +429,10 @@ Returns: // // Display Architectural protocols that were not loaded if this is DEBUG build // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); CoreDisplayMissingArchProtocols (); - ); - + DEBUG_CODE_END (); + // // Assert if the Architectural Protocols are not present. // @@ -574,15 +446,15 @@ Returns: // Display any drivers that were not dispatched because dependency expression // evaluated to false if this is a debug build // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); CoreDisplayDiscoveredNotDispatched (); - ); + DEBUG_CODE_END (); // // Transfer control to the BDS Architectural Protocol // gBds->Entry (gBds); - + // // BDS should never return // @@ -666,7 +538,7 @@ Routine Description: Arguments: Arg1 - Undefined - + Arg2 - Undefined Returns: @@ -700,9 +572,9 @@ Routine Description: Arguments: Arg1 - Undefined - + Arg2 - Undefined - + Arg3 - Undefined Returns: @@ -737,11 +609,11 @@ Routine Description: Arguments: Arg1 - Undefined - + Arg2 - Undefined - + Arg3 - Undefined - + Arg4 - Undefined Returns: @@ -777,13 +649,13 @@ Routine Description: Arguments: Arg1 - Undefined - + Arg2 - Undefined - + Arg3 - Undefined - + Arg4 - Undefined - + Arg5 - Undefined Returns: @@ -834,7 +706,7 @@ Returns: if (GuidHob == NULL) { return EFI_NOT_FOUND; } - + Buffer = GET_GUID_HOB_DATA (GuidHob); ASSERT (Buffer != NULL); @@ -868,14 +740,14 @@ Returns: UINT32 Crc; Hdr->CRC32 = 0; - + // - // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then + // If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then // Crc will come back as zero if we set it to zero here // Crc = 0; - gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc); - Hdr->CRC32 = Crc; + gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc); + Hdr->CRC32 = Crc; } @@ -890,11 +762,11 @@ CoreExitBootServices ( Routine Description: - EFI 1.0 API to terminate Boot Services + Terminates all boot services. Arguments: - ImageHandle - Handle that represents the identity of the calling image + ImageHandle - Handle that identifies the exiting image. MapKey -Key to the latest memory map. @@ -930,16 +802,6 @@ Returns: // gCpu->DisableInterrupt (gCpu); - // - // Register Runtime events with the Runtime Architectural Protocol - // - CoreShutdownEventServices (); - - // - // Register Runtime images with the Runtime Architectural Protocol - // - CoreShutdownImageServices (); - // // Report that ExitBootServices() has been called // @@ -950,24 +812,29 @@ Returns: // // Clear the non-runtime values of the EFI System Table // - gST->BootServices = NULL; - gST->ConIn = NULL; - gST->ConsoleInHandle = NULL; - gST->ConOut = NULL; - gST->ConsoleOutHandle = NULL; - gST->StdErr = NULL; - gST->StandardErrorHandle = NULL; + gDxeCoreST->BootServices = NULL; + gDxeCoreST->ConIn = NULL; + gDxeCoreST->ConsoleInHandle = NULL; + gDxeCoreST->ConOut = NULL; + gDxeCoreST->ConsoleOutHandle = NULL; + gDxeCoreST->StdErr = NULL; + gDxeCoreST->StandardErrorHandle = NULL; // // Recompute the 32-bit CRC of the EFI System Table // - CalculateEfiHdrCrc (&gST->Hdr); + CalculateEfiHdrCrc (&gDxeCoreST->Hdr); // // Zero out the Boot Service Table // - SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0); - gBS = NULL; + SetMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES), 0); + gDxeCoreBS = NULL; + + // + // Update the AtRuntime field in Runtiem AP. + // + gRuntime->AtRuntime = TRUE; return Status; } @@ -981,6 +848,11 @@ DxeMainUefiDecompressGetInfo ( OUT UINT32 *ScratchSize ) { + if (Source == NULL + || DestinationSize == NULL + || ScratchSize == NULL) { + return EFI_INVALID_PARAMETER; + } return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize); } @@ -999,7 +871,13 @@ DxeMainUefiDecompress ( EFI_STATUS Status; UINT32 TestDestinationSize; UINT32 TestScratchSize; - + + if (Source == NULL + || Destination== NULL + || Scratch == NULL) { + return EFI_INVALID_PARAMETER; + } + Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize); if (EFI_ERROR (Status)) { return Status; @@ -1021,6 +899,12 @@ DxeMainTianoDecompressGetInfo ( OUT UINT32 *ScratchSize ) { + if (Source == NULL + || DestinationSize == NULL + || ScratchSize == NULL) { + return EFI_INVALID_PARAMETER; + } + return TianoDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize); } @@ -1039,7 +923,13 @@ DxeMainTianoDecompress ( EFI_STATUS Status; UINT32 TestDestinationSize; UINT32 TestScratchSize; - + + if (Source == NULL + || Destination== NULL + || Scratch == NULL) { + return EFI_INVALID_PARAMETER; + } + Status = TianoDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize); if (EFI_ERROR (Status)) { return Status; @@ -1061,6 +951,12 @@ DxeMainCustomDecompressGetInfo ( OUT UINT32 *ScratchSize ) { + if (Source == NULL + || DestinationSize == NULL + || ScratchSize == NULL) { + return EFI_INVALID_PARAMETER; + } + return CustomDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize); } @@ -1080,6 +976,12 @@ DxeMainCustomDecompress ( UINT32 TestDestinationSize; UINT32 TestScratchSize; + if (Source == NULL + || Destination== NULL + || Scratch == NULL) { + return EFI_INVALID_PARAMETER; + } + Status = CustomDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize); if (EFI_ERROR (Status)) { return Status;