X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EdkModulePkg%2FCore%2FDxeIplPeim%2FDxeLoad.c;h=4d9ec5218a1de05c6a443ca89329850ed771fed5;hb=3401c092e4e98b97bcf86d9aa2500d5ee7b3b8cf;hp=8c3de0522d9ca46f8a84e5cf26f8247b956127ba;hpb=abb26634f230fb703906f46e7e7adebc9124214a;p=mirror_edk2.git diff --git a/EdkModulePkg/Core/DxeIplPeim/DxeLoad.c b/EdkModulePkg/Core/DxeIplPeim/DxeLoad.c index 8c3de0522d..4d9ec5218a 100644 --- a/EdkModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/EdkModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -22,10 +22,6 @@ Abstract: #include "DxeIpl.h" -#ifndef __GNUC__ -#pragma warning( disable : 4305 ) -#endif - BOOLEAN gInMemory = FALSE; // @@ -151,9 +147,6 @@ Returns: --*/ { EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS TopOfStack; - EFI_PHYSICAL_ADDRESS BaseOfStack; - EFI_PHYSICAL_ADDRESS BspStore; EFI_GUID DxeCoreFileName; EFI_GUID FirmwareFileName; VOID *Pe32Data; @@ -165,13 +158,8 @@ Returns: EFI_BOOT_MODE BootMode; EFI_PEI_RECOVERY_MODULE_PPI *PeiRecovery; EFI_PEI_S3_RESUME_PPI *S3Resume; - EFI_PHYSICAL_ADDRESS PageTables; // PERF_START (PeiServices, L"DxeIpl", NULL, 0); - TopOfStack = 0; - BaseOfStack = 0; - BspStore = 0; - PageTables = 0; // // if in S3 Resume, restore configure @@ -217,17 +205,6 @@ Returns: PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol (); ASSERT (PeiEfiPeiPeCoffLoader != NULL); - // - // Allocate 128KB for the Stack - // - PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack); - ASSERT (BaseOfStack != 0); - - // - // Add architecture-specifc HOBs (including the BspStore HOB) - // - Status = CreateArchSpecificHobs (&BspStore); - ASSERT_EFI_ERROR (Status); // // Find the EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE type compressed Firmware Volume file @@ -264,14 +241,6 @@ Returns: ); ASSERT_EFI_ERROR (Status); - // - // Transfer control to the DXE Core - // The handoff state is simply a pointer to the HOB list - // - - Status = PeiServicesInstallPpi (&mPpiSignal); - ASSERT_EFI_ERROR (Status); - // // Add HOB for the DXE Core // @@ -290,70 +259,37 @@ Returns: EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT ); - DEBUG ((EFI_D_INFO, "DXE Core Entry\n")); - if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) { - // - // Compute the top of the stack we were allocated, which is used to load X64 dxe core. - // Pre-allocate a 32 bytes which confroms to x64 calling convention. - // - // The first four parameters to a function are passed in rcx, rdx, r8 and r9. - // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the - // register parameters is reserved on the stack, in case the called function - // wants to spill them; this is important if the function is variadic. - // - TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32; - - // - // X64 Calling Conventions requires that the stack must be aligned to 16 bytes - // - TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16); - // - // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA - // memory, it may be corrupted when copying FV to high-end memory - // - LoadGo64Gdt(); - // - // Limit to 36 bits of addressing for debug. Should get it from CPU - // - PageTables = CreateIdentityMappingPageTables (36); - // - // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded. - // Call x64 drivers passing in single argument, a pointer to the HOBs. - // - ActivateLongMode ( - PageTables, - (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw), - TopOfStack, - 0x00000000, - DxeCoreEntryPoint - ); - } else { - // - // Add HOB for the EFI Decompress Protocol - // - BuildGuidDataHob ( - &gEfiDecompressProtocolGuid, - (VOID *)&gEfiDecompress, - sizeof (gEfiDecompress) - ); - - // - // Add HOB for the Tiano Decompress Protocol - // - BuildGuidDataHob ( - &gEfiTianoDecompressProtocolGuid, - (VOID *)&gTianoDecompress, - sizeof (gTianoDecompress) - ); - - // - // Add HOB for the user customized Decompress Protocol - // - BuildGuidDataHob ( - &gEfiCustomizedDecompressProtocolGuid, - (VOID *)&gCustomDecompress, - sizeof (gCustomDecompress) - ); + if (FeaturePcdGet (PcdDxeIplBuildShareCodeHobs)) { + if (FeaturePcdGet (PcdDxeIplSupportEfiDecompress)) { + // + // Add HOB for the EFI Decompress Protocol + // + BuildGuidDataHob ( + &gEfiDecompressProtocolGuid, + (VOID *)&gEfiDecompress, + sizeof (gEfiDecompress) + ); + } + if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress)) { + // + // Add HOB for the Tiano Decompress Protocol + // + BuildGuidDataHob ( + &gEfiTianoDecompressProtocolGuid, + (VOID *)&gTianoDecompress, + sizeof (gTianoDecompress) + ); + } + if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress)) { + // + // Add HOB for the user customized Decompress Protocol + // + BuildGuidDataHob ( + &gEfiCustomizedDecompressProtocolGuid, + (VOID *)&gCustomDecompress, + sizeof (gCustomDecompress) + ); + } // // Add HOB for the PE/COFF Loader Protocol @@ -363,21 +299,15 @@ Returns: (VOID *)&PeiEfiPeiPeCoffLoader, sizeof (VOID *) ); - // - // Compute the top of the stack we were allocated. Pre-allocate a UINTN - // for safety. - // - TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT; - TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); - - SwitchIplStacks ( - (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, - HobList.Raw, - NULL, - (VOID *) (UINTN) TopOfStack, - (VOID *) (UINTN) BspStore - ); - } + } + + // + // Transfer control to the DXE Core + // The handoff state is simply a pointer to the HOB list + // + + DEBUG ((EFI_D_INFO, "DXE Core Entry Point 0x%08x\n", (UINTN) DxeCoreEntryPoint)); + HandOffToDxeCore (DxeCoreEntryPoint, HobList, &mPpiSignal); // // If we get here, then the DXE Core returned. This is an error // Dxe Core should not return. @@ -425,14 +355,12 @@ Returns: { EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; EFI_FFS_FILE_HEADER *FfsFileHeader; - VOID *SectionData; EFI_STATUS Status; EFI_PEI_HOB_POINTERS Hob; FwVolHeader = NULL; FfsFileHeader = NULL; - SectionData = NULL; Status = EFI_SUCCESS; // @@ -724,7 +652,6 @@ Returns: UINTN SectionLength; UINTN OccupiedSectionLength; UINT64 FileSize; - EFI_GUID_DEFINED_SECTION *GuidedSectionHeader; UINT32 AuthenticationStatus; EFI_PEI_SECTION_EXTRACTION_PPI *SectionExtract; UINT32 BufferSize; @@ -736,6 +663,13 @@ Returns: EFI_COMPRESSION_SECTION *CompressionSection; UINT32 FvAlignment; + // + // Initialize local variables. + // + DecompressLibrary = NULL; + DstBuffer = NULL; + DstBufferSize = 0; + Status = PeiServicesFfsFindSectionData ( EFI_SECTION_COMPRESSION, FfsFileHeader, @@ -760,10 +694,6 @@ Returns: // Was the DXE Core file encapsulated in a GUID'd section? // if (Section->Type == EFI_SECTION_GUID_DEFINED) { - // - // Locate the GUID'd Section Extractor - // - GuidedSectionHeader = (VOID *) (Section + 1); // // This following code constitutes the addition of the security model @@ -851,8 +781,11 @@ Returns: switch (CompressionSection->CompressionType) { case EFI_STANDARD_COMPRESSION: + // + // Load EFI standard compression. + // if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress)) { - DecompressLibrary = &gTianoDecompress; + DecompressLibrary = &gEfiDecompress; } else { ASSERT (FALSE); return EFI_NOT_FOUND; @@ -861,7 +794,7 @@ Returns: case EFI_CUSTOMIZED_COMPRESSION: // - // Load user customized compression protocol. + // Load user customized compression. // if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress)) { DecompressLibrary = &gCustomDecompress; @@ -872,52 +805,79 @@ Returns: break; case EFI_NOT_COMPRESSED: + // + // Allocate destination buffer + // + DstBufferSize = CompressionSection->UncompressedLength; + DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize)); + if (DstBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + // + // stream is not actually compressed, just encapsulated. So just copy it. + // + CopyMem (DstBuffer, CompressionSection + 1, DstBufferSize); + break; + default: // - // Need to support not compressed file + // Don't support other unknown compression type. // ASSERT_EFI_ERROR (Status); return EFI_NOT_FOUND; } - - Status = DecompressLibrary->GetInfo ( - (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), - (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION), - &DstBufferSize, - &ScratchBufferSize - ); - if (EFI_ERROR (Status)) { + + if (CompressionSection->CompressionType != EFI_NOT_COMPRESSED) { // - // GetInfo failed + // For compressed data, decompress them to dstbuffer. // - return EFI_NOT_FOUND; - } - - // - // Allocate scratch buffer - // - ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize)); - if (ScratchBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Allocate destination buffer - // - DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize)); - if (DstBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = DecompressLibrary->GetInfo ( + (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), + (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION), + &DstBufferSize, + &ScratchBufferSize + ); + if (EFI_ERROR (Status)) { + // + // GetInfo failed + // + DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status)); + return EFI_NOT_FOUND; + } + + // + // Allocate scratch buffer + // + ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize)); + if (ScratchBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Allocate destination buffer + // + DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize)); + if (DstBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Call decompress function + // + Status = DecompressLibrary->Decompress ( + (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), + DstBuffer, + ScratchBuffer + ); + if (EFI_ERROR (Status)) { + // + // Decompress failed + // + DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status)); + return EFI_NOT_FOUND; + } } - - // - // Call decompress function - // - Status = DecompressLibrary->Decompress ( - (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), - DstBuffer, - ScratchBuffer - ); - + CmpSection = (EFI_COMMON_SECTION_HEADER *) DstBuffer; if (CmpSection->Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) { // @@ -976,7 +936,6 @@ Returns: } else { return EFI_NOT_FOUND; } - } } //