From 5dce0991864ec5a10add570dca2f8dd850ea29bf Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Thu, 22 Dec 2016 18:20:23 +0800 Subject: EmbeddedPkg: Remove unused Package Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang --- EmbeddedPkg/Library/AcpiLib/AcpiLib.c | 178 -- EmbeddedPkg/Library/AcpiLib/AcpiLib.inf | 36 - .../DebugAgentTimerLibNull/DebugAgentTimerLib.c | 63 - .../DebugAgentTimerLibNull.inf | 37 - EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoff.c | 288 ---- .../Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf | 44 - .../EblAddExternalCommandLib.c | 155 -- .../EblAddExternalCommandLib.inf | 47 - EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.c | 28 - .../Library/EblCmdLibNull/EblCmdLibNull.inf | 43 - EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.c | 173 -- .../Library/EblNetworkLib/EblNetworkLib.inf | 34 - EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c | 1779 -------------------- EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf | 64 - EmbeddedPkg/Library/FdtLib/FdtLib.inf | 38 - EmbeddedPkg/Library/FdtLib/Makefile.libfdt | 10 - EmbeddedPkg/Library/FdtLib/README.txt | 1 - EmbeddedPkg/Library/FdtLib/TODO | 3 - EmbeddedPkg/Library/FdtLib/fdt.c | 250 --- EmbeddedPkg/Library/FdtLib/fdt_empty_tree.c | 84 - EmbeddedPkg/Library/FdtLib/fdt_ro.c | 574 ------- EmbeddedPkg/Library/FdtLib/fdt_rw.c | 495 ------ EmbeddedPkg/Library/FdtLib/fdt_strerror.c | 96 -- EmbeddedPkg/Library/FdtLib/fdt_sw.c | 256 --- EmbeddedPkg/Library/FdtLib/fdt_wip.c | 118 -- EmbeddedPkg/Library/FdtLib/libfdt_internal.h | 95 -- EmbeddedPkg/Library/FdtLib/version.lds | 60 - .../GdbDebugAgent/Arm/ExceptionSupport.ARMv6.S | 258 --- .../GdbDebugAgent/Arm/ExceptionSupport.ARMv6.asm | 259 --- EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c | 675 -------- EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c | 815 --------- EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.h | 728 -------- .../Library/GdbDebugAgent/GdbDebugAgent.inf | 70 - EmbeddedPkg/Library/GdbDebugAgent/Ia32/Processor.c | 951 ----------- EmbeddedPkg/Library/GdbDebugAgent/X64/Processor.c | 963 ----------- EmbeddedPkg/Library/GdbDebugAgent/gdbnotes.txt | 15 - .../GdbSerialDebugPortLib/GdbSerialDebugPortLib.c | 187 -- .../GdbSerialDebugPortLib.inf | 49 - EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c | 262 --- EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf | 46 - .../Library/HalRuntimeServicesExampleLib/Capsule.c | 288 ---- .../Library/HalRuntimeServicesExampleLib/Mtc.c | 226 --- .../ReportStatusCode.c | 198 --- .../Library/HalRuntimeServicesExampleLib/Reset.c | 63 - .../Library/HalRuntimeServicesExampleLib/Rtc.c | 862 ---------- .../HalRuntimeServicesExampleLib/Variable.c | 306 ---- .../LzmaHobCustomDecompressLib.c | 50 - .../LzmaHobCustomDecompressLib.inf | 50 - EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c | 149 -- EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf | 41 - .../PrePiExtractGuidedSectionLib.c | 247 --- .../PrePiExtractGuidedSectionLib.inf | 36 - EmbeddedPkg/Library/PrePiHobLib/Hob.c | 852 ---------- EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf | 64 - .../PrePiHobListPointerLib/PrePiHobListPointer.c | 69 - .../PrePiHobListPointerLib.inf | 38 - EmbeddedPkg/Library/PrePiLib/FwVol.c | 845 ---------- EmbeddedPkg/Library/PrePiLib/PrePi.h | 46 - EmbeddedPkg/Library/PrePiLib/PrePiLib.c | 226 --- EmbeddedPkg/Library/PrePiLib/PrePiLib.inf | 85 - EmbeddedPkg/Library/PrePiLib/ReportStatusCode.c | 325 ---- .../PrePiMemoryAllocationLib/MemoryAllocationLib.c | 218 --- .../PrePiMemoryAllocationLib.inf | 39 - .../TemplateRealTimeClockLib/RealTimeClockLib.c | 175 -- .../TemplateRealTimeClockLib.inf | 36 - .../TemplateResetSystemLib/ResetSystemLib.c | 103 -- .../TemplateResetSystemLib.inf | 35 - 67 files changed, 15999 deletions(-) delete mode 100644 EmbeddedPkg/Library/AcpiLib/AcpiLib.c delete mode 100644 EmbeddedPkg/Library/AcpiLib/AcpiLib.inf delete mode 100755 EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLib.c delete mode 100755 EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf delete mode 100644 EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoff.c delete mode 100644 EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf delete mode 100644 EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c delete mode 100644 EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf delete mode 100644 EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.c delete mode 100644 EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf delete mode 100644 EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.c delete mode 100644 EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf delete mode 100644 EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c delete mode 100644 EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf delete mode 100644 EmbeddedPkg/Library/FdtLib/FdtLib.inf delete mode 100644 EmbeddedPkg/Library/FdtLib/Makefile.libfdt delete mode 100755 EmbeddedPkg/Library/FdtLib/README.txt delete mode 100644 EmbeddedPkg/Library/FdtLib/TODO delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt.c delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt_empty_tree.c delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt_ro.c delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt_rw.c delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt_strerror.c delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt_sw.c delete mode 100644 EmbeddedPkg/Library/FdtLib/fdt_wip.c delete mode 100644 EmbeddedPkg/Library/FdtLib/libfdt_internal.h delete mode 100644 EmbeddedPkg/Library/FdtLib/version.lds delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.S delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.asm delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.h delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/Ia32/Processor.c delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/X64/Processor.c delete mode 100755 EmbeddedPkg/Library/GdbDebugAgent/gdbnotes.txt delete mode 100644 EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.c delete mode 100644 EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.inf delete mode 100644 EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c delete mode 100644 EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf delete mode 100644 EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Capsule.c delete mode 100644 EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Mtc.c delete mode 100644 EmbeddedPkg/Library/HalRuntimeServicesExampleLib/ReportStatusCode.c delete mode 100644 EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Reset.c delete mode 100644 EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Rtc.c delete mode 100644 EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Variable.c delete mode 100644 EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.c delete mode 100644 EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf delete mode 100755 EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c delete mode 100755 EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf delete mode 100644 EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c delete mode 100644 EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf delete mode 100644 EmbeddedPkg/Library/PrePiHobLib/Hob.c delete mode 100644 EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf delete mode 100644 EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c delete mode 100644 EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf delete mode 100644 EmbeddedPkg/Library/PrePiLib/FwVol.c delete mode 100644 EmbeddedPkg/Library/PrePiLib/PrePi.h delete mode 100644 EmbeddedPkg/Library/PrePiLib/PrePiLib.c delete mode 100644 EmbeddedPkg/Library/PrePiLib/PrePiLib.inf delete mode 100644 EmbeddedPkg/Library/PrePiLib/ReportStatusCode.c delete mode 100644 EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c delete mode 100644 EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf delete mode 100644 EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c delete mode 100644 EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf delete mode 100644 EmbeddedPkg/Library/TemplateResetSystemLib/ResetSystemLib.c delete mode 100644 EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf (limited to 'EmbeddedPkg/Library') diff --git a/EmbeddedPkg/Library/AcpiLib/AcpiLib.c b/EmbeddedPkg/Library/AcpiLib/AcpiLib.c deleted file mode 100644 index 0e27276c22..0000000000 --- a/EmbeddedPkg/Library/AcpiLib/AcpiLib.c +++ /dev/null @@ -1,178 +0,0 @@ -/** @file -* -* Copyright (c) 2014-2015, ARM Limited. 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. -* -**/ - -#include - -#include -#include -#include - -#include -#include - -#include - -/** - Locate and Install the ACPI tables from the Firmware Volume if it verifies - the function condition. - - @param AcpiFile Guid of the ACPI file into the Firmware Volume - @param CheckAcpiTableFunction Function that checks if the ACPI table should be installed - - @return EFI_SUCCESS The function completed successfully. - @return EFI_NOT_FOUND The protocol could not be located. - @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol. - -**/ -EFI_STATUS -LocateAndInstallAcpiFromFvConditional ( - IN CONST EFI_GUID* AcpiFile, - IN EFI_LOCATE_ACPI_CHECK CheckAcpiTableFunction - ) -{ - EFI_STATUS Status; - EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol; - EFI_HANDLE *HandleBuffer; - UINTN NumberOfHandles; - UINT32 FvStatus; - UINTN Index; - EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance; - INTN SectionInstance; - UINTN SectionSize; - EFI_ACPI_COMMON_HEADER *AcpiTable; - UINTN AcpiTableSize; - UINTN AcpiTableKey; - BOOLEAN Valid; - - // Ensure the ACPI Table is present - Status = gBS->LocateProtocol ( - &gEfiAcpiTableProtocolGuid, - NULL, - (VOID**)&AcpiProtocol - ); - if (EFI_ERROR (Status)) { - return Status; - } - - FvStatus = 0; - SectionInstance = 0; - - // Locate all the Firmware Volume protocols. - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolume2ProtocolGuid, - NULL, - &NumberOfHandles, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // Looking for FV with ACPI storage file - for (Index = 0; Index < NumberOfHandles; Index++) { - // - // Get the protocol on this handle - // This should not fail because of LocateHandleBuffer - // - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID**) &FvInstance - ); - if (EFI_ERROR (Status)) { - goto FREE_HANDLE_BUFFER; - } - - while (Status == EFI_SUCCESS) { - // AcpiTable must be allocated by ReadSection (ie: AcpiTable == NULL) - AcpiTable = NULL; - - // See if it has the ACPI storage file - Status = FvInstance->ReadSection ( - FvInstance, - AcpiFile, - EFI_SECTION_RAW, - SectionInstance, - (VOID**) &AcpiTable, - &SectionSize, - &FvStatus - ); - if (!EFI_ERROR (Status)) { - AcpiTableKey = 0; - AcpiTableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Length; - ASSERT (SectionSize >= AcpiTableSize); - - DEBUG ((EFI_D_ERROR, "- Found '%c%c%c%c' ACPI Table\n", - (((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature & 0xFF), - ((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 8) & 0xFF), - ((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 16) & 0xFF), - ((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 24) & 0xFF))); - - // Is the ACPI table valid? - if (CheckAcpiTableFunction) { - Valid = CheckAcpiTableFunction ((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable); - } else { - Valid = TRUE; - } - - // Install the ACPI Table - if (Valid) { - Status = AcpiProtocol->InstallAcpiTable ( - AcpiProtocol, - AcpiTable, - AcpiTableSize, - &AcpiTableKey - ); - } - - // Free memory allocated by ReadSection - gBS->FreePool (AcpiTable); - - if (EFI_ERROR (Status)) { - break; - } - - // Increment the section instance - SectionInstance++; - } - } - } - -FREE_HANDLE_BUFFER: - // - // Free any allocated buffers - // - gBS->FreePool (HandleBuffer); - - return EFI_SUCCESS; -} - -/** - Locate and Install the ACPI tables from the Firmware Volume - - @param AcpiFile Guid of the ACPI file into the Firmware Volume - - @return EFI_SUCCESS The function completed successfully. - @return EFI_NOT_FOUND The protocol could not be located. - @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol. - -**/ -EFI_STATUS -LocateAndInstallAcpiFromFv ( - IN CONST EFI_GUID* AcpiFile - ) -{ - return LocateAndInstallAcpiFromFvConditional (AcpiFile, NULL); -} diff --git a/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf b/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf deleted file mode 100644 index 5080c50756..0000000000 --- a/EmbeddedPkg/Library/AcpiLib/AcpiLib.inf +++ /dev/null @@ -1,36 +0,0 @@ -#/** @file -# -# Copyright (c) 2014, ARM Ltd. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = AcpiLib - FILE_GUID = 24b9d62c-5a36-417b-94b6-38dbaea90dcf - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = AcpiLib - -[Sources.common] - AcpiLib.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - DebugLib - UefiBootServicesTableLib - -[Protocols] - gEfiAcpiTableProtocolGuid - gEfiFirmwareVolume2ProtocolGuid diff --git a/EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLib.c b/EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLib.c deleted file mode 100755 index bb1ea132cf..0000000000 --- a/EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLib.c +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - Null Debug Agent timer. - - The debug agent uses the timer so the debugger can break into running programs. - If you link against this library you will not be able to break into a running - program with the debugger. - - Copyright (c) 2008 - 2010, Apple Inc. 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. - -**/ - - -/** - Setup all the hardware needed for the debug agents timer. - - This function is used to set up debug enviroment. It may enable interrupts. - -**/ -VOID -EFIAPI -DebugAgentTimerIntialize ( - VOID - ) -{ -} - - -/** - Set the period for the debug agent timer. Zero means disable the timer. - - @param[in] TimerPeriodMilliseconds Frequency of the debug agent timer. - -**/ -VOID -EFIAPI -DebugAgentTimerSetPeriod ( - IN UINT32 TimerPeriodMilliseconds - ) -{ -} - - -/** - Perform End Of Interrupt for the debug agent timer. This is called in the - interrupt handler after the interrupt has been processed. - -**/ -VOID -EFIAPI -DebugAgentTimerEndOfInterrupt ( - VOID - ) -{ -} - diff --git a/EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf b/EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf deleted file mode 100755 index 010bed3ad3..0000000000 --- a/EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf +++ /dev/null @@ -1,37 +0,0 @@ -#/** @file -# Component description file for Base PCI Cf8 Library. -# -# PCI CF8 Library that uses I/O ports 0xCF8 and 0xCFC to perform PCI Configuration cycles. -# Layers on top of an I/O Library instance. -# Copyright (c) 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DebugAgentTimerLibNull - FILE_GUID = 02f04694-2c0a-4f1e-b0ce-64be25890b03 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = DebugAgentTimerLib|SEC BASE DXE_CORE - - -[Sources.common] - DebugAgentTimerLib.c - - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - IoLib - diff --git a/EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoff.c b/EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoff.c deleted file mode 100644 index bcc694816a..0000000000 --- a/EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoff.c +++ /dev/null @@ -1,288 +0,0 @@ -/** @file - PE/COFF Loader Library implementation that wraps a protocol passed up from - SEC/PEI via a HOB. This is done to save space. - - Copyright (c) 2010, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2010, Apple Inc. 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. - -**/ - -#include -#include -#include - -#include - - -PE_COFF_LOADER_PROTOCOL *gPeCoffLoader = NULL; - - -/** - Retrieves information about a PE/COFF image. - - Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, ImageSize, - DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and - DebugDirectoryEntryRva fields of the ImageContext structure. - If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. - If the PE/COFF image accessed through the ImageRead service in the ImageContext - structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED. - If any errors occur while computing the fields of ImageContext, - then the error status is returned in the ImageError field of ImageContext. - If the image is a TE image, then SectionAlignment is set to 0. - The ImageRead and Handle fields of ImageContext structure must be valid prior - to invoking this service. - - @param ImageContext Pointer to the image context structure that describes the PE/COFF - image that needs to be examined by this function. - - @retval RETURN_SUCCESS The information on the PE/COFF image was collected. - @retval RETURN_INVALID_PARAMETER ImageContext is NULL. - @retval RETURN_UNSUPPORTED The PE/COFF image is not supported. - -**/ -RETURN_STATUS -EFIAPI -PeCoffLoaderGetImageInfo ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - return gPeCoffLoader->GetImageInfo (ImageContext); -} - - -/** - Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage(). - - If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of - ImageContext as the relocation base address. Otherwise, use the DestinationAddress field - of ImageContext as the relocation base address. The caller must allocate the relocation - fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. - - The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress, - ImageSize, DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, - DebugDirectoryEntryRva, EntryPoint, FixupDataSize, CodeView, PdbPointer, and FixupData of - the ImageContext structure must be valid prior to invoking this service. - - If ImageContext is NULL, then ASSERT(). - - Note that if the platform does not maintain coherency between the instruction cache(s) and the data - cache(s) in hardware, then the caller is responsible for performing cache maintenance operations - prior to transferring control to a PE/COFF image that is loaded using this library. - - @param ImageContext Pointer to the image context structure that describes the PE/COFF - image that is being relocated. - - @retval RETURN_SUCCESS The PE/COFF image was relocated. - Extended status information is in the ImageError field of ImageContext. - @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image. - Extended status information is in the ImageError field of ImageContext. - @retval RETURN_UNSUPPORTED A relocation record type is not supported. - Extended status information is in the ImageError field of ImageContext. - -**/ -RETURN_STATUS -EFIAPI -PeCoffLoaderRelocateImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - return gPeCoffLoader->RelocateImage (ImageContext); -} - -/** - Loads a PE/COFF image into memory. - - Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer - specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate - the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function. - The EntryPoint, FixupDataSize, CodeView, PdbPointer and HiiResourceData fields of ImageContext are computed. - The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress, ImageSize, - DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva - fields of the ImageContext structure must be valid prior to invoking this service. - - If ImageContext is NULL, then ASSERT(). - - Note that if the platform does not maintain coherency between the instruction cache(s) and the data - cache(s) in hardware, then the caller is responsible for performing cache maintenance operations - prior to transferring control to a PE/COFF image that is loaded using this library. - - @param ImageContext Pointer to the image context structure that describes the PE/COFF - image that is being loaded. - - @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by - the ImageAddress and ImageSize fields of ImageContext. - Extended status information is in the ImageError field of ImageContext. - @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer. - Extended status information is in the ImageError field of ImageContext. - @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations. - Extended status information is in the ImageError field of ImageContext. - @retval RETURN_INVALID_PARAMETER The image address is invalid. - Extended status information is in the ImageError field of ImageContext. - -**/ -RETURN_STATUS -EFIAPI -PeCoffLoaderLoadImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - return gPeCoffLoader->LoadImage (ImageContext); -} - - - -/** - Reads contents of a PE/COFF image from a buffer in system memory. - - This is the default implementation of a PE_COFF_LOADER_READ_FILE function - that assumes FileHandle pointer to the beginning of a PE/COFF image. - This function reads contents of the PE/COFF image that starts at the system memory - address specified by FileHandle. The read operation copies ReadSize bytes from the - PE/COFF image starting at byte offset FileOffset into the buffer specified by Buffer. - The size of the buffer actually read is returned in ReadSize. - - If FileHandle is NULL, then ASSERT(). - If ReadSize is NULL, then ASSERT(). - If Buffer is NULL, then ASSERT(). - - @param FileHandle Pointer to base of the input stream - @param FileOffset Offset into the PE/COFF image to begin the read operation. - @param ReadSize On input, the size in bytes of the requested read operation. - On output, the number of bytes actually read. - @param Buffer Output buffer that contains the data read from the PE/COFF image. - - @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into - the buffer. -**/ -RETURN_STATUS -EFIAPI -PeCoffLoaderImageReadFromMemory ( - IN VOID *FileHandle, - IN UINTN FileOffset, - IN OUT UINTN *ReadSize, - OUT VOID *Buffer - ) -{ - return gPeCoffLoader->ReadFromMemory ( - FileHandle, - FileOffset, - ReadSize, - Buffer - ); - -} - - - -/** - Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI - runtime. - - This function reapplies relocation fixups to the PE/COFF image specified by ImageBase - and ImageSize so the image will execute correctly when the PE/COFF image is mapped - to the address specified by VirtualImageBase. RelocationData must be identical - to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure - after this PE/COFF image was relocated with PeCoffLoaderRelocateImage(). - - Note that if the platform does not maintain coherency between the instruction cache(s) and the data - cache(s) in hardware, then the caller is responsible for performing cache maintenance operations - prior to transferring control to a PE/COFF image that is loaded using this library. - - @param ImageBase Base address of a PE/COFF image that has been loaded - and relocated into system memory. - @param VirtImageBase The request virtual address that the PE/COFF image is to - be fixed up for. - @param ImageSize The size, in bytes, of the PE/COFF image. - @param RelocationData A pointer to the relocation data that was collected when the PE/COFF - image was relocated using PeCoffLoaderRelocateImage(). - -**/ -VOID -EFIAPI -PeCoffLoaderRelocateImageForRuntime ( - IN PHYSICAL_ADDRESS ImageBase, - IN PHYSICAL_ADDRESS VirtImageBase, - IN UINTN ImageSize, - IN VOID *RelocationData - ) -{ - return gPeCoffLoader->RelocateImageForRuntime ( - ImageBase, - VirtImageBase, - ImageSize, - RelocationData - ); -} - - -/** - Unloads a loaded PE/COFF image from memory and releases its taken resource. - Releases any environment specific resources that were allocated when the image - specified by ImageContext was loaded using PeCoffLoaderLoadImage(). - - For NT32 emulator, the PE/COFF image loaded by system needs to release. - For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, - this function can simply return RETURN_SUCCESS. - - If ImageContext is NULL, then ASSERT(). - - @param ImageContext Pointer to the image context structure that describes the PE/COFF - image to be unloaded. - - @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully. -**/ -RETURN_STATUS -EFIAPI -PeCoffLoaderUnloadImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - return gPeCoffLoader->UnloadImage (ImageContext); -} - -typedef struct { - EFI_HOB_GUID_TYPE Hob; - VOID *Interface; -} PROTOCOL_HOB; - - -/** - The constructor function caches the pointer of DXE Services Table. - - The constructor function caches the pointer of DXE Services Table. - It will ASSERT() if that operation fails. - It will ASSERT() if the pointer of DXE Services Table is NULL. - It will always return EFI_SUCCESS. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -DxeHobPeCoffLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - PROTOCOL_HOB *Hob; - - Hob = GetFirstGuidHob (&gPeCoffLoaderProtocolGuid); - if (Hob == NULL) { - return EFI_NOT_FOUND; - } - - gPeCoffLoader = Hob->Interface; - return EFI_SUCCESS; -} - - diff --git a/EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf b/EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf deleted file mode 100644 index d6eb1cf0cf..0000000000 --- a/EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf +++ /dev/null @@ -1,44 +0,0 @@ -#/** @file -# PE/COFF Loader Library implementation that wraps a protocol passed up from -# SEC/PEI via a HOB. This is done to save space. -# -# Copyright (c) 2010, Intel Corporation. All rights reserved.
-# Portions copyright (c) 2008 - 2010, Apple Inc. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DxeHobPeCoffLib - FILE_GUID = 671C6FD7-99FB-4EE3-B640-4B1D463BC3B5 - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = PeCoffLib - CONSTRUCTOR = DxeHobPeCoffLibConstructor - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM -# - -[Sources.common] - DxeHobPeCoff.c - - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - DebugLib - HobLib - -[Protocols] - gPeCoffLoaderProtocolGuid diff --git a/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c b/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c deleted file mode 100644 index 3b9f1846d3..0000000000 --- a/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c +++ /dev/null @@ -1,155 +0,0 @@ -/** @file - Add external EblCmd Lib - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. 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. - - -**/ - -#include -#include -#include -#include -#include - -STATIC BOOLEAN gInstalledCommand = FALSE; -STATIC EFI_EVENT mEblCommandRegistration = NULL; - -STATIC const EBL_COMMAND_TABLE *mAddExternalCmdLibTemplate = NULL; -STATIC UINTN mAddExternalCmdLibTemplateSize = 0; -EBL_ADD_COMMAND_PROTOCOL *gEblExternalCommand = NULL; - - -/** - Return a keypress or optionally timeout if a timeout value was passed in. - An optional callback function is called every second when waiting for a - timeout. - - @param Key EFI Key information returned - @param TimeoutInSec Number of seconds to wait to timeout - @param CallBack Callback called every second during the timeout wait - - @return EFI_SUCCESS Key was returned - @return EFI_TIMEOUT If the TimoutInSec expired - -**/ -EFI_STATUS -EFIAPI -EblGetCharKey ( - IN OUT EFI_INPUT_KEY *Key, - IN UINTN TimeoutInSec, - IN EBL_GET_CHAR_CALL_BACK CallBack OPTIONAL - ) -{ - if (gEblExternalCommand != NULL) { - return gEblExternalCommand->EblGetCharKey (Key, TimeoutInSec, CallBack); - } - return EFI_TIMEOUT; -} - - -/** - This routine is used prevent command output data from scrolling off the end - of the screen. The global gPageBreak is used to turn on or off this feature. - If the CurrentRow is near the end of the screen pause and print out a prompt - If the use hits Q to quit return TRUE else for any other key return FALSE. - PrefixNewline is used to figure out if a newline is needed before the prompt - string. This depends on the last print done before calling this function. - CurrentRow is updated by one on a call or set back to zero if a prompt is - needed. - - @param CurrentRow Used to figure out if its the end of the page and updated - @param PrefixNewline Did previous print issue a newline - - @return TRUE if Q was hit to quit, FALSE in all other cases. - -**/ -BOOLEAN -EFIAPI -EblAnyKeyToContinueQtoQuit ( - IN UINTN *CurrentRow, - IN BOOLEAN PrefixNewline - ) -{ - if (gEblExternalCommand != NULL) { - return gEblExternalCommand->EblAnyKeyToContinueQtoQuit (CurrentRow, PrefixNewline); - } - return FALSE; -} - - - -/** - Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is - reinstalled. - - @param Event The Event that is being processed - @param Context Event Context - -**/ -VOID -EFIAPI -EblAddCommandNotificationEvent ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - EFI_STATUS Status; - - if (!gInstalledCommand) { - Status = gBS->LocateProtocol (&gEfiEblAddCommandProtocolGuid, NULL, (VOID **)&gEblExternalCommand); - if (!EFI_ERROR (Status)) { - gEblExternalCommand->AddCommands (mAddExternalCmdLibTemplate, mAddExternalCmdLibTemplateSize); - gInstalledCommand = TRUE; - } - } -} - - - -/** - The user Entry Point for the driver. The user code starts with this function - as the real entry point for the image goes into a library that calls this - function. - - @param[in] ImageHandle The firmware allocated handle for the EFI image. - @param[in] SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The entry point is executed successfully. - @retval other Some error occurs when executing this entry point. - -**/ -EFI_STATUS -EFIAPI -EblAddExternalCommands ( - IN const EBL_COMMAND_TABLE *EntryArray, - IN UINTN ArrayCount - ) -{ - if (mAddExternalCmdLibTemplate != NULL) { - return EFI_ALREADY_STARTED; - } - - mAddExternalCmdLibTemplate = EntryArray; - mAddExternalCmdLibTemplateSize = ArrayCount; - - EfiCreateProtocolNotifyEvent ( - &gEfiEblAddCommandProtocolGuid, - TPL_CALLBACK, - EblAddCommandNotificationEvent, - NULL, - &mEblCommandRegistration - ); - - return EFI_SUCCESS; -} - diff --git a/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf b/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf deleted file mode 100644 index 335386a8c8..0000000000 --- a/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf +++ /dev/null @@ -1,47 +0,0 @@ -#/** @file -# Component description file for the entry point to a EFIDXE Drivers -# -# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification -# Copyright (c) 2007 - 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = EblAddExternalCommandLib - FILE_GUID = 9195D970-C6F7-484E-8013-5B03C89C3B81 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = EblAddExternalCommandLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER - - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - EblAddExternalCommandLib.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - UefiBootServicesTableLib - UefiLib - EblAddExternalCommandLib - -[Protocols] - gEfiEblAddCommandProtocolGuid - -[Guids] diff --git a/EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.c b/EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.c deleted file mode 100644 index 6cde5f95ab..0000000000 --- a/EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.c +++ /dev/null @@ -1,28 +0,0 @@ -/** @file - Null EblCmdLib - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. 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. - - -**/ - -#include -#include - - -VOID -EblInitializeExternalCmd ( - VOID - ) -{ - return; -} diff --git a/EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf b/EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf deleted file mode 100644 index c7935ae37e..0000000000 --- a/EmbeddedPkg/Library/EblCmdLibNull/EblCmdLibNull.inf +++ /dev/null @@ -1,43 +0,0 @@ -#/** @file -# Component description file for the entry point to a EFIDXE Drivers -# -# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification -# Copyright (c) 2007 - 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = EblCmdLibNull - FILE_GUID = 3513C4E2-06D6-4921-9C2B-E938777BA79E - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = EfiCmdLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER - - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - EblCmdLibNull.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - -[Protocols] - -[Guids] diff --git a/EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.c b/EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.c deleted file mode 100644 index 1c945cd33b..0000000000 --- a/EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.c +++ /dev/null @@ -1,173 +0,0 @@ -/** @file - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include -#include -#include -#include - -#include -#include - - -BOOLEAN gUseIpv6 = FALSE; - -EFI_STATUS -EFIAPI -EblGetCurrentIpAddress ( - IN OUT EFI_IP_ADDRESS *Ip - ) -{ - EFI_STATUS Status; - EFI_PXE_BASE_CODE_PROTOCOL *Pxe; - - Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); - if (EFI_ERROR(Status)) { - return Status; - } - - Status = Pxe->Start (Pxe, gUseIpv6); - if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { - return Status; - } - - CopyMem (Ip, &Pxe->Mode->StationIp, sizeof (EFI_IP_ADDRESS)); - - return EFI_SUCCESS; -} - - -EFI_STATUS -EFIAPI -EblGetCurrentMacAddress ( - IN OUT EFI_MAC_ADDRESS *Mac - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNet; - - Status = gBS->LocateProtocol (&gEfiSimpleNetworkProtocolGuid, NULL, (VOID **)&SimpleNet); - if (EFI_ERROR(Status)) { - return Status; - } - - CopyMem (Mac, SimpleNet->Mode->CurrentAddress.Addr, sizeof (EFI_MAC_ADDRESS)); - return Status; -} - - -CHAR8 * -EFIAPI -EblLoadFileBootTypeString ( - IN EFI_HANDLE Handle - ) -{ - EFI_STATUS Status; - VOID *NullPtr; - - Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, &NullPtr); - if (!EFI_ERROR (Status)) { - return "EFI PXE Network Boot"; - } - - return ""; -} - -EFI_STATUS -EFIAPI -EblPerformDHCP ( - IN BOOLEAN SortOffers - ) -{ - EFI_STATUS Status; - EFI_PXE_BASE_CODE_PROTOCOL *Pxe; - - Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); - if (EFI_ERROR(Status)) { - return Status; - } - - Status = Pxe->Start (Pxe, gUseIpv6); - if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { - return Status; - } - - Status = Pxe->Dhcp(Pxe, TRUE); - return Status; -} - - -EFI_STATUS -EFIAPI -EblSetStationIp ( - IN EFI_IP_ADDRESS *NewStationIp, OPTIONAL - IN EFI_IP_ADDRESS *NewSubnetMask OPTIONAL - ) -{ - EFI_STATUS Status; - EFI_PXE_BASE_CODE_PROTOCOL *Pxe; - - Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); - if (EFI_ERROR(Status)) { - return Status; - } - - Status = Pxe->Start (Pxe, gUseIpv6); - if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { - return Status; - } - - Status = Pxe->SetStationIp (Pxe, NewStationIp, NewSubnetMask); - return Status; -} - - -EFI_STATUS -EFIAPI -EblMtftp ( - IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation, - IN OUT VOID *BufferPtr OPTIONAL, - IN BOOLEAN Overwrite, - IN OUT UINT64 *BufferSize, - IN UINTN *BlockSize OPTIONAL, - IN EFI_IP_ADDRESS *ServerIp, - IN UINT8 *Filename OPTIONAL, - IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL, - IN BOOLEAN DontUseBuffer - ) -{ - EFI_STATUS Status; - EFI_PXE_BASE_CODE_PROTOCOL *Pxe; - - Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); - if (EFI_ERROR(Status)) { - return Status; - } - - Status = Pxe->Mtftp ( - Pxe, - Operation, - BufferPtr, - Overwrite, - BufferSize, - BlockSize, - ServerIp, - Filename, - Info, - DontUseBuffer - ); - return Status; -} - diff --git a/EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf b/EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf deleted file mode 100644 index c9b2d31dc4..0000000000 --- a/EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf +++ /dev/null @@ -1,34 +0,0 @@ -#/** @file -# -# Copyright (c) 2008 - 2010, Apple Inc. 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. -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = EblNetworkLib - FILE_GUID = D885869A-7869-47DB-9429-DE03C318BCFD - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = EblNetworkLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER - -[sources.common] - EblNetworkLib.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[Protocols] - gEfiSimpleNetworkProtocolGuid - gEfiPxeBaseCodeProtocolGuid - -[Depex] - TRUE diff --git a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c deleted file mode 100644 index 4d58c83086..0000000000 --- a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c +++ /dev/null @@ -1,1779 +0,0 @@ -/** @file -File IO routines inspired by Streams with an EFI flavor - -Copyright (c) 2007, Intel Corporation. All rights reserved.
-Portions copyright (c) 2008 - 2009, Apple Inc. 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. - -Basic support for opening files on different device types. The device string -is in the form of DevType:Path. Current DevType is required as there is no -current mounted device concept of current working directory concept implement -by this library. - -Device names are case insensitive and only check the leading characters for -unique matches. Thus the following are all the same: -LoadFile0: -l0: -L0: -Lo0: - -Supported Device Names: -A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes -l1: - EFI LoadFile device one. -B0: - EFI BlockIo zero. -fs3: - EFI Simple File System device 3 -Fv2: - EFI Firmware VOlume device 2 -10.0.1.102: - TFTP service IP followed by the file name -**/ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -CHAR8 *gCwd = NULL; - -#define EFI_OPEN_FILE_GUARD_HEADER 0x4B4D4641 -#define EFI_OPEN_FILE_GUARD_FOOTER 0x444D5A56 - -// Need to defend against this overflowing -#define MAX_CMD_LINE 0x200 - -typedef struct { - UINT32 Header; - EFI_OPEN_FILE File; - UINT32 Footer; -} EFI_OPEN_FILE_GUARD; - - -// globals to store current open device info -EFI_HANDLE *mBlkIo = NULL; -UINTN mBlkIoCount = 0; - -EFI_HANDLE *mFs = NULL; -UINTN mFsCount = 0; -// mFsInfo[] array entries must match mFs[] handles -EFI_FILE_SYSTEM_INFO **mFsInfo = NULL; - -EFI_HANDLE *mFv = NULL; -UINTN mFvCount = 0; -EFI_HANDLE *mLoadFile = NULL; -UINTN mLoadFileCount = 0; - - - -/** -Internal worker function to validate a File handle. - -@param File Open File Handle - -@return TRUE File is valid -@return FALSE File is not valid - - -**/ -BOOLEAN -FileHandleValid ( - IN EFI_OPEN_FILE *File - ) -{ - EFI_OPEN_FILE_GUARD *GuardFile; - - // Look right before and after file structure for the correct signatures - GuardFile = BASE_CR (File, EFI_OPEN_FILE_GUARD, File); - if ((GuardFile->Header != EFI_OPEN_FILE_GUARD_HEADER) || - (GuardFile->Footer != EFI_OPEN_FILE_GUARD_FOOTER) ) { - return FALSE; - } - - return TRUE; -} - -/** -Internal worker function. If Buffer is not NULL free it. - -@param Buffer Buffer to FreePool() - -**/ -VOID -EblFreePool ( - IN VOID *Buffer - ) -{ - if (Buffer != NULL) { - FreePool (Buffer); - } -} - -/** -Update Device List Global Variables - -**/ -VOID -EblUpdateDeviceLists ( - VOID - ) -{ - EFI_STATUS Status; - UINTN Size; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs; - EFI_FILE_HANDLE Root; - UINTN Index; - - if (mBlkIo != NULL) { - FreePool (mBlkIo); - } - gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo); - - - - if (mFv != NULL) { - FreePool (mFv); - } - gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &mFvCount, &mFv); - - if (mLoadFile != NULL) { - FreePool (mLoadFile); - } - gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &mLoadFileCount, &mLoadFile); - - if (mFs != NULL) { - FreePool (mFs); - } - - if (&mFsInfo[0] != NULL) { - // Need to Free the mFsInfo prior to recalculating mFsCount so don't move this code - for (Index = 0; Index < mFsCount; Index++) { - if (mFsInfo[Index] != NULL) { - FreePool (mFsInfo[Index]); - } - } - FreePool (mFsInfo); - } - - gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &mFsCount, &mFs); - - - mFsInfo = AllocateZeroPool (mFsCount * sizeof (EFI_FILE_SYSTEM_INFO *)); - if (mFsInfo == NULL) { - // If we can't do this then we can't support file system entries - mFsCount = 0; - } else { - // Loop through all the file system structures and cache the file system info data - for (Index =0; Index < mFsCount; Index++) { - Status = gBS->HandleProtocol (mFs[Index], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs); - if (!EFI_ERROR (Status)) { - Status = Fs->OpenVolume (Fs, &Root); - if (!EFI_ERROR (Status)) { - // Get information about the volume - Size = 0; - Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]); - if (Status == EFI_BUFFER_TOO_SMALL) { - mFsInfo[Index] = AllocatePool (Size); - Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]); - } - - Root->Close (Root); - } - } - } - } -} - - -/** -PathName is in the form : for example fs1:\ or ROOT:\. -Return TRUE if the prefix of PathName matches a file system -Volume Name. MatchIndex is the array index in mFsInfo[] of the match, -and it can be used with mFs[] to find the handle that needs to be opened - -@param PathName PathName to check -@param FileStart Index of the first character of the -@param MatchIndex Index in mFsInfo[] that matches - -@return TRUE PathName matches a Volume Label and MatchIndex is valid -@return FALSE PathName does not match a Volume Label MatchIndex undefined - -**/ -BOOLEAN -EblMatchVolumeName ( - IN CHAR8 *PathName, - IN UINTN FileStart, - OUT UINTN *MatchIndex - ) -{ - UINTN Index; - UINTN Compare; - UINTN VolStrLen; - BOOLEAN Match; - - for (Index =0; Index < mFsCount; Index++) { - if (mFsInfo[Index] == NULL) { - // FsInfo is not valid so skip it - continue; - } - VolStrLen = StrLen (mFsInfo[Index]->VolumeLabel); - for (Compare = 0, Match = TRUE; Compare < (FileStart - 1); Compare++) { - if (Compare > VolStrLen) { - Match = FALSE; - break; - } - if (PathName[Compare] != (CHAR8)mFsInfo[Index]->VolumeLabel[Compare]) { - // If the VolumeLabel has a space allow a _ to match with it in addition to ' ' - if (!((PathName[Compare] == '_') && (mFsInfo[Index]->VolumeLabel[Compare] == L' '))) { - Match = FALSE; - break; - } - } - } - if (Match) { - *MatchIndex = Index; - return TRUE; - } - } - - return FALSE; -} - - -/** -Return the number of devices of the current type active in the system - -@param Type Device type to check - -@return 0 Invalid type - -**/ -UINTN -EfiGetDeviceCounts ( - IN EFI_OPEN_FILE_TYPE DeviceType - ) -{ - switch (DeviceType) { - case EfiOpenLoadFile: - return mLoadFileCount; - case EfiOpenFirmwareVolume: - return mFvCount; - case EfiOpenFileSystem: - return mFsCount; - case EfiOpenBlockIo: - return mBlkIoCount; - default: - return 0; - } -} - -EFI_STATUS -ConvertIpStringToEfiIp ( - IN CHAR8 *PathName, - OUT EFI_IP_ADDRESS *ServerIp - ) -{ - CHAR8 *Str; - - Str = PathName; - ServerIp->v4.Addr[0] = (UINT8)AsciiStrDecimalToUintn (Str); - - Str = AsciiStrStr (Str, "."); - if (Str == NULL) { - return EFI_DEVICE_ERROR; - } - - ServerIp->v4.Addr[1] = (UINT8)AsciiStrDecimalToUintn (++Str); - - Str = AsciiStrStr (Str, "."); - if (Str == NULL) { - return EFI_DEVICE_ERROR; - } - - ServerIp->v4.Addr[2] = (UINT8)AsciiStrDecimalToUintn (++Str); - - Str = AsciiStrStr (Str, "."); - if (Str == NULL) { - return EFI_DEVICE_ERROR; - } - - ServerIp->v4.Addr[3] = (UINT8)AsciiStrDecimalToUintn (++Str); - - return EFI_SUCCESS; -} - - -/** -Internal work function to extract a device number from a string skipping -text. Easy way to extract numbers from strings like blk7:. - -@param Str String to extract device number form - -@return -1 Device string is not valid -@return Device # - -**/ -UINTN -EblConvertDevStringToNumber ( - IN CHAR8 *Str - ) -{ - UINTN Max; - UINTN Index; - - - // Find the first digit - Max = AsciiStrLen (Str); - for (Index = 0; !((*Str >= '0') && (*Str <= '9')) && (Index < Max); Index++) { - Str++; - } - if (Index == Max) { - return (UINTN)-1; - } - - return AsciiStrDecimalToUintn (Str); -} - - -/** -Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo - -@param File Open file handle -@param FileName Name of file after device stripped off - - -**/ -EFI_STATUS -EblFileDevicePath ( - IN OUT EFI_OPEN_FILE *File, - IN CHAR8 *FileName, - IN CONST UINT64 OpenMode - ) -{ - EFI_STATUS Status; - UINTN Size; - FILEPATH_DEVICE_PATH *FilePath; - EFI_DEVICE_PATH_PROTOCOL *FileDevicePath; - CHAR16 UnicodeFileName[MAX_PATHNAME]; - EFI_BLOCK_IO_PROTOCOL *BlkIo; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs; - EFI_FILE_HANDLE Root; - - - if ( *FileName != 0 ) { - AsciiStrToUnicodeStr (FileName, UnicodeFileName); - } else { - AsciiStrToUnicodeStr ("\\", UnicodeFileName); - } - - Size = StrSize (UnicodeFileName); - FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof (EFI_DEVICE_PATH_PROTOCOL)); - if (FileDevicePath != NULL) { - FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath; - FilePath->Header.Type = MEDIA_DEVICE_PATH; - FilePath->Header.SubType = MEDIA_FILEPATH_DP; - CopyMem (&FilePath->PathName, UnicodeFileName, Size); - SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH); - SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header)); - - if (File->EfiHandle != NULL) { - File->DevicePath = DevicePathFromHandle (File->EfiHandle); - } - - File->DevicePath = AppendDevicePath (File->DevicePath, FileDevicePath); - FreePool (FileDevicePath); - } - - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo); - if (!EFI_ERROR (Status)) { - File->FsBlockIoMedia = BlkIo->Media; - File->FsBlockIo = BlkIo; - - // If we are not opening the device this will get over written with file info - File->MaxPosition = MultU64x32 (BlkIo->Media->LastBlock + 1, BlkIo->Media->BlockSize); - } - - if (File->Type == EfiOpenFileSystem) { - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs); - if (!EFI_ERROR (Status)) { - Status = Fs->OpenVolume (Fs, &Root); - if (!EFI_ERROR (Status)) { - // Get information about the volume - Size = 0; - Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo); - if (Status == EFI_BUFFER_TOO_SMALL) { - File->FsInfo = AllocatePool (Size); - Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo); - } - - // Get information about the file - Status = Root->Open (Root, &File->FsFileHandle, UnicodeFileName, OpenMode, 0); - if (!EFI_ERROR (Status)) { - Size = 0; - Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, NULL); - if (Status == EFI_BUFFER_TOO_SMALL) { - File->FsFileInfo = AllocatePool (Size); - Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, File->FsFileInfo); - if (!EFI_ERROR (Status)) { - File->Size = (UINTN)File->FsFileInfo->FileSize; - File->MaxPosition = (UINT64)File->Size; - } - } - } - - Root->Close (Root); - } - } - } else if (File->Type == EfiOpenBlockIo) { - File->Size = (UINTN)File->MaxPosition; - } - - return Status; -} - -#define ToUpper(a) ((((a) >= 'a') && ((a) <= 'z')) ? ((a) - 'a' + 'A') : (a)) - -EFI_STATUS -CompareGuidToString ( - IN EFI_GUID *Guid, - IN CHAR8 *String - ) -{ - CHAR8 AsciiGuid[64]; - CHAR8 *StringPtr; - CHAR8 *GuidPtr; - - AsciiSPrint (AsciiGuid, sizeof(AsciiGuid), "%g", Guid); - - StringPtr = String; - GuidPtr = AsciiGuid; - - while ((*StringPtr != '\0') && (*GuidPtr != '\0')) { - // Skip dashes - if (*StringPtr == '-') { - StringPtr++; - continue; - } - - if (*GuidPtr == '-') { - GuidPtr++; - continue; - } - - if (ToUpper(*StringPtr) != ToUpper(*GuidPtr)) { - return EFI_NOT_FOUND; - } - - StringPtr++; - GuidPtr++; - } - - return EFI_SUCCESS; -} - - -/** -Internal work function to fill in EFI_OPEN_FILE information for the FV - -@param File Open file handle -@param FileName Name of file after device stripped off - - -**/ -EFI_STATUS -EblFvFileDevicePath ( - IN OUT EFI_OPEN_FILE *File, - IN CHAR8 *FileName, - IN CONST UINT64 OpenMode - ) -{ - EFI_STATUS Status; - EFI_STATUS GetNextFileStatus; - MEDIA_FW_VOL_FILEPATH_DEVICE_PATH DevicePathNode; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINTN Key; - UINT32 AuthenticationStatus; - CHAR8 AsciiSection[MAX_PATHNAME]; - VOID *Section; - UINTN SectionSize; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_LBA Lba; - UINTN BlockSize; - UINTN NumberOfBlocks; - EFI_FIRMWARE_VOLUME_HEADER *FvHeader = NULL; - UINTN Index; - - - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&File->Fv); - if (EFI_ERROR (Status)) { - return Status; - } - - // Get FVB Info about the handle - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb); - if (!EFI_ERROR (Status)) { - Status = Fvb->GetPhysicalAddress (Fvb, &File->FvStart); - if (!EFI_ERROR (Status)) { - FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)File->FvStart; - File->FvHeaderSize = sizeof (EFI_FIRMWARE_VOLUME_HEADER); - for (Index = 0; FvHeader->BlockMap[Index].Length !=0; Index++) { - File->FvHeaderSize += sizeof (EFI_FV_BLOCK_MAP_ENTRY); - } - - for (Lba = 0, File->FvSize = 0, NumberOfBlocks = 0; ; File->FvSize += (BlockSize * NumberOfBlocks), Lba += NumberOfBlocks) { - Status = Fvb->GetBlockSize (Fvb, Lba, &BlockSize, &NumberOfBlocks); - if (EFI_ERROR (Status)) { - break; - } - } - } - } - - - DevicePath = DevicePathFromHandle (File->EfiHandle); - - if (*FileName == '\0') { - File->DevicePath = DuplicateDevicePath (DevicePath); - File->Size = File->FvSize; - File->MaxPosition = File->Size; - } else { - Key = 0; - do { - File->FvType = EFI_FV_FILETYPE_ALL; - GetNextFileStatus = File->Fv->GetNextFile ( - File->Fv, - &Key, - &File->FvType, - &File->FvNameGuid, - &File->FvAttributes, - &File->Size - ); - if (!EFI_ERROR (GetNextFileStatus)) { - // Compare GUID first - Status = CompareGuidToString (&File->FvNameGuid, FileName); - if (!EFI_ERROR(Status)) { - break; - } - - Section = NULL; - Status = File->Fv->ReadSection ( - File->Fv, - &File->FvNameGuid, - EFI_SECTION_USER_INTERFACE, - 0, - &Section, - &SectionSize, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - UnicodeStrToAsciiStr (Section, AsciiSection); - if (AsciiStriCmp (FileName, AsciiSection) == 0) { - FreePool (Section); - break; - } - FreePool (Section); - } - } - } while (!EFI_ERROR (GetNextFileStatus)); - - if (EFI_ERROR (GetNextFileStatus)) { - return GetNextFileStatus; - } - - if (OpenMode != EFI_SECTION_ALL) { - // Calculate the size of the section we are targeting - Section = NULL; - File->Size = 0; - Status = File->Fv->ReadSection ( - File->Fv, - &File->FvNameGuid, - (EFI_SECTION_TYPE)OpenMode, - 0, - &Section, - &File->Size, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - - File->MaxPosition = File->Size; - EfiInitializeFwVolDevicepathNode (&DevicePathNode, &File->FvNameGuid); - File->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&DevicePathNode); - } - - - // FVB not required if FV was soft loaded... - return EFI_SUCCESS; -} - - - - -/** -Open a device named by PathName. The PathName includes a device name and -path separated by a :. See file header for more details on the PathName -syntax. There is no checking to prevent a file from being opened more than -one type. - -SectionType is only used to open an FV. Each file in an FV contains multiple -sections and only the SectionType section is opened. - -For any file that is opened with EfiOpen() must be closed with EfiClose(). - -@param PathName Path to parse to open -@param OpenMode Same as EFI_FILE.Open() -@param SectionType Section in FV to open. - -@return NULL Open failed -@return Valid EFI_OPEN_FILE handle - -**/ -EFI_OPEN_FILE * -EfiOpen ( - IN CHAR8 *PathName, - IN CONST UINT64 OpenMode, - IN CONST EFI_SECTION_TYPE SectionType - ) -{ - EFI_STATUS Status; - EFI_OPEN_FILE *File; - EFI_OPEN_FILE FileData; - UINTN StrLen; - UINTN FileStart; - UINTN DevNumber = 0; - EFI_OPEN_FILE_GUARD *GuardFile; - BOOLEAN VolumeNameMatch; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINTN Size; - EFI_IP_ADDRESS Ip; - CHAR8 *CwdPlusPathName; - UINTN Index; - EFI_SECTION_TYPE ModifiedSectionType; - - EblUpdateDeviceLists (); - - File = &FileData; - ZeroMem (File, sizeof (EFI_OPEN_FILE)); - - StrLen = AsciiStrSize (PathName); - if (StrLen <= 1) { - // Smallest valid path is 1 char and a null - return NULL; - } - - for (FileStart = 0; FileStart < StrLen; FileStart++) { - if (PathName[FileStart] == ':') { - FileStart++; - break; - } - } - - // - // Matching volume name has precedence over handle based names - // - VolumeNameMatch = EblMatchVolumeName (PathName, FileStart, &DevNumber); - if (!VolumeNameMatch) { - if (FileStart == StrLen) { - // No Volume name or device name, so try Current Working Directory - if (gCwd == NULL) { - // No CWD - return NULL; - } - - // We could add a current working directory concept - CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName)); - if (CwdPlusPathName == NULL) { - return NULL; - } - - if ((PathName[0] == '/') || (PathName[0] == '\\')) { - // PathName starts in / so this means we go to the root of the device in the CWD. - CwdPlusPathName[0] = '\0'; - for (FileStart = 0; gCwd[FileStart] != '\0'; FileStart++) { - CwdPlusPathName[FileStart] = gCwd[FileStart]; - if (gCwd[FileStart] == ':') { - FileStart++; - CwdPlusPathName[FileStart] = '\0'; - break; - } - } - } else { - AsciiStrCpy (CwdPlusPathName, gCwd); - StrLen = AsciiStrLen (gCwd); - if ((*PathName != '/') && (*PathName != '\\') && (gCwd[StrLen-1] != '/') && (gCwd[StrLen-1] != '\\')) { - AsciiStrCat (CwdPlusPathName, "\\"); - } - } - - AsciiStrCat (CwdPlusPathName, PathName); - if (AsciiStrStr (CwdPlusPathName, ":") == NULL) { - // Extra error check to make sure we don't recurse and blow stack - return NULL; - } - - File = EfiOpen (CwdPlusPathName, OpenMode, SectionType); - FreePool (CwdPlusPathName); - return File; - } - - DevNumber = EblConvertDevStringToNumber ((CHAR8 *)PathName); - } - - File->DeviceName = AllocatePool (StrLen); - AsciiStrCpy (File->DeviceName, PathName); - File->DeviceName[FileStart - 1] = '\0'; - File->FileName = &File->DeviceName[FileStart]; - if (File->FileName[0] == '\0') { - // if it is just a file name use / as root - File->FileName = "\\"; - } - - // - // Use best match algorithm on the dev names so we only need to look at the - // first few charters to match the full device name. Short name forms are - // legal from the caller. - // - Status = EFI_SUCCESS; - if (*PathName == 'f' || *PathName == 'F' || VolumeNameMatch) { - if (PathName[1] == 's' || PathName[1] == 'S' || VolumeNameMatch) { - if (DevNumber >= mFsCount) { - goto ErrorExit; - } - File->Type = EfiOpenFileSystem; - File->EfiHandle = mFs[DevNumber]; - Status = EblFileDevicePath (File, &PathName[FileStart], OpenMode); - - } else if (PathName[1] == 'v' || PathName[1] == 'V') { - if (DevNumber >= mFvCount) { - goto ErrorExit; - } - File->Type = EfiOpenFirmwareVolume; - File->EfiHandle = mFv[DevNumber]; - - if ((PathName[FileStart] == '/') || (PathName[FileStart] == '\\')) { - // Skip leading / as its not really needed for the FV since no directories are supported - FileStart++; - } - - // Check for 2nd : - ModifiedSectionType = SectionType; - for (Index = FileStart; PathName[Index] != '\0'; Index++) { - if (PathName[Index] == ':') { - // Support fv0:\DxeCore:0x10 - // This means open the PE32 Section of the file - ModifiedSectionType = (EFI_SECTION_TYPE)AsciiStrHexToUintn (&PathName[Index + 1]); - PathName[Index] = '\0'; - } - } - File->FvSectionType = ModifiedSectionType; - Status = EblFvFileDevicePath (File, &PathName[FileStart], ModifiedSectionType); - } - } else if ((*PathName == 'A') || (*PathName == 'a')) { - // Handle a:0x10000000:0x1234 address form a:ADDRESS:SIZE - File->Type = EfiOpenMemoryBuffer; - // 1st colon is at PathName[FileStart - 1] - File->Buffer = (VOID *)AsciiStrHexToUintn (&PathName[FileStart]); - - // Find 2nd colon - while ((PathName[FileStart] != ':') && (PathName[FileStart] != '\0')) { - FileStart++; - } - - // If we ran out of string, there's no extra data - if (PathName[FileStart] == '\0') { - File->Size = 0; - } else { - File->Size = AsciiStrHexToUintn (&PathName[FileStart + 1]); - } - - // if there's no number after the second colon, default - // the end of memory - if (File->Size == 0) { - File->Size = (UINTN)(0 - (UINTN)File->Buffer); - } - - File->MaxPosition = File->Size; - File->BaseOffset = (UINTN)File->Buffer; - - } else if (*PathName== 'l' || *PathName == 'L') { - if (DevNumber >= mLoadFileCount) { - goto ErrorExit; - } - File->Type = EfiOpenLoadFile; - File->EfiHandle = mLoadFile[DevNumber]; - - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiLoadFileProtocolGuid, (VOID **)&File->LoadFile); - if (EFI_ERROR (Status)) { - goto ErrorExit; - } - - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath); - if (EFI_ERROR (Status)) { - goto ErrorExit; - } - File->DevicePath = DuplicateDevicePath (DevicePath); - - } else if (*PathName == 'b' || *PathName == 'B') { - // Handle b#:0x10000000:0x1234 address form b#:ADDRESS:SIZE - if (DevNumber >= mBlkIoCount) { - goto ErrorExit; - } - File->Type = EfiOpenBlockIo; - File->EfiHandle = mBlkIo[DevNumber]; - EblFileDevicePath (File, "", OpenMode); - - // 1st colon is at PathName[FileStart - 1] - File->DiskOffset = AsciiStrHexToUintn (&PathName[FileStart]); - - // Find 2nd colon - while ((PathName[FileStart] != ':') && (PathName[FileStart] != '\0')) { - FileStart++; - } - - // If we ran out of string, there's no extra data - if (PathName[FileStart] == '\0') { - Size = 0; - } else { - Size = AsciiStrHexToUintn (&PathName[FileStart + 1]); - } - - // if a zero size is passed in (or the size is left out entirely), - // go to the end of the device. - if (Size == 0) { - File->Size = File->Size - File->DiskOffset; - } else { - File->Size = Size; - } - - File->MaxPosition = File->Size; - File->BaseOffset = File->DiskOffset; - } else if ((*PathName) >= '0' && (*PathName <= '9')) { - - // Get current IP address - Status = EblGetCurrentIpAddress (&Ip); - if (EFI_ERROR(Status)) { - AsciiPrint("Device IP Address is not configured.\n"); - goto ErrorExit; - } - - - // Parse X.X.X.X:Filename, only support IPv4 TFTP for now... - File->Type = EfiOpenTftp; - File->IsDirty = FALSE; - File->IsBufferValid = FALSE; - - Status = ConvertIpStringToEfiIp (PathName, &File->ServerIp); - } - - if (EFI_ERROR (Status)) { - goto ErrorExit; - } - - GuardFile = (EFI_OPEN_FILE_GUARD *)AllocateZeroPool (sizeof (EFI_OPEN_FILE_GUARD)); - if (GuardFile == NULL) { - goto ErrorExit; - } - - GuardFile->Header = EFI_OPEN_FILE_GUARD_HEADER; - CopyMem (&(GuardFile->File), &FileData, sizeof (EFI_OPEN_FILE)); - GuardFile->Footer = EFI_OPEN_FILE_GUARD_FOOTER; - - return &(GuardFile->File); - -ErrorExit: - FreePool (File->DeviceName); - return NULL; -} - -#define FILE_COPY_CHUNK 0x01000000 - -EFI_STATUS -EfiCopyFile ( - IN CHAR8 *DestinationFile, - IN CHAR8 *SourceFile - ) -{ - EFI_OPEN_FILE *Source = NULL; - EFI_OPEN_FILE *Destination = NULL; - EFI_STATUS Status = EFI_SUCCESS; - VOID *Buffer = NULL; - UINTN Size; - UINTN Offset; - UINTN Chunk = FILE_COPY_CHUNK; - - Source = EfiOpen (SourceFile, EFI_FILE_MODE_READ, 0); - if (Source == NULL) { - AsciiPrint("Source file open error.\n"); - Status = EFI_NOT_FOUND; - goto Exit; - } - - Destination = EfiOpen (DestinationFile, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); - if (Destination == NULL) { - AsciiPrint("Destination file open error.\n"); - Status = EFI_NOT_FOUND; - goto Exit; - } - - Buffer = AllocatePool(FILE_COPY_CHUNK); - if (Buffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Exit; - } - - Size = EfiTell(Source, NULL); - - for (Offset = 0; Offset + FILE_COPY_CHUNK <= Size; Offset += Chunk) { - Chunk = FILE_COPY_CHUNK; - - Status = EfiRead(Source, Buffer, &Chunk); - if (EFI_ERROR(Status)) { - AsciiPrint("Read file error %r\n", Status); - goto Exit; - } - - Status = EfiWrite(Destination, Buffer, &Chunk); - if (EFI_ERROR(Status)) { - AsciiPrint("Write file error %r\n", Status); - goto Exit; - } - } - - // Any left over? - if (Offset < Size) { - Chunk = Size - Offset; - - Status = EfiRead(Source, Buffer, &Chunk); - if (EFI_ERROR(Status)) { - AsciiPrint("Read file error\n"); - goto Exit; - } - - Status = EfiWrite(Destination, Buffer, &Chunk); - if (EFI_ERROR(Status)) { - AsciiPrint("Write file error\n"); - goto Exit; - } - } - -Exit: - if (Source != NULL) { - Status = EfiClose(Source); - if (EFI_ERROR(Status)) { - AsciiPrint("Source close error"); - } - } - - if (Destination != NULL) { - Status = EfiClose(Destination); - if (EFI_ERROR(Status)) { - AsciiPrint("Destination close error"); - } - } - - if (Buffer != NULL) { - FreePool(Buffer); - } - - return Status; -} - -/** -Use DeviceType and Index to form a valid PathName and try and open it. - -@param DeviceType Device type to open -@param Index Device Index to use. Zero relative. - -@return NULL Open failed -@return Valid EFI_OPEN_FILE handle - -**/ -EFI_OPEN_FILE * -EfiDeviceOpenByType ( - IN EFI_OPEN_FILE_TYPE DeviceType, - IN UINTN Index - ) -{ - CHAR8 *DevStr; - CHAR8 Path[MAX_CMD_LINE]; - - switch (DeviceType) { - case EfiOpenLoadFile: - DevStr = "loadfile%d:"; - break; - case EfiOpenFirmwareVolume: - DevStr = "fv%d:"; - break; - case EfiOpenFileSystem: - DevStr = "fs%d:"; - break; - case EfiOpenBlockIo: - DevStr = "blk%d:"; - break; - case EfiOpenMemoryBuffer: - DevStr = "a%d:"; - break; - default: - return NULL; - } - - AsciiSPrint (Path, MAX_PATHNAME, DevStr, Index); - - return EfiOpen (Path, EFI_FILE_MODE_READ, 0); -} - - -/** -Close a file handle opened by EfiOpen() and free all resources allocated by -EfiOpen(). - -@param Stream Open File Handle - -@return EFI_INVALID_PARAMETER Stream is not an Open File -@return EFI_SUCCESS Steam closed - -**/ -EFI_STATUS -EfiClose ( - IN EFI_OPEN_FILE *File - ) -{ - EFI_STATUS Status; - UINT64 TftpBufferSize; - - if (!FileHandleValid (File)) { - return EFI_INVALID_PARAMETER; - } - - //Write the buffer contents to TFTP file. - if ((File->Type == EfiOpenTftp) && (File->IsDirty)) { - - TftpBufferSize = File->Size; - Status = EblMtftp ( - EFI_PXE_BASE_CODE_TFTP_WRITE_FILE, - File->Buffer, - TRUE, - &TftpBufferSize, - NULL, - &File->ServerIp, - (UINT8 *)File->FileName, - NULL, - FALSE - ); - if (EFI_ERROR(Status)) { - AsciiPrint("TFTP error during APPLE_NSP_TFTP_WRITE_FILE: %r\n", Status); - return Status; - } - } - - if ((File->Type == EfiOpenLoadFile) || - ((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) || - ((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) { - EblFreePool(File->Buffer); - } - - EblFreePool (File->DevicePath); - EblFreePool (File->DeviceName); - EblFreePool (File->FsFileInfo); - EblFreePool (File->FsInfo); - - if (File->FsFileHandle != NULL) { - File->FsFileHandle->Close (File->FsFileHandle); - } - - // Need to free File and it's Guard structures - EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File)); - return EFI_SUCCESS; -} - - -/** -Return the size of the file represented by Stream. Also return the current -Seek position. Opening a file will enable a valid file size to be returned. -LoadFile is an exception as a load file size is set to zero. - -@param Stream Open File Handle - -@return 0 Stream is not an Open File or a valid LoadFile handle - -**/ -UINTN -EfiTell ( - IN EFI_OPEN_FILE *File, - OUT EFI_LBA *CurrentPosition OPTIONAL - ) -{ - EFI_STATUS Status; - UINT64 BufferSize = 0; - - if (!FileHandleValid (File)) { - return 0; - } - - if (CurrentPosition != NULL) { - *CurrentPosition = File->CurrentPosition; - } - - if (File->Type == EfiOpenLoadFile) { - // Figure out the File->Size - File->Buffer = NULL; - File->Size = 0; - Status = File->LoadFile->LoadFile (File->LoadFile, File->DevicePath, FALSE, &File->Size, File->Buffer); - if (Status != EFI_BUFFER_TOO_SMALL) { - return 0; - } - - File->MaxPosition = (UINT64)File->Size; - } else if (File->Type == EfiOpenTftp) { - - Status = EblMtftp ( - EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, - NULL, - FALSE, - &BufferSize, - NULL, - &File->ServerIp, - (UINT8 *)File->FileName, - NULL, - TRUE - ); - if (EFI_ERROR(Status)) { - AsciiPrint("TFTP error during APPLE_NSP_TFTP_GET_FILE_SIZE: %r\n", Status); - return 0; - } - - File->Size = (UINTN)BufferSize; - File->MaxPosition = File->Size; - } - - return File->Size; -} - - -/** -Seek to the Offset location in the file. LoadFile and FV device types do -not support EfiSeek(). It is not possible to grow the file size using -EfiSeek(). - -SeekType defines how use Offset to calculate the new file position: -EfiSeekStart : Position = Offset -EfiSeekCurrent: Position is Offset bytes from the current position -EfiSeekEnd : Only supported if Offset is zero to seek to end of file. - -@param Stream Open File Handle -@param Offset Offset to seek too. -@param SeekType Type of seek to perform - - -@return EFI_INVALID_PARAMETER Stream is not an Open File -@return EFI_UNSUPPORTED LoadFile and FV do not support Seek -@return EFI_NOT_FOUND Seek past the end of the file. -@return EFI_SUCCESS Steam closed - -**/ -EFI_STATUS -EfiSeek ( - IN EFI_OPEN_FILE *File, - IN EFI_LBA Offset, - IN EFI_SEEK_TYPE SeekType - ) -{ - EFI_STATUS Status; - UINT64 CurrentPosition; - - if (!FileHandleValid (File)) { - return EFI_INVALID_PARAMETER; - } - - if (File->Type == EfiOpenLoadFile) { - // LoadFile does not support Seek - return EFI_UNSUPPORTED; - } - - CurrentPosition = File->CurrentPosition; - switch (SeekType) { - case EfiSeekStart: - if (Offset > File->MaxPosition) { - return EFI_NOT_FOUND; - } - CurrentPosition = Offset; - break; - - case EfiSeekCurrent: - if ((File->CurrentPosition + Offset) > File->MaxPosition) { - return EFI_NOT_FOUND; - } - CurrentPosition += Offset; - break; - - case EfiSeekEnd: - if (Offset != 0) { - // We don't support growing file size via seeking past end of file - return EFI_UNSUPPORTED; - } - CurrentPosition = File->MaxPosition; - break; - - default: - return EFI_NOT_FOUND; - } - - Status = EFI_SUCCESS; - if (File->FsFileHandle != NULL) { - Status = File->FsFileHandle->SetPosition (File->FsFileHandle, CurrentPosition); - } - - if (!EFI_ERROR (Status)) { - File->CurrentPosition = CurrentPosition; - } - - return Status; -} - -EFI_STATUS -CacheTftpFile ( - IN OUT EFI_OPEN_FILE *File - ) -{ - EFI_STATUS Status; - UINT64 TftpBufferSize; - - if (File->IsBufferValid) { - return EFI_SUCCESS; - } - - // Make sure the file size is set. - EfiTell (File, NULL); - - //Allocate a buffer to hold the whole file. - File->Buffer = AllocatePool(File->Size); - if (File->Buffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - TftpBufferSize = File->Size; - - Status = EblMtftp ( - EFI_PXE_BASE_CODE_TFTP_READ_FILE, - File->Buffer, - FALSE, - &TftpBufferSize, - NULL, - &File->ServerIp, - (UINT8 *)File->FileName, - NULL, - FALSE); - if (EFI_ERROR(Status)) { - AsciiPrint("TFTP error during APPLE_NSP_TFTP_READ_FILE: %r\n", Status); - FreePool(File->Buffer); - return Status; - } - - // Set the buffer valid flag. - File->IsBufferValid = TRUE; - - return Status; -} - -/** -Read BufferSize bytes from the current location in the file. For load file, -FV, and TFTP case you must read the entire file. - -@param Stream Open File Handle -@param Buffer Caller allocated buffer. -@param BufferSize Size of buffer in bytes. - - -@return EFI_SUCCESS Stream is not an Open File -@return EFI_END_OF_FILE Tried to read past the end of the file -@return EFI_INVALID_PARAMETER Stream is not an open file handle -@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read -@return "other" Error returned from device read - -**/ -EFI_STATUS -EfiRead ( - IN EFI_OPEN_FILE *File, - OUT VOID *Buffer, - OUT UINTN *BufferSize - ) -{ - EFI_STATUS Status; - UINT32 AuthenticationStatus; - EFI_DISK_IO_PROTOCOL *DiskIo; - - if (!FileHandleValid (File)) { - return EFI_INVALID_PARAMETER; - } - - // Don't read past the end of the file. - if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) { - return EFI_END_OF_FILE; - } - - switch (File->Type) { - case EfiOpenLoadFile: - // Figure out the File->Size - EfiTell (File, NULL); - - Status = File->LoadFile->LoadFile (File->LoadFile, File->DevicePath, FALSE, BufferSize, Buffer); - break; - - case EfiOpenFirmwareVolume: - if (CompareGuid (&File->FvNameGuid, &gZeroGuid)) { - // This is the entire FV device, so treat like a memory buffer - CopyMem (Buffer, (VOID *)(UINTN)(File->FvStart + File->CurrentPosition), *BufferSize); - File->CurrentPosition += *BufferSize; - Status = EFI_SUCCESS; - } else { - if (File->Buffer == NULL) { - if (File->FvSectionType == EFI_SECTION_ALL) { - Status = File->Fv->ReadFile ( - File->Fv, - &File->FvNameGuid, - (VOID **)&File->Buffer, - &File->Size, - &File->FvType, - &File->FvAttributes, - &AuthenticationStatus - ); - } else { - Status = File->Fv->ReadSection ( - File->Fv, - &File->FvNameGuid, - File->FvSectionType, - 0, - (VOID **)&File->Buffer, - &File->Size, - &AuthenticationStatus - ); - } - if (EFI_ERROR (Status)) { - return Status; - } - File->IsBufferValid = TRUE; - } - // Operate on the cached buffer so Seek will work - CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize); - File->CurrentPosition += *BufferSize; - Status = EFI_SUCCESS; - } - break; - - case EfiOpenMemoryBuffer: - CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize); - File->CurrentPosition += *BufferSize; - Status = EFI_SUCCESS; - break; - - case EfiOpenFileSystem: - Status = File->FsFileHandle->Read (File->FsFileHandle, BufferSize, Buffer); - File->CurrentPosition += *BufferSize; - break; - - case EfiOpenBlockIo: - Status = gBS->HandleProtocol(File->EfiHandle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo); - if (!EFI_ERROR(Status)) { - Status = DiskIo->ReadDisk(DiskIo, File->FsBlockIoMedia->MediaId, File->DiskOffset + File->CurrentPosition, *BufferSize, Buffer); - } - File->CurrentPosition += *BufferSize; - break; - - case EfiOpenTftp: - // Cache the file if it hasn't been cached yet. - if (File->IsBufferValid == FALSE) { - Status = CacheTftpFile (File); - if (EFI_ERROR (Status)) { - return Status; - } - } - - // Copy out the requested data - CopyMem (Buffer, File->Buffer + File->CurrentPosition, *BufferSize); - File->CurrentPosition += *BufferSize; - - Status = EFI_SUCCESS; - break; - - default: - return EFI_INVALID_PARAMETER; - }; - - return Status; -} - - -/** -Read the entire file into a buffer. This routine allocates the buffer and -returns it to the user full of the read data. - -This is very useful for load file where it's hard to know how big the buffer -must be. - -@param Stream Open File Handle -@param Buffer Pointer to buffer to return. -@param BufferSize Pointer to Size of buffer return.. - - -@return EFI_SUCCESS Stream is not an Open File -@return EFI_END_OF_FILE Tried to read past the end of the file -@return EFI_INVALID_PARAMETER Stream is not an open file handle -@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read -@return "other" Error returned from device read - -**/ -EFI_STATUS -EfiReadAllocatePool ( - IN EFI_OPEN_FILE *File, - OUT VOID **Buffer, - OUT UINTN *BufferSize - ) -{ - if (!FileHandleValid (File)) { - return EFI_INVALID_PARAMETER; - } - - // Loadfile defers file size determination on Open so use tell to find it - EfiTell (File, NULL); - - *BufferSize = File->Size; - *Buffer = AllocatePool (*BufferSize); - if (*Buffer == NULL) { - return EFI_NOT_FOUND; - } - - return EfiRead (File, *Buffer, BufferSize); -} - - -/** -Write data back to the file. For TFTP case you must write the entire file. - -@param Stream Open File Handle -@param Buffer Pointer to buffer to return. -@param BufferSize Pointer to Size of buffer return.. - - -@return EFI_SUCCESS Stream is not an Open File -@return EFI_END_OF_FILE Tried to read past the end of the file -@return EFI_INVALID_PARAMETER Stream is not an open file handle -@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read -@return "other" Error returned from device write - -**/ -EFI_STATUS -EfiWrite ( - IN EFI_OPEN_FILE *File, - OUT VOID *Buffer, - OUT UINTN *BufferSize - ) -{ - EFI_STATUS Status; - EFI_FV_WRITE_FILE_DATA FileData; - EFI_DISK_IO_PROTOCOL *DiskIo; - - if (!FileHandleValid (File)) { - return EFI_INVALID_PARAMETER; - } - - switch (File->Type) { - case EfiOpenMemoryBuffer: - if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) { - return EFI_END_OF_FILE; - } - - CopyMem (File->Buffer + File->CurrentPosition, Buffer, *BufferSize); - File->CurrentPosition += *BufferSize; - Status = EFI_SUCCESS; - - case EfiOpenLoadFile: - // LoadFile device is read only be definition - Status = EFI_UNSUPPORTED; - - case EfiOpenFirmwareVolume: - if (File->FvSectionType != EFI_SECTION_ALL) { - // Writes not support to a specific section. You have to update entire file - return EFI_UNSUPPORTED; - } - - FileData.NameGuid = &(File->FvNameGuid); - FileData.Type = File->FvType; - FileData.FileAttributes = File->FvAttributes; - FileData.Buffer = Buffer; - FileData.BufferSize = (UINT32)*BufferSize; - Status = File->Fv->WriteFile (File->Fv, 1, EFI_FV_UNRELIABLE_WRITE, &FileData); - break; - - case EfiOpenFileSystem: - Status = File->FsFileHandle->Write (File->FsFileHandle, BufferSize, Buffer); - File->CurrentPosition += *BufferSize; - break; - - case EfiOpenBlockIo: - if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) { - return EFI_END_OF_FILE; - } - - Status = gBS->HandleProtocol (File->EfiHandle, &gEfiDiskIoProtocolGuid, (VOID **)&DiskIo); - if (!EFI_ERROR(Status)) { - Status = DiskIo->WriteDisk (DiskIo, File->FsBlockIoMedia->MediaId, File->DiskOffset + File->CurrentPosition, *BufferSize, Buffer); - } - File->CurrentPosition += *BufferSize; - break; - - case EfiOpenTftp: - // Cache the file if it hasn't been cached yet. - if (File->IsBufferValid == FALSE) { - Status = CacheTftpFile(File); - if (EFI_ERROR(Status)) { - return Status; - } - } - - // Don't overwrite the buffer - if ((File->CurrentPosition + *BufferSize) > File->MaxPosition) { - UINT8 *TempBuffer; - - TempBuffer = File->Buffer; - - File->Buffer = AllocatePool ((UINTN)(File->CurrentPosition + *BufferSize)); - if (File->Buffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - CopyMem (File->Buffer, TempBuffer, File->Size); - - FreePool (TempBuffer); - - File->Size = (UINTN)(File->CurrentPosition + *BufferSize); - File->MaxPosition = (UINT64)File->Size; - } - - // Copy in the requested data - CopyMem (File->Buffer + File->CurrentPosition, Buffer, *BufferSize); - File->CurrentPosition += *BufferSize; - - // Mark the file dirty - File->IsDirty = TRUE; - - Status = EFI_SUCCESS; - break; - - default: - Status = EFI_INVALID_PARAMETER; - }; - - return Status; -} - - -/** -Given Cwd expand Path to remove .. and replace them with real -directory names. - -@param Cwd Current Working Directory -@param Path Path to expand - -@return NULL Cwd or Path are not valid -@return 'other' Path with .. expanded - -**/ -CHAR8 * -ExpandPath ( - IN CHAR8 *Cwd, - IN CHAR8 *Path - ) -{ - CHAR8 *NewPath; - CHAR8 *Work, *Start, *End; - UINTN StrLen; - INTN i; - - if (Cwd == NULL || Path == NULL) { - return NULL; - } - - StrLen = AsciiStrSize (Cwd); - if (StrLen <= 2) { - // Smallest valid path is 1 char and a null - return NULL; - } - - StrLen = AsciiStrSize (Path); - NewPath = AllocatePool (AsciiStrSize (Cwd) + StrLen + 1); - if (NewPath == NULL) { - return NULL; - } - AsciiStrCpy (NewPath, Cwd); - - End = Path + StrLen; - for (Start = Path ;;) { - Work = AsciiStrStr (Start, "..") ; - if (Work == NULL) { - // Remaining part of Path contains no more .. - break; - } - - // append path prior to .. - AsciiStrnCat (NewPath, Start, Work - Start); - StrLen = AsciiStrLen (NewPath); - for (i = StrLen; i >= 0; i--) { - if (NewPath[i] == ':') { - // too many .. - return NULL; - } - if (NewPath[i] == '/' || NewPath[i] == '\\') { - if ((i > 0) && (NewPath[i-1] == ':')) { - // leave the / before a : - NewPath[i+1] = '\0'; - } else { - // replace / will Null to remove trailing file/dir reference - NewPath[i] = '\0'; - } - break; - } - } - - Start = Work + 3; - } - - // Handle the path that remains after the .. - AsciiStrnCat (NewPath, Start, End - Start); - - return NewPath; -} - - -/** -Set the Current Working Directory (CWD). If a call is made to EfiOpen () and -the path does not contain a device name, The CWD is prepended to the path. - -@param Cwd Current Working Directory to set - - -@return EFI_SUCCESS CWD is set -@return EFI_INVALID_PARAMETER Cwd is not a valid device:path - -**/ -EFI_STATUS -EfiSetCwd ( - IN CHAR8 *Cwd - ) -{ - EFI_OPEN_FILE *File; - UINTN Len; - CHAR8 *Path; - - if (Cwd == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (AsciiStrCmp (Cwd, ".") == 0) { - // cd . is a no-op - return EFI_SUCCESS; - } - - Path = Cwd; - if (AsciiStrStr (Cwd, "..") != NULL) { - if (gCwd == NULL) { - // no parent - return EFI_SUCCESS; - } - - Len = AsciiStrLen (gCwd); - if ((gCwd[Len-2] == ':') && ((gCwd[Len-1] == '/') || (gCwd[Len-1] == '\\'))) { - // parent is device so nothing to do - return EFI_SUCCESS; - } - - // Expand .. in Cwd, given we know current working directory - Path = ExpandPath (gCwd, Cwd); - if (Path == NULL) { - return EFI_NOT_FOUND; - } - } - - File = EfiOpen (Path, EFI_FILE_MODE_READ, 0); - if (File == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (gCwd != NULL) { - FreePool (gCwd); - } - - // Use the info returned from EfiOpen as it can add in CWD if needed. So Cwd could be - // relative to the current gCwd or not. - gCwd = AllocatePool (AsciiStrSize (File->DeviceName) + AsciiStrSize (File->FileName) + 10); - if (gCwd == NULL) { - return EFI_INVALID_PARAMETER; - } - - AsciiStrCpy (gCwd, File->DeviceName); - if (File->FileName == NULL) { - AsciiStrCat (gCwd, ":\\"); - } else { - AsciiStrCat (gCwd, ":"); - AsciiStrCat (gCwd, File->FileName); - } - - - EfiClose (File); - if (Path != Cwd) { - FreePool (Path); - } - return EFI_SUCCESS; -} - - -/** -Set the Current Working Directory (CWD). If a call is made to EfiOpen () and -the path does not contain a device name, The CWD is prepended to the path. -The CWD buffer is only valid until a new call is made to EfiSetCwd(). After -a call to EfiSetCwd() it is not legal to use the pointer returned by -this function. - -@param Cwd Current Working Directory - - -@return "" No CWD set -@return 'other' Returns buffer that contains CWD. - -**/ -CHAR8 * -EfiGetCwd ( - VOID - ) -{ - if (gCwd == NULL) { - return ""; - } - return gCwd; -} - - diff --git a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf deleted file mode 100644 index b8cb255268..0000000000 --- a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf +++ /dev/null @@ -1,64 +0,0 @@ -#/** @file -# Component description file for the entry point to a EFIDXE Drivers -# -# Library to abstract Framework extensions that conflict with UEFI 2.0 Specification -# Copyright (c) 2007 - 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = EfiFileLib - FILE_GUID = d8c640db-73ba-48f5-a7ed-8e93c6012491 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = EfiFileLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER - - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - EfiFileLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - BaseLib - MemoryAllocationLib - DevicePathLib - PrintLib - BaseMemoryLib - UefiLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - DebugLib - EblNetworkLib - -[Protocols] - gEfiBlockIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiDiskIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiSimpleFileSystemProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiFirmwareVolume2ProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiLoadFileProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - -[Guids] - gEfiFileInfoGuid - gEfiFileSystemInfoGuid - gZeroGuid diff --git a/EmbeddedPkg/Library/FdtLib/FdtLib.inf b/EmbeddedPkg/Library/FdtLib/FdtLib.inf deleted file mode 100644 index f3da231143..0000000000 --- a/EmbeddedPkg/Library/FdtLib/FdtLib.inf +++ /dev/null @@ -1,38 +0,0 @@ -#/* @file -# Copyright (c) 2011-2014, ARM Limited. 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. -# -#*/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = FdtLib - FILE_GUID = 6b2478c0-be23-11e0-a28c-0002a5d5c51b - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = FdtLib - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = ARM AARCH64 -# - -[Sources] - fdt_ro.c - fdt_rw.c - fdt_strerror.c - fdt_sw.c - fdt_wip.c - fdt.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec diff --git a/EmbeddedPkg/Library/FdtLib/Makefile.libfdt b/EmbeddedPkg/Library/FdtLib/Makefile.libfdt deleted file mode 100644 index 91126c000a..0000000000 --- a/EmbeddedPkg/Library/FdtLib/Makefile.libfdt +++ /dev/null @@ -1,10 +0,0 @@ -# Makefile.libfdt -# -# This is not a complete Makefile of itself. Instead, it is designed to -# be easily embeddable into other systems of Makefiles. -# -LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 -LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h -LIBFDT_VERSION = version.lds -LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c -LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) diff --git a/EmbeddedPkg/Library/FdtLib/README.txt b/EmbeddedPkg/Library/FdtLib/README.txt deleted file mode 100755 index fb4010539f..0000000000 --- a/EmbeddedPkg/Library/FdtLib/README.txt +++ /dev/null @@ -1 +0,0 @@ -See: https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=EmbeddedPkg/Fdt \ No newline at end of file diff --git a/EmbeddedPkg/Library/FdtLib/TODO b/EmbeddedPkg/Library/FdtLib/TODO deleted file mode 100644 index 288437e394..0000000000 --- a/EmbeddedPkg/Library/FdtLib/TODO +++ /dev/null @@ -1,3 +0,0 @@ -- Tree traversal functions -- Graft function -- Complete libfdt.h documenting comments diff --git a/EmbeddedPkg/Library/FdtLib/fdt.c b/EmbeddedPkg/Library/FdtLib/fdt.c deleted file mode 100644 index 963952820b..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -int fdt_check_header(const void *fdt) -{ - if (fdt_magic(fdt) == FDT_MAGIC) { - /* Complete tree */ - if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) - return -FDT_ERR_BADVERSION; - if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION) - return -FDT_ERR_BADVERSION; - } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { - /* Unfinished sequential-write blob */ - if (fdt_size_dt_struct(fdt) == 0) - return -FDT_ERR_BADSTATE; - } else { - return -FDT_ERR_BADMAGIC; - } - - return 0; -} - -const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) -{ - const char *p; - - if (fdt_version(fdt) >= 0x11) - if (((offset + len) < offset) - || ((offset + len) > fdt_size_dt_struct(fdt))) - return NULL; - - p = _fdt_offset_ptr(fdt, offset); - - if (p + len < p) - return NULL; - return p; -} - -uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) -{ - const fdt32_t *tagp, *lenp; - uint32_t tag; - int offset = startoffset; - const char *p; - - *nextoffset = -FDT_ERR_TRUNCATED; - tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE); - if (!tagp) - return FDT_END; /* premature end */ - tag = fdt32_to_cpu(*tagp); - offset += FDT_TAGSIZE; - - *nextoffset = -FDT_ERR_BADSTRUCTURE; - switch (tag) { - case FDT_BEGIN_NODE: - /* skip name */ - do { - p = fdt_offset_ptr(fdt, offset++, 1); - } while (p && (*p != '\0')); - if (!p) - return FDT_END; /* premature end */ - break; - - case FDT_PROP: - lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp)); - if (!lenp) - return FDT_END; /* premature end */ - /* skip-name offset, length and value */ - offset += sizeof(struct fdt_property) - FDT_TAGSIZE - + fdt32_to_cpu(*lenp); - break; - - case FDT_END: - case FDT_END_NODE: - case FDT_NOP: - break; - - default: - return FDT_END; - } - - if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset)) - return FDT_END; /* premature end */ - - *nextoffset = FDT_TAGALIGN(offset); - return tag; -} - -int _fdt_check_node_offset(const void *fdt, int offset) -{ - if ((offset < 0) || (offset % FDT_TAGSIZE) - || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)) - return -FDT_ERR_BADOFFSET; - - return offset; -} - -int _fdt_check_prop_offset(const void *fdt, int offset) -{ - if ((offset < 0) || (offset % FDT_TAGSIZE) - || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)) - return -FDT_ERR_BADOFFSET; - - return offset; -} - -int fdt_next_node(const void *fdt, int offset, int *depth) -{ - int nextoffset = 0; - uint32_t tag; - - if (offset >= 0) - if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0) - return nextoffset; - - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_PROP: - case FDT_NOP: - break; - - case FDT_BEGIN_NODE: - if (depth) - (*depth)++; - break; - - case FDT_END_NODE: - if (depth && ((--(*depth)) < 0)) - return nextoffset; - break; - - case FDT_END: - if ((nextoffset >= 0) - || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth)) - return -FDT_ERR_NOTFOUND; - else - return nextoffset; - } - } while (tag != FDT_BEGIN_NODE); - - return offset; -} - -int fdt_first_subnode(const void *fdt, int offset) -{ - int depth = 0; - - offset = fdt_next_node(fdt, offset, &depth); - if (offset < 0 || depth != 1) - return -FDT_ERR_NOTFOUND; - - return offset; -} - -int fdt_next_subnode(const void *fdt, int offset) -{ - int depth = 1; - - /* - * With respect to the parent, the depth of the next subnode will be - * the same as the last. - */ - do { - offset = fdt_next_node(fdt, offset, &depth); - if (offset < 0 || depth < 1) - return -FDT_ERR_NOTFOUND; - } while (depth > 1); - - return offset; -} - -const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) -{ - int len = strlen(s) + 1; - const char *last = strtab + tabsize - len; - const char *p; - - for (p = strtab; p <= last; p++) - if (memcmp(p, s, len) == 0) - return p; - return NULL; -} - -int fdt_move(const void *fdt, void *buf, int bufsize) -{ - FDT_CHECK_HEADER(fdt); - - if (fdt_totalsize(fdt) > bufsize) - return -FDT_ERR_NOSPACE; - - memmove(buf, fdt, fdt_totalsize(fdt)); - return 0; -} diff --git a/EmbeddedPkg/Library/FdtLib/fdt_empty_tree.c b/EmbeddedPkg/Library/FdtLib/fdt_empty_tree.c deleted file mode 100644 index f00a8991d4..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt_empty_tree.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2012 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -int fdt_create_empty_tree(void *buf, int bufsize) -{ - int err; - - err = fdt_create(buf, bufsize); - if (err) - return err; - - err = fdt_finish_reservemap(buf); - if (err) - return err; - - err = fdt_begin_node(buf, ""); - if (err) - return err; - - err = fdt_end_node(buf); - if (err) - return err; - - err = fdt_finish(buf); - if (err) - return err; - - return fdt_open_into(buf, buf, bufsize); -} - diff --git a/EmbeddedPkg/Library/FdtLib/fdt_ro.c b/EmbeddedPkg/Library/FdtLib/fdt_ro.c deleted file mode 100644 index 2055891e71..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt_ro.c +++ /dev/null @@ -1,574 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int _fdt_nodename_eq(const void *fdt, int offset, - const char *s, int len) -{ - const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1); - - if (! p) - /* short match */ - return 0; - - if (memcmp(p, s, len) != 0) - return 0; - - if (p[len] == '\0') - return 1; - else if (!memchr(s, '@', len) && (p[len] == '@')) - return 1; - else - return 0; -} - -const char *fdt_string(const void *fdt, int stroffset) -{ - return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset; -} - -static int _fdt_string_eq(const void *fdt, int stroffset, - const char *s, int len) -{ - const char *p = fdt_string(fdt, stroffset); - - return (strlen(p) == len) && (memcmp(p, s, len) == 0); -} - -int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) -{ - FDT_CHECK_HEADER(fdt); - *address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address); - *size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size); - return 0; -} - -int fdt_num_mem_rsv(const void *fdt) -{ - int i = 0; - - while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0) - i++; - return i; -} - -static int _nextprop(const void *fdt, int offset) -{ - uint32_t tag; - int nextoffset; - - do { - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_END: - if (nextoffset >= 0) - return -FDT_ERR_BADSTRUCTURE; - else - return nextoffset; - - case FDT_PROP: - return offset; - } - offset = nextoffset; - } while (tag == FDT_NOP); - - return -FDT_ERR_NOTFOUND; -} - -int fdt_subnode_offset_namelen(const void *fdt, int offset, - const char *name, int namelen) -{ - int depth; - - FDT_CHECK_HEADER(fdt); - - for (depth = 0; - (offset >= 0) && (depth >= 0); - offset = fdt_next_node(fdt, offset, &depth)) - if ((depth == 1) - && _fdt_nodename_eq(fdt, offset, name, namelen)) - return offset; - - if (depth < 0) - return -FDT_ERR_NOTFOUND; - return offset; /* error */ -} - -int fdt_subnode_offset(const void *fdt, int parentoffset, - const char *name) -{ - return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name)); -} - -int fdt_path_offset(const void *fdt, const char *path) -{ - const char *end = path + strlen(path); - const char *p = path; - int offset = 0; - - FDT_CHECK_HEADER(fdt); - - /* see if we have an alias */ - if (*path != '/') { - const char *q = strchr(path, '/'); - - if (!q) - q = end; - - p = fdt_get_alias_namelen(fdt, p, q - p); - if (!p) - return -FDT_ERR_BADPATH; - offset = fdt_path_offset(fdt, p); - - p = q; - } - - while (*p) { - const char *q; - - while (*p == '/') - p++; - if (! *p) - return offset; - q = strchr(p, '/'); - if (! q) - q = end; - - offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p); - if (offset < 0) - return offset; - - p = q; - } - - return offset; -} - -const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) -{ - const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); - int err; - - if (((err = fdt_check_header(fdt)) != 0) - || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) - goto fail; - - if (len) - *len = strlen(nh->name); - - return nh->name; - - fail: - if (len) - *len = err; - return NULL; -} - -int fdt_first_property_offset(const void *fdt, int nodeoffset) -{ - int offset; - - if ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) - return offset; - - return _nextprop(fdt, offset); -} - -int fdt_next_property_offset(const void *fdt, int offset) -{ - if ((offset = _fdt_check_prop_offset(fdt, offset)) < 0) - return offset; - - return _nextprop(fdt, offset); -} - -const struct fdt_property *fdt_get_property_by_offset(const void *fdt, - int offset, - int *lenp) -{ - int err; - const struct fdt_property *prop; - - if ((err = _fdt_check_prop_offset(fdt, offset)) < 0) { - if (lenp) - *lenp = err; - return NULL; - } - - prop = _fdt_offset_ptr(fdt, offset); - - if (lenp) - *lenp = fdt32_to_cpu(prop->len); - - return prop; -} - -const struct fdt_property *fdt_get_property_namelen(const void *fdt, - int offset, - const char *name, - int namelen, int *lenp) -{ - for (offset = fdt_first_property_offset(fdt, offset); - (offset >= 0); - (offset = fdt_next_property_offset(fdt, offset))) { - const struct fdt_property *prop; - - prop = fdt_get_property_by_offset(fdt, offset, lenp); - if (!prop) { - offset = -FDT_ERR_INTERNAL; - break; - } - if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff), - name, namelen)) - return prop; - } - - if (lenp) - *lenp = offset; - return NULL; -} - -const struct fdt_property *fdt_get_property(const void *fdt, - int nodeoffset, - const char *name, int *lenp) -{ - return fdt_get_property_namelen(fdt, nodeoffset, name, - strlen(name), lenp); -} - -const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, - const char *name, int namelen, int *lenp) -{ - const struct fdt_property *prop; - - prop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp); - if (! prop) - return NULL; - - return prop->data; -} - -const void *fdt_getprop_by_offset(const void *fdt, int offset, - const char **namep, int *lenp) -{ - const struct fdt_property *prop; - - prop = fdt_get_property_by_offset(fdt, offset, lenp); - if (!prop) - return NULL; - if (namep) - *namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); - return prop->data; -} - -const void *fdt_getprop(const void *fdt, int nodeoffset, - const char *name, int *lenp) -{ - return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp); -} - -uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) -{ - const fdt32_t *php; - int len; - - /* FIXME: This is a bit sub-optimal, since we potentially scan - * over all the properties twice. */ - php = fdt_getprop(fdt, nodeoffset, "phandle", &len); - if (!php || (len != sizeof(*php))) { - php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len); - if (!php || (len != sizeof(*php))) - return 0; - } - - return fdt32_to_cpu(*php); -} - -const char *fdt_get_alias_namelen(const void *fdt, - const char *name, int namelen) -{ - int aliasoffset; - - aliasoffset = fdt_path_offset(fdt, "/aliases"); - if (aliasoffset < 0) - return NULL; - - return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL); -} - -const char *fdt_get_alias(const void *fdt, const char *name) -{ - return fdt_get_alias_namelen(fdt, name, strlen(name)); -} - -int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) -{ - int pdepth = 0, p = 0; - int offset, depth, namelen; - const char *name; - - FDT_CHECK_HEADER(fdt); - - if (buflen < 2) - return -FDT_ERR_NOSPACE; - - for (offset = 0, depth = 0; - (offset >= 0) && (offset <= nodeoffset); - offset = fdt_next_node(fdt, offset, &depth)) { - while (pdepth > depth) { - do { - p--; - } while (buf[p-1] != '/'); - pdepth--; - } - - if (pdepth >= depth) { - name = fdt_get_name(fdt, offset, &namelen); - if (!name) - return namelen; - if ((p + namelen + 1) <= buflen) { - memcpy(buf + p, name, namelen); - p += namelen; - buf[p++] = '/'; - pdepth++; - } - } - - if (offset == nodeoffset) { - if (pdepth < (depth + 1)) - return -FDT_ERR_NOSPACE; - - if (p > 1) /* special case so that root path is "/", not "" */ - p--; - buf[p] = '\0'; - return 0; - } - } - - if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) - return -FDT_ERR_BADOFFSET; - else if (offset == -FDT_ERR_BADOFFSET) - return -FDT_ERR_BADSTRUCTURE; - - return offset; /* error from fdt_next_node() */ -} - -int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, - int supernodedepth, int *nodedepth) -{ - int offset, depth; - int supernodeoffset = -FDT_ERR_INTERNAL; - - FDT_CHECK_HEADER(fdt); - - if (supernodedepth < 0) - return -FDT_ERR_NOTFOUND; - - for (offset = 0, depth = 0; - (offset >= 0) && (offset <= nodeoffset); - offset = fdt_next_node(fdt, offset, &depth)) { - if (depth == supernodedepth) - supernodeoffset = offset; - - if (offset == nodeoffset) { - if (nodedepth) - *nodedepth = depth; - - if (supernodedepth > depth) - return -FDT_ERR_NOTFOUND; - else - return supernodeoffset; - } - } - - if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) - return -FDT_ERR_BADOFFSET; - else if (offset == -FDT_ERR_BADOFFSET) - return -FDT_ERR_BADSTRUCTURE; - - return offset; /* error from fdt_next_node() */ -} - -int fdt_node_depth(const void *fdt, int nodeoffset) -{ - int nodedepth; - int err; - - err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth); - if (err) - return (err < 0) ? err : -FDT_ERR_INTERNAL; - return nodedepth; -} - -int fdt_parent_offset(const void *fdt, int nodeoffset) -{ - int nodedepth = fdt_node_depth(fdt, nodeoffset); - - if (nodedepth < 0) - return nodedepth; - return fdt_supernode_atdepth_offset(fdt, nodeoffset, - nodedepth - 1, NULL); -} - -int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, - const char *propname, - const void *propval, int proplen) -{ - int offset; - const void *val; - int len; - - FDT_CHECK_HEADER(fdt); - - /* FIXME: The algorithm here is pretty horrible: we scan each - * property of a node in fdt_getprop(), then if that didn't - * find what we want, we scan over them again making our way - * to the next node. Still it's the easiest to implement - * approach; performance can come later. */ - for (offset = fdt_next_node(fdt, startoffset, NULL); - offset >= 0; - offset = fdt_next_node(fdt, offset, NULL)) { - val = fdt_getprop(fdt, offset, propname, &len); - if (val && (len == proplen) - && (memcmp(val, propval, len) == 0)) - return offset; - } - - return offset; /* error from fdt_next_node() */ -} - -int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) -{ - int offset; - - if ((phandle == 0) || (phandle == (uint32_t)-1)) - return -FDT_ERR_BADPHANDLE; - - FDT_CHECK_HEADER(fdt); - - /* FIXME: The algorithm here is pretty horrible: we - * potentially scan each property of a node in - * fdt_get_phandle(), then if that didn't find what - * we want, we scan over them again making our way to the next - * node. Still it's the easiest to implement approach; - * performance can come later. */ - for (offset = fdt_next_node(fdt, -1, NULL); - offset >= 0; - offset = fdt_next_node(fdt, offset, NULL)) { - if (fdt_get_phandle(fdt, offset) == phandle) - return offset; - } - - return offset; /* error from fdt_next_node() */ -} - -int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) -{ - int len = strlen(str); - const char *p; - - while (listlen >= len) { - if (memcmp(str, strlist, len+1) == 0) - return 1; - p = memchr(strlist, '\0', listlen); - if (!p) - return 0; /* malformed strlist.. */ - listlen -= (p-strlist) + 1; - strlist = p + 1; - } - return 0; -} - -int fdt_node_check_compatible(const void *fdt, int nodeoffset, - const char *compatible) -{ - const void *prop; - int len; - - prop = fdt_getprop(fdt, nodeoffset, "compatible", &len); - if (!prop) - return len; - if (fdt_stringlist_contains(prop, len, compatible)) - return 0; - else - return 1; -} - -int fdt_node_offset_by_compatible(const void *fdt, int startoffset, - const char *compatible) -{ - int offset, err; - - FDT_CHECK_HEADER(fdt); - - /* FIXME: The algorithm here is pretty horrible: we scan each - * property of a node in fdt_node_check_compatible(), then if - * that didn't find what we want, we scan over them again - * making our way to the next node. Still it's the easiest to - * implement approach; performance can come later. */ - for (offset = fdt_next_node(fdt, startoffset, NULL); - offset >= 0; - offset = fdt_next_node(fdt, offset, NULL)) { - err = fdt_node_check_compatible(fdt, offset, compatible); - if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) - return err; - else if (err == 0) - return offset; - } - - return offset; /* error from fdt_next_node() */ -} diff --git a/EmbeddedPkg/Library/FdtLib/fdt_rw.c b/EmbeddedPkg/Library/FdtLib/fdt_rw.c deleted file mode 100644 index 7a2bcf3d07..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt_rw.c +++ /dev/null @@ -1,495 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int _fdt_blocks_misordered(const void *fdt, - int mem_rsv_size, int struct_size) -{ - return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8)) - || (fdt_off_dt_struct(fdt) < - (fdt_off_mem_rsvmap(fdt) + mem_rsv_size)) - || (fdt_off_dt_strings(fdt) < - (fdt_off_dt_struct(fdt) + struct_size)) - || (fdt_totalsize(fdt) < - (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); -} - -static int _fdt_rw_check_header(void *fdt) -{ - FDT_CHECK_HEADER(fdt); - - if (fdt_version(fdt) < 17) - return -FDT_ERR_BADVERSION; - if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry), - fdt_size_dt_struct(fdt))) - return -FDT_ERR_BADLAYOUT; - if (fdt_version(fdt) > 17) - fdt_set_version(fdt, 17); - - return 0; -} - -#define FDT_RW_CHECK_HEADER(fdt) \ - { \ - int err; \ - if ((err = _fdt_rw_check_header(fdt)) != 0) \ - return err; \ - } - -static inline int _fdt_data_size(void *fdt) -{ - return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); -} - -static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen) -{ - char *p = splicepoint; - char *end = (char *)fdt + _fdt_data_size(fdt); - - if (((p + oldlen) < p) || ((p + oldlen) > end)) - return -FDT_ERR_BADOFFSET; - if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt))) - return -FDT_ERR_NOSPACE; - memmove(p + newlen, p + oldlen, end - p - oldlen); - return 0; -} - -static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p, - int oldn, int newn) -{ - int delta = (newn - oldn) * sizeof(*p); - int err; - err = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); - if (err) - return err; - fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); - fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); - return 0; -} - -static int _fdt_splice_struct(void *fdt, void *p, - int oldlen, int newlen) -{ - int delta = newlen - oldlen; - int err; - - err = _fdt_splice(fdt, p, oldlen, newlen); - if (err) - return err; - - fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); - fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); - return 0; -} - -static int _fdt_splice_string(void *fdt, int newlen) -{ - void *p = (char *)fdt - + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); - int err; - - err = _fdt_splice(fdt, p, 0, newlen); - if (err) - return err; - - fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); - return 0; -} - -static int _fdt_find_add_string(void *fdt, const char *s) -{ - char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); - const char *p; - char *new; - int len = strlen(s) + 1; - int err; - - p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s); - if (p) - /* found it */ - return (p - strtab); - - new = strtab + fdt_size_dt_strings(fdt); - err = _fdt_splice_string(fdt, len); - if (err) - return err; - - memcpy(new, s, len); - return (new - strtab); -} - -int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) -{ - struct fdt_reserve_entry *re; - int err; - - FDT_RW_CHECK_HEADER(fdt); - - re = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt)); - err = _fdt_splice_mem_rsv(fdt, re, 0, 1); - if (err) - return err; - - re->address = cpu_to_fdt64(address); - re->size = cpu_to_fdt64(size); - return 0; -} - -int fdt_del_mem_rsv(void *fdt, int n) -{ - struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n); - int err; - - FDT_RW_CHECK_HEADER(fdt); - - if (n >= fdt_num_mem_rsv(fdt)) - return -FDT_ERR_NOTFOUND; - - err = _fdt_splice_mem_rsv(fdt, re, 1, 0); - if (err) - return err; - return 0; -} - -static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, - int len, struct fdt_property **prop) -{ - int oldlen; - int err; - - *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); - if (! (*prop)) - return oldlen; - - err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), - FDT_TAGALIGN(len)); - if (err) - return err; - - (*prop)->len = cpu_to_fdt32(len); - return 0; -} - -static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, - int len, struct fdt_property **prop) -{ - int proplen; - int nextoffset; - int namestroff; - int err; - - if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) - return nextoffset; - - namestroff = _fdt_find_add_string(fdt, name); - if (namestroff < 0) - return namestroff; - - *prop = _fdt_offset_ptr_w(fdt, nextoffset); - proplen = sizeof(**prop) + FDT_TAGALIGN(len); - - err = _fdt_splice_struct(fdt, *prop, 0, proplen); - if (err) - return err; - - (*prop)->tag = cpu_to_fdt32(FDT_PROP); - (*prop)->nameoff = cpu_to_fdt32(namestroff); - (*prop)->len = cpu_to_fdt32(len); - return 0; -} - -int fdt_set_name(void *fdt, int nodeoffset, const char *name) -{ - char *namep; - int oldlen, newlen; - int err; - - FDT_RW_CHECK_HEADER(fdt); - - namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen); - if (!namep) - return oldlen; - - newlen = strlen(name); - - err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1), - FDT_TAGALIGN(newlen+1)); - if (err) - return err; - - memcpy(namep, name, newlen+1); - return 0; -} - -int fdt_setprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len) -{ - struct fdt_property *prop; - int err; - - FDT_RW_CHECK_HEADER(fdt); - - err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop); - if (err == -FDT_ERR_NOTFOUND) - err = _fdt_add_property(fdt, nodeoffset, name, len, &prop); - if (err) - return err; - - memcpy(prop->data, val, len); - return 0; -} - -int fdt_appendprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len) -{ - struct fdt_property *prop; - int err, oldlen, newlen; - - FDT_RW_CHECK_HEADER(fdt); - - prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); - if (prop) { - newlen = len + oldlen; - err = _fdt_splice_struct(fdt, prop->data, - FDT_TAGALIGN(oldlen), - FDT_TAGALIGN(newlen)); - if (err) - return err; - prop->len = cpu_to_fdt32(newlen); - memcpy(prop->data + oldlen, val, len); - } else { - err = _fdt_add_property(fdt, nodeoffset, name, len, &prop); - if (err) - return err; - memcpy(prop->data, val, len); - } - return 0; -} - -int fdt_delprop(void *fdt, int nodeoffset, const char *name) -{ - struct fdt_property *prop; - int len, proplen; - - FDT_RW_CHECK_HEADER(fdt); - - prop = fdt_get_property_w(fdt, nodeoffset, name, &len); - if (! prop) - return len; - - proplen = sizeof(*prop) + FDT_TAGALIGN(len); - return _fdt_splice_struct(fdt, prop, proplen, 0); -} - -int fdt_add_subnode_namelen(void *fdt, int parentoffset, - const char *name, int namelen) -{ - struct fdt_node_header *nh; - int offset, nextoffset; - int nodelen; - int err; - uint32_t tag; - fdt32_t *endtag; - - FDT_RW_CHECK_HEADER(fdt); - - offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen); - if (offset >= 0) - return -FDT_ERR_EXISTS; - else if (offset != -FDT_ERR_NOTFOUND) - return offset; - - /* Try to place the new node after the parent's properties */ - fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */ - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - } while ((tag == FDT_PROP) || (tag == FDT_NOP)); - - nh = _fdt_offset_ptr_w(fdt, offset); - nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE; - - err = _fdt_splice_struct(fdt, nh, 0, nodelen); - if (err) - return err; - - nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); - memset(nh->name, 0, FDT_TAGALIGN(namelen+1)); - memcpy(nh->name, name, namelen); - endtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE); - *endtag = cpu_to_fdt32(FDT_END_NODE); - - return offset; -} - -int fdt_add_subnode(void *fdt, int parentoffset, const char *name) -{ - return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name)); -} - -int fdt_del_node(void *fdt, int nodeoffset) -{ - int endoffset; - - FDT_RW_CHECK_HEADER(fdt); - - endoffset = _fdt_node_end_offset(fdt, nodeoffset); - if (endoffset < 0) - return endoffset; - - return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset), - endoffset - nodeoffset, 0); -} - -static void _fdt_packblocks(const char *old, char *new, - int mem_rsv_size, int struct_size) -{ - int mem_rsv_off, struct_off, strings_off; - - mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8); - struct_off = mem_rsv_off + mem_rsv_size; - strings_off = struct_off + struct_size; - - memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size); - fdt_set_off_mem_rsvmap(new, mem_rsv_off); - - memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size); - fdt_set_off_dt_struct(new, struct_off); - fdt_set_size_dt_struct(new, struct_size); - - memmove(new + strings_off, old + fdt_off_dt_strings(old), - fdt_size_dt_strings(old)); - fdt_set_off_dt_strings(new, strings_off); - fdt_set_size_dt_strings(new, fdt_size_dt_strings(old)); -} - -int fdt_open_into(const void *fdt, void *buf, int bufsize) -{ - int err; - int mem_rsv_size, struct_size; - int newsize; - const char *fdtstart = fdt; - const char *fdtend = fdtstart + fdt_totalsize(fdt); - char *tmp; - - FDT_CHECK_HEADER(fdt); - - mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) - * sizeof(struct fdt_reserve_entry); - - if (fdt_version(fdt) >= 17) { - struct_size = fdt_size_dt_struct(fdt); - } else { - struct_size = 0; - while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END) - ; - if (struct_size < 0) - return struct_size; - } - - if (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) { - /* no further work necessary */ - err = fdt_move(fdt, buf, bufsize); - if (err) - return err; - fdt_set_version(buf, 17); - fdt_set_size_dt_struct(buf, struct_size); - fdt_set_totalsize(buf, bufsize); - return 0; - } - - /* Need to reorder */ - newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size - + struct_size + fdt_size_dt_strings(fdt); - - if (bufsize < newsize) - return -FDT_ERR_NOSPACE; - - /* First attempt to build converted tree at beginning of buffer */ - tmp = buf; - /* But if that overlaps with the old tree... */ - if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) { - /* Try right after the old tree instead */ - tmp = (char *)(uintptr_t)fdtend; - if ((tmp + newsize) > ((char *)buf + bufsize)) - return -FDT_ERR_NOSPACE; - } - - _fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size); - memmove(buf, tmp, newsize); - - fdt_set_magic(buf, FDT_MAGIC); - fdt_set_totalsize(buf, bufsize); - fdt_set_version(buf, 17); - fdt_set_last_comp_version(buf, 16); - fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); - - return 0; -} - -int fdt_pack(void *fdt) -{ - int mem_rsv_size; - - FDT_RW_CHECK_HEADER(fdt); - - mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) - * sizeof(struct fdt_reserve_entry); - _fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); - fdt_set_totalsize(fdt, _fdt_data_size(fdt)); - - return 0; -} diff --git a/EmbeddedPkg/Library/FdtLib/fdt_strerror.c b/EmbeddedPkg/Library/FdtLib/fdt_strerror.c deleted file mode 100644 index a49793d936..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt_strerror.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -struct fdt_errtabent { - const char *str; -}; - -#define FDT_ERRTABENT(val) \ - [(val)] = { .str = #val, } - -static struct fdt_errtabent fdt_errtable[] = { - FDT_ERRTABENT(FDT_ERR_NOTFOUND), - FDT_ERRTABENT(FDT_ERR_EXISTS), - FDT_ERRTABENT(FDT_ERR_NOSPACE), - - FDT_ERRTABENT(FDT_ERR_BADOFFSET), - FDT_ERRTABENT(FDT_ERR_BADPATH), - FDT_ERRTABENT(FDT_ERR_BADSTATE), - - FDT_ERRTABENT(FDT_ERR_TRUNCATED), - FDT_ERRTABENT(FDT_ERR_BADMAGIC), - FDT_ERRTABENT(FDT_ERR_BADVERSION), - FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), - FDT_ERRTABENT(FDT_ERR_BADLAYOUT), -}; -#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) - -const char *fdt_strerror(int errval) -{ - if (errval > 0) - return ""; - else if (errval == 0) - return ""; - else if (errval > -FDT_ERRTABSIZE) { - const char *s = fdt_errtable[-errval].str; - - if (s) - return s; - } - - return ""; -} diff --git a/EmbeddedPkg/Library/FdtLib/fdt_sw.c b/EmbeddedPkg/Library/FdtLib/fdt_sw.c deleted file mode 100644 index 991919b436..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt_sw.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -static int _fdt_sw_check_header(void *fdt) -{ - if (fdt_magic(fdt) != FDT_SW_MAGIC) - return -FDT_ERR_BADMAGIC; - /* FIXME: should check more details about the header state */ - return 0; -} - -#define FDT_SW_CHECK_HEADER(fdt) \ - { \ - int err; \ - if ((err = _fdt_sw_check_header(fdt)) != 0) \ - return err; \ - } - -static void *_fdt_grab_space(void *fdt, size_t len) -{ - int offset = fdt_size_dt_struct(fdt); - int spaceleft; - - spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt) - - fdt_size_dt_strings(fdt); - - if ((offset + len < offset) || (offset + len > spaceleft)) - return NULL; - - fdt_set_size_dt_struct(fdt, offset + len); - return _fdt_offset_ptr_w(fdt, offset); -} - -int fdt_create(void *buf, int bufsize) -{ - void *fdt = buf; - - if (bufsize < sizeof(struct fdt_header)) - return -FDT_ERR_NOSPACE; - - memset(buf, 0, bufsize); - - fdt_set_magic(fdt, FDT_SW_MAGIC); - fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); - fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION); - fdt_set_totalsize(fdt, bufsize); - - fdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header), - sizeof(struct fdt_reserve_entry))); - fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); - fdt_set_off_dt_strings(fdt, bufsize); - - return 0; -} - -int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) -{ - struct fdt_reserve_entry *re; - int offset; - - FDT_SW_CHECK_HEADER(fdt); - - if (fdt_size_dt_struct(fdt)) - return -FDT_ERR_BADSTATE; - - offset = fdt_off_dt_struct(fdt); - if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) - return -FDT_ERR_NOSPACE; - - re = (struct fdt_reserve_entry *)((char *)fdt + offset); - re->address = cpu_to_fdt64(addr); - re->size = cpu_to_fdt64(size); - - fdt_set_off_dt_struct(fdt, offset + sizeof(*re)); - - return 0; -} - -int fdt_finish_reservemap(void *fdt) -{ - return fdt_add_reservemap_entry(fdt, 0, 0); -} - -int fdt_begin_node(void *fdt, const char *name) -{ - struct fdt_node_header *nh; - int namelen = strlen(name) + 1; - - FDT_SW_CHECK_HEADER(fdt); - - nh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); - if (! nh) - return -FDT_ERR_NOSPACE; - - nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); - memcpy(nh->name, name, namelen); - return 0; -} - -int fdt_end_node(void *fdt) -{ - fdt32_t *en; - - FDT_SW_CHECK_HEADER(fdt); - - en = _fdt_grab_space(fdt, FDT_TAGSIZE); - if (! en) - return -FDT_ERR_NOSPACE; - - *en = cpu_to_fdt32(FDT_END_NODE); - return 0; -} - -static int _fdt_find_add_string(void *fdt, const char *s) -{ - char *strtab = (char *)fdt + fdt_totalsize(fdt); - const char *p; - int strtabsize = fdt_size_dt_strings(fdt); - int len = strlen(s) + 1; - int struct_top, offset; - - p = _fdt_find_string(strtab - strtabsize, strtabsize, s); - if (p) - return p - strtab; - - /* Add it */ - offset = -strtabsize - len; - struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); - if (fdt_totalsize(fdt) + offset < struct_top) - return 0; /* no more room :( */ - - memcpy(strtab + offset, s, len); - fdt_set_size_dt_strings(fdt, strtabsize + len); - return offset; -} - -int fdt_property(void *fdt, const char *name, const void *val, int len) -{ - struct fdt_property *prop; - int nameoff; - - FDT_SW_CHECK_HEADER(fdt); - - nameoff = _fdt_find_add_string(fdt, name); - if (nameoff == 0) - return -FDT_ERR_NOSPACE; - - prop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); - if (! prop) - return -FDT_ERR_NOSPACE; - - prop->tag = cpu_to_fdt32(FDT_PROP); - prop->nameoff = cpu_to_fdt32(nameoff); - prop->len = cpu_to_fdt32(len); - memcpy(prop->data, val, len); - return 0; -} - -int fdt_finish(void *fdt) -{ - char *p = (char *)fdt; - fdt32_t *end; - int oldstroffset, newstroffset; - uint32_t tag; - int offset, nextoffset; - - FDT_SW_CHECK_HEADER(fdt); - - /* Add terminator */ - end = _fdt_grab_space(fdt, sizeof(*end)); - if (! end) - return -FDT_ERR_NOSPACE; - *end = cpu_to_fdt32(FDT_END); - - /* Relocate the string table */ - oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt); - newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); - memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt)); - fdt_set_off_dt_strings(fdt, newstroffset); - - /* Walk the structure, correcting string offsets */ - offset = 0; - while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) { - if (tag == FDT_PROP) { - struct fdt_property *prop = - _fdt_offset_ptr_w(fdt, offset); - int nameoff; - - nameoff = fdt32_to_cpu(prop->nameoff); - nameoff += fdt_size_dt_strings(fdt); - prop->nameoff = cpu_to_fdt32(nameoff); - } - offset = nextoffset; - } - if (nextoffset < 0) - return nextoffset; - - /* Finally, adjust the header */ - fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt)); - fdt_set_magic(fdt, FDT_MAGIC); - return 0; -} diff --git a/EmbeddedPkg/Library/FdtLib/fdt_wip.c b/EmbeddedPkg/Library/FdtLib/fdt_wip.c deleted file mode 100644 index 3f2b58172b..0000000000 --- a/EmbeddedPkg/Library/FdtLib/fdt_wip.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "libfdt_env.h" - -#include -#include - -#include "libfdt_internal.h" - -int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, - const void *val, int len) -{ - void *propval; - int proplen; - - propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen); - if (! propval) - return proplen; - - if (proplen != len) - return -FDT_ERR_NOSPACE; - - memcpy(propval, val, len); - return 0; -} - -static void _fdt_nop_region(void *start, int len) -{ - fdt32_t *p; - - for (p = start; (char *)p < ((char *)start + len); p++) - *p = cpu_to_fdt32(FDT_NOP); -} - -int fdt_nop_property(void *fdt, int nodeoffset, const char *name) -{ - struct fdt_property *prop; - int len; - - prop = fdt_get_property_w(fdt, nodeoffset, name, &len); - if (! prop) - return len; - - _fdt_nop_region(prop, len + sizeof(*prop)); - - return 0; -} - -int _fdt_node_end_offset(void *fdt, int offset) -{ - int depth = 0; - - while ((offset >= 0) && (depth >= 0)) - offset = fdt_next_node(fdt, offset, &depth); - - return offset; -} - -int fdt_nop_node(void *fdt, int nodeoffset) -{ - int endoffset; - - endoffset = _fdt_node_end_offset(fdt, nodeoffset); - if (endoffset < 0) - return endoffset; - - _fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0), - endoffset - nodeoffset); - return 0; -} diff --git a/EmbeddedPkg/Library/FdtLib/libfdt_internal.h b/EmbeddedPkg/Library/FdtLib/libfdt_internal.h deleted file mode 100644 index 15456110a3..0000000000 --- a/EmbeddedPkg/Library/FdtLib/libfdt_internal.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef _LIBFDT_INTERNAL_H -#define _LIBFDT_INTERNAL_H -/* - * libfdt - Flat Device Tree manipulation - * Copyright (C) 2006 David Gibson, IBM Corporation. - * - * libfdt is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * - * a) This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Alternatively, - * - * b) Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include - -#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) -#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) - -#define FDT_CHECK_HEADER(fdt) \ - { \ - int err; \ - if ((err = fdt_check_header(fdt)) != 0) \ - return err; \ - } - -int _fdt_check_node_offset(const void *fdt, int offset); -int _fdt_check_prop_offset(const void *fdt, int offset); -const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); -int _fdt_node_end_offset(void *fdt, int nodeoffset); - -static inline const void *_fdt_offset_ptr(const void *fdt, int offset) -{ - return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; -} - -static inline void *_fdt_offset_ptr_w(void *fdt, int offset) -{ - return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset); -} - -static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n) -{ - const struct fdt_reserve_entry *rsv_table = - (const struct fdt_reserve_entry *) - ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); - - return rsv_table + n; -} -static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n) -{ - return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n); -} - -#define FDT_SW_MAGIC (~FDT_MAGIC) - -#endif /* _LIBFDT_INTERNAL_H */ diff --git a/EmbeddedPkg/Library/FdtLib/version.lds b/EmbeddedPkg/Library/FdtLib/version.lds deleted file mode 100644 index 80b322bed6..0000000000 --- a/EmbeddedPkg/Library/FdtLib/version.lds +++ /dev/null @@ -1,60 +0,0 @@ -LIBFDT_1.2 { - global: - fdt_next_node; - fdt_check_header; - fdt_move; - fdt_string; - fdt_num_mem_rsv; - fdt_get_mem_rsv; - fdt_subnode_offset_namelen; - fdt_subnode_offset; - fdt_path_offset; - fdt_get_name; - fdt_get_property_namelen; - fdt_get_property; - fdt_getprop_namelen; - fdt_getprop; - fdt_get_phandle; - fdt_get_alias_namelen; - fdt_get_alias; - fdt_get_path; - fdt_supernode_atdepth_offset; - fdt_node_depth; - fdt_parent_offset; - fdt_node_offset_by_prop_value; - fdt_node_offset_by_phandle; - fdt_node_check_compatible; - fdt_node_offset_by_compatible; - fdt_setprop_inplace; - fdt_nop_property; - fdt_nop_node; - fdt_create; - fdt_add_reservemap_entry; - fdt_finish_reservemap; - fdt_begin_node; - fdt_property; - fdt_end_node; - fdt_finish; - fdt_open_into; - fdt_pack; - fdt_add_mem_rsv; - fdt_del_mem_rsv; - fdt_set_name; - fdt_setprop; - fdt_delprop; - fdt_add_subnode_namelen; - fdt_add_subnode; - fdt_del_node; - fdt_strerror; - fdt_offset_ptr; - fdt_next_tag; - fdt_appendprop; - fdt_create_empty_tree; - fdt_first_property_offset; - fdt_get_property_by_offset; - fdt_getprop_by_offset; - fdt_next_property_offset; - - local: - *; -}; diff --git a/EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.S b/EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.S deleted file mode 100755 index df1543a6d2..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.S +++ /dev/null @@ -1,258 +0,0 @@ -#------------------------------------------------------------------------------ -# -# Use ARMv6 instruction to operate on a single stack -# -# Copyright (c) 2008 - 2010, Apple Inc. 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. -# -#------------------------------------------------------------------------------ - -/* - -This is the stack constructed by the exception handler (low address to high address) - # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM - Reg Offset - === ====== - R0 0x00 # stmfd SP!,{R0-R12} - R1 0x04 - R2 0x08 - R3 0x0c - R4 0x10 - R5 0x14 - R6 0x18 - R7 0x1c - R8 0x20 - R9 0x24 - R10 0x28 - R11 0x2c - R12 0x30 - SP 0x34 # reserved via adding 0x20 (32) to the SP - LR 0x38 - PC 0x3c - CPSR 0x40 - DFSR 0x44 - DFAR 0x48 - IFSR 0x4c - IFAR 0x50 - - LR 0x54 # SVC Link register (we need to restore it) - - LR 0x58 # pushed by srsfd - CPSR 0x5c - - */ - - -GCC_ASM_EXPORT(ExceptionHandlersStart) -GCC_ASM_EXPORT(ExceptionHandlersEnd) -GCC_ASM_EXPORT(CommonExceptionEntry) -GCC_ASM_EXPORT(AsmCommonExceptionEntry) -GCC_ASM_EXPORT(GdbExceptionHandler) - -.text -.align 3 - - -// -// This code gets copied to the ARM vector table -// ExceptionHandlersStart - ExceptionHandlersEnd gets copied -// -ASM_PFX(ExceptionHandlersStart): - -ASM_PFX(Reset): - b ASM_PFX(Reset) - -ASM_PFX(UndefinedInstruction): - b ASM_PFX(UndefinedInstructionEntry) - -ASM_PFX(SoftwareInterrupt): - b ASM_PFX(SoftwareInterruptEntry) - -ASM_PFX(PrefetchAbort): - b ASM_PFX(PrefetchAbortEntry) - -ASM_PFX(DataAbort): - b ASM_PFX(DataAbortEntry) - -ASM_PFX(ReservedException): - b ASM_PFX(ReservedExceptionEntry) - -ASM_PFX(Irq): - b ASM_PFX(Irq) - -ASM_PFX(Fiq): - b ASM_PFX(FiqEntry) - - -ASM_PFX(UndefinedInstructionEntry): - sub LR, LR, #4 @ Only -2 for Thumb, adjust in CommonExceptionEntry - srsdb #0x13! @ Store return state on SVC stack - cpsid f,#0x13 @ Switch to SVC for common stack - stmfd SP!,{LR} @ Store the link register for the current mode - sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} @ Store the register state - - mov R0,#1 @ ExceptionType - ldr R1,ASM_PFX(CommonExceptionEntry) - bx R1 - -ASM_PFX(SoftwareInterruptEntry): - sub LR, LR, #4 @ Only -2 for Thumb, adjust in CommonExceptionEntry - srsdb #0x13! @ Store return state on SVC stack - cpsid f @ We are already in SVC mode - stmfd SP!,{LR} @ Store the link register for the current mode - sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} @ Store the register state - - mov R0,#2 @ ExceptionType - ldr R1,ASM_PFX(CommonExceptionEntry) - bx R1 - -ASM_PFX(PrefetchAbortEntry): - sub LR,LR,#4 - srsdb #0x13! @ Store return state on SVC stack - cpsid f,#0x13 @ Switch to SVC for common stack - stmfd SP!,{LR} @ Store the link register for the current mode - sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} @ Store the register state - - mov R0,#3 @ ExceptionType - ldr R1,ASM_PFX(CommonExceptionEntry) - bx R1 - -ASM_PFX(DataAbortEntry): - sub LR,LR,#8 - srsdb #0x13! @ Store return state on SVC stack - cpsid f,#0x13 @ Switch to SVC for common stack - stmfd SP!,{LR} @ Store the link register for the current mode - sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} @ Store the register state - - mov R0,#4 - ldr R1,ASM_PFX(CommonExceptionEntry) - bx R1 - -ASM_PFX(ReservedExceptionEntry): - srsdb #0x13! @ Store return state on SVC stack - cpsid f,#0x13 @ Switch to SVC for common stack - stmfd SP!,{LR} @ Store the link register for the current mode - sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} @ Store the register state - - mov R0,#5 - ldr R1,ASM_PFX(CommonExceptionEntry) - bx R1 - -ASM_PFX(FiqEntry): - sub LR,LR,#4 - srsdb #0x13! @ Store return state on SVC stack - cps #0x13 @ Switch to SVC for common stack - stmfd SP!,{LR} @ Store the link register for the current mode - sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} @ Store the register state - @ Since we have already switch to SVC R8_fiq - R12_fiq - @ never get used or saved - mov R0,#7 @ ExceptionType - ldr R1,ASM_PFX(CommonExceptionEntry) - bx R1 - -// -// This gets patched by the C code that patches in the vector table -// -ASM_PFX(CommonExceptionEntry): - .byte 0x12 - .byte 0x34 - .byte 0x56 - .byte 0x78 - -ASM_PFX(ExceptionHandlersEnd): - -// -// This code runs from CpuDxe driver loaded address. It is patched into -// CommonExceptionEntry. -// -ASM_PFX(AsmCommonExceptionEntry): - mrc p15, 0, R1, c6, c0, 2 @ Read IFAR - str R1, [SP, #0x50] @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR - - mrc p15, 0, R1, c5, c0, 1 @ Read IFSR - str R1, [SP, #0x4c] @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR - - mrc p15, 0, R1, c6, c0, 0 @ Read DFAR - str R1, [SP, #0x48] @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR - - mrc p15, 0, R1, c5, c0, 0 @ Read DFSR - str R1, [SP, #0x44] @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR - - ldr R1, [SP, #0x5c] @ srsdb saved pre-exception CPSR on the stack - str R1, [SP, #0x40] @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR - - add R2, SP, #0x38 @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR - and R3, R1, #0x1f @ Check CPSR to see if User or System Mode - cmp R3, #0x1f @ if ((CPSR == 0x10) || (CPSR == 0x1df)) - cmpne R3, #0x10 @ - stmeqed R2, {lr}^ @ save unbanked lr - @ else - stmneed R2, {lr} @ save SVC lr - - - ldr R5, [SP, #0x58] @ PC is the LR pushed by srsfd - @ Check to see if we have to adjust for Thumb entry - sub r4, r0, #1 @ if (ExceptionType == 1 || ExceptionType ==2)) { - cmp r4, #1 @ // UND & SVC have differnt LR adjust for Thumb - bhi NoAdjustNeeded - - tst r1, #0x20 @ if ((CPSR & T)) == T) { // Thumb Mode on entry - addne R5, R5, #2 @ PC += 2@ - str R5,[SP,#0x58] @ Update LR value pused by srsfd - -NoAdjustNeeded: - - str R5, [SP, #0x3c] @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC - - sub R1, SP, #0x60 @ We pused 0x60 bytes on the stack - str R1, [SP, #0x34] @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP - - @ R0 is ExceptionType - mov R1,SP @ R1 is SystemContext - -/* -VOID -EFIAPI -GdbExceptionHandler ( - IN EFI_EXCEPTION_TYPE ExceptionType, R0 - IN OUT EFI_SYSTEM_CONTEXT SystemContext R1 - ) - -*/ - blx ASM_PFX(GdbExceptionHandler) @ Call exception handler - - ldr R1,[SP,#0x3c] @ EFI_SYSTEM_CONTEXT_ARM.PC - str R1,[SP,#0x58] @ Store it back to srsfd stack slot so it can be restored - - ldr R1,[SP,#0x40] @ EFI_SYSTEM_CONTEXT_ARM.CPSR - str R1,[SP,#0x5c] @ Store it back to srsfd stack slot so it can be restored - - add R3, SP, #0x54 @ Make R3 point to SVC LR saved on entry - add R2, SP, #0x38 @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR - and R1, R1, #0x1f @ Check to see if User or System Mode - cmp R1, #0x1f @ if ((CPSR == 0x10) || (CPSR == 0x1f)) - cmpne R1, #0x10 @ - ldmeqed R2, {lr}^ @ restore unbanked lr - @ else - ldmneed R3, {lr} @ restore SVC lr, via ldmfd SP!, {LR} - - ldmfd SP!,{R0-R12} @ Restore general purpose registers - @ Exception handler can not change SP - - add SP,SP,#0x20 @ Clear out the remaining stack space - ldmfd SP!,{LR} @ restore the link register for this context - rfefd SP! @ return from exception via srsfd stack slot - diff --git a/EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.asm b/EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.asm deleted file mode 100755 index 611e83d7da..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/Arm/ExceptionSupport.ARMv6.asm +++ /dev/null @@ -1,259 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Use ARMv6 instruction to operate on a single stack -// -// Copyright (c) 2008 - 2010, Apple Inc. 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. -// -//------------------------------------------------------------------------------ - - - -/* - -This is the stack constructed by the exception handler (low address to high address) - # R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM - Reg Offset - === ====== - R0 0x00 # stmfd SP!,{R0-R12} - R1 0x04 - R2 0x08 - R3 0x0c - R4 0x10 - R5 0x14 - R6 0x18 - R7 0x1c - R8 0x20 - R9 0x24 - R10 0x28 - R11 0x2c - R12 0x30 - SP 0x34 # reserved via adding 0x20 (32) to the SP - LR 0x38 - PC 0x3c - CPSR 0x40 - DFSR 0x44 - DFAR 0x48 - IFSR 0x4c - IFAR 0x50 - - LR 0x54 # SVC Link register (we need to restore it) - - LR 0x58 # pushed by srsfd - CPSR 0x5c - - */ - - - EXPORT ExceptionHandlersStart - EXPORT ExceptionHandlersEnd - EXPORT CommonExceptionEntry - EXPORT AsmCommonExceptionEntry - IMPORT GdbExceptionHandler - - PRESERVE8 - AREA DxeExceptionHandlers, CODE, READONLY - -// -// This code gets copied to the ARM vector table -// ExceptionHandlersStart - ExceptionHandlersEnd gets copied -// -ExceptionHandlersStart - -Reset - b Reset - -UndefinedInstruction - b UndefinedInstructionEntry - -SoftwareInterrupt - b SoftwareInterruptEntry - -PrefetchAbort - b PrefetchAbortEntry - -DataAbort - b DataAbortEntry - -ReservedException - b ReservedExceptionEntry - -Irq - b Irq - -Fiq - b FiqEntry - - -UndefinedInstructionEntry - sub LR, LR, #4 ; Only -2 for Thumb, adjust in CommonExceptionEntry - srsfd #0x13! ; Store return state on SVC stack - cpsid f, #0x13 ; Switch to SVC for common stack - stmfd SP!,{LR} ; Store the link register for the current mode - sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} ; Store the register state - - mov R0,#1 ; ExceptionType - ldr R1,CommonExceptionEntry; - bx R1 - -SoftwareInterruptEntry - sub LR, LR, #4 ; Only -2 for Thumb, adjust in CommonExceptionEntry - srsfd #0x13! ; Store return state on SVC stack - cpsid f ; We are already in SVC mode - stmfd SP!,{LR} ; Store the link register for the current mode - sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} ; Store the register state - - mov R0,#2 ; ExceptionType - ldr R1,CommonExceptionEntry - bx R1 - -PrefetchAbortEntry - sub LR,LR,#4 - srsfd #0x13! ; Store return state on SVC stack - cpsid f, #0x13 ; Switch to SVC for common stack - stmfd SP!,{LR} ; Store the link register for the current mode - sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} ; Store the register state - - mov R0,#3 ; ExceptionType - ldr R1,CommonExceptionEntry - bx R1 - -DataAbortEntry - sub LR,LR,#8 - srsfd #0x13! ; Store return state on SVC stack - cpsid f, #0x13 ; Switch to SVC for common stack - stmfd SP!,{LR} ; Store the link register for the current mode - sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} ; Store the register state - - mov R0,#4 ; ExceptionType - ldr R1,CommonExceptionEntry - bx R1 - -ReservedExceptionEntry - srsfd #0x13! ; Store return state on SVC stack - cpsid f, #0x13 ; Switch to SVC for common stack - stmfd SP!,{LR} ; Store the link register for the current mode - sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} ; Store the register state - - mov R0,#5 ; ExceptionType - ldr R1,CommonExceptionEntry - bx R1 - -FiqEntry - sub LR,LR,#4 - srsfd #0x13! ; Store return state on SVC stack - cps #0x13 ; Switch to SVC for common stack - stmfd SP!,{LR} ; Store the link register for the current mode - sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR - stmfd SP!,{R0-R12} ; Store the register state - ; Since we have already switch to SVC R8_fiq - R12_fiq - ; never get used or saved - mov R0,#7 ; ExceptionType - ldr R1,CommonExceptionEntry - bx R1 - -// -// This gets patched by the C code that patches in the vector table -// -CommonExceptionEntry - dcd 0x12345678 - -ExceptionHandlersEnd - -// -// This code runs from CpuDxe driver loaded address. It is patched into -// CommonExceptionEntry. -// -AsmCommonExceptionEntry - mrc p15, 0, R1, c6, c0, 2 ; Read IFAR - str R1, [SP, #0x50] ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR - - mrc p15, 0, R1, c5, c0, 1 ; Read IFSR - str R1, [SP, #0x4c] ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR - - mrc p15, 0, R1, c6, c0, 0 ; Read DFAR - str R1, [SP, #0x48] ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR - - mrc p15, 0, R1, c5, c0, 0 ; Read DFSR - str R1, [SP, #0x44] ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR - - ldr R1, [SP, #0x5c] ; srsfd saved pre-exception CPSR on the stack - str R1, [SP, #0x40] ; Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR - - add R2, SP, #0x38 ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR - and R3, R1, #0x1f ; Check CPSR to see if User or System Mode - cmp R3, #0x1f ; if ((CPSR == 0x10) || (CPSR == 0x1df)) - cmpne R3, #0x10 ; - stmeqed R2, {lr}^ ; save unbanked lr - ; else - stmneed R2, {lr} ; save SVC lr - - - ldr R5, [SP, #0x58] ; PC is the LR pushed by srsfd - ; Check to see if we have to adjust for Thumb entry - sub r4, r0, #1 ; if (ExceptionType == 1 || ExceptionType ==2)) { - cmp r4, #1 ; // UND & SVC have differnt LR adjust for Thumb - bhi NoAdjustNeeded - - tst r1, #0x20 ; if ((CPSR & T)) == T) { // Thumb Mode on entry - addne R5, R5, #2 ; PC += 2; - str R5,[SP,#0x58] ; Update LR value pused by srsfd - -NoAdjustNeeded - - str R5, [SP, #0x3c] ; Store it in EFI_SYSTEM_CONTEXT_ARM.PC - - sub R1, SP, #0x60 ; We pused 0x60 bytes on the stack - str R1, [SP, #0x34] ; Store it in EFI_SYSTEM_CONTEXT_ARM.SP - - ; R0 is ExceptionType - mov R1,SP ; R1 is SystemContext - -/* -VOID -EFIAPI -GdbExceptionHandler ( - IN EFI_EXCEPTION_TYPE ExceptionType, R0 - IN OUT EFI_SYSTEM_CONTEXT SystemContext R1 - ) - -*/ - blx GdbExceptionHandler ; Call exception handler - - ldr R1,[SP,#0x3c] ; EFI_SYSTEM_CONTEXT_ARM.PC - str R1,[SP,#0x58] ; Store it back to srsfd stack slot so it can be restored - - ldr R1,[SP,#0x40] ; EFI_SYSTEM_CONTEXT_ARM.CPSR - str R1,[SP,#0x5c] ; Store it back to srsfd stack slot so it can be restored - - add R3, SP, #0x54 ; Make R3 point to SVC LR saved on entry - add R2, SP, #0x38 ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR - and R1, R1, #0x1f ; Check to see if User or System Mode - cmp R1, #0x1f ; if ((CPSR == 0x10) || (CPSR == 0x1f)) - cmpne R1, #0x10 ; - ldmeqed R2, {lr}^ ; restore unbanked lr - ; else - ldmneed R3, {lr} ; restore SVC lr, via ldmfd SP!, {LR} - - ldmfd SP!,{R0-R12} ; Restore general purpose registers - ; Exception handler can not change SP - - add SP,SP,#0x20 ; Clear out the remaining stack space - ldmfd SP!,{LR} ; restore the link register for this context - rfefd SP! ; return from exception via srsfd stack slot - - END - - diff --git a/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c b/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c deleted file mode 100755 index 61c6184fae..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c +++ /dev/null @@ -1,675 +0,0 @@ -/** @file - Processor specific parts of the GDB stub - - Copyright (c) 2008 - 2010, Apple Inc. 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. - -**/ - - -#include -#include -#include - -// -// Externs from the exception handler assembly file -// -VOID -ExceptionHandlersStart ( - VOID - ); - -VOID -ExceptionHandlersEnd ( - VOID - ); - -VOID -CommonExceptionEntry ( - VOID - ); - -VOID -AsmCommonExceptionEntry ( - VOID - ); - - -// -// Array of exception types that need to be hooked by the debugger -// (efi, gdb) //efi number -// -EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = { - { EXCEPT_ARM_SOFTWARE_INTERRUPT, GDB_SIGTRAP }, - { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP }, - { EXCEPT_ARM_PREFETCH_ABORT, GDB_SIGTRAP }, - { EXCEPT_ARM_DATA_ABORT, GDB_SIGTRAP }, // GDB_SIGEMT - { EXCEPT_ARM_RESERVED, GDB_SIGTRAP }, // GDB_SIGILL - { EXCEPT_ARM_FIQ, GDB_SIGINT } // Used for ctrl-c -}; - -// Shut up some annoying RVCT warnings -#ifdef __CC_ARM -#pragma diag_suppress 1296 -#endif - -UINTN gRegisterOffsets[] = { - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R0), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R1), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R2), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R3), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R4), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R5), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R6), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R7), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R8), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R9), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R10), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R11), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R12), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, SP), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, LR), - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, PC), - 0x00000F01, // f0 - 0x00000F02, - 0x00000F03, - 0x00000F11, // f1 - 0x00000F12, - 0x00000F13, - 0x00000F21, // f2 - 0x00000F22, - 0x00000F23, - 0x00000F31, // f3 - 0x00000F32, - 0x00000F33, - 0x00000F41, // f4 - 0x00000F42, - 0x00000F43, - 0x00000F51, // f5 - 0x00000F52, - 0x00000F53, - 0x00000F61, // f6 - 0x00000F62, - 0x00000F63, - 0x00000F71, // f7 - 0x00000F72, - 0x00000F73, - 0x00000FFF, // fps - OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, CPSR) -}; - -// restore warnings for RVCT -#ifdef __CC_ARM -#pragma diag_default 1296 -#endif - - -/** - Return the number of entries in the gExceptionType[] - - @retval UINTN, the number of entries in the gExceptionType[] array. - **/ -UINTN -MaxEfiException ( - VOID - ) -{ - return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY); -} - - - - -/** - Check to see if the ISA is supported. - ISA = Instruction Set Architecture - - @retval TRUE if Isa is supported - -**/ -BOOLEAN -CheckIsa ( - IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa - ) -{ - if (Isa == IsaArm) { - return TRUE; - } else { - return FALSE; - } -} - - -/** - This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering - It is, by default, set to find the register pointer of the ARM member - @param SystemContext Register content at time of the exception - @param RegNumber The register to which we want to find a pointer - @retval the pointer to the RegNumber-th pointer - **/ -UINTN * -FindPointerToRegister( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber - ) -{ - UINT8 *TempPtr; - ASSERT(gRegisterOffsets[RegNumber] < 0xF00); - TempPtr = ((UINT8 *)SystemContext.SystemContextArm) + gRegisterOffsets[RegNumber]; - return (UINT32 *)TempPtr; -} - - -/** - Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr - @param SystemContext Register content at time of the exception - @param RegNumber the number of the register that we want to read - @param OutBufPtr pointer to the output buffer's end. the new data will be added from this point on. - @retval the pointer to the next character of the output buffer that is available to be written on. - **/ -CHAR8 * -BasicReadRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *OutBufPtr - ) -{ - UINTN RegSize; - CHAR8 Char; - - if (gRegisterOffsets[RegNumber] > 0xF00) { - AsciiSPrint(OutBufPtr, 9, "00000000"); - OutBufPtr += 8; - return OutBufPtr; - } - - RegSize = 0; - while (RegSize < 32) { - Char = mHexToStr[(UINT8)((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)]; - if ((Char >= 'A') && (Char <= 'F')) { - Char = Char - 'A' + 'a'; - } - *OutBufPtr++ = Char; - - Char = mHexToStr[(UINT8)((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)]; - if ((Char >= 'A') && (Char <= 'F')) { - Char = Char - 'A' + 'a'; - } - *OutBufPtr++ = Char; - - RegSize = RegSize + 8; - } - return OutBufPtr; -} - - -/** - Reads the n-th register's value into an output buffer and sends it as a packet - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ -VOID -ReadNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN RegNumber; - CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq) - CHAR8 *OutBufPtr; // pointer to the output buffer - - RegNumber = AsciiStrHexToUintn (&InBuffer[1]); - - if (RegNumber >= (sizeof (gRegisterOffsets)/sizeof (UINTN))) { - SendError (GDB_EINVALIDREGNUM); - return; - } - - OutBufPtr = OutBuffer; - OutBufPtr = BasicReadRegister (SystemContext, RegNumber, OutBufPtr); - - *OutBufPtr = '\0'; // the end of the buffer - SendPacket(OutBuffer); -} - - -/** - Reads the general registers into an output buffer and sends it as a packet - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -ReadGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - UINTN Index; - // a UINT32 takes 8 ascii characters - CHAR8 OutBuffer[(sizeof (gRegisterOffsets) * 2) + 1]; - CHAR8 *OutBufPtr; - - // It is not safe to allocate pool here.... - OutBufPtr = OutBuffer; - for (Index = 0; Index < (sizeof (gRegisterOffsets)/sizeof (UINTN)); Index++) { - OutBufPtr = BasicReadRegister (SystemContext, Index, OutBufPtr); - } - - *OutBufPtr = '\0'; - SendPacket(OutBuffer); -} - - -/** - Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr - @param SystemContext Register content at time of the exception - @param RegNumber the number of the register that we want to write - @param InBufPtr pointer to the output buffer. the new data will be extracted from the input buffer from this point on. - @retval the pointer to the next character of the input buffer that can be used - **/ -CHAR8 * -BasicWriteRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *InBufPtr - ) -{ - UINTN RegSize; - UINTN TempValue; // the value transferred from a hex char - UINT32 NewValue; // the new value of the RegNumber-th Register - - if (gRegisterOffsets[RegNumber] > 0xF00) { - return InBufPtr + 8; - } - - NewValue = 0; - RegSize = 0; - while (RegSize < 32) { - TempValue = HexCharToInt(*InBufPtr++); - - if ((INTN)TempValue < 0) { - SendError (GDB_EBADMEMDATA); - return NULL; - } - - NewValue += (TempValue << (RegSize+4)); - TempValue = HexCharToInt(*InBufPtr++); - - if ((INTN)TempValue < 0) { - SendError (GDB_EBADMEMDATA); - return NULL; - } - - NewValue += (TempValue << RegSize); - RegSize = RegSize + 8; - } - *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue; - return InBufPtr; -} - - -/** ‘P n...=r...’ - Writes the new value of n-th register received into the input buffer to the n-th register - @param SystemContext Register content at time of the exception - @param InBuffer Ponter to the input buffer received from gdb server - **/ -VOID -WriteNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN RegNumber; - CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array - CHAR8 *RegNumBufPtr; - CHAR8 *InBufPtr; // pointer to the input buffer - - // find the register number to write - InBufPtr = &InBuffer[1]; - RegNumBufPtr = RegNumBuffer; - while (*InBufPtr != '=') { - *RegNumBufPtr++ = *InBufPtr++; - } - *RegNumBufPtr = '\0'; - RegNumber = AsciiStrHexToUintn (RegNumBuffer); - - // check if this is a valid Register Number - if (RegNumber >= (sizeof (gRegisterOffsets)/sizeof (UINTN))) { - SendError (GDB_EINVALIDREGNUM); - return; - } - InBufPtr++; // skips the '=' character - BasicWriteRegister (SystemContext, RegNumber, InBufPtr); - SendSuccess(); -} - - -/** ‘G XX...’ - Writes the new values received into the input buffer to the general registers - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ - -VOID -EFIAPI -WriteGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN i; - CHAR8 *InBufPtr; /// pointer to the input buffer - UINTN MinLength; - UINTN RegisterCount = (sizeof (gRegisterOffsets)/sizeof (UINTN)); - - MinLength = (RegisterCount * 8) + 1; // 'G' plus the registers in ASCII format - - if (AsciiStrLen(InBuffer) < MinLength) { - //Bad message. Message is not the right length - SendError (GDB_EBADBUFSIZE); - return; - } - - InBufPtr = &InBuffer[1]; - - // Read the new values for the registers from the input buffer to an array, NewValueArray. - // The values in the array are in the gdb ordering - for(i = 0; i < RegisterCount; i++) { - InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr); - } - - SendSuccess (); -} - - - - -/** - Continue. addr is Address to resume. If addr is omitted, resume at current - Address. - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -ContinueAtAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - if (PacketData[1] != '\0') { - SystemContext.SystemContextArm->PC = AsciiStrHexToUintn(&PacketData[1]); - } -} - - -/** ‘s [addr ]’ - Single step. addr is the Address at which to resume. If addr is omitted, resume - at same Address. - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -SingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - SendNotSupported(); -} - - -VOID -EFIAPI -InsertBreakPoint ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - SendNotSupported (); -} - -VOID -EFIAPI -RemoveBreakPoint ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - SendNotSupported (); -} - - -/** - Send the T signal with the given exception type (in gdb order) and possibly - with n:r pairs related to the watchpoints - - @param SystemContext Register content at time of the exception - @param GdbExceptionType GDB exception type - **/ -VOID -ProcessorSendTSignal ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINT8 GdbExceptionType, - IN OUT CHAR8 *TSignalPtr, - IN UINTN SizeOfBuffer - ) -{ - *TSignalPtr = '\0'; -} - -/** - FIQ state is only changed by FIQ exception. We don't want to take FIQ - ticks in the GDB stub. The stub disables FIQ on entry, but this is the - third instruction that executes in the execption handler. Thus we have - a crack we need to test for. - - @param PC PC of execption - - @return TRUE We are in the GDB stub exception preamble - @return FALSE We are not in GDB stub code - **/ -BOOLEAN -InFiqCrack ( - IN UINT32 PC - ) -{ - UINT32 VectorBase = PcdGet32 (PcdCpuVectorBaseAddress); - UINT32 Length = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart; - - if ((PC >= VectorBase) && (PC <= (VectorBase + Length))) { - return TRUE; - } - - return FALSE; -} - - -/** - Check to see if this exception is related to ctrl-c handling. - - In this scheme we dedicate FIQ to the ctrl-c handler so it is - independent of the rest of the system. - - SaveAndSetDebugTimerInterrupt () can be used to - - @param ExceptionType Exception that is being processed - @param SystemContext Register content at time of the exception - - @return TRUE This was a ctrl-c check that did not find a ctrl-c - @return FALSE This was not a ctrl-c check or some one hit ctrl-c - **/ -BOOLEAN -ProcessorControlC ( - IN EFI_EXCEPTION_TYPE ExceptionType, - IN OUT EFI_SYSTEM_CONTEXT SystemContext - ) -{ - CHAR8 Char; - BOOLEAN Return = TRUE; - - if (ExceptionType != EXCEPT_ARM_FIQ) { - // Skip it as it is not related to ctrl-c - return FALSE; - } - - if (InFiqCrack (SystemContext.SystemContextArm->PC)) { - // We are in our own interrupt preable, so skip this tick. - // We never want to let gdb see the debug stub running if we can help it - return FALSE; - } - - while (TRUE) { - if (!GdbIsCharAvailable ()) { - // - // No characters are pending so exit the loop - // - Return = TRUE; - break; - } - - Char = GdbGetChar (); - if (Char == 0x03) { - // - // We have a ctrl-c so exit and process exception for ctrl-c - // - Return = FALSE; - break; - } - } - - DebugAgentTimerEndOfInterrupt (); - - // Force an exit from the exception handler as we are done - return Return; -} - - -/** - Enable/Disable the interrupt of debug timer and return the interrupt state - prior to the operation. - - If EnableStatus is TRUE, enable the interrupt of debug timer. - If EnableStatus is FALSE, disable the interrupt of debug timer. - - @param[in] EnableStatus Enable/Disable. - - @retval TRUE Debug timer interrupt were enabled on entry to this call. - @retval FALSE Debug timer interrupt were disabled on entry to this call. - -**/ -BOOLEAN -EFIAPI -SaveAndSetDebugTimerInterrupt ( - IN BOOLEAN EnableStatus - ) -{ - BOOLEAN FiqEnabled; - - FiqEnabled = ArmGetFiqState (); - - if (EnableStatus) { - DebugAgentTimerSetPeriod (PcdGet32 (PcdGdbTimerPeriodMilliseconds)); - ArmEnableFiq (); - } else { - DebugAgentTimerSetPeriod (0); - ArmDisableFiq (); - } - - return FiqEnabled; -} - - - -VOID -GdbFPutString ( - IN CHAR8 *String - ); - -/** - Initialize debug agent. - - This function is used to set up debug environment to support source level debugging. - If certain Debug Agent Library instance has to save some private data in the stack, - this function must work on the mode that doesn't return to the caller, then - the caller needs to wrap up all rest of logic after InitializeDebugAgent() into one - function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is - responsible to invoke the passing-in function at the end of InitializeDebugAgent(). - - If the parameter Function is not NULL, Debug Agent Libary instance will invoke it by - passing in the Context to be its parameter. - - If Function() is NULL, Debug Agent Library instance will return after setup debug - environment. - - @param[in] InitFlag Init flag is used to decide the initialize process. - @param[in] Context Context needed according to InitFlag; it was optional. - @param[in] Function Continue function called by debug agent library; it was - optional. - -**/ -VOID -EFIAPI -InitializeDebugAgent ( - IN UINT32 InitFlag, - IN VOID *Context, OPTIONAL - IN DEBUG_AGENT_CONTINUE Function OPTIONAL - ) -{ - UINTN Offset; - UINTN Length; - BOOLEAN IrqEnabled; - UINT32 *VectorBase; - - - // - // Disable interrupts - // - IrqEnabled = ArmGetInterruptState (); - ArmDisableInterrupts (); - ArmDisableFiq (); - - // - // Copy an implementation of the ARM exception vectors to PcdCpuVectorBaseAddress. - // - Length = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart; - - // - // Reserve space for the exception handlers - // - VectorBase = (UINT32 *)(UINTN)PcdGet32 (PcdCpuVectorBaseAddress); - - - // Copy our assembly code into the page that contains the exception vectors. - CopyMem ((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length); - - // - // Patch in the common Assembly exception handler - // - Offset = (UINTN)CommonExceptionEntry - (UINTN)ExceptionHandlersStart; - *(UINTN *) (((UINT8 *)VectorBase) + Offset) = (UINTN)AsmCommonExceptionEntry; - - // Flush Caches since we updated executable stuff - InvalidateInstructionCacheRange ((VOID *)PcdGet32(PcdCpuVectorBaseAddress), Length); - - // setup a timer so gdb can break in via ctrl-c - DebugAgentTimerIntialize (); - - if (IrqEnabled) { - ArmEnableInterrupts (); - } - - if (Function != NULL) { - Function (Context); - } - - return; -} - diff --git a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c b/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c deleted file mode 100755 index 2e67de6f99..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.c +++ /dev/null @@ -1,815 +0,0 @@ -/** @file - Debug Agent library implementition with empty functions. - - Copyright (c) 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. - -**/ - -#include "GdbDebugAgent.h" - - -UINTN gMaxProcessorIndex = 0; - -// -// Buffers for basic gdb communication -// -CHAR8 gInBuffer[MAX_BUF_SIZE]; -CHAR8 gOutBuffer[MAX_BUF_SIZE]; - - -// -// Globals for returning XML from qXfer:libraries:read packet -// -UINTN gPacketqXferLibraryOffset = 0; -UINTN gEfiDebugImageTableEntry = 0; -CHAR8 gXferLibraryBuffer[2000]; - -GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; - - -// add-symbol-file c:/work/edk2/Build/BeagleBoard/DEBUG_GCC48/ARM/BeagleBoardPkg/Sec/Sec/DEBUG/BeagleBoardSec.dll 0x80008360 -CHAR8 *qXferHack = ""; - -UINTN -gXferObjectReadResponse ( - IN CHAR8 Type, - IN CHAR8 *Str - ) -{ - CHAR8 *OutBufPtr; // pointer to the output buffer - CHAR8 Char; - UINTN Count; - - // responce starts with 'm' or 'l' if it is the end - OutBufPtr = gOutBuffer; - *OutBufPtr++ = Type; - Count = 1; - - // Binary data encoding - OutBufPtr = gOutBuffer; - while (*Str != '\0') { - Char = *Str++; - if ((Char == 0x7d) || (Char == 0x23) || (Char == 0x24) || (Char == 0x2a)) { - // escape character - *OutBufPtr++ = 0x7d; - - Char ^= 0x20; - } - *OutBufPtr++ = Char; - Count++; - } - - *OutBufPtr = '\0' ; // the end of the buffer - SendPacket (gOutBuffer); - - return Count; -} - -/** - Process "qXfer:object:read:annex:offset,length" request. - - Returns an XML document that contains loaded libraries. In our case it is - infomration in the EFI Debug Inmage Table converted into an XML document. - - GDB will call with an arbitrary length (it can't know the real length and - will reply with chunks of XML that are easy for us to deal with. Gdb will - keep calling until we say we are done. XML doc looks like: - - - - - - - - Since we can not allocate memory in interupt context this module has - assumptions about how it will get called: - 1) Length will generally be max remote packet size (big enough) - 2) First Offset of an XML document read needs to be 0 - 3) This code will return back small chunks of the XML document on every read. - Each subseqent call will ask for the next availble part of the document. - - Note: The only variable size element in the XML is: - " \n" and it is - based on the file path and name of the symbol file. If the symbol file name - is bigger than the max gdb remote packet size we could update this code - to respond back in chunks. - - @param Offset offset into special data area - @param Length number of bytes to read starting at Offset - - **/ -VOID -QxferLibrary ( - IN UINTN Offset, - IN UINTN Length - ) -{ - gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', "\n"); - gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', qXferHack); - gXferObjectReadResponse ('l', "\n"); - gPacketqXferLibraryOffset = 0; -} - -/** - Transfer length bytes of input buffer, starting at Address, to memory. - - @param length the number of the bytes to be transferred/written - @param *address the start address of the transferring/writing the memory - @param *new_data the new data to be written to memory - **/ - -VOID -TransferFromInBufToMem ( - IN UINTN Length, - IN unsigned char *Address, - IN CHAR8 *NewData - ) -{ - CHAR8 c1; - CHAR8 c2; - - while (Length-- > 0) { - c1 = (CHAR8)HexCharToInt (*NewData++); - c2 = (CHAR8)HexCharToInt (*NewData++); - - if ((c1 < 0) || (c2 < 0)) { - SendError (GDB_EBADMEMDATA); - return; - } - *Address++ = (UINT8)((c1 << 4) + c2); - } - - SendSuccess(); -} - - -/** - Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer - as a packet. - - @param Length the number of the bytes to be transferred/read - @param *address pointer to the start address of the transferring/reading the memory - **/ - -VOID -TransferFromMemToOutBufAndSend ( - IN UINTN Length, - IN unsigned char *Address - ) -{ - // there are Length bytes and every byte is represented as 2 hex chars - CHAR8 OutBuffer[MAX_BUF_SIZE]; - CHAR8 *OutBufPtr; // pointer to the output buffer - CHAR8 Char; - - OutBufPtr = OutBuffer; - while (Length > 0) { - - Char = mHexToStr[*Address >> 4]; - if ((Char >= 'A') && (Char <= 'F')) { - Char = Char - 'A' + 'a'; - } - *OutBufPtr++ = Char; - - Char = mHexToStr[*Address & 0x0f]; - if ((Char >= 'A') && (Char <= 'F')) { - Char = Char - 'A' + 'a'; - } - *OutBufPtr++ = Char; - - Address++; - Length--; - } - - *OutBufPtr = '\0' ; // the end of the buffer - SendPacket (OutBuffer); -} - - - -/** - Send a GDB Remote Serial Protocol Packet - - $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', - the packet teminating character '#' and the two digit checksum. - - If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up - in an infinit loop. This is so if you unplug the debugger code just keeps running - - @param PacketData Payload data for the packet - - - @retval Number of bytes of packet data sent. - -**/ -UINTN -SendPacket ( - IN CHAR8 *PacketData - ) -{ - UINT8 CheckSum; - UINTN Timeout; - CHAR8 *Ptr; - CHAR8 TestChar; - UINTN Count; - - Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount); - - Count = 0; - do { - - Ptr = PacketData; - - if (Timeout-- == 0) { - // Only try a finite number of times so we don't get stuck in the loop - return Count; - } - - // Packet prefix - GdbPutChar ('$'); - - for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) { - GdbPutChar (*Ptr); - CheckSum = CheckSum + *Ptr; - } - - // Packet terminating character and checksum - GdbPutChar ('#'); - GdbPutChar (mHexToStr[CheckSum >> 4]); - GdbPutChar (mHexToStr[CheckSum & 0x0F]); - - TestChar = GdbGetChar (); - } while (TestChar != '+'); - - return Count; -} - -/** - Receive a GDB Remote Serial Protocol Packet - - $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', - the packet teminating character '#' and the two digit checksum. - - If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed. - (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.) - - If an ack '+' is not sent resend the packet - - @param PacketData Payload data for the packet - - @retval Number of bytes of packet data received. - -**/ -UINTN -ReceivePacket ( - OUT CHAR8 *PacketData, - IN UINTN PacketDataSize - ) -{ - UINT8 CheckSum; - UINTN Index; - CHAR8 Char; - CHAR8 SumString[3]; - CHAR8 TestChar; - - ZeroMem (PacketData, PacketDataSize); - - for (;;) { - // wait for the start of a packet - TestChar = GdbGetChar (); - while (TestChar != '$') { - TestChar = GdbGetChar (); - }; - - retry: - for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) { - Char = GdbGetChar (); - if (Char == '$') { - goto retry; - } - if (Char == '#') { - break; - } - - PacketData[Index] = Char; - CheckSum = CheckSum + Char; - } - PacketData[Index] = '\0'; - - if (Index == PacketDataSize) { - continue; - } - - SumString[0] = GdbGetChar (); - SumString[1] = GdbGetChar (); - SumString[2] = '\0'; - - if (AsciiStrHexToUintn (SumString) == CheckSum) { - // Ack: Success - GdbPutChar ('+'); - - // Null terminate the callers string - PacketData[Index] = '\0'; - return Index; - } else { - // Ack: Failure - GdbPutChar ('-'); - } - } - - //return 0; -} - - -/** - Empties the given buffer - @param Buf pointer to the first element in buffer to be emptied - **/ -VOID -EmptyBuffer ( - IN CHAR8 *Buf - ) -{ - *Buf = '\0'; -} - - -/** - Converts an 8-bit Hex Char into a INTN. - - @param Char the hex character to be converted into UINTN - @retval a INTN, from 0 to 15, that corressponds to Char - -1 if Char is not a hex character - **/ -INTN -HexCharToInt ( - IN CHAR8 Char - ) -{ - if ((Char >= 'A') && (Char <= 'F')) { - return Char - 'A' + 10; - } else if ((Char >= 'a') && (Char <= 'f')) { - return Char - 'a' + 10; - } else if ((Char >= '0') && (Char <= '9')) { - return Char - '0'; - } else { // if not a hex value, return a negative value - return -1; - } -} - - // 'E' + the biggest error number is 255, so its 2 hex digits + buffer end -CHAR8 *gError = "E__"; - -/** 'E NN' - Send an error with the given error number after converting to hex. - The error number is put into the buffer in hex. '255' is the biggest errno we can send. - ex: 162 will be sent as A2. - - @param errno the error number that will be sent - **/ -VOID -EFIAPI -SendError ( - IN UINT8 ErrorNum - ) -{ - // - // Replace _, or old data, with current errno - // - gError[1] = mHexToStr [ErrorNum >> 4]; - gError[2] = mHexToStr [ErrorNum & 0x0f]; - - SendPacket (gError); // send buffer -} - - - -/** - Send 'OK' when the function is done executing successfully. - **/ -VOID -EFIAPI -SendSuccess ( - VOID - ) -{ - SendPacket ("OK"); // send buffer -} - - -/** - Send empty packet to specify that particular command/functionality is not supported. - **/ -VOID -EFIAPI -SendNotSupported ( - VOID - ) -{ - SendPacket (""); -} - - - - - -/** - Translates the EFI mapping to GDB mapping - - @param EFIExceptionType EFI Exception that is being processed - @retval UINTN that corresponds to EFIExceptionType's GDB exception type number - **/ -UINT8 -ConvertEFItoGDBtype ( - IN EFI_EXCEPTION_TYPE EFIExceptionType - ) -{ - UINTN i; - - for (i=0; i < MaxEfiException() ; i++) { - if (gExceptionType[i].Exception == EFIExceptionType) { - return gExceptionType[i].SignalNo; - } - } - return GDB_SIGTRAP; // this is a GDB trap -} - - -/** "m addr,length" - Find the Length of the area to read and the start addres. Finally, pass them to - another function, TransferFromMemToOutBufAndSend, that will read from that memory space and - send it as a packet. - **/ - -VOID -EFIAPI -ReadFromMemory ( - CHAR8 *PacketData - ) -{ - UINTN Address; - UINTN Length; - CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars - CHAR8 *AddrBufPtr; // pointer to the address buffer - CHAR8 *InBufPtr; /// pointer to the input buffer - - AddrBufPtr = AddressBuffer; - InBufPtr = &PacketData[1]; - while (*InBufPtr != ',') { - *AddrBufPtr++ = *InBufPtr++; - } - *AddrBufPtr = '\0'; - - InBufPtr++; // this skips ',' in the buffer - - /* Error checking */ - if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) { - SendError (GDB_EBADMEMADDRBUFSIZE); - return; - } - - // 2 = 'm' + ',' - if (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - 2 >= MAX_LENGTH_SIZE) { - SendError (GDB_EBADMEMLENGTH); - return; - } - - Address = AsciiStrHexToUintn (AddressBuffer); - Length = AsciiStrHexToUintn (InBufPtr); - - TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address); -} - - -/** "M addr,length :XX..." - Find the Length of the area in bytes to write and the start addres. Finally, pass them to - another function, TransferFromInBufToMem, that will write to that memory space the info in - the input buffer. - **/ -VOID -EFIAPI -WriteToMemory ( - IN CHAR8 *PacketData - ) -{ - UINTN Address; - UINTN Length; - UINTN MessageLength; - CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars - CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars - CHAR8 *AddrBufPtr; // pointer to the Address buffer - CHAR8 *LengthBufPtr; // pointer to the Length buffer - CHAR8 *InBufPtr; /// pointer to the input buffer - - AddrBufPtr = AddressBuffer; - LengthBufPtr = LengthBuffer; - InBufPtr = &PacketData[1]; - - while (*InBufPtr != ',') { - *AddrBufPtr++ = *InBufPtr++; - } - *AddrBufPtr = '\0'; - - InBufPtr++; // this skips ',' in the buffer - - while (*InBufPtr != ':') { - *LengthBufPtr++ = *InBufPtr++; - } - *LengthBufPtr = '\0'; - - InBufPtr++; // this skips ':' in the buffer - - Address = AsciiStrHexToUintn (AddressBuffer); - Length = AsciiStrHexToUintn (LengthBuffer); - - /* Error checking */ - - //Check if Address is not too long. - if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) { - SendError (GDB_EBADMEMADDRBUFSIZE); - return; - } - - //Check if message length is not too long - if (AsciiStrLen(LengthBuffer) >= MAX_LENGTH_SIZE) { - SendError (GDB_EBADMEMLENGBUFSIZE); - return; - } - - // Check if Message is not too long/short. - // 3 = 'M' + ',' + ':' - MessageLength = (AsciiStrLen(PacketData) - AsciiStrLen(AddressBuffer) - AsciiStrLen(LengthBuffer) - 3); - if (MessageLength != (2*Length)) { - //Message too long/short. New data is not the right size. - SendError (GDB_EBADMEMDATASIZE); - return; - } - TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr); -} - -/** - Parses breakpoint packet data and captures Breakpoint type, Address and length. - In case of an error, function returns particular error code. Returning 0 meaning - no error. - - @param PacketData Pointer to the payload data for the packet. - @param Type Breakpoint type - @param Address Breakpoint address - @param Length Breakpoint length in Bytes (1 byte, 2 byte, 4 byte) - - @retval 1 Success - @retval {other} Particular error code - -**/ -UINTN -ParseBreakpointPacket ( - IN CHAR8 *PacketData, - OUT UINTN *Type, - OUT UINTN *Address, - OUT UINTN *Length - ) -{ - CHAR8 AddressBuffer[MAX_ADDR_SIZE]; - CHAR8 *AddressBufferPtr; - CHAR8 *PacketDataPtr; - - PacketDataPtr = &PacketData[1]; - AddressBufferPtr = AddressBuffer; - - *Type = AsciiStrHexToUintn (PacketDataPtr); - - //Breakpoint/watchpoint type should be between 0 to 4 - if (*Type > 4) { - return 22; //EINVAL: Invalid argument. - } - - //Skip ',' in the buffer. - while (*PacketDataPtr++ != ','); - - //Parse Address information - while (*PacketDataPtr != ',') { - *AddressBufferPtr++ = *PacketDataPtr++; - } - *AddressBufferPtr = '\0'; - - //Check if Address is not too long. - if (AsciiStrLen(AddressBuffer) >= MAX_ADDR_SIZE) { - return 40; //EMSGSIZE: Message size too long. - } - - *Address = AsciiStrHexToUintn (AddressBuffer); - - PacketDataPtr++; //This skips , in the buffer - - //Parse Length information - *Length = AsciiStrHexToUintn (PacketDataPtr); - - //Length should be 1, 2 or 4 bytes - if (*Length > 4) { - return 22; //EINVAL: Invalid argument - } - - return 0; //0 = No error -} - - - -/** - Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints - - @param SystemContext Register content at time of the exception - @param GdbExceptionType GDB exception type - **/ -VOID -GdbSendTSignal ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINT8 GdbExceptionType - ) -{ - CHAR8 TSignalBuffer[128]; - CHAR8 *TSignalPtr; - - TSignalPtr = &TSignalBuffer[0]; - - //Construct TSignal packet - *TSignalPtr++ = 'T'; - - // - // replace _, or previous value, with Exception type - // - *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4]; - *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f]; - - ProcessorSendTSignal (SystemContext, GdbExceptionType, TSignalPtr, sizeof (TSignalBuffer) - 2); - - SendPacket (TSignalBuffer); -} - -VOID -GdbFWrite ( - IN UINTN Fd, - IN CHAR8 *Data, - IN UINTN DataSize - ) -{ - CHAR8 Buffer[128]; - - AsciiSPrint (Buffer, sizeof (Buffer), "Fwrite,%x,%x,%x", Fd, Data, DataSize); - SendPacket (Buffer); - - for( ; ; ) { - ReceivePacket (gInBuffer, MAX_BUF_SIZE); - - switch (gInBuffer[0]) { - case 'm': - ReadFromMemory (gInBuffer); - break; - - case 'M': - WriteToMemory (gInBuffer); - break; - - case 'F': - return; - } - } -} - - -VOID -GdbFPutString ( - IN CHAR8 *String - ) -{ - UINTN Len = AsciiStrSize (String); - - GdbFWrite (2, String, Len); -} - - -/** - Exception Hanldler for GDB. It will be called for all exceptions - registered via the gExceptionType[] array. - - @param ExceptionType Exception that is being processed - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -GdbExceptionHandler ( - IN EFI_EXCEPTION_TYPE ExceptionType, - IN OUT EFI_SYSTEM_CONTEXT SystemContext - ) -{ - UINT8 GdbExceptionType; - CHAR8 *Ptr; - - if (ProcessorControlC (ExceptionType, SystemContext)) { - // We tried to process a control C handler and there is nothing to do - return; - } - - GdbExceptionType = ConvertEFItoGDBtype (ExceptionType); - GdbSendTSignal (SystemContext, GdbExceptionType); - - for( ; ; ) { - ReceivePacket (gInBuffer, MAX_BUF_SIZE); - - switch (gInBuffer[0]) { - case '?': - GdbSendTSignal (SystemContext, GdbExceptionType); - break; - - case 'c': - ContinueAtAddress (SystemContext, gInBuffer); - return; - - case 'D': - // gdb wants to disconnect so return "OK" packet since. - SendSuccess (); - return; - - case 'g': - ReadGeneralRegisters (SystemContext); - break; - - case 'G': - WriteGeneralRegisters (SystemContext, gInBuffer); - break; - - case 'H': - //Return "OK" packet since we don't have more than one thread. - SendSuccess (); - break; - - case 'm': - ReadFromMemory (gInBuffer); - break; - - case 'M': - WriteToMemory (gInBuffer); - break; - - case 'P': - WriteNthRegister (SystemContext, gInBuffer); - break; - - // - // Still debugging this code. Not used in Darwin - // - case 'q': - // General Query Packets - if (AsciiStrnCmp (gInBuffer, "qSupported", 10) == 0) { - // return what we currently support, we don't parse what gdb suports - AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "qXfer:libraries:read+;PacketSize=%d", MAX_BUF_SIZE); - SendPacket (gOutBuffer); - } else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) { - // ‘qXfer:libraries:read::offset,length - // gInBuffer[22] is offset string, ++Ptr is length string’ - for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++); - - // Not sure if multi-radix support is required. Currently only support decimal - QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr)); - } else if (AsciiStrnCmp (gInBuffer, "qOffsets", 8) == 0) { - AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000"); - SendPacket (gOutBuffer); - } else if (AsciiStrnCmp (gInBuffer, "qAttached", 9) == 0) { - // remote server attached to an existing process - SendPacket ("1"); - } else { - //Send empty packet - SendNotSupported (); - } - break; - - case 's': - SingleStep (SystemContext, gInBuffer); - return; - - case 'z': - RemoveBreakPoint (SystemContext, gInBuffer); - break; - - case 'Z': - InsertBreakPoint (SystemContext, gInBuffer); - break; - - default: - //Send empty packet - SendNotSupported (); - break; - } - } -} - - - - - diff --git a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.h b/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.h deleted file mode 100755 index dfdc016d9d..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.h +++ /dev/null @@ -1,728 +0,0 @@ -/** @file - Private include file for GDB stub - - Copyright (c) 2008 - 2009, Apple Inc. 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 __GCC_DEBUG_AGENT_INTERNAL__ -#define __GCC_DEBUG_AGENT_INTERNAL__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -extern CONST CHAR8 mHexToStr[]; - -// maximum size of input and output buffers -// This value came from the show remote command of the gdb we tested against -#define MAX_BUF_SIZE 2000 - -// maximum size of address buffer -#define MAX_ADDR_SIZE 32 - -// maximum size of register number buffer -#define MAX_REG_NUM_BUF_SIZE 32 - -// maximum size of length buffer -#define MAX_LENGTH_SIZE 32 - -// maximum size of T signal members -#define MAX_T_SIGNAL_SIZE 64 - -// the mask used to clear all the cache -#define TF_BIT 0x00000100 - - -// -// GDB Signal definitions - generic names for interrupts -// -#define GDB_SIGINT 2 // Interrupt process via ctrl-c -#define GDB_SIGILL 4 // Illegal instruction -#define GDB_SIGTRAP 5 // Trace Trap (Breakpoint and SingleStep) -#define GDB_SIGEMT 7 // Emulator Trap -#define GDB_SIGFPE 8 // Floating point exception -#define GDB_SIGSEGV 11 // Setgment violation, page fault - - -// -// GDB File I/O Error values, zero means no error -// Includes all general GDB Unix like error values -// -#define GDB_EBADMEMADDRBUFSIZE 11 // the buffer that stores memory Address to be read from/written to is not the right size -#define GDB_EBADMEMLENGBUFSIZE 12 // the buffer that stores Length is not the right size -#define GDB_EBADMEMLENGTH 13 // Length, the given number of bytes to read or write, is not the right size -#define GDB_EBADMEMDATA 14 // one of the bytes or nibbles of the memory is leess than 0 -#define GDB_EBADMEMDATASIZE 15 // the memory data, 'XX..', is too short or too long -#define GDB_EBADBUFSIZE 21 // the buffer created is not the correct size -#define GDB_EINVALIDARG 31 // argument is invalid -#define GDB_ENOSPACE 41 // -#define GDB_EINVALIDBRKPOINTTYPE 51 // the breakpoint type is not recognized -#define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers -#define GDB_EUNKNOWN 255 // unknown - - -// -// These devices are open by GDB so we can just read and write to them -// -#define GDB_STDIN 0x00 -#define GDB_STDOUT 0x01 -#define GDB_STDERR 0x02 - -// -//Define Register size for different architectures -// -#if defined (MDE_CPU_IA32) -#define REG_SIZE 32 -#elif defined (MDE_CPU_X64) -#define REG_SIZE 64 -#elif defined (MDE_CPU_ARM) -#define REG_SIZE 32 -#endif - - -typedef struct { - EFI_EXCEPTION_TYPE Exception; - UINT8 SignalNo; -} EFI_EXCEPTION_TYPE_ENTRY; - - -#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) - -// -// Byte packed structure for DR6 -// 32-bits on IA-32 -// 64-bits on X64. The upper 32-bits on X64 are reserved -// -typedef union { - struct { - UINT32 B0:1; // Breakpoint condition detected - UINT32 B1:1; // Breakpoint condition detected - UINT32 B2:1; // Breakpoint condition detected - UINT32 B3:1; // Breakpoint condition detected - UINT32 Reserved_1:9; // Reserved - UINT32 BD:1; // Debug register access detected - UINT32 BS:1; // Single step - UINT32 BT:1; // Task switch - UINT32 Reserved_2:16; // Reserved - } Bits; - UINTN UintN; -} IA32_DR6; - -// -// Byte packed structure for DR7 -// 32-bits on IA-32 -// 64-bits on X64. The upper 32-bits on X64 are reserved -// -typedef union { - struct { - UINT32 L0:1; // Local breakpoint enable - UINT32 G0:1; // Global breakpoint enable - UINT32 L1:1; // Local breakpoint enable - UINT32 G1:1; // Global breakpoint enable - UINT32 L2:1; // Local breakpoint enable - UINT32 G2:1; // Global breakpoint enable - UINT32 L3:1; // Local breakpoint enable - UINT32 G3:1; // Global breakpoint enable - UINT32 LE:1; // Local exact breakpoint enable - UINT32 GE:1; // Global exact breakpoint enable - UINT32 Reserved_1:3; // Reserved - UINT32 GD:1; // Global detect enable - UINT32 Reserved_2:2; // Reserved - UINT32 RW0:2; // Read/Write field - UINT32 LEN0:2; // Length field - UINT32 RW1:2; // Read/Write field - UINT32 LEN1:2; // Length field - UINT32 RW2:2; // Read/Write field - UINT32 LEN2:2; // Length field - UINT32 RW3:2; // Read/Write field - UINT32 LEN3:2; // Length field - } Bits; - UINTN UintN; -} IA32_DR7; - -#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */ - -typedef enum { - InstructionExecution, //Hardware breakpoint - DataWrite, //watch - DataRead, //rwatch - DataReadWrite, //awatch - SoftwareBreakpoint, //Software breakpoint - NotSupported -} BREAK_TYPE; - -// -// Array of exception types that need to be hooked by the debugger -// -extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[]; - -// -// If the periodic callback is called while we are processing an F packet we need -// to let the callback know to not read from the serail stream as it could steal -// characters from the F reponse packet -// -extern BOOLEAN gProcessingFPacket; - - -/** - Return the number of entries in the gExceptionType[] - - @retval UINTN, the number of entries in the gExceptionType[] array. - **/ -UINTN -MaxEfiException ( - VOID - ); - - -/** - Check to see if the ISA is supported. - ISA = Instruction Set Architecture - - @retval TRUE if Isa is supported, - FALSE otherwise. - **/ -BOOLEAN -CheckIsa ( - IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa - ); - - -/** - Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints - - @param SystemContext Register content at time of the exception - @param GdbExceptionType GDB exception type - **/ - -VOID -GdbSendTSignal ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINT8 GdbExceptionType - ); - - -/** - Translates the EFI mapping to GDB mapping - - @param EFIExceptionType EFI Exception that is being processed - @retval UINTN that corresponds to EFIExceptionType's GDB exception type number - **/ -UINT8 -ConvertEFItoGDBtype ( - IN EFI_EXCEPTION_TYPE EFIExceptionType - ); - - -/** - Empties the given buffer - @param *Buf pointer to the first element in buffer to be emptied - **/ -VOID -EmptyBuffer ( - IN CHAR8 *Buf - ); - - -/** - Converts an 8-bit Hex Char into a INTN. - - @param Char - the hex character to be converted into UINTN - @retval a INTN, from 0 to 15, that corressponds to Char - -1 if Char is not a hex character - **/ -INTN -HexCharToInt ( - IN CHAR8 Char - ); - - -/** 'E NN' - Send an error with the given error number after converting to hex. - The error number is put into the buffer in hex. '255' is the biggest errno we can send. - ex: 162 will be sent as A2. - - @param errno the error number that will be sent - **/ -VOID -EFIAPI -SendError ( - IN UINT8 ErrorNum - ); - - -/** - Send 'OK' when the function is done executing successfully. - **/ -VOID -SendSuccess ( - VOID - ); - - -/** - Send empty packet to specify that particular command/functionality is not supported. - **/ -VOID -SendNotSupported ( - VOID - ); - -/** ‘p n’ - Reads the n-th register's value into an output buffer and sends it as a packet - @param SystemContext Register content at time of the exception - @param InBuffer This is the input buffer received from gdb server - **/ -VOID -ReadNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ); - - -/** ‘g’ - Reads the general registers into an output buffer and sends it as a packet - @param SystemContext Register content at time of the exception - **/ -VOID -ReadGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext - ); - - -/** ‘P n...=r...’ - Writes the new value of n-th register received into the input buffer to the n-th register - @param SystemContext Register content at time of the exception - @param InBuffer This is the input buffer received from gdb server - **/ -VOID -WriteNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ); - - -/** ‘G XX...’ - Writes the new values received into the input buffer to the general registers - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ - -VOID -WriteGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ); - - -/** ‘m addr,length ’ - Find the Length of the area to read and the start addres. Finally, pass them to - another function, TransferFromMemToOutBufAndSend, that will read from that memory space and - send it as a packet. - - @param *PacketData Pointer to Payload data for the packet - **/ -VOID -ReadFromMemory ( - IN CHAR8 *PacketData - ); - - -/** ‘M addr,length :XX...’ - Find the Length of the area in bytes to write and the start addres. Finally, pass them to - another function, TransferFromInBufToMem, that will write to that memory space the info in - the input buffer. - - @param PacketData Pointer to Payload data for the packet - **/ -VOID -WriteToMemory ( - IN CHAR8 *PacketData - ); - - -/** ‘c [addr ]’ - Continue. addr is Address to resume. If addr is omitted, resume at current - Address. - - @param SystemContext Register content at time of the exception - @param *PacketData Pointer to PacketData - **/ - -VOID -ContinueAtAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ); - - -/** ‘s [addr ]’ - Single step. addr is the Address at which to resume. If addr is omitted, resume - at same Address. - - @param SystemContext Register content at time of the exception - @param PacketData Pointer to Payload data for the packet - **/ -VOID -SingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ); - -/** - Insert Single Step in the SystemContext - - @param SystemContext Register content at time of the exception - **/ -VOID -AddSingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext - ); - -/** - Remove Single Step in the SystemContext - - @param SystemContext Register content at time of the exception - **/ -VOID -RemoveSingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext - ); - - -/** - ‘Z1, [addr], [length]’ - ‘Z2, [addr], [length]’ - ‘Z3, [addr], [length]’ - ‘Z4, [addr], [length]’ - - Insert hardware breakpoint/watchpoint at address addr of size length - - @param SystemContext Register content at time of the exception - @param *PacketData Pointer to the Payload data for the packet - -**/ -VOID -EFIAPI -InsertBreakPoint( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ); - - -/** - ‘z1, [addr], [length]’ - ‘z2, [addr], [length]’ - ‘z3, [addr], [length]’ - ‘z4, [addr], [length]’ - - Remove hardware breakpoint/watchpoint at address addr of size length - - @param SystemContext Register content at time of the exception - @param *PacketData Pointer to the Payload data for the packet - -**/ -VOID -EFIAPI -RemoveBreakPoint( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ); - - -/** - Exception Hanldler for GDB. It will be called for all exceptions - registered via the gExceptionType[] array. - - @param ExceptionType Exception that is being processed - @param SystemContext Register content at time of the exception - - **/ -VOID -EFIAPI -GdbExceptionHandler ( - IN EFI_EXCEPTION_TYPE ExceptionType, - IN OUT EFI_SYSTEM_CONTEXT SystemContext - ); - - -/** - Periodic callback for GDB. This function is used to catch a ctrl-c or other - break in type command from GDB. - - @param SystemContext Register content at time of the call - - **/ -VOID -EFIAPI -GdbPeriodicCallBack ( - IN OUT EFI_SYSTEM_CONTEXT SystemContext - ); - - -/** - Make two serail consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB. - - These console show up on the remote system running GDB - -**/ - -VOID -GdbInitializeSerialConsole ( - VOID - ); - - -/** - Send a GDB Remote Serial Protocol Packet - - $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', - the packet teminating character '#' and the two digit checksum. - - If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up - in an infinit loop. This is so if you unplug the debugger code just keeps running - - @param PacketData Payload data for the packet - - @retval Number of bytes of packet data sent. - -**/ -UINTN -SendPacket ( - IN CHAR8 *PacketData - ); - - -/** - Receive a GDB Remote Serial Protocol Packet - - $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$', - the packet teminating character '#' and the two digit checksum. - - If host re-starts sending a packet without ending the previous packet, only the last valid packet is proccessed. - (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.) - - If an ack '+' is not sent resend the packet - - @param PacketData Payload data for the packet - - @retval Number of bytes of packet data received. - - **/ -UINTN -ReceivePacket ( - OUT CHAR8 *PacketData, - IN UINTN PacketDataSize - ); - - -/** - Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates - the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero. - - @param FileDescriptor Device to talk to. - @param Buffer Buffer to hold Count bytes that were read - @param Count Number of bytes to transfer. - - @retval -1 Error - @retval {other} Number of bytes read. - -**/ -INTN -GdbRead ( - IN INTN FileDescriptor, - OUT VOID *Buffer, - IN UINTN Count - ); - - -/** - Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates - nothing was written. On error -1 is returned. - - @param FileDescriptor Device to talk to. - @param Buffer Buffer to hold Count bytes that are to be written - @param Count Number of bytes to transfer. - - @retval -1 Error - @retval {other} Number of bytes written. - -**/ -INTN -GdbWrite ( - IN INTN FileDescriptor, - OUT CONST VOID *Buffer, - IN UINTN Count - ); - -UINTN * -FindPointerToRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber - ); - -CHAR8 * -BasicReadRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *OutBufPtr - ); - -VOID -TransferFromInBufToMem ( - IN UINTN Length, - IN UINT8 *Address, - IN CHAR8 *NewData - ); - -VOID -TransferFromMemToOutBufAndSend ( - IN UINTN Length, - IN UINT8 *Address - ); - -CHAR8 * -BasicWriteRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *InBufPtr - ); - -VOID -PrintReg ( - EFI_SYSTEM_CONTEXT SystemContext - ); - -UINTN -ParseBreakpointPacket ( - IN CHAR8 *PacketData, - OUT UINTN *Type, - OUT UINTN *Address, - OUT UINTN *Length - ); - -UINTN -GetBreakpointDataAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN BreakpointNumber - ); - -UINTN -GetBreakpointDetected ( - IN EFI_SYSTEM_CONTEXT SystemContext - ); - -BREAK_TYPE -GetBreakpointType ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN BreakpointNumber - ); - -UINTN -ConvertLengthData ( - IN UINTN Length - ); - -EFI_STATUS -FindNextFreeDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - OUT UINTN *Register - ); - -EFI_STATUS -EnableDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Register, - IN UINTN Address, - IN UINTN Length, - IN UINTN Type - ); - -EFI_STATUS -FindMatchingDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Address, - IN UINTN Length, - IN UINTN Type, - OUT UINTN *Register - ); - -EFI_STATUS -DisableDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Register - ); - -VOID -InitializeProcessor ( - VOID - ); - -/** - Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints - - @param SystemContext Register content at time of the exception - @param GdbExceptionType GDB exception type - **/ -VOID -ProcessorSendTSignal ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINT8 GdbExceptionType, - IN OUT CHAR8 *TSignalPtr, - IN UINTN SizeOfBuffer - ); - -/** - Check to see if this exception is related to ctrl-c handling. - - @param ExceptionType Exception that is being processed - @param SystemContext Register content at time of the exception - - @return TRUE This was a ctrl-c check that did not find a ctrl-c - @return FALSE This was not a ctrl-c check or some one hit ctrl-c - **/ -BOOLEAN -ProcessorControlC ( - IN EFI_EXCEPTION_TYPE ExceptionType, - IN OUT EFI_SYSTEM_CONTEXT SystemContext - ); - - -/** - Initialize debug agent. - - This function is used to set up debug enviroment. It may enable interrupts. - - @param[in] InitFlag Init flag is used to decide initialize process. - @param[in] Context Context needed according to InitFlag, it was optional. - -**/ -VOID -EFIAPI -DebugAgentHookExceptions ( - IN UINT32 InitFlag, - IN VOID *Context OPTIONAL - ); - - -#endif diff --git a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf b/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf deleted file mode 100755 index 02f80579b1..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf +++ /dev/null @@ -1,70 +0,0 @@ -#/** @file -# Null instance of Debug Agent Library with empty functions. -# -# Copyright (c) 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = GdbDebugAgent - FILE_GUID = b9f10c17-6ca0-40b5-9b44-6253cfc7d24b - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = DebugAgentLib - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - GdbDebugAgent.c - -[Sources.arm] - Arm/Processor.c - Arm/ExceptionSupport.ARMv6.S - Arm/ExceptionSupport.ARMv6.asm - -[Sources.X64] - Ia32/Processor.c - -[Sources.Ia32] - X64/Processor.c - - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[Packages.arm] - ArmPkg/ArmPkg.dec - -[LibraryClasses] - BaseLib - DebugLib - BaseMemoryLib - PcdLib - GdbSerialLib - CacheMaintenanceLib - DebugAgentTimerLib - -[FeaturePcd.common] - gEmbeddedTokenSpaceGuid.PcdGdbSerial - -[FixedPcd.common] - gEmbeddedTokenSpaceGuid.PcdGdbMaxPacketRetryCount - gEmbeddedTokenSpaceGuid.PcdGdbTimerPeriodMilliseconds - -[FixedPcd.arm] - gArmTokenSpaceGuid.PcdCpuVectorBaseAddress diff --git a/EmbeddedPkg/Library/GdbDebugAgent/Ia32/Processor.c b/EmbeddedPkg/Library/GdbDebugAgent/Ia32/Processor.c deleted file mode 100755 index d465b21183..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/Ia32/Processor.c +++ /dev/null @@ -1,951 +0,0 @@ -/** @file - Processor specific parts of the GDB stub - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include - -// -// Array of exception types that need to be hooked by the debugger -// {EFI mapping, GDB mapping} -// -EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = { - { EXCEPT_IA32_DIVIDE_ERROR, GDB_SIGFPE }, - { EXCEPT_IA32_DEBUG, GDB_SIGTRAP }, - { EXCEPT_IA32_NMI, GDB_SIGEMT }, - { EXCEPT_IA32_BREAKPOINT, GDB_SIGTRAP }, - { EXCEPT_IA32_OVERFLOW, GDB_SIGSEGV }, - { EXCEPT_IA32_BOUND, GDB_SIGSEGV }, - { EXCEPT_IA32_INVALID_OPCODE, GDB_SIGILL }, - { EXCEPT_IA32_DOUBLE_FAULT, GDB_SIGEMT }, - { EXCEPT_IA32_STACK_FAULT, GDB_SIGSEGV }, - { EXCEPT_IA32_GP_FAULT, GDB_SIGSEGV }, - { EXCEPT_IA32_PAGE_FAULT, GDB_SIGSEGV }, - { EXCEPT_IA32_FP_ERROR, GDB_SIGEMT }, - { EXCEPT_IA32_ALIGNMENT_CHECK, GDB_SIGEMT }, - { EXCEPT_IA32_MACHINE_CHECK, GDB_SIGEMT } -}; - - -// The offsets of registers SystemContext. -// The fields in the array are in the gdb ordering. -// -//16 regs -UINTN gRegisterOffsets[] = { - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eax), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ecx), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edx), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebx), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esp), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebp), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esi), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edi), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eip), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eflags), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Cs), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ss), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ds), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Es), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Fs), - OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Gs) -}; - - -//Debug only.. -VOID -PrintReg ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - Print ((CHAR16 *)L"EAX: %x ", SystemContext.SystemContextIa32->Eax); - Print ((CHAR16 *)L"ECX: %x ", SystemContext.SystemContextIa32->Ecx); - Print ((CHAR16 *)L"EDX: %x ", SystemContext.SystemContextIa32->Edx); - Print ((CHAR16 *)L"EBX: %x ", SystemContext.SystemContextIa32->Ebx); - Print ((CHAR16 *)L"ESP: %x ", SystemContext.SystemContextIa32->Esp); - Print ((CHAR16 *)L"EBP: %x ", SystemContext.SystemContextIa32->Ebp); - Print ((CHAR16 *)L"ESI: %x ", SystemContext.SystemContextIa32->Esi); - Print ((CHAR16 *)L"EDI: %x ", SystemContext.SystemContextIa32->Edi); - Print ((CHAR16 *)L"EIP: %x\n", SystemContext.SystemContextIa32->Eip); - Print ((CHAR16 *)L"EFlags: %x\n", SystemContext.SystemContextIa32->Eflags); -} - -//Debug only.. -VOID -PrintDRreg ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - Print ((CHAR16 *)L"DR0: %x ", SystemContext.SystemContextIa32->Dr0); - Print ((CHAR16 *)L"DR1: %x ", SystemContext.SystemContextIa32->Dr1); - Print ((CHAR16 *)L"DR2: %x ", SystemContext.SystemContextIa32->Dr2); - Print ((CHAR16 *)L"DR3: %x ", SystemContext.SystemContextIa32->Dr3); - Print ((CHAR16 *)L"DR6: %x ", SystemContext.SystemContextIa32->Dr6); - Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7); -} - - -/** - Return the number of entries in the gExceptionType[] - - @retval UINTN, the number of entries in the gExceptionType[] array. - **/ -UINTN -MaxEfiException ( - VOID - ) -{ - return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY); -} - - -/** - Check to see if the ISA is supported. - ISA = Instruction Set Architecture - - @retval TRUE if Isa is supported, - FALSE otherwise. -**/ -BOOLEAN -CheckIsa ( - IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa - ) -{ - return (BOOLEAN)(Isa == IsaIa32); -} - - -/** - This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering - It is, by default, set to find the register pointer of the IA32 member - - @param SystemContext Register content at time of the exception - @param RegNumber The register to which we want to find a pointer - @retval the pointer to the RegNumber-th pointer - **/ -UINTN * -FindPointerToRegister( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber - ) -{ - UINT8 *TempPtr; - TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber]; - return (UINTN *)TempPtr; -} - - -/** - Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr - - @param SystemContext Register content at time of the exception - @param RegNumber the number of the register that we want to read - @param OutBufPtr pointer to the output buffer's end. the new data will be added from this point on. - @retval the pointer to the next character of the output buffer that is available to be written on. - **/ -CHAR8 * -BasicReadRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *OutBufPtr - ) -{ - UINTN RegSize; - - RegSize = 0; - while (RegSize < REG_SIZE) { - *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)]; - *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)]; - RegSize = RegSize + 8; - } - return OutBufPtr; -} - - -/** ‘p n’ - Reads the n-th register's value into an output buffer and sends it as a packet - - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ -VOID -EFIAPI -ReadNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN RegNumber; - CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq) - CHAR8 *OutBufPtr; // pointer to the output buffer - - RegNumber = AsciiStrHexToUintn (&InBuffer[1]); - - if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) { - SendError (GDB_EINVALIDREGNUM); - return; - } - - OutBufPtr = OutBuffer; - OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr); - - *OutBufPtr = '\0'; // the end of the buffer - SendPacket(OutBuffer); -} - - -/** ‘g’ - Reads the general registers into an output buffer and sends it as a packet - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -ReadGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - UINTN i; - CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq) - CHAR8 *OutBufPtr; // pointer to the output buffer - - OutBufPtr = OutBuffer; - for(i = 0 ; i < sizeof (gRegisterOffsets)/sizeof (UINTN) ; i++) { // there are only 16 registers to read - OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr); - } - - *OutBufPtr = '\0'; // the end of the buffer - SendPacket(OutBuffer); -} - - -/** - Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr - - @param SystemContext Register content at time of the exception - @param RegNumber the number of the register that we want to write - @param InBufPtr pointer to the output buffer. the new data will be extracted from the input buffer from this point on. - @retval the pointer to the next character of the input buffer that can be used - **/ -CHAR8 * -BasicWriteRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *InBufPtr - ) -{ - UINTN RegSize; - UINTN TempValue; // the value transferred from a hex char - UINT32 NewValue; // the new value of the RegNumber-th Register - - NewValue = 0; - RegSize = 0; - while (RegSize < REG_SIZE) { - TempValue = HexCharToInt(*InBufPtr++); - - if (TempValue < 0) { - SendError (GDB_EBADMEMDATA); - return NULL; - } - - NewValue += (TempValue << (RegSize+4)); - TempValue = HexCharToInt(*InBufPtr++); - - if (TempValue < 0) { - SendError (GDB_EBADMEMDATA); - return NULL; - } - - NewValue += (TempValue << RegSize); - RegSize = RegSize + 8; - } - *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue; - return InBufPtr; -} - - -/** ‘P n...=r...’ - Writes the new value of n-th register received into the input buffer to the n-th register - - @param SystemContext Register content at time of the exception - @param InBuffer Ponter to the input buffer received from gdb server - **/ -VOID -EFIAPI -WriteNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN RegNumber; - CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array - CHAR8 *RegNumBufPtr; - CHAR8 *InBufPtr; // pointer to the input buffer - - // find the register number to write - InBufPtr = &InBuffer[1]; - RegNumBufPtr = RegNumBuffer; - while (*InBufPtr != '=') { - *RegNumBufPtr++ = *InBufPtr++; - } - *RegNumBufPtr = '\0'; - RegNumber = AsciiStrHexToUintn (RegNumBuffer); - - // check if this is a valid Register Number - if ((RegNumber < 0) || (RegNumber >= sizeof (gRegisterOffsets)/sizeof (UINTN))) { - SendError (GDB_EINVALIDREGNUM); - return; - } - InBufPtr++; // skips the '=' character - BasicWriteRegister (SystemContext, RegNumber, InBufPtr); - SendSuccess(); -} - - -/** ‘G XX...’ - Writes the new values received into the input buffer to the general registers - - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ -VOID -EFIAPI -WriteGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN i; - CHAR8 *InBufPtr; /// pointer to the input buffer - - // check to see if the buffer is the right size which is - // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 - if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq) - //Bad message. Message is not the right length - SendError (GDB_EBADBUFSIZE); - return; - } - - InBufPtr = &InBuffer[1]; - - // Read the new values for the registers from the input buffer to an array, NewValueArray. - // The values in the array are in the gdb ordering - for(i=0; i < sizeof (gRegisterOffsets)/sizeof (UINTN); i++) { // there are only 16 registers to write - InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr); - } - - SendSuccess(); -} - -/** ‘c [addr ]’ - Continue. addr is Address to resume. If addr is omitted, resume at current - Address. - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -ContinueAtAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - if (PacketData[1] != '\0') { - SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]); - } -} - - -/** ‘s [addr ]’ - Single step. addr is the Address at which to resume. If addr is omitted, resume - at same Address. - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -SingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - SendNotSupported(); -} - - -/** - Returns breakpoint data address from DR0-DR3 based on the input breakpoint number - - @param SystemContext Register content at time of the exception - @param BreakpointNumber Breakpoint number - - @retval Address Data address from DR0-DR3 based on the breakpoint number. - -**/ -UINTN -GetBreakpointDataAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN BreakpointNumber - ) -{ - UINTN Address; - - if (BreakpointNumber == 1) { - Address = SystemContext.SystemContextIa32->Dr0; - } else if (BreakpointNumber == 2) { - Address = SystemContext.SystemContextIa32->Dr1; - } else if (BreakpointNumber == 3) { - Address = SystemContext.SystemContextIa32->Dr2; - } else if (BreakpointNumber == 4) { - Address = SystemContext.SystemContextIa32->Dr3; - } else { - Address = 0; - } - - return Address; -} - - -/** - Returns currently detected breakpoint value based on the register DR6 B0-B3 field. - If no breakpoint is detected then it returns 0. - - @param SystemContext Register content at time of the exception - - @retval {1-4} Currently detected breakpoint value - @retval 0 No breakpoint detected. - -**/ -UINTN -GetBreakpointDetected ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - IA32_DR6 Dr6; - UINTN BreakpointNumber; - - Dr6.UintN = SystemContext.SystemContextIa32->Dr6; - - if (Dr6.Bits.B0 == 1) { - BreakpointNumber = 1; - } else if (Dr6.Bits.B1 == 1) { - BreakpointNumber = 2; - } else if (Dr6.Bits.B2 == 1) { - BreakpointNumber = 3; - } else if (Dr6.Bits.B3 == 1) { - BreakpointNumber = 4; - } else { - BreakpointNumber = 0; //No breakpoint detected - } - - return BreakpointNumber; -} - - -/** - Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite) - based on the Breakpoint number - - @param SystemContext Register content at time of the exception - @param BreakpointNumber Breakpoint number - - @retval BREAK_TYPE Breakpoint type value read from register DR7 RWn field - For unknown value, it returns NotSupported. - -**/ -BREAK_TYPE -GetBreakpointType ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN BreakpointNumber - ) -{ - IA32_DR7 Dr7; - BREAK_TYPE Type = NotSupported; //Default is NotSupported type - - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (BreakpointNumber == 1) { - Type = (BREAK_TYPE) Dr7.Bits.RW0; - } else if (BreakpointNumber == 2) { - Type = (BREAK_TYPE) Dr7.Bits.RW1; - } else if (BreakpointNumber == 3) { - Type = (BREAK_TYPE) Dr7.Bits.RW2; - } else if (BreakpointNumber == 4) { - Type = (BREAK_TYPE) Dr7.Bits.RW3; - } - - return Type; -} - - -/** - Parses Length and returns the length which DR7 LENn field accepts. - For example: If we receive 1-Byte length then we should return 0. - Zero gets written to DR7 LENn field. - - @param Length Breakpoint length in Bytes (1 byte, 2 byte, 4 byte) - - @retval Length Appropriate converted values which DR7 LENn field accepts. - -**/ -UINTN -ConvertLengthData ( - IN UINTN Length - ) -{ - if (Length == 1) { //1-Byte length - return 0; - } else if (Length == 2) { //2-Byte length - return 1; - } else if (Length == 4) { //4-Byte length - return 3; - } else { //Undefined or 8-byte length - return 2; - } -} - - -/** - Finds the next free debug register. If all the registers are occupied then - EFI_OUT_OF_RESOURCES is returned. - - @param SystemContext Register content at time of the exception - @param Register Register value (0 - 3 for the first free debug register) - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -FindNextFreeDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - OUT UINTN *Register - ) -{ - IA32_DR7 Dr7; - - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (Dr7.Bits.G0 == 0) { - *Register = 0; - } else if (Dr7.Bits.G1 == 0) { - *Register = 1; - } else if (Dr7.Bits.G2 == 0) { - *Register = 2; - } else if (Dr7.Bits.G3 == 0) { - *Register = 3; - } else { - return EFI_OUT_OF_RESOURCES; - } - - return EFI_SUCCESS; -} - - -/** - Enables the debug register. Writes Address value to appropriate DR0-3 register. - Sets LENn, Gn, RWn bits in DR7 register. - - @param SystemContext Register content at time of the exception - @param Register Register value (0 - 3) - @param Address Breakpoint address value - @param Type Breakpoint type (Instruction, Data write, Data read - or write etc.) - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -EnableDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Register, - IN UINTN Address, - IN UINTN Length, - IN UINTN Type - ) -{ - IA32_DR7 Dr7; - - //Convert length data - Length = ConvertLengthData (Length); - - //For Instruction execution, length should be 0 - //(Ref. Intel reference manual 18.2.4) - if ((Type == 0) && (Length != 0)) { - return EFI_INVALID_PARAMETER; - } - - //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle - //software breakpoint. We should send empty packet in both these cases. - if ((Type == (BREAK_TYPE)DataRead) || - (Type == (BREAK_TYPE)SoftwareBreakpoint)) { - return EFI_UNSUPPORTED; - } - - //Read DR7 so appropriate Gn, RWn and LENn bits can be modified. - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (Register == 0) { - SystemContext.SystemContextIa32->Dr0 = Address; - Dr7.Bits.G0 = 1; - Dr7.Bits.RW0 = Type; - Dr7.Bits.LEN0 = Length; - } else if (Register == 1) { - SystemContext.SystemContextIa32->Dr1 = Address; - Dr7.Bits.G1 = 1; - Dr7.Bits.RW1 = Type; - Dr7.Bits.LEN1 = Length; - } else if (Register == 2) { - SystemContext.SystemContextIa32->Dr2 = Address; - Dr7.Bits.G2 = 1; - Dr7.Bits.RW2 = Type; - Dr7.Bits.LEN2 = Length; - } else if (Register == 3) { - SystemContext.SystemContextIa32->Dr3 = Address; - Dr7.Bits.G3 = 1; - Dr7.Bits.RW3 = Type; - Dr7.Bits.LEN3 = Length; - } else { - return EFI_INVALID_PARAMETER; - } - - //Update Dr7 with appropriate Gn, RWn and LENn bits - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; - - return EFI_SUCCESS; -} - - -/** - Returns register number 0 - 3 for the maching debug register. - This function compares incoming Address, Type, Length and - if there is a match then it returns the appropriate register number. - In case of mismatch, function returns EFI_NOT_FOUND message. - - @param SystemContext Register content at time of the exception - @param Address Breakpoint address value - @param Length Breakpoint length value - @param Type Breakpoint type (Instruction, Data write, - Data read or write etc.) - @param Register Register value to be returned - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -FindMatchingDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Address, - IN UINTN Length, - IN UINTN Type, - OUT UINTN *Register - ) -{ - IA32_DR7 Dr7; - - //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle - //software breakpoint. We should send empty packet in both these cases. - if ((Type == (BREAK_TYPE)DataRead) || - (Type == (BREAK_TYPE)SoftwareBreakpoint)) { - return EFI_UNSUPPORTED; - } - - //Convert length data - Length = ConvertLengthData(Length); - - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if ((Dr7.Bits.G0 == 1) && - (Dr7.Bits.LEN0 == Length) && - (Dr7.Bits.RW0 == Type) && - (Address == SystemContext.SystemContextIa32->Dr0)) { - *Register = 0; - } else if ((Dr7.Bits.G1 == 1) && - (Dr7.Bits.LEN1 == Length) && - (Dr7.Bits.RW1 == Type) && - (Address == SystemContext.SystemContextIa32->Dr1)) { - *Register = 1; - } else if ((Dr7.Bits.G2 == 1) && - (Dr7.Bits.LEN2 == Length) && - (Dr7.Bits.RW2 == Type) && - (Address == SystemContext.SystemContextIa32->Dr2)) { - *Register = 2; - } else if ((Dr7.Bits.G3 == 1) && - (Dr7.Bits.LEN3 == Length) && - (Dr7.Bits.RW3 == Type) && - (Address == SystemContext.SystemContextIa32->Dr3)) { - *Register = 3; - } else { - Print ((CHAR16 *)L"No match found..\n"); - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; -} - - -/** - Disables the particular debug register. - - @param SystemContext Register content at time of the exception - @param Register Register to be disabled - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -DisableDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Register - ) -{ - IA32_DR7 Dr7; - UINTN Address = 0; - - //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off. - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (Register == 0) { - SystemContext.SystemContextIa32->Dr0 = Address; - Dr7.Bits.G0 = 0; - Dr7.Bits.RW0 = 0; - Dr7.Bits.LEN0 = 0; - } else if (Register == 1) { - SystemContext.SystemContextIa32->Dr1 = Address; - Dr7.Bits.G1 = 0; - Dr7.Bits.RW1 = 0; - Dr7.Bits.LEN1 = 0; - } else if (Register == 2) { - SystemContext.SystemContextIa32->Dr2 = Address; - Dr7.Bits.G2 = 0; - Dr7.Bits.RW2 = 0; - Dr7.Bits.LEN2 = 0; - } else if (Register == 3) { - SystemContext.SystemContextIa32->Dr3 = Address; - Dr7.Bits.G3 = 0; - Dr7.Bits.RW3 = 0; - Dr7.Bits.LEN3 = 0; - } else { - return EFI_INVALID_PARAMETER; - } - - //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off. - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; - - return EFI_SUCCESS; -} - - -/** - ‘Z1, [addr], [length]’ - ‘Z2, [addr], [length]’ - ‘Z3, [addr], [length]’ - ‘Z4, [addr], [length]’ - - Insert hardware breakpoint/watchpoint at address addr of size length - - @param SystemContext Register content at time of the exception - @param *PacketData Pointer to the Payload data for the packet - -**/ -VOID -EFIAPI -InsertBreakPoint ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - UINTN Type; - UINTN Address; - UINTN Length; - UINTN Register; - EFI_STATUS Status; - BREAK_TYPE BreakType = NotSupported; - UINTN ErrorCode; - - ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); - if (ErrorCode > 0) { - SendError ((UINT8)ErrorCode); - return; - } - - switch (Type) { - - case 0: //Software breakpoint - BreakType = SoftwareBreakpoint; - break; - - case 1: //Hardware breakpoint - BreakType = InstructionExecution; - break; - - case 2: //Write watchpoint - BreakType = DataWrite; - break; - - case 3: //Read watchpoint - BreakType = DataRead; - break; - - case 4: //Access watchpoint - BreakType = DataReadWrite; - break; - - default : - Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type); - SendError (GDB_EINVALIDBRKPOINTTYPE); - return; - } - - // Find next free debug register - Status = FindNextFreeDebugRegister (SystemContext, &Register); - if (EFI_ERROR(Status)) { - Print ((CHAR16 *)L"No space left on device\n"); - SendError (GDB_ENOSPACE); - return; - } - - // Write Address, length data at particular DR register - Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType); - if (EFI_ERROR(Status)) { - if (Status == EFI_UNSUPPORTED) { - SendNotSupported(); - return; - } - - SendError (GDB_EINVALIDARG); - return; - } - - SendSuccess (); -} - - -/** - ‘z1, [addr], [length]’ - ‘z2, [addr], [length]’ - ‘z3, [addr], [length]’ - ‘z4, [addr], [length]’ - - Remove hardware breakpoint/watchpoint at address addr of size length - - @param *PacketData Pointer to the Payload data for the packet - -**/ -VOID -EFIAPI -RemoveBreakPoint ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - UINTN Type; - UINTN Address; - UINTN Length; - UINTN Register; - BREAK_TYPE BreakType = NotSupported; - EFI_STATUS Status; - UINTN ErrorCode; - - //Parse breakpoint packet data - ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); - if (ErrorCode > 0) { - SendError ((UINT8)ErrorCode); - return; - } - - switch (Type) { - - case 0: //Software breakpoint - BreakType = SoftwareBreakpoint; - break; - - case 1: //Hardware breakpoint - BreakType = InstructionExecution; - break; - - case 2: //Write watchpoint - BreakType = DataWrite; - break; - - case 3: //Read watchpoint - BreakType = DataRead; - break; - - case 4: //Access watchpoint - BreakType = DataReadWrite; - break; - - default : - SendError (GDB_EINVALIDBRKPOINTTYPE); - return; - } - - //Find matching debug register - Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register); - if (EFI_ERROR(Status)) { - if (Status == EFI_UNSUPPORTED) { - SendNotSupported(); - return; - } - - SendError (GDB_ENOSPACE); - return; - } - - //Remove breakpoint - Status = DisableDebugRegister(SystemContext, Register); - if (EFI_ERROR(Status)) { - SendError (GDB_EINVALIDARG); - return; - } - - SendSuccess (); -} - - -/** - Initialize debug agent. - - This function is used to set up debug environment to support source level debugging. - If certain Debug Agent Library instance has to save some private data in the stack, - this function must work on the mode that doesn't return to the caller, then - the caller needs to wrap up all rest of logic after InitializeDebugAgent() into one - function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is - responsible to invoke the passing-in function at the end of InitializeDebugAgent(). - - If the parameter Function is not NULL, Debug Agent Libary instance will invoke it by - passing in the Context to be its parameter. - - If Function() is NULL, Debug Agent Library instance will return after setup debug - environment. - - @param[in] InitFlag Init flag is used to decide the initialize process. - @param[in] Context Context needed according to InitFlag; it was optional. - @param[in] Function Continue function called by debug agent library; it was - optional. - -**/ -VOID -EFIAPI -InitializeDebugAgent ( - IN UINT32 InitFlag, - IN VOID *Context, OPTIONAL - IN DEBUG_AGENT_CONTINUE Function OPTIONAL - ) -{ - // BugBug: Add the code to build an GDT/IDT - - if (Function != NULL) { - Function (Context); - } -} - diff --git a/EmbeddedPkg/Library/GdbDebugAgent/X64/Processor.c b/EmbeddedPkg/Library/GdbDebugAgent/X64/Processor.c deleted file mode 100755 index cbe50d78ec..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/X64/Processor.c +++ /dev/null @@ -1,963 +0,0 @@ -/** @file - Processor specific parts of the GDB stub - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include - -// -// Array of exception types that need to be hooked by the debugger -// -EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = { - { EXCEPT_X64_DIVIDE_ERROR, GDB_SIGFPE }, - { EXCEPT_X64_DEBUG, GDB_SIGTRAP }, - { EXCEPT_X64_NMI, GDB_SIGEMT }, - { EXCEPT_X64_BREAKPOINT, GDB_SIGTRAP }, - { EXCEPT_X64_OVERFLOW, GDB_SIGSEGV }, - { EXCEPT_X64_BOUND, GDB_SIGSEGV }, - { EXCEPT_X64_INVALID_OPCODE, GDB_SIGILL }, - { EXCEPT_X64_DOUBLE_FAULT, GDB_SIGEMT }, - { EXCEPT_X64_STACK_FAULT, GDB_SIGSEGV }, - { EXCEPT_X64_GP_FAULT, GDB_SIGSEGV }, - { EXCEPT_X64_PAGE_FAULT, GDB_SIGSEGV }, - { EXCEPT_X64_FP_ERROR, GDB_SIGEMT }, - { EXCEPT_X64_ALIGNMENT_CHECK, GDB_SIGEMT }, - { EXCEPT_X64_MACHINE_CHECK, GDB_SIGEMT } -}; - - -// The offsets of registers SystemContextX64. -// The fields in the array are in the gdb ordering. -// HAVE TO DOUBLE-CHECK THE ORDER of the 24 regs -// -UINTN gRegisterOffsets[] = { - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rax), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rcx), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rdx), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rbx), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rsp), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rbp), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rsi), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rdi), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rip), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rflags), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Cs), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Ss), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Ds), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Es), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Fs), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Gs), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R8), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R9), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R10), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R11), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R12), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R13), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R14), - OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R15) -}; - - -/** - Return the number of entries in the gExceptionType[] - - @retval UINTN, the number of entries in the gExceptionType[] array. - **/ -UINTN -MaxEfiException ( - VOID - ) -{ - return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY); -} - - -/** - Return the number of entries in the gRegisters[] - - @retval UINTN, the number of entries (registers) in the gRegisters[] array. - **/ -UINTN -MaxRegisterCount ( - VOID - ) -{ - return sizeof (gRegisterOffsets)/sizeof (UINTN); -} - - -/** - Check to see if the ISA is supported. - ISA = Instruction Set Architecture - - @retval TRUE if Isa is supported -**/ -BOOLEAN -CheckIsa ( - IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa - ) -{ - return (BOOLEAN)(Isa == IsaX64); -} - - -/** - This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering - It is, by default, set to find the register pointer of the X64 member - @param SystemContext Register content at time of the exception - @param RegNumber The register to which we want to find a pointer - @retval the pointer to the RegNumber-th pointer - **/ -UINTN * -FindPointerToRegister( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber - ) -{ - UINT8 *TempPtr; - TempPtr = ((UINT8 *)SystemContext.SystemContextX64) + gRegisterOffsets[RegNumber]; - return (UINTN *)TempPtr; -} - - -/** - Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr - @param SystemContext Register content at time of the exception - @param RegNumber the number of the register that we want to read - @param OutBufPtr pointer to the output buffer's end. the new data will be added from this point on. - @retval the pointer to the next character of the output buffer that is available to be written on. - **/ -CHAR8 * -BasicReadRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *OutBufPtr - ) -{ - UINTN RegSize; - - RegSize = 0; - while (RegSize < 64) { - *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)]; - *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)]; - RegSize = RegSize + 8; - } - return OutBufPtr; -} - - -/** ‘p n’ - Reads the n-th register's value into an output buffer and sends it as a packet - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ -VOID -ReadNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN RegNumber; - CHAR8 OutBuffer[17]; // 1 reg=16 hex chars, and the end '\0' (escape seq) - CHAR8 *OutBufPtr; // pointer to the output buffer - - RegNumber = AsciiStrHexToUintn (&InBuffer[1]); - - if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) { - SendError (GDB_EINVALIDREGNUM); - return; - } - - OutBufPtr = OutBuffer; - OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr); - - *OutBufPtr = '\0'; // the end of the buffer - SendPacket (OutBuffer); -} - - -/** ‘g’ - Reads the general registers into an output buffer and sends it as a packet - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -ReadGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - UINTN i; - CHAR8 OutBuffer[385]; // 24 regs, 16 hex chars each, and the end '\0' (escape seq) - CHAR8 *OutBufPtr; // pointer to the output buffer - - OutBufPtr = OutBuffer; - for(i = 0 ; i < MaxRegisterCount() ; i++) { // there are only 24 registers to read - OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr); - } - - *OutBufPtr = '\0'; // the end of the buffer - SendPacket (OutBuffer); -} - - -/** - Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr - - @param SystemContext Register content at time of the exception - @param RegNumber the number of the register that we want to write - @param InBufPtr pointer to the output buffer. the new data will be extracted from the input buffer from this point on. - @retval the pointer to the next character of the input buffer that can be used - **/ -CHAR8 * -BasicWriteRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN RegNumber, - IN CHAR8 *InBufPtr - ) -{ - UINTN RegSize; - UINTN TempValue; // the value transferred from a hex char - UINT64 NewValue; // the new value of the RegNumber-th Register - - NewValue = 0; - RegSize = 0; - while (RegSize < 64) { - TempValue = HexCharToInt(*InBufPtr++); - - if (TempValue < 0) { - SendError (GDB_EBADMEMDATA); - return NULL; - } - - NewValue += (TempValue << (RegSize+4)); - TempValue = HexCharToInt(*InBufPtr++); - - if (TempValue < 0) { - SendError (GDB_EBADMEMDATA); - return NULL; - } - - NewValue += (TempValue << RegSize); - RegSize = RegSize + 8; - } - *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue; - return InBufPtr; -} - - -/** ‘P n...=r...’ - Writes the new value of n-th register received into the input buffer to the n-th register - - @param SystemContext Register content at time of the exception - @param InBuffer Ponter to the input buffer received from gdb server - **/ -VOID -EFIAPI -WriteNthRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN RegNumber; - CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array - CHAR8 *RegNumBufPtr; - CHAR8 *InBufPtr; // pointer to the input buffer - - // find the register number to write - InBufPtr = &InBuffer[1]; - RegNumBufPtr = RegNumBuffer; - while (*InBufPtr != '=') { - *RegNumBufPtr++ = *InBufPtr++; - } - *RegNumBufPtr = '\0'; - RegNumber = AsciiStrHexToUintn (RegNumBuffer); - - // check if this is a valid Register Number - if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) { - SendError (GDB_EINVALIDREGNUM); - return; - } - InBufPtr++; // skips the '=' character - BasicWriteRegister (SystemContext, RegNumber, InBufPtr); - SendSuccess(); -} - - -/** ‘G XX...’ - Writes the new values received into the input buffer to the general registers - - @param SystemContext Register content at time of the exception - @param InBuffer Pointer to the input buffer received from gdb server - **/ -VOID -EFIAPI -WriteGeneralRegisters ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *InBuffer - ) -{ - UINTN i; - CHAR8 *InBufPtr; /// pointer to the input buffer - - // check to see if the buffer is the right size which is - // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 385 - if (AsciiStrLen(InBuffer) != 385) { // 24 regs, 16 hex chars each, and the end '\0' (escape seq) - //Bad message. Message is not the right length - SendError (GDB_EBADBUFSIZE); - return; - } - - InBufPtr = &InBuffer[1]; - - // Read the new values for the registers from the input buffer to an array, NewValueArray. - // The values in the array are in the gdb ordering - for(i=0; i < MaxRegisterCount(); i++) { // there are only 16 registers to write - InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr); - } - - SendSuccess(); -} - - - /** - Insert Single Step in the SystemContext - - @param SystemContext Register content at time of the exception - **/ -VOID -AddSingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - SystemContext.SystemContextX64->Rflags |= TF_BIT; //Setting the TF bit. -} - - - -/** - Remove Single Step in the SystemContext - - @param SystemContext Register content at time of the exception - **/ -VOID -RemoveSingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - SystemContext.SystemContextX64->Rflags &= ~TF_BIT; // clearing the TF bit. -} - - - -/** ‘c [addr ]’ - Continue. addr is Address to resume. If addr is omitted, resume at current - Address. - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -ContinueAtAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - if (PacketData[1] != '\0') { - SystemContext.SystemContextX64->Rip = AsciiStrHexToUintn(&PacketData[1]); - } -} - - -/** ‘s [addr ]’ - Single step. addr is the Address at which to resume. If addr is omitted, resume - at same Address. - - @param SystemContext Register content at time of the exception - **/ -VOID -EFIAPI -SingleStep ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - if (PacketData[1] != '\0') { - SystemContext.SystemContextX64->Rip = AsciiStrHexToUintn (&PacketData[1]); - } - - AddSingleStep (SystemContext); -} - - -/** - Returns breakpoint data address from DR0-DR3 based on the input breakpoint - number - - @param SystemContext Register content at time of the exception - @param BreakpointNumber Breakpoint number - - @retval Address Data address from DR0-DR3 based on the - breakpoint number. - -**/ -UINTN -GetBreakpointDataAddress ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN BreakpointNumber - ) -{ - UINTN Address; - - if (BreakpointNumber == 1) { - Address = SystemContext.SystemContextIa32->Dr0; - } else if (BreakpointNumber == 2) { - Address = SystemContext.SystemContextIa32->Dr1; - } else if (BreakpointNumber == 3) { - Address = SystemContext.SystemContextIa32->Dr2; - } else if (BreakpointNumber == 4) { - Address = SystemContext.SystemContextIa32->Dr3; - } else { - Address = 0; - } - - return Address; -} - -/** - Returns currently detected breakpoint value based on the register - DR6 B0-B3 field. - If no breakpoint is detected then it returns 0. - - @param SystemContext Register content at time of the exception - - @retval {1-4} Currently detected breakpoint value - @retval 0 No breakpoint detected. - -**/ -UINTN -GetBreakpointDetected ( - IN EFI_SYSTEM_CONTEXT SystemContext - ) -{ - IA32_DR6 Dr6; - UINTN BreakpointNumber; - - Dr6.UintN = SystemContext.SystemContextIa32->Dr6; - - if (Dr6.Bits.B0 == 1) { - BreakpointNumber = 1; - } else if (Dr6.Bits.B1 == 1) { - BreakpointNumber = 2; - } else if (Dr6.Bits.B2 == 1) { - BreakpointNumber = 3; - } else if (Dr6.Bits.B3 == 1) { - BreakpointNumber = 4; - } else { - BreakpointNumber = 0; //No breakpoint detected - } - - return BreakpointNumber; -} - -/** - Returns Breakpoint type (InstructionExecution, DataWrite, DataRead - or DataReadWrite) based on the Breakpoint number - - @param SystemContext Register content at time of the exception - @param BreakpointNumber Breakpoint number - - @retval BREAK_TYPE Breakpoint type value read from register DR7 RWn - field. For unknown value, it returns NotSupported. - -**/ -BREAK_TYPE -GetBreakpointType ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN BreakpointNumber - ) -{ - IA32_DR7 Dr7; - BREAK_TYPE Type = NotSupported; //Default is NotSupported type - - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (BreakpointNumber == 1) { - Type = (BREAK_TYPE) Dr7.Bits.RW0; - } else if (BreakpointNumber == 2) { - Type = (BREAK_TYPE) Dr7.Bits.RW1; - } else if (BreakpointNumber == 3) { - Type = (BREAK_TYPE) Dr7.Bits.RW2; - } else if (BreakpointNumber == 4) { - Type = (BREAK_TYPE) Dr7.Bits.RW3; - } - - return Type; -} - - -/** - Parses Length and returns the length which DR7 LENn field accepts. - For example: If we receive 1-Byte length then we should return 0. - Zero gets written to DR7 LENn field. - - @param Length Breakpoint length in Bytes (1 byte, 2 byte, 4 byte) - - @retval Length Appropriate converted values which DR7 LENn field accepts. - -**/ -UINTN -ConvertLengthData ( - IN UINTN Length - ) -{ - if (Length == 1) { //1-Byte length - return 0; - } else if (Length == 2) { //2-Byte length - return 1; - } else if (Length == 4) { //4-Byte length - return 3; - } else { //Undefined or 8-byte length - return 2; - } -} - - -/** - Finds the next free debug register. If all the registers are occupied then - EFI_OUT_OF_RESOURCES is returned. - - @param SystemContext Register content at time of the exception - @param Register Register value (0 - 3 for the first free debug register) - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -FindNextFreeDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - OUT UINTN *Register - ) -{ - IA32_DR7 Dr7; - - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (Dr7.Bits.G0 == 0) { - *Register = 0; - } else if (Dr7.Bits.G1 == 0) { - *Register = 1; - } else if (Dr7.Bits.G2 == 0) { - *Register = 2; - } else if (Dr7.Bits.G3 == 0) { - *Register = 3; - } else { - return EFI_OUT_OF_RESOURCES; - } - - return EFI_SUCCESS; -} - - -/** - Enables the debug register. Writes Address value to appropriate DR0-3 register. - Sets LENn, Gn, RWn bits in DR7 register. - - @param SystemContext Register content at time of the exception - @param Register Register value (0 - 3) - @param Address Breakpoint address value - @param Type Breakpoint type (Instruction, Data write, - Data read or write etc.) - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -EnableDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Register, - IN UINTN Address, - IN UINTN Length, - IN UINTN Type - ) -{ - IA32_DR7 Dr7; - - //Convert length data - Length = ConvertLengthData (Length); - - //For Instruction execution, length should be 0 - //(Ref. Intel reference manual 18.2.4) - if ((Type == 0) && (Length != 0)) { - return EFI_INVALID_PARAMETER; - } - - //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle - //software breakpoint. We should send empty packet in both these cases. - if ((Type == (BREAK_TYPE)DataRead) || - (Type == (BREAK_TYPE)SoftwareBreakpoint)) { - return EFI_UNSUPPORTED; - } - - //Read DR7 so appropriate Gn, RWn and LENn bits can be modified. - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (Register == 0) { - SystemContext.SystemContextIa32->Dr0 = Address; - Dr7.Bits.G0 = 1; - Dr7.Bits.RW0 = Type; - Dr7.Bits.LEN0 = Length; - } else if (Register == 1) { - SystemContext.SystemContextIa32->Dr1 = Address; - Dr7.Bits.G1 = 1; - Dr7.Bits.RW1 = Type; - Dr7.Bits.LEN1 = Length; - } else if (Register == 2) { - SystemContext.SystemContextIa32->Dr2 = Address; - Dr7.Bits.G2 = 1; - Dr7.Bits.RW2 = Type; - Dr7.Bits.LEN2 = Length; - } else if (Register == 3) { - SystemContext.SystemContextIa32->Dr3 = Address; - Dr7.Bits.G3 = 1; - Dr7.Bits.RW3 = Type; - Dr7.Bits.LEN3 = Length; - } else { - return EFI_INVALID_PARAMETER; - } - - //Update Dr7 with appropriate Gn, RWn and LENn bits - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; - - return EFI_SUCCESS; -} - - -/** - Returns register number 0 - 3 for the maching debug register. - This function compares incoming Address, Type, Length and - if there is a match then it returns the appropriate register number. - In case of mismatch, function returns EFI_NOT_FOUND message. - - @param SystemContext Register content at time of the exception - @param Address Breakpoint address value - @param Length Breakpoint length value - @param Type Breakpoint type (Instruction, Data write, Data read - or write etc.) - @param Register Register value to be returned - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -FindMatchingDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Address, - IN UINTN Length, - IN UINTN Type, - OUT UINTN *Register - ) -{ - IA32_DR7 Dr7; - - //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle - //software breakpoint. We should send empty packet in both these cases. - if ((Type == (BREAK_TYPE)DataRead) || - (Type == (BREAK_TYPE)SoftwareBreakpoint)) { - return EFI_UNSUPPORTED; - } - - //Convert length data - Length = ConvertLengthData(Length); - - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if ((Dr7.Bits.G0 == 1) && - (Dr7.Bits.LEN0 == Length) && - (Dr7.Bits.RW0 == Type) && - (Address == SystemContext.SystemContextIa32->Dr0)) { - *Register = 0; - } else if ((Dr7.Bits.G1 == 1) && - (Dr7.Bits.LEN1 == Length) && - (Dr7.Bits.RW1 == Type) && - (Address == SystemContext.SystemContextIa32->Dr1)) { - *Register = 1; - } else if ((Dr7.Bits.G2 == 1) && - (Dr7.Bits.LEN2 == Length) && - (Dr7.Bits.RW2 == Type) && - (Address == SystemContext.SystemContextIa32->Dr2)) { - *Register = 2; - } else if ((Dr7.Bits.G3 == 1) && - (Dr7.Bits.LEN3 == Length) && - (Dr7.Bits.RW3 == Type) && - (Address == SystemContext.SystemContextIa32->Dr3)) { - *Register = 3; - } else { - Print ((CHAR16 *)L"No match found..\n"); - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; -} - - -/** - Disables the particular debug register. - - @param SystemContext Register content at time of the exception - @param Register Register to be disabled - - @retval EFI_STATUS Appropriate status value. - -**/ -EFI_STATUS -DisableDebugRegister ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN UINTN Register - ) -{ - IA32_DR7 Dr7; - UINTN Address = 0; - - //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off. - Dr7.UintN = SystemContext.SystemContextIa32->Dr7; - - if (Register == 0) { - SystemContext.SystemContextIa32->Dr0 = Address; - Dr7.Bits.G0 = 0; - Dr7.Bits.RW0 = 0; - Dr7.Bits.LEN0 = 0; - } else if (Register == 1) { - SystemContext.SystemContextIa32->Dr1 = Address; - Dr7.Bits.G1 = 0; - Dr7.Bits.RW1 = 0; - Dr7.Bits.LEN1 = 0; - } else if (Register == 2) { - SystemContext.SystemContextIa32->Dr2 = Address; - Dr7.Bits.G2 = 0; - Dr7.Bits.RW2 = 0; - Dr7.Bits.LEN2 = 0; - } else if (Register == 3) { - SystemContext.SystemContextIa32->Dr3 = Address; - Dr7.Bits.G3 = 0; - Dr7.Bits.RW3 = 0; - Dr7.Bits.LEN3 = 0; - } else { - return EFI_INVALID_PARAMETER; - } - - //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off. - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; - - return EFI_SUCCESS; -} - -/** - ‘Z1, [addr], [length]’ - ‘Z2, [addr], [length]’ - ‘Z3, [addr], [length]’ - ‘Z4, [addr], [length]’ - - Insert hardware breakpoint/watchpoint at address addr of size length - - @param SystemContext Register content at time of the exception - @param *PacketData Pointer to the Payload data for the packet - -**/ -VOID -EFIAPI -InsertBreakPoint ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - UINTN Type; - UINTN Address; - UINTN Length; - UINTN Register; - EFI_STATUS Status; - BREAK_TYPE BreakType = NotSupported; - UINTN ErrorCode; - - ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); - if (ErrorCode > 0) { - SendError ((UINT8)ErrorCode); - return; - } - - switch (Type) { - - case 0: //Software breakpoint - BreakType = SoftwareBreakpoint; - break; - - case 1: //Hardware breakpoint - BreakType = InstructionExecution; - break; - - case 2: //Write watchpoint - BreakType = DataWrite; - break; - - case 3: //Read watchpoint - BreakType = DataRead; - break; - - case 4: //Access watchpoint - BreakType = DataReadWrite; - break; - - default : - Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type); - SendError (GDB_EINVALIDBRKPOINTTYPE); - return; - } - - // Find next free debug register - Status = FindNextFreeDebugRegister (SystemContext, &Register); - if (EFI_ERROR(Status)) { - Print ((CHAR16 *)L"No space left on device\n"); - SendError (GDB_ENOSPACE); - return; - } - - // Write Address, length data at particular DR register - Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType); - if (EFI_ERROR(Status)) { - - if (Status == EFI_UNSUPPORTED) { - Print ((CHAR16 *)L"Not supported\n"); - SendNotSupported(); - return; - } - - Print ((CHAR16 *)L"Invalid argument\n"); - SendError (GDB_EINVALIDARG); - return; - } - - SendSuccess (); -} - - -/** - ‘z1, [addr], [length]’ - ‘z2, [addr], [length]’ - ‘z3, [addr], [length]’ - ‘z4, [addr], [length]’ - - Remove hardware breakpoint/watchpoint at address addr of size length - - @param *PacketData Pointer to the Payload data for the packet - -**/ -VOID -EFIAPI -RemoveBreakPoint ( - IN EFI_SYSTEM_CONTEXT SystemContext, - IN CHAR8 *PacketData - ) -{ - UINTN Type; - UINTN Address; - UINTN Length; - UINTN Register; - BREAK_TYPE BreakType = NotSupported; - EFI_STATUS Status; - UINTN ErrorCode; - - //Parse breakpoint packet data - ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length); - if (ErrorCode > 0) { - SendError ((UINT8)ErrorCode); - return; - } - - switch (Type) { - - case 0: //Software breakpoint - BreakType = SoftwareBreakpoint; - break; - - case 1: //Hardware breakpoint - BreakType = InstructionExecution; - break; - - case 2: //Write watchpoint - BreakType = DataWrite; - break; - - case 3: //Read watchpoint - BreakType = DataRead; - break; - - case 4: //Access watchpoint - BreakType = DataReadWrite; - break; - - default : - SendError (GDB_EINVALIDBRKPOINTTYPE); - return; - } - - //Find matching debug register - Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register); - if (EFI_ERROR(Status)) { - - if (Status == EFI_UNSUPPORTED) { - Print ((CHAR16 *)L"Not supported.\n"); - SendNotSupported(); - return; - } - - Print ((CHAR16 *)L"No matching register found.\n"); - SendError (GDB_ENOSPACE); - return; - } - - //Remove breakpoint - Status = DisableDebugRegister(SystemContext, Register); - if (EFI_ERROR(Status)) { - Print ((CHAR16 *)L"Invalid argument.\n"); - SendError (GDB_EINVALIDARG); - return; - } - - SendSuccess (); -} - - -VOID -InitializeProcessor ( - VOID - ) -{ -} - -BOOLEAN -ValidateAddress ( - IN VOID *Address - ) -{ - return TRUE; -} - -BOOLEAN -ValidateException ( - IN EFI_EXCEPTION_TYPE ExceptionType, - IN OUT EFI_SYSTEM_CONTEXT SystemContext - ) -{ - return TRUE; -} - diff --git a/EmbeddedPkg/Library/GdbDebugAgent/gdbnotes.txt b/EmbeddedPkg/Library/GdbDebugAgent/gdbnotes.txt deleted file mode 100755 index 287b09e6a8..0000000000 --- a/EmbeddedPkg/Library/GdbDebugAgent/gdbnotes.txt +++ /dev/null @@ -1,15 +0,0 @@ -arm-none-eabi-gcc -march=armv7-a -mthumb t.c -Wl,-nostdlib --emit-relocs - -target remote com7 -set debug remote 1 -set remotetimeout 30 -set remotelogfile log.txt -add-symbol-file c:/work/edk2/Build/BeagleBoard/DEBUG_GCC48/ARM/BeagleBoardPkg/Sec/Sec/DEBUG/BeagleBoardSec.dll 0x80008360 - - -qSupported -Hg0 - -Hc-1 -qC -qAttached \ No newline at end of file diff --git a/EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.c b/EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.c deleted file mode 100644 index e3d1b47cc4..0000000000 --- a/EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.c +++ /dev/null @@ -1,187 +0,0 @@ -/** @file - Basic serial IO abstaction for GDB - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include -#include -#include -#include -#include - -#include - - -EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL; -UINTN gTimeOut = 0; - -/** - The constructor function initializes the UART. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -GdbSerialLibDebugPortConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - - Status = gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **)&gDebugPort); - if (!EFI_ERROR (Status)) { - gTimeOut = PcdGet32 (PcdGdbMaxPacketRetryCount); - gDebugPort->Reset (gDebugPort); - } - - return Status; -} - - - -/** - Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, - data buts, and stop bits on a serial device. This call is optional as the serial - port will be set up with defaults base on PCD values. - - @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the - device's default interface speed. - @param Parity The type of parity to use on this serial device. A Parity value of - DefaultParity will use the device's default parity value. - @param DataBits The number of data bits to use on the serial device. A DataBits - vaule of 0 will use the device's default data bit setting. - @param StopBits The number of stop bits to use on this serial device. A StopBits - value of DefaultStopBits will use the device's default number of - stop bits. - - @retval EFI_SUCCESS The device was configured. - @retval EFI_DEVICE_ERROR The serial device could not be coonfigured. - -**/ -RETURN_STATUS -EFIAPI -GdbSerialInit ( - IN UINT64 BaudRate, - IN UINT8 Parity, - IN UINT8 DataBits, - IN UINT8 StopBits - ) -{ - EFI_STATUS Status; - - Status = gDebugPort->Reset (gDebugPort); - return Status; -} - - -/** - Check to see if a character is available from GDB. Do not read the character as that is - done via GdbGetChar(). - - @return TRUE - Character availible - @return FALSE - Character not availible - -**/ -BOOLEAN -EFIAPI -GdbIsCharAvailable ( - VOID - ) -{ - EFI_STATUS Status; - - Status = gDebugPort->Poll (gDebugPort); - - return (Status == EFI_SUCCESS ? TRUE : FALSE); -} - - -/** - Get a character from GDB. This function must be able to run in interrupt context. - - @return A character from GDB - -**/ -CHAR8 -EFIAPI -GdbGetChar ( - VOID - ) -{ - EFI_STATUS Status; - CHAR8 Char; - UINTN BufferSize; - - do { - BufferSize = sizeof (Char); - Status = gDebugPort->Read (gDebugPort, gTimeOut, &BufferSize, &Char); - } while (EFI_ERROR (Status) || BufferSize != sizeof (Char)); - - return Char; -} - - -/** - Send a character to GDB. This function must be able to run in interrupt context. - - - @param Char Send a character to GDB - -**/ - -VOID -EFIAPI -GdbPutChar ( - IN CHAR8 Char - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - - do { - BufferSize = sizeof (Char); - Status = gDebugPort->Write (gDebugPort, gTimeOut, &BufferSize, &Char); - } while (EFI_ERROR (Status) || BufferSize != sizeof (Char)); - - return; -} - -/** - Send an ASCII string to GDB. This function must be able to run in interrupt context. - - - @param String Send a string to GDB - -**/ - -VOID -GdbPutString ( - IN CHAR8 *String - ) -{ - // We could performance enhance this function by calling gDebugPort->Write () - while (*String != '\0') { - GdbPutChar (*String); - String++; - } -} - - - - diff --git a/EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.inf b/EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.inf deleted file mode 100644 index b7c289c5a3..0000000000 --- a/EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.inf +++ /dev/null @@ -1,49 +0,0 @@ -#/** @file -# Component description file for Base PCI Cf8 Library. -# -# PCI CF8 Library that uses I/O ports 0xCF8 and 0xCFC to perform PCI Configuration cycles. -# Layers on top of an I/O Library instance. -# Copyright (c) 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = GdbSerialDebugPortLib - FILE_GUID = 42ABB10A-660A-4BEC-AEFA-CC94AB4D993D - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = GdbSerialLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER - - CONSTRUCTOR = GdbSerialLibDebugPortConstructor - - -[Sources.common] - GdbSerialDebugPortLib.c - - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - DebugLib - IoLib - -[Protocols.common] - gEfiDebugPortProtocolGuid - -[FixedPcd.common] - gEmbeddedTokenSpaceGuid.PcdGdbBaudRate|115200 - gEmbeddedTokenSpaceGuid.PcdGdbDataBits|8 - gEmbeddedTokenSpaceGuid.PcdGdbParity|1 - gEmbeddedTokenSpaceGuid.PcdGdbStopBits|1 - gEmbeddedTokenSpaceGuid.PcdGdbMaxPacketRetryCount diff --git a/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c b/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c deleted file mode 100644 index 7ea976ff9d..0000000000 --- a/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c +++ /dev/null @@ -1,262 +0,0 @@ -/** @file - Basic serial IO abstaction for GDB - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include -#include -#include -#include - - -//--------------------------------------------- -// UART Register Offsets -//--------------------------------------------- -#define BAUD_LOW_OFFSET 0x00 -#define BAUD_HIGH_OFFSET 0x01 -#define IER_OFFSET 0x01 -#define LCR_SHADOW_OFFSET 0x01 -#define FCR_SHADOW_OFFSET 0x02 -#define IR_CONTROL_OFFSET 0x02 -#define FCR_OFFSET 0x02 -#define EIR_OFFSET 0x02 -#define BSR_OFFSET 0x03 -#define LCR_OFFSET 0x03 -#define MCR_OFFSET 0x04 -#define LSR_OFFSET 0x05 -#define MSR_OFFSET 0x06 - -//--------------------------------------------- -// UART Register Bit Defines -//--------------------------------------------- -#define LSR_TXRDY 0x20 -#define LSR_RXDA 0x01 -#define DLAB 0x01 -#define ENABLE_FIFO 0x01 -#define CLEAR_FIFOS 0x06 - - - -// IO Port Base for the UART -UINTN gPort; - - -/** - The constructor function initializes the UART. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -GdbSerialLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - UINT64 BaudRate; - UINT8 DataBits; - UINT8 Parity; - UINT8 StopBits; - - gPort = (UINTN)PcdGet32 (PcdGdbUartPort); - - BaudRate = PcdGet64 (PcdGdbBaudRate); - Parity = PcdGet8 (PcdGdbParity); - DataBits = PcdGet8 (PcdGdbDataBits); - StopBits = PcdGet8 (PcdGdbStopBits); - - return GdbSerialInit (BaudRate, Parity, DataBits, StopBits); -} - - - -/** - Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, - data buts, and stop bits on a serial device. This call is optional as the serial - port will be set up with defaults base on PCD values. - - @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the - device's default interface speed. - @param Parity The type of parity to use on this serial device. A Parity value of - DefaultParity will use the device's default parity value. - @param DataBits The number of data bits to use on the serial device. A DataBits - vaule of 0 will use the device's default data bit setting. - @param StopBits The number of stop bits to use on this serial device. A StopBits - value of DefaultStopBits will use the device's default number of - stop bits. - - @retval EFI_SUCCESS The device was configured. - @retval EFI_DEVICE_ERROR The serial device could not be coonfigured. - -**/ -RETURN_STATUS -EFIAPI -GdbSerialInit ( - IN UINT64 BaudRate, - IN UINT8 Parity, - IN UINT8 DataBits, - IN UINT8 StopBits - ) -{ - UINTN Divisor; - UINT8 OutputData; - UINT8 Data; - UINT8 BreakSet = 0; - - // - // We assume the UART has been turned on to decode gPort address range - // - - // - // Map 5..8 to 0..3 - // - Data = (UINT8) (DataBits - (UINT8)5); - - // - // Calculate divisor for baud generator - // - Divisor = 115200/(UINTN)BaudRate; - - // - // Set communications format - // - OutputData = (UINT8)((DLAB << 7) | ((BreakSet << 6) | ((Parity << 3) | ((StopBits << 2) | Data)))); - IoWrite8 (gPort + LCR_OFFSET, OutputData); - - // - // Configure baud rate - // - IoWrite8 (gPort + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8)); - IoWrite8 (gPort + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff)); - - - // - // Switch back to bank 0 - // - OutputData = (UINT8)((~DLAB<<7)|((BreakSet<<6)|((Parity<<3)|((StopBits<<2)| Data)))); - IoWrite8 (gPort + LCR_OFFSET, OutputData); - - // Not sure this is the right place to enable the FIFOs.... - // We probably need the FIFO enabled to not drop input - IoWrite8 (gPort + FCR_SHADOW_OFFSET, ENABLE_FIFO); - - - // Configure the UART hardware here - return RETURN_SUCCESS; -} - - -/** - Check to see if a character is available from GDB. Do not read the character as that is - done via GdbGetChar(). - - @return TRUE - Character availible - @return FALSE - Character not availible - -**/ -BOOLEAN -EFIAPI -GdbIsCharAvailable ( - VOID - ) -{ - UINT8 Data; - - Data = IoRead8 (gPort + LSR_OFFSET); - - return ((Data & LSR_RXDA) == LSR_RXDA); -} - - -/** - Get a character from GDB. This function must be able to run in interrupt context. - - @return A character from GDB - -**/ -CHAR8 -EFIAPI -GdbGetChar ( - VOID - ) -{ - UINT8 Data; - CHAR8 Char; - - // Wait for the serial port to be ready - do { - Data = IoRead8 (gPort + LSR_OFFSET); - } while ((Data & LSR_RXDA) == 0); - - Char = IoRead8 (gPort); - - // Make this an EFI_D_INFO after we get everything debugged. - DEBUG ((EFI_D_ERROR, "<%c<", Char)); - return Char; -} - - -/** - Send a character to GDB. This function must be able to run in interrupt context. - - - @param Char Send a character to GDB - -**/ - -VOID -EFIAPI -GdbPutChar ( - IN CHAR8 Char - ) -{ - UINT8 Data; - - // Make this an EFI_D_INFO after we get everything debugged. - DEBUG ((EFI_D_ERROR, ">%c>", Char)); - - // Wait for the serial port to be ready - do { - Data = IoRead8 (gPort + LSR_OFFSET); - } while ((Data & LSR_TXRDY) == 0); - - IoWrite8 (gPort, Char); -} - -/** - Send an ASCII string to GDB. This function must be able to run in interrupt context. - - - @param String Send a string to GDB - -**/ - -VOID -GdbPutString ( - IN CHAR8 *String - ) -{ - while (*String != '\0') { - GdbPutChar (*String); - String++; - } -} - - - - diff --git a/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf b/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf deleted file mode 100644 index fed36b059d..0000000000 --- a/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.inf +++ /dev/null @@ -1,46 +0,0 @@ -#/** @file -# Component description file for Base PCI Cf8 Library. -# -# PCI CF8 Library that uses I/O ports 0xCF8 and 0xCFC to perform PCI Configuration cycles. -# Layers on top of an I/O Library instance. -# Copyright (c) 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = GdbSerialLib - FILE_GUID = 9999B4EE-081F-4501-AEDC-137A534BAF69 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = GdbSerialLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER - - CONSTRUCTOR = GdbSerialLibConstructor - - -[Sources.common] - GdbSerialLib.c - - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - DebugLib - IoLib - -[FixedPcd.common] - gEmbeddedTokenSpaceGuid.PcdGdbBaudRate|115200 - gEmbeddedTokenSpaceGuid.PcdGdbDataBits|8 - gEmbeddedTokenSpaceGuid.PcdGdbParity|1 - gEmbeddedTokenSpaceGuid.PcdGdbStopBits|1 - gEmbeddedTokenSpaceGuid.PcdGdbUartPort diff --git a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Capsule.c b/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Capsule.c deleted file mode 100644 index ec89cfdeec..0000000000 --- a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Capsule.c +++ /dev/null @@ -1,288 +0,0 @@ -/** @file - Generic Capsule services - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include - - -// -//Max size capsule services support are platform policy,to populate capsules we just need -//memory to maintain them across reset,it is not a problem. And to special capsules ,for -//example,update flash,it is mostly decided by the platform. Here is a sample size for -//different type capsules. -// -#define MAX_SIZE_POPULATE (0) -#define MAX_SIZE_NON_POPULATE (0) -#define MAX_SUPPORT_CAPSULE_NUM 0x10 - - -BOOLEAN -EFIAPI -SupportUpdateCapsuleRest ( - VOID - ) -{ - // - //If the platform has a way to guarantee the memory integrity across a system reset, return - //TRUE, else FALSE. - // - return FALSE; -} - - - -VOID -EFIAPI -SupportCapsuleSize ( - IN OUT UINT32 *MaxSizePopulate, - IN OUT UINT32 *MaxSizeNonPopulate - ) -{ - // - //Here is a sample size, different platforms have different sizes. - // - *MaxSizePopulate = MAX_SIZE_POPULATE; - *MaxSizeNonPopulate = MAX_SIZE_NON_POPULATE; - return; -} - - - - -EFI_STATUS -LibUpdateCapsule ( - IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray, - IN UINTN CapsuleCount, - IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL - ) -/*++ - -Routine Description: - - This code finds if the capsule needs reset to update, if no, update immediately. - -Arguments: - - CapsuleHeaderArray A array of pointers to capsule headers passed in - CapsuleCount The number of capsule - ScatterGatherList Physical address of datablock list points to capsule - -Returns: - - EFI STATUS - EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is - not set, the capsule has been successfully processed by the firmware. - If it set, the ScattlerGatherList is successfully to be set. - EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported. - EFI_DEVICE_ERROR Failed to SetVariable or AllocatePool or ProcessFirmwareVolume. - ---*/ -{ - UINTN CapsuleSize; - UINTN ArrayNumber; - VOID *BufferPtr; - EFI_STATUS Status; - EFI_HANDLE FvHandle; - UEFI_CAPSULE_HEADER *CapsuleHeader; - - if ((CapsuleCount < 1) || (CapsuleCount > MAX_SUPPORT_CAPSULE_NUM)){ - return EFI_INVALID_PARAMETER; - } - - BufferPtr = NULL; - CapsuleHeader = NULL; - - // - //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET - //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports. - // - for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) { - CapsuleHeader = CapsuleHeaderArray[ArrayNumber]; - if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) { - return EFI_INVALID_PARAMETER; - } - if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiCapsuleGuid)) { - if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) { - return EFI_UNSUPPORTED; - } - } - } - - // - //Assume that capsules have the same flags on reseting or not. - // - CapsuleHeader = CapsuleHeaderArray[0]; - - if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) { - // - //Check if the platform supports update capsule across a system reset - // - if (!SupportUpdateCapsuleRest()) { - return EFI_UNSUPPORTED; - } - - if (ScatterGatherList == 0) { - return EFI_INVALID_PARAMETER; - } else { - Status = EfiSetVariable ( - EFI_CAPSULE_VARIABLE_NAME, - &gEfiCapsuleVendorGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, - sizeof (UINTN), - (VOID *) &ScatterGatherList - ); - if (Status != EFI_SUCCESS) { - return EFI_DEVICE_ERROR; - } - } - return EFI_SUCCESS; - } - - // - //The rest occurs in the condition of non-reset mode - // - if (EfiAtRuntime ()) { - return EFI_INVALID_PARAMETER; - } - - // - //Here should be in the boot-time - // - for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) { - CapsuleHeader = CapsuleHeaderArray[ArrayNumber]; - CapsuleSize = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize; - Status = gBS->AllocatePool (EfiBootServicesData, CapsuleSize, &BufferPtr); - if (Status != EFI_SUCCESS) { - goto Done; - } - gBS->CopyMem (BufferPtr, (UINT8*)CapsuleHeader+ CapsuleHeader->HeaderSize, CapsuleSize); - - // - //Call DXE service ProcessFirmwareVolume to process immediatelly - // - Status = gDS->ProcessFirmwareVolume (BufferPtr, CapsuleSize, &FvHandle); - if (Status != EFI_SUCCESS) { - gBS->FreePool (BufferPtr); - return EFI_DEVICE_ERROR; - } - gDS->Dispatch (); - gBS->FreePool (BufferPtr); - } - return EFI_SUCCESS; - -Done: - if (BufferPtr != NULL) { - gBS->FreePool (BufferPtr); - } - return EFI_DEVICE_ERROR; -} - - -EFI_STATUS -QueryCapsuleCapabilities ( - IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray, - IN UINTN CapsuleCount, - OUT UINT64 *MaxiumCapsuleSize, - OUT EFI_RESET_TYPE *ResetType - ) -/*++ - -Routine Description: - - This code is query about capsule capability. - -Arguments: - - CapsuleHeaderArray A array of pointers to capsule headers passed in - CapsuleCount The number of capsule - MaxiumCapsuleSize Max capsule size is supported - ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold. - If reset is needed, return EfiResetWarm. - -Returns: - - EFI STATUS - EFI_SUCCESS Valid answer returned - EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported. - EFI_UNSUPPORTED The capsule type is not supported. - ---*/ -{ - UINTN ArrayNumber; - UEFI_CAPSULE_HEADER *CapsuleHeader; - UINT32 MaxSizePopulate; - UINT32 MaxSizeNonPopulate; - - - if ((CapsuleCount < 1) || (CapsuleCount > MAX_SUPPORT_CAPSULE_NUM)){ - return EFI_INVALID_PARAMETER; - } - - if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) { - return EFI_INVALID_PARAMETER; - } - - CapsuleHeader = NULL; - - // - //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET - //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports. - // - for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) { - CapsuleHeader = CapsuleHeaderArray[ArrayNumber]; - if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) { - return EFI_INVALID_PARAMETER; - } - if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiCapsuleGuid)) { - if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) { - return EFI_UNSUPPORTED; - } - } - } - - SupportCapsuleSize(&MaxSizePopulate,&MaxSizeNonPopulate); - // - //Assume that capsules have the same flags on reseting or not. - // - CapsuleHeader = CapsuleHeaderArray[0]; - if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) { - // - //Check if the platform supports update capsule across a system reset - // - if (!SupportUpdateCapsuleRest()) { - return EFI_UNSUPPORTED; - } - *ResetType = EfiResetWarm; - *MaxiumCapsuleSize = MaxSizePopulate; - } else { - *ResetType = EfiResetCold; - *MaxiumCapsuleSize = MaxSizeNonPopulate; - } - return EFI_SUCCESS; -} - - -VOID -LibCapsuleVirtualAddressChangeEvent ( - VOID - ) -{ -} - -VOID -LibCapsuleInitialize ( - VOID - ) -{ -} diff --git a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Mtc.c b/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Mtc.c deleted file mode 100644 index 2b60d07203..0000000000 --- a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Mtc.c +++ /dev/null @@ -1,226 +0,0 @@ -/** @file - Generic Monotonic Counter services - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. 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. - - -**/ - - -// -// The current Monotonic count value -// -UINT64 mEfiMtc = 0; - - -// -// Event to use to update the Mtc's high part when wrapping -// -EFI_EVENT mEfiMtcEvent; - -// -// EfiMtcName - Variable name of the MTC value -// -CHAR16 *mEfiMtcName = L"MTC"; - -// -// EfiMtcGuid - Guid of the MTC value -// -EFI_GUID mEfiMtcGuid = { 0xeb704011, 0x1402, 0x11d3, { 0x8e, 0x77, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } }; - - - -// -// Worker functions -// - - -VOID -EFIAPI -EfiMtcEventHandler ( - IN EFI_EVENT Event, - IN VOID *Context - ) -/*++ - -Routine Description: - - Monotonic count event handler. This handler updates the high monotonic count. - -Arguments: - - Event The event to handle - Context The event context - -Returns: - - EFI_SUCCESS The event has been handled properly - EFI_NOT_FOUND An error occurred updating the variable. - ---*/ -{ - UINT32 HighCount; - - EfiGetNextHighMonotonicCount (&HighCount); - return; -} - - - -VOID -LibMtcVirtualAddressChangeEvent (VOID) -{ -} - - -EFI_STATUS -EFIAPI -LibMtcGetNextHighMonotonicCount ( - OUT UINT32 *HighCount - ) -{ - EFI_STATUS Status; - EFI_TPL OldTpl; - - // - // Check input parameters - // - if (HighCount == NULL) { - return EFI_INVALID_PARAMETER; - } - - - if (!EfiAtRuntime ()) { - // Use a lock if called before ExitBootServices() - OldTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL); - } - - *HighCount = (UINT32) RShiftU64 (mEfiMtc, 32) + 1; - mEfiMtc = LShiftU64 (*HighCount, 32); - - if (!EfiAtRuntime ()) { - gBS->RestoreTPL (OldTpl); - } - - // - // Update the NvRam store to match the new high part - // - Status = EfiSetVariable ( - mEfiMtcName, - &mEfiMtcGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, - sizeof (UINT32), - HighCount - ); - - return Status; -} - - -EFI_STATUS -LibMtcGetNextMonotonicCount ( - OUT UINT64 *Count - ) -{ - EFI_STATUS Status; - EFI_TPL OldTpl; - UINT32 HighCount; - UINTN BufferSize; - - // - // Can not be called after ExitBootServices() - // - if (EfiAtRuntime ()) { - return EFI_UNSUPPORTED; - } - - // - // Check input parameters - // - if (Count == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (mEfiMtc == 0) { - // - // If the MTC has not been initialized read the variable - // - - // - // Read the last high part - // - BufferSize = sizeof (UINT32); - Status = EfiGetVariable ( - mEfiMtcName, - &mEfiMtcGuid, - NULL, - &BufferSize, - &HighCount - ); - if (EFI_ERROR (Status)) { - HighCount = 0; - } - - // - // Set the current value - // - mEfiMtc = LShiftU64 (HighCount, 32); - // - // Increment the upper 32 bits for this boot - // Continue even if it fails. It will only fail if the variable services are - // not functional. - // - Status = EfiGetNextHighMonotonicCount (&HighCount); - } - - - // - // Update the monotonic counter with a lock - // - OldTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL); - *Count = mEfiMtc; - mEfiMtc++; - gBS->RestoreTPL (OldTpl); - - // - // If the MSB bit of the low part toggled, then signal that the high - // part needs updated now - // - if ((((UINT32) mEfiMtc) ^ ((UINT32) *Count)) & 0x80000000) { - gBS->SignalEvent (mEfiMtcEvent); - } - - return EFI_SUCCESS; -} - - - -VOID -LibMtcInitialize ( - VOID - ) -{ - EFI_STATUS Status; - - // - // Initialize event to handle overflows - // - Status = gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - EFI_TPL_CALLBACK, - EfiMtcEventHandler, - NULL, - &mEfiMtcEvent - ); - ASSERT_EFI_ERROR (Status); -} - diff --git a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/ReportStatusCode.c b/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/ReportStatusCode.c deleted file mode 100644 index e2d5500ae0..0000000000 --- a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/ReportStatusCode.c +++ /dev/null @@ -1,198 +0,0 @@ -/** @file - Report status code lib on top of either SerialLib and/or EFI Serial Protocol. - Based on PcdStatusCodeUseEfiSerial & PcdStatusCodeUseHardSerial settings - - There is just a single runtime memory buffer that contans all the data. - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. 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. - - -**/ - -//////////#include "DxeStatusCode.h" - - -EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol = NULL; - - -EFI_STATUS -LibReportStatusCode ( - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value, - IN UINT32 Instance, - IN EFI_GUID *CallerId, - IN EFI_STATUS_CODE_DATA *Data OPTIONAL - ) -{ - CHAR8 *Filename; - CHAR8 *Description; - CHAR8 *Format; - CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE]; - UINT32 ErrorLevel; - UINT32 LineNumber; - UINTN CharCount; - VA_LIST Marker; - EFI_DEBUG_INFO *DebugInfo; - EFI_TPL CurrentTpl; - - - if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) { - if (EfiAtRuntime ()) { - return EFI_DEVICE_ERROR; - } - CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL); - gBS->RestoreTPL (CurrentTpl); - - if (CurrentTpl > EFI_TPL_CALLBACK ) { - return EFI_DEVICE_ERROR; - } - } - - Buffer[0] = '\0'; - - if (Data != NULL && - ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) { - // - // Print ASSERT() information into output buffer. - // - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "\n\rDXE_ASSERT!: %a (%d): %a\n\r", - Filename, - LineNumber, - Description - ); - } else if (Data != NULL && - ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) { - // - // Print DEBUG() information into output buffer. - // - CharCount = AsciiVSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - Format, - Marker - ); - } else if (Data != NULL && - CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) && - (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) { - // - // Print specific data into output buffer. - // - DebugInfo = (EFI_DEBUG_INFO *) (Data + 1); - Marker = (VA_LIST) (DebugInfo + 1); - Format = (CHAR8 *) (((UINT64 *) (DebugInfo + 1)) + 12); - - CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker); - } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) { - // - // Print ERROR information into output buffer. - // - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "ERROR: C%x:V%x I%x", - CodeType, - Value, - Instance - ); - - // - // Make sure we don't try to print values that weren't - // intended to be printed, especially NULL GUID pointers. - // - - if (CallerId != NULL) { - CharCount += AsciiSPrint ( - &Buffer[CharCount - 1], - (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)), - " %g", - CallerId - ); - } - - if (Data != NULL) { - CharCount += AsciiSPrint ( - &Buffer[CharCount - 1], - (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)), - " %x", - Data - ); - } - - CharCount += AsciiSPrint ( - &Buffer[CharCount - 1], - (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)), - "\n\r" - ); - } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) { - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "PROGRESS CODE: V%x I%x\n\r", - Value, - Instance - ); - } else { - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "Undefined: C%x:V%x I%x\n\r", - CodeType, - Value, - Instance - ); - } - - - if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) { - // - // Callout to SerialPort Lib function to do print. - // - SerialPortWrite ((UINT8 *) Buffer, CharCount); - } - if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) { - if (mSerialIoProtocol == NULL) { - gBS->LocateProtocol (&gEfiSerialIoProtocolGuid, NULL, (VOID **) &mSerialIoProtocol); - } - - if (mSerialIoProtocol == NULL) { - mSerialIoProtocol->Write ( - mSerialIoProtocol, - &CharCount, - Buffer - ); - } - } - - return EFI_SUCCESS; -} - - -VOID -LibReportStatusCodeVirtualAddressChangeEvent ( - VOID - ) -{ - return; -} - -VOID -LibReportStatusCodeInitialize ( - VOID - ) -{ - return; -} - - - diff --git a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Reset.c b/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Reset.c deleted file mode 100644 index c6ae1f0c32..0000000000 --- a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Reset.c +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - Simple PC Port 0x92 reset driver - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. 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. - - -**/ - - - -VOID -LibResetInitializeReset ( - VOID - ) -{ -} - -VOID -LibResetVirtualAddressChangeEvent ( - VOID - ) -{ -} - - -VOID -LibResetSystem ( - IN EFI_RESET_TYPE ResetType, - IN EFI_STATUS ResetStatus, - IN UINTN DataSize, - IN CHAR16 *ResetData OPTIONAL - ) -{ - UINT8 Data; - - switch (ResetType) { - case EfiResetWarm: - case EfiResetCold: - case EfiResetShutdown: - Data = IoRead8 (0x92); - Data |= 1; - IoWrite8 (0x92, Data); - break; - - default: - return ; - } - - // - // Given we should have reset getting here would be bad - // - ASSERT (FALSE); -} - diff --git a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Rtc.c b/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Rtc.c deleted file mode 100644 index c35d72c03c..0000000000 --- a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Rtc.c +++ /dev/null @@ -1,862 +0,0 @@ -/** @file - Simple PC RTC - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Copyright (c) 2014, ARM Ltd. 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. - - -**/ - - - -typedef struct { - EFI_LOCK RtcLock; - UINT16 SavedTimeZone; - UINT8 Daylight; -} PC_RTC_GLOBALS; - -#define PCAT_RTC_ADDRESS_REGISTER 0x70 -#define PCAT_RTC_DATA_REGISTER 0x71 - -// -// Dallas DS12C887 Real Time Clock -// -#define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59 -#define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59 -#define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59 -#define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59 -#define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM -#define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM -#define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7 -#define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31 -#define RTC_ADDRESS_MONTH 8 // R/W Range 1..12 -#define RTC_ADDRESS_YEAR 9 // R/W Range 0..99 -#define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7] -#define RTC_ADDRESS_REGISTER_B 11 // R/W -#define RTC_ADDRESS_REGISTER_C 12 // RO -#define RTC_ADDRESS_REGISTER_D 13 // RO -#define RTC_ADDRESS_CENTURY 50 // R/W Range 19..20 Bit 8 is R/W -// -// Date and time initial values. -// They are used if the RTC values are invalid during driver initialization -// -#define RTC_INIT_SECOND 0 -#define RTC_INIT_MINUTE 0 -#define RTC_INIT_HOUR 0 -#define RTC_INIT_DAY 1 -#define RTC_INIT_MONTH 1 -#define RTC_INIT_YEAR 2001 - -// -// Register initial values -// -#define RTC_INIT_REGISTER_A 0x26 -#define RTC_INIT_REGISTER_B 0x02 -#define RTC_INIT_REGISTER_D 0x0 - -#pragma pack(1) -// -// Register A -// -typedef struct { - UINT8 RS : 4; // Rate Selection Bits - UINT8 DV : 3; // Divisor - UINT8 UIP : 1; // Update in progress -} RTC_REGISTER_A_BITS; - -typedef union { - RTC_REGISTER_A_BITS Bits; - UINT8 Data; -} RTC_REGISTER_A; - -// -// Register B -// -typedef struct { - UINT8 DSE : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled - UINT8 MIL : 1; // 0 - 12 hour mode 1 - 24 hour mode - UINT8 DM : 1; // 0 - BCD Format 1 - Binary Format - UINT8 SQWE : 1; // 0 - Disable SQWE output 1 - Enable SQWE output - UINT8 UIE : 1; // 0 - Update INT disabled 1 - Update INT enabled - UINT8 AIE : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled - UINT8 PIE : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled - UINT8 SET : 1; // 0 - Normal operation. 1 - Updates inhibited -} RTC_REGISTER_B_BITS; - -typedef union { - RTC_REGISTER_B_BITS Bits; - UINT8 Data; -} RTC_REGISTER_B; - -// -// Register C -// -typedef struct { - UINT8 Reserved : 4; // Read as zero. Can not be written. - UINT8 UF : 1; // Update End Interrupt Flag - UINT8 AF : 1; // Alarm Interrupt Flag - UINT8 PF : 1; // Periodic Interrupt Flag - UINT8 IRQF : 1; // Iterrupt Request Flag = PF & PIE | AF & AIE | UF & UIE -} RTC_REGISTER_C_BITS; - -typedef union { - RTC_REGISTER_C_BITS Bits; - UINT8 Data; -} RTC_REGISTER_C; - -// -// Register D -// -typedef struct { - UINT8 Reserved : 7; // Read as zero. Can not be written. - UINT8 VRT : 1; // Valid RAM and Time -} RTC_REGISTER_D_BITS; - -typedef union { - RTC_REGISTER_D_BITS Bits; - UINT8 Data; -} RTC_REGISTER_D; - -#pragma pack() - -PC_RTC_GLOBALS mRtc; - -BOOLEAN -IsLeapYear ( - IN EFI_TIME *Time - ) -{ - if (Time->Year % 4 == 0) { - if (Time->Year % 100 == 0) { - if (Time->Year % 400 == 0) { - return TRUE; - } else { - return FALSE; - } - } else { - return TRUE; - } - } else { - return FALSE; - } -} - - -const INTN mDayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - -BOOLEAN -DayValid ( - IN EFI_TIME *Time - ) -{ - if (Time->Day < 1 || - Time->Day > mDayOfMonth[Time->Month - 1] || - (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28)) - ) { - return FALSE; - } - - return TRUE; -} - - -UINT8 -DecimaltoBcd ( - IN UINT8 DecValue - ) -{ - UINTN High; - UINTN Low; - - High = DecValue / 10; - Low = DecValue - (High * 10); - - return (UINT8) (Low + (High << 4)); -} - -UINT8 -BcdToDecimal ( - IN UINT8 BcdValue - ) -{ - UINTN High; - UINTN Low; - - High = BcdValue >> 4; - Low = BcdValue - (High << 4); - - return (UINT8) (Low + (High * 10)); -} - - - - -VOID -ConvertEfiTimeToRtcTime ( - IN EFI_TIME *Time, - IN RTC_REGISTER_B RegisterB, - IN UINT8 *Century - ) -{ - BOOLEAN PM; - - PM = TRUE; - // - // Adjust hour field if RTC in in 12 hour mode - // - if (RegisterB.Bits.MIL == 0) { - if (Time->Hour < 12) { - PM = FALSE; - } - - if (Time->Hour >= 13) { - Time->Hour = (UINT8) (Time->Hour - 12); - } else if (Time->Hour == 0) { - Time->Hour = 12; - } - } - // - // Set the Time/Date/Daylight Savings values. - // - *Century = DecimaltoBcd ((UINT8) (Time->Year / 100)); - - Time->Year = (UINT16) (Time->Year % 100); - - if (RegisterB.Bits.DM == 0) { - Time->Year = DecimaltoBcd ((UINT8) Time->Year); - Time->Month = DecimaltoBcd (Time->Month); - Time->Day = DecimaltoBcd (Time->Day); - Time->Hour = DecimaltoBcd (Time->Hour); - Time->Minute = DecimaltoBcd (Time->Minute); - Time->Second = DecimaltoBcd (Time->Second); - } - // - // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field. - // - if (RegisterB.Bits.MIL == 0 && PM) { - Time->Hour = (UINT8) (Time->Hour | 0x80); - } -} - -/** - Check the validity of all the fields of a data structure of type EFI_TIME - - @param[in] Time Pointer to a data structure of type EFI_TIME that defines a date and time - - @retval EFI_SUCCESS All date and time fields are valid - @retval EFI_INVALID_PARAMETER At least one date or time field is not valid -**/ -EFI_STATUS -RtcTimeFieldsValid ( - IN EFI_TIME *Time - ) -{ - if ((Time->Year < 1998 ) || - (Time->Year > 2099 ) || - (Time->Month < 1 ) || - (Time->Month > 12 ) || - (!DayValid (Time)) || - (Time->Hour > 23 ) || - (Time->Minute > 59 ) || - (Time->Second > 59 ) || - (Time->Nanosecond > 999999999) || - ((Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) && - ((Time->TimeZone < -1440) || - (Time->TimeZone > 1440 ) ) ) || - (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | - EFI_TIME_IN_DAYLIGHT ))) - ) { - return EFI_INVALID_PARAMETER; - } - - return EFI_SUCCESS; -} - -UINT8 -RtcRead ( - IN UINT8 Address - ) -{ - IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80))); - return IoRead8 (PCAT_RTC_DATA_REGISTER); -} - -VOID -RtcWrite ( - IN UINT8 Address, - IN UINT8 Data - ) -{ - IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, (UINT8) (Address | (UINT8) (IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80))); - IoWrite8 (PCAT_RTC_DATA_REGISTER, Data); -} - - -EFI_STATUS -RtcTestCenturyRegister ( - VOID - ) -{ - UINT8 Century; - UINT8 Temp; - - Century = RtcRead (RTC_ADDRESS_CENTURY); - // - // RtcWrite (RTC_ADDRESS_CENTURY, 0x00); - // - Temp = (UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f); - RtcWrite (RTC_ADDRESS_CENTURY, Century); - if (Temp == 0x19 || Temp == 0x20) { - return EFI_SUCCESS; - } - - return EFI_DEVICE_ERROR; -} - -VOID -ConvertRtcTimeToEfiTime ( - IN EFI_TIME *Time, - IN RTC_REGISTER_B RegisterB - ) -{ - BOOLEAN PM; - - if ((Time->Hour) & 0x80) { - PM = TRUE; - } else { - PM = FALSE; - } - - Time->Hour = (UINT8) (Time->Hour & 0x7f); - - if (RegisterB.Bits.DM == 0) { - Time->Year = BcdToDecimal ((UINT8) Time->Year); - Time->Month = BcdToDecimal (Time->Month); - Time->Day = BcdToDecimal (Time->Day); - Time->Hour = BcdToDecimal (Time->Hour); - Time->Minute = BcdToDecimal (Time->Minute); - Time->Second = BcdToDecimal (Time->Second); - } - // - // If time is in 12 hour format, convert it to 24 hour format - // - if (RegisterB.Bits.MIL == 0) { - if (PM && Time->Hour < 12) { - Time->Hour = (UINT8) (Time->Hour + 12); - } - - if (!PM && Time->Hour == 12) { - Time->Hour = 0; - } - } - - Time->Nanosecond = 0; - Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE; - Time->Daylight = 0; -} - -EFI_STATUS -RtcWaitToUpdate ( - UINTN Timeout - ) -{ - RTC_REGISTER_A RegisterA; - RTC_REGISTER_D RegisterD; - - // - // See if the RTC is functioning correctly - // - RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D); - - if (RegisterD.Bits.VRT == 0) { - return EFI_DEVICE_ERROR; - } - // - // Wait for up to 0.1 seconds for the RTC to be ready. - // - Timeout = (Timeout / 10) + 1; - RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); - while (RegisterA.Bits.UIP == 1 && Timeout > 0) { - MicroSecondDelay (10); - RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); - Timeout--; - } - - RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D); - if (Timeout == 0 || RegisterD.Bits.VRT == 0) { - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; -} - -EFI_STATUS -LibGetTime ( - OUT EFI_TIME *Time, - OUT EFI_TIME_CAPABILITIES *Capabilities - ) -{ - EFI_STATUS Status; - RTC_REGISTER_B RegisterB; - UINT8 Century; - UINTN BufferSize; - - // - // Check parameters for null pointer - // - if (Time == NULL) { - return EFI_INVALID_PARAMETER; - - } - // - // Acquire RTC Lock to make access to RTC atomic - // - EfiAcquireLock (&mRtc.RtcLock); - - // - // Wait for up to 0.1 seconds for the RTC to be updated - // - Status = RtcWaitToUpdate (100000); - if (EFI_ERROR (Status)) { - EfiReleaseLock (&mRtc.RtcLock); - return Status; - } - // - // Read Register B - // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - - // - // Get the Time/Date/Daylight Savings values. - // - Time->Second = RtcRead (RTC_ADDRESS_SECONDS); - Time->Minute = RtcRead (RTC_ADDRESS_MINUTES); - Time->Hour = RtcRead (RTC_ADDRESS_HOURS); - Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - Time->Month = RtcRead (RTC_ADDRESS_MONTH); - Time->Year = RtcRead (RTC_ADDRESS_YEAR); - - ConvertRtcTimeToEfiTime (Time, RegisterB); - - if (RtcTestCenturyRegister () == EFI_SUCCESS) { - Century = BcdToDecimal ((UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f)); - } else { - Century = BcdToDecimal (RtcRead (RTC_ADDRESS_CENTURY)); - } - - Time->Year = (UINT16) (Century * 100 + Time->Year); - - // - // Release RTC Lock. - // - EfiReleaseLock (&mRtc.RtcLock); - - // - // Get the variable that containts the TimeZone and Daylight fields - // - Time->TimeZone = mRtc.SavedTimeZone; - Time->Daylight = mRtc.Daylight; - - BufferSize = sizeof (INT16) + sizeof (UINT8); - - // - // Make sure all field values are in correct range - // - Status = RtcTimeFieldsValid (Time); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - // - // Fill in Capabilities if it was passed in - // - if (Capabilities) { - Capabilities->Resolution = 1; - // - // 1 hertz - // - Capabilities->Accuracy = 50000000; - // - // 50 ppm - // - Capabilities->SetsToZero = FALSE; - } - - return EFI_SUCCESS; -} - - - -EFI_STATUS -LibSetTime ( - IN EFI_TIME *Time - ) -{ - EFI_STATUS Status; - EFI_TIME RtcTime; - RTC_REGISTER_B RegisterB; - UINT8 Century; - - if (Time == NULL) { - return EFI_INVALID_PARAMETER; - } - // - // Make sure that the time fields are valid - // - Status = RtcTimeFieldsValid (Time); - if (EFI_ERROR (Status)) { - return Status; - } - - CopyMem (&RtcTime, Time, sizeof (EFI_TIME)); - - // - // Acquire RTC Lock to make access to RTC atomic - // - EfiAcquireLock (&mRtc.RtcLock); - - // - // Wait for up to 0.1 seconds for the RTC to be updated - // - Status = RtcWaitToUpdate (100000); - if (EFI_ERROR (Status)) { - EfiReleaseLock (&mRtc.RtcLock); - return Status; - } - // - // Read Register B, and inhibit updates of the RTC - // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - RegisterB.Bits.SET = 1; - RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - - ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century); - - RtcWrite (RTC_ADDRESS_SECONDS, RtcTime.Second); - RtcWrite (RTC_ADDRESS_MINUTES, RtcTime.Minute); - RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour); - RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day); - RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month); - RtcWrite (RTC_ADDRESS_YEAR, (UINT8) RtcTime.Year); - if (RtcTestCenturyRegister () == EFI_SUCCESS) { - Century = (UINT8) ((Century & 0x7f) | (RtcRead (RTC_ADDRESS_CENTURY) & 0x80)); - } - - RtcWrite (RTC_ADDRESS_CENTURY, Century); - - // - // Allow updates of the RTC registers - // - RegisterB.Bits.SET = 0; - RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - - // - // Release RTC Lock. - // - EfiReleaseLock (&mRtc.RtcLock); - - // - // Set the variable that containts the TimeZone and Daylight fields - // - mRtc.SavedTimeZone = Time->TimeZone; - mRtc.Daylight = Time->Daylight; - return Status; -} - -EFI_STATUS -libGetWakeupTime ( - OUT BOOLEAN *Enabled, - OUT BOOLEAN *Pending, - OUT EFI_TIME *Time - ) -{ - EFI_STATUS Status; - RTC_REGISTER_B RegisterB; - RTC_REGISTER_C RegisterC; - UINT8 Century; - - // - // Check paramters for null pointers - // - if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) { - return EFI_INVALID_PARAMETER; - - } - // - // Acquire RTC Lock to make access to RTC atomic - // - EfiAcquireLock (&mRtc.RtcLock); - - // - // Wait for up to 0.1 seconds for the RTC to be updated - // - Status = RtcWaitToUpdate (100000); - if (EFI_ERROR (Status)) { - EfiReleaseLock (&mRtc.RtcLock); - return EFI_DEVICE_ERROR; - } - // - // Read Register B and Register C - // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C); - - // - // Get the Time/Date/Daylight Savings values. - // - *Enabled = RegisterB.Bits.AIE; - if (*Enabled) { - Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); - Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); - Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); - Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - Time->Month = RtcRead (RTC_ADDRESS_MONTH); - Time->Year = RtcRead (RTC_ADDRESS_YEAR); - } else { - Time->Second = 0; - Time->Minute = 0; - Time->Hour = 0; - Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - Time->Month = RtcRead (RTC_ADDRESS_MONTH); - Time->Year = RtcRead (RTC_ADDRESS_YEAR); - } - - ConvertRtcTimeToEfiTime (Time, RegisterB); - - if (RtcTestCenturyRegister () == EFI_SUCCESS) { - Century = BcdToDecimal ((UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f)); - } else { - Century = BcdToDecimal (RtcRead (RTC_ADDRESS_CENTURY)); - } - - Time->Year = (UINT16) (Century * 100 + Time->Year); - - // - // Release RTC Lock. - // - EfiReleaseLock (&mRtc.RtcLock); - - // - // Make sure all field values are in correct range - // - Status = RtcTimeFieldsValid (Time); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - *Pending = RegisterC.Bits.AF; - - return EFI_SUCCESS; -} - -EFI_STATUS -LibSetWakeupTime ( - IN BOOLEAN Enabled, - OUT EFI_TIME *Time - ) -{ - EFI_STATUS Status; - EFI_TIME RtcTime; - RTC_REGISTER_B RegisterB; - UINT8 Century; - EFI_TIME_CAPABILITIES Capabilities; - - if (Enabled) { - - if (Time == NULL) { - return EFI_INVALID_PARAMETER; - } - // - // Make sure that the time fields are valid - // - Status = RtcTimeFieldsValid (Time); - if (EFI_ERROR (Status)) { - return EFI_INVALID_PARAMETER; - } - // - // Just support set alarm time within 24 hours - // - LibGetTime (&RtcTime, &Capabilities); - if (Time->Year != RtcTime.Year || - Time->Month != RtcTime.Month || - (Time->Day != RtcTime.Day && Time->Day != (RtcTime.Day + 1)) - ) { - return EFI_UNSUPPORTED; - } - // - // Make a local copy of the time and date - // - CopyMem (&RtcTime, Time, sizeof (EFI_TIME)); - - } - // - // Acquire RTC Lock to make access to RTC atomic - // - EfiAcquireLock (&mRtc.RtcLock); - - // - // Wait for up to 0.1 seconds for the RTC to be updated - // - Status = RtcWaitToUpdate (100000); - if (EFI_ERROR (Status)) { - EfiReleaseLock (&mRtc.RtcLock); - return EFI_DEVICE_ERROR; - } - // - // Read Register B, and inhibit updates of the RTC - // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - - RegisterB.Bits.SET = 1; - RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - - if (Enabled) { - ConvertEfiTimeToRtcTime (&RtcTime, RegisterB, &Century); - - // - // Set RTC alarm time - // - RtcWrite (RTC_ADDRESS_SECONDS_ALARM, RtcTime.Second); - RtcWrite (RTC_ADDRESS_MINUTES_ALARM, RtcTime.Minute); - RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour); - - RegisterB.Bits.AIE = 1; - - } else { - RegisterB.Bits.AIE = 0; - } - // - // Allow updates of the RTC registers - // - RegisterB.Bits.SET = 0; - RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); - - // - // Release RTC Lock. - // - EfiReleaseLock (&mRtc.RtcLock); - - return EFI_SUCCESS; -} - - - -VOID -LibRtcVirtualAddressChangeEvent ( - VOID - ) -{ -} - - -VOID -LibRtcInitialize ( - VOID - ) -{ - EFI_STATUS Status; - RTC_REGISTER_A RegisterA; - RTC_REGISTER_B RegisterB; - RTC_REGISTER_C RegisterC; - RTC_REGISTER_D RegisterD; - UINT8 Century; - EFI_TIME Time; - - // - // Acquire RTC Lock to make access to RTC atomic - // - EfiAcquireLock (&mRtc.RtcLock); - - // - // Initialize RTC Register - // - // Make sure Division Chain is properly configured, - // or RTC clock won't "tick" -- time won't increment - // - RegisterA.Data = RTC_INIT_REGISTER_A; - RtcWrite (RTC_ADDRESS_REGISTER_A, RegisterA.Data); - - // - // Read Register B - // - RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); - - // - // Clear RTC flag register - // - RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C); - - // - // Clear RTC register D - // - RegisterD.Data = RTC_INIT_REGISTER_D; - RtcWrite (RTC_ADDRESS_REGISTER_D, RegisterD.Data); - - // - // Wait for up to 0.1 seconds for the RTC to be updated - // - Status = RtcWaitToUpdate (100000); - if (EFI_ERROR (Status)) { - EfiReleaseLock (&mRtc.RtcLock); - return; - } - - // - // Get the Time/Date/Daylight Savings values. - // - Time.Second = RtcRead (RTC_ADDRESS_SECONDS); - Time.Minute = RtcRead (RTC_ADDRESS_MINUTES); - Time.Hour = RtcRead (RTC_ADDRESS_HOURS); - Time.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); - Time.Month = RtcRead (RTC_ADDRESS_MONTH); - Time.Year = RtcRead (RTC_ADDRESS_YEAR); - - ConvertRtcTimeToEfiTime (&Time, RegisterB); - - if (RtcTestCenturyRegister () == EFI_SUCCESS) { - Century = BcdToDecimal ((UINT8) (RtcRead (RTC_ADDRESS_CENTURY) & 0x7f)); - } else { - Century = BcdToDecimal (RtcRead (RTC_ADDRESS_CENTURY)); - } - - Time.Year = (UINT16) (Century * 100 + Time.Year); - - // - // Set RTC configuration after get original time - // - RtcWrite (RTC_ADDRESS_REGISTER_B, RTC_INIT_REGISTER_B); - - // - // Release RTC Lock. - // - EfiReleaseLock (&mRtc.RtcLock); - - // - // Validate time fields - // - Status = RtcTimeFieldsValid (&Time); - if (EFI_ERROR (Status)) { - Time.Second = RTC_INIT_SECOND; - Time.Minute = RTC_INIT_MINUTE; - Time.Hour = RTC_INIT_HOUR; - Time.Day = RTC_INIT_DAY; - Time.Month = RTC_INIT_MONTH; - Time.Year = RTC_INIT_YEAR; - } - // - // Reset time value according to new RTC configuration - // - LibSetTime (&Time); - - return; -} - - diff --git a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Variable.c b/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Variable.c deleted file mode 100644 index 0c1b76a4bb..0000000000 --- a/EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Variable.c +++ /dev/null @@ -1,306 +0,0 @@ -/** @file - Variable services implemented from system memory - - There is just a single runtime memory buffer that contans all the data. - - Copyright (c) 2007, Intel Corporation. All rights reserved.
- Portions copyright (c) 2008 - 2009, Apple Inc. 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. - - -**/ - - -UINT64 mMaximumVariableStorageSize; -UINT64 mRemainingVariableStorageSize; -UINT64 mMaximumVariableSize; - -typedef struct { - EFI_GUID VendorGuid; - UINT32 Attribute; - UINTN DataSize; -} VARIABLE_ARRAY_ENTRY; -// CHAR16 VariableName[] -// UINT8 Data[] - -VARIABLE_ARRAY_ENTRY *mVariableArray = NULL; -VARIABLE_ARRAY_ENTRY *mVariableArrayNextFree = NULL; -VARIABLE_ARRAY_ENTRY *mVariableArrayEnd = NULL; - - -VARIABLE_ARRAY_ENTRY * -AddEntry ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - UINTN Size; - UINTN SizeOfString; - VARIABLE_ARRAY_ENTRY *Entry; - EFI_TPL CurrentTpl; - - - SizeOfString = StrSize (VariableName); - Size = SizeOfString + sizeof (VARIABLE_ARRAY_ENTRY) + DataSize; - if ((VARIABLE_ARRAY_ENTRY *)(((UINT8 *)mVariableArrayNextFree) + Size) > mVariableArrayEnd) { - // ran out of space - return NULL; - } - - if (!EfiAtRuntime ()) { - // Enter critical section - CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL); - } - - Entry = mVariableArrayNextFree; - CopyGuid (&Entry->VendorGuid, VendorGuid); - Entry->Attribute = Attributes; - Entry->DataSize = DataSize; - StrCpy ((CHAR16 *)++mVariableArrayNextFree, VariableName); - mVariableArrayNextFree = (VARIABLE_ARRAY_ENTRY *)(((UINT8 *)mVariableArrayNextFree) + SizeOfString); - CopyMem (mVariableArrayNextFree, Data, DataSize); - mVariableArrayNextFree = (VARIABLE_ARRAY_ENTRY *)(((UINT8 *)mVariableArrayNextFree) + DataSize); - - if (!EfiAtRuntime ()) { - // Exit Critical section - gBS->RestoreTPL (CurrentTpl); - } - - return Entry; -} - -VOID -DeleteEntry ( - IN VARIABLE_ARRAY_ENTRY *Entry - ) -{ - UINTN Size; - UINT8 *Data; - EFI_TPL CurrentTpl; - - Size = StrSize ((CHAR16 *)(Entry + 1)) + sizeof (VARIABLE_ARRAY_ENTRY) + Entry->DataSize; - Data = ((UINT8 *)Entry) + Size; - - CopyMem (Entry, Data, (UINTN)mVariableArrayNextFree - (UINTN)Data); - - if (!EfiAtRuntime ()) { - // Enter critical section - CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL); - } - - mVariableArrayNextFree = (VARIABLE_ARRAY_ENTRY *)(((UINT8 *)mVariableArrayNextFree) - Size); - - if (!EfiAtRuntime ()) { - // Exit Critical section - gBS->RestoreTPL (CurrentTpl); - } -} - - -VARIABLE_ARRAY_ENTRY * -GetVariableArrayEntry ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - OUT VOID **Data OPTIONAL - ) -{ - VARIABLE_ARRAY_ENTRY *Entry; - UINTN Size; - - if (*VariableName == L'\0') { - // by definition first entry is null-terminated string - if (mVariableArray == mVariableArrayNextFree) { - return NULL; - } - return mVariableArray; - } - - for (Entry = mVariableArray; Entry < mVariableArrayEnd;) { - if (CompareGuid (VendorGuid, &Entry->VendorGuid)) { - if (StrCmp (VariableName, (CHAR16 *)(Entry + 1))) { - Size = StrSize ((CHAR16 *)(Entry + 1)); - if (Data != NULL) { - *Data = (VOID *)(((UINT8 *)Entry) + (Size + sizeof (VARIABLE_ARRAY_ENTRY))); - } - return Entry; - } - } - - Size = StrSize ((CHAR16 *)(Entry + 1)) + sizeof (VARIABLE_ARRAY_ENTRY) + Entry->DataSize; - Entry = (VARIABLE_ARRAY_ENTRY *)(((UINT8 *)Entry) + Size); - } - - return NULL; -} - - -EFI_STATUS -LibGetVariable ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - OUT UINT32 *Attributes OPTIONAL, - IN OUT UINTN *DataSize, - OUT VOID *Data - ) -{ - VARIABLE_ARRAY_ENTRY *Entry; - VOID *InternalData; - - if (EfiAtRuntime () && (Attributes != NULL)) { - if ((*Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) { - return EFI_NOT_FOUND; - } - } - - Entry = GetVariableArrayEntry (VariableName, VendorGuid, &InternalData); - if (Entry == NULL) { - return EFI_NOT_FOUND; - } - - if (*DataSize < Entry->DataSize) { - *DataSize = Entry->DataSize; - return EFI_BUFFER_TOO_SMALL; - } - - *DataSize = Entry->DataSize; - if (Attributes != NULL) { - *Attributes = Entry->Attribute; - } - - CopyMem (Data, InternalData, *DataSize); - return EFI_SUCCESS; -} - - -EFI_STATUS -LibGetNextVariableName ( - IN OUT UINTN *VariableNameSize, - IN OUT CHAR16 *VariableName, - IN OUT EFI_GUID *VendorGuid - ) -{ - VARIABLE_ARRAY_ENTRY *Entry; - VOID *InternalData; - UINTN StringSize; - BOOLEAN Done; - - for (Done = FALSE; !Done; ) { - Entry = GetVariableArrayEntry (VariableName, VendorGuid, &InternalData); - if (Entry == NULL) { - return EFI_NOT_FOUND; - } - - // If we are at runtime skip variables that do not have the Runitme attribute set. - Done = (EfiAtRuntime () && ((Entry->Attribute & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) ? FALSE : TRUE; - } - - StringSize = StrSize ((CHAR16 *)(Entry + 1)); - Entry = (VARIABLE_ARRAY_ENTRY *)(((UINT8 *)Entry) + (StringSize + sizeof (VARIABLE_ARRAY_ENTRY) + Entry->DataSize)); - if (Entry >= mVariableArrayEnd) { - return EFI_NOT_FOUND; - } - - if (*VariableNameSize < StringSize) { - *VariableNameSize = StringSize; - return EFI_BUFFER_TOO_SMALL; - } - - *VariableNameSize = StringSize; - CopyMem (VariableName, (CHAR16 *)(Entry + 1), StringSize); - CopyMem (VendorGuid, &Entry->VendorGuid, sizeof (EFI_GUID)); - return EFI_SUCCESS; -} - - - -EFI_STATUS -LibSetVariable ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN UINT32 Attributes, - IN UINTN DataSize, - IN VOID *Data - ) -{ - VARIABLE_ARRAY_ENTRY *Entry; - VOID *InternalData; - - if (EfiAtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) { - return EFI_NOT_FOUND; - } - - Entry = GetVariableArrayEntry (VariableName, VendorGuid, &InternalData); - if (Entry == NULL) { - if (DataSize == 0) { - return EFI_NOT_FOUND; - } - Entry = AddEntry (VariableName, VendorGuid, Attributes, DataSize, Data); - return (Entry == NULL) ? EFI_OUT_OF_RESOURCES : EFI_SUCCESS; - - } else if (DataSize == 0) { - // DataSize is zero so delete - DeleteEntry (Entry); - } else if (DataSize == Entry->DataSize) { - // No change is size so just update the store - Entry->Attribute |= Attributes; - CopyMem (InternalData, Data, DataSize); - } else { - // Grow the entry by deleting and adding back. Don't lose previous Attributes - Attributes |= Entry->Attribute; - DeleteEntry (Entry); - Entry = AddEntry (VariableName, VendorGuid, Attributes, DataSize, Data); - return (Entry == NULL) ? EFI_OUT_OF_RESOURCES : EFI_SUCCESS; - } -} - - -EFI_STATUS -LibQueryVariableInfo ( - IN UINT32 Attributes, - OUT UINT64 *MaximumVariableStorageSize, - OUT UINT64 *RemainingVariableStorageSize, - OUT UINT64 *MaximumVariableSize - ) -{ - *MaximumVariableStorageSize = mMaximumVariableStorageSize; - *RemainingVariableStorageSize = mRemainingVariableStorageSize; - *MaximumVariableStorageSize = mRemainingVariableStorageSize; - return EFI_SUCCESS; -} - - -VOID -LibVariableVirtualAddressChangeEvent (VOID) -{ - EfiConvertPointer (0, (VOID **)&mVariableArray); - EfiConvertPointer (0, (VOID **)&mVariableArrayNextFree); - EfiConvertPointer (0, (VOID **)&mVariableArrayEnd); -} - - -VOID -LibVariableInitialize (VOID) -{ - UINTN Size; - - Size = PcdGet32 (PcdEmbeddedMemVariableStoreSize); - mVariableArray = mVariableArrayNextFree = (VARIABLE_ARRAY_ENTRY *)AllocateRuntimePool (Size); - ASSERT (mVariableArray != NULL); - - mVariableArrayEnd = (VARIABLE_ARRAY_ENTRY *)(((UINT8 *)mVariableArray) + Size); - - mMaximumVariableStorageSize = Size - sizeof (VARIABLE_ARRAY_ENTRY); - mRemainingVariableStorageSize = mMaximumVariableStorageSize; - mMaximumVariableSize = mMaximumVariableStorageSize; -} - diff --git a/EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.c b/EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.c deleted file mode 100644 index 2a91a98ba8..0000000000 --- a/EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.c +++ /dev/null @@ -1,50 +0,0 @@ -/** @file - LZMA Decompress GUIDed Section Extraction Library. - It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces - and registers them into GUIDed handler table. - - Copyright (c) 2009, 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. - -**/ - -#include -#include -#include - -#include -#include - - -/** - Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid. - - @retval RETURN_SUCCESS Register successfully. - @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler. -**/ -EFI_STATUS -EFIAPI -LzmaDecompressLibConstructor ( - ) -{ - EXTRACT_SECTION_HOB *Hob; - - Hob = GetFirstGuidHob (&gLzmaCustomDecompressGuid); - if (Hob == NULL) { - return EFI_NOT_FOUND; - } - - // Locate Guided Hob - - return ExtractGuidedSectionRegisterHandlers ( - &gLzmaCustomDecompressGuid, - Hob->Data.SectionGetInfo, - Hob->Data.SectionExtraction - ); -} diff --git a/EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf b/EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf deleted file mode 100644 index d64f5a3ff0..0000000000 --- a/EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf +++ /dev/null @@ -1,50 +0,0 @@ -#/** @file -# LzmaCustomDecompressLib produces LZMA custom decompression algorithm. -# -# It is based on the LZMA SDK 4.65. -# LZMA SDK 4.65 was placed in the public domain on 2009-02-03. -# It was released on the http://www.7-zip.org/sdk.html website. -# -# Copyright (c) 2009, 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = LzmaDecompressLib - FILE_GUID = 35194660-7421-44ad-9636-e44885f092d1 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = NULL - CONSTRUCTOR = LzmaDecompressLibConstructor - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - LzmaHobCustomDecompressLib.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[Guids] - gLzmaCustomDecompressGuid ## PRODUCED ## GUID specifies LZMA custom decompress algorithm. - -[LibraryClasses] - DebugLib - HobLib - ExtractGuidedSectionLib - diff --git a/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c b/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c deleted file mode 100755 index a0bb57541d..0000000000 --- a/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c +++ /dev/null @@ -1,149 +0,0 @@ -/** @file - Generic ARM implementation of DmaLib.h - - Copyright (c) 2008 - 2010, Apple Inc. 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. - -**/ - -#include -#include -#include -#include - - - -/** - Provides the DMA controller-specific addresses needed to access system memory. - - Operation is relative to the DMA bus master. - - @param Operation Indicates if the bus master is going to read or write to system memory. - @param HostAddress The system memory address to map to the DMA controller. - @param NumberOfBytes On input the number of bytes to map. On output the number of bytes - that were mapped. - @param DeviceAddress The resulting map address for the bus master controller to use to - access the hosts HostAddress. - @param Mapping A resulting value to pass to Unmap(). - - @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes. - @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. - @retval EFI_DEVICE_ERROR The system hardware could not map the requested address. - -**/ -EFI_STATUS -EFIAPI -DmaMap ( - IN DMA_MAP_OPERATION Operation, - IN VOID *HostAddress, - IN OUT UINTN *NumberOfBytes, - OUT PHYSICAL_ADDRESS *DeviceAddress, - OUT VOID **Mapping - ) -{ - *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress; - *Mapping = NULL; - return EFI_SUCCESS; -} - - -/** - Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer() - operation and releases any corresponding resources. - - @param Mapping The mapping value returned from DmaMap*(). - - @retval EFI_SUCCESS The range was unmapped. - @retval EFI_DEVICE_ERROR The data was not committed to the target system memory. - -**/ -EFI_STATUS -EFIAPI -DmaUnmap ( - IN VOID *Mapping - ) -{ - return EFI_SUCCESS; -} - -/** - Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer. - mapping. - - @param MemoryType The type of memory to allocate, EfiBootServicesData or - EfiRuntimeServicesData. - @param Pages The number of pages to allocate. - @param HostAddress A pointer to store the base system memory address of the - allocated range. - - @retval EFI_SUCCESS The requested memory pages were allocated. - @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are - MEMORY_WRITE_COMBINE and MEMORY_CACHED. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. - -**/ -EFI_STATUS -EFIAPI -DmaAllocateBuffer ( - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN Pages, - OUT VOID **HostAddress - ) -{ - if (HostAddress == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData - // - // We used uncached memory to keep coherency - // - if (MemoryType == EfiBootServicesData) { - *HostAddress = AllocatePages (Pages); - } else if (MemoryType != EfiRuntimeServicesData) { - *HostAddress = AllocateRuntimePages (Pages); - } else { - return EFI_INVALID_PARAMETER; - } - - return EFI_SUCCESS; -} - - -/** - Frees memory that was allocated with DmaAllocateBuffer(). - - @param Pages The number of pages to free. - @param HostAddress The base system memory address of the allocated range. - - @retval EFI_SUCCESS The requested memory pages were freed. - @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages - was not allocated with DmaAllocateBuffer(). - -**/ -EFI_STATUS -EFIAPI -DmaFreeBuffer ( - IN UINTN Pages, - IN VOID *HostAddress - ) -{ - if (HostAddress == NULL) { - return EFI_INVALID_PARAMETER; - } - - FreePages (HostAddress, Pages); - return EFI_SUCCESS; -} - diff --git a/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf b/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf deleted file mode 100755 index 38261d5ede..0000000000 --- a/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf +++ /dev/null @@ -1,41 +0,0 @@ -#/** @file -# -# Copyright (c) 2008 - 2010, Apple Inc. 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. -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = NullDmaLib - FILE_GUID = 0F2A0816-D319-4ee7-A6B8-D58524E4428F - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = DmaLib - -[Sources.common] - NullDmaLib.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - DebugLib - MemoryAllocationLib - - -[Protocols] - -[Guids] - -[Pcd] - -[Depex] - TRUE diff --git a/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c b/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c deleted file mode 100644 index cee15c4be2..0000000000 --- a/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c +++ /dev/null @@ -1,247 +0,0 @@ -/** @file - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include -#include -#include -#include -#include - -#define PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID { 0x385A982C, 0x2F49, 0x4043, { 0xA5, 0x1E, 0x49, 0x01, 0x02, 0x5C, 0x8B, 0x6B }} - -typedef struct { - UINT32 NumberOfExtractHandler; - GUID *ExtractHandlerGuidTable; - EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable; - EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable; -} PRE_PI_EXTRACT_GUIDED_SECTION_DATA; - -PRE_PI_EXTRACT_GUIDED_SECTION_DATA * -GetSavedData ( - VOID - ) -{ - EFI_HOB_GUID_TYPE *GuidHob; - GUID SavedDataGuid = PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID; - - GuidHob = GetFirstGuidHob(&SavedDataGuid); - GuidHob++; - - return (PRE_PI_EXTRACT_GUIDED_SECTION_DATA *)GuidHob; -} - -RETURN_STATUS -EFIAPI -ExtractGuidedSectionRegisterHandlers ( - IN CONST GUID *SectionGuid, - IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler, - IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler - ) -{ - PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData; - UINT32 Index; - // - // Check input paramter. - // - if (SectionGuid == NULL) { - return RETURN_INVALID_PARAMETER; - } - - SavedData = GetSavedData(); - - // - // Search the match registered GetInfo handler for the input guided section. - // - for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index ++) { - if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], SectionGuid)) { - break; - } - } - - // - // If the guided handler has been registered before, only update its handler. - // - if (Index < SavedData->NumberOfExtractHandler) { - SavedData->ExtractDecodeHandlerTable [Index] = DecodeHandler; - SavedData->ExtractGetInfoHandlerTable [Index] = GetInfoHandler; - return RETURN_SUCCESS; - } - - // - // Check the global table is enough to contain new Handler. - // - if (SavedData->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) { - return RETURN_OUT_OF_RESOURCES; - } - - // - // Register new Handler and guid value. - // - CopyGuid (&SavedData->ExtractHandlerGuidTable [SavedData->NumberOfExtractHandler], SectionGuid); - SavedData->ExtractDecodeHandlerTable [SavedData->NumberOfExtractHandler] = DecodeHandler; - SavedData->ExtractGetInfoHandlerTable [SavedData->NumberOfExtractHandler++] = GetInfoHandler; - - return RETURN_SUCCESS; -} - -UINTN -EFIAPI -ExtractGuidedSectionGetGuidList ( - IN OUT GUID **ExtractHandlerGuidTable - ) -{ - PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData; - - ASSERT(ExtractHandlerGuidTable != NULL); - - SavedData = GetSavedData(); - - *ExtractHandlerGuidTable = SavedData->ExtractHandlerGuidTable; - return SavedData->NumberOfExtractHandler; -} - -RETURN_STATUS -EFIAPI -ExtractGuidedSectionGetInfo ( - IN CONST VOID *InputSection, - OUT UINT32 *OutputBufferSize, - OUT UINT32 *ScratchBufferSize, - OUT UINT16 *SectionAttribute - ) -{ - PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData; - UINT32 Index; - - if (InputSection == NULL) { - return RETURN_INVALID_PARAMETER; - } - - ASSERT (OutputBufferSize != NULL); - ASSERT (ScratchBufferSize != NULL); - ASSERT (SectionAttribute != NULL); - - SavedData = GetSavedData(); - - // - // Search the match registered GetInfo handler for the input guided section. - // - for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index ++) { - if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) { - break; - } - } - - // - // Not found, the input guided section is not supported. - // - if (Index == SavedData->NumberOfExtractHandler) { - return RETURN_INVALID_PARAMETER; - } - - // - // Call the match handler to getinfo for the input section data. - // - return SavedData->ExtractGetInfoHandlerTable [Index] ( - InputSection, - OutputBufferSize, - ScratchBufferSize, - SectionAttribute - ); -} - -RETURN_STATUS -EFIAPI -ExtractGuidedSectionDecode ( - IN CONST VOID *InputSection, - OUT VOID **OutputBuffer, - OUT VOID *ScratchBuffer, OPTIONAL - OUT UINT32 *AuthenticationStatus - ) -{ - PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData; - UINT32 Index; - - if (InputSection == NULL) { - return RETURN_INVALID_PARAMETER; - } - - ASSERT (OutputBuffer != NULL); - ASSERT (AuthenticationStatus != NULL); - - SavedData = GetSavedData(); - - // - // Search the match registered GetInfo handler for the input guided section. - // - for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index ++) { - if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) { - break; - } - } - - // - // Not found, the input guided section is not supported. - // - if (Index == SavedData->NumberOfExtractHandler) { - return RETURN_INVALID_PARAMETER; - } - - // - // Call the match handler to getinfo for the input section data. - // - return SavedData->ExtractDecodeHandlerTable [Index] ( - InputSection, - OutputBuffer, - ScratchBuffer, - AuthenticationStatus - ); -} - -RETURN_STATUS -EFIAPI -ExtractGuidedSectionLibConstructor ( - VOID - ) -{ - PRE_PI_EXTRACT_GUIDED_SECTION_DATA SavedData; - GUID HobGuid = PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID; - - // - // Allocate global pool space to store the registered handler and its guid value. - // - SavedData.ExtractHandlerGuidTable = (GUID *)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler) * sizeof(GUID)); - if (SavedData.ExtractHandlerGuidTable == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - SavedData.ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler) * sizeof(EXTRACT_GUIDED_SECTION_DECODE_HANDLER)); - if (SavedData.ExtractDecodeHandlerTable == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - SavedData.ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler) * sizeof(EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)); - if (SavedData.ExtractGetInfoHandlerTable == NULL) { - return RETURN_OUT_OF_RESOURCES; - } - - // - // the initialized number is Zero. - // - SavedData.NumberOfExtractHandler = 0; - - BuildGuidDataHob(&HobGuid, &SavedData, sizeof(SavedData)); - - return RETURN_SUCCESS; -} diff --git a/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf b/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf deleted file mode 100644 index ba74c26268..0000000000 --- a/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf +++ /dev/null @@ -1,36 +0,0 @@ -#/** @file -# -# Copyright (c) 2008 - 2010, Apple Inc. 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. -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PrePiExtractGuidedSectionLib - FILE_GUID = 36F6E94E-6E8E-488E-89A4-7AD911C5AFB1 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = ExtractGuidedSectionLib - - CONSTRUCTOR = ExtractGuidedSectionLibConstructor - -[Sources.common] - PrePiExtractGuidedSectionLib.c - -[Packages] - EmbeddedPkg/EmbeddedPkg.dec - MdePkg/MdePkg.dec - -[LibraryClasses] - BaseMemoryLib - DebugLib - -[FixedPcd.common] - gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler diff --git a/EmbeddedPkg/Library/PrePiHobLib/Hob.c b/EmbeddedPkg/Library/PrePiHobLib/Hob.c deleted file mode 100644 index aff532259e..0000000000 --- a/EmbeddedPkg/Library/PrePiHobLib/Hob.c +++ /dev/null @@ -1,852 +0,0 @@ -/** @file - - Copyright (c) 2010, Apple Inc. 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. - -**/ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -VOID -BuildMemoryTypeInformationHob ( - VOID - ); - -/** - Returns the pointer to the HOB list. - - This function returns the pointer to first HOB in the list. - - @return The pointer to the HOB list. - -**/ -VOID * -EFIAPI -GetHobList ( - VOID - ) -{ - return PrePeiGetHobList (); -} - - - -/** - Updates the pointer to the HOB list. - - @param HobList Hob list pointer to store - -**/ -EFI_STATUS -EFIAPI -SetHobList ( - IN VOID *HobList - ) -{ - return PrePeiSetHobList (HobList); -} - -/** - - -**/ -EFI_HOB_HANDOFF_INFO_TABLE* -HobConstructor ( - IN VOID *EfiMemoryBegin, - IN UINTN EfiMemoryLength, - IN VOID *EfiFreeMemoryBottom, - IN VOID *EfiFreeMemoryTop - ) -{ - EFI_HOB_HANDOFF_INFO_TABLE *Hob; - EFI_HOB_GENERIC_HEADER *HobEnd; - - Hob = EfiFreeMemoryBottom; - HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1); - - Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF; - Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE); - Hob->Header.Reserved = 0; - - HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; - HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER); - HobEnd->Reserved = 0; - - Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION; - Hob->BootMode = BOOT_WITH_FULL_CONFIGURATION; - - Hob->EfiMemoryTop = (UINTN)EfiMemoryBegin + EfiMemoryLength; - Hob->EfiMemoryBottom = (UINTN)EfiMemoryBegin; - Hob->EfiFreeMemoryTop = (UINTN)EfiFreeMemoryTop; - Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)(HobEnd+1); - Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd; - - return Hob; -} - -VOID * -CreateHob ( - IN UINT16 HobType, - IN UINT16 HobLength - ) -{ - EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob; - EFI_HOB_GENERIC_HEADER *HobEnd; - EFI_PHYSICAL_ADDRESS FreeMemory; - VOID *Hob; - - HandOffHob = GetHobList (); - - HobLength = (UINT16)((HobLength + 0x7) & (~0x7)); - - FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom; - - if (FreeMemory < HobLength) { - return NULL; - } - - Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList; - ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType; - ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength; - ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0; - - HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength); - HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd; - - HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST; - HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER); - HobEnd->Reserved = 0; - HobEnd++; - HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd; - - return Hob; -} - -/** - Builds a HOB that describes a chunk of system memory. - - This function builds a HOB that describes a chunk of system memory. - If there is no additional space for HOB creation, then ASSERT(). - - @param ResourceType The type of resource described by this HOB. - @param ResourceAttribute The resource attributes of the memory described by this HOB. - @param PhysicalStart The 64 bit physical address of memory described by this HOB. - @param NumberOfBytes The length of the memory described by this HOB in bytes. - -**/ -VOID -EFIAPI -BuildResourceDescriptorHob ( - IN EFI_RESOURCE_TYPE ResourceType, - IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, - IN EFI_PHYSICAL_ADDRESS PhysicalStart, - IN UINT64 NumberOfBytes - ) -{ - EFI_HOB_RESOURCE_DESCRIPTOR *Hob; - - Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR)); - ASSERT(Hob != NULL); - - Hob->ResourceType = ResourceType; - Hob->ResourceAttribute = ResourceAttribute; - Hob->PhysicalStart = PhysicalStart; - Hob->ResourceLength = NumberOfBytes; -} - -/** - - -**/ -VOID -CreateHobList ( - IN VOID *MemoryBegin, - IN UINTN MemoryLength, - IN VOID *HobBase, - IN VOID *StackBase - ) -{ - EFI_HOB_HANDOFF_INFO_TABLE *Hob; - EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; - - Hob = HobConstructor (MemoryBegin,MemoryLength,HobBase,StackBase); - SetHobList (Hob); - - BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize)); - - Attributes =( - EFI_RESOURCE_ATTRIBUTE_PRESENT | - EFI_RESOURCE_ATTRIBUTE_INITIALIZED | - EFI_RESOURCE_ATTRIBUTE_TESTED | - EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | - EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE - ); - - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, Attributes, (UINTN)MemoryBegin, MemoryLength); - - BuildStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)StackBase, ((UINTN)MemoryBegin + MemoryLength) - (UINTN)StackBase); - - if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) { - // Optional feature that helps prevent EFI memory map fragmentation. - BuildMemoryTypeInformationHob (); - } -} - - -VOID -EFIAPI -BuildFvHobs ( - IN EFI_PHYSICAL_ADDRESS PhysicalStart, - IN UINT64 NumberOfBytes, - IN EFI_RESOURCE_ATTRIBUTE_TYPE *ResourceAttribute - ) -{ - - EFI_RESOURCE_ATTRIBUTE_TYPE Resource; - - BuildFvHob (PhysicalStart, NumberOfBytes); - - if (ResourceAttribute == NULL) { - Resource = (EFI_RESOURCE_ATTRIBUTE_PRESENT | - EFI_RESOURCE_ATTRIBUTE_INITIALIZED | - EFI_RESOURCE_ATTRIBUTE_TESTED | - EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE); - } else { - Resource = *ResourceAttribute; - } - - BuildResourceDescriptorHob (EFI_RESOURCE_FIRMWARE_DEVICE, Resource, PhysicalStart, NumberOfBytes); -} - -/** - Returns the next instance of a HOB type from the starting HOB. - - This function searches the first instance of a HOB type from the starting HOB pointer. - If there does not exist such HOB type from the starting HOB pointer, it will return NULL. - In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer - unconditionally: it returns HobStart back if HobStart itself meets the requirement; - caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart. - If HobStart is NULL, then ASSERT(). - - @param Type The HOB type to return. - @param HobStart The starting HOB pointer to search from. - - @return The next instance of a HOB type from the starting HOB. - -**/ -VOID * -EFIAPI -GetNextHob ( - IN UINT16 Type, - IN CONST VOID *HobStart - ) -{ - EFI_PEI_HOB_POINTERS Hob; - - ASSERT (HobStart != NULL); - - Hob.Raw = (UINT8 *) HobStart; - // - // Parse the HOB list until end of list or matching type is found. - // - while (!END_OF_HOB_LIST (Hob)) { - if (Hob.Header->HobType == Type) { - return Hob.Raw; - } - Hob.Raw = GET_NEXT_HOB (Hob); - } - return NULL; -} - - - -/** - Returns the first instance of a HOB type among the whole HOB list. - - This function searches the first instance of a HOB type among the whole HOB list. - If there does not exist such HOB type in the HOB list, it will return NULL. - - @param Type The HOB type to return. - - @return The next instance of a HOB type from the starting HOB. - -**/ -VOID * -EFIAPI -GetFirstHob ( - IN UINT16 Type - ) -{ - VOID *HobList; - - HobList = GetHobList (); - return GetNextHob (Type, HobList); -} - - -/** - This function searches the first instance of a HOB from the starting HOB pointer. - Such HOB should satisfy two conditions: - its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. - If there does not exist such HOB from the starting HOB pointer, it will return NULL. - Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE () - to extract the data section and its size info respectively. - In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer - unconditionally: it returns HobStart back if HobStart itself meets the requirement; - caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart. - If Guid is NULL, then ASSERT(). - If HobStart is NULL, then ASSERT(). - - @param Guid The GUID to match with in the HOB list. - @param HobStart A pointer to a Guid. - - @return The next instance of the matched GUID HOB from the starting HOB. - -**/ -VOID * -EFIAPI -GetNextGuidHob ( - IN CONST EFI_GUID *Guid, - IN CONST VOID *HobStart - ){ - EFI_PEI_HOB_POINTERS GuidHob; - - GuidHob.Raw = (UINT8 *) HobStart; - while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) { - if (CompareGuid (Guid, &GuidHob.Guid->Name)) { - break; - } - GuidHob.Raw = GET_NEXT_HOB (GuidHob); - } - return GuidHob.Raw; -} - - -/** - This function searches the first instance of a HOB among the whole HOB list. - Such HOB should satisfy two conditions: - its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. - If there does not exist such HOB from the starting HOB pointer, it will return NULL. - Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE () - to extract the data section and its size info respectively. - If Guid is NULL, then ASSERT(). - - @param Guid The GUID to match with in the HOB list. - - @return The first instance of the matched GUID HOB among the whole HOB list. - -**/ -VOID * -EFIAPI -GetFirstGuidHob ( - IN CONST EFI_GUID *Guid - ) -{ - VOID *HobList; - - HobList = GetHobList (); - return GetNextGuidHob (Guid, HobList); -} - - -/** - Get the Boot Mode from the HOB list. - - This function returns the system boot mode information from the - PHIT HOB in HOB list. - - @param VOID - - @return The Boot Mode. - -**/ -EFI_BOOT_MODE -EFIAPI -GetBootMode ( - VOID - ) -{ - EFI_PEI_HOB_POINTERS Hob; - - Hob.Raw = GetHobList (); - return Hob.HandoffInformationTable->BootMode; -} - - -/** - Get the Boot Mode from the HOB list. - - This function returns the system boot mode information from the - PHIT HOB in HOB list. - - @param VOID - - @return The Boot Mode. - -**/ -EFI_STATUS -EFIAPI -SetBootMode ( - IN EFI_BOOT_MODE BootMode - ) -{ - EFI_PEI_HOB_POINTERS Hob; - - Hob.Raw = GetHobList (); - Hob.HandoffInformationTable->BootMode = BootMode; - return BootMode; -} - -/** - Builds a HOB for a loaded PE32 module. - - This function builds a HOB for a loaded PE32 module. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If ModuleName is NULL, then ASSERT(). - If there is no additional space for HOB creation, then ASSERT(). - - @param ModuleName The GUID File Name of the module. - @param MemoryAllocationModule The 64 bit physical address of the module. - @param ModuleLength The length of the module in bytes. - @param EntryPoint The 64 bit physical address of the module entry point. - -**/ -VOID -EFIAPI -BuildModuleHob ( - IN CONST EFI_GUID *ModuleName, - IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule, - IN UINT64 ModuleLength, - IN EFI_PHYSICAL_ADDRESS EntryPoint - ) -{ - EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob; - - ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) && - ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)); - - Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE)); - - CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid); - Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule; - Hob->MemoryAllocationHeader.MemoryLength = ModuleLength; - Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode; - - // - // Zero the reserved space to match HOB spec - // - ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved)); - - CopyGuid (&Hob->ModuleName, ModuleName); - Hob->EntryPoint = EntryPoint; -} - -/** - Builds a GUID HOB with a certain data length. - - This function builds a customized HOB tagged with a GUID for identification - and returns the start address of GUID HOB data so that caller can fill the customized data. - The HOB Header and Name field is already stripped. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If Guid is NULL, then ASSERT(). - If there is no additional space for HOB creation, then ASSERT(). - If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT(). - - @param Guid The GUID to tag the customized HOB. - @param DataLength The size of the data payload for the GUID HOB. - - @return The start address of GUID HOB data. - -**/ -VOID * -EFIAPI -BuildGuidHob ( - IN CONST EFI_GUID *Guid, - IN UINTN DataLength - ) -{ - EFI_HOB_GUID_TYPE *Hob; - - // - // Make sure that data length is not too long. - // - ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE))); - - Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength)); - CopyGuid (&Hob->Name, Guid); - return Hob + 1; -} - - -/** - Copies a data buffer to a newly-built HOB. - - This function builds a customized HOB tagged with a GUID for identification, - copies the input data to the HOB data field and returns the start address of the GUID HOB data. - The HOB Header and Name field is already stripped. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If Guid is NULL, then ASSERT(). - If Data is NULL and DataLength > 0, then ASSERT(). - If there is no additional space for HOB creation, then ASSERT(). - If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT(). - - @param Guid The GUID to tag the customized HOB. - @param Data The data to be copied into the data field of the GUID HOB. - @param DataLength The size of the data payload for the GUID HOB. - - @return The start address of GUID HOB data. - -**/ -VOID * -EFIAPI -BuildGuidDataHob ( - IN CONST EFI_GUID *Guid, - IN VOID *Data, - IN UINTN DataLength - ) -{ - VOID *HobData; - - ASSERT (Data != NULL || DataLength == 0); - - HobData = BuildGuidHob (Guid, DataLength); - - return CopyMem (HobData, Data, DataLength); -} - - -/** - Builds a Firmware Volume HOB. - - This function builds a Firmware Volume HOB. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If there is no additional space for HOB creation, then ASSERT(). - - @param BaseAddress The base address of the Firmware Volume. - @param Length The size of the Firmware Volume in bytes. - -**/ -VOID -EFIAPI -BuildFvHob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length - ) -{ - EFI_HOB_FIRMWARE_VOLUME *Hob; - - Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME)); - - Hob->BaseAddress = BaseAddress; - Hob->Length = Length; -} - - -/** - Builds a EFI_HOB_TYPE_FV2 HOB. - - This function builds a EFI_HOB_TYPE_FV2 HOB. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If there is no additional space for HOB creation, then ASSERT(). - - @param BaseAddress The base address of the Firmware Volume. - @param Length The size of the Firmware Volume in bytes. - @param FvName The name of the Firmware Volume. - @param FileName The name of the file. - -**/ -VOID -EFIAPI -BuildFv2Hob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - IN CONST EFI_GUID *FvName, - IN CONST EFI_GUID *FileName - ) -{ - EFI_HOB_FIRMWARE_VOLUME2 *Hob; - - Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2)); - - Hob->BaseAddress = BaseAddress; - Hob->Length = Length; - CopyGuid (&Hob->FvName, FvName); - CopyGuid (&Hob->FileName, FileName); -} - - - -/** - Builds a Capsule Volume HOB. - - This function builds a Capsule Volume HOB. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If there is no additional space for HOB creation, then ASSERT(). - - @param BaseAddress The base address of the Capsule Volume. - @param Length The size of the Capsule Volume in bytes. - -**/ -VOID -EFIAPI -BuildCvHob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length - ) -{ - ASSERT (FALSE); -} - - -/** - Builds a HOB for the CPU. - - This function builds a HOB for the CPU. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If there is no additional space for HOB creation, then ASSERT(). - - @param SizeOfMemorySpace The maximum physical memory addressability of the processor. - @param SizeOfIoSpace The maximum physical I/O addressability of the processor. - -**/ -VOID -EFIAPI -BuildCpuHob ( - IN UINT8 SizeOfMemorySpace, - IN UINT8 SizeOfIoSpace - ) -{ - EFI_HOB_CPU *Hob; - - Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU)); - - Hob->SizeOfMemorySpace = SizeOfMemorySpace; - Hob->SizeOfIoSpace = SizeOfIoSpace; - - // - // Zero the reserved space to match HOB spec - // - ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); -} - - -/** - Builds a HOB for the Stack. - - This function builds a HOB for the stack. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If there is no additional space for HOB creation, then ASSERT(). - - @param BaseAddress The 64 bit physical address of the Stack. - @param Length The length of the stack in bytes. - -**/ -VOID -EFIAPI -BuildStackHob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length - ) -{ - EFI_HOB_MEMORY_ALLOCATION_STACK *Hob; - - ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) && - ((Length & (EFI_PAGE_SIZE - 1)) == 0)); - - Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK)); - - CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid); - Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress; - Hob->AllocDescriptor.MemoryLength = Length; - Hob->AllocDescriptor.MemoryType = EfiBootServicesData; - - // - // Zero the reserved space to match HOB spec - // - ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved)); -} - - -/** - Update the Stack Hob if the stack has been moved - - @param BaseAddress The 64 bit physical address of the Stack. - @param Length The length of the stack in bytes. - -**/ -VOID -UpdateStackHob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length - ) -{ - EFI_PEI_HOB_POINTERS Hob; - - Hob.Raw = GetHobList (); - while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) { - if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) { - // - // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type - // to be reclaimed by DXE core. - // - BuildMemoryAllocationHob ( - Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress, - Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength, - EfiConventionalMemory - ); - // - // Update the BSP Stack Hob to reflect the new stack info. - // - Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress; - Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length; - break; - } - Hob.Raw = GET_NEXT_HOB (Hob); - } -} - - - -/** - Builds a HOB for the memory allocation. - - This function builds a HOB for the memory allocation. - It can only be invoked during PEI phase; - for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase. - If there is no additional space for HOB creation, then ASSERT(). - - @param BaseAddress The 64 bit physical address of the memory. - @param Length The length of the memory allocation in bytes. - @param MemoryType Type of memory allocated by this HOB. - -**/ -VOID -EFIAPI -BuildMemoryAllocationHob ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - IN EFI_MEMORY_TYPE MemoryType - ) -{ - EFI_HOB_MEMORY_ALLOCATION *Hob; - - ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) && - ((Length & (EFI_PAGE_SIZE - 1)) == 0)); - - Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION)); - - ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID)); - Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress; - Hob->AllocDescriptor.MemoryLength = Length; - Hob->AllocDescriptor.MemoryType = MemoryType; - // - // Zero the reserved space to match HOB spec - // - ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved)); -} - - - -VOID -EFIAPI -BuildExtractSectionHob ( - IN EFI_GUID *Guid, - IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER SectionGetInfo, - IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER SectionExtraction - ) -{ - EXTRACT_SECTION_DATA Data; - - Data.SectionGetInfo = SectionGetInfo; - Data.SectionExtraction = SectionExtraction; - BuildGuidDataHob (Guid, &Data, sizeof (Data)); -} - -PE_COFF_LOADER_PROTOCOL gPeCoffProtocol = { - PeCoffLoaderGetImageInfo, - PeCoffLoaderLoadImage, - PeCoffLoaderRelocateImage, - PeCoffLoaderImageReadFromMemory, - PeCoffLoaderRelocateImageForRuntime, - PeCoffLoaderUnloadImage -}; - - - -VOID -EFIAPI -BuildPeCoffLoaderHob ( - VOID - ) -{ - VOID *Ptr; - - Ptr = &gPeCoffProtocol; - BuildGuidDataHob (&gPeCoffLoaderProtocolGuid, &Ptr, sizeof (VOID *)); -} - -// May want to put this into a library so you only need the PCD setings if you are using the feature? -VOID -BuildMemoryTypeInformationHob ( - VOID - ) -{ - EFI_MEMORY_TYPE_INFORMATION Info[10]; - - Info[0].Type = EfiACPIReclaimMemory; - Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory); - Info[1].Type = EfiACPIMemoryNVS; - Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS); - Info[2].Type = EfiReservedMemoryType; - Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType); - Info[3].Type = EfiRuntimeServicesData; - Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData); - Info[4].Type = EfiRuntimeServicesCode; - Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode); - Info[5].Type = EfiBootServicesCode; - Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode); - Info[6].Type = EfiBootServicesData; - Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData); - Info[7].Type = EfiLoaderCode; - Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode); - Info[8].Type = EfiLoaderData; - Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData); - - // Terminator for the list - Info[9].Type = EfiMaxMemoryType; - Info[9].NumberOfPages = 0; - - - BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info)); -} - diff --git a/EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf b/EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf deleted file mode 100644 index 19e5a298f3..0000000000 --- a/EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf +++ /dev/null @@ -1,64 +0,0 @@ -#/** @file -# Hob lib that does not contain the APIs as they are already in the PrePiLib -# -# Copyright (c) 2008 - 2010, Apple Inc. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PrePiHobLib - FILE_GUID = 1F3A3278-82EB-4C0D-86F1-5BCDA5846CB2 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = HobLib - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - Hob.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - - -[LibraryClasses] - BaseLib - BaseMemoryLib - DebugLib - PrePiHobListPointerLib - -[Guids] - gEfiHobMemoryAllocModuleGuid - gEfiHobMemoryAllocStackGuid - -[FixedPcd.common] - gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize - gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize - - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData - -[FeaturePcd] - gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob - diff --git a/EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c b/EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c deleted file mode 100644 index 9065b1132f..0000000000 --- a/EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c +++ /dev/null @@ -1,69 +0,0 @@ -/** @file -* -* Copyright (c) 2011, ARM Limited. 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. -* -**/ - -#include -#include -#include -#include - -// -// Have to use build system to set the original value in case we are running -// from FLASH and globals don't work. So if you do a GetHobList() and gHobList -// and gHobList is NULL the PCD default values are used. -// -VOID *gHobList = NULL; - - -/** - Returns the pointer to the HOB list. - - This function returns the pointer to first HOB in the list. - - @return The pointer to the HOB list. - -**/ -VOID * -EFIAPI -PrePeiGetHobList ( - VOID - ) -{ - if (gHobList == NULL) { - return (VOID *)*(UINTN*)PcdGet32 (PcdPrePiHobBase); - } else { - return gHobList; - } -} - - - -/** - Updates the pointer to the HOB list. - - @param HobList Hob list pointer to store - -**/ -EFI_STATUS -EFIAPI -PrePeiSetHobList ( - IN VOID *HobList - ) -{ - gHobList = HobList; - - // - // If this code is running from ROM this could fail - // - return (gHobList == HobList) ? EFI_SUCCESS: EFI_UNSUPPORTED; -} diff --git a/EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf b/EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf deleted file mode 100644 index bfd3c209a1..0000000000 --- a/EmbeddedPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf +++ /dev/null @@ -1,38 +0,0 @@ -#/** @file -# -# Copyright (c) 2011, ARM Limited. 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. -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PrePiHobListPointerLib - FILE_GUID = 7a6a7fc0-5ee0-11e0-b47f-0002a5d5c51b - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = PrePiHobListPointerLib - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC (EBC is for build only) -# - -[Sources] - PrePiHobListPointer.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - #DebugLib - -[FixedPcd.common] - gEmbeddedTokenSpaceGuid.PcdPrePiHobBase diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/PrePiLib/FwVol.c deleted file mode 100644 index 530fc15dca..0000000000 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ /dev/null @@ -1,845 +0,0 @@ -/** @file - Implementation of the 6 PEI Ffs (FV) APIs in library form. - - This code only knows about a FV if it has a EFI_HOB_TYPE_FV entry in the HOB list - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include - - -#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \ - (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)) - - -/** - Returns the highest bit set of the State field - - @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY - in the Attributes field. - @param FfsHeader Pointer to FFS File Header - - - @retval the highest bit in the State field - -**/ -STATIC -EFI_FFS_FILE_STATE -GetFileState( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - EFI_FFS_FILE_STATE FileState; - EFI_FFS_FILE_STATE HighestBit; - - FileState = FfsHeader->State; - - if (ErasePolarity != 0) { - FileState = (EFI_FFS_FILE_STATE)~FileState; - } - - HighestBit = 0x80; - while (HighestBit != 0 && (HighestBit & FileState) == 0) { - HighestBit >>= 1; - } - - return HighestBit; -} - - -/** - Calculates the checksum of the header of a file. - The header is a zero byte checksum, so zero means header is good - - @param FfsHeader Pointer to FFS File Header - - @retval Checksum of the header - -**/ -STATIC -UINT8 -CalculateHeaderChecksum ( - IN EFI_FFS_FILE_HEADER *FileHeader - ) -{ - UINT8 *Ptr; - UINTN Index; - UINT8 Sum; - - Sum = 0; - Ptr = (UINT8 *)FileHeader; - - for (Index = 0; Index < sizeof(EFI_FFS_FILE_HEADER) - 3; Index += 4) { - Sum = (UINT8)(Sum + Ptr[Index]); - Sum = (UINT8)(Sum + Ptr[Index+1]); - Sum = (UINT8)(Sum + Ptr[Index+2]); - Sum = (UINT8)(Sum + Ptr[Index+3]); - } - - for (; Index < sizeof(EFI_FFS_FILE_HEADER); Index++) { - Sum = (UINT8)(Sum + Ptr[Index]); - } - - // - // State field (since this indicates the different state of file). - // - Sum = (UINT8)(Sum - FileHeader->State); - // - // Checksum field of the file is not part of the header checksum. - // - Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File); - - return Sum; -} - - -/** - Given a FileHandle return the VolumeHandle - - @param FileHandle File handle to look up - @param VolumeHandle Match for FileHandle - - @retval TRUE VolumeHandle is valid - -**/ -STATIC -BOOLEAN -EFIAPI -FileHandleToVolume ( - IN EFI_PEI_FILE_HANDLE FileHandle, - OUT EFI_PEI_FV_HANDLE *VolumeHandle - ) -{ - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_PEI_HOB_POINTERS Hob; - - Hob.Raw = GetHobList (); - if (Hob.Raw == NULL) { - return FALSE; - } - - do { - Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw); - if (Hob.Raw != NULL) { - FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(Hob.FirmwareVolume->BaseAddress); - if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \ - ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) { - *VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader; - return TRUE; - } - - Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, GET_NEXT_HOB (Hob)); - } - } while (Hob.Raw != NULL); - - return FALSE; -} - - - -/** - Given the input file pointer, search for the next matching file in the - FFS volume as defined by SearchType. The search starts from FileHeader inside - the Firmware Volume defined by FwVolHeader. - - @param FileHandle File handle to look up - @param VolumeHandle Match for FileHandle - - -**/ -EFI_STATUS -FindFileEx ( - IN CONST EFI_PEI_FV_HANDLE FvHandle, - IN CONST EFI_GUID *FileName, OPTIONAL - IN EFI_FV_FILETYPE SearchType, - IN OUT EFI_PEI_FILE_HANDLE *FileHandle - ) -{ - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_FFS_FILE_HEADER **FileHeader; - EFI_FFS_FILE_HEADER *FfsFileHeader; - EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo; - UINT32 FileLength; - UINT32 FileOccupiedSize; - UINT32 FileOffset; - UINT64 FvLength; - UINT8 ErasePolarity; - UINT8 FileState; - - FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvHandle; - FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle; - - FvLength = FwVolHeader->FvLength; - if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) { - ErasePolarity = 1; - } else { - ErasePolarity = 0; - } - - // - // If FileHeader is not specified (NULL) or FileName is not NULL, - // start with the first file in the firmware volume. Otherwise, - // start from the FileHeader. - // - if ((*FileHeader == NULL) || (FileName != NULL)) { - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength); - if (FwVolHeader->ExtHeaderOffset != 0) { - FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset); - FfsFileHeader = (EFI_FFS_FILE_HEADER *)(((UINT8 *)FwVolExHeaderInfo) + FwVolExHeaderInfo->ExtHeaderSize); - } - } else { - // - // Length is 24 bits wide so mask upper 8 bits - // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned. - // - FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize); - } - - // FFS files begin with a header that is aligned on an 8-byte boundary - FfsFileHeader = ALIGN_POINTER (FfsFileHeader, 8); - - FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader); - ASSERT (FileOffset <= 0xFFFFFFFF); - - while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) { - // - // Get FileState which is the highest bit of the State - // - FileState = GetFileState (ErasePolarity, FfsFileHeader); - - switch (FileState) { - - case EFI_FILE_HEADER_INVALID: - FileOffset += sizeof(EFI_FFS_FILE_HEADER); - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER)); - break; - - case EFI_FILE_DATA_VALID: - case EFI_FILE_MARKED_FOR_UPDATE: - if (CalculateHeaderChecksum (FfsFileHeader) != 0) { - ASSERT (FALSE); - *FileHeader = NULL; - return EFI_NOT_FOUND; - } - - FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); - - if (FileName != NULL) { - if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) { - *FileHeader = FfsFileHeader; - return EFI_SUCCESS; - } - } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && - (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { - *FileHeader = FfsFileHeader; - return EFI_SUCCESS; - } - - FileOffset += FileOccupiedSize; - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize); - break; - - case EFI_FILE_DELETED: - FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); - FileOffset += FileOccupiedSize; - FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize); - break; - - default: - *FileHeader = NULL; - return EFI_NOT_FOUND; - } - } - - - *FileHeader = NULL; - return EFI_NOT_FOUND; -} - - -/** - Go through the file to search SectionType section, - when meeting an encapsuled section. - - @param SectionType - Filter to find only section of this type. - @param Section - From where to search. - @param SectionSize - The file size to search. - @param OutputBuffer - Pointer to the section to search. - - @retval EFI_SUCCESS -**/ -EFI_STATUS -FfsProcessSection ( - IN EFI_SECTION_TYPE SectionType, - IN EFI_COMMON_SECTION_HEADER *Section, - IN UINTN SectionSize, - OUT VOID **OutputBuffer - ) -{ - EFI_STATUS Status; - UINT32 SectionLength; - UINT32 ParsedLength; - EFI_COMPRESSION_SECTION *CompressionSection; - UINT32 DstBufferSize; - VOID *ScratchBuffer; - UINT32 ScratchBufferSize; - VOID *DstBuffer; - UINT16 SectionAttribute; - UINT32 AuthenticationStatus; - - - *OutputBuffer = NULL; - ParsedLength = 0; - Status = EFI_NOT_FOUND; - while (ParsedLength < SectionSize) { - if (Section->Type == SectionType) { - *OutputBuffer = (VOID *)(Section + 1); - - return EFI_SUCCESS; - } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) { - - if (Section->Type == EFI_SECTION_COMPRESSION) { - CompressionSection = (EFI_COMPRESSION_SECTION *) Section; - SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF; - - if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) { - return EFI_UNSUPPORTED; - } - - Status = UefiDecompressGetInfo ( - (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), - (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION), - &DstBufferSize, - &ScratchBufferSize - ); - } else if (Section->Type == EFI_SECTION_GUID_DEFINED) { - Status = ExtractGuidedSectionGetInfo ( - Section, - &DstBufferSize, - &ScratchBufferSize, - &SectionAttribute - ); - } - - if (EFI_ERROR (Status)) { - // - // GetInfo failed - // - DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status)); - return EFI_NOT_FOUND; - } - // - // Allocate scratch buffer - // - ScratchBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize)); - if (ScratchBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // Allocate destination buffer, extra one page for adjustment - // - DstBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1); - if (DstBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header - // to make section data at page alignment. - // - DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER); - // - // Call decompress function - // - if (Section->Type == EFI_SECTION_COMPRESSION) { - Status = UefiDecompress ( - (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), - DstBuffer, - ScratchBuffer - ); - } else if (Section->Type == EFI_SECTION_GUID_DEFINED) { - Status = ExtractGuidedSectionDecode ( - Section, - &DstBuffer, - ScratchBuffer, - &AuthenticationStatus - ); - } - - if (EFI_ERROR (Status)) { - // - // Decompress failed - // - DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status)); - return EFI_NOT_FOUND; - } else { - return FfsProcessSection ( - SectionType, - DstBuffer, - DstBufferSize, - OutputBuffer - ); - } - } - - // - // Size is 24 bits wide so mask upper 8 bits. - // SectionLength is adjusted it is 4 byte aligned. - // Go to the next section - // - SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF; - SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4); - ASSERT (SectionLength != 0); - ParsedLength += SectionLength; - Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength); - } - - return EFI_NOT_FOUND; -} - - - -/** - This service enables discovery sections of a given type within a valid FFS file. - - @param SearchType The value of the section type to find. - @param FfsFileHeader A pointer to the file header that contains the set of sections to - be searched. - @param SectionData A pointer to the discovered section, if successful. - - @retval EFI_SUCCESS The section was found. - @retval EFI_NOT_FOUND The section was not found. - -**/ -EFI_STATUS -EFIAPI -FfsFindSectionData ( - IN EFI_SECTION_TYPE SectionType, - IN EFI_PEI_FILE_HANDLE FileHandle, - OUT VOID **SectionData - ) -{ - EFI_FFS_FILE_HEADER *FfsFileHeader; - UINT32 FileSize; - EFI_COMMON_SECTION_HEADER *Section; - - FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle); - - // - // Size is 24 bits wide so mask upper 8 bits. - // Does not include FfsFileHeader header size - // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. - // - Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); - FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; - FileSize -= sizeof (EFI_FFS_FILE_HEADER); - - return FfsProcessSection ( - SectionType, - Section, - FileSize, - SectionData - ); -} - - - - - - -/** - This service enables discovery of additional firmware files. - - @param SearchType A filter to find files only of this type. - @param FwVolHeader Pointer to the firmware volume header of the volume to search. - This parameter must point to a valid FFS volume. - @param FileHeader Pointer to the current file from which to begin searching. - - @retval EFI_SUCCESS The file was found. - @retval EFI_NOT_FOUND The file was not found. - @retval EFI_NOT_FOUND The header checksum was not zero. - -**/ -EFI_STATUS -EFIAPI -FfsFindNextFile ( - IN UINT8 SearchType, - IN EFI_PEI_FV_HANDLE VolumeHandle, - IN OUT EFI_PEI_FILE_HANDLE *FileHandle - ) -{ - return FindFileEx (VolumeHandle, NULL, SearchType, FileHandle); -} - - -/** - This service enables discovery of additional firmware volumes. - - @param Instance This instance of the firmware volume to find. The value 0 is the - Boot Firmware Volume (BFV). - @param FwVolHeader Pointer to the firmware volume header of the volume to return. - - @retval EFI_SUCCESS The volume was found. - @retval EFI_NOT_FOUND The volume was not found. - -**/ -EFI_STATUS -EFIAPI -FfsFindNextVolume ( - IN UINTN Instance, - IN OUT EFI_PEI_FV_HANDLE *VolumeHandle - ) -{ - EFI_PEI_HOB_POINTERS Hob; - - - Hob.Raw = GetHobList (); - if (Hob.Raw == NULL) { - return EFI_NOT_FOUND; - } - - do { - Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, Hob.Raw); - if (Hob.Raw != NULL) { - if (Instance-- == 0) { - *VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)(Hob.FirmwareVolume->BaseAddress); - return EFI_SUCCESS; - } - - Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV, GET_NEXT_HOB (Hob)); - } - } while (Hob.Raw != NULL); - - return EFI_NOT_FOUND; - -} - - -/** - Find a file in the volume by name - - @param FileName A pointer to the name of the file to - find within the firmware volume. - - @param VolumeHandle The firmware volume to search FileHandle - Upon exit, points to the found file's - handle or NULL if it could not be found. - - @retval EFI_SUCCESS File was found. - - @retval EFI_NOT_FOUND File was not found. - - @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or - FileName was NULL. - -**/ -EFI_STATUS -EFIAPI -FfsFindFileByName ( - IN CONST EFI_GUID *FileName, - IN EFI_PEI_FV_HANDLE VolumeHandle, - OUT EFI_PEI_FILE_HANDLE *FileHandle - ) -{ - EFI_STATUS Status; - if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) { - return EFI_INVALID_PARAMETER; - } - Status = FindFileEx (VolumeHandle, FileName, 0, FileHandle); - if (Status == EFI_NOT_FOUND) { - *FileHandle = NULL; - } - return Status; -} - - - - -/** - Get information about the file by name. - - @param FileHandle Handle of the file. - - @param FileInfo Upon exit, points to the file's - information. - - @retval EFI_SUCCESS File information returned. - - @retval EFI_INVALID_PARAMETER If FileHandle does not - represent a valid file. - - @retval EFI_INVALID_PARAMETER If FileInfo is NULL. - -**/ -EFI_STATUS -EFIAPI -FfsGetFileInfo ( - IN EFI_PEI_FILE_HANDLE FileHandle, - OUT EFI_FV_FILE_INFO *FileInfo - ) -{ - UINT8 FileState; - UINT8 ErasePolarity; - EFI_FFS_FILE_HEADER *FileHeader; - EFI_PEI_FV_HANDLE VolumeHandle; - - if ((FileHandle == NULL) || (FileInfo == NULL)) { - return EFI_INVALID_PARAMETER; - } - - VolumeHandle = 0; - // - // Retrieve the FirmwareVolume which the file resides in. - // - if (!FileHandleToVolume(FileHandle, &VolumeHandle)) { - return EFI_INVALID_PARAMETER; - } - - if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) { - ErasePolarity = 1; - } else { - ErasePolarity = 0; - } - - // - // Get FileState which is the highest bit of the State - // - FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle); - - switch (FileState) { - case EFI_FILE_DATA_VALID: - case EFI_FILE_MARKED_FOR_UPDATE: - break; - default: - return EFI_INVALID_PARAMETER; - } - - FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle; - CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID)); - FileInfo->FileType = FileHeader->Type; - FileInfo->FileAttributes = FileHeader->Attributes; - FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER); - FileInfo->Buffer = (FileHeader + 1); - return EFI_SUCCESS; -} - - -/** - Get Information about the volume by name - - @param VolumeHandle Handle of the volume. - - @param VolumeInfo Upon exit, points to the volume's - information. - - @retval EFI_SUCCESS File information returned. - - @retval EFI_INVALID_PARAMETER If FileHandle does not - represent a valid file. - - @retval EFI_INVALID_PARAMETER If FileInfo is NULL. - -**/ -EFI_STATUS -EFIAPI -FfsGetVolumeInfo ( - IN EFI_PEI_FV_HANDLE VolumeHandle, - OUT EFI_FV_INFO *VolumeInfo - ) -{ - EFI_FIRMWARE_VOLUME_HEADER FwVolHeader; - EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo; - - if (VolumeInfo == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // VolumeHandle may not align at 8 byte, - // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. - // So, Copy FvHeader into the local FvHeader structure. - // - CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER)); - // - // Check Fv Image Signature - // - if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) { - return EFI_INVALID_PARAMETER; - } - VolumeInfo->FvAttributes = FwVolHeader.Attributes; - VolumeInfo->FvStart = (VOID *) VolumeHandle; - VolumeInfo->FvSize = FwVolHeader.FvLength; - CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID)); - - if (FwVolHeader.ExtHeaderOffset != 0) { - FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset); - CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID)); - } - return EFI_SUCCESS; -} - - - -/** - Search through every FV until you find a file of type FileType - - @param FileType File handle of a Fv type file. - @param Volumehandle On succes Volume Handle of the match - @param FileHandle On success File Handle of the match - - @retval EFI_NOT_FOUND FV image can't be found. - @retval EFI_SUCCESS Successfully found FileType - -**/ -EFI_STATUS -EFIAPI -FfsAnyFvFindFirstFile ( - IN EFI_FV_FILETYPE FileType, - OUT EFI_PEI_FV_HANDLE *VolumeHandle, - OUT EFI_PEI_FILE_HANDLE *FileHandle - ) -{ - EFI_STATUS Status; - UINTN Instance; - - // - // Search every FV for the DXE Core - // - Instance = 0; - *FileHandle = NULL; - - while (1) - { - Status = FfsFindNextVolume (Instance++, VolumeHandle); - if (EFI_ERROR (Status)) - { - break; - } - - Status = FfsFindNextFile (FileType, *VolumeHandle, FileHandle); - if (!EFI_ERROR (Status)) - { - break; - } - } - - return Status; -} - - - -/** - Get Fv image from the FV type file, then add FV & FV2 Hob. - - @param FileHandle File handle of a Fv type file. - - - @retval EFI_NOT_FOUND FV image can't be found. - @retval EFI_SUCCESS Successfully to process it. - -**/ -EFI_STATUS -EFIAPI -FfsProcessFvFile ( - IN EFI_PEI_FILE_HANDLE FvFileHandle - ) -{ - EFI_STATUS Status; - EFI_PEI_FV_HANDLE FvImageHandle; - EFI_FV_INFO FvImageInfo; - UINT32 FvAlignment; - VOID *FvBuffer; - EFI_PEI_HOB_POINTERS HobFv2; - - FvBuffer = NULL; - - - // - // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already - // been extracted. - // - HobFv2.Raw = GetHobList (); - while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) { - if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobFv2.FirmwareVolume2->FileName)) { - // - // this FILE has been dispatched, it will not be dispatched again. - // - return EFI_SUCCESS; - } - HobFv2.Raw = GET_NEXT_HOB (HobFv2); - } - - // - // Find FvImage in FvFile - // - Status = FfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE, FvFileHandle, (VOID **)&FvImageHandle); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Collect FvImage Info. - // - ZeroMem (&FvImageInfo, sizeof (FvImageInfo)); - Status = FfsGetVolumeInfo (FvImageHandle, &FvImageInfo); - ASSERT_EFI_ERROR (Status); - - // - // FvAlignment must be more than 8 bytes required by FvHeader structure. - // - FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16); - if (FvAlignment < 8) { - FvAlignment = 8; - } - - // - // Check FvImage - // - if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) { - FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment); - if (FvBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize); - // - // Update FvImageInfo after reload FvImage to new aligned memory - // - FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo); - } - - - // - // Inform HOB consumer phase, i.e. DXE core, the existance of this FV - // - BuildFvHob ((EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, FvImageInfo.FvSize); - - // - // Makes the encapsulated volume show up in DXE phase to skip processing of - // encapsulated file again. - // - BuildFv2Hob ( - (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart, - FvImageInfo.FvSize, - &FvImageInfo.FvName, - &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name) - ); - - return EFI_SUCCESS; -} - - diff --git a/EmbeddedPkg/Library/PrePiLib/PrePi.h b/EmbeddedPkg/Library/PrePiLib/PrePi.h deleted file mode 100644 index 607561cd24..0000000000 --- a/EmbeddedPkg/Library/PrePiLib/PrePi.h +++ /dev/null @@ -1,46 +0,0 @@ -/** @file - Library that helps implement monolithic PEI (i.e. PEI part of SEC) - - Copyright (c) 2008 - 2009, Apple Inc. 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 _PI_PEI_H_ -#define _PI_PEI_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -#define GET_HOB_TYPE(Hob) ((Hob).Header->HobType) -#define GET_HOB_LENGTH(Hob) ((Hob).Header->HobLength) -#define GET_NEXT_HOB(Hob) ((Hob).Raw + GET_HOB_LENGTH (Hob)) -#define END_OF_HOB_LIST(Hob) (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_END_OF_HOB_LIST) - -// -// Get the data and data size field of GUID -// -#define GET_GUID_HOB_DATA(GuidHob) ((VOID *) (((UINT8 *) &((GuidHob)->Name)) + sizeof (EFI_GUID))) -#define GET_GUID_HOB_DATA_SIZE(GuidHob) (((GuidHob)->Header).HobLength - sizeof (EFI_HOB_GUID_TYPE)) - -#endif diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c deleted file mode 100644 index 9a1ef344df..0000000000 --- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c +++ /dev/null @@ -1,226 +0,0 @@ -/** @file - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include - -// -// Hack to work in NT32 -// -EFI_STATUS - -EFIAPI - -SecWinNtPeiLoadFile ( - IN VOID *Pe32Data, - IN EFI_PHYSICAL_ADDRESS *ImageAddress, - IN UINT64 *ImageSize, - IN EFI_PHYSICAL_ADDRESS *EntryPoint - ); - - -EFI_STATUS -EFIAPI -LoadPeCoffImage ( - IN VOID *PeCoffImage, - OUT EFI_PHYSICAL_ADDRESS *ImageAddress, - OUT UINT64 *ImageSize, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint - ) -{ - RETURN_STATUS Status; - PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; - VOID *Buffer; - - ZeroMem (&ImageContext, sizeof (ImageContext)); - - ImageContext.Handle = PeCoffImage; - ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; - - Status = PeCoffLoaderGetImageInfo (&ImageContext); - ASSERT_EFI_ERROR (Status); - - - // - // Allocate Memory for the image - // - Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize)); - ASSERT (Buffer != 0); - - - ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer; - - // - // Load the image to our new buffer - // - Status = PeCoffLoaderLoadImage (&ImageContext); - ASSERT_EFI_ERROR (Status); - - // - // Relocate the image in our new buffer - // - Status = PeCoffLoaderRelocateImage (&ImageContext); - ASSERT_EFI_ERROR (Status); - - - *ImageAddress = ImageContext.ImageAddress; - *ImageSize = ImageContext.ImageSize; - *EntryPoint = ImageContext.EntryPoint; - - // - // Flush not needed for all architectures. We could have a processor specific - // function in this library that does the no-op if needed. - // - InvalidateInstructionCacheRange ((VOID *)(UINTN)*ImageAddress, (UINTN)*ImageSize); - - return Status; -} - - - -typedef -VOID -(EFIAPI *DXE_CORE_ENTRY_POINT) ( - IN VOID *HobStart - ); - -EFI_STATUS -EFIAPI -LoadDxeCoreFromFfsFile ( - IN EFI_PEI_FILE_HANDLE FileHandle, - IN UINTN StackSize - ) -{ - EFI_STATUS Status; - VOID *PeCoffImage; - EFI_PHYSICAL_ADDRESS ImageAddress; - UINT64 ImageSize; - EFI_PHYSICAL_ADDRESS EntryPoint; - VOID *BaseOfStack; - VOID *TopOfStack; - VOID *Hob; - EFI_FV_FILE_INFO FvFileInfo; - - Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage); - if (EFI_ERROR (Status)) { - return Status; - } - - - Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint); -// For NT32 Debug Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint); - ASSERT_EFI_ERROR (Status); - - // - // Extract the DxeCore GUID file name. - // - Status = FfsGetFileInfo (FileHandle, &FvFileInfo); - ASSERT_EFI_ERROR (Status); - - BuildModuleHob (&FvFileInfo.FileName, (EFI_PHYSICAL_ADDRESS)(UINTN)ImageAddress, EFI_SIZE_TO_PAGES ((UINT32) ImageSize) * EFI_PAGE_SIZE, EntryPoint); - - DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading DxeCore at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)EntryPoint)); - - Hob = GetHobList (); - if (StackSize == 0) { - // User the current stack - - ((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint) (Hob); - } else { - - // - // Allocate 128KB for the Stack - // - BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (StackSize)); - ASSERT (BaseOfStack != NULL); - - // - // Compute the top of the stack we were allocated. Pre-allocate a UINTN - // for safety. - // - TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (StackSize) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); - TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); - - // - // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore. - // - UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, StackSize); - - SwitchStack ( - (SWITCH_STACK_ENTRY_POINT)(UINTN)EntryPoint, - Hob, - NULL, - TopOfStack - ); - - } - - // Should never get here as DXE Core does not return - DEBUG ((EFI_D_ERROR, "DxeCore returned\n")); - ASSERT (FALSE); - - return EFI_DEVICE_ERROR; -} - - - -EFI_STATUS -EFIAPI -LoadDxeCoreFromFv ( - IN UINTN *FvInstance, OPTIONAL - IN UINTN StackSize - ) -{ - EFI_STATUS Status; - EFI_PEI_FV_HANDLE VolumeHandle; - EFI_PEI_FILE_HANDLE FileHandle = NULL; - - if (FvInstance != NULL) { - // - // Caller passed in a specific FV to try, so only try that one - // - Status = FfsFindNextVolume (*FvInstance, &VolumeHandle); - if (!EFI_ERROR (Status)) { - Status = FfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle); - } - } else { - Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_DXE_CORE, &VolumeHandle, &FileHandle); - } - - if (!EFI_ERROR (Status)) { - return LoadDxeCoreFromFfsFile (FileHandle, StackSize); - } - - return Status; -} - - -EFI_STATUS -EFIAPI -DecompressFirstFv ( - VOID - ) -{ - EFI_STATUS Status; - EFI_PEI_FV_HANDLE VolumeHandle; - EFI_PEI_FILE_HANDLE FileHandle; - - Status = FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, &VolumeHandle, &FileHandle); - if (!EFI_ERROR (Status)) { - Status = FfsProcessFvFile (FileHandle); - } - - return Status; -} - - diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.inf b/EmbeddedPkg/Library/PrePiLib/PrePiLib.inf deleted file mode 100644 index b27b0441d5..0000000000 --- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.inf +++ /dev/null @@ -1,85 +0,0 @@ -#/** @file -# Component description file for Apple Pre PI Library -# -# LIbrary helps you build a platform that skips PEI and loads DXE Core -# directly. Helps building HOBs, reading data from the FV, and doing -# decompression. -# -# Copyright (c) 2008, Apple Inc. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PrePiLib - FILE_GUID = 1F3A3278-82EB-4C0D-86F1-5BCDA5846CB2 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = PrePiLib - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - FwVol.c - PrePiLib.c - ReportStatusCode.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec # needed to support StatusCodes - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec # needed to support StatusCodes - - -[LibraryClasses] - BaseLib - DebugLib - BaseMemoryLib - UefiDecompressLib - PeCoffLib - CacheMaintenanceLib - PrintLib - SerialPortLib - ExtractGuidedSectionLib - TimerLib - PerformanceLib - HobLib - -[Guids] - gEfiStatusCodeSpecificDataGuid - gEfiMemoryTypeInformationGuid - gEfiStatusCodeDataTypeDebugGuid - -[Protocols] - gEfiStatusCodeRuntimeProtocolGuid - gPeCoffLoaderProtocolGuid - - -[FixedPcd.common] - gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize - gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize - - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode - gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData - -[FeaturePcd] - gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob diff --git a/EmbeddedPkg/Library/PrePiLib/ReportStatusCode.c b/EmbeddedPkg/Library/PrePiLib/ReportStatusCode.c deleted file mode 100644 index 7a0b90a1e6..0000000000 --- a/EmbeddedPkg/Library/PrePiLib/ReportStatusCode.c +++ /dev/null @@ -1,325 +0,0 @@ -/** @file - Library that helps implement monolithic PEI - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include -#include -#include - -#include -#include -#include -#include - -EFI_STATUS -EFIAPI -SerialReportStatusCode ( - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value, - IN UINT32 Instance, - IN CONST EFI_GUID *CallerId, - IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL - ); - - -EFI_STATUS_CODE_PROTOCOL gStatusCode = { - (EFI_REPORT_STATUS_CODE)SerialReportStatusCode -}; - -/** - Extracts ASSERT() information from a status code structure. - - Converts the status code specified by CodeType, Value, and Data to the ASSERT() - arguments specified by Filename, Description, and LineNumber. If CodeType is - an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and - Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract - Filename, Description, and LineNumber from the optional data area of the - status code buffer specified by Data. The optional data area of Data contains - a Null-terminated ASCII string for the FileName, followed by a Null-terminated - ASCII string for the Description, followed by a 32-bit LineNumber. If the - ASSERT() information could be extracted from Data, then return TRUE. - Otherwise, FALSE is returned. - - If Data is NULL, then ASSERT(). - If Filename is NULL, then ASSERT(). - If Description is NULL, then ASSERT(). - If LineNumber is NULL, then ASSERT(). - - @param CodeType The type of status code being converted. - @param Value The status code value being converted. - @param Data Pointer to status code data buffer. - @param Filename Pointer to the source file name that generated the ASSERT(). - @param Description Pointer to the description of the ASSERT(). - @param LineNumber Pointer to source line number that generated the ASSERT(). - - @retval TRUE The status code specified by CodeType, Value, and Data was - converted ASSERT() arguments specified by Filename, Description, - and LineNumber. - @retval FALSE The status code specified by CodeType, Value, and Data could - not be converted to ASSERT() arguments. - -**/ -BOOLEAN -EFIAPI -ReportStatusCodeExtractAssertInfo ( - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value, - IN CONST EFI_STATUS_CODE_DATA *Data, - OUT CHAR8 **Filename, - OUT CHAR8 **Description, - OUT UINT32 *LineNumber - ) -{ - EFI_DEBUG_ASSERT_DATA *AssertData; - - ASSERT (Data != NULL); - ASSERT (Filename != NULL); - ASSERT (Description != NULL); - ASSERT (LineNumber != NULL); - - if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) && - ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) && - ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) { - AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1); - *Filename = (CHAR8 *)(AssertData + 1); - *Description = *Filename + AsciiStrLen (*Filename) + 1; - *LineNumber = AssertData->LineNumber; - return TRUE; - } - return FALSE; -} - - -/** - Extracts DEBUG() information from a status code structure. - - Converts the status code specified by Data to the DEBUG() arguments specified - by ErrorLevel, Marker, and Format. If type GUID in Data is - EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and - Format from the optional data area of the status code buffer specified by Data. - The optional data area of Data contains a 32-bit ErrorLevel followed by Marker - which is 12 UINTN parameters, followed by a Null-terminated ASCII string for - the Format. If the DEBUG() information could be extracted from Data, then - return TRUE. Otherwise, FALSE is returned. - - If Data is NULL, then ASSERT(). - If ErrorLevel is NULL, then ASSERT(). - If Marker is NULL, then ASSERT(). - If Format is NULL, then ASSERT(). - - @param Data Pointer to status code data buffer. - @param ErrorLevel Pointer to error level mask for a debug message. - @param Marker Pointer to the variable argument list associated with Format. - @param Format Pointer to a Null-terminated ASCII format string of a - debug message. - - @retval TRUE The status code specified by Data was converted DEBUG() arguments - specified by ErrorLevel, Marker, and Format. - @retval FALSE The status code specified by Data could not be converted to - DEBUG() arguments. - -**/ -BOOLEAN -EFIAPI -ReportStatusCodeExtractDebugInfo ( - IN CONST EFI_STATUS_CODE_DATA *Data, - OUT UINT32 *ErrorLevel, - OUT BASE_LIST *Marker, - OUT CHAR8 **Format - ) -{ - EFI_DEBUG_INFO *DebugInfo; - - ASSERT (Data != NULL); - ASSERT (ErrorLevel != NULL); - ASSERT (Marker != NULL); - ASSERT (Format != NULL); - - // - // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE - // - if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) { - return FALSE; - } - - // - // Retrieve the debug information from the status code record - // - DebugInfo = (EFI_DEBUG_INFO *)(Data + 1); - - *ErrorLevel = DebugInfo->ErrorLevel; - - // - // The first 12 * UINTN bytes of the string are really an - // argument stack to support varargs on the Format string. - // - *Marker = (BASE_LIST) (DebugInfo + 1); - *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12); - - return TRUE; -} - - - - -EFI_STATUS -EFIAPI -SerialReportStatusCode ( - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value, - IN UINT32 Instance, - IN CONST EFI_GUID *CallerId, - IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL - ) -{ - CHAR8 *Filename; - CHAR8 *Description; - CHAR8 *Format; - CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE]; - UINT32 ErrorLevel; - UINT32 LineNumber; - UINTN CharCount; - BASE_LIST Marker; - EFI_DEBUG_INFO *DebugInfo; - - Buffer[0] = '\0'; - - - if (Data != NULL && - ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) { - - // - // Print ASSERT() information into output buffer. - // - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "\n\rASSERT!: %a (%d): %a\n\r", - Filename, - LineNumber, - Description - ); - - - // - // Callout to standard output. - // - SerialPortWrite ((UINT8 *)Buffer, CharCount); - return EFI_SUCCESS; - - } else if (Data != NULL && - ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) { - - // - // Print DEBUG() information into output buffer. - // - CharCount = AsciiBSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - Format, - Marker - ); - - } else if (Data != NULL && - CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) && - (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) { - - // - // Print specific data into output buffer. - // - DebugInfo = (EFI_DEBUG_INFO *) (Data + 1); - Marker = (BASE_LIST) (DebugInfo + 1); - Format = (CHAR8 *) (((UINT64 *) (DebugInfo + 1)) + 12); - - CharCount = AsciiBSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker); - - } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) { - // - // Print ERROR information into output buffer. - // - - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "ERROR: C%x:V%x I%x", - CodeType, - Value, - Instance - ); - - // - // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers. - // - if (CallerId != NULL) { - CharCount += AsciiSPrint ( - &Buffer[CharCount - 1], - (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)), - " %g", - CallerId - ); - } - - if (Data != NULL) { - CharCount += AsciiSPrint ( - &Buffer[CharCount - 1], - (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)), - " %x", - Data - ); - - } - - - CharCount += AsciiSPrint ( - &Buffer[CharCount - 1], - (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)), - "\n\r" - ); - - } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) { - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "PROGRESS CODE: V%x I%x\n\r", - Value, - Instance - ); - } else { - CharCount = AsciiSPrint ( - Buffer, - EFI_STATUS_CODE_DATA_MAX_SIZE, - "Undefined: C%x:V%x I%x\n\r", - CodeType, - Value, - Instance - ); - - } - - SerialPortWrite ((UINT8 *)Buffer, CharCount); - return EFI_SUCCESS; - -} - - -VOID -EFIAPI -AddDxeCoreReportStatusCodeCallback ( - VOID - ) -{ - BuildGuidDataHob (&gEfiStatusCodeRuntimeProtocolGuid, &gStatusCode, sizeof(VOID *)); -} - diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c deleted file mode 100644 index 0e75e23933..0000000000 --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c +++ /dev/null @@ -1,218 +0,0 @@ -/** @file - Implementation of the 6 PEI Ffs (FV) APIs in library form. - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include - -#include -#include -#include - - - -/** - Allocates one or more 4KB pages of type EfiBootServicesData. - - Allocates the number of 4KB pages of MemoryType and returns a pointer to the - allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL - is returned. If there is not enough memory remaining to satisfy the request, then NULL is - returned. - - @param Pages The number of 4 KB pages to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocatePages ( - IN UINTN Pages - ) -{ - EFI_PEI_HOB_POINTERS Hob; - EFI_PHYSICAL_ADDRESS Offset; - - Hob.Raw = GetHobList (); - - // Check to see if on 4k boundary - Offset = Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF; - if (Offset != 0) { - // If not aligned, make the allocation aligned. - Hob.HandoffInformationTable->EfiFreeMemoryTop -= Offset; - } - - // - // Verify that there is sufficient memory to satisfy the allocation - // - if (Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < Hob.HandoffInformationTable->EfiFreeMemoryBottom) { - return 0; - } else { - // - // Update the PHIT to reflect the memory usage - // - Hob.HandoffInformationTable->EfiFreeMemoryTop -= Pages * EFI_PAGE_SIZE; - - // This routine used to create a memory allocation HOB a la PEI, but that's not - // necessary for us. - - // - // Create a memory allocation HOB. - // - BuildMemoryAllocationHob ( - Hob.HandoffInformationTable->EfiFreeMemoryTop, - Pages * EFI_PAGE_SIZE, - EfiBootServicesData - ); - return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop; - } -} - - -/** - Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. - - Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an - alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is - returned. If there is not enough memory at the specified alignment remaining to satisfy the - request, then NULL is returned. - If Alignment is not a power of two and Alignment is not zero, then ASSERT(). - - @param Pages The number of 4 KB pages to allocate. - @param Alignment The requested alignment of the allocation. Must be a power of two. - If Alignment is zero, then byte alignment is used. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAlignedPages ( - IN UINTN Pages, - IN UINTN Alignment - ) -{ - VOID *Memory; - UINTN AlignmentMask; - - // - // Alignment must be a power of two or zero. - // - ASSERT ((Alignment & (Alignment - 1)) == 0); - - if (Pages == 0) { - return NULL; - } - // - // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. - // - ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment))); - // - // We would rather waste some memory to save PEI code size. - // - Memory = (VOID *)(UINTN)AllocatePages (Pages + EFI_SIZE_TO_PAGES (Alignment)); - if (Alignment == 0) { - AlignmentMask = Alignment; - } else { - AlignmentMask = Alignment - 1; - } - return (VOID *) (UINTN) (((UINTN) Memory + AlignmentMask) & ~AlignmentMask); -} - - -/** - Frees one or more 4KB pages that were previously allocated with one of the page allocation - functions in the Memory Allocation Library. - - Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer - must have been allocated on a previous call to the page allocation services of the Memory - Allocation Library. If it is not possible to free allocated pages, then this function will - perform no actions. - - If Buffer was not allocated with a page allocation function in the Memory Allocation Library, - then ASSERT(). - If Pages is zero, then ASSERT(). - - @param Buffer Pointer to the buffer of pages to free. - @param Pages The number of 4 KB pages to free. - -**/ -VOID -EFIAPI -FreePages ( - IN VOID *Buffer, - IN UINTN Pages - ) -{ - // For now, we do not support the ability to free pages in the PrePei Memory Allocator. - // The allocated memory is lost. -} - -/** - Allocates a buffer of type EfiBootServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a - pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocatePool ( - IN UINTN AllocationSize - ) -{ - EFI_HOB_MEMORY_POOL *Hob; - - Hob = GetHobList (); - - - // - // Verify that there is sufficient memory to satisfy the allocation - // - if (AllocationSize > 0x10000) { - // Please call AllcoatePages for big allocations - return 0; - } else { - - Hob = (EFI_HOB_MEMORY_POOL *)CreateHob (EFI_HOB_TYPE_MEMORY_POOL, (UINT16)(sizeof (EFI_HOB_TYPE_MEMORY_POOL) + AllocationSize)); - return (VOID *)(Hob + 1); - } -} - -/** - Frees a buffer that was previously allocated with one of the pool allocation functions in the - Memory Allocation Library. - - Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the - pool allocation services of the Memory Allocation Library. If it is not possible to free pool - resources, then this function will perform no actions. - - If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, - then ASSERT(). - - @param Buffer Pointer to the buffer to free. - -**/ -VOID -EFIAPI -FreePool ( - IN VOID *Buffer - ) -{ - // Not implemented yet -} diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf deleted file mode 100644 index 21f6eb1e14..0000000000 --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf +++ /dev/null @@ -1,39 +0,0 @@ -#/** @file -# -# Copyright (c) 2011, ARM Ltd. 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. -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PrePiMemoryAllocationLib - FILE_GUID = 4f14c900-51a9-11e0-afbf-0002a5d5c51b - MODULE_TYPE = PEIM - VERSION_STRING = 1.0 - LIBRARY_CLASS = MemoryAllocationLib - - -# -# VALID_ARCHITECTURES = ARM -# - -[Sources] - MemoryAllocationLib.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - DebugLib - BaseMemoryLib - PrePiLib - #PeiServicesLib - diff --git a/EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c b/EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c deleted file mode 100644 index 8e4ee9b919..0000000000 --- a/EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c +++ /dev/null @@ -1,175 +0,0 @@ -/** @file - Implement EFI RealTimeClock runtime services via RTC Lib. - - Currently this driver does not support runtime virtual calling. - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - -#include -#include -#include -#include -#include - - -/** - Returns the current time and date information, and the time-keeping capabilities - of the hardware platform. - - @param Time A pointer to storage to receive a snapshot of the current time. - @param Capabilities An optional pointer to a buffer to receive the real time clock - device's capabilities. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_INVALID_PARAMETER Time is NULL. - @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error. - -**/ -EFI_STATUS -EFIAPI -LibGetTime ( - OUT EFI_TIME *Time, - OUT EFI_TIME_CAPABILITIES *Capabilities - ) -{ - // - // Fill in Time and Capabilities via data from you RTC - // - return EFI_DEVICE_ERROR; -} - - -/** - Sets the current local time and date information. - - @param Time A pointer to the current time. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_INVALID_PARAMETER A time field is out of range. - @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error. - -**/ -EFI_STATUS -EFIAPI -LibSetTime ( - IN EFI_TIME *Time - ) -{ - // - // Use Time, to set the time in your RTC hardware - // - return EFI_DEVICE_ERROR; -} - - -/** - Returns the current wakeup alarm clock setting. - - @param Enabled Indicates if the alarm is currently enabled or disabled. - @param Pending Indicates if the alarm signal is pending and requires acknowledgement. - @param Time The current alarm setting. - - @retval EFI_SUCCESS The alarm settings were returned. - @retval EFI_INVALID_PARAMETER Any parameter is NULL. - @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error. - -**/ -EFI_STATUS -EFIAPI -LibGetWakeupTime ( - OUT BOOLEAN *Enabled, - OUT BOOLEAN *Pending, - OUT EFI_TIME *Time - ) -{ - // Not a required feature - return EFI_UNSUPPORTED; -} - - -/** - Sets the system wakeup alarm clock time. - - @param Enabled Enable or disable the wakeup alarm. - @param Time If Enable is TRUE, the time to set the wakeup alarm for. - - @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If - Enable is FALSE, then the wakeup alarm was disabled. - @retval EFI_INVALID_PARAMETER A time field is out of range. - @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error. - @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform. - -**/ -EFI_STATUS -EFIAPI -LibSetWakeupTime ( - IN BOOLEAN Enabled, - OUT EFI_TIME *Time - ) -{ - // Not a required feature - return EFI_UNSUPPORTED; -} - - - -/** - This is the declaration of an EFI image entry point. This can be the entry point to an application - written to this specification, an EFI boot service driver, or an EFI runtime driver. - - @param ImageHandle Handle that identifies the loaded image. - @param SystemTable System Table for this image. - - @retval EFI_SUCCESS The operation completed successfully. - -**/ -EFI_STATUS -EFIAPI -LibRtcInitialize ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - // - // Do some initialization if reqruied to turn on the RTC - // - return EFI_SUCCESS; -} - - -/** - Fixup internal data so that EFI can be call in virtual mode. - Call the passed in Child Notify event and convert any pointers in - lib to virtual mode. - - @param[in] Event The Event that is being processed - @param[in] Context Event Context -**/ -VOID -EFIAPI -LibRtcVirtualNotifyEvent ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - // - // Only needed if you are going to support the OS calling RTC functions in virtual mode. - // You will need to call EfiConvertPointer (). To convert any stored physical addresses - // to virtual address. After the OS transistions to calling in virtual mode, all future - // runtime calls will be made in virtual mode. - // - return; -} - - - diff --git a/EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf b/EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf deleted file mode 100644 index ebc3729aae..0000000000 --- a/EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf +++ /dev/null @@ -1,36 +0,0 @@ -#/** @file -# Memory Status Code Library for UEFI drivers -# -# Lib to provide memory journal status code reporting Routines -# 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = TemplateRealTimeClockLib - FILE_GUID = B661E02D-A90B-42AB-A5F9-CF841AAA43D9 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = RealTimeClockLib - - -[Sources.common] - RealTimeClockLib.c - - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - IoLib - DebugLib diff --git a/EmbeddedPkg/Library/TemplateResetSystemLib/ResetSystemLib.c b/EmbeddedPkg/Library/TemplateResetSystemLib/ResetSystemLib.c deleted file mode 100644 index 328bcbcf16..0000000000 --- a/EmbeddedPkg/Library/TemplateResetSystemLib/ResetSystemLib.c +++ /dev/null @@ -1,103 +0,0 @@ -/** @file - Template library implementation to support ResetSystem Runtime call. - - Fill in the templates with what ever makes you system reset. - - - Copyright (c) 2008 - 2009, Apple Inc. 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. - -**/ - - -#include - -#include -#include -#include - - -/** - Resets the entire platform. - - @param ResetType The type of reset to perform. - @param ResetStatus The status code for the reset. - @param DataSize The size, in bytes, of WatchdogData. - @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or - EfiResetShutdown the data buffer starts with a Null-terminated - Unicode string, optionally followed by additional binary data. - -**/ -EFI_STATUS -EFIAPI -LibResetSystem ( - IN EFI_RESET_TYPE ResetType, - IN EFI_STATUS ResetStatus, - IN UINTN DataSize, - IN CHAR16 *ResetData OPTIONAL - ) -{ - UINTN Address; - UINT8 Data; - - - switch (ResetType) { - case EfiResetCold: - // system power cycle - - // Example using IoLib functions to do IO. - Address = 0x12345678; - Data = MmioRead8 (Address); - MmioWrite8 (Address, Data | 0x01); - - // Note this is a bad example asa MmioOr8 (Address, 0x01) does the same thing - break; - - case EfiResetWarm: - // not a full power cycle, maybe memory stays around. - // if not support do the same thing as EfiResetCold. - break; - - case EfiResetShutdown: - // turn off the system. - // if not support do the same thing as EfiResetCold. - break; - - default: - return EFI_INVALID_PARAMETER; - } - - // - // If we reset, we would not have returned... - // - return EFI_DEVICE_ERROR; -} - - - -/** - Initialize any infrastructure required for LibResetSystem () to function. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -LibInitializeResetSystem ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - return EFI_SUCCESS; -} - diff --git a/EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf b/EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf deleted file mode 100644 index 375cb49421..0000000000 --- a/EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf +++ /dev/null @@ -1,35 +0,0 @@ -#/** @file -# Memory Status Code Library for UEFI drivers -# -# Lib to provide memory journal status code reporting Routines -# 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = TemplateResetSystemLib - FILE_GUID = 40BAFDE5-4CC8-4FBE-A8BA-071890076E50 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = EfiResetSystemLib - - -[Sources.common] - ResetSystemLib.c - -[Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec - -[LibraryClasses] - IoLib - DebugLib \ No newline at end of file -- cgit v1.2.3