From 6c128c65b5ec0e5b8b5a0ccb165f3afd29e485f8 Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Wed, 2 Aug 2017 09:54:47 +0800 Subject: Remove core packages since we can get them from edk2 repository Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang --- DuetPkg/EfiLdr/Debug.c | 79 ---- DuetPkg/EfiLdr/Debug.h | 40 -- DuetPkg/EfiLdr/EfiLdr.h | 92 ---- DuetPkg/EfiLdr/EfiLdr.inf | 55 --- DuetPkg/EfiLdr/EfiLdrHandoff.h | 56 --- DuetPkg/EfiLdr/EfiLoader.c | 291 ------------ DuetPkg/EfiLdr/LzmaDecompress.h | 70 --- DuetPkg/EfiLdr/PeLoader.c | 641 ------------------------- DuetPkg/EfiLdr/PeLoader.h | 42 -- DuetPkg/EfiLdr/Support.c | 237 ---------- DuetPkg/EfiLdr/Support.h | 50 -- DuetPkg/EfiLdr/TianoDecompress.c | 990 --------------------------------------- DuetPkg/EfiLdr/TianoDecompress.h | 90 ---- DuetPkg/EfiLdr/efildr.c | 28 -- 14 files changed, 2761 deletions(-) delete mode 100644 DuetPkg/EfiLdr/Debug.c delete mode 100644 DuetPkg/EfiLdr/Debug.h delete mode 100644 DuetPkg/EfiLdr/EfiLdr.h delete mode 100644 DuetPkg/EfiLdr/EfiLdr.inf delete mode 100644 DuetPkg/EfiLdr/EfiLdrHandoff.h delete mode 100644 DuetPkg/EfiLdr/EfiLoader.c delete mode 100644 DuetPkg/EfiLdr/LzmaDecompress.h delete mode 100644 DuetPkg/EfiLdr/PeLoader.c delete mode 100644 DuetPkg/EfiLdr/PeLoader.h delete mode 100644 DuetPkg/EfiLdr/Support.c delete mode 100644 DuetPkg/EfiLdr/Support.h delete mode 100644 DuetPkg/EfiLdr/TianoDecompress.c delete mode 100644 DuetPkg/EfiLdr/TianoDecompress.h delete mode 100644 DuetPkg/EfiLdr/efildr.c (limited to 'DuetPkg/EfiLdr') diff --git a/DuetPkg/EfiLdr/Debug.c b/DuetPkg/EfiLdr/Debug.c deleted file mode 100644 index 84b2772112..0000000000 --- a/DuetPkg/EfiLdr/Debug.c +++ /dev/null @@ -1,79 +0,0 @@ -/*++ - -Copyright (c) 2006 - 2011, 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: - Debug.c - -Abstract: - -Revision History: - ---*/ -#include "EfiLdr.h" -#include "Debug.h" - -UINT8 *mCursor; -UINT8 mHeaderIndex = 10; - - -VOID -PrintHeader ( - CHAR8 Char - ) -{ - *(UINT8 *)(UINTN)(0x000b8000 + mHeaderIndex) = Char; - mHeaderIndex += 2; -} - -VOID -ClearScreen ( - VOID - ) -{ - UINT32 Index; - - mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160); - for (Index = 0; Index < 80 * 49; Index++) { - *mCursor = ' '; - mCursor += 2; - } - mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160); -} - -VOID -PrintString ( - IN CONST CHAR8 *FormatString, - ... - ) -{ - UINTN Index; - CHAR8 PrintBuffer[256]; - VA_LIST Marker; - - VA_START (Marker, FormatString); - AsciiVSPrint (PrintBuffer, sizeof (PrintBuffer), FormatString, Marker); - VA_END (Marker); - - for (Index = 0; PrintBuffer[Index] != 0; Index++) { - if (PrintBuffer[Index] == '\n') { - mCursor = (UINT8 *) (UINTN) (0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160)); - } else { - *mCursor = (UINT8) PrintBuffer[Index]; - mCursor += 2; - } - } - - // - // All information also output to serial port. - // - SerialPortWrite ((UINT8 *) PrintBuffer, Index); -} - diff --git a/DuetPkg/EfiLdr/Debug.h b/DuetPkg/EfiLdr/Debug.h deleted file mode 100644 index f6aa7a2cf7..0000000000 --- a/DuetPkg/EfiLdr/Debug.h +++ /dev/null @@ -1,40 +0,0 @@ -/*++ - -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. - -Module Name: - Debug.h - -Abstract: - -Revision History: - ---*/ - -#ifndef _EFILDR_DEBUG_H_ -#define _EFILDR_DEBUG_H_ - -VOID -PrintHeader ( - CHAR8 Char - ); - -VOID -PrintString ( - IN CONST CHAR8 *FormatString, - ... - ); - -VOID -ClearScreen ( - VOID - ); - -#endif diff --git a/DuetPkg/EfiLdr/EfiLdr.h b/DuetPkg/EfiLdr/EfiLdr.h deleted file mode 100644 index 665f405855..0000000000 --- a/DuetPkg/EfiLdr/EfiLdr.h +++ /dev/null @@ -1,92 +0,0 @@ -/*++ - -Copyright (c) 2006 - 2011, 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: - EfiLdr.c - -Abstract: - -Revision History: - ---*/ - -#ifndef _DUET_EFI_LOADER_H_ -#define _DUET_EFI_LOADER_H_ - -#include "Uefi.h" -#include "EfiLdrHandoff.h" - -#include -#include -#include -#include -#include -#include - -#define INT15_E820_AddressRangeMemory 1 -#define INT15_E820_AddressRangeReserved 2 -#define INT15_E820_AddressRangeACPI 3 -#define INT15_E820_AddressRangeNVS 4 - -#define EFI_FIRMWARE_BASE_ADDRESS 0x00200000 - -#define EFI_DECOMPRESSED_BUFFER_ADDRESS 0x00600000 - -#define EFI_MAX_MEMORY_DESCRIPTORS 64 - -#define LOADED_IMAGE_SIGNATURE SIGNATURE_32('l','d','r','i') - -typedef struct { - UINTN Signature; - CHAR16 *Name; // Displayable name - UINTN Type; - - BOOLEAN Started; // If entrypoint has been called - VOID *StartImageContext; - - EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point - EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol - - // - EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory - UINTN NoPages; // Number of pages - UINT8 *ImageBase; // As a char pointer - UINT8 *ImageEof; // End of memory image - - // relocate info - UINT8 *ImageAdjust; // Bias for reloc calculations - UINTN StackAddress; - UINT8 *FixupData; // Original fixup data -} EFILDR_LOADED_IMAGE; - -#pragma pack(4) -typedef struct { - UINT64 BaseAddress; - UINT64 Length; - UINT32 Type; -} BIOS_MEMORY_MAP_ENTRY; -#pragma pack() - -typedef struct { - UINT32 MemoryMapSize; - BIOS_MEMORY_MAP_ENTRY MemoryMapEntry[1]; -} BIOS_MEMORY_MAP; - -EFILDR_LOADED_IMAGE DxeCoreImage; -EFILDR_LOADED_IMAGE DxeIplImage; - -typedef -VOID -(EFIAPI * EFI_MAIN_ENTRYPOINT) ( - IN EFILDRHANDOFF *Handoff - ); - -#endif //_DUET_EFI_LOADER_H_ diff --git a/DuetPkg/EfiLdr/EfiLdr.inf b/DuetPkg/EfiLdr/EfiLdr.inf deleted file mode 100644 index b5a46db870..0000000000 --- a/DuetPkg/EfiLdr/EfiLdr.inf +++ /dev/null @@ -1,55 +0,0 @@ -## @file -# -# Copyright (c) 2006 - 2011, 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: -# EfiLdr.inf -# -# Abstract: -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = EfiLoader - FILE_GUID = A9620E5C-5FA1-40b7-8B21-50B632F88F38 - MODULE_TYPE = UEFI_APPLICATION - VERSION_STRING = 1.0 - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - PrintLib - SerialPortLib - -[Sources] - Debug.h - PeLoader.h - Support.h - EfiLdrHandoff.h - EfiLdr.h - EfiLoader.c - Debug.c - PeLoader.c - Support.c - #TianoDecompress.c - #TianoDecompress.h - LzmaDecompress.h - -[Guids] - gTianoCustomDecompressGuid - -[BuildOptions] - MSFT:*_*_*_DLINK_FLAGS = /BASE:0x10000 diff --git a/DuetPkg/EfiLdr/EfiLdrHandoff.h b/DuetPkg/EfiLdr/EfiLdrHandoff.h deleted file mode 100644 index 3e5210f438..0000000000 --- a/DuetPkg/EfiLdr/EfiLdrHandoff.h +++ /dev/null @@ -1,56 +0,0 @@ -/*++ - -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. - -Module Name: - EfiLdrHandoff.h - -Abstract: - -Revision History: - ---*/ - -#ifndef _EFILDR_HANDOFF_H_ -#define _EFILDR_HANDOFF_H_ - -#define EFILDR_BASE_SEGMENT 0x2000 -#define EFILDR_LOAD_ADDRESS (EFILDR_BASE_SEGMENT << 4) -#define EFILDR_HEADER_ADDRESS (EFILDR_LOAD_ADDRESS+0x2000) - -#define EFILDR_CB_VA 0x00 - -typedef struct _EFILDRHANDOFF { - UINTN MemDescCount; - EFI_MEMORY_DESCRIPTOR *MemDesc; - VOID *BfvBase; - UINTN BfvSize; - VOID *DxeIplImageBase; - UINTN DxeIplImageSize; - VOID *DxeCoreImageBase; - UINTN DxeCoreImageSize; - VOID *DxeCoreEntryPoint; -} EFILDRHANDOFF; - -typedef struct { - UINT32 CheckSum; - UINT32 Offset; - UINT32 Length; - UINT8 FileName[52]; -} EFILDR_IMAGE; - -typedef struct { - UINT32 Signature; - UINT32 HeaderCheckSum; - UINT32 FileLength; - UINT32 NumberOfImages; -} EFILDR_HEADER; - -#endif diff --git a/DuetPkg/EfiLdr/EfiLoader.c b/DuetPkg/EfiLdr/EfiLoader.c deleted file mode 100644 index 6913027650..0000000000 --- a/DuetPkg/EfiLdr/EfiLoader.c +++ /dev/null @@ -1,291 +0,0 @@ -/*++ - -Copyright (c) 2006 - 2011, 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: - EfiLoader.c - -Abstract: - -Revision History: - ---*/ - -#include "EfiLdr.h" -#include "Support.h" -#include "Debug.h" -#include "PeLoader.h" -#include "LzmaDecompress.h" - -VOID -SystemHang ( - CHAR8 *Message - ) -{ - PrintString ( - "%s## FATAL ERROR ##: Fail to load DUET images! System hang!\n", - Message - ); - CpuDeadLoop(); -} - -VOID -EfiLoader ( - UINT32 BiosMemoryMapBaseAddress - ) -{ - BIOS_MEMORY_MAP *BiosMemoryMap; - EFILDR_IMAGE *EFILDRImage; - EFI_MEMORY_DESCRIPTOR EfiMemoryDescriptor[EFI_MAX_MEMORY_DESCRIPTORS]; - EFI_STATUS Status; - UINTN NumberOfMemoryMapEntries; - UINT32 DestinationSize; - UINT32 ScratchSize; - UINTN BfvPageNumber; - UINTN BfvBase; - EFI_MAIN_ENTRYPOINT EfiMainEntrypoint; - EFILDRHANDOFF Handoff; - UINTN Index; - - ClearScreen(); - - PrintHeader ('A'); - - PrintString ("Enter DUET Loader...\n"); - PrintString ("BiosMemoryMapBaseAddress = %x\n", (UINTN) BiosMemoryMapBaseAddress); - - // - // Add all EfiConventionalMemory descriptors to the table. If there are partial pages, then - // round the start address up to the next page, and round the length down to a page boundry. - // - BiosMemoryMap = (BIOS_MEMORY_MAP *) (UINTN) BiosMemoryMapBaseAddress; - NumberOfMemoryMapEntries = 0; - GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap); - - PrintString ("Get %d entries of memory map!\n", NumberOfMemoryMapEntries); - - // - // Get information on where the image is in memory - // - EFILDRImage = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER)); - - - // - // Point to the 4th image (Bfv) - // - EFILDRImage += 3; - - // - // Decompress the image - // - PrintString ( - "Decompress BFV image, Image Address = %x Offset = %x\n", - (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - (UINTN) EFILDRImage->Offset - ); - Status = LzmaUefiDecompressGetInfo ( - (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - EFILDRImage->Length, - &DestinationSize, - &ScratchSize - ); - - if (EFI_ERROR (Status)) { - SystemHang ("Failed to get decompress information for BFV!\n"); - } - - PrintString ("BFV decompress: DestinationSize = %x, ScratchSize = %x\n", (UINTN) DestinationSize, (UINTN) ScratchSize); - Status = LzmaUefiDecompress ( - (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - EFILDRImage->Length, - (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, - (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000) - ); - - - if (EFI_ERROR (Status)) { - SystemHang ("Failed to decompress BFV!\n"); - } - - BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize); - BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB); - if (BfvBase == 0) { - SystemHang ("Failed to find free space to hold decompressed BFV\n"); - } - ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE); - CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize); - - PrintHeader ('B'); - - // - // Point to the 2nd image (DxeIpl) - // - - EFILDRImage -= 2; - - // - // Decompress the image - // - PrintString ( - "Decompress DxeIpl image, Image Address = %x Offset = %x\n", - (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - (UINTN) EFILDRImage->Offset - ); - - Status = LzmaUefiDecompressGetInfo ( - (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - EFILDRImage->Length, - &DestinationSize, - &ScratchSize - ); - if (EFI_ERROR (Status)) { - SystemHang ("Failed to get decompress information for DxeIpl!\n"); - } - - Status = LzmaUefiDecompress ( - (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - EFILDRImage->Length, - (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, - (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000) - ); - if (EFI_ERROR (Status)) { - SystemHang ("Failed to decompress DxeIpl image\n"); - } - - PrintString ("Start load DxeIpl PE image\n"); - - // - // Load and relocate the EFI PE/COFF Firmware Image - // - Status = EfiLdrPeCoffLoadPeImage ( - (VOID *)(UINTN)(EFI_DECOMPRESSED_BUFFER_ADDRESS), - &DxeIplImage, - &NumberOfMemoryMapEntries, - EfiMemoryDescriptor - ); - if (EFI_ERROR (Status)) { - SystemHang ("Failed to load and relocate DxeIpl PE image!\n"); - } - PrintString ( - "DxeIpl PE image is successed loaded at %lx, entry=%p\n", - DxeIplImage.ImageBasePage, - DxeIplImage.EntryPoint - ); - -PrintHeader ('C'); - - // - // Point to the 3rd image (DxeMain) - // - EFILDRImage++; - - // - // Decompress the image - // - PrintString ( - "Decompress DxeMain FV image, Image Address = %x Offset = %x\n", - (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - (UINTN) EFILDRImage->Offset - ); - - Status = LzmaUefiDecompressGetInfo ( - (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - EFILDRImage->Length, - &DestinationSize, - &ScratchSize - ); - if (EFI_ERROR (Status)) { - SystemHang ("Failed to get decompress information for DxeMain FV image!\n"); - } - - Status = LzmaUefiDecompress ( - (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset), - EFILDRImage->Length, - (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, - (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000) - ); - if (EFI_ERROR (Status)) { - SystemHang ("Failed to decompress DxeMain FV image!\n"); - } - - // - // Load and relocate the EFI PE/COFF Firmware Image - // - Status = EfiLdrPeCoffLoadPeImage ( - (VOID *)(UINTN)(EFI_DECOMPRESSED_BUFFER_ADDRESS), - &DxeCoreImage, - &NumberOfMemoryMapEntries, - EfiMemoryDescriptor - ); - if (EFI_ERROR (Status)) { - SystemHang ("Failed to load/relocate DxeMain!\n"); - } - PrintString ( - "DxeCore PE image is successed loaded at %lx, entry=%p\n", - DxeCoreImage.ImageBasePage, - DxeCoreImage.EntryPoint - ); - -PrintHeader ('E'); - - // - // Display the table of memory descriptors. - // - PrintString ("\nEFI Memory Descriptors\n"); - for (Index = 0; Index < NumberOfMemoryMapEntries; Index++) { - PrintString ( - "Type = %x Start = %08lx NumberOfPages = %08lx\n", - EfiMemoryDescriptor[Index].Type, EfiMemoryDescriptor[Index].PhysicalStart, EfiMemoryDescriptor[Index].NumberOfPages - ); - } - - // - // Jump to EFI Firmware - // - - if (DxeIplImage.EntryPoint != NULL) { - - Handoff.MemDescCount = NumberOfMemoryMapEntries; - Handoff.MemDesc = EfiMemoryDescriptor; - Handoff.BfvBase = (VOID *)(UINTN)BfvBase; - Handoff.BfvSize = BfvPageNumber * EFI_PAGE_SIZE; - Handoff.DxeIplImageBase = (VOID *)(UINTN)DxeIplImage.ImageBasePage; - Handoff.DxeIplImageSize = DxeIplImage.NoPages * EFI_PAGE_SIZE; - Handoff.DxeCoreImageBase = (VOID *)(UINTN)DxeCoreImage.ImageBasePage; - Handoff.DxeCoreImageSize = DxeCoreImage.NoPages * EFI_PAGE_SIZE; - Handoff.DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreImage.EntryPoint; - - PrintString ("Transfer to DxeIpl ...EntryPoint = %p\n", DxeIplImage.EntryPoint); - - EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT) DxeIplImage.EntryPoint; - EfiMainEntrypoint (&Handoff); - } - -PrintHeader ('F'); - - // - // There was a problem loading the image, so HALT the system. - // - - SystemHang ("Failed to jump to DxeIpl!\n"); -} - -EFI_STATUS -EFIAPI -_ModuleEntryPoint ( - UINT32 BiosMemoryMapBaseAddress - ) -{ - SerialPortInitialize (); - EfiLoader(BiosMemoryMapBaseAddress); - return EFI_SUCCESS; -} - - diff --git a/DuetPkg/EfiLdr/LzmaDecompress.h b/DuetPkg/EfiLdr/LzmaDecompress.h deleted file mode 100644 index 7d20fdace4..0000000000 --- a/DuetPkg/EfiLdr/LzmaDecompress.h +++ /dev/null @@ -1,70 +0,0 @@ -/** @file - LZMA Decompress Library header file - - Copyright (c) 2006 - 2010, 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. - -**/ - -#ifndef __LZMADECOMPRESS_H__ -#define __LZMADECOMPRESS_H__ - -/** - The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo(). - - @param Source The source buffer containing the compressed data. - @param SourceSize The size of source buffer - @param DestinationSize The size of destination buffer. - @param ScratchSize The size of scratch buffer. - - @retval RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. - @retval RETURN_INVALID_PARAMETER - The source data is corrupted -**/ -RETURN_STATUS -EFIAPI -LzmaUefiDecompressGetInfo ( - IN CONST VOID *Source, - IN UINT32 SourceSize, - OUT UINT32 *DestinationSize, - OUT UINT32 *ScratchSize - ); - -/** - Decompresses a Lzma compressed source buffer. - - Extracts decompressed data to its original form. - If the compressed source data specified by Source is successfully decompressed - into Destination, then RETURN_SUCCESS is returned. If the compressed source data - specified by Source is not in a valid compressed data format, - then RETURN_INVALID_PARAMETER is returned. - - @param Source The source buffer containing the compressed data. - @param SourceSize The size of source buffer. - @param Destination The destination buffer to store the decompressed data - @param Scratch A temporary scratch buffer that is used to perform the decompression. - This is an optional parameter that may be NULL if the - required scratch buffer size is 0. - - @retval RETURN_SUCCESS Decompression completed successfully, and - the uncompressed buffer is returned in Destination. - @retval RETURN_INVALID_PARAMETER - The source buffer specified by Source is corrupted - (not in a valid compressed format). -**/ -RETURN_STATUS -EFIAPI -LzmaUefiDecompress ( - IN CONST VOID *Source, - IN UINTN SourceSize, - IN OUT VOID *Destination, - IN OUT VOID *Scratch - ); - -#endif // __LZMADECOMPRESS_H__ - diff --git a/DuetPkg/EfiLdr/PeLoader.c b/DuetPkg/EfiLdr/PeLoader.c deleted file mode 100644 index 7fafdfb14b..0000000000 --- a/DuetPkg/EfiLdr/PeLoader.c +++ /dev/null @@ -1,641 +0,0 @@ -/*++ - -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. - -Module Name: - PeLoader.c - -Abstract: - -Revision History: - ---*/ -#include "EfiLdr.h" -#include "Debug.h" -#include "Support.h" - -EFI_STATUS -EfiLdrPeCoffLoadPeRelocate ( - IN EFILDR_LOADED_IMAGE *Image, - IN EFI_IMAGE_DATA_DIRECTORY *RelocDir, - IN UINTN Adjust, - IN UINTN *NumberOfMemoryMapEntries, - IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor - ); - -EFI_STATUS -EfiLdrPeCoffImageRead ( - IN VOID *FHand, - IN UINTN Offset, - IN OUT UINTN ReadSize, - OUT VOID *Buffer - ); - -VOID * -EfiLdrPeCoffImageAddress ( - IN EFILDR_LOADED_IMAGE *Image, - IN UINTN Address - ); - - -EFI_STATUS -EfiLdrPeCoffSetImageType ( - IN OUT EFILDR_LOADED_IMAGE *Image, - IN UINTN ImageType - ); - -EFI_STATUS -EfiLdrPeCoffCheckImageMachineType ( - IN UINT16 MachineType - ); - -EFI_STATUS -EfiLdrGetPeImageInfo ( - IN VOID *FHand, - OUT UINT64 *ImageBase, - OUT UINT32 *ImageSize - ) -{ - EFI_STATUS Status; - EFI_IMAGE_DOS_HEADER DosHdr; - EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr; - - ZeroMem (&DosHdr, sizeof(DosHdr)); - ZeroMem (&PeHdr, sizeof(PeHdr)); - - // - // Read image headers - // - - EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr); - if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) { - return EFI_UNSUPPORTED; - } - - EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr); - - if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) { - return EFI_UNSUPPORTED; - } - - // - // Verify machine type - // - - Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine); - if (EFI_ERROR(Status)) { - return Status; - } - - if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - *ImageBase = (UINT32)PeHdr.Pe32.OptionalHeader.ImageBase; - } else if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { - *ImageBase = PeHdr.Pe32Plus.OptionalHeader.ImageBase; - } else { - return EFI_UNSUPPORTED; - } - - *ImageSize = PeHdr.Pe32.OptionalHeader.SizeOfImage; - - return EFI_SUCCESS; -} - -EFI_STATUS -EfiLdrPeCoffLoadPeImage ( - IN VOID *FHand, - IN EFILDR_LOADED_IMAGE *Image, - IN UINTN *NumberOfMemoryMapEntries, - IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor - ) -{ - EFI_IMAGE_DOS_HEADER DosHdr; - EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr; - EFI_IMAGE_SECTION_HEADER *FirstSection; - EFI_IMAGE_SECTION_HEADER *Section; - UINTN Index; - EFI_STATUS Status; - UINT8 *Base; - UINT8 *End; - EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; - UINTN DirCount; - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY TempDebugEntry; - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry; - UINTN CodeViewSize; - UINTN CodeViewOffset; - UINTN CodeViewFileOffset; - UINTN OptionalHeaderSize; - UINTN PeHeaderSize; - UINT32 NumberOfRvaAndSizes; - EFI_IMAGE_DATA_DIRECTORY *DataDirectory; - UINT64 ImageBase; - CHAR8 PrintBuffer[256]; - - ZeroMem (&DosHdr, sizeof(DosHdr)); - ZeroMem (&PeHdr, sizeof(PeHdr)); - - // - // Read image headers - // - - EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr); - if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) { - AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Dos header signature not found\n"); - PrintString (PrintBuffer); - PrintHeader ('F'); - return EFI_UNSUPPORTED; - } - - EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr); - - if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) { - AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: PE image header signature not found\n"); - PrintString (PrintBuffer); - PrintHeader ('G'); - return EFI_UNSUPPORTED; - } - - // - // Set the image subsystem type - // - - Status = EfiLdrPeCoffSetImageType (Image, PeHdr.Pe32.OptionalHeader.Subsystem); - if (EFI_ERROR(Status)) { - AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Subsystem type not known\n"); - PrintString (PrintBuffer); - PrintHeader ('H'); - return Status; - } - - // - // Verify machine type - // - - Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine); - if (EFI_ERROR(Status)) { - AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Incorrect machine type\n"); - PrintString (PrintBuffer); - PrintHeader ('I'); - return Status; - } - - // - // Compute the amount of memory needed to load the image and - // allocate it. This will include all sections plus the codeview debug info. - // Since the codeview info is actually outside of the image, we calculate - // its size seperately and add it to the total. - // - // Memory starts off as data - // - - CodeViewSize = 0; - CodeViewFileOffset = 0; - if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(PeHdr.Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); - } else if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { - DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(PeHdr.Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); - } else { - return EFI_UNSUPPORTED; - } - for (DirCount = 0; - (DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && (CodeViewSize == 0); - DirCount++) { - Status = EfiLdrPeCoffImageRead ( - FHand, - DirectoryEntry->VirtualAddress + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), - sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), - &TempDebugEntry - ); - if (!EFI_ERROR (Status)) { - if (TempDebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) { - CodeViewSize = TempDebugEntry.SizeOfData; - CodeViewFileOffset = TempDebugEntry.FileOffset; - } - } - } - - CodeViewOffset = PeHdr.Pe32.OptionalHeader.SizeOfImage + PeHdr.Pe32.OptionalHeader.SectionAlignment; - Image->NoPages = EFI_SIZE_TO_PAGES (CodeViewOffset + CodeViewSize); - - // - // Compute the amount of memory needed to load the image and - // allocate it. Memory starts off as data - // - - Image->ImageBasePage = (EFI_PHYSICAL_ADDRESS)FindSpace (Image->NoPages, NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesCode, EFI_MEMORY_WB); - if (Image->ImageBasePage == 0) { - return EFI_OUT_OF_RESOURCES; - } - - if (EFI_ERROR(Status)) { - PrintHeader ('J'); - return Status; - } - - AsciiSPrint (PrintBuffer, 256, "LoadPe: new image base %lx\n", Image->ImageBasePage); - PrintString (PrintBuffer); - Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageBasePage; - Image->Info.ImageSize = (Image->NoPages << EFI_PAGE_SHIFT) - 1; - Image->ImageBase = (UINT8 *)(UINTN)Image->ImageBasePage; - Image->ImageEof = Image->ImageBase + Image->Info.ImageSize; - Image->ImageAdjust = Image->ImageBase; - - // - // Copy the Image header to the base location - // - Status = EfiLdrPeCoffImageRead ( - FHand, - 0, - PeHdr.Pe32.OptionalHeader.SizeOfHeaders, - Image->ImageBase - ); - - if (EFI_ERROR(Status)) { - PrintHeader ('K'); - return Status; - } - - // - // Load each directory of the image into memory... - // Save the address of the Debug directory for later - // - if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - NumberOfRvaAndSizes = PeHdr.Pe32.OptionalHeader.NumberOfRvaAndSizes; - DataDirectory = PeHdr.Pe32.OptionalHeader.DataDirectory; - } else { - NumberOfRvaAndSizes = PeHdr.Pe32Plus.OptionalHeader.NumberOfRvaAndSizes; - DataDirectory = PeHdr.Pe32Plus.OptionalHeader.DataDirectory; - } - DebugEntry = NULL; - for (Index = 0; Index < NumberOfRvaAndSizes; Index++) { - if ((DataDirectory[Index].VirtualAddress != 0) && (DataDirectory[Index].Size != 0)) { - Status = EfiLdrPeCoffImageRead ( - FHand, - DataDirectory[Index].VirtualAddress, - DataDirectory[Index].Size, - Image->ImageBase + DataDirectory[Index].VirtualAddress - ); - if (EFI_ERROR(Status)) { - return Status; - } - if (Index == EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) { - DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (Image->ImageBase + DataDirectory[Index].VirtualAddress); - } - } - } - - // - // Load each section of the image - // - - // BUGBUG: change this to use the in memory copy - if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - OptionalHeaderSize = sizeof(EFI_IMAGE_OPTIONAL_HEADER32); - PeHeaderSize = sizeof(EFI_IMAGE_NT_HEADERS32); - } else { - OptionalHeaderSize = sizeof(EFI_IMAGE_OPTIONAL_HEADER64); - PeHeaderSize = sizeof(EFI_IMAGE_NT_HEADERS64); - } - FirstSection = (EFI_IMAGE_SECTION_HEADER *) ( - Image->ImageBase + - DosHdr.e_lfanew + - PeHeaderSize + - PeHdr.Pe32.FileHeader.SizeOfOptionalHeader - - OptionalHeaderSize - ); - - Section = FirstSection; - for (Index=0; Index < PeHdr.Pe32.FileHeader.NumberOfSections; Index += 1) { - - // - // Compute sections address - // - - Base = EfiLdrPeCoffImageAddress (Image, (UINTN)Section->VirtualAddress); - End = EfiLdrPeCoffImageAddress (Image, (UINTN)(Section->VirtualAddress + Section->Misc.VirtualSize)); - - if (EFI_ERROR(Status) || !Base || !End) { -// DEBUG((D_LOAD|D_ERROR, "LoadPe: Section %d was not loaded\n", Index)); - PrintHeader ('L'); - return EFI_LOAD_ERROR; - } - -// DEBUG((D_LOAD, "LoadPe: Section %d, loaded at %x\n", Index, Base)); - - // - // Read the section - // - - if (Section->SizeOfRawData) { - Status = EfiLdrPeCoffImageRead (FHand, Section->PointerToRawData, Section->SizeOfRawData, Base); - if (EFI_ERROR(Status)) { -PrintHeader ('M'); - return Status; - } - } - - // - // If raw size is less then virt size, zero fill the remaining - // - - if (Section->SizeOfRawData < Section->Misc.VirtualSize) { - ZeroMem ( - Base + Section->SizeOfRawData, - Section->Misc.VirtualSize - Section->SizeOfRawData - ); - } - - // - // Next Section - // - - Section += 1; - } - - // - // Copy in CodeView information if it exists - // - if (CodeViewSize != 0) { - Status = EfiLdrPeCoffImageRead (FHand, CodeViewFileOffset, CodeViewSize, Image->ImageBase + CodeViewOffset); - DebugEntry->RVA = (UINT32) (CodeViewOffset); - } - - // - // Apply relocations only if needed - // - if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - ImageBase = (UINT64)PeHdr.Pe32.OptionalHeader.ImageBase; - } else { - ImageBase = PeHdr.Pe32Plus.OptionalHeader.ImageBase; - } - if ((UINTN)(Image->ImageBase) != (UINTN) (ImageBase)) { - Status = EfiLdrPeCoffLoadPeRelocate ( - Image, - &DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC], - (UINTN) Image->ImageBase - (UINTN)ImageBase, - NumberOfMemoryMapEntries, - EfiMemoryDescriptor - ); - - if (EFI_ERROR(Status)) { - PrintHeader ('N'); - return Status; - } - } - - // - // Use exported EFI specific interface if present, else use the image's entry point - // - Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN) - (EfiLdrPeCoffImageAddress( - Image, - PeHdr.Pe32.OptionalHeader.AddressOfEntryPoint - )); - - return Status; -} - -EFI_STATUS -EfiLdrPeCoffLoadPeRelocate ( - IN EFILDR_LOADED_IMAGE *Image, - IN EFI_IMAGE_DATA_DIRECTORY *RelocDir, - IN UINTN Adjust, - IN UINTN *NumberOfMemoryMapEntries, - IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor - ) -{ - EFI_IMAGE_BASE_RELOCATION *RelocBase; - EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd; - UINT16 *Reloc; - UINT16 *RelocEnd; - UINT8 *Fixup; - UINT8 *FixupBase; - UINT16 *F16; - UINT32 *F32; - UINT64 *F64; - UINT8 *FixupData; - UINTN NoFixupPages; - - // - // Find the relocation block - // - - RelocBase = EfiLdrPeCoffImageAddress (Image, RelocDir->VirtualAddress); - RelocBaseEnd = EfiLdrPeCoffImageAddress (Image, RelocDir->VirtualAddress + RelocDir->Size); - if (!RelocBase || !RelocBaseEnd) { -PrintHeader ('O'); - return EFI_LOAD_ERROR; - } - - NoFixupPages = EFI_SIZE_TO_PAGES(RelocDir->Size / sizeof(UINT16) * sizeof(UINTN)); - Image->FixupData = (UINT8*) FindSpace (NoFixupPages, NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB); - if (Image->FixupData == 0) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Run the whole relocation block - // - - FixupData = Image->FixupData; - while (RelocBase < RelocBaseEnd) { - - Reloc = (UINT16 *) ((UINT8 *) RelocBase + sizeof(EFI_IMAGE_BASE_RELOCATION)); - RelocEnd = (UINT16 *) ((UINT8 *) RelocBase + RelocBase->SizeOfBlock); - FixupBase = EfiLdrPeCoffImageAddress (Image, RelocBase->VirtualAddress); - if ((UINT8 *) RelocEnd < Image->ImageBase || (UINT8 *) RelocEnd > Image->ImageEof) { -PrintHeader ('P'); - return EFI_LOAD_ERROR; - } - - // - // Run this relocation record - // - - while (Reloc < RelocEnd) { - - Fixup = FixupBase + (*Reloc & 0xFFF); - switch ((*Reloc) >> 12) { - - case EFI_IMAGE_REL_BASED_ABSOLUTE: - break; - - case EFI_IMAGE_REL_BASED_HIGH: - F16 = (UINT16 *) Fixup; - *F16 = (UINT16) (*F16 + (UINT16)(((UINT32)Adjust) >> 16)); - if (FixupData != NULL) { - *(UINT16 *) FixupData = *F16; - FixupData = FixupData + sizeof(UINT16); - } - break; - - case EFI_IMAGE_REL_BASED_LOW: - F16 = (UINT16 *) Fixup; - *F16 = (UINT16) (*F16 + (UINT16) Adjust); - if (FixupData != NULL) { - *(UINT16 *) FixupData = *F16; - FixupData = FixupData + sizeof(UINT16); - } - break; - - case EFI_IMAGE_REL_BASED_HIGHLOW: - F32 = (UINT32 *) Fixup; - *F32 = *F32 + (UINT32) Adjust; - if (FixupData != NULL) { - FixupData = ALIGN_POINTER(FixupData, sizeof(UINT32)); - *(UINT32 *) FixupData = *F32; - FixupData = FixupData + sizeof(UINT32); - } - break; - - case EFI_IMAGE_REL_BASED_DIR64: - F64 = (UINT64 *) Fixup; - *F64 = *F64 + (UINT64) Adjust; - if (FixupData != NULL) { - FixupData = ALIGN_POINTER(FixupData, sizeof(UINT64)); - *(UINT64 *) FixupData = *F64; - FixupData = FixupData + sizeof(UINT64); - } - break; - - case EFI_IMAGE_REL_BASED_HIGHADJ: - CpuDeadLoop(); // BUGBUG: not done - break; - - default: -// DEBUG((D_LOAD|D_ERROR, "PeRelocate: unknown fixed type\n")); -PrintHeader ('Q'); - CpuDeadLoop(); - return EFI_LOAD_ERROR; - } - - // Next reloc record - Reloc += 1; - } - - // next reloc block - RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd; - } - - // - // Add Fixup data to whole Image (assume Fixup data just below the image), so that there is no hole in the descriptor. - // Because only NoPages or ImageBasePage will be used in EfiLoader(), we update these 2 fields. - // - Image->NoPages += NoFixupPages; - Image->ImageBasePage -= (NoFixupPages << EFI_PAGE_SHIFT); - - return EFI_SUCCESS; -} - -EFI_STATUS -EfiLdrPeCoffImageRead ( - IN VOID *FHand, - IN UINTN Offset, - IN OUT UINTN ReadSize, - OUT VOID *Buffer - ) -{ - CopyMem (Buffer, (VOID *)((UINTN)FHand + Offset), ReadSize); - - return EFI_SUCCESS; -} - -VOID * -EfiLdrPeCoffImageAddress ( - IN EFILDR_LOADED_IMAGE *Image, - IN UINTN Address - ) -{ - UINT8 *FixedAddress; - - FixedAddress = Image->ImageAdjust + Address; - - if ((FixedAddress < Image->ImageBase) || (FixedAddress > Image->ImageEof)) { -// DEBUG((D_LOAD|D_ERROR, "PeCoffImageAddress: pointer is outside of image\n")); - FixedAddress = NULL; - } - -// DEBUG(( -// D_LOAD, -// "PeCoffImageAddress: ImageBase %x, ImageEof %x, Address %x, FixedAddress %x\n", -// Image->ImageBase, -// Image->ImageEof, -// Address, -// FixedAddress -// )); - return FixedAddress; -} - - -EFI_STATUS -EfiLdrPeCoffSetImageType ( - IN OUT EFILDR_LOADED_IMAGE *Image, - IN UINTN ImageType - ) -{ - EFI_MEMORY_TYPE CodeType; - EFI_MEMORY_TYPE DataType; - - switch (ImageType) { - case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION: - CodeType = EfiLoaderCode; - DataType = EfiLoaderData; - break; - - case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER: - CodeType = EfiBootServicesCode; - DataType = EfiBootServicesData; - break; - - case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER: - CodeType = EfiRuntimeServicesCode; - DataType = EfiRuntimeServicesData; - break; - - default: - return EFI_INVALID_PARAMETER; - } - - Image->Type = ImageType; - Image->Info.ImageCodeType = CodeType; - Image->Info.ImageDataType = DataType; - - return EFI_SUCCESS; -} - -EFI_STATUS -EfiLdrPeCoffCheckImageMachineType ( - IN UINT16 MachineType - ) -{ - EFI_STATUS Status; - - Status = EFI_UNSUPPORTED; - -#ifdef MDE_CPU_IA32 - if (MachineType == EFI_IMAGE_MACHINE_IA32) { - Status = EFI_SUCCESS; - } -#endif - -#ifdef MDE_CPU_X64 - if (MachineType == EFI_IMAGE_MACHINE_X64) { - Status = EFI_SUCCESS; - } -#endif - -#ifdef MDE_CPU_IPF - if (MachineType == EFI_IMAGE_MACHINE_IA64) { - Status = EFI_SUCCESS; - } -#endif - - return Status; -} - diff --git a/DuetPkg/EfiLdr/PeLoader.h b/DuetPkg/EfiLdr/PeLoader.h deleted file mode 100644 index c6c2398737..0000000000 --- a/DuetPkg/EfiLdr/PeLoader.h +++ /dev/null @@ -1,42 +0,0 @@ -/*++ - -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. - -Module Name: - PeLoader.h - -Abstract: - -Revision History: - ---*/ - -#ifndef _EFILDR_PELOADER_H_ -#define _EFILDR_PELOADER_H_ - -#include "EfiLdr.h" - -EFI_STATUS -EfiLdrGetPeImageInfo ( - IN VOID *FHand, - OUT UINT64 *ImageBase, - OUT UINT32 *ImageSize - ); - -EFI_STATUS -EfiLdrPeCoffLoadPeImage ( - IN VOID *FHand, - IN EFILDR_LOADED_IMAGE *Image, - IN UINTN *NumberOfMemoryMapEntries, - IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor - ); - - -#endif diff --git a/DuetPkg/EfiLdr/Support.c b/DuetPkg/EfiLdr/Support.c deleted file mode 100644 index a0c9046935..0000000000 --- a/DuetPkg/EfiLdr/Support.c +++ /dev/null @@ -1,237 +0,0 @@ -/*++ - -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. - -Module Name: - Support.c - -Abstract: - -Revision History: - ---*/ -#include "EfiLdr.h" - -EFI_STATUS -EfiAddMemoryDescriptor( - UINTN *NoDesc, - EFI_MEMORY_DESCRIPTOR *Desc, - EFI_MEMORY_TYPE Type, - EFI_PHYSICAL_ADDRESS BaseAddress, - UINT64 NoPages, - UINT64 Attribute - ) -{ - UINTN NumberOfDesc; - UINT64 Temp; - UINTN Index; - - if (NoPages == 0) { - return EFI_SUCCESS; - } - - // - // See if the new memory descriptor needs to be carved out of an existing memory descriptor - // - - NumberOfDesc = *NoDesc; - for (Index = 0; Index < NumberOfDesc; Index++) { - - if (Desc[Index].Type == EfiConventionalMemory) { - - Temp = DivU64x32 ((BaseAddress - Desc[Index].PhysicalStart), EFI_PAGE_SIZE) + NoPages; - - if ((Desc[Index].PhysicalStart < BaseAddress) && (Desc[Index].NumberOfPages >= Temp)) { - if (Desc[Index].NumberOfPages > Temp) { - Desc[*NoDesc].Type = EfiConventionalMemory; - Desc[*NoDesc].PhysicalStart = BaseAddress + MultU64x32 (NoPages, EFI_PAGE_SIZE); - Desc[*NoDesc].NumberOfPages = Desc[Index].NumberOfPages - Temp; - Desc[*NoDesc].VirtualStart = 0; - Desc[*NoDesc].Attribute = Desc[Index].Attribute; - *NoDesc = *NoDesc + 1; - } - Desc[Index].NumberOfPages = Temp - NoPages; - } - - if ((Desc[Index].PhysicalStart == BaseAddress) && (Desc[Index].NumberOfPages == NoPages)) { - Desc[Index].Type = Type; - Desc[Index].Attribute = Attribute; - return EFI_SUCCESS; - } - - if ((Desc[Index].PhysicalStart == BaseAddress) && (Desc[Index].NumberOfPages > NoPages)) { - Desc[Index].NumberOfPages -= NoPages; - Desc[Index].PhysicalStart += MultU64x32 (NoPages, EFI_PAGE_SIZE); - } - } - } - - // - // Add the new memory descriptor - // - - Desc[*NoDesc].Type = Type; - Desc[*NoDesc].PhysicalStart = BaseAddress; - Desc[*NoDesc].NumberOfPages = NoPages; - Desc[*NoDesc].VirtualStart = 0; - Desc[*NoDesc].Attribute = Attribute; - *NoDesc = *NoDesc + 1; - - return EFI_SUCCESS; -} - -UINTN -FindSpace ( - UINTN NoPages, - IN UINTN *NumberOfMemoryMapEntries, - IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor, - EFI_MEMORY_TYPE Type, - UINT64 Attribute - ) -{ - EFI_PHYSICAL_ADDRESS MaxPhysicalStart; - UINT64 MaxNoPages; - UINTN Index; - EFI_MEMORY_DESCRIPTOR *CurrentMemoryDescriptor; - - MaxPhysicalStart = 0; - MaxNoPages = 0; - CurrentMemoryDescriptor = NULL; - for (Index = 0; Index < *NumberOfMemoryMapEntries; Index++) { - if (EfiMemoryDescriptor[Index].PhysicalStart + LShiftU64(EfiMemoryDescriptor[Index].NumberOfPages, EFI_PAGE_SHIFT) <= 0x100000) { - continue; - } - if ((EfiMemoryDescriptor[Index].Type == EfiConventionalMemory) && - (EfiMemoryDescriptor[Index].NumberOfPages >= NoPages)) { - if (EfiMemoryDescriptor[Index].PhysicalStart > MaxPhysicalStart) { - if (EfiMemoryDescriptor[Index].PhysicalStart + LShiftU64(EfiMemoryDescriptor[Index].NumberOfPages, EFI_PAGE_SHIFT) <= 0x100000000ULL) { - MaxPhysicalStart = EfiMemoryDescriptor[Index].PhysicalStart; - MaxNoPages = EfiMemoryDescriptor[Index].NumberOfPages; - CurrentMemoryDescriptor = &EfiMemoryDescriptor[Index]; - } - } - } - if ((EfiMemoryDescriptor[Index].Type == EfiReservedMemoryType) || - (EfiMemoryDescriptor[Index].Type >= EfiACPIReclaimMemory) ) { - continue; - } - if ((EfiMemoryDescriptor[Index].Type == EfiRuntimeServicesCode) || - (EfiMemoryDescriptor[Index].Type == EfiRuntimeServicesData)) { - break; - } - } - - if (MaxPhysicalStart == 0) { - return 0; - } - - if (MaxNoPages != NoPages) { - CurrentMemoryDescriptor->NumberOfPages = MaxNoPages - NoPages; - EfiMemoryDescriptor[*NumberOfMemoryMapEntries].Type = Type; - EfiMemoryDescriptor[*NumberOfMemoryMapEntries].PhysicalStart = MaxPhysicalStart + LShiftU64(MaxNoPages - NoPages, EFI_PAGE_SHIFT); - EfiMemoryDescriptor[*NumberOfMemoryMapEntries].NumberOfPages = NoPages; - EfiMemoryDescriptor[*NumberOfMemoryMapEntries].VirtualStart = 0; - EfiMemoryDescriptor[*NumberOfMemoryMapEntries].Attribute = Attribute; - *NumberOfMemoryMapEntries = *NumberOfMemoryMapEntries + 1; - } else { - CurrentMemoryDescriptor->Type = Type; - CurrentMemoryDescriptor->Attribute = Attribute; - } - - return (UINTN)(MaxPhysicalStart + LShiftU64(MaxNoPages - NoPages, EFI_PAGE_SHIFT)); -} - -VOID -GenMemoryMap ( - UINTN *NumberOfMemoryMapEntries, - EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor, - BIOS_MEMORY_MAP *BiosMemoryMap - ) -{ - UINT64 BaseAddress; - UINT64 Length; - EFI_MEMORY_TYPE Type; - UINTN Index; - UINTN Attr; - UINT64 Ceiling; - - Ceiling = 0xFFFFFFFF; - for (Index = 0; Index < BiosMemoryMap->MemoryMapSize / sizeof(BIOS_MEMORY_MAP_ENTRY); Index++) { - - switch (BiosMemoryMap->MemoryMapEntry[Index].Type) { - case (INT15_E820_AddressRangeMemory): - Type = EfiConventionalMemory; - Attr = EFI_MEMORY_WB; - break; - case (INT15_E820_AddressRangeReserved): - Type = EfiReservedMemoryType; - Attr = EFI_MEMORY_UC; - break; - case (INT15_E820_AddressRangeACPI): - Type = EfiACPIReclaimMemory; - Attr = EFI_MEMORY_WB; - break; - case (INT15_E820_AddressRangeNVS): - Type = EfiACPIMemoryNVS; - Attr = EFI_MEMORY_UC; - break; - default: - // We should not get here, according to ACPI 2.0 Spec. - // BIOS behaviour of the Int15h, E820h - Type = EfiReservedMemoryType; - Attr = EFI_MEMORY_UC; - break; - } - if (Type == EfiConventionalMemory) { - BaseAddress = BiosMemoryMap->MemoryMapEntry[Index].BaseAddress; - Length = BiosMemoryMap->MemoryMapEntry[Index].Length; - if (BaseAddress & EFI_PAGE_MASK) { - Length = Length + (BaseAddress & EFI_PAGE_MASK) - EFI_PAGE_SIZE; - BaseAddress = LShiftU64 (RShiftU64 (BaseAddress, EFI_PAGE_SHIFT) + 1, EFI_PAGE_SHIFT); - } - } else { - BaseAddress = BiosMemoryMap->MemoryMapEntry[Index].BaseAddress; - Length = BiosMemoryMap->MemoryMapEntry[Index].Length + (BaseAddress & EFI_PAGE_MASK); - BaseAddress = LShiftU64 (RShiftU64 (BaseAddress, EFI_PAGE_SHIFT), EFI_PAGE_SHIFT); - if (Length & EFI_PAGE_MASK) { - Length = LShiftU64 (RShiftU64 (Length, EFI_PAGE_SHIFT) + 1, EFI_PAGE_SHIFT); - } - // - // Update Memory Ceiling - // - if ((BaseAddress >= 0x100000) && (BaseAddress < 0x100000000ULL)) { - if (Ceiling > BaseAddress) { - Ceiling = BaseAddress; - } - } - } - EfiAddMemoryDescriptor ( - NumberOfMemoryMapEntries, - EfiMemoryDescriptor, - Type, - (EFI_PHYSICAL_ADDRESS)BaseAddress, - RShiftU64 (Length, EFI_PAGE_SHIFT), - Attr - ); - } - - // - // Update MemoryMap according to Ceiling - // - for (Index = 0; Index < *NumberOfMemoryMapEntries; Index++) { - if ((EfiMemoryDescriptor[Index].Type == EfiConventionalMemory) && - (EfiMemoryDescriptor[Index].PhysicalStart > 0x100000) && - (EfiMemoryDescriptor[Index].PhysicalStart < 0x100000000ULL)) { - if (EfiMemoryDescriptor[Index].PhysicalStart >= Ceiling) { - EfiMemoryDescriptor[Index].Type = EfiReservedMemoryType; - } - } - } -} diff --git a/DuetPkg/EfiLdr/Support.h b/DuetPkg/EfiLdr/Support.h deleted file mode 100644 index 6c5789a943..0000000000 --- a/DuetPkg/EfiLdr/Support.h +++ /dev/null @@ -1,50 +0,0 @@ -/*++ - -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. - -Module Name: - Support.h - -Abstract: - -Revision History: - ---*/ - -#ifndef _EFILDR_SUPPORT_H_ -#define _EFILDR_SUPPORT_H_ - -EFI_STATUS -EfiAddMemoryDescriptor( - UINTN *NoDesc, - EFI_MEMORY_DESCRIPTOR *Desc, - EFI_MEMORY_TYPE Type, - EFI_PHYSICAL_ADDRESS BaseAddress, - UINT64 NoPages, - UINT64 Attribute - ); - -UINTN -FindSpace( - UINTN NoPages, - IN UINTN *NumberOfMemoryMapEntries, - IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor, - EFI_MEMORY_TYPE Type, - UINT64 Attribute - ); - -VOID -GenMemoryMap ( - UINTN *NumberOfMemoryMapEntries, - EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor, - BIOS_MEMORY_MAP *BiosMemoryMap - ); - -#endif diff --git a/DuetPkg/EfiLdr/TianoDecompress.c b/DuetPkg/EfiLdr/TianoDecompress.c deleted file mode 100644 index 6fed7a1591..0000000000 --- a/DuetPkg/EfiLdr/TianoDecompress.c +++ /dev/null @@ -1,990 +0,0 @@ -/*++ - -Copyright (c) 2004 - 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. - -Module Name: - - Decompress.c - -Abstract: - - Decompressor. Algorithm Ported from OPSD code (Decomp.asm) - ---*/ -#include -// -// Decompression algorithm begins here -// -#define BITBUFSIZ 32 -#define MAXMATCH 256 -#define THRESHOLD 3 -#define CODE_BIT 16 -#define BAD_TABLE - 1 - -// -// C: Char&Len Set; P: Position Set; T: exTra Set -// -#define NC (0xff + MAXMATCH + 2 - THRESHOLD) -#define CBIT 9 -#define MAXPBIT 5 -#define TBIT 5 -#define MAXNP ((1U << MAXPBIT) - 1) -#define NT (CODE_BIT + 3) -#if NT > MAXNP -#define NPT NT -#else -#define NPT MAXNP -#endif - -typedef struct { - UINT8 *mSrcBase; // Starting address of compressed data - UINT8 *mDstBase; // Starting address of decompressed data - UINT32 mOutBuf; - UINT32 mInBuf; - - UINT16 mBitCount; - UINT32 mBitBuf; - UINT32 mSubBitBuf; - UINT16 mBlockSize; - UINT32 mCompSize; - UINT32 mOrigSize; - - UINT16 mBadTableFlag; - - UINT16 mLeft[2 * NC - 1]; - UINT16 mRight[2 * NC - 1]; - UINT8 mCLen[NC]; - UINT8 mPTLen[NPT]; - UINT16 mCTable[4096]; - UINT16 mPTTable[256]; - - // - // The length of the field 'Position Set Code Length Array Size' in Block Header. - // For EFI 1.1 de/compression algorithm, mPBit = 4 - // For Tiano de/compression algorithm, mPBit = 5 - // - UINT8 mPBit; -} SCRATCH_DATA; - -VOID -FillBuf ( - IN SCRATCH_DATA *Sd, - IN UINT16 NumOfBits - ) -/*++ - -Routine Description: - - Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source. - -Arguments: - - Sd - The global scratch data - NumOfBits - The number of bits to shift and read. - -Returns: (VOID) - ---*/ -{ - Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits); - - while (NumOfBits > Sd->mBitCount) { - - Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount))); - - if (Sd->mCompSize > 0) { - // - // Get 1 byte into SubBitBuf - // - Sd->mCompSize--; - Sd->mSubBitBuf = 0; - Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++]; - Sd->mBitCount = 8; - - } else { - // - // No more bits from the source, just pad zero bit. - // - Sd->mSubBitBuf = 0; - Sd->mBitCount = 8; - - } - } - - Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits); - Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount; -} - -UINT32 -GetBits ( - IN SCRATCH_DATA *Sd, - IN UINT16 NumOfBits - ) -/*++ - -Routine Description: - - Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent - NumOfBits of bits from source. Returns NumOfBits of bits that are - popped out. - -Arguments: - - Sd - The global scratch data. - NumOfBits - The number of bits to pop and read. - -Returns: - - The bits that are popped out. - ---*/ -{ - UINT32 OutBits; - - OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits)); - - FillBuf (Sd, NumOfBits); - - return OutBits; -} - -UINT16 -MakeTable ( - IN SCRATCH_DATA *Sd, - IN UINT16 NumOfChar, - IN UINT8 *BitLen, - IN UINT16 TableBits, - OUT UINT16 *Table - ) -/*++ - -Routine Description: - - Creates Huffman Code mapping table according to code length array. - -Arguments: - - Sd - The global scratch data - NumOfChar - Number of symbols in the symbol set - BitLen - Code length array - TableBits - The width of the mapping table - Table - The table - -Returns: - - 0 - OK. - BAD_TABLE - The table is corrupted. - ---*/ -{ - UINT16 Count[17]; - UINT16 Weight[17]; - UINT16 Start[18]; - UINT16 *Pointer; - UINT16 Index3; - volatile UINT16 Index; - UINT16 Len; - UINT16 Char; - UINT16 JuBits; - UINT16 Avail; - UINT16 NextCode; - UINT16 Mask; - UINT16 WordOfStart; - UINT16 WordOfCount; - - for (Index = 1; Index <= 16; Index++) { - Count[Index] = 0; - } - - for (Index = 0; Index < NumOfChar; Index++) { - Count[BitLen[Index]]++; - } - - Start[1] = 0; - - for (Index = 1; Index <= 16; Index++) { - WordOfStart = Start[Index]; - WordOfCount = Count[Index]; - Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index))); - } - - if (Start[17] != 0) { - /*(1U << 16)*/ - return (UINT16) BAD_TABLE; - } - - JuBits = (UINT16) (16 - TableBits); - - for (Index = 1; Index <= TableBits; Index++) { - Start[Index] >>= JuBits; - Weight[Index] = (UINT16) (1U << (TableBits - Index)); - } - - while (Index <= 16) { - Weight[Index] = (UINT16) (1U << (16 - Index)); - Index++; - } - - Index = (UINT16) (Start[TableBits + 1] >> JuBits); - - if (Index != 0) { - Index3 = (UINT16) (1U << TableBits); - while (Index != Index3) { - Table[Index++] = 0; - } - } - - Avail = NumOfChar; - Mask = (UINT16) (1U << (15 - TableBits)); - - for (Char = 0; Char < NumOfChar; Char++) { - - Len = BitLen[Char]; - if (Len == 0) { - continue; - } - - NextCode = (UINT16) (Start[Len] + Weight[Len]); - - if (Len <= TableBits) { - - for (Index = Start[Len]; Index < NextCode; Index++) { - Table[Index] = Char; - } - - } else { - - Index3 = Start[Len]; - Pointer = &Table[Index3 >> JuBits]; - Index = (UINT16) (Len - TableBits); - - while (Index != 0) { - if (*Pointer == 0) { - Sd->mRight[Avail] = Sd->mLeft[Avail] = 0; - *Pointer = Avail++; - } - - if (Index3 & Mask) { - Pointer = &Sd->mRight[*Pointer]; - } else { - Pointer = &Sd->mLeft[*Pointer]; - } - - Index3 <<= 1; - Index--; - } - - *Pointer = Char; - - } - - Start[Len] = NextCode; - } - // - // Succeeds - // - return 0; -} - -UINT32 -DecodeP ( - IN SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - - Decodes a position value. - -Arguments: - - Sd - the global scratch data - -Returns: - - The position value decoded. - ---*/ -{ - UINT16 Val; - UINT32 Mask; - UINT32 Pos; - - Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)]; - - if (Val >= MAXNP) { - Mask = 1U << (BITBUFSIZ - 1 - 8); - - do { - - if (Sd->mBitBuf & Mask) { - Val = Sd->mRight[Val]; - } else { - Val = Sd->mLeft[Val]; - } - - Mask >>= 1; - } while (Val >= MAXNP); - } - // - // Advance what we have read - // - FillBuf (Sd, Sd->mPTLen[Val]); - - Pos = Val; - if (Val > 1) { - Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1))); - } - - return Pos; -} - -UINT16 -ReadPTLen ( - IN SCRATCH_DATA *Sd, - IN UINT16 nn, - IN UINT16 nbit, - IN UINT16 Special - ) -/*++ - -Routine Description: - - Reads code lengths for the Extra Set or the Position Set - -Arguments: - - Sd - The global scratch data - nn - Number of symbols - nbit - Number of bits needed to represent nn - Special - The special symbol that needs to be taken care of - -Returns: - - 0 - OK. - BAD_TABLE - Table is corrupted. - ---*/ -{ - UINT16 Number; - UINT16 CharC; - volatile UINT16 Index; - UINT32 Mask; - - Number = (UINT16) GetBits (Sd, nbit); - - if (Number == 0) { - CharC = (UINT16) GetBits (Sd, nbit); - - for (Index = 0; Index < 256; Index++) { - Sd->mPTTable[Index] = CharC; - } - - for (Index = 0; Index < nn; Index++) { - Sd->mPTLen[Index] = 0; - } - - return 0; - } - - Index = 0; - - while (Index < Number) { - - CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3)); - - if (CharC == 7) { - Mask = 1U << (BITBUFSIZ - 1 - 3); - while (Mask & Sd->mBitBuf) { - Mask >>= 1; - CharC += 1; - } - } - - FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3)); - - Sd->mPTLen[Index++] = (UINT8) CharC; - - if (Index == Special) { - CharC = (UINT16) GetBits (Sd, 2); - while ((INT16) (--CharC) >= 0) { - Sd->mPTLen[Index++] = 0; - } - } - } - - while (Index < nn) { - Sd->mPTLen[Index++] = 0; - } - - return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable); -} - -VOID -ReadCLen ( - SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - - Reads code lengths for Char&Len Set. - -Arguments: - - Sd - the global scratch data - -Returns: (VOID) - ---*/ -{ - UINT16 Number; - UINT16 CharC; - volatile UINT16 Index; - UINT32 Mask; - - Number = (UINT16) GetBits (Sd, CBIT); - - if (Number == 0) { - CharC = (UINT16) GetBits (Sd, CBIT); - - for (Index = 0; Index < NC; Index++) { - Sd->mCLen[Index] = 0; - } - - for (Index = 0; Index < 4096; Index++) { - Sd->mCTable[Index] = CharC; - } - - return ; - } - - Index = 0; - while (Index < Number) { - - CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)]; - if (CharC >= NT) { - Mask = 1U << (BITBUFSIZ - 1 - 8); - - do { - - if (Mask & Sd->mBitBuf) { - CharC = Sd->mRight[CharC]; - } else { - CharC = Sd->mLeft[CharC]; - } - - Mask >>= 1; - - } while (CharC >= NT); - } - // - // Advance what we have read - // - FillBuf (Sd, Sd->mPTLen[CharC]); - - if (CharC <= 2) { - - if (CharC == 0) { - CharC = 1; - } else if (CharC == 1) { - CharC = (UINT16) (GetBits (Sd, 4) + 3); - } else if (CharC == 2) { - CharC = (UINT16) (GetBits (Sd, CBIT) + 20); - } - - while ((INT16) (--CharC) >= 0) { - Sd->mCLen[Index++] = 0; - } - - } else { - - Sd->mCLen[Index++] = (UINT8) (CharC - 2); - - } - } - - while (Index < NC) { - Sd->mCLen[Index++] = 0; - } - - MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable); - - return ; -} - -UINT16 -DecodeC ( - SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - - Decode a character/length value. - -Arguments: - - Sd - The global scratch data. - -Returns: - - The value decoded. - ---*/ -{ - UINT16 Index2; - UINT32 Mask; - - if (Sd->mBlockSize == 0) { - // - // Starting a new block - // - Sd->mBlockSize = (UINT16) GetBits (Sd, 16); - Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3); - if (Sd->mBadTableFlag != 0) { - return 0; - } - - ReadCLen (Sd); - - Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1)); - if (Sd->mBadTableFlag != 0) { - return 0; - } - } - - Sd->mBlockSize--; - Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)]; - - if (Index2 >= NC) { - Mask = 1U << (BITBUFSIZ - 1 - 12); - - do { - if (Sd->mBitBuf & Mask) { - Index2 = Sd->mRight[Index2]; - } else { - Index2 = Sd->mLeft[Index2]; - } - - Mask >>= 1; - } while (Index2 >= NC); - } - // - // Advance what we have read - // - FillBuf (Sd, Sd->mCLen[Index2]); - - return Index2; -} - -VOID -Decode ( - SCRATCH_DATA *Sd - ) -/*++ - -Routine Description: - - Decode the source data and put the resulting data into the destination buffer. - -Arguments: - - Sd - The global scratch data - -Returns: (VOID) - - --*/ -{ - UINT16 BytesRemain; - UINT32 DataIdx; - UINT16 CharC; - - BytesRemain = (UINT16) (-1); - - DataIdx = 0; - - for (;;) { - CharC = DecodeC (Sd); - if (Sd->mBadTableFlag != 0) { - goto Done ; - } - - if (CharC < 256) { - // - // Process an Original character - // - if (Sd->mOutBuf >= Sd->mOrigSize) { - goto Done ; - } else { - Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC; - } - - } else { - // - // Process a Pointer - // - CharC = (UINT16) (CharC - (BIT8 - THRESHOLD)); - - BytesRemain = CharC; - - DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1; - - BytesRemain--; - while ((INT16) (BytesRemain) >= 0) { - Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++]; - if (Sd->mOutBuf >= Sd->mOrigSize) { - goto Done ; - } - - BytesRemain--; - } - } - } - -Done: - return ; -} - -EFI_STATUS -GetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ) -/*++ - -Routine Description: - - The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo(). - -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - UINT8 *Src; - - *ScratchSize = sizeof (SCRATCH_DATA); - - Src = Source; - if (SrcSize < 8) { - return EFI_INVALID_PARAMETER; - } - - *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); - return EFI_SUCCESS; -} - -EFI_STATUS -Decompress ( - IN VOID *Source, - IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize, - IN UINT8 Version - ) -/*++ - -Routine Description: - - The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress(). - -Arguments: - - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - Version - The version of de/compression algorithm. - Version 1 for EFI 1.1 de/compression algorithm. - Version 2 for Tiano de/compression algorithm. - -Returns: - - EFI_SUCCESS - Decompression is successfull - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - UINT32 CompSize; - UINT32 OrigSize; - EFI_STATUS Status; - SCRATCH_DATA *Sd; - UINT8 *Src; - UINT8 *Dst; - volatile UINT32 Index; - - Status = EFI_SUCCESS; - Src = Source; - Dst = Destination; - - if (ScratchSize < sizeof (SCRATCH_DATA)) { - return EFI_INVALID_PARAMETER; - } - - Sd = (SCRATCH_DATA *) Scratch; - - if (SrcSize < 8) { - return EFI_INVALID_PARAMETER; - } - - CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24); - OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24); - - // - // If compressed file size is 0, return - // - if (OrigSize == 0) { - return Status; - } - - if (SrcSize < CompSize + 8) { - return EFI_INVALID_PARAMETER; - } - - if (DstSize != OrigSize) { - return EFI_INVALID_PARAMETER; - } - - Src = Src + 8; - - for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) { - ((UINT8 *) Sd)[Index] = 0; - } - - // - // The length of the field 'Position Set Code Length Array Size' in Block Header. - // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4 - // For Tiano de/compression algorithm(Version 2), mPBit = 5 - // - switch (Version) { - case 1: - Sd->mPBit = 4; - break; - - case 2: - Sd->mPBit = 5; - break; - - default: - // - // Currently, only have 2 versions - // - return EFI_INVALID_PARAMETER; - } - - Sd->mSrcBase = Src; - Sd->mDstBase = Dst; - Sd->mCompSize = CompSize; - Sd->mOrigSize = OrigSize; - - // - // Fill the first BITBUFSIZ bits - // - FillBuf (Sd, BITBUFSIZ); - - // - // Decompress it - // - Decode (Sd); - - if (Sd->mBadTableFlag != 0) { - // - // Something wrong with the source - // - Status = EFI_INVALID_PARAMETER; - } - - return Status; -} - -EFI_STATUS -EFIAPI -EfiGetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ) -/*++ - -Routine Description: - - The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo(). - -Arguments: - - This - The protocol instance pointer - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - return GetInfo ( - Source, - SrcSize, - DstSize, - ScratchSize - ); -} - -EFI_STATUS -EFIAPI -EfiDecompress ( - IN VOID *Source, - IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ) -/*++ - -Routine Description: - - The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress(). - -Arguments: - - This - The protocol instance pointer - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successfull - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - // - // For EFI 1.1 de/compression algorithm, the version is 1. - // - return Decompress ( - Source, - SrcSize, - Destination, - DstSize, - Scratch, - ScratchSize, - 1 - ); -} - -EFI_STATUS -EFIAPI -TianoGetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ) -/*++ - -Routine Description: - - The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo(). - -Arguments: - - This - The protocol instance pointer - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - return GetInfo ( - Source, - SrcSize, - DstSize, - ScratchSize - ); -} - -EFI_STATUS -EFIAPI -TianoDecompress ( - IN VOID *Source, - IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ) -/*++ - -Routine Description: - - The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress(). - -Arguments: - - This - The protocol instance pointer - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successfull - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -{ - // - // For Tiano de/compression algorithm, the version is 2. - // - return Decompress ( - Source, - SrcSize, - Destination, - DstSize, - Scratch, - ScratchSize, - 2 - ); -} - diff --git a/DuetPkg/EfiLdr/TianoDecompress.h b/DuetPkg/EfiLdr/TianoDecompress.h deleted file mode 100644 index 0d85b7bd0f..0000000000 --- a/DuetPkg/EfiLdr/TianoDecompress.h +++ /dev/null @@ -1,90 +0,0 @@ -/** @file - Internal include file for Base UEFI Decompress Libary. - - 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. - - Module Name: BaseUefiCustomDecompressLibInternals.h - -**/ - -#ifndef __BASE_UEFI_TIANO_CUSTOM_DECOMPRESS_LIB_INTERNALS_H__ -#define __BASE_UEFI_TIANO_CUSTOM_DECOMPRESS_LIB_INTERNALS_H__ - -#include - -#include -#include -#include - -EFI_STATUS -EFIAPI -TianoGetInfo ( - IN VOID *Source, - IN UINT32 SrcSize, - OUT UINT32 *DstSize, - OUT UINT32 *ScratchSize - ) -/*++ - -Routine Description: - - The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo(). - -Arguments: - - This - The protocol instance pointer - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - DstSize - The size of destination buffer. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -; - -EFI_STATUS -EFIAPI -TianoDecompress ( - IN VOID *Source, - IN UINT32 SrcSize, - IN OUT VOID *Destination, - IN UINT32 DstSize, - IN OUT VOID *Scratch, - IN UINT32 ScratchSize - ) -/*++ - -Routine Description: - - The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress(). - -Arguments: - - This - The protocol instance pointer - Source - The source buffer containing the compressed data. - SrcSize - The size of source buffer - Destination - The destination buffer to store the decompressed data - DstSize - The size of destination buffer. - Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data. - ScratchSize - The size of scratch buffer. - -Returns: - - EFI_SUCCESS - Decompression is successfull - EFI_INVALID_PARAMETER - The source data is corrupted - ---*/ -; - -#endif diff --git a/DuetPkg/EfiLdr/efildr.c b/DuetPkg/EfiLdr/efildr.c deleted file mode 100644 index 2b40aca94e..0000000000 --- a/DuetPkg/EfiLdr/efildr.c +++ /dev/null @@ -1,28 +0,0 @@ -/*++ - -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. - -Module Name: - EfiLdr.c - -Abstract: - -Revision History: - ---*/ - -// -// BUGBUG, include all C files -// -#include "EfiLoader.c" -#include "PeLoader.c" -#include "Support.c" -#include "Debug.c" - -- cgit v1.2.3